+ The function loops over the entries of the list of boot options that is passed\r
+ in. For each entry, the boot option description is displayed on a single line\r
+ along with the position of the option in the list. In debug mode, the UEFI\r
+ device path and the arguments of the boot option are displayed as well in\r
+ subsequent lines.\r
+\r
+ @param[in] BootOptionsList List of the boot options\r
+\r
+**/\r
+STATIC\r
+VOID\r
+DisplayBootOptions (\r
+ IN LIST_ENTRY* BootOptionsList\r
+ )\r
+{\r
+ EFI_STATUS Status;\r
+ UINTN BootOptionCount;\r
+ LIST_ENTRY *Entry;\r
+ BDS_LOAD_OPTION *BdsLoadOption;\r
+ BOOLEAN IsUnicode;\r
+\r
+ BootOptionCount = 0 ;\r
+ for (Entry = GetFirstNode (BootOptionsList);\r
+ !IsNull (BootOptionsList, Entry);\r
+ Entry = GetNextNode (BootOptionsList, Entry)\r
+ ) {\r
+\r
+ BdsLoadOption = LOAD_OPTION_FROM_LINK (Entry);\r
+ Print (L"[%d] %s\n", ++BootOptionCount, BdsLoadOption->Description);\r
+\r
+ DEBUG_CODE_BEGIN ();\r
+ CHAR16* DevicePathTxt;\r
+ EFI_DEVICE_PATH_TO_TEXT_PROTOCOL* DevicePathToTextProtocol;\r
+ ARM_BDS_LOADER_TYPE LoaderType;\r
+ ARM_BDS_LOADER_OPTIONAL_DATA* OptionalData;\r
+\r
+ Status = gBS->LocateProtocol (\r
+ &gEfiDevicePathToTextProtocolGuid,\r
+ NULL,\r
+ (VOID **)&DevicePathToTextProtocol\r
+ );\r
+ ASSERT_EFI_ERROR (Status);\r
+ DevicePathTxt = DevicePathToTextProtocol->ConvertDevicePathToText (\r
+ BdsLoadOption->FilePathList,\r
+ TRUE,\r
+ TRUE\r
+ );\r
+ Print (L"\t- %s\n", DevicePathTxt);\r
+\r
+ OptionalData = BdsLoadOption->OptionalData;\r
+ if (IS_ARM_BDS_BOOTENTRY (BdsLoadOption)) {\r
+ LoaderType = (ARM_BDS_LOADER_TYPE)ReadUnaligned32 ((CONST UINT32*)&OptionalData->Header.LoaderType);\r
+ if ((LoaderType == BDS_LOADER_KERNEL_LINUX_ATAG) ||\r
+ (LoaderType == BDS_LOADER_KERNEL_LINUX_FDT ) ) {\r
+ Print (L"\t- Arguments: %a\n", &OptionalData->Arguments.LinuxArguments + 1);\r
+ }\r
+ } else if (OptionalData != NULL) {\r
+ if (IsPrintableString (OptionalData, &IsUnicode)) {\r
+ if (IsUnicode) {\r
+ Print (L"\t- Arguments: %s\n", OptionalData);\r
+ } else {\r
+ AsciiPrint ("\t- Arguments: %a\n", OptionalData);\r
+ }\r
+ }\r
+ }\r
+\r
+ FreePool (DevicePathTxt);\r
+ DEBUG_CODE_END ();\r
+ }\r
+}\r
+\r
+/**\r
+ Worker function that asks for a boot option to be selected and returns a\r
+ pointer to the structure describing the selected boot option.\r
+\r
+ @param[in] BootOptionsList List of the boot options\r
+\r
+ @retval EFI_SUCCESS Selection succeeded\r
+ @retval !EFI_SUCCESS Input error or input cancelled\r
+\r
+**/\r
+STATIC\r
+EFI_STATUS\r
+SelectBootOption (\r
+ IN LIST_ENTRY* BootOptionsList,\r
+ IN CONST CHAR16* InputStatement,\r
+ OUT BDS_LOAD_OPTION_ENTRY** BdsLoadOptionEntry\r
+ )\r
+{\r
+ EFI_STATUS Status;\r
+ UINTN BootOptionCount;\r
+ UINT16 *BootOrder;\r
+ LIST_ENTRY* Entry;\r
+ UINTN BootOptionSelected;\r
+ UINTN Index;\r
+\r
+ // Get the number of boot options\r
+ Status = GetGlobalEnvironmentVariable (\r
+ L"BootOrder", NULL, &BootOptionCount, (VOID**)&BootOrder\r
+ );\r
+ if (EFI_ERROR (Status)) {\r
+ goto ErrorExit;\r
+ }\r
+ FreePool (BootOrder);\r
+ BootOptionCount /= sizeof (UINT16);\r
+\r
+ // Check if a valid boot option(s) is found\r
+ if (BootOptionCount == 0) {\r
+ if (StrCmp (InputStatement, DELETE_BOOT_ENTRY) == 0) {\r
+ Print (L"Nothing to remove!\n");\r
+ } else if (StrCmp (InputStatement, UPDATE_BOOT_ENTRY) == 0) {\r
+ Print (L"Nothing to update!\n");\r
+ } else if (StrCmp (InputStatement, MOVE_BOOT_ENTRY) == 0) {\r
+ Print (L"Nothing to move!\n");\r
+ } else {\r
+ Print (L"No supported Boot Entry.\n");\r
+ }\r
+ return EFI_NOT_FOUND;\r
+ }\r
+\r
+ // Get the index of the boot device to delete\r
+ BootOptionSelected = 0;\r
+ while (BootOptionSelected == 0) {\r
+ Print (InputStatement);\r
+ Status = GetHIInputInteger (&BootOptionSelected);\r
+ if (EFI_ERROR (Status)) {\r
+ Print (L"\n");\r
+ goto ErrorExit;\r
+ } else if ((BootOptionSelected == 0) || (BootOptionSelected > BootOptionCount)) {\r
+ Print (L"Invalid input (max %d)\n", BootOptionCount);\r
+ BootOptionSelected = 0;\r
+ }\r
+ }\r
+\r
+ // Get the structure of the Boot device to delete\r
+ Index = 1;\r
+ for (Entry = GetFirstNode (BootOptionsList);\r
+ !IsNull (BootOptionsList, Entry);\r
+ Entry = GetNextNode (BootOptionsList,Entry)\r
+ )\r
+ {\r
+ if (Index == BootOptionSelected) {\r
+ *BdsLoadOptionEntry = LOAD_OPTION_ENTRY_FROM_LINK (Entry);\r
+ break;\r
+ }\r
+ Index++;\r
+ }\r
+\r
+ErrorExit:\r
+ return Status;\r
+}\r
+\r
+STATIC\r