aboutsummaryrefslogtreecommitdiffstats
path: root/UefiLessonsPkg
diff options
context:
space:
mode:
authorKonstantin Aladyshev <aladyshev22@gmail.com>2021-07-12 13:04:07 +0300
committerKonstantin Aladyshev <aladyshev22@gmail.com>2021-07-12 13:06:10 +0300
commitea5d514727e1b9abcc4558e62ca9311755937a5d (patch)
tree7d09250b31bfaaff0d028b75268fd9d336a093c5 /UefiLessonsPkg
parent7d9311124853be51b5a65f41daa7bee0f37bf2ba (diff)
downloadUEFI-Lessons-ea5d514727e1b9abcc4558e62ca9311755937a5d.tar.gz
UEFI-Lessons-ea5d514727e1b9abcc4558e62ca9311755937a5d.tar.bz2
UEFI-Lessons-ea5d514727e1b9abcc4558e62ca9311755937a5d.zip
Add 'UefiLessonsPkg' folder to the repo
Signed-off-by: Konstantin Aladyshev <aladyshev22@gmail.com>
Diffstat (limited to 'UefiLessonsPkg')
-rw-r--r--UefiLessonsPkg/AcpiInfo/AcpiInfo.c69
-rw-r--r--UefiLessonsPkg/AcpiInfo/AcpiInfo.inf21
-rw-r--r--UefiLessonsPkg/HelloWorld/HelloWorld.c19
-rw-r--r--UefiLessonsPkg/HelloWorld/HelloWorld.inf18
-rw-r--r--UefiLessonsPkg/ImageHandle/ImageHandle.c105
-rw-r--r--UefiLessonsPkg/ImageHandle/ImageHandle.inf18
-rw-r--r--UefiLessonsPkg/ImageInfo/ImageInfo.c44
-rw-r--r--UefiLessonsPkg/ImageInfo/ImageInfo.inf22
-rw-r--r--UefiLessonsPkg/InteractiveApp/InteractiveApp.c34
-rw-r--r--UefiLessonsPkg/InteractiveApp/InteractiveApp.inf18
-rw-r--r--UefiLessonsPkg/ListPCI/ListPCI.c267
-rw-r--r--UefiLessonsPkg/ListPCI/ListPCI.c:Zone.Identifierbin0 -> 27 bytes
-rw-r--r--UefiLessonsPkg/ListPCI/ListPCI.inf22
-rw-r--r--UefiLessonsPkg/ListPCI/ListPCI.inf:Zone.Identifierbin0 -> 27 bytes
-rw-r--r--UefiLessonsPkg/ListVariables/ListVariables.c46
-rw-r--r--UefiLessonsPkg/ListVariables/ListVariables.inf19
-rw-r--r--UefiLessonsPkg/MemoryInfo/MemoryInfo.c215
-rw-r--r--UefiLessonsPkg/MemoryInfo/MemoryInfo.inf21
-rw-r--r--UefiLessonsPkg/PCDLesson/PCDLesson.c43
-rw-r--r--UefiLessonsPkg/PCDLesson/PCDLesson.inf39
-rw-r--r--UefiLessonsPkg/ShowBootVariables/ShowBootVariables.c93
-rw-r--r--UefiLessonsPkg/ShowBootVariables/ShowBootVariables.inf19
-rw-r--r--UefiLessonsPkg/ShowHii/ShowHii.c120
-rw-r--r--UefiLessonsPkg/ShowHii/ShowHii.inf22
-rw-r--r--UefiLessonsPkg/SimpleDriver/SimpleDriver.c26
-rw-r--r--UefiLessonsPkg/SimpleDriver/SimpleDriver.inf19
-rw-r--r--UefiLessonsPkg/SimpleShellApp/SimpleShellApp.c14
-rw-r--r--UefiLessonsPkg/SimpleShellApp/SimpleShellApp.inf19
-rw-r--r--UefiLessonsPkg/SimplestApp/SimplestApp.c10
-rw-r--r--UefiLessonsPkg/SimplestApp/SimplestApp.inf16
-rw-r--r--UefiLessonsPkg/SmbiosInfo/SmbiosInfo.c88
-rw-r--r--UefiLessonsPkg/SmbiosInfo/SmbiosInfo.inf24
-rw-r--r--UefiLessonsPkg/UefiLessonsPkg.dec35
-rw-r--r--UefiLessonsPkg/UefiLessonsPkg.dsc63
34 files changed, 1608 insertions, 0 deletions
diff --git a/UefiLessonsPkg/AcpiInfo/AcpiInfo.c b/UefiLessonsPkg/AcpiInfo/AcpiInfo.c
new file mode 100644
index 0000000..88c78b6
--- /dev/null
+++ b/UefiLessonsPkg/AcpiInfo/AcpiInfo.c
@@ -0,0 +1,69 @@
+#include <Library/UefiBootServicesTableLib.h>
+#include <Library/UefiLib.h>
+
+#include <Library/BaseMemoryLib.h>
+
+EFI_STATUS
+EFIAPI
+UefiMain (
+ IN EFI_HANDLE ImageHandle,
+ IN EFI_SYSTEM_TABLE *SystemTable
+ )
+{
+ EFI_ACPI_6_3_ROOT_SYSTEM_DESCRIPTION_POINTER* RSDP = NULL;
+
+ for (UINTN i=0; i<SystemTable->NumberOfTableEntries; i++) {
+ if (CompareGuid(&(SystemTable->ConfigurationTable[i].VendorGuid), &gEfiAcpi20TableGuid)) {
+ Print(L"RSDP table is placed at %p\n\n", SystemTable->ConfigurationTable[i].VendorTable);
+ RSDP = SystemTable->ConfigurationTable[i].VendorTable;
+ }
+ }
+
+ if (!RSDP) {
+ Print(L"No ACPI2.0 table was found in the system\n");
+ return EFI_SUCCESS;
+ }
+
+ if (((CHAR8)((RSDP->Signature >> 0) & 0xFF) != 'R') ||
+ ((CHAR8)((RSDP->Signature >> 8) & 0xFF) != 'S') ||
+ ((CHAR8)((RSDP->Signature >> 16) & 0xFF) != 'D') ||
+ ((CHAR8)((RSDP->Signature >> 24) & 0xFF) != ' ') ||
+ ((CHAR8)((RSDP->Signature >> 32) & 0xFF) != 'P') ||
+ ((CHAR8)((RSDP->Signature >> 40) & 0xFF) != 'T') ||
+ ((CHAR8)((RSDP->Signature >> 48) & 0xFF) != 'R') ||
+ ((CHAR8)((RSDP->Signature >> 56) & 0xFF) != ' ')) {
+ Print(L"Error! RSDP signature is not valid!\n");
+ return EFI_SUCCESS;
+ }
+
+ Print(L"System description tables:\n");
+ Print(L"\tRSDT table is placed at address %p\n", RSDP->RsdtAddress);
+ Print(L"\tXSDT table is placed at address %p\n", RSDP->XsdtAddress);
+ Print(L"\n");
+
+ EFI_ACPI_DESCRIPTION_HEADER* XSDT = (EFI_ACPI_DESCRIPTION_HEADER*)RSDP->XsdtAddress;
+ if (((CHAR8)((XSDT->Signature >> 0) & 0xFF) != 'X') ||
+ ((CHAR8)((XSDT->Signature >> 8) & 0xFF) != 'S') ||
+ ((CHAR8)((XSDT->Signature >> 16) & 0xFF) != 'D') ||
+ ((CHAR8)((XSDT->Signature >> 24) & 0xFF) != 'T')) {
+ Print(L"Error! XSDT signature is not valid!\n");
+ return EFI_SUCCESS;
+ }
+
+ Print(L"Main ACPI tables:\n");
+ UINT64 offset = sizeof(EFI_ACPI_DESCRIPTION_HEADER);
+ while (offset < XSDT->Length) {
+ UINT64* table_address = (UINT64*)((UINT8*)XSDT + offset);
+ EFI_ACPI_6_3_COMMON_HEADER* table = (EFI_ACPI_6_3_COMMON_HEADER*)(*table_address);
+ Print(L"\t%c%c%c%c table is placed at address %p with length 0x%x\n",
+ (CHAR8)((table->Signature>> 0)&0xFF),
+ (CHAR8)((table->Signature>> 8)&0xFF),
+ (CHAR8)((table->Signature>>16)&0xFF),
+ (CHAR8)((table->Signature>>24)&0xFF),
+ table,
+ table->Length);
+ offset += sizeof(UINT64);
+ }
+
+ return EFI_SUCCESS;
+}
diff --git a/UefiLessonsPkg/AcpiInfo/AcpiInfo.inf b/UefiLessonsPkg/AcpiInfo/AcpiInfo.inf
new file mode 100644
index 0000000..3884e76
--- /dev/null
+++ b/UefiLessonsPkg/AcpiInfo/AcpiInfo.inf
@@ -0,0 +1,21 @@
+[Defines]
+ INF_VERSION = 1.25
+ BASE_NAME = AcpiInfo
+ FILE_GUID = 18998798-69a2-4ab5-9ffc-a8ee2494b029
+ MODULE_TYPE = UEFI_APPLICATION
+ VERSION_STRING = 1.0
+ ENTRY_POINT = UefiMain
+
+[Sources]
+ AcpiInfo.c
+
+[Packages]
+ MdePkg/MdePkg.dec
+
+[LibraryClasses]
+ UefiApplicationEntryPoint
+ UefiLib
+
+[Guids]
+ gEfiAcpi20TableGuid
+
diff --git a/UefiLessonsPkg/HelloWorld/HelloWorld.c b/UefiLessonsPkg/HelloWorld/HelloWorld.c
new file mode 100644
index 0000000..29a4812
--- /dev/null
+++ b/UefiLessonsPkg/HelloWorld/HelloWorld.c
@@ -0,0 +1,19 @@
+#include <Library/UefiBootServicesTableLib.h>
+#include <Library/UefiLib.h>
+
+EFI_STATUS
+EFIAPI
+UefiMain (
+ IN EFI_HANDLE ImageHandle,
+ IN EFI_SYSTEM_TABLE *SystemTable
+ )
+{
+ SystemTable->ConOut->OutputString(SystemTable->ConOut, L"Hello World!\n");
+ gST->ConOut->OutputString(gST->ConOut, L"Hello again!\n");
+ Print(L"Bye!\n");
+
+ UINTN Index;
+ gBS->WaitForEvent(1, &(gST->ConIn->WaitForKey), &Index);
+ gST->ConIn->Reset(gST->ConIn, FALSE);
+ return EFI_SUCCESS;
+}
diff --git a/UefiLessonsPkg/HelloWorld/HelloWorld.inf b/UefiLessonsPkg/HelloWorld/HelloWorld.inf
new file mode 100644
index 0000000..d65ca2e
--- /dev/null
+++ b/UefiLessonsPkg/HelloWorld/HelloWorld.inf
@@ -0,0 +1,18 @@
+[Defines]
+ INF_VERSION = 1.25
+ BASE_NAME = HelloWorld
+ FILE_GUID = 2e55fa38-f148-42d3-af90-1be247323e30
+ MODULE_TYPE = UEFI_APPLICATION
+ VERSION_STRING = 1.0
+ ENTRY_POINT = UefiMain
+
+[Sources]
+ HelloWorld.c
+
+[Packages]
+ MdePkg/MdePkg.dec
+
+[LibraryClasses]
+ UefiApplicationEntryPoint
+ UefiLib
+
diff --git a/UefiLessonsPkg/ImageHandle/ImageHandle.c b/UefiLessonsPkg/ImageHandle/ImageHandle.c
new file mode 100644
index 0000000..32e9c43
--- /dev/null
+++ b/UefiLessonsPkg/ImageHandle/ImageHandle.c
@@ -0,0 +1,105 @@
+#include <Library/MemoryAllocationLib.h>
+#include <Library/UefiBootServicesTableLib.h>
+#include <Library/UefiLib.h>
+
+typedef struct {
+ UINTN Signature;
+ /// All handles list of IHANDLE
+ LIST_ENTRY AllHandles;
+ /// List of PROTOCOL_INTERFACE's for this handle
+ LIST_ENTRY Protocols;
+ UINTN LocateRequest;
+ /// The Handle Database Key value when this handle was last created or modified
+ UINT64 Key;
+} IHANDLE;
+
+typedef struct {
+ UINTN Signature;
+ /// Link Entry inserted to mProtocolDatabase
+ LIST_ENTRY AllEntries;
+ /// ID of the protocol
+ EFI_GUID ProtocolID;
+ /// All protocol interfaces
+ LIST_ENTRY Protocols;
+ /// Registerd notification handlers
+ LIST_ENTRY Notify;
+} PROTOCOL_ENTRY;
+
+typedef struct {
+ UINTN Signature;
+ /// Link on IHANDLE.Protocols
+ LIST_ENTRY Link;
+ /// Back pointer
+ IHANDLE *Handle;
+ /// Link on PROTOCOL_ENTRY.Protocols
+ LIST_ENTRY ByProtocol;
+ /// The protocol ID
+ PROTOCOL_ENTRY *Protocol;
+ /// The interface value
+ VOID *Interface;
+ /// OPEN_PROTOCOL_DATA list
+ LIST_ENTRY OpenList;
+ UINTN OpenListCount;
+
+} PROTOCOL_INTERFACE;
+
+
+#define offsetof(a,b) ((INTN)(&(((a*)(0))->b)))
+
+#define container_of(ptr, type, member) ({ \
+ const typeof( ((type *)0)->member ) *__mptr = (ptr); \
+ (type *)( (char *)__mptr - offsetof(type,member) );})
+
+EFI_STATUS
+EFIAPI
+UefiMain (
+ IN EFI_HANDLE ImageHandle,
+ IN EFI_SYSTEM_TABLE *SystemTable
+ )
+{
+ IHANDLE* MyHandle = ImageHandle;
+ Print(L"Signature: %c %c %c %c\n", (MyHandle->Signature >> 0) & 0xff,
+ (MyHandle->Signature >> 8) & 0xff,
+ (MyHandle->Signature >> 16) & 0xff,
+ (MyHandle->Signature >> 24) & 0xff);
+
+ Print(L"Back Protocol Interface Link: %p\n", MyHandle->Protocols.BackLink);
+ Print(L"Forward Protocol Interface Link: %p\n", MyHandle->Protocols.ForwardLink);
+
+ LIST_ENTRY *FirstLink = MyHandle->Protocols.ForwardLink;
+ LIST_ENTRY *CurrentLink = FirstLink;
+ do {
+ PROTOCOL_INTERFACE* MyProtocolInterface = container_of(CurrentLink, PROTOCOL_INTERFACE, Link);
+
+ Print(L"\n");
+ Print(L"Current Link: %p\n", CurrentLink);
+ Print(L"Signature: %x %x %x %x\n", (MyProtocolInterface->Signature >> 0) & 0xff,
+ (MyProtocolInterface->Signature >> 8) & 0xff,
+ (MyProtocolInterface->Signature >> 16) & 0xff,
+ (MyProtocolInterface->Signature >> 24) & 0xff);
+
+ Print(L"Back Link: %p\n", MyProtocolInterface->Link.BackLink);
+ Print(L"Forward Link: %p\n", MyProtocolInterface->Link.ForwardLink);
+ Print(L"GUID=%g\n", MyProtocolInterface->Protocol->ProtocolID);
+ CurrentLink = MyProtocolInterface->Link.ForwardLink;
+ } while (CurrentLink != FirstLink);
+
+ Print(L"________\n");
+ EFI_GUID **ProtocolGuidArray;
+ UINTN ArrayCount;
+ //EFI_STATUS Status = gBS->ProtocolsPerHandle(NULL, // Use this to test %r Print formatting option
+ EFI_STATUS Status = gBS->ProtocolsPerHandle(ImageHandle,
+ &ProtocolGuidArray,
+ &ArrayCount);
+
+ if (!EFI_ERROR(Status)) {
+ for (int i=0; i<ArrayCount; i++) {
+ Print(L"%g\n", ProtocolGuidArray[i]);
+ }
+ FreePool(ProtocolGuidArray);
+ } else {
+ Print(L"ProtocolsPerHandle error: %r\n", Status);
+ }
+
+ return EFI_SUCCESS;
+}
diff --git a/UefiLessonsPkg/ImageHandle/ImageHandle.inf b/UefiLessonsPkg/ImageHandle/ImageHandle.inf
new file mode 100644
index 0000000..34256ee
--- /dev/null
+++ b/UefiLessonsPkg/ImageHandle/ImageHandle.inf
@@ -0,0 +1,18 @@
+[Defines]
+ INF_VERSION = 1.25
+ BASE_NAME = ImageHandle
+ FILE_GUID = b68d3472-70c7-4928-841b-6566032e0a23
+ MODULE_TYPE = UEFI_APPLICATION
+ VERSION_STRING = 1.0
+ ENTRY_POINT = UefiMain
+
+[Sources]
+ ImageHandle.c
+
+[Packages]
+ MdePkg/MdePkg.dec
+
+[LibraryClasses]
+ UefiApplicationEntryPoint
+ UefiLib
+
diff --git a/UefiLessonsPkg/ImageInfo/ImageInfo.c b/UefiLessonsPkg/ImageInfo/ImageInfo.c
new file mode 100644
index 0000000..c45570e
--- /dev/null
+++ b/UefiLessonsPkg/ImageInfo/ImageInfo.c
@@ -0,0 +1,44 @@
+#include <Library/UefiBootServicesTableLib.h>
+#include <Library/UefiLib.h>
+
+#include <Protocol/LoadedImage.h>
+#include <Library/DevicePathLib.h>
+
+EFI_STATUS
+EFIAPI
+UefiMain (
+ IN EFI_HANDLE ImageHandle,
+ IN EFI_SYSTEM_TABLE *SystemTable
+ )
+{
+ EFI_STATUS Status;
+ EFI_LOADED_IMAGE_PROTOCOL* LoadedImage;
+
+ Status = gBS->HandleProtocol(
+ ImageHandle,
+ &gEfiLoadedImageProtocolGuid,
+ (VOID **) &LoadedImage
+ );
+
+ if (Status == EFI_SUCCESS) {
+ EFI_DEVICE_PATH_PROTOCOL* DevicePath;
+
+ Status = gBS->HandleProtocol(
+ ImageHandle,
+ &gEfiLoadedImageDevicePathProtocolGuid,
+ (VOID**) &DevicePath
+ );
+
+ if (Status == EFI_SUCCESS) {
+ Print(L"Image device: %s\n", ConvertDevicePathToText(DevicePath, FALSE, TRUE));
+ Print(L"Image file: %s\n", ConvertDevicePathToText(LoadedImage->FilePath, FALSE, TRUE)); // EFI_DEVICE_PATH_PROTOCOL *FilePath
+ Print(L"Image Base: %X\n", LoadedImage->ImageBase);
+ Print(L"Image Size: %X\n", LoadedImage->ImageSize);
+ } else {
+ Print(L"Can't get EFI_LOADED_IMAGE_PROTOCOL, Status=%r\n", Status);
+ }
+ } else {
+ Print(L"Can't get EFI_DEVICE_PATH_PROTOCOL, Status=%r\n", Status);
+ }
+ return EFI_SUCCESS;
+}
diff --git a/UefiLessonsPkg/ImageInfo/ImageInfo.inf b/UefiLessonsPkg/ImageInfo/ImageInfo.inf
new file mode 100644
index 0000000..0ce54a6
--- /dev/null
+++ b/UefiLessonsPkg/ImageInfo/ImageInfo.inf
@@ -0,0 +1,22 @@
+[Defines]
+ INF_VERSION = 1.25
+ BASE_NAME = ImageInfo
+ FILE_GUID = b68d3472-70c7-4928-841b-6566032e0a23
+ MODULE_TYPE = UEFI_APPLICATION
+ VERSION_STRING = 1.0
+ ENTRY_POINT = UefiMain
+
+[Sources]
+ ImageInfo.c
+
+[Packages]
+ MdePkg/MdePkg.dec
+
+[LibraryClasses]
+ UefiApplicationEntryPoint
+ UefiLib
+
+[Protocols]
+ gEfiLoadedImageProtocolGuid
+ gEfiLoadedImageDevicePathProtocolGuid
+
diff --git a/UefiLessonsPkg/InteractiveApp/InteractiveApp.c b/UefiLessonsPkg/InteractiveApp/InteractiveApp.c
new file mode 100644
index 0000000..59c89a9
--- /dev/null
+++ b/UefiLessonsPkg/InteractiveApp/InteractiveApp.c
@@ -0,0 +1,34 @@
+#include <Library/UefiBootServicesTableLib.h>
+#include <Library/UefiLib.h>
+
+EFI_STATUS
+EFIAPI
+UefiMain (
+ IN EFI_HANDLE ImageHandle,
+ IN EFI_SYSTEM_TABLE *SystemTable
+ )
+{
+ UINTN Index;
+ EFI_INPUT_KEY Key;
+
+ Print(L"Try to guess the secret symbol!\n");
+ Print(L"To quit press 'q'\n");
+
+ while(TRUE) {
+ gBS->WaitForEvent(1, &(gST->ConIn->WaitForKey), &Index);
+ gST->ConIn->ReadKeyStroke(gST->ConIn, &Key);
+ Print(L"ScanCode = %04x, UnicodeChar = %04x (%c)\n", Key.ScanCode, Key.UnicodeChar, Key.UnicodeChar);
+
+ if (Key.UnicodeChar == 'k') {
+ Print(L"Correct!\n");
+ break;
+ } else if (Key.UnicodeChar == 'q') {
+ Print(L"Bye!\n");
+ break;
+ } else {
+ Print(L"Wrong!\n");
+ }
+ }
+ gST->ConIn->Reset(gST->ConIn, FALSE);
+ return EFI_SUCCESS;
+}
diff --git a/UefiLessonsPkg/InteractiveApp/InteractiveApp.inf b/UefiLessonsPkg/InteractiveApp/InteractiveApp.inf
new file mode 100644
index 0000000..700b779
--- /dev/null
+++ b/UefiLessonsPkg/InteractiveApp/InteractiveApp.inf
@@ -0,0 +1,18 @@
+[Defines]
+ INF_VERSION = 1.25
+ BASE_NAME = InteractiveApp
+ FILE_GUID = 1539451b-f300-41fa-a565-dde69c1bed66
+ MODULE_TYPE = UEFI_APPLICATION
+ VERSION_STRING = 1.0
+ ENTRY_POINT = UefiMain
+
+[Sources]
+ InteractiveApp.c
+
+[Packages]
+ MdePkg/MdePkg.dec
+
+[LibraryClasses]
+ UefiApplicationEntryPoint
+ UefiLib
+
diff --git a/UefiLessonsPkg/ListPCI/ListPCI.c b/UefiLessonsPkg/ListPCI/ListPCI.c
new file mode 100644
index 0000000..6eb2eef
--- /dev/null
+++ b/UefiLessonsPkg/ListPCI/ListPCI.c
@@ -0,0 +1,267 @@
+#include <Library/UefiBootServicesTableLib.h>
+#include <Library/UefiLib.h>
+
+#include <Protocol/PciRootBridgeIo.h>
+#include <Library/MemoryAllocationLib.h>
+#include <IndustryStandard/Pci.h>
+#include <Library/ShellLib.h>
+#include <Library/PrintLib.h>
+
+
+#define DESCRIPTOR_STR_MAX_SIZE 200
+#define BLOCK_READ_SIZE (1024*4)
+
+VOID ToLowerASCII(CHAR8* Str, UINTN Size)
+{
+ for (UINT8 i=0; i<Size; i++) {
+ if ((Str[i]>='A')&&(Str[i]<='Z')) {
+ Str[i]+=32;
+ }
+ }
+}
+
+EFI_STATUS FindPCIDevDescription(UINT16 VendorId,
+ UINT16 DeviceId,
+ CHAR16* VendorDesc,
+ CHAR16* DeviceDesc,
+ UINTN DescBufferSize)
+{
+ EFI_STATUS Status = ShellFileExists(L"pci.ids");
+ if (EFI_ERROR(Status))
+ {
+ Print(L"No file pci.ids: %r\n", Status);
+ return Status;
+ }
+
+ SHELL_FILE_HANDLE FileHandle;
+ Status = ShellOpenFileByName(L"pci.ids",
+ &FileHandle,
+ EFI_FILE_MODE_READ,
+ 0);
+ if (EFI_ERROR(Status))
+ {
+ Print(L"Can't open file pci.ids: %r\n", Status);
+ return Status;
+ }
+
+ UINT64 FileSize;
+ Status = ShellGetFileSize(FileHandle, &FileSize);
+ if (EFI_ERROR(Status))
+ {
+ Print(L"Can't get file size for file pci.ids: %r\n", Status);
+ goto end;
+ }
+
+ CHAR8 VendorStr[5];
+ CHAR8 DeviceStr[5];
+ AsciiValueToStringS(VendorStr,
+ 5,
+ RADIX_HEX | PREFIX_ZERO,
+ VendorId,
+ 4);
+ AsciiValueToStringS(DeviceStr,
+ 5,
+ RADIX_HEX | PREFIX_ZERO,
+ DeviceId,
+ 4);
+ ToLowerASCII(VendorStr, 4);
+ ToLowerASCII(DeviceStr, 4);
+
+ CHAR8 Buffer[BLOCK_READ_SIZE];
+ UINTN Size;
+ UINT64 FilePos = 0;
+ BOOLEAN Vendor_found = FALSE;
+ BOOLEAN Device_found = FALSE;
+ while (TRUE)
+ {
+ Size = BLOCK_READ_SIZE;
+ Status = ShellReadFile(FileHandle, &Size, Buffer);
+ if (EFI_ERROR(Status))
+ {
+ Print(L"Can't read file pci.ids: %r\n", Status);
+ goto end;
+ }
+ UINTN StrStart = 0;
+ UINTN StrEnd = 0;
+ for (UINTN i=0; i<Size; i++) {
+ if (Buffer[i]=='\n') {
+ StrEnd=i;
+ if (!Vendor_found){
+ // 0123456 7
+ //\nXXXX |<desc>|\n
+ if ((StrEnd - StrStart) > 7) {
+ if ((Buffer[StrStart+1]==VendorStr[0]) &&
+ (Buffer[StrStart+2]==VendorStr[1]) &&
+ (Buffer[StrStart+3]==VendorStr[2]) &&
+ (Buffer[StrStart+4]==VendorStr[3])) {
+ Buffer[StrEnd] = 0;
+ UnicodeSPrintAsciiFormat(VendorDesc, DescBufferSize, "%a", &Buffer[StrStart+1+4+2]);
+ Vendor_found = TRUE;
+ }
+ }
+ } else {
+ // 0 1234567 8
+ //\n\tXXXX |<desc>|\n
+ if ((StrEnd - StrStart) > 8) {
+ if ((Buffer[StrStart+1]=='\t') &&
+ (Buffer[StrStart+2]==DeviceStr[0]) &&
+ (Buffer[StrStart+3]==DeviceStr[1]) &&
+ (Buffer[StrStart+4]==DeviceStr[2]) &&
+ (Buffer[StrStart+5]==DeviceStr[3])) {
+ Buffer[StrEnd] = 0;
+ UnicodeSPrintAsciiFormat(DeviceDesc, DescBufferSize, "%a", &Buffer[StrStart+1+1+4+2]);
+ Device_found = TRUE;
+ break;
+ }
+ }
+ }
+ StrStart = StrEnd;
+ }
+ }
+
+ if (FilePos+Size >= FileSize) {
+ break;
+ }
+ FilePos += StrEnd;
+ Status = ShellSetFilePosition(FileHandle, FilePos);
+ if (EFI_ERROR(Status))
+ {
+ Print(L"Can't set file position pci.ids: %r\n", Status);
+ goto end;
+ }
+ }
+
+end:
+ if (!Vendor_found) {
+ UnicodeSPrint(VendorDesc, DescBufferSize, L"Undefined");
+ }
+ if (!Device_found) {
+ UnicodeSPrint(DeviceDesc, DescBufferSize, L"Undefined");
+ }
+ ShellCloseFile(&FileHandle);
+
+ return Status;
+}
+
+
+UINT64 PciConfigurationAddress(UINT8 Bus,
+ UINT8 Device,
+ UINT8 Function,
+ UINT32 Register)
+{
+ UINT64 Address = (((UINT64)Bus) << 24) + (((UINT64)Device) << 16) + (((UINT64)Function) << 8);
+ if (Register & 0xFFFFFF00) {
+ Address += (((UINT64)Register) << 32);
+ } else {
+ Address += (((UINT64)Register) << 0);
+ }
+ return Address;
+}
+
+
+EFI_STATUS PrintRootBridge(EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL* PciRootBridgeIo)
+{
+ EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR* AddressDescriptor;
+ EFI_STATUS Status = PciRootBridgeIo->Configuration(
+ PciRootBridgeIo,
+ (VOID**)&AddressDescriptor
+ );
+ if (EFI_ERROR(Status)) {
+ Print(L"\tError! Can't get EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR: %r\n", Status);
+ return Status;
+ }
+ while (AddressDescriptor->Desc != ACPI_END_TAG_DESCRIPTOR) {
+ if (AddressDescriptor->ResType == ACPI_ADDRESS_SPACE_TYPE_BUS) {
+ for (UINT8 Bus = AddressDescriptor->AddrRangeMin; Bus <= AddressDescriptor->AddrRangeMax; Bus++) {
+ for (UINT8 Device = 0; Device <= PCI_MAX_DEVICE; Device++) {
+ for (UINT8 Func = 0; Func <= PCI_MAX_FUNC; Func++) {
+ UINT64 Address = PciConfigurationAddress(Bus, Device, Func, 0);
+ PCI_DEVICE_INDEPENDENT_REGION PCIConfHdr;
+ Status = PciRootBridgeIo->Pci.Read(
+ PciRootBridgeIo,
+ EfiPciWidthUint8,
+ Address,
+ sizeof(PCI_DEVICE_INDEPENDENT_REGION),
+ &PCIConfHdr
+ );
+ if (!EFI_ERROR(Status)) {
+ if (PCIConfHdr.VendorId != 0xffff) {
+ Print(L"\t%02x:%02x.%02x - Vendor:%04x, Device:%04x",
+ Bus,
+ Device,
+ Func,
+ PCIConfHdr.VendorId,
+ PCIConfHdr.DeviceId);
+
+ CHAR16 VendorDesc[DESCRIPTOR_STR_MAX_SIZE];
+ CHAR16 DeviceDesc[DESCRIPTOR_STR_MAX_SIZE];
+ Status = FindPCIDevDescription(PCIConfHdr.VendorId,
+ PCIConfHdr.DeviceId,
+ VendorDesc,
+ DeviceDesc,
+ DESCRIPTOR_STR_MAX_SIZE);
+ if (!EFI_ERROR(Status)) {
+ Print(L": %s, %s\n", VendorDesc, DeviceDesc);
+ } else {
+ Print(L"\n");
+ }
+ }
+ } else {
+ Print(L"\tError in PCI read: %r\n", Status);
+ }
+ }
+ }
+ }
+ }
+ AddressDescriptor++;
+ }
+ return Status;
+}
+
+EFI_STATUS
+EFIAPI
+UefiMain (
+ IN EFI_HANDLE ImageHandle,
+ IN EFI_SYSTEM_TABLE *SystemTable
+ )
+{
+ EFI_STATUS Status;
+ UINTN HandleCount;
+ EFI_HANDLE *HandleBuffer;
+ Status = gBS->LocateHandleBuffer(
+ ByProtocol,
+ &gEfiPciRootBridgeIoProtocolGuid,
+ NULL,
+ &HandleCount,
+ &HandleBuffer
+ );
+ if (EFI_ERROR (Status)) {
+ Print(L"Can't locate EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL: %r\n", Status);
+ return Status;
+ }
+
+ Print(L"Number of PCI root bridges in the system: %d\n", HandleCount);
+ EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL* PciRootBridgeIo;
+ for (UINTN Index = 0; Index < HandleCount; Index++) {
+ Status = gBS->OpenProtocol (
+ HandleBuffer[Index],
+ &gEfiPciRootBridgeIoProtocolGuid,
+ (VOID **)&PciRootBridgeIo,
+ ImageHandle,
+ NULL,
+ EFI_OPEN_PROTOCOL_GET_PROTOCOL
+ );
+ if (EFI_ERROR(Status)) {
+ Print(L"Can't open protocol: %r\n", Status);
+ return Status;
+ }
+ Print(L"\nPCI Root Bridge %d\n", Index);
+ Status = PrintRootBridge(PciRootBridgeIo);
+ if (EFI_ERROR(Status)) {
+ Print(L"Error in PCI Root Bridge printing\n");
+ }
+ }
+ FreePool(HandleBuffer);
+
+ return EFI_SUCCESS;
+}
diff --git a/UefiLessonsPkg/ListPCI/ListPCI.c:Zone.Identifier b/UefiLessonsPkg/ListPCI/ListPCI.c:Zone.Identifier
new file mode 100644
index 0000000..be537eb
--- /dev/null
+++ b/UefiLessonsPkg/ListPCI/ListPCI.c:Zone.Identifier
Binary files differ
diff --git a/UefiLessonsPkg/ListPCI/ListPCI.inf b/UefiLessonsPkg/ListPCI/ListPCI.inf
new file mode 100644
index 0000000..0080d75
--- /dev/null
+++ b/UefiLessonsPkg/ListPCI/ListPCI.inf
@@ -0,0 +1,22 @@
+[Defines]
+ INF_VERSION = 1.25
+ BASE_NAME = ListPCI
+ FILE_GUID = 07aceb78-97df-4e49-84a8-28997896e42a
+ MODULE_TYPE = UEFI_APPLICATION
+ VERSION_STRING = 1.0
+ ENTRY_POINT = UefiMain
+
+[Sources]
+ ListPCI.c
+
+[Packages]
+ MdePkg/MdePkg.dec
+ ShellPkg/ShellPkg.dec
+
+[LibraryClasses]
+ UefiApplicationEntryPoint
+ UefiLib
+ ShellLib
+
+[Protocols]
+ gEfiPciRootBridgeIoProtocolGuid
diff --git a/UefiLessonsPkg/ListPCI/ListPCI.inf:Zone.Identifier b/UefiLessonsPkg/ListPCI/ListPCI.inf:Zone.Identifier
new file mode 100644
index 0000000..be537eb
--- /dev/null
+++ b/UefiLessonsPkg/ListPCI/ListPCI.inf:Zone.Identifier
Binary files differ
diff --git a/UefiLessonsPkg/ListVariables/ListVariables.c b/UefiLessonsPkg/ListVariables/ListVariables.c
new file mode 100644
index 0000000..1f3ef4a
--- /dev/null
+++ b/UefiLessonsPkg/ListVariables/ListVariables.c
@@ -0,0 +1,46 @@
+#include <Library/UefiBootServicesTableLib.h>
+#include <Library/UefiLib.h>
+
+
+#include <Library/MemoryAllocationLib.h>
+#include <Library/UefiRuntimeServicesTableLib.h>
+
+INTN EFIAPI ShellAppMain(IN UINTN Argc, IN CHAR16 **Argv)
+{
+ EFI_GUID VendorGuid;
+ UINTN VariableNameSize = sizeof (CHAR16);
+ CHAR16* VariableName = AllocateZeroPool(sizeof(CHAR16));
+ if (VariableName == NULL) {
+ Print(L"Error on AllocateZeroPool call\n");
+ return EFI_OUT_OF_RESOURCES;
+ }
+
+ while (TRUE)
+ {
+ UINTN VariableNameSizeOld = VariableNameSize;
+ EFI_STATUS Status = gRT->GetNextVariableName(&VariableNameSize, VariableName, &VendorGuid);
+ if (Status == EFI_SUCCESS) {
+ Print(L"%g: %s\n", VendorGuid, VariableName);
+ } else if (Status == EFI_BUFFER_TOO_SMALL) {
+ VariableName = ReallocatePool(VariableNameSizeOld, VariableNameSize, VariableName);
+ if (VariableName == NULL) {
+ Print(L"Error on ReallocatePool call\n");
+ return EFI_OUT_OF_RESOURCES;
+ }
+ Status = gRT->GetNextVariableName(&VariableNameSize, VariableName, &VendorGuid);
+ if (Status == EFI_SUCCESS) {
+ Print(L"%g: %s\n", VendorGuid, VariableName);
+ } else {
+ Print(L"Error on 'gRT->GetNextVariableName' call: %s\n", Status);
+ return Status;
+ }
+ } else if (Status == EFI_NOT_FOUND) {
+ FreePool(VariableName);
+ return EFI_SUCCESS;
+ } else {
+ Print(L"Error on 'gRT->GetNextVariableName' call: %s\n", Status);
+ return Status;
+ }
+ }
+ return EFI_SUCCESS;
+}
diff --git a/UefiLessonsPkg/ListVariables/ListVariables.inf b/UefiLessonsPkg/ListVariables/ListVariables.inf
new file mode 100644
index 0000000..14e9fa2
--- /dev/null
+++ b/UefiLessonsPkg/ListVariables/ListVariables.inf
@@ -0,0 +1,19 @@
+[Defines]
+ INF_VERSION = 1.25
+ BASE_NAME = ListVariables
+ FILE_GUID = d66f68b2-3591-45af-bf5d-519152b9d877
+ MODULE_TYPE = UEFI_APPLICATION
+ VERSION_STRING = 1.0
+ ENTRY_POINT = ShellCEntryLib
+
+[Sources]
+ ListVariables.c
+
+[Packages]
+ MdePkg/MdePkg.dec
+
+[LibraryClasses]
+ UefiApplicationEntryPoint
+ UefiLib
+ ShellCEntryLib
+
diff --git a/UefiLessonsPkg/MemoryInfo/MemoryInfo.c b/UefiLessonsPkg/MemoryInfo/MemoryInfo.c
new file mode 100644
index 0000000..8c3bcf2
--- /dev/null
+++ b/UefiLessonsPkg/MemoryInfo/MemoryInfo.c
@@ -0,0 +1,215 @@
+#include <Library/UefiBootServicesTableLib.h>
+#include <Library/UefiLib.h>
+
+// for SetMem
+#include <Library/BaseMemoryLib.h>
+
+#include <Protocol/ShellParameters.h>
+
+const CHAR16 *memory_types[] = {
+ L"EfiReservedMemoryType",
+ L"EfiLoaderCode",
+ L"EfiLoaderData",
+ L"EfiBootServicesCode",
+ L"EfiBootServicesData",
+ L"EfiRuntimeServicesCode",
+ L"EfiRuntimeServicesData",
+ L"EfiConventionalMemory",
+ L"EfiUnusableMemory",
+ L"EfiACPIReclaimMemory",
+ L"EfiACPIMemoryNVS",
+ L"EfiMemoryMappedIO",
+ L"EfiMemoryMappedIOPortSpace",
+ L"EfiPalCode",
+ L"EfiPersistentMemory",
+ L"EfiMaxMemoryType"
+};
+
+
+const CHAR16 *memory_types_OS_view[] = {
+ L"reserved", // L"EfiReservedMemoryType",
+ L"usable", // L"EfiLoaderCode",
+ L"usable", // L"EfiLoaderData",
+ L"usable", // L"EfiBootServicesCode",
+ L"usable", // L"EfiBootServicesData",
+ L"reserved", // L"EfiRuntimeServicesCode",
+ L"reserved", // L"EfiRuntimeServicesData",
+ L"usable", // L"EfiConventionalMemory",
+ L"reserved", // L"EfiUnusableMemory",
+ L"ACPI data",// L"EfiACPIReclaimMemory",
+ L"ACPI NVS", // L"EfiACPIMemoryNVS",
+ L"reserved", // L"EfiMemoryMappedIO",
+ L"reserved", // L"EfiMemoryMappedIOPortSpace",
+ L"reserved", // L"EfiPalCode",
+ L"usable", // L"EfiPersistentMemory",
+ L"usable", // L"EfiMaxMemoryType"
+};
+
+
+const CHAR16 *
+memory_type_to_str(UINT32 type)
+{
+ if (type > sizeof(memory_types)/sizeof(CHAR16 *))
+ return L"Unknown";
+
+ return memory_types[type];
+}
+
+const CHAR16 *
+memory_type_to_str_OS_view(UINT32 type)
+{
+ if (type > sizeof(memory_types_OS_view)/sizeof(CHAR16 *))
+ return L"Unknown";
+
+ return memory_types_OS_view[type];
+}
+
+#define ATTRIBUTE_STR_SIZE 50
+
+#define CHECK_EFI_MEMORY_ATTRIBUTE(attr) if (attrs & EFI_MEMORY_##attr) { \
+ StrCpyS(&str[i], ATTRIBUTE_STR_SIZE, L" "#attr); \
+ i+=StrLen(L" "#attr); \
+ }
+
+const CHAR16 *
+memory_attrs_to_str(CHAR16* str, UINT64 attrs)
+{
+ int i=0;
+ SetMem((VOID *)str, sizeof(str), 0);
+
+ CHECK_EFI_MEMORY_ATTRIBUTE(UC)
+ CHECK_EFI_MEMORY_ATTRIBUTE(WC)
+ CHECK_EFI_MEMORY_ATTRIBUTE(WT)
+ CHECK_EFI_MEMORY_ATTRIBUTE(WB)
+ CHECK_EFI_MEMORY_ATTRIBUTE(UCE)
+ CHECK_EFI_MEMORY_ATTRIBUTE(WP)
+ CHECK_EFI_MEMORY_ATTRIBUTE(RP)
+ CHECK_EFI_MEMORY_ATTRIBUTE(XP)
+ CHECK_EFI_MEMORY_ATTRIBUTE(NV)
+ CHECK_EFI_MEMORY_ATTRIBUTE(MORE_RELIABLE)
+ CHECK_EFI_MEMORY_ATTRIBUTE(RO)
+ CHECK_EFI_MEMORY_ATTRIBUTE(SP)
+ CHECK_EFI_MEMORY_ATTRIBUTE(CPU_CRYPTO)
+ CHECK_EFI_MEMORY_ATTRIBUTE(RUNTIME)
+
+ return str;
+}
+
+EFI_STATUS
+EFIAPI
+UefiMain (
+ IN EFI_HANDLE ImageHandle,
+ IN EFI_SYSTEM_TABLE *SystemTable
+ )
+{
+ UINTN MemoryMapSize = 0;
+ EFI_MEMORY_DESCRIPTOR* MemoryMap = NULL;
+ UINTN MapKey;
+ UINTN DescriptorSize;
+ UINT32 DescriptorVersion;
+
+ EFI_STATUS Status;
+
+
+ EFI_SHELL_PARAMETERS_PROTOCOL* ShellParameters;
+
+ Status = gBS->HandleProtocol(
+ ImageHandle,
+ &gEfiShellParametersProtocolGuid,
+ (VOID **) &ShellParameters
+ );
+
+ BOOLEAN full=FALSE;
+ if (Status == EFI_SUCCESS) {
+ if (ShellParameters->Argc == 2) {
+ if (!StrCmp(ShellParameters->Argv[1], L"full")) {
+ full=TRUE;
+ }
+ }
+ }
+
+
+ Status = gBS->GetMemoryMap(
+ &MemoryMapSize,
+ MemoryMap,
+ &MapKey,
+ &DescriptorSize,
+ &DescriptorVersion
+ );
+
+ if (Status == EFI_BUFFER_TOO_SMALL) {
+ Status = gBS->AllocatePool(
+ EfiBootServicesData,
+ MemoryMapSize,
+ (void**)&MemoryMap
+ );
+
+ if (EFI_ERROR(Status)) {
+ Print(L"AllocatePool error: %r\n", Status);
+ return Status;
+ }
+
+ Status = gBS->GetMemoryMap(
+ &MemoryMapSize,
+ MemoryMap,
+ &MapKey,
+ &DescriptorSize,
+ &DescriptorVersion
+ );
+
+ if (!EFI_ERROR(Status))
+ {
+ EFI_MEMORY_DESCRIPTOR* desc = MemoryMap;
+ EFI_MEMORY_DESCRIPTOR* next_desc;
+ int i = 0;
+ while ((UINT8 *)desc < (UINT8 *)MemoryMap + MemoryMapSize) {
+ UINTN PAGE_SIZE = 4096;
+ UINTN mapping_size =(UINTN) desc->NumberOfPages * PAGE_SIZE;
+
+ UINT64 Start = desc->PhysicalStart;
+
+ next_desc = (EFI_MEMORY_DESCRIPTOR *)((UINT8 *)desc + DescriptorSize);
+ if (!full) {
+ while ((UINT8 *)next_desc < (UINT8 *)MemoryMap + MemoryMapSize) {
+ mapping_size =(UINTN) desc->NumberOfPages * PAGE_SIZE;
+ if ((desc->PhysicalStart + mapping_size) == (next_desc->PhysicalStart)) {
+
+ if (desc->Type != next_desc->Type) {
+ if (StrCmp(memory_type_to_str_OS_view(desc->Type),
+ memory_type_to_str_OS_view(next_desc->Type)))
+ break;
+ }
+
+ desc=next_desc;
+ next_desc = (EFI_MEMORY_DESCRIPTOR *)((UINT8 *)next_desc + DescriptorSize);
+ } else {
+ break;
+ }
+ }
+ }
+
+ if (full) {
+ CHAR16 str[ATTRIBUTE_STR_SIZE];
+ Print(L"[#%02d] Type: %s Attr: %s\n", i++,
+ memory_type_to_str(desc->Type), memory_attrs_to_str(str, desc->Attribute));
+ Print(L" Phys: %016llx-%016llx\n", Start, Start + mapping_size - 1);
+ }
+ else {
+ Print(L" [mem: %016llx-%016llx] %s\n", Start, desc->PhysicalStart + mapping_size - 1,
+ memory_type_to_str_OS_view(desc->Type) );
+ }
+
+ desc = next_desc;
+ }
+
+ gBS->FreePool(MemoryMap);
+ } else {
+ Print(L"GetMemoryMap with buffer error: %r\n", Status);
+ }
+ } else {
+ Print(L"GetMemoryMap without buffer error: %r\n", Status);
+ }
+
+ return Status;
+}
+
diff --git a/UefiLessonsPkg/MemoryInfo/MemoryInfo.inf b/UefiLessonsPkg/MemoryInfo/MemoryInfo.inf
new file mode 100644
index 0000000..777010d
--- /dev/null
+++ b/UefiLessonsPkg/MemoryInfo/MemoryInfo.inf
@@ -0,0 +1,21 @@
+[Defines]
+ INF_VERSION = 1.25
+ BASE_NAME = MemoryInfo
+ FILE_GUID = d2ce1d65-603e-4b48-b3e1-fe65d5d0bca8
+ MODULE_TYPE = UEFI_APPLICATION
+ VERSION_STRING = 1.0
+ ENTRY_POINT = UefiMain
+
+[Sources]
+ MemoryInfo.c
+
+[Packages]
+ MdePkg/MdePkg.dec
+
+[LibraryClasses]
+ UefiApplicationEntryPoint
+ UefiLib
+
+[Protocols]
+ gEfiShellParametersProtocolGuid
+
diff --git a/UefiLessonsPkg/PCDLesson/PCDLesson.c b/UefiLessonsPkg/PCDLesson/PCDLesson.c
new file mode 100644
index 0000000..03be437
--- /dev/null
+++ b/UefiLessonsPkg/PCDLesson/PCDLesson.c
@@ -0,0 +1,43 @@
+#include <Library/UefiBootServicesTableLib.h>
+#include <Library/UefiLib.h>
+
+#include <Library/PcdLib.h>
+
+EFI_STATUS
+EFIAPI
+UefiMain (
+ IN EFI_HANDLE ImageHandle,
+ IN EFI_SYSTEM_TABLE *SystemTable
+ )
+{
+ Print(L"PcdMyVar32=%d\n", FixedPcdGet32(PcdMyVar32));
+ Print(L"PcdMyVar32_1=%d\n", FixedPcdGet32(PcdMyVar32_1));
+ Print(L"PcdMyVar32_2=%d\n", FixedPcdGet32(PcdMyVar32_2));
+
+ Print(L"PcdMyVar32=%d\n", PcdGet32(PcdMyVar32));
+
+ Print(L"PcdMyPatchableVar32=%d\n", PcdGet32(PcdMyPatchableVar32));
+ EFI_STATUS Status = PcdSet32S(PcdMyPatchableVar32, 44);
+ Print(L"Status=%r\n", Status);
+ Print(L"PcdMyPatchableVar32=%d\n", PcdGet32(PcdMyPatchableVar32));
+ PatchPcdSet32(PcdMyPatchableVar32, 45);
+ Print(L"PcdMyPatchableVar32=%d\n", PatchPcdGet32(PcdMyPatchableVar32));
+
+
+ Print(L"PcdMyFeatureFlagVar=%d\n", FeaturePcdGet(PcdMyFeatureFlagVar));
+ Print(L"PcdMyFeatureFlagVar=%d\n", PcdGetBool(PcdMyFeatureFlagVar));
+ Print(L"PcdMyVarBool=%d\n", FixedPcdGetBool(PcdMyVarBool));
+ Print(L"PcdMyVarBool=%d\n", PcdGetBool(PcdMyVarBool));
+
+
+
+
+ Print(L"PcdMyDynamicExVar32=%x\n", PcdGet32(PcdMyDynamicExVar32));
+ PcdSet32S(PcdMyDynamicExVar32, 52);
+ Print(L"PcdMyDynamicExVar32=%x\n", PcdGet32(PcdMyDynamicExVar32));
+
+ Print(L"PcdMyDynamicVar32=%x\n", PcdGet32(PcdMyDynamicVar32));
+ PcdSet32S(PcdMyDynamicVar32, 52);
+ Print(L"PcdMyDynamicVar32=%x\n", PcdGet32(PcdMyDynamicVar32));
+ return EFI_SUCCESS;
+}
diff --git a/UefiLessonsPkg/PCDLesson/PCDLesson.inf b/UefiLessonsPkg/PCDLesson/PCDLesson.inf
new file mode 100644
index 0000000..cfd39d2
--- /dev/null
+++ b/UefiLessonsPkg/PCDLesson/PCDLesson.inf
@@ -0,0 +1,39 @@
+[Defines]
+ INF_VERSION = 1.25
+ BASE_NAME = PCDLesson
+ FILE_GUID = 8c1a6b71-0c4b-4497-aaad-07404edf142c
+ MODULE_TYPE = UEFI_APPLICATION
+ VERSION_STRING = 1.0
+ ENTRY_POINT = UefiMain
+
+[Sources]
+ PCDLesson.c
+
+[Packages]
+ MdePkg/MdePkg.dec
+ UefiLessonsPkg/UefiLessonsPkg.dec
+
+[LibraryClasses]
+ UefiApplicationEntryPoint
+ UefiLib
+
+[FixedPcd]
+ gUefiLessonsPkgTokenSpaceGuid.PcdMyVar32
+ gUefiLessonsPkgTokenSpaceGuid.PcdMyVar32_1|43
+ gUefiLessonsPkgTokenSpaceGuid.PcdMyVar32_2|43
+ gUefiLessonsPkgTokenSpaceGuid.PcdMyVarBool
+
+[PatchPcd]
+ gUefiLessonsPkgTokenSpaceGuid.PcdMyPatchableVar32
+
+[FeaturePcd]
+ gUefiLessonsPkgTokenSpaceGuid.PcdMyFeatureFlagVar
+
+[Pcd]
+ gUefiLessonsPkgTokenSpaceGuid.PcdMyDynamicVar32
+ gUefiLessonsPkgTokenSpaceGuid.PcdMyDynamicVar32_1
+
+[PcdEx]
+ gUefiLessonsPkgTokenSpaceGuid.PcdMyDynamicExVar32
+
+
diff --git a/UefiLessonsPkg/ShowBootVariables/ShowBootVariables.c b/UefiLessonsPkg/ShowBootVariables/ShowBootVariables.c
new file mode 100644
index 0000000..7f6b58c
--- /dev/null
+++ b/UefiLessonsPkg/ShowBootVariables/ShowBootVariables.c
@@ -0,0 +1,93 @@
+#include <Library/UefiBootServicesTableLib.h>
+#include <Library/UefiLib.h>
+
+#include <Library/MemoryAllocationLib.h>
+#include <Library/UefiRuntimeServicesTableLib.h>
+
+#include <Library/DevicePathLib.h>
+#include <Library/PrintLib.h>
+
+
+EFI_STATUS
+GetNvramVariable( CHAR16 *VariableName,
+ EFI_GUID *VariableOwnerGuid,
+ VOID **Buffer,
+ UINTN *BufferSize)
+{
+ UINTN Size = 0;
+ *BufferSize = 0;
+
+ EFI_STATUS Status = gRT->GetVariable(VariableName, VariableOwnerGuid, NULL, &Size, NULL);
+ if (Status != EFI_BUFFER_TOO_SMALL) {
+ Print(L"Error! 'gRT->GetVariable' call returned %r\n", Status);
+ return Status;
+ }
+
+ *Buffer = AllocateZeroPool(Size);
+ if (!Buffer) {
+ Print(L"Error! 'AllocateZeroPool' call returned %r\n", Status);
+ return EFI_OUT_OF_RESOURCES;
+ }
+
+ Status = gRT->GetVariable(VariableName, VariableOwnerGuid, NULL, &Size, *Buffer);
+ if (Status == EFI_SUCCESS) {
+ *BufferSize = Size;
+ } else {
+ FreePool( *Buffer );
+ *Buffer = NULL;
+ }
+
+ return Status;
+}
+
+
+VOID PrintBootOption(CHAR16* BootOptionName)
+{
+ UINTN OptionSize;
+ UINT8* Buffer;
+
+ EFI_STATUS Status = GetNvramVariable(BootOptionName, &gEfiGlobalVariableGuid, (VOID**)&Buffer, &OptionSize);
+ if (Status == EFI_SUCCESS) {
+ EFI_LOAD_OPTION* LoadOption = (EFI_LOAD_OPTION*) Buffer;
+ CHAR16* Description = (CHAR16*)(Buffer + sizeof (EFI_LOAD_OPTION));
+ UINTN DescriptionSize = StrSize(Description);
+
+ Print(L"%s\n", Description);
+ if (LoadOption->FilePathListLength != 0) {
+ VOID* FilePathList = (UINT8 *)Description + DescriptionSize;
+ CHAR16* DevPathString = ConvertDevicePathToText(FilePathList, TRUE, FALSE);
+ Print(L"%s\n", DevPathString);
+ }
+ } else {
+ Print(L"Can't get %s variable\n", BootOptionName);
+ }
+}
+
+
+INTN EFIAPI ShellAppMain(IN UINTN Argc, IN CHAR16 **Argv)
+{
+ UINTN OptionSize;
+ EFI_STATUS Status;
+
+ UINT16* BootCurrent;
+ Status = GetNvramVariable(L"BootCurrent", &gEfiGlobalVariableGuid, (VOID**)&BootCurrent, &OptionSize);
+ if (Status != EFI_SUCCESS) {
+ Print(L"Can't get BootCurrent variable\n");
+ }
+
+ UINT16* BootOrderArray;
+ Status = GetNvramVariable(L"BootOrder", &gEfiGlobalVariableGuid, (VOID**)&BootOrderArray, &OptionSize);
+ if (Status == EFI_SUCCESS) {
+ for (UINTN i=0; i<(OptionSize/sizeof(UINT16)); i++) {
+ CHAR16 BootOptionStr[sizeof("Boot####")+1];
+ UnicodeSPrint(BootOptionStr, (sizeof("Boot####")+1)*sizeof(CHAR16), L"Boot%04x", BootOrderArray[i]);
+ Print(L"%s%s\n", BootOptionStr, (BootOrderArray[i] == *BootCurrent)? L"*" : L"" );
+ PrintBootOption(BootOptionStr);
+ Print(L"\n");
+ }
+ } else {
+ Print(L"Can't get BootOrder variable\n");
+ }
+
+ return EFI_SUCCESS;
+}
diff --git a/UefiLessonsPkg/ShowBootVariables/ShowBootVariables.inf b/UefiLessonsPkg/ShowBootVariables/ShowBootVariables.inf
new file mode 100644
index 0000000..d2cfba9
--- /dev/null
+++ b/UefiLessonsPkg/ShowBootVariables/ShowBootVariables.inf
@@ -0,0 +1,19 @@
+[Defines]
+ INF_VERSION = 1.25
+ BASE_NAME = ShowBootVariables
+ FILE_GUID = 31266d12-9c60-478e-905e-05d117a3a9df
+ MODULE_TYPE = UEFI_APPLICATION
+ VERSION_STRING = 1.0
+ ENTRY_POINT = ShellCEntryLib
+
+[Sources]
+ ShowBootVariables.c
+
+[Packages]
+ MdePkg/MdePkg.dec
+
+[LibraryClasses]
+ UefiApplicationEntryPoint
+ UefiLib
+ ShellCEntryLib
+
diff --git a/UefiLessonsPkg/ShowHii/ShowHii.c b/UefiLessonsPkg/ShowHii/ShowHii.c
new file mode 100644
index 0000000..27f23c3
--- /dev/null
+++ b/UefiLessonsPkg/ShowHii/ShowHii.c
@@ -0,0 +1,120 @@
+#include <Library/UefiBootServicesTableLib.h>
+#include <Library/UefiLib.h>
+
+#include <Protocol/HiiDatabase.h>
+#include <Library/MemoryAllocationLib.h>
+
+
+CHAR16* PackageType(UINTN Type)
+{
+ switch(Type) {
+ case EFI_HII_PACKAGE_TYPE_ALL:
+ return L"ALL";
+ case EFI_HII_PACKAGE_TYPE_GUID:
+ return L"GUID";
+ case EFI_HII_PACKAGE_FORMS:
+ return L"FORMS";
+ case EFI_HII_PACKAGE_STRINGS:
+ return L"STRINGS";
+ case EFI_HII_PACKAGE_FONTS:
+ return L"FONTS";
+ case EFI_HII_PACKAGE_IMAGES:
+ return L"IMAGES";
+ case EFI_HII_PACKAGE_SIMPLE_FONTS:
+ return L"SIMPLE_FONTS";
+ case EFI_HII_PACKAGE_DEVICE_PATH:
+ return L"DEVICE_PATH";
+ case EFI_HII_PACKAGE_KEYBOARD_LAYOUT:
+ return L"KEYBOARD_LAYOUT";
+ case EFI_HII_PACKAGE_ANIMATIONS:
+ return L"ANIMATIONS";
+ case EFI_HII_PACKAGE_END:
+ return L"END";
+ case EFI_HII_PACKAGE_TYPE_SYSTEM_BEGIN:
+ return L"SYSTEM_BEGIN";
+ case EFI_HII_PACKAGE_TYPE_SYSTEM_END:
+ return L"SYSTEM_END";
+ }
+ return L"UNKNOWN";
+}
+
+VOID ParseHiiPackageLists(EFI_HII_PACKAGE_LIST_HEADER* HiiDatabase, UINTN HiiDatabaseSize)
+{
+ EFI_HII_PACKAGE_LIST_HEADER* HiiPackageListHeader;
+ HiiPackageListHeader = (EFI_HII_PACKAGE_LIST_HEADER*) HiiDatabase;
+
+ UINTN i=0;
+ while ((UINTN) HiiPackageListHeader < ((UINTN) HiiDatabase + HiiDatabaseSize)) {
+ UINTN HiiPackageListSize = HiiPackageListHeader->PackageLength;
+ if (HiiPackageListSize == 0)
+ break;
+ Print(L"PackageList[%d]: GUID=%g\n", i++, HiiPackageListHeader->PackageListGuid);
+
+ EFI_HII_PACKAGE_HEADER* HiiPackageHeader = (EFI_HII_PACKAGE_HEADER*)((UINTN) HiiPackageListHeader + sizeof(EFI_HII_PACKAGE_LIST_HEADER));
+ UINTN j=0;
+ while ((UINTN) HiiPackageHeader < ((UINTN) HiiPackageListHeader + HiiPackageListSize)) {
+ Print(L"\tPackage[%d]: type=%s\n", j++, PackageType(HiiPackageHeader->Type));
+ // Go to next Package
+ HiiPackageHeader = (EFI_HII_PACKAGE_HEADER*)((UINTN) HiiPackageHeader + HiiPackageHeader->Length);
+ }
+ // Go to next PackageList
+ HiiPackageListHeader = (EFI_HII_PACKAGE_LIST_HEADER*)((UINTN) HiiPackageListHeader + HiiPackageListSize);
+ }
+}
+
+EFI_STATUS
+EFIAPI
+UefiMain (
+ IN EFI_HANDLE ImageHandle,
+ IN EFI_SYSTEM_TABLE *SystemTable
+ )
+{
+ EFI_STATUS Status;
+ EFI_HII_DATABASE_PROTOCOL* HiiDbProtocol;
+ Status = gBS->LocateProtocol(&gEfiHiiDatabaseProtocolGuid,
+ NULL,
+ (VOID**)&HiiDbProtocol);
+ if (EFI_ERROR(Status)) {
+ Print(L"ERROR: Could not find HII Database protocol: %r\n", Status);
+ return Status;
+ }
+
+
+ UINTN PackageListSize = 0;
+ EFI_HII_PACKAGE_LIST_HEADER* PackageList = NULL;
+
+ Status = HiiDbProtocol->ExportPackageLists(HiiDbProtocol,
+ NULL, // All package lists
+ &PackageListSize,
+ PackageList);
+ if (Status != EFI_BUFFER_TOO_SMALL) {
+ Print(L"ERROR: Could not obtain package list size\n");
+ return Status;
+ }
+
+ Status = gBS->AllocatePool(EfiBootServicesData,
+ PackageListSize,
+ (VOID**)&PackageList);
+ if (EFI_ERROR(Status)) {
+ Print(L"ERROR: Could not allocate sufficient memory for package list: %r\n", Status);
+ return Status;
+ }
+
+
+ Status = HiiDbProtocol->ExportPackageLists(HiiDbProtocol,
+ NULL,
+ &PackageListSize,
+ PackageList);
+ if (EFI_ERROR(Status)) {
+ Print(L"ERROR: Could not retrieve the package list: %r\n", Status);
+ FreePool(PackageList);
+ return Status;
+ }
+
+ ParseHiiPackageLists(PackageList, PackageListSize);
+ ////////
+
+ FreePool(PackageList);
+
+ return EFI_SUCCESS;
+}
diff --git a/UefiLessonsPkg/ShowHii/ShowHii.inf b/UefiLessonsPkg/ShowHii/ShowHii.inf
new file mode 100644
index 0000000..ec8ba46
--- /dev/null
+++ b/UefiLessonsPkg/ShowHii/ShowHii.inf
@@ -0,0 +1,22 @@
+[Defines]
+ INF_VERSION = 1.25
+ BASE_NAME = ShowHii
+ FILE_GUID = 75a15862-aa04-47c2-a0ac-14a0a8bf5756
+ MODULE_TYPE = UEFI_APPLICATION
+ VERSION_STRING = 1.0
+ ENTRY_POINT = UefiMain
+
+[Sources]
+ ShowHii.c
+
+[Packages]
+ MdePkg/MdePkg.dec
+
+[LibraryClasses]
+ UefiApplicationEntryPoint
+ UefiLib
+
+[Protocols]
+ gEfiHiiDatabaseProtocolGuid
+
+
diff --git a/UefiLessonsPkg/SimpleDriver/SimpleDriver.c b/UefiLessonsPkg/SimpleDriver/SimpleDriver.c
new file mode 100644
index 0000000..fd96d17
--- /dev/null
+++ b/UefiLessonsPkg/SimpleDriver/SimpleDriver.c
@@ -0,0 +1,26 @@
+#include <Library/UefiBootServicesTableLib.h>
+#include <Library/UefiLib.h>
+
+
+EFI_STATUS
+EFIAPI
+SimpleDriverUnload (
+ EFI_HANDLE ImageHandle
+ )
+{
+ Print(L"Bye-bye from driver!\n");
+
+ return EFI_SUCCESS;
+}
+
+EFI_STATUS
+EFIAPI
+SimpleDriverEntryPoint (
+ IN EFI_HANDLE ImageHandle,
+ IN EFI_SYSTEM_TABLE *SystemTable
+ )
+{
+ Print(L"Hello from driver!\n");
+
+ return EFI_SUCCESS;
+}
diff --git a/UefiLessonsPkg/SimpleDriver/SimpleDriver.inf b/UefiLessonsPkg/SimpleDriver/SimpleDriver.inf
new file mode 100644
index 0000000..a6008c2
--- /dev/null
+++ b/UefiLessonsPkg/SimpleDriver/SimpleDriver.inf
@@ -0,0 +1,19 @@
+[Defines]
+ INF_VERSION = 1.25
+ BASE_NAME = SimpleDriver
+ FILE_GUID = 384aeb18-105d-4af1-bf17-5e349e8f4d4c
+ MODULE_TYPE = UEFI_DRIVER
+ VERSION_STRING = 1.0
+ ENTRY_POINT = SimpleDriverEntryPoint
+ UNLOAD_IMAGE = SimpleDriverUnload
+
+[Sources]
+ SimpleDriver.c
+
+[Packages]
+ MdePkg/MdePkg.dec
+
+[LibraryClasses]
+ UefiDriverEntryPoint
+ UefiLib
+
diff --git a/UefiLessonsPkg/SimpleShellApp/SimpleShellApp.c b/UefiLessonsPkg/SimpleShellApp/SimpleShellApp.c
new file mode 100644
index 0000000..b13aa6c
--- /dev/null
+++ b/UefiLessonsPkg/SimpleShellApp/SimpleShellApp.c
@@ -0,0 +1,14 @@
+#include <Library/UefiBootServicesTableLib.h>
+#include <Library/UefiLib.h>
+
+INTN EFIAPI ShellAppMain(IN UINTN Argc, IN CHAR16 **Argv)
+{
+// SystemTable->ConOut->OutputString(SystemTable->ConOut, L"Hello World!\n");
+ gST->ConOut->OutputString(gST->ConOut, L"Hello again!\n");
+ Print(L"Bye!\n");
+
+ for (UINTN i=Argc; i>0; i--) {
+ Print(L"Arg[%d]=%s\n", Argc-i, Argv[Argc-i]);
+ }
+ return 0;
+}
diff --git a/UefiLessonsPkg/SimpleShellApp/SimpleShellApp.inf b/UefiLessonsPkg/SimpleShellApp/SimpleShellApp.inf
new file mode 100644
index 0000000..013bf4e
--- /dev/null
+++ b/UefiLessonsPkg/SimpleShellApp/SimpleShellApp.inf
@@ -0,0 +1,19 @@
+[Defines]
+ INF_VERSION = 1.25
+ BASE_NAME = SimpleShellApp
+ FILE_GUID = 2afd1202-545e-4f8d-b8fb-bc179e84ddc8
+ MODULE_TYPE = UEFI_APPLICATION
+ VERSION_STRING = 1.0
+ ENTRY_POINT = ShellCEntryLib
+
+[Sources]
+ SimpleShellApp.c
+
+[Packages]
+ MdePkg/MdePkg.dec
+
+[LibraryClasses]
+ UefiApplicationEntryPoint
+ UefiLib
+ ShellCEntryLib
+
diff --git a/UefiLessonsPkg/SimplestApp/SimplestApp.c b/UefiLessonsPkg/SimplestApp/SimplestApp.c
new file mode 100644
index 0000000..8bdf500
--- /dev/null
+++ b/UefiLessonsPkg/SimplestApp/SimplestApp.c
@@ -0,0 +1,10 @@
+EFI_STATUS
+EFIAPI
+UefiMain (
+ IN EFI_HANDLE ImageHandle,
+ IN EFI_SYSTEM_TABLE *SystemTable
+ )
+{
+ return EFI_SUCCESS;
+}
+
diff --git a/UefiLessonsPkg/SimplestApp/SimplestApp.inf b/UefiLessonsPkg/SimplestApp/SimplestApp.inf
new file mode 100644
index 0000000..7d4bae2
--- /dev/null
+++ b/UefiLessonsPkg/SimplestApp/SimplestApp.inf
@@ -0,0 +1,16 @@
+[Defines]
+ INF_VERSION = 1.25
+ BASE_NAME = SimplestApp
+ FILE_GUID = 4a298956-fbe0-47fb-ae3a-2d5a0a959a26
+ MODULE_TYPE = UEFI_APPLICATION
+ VERSION_STRING = 1.0
+ ENTRY_POINT = UefiMain
+
+[Sources]
+ SimplestApp.c
+
+[Packages]
+ MdePkg/MdePkg.dec
+
+[LibraryClasses]
+ UefiApplicationEntryPoint
diff --git a/UefiLessonsPkg/SmbiosInfo/SmbiosInfo.c b/UefiLessonsPkg/SmbiosInfo/SmbiosInfo.c
new file mode 100644
index 0000000..b75026d
--- /dev/null
+++ b/UefiLessonsPkg/SmbiosInfo/SmbiosInfo.c
@@ -0,0 +1,88 @@
+#include <Library/UefiBootServicesTableLib.h>
+#include <Library/UefiLib.h>
+
+#include <Library/BaseMemoryLib.h>
+#include <Protocol/Smbios.h>
+
+CHAR8* GetRecordString(EFI_SMBIOS_TABLE_HEADER* Record, UINTN number)
+{
+ if (!number)
+ return "";
+
+ CHAR8* String = (CHAR8*)Record + Record->Length;
+ UINTN i=1;
+ while (i < number) {
+ String = String + AsciiStrSize(String);
+ i++;
+ }
+ return String;
+}
+
+EFI_STATUS
+EFIAPI
+UefiMain (
+ IN EFI_HANDLE ImageHandle,
+ IN EFI_SYSTEM_TABLE *SystemTable
+ )
+{
+ for (UINTN i=0; i<SystemTable->NumberOfTableEntries; i++) {
+ if (CompareGuid(&(SystemTable->ConfigurationTable[i].VendorGuid), &gEfiSmbiosTableGuid)) {
+ Print(L"SMBIOS table is placed at %p\n\n", SystemTable->ConfigurationTable[i].VendorTable);
+ }
+ }
+
+ EFI_SMBIOS_PROTOCOL* SmbiosProtocol;
+ EFI_STATUS Status = gBS->LocateProtocol (
+ &gEfiSmbiosProtocolGuid,
+ NULL,
+ (VOID**)&SmbiosProtocol
+ );
+ if (EFI_ERROR (Status)) {
+ return Status;
+ }
+
+ EFI_SMBIOS_HANDLE SmbiosHandle = SMBIOS_HANDLE_PI_RESERVED;
+ EFI_SMBIOS_TABLE_HEADER* Record;
+ Status = SmbiosProtocol->GetNext(SmbiosProtocol,
+ &SmbiosHandle,
+ NULL,
+ &Record,
+ NULL);
+ while (!EFI_ERROR(Status)) {
+ Print (L"SMBIOS Type %d \n", Record->Type);
+ switch (Record->Type) {
+ case EFI_SMBIOS_TYPE_BIOS_INFORMATION: {
+ SMBIOS_TABLE_TYPE0* Type0Record = (SMBIOS_TABLE_TYPE0*) Record;
+ Print(L"\tVendor=%a\n", GetRecordString(Record, Type0Record->Vendor));
+ Print(L"\tBiosVersion=%a\n", GetRecordString(Record, Type0Record->BiosVersion));
+ Print(L"\tBiosReleaseDate=%a\n", GetRecordString(Record, Type0Record->BiosReleaseDate));
+ Print(L"\tBiosSegment=0x%x\n", Type0Record->BiosSegment);
+ Print(L"\tSystemBiosMajorRelease=0x%x\n", Type0Record->SystemBiosMajorRelease);
+ Print(L"\tSystemBiosMinorRelease=0x%x\n", Type0Record->SystemBiosMinorRelease);
+ break;
+ }
+ case EFI_SMBIOS_TYPE_SYSTEM_INFORMATION: {
+ SMBIOS_TABLE_TYPE1* Type1Record = (SMBIOS_TABLE_TYPE1*) Record;
+ Print(L"\tManufacturer=%a\n", GetRecordString(Record, Type1Record->Manufacturer));
+ Print(L"\tProductName=%a\n", GetRecordString(Record, Type1Record->ProductName));
+ Print(L"\tVersion=%a\n", GetRecordString(Record, Type1Record->Version));
+ Print(L"\tSerialNumber=%a\n", GetRecordString(Record, Type1Record->SerialNumber));
+ Print(L"\tUUID=%g\n", Type1Record->Uuid);
+ Print(L"\tWakeUpType=%d\n", Type1Record->WakeUpType);
+ Print(L"\tSKUNumber=%a\n", GetRecordString(Record, Type1Record->SKUNumber));
+ Print(L"\tFamily=%a\n", GetRecordString(Record, Type1Record->Family));
+ break;
+ }
+ default:
+ Print(L"\tTODO: Parsing for this table is not ready yet\n");
+ break;
+ }
+ Status = SmbiosProtocol->GetNext(SmbiosProtocol,
+ &SmbiosHandle,
+ NULL,
+ &Record,
+ NULL);
+ }
+
+ return EFI_SUCCESS;
+}
diff --git a/UefiLessonsPkg/SmbiosInfo/SmbiosInfo.inf b/UefiLessonsPkg/SmbiosInfo/SmbiosInfo.inf
new file mode 100644
index 0000000..ab6013a
--- /dev/null
+++ b/UefiLessonsPkg/SmbiosInfo/SmbiosInfo.inf
@@ -0,0 +1,24 @@
+[Defines]
+ INF_VERSION = 1.25
+ BASE_NAME = SmbiosInfo
+ FILE_GUID = 4a8836db-9e1d-4b7d-a785-f552340fba59
+ MODULE_TYPE = UEFI_APPLICATION
+ VERSION_STRING = 1.0
+ ENTRY_POINT = UefiMain
+
+[Sources]
+ SmbiosInfo.c
+
+[Packages]
+ MdePkg/MdePkg.dec
+
+[LibraryClasses]
+ UefiApplicationEntryPoint
+ UefiLib
+
+[Guids]
+ gEfiSmbiosTableGuid
+
+[Protocols]
+ gEfiSmbiosProtocolGuid
+
diff --git a/UefiLessonsPkg/UefiLessonsPkg.dec b/UefiLessonsPkg/UefiLessonsPkg.dec
new file mode 100644
index 0000000..8d14eec
--- /dev/null
+++ b/UefiLessonsPkg/UefiLessonsPkg.dec
@@ -0,0 +1,35 @@
+[Defines]
+ DEC_SPECIFICATION = 0x00010005
+ PACKAGE_NAME = UefiLessonsPkg
+ PACKAGE_GUID = 7e7edbba-ca2c-4177-a3f0-d3371358773a
+ PACKAGE_VERSION = 1.01
+
+[Includes]
+ Include
+
+[Guids]
+ # FILE_GUID as defined in UefiLessonsPkg/HelloWorld/HelloWorld.inf
+ gHelloWorldFileGuid = {0x2e55fa38, 0xf148, 0x42d3, {0xaf, 0x90, 0x1b, 0xe2, 0x47, 0x32, 0x3e, 0x30}}
+ gUefiLessonsPkgTokenSpaceGuid = {0x150cab53, 0xad47, 0x4385, {0xb5, 0xdd, 0xbc, 0xfc, 0x76, 0xba, 0xca, 0xf0}}
+
+[Protocols]
+ gSimpleClassProtocolGuid = { 0xb5510eea, 0x6f11, 0x4e4b, { 0xad, 0x0f, 0x35, 0xce, 0x17, 0xbd, 0x7a, 0x67 }}
+
+[PcdsFixedAtBuild]
+ gUefiLessonsPkgTokenSpaceGuid.PcdMyVar32|42|UINT32|0x00000001
+ gUefiLessonsPkgTokenSpaceGuid.PcdMyVar32_1|42|UINT32|0x00000002
+ gUefiLessonsPkgTokenSpaceGuid.PcdMyVar32_2|42|UINT32|0x00000003
+ gUefiLessonsPkgTokenSpaceGuid.PcdMyVarBool|FALSE|BOOLEAN|0x00000004
+
+[PcdsPatchableInModule]
+ gUefiLessonsPkgTokenSpaceGuid.PcdMyPatchableVar32|0x31313131|UINT32|0x10000001
+
+[PcdsFeatureFlag]
+ gUefiLessonsPkgTokenSpaceGuid.PcdMyFeatureFlagVar|FALSE|BOOLEAN|0x20000001
+
+[PcdsDynamic]
+ gUefiLessonsPkgTokenSpaceGuid.PcdMyDynamicVar32|0x38323232|UINT32|0x30000001
+ gUefiLessonsPkgTokenSpaceGuid.PcdMyDynamicVar32_1|42|UINT32|0x30000002
+
+[PcdsDynamicEx]
+ gUefiLessonsPkgTokenSpaceGuid.PcdMyDynamicExVar32|0x38333333|UINT32|0x40000001
diff --git a/UefiLessonsPkg/UefiLessonsPkg.dsc b/UefiLessonsPkg/UefiLessonsPkg.dsc
new file mode 100644
index 0000000..0bb1762
--- /dev/null
+++ b/UefiLessonsPkg/UefiLessonsPkg.dsc
@@ -0,0 +1,63 @@
+[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
+
+[PcdsFixedAtBuild]
+ gUefiLessonsPkgTokenSpaceGuid.PcdMyVar32_2|44
+