From 9b432054dcb16b0e31a22538b88e7b75467d1288 Mon Sep 17 00:00:00 2001 From: Daniel Rosenberg Date: Wed, 25 Nov 2015 15:17:10 -0800 Subject: [PATCH] fastboot: Re-add set_active as a command. It turns out that adding a -- allows suffixes starting with - to work fine, and there are edge cases where calling set_active twice in a command is useful, so the command version has been re-added. Change-Id: I528c258bf23ade61db530eb27586c1a1721896bc --- fastboot/fastboot.cpp | 35 ++++++++++++++++++++++++++++++----- 1 file changed, 30 insertions(+), 5 deletions(-) diff --git a/fastboot/fastboot.cpp b/fastboot/fastboot.cpp index a16d7dd23..7ace5cd63 100644 --- a/fastboot/fastboot.cpp +++ b/fastboot/fastboot.cpp @@ -279,6 +279,10 @@ static void usage() { " override the fs type and/or size\n" " the bootloader reports.\n" " getvar Display a bootloader variable.\n" + " set_active Sets the active slot. If slots are\n" + " not supported, this does nothing.\n" + " note: suffixes starting with a '-'\n" + " must use set_active -- \n" " boot [ [ ] ] Download and boot kernel.\n" " flash:raw boot [ [ ] ]\n" " Create bootimage and flash it.\n" @@ -321,7 +325,8 @@ static void usage() { " -a, --set-active[=] Sets the active slot. If no suffix is\n" " provided, this will default to the value\n" " given by --slot. If slots are not\n" - " supported, this does nothing.\n" + " supported, this does nothing. This will\n" + " run after all non-reboot commands.\n" " --unbuffered Do not buffer input or output.\n" " --version Display version.\n" " -h, --help show this message.\n" @@ -724,9 +729,19 @@ static std::vector get_suffixes(Transport* transport) { return android::base::Split(suffix_list, ","); } -static std::string verify_slot(Transport* transport, const char *slot) { +static std::string verify_slot(Transport* transport, const char *slot, bool allow_all) { if (strcmp(slot, "all") == 0) { - return "all"; + if (allow_all) { + return "all"; + } else { + std::vector suffixes = get_suffixes(transport); + if (!suffixes.empty()) { + return suffixes[0]; + } else { + fprintf(stderr, "No known slots.\n"); + exit(1); + } + } } std::vector suffixes = get_suffixes(transport); for (const std::string &suffix : suffixes) { @@ -740,6 +755,10 @@ static std::string verify_slot(Transport* transport, const char *slot) { exit(1); } +static std::string verify_slot(Transport* transport, const char *slot) { + return verify_slot(transport, slot, true); +} + static void do_for_partition(Transport* transport, const char *part, const char *slot, std::function func, bool force_slot) { std::string has_slot; @@ -1220,14 +1239,14 @@ int main(int argc, char **argv) if (slot_override != "") slot_override = verify_slot(transport, slot_override.c_str()); if (next_active != "") - next_active = verify_slot(transport, next_active.c_str()); + next_active = verify_slot(transport, next_active.c_str(), false); if (wants_set_active) { if (next_active == "") { if (slot_override == "") { wants_set_active = false; } else { - next_active = slot_override; + next_active = verify_slot(transport, slot_override.c_str(), false); } } } @@ -1385,6 +1404,12 @@ int main(int argc, char **argv) do_update(transport, "update.zip", slot_override.c_str(), erase_first); skip(1); } + wants_reboot = 1; + } else if(!strcmp(*argv, "set_active")) { + require(2); + std::string slot = verify_slot(transport, argv[1], false); + fb_set_active(slot.c_str()); + skip(2); wants_reboot = true; } else if(!strcmp(*argv, "oem")) { argc = do_oem_command(argc, argv);