Rockbox Utility: add support for mkimxboot bootloader.
[maemo-rb.git] / rbutil / rbutilqt / base / bootloaderinstallimx.cpp
blobe25244f80af087cd882872408c8b841280893271
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
9 * Copyright (C) 2011 by Jean-Louis Biasini
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 ****************************************************************************/
19 #include <QtCore>
20 #include <QtDebug>
21 #include "bootloaderinstallbase.h"
22 #include "bootloaderinstallimx.h"
23 #include "../mkimxboot/mkimxboot.h"
25 // class for running mkimxboot() in a separate thread to keep the UI responsive.
26 class BootloaderThreadImx : public QThread
28 public:
29 void run(void);
30 void setInputFile(QString f)
31 { m_inputfile = f; }
32 void setOutputFile(QString f)
33 { m_outputfile = f; }
34 void setBootloaderFile(QString f)
35 { m_bootfile = f; }
36 enum imx_error_t error(void)
37 { return m_error; }
38 private:
39 QString m_inputfile;
40 QString m_bootfile;
41 QString m_outputfile;
42 enum imx_error_t m_error;
46 void BootloaderThreadImx::run(void)
48 qDebug() << "[BootloaderThreadImx] Thread started.";
49 struct imx_option_t opt;
50 opt.debug = false;
51 opt.output = IMX_DUALBOOT;
53 m_error = mkimxboot(m_inputfile.toLocal8Bit().constData(),
54 m_bootfile.toLocal8Bit().constData(),
55 m_outputfile.toLocal8Bit().constData(), opt);
56 qDebug() << "[BootloaderThreadImx] Thread finished, result:" << m_error;
60 BootloaderInstallImx::BootloaderInstallImx(QObject *parent)
61 : BootloaderInstallBase(parent)
63 m_thread = NULL;
67 QString BootloaderInstallImx::ofHint()
69 return tr("Bootloader installation requires you to provide "
70 "a copy of the original Sandisk firmware (firmware.sb file). "
71 "This file will be patched with the Rockbox bootloader and "
72 "installed to your player. You need to download this file "
73 "yourself due to legal reasons. Please browse the "
74 "<a href='http://forums.sandisk.com/sansa/'>Sansa Forums</a> "
75 "or refer to the "
76 "<a href= 'http://www.rockbox.org/wiki/SansaFuzePlus'>SansaFuzePlus</a> "
77 "wiki page on how to obtain this file.<br/>"
78 "Press Ok to continue and browse your computer for the firmware "
79 "file.");
83 /** Start bootloader installation.
85 bool BootloaderInstallImx::install(void)
87 if(!QFileInfo(m_offile).isReadable())
89 qDebug() << "[BootloaderInstallImx] could not read original firmware file"
90 << m_offile;
91 emit logItem(tr("Could not read original firmware file"), LOGERROR);
92 return false;
95 qDebug() << "[BootloaderInstallImx] downloading bootloader";
96 // download bootloader from server
97 emit logItem(tr("Downloading bootloader file"), LOGINFO);
98 connect(this, SIGNAL(downloadDone()), this, SLOT(installStage2()));
99 downloadBlStart(m_blurl);
100 return true;
104 void BootloaderInstallImx::installStage2(void)
106 qDebug() << "[BootloaderInstallImx] patching file...";
107 emit logItem(tr("Patching file..."), LOGINFO);
108 m_tempfile.open();
110 // we have not detailed progress on the patching so just show a busy
111 // indicator instead.
112 emit logProgress(0, 0);
113 m_patchedFile.open();
114 m_thread = new BootloaderThreadImx();
115 m_thread->setInputFile(m_offile);
116 m_thread->setBootloaderFile(m_tempfile.fileName());
117 m_thread->setOutputFile(m_patchedFile.fileName());
118 m_tempfile.close();
119 m_patchedFile.close();
120 connect(m_thread, SIGNAL(finished()), this, SLOT(installStage3()));
121 connect(m_thread, SIGNAL(terminated()), this, SLOT(installStage3()));
122 m_thread->start();
126 void BootloaderInstallImx::installStage3(void)
128 enum imx_error_t err = m_thread->error();
129 emit logProgress(1, 1);
130 // if the patch failed
131 if (err != IMX_SUCCESS)
133 qDebug() << "[BootloaderInstallImx] Could not patch the original firmware file";
134 emit logItem(tr("Patching the original firmware failed"), LOGERROR);
135 emit done(true);
136 return;
139 qDebug() << "[BootloaderInstallImx] Original Firmware succesfully patched";
140 emit logItem(tr("Succesfully patched firmware file"), LOGINFO);
142 // if a bootloader is already present delete it.
143 QString fwfile(m_blfile);
144 if(QFileInfo(fwfile).isFile())
146 qDebug() << "[BootloaderInstallImx] deleting old target file";
147 QFile::remove(fwfile);
150 // place (new) bootloader. Copy, since the temporary file will be removed
151 // automatically.
152 qDebug() << "[BootloaderInstallImx] moving patched bootloader to" << fwfile;
153 if(m_patchedFile.copy(fwfile))
155 emit logItem(tr("Bootloader successful installed"), LOGOK);
156 logInstall(LogAdd);
157 emit done(false);
159 else
161 emit logItem(tr("Patched bootloader could not be installed"), LOGERROR);
162 emit done(true);
164 // clean up thread object.
165 delete m_thread;
166 return;
170 bool BootloaderInstallImx::uninstall(void)
172 emit logItem(tr("To uninstall, perform a normal upgrade with an unmodified "
173 "original firmware."), LOGINFO);
174 logInstall(LogRemove);
175 return false;
179 BootloaderInstallBase::BootloaderType BootloaderInstallImx::installed(void)
181 return BootloaderUnknown;
185 BootloaderInstallBase::Capabilities BootloaderInstallImx::capabilities(void)
187 return (Install | NeedsOf);