diff options
author | Tianjie <xunchang@google.com> | 2020-11-25 15:08:38 -0800 |
---|---|---|
committer | Tianjie <xunchang@google.com> | 2020-11-25 15:09:42 -0800 |
commit | cc5edd34ad28dc3303ce299f0479873cffdb7cbb (patch) | |
tree | 33afaf05b59b47cd6a53a0d1fb01f245e692d1fe /bootctl | |
parent | be9534d22b6efcd1a6965986aeaae2cef33e85b1 (diff) | |
download | extras-cc5edd34ad28dc3303ce299f0479873cffdb7cbb.tar.gz |
Add command to get active slot
Bug: 173808057
Test: bootctl get-active-boot-slot
Change-Id: Iada4a608d3976adb0284cf517c376cfe9c4f8aa3
Diffstat (limited to 'bootctl')
-rw-r--r-- | bootctl/Android.bp | 1 | ||||
-rw-r--r-- | bootctl/bootctl.cpp | 27 |
2 files changed, 26 insertions, 2 deletions
diff --git a/bootctl/Android.bp b/bootctl/Android.bp index bbc33267..8843b946 100644 --- a/bootctl/Android.bp +++ b/bootctl/Android.bp @@ -12,6 +12,7 @@ cc_binary { shared_libs: [ "android.hardware.boot@1.0", "android.hardware.boot@1.1", + "android.hardware.boot@1.2", "libhidlbase", "libutils", ], diff --git a/bootctl/bootctl.cpp b/bootctl/bootctl.cpp index cefdff5b..8ead010d 100644 --- a/bootctl/bootctl.cpp +++ b/bootctl/bootctl.cpp @@ -17,7 +17,7 @@ #include <optional> #include <sstream> -#include <android/hardware/boot/1.1/IBootControl.h> +#include <android/hardware/boot/1.2/IBootControl.h> #include <sysexits.h> using android::sp; @@ -33,8 +33,9 @@ using android::hardware::boot::V1_1::MergeStatus; namespace V1_0 = android::hardware::boot::V1_0; namespace V1_1 = android::hardware::boot::V1_1; +namespace V1_2 = android::hardware::boot::V1_2; -enum BootCtlVersion { BOOTCTL_V1_0, BOOTCTL_V1_1 }; +enum BootCtlVersion { BOOTCTL_V1_0, BOOTCTL_V1_1, BOOTCTL_V1_2 }; static void usage(FILE* where, BootCtlVersion bootVersion, int /* argc */, char* argv[]) { fprintf(where, @@ -48,6 +49,7 @@ static void usage(FILE* where, BootCtlVersion bootVersion, int /* argc */, char* " get-number-slots - Prints number of slots.\n" " get-current-slot - Prints currently running SLOT.\n" " mark-boot-successful - Mark current slot as GOOD.\n" + " get-active-boot-slot - Prints the SLOT to load on next boot.\n" " set-active-boot-slot SLOT - On next boot, load and execute SLOT.\n" " set-slot-as-unbootable SLOT - Mark SLOT as invalid.\n" " is-slot-bootable SLOT - Returns 0 only if SLOT is bootable.\n" @@ -107,6 +109,12 @@ static int do_mark_boot_successful(sp<V1_0::IBootControl> module) { return handle_return(ret, cr, "Error marking as having booted successfully: %s\n"); } +static int do_get_active_boot_slot(sp<V1_2::IBootControl> module) { + uint32_t slot = module->getActiveBootSlot(); + fprintf(stdout, "%u\n", slot); + return EX_OK; +} + static int do_set_active_boot_slot(sp<V1_0::IBootControl> module, Slot slot_number) { CommandResult cr; Return<void> ret = module->setActiveBootSlot(slot_number, generate_callback(&cr)); @@ -228,6 +236,7 @@ static uint32_t parse_slot(BootCtlVersion bootVersion, int pos, int argc, char* int main(int argc, char* argv[]) { sp<V1_0::IBootControl> v1_0_module; sp<V1_1::IBootControl> v1_1_module; + sp<V1_2::IBootControl> v1_2_module; BootCtlVersion bootVersion = BOOTCTL_V1_0; v1_0_module = V1_0::IBootControl::getService(); @@ -240,6 +249,11 @@ int main(int argc, char* argv[]) { bootVersion = BOOTCTL_V1_1; } + v1_2_module = V1_2::IBootControl::castFrom(v1_0_module); + if (v1_2_module != nullptr) { + bootVersion = BOOTCTL_V1_2; + } + if (argc < 2) { usage(stderr, bootVersion, argc, argv); return EX_USAGE; @@ -280,6 +294,15 @@ int main(int argc, char* argv[]) { } } + if (strcmp(argv[1], "get-active-boot-slot") == 0) { + if (v1_2_module == nullptr) { + fprintf(stderr, "Error getting bootctrl v1.2 module.\n"); + return EX_SOFTWARE; + } + + return do_get_active_boot_slot(v1_2_module); + } + // Parameter not matched, print usage usage(stderr, bootVersion, argc, argv); return EX_USAGE; |