aboutsummaryrefslogtreecommitdiffstats
path: root/Lessons/Lesson_62/UefiLessonsPkg
diff options
context:
space:
mode:
Diffstat (limited to 'Lessons/Lesson_62/UefiLessonsPkg')
-rw-r--r--Lessons/Lesson_62/UefiLessonsPkg/DevicePath/DevicePath.c120
-rw-r--r--Lessons/Lesson_62/UefiLessonsPkg/DevicePath/DevicePath.inf23
-rw-r--r--Lessons/Lesson_62/UefiLessonsPkg/UefiLessonsPkg.dsc85
3 files changed, 228 insertions, 0 deletions
diff --git a/Lessons/Lesson_62/UefiLessonsPkg/DevicePath/DevicePath.c b/Lessons/Lesson_62/UefiLessonsPkg/DevicePath/DevicePath.c
new file mode 100644
index 0000000..e1f80fc
--- /dev/null
+++ b/Lessons/Lesson_62/UefiLessonsPkg/DevicePath/DevicePath.c
@@ -0,0 +1,120 @@
+/*
+ * Copyright (c) 2021, Konstantin Aladyshev <aladyshev22@gmail.com>
+ *
+ * SPDX-License-Identifier: MIT
+ */
+
+#include <Library/UefiBootServicesTableLib.h>
+#include <Library/UefiLib.h>
+
+#include <Library/DevicePathLib.h>
+#include <Library/MemoryAllocationLib.h>
+
+
+#define EXAMPLE_PCI_FUNCTION 5
+#define EXAMPLE_PCI_DEVICE 3
+
+#pragma pack(1)
+typedef struct {
+ PCI_DEVICE_PATH PciDevicePath;
+ EFI_DEVICE_PATH_PROTOCOL End;
+} FULL_PCI_DEVICE_PATH;
+#pragma pack()
+
+
+FULL_PCI_DEVICE_PATH PciDevicePathStatic = {
+ {
+ {
+ HARDWARE_DEVICE_PATH,
+ HW_PCI_DP,
+ {
+ (UINT8) (sizeof (PCI_DEVICE_PATH)),
+ (UINT8) ((sizeof (PCI_DEVICE_PATH)) >> 8)
+ }
+ },
+ EXAMPLE_PCI_FUNCTION,
+ EXAMPLE_PCI_DEVICE
+ },
+ {
+ END_DEVICE_PATH_TYPE,
+ END_ENTIRE_DEVICE_PATH_SUBTYPE,
+ {
+ (UINT8) (END_DEVICE_PATH_LENGTH),
+ (UINT8) ((END_DEVICE_PATH_LENGTH) >> 8)
+ }
+ }
+};
+
+
+EFI_STATUS
+EFIAPI
+UefiMain (
+ IN EFI_HANDLE ImageHandle,
+ IN EFI_SYSTEM_TABLE *SystemTable
+ )
+{
+ PCI_DEVICE_PATH PciDevicePathNodeStatic;
+ PciDevicePathNodeStatic.Header.Type = HARDWARE_DEVICE_PATH;
+ PciDevicePathNodeStatic.Header.SubType = HW_PCI_DP;
+ PciDevicePathNodeStatic.Header.Length[0] = sizeof(PCI_DEVICE_PATH);
+ PciDevicePathNodeStatic.Header.Length[1] = 0;
+ PciDevicePathNodeStatic.Function = EXAMPLE_PCI_FUNCTION;
+ PciDevicePathNodeStatic.Device = EXAMPLE_PCI_DEVICE;
+ Print(L"PciDevicePathNodeStatic: %s\n", ConvertDeviceNodeToText((EFI_DEVICE_PATH_PROTOCOL*) &PciDevicePathNodeStatic, FALSE, FALSE));
+
+ EFI_DEVICE_PATH_PROTOCOL* PciDevicePathNodeDynamic = CreateDeviceNode(HARDWARE_DEVICE_PATH, HW_PCI_DP, sizeof(PCI_DEVICE_PATH));
+ ((PCI_DEVICE_PATH*)PciDevicePathNodeDynamic)->Function = EXAMPLE_PCI_FUNCTION;
+ ((PCI_DEVICE_PATH*)PciDevicePathNodeDynamic)->Device = EXAMPLE_PCI_DEVICE;
+ Print(L"PciDevicePathNodeDynamic: %s\n", ConvertDeviceNodeToText((EFI_DEVICE_PATH_PROTOCOL*) PciDevicePathNodeDynamic, FALSE, FALSE));
+
+ Print(L"PciDevicePathStatic: %s\n", ConvertDevicePathToText((EFI_DEVICE_PATH_PROTOCOL*) &PciDevicePathStatic, FALSE, FALSE));
+
+ EFI_DEVICE_PATH_PROTOCOL* PciDevicePathDynamic = AppendDevicePathNode((EFI_DEVICE_PATH_PROTOCOL*)NULL, (EFI_DEVICE_PATH_PROTOCOL*)PciDevicePathNodeDynamic);
+ Print(L"PciDevicePathDynamic: %s\n", ConvertDevicePathToText((EFI_DEVICE_PATH_PROTOCOL*) PciDevicePathDynamic, FALSE, FALSE));
+
+
+ Print(L"_____________________\n\n");
+
+ EFI_DEVICE_PATH_PROTOCOL* PciDevicePathDynamicMulti;
+ EFI_DEVICE_PATH_PROTOCOL* TempPath;
+ PciDevicePathDynamicMulti = AppendDevicePathNode((EFI_DEVICE_PATH_PROTOCOL*)PciDevicePathDynamic, (EFI_DEVICE_PATH_PROTOCOL*)PciDevicePathNodeDynamic);
+ TempPath = PciDevicePathDynamicMulti;
+ PciDevicePathDynamicMulti = AppendDevicePathNode((EFI_DEVICE_PATH_PROTOCOL*)TempPath, (EFI_DEVICE_PATH_PROTOCOL*)PciDevicePathNodeDynamic);
+ FreePool(TempPath);
+ TempPath = PciDevicePathDynamicMulti;
+ PciDevicePathDynamicMulti = AppendDevicePathNode((EFI_DEVICE_PATH_PROTOCOL*)TempPath, (EFI_DEVICE_PATH_PROTOCOL*)PciDevicePathNodeDynamic);
+ FreePool(TempPath);
+ Print(L"Complicated DevicePath (AppendDevicePathNode): %s\n", ConvertDevicePathToText((EFI_DEVICE_PATH_PROTOCOL*) PciDevicePathDynamicMulti, FALSE, FALSE));
+
+ TempPath = PciDevicePathDynamicMulti;
+ PciDevicePathDynamicMulti = AppendDevicePath((EFI_DEVICE_PATH_PROTOCOL*)TempPath, (EFI_DEVICE_PATH_PROTOCOL*)TempPath);
+ FreePool(TempPath);
+ Print(L"Complicated DevicePath (AppendDevicePath): %s\n", ConvertDevicePathToText((EFI_DEVICE_PATH_PROTOCOL*) PciDevicePathDynamicMulti, FALSE, FALSE));
+
+
+ Print(L"_____________________\n\n");
+
+ EFI_DEVICE_PATH_PROTOCOL* TempDevicePathNode = PciDevicePathDynamicMulti;
+ UINT8 PciNodeCount = 0;
+ while (!IsDevicePathEnd(TempDevicePathNode)) {
+ if ( (DevicePathType(TempDevicePathNode) == HARDWARE_DEVICE_PATH) && (DevicePathSubType(TempDevicePathNode) == HW_PCI_DP) )
+ PciNodeCount++;
+ TempDevicePathNode = NextDevicePathNode(TempDevicePathNode);
+ }
+ Print(L"Last device path has %d PCI nodes\n", PciNodeCount);
+
+ Print(L"_____________________\n\n");
+
+ EFI_DEVICE_PATH_PROTOCOL* PciDevicePathNodeFromText = ConvertTextToDeviceNode(L"Pci(0x3,0x5)");
+ Print(L"PciDevicePathNodeFromText: %s\n", ConvertDeviceNodeToText((EFI_DEVICE_PATH_PROTOCOL*) PciDevicePathNodeFromText, FALSE, FALSE));
+ EFI_DEVICE_PATH_PROTOCOL* PciDevicePathFromText = ConvertTextToDevicePath(L"Pci(0x3,0x5)");
+ Print(L"PciDevicePathFromText: %s\n", ConvertDevicePathToText((EFI_DEVICE_PATH_PROTOCOL*) PciDevicePathFromText, FALSE, FALSE));
+
+ FreePool(PciDevicePathNodeDynamic);
+ FreePool(PciDevicePathDynamic);
+ FreePool(PciDevicePathNodeFromText);
+ FreePool(PciDevicePathFromText);
+ FreePool(PciDevicePathDynamicMulti);
+
+ return EFI_SUCCESS;
+}
diff --git a/Lessons/Lesson_62/UefiLessonsPkg/DevicePath/DevicePath.inf b/Lessons/Lesson_62/UefiLessonsPkg/DevicePath/DevicePath.inf
new file mode 100644
index 0000000..3c5bf45
--- /dev/null
+++ b/Lessons/Lesson_62/UefiLessonsPkg/DevicePath/DevicePath.inf
@@ -0,0 +1,23 @@
+##
+# Copyright (c) 2021, Konstantin Aladyshev <aladyshev22@gmail.com>
+#
+# SPDX-License-Identifier: MIT
+##
+
+[Defines]
+ INF_VERSION = 1.25
+ BASE_NAME = DevicePath
+ FILE_GUID = f93d7d15-057a-442e-a8a5-fcb19d909989
+ MODULE_TYPE = UEFI_APPLICATION
+ VERSION_STRING = 1.0
+ ENTRY_POINT = UefiMain
+
+[Sources]
+ DevicePath.c
+
+[Packages]
+ MdePkg/MdePkg.dec
+
+[LibraryClasses]
+ UefiApplicationEntryPoint
+ UefiLib
diff --git a/Lessons/Lesson_62/UefiLessonsPkg/UefiLessonsPkg.dsc b/Lessons/Lesson_62/UefiLessonsPkg/UefiLessonsPkg.dsc
new file mode 100644
index 0000000..d94d78c
--- /dev/null
+++ b/Lessons/Lesson_62/UefiLessonsPkg/UefiLessonsPkg.dsc
@@ -0,0 +1,85 @@
+##
+# 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
+
+[PcdsFixedAtBuild]
+ gUefiLessonsPkgTokenSpaceGuid.PcdMyVar32_2|44
+