diff options
Diffstat (limited to 'rbutil/mkamsboot/mkamsboot.c')
-rw-r--r-- | rbutil/mkamsboot/mkamsboot.c | 132 |
1 files changed, 4 insertions, 128 deletions
diff --git a/rbutil/mkamsboot/mkamsboot.c b/rbutil/mkamsboot/mkamsboot.c index 9d0ad9cd9a..8d40a1966c 100644 --- a/rbutil/mkamsboot/mkamsboot.c +++ b/rbutil/mkamsboot/mkamsboot.c | |||
@@ -110,7 +110,7 @@ execution to the uncompressed firmware. | |||
110 | #endif | 110 | #endif |
111 | 111 | ||
112 | /* 4 for m200, 2 for e200/c200, 1 or 2 for fuze/clop */ | 112 | /* 4 for m200, 2 for e200/c200, 1 or 2 for fuze/clop */ |
113 | static const unsigned short hw_revisions[] = { | 113 | const unsigned short hw_revisions[] = { |
114 | [MODEL_FUZE] = 1, | 114 | [MODEL_FUZE] = 1, |
115 | [MODEL_CLIP] = 1, | 115 | [MODEL_CLIP] = 1, |
116 | [MODEL_CLIPV2] = 2, | 116 | [MODEL_CLIPV2] = 2, |
@@ -120,7 +120,7 @@ static const unsigned short hw_revisions[] = { | |||
120 | }; | 120 | }; |
121 | 121 | ||
122 | /* version 2 is used in Clipv2 and Fuzev2 firmwares */ | 122 | /* version 2 is used in Clipv2 and Fuzev2 firmwares */ |
123 | static const unsigned short fw_revisions[] = { | 123 | const unsigned short fw_revisions[] = { |
124 | [MODEL_FUZE] = 1, | 124 | [MODEL_FUZE] = 1, |
125 | [MODEL_CLIP] = 1, | 125 | [MODEL_CLIP] = 1, |
126 | [MODEL_CLIPV2] = 2, | 126 | [MODEL_CLIPV2] = 2, |
@@ -130,7 +130,7 @@ static const unsigned short fw_revisions[] = { | |||
130 | }; | 130 | }; |
131 | 131 | ||
132 | /* Descriptive name of these models */ | 132 | /* Descriptive name of these models */ |
133 | static const char* model_names[] = { | 133 | const char* model_names[] = { |
134 | [MODEL_FUZE] = "Fuze", | 134 | [MODEL_FUZE] = "Fuze", |
135 | [MODEL_CLIP] = "Clip", | 135 | [MODEL_CLIP] = "Clip", |
136 | [MODEL_CLIPV2] = "Clip", | 136 | [MODEL_CLIPV2] = "Clip", |
@@ -150,7 +150,7 @@ static const unsigned char* bootloaders[] = { | |||
150 | }; | 150 | }; |
151 | 151 | ||
152 | /* Size of dualboot functions for these models */ | 152 | /* Size of dualboot functions for these models */ |
153 | static const int bootloader_sizes[] = { | 153 | const int bootloader_sizes[] = { |
154 | [MODEL_FUZE] = sizeof(dualboot_fuze), | 154 | [MODEL_FUZE] = sizeof(dualboot_fuze), |
155 | [MODEL_CLIP] = sizeof(dualboot_clip), | 155 | [MODEL_CLIP] = sizeof(dualboot_clip), |
156 | [MODEL_CLIPV2] = sizeof(dualboot_clipv2), | 156 | [MODEL_CLIPV2] = sizeof(dualboot_clipv2), |
@@ -574,127 +574,3 @@ int total_size(int model, int rb_packedsize, int of_packedsize) | |||
574 | rb_packedsize; | 574 | rb_packedsize; |
575 | } | 575 | } |
576 | 576 | ||
577 | #ifndef LIB | ||
578 | /* standalone executable */ | ||
579 | int main(int argc, char* argv[]) | ||
580 | { | ||
581 | char *infile, *bootfile, *outfile; | ||
582 | int fdout; | ||
583 | off_t len; | ||
584 | uint32_t n; | ||
585 | unsigned char* buf; | ||
586 | int firmware_size; | ||
587 | int bootloader_size; | ||
588 | unsigned char* of_packed; | ||
589 | int of_packedsize; | ||
590 | unsigned char* rb_packed; | ||
591 | int rb_packedsize; | ||
592 | int totalsize; | ||
593 | char errstr[200]; | ||
594 | struct md5sums sum; | ||
595 | char md5sum[33]; /* 32 digits + \0 */ | ||
596 | |||
597 | sum.md5 = md5sum; | ||
598 | |||
599 | /* VERSION comes frome the Makefile */ | ||
600 | fprintf(stderr, | ||
601 | "mkamsboot Version " VERSION "\n" | ||
602 | "This is free software; see the source for copying conditions. There is NO\n" | ||
603 | "warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n" | ||
604 | "\n"); | ||
605 | |||
606 | if(argc != 4) { | ||
607 | printf("Usage: mkamsboot <firmware file> <boot file> <output file>\n"); | ||
608 | return 1; | ||
609 | } | ||
610 | |||
611 | infile = argv[1]; | ||
612 | bootfile = argv[2]; | ||
613 | outfile = argv[3]; | ||
614 | |||
615 | /* Load original firmware file */ | ||
616 | buf = load_of_file(infile, &len, &sum, | ||
617 | &firmware_size, &of_packed, &of_packedsize, errstr, sizeof(errstr)); | ||
618 | |||
619 | if (buf == NULL) { | ||
620 | fprintf(stderr, "%s", errstr); | ||
621 | fprintf(stderr, "[ERR] Could not load %s\n", infile); | ||
622 | return 1; | ||
623 | } | ||
624 | |||
625 | fprintf(stderr, "[INFO] Original firmware MD5 checksum match\n"); | ||
626 | fprintf(stderr, "[INFO] Model: Sansa %s v%d - Firmware version: %s\n", | ||
627 | model_names[sum.model], hw_revisions[sum.model], sum.version); | ||
628 | |||
629 | |||
630 | /* Load bootloader file */ | ||
631 | rb_packed = load_rockbox_file(bootfile, sum.model, &bootloader_size, | ||
632 | &rb_packedsize, errstr, sizeof(errstr)); | ||
633 | if (rb_packed == NULL) { | ||
634 | fprintf(stderr, "%s", errstr); | ||
635 | fprintf(stderr, "[ERR] Could not load %s\n", bootfile); | ||
636 | free(buf); | ||
637 | free(of_packed); | ||
638 | return 1; | ||
639 | } | ||
640 | |||
641 | printf("[INFO] Firmware patching has begun !\n\n"); | ||
642 | |||
643 | fprintf(stderr, "[INFO] Original firmware size: %d bytes\n", | ||
644 | firmware_size); | ||
645 | fprintf(stderr, "[INFO] Packed OF size: %d bytes\n", | ||
646 | of_packedsize); | ||
647 | fprintf(stderr, "[INFO] Bootloader size: %d bytes\n", | ||
648 | (int)bootloader_size); | ||
649 | fprintf(stderr, "[INFO] Packed bootloader size: %d bytes\n", | ||
650 | rb_packedsize); | ||
651 | fprintf(stderr, "[INFO] Dual-boot function size: %d bytes\n", | ||
652 | bootloader_sizes[sum.model]); | ||
653 | fprintf(stderr, "[INFO] UCL unpack function size: %u bytes\n", | ||
654 | (unsigned int)sizeof(nrv2e_d8)); | ||
655 | |||
656 | totalsize = total_size(sum.model, of_packedsize, rb_packedsize); | ||
657 | |||
658 | fprintf(stderr, "[INFO] Total size of new image: %d bytes\n", totalsize); | ||
659 | |||
660 | if (totalsize > firmware_size) { | ||
661 | fprintf(stderr, "[ERR] No room to insert bootloader, aborting\n"); | ||
662 | free(buf); | ||
663 | free(of_packed); | ||
664 | free(rb_packed); | ||
665 | return 1; | ||
666 | } | ||
667 | |||
668 | patch_firmware(sum.model, fw_revisions[sum.model], firmware_size, buf, len, | ||
669 | of_packed, of_packedsize, rb_packed, rb_packedsize); | ||
670 | |||
671 | /* Write the new firmware */ | ||
672 | fdout = open(outfile, O_CREAT|O_TRUNC|O_WRONLY|O_BINARY, 0666); | ||
673 | |||
674 | if (fdout < 0) { | ||
675 | fprintf(stderr, "[ERR] Could not open %s for writing\n", outfile); | ||
676 | free(buf); | ||
677 | free(of_packed); | ||
678 | free(rb_packed); | ||
679 | return 1; | ||
680 | } | ||
681 | |||
682 | n = write(fdout, buf, len); | ||
683 | |||
684 | if (n != (unsigned)len) { | ||
685 | fprintf(stderr, "[ERR] Could not write firmware file\n"); | ||
686 | free(buf); | ||
687 | free(of_packed); | ||
688 | free(rb_packed); | ||
689 | return 1; | ||
690 | } | ||
691 | |||
692 | close(fdout); | ||
693 | free(buf); | ||
694 | free(of_packed); | ||
695 | free(rb_packed); | ||
696 | fprintf(stderr, "\n[INFO] Patching succeeded!\n"); | ||
697 | |||
698 | return 0; | ||
699 | } | ||
700 | #endif | ||