ArmPlatformPkg/Bds: Fix when the default console variables are empty (or null)
[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
95b3580f 439EFI_STATUS\r
440UpdateFdtPath (\r
441 IN LIST_ENTRY *BootOptionsList\r
442 )\r
443{\r
444 EFI_STATUS Status;\r
445\r
446 BDS_SUPPORTED_DEVICE *SupportedBootDevice;\r
447 EFI_DEVICE_PATH_PROTOCOL *FdtDevicePathNode;\r
448 EFI_DEVICE_PATH_PROTOCOL *FdtDevicePath;\r
449\r
450 Status = SelectBootDevice (&SupportedBootDevice);\r
451 if (EFI_ERROR(Status)) {\r
452 Status = EFI_ABORTED;\r
453 goto EXIT;\r
454 }\r
455\r
456 // Create the specific device path node\r
457 Print(L"File path of the FDT blob: ");\r
458 Status = SupportedBootDevice->Support->CreateDevicePathNode (SupportedBootDevice, &FdtDevicePathNode, NULL, NULL);\r
459 if (EFI_ERROR(Status)) {\r
460 Status = EFI_ABORTED;\r
461 goto EXIT;\r
462 }\r
463\r
464 if (FdtDevicePathNode != NULL) {\r
465 // Append the Device Path node to the select device path\r
466 FdtDevicePath = AppendDevicePathNode (SupportedBootDevice->DevicePathProtocol, FdtDevicePathNode);\r
467 Status = gRT->SetVariable ((CHAR16*)L"FDT", &gEfiGlobalVariableGuid, (EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS ), 4, &FdtDevicePath);\r
468 ASSERT_EFI_ERROR(Status);\r
469 } else {\r
470 gRT->SetVariable ((CHAR16*)L"FDT", &gEfiGlobalVariableGuid, (EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS ), 0, NULL);\r
471 ASSERT_EFI_ERROR(Status);\r
472 }\r
473\r
474EXIT:\r
475 if (Status == EFI_ABORTED) {\r
476 Print(L"\n");\r
477 }\r
478 FreePool(SupportedBootDevice);\r
479 return Status;\r
480}\r
481\r
ea46ebbe 482struct BOOT_MANAGER_ENTRY {\r
483 CONST CHAR16* Description;\r
484 EFI_STATUS (*Callback) (IN LIST_ENTRY *BootOptionsList);\r
485} BootManagerEntries[] = {\r
486 { L"Add Boot Device Entry", BootMenuAddBootOption },\r
487 { L"Update Boot Device Entry", BootMenuUpdateBootOption },\r
488 { L"Remove Boot Device Entry", BootMenuRemoveBootOption },\r
95b3580f 489 { L"Update FDT path", UpdateFdtPath },\r
ea46ebbe 490};\r
491\r
492EFI_STATUS\r
493BootMenuManager (\r
494 IN LIST_ENTRY *BootOptionsList\r
495 )\r
496{\r
497 UINTN Index;\r
498 UINTN OptionSelected;\r
499 UINTN BootManagerEntryCount;\r
500 EFI_STATUS Status;\r
501\r
502 BootManagerEntryCount = sizeof(BootManagerEntries) / sizeof(struct BOOT_MANAGER_ENTRY);\r
503\r
504 while (TRUE) {\r
505 // Display Boot Manager menu\r
506 for (Index = 0; Index < BootManagerEntryCount; Index++) {\r
507 Print(L"[%d] %s\n",Index+1,BootManagerEntries[Index]);\r
508 }\r
509 Print(L"[%d] Return to main menu\n",Index+1);\r
510\r
511 // Select which entry to call\r
512 Print(L"Choice: ");\r
513 Status = GetHIInputInteger (&OptionSelected);\r
514 if (EFI_ERROR(Status) || (OptionSelected == (BootManagerEntryCount+1))) {\r
326d1df9 515 if (EFI_ERROR(Status)) {\r
516 Print(L"\n");\r
517 }\r
ea46ebbe 518 return EFI_SUCCESS;\r
519 } else if ((OptionSelected > 0) && (OptionSelected <= BootManagerEntryCount)) {\r
ff7666c5 520 BootManagerEntries[OptionSelected-1].Callback (BootOptionsList);\r
ea46ebbe 521 }\r
522 }\r
11c20f4e 523 // Should never go here\r
ea46ebbe 524}\r
525\r
526EFI_STATUS\r
527BootEBL (\r
528 IN LIST_ENTRY *BootOptionsList\r
529 )\r
530{\r
531 EFI_STATUS Status;\r
532\r
533 // Start EFI Shell\r
2755d844 534 Status = BdsLoadApplication (mImageHandle, L"Ebl", 0, NULL);\r
ea46ebbe 535 if (Status == EFI_NOT_FOUND) {\r
536 Print (L"Error: EFI Application not found.\n");\r
537 } else if (EFI_ERROR(Status)) {\r
538 Print (L"Error: Status Code: 0x%X\n",(UINT32)Status);\r
539 }\r
540\r
541 return Status;\r
542}\r
543\r
544struct BOOT_MAIN_ENTRY {\r
545 CONST CHAR16* Description;\r
546 EFI_STATUS (*Callback) (IN LIST_ENTRY *BootOptionsList);\r
547} BootMainEntries[] = {\r
548 { L"EBL", BootEBL },\r
549 { L"Boot Manager", BootMenuManager },\r
550};\r
551\r
552\r
553EFI_STATUS\r
554BootMenuMain (\r
555 VOID\r
556 )\r
557{\r
2ccfb71e 558 LIST_ENTRY BootOptionsList;\r
559 UINTN OptionCount;\r
560 UINTN BootOptionCount;\r
561 EFI_STATUS Status;\r
562 LIST_ENTRY* Entry;\r
563 BDS_LOAD_OPTION* BootOption;\r
564 UINTN BootOptionSelected;\r
565 UINTN Index;\r
566 UINTN BootMainEntryCount;\r
ea46ebbe 567\r
e862cd50 568 BootOption = NULL;\r
ea46ebbe 569 BootMainEntryCount = sizeof(BootMainEntries) / sizeof(struct BOOT_MAIN_ENTRY);\r
a6caee65 570\r
ea46ebbe 571 while (TRUE) {\r
a6e97d28 572 // Get Boot#### list\r
573 BootOptionList (&BootOptionsList);\r
574\r
ea46ebbe 575 OptionCount = 1;\r
576\r
577 // Display the Boot options\r
578 for (Entry = GetFirstNode (&BootOptionsList);\r
579 !IsNull (&BootOptionsList,Entry);\r
580 Entry = GetNextNode (&BootOptionsList,Entry)\r
581 )\r
582 {\r
583 BootOption = LOAD_OPTION_FROM_LINK(Entry);\r
584\r
ff7666c5 585 Print(L"[%d] %s\n", OptionCount, BootOption->Description);\r
ea46ebbe 586\r
587 DEBUG_CODE_BEGIN();\r
588 CHAR16* DevicePathTxt;\r
589 EFI_DEVICE_PATH_TO_TEXT_PROTOCOL* DevicePathToTextProtocol;\r
2ccfb71e 590 ARM_BDS_LOADER_OPTIONAL_DATA* OptionalData;\r
591 UINTN CmdLineSize;\r
3e710183 592 ARM_BDS_LOADER_TYPE LoaderType;\r
ea46ebbe 593\r
ff7666c5 594 Status = gBS->LocateProtocol (&gEfiDevicePathToTextProtocolGuid, NULL, (VOID **)&DevicePathToTextProtocol);\r
aa95e2f7 595 if (EFI_ERROR(Status)) {\r
596 // You must provide an implementation of DevicePathToTextProtocol in your firmware (eg: DevicePathDxe)\r
597 DEBUG((EFI_D_ERROR,"Error: Bds requires DevicePathToTextProtocol\n"));\r
598 return Status;\r
599 }\r
ff7666c5 600 DevicePathTxt = DevicePathToTextProtocol->ConvertDevicePathToText (BootOption->FilePathList, TRUE, TRUE);\r
ea46ebbe 601\r
602 Print(L"\t- %s\n",DevicePathTxt);\r
2ccfb71e 603\r
604 // If it is a supported BootEntry then print its details\r
605 if (IS_ARM_BDS_BOOTENTRY (BootOption)) {\r
606 OptionalData = BootOption->OptionalData;\r
607 LoaderType = (ARM_BDS_LOADER_TYPE)ReadUnaligned32 ((CONST UINT32*)&OptionalData->Header.LoaderType);\r
608 if ((LoaderType == BDS_LOADER_KERNEL_LINUX_ATAG) || (LoaderType == BDS_LOADER_KERNEL_LINUX_FDT)) {\r
609 if (ReadUnaligned16 (&OptionalData->Arguments.LinuxArguments.InitrdSize) > 0) {\r
610 CmdLineSize = ReadUnaligned16 (&OptionalData->Arguments.LinuxArguments.CmdLineSize);\r
611 DevicePathTxt = DevicePathToTextProtocol->ConvertDevicePathToText (\r
612 GetAlignedDevicePath ((EFI_DEVICE_PATH*)((UINTN)(&OptionalData->Arguments.LinuxArguments + 1) + CmdLineSize)), TRUE, TRUE);\r
613 Print(L"\t- Initrd: %s\n", DevicePathTxt);\r
614 }\r
615 Print(L"\t- Arguments: %a\n", (&OptionalData->Arguments.LinuxArguments + 1));\r
ea46ebbe 616 }\r
2ccfb71e 617 Print(L"\t- LoaderType: %d\n", LoaderType);\r
ea46ebbe 618 }\r
ea46ebbe 619 FreePool(DevicePathTxt);\r
620 DEBUG_CODE_END();\r
621\r
622 OptionCount++;\r
623 }\r
624 BootOptionCount = OptionCount-1;\r
625\r
626 // Display the hardcoded Boot entries\r
627 for (Index = 0; Index < BootMainEntryCount; Index++) {\r
628 Print(L"[%d] %s\n",OptionCount,BootMainEntries[Index]);\r
629 OptionCount++;\r
630 }\r
631\r
632 // Request the boot entry from the user\r
633 BootOptionSelected = 0;\r
634 while (BootOptionSelected == 0) {\r
635 Print(L"Start: ");\r
636 Status = GetHIInputInteger (&BootOptionSelected);\r
637 if (EFI_ERROR(Status) || (BootOptionSelected == 0) || (BootOptionSelected > OptionCount)) {\r
638 Print(L"Invalid input (max %d)\n",(OptionCount-1));\r
639 BootOptionSelected = 0;\r
640 }\r
641 }\r
642\r
643 // Start the selected entry\r
644 if (BootOptionSelected > BootOptionCount) {\r
645 // Start the hardcoded entry\r
646 Status = BootMainEntries[BootOptionSelected - BootOptionCount - 1].Callback (&BootOptionsList);\r
647 } else {\r
648 // Find the selected entry from the Boot#### list\r
649 Index = 1;\r
650 for (Entry = GetFirstNode (&BootOptionsList);\r
651 !IsNull (&BootOptionsList,Entry);\r
652 Entry = GetNextNode (&BootOptionsList,Entry)\r
653 )\r
654 {\r
655 if (Index == BootOptionSelected) {\r
656 BootOption = LOAD_OPTION_FROM_LINK(Entry);\r
657 break;\r
658 }\r
659 Index++;\r
660 }\r
661\r
662 Status = BootOptionStart (BootOption);\r
663 }\r
664 }\r
11c20f4e 665 // Should never go here\r
ea46ebbe 666}\r