summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJason Chiu <jasoncschiu@google.com>2023-11-09 21:20:42 +0800
committerTreehugger Robot <android-test-infra-autosubmit@system.gserviceaccount.com>2023-12-05 02:30:54 +0000
commitfcab3aa32fbfded0e76b60fabd0316afae2e2cd0 (patch)
tree6c1a2e25eb8fbe548cf647679d8e0bb9b4c440e4
parentc41e6f519bc79da4a1578a88a68f17d604660a3b (diff)
downloadgs201-fcab3aa32fbfded0e76b60fabd0316afae2e2cd0.tar.gz
gs201: move bootctrl hal to gs-common
Bug: 265063384 Change-Id: I11d07835c2785bdcc2a373befc1109bc12e4d11f Signed-off-by: Jason Chiu <jasoncschiu@google.com>
-rw-r--r--interfaces/boot/1.0/Android.bp66
-rw-r--r--interfaces/boot/1.0/BootControl.cpp272
-rw-r--r--interfaces/boot/1.0/BootControl.h59
-rw-r--r--interfaces/boot/1.0/GptUtils.cpp199
-rw-r--r--interfaces/boot/1.0/GptUtils.h79
-rw-r--r--interfaces/boot/1.0/android.hardware.boot@1.0-service-gs201.rc4
-rw-r--r--interfaces/boot/1.0/service.cpp47
-rw-r--r--interfaces/boot/1.2/Android.bp81
-rw-r--r--interfaces/boot/1.2/BootControl.cpp420
-rw-r--r--interfaces/boot/1.2/BootControl.h69
-rw-r--r--interfaces/boot/1.2/DevInfo.h61
-rw-r--r--interfaces/boot/1.2/GptUtils.cpp193
-rw-r--r--interfaces/boot/1.2/GptUtils.h79
-rw-r--r--interfaces/boot/1.2/android.hardware.boot@1.2-service-gs201.rc7
-rw-r--r--interfaces/boot/1.2/service.cpp50
15 files changed, 0 insertions, 1686 deletions
diff --git a/interfaces/boot/1.0/Android.bp b/interfaces/boot/1.0/Android.bp
deleted file mode 100644
index a5937e7..0000000
--- a/interfaces/boot/1.0/Android.bp
+++ /dev/null
@@ -1,66 +0,0 @@
-//
-// Copyright (C) 2019 The Android Open Source 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.
-
-package {
- // See: http://go/android-license-faq
- // A large-scale-change added 'default_applicable_licenses' to import
- // all of the 'license_kinds' from "//device/google/gs201:device_google_gs201_license"
- // to get the below license kinds:
- // SPDX-license-identifier-Apache-2.0
- default_applicable_licenses: [
- "//device/google/gs201:device_google_gs201_license",
- ],
-}
-
-cc_binary {
- name: "android.hardware.boot@1.0-service-gs201",
- defaults: ["hidl_defaults"],
- relative_install_path: "hw",
- vendor: true,
- init_rc: ["android.hardware.boot@1.0-service-gs201.rc"],
- srcs: [
- "BootControl.cpp",
- "GptUtils.cpp",
- "service.cpp"
- ],
- shared_libs: [
- "libbase",
- "liblog",
- "libhidlbase",
- "libutils",
- "libcutils",
- "libz",
- "android.hardware.boot@1.0",
- ],
-}
-
-cc_library {
- name: "android.hardware.boot@1.0-impl-gs201",
- recovery: true,
- srcs: [
- "BootControl.cpp",
- "GptUtils.cpp",
- ],
- relative_install_path: "hw",
- shared_libs: [
- "libbase",
- "liblog",
- "libhidlbase",
- "libutils",
- "libcutils",
- "libz",
- "android.hardware.boot@1.0",
- ],
-}
diff --git a/interfaces/boot/1.0/BootControl.cpp b/interfaces/boot/1.0/BootControl.cpp
deleted file mode 100644
index 1f155c9..0000000
--- a/interfaces/boot/1.0/BootControl.cpp
+++ /dev/null
@@ -1,272 +0,0 @@
-/*
- * Copyright (C) 2019 The Android Open Source 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.
- */
-
-#define LOG_TAG "bootcontrolhal"
-
-#include "BootControl.h"
-#include "GptUtils.h"
-
-#include <android-base/file.h>
-#include <cutils/properties.h>
-#include <log/log.h>
-
-namespace android {
-namespace hardware {
-namespace boot {
-namespace V1_0 {
-namespace implementation {
-
-namespace {
-
-#define BOOT_A_PATH "/dev/block/by-name/boot_a"
-#define BOOT_B_PATH "/dev/block/by-name/boot_b"
-
-// slot flags
-#define AB_ATTR_PRIORITY_SHIFT 52
-#define AB_ATTR_PRIORITY_MASK (3UL << AB_ATTR_PRIORITY_SHIFT)
-#define AB_ATTR_ACTIVE_SHIFT 54
-#define AB_ATTR_ACTIVE (1UL << AB_ATTR_ACTIVE_SHIFT)
-#define AB_ATTR_RETRY_COUNT_SHIFT (55)
-#define AB_ATTR_RETRY_COUNT_MASK (7UL << AB_ATTR_RETRY_COUNT_SHIFT)
-#define AB_ATTR_SUCCESSFUL (1UL << 58)
-#define AB_ATTR_UNBOOTABLE (1UL << 59)
-
-#define AB_ATTR_MAX_PRIORITY 3UL
-#define AB_ATTR_MAX_RETRY_COUNT 3UL
-
-static std::string getDevPath(uint32_t slot) {
- char real_path[PATH_MAX];
-
- const char *path = slot == 0 ? BOOT_A_PATH : BOOT_B_PATH;
-
- int ret = readlink(path, real_path, sizeof real_path);
- if (ret < 0) {
- ALOGE("readlink failed for boot device %s\n", strerror(errno));
- return std::string();
- }
-
- std::string dp(real_path);
- // extract /dev/sda.. part
- return dp.substr(0, sizeof "/dev/block/sdX" - 1);
-}
-
-static bool isSlotFlagSet(uint32_t slot, uint64_t flag) {
- std::string dev_path = getDevPath(slot);
- if (dev_path.empty()) {
- ALOGI("Could not get device path for slot %d\n", slot);
- return false;
- }
-
- GptUtils gpt(dev_path);
- if (gpt.Load()) {
- ALOGI("failed to load gpt data\n");
- return false;
- }
-
- gpt_entry *e = gpt.GetPartitionEntry(slot ? "boot_b" : "boot_a");
- if (e == nullptr) {
- ALOGI("failed to get gpt entry\n");
- return false;
- }
-
- return !!(e->attr & flag);
-}
-
-static int setSlotFlag(uint32_t slot, uint64_t flag) {
- std::string dev_path = getDevPath(slot);
- if (dev_path.empty()) {
- ALOGI("Could not get device path for slot %d\n", slot);
- return -1;
- }
-
- GptUtils gpt(dev_path);
- if (gpt.Load()) {
- ALOGI("failed to load gpt data\n");
- return -1;
- }
-
- gpt_entry *e = gpt.GetPartitionEntry(slot ? "boot_b" : "boot_a");
- if (e == nullptr) {
- ALOGI("failed to get gpt entry\n");
- return -1;
- }
-
- e->attr |= flag;
- gpt.Sync();
-
- return 0;
-}
-
-}
-
-// Methods from ::android::hardware::boot::V1_0::IBootControl follow.
-Return<uint32_t> BootControl::getNumberSlots() {
- uint32_t slots = 0;
-
- if (access(BOOT_A_PATH, F_OK) == 0)
- slots++;
-
- if (access(BOOT_B_PATH, F_OK) == 0)
- slots++;
-
- return slots;
-}
-
-Return<uint32_t> BootControl::getCurrentSlot() {
- char suffix[PROPERTY_VALUE_MAX];
- property_get("ro.boot.slot_suffix", suffix, "_a");
- return std::string(suffix) == "_b" ? 1 : 0;
-}
-
-Return<void> BootControl::markBootSuccessful(markBootSuccessful_cb _hidl_cb) {
- if (getNumberSlots() == 0) {
- // no slots, just return true otherwise Android keeps trying
- _hidl_cb({true, ""});
- return Void();
- }
- int ret = setSlotFlag(getCurrentSlot(), AB_ATTR_SUCCESSFUL);
- ret ? _hidl_cb({false, "Failed to set successfull flag"}) : _hidl_cb({true, ""});
- return Void();
-}
-
-Return<void> BootControl::setActiveBootSlot(uint32_t slot, setActiveBootSlot_cb _hidl_cb) {
- if (slot >= 2) {
- _hidl_cb({false, "Invalid slot"});
- return Void();
- }
-
- std::string dev_path = getDevPath(slot);
- if (dev_path.empty()) {
- _hidl_cb({false, "Could not get device path for slot"});
- return Void();
- }
-
- GptUtils gpt(dev_path);
- if (gpt.Load()) {
- _hidl_cb({false, "failed to load gpt data"});
- return Void();
- }
-
- gpt_entry *active_entry = gpt.GetPartitionEntry(slot == 0 ? "boot_a" : "boot_b");
- gpt_entry *inactive_entry = gpt.GetPartitionEntry(slot == 0 ? "boot_b" : "boot_a");
- if (active_entry == nullptr || inactive_entry == nullptr) {
- _hidl_cb({false, "failed to get entries for boot partitions"});
- return Void();
- }
-
- ALOGV("slot active attributes %lx\n", active_entry->attr);
- ALOGV("slot inactive attributes %lx\n", inactive_entry->attr);
-
- char boot_dev[PROPERTY_VALUE_MAX];
- property_get("ro.boot.bootdevice", boot_dev, "");
- if (boot_dev[0] == '\0') {
- _hidl_cb({false, "invalid ro.boot.bootdevice prop"});
- return Void();
- }
-
- std::string boot_lun_path = std::string("/sys/devices/platform/") +
- boot_dev + "/pixel/boot_lun_enabled";
- int fd = open(boot_lun_path.c_str(), O_RDWR);
- if (fd < 0) {
- // Try old path for kernels < 5.4
- // TODO: remove once kernel 4.19 support is deprecated
- std::string boot_lun_path = std::string("/sys/devices/platform/") +
- boot_dev + "/attributes/boot_lun_enabled";
- fd = open(boot_lun_path.c_str(), O_RDWR);
- if (fd < 0) {
- _hidl_cb({false, "failed to open ufs attr boot_lun_enabled"});
- return Void();
- }
- }
-
- // update attributes for active and inactive
- inactive_entry->attr &= ~AB_ATTR_ACTIVE;
- active_entry->attr = AB_ATTR_ACTIVE | (AB_ATTR_MAX_PRIORITY << AB_ATTR_PRIORITY_SHIFT) |
- (AB_ATTR_MAX_RETRY_COUNT << AB_ATTR_RETRY_COUNT_SHIFT);
-
- //
- // bBootLunEn
- // 0x1 => Boot LU A = enabled, Boot LU B = disable
- // 0x2 => Boot LU A = disable, Boot LU B = enabled
- //
- int ret = android::base::WriteStringToFd(slot == 0 ? "1" : "2", fd);
- close(fd);
- if (ret < 0) {
- _hidl_cb({false, "faied to write boot_lun_enabled attribute"});
- return Void();
- }
-
- _hidl_cb({true, ""});
- return Void();
-}
-
-Return<void> BootControl::setSlotAsUnbootable(uint32_t slot, setSlotAsUnbootable_cb _hidl_cb) {
- if (slot >= 2) {
- _hidl_cb({false, "Invalid slot"});
- return Void();
- }
-
- std::string dev_path = getDevPath(slot);
- if (dev_path.empty()) {
- _hidl_cb({false, "Could not get device path for slot"});
- return Void();
- }
-
- GptUtils gpt(dev_path);
- gpt.Load();
-
- gpt_entry *e = gpt.GetPartitionEntry(slot ? "boot_b" : "boot_a");
- e->attr |= AB_ATTR_UNBOOTABLE;
-
- gpt.Sync();
-
- _hidl_cb({true, ""});
- return Void();
-}
-
-Return<::android::hardware::boot::V1_0::BoolResult> BootControl::isSlotBootable(uint32_t slot) {
- if (getNumberSlots() == 0)
- return BoolResult::FALSE;
- if (slot >= getNumberSlots())
- return BoolResult::INVALID_SLOT;
- return isSlotFlagSet(slot, AB_ATTR_UNBOOTABLE) ? BoolResult::FALSE : BoolResult::TRUE;
-}
-
-Return<::android::hardware::boot::V1_0::BoolResult> BootControl::isSlotMarkedSuccessful(uint32_t slot) {
- if (getNumberSlots() == 0) {
- // just return true so that we don't we another call trying to mark it as successful
- // when there is no slots
- return BoolResult::TRUE;
- }
- if (slot >= getNumberSlots())
- return BoolResult::INVALID_SLOT;
- return isSlotFlagSet(slot, AB_ATTR_SUCCESSFUL) ? BoolResult::TRUE : BoolResult::FALSE;
-}
-
-Return<void> BootControl::getSuffix(uint32_t slot, getSuffix_cb _hidl_cb) {
- _hidl_cb(slot == 0 ? "_a" : slot == 1 ? "_b" : "");
- return Void();
-}
-
-extern "C" IBootControl* HIDL_FETCH_IBootControl(const char*) {
- return new BootControl();
-}
-
-} // namespace implementation
-} // namespace V1_0
-} // namespace boot
-} // namespace hardware
-} // namespace android
diff --git a/interfaces/boot/1.0/BootControl.h b/interfaces/boot/1.0/BootControl.h
deleted file mode 100644
index eb81cb0..0000000
--- a/interfaces/boot/1.0/BootControl.h
+++ /dev/null
@@ -1,59 +0,0 @@
-/*
- * Copyright (C) 2019 The Android Open Source 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.
- */
-
-#pragma once
-
-#include <android/hardware/boot/1.0/IBootControl.h>
-#include <hidl/MQDescriptor.h>
-#include <hidl/Status.h>
-
-namespace android {
-namespace hardware {
-namespace boot {
-namespace V1_0 {
-namespace implementation {
-
-using ::android::hardware::hidl_array;
-using ::android::hardware::hidl_memory;
-using ::android::hardware::hidl_string;
-using ::android::hardware::hidl_vec;
-using ::android::hardware::Return;
-using ::android::hardware::Void;
-using ::android::sp;
-
-struct BootControl : public IBootControl {
- // Methods from ::android::hardware::boot::V1_0::IBootControl follow.
- Return<uint32_t> getNumberSlots() override;
- Return<uint32_t> getCurrentSlot() override;
- Return<void> markBootSuccessful(markBootSuccessful_cb _hidl_cb) override;
- Return<void> setActiveBootSlot(uint32_t slot, setActiveBootSlot_cb _hidl_cb) override;
- Return<void> setSlotAsUnbootable(uint32_t slot, setSlotAsUnbootable_cb _hidl_cb) override;
- Return<::android::hardware::boot::V1_0::BoolResult> isSlotBootable(uint32_t slot) override;
- Return<::android::hardware::boot::V1_0::BoolResult> isSlotMarkedSuccessful(uint32_t slot) override;
- Return<void> getSuffix(uint32_t slot, getSuffix_cb _hidl_cb) override;
-
- // Methods from ::android::hidl::base::V1_0::IBase follow.
-
-};
-
-// FIXME: most likely delete, this is only for passthrough implementations
-extern "C" IBootControl* HIDL_FETCH_IBootControl(const char* name);
-
-} // namespace implementation
-} // namespace V1_0
-} // namespace boot
-} // namespace hardware
-} // namespace android
diff --git a/interfaces/boot/1.0/GptUtils.cpp b/interfaces/boot/1.0/GptUtils.cpp
deleted file mode 100644
index f893617..0000000
--- a/interfaces/boot/1.0/GptUtils.cpp
+++ /dev/null
@@ -1,199 +0,0 @@
-/*
- * Copyright (C) 2019 The Android Open Source 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.
- */
-
-#define LOG_TAG "bootcontrolhal"
-
-#include "GptUtils.h"
-
-#include <errno.h>
-#include <log/log.h>
-#include <android-base/file.h>
-#include <linux/fs.h>
-#include <zlib.h>
-
-namespace android {
-namespace hardware {
-namespace boot {
-namespace V1_0 {
-namespace implementation {
-
-namespace {
-
-static int ValidateGptHeader(gpt_header *gpt)
-{
- if (gpt->signature != GPT_SIGNATURE) {
- ALOGE("invalid gpt signature 0x%lx\n", gpt->signature);
- return -1;
- }
-
- if (gpt->header_size != sizeof(gpt_header)) {
- ALOGE("invalid gpt header size %u\n", gpt->header_size);
- return -1;
- }
-
- if (gpt->entry_size != sizeof(gpt_entry)) {
- ALOGE("invalid gpt entry size %u\n", gpt->entry_size);
- return -1;
- }
-
- return 0;
-}
-
-}
-
-GptUtils::GptUtils(const std::string dev_path) : dev_path(dev_path), fd(0) {}
-
-int GptUtils::Load(void)
-{
- fd = open(dev_path.c_str(), O_RDWR);
- if (fd < 0) {
- ALOGE("failed to open block dev %s, %d\n", dev_path.c_str(), errno);
- return -1;
- }
-
- int ret = ioctl(fd, BLKSSZGET, &block_size);
- if (ret < 0) {
- ALOGE("failed to get block size %d\n", errno);
- return -1;
- }
-
- // read primary header
- lseek64(fd, block_size, SEEK_SET);
- ret = read(fd, &gpt_primary, sizeof gpt_primary);
- if (ret < 0) {
- ALOGE("failed to read gpt primary header %d\n", errno);
- return -1;
- }
-
- if (ValidateGptHeader(&gpt_primary)) {
- ALOGE("error validating gpt header\n");
- return -1;
- }
-
- // read partition entries
- entry_array.resize(gpt_primary.entry_count);
- uint32_t entries_size = gpt_primary.entry_size * gpt_primary.entry_count;
- lseek64(fd, block_size * gpt_primary.start_lba, SEEK_SET);
- ret = read(fd, entry_array.data(), entries_size);
- if (ret < 0) {
- ALOGE("failed to read gpt partition entries %d\n", errno);
- return -1;
- }
-
- // read gpt back header
- lseek64(fd, block_size * gpt_primary.backup_lba, SEEK_SET);
- ret = read(fd, &gpt_backup, sizeof gpt_backup);
- if (ret < 0) {
- ALOGE("failed to read gpt backup header %d\n", errno);
- return -1;
- }
-
- if (ValidateGptHeader(&gpt_backup)) {
- ALOGW("error validating gpt backup\n"); // just warn about it, not fail
- }
-
- // Create map <partition name, gpt_entry pointer>
- auto get_name = [](const uint16_t *efi_name) {
- char name[37] = {};
- for (int i = 0; efi_name[i] && i < sizeof name - 1; ++i)
- name[i] = efi_name[i];
- return std::string(name);
- };
-
- for (auto const &e: entry_array) {
- if (e.name[0] == 0)
- break; // stop at the first partition with no name
- std::string s = get_name(e.name);
- entries[s] = const_cast<gpt_entry *>(&e);
- }
-
- return 0;
-}
-
-gpt_entry *GptUtils::GetPartitionEntry(std::string name)
-{
- return entries.find(name) != entries.end() ? entries[name] : nullptr;
-}
-
-int GptUtils::Sync(void)
-{
- if (!fd)
- return -1;
-
- // calculate crc and check if we need to update gpt
- gpt_primary.entries_crc32 = crc32(0, reinterpret_cast<uint8_t *>(entry_array.data()),
- entry_array.size() * sizeof(gpt_entry));
-
- // save old crc
- uint32_t crc = gpt_primary.crc32;
- gpt_primary.crc32 = 0;
-
- gpt_primary.crc32 = crc32(0, reinterpret_cast<uint8_t *>(&gpt_primary), sizeof gpt_primary);
- if (crc == gpt_primary.crc32)
- return 0; // nothing to do (no changes)
-
- ALOGI("updating GPT\n");
-
- lseek64(fd, block_size * gpt_primary.current_lba, SEEK_SET);
- int ret = write(fd, &gpt_primary, sizeof gpt_primary);
- if (ret < 0) {
- ALOGE("failed to write gpt primary header %d\n", errno);
- return -1;
- }
-
- lseek64(fd, block_size * gpt_primary.start_lba, SEEK_SET);
- ret = write(fd, entry_array.data(), entry_array.size() * sizeof(gpt_entry));
- if (ret < 0) {
- ALOGE("failed to write gpt partition entries %d\n", errno);
- return -1;
- }
-
- //update GPT backup entries and backup
- lseek64(fd, block_size * gpt_backup.start_lba, SEEK_SET);
- ret = write(fd, entry_array.data(), entry_array.size() * sizeof(gpt_entry));
- if (ret < 0) {
- ALOGE("failed to write gpt backup partition entries %d\n", errno);
- return -1;
- }
-
- gpt_backup.entries_crc32 = gpt_primary.entries_crc32;
- gpt_backup.crc32 = 0;
- gpt_backup.crc32 = crc32(0, reinterpret_cast<uint8_t *>(&gpt_backup), sizeof gpt_backup);
- lseek64(fd, block_size * gpt_primary.backup_lba, SEEK_SET);
- ret = write(fd, &gpt_backup, sizeof gpt_backup);
- if (ret < 0) {
- ALOGE("failed to write gpt backup header %d\n", errno);
- return -1;
- }
-
- fsync(fd);
-
- return 0;
-}
-
-GptUtils::~GptUtils()
-{
- if (fd) {
- Sync();
- close(fd);
- }
-}
-
-} // namespace implementation
-} // namespace V1_0
-} // namespace boot
-} // namespace hardware
-} // namespace android
diff --git a/interfaces/boot/1.0/GptUtils.h b/interfaces/boot/1.0/GptUtils.h
deleted file mode 100644
index d969d9d..0000000
--- a/interfaces/boot/1.0/GptUtils.h
+++ /dev/null
@@ -1,79 +0,0 @@
-/*
- * Copyright (C) 2019 The Android Open Source 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.
- */
-
-#pragma once
-
-#include <string>
-#include <vector>
-#include <map>
-
-namespace android {
-namespace hardware {
-namespace boot {
-namespace V1_0 {
-namespace implementation {
-
-#define GPT_SIGNATURE 0x5452415020494645UL
-
-typedef struct {
- uint8_t type_guid[16];
- uint8_t guid[16];
- uint64_t first_lba;
- uint64_t last_lba;
- uint64_t attr;
- uint16_t name[36];
-} __attribute__((packed)) gpt_entry;
-
-typedef struct {
- uint64_t signature;
- uint32_t revision;
- uint32_t header_size;
- uint32_t crc32;
- uint32_t reserved;
- uint64_t current_lba;
- uint64_t backup_lba;
- uint64_t first_usable_lba;
- uint64_t last_usable_lba;
- uint8_t disk_guid[16];
- uint64_t start_lba;
- uint32_t entry_count;
- uint32_t entry_size;
- uint32_t entries_crc32;
-} __attribute__((packed)) gpt_header;
-
-class GptUtils {
- public:
- GptUtils(const std::string dev_path);
- int Load(void);
- gpt_entry *GetPartitionEntry(std::string name);
- int Sync(void);
- ~GptUtils();
-
- private:
- std::string dev_path;
- int fd;
- uint32_t block_size;
- gpt_header gpt_primary;
- gpt_header gpt_backup;
- std::vector<gpt_entry> entry_array;
- std::map<std::string, gpt_entry *>entries;
-};
-
-} // namespace implementation
-} // namespace V1_0
-} // namespace boot
-} // namespace hardware
-} // namespace android
diff --git a/interfaces/boot/1.0/android.hardware.boot@1.0-service-gs201.rc b/interfaces/boot/1.0/android.hardware.boot@1.0-service-gs201.rc
deleted file mode 100644
index 7a7849f..0000000
--- a/interfaces/boot/1.0/android.hardware.boot@1.0-service-gs201.rc
+++ /dev/null
@@ -1,4 +0,0 @@
-service vendor.boot-hal-1-0 /vendor/bin/hw/android.hardware.boot@1.0-service-gs201
- class early_hal
- user root
- group root
diff --git a/interfaces/boot/1.0/service.cpp b/interfaces/boot/1.0/service.cpp
deleted file mode 100644
index 9dcd78c..0000000
--- a/interfaces/boot/1.0/service.cpp
+++ /dev/null
@@ -1,47 +0,0 @@
-/*
- * Copyright (C) 2016 The Android Open Source 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.
- */
-#define LOG_TAG "android.hardware.boot@1.0-service"
-
-#include <log/log.h>
-#include <hidl/HidlTransportSupport.h>
-#include <hidl/Status.h>
-#include <android/hardware/boot/1.0/IBootControl.h>
-#include "BootControl.h"
-
-using ::android::status_t;
-
-using ::android::hardware::boot::V1_0::IBootControl;
-
-using ::android::hardware::boot::V1_0::implementation::BootControl;
-
-int main (int /* argc */, char * /* argv */ []) {
- // This function must be called before you join to ensure the proper
- // number of threads are created. The threadpool will never exceed
- // size one because of this call.
- ::android::hardware::configureRpcThreadpool(1 /*threads*/, true /*willJoin*/);
-
- ::android::sp bootctrl = new BootControl();
- const status_t status = bootctrl->registerAsService();
- if (status != ::android::OK) {
- return 1; // or handle error
- }
-
- // Adds this thread to the threadpool, resulting in one total
- // thread in the threadpool. We could also do other things, but
- // would have to specify 'false' to willJoin in configureRpcThreadpool.
- ::android::hardware::joinRpcThreadpool();
- return 1; // joinRpcThreadpool should never return
-}
diff --git a/interfaces/boot/1.2/Android.bp b/interfaces/boot/1.2/Android.bp
deleted file mode 100644
index a9fb7f4..0000000
--- a/interfaces/boot/1.2/Android.bp
+++ /dev/null
@@ -1,81 +0,0 @@
-//
-// Copyright (C) 2020 The Android Open Source 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.
-
-package {
- // See: http://go/android-license-faq
- // A large-scale-change added 'default_applicable_licenses' to import
- // all of the 'license_kinds' from "//device/google/gs201:device_google_gs201_license"
- // to get the below license kinds:
- // SPDX-license-identifier-Apache-2.0
- default_applicable_licenses: [
- "//device/google/gs201:device_google_gs201_license",
- ],
-}
-
-cc_binary {
- name: "android.hardware.boot@1.2-service-gs201",
- defaults: ["hidl_defaults"],
- relative_install_path: "hw",
- vendor: true,
- init_rc: ["android.hardware.boot@1.2-service-gs201.rc"],
- srcs: [
- "BootControl.cpp",
- "GptUtils.cpp",
- "service.cpp"
- ],
- shared_libs: [
- "libbase",
- "liblog",
- "libhidlbase",
- "libutils",
- "libcutils",
- "libz",
- "android.hardware.boot@1.0",
- "android.hardware.boot@1.1",
- "android.hardware.boot@1.2",
- ],
- static_libs: [
- "libboot_control",
- "libbootloader_message_vendor",
- "libfstab",
- ],
-}
-
-cc_library {
- name: "android.hardware.boot@1.2-impl-gs201",
- stem: "android.hardware.boot@1.0-impl-1.2-impl-gs201",
- recovery: true,
- srcs: [
- "BootControl.cpp",
- "GptUtils.cpp",
- ],
- relative_install_path: "hw",
- shared_libs: [
- "libbase",
- "liblog",
- "libhidlbase",
- "libutils",
- "libcutils",
- "libz",
- "android.hardware.boot@1.0",
- "android.hardware.boot@1.1",
- "android.hardware.boot@1.2",
- ],
- static_libs: [
- "libboot_control",
- "libbootloader_message_vendor",
- "libfstab",
- ],
-}
diff --git a/interfaces/boot/1.2/BootControl.cpp b/interfaces/boot/1.2/BootControl.cpp
deleted file mode 100644
index a28be05..0000000
--- a/interfaces/boot/1.2/BootControl.cpp
+++ /dev/null
@@ -1,420 +0,0 @@
-/*
- * Copyright (C) 2020 The Android Open Source 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.
- */
-
-#define LOG_TAG "bootcontrolhal"
-
-#include "BootControl.h"
-
-#include <android-base/file.h>
-#include <android-base/unique_fd.h>
-#include <bootloader_message/bootloader_message.h>
-#include <cutils/properties.h>
-#include <libboot_control/libboot_control.h>
-#include <log/log.h>
-
-#include "DevInfo.h"
-#include "GptUtils.h"
-
-namespace android {
-namespace hardware {
-namespace boot {
-namespace V1_2 {
-namespace implementation {
-
-using android::bootable::GetMiscVirtualAbMergeStatus;
-using android::bootable::InitMiscVirtualAbMessageIfNeeded;
-using android::bootable::SetMiscVirtualAbMergeStatus;
-using android::hardware::boot::V1_0::BoolResult;
-using android::hardware::boot::V1_0::CommandResult;
-using android::hardware::boot::V1_1::MergeStatus;
-
-namespace {
-
-// clang-format off
-
-#define BOOT_A_PATH "/dev/block/by-name/boot_a"
-#define BOOT_B_PATH "/dev/block/by-name/boot_b"
-#define DEVINFO_PATH "/dev/block/by-name/devinfo"
-
-// slot flags
-#define AB_ATTR_PRIORITY_SHIFT 52
-#define AB_ATTR_PRIORITY_MASK (3UL << AB_ATTR_PRIORITY_SHIFT)
-#define AB_ATTR_ACTIVE_SHIFT 54
-#define AB_ATTR_ACTIVE (1UL << AB_ATTR_ACTIVE_SHIFT)
-#define AB_ATTR_RETRY_COUNT_SHIFT (55)
-#define AB_ATTR_RETRY_COUNT_MASK (7UL << AB_ATTR_RETRY_COUNT_SHIFT)
-#define AB_ATTR_SUCCESSFUL (1UL << 58)
-#define AB_ATTR_UNBOOTABLE (1UL << 59)
-
-#define AB_ATTR_MAX_PRIORITY 3UL
-#define AB_ATTR_MAX_RETRY_COUNT 3UL
-
-// clang-format on
-
-static std::string getDevPath(uint32_t slot) {
- char real_path[PATH_MAX];
-
- const char *path = slot == 0 ? BOOT_A_PATH : BOOT_B_PATH;
-
- int ret = readlink(path, real_path, sizeof real_path);
- if (ret < 0) {
- ALOGE("readlink failed for boot device %s\n", strerror(errno));
- return std::string();
- }
-
- std::string dp(real_path);
- // extract /dev/sda.. part
- return dp.substr(0, sizeof "/dev/block/sdX" - 1);
-}
-
-static bool isSlotFlagSet(uint32_t slot, uint64_t flag) {
- std::string dev_path = getDevPath(slot);
- if (dev_path.empty()) {
- ALOGI("Could not get device path for slot %d\n", slot);
- return false;
- }
-
- GptUtils gpt(dev_path);
- if (gpt.Load()) {
- ALOGI("failed to load gpt data\n");
- return false;
- }
-
- gpt_entry *e = gpt.GetPartitionEntry(slot ? "boot_b" : "boot_a");
- if (e == nullptr) {
- ALOGI("failed to get gpt entry\n");
- return false;
- }
-
- return !!(e->attr & flag);
-}
-
-static bool setSlotFlag(uint32_t slot, uint64_t flag) {
- std::string dev_path = getDevPath(slot);
- if (dev_path.empty()) {
- ALOGI("Could not get device path for slot %d\n", slot);
- return false;
- }
-
- GptUtils gpt(dev_path);
- if (gpt.Load()) {
- ALOGI("failed to load gpt data\n");
- return false;
- }
-
- gpt_entry *e = gpt.GetPartitionEntry(slot ? "boot_b" : "boot_a");
- if (e == nullptr) {
- ALOGI("failed to get gpt entry\n");
- return false;
- }
-
- e->attr |= flag;
- gpt.Sync();
-
- return true;
-}
-
-static bool is_devinfo_valid;
-static bool is_devinfo_initialized;
-static std::mutex devinfo_lock;
-static devinfo_t devinfo;
-
-static bool isDevInfoValid() {
- const std::lock_guard<std::mutex> lock(devinfo_lock);
-
- if (is_devinfo_initialized) {
- return is_devinfo_valid;
- }
-
- is_devinfo_initialized = true;
-
- android::base::unique_fd fd(open(DEVINFO_PATH, O_RDONLY));
- android::base::ReadFully(fd, &devinfo, sizeof devinfo);
-
- if (devinfo.magic != DEVINFO_MAGIC) {
- return is_devinfo_valid;
- }
-
- uint32_t version = ((uint32_t)devinfo.ver_major << 16) | devinfo.ver_minor;
- // only version 3.3+ supports A/B data
- if (version >= 0x0003'0003) {
- is_devinfo_valid = true;
- }
-
- return is_devinfo_valid;
-}
-
-static bool DevInfoSync() {
- if (!isDevInfoValid()) {
- return false;
- }
-
- android::base::unique_fd fd(open(DEVINFO_PATH, O_WRONLY | O_DSYNC));
- return android::base::WriteFully(fd, &devinfo, sizeof devinfo);
-}
-
-static void DevInfoInitSlot(devinfo_ab_slot_data_t &slot_data) {
- slot_data.retry_count = AB_ATTR_MAX_RETRY_COUNT;
- slot_data.unbootable = 0;
- slot_data.successful = 0;
- slot_data.active = 1;
- slot_data.fastboot_ok = 0;
-}
-
-} // namespace
-
-// Methods from ::android::hardware::boot::V1_0::IBootControl follow.
-Return<uint32_t> BootControl::getNumberSlots() {
- uint32_t slots = 0;
-
- if (access(BOOT_A_PATH, F_OK) == 0)
- slots++;
-
- if (access(BOOT_B_PATH, F_OK) == 0)
- slots++;
-
- return slots;
-}
-
-Return<uint32_t> BootControl::getCurrentSlot() {
- char suffix[PROPERTY_VALUE_MAX];
- property_get("ro.boot.slot_suffix", suffix, "_a");
- return std::string(suffix) == "_b" ? 1 : 0;
-}
-
-Return<void> BootControl::markBootSuccessful(markBootSuccessful_cb _hidl_cb) {
- if (getNumberSlots() == 0) {
- // no slots, just return true otherwise Android keeps trying
- _hidl_cb({true, ""});
- return Void();
- }
-
- bool ret;
- if (isDevInfoValid()) {
- auto const slot = getCurrentSlot();
- devinfo.ab_data.slots[slot].successful = 1;
- ret = DevInfoSync();
- } else {
- ret = setSlotFlag(getCurrentSlot(), AB_ATTR_SUCCESSFUL);
- }
-
- !ret ? _hidl_cb({false, "Failed to set successful flag"}) : _hidl_cb({true, ""});
- return Void();
-}
-
-Return<void> BootControl::setActiveBootSlot(uint32_t slot, setActiveBootSlot_cb _hidl_cb) {
- if (slot >= 2) {
- _hidl_cb({false, "Invalid slot"});
- return Void();
- }
-
- if (isDevInfoValid()) {
- auto &active_slot_data = devinfo.ab_data.slots[slot];
- auto &inactive_slot_data = devinfo.ab_data.slots[!slot];
-
- inactive_slot_data.active = 0;
- DevInfoInitSlot(active_slot_data);
-
- if (!DevInfoSync()) {
- _hidl_cb({false, "Could not update DevInfo data"});
- return Void();
- }
- } else {
- std::string dev_path = getDevPath(slot);
- if (dev_path.empty()) {
- _hidl_cb({false, "Could not get device path for slot"});
- return Void();
- }
-
- GptUtils gpt(dev_path);
- if (gpt.Load()) {
- _hidl_cb({false, "failed to load gpt data"});
- return Void();
- }
-
- gpt_entry *active_entry = gpt.GetPartitionEntry(slot == 0 ? "boot_a" : "boot_b");
- gpt_entry *inactive_entry = gpt.GetPartitionEntry(slot == 0 ? "boot_b" : "boot_a");
- if (active_entry == nullptr || inactive_entry == nullptr) {
- _hidl_cb({false, "failed to get entries for boot partitions"});
- return Void();
- }
-
- ALOGV("slot active attributes %lx\n", active_entry->attr);
- ALOGV("slot inactive attributes %lx\n", inactive_entry->attr);
-
- // update attributes for active and inactive
- inactive_entry->attr &= ~AB_ATTR_ACTIVE;
- active_entry->attr = AB_ATTR_ACTIVE | (AB_ATTR_MAX_PRIORITY << AB_ATTR_PRIORITY_SHIFT) |
- (AB_ATTR_MAX_RETRY_COUNT << AB_ATTR_RETRY_COUNT_SHIFT);
- }
-
- char boot_dev[PROPERTY_VALUE_MAX];
- property_get("ro.boot.bootdevice", boot_dev, "");
- if (boot_dev[0] == '\0') {
- _hidl_cb({false, "invalid ro.boot.bootdevice prop"});
- return Void();
- }
-
- std::string boot_lun_path =
- std::string("/sys/devices/platform/") + boot_dev + "/pixel/boot_lun_enabled";
- int fd = open(boot_lun_path.c_str(), O_RDWR | O_DSYNC);
- if (fd < 0) {
- // Try old path for kernels < 5.4
- // TODO: remove once kernel 4.19 support is deprecated
- std::string boot_lun_path =
- std::string("/sys/devices/platform/") + boot_dev + "/attributes/boot_lun_enabled";
- fd = open(boot_lun_path.c_str(), O_RDWR | O_DSYNC);
- if (fd < 0) {
- _hidl_cb({false, "failed to open ufs attr boot_lun_enabled"});
- return Void();
- }
- }
-
- //
- // bBootLunEn
- // 0x1 => Boot LU A = enabled, Boot LU B = disable
- // 0x2 => Boot LU A = disable, Boot LU B = enabled
- //
- int ret = android::base::WriteStringToFd(slot == 0 ? "1" : "2", fd);
- close(fd);
- if (ret < 0) {
- _hidl_cb({false, "faied to write boot_lun_enabled attribute"});
- return Void();
- }
-
- _hidl_cb({true, ""});
- return Void();
-}
-
-Return<void> BootControl::setSlotAsUnbootable(uint32_t slot, setSlotAsUnbootable_cb _hidl_cb) {
- if (slot >= 2) {
- _hidl_cb({false, "Invalid slot"});
- return Void();
- }
-
- if (isDevInfoValid()) {
- auto &slot_data = devinfo.ab_data.slots[slot];
- slot_data.unbootable = 1;
- if (!DevInfoSync()) {
- _hidl_cb({false, "Could not update DevInfo data"});
- return Void();
- }
- } else {
- std::string dev_path = getDevPath(slot);
- if (dev_path.empty()) {
- _hidl_cb({false, "Could not get device path for slot"});
- return Void();
- }
-
- GptUtils gpt(dev_path);
- gpt.Load();
-
- gpt_entry *e = gpt.GetPartitionEntry(slot ? "boot_b" : "boot_a");
- e->attr |= AB_ATTR_UNBOOTABLE;
-
- gpt.Sync();
- }
-
- _hidl_cb({true, ""});
- return Void();
-}
-
-Return<::android::hardware::boot::V1_0::BoolResult> BootControl::isSlotBootable(uint32_t slot) {
- if (getNumberSlots() == 0)
- return BoolResult::FALSE;
- if (slot >= getNumberSlots())
- return BoolResult::INVALID_SLOT;
-
- bool unbootable;
- if (isDevInfoValid()) {
- auto &slot_data = devinfo.ab_data.slots[slot];
- unbootable = !!slot_data.unbootable;
- } else {
- unbootable = isSlotFlagSet(slot, AB_ATTR_UNBOOTABLE);
- }
-
- return unbootable ? BoolResult::FALSE : BoolResult::TRUE;
-}
-
-Return<::android::hardware::boot::V1_0::BoolResult> BootControl::isSlotMarkedSuccessful(
- uint32_t slot) {
- if (getNumberSlots() == 0) {
- // just return true so that we don't we another call trying to mark it as successful
- // when there is no slots
- return BoolResult::TRUE;
- }
- if (slot >= getNumberSlots())
- return BoolResult::INVALID_SLOT;
-
- bool successful;
- if (isDevInfoValid()) {
- auto &slot_data = devinfo.ab_data.slots[slot];
- successful = !!slot_data.successful;
- } else {
- successful = isSlotFlagSet(slot, AB_ATTR_SUCCESSFUL);
- }
-
- return successful ? BoolResult::TRUE : BoolResult::FALSE;
-}
-
-Return<void> BootControl::getSuffix(uint32_t slot, getSuffix_cb _hidl_cb) {
- _hidl_cb(slot == 0 ? "_a" : slot == 1 ? "_b" : "");
- return Void();
-}
-
-// Methods from ::android::hardware::boot::V1_1::IBootControl follow.
-bool BootControl::Init() {
- return InitMiscVirtualAbMessageIfNeeded();
-}
-
-Return<bool> BootControl::setSnapshotMergeStatus(
- ::android::hardware::boot::V1_1::MergeStatus status) {
- return SetMiscVirtualAbMergeStatus(getCurrentSlot(), status);
-}
-
-Return<::android::hardware::boot::V1_1::MergeStatus> BootControl::getSnapshotMergeStatus() {
- MergeStatus status;
- if (!GetMiscVirtualAbMergeStatus(getCurrentSlot(), &status)) {
- return MergeStatus::UNKNOWN;
- }
- return status;
-}
-
-// Methods from ::android::hardware::boot::V1_2::IBootControl follow.
-Return<uint32_t> BootControl::getActiveBootSlot() {
- if (getNumberSlots() == 0)
- return 0;
-
- if (isDevInfoValid())
- return devinfo.ab_data.slots[1].active ? 1 : 0;
- return isSlotFlagSet(1, AB_ATTR_ACTIVE) ? 1 : 0;
-}
-
-// Methods from ::android::hidl::base::V1_0::IBase follow.
-
-IBootControl *HIDL_FETCH_IBootControl(const char * /* name */) {
- auto module = new BootControl();
-
- module->Init();
-
- return module;
-}
-
-} // namespace implementation
-} // namespace V1_2
-} // namespace boot
-} // namespace hardware
-} // namespace android
diff --git a/interfaces/boot/1.2/BootControl.h b/interfaces/boot/1.2/BootControl.h
deleted file mode 100644
index 17b5f0f..0000000
--- a/interfaces/boot/1.2/BootControl.h
+++ /dev/null
@@ -1,69 +0,0 @@
-/*
- * Copyright (C) 2020 The Android Open Source 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.
- */
-
-#pragma once
-
-#include <android/hardware/boot/1.2/IBootControl.h>
-#include <hidl/MQDescriptor.h>
-#include <hidl/Status.h>
-
-namespace android {
-namespace hardware {
-namespace boot {
-namespace V1_2 {
-namespace implementation {
-
-using ::android::sp;
-using ::android::hardware::hidl_array;
-using ::android::hardware::hidl_memory;
-using ::android::hardware::hidl_string;
-using ::android::hardware::hidl_vec;
-using ::android::hardware::Return;
-using ::android::hardware::Void;
-
-struct BootControl : public IBootControl {
- bool Init();
-
- // Methods from ::android::hardware::boot::V1_0::IBootControl follow.
- Return<uint32_t> getNumberSlots() override;
- Return<uint32_t> getCurrentSlot() override;
- Return<void> markBootSuccessful(markBootSuccessful_cb _hidl_cb) override;
- Return<void> setActiveBootSlot(uint32_t slot, setActiveBootSlot_cb _hidl_cb) override;
- Return<void> setSlotAsUnbootable(uint32_t slot, setSlotAsUnbootable_cb _hidl_cb) override;
- Return<::android::hardware::boot::V1_0::BoolResult> isSlotBootable(uint32_t slot) override;
- Return<::android::hardware::boot::V1_0::BoolResult> isSlotMarkedSuccessful(
- uint32_t slot) override;
- Return<void> getSuffix(uint32_t slot, getSuffix_cb _hidl_cb) override;
-
- // Methods from ::android::hardware::boot::V1_1::IBootControl follow.
- Return<bool> setSnapshotMergeStatus(
- ::android::hardware::boot::V1_1::MergeStatus status) override;
- Return<::android::hardware::boot::V1_1::MergeStatus> getSnapshotMergeStatus() override;
-
- // Methods from ::android::hardware::boot::V1_2::IBootControl follow.
- Return<uint32_t> getActiveBootSlot() override;
-
- // Methods from ::android::hidl::base::V1_0::IBase follow.
-};
-
-// FIXME: most likely delete, this is only for passthrough implementations
-extern "C" IBootControl *HIDL_FETCH_IBootControl(const char *name);
-
-} // namespace implementation
-} // namespace V1_2
-} // namespace boot
-} // namespace hardware
-} // namespace android
diff --git a/interfaces/boot/1.2/DevInfo.h b/interfaces/boot/1.2/DevInfo.h
deleted file mode 100644
index a09a83a..0000000
--- a/interfaces/boot/1.2/DevInfo.h
+++ /dev/null
@@ -1,61 +0,0 @@
-/*
- * Copyright (C) 2021 The Android Open Source 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.
- */
-
-#pragma once
-
-namespace android {
-namespace hardware {
-namespace boot {
-namespace V1_2 {
-namespace implementation {
-
-//
-// definitions taken from ABL code
-//
-
-constexpr uint32_t DEVINFO_MAGIC = 0x49564544;
-constexpr size_t DEVINFO_AB_SLOT_COUNT = 2;
-
-struct devinfo_ab_slot_data_t {
- uint8_t retry_count;
- uint8_t unbootable : 1;
- uint8_t successful : 1;
- uint8_t active : 1;
- uint8_t fastboot_ok : 1;
- uint8_t : 4;
- uint8_t unused[2];
-} __attribute__((packed));
-
-typedef struct {
- devinfo_ab_slot_data_t slots[DEVINFO_AB_SLOT_COUNT];
-} __attribute__((packed)) devinfo_ab_data_t;
-
-struct devinfo_t {
- uint32_t magic;
- uint16_t ver_major;
- uint16_t ver_minor;
- uint8_t unused[40];
- devinfo_ab_data_t ab_data;
- uint8_t unused1[72]; // use remaining up to complete 128 bytes
-} __attribute__((packed));
-
-static_assert(sizeof(devinfo_t) == 128, "invalid devinfo struct size");
-
-} // namespace implementation
-} // namespace V1_2
-} // namespace boot
-} // namespace hardware
-} // namespace android
diff --git a/interfaces/boot/1.2/GptUtils.cpp b/interfaces/boot/1.2/GptUtils.cpp
deleted file mode 100644
index 25088e7..0000000
--- a/interfaces/boot/1.2/GptUtils.cpp
+++ /dev/null
@@ -1,193 +0,0 @@
-/*
- * Copyright (C) 2019 The Android Open Source 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.
- */
-
-#define LOG_TAG "bootcontrolhal"
-
-#include "GptUtils.h"
-
-#include <android-base/file.h>
-#include <errno.h>
-#include <linux/fs.h>
-#include <log/log.h>
-#include <zlib.h>
-
-namespace android {
-namespace hardware {
-namespace boot {
-namespace V1_2 {
-namespace implementation {
-
-namespace {
-
-static int ValidateGptHeader(gpt_header *gpt) {
- if (gpt->signature != GPT_SIGNATURE) {
- ALOGE("invalid gpt signature 0x%lx\n", gpt->signature);
- return -1;
- }
-
- if (gpt->header_size != sizeof(gpt_header)) {
- ALOGE("invalid gpt header size %u\n", gpt->header_size);
- return -1;
- }
-
- if (gpt->entry_size != sizeof(gpt_entry)) {
- ALOGE("invalid gpt entry size %u\n", gpt->entry_size);
- return -1;
- }
-
- return 0;
-}
-
-} // namespace
-
-GptUtils::GptUtils(const std::string dev_path) : dev_path(dev_path), fd(0) {}
-
-int GptUtils::Load(void) {
- fd = open(dev_path.c_str(), O_RDWR);
- if (fd < 0) {
- ALOGE("failed to open block dev %s, %d\n", dev_path.c_str(), errno);
- return -1;
- }
-
- int ret = ioctl(fd, BLKSSZGET, &block_size);
- if (ret < 0) {
- ALOGE("failed to get block size %d\n", errno);
- return -1;
- }
-
- // read primary header
- lseek64(fd, block_size, SEEK_SET);
- ret = read(fd, &gpt_primary, sizeof gpt_primary);
- if (ret < 0) {
- ALOGE("failed to read gpt primary header %d\n", errno);
- return -1;
- }
-
- if (ValidateGptHeader(&gpt_primary)) {
- ALOGE("error validating gpt header\n");
- return -1;
- }
-
- // read partition entries
- entry_array.resize(gpt_primary.entry_count);
- uint32_t entries_size = gpt_primary.entry_size * gpt_primary.entry_count;
- lseek64(fd, block_size * gpt_primary.start_lba, SEEK_SET);
- ret = read(fd, entry_array.data(), entries_size);
- if (ret < 0) {
- ALOGE("failed to read gpt partition entries %d\n", errno);
- return -1;
- }
-
- // read gpt back header
- lseek64(fd, block_size * gpt_primary.backup_lba, SEEK_SET);
- ret = read(fd, &gpt_backup, sizeof gpt_backup);
- if (ret < 0) {
- ALOGE("failed to read gpt backup header %d\n", errno);
- return -1;
- }
-
- if (ValidateGptHeader(&gpt_backup)) {
- ALOGW("error validating gpt backup\n"); // just warn about it, not fail
- }
-
- // Create map <partition name, gpt_entry pointer>
- auto get_name = [](const uint16_t *efi_name) {
- char name[37] = {};
- for (int i = 0; efi_name[i] && i < sizeof name - 1; ++i) name[i] = efi_name[i];
- return std::string(name);
- };
-
- for (auto const &e : entry_array) {
- if (e.name[0] == 0)
- break; // stop at the first partition with no name
- std::string s = get_name(e.name);
- entries[s] = const_cast<gpt_entry *>(&e);
- }
-
- return 0;
-}
-
-gpt_entry *GptUtils::GetPartitionEntry(std::string name) {
- return entries.find(name) != entries.end() ? entries[name] : nullptr;
-}
-
-int GptUtils::Sync(void) {
- if (!fd)
- return -1;
-
- // calculate crc and check if we need to update gpt
- gpt_primary.entries_crc32 = crc32(0, reinterpret_cast<uint8_t *>(entry_array.data()),
- entry_array.size() * sizeof(gpt_entry));
-
- // save old crc
- uint32_t crc = gpt_primary.crc32;
- gpt_primary.crc32 = 0;
-
- gpt_primary.crc32 = crc32(0, reinterpret_cast<uint8_t *>(&gpt_primary), sizeof gpt_primary);
- if (crc == gpt_primary.crc32)
- return 0; // nothing to do (no changes)
-
- ALOGI("updating GPT\n");
-
- lseek64(fd, block_size * gpt_primary.current_lba, SEEK_SET);
- int ret = write(fd, &gpt_primary, sizeof gpt_primary);
- if (ret < 0) {
- ALOGE("failed to write gpt primary header %d\n", errno);
- return -1;
- }
-
- lseek64(fd, block_size * gpt_primary.start_lba, SEEK_SET);
- ret = write(fd, entry_array.data(), entry_array.size() * sizeof(gpt_entry));
- if (ret < 0) {
- ALOGE("failed to write gpt partition entries %d\n", errno);
- return -1;
- }
-
- // update GPT backup entries and backup
- lseek64(fd, block_size * gpt_backup.start_lba, SEEK_SET);
- ret = write(fd, entry_array.data(), entry_array.size() * sizeof(gpt_entry));
- if (ret < 0) {
- ALOGE("failed to write gpt backup partition entries %d\n", errno);
- return -1;
- }
-
- gpt_backup.entries_crc32 = gpt_primary.entries_crc32;
- gpt_backup.crc32 = 0;
- gpt_backup.crc32 = crc32(0, reinterpret_cast<uint8_t *>(&gpt_backup), sizeof gpt_backup);
- lseek64(fd, block_size * gpt_primary.backup_lba, SEEK_SET);
- ret = write(fd, &gpt_backup, sizeof gpt_backup);
- if (ret < 0) {
- ALOGE("failed to write gpt backup header %d\n", errno);
- return -1;
- }
-
- fsync(fd);
-
- return 0;
-}
-
-GptUtils::~GptUtils() {
- if (fd) {
- Sync();
- close(fd);
- }
-}
-
-} // namespace implementation
-} // namespace V1_2
-} // namespace boot
-} // namespace hardware
-} // namespace android
diff --git a/interfaces/boot/1.2/GptUtils.h b/interfaces/boot/1.2/GptUtils.h
deleted file mode 100644
index a2bed33..0000000
--- a/interfaces/boot/1.2/GptUtils.h
+++ /dev/null
@@ -1,79 +0,0 @@
-/*
- * Copyright (C) 2019 The Android Open Source 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.
- */
-
-#pragma once
-
-#include <map>
-#include <string>
-#include <vector>
-
-namespace android {
-namespace hardware {
-namespace boot {
-namespace V1_2 {
-namespace implementation {
-
-#define GPT_SIGNATURE 0x5452415020494645UL
-
-typedef struct {
- uint8_t type_guid[16];
- uint8_t guid[16];
- uint64_t first_lba;
- uint64_t last_lba;
- uint64_t attr;
- uint16_t name[36];
-} __attribute__((packed)) gpt_entry;
-
-typedef struct {
- uint64_t signature;
- uint32_t revision;
- uint32_t header_size;
- uint32_t crc32;
- uint32_t reserved;
- uint64_t current_lba;
- uint64_t backup_lba;
- uint64_t first_usable_lba;
- uint64_t last_usable_lba;
- uint8_t disk_guid[16];
- uint64_t start_lba;
- uint32_t entry_count;
- uint32_t entry_size;
- uint32_t entries_crc32;
-} __attribute__((packed)) gpt_header;
-
-class GptUtils {
- public:
- GptUtils(const std::string dev_path);
- int Load(void);
- gpt_entry *GetPartitionEntry(std::string name);
- int Sync(void);
- ~GptUtils();
-
- private:
- std::string dev_path;
- int fd;
- uint32_t block_size;
- gpt_header gpt_primary;
- gpt_header gpt_backup;
- std::vector<gpt_entry> entry_array;
- std::map<std::string, gpt_entry *> entries;
-};
-
-} // namespace implementation
-} // namespace V1_2
-} // namespace boot
-} // namespace hardware
-} // namespace android
diff --git a/interfaces/boot/1.2/android.hardware.boot@1.2-service-gs201.rc b/interfaces/boot/1.2/android.hardware.boot@1.2-service-gs201.rc
deleted file mode 100644
index 3457b5f..0000000
--- a/interfaces/boot/1.2/android.hardware.boot@1.2-service-gs201.rc
+++ /dev/null
@@ -1,7 +0,0 @@
-service vendor.boot-hal-1-2 /vendor/bin/hw/android.hardware.boot@1.2-service-gs201
- interface android.hardware.boot@1.0::IBootControl default
- interface android.hardware.boot@1.1::IBootControl default
- interface android.hardware.boot@1.2::IBootControl default
- class early_hal
- user root
- group root
diff --git a/interfaces/boot/1.2/service.cpp b/interfaces/boot/1.2/service.cpp
deleted file mode 100644
index f07682e..0000000
--- a/interfaces/boot/1.2/service.cpp
+++ /dev/null
@@ -1,50 +0,0 @@
-/*
- * Copyright (C) 2020 The Android Open Source 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.
- */
-
-#define LOG_TAG "android.hardware.boot@1.2-service"
-
-#include <android/hardware/boot/1.2/IBootControl.h>
-#include <hidl/HidlTransportSupport.h>
-#include <hidl/Status.h>
-#include <log/log.h>
-
-#include "BootControl.h"
-
-using ::android::status_t;
-
-using ::android::hardware::boot::V1_2::IBootControl;
-
-using ::android::hardware::boot::V1_2::implementation::BootControl;
-// using ::android::hardware::boot::implementation::BootControl;
-
-int main(int /* argc */, char * /* argv */[]) {
- // This function must be called before you join to ensure the proper
- // number of threads are created. The threadpool will never exceed
- // size one because of this call.
- ::android::hardware::configureRpcThreadpool(1 /*threads*/, true /*willJoin*/);
-
- ::android::sp bootctrl = new BootControl();
- const status_t status = bootctrl->registerAsService();
- if (status != ::android::OK) {
- return 1; // or handle error
- }
-
- // Adds this thread to the threadpool, resulting in one total
- // thread in the threadpool. We could also do other things, but
- // would have to specify 'false' to willJoin in configureRpcThreadpool.
- ::android::hardware::joinRpcThreadpool();
- return 1; // joinRpcThreadpool should never return
-}