diff --git a/bootloader/main-pp.c b/bootloader/main-pp.c index b0add13fb4..0262384d91 100644 --- a/bootloader/main-pp.c +++ b/bootloader/main-pp.c @@ -344,32 +344,6 @@ int load_mi4(unsigned char* buf, char* firmware, unsigned int buffer_size) } #if defined(SANSA_E200) || defined(SANSA_C200) -#ifdef SANSA_E200 -struct OFDB_info { - char *version; - int version_length; - int sector; - int offset; -} OFDatabaseOffsets[] = { - { "PP5022AF-05.51-S301-01.11-S301.01.11A-D", 39, 0x3c08, 0xe1 }, - { "PP5022AF-05.51-S301-00.12-S301.00.12E-D", 39, 0x3c5c, 0x2 }, - { "PP5022AF-05.51-S301-00.12-S301.00.12A-D", 39, 0x3c08, 0xe1 }, - { "PP5022AF-05.51-S301-02.15-S301.02.15E-D", 39, 0x3c08, 0xe1 }, - { "PP5022AF-05.51-S301-02.18-S301.02.18A-D", 39, 0x3c08, 0xe1 }, - { "PP5022AF-05.51-S301-02.18-S301.02.18E-D", 39, 0x3c08, 0xe1 } -}; -#else /* SANSA_C200 */ -/* TODO: need to determine these for the c200 */ -struct OFDB_info { - char *version; - int version_length; - int sector; - int offset; -} OFDatabaseOffsets[] = { - { "PP5022AF-05.51-S301-01.11-S301.01.11A-D", 39, 0x3c08, 0xe1 }, -}; -#endif - /* Load mi4 firmware from a hidden disk partition */ int load_mi4_part(unsigned char* buf, struct partinfo* pinfo, unsigned int buffer_size, bool disable_rebuild) @@ -424,31 +398,19 @@ int load_mi4_part(unsigned char* buf, struct partinfo* pinfo, if(sum != mi4header.crc32) return EBAD_CHKSUM; +#ifdef SANSA_E200 if (disable_rebuild) { char block[512]; - int sector = 0, offset = 0; - unsigned int i; - /* check which known version we have */ - /* These are taken from the PPPS section, 0x00780240 */ - ata_read_sectors(IF_MV2(0,) pinfo->start + 0x3C01, 1, block); - for (i=0; istart + OFDatabaseOffsets[i].sector; - offset = OFDatabaseOffsets[i].offset; - break; - } - } - if (sector && offset) - { - ata_read_sectors(IF_MV2(0,) sector, 1, block); - block[offset] = 0; - ata_write_sectors(IF_MV2(0,) sector, 1, block); - } + + printf("Disabling database rebuild"); + + ata_read_sectors(IF_MV2(0,) pinfo->start + 0x3c08, 1, block); + block[0xe1] = 0; + ata_write_sectors(IF_MV2(0,) pinfo->start + 0x3c08, 1, block); } +#endif + return EOK; } #endif diff --git a/rbutil/sansapatcher/sansapatcher.c b/rbutil/sansapatcher/sansapatcher.c index 2d44e75303..bc03108930 100644 --- a/rbutil/sansapatcher/sansapatcher.c +++ b/rbutil/sansapatcher/sansapatcher.c @@ -34,7 +34,9 @@ #include "bootimg_e200.h" #endif /* The offset of the MI4 image header in the firmware partition */ -#define PPMI_OFFSET 0x80000 +#define PPMI_OFFSET 0x80000 +#define NVPARAMS_OFFSET 0x780000 +#define NVPARAMS_SIZE (0x80000-0x200) extern int verbose; @@ -882,7 +884,26 @@ int sansa_update_of(struct sansa_t* sansa, char* filename) fprintf(stderr,"[ERR] Short write in sansa_update_of\n"); return -1; } - + + /* Step 4 - zero out the nvparams section - we have to do this or we end up + with multiple copies of the nvparams data and don't know which one to + work with for the database rebuild disabling trick in our bootloader */ + if (strcmp(sansa->targetname,"e200") == 0) { + printf("[INFO] Resetting Original Firmware settings\n"); + if (sansa_seek(sansa, sansa->start+NVPARAMS_OFFSET+0x200) < 0) { + fprintf(stderr,"[ERR] Seek to 0x%08llx in sansa_update_of failed.\n", + sansa->start+NVPARAMS_OFFSET+0x200); + return -1; + } + + memset(sectorbuf,0,NVPARAMS_SIZE); + n=sansa_write(sansa, sectorbuf, NVPARAMS_SIZE); + if (n < NVPARAMS_SIZE) { + fprintf(stderr,"[ERR] Short write in sansa_update_of\n"); + return -1; + } + } + return 0; }