summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorDave Chapman <dave@dchapman.com>2006-07-21 16:16:48 +0000
committerDave Chapman <dave@dchapman.com>2006-07-21 16:16:48 +0000
commitc52ae7abe7bdcf398d4adf79b5f5bd0760fda73a (patch)
treedd94c8f2cb69422250ce9a117097afd39444df79 /tools
parenteec48a8956ce56be02e67ea9097e4c171bece995 (diff)
downloadrockbox-c52ae7abe7bdcf398d4adf79b5f5bd0760fda73a.tar.gz
rockbox-c52ae7abe7bdcf398d4adf79b5f5bd0760fda73a.zip
Initial support for creating ipod firmware partition images. Only tested on an ipod photo so far, and will definitely not work on either a 3g or a 5g. If you never want to use the Apple firmware, you can create a firmware partition image containing just the Rockbox bootloader with the command "../tools/scramble -ipod bootloader/bootloader.bin bootloader.img" and then write bootloader.img to your firmware partition.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@10275 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'tools')
-rw-r--r--tools/scramble.c113
1 files changed, 113 insertions, 0 deletions
diff --git a/tools/scramble.c b/tools/scramble.c
index 8bab41596a..8e104cc43c 100644
--- a/tools/scramble.c
+++ b/tools/scramble.c
@@ -23,6 +23,7 @@
23#include "iriver.h" 23#include "iriver.h"
24 24
25int iaudio_encode(char *iname, char *oname, char *idstring); 25int iaudio_encode(char *iname, char *oname, char *idstring);
26int ipod_encode(char *iname, char *oname, int fw_ver);
26 27
27enum 28enum
28{ 29{
@@ -42,6 +43,12 @@ int size_limit[] =
42 0x64000 /* ARCHOS_ONDIO_FM */ 43 0x64000 /* ARCHOS_ONDIO_FM */
43}; 44};
44 45
46void short2le(unsigned short val, unsigned char* addr)
47{
48 addr[0] = val & 0xFF;
49 addr[1] = (val >> 8) & 0xff;
50}
51
45void int2le(unsigned int val, unsigned char* addr) 52void int2le(unsigned int val, unsigned char* addr)
46{ 53{
47 addr[0] = val & 0xFF; 54 addr[0] = val & 0xFF;
@@ -211,6 +218,11 @@ int main (int argc, char** argv)
211 oname = argv[3]; 218 oname = argv[3];
212 return iaudio_encode(iname, oname, "COWON_X5V_FW"); 219 return iaudio_encode(iname, oname, "COWON_X5V_FW");
213 } 220 }
221 else if(!strcmp(argv[1], "-ipod")) {
222 iname = argv[2];
223 oname = argv[3];
224 return ipod_encode(iname, oname, 3); /* Firmware image v3 */
225 }
214 226
215 /* open file */ 227 /* open file */
216 file = fopen(iname,"rb"); 228 file = fopen(iname,"rb");
@@ -437,3 +449,104 @@ int iaudio_encode(char *iname, char *oname, char *idstring)
437 449
438 fclose(file); 450 fclose(file);
439} 451}
452
453
454/* Create an ipod firmware partition image
455
456 fw_ver = 2 for 3rd Gen ipods, 3 for all later ipods including 5g.
457
458 This function doesn't yet handle the Broadcom resource image for the 5g,
459 so the resulting images won't be usable.
460
461 This has also only been tested on an ipod Photo
462*/
463
464int ipod_encode(char *iname, char *oname, int fw_ver)
465{
466 static const char *apple_stop_sign = "{{~~ /-----\\ "\
467 "{{~~ / \\ "\
468 "{{~~| | "\
469 "{{~~| S T O P | "\
470 "{{~~| | "\
471 "{{~~ \\ / "\
472 "{{~~ \\-----/ "\
473 "Copyright(C) 200"\
474 "1 Apple Computer"\
475 ", Inc.----------"\
476 "----------------"\
477 "----------------"\
478 "----------------"\
479 "----------------"\
480 "----------------"\
481 "---------------";
482 size_t len;
483 int length;
484 FILE *file;
485 unsigned char *outbuf;
486 int i;
487 unsigned int sum = 0;
488
489 file = fopen(iname, "rb");
490 if (!file) {
491 perror(iname);
492 return -1;
493 }
494 fseek(file,0,SEEK_END);
495 length = ftell(file);
496
497 fseek(file,0,SEEK_SET);
498 outbuf = malloc(length+0x4600);
499
500 if ( !outbuf ) {
501 printf("out of memory!\n");
502 return -1;
503 }
504
505 len = fread(outbuf+0x4600, 1, length, file);
506 if(len < length) {
507 perror(iname);
508 return -2;
509 }
510 fclose(file);
511
512 /* Calculate checksum for later use in header */
513 for(i = 0x4600; i < 0x4600+length;i++)
514 sum += outbuf[i];
515
516 /* Clear the header area to zero */
517 memset(outbuf, 0, 0x4600);
518
519 /* APPLE STOP SIGN */
520 strcpy((char *)outbuf, apple_stop_sign);
521
522 /* VOLUME HEADER */
523 memcpy(&outbuf[0x100],"]ih[",4); /* Magic */
524 int2le(0x4000, &outbuf[0x104]); /* Firmware offset relative to 0x200 */
525 short2le(0x10c, &outbuf[0x108]); /* Location of extended header */
526 short2le(fw_ver, &outbuf[0x10a]);
527
528 /* Firmware Directory - "osos" entry */
529 memcpy(&outbuf[0x4200],"!ATAsoso",8); /* dev and type */
530 int2le(0, &outbuf[0x4208]); /* id */
531 int2le(0x4400, &outbuf[0x420c]); /* devOffset */
532 int2le(length, &outbuf[0x4210]); /* Length of firmware */
533 int2le(0x10000000, &outbuf[0x4214]); /* Addr */
534 int2le(0, &outbuf[0x4218]); /* Entry Offset */
535 int2le(sum, &outbuf[0x421c]); /* Checksum */
536 int2le(0x00006012, &outbuf[0x4220]); /* vers - 0x6012 is a guess */
537 int2le(0xffffffff, &outbuf[0x4224]); /* LoadAddr - for flash images */
538
539 file = fopen(oname, "wb");
540 if (!file) {
541 perror(oname);
542 return -3;
543 }
544
545 len = fwrite(outbuf, 1, length+0x4600, file);
546 if(len < length) {
547 perror(oname);
548 return -4;
549 }
550
551 fclose(file);
552}