Roopesh Nataraja | 2afd1bd | 2021-07-13 15:11:37 -0700 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright (c) 2021, The Linux Foundation. All rights reserved. |
| 3 | * |
| 4 | * Redistribution and use in source and binary forms, with or without |
| 5 | * modification, are permitted provided that the following conditions are |
| 6 | * met: |
| 7 | * * Redistributions of source code must retain the above copyright |
| 8 | * notice, this list of conditions and the following disclaimer. |
| 9 | * * Redistributions in binary form must reproduce the above |
| 10 | * copyright notice, this list of conditions and the following |
| 11 | * disclaimer in the documentation and/or other materials provided |
| 12 | * with the distribution. |
| 13 | * * Neither the name of The Linux Foundation nor the names of its |
| 14 | * contributors may be used to endorse or promote products derived |
| 15 | * from this software without specific prior written permission. |
| 16 | * |
| 17 | * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED |
| 18 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF |
| 19 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT |
| 20 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS |
| 21 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 22 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 23 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR |
| 24 | * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, |
| 25 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE |
| 26 | * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN |
| 27 | * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 28 | */ |
| 29 | |
| 30 | #define LOG_TAG "android.hardware.boot@1.2-impl-qti" |
| 31 | |
| 32 | #include <memory> |
| 33 | |
| 34 | #include <log/log.h> |
| 35 | |
| 36 | #include "BootControl.h" |
| 37 | |
| 38 | namespace android { |
| 39 | namespace hardware { |
| 40 | namespace boot { |
| 41 | namespace V1_2 { |
| 42 | namespace implementation { |
| 43 | |
| 44 | using ::android::hardware::boot::V1_0::CommandResult; |
| 45 | |
| 46 | bool BootControl::Init() { |
| 47 | return bootcontrol_init(); |
| 48 | } |
| 49 | |
| 50 | // Methods from ::android::hardware::boot::V1_0::IBootControl. |
| 51 | Return<uint32_t> BootControl::getNumberSlots() { |
| 52 | return get_number_slots(); |
| 53 | } |
| 54 | |
| 55 | Return<uint32_t> BootControl::getCurrentSlot() { |
| 56 | return get_current_slot(); |
| 57 | } |
| 58 | |
| 59 | Return<void> BootControl::markBootSuccessful(markBootSuccessful_cb _hidl_cb) { |
| 60 | int ret = mark_boot_successful(); |
| 61 | struct CommandResult cr; |
| 62 | cr.success = (ret == 0); |
| 63 | cr.errMsg = strerror(-ret); |
| 64 | _hidl_cb(cr); |
| 65 | return Void(); |
| 66 | } |
| 67 | |
| 68 | Return<void> BootControl::setActiveBootSlot(uint32_t slot, setActiveBootSlot_cb _hidl_cb) { |
| 69 | int ret = set_active_boot_slot(slot); |
| 70 | struct CommandResult cr; |
| 71 | cr.success = (ret == 0); |
| 72 | cr.errMsg = strerror(-ret); |
| 73 | _hidl_cb(cr); |
| 74 | return Void(); |
| 75 | } |
| 76 | |
| 77 | Return<void> BootControl::setSlotAsUnbootable(uint32_t slot, setSlotAsUnbootable_cb _hidl_cb) { |
| 78 | int ret = set_slot_as_unbootable(slot); |
| 79 | struct CommandResult cr; |
| 80 | cr.success = (ret == 0); |
| 81 | cr.errMsg = strerror(-ret); |
| 82 | _hidl_cb(cr); |
| 83 | return Void(); |
| 84 | } |
| 85 | |
| 86 | Return<BoolResult> BootControl::isSlotBootable(uint32_t slot) { |
| 87 | int32_t ret = is_slot_bootable(slot); |
| 88 | if (ret < 0) { |
| 89 | return BoolResult::INVALID_SLOT; |
| 90 | } |
| 91 | return ret ? BoolResult::TRUE : BoolResult::FALSE; |
| 92 | } |
| 93 | |
| 94 | Return<BoolResult> BootControl::isSlotMarkedSuccessful(uint32_t slot) { |
| 95 | int32_t ret = is_slot_marked_successful(slot); |
| 96 | if (ret < 0) { |
| 97 | return BoolResult::INVALID_SLOT; |
| 98 | } |
| 99 | return ret ? BoolResult::TRUE : BoolResult::FALSE; |
| 100 | } |
| 101 | |
| 102 | Return<void> BootControl::getSuffix(uint32_t slot, getSuffix_cb _hidl_cb) { |
| 103 | hidl_string ans; |
| 104 | const char* suffix = get_suffix(slot); |
| 105 | if (suffix) { |
| 106 | ans = suffix; |
| 107 | } |
| 108 | _hidl_cb(ans); |
| 109 | return Void(); |
| 110 | } |
| 111 | |
| 112 | // Methods from ::android::hardware::boot::V1_1::IBootControl. |
| 113 | Return<bool> BootControl::setSnapshotMergeStatus(MergeStatus status) { |
| 114 | return set_snapshot_merge_status(status); |
| 115 | } |
| 116 | |
| 117 | Return<MergeStatus> BootControl::getSnapshotMergeStatus() { |
| 118 | return get_snapshot_merge_status(); |
| 119 | } |
| 120 | |
| 121 | // Methods from ::android::hardware::boot::V1_2::IBootControl. |
| 122 | Return<uint32_t> BootControl::getActiveBootSlot() { |
| 123 | int32_t ret = get_active_boot_slot(); |
| 124 | return ret < 0 ? 0 : ret; |
| 125 | } |
| 126 | |
| 127 | IBootControl* HIDL_FETCH_IBootControl(const char* /* hal */) { |
| 128 | auto module = std::make_unique<BootControl>(); |
| 129 | if (!module->Init()) { |
| 130 | ALOGE("Could not initialize BootControl module"); |
| 131 | return nullptr; |
| 132 | } |
| 133 | return module.release(); |
| 134 | } |
| 135 | |
| 136 | } // namespace implementation |
| 137 | } // namespace V1_2 |
| 138 | } // namespace boot |
| 139 | } // namespace hardware |
| 140 | } // namespace android |