1
0
Fork 0
forked from len0rd/rockbox

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
This commit is contained in:
Dave Chapman 2007-02-08 21:31:38 +00:00
parent c76dfb3aa6
commit eca5222cad

View file

@ -567,6 +567,7 @@ int add_bootloader(struct ipod_t* ipod, char* filename, int type)
unsigned long chksum=0; unsigned long chksum=0;
unsigned long filechksum=0; unsigned long filechksum=0;
unsigned char header[8]; /* Header for .ipod file */ unsigned char header[8]; /* Header for .ipod file */
unsigned char* bootloader_buf;
/* Calculate the position in the OSOS image where our bootloader will go. */ /* Calculate the position in the OSOS image where our bootloader will go. */
if (ipod->ipod_directory[0].entryOffset>0) { 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); length=filesize(infile);
} }
paddedlength=(length+ipod->sector_size-1)&~(ipod->sector_size-1); 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*/ /* 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); close(infile);
if (n < 0) { if (n < 0) {
@ -628,9 +633,9 @@ int add_bootloader(struct ipod_t* ipod, char* filename, int type)
if (type==FILETYPE_DOT_IPOD) { if (type==FILETYPE_DOT_IPOD) {
/* Calculate and confirm bootloader checksum */ /* Calculate and confirm bootloader checksum */
chksum = ipod->modelnum; 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 */ /* add 8 unsigned bits but keep a 32 bit sum */
chksum += sectorbuf[i]; chksum += bootloader_buf[i];
} }
if (chksum == filechksum) { if (chksum == filechksum) {
@ -690,6 +695,17 @@ int add_bootloader(struct ipod_t* ipod, char* filename, int type)
return -1; 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 */ /* Calculate new checksum for combined image */
chksum = 0; chksum = 0;
for (i=0;i<entryOffset + length; i++) { for (i=0;i<entryOffset + length; i++) {
@ -1320,9 +1336,7 @@ int ipod_scan(struct ipod_t* ipod)
ipod_close(ipod); ipod_close(ipod);
} }
if (n==0) { if (n==1) {
fprintf(stderr,"[ERR] No ipods found.\n");
} else if (n==1) {
/* Remember the disk name */ /* Remember the disk name */
strcpy(ipod->diskname,last_ipod); strcpy(ipod->diskname,last_ipod);
} }
@ -1357,7 +1371,8 @@ int main(int argc, char* argv[])
} }
if ((argc > 1) && (strcmp(argv[1],"--scan")==0)) { 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; return 0;
} }