Exemple #1
0
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();
	}
}
Exemple #2
0
static inline enum boot_action get_boot_action(void)
{
    static struct bootloader_message update_bcb = {
        .command = "boot-recovery",
        .status = "",
        .recovery = "",
    };

    static const struct bootloader_message master_clear_bcb = {
        .command = "boot-recovery",
        .status = "",
        .recovery = "recovery\n--wipe_data_ui\n",
    };

    volatile unsigned int *reset_reason = (unsigned int *) 0x4A307B04;
    volatile struct bootloader_message *bcb = (struct bootloader_message *) 0x81000000;
    static const char reboot_panic[] = "reboot\0panic";

    u8 pwron = 0;
    int update_zip;

    if (!memcmp((const char *) PUBLIC_SAR_RAM_1_FREE, reboot_panic, sizeof(reboot_panic))) {
        printf("REBOOT DUE TO KERNEL PANIC!\n");
    }

    // First check for sd boot
    if (running_from_sd()) {
        printf("Booting from sd\n");
        return BOOT_SD;
    }

    if (mmc_init(1)) {
        printf("mmc_init failed!\n");
        return INVALID;
    }

    if (load_serial_num()) {
        printf("No serialnum found, rom restore forced.\n");
        write_bcb(&romrestore_bcb);
        return RECOVERY;
    }

    fastboot_flash_dump_ptn();

    // Then check if there's a BCB file

    if (!read_bcb()) {
        printf("BCB found, checking...\n");

        if (bcb->command[0] != 0 &&
                bcb->command[0] != 255) {
            printf("Booting into recovery\n");
            return RECOVERY;
        }
    } else {
        printf("No BCB found, recovery mode forced.\n");
        return RECOVERY;
    }

    // If cold reboot/start
    if (!(*reset_reason & WARM_RESET) &&
            strcmp((const char *) PUBLIC_SAR_RAM_1_FREE, "reboot")) {

        // Then check for update zip on sd
        update_zip = check_update_zip();

        if (update_zip >= 0 && update_zip < ARRAY_SIZE(update_zip_names)) {
            sprintf(update_bcb.recovery, "recovery\n--update_package=/sdcard/%s\n--update_factory\n", update_zip_names[update_zip]);
            write_bcb(&update_bcb);
            printf("Found %s, booting into recovery\n", update_zip_names[update_zip]);
            return RECOVERY;
        }
    } else if (!strcmp((const char *) PUBLIC_SAR_RAM_1_FREE, "recovery")) {
        printf("Rebooted with recovery reason, booting into recovery\n");
        return RECOVERY;
    }

    if (twl6030_hw_status(&pwron)) {
        printf("Failed to read twl6030 hw_status\n");
    }

    // Check master clear button press combination (power+home)
    // note that home button is inverted
    if ((gpio_read(HOME_BUTTON) == 0) &&
            (pwron & STS_PWRON) != STS_PWRON) {
        printf("Master Clear forced, booting into recovery\n");
        write_bcb(&master_clear_bcb);
        return RECOVERY;
    }

    printf("Booting into Android\n");
    return BOOT_EMMC;
}

int determine_boot_type(void)
{
    setenv("bootlimit", stringify(ACCLAIM_BOOTLIMIT));
    setenv("altbootcmd", "mmcinit 1; booti mmc1 recovery");

    switch(get_boot_action()) {
    case BOOT_SD:
        setenv ("bootcmd", "setenv setbootargs setenv bootargs ${sdbootargs}; run setbootargs; mmcinit 0; fatload mmc 0:1 0x81000000 flashing_boot.img; booti 0x81000000");
        setenv ("altbootcmd", "run bootcmd"); // for sd boot altbootcmd is the same as bootcmd
        break;

    case RECOVERY:
        setenv("bootcmd", "mmcinit 1; booti mmc1 recovery");
        break;

    case BOOT_EMMC:
        setenv("bootcmd", "mmcinit 1; booti mmc1 boot");
        break;
    case INVALID:
    default:
        printf("Aborting boot!\n");
        return 1;
    }

    return 0;
}