diff options
author | Solomon Peachy <pizza@shaftnet.org> | 2020-07-19 17:13:55 -0400 |
---|---|---|
committer | Solomon Peachy <pizza@shaftnet.org> | 2020-07-20 18:40:24 +0000 |
commit | f6060d62d90c6920bd6edf9ed618f41b9cf7b60f (patch) | |
tree | f0aa84fe8428d2bca0f75a266d3795770cf43aed /rbutil/rbutilqt/base | |
parent | 561937f2f4bbd38493408a99593c1bccbe36eb48 (diff) | |
download | rockbox-f6060d62d90c6920bd6edf9ed618f41b9cf7b60f.tar.gz rockbox-f6060d62d90c6920bd6edf9ed618f41b9cf7b60f.zip |
rbutil: Add support for the xDuoo X3, X3ii, X20, and AGPTek Rocker.
* All include full bootloader installation!
* X20 lack USB VID/PIDs so cannot be autodetected.
* Benjie T6 (variant/OEM of the Rocker) USB VID/PID unknown.
Change-Id: Ia823de072c83506d36410ec436be15a0caf97151
Diffstat (limited to 'rbutil/rbutilqt/base')
-rw-r--r-- | rbutil/rbutilqt/base/bootloaderinstallbspatch.cpp | 179 | ||||
-rw-r--r-- | rbutil/rbutilqt/base/bootloaderinstallbspatch.h | 47 | ||||
-rw-r--r-- | rbutil/rbutilqt/base/bootloaderinstallhelper.cpp | 6 |
3 files changed, 230 insertions, 2 deletions
diff --git a/rbutil/rbutilqt/base/bootloaderinstallbspatch.cpp b/rbutil/rbutilqt/base/bootloaderinstallbspatch.cpp new file mode 100644 index 0000000000..c9cbd91abe --- /dev/null +++ b/rbutil/rbutilqt/base/bootloaderinstallbspatch.cpp | |||
@@ -0,0 +1,179 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * | ||
9 | * Copyright (C) 2020 by Solomon Peachy | ||
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 "bootloaderinstallbase.h" | ||
22 | #include "bootloaderinstallbspatch.h" | ||
23 | #include "../bspatch/bspatch.h" | ||
24 | #include "Logger.h" | ||
25 | |||
26 | /* class for running bspatch() in a separate thread to keep the UI responsive. */ | ||
27 | class BootloaderThreadBSPatch : public QThread | ||
28 | { | ||
29 | public: | ||
30 | void run(void); | ||
31 | void setInputFile(QString f) | ||
32 | { m_inputfile = f; } | ||
33 | void setOutputFile(QString f) | ||
34 | { m_outputfile = f; } | ||
35 | void setBootloaderFile(QString f) | ||
36 | { m_bootfile = f; } | ||
37 | int error(void) | ||
38 | { return m_error; } | ||
39 | private: | ||
40 | QString m_inputfile; | ||
41 | QString m_bootfile; | ||
42 | QString m_outputfile; | ||
43 | int m_error; | ||
44 | }; | ||
45 | |||
46 | void BootloaderThreadBSPatch::run(void) | ||
47 | { | ||
48 | LOG_INFO() << "Thread started."; | ||
49 | |||
50 | m_error = apply_bspatch(m_inputfile.toLocal8Bit().constData(), | ||
51 | m_outputfile.toLocal8Bit().constData(), | ||
52 | m_bootfile.toLocal8Bit().constData()); | ||
53 | |||
54 | LOG_INFO() << "Thread finished, result:" << m_error; | ||
55 | } | ||
56 | |||
57 | BootloaderInstallBSPatch::BootloaderInstallBSPatch(QObject *parent) | ||
58 | : BootloaderInstallBase(parent) | ||
59 | { | ||
60 | m_thread = NULL; | ||
61 | } | ||
62 | |||
63 | QString BootloaderInstallBSPatch::ofHint() | ||
64 | { | ||
65 | return tr("Bootloader installation requires you to provide " | ||
66 | "the correct verrsion of the original firmware file. " | ||
67 | "This file will be patched with the Rockbox bootloader and " | ||
68 | "installed to your player. You need to download this file " | ||
69 | "yourself due to legal reasons. Please refer to the " | ||
70 | "<a href='http://www.rockbox.org/wiki/'>rockbox wiki</a> " | ||
71 | "pages on how to obtain this file.<br/>" | ||
72 | "Press Ok to continue and browse your computer for the firmware " | ||
73 | "file."); | ||
74 | } | ||
75 | |||
76 | /** Start bootloader installation. | ||
77 | */ | ||
78 | bool BootloaderInstallBSPatch::install(void) | ||
79 | { | ||
80 | if(!QFileInfo(m_offile).isReadable()) | ||
81 | { | ||
82 | LOG_ERROR() << "could not read original firmware file" | ||
83 | << m_offile; | ||
84 | emit logItem(tr("Could not read original firmware file"), LOGERROR); | ||
85 | return false; | ||
86 | } | ||
87 | |||
88 | LOG_INFO() << "downloading bootloader"; | ||
89 | // download bootloader from server | ||
90 | emit logItem(tr("Downloading bootloader file"), LOGINFO); | ||
91 | connect(this, SIGNAL(downloadDone()), this, SLOT(installStage2())); | ||
92 | downloadBlStart(m_blurl); | ||
93 | return true; | ||
94 | } | ||
95 | |||
96 | void BootloaderInstallBSPatch::installStage2(void) | ||
97 | { | ||
98 | LOG_INFO() << "patching file..."; | ||
99 | emit logItem(tr("Patching file..."), LOGINFO); | ||
100 | m_tempfile.open(); | ||
101 | |||
102 | // we have not detailed progress on the patching so just show a busy | ||
103 | // indicator instead. | ||
104 | emit logProgress(0, 0); | ||
105 | m_patchedFile.open(); | ||
106 | m_thread = new BootloaderThreadBSPatch(); | ||
107 | m_thread->setInputFile(m_offile); | ||
108 | m_thread->setBootloaderFile(m_tempfile.fileName()); | ||
109 | m_thread->setOutputFile(m_patchedFile.fileName()); | ||
110 | m_tempfile.close(); | ||
111 | m_patchedFile.close(); | ||
112 | connect(m_thread, SIGNAL(finished()), this, SLOT(installStage3())); | ||
113 | connect(m_thread, SIGNAL(terminated()), this, SLOT(installStage3())); | ||
114 | m_thread->start(); | ||
115 | } | ||
116 | |||
117 | void BootloaderInstallBSPatch::installStage3(void) | ||
118 | { | ||
119 | int err = m_thread->error(); | ||
120 | emit logProgress(1, 1); | ||
121 | // if the patch failed | ||
122 | if (err != 0) | ||
123 | { | ||
124 | LOG_ERROR() << "Could not patch the original firmware file"; | ||
125 | emit logItem(tr("Patching the original firmware failed"), LOGERROR); | ||
126 | emit done(true); | ||
127 | return; | ||
128 | } | ||
129 | |||
130 | LOG_INFO() << "Original Firmware succesfully patched"; | ||
131 | emit logItem(tr("Succesfully patched firmware file"), LOGINFO); | ||
132 | |||
133 | // if a bootloader is already present delete it. | ||
134 | QString fwfile(m_blfile); | ||
135 | if(QFileInfo(fwfile).isFile()) | ||
136 | { | ||
137 | LOG_INFO() << "deleting old target file"; | ||
138 | QFile::remove(fwfile); | ||
139 | } | ||
140 | |||
141 | // place (new) bootloader. Copy, since the temporary file will be removed | ||
142 | // automatically. | ||
143 | LOG_INFO() << "moving patched bootloader to" << fwfile; | ||
144 | if(m_patchedFile.copy(fwfile)) | ||
145 | { | ||
146 | emit logItem(tr("Bootloader successful installed"), LOGOK); | ||
147 | logInstall(LogAdd); | ||
148 | emit done(false); | ||
149 | } | ||
150 | else | ||
151 | { | ||
152 | emit logItem(tr("Patched bootloader could not be installed"), LOGERROR); | ||
153 | emit done(true); | ||
154 | } | ||
155 | // clean up thread object. | ||
156 | delete m_thread; | ||
157 | return; | ||
158 | } | ||
159 | |||
160 | bool BootloaderInstallBSPatch::uninstall(void) | ||
161 | { | ||
162 | emit logItem(tr("To uninstall, perform a normal upgrade with an unmodified " | ||
163 | "original firmware."), LOGINFO); | ||
164 | logInstall(LogRemove); | ||
165 | emit done(true); | ||
166 | return false; | ||
167 | } | ||
168 | |||
169 | |||
170 | BootloaderInstallBase::BootloaderType BootloaderInstallBSPatch::installed(void) | ||
171 | { | ||
172 | return BootloaderUnknown; | ||
173 | } | ||
174 | |||
175 | |||
176 | BootloaderInstallBase::Capabilities BootloaderInstallBSPatch::capabilities(void) | ||
177 | { | ||
178 | return (Install | NeedsOf); | ||
179 | } | ||
diff --git a/rbutil/rbutilqt/base/bootloaderinstallbspatch.h b/rbutil/rbutilqt/base/bootloaderinstallbspatch.h new file mode 100644 index 0000000000..7108820fda --- /dev/null +++ b/rbutil/rbutilqt/base/bootloaderinstallbspatch.h | |||
@@ -0,0 +1,47 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * | ||
9 | * Copyright (C) 2020 Solomon Peachy | ||
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 | #ifndef BOOTLOADERINSTALLBSPATCH_H | ||
19 | #define BOOTLOADERINSTALLBSPATCH_H | ||
20 | |||
21 | #include <QtCore> | ||
22 | #include "bootloaderinstallbase.h" | ||
23 | |||
24 | class BootloaderThreadBSPatch; | ||
25 | |||
26 | //! bootloader installation class for devices handled by mkimxboot. | ||
27 | class BootloaderInstallBSPatch : public BootloaderInstallBase | ||
28 | { | ||
29 | Q_OBJECT | ||
30 | public: | ||
31 | BootloaderInstallBSPatch(QObject *parent); | ||
32 | bool install(void); | ||
33 | bool uninstall(void); | ||
34 | BootloaderInstallBase::BootloaderType installed(void); | ||
35 | Capabilities capabilities(void); | ||
36 | QString ofHint(); | ||
37 | |||
38 | private slots: | ||
39 | void installStage2(void); | ||
40 | void installStage3(void); | ||
41 | |||
42 | private: | ||
43 | BootloaderThreadBSPatch *m_thread; | ||
44 | QTemporaryFile m_patchedFile; | ||
45 | }; | ||
46 | |||
47 | #endif | ||
diff --git a/rbutil/rbutilqt/base/bootloaderinstallhelper.cpp b/rbutil/rbutilqt/base/bootloaderinstallhelper.cpp index d6d2dbc7a1..d7d7ace5e9 100644 --- a/rbutil/rbutilqt/base/bootloaderinstallhelper.cpp +++ b/rbutil/rbutilqt/base/bootloaderinstallhelper.cpp | |||
@@ -32,6 +32,7 @@ | |||
32 | #include "bootloaderinstallmpio.h" | 32 | #include "bootloaderinstallmpio.h" |
33 | #include "bootloaderinstallimx.h" | 33 | #include "bootloaderinstallimx.h" |
34 | #include "bootloaderinstalls5l.h" | 34 | #include "bootloaderinstalls5l.h" |
35 | #include "bootloaderinstallbspatch.h" | ||
35 | 36 | ||
36 | BootloaderInstallBase* BootloaderInstallHelper::createBootloaderInstaller(QObject* parent, QString type) | 37 | BootloaderInstallBase* BootloaderInstallHelper::createBootloaderInstaller(QObject* parent, QString type) |
37 | { | 38 | { |
@@ -68,10 +69,12 @@ BootloaderInstallBase* BootloaderInstallHelper::createBootloaderInstaller(QObjec | |||
68 | else if(type == "s5l") { | 69 | else if(type == "s5l") { |
69 | return new BootloaderInstallS5l(parent); | 70 | return new BootloaderInstallS5l(parent); |
70 | } | 71 | } |
72 | else if(type == "bspatch") { | ||
73 | return new BootloaderInstallBSPatch(parent); | ||
74 | } | ||
71 | else { | 75 | else { |
72 | return NULL; | 76 | return NULL; |
73 | } | 77 | } |
74 | |||
75 | } | 78 | } |
76 | 79 | ||
77 | 80 | ||
@@ -134,4 +137,3 @@ QString BootloaderInstallHelper::postinstallHints(QString model) | |||
134 | else | 137 | else |
135 | return QString(); | 138 | return QString(); |
136 | } | 139 | } |
137 | |||