2008-09-28 17:02:36 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* __________ __ ___.
|
|
|
|
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
|
|
|
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
|
|
|
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
|
|
|
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
|
|
|
* \/ \/ \/ \/ \/
|
|
|
|
*
|
|
|
|
* Copyright (C) 2008 by Dominik Riebeling
|
|
|
|
*
|
|
|
|
* All files in this archive are subject to the GNU General Public License.
|
|
|
|
* See the file COPYING in the source tree root for full license agreement.
|
|
|
|
*
|
|
|
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
|
|
|
* KIND, either express or implied.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include <QtCore>
|
|
|
|
#include <QtDebug>
|
|
|
|
#include <QtDebug>
|
|
|
|
#include "bootloaderinstallmi4.h"
|
|
|
|
#include "utils.h"
|
|
|
|
|
|
|
|
BootloaderInstallMi4::BootloaderInstallMi4(QObject *parent)
|
|
|
|
: BootloaderInstallBase(parent)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool BootloaderInstallMi4::install(void)
|
|
|
|
{
|
|
|
|
emit logItem(tr("Downloading bootloader"), LOGINFO);
|
2009-08-09 10:57:33 +00:00
|
|
|
qDebug() << "[BootloaderInstallMi4] installing bootloader";
|
2008-09-28 17:02:36 +00:00
|
|
|
downloadBlStart(m_blurl);
|
|
|
|
connect(this, SIGNAL(downloadDone()), this, SLOT(installStage2()));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void BootloaderInstallMi4::installStage2(void)
|
|
|
|
{
|
|
|
|
emit logItem(tr("Installing Rockbox bootloader"), LOGINFO);
|
2009-01-08 17:16:53 +00:00
|
|
|
QCoreApplication::processEvents();
|
2008-09-28 17:02:36 +00:00
|
|
|
|
|
|
|
// move old bootloader out of the way
|
2010-04-02 21:24:19 +00:00
|
|
|
QString fwfile(Utils::resolvePathCase(m_blfile));
|
2008-09-28 17:02:36 +00:00
|
|
|
QFile oldbl(fwfile);
|
2010-04-02 21:24:19 +00:00
|
|
|
QString moved = QFileInfo(Utils::resolvePathCase(m_blfile)).absolutePath()
|
2008-09-28 17:02:36 +00:00
|
|
|
+ "/OF.mi4";
|
2008-12-18 21:16:47 +00:00
|
|
|
if(!QFileInfo(moved).exists()) {
|
2009-08-09 10:57:33 +00:00
|
|
|
qDebug() << "[BootloaderInstallMi4] renaming" << fwfile << "to" << moved;
|
2008-12-18 21:16:47 +00:00
|
|
|
oldbl.rename(moved);
|
|
|
|
}
|
|
|
|
else {
|
2009-08-09 10:57:33 +00:00
|
|
|
qDebug() << "[BootloaderInstallMi4] OF.mi4 already present, not renaming again.";
|
2008-12-18 21:16:47 +00:00
|
|
|
oldbl.remove();
|
|
|
|
}
|
2008-09-28 17:02:36 +00:00
|
|
|
|
|
|
|
// place new bootloader
|
|
|
|
m_tempfile.open();
|
2012-04-26 20:01:33 +00:00
|
|
|
qDebug() << "[BootloaderInstallMi4] renaming" << m_tempfile.fileName()
|
|
|
|
<< "to" << fwfile;
|
2008-09-28 17:02:36 +00:00
|
|
|
m_tempfile.close();
|
2012-04-26 20:01:33 +00:00
|
|
|
if(!Utils::resolvePathCase(fwfile).isEmpty()) {
|
|
|
|
emit logItem(tr("A firmware file is already present on player"), LOGERROR);
|
|
|
|
emit done(true);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if(m_tempfile.copy(fwfile)) {
|
|
|
|
emit logItem(tr("Bootloader successful installed"), LOGOK);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
emit logItem(tr("Copying modified firmware file failed"), LOGERROR);
|
|
|
|
emit done(true);
|
|
|
|
return;
|
|
|
|
}
|
2008-09-28 17:02:36 +00:00
|
|
|
|
|
|
|
emit logItem(tr("Bootloader successful installed"), LOGOK);
|
|
|
|
logInstall(LogAdd);
|
|
|
|
|
2008-12-18 21:16:47 +00:00
|
|
|
emit done(false);
|
2008-09-28 17:02:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool BootloaderInstallMi4::uninstall(void)
|
|
|
|
{
|
2009-08-09 10:57:33 +00:00
|
|
|
qDebug() << "[BootloaderInstallMi4] Uninstalling bootloader";
|
2008-09-28 17:02:36 +00:00
|
|
|
|
|
|
|
// check if it's actually a Rockbox bootloader
|
|
|
|
emit logItem(tr("Checking for Rockbox bootloader"), LOGINFO);
|
|
|
|
if(installed() != BootloaderRockbox) {
|
|
|
|
emit logItem(tr("No Rockbox bootloader found"), LOGERROR);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// check if OF file present
|
|
|
|
emit logItem(tr("Checking for original firmware file"), LOGINFO);
|
2010-04-02 21:24:19 +00:00
|
|
|
QString original = QFileInfo(Utils::resolvePathCase(m_blfile)).absolutePath()
|
2008-09-28 17:02:36 +00:00
|
|
|
+ "/OF.mi4";
|
|
|
|
|
2010-04-02 21:24:19 +00:00
|
|
|
if(Utils::resolvePathCase(original).isEmpty()) {
|
2008-09-28 17:02:36 +00:00
|
|
|
emit logItem(tr("Error finding original firmware file"), LOGERROR);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// finally remove RB bootloader
|
2010-04-02 21:24:19 +00:00
|
|
|
QString resolved = Utils::resolvePathCase(m_blfile);
|
2008-09-28 17:02:36 +00:00
|
|
|
QFile blfile(resolved);
|
|
|
|
blfile.remove();
|
|
|
|
|
2010-04-02 21:24:19 +00:00
|
|
|
QFile::rename(Utils::resolvePathCase(original), m_blfile);
|
2008-09-28 17:02:36 +00:00
|
|
|
emit logItem(tr("Rockbox bootloader successful removed"), LOGINFO);
|
|
|
|
logInstall(LogRemove);
|
|
|
|
emit done(false);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//! check if a bootloader is installed and return its state.
|
|
|
|
BootloaderInstallBase::BootloaderType BootloaderInstallMi4::installed(void)
|
|
|
|
{
|
|
|
|
// for MI4 files we can check if we actually have a RB bootloader
|
|
|
|
// installed.
|
|
|
|
// RB bootloader has "RBBL" at 0x1f8 in the mi4 file.
|
|
|
|
|
|
|
|
// make sure to resolve case to prevent case issues
|
|
|
|
QString resolved;
|
2010-04-02 21:24:19 +00:00
|
|
|
resolved = Utils::resolvePathCase(m_blfile);
|
2008-09-28 17:02:36 +00:00
|
|
|
if(resolved.isEmpty()) {
|
2009-08-09 10:57:33 +00:00
|
|
|
qDebug() << "[BootloaderInstallMi4] installed: BootloaderNone";
|
2008-09-28 17:02:36 +00:00
|
|
|
return BootloaderNone;
|
|
|
|
}
|
|
|
|
|
|
|
|
QFile f(resolved);
|
|
|
|
f.open(QIODevice::ReadOnly);
|
|
|
|
f.seek(0x1f8);
|
|
|
|
char magic[4];
|
|
|
|
f.read(magic, 4);
|
|
|
|
f.close();
|
|
|
|
|
|
|
|
if(!memcmp(magic, "RBBL", 4)) {
|
2009-08-09 10:57:33 +00:00
|
|
|
qDebug() << "[BootloaderInstallMi4] installed: BootloaderRockbox";
|
2008-09-28 17:02:36 +00:00
|
|
|
return BootloaderRockbox;
|
|
|
|
}
|
|
|
|
else {
|
2009-08-09 10:57:33 +00:00
|
|
|
qDebug() << "[BootloaderInstallMi4] installed: BootloaderOther";
|
2008-09-28 17:02:36 +00:00
|
|
|
return BootloaderOther;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
BootloaderInstallBase::Capabilities BootloaderInstallMi4::capabilities(void)
|
|
|
|
{
|
2009-08-09 10:57:33 +00:00
|
|
|
qDebug() << "[BootloaderInstallMi4] getting capabilities";
|
2008-09-28 17:02:36 +00:00
|
|
|
return Install | Uninstall | Backup | IsFile | CanCheckInstalled | CanCheckVersion;
|
|
|
|
}
|
|
|
|
|