이를 위해서는 EFI Runtime Services에서 제공하는 GetVariable()API 함수를 사용해야한다.
GetVariable()
Summary:
Returns the value of a variable.
Prototype:
typedef
EFI_STATUS
GetVariable (
IN CHAR16 *VariableName,
IN EFI_GUID *VendorGuid,
OUT UINT32 *Attributes OPTIONAL,
IN OUT UINTN *DataSize,
OUT VOID *Data OPTIONAL
);
Parameters:
VariableName A Null-terminated string that is the name of the vendor’s variable.
VendorGuid A unique identifier for the vendor
Attributes If not NULL, a pointer to the memory location to return the
attributes bitmask for the variable.
If not NULL, then Attributes is set on output both when
EFI_SUCCESS and when EFI_BUFFER_TOO_SMALL is returned.
DataSize On input, the size in bytes of the return Data buffer.
On output the size of data returned in Data.
Data The buffer to return the contents of the variable. May be NULL
with a zero DataSize in order to determine the size buffer needed.
Description:
Each vendor may create and manage its own variables without the risk of name conflicts by using a
unique VendorGuid. When a variable is set its Attributes are supplied to indicate how the data variable
should be stored and maintained by the system. The attributes affect when the variable may be accessed
and volatility of the data
If the Data buffer is too small to hold the contents of the variable, the error EFI_BUFFER_TOO_SMALL is
returned and DataSize is set to the required buffer size to obtain the data.
Status Codes Returned:
EFI_SUCCESS The function completed successfully.
EFI_NOT_FOUND The variable was not found.
EFI_BUFFER_TOO_SMALL The DataSize is too small for the result. DataSize has been
updated with the size needed to complete the request. If
Attributes is not NULL, then the attributes bitmask for the
variable has been stored to the memory location pointed-to by
Attributes.
...
이전 장에서 다음 옵션들이 GUID EFI_GLOBAL_VARIABLE(gEfiGlobalVariableGuid) 아래 환경에 있음을 발견했다.
Each Boot#### variable contains an EFI_LOAD_OPTION. Each Boot#### variable is the name “Boot”
appended with a unique four digit hexadecimal number. For example, Boot0001, Boot0002, Boot0A02,
etc.
...
The BootOrder variable contains an array of UINT16’s that make up an ordered list of the Boot####
options. The first element in the array is the value for the first logical boot option, the second element is
the value for the second logical boot option, etc. The BootOrder order list is used by the firmware’s
boot manager as the default boot order.
...
The BootCurrent variable is a single UINT16 that defines the Boot#### option that was selected on
the current boot.
ShowBootVariables애플리케이션을 만들어보자.
먼저 간단한 UINT16 BootCurrent 옵션을 가져와 보는 것을 목표로 한다.
이 프로그램에서 변수를 많이 가져올 것이므로 GetVariable()함수를 호출할 때 필요한 사항을 추상화하여 함수를 만드는 것이 가장 좋은 방법이다.
typedef struct _EFI_LOAD_OPTION {
UINT32 Attributes;
UINT16 FilePathListLength;
// CHAR16 Description[];
// EFI_DEVICE_PATH_PROTOCOL FilePathList[];
// UINT8 OptionalData[];
} EFI_LOAD_OPTION;
Parameters
Attributes The attributes for this load option entry. All unused bits must be zero
and are reserved by the UEFI specification for future growth.
FilePathListLength Length in bytes of the FilePathList. OptionalData starts at
offset sizeof(UINT32) + sizeof(UINT16) +
StrSize(Description) + FilePathListLength of the
EFI_LOAD_OPTION descriptor.
Description The user readable description for the load option. This field ends
with a Null character.
FilePathList A packed array of UEFI device paths. The first element of the array is
a device path that describes the device and location of the Image for
this load option. The FilePathList[0] is specific to the device
type. Other device paths may optionally exist in the FilePathList,
but their usage is OSV specific. Each element in the array is variable
length, and ends at the device path end structure. Because the size
of Description is arbitrary, this data structure is not guaranteed
to be aligned on a natural boundary. This data structure may have to
be copied to an aligned natural boundary before it is used.
OptionalData The remaining bytes in the load option descriptor are a binary data
buffer that is passed to the loaded image. If the field is zero bytes
long, a NULL pointer is passed to the loaded image. The number of
bytes in OptionalData can be computed by subtracting the
starting offset of OptionalData from total size in bytes of the
EFI_LOAD_OPTION.
/** Produces a Null-terminated Unicode string in an output buffer based on a Null-terminated Unicode format string and variable argument list. This function is similar as snprintf_s defined in C11. ...@param StartOfBuffer A pointer to the output buffer for the produced Null-terminated Unicode string.@param BufferSize The size, in bytes, of the output buffer specified by StartOfBuffer.@param FormatString A Null-terminated Unicode format string.@param ... Variable argument list whose contents are accessed based on the format string specified by FormatString.@return The number of Unicode characters in the produced output buffer not including the Null-terminator.**/UINTNEFIAPIUnicodeSPrint ( OUT CHAR16 *StartOfBuffer, IN UINTN BufferSize, IN CONST CHAR16 *FormatString, ... );
동일한 파일에 ASCII를 위한 비슷한 함수도 있다.
UINTNEFIAPIAsciiSPrint ( OUT CHAR8 *StartOfBuffer, IN UINTN BufferSize, IN CONST CHAR8 *FormatString, ... );