diff options
author | Solomon Peachy <pizza@shaftnet.org> | 2020-03-29 12:46:52 -0400 |
---|---|---|
committer | Solomon Peachy <pizza@shaftnet.org> | 2020-03-29 18:48:09 +0200 |
commit | 5fa6acf39fc56fa4def3c8553a426c11c026f4ad (patch) | |
tree | 19222bd08d08fe7475690da1627465d89c6be3e2 | |
parent | 51ad6254048c85284a287ade1a602e3432209b77 (diff) | |
download | rockbox-5fa6acf39fc56fa4def3c8553a426c11c026f4ad.tar.gz rockbox-5fa6acf39fc56fa4def3c8553a426c11c026f4ad.zip |
FS#13184: Support 2048 byte sectors and images without bootloader in ipod_fw
(From Stefan Ott)
I wrote a little patch for ipod_fw.c that allows me to create bootable
images for the iPod video without using any external software.
The patch adds two new options:
- The -s option can now be used to specify the sector size in blocks (typically 512 or 2048) when generating an image.
- The -n option can be used to create an image without a boot loader
Change-Id: I35ebcd19ba1491bba76dfc8011e5a856108bb9ad
-rw-r--r-- | tools/ipod_fw.c | 49 |
1 files changed, 32 insertions, 17 deletions
diff --git a/tools/ipod_fw.c b/tools/ipod_fw.c index eefe3f7db8..59285df63c 100644 --- a/tools/ipod_fw.c +++ b/tools/ipod_fw.c | |||
@@ -110,7 +110,7 @@ usage() | |||
110 | { | 110 | { |
111 | printf("Usage: ipod_fw [-h]\n" | 111 | printf("Usage: ipod_fw [-h]\n" |
112 | " ipod_fw [-v] -o outfile -e img_no fw_file\n" | 112 | " ipod_fw [-v] -o outfile -e img_no fw_file\n" |
113 | " ipod_fw [-v] -g gen [-r rev] -o outfile [-i img_from_-e]* [-l raw_img]* ldr_img\n\n" | 113 | " ipod_fw [-v] -g gen [-r rev] [-s size] -o outfile [-i img_from_-e]* [-l raw_img]* ldr_img\n\n" |
114 | " -g: set target ipod generation, valid options are: 1g, 2g, 3g\n" | 114 | " -g: set target ipod generation, valid options are: 1g, 2g, 3g\n" |
115 | " 4g, 5g, scroll, touch, dock, mini, photo, color, nano and video\n" | 115 | " 4g, 5g, scroll, touch, dock, mini, photo, color, nano and video\n" |
116 | " -e: extract the image at img_no in boot table to outfile\n" | 116 | " -e: extract the image at img_no in boot table to outfile\n" |
@@ -124,7 +124,9 @@ usage() | |||
124 | " may be needed if newest -e img is not the same as the flash rev\n" | 124 | " may be needed if newest -e img is not the same as the flash rev\n" |
125 | " ldr_img is the iPodLinux loader binary.\n" | 125 | " ldr_img is the iPodLinux loader binary.\n" |
126 | " first image is loaded by default, 2., 3., 4. or 5. loaded if\n" | 126 | " first image is loaded by default, 2., 3., 4. or 5. loaded if\n" |
127 | " rew, menu, play or ff is hold while booting\n\n" | 127 | " rew, menu, play or ff is hold while booting\n" |
128 | " -n: do not add a boot loader (ldr_img)\n" | ||
129 | " -s: set sector size in bytes (default is 512)\n\n" | ||
128 | " -v: verbose\n\n" | 130 | " -v: verbose\n\n" |
129 | " This program is used to create a bootable ipod image.\n\n"); | 131 | " This program is used to create a bootable ipod image.\n\n"); |
130 | } | 132 | } |
@@ -339,12 +341,13 @@ main(int argc, char **argv) | |||
339 | int images_done = 0; | 341 | int images_done = 0; |
340 | unsigned version = 0, offset = 0, len = 0; | 342 | unsigned version = 0, offset = 0, len = 0; |
341 | int needs_rcsc = 0; | 343 | int needs_rcsc = 0; |
344 | int no_boot = 0; | ||
342 | 345 | ||
343 | test_endian(); | 346 | test_endian(); |
344 | 347 | ||
345 | /* parse options */ | 348 | /* parse options */ |
346 | opterr = 0; | 349 | opterr = 0; |
347 | while ((c = getopt(argc, argv, "3hve:o:i:l:r:g:")) != -1) | 350 | while ((c = getopt(argc, argv, "3hve:o:i:l:nr:g:s:")) != -1) |
348 | switch (c) { | 351 | switch (c) { |
349 | case 'h': | 352 | case 'h': |
350 | if (verbose || in || out || images_done || ext) { | 353 | if (verbose || in || out || images_done || ext) { |
@@ -471,6 +474,9 @@ main(int argc, char **argv) | |||
471 | images_done++; | 474 | images_done++; |
472 | fclose(in); | 475 | fclose(in); |
473 | break; | 476 | break; |
477 | case 'n': | ||
478 | no_boot = 1; | ||
479 | break; | ||
474 | case 'r': | 480 | case 'r': |
475 | if (ext) { | 481 | if (ext) { |
476 | usage(); | 482 | usage(); |
@@ -478,6 +484,9 @@ main(int argc, char **argv) | |||
478 | } | 484 | } |
479 | version = strtol(optarg, NULL, 16); | 485 | version = strtol(optarg, NULL, 16); |
480 | break; | 486 | break; |
487 | case 's': | ||
488 | sectorsize = atoi(optarg); | ||
489 | break; | ||
481 | case '?': | 490 | case '?': |
482 | fprintf(stderr, "invalid option -%c specified\n", optopt); | 491 | fprintf(stderr, "invalid option -%c specified\n", optopt); |
483 | usage(); | 492 | usage(); |
@@ -488,7 +497,7 @@ main(int argc, char **argv) | |||
488 | return 1; | 497 | return 1; |
489 | } | 498 | } |
490 | 499 | ||
491 | if (argc - optind != 1) { | 500 | if ((argc - optind != 1) && !no_boot) { |
492 | usage(); | 501 | usage(); |
493 | return 1; | 502 | return 1; |
494 | } | 503 | } |
@@ -528,19 +537,22 @@ main(int argc, char **argv) | |||
528 | fprintf(stderr, "no images specified!\n"); | 537 | fprintf(stderr, "no images specified!\n"); |
529 | return 1; | 538 | return 1; |
530 | } | 539 | } |
531 | if ((in = fopen(argv[optind], "rb")) == NULL) { | 540 | if (!no_boot) |
532 | fprintf(stderr, "Cannot open loader image file %s\n", argv[optind]); | 541 | { |
533 | return 1; | 542 | if ((in = fopen(argv[optind], "rb")) == NULL) { |
534 | } | 543 | fprintf(stderr, "Cannot open loader image file %s\n", argv[optind]); |
535 | offset = (offset + 0x1ff) & ~0x1ff; | 544 | return 1; |
536 | if ((len = lengthof(in)) == -1) | 545 | } |
537 | return 1; | 546 | offset = (offset + 0x1ff) & ~0x1ff; |
538 | if (fseek(out, offset, SEEK_SET) == -1) { | 547 | if ((len = lengthof(in)) == -1) |
539 | fprintf(stderr, "fseek failed: %s\n", strerror(errno)); | 548 | return 1; |
540 | return 1; | 549 | if (fseek(out, offset, SEEK_SET) == -1) { |
550 | fprintf(stderr, "fseek failed: %s\n", strerror(errno)); | ||
551 | return 1; | ||
552 | } | ||
553 | if (copysum(in, out, len, 0) == -1) | ||
554 | return 1; | ||
541 | } | 555 | } |
542 | if (copysum(in, out, len, 0) == -1) | ||
543 | return 1; | ||
544 | for (i=0; i < images_done; i++) { | 556 | for (i=0; i < images_done; i++) { |
545 | if (images[i].vers > image.vers) image.vers = images[i].vers; | 557 | if (images[i].vers > image.vers) image.vers = images[i].vers; |
546 | if (write_entry(images+i, out, offset+0x0100, i) == -1) | 558 | if (write_entry(images+i, out, offset+0x0100, i) == -1) |
@@ -548,7 +560,10 @@ main(int argc, char **argv) | |||
548 | } | 560 | } |
549 | if (version) image.vers = version; | 561 | if (version) image.vers = version; |
550 | image.len = offset + len - FIRST_OFFSET; | 562 | image.len = offset + len - FIRST_OFFSET; |
551 | image.entryOffset = offset - FIRST_OFFSET; | 563 | if (!no_boot) |
564 | { | ||
565 | image.entryOffset = offset - FIRST_OFFSET; | ||
566 | } | ||
552 | image.devOffset = (sectorsize==512 ? 0x4400 : 0x4800); | 567 | image.devOffset = (sectorsize==512 ? 0x4400 : 0x4800); |
553 | if ((image.chksum = copysum(out, NULL, image.len, FIRST_OFFSET)) == -1) | 568 | if ((image.chksum = copysum(out, NULL, image.len, FIRST_OFFSET)) == -1) |
554 | return 1; | 569 | return 1; |