diff options
author | Miika Pekkarinen <miipekk@ihme.org> | 2006-10-16 08:34:48 +0000 |
---|---|---|
committer | Miika Pekkarinen <miipekk@ihme.org> | 2006-10-16 08:34:48 +0000 |
commit | 7c9230c64f5b4b3aba0baf4fb9ae6d38fd8ae6c2 (patch) | |
tree | b63e14bfa475b0379ae44113fba44817029ee894 /apps | |
parent | 1102afb0b033245fe57ecef931ab19cdd7893aa9 (diff) | |
download | rockbox-7c9230c64f5b4b3aba0baf4fb9ae6d38fd8ae6c2.tar.gz rockbox-7c9230c64f5b4b3aba0baf4fb9ae6d38fd8ae6c2.zip |
Don't corrupt the original firmware when updating bootloader.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@11234 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps')
-rw-r--r-- | apps/plugins/iriver_flash.c | 50 |
1 files changed, 31 insertions, 19 deletions
diff --git a/apps/plugins/iriver_flash.c b/apps/plugins/iriver_flash.c index 8cbf75ebd8..590622f6d2 100644 --- a/apps/plugins/iriver_flash.c +++ b/apps/plugins/iriver_flash.c | |||
@@ -307,7 +307,7 @@ int load_firmware_file(const char *filename, uint32_t *checksum) | |||
307 | 307 | ||
308 | if (audiobuf_size < len) | 308 | if (audiobuf_size < len) |
309 | { | 309 | { |
310 | rb->splash(HZ*3, true, "Out of memory!"); | 310 | rb->splash(HZ*3, true, "Aborting: Out of memory!"); |
311 | rb->close(fd); | 311 | rb->close(fd); |
312 | return -2; | 312 | return -2; |
313 | } | 313 | } |
@@ -320,7 +320,7 @@ int load_firmware_file(const char *filename, uint32_t *checksum) | |||
320 | rb->close(fd); | 320 | rb->close(fd); |
321 | if (rc != len) | 321 | if (rc != len) |
322 | { | 322 | { |
323 | rb->splash(HZ*3, true, "Read failure"); | 323 | rb->splash(HZ*3, true, "Aborting: Read failure"); |
324 | return -3; | 324 | return -3; |
325 | } | 325 | } |
326 | 326 | ||
@@ -331,7 +331,7 @@ int load_firmware_file(const char *filename, uint32_t *checksum) | |||
331 | 331 | ||
332 | if (sum != *checksum) | 332 | if (sum != *checksum) |
333 | { | 333 | { |
334 | rb->splash(HZ*3, true, "Checksums mismatch!"); | 334 | rb->splash(HZ*3, true, "Aborting: Checksums mismatch!"); |
335 | return -4; | 335 | return -4; |
336 | } | 336 | } |
337 | 337 | ||
@@ -387,10 +387,6 @@ int flash_rockbox(const char *filename) | |||
387 | unsigned char *p8; | 387 | unsigned char *p8; |
388 | uint16_t *p16; | 388 | uint16_t *p16; |
389 | 389 | ||
390 | len = load_firmware_file(filename, &checksum); | ||
391 | if (len <= 0) | ||
392 | return len * 10; | ||
393 | |||
394 | p8 = (char *)BOOTLOADER_ENTRYPOINT; | 390 | p8 = (char *)BOOTLOADER_ENTRYPOINT; |
395 | if (!detect_valid_bootloader(p8, 0)) | 391 | if (!detect_valid_bootloader(p8, 0)) |
396 | { | 392 | { |
@@ -409,6 +405,10 @@ int flash_rockbox(const char *filename) | |||
409 | return -3; | 405 | return -3; |
410 | } | 406 | } |
411 | 407 | ||
408 | len = load_firmware_file(filename, &checksum); | ||
409 | if (len <= 0) | ||
410 | return len * 10; | ||
411 | |||
412 | /* Erase the program flash. */ | 412 | /* Erase the program flash. */ |
413 | for (i = 1; i < BOOTLOADER_ERASEGUARD && (i-1)*4096 < len + 32; i++) | 413 | for (i = 1; i < BOOTLOADER_ERASEGUARD && (i-1)*4096 < len + 32; i++) |
414 | { | 414 | { |
@@ -475,13 +475,19 @@ void show_fatal_error(void) | |||
475 | 475 | ||
476 | int flash_bootloader(const char *filename) | 476 | int flash_bootloader(const char *filename) |
477 | { | 477 | { |
478 | char buf[32]; | 478 | char *bootsector; |
479 | int pos, i, len, rc; | 479 | int pos, i, len, rc; |
480 | unsigned long checksum, sum; | 480 | unsigned long checksum, sum; |
481 | unsigned char *p8; | 481 | unsigned char *p8; |
482 | uint16_t *p16; | 482 | uint16_t *p16; |
483 | |||
484 | bootsector = audiobuf; | ||
485 | audiobuf += SEC_SIZE; | ||
486 | audiobuf_size -= SEC_SIZE; | ||
487 | |||
488 | if (!confirm("Update bootloader?")) | ||
489 | return -2; | ||
483 | 490 | ||
484 | (void)buf; | ||
485 | len = load_firmware_file(filename, &checksum); | 491 | len = load_firmware_file(filename, &checksum); |
486 | if (len <= 0) | 492 | if (len <= 0) |
487 | return len * 10; | 493 | return len * 10; |
@@ -499,16 +505,22 @@ int flash_bootloader(const char *filename) | |||
499 | return -1; | 505 | return -1; |
500 | } | 506 | } |
501 | 507 | ||
502 | if (!confirm("Update bootloader?")) | ||
503 | return -2; | ||
504 | |||
505 | rb->lcd_puts(0, 3, "Flashing..."); | 508 | rb->lcd_puts(0, 3, "Flashing..."); |
506 | rb->lcd_update(); | 509 | rb->lcd_update(); |
507 | 510 | ||
511 | /* Backup the bootloader sector first. */ | ||
512 | p8 = (char *)FB; | ||
513 | rb->memcpy(bootsector, p8, SEC_SIZE); | ||
514 | |||
508 | /* Erase the boot sector and write a proper reset vector. */ | 515 | /* Erase the boot sector and write a proper reset vector. */ |
509 | cfi_erase_sector(FB); | 516 | cfi_erase_sector(FB); |
510 | p16 = (uint16_t *)audiobuf; | 517 | p16 = (uint16_t *)audiobuf; |
511 | for (i = 0; i < 4; i++) | 518 | for (i = 0; i < 8/2; i++) |
519 | cfi_program_word(FB + i, p16[i]); | ||
520 | |||
521 | /* And restore original content for original FW to function. */ | ||
522 | p16 = (uint16_t *)bootsector; | ||
523 | for (i = 8/2; i < SEC_SIZE/2; i++) | ||
512 | cfi_program_word(FB + i, p16[i]); | 524 | cfi_program_word(FB + i, p16[i]); |
513 | 525 | ||
514 | /* Erase the bootloader flash section. */ | 526 | /* Erase the bootloader flash section. */ |
@@ -632,6 +644,9 @@ int load_original_bin(const char *filename) | |||
632 | int len, rc; | 644 | int len, rc; |
633 | int fd; | 645 | int fd; |
634 | 646 | ||
647 | if (!confirm("Restore original firmware (bootloader will be kept)?")) | ||
648 | return -2; | ||
649 | |||
635 | fd = rb->open(filename, O_RDONLY); | 650 | fd = rb->open(filename, O_RDONLY); |
636 | if (fd < 0) | 651 | if (fd < 0) |
637 | return -1; | 652 | return -1; |
@@ -658,9 +673,6 @@ int load_original_bin(const char *filename) | |||
658 | if (len % 2) | 673 | if (len % 2) |
659 | len++; | 674 | len++; |
660 | 675 | ||
661 | if (!confirm("Restore original firmware (bootloader will be kept)?")) | ||
662 | return -2; | ||
663 | |||
664 | return flash_original_fw(len); | 676 | return flash_original_fw(len); |
665 | } | 677 | } |
666 | 678 | ||
@@ -669,6 +681,9 @@ int load_romdump(const char *filename) | |||
669 | int len, rc; | 681 | int len, rc; |
670 | int fd; | 682 | int fd; |
671 | 683 | ||
684 | if (!confirm("Restore firmware section (bootloader will be kept)?")) | ||
685 | return -2; | ||
686 | |||
672 | fd = rb->open(filename, O_RDONLY); | 687 | fd = rb->open(filename, O_RDONLY); |
673 | if (fd < 0) | 688 | if (fd < 0) |
674 | return -1; | 689 | return -1; |
@@ -693,9 +708,6 @@ int load_romdump(const char *filename) | |||
693 | if (len > BOOTLOADER_ENTRYPOINT - 8) | 708 | if (len > BOOTLOADER_ENTRYPOINT - 8) |
694 | len = BOOTLOADER_ENTRYPOINT - 8; | 709 | len = BOOTLOADER_ENTRYPOINT - 8; |
695 | 710 | ||
696 | if (!confirm("Restore firmware section (bootloader will be kept)?")) | ||
697 | return -2; | ||
698 | |||
699 | return flash_original_fw(len); | 711 | return flash_original_fw(len); |
700 | } | 712 | } |
701 | 713 | ||