summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTianjie Xu <xunchang@google.com>2020-12-11 22:41:54 +0000
committerAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>2020-12-11 22:41:54 +0000
commit518eb4a2adc939f139c6546040836f39a1bbc7e8 (patch)
tree5e79c0f41f18a781311ded5cb48b2e5df53a219d
parent09eb4be25f9da68eb649df89a21390ca2d3d595a (diff)
parent054c52c30a078f5a2d8883ef0cc7d3d303420f91 (diff)
downloadbootctrl-518eb4a2adc939f139c6546040836f39a1bbc7e8.tar.gz
Merge "Add function to get active boot slot" am: 054c52c30a
Original change: https://android-review.googlesource.com/c/platform/hardware/qcom/bootctrl/+/1514839 MUST ONLY BE SUBMITTED BY AUTOMERGER Change-Id: Iebe4ea85ab1c57c388b771a920b198d23000a668
-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,