Esempio n. 1
0
void console_init(console_t* const console, lcd_t* const lcd, const uint_fast16_t y_top, const uint_fast16_t y_bottom) {
	console->lcd = lcd;
	console->background = color_black;
	console->foreground = color_white;
	console->x = 0;
	console->y = 0;
	lcd_set_scroll_area(console->lcd, y_top, y_bottom);
	lcd_scroll_set_position(console->lcd, 0);

	const lcd_color_t prior_background = lcd_set_background(console->lcd, console->background);
	lcd_clear_rectangle(console->lcd, 0, y_top, lcd->size.w, y_bottom - y_top);
	lcd_set_background(console->lcd, prior_background);
}
Esempio n. 2
0
static void console_crlf(console_t* const console) {
	const uint_fast16_t line_height = console->lcd->font->line_height;
	console->x = 0;
	console->y += line_height;
	const int32_t y_excess = console->y + console->lcd->font->line_height - console->lcd->scroll.height;
	if( y_excess > 0 ) {
		lcd_scroll(console->lcd, -line_height);
		console->y -= y_excess;

		const lcd_color_t prior_background = lcd_set_background(console->lcd, console->background);
		lcd_clear_rectangle(console->lcd, 0, lcd_scroll_area_y(console->lcd, console->y), console->lcd->size.w, line_height);
		lcd_set_background(console->lcd, prior_background);
	}
}
void power_off(void)
{
#if defined(HAVE_LCD_COLOR) && !defined(HAVE_LCD_SHUTDOWN)
    /* Clear the screen and backdrop to
    remove ghosting effect on shutdown */
    lcd_set_backdrop(NULL);
    lcd_set_background(LCD_WHITE);
    lcd_clear_display();
    lcd_update();
    sleep(HZ/16);
#endif

#ifndef BOOTLOADER
#ifdef IPOD_1G2G
    /* we cannot turn off the 1st gen/ 2nd gen yet. Need to figure out sleep mode. */
    system_reboot();
#else
    /* We don't turn off the ipod, we put it in a deep sleep */
    /* Clear latter part of iram (the part used by plugins/codecs) to ensure
     * that the OF behaves properly on boot. There is some kind of boot
     * failure flag there which otherwise may not be cleared.
     */
#if CONFIG_CPU == PP5022
    memset((void*)0x4000c000, 0, 0x14000);
#elif CONFIG_CPU == PP5020
    memset((void*)0x4000c000, 0, 0xc000);
#endif
    pcf50605_standby_mode();
#endif
#endif
}
Esempio n. 4
0
void console_write(console_t* const console, const char* message) {
	char c;
	
	const lcd_color_t prior_background = lcd_set_background(console->lcd, console->background);
	const lcd_color_t prior_foreground = lcd_set_foreground(console->lcd, console->foreground);

	while( (c = *(message++)) != 0 ) {
		const lcd_glyph_t* const glyph = lcd_get_glyph(console->lcd, c);
		if( (console->x + glyph->advance) > console->lcd->size.w ) {
			console_crlf(console);
		}
		lcd_draw_char(
			console->lcd,
			console->x,
			lcd_scroll_area_y(console->lcd, console->y),
			c
		);
		console->x += glyph->advance;
	}

	lcd_set_background(console->lcd, prior_background);
	lcd_set_foreground(console->lcd, prior_foreground);
}
Esempio n. 5
0
static void sig_handler(int sig, siginfo_t *siginfo, void *context)
{
    /* safe guard variable - we call backtrace() only on first
     * UIE call. This prevent endless loop if backtrace() touches
     * memory regions which cause abort
     */
    static bool triggered = false;

    lcd_set_backdrop(NULL);
    lcd_set_drawmode(DRMODE_SOLID);
    lcd_set_foreground(LCD_BLACK);
    lcd_set_background(LCD_WHITE);
    unsigned line = 0;

    lcd_setfont(FONT_SYSFIXED);
    lcd_set_viewport(NULL);
    lcd_clear_display();

    /* get context info */
    ucontext_t *uc = (ucontext_t *)context;
    unsigned long pc = uc->uc_mcontext.pc;
    unsigned long sp = uc->uc_mcontext.gregs[29];

    lcd_putsf(0, line++, "%s at %08x", strsignal(sig), pc);

    if(sig == SIGILL || sig == SIGFPE || sig == SIGSEGV || sig == SIGBUS || sig == SIGTRAP)
        lcd_putsf(0, line++, "address 0x%08x", siginfo->si_addr);

    if(!triggered)
    {
        triggered = true;
        rb_backtrace(pc, sp, &line);
    }

#ifdef ROCKBOX_HAS_LOGF
    lcd_putsf(0, line++, "logf:");
    logf_panic_dump(&line);
#endif

    lcd_update();

    system_exception_wait(); /* If this returns, try to reboot */
    system_reboot();
    while (1);       /* halt */
}
Esempio n. 6
0
void lcd_set_drawinfo(int mode, unsigned fg_brightness, unsigned bg_brightness)
{
    lcd_set_drawmode(mode);
    lcd_set_foreground(fg_brightness);
    lcd_set_background(bg_brightness);
}
Esempio n. 7
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(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;
}