Page 1 of 1

Force selection of load option in UEFI via C code

Posted: Sat Apr 29, 2023 10:45 am
by DeadBrother
Hello, friends.

I am involved in a small project (in California).
We are developing a DXE-driver (by C-language).
We have a task - forced selection of a partition to boot the operating system (set boot option in stage before BDS).

Our current implementation forced sets the BootOrder variable with a single entry - with the necessary index of BootNNNN variable.
Also, we overload the SetVariable() function, and we do not allow changing the BootOrder variable in it.

But this implementation does not fully work - on VmWare everything works with bugs.
Also, for different motherboards, the implementation has different behavior, and it is also not always correct.

Please advise how best to solve the problem? Has anyone had a similar experience.

Thanks.

Re: Force selection of load option in UEFI via C code

Posted: Sun May 07, 2023 2:34 pm
by Octocontrabass
EggHead wrote:We are developing a DXE-driver (by C-language).
We have a task - forced selection of a partition to boot the operating system (set boot option in stage before BDS).
That's a pretty unusual task for a DXE driver. Are you able to explain your situation in any more detail than that? I'm particularly interested in why you can't write a bootloader that chain-loads the appropriate operating system.
EggHead wrote:But this implementation does not fully work - on VmWare everything works with bugs.
Also, for different motherboards, the implementation has different behavior, and it is also not always correct.
What kind of bugs?

Some motherboards ignore the BootOrder variable.

Re: Force selection of load option in UEFI via C code

Posted: Wed Jul 12, 2023 8:37 am
by DeadBrother
Octocontrabass, thanks to answer!
Octocontrabass wrote:That's a pretty unusual task for a DXE driver. Are you able to explain your situation in any more detail than that? I'm particularly interested in why you can't write a bootloader that chain-loads the appropriate operating system.
I am developing a trusted OS boot control tool with additional functionality (user login and password entry, checking the integrity of hardware, firmware, etc.). The tool itself is in the form of a DXE-module to run before the OS boots. Therefore, I have to allow the user to boot only the allowed OS.
EggHead wrote:What kind of bugs?
Very different bugs.
I tried to make the BootOrder with a single entry, overwrite SetVariable/GetVariable to return the correct BootOrder and Boot#### variables.
However, on different motherboards, entries in the BootOrder begin to be duplicated or disappear altogether, etc. That is, this approach does not work well.

Re: Force selection of load option in UEFI via C code

Posted: Wed Jul 12, 2023 8:40 am
by DeadBrother
At the moment I'm trying to manually download efi-boot loader (\EFI\Boot\BOOTX64.efi etc.) using LoadImage/StartImage functions.

However, there are also a number of problems for which I will now create another post - viewtopic.php?f=1&t=56900 =)