diff options
Diffstat (limited to 'rbutil/sansapatcher')
-rw-r--r-- | rbutil/sansapatcher/main.c | 37 | ||||
-rw-r--r-- | rbutil/sansapatcher/sansapatcher.c | 39 | ||||
-rw-r--r-- | rbutil/sansapatcher/sansapatcher.h | 16 |
3 files changed, 45 insertions, 47 deletions
diff --git a/rbutil/sansapatcher/main.c b/rbutil/sansapatcher/main.c index 07e44a044e..813e51c941 100644 --- a/rbutil/sansapatcher/main.c +++ b/rbutil/sansapatcher/main.c | |||
@@ -28,6 +28,7 @@ | |||
28 | 28 | ||
29 | #include "sansapatcher.h" | 29 | #include "sansapatcher.h" |
30 | #include "sansaio.h" | 30 | #include "sansaio.h" |
31 | #include "parttypes.h" | ||
31 | 32 | ||
32 | #define VERSION "0.1" | 33 | #define VERSION "0.1" |
33 | 34 | ||
@@ -83,6 +84,26 @@ void print_usage(void) | |||
83 | #endif | 84 | #endif |
84 | } | 85 | } |
85 | 86 | ||
87 | char* get_parttype(int pt) | ||
88 | { | ||
89 | int i; | ||
90 | static char unknown[]="Unknown"; | ||
91 | |||
92 | if (pt == -1) { | ||
93 | return "HFS/HFS+"; | ||
94 | } | ||
95 | |||
96 | i=0; | ||
97 | while (parttypes[i].name != NULL) { | ||
98 | if (parttypes[i].type == pt) { | ||
99 | return (parttypes[i].name); | ||
100 | } | ||
101 | i++; | ||
102 | } | ||
103 | |||
104 | return unknown; | ||
105 | } | ||
106 | |||
86 | void display_partinfo(struct sansa_t* sansa) | 107 | void display_partinfo(struct sansa_t* sansa) |
87 | { | 108 | { |
88 | int i; | 109 | int i; |
@@ -214,7 +235,7 @@ int main(int argc, char* argv[]) | |||
214 | fprintf(stderr,"[INFO] Reading partition table from %s\n",sansa.diskname); | 235 | fprintf(stderr,"[INFO] Reading partition table from %s\n",sansa.diskname); |
215 | fprintf(stderr,"[INFO] Sector size is %d bytes\n",sansa.sector_size); | 236 | fprintf(stderr,"[INFO] Sector size is %d bytes\n",sansa.sector_size); |
216 | 237 | ||
217 | if (read_partinfo(&sansa,0) < 0) { | 238 | if (sansa_read_partinfo(&sansa,0) < 0) { |
218 | return 2; | 239 | return 2; |
219 | } | 240 | } |
220 | 241 | ||
@@ -237,7 +258,7 @@ int main(int argc, char* argv[]) | |||
237 | } | 258 | } |
238 | 259 | ||
239 | if (action==LIST_IMAGES) { | 260 | if (action==LIST_IMAGES) { |
240 | list_images(&sansa); | 261 | sansa_list_images(&sansa); |
241 | } else if (action==INTERACTIVE) { | 262 | } else if (action==INTERACTIVE) { |
242 | 263 | ||
243 | printf("Enter i to install the Rockbox bootloader, u to uninstall\n or c to cancel and do nothing (i/u/c) :"); | 264 | printf("Enter i to install the Rockbox bootloader, u to uninstall\n or c to cancel and do nothing (i/u/c) :"); |
@@ -248,7 +269,7 @@ int main(int argc, char* argv[]) | |||
248 | return 5; | 269 | return 5; |
249 | } | 270 | } |
250 | 271 | ||
251 | if (add_bootloader(&sansa, NULL, FILETYPE_INTERNAL)==0) { | 272 | if (sansa_add_bootloader(&sansa, NULL, FILETYPE_INTERNAL)==0) { |
252 | fprintf(stderr,"[INFO] Bootloader installed successfully.\n"); | 273 | fprintf(stderr,"[INFO] Bootloader installed successfully.\n"); |
253 | } else { | 274 | } else { |
254 | fprintf(stderr,"[ERR] --install failed.\n"); | 275 | fprintf(stderr,"[ERR] --install failed.\n"); |
@@ -258,7 +279,7 @@ int main(int argc, char* argv[]) | |||
258 | return 5; | 279 | return 5; |
259 | } | 280 | } |
260 | 281 | ||
261 | if (delete_bootloader(&sansa)==0) { | 282 | if (sansa_delete_bootloader(&sansa)==0) { |
262 | fprintf(stderr,"[INFO] Bootloader removed.\n"); | 283 | fprintf(stderr,"[INFO] Bootloader removed.\n"); |
263 | } else { | 284 | } else { |
264 | fprintf(stderr,"[ERR] Bootloader removal failed.\n"); | 285 | fprintf(stderr,"[ERR] Bootloader removal failed.\n"); |
@@ -266,7 +287,7 @@ int main(int argc, char* argv[]) | |||
266 | } | 287 | } |
267 | } | 288 | } |
268 | } else if (action==READ_FIRMWARE) { | 289 | } else if (action==READ_FIRMWARE) { |
269 | if (read_firmware(&sansa, filename)==0) { | 290 | if (sansa_read_firmware(&sansa, filename)==0) { |
270 | fprintf(stderr,"[INFO] Firmware read to file %s.\n",filename); | 291 | fprintf(stderr,"[INFO] Firmware read to file %s.\n",filename); |
271 | } else { | 292 | } else { |
272 | fprintf(stderr,"[ERR] --read-firmware failed.\n"); | 293 | fprintf(stderr,"[ERR] --read-firmware failed.\n"); |
@@ -276,7 +297,7 @@ int main(int argc, char* argv[]) | |||
276 | return 5; | 297 | return 5; |
277 | } | 298 | } |
278 | 299 | ||
279 | if (add_bootloader(&sansa, NULL, FILETYPE_INTERNAL)==0) { | 300 | if (sansa_add_bootloader(&sansa, NULL, FILETYPE_INTERNAL)==0) { |
280 | fprintf(stderr,"[INFO] Bootloader installed successfully.\n"); | 301 | fprintf(stderr,"[INFO] Bootloader installed successfully.\n"); |
281 | } else { | 302 | } else { |
282 | fprintf(stderr,"[ERR] --install failed.\n"); | 303 | fprintf(stderr,"[ERR] --install failed.\n"); |
@@ -286,7 +307,7 @@ int main(int argc, char* argv[]) | |||
286 | return 5; | 307 | return 5; |
287 | } | 308 | } |
288 | 309 | ||
289 | if (add_bootloader(&sansa, filename, type)==0) { | 310 | if (sansa_add_bootloader(&sansa, filename, type)==0) { |
290 | fprintf(stderr,"[INFO] Bootloader %s written to device.\n",filename); | 311 | fprintf(stderr,"[INFO] Bootloader %s written to device.\n",filename); |
291 | } else { | 312 | } else { |
292 | fprintf(stderr,"[ERR] --add-bootloader failed.\n"); | 313 | fprintf(stderr,"[ERR] --add-bootloader failed.\n"); |
@@ -296,7 +317,7 @@ int main(int argc, char* argv[]) | |||
296 | return 5; | 317 | return 5; |
297 | } | 318 | } |
298 | 319 | ||
299 | if (delete_bootloader(&sansa)==0) { | 320 | if (sansa_delete_bootloader(&sansa)==0) { |
300 | fprintf(stderr,"[INFO] Bootloader removed successfully.\n"); | 321 | fprintf(stderr,"[INFO] Bootloader removed successfully.\n"); |
301 | } else { | 322 | } else { |
302 | fprintf(stderr,"[ERR] --delete-bootloader failed.\n"); | 323 | fprintf(stderr,"[ERR] --delete-bootloader failed.\n"); |
diff --git a/rbutil/sansapatcher/sansapatcher.c b/rbutil/sansapatcher/sansapatcher.c index aa13df00e5..55f5245bd9 100644 --- a/rbutil/sansapatcher/sansapatcher.c +++ b/rbutil/sansapatcher/sansapatcher.c | |||
@@ -26,7 +26,6 @@ | |||
26 | #include <sys/types.h> | 26 | #include <sys/types.h> |
27 | #include <sys/stat.h> | 27 | #include <sys/stat.h> |
28 | 28 | ||
29 | #include "parttypes.h" | ||
30 | #include "sansaio.h" | 29 | #include "sansaio.h" |
31 | #include "sansapatcher.h" | 30 | #include "sansapatcher.h" |
32 | #include "bootimg.h" | 31 | #include "bootimg.h" |
@@ -43,27 +42,7 @@ extern int verbose; | |||
43 | 42 | ||
44 | unsigned char* sectorbuf; | 43 | unsigned char* sectorbuf; |
45 | 44 | ||
46 | char* get_parttype(int pt) | 45 | static off_t filesize(int fd) { |
47 | { | ||
48 | int i; | ||
49 | static char unknown[]="Unknown"; | ||
50 | |||
51 | if (pt == -1) { | ||
52 | return "HFS/HFS+"; | ||
53 | } | ||
54 | |||
55 | i=0; | ||
56 | while (parttypes[i].name != NULL) { | ||
57 | if (parttypes[i].type == pt) { | ||
58 | return (parttypes[i].name); | ||
59 | } | ||
60 | i++; | ||
61 | } | ||
62 | |||
63 | return unknown; | ||
64 | } | ||
65 | |||
66 | off_t filesize(int fd) { | ||
67 | struct stat buf; | 46 | struct stat buf; |
68 | 47 | ||
69 | if (fstat(fd,&buf) < 0) { | 48 | if (fstat(fd,&buf) < 0) { |
@@ -134,7 +113,7 @@ void int2be(unsigned int val, unsigned char* addr) | |||
134 | ((long)array[pos] | ((long)array[pos+1] << 8 ) |\ | 113 | ((long)array[pos] | ((long)array[pos+1] << 8 ) |\ |
135 | ((long)array[pos+2] << 16 ) | ((long)array[pos+3] << 24 )) | 114 | ((long)array[pos+2] << 16 ) | ((long)array[pos+3] << 24 )) |
136 | 115 | ||
137 | int read_partinfo(struct sansa_t* sansa, int silent) | 116 | int sansa_read_partinfo(struct sansa_t* sansa, int silent) |
138 | { | 117 | { |
139 | int i; | 118 | int i; |
140 | unsigned long count; | 119 | unsigned long count; |
@@ -340,7 +319,7 @@ static int set_mi4header(unsigned char* buf,struct mi4header_t* mi4header) | |||
340 | return 0; | 319 | return 0; |
341 | } | 320 | } |
342 | 321 | ||
343 | int sansa_seek_and_read(struct sansa_t* sansa, loff_t pos, unsigned char* buf, int nbytes) | 322 | static int sansa_seek_and_read(struct sansa_t* sansa, loff_t pos, unsigned char* buf, int nbytes) |
344 | { | 323 | { |
345 | int n; | 324 | int n; |
346 | 325 | ||
@@ -450,7 +429,7 @@ int sansa_scan(struct sansa_t* sansa) | |||
450 | continue; | 429 | continue; |
451 | } | 430 | } |
452 | 431 | ||
453 | if (read_partinfo(sansa,1) < 0) { | 432 | if (sansa_read_partinfo(sansa,1) < 0) { |
454 | continue; | 433 | continue; |
455 | } | 434 | } |
456 | 435 | ||
@@ -475,7 +454,7 @@ int sansa_scan(struct sansa_t* sansa) | |||
475 | return n; | 454 | return n; |
476 | } | 455 | } |
477 | 456 | ||
478 | int load_original_firmware(struct sansa_t* sansa, unsigned char* buf, struct mi4header_t* mi4header) | 457 | static int load_original_firmware(struct sansa_t* sansa, unsigned char* buf, struct mi4header_t* mi4header) |
479 | { | 458 | { |
480 | int ppmi_length; | 459 | int ppmi_length; |
481 | int n; | 460 | int n; |
@@ -564,7 +543,7 @@ int load_original_firmware(struct sansa_t* sansa, unsigned char* buf, struct mi4 | |||
564 | return 0; | 543 | return 0; |
565 | } | 544 | } |
566 | 545 | ||
567 | int read_firmware(struct sansa_t* sansa, char* filename) | 546 | int sansa_read_firmware(struct sansa_t* sansa, char* filename) |
568 | { | 547 | { |
569 | int res; | 548 | int res; |
570 | int outfile; | 549 | int outfile; |
@@ -587,7 +566,7 @@ int read_firmware(struct sansa_t* sansa, char* filename) | |||
587 | } | 566 | } |
588 | 567 | ||
589 | 568 | ||
590 | int add_bootloader(struct sansa_t* sansa, char* filename, int type) | 569 | int sansa_add_bootloader(struct sansa_t* sansa, char* filename, int type) |
591 | { | 570 | { |
592 | int res; | 571 | int res; |
593 | int infile; | 572 | int infile; |
@@ -656,7 +635,7 @@ int add_bootloader(struct sansa_t* sansa, char* filename, int type) | |||
656 | return 0; | 635 | return 0; |
657 | } | 636 | } |
658 | 637 | ||
659 | int delete_bootloader(struct sansa_t* sansa) | 638 | int sansa_delete_bootloader(struct sansa_t* sansa) |
660 | { | 639 | { |
661 | int res; | 640 | int res; |
662 | struct mi4header_t mi4header; | 641 | struct mi4header_t mi4header; |
@@ -693,7 +672,7 @@ int delete_bootloader(struct sansa_t* sansa) | |||
693 | return 0; | 672 | return 0; |
694 | } | 673 | } |
695 | 674 | ||
696 | void list_images(struct sansa_t* sansa) | 675 | void sansa_list_images(struct sansa_t* sansa) |
697 | { | 676 | { |
698 | struct mi4header_t mi4header; | 677 | struct mi4header_t mi4header; |
699 | loff_t ppmi_length; | 678 | loff_t ppmi_length; |
diff --git a/rbutil/sansapatcher/sansapatcher.h b/rbutil/sansapatcher/sansapatcher.h index d422aa5932..a393a86576 100644 --- a/rbutil/sansapatcher/sansapatcher.h +++ b/rbutil/sansapatcher/sansapatcher.h | |||
@@ -17,8 +17,8 @@ | |||
17 | * | 17 | * |
18 | ****************************************************************************/ | 18 | ****************************************************************************/ |
19 | 19 | ||
20 | #ifndef _IPODPATCHER_H | 20 | #ifndef _SANSAPATCHER_H |
21 | #define _IPODPATCHER_H | 21 | #define _SANSAPATCHER_H |
22 | 22 | ||
23 | #include "sansaio.h" | 23 | #include "sansaio.h" |
24 | 24 | ||
@@ -30,14 +30,12 @@ extern unsigned char* sectorbuf; | |||
30 | #define FILETYPE_MI4 0 | 30 | #define FILETYPE_MI4 0 |
31 | #define FILETYPE_INTERNAL 1 | 31 | #define FILETYPE_INTERNAL 1 |
32 | 32 | ||
33 | char* get_parttype(int pt); | 33 | int sansa_read_partinfo(struct sansa_t* sansa, int silent); |
34 | int read_partinfo(struct sansa_t* sansa, int silent); | ||
35 | off_t filesize(int fd); | ||
36 | int is_e200(struct sansa_t* sansa); | 34 | int is_e200(struct sansa_t* sansa); |
37 | int sansa_scan(struct sansa_t* sansa); | 35 | int sansa_scan(struct sansa_t* sansa); |
38 | int read_firmware(struct sansa_t* sansa, char* filename); | 36 | int sansa_read_firmware(struct sansa_t* sansa, char* filename); |
39 | int add_bootloader(struct sansa_t* sansa, char* filename, int type); | 37 | int sansa_add_bootloader(struct sansa_t* sansa, char* filename, int type); |
40 | int delete_bootloader(struct sansa_t* sansa); | 38 | int sansa_delete_bootloader(struct sansa_t* sansa); |
41 | void list_images(struct sansa_t* sansa); | 39 | void sansa_list_images(struct sansa_t* sansa); |
42 | 40 | ||
43 | #endif | 41 | #endif |