1
0
Fork 0
forked from len0rd/rockbox

Sync with ipodlinux CVS

git-svn-id: svn://svn.rockbox.org/rockbox/trunk@11697 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
Dave Chapman 2006-12-09 10:08:36 +00:00
parent 552ac5a724
commit 7ccb505488

View file

@ -95,7 +95,7 @@ switch_endian(image_t *image)
void
print_image(image_t *image, const char *head)
{
printf("%stype: '%s' id: 0x%4x len: 0x%4x addr: 0x%4x vers: 0x%8x\r\n",
printf("%stype: '%s' id: 0x%08x len: 0x%x addr: 0x%08x vers: 0x%x\n",
head, image->type, image->id, image->len, image->addr, image->vers);
printf(" devOffset: 0x%08X entryOffset: 0x%08X "
"loadAddr: 0x%08X chksum: 0x%08X\n",
@ -106,9 +106,9 @@ print_image(image_t *image, const char *head)
void
usage()
{
printf("Usage: patch_fw [-h]\n"
" patch_fw [-v] -o outfile -e img_no fw_file\n"
" patch_fw [-v] -g gen [-r rev] -o outfile [-i img_from_-e]* [-l raw_img]* ldr_img\n\n"
printf("Usage: ipod_fw [-h]\n"
" ipod_fw [-v] -o outfile -e img_no fw_file\n"
" ipod_fw [-v] -g gen [-r rev] -o outfile [-i img_from_-e]* [-l raw_img]* ldr_img\n\n"
" -g: set target ipod generation, valid options are: 1g, 2g, 3g\n"
" 4g, 5g, scroll, touch, dock, mini, photo, color, nano and video\n"
" -e: extract the image at img_no in boot table to outfile\n"
@ -142,13 +142,17 @@ copysum(FILE *s, FILE *d, unsigned len, unsigned off)
}
for (i = 0; i < len; i++) {
if (fread(&temp, 1, 1, s) != 1) {
fprintf(stderr, "fread failed: %s\n", strerror(errno));
fprintf(stderr, "Failure in copysum: ");
if (ferror(s))
fprintf(stderr, "fread error: %s\n", strerror(errno));
else if (feof(s))
fprintf(stderr, "fread length 1 at offset %d hit EOF.\n", off);
return -1;
}
sum = sum + (temp & 0xff);
if (d)
if (fwrite(&temp, 1, 1, d) != 1) {
fprintf(stderr, "fwrite failed: %s\n", strerror(errno));
fprintf(stderr, "Failure in copysum; fwrite error: %s\n", strerror(errno));
return -1;
}
}
@ -167,7 +171,12 @@ load_entry(image_t *image, FILE *fw, unsigned offset, int entry)
return -1;
}
if (fread(image, sizeof(image_t), 1, fw) != 1) {
fprintf(stderr, "fread failed: %s\n", strerror(errno));
if (ferror(fw))
fprintf(stderr, "fread error (%s), ", strerror(errno));
else if (feof(fw))
fprintf(stderr, "fread length %lu at offset %lu hit EOF, ",
sizeof(image_t), offset + entry * sizeof(image_t));
fprintf(stderr, "unable to load boot entry.\n");
return -1;
}
switch_endian(image);
@ -187,7 +196,7 @@ write_entry(image_t *image, FILE *fw, unsigned offset, int entry)
}
switch_endian(image);
if (fwrite(image, sizeof(image_t), 1, fw) != 1) {
fprintf(stderr, "fwrite failed: %s\n", strerror(errno));
fprintf(stderr, "fwrite error (%s), unable to write boot entry\n", strerror(errno));
switch_endian(image);
return -1;
}
@ -230,6 +239,33 @@ extract(FILE *f, int idx, FILE *out)
return 0;
}
/* list all images */
int
listall(FILE *f)
{
image_t *image;
unsigned char buf[512];
int idx;
fseek(f, 0x100 + 10, SEEK_SET);
fread(&fw_version, sizeof(fw_version), 1, f);
fw_version = switch_16(fw_version);
image = (image_t *)buf;
idx = 0;
while (idx < 20) {
char prefix[32];
if (load_entry(image, f, TBL, idx) < 0) return -1;
if (!image->id) break;
sprintf (prefix, "%2d: ", idx);
print_image (image, prefix);
++idx;
}
return 0;
}
/* return the size of f */
unsigned
lengthof(FILE *f)
@ -447,6 +483,12 @@ main(int argc, char **argv)
return 0;
}
else if (!gen_set) {
if ((in = fopen(argv[optind], "rb")) != NULL) {
// just list all available entries
listall (in);
fclose(in);
return 0;
}
usage();
return 1;
}
@ -494,17 +536,17 @@ main(int argc, char **argv)
return 1;
}
if (fwrite(apple_copyright, 0x100, 1, out) != 1) {
fprintf(stderr, "fwrite failed: %s\n", strerror(errno));
fprintf(stderr, "fwrite error (%s) while writing copyright\n", strerror(errno));
return 1;
}
version = switch_32(0x5b68695d); /* magic */
if (fwrite(&version, 4, 1, out) != 1) {
fprintf(stderr, "fwrite failed: %s\n", strerror(errno));
fprintf(stderr, "fwrite error (%s) while writing version magic\n", strerror(errno));
return 1;
}
version = switch_32(0x00004000); /* magic */
if (fwrite(&version, 4, 1, out) != 1) {
fprintf(stderr, "fwrite failed: %s\n", strerror(errno));
fprintf(stderr, "fwrite error (%s) while writing version magic\n", strerror(errno));
return 1;
}
if (fw_version == 3) {
@ -514,7 +556,7 @@ main(int argc, char **argv)
}
if (fwrite(&version, 4, 1, out) != 1) {
fprintf(stderr, "fwrite failed: %s\n", strerror(errno));
fprintf(stderr, "fwrite error (%s) while writing version magic\n", strerror(errno));
return 1;
}
if (write_entry(&image, out, TBL, 0) == -1)