0

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 "->"

lokusking
  • 7,396
  • 13
  • 38
  • 57

1 Answers1

0

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

CodeRush
  • 839
  • 4
  • 10
  • Thank you! Seems to work... I need to find a way to convert the data into unicode to print it correct. Product code and stuff like serial is stored inside the smbios data, that will be the next topic... ;-) – KingBonecrusher Jan 30 '17 at 14:36
  • Use APrint instead of Print to work with ASCII data. – CodeRush Jan 30 '17 at 19:37