From ff6b0425e438add8d12393f90fdbfe93e1fb4746 Mon Sep 17 00:00:00 2001 From: Rafaël Carré Date: Mon, 24 May 2010 10:06:52 +0000 Subject: mkamsboot/rbutil/amsinfo : do not try to detect the model of a given Sansa AMS OF The field we thought was representative of the model is not, it has changed in the past for fuzev1 and fuzev2. For example the value 0x23 is found in 2 old fuzev1 OF versions, and in the c200v2 OF The only reliable way to detect the model of a given OF is by using the built-in list of md5sums. Modify mkamsboot and rbutilqt to load the rockbox bootloader first, and then check if the model in the bootloader corresponds to the model of the known md5sum of the given OF. That way we can continue to present the user with a list of known OF versions in case the OF is unknown to mkamsboot Also explicit the dependency of main.c on mkamsboot.h in case the prototypes change Correct the header's description not updated in r21648 git-svn-id: svn://svn.rockbox.org/rockbox/trunk@26248 a1c6a512-1295-4272-9138-f99709370657 --- rbutil/mkamsboot/mkamsboot.c | 63 +++++++++++++------------------------------- 1 file changed, 19 insertions(+), 44 deletions(-) (limited to 'rbutil/mkamsboot/mkamsboot.c') diff --git a/rbutil/mkamsboot/mkamsboot.c b/rbutil/mkamsboot/mkamsboot.c index 1ec9ec26e6..f47afe312a 100644 --- a/rbutil/mkamsboot/mkamsboot.c +++ b/rbutil/mkamsboot/mkamsboot.c @@ -323,30 +323,6 @@ static uint32_t calc_checksum(unsigned char* buf, uint32_t n) return sum; } -static int get_model(int model_id) -{ - switch(model_id) { - case 0x1e: - return MODEL_FUZE; - case 0x22: - return MODEL_CLIP; - case 0x23: - return MODEL_C200V2; - case 0x24: - return MODEL_E200V2; - case 0x25: - return MODEL_M200V4; - case 0x27: - return MODEL_CLIPV2; - case 0x28: - return MODEL_CLIPPLUS; - case 0x70: - return MODEL_FUZEV2; - } - - return MODEL_UNKNOWN; -} - /* Compress using nrv2e algorithm : Thumb decompressor fits in 168 bytes ! */ static unsigned char* uclpack(unsigned char* inbuf, int insize, int* outsize) { @@ -388,7 +364,7 @@ static unsigned char* uclpack(unsigned char* inbuf, int insize, int* outsize) /* Loads a Sansa AMS Original Firmware file into memory */ unsigned char* load_of_file( - char* filename, off_t* bufsize, struct md5sums *sum, + char* filename, int model, off_t* bufsize, struct md5sums *sum, int* firmware_size, unsigned char** of_packed, int* of_packedsize, char* errstr, int errstrsize) { @@ -397,7 +373,6 @@ unsigned char* load_of_file( off_t n; unsigned int i=0; uint32_t checksum; - int model_id; unsigned int last_word; fd = open(filename, O_RDONLY|O_BINARY); @@ -425,21 +400,20 @@ unsigned char* load_of_file( if (i < NUM_MD5S) { *sum = sansasums[i]; + if(sum->model != model) { + ERROR("[ERR] OF File provided is %sv%d version %s, not for %sv%d\n", + model_names[sum->model], hw_revisions[sum->model], + sum->version, model_names[model], hw_revisions[model] + ); + } } else { - int fw_version = (get_uint32le(&buf[0x204]) == 0x0000f000) ? 2 : 1; - model_id = buf[(fw_version == 2) ? 0x219 : 0x215]; - sum->model = get_model(model_id); - - if (sum->model == MODEL_UNKNOWN) - ERROR("[ERR] Unknown firmware model (v%d) - model id 0x%02x\n", - fw_version, model_id); + /* OF unknown, give a list of tested versions for the requested model */ -#if 1 /* comment to test new OFs */ char tested_versions[100]; tested_versions[0] = '\0'; for (i = 0; i < NUM_MD5S ; i++) - if (sansasums[i].model == sum->model) { + if (sansasums[i].model == model) { if (tested_versions[0] != '\0') { strncat(tested_versions, ", ", sizeof(tested_versions) - strlen(tested_versions) - 1); @@ -449,9 +423,8 @@ unsigned char* load_of_file( } ERROR("[ERR] Original firmware unknown, please try an other version." \ - " Tested %s versions are : %s\n", - model_names[sum->model], tested_versions); -#endif + " Tested %sv%d versions are : %s\n", + model_names[model], hw_revisions[model], tested_versions); } /* TODO: Do some more sanity checks on the OF image. Some images (like @@ -484,7 +457,7 @@ error: /* Loads a rockbox bootloader file into memory */ unsigned char* load_rockbox_file( - char* filename, int model, int* bufsize, int* rb_packedsize, + char* filename, int *model, int* bufsize, int* rb_packedsize, char* errstr, int errstrsize) { int fd; @@ -504,10 +477,12 @@ unsigned char* load_rockbox_file( if (n != sizeof(header)) ERROR("[ERR] Could not read file %s\n", filename); - /* Check for correct model string */ - if (memcmp(rb_model_names[model], header + 4, 4)!=0) - ERROR("[ERR] Expected model name \"%s\" in %s, not \"%4.4s\"\n", - rb_model_names[model], filename, (char*)header+4); + for(*model = 0; *model < NUM_MODELS; (*model)++) + if (memcmp(rb_model_names[*model], header + 4, 4) == 0) + break; + + if(*model == NUM_MODELS) + ERROR("[ERR] Model name \"%4.4s\" unknown. Is this really a rockbox bootloader?\n", header + 4); *bufsize = filesize(fd) - sizeof(header); @@ -521,7 +496,7 @@ unsigned char* load_rockbox_file( ERROR("[ERR] Could not read file %s\n", filename); /* Check checksum */ - sum = rb_model_num[model]; + sum = rb_model_num[*model]; for (i = 0; i < *bufsize; i++) { /* add 8 unsigned bits but keep a 32 bit sum */ sum += buf[i]; -- cgit v1.2.3