fastboot: Add "--slot other"
This allows you to flash to a slot other than the current one
without needing to enter the name of the slots.
Change-Id: I6bf8c29817be0a29b1abb005f1e72056cee126df
diff --git a/fastboot/fastboot.cpp b/fastboot/fastboot.cpp
index 5eca845..bd17485 100644
--- a/fastboot/fastboot.cpp
+++ b/fastboot/fastboot.cpp
@@ -318,9 +318,10 @@
" 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"
@@ -737,12 +738,28 @@
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;