Bump version numbers for 3.13
[maemo-rb.git] / rbutil / rbutilqt / base / bootloaderinstallimx.cpp
blobe12849e8563b946da93b055eb6017fc632cc8348
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 memset(&opt, 0, sizeof(opt));
51 opt.debug = false;
52 opt.output = IMX_DUALBOOT;
53 opt.fw_variant = VARIANT_DEFAULT;
55 m_error = mkimxboot(m_inputfile.toLocal8Bit().constData(),
56 m_bootfile.toLocal8Bit().constData(),
57 m_outputfile.toLocal8Bit().constData(), opt);
58 qDebug() << "[BootloaderThreadImx] Thread finished, result:" << m_error;
62 BootloaderInstallImx::BootloaderInstallImx(QObject *parent)
63 : BootloaderInstallBase(parent)
65 m_thread = NULL;
69 QString BootloaderInstallImx::ofHint()
71 return tr("Bootloader installation requires you to provide "
72 "a copy of the original Sandisk firmware (firmware.sb file). "
73 "This file will be patched with the Rockbox bootloader and "
74 "installed to your player. You need to download this file "
75 "yourself due to legal reasons. Please browse the "
76 "<a href='http://forums.sandisk.com/sansa/'>Sansa Forums</a> "
77 "or refer to the "
78 "<a href= 'http://www.rockbox.org/wiki/SansaFuzePlus'>SansaFuzePlus</a> "
79 "wiki page on how to obtain this file.<br/>"
80 "Press Ok to continue and browse your computer for the firmware "
81 "file.");
85 /** Start bootloader installation.
87 bool BootloaderInstallImx::install(void)
89 if(!QFileInfo(m_offile).isReadable())
91 qDebug() << "[BootloaderInstallImx] could not read original firmware file"
92 << m_offile;
93 emit logItem(tr("Could not read original firmware file"), LOGERROR);
94 return false;
97 qDebug() << "[BootloaderInstallImx] downloading bootloader";
98 // download bootloader from server
99 emit logItem(tr("Downloading bootloader file"), LOGINFO);
100 connect(this, SIGNAL(downloadDone()), this, SLOT(installStage2()));
101 downloadBlStart(m_blurl);
102 return true;
106 void BootloaderInstallImx::installStage2(void)
108 qDebug() << "[BootloaderInstallImx] patching file...";
109 emit logItem(tr("Patching file..."), LOGINFO);
110 m_tempfile.open();
112 // we have not detailed progress on the patching so just show a busy
113 // indicator instead.
114 emit logProgress(0, 0);
115 m_patchedFile.open();
116 m_thread = new BootloaderThreadImx();
117 m_thread->setInputFile(m_offile);
118 m_thread->setBootloaderFile(m_tempfile.fileName());
119 m_thread->setOutputFile(m_patchedFile.fileName());
120 m_tempfile.close();
121 m_patchedFile.close();
122 connect(m_thread, SIGNAL(finished()), this, SLOT(installStage3()));
123 connect(m_thread, SIGNAL(terminated()), this, SLOT(installStage3()));
124 m_thread->start();
128 void BootloaderInstallImx::installStage3(void)
130 enum imx_error_t err = m_thread->error();
131 emit logProgress(1, 1);
132 // if the patch failed
133 if (err != IMX_SUCCESS)
135 qDebug() << "[BootloaderInstallImx] Could not patch the original firmware file";
136 emit logItem(tr("Patching the original firmware failed"), LOGERROR);
137 emit done(true);
138 return;
141 qDebug() << "[BootloaderInstallImx] Original Firmware succesfully patched";
142 emit logItem(tr("Succesfully patched firmware file"), LOGINFO);
144 // if a bootloader is already present delete it.
145 QString fwfile(m_blfile);
146 if(QFileInfo(fwfile).isFile())
148 qDebug() << "[BootloaderInstallImx] deleting old target file";
149 QFile::remove(fwfile);
152 // place (new) bootloader. Copy, since the temporary file will be removed
153 // automatically.
154 qDebug() << "[BootloaderInstallImx] moving patched bootloader to" << fwfile;
155 if(m_patchedFile.copy(fwfile))
157 emit logItem(tr("Bootloader successful installed"), LOGOK);
158 logInstall(LogAdd);
159 emit done(false);
161 else
163 emit logItem(tr("Patched bootloader could not be installed"), LOGERROR);
164 emit done(true);
166 // clean up thread object.
167 delete m_thread;
168 return;
172 bool BootloaderInstallImx::uninstall(void)
174 emit logItem(tr("To uninstall, perform a normal upgrade with an unmodified "
175 "original firmware."), LOGINFO);
176 logInstall(LogRemove);
177 return false;
181 BootloaderInstallBase::BootloaderType BootloaderInstallImx::installed(void)
183 return BootloaderUnknown;
187 BootloaderInstallBase::Capabilities BootloaderInstallImx::capabilities(void)
189 return (Install | NeedsOf);