From 51e8b03f840f611ec7ca9f536e212d40b1b5c4e9 Mon Sep 17 00:00:00 2001 From: Patrick Tjin Date: Tue, 1 Sep 2015 08:15:23 -0700 Subject: [PATCH] fastboot: add flashing bootloader commands add the following commands: flashing unlock_bootloader flashing lock_bootloader flashing get_unlock_bootloader_nonce Change-Id: Ia4f56ebdcb6785a5196cc669d68da1553ed53c58 Signed-off-by: Patrick Tjin --- fastboot/fastboot.cpp | 56 +++++++++++++++++++++++++++++++++---------- 1 file changed, 44 insertions(+), 12 deletions(-) diff --git a/fastboot/fastboot.cpp b/fastboot/fastboot.cpp index be80cced4..de4c0ea41 100644 --- a/fastboot/fastboot.cpp +++ b/fastboot/fastboot.cpp @@ -279,17 +279,22 @@ void usage(void) " flashall flash boot, system, vendor and if found,\n" " recovery\n" " flash [ ] write a file to a flash partition\n" - " flashing lock locks the device. Prevents flashing" + " flashing lock locks the device. Prevents flashing\n" " partitions\n" - " flashing unlock unlocks the device. Allows user to" - " flash any partition except the ones" + " flashing unlock unlocks the device. Allows user to\n" + " flash any partition except the ones\n" " that are related to bootloader\n" - " flashing lock_critical Prevents flashing bootloader related" + " flashing lock_critical Prevents flashing bootloader related\n" " partitions\n" - " flashing unlock_critical Enables flashing bootloader related" + " flashing unlock_critical Enables flashing bootloader related\n" " partitions\n" - " flashing get_unlock_ability Queries bootloader to see if the" + " flashing get_unlock_ability Queries bootloader to see if the\n" " device is unlocked\n" + " flashing get_unlock_bootloader_nonce Queries the bootloader to get the\n" + " unlock nonce\n" + " flashing unlock_bootloader Issue unlock bootloader using request\n" + " flashing lock_bootloader Locks the bootloader to prevent\n" + " bootloader version rollback\n" " erase erase a flash partition\n" " format[:[][:[]] format a flash partition.\n" " Can override the fs type and/or\n" @@ -831,6 +836,27 @@ void do_flashall(usb_handle *usb, int erase_first) #define skip(n) do { argc -= (n); argv += (n); } while (0) #define require(n) do { if (argc < (n)) {usage(); exit(1);}} while (0) +int do_bypass_unlock_command(int argc, char **argv) +{ + unsigned sz; + void *data; + + if (argc <= 2) return 0; + skip(2); + + /* + * Process unlock_bootloader, we have to load the message file + * and send that to the remote device. + */ + require(1); + data = load_file(*argv, &sz); + if (data == 0) die("could not load '%s': %s", *argv, strerror(errno)); + fb_queue_download("unlock_message", data, sz); + fb_queue_command("flashing unlock_bootloader", "unlocking bootloader"); + skip(1); + return 0; +} + int do_oem_command(int argc, char **argv) { char command[256]; @@ -1230,12 +1256,18 @@ int main(int argc, char **argv) wants_reboot = 1; } else if(!strcmp(*argv, "oem")) { argc = do_oem_command(argc, argv); - } else if(!strcmp(*argv, "flashing") && argc == 2) { - if(!strcmp(*(argv+1), "unlock") || !strcmp(*(argv+1), "lock") - || !strcmp(*(argv+1), "unlock_critical") - || !strcmp(*(argv+1), "lock_critical") - || !strcmp(*(argv+1), "get_unlock_ability")) { - argc = do_oem_command(argc, argv); + } else if(!strcmp(*argv, "flashing")) { + if (argc == 2 && (!strcmp(*(argv+1), "unlock") || + !strcmp(*(argv+1), "lock") || + !strcmp(*(argv+1), "unlock_critical") || + !strcmp(*(argv+1), "lock_critical") || + !strcmp(*(argv+1), "get_unlock_ability") || + !strcmp(*(argv+1), "get_unlock_bootloader_nonce") || + !strcmp(*(argv+1), "lock_bootloader"))) { + argc = do_oem_command(argc, argv); + } else + if (argc == 3 && !strcmp(*(argv+1), "unlock_bootloader")) { + argc = do_bypass_unlock_command(argc, argv); } else { usage(); return 1;