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(resolvePathCase(m_blfile
));
49 QString moved
= QFileInfo(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
.rename(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(resolvePathCase(m_blfile
)).absolutePath()
89 if(resolvePathCase(original
).isEmpty()) {
90 emit
logItem(tr("Error finding original firmware file"), LOGERROR
);
94 // finally remove RB bootloader
95 QString resolved
= resolvePathCase(m_blfile
);
96 QFile
blfile(resolved
);
99 QFile
oldbl(resolvePathCase(original
));
100 oldbl
.rename(m_blfile
);
101 emit
logItem(tr("Rockbox bootloader successful removed"), LOGINFO
);
102 logInstall(LogRemove
);
109 //! check if a bootloader is installed and return its state.
110 BootloaderInstallBase::BootloaderType
BootloaderInstallMi4::installed(void)
112 // for MI4 files we can check if we actually have a RB bootloader
114 // RB bootloader has "RBBL" at 0x1f8 in the mi4 file.
116 // make sure to resolve case to prevent case issues
118 resolved
= resolvePathCase(m_blfile
);
119 if(resolved
.isEmpty()) {
120 qDebug() << "[BootloaderInstallMi4] installed: BootloaderNone";
121 return BootloaderNone
;
125 f
.open(QIODevice::ReadOnly
);
131 if(!memcmp(magic
, "RBBL", 4)) {
132 qDebug() << "[BootloaderInstallMi4] installed: BootloaderRockbox";
133 return BootloaderRockbox
;
136 qDebug() << "[BootloaderInstallMi4] installed: BootloaderOther";
137 return BootloaderOther
;
142 BootloaderInstallBase::Capabilities
BootloaderInstallMi4::capabilities(void)
144 qDebug() << "[BootloaderInstallMi4] getting capabilities";
145 return Install
| Uninstall
| Backup
| IsFile
| CanCheckInstalled
| CanCheckVersion
;