summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJames Buren <braewoods+rb@braewoods.net>2020-10-30 02:14:43 +0000
committerJames Buren <braewoods+rb@braewoods.net>2020-10-30 05:40:29 +0000
commit7c498b904337e54799cb992adc22272be72fbc19 (patch)
tree1389b9a3d31e2676c2489ea78d3a2be8850bb83c
parent6bc6af6a0ec5ff6a69091d9c46c1a890a1e706a6 (diff)
downloadrockbox-7c498b904337e54799cb992adc22272be72fbc19.tar.gz
rockbox-7c498b904337e54799cb992adc22272be72fbc19.zip
iriver_flash: revise valid_bootloaders and detect_valid_bootloader
The main change is revising how the checksums are guarded by macros. But both are also converted to static linkage so they can be better optimized by GCC. I also change the types around to reflect how the space the data types actually need. Furthermore I make use of C99 changes to how variables can be declared to move them closer to where they are used. Change-Id: I0b21b655f3f4a7c4bbd4365a384a551e75451159
-rw-r--r--apps/plugins/iriver_flash.c36
1 files changed, 16 insertions, 20 deletions
diff --git a/apps/plugins/iriver_flash.c b/apps/plugins/iriver_flash.c
index 449bf349a8..a9cf62d3c4 100644
--- a/apps/plugins/iriver_flash.c
+++ b/apps/plugins/iriver_flash.c
@@ -66,11 +66,11 @@ enum sections {
66static volatile uint16_t* FB = (uint16_t*)0x00000000; /* Flash base address */ 66static volatile uint16_t* FB = (uint16_t*)0x00000000; /* Flash base address */
67#endif 67#endif
68 68
69#ifdef IRIVER_H100 69#ifdef IRIVER_H100 /* iRiver H110/H115 */
70#define MODEL "h100" 70#define MODEL "h100"
71#elif defined(IRIVER_H120) 71#elif defined(IRIVER_H120) /* iRiver H120/H140 */
72#define MODEL "h120" 72#define MODEL "h120"
73#elif defined(IRIVER_H300) 73#elif defined(IRIVER_H300) /* iRiver H320/H340 */
74#define MODEL "h300" 74#define MODEL "h300"
75#endif 75#endif
76 76
@@ -307,33 +307,29 @@ static off_t load_firmware_file(const char* filename, uint32_t* out_checksum)
307 return len; 307 return len;
308} 308}
309 309
310unsigned long valid_bootloaders[][2] = { 310static const uint32_t valid_bootloaders[][2] = {
311 /* Size-8 CRC32 */ 311 /* Size-8, CRC32 */
312#ifdef IRIVER_H120 /* Iriver H120/H140 checksums */ 312#ifdef IRIVER_H100 /* iRiver H110/H115 */
313 { 48760, 0x2efc3323 }, /* 7-pre4 */
314 { 56896, 0x0cd8dad4 }, /* 7-pre5 */
315#elif defined(IRIVER_H120) /* iRiver H120/H140 */
313 { 63788, 0x08ff01a9 }, /* 7-pre3, improved failsafe functions */ 316 { 63788, 0x08ff01a9 }, /* 7-pre3, improved failsafe functions */
314 { 48764, 0xc674323e }, /* 7-pre4. Fixed audio thump & remote bootup */ 317 { 48764, 0xc674323e }, /* 7-pre4. Fixed audio thump & remote bootup */
315 { 56896, 0x167f5d25 }, /* 7-pre5, various ATA fixes */ 318 { 56896, 0x167f5d25 }, /* 7-pre5, various ATA fixes */
319#elif defined(IRIVER_H300) /* iRiver H320/H340 */
316#endif 320#endif
317#ifdef IRIVER_H100 321 {}
318 { 48760, 0x2efc3323 }, /* 7-pre4 */
319 { 56896, 0x0cd8dad4 }, /* 7-pre5 */
320#endif
321 { 0, 0 }
322}; 322};
323 323
324 324/* check if the bootloader is a known good one */
325bool detect_valid_bootloader(const unsigned char *addr, int len) 325static bool detect_valid_bootloader(const uint8_t* pAddr, uint32_t len)
326{ 326{
327 int i; 327 for (size_t i = 0; valid_bootloaders[i][0]; i++)
328 unsigned long crc32;
329
330 /* Try to scan through all valid bootloaders. */
331 for (i = 0; valid_bootloaders[i][0]; i++)
332 { 328 {
333 if (len > 0 && len != (long)valid_bootloaders[i][0]) 329 if (len != valid_bootloaders[i][0])
334 continue; 330 continue;
335 331
336 crc32 = rb->crc_32(addr, valid_bootloaders[i][0], 0xffffffff); 332 uint32_t crc32 = rb->crc_32(pAddr, valid_bootloaders[i][0], 0xffffffff);
337 if (crc32 == valid_bootloaders[i][1]) 333 if (crc32 == valid_bootloaders[i][1])
338 return true; 334 return true;
339 } 335 }