[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
This commit is contained in:
Kelvin Zhang
2025-09-17 15:25:57 -07:00
committed by Kelvin Zhang
parent 72c92b5d81
commit 848fbfefe7
4 changed files with 5 additions and 7 deletions

View File

@@ -27,7 +27,6 @@
#include <uefi/protocols/block_io2_protocol.h> #include <uefi/protocols/block_io2_protocol.h>
#include <uefi/types.h> #include <uefi/types.h>
#include "defer.h"
#include "events.h" #include "events.h"
#include "io_stack.h" #include "io_stack.h"
#include "memory_protocols.h" #include "memory_protocols.h"
@@ -134,7 +133,7 @@ EfiStatus flush_blocks_ex(EfiBlockIo2Protocol* self, EfiBlockIo2Token* token) {
} // namespace } // 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<const char*>(handle)); auto dev = bio_open(reinterpret_cast<const char*>(handle));
printf("%s(%s)\n", __FUNCTION__, dev->name); printf("%s(%s)\n", __FUNCTION__, dev->name);
auto interface = reinterpret_cast<EfiBlockIo2Interface*>( auto interface = reinterpret_cast<EfiBlockIo2Interface*>(

View File

@@ -75,7 +75,7 @@ EfiStatus reset(EfiBlockIoProtocol *self, bool extended_verification) {
} }
} // namespace } // namespace
EfiStatus open_block_device(EfiHandle handle, void **intf) { __WEAK EfiStatus open_block_device(EfiHandle handle, void** intf) {
printf("%s(%p)\n", __FUNCTION__, handle); printf("%s(%p)\n", __FUNCTION__, handle);
auto io_stack = get_io_stack(); auto io_stack = get_io_stack();
if (io_stack == nullptr) { if (io_stack == nullptr) {

View File

@@ -31,7 +31,6 @@
#include <uefi/types.h> #include <uefi/types.h>
#include "defer.h" #include "defer.h"
#include "memory_protocols.h"
#define LOCAL_TRACE 0 #define LOCAL_TRACE 0
@@ -173,6 +172,7 @@ const char* GetImageType(const char16_t* ImageType) {
} }
return "unknown"; return "unknown";
} }
template <typename T> template <typename T>
T clamp(T n, T lower, T upper) { T clamp(T n, T lower, T upper) {
if (n < lower) { if (n < lower) {
@@ -241,8 +241,7 @@ __WEAK EfiStatus get_buffer(struct GblEfiImageLoadingProtocol* self,
return EFI_STATUS_SUCCESS; return EFI_STATUS_SUCCESS;
} }
__WEAK __WEAK EfiStatus open_efi_erase_block_protocol(EfiHandle handle, void** intf) {
EfiStatus open_efi_erase_block_protocol(const EfiHandle handle, void** intf) {
auto* device_name = static_cast<const char*>(handle); auto* device_name = static_cast<const char*>(handle);
LTRACEF("handle=%p (%s)\n", handle, device_name); LTRACEF("handle=%p (%s)\n", handle, device_name);
auto* p = reinterpret_cast<EfiEraseBlockInterface*>( auto* p = reinterpret_cast<EfiEraseBlockInterface*>(

View File

@@ -75,6 +75,6 @@ void setup_heap();
// Caled by LK once after executing UEFI application to tear down the heap // Caled by LK once after executing UEFI application to tear down the heap
void reset_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 #endif