From 848fbfefe7c00de49cdc5177bd03d079819ff40f Mon Sep 17 00:00:00 2001 From: Kelvin Zhang Date: Wed, 17 Sep 2025 15:25:57 -0700 Subject: [PATCH] [lib][uefi] Mark bio functions as WEAK OEMs may want to override certain bio functions, hence mark `open_block_device` and `open_async_block_device` as WEAK. This allows OEMs to customize any of the bio functions --- lib/uefi/blockio2_protocols.cpp | 3 +-- lib/uefi/blockio_protocols.cpp | 2 +- lib/uefi/uefi_platform.cpp | 5 ++--- lib/uefi/uefi_platform.h | 2 +- 4 files changed, 5 insertions(+), 7 deletions(-) diff --git a/lib/uefi/blockio2_protocols.cpp b/lib/uefi/blockio2_protocols.cpp index 3817fbb8..a389278f 100644 --- a/lib/uefi/blockio2_protocols.cpp +++ b/lib/uefi/blockio2_protocols.cpp @@ -27,7 +27,6 @@ #include #include -#include "defer.h" #include "events.h" #include "io_stack.h" #include "memory_protocols.h" @@ -134,7 +133,7 @@ EfiStatus flush_blocks_ex(EfiBlockIo2Protocol* self, EfiBlockIo2Token* token) { } // namespace -EfiStatus open_async_block_device(EfiHandle handle, void** intf) { +__WEAK EfiStatus open_async_block_device(EfiHandle handle, void** intf) { auto dev = bio_open(reinterpret_cast(handle)); printf("%s(%s)\n", __FUNCTION__, dev->name); auto interface = reinterpret_cast( diff --git a/lib/uefi/blockio_protocols.cpp b/lib/uefi/blockio_protocols.cpp index 7feafdce..d8c01aa0 100644 --- a/lib/uefi/blockio_protocols.cpp +++ b/lib/uefi/blockio_protocols.cpp @@ -75,7 +75,7 @@ EfiStatus reset(EfiBlockIoProtocol *self, bool extended_verification) { } } // namespace -EfiStatus open_block_device(EfiHandle handle, void **intf) { +__WEAK EfiStatus open_block_device(EfiHandle handle, void** intf) { printf("%s(%p)\n", __FUNCTION__, handle); auto io_stack = get_io_stack(); if (io_stack == nullptr) { diff --git a/lib/uefi/uefi_platform.cpp b/lib/uefi/uefi_platform.cpp index 8ee62132..cde12d67 100644 --- a/lib/uefi/uefi_platform.cpp +++ b/lib/uefi/uefi_platform.cpp @@ -31,7 +31,6 @@ #include #include "defer.h" -#include "memory_protocols.h" #define LOCAL_TRACE 0 @@ -173,6 +172,7 @@ const char* GetImageType(const char16_t* ImageType) { } return "unknown"; } + template T clamp(T n, T lower, T upper) { if (n < lower) { @@ -241,8 +241,7 @@ __WEAK EfiStatus get_buffer(struct GblEfiImageLoadingProtocol* self, return EFI_STATUS_SUCCESS; } -__WEAK -EfiStatus open_efi_erase_block_protocol(const EfiHandle handle, void** intf) { +__WEAK EfiStatus open_efi_erase_block_protocol(EfiHandle handle, void** intf) { auto* device_name = static_cast(handle); LTRACEF("handle=%p (%s)\n", handle, device_name); auto* p = reinterpret_cast( diff --git a/lib/uefi/uefi_platform.h b/lib/uefi/uefi_platform.h index dc65eeb8..df9c16dc 100644 --- a/lib/uefi/uefi_platform.h +++ b/lib/uefi/uefi_platform.h @@ -75,6 +75,6 @@ void setup_heap(); // Caled by LK once after executing UEFI application to tear down the heap void reset_heap(); -EfiStatus open_efi_erase_block_protocol(const EfiHandle handle, void** intf); +EfiStatus open_efi_erase_block_protocol(EfiHandle handle, void** intf); #endif