summaryrefslogtreecommitdiff
path: root/utils/rbutilqt/base/bootloaderinstallams.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'utils/rbutilqt/base/bootloaderinstallams.cpp')
-rw-r--r--utils/rbutilqt/base/bootloaderinstallams.cpp201
1 files changed, 201 insertions, 0 deletions
diff --git a/utils/rbutilqt/base/bootloaderinstallams.cpp b/utils/rbutilqt/base/bootloaderinstallams.cpp
new file mode 100644
index 0000000000..be43ed52db
--- /dev/null
+++ b/utils/rbutilqt/base/bootloaderinstallams.cpp
@@ -0,0 +1,201 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 *
9 * Copyright (C) 2008 by Dominik Wenger
10 *
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.
13 *
14 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
15 * KIND, either express or implied.
16 *
17 ****************************************************************************/
18
19#include <QtCore>
20#include "bootloaderinstallbase.h"
21#include "bootloaderinstallams.h"
22#include "Logger.h"
23
24#include "../mkamsboot/mkamsboot.h"
25
26BootloaderInstallAms::BootloaderInstallAms(QObject *parent)
27 : BootloaderInstallBase(parent)
28{
29}
30
31QString BootloaderInstallAms::ofHint()
32{
33 return tr("Bootloader installation requires you to provide "
34 "a copy of the original Sandisk firmware (bin file). "
35 "This firmware file will be patched and then installed to your "
36 "player along with the rockbox bootloader. "
37 "You need to download this file yourself due to legal "
38 "reasons. Please browse the "
39 "<a href='http://forums.sandisk.com/sansa/'>Sansa Forums</a> "
40 "or refer to the "
41 "<a href='http://www.rockbox.org/manual.shtml'>manual</a> and "
42 "the <a href='http://www.rockbox.org/wiki/SansaAMS'>SansaAMS</a> "
43 "wiki page on how to obtain this file.<br/>"
44 "<b>Note:</b> This file is not present on your player and will "
45 "disappear automatically after installing it.<br/><br/>"
46 "Press Ok to continue and browse your computer for the firmware "
47 "file.");
48}
49
50bool BootloaderInstallAms::install(void)
51{
52 if(m_offile.isEmpty())
53 return false;
54
55 LOG_INFO() << "installing bootloader";
56
57 // download firmware from server
58 emit logItem(tr("Downloading bootloader file"), LOGINFO);
59
60 connect(this, &BootloaderInstallBase::downloadDone, this, &BootloaderInstallAms::installStage2);
61 downloadBlStart(m_blurl);
62
63 return true;
64}
65
66void BootloaderInstallAms::installStage2(void)
67{
68 LOG_INFO() << "installStage2";
69
70 unsigned char* buf;
71 unsigned char* of_packed;
72 int of_packedsize;
73 unsigned char* rb_packed;
74 int rb_packedsize;
75 off_t len;
76 struct md5sums sum;
77 char md5sum[33]; /* 32 hex digits, plus terminating zero */
78 int n;
79 int model;
80 int firmware_size;
81 int bootloader_size;
82 int patchable;
83 int totalsize;
84 char errstr[200];
85
86 sum.md5 = md5sum;
87
88 m_tempfile.open();
89 QString bootfile = m_tempfile.fileName();
90 m_tempfile.close();
91
92 /* Load bootloader file */
93 rb_packed = load_rockbox_file(bootfile.toLocal8Bit().data(), &model,
94 &bootloader_size,&rb_packedsize,
95 errstr,sizeof(errstr));
96 if (rb_packed == nullptr)
97 {
98 LOG_ERROR() << "could not load bootloader: " << bootfile;
99 emit logItem(errstr, LOGERROR);
100 emit logItem(tr("Could not load %1").arg(bootfile), LOGERROR);
101 emit done(true);
102 return;
103 }
104
105 /* Load original firmware file */
106 buf = load_of_file(m_offile.toLocal8Bit().data(), model, &len, &sum,
107 &firmware_size, &of_packed ,&of_packedsize,
108 errstr, sizeof(errstr));
109 if (buf == nullptr)
110 {
111 LOG_ERROR() << "could not load OF: " << m_offile;
112 emit logItem(errstr, LOGERROR);
113 emit logItem(tr("Could not load %1").arg(m_offile), LOGERROR);
114 free(rb_packed);
115 emit done(true);
116 return;
117 }
118
119 /* check total size */
120 patchable = check_sizes(sum.model, rb_packedsize, bootloader_size,
121 of_packedsize, firmware_size, &totalsize, errstr, sizeof(errstr));
122
123 if (!patchable)
124 {
125 LOG_ERROR() << "No room to insert bootloader";
126 emit logItem(errstr, LOGERROR);
127 emit logItem(tr("No room to insert bootloader, try another firmware version"),
128 LOGERROR);
129 free(buf);
130 free(of_packed);
131 free(rb_packed);
132 emit done(true);
133 return;
134 }
135
136 /* patch the firmware */
137 emit logItem(tr("Patching Firmware..."), LOGINFO);
138
139 patch_firmware(sum.model,firmware_revision(sum.model),firmware_size,buf,
140 len,of_packed,of_packedsize,rb_packed,rb_packedsize);
141
142 /* write out file */
143 QFile out(m_blfile);
144
145 if(!out.open(QIODevice::WriteOnly | QIODevice::Truncate))
146 {
147 LOG_ERROR() << "Could not open" << m_blfile << "for writing";
148 emit logItem(tr("Could not open %1 for writing").arg(m_blfile),LOGERROR);
149 free(buf);
150 free(of_packed);
151 free(rb_packed);
152 emit done(true);
153 return;
154 }
155
156 n = out.write((char*)buf, len);
157
158 if (n != len)
159 {
160 LOG_ERROR() << "Could not write firmware file";
161 emit logItem(tr("Could not write firmware file"),LOGERROR);
162 free(buf);
163 free(of_packed);
164 free(rb_packed);
165 emit done(true);
166 return;
167 }
168
169 out.close();
170
171 free(buf);
172 free(of_packed);
173 free(rb_packed);
174
175 //end of install
176 LOG_INFO() << "install successfull";
177 emit logItem(tr("Success: modified firmware file created"), LOGINFO);
178 logInstall(LogAdd);
179 emit done(false);
180 return;
181}
182
183bool BootloaderInstallAms::uninstall(void)
184{
185 emit logItem(tr("To uninstall, perform a normal upgrade with an unmodified "
186 "original firmware"), LOGINFO);
187 logInstall(LogRemove);
188 emit done(true);
189 return false;
190}
191
192BootloaderInstallBase::BootloaderType BootloaderInstallAms::installed(void)
193{
194 return BootloaderUnknown;
195}
196
197BootloaderInstallBase::Capabilities BootloaderInstallAms::capabilities(void)
198{
199 return (Install | NeedsOf);
200}
201