diff options
author | Tianjie <xunchang@google.com> | 2020-11-30 14:40:55 -0800 |
---|---|---|
committer | Tianjie <xunchang@google.com> | 2020-12-03 15:18:40 -0800 |
commit | 01d460b408b9b771d58e5e53ef1229bdd57649e7 (patch) | |
tree | fe296533f77020d60dd407a9dcc4707bce59b3cd /boot/1.1/default/boot_control/libboot_control.cpp | |
parent | 1f551d879a62f340f4d14acd9d6b22025dae928a (diff) |
Extend the bootcontrol HAL to get the active slot
The existing HAL has a setter, but no getter for the active slot for
next boot. The information is useful. For example, clients may need
to figure out which build the device will boot into.
In the resume on reboot case, we want to put the vbmeta digest
together with an encrypted key. And the vbmeta digest is associated
with a set of images (depending on which slot to boot into).
Bug: 173808057
Test: run vts test on cuttlefish
Change-Id: Ia8578926c781eb8e006589f45ab35a95dfe4f9a0
Diffstat (limited to 'boot/1.1/default/boot_control/libboot_control.cpp')
-rw-r--r-- | boot/1.1/default/boot_control/libboot_control.cpp | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/boot/1.1/default/boot_control/libboot_control.cpp b/boot/1.1/default/boot_control/libboot_control.cpp index 2c6ccafd7d..9387c32b14 100644 --- a/boot/1.1/default/boot_control/libboot_control.cpp +++ b/boot/1.1/default/boot_control/libboot_control.cpp @@ -261,6 +261,24 @@ bool BootControl::MarkBootSuccessful() { return UpdateAndSaveBootloaderControl(misc_device_, &bootctrl); } +unsigned int BootControl::GetActiveBootSlot() { + bootloader_control bootctrl; + if (!LoadBootloaderControl(misc_device_, &bootctrl)) return false; + + // Use the current slot by default. + unsigned int active_boot_slot = current_slot_; + unsigned int max_priority = bootctrl.slot_info[current_slot_].priority; + // Find the slot with the highest priority. + for (unsigned int i = 0; i < num_slots_; ++i) { + if (bootctrl.slot_info[i].priority > max_priority) { + max_priority = bootctrl.slot_info[i].priority; + active_boot_slot = i; + } + } + + return active_boot_slot; +} + bool BootControl::SetActiveBootSlot(unsigned int slot) { if (slot >= kMaxNumSlots || slot >= num_slots_) { // Invalid slot number. |