summaryrefslogtreecommitdiff
path: root/utils/rbutilqt/base/bootloaderinstallimx.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'utils/rbutilqt/base/bootloaderinstallimx.cpp')
-rw-r--r--utils/rbutilqt/base/bootloaderinstallimx.cpp193
1 files changed, 193 insertions, 0 deletions
diff --git a/utils/rbutilqt/base/bootloaderinstallimx.cpp b/utils/rbutilqt/base/bootloaderinstallimx.cpp
new file mode 100644
index 0000000000..7428cf10c8
--- /dev/null
+++ b/utils/rbutilqt/base/bootloaderinstallimx.cpp
@@ -0,0 +1,193 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 *
9 * Copyright (C) 2011 by Jean-Louis Biasini
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 <QtDebug>
21#include "bootloaderinstallbase.h"
22#include "bootloaderinstallimx.h"
23#include "../mkimxboot/mkimxboot.h"
24#include "Logger.h"
25
26// class for running mkimxboot() in a separate thread to keep the UI responsive.
27class BootloaderThreadImx : public QThread
28{
29 public:
30 void run(void);
31 void setInputFile(QString f)
32 { m_inputfile = f; }
33 void setOutputFile(QString f)
34 { m_outputfile = f; }
35 void setBootloaderFile(QString f)
36 { m_bootfile = f; }
37 enum imx_error_t error(void)
38 { return m_error; }
39 private:
40 QString m_inputfile;
41 QString m_bootfile;
42 QString m_outputfile;
43 enum imx_error_t m_error;
44};
45
46
47void BootloaderThreadImx::run(void)
48{
49 LOG_INFO() << "Thread started.";
50 struct imx_option_t opt;
51 memset(&opt, 0, sizeof(opt));
52 opt.debug = false;
53 opt.output = IMX_DUALBOOT;
54 opt.fw_variant = VARIANT_DEFAULT;
55
56 m_error = mkimxboot(m_inputfile.toLocal8Bit().constData(),
57 m_bootfile.toLocal8Bit().constData(),
58 m_outputfile.toLocal8Bit().constData(), opt);
59 LOG_INFO() << "Thread finished, result:" << m_error;
60}
61
62
63BootloaderInstallImx::BootloaderInstallImx(QObject *parent)
64 : BootloaderInstallBase(parent)
65{
66 m_thread = nullptr;
67}
68
69
70QString BootloaderInstallImx::ofHint()
71{
72 return tr("Bootloader installation requires you to provide "
73 "a copy of the original Sandisk firmware (firmware.sb file). "
74 "This file will be patched with the Rockbox bootloader and "
75 "installed to your player. You need to download this file "
76 "yourself due to legal reasons. Please browse the "
77 "<a href='http://forums.sandisk.com/sansa/'>Sansa Forums</a> "
78 "or refer to the "
79 "<a href= 'http://www.rockbox.org/wiki/SansaFuzePlus'>SansaFuzePlus</a> "
80 "wiki page on how to obtain this file.<br/>"
81 "Press Ok to continue and browse your computer for the firmware "
82 "file.");
83}
84
85
86/** Start bootloader installation.
87 */
88bool BootloaderInstallImx::install(void)
89{
90 if(!QFileInfo(m_offile).isReadable())
91 {
92 LOG_ERROR() << "could not read original firmware file"
93 << m_offile;
94 emit logItem(tr("Could not read original firmware file"), LOGERROR);
95 return false;
96 }
97
98 LOG_INFO() << "downloading bootloader";
99 // download bootloader from server
100 emit logItem(tr("Downloading bootloader file"), LOGINFO);
101 connect(this, &BootloaderInstallBase::downloadDone, this, &BootloaderInstallImx::installStage2);
102 downloadBlStart(m_blurl);
103 return true;
104}
105
106
107void BootloaderInstallImx::installStage2(void)
108{
109 LOG_INFO() << "patching file...";
110 emit logItem(tr("Patching file..."), LOGINFO);
111 m_tempfile.open();
112
113 // we have not detailed progress on the patching so just show a busy
114 // indicator instead.
115 emit logProgress(0, 0);
116 m_patchedFile.open();
117 m_thread = new BootloaderThreadImx();
118 m_thread->setInputFile(m_offile);
119 m_thread->setBootloaderFile(m_tempfile.fileName());
120 m_thread->setOutputFile(m_patchedFile.fileName());
121 m_tempfile.close();
122 m_patchedFile.close();
123 connect(m_thread, &QThread::finished, this, &BootloaderInstallImx::installStage3);
124 connect(m_thread, SIGNAL(terminated()), this, SLOT(installStage3()));
125 m_thread->start();
126}
127
128
129void BootloaderInstallImx::installStage3(void)
130{
131 enum imx_error_t err = m_thread->error();
132 emit logProgress(1, 1);
133 // if the patch failed
134 if (err != IMX_SUCCESS)
135 {
136 LOG_ERROR() << "Could not patch the original firmware file";
137 emit logItem(tr("Patching the original firmware failed"), LOGERROR);
138 emit done(true);
139 return;
140 }
141
142 LOG_INFO() << "Original Firmware succesfully patched";
143 emit logItem(tr("Succesfully patched firmware file"), LOGINFO);
144
145 // if a bootloader is already present delete it.
146 QString fwfile(m_blfile);
147 if(QFileInfo(fwfile).isFile())
148 {
149 LOG_INFO() << "deleting old target file";
150 QFile::remove(fwfile);
151 }
152
153 // place (new) bootloader. Copy, since the temporary file will be removed
154 // automatically.
155 LOG_INFO() << "moving patched bootloader to" << fwfile;
156 if(m_patchedFile.copy(fwfile))
157 {
158 emit logItem(tr("Bootloader successful installed"), LOGOK);
159 logInstall(LogAdd);
160 emit done(false);
161 }
162 else
163 {
164 emit logItem(tr("Patched bootloader could not be installed"), LOGERROR);
165 emit done(true);
166 }
167 // clean up thread object.
168 delete m_thread;
169 return;
170}
171
172
173bool BootloaderInstallImx::uninstall(void)
174{
175 emit logItem(tr("To uninstall, perform a normal upgrade with an unmodified "
176 "original firmware."), LOGINFO);
177 logInstall(LogRemove);
178 emit done(true);
179 return false;
180}
181
182
183BootloaderInstallBase::BootloaderType BootloaderInstallImx::installed(void)
184{
185 return BootloaderUnknown;
186}
187
188
189BootloaderInstallBase::Capabilities BootloaderInstallImx::capabilities(void)
190{
191 return (Install | NeedsOf);
192}
193