flat assembler
Message board for the users of flat assembler.

Index > OS Construction > UEFI grT->GetVariable() returning Not Found Status

Author
Thread Post new topic Reply to topic
Cantaff0rd



Joined: 11 Jul 2025
Posts: 1
Cantaff0rd 11 Jul 2025, 05:08
Hello,

I have written a UEFI application and running it in a QEMU setup where I have Ubuntu as an operating system.

I am reading the variable like this in the code:

Code:
EFI_STATUS
EFIAPI
UefiMain(
    IN EFI_HANDLE ImageHandle,
    IN EFI_SYSTEM_TABLE *SystemTable
) {
    EFI_STATUS Status;
    UINT8 CheckValue;
    UINTN DataSize = sizeof(CheckValue);
    UINT32 Attributes;  

    Status = gRT->GetVariable(
        L"my_variable",
        &MyGuid,
        &Attributes,    
        &DataSize,
        &CheckValue
    );
if (EFI_ERROR(Status)) {
        Print(L"Error: variable not found. Returning\n");
        return EFI_SUCCESS;
    }

    if (CheckValue != 100) {
        Print(L"Variable is not set to 100. Returning\n");
        return EFI_SUCCESS;
    }
    


And the value is beiing set like this from Ubuntu OS on QEMU with this script:

Code:
#!/bin/bash

VAR_NAME="my_variable"
GUID="12345678-1234-1234-1234-123456789abc"
DATA_FILE="/tmp/check_data"

echo -ne '\x07\x00\x00\x00\x64' > "$DATA_FILE"

sudo efivar --name "${GUID}-${VAR_NAME}" --write --data "$DATA_FILE"

rm "$DATA_FILE"
    






As you can see from the script I am trying to set the variable to 100(0x64). I also have another similar script for setting it to 0. At boottime when UEFI shell comes up I read the value with dmpstore command and I confirm that it's value is 0x64(100). However when the application tries to read it with GetVariable() as in the above example it doesn't find it as if the variable would not exist(Not found status).
My variable which I set from ubuntu has following propreties: Non-Volatile, Boot Service Access, Runtime service Access. So the way I see it it should be accessible for the app.
I am reading through UEFI specs but I have not figured out what the issue is. Please help me fix this if possible. Thanks.
Post 11 Jul 2025, 05:08
View user's profile Send private message Reply with quote
bzt



Joined: 09 Nov 2018
Posts: 91
bzt 11 Jul 2025, 15:34
This has nothing to do with Assembly.

Regardless, your bash script sets the UEFI variable on your HOST, while your code running in QEMU queries the variable emulated for the GUEST. No wonder it's not found.

What you should try instead is to enter UEFI setup on QEMU (by pressing Esc when you see the TIanoCore logo), select "EFI Internal Shell" under "Boot Manager", and set the variable there in the UEFI Shell prompt. I'm not sure what file is configured by default under Ubuntu, but QEMU stores the guest UEFI variables in a file, and not in the host's NVRAM. That file is then used when NVRAM is emulated inside QEMU; therefore adding a variable to your host's NVRAM is futile, you need to add it to that file.

For simplicity, you can use my minimalistic POSIX-UEFI library which provides functions getenv() and setenv() to do this.

Cheers,
bzt
Post 11 Jul 2025, 15:34
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.