aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKonstantin Aladyshev <aladyshev22@gmail.com>2021-07-14 16:48:11 +0300
committerKonstantin Aladyshev <aladyshev22@gmail.com>2021-07-14 16:48:11 +0300
commit713789e49430ca2442ce541bb69bcb8b40487747 (patch)
treeefbde66a26d87795ae8fcf67307eebb53fd44b6c
parent6c7c10adfb301214b64c698d2874828c7a809361 (diff)
downloadUEFI-Lessons-713789e49430ca2442ce541bb69bcb8b40487747.tar.gz
UEFI-Lessons-713789e49430ca2442ce541bb69bcb8b40487747.tar.bz2
UEFI-Lessons-713789e49430ca2442ce541bb69bcb8b40487747.zip
Add missed packages to the UefiLessonsPkg
Signed-off-by: Konstantin Aladyshev <aladyshev22@gmail.com>
-rw-r--r--UefiLessonsPkg/SaveBGRT/SaveBGRT.c104
-rw-r--r--UefiLessonsPkg/SaveBGRT/SaveBGRT.inf23
-rw-r--r--UefiLessonsPkg/ShowTables/ShowTables.c16
-rw-r--r--UefiLessonsPkg/ShowTables/ShowTables.inf18
4 files changed, 161 insertions, 0 deletions
diff --git a/UefiLessonsPkg/SaveBGRT/SaveBGRT.c b/UefiLessonsPkg/SaveBGRT/SaveBGRT.c
new file mode 100644
index 0000000..2fda8d8
--- /dev/null
+++ b/UefiLessonsPkg/SaveBGRT/SaveBGRT.c
@@ -0,0 +1,104 @@
+#include <Library/UefiBootServicesTableLib.h>
+#include <Library/UefiLib.h>
+
+#include <Protocol/AcpiSystemDescriptionTable.h>
+#include <Library/ShellLib.h>
+#include <IndustryStandard/Bmp.h>
+
+EFI_STATUS WriteFile(CHAR16* FileName, VOID* Data, UINTN* Size)
+{
+ SHELL_FILE_HANDLE FileHandle;
+ EFI_STATUS Status = ShellOpenFileByName(
+ FileName,
+ &FileHandle,
+ EFI_FILE_MODE_CREATE | EFI_FILE_MODE_WRITE | EFI_FILE_MODE_READ,
+ 0
+ );
+ if (!EFI_ERROR(Status)) {
+ Print(L"Save it to %s\n", FileName);
+ UINTN ToWrite = *Size;
+ Status = ShellWriteFile(
+ FileHandle,
+ Size,
+ Data
+ );
+ if (EFI_ERROR(Status)) {
+ Print(L"Can't write file: %r\n", Status);
+ }
+ if (*Size != ToWrite) {
+ Print(L"Error! Not all data was written\n");
+ }
+ Status = ShellCloseFile(
+ &FileHandle
+ );
+ if (EFI_ERROR(Status)) {
+ Print(L"Can't close file: %r\n", Status);
+ }
+ } else {
+ Print(L"Can't open file: %r\n", Status);
+ }
+ return Status;
+}
+
+EFI_STATUS
+EFIAPI
+UefiMain (
+ IN EFI_HANDLE ImageHandle,
+ IN EFI_SYSTEM_TABLE *SystemTable
+ )
+{
+ EFI_ACPI_SDT_PROTOCOL* AcpiSdtProtocol;
+ EFI_STATUS Status = gBS->LocateProtocol (
+ &gEfiAcpiSdtProtocolGuid,
+ NULL,
+ (VOID**)&AcpiSdtProtocol
+ );
+ if (EFI_ERROR (Status)) {
+ return Status;
+ }
+
+ BOOLEAN BGRT_found = FALSE;
+ UINTN Index = 0;
+ EFI_ACPI_SDT_HEADER* Table;
+ EFI_ACPI_TABLE_VERSION Version;
+ UINTN TableKey;
+ while (TRUE) {
+ Status = AcpiSdtProtocol->GetAcpiTable(Index,
+ &Table,
+ &Version,
+ &TableKey
+ );
+ if (EFI_ERROR(Status)) {
+ break;
+ }
+ if (((CHAR8)((Table->Signature >> 0) & 0xFF) == 'B') &&
+ ((CHAR8)((Table->Signature >> 8) & 0xFF) == 'G') &&
+ ((CHAR8)((Table->Signature >> 16) & 0xFF) == 'R') &&
+ ((CHAR8)((Table->Signature >> 24) & 0xFF) == 'T')) {
+ BGRT_found = TRUE;
+ break;
+ }
+ Index++;
+ }
+ if (!BGRT_found) {
+ Print(L"BGRT table is not present in the system\n");
+ return EFI_UNSUPPORTED;
+ }
+
+ EFI_ACPI_6_3_BOOT_GRAPHICS_RESOURCE_TABLE* BGRT = (EFI_ACPI_6_3_BOOT_GRAPHICS_RESOURCE_TABLE*)Table;
+ if (BGRT->ImageType == 0) {
+ BMP_IMAGE_HEADER* BMP = (BMP_IMAGE_HEADER*)(BGRT->ImageAddress);
+
+ if ((BMP->CharB != 'B') || (BMP->CharM != 'M')) {
+ Print(L"BMP image has wrong signature!\n");
+ return EFI_UNSUPPORTED;
+ }
+ Print(L"BGRT conatins BMP image with %dx%d resolution\n", BMP->PixelWidth, BMP->PixelHeight);
+ UINTN Size = BMP->Size;
+ Status = WriteFile(L"BGRT.bmp", BMP, &Size);
+ if (EFI_ERROR(Status)) {
+ Print(L"Error! Can't write BGRT.bmp file\n");
+ }
+ }
+ return Status;
+}
diff --git a/UefiLessonsPkg/SaveBGRT/SaveBGRT.inf b/UefiLessonsPkg/SaveBGRT/SaveBGRT.inf
new file mode 100644
index 0000000..93ab1b9
--- /dev/null
+++ b/UefiLessonsPkg/SaveBGRT/SaveBGRT.inf
@@ -0,0 +1,23 @@
+[Defines]
+ INF_VERSION = 1.25
+ BASE_NAME = SaveBGRT
+ FILE_GUID = efe33e23-b17c-42b2-9551-87546f215935
+ MODULE_TYPE = UEFI_APPLICATION
+ VERSION_STRING = 1.0
+ ENTRY_POINT = UefiMain
+
+[Sources]
+ SaveBGRT.c
+
+[Packages]
+ MdePkg/MdePkg.dec
+ ShellPkg/ShellPkg.dec
+
+[LibraryClasses]
+ UefiApplicationEntryPoint
+ UefiLib
+ ShellLib
+
+[Protocols]
+ gEfiAcpiSdtProtocolGuid
+
diff --git a/UefiLessonsPkg/ShowTables/ShowTables.c b/UefiLessonsPkg/ShowTables/ShowTables.c
new file mode 100644
index 0000000..aa32f41
--- /dev/null
+++ b/UefiLessonsPkg/ShowTables/ShowTables.c
@@ -0,0 +1,16 @@
+#include <Library/UefiBootServicesTableLib.h>
+#include <Library/UefiLib.h>
+
+EFI_STATUS
+EFIAPI
+UefiMain (
+ IN EFI_HANDLE ImageHandle,
+ IN EFI_SYSTEM_TABLE *SystemTable
+ )
+{
+ for (UINTN i=0; i<SystemTable->NumberOfTableEntries; i++) {
+ Print(L"%g, %p\n", SystemTable->ConfigurationTable[i].VendorGuid,
+ SystemTable->ConfigurationTable[i].VendorTable);
+ }
+ return EFI_SUCCESS;
+}
diff --git a/UefiLessonsPkg/ShowTables/ShowTables.inf b/UefiLessonsPkg/ShowTables/ShowTables.inf
new file mode 100644
index 0000000..056b823
--- /dev/null
+++ b/UefiLessonsPkg/ShowTables/ShowTables.inf
@@ -0,0 +1,18 @@
+[Defines]
+ INF_VERSION = 1.25
+ BASE_NAME = ShowTables
+ FILE_GUID = e249532c-d41a-4bd9-a4a8-7fc143e703f2
+ MODULE_TYPE = UEFI_APPLICATION
+ VERSION_STRING = 1.0
+ ENTRY_POINT = UefiMain
+
+[Sources]
+ ShowTables.c
+
+[Packages]
+ MdePkg/MdePkg.dec
+
+[LibraryClasses]
+ UefiApplicationEntryPoint
+ UefiLib
+