/* * Copyright (C) The Android Open Source Project * Copyright (C) 2025 oxmc / PawletOS * * SPDX-License-Identifier: Apache-2.0 * * Implements the AOSP android.hardware.boot AIDL interface * (hardware/interfaces/boot/) for Raspberry Pi 4/5. */ #pragma once #include #include #include "misc_rpi.h" namespace aidl::android::hardware::boot { /** * PawletOS boot_control AIDL HAL for Raspberry Pi 4 / 5. * * Slot metadata is persisted in the "misc" GPT partition at * PAWLET_MISC_OFFSET (see misc_rpi.h). * * The RPi firmware's tryboot mechanism is used for slot switching: * setActiveBootSlot(1) — writes pending-B to misc * (caller triggers `reboot tryboot`) * markBootSuccessful() — confirms boot; if current slot is B, copies * boot_b → boot_a to make the change permanent */ class BootControl : public BnBootControl { public: BootControl(const char* misc_device, const char* boot_a_device, const char* boot_b_device); // IBootControl ndk::ScopedAStatus getNumberSlots(int32_t* out) override; ndk::ScopedAStatus getCurrentSlot(int32_t* out) override; ndk::ScopedAStatus getActiveBootSlot(int32_t* out) override; ndk::ScopedAStatus getSuffix(int32_t slot, std::string* out) override; ndk::ScopedAStatus markBootSuccessful() override; ndk::ScopedAStatus setActiveBootSlot(int32_t slot) override; ndk::ScopedAStatus setSlotAsUnbootable(int32_t slot) override; ndk::ScopedAStatus isSlotBootable(int32_t slot, bool* out) override; ndk::ScopedAStatus isSlotMarkedSuccessful(int32_t slot, bool* out) override; ndk::ScopedAStatus getSnapshotMergeStatus(MergeStatus* out) override; ndk::ScopedAStatus setSnapshotMergeStatus(MergeStatus status) override; private: const std::string misc_device_; const std::string boot_a_device_; const std::string boot_b_device_; bool readMisc(PawletBootControl* ctrl); bool writeMisc(const PawletBootControl& ctrl); void initDefaultMisc(PawletBootControl* ctrl); bool copyBootPartition(const std::string& src, const std::string& dst); static uint32_t computeCrc32(const void* data, size_t len); static bool isValidSlot(int32_t slot); }; } // namespace aidl::android::hardware::boot