blob: 135d2eb56490c47b4dcaf71f7ffeebd076282256 [file] [log] [blame]
Alex Deymo763e7db2015-08-27 21:08:08 -07001//
2// Copyright (C) 2015 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#ifndef UPDATE_ENGINE_BOOT_CONTROL_INTERFACE_H_
18#define UPDATE_ENGINE_BOOT_CONTROL_INTERFACE_H_
19
20#include <climits>
21#include <string>
22
23#include <base/macros.h>
24
25namespace chromeos_update_engine {
26
27// The abstract boot control interface defines the interaction with the
28// platform's bootloader hiding vendor-specific details from the rest of
29// update_engine. This interface is used for controlling where the device should
30// boot from.
31class BootControlInterface {
32 public:
33 using Slot = unsigned int;
34
35 static const Slot kInvalidSlot = UINT_MAX;
36
37 virtual ~BootControlInterface() = default;
38
39 // Return the number of update slots in the system. A system will normally
40 // have two slots, named "A" and "B" in the documentation, but sometimes
41 // images running from other media can have only one slot, like some USB
42 // image. Systems with only one slot won't be able to update.
43 virtual unsigned int GetNumSlots() const = 0;
44
45 // Return the slot where we are running the system from. On success, the
46 // result is a number between 0 and GetNumSlots() - 1. Otherwise, log an error
47 // and return kInvalidSlot.
48 virtual Slot GetCurrentSlot() const = 0;
49
50 // Determines the block device for the given partition name and slot number.
51 // The |slot| number must be between 0 and GetNumSlots() - 1 and the
52 // |partition_name| is a platform-specific name that identifies a partition on
53 // every slot. On success, returns true and stores the block device in
54 // |device|.
55 virtual bool GetPartitionDevice(const std::string& partition_name,
56 Slot slot,
57 std::string* device) const = 0;
58
59 // Returns whether the passed |slot| is marked as bootable. Returns false if
60 // the slot is invalid.
61 virtual bool IsSlotBootable(Slot slot) const = 0;
62
63 // Mark the specified slot unbootable. No other slot flags are modified.
64 // Returns true on success.
65 virtual bool MarkSlotUnbootable(Slot slot) = 0;
66
67 // Return a human-readable slot name used for logging.
68 static std::string SlotName(Slot slot) {
69 if (slot == kInvalidSlot)
70 return "INVALID";
71 if (slot < 26)
72 return std::string(1, 'A' + slot);
73 return "TOO_BIG";
74 }
75
76 protected:
77 BootControlInterface() = default;
78
79 private:
80 DISALLOW_COPY_AND_ASSIGN(BootControlInterface);
81};
82
83} // namespace chromeos_update_engine
84
85#endif // UPDATE_ENGINE_BOOT_CONTROL_INTERFACE_H_