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
;
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
)
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> "
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 "
83 /** Start bootloader installation.
85 bool BootloaderInstallImx::install(void)
87 if(!QFileInfo(m_offile
).isReadable())
89 qDebug() << "[BootloaderInstallImx] could not read original firmware file"
91 emit
logItem(tr("Could not read original firmware file"), LOGERROR
);
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
);
104 void BootloaderInstallImx::installStage2(void)
106 qDebug() << "[BootloaderInstallImx] patching file...";
107 emit
logItem(tr("Patching file..."), LOGINFO
);
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());
119 m_patchedFile
.close();
120 connect(m_thread
, SIGNAL(finished()), this, SLOT(installStage3()));
121 connect(m_thread
, SIGNAL(terminated()), this, SLOT(installStage3()));
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
);
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
152 qDebug() << "[BootloaderInstallImx] moving patched bootloader to" << fwfile
;
153 if(m_patchedFile
.copy(fwfile
))
155 emit
logItem(tr("Bootloader successful installed"), LOGOK
);
161 emit
logItem(tr("Patched bootloader could not be installed"), LOGERROR
);
164 // clean up thread object.
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
);
179 BootloaderInstallBase::BootloaderType
BootloaderInstallImx::installed(void)
181 return BootloaderUnknown
;
185 BootloaderInstallBase::Capabilities
BootloaderInstallImx::capabilities(void)
187 return (Install
| NeedsOf
);