2009-08-15 13:04:21 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* __________ __ ___.
|
|
|
|
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
|
|
|
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
|
|
|
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
|
|
|
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
|
|
|
* \/ \/ \/ \/ \/
|
|
|
|
*
|
|
|
|
* Copyright (C) 2008 by Dominik Wenger
|
|
|
|
*
|
|
|
|
* All files in this archive are subject to the GNU General Public License.
|
|
|
|
* See the file COPYING in the source tree root for full license agreement.
|
|
|
|
*
|
|
|
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
|
|
|
* KIND, either express or implied.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include <QtCore>
|
|
|
|
#include "bootloaderinstallbase.h"
|
|
|
|
#include "bootloaderinstallams.h"
|
|
|
|
|
2009-08-15 14:09:05 +00:00
|
|
|
#include "../mkamsboot/mkamsboot.h"
|
2009-08-15 13:04:21 +00:00
|
|
|
|
|
|
|
BootloaderInstallAms::BootloaderInstallAms(QObject *parent)
|
|
|
|
: BootloaderInstallBase(parent)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
QString BootloaderInstallAms::ofHint()
|
|
|
|
{
|
|
|
|
return tr("Bootloader installation requires you to provide "
|
2011-05-13 18:35:19 +00:00
|
|
|
"a copy of the original Sandisk firmware (bin file). "
|
|
|
|
"This firmware file will be patched and then installed to your "
|
|
|
|
"player along with the rockbox bootloader. "
|
2009-10-26 22:18:27 +00:00
|
|
|
"You need to download this file yourself due to legal "
|
2010-02-19 23:45:29 +00:00
|
|
|
"reasons. Please browse the "
|
|
|
|
"<a href='http://forums.sandisk.com/sansa/'>Sansa Forums'</a> "
|
|
|
|
"or refer to the "
|
|
|
|
"<a href='http://www.rockbox.org/manual.shtml'>manual</a> and "
|
|
|
|
"the <a href='http://www.rockbox.org/wiki/SansaAMS'>SansaAMS</a> "
|
2009-10-26 22:18:27 +00:00
|
|
|
"wiki page on how to obtain this file.<br/>"
|
2013-06-09 15:32:30 +00:00
|
|
|
"<b>Note:</b> This file is not present on your player and will "
|
|
|
|
"disappear automatically after installing it.<br/><br/>"
|
2009-10-26 22:18:27 +00:00
|
|
|
"Press Ok to continue and browse your computer for the firmware "
|
|
|
|
"file.");
|
2009-08-15 13:04:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool BootloaderInstallAms::install(void)
|
|
|
|
{
|
|
|
|
if(m_offile.isEmpty())
|
|
|
|
return false;
|
2013-06-09 15:32:30 +00:00
|
|
|
|
2010-01-19 21:59:25 +00:00
|
|
|
qDebug() << "[BootloaderInstallAms] installing bootloader";
|
2013-06-09 15:32:30 +00:00
|
|
|
|
2009-08-15 13:04:21 +00:00
|
|
|
// download firmware from server
|
|
|
|
emit logItem(tr("Downloading bootloader file"), LOGINFO);
|
2013-06-09 15:32:30 +00:00
|
|
|
|
2009-08-15 13:04:21 +00:00
|
|
|
connect(this, SIGNAL(downloadDone()), this, SLOT(installStage2()));
|
|
|
|
downloadBlStart(m_blurl);
|
2013-06-09 15:32:30 +00:00
|
|
|
|
2009-08-15 13:04:21 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void BootloaderInstallAms::installStage2(void)
|
2013-06-09 15:32:30 +00:00
|
|
|
{
|
2010-01-19 21:59:25 +00:00
|
|
|
qDebug() << "[BootloaderInstallAms] installStage2";
|
2013-06-09 15:32:30 +00:00
|
|
|
|
2009-08-15 13:04:21 +00:00
|
|
|
unsigned char* buf;
|
|
|
|
unsigned char* of_packed;
|
|
|
|
int of_packedsize;
|
|
|
|
unsigned char* rb_packed;
|
|
|
|
int rb_packedsize;
|
|
|
|
off_t len;
|
|
|
|
struct md5sums sum;
|
|
|
|
char md5sum[33]; /* 32 hex digits, plus terminating zero */
|
|
|
|
int n;
|
2010-05-24 10:06:52 +00:00
|
|
|
int model;
|
2009-08-15 13:04:21 +00:00
|
|
|
int firmware_size;
|
|
|
|
int bootloader_size;
|
mkamsboot: prevents 2 potential problems
We checked if the new firmware block (bootloader+ucl function+packed
bootloader & OF) fit in the OF file, but not if it would run properly.
For example the Clipv2 OF is bigger than 0x50000 bytes uncompressed, but
it fitted in this space when packed and concatenated to a packed
bootloader + ucl function and dualboot code (but we use 1MB of RAM and
not 0x50000 anyway).
Now we check that both bootloader and OF are small enough to be unpacked
at runtime: the unpacked data must be smaller than available memory and
not overlap with ucl function and packed data (although the unpacked and
packed data could probably overlap a bit, I don't know how to calculate
this and this could be quite complex).
total_size() is replaced by check_sizes() which will perform all the
checks and set an error string if the firmware can't be patched.
(both mkamsboot and rbutilqt modified accordingly)
The second problem is that dualboot.S assumed r3 and r5 were left
untouched in the device specific checks. This was undocumented and very
error prone when modifying these checks.
r3 is the last byte of packed copy (bootloader or OF)
r5 is the entry point of uclunpack function derived from r3, so move r5
calculation after the device specific code.
Even if r3 is currently unused in the device specific code, we store it
in memory after copying the ucl function, when it points to the last byte
of packed data (not yet copied at this point since we didn't chose if we
boot the OF or the bootloader), and restore it just before using it so no
restriction is placed on registers usage in device specific code.
Add a new variable ucl_dest in dualboot.S set by mkamsboot.c, which
represents the last bound of buffer where we copy the ucl function, and
then the packed data (bootloader or OF).
RAM_SIZE definition is moved from dualboot.S to mkamsboot.c new
model_memory_size(), where it is a bit better documented.
Tested on e200v2 and Clip+
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@24772 a1c6a512-1295-4272-9138-f99709370657
2010-02-19 14:10:26 +00:00
|
|
|
int patchable;
|
2009-08-15 13:04:21 +00:00
|
|
|
int totalsize;
|
|
|
|
char errstr[200];
|
2013-06-09 15:32:30 +00:00
|
|
|
|
|
|
|
sum.md5 = md5sum;
|
|
|
|
|
2009-08-15 13:04:21 +00:00
|
|
|
m_tempfile.open();
|
|
|
|
QString bootfile = m_tempfile.fileName();
|
|
|
|
m_tempfile.close();
|
|
|
|
|
|
|
|
/* Load bootloader file */
|
2010-05-24 10:06:52 +00:00
|
|
|
rb_packed = load_rockbox_file(bootfile.toLocal8Bit().data(), &model,
|
2010-01-19 23:16:43 +00:00
|
|
|
&bootloader_size,&rb_packedsize,
|
2009-08-15 13:04:21 +00:00
|
|
|
errstr,sizeof(errstr));
|
2010-05-24 10:06:52 +00:00
|
|
|
if (rb_packed == NULL)
|
2013-06-09 15:32:30 +00:00
|
|
|
{
|
2010-01-19 21:59:25 +00:00
|
|
|
qDebug() << "[BootloaderInstallAms] could not load bootloader: " << bootfile;
|
2009-08-15 13:04:21 +00:00
|
|
|
emit logItem(errstr, LOGERROR);
|
|
|
|
emit logItem(tr("Could not load %1").arg(bootfile), LOGERROR);
|
|
|
|
emit done(true);
|
|
|
|
return;
|
|
|
|
}
|
2013-06-09 15:32:30 +00:00
|
|
|
|
2010-05-24 10:06:52 +00:00
|
|
|
/* Load original firmware file */
|
|
|
|
buf = load_of_file(m_offile.toLocal8Bit().data(), model, &len, &sum,
|
|
|
|
&firmware_size, &of_packed ,&of_packedsize,
|
|
|
|
errstr, sizeof(errstr));
|
|
|
|
if (buf == NULL)
|
|
|
|
{
|
|
|
|
qDebug() << "[BootloaderInstallAms] could not load OF: " << m_offile;
|
|
|
|
emit logItem(errstr, LOGERROR);
|
|
|
|
emit logItem(tr("Could not load %1").arg(m_offile), LOGERROR);
|
|
|
|
free(rb_packed);
|
|
|
|
emit done(true);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-08-15 13:04:21 +00:00
|
|
|
/* check total size */
|
mkamsboot: prevents 2 potential problems
We checked if the new firmware block (bootloader+ucl function+packed
bootloader & OF) fit in the OF file, but not if it would run properly.
For example the Clipv2 OF is bigger than 0x50000 bytes uncompressed, but
it fitted in this space when packed and concatenated to a packed
bootloader + ucl function and dualboot code (but we use 1MB of RAM and
not 0x50000 anyway).
Now we check that both bootloader and OF are small enough to be unpacked
at runtime: the unpacked data must be smaller than available memory and
not overlap with ucl function and packed data (although the unpacked and
packed data could probably overlap a bit, I don't know how to calculate
this and this could be quite complex).
total_size() is replaced by check_sizes() which will perform all the
checks and set an error string if the firmware can't be patched.
(both mkamsboot and rbutilqt modified accordingly)
The second problem is that dualboot.S assumed r3 and r5 were left
untouched in the device specific checks. This was undocumented and very
error prone when modifying these checks.
r3 is the last byte of packed copy (bootloader or OF)
r5 is the entry point of uclunpack function derived from r3, so move r5
calculation after the device specific code.
Even if r3 is currently unused in the device specific code, we store it
in memory after copying the ucl function, when it points to the last byte
of packed data (not yet copied at this point since we didn't chose if we
boot the OF or the bootloader), and restore it just before using it so no
restriction is placed on registers usage in device specific code.
Add a new variable ucl_dest in dualboot.S set by mkamsboot.c, which
represents the last bound of buffer where we copy the ucl function, and
then the packed data (bootloader or OF).
RAM_SIZE definition is moved from dualboot.S to mkamsboot.c new
model_memory_size(), where it is a bit better documented.
Tested on e200v2 and Clip+
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@24772 a1c6a512-1295-4272-9138-f99709370657
2010-02-19 14:10:26 +00:00
|
|
|
patchable = check_sizes(sum.model, rb_packedsize, bootloader_size,
|
|
|
|
of_packedsize, firmware_size, &totalsize, errstr, sizeof(errstr));
|
|
|
|
|
|
|
|
if (!patchable)
|
2009-08-15 13:04:21 +00:00
|
|
|
{
|
2010-01-19 21:59:25 +00:00
|
|
|
qDebug() << "[BootloaderInstallAms] No room to insert bootloader";
|
mkamsboot: prevents 2 potential problems
We checked if the new firmware block (bootloader+ucl function+packed
bootloader & OF) fit in the OF file, but not if it would run properly.
For example the Clipv2 OF is bigger than 0x50000 bytes uncompressed, but
it fitted in this space when packed and concatenated to a packed
bootloader + ucl function and dualboot code (but we use 1MB of RAM and
not 0x50000 anyway).
Now we check that both bootloader and OF are small enough to be unpacked
at runtime: the unpacked data must be smaller than available memory and
not overlap with ucl function and packed data (although the unpacked and
packed data could probably overlap a bit, I don't know how to calculate
this and this could be quite complex).
total_size() is replaced by check_sizes() which will perform all the
checks and set an error string if the firmware can't be patched.
(both mkamsboot and rbutilqt modified accordingly)
The second problem is that dualboot.S assumed r3 and r5 were left
untouched in the device specific checks. This was undocumented and very
error prone when modifying these checks.
r3 is the last byte of packed copy (bootloader or OF)
r5 is the entry point of uclunpack function derived from r3, so move r5
calculation after the device specific code.
Even if r3 is currently unused in the device specific code, we store it
in memory after copying the ucl function, when it points to the last byte
of packed data (not yet copied at this point since we didn't chose if we
boot the OF or the bootloader), and restore it just before using it so no
restriction is placed on registers usage in device specific code.
Add a new variable ucl_dest in dualboot.S set by mkamsboot.c, which
represents the last bound of buffer where we copy the ucl function, and
then the packed data (bootloader or OF).
RAM_SIZE definition is moved from dualboot.S to mkamsboot.c new
model_memory_size(), where it is a bit better documented.
Tested on e200v2 and Clip+
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@24772 a1c6a512-1295-4272-9138-f99709370657
2010-02-19 14:10:26 +00:00
|
|
|
emit logItem(errstr, LOGERROR);
|
2010-01-19 23:16:43 +00:00
|
|
|
emit logItem(tr("No room to insert bootloader, try another firmware version"),
|
|
|
|
LOGERROR);
|
2009-08-15 13:04:21 +00:00
|
|
|
free(buf);
|
|
|
|
free(of_packed);
|
|
|
|
free(rb_packed);
|
|
|
|
emit done(true);
|
|
|
|
return;
|
|
|
|
}
|
2013-06-09 15:32:30 +00:00
|
|
|
|
2009-08-15 13:04:21 +00:00
|
|
|
/* patch the firmware */
|
|
|
|
emit logItem(tr("Patching Firmware..."), LOGINFO);
|
2013-06-09 15:32:30 +00:00
|
|
|
|
2010-01-19 23:16:43 +00:00
|
|
|
patch_firmware(sum.model,firmware_revision(sum.model),firmware_size,buf,
|
|
|
|
len,of_packed,of_packedsize,rb_packed,rb_packedsize);
|
2009-08-15 13:04:21 +00:00
|
|
|
|
2009-11-22 14:28:48 +00:00
|
|
|
/* write out file */
|
|
|
|
QFile out(m_blfile);
|
2013-06-09 15:32:30 +00:00
|
|
|
|
2009-08-15 13:04:21 +00:00
|
|
|
if(!out.open(QIODevice::WriteOnly | QIODevice::Truncate))
|
|
|
|
{
|
2010-01-19 23:16:43 +00:00
|
|
|
qDebug() << "[BootloaderInstallAms] Could not open" << m_blfile << "for writing";
|
2009-08-15 13:04:21 +00:00
|
|
|
emit logItem(tr("Could not open %1 for writing").arg(m_blfile),LOGERROR);
|
|
|
|
free(buf);
|
|
|
|
free(of_packed);
|
|
|
|
free(rb_packed);
|
|
|
|
emit done(true);
|
|
|
|
return;
|
|
|
|
}
|
2013-06-09 15:32:30 +00:00
|
|
|
|
2009-08-15 13:04:21 +00:00
|
|
|
n = out.write((char*)buf, len);
|
|
|
|
|
|
|
|
if (n != len)
|
|
|
|
{
|
2010-01-19 21:59:25 +00:00
|
|
|
qDebug() << "[BootloaderInstallAms] Could not write firmware file";
|
2009-08-15 13:04:21 +00:00
|
|
|
emit logItem(tr("Could not write firmware file"),LOGERROR);
|
|
|
|
free(buf);
|
|
|
|
free(of_packed);
|
|
|
|
free(rb_packed);
|
|
|
|
emit done(true);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
out.close();
|
2013-06-09 15:32:30 +00:00
|
|
|
|
2009-08-15 13:04:21 +00:00
|
|
|
free(buf);
|
|
|
|
free(of_packed);
|
|
|
|
free(rb_packed);
|
2013-06-09 15:32:30 +00:00
|
|
|
|
2009-08-15 13:04:21 +00:00
|
|
|
//end of install
|
2010-01-19 21:59:25 +00:00
|
|
|
qDebug() << "[BootloaderInstallAms] install successfull";
|
2009-08-15 13:04:21 +00:00
|
|
|
emit logItem(tr("Success: modified firmware file created"), LOGINFO);
|
|
|
|
logInstall(LogAdd);
|
|
|
|
emit done(false);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool BootloaderInstallAms::uninstall(void)
|
|
|
|
{
|
2010-01-19 23:16:43 +00:00
|
|
|
emit logItem(tr("To uninstall, perform a normal upgrade with an unmodified "
|
|
|
|
"original firmware"), LOGINFO);
|
2009-08-15 13:04:21 +00:00
|
|
|
logInstall(LogRemove);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
BootloaderInstallBase::BootloaderType BootloaderInstallAms::installed(void)
|
|
|
|
{
|
|
|
|
return BootloaderUnknown;
|
|
|
|
}
|
|
|
|
|
|
|
|
BootloaderInstallBase::Capabilities BootloaderInstallAms::capabilities(void)
|
|
|
|
{
|
|
|
|
return (Install | NeedsOf);
|
|
|
|
}
|
2010-01-19 23:16:43 +00:00
|
|
|
|