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