mirror of
https://github.com/tuxbox-neutrino/neutrino.git
synced 2025-08-28 07:51:19 +02:00
Image backup apollo Part #1
- Use src/system/mtdutils for image creation
This commit is contained in:
@@ -53,6 +53,9 @@
|
|||||||
|
|
||||||
#include <system/flashtool.h>
|
#include <system/flashtool.h>
|
||||||
#include <system/httptool.h>
|
#include <system/httptool.h>
|
||||||
|
#ifdef BOXMODEL_APOLLO
|
||||||
|
#include <system/mtdutils/mkfs.jffs2.h>
|
||||||
|
#endif
|
||||||
#include <system/helpers.h>
|
#include <system/helpers.h>
|
||||||
|
|
||||||
#include <lib/libnet/libnet.h>
|
#include <lib/libnet/libnet.h>
|
||||||
@@ -582,6 +585,27 @@ bool CFlashExpert::checkSize(int mtd, std::string &backupFile)
|
|||||||
return true;
|
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)
|
void CFlashExpert::readmtd(int preadmtd)
|
||||||
{
|
{
|
||||||
std::string filename;
|
std::string filename;
|
||||||
@@ -594,6 +618,12 @@ void CFlashExpert::readmtd(int preadmtd)
|
|||||||
else
|
else
|
||||||
filename = (std::string)g_settings.update_dir + "/" + mtdInfo->getMTDName(preadmtd) + timeStr + ".img";
|
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) {
|
if (preadmtd == -1) {
|
||||||
filename = (std::string)g_settings.update_dir + "/flashimage.img"; // US-ASCII (subset of UTF-8 and ISO8859-1)
|
filename = (std::string)g_settings.update_dir + "/flashimage.img"; // US-ASCII (subset of UTF-8 and ISO8859-1)
|
||||||
preadmtd = MTD_OF_WHOLE_IMAGE;
|
preadmtd = MTD_OF_WHOLE_IMAGE;
|
||||||
|
@@ -77,6 +77,9 @@ class CFlashExpert : public CProgressWindow
|
|||||||
|
|
||||||
bool checkSize(int mtd, std::string &backupFile);
|
bool checkSize(int mtd, std::string &backupFile);
|
||||||
void readmtd(int readmtd);
|
void readmtd(int readmtd);
|
||||||
|
#ifdef BOXMODEL_APOLLO
|
||||||
|
void readmtdJFFS2(std::string &filename);
|
||||||
|
#endif
|
||||||
|
|
||||||
public:
|
public:
|
||||||
CFlashExpert();
|
CFlashExpert();
|
||||||
|
@@ -169,8 +169,6 @@ void CMkfsJFFS2::Init()
|
|||||||
printProgress = 0;
|
printProgress = 0;
|
||||||
kbUsed = 0;
|
kbUsed = 0;
|
||||||
progressBar = NULL;
|
progressBar = NULL;
|
||||||
progressBarGlobalX1 = 0;
|
|
||||||
progressBarGlobalX2 = 0;
|
|
||||||
|
|
||||||
ino = 0;
|
ino = 0;
|
||||||
out_ofs = 0;
|
out_ofs = 0;
|
||||||
@@ -371,6 +369,7 @@ struct filesystem_entry *CMkfsJFFS2::find_filesystem_entry(
|
|||||||
void CMkfsJFFS2::printProgressData(bool finish)
|
void CMkfsJFFS2::printProgressData(bool finish)
|
||||||
{
|
{
|
||||||
static int p_old = -1;
|
static int p_old = -1;
|
||||||
|
if (finish) p_old = -1;
|
||||||
int p = (finish) ? 100 : ((all_read/1024)*100 )/kbUsed;
|
int p = (finish) ? 100 : ((all_read/1024)*100 )/kbUsed;
|
||||||
if (p != p_old) {
|
if (p != p_old) {
|
||||||
p_old = p;
|
p_old = p;
|
||||||
@@ -378,21 +377,14 @@ void CMkfsJFFS2::printProgressData(bool finish)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CMkfsJFFS2::setProgressBarGlobal(int x1, int x2)
|
void CMkfsJFFS2::paintProgressBar(bool finish)
|
||||||
{
|
|
||||||
progressBarGlobalX1 = x1;
|
|
||||||
progressBarGlobalX2 = x2;
|
|
||||||
}
|
|
||||||
|
|
||||||
void CMkfsJFFS2::paintProgressBar()
|
|
||||||
{
|
{
|
||||||
static int p_old = -1;
|
static int p_old = -1;
|
||||||
int p1 = ((all_read/1024)*100)/kbUsed;
|
if (finish) p_old = -1;
|
||||||
if (p1 != p_old) {
|
int p = (finish) ? 100 : ((all_read/1024)*100 )/kbUsed;
|
||||||
p_old = p1;
|
if (p != p_old) {
|
||||||
int p2 = progressBarGlobalX1 + (((all_read/1024)*(progressBarGlobalX2-progressBarGlobalX1))/kbUsed);
|
p_old = p;
|
||||||
progressBar->showLocalStatus(p1);
|
progressBar->showLocalStatus(p);
|
||||||
progressBar->showGlobalStatus(p2);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -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 *CMkfsJFFS2::recursive_add_host_directory(
|
||||||
struct filesystem_entry *parent, const char *targetpath,
|
struct filesystem_entry *parent, const char *targetpath,
|
||||||
const char *hostpath,
|
const char *hostpath, bool skipSpezialFolders,
|
||||||
bool skipSpezialFolders) {
|
CProgressWindow *progress) {
|
||||||
int i, n;
|
int i, n;
|
||||||
struct stat sb;
|
struct stat sb;
|
||||||
char *hpath, *tpath;
|
char *hpath, *tpath;
|
||||||
@@ -1111,6 +1103,10 @@ struct filesystem_entry *CMkfsJFFS2::recursive_add_host_directory(
|
|||||||
sys_errmsg("opening directory %s", hostpath);
|
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++) {
|
for (i=0; i<n; i++) {
|
||||||
struct dirent *dp = namelist[i];
|
struct dirent *dp = namelist[i];
|
||||||
if (dp->d_name[0] == '.' && (dp->d_name[1] == 0 ||
|
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(dp);
|
||||||
free(hpath);
|
free(hpath);
|
||||||
free(tpath);
|
free(tpath);
|
||||||
|
if (progress != NULL) {
|
||||||
|
progress->showLocalStatus((i_pr * 100) / n_pr);
|
||||||
|
i_pr++;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
free(namelist);
|
free(namelist);
|
||||||
return (entry);
|
return (entry);
|
||||||
@@ -1190,6 +1190,11 @@ bool CMkfsJFFS2::makeJffs2Image(std::string& path,
|
|||||||
progressBar = progress;
|
progressBar = progress;
|
||||||
hardlinks.rb_node = NULL;
|
hardlinks.rb_node = NULL;
|
||||||
|
|
||||||
|
/* if (progressBar != NULL) {
|
||||||
|
progressBar->setTitle(LOCALE_FLASHUPDATE_TITLEREADFLASH);
|
||||||
|
progressBar->paint();
|
||||||
|
}*/
|
||||||
|
|
||||||
printf("[%s] erase_block_size: 0x%X\n", __FUNCTION__, eraseBlockSize);
|
printf("[%s] erase_block_size: 0x%X\n", __FUNCTION__, eraseBlockSize);
|
||||||
if (useDevTable) {
|
if (useDevTable) {
|
||||||
if (devTable == "") {
|
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)
|
if (devtable)
|
||||||
parse_device_table(fse_root, devtable);
|
parse_device_table(fse_root, devtable);
|
||||||
|
|
||||||
@@ -1247,7 +1262,14 @@ bool CMkfsJFFS2::makeJffs2Image(std::string& path,
|
|||||||
if (kbUsed == 0)
|
if (kbUsed == 0)
|
||||||
kbUsed = 60000;
|
kbUsed = 60000;
|
||||||
|
|
||||||
|
if (progressBar != NULL) {
|
||||||
|
progressBar->showLocalStatus(0);
|
||||||
|
progressBar->showStatusMessageUTF("Create Image");
|
||||||
|
}
|
||||||
create_target_filesystem(fse_root);
|
create_target_filesystem(fse_root);
|
||||||
|
if (progressBar != NULL) {
|
||||||
|
progressBar->showGlobalStatus(90);
|
||||||
|
}
|
||||||
if (printProgress)
|
if (printProgress)
|
||||||
printProgressData(true);
|
printProgressData(true);
|
||||||
|
|
||||||
@@ -1260,6 +1282,12 @@ bool CMkfsJFFS2::makeJffs2Image(std::string& path,
|
|||||||
unlink(imageName_.c_str());
|
unlink(imageName_.c_str());
|
||||||
sync();
|
sync();
|
||||||
}
|
}
|
||||||
|
if (progressBar != NULL) {
|
||||||
|
paintProgressBar(true);
|
||||||
|
progressBar->showGlobalStatus(100);
|
||||||
|
sync();
|
||||||
|
sleep(2);
|
||||||
|
}
|
||||||
|
|
||||||
progressBar = NULL;
|
progressBar = NULL;
|
||||||
return true;
|
return true;
|
||||||
|
@@ -51,8 +51,6 @@ class CMkfsJFFS2
|
|||||||
long kbUsed;
|
long kbUsed;
|
||||||
dev_t dev_x[dev_max];
|
dev_t dev_x[dev_max];
|
||||||
CProgressWindow *progressBar;
|
CProgressWindow *progressBar;
|
||||||
int progressBarGlobalX1;
|
|
||||||
int progressBarGlobalX2;
|
|
||||||
std::string imageName_, sumName_;
|
std::string imageName_, sumName_;
|
||||||
bool useSumtool_;
|
bool useSumtool_;
|
||||||
|
|
||||||
@@ -70,8 +68,8 @@ class CMkfsJFFS2
|
|||||||
bool classInit();
|
bool classInit();
|
||||||
struct filesystem_entry *recursive_add_host_directory(
|
struct filesystem_entry *recursive_add_host_directory(
|
||||||
struct filesystem_entry *parent, const char *targetpath,
|
struct filesystem_entry *parent, const char *targetpath,
|
||||||
const char *hostpath,
|
const char *hostpath, bool skipSpezialFolders,
|
||||||
bool skipSpezialFolders);
|
CProgressWindow *progress=NULL);
|
||||||
int parse_device_table(struct filesystem_entry *root, FILE * file);
|
int parse_device_table(struct filesystem_entry *root, FILE * file);
|
||||||
int interpret_table_entry(struct filesystem_entry *root, char *line);
|
int interpret_table_entry(struct filesystem_entry *root, char *line);
|
||||||
void create_target_filesystem(struct filesystem_entry *root);
|
void create_target_filesystem(struct filesystem_entry *root);
|
||||||
@@ -87,9 +85,8 @@ class CMkfsJFFS2
|
|||||||
void write_pipe(struct filesystem_entry *e);
|
void write_pipe(struct filesystem_entry *e);
|
||||||
void write_symlink(struct filesystem_entry *e);
|
void write_symlink(struct filesystem_entry *e);
|
||||||
unsigned int write_regular_file(struct filesystem_entry *e);
|
unsigned int write_regular_file(struct filesystem_entry *e);
|
||||||
void paintProgressBar();
|
void paintProgressBar(bool finish=false);
|
||||||
void setProgressBarGlobal(int x1, int x2);
|
void printProgressData(bool finish=false);
|
||||||
void printProgressData(bool finish);
|
|
||||||
struct filesystem_entry *find_filesystem_entry(struct filesystem_entry *dir, char *fullname, uint32_t type);
|
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,
|
struct filesystem_entry *add_host_filesystem_entry(const char *name,
|
||||||
const char *path, unsigned long uid, unsigned long gid,
|
const char *path, unsigned long uid, unsigned long gid,
|
||||||
|
Reference in New Issue
Block a user