• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
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  */
16 #define LOG_TAG "android.hardware.boot@1.0-impl"
17 
18 #include <log/log.h>
19 
20 #include <hardware/hardware.h>
21 #include <hardware/boot_control.h>
22 #include "BootControl.h"
23 
24 namespace android {
25 namespace hardware {
26 namespace boot {
27 namespace V1_0 {
28 namespace implementation {
29 
BootControl(boot_control_module_t * module)30 BootControl::BootControl(boot_control_module_t *module) : mModule(module){
31 }
32 
33 // Methods from ::android::hardware::boot::V1_0::IBootControl follow.
getNumberSlots()34 Return<uint32_t> BootControl::getNumberSlots()  {
35     return mModule->getNumberSlots(mModule);
36 }
37 
getCurrentSlot()38 Return<uint32_t> BootControl::getCurrentSlot()  {
39     return mModule->getCurrentSlot(mModule);
40 }
41 
markBootSuccessful(markBootSuccessful_cb _hidl_cb)42 Return<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 
setActiveBootSlot(uint32_t slot,setActiveBootSlot_cb _hidl_cb)51 Return<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 
setSlotAsUnbootable(uint32_t slot,setSlotAsUnbootable_cb _hidl_cb)60 Return<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 
isSlotBootable(uint32_t slot)69 Return<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 
isSlotMarkedSuccessful(uint32_t slot)77 Return<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 
getSuffix(uint32_t slot,getSuffix_cb _hidl_cb)85 Return<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 
HIDL_FETCH_IBootControl(const char *)96 IBootControl* HIDL_FETCH_IBootControl(const char* /* hal */) {
97     int ret = 0;
98     boot_control_module_t* module = NULL;
99     hw_module_t **hwm = reinterpret_cast<hw_module_t**>(&module);
100     ret = hw_get_module(BOOT_CONTROL_HARDWARE_MODULE_ID, const_cast<const hw_module_t**>(hwm));
101     if (ret)
102     {
103         ALOGE("hw_get_module %s failed: %d", BOOT_CONTROL_HARDWARE_MODULE_ID, ret);
104         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
115