我在编码方面是新的。所以我尽量保持简单。我的目标是读取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;
^~~~~~~~~~~~~~~~~~~如果我在设备上执行它,屏幕就会变成正确的红色,但是来自变体的数据不会被打印出来。只有"->“
发布于 2017-01-28 12:03:55
对于vendorguid、属性和datasize,您使用的是指针而不是类型,并试图写入未分配的缓冲区。Sample code for reference。
https://stackoverflow.com/questions/41896027
复制相似问题