diff options
author | Dominik Riebeling <Dominik.Riebeling@gmail.com> | 2021-12-15 21:04:28 +0100 |
---|---|---|
committer | Dominik Riebeling <Dominik.Riebeling@gmail.com> | 2021-12-24 18:05:53 +0100 |
commit | c876d3bbefe0dc00c27ca0c12d29da5874946962 (patch) | |
tree | 69f468a185a369b01998314bc3ecc19b70f4fcaa /utils/rbutilqt/base/bootloaderinstallmi4.cpp | |
parent | 6c6f0757d7a902feb293be165d1490c42bc8e7ad (diff) | |
download | rockbox-c876d3bbefe0dc00c27ca0c12d29da5874946962.tar.gz rockbox-c876d3bbefe0dc00c27ca0c12d29da5874946962.zip |
rbutil: Merge rbutil with utils folder.
rbutil uses several components from the utils folder, and can be
considered part of utils too. Having it in a separate folder is an
arbitrary split that doesn't help anymore these days, so merge them.
This also allows other utils to easily use libtools.make without the
need to navigate to a different folder.
Change-Id: I3fc2f4de19e3e776553efb5dea5f779dfec0dc21
Diffstat (limited to 'utils/rbutilqt/base/bootloaderinstallmi4.cpp')
-rw-r--r-- | utils/rbutilqt/base/bootloaderinstallmi4.cpp | 162 |
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 | |||
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 | LOG_INFO() << "installing bootloader"; | ||
36 | downloadBlStart(m_blurl); | ||
37 | connect(this, &BootloaderInstallBase::downloadDone, this, &BootloaderInstallMi4::installStage2); | ||
38 | return true; | ||
39 | } | ||
40 | |||
41 | void 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 | |||
86 | bool 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. | ||
125 | BootloaderInstallBase::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 | |||
157 | BootloaderInstallBase::Capabilities BootloaderInstallMi4::capabilities(void) | ||
158 | { | ||
159 | LOG_INFO() << "getting capabilities"; | ||
160 | return Install | Uninstall | Backup | IsFile | CanCheckInstalled | CanCheckVersion; | ||
161 | } | ||
162 | |||