blob: 1287c8e6a79eed9333e4d8611cc22df548484fe3 [file] [log] [blame]
David Anderson9c1020d2019-09-16 13:53:47 -07001/*
2 * Copyright (C) 2016 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 */
David Andersonb93d6702019-09-16 17:20:03 -070016#define LOG_TAG "android.hardware.boot@1.1-impl"
David Anderson9c1020d2019-09-16 13:53:47 -070017
18#include <log/log.h>
19
20#include <hardware/boot_control.h>
21#include <hardware/hardware.h>
22#include "LegacyBootControl.h"
23
24#ifdef BOOT_CONTROL_RECOVERY
25extern const hw_module_t HAL_MODULE_INFO_SYM;
26#endif
27
28namespace android {
29namespace hardware {
30namespace boot {
Tianjie253b46d2020-11-30 14:38:35 -080031namespace V1_2 {
David Anderson9c1020d2019-09-16 13:53:47 -070032namespace implementation {
33
David Andersonb93d6702019-09-16 17:20:03 -070034using ::android::hardware::boot::V1_0::CommandResult;
35
David Anderson9c1020d2019-09-16 13:53:47 -070036BootControl::BootControl(boot_control_module_t *module) : mModule(module) {}
37
38// Methods from ::android::hardware::boot::V1_0::IBootControl follow.
39Return<uint32_t> BootControl::getNumberSlots() {
40 return mModule->getNumberSlots(mModule);
41}
42
43Return<uint32_t> BootControl::getCurrentSlot() {
44 return mModule->getCurrentSlot(mModule);
45}
46
47Return<void> BootControl::markBootSuccessful(markBootSuccessful_cb _hidl_cb) {
48 int ret = mModule->markBootSuccessful(mModule);
49 struct CommandResult cr;
50 cr.success = (ret == 0);
51 cr.errMsg = strerror(-ret);
52 _hidl_cb(cr);
53 return Void();
54}
55
56Return<void> BootControl::setActiveBootSlot(uint32_t slot, setActiveBootSlot_cb _hidl_cb) {
57 int ret = mModule->setActiveBootSlot(mModule, slot);
58 struct CommandResult cr;
59 cr.success = (ret == 0);
60 cr.errMsg = strerror(-ret);
61 _hidl_cb(cr);
62 return Void();
63}
64
65Return<void> BootControl::setSlotAsUnbootable(uint32_t slot, setSlotAsUnbootable_cb _hidl_cb) {
66 int ret = mModule->setSlotAsUnbootable(mModule, slot);
67 struct CommandResult cr;
68 cr.success = (ret == 0);
69 cr.errMsg = strerror(-ret);
70 _hidl_cb(cr);
71 return Void();
72}
73
74Return<BoolResult> BootControl::isSlotBootable(uint32_t slot) {
75 int32_t ret = mModule->isSlotBootable(mModule, slot);
76 if (ret < 0) {
77 return BoolResult::INVALID_SLOT;
78 }
79 return ret ? BoolResult::TRUE : BoolResult::FALSE;
80}
81
82Return<BoolResult> BootControl::isSlotMarkedSuccessful(uint32_t slot) {
83 int32_t ret = mModule->isSlotMarkedSuccessful(mModule, slot);
84 if (ret < 0) {
85 return BoolResult::INVALID_SLOT;
86 }
87 return ret ? BoolResult::TRUE : BoolResult::FALSE;
88}
89
90Return<void> BootControl::getSuffix(uint32_t slot, getSuffix_cb _hidl_cb) {
91 hidl_string ans;
92 const char *suffix = mModule->getSuffix(mModule, slot);
93 if (suffix) {
94 ans = suffix;
95 }
96 _hidl_cb(ans);
97 return Void();
98}
99
Tianjie253b46d2020-11-30 14:38:35 -0800100// Methods from ::android::hardware::boot::V1_2::IBootControl follow.
101Return<uint32_t> BootControl::getActiveBootSlot() {
102 auto get_active_slot = mModule->getActiveBootSlot;
103 if (!get_active_slot) {
104 ALOGE("Failed to find the implementation of getActiveBootSlot in boot"
105 " control HAL.");
106 return 0;
107 }
108 return get_active_slot(mModule);
109}
110
David Anderson9c1020d2019-09-16 13:53:47 -0700111IBootControl *HIDL_FETCH_IBootControl(const char * /* hal */) {
112 int ret = 0;
113 boot_control_module_t *module = NULL;
114 hw_module_t **hwm = reinterpret_cast<hw_module_t **>(&module);
115 ret = hw_get_module(BOOT_CONTROL_HARDWARE_MODULE_ID, const_cast<const hw_module_t **>(hwm));
116 if (ret) {
117 ALOGE("hw_get_module %s failed: %d", BOOT_CONTROL_HARDWARE_MODULE_ID, ret);
118 return nullptr;
119 }
120 module->init(module);
David Anderson953ea5d2019-10-30 13:07:33 -0700121
122 auto hal = new BootControl(module);
123 if (!hal->Init()) {
124 ALOGE("Failed to initialize boot control HAL");
125 }
126 return hal;
David Anderson9c1020d2019-09-16 13:53:47 -0700127}
David Anderson953ea5d2019-10-30 13:07:33 -0700128
David Anderson9c1020d2019-09-16 13:53:47 -0700129} // namespace implementation
Tianjie253b46d2020-11-30 14:38:35 -0800130} // namespace V1_2
David Anderson9c1020d2019-09-16 13:53:47 -0700131} // namespace boot
132} // namespace hardware
133} // namespace android