blob: 34a9affe111680c9a4344e2ed1cc901fa4ff9c8f [file] [log] [blame]
David Anderson8108e252019-08-28 15:24:07 -07001//
2// Copyright (C) 2019 The Android Open Source Project
3//
4// Licensed under the Apache License, Version 2.0 (the "License");
5// you may not use this file except in compliance with the License.
6// You may obtain a copy of the License at
7//
8// http://www.apache.org/licenses/LICENSE-2.0
9//
10// Unless required by applicable law or agreed to in writing, software
11// distributed under the License is distributed on an "AS IS" BASIS,
12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13// See the License for the specific language governing permissions and
14// limitations under the License.
15//
16
17#pragma once
18
19#include <string>
20
David Anderson46f38e42019-08-29 15:09:22 -070021#include <android/hardware/boot/1.1/IBootControl.h>
22
David Anderson8108e252019-08-28 15:24:07 -070023namespace android {
24namespace bootable {
25
26// Helper library to implement the IBootControl HAL using the misc partition.
27class BootControl {
David Anderson46f38e42019-08-29 15:09:22 -070028 using MergeStatus = ::android::hardware::boot::V1_1::MergeStatus;
29
David Anderson8108e252019-08-28 15:24:07 -070030 public:
31 bool Init();
32 unsigned int GetNumberSlots();
33 unsigned int GetCurrentSlot();
34 bool MarkBootSuccessful();
35 bool SetActiveBootSlot(unsigned int slot);
36 bool SetSlotAsUnbootable(unsigned int slot);
37 bool SetSlotBootable(unsigned int slot);
38 bool IsSlotBootable(unsigned int slot);
39 const char* GetSuffix(unsigned int slot);
40 bool IsSlotMarkedSuccessful(unsigned int slot);
David Anderson46f38e42019-08-29 15:09:22 -070041 bool SetSnapshotMergeStatus(MergeStatus status);
42 MergeStatus GetSnapshotMergeStatus();
43
44 bool IsValidSlot(unsigned int slot);
David Anderson8108e252019-08-28 15:24:07 -070045
46 const std::string& misc_device() const {
47 return misc_device_;
48 }
49
50 private:
51 // Whether this object was initialized with data from the bootloader message
52 // that doesn't change until next reboot.
53 bool initialized_ = false;
54
55 // The path to the misc_device as reported in the fstab.
56 std::string misc_device_;
57
58 // The number of slots present on the device.
59 unsigned int num_slots_ = 0;
60
61 // The slot where we are running from.
62 unsigned int current_slot_ = 0;
63};
64
65} // namespace bootable
66} // namespace android