int main(int argc, char** argv) { if (argc == 2) { if (strcmp(argv[1], "--reboot") == 0) { reboot_to_recovery(); } else if (strcmp(argv[1], "--clear-bcb") == 0) { return clear_bcb(STATUS_FILE); } else if (strcmp(argv[1], "--setup-bcb") == 0) { return setup_bcb(COMMAND_FILE, STATUS_FILE); } else if (strcmp(argv[1], "--read-bcb") == 0) { return read_bcb(); } } else if (argc == 1 || argc == 3) { const char* input_path = nullptr; const char* map_file = CACHE_BLOCK_MAP.c_str(); if (argc == 3) { input_path = argv[1]; map_file = argv[2]; } return uncrypt_wrapper(input_path, map_file, STATUS_FILE); } usage(argv[0]); return 2; }
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; } } } }
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; }