aboutsummaryrefslogtreecommitdiffstats
path: root/Lessons/Lesson_61/UefiLessonsPkg
diff options
context:
space:
mode:
authorKonstantin Aladyshev <aladyshev22@gmail.com>2022-02-25 15:39:26 +0300
committerKonstantin Aladyshev <aladyshev22@gmail.com>2022-02-25 15:45:35 +0300
commitcf884399031c711205f837a5b65eeeb26fee3258 (patch)
treefdd7e34311adf1e33a5e753ecd02af260605d154 /Lessons/Lesson_61/UefiLessonsPkg
parent68b64507709c0b4e57c9dda6c096bfa4a35b5973 (diff)
downloadUEFI-Lessons-cf884399031c711205f837a5b65eeeb26fee3258.tar.gz
UEFI-Lessons-cf884399031c711205f837a5b65eeeb26fee3258.tar.bz2
UEFI-Lessons-cf884399031c711205f837a5b65eeeb26fee3258.zip
Add lesson 61
Signed-off-by: Konstantin Aladyshev <aladyshev22@gmail.com>
Diffstat (limited to 'Lessons/Lesson_61/UefiLessonsPkg')
-rw-r--r--Lessons/Lesson_61/UefiLessonsPkg/UefiLessonsPkg.dsc84
-rw-r--r--Lessons/Lesson_61/UefiLessonsPkg/UpdateDmpstoreDump/UpdateDmpstoreDump.c123
-rw-r--r--Lessons/Lesson_61/UefiLessonsPkg/UpdateDmpstoreDump/UpdateDmpstoreDump.inf26
3 files changed, 233 insertions, 0 deletions
diff --git a/Lessons/Lesson_61/UefiLessonsPkg/UefiLessonsPkg.dsc b/Lessons/Lesson_61/UefiLessonsPkg/UefiLessonsPkg.dsc
new file mode 100644
index 0000000..2180620
--- /dev/null
+++ b/Lessons/Lesson_61/UefiLessonsPkg/UefiLessonsPkg.dsc
@@ -0,0 +1,84 @@
+##
+# 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
+
+[PcdsFixedAtBuild]
+ gUefiLessonsPkgTokenSpaceGuid.PcdMyVar32_2|44
+
diff --git a/Lessons/Lesson_61/UefiLessonsPkg/UpdateDmpstoreDump/UpdateDmpstoreDump.c b/Lessons/Lesson_61/UefiLessonsPkg/UpdateDmpstoreDump/UpdateDmpstoreDump.c
new file mode 100644
index 0000000..e926514
--- /dev/null
+++ b/Lessons/Lesson_61/UefiLessonsPkg/UpdateDmpstoreDump/UpdateDmpstoreDump.c
@@ -0,0 +1,123 @@
+/*
+ * Copyright (c) 2021, Konstantin Aladyshev <aladyshev22@gmail.com>
+ *
+ * SPDX-License-Identifier: MIT
+ */
+
+#include <Library/UefiBootServicesTableLib.h>
+#include <Library/UefiLib.h>
+#include <Library/ShellLib.h>
+#include <Library/MemoryAllocationLib.h>
+
+VOID Usage()
+{
+ Print(L"Recalculate CRCs for dmpstore command dump\n");
+ Print(L"\n");
+ Print(L" UpdateDmpstoreDump <filename>\n");
+}
+
+INTN EFIAPI ShellAppMain(IN UINTN Argc, IN CHAR16 **Argv)
+{
+ if (Argc!=2) {
+ Usage();
+ return EFI_INVALID_PARAMETER;
+ }
+
+ SHELL_FILE_HANDLE FileHandle;
+
+ CHAR16* Filename = Argv[1];
+ EFI_STATUS Status = ShellOpenFileByName(
+ Filename,
+ &FileHandle,
+ EFI_FILE_MODE_WRITE | EFI_FILE_MODE_READ,
+ 0
+ );
+ if (EFI_ERROR(Status)) {
+ Print(L"Error! Can't open file %s\n", Filename);
+ return Status;
+ }
+
+ UINT64 FileSize;
+ Status = ShellGetFileSize(FileHandle, &FileSize);
+ if (EFI_ERROR(Status)) {
+ Status = ShellCloseFile(&FileHandle);
+ return SHELL_DEVICE_ERROR;
+ }
+
+ UINT64 FilePos = 0;
+ while (FilePos < FileSize) {
+ UINTN ToReadSize;
+ UINT32 NameSize;
+ ToReadSize = sizeof(NameSize);
+ Status = ShellReadFile(FileHandle, &ToReadSize, &NameSize);
+ if (EFI_ERROR(Status) || (ToReadSize != sizeof(NameSize))) {
+ Status = SHELL_VOLUME_CORRUPTED;
+ break;
+ }
+ FilePos += ToReadSize;
+
+ UINT32 DataSize;
+ ToReadSize = sizeof(DataSize);
+ Status = ShellReadFile(FileHandle, &ToReadSize, &DataSize);
+ if (EFI_ERROR(Status) || (ToReadSize != sizeof(DataSize))) {
+ Status = SHELL_VOLUME_CORRUPTED;
+ break;
+ }
+ FilePos += ToReadSize;
+
+ UINTN RemainingSize = NameSize +
+ sizeof(EFI_GUID) +
+ sizeof(UINT32) +
+ DataSize;
+ UINT8* Buffer = AllocatePool(sizeof(NameSize) + sizeof(DataSize) + RemainingSize);
+ if (Buffer == NULL) {
+ Status = SHELL_OUT_OF_RESOURCES;
+ break;
+ }
+
+ *(UINT32*)Buffer = NameSize;
+ *((UINT32*)Buffer + 1) = DataSize;
+
+ ToReadSize = RemainingSize;
+ Status = ShellReadFile(FileHandle, &ToReadSize, (UINT32*)Buffer + 2);
+ if (EFI_ERROR(Status) || (ToReadSize != RemainingSize)) {
+ Status = SHELL_VOLUME_CORRUPTED;
+ FreePool (Buffer);
+ break;
+ }
+ FilePos += ToReadSize;
+
+
+ UINT32 Crc32;
+ gBS->CalculateCrc32 (
+ Buffer,
+ sizeof(NameSize) + sizeof(DataSize) + RemainingSize,
+ &Crc32
+ );
+
+ UINTN ToWriteSize = sizeof(Crc32);
+ Status = ShellWriteFile(
+ FileHandle,
+ &ToWriteSize,
+ &Crc32
+ );
+ if (EFI_ERROR(Status) || (ToWriteSize != sizeof(Crc32))) {
+ Print(L"Error! Not all data was written\n");
+ FreePool(Buffer);
+ break;
+ }
+ FilePos += ToWriteSize;
+ FreePool(Buffer);
+ }
+
+ if (EFI_ERROR(Status)) {
+ Print(L"Error! %r\n", Status);
+ }
+
+ Status = ShellCloseFile(&FileHandle);
+ if (EFI_ERROR(Status)) {
+ Print(L"Can't close file: %r\n", Status);
+ }
+
+ return EFI_SUCCESS;
+}
diff --git a/Lessons/Lesson_61/UefiLessonsPkg/UpdateDmpstoreDump/UpdateDmpstoreDump.inf b/Lessons/Lesson_61/UefiLessonsPkg/UpdateDmpstoreDump/UpdateDmpstoreDump.inf
new file mode 100644
index 0000000..eef23cc
--- /dev/null
+++ b/Lessons/Lesson_61/UefiLessonsPkg/UpdateDmpstoreDump/UpdateDmpstoreDump.inf
@@ -0,0 +1,26 @@
+##
+# Copyright (c) 2021, Konstantin Aladyshev <aladyshev22@gmail.com>
+#
+# SPDX-License-Identifier: MIT
+##
+
+[Defines]
+ INF_VERSION = 1.25
+ BASE_NAME = UpdateDmpstoreDump
+ FILE_GUID = d14fe21b-7dbf-40ff-96cb-5d6f5b63cda6
+ MODULE_TYPE = UEFI_APPLICATION
+ VERSION_STRING = 1.0
+ ENTRY_POINT = ShellCEntryLib
+
+[Sources]
+ UpdateDmpstoreDump.c
+
+[Packages]
+ MdePkg/MdePkg.dec
+ ShellPkg/ShellPkg.dec
+
+[LibraryClasses]
+ UefiApplicationEntryPoint
+ UefiLib
+ ShellCEntryLib
+ ShellLib