summaryrefslogtreecommitdiff
path: root/rbutil/sansapatcher/sansapatcher.c
diff options
context:
space:
mode:
Diffstat (limited to 'rbutil/sansapatcher/sansapatcher.c')
-rw-r--r--rbutil/sansapatcher/sansapatcher.c44
1 files changed, 44 insertions, 0 deletions
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