1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
9 * Copyright (C) 2008 by Dominik Wenger
12 * All files in this archive are subject to the GNU General Public License.
13 * See the file COPYING in the source tree root for full license agreement.
15 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
16 * KIND, either express or implied.
18 ****************************************************************************/
21 #include "bootloaderinstallbase.h"
22 #include "bootloaderinstallams.h"
24 #include "../mkamsboot/mkamsboot.h"
26 BootloaderInstallAms::BootloaderInstallAms(QObject
*parent
)
27 : BootloaderInstallBase(parent
)
31 QString
BootloaderInstallAms::ofHint()
33 return tr("Bootloader installation requires you to provide "
34 "a firmware file of the original firmware (bin file). "
35 "You need to download this file yourself due to legal "
36 "reasons. Please refer to the "
37 "<a href='http://www.rockbox.org/manual.shtml'>manual</a> and the "
38 "<a href='http://www.rockbox.org/wiki/SansaAMS'>SansaAMS</a> "
39 "wiki page on how to obtain this file.<br/>"
40 "Press Ok to continue and browse your computer for the firmware "
44 bool BootloaderInstallAms::install(void)
46 if(m_offile
.isEmpty())
49 qDebug() << "[BootloaderInstallAms] installing bootloader";
51 // download firmware from server
52 emit
logItem(tr("Downloading bootloader file"), LOGINFO
);
54 connect(this, SIGNAL(downloadDone()), this, SLOT(installStage2()));
55 downloadBlStart(m_blurl
);
60 void BootloaderInstallAms::installStage2(void)
62 qDebug() << "[BootloaderInstallAms] installStage2";
65 unsigned char* of_packed
;
67 unsigned char* rb_packed
;
71 char md5sum
[33]; /* 32 hex digits, plus terminating zero */
81 QString bootfile
= m_tempfile
.fileName();
84 /* Load original firmware file */
85 buf
= load_of_file(m_offile
.toLocal8Bit().data(), &len
,&sum
,&firmware_size
,
86 &of_packed
,&of_packedsize
,errstr
,sizeof(errstr
));
89 qDebug() << "[BootloaderInstallAms] could not load OF: " << m_offile
;
90 emit
logItem(errstr
, LOGERROR
);
91 emit
logItem(tr("Could not load %1").arg(m_offile
), LOGERROR
);
96 /* Load bootloader file */
97 rb_packed
= load_rockbox_file(bootfile
.toLocal8Bit().data(), sum
.model
,
98 &bootloader_size
,&rb_packedsize
,
99 errstr
,sizeof(errstr
));
100 if (rb_packed
== NULL
)
102 qDebug() << "[BootloaderInstallAms] could not load bootloader: " << bootfile
;
103 emit
logItem(errstr
, LOGERROR
);
104 emit
logItem(tr("Could not load %1").arg(bootfile
), LOGERROR
);
111 /* check total size */
112 totalsize
= total_size(sum
.model
,rb_packedsize
,of_packedsize
);
113 if (totalsize
> firmware_size
)
115 qDebug() << "[BootloaderInstallAms] No room to insert bootloader";
116 emit
logItem(tr("No room to insert bootloader, try another firmware version"),
125 /* patch the firmware */
126 emit
logItem(tr("Patching Firmware..."), LOGINFO
);
128 patch_firmware(sum
.model
,firmware_revision(sum
.model
),firmware_size
,buf
,
129 len
,of_packed
,of_packedsize
,rb_packed
,rb_packedsize
);
134 if(!out
.open(QIODevice::WriteOnly
| QIODevice::Truncate
))
136 qDebug() << "[BootloaderInstallAms] Could not open" << m_blfile
<< "for writing";
137 emit
logItem(tr("Could not open %1 for writing").arg(m_blfile
),LOGERROR
);
145 n
= out
.write((char*)buf
, len
);
149 qDebug() << "[BootloaderInstallAms] Could not write firmware file";
150 emit
logItem(tr("Could not write firmware file"),LOGERROR
);
165 qDebug() << "[BootloaderInstallAms] install successfull";
166 emit
logItem(tr("Success: modified firmware file created"), LOGINFO
);
172 bool BootloaderInstallAms::uninstall(void)
174 emit
logItem(tr("To uninstall, perform a normal upgrade with an unmodified "
175 "original firmware"), LOGINFO
);
176 logInstall(LogRemove
);
180 BootloaderInstallBase::BootloaderType
BootloaderInstallAms::installed(void)
182 return BootloaderUnknown
;
185 BootloaderInstallBase::Capabilities
BootloaderInstallAms::capabilities(void)
187 return (Install
| NeedsOf
);