aboutsummaryrefslogtreecommitdiffstats
path: root/Lessons
diff options
context:
space:
mode:
authorKonstantin Aladyshev <aladyshev22@gmail.com>2022-02-25 11:08:20 +0300
committerKonstantin Aladyshev <aladyshev22@gmail.com>2022-02-25 15:39:35 +0300
commit68b64507709c0b4e57c9dda6c096bfa4a35b5973 (patch)
tree13102afaa6aa47b2117da80d7b9c70681d9870fe /Lessons
parenta8d3afe27ff6fad28f0f7c756bc4f1bbeb9d13aa (diff)
downloadUEFI-Lessons-68b64507709c0b4e57c9dda6c096bfa4a35b5973.tar.gz
UEFI-Lessons-68b64507709c0b4e57c9dda6c096bfa4a35b5973.tar.bz2
UEFI-Lessons-68b64507709c0b4e57c9dda6c096bfa4a35b5973.zip
Add sources for lesson 60
Signed-off-by: Konstantin Aladyshev <aladyshev22@gmail.com>
Diffstat (limited to 'Lessons')
-rw-r--r--Lessons/Lesson_60/UefiLessonsPkg.dsc83
-rw-r--r--Lessons/Lesson_60/UefiLessonsPkg/SetVariableExample/SetVariableExample.c84
-rw-r--r--Lessons/Lesson_60/UefiLessonsPkg/SetVariableExample/SetVariableExample.inf24
3 files changed, 191 insertions, 0 deletions
diff --git a/Lessons/Lesson_60/UefiLessonsPkg.dsc b/Lessons/Lesson_60/UefiLessonsPkg.dsc
new file mode 100644
index 0000000..b33c87d
--- /dev/null
+++ b/Lessons/Lesson_60/UefiLessonsPkg.dsc
@@ -0,0 +1,83 @@
+##
+# 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
+
+[PcdsFixedAtBuild]
+ gUefiLessonsPkgTokenSpaceGuid.PcdMyVar32_2|44
+
diff --git a/Lessons/Lesson_60/UefiLessonsPkg/SetVariableExample/SetVariableExample.c b/Lessons/Lesson_60/UefiLessonsPkg/SetVariableExample/SetVariableExample.c
new file mode 100644
index 0000000..9c99e52
--- /dev/null
+++ b/Lessons/Lesson_60/UefiLessonsPkg/SetVariableExample/SetVariableExample.c
@@ -0,0 +1,84 @@
+/*
+ * Copyright (c) 2021, Konstantin Aladyshev <aladyshev22@gmail.com>
+ *
+ * SPDX-License-Identifier: MIT
+ */
+
+#include <Library/UefiBootServicesTableLib.h>
+#include <Library/UefiRuntimeServicesTableLib.h>
+#include <Library/UefiLib.h>
+
+
+VOID Usage()
+{
+ Print(L"Delete variable\n");
+ Print(L" SetVariableExample <variable name>\n");
+ Print(L"\n");
+ Print(L"Set variable\n");
+ Print(L" SetVariableExample <variable name> <attributes> <value>\n");
+ Print(L"\n");
+ Print(L"<attributes> can be <n|b|r>\n");
+ Print(L"n - NON_VOLATILE\n");
+ Print(L"b - BOOTSERVICE_ACCESS\n");
+ Print(L"r - RUNTIME_ACCESS\n");
+}
+
+INTN EFIAPI ShellAppMain(IN UINTN Argc, IN CHAR16 **Argv)
+{
+ EFI_STATUS Status;
+
+ if (Argc==2) {
+ CHAR16* VariableName = Argv[1];
+ Status = gRT->SetVariable (
+ VariableName,
+ &gEfiCallerIdGuid,
+ 0,
+ 0,
+ NULL
+ );
+ if (EFI_ERROR (Status)) {
+ Print(L"%r\n", Status);
+ } else {
+ Print(L"Variable %s was successfully deleted\n", VariableName);
+ }
+ return Status;
+ } else if (Argc==4) {
+ CHAR16* VariableName = Argv[1];
+ CHAR16* AttributesStr = Argv[2];
+ CHAR16* Value = Argv[3];
+ UINT32 Attributes = 0;
+ for (UINTN i=0; i<StrLen(AttributesStr); i++) {
+ switch(AttributesStr[i]) {
+ case L'n':
+ Attributes |= EFI_VARIABLE_NON_VOLATILE;
+ break;
+ case L'b':
+ Attributes |= EFI_VARIABLE_BOOTSERVICE_ACCESS;
+ break;
+ case L'r':
+ Attributes |= EFI_VARIABLE_RUNTIME_ACCESS;
+ break;
+ default:
+ Print(L"Error! Unknown attribute!");
+ return EFI_INVALID_PARAMETER;
+ }
+ }
+ Status = gRT->SetVariable (
+ VariableName,
+ &gEfiCallerIdGuid,
+ Attributes,
+ StrSize(Value),
+ Value
+ );
+ if (EFI_ERROR (Status)) {
+ Print(L"%r\n", Status);
+ } else {
+ Print(L"Variable %s was successfully changed\n", VariableName);
+ }
+ return Status;
+ } else {
+ Usage();
+ }
+
+ return EFI_SUCCESS;
+}
diff --git a/Lessons/Lesson_60/UefiLessonsPkg/SetVariableExample/SetVariableExample.inf b/Lessons/Lesson_60/UefiLessonsPkg/SetVariableExample/SetVariableExample.inf
new file mode 100644
index 0000000..948e49a
--- /dev/null
+++ b/Lessons/Lesson_60/UefiLessonsPkg/SetVariableExample/SetVariableExample.inf
@@ -0,0 +1,24 @@
+##
+# Copyright (c) 2021, Konstantin Aladyshev <aladyshev22@gmail.com>
+#
+# SPDX-License-Identifier: MIT
+##
+
+[Defines]
+ INF_VERSION = 1.25
+ BASE_NAME = SetVariableExample
+ FILE_GUID = bb2a829f-7943-4691-a03a-f1f48519d7e6
+ MODULE_TYPE = UEFI_APPLICATION
+ VERSION_STRING = 1.0
+ ENTRY_POINT = ShellCEntryLib
+
+[Sources]
+ SetVariableExample.c
+
+[Packages]
+ MdePkg/MdePkg.dec
+
+[LibraryClasses]
+ UefiApplicationEntryPoint
+ UefiLib
+ ShellCEntryLib