summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTianjie Xu <xunchang@google.com>2020-12-11 23:21:48 +0000
committerAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>2020-12-11 23:21:48 +0000
commita3c5bdb5941ac8f67f27f12f633fe6bfe59b1341 (patch)
tree5e79c0f41f18a781311ded5cb48b2e5df53a219d
parent75e1358d6b73224cd3c42deb556d72a473f2cf7b (diff)
parentfed02fe9c85c630dc6c750fd9f6d05ec5b6dc13e (diff)
downloadbootctrl-a3c5bdb5941ac8f67f27f12f633fe6bfe59b1341.tar.gz
Merge "Add function to get active boot slot" am: 054c52c30a am: 518eb4a2ad am: fed02fe9c8
Original change: https://android-review.googlesource.com/c/platform/hardware/qcom/bootctrl/+/1514839 MUST ONLY BE SUBMITTED BY AUTOMERGER Change-Id: Ideecb39176d0f41b3f5c26f28e9d42043e363a11
-rw-r--r--boot_control.cpp30
1 files changed, 30 insertions, 0 deletions
diff --git a/boot_control.cpp b/boot_control.cpp
index 2452412..82daba0 100644
--- a/boot_control.cpp
+++ b/boot_control.cpp
@@ -518,6 +518,35 @@ error:
return -1;
}
+unsigned get_active_boot_slot(struct boot_control_module *module)
+{
+ if (!module) {
+ ALOGE("%s: Invalid argument", __func__);
+ // The HAL spec requires that we return a number between
+ // 0 to num_slots - 1. Since something went wrong here we
+ // are just going to return the default slot.
+ return 0;
+ }
+
+ uint32_t num_slots = get_number_slots(module);
+ if (num_slots <= 1) {
+ //Slot 0 is the only slot around.
+ return 0;
+ }
+
+ for (uint32_t i = 0; i < num_slots; i++) {
+ char bootPartition[MAX_GPT_NAME_SIZE + 1] = {0};
+ snprintf(bootPartition, sizeof(bootPartition) - 1, "boot%s",
+ slot_suffix_arr[i]);
+ if (get_partition_attribute(bootPartition, ATTR_SLOT_ACTIVE) == 1) {
+ return i;
+ }
+ }
+
+ ALOGE("%s: Failed to find the active boot slot", __func__);
+ return 0;
+}
+
int set_active_boot_slot(struct boot_control_module *module, unsigned slot)
{
map<string, vector<string>> ptn_map;
@@ -663,6 +692,7 @@ boot_control_module_t HAL_MODULE_INFO_SYM = {
.getNumberSlots = get_number_slots,
.getCurrentSlot = get_current_slot,
.markBootSuccessful = mark_boot_successful,
+ .getActiveBootSlot = get_active_boot_slot,
.setActiveBootSlot = set_active_boot_slot,
.setSlotAsUnbootable = set_slot_as_unbootable,
.isSlotBootable = is_slot_bootable,