rbutil: add a few qDebug outputs, to better track the install process in BootloaderIn...
[kugel-rb.git] / rbutil / rbutilqt / base / bootloaderinstallams.cpp
blob24fb3eb490b5791a3628e3236f7390afea0aaee7
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
9 * Copyright (C) 2008 by Dominik Wenger
10 * $Id$
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 ****************************************************************************/
20 #include <QtCore>
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 "
41 "file.");
44 bool BootloaderInstallAms::install(void)
46 if(m_offile.isEmpty())
47 return false;
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);
57 return true;
60 void BootloaderInstallAms::installStage2(void)
62 qDebug() << "[BootloaderInstallAms] installStage2";
64 unsigned char* buf;
65 unsigned char* of_packed;
66 int of_packedsize;
67 unsigned char* rb_packed;
68 int rb_packedsize;
69 off_t len;
70 struct md5sums sum;
71 char md5sum[33]; /* 32 hex digits, plus terminating zero */
72 int n;
73 int firmware_size;
74 int bootloader_size;
75 int totalsize;
76 char errstr[200];
78 sum.md5 = md5sum;
80 m_tempfile.open();
81 QString bootfile = m_tempfile.fileName();
82 m_tempfile.close();
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));
87 if (buf == NULL)
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);
92 emit done(true);
93 return;
96 /* Load bootloader file */
97 rb_packed = load_rockbox_file(bootfile.toLocal8Bit().data(), sum.model, &bootloader_size,&rb_packedsize,
98 errstr,sizeof(errstr));
99 if (rb_packed == NULL)
101 qDebug() << "[BootloaderInstallAms] could not load bootloader: " << bootfile;
102 emit logItem(errstr, LOGERROR);
103 emit logItem(tr("Could not load %1").arg(bootfile), LOGERROR);
104 free(buf);
105 free(of_packed);
106 emit done(true);
107 return;
110 /* check total size */
111 totalsize = total_size(sum.model,rb_packedsize,of_packedsize);
112 if (totalsize > firmware_size)
114 qDebug() << "[BootloaderInstallAms] No room to insert bootloader";
115 emit logItem("No room to insert bootloader, try another firmware version",LOGERROR);
116 free(buf);
117 free(of_packed);
118 free(rb_packed);
119 emit done(true);
120 return;
123 /* patch the firmware */
124 emit logItem(tr("Patching Firmware..."), LOGINFO);
126 patch_firmware(sum.model,firmware_revision(sum.model),firmware_size,buf,len,of_packed,of_packedsize,rb_packed,rb_packedsize);
128 /* write out file */
129 QFile out(m_blfile);
131 if(!out.open(QIODevice::WriteOnly | QIODevice::Truncate))
133 qDebug() << "[BootloaderInstallAms] Could not open" << m_blfile "for writing";
134 emit logItem(tr("Could not open %1 for writing").arg(m_blfile),LOGERROR);
135 free(buf);
136 free(of_packed);
137 free(rb_packed);
138 emit done(true);
139 return;
142 n = out.write((char*)buf, len);
144 if (n != len)
146 qDebug() << "[BootloaderInstallAms] Could not write firmware file";
147 emit logItem(tr("Could not write firmware file"),LOGERROR);
148 free(buf);
149 free(of_packed);
150 free(rb_packed);
151 emit done(true);
152 return;
155 out.close();
157 free(buf);
158 free(of_packed);
159 free(rb_packed);
161 //end of install
162 qDebug() << "[BootloaderInstallAms] install successfull";
163 emit logItem(tr("Success: modified firmware file created"), LOGINFO);
164 logInstall(LogAdd);
165 emit done(false);
166 return;
169 bool BootloaderInstallAms::uninstall(void)
171 emit logItem("To uninstall, perform a normal upgrade with an unmodified original firmware", LOGINFO);
172 logInstall(LogRemove);
173 return false;
176 BootloaderInstallBase::BootloaderType BootloaderInstallAms::installed(void)
178 return BootloaderUnknown;
181 BootloaderInstallBase::Capabilities BootloaderInstallAms::capabilities(void)
183 return (Install | NeedsOf);