1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
9 * Copyright (C) 2008 by Dominik Riebeling
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 ****************************************************************************/
22 #include "bootloaderinstallmi4.h"
25 BootloaderInstallMi4::BootloaderInstallMi4(QObject
*parent
)
26 : BootloaderInstallBase(parent
)
31 bool BootloaderInstallMi4::install(void)
33 emit
logItem(tr("Downloading bootloader"), LOGINFO
);
34 qDebug() << "[BootloaderInstallMi4] installing bootloader";
35 downloadBlStart(m_blurl
);
36 connect(this, SIGNAL(downloadDone()), this, SLOT(installStage2()));
40 void BootloaderInstallMi4::installStage2(void)
42 emit
logItem(tr("Installing Rockbox bootloader"), LOGINFO
);
43 QCoreApplication::processEvents();
45 // move old bootloader out of the way
46 QString
fwfile(Utils::resolvePathCase(m_blfile
));
48 QString moved
= QFileInfo(Utils::resolvePathCase(m_blfile
)).absolutePath()
50 if(!QFileInfo(moved
).exists()) {
51 qDebug() << "[BootloaderInstallMi4] renaming" << fwfile
<< "to" << moved
;
55 qDebug() << "[BootloaderInstallMi4] OF.mi4 already present, not renaming again.";
59 // place new bootloader
61 qDebug() << "[BootloaderInstallMi4] renaming" << m_tempfile
.fileName() << "to" << fwfile
;
63 m_tempfile
.copy(fwfile
);
65 emit
logItem(tr("Bootloader successful installed"), LOGOK
);
72 bool BootloaderInstallMi4::uninstall(void)
74 qDebug() << "[BootloaderInstallMi4] Uninstalling bootloader";
76 // check if it's actually a Rockbox bootloader
77 emit
logItem(tr("Checking for Rockbox bootloader"), LOGINFO
);
78 if(installed() != BootloaderRockbox
) {
79 emit
logItem(tr("No Rockbox bootloader found"), LOGERROR
);
83 // check if OF file present
84 emit
logItem(tr("Checking for original firmware file"), LOGINFO
);
85 QString original
= QFileInfo(Utils::resolvePathCase(m_blfile
)).absolutePath()
88 if(Utils::resolvePathCase(original
).isEmpty()) {
89 emit
logItem(tr("Error finding original firmware file"), LOGERROR
);
93 // finally remove RB bootloader
94 QString resolved
= Utils::resolvePathCase(m_blfile
);
95 QFile
blfile(resolved
);
98 QFile::rename(Utils::resolvePathCase(original
), m_blfile
);
99 emit
logItem(tr("Rockbox bootloader successful removed"), LOGINFO
);
100 logInstall(LogRemove
);
107 //! check if a bootloader is installed and return its state.
108 BootloaderInstallBase::BootloaderType
BootloaderInstallMi4::installed(void)
110 // for MI4 files we can check if we actually have a RB bootloader
112 // RB bootloader has "RBBL" at 0x1f8 in the mi4 file.
114 // make sure to resolve case to prevent case issues
116 resolved
= Utils::resolvePathCase(m_blfile
);
117 if(resolved
.isEmpty()) {
118 qDebug() << "[BootloaderInstallMi4] installed: BootloaderNone";
119 return BootloaderNone
;
123 f
.open(QIODevice::ReadOnly
);
129 if(!memcmp(magic
, "RBBL", 4)) {
130 qDebug() << "[BootloaderInstallMi4] installed: BootloaderRockbox";
131 return BootloaderRockbox
;
134 qDebug() << "[BootloaderInstallMi4] installed: BootloaderOther";
135 return BootloaderOther
;
140 BootloaderInstallBase::Capabilities
BootloaderInstallMi4::capabilities(void)
142 qDebug() << "[BootloaderInstallMi4] getting capabilities";
143 return Install
| Uninstall
| Backup
| IsFile
| CanCheckInstalled
| CanCheckVersion
;