summaryrefslogtreecommitdiff
path: root/fastboot/fastboot.cpp
diff options
context:
space:
mode:
authorDavid Anderson <dvander@google.com>2019-10-21 16:45:59 -0700
committerDavid Anderson <dvander@google.com>2019-10-31 01:11:16 +0000
commitab8f466107572cd18bad3ed79c77b35daca5f0e4 (patch)
treea368582462a24ac11fbd1aa5a2b4550f107ce739 /fastboot/fastboot.cpp
parent32e7325c4400dd9f5fbf359c5673c2aab53a0e85 (diff)
fastboot: Implement helper commands for Virtual A/B.
This introduces two new commands to the fastboot protocol: - getvar snapshot-update-status - Return "none", "snapshotted", or "merging" depending on the current status set by the boot control HAL. - snapshot-update [cancel] - Cancel any pending snapshot-based updates via the boot control HAL. After this, the HAL should return MergeStatus::CANCELLED and "update-merge-status" should be "none". If no argument is specified, the snapshot-update-status is returned via an INFO response. Bootloaders are expected to implement this in a manner consistent with the boot control HAL. Fastboot-based tooling should expect wipes of userdata to fail when update-merge-status returns "merging". Thus, the force flag now cancel any pending snapshots. Bug: 139154945 Test: fastboot getvar snapshot-update-status fastboot snapshot-update cancel fastboot snapshot-update Change-Id: Idc423fe7656b212e929e64eb0e6b85b453e0e8dc
Diffstat (limited to 'fastboot/fastboot.cpp')
-rw-r--r--fastboot/fastboot.cpp25
1 files changed, 25 insertions, 0 deletions
diff --git a/fastboot/fastboot.cpp b/fastboot/fastboot.cpp
index 2fe3b1a9e..7ce7c7c0e 100644
--- a/fastboot/fastboot.cpp
+++ b/fastboot/fastboot.cpp
@@ -396,6 +396,9 @@ static int show_help() {
" gsi wipe|disable Wipe or disable a GSI installation (fastbootd only).\n"
" wipe-super [SUPER_EMPTY] Wipe the super partition. This will reset it to\n"
" contain an empty set of default dynamic partitions.\n"
+ " snapshot-update cancel On devices that support snapshot-based updates, cancel\n"
+ " an in-progress update. This may make the device\n"
+ " unbootable until it is reflashed.\n"
"\n"
"boot image:\n"
" boot KERNEL [RAMDISK [SECOND]]\n"
@@ -1216,6 +1219,14 @@ static void reboot_to_userspace_fastboot() {
target_sparse_limit = -1;
}
+static void CancelSnapshotIfNeeded() {
+ std::string merge_status = "none";
+ if (fb->GetVar(FB_VAR_SNAPSHOT_UPDATE_STATUS, &merge_status) == fastboot::SUCCESS &&
+ merge_status != "none") {
+ fb->SnapshotUpdateCommand("Cancel");
+ }
+}
+
class ImageSource {
public:
virtual bool ReadFile(const std::string& name, std::vector<char>* out) const = 0;
@@ -1268,6 +1279,8 @@ void FlashAllTool::Flash() {
DetermineSecondarySlot();
CollectImages();
+ CancelSnapshotIfNeeded();
+
// First flash boot partitions. We allow this to happen either in userspace
// or in bootloader fastboot.
FlashImages(boot_images_);
@@ -2071,12 +2084,24 @@ int FastBootTool::Main(int argc, char* argv[]) {
image = next_arg(&args);
}
do_wipe_super(image, slot_override);
+ } else if (command == "snapshot-update") {
+ std::string arg;
+ if (!args.empty()) {
+ arg = next_arg(&args);
+ }
+ if (!arg.empty() && arg != "cancel") {
+ syntax_error("expected: snapshot-update [cancel]");
+ }
+ fb->SnapshotUpdateCommand(arg);
} else {
syntax_error("unknown command %s", command.c_str());
}
}
if (wants_wipe) {
+ if (force_flash) {
+ CancelSnapshotIfNeeded();
+ }
std::vector<std::string> partitions = { "userdata", "cache", "metadata" };
for (const auto& partition : partitions) {
std::string partition_type;