diff options
Diffstat (limited to 'Lessons/Lesson_72/HIIFormLabel')
-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 |
5 files changed, 205 insertions, 0 deletions
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" |