int install_zip(const char* packagefilepath) { ui_print("\n-- Installing: %s\n", packagefilepath); set_sdcard_update_bootloader_message(); // will ensure_path_mounted(packagefilepath) // will also set background icon to installing and indeterminate progress bar int wipe_cache = 0; int status = install_package(packagefilepath, &wipe_cache, TEMPORARY_INSTALL_FILE); ui_reset_progress(); if (status != INSTALL_SUCCESS) { copy_logs(); ui_set_background(BACKGROUND_ICON_ERROR); LOGE("Installation aborted.\n"); return 1; } else if (wipe_cache && erase_volume("/cache")) { LOGE("Cache wipe (requested by package) failed.\n"); } #ifdef PHILZ_TOUCH_RECOVERY if (show_background_icon.value) ui_set_background(BACKGROUND_ICON_CLOCKWORK); else #endif ui_set_background(BACKGROUND_ICON_NONE); ui_print("\nInstall from sdcard complete.\n"); return 0; }
int tarbackup_backup(const char* backup_path, int backup_system, int backup_data, int backup_cache, int backup_android_secure) { ui_set_background(BACKGROUND_ICON_INSTALLING); if (ensure_root_path_mounted("SDCARD:") != 0) return print_and_error("Can't mount /sdcard\n"); int ret=0; struct statfs s; if (0 != (ret = statfs("/sdcard", &s))) return print_and_error("Unable to stat /sdcard\n"); uint64_t bavail = s.f_bavail; uint64_t bsize = s.f_bsize; uint64_t sdcard_free = bavail * bsize; uint64_t sdcard_free_mb = sdcard_free / (uint64_t)(1024 * 1024); ui_print("SD Card space free: %lluMB\n", sdcard_free_mb); if (sdcard_free_mb < 220) ui_print("There may not be enough free space to complete backup... continuing...\n"); char tmp[PATH_MAX]; sprintf(tmp, "mkdir -p %s", backup_path); __system(tmp); if (backup_system && 0 != (ret = tarbackup_backup_partition_extended(backup_path, "SYSTEM:", 1))) return ret; if (backup_data && 0 != (ret = tarbackup_backup_partition_extended(backup_path, "DATA:", 1))) return ret; if (backup_data && 0 != (ret = tarbackup_backup_partition_extended(backup_path, "DATADATA:", 1))) return ret; /* struct stat st; if (0 != stat("/sdcard/.android_secure", &st)) { ui_print("No /sdcard/.android_secure found. Skipping backup of applications on external storage.\n"); } else { if (0 != (ret = nandroid_backup_partition_extended(backup_path, "SDCARD:/.android_secure", 0))) return ret; } */ if (backup_cache && 0 != (ret = tarbackup_backup_partition_extended(backup_path, "CACHE:", 0))) return ret; /* ui_print("Generating md5 sum...\n"); sprintf(tmp, "nandroid-md5.sh %s", backup_path); if (0 != (ret = __system(tmp))) { ui_print("Error while generating md5 sum!\n"); return ret; } */ sync(); ui_set_background(BACKGROUND_ICON_EBCLOCKWORK); ui_reset_progress(); ui_print("\nBackup complete!\n"); return 0; }
int nandroid_backup_cache(const char* backup_path) { ui_set_background(BACKGROUND_ICON_INSTALLING); if (ensure_root_path_mounted("SDCARD:") != 0) return print_and_error("Can't mount /sdcard\n"); int ret; struct statfs s; if (0 != (ret = statfs("/sdcard", &s))) return print_and_error("Unable to stat /sdcard\n"); uint64_t bavail = s.f_bavail; uint64_t bsize = s.f_bsize; uint64_t sdcard_free = bavail * bsize; uint64_t sdcard_free_mb = sdcard_free / (uint64_t)(1024 * 1024); ui_print("SD Card space free: %lluMB\n", sdcard_free_mb); if (sdcard_free_mb < 150) ui_print("There may not be enough free space to complete backup... continuing...\n"); char tmp[PATH_MAX]; sprintf(tmp, "mkdir -p %s", backup_path); __system(tmp); if (0 != (ret = nandroid_backup_partition_extended(backup_path, "CACHE:", 0))) return ret; sync(); ui_set_background(BACKGROUND_ICON_NONE); ui_reset_progress(); ui_print("\nBackup complete!\n"); return 0; }
int apply_from_adb() { stop_adbd(); set_usb_driver(1); ui_print("\n\n电脑端刷机开始 ...\n请在电脑上使用如下命令:\n" "\"adb sideload <刷机包路径>\"从电脑刷机...\n\n"); struct sideload_waiter_data data; if ((data.child = fork()) == 0) { execl("/sbin/recovery", "recovery", "adbd", NULL); _exit(-1); } pthread_t sideload_thread; pthread_create(&sideload_thread, NULL, &adb_sideload_thread, &data); static char* headers[] = { "ADB Sideload", "", NULL }; static char* list[] = { "返回取消", NULL }; get_menu_selection(headers, list, 0, 0); set_usb_driver(0); maybe_restart_adbd(); // kill the child kill(data.child, SIGTERM); pthread_join(sideload_thread, NULL); ui_clear_key_queue(); struct stat st; if (stat(ADB_SIDELOAD_FILENAME, &st) != 0) { if (errno == ENOENT) { ui_print("没有接收到刷机包.\n"); ui_set_background(BACKGROUND_ICON_ERROR); } else { ui_print("读取刷机包失败:\n %s\n", strerror(errno)); ui_set_background(BACKGROUND_ICON_ERROR); } return INSTALL_ERROR; } int install_status = install_package(ADB_SIDELOAD_FILENAME); ui_reset_progress(); if (install_status != INSTALL_SUCCESS) { ui_set_background(BACKGROUND_ICON_ERROR); ui_print("电脑端刷机失败.\n"); } remove(ADB_SIDELOAD_FILENAME); return install_status; }
int nandroid_restore(const char* backup_path, int restore_boot, int restore_system, int restore_data, int restore_cache, int restore_sdext) { ui_set_background(BACKGROUND_ICON_INSTALLING); ui_show_indeterminate_progress(); yaffs_files_total = 0; if (ensure_root_path_mounted("SDCARD:") != 0) return print_and_error("Can't mount /sdcard\n"); char tmp[PATH_MAX]; //ui_print("Checking MD5 sums...\n"); //sprintf(tmp, "cd %s && md5sum -c nandroid.md5", backup_path); //if (0 != __system(tmp)) // return print_and_error("MD5 mismatch!\n"); int ret; #ifndef BOARD_RECOVERY_IGNORE_BOOTABLES if (restore_boot) { ui_print("Erasing boot before restore...\n"); if (0 != (ret = format_root_device("BOOT:"))) return print_and_error("Error while formatting BOOT:!\n"); sprintf(tmp, "%s/boot.img", backup_path); ui_print("Restoring boot image...\n"); if (0 != (ret = restore_raw_partition("boot", tmp))) { ui_print("Error while flashing boot image!"); return ret; } } #endif if (restore_system && 0 != (ret = nandroid_restore_partition(backup_path, "SYSTEM:"))) return ret; if (restore_data && 0 != (ret = nandroid_restore_partition(backup_path, "DATA:"))) return ret; #ifdef BOARD_HAS_DATADATA if (restore_data && 0 != (ret = nandroid_restore_partition(backup_path, "DATADATA:"))) return ret; #endif if (restore_data && 0 != (ret = nandroid_restore_partition_extended(backup_path, "SDCARD:/.android_secure", 0))) return ret; if (restore_cache && 0 != (ret = nandroid_restore_partition_extended(backup_path, "CACHE:", 0))) return ret; if (restore_sdext && 0 != (ret = nandroid_restore_partition(backup_path, "SDEXT:"))) return ret; sync(); ui_set_background(BACKGROUND_ICON_NONE); ui_reset_progress(); ui_print("\nRestore complete!\n"); return 0; }
int apply_from_adb() { stop_adbd(); set_usb_driver(1); ui_print("\n\nSideload started ...\nNow send the package you want to apply\n" "to the device with \"adb sideload <filename>\"...\n\n"); struct sideload_waiter_data data; if ((data.child = fork()) == 0) { execl("/sbin/recovery", "recovery", "adbd", NULL); _exit(-1); } pthread_t sideload_thread; pthread_create(&sideload_thread, NULL, &adb_sideload_thread, &data); static const char* headers[] = { "ADB Sideload", "", NULL }; static char* list[] = { "Cancel sideload", NULL }; get_menu_selection(headers, list, 0, 0); set_usb_driver(0); maybe_restart_adbd(); // kill the child kill(data.child, SIGTERM); pthread_join(sideload_thread, NULL); ui_clear_key_queue(); struct stat st; if (stat(ADB_SIDELOAD_FILENAME, &st) != 0) { if (errno == ENOENT) { ui_print("No package received.\n"); ui_set_background(BACKGROUND_ICON_ERROR); } else { ui_print("Error reading package:\n %s\n", strerror(errno)); ui_set_background(BACKGROUND_ICON_ERROR); } return INSTALL_ERROR; } int install_status = install_package(ADB_SIDELOAD_FILENAME); ui_reset_progress(); if (install_status != INSTALL_SUCCESS) { ui_set_background(BACKGROUND_ICON_ERROR); ui_print("Installation aborted.\n"); } remove(ADB_SIDELOAD_FILENAME); return install_status; }
// resetting progress bar and background icon once backup/restore done or cancelled by user void finish_nandroid_job() { ui_print("Finalizing, please wait...\n"); sync(); #ifdef PHILZ_TOUCH_RECOVERY vibrate_device(1500); if (show_background_icon.value) ui_set_background(BACKGROUND_ICON_CLOCKWORK); else #endif ui_set_background(BACKGROUND_ICON_NONE); ui_reset_progress(); }
void nandroid_menu() { // define constants for menu selection #define ITEM_BACKUP_MENU 0 #define ITEM_RESTORE_MENU 1 #define ITEM_MENU_RBOOT 2 #define ITEM_MENU_BACK 3 // build headers and items in menu char* nan_headers[] = { "Nandroid Menu", "Choose Backup or Restore:", NULL }; char* nan_items[] = { "Backup Partitions", "Restore Partitions", "--> Reboot System", "<-- Back To Main Menu", NULL }; char** headers = prepend_title(nan_headers); int chosen_item; inc_menu_loc(ITEM_MENU_BACK); // record back selection into array for (;;) { ui_set_background(BACKGROUND_ICON_NANDROID); chosen_item = get_menu_selection(headers, nan_items, 0, 0); switch (chosen_item) { case ITEM_BACKUP_MENU: nan_backup_menu(0); break; case ITEM_RESTORE_MENU: choose_backup_folder(); break; case ITEM_MENU_RBOOT: tw_reboot(); break; case ITEM_MENU_BACK: dec_menu_loc(); ui_set_background(BACKGROUND_ICON_MAIN); return; } if (go_home) { // if home was called dec_menu_loc(); ui_set_background(BACKGROUND_ICON_MAIN); return; } } }
int nandroid_backup_sd(const char* backup_path) { ui_set_background(BACKGROUND_ICON_INSTALLING); if (ensure_path_mounted(backup_path) != 0) { return print_and_error("Can't mount backup path.\n"); } Volume* volume = volume_for_path(backup_path); if (NULL == volume) { if (strstr(backup_path, "/sdcard") == backup_path && is_data_media()) volume = volume_for_path("/data"); else return print_and_error("Unable to find volume for backup path.\n"); } int ret; struct statfs s; if (NULL != volume) { if (0 != (ret = statfs(volume->mount_point, &s))) return print_and_error("Unable to stat backup path.\n"); uint64_t bavail = s.f_bavail; uint64_t bsize = s.f_bsize; uint64_t sdcard_free = bavail * bsize; uint64_t sdcard_free_mb = sdcard_free / (uint64_t)(1024 * 1024); ui_print("SD Card space free: %lluMB\n", sdcard_free_mb); if (sdcard_free_mb < 150) ui_print("There may not be enough free space to complete backup... continuing...\n"); } char tmp[PATH_MAX]; sprintf(tmp, "mkdir -p %s", backup_path); __system(tmp); Volume *vol = volume_for_path("/sd-ext"); if (vol == NULL || 0 != stat(vol->device, &s)) { ui_print("No sd-ext found. Skipping backup of sd-ext.\n"); } else { if (0 != ensure_path_mounted("/sd-ext")) ui_print("Could not mount sd-ext. sd-ext backup may not be supported on this device. Skipping backup of sd-ext.\n"); else if (0 != (ret = nandroid_backup_partition(backup_path, "/sd-ext"))) return ret; } sync(); ui_set_background(BACKGROUND_ICON_NONE); ui_reset_progress(); ui_print("\nBackup complete!\n"); return 0; }
int erase_volume(const char *volume) { ui_set_background(BACKGROUND_ICON_INSTALLING); ui_show_indeterminate_progress(); ui_print("Formatting %s...\n", volume); if (strcmp(volume, "/cache") == 0) { // Any part of the log we'd copied to cache is now gone. // Reset the pointer so we copy from the beginning of the temp // log. tmplog_offset = 0; } ui_set_background(BACKGROUND_ICON_CLOCKWORK); return format_volume(volume); }
int install_update_zip (char *filename) { char *path = NULL; puts (filename); ui_print ("\n-- Install update.zip from sdcard...\n"); set_sdcard_update_bootloader_message (); ui_print ("Attempting update from...\n"); ui_print ("%s", filename); ui_print ("\n"); int status = install_package (filename); if (status != INSTALL_SUCCESS) { ui_set_background (BACKGROUND_ICON_RZ); ui_print ("Installation aborted.\n"); return 0; } else { ui_print ("\nInstall from sdcard complete.\n"); ui_print ("\nThanks for using RZrecovery.\n"); } return 0; }
int install_update_zip(char* filename) { char *path = NULL; puts(filename); path = replace_str(filename, "/sdcard/", "SDCARD:"); ui_print("\n-- Install update.zip from sdcard...\n"); set_sdcard_update_bootloader_message(); ui_print("Attempting update from...\n"); ui_print(filename); ui_print("\n"); int status = install_package(path); if (status != INSTALL_SUCCESS) { ui_set_background(BACKGROUND_ICON_ERROR); ui_print("Installation aborted.\n"); return 0; } else if (!ui_text_visible()) { return 0; // reboot if logs aren't visible } else { if (firmware_update_pending()) { ui_print("\nReboot via menu to complete\ninstallation.\n"); return 0; } else { ui_print("\nInstall from sdcard complete.\n"); ui_print("\nThanks for using RZrecovery.\n"); } } return 0; }
int install_package(const char *root_path) { ui_set_background(BACKGROUND_ICON_INSTALLING); ui_print("Finding update package...\n"); ui_show_indeterminate_progress(); LOGI("Update location: %s\n", root_path); if (ensure_root_path_mounted(root_path) != 0) { LOGE("Can't mount %s\n", root_path); return INSTALL_CORRUPT; } char path[PATH_MAX] = ""; if (translate_root_path(root_path, path, sizeof(path)) == NULL) { LOGE("Bad path %s\n", root_path); return INSTALL_CORRUPT; } ui_print("Opening update package...\n"); LOGI("Update file path: %s\n", path); int numKeys; RSAPublicKey* loadedKeys = load_keys(PUBLIC_KEYS_FILE, &numKeys); if (loadedKeys == NULL) { LOGE("Failed to load keys\n"); return INSTALL_CORRUPT; } LOGI("%d key(s) loaded from %s\n", numKeys, PUBLIC_KEYS_FILE); // Give verification half the progress bar... ui_print("Verifying update package...\n"); ui_show_progress( VERIFICATION_PROGRESS_FRACTION, VERIFICATION_PROGRESS_TIME); int err; err = verify_file(path, loadedKeys, numKeys); free(loadedKeys); LOGI("verify_file returned %d\n", err); if (err != VERIFY_SUCCESS) { LOGE("signature verification failed\n"); return INSTALL_CORRUPT; } /* Try to open the package. */ ZipArchive zip; err = mzOpenZipArchive(path, &zip); if (err != 0) { LOGE("Can't open %s\n(%s)\n", path, err != -1 ? strerror(err) : "bad"); return INSTALL_CORRUPT; } /* Verify and install the contents of the package. */ int status = handle_update_package(path, &zip); mzCloseZipArchive(&zip); return status; }
static int erase_root(const char *root) { ui_set_background(BACKGROUND_ICON_INSTALLING); ui_show_indeterminate_progress(); ui_print("Formatting %s...\n", root); return format_root_device(root); }
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; }
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; }
void wipe_data(int confirm) { if (confirm) { static char** title_headers = NULL; ui_set_background(BACKGROUND_ICON_WIPE_CHOOSE); if (title_headers == NULL) { char* headers[] = { "Confirm wipe of all user data?", " THIS CAN NOT BE UNDONE.", "", NULL }; title_headers = prepend_title((const char**)headers); } char* items[] = { " No", " Yes -- delete all user data", // [1] NULL }; int chosen_item = get_menu_selection(title_headers, items, 1, 0); if (chosen_item != 1) { return; } } ui_set_background(BACKGROUND_ICON_WIPE); ui_print("\n-- Wiping data...\n"); device_wipe_data(); erase_volume("/data"); erase_volume("/cache"); struct stat st; if (stat("/sd-ext",&st) == 0) { ui_print("Formatting /sd-ext...\n"); __system("rm -rf /sd-ext/* && rm -rf /sd-ext/.*"); } else { ui_print("/sd-ext not found, skipping...\n"); } if (0 == stat("/sdcard/.android_secure", &st)) { __system("rm -rf /sdcard/.android_secure/* && rm -rf /sdcard/.android_secure/.*"); ui_print("Formatting /sdcard/.android_secure...\n"); } else { ui_print("/sdcard/.android_secure not found, skipping...\n"); } ui_reset_progress(); ui_print("-- Data wipe complete.\n"); }
static int really_install_package(const char *path) { ui_set_background(BACKGROUND_ICON_INSTALLING); ui_print("正在查找升级包...\n"); ui_show_indeterminate_progress(); LOGI("Update location: %s\n", path); if (ensure_path_mounted(path) != 0) { LOGE("Can't mount %s\n", path); return INSTALL_CORRUPT; } ui_print("正在打开升级包...\n"); int err; if (signature_check_enabled) { int numKeys; RSAPublicKey* loadedKeys = load_keys(PUBLIC_KEYS_FILE, &numKeys); if (loadedKeys == NULL) { LOGE("Failed to load keys\n"); return INSTALL_CORRUPT; } LOGI("%d key(s) loaded from %s\n", numKeys, PUBLIC_KEYS_FILE); // Give verification half the progress bar... ui_print("正在校验升级包...\n"); ui_show_progress( VERIFICATION_PROGRESS_FRACTION, VERIFICATION_PROGRESS_TIME); err = verify_file(path, loadedKeys, numKeys); free(loadedKeys); LOGI("verify_file returned %d\n", err); if (err != VERIFY_SUCCESS) { LOGE("signature verification failed\n"); ui_show_text(1); if (!confirm_selection("Install Untrusted Package?", "确认 - 安装不严格的zip卡刷包")) return INSTALL_CORRUPT; } } /* Try to open the package. */ ZipArchive zip; err = mzOpenZipArchive(path, &zip); if (err != 0) { LOGE("Can't open %s\n(%s)\n", path, err != -1 ? strerror(err) : "bad"); return INSTALL_CORRUPT; } /* Verify and install the contents of the package. */ ui_print("正在安装更新...\n"); return try_update_binary(path, &zip); }
int start_deltaupdate(char* diff_pkg_path_name) { int status; int wipe_cache = 0; LOGI("Start delta update...\n"); set_deltaupdate_recovery_bootmessage(); status = install_package(diff_pkg_path_name, &wipe_cache, TEMPORARY_INSTALL_FILE); if (status != INSTALL_SUCCESS) { ui_set_background(BACKGROUND_ICON_ERROR); ui_print("Delta update failed.\n"); finish_recovery("--send_intent=DELTA_UPDATE_FAILED"); set_deltaupdate_status(DELTA_UPDATE_FAILED, DELTA_UPDATE_FAILED_410); reset_fota_cookie(); return -1; } // modem update starts only if android update is successful status = start_delta_modemupdate(diff_pkg_path_name); reset_fota_cookie(); // modem update is complete. Handle update result. if (status != DELTA_UPDATE_SUCCESS_200) { ui_set_background(BACKGROUND_ICON_ERROR); ui_print("Delta update failed(%d)\n",status); finish_recovery("--send_intent=DELTA_UPDATE_FAILED"); set_deltaupdate_status(DELTA_UPDATE_FAILED, DELTA_UPDATE_FAILED_410); return -1; } finish_recovery("--send_intent=DELTA_UPDATE_SUCCESSFUL"); set_deltaupdate_status(DELTA_UPDATE_SUCCESSFUL, DELTA_UPDATE_SUCCESS_200); ui_print("\nAndroid Delta Update Completed \n"); // Remove all temp files remove_tempfiles(diff_pkg_path_name); update_fotaprop(); return 0; }
int install_package(const char *path) { ui_set_background(BACKGROUND_ICON_INSTALLING); ui_print("Finding update package...\n"); ui_show_indeterminate_progress(); LOGI("Update location: %s\n", path); if (ensure_path_mounted(path) != 0) { LOGE("Can't mount %s\n", path); return INSTALL_CORRUPT; } ui_print("Opening update package...\n"); //TODO: put this back at some point /* int numKeys; RSAPublicKey* loadedKeys = load_keys(PUBLIC_KEYS_FILE, &numKeys); if (loadedKeys == NULL) { LOGE("Failed to load keys\n"); return INSTALL_CORRUPT; } LOGI("%d key(s) loaded from %s\n", numKeys, PUBLIC_KEYS_FILE); // Give verification half the progress bar... ui_print("Verifying update package...\n"); ui_show_progress( VERIFICATION_PROGRESS_FRACTION, VERIFICATION_PROGRESS_TIME); */ int err; /* err = verify_file(path, loadedKeys, numKeys); free(loadedKeys); LOGI("verify_file returned %d\n", err); if (err != VERIFY_SUCCESS) { LOGE("signature verification failed\n"); return INSTALL_CORRUPT; } */ /* Try to open the package. */ ZipArchive zip; err = mzOpenZipArchive(path, &zip); if (err != 0) { LOGE("Can't open %s\n(%s)\n", path, err != -1 ? strerror(err) : "bad"); return INSTALL_CORRUPT; } /* Verify and install the contents of the package. */ ui_print("Installing update...\n"); return try_update_binary(path, &zip); }
static void prompt_and_wait() { char** headers = prepend_title(MENU_HEADERS); for (;;) { finish_recovery(NULL); ui_reset_progress(); ui_set_background(BACKGROUND_ICON_ERROR); int chosen_item = get_menu_selection(headers, MENU_ITEMS, 0); // device-specific code may take some action here. It may // return one of the core actions handled in the switch // statement below. chosen_item = device_perform_action(chosen_item); switch (chosen_item) { case ITEM_REBOOT: return; case ITEM_APPLY_SDCARD: show_install_update_menu(); /* ui_print("\n-- Install from sdcard...\n"); set_sdcard_update_bootloader_message(); int status = install_package(SDCARD_PACKAGE_FILE); if (status != INSTALL_SUCCESS) { ui_set_background(BACKGROUND_ICON_ERROR); ui_print("Installation aborted.\n"); } else if (!ui_text_visible()) { return; // reboot if logs aren't visible } else { ui_print("\nInstall from sdcard complete.\n"); } */ break; case ITEM_WIPE_DATA: wipe_data(ui_text_visible()); if (!ui_text_visible()) return; break; case ITEM_WIPE_CACHE: ui_print("\n-- Wiping cache...\n"); erase_root("CACHE:"); ui_print("Cache wipe complete.\n"); if (!ui_text_visible()) return; break; case ITEM_ADVANCED: show_advanced_menu(); break; } } }
int install_package(const char *path) { ui_set_background(BACKGROUND_ICON_INSTALLING); ui_print("Finding update package...\n"); ui_show_indeterminate_progress(); LOGI("Update location: %s\n", path); /* if (strcmp(root_path, ":") == 0) { if (ensure_root_path_mounted(root_path) != 0) { LOGE("Can't mount %s\n", root_path); return INSTALL_CORRUPT; } if (translate_root_path(root_path, path, sizeof(path)) == NULL) { LOGE("Bad path %s\n", root_path); return INSTALL_CORRUPT; } } else { path = strndup(path, root_path); } */ ui_print("Opening update package...\n"); LOGI("Update file path: %s\n", path); /* int numKeys; RSAPublicKey* loadedKeys = load_keys(PUBLIC_KEYS_FILE, &numKeys); if (loadedKeys == NULL) { LOGE("Failed to load keys\n"); return INSTALL_CORRUPT; } LOGI("%d key(s) loaded from %s\n", numKeys, PUBLIC_KEYS_FILE); */ /* Try to open the package. */ ZipArchive zip; int err = mzOpenZipArchive(path, &zip); if (err != 0) { LOGE("Can't open %s\n(%s)\n", path, err != -1 ? strerror(err) : "bad"); return INSTALL_CORRUPT; } /* Verify and install the contents of the package. */ // int status = handle_update_package(path, &zip, loadedKeys, numKeys); int status = handle_update_package(path, &zip); mzCloseZipArchive(&zip); // free(loadedKeys); return status; }
int nandroid_backup_sd(const char* backup_path) { ui_set_background(BACKGROUND_ICON_INSTALLING); if (ensure_root_path_mounted("SDCARD:") != 0) return print_and_error("Can't mount /sdcard\n"); int ret; struct statfs s; if (0 != (ret = statfs("/sdcard", &s))) return print_and_error("Unable to stat /sdcard\n"); uint64_t bavail = s.f_bavail; uint64_t bsize = s.f_bsize; uint64_t sdcard_free = bavail * bsize; uint64_t sdcard_free_mb = sdcard_free / (uint64_t)(1024 * 1024); ui_print("SD Card space free: %lluMB\n", sdcard_free_mb); if (sdcard_free_mb < 150) ui_print("There may not be enough free space to complete backup... continuing...\n"); char tmp[PATH_MAX]; sprintf(tmp, "mkdir -p %s", backup_path); __system(tmp); struct stat st; if (0 != stat(BOARD_SDEXT_DEVICE, &st)) { ui_print("No sd-ext found. Skipping backup of sd-ext.\n"); } else { if (0 != ensure_root_path_mounted("SDEXT:")) ui_print("Could not mount sd-ext. sd-ext backup may not be supported on this device. Skipping backup of sd-ext.\n"); else if (0 != (ret = nandroid_backup_partition(backup_path, "SDEXT:"))) return ret; } sync(); ui_set_background(BACKGROUND_ICON_NONE); ui_reset_progress(); ui_print("\nBackup complete!\n"); return 0; }
static int run_bootmenu(void) { time_t start = time(NULL); LOGI("Starting bootmenu on %s", ctime(&start)); if (bypass_check()) { int status = INSTALL_SUCCESS; exec_script(FILE_PRE_MENU, DISABLE); led_alert("blue", ENABLE); status = wait_key(KEY_VOLUMEDOWN); if (status != INSTALL_ERROR) { int mode = get_bootmode(); switch (mode) { case MODE_2NDINIT: led_alert("blue", DISABLE); led_alert("green", ENABLE); snd_init(DISABLE); led_alert("green", DISABLE); break; case MODE_2NDBOOT: led_alert("blue", DISABLE); led_alert("red", ENABLE); snd_boot(DISABLE); led_alert("red", DISABLE); break; case MODE_BOOTMENU: status = INSTALL_ERROR; break; } } if (status != INSTALL_SUCCESS) { ui_init(); ui_set_background(BACKGROUND_ICON_ERROR); ui_show_text(ENABLE); LOGI("Start Android BootMenu....\n"); prompt_and_wait(); ui_finish(); } led_alert("blue", DISABLE); return EXIT_SUCCESS; } return EXIT_SUCCESS; }
int nandroid_restore_androidSecure(const char* backup_path, int restore_androidSecure) { ui_set_background(BACKGROUND_ICON_INSTALLING); ui_show_indeterminate_progress(); yaffs_files_total = 0; if (ensure_root_path_mounted("SDCARD:") != 0) return print_and_error("Can't mount /sdcard\n"); char tmp[PATH_MAX]; int ret; if (restore_androidSecure && 0 != (ret = nandroid_restore_partition_extended(backup_path, "SDCARD:/.android_secure", 0))) return ret; sync(); ui_set_background(BACKGROUND_ICON_NONE); ui_reset_progress(); ui_print("\nRestore complete!\n"); return 0; }
int install_zip(const char* packagefilepath) { ui_print("\n-- Installing: %s\n", packagefilepath); #ifndef BOARD_HAS_NO_MISC_PARTITION set_sdcard_update_bootloader_message(); #endif 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; } #ifndef BOARD_HAS_NO_MISC_PARTITION if (firmware_update_pending()) { ui_print("\nReboot via menu to complete\ninstallation.\n"); } #endif ui_set_background(BACKGROUND_ICON_EBCLOCKWORK); ui_print("\nInstall from sdcard complete.\n"); return 0; }
void dualboot_init(void) { // backup old values int backup_root = ui_root_menu; int backup_level = ui_menu_level; // show ui ui_set_show_text(1); ui_set_background(BACKGROUND_ICON_CLOCKWORK); ui_root_menu = 1; ui_menu_level = 0; // get selection dualboot_show_selection_ui(); dualboot_prepare_env(); dualboot_setup_env(); // hide ui ui_menu_level = backup_level; ui_root_menu = backup_root; ui_set_background(BACKGROUND_ICON_NONE); ui_set_show_text(1); }
int tarbackup_restore(const char* backup_path, int restore_system, int restore_data, int restore_cache, int restore_sdext) { ui_set_background(BACKGROUND_ICON_INSTALLING); ui_show_indeterminate_progress(); if (ensure_root_path_mounted("SDCARD:") != 0) return print_and_error("Can't mount /sdcard\n"); char tmp[PATH_MAX]; /* ui_print("Checking MD5 sums...\n"); sprintf(tmp, "cd %s && md5sum -c nandroid.md5", backup_path); if (0 != __system(tmp)) return print_and_error("MD5 mismatch!\n"); */ int ret=0; if (restore_system && 0 != (ret = tarbackup_restore_partition_extended(backup_path, "SYSTEM:", 1))) return ret; if (restore_data && 0 != (ret = tarbackup_restore_partition_extended(backup_path, "DATA:", 1))) return ret; if (restore_data && 0 != (ret = tarbackup_restore_partition_extended(backup_path, "DATADATA:", 1))) return ret; /* if (restore_data && 0 != (ret = tarbackup_restore_partition_extended(backup_path, "SDCARD:/.android_secure", 0))) return ret; */ if (restore_cache && 0 != (ret = tarbackup_restore_partition_extended(backup_path, "CACHE:", 0))) return ret; sync(); ui_set_background(BACKGROUND_ICON_EBCLOCKWORK); ui_reset_progress(); ui_print("\nRestore complete!\n"); detect_root_fs(); return 0; }
int nandroid_restore_sd(const char* backup_path, int restore_sdext) { ui_set_background(BACKGROUND_ICON_INSTALLING); ui_show_indeterminate_progress(); yaffs_files_total = 0; if (ensure_path_mounted(backup_path) != 0) return print_and_error("Can't mount backup path\n"); char tmp[PATH_MAX]; int ret; if (restore_sdext && 0 != (ret = nandroid_restore_partition(backup_path, "/sd-ext"))) return ret; sync(); ui_set_background(BACKGROUND_ICON_NONE); ui_reset_progress(); ui_print("\nRestore complete!\n"); return 0; }
int enter_sideload_mode(int status) { ensure_path_mounted(CACHE_ROOT); start_sideload(); static const char* headers[] = { "ADB Sideload", "", NULL }; static char* list[] = { "Cancel sideload", NULL }; int icon = ui_get_background_icon(); int wipe_cache = 0; // we need show_text to show adb sideload cancel menu (get_menu_selection()) bool text_visible = ui_IsTextVisible(); ui_SetShowText(true); get_menu_selection(headers, list, 0, 0); ui_SetShowText(text_visible); int ret = apply_from_adb(&wipe_cache, TEMPORARY_INSTALL_FILE); // if item < 0 (cancel), apply_from_adb() will return INSTALL_NONE with appropriate log message if (ret != INSTALL_NONE) { status = ret; if (status != INSTALL_SUCCESS) { ui_set_background(BACKGROUND_ICON_ERROR); ui_print("Installation aborted.\n"); } else { if (wipe_cache && erase_volume("/cache")) { LOGE("Cache wipe (requested by package) failed.\n"); } if (ui_IsTextVisible()) { ui_set_background(icon); ui_print("\nInstall from ADB complete.\n"); } } } return status; }