我是编码新手。所以我尽量保持简单。我的目标是读取像vendor / serial这样的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;
^~~~~~~~~~~~~~~~~~~
如果我在设备上执行此操作,屏幕将变为正确的红色,但不会打印来自变量的数据。只有" - >"
答案 0 :(得分:0)
您正在使用指针而不是vendorguid,attributes和datasize的类型,并尝试写入未分配的缓冲区。 Sample code for reference