diff options
-rw-r--r-- | apps/main.c | 4 | ||||
-rw-r--r-- | apps/plugins/iriver_flash.c | 14 | ||||
-rw-r--r-- | apps/plugins/viewers.config | 1 | ||||
-rw-r--r-- | bootloader/main.c | 95 | ||||
-rw-r--r-- | firmware/drivers/eeprom_24cxx.c | 10 | ||||
-rw-r--r-- | firmware/eeprom_settings.c | 10 | ||||
-rw-r--r-- | firmware/export/config-h300.h | 4 | ||||
-rw-r--r-- | firmware/export/eeprom_settings.h | 1 |
8 files changed, 115 insertions, 24 deletions
diff --git a/apps/main.c b/apps/main.c index 907e1126cf..d590790a85 100644 --- a/apps/main.c +++ b/apps/main.c | |||
@@ -120,7 +120,9 @@ int init_dircache(void) | |||
120 | # ifdef HAVE_EEPROM | 120 | # ifdef HAVE_EEPROM |
121 | if (firmware_settings.initialized && firmware_settings.disk_clean) | 121 | if (firmware_settings.initialized && firmware_settings.disk_clean) |
122 | { | 122 | { |
123 | if (dircache_load(DIRCACHE_FILE) == 0) | 123 | result = dircache_load(DIRCACHE_FILE); |
124 | remove(DIRCACHE_FILE); | ||
125 | if (result == 0) | ||
124 | return 0; | 126 | return 0; |
125 | } | 127 | } |
126 | # endif | 128 | # endif |
diff --git a/apps/plugins/iriver_flash.c b/apps/plugins/iriver_flash.c index 28734d197b..40c9a2979b 100644 --- a/apps/plugins/iriver_flash.c +++ b/apps/plugins/iriver_flash.c | |||
@@ -381,12 +381,13 @@ void show_fatal_error(void) | |||
381 | 381 | ||
382 | int flash_bootloader(const char *filename) | 382 | int flash_bootloader(const char *filename) |
383 | { | 383 | { |
384 | // char buf[32]; | 384 | char buf[32]; |
385 | int pos, i, len, rc; | 385 | int pos, i, len, rc; |
386 | unsigned long checksum, sum, crc32; | 386 | unsigned long checksum, sum, crc32; |
387 | unsigned char *p8; | 387 | unsigned char *p8; |
388 | uint16_t *p16; | 388 | uint16_t *p16; |
389 | 389 | ||
390 | (void)buf; | ||
390 | len = load_firmware_file(filename, &checksum); | 391 | len = load_firmware_file(filename, &checksum); |
391 | if (len < 0) | 392 | if (len < 0) |
392 | return len * 10; | 393 | return len * 10; |
@@ -399,15 +400,16 @@ int flash_bootloader(const char *filename) | |||
399 | 400 | ||
400 | /* Verify the crc32 checksum also. */ | 401 | /* Verify the crc32 checksum also. */ |
401 | crc32 = crc_32(audiobuf, len, 0xffffffff); | 402 | crc32 = crc_32(audiobuf, len, 0xffffffff); |
402 | // rb->snprintf(buf, sizeof buf, "crc32 = 0x%08x", crc32); | 403 | #if 0 |
403 | // rb->splash(HZ*10, true, buf); | 404 | rb->snprintf(buf, sizeof buf, "crc32 = 0x%08x", crc32); |
404 | 405 | rb->splash(HZ*10, true, buf); | |
405 | if (crc32 != 0x5361a679) | 406 | #else |
407 | if (crc32 != 0xa930906d) | ||
406 | { | 408 | { |
407 | rb->splash(HZ*3, true, "Untested bootloader"); | 409 | rb->splash(HZ*3, true, "Untested bootloader"); |
408 | return -2; | 410 | return -2; |
409 | } | 411 | } |
410 | 412 | #endif | |
411 | rb->lcd_puts(0, 3, "Processing critical sections..."); | 413 | rb->lcd_puts(0, 3, "Processing critical sections..."); |
412 | rb->lcd_update(); | 414 | rb->lcd_update(); |
413 | 415 | ||
diff --git a/apps/plugins/viewers.config b/apps/plugins/viewers.config index 5e1c6283f8..cc05bbc47d 100644 --- a/apps/plugins/viewers.config +++ b/apps/plugins/viewers.config | |||
@@ -22,3 +22,4 @@ wav,viewers/mp3_encoder, 00 00 00 00 00 00 | |||
22 | wav,viewers/wavplay,60 7F 05 35 3F 00 | 22 | wav,viewers/wavplay,60 7F 05 35 3F 00 |
23 | bmp,rocks/rockpaint, 01 10 01 10 01 10 | 23 | bmp,rocks/rockpaint, 01 10 01 10 01 10 |
24 | m2v,viewers/mpegplayer,5D 7F 5D 7F 5D 7F | 24 | m2v,viewers/mpegplayer,5D 7F 5D 7F 5D 7F |
25 | iriver,viewers/iriver_flash,2A 7F 41 41 7F 2A | ||
diff --git a/bootloader/main.c b/bootloader/main.c index 181dbeade3..0ef6d8944e 100644 --- a/bootloader/main.c +++ b/bootloader/main.c | |||
@@ -20,6 +20,8 @@ | |||
20 | 20 | ||
21 | #include <stdlib.h> | 21 | #include <stdlib.h> |
22 | #include <stdio.h> | 22 | #include <stdio.h> |
23 | #include "inttypes.h" | ||
24 | #include "string.h" | ||
23 | #include "cpu.h" | 25 | #include "cpu.h" |
24 | #include "system.h" | 26 | #include "system.h" |
25 | #include "lcd.h" | 27 | #include "lcd.h" |
@@ -39,6 +41,7 @@ | |||
39 | #include "power.h" | 41 | #include "power.h" |
40 | #include "file.h" | 42 | #include "file.h" |
41 | #include "uda1380.h" | 43 | #include "uda1380.h" |
44 | #include "eeprom_settings.h" | ||
42 | 45 | ||
43 | #include "pcf50606.h" | 46 | #include "pcf50606.h" |
44 | 47 | ||
@@ -151,6 +154,21 @@ int load_firmware(void) | |||
151 | return 0; | 154 | return 0; |
152 | } | 155 | } |
153 | 156 | ||
157 | int load_flashed_rockbox(void) | ||
158 | { | ||
159 | struct flash_header hdr; | ||
160 | unsigned char *buf = (unsigned char *)DRAM_START; | ||
161 | uint8_t *src = (uint8_t *)FLASH_ENTRYPOINT; | ||
162 | |||
163 | cpu_boost(true); | ||
164 | memcpy(&hdr, src, sizeof(struct flash_header)); | ||
165 | src += sizeof(struct flash_header); | ||
166 | memcpy(buf, src, hdr.length); | ||
167 | cpu_boost(false); | ||
168 | |||
169 | return 0; | ||
170 | } | ||
171 | |||
154 | 172 | ||
155 | void start_firmware(void) | 173 | void start_firmware(void) |
156 | { | 174 | { |
@@ -171,12 +189,14 @@ void main(void) | |||
171 | int rc; | 189 | int rc; |
172 | bool rc_on_button = false; | 190 | bool rc_on_button = false; |
173 | bool on_button = false; | 191 | bool on_button = false; |
192 | bool rec_button = false; | ||
174 | int data; | 193 | int data; |
175 | int adc_battery, battery_voltage, batt_int, batt_frac; | 194 | int adc_battery, battery_voltage, batt_int, batt_frac; |
176 | 195 | ||
177 | #ifdef IAUDIO_X5 | 196 | #ifdef IAUDIO_X5 |
178 | (void)rc_on_button; | 197 | (void)rc_on_button; |
179 | (void)on_button; | 198 | (void)on_button; |
199 | (void)rec_button; | ||
180 | (void)data; | 200 | (void)data; |
181 | power_init(); | 201 | power_init(); |
182 | 202 | ||
@@ -311,13 +331,66 @@ void main(void) | |||
311 | lcd_update(); | 331 | lcd_update(); |
312 | 332 | ||
313 | sleep(HZ/50); /* Allow the button driver to check the buttons */ | 333 | sleep(HZ/50); /* Allow the button driver to check the buttons */ |
334 | rec_button = ((button_status() & BUTTON_REC) == BUTTON_REC) | ||
335 | || ((button_status() & BUTTON_RC_REC) == BUTTON_RC_REC); | ||
336 | |||
314 | 337 | ||
315 | /* Holding REC while starting runs the original firmware */ | 338 | #ifdef HAVE_EEPROM |
316 | if(((button_status() & BUTTON_REC) == BUTTON_REC) || | 339 | firmware_settings.initialized = false; |
317 | ((button_status() & BUTTON_RC_REC) == BUTTON_RC_REC)) { | 340 | #endif |
318 | printf("Starting original firmware..."); | 341 | if (detect_flashed_rockbox()) |
342 | { | ||
343 | bool load_from_flash; | ||
344 | |||
345 | load_from_flash = !rec_button; | ||
346 | #ifdef HAVE_EEPROM | ||
347 | if (eeprom_settings_init()) | ||
348 | { | ||
349 | /* If bootloader version has not been reset, disk might | ||
350 | * not be intact. */ | ||
351 | if (firmware_settings.bl_version) | ||
352 | firmware_settings.disk_clean = false; | ||
353 | |||
354 | firmware_settings.bl_version = 7; | ||
355 | /* Invert the record button if we want to load from disk | ||
356 | * by default. */ | ||
357 | if (firmware_settings.boot_disk) | ||
358 | load_from_flash = rec_button; | ||
359 | } | ||
360 | #endif | ||
361 | |||
362 | if (load_from_flash) | ||
363 | { | ||
364 | /* Load firmware from flash */ | ||
365 | i = load_flashed_rockbox(); | ||
366 | printf("Result: %d", i); | ||
367 | lcd_update(); | ||
368 | if (i == 0) | ||
369 | { | ||
370 | #ifdef HAVE_EEPROM | ||
371 | eeprom_settings_store(); | ||
372 | #endif | ||
373 | start_firmware(); | ||
374 | printf("Fatal: Corrupted firmware"); | ||
375 | printf("Hold down REC on next boot"); | ||
376 | lcd_update(); | ||
377 | sleep(HZ*2); | ||
378 | power_off(); | ||
379 | } | ||
380 | } | ||
381 | |||
382 | printf("Loading from disk..."); | ||
319 | lcd_update(); | 383 | lcd_update(); |
320 | start_iriver_fw(); | 384 | } |
385 | else | ||
386 | { | ||
387 | /* Holding REC while starting runs the original firmware */ | ||
388 | if (rec_button) | ||
389 | { | ||
390 | printf("Starting original firmware..."); | ||
391 | lcd_update(); | ||
392 | start_iriver_fw(); | ||
393 | } | ||
321 | } | 394 | } |
322 | 395 | ||
323 | /* Don't start if the Hold button is active on the device you | 396 | /* Don't start if the Hold button is active on the device you |
@@ -384,6 +457,13 @@ void main(void) | |||
384 | sleep(HZ); | 457 | sleep(HZ); |
385 | #endif | 458 | #endif |
386 | 459 | ||
460 | #ifdef HAVE_EEPROM | ||
461 | if (firmware_settings.initialized) | ||
462 | { | ||
463 | firmware_settings.disk_clean = false; | ||
464 | eeprom_settings_store(); | ||
465 | } | ||
466 | #endif | ||
387 | ata_spin(); | 467 | ata_spin(); |
388 | ata_enable(false); | 468 | ata_enable(false); |
389 | usb_enable(true); | 469 | usb_enable(true); |
@@ -423,6 +503,11 @@ void main(void) | |||
423 | printf("Result: %d", i); | 503 | printf("Result: %d", i); |
424 | lcd_update(); | 504 | lcd_update(); |
425 | 505 | ||
506 | #ifdef HAVE_EEPROM | ||
507 | if (firmware_settings.initialized) | ||
508 | eeprom_settings_store(); | ||
509 | #endif | ||
510 | |||
426 | if(i == 0) | 511 | if(i == 0) |
427 | start_firmware(); | 512 | start_firmware(); |
428 | 513 | ||
diff --git a/firmware/drivers/eeprom_24cxx.c b/firmware/drivers/eeprom_24cxx.c index 75521ce2db..03e5a3d620 100644 --- a/firmware/drivers/eeprom_24cxx.c +++ b/firmware/drivers/eeprom_24cxx.c | |||
@@ -82,10 +82,6 @@ static void sw_i2c_start(void) | |||
82 | 82 | ||
83 | static void sw_i2c_stop(void) | 83 | static void sw_i2c_stop(void) |
84 | { | 84 | { |
85 | // SCL_LO; | ||
86 | // DELAY; | ||
87 | // SDA_LO; | ||
88 | // DELAY; | ||
89 | SCL_HI; | 85 | SCL_HI; |
90 | DELAY; | 86 | DELAY; |
91 | SDA_HI; | 87 | SDA_HI; |
@@ -294,7 +290,7 @@ int eeprom_24cxx_read_byte(unsigned int address, char *c) | |||
294 | if (ret < 0) | 290 | if (ret < 0) |
295 | { | 291 | { |
296 | /* keep between {} as logf is whitespace in normal builds */ | 292 | /* keep between {} as logf is whitespace in normal builds */ |
297 | logf("EEPROM Fail: %d/%d", ret, address); | 293 | logf("EEPROM rFail: %d/%d", ret, address); |
298 | } | 294 | } |
299 | } while (ret < 0 && count--); | 295 | } while (ret < 0 && count--); |
300 | 296 | ||
@@ -325,7 +321,7 @@ int eeprom_24cxx_write_byte(unsigned int address, char c) | |||
325 | if (ret < 0) | 321 | if (ret < 0) |
326 | { | 322 | { |
327 | /* keep between {} as logf is whitespace in normal builds */ | 323 | /* keep between {} as logf is whitespace in normal builds */ |
328 | logf("EEPROM Fail: %d/%d", ret, address); | 324 | logf("EEPROM wFail: %d/%d", ret, address); |
329 | } | 325 | } |
330 | } while (ret < 0 && count--) ; | 326 | } while (ret < 0 && count--) ; |
331 | 327 | ||
@@ -357,7 +353,7 @@ int eeprom_24cxx_read(unsigned char address, void *dest, int length) | |||
357 | int eeprom_24cxx_write(unsigned char address, const void *src, int length) | 353 | int eeprom_24cxx_write(unsigned char address, const void *src, int length) |
358 | { | 354 | { |
359 | const char *buf = (const char *)src; | 355 | const char *buf = (const char *)src; |
360 | int count = 10; | 356 | int count = 5; |
361 | int i; | 357 | int i; |
362 | bool ok; | 358 | bool ok; |
363 | 359 | ||
diff --git a/firmware/eeprom_settings.c b/firmware/eeprom_settings.c index e472f4df07..450eff9623 100644 --- a/firmware/eeprom_settings.c +++ b/firmware/eeprom_settings.c | |||
@@ -21,6 +21,7 @@ | |||
21 | #include "eeprom_24cxx.h" | 21 | #include "eeprom_24cxx.h" |
22 | #include "crc32.h" | 22 | #include "crc32.h" |
23 | 23 | ||
24 | #include "system.h" | ||
24 | #include "string.h" | 25 | #include "string.h" |
25 | #include "logf.h" | 26 | #include "logf.h" |
26 | 27 | ||
@@ -64,16 +65,17 @@ bool eeprom_settings_init(void) | |||
64 | sum = crc_32(&firmware_settings, sizeof(struct eeprom_settings)-4, | 65 | sum = crc_32(&firmware_settings, sizeof(struct eeprom_settings)-4, |
65 | 0xffffffff); | 66 | 0xffffffff); |
66 | 67 | ||
67 | if (firmware_settings.checksum != sum) | 68 | logf("BL version: %d", firmware_settings.bl_version); |
69 | if (firmware_settings.version != EEPROM_SETTINGS_VERSION) | ||
68 | { | 70 | { |
69 | logf("Checksum mismatch"); | 71 | logf("Version mismatch"); |
70 | reset_config(); | 72 | reset_config(); |
71 | return true; | 73 | return true; |
72 | } | 74 | } |
73 | 75 | ||
74 | if (firmware_settings.version != EEPROM_SETTINGS_VERSION) | 76 | if (firmware_settings.checksum != sum) |
75 | { | 77 | { |
76 | logf("Version mismatch"); | 78 | logf("Checksum mismatch"); |
77 | reset_config(); | 79 | reset_config(); |
78 | return true; | 80 | return true; |
79 | } | 81 | } |
diff --git a/firmware/export/config-h300.h b/firmware/export/config-h300.h index 6d5fbabbdf..f3ba076334 100644 --- a/firmware/export/config-h300.h +++ b/firmware/export/config-h300.h | |||
@@ -124,6 +124,10 @@ | |||
124 | #define BOOTFILE_EXT "iriver" | 124 | #define BOOTFILE_EXT "iriver" |
125 | #define BOOTFILE "rockbox." BOOTFILE_EXT | 125 | #define BOOTFILE "rockbox." BOOTFILE_EXT |
126 | 126 | ||
127 | #define BOOTLOADER_ENTRYPOINT 0x001F0000 | ||
128 | #define FLASH_ENTRYPOINT 0x00001000 | ||
129 | #define FLASH_MAGIC 0xfbfbfbf1 | ||
130 | |||
127 | #define HAVE_BACKLIGHT_BRIGHTNESS | 131 | #define HAVE_BACKLIGHT_BRIGHTNESS |
128 | 132 | ||
129 | /* define this if the unit can be powered or charged via USB */ | 133 | /* define this if the unit can be powered or charged via USB */ |
diff --git a/firmware/export/eeprom_settings.h b/firmware/export/eeprom_settings.h index a3515bd69e..367e7b24e9 100644 --- a/firmware/export/eeprom_settings.h +++ b/firmware/export/eeprom_settings.h | |||
@@ -40,7 +40,6 @@ struct eeprom_settings | |||
40 | 40 | ||
41 | extern struct eeprom_settings firmware_settings; | 41 | extern struct eeprom_settings firmware_settings; |
42 | 42 | ||
43 | bool detect_flashed_rockbox(void); | ||
44 | bool eeprom_settings_init(void); | 43 | bool eeprom_settings_init(void); |
45 | bool eeprom_settings_store(void); | 44 | bool eeprom_settings_store(void); |
46 | 45 | ||