]> git.proxmox.com Git - mirror_edk2.git/blame - ArmPlatformPkg/Bds/BootMenu.c
ArmPlatformPkg/Bds: Fix the update of existing boot entries
[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
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
ff7666c5 288 !IsNull (BootOptionsList, Entry);\r
ea46ebbe 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
ff7666c5 354 Status = BootDeviceGetDeviceSupport (BootOption, &DeviceSupport);\r
ea46ebbe 355 if (EFI_ERROR(Status)) {\r
ff7666c5 356 Print(L"Not possible to retrieve the supported device for the update\n");\r
ea46ebbe 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
2ccfb71e 375\r
3e710183 376 InitrdSize = ReadUnaligned16 ((CONST UINT16*)&LinuxArguments->InitrdSize);\r
377 if (InitrdSize > 0) {\r
378 Print(L"File path of the initrd: ");\r
379 Status = DeviceSupport->UpdateDevicePathNode ((EFI_DEVICE_PATH*)((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
383 }\r
384 InitrdSize = GetDevicePathSize (InitrdPathList);\r
656416bc 385 }\r
386\r
2ccfb71e 387 Print(L"Arguments to pass to the binary: "); \r
388 if (CmdLineSize > 0) {\r
389 AsciiStrnCpy(CmdLine, (CONST CHAR8*)(LinuxArguments + 1), CmdLineSize);\r
656416bc 390 } else {\r
2ccfb71e 391 CmdLine[0] = '\0';\r
656416bc 392 }\r
2ccfb71e 393 Status = EditHIInputAscii (CmdLine, BOOT_DEVICE_OPTION_MAX);\r
656416bc 394 if (EFI_ERROR(Status)) {\r
395 Status = EFI_ABORTED;\r
396 goto FREE_DEVICE_PATH;\r
397 }\r
2ccfb71e 398\r
399 CmdLineSize = AsciiStrSize (CmdLine);\r
2ccfb71e 400\r
401 BootArguments = (ARM_BDS_LOADER_ARGUMENTS*)AllocatePool(sizeof(ARM_BDS_LOADER_ARGUMENTS) + CmdLineSize + InitrdSize);\r
402 BootArguments->LinuxArguments.CmdLineSize = CmdLineSize;\r
403 BootArguments->LinuxArguments.InitrdSize = InitrdSize;\r
404 CopyMem (&BootArguments->LinuxArguments + 1, CmdLine, CmdLineSize);\r
405 CopyMem ((UINTN)(&BootArguments->LinuxArguments + 1) + CmdLine, InitrdPathList, InitrdSize);\r
406 } else {\r
407 BootArguments = NULL;\r
ea46ebbe 408 }\r
409\r
410 Print(L"Description for this new Entry: ");\r
3e710183 411 StrnCpy (BootDescription, BootOption->Description, BOOT_DEVICE_DESCRIPTION_MAX);\r
74b96132 412 Status = EditHIInputStr (BootDescription, BOOT_DEVICE_DESCRIPTION_MAX);\r
ea46ebbe 413 if (EFI_ERROR(Status)) {\r
414 Status = EFI_ABORTED;\r
415 goto FREE_DEVICE_PATH;\r
416 }\r
417\r
ea46ebbe 418 // Update the entry\r
2ccfb71e 419 Status = BootOptionUpdate (BootOption, BootOption->Attributes, BootDescription, DevicePath, BootType, BootArguments);\r
ea46ebbe 420\r
ea46ebbe 421FREE_DEVICE_PATH:\r
422 FreePool (DevicePath);\r
423\r
424EXIT:\r
326d1df9 425 if (Status == EFI_ABORTED) {\r
426 Print(L"\n");\r
427 }\r
ea46ebbe 428 return Status;\r
429}\r
430\r
431struct BOOT_MANAGER_ENTRY {\r
432 CONST CHAR16* Description;\r
433 EFI_STATUS (*Callback) (IN LIST_ENTRY *BootOptionsList);\r
434} BootManagerEntries[] = {\r
435 { L"Add Boot Device Entry", BootMenuAddBootOption },\r
436 { L"Update Boot Device Entry", BootMenuUpdateBootOption },\r
437 { L"Remove Boot Device Entry", BootMenuRemoveBootOption },\r
438};\r
439\r
440EFI_STATUS\r
441BootMenuManager (\r
442 IN LIST_ENTRY *BootOptionsList\r
443 )\r
444{\r
445 UINTN Index;\r
446 UINTN OptionSelected;\r
447 UINTN BootManagerEntryCount;\r
448 EFI_STATUS Status;\r
449\r
450 BootManagerEntryCount = sizeof(BootManagerEntries) / sizeof(struct BOOT_MANAGER_ENTRY);\r
451\r
452 while (TRUE) {\r
453 // Display Boot Manager menu\r
454 for (Index = 0; Index < BootManagerEntryCount; Index++) {\r
455 Print(L"[%d] %s\n",Index+1,BootManagerEntries[Index]);\r
456 }\r
457 Print(L"[%d] Return to main menu\n",Index+1);\r
458\r
459 // Select which entry to call\r
460 Print(L"Choice: ");\r
461 Status = GetHIInputInteger (&OptionSelected);\r
462 if (EFI_ERROR(Status) || (OptionSelected == (BootManagerEntryCount+1))) {\r
326d1df9 463 if (EFI_ERROR(Status)) {\r
464 Print(L"\n");\r
465 }\r
ea46ebbe 466 return EFI_SUCCESS;\r
467 } else if ((OptionSelected > 0) && (OptionSelected <= BootManagerEntryCount)) {\r
ff7666c5 468 BootManagerEntries[OptionSelected-1].Callback (BootOptionsList);\r
ea46ebbe 469 }\r
470 }\r
471\r
472 return EFI_SUCCESS;\r
473}\r
474\r
475EFI_STATUS\r
476BootEBL (\r
477 IN LIST_ENTRY *BootOptionsList\r
478 )\r
479{\r
480 EFI_STATUS Status;\r
481\r
482 // Start EFI Shell\r
2755d844 483 Status = BdsLoadApplication (mImageHandle, L"Ebl", 0, NULL);\r
ea46ebbe 484 if (Status == EFI_NOT_FOUND) {\r
485 Print (L"Error: EFI Application not found.\n");\r
486 } else if (EFI_ERROR(Status)) {\r
487 Print (L"Error: Status Code: 0x%X\n",(UINT32)Status);\r
488 }\r
489\r
490 return Status;\r
491}\r
492\r
493struct BOOT_MAIN_ENTRY {\r
494 CONST CHAR16* Description;\r
495 EFI_STATUS (*Callback) (IN LIST_ENTRY *BootOptionsList);\r
496} BootMainEntries[] = {\r
497 { L"EBL", BootEBL },\r
498 { L"Boot Manager", BootMenuManager },\r
499};\r
500\r
501\r
502EFI_STATUS\r
503BootMenuMain (\r
504 VOID\r
505 )\r
506{\r
2ccfb71e 507 LIST_ENTRY BootOptionsList;\r
508 UINTN OptionCount;\r
509 UINTN BootOptionCount;\r
510 EFI_STATUS Status;\r
511 LIST_ENTRY* Entry;\r
512 BDS_LOAD_OPTION* BootOption;\r
513 UINTN BootOptionSelected;\r
514 UINTN Index;\r
515 UINTN BootMainEntryCount;\r
ea46ebbe 516\r
e862cd50 517 BootOption = NULL;\r
ea46ebbe 518 BootMainEntryCount = sizeof(BootMainEntries) / sizeof(struct BOOT_MAIN_ENTRY);\r
a6caee65 519\r
ea46ebbe 520 while (TRUE) {\r
a6e97d28 521 // Get Boot#### list\r
522 BootOptionList (&BootOptionsList);\r
523\r
ea46ebbe 524 OptionCount = 1;\r
525\r
526 // Display the Boot options\r
527 for (Entry = GetFirstNode (&BootOptionsList);\r
528 !IsNull (&BootOptionsList,Entry);\r
529 Entry = GetNextNode (&BootOptionsList,Entry)\r
530 )\r
531 {\r
532 BootOption = LOAD_OPTION_FROM_LINK(Entry);\r
533\r
ff7666c5 534 Print(L"[%d] %s\n", OptionCount, BootOption->Description);\r
ea46ebbe 535\r
536 DEBUG_CODE_BEGIN();\r
537 CHAR16* DevicePathTxt;\r
538 EFI_DEVICE_PATH_TO_TEXT_PROTOCOL* DevicePathToTextProtocol;\r
2ccfb71e 539 ARM_BDS_LOADER_OPTIONAL_DATA* OptionalData;\r
540 UINTN CmdLineSize;\r
3e710183 541 ARM_BDS_LOADER_TYPE LoaderType;\r
ea46ebbe 542\r
ff7666c5 543 Status = gBS->LocateProtocol (&gEfiDevicePathToTextProtocolGuid, NULL, (VOID **)&DevicePathToTextProtocol);\r
aa95e2f7 544 if (EFI_ERROR(Status)) {\r
545 // You must provide an implementation of DevicePathToTextProtocol in your firmware (eg: DevicePathDxe)\r
546 DEBUG((EFI_D_ERROR,"Error: Bds requires DevicePathToTextProtocol\n"));\r
547 return Status;\r
548 }\r
ff7666c5 549 DevicePathTxt = DevicePathToTextProtocol->ConvertDevicePathToText (BootOption->FilePathList, TRUE, TRUE);\r
ea46ebbe 550\r
551 Print(L"\t- %s\n",DevicePathTxt);\r
2ccfb71e 552\r
553 // If it is a supported BootEntry then print its details\r
554 if (IS_ARM_BDS_BOOTENTRY (BootOption)) {\r
555 OptionalData = BootOption->OptionalData;\r
556 LoaderType = (ARM_BDS_LOADER_TYPE)ReadUnaligned32 ((CONST UINT32*)&OptionalData->Header.LoaderType);\r
557 if ((LoaderType == BDS_LOADER_KERNEL_LINUX_ATAG) || (LoaderType == BDS_LOADER_KERNEL_LINUX_FDT)) {\r
558 if (ReadUnaligned16 (&OptionalData->Arguments.LinuxArguments.InitrdSize) > 0) {\r
559 CmdLineSize = ReadUnaligned16 (&OptionalData->Arguments.LinuxArguments.CmdLineSize);\r
560 DevicePathTxt = DevicePathToTextProtocol->ConvertDevicePathToText (\r
561 GetAlignedDevicePath ((EFI_DEVICE_PATH*)((UINTN)(&OptionalData->Arguments.LinuxArguments + 1) + CmdLineSize)), TRUE, TRUE);\r
562 Print(L"\t- Initrd: %s\n", DevicePathTxt);\r
563 }\r
564 Print(L"\t- Arguments: %a\n", (&OptionalData->Arguments.LinuxArguments + 1));\r
ea46ebbe 565 }\r
2ccfb71e 566 Print(L"\t- LoaderType: %d\n", LoaderType);\r
ea46ebbe 567 }\r
ea46ebbe 568 FreePool(DevicePathTxt);\r
569 DEBUG_CODE_END();\r
570\r
571 OptionCount++;\r
572 }\r
573 BootOptionCount = OptionCount-1;\r
574\r
575 // Display the hardcoded Boot entries\r
576 for (Index = 0; Index < BootMainEntryCount; Index++) {\r
577 Print(L"[%d] %s\n",OptionCount,BootMainEntries[Index]);\r
578 OptionCount++;\r
579 }\r
580\r
581 // Request the boot entry from the user\r
582 BootOptionSelected = 0;\r
583 while (BootOptionSelected == 0) {\r
584 Print(L"Start: ");\r
585 Status = GetHIInputInteger (&BootOptionSelected);\r
586 if (EFI_ERROR(Status) || (BootOptionSelected == 0) || (BootOptionSelected > OptionCount)) {\r
587 Print(L"Invalid input (max %d)\n",(OptionCount-1));\r
588 BootOptionSelected = 0;\r
589 }\r
590 }\r
591\r
592 // Start the selected entry\r
593 if (BootOptionSelected > BootOptionCount) {\r
594 // Start the hardcoded entry\r
595 Status = BootMainEntries[BootOptionSelected - BootOptionCount - 1].Callback (&BootOptionsList);\r
596 } else {\r
597 // Find the selected entry from the Boot#### list\r
598 Index = 1;\r
599 for (Entry = GetFirstNode (&BootOptionsList);\r
600 !IsNull (&BootOptionsList,Entry);\r
601 Entry = GetNextNode (&BootOptionsList,Entry)\r
602 )\r
603 {\r
604 if (Index == BootOptionSelected) {\r
605 BootOption = LOAD_OPTION_FROM_LINK(Entry);\r
606 break;\r
607 }\r
608 Index++;\r
609 }\r
610\r
611 Status = BootOptionStart (BootOption);\r
612 }\r
613 }\r
614\r
615 return Status;\r
616}\r