1cee6ad93d1772be82477fe30407c768160406539Connor O'Brien// 2cee6ad93d1772be82477fe30407c768160406539Connor O'Brien// Copyright (C) 2015 The Android Open Source Project 3cee6ad93d1772be82477fe30407c768160406539Connor O'Brien// 4cee6ad93d1772be82477fe30407c768160406539Connor O'Brien// Licensed under the Apache License, Version 2.0 (the "License"); 5cee6ad93d1772be82477fe30407c768160406539Connor O'Brien// you may not use this file except in compliance with the License. 6cee6ad93d1772be82477fe30407c768160406539Connor O'Brien// You may obtain a copy of the License at 7cee6ad93d1772be82477fe30407c768160406539Connor O'Brien// 8cee6ad93d1772be82477fe30407c768160406539Connor O'Brien// http://www.apache.org/licenses/LICENSE-2.0 9cee6ad93d1772be82477fe30407c768160406539Connor O'Brien// 10cee6ad93d1772be82477fe30407c768160406539Connor O'Brien// Unless required by applicable law or agreed to in writing, software 11cee6ad93d1772be82477fe30407c768160406539Connor O'Brien// distributed under the License is distributed on an "AS IS" BASIS, 12cee6ad93d1772be82477fe30407c768160406539Connor O'Brien// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13cee6ad93d1772be82477fe30407c768160406539Connor O'Brien// See the License for the specific language governing permissions and 14cee6ad93d1772be82477fe30407c768160406539Connor O'Brien// limitations under the License. 15cee6ad93d1772be82477fe30407c768160406539Connor O'Brien// 16cee6ad93d1772be82477fe30407c768160406539Connor O'Brien 17cee6ad93d1772be82477fe30407c768160406539Connor O'Brien#ifndef UPDATE_ENGINE_BOOT_CONTROL_RECOVERY_H_ 18cee6ad93d1772be82477fe30407c768160406539Connor O'Brien#define UPDATE_ENGINE_BOOT_CONTROL_RECOVERY_H_ 19cee6ad93d1772be82477fe30407c768160406539Connor O'Brien 20cee6ad93d1772be82477fe30407c768160406539Connor O'Brien#include <string> 21cee6ad93d1772be82477fe30407c768160406539Connor O'Brien 22cee6ad93d1772be82477fe30407c768160406539Connor O'Brien#include <hardware/boot_control.h> 23cee6ad93d1772be82477fe30407c768160406539Connor O'Brien#include <hardware/hardware.h> 24cee6ad93d1772be82477fe30407c768160406539Connor O'Brien 25cee6ad93d1772be82477fe30407c768160406539Connor O'Brien#include "update_engine/common/boot_control.h" 26cee6ad93d1772be82477fe30407c768160406539Connor O'Brien 27cee6ad93d1772be82477fe30407c768160406539Connor O'Briennamespace chromeos_update_engine { 28cee6ad93d1772be82477fe30407c768160406539Connor O'Brien 29cee6ad93d1772be82477fe30407c768160406539Connor O'Brien// The Android recovery implementation of the BootControlInterface. This 30cee6ad93d1772be82477fe30407c768160406539Connor O'Brien// implementation uses the legacy libhardware's boot_control HAL to access the 31cee6ad93d1772be82477fe30407c768160406539Connor O'Brien// bootloader by linking against it statically. This should only be used in 32cee6ad93d1772be82477fe30407c768160406539Connor O'Brien// recovery. 33cee6ad93d1772be82477fe30407c768160406539Connor O'Brienclass BootControlRecovery : public BootControlInterface { 34cee6ad93d1772be82477fe30407c768160406539Connor O'Brien public: 35cee6ad93d1772be82477fe30407c768160406539Connor O'Brien BootControlRecovery() = default; 36cee6ad93d1772be82477fe30407c768160406539Connor O'Brien ~BootControlRecovery() = default; 37cee6ad93d1772be82477fe30407c768160406539Connor O'Brien 38cee6ad93d1772be82477fe30407c768160406539Connor O'Brien // Load boot_control HAL implementation using libhardware and 39cee6ad93d1772be82477fe30407c768160406539Connor O'Brien // initializes it. Returns false if an error occurred. 40cee6ad93d1772be82477fe30407c768160406539Connor O'Brien bool Init(); 41cee6ad93d1772be82477fe30407c768160406539Connor O'Brien 42cee6ad93d1772be82477fe30407c768160406539Connor O'Brien // BootControlInterface overrides. 43cee6ad93d1772be82477fe30407c768160406539Connor O'Brien unsigned int GetNumSlots() const override; 44cee6ad93d1772be82477fe30407c768160406539Connor O'Brien BootControlInterface::Slot GetCurrentSlot() const override; 45cee6ad93d1772be82477fe30407c768160406539Connor O'Brien bool GetPartitionDevice(const std::string& partition_name, 46cee6ad93d1772be82477fe30407c768160406539Connor O'Brien BootControlInterface::Slot slot, 47cee6ad93d1772be82477fe30407c768160406539Connor O'Brien std::string* device) const override; 48cee6ad93d1772be82477fe30407c768160406539Connor O'Brien bool IsSlotBootable(BootControlInterface::Slot slot) const override; 49cee6ad93d1772be82477fe30407c768160406539Connor O'Brien bool MarkSlotUnbootable(BootControlInterface::Slot slot) override; 50cee6ad93d1772be82477fe30407c768160406539Connor O'Brien bool SetActiveBootSlot(BootControlInterface::Slot slot) override; 51cee6ad93d1772be82477fe30407c768160406539Connor O'Brien bool MarkBootSuccessfulAsync(base::Callback<void(bool)> callback) override; 52cee6ad93d1772be82477fe30407c768160406539Connor O'Brien 53cee6ad93d1772be82477fe30407c768160406539Connor O'Brien private: 54cee6ad93d1772be82477fe30407c768160406539Connor O'Brien // NOTE: There is no way to release/unload HAL implementations so 55cee6ad93d1772be82477fe30407c768160406539Connor O'Brien // this is essentially leaked on object destruction. 56cee6ad93d1772be82477fe30407c768160406539Connor O'Brien boot_control_module_t* module_; 57cee6ad93d1772be82477fe30407c768160406539Connor O'Brien 58cee6ad93d1772be82477fe30407c768160406539Connor O'Brien DISALLOW_COPY_AND_ASSIGN(BootControlRecovery); 59cee6ad93d1772be82477fe30407c768160406539Connor O'Brien}; 60cee6ad93d1772be82477fe30407c768160406539Connor O'Brien 61cee6ad93d1772be82477fe30407c768160406539Connor O'Brien} // namespace chromeos_update_engine 62cee6ad93d1772be82477fe30407c768160406539Connor O'Brien 63cee6ad93d1772be82477fe30407c768160406539Connor O'Brien#endif // UPDATE_ENGINE_BOOT_CONTROL_RECOVERY_H_ 64