]> git.proxmox.com Git - mirror_edk2.git/blame - ArmPlatformPkg/Bds/BootMenu.c
ArmPkg/BdsLib: Fix MemMap Device Path node support
[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
a6e97d28 123 BDS_LOAD_OPTION_ENTRY *BdsLoadOptionEntry;\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
a6e97d28 195 BdsLoadOptionEntry = (BDS_LOAD_OPTION_ENTRY*)AllocatePool (sizeof(BDS_LOAD_OPTION_ENTRY));\r
196 Status = BootOptionCreate (Attributes, BootDescription, DevicePath, BootType, BootArguments, &BdsLoadOptionEntry->BdsLoadOption);\r
ea46ebbe 197 if (!EFI_ERROR(Status)) {\r
a6e97d28 198 InsertTailList (BootOptionsList, &BdsLoadOptionEntry->Link);\r
ea46ebbe 199 }\r
200\r
ea46ebbe 201FREE_DEVICE_PATH:\r
202 FreePool (DevicePath);\r
203\r
656416bc 204 \r
ea46ebbe 205EXIT:\r
656416bc 206 if (Status == EFI_ABORTED) {\r
207 Print(L"\n");\r
208 }\r
209 FreePool(SupportedBootDevice);\r
ea46ebbe 210 return Status;\r
211}\r
212\r
213STATIC\r
214EFI_STATUS\r
215BootMenuSelectBootOption (\r
a6e97d28 216 IN LIST_ENTRY* BootOptionsList,\r
217 IN CONST CHAR16* InputStatement,\r
218 IN BOOLEAN OnlyArmBdsBootEntry,\r
219 OUT BDS_LOAD_OPTION_ENTRY** BdsLoadOptionEntry\r
ea46ebbe 220 )\r
221{\r
a6e97d28 222 EFI_STATUS Status;\r
223 LIST_ENTRY* Entry;\r
224 BDS_LOAD_OPTION* BdsLoadOption;\r
225 UINTN BootOptionSelected;\r
226 UINTN BootOptionCount;\r
227 UINTN Index;\r
ea46ebbe 228\r
229 // Display the list of supported boot devices\r
230 BootOptionCount = 1;\r
231 for (Entry = GetFirstNode (BootOptionsList);\r
232 !IsNull (BootOptionsList,Entry);\r
a6e97d28 233 Entry = GetNextNode (BootOptionsList, Entry)\r
ea46ebbe 234 )\r
235 {\r
a6e97d28 236 BdsLoadOption = LOAD_OPTION_FROM_LINK(Entry);\r
237\r
238 if (OnlyArmBdsBootEntry && !IS_ARM_BDS_BOOTENTRY (BdsLoadOption)) {\r
239 continue;\r
240 }\r
241\r
242 Print (L"[%d] %s\n", BootOptionCount, BdsLoadOption->Description);\r
ea46ebbe 243\r
244 DEBUG_CODE_BEGIN();\r
245 CHAR16* DevicePathTxt;\r
246 EFI_DEVICE_PATH_TO_TEXT_PROTOCOL* DevicePathToTextProtocol;\r
2ccfb71e 247 ARM_BDS_LOADER_TYPE LoaderType;\r
a6e97d28 248 ARM_BDS_LOADER_OPTIONAL_DATA* OptionalData;\r
ea46ebbe 249\r
250 Status = gBS->LocateProtocol(&gEfiDevicePathToTextProtocolGuid, NULL, (VOID **)&DevicePathToTextProtocol);\r
251 ASSERT_EFI_ERROR(Status);\r
a6e97d28 252 DevicePathTxt = DevicePathToTextProtocol->ConvertDevicePathToText(BdsLoadOption->FilePathList,TRUE,TRUE);\r
ea46ebbe 253\r
254 Print(L"\t- %s\n",DevicePathTxt);\r
2ccfb71e 255 OptionalData = BdsLoadOption->OptionalData;\r
256 LoaderType = (ARM_BDS_LOADER_TYPE)ReadUnaligned32 ((CONST UINT32*)&OptionalData->Header.LoaderType);\r
257 if ((LoaderType == BDS_LOADER_KERNEL_LINUX_ATAG) || (LoaderType == BDS_LOADER_KERNEL_LINUX_FDT)) {\r
258 Print (L"\t- Arguments: %a\n",&OptionalData->Arguments.LinuxArguments + 1);\r
ea46ebbe 259 }\r
260\r
261 FreePool(DevicePathTxt);\r
262 DEBUG_CODE_END();\r
263\r
264 BootOptionCount++;\r
265 }\r
266\r
a6e97d28 267 if (BootOptionCount == 0) {\r
268 Print (L"No supported Boot Entry.\n");\r
269 return EFI_NOT_FOUND;\r
270 }\r
271\r
ea46ebbe 272 // Get the index of the boot device to delete\r
273 BootOptionSelected = 0;\r
274 while (BootOptionSelected == 0) {\r
275 Print(InputStatement);\r
276 Status = GetHIInputInteger (&BootOptionSelected);\r
277 if (EFI_ERROR(Status)) {\r
278 return Status;\r
279 } else if ((BootOptionSelected == 0) || (BootOptionSelected >= BootOptionCount)) {\r
656416bc 280 Print(L"Invalid input (max %d)\n",BootOptionCount-1);\r
ea46ebbe 281 BootOptionSelected = 0;\r
282 }\r
283 }\r
284\r
285 // Get the structure of the Boot device to delete\r
286 Index = 1;\r
287 for (Entry = GetFirstNode (BootOptionsList);\r
288 !IsNull (BootOptionsList,Entry);\r
289 Entry = GetNextNode (BootOptionsList,Entry)\r
290 )\r
291 {\r
292 if (Index == BootOptionSelected) {\r
a6e97d28 293 *BdsLoadOptionEntry = LOAD_OPTION_ENTRY_FROM_LINK(Entry);\r
ea46ebbe 294 break;\r
295 }\r
296 Index++;\r
297 }\r
298\r
299 return EFI_SUCCESS;\r
300}\r
301\r
302EFI_STATUS\r
303BootMenuRemoveBootOption (\r
304 IN LIST_ENTRY *BootOptionsList\r
305 )\r
306{\r
a6e97d28 307 EFI_STATUS Status;\r
308 BDS_LOAD_OPTION_ENTRY* BootOptionEntry;\r
ea46ebbe 309\r
a6e97d28 310 Status = BootMenuSelectBootOption (BootOptionsList, L"Delete entry: ", FALSE, &BootOptionEntry);\r
ea46ebbe 311 if (EFI_ERROR(Status)) {\r
312 return Status;\r
313 }\r
314\r
a6e97d28 315 // If the Boot Option was attached to a list remove it\r
316 if (!IsListEmpty (&BootOptionEntry->Link)) {\r
317 // Remove the entry from the list\r
318 RemoveEntryList (&BootOptionEntry->Link);\r
319 }\r
320\r
ea46ebbe 321 // Delete the BDS Load option structures\r
a6e97d28 322 BootOptionDelete (BootOptionEntry->BdsLoadOption);\r
ea46ebbe 323\r
324 return EFI_SUCCESS;\r
325}\r
326\r
327EFI_STATUS\r
328BootMenuUpdateBootOption (\r
329 IN LIST_ENTRY *BootOptionsList\r
330 )\r
331{\r
2ccfb71e 332 EFI_STATUS Status;\r
a6e97d28 333 BDS_LOAD_OPTION_ENTRY *BootOptionEntry;\r
2ccfb71e 334 BDS_LOAD_OPTION *BootOption;\r
335 BDS_LOAD_OPTION_SUPPORT* DeviceSupport;\r
336 ARM_BDS_LOADER_ARGUMENTS* BootArguments;\r
74b96132 337 CHAR16 BootDescription[BOOT_DEVICE_DESCRIPTION_MAX];\r
2ccfb71e 338 CHAR8 CmdLine[BOOT_DEVICE_OPTION_MAX];\r
339 EFI_DEVICE_PATH* DevicePath;\r
340 ARM_BDS_LOADER_TYPE BootType;\r
341 ARM_BDS_LOADER_OPTIONAL_DATA* OptionalData;\r
342 ARM_BDS_LINUX_ARGUMENTS* LinuxArguments;\r
343 EFI_DEVICE_PATH* InitrdPathList;\r
344 UINTN InitrdSize;\r
345 UINTN CmdLineSize;\r
ea46ebbe 346\r
a6e97d28 347 Status = BootMenuSelectBootOption (BootOptionsList, L"Update entry: ", TRUE, &BootOptionEntry);\r
ea46ebbe 348 if (EFI_ERROR(Status)) {\r
349 return Status;\r
350 }\r
a6e97d28 351 BootOption = BootOptionEntry->BdsLoadOption;\r
ea46ebbe 352\r
353 // Get the device support for this Boot Option\r
354 Status = BootDeviceGetDeviceSupport (BootOption,&DeviceSupport);\r
355 if (EFI_ERROR(Status)) {\r
356 Print(L"Impossible to retrieve the supported device for the update\n");\r
357 return EFI_UNSUPPORTED;\r
358 }\r
359\r
656416bc 360 Print(L"File path of the EFI Application or the kernel: ");\r
361 Status = DeviceSupport->UpdateDevicePathNode (BootOption->FilePathList, &DevicePath, NULL, NULL);\r
ea46ebbe 362 if (EFI_ERROR(Status)) {\r
363 Status = EFI_ABORTED;\r
364 goto EXIT;\r
365 }\r
366\r
2ccfb71e 367 OptionalData = BootOption->OptionalData;\r
368 BootType = (ARM_BDS_LOADER_TYPE)ReadUnaligned32 ((UINT32 *)(&OptionalData->Header.LoaderType));\r
656416bc 369\r
370 // TODO: Allow adding an initrd to a boot entry without one\r
2ccfb71e 371 if ((BootType == BDS_LOADER_KERNEL_LINUX_ATAG) || (BootType == BDS_LOADER_KERNEL_LINUX_FDT)) {\r
372 LinuxArguments = &OptionalData->Arguments.LinuxArguments;\r
373\r
374 CmdLineSize = ReadUnaligned16 ((CONST UINT16*)&LinuxArguments->CmdLineSize);\r
375 InitrdSize = GetUnalignedDevicePathSize ((EFI_DEVICE_PATH*)((LinuxArguments + 1) + CmdLineSize));\r
376\r
377 Print(L"File path of the initrd: ");\r
378 Status = DeviceSupport->UpdateDevicePathNode (\r
379 (EFI_DEVICE_PATH_PROTOCOL *)((UINTN)(LinuxArguments + 1) + CmdLineSize), &InitrdPathList, NULL, NULL);\r
380 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
381 Status = EFI_ABORTED;\r
382 goto EXIT;\r
656416bc 383 }\r
384\r
2ccfb71e 385 Print(L"Arguments to pass to the binary: "); \r
386 if (CmdLineSize > 0) {\r
387 AsciiStrnCpy(CmdLine, (CONST CHAR8*)(LinuxArguments + 1), CmdLineSize);\r
656416bc 388 } else {\r
2ccfb71e 389 CmdLine[0] = '\0';\r
656416bc 390 }\r
2ccfb71e 391 Status = EditHIInputAscii (CmdLine, BOOT_DEVICE_OPTION_MAX);\r
656416bc 392 if (EFI_ERROR(Status)) {\r
393 Status = EFI_ABORTED;\r
394 goto FREE_DEVICE_PATH;\r
395 }\r
2ccfb71e 396\r
397 CmdLineSize = AsciiStrSize (CmdLine);\r
398 InitrdSize = GetDevicePathSize (InitrdPathList);\r
399\r
400 BootArguments = (ARM_BDS_LOADER_ARGUMENTS*)AllocatePool(sizeof(ARM_BDS_LOADER_ARGUMENTS) + CmdLineSize + InitrdSize);\r
401 BootArguments->LinuxArguments.CmdLineSize = CmdLineSize;\r
402 BootArguments->LinuxArguments.InitrdSize = InitrdSize;\r
403 CopyMem (&BootArguments->LinuxArguments + 1, CmdLine, CmdLineSize);\r
404 CopyMem ((UINTN)(&BootArguments->LinuxArguments + 1) + CmdLine, InitrdPathList, InitrdSize);\r
405 } else {\r
406 BootArguments = NULL;\r
ea46ebbe 407 }\r
408\r
409 Print(L"Description for this new Entry: ");\r
74b96132 410 Status = EditHIInputStr (BootDescription, BOOT_DEVICE_DESCRIPTION_MAX);\r
ea46ebbe 411 if (EFI_ERROR(Status)) {\r
412 Status = EFI_ABORTED;\r
413 goto FREE_DEVICE_PATH;\r
414 }\r
415\r
ea46ebbe 416 // Update the entry\r
2ccfb71e 417 Status = BootOptionUpdate (BootOption, BootOption->Attributes, BootDescription, DevicePath, BootType, BootArguments);\r
ea46ebbe 418\r
ea46ebbe 419FREE_DEVICE_PATH:\r
420 FreePool (DevicePath);\r
421\r
422EXIT:\r
326d1df9 423 if (Status == EFI_ABORTED) {\r
424 Print(L"\n");\r
425 }\r
ea46ebbe 426 return Status;\r
427}\r
428\r
429struct BOOT_MANAGER_ENTRY {\r
430 CONST CHAR16* Description;\r
431 EFI_STATUS (*Callback) (IN LIST_ENTRY *BootOptionsList);\r
432} BootManagerEntries[] = {\r
433 { L"Add Boot Device Entry", BootMenuAddBootOption },\r
434 { L"Update Boot Device Entry", BootMenuUpdateBootOption },\r
435 { L"Remove Boot Device Entry", BootMenuRemoveBootOption },\r
436};\r
437\r
438EFI_STATUS\r
439BootMenuManager (\r
440 IN LIST_ENTRY *BootOptionsList\r
441 )\r
442{\r
443 UINTN Index;\r
444 UINTN OptionSelected;\r
445 UINTN BootManagerEntryCount;\r
446 EFI_STATUS Status;\r
447\r
448 BootManagerEntryCount = sizeof(BootManagerEntries) / sizeof(struct BOOT_MANAGER_ENTRY);\r
449\r
450 while (TRUE) {\r
451 // Display Boot Manager menu\r
452 for (Index = 0; Index < BootManagerEntryCount; Index++) {\r
453 Print(L"[%d] %s\n",Index+1,BootManagerEntries[Index]);\r
454 }\r
455 Print(L"[%d] Return to main menu\n",Index+1);\r
456\r
457 // Select which entry to call\r
458 Print(L"Choice: ");\r
459 Status = GetHIInputInteger (&OptionSelected);\r
460 if (EFI_ERROR(Status) || (OptionSelected == (BootManagerEntryCount+1))) {\r
326d1df9 461 if (EFI_ERROR(Status)) {\r
462 Print(L"\n");\r
463 }\r
ea46ebbe 464 return EFI_SUCCESS;\r
465 } else if ((OptionSelected > 0) && (OptionSelected <= BootManagerEntryCount)) {\r
466 Status = BootManagerEntries[OptionSelected-1].Callback (BootOptionsList);\r
467 }\r
468 }\r
469\r
470 return EFI_SUCCESS;\r
471}\r
472\r
473EFI_STATUS\r
474BootEBL (\r
475 IN LIST_ENTRY *BootOptionsList\r
476 )\r
477{\r
478 EFI_STATUS Status;\r
479\r
480 // Start EFI Shell\r
2755d844 481 Status = BdsLoadApplication (mImageHandle, L"Ebl", 0, NULL);\r
ea46ebbe 482 if (Status == EFI_NOT_FOUND) {\r
483 Print (L"Error: EFI Application not found.\n");\r
484 } else if (EFI_ERROR(Status)) {\r
485 Print (L"Error: Status Code: 0x%X\n",(UINT32)Status);\r
486 }\r
487\r
488 return Status;\r
489}\r
490\r
491struct BOOT_MAIN_ENTRY {\r
492 CONST CHAR16* Description;\r
493 EFI_STATUS (*Callback) (IN LIST_ENTRY *BootOptionsList);\r
494} BootMainEntries[] = {\r
495 { L"EBL", BootEBL },\r
496 { L"Boot Manager", BootMenuManager },\r
497};\r
498\r
499\r
500EFI_STATUS\r
501BootMenuMain (\r
502 VOID\r
503 )\r
504{\r
2ccfb71e 505 LIST_ENTRY BootOptionsList;\r
506 UINTN OptionCount;\r
507 UINTN BootOptionCount;\r
508 EFI_STATUS Status;\r
509 LIST_ENTRY* Entry;\r
510 BDS_LOAD_OPTION* BootOption;\r
511 UINTN BootOptionSelected;\r
512 UINTN Index;\r
513 UINTN BootMainEntryCount;\r
ea46ebbe 514\r
e862cd50 515 BootOption = NULL;\r
ea46ebbe 516 BootMainEntryCount = sizeof(BootMainEntries) / sizeof(struct BOOT_MAIN_ENTRY);\r
a6caee65 517\r
ea46ebbe 518 while (TRUE) {\r
a6e97d28 519 // Get Boot#### list\r
520 BootOptionList (&BootOptionsList);\r
521\r
ea46ebbe 522 OptionCount = 1;\r
523\r
524 // Display the Boot options\r
525 for (Entry = GetFirstNode (&BootOptionsList);\r
526 !IsNull (&BootOptionsList,Entry);\r
527 Entry = GetNextNode (&BootOptionsList,Entry)\r
528 )\r
529 {\r
530 BootOption = LOAD_OPTION_FROM_LINK(Entry);\r
531\r
532 Print(L"[%d] %s\n",OptionCount,BootOption->Description);\r
533\r
534 DEBUG_CODE_BEGIN();\r
535 CHAR16* DevicePathTxt;\r
536 EFI_DEVICE_PATH_TO_TEXT_PROTOCOL* DevicePathToTextProtocol;\r
2ccfb71e 537 ARM_BDS_LOADER_OPTIONAL_DATA* OptionalData;\r
538 UINTN CmdLineSize;\r
539 ARM_BDS_LOADER_TYPE LoaderType;\r
ea46ebbe 540\r
541 Status = gBS->LocateProtocol(&gEfiDevicePathToTextProtocolGuid, NULL, (VOID **)&DevicePathToTextProtocol);\r
aa95e2f7 542 if (EFI_ERROR(Status)) {\r
543 // You must provide an implementation of DevicePathToTextProtocol in your firmware (eg: DevicePathDxe)\r
544 DEBUG((EFI_D_ERROR,"Error: Bds requires DevicePathToTextProtocol\n"));\r
545 return Status;\r
546 }\r
ea46ebbe 547 DevicePathTxt = DevicePathToTextProtocol->ConvertDevicePathToText(BootOption->FilePathList,TRUE,TRUE);\r
548\r
549 Print(L"\t- %s\n",DevicePathTxt);\r
2ccfb71e 550\r
551 // If it is a supported BootEntry then print its details\r
552 if (IS_ARM_BDS_BOOTENTRY (BootOption)) {\r
553 OptionalData = BootOption->OptionalData;\r
554 LoaderType = (ARM_BDS_LOADER_TYPE)ReadUnaligned32 ((CONST UINT32*)&OptionalData->Header.LoaderType);\r
555 if ((LoaderType == BDS_LOADER_KERNEL_LINUX_ATAG) || (LoaderType == BDS_LOADER_KERNEL_LINUX_FDT)) {\r
556 if (ReadUnaligned16 (&OptionalData->Arguments.LinuxArguments.InitrdSize) > 0) {\r
557 CmdLineSize = ReadUnaligned16 (&OptionalData->Arguments.LinuxArguments.CmdLineSize);\r
558 DevicePathTxt = DevicePathToTextProtocol->ConvertDevicePathToText (\r
559 GetAlignedDevicePath ((EFI_DEVICE_PATH*)((UINTN)(&OptionalData->Arguments.LinuxArguments + 1) + CmdLineSize)), TRUE, TRUE);\r
560 Print(L"\t- Initrd: %s\n", DevicePathTxt);\r
561 }\r
562 Print(L"\t- Arguments: %a\n", (&OptionalData->Arguments.LinuxArguments + 1));\r
ea46ebbe 563 }\r
2ccfb71e 564 Print(L"\t- LoaderType: %d\n", LoaderType);\r
ea46ebbe 565 }\r
ea46ebbe 566 FreePool(DevicePathTxt);\r
567 DEBUG_CODE_END();\r
568\r
569 OptionCount++;\r
570 }\r
571 BootOptionCount = OptionCount-1;\r
572\r
573 // Display the hardcoded Boot entries\r
574 for (Index = 0; Index < BootMainEntryCount; Index++) {\r
575 Print(L"[%d] %s\n",OptionCount,BootMainEntries[Index]);\r
576 OptionCount++;\r
577 }\r
578\r
579 // Request the boot entry from the user\r
580 BootOptionSelected = 0;\r
581 while (BootOptionSelected == 0) {\r
582 Print(L"Start: ");\r
583 Status = GetHIInputInteger (&BootOptionSelected);\r
584 if (EFI_ERROR(Status) || (BootOptionSelected == 0) || (BootOptionSelected > OptionCount)) {\r
585 Print(L"Invalid input (max %d)\n",(OptionCount-1));\r
586 BootOptionSelected = 0;\r
587 }\r
588 }\r
589\r
590 // Start the selected entry\r
591 if (BootOptionSelected > BootOptionCount) {\r
592 // Start the hardcoded entry\r
593 Status = BootMainEntries[BootOptionSelected - BootOptionCount - 1].Callback (&BootOptionsList);\r
594 } else {\r
595 // Find the selected entry from the Boot#### list\r
596 Index = 1;\r
597 for (Entry = GetFirstNode (&BootOptionsList);\r
598 !IsNull (&BootOptionsList,Entry);\r
599 Entry = GetNextNode (&BootOptionsList,Entry)\r
600 )\r
601 {\r
602 if (Index == BootOptionSelected) {\r
603 BootOption = LOAD_OPTION_FROM_LINK(Entry);\r
604 break;\r
605 }\r
606 Index++;\r
607 }\r
608\r
609 Status = BootOptionStart (BootOption);\r
610 }\r
611 }\r
612\r
613 return Status;\r
614}\r