1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
9 * Copyright (C) 2008 by Dominik Wenger
11 * All files in this archive are subject to the GNU General Public License.
12 * See the file COPYING in the source tree root for full license agreement.
14 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
15 * KIND, either express or implied.
17 ****************************************************************************/
20 #include "bootloaderinstallbase.h"
21 #include "bootloaderinstallams.h"
23 #include "../mkamsboot/mkamsboot.h"
25 BootloaderInstallAms::BootloaderInstallAms(QObject
*parent
)
26 : BootloaderInstallBase(parent
)
30 QString
BootloaderInstallAms::ofHint()
32 return tr("Bootloader installation requires you to provide "
33 "a copy of the original Sandisk firmware (bin file). "
34 "This firmware file will be patched and then installed to your "
35 "player along with the rockbox bootloader. "
36 "You need to download this file yourself due to legal "
37 "reasons. Please browse the "
38 "<a href='http://forums.sandisk.com/sansa/'>Sansa Forums'</a> "
40 "<a href='http://www.rockbox.org/manual.shtml'>manual</a> and "
41 "the <a href='http://www.rockbox.org/wiki/SansaAMS'>SansaAMS</a> "
42 "wiki page on how to obtain this file.<br/>"
43 "Press Ok to continue and browse your computer for the firmware "
47 bool BootloaderInstallAms::install(void)
49 if(m_offile
.isEmpty())
52 qDebug() << "[BootloaderInstallAms] installing bootloader";
54 // download firmware from server
55 emit
logItem(tr("Downloading bootloader file"), LOGINFO
);
57 connect(this, SIGNAL(downloadDone()), this, SLOT(installStage2()));
58 downloadBlStart(m_blurl
);
63 void BootloaderInstallAms::installStage2(void)
65 qDebug() << "[BootloaderInstallAms] installStage2";
68 unsigned char* of_packed
;
70 unsigned char* rb_packed
;
74 char md5sum
[33]; /* 32 hex digits, plus terminating zero */
86 QString bootfile
= m_tempfile
.fileName();
89 /* Load bootloader file */
90 rb_packed
= load_rockbox_file(bootfile
.toLocal8Bit().data(), &model
,
91 &bootloader_size
,&rb_packedsize
,
92 errstr
,sizeof(errstr
));
93 if (rb_packed
== NULL
)
95 qDebug() << "[BootloaderInstallAms] could not load bootloader: " << bootfile
;
96 emit
logItem(errstr
, LOGERROR
);
97 emit
logItem(tr("Could not load %1").arg(bootfile
), LOGERROR
);
102 /* Load original firmware file */
103 buf
= load_of_file(m_offile
.toLocal8Bit().data(), model
, &len
, &sum
,
104 &firmware_size
, &of_packed
,&of_packedsize
,
105 errstr
, sizeof(errstr
));
108 qDebug() << "[BootloaderInstallAms] could not load OF: " << m_offile
;
109 emit
logItem(errstr
, LOGERROR
);
110 emit
logItem(tr("Could not load %1").arg(m_offile
), LOGERROR
);
116 /* check total size */
117 patchable
= check_sizes(sum
.model
, rb_packedsize
, bootloader_size
,
118 of_packedsize
, firmware_size
, &totalsize
, errstr
, sizeof(errstr
));
122 qDebug() << "[BootloaderInstallAms] No room to insert bootloader";
123 emit
logItem(errstr
, LOGERROR
);
124 emit
logItem(tr("No room to insert bootloader, try another firmware version"),
133 /* patch the firmware */
134 emit
logItem(tr("Patching Firmware..."), LOGINFO
);
136 patch_firmware(sum
.model
,firmware_revision(sum
.model
),firmware_size
,buf
,
137 len
,of_packed
,of_packedsize
,rb_packed
,rb_packedsize
);
142 if(!out
.open(QIODevice::WriteOnly
| QIODevice::Truncate
))
144 qDebug() << "[BootloaderInstallAms] Could not open" << m_blfile
<< "for writing";
145 emit
logItem(tr("Could not open %1 for writing").arg(m_blfile
),LOGERROR
);
153 n
= out
.write((char*)buf
, len
);
157 qDebug() << "[BootloaderInstallAms] Could not write firmware file";
158 emit
logItem(tr("Could not write firmware file"),LOGERROR
);
173 qDebug() << "[BootloaderInstallAms] install successfull";
174 emit
logItem(tr("Success: modified firmware file created"), LOGINFO
);
180 bool BootloaderInstallAms::uninstall(void)
182 emit
logItem(tr("To uninstall, perform a normal upgrade with an unmodified "
183 "original firmware"), LOGINFO
);
184 logInstall(LogRemove
);
188 BootloaderInstallBase::BootloaderType
BootloaderInstallAms::installed(void)
190 return BootloaderUnknown
;
193 BootloaderInstallBase::Capabilities
BootloaderInstallAms::capabilities(void)
195 return (Install
| NeedsOf
);