简体   繁体   中英

UEFI read variable with RT->GetVariable

Iam new in coding. So i try to keep it much simple as possible. My goal is to read uefi variables like vendor/serial and print it back. My Code will not work like it should. Iam using 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;
}

I got a bunch of compiler warnings, but it will be compiled:

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;
                         ^~~~~~~~~~~~~~~~~~~

If i excute it on the device the screen turns correct red but the data from the varaible is not printed. Only the "->"

You are using pointers instead of types for vendorguid, attributes and datasize, and trying to write into an unallocated buffer. Sample code for reference .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM