Add -rfb option for reading the main firmware (OSOS image) as a binary file.

git-svn-id: svn://svn.rockbox.org/rockbox/trunk@13148 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
Dave Chapman 2007-04-13 23:28:20 +00:00
parent 266707f818
commit 427fff4320
3 changed files with 26 additions and 13 deletions

View file

@ -885,7 +885,7 @@ int write_firmware(struct ipod_t* ipod, char* filename, int type)
return 0;
}
int read_firmware(struct ipod_t* ipod, char* filename)
int read_firmware(struct ipod_t* ipod, char* filename, int type)
{
int length;
int i;
@ -921,22 +921,25 @@ int read_firmware(struct ipod_t* ipod, char* filename)
return -1;
}
chksum = ipod->modelnum;
for (i = 0; i < length; i++) {
/* add 8 unsigned bits but keep a 32 bit sum */
chksum += sectorbuf[i];
}
int2be(chksum,header);
memcpy(header+4, ipod->modelname,4);
outfile = open(filename,O_CREAT|O_TRUNC|O_WRONLY|O_BINARY,0666);
if (outfile < 0) {
fprintf(stderr,"[ERR] Couldn't open file %s\n",filename);
return -1;
}
write(outfile,header,8);
if (type == FILETYPE_DOT_IPOD) {
chksum = ipod->modelnum;
for (i = 0; i < length; i++) {
/* add 8 unsigned bits but keep a 32 bit sum */
chksum += sectorbuf[i];
}
int2be(chksum,header);
memcpy(header+4, ipod->modelname,4);
write(outfile,header,8);
}
write(outfile,sectorbuf,length);
close(outfile);

View file

@ -41,7 +41,7 @@ int diskmove(struct ipod_t* ipod, int delta);
int add_bootloader(struct ipod_t* ipod, char* filename, int type);
int delete_bootloader(struct ipod_t* ipod);
int write_firmware(struct ipod_t* ipod, char* filename, int type);
int read_firmware(struct ipod_t* ipod, char* filename);
int read_firmware(struct ipod_t* ipod, char* filename, int type);
int read_directory(struct ipod_t* ipod);
int list_images(struct ipod_t* ipod);
int getmodel(struct ipod_t* ipod, int ipod_version);

View file

@ -76,6 +76,7 @@ void print_usage(void)
fprintf(stderr," -r, --read-partition bootpartition.bin\n");
fprintf(stderr," -w, --write-partition bootpartition.bin\n");
fprintf(stderr," -rf, --read-firmware filename.ipod\n");
fprintf(stderr," -rfb, --read-firmware-bin filename.bin\n");
fprintf(stderr," -wf, --write-firmware filename.ipod\n");
fprintf(stderr," -wfb, --write-firmware-bin filename.bin\n");
fprintf(stderr," -a, --add-bootloader filename.ipod\n");
@ -234,6 +235,15 @@ int main(int argc, char* argv[])
} else if ((strcmp(argv[i],"-rf")==0) ||
(strcmp(argv[i],"--read-firmware")==0)) {
action = READ_FIRMWARE;
type = FILETYPE_DOT_IPOD;
i++;
if (i == argc) { print_usage(); return 1; }
filename=argv[i];
i++;
} else if ((strcmp(argv[i],"-rfb")==0) ||
(strcmp(argv[i],"--read-firmware-bin")==0)) {
action = READ_FIRMWARE;
type = FILETYPE_DOT_BIN;
i++;
if (i == argc) { print_usage(); return 1; }
filename=argv[i];
@ -399,7 +409,7 @@ int main(int argc, char* argv[])
fprintf(stderr,"[ERR] --write-firmware failed.\n");
}
} else if (action==READ_FIRMWARE) {
if (read_firmware(&ipod, filename)==0) {
if (read_firmware(&ipod, filename, type)==0) {
fprintf(stderr,"[INFO] Firmware read to file %s.\n",filename);
} else {
fprintf(stderr,"[ERR] --read-firmware failed.\n");