mirror of
https://github.com/tuxbox-fork-migrations/recycled-ni-neutrino.git
synced 2025-08-29 16:31:05 +02:00
Software Update with apply the settings (Part5)
- Fix 'load mtdram driver'
Origin commit data
------------------
Branch: ni/coolstream
Commit: baf803c0db
Author: Michael Liebmann <tuxcode.bbg@gmail.com>
Date: 2012-10-26 (Fri, 26 Oct 2012)
Origin message was:
------------------
* Software Update with apply the settings (Part5)
- Fix 'load mtdram driver'
------------------
This commit was generated by Migit
This commit is contained in:
@@ -53,6 +53,7 @@
|
|||||||
#include <dirent.h>
|
#include <dirent.h>
|
||||||
#include <fnmatch.h>
|
#include <fnmatch.h>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
|
#include <sys/utsname.h>
|
||||||
|
|
||||||
CHintBox * hintBox = 0;
|
CHintBox * hintBox = 0;
|
||||||
|
|
||||||
@@ -96,8 +97,7 @@ bool CExtUpdate::ErrorReset(bool modus, const std::string & msg1, const std::str
|
|||||||
|
|
||||||
if (modus & RESET_UNLOAD) {
|
if (modus & RESET_UNLOAD) {
|
||||||
umount(mountPkt.c_str());
|
umount(mountPkt.c_str());
|
||||||
snprintf(buf, sizeof(buf), "rmmod %s", mtdramDriver.c_str());
|
my_system("rmmod", mtdramDriver.c_str());
|
||||||
my_system(buf);
|
|
||||||
}
|
}
|
||||||
if (modus & RESET_FD1)
|
if (modus & RESET_FD1)
|
||||||
close(fd1);
|
close(fd1);
|
||||||
@@ -149,6 +149,23 @@ bool CExtUpdate::writemtdExt(const std::string & filename)
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool CExtUpdate::isMtdramLoad()
|
||||||
|
{
|
||||||
|
char buf[256] = "";
|
||||||
|
bool ret = false;
|
||||||
|
FILE* f = fopen("/proc/modules", "r");
|
||||||
|
if (f) {
|
||||||
|
while(fgets(buf, sizeof(buf), f) != NULL) {
|
||||||
|
if (strstr(buf, "mtdram") != NULL) {
|
||||||
|
ret = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fclose(f);
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
bool CExtUpdate::writemtdExt()
|
bool CExtUpdate::writemtdExt()
|
||||||
{
|
{
|
||||||
if(!hintBox)
|
if(!hintBox)
|
||||||
@@ -167,51 +184,26 @@ bool CExtUpdate::writemtdExt()
|
|||||||
mtdNumber = mtdInfo->findMTDNumber(mtdFilename);
|
mtdNumber = mtdInfo->findMTDNumber(mtdFilename);
|
||||||
|
|
||||||
// get osrelease
|
// get osrelease
|
||||||
f1 = fopen("/proc/sys/kernel/osrelease", "r");
|
struct utsname uts_info;
|
||||||
if (f1) {
|
if( uname(&uts_info) == 0 )
|
||||||
fgets(buf1, sizeof(buf1), f1);
|
osrelease = uts_info.release;
|
||||||
buf1[strlen(buf1)-1] = '\0';
|
|
||||||
osrelease = buf1;
|
|
||||||
fclose(f1);
|
|
||||||
}
|
|
||||||
else
|
else
|
||||||
return ErrorReset(0, "error with open /proc/sys/kernel/osrelease");
|
return ErrorReset(0, "error no kernel info");
|
||||||
|
|
||||||
// check if mtdram driver is already loaded
|
// check if mtdram driver is already loaded
|
||||||
f1 = fopen("/proc/modules", "r");
|
if (!isMtdramLoad()) {
|
||||||
bool mtdramLoad = false;
|
|
||||||
if (f1) {
|
|
||||||
while(fgets(buf1, sizeof(buf1), f1) != NULL) {
|
|
||||||
if (strstr(buf1, "mtdram") != NULL) {
|
|
||||||
mtdramLoad = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
return ErrorReset(0, "error with open /proc/modules");
|
|
||||||
|
|
||||||
if (!mtdramLoad) {
|
|
||||||
// check if exist mtdram driver
|
// check if exist mtdram driver
|
||||||
snprintf(buf1, sizeof(buf1), "/lib/modules/%s/mtdram.ko", osrelease.c_str());
|
snprintf(buf1, sizeof(buf1), "/lib/modules/%s/mtdram.ko", osrelease.c_str());
|
||||||
mtdramDriver = buf1;
|
mtdramDriver = buf1;
|
||||||
f1 = fopen(mtdramDriver.c_str(), "r");
|
if ( !file_exists(mtdramDriver.c_str()) )
|
||||||
if (f1)
|
|
||||||
fclose(f1);
|
|
||||||
else
|
|
||||||
return ErrorReset(0, "no mtdram driver available");
|
return ErrorReset(0, "no mtdram driver available");
|
||||||
// load mtdram driver
|
// load mtdram driver
|
||||||
snprintf(buf1, sizeof(buf1), "insmod %s total_size=%d erase_size=%d 2>&1", mtdramDriver.c_str(), mtdSize/1024, mtdEraseSize/1024);
|
snprintf(buf1, sizeof(buf1), "total_size=%d", mtdSize/1024);
|
||||||
f1 = popen(buf1, "r");
|
snprintf(buf2, sizeof(buf2), "erase_size=%d", mtdEraseSize/1024);
|
||||||
if (f1) {
|
my_system("insmod", mtdramDriver.c_str(), buf1, buf2);
|
||||||
buf1[0] = '\0';
|
// check if mtdram driver is now loaded
|
||||||
while (fgets(buf1, sizeof(buf1), f1) != NULL) {}
|
if (!isMtdramLoad())
|
||||||
if (strstr(buf1, "insmod:") != NULL)
|
return ErrorReset(0, "error load mtdram driver");
|
||||||
return ErrorReset(RESET_F1, buf1);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
return ErrorReset(0, "error open mtdram driver");
|
|
||||||
pclose(f1);
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
DBG_MSG("mtdram driver is already loaded");
|
DBG_MSG("mtdram driver is already loaded");
|
||||||
|
@@ -60,6 +60,7 @@ class CExtUpdate
|
|||||||
bool copyFileList(const std::string & fileList, const std::string & dstPath);
|
bool copyFileList(const std::string & fileList, const std::string & dstPath);
|
||||||
bool readConfig(const std::string & Config);
|
bool readConfig(const std::string & Config);
|
||||||
bool findConfigEntry(std::string & line, std::string find);
|
bool findConfigEntry(std::string & line, std::string find);
|
||||||
|
bool isMtdramLoad();
|
||||||
|
|
||||||
FILE * fUpdate;
|
FILE * fUpdate;
|
||||||
char updateLogBuf[1024];
|
char updateLogBuf[1024];
|
||||||
|
Reference in New Issue
Block a user