1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
9 * Copyright (C) 2008 by Dominik Riebeling
12 * All files in this archive are subject to the GNU General Public License.
13 * See the file COPYING in the source tree root for full license agreement.
15 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
16 * KIND, either express or implied.
18 ****************************************************************************/
23 #include "bootloaderinstallmi4.h"
26 BootloaderInstallMi4::BootloaderInstallMi4(QObject
*parent
)
27 : BootloaderInstallBase(parent
)
32 bool BootloaderInstallMi4::install(void)
34 emit
logItem(tr("Downloading bootloader"), LOGINFO
);
35 qDebug() << "[BootloaderInstallMi4] installing bootloader";
36 downloadBlStart(m_blurl
);
37 connect(this, SIGNAL(downloadDone()), this, SLOT(installStage2()));
41 void BootloaderInstallMi4::installStage2(void)
43 emit
logItem(tr("Installing Rockbox bootloader"), LOGINFO
);
44 QCoreApplication::processEvents();
46 // move old bootloader out of the way
47 QString
fwfile(Utils::resolvePathCase(m_blfile
));
49 QString moved
= QFileInfo(Utils::resolvePathCase(m_blfile
)).absolutePath()
51 if(!QFileInfo(moved
).exists()) {
52 qDebug() << "[BootloaderInstallMi4] renaming" << fwfile
<< "to" << moved
;
56 qDebug() << "[BootloaderInstallMi4] OF.mi4 already present, not renaming again.";
60 // place new bootloader
62 qDebug() << "[BootloaderInstallMi4] renaming" << m_tempfile
.fileName() << "to" << fwfile
;
64 m_tempfile
.copy(fwfile
);
66 emit
logItem(tr("Bootloader successful installed"), LOGOK
);
73 bool BootloaderInstallMi4::uninstall(void)
75 qDebug() << "[BootloaderInstallMi4] Uninstalling bootloader";
77 // check if it's actually a Rockbox bootloader
78 emit
logItem(tr("Checking for Rockbox bootloader"), LOGINFO
);
79 if(installed() != BootloaderRockbox
) {
80 emit
logItem(tr("No Rockbox bootloader found"), LOGERROR
);
84 // check if OF file present
85 emit
logItem(tr("Checking for original firmware file"), LOGINFO
);
86 QString original
= QFileInfo(Utils::resolvePathCase(m_blfile
)).absolutePath()
89 if(Utils::resolvePathCase(original
).isEmpty()) {
90 emit
logItem(tr("Error finding original firmware file"), LOGERROR
);
94 // finally remove RB bootloader
95 QString resolved
= Utils::resolvePathCase(m_blfile
);
96 QFile
blfile(resolved
);
99 QFile::rename(Utils::resolvePathCase(original
), m_blfile
);
100 emit
logItem(tr("Rockbox bootloader successful removed"), LOGINFO
);
101 logInstall(LogRemove
);
108 //! check if a bootloader is installed and return its state.
109 BootloaderInstallBase::BootloaderType
BootloaderInstallMi4::installed(void)
111 // for MI4 files we can check if we actually have a RB bootloader
113 // RB bootloader has "RBBL" at 0x1f8 in the mi4 file.
115 // make sure to resolve case to prevent case issues
117 resolved
= Utils::resolvePathCase(m_blfile
);
118 if(resolved
.isEmpty()) {
119 qDebug() << "[BootloaderInstallMi4] installed: BootloaderNone";
120 return BootloaderNone
;
124 f
.open(QIODevice::ReadOnly
);
130 if(!memcmp(magic
, "RBBL", 4)) {
131 qDebug() << "[BootloaderInstallMi4] installed: BootloaderRockbox";
132 return BootloaderRockbox
;
135 qDebug() << "[BootloaderInstallMi4] installed: BootloaderOther";
136 return BootloaderOther
;
141 BootloaderInstallBase::Capabilities
BootloaderInstallMi4::capabilities(void)
143 qDebug() << "[BootloaderInstallMi4] getting capabilities";
144 return Install
| Uninstall
| Backup
| IsFile
| CanCheckInstalled
| CanCheckVersion
;