diff options
author | Daniel Rosenberg <drosen@google.com> | 2016-01-06 20:56:13 +0000 |
---|---|---|
committer | android-build-merger <android-build-merger@google.com> | 2016-01-06 20:56:13 +0000 |
commit | ba3e38f9e1dd8884b4d2aaa396bb5342a440a727 (patch) | |
tree | ef4a2244ac33d293391528cd6a1dbc2805b416b1 /fastboot/fastboot.cpp | |
parent | ed60d0706e8adf45668c120540589f05a946c119 (diff) | |
parent | abf108f6b2cbcc4aaf7cea9719aff8b569245d60 (diff) |
Merge "fastboot: Add "--slot other"" am: 6bb8f752ec
am: abf108f6b2
* commit 'abf108f6b2cbcc4aaf7cea9719aff8b569245d60':
fastboot: Add "--slot other"
Diffstat (limited to 'fastboot/fastboot.cpp')
-rw-r--r-- | fastboot/fastboot.cpp | 27 |
1 files changed, 22 insertions, 5 deletions
diff --git a/fastboot/fastboot.cpp b/fastboot/fastboot.cpp index 1152520f2..a66a45a8e 100644 --- a/fastboot/fastboot.cpp +++ b/fastboot/fastboot.cpp @@ -320,9 +320,10 @@ static void usage() { " device supports slots. This will be\n" " added to all partition names that use\n" " slots. 'all' can be given to refer\n" - " to all slots. If this is not given,\n" - " slotted partitions will default to\n" - " the current active slot.\n" + " to all slots. 'other' can be given to\n" + " refer to a non-current slot. If this\n" + " flag is not used, slotted partitions\n" + " will default to the current active slot.\n" " -a, --set-active[=<suffix>] 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" @@ -797,12 +798,28 @@ static std::string verify_slot(Transport* transport, const char *slot, bool allo if (!suffixes.empty()) { return suffixes[0]; } else { - fprintf(stderr, "No known slots.\n"); - exit(1); + die("No known slots."); } } } + std::vector<std::string> suffixes = get_suffixes(transport); + + if (strcmp(slot, "other") == 0) { + std::string current_slot; + if (!fb_getvar(transport, "current-slot", ¤t_slot)) { + die("Failed to identify current slot."); + } + if (!suffixes.empty()) { + for (size_t i = 0; i < suffixes.size(); i++) { + if (current_slot == suffixes[i]) + return suffixes[(i+1)%suffixes.size()]; + } + } else { + die("No known slots."); + } + } + for (const std::string &suffix : suffixes) { if (suffix == slot) return slot; |