micky387 | ec5db57 | 2021-06-10 19:46:35 +0200 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright (c) 2020, 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.1-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_1 { |
| 42 | namespace implementation { |
| 43 | |
| 44 | using ::android::hardware::boot::V1_0::CommandResult; |
| 45 | |
| 46 | bool BootControl::Init() { |
| 47 | return bootcontrol_init(); |
| 48 | } |
| 49 | |
| 50 | Return<uint32_t> BootControl::getNumberSlots() { |
| 51 | return get_number_slots(); |
| 52 | } |
| 53 | |
| 54 | Return<uint32_t> BootControl::getCurrentSlot() { |
| 55 | return get_current_slot(); |
| 56 | } |
| 57 | |
| 58 | Return<void> BootControl::markBootSuccessful(markBootSuccessful_cb _hidl_cb) { |
| 59 | int ret = mark_boot_successful(); |
| 60 | struct CommandResult cr; |
| 61 | cr.success = (ret == 0); |
| 62 | cr.errMsg = strerror(-ret); |
| 63 | _hidl_cb(cr); |
| 64 | return Void(); |
| 65 | } |
| 66 | |
| 67 | Return<void> BootControl::setActiveBootSlot(uint32_t slot, setActiveBootSlot_cb _hidl_cb) { |
| 68 | int ret = set_active_boot_slot(slot); |
| 69 | struct CommandResult cr; |
| 70 | cr.success = (ret == 0); |
| 71 | cr.errMsg = strerror(-ret); |
| 72 | _hidl_cb(cr); |
| 73 | return Void(); |
| 74 | } |
| 75 | |
| 76 | Return<void> BootControl::setSlotAsUnbootable(uint32_t slot, setSlotAsUnbootable_cb _hidl_cb) { |
| 77 | int ret = set_slot_as_unbootable(slot); |
| 78 | struct CommandResult cr; |
| 79 | cr.success = (ret == 0); |
| 80 | cr.errMsg = strerror(-ret); |
| 81 | _hidl_cb(cr); |
| 82 | return Void(); |
| 83 | } |
| 84 | |
| 85 | Return<BoolResult> BootControl::isSlotBootable(uint32_t slot) { |
| 86 | int32_t ret = is_slot_bootable(slot); |
| 87 | if (ret < 0) { |
| 88 | return BoolResult::INVALID_SLOT; |
| 89 | } |
| 90 | return ret ? BoolResult::TRUE : BoolResult::FALSE; |
| 91 | } |
| 92 | |
| 93 | Return<BoolResult> BootControl::isSlotMarkedSuccessful(uint32_t slot) { |
| 94 | int32_t ret = is_slot_marked_successful(slot); |
| 95 | if (ret < 0) { |
| 96 | return BoolResult::INVALID_SLOT; |
| 97 | } |
| 98 | return ret ? BoolResult::TRUE : BoolResult::FALSE; |
| 99 | } |
| 100 | |
| 101 | Return<void> BootControl::getSuffix(uint32_t slot, getSuffix_cb _hidl_cb) { |
| 102 | hidl_string ans; |
| 103 | const char* suffix = get_suffix(slot); |
| 104 | if (suffix) { |
| 105 | ans = suffix; |
| 106 | } |
| 107 | _hidl_cb(ans); |
| 108 | return Void(); |
| 109 | } |
| 110 | |
| 111 | Return<bool> BootControl::setSnapshotMergeStatus(MergeStatus status) { |
| 112 | return set_snapshot_merge_status(status); |
| 113 | } |
| 114 | |
| 115 | Return<MergeStatus> BootControl::getSnapshotMergeStatus() { |
| 116 | return get_snapshot_merge_status(); |
| 117 | } |
| 118 | |
| 119 | IBootControl* HIDL_FETCH_IBootControl(const char* /* hal */) { |
| 120 | auto module = std::make_unique<BootControl>(); |
| 121 | if (!module->Init()) { |
| 122 | ALOGE("Could not initialize BootControl module"); |
| 123 | return nullptr; |
| 124 | } |
| 125 | return module.release(); |
| 126 | } |
| 127 | |
| 128 | } // namespace implementation |
| 129 | } // namespace V1_1 |
| 130 | } // namespace boot |
| 131 | } // namespace hardware |
| 132 | } // namespace android |