From eca5222cadbc6595470bb9c3a295d7fcb7d1e99b Mon Sep 17 00:00:00 2001 From: Dave Chapman Date: Thu, 8 Feb 2007 21:31:38 +0000 Subject: Bugfix - the bootloader was being overwritten if the firmware partition needed to be rearranged to make space (i.e. the first time a bootloader is installed). Thanks to Paul Louden for helping to test and debug. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@12237 a1c6a512-1295-4272-9138-f99709370657 --- tools/ipodpatcher/ipodpatcher.c | 31 +++++++++++++++++++++++-------- 1 file changed, 23 insertions(+), 8 deletions(-) (limited to 'tools/ipodpatcher/ipodpatcher.c') diff --git a/tools/ipodpatcher/ipodpatcher.c b/tools/ipodpatcher/ipodpatcher.c index 8f8fda2e3f..93fd8c16ad 100644 --- a/tools/ipodpatcher/ipodpatcher.c +++ b/tools/ipodpatcher/ipodpatcher.c @@ -567,6 +567,7 @@ int add_bootloader(struct ipod_t* ipod, char* filename, int type) unsigned long chksum=0; unsigned long filechksum=0; unsigned char header[8]; /* Header for .ipod file */ + unsigned char* bootloader_buf; /* Calculate the position in the OSOS image where our bootloader will go. */ if (ipod->ipod_directory[0].entryOffset>0) { @@ -615,9 +616,13 @@ int add_bootloader(struct ipod_t* ipod, char* filename, int type) length=filesize(infile); } paddedlength=(length+ipod->sector_size-1)&~(ipod->sector_size-1); - + + bootloader_buf = malloc(length); + if (bootloader_buf == NULL) { + fprintf(stderr,"[ERR] Can not allocate memory for bootlaoder\n"); + } /* Now read our bootloader - we need to check it before modifying the partition*/ - n = read(infile,sectorbuf+entryOffset,length); + n = read(infile,bootloader_buf,length); close(infile); if (n < 0) { @@ -628,9 +633,9 @@ int add_bootloader(struct ipod_t* ipod, char* filename, int type) if (type==FILETYPE_DOT_IPOD) { /* Calculate and confirm bootloader checksum */ chksum = ipod->modelnum; - for (i = entryOffset; i < entryOffset+length; i++) { + for (i = 0; i < length; i++) { /* add 8 unsigned bits but keep a 32 bit sum */ - chksum += sectorbuf[i]; + chksum += bootloader_buf[i]; } if (chksum == filechksum) { @@ -690,6 +695,17 @@ int add_bootloader(struct ipod_t* ipod, char* filename, int type) return -1; } +#ifdef WITH_BOOTOBJS + if (type == FILETYPE_INTERNAL) { + memcpy(sectorbuf+entryOffset,ipod->bootloader,ipod->bootloader_len); + } + else +#endif + { + memcpy(sectorbuf+entryOffset,bootloader_buf,length); + free(bootloader_buf); + } + /* Calculate new checksum for combined image */ chksum = 0; for (i=0;idiskname,last_ipod); } @@ -1357,7 +1371,8 @@ int main(int argc, char* argv[]) } if ((argc > 1) && (strcmp(argv[1],"--scan")==0)) { - ipod_scan(&ipod); + if (ipod_scan(&ipod) == 0) + fprintf(stderr,"[ERR] No ipods found.\n"); return 0; } -- cgit