// clear the recovery command and prepare to boot a (hopefully working) system, // copy our log file to cache as well (for the system to read), and // record any intent we were asked to communicate back to the system. // this function is idempotent: call it as many times as you like. static void finish_recovery(const char *send_intent) { // By this point, we're ready to return to the main system... if (send_intent != NULL) { FILE *fp = fopen_path(INTENT_FILE, "w"); if (fp == NULL) { LOGE("Can't open %s\n", INTENT_FILE); } else { fputs(send_intent, fp); check_and_fclose(fp, INTENT_FILE); } } // Copy logs to cache so the system can find out what happened. copy_log_file(LOG_FILE, true); copy_log_file(LAST_LOG_FILE, false); chmod(LAST_LOG_FILE, 0640); if (device_flash_type() == MTD) { // Reset to mormal system boot so recovery won't cycle indefinitely. struct bootloader_message boot; memset(&boot, 0, sizeof(boot)); set_bootloader_message(&boot); } // Remove the command file, so recovery won't repeat indefinitely. if (ensure_path_mounted(COMMAND_FILE) != 0 || (unlink(COMMAND_FILE) && errno != ENOENT)) { LOGW("Can't unlink %s\n", COMMAND_FILE); } sync(); // For good measure. }
int get_partition_device(const char *partition, char *device) { int type = device_flash_type(); switch (type) { case MTD: return cmd_mtd_get_partition_device(partition, device); case MMC: return cmd_mmc_get_partition_device(partition, device); case BML: return cmd_bml_get_partition_device(partition, device); default: return -1; } }
void process_volumes() { create_fstab(); if (is_data_media()) { setup_data_media(); } return; // dead code. if (device_flash_type() != BML) return; ui_print("Checking for ext4 partitions...\n"); int ret = 0; ret = bml_check_volume("/system"); ret |= bml_check_volume("/data"); if (has_datadata()) ret |= bml_check_volume("/datadata"); ret |= bml_check_volume("/cache"); if (ret == 0) { ui_print("Done!\n"); return; } char backup_path[PATH_MAX]; //time_t t = time(NULL); char backup_name[PATH_MAX]; struct timeval tp; gettimeofday(&tp, NULL); sprintf(backup_name, "before-ext4-convert-%d", tp.tv_sec); if (target_sdcard == TARGET_INTERNAL_SDCARD) { sprintf(backup_path, INTERNAL_SDCARD_PATH "/clockworkmod/backup/%s", backup_name); } else { sprintf(backup_path, EXTERNAL_SDCARD_PATH "/clockworkmod/backup/%s", backup_name); } ui_set_show_text(1); ui_print("Filesystems need to be converted to ext4.\n"); ui_print("A backup and restore will now take place.\n"); ui_print("If anything goes wrong, your backup will be\n"); ui_print("named %s. Try restoring it\n", backup_name); ui_print("in case of error.\n"); nandroid_backup(backup_path); nandroid_restore(backup_path, 1, 1, 1, 1, 1, 0); ui_set_show_text(0); }
static int detect_partition(const char *partitionType, const char *partition) { int type = device_flash_type(); if (strstr(partition, "/dev/block/mtd") != NULL) type = MTD; else if (strstr(partition, "/dev/block/mmc") != NULL) type = MMC; else if (strstr(partition, "/dev/block/bml") != NULL) type = BML; if (partitionType != NULL) { type = get_flash_type(partitionType); } return type; }
int install_zip(const char* packagefilepath) { ui_print("\n-- Installing: %s\n", packagefilepath); if (device_flash_type() == MTD) { set_sdcard_update_bootloader_message(); } int status = install_package(packagefilepath); ui_reset_progress(); if (status != INSTALL_SUCCESS) { ui_set_background(BACKGROUND_ICON_ERROR); ui_print("Installation aborted.\n"); return 1; } ui_set_background(BACKGROUND_ICON_NONE); ui_print("\nInstall from sdcard complete.\n"); return 0; }
int install_zip(const char* packagefilepath) { ui_print("\n-- 正在安装: %s\n", packagefilepath); if (device_flash_type() == MTD) { set_sdcard_update_bootloader_message(); } int status = install_package(packagefilepath); ui_reset_progress(); if (status != INSTALL_SUCCESS) { ui_set_background(BACKGROUND_ICON_ERROR); ui_print("安装已取消.\n"); return 1; } ui_set_background(BACKGROUND_ICON_NONE); ui_print("\n从SD卡安装刷机包成功!\n"); return 0; }
void process_volumes() { create_fstab(); if (is_data_media()) { setup_data_media(); } return; // dead code. if (device_flash_type() != BML) return; ui_print("正在校验 EXT4 分区...\n"); int ret = 0; ret = bml_check_volume("/system"); ret |= bml_check_volume("/data"); if (has_datadata()) ret |= bml_check_volume("/datadata"); ret |= bml_check_volume("/cache"); if (ret == 0) { ui_print("校验完成!\n"); return; } char backup_path[PATH_MAX]; time_t t = time(NULL); char backup_name[PATH_MAX]; struct timeval tp; gettimeofday(&tp, NULL); sprintf(backup_name, "before-ext4-convert-%d", tp.tv_sec); sprintf(backup_path, "/sdcard/clockworkmod/backup/%s", backup_name); ui_set_show_text(1); ui_print("文件系统将会被转换为 EXT4格式.\n"); ui_print("将会进行备份和恢复操作.\n"); ui_print("如果出现错误你可以恢复\n"); ui_print("文件名为%s的备份\n", backup_name); ui_print("在错误的情况下.\n"); nandroid_backup(backup_path); nandroid_restore(backup_path, 1, 1, 1, 1, 1, 0); ui_set_show_text(0); }
// command line args come from, in decreasing precedence: // - the actual command line // - the bootloader control block (one per line, after "recovery") // - the contents of COMMAND_FILE (one per line) static void get_args(int *argc, char ***argv) { struct bootloader_message boot; memset(&boot, 0, sizeof(boot)); if (device_flash_type() == MTD || device_flash_type() == MMC) { get_bootloader_message(&boot); // this may fail, leaving a zeroed structure } if (boot.command[0] != 0 && boot.command[0] != 255) { LOGI("Boot command: %.*s\n", sizeof(boot.command), boot.command); } if (boot.status[0] != 0 && boot.status[0] != 255) { LOGI("Boot status: %.*s\n", sizeof(boot.status), boot.status); } struct stat file_info; // --- if arguments weren't supplied, look in the bootloader control block if (*argc <= 1 && 0 != stat("/tmp/.ignorebootmessage", &file_info)) { boot.recovery[sizeof(boot.recovery) - 1] = '\0'; // Ensure termination const char *arg = strtok(boot.recovery, "\n"); if (arg != NULL && !strcmp(arg, "recovery")) { *argv = (char **) malloc(sizeof(char *) * MAX_ARGS); (*argv)[0] = strdup(arg); for (*argc = 1; *argc < MAX_ARGS; ++*argc) { if ((arg = strtok(NULL, "\n")) == NULL) break; (*argv)[*argc] = strdup(arg); } LOGI("Got arguments from boot message\n"); } else if (boot.recovery[0] != 0 && boot.recovery[0] != 255) { LOGE("Bad boot message\n\"%.20s\"\n", boot.recovery); } } // --- if that doesn't work, try the command file if (*argc <= 1) { FILE *fp = fopen_path(COMMAND_FILE, "r"); if (fp != NULL) { char *argv0 = (*argv)[0]; *argv = (char **) malloc(sizeof(char *) * MAX_ARGS); (*argv)[0] = argv0; // use the same program name char buf[MAX_ARG_LENGTH]; for (*argc = 1; *argc < MAX_ARGS; ++*argc) { if (!fgets(buf, sizeof(buf), fp)) break; (*argv)[*argc] = strdup(strtok(buf, "\r\n")); // Strip newline. } check_and_fclose(fp, COMMAND_FILE); LOGI("Got arguments from %s\n", COMMAND_FILE); } } // --> write the arguments we have back into the bootloader control block // always boot into recovery after this (until finish_recovery() is called) strlcpy(boot.command, "boot-recovery", sizeof(boot.command)); strlcpy(boot.recovery, "recovery\n", sizeof(boot.recovery)); int i; for (i = 1; i < *argc; ++i) { strlcat(boot.recovery, (*argv)[i], sizeof(boot.recovery)); strlcat(boot.recovery, "\n", sizeof(boot.recovery)); } set_bootloader_message(&boot); }
char * get_default_filesystem () { return device_flash_type () == MMC ? "ext3" : "yaffs2"; }