Packard Bell Vibe 500: correct the path to a proper one in rbutil (proper directory...
[kugel-rb.git] / rbutil / rbutilqt / base / bootloaderinstallmi4.cpp
blob936ad175c3cce99d7695fc0c305dd25af2c2d6d8
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
9 * Copyright (C) 2008 by Dominik Riebeling
10 * $Id$
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 ****************************************************************************/
20 #include <QtCore>
21 #include <QtDebug>
22 #include <QtDebug>
23 #include "bootloaderinstallmi4.h"
24 #include "utils.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()));
38 return true;
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));
48 QFile oldbl(fwfile);
49 QString moved = QFileInfo(resolvePathCase(m_blfile)).absolutePath()
50 + "/OF.mi4";
51 if(!QFileInfo(moved).exists()) {
52 qDebug() << "[BootloaderInstallMi4] renaming" << fwfile << "to" << moved;
53 oldbl.rename(moved);
55 else {
56 qDebug() << "[BootloaderInstallMi4] OF.mi4 already present, not renaming again.";
57 oldbl.remove();
60 // place new bootloader
61 m_tempfile.open();
62 qDebug() << "[BootloaderInstallMi4] renaming" << m_tempfile.fileName() << "to" << fwfile;
63 m_tempfile.close();
64 m_tempfile.copy(fwfile);
66 emit logItem(tr("Bootloader successful installed"), LOGOK);
67 logInstall(LogAdd);
69 emit done(false);
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);
81 return false;
84 // check if OF file present
85 emit logItem(tr("Checking for original firmware file"), LOGINFO);
86 QString original = QFileInfo(resolvePathCase(m_blfile)).absolutePath()
87 + "/OF.mi4";
89 if(resolvePathCase(original).isEmpty()) {
90 emit logItem(tr("Error finding original firmware file"), LOGERROR);
91 return false;
94 // finally remove RB bootloader
95 QString resolved = resolvePathCase(m_blfile);
96 QFile blfile(resolved);
97 blfile.remove();
99 QFile::rename(resolvePathCase(original), m_blfile);
100 emit logItem(tr("Rockbox bootloader successful removed"), LOGINFO);
101 logInstall(LogRemove);
102 emit done(false);
104 return true;
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
112 // installed.
113 // RB bootloader has "RBBL" at 0x1f8 in the mi4 file.
115 // make sure to resolve case to prevent case issues
116 QString resolved;
117 resolved = resolvePathCase(m_blfile);
118 if(resolved.isEmpty()) {
119 qDebug() << "[BootloaderInstallMi4] installed: BootloaderNone";
120 return BootloaderNone;
123 QFile f(resolved);
124 f.open(QIODevice::ReadOnly);
125 f.seek(0x1f8);
126 char magic[4];
127 f.read(magic, 4);
128 f.close();
130 if(!memcmp(magic, "RBBL", 4)) {
131 qDebug() << "[BootloaderInstallMi4] installed: BootloaderRockbox";
132 return BootloaderRockbox;
134 else {
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;