diff options
author | Dave Chapman <dave@dchapman.com> | 2006-07-22 13:21:50 +0000 |
---|---|---|
committer | Dave Chapman <dave@dchapman.com> | 2006-07-22 13:21:50 +0000 |
commit | 3ba16cbed03809faf33f61bd4ce150618133a226 (patch) | |
tree | bae304dcff34df17f1d862f36fb30c4e79ac8d1f | |
parent | 792f64e64eaddb55d94c43aa5f44e738b6c7614b (diff) | |
download | rockbox-3ba16cbed03809faf33f61bd4ce150618133a226.tar.gz rockbox-3ba16cbed03809faf33f61bd4ce150618133a226.zip |
Add support for ipod 5g firmware partitions and untested support for ipod 3g
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@10282 a1c6a512-1295-4272-9138-f99709370657
-rw-r--r-- | tools/scramble.c | 57 |
1 files changed, 49 insertions, 8 deletions
diff --git a/tools/scramble.c b/tools/scramble.c index 8e104cc43c..c91c05d6ee 100644 --- a/tools/scramble.c +++ b/tools/scramble.c | |||
@@ -19,11 +19,12 @@ | |||
19 | 19 | ||
20 | #include <stdio.h> | 20 | #include <stdio.h> |
21 | #include <stdlib.h> | 21 | #include <stdlib.h> |
22 | #include <stdbool.h> | ||
22 | #include <string.h> | 23 | #include <string.h> |
23 | #include "iriver.h" | 24 | #include "iriver.h" |
24 | 25 | ||
25 | int iaudio_encode(char *iname, char *oname, char *idstring); | 26 | int iaudio_encode(char *iname, char *oname, char *idstring); |
26 | int ipod_encode(char *iname, char *oname, int fw_ver); | 27 | int ipod_encode(char *iname, char *oname, int fw_ver, bool fake_rsrc); |
27 | 28 | ||
28 | enum | 29 | enum |
29 | { | 30 | { |
@@ -78,6 +79,9 @@ void usage(void) | |||
78 | "\t-iriver iRiver format\n" | 79 | "\t-iriver iRiver format\n" |
79 | "\t-iaudiox5 iAudio X5 format\n" | 80 | "\t-iaudiox5 iAudio X5 format\n" |
80 | "\t-iaudiox5v iAudio X5V format\n" | 81 | "\t-iaudiox5v iAudio X5V format\n" |
82 | "\t-ipod3g ipod firmware partition format (3rd Gen)\n" | ||
83 | "\t-ipod4g ipod firmware partition format (4th Gen, Mini, Nano, Photo/Color)\n" | ||
84 | "\t-ipod5g ipod firmware partition format (5th Gen - aka Video)\n" | ||
81 | "\t-add=X Rockbox generic \"add-up\" checksum format\n" | 85 | "\t-add=X Rockbox generic \"add-up\" checksum format\n" |
82 | "\t (X values: h100, h120, h140, h300, ipco, nano, ipvd\n" | 86 | "\t (X values: h100, h120, h140, h300, ipco, nano, ipvd\n" |
83 | "\t ip3g, ip4g, mini, x5)\n" | 87 | "\t ip3g, ip4g, mini, x5)\n" |
@@ -218,10 +222,20 @@ int main (int argc, char** argv) | |||
218 | oname = argv[3]; | 222 | oname = argv[3]; |
219 | return iaudio_encode(iname, oname, "COWON_X5V_FW"); | 223 | return iaudio_encode(iname, oname, "COWON_X5V_FW"); |
220 | } | 224 | } |
221 | else if(!strcmp(argv[1], "-ipod")) { | 225 | else if(!strcmp(argv[1], "-ipod3g")) { |
222 | iname = argv[2]; | 226 | iname = argv[2]; |
223 | oname = argv[3]; | 227 | oname = argv[3]; |
224 | return ipod_encode(iname, oname, 3); /* Firmware image v3 */ | 228 | return ipod_encode(iname, oname, 2, false); /* Firmware image v2 */ |
229 | } | ||
230 | else if(!strcmp(argv[1], "-ipod4g")) { | ||
231 | iname = argv[2]; | ||
232 | oname = argv[3]; | ||
233 | return ipod_encode(iname, oname, 3, false); /* Firmware image v3 */ | ||
234 | } | ||
235 | else if(!strcmp(argv[1], "-ipod5g")) { | ||
236 | iname = argv[2]; | ||
237 | oname = argv[3]; | ||
238 | return ipod_encode(iname, oname, 3, true); /* Firmware image v3 */ | ||
225 | } | 239 | } |
226 | 240 | ||
227 | /* open file */ | 241 | /* open file */ |
@@ -461,7 +475,7 @@ int iaudio_encode(char *iname, char *oname, char *idstring) | |||
461 | This has also only been tested on an ipod Photo | 475 | This has also only been tested on an ipod Photo |
462 | */ | 476 | */ |
463 | 477 | ||
464 | int ipod_encode(char *iname, char *oname, int fw_ver) | 478 | int ipod_encode(char *iname, char *oname, int fw_ver, bool fake_rsrc) |
465 | { | 479 | { |
466 | static const char *apple_stop_sign = "{{~~ /-----\\ "\ | 480 | static const char *apple_stop_sign = "{{~~ /-----\\ "\ |
467 | "{{~~ / \\ "\ | 481 | "{{~~ / \\ "\ |
@@ -481,11 +495,15 @@ int ipod_encode(char *iname, char *oname, int fw_ver) | |||
481 | "---------------"; | 495 | "---------------"; |
482 | size_t len; | 496 | size_t len; |
483 | int length; | 497 | int length; |
498 | int rsrclength; | ||
499 | int rsrcoffset; | ||
484 | FILE *file; | 500 | FILE *file; |
501 | unsigned int sum = 0; | ||
502 | unsigned int rsrcsum = 0; | ||
485 | unsigned char *outbuf; | 503 | unsigned char *outbuf; |
504 | int bufsize; | ||
486 | int i; | 505 | int i; |
487 | unsigned int sum = 0; | 506 | |
488 | |||
489 | file = fopen(iname, "rb"); | 507 | file = fopen(iname, "rb"); |
490 | if (!file) { | 508 | if (!file) { |
491 | perror(iname); | 509 | perror(iname); |
@@ -494,8 +512,14 @@ int ipod_encode(char *iname, char *oname, int fw_ver) | |||
494 | fseek(file,0,SEEK_END); | 512 | fseek(file,0,SEEK_END); |
495 | length = ftell(file); | 513 | length = ftell(file); |
496 | 514 | ||
497 | fseek(file,0,SEEK_SET); | 515 | fseek(file,0,SEEK_SET); |
498 | outbuf = malloc(length+0x4600); | 516 | |
517 | bufsize=(length+0x4600); | ||
518 | if (fake_rsrc) { | ||
519 | bufsize = (bufsize + 0x400) & ~0x200; | ||
520 | } | ||
521 | |||
522 | outbuf = malloc(bufsize); | ||
499 | 523 | ||
500 | if ( !outbuf ) { | 524 | if ( !outbuf ) { |
501 | printf("out of memory!\n"); | 525 | printf("out of memory!\n"); |
@@ -536,6 +560,23 @@ int ipod_encode(char *iname, char *oname, int fw_ver) | |||
536 | int2le(0x00006012, &outbuf[0x4220]); /* vers - 0x6012 is a guess */ | 560 | int2le(0x00006012, &outbuf[0x4220]); /* vers - 0x6012 is a guess */ |
537 | int2le(0xffffffff, &outbuf[0x4224]); /* LoadAddr - for flash images */ | 561 | int2le(0xffffffff, &outbuf[0x4224]); /* LoadAddr - for flash images */ |
538 | 562 | ||
563 | /* "rsrc" entry (if applicable) */ | ||
564 | if (fake_rsrc) { | ||
565 | rsrcoffset=(length+0x4600+0x200) & ~0x200; | ||
566 | rsrclength=0x200; | ||
567 | rsrcsum=0; | ||
568 | |||
569 | memcpy(&outbuf[0x4228],"!ATAcrsr",8); /* dev and type */ | ||
570 | int2le(0, &outbuf[0x4230]); /* id */ | ||
571 | int2le(rsrcoffset, &outbuf[0x4234]); /* devOffset */ | ||
572 | int2le(rsrclength, &outbuf[0x4238]); /* Length of firmware */ | ||
573 | int2le(0x10000000, &outbuf[0x423c]); /* Addr */ | ||
574 | int2le(0, &outbuf[0x4240]); /* Entry Offset */ | ||
575 | int2le(rsrcsum, &outbuf[0x4244]); /* Checksum */ | ||
576 | int2le(0x0000b000, &outbuf[0x4248]); /* vers */ | ||
577 | int2le(0xffffffff, &outbuf[0x424c]); /* LoadAddr - for flash images */ | ||
578 | } | ||
579 | |||
539 | file = fopen(oname, "wb"); | 580 | file = fopen(oname, "wb"); |
540 | if (!file) { | 581 | if (!file) { |
541 | perror(oname); | 582 | perror(oname); |