Add IBootControl 1.1 support to libboot_control.
Bug: 138861550 Test: vts Change-Id: Id4a2963d6ab657d8ab076b7013492a691462b287
This commit is contained in:
parent
b18f153b12
commit
46f38e4610
4 changed files with 33 additions and 1 deletions
|
@ -28,6 +28,7 @@ cc_defaults {
|
||||||
],
|
],
|
||||||
|
|
||||||
shared_libs: [
|
shared_libs: [
|
||||||
|
"android.hardware.boot@1.1",
|
||||||
"libbase",
|
"libbase",
|
||||||
"liblog",
|
"liblog",
|
||||||
],
|
],
|
||||||
|
|
|
@ -18,11 +18,15 @@
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
|
#include <android/hardware/boot/1.1/IBootControl.h>
|
||||||
|
|
||||||
namespace android {
|
namespace android {
|
||||||
namespace bootable {
|
namespace bootable {
|
||||||
|
|
||||||
// Helper library to implement the IBootControl HAL using the misc partition.
|
// Helper library to implement the IBootControl HAL using the misc partition.
|
||||||
class BootControl {
|
class BootControl {
|
||||||
|
using MergeStatus = ::android::hardware::boot::V1_1::MergeStatus;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
bool Init();
|
bool Init();
|
||||||
unsigned int GetNumberSlots();
|
unsigned int GetNumberSlots();
|
||||||
|
@ -34,6 +38,10 @@ class BootControl {
|
||||||
bool IsSlotBootable(unsigned int slot);
|
bool IsSlotBootable(unsigned int slot);
|
||||||
const char* GetSuffix(unsigned int slot);
|
const char* GetSuffix(unsigned int slot);
|
||||||
bool IsSlotMarkedSuccessful(unsigned int slot);
|
bool IsSlotMarkedSuccessful(unsigned int slot);
|
||||||
|
bool SetSnapshotMergeStatus(MergeStatus status);
|
||||||
|
MergeStatus GetSnapshotMergeStatus();
|
||||||
|
|
||||||
|
bool IsValidSlot(unsigned int slot);
|
||||||
|
|
||||||
const std::string& misc_device() const {
|
const std::string& misc_device() const {
|
||||||
return misc_device_;
|
return misc_device_;
|
||||||
|
|
|
@ -34,6 +34,8 @@
|
||||||
namespace android {
|
namespace android {
|
||||||
namespace bootable {
|
namespace bootable {
|
||||||
|
|
||||||
|
using ::android::hardware::boot::V1_1::MergeStatus;
|
||||||
|
|
||||||
// The number of boot attempts that should be made from a new slot before
|
// The number of boot attempts that should be made from a new slot before
|
||||||
// rolling back to the previous slot.
|
// rolling back to the previous slot.
|
||||||
constexpr unsigned int kDefaultBootAttempts = 7;
|
constexpr unsigned int kDefaultBootAttempts = 7;
|
||||||
|
@ -327,6 +329,25 @@ bool BootControl::IsSlotMarkedSuccessful(unsigned int slot) {
|
||||||
return bootctrl.slot_info[slot].successful_boot && bootctrl.slot_info[slot].tries_remaining;
|
return bootctrl.slot_info[slot].successful_boot && bootctrl.slot_info[slot].tries_remaining;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool BootControl::IsValidSlot(unsigned int slot) {
|
||||||
|
return slot < kMaxNumSlots && slot < num_slots_;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool BootControl::SetSnapshotMergeStatus(MergeStatus status) {
|
||||||
|
bootloader_control bootctrl;
|
||||||
|
if (!LoadBootloaderControl(misc_device_, &bootctrl)) return false;
|
||||||
|
|
||||||
|
bootctrl.merge_status = (unsigned int)status;
|
||||||
|
return UpdateAndSaveBootloaderControl(misc_device_, &bootctrl);
|
||||||
|
}
|
||||||
|
|
||||||
|
MergeStatus BootControl::GetSnapshotMergeStatus() {
|
||||||
|
bootloader_control bootctrl;
|
||||||
|
if (!LoadBootloaderControl(misc_device_, &bootctrl)) return MergeStatus::UNKNOWN;
|
||||||
|
|
||||||
|
return (MergeStatus)bootctrl.merge_status;
|
||||||
|
}
|
||||||
|
|
||||||
const char* BootControl::GetSuffix(unsigned int slot) {
|
const char* BootControl::GetSuffix(unsigned int slot) {
|
||||||
if (slot >= kMaxNumSlots || slot >= num_slots_) {
|
if (slot >= kMaxNumSlots || slot >= num_slots_) {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
|
|
@ -163,8 +163,10 @@ struct bootloader_control {
|
||||||
uint8_t nb_slot : 3;
|
uint8_t nb_slot : 3;
|
||||||
// Number of times left attempting to boot recovery.
|
// Number of times left attempting to boot recovery.
|
||||||
uint8_t recovery_tries_remaining : 3;
|
uint8_t recovery_tries_remaining : 3;
|
||||||
|
// Status of any pending snapshot merge of dynamic partitions.
|
||||||
|
uint8_t merge_status : 3;
|
||||||
// Ensure 4-bytes alignment for slot_info field.
|
// Ensure 4-bytes alignment for slot_info field.
|
||||||
uint8_t reserved0[2];
|
uint8_t reserved0[1];
|
||||||
// Per-slot information. Up to 4 slots.
|
// Per-slot information. Up to 4 slots.
|
||||||
struct slot_metadata slot_info[4];
|
struct slot_metadata slot_info[4];
|
||||||
// Reserved for further use.
|
// Reserved for further use.
|
||||||
|
|
Loading…
Reference in a new issue