1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
10 * Copyright (C) 2007 Dave Chapman
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
20 ****************************************************************************/
27 static void int2be(unsigned int val
, unsigned char* addr
)
29 addr
[0] = (val
>> 24) & 0xff;
30 addr
[1] = (val
>> 16) & 0xff;
31 addr
[2] = (val
>> 8) & 0xff;
35 static int le2int(unsigned char* buf
)
37 int32_t res
= (buf
[3] << 24) | (buf
[2] << 16) | (buf
[1] << 8) | buf
[0];
42 static char* get_modelname(int version
)
45 switch (version
>> 8) {
75 static int get_modelnum(int version
)
78 switch (version
>> 8) {
109 static void dump_app(char* name
, unsigned char* p
, unsigned char* flash
)
112 unsigned char header
[8];
117 unsigned int unknown1
;
120 unsigned int loadaddr
;
121 unsigned int unknown2
;
122 unsigned int checksum
;
123 unsigned int version
;
124 unsigned int unknown3
;
127 /* Extract variables from header */
128 unknown1
= le2int(p
+0x08);
129 offset
= le2int(p
+0x0c);
130 length
= le2int(p
+0x10);
131 loadaddr
= le2int(p
+0x14);
132 unknown2
= le2int(p
+0x18);
133 checksum
= le2int(p
+0x1c);
134 version
= le2int(p
+0x20);
135 unknown3
= le2int(p
+0x24);
137 modelname
= get_modelname(version
);
140 for (i
= offset
; i
< offset
+length
; i
++) {
144 /* Display information: */
145 printf("Image: %s\n",name
);
146 printf("unknown1: %08x\n",unknown1
);
147 printf("offset: %08x\n",offset
);
148 printf("length: %08x\n",length
);
149 printf("loadaddr: %08x\n",loadaddr
);
150 printf("unknown2: %08x\n",unknown2
);
151 printf("checksum: %08x (flashsplit sum: %08x)\n",checksum
,sum
);
152 printf("version: %08x (ipod model: %s)\n",version
,modelname
);
153 printf("unknown3: %08x\n",unknown3
);
156 if (modelname
== NULL
) {
157 printf("Unknown version, not exporting to .ipod file\n");
159 } else if (checksum
!= sum
) {
160 printf("Checksum mismatch, not exporting to .ipod file\n");
162 sum
+= get_modelnum(version
);
164 memcpy(header
+4,modelname
,4);
166 sprintf(filename
,"%s.ipod",name
);
167 outfile
= open(filename
,O_CREAT
|O_TRUNC
|O_WRONLY
,0666);
169 fprintf(stderr
,"[ERR] Couldn't open file %s\n",filename
);
173 write(outfile
,header
,8);
174 write(outfile
,flash
+offset
,length
);
178 sprintf(filename
,"%s.bin",name
);
179 outfile
= open(filename
,O_CREAT
|O_TRUNC
|O_WRONLY
,0666);
181 fprintf(stderr
,"[ERR] Couldn't open file %s\n",filename
);
185 write(outfile
,flash
+offset
,length
);
189 int main(int argc
,char* argv
[])
192 unsigned char buf
[1024*1024];
196 fprintf(stderr
,"Usage: flashsplit flash.bin\n");
200 fd
=open(argv
[1],O_RDONLY
);
202 fprintf(stderr
,"Can not open %s\n",argv
[1]);
206 read(fd
,buf
,sizeof(buf
));
210 p
= buf
+ 0xffe00; /* Start of flash directory */
212 while (le2int(p
) != 0) {
213 if (memcmp(p
,"hslfksid",8)==0) {
214 dump_app("diskmode",p
,buf
);
215 } else if (memcmp(p
,"hslfgaid",8)==0) {
216 dump_app("diagmode",p
,buf
);
217 } else if (memcmp(p
,"hslfogol",8)==0) {
218 dump_app("logo",p
,buf
);
219 } else if (memcmp(p
,"hslfnacs",8)==0) {
220 dump_app("diskscan",p
,buf
);
221 } else if (memcmp(p
,"hslfscmv",8)==0) {
222 dump_app("vmcs",p
,buf
);
224 printf("Unknown image type - %c%c%c%c%c%c%c%c\n",p
[3],p
[2],p
[1],p
[0],p
[7],p
[6],p
[5],p
[4]);