summaryrefslogtreecommitdiffstats
path: root/tools/ipodpatcher/ipodpatcher.c
diff options
context:
space:
mode:
authorDave Chapman <dave@dchapman.com>2006-12-15 09:55:21 +0000
committerDave Chapman <dave@dchapman.com>2006-12-15 09:55:21 +0000
commit408c65bb219d81f7a65471cc74014902df606795 (patch)
tree78ab0ed6281dac7eeec749950d380dde4e82070e /tools/ipodpatcher/ipodpatcher.c
parent49e016c48fe58ee50cd2f1dbb95bad420dd6c50e (diff)
downloadrockbox-408c65bb219d81f7a65471cc74014902df606795.tar.gz
rockbox-408c65bb219d81f7a65471cc74014902df606795.zip
Attempt #2 at moving the images to make space for the bootloader. The previous attempt was completely broken. This should hopefully fix the --add-bootloader functionality.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@11769 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'tools/ipodpatcher/ipodpatcher.c')
-rw-r--r--tools/ipodpatcher/ipodpatcher.c29
1 files changed, 14 insertions, 15 deletions
diff --git a/tools/ipodpatcher/ipodpatcher.c b/tools/ipodpatcher/ipodpatcher.c
index 87b181b322..ad5d5c7d0f 100644
--- a/tools/ipodpatcher/ipodpatcher.c
+++ b/tools/ipodpatcher/ipodpatcher.c
@@ -395,25 +395,21 @@ int diskmove(HANDLE dh, int start, int nimages, struct ipod_directory_t* ipod_di
{
int src_start;
int src_end;
- int dest_start;
- int dest_end;
int bytesleft;
int chunksize;
int i;
int n;
- src_start = start + ipod_directory[1].devOffset + sector_size;
- src_end = (start + ipod_directory[nimages-1].devOffset + sector_size + ipod_directory[nimages-1].len + (sector_size-1)) & ~(sector_size-1);
+ src_start = ipod_directory[1].devOffset + sector_size;
+ src_end = (ipod_directory[nimages-1].devOffset + sector_size + ipod_directory[nimages-1].len + (sector_size-1)) & ~(sector_size-1);
bytesleft = src_end - src_start;
- dest_start = start + src_start + delta;
- dest_end = start + src_end + delta;
if (verbose) {
fprintf(stderr,"[INFO] Need to move images 2-%d forward %08x bytes\n",nimages,delta);
fprintf(stderr,"[VERB] src_start = %08x\n",src_start);
fprintf(stderr,"[VERB] src_end = %08x\n",src_end);
- fprintf(stderr,"[VERB] dest_start = %08x\n",dest_start);
- fprintf(stderr,"[VERB] dest_end = %08x\n",dest_end);
+ fprintf(stderr,"[VERB] dest_start = %08x\n",src_start+delta);
+ fprintf(stderr,"[VERB] dest_end = %08x\n",src_end+delta);
fprintf(stderr,"[VERB] bytes to copy = %08x\n",bytesleft);
}
@@ -425,14 +421,16 @@ int diskmove(HANDLE dh, int start, int nimages, struct ipod_directory_t* ipod_di
}
if (verbose) {
- fprintf(stderr,"[VERB] Copying %08x bytes from %08x to %08x\n",
+ fprintf(stderr,"[VERB] Copying %08x bytes from %08x to %08x (absolute %08x to %08x)\n",
chunksize,
- dest_end-chunksize,
- dest_end-chunksize+delta);
+ src_end-chunksize,
+ src_end-chunksize+delta,
+ start+src_end-chunksize,
+ start+src_end-chunksize+delta);
}
- if (ipod_seek(dh,dest_end-chunksize) < 0) {
+ if (ipod_seek(dh,start+src_end-chunksize) < 0) {
fprintf(stderr,"[ERR] Seek failed\n");
return -1;
}
@@ -448,7 +446,7 @@ int diskmove(HANDLE dh, int start, int nimages, struct ipod_directory_t* ipod_di
return -1;
}
- if (ipod_seek(dh,dest_end-chunksize+delta) < 0) {
+ if (ipod_seek(dh,start+src_end-chunksize+delta) < 0) {
fprintf(stderr,"[ERR] Seek failed\n");
return -1;
}
@@ -464,7 +462,7 @@ int diskmove(HANDLE dh, int start, int nimages, struct ipod_directory_t* ipod_di
return -1;
}
- dest_end -= chunksize;
+ src_end -= chunksize;
bytesleft -= chunksize;
}
@@ -558,7 +556,8 @@ int add_bootloader(HANDLE dh, char* filename, int start, int sector_size,
if (nimages > 1) {
if ((entryOffset+paddedlength) >= ipod_directory[1].devOffset) {
fprintf(stderr,"[INFO] Moving images to create room for new firmware...\n");
- delta = entryOffset+paddedlength-ipod_directory[1].devOffset;
+ delta = ipod_directory[0].devOffset + entryOffset+paddedlength
+ - ipod_directory[1].devOffset;
if (diskmove(dh,start,nimages,ipod_directory,sector_size,delta) < 0) {
close(infile);