From 13454095374239a807237d3e073bd3ff488bd98d Mon Sep 17 00:00:00 2001 From: Daniel Rosenberg Date: Mon, 27 Jun 2016 19:43:11 -0700 Subject: [PATCH] Call set_active after flashall and update If the device has previously failed to boot, and the current slot is marked as unbootable, we must call set_active to reenable the slot. Bug: 29827625 Change-Id: I8b723dda80e246b48e5967aff4503c3d120bfb9b (cherry-picked from commit 9c9a6c62e5a6dde562a291a11602d4f32b2c1c80) --- fastboot/fastboot.cpp | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/fastboot/fastboot.cpp b/fastboot/fastboot.cpp index c097d045e..a2af61a87 100644 --- a/fastboot/fastboot.cpp +++ b/fastboot/fastboot.cpp @@ -307,8 +307,11 @@ static void usage() { "\n" "commands:\n" " update Reflash device from update.zip.\n" + " Sets the flashed slot as active.\n" " flashall Flash boot, system, vendor, and --\n" - " if found -- recovery.\n" + " if found -- recovery. If the device\n" + " supports slots, the slot that has\n" + " been flashed to is set as active.\n" " flash [ ] Write a file to a flash partition.\n" " flashing lock Locks the device. Prevents flashing.\n" " flashing unlock Unlocks the device. Allows flashing\n" @@ -907,6 +910,20 @@ static void do_update_signature(ZipArchiveHandle zip, char* fn) { fb_queue_command("signature", "installing signature"); } +// Sets slot_override as the active slot. If slot_override is blank, +// set current slot as active instead. This clears slot-unbootable. +static void set_active(Transport* transport, const char* slot_override) { + if (slot_override && slot_override[0]) { + fb_set_active(slot_override); + } else { + std::string current_slot; + if (fb_getvar(transport, "current-slot", ¤t_slot)) { + current_slot = verify_slot(transport, current_slot.c_str(), false); + fb_set_active(current_slot.c_str()); + } + } +} + static void do_update(Transport* transport, const char* filename, const char* slot_override, bool erase_first) { queue_info_dump(); @@ -957,6 +974,7 @@ static void do_update(Transport* transport, const char* filename, const char* sl } CloseArchive(zip); + set_active(transport, slot_override); } static void do_send_signature(const char* filename) { @@ -1007,6 +1025,8 @@ static void do_flashall(Transport* transport, const char* slot_override, int era }; do_for_partitions(transport, images[i].part_name, slot_override, flashall, false); } + + set_active(transport, slot_override); } #define skip(n) do { argc -= (n); argv += (n); } while (0) @@ -1327,7 +1347,12 @@ int main(int argc, char **argv) if (wants_set_active) { if (next_active == "") { if (slot_override == "") { - wants_set_active = false; + std::string current_slot; + if (fb_getvar(transport, "current-slot", ¤t_slot)) { + next_active = verify_slot(transport, current_slot.c_str(), false); + } else { + wants_set_active = false; + } } else { next_active = verify_slot(transport, slot_override.c_str(), false); }