Support "eject" on OS X.
[maemo-rb.git] / rbutil / rbutilqt / base / bootloaderinstallimx.cpp
blobc085b3034618464346518d04957d01ac728a9ff4
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;
52 opt.fw_variant = VARIANT_DEFAULT;
54 m_error = mkimxboot(m_inputfile.toLocal8Bit().constData(),
55 m_bootfile.toLocal8Bit().constData(),
56 m_outputfile.toLocal8Bit().constData(), opt);
57 qDebug() << "[BootloaderThreadImx] Thread finished, result:" << m_error;
61 BootloaderInstallImx::BootloaderInstallImx(QObject *parent)
62 : BootloaderInstallBase(parent)
64 m_thread = NULL;
68 QString BootloaderInstallImx::ofHint()
70 return tr("Bootloader installation requires you to provide "
71 "a copy of the original Sandisk firmware (firmware.sb file). "
72 "This file will be patched with the Rockbox bootloader and "
73 "installed to your player. You need to download this file "
74 "yourself due to legal reasons. Please browse the "
75 "<a href='http://forums.sandisk.com/sansa/'>Sansa Forums</a> "
76 "or refer to the "
77 "<a href= 'http://www.rockbox.org/wiki/SansaFuzePlus'>SansaFuzePlus</a> "
78 "wiki page on how to obtain this file.<br/>"
79 "Press Ok to continue and browse your computer for the firmware "
80 "file.");
84 /** Start bootloader installation.
86 bool BootloaderInstallImx::install(void)
88 if(!QFileInfo(m_offile).isReadable())
90 qDebug() << "[BootloaderInstallImx] could not read original firmware file"
91 << m_offile;
92 emit logItem(tr("Could not read original firmware file"), LOGERROR);
93 return false;
96 qDebug() << "[BootloaderInstallImx] downloading bootloader";
97 // download bootloader from server
98 emit logItem(tr("Downloading bootloader file"), LOGINFO);
99 connect(this, SIGNAL(downloadDone()), this, SLOT(installStage2()));
100 downloadBlStart(m_blurl);
101 return true;
105 void BootloaderInstallImx::installStage2(void)
107 qDebug() << "[BootloaderInstallImx] patching file...";
108 emit logItem(tr("Patching file..."), LOGINFO);
109 m_tempfile.open();
111 // we have not detailed progress on the patching so just show a busy
112 // indicator instead.
113 emit logProgress(0, 0);
114 m_patchedFile.open();
115 m_thread = new BootloaderThreadImx();
116 m_thread->setInputFile(m_offile);
117 m_thread->setBootloaderFile(m_tempfile.fileName());
118 m_thread->setOutputFile(m_patchedFile.fileName());
119 m_tempfile.close();
120 m_patchedFile.close();
121 connect(m_thread, SIGNAL(finished()), this, SLOT(installStage3()));
122 connect(m_thread, SIGNAL(terminated()), this, SLOT(installStage3()));
123 m_thread->start();
127 void BootloaderInstallImx::installStage3(void)
129 enum imx_error_t err = m_thread->error();
130 emit logProgress(1, 1);
131 // if the patch failed
132 if (err != IMX_SUCCESS)
134 qDebug() << "[BootloaderInstallImx] Could not patch the original firmware file";
135 emit logItem(tr("Patching the original firmware failed"), LOGERROR);
136 emit done(true);
137 return;
140 qDebug() << "[BootloaderInstallImx] Original Firmware succesfully patched";
141 emit logItem(tr("Succesfully patched firmware file"), LOGINFO);
143 // if a bootloader is already present delete it.
144 QString fwfile(m_blfile);
145 if(QFileInfo(fwfile).isFile())
147 qDebug() << "[BootloaderInstallImx] deleting old target file";
148 QFile::remove(fwfile);
151 // place (new) bootloader. Copy, since the temporary file will be removed
152 // automatically.
153 qDebug() << "[BootloaderInstallImx] moving patched bootloader to" << fwfile;
154 if(m_patchedFile.copy(fwfile))
156 emit logItem(tr("Bootloader successful installed"), LOGOK);
157 logInstall(LogAdd);
158 emit done(false);
160 else
162 emit logItem(tr("Patched bootloader could not be installed"), LOGERROR);
163 emit done(true);
165 // clean up thread object.
166 delete m_thread;
167 return;
171 bool BootloaderInstallImx::uninstall(void)
173 emit logItem(tr("To uninstall, perform a normal upgrade with an unmodified "
174 "original firmware."), LOGINFO);
175 logInstall(LogRemove);
176 return false;
180 BootloaderInstallBase::BootloaderType BootloaderInstallImx::installed(void)
182 return BootloaderUnknown;
186 BootloaderInstallBase::Capabilities BootloaderInstallImx::capabilities(void)
188 return (Install | NeedsOf);