1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
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 ****************************************************************************/
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
30 void setInputFile(QString f
)
32 void setOutputFile(QString f
)
34 void setBootloaderFile(QString f
)
36 enum imx_error_t
error(void)
42 enum imx_error_t m_error
;
46 void BootloaderThreadImx::run(void)
48 qDebug() << "[BootloaderThreadImx] Thread started.";
49 struct imx_option_t opt
;
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
)
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> "
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 "
84 /** Start bootloader installation.
86 bool BootloaderInstallImx::install(void)
88 if(!QFileInfo(m_offile
).isReadable())
90 qDebug() << "[BootloaderInstallImx] could not read original firmware file"
92 emit
logItem(tr("Could not read original firmware file"), LOGERROR
);
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
);
105 void BootloaderInstallImx::installStage2(void)
107 qDebug() << "[BootloaderInstallImx] patching file...";
108 emit
logItem(tr("Patching file..."), LOGINFO
);
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());
120 m_patchedFile
.close();
121 connect(m_thread
, SIGNAL(finished()), this, SLOT(installStage3()));
122 connect(m_thread
, SIGNAL(terminated()), this, SLOT(installStage3()));
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
);
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
153 qDebug() << "[BootloaderInstallImx] moving patched bootloader to" << fwfile
;
154 if(m_patchedFile
.copy(fwfile
))
156 emit
logItem(tr("Bootloader successful installed"), LOGOK
);
162 emit
logItem(tr("Patched bootloader could not be installed"), LOGERROR
);
165 // clean up thread object.
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
);
180 BootloaderInstallBase::BootloaderType
BootloaderInstallImx::installed(void)
182 return BootloaderUnknown
;
186 BootloaderInstallBase::Capabilities
BootloaderInstallImx::capabilities(void)
188 return (Install
| NeedsOf
);