diff options
Diffstat (limited to 'rbutil')
-rw-r--r-- | rbutil/rbutilqt/base/bootloaderinstallsansa.cpp | 6 | ||||
-rw-r--r-- | rbutil/sansapatcher/main.c | 37 | ||||
-rw-r--r-- | rbutil/sansapatcher/sansapatcher.c | 97 | ||||
-rw-r--r-- | rbutil/sansapatcher/sansapatcher.h | 6 |
4 files changed, 80 insertions, 66 deletions
diff --git a/rbutil/rbutilqt/base/bootloaderinstallsansa.cpp b/rbutil/rbutilqt/base/bootloaderinstallsansa.cpp index b07ddfad93..ae46df273d 100644 --- a/rbutil/rbutilqt/base/bootloaderinstallsansa.cpp +++ b/rbutil/rbutilqt/base/bootloaderinstallsansa.cpp | |||
@@ -96,6 +96,8 @@ bool BootloaderInstallSansa::install(void) | |||
96 | void BootloaderInstallSansa::installStage2(void) | 96 | void BootloaderInstallSansa::installStage2(void) |
97 | { | 97 | { |
98 | struct sansa_t sansa; | 98 | struct sansa_t sansa; |
99 | unsigned char* buf = NULL; | ||
100 | unsigned int len; | ||
99 | 101 | ||
100 | emit logItem(tr("Installing Rockbox bootloader"), LOGINFO); | 102 | emit logItem(tr("Installing Rockbox bootloader"), LOGINFO); |
101 | QCoreApplication::processEvents(); | 103 | QCoreApplication::processEvents(); |
@@ -130,8 +132,8 @@ void BootloaderInstallSansa::installStage2(void) | |||
130 | return; | 132 | return; |
131 | } | 133 | } |
132 | 134 | ||
133 | if(sansa_add_bootloader(&sansa, blfile.toLatin1().data(), | 135 | len = sansa_read_bootloader(&sansa, blfile.toLatin1().data(), &buf); |
134 | FILETYPE_MI4) == 0) { | 136 | if(sansa_add_bootloader(&sansa, buf, len) == 0) { |
135 | emit logItem(tr("Successfully installed bootloader"), LOGOK); | 137 | emit logItem(tr("Successfully installed bootloader"), LOGOK); |
136 | sansa_close(&sansa); | 138 | sansa_close(&sansa); |
137 | #if defined(Q_OS_MACX) | 139 | #if defined(Q_OS_MACX) |
diff --git a/rbutil/sansapatcher/main.c b/rbutil/sansapatcher/main.c index 6b65876eac..31b690509f 100644 --- a/rbutil/sansapatcher/main.c +++ b/rbutil/sansapatcher/main.c | |||
@@ -31,6 +31,8 @@ | |||
31 | #include "sansapatcher.h" | 31 | #include "sansapatcher.h" |
32 | #include "sansaio.h" | 32 | #include "sansaio.h" |
33 | #include "parttypes.h" | 33 | #include "parttypes.h" |
34 | #include "bootimg_c200.h" | ||
35 | #include "bootimg_e200.h" | ||
34 | 36 | ||
35 | #define VERSION "0.8 with v6.0 bootloaders" | 37 | #define VERSION "0.8 with v6.0 bootloaders" |
36 | 38 | ||
@@ -135,9 +137,10 @@ int main(int argc, char* argv[]) | |||
135 | int n; | 137 | int n; |
136 | char* filename; | 138 | char* filename; |
137 | int action = SHOW_INFO; | 139 | int action = SHOW_INFO; |
138 | int type; | ||
139 | struct sansa_t sansa; | 140 | struct sansa_t sansa; |
140 | int res = 0; | 141 | int res = 0; |
142 | unsigned char* buf = NULL; | ||
143 | unsigned int len; | ||
141 | 144 | ||
142 | fprintf(stderr,"sansapatcher v" VERSION " - (C) Dave Chapman 2006-2007\n"); | 145 | fprintf(stderr,"sansapatcher v" VERSION " - (C) Dave Chapman 2006-2007\n"); |
143 | fprintf(stderr,"This is free software; see the source for copying conditions. There is NO\n"); | 146 | fprintf(stderr,"This is free software; see the source for copying conditions. There is NO\n"); |
@@ -213,7 +216,6 @@ int main(int argc, char* argv[]) | |||
213 | } else if ((strcmp(argv[i],"-a")==0) || | 216 | } else if ((strcmp(argv[i],"-a")==0) || |
214 | (strcmp(argv[i],"--add-bootloader")==0)) { | 217 | (strcmp(argv[i],"--add-bootloader")==0)) { |
215 | action = ADD_BOOTLOADER; | 218 | action = ADD_BOOTLOADER; |
216 | type = FILETYPE_MI4; | ||
217 | i++; | 219 | i++; |
218 | if (i == argc) { print_usage(); return 1; } | 220 | if (i == argc) { print_usage(); return 1; } |
219 | filename=argv[i]; | 221 | filename=argv[i]; |
@@ -286,8 +288,14 @@ int main(int argc, char* argv[]) | |||
286 | if (sansa_reopen_rw(&sansa) < 0) { | 288 | if (sansa_reopen_rw(&sansa) < 0) { |
287 | res = 5; | 289 | res = 5; |
288 | } | 290 | } |
289 | 291 | if (strcmp(sansa.targetname,"c200") == 0) { | |
290 | if (sansa_add_bootloader(&sansa, NULL, FILETYPE_INTERNAL)==0) { | 292 | len = LEN_bootimg_c200; |
293 | buf = bootimg_c200; | ||
294 | } else { | ||
295 | len = LEN_bootimg_e200; | ||
296 | buf = bootimg_e200; | ||
297 | } | ||
298 | if (sansa_add_bootloader(&sansa, buf, len)==0) { | ||
291 | fprintf(stderr,"[INFO] Bootloader installed successfully.\n"); | 299 | fprintf(stderr,"[INFO] Bootloader installed successfully.\n"); |
292 | } else { | 300 | } else { |
293 | fprintf(stderr,"[ERR] --install failed.\n"); | 301 | fprintf(stderr,"[ERR] --install failed.\n"); |
@@ -317,7 +325,15 @@ int main(int argc, char* argv[]) | |||
317 | return 5; | 325 | return 5; |
318 | } | 326 | } |
319 | 327 | ||
320 | if (sansa_add_bootloader(&sansa, NULL, FILETYPE_INTERNAL)==0) { | 328 | if (strcmp(sansa.targetname,"c200") == 0) { |
329 | len = LEN_bootimg_c200; | ||
330 | buf = bootimg_c200; | ||
331 | } else { | ||
332 | len = LEN_bootimg_e200; | ||
333 | buf = bootimg_e200; | ||
334 | } | ||
335 | |||
336 | if (sansa_add_bootloader(&sansa, buf, len)==0) { | ||
321 | fprintf(stderr,"[INFO] Bootloader installed successfully.\n"); | 337 | fprintf(stderr,"[INFO] Bootloader installed successfully.\n"); |
322 | } else { | 338 | } else { |
323 | fprintf(stderr,"[ERR] --install failed.\n"); | 339 | fprintf(stderr,"[ERR] --install failed.\n"); |
@@ -327,10 +343,13 @@ int main(int argc, char* argv[]) | |||
327 | return 5; | 343 | return 5; |
328 | } | 344 | } |
329 | 345 | ||
330 | if (sansa_add_bootloader(&sansa, filename, type)==0) { | 346 | len = sansa_read_bootloader(&sansa, filename, &buf); |
331 | fprintf(stderr,"[INFO] Bootloader %s written to device.\n",filename); | 347 | if (len > 0) { |
332 | } else { | 348 | if (sansa_add_bootloader(&sansa, buf, len)==0) { |
333 | fprintf(stderr,"[ERR] --add-bootloader failed.\n"); | 349 | fprintf(stderr,"[INFO] Bootloader %s written to device.\n",filename); |
350 | } else { | ||
351 | fprintf(stderr,"[ERR] --add-bootloader failed.\n"); | ||
352 | } | ||
334 | } | 353 | } |
335 | } else if (action==DELETE_BOOTLOADER) { | 354 | } else if (action==DELETE_BOOTLOADER) { |
336 | if (sansa_reopen_rw(&sansa) < 0) { | 355 | if (sansa_reopen_rw(&sansa) < 0) { |
diff --git a/rbutil/sansapatcher/sansapatcher.c b/rbutil/sansapatcher/sansapatcher.c index 69e89e993e..9297f36e02 100644 --- a/rbutil/sansapatcher/sansapatcher.c +++ b/rbutil/sansapatcher/sansapatcher.c | |||
@@ -31,10 +31,6 @@ | |||
31 | #include "sansaio.h" | 31 | #include "sansaio.h" |
32 | #include "sansapatcher.h" | 32 | #include "sansapatcher.h" |
33 | 33 | ||
34 | #ifndef RBUTIL | ||
35 | #include "bootimg_c200.h" | ||
36 | #include "bootimg_e200.h" | ||
37 | #endif | ||
38 | /* The offset of the MI4 image header in the firmware partition */ | 34 | /* The offset of the MI4 image header in the firmware partition */ |
39 | #define PPMI_OFFSET 0x80000 | 35 | #define PPMI_OFFSET 0x80000 |
40 | #define NVPARAMS_OFFSET 0x780000 | 36 | #define NVPARAMS_OFFSET 0x780000 |
@@ -683,34 +679,55 @@ int sansa_read_firmware(struct sansa_t* sansa, const char* filename) | |||
683 | return 0; | 679 | return 0; |
684 | } | 680 | } |
685 | 681 | ||
682 | unsigned int sansa_read_bootloader(struct sansa_t* sansa, const char* filename, unsigned char** bl_buffer) | ||
683 | { | ||
684 | /* Step 1 - read bootloader into RAM. */ | ||
685 | int infile; | ||
686 | unsigned int n; | ||
687 | unsigned int len; | ||
688 | infile=open(filename,O_RDONLY|O_BINARY); | ||
689 | if (infile < 0) { | ||
690 | fprintf(stderr,"[ERR] Couldn't open input file %s\n",filename); | ||
691 | return 0; | ||
692 | } | ||
693 | |||
694 | len = filesize(infile); | ||
695 | |||
696 | unsigned char* b = malloc(len); | ||
697 | if (b == NULL) { | ||
698 | fprintf(stderr,"[ERR] Could not allocate memory for bootloader\n"); | ||
699 | close(infile); | ||
700 | return 0; | ||
701 | } | ||
702 | |||
703 | n = read(infile,b,len); | ||
704 | close(infile); | ||
705 | if (n < len) { | ||
706 | fprintf(stderr,"[ERR] Short read - requested %d bytes, received %d\n" | ||
707 | ,len,n); | ||
708 | return 0; | ||
709 | } | ||
710 | |||
711 | if (memcmp(b+0x1f8,"RBBL",4)!=0) { | ||
712 | fprintf(stderr,"[ERR] %s is not a Rockbox bootloader, aborting.\n", | ||
713 | filename); | ||
714 | return 0; | ||
715 | } | ||
716 | if (memcmp(b+0x1fc,sansa->targetname,4)!=0) { | ||
717 | fprintf(stderr,"[ERR] %s is not a Rockbox bootloader for %s, aborting.\n", | ||
718 | filename, sansa->targetname); | ||
719 | return 0; | ||
720 | } | ||
721 | *bl_buffer = b; | ||
722 | return len; | ||
723 | } | ||
686 | 724 | ||
687 | int sansa_add_bootloader(struct sansa_t* sansa, const char* filename, int type) | 725 | int sansa_add_bootloader(struct sansa_t* sansa, const unsigned char* bootloader, const unsigned int bl_length) |
688 | { | 726 | { |
689 | int res; | 727 | int res; |
690 | int infile = -1; /* Prevent an erroneous "may be used uninitialised" gcc warning */ | ||
691 | int bl_length = 0; /* Keep gcc happy when building for rbutil */ | ||
692 | struct mi4header_t mi4header; | 728 | struct mi4header_t mi4header; |
693 | int n; | ||
694 | int length; | 729 | int length; |
695 | 730 | int n; | |
696 | if (type==FILETYPE_MI4) { | ||
697 | /* Step 1 - read bootloader into RAM. */ | ||
698 | infile=open(filename,O_RDONLY|O_BINARY); | ||
699 | if (infile < 0) { | ||
700 | fprintf(stderr,"[ERR] Couldn't open input file %s\n",filename); | ||
701 | return -1; | ||
702 | } | ||
703 | |||
704 | bl_length = filesize(infile); | ||
705 | } else { | ||
706 | #ifndef RBUTIL | ||
707 | if (strcmp(sansa->targetname,"c200") == 0) { | ||
708 | bl_length = LEN_bootimg_c200; | ||
709 | } else { | ||
710 | bl_length = LEN_bootimg_e200; | ||
711 | } | ||
712 | #endif | ||
713 | } | ||
714 | 731 | ||
715 | /* Create PPMI header */ | 732 | /* Create PPMI header */ |
716 | memset(sansa_sectorbuf,0,0x200); | 733 | memset(sansa_sectorbuf,0,0x200); |
@@ -718,30 +735,8 @@ int sansa_add_bootloader(struct sansa_t* sansa, const char* filename, int type) | |||
718 | int2le(bl_length, sansa_sectorbuf+4); | 735 | int2le(bl_length, sansa_sectorbuf+4); |
719 | int2le(0x00020000, sansa_sectorbuf+8); | 736 | int2le(0x00020000, sansa_sectorbuf+8); |
720 | 737 | ||
721 | if (type==FILETYPE_MI4) { | 738 | /* copy bootloader to sansa_sectorbuf+0x200 */ |
722 | /* Read bootloader into sansa_sectorbuf+0x200 */ | 739 | memcpy(sansa_sectorbuf+0x200,bootloader,bl_length); |
723 | n = read(infile,sansa_sectorbuf+0x200,bl_length); | ||
724 | close(infile); | ||
725 | if (n < bl_length) { | ||
726 | fprintf(stderr,"[ERR] Short read - requested %d bytes, received %d\n" | ||
727 | ,bl_length,n); | ||
728 | return -1; | ||
729 | } | ||
730 | |||
731 | if (memcmp(sansa_sectorbuf+0x200+0x1f8,"RBBL",4)!=0) { | ||
732 | fprintf(stderr,"[ERR] %s is not a Rockbox bootloader, aborting.\n", | ||
733 | filename); | ||
734 | return -1; | ||
735 | } | ||
736 | } else { | ||
737 | #ifndef RBUTIL | ||
738 | if (strcmp(sansa->targetname,"c200") == 0) { | ||
739 | memcpy(sansa_sectorbuf+0x200,bootimg_c200,LEN_bootimg_c200); | ||
740 | } else { | ||
741 | memcpy(sansa_sectorbuf+0x200,bootimg_e200,LEN_bootimg_e200); | ||
742 | } | ||
743 | #endif | ||
744 | } | ||
745 | 740 | ||
746 | /* Load original firmware from Sansa to the space after the bootloader */ | 741 | /* Load original firmware from Sansa to the space after the bootloader */ |
747 | res = load_original_firmware(sansa,sansa_sectorbuf+0x200+bl_length,&mi4header); | 742 | res = load_original_firmware(sansa,sansa_sectorbuf+0x200+bl_length,&mi4header); |
diff --git a/rbutil/sansapatcher/sansapatcher.h b/rbutil/sansapatcher/sansapatcher.h index 7416e1928b..4f08eea432 100644 --- a/rbutil/sansapatcher/sansapatcher.h +++ b/rbutil/sansapatcher/sansapatcher.h | |||
@@ -34,14 +34,12 @@ extern int sansa_verbose; | |||
34 | #define BUFFER_SIZE 8*1024*1024 | 34 | #define BUFFER_SIZE 8*1024*1024 |
35 | extern unsigned char* sansa_sectorbuf; | 35 | extern unsigned char* sansa_sectorbuf; |
36 | 36 | ||
37 | #define FILETYPE_MI4 0 | ||
38 | #define FILETYPE_INTERNAL 1 | ||
39 | |||
40 | int sansa_read_partinfo(struct sansa_t* sansa, int silent); | 37 | int sansa_read_partinfo(struct sansa_t* sansa, int silent); |
41 | int is_sansa(struct sansa_t* sansa); | 38 | int is_sansa(struct sansa_t* sansa); |
42 | int sansa_scan(struct sansa_t* sansa); | 39 | int sansa_scan(struct sansa_t* sansa); |
43 | int sansa_read_firmware(struct sansa_t* sansa, const char* filename); | 40 | int sansa_read_firmware(struct sansa_t* sansa, const char* filename); |
44 | int sansa_add_bootloader(struct sansa_t* sansa, const char* filename, int type); | 41 | unsigned int sansa_read_bootloader(struct sansa_t* sansa, const char* filename, unsigned char** bl_buffer); |
42 | int sansa_add_bootloader(struct sansa_t* sansa, const unsigned char* buf, unsigned int len); | ||
45 | int sansa_delete_bootloader(struct sansa_t* sansa); | 43 | int sansa_delete_bootloader(struct sansa_t* sansa); |
46 | int sansa_update_of(struct sansa_t* sansa,const char* filename); | 44 | int sansa_update_of(struct sansa_t* sansa,const char* filename); |
47 | int sansa_update_ppbl(struct sansa_t* sansa,const char* filename); | 45 | int sansa_update_ppbl(struct sansa_t* sansa,const char* filename); |