update: move function to get active partition to helpers.cpp

Origin commit data
------------------
Branch: ni/coolstream
Commit: b4b3264967
Author: vanhofen <vanhofen@gmx.de>
Date: 2019-12-21 (Sat, 21 Dec 2019)

Origin message was:
------------------
- update: move function to get active partition to helpers.cpp

------------------
No further description and justification available within origin commit message!

------------------
This commit was generated by Migit
This commit is contained in:
vanhofen
2019-12-21 01:26:01 +01:00
parent d0fe0e6d4e
commit 1f66f75ed0
3 changed files with 122 additions and 122 deletions

View File

@@ -659,126 +659,7 @@ int CFlashUpdate::exec(CMenuTarget* parent, const std::string &actionKey)
// get active partition
char c[2] = {0};
FILE *f;
#if BOXMODEL_VUPLUS4K
f = fopen("/proc/cmdline", "r");
if (f) {
#if BOXMODEL_VUUNO4K || BOXMODEL_VUUNO4KSE || BOXMODEL_VUSOLO4K || BOXMODEL_VUULTIMO4K
char buf[256] = "";
while(fgets(buf, sizeof(buf), f) != NULL) {
if (strstr(buf, "mmcblk0p5") != NULL) {
c[0] = '1';
c[1] = '\0';
break;
}
if (strstr(buf, "mmcblk0p7") != NULL) {
c[0] = '2';
c[1] = '\0';
break;
}
if (strstr(buf, "mmcblk0p9") != NULL) {
c[0] = '3';
c[1] = '\0';
break;
}
if (strstr(buf, "mmcblk0p11") != NULL) {
c[0] = '4';
c[1] = '\0';
break;
}
}
#elif BOXMODEL_VUZERO4K
char buf[256] = "";
while(fgets(buf, sizeof(buf), f) != NULL) {
if (strstr(buf, "mmcblk0p8") != NULL) {
c[0] = '1';
c[1] = '\0';
break;
}
if (strstr(buf, "mmcblk0p10") != NULL) {
c[0] = '2';
c[1] = '\0';
break;
}
if (strstr(buf, "mmcblk0p12") != NULL) {
c[0] = '3';
c[1] = '\0';
break;
}
if (strstr(buf, "mmcblk0p14") != NULL) {
c[0] = '4';
c[1] = '\0';
break;
}
}
#elif BOXMODEL_VUDUO4K
char buf[256] = "";
while(fgets(buf, sizeof(buf), f) != NULL) {
if (strstr(buf, "mmcblk0p10") != NULL) {
c[0] = '1';
c[1] = '\0';
break;
}
if (strstr(buf, "mmcblk0p12") != NULL) {
c[0] = '2';
c[1] = '\0';
break;
}
if (strstr(buf, "mmcblk0p14") != NULL) {
c[0] = '3';
c[1] = '\0';
break;
}
if (strstr(buf, "mmcblk0p16") != NULL) {
c[0] = '4';
c[1] = '\0';
break;
}
}
#else
printf("VU+ not found.\n");
#endif
fclose(f);
}
#else
char line[1024];
char *pch;
// first check for hd51 new layout
f = fopen("/sys/firmware/devicetree/base/chosen/bootargs", "r");
if (f)
{
if (fgets (line , sizeof(line), f) != NULL)
{
pch = strtok(line, " =");
while (pch != NULL)
{
if (strncmp("linuxrootfs", pch, 11) == 0)
{
strncpy(c, pch + 11, 1);
c[1] = '\0';
dprintf(DEBUG_NORMAL, "[update] Current partition: %s\n", c);
break;
}
pch = strtok(NULL, " =");
}
}
fclose(f);
}
// if no new layout
if (!atoi(c))
{
f = fopen("/sys/firmware/devicetree/base/chosen/kerneldev", "r");
if (f)
{
if (fseek(f, -2, SEEK_END) == 0)
{
c[0] = fgetc(f);
dprintf(DEBUG_NORMAL, "[update] Current partition: %s\n", c);
}
fclose(f);
}
}
#endif
sprintf(c, "%d", getActivePartition());
// select partition
int selected = 0;

View File

@@ -1981,4 +1981,122 @@ bool isDigitWord(std::string str)
return true;
}
//
int getActivePartition()
{
int c = -1;
#if BOXMODEL_VUPLUS4K
FILE *f;
f = fopen("/proc/cmdline", "r");
if (f)
{
char buf[256] = "";
while(fgets(buf, sizeof(buf), f) != NULL)
{
#if BOXMODEL_VUUNO4K || BOXMODEL_VUUNO4KSE || BOXMODEL_VUSOLO4K || BOXMODEL_VUULTIMO4K
if (strstr(buf, "mmcblk0p5") != NULL)
{
c = 1;
break;
}
if (strstr(buf, "mmcblk0p7") != NULL)
{
c = 2;
break;
}
if (strstr(buf, "mmcblk0p9") != NULL)
{
c = 3;
break;
}
if (strstr(buf, "mmcblk0p11") != NULL)
{
c = 4;
break;
}
#elif BOXMODEL_VUZERO4K
if (strstr(buf, "mmcblk0p8") != NULL)
{
c = 1;
break;
}
if (strstr(buf, "mmcblk0p10") != NULL)
{
c = 2;
break;
}
if (strstr(buf, "mmcblk0p12") != NULL)
{
c = 3;
break;
}
if (strstr(buf, "mmcblk0p14") != NULL)
{
c = 4;
break;
}
#elif BOXMODEL_VUDUO4K
if (strstr(buf, "mmcblk0p10") != NULL)
{
c = 1;
break;
}
if (strstr(buf, "mmcblk0p12") != NULL)
{
c = 2;
break;
}
if (strstr(buf, "mmcblk0p14") != NULL)
{
c = 3;
break;
}
if (strstr(buf, "mmcblk0p16") != NULL)
{
c = 4;
break;
}
#endif
}
fclose(f);
}
#elif BOXMODEL_HD51 || BOXMODEL_HD60 || BOXMODEL_HD61 || BOXMODEL_BRE2ZE4K || BOXMODEL_H7
FILE *f;
// first check for subdirboot layout
f = fopen("/sys/firmware/devicetree/base/chosen/bootargs", "r");
if (f)
{
char line[1024];
char *p;
if (fgets(line, sizeof(line), f) != NULL)
{
p = strtok(line, " =");
while (p != NULL)
{
if (strncmp("linuxrootfs", p, 11) == 0)
{
c = atoi(p + 11);
break;
}
p = strtok(NULL, " =");
}
}
fclose(f);
}
// then check for classic layout
if (c < 0)
{
f = fopen("/sys/firmware/devicetree/base/chosen/kerneldev", "r");
if (f)
{
if (fseek(f, -2, SEEK_END) == 0)
{
c = (int)fgetc(f);
}
fclose(f);
}
}
#endif
return c;
}

View File

@@ -192,5 +192,6 @@ bool downloadUrl(std::string url, std::string file, const std::string userAgent
bool isDigitWord(std::string str);
//
int getActivePartition();
#endif