diff options
author | Konstantin Aladyshev <aladyshev22@gmail.com> | 2022-03-26 15:05:19 +0300 |
---|---|---|
committer | Konstantin Aladyshev <aladyshev22@gmail.com> | 2022-03-26 15:05:19 +0300 |
commit | d6f79dbb1a24cee84e9f17fdfb20e176f8ed8a2c (patch) | |
tree | dd514455aacecfd7435550c3ddde36010465b55c /Lessons | |
parent | e67d65c139322903a282abcc605ba7089f9991ec (diff) | |
download | UEFI-Lessons-d6f79dbb1a24cee84e9f17fdfb20e176f8ed8a2c.tar.gz UEFI-Lessons-d6f79dbb1a24cee84e9f17fdfb20e176f8ed8a2c.tar.bz2 UEFI-Lessons-d6f79dbb1a24cee84e9f17fdfb20e176f8ed8a2c.zip |
Add lesson 72
Signed-off-by: Konstantin Aladyshev <aladyshev22@gmail.com>
Diffstat (limited to 'Lessons')
-rw-r--r-- | Lessons/Lesson_72/Before.png | bin | 0 -> 2526 bytes | |||
-rw-r--r-- | Lessons/Lesson_72/HIIFormLabel/Data.h | 9 | ||||
-rw-r--r-- | Lessons/Lesson_72/HIIFormLabel/Form.vfr | 14 | ||||
-rw-r--r-- | Lessons/Lesson_72/HIIFormLabel/HIIFormLabel.c | 140 | ||||
-rw-r--r-- | Lessons/Lesson_72/HIIFormLabel/HIIFormLabel.inf | 31 | ||||
-rw-r--r-- | Lessons/Lesson_72/HIIFormLabel/Strings.uni | 11 | ||||
-rw-r--r-- | Lessons/Lesson_72/Label.png | bin | 0 -> 3608 bytes | |||
-rw-r--r-- | Lessons/Lesson_72/README.md | 66 | ||||
-rw-r--r-- | Lessons/Lesson_72/UefiLessonsPkg/UefiLessonsPkg.dsc | 88 |
9 files changed, 356 insertions, 3 deletions
diff --git a/Lessons/Lesson_72/Before.png b/Lessons/Lesson_72/Before.png Binary files differnew file mode 100644 index 0000000..f279081 --- /dev/null +++ b/Lessons/Lesson_72/Before.png diff --git a/Lessons/Lesson_72/HIIFormLabel/Data.h b/Lessons/Lesson_72/HIIFormLabel/Data.h new file mode 100644 index 0000000..0ba704d --- /dev/null +++ b/Lessons/Lesson_72/HIIFormLabel/Data.h @@ -0,0 +1,9 @@ +#ifndef _DATA_H_ +#define _DATA_H_ + +#define FORMSET_GUID {0x29caf8e0, 0x2788, 0x4e1c, {0xb6, 0x15, 0x5b, 0xf8, 0x2f, 0x06, 0x7a, 0xa5}} + +#define LABEL_START 0x1111 +#define LABEL_END 0x2222 + +#endif diff --git a/Lessons/Lesson_72/HIIFormLabel/Form.vfr b/Lessons/Lesson_72/HIIFormLabel/Form.vfr new file mode 100644 index 0000000..71f7a41 --- /dev/null +++ b/Lessons/Lesson_72/HIIFormLabel/Form.vfr @@ -0,0 +1,14 @@ +#include "Data.h" + +formset + guid = FORMSET_GUID, + title = STRING_TOKEN(FORMSET_TITLE), + help = STRING_TOKEN(FORMSET_HELP), + form + formid = 1, + title = STRING_TOKEN(FORMID1_TITLE); + + label LABEL_START; + label LABEL_END; + endform; +endformset; diff --git a/Lessons/Lesson_72/HIIFormLabel/HIIFormLabel.c b/Lessons/Lesson_72/HIIFormLabel/HIIFormLabel.c new file mode 100644 index 0000000..adf3172 --- /dev/null +++ b/Lessons/Lesson_72/HIIFormLabel/HIIFormLabel.c @@ -0,0 +1,140 @@ +/* + * Copyright (c) 2021, Konstantin Aladyshev <aladyshev22@gmail.com> + * + * SPDX-License-Identifier: MIT + */ + +#include <Library/UefiBootServicesTableLib.h> +#include <Library/UefiLib.h> +#include <Library/HiiLib.h> +#include <Guid/MdeModuleHii.h> +#include "Data.h" + +extern UINT8 FormBin[]; + +EFI_HII_HANDLE mHiiHandle = NULL; + + +EFI_STATUS +EFIAPI +HIIFormLabelUnload ( + EFI_HANDLE ImageHandle + ) +{ + if (mHiiHandle != NULL) + HiiRemovePackages(mHiiHandle); + + return EFI_SUCCESS; +} + +EFI_STATUS +EFIAPI +HIIFormLabelEntryPoint ( + IN EFI_HANDLE ImageHandle, + IN EFI_SYSTEM_TABLE *SystemTable + ) +{ + mHiiHandle = HiiAddPackages( + &gEfiCallerIdGuid, + NULL, + HIIFormLabelStrings, + FormBin, + NULL + ); + if (mHiiHandle == NULL) { + return EFI_OUT_OF_RESOURCES; + } + + VOID* StartOpCodeHandle = HiiAllocateOpCodeHandle(); + EFI_IFR_GUID_LABEL* StartLabel = (EFI_IFR_GUID_LABEL*) HiiCreateGuidOpCode(StartOpCodeHandle, + &gEfiIfrTianoGuid, + NULL, + sizeof(EFI_IFR_GUID_LABEL) + ); + if (StartLabel == NULL) { + Print(L"Error! Can't create StartLabel opcode, not enough space\n"); + HiiRemovePackages(mHiiHandle); + return EFI_BUFFER_TOO_SMALL; + } + StartLabel->ExtendOpCode = EFI_IFR_EXTEND_OP_LABEL; + StartLabel->Number = LABEL_START; + + + VOID* EndOpCodeHandle = HiiAllocateOpCodeHandle(); + EFI_IFR_GUID_LABEL* EndLabel = (EFI_IFR_GUID_LABEL*) HiiCreateGuidOpCode(EndOpCodeHandle, + &gEfiIfrTianoGuid, + NULL, + sizeof(EFI_IFR_GUID_LABEL) + ); + if (EndLabel == NULL) { + Print(L"Error! Can't create EndLabel opcode, not enough space\n"); + HiiFreeOpCodeHandle(StartOpCodeHandle); + HiiFreeOpCodeHandle(EndOpCodeHandle); + HiiRemovePackages(mHiiHandle); + return EFI_BUFFER_TOO_SMALL; + } + + EndLabel->ExtendOpCode = EFI_IFR_EXTEND_OP_LABEL; + EndLabel->Number = LABEL_END; + + EFI_STRING_ID text_prompt = HiiSetString(mHiiHandle, + 0, + L"Text prompt", + NULL); + EFI_STRING_ID text_help = HiiSetString(mHiiHandle, + 0, + L"Text help", + NULL); + + + UINT8* Result = HiiCreateTextOpCode(StartOpCodeHandle, + text_prompt, + text_help, + 0); + if (Result == NULL) { + Print(L"Error! Can't create Text opcode, not enough space\n"); + HiiFreeOpCodeHandle(StartOpCodeHandle); + HiiFreeOpCodeHandle(EndOpCodeHandle); + HiiRemovePackages(mHiiHandle); + return EFI_BUFFER_TOO_SMALL; + } + + text_prompt = HiiSetString(mHiiHandle, + 0, + L"Another text prompt", + NULL); + text_help = HiiSetString(mHiiHandle, + 0, + L"Another text help", + NULL); + + Result = HiiCreateTextOpCode(StartOpCodeHandle, + text_prompt, + text_help, + 0); + if (Result == NULL) { + Print(L"Error! Can't create Text opcode, not enough space\n"); + HiiFreeOpCodeHandle(StartOpCodeHandle); + HiiFreeOpCodeHandle(EndOpCodeHandle); + HiiRemovePackages(mHiiHandle); + return EFI_BUFFER_TOO_SMALL; + } + + + + EFI_GUID formsetGuid = FORMSET_GUID; + EFI_STATUS Status = HiiUpdateForm( + mHiiHandle, + &formsetGuid, + 0x1, + StartOpCodeHandle, + EndOpCodeHandle + ); + if (EFI_ERROR(Status)) { + Print(L"Error! HiiUpdateForm returned = %r\n", Status); + } + + HiiFreeOpCodeHandle(StartOpCodeHandle); + HiiFreeOpCodeHandle(EndOpCodeHandle); + return Status; +} diff --git a/Lessons/Lesson_72/HIIFormLabel/HIIFormLabel.inf b/Lessons/Lesson_72/HIIFormLabel/HIIFormLabel.inf new file mode 100644 index 0000000..8ad87e0 --- /dev/null +++ b/Lessons/Lesson_72/HIIFormLabel/HIIFormLabel.inf @@ -0,0 +1,31 @@ +## +# Copyright (c) 2021, Konstantin Aladyshev <aladyshev22@gmail.com> +# +# SPDX-License-Identifier: MIT +## + +[Defines] + INF_VERSION = 1.25 + BASE_NAME = HIIFormLabel + FILE_GUID = a869c42c-fd49-469d-b6ab-b37569c0e90d + MODULE_TYPE = UEFI_DRIVER + VERSION_STRING = 1.0 + ENTRY_POINT = HIIFormLabelEntryPoint + UNLOAD_IMAGE = HIIFormLabelUnload + +[Sources] + HIIFormLabel.c + Strings.uni + Form.vfr + +[Packages] + MdePkg/MdePkg.dec + MdeModulePkg/MdeModulePkg.dec + +[LibraryClasses] + UefiDriverEntryPoint + UefiLib + HiiLib + +[Guids] + gEfiIfrTianoGuid diff --git a/Lessons/Lesson_72/HIIFormLabel/Strings.uni b/Lessons/Lesson_72/HIIFormLabel/Strings.uni new file mode 100644 index 0000000..8cb6b49 --- /dev/null +++ b/Lessons/Lesson_72/HIIFormLabel/Strings.uni @@ -0,0 +1,11 @@ +// +// Copyright (c) 2021, Konstantin Aladyshev <aladyshev22@gmail.com> +// +// 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" diff --git a/Lessons/Lesson_72/Label.png b/Lessons/Lesson_72/Label.png Binary files differnew file mode 100644 index 0000000..498d945 --- /dev/null +++ b/Lessons/Lesson_72/Label.png diff --git a/Lessons/Lesson_72/README.md b/Lessons/Lesson_72/README.md index 1993bf8..3d3de24 100644 --- a/Lessons/Lesson_72/README.md +++ b/Lessons/Lesson_72/README.md @@ -448,8 +448,13 @@ if (EndLabel == NULL) { EndLabel->ExtendOpCode = EFI_IFR_EXTEND_OP_LABEL; EndLabel->Number = LABEL_END; ``` +As we are using `gEfiIfrTianoGuid` here, don't forget to add `#include <Guid/MdeModuleHii.h>` to our code and add proper `Guids` section to the INF file: +``` +[Guids] + gEfiIfrTianoGuid +``` -We doing all of this to embed new code to the IFR. So besides the markers (=labels) we need to add new IFR codes to the buffer refernced by the `StartOpCodeHandle`. Let's add a VFR `text` element with a help of a `HiiCreateTextOpCode` function: +Our final task is to embed new code to the IFR. So besides the markers (=labels) we need to add actually new IFR codes to the buffer refernced by the `StartOpCodeHandle`. Let's add a VFR `text` element with a help of a `HiiCreateTextOpCode` function: ``` /** Create EFI_IFR_TEXT_OP opcode. @@ -532,7 +537,7 @@ EFI_STRING_ID text_help = HiiSetString(mHiiHandle, NULL); ``` -Now we can use `HiiCreateTextOpCode` function: +Now we can use `HiiCreateTextOpCode` function to add more opcodes to the opcode buffer refernced by `StartOpCodeHandle`: ``` UINT8* Result = HiiCreateTextOpCode(StartOpCodeHandle, text_prompt, @@ -547,7 +552,7 @@ if (Result == NULL) { } ``` - +Let's add another `text` element for our example. Once again the `HiiCreateTextOpCode` would use the same `StartOpCodeHandle`: ``` text_prompt = HiiSetString(mHiiHandle, 0, @@ -570,3 +575,58 @@ if (Result == NULL) { return EFI_BUFFER_TOO_SMALL; } ``` + +Now when we have `StartOpCodeHandle` and `EndOpCodeHandle` filled, `HiiUpdateForm` call should succeed. So let's build and load our driver. + +If you look at our form, you will see that now that it has 2 `text` elements like we have intended: + +![Label](Label.png?raw=true "Label") + +# `HIICreate*` + +In our example we've used `HiiCreateTextOpCode` function to create `EFI_IFR_TEXT_OP` opcode (i.e. `text` element). But `HiiLib` offers many functions to create all kinds of elements. Most of them we are already know: + +https://github.com/tianocore/edk2/blob/master/MdeModulePkg/Include/Library/HiiLib.h + +https://github.com/tianocore/edk2/blob/master/MdeModulePkg/Library/UefiHiiLib/HiiLib.c + +``` +HiiCreateSubTitleOpCode EFI_IFR_SUBTITLE_OP +HiiCreateCheckBoxOpCode EFI_IFR_CHECKBOX_OP +HiiCreateTextOpCode EFI_IFR_TEXT_OP +HiiCreateNumericOpCode EFI_IFR_NUMERIC_OP +HiiCreateStringOpCode EFI_IFR_STRING_OP +HiiCreateDateOpCode EFI_IFR_DATE_OP +HiiCreateTimeOpCode EFI_IFR_TIME_OP +HiiCreateOneOfOpCode EFI_IFR_ONE_OF_OP +HiiCreateOneOfOptionOpCode EFI_IFR_ONE_OF_OPTION_OP +HiiCreateOrderedListOpCode EFI_IFR_ORDERED_LIST_OP + +HiiCreateDefaultOpCode EFI_IFR_DEFAULT_OP +HiiCreateGuidOpCode EFI_IFR_GUID +HiiCreateActionOpCode EFI_IFR_ACTION_OP +HiiCreateGotoOpCode EFI_IFR_REF_OP +HiiCreateGotoExOpCode EFI_IFR_REF_OP, EFI_IFR_REF2_OP, EFI_IFR_REF3_OP and EFI_IFR_REF4_OP +HiiCreateEndOpCode EFI_IFR_END_OP +``` + +And if this is not enough for you `HiiLib` library has a function to add raw opcode buffer: +``` +/** + Append raw opcodes to an OpCodeHandle. + If OpCodeHandle is NULL, then ASSERT(). + If RawBuffer is NULL, then ASSERT(); + @param[in] OpCodeHandle Handle to the buffer of opcodes. + @param[in] RawBuffer Buffer of opcodes to append. + @param[in] RawBufferSize The size, in bytes, of Buffer. + @retval NULL There is not enough space left in Buffer to add the opcode. + @retval Other A pointer to the appended opcodes. +**/ +UINT8 * +EFIAPI +HiiCreateRawOpCodes ( + IN VOID *OpCodeHandle, + IN UINT8 *RawBuffer, + IN UINTN RawBufferSize + ) +``` diff --git a/Lessons/Lesson_72/UefiLessonsPkg/UefiLessonsPkg.dsc b/Lessons/Lesson_72/UefiLessonsPkg/UefiLessonsPkg.dsc new file mode 100644 index 0000000..b63f118 --- /dev/null +++ b/Lessons/Lesson_72/UefiLessonsPkg/UefiLessonsPkg.dsc @@ -0,0 +1,88 @@ +## +# Copyright (c) 2021, Konstantin Aladyshev <aladyshev22@gmail.com> +# +# 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 + UefiLessonsPkg/HIIFormDataElements/HIIFormDataElements.inf + UefiLessonsPkg/HIIFormLabel/HIIFormLabel.inf + +[PcdsFixedAtBuild] + gUefiLessonsPkgTokenSpaceGuid.PcdMyVar32_2|44 + |