Exemplo n.º 1
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;
}
Exemplo n.º 2
0
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;
}
Exemplo n.º 3
0
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(&sector[HACK_OFFSET], knownBytes, 
                sizeof(knownBytes)/sizeof(*knownBytes)))
    {
        /* E200R bootloader detected - patch it */
        memcpy(&sector[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;
}