Image backup apollo Part #1

- Use src/system/mtdutils for image creation
This commit is contained in:
Michael Liebmann
2013-09-21 18:26:38 +02:00
parent 2299807e11
commit d4ca6a552e
4 changed files with 83 additions and 25 deletions

View File

@@ -53,6 +53,9 @@
#include <system/flashtool.h>
#include <system/httptool.h>
#ifdef BOXMODEL_APOLLO
#include <system/mtdutils/mkfs.jffs2.h>
#endif
#include <system/helpers.h>
#include <lib/libnet/libnet.h>
@@ -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;

View File

@@ -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();

View File

@@ -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; i<n; i++) {
struct dirent *dp = namelist[i];
if (dp->d_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;

View File

@@ -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,