summaryrefslogtreecommitdiff
path: root/utils/rbutilqt/base/bootloaderinstallmi4.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'utils/rbutilqt/base/bootloaderinstallmi4.cpp')
-rw-r--r--utils/rbutilqt/base/bootloaderinstallmi4.cpp162
1 files changed, 162 insertions, 0 deletions
diff --git a/utils/rbutilqt/base/bootloaderinstallmi4.cpp b/utils/rbutilqt/base/bootloaderinstallmi4.cpp
new file mode 100644
index 0000000000..2657347b87
--- /dev/null
+++ b/utils/rbutilqt/base/bootloaderinstallmi4.cpp
@@ -0,0 +1,162 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 *
9 * Copyright (C) 2008 by Dominik Riebeling
10 *
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.
13 *
14 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
15 * KIND, either express or implied.
16 *
17 ****************************************************************************/
18
19#include <QtCore>
20#include <QtDebug>
21#include <QtDebug>
22#include "bootloaderinstallmi4.h"
23#include "utils.h"
24#include "Logger.h"
25
26BootloaderInstallMi4::BootloaderInstallMi4(QObject *parent)
27 : BootloaderInstallBase(parent)
28{
29}
30
31
32bool BootloaderInstallMi4::install(void)
33{
34 emit logItem(tr("Downloading bootloader"), LOGINFO);
35 LOG_INFO() << "installing bootloader";
36 downloadBlStart(m_blurl);
37 connect(this, &BootloaderInstallBase::downloadDone, this, &BootloaderInstallMi4::installStage2);
38 return true;
39}
40
41void BootloaderInstallMi4::installStage2(void)
42{
43 emit logItem(tr("Installing Rockbox bootloader"), LOGINFO);
44 QCoreApplication::processEvents();
45
46 // move old bootloader out of the way
47 QString fwfile(Utils::resolvePathCase(m_blfile));
48 QFile oldbl(fwfile);
49 QString moved = QFileInfo(Utils::resolvePathCase(m_blfile)).absolutePath()
50 + "/OF.mi4";
51 if(!QFileInfo::exists(moved)) {
52 LOG_INFO() << "renaming" << fwfile << "to" << moved;
53 oldbl.rename(moved);
54 }
55 else {
56 LOG_INFO() << "OF.mi4 already present, not renaming again.";
57 oldbl.remove();
58 }
59
60 // place new bootloader
61 m_tempfile.open();
62 LOG_INFO() << "renaming" << m_tempfile.fileName()
63 << "to" << fwfile;
64 m_tempfile.close();
65 if(!Utils::resolvePathCase(fwfile).isEmpty()) {
66 emit logItem(tr("A firmware file is already present on player"), LOGERROR);
67 emit done(true);
68 return;
69 }
70 if(m_tempfile.copy(fwfile)) {
71 emit logItem(tr("Bootloader successful installed"), LOGOK);
72 }
73 else {
74 emit logItem(tr("Copying modified firmware file failed"), LOGERROR);
75 emit done(true);
76 return;
77 }
78
79 emit logItem(tr("Bootloader successful installed"), LOGOK);
80 logInstall(LogAdd);
81
82 emit done(false);
83}
84
85
86bool BootloaderInstallMi4::uninstall(void)
87{
88 LOG_INFO() << "Uninstalling bootloader";
89
90 // check if it's actually a Rockbox bootloader
91 emit logItem(tr("Checking for Rockbox bootloader"), LOGINFO);
92 if(installed() != BootloaderRockbox) {
93 emit logItem(tr("No Rockbox bootloader found"), LOGERROR);
94 emit done(true);
95 return false;
96 }
97
98 // check if OF file present
99 emit logItem(tr("Checking for original firmware file"), LOGINFO);
100 QString original = QFileInfo(Utils::resolvePathCase(m_blfile)).absolutePath()
101 + "/OF.mi4";
102
103 if(Utils::resolvePathCase(original).isEmpty()) {
104 emit logItem(tr("Error finding original firmware file"), LOGERROR);
105 emit done(true);
106 return false;
107 }
108
109 // finally remove RB bootloader
110 QString resolved = Utils::resolvePathCase(m_blfile);
111 QFile blfile(resolved);
112 blfile.remove();
113
114 QFile::rename(Utils::resolvePathCase(original), resolved);
115 emit logItem(tr("Rockbox bootloader successful removed"), LOGINFO);
116 logInstall(LogRemove);
117 emit logProgress(1, 1);
118 emit done(false);
119
120 return true;
121}
122
123
124//! check if a bootloader is installed and return its state.
125BootloaderInstallBase::BootloaderType BootloaderInstallMi4::installed(void)
126{
127 // for MI4 files we can check if we actually have a RB bootloader
128 // installed.
129 // RB bootloader has "RBBL" at 0x1f8 in the mi4 file.
130
131 // make sure to resolve case to prevent case issues
132 QString resolved;
133 resolved = Utils::resolvePathCase(m_blfile);
134 if(resolved.isEmpty()) {
135 LOG_INFO() << "installed: BootloaderNone";
136 return BootloaderNone;
137 }
138
139 QFile f(resolved);
140 f.open(QIODevice::ReadOnly);
141 f.seek(0x1f8);
142 char magic[4];
143 f.read(magic, 4);
144 f.close();
145
146 if(!memcmp(magic, "RBBL", 4)) {
147 LOG_INFO() << "installed: BootloaderRockbox";
148 return BootloaderRockbox;
149 }
150 else {
151 LOG_INFO() << "installed: BootloaderOther";
152 return BootloaderOther;
153 }
154}
155
156
157BootloaderInstallBase::Capabilities BootloaderInstallMi4::capabilities(void)
158{
159 LOG_INFO() << "getting capabilities";
160 return Install | Uninstall | Backup | IsFile | CanCheckInstalled | CanCheckVersion;
161}
162