From 142741a87102ecac4e9d0f801ec95cf27708a694 Mon Sep 17 00:00:00 2001 From: Konstantin Aladyshev Date: Mon, 14 Mar 2022 12:35:38 +0300 Subject: Add sources for the HII Checkbox lesson Signed-off-by: Konstantin Aladyshev --- .../UefiLessonsPkg/HIIFormCheckbox/Form.vfr | 25 ++++ .../HIIFormCheckbox/HIIFormCheckbox.c | 152 +++++++++++++++++++++ .../HIIFormCheckbox/HIIFormCheckbox.inf | 28 ++++ .../UefiLessonsPkg/HIIFormCheckbox/Strings.uni | 13 ++ .../Lesson_64/UefiLessonsPkg/UefiLessonsPkg.dsc | 86 ++++++++++++ 5 files changed, 304 insertions(+) create mode 100644 Lessons/Lesson_64/UefiLessonsPkg/HIIFormCheckbox/Form.vfr create mode 100644 Lessons/Lesson_64/UefiLessonsPkg/HIIFormCheckbox/HIIFormCheckbox.c create mode 100644 Lessons/Lesson_64/UefiLessonsPkg/HIIFormCheckbox/HIIFormCheckbox.inf create mode 100644 Lessons/Lesson_64/UefiLessonsPkg/HIIFormCheckbox/Strings.uni create mode 100644 Lessons/Lesson_64/UefiLessonsPkg/UefiLessonsPkg.dsc (limited to 'Lessons/Lesson_64') diff --git a/Lessons/Lesson_64/UefiLessonsPkg/HIIFormCheckbox/Form.vfr b/Lessons/Lesson_64/UefiLessonsPkg/HIIFormCheckbox/Form.vfr new file mode 100644 index 0000000..01759f7 --- /dev/null +++ b/Lessons/Lesson_64/UefiLessonsPkg/HIIFormCheckbox/Form.vfr @@ -0,0 +1,25 @@ +#include + +#define FORMSET_GUID {0xef2acc91, 0x7b50, 0x4ab9, {0xab, 0x67, 0x2b, 0x4, 0xf8, 0xbc, 0x13, 0x5e}} + +formset + guid = FORMSET_GUID, + title = STRING_TOKEN(FORMSET_TITLE), + help = STRING_TOKEN(FORMSET_HELP), + + efivarstore UINT8, + attribute = EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_NON_VOLATILE, + name = CheckboxValue, + guid = FORMSET_GUID; + + form + formid = 1, + title = STRING_TOKEN(FORMID1_TITLE); + + checkbox + varid = CheckboxValue, + prompt = STRING_TOKEN(CHECKBOX_PROMPT), + help = STRING_TOKEN(CHECKBOX_HELP), + endcheckbox; + endform; +endformset; diff --git a/Lessons/Lesson_64/UefiLessonsPkg/HIIFormCheckbox/HIIFormCheckbox.c b/Lessons/Lesson_64/UefiLessonsPkg/HIIFormCheckbox/HIIFormCheckbox.c new file mode 100644 index 0000000..c4f6fd3 --- /dev/null +++ b/Lessons/Lesson_64/UefiLessonsPkg/HIIFormCheckbox/HIIFormCheckbox.c @@ -0,0 +1,152 @@ +/* + * Copyright (c) 2021, Konstantin Aladyshev + * + * SPDX-License-Identifier: MIT + */ + +#include +#include +#include + +#include + +#include +#include + +#define FORMSET_GUID {0xef2acc91, 0x7b50, 0x4ab9, {0xab, 0x67, 0x2b, 0x4, 0xf8, 0xbc, 0x13, 0x5e}} + +extern UINT8 FormBin[]; + +#pragma pack(1) +/// +/// HII specific Vendor Device Path definition. +/// +typedef struct { + VENDOR_DEVICE_PATH VendorDevicePath; + EFI_DEVICE_PATH_PROTOCOL End; +} HII_VENDOR_DEVICE_PATH; +#pragma pack() + +HII_VENDOR_DEVICE_PATH mHiiVendorDevicePath = { + { + { + HARDWARE_DEVICE_PATH, + HW_VENDOR_DP, + { + (UINT8) (sizeof (VENDOR_DEVICE_PATH)), + (UINT8) ((sizeof (VENDOR_DEVICE_PATH)) >> 8) + } + }, + FORMSET_GUID + }, + { + END_DEVICE_PATH_TYPE, + END_ENTIRE_DEVICE_PATH_SUBTYPE, + { + (UINT8) (END_DEVICE_PATH_LENGTH), + (UINT8) ((END_DEVICE_PATH_LENGTH) >> 8) + } + } +}; + + +EFI_HII_HANDLE mHiiHandle = NULL; +EFI_HANDLE mDriverHandle = NULL; + + +EFI_STATUS +EFIAPI +HIIFormCheckboxUnload ( + EFI_HANDLE ImageHandle + ) +{ + if (mHiiHandle != NULL) + HiiRemovePackages(mHiiHandle); + + EFI_STATUS Status; + UINTN BufferSize; + UINT8 EfiVarstore; + + BufferSize = sizeof(UINT8); + Status = gRT->GetVariable( + L"CheckboxValue", + &mHiiVendorDevicePath.VendorDevicePath.Guid, + NULL, + &BufferSize, + &EfiVarstore); + if (!EFI_ERROR(Status)) { + Status = gRT->SetVariable( + L"CheckboxValue", + &mHiiVendorDevicePath.VendorDevicePath.Guid, + 0, + 0, + NULL); + if (EFI_ERROR(Status)) { + Print(L"Error! Can't delete variable! %r\n", Status); + } + } + + Status = gBS->UninstallMultipleProtocolInterfaces( + mDriverHandle, + &gEfiDevicePathProtocolGuid, + &mHiiVendorDevicePath, + NULL + ); + + return Status; +} + +EFI_STATUS +EFIAPI +HIIFormCheckboxEntryPoint ( + IN EFI_HANDLE ImageHandle, + IN EFI_SYSTEM_TABLE *SystemTable + ) +{ + EFI_STATUS Status; + Status = gBS->InstallMultipleProtocolInterfaces( + &mDriverHandle, + &gEfiDevicePathProtocolGuid, + &mHiiVendorDevicePath, + NULL + ); + if (EFI_ERROR (Status)) { + return Status; + } + + + UINTN BufferSize; + UINT8 EfiVarstore; + BufferSize = sizeof(UINT8); + Status = gRT->GetVariable ( + L"CheckboxValue", + &mHiiVendorDevicePath.VendorDevicePath.Guid, + NULL, + &BufferSize, + &EfiVarstore); + if (EFI_ERROR(Status)) { + ZeroMem(&EfiVarstore, sizeof(EfiVarstore)); + Status = gRT->SetVariable( + L"CheckboxValue", + &mHiiVendorDevicePath.VendorDevicePath.Guid, + EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS, + sizeof(EfiVarstore), + &EfiVarstore); + if (EFI_ERROR(Status)) { + Print(L"Error! Can't create variable! %r\n", Status); + } + } + + mHiiHandle = HiiAddPackages( + &gEfiCallerIdGuid, + mDriverHandle, + HIIFormCheckboxStrings, + FormBin, + NULL + ); + if (mHiiHandle == NULL) { + return EFI_OUT_OF_RESOURCES; + } + + return EFI_SUCCESS; +} diff --git a/Lessons/Lesson_64/UefiLessonsPkg/HIIFormCheckbox/HIIFormCheckbox.inf b/Lessons/Lesson_64/UefiLessonsPkg/HIIFormCheckbox/HIIFormCheckbox.inf new file mode 100644 index 0000000..4df03e8 --- /dev/null +++ b/Lessons/Lesson_64/UefiLessonsPkg/HIIFormCheckbox/HIIFormCheckbox.inf @@ -0,0 +1,28 @@ +## +# Copyright (c) 2021, Konstantin Aladyshev +# +# SPDX-License-Identifier: MIT +## + +[Defines] + INF_VERSION = 1.25 + BASE_NAME = HIIFormCheckbox + FILE_GUID = 771a4631-43ba-4852-9593-919d9de079f1 + MODULE_TYPE = UEFI_DRIVER + VERSION_STRING = 1.0 + ENTRY_POINT = HIIFormCheckboxEntryPoint + UNLOAD_IMAGE = HIIFormCheckboxUnload + +[Sources] + HIIFormCheckbox.c + Strings.uni + Form.vfr + +[Packages] + MdePkg/MdePkg.dec + MdeModulePkg/MdeModulePkg.dec + +[LibraryClasses] + UefiDriverEntryPoint + UefiLib + HiiLib diff --git a/Lessons/Lesson_64/UefiLessonsPkg/HIIFormCheckbox/Strings.uni b/Lessons/Lesson_64/UefiLessonsPkg/HIIFormCheckbox/Strings.uni new file mode 100644 index 0000000..7788773 --- /dev/null +++ b/Lessons/Lesson_64/UefiLessonsPkg/HIIFormCheckbox/Strings.uni @@ -0,0 +1,13 @@ +// +// Copyright (c) 2021, Konstantin Aladyshev +// +// SPDX-License-Identifier: MIT +// + +#langdef en-US "English" + +#string FORMSET_TITLE #language en-US "Simple Formset" +#string FORMSET_HELP #language en-US "This is a very simple formset" +#string FORMID1_TITLE #language en-US "Simple Form" +#string CHECKBOX_PROMPT #language en-US "Checkbox prompt" +#string CHECKBOX_HELP #language en-US "Checkbox help" diff --git a/Lessons/Lesson_64/UefiLessonsPkg/UefiLessonsPkg.dsc b/Lessons/Lesson_64/UefiLessonsPkg/UefiLessonsPkg.dsc new file mode 100644 index 0000000..b55f860 --- /dev/null +++ b/Lessons/Lesson_64/UefiLessonsPkg/UefiLessonsPkg.dsc @@ -0,0 +1,86 @@ +## +# Copyright (c) 2021, Konstantin Aladyshev +# +# SPDX-License-Identifier: MIT +## + +[Defines] + DSC_SPECIFICATION = 0x0001001C + PLATFORM_GUID = 3db7270f-ffac-4139-90a4-0ae68f3f8167 + PLATFORM_VERSION = 0.01 + PLATFORM_NAME = UefiLessonsPkg + SKUID_IDENTIFIER = DEFAULT + SUPPORTED_ARCHITECTURES = X64 + BUILD_TARGETS = RELEASE + + +[LibraryClasses] + UefiApplicationEntryPoint|MdePkg/Library/UefiApplicationEntryPoint/UefiApplicationEntryPoint.inf + UefiBootServicesTableLib|MdePkg/Library/UefiBootServicesTableLib/UefiBootServicesTableLib.inf + DebugLib|MdePkg/Library/UefiDebugLibConOut/UefiDebugLibConOut.inf + BaseLib|MdePkg/Library/BaseLib/BaseLib.inf + #PcdLib|MdePkg/Library/BasePcdLibNull/BasePcdLibNull.inf + PcdLib|MdePkg/Library/DxePcdLib/DxePcdLib.inf + BaseMemoryLib|MdePkg/Library/BaseMemoryLib/BaseMemoryLib.inf + RegisterFilterLib|MdePkg/Library/RegisterFilterLibNull/RegisterFilterLibNull.inf + PrintLib|MdePkg/Library/BasePrintLib/BasePrintLib.inf + DebugPrintErrorLevelLib|MdePkg/Library/BaseDebugPrintErrorLevelLib/BaseDebugPrintErrorLevelLib.inf + UefiLib|MdePkg/Library/UefiLib/UefiLib.inf + MemoryAllocationLib|MdePkg/Library/UefiMemoryAllocationLib/UefiMemoryAllocationLib.inf + DevicePathLib|MdePkg/Library/UefiDevicePathLib/UefiDevicePathLib.inf + UefiRuntimeServicesTableLib|MdePkg/Library/UefiRuntimeServicesTableLib/UefiRuntimeServicesTableLib.inf + ShellCEntryLib|ShellPkg/Library/UefiShellCEntryLib/UefiShellCEntryLib.inf + ShellLib|ShellPkg/Library/UefiShellLib/UefiShellLib.inf + FileHandleLib|MdePkg/Library/UefiFileHandleLib/UefiFileHandleLib.inf + HiiLib|MdeModulePkg/Library/UefiHiiLib/UefiHiiLib.inf + SortLib|MdeModulePkg/Library/UefiSortLib/UefiSortLib.inf + UefiHiiServicesLib|MdeModulePkg/Library/UefiHiiServicesLib/UefiHiiServicesLib.inf + UefiDriverEntryPoint|MdePkg/Library/UefiDriverEntryPoint/UefiDriverEntryPoint.inf + #SimpleLibrary|UefiLessonsPkg/Library/SimpleLibrary/SimpleLibrary.inf + #SimpleLibrary|UefiLessonsPkg/Library/SimpleLibraryWithConstructor/SimpleLibraryWithConstructor.inf + SimpleLibrary|UefiLessonsPkg/Library/SimpleLibraryWithConstructorAndDestructor/SimpleLibraryWithConstructorAndDestructor.inf + +[Components] + UefiLessonsPkg/SimplestApp/SimplestApp.inf + UefiLessonsPkg/HelloWorld/HelloWorld.inf + UefiLessonsPkg/ImageHandle/ImageHandle.inf + UefiLessonsPkg/ImageInfo/ImageInfo.inf + UefiLessonsPkg/MemoryInfo/MemoryInfo.inf + UefiLessonsPkg/SimpleShellApp/SimpleShellApp.inf + UefiLessonsPkg/ListVariables/ListVariables.inf + UefiLessonsPkg/ShowBootVariables/ShowBootVariables.inf + UefiLessonsPkg/InteractiveApp/InteractiveApp.inf + UefiLessonsPkg/PCDLesson/PCDLesson.inf + UefiLessonsPkg/SmbiosInfo/SmbiosInfo.inf + UefiLessonsPkg/ShowTables/ShowTables.inf + UefiLessonsPkg/AcpiInfo/AcpiInfo.inf + UefiLessonsPkg/SaveBGRT/SaveBGRT.inf + UefiLessonsPkg/ListPCI/ListPCI.inf + UefiLessonsPkg/SimpleDriver/SimpleDriver.inf + UefiLessonsPkg/PCIRomInfo/PCIRomInfo.inf + UefiLessonsPkg/Library/SimpleLibrary/SimpleLibrary.inf + UefiLessonsPkg/Library/SimpleLibraryWithConstructor/SimpleLibraryWithConstructor.inf + UefiLessonsPkg/SimpleLibraryUser/SimpleLibraryUser.inf + UefiLessonsPkg/SimpleClassProtocol/SimpleClassProtocol.inf + UefiLessonsPkg/SimpleClassUser/SimpleClassUser.inf + UefiLessonsPkg/HotKeyDriver/HotKeyDriver.inf + UefiLessonsPkg/ShowHII/ShowHII.inf + UefiLessonsPkg/HIIStringsC/HIIStringsC.inf + UefiLessonsPkg/HIIStringsUNI/HIIStringsUNI.inf + UefiLessonsPkg/HIIStringsUNIRC/HIIStringsUNIRC.inf + UefiLessonsPkg/HIIStringsMan/HIIStringsMan.inf + UefiLessonsPkg/HIIAddRussianFont/HIIAddRussianFont.inf + UefiLessonsPkg/HIIAddLocalization/HIIAddLocalization.inf + UefiLessonsPkg/AddNewLanguage/AddNewLanguage.inf + UefiLessonsPkg/HIISimpleForm/HIISimpleForm.inf + UefiLessonsPkg/HIIStaticForm/HIIStaticForm.inf + UefiLessonsPkg/HIIStaticFormDriver/HIIStaticFormDriver.inf + UefiLessonsPkg/DisplayHIIByGuid/DisplayHIIByGuid.inf + UefiLessonsPkg/SetVariableExample/SetVariableExample.inf + UefiLessonsPkg/UpdateDmpstoreDump/UpdateDmpstoreDump.inf + UefiLessonsPkg/DevicePath/DevicePath.inf + UefiLessonsPkg/HIIFormCheckbox/HIIFormCheckbox.inf + +[PcdsFixedAtBuild] + gUefiLessonsPkgTokenSpaceGuid.PcdMyVar32_2|44 + -- cgit v1.2.3-18-g5258