summaryrefslogtreecommitdiff
path: root/rbutil/mkamsboot/mkamsboot.c
diff options
context:
space:
mode:
authorRafaël Carré <rafael.carre@gmail.com>2010-05-24 10:06:52 +0000
committerRafaël Carré <rafael.carre@gmail.com>2010-05-24 10:06:52 +0000
commitff6b0425e438add8d12393f90fdbfe93e1fb4746 (patch)
treeb8ac1a3254a8e01051a5d7f2c5c94e61bacd5c02 /rbutil/mkamsboot/mkamsboot.c
parenteae2464e9a93dc3a8918abcc62348af6c8d9bc9b (diff)
downloadrockbox-ff6b0425e438add8d12393f90fdbfe93e1fb4746.tar.gz
rockbox-ff6b0425e438add8d12393f90fdbfe93e1fb4746.zip
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
Diffstat (limited to 'rbutil/mkamsboot/mkamsboot.c')
-rw-r--r--rbutil/mkamsboot/mkamsboot.c63
1 files changed, 19 insertions, 44 deletions
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)
323 return sum; 323 return sum;
324} 324}
325 325
326static int get_model(int model_id)
327{
328 switch(model_id) {
329 case 0x1e:
330 return MODEL_FUZE;
331 case 0x22:
332 return MODEL_CLIP;
333 case 0x23:
334 return MODEL_C200V2;
335 case 0x24:
336 return MODEL_E200V2;
337 case 0x25:
338 return MODEL_M200V4;
339 case 0x27:
340 return MODEL_CLIPV2;
341 case 0x28:
342 return MODEL_CLIPPLUS;
343 case 0x70:
344 return MODEL_FUZEV2;
345 }
346
347 return MODEL_UNKNOWN;
348}
349
350/* Compress using nrv2e algorithm : Thumb decompressor fits in 168 bytes ! */ 326/* Compress using nrv2e algorithm : Thumb decompressor fits in 168 bytes ! */
351static unsigned char* uclpack(unsigned char* inbuf, int insize, int* outsize) 327static unsigned char* uclpack(unsigned char* inbuf, int insize, int* outsize)
352{ 328{
@@ -388,7 +364,7 @@ static unsigned char* uclpack(unsigned char* inbuf, int insize, int* outsize)
388 364
389/* Loads a Sansa AMS Original Firmware file into memory */ 365/* Loads a Sansa AMS Original Firmware file into memory */
390unsigned char* load_of_file( 366unsigned char* load_of_file(
391 char* filename, off_t* bufsize, struct md5sums *sum, 367 char* filename, int model, off_t* bufsize, struct md5sums *sum,
392 int* firmware_size, unsigned char** of_packed, 368 int* firmware_size, unsigned char** of_packed,
393 int* of_packedsize, char* errstr, int errstrsize) 369 int* of_packedsize, char* errstr, int errstrsize)
394{ 370{
@@ -397,7 +373,6 @@ unsigned char* load_of_file(
397 off_t n; 373 off_t n;
398 unsigned int i=0; 374 unsigned int i=0;
399 uint32_t checksum; 375 uint32_t checksum;
400 int model_id;
401 unsigned int last_word; 376 unsigned int last_word;
402 377
403 fd = open(filename, O_RDONLY|O_BINARY); 378 fd = open(filename, O_RDONLY|O_BINARY);
@@ -425,21 +400,20 @@ unsigned char* load_of_file(
425 400
426 if (i < NUM_MD5S) { 401 if (i < NUM_MD5S) {
427 *sum = sansasums[i]; 402 *sum = sansasums[i];
403 if(sum->model != model) {
404 ERROR("[ERR] OF File provided is %sv%d version %s, not for %sv%d\n",
405 model_names[sum->model], hw_revisions[sum->model],
406 sum->version, model_names[model], hw_revisions[model]
407 );
408 }
428 } else { 409 } else {
429 int fw_version = (get_uint32le(&buf[0x204]) == 0x0000f000) ? 2 : 1; 410 /* OF unknown, give a list of tested versions for the requested model */
430 model_id = buf[(fw_version == 2) ? 0x219 : 0x215];
431 sum->model = get_model(model_id);
432
433 if (sum->model == MODEL_UNKNOWN)
434 ERROR("[ERR] Unknown firmware model (v%d) - model id 0x%02x\n",
435 fw_version, model_id);
436 411
437#if 1 /* comment to test new OFs */
438 char tested_versions[100]; 412 char tested_versions[100];
439 tested_versions[0] = '\0'; 413 tested_versions[0] = '\0';
440 414
441 for (i = 0; i < NUM_MD5S ; i++) 415 for (i = 0; i < NUM_MD5S ; i++)
442 if (sansasums[i].model == sum->model) { 416 if (sansasums[i].model == model) {
443 if (tested_versions[0] != '\0') { 417 if (tested_versions[0] != '\0') {
444 strncat(tested_versions, ", ", 418 strncat(tested_versions, ", ",
445 sizeof(tested_versions) - strlen(tested_versions) - 1); 419 sizeof(tested_versions) - strlen(tested_versions) - 1);
@@ -449,9 +423,8 @@ unsigned char* load_of_file(
449 } 423 }
450 424
451 ERROR("[ERR] Original firmware unknown, please try an other version." \ 425 ERROR("[ERR] Original firmware unknown, please try an other version." \
452 " Tested %s versions are : %s\n", 426 " Tested %sv%d versions are : %s\n",
453 model_names[sum->model], tested_versions); 427 model_names[model], hw_revisions[model], tested_versions);
454#endif
455 } 428 }
456 429
457 /* TODO: Do some more sanity checks on the OF image. Some images (like 430 /* TODO: Do some more sanity checks on the OF image. Some images (like
@@ -484,7 +457,7 @@ error:
484 457
485/* Loads a rockbox bootloader file into memory */ 458/* Loads a rockbox bootloader file into memory */
486unsigned char* load_rockbox_file( 459unsigned char* load_rockbox_file(
487 char* filename, int model, int* bufsize, int* rb_packedsize, 460 char* filename, int *model, int* bufsize, int* rb_packedsize,
488 char* errstr, int errstrsize) 461 char* errstr, int errstrsize)
489{ 462{
490 int fd; 463 int fd;
@@ -504,10 +477,12 @@ unsigned char* load_rockbox_file(
504 if (n != sizeof(header)) 477 if (n != sizeof(header))
505 ERROR("[ERR] Could not read file %s\n", filename); 478 ERROR("[ERR] Could not read file %s\n", filename);
506 479
507 /* Check for correct model string */ 480 for(*model = 0; *model < NUM_MODELS; (*model)++)
508 if (memcmp(rb_model_names[model], header + 4, 4)!=0) 481 if (memcmp(rb_model_names[*model], header + 4, 4) == 0)
509 ERROR("[ERR] Expected model name \"%s\" in %s, not \"%4.4s\"\n", 482 break;
510 rb_model_names[model], filename, (char*)header+4); 483
484 if(*model == NUM_MODELS)
485 ERROR("[ERR] Model name \"%4.4s\" unknown. Is this really a rockbox bootloader?\n", header + 4);
511 486
512 *bufsize = filesize(fd) - sizeof(header); 487 *bufsize = filesize(fd) - sizeof(header);
513 488
@@ -521,7 +496,7 @@ unsigned char* load_rockbox_file(
521 ERROR("[ERR] Could not read file %s\n", filename); 496 ERROR("[ERR] Could not read file %s\n", filename);
522 497
523 /* Check checksum */ 498 /* Check checksum */
524 sum = rb_model_num[model]; 499 sum = rb_model_num[*model];
525 for (i = 0; i < *bufsize; i++) { 500 for (i = 0; i < *bufsize; i++) {
526 /* add 8 unsigned bits but keep a 32 bit sum */ 501 /* add 8 unsigned bits but keep a 32 bit sum */
527 sum += buf[i]; 502 sum += buf[i];