summaryrefslogtreecommitdiff
path: root/bootloader/iriver_h1x0.c
diff options
context:
space:
mode:
authorJames Buren <braewoods+rb@braewoods.net>2020-11-14 14:57:47 +0000
committerWilliam Wilgus <me.theuser@yahoo.com>2020-11-14 23:20:43 +0000
commit7d9ac021b5bac5078778c4b2489d31c9f2892404 (patch)
tree34dbebfaf91d3b57a2fdc582cf727777e9e250d8 /bootloader/iriver_h1x0.c
parent33d42c20de9a66cbfec8b213d19b454794d63900 (diff)
downloadrockbox-7d9ac021b5bac5078778c4b2489d31c9f2892404.tar.gz
rockbox-7d9ac021b5bac5078778c4b2489d31c9f2892404.zip
h1x0/h300: bring the two bootloaders more in sync
The most major change here is the porting of the failsafe boot menu and eeprom settings support from the h1x0 bootloader to the h300 bootloader. This has been successfully tested already and indeed works about the same as it does on the h1x0 bootloader. The other major change is the addition of new code to both bootloaders that will retry the flash boot function after exitting disk mode. It still falls back to booting from disk if this either fails or is not configured to boot from flash. There were also various other modifications to bring the two closer in sync so there are fewer differences. Change-Id: I17a5724e03225b57e9d0071387294aa6cd025178
Diffstat (limited to 'bootloader/iriver_h1x0.c')
-rw-r--r--bootloader/iriver_h1x0.c59
1 files changed, 20 insertions, 39 deletions
diff --git a/bootloader/iriver_h1x0.c b/bootloader/iriver_h1x0.c
index 168bd29b67..d5a3b887a2 100644
--- a/bootloader/iriver_h1x0.c
+++ b/bootloader/iriver_h1x0.c
@@ -61,9 +61,7 @@
61extern int line; 61extern int line;
62extern int remote_line; 62extern int remote_line;
63 63
64#ifdef HAVE_EEPROM_SETTINGS
65static bool recovery_mode = false; 64static bool recovery_mode = false;
66#endif
67 65
68/* Reset the cookie for the crt0 crash check */ 66/* Reset the cookie for the crt0 crash check */
69inline void __reset_cookie(void) 67inline void __reset_cookie(void)
@@ -96,12 +94,12 @@ void start_firmware(void)
96void start_flashed_romimage(void) 94void start_flashed_romimage(void)
97{ 95{
98 uint8_t *src = (uint8_t *)FLASH_ROMIMAGE_ENTRY; 96 uint8_t *src = (uint8_t *)FLASH_ROMIMAGE_ENTRY;
99 int *reset_vector; 97 uint32_t *reset_vector;
100 98
101 if (!detect_flashed_romimage()) 99 if (!detect_flashed_romimage())
102 return ; 100 return ;
103 101
104 reset_vector = (int *)(&src[sizeof(struct flash_header)+4]); 102 reset_vector = (uint32_t *)(&src[sizeof(struct flash_header)+sizeof(uint32_t)]);
105 103
106 asm(" move.w #0x2700,%sr"); 104 asm(" move.w #0x2700,%sr");
107 __reset_cookie(); 105 __reset_cookie();
@@ -119,7 +117,7 @@ void start_flashed_romimage(void)
119void start_flashed_ramimage(void) 117void start_flashed_ramimage(void)
120{ 118{
121 struct flash_header hdr; 119 struct flash_header hdr;
122 unsigned char *buf = (unsigned char *)DRAM_START; 120 uint8_t *buf = (uint8_t *)DRAM_START;
123 uint8_t *src = (uint8_t *)FLASH_RAMIMAGE_ENTRY; 121 uint8_t *src = (uint8_t *)FLASH_RAMIMAGE_ENTRY;
124 122
125 if (!detect_flashed_ramimage()) 123 if (!detect_flashed_ramimage())
@@ -141,11 +139,9 @@ void start_flashed_ramimage(void)
141void shutdown(void) 139void shutdown(void)
142{ 140{
143 printf("Shutting down..."); 141 printf("Shutting down...");
144#ifdef HAVE_EEPROM_SETTINGS
145 /* Reset the rockbox crash check. */ 142 /* Reset the rockbox crash check. */
146 firmware_settings.bl_version = 0; 143 firmware_settings.bl_version = 0;
147 eeprom_settings_store(); 144 eeprom_settings_store();
148#endif
149 145
150 /* We need to gracefully spin down the disk to prevent clicks. */ 146 /* We need to gracefully spin down the disk to prevent clicks. */
151 if (ide_powered()) 147 if (ide_powered())
@@ -185,7 +181,6 @@ void check_battery(void)
185 } 181 }
186} 182}
187 183
188#ifdef HAVE_EEPROM_SETTINGS
189void initialize_eeprom(void) 184void initialize_eeprom(void)
190{ 185{
191 if (detect_original_firmware()) 186 if (detect_original_firmware())
@@ -235,17 +230,17 @@ void try_flashboot(void)
235 } 230 }
236} 231}
237 232
238static const char *options[] = {
239 "Boot from disk",
240 "Boot RAM image",
241 "Boot ROM image",
242 "Shutdown"
243};
244
245#define FAILSAFE_OPTIONS 4
246#define TIMEOUT (15*HZ)
247void failsafe_menu(void) 233void failsafe_menu(void)
248{ 234{
235 static const char *options[] =
236 {
237 "Boot from disk",
238 "Boot RAM image",
239 "Boot ROM image",
240 "Shutdown"
241 };
242 const int FAILSAFE_OPTIONS = sizeof(options) / sizeof(*options);
243 const long TIMEOUT = 15 * HZ;
249 long start_tick = current_tick; 244 long start_tick = current_tick;
250 int option = 3; 245 int option = 3;
251 int button; 246 int button;
@@ -355,7 +350,6 @@ void failsafe_menu(void)
355 350
356 shutdown(); 351 shutdown();
357} 352}
358#endif
359 353
360/* get rid of a nasty humming sound during boot 354/* get rid of a nasty humming sound during boot
361 -> RESET signal */ 355 -> RESET signal */
@@ -427,9 +421,7 @@ void main(void)
427 coldfire_set_pllcr_audio_bits(DEFAULT_PLLCR_AUDIO_BITS); 421 coldfire_set_pllcr_audio_bits(DEFAULT_PLLCR_AUDIO_BITS);
428 enable_irq(); 422 enable_irq();
429 423
430#ifdef HAVE_EEPROM_SETTINGS
431 initialize_eeprom(); 424 initialize_eeprom();
432#endif
433 425
434 usb_init(); 426 usb_init();
435 /* A small delay after usb_init is necessary to read the I/O port correctly 427 /* A small delay after usb_init is necessary to read the I/O port correctly
@@ -458,19 +450,11 @@ void main(void)
458 } 450 }
459 451
460 /* Power on the hard drive early, to speed up the loading. */ 452 /* Power on the hard drive early, to speed up the loading. */
461 if (!hold_status 453 if (!hold_status && !recovery_mode)
462# ifdef HAVE_EEPROM_SETTINGS
463 && !recovery_mode
464# endif
465 )
466 {
467 ide_power_enable(true); 454 ide_power_enable(true);
468 }
469 455
470# ifdef HAVE_EEPROM_SETTINGS
471 if (!hold_status && (usb_detect() != USB_INSERTED) && !recovery_mode) 456 if (!hold_status && (usb_detect() != USB_INSERTED) && !recovery_mode)
472 try_flashboot(); 457 try_flashboot();
473# endif
474 458
475 lcd_init(); 459 lcd_init();
476 460
@@ -500,11 +484,7 @@ void main(void)
500 484
501 /* Don't start if the Hold button is active on the device you 485 /* Don't start if the Hold button is active on the device you
502 are starting with */ 486 are starting with */
503 if ((usb_detect() != USB_INSERTED) && (hold_status 487 if ((usb_detect() != USB_INSERTED) && (hold_status || recovery_mode))
504#ifdef HAVE_EEPROM_SETTINGS
505 || recovery_mode
506#endif
507 ))
508 { 488 {
509 if (detect_original_firmware()) 489 if (detect_original_firmware())
510 { 490 {
@@ -512,9 +492,7 @@ void main(void)
512 shutdown(); 492 shutdown();
513 } 493 }
514 494
515#ifdef HAVE_EEPROM_SETTINGS
516 failsafe_menu(); 495 failsafe_menu();
517#endif
518 } 496 }
519 497
520 /* Holding REC while starting runs the original firmware */ 498 /* Holding REC while starting runs the original firmware */
@@ -537,13 +515,12 @@ void main(void)
537 lcd_remote_puts(0, 3, msg); 515 lcd_remote_puts(0, 3, msg);
538 lcd_remote_update(); 516 lcd_remote_update();
539 517
540#ifdef HAVE_EEPROM_SETTINGS
541 if (firmware_settings.initialized) 518 if (firmware_settings.initialized)
542 { 519 {
543 firmware_settings.disk_clean = false; 520 firmware_settings.disk_clean = false;
544 eeprom_settings_store(); 521 eeprom_settings_store();
545 } 522 }
546#endif 523
547 ide_power_enable(true); 524 ide_power_enable(true);
548 storage_enable(false); 525 storage_enable(false);
549 sleep(HZ/20); 526 sleep(HZ/20);
@@ -570,6 +547,11 @@ void main(void)
570 lcd_update(); 547 lcd_update();
571 } 548 }
572 549
550 /* boot from flash if that is the default */
551 try_flashboot();
552 if (recovery_mode)
553 printf("Falling back to boot from disk");
554
573 rc = storage_init(); 555 rc = storage_init();
574 if(rc) 556 if(rc)
575 { 557 {
@@ -580,7 +562,6 @@ void main(void)
580 while(!(button_get(true) & BUTTON_REL)); 562 while(!(button_get(true) & BUTTON_REL));
581 } 563 }
582 564
583
584 filesystem_init(); 565 filesystem_init();
585 566
586 rc = disk_mount_all(); 567 rc = disk_mount_all();