3 * Copyright (c) 2011 - 2014, ARM Limited. All rights reserved.
5 * This program and the accompanying materials
6 * are licensed and made available under the terms and conditions of the BSD License
7 * which accompanies this distribution. The full text of the license may be found at
8 * http://opensource.org/licenses/bsd-license.php
10 * THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
15 #include "BdsInternal.h"
17 #include <Guid/ArmGlobalVariableHob.h>
19 extern BDS_LOAD_OPTION_SUPPORT
*BdsLoadOptionSupportList
;
22 Worker function that displays the list of boot options that is passed in.
24 The function loops over the entries of the list of boot options that is passed
25 in. For each entry, the boot option description is displayed on a single line
26 along with the position of the option in the list. In debug mode, the UEFI
27 device path and the arguments of the boot option are displayed as well in
30 @param[in] BootOptionsList List of the boot options
36 IN LIST_ENTRY
* BootOptionsList
40 UINTN BootOptionCount
;
42 BDS_LOAD_OPTION
*BdsLoadOption
;
46 for (Entry
= GetFirstNode (BootOptionsList
);
47 !IsNull (BootOptionsList
, Entry
);
48 Entry
= GetNextNode (BootOptionsList
, Entry
)
51 BdsLoadOption
= LOAD_OPTION_FROM_LINK (Entry
);
52 Print (L
"[%d] %s\n", ++BootOptionCount
, BdsLoadOption
->Description
);
55 CHAR16
* DevicePathTxt
;
56 EFI_DEVICE_PATH_TO_TEXT_PROTOCOL
* DevicePathToTextProtocol
;
57 ARM_BDS_LOADER_TYPE LoaderType
;
58 ARM_BDS_LOADER_OPTIONAL_DATA
* OptionalData
;
60 Status
= gBS
->LocateProtocol (
61 &gEfiDevicePathToTextProtocolGuid
,
63 (VOID
**)&DevicePathToTextProtocol
65 ASSERT_EFI_ERROR (Status
);
66 DevicePathTxt
= DevicePathToTextProtocol
->ConvertDevicePathToText (
67 BdsLoadOption
->FilePathList
,
71 Print (L
"\t- %s\n", DevicePathTxt
);
73 OptionalData
= BdsLoadOption
->OptionalData
;
74 if (IS_ARM_BDS_BOOTENTRY (BdsLoadOption
)) {
75 LoaderType
= (ARM_BDS_LOADER_TYPE
)ReadUnaligned32 ((CONST UINT32
*)&OptionalData
->Header
.LoaderType
);
76 if ((LoaderType
== BDS_LOADER_KERNEL_LINUX_ATAG
) ||
77 (LoaderType
== BDS_LOADER_KERNEL_LINUX_FDT
) ) {
78 Print (L
"\t- Arguments: %a\n", &OptionalData
->Arguments
.LinuxArguments
+ 1);
80 } else if (OptionalData
!= NULL
) {
81 if (IsPrintableString (OptionalData
, &IsUnicode
)) {
83 Print (L
"\t- Arguments: %s\n", OptionalData
);
85 AsciiPrint ("\t- Arguments: %a\n", OptionalData
);
90 FreePool (DevicePathTxt
);
96 Worker function that asks for a boot option to be selected and returns a
97 pointer to the structure describing the selected boot option.
99 @param[in] BootOptionsList List of the boot options
101 @retval EFI_SUCCESS Selection succeeded
102 @retval !EFI_SUCCESS Input error or input cancelled
108 IN LIST_ENTRY
* BootOptionsList
,
109 IN CONST CHAR16
* InputStatement
,
110 OUT BDS_LOAD_OPTION_ENTRY
** BdsLoadOptionEntry
114 UINTN BootOptionCount
;
117 UINTN BootOptionSelected
;
120 // Get the number of boot options
121 Status
= GetGlobalEnvironmentVariable (
122 L
"BootOrder", NULL
, &BootOptionCount
, (VOID
**)&BootOrder
124 if (EFI_ERROR (Status
)) {
127 FreePool (BootOrder
);
128 BootOptionCount
/= sizeof (UINT16
);
130 // Check if a valid boot option(s) is found
131 if (BootOptionCount
== 0) {
132 if (StrCmp (InputStatement
, DELETE_BOOT_ENTRY
) == 0) {
133 Print (L
"Nothing to remove!\n");
134 } else if (StrCmp (InputStatement
, UPDATE_BOOT_ENTRY
) == 0) {
135 Print (L
"Nothing to update!\n");
136 } else if (StrCmp (InputStatement
, MOVE_BOOT_ENTRY
) == 0) {
137 Print (L
"Nothing to move!\n");
139 Print (L
"No supported Boot Entry.\n");
141 return EFI_NOT_FOUND
;
144 // Get the index of the boot device to delete
145 BootOptionSelected
= 0;
146 while (BootOptionSelected
== 0) {
147 Print (InputStatement
);
148 Status
= GetHIInputInteger (&BootOptionSelected
);
149 if (EFI_ERROR (Status
)) {
152 } else if ((BootOptionSelected
== 0) || (BootOptionSelected
> BootOptionCount
)) {
153 Print (L
"Invalid input (max %d)\n", BootOptionCount
);
154 BootOptionSelected
= 0;
158 // Get the structure of the Boot device to delete
160 for (Entry
= GetFirstNode (BootOptionsList
);
161 !IsNull (BootOptionsList
, Entry
);
162 Entry
= GetNextNode (BootOptionsList
,Entry
)
165 if (Index
== BootOptionSelected
) {
166 *BdsLoadOptionEntry
= LOAD_OPTION_ENTRY_FROM_LINK (Entry
);
179 OUT BDS_SUPPORTED_DEVICE
** SupportedBootDevice
183 LIST_ENTRY SupportedDeviceList
;
184 UINTN SupportedDeviceCount
;
186 UINTN SupportedDeviceSelected
;
190 // List the Boot Devices supported
193 // Start all the drivers first
194 BdsConnectAllDrivers ();
196 // List the supported devices
197 Status
= BootDeviceListSupportedInit (&SupportedDeviceList
);
198 ASSERT_EFI_ERROR(Status
);
200 SupportedDeviceCount
= 0;
201 for (Entry
= GetFirstNode (&SupportedDeviceList
);
202 !IsNull (&SupportedDeviceList
,Entry
);
203 Entry
= GetNextNode (&SupportedDeviceList
,Entry
)
206 *SupportedBootDevice
= SUPPORTED_BOOT_DEVICE_FROM_LINK(Entry
);
207 Print(L
"[%d] %s\n",SupportedDeviceCount
+1,(*SupportedBootDevice
)->Description
);
210 CHAR16
* DevicePathTxt
;
211 EFI_DEVICE_PATH_TO_TEXT_PROTOCOL
* DevicePathToTextProtocol
;
213 Status
= gBS
->LocateProtocol (&gEfiDevicePathToTextProtocolGuid
, NULL
, (VOID
**)&DevicePathToTextProtocol
);
214 ASSERT_EFI_ERROR(Status
);
215 DevicePathTxt
= DevicePathToTextProtocol
->ConvertDevicePathToText ((*SupportedBootDevice
)->DevicePathProtocol
,TRUE
,TRUE
);
217 Print(L
"\t- %s\n",DevicePathTxt
);
219 FreePool(DevicePathTxt
);
222 SupportedDeviceCount
++;
225 if (SupportedDeviceCount
== 0) {
226 Print(L
"There is no supported device.\n");
227 Status
= EFI_ABORTED
;
232 // Select the Boot Device
234 SupportedDeviceSelected
= 0;
235 while (SupportedDeviceSelected
== 0) {
236 Print(L
"Select the Boot Device: ");
237 Status
= GetHIInputInteger (&SupportedDeviceSelected
);
238 if (EFI_ERROR(Status
)) {
239 Status
= EFI_ABORTED
;
241 } else if ((SupportedDeviceSelected
== 0) || (SupportedDeviceSelected
> SupportedDeviceCount
)) {
242 Print(L
"Invalid input (max %d)\n",SupportedDeviceCount
);
243 SupportedDeviceSelected
= 0;
248 // Get the Device Path for the selected boot device
251 for (Entry
= GetFirstNode (&SupportedDeviceList
);
252 !IsNull (&SupportedDeviceList
,Entry
);
253 Entry
= GetNextNode (&SupportedDeviceList
,Entry
)
256 if (Index
== SupportedDeviceSelected
) {
257 *SupportedBootDevice
= SUPPORTED_BOOT_DEVICE_FROM_LINK(Entry
);
264 BootDeviceListSupportedFree (&SupportedDeviceList
, *SupportedBootDevice
);
269 BootMenuAddBootOption (
270 IN LIST_ENTRY
*BootOptionsList
274 BDS_SUPPORTED_DEVICE
* SupportedBootDevice
;
275 ARM_BDS_LOADER_ARGUMENTS
* BootArguments
;
276 CHAR16 BootDescription
[BOOT_DEVICE_DESCRIPTION_MAX
];
277 CHAR8 AsciiCmdLine
[BOOT_DEVICE_OPTION_MAX
];
278 CHAR16 CmdLine
[BOOT_DEVICE_OPTION_MAX
];
280 ARM_BDS_LOADER_TYPE BootType
;
281 BDS_LOAD_OPTION_ENTRY
*BdsLoadOptionEntry
;
282 EFI_DEVICE_PATH
*DevicePath
;
283 EFI_DEVICE_PATH_PROTOCOL
*DevicePathNodes
;
284 EFI_DEVICE_PATH_PROTOCOL
*InitrdPathNodes
;
285 EFI_DEVICE_PATH_PROTOCOL
*InitrdPath
;
287 BOOLEAN InitrdSupport
;
290 UINTN OptionalDataSize
;
293 SupportedBootDevice
= NULL
;
295 // List the Boot Devices supported
296 Status
= SelectBootDevice (&SupportedBootDevice
);
297 if (EFI_ERROR(Status
)) {
298 Status
= EFI_ABORTED
;
302 // Create the specific device path node
303 Status
= SupportedBootDevice
->Support
->CreateDevicePathNode (L
"EFI Application or the kernel", &DevicePathNodes
);
304 if (EFI_ERROR(Status
)) {
305 Status
= EFI_ABORTED
;
308 // Append the Device Path to the selected device path
309 DevicePath
= AppendDevicePath (SupportedBootDevice
->DevicePathProtocol
, (CONST EFI_DEVICE_PATH_PROTOCOL
*)DevicePathNodes
);
310 if (DevicePath
== NULL
) {
311 Status
= EFI_OUT_OF_RESOURCES
;
315 if (SupportedBootDevice
->Support
->RequestBootType
) {
316 Status
= BootDeviceGetType (DevicePath
, &BootType
, &Attributes
);
317 if (EFI_ERROR(Status
)) {
318 Status
= EFI_ABORTED
;
322 BootType
= BDS_LOADER_EFI_APPLICATION
;
325 if ((BootType
== BDS_LOADER_KERNEL_LINUX_ATAG
) || (BootType
== BDS_LOADER_KERNEL_LINUX_FDT
)) {
326 Print(L
"Add an initrd: ");
327 Status
= GetHIInputBoolean (&InitrdSupport
);
328 if (EFI_ERROR(Status
)) {
329 Status
= EFI_ABORTED
;
334 // Create the specific device path node
335 Status
= SupportedBootDevice
->Support
->CreateDevicePathNode (L
"initrd", &InitrdPathNodes
);
336 if (EFI_ERROR(Status
) && Status
!= EFI_NOT_FOUND
) { // EFI_NOT_FOUND is returned on empty input string, but we can boot without an initrd
337 Status
= EFI_ABORTED
;
341 if (InitrdPathNodes
!= NULL
) {
342 // Append the Device Path to the selected device path
343 InitrdPath
= AppendDevicePath (SupportedBootDevice
->DevicePathProtocol
, (CONST EFI_DEVICE_PATH_PROTOCOL
*)InitrdPathNodes
);
344 if (InitrdPath
== NULL
) {
345 Status
= EFI_OUT_OF_RESOURCES
;
355 Print(L
"Arguments to pass to the binary: ");
356 Status
= GetHIInputAscii (AsciiCmdLine
, BOOT_DEVICE_OPTION_MAX
);
357 if (EFI_ERROR(Status
)) {
358 Status
= EFI_ABORTED
;
359 goto FREE_DEVICE_PATH
;
362 CmdLineSize
= AsciiStrSize (AsciiCmdLine
);
363 InitrdSize
= GetDevicePathSize (InitrdPath
);
365 OptionalDataSize
= sizeof(ARM_BDS_LOADER_ARGUMENTS
) + CmdLineSize
+ InitrdSize
;
366 BootArguments
= (ARM_BDS_LOADER_ARGUMENTS
*)AllocatePool (OptionalDataSize
);
368 BootArguments
->LinuxArguments
.CmdLineSize
= CmdLineSize
;
369 BootArguments
->LinuxArguments
.InitrdSize
= InitrdSize
;
370 CopyMem ((VOID
*)(&BootArguments
->LinuxArguments
+ 1), AsciiCmdLine
, CmdLineSize
);
371 CopyMem ((VOID
*)((UINTN
)(&BootArguments
->LinuxArguments
+ 1) + CmdLineSize
), InitrdPath
, InitrdSize
);
373 OptionalData
= (UINT8
*)BootArguments
;
375 Print (L
"Arguments to pass to the EFI Application: ");
376 Status
= GetHIInputStr (CmdLine
, BOOT_DEVICE_OPTION_MAX
);
377 if (EFI_ERROR (Status
)) {
378 Status
= EFI_ABORTED
;
382 OptionalData
= (UINT8
*)CmdLine
;
383 OptionalDataSize
= StrSize (CmdLine
);
386 Print(L
"Description for this new Entry: ");
387 Status
= GetHIInputStr (BootDescription
, BOOT_DEVICE_DESCRIPTION_MAX
);
388 if (EFI_ERROR(Status
)) {
389 Status
= EFI_ABORTED
;
390 goto FREE_DEVICE_PATH
;
394 BdsLoadOptionEntry
= (BDS_LOAD_OPTION_ENTRY
*)AllocatePool (sizeof(BDS_LOAD_OPTION_ENTRY
));
395 Status
= BootOptionCreate (Attributes
, BootDescription
, DevicePath
, BootType
, OptionalData
, OptionalDataSize
, &BdsLoadOptionEntry
->BdsLoadOption
);
396 if (!EFI_ERROR(Status
)) {
397 InsertTailList (BootOptionsList
, &BdsLoadOptionEntry
->Link
);
401 FreePool (DevicePath
);
404 if (Status
== EFI_ABORTED
) {
407 FreePool(SupportedBootDevice
);
412 BootMenuRemoveBootOption (
413 IN LIST_ENTRY
*BootOptionsList
417 BDS_LOAD_OPTION_ENTRY
* BootOptionEntry
;
419 DisplayBootOptions (BootOptionsList
);
420 Status
= SelectBootOption (BootOptionsList
, DELETE_BOOT_ENTRY
, &BootOptionEntry
);
421 if (EFI_ERROR (Status
)) {
425 // If the Boot Option was attached to a list remove it
426 if (!IsListEmpty (&BootOptionEntry
->Link
)) {
427 // Remove the entry from the list
428 RemoveEntryList (&BootOptionEntry
->Link
);
431 // Delete the BDS Load option structures
432 BootOptionDelete (BootOptionEntry
->BdsLoadOption
);
438 BootMenuUpdateBootOption (
439 IN LIST_ENTRY
*BootOptionsList
443 BDS_LOAD_OPTION_ENTRY
*BootOptionEntry
;
444 BDS_LOAD_OPTION
*BootOption
;
445 BDS_LOAD_OPTION_SUPPORT
* DeviceSupport
;
446 ARM_BDS_LOADER_ARGUMENTS
* BootArguments
;
447 CHAR16 BootDescription
[BOOT_DEVICE_DESCRIPTION_MAX
];
448 CHAR8 CmdLine
[BOOT_DEVICE_OPTION_MAX
];
449 CHAR16 UnicodeCmdLine
[BOOT_DEVICE_OPTION_MAX
];
450 EFI_DEVICE_PATH
*DevicePath
;
451 EFI_DEVICE_PATH
*TempInitrdPath
;
452 ARM_BDS_LOADER_TYPE BootType
;
453 ARM_BDS_LOADER_OPTIONAL_DATA
* LoaderOptionalData
;
454 ARM_BDS_LINUX_ARGUMENTS
* LinuxArguments
;
455 EFI_DEVICE_PATH
*InitrdPathNodes
;
456 EFI_DEVICE_PATH
*InitrdPath
;
459 BOOLEAN InitrdSupport
;
461 UINTN OptionalDataSize
;
465 DisplayBootOptions (BootOptionsList
);
466 Status
= SelectBootOption (BootOptionsList
, UPDATE_BOOT_ENTRY
, &BootOptionEntry
);
467 if (EFI_ERROR (Status
)) {
470 BootOption
= BootOptionEntry
->BdsLoadOption
;
472 // Get the device support for this Boot Option
473 Status
= BootDeviceGetDeviceSupport (BootOption
->FilePathList
, &DeviceSupport
);
474 if (EFI_ERROR(Status
)) {
475 Print(L
"Not possible to retrieve the supported device for the update\n");
476 return EFI_UNSUPPORTED
;
479 Status
= DeviceSupport
->UpdateDevicePathNode (BootOption
->FilePathList
, L
"EFI Application or the kernel", &DevicePath
);
480 if (EFI_ERROR(Status
)) {
481 Status
= EFI_ABORTED
;
485 if (DeviceSupport
->RequestBootType
) {
486 Status
= BootDeviceGetType (DevicePath
, &BootType
, &BootOption
->Attributes
);
487 if (EFI_ERROR(Status
)) {
488 Status
= EFI_ABORTED
;
493 LoaderOptionalData
= BootOption
->OptionalData
;
494 if (LoaderOptionalData
!= NULL
) {
495 BootType
= (ARM_BDS_LOADER_TYPE
)ReadUnaligned32 ((UINT32
*)(&LoaderOptionalData
->Header
.LoaderType
));
497 BootType
= BDS_LOADER_EFI_APPLICATION
;
500 if ((BootType
== BDS_LOADER_KERNEL_LINUX_ATAG
) || (BootType
== BDS_LOADER_KERNEL_LINUX_FDT
)) {
501 LinuxArguments
= &LoaderOptionalData
->Arguments
.LinuxArguments
;
503 CmdLineSize
= ReadUnaligned16 ((CONST UINT16
*)&LinuxArguments
->CmdLineSize
);
505 InitrdSize
= ReadUnaligned16 ((CONST UINT16
*)&LinuxArguments
->InitrdSize
);
506 if (InitrdSize
> 0) {
507 Print(L
"Keep the initrd: ");
509 Print(L
"Add an initrd: ");
511 Status
= GetHIInputBoolean (&InitrdSupport
);
512 if (EFI_ERROR(Status
)) {
513 Status
= EFI_ABORTED
;
518 if (InitrdSize
> 0) {
519 // Case we update the initrd device path
520 Status
= DeviceSupport
->UpdateDevicePathNode ((EFI_DEVICE_PATH
*)((UINTN
)(LinuxArguments
+ 1) + CmdLineSize
), L
"initrd", &InitrdPath
);
521 if (EFI_ERROR(Status
) && Status
!= EFI_NOT_FOUND
) {// EFI_NOT_FOUND is returned on empty input string, but we can boot without an initrd
522 Status
= EFI_ABORTED
;
525 InitrdSize
= GetDevicePathSize (InitrdPath
);
527 // Case we create the initrd device path
529 Status
= DeviceSupport
->CreateDevicePathNode (L
"initrd", &InitrdPathNodes
);
530 if (EFI_ERROR(Status
) && Status
!= EFI_NOT_FOUND
) { // EFI_NOT_FOUND is returned on empty input string, but we can boot without an initrd
531 Status
= EFI_ABORTED
;
535 if (InitrdPathNodes
!= NULL
) {
536 // Duplicate Linux kernel Device Path
537 TempInitrdPath
= DuplicateDevicePath (BootOption
->FilePathList
);
538 // Replace Linux kernel Node by EndNode
539 SetDevicePathEndNode (GetLastDevicePathNode (TempInitrdPath
));
540 // Append the Device Path to the selected device path
541 InitrdPath
= AppendDevicePath (TempInitrdPath
, (CONST EFI_DEVICE_PATH_PROTOCOL
*)InitrdPathNodes
);
542 FreePool (TempInitrdPath
);
543 if (InitrdPath
== NULL
) {
544 Status
= EFI_OUT_OF_RESOURCES
;
547 InitrdSize
= GetDevicePathSize (InitrdPath
);
556 Print(L
"Arguments to pass to the binary: ");
557 if (CmdLineSize
> 0) {
558 AsciiStrnCpy(CmdLine
, (CONST CHAR8
*)(LinuxArguments
+ 1), CmdLineSize
);
562 Status
= EditHIInputAscii (CmdLine
, BOOT_DEVICE_OPTION_MAX
);
563 if (EFI_ERROR(Status
)) {
564 Status
= EFI_ABORTED
;
565 goto FREE_DEVICE_PATH
;
568 CmdLineSize
= AsciiStrSize (CmdLine
);
570 OptionalDataSize
= sizeof(ARM_BDS_LOADER_ARGUMENTS
) + CmdLineSize
+ InitrdSize
;
571 BootArguments
= (ARM_BDS_LOADER_ARGUMENTS
*)AllocatePool (OptionalDataSize
);
572 BootArguments
->LinuxArguments
.CmdLineSize
= CmdLineSize
;
573 BootArguments
->LinuxArguments
.InitrdSize
= InitrdSize
;
574 CopyMem (&BootArguments
->LinuxArguments
+ 1, CmdLine
, CmdLineSize
);
575 CopyMem ((VOID
*)((UINTN
)(&BootArguments
->LinuxArguments
+ 1) + CmdLineSize
), InitrdPath
, InitrdSize
);
577 OptionalData
= (UINT8
*)BootArguments
;
579 Print (L
"Arguments to pass to the EFI Application: ");
581 if (BootOption
->OptionalDataSize
> 0) {
582 IsPrintable
= IsPrintableString (BootOption
->OptionalData
, &IsUnicode
);
585 StrnCpy (UnicodeCmdLine
, BootOption
->OptionalData
, BootOption
->OptionalDataSize
/ 2);
587 AsciiStrnCpy (CmdLine
, BootOption
->OptionalData
, BootOption
->OptionalDataSize
);
591 UnicodeCmdLine
[0] = L
'\0';
596 // We do not request arguments for OptionalData that cannot be printed
599 Status
= EditHIInputStr (UnicodeCmdLine
, BOOT_DEVICE_OPTION_MAX
);
600 if (EFI_ERROR (Status
)) {
601 Status
= EFI_ABORTED
;
602 goto FREE_DEVICE_PATH
;
605 OptionalData
= (UINT8
*)UnicodeCmdLine
;
606 OptionalDataSize
= StrSize (UnicodeCmdLine
);
608 Status
= EditHIInputAscii (CmdLine
, BOOT_DEVICE_OPTION_MAX
);
609 if (EFI_ERROR (Status
)) {
610 Status
= EFI_ABORTED
;
611 goto FREE_DEVICE_PATH
;
614 OptionalData
= (UINT8
*)CmdLine
;
615 OptionalDataSize
= AsciiStrSize (CmdLine
);
618 // We keep the former OptionalData
619 OptionalData
= BootOption
->OptionalData
;
620 OptionalDataSize
= BootOption
->OptionalDataSize
;
624 Print(L
"Description for this new Entry: ");
625 StrnCpy (BootDescription
, BootOption
->Description
, BOOT_DEVICE_DESCRIPTION_MAX
);
626 Status
= EditHIInputStr (BootDescription
, BOOT_DEVICE_DESCRIPTION_MAX
);
627 if (EFI_ERROR(Status
)) {
628 Status
= EFI_ABORTED
;
629 goto FREE_DEVICE_PATH
;
633 Status
= BootOptionUpdate (BootOption
, BootOption
->Attributes
, BootDescription
, DevicePath
, BootType
, OptionalData
, OptionalDataSize
);
636 FreePool (DevicePath
);
639 if (Status
== EFI_ABORTED
) {
648 Ask for the boot option to move and then move it when up or down arrows
649 are pressed. This function is called when the user selects the "Reorder Boot
650 Device Entries" entry in the boot manager menu.
651 The order of the boot options in BootOptionList and in the UEFI BootOrder
652 global variable are kept coherent until the user confirm his reordering (ie:
653 he does not exit by pressing escape).
655 @param[in] BootOptionsList List of the boot devices constructed in
658 @retval EFI_SUCCESS No error encountered.
659 @retval !EFI_SUCCESS An error has occured either in the selection of the
660 boot option to move or while interacting with the user.
665 BootMenuReorderBootOptions (
666 IN LIST_ENTRY
*BootOptionsList
670 BDS_LOAD_OPTION_ENTRY
*BootOptionEntry
;
671 LIST_ENTRY
*SelectedEntry
;
672 LIST_ENTRY
*PrevEntry
;
678 LIST_ENTRY
*SecondEntry
;
684 DisplayBootOptions (BootOptionsList
);
686 // Ask to select the boot option to move
688 Status
= SelectBootOption (BootOptionsList
, MOVE_BOOT_ENTRY
, &BootOptionEntry
);
689 if (EFI_ERROR (Status
)) {
693 SelectedEntry
= &BootOptionEntry
->Link
;
695 // Note down the previous entry in the list to be able to cancel changes
696 PrevEntry
= GetPreviousNode (BootOptionsList
, SelectedEntry
);
698 // Start of interaction
701 L
"* Use up/down arrows to move the entry '%s'",
702 BootOptionEntry
->BdsLoadOption
->Description
705 // Wait for a move, save or cancel request
710 Status
= gBS
->WaitForEvent (1, &gST
->ConIn
->WaitForKey
, &WaitIndex
);
711 if (!EFI_ERROR (Status
)) {
712 Status
= gST
->ConIn
->ReadKeyStroke (gST
->ConIn
, &Key
);
714 if (EFI_ERROR (Status
)) {
719 switch (Key
.ScanCode
) {
721 Save
= (Key
.UnicodeChar
== CHAR_LINEFEED
) ||
722 (Key
.UnicodeChar
== CHAR_CARRIAGE_RETURN
) ||
723 (Key
.UnicodeChar
== 0x7f);
727 SecondEntry
= GetPreviousNode (BootOptionsList
, SelectedEntry
);
728 Move
= SecondEntry
!= BootOptionsList
;
732 SecondEntry
= GetNextNode (BootOptionsList
, SelectedEntry
);
733 Move
= SecondEntry
!= BootOptionsList
;
740 } while ((!Move
) && (!Save
) && (!Cancel
));
743 if ((SelectedEntry
!= NULL
) && (SecondEntry
!= NULL
)) {
744 SwapListEntries (SelectedEntry
, SecondEntry
);
748 Status
= GetGlobalEnvironmentVariable (
749 L
"BootOrder", NULL
, &BootOrderSize
, (VOID
**)&BootOrder
751 BootOrderSize
/= sizeof (UINT16
);
753 if (!EFI_ERROR (Status
)) {
754 // The order of the boot options in the 'BootOptionsList' is the
755 // new order that has been just defined by the user. Save this new
756 // order in "BootOrder" UEFI global variable.
757 Entry
= GetFirstNode (BootOptionsList
);
758 for (Index
= 0; Index
< BootOrderSize
; Index
++) {
759 BootOrder
[Index
] = (LOAD_OPTION_FROM_LINK (Entry
))->LoadOptionIndex
;
760 Entry
= GetNextNode (BootOptionsList
, Entry
);
762 Status
= gRT
->SetVariable (
763 (CHAR16
*)L
"BootOrder",
764 &gEfiGlobalVariableGuid
,
765 EFI_VARIABLE_NON_VOLATILE
|
766 EFI_VARIABLE_BOOTSERVICE_ACCESS
|
767 EFI_VARIABLE_RUNTIME_ACCESS
,
768 BootOrderSize
* sizeof (UINT16
),
771 FreePool (BootOrder
);
774 if (EFI_ERROR (Status
)) {
775 Print (L
"\nAn error occurred, move not completed!\n");
782 // Restore initial position of the selected boot option
784 RemoveEntryList (SelectedEntry
);
785 InsertHeadList (PrevEntry
, SelectedEntry
);
790 DisplayBootOptions (BootOptionsList
);
791 // Saved or cancelled, back to the choice of boot option to move
804 IN LIST_ENTRY
*BootOptionsList
808 UINTN FdtDevicePathSize
;
809 BDS_SUPPORTED_DEVICE
*SupportedBootDevice
;
810 EFI_DEVICE_PATH_PROTOCOL
*FdtDevicePathNodes
;
811 EFI_DEVICE_PATH_PROTOCOL
*FdtDevicePath
;
813 Status
= SelectBootDevice (&SupportedBootDevice
);
814 if (EFI_ERROR(Status
)) {
815 Status
= EFI_ABORTED
;
819 // Create the specific device path node
820 Status
= SupportedBootDevice
->Support
->CreateDevicePathNode (L
"FDT blob", &FdtDevicePathNodes
);
821 if (EFI_ERROR(Status
)) {
822 Status
= EFI_ABORTED
;
826 if (FdtDevicePathNodes
!= NULL
) {
827 // Append the Device Path node to the select device path
828 FdtDevicePath
= AppendDevicePath (SupportedBootDevice
->DevicePathProtocol
, FdtDevicePathNodes
);
829 FdtDevicePathSize
= GetDevicePathSize (FdtDevicePath
);
830 Status
= gRT
->SetVariable (
832 &gArmGlobalVariableGuid
,
833 EFI_VARIABLE_RUNTIME_ACCESS
| EFI_VARIABLE_NON_VOLATILE
| EFI_VARIABLE_BOOTSERVICE_ACCESS
,
837 ASSERT_EFI_ERROR(Status
);
841 &gArmGlobalVariableGuid
,
842 EFI_VARIABLE_RUNTIME_ACCESS
| EFI_VARIABLE_NON_VOLATILE
| EFI_VARIABLE_BOOTSERVICE_ACCESS
,
846 ASSERT_EFI_ERROR(Status
);
850 if (Status
== EFI_ABORTED
) {
853 FreePool(SupportedBootDevice
);
860 Ask for the boot timeout in seconds and if the input succeeds assign the
861 input value to the UEFI global variable "Timeout". This function is called
862 when the user selects the "Set Boot Timeout" of the boot manager menu.
864 @param[in] BootOptionsList List of the boot devices, not used here
866 @retval EFI_SUCCESS Boot timeout in second retrieved from the standard
867 input and assigned to the UEFI "Timeout" global
869 @retval !EFI_SUCCESS Either the input or the setting of the UEFI global
870 variable "Timeout" has failed.
874 BootMenuSetBootTimeout (
875 IN LIST_ENTRY
*BootOptionsList
882 Print (L
"Timeout duration (in seconds): ");
883 Status
= GetHIInputInteger (&Input
);
884 if (EFI_ERROR (Status
)) {
890 Status
= gRT
->SetVariable (
892 &gEfiGlobalVariableGuid
,
893 EFI_VARIABLE_NON_VOLATILE
|
894 EFI_VARIABLE_BOOTSERVICE_ACCESS
|
895 EFI_VARIABLE_RUNTIME_ACCESS
,
899 ASSERT_EFI_ERROR (Status
);
905 struct BOOT_MANAGER_ENTRY
{
906 CONST CHAR16
* Description
;
907 EFI_STATUS (*Callback
) (IN LIST_ENTRY
*BootOptionsList
);
908 } BootManagerEntries
[] = {
909 { L
"Add Boot Device Entry", BootMenuAddBootOption
},
910 { L
"Update Boot Device Entry", BootMenuUpdateBootOption
},
911 { L
"Remove Boot Device Entry", BootMenuRemoveBootOption
},
912 { L
"Reorder Boot Device Entries", BootMenuReorderBootOptions
},
913 { L
"Update FDT path", UpdateFdtPath
},
914 { L
"Set Boot Timeout", BootMenuSetBootTimeout
},
919 IN LIST_ENTRY
*BootOptionsList
923 UINTN OptionSelected
;
924 UINTN BootManagerEntryCount
;
927 BootManagerEntryCount
= sizeof(BootManagerEntries
) / sizeof(struct BOOT_MANAGER_ENTRY
);
930 // Display Boot Manager menu
931 for (Index
= 0; Index
< BootManagerEntryCount
; Index
++) {
932 Print(L
"[%d] %s\n",Index
+1,BootManagerEntries
[Index
]);
934 Print(L
"[%d] Return to main menu\n",Index
+1);
936 // Select which entry to call
938 Status
= GetHIInputInteger (&OptionSelected
);
939 if (EFI_ERROR(Status
) || (OptionSelected
== (BootManagerEntryCount
+1))) {
940 if (EFI_ERROR(Status
)) {
944 } else if ((OptionSelected
> 0) && (OptionSelected
<= BootManagerEntryCount
)) {
945 BootManagerEntries
[OptionSelected
-1].Callback (BootOptionsList
);
948 // Should never go here
953 IN LIST_ENTRY
*BootOptionsList
959 Status
= BdsLoadApplication (gImageHandle
, L
"Shell", 0, NULL
);
960 if (Status
== EFI_NOT_FOUND
) {
961 Print (L
"Error: EFI Application not found.\n");
962 } else if (EFI_ERROR(Status
)) {
963 Print (L
"Error: Status Code: 0x%X\n",(UINT32
)Status
);
969 struct BOOT_MAIN_ENTRY
{
970 CONST CHAR16
* Description
;
971 EFI_STATUS (*Callback
) (IN LIST_ENTRY
*BootOptionsList
);
972 } BootMainEntries
[] = {
973 { L
"Shell", BootShell
},
974 { L
"Boot Manager", BootMenuManager
},
983 LIST_ENTRY BootOptionsList
;
985 UINTN BootOptionCount
;
988 BDS_LOAD_OPTION
* BootOption
;
989 UINTN BootOptionSelected
;
991 UINTN BootMainEntryCount
;
995 BootMainEntryCount
= sizeof(BootMainEntries
) / sizeof(struct BOOT_MAIN_ENTRY
);
999 BootOptionList (&BootOptionsList
);
1003 // Display the Boot options
1004 for (Entry
= GetFirstNode (&BootOptionsList
);
1005 !IsNull (&BootOptionsList
,Entry
);
1006 Entry
= GetNextNode (&BootOptionsList
,Entry
)
1009 BootOption
= LOAD_OPTION_FROM_LINK(Entry
);
1011 Print(L
"[%d] %s\n", OptionCount
, BootOption
->Description
);
1014 CHAR16
* DevicePathTxt
;
1015 EFI_DEVICE_PATH_TO_TEXT_PROTOCOL
* DevicePathToTextProtocol
;
1016 ARM_BDS_LOADER_OPTIONAL_DATA
* OptionalData
;
1018 ARM_BDS_LOADER_TYPE LoaderType
;
1020 Status
= gBS
->LocateProtocol (&gEfiDevicePathToTextProtocolGuid
, NULL
, (VOID
**)&DevicePathToTextProtocol
);
1021 if (EFI_ERROR(Status
)) {
1022 // You must provide an implementation of DevicePathToTextProtocol in your firmware (eg: DevicePathDxe)
1023 DEBUG((EFI_D_ERROR
,"Error: Bds requires DevicePathToTextProtocol\n"));
1026 DevicePathTxt
= DevicePathToTextProtocol
->ConvertDevicePathToText (BootOption
->FilePathList
, TRUE
, TRUE
);
1028 Print(L
"\t- %s\n",DevicePathTxt
);
1030 // If it is a supported BootEntry then print its details
1031 if (IS_ARM_BDS_BOOTENTRY (BootOption
)) {
1032 OptionalData
= BootOption
->OptionalData
;
1033 LoaderType
= (ARM_BDS_LOADER_TYPE
)ReadUnaligned32 ((CONST UINT32
*)&OptionalData
->Header
.LoaderType
);
1034 if ((LoaderType
== BDS_LOADER_KERNEL_LINUX_ATAG
) || (LoaderType
== BDS_LOADER_KERNEL_LINUX_FDT
)) {
1035 if (ReadUnaligned16 (&OptionalData
->Arguments
.LinuxArguments
.InitrdSize
) > 0) {
1036 CmdLineSize
= ReadUnaligned16 (&OptionalData
->Arguments
.LinuxArguments
.CmdLineSize
);
1037 DevicePathTxt
= DevicePathToTextProtocol
->ConvertDevicePathToText (
1038 GetAlignedDevicePath ((EFI_DEVICE_PATH
*)((UINTN
)(&OptionalData
->Arguments
.LinuxArguments
+ 1) + CmdLineSize
)), TRUE
, TRUE
);
1039 Print(L
"\t- Initrd: %s\n", DevicePathTxt
);
1041 if (ReadUnaligned16 (&OptionalData
->Arguments
.LinuxArguments
.CmdLineSize
) > 0) {
1042 Print(L
"\t- Arguments: %a\n", (&OptionalData
->Arguments
.LinuxArguments
+ 1));
1046 switch (LoaderType
) {
1047 case BDS_LOADER_EFI_APPLICATION
:
1048 Print(L
"\t- LoaderType: EFI Application\n");
1051 case BDS_LOADER_KERNEL_LINUX_ATAG
:
1052 Print(L
"\t- LoaderType: Linux kernel with ATAG support\n");
1055 case BDS_LOADER_KERNEL_LINUX_FDT
:
1056 Print(L
"\t- LoaderType: Linux kernel with FDT support\n");
1060 Print(L
"\t- LoaderType: Not recognized (%d)\n", LoaderType
);
1062 } else if (BootOption
->OptionalData
!= NULL
) {
1063 if (IsPrintableString (BootOption
->OptionalData
, &IsUnicode
)) {
1065 Print (L
"\t- Arguments: %s\n", BootOption
->OptionalData
);
1067 AsciiPrint ("\t- Arguments: %a\n", BootOption
->OptionalData
);
1071 FreePool(DevicePathTxt
);
1076 BootOptionCount
= OptionCount
-1;
1078 // Display the hardcoded Boot entries
1079 for (Index
= 0; Index
< BootMainEntryCount
; Index
++) {
1080 Print(L
"[%d] %s\n",OptionCount
,BootMainEntries
[Index
]);
1084 // Request the boot entry from the user
1085 BootOptionSelected
= 0;
1086 while (BootOptionSelected
== 0) {
1088 Status
= GetHIInputInteger (&BootOptionSelected
);
1089 if (EFI_ERROR(Status
) || (BootOptionSelected
== 0) || (BootOptionSelected
> OptionCount
)) {
1090 Print(L
"Invalid input (max %d)\n",(OptionCount
-1));
1091 BootOptionSelected
= 0;
1095 // Start the selected entry
1096 if (BootOptionSelected
> BootOptionCount
) {
1097 // Start the hardcoded entry
1098 Status
= BootMainEntries
[BootOptionSelected
- BootOptionCount
- 1].Callback (&BootOptionsList
);
1100 // Find the selected entry from the Boot#### list
1102 for (Entry
= GetFirstNode (&BootOptionsList
);
1103 !IsNull (&BootOptionsList
,Entry
);
1104 Entry
= GetNextNode (&BootOptionsList
,Entry
)
1107 if (Index
== BootOptionSelected
) {
1108 BootOption
= LOAD_OPTION_FROM_LINK(Entry
);
1114 Status
= BootOptionStart (BootOption
);
1117 // Should never go here