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); }
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 */ }
void GIO0(void) { /* Mask GIO0 interrupt */ IO_INTC_IRQ1 = INTR_IRQ1_EXT0; unsigned char msg[4]; i2c_read(PIC_ADR, msg, sizeof(msg)); tick_diff = current_tick - last_tick; last_tick = current_tick; unsigned short btn_press = le2short(msg); if(tick_diff >= TICK_MIN && tick_diff <= TICK_MAX) { /* Ignore this, as it is a hold event */ return; } last_btn = btn_press; switch(btn_press) { map_button(BTN_LEFT, BUTTON_LEFT); map_button(BTN_RIGHT, BUTTON_RIGHT); map_button(BTN_BACK, BUTTON_BACK); map_button(BTN_CUSTOM, BUTTON_CUSTOM); map_button(BTN_MENU, BUTTON_MENU); map_button(BTN_PLAY, BUTTON_PLAY); map_button(BTN_POWER, BUTTON_POWER); map_button(BTN_TOUCHPAD_PRESS, BUTTON_SELECT); map_button(BTN_TOUCHPAD_CORNER_DOWN, BUTTON_DOWN); map_button(BTN_TOUCHPAD_CORNER_UP, BUTTON_UP); #ifndef ZEN_VISION /* These don't seem to work for some reason on the Zen Vision.. */ case BTN_TOUCHPAD_SCROLL_DOWN: btn = BUTTON_DOWN; break; case BTN_TOUCHPAD_SCROLL_UP: btn = BUTTON_UP; break; #endif case BTN_HOLD: hold_switch = true; break; case BTN_UNHOLD: hold_switch = false; break; #ifndef ZEN_VISION /* These don't seem to work for some reason.. */ case HEADPHONE_PLUGIN_A: case HEADPHONE_PLUGIN_B: nonbtn |= NONBUTTON_HEADPHONE; break; case HEADPHONE_UNPLUG_A: case HEADPHONE_UNPLUG_B: nonbtn &= ~NONBUTTON_HEADPHONE; break; #endif case DOCK_INSERT: nonbtn |= NONBUTTON_DOCK; break; case DOCK_UNPLUG: nonbtn &= ~(NONBUTTON_DOCK | NONBUTTON_USB | NONBUTTON_POWER); break; case DOCK_USB_INSERT: nonbtn |= NONBUTTON_USB; break; case DOCK_USB_UNPLUG: nonbtn &= ~NONBUTTON_USB; break; case DOCK_POWER_INSERT: nonbtn |= NONBUTTON_POWER; break; case DOCK_POWER_UNPLUG: nonbtn &= ~NONBUTTON_POWER; break; } #ifdef BUTTON_DEBUG unsigned char weergvn[10]; #ifdef BOOTLOADER lcd_set_foreground((sw ? LCD_RGBPACK(255,0,0) : LCD_RGBPACK(0,255,0) )); #endif snprintf(weergvn, sizeof(char)*10, "%x", (unsigned int)((msg[3] << 24) | (msg[2] << 16) | (msg[1] << 8) | msg[0])); lcd_putsxy(LCD_WIDTH-SYSFONT_WIDTH*10, LCD_HEIGHT-SYSFONT_HEIGHT*10, weergvn); snprintf(weergvn, sizeof(char)*10, "%x", btn); lcd_putsxy(LCD_WIDTH-SYSFONT_WIDTH*10, LCD_HEIGHT-SYSFONT_HEIGHT*7, weergvn); #ifdef BOOTLOADER lcd_set_foreground(LCD_BLACK); #endif lcd_update(); sw = !sw; #endif logf("PIC: 0x%x", (unsigned int)((msg[3] << 24) | (msg[2] << 16) | (msg[1] << 8) | msg[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); }
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(§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; }