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
;
50 memset(&opt
, 0, sizeof(opt
));
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
)
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> "
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 "
85 /** Start bootloader installation.
87 bool BootloaderInstallImx::install(void)
89 if(!QFileInfo(m_offile
).isReadable())
91 qDebug() << "[BootloaderInstallImx] could not read original firmware file"
93 emit
logItem(tr("Could not read original firmware file"), LOGERROR
);
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
);
106 void BootloaderInstallImx::installStage2(void)
108 qDebug() << "[BootloaderInstallImx] patching file...";
109 emit
logItem(tr("Patching file..."), LOGINFO
);
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());
121 m_patchedFile
.close();
122 connect(m_thread
, SIGNAL(finished()), this, SLOT(installStage3()));
123 connect(m_thread
, SIGNAL(terminated()), this, SLOT(installStage3()));
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
);
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
154 qDebug() << "[BootloaderInstallImx] moving patched bootloader to" << fwfile
;
155 if(m_patchedFile
.copy(fwfile
))
157 emit
logItem(tr("Bootloader successful installed"), LOGOK
);
163 emit
logItem(tr("Patched bootloader could not be installed"), LOGERROR
);
166 // clean up thread object.
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
);
181 BootloaderInstallBase::BootloaderType
BootloaderInstallImx::installed(void)
183 return BootloaderUnknown
;
187 BootloaderInstallBase::Capabilities
BootloaderInstallImx::capabilities(void)
189 return (Install
| NeedsOf
);