diff options
-rw-r--r-- | apps/plugins/firmware_flash.c | 89 | ||||
-rw-r--r-- | apps/plugins/rockbox_flash.c | 2 |
2 files changed, 80 insertions, 11 deletions
diff --git a/apps/plugins/firmware_flash.c b/apps/plugins/firmware_flash.c index 88201b23dd..82e914d99a 100644 --- a/apps/plugins/firmware_flash.c +++ b/apps/plugins/firmware_flash.c | |||
@@ -21,9 +21,7 @@ | |||
21 | ****************************************************************************/ | 21 | ****************************************************************************/ |
22 | #include "plugin.h" | 22 | #include "plugin.h" |
23 | 23 | ||
24 | #ifndef ARCHOS_RECORDERV2 | 24 | #ifndef SIMULATOR /* only for target */ |
25 | |||
26 | #ifndef SIMULATOR | ||
27 | 25 | ||
28 | /* define DUMMY if you only want to "play" with the UI, does no harm */ | 26 | /* define DUMMY if you only want to "play" with the UI, does no harm */ |
29 | /* #define DUMMY */ | 27 | /* #define DUMMY */ |
@@ -40,15 +38,28 @@ | |||
40 | #define UINT32 unsigned long | 38 | #define UINT32 unsigned long |
41 | #endif | 39 | #endif |
42 | 40 | ||
41 | /* platform IDs as I have used them in my firmware templates */ | ||
42 | #define ID_RECORDER 0 | ||
43 | #define ID_FM 1 | ||
44 | #define ID_PLAYER 2 | ||
45 | #define ID_REC_V2 3 | ||
46 | |||
43 | #if defined(ARCHOS_PLAYER) | 47 | #if defined(ARCHOS_PLAYER) |
44 | #define FILE_TYPE "player" | 48 | #define FILE_TYPE "player" |
45 | #define KEEP VERSION_ADR /* keep the firmware version */ | 49 | #define KEEP VERSION_ADR /* keep the firmware version */ |
50 | #define PLATFORM_ID ID_PLAYER | ||
46 | #elif defined(ARCHOS_RECORDER) | 51 | #elif defined(ARCHOS_RECORDER) |
47 | #define FILE_TYPE "rec" | 52 | #define FILE_TYPE "rec" |
48 | #define KEEP MASK_ADR /* keep the mask value */ | 53 | #define KEEP MASK_ADR /* keep the mask value */ |
54 | #define PLATFORM_ID ID_RECORDER | ||
55 | #elif defined(ARCHOS_RECORDERV2) | ||
56 | #define FILE_TYPE "v2" | ||
57 | #define KEEP MASK_ADR /* keep the mask value */ | ||
58 | #define PLATFORM_ID ID_REC_V2 | ||
49 | #elif defined(ARCHOS_FMRECORDER) | 59 | #elif defined(ARCHOS_FMRECORDER) |
50 | #define FILE_TYPE "fm" | 60 | #define FILE_TYPE "fm" |
51 | #define KEEP MASK_ADR /* keep the mask value */ | 61 | #define KEEP MASK_ADR /* keep the mask value */ |
62 | #define PLATFORM_ID ID_FM | ||
52 | #else | 63 | #else |
53 | #error ("No known platform given!") | 64 | #error ("No known platform given!") |
54 | #endif | 65 | #endif |
@@ -63,6 +74,7 @@ typedef enum | |||
63 | eReadErr, | 74 | eReadErr, |
64 | eBadContent, | 75 | eBadContent, |
65 | eCrcErr, | 76 | eCrcErr, |
77 | eBadPlatform, | ||
66 | } tCheckResult; | 78 | } tCheckResult; |
67 | 79 | ||
68 | /* result of the CheckBootROM() function */ | 80 | /* result of the CheckBootROM() function */ |
@@ -83,8 +95,9 @@ typedef struct | |||
83 | 95 | ||
84 | static struct plugin_api* rb; /* here is a global api struct pointer */ | 96 | static struct plugin_api* rb; /* here is a global api struct pointer */ |
85 | 97 | ||
86 | #define MASK_ADR 0xFC /* position of hardware mask value in Flash */ | 98 | #define MASK_ADR 0xFC /* position of hardware mask value in Flash */ |
87 | #define VERSION_ADR 0xFE /* position of firmware version value in Flash */ | 99 | #define VERSION_ADR 0xFE /* position of firmware version value in Flash */ |
100 | #define PLATFORM_ADR 0xFB /* position of my platform ID value in Flash */ | ||
88 | #define SEC_SIZE 4096 /* size of one flash sector */ | 101 | #define SEC_SIZE 4096 /* size of one flash sector */ |
89 | static UINT8* sector; /* better not place this on the stack... */ | 102 | static UINT8* sector; /* better not place this on the stack... */ |
90 | static volatile UINT8* FB = (UINT8*)0x02000000; /* Flash base address */ | 103 | static volatile UINT8* FB = (UINT8*)0x02000000; /* Flash base address */ |
@@ -252,7 +265,27 @@ unsigned crc_32(unsigned char* buf, unsigned len, unsigned crc32) | |||
252 | } | 265 | } |
253 | 266 | ||
254 | 267 | ||
255 | /*********** Firmware File Functions ************/ | 268 | /*********** Firmware File Functions + helpers ************/ |
269 | |||
270 | /* test if the version number is consistent with the platform */ | ||
271 | bool CheckPlatform(int platform_id, UINT16 version) | ||
272 | { | ||
273 | if (version == 123) | ||
274 | { /* it can be a FM or V2 recorder */ | ||
275 | return (platform_id == ID_FM || platform_id == ID_REC_V2); | ||
276 | } | ||
277 | else if ((version >= 124 && version <= 128) || version == 200) | ||
278 | { /* for my very first firmware, I foolishly changed it to 200 */ | ||
279 | return (platform_id == ID_RECORDER); | ||
280 | } | ||
281 | else if (version == 0 || (version >= 300 && version <= 506)) | ||
282 | { /* for very old players, I've seen zero */ | ||
283 | return (platform_id == ID_PLAYER); | ||
284 | } | ||
285 | |||
286 | return false; /* unknown */ | ||
287 | } | ||
288 | |||
256 | 289 | ||
257 | tCheckResult CheckFirmwareFile(char* filename, int chipsize, bool is_romless) | 290 | tCheckResult CheckFirmwareFile(char* filename, int chipsize, bool is_romless) |
258 | { | 291 | { |
@@ -283,7 +316,7 @@ tCheckResult CheckFirmwareFile(char* filename, int chipsize, bool is_romless) | |||
283 | } | 316 | } |
284 | 317 | ||
285 | if (fileleft == 256*1024) | 318 | if (fileleft == 256*1024) |
286 | { // original dumped firmware file has no CRC | 319 | { // original dumped firmware file has no CRC nor platform ID |
287 | has_crc = false; | 320 | has_crc = false; |
288 | } | 321 | } |
289 | else | 322 | else |
@@ -303,8 +336,24 @@ tCheckResult CheckFirmwareFile(char* filename, int chipsize, bool is_romless) | |||
303 | return eReadErr; | 336 | return eReadErr; |
304 | } | 337 | } |
305 | 338 | ||
339 | // version number in file plausible with this hardware? | ||
340 | if (!CheckPlatform(PLATFORM_ID, *(UINT16*)(sector + VERSION_ADR))) | ||
341 | { | ||
342 | rb->close(fd); | ||
343 | return eBadPlatform; | ||
344 | } | ||
345 | |||
306 | if (has_crc) | 346 | if (has_crc) |
347 | { | ||
307 | crc32 = crc_32(sector, SEC_SIZE, crc32); /* checksum */ | 348 | crc32 = crc_32(sector, SEC_SIZE, crc32); /* checksum */ |
349 | |||
350 | /* in addition to the CRC, my files also have a platform ID */ | ||
351 | if (sector[PLATFORM_ADR] != PLATFORM_ID) /* for our hardware? */ | ||
352 | { | ||
353 | rb->close(fd); | ||
354 | return eBadPlatform; | ||
355 | } | ||
356 | } | ||
308 | 357 | ||
309 | if (is_romless) | 358 | if (is_romless) |
310 | { /* in this case, there is not much we can check */ | 359 | { /* in this case, there is not much we can check */ |
@@ -419,6 +468,7 @@ unsigned ProgramFirmwareFile(char* filename, int chipsize) | |||
419 | return failures; | 468 | return failures; |
420 | } | 469 | } |
421 | 470 | ||
471 | |||
422 | /* returns the # of failures, 0 on success */ | 472 | /* returns the # of failures, 0 on success */ |
423 | unsigned VerifyFirmwareFile(char* filename) | 473 | unsigned VerifyFirmwareFile(char* filename) |
424 | { | 474 | { |
@@ -452,6 +502,7 @@ unsigned VerifyFirmwareFile(char* filename) | |||
452 | return failures; | 502 | return failures; |
453 | } | 503 | } |
454 | 504 | ||
505 | |||
455 | /***************** Support Functions *****************/ | 506 | /***************** Support Functions *****************/ |
456 | 507 | ||
457 | /* check if we have "normal" boot ROM or flash mirrored to zero */ | 508 | /* check if we have "normal" boot ROM or flash mirrored to zero */ |
@@ -544,6 +595,13 @@ void DoUserDialog(char* filename) | |||
544 | 595 | ||
545 | rb->lcd_setfont(FONT_SYSFIXED); | 596 | rb->lcd_setfont(FONT_SYSFIXED); |
546 | 597 | ||
598 | /* test if the user is running the correct plugin for this box */ | ||
599 | if (!CheckPlatform(PLATFORM_ID, *(UINT16*)(FB + VERSION_ADR))) | ||
600 | { | ||
601 | rb->splash(HZ*3, 0, true, "Wrong plugin"); | ||
602 | return; /* exit */ | ||
603 | } | ||
604 | |||
547 | /* check boot ROM */ | 605 | /* check boot ROM */ |
548 | result = CheckBootROM(); | 606 | result = CheckBootROM(); |
549 | if (result == eUnknown) | 607 | if (result == eUnknown) |
@@ -629,6 +687,10 @@ void DoUserDialog(char* filename) | |||
629 | rb->lcd_puts(0, 2, "CRC check failed,"); | 687 | rb->lcd_puts(0, 2, "CRC check failed,"); |
630 | rb->lcd_puts(0, 3, "checksum mismatch."); | 688 | rb->lcd_puts(0, 3, "checksum mismatch."); |
631 | break; | 689 | break; |
690 | case eBadPlatform: | ||
691 | rb->lcd_puts(0, 1, "Wrong file for"); | ||
692 | rb->lcd_puts(0, 2, "this hardware."); | ||
693 | break; | ||
632 | default: | 694 | default: |
633 | rb->lcd_puts(0, 1, "Check failed."); | 695 | rb->lcd_puts(0, 1, "Check failed."); |
634 | break; | 696 | break; |
@@ -754,6 +816,13 @@ void DoUserDialog(char* filename) | |||
754 | tCheckROM result; | 816 | tCheckROM result; |
755 | bool is_romless; | 817 | bool is_romless; |
756 | 818 | ||
819 | /* test if the user is running the correct plugin for this box */ | ||
820 | if (!CheckPlatform(PLATFORM_ID, *(UINT16*)(FB + VERSION_ADR))) | ||
821 | { | ||
822 | rb->splash(HZ*3, 0, true, "Wrong plugin"); | ||
823 | return; /* exit */ | ||
824 | } | ||
825 | |||
757 | /* check boot ROM */ | 826 | /* check boot ROM */ |
758 | result = CheckBootROM(); | 827 | result = CheckBootROM(); |
759 | if (result == eUnknown) | 828 | if (result == eUnknown) |
@@ -833,6 +902,10 @@ void DoUserDialog(char* filename) | |||
833 | rb->lcd_puts_scroll(0, 0, "File invalid."); | 902 | rb->lcd_puts_scroll(0, 0, "File invalid."); |
834 | rb->lcd_puts_scroll(0, 1, "CRC check failed."); | 903 | rb->lcd_puts_scroll(0, 1, "CRC check failed."); |
835 | break; | 904 | break; |
905 | case eBadPlatform: | ||
906 | rb->lcd_puts_scroll(0, 0, "Wrong file for"); | ||
907 | rb->lcd_puts_scroll(0, 1, "this hardware."); | ||
908 | break; | ||
836 | default: | 909 | default: |
837 | rb->lcd_puts_scroll(0, 0, "Check failed."); | 910 | rb->lcd_puts_scroll(0, 0, "Check failed."); |
838 | break; | 911 | break; |
@@ -924,5 +997,3 @@ enum plugin_status plugin_start(struct plugin_api* api, void* parameter) | |||
924 | } | 997 | } |
925 | 998 | ||
926 | #endif /* #ifndef SIMULATOR */ | 999 | #endif /* #ifndef SIMULATOR */ |
927 | |||
928 | #endif /* model */ | ||
diff --git a/apps/plugins/rockbox_flash.c b/apps/plugins/rockbox_flash.c index ce7976fd4d..9dc4b3a663 100644 --- a/apps/plugins/rockbox_flash.c +++ b/apps/plugins/rockbox_flash.c | |||
@@ -22,7 +22,6 @@ | |||
22 | #include "plugin.h" | 22 | #include "plugin.h" |
23 | 23 | ||
24 | #ifndef SIMULATOR /* Only build for target */ | 24 | #ifndef SIMULATOR /* Only build for target */ |
25 | #ifndef ARCHOS_RECORDERV2 /* not for those yet */ | ||
26 | 25 | ||
27 | /* define DUMMY if you only want to "play" with the UI, does no harm */ | 26 | /* define DUMMY if you only want to "play" with the UI, does no harm */ |
28 | /* #define DUMMY */ | 27 | /* #define DUMMY */ |
@@ -873,5 +872,4 @@ enum plugin_status plugin_start(struct plugin_api* api, void* parameter) | |||
873 | } | 872 | } |
874 | 873 | ||
875 | 874 | ||
876 | #endif /* #ifndef ARCHOS_RECORDERV2 */ | ||
877 | #endif /* #ifndef SIMULATOR */ | 875 | #endif /* #ifndef SIMULATOR */ |