예를 들어 시스템에서 이름이 MyVariableName이고 EFI_VARIABLE_BOOTSERVICE_ACCESS 플래그가 있는 MyVariableGuid 아래에 있는 특수한 MyCustomStructure 유형으로 UEFI 변수를 나타내려면 다음과 같이 선언해야한다.
우리는 현재 이렇게 특별한 구조가 필요하지 않다. 간단하게 UINT8이 우리가 만들려는 Checkbox에 적합하다.
EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_NON_VOLATILE 속성을 가진 변수를 선언하고 이름이 CheckboxValue인 FORMSET_GUID 아래에 배치하자.
Checkbox 값을 이 변수와 연결하려면 varid = CheckboxValue 구문을 사용하면 된다.
IFR 변경 사항 확인
이 새로운 VFR 코드가 IFR 구조를 어떻게 변경했는지 조사해보자.
먼저 우리는 efivarstore를 추가했고, 그 결과 다음 코드가 생성되었다.
이것은 다음의 뜻인 opcode 0x26으로 시작한다.
따라서 처음 2바이트는 EFI_IFR_OP_HEADER이다.
나머지 데이터는 EFI_IFR_VARSTORE_EFI 구조체이다.
바이너리 데이터가 구조체 필드를 채우는 방식을 살펴보자.
보다시피 코드는 UEFI 변수에 대한 GUID+ name 조합과 해당 유형 및 플래그를 제공한다.
이제 이 저장소를 참조하는 방식을 알아보자. 우리는 폼에 varid = CheckboxValue를 추가했었다.
기본적으로 데이터는 다음과 같이 변경되었다.
이는 다음을 의미한다.
이제 checkbox 코드는 id = 1(위에서 선언한 저장소의 id)인 varstore를 가리킨다.
varstore가 있는 HII Checkbox 폼
애플리케이션 폼을 다시 보면 아래쪽 패널에 몇 가지 새로운 도움말 메시지가 추가된 것을 알 수 있다.
F9=Reset to Defaults
F10=Save
이제 구성을 변경하면 구성 변경 메시지가 나타난다.
설정을 저장하려면 하단 패널에 설명된 것처럼 F10을 사용하면 된다. 그러면 다음과 같은 확인 창이 생성된다.
EFI_IFR_CHECKBOX
Summary:
Creates a boolean checkbox.
Prototype:
#define EFI_IFR_CHECKBOX_OP 0x06
typedef struct _EFI_IFR_CHECKBOX {
EFI_IFR_OP_HEADER Header;
EFI_IFR_QUESTION_HEADER Question;
UINT8 Flags;
} EFI_IFR_CHECKBOX;
Members:
Header The standard question header, where Header.OpCode = EFI_IFR_CHECKBOX_OP.
Question The standard question header.
Flags Flags that describe the behavior of the question. All undefined bits should be zero.
Description:
Creates a Boolean checkbox question and adds it to the current form. The checkbox has two values:
FALSE if the box is not checked and TRUE if it is.
EFI_IFR_QUESTION_HEADER
Summary:
Standard question header.
Prototype:
typedef struct _EFI_IFR_QUESTION_HEADER {
EFI_IFR_STATEMENT_HEADER Header;
EFI_QUESTION_ID QuestionId;
EFI_VARSTORE_ID VarStoreId;
union {
EFI_STRING_ID VarName;
UINT16 VarOffset;
} VarStoreInfo;
UINT8 Flags;
} EFI_IFR_QUESTION_HEADER;
Members:
Header The standard statement header.
QuestionId The unique value that identifies the particular question being defined by the opcode. The value of zero is reserved.
Flags A bit-mask that determines which unique settings are active for this question.
VarStoreId Specifies the identifier of a previously declared variable store to use when storing the question’s value.
A value of zero indicates no associated variable store.
VarStoreInfo If VarStoreId refers to Buffer Storage (EFI_IFR_VARSTORE or EFI_IFR_VARSTORE_EFI), then VarStoreInfo contains a 16-bit Buffer Storage offset (VarOffset).
If VarStoreId refers to Name/Value Storage (EFI_IFR_VARSTORE_NAME_VALUE), then VarStoreInfo contains the String ID of the name (VarName) for this name/value pair.
Description:
This is the standard header for questions.
EFI_IFR_STATEMENT_HEADER
Summary:
Standard statement header.
Prototype:
typedef struct _EFI_IFR_STATEMENT_HEADER {
EFI_STRING_ID Prompt;
EFI_STRING_ID Help;
} EFI_IFR_STATEMENT_HEADER;
Members:
Prompt The string identifier of the prompt string for this particular statement. The value 0 indicates no prompt string.
Help The string identifier of the help string for this particular statement. The value 0 indicates no help string.
Description:
This is the standard header for statements, including questions
typedef UINT16 EFI_STRING_ID;
EFI_STRING_ID Prompt = 00 05
EFI_STRING_ID Help = 00 06
EFI_IFR_VARSTORE_EFI
Summary:
Creates a variable storage short-cut for EFI variable storage.
Prototype:
#define EFI_IFR_VARSTORE_EFI_OP 0x26
typedef struct _EFI_IFR_VARSTORE_EFI {
EFI_IFR_OP_HEADER Header;
EFI_VARSTORE_ID VarStoreId;
EFI_GUID Guid;
UINT32 Attributes
UINT16 Size;
//UINT8 Name[];
} EFI_IFR_VARSTORE_EFI;
Members:
Header The byte sequence that defines the type of opcode as well as the length of the opcode being defined. For this tag,
Header.OpCode = EFI_IFR_VARSTORE_EFI_OP.
VarStoreId The variable store identifier, which is unique within the current form set. This field is the value that uniquely identifies
this variable store definition instance from others. Question headers refer to this value to designate which is the active
variable that is being used. A value of zero is invalid.
Guid The EFI variable’s GUID definition. This field comprises one half of the EFI variable name, with the other half being the
human-readable aspect of the name, which is specified in the Name field below.
Attributes Specifies the flags to use for the variable.
Size The size of the variable store.
Name A null-terminated ASCII string that specifies one half of the EFI name for this variable store. The other half is specified in
the Guid field (above). The Name field is not actually included in the structure but is included here to help illustrate the
encoding of the opcode. The size of the string, including the null termination, is included in the opcode's header size.
Description:
This opcode describes an EFI Variable Variable Store within a form set. The Guid and Name specified here will be used with GetVariable() and SetVariable().
EFI_VARSTORE_ID VarStoreId // 01 00
EFI_GUID Guid; // 91 CC 2A EF 50 7B B9 4A AB 67 2B 04 F8 BC 13 5E (= FORMSET_GUID)
UINT32 Attributes // 03 00 00 00
UINT16 Size; // 01 00
//UINT8 Name[]; // 43 68 65 63 6B 62 6F 78 56 61 6C 75 65 00 (= "C h e c k b o x V a l u e")