summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--rbutil/ipodpatcher/ipodpatcher.c87
-rw-r--r--rbutil/ipodpatcher/main.c13
2 files changed, 66 insertions, 34 deletions
diff --git a/rbutil/ipodpatcher/ipodpatcher.c b/rbutil/ipodpatcher/ipodpatcher.c
index 2be6d2333c..4aae029fa2 100644
--- a/rbutil/ipodpatcher/ipodpatcher.c
+++ b/rbutil/ipodpatcher/ipodpatcher.c
@@ -765,34 +765,45 @@ int write_firmware(struct ipod_t* ipod, char* filename, int type)
765 unsigned long filechksum=0; 765 unsigned long filechksum=0;
766 unsigned char header[8]; /* Header for .ipod file */ 766 unsigned char header[8]; /* Header for .ipod file */
767 767
768 /* First check that the input file is the correct type for this ipod. */ 768#ifdef WITH_BOOTOBJS
769 infile=open(filename,O_RDONLY); 769 if (type == FILETYPE_INTERNAL) {
770 if (infile < 0) { 770 fprintf(stderr,"[INFO] Using internal bootloader - %d bytes\n",ipod->bootloader_len);
771 fprintf(stderr,"[ERR] Couldn't open input file %s\n",filename); 771 length = ipod->bootloader_len;
772 return -1; 772 infile = -1;
773 } 773 }
774 774 else
775 if (type==FILETYPE_DOT_IPOD) { 775#endif
776 n = read(infile,header,8); 776 {
777 if (n < 8) { 777 /* First check that the input file is the correct type for this ipod. */
778 fprintf(stderr,"[ERR] Failed to read header from %s\n",filename); 778 infile=open(filename,O_RDONLY);
779 close(infile); 779 if (infile < 0) {
780 fprintf(stderr,"[ERR] Couldn't open input file %s\n",filename);
780 return -1; 781 return -1;
781 } 782 }
782 783
783 if (memcmp(header+4, ipod->modelname,4)!=0) { 784 if (type==FILETYPE_DOT_IPOD) {
784 fprintf(stderr,"[ERR] Model name in input file (%c%c%c%c) doesn't match ipod model (%s)\n", 785 n = read(infile,header,8);
785 header[4],header[5],header[6],header[7], ipod->modelname); 786 if (n < 8) {
786 close(infile); 787 fprintf(stderr,"[ERR] Failed to read header from %s\n",filename);
787 return -1; 788 close(infile);
789 return -1;
790 }
791
792 if (memcmp(header+4, ipod->modelname,4)!=0) {
793 fprintf(stderr,"[ERR] Model name in input file (%c%c%c%c) doesn't match ipod model (%s)\n",
794 header[4],header[5],header[6],header[7], ipod->modelname);
795 close(infile);
796 return -1;
797 }
798
799 filechksum = be2int(header);
800
801 length = filesize(infile)-8;
802 } else {
803 length = filesize(infile);
788 } 804 }
789
790 filechksum = be2int(header);
791
792 length = filesize(infile)-8;
793 } else {
794 length = filesize(infile);
795 } 805 }
806
796 newsize=(length+ipod->sector_size-1)&~(ipod->sector_size-1); 807 newsize=(length+ipod->sector_size-1)&~(ipod->sector_size-1);
797 808
798 fprintf(stderr,"[INFO] Padding input file from 0x%08x to 0x%08x bytes\n", 809 fprintf(stderr,"[INFO] Padding input file from 0x%08x to 0x%08x bytes\n",
@@ -800,7 +811,7 @@ int write_firmware(struct ipod_t* ipod, char* filename, int type)
800 811
801 if (newsize > BUFFER_SIZE) { 812 if (newsize > BUFFER_SIZE) {
802 fprintf(stderr,"[ERR] Input file too big for buffer\n"); 813 fprintf(stderr,"[ERR] Input file too big for buffer\n");
803 close(infile); 814 if (infile >= 0) close(infile);
804 return -1; 815 return -1;
805 } 816 }
806 817
@@ -818,16 +829,26 @@ int write_firmware(struct ipod_t* ipod, char* filename, int type)
818 } 829 }
819 } 830 }
820 831
821 fprintf(stderr,"[INFO] Reading input file...\n"); 832#ifdef WITH_BOOTOBJS
822 /* We now know we have enough space, so write it. */ 833 if (type == FILETYPE_INTERNAL) {
823 memset(sectorbuf+length,0,newsize-length); 834 memcpy(sectorbuf,ipod->bootloader,ipod->bootloader_len);
824 n = read(infile,sectorbuf,length); 835 }
825 if (n < 0) { 836 else
826 fprintf(stderr,"[ERR] Couldn't read input file\n"); 837#endif
838 {
839 fprintf(stderr,"[INFO] Reading input file...\n");
840 /* We now know we have enough space, so write it. */
841 n = read(infile,sectorbuf,length);
842 if (n < 0) {
843 fprintf(stderr,"[ERR] Couldn't read input file\n");
844 close(infile);
845 return -1;
846 }
827 close(infile); 847 close(infile);
828 return -1;
829 } 848 }
830 close(infile); 849
850 /* Pad the data with zeros */
851 memset(sectorbuf+length,0,newsize-length);
831 852
832 if (type==FILETYPE_DOT_IPOD) { 853 if (type==FILETYPE_DOT_IPOD) {
833 chksum = ipod->modelnum; 854 chksum = ipod->modelnum;
diff --git a/rbutil/ipodpatcher/main.c b/rbutil/ipodpatcher/main.c
index 8d70fd789c..0983af768f 100644
--- a/rbutil/ipodpatcher/main.c
+++ b/rbutil/ipodpatcher/main.c
@@ -29,7 +29,7 @@
29#include "ipodpatcher.h" 29#include "ipodpatcher.h"
30#include "ipodio.h" 30#include "ipodio.h"
31 31
32#define VERSION "1.0 with v1.1 bootloaders" 32#define VERSION "1.1-svn"
33 33
34int verbose = 0; 34int verbose = 0;
35 35
@@ -79,6 +79,9 @@ void print_usage(void)
79 fprintf(stderr," -rfb, --read-firmware-bin filename.bin\n"); 79 fprintf(stderr," -rfb, --read-firmware-bin filename.bin\n");
80 fprintf(stderr," -wf, --write-firmware filename.ipod\n"); 80 fprintf(stderr," -wf, --write-firmware filename.ipod\n");
81 fprintf(stderr," -wfb, --write-firmware-bin filename.bin\n"); 81 fprintf(stderr," -wfb, --write-firmware-bin filename.bin\n");
82#ifdef WITH_BOOTOBJS
83 fprintf(stderr," -we, --write-embedded\n");
84#endif
82 fprintf(stderr," -a, --add-bootloader filename.ipod\n"); 85 fprintf(stderr," -a, --add-bootloader filename.ipod\n");
83 fprintf(stderr," -ab, --add-bootloader-bin filename.bin\n"); 86 fprintf(stderr," -ab, --add-bootloader-bin filename.bin\n");
84 fprintf(stderr," -d, --delete-bootloader\n"); 87 fprintf(stderr," -d, --delete-bootloader\n");
@@ -248,6 +251,14 @@ int main(int argc, char* argv[])
248 if (i == argc) { print_usage(); return 1; } 251 if (i == argc) { print_usage(); return 1; }
249 filename=argv[i]; 252 filename=argv[i];
250 i++; 253 i++;
254#ifdef WITH_BOOTOBJS
255 } else if ((strcmp(argv[i],"-we")==0) ||
256 (strcmp(argv[i],"--write-embedded")==0)) {
257 action = WRITE_FIRMWARE;
258 type = FILETYPE_INTERNAL;
259 filename="[embedded bootloader]"; /* Only displayed for user */
260 i++;
261#endif
251 } else if ((strcmp(argv[i],"-wf")==0) || 262 } else if ((strcmp(argv[i],"-wf")==0) ||
252 (strcmp(argv[i],"--write-firmware")==0)) { 263 (strcmp(argv[i],"--write-firmware")==0)) {
253 action = WRITE_FIRMWARE; 264 action = WRITE_FIRMWARE;