2
votes

How can i write code which add boot option from UEFI driver programmatically? 1) I try to add "Boot0001" variable:

  ZeroMem(Data, 2048);
  StrCpy(Data, L"Boot0001");
  DataSize = StrLen(Data) * 2;

  Status = gRT->SetVariable(L"Boot0001", &dGuid, Attr, DataSize, &Data);

2) I need add entry to "BootOrder" variable. But i can't understand how. Ideally, i want to add boot option boot from sample efi application.

2
1) What is the result? 2) What aspect do you not understand? - unixsmurf
1) new variable "Boot0001" in NVRAM. 2) How to change "BootOrder" variable to add "Boot0001" option as second option? - yakovlev.it
(Sorry, out travelling, intermittent computer access.) OK that makes it clear enough to answer. - unixsmurf

2 Answers

2
votes

To add something to UEFI boot list:

  1. Create BootXXXX variable, it's format looks like this.
  2. Change BootOrder variable, adding newly created option somewhere in the list.

You can find a working code snippet in UEFI shell sources.

1
votes

How this works is described in the UEFI specification - available without payment from the UEFI Forum. The current version is 2.4B.

The BootOrder variable mechanism (among other things) is described in section 3.2 - Globally Defined Variables, but I'll give a brief summary.

It is an array of UINT16 elements in the order of the preferred boot order. The UINT16 value is the number portion of your Boot#### variable name. So to rank options Boot0001, Boot0002 and Boot0003 in reverse order of preference, your BootOrder variable should contain (hex, ignoring endianness) 000300020001.

It also needs to have Non-Volatile, Boot-services and Runtime-services attributes set (as described in table 11 in that chapter).