我是编码新手。所以我尽量保持简单。我的目标是读取 uefi 变量,如供应商/串行并将其打印回来。我的代码将无法正常工作。我正在使用 gnu-efi。
include "efi.h"
include "efilib.h"
CHAR16* name;
EFI_GUID* vendorguid = EFI_GLOBAL_VARIABLE;
UINT32* attributes;
UINTN* datasize;
VOID* data;
EFI_STATUS
EFIAPI
efi_main (EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable){
InitializeLib(ImageHandle, SystemTable);
uefi_call_wrapper(ST->ConOut->SetMode, 2, ST->ConOut, 0);
uefi_call_wrapper(ST->ConOut->SetAttribute, 2, ST->ConOut, EFI_WHITE | EFI_BACKGROUND_RED);
uefi_call_wrapper(ST->ConOut->ClearScreen, 2, ST->ConOut);
RT->GetVariable(L"Product", vendorguid, attributes, datasize, data);
Print(L"-> %s", data);
for(;;) __asm__("hlt");
return EFI_SUCCESS;
}
我收到了一堆编译器警告,但它将被编译:
test.c:79:25: note: in expansion of macro 'EFI_GLOBAL_VARIABLE'
EFI_GUID* vendorguid = EFI_GLOBAL_VARIABLE;
^~~~~~~~~~~~~~~~~~~
/usr/include/efi/efiapi.h:210:35: warning: excess elements in scalar initializer
{ 0x8BE4DF61, 0x93CA, 0x11d2, {0xAA, 0x0D, 0x00, 0xE0, 0x98, 0x03, 0x2B, 0x8C} }
^
test.c:79:25: note: in expansion of macro 'EFI_GLOBAL_VARIABLE'
EFI_GUID* vendorguid = EFI_GLOBAL_VARIABLE;
^~~~~~~~~~~~~~~~~~~
/usr/include/efi/efiapi.h:210:35: note: (near initialization for 'vendorguid')
{ 0x8BE4DF61, 0x93CA, 0x11d2, {0xAA, 0x0D, 0x00, 0xE0, 0x98, 0x03, 0x2B, 0x8C} }
^
test.c:79:25: note: in expansion of macro 'EFI_GLOBAL_VARIABLE'
EFI_GUID* vendorguid = EFI_GLOBAL_VARIABLE;
^~~~~~~~~~~~~~~~~~~
如果我在设备上执行它,屏幕会变成正确的红色,但不会打印来自变量的数据。只有"->"
您正在使用指针而不是供应商 guid、属性和数据大小的类型,并尝试写入未分配的缓冲区。示例代码以供参考。