问题
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.
回答1:
To add something to UEFI boot list:
- Create BootXXXX variable, it's format looks like this.
- Change BootOrder variable, adding newly created option somewhere in the list.
You can find a working code snippet in UEFI shell sources.
回答2:
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).
来源:https://stackoverflow.com/questions/25525590/uefi-add-boot-option-programmatically