Beispiel #1
0
static void woof_woof(void)
{
    /* stop hadrware watchdog, we catched the error */
    imx233_rtc_enable_watchdog(false);
    uint32_t pc = HW_DIGCTL_SCRATCH0;
    /* write a "SWI #0xdead" instruction at the faulty instruction so that it
     * will trigger a proper backtrace */
    *(uint32_t *)pc = 0xef00dead;
    commit_discard_idcache();
}
Beispiel #2
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 */
}
Beispiel #3
0
/* load binary blob from disk to memory, returning a handle */
void * lc_open(const char *filename, unsigned char *buf, size_t buf_size)
{
    int fd = open(filename, O_RDONLY);
    ssize_t read_size;
    struct lc_header hdr;
    unsigned char *buf_end = buf+buf_size;
    off_t copy_size;

    if (fd < 0)
    {
        DEBUGF("Could not open file");
        goto error;
    }

#if NUM_CORES > 1
    /* Make sure COP cache is flushed and invalidated before loading */
    {
        int my_core = switch_core(CURRENT_CORE ^ 1);
        switch_core(my_core);
    }
#endif

    /* read the header to obtain the load address */
    read_size = read(fd, &hdr, sizeof(hdr));

    if (read_size < 0)
    {
        DEBUGF("Could not read from file");
        goto error_fd;
    }

    /* hdr.end_addr points to the end of the bss section,
     * but there might be idata/icode behind that so the bytes to copy
     * can be larger */
    copy_size = MAX(filesize(fd), hdr.end_addr - hdr.load_addr);

    if (hdr.load_addr < buf || (hdr.load_addr+copy_size) > buf_end)
    {
        DEBUGF("Binary doesn't fit into memory");
        goto error_fd;
    }

    /* go back to beginning to load the whole thing (incl. header) */
    if (lseek(fd, 0, SEEK_SET) < 0)
    {
        DEBUGF("lseek failed");
        goto error_fd;
    }

    /* the header has the addresses where the code is linked at */
    read_size = read(fd, hdr.load_addr, copy_size);
    close(fd);

    if (read_size < 0)
    {
        DEBUGF("Could not read from file");
        goto error;
    }

    /* commit dcache and discard icache */
    commit_discard_idcache();
    /* return a pointer the header, reused by lc_get_header() */
    return hdr.load_addr;

error_fd:
    close(fd);
error:
    return NULL;
}
Beispiel #4
0
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(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) ;
}