summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBarry Wardell <rockbox@barrywardell.net>2007-10-14 18:09:40 +0000
committerBarry Wardell <rockbox@barrywardell.net>2007-10-14 18:09:40 +0000
commit080889a135bb5a1e34f8acae3c0a330d6bd620f5 (patch)
treec7fb29763633e23521123ee2d08cd1ded6071cff
parente6e597594dcfe31ff1447e1ca8e620e5fb3ba23e (diff)
downloadrockbox-080889a135bb5a1e34f8acae3c0a330d6bd620f5.tar.gz
rockbox-080889a135bb5a1e34f8acae3c0a330d6bd620f5.zip
Add support for installing/replacing the bootloader in the PPBL section of the firmware partition. Allows installation of the Rockbox bootloader in place of the Sandisk one. This expects a plain bootloader binary with no header. Our Rockbox bootloader successfully boots both Rockbox and the OF when installed in this way. This makes it easy to get to a state where e200tool is required, so care is advised.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@15108 a1c6a512-1295-4272-9138-f99709370657
-rw-r--r--rbutil/sansapatcher/main.c30
-rw-r--r--rbutil/sansapatcher/sansapatcher.c44
-rw-r--r--rbutil/sansapatcher/sansapatcher.h1
3 files changed, 74 insertions, 1 deletions
diff --git a/rbutil/sansapatcher/main.c b/rbutil/sansapatcher/main.c
index 4b07af14ec..fb87aec2a4 100644
--- a/rbutil/sansapatcher/main.c
+++ b/rbutil/sansapatcher/main.c
@@ -48,7 +48,8 @@ enum {
48 WRITE_FIRMWARE, 48 WRITE_FIRMWARE,
49 READ_PARTITION, 49 READ_PARTITION,
50 WRITE_PARTITION, 50 WRITE_PARTITION,
51 UPDATE_OF 51 UPDATE_OF,
52 UPDATE_PPBL
52}; 53};
53 54
54void print_usage(void) 55void print_usage(void)
@@ -67,6 +68,7 @@ void print_usage(void)
67 fprintf(stderr," -a, --add-bootloader filename.mi4\n"); 68 fprintf(stderr," -a, --add-bootloader filename.mi4\n");
68 fprintf(stderr," -d, --delete-bootloader\n"); 69 fprintf(stderr," -d, --delete-bootloader\n");
69 fprintf(stderr," -of --update-original-firmware filename.mi4\n"); 70 fprintf(stderr," -of --update-original-firmware filename.mi4\n");
71 fprintf(stderr," -bl --update-ppbl filename.bin\n");
70 fprintf(stderr,"\n"); 72 fprintf(stderr,"\n");
71 73
72#ifdef __WIN32__ 74#ifdef __WIN32__
@@ -225,6 +227,13 @@ int main(int argc, char* argv[])
225 if (i == argc) { print_usage(); return 1; } 227 if (i == argc) { print_usage(); return 1; }
226 filename=argv[i]; 228 filename=argv[i];
227 i++; 229 i++;
230 } else if ((strcmp(argv[i],"-bl")==0) ||
231 (strcmp(argv[i],"--update-ppbl")==0)) {
232 action = UPDATE_PPBL;
233 i++;
234 if (i == argc) { print_usage(); return 1; }
235 filename=argv[i];
236 i++;
228 } else if ((strcmp(argv[i],"-rf")==0) || 237 } else if ((strcmp(argv[i],"-rf")==0) ||
229 (strcmp(argv[i],"--read-firmware")==0)) { 238 (strcmp(argv[i],"--read-firmware")==0)) {
230 action = READ_FIRMWARE; 239 action = READ_FIRMWARE;
@@ -345,6 +354,25 @@ int main(int argc, char* argv[])
345 } else { 354 } else {
346 fprintf(stderr,"[ERR] --update-original-firmware failed.\n"); 355 fprintf(stderr,"[ERR] --update-original-firmware failed.\n");
347 } 356 }
357 } else if (action==UPDATE_PPBL) {
358 printf("[WARN] PPBL installation will overwrite your bootloader. This will lead to a\n");
359 printf(" Sansa that won't boot if the bootloader file is invalid. Only continue if\n");
360 printf(" you're sure you know what you're doing.\n");
361 printf(" Continue (y/n)? ");
362
363 if (fgets(yesno,4,stdin)) {
364 if (yesno[0]=='y') {
365 if (sansa_reopen_rw(&sansa) < 0) {
366 return 5;
367 }
368
369 if (sansa_update_ppbl(&sansa, filename)==0) {
370 fprintf(stderr,"[INFO] PPBL updated successfully.\n");
371 } else {
372 fprintf(stderr,"[ERR] --update-ppbl failed.\n");
373 }
374 }
375 }
348 } 376 }
349 } 377 }
350 378
diff --git a/rbutil/sansapatcher/sansapatcher.c b/rbutil/sansapatcher/sansapatcher.c
index 1f74067344..2d44e75303 100644
--- a/rbutil/sansapatcher/sansapatcher.c
+++ b/rbutil/sansapatcher/sansapatcher.c
@@ -886,3 +886,47 @@ int sansa_update_of(struct sansa_t* sansa, char* filename)
886 return 0; 886 return 0;
887} 887}
888 888
889/* Update the PPBL (bootloader) image in the hidden firmware partition */
890int sansa_update_ppbl(struct sansa_t* sansa, char* filename)
891{
892 int n;
893 int infile = -1; /* Prevent an erroneous "may be used uninitialised" gcc warning */
894 int ppbl_length = 0; /* Keep gcc happy when building for rbutil */
895
896 /* Step 1 - read bootloader into RAM. */
897 infile=open(filename,O_RDONLY|O_BINARY);
898 if (infile < 0) {
899 fprintf(stderr,"[ERR] Couldn't open input file %s\n",filename);
900 return -1;
901 }
902
903 ppbl_length = filesize(infile);
904
905 n = read(infile,sectorbuf+0x200,ppbl_length);
906 close(infile);
907 if (n < ppbl_length) {
908 fprintf(stderr,"[ERR] Short read - requested %d bytes, received %d\n", ppbl_length, n);
909 return -1;
910 }
911
912 /* Step 2 - Build the header */
913 memset(sectorbuf,0,0x200);
914 memcpy(sectorbuf,"PPBL",4);
915 int2le(ppbl_length, sectorbuf+4);
916 int2le(0x00010000, sectorbuf+8);
917
918 /* Step 3 - write the bootloader to the Sansa */
919 if (sansa_seek(sansa, sansa->start) < 0) {
920 fprintf(stderr,"[ERR] Seek to 0x%08llx in sansa_update_ppbl failed.\n", sansa->start);
921 return -1;
922 }
923
924 n=sansa_write(sansa, sectorbuf, ppbl_length + 0x200);
925 if (n < (ppbl_length+0x200)) {
926 fprintf(stderr,"[ERR] Short write in sansa_update_ppbl\n");
927 return -1;
928 }
929
930 return 0;
931}
932
diff --git a/rbutil/sansapatcher/sansapatcher.h b/rbutil/sansapatcher/sansapatcher.h
index bb9e0f1340..7f113ec083 100644
--- a/rbutil/sansapatcher/sansapatcher.h
+++ b/rbutil/sansapatcher/sansapatcher.h
@@ -37,6 +37,7 @@ int sansa_read_firmware(struct sansa_t* sansa, char* filename);
37int sansa_add_bootloader(struct sansa_t* sansa, char* filename, int type); 37int sansa_add_bootloader(struct sansa_t* sansa, char* filename, int type);
38int sansa_delete_bootloader(struct sansa_t* sansa); 38int sansa_delete_bootloader(struct sansa_t* sansa);
39int sansa_update_of(struct sansa_t* sansa,char* filename); 39int sansa_update_of(struct sansa_t* sansa,char* filename);
40int sansa_update_ppbl(struct sansa_t* sansa,char* filename);
40void sansa_list_images(struct sansa_t* sansa); 41void sansa_list_images(struct sansa_t* sansa);
41 42
42#endif 43#endif