]> git.proxmox.com Git - mirror_edk2.git/blame - ArmPlatformPkg/Bds/BootMenu.c
ArmPlatformPkg/Bds: Add a signature in front of the Boot Argument propoer to this Bds
[mirror_edk2.git] / ArmPlatformPkg / Bds / BootMenu.c
CommitLineData
ea46ebbe 1/** @file\r
2*\r
3* Copyright (c) 2011, ARM Limited. All rights reserved.\r
4*\r
5* This program and the accompanying materials\r
6* are licensed and made available under the terms and conditions of the BSD License\r
7* which accompanies this distribution. The full text of the license may be found at\r
8* http://opensource.org/licenses/bsd-license.php\r
9*\r
10* THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
11* WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
12*\r
13**/\r
14\r
15#include "BdsInternal.h"\r
16\r
17extern EFI_HANDLE mImageHandle;\r
18extern BDS_LOAD_OPTION_SUPPORT *BdsLoadOptionSupportList;\r
19\r
20EFI_STATUS\r
656416bc 21SelectBootDevice (\r
22 OUT BDS_SUPPORTED_DEVICE** SupportedBootDevice\r
ea46ebbe 23 )\r
24{\r
656416bc 25 EFI_STATUS Status;\r
ea46ebbe 26 LIST_ENTRY SupportedDeviceList;\r
27 UINTN SupportedDeviceCount;\r
ea46ebbe 28 LIST_ENTRY* Entry;\r
29 UINTN SupportedDeviceSelected;\r
ea46ebbe 30 UINTN Index;\r
ea46ebbe 31\r
32 //\r
33 // List the Boot Devices supported\r
34 //\r
35\r
36 // Start all the drivers first\r
37 BdsConnectAllDrivers ();\r
38\r
39 // List the supported devices\r
40 Status = BootDeviceListSupportedInit (&SupportedDeviceList);\r
41 ASSERT_EFI_ERROR(Status);\r
42\r
43 SupportedDeviceCount = 0;\r
44 for (Entry = GetFirstNode (&SupportedDeviceList);\r
45 !IsNull (&SupportedDeviceList,Entry);\r
46 Entry = GetNextNode (&SupportedDeviceList,Entry)\r
47 )\r
48 {\r
656416bc 49 *SupportedBootDevice = SUPPORTED_BOOT_DEVICE_FROM_LINK(Entry);\r
50 Print(L"[%d] %s\n",SupportedDeviceCount+1,(*SupportedBootDevice)->Description);\r
ea46ebbe 51\r
52 DEBUG_CODE_BEGIN();\r
53 CHAR16* DevicePathTxt;\r
54 EFI_DEVICE_PATH_TO_TEXT_PROTOCOL* DevicePathToTextProtocol;\r
55\r
56 Status = gBS->LocateProtocol(&gEfiDevicePathToTextProtocolGuid, NULL, (VOID **)&DevicePathToTextProtocol);\r
57 ASSERT_EFI_ERROR(Status);\r
656416bc 58 DevicePathTxt = DevicePathToTextProtocol->ConvertDevicePathToText((*SupportedBootDevice)->DevicePathProtocol,TRUE,TRUE);\r
ea46ebbe 59\r
60 Print(L"\t- %s\n",DevicePathTxt);\r
61\r
62 FreePool(DevicePathTxt);\r
63 DEBUG_CODE_END();\r
64\r
65 SupportedDeviceCount++;\r
66 }\r
67\r
68 if (SupportedDeviceCount == 0) {\r
69 Print(L"There is no supported device.\n");\r
70 Status = EFI_ABORTED;\r
71 goto EXIT;\r
72 }\r
73\r
74 //\r
75 // Select the Boot Device\r
76 //\r
77 SupportedDeviceSelected = 0;\r
78 while (SupportedDeviceSelected == 0) {\r
79 Print(L"Select the Boot Device: ");\r
80 Status = GetHIInputInteger (&SupportedDeviceSelected);\r
81 if (EFI_ERROR(Status)) {\r
82 Status = EFI_ABORTED;\r
83 goto EXIT;\r
84 } else if ((SupportedDeviceSelected == 0) || (SupportedDeviceSelected > SupportedDeviceCount)) {\r
85 Print(L"Invalid input (max %d)\n",SupportedDeviceSelected);\r
86 SupportedDeviceSelected = 0;\r
87 }\r
88 }\r
89\r
90 //\r
91 // Get the Device Path for the selected boot device\r
92 //\r
93 Index = 1;\r
94 for (Entry = GetFirstNode (&SupportedDeviceList);\r
95 !IsNull (&SupportedDeviceList,Entry);\r
96 Entry = GetNextNode (&SupportedDeviceList,Entry)\r
97 )\r
98 {\r
99 if (Index == SupportedDeviceSelected) {\r
656416bc 100 *SupportedBootDevice = SUPPORTED_BOOT_DEVICE_FROM_LINK(Entry);\r
ea46ebbe 101 break;\r
102 }\r
103 Index++;\r
104 }\r
656416bc 105 \r
106EXIT:\r
107 BootDeviceListSupportedFree (&SupportedDeviceList, *SupportedBootDevice);\r
108 return Status;\r
109}\r
110\r
111EFI_STATUS\r
112BootMenuAddBootOption (\r
113 IN LIST_ENTRY *BootOptionsList\r
114 )\r
115{\r
2ccfb71e 116 EFI_STATUS Status;\r
117 BDS_SUPPORTED_DEVICE* SupportedBootDevice;\r
118 ARM_BDS_LOADER_ARGUMENTS* BootArguments;\r
74b96132 119 CHAR16 BootDescription[BOOT_DEVICE_DESCRIPTION_MAX];\r
2ccfb71e 120 CHAR8 CmdLine[BOOT_DEVICE_OPTION_MAX];\r
121 UINT32 Attributes;\r
122 ARM_BDS_LOADER_TYPE BootType;\r
656416bc 123 BDS_LOAD_OPTION *BdsLoadOption;\r
2ccfb71e 124 EFI_DEVICE_PATH *DevicePath;\r
125 EFI_DEVICE_PATH_PROTOCOL *DevicePathNode;\r
126 EFI_DEVICE_PATH_PROTOCOL *InitrdPathNode;\r
127 EFI_DEVICE_PATH_PROTOCOL *InitrdPath;\r
128 UINTN CmdLineSize;\r
129 UINTN InitrdSize;\r
656416bc 130\r
131 Attributes = 0;\r
132 SupportedBootDevice = NULL;\r
133\r
134 // List the Boot Devices supported\r
2ccfb71e 135 Status = SelectBootDevice (&SupportedBootDevice);\r
656416bc 136 if (EFI_ERROR(Status)) {\r
137 Status = EFI_ABORTED;\r
138 goto EXIT;\r
139 }\r
ea46ebbe 140\r
141 // Create the specific device path node\r
656416bc 142 Print(L"File path of the EFI Application or the kernel: ");\r
ea46ebbe 143 Status = SupportedBootDevice->Support->CreateDevicePathNode (SupportedBootDevice, &DevicePathNode, &BootType, &Attributes);\r
144 if (EFI_ERROR(Status)) {\r
145 Status = EFI_ABORTED;\r
146 goto EXIT;\r
147 }\r
148 // Append the Device Path node to the select device path\r
149 DevicePath = AppendDevicePathNode (SupportedBootDevice->DevicePathProtocol, (CONST EFI_DEVICE_PATH_PROTOCOL *)DevicePathNode);\r
150\r
2ccfb71e 151 if ((BootType == BDS_LOADER_KERNEL_LINUX_ATAG) || (BootType == BDS_LOADER_KERNEL_LINUX_FDT)) {\r
656416bc 152 // Create the specific device path node\r
153 Print(L"File path of the initrd: ");\r
154 Status = SupportedBootDevice->Support->CreateDevicePathNode (SupportedBootDevice, &InitrdPathNode, NULL, NULL);\r
155 if (EFI_ERROR(Status) && Status != EFI_NOT_FOUND) { // EFI_NOT_FOUND is returned on empty input string, but we can boot without an initrd\r
156 Status = EFI_ABORTED;\r
157 goto EXIT;\r
158 }\r
159\r
160 if (InitrdPathNode != NULL) {\r
161 // Append the Device Path node to the select device path\r
2ccfb71e 162 InitrdPath = AppendDevicePathNode (SupportedBootDevice->DevicePathProtocol, (CONST EFI_DEVICE_PATH_PROTOCOL *)InitrdPathNode);\r
656416bc 163 } else {\r
2ccfb71e 164 InitrdPath = NULL;\r
656416bc 165 }\r
166\r
167 Print(L"Arguments to pass to the binary: ");\r
2ccfb71e 168 Status = GetHIInputAscii (CmdLine,BOOT_DEVICE_OPTION_MAX);\r
656416bc 169 if (EFI_ERROR(Status)) {\r
170 Status = EFI_ABORTED;\r
171 goto FREE_DEVICE_PATH;\r
172 }\r
2ccfb71e 173\r
174 CmdLineSize = AsciiStrSize (CmdLine);\r
175 InitrdSize = GetDevicePathSize (InitrdPath);\r
176\r
177 BootArguments = (ARM_BDS_LOADER_ARGUMENTS*)AllocatePool (sizeof(ARM_BDS_LOADER_ARGUMENTS) + CmdLineSize + InitrdSize);\r
178 \r
179 BootArguments->LinuxArguments.CmdLineSize = CmdLineSize;\r
180 BootArguments->LinuxArguments.InitrdSize = InitrdSize;\r
181 CopyMem ((VOID*)(&BootArguments->LinuxArguments + 1), CmdLine, CmdLineSize);\r
182 CopyMem ((VOID*)((UINTN)(&BootArguments->LinuxArguments + 1) + CmdLineSize), InitrdPath, InitrdSize);\r
183 } else {\r
184 BootArguments = NULL;\r
ea46ebbe 185 }\r
186\r
187 Print(L"Description for this new Entry: ");\r
74b96132 188 Status = GetHIInputStr (BootDescription, BOOT_DEVICE_DESCRIPTION_MAX);\r
ea46ebbe 189 if (EFI_ERROR(Status)) {\r
190 Status = EFI_ABORTED;\r
191 goto FREE_DEVICE_PATH;\r
192 }\r
193\r
ea46ebbe 194 // Create new entry\r
656416bc 195 Status = BootOptionCreate (Attributes, BootDescription, DevicePath, BootType, &BootArguments, &BdsLoadOption);\r
ea46ebbe 196 if (!EFI_ERROR(Status)) {\r
197 InsertTailList (BootOptionsList,&BdsLoadOption->Link);\r
198 }\r
199\r
ea46ebbe 200FREE_DEVICE_PATH:\r
201 FreePool (DevicePath);\r
202\r
656416bc 203 \r
ea46ebbe 204EXIT:\r
656416bc 205 if (Status == EFI_ABORTED) {\r
206 Print(L"\n");\r
207 }\r
208 FreePool(SupportedBootDevice);\r
ea46ebbe 209 return Status;\r
210}\r
211\r
212STATIC\r
213EFI_STATUS\r
214BootMenuSelectBootOption (\r
215 IN LIST_ENTRY *BootOptionsList,\r
216 IN CONST CHAR16* InputStatement,\r
217 OUT BDS_LOAD_OPTION **BdsLoadOption\r
218 )\r
219{\r
220 EFI_STATUS Status;\r
221 LIST_ENTRY* Entry;\r
222 BDS_LOAD_OPTION *BootOption;\r
223 UINTN BootOptionSelected;\r
224 UINTN BootOptionCount;\r
225 UINTN Index;\r
226\r
227 // Display the list of supported boot devices\r
228 BootOptionCount = 1;\r
229 for (Entry = GetFirstNode (BootOptionsList);\r
230 !IsNull (BootOptionsList,Entry);\r
231 Entry = GetNextNode (BootOptionsList,Entry)\r
232 )\r
233 {\r
234 BootOption = LOAD_OPTION_FROM_LINK(Entry);\r
235 Print(L"[%d] %s\n",BootOptionCount,BootOption->Description);\r
236\r
237 DEBUG_CODE_BEGIN();\r
238 CHAR16* DevicePathTxt;\r
239 EFI_DEVICE_PATH_TO_TEXT_PROTOCOL* DevicePathToTextProtocol;\r
2ccfb71e 240 ARM_BDS_LOADER_TYPE LoaderType;\r
ea46ebbe 241\r
242 Status = gBS->LocateProtocol(&gEfiDevicePathToTextProtocolGuid, NULL, (VOID **)&DevicePathToTextProtocol);\r
243 ASSERT_EFI_ERROR(Status);\r
244 DevicePathTxt = DevicePathToTextProtocol->ConvertDevicePathToText(BootOption->FilePathList,TRUE,TRUE);\r
245\r
246 Print(L"\t- %s\n",DevicePathTxt);\r
2ccfb71e 247 OptionalData = BdsLoadOption->OptionalData;\r
248 LoaderType = (ARM_BDS_LOADER_TYPE)ReadUnaligned32 ((CONST UINT32*)&OptionalData->Header.LoaderType);\r
249 if ((LoaderType == BDS_LOADER_KERNEL_LINUX_ATAG) || (LoaderType == BDS_LOADER_KERNEL_LINUX_FDT)) {\r
250 Print (L"\t- Arguments: %a\n",&OptionalData->Arguments.LinuxArguments + 1);\r
ea46ebbe 251 }\r
252\r
253 FreePool(DevicePathTxt);\r
254 DEBUG_CODE_END();\r
255\r
256 BootOptionCount++;\r
257 }\r
258\r
259 // Get the index of the boot device to delete\r
260 BootOptionSelected = 0;\r
261 while (BootOptionSelected == 0) {\r
262 Print(InputStatement);\r
263 Status = GetHIInputInteger (&BootOptionSelected);\r
264 if (EFI_ERROR(Status)) {\r
265 return Status;\r
266 } else if ((BootOptionSelected == 0) || (BootOptionSelected >= BootOptionCount)) {\r
656416bc 267 Print(L"Invalid input (max %d)\n",BootOptionCount-1);\r
ea46ebbe 268 BootOptionSelected = 0;\r
269 }\r
270 }\r
271\r
272 // Get the structure of the Boot device to delete\r
273 Index = 1;\r
274 for (Entry = GetFirstNode (BootOptionsList);\r
275 !IsNull (BootOptionsList,Entry);\r
276 Entry = GetNextNode (BootOptionsList,Entry)\r
277 )\r
278 {\r
279 if (Index == BootOptionSelected) {\r
280 *BdsLoadOption = LOAD_OPTION_FROM_LINK(Entry);\r
281 break;\r
282 }\r
283 Index++;\r
284 }\r
285\r
286 return EFI_SUCCESS;\r
287}\r
288\r
289EFI_STATUS\r
290BootMenuRemoveBootOption (\r
291 IN LIST_ENTRY *BootOptionsList\r
292 )\r
293{\r
294 EFI_STATUS Status;\r
295 BDS_LOAD_OPTION *BootOption;\r
296\r
297 Status = BootMenuSelectBootOption (BootOptionsList,L"Delete entry: ",&BootOption);\r
298 if (EFI_ERROR(Status)) {\r
299 return Status;\r
300 }\r
301\r
302 // Delete the BDS Load option structures\r
303 BootOptionDelete (BootOption);\r
304\r
305 return EFI_SUCCESS;\r
306}\r
307\r
308EFI_STATUS\r
309BootMenuUpdateBootOption (\r
310 IN LIST_ENTRY *BootOptionsList\r
311 )\r
312{\r
2ccfb71e 313 EFI_STATUS Status;\r
314 BDS_LOAD_OPTION *BootOption;\r
315 BDS_LOAD_OPTION_SUPPORT* DeviceSupport;\r
316 ARM_BDS_LOADER_ARGUMENTS* BootArguments;\r
74b96132 317 CHAR16 BootDescription[BOOT_DEVICE_DESCRIPTION_MAX];\r
2ccfb71e 318 CHAR8 CmdLine[BOOT_DEVICE_OPTION_MAX];\r
319 EFI_DEVICE_PATH* DevicePath;\r
320 ARM_BDS_LOADER_TYPE BootType;\r
321 ARM_BDS_LOADER_OPTIONAL_DATA* OptionalData;\r
322 ARM_BDS_LINUX_ARGUMENTS* LinuxArguments;\r
323 EFI_DEVICE_PATH* InitrdPathList;\r
324 UINTN InitrdSize;\r
325 UINTN CmdLineSize;\r
ea46ebbe 326\r
327 Status = BootMenuSelectBootOption (BootOptionsList,L"Update entry: ",&BootOption);\r
328 if (EFI_ERROR(Status)) {\r
329 return Status;\r
330 }\r
331\r
332 // Get the device support for this Boot Option\r
333 Status = BootDeviceGetDeviceSupport (BootOption,&DeviceSupport);\r
334 if (EFI_ERROR(Status)) {\r
335 Print(L"Impossible to retrieve the supported device for the update\n");\r
336 return EFI_UNSUPPORTED;\r
337 }\r
338\r
656416bc 339 Print(L"File path of the EFI Application or the kernel: ");\r
340 Status = DeviceSupport->UpdateDevicePathNode (BootOption->FilePathList, &DevicePath, NULL, NULL);\r
ea46ebbe 341 if (EFI_ERROR(Status)) {\r
342 Status = EFI_ABORTED;\r
343 goto EXIT;\r
344 }\r
345\r
2ccfb71e 346 OptionalData = BootOption->OptionalData;\r
347 BootType = (ARM_BDS_LOADER_TYPE)ReadUnaligned32 ((UINT32 *)(&OptionalData->Header.LoaderType));\r
656416bc 348\r
349 // TODO: Allow adding an initrd to a boot entry without one\r
2ccfb71e 350 if ((BootType == BDS_LOADER_KERNEL_LINUX_ATAG) || (BootType == BDS_LOADER_KERNEL_LINUX_FDT)) {\r
351 LinuxArguments = &OptionalData->Arguments.LinuxArguments;\r
352\r
353 CmdLineSize = ReadUnaligned16 ((CONST UINT16*)&LinuxArguments->CmdLineSize);\r
354 InitrdSize = GetUnalignedDevicePathSize ((EFI_DEVICE_PATH*)((LinuxArguments + 1) + CmdLineSize));\r
355\r
356 Print(L"File path of the initrd: ");\r
357 Status = DeviceSupport->UpdateDevicePathNode (\r
358 (EFI_DEVICE_PATH_PROTOCOL *)((UINTN)(LinuxArguments + 1) + CmdLineSize), &InitrdPathList, NULL, NULL);\r
359 if (EFI_ERROR(Status) && Status != EFI_NOT_FOUND) {// EFI_NOT_FOUND is returned on empty input string, but we can boot without an initrd\r
360 Status = EFI_ABORTED;\r
361 goto EXIT;\r
656416bc 362 }\r
363\r
2ccfb71e 364 Print(L"Arguments to pass to the binary: "); \r
365 if (CmdLineSize > 0) {\r
366 AsciiStrnCpy(CmdLine, (CONST CHAR8*)(LinuxArguments + 1), CmdLineSize);\r
656416bc 367 } else {\r
2ccfb71e 368 CmdLine[0] = '\0';\r
656416bc 369 }\r
2ccfb71e 370 Status = EditHIInputAscii (CmdLine, BOOT_DEVICE_OPTION_MAX);\r
656416bc 371 if (EFI_ERROR(Status)) {\r
372 Status = EFI_ABORTED;\r
373 goto FREE_DEVICE_PATH;\r
374 }\r
2ccfb71e 375\r
376 CmdLineSize = AsciiStrSize (CmdLine);\r
377 InitrdSize = GetDevicePathSize (InitrdPathList);\r
378\r
379 BootArguments = (ARM_BDS_LOADER_ARGUMENTS*)AllocatePool(sizeof(ARM_BDS_LOADER_ARGUMENTS) + CmdLineSize + InitrdSize);\r
380 BootArguments->LinuxArguments.CmdLineSize = CmdLineSize;\r
381 BootArguments->LinuxArguments.InitrdSize = InitrdSize;\r
382 CopyMem (&BootArguments->LinuxArguments + 1, CmdLine, CmdLineSize);\r
383 CopyMem ((UINTN)(&BootArguments->LinuxArguments + 1) + CmdLine, InitrdPathList, InitrdSize);\r
384 } else {\r
385 BootArguments = NULL;\r
ea46ebbe 386 }\r
387\r
388 Print(L"Description for this new Entry: ");\r
74b96132 389 Status = EditHIInputStr (BootDescription, BOOT_DEVICE_DESCRIPTION_MAX);\r
ea46ebbe 390 if (EFI_ERROR(Status)) {\r
391 Status = EFI_ABORTED;\r
392 goto FREE_DEVICE_PATH;\r
393 }\r
394\r
ea46ebbe 395 // Update the entry\r
2ccfb71e 396 Status = BootOptionUpdate (BootOption, BootOption->Attributes, BootDescription, DevicePath, BootType, BootArguments);\r
ea46ebbe 397\r
ea46ebbe 398FREE_DEVICE_PATH:\r
399 FreePool (DevicePath);\r
400\r
401EXIT:\r
326d1df9 402 if (Status == EFI_ABORTED) {\r
403 Print(L"\n");\r
404 }\r
ea46ebbe 405 return Status;\r
406}\r
407\r
408struct BOOT_MANAGER_ENTRY {\r
409 CONST CHAR16* Description;\r
410 EFI_STATUS (*Callback) (IN LIST_ENTRY *BootOptionsList);\r
411} BootManagerEntries[] = {\r
412 { L"Add Boot Device Entry", BootMenuAddBootOption },\r
413 { L"Update Boot Device Entry", BootMenuUpdateBootOption },\r
414 { L"Remove Boot Device Entry", BootMenuRemoveBootOption },\r
415};\r
416\r
417EFI_STATUS\r
418BootMenuManager (\r
419 IN LIST_ENTRY *BootOptionsList\r
420 )\r
421{\r
422 UINTN Index;\r
423 UINTN OptionSelected;\r
424 UINTN BootManagerEntryCount;\r
425 EFI_STATUS Status;\r
426\r
427 BootManagerEntryCount = sizeof(BootManagerEntries) / sizeof(struct BOOT_MANAGER_ENTRY);\r
428\r
429 while (TRUE) {\r
430 // Display Boot Manager menu\r
431 for (Index = 0; Index < BootManagerEntryCount; Index++) {\r
432 Print(L"[%d] %s\n",Index+1,BootManagerEntries[Index]);\r
433 }\r
434 Print(L"[%d] Return to main menu\n",Index+1);\r
435\r
436 // Select which entry to call\r
437 Print(L"Choice: ");\r
438 Status = GetHIInputInteger (&OptionSelected);\r
439 if (EFI_ERROR(Status) || (OptionSelected == (BootManagerEntryCount+1))) {\r
326d1df9 440 if (EFI_ERROR(Status)) {\r
441 Print(L"\n");\r
442 }\r
ea46ebbe 443 return EFI_SUCCESS;\r
444 } else if ((OptionSelected > 0) && (OptionSelected <= BootManagerEntryCount)) {\r
445 Status = BootManagerEntries[OptionSelected-1].Callback (BootOptionsList);\r
446 }\r
447 }\r
448\r
449 return EFI_SUCCESS;\r
450}\r
451\r
452EFI_STATUS\r
453BootEBL (\r
454 IN LIST_ENTRY *BootOptionsList\r
455 )\r
456{\r
457 EFI_STATUS Status;\r
458\r
459 // Start EFI Shell\r
460 Status = BdsLoadApplication(mImageHandle, L"Ebl");\r
461 if (Status == EFI_NOT_FOUND) {\r
462 Print (L"Error: EFI Application not found.\n");\r
463 } else if (EFI_ERROR(Status)) {\r
464 Print (L"Error: Status Code: 0x%X\n",(UINT32)Status);\r
465 }\r
466\r
467 return Status;\r
468}\r
469\r
470struct BOOT_MAIN_ENTRY {\r
471 CONST CHAR16* Description;\r
472 EFI_STATUS (*Callback) (IN LIST_ENTRY *BootOptionsList);\r
473} BootMainEntries[] = {\r
474 { L"EBL", BootEBL },\r
475 { L"Boot Manager", BootMenuManager },\r
476};\r
477\r
478\r
479EFI_STATUS\r
480BootMenuMain (\r
481 VOID\r
482 )\r
483{\r
2ccfb71e 484 LIST_ENTRY BootOptionsList;\r
485 UINTN OptionCount;\r
486 UINTN BootOptionCount;\r
487 EFI_STATUS Status;\r
488 LIST_ENTRY* Entry;\r
489 BDS_LOAD_OPTION* BootOption;\r
490 UINTN BootOptionSelected;\r
491 UINTN Index;\r
492 UINTN BootMainEntryCount;\r
ea46ebbe 493\r
e862cd50 494 BootOption = NULL;\r
ea46ebbe 495 BootMainEntryCount = sizeof(BootMainEntries) / sizeof(struct BOOT_MAIN_ENTRY);\r
a6caee65 496\r
ea46ebbe 497 // Get Boot#### list\r
498 BootOptionList (&BootOptionsList);\r
499\r
500 while (TRUE) {\r
501 OptionCount = 1;\r
502\r
503 // Display the Boot options\r
504 for (Entry = GetFirstNode (&BootOptionsList);\r
505 !IsNull (&BootOptionsList,Entry);\r
506 Entry = GetNextNode (&BootOptionsList,Entry)\r
507 )\r
508 {\r
509 BootOption = LOAD_OPTION_FROM_LINK(Entry);\r
510\r
511 Print(L"[%d] %s\n",OptionCount,BootOption->Description);\r
512\r
513 DEBUG_CODE_BEGIN();\r
514 CHAR16* DevicePathTxt;\r
515 EFI_DEVICE_PATH_TO_TEXT_PROTOCOL* DevicePathToTextProtocol;\r
2ccfb71e 516 ARM_BDS_LOADER_OPTIONAL_DATA* OptionalData;\r
517 UINTN CmdLineSize;\r
518 ARM_BDS_LOADER_TYPE LoaderType;\r
ea46ebbe 519\r
520 Status = gBS->LocateProtocol(&gEfiDevicePathToTextProtocolGuid, NULL, (VOID **)&DevicePathToTextProtocol);\r
aa95e2f7 521 if (EFI_ERROR(Status)) {\r
522 // You must provide an implementation of DevicePathToTextProtocol in your firmware (eg: DevicePathDxe)\r
523 DEBUG((EFI_D_ERROR,"Error: Bds requires DevicePathToTextProtocol\n"));\r
524 return Status;\r
525 }\r
ea46ebbe 526 DevicePathTxt = DevicePathToTextProtocol->ConvertDevicePathToText(BootOption->FilePathList,TRUE,TRUE);\r
527\r
528 Print(L"\t- %s\n",DevicePathTxt);\r
2ccfb71e 529\r
530 // If it is a supported BootEntry then print its details\r
531 if (IS_ARM_BDS_BOOTENTRY (BootOption)) {\r
532 OptionalData = BootOption->OptionalData;\r
533 LoaderType = (ARM_BDS_LOADER_TYPE)ReadUnaligned32 ((CONST UINT32*)&OptionalData->Header.LoaderType);\r
534 if ((LoaderType == BDS_LOADER_KERNEL_LINUX_ATAG) || (LoaderType == BDS_LOADER_KERNEL_LINUX_FDT)) {\r
535 if (ReadUnaligned16 (&OptionalData->Arguments.LinuxArguments.InitrdSize) > 0) {\r
536 CmdLineSize = ReadUnaligned16 (&OptionalData->Arguments.LinuxArguments.CmdLineSize);\r
537 DevicePathTxt = DevicePathToTextProtocol->ConvertDevicePathToText (\r
538 GetAlignedDevicePath ((EFI_DEVICE_PATH*)((UINTN)(&OptionalData->Arguments.LinuxArguments + 1) + CmdLineSize)), TRUE, TRUE);\r
539 Print(L"\t- Initrd: %s\n", DevicePathTxt);\r
540 }\r
541 Print(L"\t- Arguments: %a\n", (&OptionalData->Arguments.LinuxArguments + 1));\r
ea46ebbe 542 }\r
2ccfb71e 543 Print(L"\t- LoaderType: %d\n", LoaderType);\r
ea46ebbe 544 }\r
ea46ebbe 545 FreePool(DevicePathTxt);\r
546 DEBUG_CODE_END();\r
547\r
548 OptionCount++;\r
549 }\r
550 BootOptionCount = OptionCount-1;\r
551\r
552 // Display the hardcoded Boot entries\r
553 for (Index = 0; Index < BootMainEntryCount; Index++) {\r
554 Print(L"[%d] %s\n",OptionCount,BootMainEntries[Index]);\r
555 OptionCount++;\r
556 }\r
557\r
558 // Request the boot entry from the user\r
559 BootOptionSelected = 0;\r
560 while (BootOptionSelected == 0) {\r
561 Print(L"Start: ");\r
562 Status = GetHIInputInteger (&BootOptionSelected);\r
563 if (EFI_ERROR(Status) || (BootOptionSelected == 0) || (BootOptionSelected > OptionCount)) {\r
564 Print(L"Invalid input (max %d)\n",(OptionCount-1));\r
565 BootOptionSelected = 0;\r
566 }\r
567 }\r
568\r
569 // Start the selected entry\r
570 if (BootOptionSelected > BootOptionCount) {\r
571 // Start the hardcoded entry\r
572 Status = BootMainEntries[BootOptionSelected - BootOptionCount - 1].Callback (&BootOptionsList);\r
573 } else {\r
574 // Find the selected entry from the Boot#### list\r
575 Index = 1;\r
576 for (Entry = GetFirstNode (&BootOptionsList);\r
577 !IsNull (&BootOptionsList,Entry);\r
578 Entry = GetNextNode (&BootOptionsList,Entry)\r
579 )\r
580 {\r
581 if (Index == BootOptionSelected) {\r
582 BootOption = LOAD_OPTION_FROM_LINK(Entry);\r
583 break;\r
584 }\r
585 Index++;\r
586 }\r
587\r
588 Status = BootOptionStart (BootOption);\r
589 }\r
590 }\r
591\r
592 return Status;\r
593}\r