60. gRT->SetVariable() 함수를 사용한 UEFI 변수 생성, 변경 및 삭제
비휘발성 UEFI 변수(재부팅 후에도 지속되는 변수)와 함께 작동하는 HII 폼을 만들기 전에 UEFI 변수 서비스를 한 번 더 확인해야 한다.
지금까지는 gRT->GetVariable 및 gRT->GetNextVariableName 서비스를 통해 이미 존재하는 변수만 확인했다.
이번 장에서는 사용자 지정 UEFI 변수를 생성, 변경 및 삭제할 수 있는 애플리케이션을 만들어 본다.
이번 장에서는 gRT->SetVariable 함수를 사용한다.
SetVariable()
Summary:
Sets the value of a variable.
Prototype:
typedef
EFI_STATUS
SetVariable (
IN CHAR16 *VariableName,
IN EFI_GUID *VendorGuid,
IN UINT32 Attributes,
IN UINTN DataSize,
IN VOID *Data
);
Parameters:
VariableName A Null-terminated string that is the name of the vendor’s variable.
Each VariableName is unique for each VendorGuid.
VariableName must contain 1 or more characters. If VariableName is an empty string, then
EFI_INVALID_PARAMETER is returned
VendorGuid A unique identifier for the vendor
Attributes Attributes bitmask to set for the variable
DataSize The size in bytes of the Data buffer ... A size of zero causes the variable to be deleted.
Data The contents for the variable
이제 애플리케이션을 생성한다.
UefiLessonsPkg/UefiLessonsPkg.dsc
사용자에게 사용자 정의 UEFI 변수를 만들거나 삭제할 수 있는 기능을 제공한다. 단순화를 위해 변수 값은 사용자가 제공하는 문자열이다. 아래는애플리케이션에 대한 도움말이다.
UefiLessonsPkg/SetVariableExample/SetVariableExample.c
변수를 생성할 때 변수 속성을 제공해야 한다는 것을 알 수 있다. 아래는 플래그의 조합일 수 있다.
EFI_VARIABLE_NOW_VOLATILE - 재부팅 후에도 변수가 남아있다.
EFI_VARIABLE_BOOTSERVICE_ACCESS - 변수를UEFI 단계에서 사용할 수 있다.
EFI_VARIABLE_RUNTIME_ACCESS - 변수를 OS단계에서 사용할 수 있다. (EFI_BOOT_SERVICES.ExitBootServices() 호출이 성공한 후)