]> git.proxmox.com Git - mirror_edk2.git/blame - ArmPlatformPkg/Bds/BootMenu.c
BeagleBoardPkg/b.bat: Updated RVCT toolchain name
[mirror_edk2.git] / ArmPlatformPkg / Bds / BootMenu.c
CommitLineData
ea46ebbe 1/** @file\r
2*\r
49a25d84 3* Copyright (c) 2011-2012, ARM Limited. All rights reserved.\r
ea46ebbe 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
22a262c8 129 BOOLEAN InitrdSupport;\r
2ccfb71e 130 UINTN InitrdSize;\r
656416bc 131\r
132 Attributes = 0;\r
133 SupportedBootDevice = NULL;\r
134\r
135 // List the Boot Devices supported\r
2ccfb71e 136 Status = SelectBootDevice (&SupportedBootDevice);\r
656416bc 137 if (EFI_ERROR(Status)) {\r
138 Status = EFI_ABORTED;\r
139 goto EXIT;\r
140 }\r
ea46ebbe 141\r
142 // Create the specific device path node\r
22a262c8 143 Status = SupportedBootDevice->Support->CreateDevicePathNode (L"EFI Application or the kernel", &DevicePathNode, &BootType, &Attributes);\r
ea46ebbe 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
22a262c8 152 Print(L"Add an initrd: ");\r
153 Status = GetHIInputBoolean (&InitrdSupport);\r
154 if (EFI_ERROR(Status)) {\r
656416bc 155 Status = EFI_ABORTED;\r
156 goto EXIT;\r
157 }\r
158\r
22a262c8 159 if (InitrdSupport) {\r
160 // Create the specific device path node\r
161 Status = SupportedBootDevice->Support->CreateDevicePathNode (L"initrd", &InitrdPathNode, NULL, NULL);\r
162 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
163 Status = EFI_ABORTED;\r
164 goto EXIT;\r
165 }\r
166\r
167 if (InitrdPathNode != NULL) {\r
168 // Append the Device Path node to the select device path\r
169 InitrdPath = AppendDevicePathNode (SupportedBootDevice->DevicePathProtocol, (CONST EFI_DEVICE_PATH_PROTOCOL *)InitrdPathNode);\r
170 } else {\r
171 InitrdPath = NULL;\r
172 }\r
656416bc 173 } else {\r
2ccfb71e 174 InitrdPath = NULL;\r
656416bc 175 }\r
176\r
177 Print(L"Arguments to pass to the binary: ");\r
2ccfb71e 178 Status = GetHIInputAscii (CmdLine,BOOT_DEVICE_OPTION_MAX);\r
656416bc 179 if (EFI_ERROR(Status)) {\r
180 Status = EFI_ABORTED;\r
181 goto FREE_DEVICE_PATH;\r
182 }\r
2ccfb71e 183\r
184 CmdLineSize = AsciiStrSize (CmdLine);\r
185 InitrdSize = GetDevicePathSize (InitrdPath);\r
186\r
187 BootArguments = (ARM_BDS_LOADER_ARGUMENTS*)AllocatePool (sizeof(ARM_BDS_LOADER_ARGUMENTS) + CmdLineSize + InitrdSize);\r
188 \r
189 BootArguments->LinuxArguments.CmdLineSize = CmdLineSize;\r
190 BootArguments->LinuxArguments.InitrdSize = InitrdSize;\r
191 CopyMem ((VOID*)(&BootArguments->LinuxArguments + 1), CmdLine, CmdLineSize);\r
192 CopyMem ((VOID*)((UINTN)(&BootArguments->LinuxArguments + 1) + CmdLineSize), InitrdPath, InitrdSize);\r
193 } else {\r
194 BootArguments = NULL;\r
ea46ebbe 195 }\r
196\r
197 Print(L"Description for this new Entry: ");\r
74b96132 198 Status = GetHIInputStr (BootDescription, BOOT_DEVICE_DESCRIPTION_MAX);\r
ea46ebbe 199 if (EFI_ERROR(Status)) {\r
200 Status = EFI_ABORTED;\r
201 goto FREE_DEVICE_PATH;\r
202 }\r
203\r
ea46ebbe 204 // Create new entry\r
a6e97d28 205 BdsLoadOptionEntry = (BDS_LOAD_OPTION_ENTRY*)AllocatePool (sizeof(BDS_LOAD_OPTION_ENTRY));\r
206 Status = BootOptionCreate (Attributes, BootDescription, DevicePath, BootType, BootArguments, &BdsLoadOptionEntry->BdsLoadOption);\r
ea46ebbe 207 if (!EFI_ERROR(Status)) {\r
a6e97d28 208 InsertTailList (BootOptionsList, &BdsLoadOptionEntry->Link);\r
ea46ebbe 209 }\r
210\r
ea46ebbe 211FREE_DEVICE_PATH:\r
212 FreePool (DevicePath);\r
213\r
656416bc 214 \r
ea46ebbe 215EXIT:\r
656416bc 216 if (Status == EFI_ABORTED) {\r
217 Print(L"\n");\r
218 }\r
219 FreePool(SupportedBootDevice);\r
ea46ebbe 220 return Status;\r
221}\r
222\r
223STATIC\r
224EFI_STATUS\r
225BootMenuSelectBootOption (\r
a6e97d28 226 IN LIST_ENTRY* BootOptionsList,\r
227 IN CONST CHAR16* InputStatement,\r
228 IN BOOLEAN OnlyArmBdsBootEntry,\r
229 OUT BDS_LOAD_OPTION_ENTRY** BdsLoadOptionEntry\r
ea46ebbe 230 )\r
231{\r
a6e97d28 232 EFI_STATUS Status;\r
233 LIST_ENTRY* Entry;\r
234 BDS_LOAD_OPTION* BdsLoadOption;\r
235 UINTN BootOptionSelected;\r
236 UINTN BootOptionCount;\r
237 UINTN Index;\r
ea46ebbe 238\r
239 // Display the list of supported boot devices\r
c93ab96c 240 BootOptionCount = 0;\r
ea46ebbe 241 for (Entry = GetFirstNode (BootOptionsList);\r
242 !IsNull (BootOptionsList,Entry);\r
a6e97d28 243 Entry = GetNextNode (BootOptionsList, Entry)\r
ea46ebbe 244 )\r
245 {\r
a6e97d28 246 BdsLoadOption = LOAD_OPTION_FROM_LINK(Entry);\r
247\r
248 if (OnlyArmBdsBootEntry && !IS_ARM_BDS_BOOTENTRY (BdsLoadOption)) {\r
249 continue;\r
250 }\r
251\r
c93ab96c 252 Print (L"[%d] %s\n", (BootOptionCount + 1), BdsLoadOption->Description);\r
ea46ebbe 253\r
254 DEBUG_CODE_BEGIN();\r
255 CHAR16* DevicePathTxt;\r
256 EFI_DEVICE_PATH_TO_TEXT_PROTOCOL* DevicePathToTextProtocol;\r
2ccfb71e 257 ARM_BDS_LOADER_TYPE LoaderType;\r
a6e97d28 258 ARM_BDS_LOADER_OPTIONAL_DATA* OptionalData;\r
ea46ebbe 259\r
260 Status = gBS->LocateProtocol(&gEfiDevicePathToTextProtocolGuid, NULL, (VOID **)&DevicePathToTextProtocol);\r
261 ASSERT_EFI_ERROR(Status);\r
a6e97d28 262 DevicePathTxt = DevicePathToTextProtocol->ConvertDevicePathToText(BdsLoadOption->FilePathList,TRUE,TRUE);\r
ea46ebbe 263\r
264 Print(L"\t- %s\n",DevicePathTxt);\r
2ccfb71e 265 OptionalData = BdsLoadOption->OptionalData;\r
266 LoaderType = (ARM_BDS_LOADER_TYPE)ReadUnaligned32 ((CONST UINT32*)&OptionalData->Header.LoaderType);\r
267 if ((LoaderType == BDS_LOADER_KERNEL_LINUX_ATAG) || (LoaderType == BDS_LOADER_KERNEL_LINUX_FDT)) {\r
268 Print (L"\t- Arguments: %a\n",&OptionalData->Arguments.LinuxArguments + 1);\r
ea46ebbe 269 }\r
270\r
271 FreePool(DevicePathTxt);\r
272 DEBUG_CODE_END();\r
273\r
274 BootOptionCount++;\r
275 }\r
276\r
c93ab96c 277 // Check if a valid boot option(s) is found\r
a6e97d28 278 if (BootOptionCount == 0) {\r
c93ab96c 279 if (StrCmp (InputStatement, DELETE_BOOT_ENTRY) == 0) {\r
280 Print (L"Nothing to remove!\n");\r
281 }else if (StrCmp (InputStatement, UPDATE_BOOT_ENTRY) == 0) {\r
282 Print (L"Couldn't find valid boot entries\n");\r
283 } else{\r
284 Print (L"No supported Boot Entry.\n");\r
285 }\r
286\r
a6e97d28 287 return EFI_NOT_FOUND;\r
288 }\r
289\r
ea46ebbe 290 // Get the index of the boot device to delete\r
291 BootOptionSelected = 0;\r
292 while (BootOptionSelected == 0) {\r
293 Print(InputStatement);\r
294 Status = GetHIInputInteger (&BootOptionSelected);\r
295 if (EFI_ERROR(Status)) {\r
296 return Status;\r
c93ab96c 297 } else if ((BootOptionSelected == 0) || (BootOptionSelected > BootOptionCount)) {\r
298 Print(L"Invalid input (max %d)\n",BootOptionCount);\r
ea46ebbe 299 BootOptionSelected = 0;\r
300 }\r
301 }\r
302\r
303 // Get the structure of the Boot device to delete\r
304 Index = 1;\r
305 for (Entry = GetFirstNode (BootOptionsList);\r
ff7666c5 306 !IsNull (BootOptionsList, Entry);\r
ea46ebbe 307 Entry = GetNextNode (BootOptionsList,Entry)\r
308 )\r
309 {\r
310 if (Index == BootOptionSelected) {\r
a6e97d28 311 *BdsLoadOptionEntry = LOAD_OPTION_ENTRY_FROM_LINK(Entry);\r
ea46ebbe 312 break;\r
313 }\r
314 Index++;\r
315 }\r
316\r
317 return EFI_SUCCESS;\r
318}\r
319\r
320EFI_STATUS\r
321BootMenuRemoveBootOption (\r
322 IN LIST_ENTRY *BootOptionsList\r
323 )\r
324{\r
a6e97d28 325 EFI_STATUS Status;\r
326 BDS_LOAD_OPTION_ENTRY* BootOptionEntry;\r
ea46ebbe 327\r
11c20f4e 328 Status = BootMenuSelectBootOption (BootOptionsList, DELETE_BOOT_ENTRY, FALSE, &BootOptionEntry);\r
ea46ebbe 329 if (EFI_ERROR(Status)) {\r
330 return Status;\r
331 }\r
332\r
a6e97d28 333 // If the Boot Option was attached to a list remove it\r
334 if (!IsListEmpty (&BootOptionEntry->Link)) {\r
335 // Remove the entry from the list\r
336 RemoveEntryList (&BootOptionEntry->Link);\r
337 }\r
338\r
ea46ebbe 339 // Delete the BDS Load option structures\r
a6e97d28 340 BootOptionDelete (BootOptionEntry->BdsLoadOption);\r
ea46ebbe 341\r
342 return EFI_SUCCESS;\r
343}\r
344\r
345EFI_STATUS\r
346BootMenuUpdateBootOption (\r
347 IN LIST_ENTRY *BootOptionsList\r
348 )\r
349{\r
2ccfb71e 350 EFI_STATUS Status;\r
a6e97d28 351 BDS_LOAD_OPTION_ENTRY *BootOptionEntry;\r
2ccfb71e 352 BDS_LOAD_OPTION *BootOption;\r
353 BDS_LOAD_OPTION_SUPPORT* DeviceSupport;\r
354 ARM_BDS_LOADER_ARGUMENTS* BootArguments;\r
74b96132 355 CHAR16 BootDescription[BOOT_DEVICE_DESCRIPTION_MAX];\r
2ccfb71e 356 CHAR8 CmdLine[BOOT_DEVICE_OPTION_MAX];\r
357 EFI_DEVICE_PATH* DevicePath;\r
358 ARM_BDS_LOADER_TYPE BootType;\r
359 ARM_BDS_LOADER_OPTIONAL_DATA* OptionalData;\r
360 ARM_BDS_LINUX_ARGUMENTS* LinuxArguments;\r
22a262c8 361 EFI_DEVICE_PATH *InitrdPathNode;\r
362 EFI_DEVICE_PATH *InitrdPath;\r
2ccfb71e 363 UINTN InitrdSize;\r
364 UINTN CmdLineSize;\r
22a262c8 365 BOOLEAN InitrdSupport;\r
ea46ebbe 366\r
11c20f4e 367 Status = BootMenuSelectBootOption (BootOptionsList, UPDATE_BOOT_ENTRY, TRUE, &BootOptionEntry);\r
ea46ebbe 368 if (EFI_ERROR(Status)) {\r
369 return Status;\r
370 }\r
a6e97d28 371 BootOption = BootOptionEntry->BdsLoadOption;\r
ea46ebbe 372\r
373 // Get the device support for this Boot Option\r
22a262c8 374 Status = BootDeviceGetDeviceSupport (BootOption->FilePathList, &DeviceSupport);\r
ea46ebbe 375 if (EFI_ERROR(Status)) {\r
ff7666c5 376 Print(L"Not possible to retrieve the supported device for the update\n");\r
ea46ebbe 377 return EFI_UNSUPPORTED;\r
378 }\r
379\r
22a262c8 380 Status = DeviceSupport->UpdateDevicePathNode (BootOption->FilePathList, L"EFI Application or the kernel", &DevicePath, NULL, NULL);\r
ea46ebbe 381 if (EFI_ERROR(Status)) {\r
382 Status = EFI_ABORTED;\r
383 goto EXIT;\r
384 }\r
385\r
2ccfb71e 386 OptionalData = BootOption->OptionalData;\r
387 BootType = (ARM_BDS_LOADER_TYPE)ReadUnaligned32 ((UINT32 *)(&OptionalData->Header.LoaderType));\r
656416bc 388\r
2ccfb71e 389 if ((BootType == BDS_LOADER_KERNEL_LINUX_ATAG) || (BootType == BDS_LOADER_KERNEL_LINUX_FDT)) {\r
390 LinuxArguments = &OptionalData->Arguments.LinuxArguments;\r
391\r
392 CmdLineSize = ReadUnaligned16 ((CONST UINT16*)&LinuxArguments->CmdLineSize);\r
2ccfb71e 393\r
3e710183 394 InitrdSize = ReadUnaligned16 ((CONST UINT16*)&LinuxArguments->InitrdSize);\r
395 if (InitrdSize > 0) {\r
22a262c8 396 Print(L"Keep the initrd: ");\r
397 } else {\r
398 Print(L"Add an initrd: ");\r
399 }\r
400 Status = GetHIInputBoolean (&InitrdSupport);\r
401 if (EFI_ERROR(Status)) {\r
402 Status = EFI_ABORTED;\r
403 goto EXIT;\r
404 }\r
405\r
406 if (InitrdSupport) {\r
407 if (InitrdSize > 0) {\r
408 // Case we update the initrd device path\r
49a25d84 409 Status = DeviceSupport->UpdateDevicePathNode ((EFI_DEVICE_PATH*)((UINTN)(LinuxArguments + 1) + CmdLineSize), L"initrd", &InitrdPath, NULL, NULL);\r
22a262c8 410 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
411 Status = EFI_ABORTED;\r
412 goto EXIT;\r
413 }\r
414 InitrdSize = GetDevicePathSize (InitrdPath);\r
415 } else {\r
416 // Case we create the initrd device path\r
417\r
418 Status = DeviceSupport->CreateDevicePathNode (L"initrd", &InitrdPathNode, NULL, NULL);\r
419 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
420 Status = EFI_ABORTED;\r
421 goto EXIT;\r
422 }\r
423\r
424 if (InitrdPathNode != NULL) {\r
425 // Duplicate Linux kernel Device Path\r
426 DevicePath = DuplicateDevicePath (BootOption->FilePathList);\r
427 // Replace Linux kernel Node by EndNode\r
428 SetDevicePathEndNode (GetLastDevicePathNode (DevicePath));\r
429 // Append the Device Path node to the select device path\r
430 InitrdPath = AppendDevicePathNode (DevicePath, (CONST EFI_DEVICE_PATH_PROTOCOL *)InitrdPathNode);\r
431 } else {\r
432 InitrdPath = NULL;\r
433 }\r
3e710183 434 }\r
22a262c8 435 } else {\r
436 InitrdSize = 0;\r
656416bc 437 }\r
438\r
2ccfb71e 439 Print(L"Arguments to pass to the binary: "); \r
440 if (CmdLineSize > 0) {\r
441 AsciiStrnCpy(CmdLine, (CONST CHAR8*)(LinuxArguments + 1), CmdLineSize);\r
656416bc 442 } else {\r
2ccfb71e 443 CmdLine[0] = '\0';\r
656416bc 444 }\r
2ccfb71e 445 Status = EditHIInputAscii (CmdLine, BOOT_DEVICE_OPTION_MAX);\r
656416bc 446 if (EFI_ERROR(Status)) {\r
447 Status = EFI_ABORTED;\r
448 goto FREE_DEVICE_PATH;\r
449 }\r
2ccfb71e 450\r
451 CmdLineSize = AsciiStrSize (CmdLine);\r
2ccfb71e 452\r
453 BootArguments = (ARM_BDS_LOADER_ARGUMENTS*)AllocatePool(sizeof(ARM_BDS_LOADER_ARGUMENTS) + CmdLineSize + InitrdSize);\r
454 BootArguments->LinuxArguments.CmdLineSize = CmdLineSize;\r
455 BootArguments->LinuxArguments.InitrdSize = InitrdSize;\r
456 CopyMem (&BootArguments->LinuxArguments + 1, CmdLine, CmdLineSize);\r
49a25d84 457 CopyMem ((VOID*)((UINTN)(&BootArguments->LinuxArguments + 1) + CmdLineSize), InitrdPath, InitrdSize);\r
2ccfb71e 458 } else {\r
459 BootArguments = NULL;\r
ea46ebbe 460 }\r
461\r
462 Print(L"Description for this new Entry: ");\r
3e710183 463 StrnCpy (BootDescription, BootOption->Description, BOOT_DEVICE_DESCRIPTION_MAX);\r
74b96132 464 Status = EditHIInputStr (BootDescription, BOOT_DEVICE_DESCRIPTION_MAX);\r
ea46ebbe 465 if (EFI_ERROR(Status)) {\r
466 Status = EFI_ABORTED;\r
467 goto FREE_DEVICE_PATH;\r
468 }\r
469\r
ea46ebbe 470 // Update the entry\r
2ccfb71e 471 Status = BootOptionUpdate (BootOption, BootOption->Attributes, BootDescription, DevicePath, BootType, BootArguments);\r
ea46ebbe 472\r
ea46ebbe 473FREE_DEVICE_PATH:\r
474 FreePool (DevicePath);\r
475\r
476EXIT:\r
326d1df9 477 if (Status == EFI_ABORTED) {\r
478 Print(L"\n");\r
479 }\r
ea46ebbe 480 return Status;\r
481}\r
482\r
95b3580f 483EFI_STATUS\r
484UpdateFdtPath (\r
485 IN LIST_ENTRY *BootOptionsList\r
486 )\r
487{\r
c0658bd6 488 EFI_STATUS Status;\r
489 UINTN FdtDevicePathSize;\r
490 BDS_SUPPORTED_DEVICE *SupportedBootDevice;\r
491 EFI_DEVICE_PATH_PROTOCOL *FdtDevicePathNode;\r
492 EFI_DEVICE_PATH_PROTOCOL *FdtDevicePath;\r
95b3580f 493\r
494 Status = SelectBootDevice (&SupportedBootDevice);\r
495 if (EFI_ERROR(Status)) {\r
496 Status = EFI_ABORTED;\r
497 goto EXIT;\r
498 }\r
499\r
500 // Create the specific device path node\r
c0658bd6 501 Status = SupportedBootDevice->Support->CreateDevicePathNode (L"FDT blob", &FdtDevicePathNode, NULL, NULL);\r
95b3580f 502 if (EFI_ERROR(Status)) {\r
503 Status = EFI_ABORTED;\r
504 goto EXIT;\r
505 }\r
506\r
507 if (FdtDevicePathNode != NULL) {\r
508 // Append the Device Path node to the select device path\r
509 FdtDevicePath = AppendDevicePathNode (SupportedBootDevice->DevicePathProtocol, FdtDevicePathNode);\r
c0658bd6 510 FdtDevicePathSize = GetDevicePathSize (FdtDevicePath);\r
511 Status = gRT->SetVariable ((CHAR16*)L"Fdt", &gEfiGlobalVariableGuid, (EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS ), FdtDevicePathSize, FdtDevicePath);\r
95b3580f 512 ASSERT_EFI_ERROR(Status);\r
513 } else {\r
c0658bd6 514 gRT->SetVariable ((CHAR16*)L"Fdt", &gEfiGlobalVariableGuid, (EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS ), 0, NULL);\r
95b3580f 515 ASSERT_EFI_ERROR(Status);\r
516 }\r
517\r
518EXIT:\r
519 if (Status == EFI_ABORTED) {\r
520 Print(L"\n");\r
521 }\r
522 FreePool(SupportedBootDevice);\r
523 return Status;\r
524}\r
525\r
ea46ebbe 526struct BOOT_MANAGER_ENTRY {\r
527 CONST CHAR16* Description;\r
528 EFI_STATUS (*Callback) (IN LIST_ENTRY *BootOptionsList);\r
529} BootManagerEntries[] = {\r
530 { L"Add Boot Device Entry", BootMenuAddBootOption },\r
531 { L"Update Boot Device Entry", BootMenuUpdateBootOption },\r
532 { L"Remove Boot Device Entry", BootMenuRemoveBootOption },\r
95b3580f 533 { L"Update FDT path", UpdateFdtPath },\r
ea46ebbe 534};\r
535\r
536EFI_STATUS\r
537BootMenuManager (\r
538 IN LIST_ENTRY *BootOptionsList\r
539 )\r
540{\r
541 UINTN Index;\r
542 UINTN OptionSelected;\r
543 UINTN BootManagerEntryCount;\r
544 EFI_STATUS Status;\r
545\r
546 BootManagerEntryCount = sizeof(BootManagerEntries) / sizeof(struct BOOT_MANAGER_ENTRY);\r
547\r
548 while (TRUE) {\r
549 // Display Boot Manager menu\r
550 for (Index = 0; Index < BootManagerEntryCount; Index++) {\r
551 Print(L"[%d] %s\n",Index+1,BootManagerEntries[Index]);\r
552 }\r
553 Print(L"[%d] Return to main menu\n",Index+1);\r
554\r
555 // Select which entry to call\r
556 Print(L"Choice: ");\r
557 Status = GetHIInputInteger (&OptionSelected);\r
558 if (EFI_ERROR(Status) || (OptionSelected == (BootManagerEntryCount+1))) {\r
326d1df9 559 if (EFI_ERROR(Status)) {\r
560 Print(L"\n");\r
561 }\r
ea46ebbe 562 return EFI_SUCCESS;\r
563 } else if ((OptionSelected > 0) && (OptionSelected <= BootManagerEntryCount)) {\r
ff7666c5 564 BootManagerEntries[OptionSelected-1].Callback (BootOptionsList);\r
ea46ebbe 565 }\r
566 }\r
11c20f4e 567 // Should never go here\r
ea46ebbe 568}\r
569\r
570EFI_STATUS\r
571BootEBL (\r
572 IN LIST_ENTRY *BootOptionsList\r
573 )\r
574{\r
575 EFI_STATUS Status;\r
576\r
577 // Start EFI Shell\r
2755d844 578 Status = BdsLoadApplication (mImageHandle, L"Ebl", 0, NULL);\r
ea46ebbe 579 if (Status == EFI_NOT_FOUND) {\r
580 Print (L"Error: EFI Application not found.\n");\r
581 } else if (EFI_ERROR(Status)) {\r
582 Print (L"Error: Status Code: 0x%X\n",(UINT32)Status);\r
583 }\r
584\r
585 return Status;\r
586}\r
587\r
588struct BOOT_MAIN_ENTRY {\r
589 CONST CHAR16* Description;\r
590 EFI_STATUS (*Callback) (IN LIST_ENTRY *BootOptionsList);\r
591} BootMainEntries[] = {\r
592 { L"EBL", BootEBL },\r
593 { L"Boot Manager", BootMenuManager },\r
594};\r
595\r
596\r
597EFI_STATUS\r
598BootMenuMain (\r
599 VOID\r
600 )\r
601{\r
2ccfb71e 602 LIST_ENTRY BootOptionsList;\r
603 UINTN OptionCount;\r
604 UINTN BootOptionCount;\r
605 EFI_STATUS Status;\r
606 LIST_ENTRY* Entry;\r
607 BDS_LOAD_OPTION* BootOption;\r
608 UINTN BootOptionSelected;\r
609 UINTN Index;\r
610 UINTN BootMainEntryCount;\r
ea46ebbe 611\r
e862cd50 612 BootOption = NULL;\r
ea46ebbe 613 BootMainEntryCount = sizeof(BootMainEntries) / sizeof(struct BOOT_MAIN_ENTRY);\r
a6caee65 614\r
ea46ebbe 615 while (TRUE) {\r
a6e97d28 616 // Get Boot#### list\r
617 BootOptionList (&BootOptionsList);\r
618\r
ea46ebbe 619 OptionCount = 1;\r
620\r
621 // Display the Boot options\r
622 for (Entry = GetFirstNode (&BootOptionsList);\r
623 !IsNull (&BootOptionsList,Entry);\r
624 Entry = GetNextNode (&BootOptionsList,Entry)\r
625 )\r
626 {\r
627 BootOption = LOAD_OPTION_FROM_LINK(Entry);\r
628\r
ff7666c5 629 Print(L"[%d] %s\n", OptionCount, BootOption->Description);\r
ea46ebbe 630\r
631 DEBUG_CODE_BEGIN();\r
632 CHAR16* DevicePathTxt;\r
633 EFI_DEVICE_PATH_TO_TEXT_PROTOCOL* DevicePathToTextProtocol;\r
2ccfb71e 634 ARM_BDS_LOADER_OPTIONAL_DATA* OptionalData;\r
635 UINTN CmdLineSize;\r
3e710183 636 ARM_BDS_LOADER_TYPE LoaderType;\r
ea46ebbe 637\r
ff7666c5 638 Status = gBS->LocateProtocol (&gEfiDevicePathToTextProtocolGuid, NULL, (VOID **)&DevicePathToTextProtocol);\r
aa95e2f7 639 if (EFI_ERROR(Status)) {\r
640 // You must provide an implementation of DevicePathToTextProtocol in your firmware (eg: DevicePathDxe)\r
641 DEBUG((EFI_D_ERROR,"Error: Bds requires DevicePathToTextProtocol\n"));\r
642 return Status;\r
643 }\r
ff7666c5 644 DevicePathTxt = DevicePathToTextProtocol->ConvertDevicePathToText (BootOption->FilePathList, TRUE, TRUE);\r
ea46ebbe 645\r
646 Print(L"\t- %s\n",DevicePathTxt);\r
2ccfb71e 647\r
648 // If it is a supported BootEntry then print its details\r
649 if (IS_ARM_BDS_BOOTENTRY (BootOption)) {\r
650 OptionalData = BootOption->OptionalData;\r
651 LoaderType = (ARM_BDS_LOADER_TYPE)ReadUnaligned32 ((CONST UINT32*)&OptionalData->Header.LoaderType);\r
652 if ((LoaderType == BDS_LOADER_KERNEL_LINUX_ATAG) || (LoaderType == BDS_LOADER_KERNEL_LINUX_FDT)) {\r
653 if (ReadUnaligned16 (&OptionalData->Arguments.LinuxArguments.InitrdSize) > 0) {\r
654 CmdLineSize = ReadUnaligned16 (&OptionalData->Arguments.LinuxArguments.CmdLineSize);\r
655 DevicePathTxt = DevicePathToTextProtocol->ConvertDevicePathToText (\r
656 GetAlignedDevicePath ((EFI_DEVICE_PATH*)((UINTN)(&OptionalData->Arguments.LinuxArguments + 1) + CmdLineSize)), TRUE, TRUE);\r
657 Print(L"\t- Initrd: %s\n", DevicePathTxt);\r
658 }\r
659 Print(L"\t- Arguments: %a\n", (&OptionalData->Arguments.LinuxArguments + 1));\r
ea46ebbe 660 }\r
2ccfb71e 661 Print(L"\t- LoaderType: %d\n", LoaderType);\r
ea46ebbe 662 }\r
ea46ebbe 663 FreePool(DevicePathTxt);\r
664 DEBUG_CODE_END();\r
665\r
666 OptionCount++;\r
667 }\r
668 BootOptionCount = OptionCount-1;\r
669\r
670 // Display the hardcoded Boot entries\r
671 for (Index = 0; Index < BootMainEntryCount; Index++) {\r
672 Print(L"[%d] %s\n",OptionCount,BootMainEntries[Index]);\r
673 OptionCount++;\r
674 }\r
675\r
676 // Request the boot entry from the user\r
677 BootOptionSelected = 0;\r
678 while (BootOptionSelected == 0) {\r
679 Print(L"Start: ");\r
680 Status = GetHIInputInteger (&BootOptionSelected);\r
681 if (EFI_ERROR(Status) || (BootOptionSelected == 0) || (BootOptionSelected > OptionCount)) {\r
682 Print(L"Invalid input (max %d)\n",(OptionCount-1));\r
683 BootOptionSelected = 0;\r
684 }\r
685 }\r
686\r
687 // Start the selected entry\r
688 if (BootOptionSelected > BootOptionCount) {\r
689 // Start the hardcoded entry\r
690 Status = BootMainEntries[BootOptionSelected - BootOptionCount - 1].Callback (&BootOptionsList);\r
691 } else {\r
692 // Find the selected entry from the Boot#### list\r
693 Index = 1;\r
694 for (Entry = GetFirstNode (&BootOptionsList);\r
695 !IsNull (&BootOptionsList,Entry);\r
696 Entry = GetNextNode (&BootOptionsList,Entry)\r
697 )\r
698 {\r
699 if (Index == BootOptionSelected) {\r
700 BootOption = LOAD_OPTION_FROM_LINK(Entry);\r
701 break;\r
702 }\r
703 Index++;\r
704 }\r
705\r
706 Status = BootOptionStart (BootOption);\r
707 }\r
708 }\r
11c20f4e 709 // Should never go here\r
ea46ebbe 710}\r