static int boot_rockbox(void) { int rc; void (*kernel_entry)(void); printf("Mounting disk..."); rc = disk_mount_all(); if (rc <= 0) error(EDISK,rc, true); printf("Loading firmware..."); rc = load_firmware((unsigned char *)CONFIG_SDRAM_START, BOOTFILE, 0x400000); if(rc <= EFILE_EMPTY) return rc; else { printf("Starting Rockbox..."); adc_close(); /* Disable SADC, seems to fix the re-init Rockbox does */ disable_interrupt(); kernel_entry = (void*) CONFIG_SDRAM_START; kernel_entry(); return 0; /* Shouldn't happen */ } }
/* 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); } }
static int boot_of(void) { int fd, rc, len, i, checksum = 0; void (*kernel_entry)(int, void*, void*); printf("Mounting disk..."); rc = disk_mount_all(); if (rc <= 0) error(EDISK, rc, true); /* TODO: get this from the NAND flash instead of SD */ fd = open("/ccpmp.bin", O_RDONLY); if(fd < 0) return EFILE_NOT_FOUND; lseek(fd, 4, SEEK_SET); rc = read(fd, (char*)&len, 4); /* CPU is LE */ if(rc < 4) return EREAD_IMAGE_FAILED; len += 8; printf("Reading %d bytes...", len); lseek(fd, 0, SEEK_SET); rc = read(fd, (void*)0x80004000, len); if(rc < len) return EREAD_IMAGE_FAILED; close(fd); for(i=0; i<len; i++) checksum += ((unsigned char*)0x80004000)[i]; *((unsigned int*)0x80004000) = checksum; printf("Starting the OF..."); /* OF requires all clocks on */ __cpm_start_all(); disable_interrupt(); __dcache_writeback_all(); __icache_invalidate_all(); for(i=8000; i>0; i--) asm volatile("nop\n"); kernel_entry = (void*) 0x80004008; kernel_entry(0, "Jan 10 2008", "15:34:42"); /* Reversed from the SPL */ return 0; /* Shouldn't happen */ }
static void reset_configuration(void) { int rc; rc = disk_mount_all(); if (rc <= 0) error(EDISK,rc, true); if(rename(ROCKBOX_DIR "/config.cfg", ROCKBOX_DIR "/config.old") == 0) show_splash(HZ/2, "Configuration reset successfully!"); else show_splash(HZ/2, "Couldn't reset configuration!"); }
/* inline since branch is chosen at compile time */ static inline void usb_slave_mode(bool on) { #ifdef USE_ROCKBOX_USB int rc; if (on) { trigger_cpu_boost(); #ifdef HAVE_PRIORITY_SCHEDULING thread_set_priority(THREAD_ID_CURRENT, PRIORITY_REALTIME); #endif usb_attach(); } else /* usb_state == USB_INSERTED (only!) */ { #ifndef USB_DETECT_BY_DRV usb_enable(false); #endif #ifdef HAVE_PRIORITY_SCHEDULING thread_set_priority(THREAD_ID_CURRENT, PRIORITY_SYSTEM); #endif /* Entered exclusive mode */ rc = disk_mount_all(); if (rc <= 0) /* no partition */ panicf("mount: %d",rc); cancel_cpu_boost(); } #else /* !USE_ROCKBOX_USB */ if (on) { /* until we have native mass-storage mode, we want to reboot on usb host connect */ try_reboot(); } #endif /* USE_ROCKBOX_USB */ }
void* main(void) { int i; int rc; int fd; char buffer[80]; unsigned char* framebuffer = (unsigned char*)0x11e00000; #if 0 lcd_init(); font_init(); printf("Hello World!"); #endif i=storage_init(); disk_init(); rc = disk_mount_all(); #if 0 /* Dump the flash */ fd=open("/flash.bin",O_CREAT|O_RDWR, 0666); write(fd,(char*)0,1024*1024); close(fd); #endif #if 1 /* Dump what may be the framebuffer */ fd=open("/framebuffer.bin",O_CREAT|O_RDWR|O_TRUNC, 0666); write(fd,framebuffer,220*176*4); close(fd); #endif fd=open("/gpio.txt",O_CREAT|O_RDWR|O_TRUNC, 0666); unsigned int gpio_a = GPIOA_INPUT_VAL; unsigned int gpio_b = GPIOB_INPUT_VAL; unsigned int gpio_c = GPIOC_INPUT_VAL; unsigned int gpio_d = GPIOD_INPUT_VAL; unsigned int gpio_e = GPIOE_INPUT_VAL; unsigned int gpio_f = GPIOF_INPUT_VAL; unsigned int gpio_g = GPIOG_INPUT_VAL; unsigned int gpio_h = GPIOH_INPUT_VAL; unsigned int gpio_i = GPIOI_INPUT_VAL; unsigned int gpio_j = GPIOJ_INPUT_VAL; unsigned int gpio_k = GPIOK_INPUT_VAL; unsigned int gpio_l = GPIOL_INPUT_VAL; snprintf(buffer, sizeof(buffer), "%02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x\n",gpio_a,gpio_b,gpio_c,gpio_d,gpio_e,gpio_f,gpio_g,gpio_h,gpio_i,gpio_j,gpio_k,gpio_l); write(fd,buffer,strlen(buffer)+1); close(fd); /* Wait for FFWD button to be pressed */ while((GPIOA_INPUT_VAL & 0x04) != 0); /* Now reboot */ DEV_RS |= 0x4; return 0; }
int main(void) { unsigned char* loadbuffer; int buffer_size; int rc; int(*kernel_entry)(void); led_init(); clear_leds(LED_ALL); /* NB: something in system_init() prevents H-JTAG from downloading */ /* system_init(); */ kernel_init(); /* enable_interrupt(IRQ_FIQ_STATUS); */ backlight_init(); lcd_init(); lcd_setfont(FONT_SYSFIXED); button_init(); dma_init(); uart_init(); uart_init_device(DEBUG_UART_PORT); /* mini2440_test(); */ /* Show debug messages if button is pressed */ int touch_data; if(button_read_device(&touch_data) & BUTTON_MENU) verbose = true; printf("Rockbox boot loader"); printf("Version " RBVERSION); rc = storage_init(); if(rc) { reset_screen(); error(EATA, rc, true); } disk_init(IF_MD(0)); 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 <= 0) error(EBOOTFILE, rc, true); printf("Loaded firmware %d\n", rc); /* storage_close(); */ system_prepare_fw_start(); commit_discard_idcache(); kernel_entry = (void*) loadbuffer; rc = kernel_entry(); /* end stop - should not get here */ led_flash(LED_ALL, LED_NONE); while (1); /* avoid warning */ }
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 }
void main(void) { int rc; power_init(); system_init(); kernel_init(); lcd_init(); show_logo(); enable_irq(); adc_init(); usb_init(); button_init(); powermgmt_init(); #if CONFIG_CHARGING && (CONFIG_CPU == SH7034) if (charger_inserted() #ifdef ATA_POWER_PLAYERSTYLE && !ide_powered() /* relies on probing result from bootloader */ #endif ) { charging_screen(); /* display a "charging" screen */ show_logo(); /* again, to provide better visual feedback */ } #endif rc = storage_init(); if(rc) { #ifdef HAVE_LCD_BITMAP char str[32]; lcd_clear_display(); snprintf(str, 31, "ATA error: %d", rc); lcd_puts(0, 1, str); lcd_update(); while(!(button_get(true) & BUTTON_REL)); #endif panicf("storage: %d", rc); } usb_start_monitoring(); while (usb_detect() == USB_INSERTED) { /* enter USB mode early, before trying to mount */ if (button_get_w_tmo(HZ/10) == SYS_USB_CONNECTED) { usb_screen(); } } rc = disk_mount_all(); if (rc<=0) { prompt_usb("No partition", "found."); } { // rolo the firmware static const char filename[] = "/" BOOTFILE; rolo_load((char*)filename); /* won't return if started */ prompt_usb("No firmware", filename); } }
static void init(void) { int rc; bool mounted = false; #if CONFIG_CHARGING && (CONFIG_CPU == SH7034) /* if nobody initialized ATA before, I consider this a cold start */ bool coldstart = (PACR2 & 0x4000) != 0; /* starting from Flash */ #endif system_init(); kernel_init(); #ifdef HAVE_ADJUSTABLE_CPU_FREQ set_cpu_frequency(CPUFREQ_NORMAL); #ifdef CPU_COLDFIRE coldfire_set_pllcr_audio_bits(DEFAULT_PLLCR_AUDIO_BITS); #endif cpu_boost(true); #endif buffer_init(); settings_reset(); i2c_init(); power_init(); enable_irq(); #ifdef CPU_ARM enable_fiq(); #endif /* current_tick should be ticking by now */ CHART("ticking"); lcd_init(); #ifdef HAVE_REMOTE_LCD lcd_remote_init(); #endif font_init(); CHART(">show_logo"); show_logo(); CHART("<show_logo"); lang_init(core_language_builtin, language_strings, LANG_LAST_INDEX_IN_ARRAY); #ifdef DEBUG debug_init(); #else #ifdef HAVE_SERIAL serial_setup(); #endif #endif #if CONFIG_RTC rtc_init(); #endif #ifdef HAVE_RTC_RAM CHART(">settings_load(RTC)"); settings_load(SETTINGS_RTC); /* early load parts of global_settings */ CHART("<settings_load(RTC)"); #endif adc_init(); usb_init(); #if CONFIG_USBOTG == USBOTG_ISP1362 isp1362_init(); #elif CONFIG_USBOTG == USBOTG_M5636 m5636_init(); #endif backlight_init(); button_init(); powermgmt_init(); #if CONFIG_TUNER radio_init(); #endif /* Keep the order of this 3 (viewportmanager handles statusbars) * Must be done before any code uses the multi-screen API */ CHART(">gui_syncstatusbar_init"); gui_syncstatusbar_init(&statusbars); CHART("<gui_syncstatusbar_init"); CHART(">sb_skin_init"); sb_skin_init(); CHART("<sb_skin_init"); CHART(">gui_sync_wps_init"); gui_sync_wps_init(); CHART("<gui_sync_wps_init"); CHART(">viewportmanager_init"); viewportmanager_init(); CHART("<viewportmanager_init"); #if CONFIG_CHARGING && (CONFIG_CPU == SH7034) /* charger_inserted() can't be used here because power_thread() hasn't checked power_input_status() yet */ if (coldstart && (power_input_status() & POWER_INPUT_MAIN_CHARGER) && !global_settings.car_adapter_mode #ifdef ATA_POWER_PLAYERSTYLE && !ide_powered() /* relies on probing result from bootloader */ #endif ) { rc = charging_screen(); /* display a "charging" screen */ if (rc == 1) /* charger removed */ power_off(); /* "On" pressed or USB connected: proceed */ show_logo(); /* again, to provide better visual feedback */ } #endif CHART(">storage_init"); rc = storage_init(); CHART("<storage_init"); if(rc) { #ifdef HAVE_LCD_BITMAP lcd_clear_display(); lcd_putsf(0, 1, "ATA error: %d", rc); lcd_puts(0, 3, "Press ON to debug"); lcd_update(); while(!(button_get(true) & BUTTON_REL)); /*DO NOT CHANGE TO ACTION SYSTEM */ dbg_ports(); #endif panicf("ata: %d", rc); } #ifdef HAVE_EEPROM_SETTINGS CHART(">eeprom_settings_init"); eeprom_settings_init(); CHART("<eeprom_settings_init"); #endif #ifndef HAVE_USBSTACK usb_start_monitoring(); while (usb_detect() == USB_INSERTED) { #ifdef HAVE_EEPROM_SETTINGS firmware_settings.disk_clean = false; #endif /* enter USB mode early, before trying to mount */ if (button_get_w_tmo(HZ/10) == SYS_USB_CONNECTED) #if (CONFIG_STORAGE & STORAGE_MMC) if (!mmc_touched() || (mmc_remove_request() == SYS_HOTSWAP_EXTRACTED)) #endif { gui_usb_screen_run(); mounted = true; /* mounting done @ end of USB mode */ } #ifdef HAVE_USB_POWER if (usb_powered()) /* avoid deadlock */ break; #endif } #endif if (!mounted) { CHART(">disk_mount_all"); rc = disk_mount_all(); CHART("<disk_mount_all"); if (rc<=0) { lcd_clear_display(); lcd_puts(0, 0, "No partition"); lcd_puts(0, 1, "found."); #ifdef HAVE_LCD_BITMAP lcd_puts(0, 2, "Insert USB cable"); lcd_puts(0, 3, "and fix it."); #endif lcd_update(); while(button_get(true) != SYS_USB_CONNECTED) {}; gui_usb_screen_run(); system_reboot(); } } #if defined(SETTINGS_RESET) || (CONFIG_KEYPAD == IPOD_4G_PAD) || \ (CONFIG_KEYPAD == IRIVER_H10_PAD) #ifdef SETTINGS_RESET /* Reset settings if holding the reset button. (Rec on Archos, A on Gigabeat) */ if ((button_status() & SETTINGS_RESET) == SETTINGS_RESET) #else /* Reset settings if the hold button is turned on */ if (button_hold()) #endif { splash(HZ*2, str(LANG_RESET_DONE_CLEAR)); settings_reset(); } else #endif { CHART(">settings_load(ALL)"); settings_load(SETTINGS_ALL); CHART("<settings_load(ALL)"); } CHART(">init_dircache(true)"); rc = init_dircache(true); CHART("<init_dircache(true)"); if (rc < 0) { #ifdef HAVE_TAGCACHE remove(TAGCACHE_STATEFILE); #endif } CHART(">settings_apply(true)"); settings_apply(true); CHART("<settings_apply(true)"); CHART(">init_dircache(false)"); init_dircache(false); CHART("<init_dircache(false)"); #ifdef HAVE_TAGCACHE CHART(">init_tagcache"); init_tagcache(); CHART("<init_tagcache"); #endif #ifdef HAVE_EEPROM_SETTINGS if (firmware_settings.initialized) { /* In case we crash. */ firmware_settings.disk_clean = false; CHART(">eeprom_settings_store"); eeprom_settings_store(); CHART("<eeprom_settings_store"); } #endif playlist_init(); tree_mem_init(); filetype_init(); scrobbler_init(); #if CONFIG_CODEC == SWCODEC tdspeed_init(); #endif /* CONFIG_CODEC == SWCODEC */ #if CONFIG_CODEC != SWCODEC /* No buffer allocation (see buffer.c) may take place after the call to audio_init() since the mpeg thread takes the rest of the buffer space */ mp3_init( global_settings.volume, global_settings.bass, global_settings.treble, global_settings.balance, global_settings.loudness, global_settings.avc, global_settings.channel_config, global_settings.stereo_width, global_settings.mdb_strength, global_settings.mdb_harmonics, global_settings.mdb_center, global_settings.mdb_shape, global_settings.mdb_enable, global_settings.superbass); /* audio_init must to know the size of voice buffer so init voice first */ talk_init(); #endif /* CONFIG_CODEC != SWCODEC */ CHART(">audio_init"); audio_init(); CHART("<audio_init"); #if (CONFIG_CODEC == SWCODEC) && defined(HAVE_RECORDING) && !defined(SIMULATOR) pcm_rec_init(); #endif /* runtime database has to be initialized after audio_init() */ cpu_boost(false); #if CONFIG_CHARGING car_adapter_mode_init(); #endif #ifdef IPOD_ACCESSORY_PROTOCOL iap_setup(global_settings.serial_bitrate); #endif #ifdef HAVE_ACCESSORY_SUPPLY accessory_supply_set(global_settings.accessory_supply); #endif #ifdef HAVE_LINEOUT_POWEROFF lineout_set(global_settings.lineout_active); #endif #ifdef HAVE_HOTSWAP_STORAGE_AS_MAIN CHART("<check_bootfile(false)"); check_bootfile(false); /* remember write time and filesize */ CHART(">check_bootfile(false)"); #endif CHART("<settings_apply_skins"); settings_apply_skins(); CHART(">settings_apply_skins"); }
void* main(void) { char filename[MAX_PATH]; int i; int btn; int rc; int num_partitions; struct partinfo* pinfo; #if !(CONFIG_STORAGE & STORAGE_SD) char buf[256]; unsigned short* identify_info; #endif int usb = USB_EXTRACTED; chksum_crc32gentab (); system_init(); kernel_init(); #ifdef HAVE_BOOTLOADER_USB_MODE /* loader must service interrupts */ enable_interrupt(IRQ_FIQ_STATUS); #endif lcd_init(); font_init(); show_logo(); adc_init(); #ifdef HAVE_BOOTLOADER_USB_MODE button_init_device(); #else button_init(); #endif #if defined(SANSA_E200) || defined(PHILIPS_SA9200) i2c_init(); _backlight_on(); #endif if (button_hold()) { verbose = true; lcd_clear_display(); printf("Hold switch on"); printf("Shutting down..."); sleep(HZ); power_off(); } btn = button_read_device(); /* Enable bootloader messages if any button is pressed */ #ifdef HAVE_BOOTLOADER_USB_MODE lcd_clear_display(); if (btn) verbose = true; #else if (btn) { lcd_clear_display(); verbose = true; } #endif lcd_setfont(FONT_SYSFIXED); printf("Rockbox boot loader"); printf("Version: " RBVERSION); printf(MODEL_NAME); i=storage_init(); #if !(CONFIG_STORAGE & STORAGE_SD) if (i==0) { identify_info=ata_get_identify(); /* Show model */ for (i=0; i < 20; i++) { ((unsigned short*)buf)[i]=htobe16(identify_info[i+27]); } buf[40]=0; for (i=39; i && buf[i]==' '; i--) { buf[i]=0; } printf(buf); } else { error(EATA, i, true); } #endif disk_init(IF_MV(0)); num_partitions = disk_mount_all(); if (num_partitions<=0) { error(EDISK,num_partitions, true); } /* Just list the first 2 partitions since we don't have any devices yet that have more than that */ for(i=0; i<NUM_PARTITIONS; i++) { pinfo = disk_partinfo(i); printf("Partition %d: 0x%02x %ld MB", i, pinfo->type, pinfo->size / 2048); } /* Now that storage is initialized, check for USB connection */ if ((btn & BOOTLOADER_BOOT_OF) == 0) { usb_pin_init(); usb = handle_usb(HZ*2); if (usb == USB_INSERTED) btn |= BOOTLOADER_BOOT_OF; } /* Try loading Rockbox, if that fails, fall back to the OF */ if((btn & BOOTLOADER_BOOT_OF) == 0) { printf("Loading Rockbox..."); snprintf(filename,sizeof(filename), BOOTDIR "/%s", BOOTFILE); rc = load_mi4(loadbuffer, filename, MAX_LOADSIZE); if (rc <= EFILE_EMPTY) { bool old_verbose = verbose; verbose = true; printf("Can't load " BOOTFILE ": "); printf(loader_strerror(rc)); verbose = old_verbose; btn |= BOOTLOADER_BOOT_OF; sleep(5*HZ); } else goto main_exit; } if(btn & BOOTLOADER_BOOT_OF) { /* Load original mi4 firmware in to a memory buffer called loadbuffer. The rest of the loading is done in crt0.S. 1) First try reading from the hidden partition (on Sansa only). 2) Next try a decrypted mi4 file in /System/OF.mi4 3) Finally, try a raw firmware binary in /System/OF.bin. It should be a mi4 firmware decrypted and header stripped using mi4code. */ printf("Loading original firmware..."); #if (CONFIG_STORAGE & STORAGE_SD) /* First try a (hidden) firmware partition */ printf("Trying firmware partition"); pinfo = disk_partinfo(1); if(pinfo->type == PARTITION_TYPE_OS2_HIDDEN_C_DRIVE) { rc = load_mi4_part(loadbuffer, pinfo, MAX_LOADSIZE, usb == USB_INSERTED); if (rc <= EFILE_EMPTY) { printf("Can't load from partition"); printf(loader_strerror(rc)); } else { goto main_exit; } } else { printf("No hidden partition found."); } #endif #if defined(PHILIPS_HDD1630) || defined(PHILIPS_HDD6330) || defined(PHILIPS_SA9200) printf("Trying /System/OF.ebn"); rc=load_mi4(loadbuffer, "/System/OF.ebn", MAX_LOADSIZE); if (rc <= EFILE_EMPTY) { printf("Can't load /System/OF.ebn"); printf(loader_strerror(rc)); } else { goto main_exit; } #endif printf("Trying /System/OF.mi4"); rc=load_mi4(loadbuffer, "/System/OF.mi4", MAX_LOADSIZE); if (rc <= EFILE_EMPTY) { printf("Can't load /System/OF.mi4"); printf(loader_strerror(rc)); } else { #if defined(SAMSUNG_YH925) lcd_reset(); #endif goto main_exit; } printf("Trying /System/OF.bin"); rc=load_raw_firmware(loadbuffer, "/System/OF.bin", MAX_LOADSIZE); if (rc <= EFILE_EMPTY) { printf("Can't load /System/OF.bin"); printf(loader_strerror(rc)); } else { #if defined(SAMSUNG_YH925) lcd_reset(); #endif goto main_exit; } error(0, 0, true); } main_exit: #ifdef HAVE_BOOTLOADER_USB_MODE storage_close(); system_prepare_fw_start(); #endif return (void*)loadbuffer; }
void* main(void) { #ifdef TCCBOOT int rc; unsigned char* loadbuffer = (unsigned char*)LOAD_ADDRESS; #endif system_init(); power_init(); kernel_init(); enable_irq(); lcd_init(); adc_init(); button_init(); backlight_init(); font_init(); lcd_setfont(FONT_SYSFIXED); show_logo(); _backlight_on(); /* Only load the firmware if TCCBOOT is defined - this ensures SDRAM_START is available for loading the firmware. Otherwise display the debug screen. */ #ifdef TCCBOOT printf("Rockbox boot loader"); printf("Version " RBVERSION); printf("ATA"); rc = storage_init(); if(rc) { reset_screen(); error(EATA, rc, true); } printf("mount"); rc = disk_mount_all(); if (rc<=0) { error(EDISK,rc, true); } rc = load_firmware(loadbuffer, BOOTFILE, MAX_LOAD_SIZE); if (rc <= EFILE_EMPTY) { error(EBOOTFILE,rc, true); } else { int(*kernel_entry)(void) = (void *) loadbuffer; disable_irq(); rc = kernel_entry(); } panicf("Boot failed!"); #else show_debug_screen(); #endif return 0; }
void* main(void) { char buf[256]; int i; int btn; int rc; bool haveramos; bool button_was_held; struct partinfo* pinfo; unsigned short* identify_info; /* Check the button hold status as soon as possible - to give the user maximum chance to turn it off in order to reset the settings in rockbox. */ button_was_held = button_hold(); system_init(); kernel_init(); #ifndef HAVE_BACKLIGHT_INVERSION backlight_init(); /* Turns on the backlight */ #endif lcd_init(); font_init(); #ifdef HAVE_LCD_COLOR lcd_set_foreground(LCD_WHITE); lcd_set_background(LCD_BLACK); lcd_clear_display(); #endif #if 0 /* ADC and button drivers are not yet implemented */ adc_init(); button_init(); #endif btn=key_pressed(); /* Enable bootloader messages */ if (btn==BUTTON_RIGHT) verbose = true; lcd_setfont(FONT_SYSFIXED); printf("Rockbox boot loader"); printf("Version: " RBVERSION); printf("IPOD version: 0x%08x", IPOD_HW_REVISION); i=ata_init(); if (i==0) { identify_info=ata_get_identify(); /* Show model */ for (i=0; i < 20; i++) { ((unsigned short*)buf)[i]=htobe16(identify_info[i+27]); } buf[40]=0; for (i=39; i && buf[i]==' '; i--) { buf[i]=0; } printf(buf); } else { printf("ATA: %d", i); } disk_init(); rc = disk_mount_all(); if (rc<=0) { printf("No partition found"); fatal_error(); } pinfo = disk_partinfo(1); printf("Partition 1: 0x%02x %ld sectors", pinfo->type, pinfo->size); if (button_was_held || (btn==BUTTON_MENU)) { /* If either the hold switch was on, or the Menu button was held, then try the Apple firmware */ printf("Loading original firmware..."); /* First try an apple_os.ipod file on the FAT32 partition (either in .rockbox or the root) */ rc=load_firmware(loadbuffer, "apple_os.ipod", MAX_LOADSIZE); if (rc > 0) { printf("apple_os.ipod loaded."); return (void*)DRAM_START; } else if (rc == EFILE_NOT_FOUND) { /* If apple_os.ipod doesn't exist, then check if there is an Apple firmware image in RAM */ haveramos = (memcmp((void*)(DRAM_START+0x20),"portalplayer",12)==0); if (haveramos) { /* We have a copy of the retailos in RAM, lets just run it. */ return (void*)DRAM_START; } } else { printf("Error!"); printf("Can't load apple_os.ipod:"); printf(loader_strerror(rc)); } /* Everything failed - just loop forever */ printf("No RetailOS detected"); } else if (btn==BUTTON_PLAY) { printf("Loading Linux..."); rc=load_raw_firmware(loadbuffer, "/linux.bin", MAX_LOADSIZE); if (rc <= EFILE_EMPTY) { printf("Error!"); printf("Can't load linux.bin:"); printf(loader_strerror(rc)); } else { return (void*)DRAM_START; } } else { printf("Loading Rockbox..."); rc=load_firmware(loadbuffer, BOOTFILE, MAX_LOADSIZE); if (rc > 0) { printf("Rockbox loaded."); return (void*)DRAM_START; } else if (rc == EFILE_NOT_FOUND) { /* if rockbox.ipod doesn't exist, then check if there is a Rockbox image in RAM */ haveramos = (memcmp((void*)(DRAM_START+0x20),"Rockbox\1",8)==0); if (haveramos) { /* We have a copy of Rockbox in RAM, lets just run it. */ return (void*)DRAM_START; } } printf("Error!"); printf("Can't load " BOOTFILE ": "); printf(loader_strerror(rc)); } /* If we get to here, then we haven't been able to load any firmware */ fatal_error(); /* We never get here, but keep gcc happy */ return (void*)0; }
void main(uint32_t arg, uint32_t addr) { unsigned char* loadbuffer; int buffer_size; void(*kernel_entry)(void); int ret; system_init(); kernel_init(); power_init(); enable_irq(); lcd_init(); lcd_clear_display(); lcd_update(); backlight_init(); button_init(); //button_debug_screen(); printf("Boot version: %s", RBVERSION); printf("arg=%x addr=%x", arg, addr); #ifdef SANSA_FUZEPLUS extern void imx233_mmc_disable_window(void); if(arg == 0xfee1dead) { printf("Disable MMC window."); imx233_mmc_disable_window(); } #endif ret = storage_init(); if(ret < 0) error(EATA, ret, true); /* NOTE: allow disk_init and disk_mount_all to fail since we can do USB after. * We need this order to determine the correct logical sector size */ while(!disk_init(IF_MV(0))) printf("disk_init failed!"); if((ret = disk_mount_all()) <= 0) error(EDISK, ret, false); if(usb_detect() == USB_INSERTED) usb_mode(HZ); printf("Loading firmware"); loadbuffer = (unsigned char*)loadaddress; buffer_size = (int)(loadaddressend - loadaddress); while((ret = load_firmware(loadbuffer, BOOTFILE, buffer_size)) < 0) { error(EBOOTFILE, ret, true); } kernel_entry = (void*) loadbuffer; printf("Executing"); disable_interrupt(IRQ_FIQ_STATUS); commit_discard_idcache(); kernel_entry(); printf("ERR: Failed to boot"); /* never returns */ while(1) ; }
void* main(void) { int i; int btn; int num_partitions; int crc32; char sector[512]; struct partinfo pinfo; system_init(); kernel_init(); lcd_init(); font_init(); button_init(); i2c_init(); backlight_hw_on(); lcd_set_foreground(LCD_WHITE); lcd_set_background(LCD_BLACK); lcd_clear_display(); btn = button_read_device(); verbose = true; lcd_setfont(FONT_SYSFIXED); printf("Rockbox e200R installer"); printf("Version: %s", rbversion); printf(MODEL_NAME); printf(""); i=storage_init(); filesystem_init(); num_partitions = disk_mount_all(); if (num_partitions<=0) { error(EDISK, num_partitions, true); } disk_partinfo(1, &pinfo); #if 0 /* not needed in release builds */ printf("--- Partition info ---"); printf("start: %x", pinfo.start); printf("size: %x", pinfo.size); printf("type: %x", pinfo.type); printf("reading: %x", (START_SECTOR_OF_ROM + ROMSECTOR_TO_HACK)*512); #endif storage_read_sectors(pinfo.start + START_SECTOR_OF_ROM + ROMSECTOR_TO_HACK, 1 , sector); crc32 = chksum_crc32 (sector, 512); #if 0 /* not needed in release builds */ printf("--- Hack Status ---"); printf("Sector checksum: %x", crc32); #endif if (crc32 == PATCHED_CRC32) { /* Bootloader already patched */ printf("Already unlocked"); printf("Proceed to Step 2"); } else if ((crc32 == KNOWN_CRC32) && !memcmp(§or[HACK_OFFSET], knownBytes, sizeof(knownBytes)/sizeof(*knownBytes))) { /* E200R bootloader detected - patch it */ memcpy(§or[HACK_OFFSET], changedBytes, sizeof(changedBytes)/sizeof(*changedBytes)); storage_write_sectors( pinfo.start + START_SECTOR_OF_ROM + ROMSECTOR_TO_HACK, 1 , sector); printf("Firmware unlocked"); printf("Proceed to Step 2"); } else if (is_e200(crc32)) { printf("Vanilla E200 detected!"); printf("Please install using"); printf("Sansapatcher"); } else { printf("Unknown bootloader"); printf("Rockbox installer cannot"); printf("continue"); } /* Turn button lights off */ GPIOG_OUTPUT_VAL &=~0x80; printf(""); if (button_hold()) printf("Release Hold and"); printf("Press any key to shutdown"); while(button_read_device() == BUTTON_NONE); power_off(); return NULL; }