diff options
author | Tianjie Xu <xunchang@google.com> | 2020-12-11 23:02:11 +0000 |
---|---|---|
committer | Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com> | 2020-12-11 23:02:11 +0000 |
commit | fed02fe9c85c630dc6c750fd9f6d05ec5b6dc13e (patch) | |
tree | 5e79c0f41f18a781311ded5cb48b2e5df53a219d | |
parent | 09eb4be25f9da68eb649df89a21390ca2d3d595a (diff) | |
parent | 518eb4a2adc939f139c6546040836f39a1bbc7e8 (diff) | |
download | bootctrl-fed02fe9c85c630dc6c750fd9f6d05ec5b6dc13e.tar.gz |
Merge "Add function to get active boot slot" am: 054c52c30a am: 518eb4a2ad
Original change: https://android-review.googlesource.com/c/platform/hardware/qcom/bootctrl/+/1514839
MUST ONLY BE SUBMITTED BY AUTOMERGER
Change-Id: Id1fcb9b1808a1c769addd79dc1ba972d67407ec1
-rw-r--r-- | boot_control.cpp | 30 |
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, |