int determine_boot_type(void) { DECLARE_GLOBAL_DATA_PTR; uint8_t charging; uint16_t batt_lvl; extern uint16_t check_charging(uint8_t* enabling); unsigned long bootcount = bootcount_load(); char s [5]; setenv("bootlimit", stringify(ACCLAIM_BOOTLIMIT)); setenv("altbootcmd", "mmcinit 1; booti mmc1 recovery"); batt_lvl = check_charging(&charging); lcd_console_init(); // give subtle indicator if uboot is booting from emmc or sd if(charging) lcd_bl_set_brightness(35); //batt very low, let it charge lcd_console_setpos(0, 1); //indent slightly lcd_console_setcolor(CONSOLE_COLOR_GRAY, CONSOLE_COLOR_BLACK); if (running_from_sd()) { lcd_puts("SD"); } else { lcd_puts("EMMC"); } sprintf(s, " %u", bootcount); lcd_puts(s); extern const char* board_rev_string(unsigned long btype); lcd_console_setpos(1, 1); lcd_printf("board rev: %s | %s", board_rev_string(gd->bd->bi_board_revision), (get_sdram_size() == SZ_512M?"512MB/8GB":"1GB/16GB")); lcd_console_setpos(2, 1); lcd_console_setcolor((batt_lvl < 30?(batt_lvl <= 10?CONSOLE_COLOR_RED:CONSOLE_COLOR_ORANGE):CONSOLE_COLOR_GREEN), CONSOLE_COLOR_BLACK); lcd_printf("batt level: %d\n charging %s", batt_lvl, (charging?"ENABLED":"DISABLED")); int action = get_boot_action(); while(1){ if(charging) lcd_bl_set_brightness(35); //batt very low, let it charge else lcd_bl_set_brightness(100); //batt very low, let it charge switch(action) { case BOOT_SD_NORMAL: setenv ("bootcmd", "setenv setbootargs setenv bootargs ${sdbootargs}; run setbootargs; mmcinit 0; fatload mmc 0:1 0x81000000 boot.img; booti 0x81000000"); setenv ("altbootcmd", "run bootcmd"); // for sd boot altbootcmd is the same as bootcmd display_feedback(BOOT_SD_NORMAL); return 0; case BOOT_SD_RECOVERY: setenv ("bootcmd", "setenv setbootargs setenv bootargs ${sdbootargs}; run setbootargs; mmcinit 0; fatload mmc 0:1 0x81000000 recovery.img; booti 0x81000000"); setenv ("altbootcmd", "run bootcmd"); // for sd boot altbootcmd is the same as bootcmd display_feedback(BOOT_SD_RECOVERY); return 0; case BOOT_SD_ALTBOOT: setenv ("bootcmd", "setenv setbootargs setenv bootargs ${sdbootargs}; run setbootargs; mmcinit 0; fatload mmc 0:1 0x81000000 altboot.img; booti 0x81000000"); setenv ("altbootcmd", "run bootcmd"); // for sd boot altbootcmd is the same as bootcmd display_feedback(BOOT_SD_ALTBOOT); return 0; //actually, boot from boot+512K -- thanks bauwks! case BOOT_EMMC_NORMAL: setenv("bootcmd", "mmcinit 1; booti mmc1 boot 0x80000"); display_feedback(BOOT_EMMC_NORMAL); return 0; //actually, boot from recovery+512K -- thanks bauwks! case BOOT_EMMC_RECOVERY: setenv("bootcmd", "mmcinit 1; booti mmc1 recovery 0x80000"); display_feedback(BOOT_EMMC_RECOVERY); return 0; case BOOT_EMMC_ALTBOOT: // no 512K offset, this is just a file. setenv ("bootcmd", "setenv setbootargs setenv bootargs ${emmcbootargs}; run setbootargs; mmcinit 1; fatload mmc 1:5 0x81000000 altboot.img; booti 0x81000000"); setenv ("altbootcmd", "run bootcmd"); // for emmc altboot altbootcmd is the same as bootcmd display_feedback(BOOT_EMMC_ALTBOOT); return 0; case BOOT_FASTBOOT: display_feedback(BOOT_FASTBOOT); run_command("fastboot", 0); break; case INVALID: default: printf("Aborting boot!\n"); return 1; } action = do_menu(); } }
/* * USB boot routine * * Desc: usb boot. * Retn: 0 for success, -1 for error. */ int usb_boot(unsigned zero, unsigned type, unsigned tags) { #ifdef DEBUG serial_puts_info("Usb_boot: In function of usb_boot ...\n"); #endif /* see all of files in android-1.5r2/bootable/bootloader/legacy/usbloader */ unsigned long ram_size; unsigned long addr; USB_STATUS status = {NULL, {0, 0}, 0, 0, 0}; int usb_last_stat; /* must do this before board_init() so that we ** use the partition table in the tags if it ** already exists */ linux_type = board_machtype(); linux_tags = 0; #ifdef DEBUG serial_puts_info("Usb_boot: Board init ...\n"); #endif board_init(); ram_size = initdram(0); /*test*/ if (ram_size > EMC_LOW_SDRAM_SPACE_SIZE) ram_size = EMC_LOW_SDRAM_SPACE_SIZE; /*test*/ addr = CFG_SDRAM_BASE + ram_size; /* We can reserve some RAM "on top" here. */ /* round down to next 4 kB limit. */ addr &= ~(4096 - 1); #ifdef DEBUG serial_puts_info("Usb_boot: Lcd_setmem ...\n"); #endif addr = lcd_setmem(addr); fb_base = addr; #ifdef DEBUG serial_puts_info("Usb_boot: Drv_lcd_init ...\n"); #endif drv_lcd_init(); lcd_console_init(); #if 0 memset(print_buf, 0, PRINT_BUF_MAX); strcpy(print_buf, "123456:USB FastBoot:bbb"); lcd_puts(print_buf); memset(print_buf, 0, PRINT_BUF_MAX); cprintf(print_buf, ":ABC%dEFG:a\rabc",3); lcd_puts(print_buf); #endif #if 1 memset(print_buf, '\0', PRINT_BUF_MAX); cprintf(print_buf, "USB FastBoot: V %s\n", FAST_BOOT_VERSION); lcd_puts(print_buf); memset(print_buf, '\0', PRINT_BUF_MAX); cprintf(print_buf, "Machine ID: %d v %d\n", linux_type, revision); lcd_puts(print_buf); memset(print_buf, '\0', PRINT_BUF_MAX); cprintf(print_buf, "Build Date: "__DATE__", "__TIME__"\n"); lcd_puts(print_buf); /* memset(print_buf, '\0', PRINT_BUF_MAX); */ /* cprintf(print_buf, "Serial Number: %s\n", "UNKNOWN"); */ /* lcd_puts(print_buf); */ #endif #if 1 serial_puts_msg("\nUSB FastBoot: V "); serial_puts_msg(FAST_BOOT_VERSION); serial_puts_msg(" \n"); serial_puts_msg("Machine ID: "); dump_uint(linux_type); serial_puts_msg(" v "); dump_uint(revision); serial_puts_msg(" \n"); serial_puts_msg("Build Date: "); serial_puts_msg(__DATE__); serial_puts_msg(" "); serial_puts_msg(__TIME__); serial_puts_msg("\n"); serial_puts_msg("Serial Number: "); if (serialno[0]) serial_puts_msg(serialno); else serial_puts_msg("UNKNOWN\n"); #endif flash_dump_ptn(); jz4780_usbloader_init(); usb_last_stat = 1; for(;;) { /* if(__usb_detected()) { */ /* if(usb_last_stat == 0) { */ /* serial_puts("USB status: ONLINE\n"); */ /* memset(print_buf, 0, PRINT_BUF_MAX); */ /* cprintf(print_buf, "\rUSB status: ONLINE"); */ /* lcd_puts(print_buf); */ /* } */ /* usb_last_stat = 1; */ /* } else { */ /* if(usb_last_stat == 1) { */ /* serial_puts("USB status: OFFLINE\n"); */ /* memset(print_buf, 0, PRINT_BUF_MAX); */ /* cprintf(print_buf, "\rUSB status: OFFLINE"); */ /* lcd_puts(print_buf); */ /* } */ /* usb_last_stat = 0; */ /* } */ jz4780_usb_poll(&status); } return 0; }