From 786fd143169183eb1835b47a040cc6a7fac515af Mon Sep 17 00:00:00 2001 From: Michael Liebmann Date: Sat, 21 Sep 2013 18:26:38 +0200 Subject: [PATCH] Image backup apollo Part #1 - Use src/system/mtdutils for image creation Origin commit data ------------------ Commit: https://github.com/neutrino-images/ni-neutrino/commit/d4ca6a552e5498eb1640311afe53793176c61398 Author: Michael Liebmann Date: 2013-09-21 (Sat, 21 Sep 2013) --- src/gui/update.cpp | 30 ++++++++++++++ src/gui/update.h | 3 ++ src/system/mtdutils/mkfs.jffs2.cpp | 64 +++++++++++++++++++++--------- src/system/mtdutils/mkfs.jffs2.h | 11 ++--- 4 files changed, 83 insertions(+), 25 deletions(-) diff --git a/src/gui/update.cpp b/src/gui/update.cpp index c286283b9..941e44eb0 100644 --- a/src/gui/update.cpp +++ b/src/gui/update.cpp @@ -53,6 +53,9 @@ #include #include +#ifdef BOXMODEL_APOLLO +#include +#endif #include #include @@ -582,6 +585,27 @@ bool CFlashExpert::checkSize(int mtd, std::string &backupFile) return true; } +#ifdef BOXMODEL_APOLLO +void CFlashExpert::readmtdJFFS2(std::string &filename) +{ + int esize = CMTDInfo::getInstance()->getMTDEraseSize(CMTDInfo::getInstance()->findMTDsystem()); + CMkfsJFFS2 mkfs; + std::string path = "/"; + CProgressWindow *progress = new CProgressWindow; + progress->setTitle(LOCALE_FLASHUPDATE_TITLEREADFLASH); + progress->paint(); + mkfs.makeJffs2Image(path, filename, esize, 0, 0, __LITTLE_ENDIAN, true, true, progress); + progress->hide(); + delete progress; + + sleep(1); + char message[500]; + sprintf(message, g_Locale->getText(LOCALE_FLASHUPDATE_SAVESUCCESS), filename.c_str()); + ShowHintUTF(LOCALE_MESSAGEBOX_INFO, message); + +} +#endif + void CFlashExpert::readmtd(int preadmtd) { std::string filename; @@ -594,6 +618,12 @@ void CFlashExpert::readmtd(int preadmtd) else filename = (std::string)g_settings.update_dir + "/" + mtdInfo->getMTDName(preadmtd) + timeStr + ".img"; +#ifdef BOXMODEL_APOLLO + if (preadmtd == 0) { + readmtdJFFS2(filename); + return; + } +#endif if (preadmtd == -1) { filename = (std::string)g_settings.update_dir + "/flashimage.img"; // US-ASCII (subset of UTF-8 and ISO8859-1) preadmtd = MTD_OF_WHOLE_IMAGE; diff --git a/src/gui/update.h b/src/gui/update.h index 1992b6aca..a5a26da47 100644 --- a/src/gui/update.h +++ b/src/gui/update.h @@ -77,6 +77,9 @@ class CFlashExpert : public CProgressWindow bool checkSize(int mtd, std::string &backupFile); void readmtd(int readmtd); +#ifdef BOXMODEL_APOLLO + void readmtdJFFS2(std::string &filename); +#endif public: CFlashExpert(); diff --git a/src/system/mtdutils/mkfs.jffs2.cpp b/src/system/mtdutils/mkfs.jffs2.cpp index ed9168ea4..b80d4c799 100644 --- a/src/system/mtdutils/mkfs.jffs2.cpp +++ b/src/system/mtdutils/mkfs.jffs2.cpp @@ -169,8 +169,6 @@ void CMkfsJFFS2::Init() printProgress = 0; kbUsed = 0; progressBar = NULL; - progressBarGlobalX1 = 0; - progressBarGlobalX2 = 0; ino = 0; out_ofs = 0; @@ -371,6 +369,7 @@ struct filesystem_entry *CMkfsJFFS2::find_filesystem_entry( void CMkfsJFFS2::printProgressData(bool finish) { static int p_old = -1; + if (finish) p_old = -1; int p = (finish) ? 100 : ((all_read/1024)*100 )/kbUsed; if (p != p_old) { p_old = p; @@ -378,21 +377,14 @@ void CMkfsJFFS2::printProgressData(bool finish) } } -void CMkfsJFFS2::setProgressBarGlobal(int x1, int x2) -{ - progressBarGlobalX1 = x1; - progressBarGlobalX2 = x2; -} - -void CMkfsJFFS2::paintProgressBar() +void CMkfsJFFS2::paintProgressBar(bool finish) { static int p_old = -1; - int p1 = ((all_read/1024)*100)/kbUsed; - if (p1 != p_old) { - p_old = p1; - int p2 = progressBarGlobalX1 + (((all_read/1024)*(progressBarGlobalX2-progressBarGlobalX1))/kbUsed); - progressBar->showLocalStatus(p1); - progressBar->showGlobalStatus(p2); + if (finish) p_old = -1; + int p = (finish) ? 100 : ((all_read/1024)*100 )/kbUsed; + if (p != p_old) { + p_old = p; + progressBar->showLocalStatus(p); } } @@ -1050,8 +1042,8 @@ int CMkfsJFFS2::parse_device_table(struct filesystem_entry *root, FILE * file) struct filesystem_entry *CMkfsJFFS2::recursive_add_host_directory( struct filesystem_entry *parent, const char *targetpath, - const char *hostpath, - bool skipSpezialFolders) { + const char *hostpath, bool skipSpezialFolders, + CProgressWindow *progress) { int i, n; struct stat sb; char *hpath, *tpath; @@ -1111,6 +1103,10 @@ struct filesystem_entry *CMkfsJFFS2::recursive_add_host_directory( sys_errmsg("opening directory %s", hostpath); } + int i_pr = 0, n_pr = 0; + if (progress != NULL) { + n_pr = (n <= 2) ? 1 : n-2; + } for (i=0; id_name[0] == '.' && (dp->d_name[1] == 0 || @@ -1151,6 +1147,10 @@ struct filesystem_entry *CMkfsJFFS2::recursive_add_host_directory( free(dp); free(hpath); free(tpath); + if (progress != NULL) { + progress->showLocalStatus((i_pr * 100) / n_pr); + i_pr++; + } } free(namelist); return (entry); @@ -1190,6 +1190,11 @@ bool CMkfsJFFS2::makeJffs2Image(std::string& path, progressBar = progress; hardlinks.rb_node = NULL; +/* if (progressBar != NULL) { + progressBar->setTitle(LOCALE_FLASHUPDATE_TITLEREADFLASH); + progressBar->paint(); + }*/ + printf("[%s] erase_block_size: 0x%X\n", __FUNCTION__, eraseBlockSize); if (useDevTable) { if (devTable == "") { @@ -1231,7 +1236,17 @@ bool CMkfsJFFS2::makeJffs2Image(std::string& path, } } - fse_root = recursive_add_host_directory(NULL, "/", cwd, skipSpezialFolders); + if (progressBar != NULL) { + progressBar->showLocalStatus(0); + progressBar->showGlobalStatus(0); + progressBar->showStatusMessageUTF("Read Files and Directories"); + } + fse_root = recursive_add_host_directory(NULL, "/", cwd, skipSpezialFolders, progressBar); + if (progressBar != NULL) { + progressBar->showLocalStatus(100); + progressBar->showGlobalStatus(50); + } + if (devtable) parse_device_table(fse_root, devtable); @@ -1247,7 +1262,14 @@ bool CMkfsJFFS2::makeJffs2Image(std::string& path, if (kbUsed == 0) kbUsed = 60000; + if (progressBar != NULL) { + progressBar->showLocalStatus(0); + progressBar->showStatusMessageUTF("Create Image"); + } create_target_filesystem(fse_root); + if (progressBar != NULL) { + progressBar->showGlobalStatus(90); + } if (printProgress) printProgressData(true); @@ -1260,6 +1282,12 @@ bool CMkfsJFFS2::makeJffs2Image(std::string& path, unlink(imageName_.c_str()); sync(); } + if (progressBar != NULL) { + paintProgressBar(true); + progressBar->showGlobalStatus(100); + sync(); + sleep(2); + } progressBar = NULL; return true; diff --git a/src/system/mtdutils/mkfs.jffs2.h b/src/system/mtdutils/mkfs.jffs2.h index 54f1a3333..8275e2f72 100644 --- a/src/system/mtdutils/mkfs.jffs2.h +++ b/src/system/mtdutils/mkfs.jffs2.h @@ -51,8 +51,6 @@ class CMkfsJFFS2 long kbUsed; dev_t dev_x[dev_max]; CProgressWindow *progressBar; - int progressBarGlobalX1; - int progressBarGlobalX2; std::string imageName_, sumName_; bool useSumtool_; @@ -70,8 +68,8 @@ class CMkfsJFFS2 bool classInit(); struct filesystem_entry *recursive_add_host_directory( struct filesystem_entry *parent, const char *targetpath, - const char *hostpath, - bool skipSpezialFolders); + const char *hostpath, bool skipSpezialFolders, + CProgressWindow *progress=NULL); int parse_device_table(struct filesystem_entry *root, FILE * file); int interpret_table_entry(struct filesystem_entry *root, char *line); void create_target_filesystem(struct filesystem_entry *root); @@ -87,9 +85,8 @@ class CMkfsJFFS2 void write_pipe(struct filesystem_entry *e); void write_symlink(struct filesystem_entry *e); unsigned int write_regular_file(struct filesystem_entry *e); - void paintProgressBar(); - void setProgressBarGlobal(int x1, int x2); - void printProgressData(bool finish); + void paintProgressBar(bool finish=false); + void printProgressData(bool finish=false); struct filesystem_entry *find_filesystem_entry(struct filesystem_entry *dir, char *fullname, uint32_t type); struct filesystem_entry *add_host_filesystem_entry(const char *name, const char *path, unsigned long uid, unsigned long gid,