OSDN Git Service

bootctl: add is-slot-marked-successful command.
authorDavid Zeuthen <zeuthen@google.com>
Thu, 10 Dec 2015 21:09:17 +0000 (16:09 -0500)
committerDavid Zeuthen <zeuthen@google.com>
Thu, 10 Dec 2015 21:11:52 +0000 (16:11 -0500)
This makes it easy to call the newly added isSlotMarkedSuccessful()
boot_control HAL method added in the CL at

 https://android-review.googlesource.com/#/c/185841/

This is useful for e.g. test suites.

Also improve error reporting for is-slot-bootable command.

Change-Id: I603e07d8310fc1de88114dadbaa1622a76289afb
Test: tested on edison (Brillo).

bootctl/bootctl.c

index 58fdbb6..ee8378b 100644 (file)
@@ -37,17 +37,18 @@ static void usage(FILE* where, int argc, char* argv[])
             "  %s COMMAND\n"
             "\n"
             "Commands:\n"
-            "  %s hal-info                    - Show info about boot_control HAL used.\n"
-            "  %s get-number-slots            - Prints number of slots.\n"
-            "  %s get-current-slot            - Prints currently running SLOT.\n"
-            "  %s mark-boot-successful        - Mark current slot as GOOD.\n"
-            "  %s set-active-boot-slot SLOT   - On next boot, load and execute SLOT.\n"
-            "  %s set-slot-as-unbootable SLOT - Mark SLOT as invalid.\n"
-            "  %s is-slot-bootable SLOT       - Returns 0 only if SLOT is bootable.\n"
-            "  %s get-suffix SLOT             - Prints suffix for SLOT.\n"
+            "  %s hal-info                       - Show info about boot_control HAL used.\n"
+            "  %s get-number-slots               - Prints number of slots.\n"
+            "  %s get-current-slot               - Prints currently running SLOT.\n"
+            "  %s mark-boot-successful           - Mark current slot as GOOD.\n"
+            "  %s set-active-boot-slot SLOT      - On next boot, load and execute SLOT.\n"
+            "  %s set-slot-as-unbootable SLOT    - Mark SLOT as invalid.\n"
+            "  %s is-slot-bootable SLOT          - Returns 0 only if SLOT is bootable.\n"
+            "  %s is-slot-marked-successful SLOT - Returns 0 only if SLOT is marked GOOD.\n"
+            "  %s get-suffix SLOT                - Prints suffix for SLOT.\n"
             "\n"
             "SLOT parameter is the zero-based slot-number.\n",
-            argv[0], argv[0], argv[0], argv[0], argv[0],
+            argv[0], argv[0], argv[0], argv[0], argv[0], argv[0],
             argv[0], argv[0], argv[0], argv[0], argv[0]);
 }
 
@@ -112,8 +113,13 @@ static int do_set_slot_as_unbootable(boot_control_module_t *module,
 static int do_is_slot_bootable(boot_control_module_t *module, int slot_number)
 {
     int ret = module->isSlotBootable(module, slot_number);
-    if (ret == 0)
+    if (ret == 0) {
+        return EX_SOFTWARE;
+    } else if (ret < 0) {
+        fprintf(stderr, "Error calling isSlotBootable(): %s\n",
+                strerror(-ret));
         return EX_SOFTWARE;
+    }
     return EX_OK;
 }
 
@@ -125,6 +131,24 @@ static int do_get_suffix(boot_control_module_t *module, int slot_number)
     return EX_OK;
 }
 
+static int do_is_slot_marked_successful(boot_control_module_t *module,
+                                        int slot_number)
+{
+    if (module->isSlotMarkedSuccessful == NULL) {
+        fprintf(stderr, "isSlotMarkedSuccessful() is not implemented by HAL.\n");
+        return EX_UNAVAILABLE;
+    }
+    int ret = module->isSlotMarkedSuccessful(module, slot_number);
+    if (ret == 0) {
+        return EX_SOFTWARE;
+    } else if (ret < 0) {
+        fprintf(stderr, "Error calling isSlotMarkedSuccessful(): %s\n",
+                strerror(-ret));
+        return EX_SOFTWARE;
+    }
+    return EX_OK;
+}
+
 static int parse_slot(int pos, int argc, char *argv[])
 {
     if (pos > argc - 1) {
@@ -177,6 +201,8 @@ int main(int argc, char *argv[])
         return do_is_slot_bootable(module, parse_slot(2, argc, argv));
     } else if (strcmp(argv[1], "get-suffix") == 0) {
         return do_get_suffix(module, parse_slot(2, argc, argv));
+    } else if (strcmp(argv[1], "is-slot-marked-successful") == 0) {
+        return do_is_slot_marked_successful(module, parse_slot(2, argc, argv));
     } else {
         usage(stderr, argc, argv);
         return EX_USAGE;