blob: 6582d024449ca34dec87544240486dc23657180b [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
21namespace android {
22namespace bootable {
23
24// Helper library to implement the IBootControl HAL using the misc partition.
25class BootControl {
26 public:
27 bool Init();
28 unsigned int GetNumberSlots();
29 unsigned int GetCurrentSlot();
30 bool MarkBootSuccessful();
31 bool SetActiveBootSlot(unsigned int slot);
32 bool SetSlotAsUnbootable(unsigned int slot);
33 bool SetSlotBootable(unsigned int slot);
34 bool IsSlotBootable(unsigned int slot);
35 const char* GetSuffix(unsigned int slot);
36 bool IsSlotMarkedSuccessful(unsigned int slot);
37
38 const std::string& misc_device() const {
39 return misc_device_;
40 }
41
42 private:
43 // Whether this object was initialized with data from the bootloader message
44 // that doesn't change until next reboot.
45 bool initialized_ = false;
46
47 // The path to the misc_device as reported in the fstab.
48 std::string misc_device_;
49
50 // The number of slots present on the device.
51 unsigned int num_slots_ = 0;
52
53 // The slot where we are running from.
54 unsigned int current_slot_ = 0;
55};
56
57} // namespace bootable
58} // namespace android