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:
parent
c76dfb3aa6
commit
eca5222cad
1 changed files with 23 additions and 8 deletions
|
|
@ -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;i<entryOffset + length; i++) {
|
||||
|
|
@ -1320,9 +1336,7 @@ int ipod_scan(struct ipod_t* ipod)
|
|||
ipod_close(ipod);
|
||||
}
|
||||
|
||||
if (n==0) {
|
||||
fprintf(stderr,"[ERR] No ipods found.\n");
|
||||
} else if (n==1) {
|
||||
if (n==1) {
|
||||
/* Remember the disk name */
|
||||
strcpy(ipod->diskname,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;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue