/* inline since branch is chosen at compile time */ static inline void usb_slave_mode(bool on) { int rc; if(on) { DEBUGF("Entering USB slave mode\n"); storage_soft_reset(); storage_init(); storage_enable(false); usb_enable(true); cpu_idle_mode(true); } else { DEBUGF("Leaving USB slave mode\n"); cpu_idle_mode(false); /* Let the ISDx00 settle */ sleep(HZ*1); usb_enable(false); rc = storage_init(); if(rc) panicf("storage: %d",rc); rc = disk_mount_all(); if (rc <= 0) /* no partition */ panicf("mount: %d",rc); } }
void main(void) { unsigned char* loadbuffer; int buffer_size; int rc; int(*kernel_entry)(void); /* Make sure interrupts are disabled */ set_irq_level(IRQ_DISABLED); set_fiq_status(FIQ_DISABLED); system_init(); kernel_init(); /* Now enable interrupts */ set_irq_level(IRQ_ENABLED); set_fiq_status(FIQ_ENABLED); lcd_init(); backlight_init(); font_init(); button_init(); usb_init(); power_init(); // enable_irq(); // enable_fiq(); adc_init(); lcd_setfont(FONT_SYSFIXED); /* Show debug messages if button is pressed */ // if(button_read_device()) verbose = true; printf("Rockbox boot loader"); printf("Version %s", rbversion); /* Enter USB mode without USB thread */ if(usb_detect() == USB_INSERTED) { const char msg[] = "Bootloader USB mode"; reset_screen(); lcd_putsxy( (LCD_WIDTH - (SYSFONT_WIDTH * strlen(msg))) / 2, (LCD_HEIGHT - SYSFONT_HEIGHT) / 2, msg); lcd_update(); ide_power_enable(true); storage_enable(false); sleep(HZ/20); usb_enable(true); while (usb_detect() == USB_INSERTED) { storage_spin(); /* Prevent the drive from spinning down */ sleep(HZ); } usb_enable(false); reset_screen(); lcd_update(); } sleep(50); printf("ATA"); rc = storage_init(); if(rc) { reset_screen(); error(EATA, rc, true); } printf("filesystem"); filesystem_init(); printf("mount"); rc = disk_mount_all(); if (rc<=0) { error(EDISK,rc, true); } printf("Loading firmware"); loadbuffer = (unsigned char*) 0x00900000; buffer_size = (unsigned char*)0x01900000 - loadbuffer; rc = load_firmware(loadbuffer, BOOTFILE, buffer_size); if(rc <= EFILE_EMPTY) error(EBOOTFILE, rc, true); kernel_entry = (void*) loadbuffer; rc = kernel_entry(); /* Should not get here! */ return rc; }
void main(void) { unsigned char* loadbuffer; int buffer_size; int rc; int(*kernel_entry)(void); system_init(); kernel_init(); /* Need the kernel to sleep */ enable_interrupt(IRQ_FIQ_STATUS); lcd_init(); backlight_init(); button_init(); font_init(); adc_init(); lcd_setfont(FONT_SYSFIXED); /* These checks should only run if the bootloader is flashed */ if(GSTATUS3&0x02) { GSTATUS3&=0xFFFFFFFD; if(!(GPGDAT&BUTTON_POWER) && charger_inserted()) { while(!(GPGDAT&BUTTON_POWER) && charger_inserted()) { char msg[20]; if(charging_state()) { snprintf(msg,sizeof(msg),"Charging"); } else { snprintf(msg,sizeof(msg),"Charge Complete"); } reset_screen(); lcd_putsxy( (LCD_WIDTH - (SYSFONT_WIDTH * strlen(msg))) / 2, (LCD_HEIGHT - SYSFONT_HEIGHT) / 2, msg); lcd_update(); #if defined(HAVE_RTC_ALARM) /* Check if the alarm went off while charging */ if(rtc_check_alarm_flag()) { GSTATUS3=1; /* Normally this is set in crt0.s */ break; } #endif } if(!(GPGDAT&BUTTON_POWER) #if defined(HAVE_RTC_ALARM) && !GSTATUS3 #endif ) { shutdown(); } } if(button_hold()) { const char msg[] = "HOLD is enabled"; reset_screen(); lcd_putsxy( (LCD_WIDTH - (SYSFONT_WIDTH * strlen(msg))) / 2, (LCD_HEIGHT - SYSFONT_HEIGHT) / 2, msg); lcd_update(); sleep(2*HZ); shutdown(); } } power_init(); usb_init(); /* Enter USB mode without USB thread */ if(usb_detect() == USB_INSERTED) { const char msg[] = "Bootloader USB mode"; reset_screen(); lcd_putsxy( (LCD_WIDTH - (SYSFONT_WIDTH * strlen(msg))) / 2, (LCD_HEIGHT - SYSFONT_HEIGHT) / 2, msg); lcd_update(); storage_enable(false); sleep(HZ/20); usb_enable(true); while (usb_detect() == USB_INSERTED) sleep(HZ); usb_enable(false); reset_screen(); lcd_update(); } reset_screen(); /* Show debug messages if button is pressed */ if(button_read_device()&BUTTON_A) verbose = true; printf("Rockbox boot loader"); printf("Version %s", rbversion); sleep(50); /* ATA seems to error without this pause */ rc = storage_init(); if(rc) { reset_screen(); error(EATA, rc, true); } filesystem_init(); rc = disk_mount_all(); if (rc<=0) { error(EDISK, rc, true); } printf("Loading firmware"); /* Flush out anything pending first */ commit_discard_idcache(); loadbuffer = (unsigned char*) 0x31000000; buffer_size = (unsigned char*)0x31400000 - loadbuffer; rc = load_firmware(loadbuffer, BOOTFILE, buffer_size); if(rc <= EFILE_EMPTY) error(EBOOTFILE, rc, true); storage_close(); system_prepare_fw_start(); commit_discard_idcache(); kernel_entry = (void*) loadbuffer; rc = kernel_entry(); #if 0 /* Halt */ while (1) core_idle(); #else /* Return and restart */ #endif }