diff options
Diffstat (limited to 'rbutil/sansapatcher/main.c')
-rw-r--r-- | rbutil/sansapatcher/main.c | 53 |
1 files changed, 37 insertions, 16 deletions
diff --git a/rbutil/sansapatcher/main.c b/rbutil/sansapatcher/main.c index 0828095bae..07e44a044e 100644 --- a/rbutil/sansapatcher/main.c +++ b/rbutil/sansapatcher/main.c | |||
@@ -35,9 +35,7 @@ int verbose = 0; | |||
35 | 35 | ||
36 | enum { | 36 | enum { |
37 | NONE, | 37 | NONE, |
38 | #ifdef WITH_BOOTOBJS | ||
39 | INSTALL, | 38 | INSTALL, |
40 | #endif | ||
41 | INTERACTIVE, | 39 | INTERACTIVE, |
42 | SHOW_INFO, | 40 | SHOW_INFO, |
43 | LIST_IMAGES, | 41 | LIST_IMAGES, |
@@ -59,9 +57,7 @@ void print_usage(void) | |||
59 | #endif | 57 | #endif |
60 | fprintf(stderr,"\n"); | 58 | fprintf(stderr,"\n"); |
61 | fprintf(stderr,"Where [action] is one of the following options:\n"); | 59 | fprintf(stderr,"Where [action] is one of the following options:\n"); |
62 | #ifdef WITH_BOOTOBJS | ||
63 | fprintf(stderr," --install\n"); | 60 | fprintf(stderr," --install\n"); |
64 | #endif | ||
65 | fprintf(stderr," -l, --list\n"); | 61 | fprintf(stderr," -l, --list\n"); |
66 | fprintf(stderr," -rf, --read-firmware filename.mi4\n"); | 62 | fprintf(stderr," -rf, --read-firmware filename.mi4\n"); |
67 | fprintf(stderr," -a, --add-bootloader filename.mi4\n"); | 63 | fprintf(stderr," -a, --add-bootloader filename.mi4\n"); |
@@ -109,9 +105,7 @@ void display_partinfo(struct sansa_t* sansa) | |||
109 | 105 | ||
110 | int main(int argc, char* argv[]) | 106 | int main(int argc, char* argv[]) |
111 | { | 107 | { |
112 | #ifdef WITH_BOOTOBJS | ||
113 | char yesno[4]; | 108 | char yesno[4]; |
114 | #endif | ||
115 | int i; | 109 | int i; |
116 | int n; | 110 | int n; |
117 | char* filename; | 111 | char* filename; |
@@ -167,33 +161,25 @@ int main(int argc, char* argv[]) | |||
167 | } | 161 | } |
168 | 162 | ||
169 | if (n != 1) { | 163 | if (n != 1) { |
170 | #ifdef WITH_BOOTOBJS | ||
171 | if (argc==1) { | 164 | if (argc==1) { |
172 | printf("\nPress ENTER to exit sansapatcher :"); | 165 | printf("\nPress ENTER to exit sansapatcher :"); |
173 | fgets(yesno,4,stdin); | 166 | fgets(yesno,4,stdin); |
174 | } | 167 | } |
175 | #endif | ||
176 | return 0; | 168 | return 0; |
177 | } | 169 | } |
178 | 170 | ||
179 | i = 1; | 171 | i = 1; |
180 | } | 172 | } |
181 | 173 | ||
182 | #ifdef WITH_BOOTOBJS | ||
183 | action = INTERACTIVE; | 174 | action = INTERACTIVE; |
184 | #else | ||
185 | action = NONE; | ||
186 | #endif | ||
187 | 175 | ||
188 | while (i < argc) { | 176 | while (i < argc) { |
189 | if ((strcmp(argv[i],"-l")==0) || (strcmp(argv[i],"--list")==0)) { | 177 | if ((strcmp(argv[i],"-l")==0) || (strcmp(argv[i],"--list")==0)) { |
190 | action = LIST_IMAGES; | 178 | action = LIST_IMAGES; |
191 | i++; | 179 | i++; |
192 | #ifdef WITH_BOOTOBJS | ||
193 | } else if (strcmp(argv[i],"--install")==0) { | 180 | } else if (strcmp(argv[i],"--install")==0) { |
194 | action = INSTALL; | 181 | action = INSTALL; |
195 | i++; | 182 | i++; |
196 | #endif | ||
197 | } else if ((strcmp(argv[i],"-d")==0) || | 183 | } else if ((strcmp(argv[i],"-d")==0) || |
198 | (strcmp(argv[i],"--delete-bootloader")==0)) { | 184 | (strcmp(argv[i],"--delete-bootloader")==0)) { |
199 | action = DELETE_BOOTLOADER; | 185 | action = DELETE_BOOTLOADER; |
@@ -252,12 +238,49 @@ int main(int argc, char* argv[]) | |||
252 | 238 | ||
253 | if (action==LIST_IMAGES) { | 239 | if (action==LIST_IMAGES) { |
254 | list_images(&sansa); | 240 | list_images(&sansa); |
241 | } else if (action==INTERACTIVE) { | ||
242 | |||
243 | printf("Enter i to install the Rockbox bootloader, u to uninstall\n or c to cancel and do nothing (i/u/c) :"); | ||
244 | |||
245 | if (fgets(yesno,4,stdin)) { | ||
246 | if (yesno[0]=='i') { | ||
247 | if (sansa_reopen_rw(&sansa) < 0) { | ||
248 | return 5; | ||
249 | } | ||
250 | |||
251 | if (add_bootloader(&sansa, NULL, FILETYPE_INTERNAL)==0) { | ||
252 | fprintf(stderr,"[INFO] Bootloader installed successfully.\n"); | ||
253 | } else { | ||
254 | fprintf(stderr,"[ERR] --install failed.\n"); | ||
255 | } | ||
256 | } else if (yesno[0]=='u') { | ||
257 | if (sansa_reopen_rw(&sansa) < 0) { | ||
258 | return 5; | ||
259 | } | ||
260 | |||
261 | if (delete_bootloader(&sansa)==0) { | ||
262 | fprintf(stderr,"[INFO] Bootloader removed.\n"); | ||
263 | } else { | ||
264 | fprintf(stderr,"[ERR] Bootloader removal failed.\n"); | ||
265 | } | ||
266 | } | ||
267 | } | ||
255 | } else if (action==READ_FIRMWARE) { | 268 | } else if (action==READ_FIRMWARE) { |
256 | if (read_firmware(&sansa, filename)==0) { | 269 | if (read_firmware(&sansa, filename)==0) { |
257 | fprintf(stderr,"[INFO] Firmware read to file %s.\n",filename); | 270 | fprintf(stderr,"[INFO] Firmware read to file %s.\n",filename); |
258 | } else { | 271 | } else { |
259 | fprintf(stderr,"[ERR] --read-firmware failed.\n"); | 272 | fprintf(stderr,"[ERR] --read-firmware failed.\n"); |
260 | } | 273 | } |
274 | } else if (action==INSTALL) { | ||
275 | if (sansa_reopen_rw(&sansa) < 0) { | ||
276 | return 5; | ||
277 | } | ||
278 | |||
279 | if (add_bootloader(&sansa, NULL, FILETYPE_INTERNAL)==0) { | ||
280 | fprintf(stderr,"[INFO] Bootloader installed successfully.\n"); | ||
281 | } else { | ||
282 | fprintf(stderr,"[ERR] --install failed.\n"); | ||
283 | } | ||
261 | } else if (action==ADD_BOOTLOADER) { | 284 | } else if (action==ADD_BOOTLOADER) { |
262 | if (sansa_reopen_rw(&sansa) < 0) { | 285 | if (sansa_reopen_rw(&sansa) < 0) { |
263 | return 5; | 286 | return 5; |
@@ -282,12 +305,10 @@ int main(int argc, char* argv[]) | |||
282 | 305 | ||
283 | sansa_close(&sansa); | 306 | sansa_close(&sansa); |
284 | 307 | ||
285 | #ifdef WITH_BOOTOBJS | ||
286 | if (action==INTERACTIVE) { | 308 | if (action==INTERACTIVE) { |
287 | printf("Press ENTER to exit sansapatcher :"); | 309 | printf("Press ENTER to exit sansapatcher :"); |
288 | fgets(yesno,4,stdin); | 310 | fgets(yesno,4,stdin); |
289 | } | 311 | } |
290 | #endif | ||
291 | 312 | ||
292 | return 0; | 313 | return 0; |
293 | } | 314 | } |