MA-18087-3 Add snapshot-update command
authorJi Luo <ji.luo@nxp.com>
Wed, 21 Oct 2020 04:36:03 +0000 (12:36 +0800)
committerJi Luo <ji.luo@nxp.com>
Thu, 13 May 2021 01:49:18 +0000 (09:49 +0800)
Add support for 'fastboot snapshot-update cancel', it cancels
the snapshot update process so erase/update partitions can
proceed.

Test: run 'fastboot snapshot-update cancel'.

Signed-off-by: Ji Luo <ji.luo@nxp.com>
Change-Id: Ic1dfaf09a27fecf6e14b7149aeb5e0a9a1d220c9
(cherry picked from commit 3074fbf88b1b654026608574b94fdd58426ae493)
(cherry picked from commit 18c6b24524b13b3c6c5c1d7db2043159a784fccc)

drivers/fastboot/fb_fsl/fb_fsl_command.c
include/fastboot.h

index f6f7eae..2cce088 100644 (file)
@@ -948,6 +948,35 @@ static void run_acmd(char *cmd_parameter, char *response)
 }
 #endif
 
+#ifdef CONFIG_VIRTUAL_AB_SUPPORT
+static void snapshot_update(char *cmd_parameter, char *response)
+{
+       if (endswith(cmd_parameter, "cancel")) {
+               FbLockState status;
+               status = fastboot_get_lock_stat();
+               if ((status == FASTBOOT_LOCK) || (status == FASTBOOT_LOCK_ERROR)) {
+                       printf("Can not cancel snapshot update when the device is locked!\n");
+                       fastboot_fail("device is locked!", response);
+               } else if (virtual_ab_update_is_merging() || virtual_ab_update_is_snapshoted()) {
+                       if (virtual_ab_cancel_update() != -1)
+                               fastboot_okay(NULL, response);
+                       else
+                               fastboot_fail("Can't cancel snapshot update!", response);
+               } else {
+                       printf("Device is not in 'merging' or 'snapshotted' state, do nothing...\n");
+                       fastboot_okay(NULL, response);
+               }
+
+               return;
+       } else {
+               printf("Error! Only 'cancel' is supported!");
+               strcpy(response, "FAILInternal error!");
+       }
+
+       return;
+}
+#endif
+
 static const struct {
        const char *command;
        void (*dispatch)(char *cmd_parameter, char *response);
@@ -1032,6 +1061,12 @@ static const struct {
                        .dispatch = reboot_fastboot,
                },
 #endif
+#ifdef CONFIG_VIRTUAL_AB_SUPPORT
+               [FASTBOOT_COMMAND_SNAPSHOT_UPDATE] = {
+                       .command = "snapshot-update",
+                       .dispatch = snapshot_update,
+               },
+#endif
 };
 
 /**
index d2fce5b..70d5b33 100644 (file)
@@ -64,6 +64,9 @@ enum {
 #endif
 #ifdef CONFIG_ANDROID_RECOVERY
        FASTBOOT_COMMAND_RECOVERY_FASTBOOT,
+#endif
+#ifdef CONFIG_VIRTUAL_AB_SUPPORT
+       FASTBOOT_COMMAND_SNAPSHOT_UPDATE,
 #endif
        FASTBOOT_COMMAND_COUNT
 };