【问题标题】:UEFI read variable with RT->GetVariableUEFI 使用 RT->GetVariable 读取变量
【发布时间】:2017-01-30 14:30:45
【问题描述】:

我是编码新手。所以我尽量保持简单。我的目标是读取 uefi 变量,例如 vendor/serial 并将其打印回来。我的代码将无法正常工作。我正在使用 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;
                         ^~~~~~~~~~~~~~~~~~~

如果我在设备上执行它,屏幕会变为正确的红色,但不会打印来自变量的数据。只有“->”

【问题讨论】:

  • 哪方面不行?编译器错误?执行期间的意外行为?请提供更多详细信息。
  • RT->GetVariable() 返回什么?

标签: c uefi gnu-efi


【解决方案1】:

您正在使用指针而不是 vendorguid、属性和数据大小的类型,并尝试写入未分配的缓冲区。 Sample code for reference.

【讨论】:

  • 谢谢!似乎工作......我需要找到一种方法将数据转换为 unicode 以正确打印它。产品代码和序列等内容存储在 smbios 数据中,这将是下一个主题... ;-)
  • 使用 APrint 而不是 Print 来处理 ASCII 数据。
猜你喜欢
  • 2016-01-11
  • 2023-03-28
  • 2016-10-02
  • 1970-01-01
  • 2016-01-24
  • 1970-01-01
  • 1970-01-01
  • 2016-05-29
相关资源
最近更新 更多