summaryrefslogtreecommitdiffstats
path: root/rbutil
diff options
context:
space:
mode:
authorDominik Riebeling <Dominik.Riebeling@gmail.com>2008-05-23 19:05:20 +0000
committerDominik Riebeling <Dominik.Riebeling@gmail.com>2008-05-23 19:05:20 +0000
commit9c3bbc3bf9685db4887dc5fa1ffc558811ce78b9 (patch)
tree7313272f283c2703bbfa659d2a1c9d826afe069f /rbutil
parent3de96af1252c5ec6e4765cf583460b334d516210 (diff)
downloadrockbox-9c3bbc3bf9685db4887dc5fa1ffc558811ce78b9.tar.gz
rockbox-9c3bbc3bf9685db4887dc5fa1ffc558811ce78b9.tar.bz2
rockbox-9c3bbc3bf9685db4887dc5fa1ffc558811ce78b9.zip
Move error message generation out of irivertools.cpp to make it independent from the GUI. First step to improve code reuse later.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@17614 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'rbutil')
-rw-r--r--rbutil/rbutilqt/installbootloader.cpp73
-rw-r--r--rbutil/rbutilqt/irivertools/irivertools.cpp101
-rw-r--r--rbutil/rbutilqt/irivertools/irivertools.h13
3 files changed, 109 insertions, 78 deletions
diff --git a/rbutil/rbutilqt/installbootloader.cpp b/rbutil/rbutilqt/installbootloader.cpp
index 3f28323c8c..10f6a9f678 100644
--- a/rbutil/rbutilqt/installbootloader.cpp
+++ b/rbutil/rbutilqt/installbootloader.cpp
@@ -312,7 +312,7 @@ void BootloaderInstaller::gigabeatPrepare()
QString url = m_bootloaderUrlBase + "/gigabeat/" + m_bootloadername;
m_dp->addItem(tr("Downloading file %1.%2")
- .arg(QFileInfo(url).baseName(), QFileInfo(url).completeSuffix()),LOGINFO);
+ .arg(QFileInfo(url).baseName(), QFileInfo(url).completeSuffix()),LOGINFO);
// temporary file needs to be opened to get the filename
downloadFile.open();
@@ -325,11 +325,11 @@ void BootloaderInstaller::gigabeatPrepare()
connect(getter, SIGNAL(done(bool)), this, SLOT(downloadDone(bool)));
connect(getter, SIGNAL(dataReadProgress(int, int)), this, SLOT(updateDataReadProgress(int, int)));
connect(m_dp, SIGNAL(aborted()), getter, SLOT(abort()));
-
+
getter->getFile(QUrl(url));
- }
- else //UnInstallation
- {
+ }
+ else //UnInstallation
+ {
QString firmware;
firmware = resolvePathCase(m_mountpoint + "/GBSYSTEM/FWIMG/FWIMG01.DAT");
QString firmwareOrig = resolvePathCase(firmware.append(".ORIG"));
@@ -339,7 +339,7 @@ void BootloaderInstaller::gigabeatPrepare()
// check if original firmware exists
if(!firmwareOrigFI.exists())
{
- m_dp->addItem(tr("Could not find the Original Firmware at: %1")
+ m_dp->addItem(tr("Could not find the Original Firmware at: %1")
.arg(firmwareOrig),LOGERROR);
emit done(true);
return;
@@ -351,7 +351,7 @@ void BootloaderInstaller::gigabeatPrepare()
//remove modified firmware
if(!firmwareFile.remove())
{
- m_dp->addItem(tr("Could not remove the Firmware at: %1")
+ m_dp->addItem(tr("Could not remove the Firmware at: %1")
.arg(firmware),LOGERROR);
emit done(true);
return;
@@ -360,7 +360,7 @@ void BootloaderInstaller::gigabeatPrepare()
// rename original firmware back
if(!firmwareOrigFile.rename(firmware))
{
- m_dp->addItem(tr("Could not copy the Firmware from: %1 to %2")
+ m_dp->addItem(tr("Could not copy the Firmware from: %1 to %2")
.arg(firmwareOrig,firmware),LOGERROR);
emit done(true);
return;
@@ -369,7 +369,7 @@ void BootloaderInstaller::gigabeatPrepare()
removeInstallLog();
emit done(false); //success
- }
+ }
}
@@ -1330,9 +1330,22 @@ void BootloaderInstaller::iriverFinish()
newHex.close();
// iriver decode
- if (iriver_decode(m_origfirmware, firmwareBinName, FALSE, STRIP_NONE,m_dp) == -1)
- {
- m_dp->addItem(tr("Error in descramble"),LOGERROR);
+ int result;
+ if ((result = iriver_decode(m_origfirmware, firmwareBinName, FALSE, STRIP_NONE)) < 0)
+ {
+ QString error;
+ switch(result) {
+ case -1: error = tr("Can't open input file"); break;
+ case -2: error = tr("Can't open output file"); break;
+ case -3: error = tr("invalid file: header length wrong"); break;
+ case -4: error = tr("invalid file: unrecognized header"); break;
+ case -5: error = tr("invalid file: \"length\" field wrong"); break;
+ case -6: error = tr("invalid file: \"length2\" field wrong"); break;
+ case -7: error = tr("invalid file: internal checksum error"); break;
+ case -8: error = tr("invalid file: \"length3\" field wrong"); break;
+ default: error = tr("unknown"); break;
+ }
+ m_dp->addItem(tr("Error in descramble: %1").arg(error), LOGERROR);
firmwareBin.remove();
newBin.remove();
newHex.remove();
@@ -1340,9 +1353,20 @@ void BootloaderInstaller::iriverFinish()
return;
}
// mkboot
- if (!mkboot(firmwareBinName, newBinName, m_tempfilename, origin,m_dp))
- {
- m_dp->addItem(tr("Error in patching"),LOGERROR);
+ if((result = mkboot(firmwareBinName, newBinName, m_tempfilename, origin)) < 0)
+ {
+ QString error;
+ switch(result) {
+ case -1: error = tr("could not open input file"); break;
+ case -2: error = tr("reading header failed"); break;
+ case -3: error = tr("reading firmware failed"); break;
+ case -4: error = tr("can't open bootloader file"); break;
+ case -5: error = tr("reading bootloader file failed"); break;
+ case -6: error = tr("can't open output file"); break;
+ case -7: error = tr("writing output file failed"); break;
+ }
+ m_dp->addItem(tr("Error in patching: %1").arg(error), LOGERROR);
+
firmwareBin.remove();
newBin.remove();
newHex.remove();
@@ -1350,9 +1374,22 @@ void BootloaderInstaller::iriverFinish()
return;
}
// iriver_encode
- if (iriver_encode(newBinName, newHexName, FALSE,m_dp) == -1)
- {
- m_dp->addItem(tr("Error in scramble"),LOGERROR);
+ if((result = iriver_encode(newBinName, newHexName, FALSE)) < 0)
+ {
+ QString error;
+ switch(result) {
+ case -1: error = tr("Can't open input file"); break;
+ case -2: error = tr("Can't open output file"); break;
+ case -3: error = tr("invalid file: header length wrong"); break;
+ case -4: error = tr("invalid file: unrecognized header"); break;
+ case -5: error = tr("invalid file: \"length\" field wrong"); break;
+ case -6: error = tr("invalid file: \"length2\" field wrong"); break;
+ case -7: error = tr("invalid file: internal checksum error"); break;
+ case -8: error = tr("invalid file: \"length3\" field wrong"); break;
+ default: error = tr("unknown"); break;
+ }
+ m_dp->addItem(tr("Error in scramble: %1").arg(error), LOGERROR);
+
firmwareBin.remove();
newBin.remove();
newHex.remove();
diff --git a/rbutil/rbutilqt/irivertools/irivertools.cpp b/rbutil/rbutilqt/irivertools/irivertools.cpp
index af06e86e06..2bcd9ffb80 100644
--- a/rbutil/rbutilqt/irivertools/irivertools.cpp
+++ b/rbutil/rbutilqt/irivertools/irivertools.cpp
@@ -18,9 +18,9 @@
*
****************************************************************************/
+#include <QtCore>
#include "irivertools.h"
-
const unsigned char munge[] = {
0x7a, 0x36, 0xc4, 0x43, 0x49, 0x6b, 0x35, 0x4e, 0xa3, 0x46, 0x25, 0x84,
0x4d, 0x73, 0x74, 0x61
@@ -47,7 +47,7 @@ const unsigned char header[][16] = {
/* begin mkboot.c excerpt */
unsigned char image[0x400000 + 0x220 + 0x400000/0x200];
-bool mkboot(QString infile, QString outfile,QString bootloader,int origin,ProgressloggerInterface* dp)
+int mkboot(QString infile, QString outfile, QString bootloader, int origin)
{
int i;
int len,bllen;
@@ -59,13 +59,13 @@ bool mkboot(QString infile, QString outfile,QString bootloader,int origin,Progre
QFile f(infile);
if(!f.open(QIODevice::ReadOnly))
{
- dp->addItem("Could not open: %1" + infile,LOGERROR);
- return false;
+ // can't open input file
+ return -1;
}
i = f.read((char*)image,16);
if(i < 16) {
- dp->addItem("reading header failed",LOGERROR);
- return false;
+ // reading header failed
+ return -2;
}
/* This is the length of the binary image without the scrambling
@@ -77,8 +77,8 @@ bool mkboot(QString infile, QString outfile,QString bootloader,int origin,Progre
len = binary_length+0x200-16;
i = f.read((char*)image+16, len);
if(i < len) {
- dp->addItem("reading firmware failed",LOGERROR);
- return false;
+ // reading firmware failed
+ return -3;
}
f.close();
@@ -86,24 +86,24 @@ bool mkboot(QString infile, QString outfile,QString bootloader,int origin,Progre
f.setFileName(bootloader);
if(!f.open(QIODevice::ReadOnly))
{
- dp->addItem("Could not open: %1" + bootloader,LOGERROR);
- return false;
+ // can't open bootloader file
+ return -4;
}
bllen = f.size();
i = f.read((char*)image+0x220 + origin, bllen);
if(i < bllen) {
- dp->addItem("reading bootloader failed",LOGERROR);
- return false;
+ // reading bootloader file failed
+ return -5;
}
f.close();
f.setFileName(outfile);
if(!f.open(QIODevice::WriteOnly))
{
- dp->addItem("Could not open: %1" + outfile,LOGERROR);
- return false;
+ // can't open output file
+ return -6;
}
/* Patch the reset vector to start the boot loader */
@@ -154,13 +154,13 @@ bool mkboot(QString infile, QString outfile,QString bootloader,int origin,Progre
i = f.write((char*)image,total_length);
if(i < total_length) {
- dp->addItem("writing bootloader failed",LOGERROR);
- return false;
+ // writing bootloader file failed
+ return -7;
}
f.close();
- return true;
+ return 0;
}
/* end mkboot.c excerpt */
@@ -208,7 +208,7 @@ static void modifyheader( unsigned char * data )
};
int iriver_decode(QString infile_name, QString outfile_name, unsigned int modify,
- enum striptype stripmode,ProgressloggerInterface* dp )
+ enum striptype stripmode)
{
QFile infile(infile_name);
QFile outfile(outfile_name);
@@ -226,32 +226,30 @@ int iriver_decode(QString infile_name, QString outfile_name, unsigned int modify
if(!infile.open(QIODevice::ReadOnly))
{
- dp->addItem("Could not open: %1" + infile_name,LOGERROR);
+ // can't open input file
return -1;
}
if(!outfile.open(QIODevice::WriteOnly))
{
- dp->addItem("Could not open: %1" + outfile_name,LOGERROR);
- return -1;
+ // can't open output file
+ return -2;
}
lenread = infile.read( (char*)headerdata, 512);
if( lenread != 512 )
{
- dp->addItem("This doesn't look like a valid encrypted iHP"
- "firmware - reason: header length.",LOGERROR);
+ // header length doesn't match
infile.close();
outfile.close();
- return -1;
+ return -3;
};
i = testheader( headerdata );
if( i == -1 )
{
- dp->addItem("This firmware is for an unknown model, or is not"
- " a valid encrypted iHP firmware.",LOGERROR);
+ // header unknown
infile.close();
outfile.close();
- return -1;
+ return -4;
};
fprintf( stderr, "Model %s\n", models[ i ] );
@@ -270,11 +268,10 @@ int iriver_decode(QString infile_name, QString outfile_name, unsigned int modify
dwLength2>>9 != dwLength3 ||
dwLength2+dwLength3+512 != dwLength1 )
{
- dp->addItem("This doesn't look like a valid encrypted "
- "iHP firmware - reason: file 'length' data.",LOGERROR);
+ // file 'length' data is wrong
infile.close();
outfile.close();
- return -1;
+ return -5;
};
pChecksums = ppChecksums = (unsigned char *)( malloc( dwLength3 ) );
@@ -332,11 +329,10 @@ int iriver_decode(QString infile_name, QString outfile_name, unsigned int modify
if( fp != dwLength2 )
{
- dp->addItem("This doesn't look like a valid encrypted "
- "iHP firmware - reason: 'length2' mismatch.",LOGERROR);
+ // 'length2' field mismatch
infile.close();
outfile.close();
- return -1;
+ return -6;
};
fp = 0;
@@ -349,22 +345,20 @@ int iriver_decode(QString infile_name, QString outfile_name, unsigned int modify
outfile.write((char*) blockdata, lenread );
if( memcmp( ppChecksums, blockdata, lenread ) != 0 )
{
- dp->addItem("This doesn't look like a valid encrypted "
- "iHP firmware - reason: Checksum mismatch!",LOGERROR);
+ // file checksum wrong
infile.close();
outfile.close();
- return -1;
+ return -7;
};
ppChecksums += lenread;
};
if( fp != dwLength3 )
{
- dp->addItem("This doesn't look like a valid encrypted "
- "iHP firmware - reason: 'length3' mismatch.",LOGERROR);
+ // 'length3' field mismatch
infile.close();
outfile.close();
- return -1;
+ return -8;
};
@@ -392,7 +386,7 @@ int iriver_decode(QString infile_name, QString outfile_name, unsigned int modify
};
-int iriver_encode(QString infile_name, QString outfile_name, unsigned int modify,ProgressloggerInterface* dp )
+int iriver_encode(QString infile_name, QString outfile_name, unsigned int modify)
{
QFile infile(infile_name);
QFile outfile(outfile_name);
@@ -409,22 +403,23 @@ int iriver_encode(QString infile_name, QString outfile_name, unsigned int modify
if(!infile.open(QIODevice::ReadOnly))
{
- dp->addItem("Could not open: %1" + infile_name,LOGERROR);
+ // can't open input file
return -1;
}
if(!outfile.open(QIODevice::WriteOnly))
{
- dp->addItem("Could not open: %1" + outfile_name,LOGERROR);
- return -1;
+ // can't open output file
+ infile.close();
+ return -2;
}
lenread = infile.read((char*) headerdata, 512 );
if( lenread != 512 )
{
- dp->addItem("This doesn't look like a valid decoded "
- "iHP firmware - reason: header length.",LOGERROR);
+ // header length error
infile.close();
outfile.close();
+ return -3;
};
if( modify )
@@ -435,10 +430,10 @@ int iriver_encode(QString infile_name, QString outfile_name, unsigned int modify
i = testheader( headerdata );
if( i == -1 )
{
- dp->addItem("This firmware is for an unknown model, or is not"
- " a valid decoded iHP firmware.",LOGERROR);
+ // header verification error
infile.close();
outfile.close();
+ return -4;
};
fprintf( stderr, "Model %s\n", models[ i ] );
@@ -456,10 +451,10 @@ int iriver_encode(QString infile_name, QString outfile_name, unsigned int modify
dwLength3 > dwLength1 ||
dwLength2+dwLength3+512 != dwLength1 )
{
- dp->addItem("This doesn't look like a valid decoded "
- "iHP firmware - reason:file 'length' data.",LOGERROR);
+ // file 'length' error
infile.close();
outfile.close();
+ return -5;
};
pChecksums = ppChecksums = (unsigned char *)( malloc( dwLength3 ) );
@@ -494,10 +489,10 @@ int iriver_encode(QString infile_name, QString outfile_name, unsigned int modify
if( fp != dwLength2 )
{
- dp->addItem("This doesn't look like a valid decoded "
- "iHP firmware - reason: 'length1' mismatch.",LOGERROR);
+ // file 'length1' mismatch
infile.close();
outfile.close();
+ return -6;
};
/* write out remainder w/out applying descrambler */
@@ -514,10 +509,10 @@ int iriver_encode(QString infile_name, QString outfile_name, unsigned int modify
if( fp != dwLength3 )
{
- dp->addItem("This doesn't look like a valid decoded "
- "iHP firmware - 'length2' mismatch.",LOGERROR);
+ // 'length2' field mismatch
infile.close();
outfile.close();
+ return -8;
};
fprintf( stderr, "File encoded successfully and checksum table built!\n" );
diff --git a/rbutil/rbutilqt/irivertools/irivertools.h b/rbutil/rbutilqt/irivertools/irivertools.h
index d0d1de6730..4fae06e6d7 100644
--- a/rbutil/rbutilqt/irivertools/irivertools.h
+++ b/rbutil/rbutilqt/irivertools/irivertools.h
@@ -25,7 +25,6 @@
#include <QtCore>
#include "md5sum.h"
-#include "progressloggerinterface.h"
#define ESTF_SIZE 32
@@ -37,18 +36,18 @@ struct sumpairs {
enum striptype
{
- STRIP_NONE,
- STRIP_HEADER_CHECKSUM,
- STRIP_HEADER_CHECKSUM_ESTF
+ STRIP_NONE,
+ STRIP_HEADER_CHECKSUM,
+ STRIP_HEADER_CHECKSUM_ESTF
};
/* protos for iriver.c */
int intable(char *md5, struct sumpairs *table, int len);
-bool mkboot(QString infile, QString outfile,QString bootloader,int origin,ProgressloggerInterface* dp);
+int mkboot(QString infile, QString outfile,QString bootloader,int origin);
int iriver_decode(QString infile_name, QString outfile_name, unsigned int modify,
- enum striptype stripmode,ProgressloggerInterface* dp );
-int iriver_encode(QString infile_name, QString outfile_name, unsigned int modify,ProgressloggerInterface* dp);
+ enum striptype stripmode);
+int iriver_encode(QString infile_name, QString outfile_name, unsigned int modify);
#endif // IRIVERTOOLS_H_INCLUDED