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
);
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
);
45 // move old bootloader out of the way
46 QString
fwfile(resolvePathCase(m_blfile
));
48 QString moved
= QFileInfo(resolvePathCase(m_blfile
)).absolutePath()
50 qDebug() << "renaming" << fwfile
<< "->" << moved
;
53 // place new bootloader
55 qDebug() << "renaming" << m_tempfile
.fileName() << "->" << fwfile
;
57 m_tempfile
.rename(fwfile
);
59 emit
logItem(tr("Bootloader successful installed"), LOGOK
);
66 bool BootloaderInstallMi4::uninstall(void)
70 // check if it's actually a Rockbox bootloader
71 emit
logItem(tr("Checking for Rockbox bootloader"), LOGINFO
);
72 if(installed() != BootloaderRockbox
) {
73 emit
logItem(tr("No Rockbox bootloader found"), LOGERROR
);
77 // check if OF file present
78 emit
logItem(tr("Checking for original firmware file"), LOGINFO
);
79 QString original
= QFileInfo(resolvePathCase(m_blfile
)).absolutePath()
82 if(resolvePathCase(original
).isEmpty()) {
83 emit
logItem(tr("Error finding original firmware file"), LOGERROR
);
87 // finally remove RB bootloader
88 QString resolved
= resolvePathCase(m_blfile
);
89 QFile
blfile(resolved
);
92 QFile
oldbl(resolvePathCase(original
));
93 oldbl
.rename(m_blfile
);
94 emit
logItem(tr("Rockbox bootloader successful removed"), LOGINFO
);
95 logInstall(LogRemove
);
102 //! check if a bootloader is installed and return its state.
103 BootloaderInstallBase::BootloaderType
BootloaderInstallMi4::installed(void)
105 // for MI4 files we can check if we actually have a RB bootloader
107 // RB bootloader has "RBBL" at 0x1f8 in the mi4 file.
109 // make sure to resolve case to prevent case issues
111 resolved
= resolvePathCase(m_blfile
);
112 if(resolved
.isEmpty()) {
113 qDebug("%s: BootloaderNone", __func__
);
114 return BootloaderNone
;
118 f
.open(QIODevice::ReadOnly
);
124 if(!memcmp(magic
, "RBBL", 4)) {
125 qDebug("%s: BootloaderRockbox", __func__
);
126 return BootloaderRockbox
;
129 qDebug("%s: BootloaderOther", __func__
);
130 return BootloaderOther
;
135 BootloaderInstallBase::Capabilities
BootloaderInstallMi4::capabilities(void)
137 qDebug() << __func__
;
138 return Install
| Uninstall
| Backup
| IsFile
| CanCheckInstalled
| CanCheckVersion
;