aboutsummaryrefslogtreecommitdiffstats
path: root/Lesson_29/UefiLessonsPkg/ShowBootVariables
diff options
context:
space:
mode:
authorKonstantin Aladyshev <aladyshev22@gmail.com>2021-07-03 16:21:52 +0300
committerKonstantin Aladyshev <aladyshev22@gmail.com>2021-07-03 16:21:52 +0300
commite74febc523101b82671160078173acd650f76dc2 (patch)
treeb30a18d9d6b85547eb0c42751f3dabffc7805cbf /Lesson_29/UefiLessonsPkg/ShowBootVariables
parent0872ca11d741d039846c8b301eed1d720d640ed0 (diff)
downloadUEFI-Lessons-e74febc523101b82671160078173acd650f76dc2.tar.gz
UEFI-Lessons-e74febc523101b82671160078173acd650f76dc2.tar.bz2
UEFI-Lessons-e74febc523101b82671160078173acd650f76dc2.zip
Add source files for lesson 29
Signed-off-by: Konstantin Aladyshev <aladyshev22@gmail.com>
Diffstat (limited to 'Lesson_29/UefiLessonsPkg/ShowBootVariables')
-rw-r--r--Lesson_29/UefiLessonsPkg/ShowBootVariables/ShowBootVariables.c93
-rw-r--r--Lesson_29/UefiLessonsPkg/ShowBootVariables/ShowBootVariables.inf19
2 files changed, 112 insertions, 0 deletions
diff --git a/Lesson_29/UefiLessonsPkg/ShowBootVariables/ShowBootVariables.c b/Lesson_29/UefiLessonsPkg/ShowBootVariables/ShowBootVariables.c
new file mode 100644
index 0000000..7f6b58c
--- /dev/null
+++ b/Lesson_29/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/Lesson_29/UefiLessonsPkg/ShowBootVariables/ShowBootVariables.inf b/Lesson_29/UefiLessonsPkg/ShowBootVariables/ShowBootVariables.inf
new file mode 100644
index 0000000..d2cfba9
--- /dev/null
+++ b/Lesson_29/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
+