示例#1
0
unsigned long bootcount_load(void)
{
    if (running_from_sd()) {
        return 0;
    }

    unsigned long bootcount = ACCLAIM_BOOTLIMIT + 1; // Set bootcount to limit+1 per default, in case we fail to read it apply factory fallback

    sprintf(buf, "mmcinit 1; fatload mmc 1:5 0x%08x BootCnt 4", &bootcount);
    if (run_command(buf, 0)) {
        printf("No BootCnt found, rom restore forced.\n");
        write_bcb(&romrestore_bcb);
    }
    return bootcount;
}
static int init_batt(void)
{
	int retries_left;
	int ret;

	for (retries_left = MAX_MAX17042_RETRIES; retries_left > 0; --retries_left) {
		// Due to issue in factory with corrupt eMMC
		// prevent access to eMMC in case of SD_BOOT
		ret = max17042_init(!running_from_sd());

		if (ret == 0) {
			break;
		}
	}

	if (ret) {
		printf("failed to initialize max17042: %d\n", ret);
	}

	return ret;
}
示例#3
0
void bootcount_store(unsigned long bootcount)
{
    if (running_from_sd()) {
        return;
    }

    printf("BootCnt %lu\n", bootcount);
    if (bootcount > ACCLAIM_BOOTLIMIT) {
        // In case we have reached the bootlimit
        // we write the factory restore bcb
        write_bcb(&factory_bcb);

        // and to prevent us from applying the factory
        // fallback for infinity we clear it before entering recovery
        bootcount = 0;
    }

    sprintf(buf, "mmcinit 1; fatsave mmc 1:5 0x%08x BootCnt", &bootcount);
    if (run_command(buf, 0)) {
        printf("Cannot write BootCnt, rom restore forced.\n");
        write_bcb(&romrestore_bcb);
    }
}
示例#4
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();
	}
}
示例#5
0
static inline enum boot_action get_boot_action(void) 
{
	u8 pwron = 0;
        volatile struct bootloader_message *bcb = (struct bootloader_message *) 0x81000000;
	volatile unsigned int *reset_reason = (unsigned int *) 0x4A307B04;

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

	// clear bootcount if requested
	if (read_u_boot_clearbc()=='1') {
		bootcount_store((unsigned long)0);
	}

        // 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) {
                      	  if (running_from_sd()) {
				return BOOT_SD_RECOVERY;
				}
				return BOOT_EMMC_RECOVERY;
			  }
                } else {
		lcd_console_setpos(53, 15);
		lcd_console_setcolor(CONSOLE_COLOR_ORANGE, CONSOLE_COLOR_BLACK);
		lcd_puts("/bootdata/BCB missing.  Running recovery.");
		if (running_from_sd()) {
			return BOOT_SD_RECOVERY;
			}
			return BOOT_EMMC_RECOVERY;
                }

	// give them time to press the button(s)
	udelay(2000*1000);

	if ((gpio_read(HOME_BUTTON) == 0) &&
		(gpio_read(POWER_BUTTON) == 1)) {  // BOTH KEYS STILL HELD FROM UB1
		if (running_from_sd()) {
			return BOOT_SD_RECOVERY;
			}
			return BOOT_EMMC_RECOVERY;
		}

		if ((gpio_read(HOME_BUTTON) == 0) &&
               		 (gpio_read(POWER_BUTTON) == 0))    // just HOME button is pressed
		{ return do_menu();
		}
	else	// default boot
		{

		char device_flag, altboot_flag;
		if ((running_from_sd()) && (!((device_flag = read_u_boot_device()) == '1'))) {
			if (altboot_flag = read_u_boot_altboot() == '1') {
				lcd_console_setpos(53, 15);
				lcd_console_setcolor(CONSOLE_COLOR_ORANGE, CONSOLE_COLOR_BLACK);
				lcd_puts("Normal SD boot overridden.  Alt boot from SD...");
				return BOOT_SD_ALTBOOT;
			} else {
				return BOOT_SD_NORMAL;
			}
		} else { 	// running from emmc or overridden
				if (altboot_flag = read_u_boot_altboot() == '1') {
					lcd_console_setpos(53, 11);
					lcd_console_setcolor(CONSOLE_COLOR_ORANGE, CONSOLE_COLOR_BLACK);
					lcd_puts("Normal SD boot overridden.  Alt boot from EMMC...");
					return BOOT_EMMC_ALTBOOT; }
				else {
					if ((device_flag == '1') && (running_from_sd())) {
					lcd_console_setpos(53, 15);
					lcd_console_setcolor(CONSOLE_COLOR_ORANGE, CONSOLE_COLOR_BLACK);
					lcd_puts("SD boot overridden.  Normal boot from EMMC..."); }
					return BOOT_EMMC_NORMAL;
				}
		}
	}
}
示例#6
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;
}