From e815601afb0eabe1ef59a2e8d1e0a746c4c33c34 Mon Sep 17 00:00:00 2001 From: Dave Chapman Date: Thu, 15 Mar 2007 23:26:47 +0000 Subject: 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 --- rbutil/sansapatcher/sansapatcher.c | 35 +++++++++++++++++++++-------------- 1 file changed, 21 insertions(+), 14 deletions(-) (limited to 'rbutil/sansapatcher/sansapatcher.c') 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 */ -- cgit v1.2.3