blob: 9a900767d70331b0cc8ade416ce33733897d9698 [file] [log] [blame]
Steven Moreland9f8b5c72016-11-29 15:03:38 -08001/*
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 */
Connor O'Brien74f82922016-10-10 12:31:37 -070016#define LOG_TAG "android.hardware.boot@1.0-impl"
Mark Salyzyna4842ac2017-01-10 10:16:48 -080017
18#include <log/log.h>
Connor O'Brien74f82922016-10-10 12:31:37 -070019
20#include <hardware/hardware.h>
21#include <hardware/boot_control.h>
22#include "BootControl.h"
23
24namespace android {
25namespace hardware {
26namespace boot {
27namespace V1_0 {
28namespace implementation {
29
30BootControl::BootControl(boot_control_module_t *module) : mModule(module){
31}
32
33// Methods from ::android::hardware::boot::V1_0::IBootControl follow.
34Return<uint32_t> BootControl::getNumberSlots() {
35 return mModule->getNumberSlots(mModule);
36}
37
38Return<uint32_t> BootControl::getCurrentSlot() {
39 return mModule->getCurrentSlot(mModule);
40}
41
42Return<void> BootControl::markBootSuccessful(markBootSuccessful_cb _hidl_cb) {
43 int ret = mModule->markBootSuccessful(mModule);
44 struct CommandResult cr;
45 cr.success = (ret == 0);
46 cr.errMsg = strerror(-ret);
47 _hidl_cb(cr);
48 return Void();
49}
50
51Return<void> BootControl::setActiveBootSlot(uint32_t slot, setActiveBootSlot_cb _hidl_cb) {
52 int ret = mModule->setActiveBootSlot(mModule, slot);
53 struct CommandResult cr;
54 cr.success = (ret == 0);
55 cr.errMsg = strerror(-ret);
56 _hidl_cb(cr);
57 return Void();
58}
59
60Return<void> BootControl::setSlotAsUnbootable(uint32_t slot, setSlotAsUnbootable_cb _hidl_cb) {
61 int ret = mModule->setSlotAsUnbootable(mModule, slot);
62 struct CommandResult cr;
63 cr.success = (ret == 0);
64 cr.errMsg = strerror(-ret);
65 _hidl_cb(cr);
66 return Void();
67}
68
69Return<BoolResult> BootControl::isSlotBootable(uint32_t slot) {
70 int32_t ret = mModule->isSlotBootable(mModule, slot);
71 if (ret < 0) {
72 return BoolResult::INVALID_SLOT;
73 }
74 return ret ? BoolResult::TRUE : BoolResult::FALSE;
75}
76
77Return<BoolResult> BootControl::isSlotMarkedSuccessful(uint32_t slot) {
78 int32_t ret = mModule->isSlotMarkedSuccessful(mModule, slot);
79 if (ret < 0) {
80 return BoolResult::INVALID_SLOT;
81 }
82 return ret ? BoolResult::TRUE : BoolResult::FALSE;
83}
84
85Return<void> BootControl::getSuffix(uint32_t slot, getSuffix_cb _hidl_cb) {
86 hidl_string ans;
87 const char *suffix = mModule->getSuffix(mModule, slot);
88 if (suffix) {
89 ans = suffix;
90 }
91 _hidl_cb(ans);
92 return Void();
93}
94
95
Chris Phoenixa79b3b62017-01-20 13:46:36 -080096IBootControl* HIDL_FETCH_IBootControl(const char* /* hal */) {
Connor O'Brien74f82922016-10-10 12:31:37 -070097 int ret = 0;
98 boot_control_module_t* module = NULL;
99 hw_module_t **hwm = reinterpret_cast<hw_module_t**>(&module);
Chris Phoenixa79b3b62017-01-20 13:46:36 -0800100 ret = hw_get_module(BOOT_CONTROL_HARDWARE_MODULE_ID, const_cast<const hw_module_t**>(hwm));
Connor O'Brien74f82922016-10-10 12:31:37 -0700101 if (ret)
102 {
Chris Phoenixa79b3b62017-01-20 13:46:36 -0800103 ALOGE("hw_get_module %s failed: %d", BOOT_CONTROL_HARDWARE_MODULE_ID, ret);
Connor O'Brien74f82922016-10-10 12:31:37 -0700104 return nullptr;
105 }
106 module->init(module);
107 return new BootControl(module);
108}
109
110} // namespace implementation
111} // namespace V1_0
112} // namespace boot
113} // namespace hardware
114} // namespace android