summaryrefslogtreecommitdiff
path: root/rbutil/rbutilqt/bootloaderinstallsansa.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'rbutil/rbutilqt/bootloaderinstallsansa.cpp')
-rw-r--r--rbutil/rbutilqt/bootloaderinstallsansa.cpp244
1 files changed, 244 insertions, 0 deletions
diff --git a/rbutil/rbutilqt/bootloaderinstallsansa.cpp b/rbutil/rbutilqt/bootloaderinstallsansa.cpp
new file mode 100644
index 0000000000..170cfd5905
--- /dev/null
+++ b/rbutil/rbutilqt/bootloaderinstallsansa.cpp
@@ -0,0 +1,244 @@
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 "bootloaderinstallbase.h"
22#include "bootloaderinstallsansa.h"
23
24#include "../sansapatcher/sansapatcher.h"
25
26BootloaderInstallSansa::BootloaderInstallSansa(QObject *parent)
27 : BootloaderInstallBase(parent)
28{
29 (void)parent;
30 // initialize sector buffer. sansa_sectorbuf is instantiated by
31 // sansapatcher.
32 sansa_sectorbuf = NULL;
33 sansa_alloc_buffer(&sansa_sectorbuf, BUFFER_SIZE);
34}
35
36
37BootloaderInstallSansa::~BootloaderInstallSansa()
38{
39 free(sansa_sectorbuf);
40}
41
42
43/** Start bootloader installation.
44 */
45bool BootloaderInstallSansa::install(void)
46{
47 if(sansa_sectorbuf == NULL) {
48 emit logItem(tr("Error: can't allocate buffer memory!"), LOGERROR);
49 return false;
50 emit done(true);
51 }
52
53 emit logItem(tr("Searching for Sansa"), LOGINFO);
54
55 struct sansa_t sansa;
56
57 int n = sansa_scan(&sansa);
58 if(n == -1) {
59 emit logItem(tr("Permission for disc access denied!\n"
60 "This is required to install the bootloader"),
61 LOGERROR);
62 emit done(true);
63 return false;
64 }
65 if(n == 0) {
66 emit logItem(tr("No Sansa detected!"), LOGERROR);
67 emit done(true);
68 return false;
69 }
70 emit logItem(tr("Downloading bootloader file"), LOGINFO);
71
72 downloadBlStart(m_blurl);
73 connect(this, SIGNAL(downloadDone()), this, SLOT(installStage2()));
74 return true;
75}
76
77
78/** Finish bootloader installation.
79 */
80void BootloaderInstallSansa::installStage2(void)
81{
82 struct sansa_t sansa;
83 sansa_scan(&sansa);
84
85 if(sansa_open(&sansa, 0) < 0) {
86 emit logItem(tr("could not open Sansa"), LOGERROR);
87 emit done(true);
88 return;
89 }
90
91 if(sansa_read_partinfo(&sansa, 0) < 0)
92 {
93 emit logItem(tr("could not read partitiontable"), LOGERROR);
94 emit done(true);
95 return;
96 }
97
98 int i = is_sansa(&sansa);
99 if(i < 0) {
100
101 emit logItem(tr("Disk is not a Sansa (Error: %1), aborting.").arg(i), LOGERROR);
102 emit done(true);
103 return;
104 }
105
106 if(sansa.hasoldbootloader) {
107 emit logItem(tr("OLD ROCKBOX INSTALLATION DETECTED, ABORTING.\n"
108 "You must reinstall the original Sansa firmware before running\n"
109 "sansapatcher for the first time.\n"
110 "See http://www.rockbox.org/wiki/SansaE200Install\n"),
111 LOGERROR);
112 emit done(true);
113 return;
114 }
115
116 if(sansa_reopen_rw(&sansa) < 0) {
117 emit logItem(tr("Could not open Sansa in R/W mode"), LOGERROR);
118 emit done(true);
119 return;
120 }
121
122 m_tempfile.open();
123 QString blfile = m_tempfile.fileName();
124 m_tempfile.close();
125 if(sansa_add_bootloader(&sansa, blfile.toLatin1().data(),
126 FILETYPE_MI4) == 0) {
127 emit logItem(tr("Successfully installed bootloader"), LOGOK);
128 logInstall(LogAdd);
129 emit done(false);
130 sansa_close(&sansa);
131 return;
132 }
133 else {
134 emit logItem(tr("Failed to install bootloader"), LOGERROR);
135 sansa_close(&sansa);
136 emit done(true);
137 return;
138 }
139
140}
141
142
143/** Uninstall the bootloader.
144 */
145bool BootloaderInstallSansa::uninstall(void)
146{
147 struct sansa_t sansa;
148
149 if(sansa_scan(&sansa) != 1) {
150 emit logItem(tr("Can't find Sansa"), LOGERROR);
151 emit done(true);
152 return false;
153 }
154
155 if (sansa_open(&sansa, 0) < 0) {
156 emit logItem(tr("Could not open Sansa"), LOGERROR);
157 emit done(true);
158 return false;
159 }
160
161 if (sansa_read_partinfo(&sansa,0) < 0) {
162 emit logItem(tr("Could not read partition table"), LOGERROR);
163 emit done(true);
164 return false;
165 }
166
167 int i = is_sansa(&sansa);
168 if(i < 0) {
169 emit logItem(tr("Disk is not a Sansa (Error %1), aborting.").arg(i), LOGERROR);
170 emit done(true);
171 return false;
172 }
173
174 if (sansa.hasoldbootloader) {
175 emit logItem(tr("OLD ROCKBOX INSTALLATION DETECTED, ABORTING.\n"
176 "You must reinstall the original Sansa firmware before running\n"
177 "sansapatcher for the first time.\n"
178 "See http://www.rockbox.org/wiki/SansaE200Install\n"),
179 LOGERROR);
180 emit done(true);
181 return false;
182 }
183
184 if (sansa_reopen_rw(&sansa) < 0) {
185 emit logItem(tr("Could not open Sansa in R/W mode"), LOGERROR);
186 emit done(true);
187 return false;
188 }
189
190 if (sansa_delete_bootloader(&sansa)==0) {
191 emit logItem(tr("Successfully removed bootloader"), LOGOK);
192 logInstall(LogRemove);
193 emit done(false);
194 sansa_close(&sansa);
195 return true;
196 }
197 else {
198 emit logItem(tr("Removing bootloader failed."),LOGERROR);
199 emit done(true);
200 sansa_close(&sansa);
201 return false;
202 }
203
204 return false;
205}
206
207
208/** Check if bootloader is already installed
209 */
210BootloaderInstallBase::BootloaderType BootloaderInstallSansa::installed(void)
211{
212 struct sansa_t sansa;
213 int num;
214
215 if(sansa_scan(&sansa) != 1) {
216 return BootloaderUnknown;
217 }
218 if (sansa_open(&sansa, 0) < 0) {
219 return BootloaderUnknown;
220 }
221 if (sansa_read_partinfo(&sansa,0) < 0) {
222 return BootloaderUnknown;
223 }
224 if(is_sansa(&sansa) < 0) {
225 return BootloaderUnknown;
226 }
227 if((num = sansa_list_images(&sansa)) == 2) {
228 return BootloaderRockbox;
229 }
230 else if(num == 1) {
231 return BootloaderOther;
232 }
233 return BootloaderUnknown;
234
235}
236
237
238/** Get capabilities of subclass installer.
239 */
240BootloaderInstallBase::Capabilities BootloaderInstallSansa::capabilities(void)
241{
242 return (Install | Uninstall | IsRaw | CanCheckInstalled);
243}
244