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