int maybe_install_firmware_update(const char *send_intent) { if (update_data == NULL || update_length == 0) return 0; /* We destroy the cache partition to pass the update image to the * bootloader, so all we can really do afterwards is wipe cache and reboot. * Set up this instruction now, in case we're interrupted while writing. */ struct bootloader_message boot; memset(&boot, 0, sizeof(boot)); strlcpy(boot.command, "boot-recovery", sizeof(boot.command)); strlcpy(boot.recovery, "recovery\n--wipe_cache\n", sizeof(boot.command)); if (send_intent != NULL) { strlcat(boot.recovery, "--send_intent=", sizeof(boot.recovery)); strlcat(boot.recovery, send_intent, sizeof(boot.recovery)); strlcat(boot.recovery, "\n", sizeof(boot.recovery)); } if (set_bootloader_message(&boot)) return -1; int width = 0, height = 0, bpp = 0; char *busy_image = ui_copy_image( BACKGROUND_ICON_FIRMWARE_INSTALLING, &width, &height, &bpp); char *fail_image = ui_copy_image( BACKGROUND_ICON_FIRMWARE_ERROR, &width, &height, &bpp); ui_print("Writing %s image...\n", update_type); if (write_update_for_bootloader( update_data, update_length, width, height, bpp, busy_image, fail_image)) { LOGE("Can't write %s image\n(%s)\n", update_type, strerror(errno)); format_volume("/cache"); // Attempt to clean cache up, at least. return -1; } free(busy_image); free(fail_image); /* The update image is fully written, so now we can instruct the bootloader * to install it. (After doing so, it will come back here, and we will * wipe the cache and reboot into the system.) */ snprintf(boot.command, sizeof(boot.command), "update-%s", update_type); if (set_bootloader_message(&boot)) { format_volume("/cache"); return -1; } reboot(RB_AUTOBOOT); // Can't reboot? WTF? LOGE("Can't reboot\n"); return -1; }
int install_firmware_update(const char *update_type, const char *update_data, size_t update_length, int width, int height, int bpp, const char* busy_image, const char* fail_image, const char *log_filename) { if (update_data == NULL || update_length == 0) return 0; mtd_scan_partitions(); /* We destroy the cache partition to pass the update image to the * bootloader, so all we can really do afterwards is wipe cache and reboot. * Set up this instruction now, in case we're interrupted while writing. */ struct bootloader_message boot; memset(&boot, 0, sizeof(boot)); strlcpy(boot.command, "boot-recovery", sizeof(boot.command)); strlcpy(boot.recovery, "recovery\n--wipe_cache\n", sizeof(boot.command)); if (set_bootloader_message(&boot)) return -1; if (write_update_for_bootloader( update_data, update_length, width, height, bpp, busy_image, fail_image, log_filename)) { LOGE("Can't write %s image\n(%s)\n", update_type, strerror(errno)); return -1; } /* The update image is fully written, so now we can instruct the bootloader * to install it. (After doing so, it will come back here, and we will * wipe the cache and reboot into the system.) */ snprintf(boot.command, sizeof(boot.command), "update-%s", update_type); if (set_bootloader_message(&boot)) { return -1; } reboot(RB_AUTOBOOT); // Can't reboot? WTF? LOGE("Can't reboot\n"); return -1; }