summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTianjie <xunchang@google.com>2020-11-30 17:40:38 -0800
committerTianjie <xunchang@google.com>2020-12-03 17:40:47 -0800
commit6cc03fa37a3b990b77df0a6f7a08e7244b377124 (patch)
tree5e79c0f41f18a781311ded5cb48b2e5df53a219d
parent251f446cd40ef36dc803dc7ff2bf3c39f95638e9 (diff)
downloadbootctrl-6cc03fa37a3b990b77df0a6f7a08e7244b377124.tar.gz
Add function to get active boot slot
This implements bootcontrol HAL 1.2; and it's useful for clients to query the slot to boot into on the next boot. Bug: 170664917 Bug: 173808057 Test: Vts test for bootcontrol Change-Id: I23e706e420c6248d181352d9566feaa2ab0f91c2
-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,