From: deadman96385 Date: Tue, 24 Mar 2020 03:06:34 +0000 (-0500) Subject: Add Exynos bootctrl hal X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=f8cbf40d3f60614e0992e30a92b34186d0972ecd;p=GitHub%2Fmoto-9609%2Ftwrp_device_motorola_troika.git Add Exynos bootctrl hal https://review.lineageos.org/c/LineageOS/android_hardware_samsung/+/271378 --- diff --git a/Android.bp b/Android.bp new file mode 100644 index 0000000..3b7eec2 --- /dev/null +++ b/Android.bp @@ -0,0 +1,6 @@ +soong_namespace { +} + +subdirs = [ + "bootctrl", +] \ No newline at end of file diff --git a/bootctrl/Android.bp b/bootctrl/Android.bp new file mode 100644 index 0000000..05df943 --- /dev/null +++ b/bootctrl/Android.bp @@ -0,0 +1,32 @@ +// Copyright (C) 2020 The LineageOS Project +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +cc_library_shared { + name: "android.hardware.boot@1.0-impl.exynos", + defaults: ["hidl_defaults"], + relative_install_path: "hw", + vendor: true, + recovery_available: true, + srcs: ["BootControl.cpp"], + + shared_libs: [ + "liblog", + "libhidlbase", + "libhidltransport", + "libhardware", + "libutils", + "android.hardware.boot@1.0", + ], + +} diff --git a/bootctrl/BootControl.cpp b/bootctrl/BootControl.cpp new file mode 100644 index 0000000..2f2b8c6 --- /dev/null +++ b/bootctrl/BootControl.cpp @@ -0,0 +1,247 @@ +/* + * Copyright (C) 2020 The LineageOS Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "BootControl.h" + +#include + +namespace android { +namespace hardware { +namespace boot { +namespace V1_0 { +namespace implementation { + +bool BootControl::readMetadata(bctl_metadata_t& data) { + std::fstream in(mBlkDevice, std::ios::binary | std::ios::in); + + if (in.fail()) { + return false; + } + + in.seekg(BCTL_METADATA_OFFSET); + + if (in.fail()) { + return false; + } + + in.read(reinterpret_cast(&data), sizeof(bctl_metadata_t)); + + if (!validateMetadata(data)) + return -1; + + return !in.eof() && !in.fail(); +} + +bool BootControl::writeMetadata(bctl_metadata_t& data) { + if (!validateMetadata(data)) + return -1; + + // We use std::ios::in | std::ios::out even though we only write so that + // we don't truncate or append to the file, but rather overwrite the file + // in the exact place that we want to write the struct to. + std::fstream out(mBlkDevice, std::ios::binary | std::ios::in | std::ios::out); + + if (out.fail()) { + return false; + } + + out.seekp(BCTL_METADATA_OFFSET); + + if (out.fail()) { + return false; + } + + out.write(reinterpret_cast(&data), sizeof(bctl_metadata_t)); + + return !out.eof() && !out.fail(); +} + +bool BootControl::validateMetadata(bctl_metadata_t& data) { + if (data.slot_info[0].magic != BCTL_METADATA_MAGIC || data.slot_info[1].magic != BCTL_METADATA_MAGIC) { + return false; + } + + return true; +} + +void BootControl::resetMetadata(bctl_metadata_t& data) { + // reset to defaults + data.slot_info[0].magic = BCTL_METADATA_MAGIC; + data.slot_info[0].bootable = 1; + data.slot_info[0].is_active = 1; + data.slot_info[0].boot_successful = 0; + data.slot_info[0].tries_remaining = 7; + + data.slot_info[1].magic = BCTL_METADATA_MAGIC; + data.slot_info[1].bootable = 1; + data.slot_info[1].is_active = 0; + data.slot_info[1].boot_successful = 0; + data.slot_info[1].tries_remaining = 7; +} + +// Methods from ::android::hardware::boot::V1_0::IBootControl follow. +Return BootControl::getNumberSlots() { + return 2; +} + +Return BootControl::getCurrentSlot() { + bctl_metadata_t data; + + if (readMetadata(data)) { + // This is a clever hack because if slot b is active, + // is_active will be 0 and if slot a is active, is_active + // will be 1. In other words, the "not" value of slot A's + // is_active var lines up to the current active slot index. + return !data.slot_info[0].is_active; + } + + return 0; +} + +Return BootControl::markBootSuccessful(markBootSuccessful_cb _hidl_cb) { + bctl_metadata_t data; + bool success = false; + int active_slot; + + if (readMetadata(data)) { + active_slot = !data.slot_info[0].is_active; + + data.slot_info[active_slot].boot_successful = 0; + data.slot_info[active_slot].tries_remaining = 0; + + if (success) + if (writeMetadata(data)) { + _hidl_cb(CommandResult{true, ""}); + } else { + _hidl_cb(CommandResult{false, "Failed to write metadata"}); + } + else { + _hidl_cb(CommandResult{false, "No active slot"}); + } + } else { + _hidl_cb(CommandResult{false, "Failed to read metadata"}); + } + + return Void(); +} + +Return BootControl::setActiveBootSlot(uint32_t slot, setActiveBootSlot_cb _hidl_cb) { + bctl_metadata_t data; + int slot2 = (slot == 0) ? 1 : 0; + + if (slot < 2) { + if (readMetadata(data)) { + data.slot_info[slot].bootable = 1; + data.slot_info[slot].is_active = 1; + data.slot_info[slot].boot_successful = 0; + data.slot_info[slot].tries_remaining = 7; + + data.slot_info[slot2].bootable = 1; + data.slot_info[slot2].is_active = 0; + data.slot_info[slot2].boot_successful = 0; + data.slot_info[slot2].tries_remaining = 7; + + if (writeMetadata(data)) { + _hidl_cb(CommandResult{true, ""}); + } else { + _hidl_cb(CommandResult{false, "Failed to write metadata"}); + } + } else { + _hidl_cb(CommandResult{false, "Failed to read metadata"}); + } + } else { + _hidl_cb(CommandResult{false, "Invalid slot"}); + } + + return Void(); +} + +Return BootControl::setSlotAsUnbootable(uint32_t slot, setSlotAsUnbootable_cb _hidl_cb) { + bctl_metadata_t data; + + if (slot < 2) { + if (readMetadata(data)) { + data.slot_info[slot].bootable = 0; + + if (writeMetadata(data)) { + _hidl_cb(CommandResult{true, ""}); + } else { + _hidl_cb(CommandResult{false, "Failed to write metadata"}); + } + } else { + _hidl_cb(CommandResult{false, "Failed to read metadata"}); + } + } else { + _hidl_cb(CommandResult{false, "Invalid slot"}); + } + + return Void(); +} + +Return BootControl::isSlotBootable(uint32_t slot) { + bctl_metadata_t data; + BoolResult ret = BoolResult::FALSE; + + if (slot < 2) { + if (readMetadata(data)) { + ret = static_cast(data.slot_info[slot].bootable); + } else { + ret = BoolResult::FALSE; + } + } else { + ret = BoolResult::INVALID_SLOT; + } + + return ret; +} + +Return BootControl::isSlotMarkedSuccessful(uint32_t slot) { + bctl_metadata_t data; + BoolResult ret = BoolResult::FALSE; + + if (slot < 2) { + if (readMetadata(data)) { + ret = static_cast(data.slot_info[slot].boot_successful); + } else { + ret = BoolResult::FALSE; + } + } else { + ret = BoolResult::INVALID_SLOT; + } + + return ret; +} + +Return BootControl::getSuffix(uint32_t slot, getSuffix_cb _hidl_cb) { + if (slot < 2) { + if (slot == 0) { + _hidl_cb(SLOT_SUFFIX_A); + } else { + _hidl_cb(SLOT_SUFFIX_B); + } + } else { + // default to slot A + _hidl_cb(SLOT_SUFFIX_A); + } + + return Void(); +} + +} // namespace implementation +} // namespace V1_0 +} // namespace boot +} // namespace hardware +} // namespace android diff --git a/bootctrl/BootControl.h b/bootctrl/BootControl.h new file mode 100644 index 0000000..f5fd06a --- /dev/null +++ b/bootctrl/BootControl.h @@ -0,0 +1,62 @@ +/* + * Copyright (C) 2020 The LineageOS Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef ANDROID_HARDWARE_BOOT_V1_0_BOOTCONTROL_H +#define ANDROID_HARDWARE_BOOT_V1_0_BOOTCONTROL_H + +#include + +#include "bctl_metadata.h" + +namespace android { +namespace hardware { +namespace boot { +namespace V1_0 { +namespace implementation { + +using ::android::hardware::boot::V1_0::BoolResult; +using ::android::hardware::boot::V1_0::CommandResult; +using ::android::hardware::Return; +using ::android::hardware::Void; + +class BootControl : public IBootControl { + public: + // Methods from ::android::hardware::boot::V1_0::IBootControl follow. + Return getNumberSlots() override; + Return getCurrentSlot() override; + Return markBootSuccessful(markBootSuccessful_cb _hidl_cb) override; + Return setActiveBootSlot(uint32_t slot, setActiveBootSlot_cb _hidl_cb) override; + Return setSlotAsUnbootable(uint32_t slot, setSlotAsUnbootable_cb _hidl_cb) override; + Return isSlotBootable(uint32_t slot) override; + Return isSlotMarkedSuccessful(uint32_t slot) override; + Return getSuffix(uint32_t slot, getSuffix_cb _hidl_cb) override; + + private: + std::string mBlkDevice = BCTL_METADATA_PARTITION; + + bool readMetadata(bctl_metadata_t& data); + bool writeMetadata(bctl_metadata_t& data); + bool validateMetadata(bctl_metadata_t& data); + void resetMetadata(bctl_metadata_t& data); +}; + +} // namespace implementation +} // namespace V1_0 +} // namespace boot +} // namespace hardware +} // namespace android + +#endif // ANDROID_HARDWARE_BOOT_V1_0_BOOTCONTROL_H diff --git a/bootctrl/bctl_metadata.h b/bootctrl/bctl_metadata.h new file mode 100644 index 0000000..8145edc --- /dev/null +++ b/bootctrl/bctl_metadata.h @@ -0,0 +1,43 @@ +/* + * Copyright (C) 2020 The LineageOS Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef SAMSUNG_BCTL_METADATA_H +#define SAMSUNG_BCTL_METADATA_H + +#include + +#define BCTL_METADATA_PARTITION "/dev/block/bootdevice/by-name/slotinfo" +#define BCTL_METADATA_OFFSET 0x800 +#define BCTL_METADATA_MAGIC 0x43425845 + +#define SLOT_SUFFIX_A "_a" +#define SLOT_SUFFIX_B "_b" + +// Our internal data structures +struct slot_metadata_t { + uint32_t magic; + uint8_t bootable; + uint8_t is_active; + uint8_t boot_successful; + uint8_t tries_remaining; + uint8_t reserved[8]; +}; + +struct bctl_metadata_t { + slot_metadata_t slot_info[2]; +}; + +#endif // SAMSUNG_BCTL_METADATA_H diff --git a/device.mk b/device.mk index b2aa6a1..00329d6 100644 --- a/device.mk +++ b/device.mk @@ -31,7 +31,7 @@ PRODUCT_STATIC_BOOT_CONTROL_HAL := \ # Boot control HAL PRODUCT_PACKAGES += \ - android.hardware.boot@1.0-impl \ + android.hardware.boot@1.0-impl.exynos \ android.hardware.boot@1.0-service \ diff --git a/recovery/root/sbin/android.hidl.base@1.0.so b/recovery/root/sbin/android.hidl.base@1.0.so deleted file mode 100644 index d7a4c3c..0000000 Binary files a/recovery/root/sbin/android.hidl.base@1.0.so and /dev/null differ diff --git a/recovery/root/vendor/lib64/hw/android.hardware.boot@1.0-impl.so b/recovery/root/vendor/lib64/hw/android.hardware.boot@1.0-impl.so deleted file mode 100644 index 2d9df27..0000000 Binary files a/recovery/root/vendor/lib64/hw/android.hardware.boot@1.0-impl.so and /dev/null differ diff --git a/recovery/root/vendor/lib64/hw/bootctrl.exynos9610.so b/recovery/root/vendor/lib64/hw/bootctrl.exynos9610.so deleted file mode 100644 index 0bb6d1c..0000000 Binary files a/recovery/root/vendor/lib64/hw/bootctrl.exynos9610.so and /dev/null differ diff --git a/recovery/root/vendor/manifest.xml b/recovery/root/vendor/manifest.xml deleted file mode 100644 index 9257a38..0000000 --- a/recovery/root/vendor/manifest.xml +++ /dev/null @@ -1,379 +0,0 @@ - - - android.hardware.boot - hwbinder - - 1.0 - - IBootControl - default - - - - vendor.samsung_slsi.hardware.ofi - hwbinder - 1.0 - - IOfiService - default - - - - android.hardware.vibrator - hwbinder - 1.0 - - IVibrator - default - - - - android.hardware.wifi.supplicant - hwbinder - 1.1 - - ISupplicant - default - - - - vendor.samsung_slsi.hardware.wifi.supplicant - hwbinder - 1.0 - - ISupplicantVendor - default - - - - android.hardware.wifi - hwbinder - - 1.2 - - IWifi - default - - - - android.hardware.wifi.hostapd - hwbinder - - 1.0 - - IHostapd - default - - - - android.hardware.audio - hwbinder - 4.0 - - IDevicesFactory - default - - - - android.hardware.audio.effect - hwbinder - 4.0 - - IEffectsFactory - default - - - - android.hardware.soundtrigger - hwbinder - 2.0 - - ISoundTriggerHw - default - - - - android.hardware.media.omx - hwbinder - 1.0 - - IOmx - default - - - IOmxStore - default - - - - android.hardware.graphics.allocator - hwbinder - 2.0 - - IAllocator - default - - - - android.hardware.graphics.mapper - passthrough - 2.0 - - IMapper - default - - - - android.hardware.graphics.composer - hwbinder - 2.2 - - IComposer - default - - - - android.hardware.gatekeeper - hwbinder - - 1.0 - - IGatekeeper - default - - - - android.hardware.camera.provider - hwbinder - - 2.4 - - ICameraProvider - legacy/0 - - - - vendor.samsung_slsi.hardware.ExynosHWCServiceTW - hwbinder - 1.0 - - IExynosHWCServiceTW - default - - - - android.hardware.neuralnetworks - hwbinder - 1.1 - - IDevice - armnn - - @1.1::IDevice/armnn - - - android.hardware.memtrack - hwbinder - 1.0 - - IMemtrack - default - - - - vendor.samsung.hardware.gnss - hwbinder - 1.0 - - ISlsiGnss - default - - @1.0::ISlsiGnss/default - - - android.hardware.gnss - hwbinder - 1.1 - - IGnss - default - - - - android.hardware.keymaster - hwbinder - - 3.0 - - IKeymasterDevice - default - - - - android.hardware.renderscript - passthrough - 1.0 - - IDevice - default - - - - android.hardware.drm - hwbinder - - 1.0 - - ICryptoFactory - default - - - IDrmFactory - default - - @1.1::ICryptoFactory/clearkey - @1.1::IDrmFactory/clearkey - @1.1::ICryptoFactory/widevine - @1.1::IDrmFactory/widevine - - - android.hardware.configstore - hwbinder - 1.1 - - ISurfaceFlingerConfigs - default - - - - vendor.samsung_slsi.hardware.configstore - hwbinder - 1.0 - - IExynosHWCConfigs - default - - - - android.hardware.bluetooth - hwbinder - 1.0 - - IBluetoothHci - default - - - - android.hardware.power - hwbinder - 1.0 - - IPower - default - - - - android.hardware.thermal - hwbinder - 1.0 - - IThermal - default - - - - android.hardware.usb - hwbinder - 1.1 - - IUsb - default - - - - android.hardware.nfc - hwbinder - 1.1 - - INfc - default - - - - vendor.sec.hardware.nfc - hwbinder - 1.1 - - ISecNfc - default - - - - android.hardware.sensors - hwbinder - 1.0 - - ISensors - default - - - - 26.0 - - - android.hardware.radio - hwbinder - 1.1 - - IRadio - slot1 - slot2 - - - - android.hardware.light - hwbinder - 2.0 - - ILight - default - - - - android.hardware.health - hwbinder - 2.0 - - IHealth - default - - - - vendor.trustonic.tee.tui - hwbinder - 1.0 - - ITui - default - - - - android.hardware.cas - hwbinder - 1.0 - - IMediaCasService - default - - - - vendor.dolby.hardware.dms - hwbinder - 1.0 - - IDms - default - - - - \ No newline at end of file