3 * Copyright (c) 2011-2013, 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 EFI_HANDLE mImageHandle
;
20 extern BDS_LOAD_OPTION_SUPPORT
*BdsLoadOptionSupportList
;
25 OUT BDS_SUPPORTED_DEVICE
** SupportedBootDevice
29 LIST_ENTRY SupportedDeviceList
;
30 UINTN SupportedDeviceCount
;
32 UINTN SupportedDeviceSelected
;
36 // List the Boot Devices supported
39 // Start all the drivers first
40 BdsConnectAllDrivers ();
42 // List the supported devices
43 Status
= BootDeviceListSupportedInit (&SupportedDeviceList
);
44 ASSERT_EFI_ERROR(Status
);
46 SupportedDeviceCount
= 0;
47 for (Entry
= GetFirstNode (&SupportedDeviceList
);
48 !IsNull (&SupportedDeviceList
,Entry
);
49 Entry
= GetNextNode (&SupportedDeviceList
,Entry
)
52 *SupportedBootDevice
= SUPPORTED_BOOT_DEVICE_FROM_LINK(Entry
);
53 Print(L
"[%d] %s\n",SupportedDeviceCount
+1,(*SupportedBootDevice
)->Description
);
56 CHAR16
* DevicePathTxt
;
57 EFI_DEVICE_PATH_TO_TEXT_PROTOCOL
* DevicePathToTextProtocol
;
59 Status
= gBS
->LocateProtocol (&gEfiDevicePathToTextProtocolGuid
, NULL
, (VOID
**)&DevicePathToTextProtocol
);
60 ASSERT_EFI_ERROR(Status
);
61 DevicePathTxt
= DevicePathToTextProtocol
->ConvertDevicePathToText ((*SupportedBootDevice
)->DevicePathProtocol
,TRUE
,TRUE
);
63 Print(L
"\t- %s\n",DevicePathTxt
);
65 FreePool(DevicePathTxt
);
68 SupportedDeviceCount
++;
71 if (SupportedDeviceCount
== 0) {
72 Print(L
"There is no supported device.\n");
78 // Select the Boot Device
80 SupportedDeviceSelected
= 0;
81 while (SupportedDeviceSelected
== 0) {
82 Print(L
"Select the Boot Device: ");
83 Status
= GetHIInputInteger (&SupportedDeviceSelected
);
84 if (EFI_ERROR(Status
)) {
87 } else if ((SupportedDeviceSelected
== 0) || (SupportedDeviceSelected
> SupportedDeviceCount
)) {
88 Print(L
"Invalid input (max %d)\n",SupportedDeviceCount
);
89 SupportedDeviceSelected
= 0;
94 // Get the Device Path for the selected boot device
97 for (Entry
= GetFirstNode (&SupportedDeviceList
);
98 !IsNull (&SupportedDeviceList
,Entry
);
99 Entry
= GetNextNode (&SupportedDeviceList
,Entry
)
102 if (Index
== SupportedDeviceSelected
) {
103 *SupportedBootDevice
= SUPPORTED_BOOT_DEVICE_FROM_LINK(Entry
);
110 BootDeviceListSupportedFree (&SupportedDeviceList
, *SupportedBootDevice
);
115 BootMenuAddBootOption (
116 IN LIST_ENTRY
*BootOptionsList
120 BDS_SUPPORTED_DEVICE
* SupportedBootDevice
;
121 ARM_BDS_LOADER_ARGUMENTS
* BootArguments
;
122 CHAR16 BootDescription
[BOOT_DEVICE_DESCRIPTION_MAX
];
123 CHAR8 CmdLine
[BOOT_DEVICE_OPTION_MAX
];
125 ARM_BDS_LOADER_TYPE BootType
;
126 BDS_LOAD_OPTION_ENTRY
*BdsLoadOptionEntry
;
127 EFI_DEVICE_PATH
*DevicePath
;
128 EFI_DEVICE_PATH_PROTOCOL
*DevicePathNodes
;
129 EFI_DEVICE_PATH_PROTOCOL
*InitrdPathNodes
;
130 EFI_DEVICE_PATH_PROTOCOL
*InitrdPath
;
132 BOOLEAN InitrdSupport
;
136 SupportedBootDevice
= NULL
;
138 // List the Boot Devices supported
139 Status
= SelectBootDevice (&SupportedBootDevice
);
140 if (EFI_ERROR(Status
)) {
141 Status
= EFI_ABORTED
;
145 // Create the specific device path node
146 Status
= SupportedBootDevice
->Support
->CreateDevicePathNode (L
"EFI Application or the kernel", &DevicePathNodes
, &BootType
, &Attributes
);
147 if (EFI_ERROR(Status
)) {
148 Status
= EFI_ABORTED
;
151 // Append the Device Path to the selected device path
152 DevicePath
= AppendDevicePath (SupportedBootDevice
->DevicePathProtocol
, (CONST EFI_DEVICE_PATH_PROTOCOL
*)DevicePathNodes
);
153 if (DevicePath
== NULL
) {
154 Status
= EFI_OUT_OF_RESOURCES
;
158 if ((BootType
== BDS_LOADER_KERNEL_LINUX_ATAG
) || (BootType
== BDS_LOADER_KERNEL_LINUX_FDT
)) {
159 Print(L
"Add an initrd: ");
160 Status
= GetHIInputBoolean (&InitrdSupport
);
161 if (EFI_ERROR(Status
)) {
162 Status
= EFI_ABORTED
;
167 // Create the specific device path node
168 Status
= SupportedBootDevice
->Support
->CreateDevicePathNode (L
"initrd", &InitrdPathNodes
, NULL
, NULL
);
169 if (EFI_ERROR(Status
) && Status
!= EFI_NOT_FOUND
) { // EFI_NOT_FOUND is returned on empty input string, but we can boot without an initrd
170 Status
= EFI_ABORTED
;
174 if (InitrdPathNodes
!= NULL
) {
175 // Append the Device Path to the selected device path
176 InitrdPath
= AppendDevicePath (SupportedBootDevice
->DevicePathProtocol
, (CONST EFI_DEVICE_PATH_PROTOCOL
*)InitrdPathNodes
);
177 if (InitrdPath
== NULL
) {
178 Status
= EFI_OUT_OF_RESOURCES
;
188 Print(L
"Arguments to pass to the binary: ");
189 Status
= GetHIInputAscii (CmdLine
,BOOT_DEVICE_OPTION_MAX
);
190 if (EFI_ERROR(Status
)) {
191 Status
= EFI_ABORTED
;
192 goto FREE_DEVICE_PATH
;
195 CmdLineSize
= AsciiStrSize (CmdLine
);
196 InitrdSize
= GetDevicePathSize (InitrdPath
);
198 BootArguments
= (ARM_BDS_LOADER_ARGUMENTS
*)AllocatePool (sizeof(ARM_BDS_LOADER_ARGUMENTS
) + CmdLineSize
+ InitrdSize
);
200 BootArguments
->LinuxArguments
.CmdLineSize
= CmdLineSize
;
201 BootArguments
->LinuxArguments
.InitrdSize
= InitrdSize
;
202 CopyMem ((VOID
*)(&BootArguments
->LinuxArguments
+ 1), CmdLine
, CmdLineSize
);
203 CopyMem ((VOID
*)((UINTN
)(&BootArguments
->LinuxArguments
+ 1) + CmdLineSize
), InitrdPath
, InitrdSize
);
205 BootArguments
= NULL
;
208 Print(L
"Description for this new Entry: ");
209 Status
= GetHIInputStr (BootDescription
, BOOT_DEVICE_DESCRIPTION_MAX
);
210 if (EFI_ERROR(Status
)) {
211 Status
= EFI_ABORTED
;
212 goto FREE_DEVICE_PATH
;
216 BdsLoadOptionEntry
= (BDS_LOAD_OPTION_ENTRY
*)AllocatePool (sizeof(BDS_LOAD_OPTION_ENTRY
));
217 Status
= BootOptionCreate (Attributes
, BootDescription
, DevicePath
, BootType
, BootArguments
, &BdsLoadOptionEntry
->BdsLoadOption
);
218 if (!EFI_ERROR(Status
)) {
219 InsertTailList (BootOptionsList
, &BdsLoadOptionEntry
->Link
);
223 FreePool (DevicePath
);
226 if (Status
== EFI_ABORTED
) {
229 FreePool(SupportedBootDevice
);
235 BootMenuSelectBootOption (
236 IN LIST_ENTRY
* BootOptionsList
,
237 IN CONST CHAR16
* InputStatement
,
238 IN BOOLEAN OnlyArmBdsBootEntry
,
239 OUT BDS_LOAD_OPTION_ENTRY
** BdsLoadOptionEntry
244 BDS_LOAD_OPTION
* BdsLoadOption
;
245 UINTN BootOptionSelected
;
246 UINTN BootOptionCount
;
249 // Display the list of supported boot devices
251 for (Entry
= GetFirstNode (BootOptionsList
);
252 !IsNull (BootOptionsList
,Entry
);
253 Entry
= GetNextNode (BootOptionsList
, Entry
)
256 BdsLoadOption
= LOAD_OPTION_FROM_LINK(Entry
);
258 if (OnlyArmBdsBootEntry
&& !IS_ARM_BDS_BOOTENTRY (BdsLoadOption
)) {
262 Print (L
"[%d] %s\n", (BootOptionCount
+ 1), BdsLoadOption
->Description
);
265 CHAR16
* DevicePathTxt
;
266 EFI_DEVICE_PATH_TO_TEXT_PROTOCOL
* DevicePathToTextProtocol
;
267 ARM_BDS_LOADER_TYPE LoaderType
;
268 ARM_BDS_LOADER_OPTIONAL_DATA
* OptionalData
;
270 Status
= gBS
->LocateProtocol(&gEfiDevicePathToTextProtocolGuid
, NULL
, (VOID
**)&DevicePathToTextProtocol
);
271 ASSERT_EFI_ERROR(Status
);
272 DevicePathTxt
= DevicePathToTextProtocol
->ConvertDevicePathToText(BdsLoadOption
->FilePathList
,TRUE
,TRUE
);
274 Print(L
"\t- %s\n",DevicePathTxt
);
275 OptionalData
= BdsLoadOption
->OptionalData
;
276 LoaderType
= (ARM_BDS_LOADER_TYPE
)ReadUnaligned32 ((CONST UINT32
*)&OptionalData
->Header
.LoaderType
);
277 if ((LoaderType
== BDS_LOADER_KERNEL_LINUX_ATAG
) || (LoaderType
== BDS_LOADER_KERNEL_LINUX_FDT
)) {
278 Print (L
"\t- Arguments: %a\n",&OptionalData
->Arguments
.LinuxArguments
+ 1);
281 FreePool(DevicePathTxt
);
287 // Check if a valid boot option(s) is found
288 if (BootOptionCount
== 0) {
289 if (StrCmp (InputStatement
, DELETE_BOOT_ENTRY
) == 0) {
290 Print (L
"Nothing to remove!\n");
291 } else if (StrCmp (InputStatement
, UPDATE_BOOT_ENTRY
) == 0) {
292 Print (L
"Couldn't find valid boot entries\n");
294 Print (L
"No supported Boot Entry.\n");
297 return EFI_NOT_FOUND
;
300 // Get the index of the boot device to delete
301 BootOptionSelected
= 0;
302 while (BootOptionSelected
== 0) {
303 Print(InputStatement
);
304 Status
= GetHIInputInteger (&BootOptionSelected
);
305 if (EFI_ERROR(Status
)) {
307 } else if ((BootOptionSelected
== 0) || (BootOptionSelected
> BootOptionCount
)) {
308 Print(L
"Invalid input (max %d)\n",BootOptionCount
);
309 BootOptionSelected
= 0;
313 // Get the structure of the Boot device to delete
315 for (Entry
= GetFirstNode (BootOptionsList
);
316 !IsNull (BootOptionsList
, Entry
);
317 Entry
= GetNextNode (BootOptionsList
,Entry
)
320 if (Index
== BootOptionSelected
) {
321 *BdsLoadOptionEntry
= LOAD_OPTION_ENTRY_FROM_LINK(Entry
);
331 BootMenuRemoveBootOption (
332 IN LIST_ENTRY
*BootOptionsList
336 BDS_LOAD_OPTION_ENTRY
* BootOptionEntry
;
338 Status
= BootMenuSelectBootOption (BootOptionsList
, DELETE_BOOT_ENTRY
, FALSE
, &BootOptionEntry
);
339 if (EFI_ERROR(Status
)) {
343 // If the Boot Option was attached to a list remove it
344 if (!IsListEmpty (&BootOptionEntry
->Link
)) {
345 // Remove the entry from the list
346 RemoveEntryList (&BootOptionEntry
->Link
);
349 // Delete the BDS Load option structures
350 BootOptionDelete (BootOptionEntry
->BdsLoadOption
);
356 BootMenuUpdateBootOption (
357 IN LIST_ENTRY
*BootOptionsList
361 BDS_LOAD_OPTION_ENTRY
*BootOptionEntry
;
362 BDS_LOAD_OPTION
*BootOption
;
363 BDS_LOAD_OPTION_SUPPORT
* DeviceSupport
;
364 ARM_BDS_LOADER_ARGUMENTS
* BootArguments
;
365 CHAR16 BootDescription
[BOOT_DEVICE_DESCRIPTION_MAX
];
366 CHAR8 CmdLine
[BOOT_DEVICE_OPTION_MAX
];
367 EFI_DEVICE_PATH
*DevicePath
;
368 EFI_DEVICE_PATH
*TempInitrdPath
;
369 ARM_BDS_LOADER_TYPE BootType
;
370 ARM_BDS_LOADER_OPTIONAL_DATA
* OptionalData
;
371 ARM_BDS_LINUX_ARGUMENTS
* LinuxArguments
;
372 EFI_DEVICE_PATH
*InitrdPathNodes
;
373 EFI_DEVICE_PATH
*InitrdPath
;
376 BOOLEAN InitrdSupport
;
378 Status
= BootMenuSelectBootOption (BootOptionsList
, UPDATE_BOOT_ENTRY
, TRUE
, &BootOptionEntry
);
379 if (EFI_ERROR(Status
)) {
382 BootOption
= BootOptionEntry
->BdsLoadOption
;
384 // Get the device support for this Boot Option
385 Status
= BootDeviceGetDeviceSupport (BootOption
->FilePathList
, &DeviceSupport
);
386 if (EFI_ERROR(Status
)) {
387 Print(L
"Not possible to retrieve the supported device for the update\n");
388 return EFI_UNSUPPORTED
;
391 Status
= DeviceSupport
->UpdateDevicePathNode (BootOption
->FilePathList
, L
"EFI Application or the kernel", &DevicePath
, NULL
, NULL
);
392 if (EFI_ERROR(Status
)) {
393 Status
= EFI_ABORTED
;
397 OptionalData
= BootOption
->OptionalData
;
398 BootType
= (ARM_BDS_LOADER_TYPE
)ReadUnaligned32 ((UINT32
*)(&OptionalData
->Header
.LoaderType
));
400 if ((BootType
== BDS_LOADER_KERNEL_LINUX_ATAG
) || (BootType
== BDS_LOADER_KERNEL_LINUX_FDT
)) {
401 LinuxArguments
= &OptionalData
->Arguments
.LinuxArguments
;
403 CmdLineSize
= ReadUnaligned16 ((CONST UINT16
*)&LinuxArguments
->CmdLineSize
);
405 InitrdSize
= ReadUnaligned16 ((CONST UINT16
*)&LinuxArguments
->InitrdSize
);
406 if (InitrdSize
> 0) {
407 Print(L
"Keep the initrd: ");
409 Print(L
"Add an initrd: ");
411 Status
= GetHIInputBoolean (&InitrdSupport
);
412 if (EFI_ERROR(Status
)) {
413 Status
= EFI_ABORTED
;
418 if (InitrdSize
> 0) {
419 // Case we update the initrd device path
420 Status
= DeviceSupport
->UpdateDevicePathNode ((EFI_DEVICE_PATH
*)((UINTN
)(LinuxArguments
+ 1) + CmdLineSize
), L
"initrd", &InitrdPath
, NULL
, NULL
);
421 if (EFI_ERROR(Status
) && Status
!= EFI_NOT_FOUND
) {// EFI_NOT_FOUND is returned on empty input string, but we can boot without an initrd
422 Status
= EFI_ABORTED
;
425 InitrdSize
= GetDevicePathSize (InitrdPath
);
427 // Case we create the initrd device path
429 Status
= DeviceSupport
->CreateDevicePathNode (L
"initrd", &InitrdPathNodes
, NULL
, NULL
);
430 if (EFI_ERROR(Status
) && Status
!= EFI_NOT_FOUND
) { // EFI_NOT_FOUND is returned on empty input string, but we can boot without an initrd
431 Status
= EFI_ABORTED
;
435 if (InitrdPathNodes
!= NULL
) {
436 // Duplicate Linux kernel Device Path
437 TempInitrdPath
= DuplicateDevicePath (BootOption
->FilePathList
);
438 // Replace Linux kernel Node by EndNode
439 SetDevicePathEndNode (GetLastDevicePathNode (TempInitrdPath
));
440 // Append the Device Path to the selected device path
441 InitrdPath
= AppendDevicePath (TempInitrdPath
, (CONST EFI_DEVICE_PATH_PROTOCOL
*)InitrdPathNodes
);
442 FreePool (TempInitrdPath
);
443 if (InitrdPath
== NULL
) {
444 Status
= EFI_OUT_OF_RESOURCES
;
447 InitrdSize
= GetDevicePathSize (InitrdPath
);
456 Print(L
"Arguments to pass to the binary: ");
457 if (CmdLineSize
> 0) {
458 AsciiStrnCpy(CmdLine
, (CONST CHAR8
*)(LinuxArguments
+ 1), CmdLineSize
);
462 Status
= EditHIInputAscii (CmdLine
, BOOT_DEVICE_OPTION_MAX
);
463 if (EFI_ERROR(Status
)) {
464 Status
= EFI_ABORTED
;
465 goto FREE_DEVICE_PATH
;
468 CmdLineSize
= AsciiStrSize (CmdLine
);
470 BootArguments
= (ARM_BDS_LOADER_ARGUMENTS
*)AllocatePool(sizeof(ARM_BDS_LOADER_ARGUMENTS
) + CmdLineSize
+ InitrdSize
);
471 BootArguments
->LinuxArguments
.CmdLineSize
= CmdLineSize
;
472 BootArguments
->LinuxArguments
.InitrdSize
= InitrdSize
;
473 CopyMem (&BootArguments
->LinuxArguments
+ 1, CmdLine
, CmdLineSize
);
474 CopyMem ((VOID
*)((UINTN
)(&BootArguments
->LinuxArguments
+ 1) + CmdLineSize
), InitrdPath
, InitrdSize
);
476 BootArguments
= NULL
;
479 Print(L
"Description for this new Entry: ");
480 StrnCpy (BootDescription
, BootOption
->Description
, BOOT_DEVICE_DESCRIPTION_MAX
);
481 Status
= EditHIInputStr (BootDescription
, BOOT_DEVICE_DESCRIPTION_MAX
);
482 if (EFI_ERROR(Status
)) {
483 Status
= EFI_ABORTED
;
484 goto FREE_DEVICE_PATH
;
488 Status
= BootOptionUpdate (BootOption
, BootOption
->Attributes
, BootDescription
, DevicePath
, BootType
, BootArguments
);
491 FreePool (DevicePath
);
494 if (Status
== EFI_ABORTED
) {
502 IN LIST_ENTRY
*BootOptionsList
506 UINTN FdtDevicePathSize
;
507 BDS_SUPPORTED_DEVICE
*SupportedBootDevice
;
508 EFI_DEVICE_PATH_PROTOCOL
*FdtDevicePathNodes
;
509 EFI_DEVICE_PATH_PROTOCOL
*FdtDevicePath
;
511 Status
= SelectBootDevice (&SupportedBootDevice
);
512 if (EFI_ERROR(Status
)) {
513 Status
= EFI_ABORTED
;
517 // Create the specific device path node
518 Status
= SupportedBootDevice
->Support
->CreateDevicePathNode (L
"FDT blob", &FdtDevicePathNodes
, NULL
, NULL
);
519 if (EFI_ERROR(Status
)) {
520 Status
= EFI_ABORTED
;
524 if (FdtDevicePathNodes
!= NULL
) {
525 // Append the Device Path node to the select device path
526 FdtDevicePath
= AppendDevicePath (SupportedBootDevice
->DevicePathProtocol
, FdtDevicePathNodes
);
527 FdtDevicePathSize
= GetDevicePathSize (FdtDevicePath
);
528 Status
= gRT
->SetVariable (
530 &gArmGlobalVariableGuid
,
531 EFI_VARIABLE_RUNTIME_ACCESS
| EFI_VARIABLE_NON_VOLATILE
| EFI_VARIABLE_BOOTSERVICE_ACCESS
,
535 ASSERT_EFI_ERROR(Status
);
539 &gArmGlobalVariableGuid
,
540 EFI_VARIABLE_RUNTIME_ACCESS
| EFI_VARIABLE_NON_VOLATILE
| EFI_VARIABLE_BOOTSERVICE_ACCESS
,
544 ASSERT_EFI_ERROR(Status
);
548 if (Status
== EFI_ABORTED
) {
551 FreePool(SupportedBootDevice
);
555 struct BOOT_MANAGER_ENTRY
{
556 CONST CHAR16
* Description
;
557 EFI_STATUS (*Callback
) (IN LIST_ENTRY
*BootOptionsList
);
558 } BootManagerEntries
[] = {
559 { L
"Add Boot Device Entry", BootMenuAddBootOption
},
560 { L
"Update Boot Device Entry", BootMenuUpdateBootOption
},
561 { L
"Remove Boot Device Entry", BootMenuRemoveBootOption
},
562 { L
"Update FDT path", UpdateFdtPath
},
567 IN LIST_ENTRY
*BootOptionsList
571 UINTN OptionSelected
;
572 UINTN BootManagerEntryCount
;
575 BootManagerEntryCount
= sizeof(BootManagerEntries
) / sizeof(struct BOOT_MANAGER_ENTRY
);
578 // Display Boot Manager menu
579 for (Index
= 0; Index
< BootManagerEntryCount
; Index
++) {
580 Print(L
"[%d] %s\n",Index
+1,BootManagerEntries
[Index
]);
582 Print(L
"[%d] Return to main menu\n",Index
+1);
584 // Select which entry to call
586 Status
= GetHIInputInteger (&OptionSelected
);
587 if (EFI_ERROR(Status
) || (OptionSelected
== (BootManagerEntryCount
+1))) {
588 if (EFI_ERROR(Status
)) {
592 } else if ((OptionSelected
> 0) && (OptionSelected
<= BootManagerEntryCount
)) {
593 BootManagerEntries
[OptionSelected
-1].Callback (BootOptionsList
);
596 // Should never go here
601 IN LIST_ENTRY
*BootOptionsList
607 Status
= BdsLoadApplication (mImageHandle
, L
"Shell", 0, NULL
);
608 if (Status
== EFI_NOT_FOUND
) {
609 Print (L
"Error: EFI Application not found.\n");
610 } else if (EFI_ERROR(Status
)) {
611 Print (L
"Error: Status Code: 0x%X\n",(UINT32
)Status
);
617 struct BOOT_MAIN_ENTRY
{
618 CONST CHAR16
* Description
;
619 EFI_STATUS (*Callback
) (IN LIST_ENTRY
*BootOptionsList
);
620 } BootMainEntries
[] = {
621 { L
"Shell", BootShell
},
622 { L
"Boot Manager", BootMenuManager
},
631 LIST_ENTRY BootOptionsList
;
633 UINTN BootOptionCount
;
636 BDS_LOAD_OPTION
* BootOption
;
637 UINTN BootOptionSelected
;
639 UINTN BootMainEntryCount
;
642 BootMainEntryCount
= sizeof(BootMainEntries
) / sizeof(struct BOOT_MAIN_ENTRY
);
646 BootOptionList (&BootOptionsList
);
650 // Display the Boot options
651 for (Entry
= GetFirstNode (&BootOptionsList
);
652 !IsNull (&BootOptionsList
,Entry
);
653 Entry
= GetNextNode (&BootOptionsList
,Entry
)
656 BootOption
= LOAD_OPTION_FROM_LINK(Entry
);
658 Print(L
"[%d] %s\n", OptionCount
, BootOption
->Description
);
661 CHAR16
* DevicePathTxt
;
662 EFI_DEVICE_PATH_TO_TEXT_PROTOCOL
* DevicePathToTextProtocol
;
663 ARM_BDS_LOADER_OPTIONAL_DATA
* OptionalData
;
665 ARM_BDS_LOADER_TYPE LoaderType
;
667 Status
= gBS
->LocateProtocol (&gEfiDevicePathToTextProtocolGuid
, NULL
, (VOID
**)&DevicePathToTextProtocol
);
668 if (EFI_ERROR(Status
)) {
669 // You must provide an implementation of DevicePathToTextProtocol in your firmware (eg: DevicePathDxe)
670 DEBUG((EFI_D_ERROR
,"Error: Bds requires DevicePathToTextProtocol\n"));
673 DevicePathTxt
= DevicePathToTextProtocol
->ConvertDevicePathToText (BootOption
->FilePathList
, TRUE
, TRUE
);
675 Print(L
"\t- %s\n",DevicePathTxt
);
677 // If it is a supported BootEntry then print its details
678 if (IS_ARM_BDS_BOOTENTRY (BootOption
)) {
679 OptionalData
= BootOption
->OptionalData
;
680 LoaderType
= (ARM_BDS_LOADER_TYPE
)ReadUnaligned32 ((CONST UINT32
*)&OptionalData
->Header
.LoaderType
);
681 if ((LoaderType
== BDS_LOADER_KERNEL_LINUX_ATAG
) || (LoaderType
== BDS_LOADER_KERNEL_LINUX_FDT
)) {
682 if (ReadUnaligned16 (&OptionalData
->Arguments
.LinuxArguments
.InitrdSize
) > 0) {
683 CmdLineSize
= ReadUnaligned16 (&OptionalData
->Arguments
.LinuxArguments
.CmdLineSize
);
684 DevicePathTxt
= DevicePathToTextProtocol
->ConvertDevicePathToText (
685 GetAlignedDevicePath ((EFI_DEVICE_PATH
*)((UINTN
)(&OptionalData
->Arguments
.LinuxArguments
+ 1) + CmdLineSize
)), TRUE
, TRUE
);
686 Print(L
"\t- Initrd: %s\n", DevicePathTxt
);
688 Print(L
"\t- Arguments: %a\n", (&OptionalData
->Arguments
.LinuxArguments
+ 1));
691 switch (LoaderType
) {
692 case BDS_LOADER_EFI_APPLICATION
:
693 Print(L
"\t- LoaderType: EFI Application\n");
696 case BDS_LOADER_KERNEL_LINUX_ATAG
:
697 Print(L
"\t- LoaderType: Linux kernel with ATAG support\n");
700 case BDS_LOADER_KERNEL_LINUX_FDT
:
701 Print(L
"\t- LoaderType: Linux kernel with FDT support\n");
705 Print(L
"\t- LoaderType: Not recognized (%d)\n", LoaderType
);
708 FreePool(DevicePathTxt
);
713 BootOptionCount
= OptionCount
-1;
715 // Display the hardcoded Boot entries
716 for (Index
= 0; Index
< BootMainEntryCount
; Index
++) {
717 Print(L
"[%d] %s\n",OptionCount
,BootMainEntries
[Index
]);
721 // Request the boot entry from the user
722 BootOptionSelected
= 0;
723 while (BootOptionSelected
== 0) {
725 Status
= GetHIInputInteger (&BootOptionSelected
);
726 if (EFI_ERROR(Status
) || (BootOptionSelected
== 0) || (BootOptionSelected
> OptionCount
)) {
727 Print(L
"Invalid input (max %d)\n",(OptionCount
-1));
728 BootOptionSelected
= 0;
732 // Start the selected entry
733 if (BootOptionSelected
> BootOptionCount
) {
734 // Start the hardcoded entry
735 Status
= BootMainEntries
[BootOptionSelected
- BootOptionCount
- 1].Callback (&BootOptionsList
);
737 // Find the selected entry from the Boot#### list
739 for (Entry
= GetFirstNode (&BootOptionsList
);
740 !IsNull (&BootOptionsList
,Entry
);
741 Entry
= GetNextNode (&BootOptionsList
,Entry
)
744 if (Index
== BootOptionSelected
) {
745 BootOption
= LOAD_OPTION_FROM_LINK(Entry
);
751 Status
= BootOptionStart (BootOption
);
754 // Should never go here