summaryrefslogtreecommitdiffstats
path: root/rbutil/sansapatcher/sansapatcher.c
diff options
context:
space:
mode:
authorDave Chapman <dave@dchapman.com>2007-03-15 23:26:47 +0000
committerDave Chapman <dave@dchapman.com>2007-03-15 23:26:47 +0000
commite815601afb0eabe1ef59a2e8d1e0a746c4c33c34 (patch)
tree69ba3d9bc54042bafa03b5917f2a45dc454a1705 /rbutil/sansapatcher/sansapatcher.c
parent4a812912846dd5f02f3c8aa81af59b2d1cb67b65 (diff)
downloadrockbox-e815601afb0eabe1ef59a2e8d1e0a746c4c33c34.tar.gz
rockbox-e815601afb0eabe1ef59a2e8d1e0a746c4c33c34.zip
Implement the ability to embed a bootloader in sansapatcher - the --install option installs the embedded bootloader, and running without any parameters will cause a prompt to be displayed asking the user if they want to install, uninstall or cancel. sansapatcher now requres a PP5022.mi4 file (the Rockbox bootloader) in the current directory when building.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@12794 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'rbutil/sansapatcher/sansapatcher.c')
-rw-r--r--rbutil/sansapatcher/sansapatcher.c35
1 files changed, 21 insertions, 14 deletions
diff --git a/rbutil/sansapatcher/sansapatcher.c b/rbutil/sansapatcher/sansapatcher.c
index a19c60eaa0..3c6848e6d4 100644
--- a/rbutil/sansapatcher/sansapatcher.c
+++ b/rbutil/sansapatcher/sansapatcher.c
@@ -539,7 +539,6 @@ int load_original_firmware(struct sansa_t* sansa, unsigned char* buf, struct mi4
}
if (key_found) {
-printf("Key found - %d\n",i);
memcpy(buf+(mi4header->plaintext+0x200),tmpbuf,mi4header->mi4size-(mi4header->plaintext+0x200));
free(tmpbuf);
} else {
@@ -593,14 +592,18 @@ int add_bootloader(struct sansa_t* sansa, char* filename, int type)
int n;
int length;
- /* Step 1 - read bootloader into RAM. */
- infile=open(filename,O_RDONLY|O_BINARY);
- if (infile < 0) {
- fprintf(stderr,"[ERR] Couldn't open input file %s\n",filename);
- return -1;
- }
+ if (type==FILETYPE_MI4) {
+ /* Step 1 - read bootloader into RAM. */
+ infile=open(filename,O_RDONLY|O_BINARY);
+ if (infile < 0) {
+ fprintf(stderr,"[ERR] Couldn't open input file %s\n",filename);
+ return -1;
+ }
- bl_length = filesize(infile);
+ bl_length = filesize(infile);
+ } else {
+ bl_length = LEN_bootimg;
+ }
/* Create PPMI header */
memset(sectorbuf,0,0x200);
@@ -608,12 +611,16 @@ int add_bootloader(struct sansa_t* sansa, char* filename, int type)
int2le(bl_length, sectorbuf+4);
int2le(0x00020000, sectorbuf+8);
- /* Read bootloader into sectorbuf+0x200 */
- n = read(infile,sectorbuf+0x200,bl_length);
- if (n < bl_length) {
- fprintf(stderr,"[ERR] Short read - requested %d bytes, received %d\n"
- ,bl_length,n);
- return -1;
+ if (type==FILETYPE_MI4) {
+ /* Read bootloader into sectorbuf+0x200 */
+ n = read(infile,sectorbuf+0x200,bl_length);
+ if (n < bl_length) {
+ fprintf(stderr,"[ERR] Short read - requested %d bytes, received %d\n"
+ ,bl_length,n);
+ return -1;
+ }
+ } else {
+ memcpy(sectorbuf+0x200,bootimg,LEN_bootimg);
}
/* Load original firmware from Sansa to the space after the bootloader */