]> git.proxmox.com Git - mirror_edk2.git/blame - ArmPlatformPkg/Bds/BootMenu.c
ArmPkg/CompilerIntrinsicsLib: Add missing __aeabi_llsl and __aeabi_llsr for GCC
[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
14238a61 357 EFI_DEVICE_PATH *DevicePath;\r
358 EFI_DEVICE_PATH *TempInitrdPath;\r
2ccfb71e 359 ARM_BDS_LOADER_TYPE BootType;\r
360 ARM_BDS_LOADER_OPTIONAL_DATA* OptionalData;\r
361 ARM_BDS_LINUX_ARGUMENTS* LinuxArguments;\r
22a262c8 362 EFI_DEVICE_PATH *InitrdPathNode;\r
363 EFI_DEVICE_PATH *InitrdPath;\r
2ccfb71e 364 UINTN InitrdSize;\r
365 UINTN CmdLineSize;\r
22a262c8 366 BOOLEAN InitrdSupport;\r
ea46ebbe 367\r
11c20f4e 368 Status = BootMenuSelectBootOption (BootOptionsList, UPDATE_BOOT_ENTRY, TRUE, &BootOptionEntry);\r
ea46ebbe 369 if (EFI_ERROR(Status)) {\r
370 return Status;\r
371 }\r
a6e97d28 372 BootOption = BootOptionEntry->BdsLoadOption;\r
ea46ebbe 373\r
374 // Get the device support for this Boot Option\r
22a262c8 375 Status = BootDeviceGetDeviceSupport (BootOption->FilePathList, &DeviceSupport);\r
ea46ebbe 376 if (EFI_ERROR(Status)) {\r
ff7666c5 377 Print(L"Not possible to retrieve the supported device for the update\n");\r
ea46ebbe 378 return EFI_UNSUPPORTED;\r
379 }\r
380\r
22a262c8 381 Status = DeviceSupport->UpdateDevicePathNode (BootOption->FilePathList, L"EFI Application or the kernel", &DevicePath, NULL, NULL);\r
ea46ebbe 382 if (EFI_ERROR(Status)) {\r
383 Status = EFI_ABORTED;\r
384 goto EXIT;\r
385 }\r
386\r
2ccfb71e 387 OptionalData = BootOption->OptionalData;\r
388 BootType = (ARM_BDS_LOADER_TYPE)ReadUnaligned32 ((UINT32 *)(&OptionalData->Header.LoaderType));\r
656416bc 389\r
2ccfb71e 390 if ((BootType == BDS_LOADER_KERNEL_LINUX_ATAG) || (BootType == BDS_LOADER_KERNEL_LINUX_FDT)) {\r
391 LinuxArguments = &OptionalData->Arguments.LinuxArguments;\r
392\r
393 CmdLineSize = ReadUnaligned16 ((CONST UINT16*)&LinuxArguments->CmdLineSize);\r
2ccfb71e 394\r
3e710183 395 InitrdSize = ReadUnaligned16 ((CONST UINT16*)&LinuxArguments->InitrdSize);\r
396 if (InitrdSize > 0) {\r
22a262c8 397 Print(L"Keep the initrd: ");\r
398 } else {\r
399 Print(L"Add an initrd: ");\r
400 }\r
401 Status = GetHIInputBoolean (&InitrdSupport);\r
402 if (EFI_ERROR(Status)) {\r
403 Status = EFI_ABORTED;\r
404 goto EXIT;\r
405 }\r
406\r
407 if (InitrdSupport) {\r
408 if (InitrdSize > 0) {\r
409 // Case we update the initrd device path\r
49a25d84 410 Status = DeviceSupport->UpdateDevicePathNode ((EFI_DEVICE_PATH*)((UINTN)(LinuxArguments + 1) + CmdLineSize), L"initrd", &InitrdPath, NULL, NULL);\r
22a262c8 411 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
412 Status = EFI_ABORTED;\r
413 goto EXIT;\r
414 }\r
415 InitrdSize = GetDevicePathSize (InitrdPath);\r
416 } else {\r
417 // Case we create the initrd device path\r
418\r
419 Status = DeviceSupport->CreateDevicePathNode (L"initrd", &InitrdPathNode, NULL, NULL);\r
420 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
421 Status = EFI_ABORTED;\r
422 goto EXIT;\r
423 }\r
424\r
425 if (InitrdPathNode != NULL) {\r
426 // Duplicate Linux kernel Device Path\r
14238a61 427 TempInitrdPath = DuplicateDevicePath (BootOption->FilePathList);\r
22a262c8 428 // Replace Linux kernel Node by EndNode\r
14238a61 429 SetDevicePathEndNode (GetLastDevicePathNode (TempInitrdPath));\r
22a262c8 430 // Append the Device Path node to the select device path\r
14238a61 431 InitrdPath = AppendDevicePathNode (TempInitrdPath, (CONST EFI_DEVICE_PATH_PROTOCOL *)InitrdPathNode);\r
432 FreePool (TempInitrdPath);\r
433 InitrdSize = GetDevicePathSize (InitrdPath);\r
22a262c8 434 } else {\r
435 InitrdPath = NULL;\r
436 }\r
3e710183 437 }\r
22a262c8 438 } else {\r
439 InitrdSize = 0;\r
656416bc 440 }\r
441\r
2ccfb71e 442 Print(L"Arguments to pass to the binary: "); \r
443 if (CmdLineSize > 0) {\r
444 AsciiStrnCpy(CmdLine, (CONST CHAR8*)(LinuxArguments + 1), CmdLineSize);\r
656416bc 445 } else {\r
2ccfb71e 446 CmdLine[0] = '\0';\r
656416bc 447 }\r
2ccfb71e 448 Status = EditHIInputAscii (CmdLine, BOOT_DEVICE_OPTION_MAX);\r
656416bc 449 if (EFI_ERROR(Status)) {\r
450 Status = EFI_ABORTED;\r
451 goto FREE_DEVICE_PATH;\r
452 }\r
2ccfb71e 453\r
454 CmdLineSize = AsciiStrSize (CmdLine);\r
2ccfb71e 455\r
456 BootArguments = (ARM_BDS_LOADER_ARGUMENTS*)AllocatePool(sizeof(ARM_BDS_LOADER_ARGUMENTS) + CmdLineSize + InitrdSize);\r
457 BootArguments->LinuxArguments.CmdLineSize = CmdLineSize;\r
458 BootArguments->LinuxArguments.InitrdSize = InitrdSize;\r
459 CopyMem (&BootArguments->LinuxArguments + 1, CmdLine, CmdLineSize);\r
49a25d84 460 CopyMem ((VOID*)((UINTN)(&BootArguments->LinuxArguments + 1) + CmdLineSize), InitrdPath, InitrdSize);\r
2ccfb71e 461 } else {\r
462 BootArguments = NULL;\r
ea46ebbe 463 }\r
464\r
465 Print(L"Description for this new Entry: ");\r
3e710183 466 StrnCpy (BootDescription, BootOption->Description, BOOT_DEVICE_DESCRIPTION_MAX);\r
74b96132 467 Status = EditHIInputStr (BootDescription, BOOT_DEVICE_DESCRIPTION_MAX);\r
ea46ebbe 468 if (EFI_ERROR(Status)) {\r
469 Status = EFI_ABORTED;\r
470 goto FREE_DEVICE_PATH;\r
471 }\r
472\r
ea46ebbe 473 // Update the entry\r
2ccfb71e 474 Status = BootOptionUpdate (BootOption, BootOption->Attributes, BootDescription, DevicePath, BootType, BootArguments);\r
ea46ebbe 475\r
ea46ebbe 476FREE_DEVICE_PATH:\r
477 FreePool (DevicePath);\r
478\r
479EXIT:\r
326d1df9 480 if (Status == EFI_ABORTED) {\r
481 Print(L"\n");\r
482 }\r
ea46ebbe 483 return Status;\r
484}\r
485\r
95b3580f 486EFI_STATUS\r
487UpdateFdtPath (\r
488 IN LIST_ENTRY *BootOptionsList\r
489 )\r
490{\r
c0658bd6 491 EFI_STATUS Status;\r
492 UINTN FdtDevicePathSize;\r
493 BDS_SUPPORTED_DEVICE *SupportedBootDevice;\r
494 EFI_DEVICE_PATH_PROTOCOL *FdtDevicePathNode;\r
495 EFI_DEVICE_PATH_PROTOCOL *FdtDevicePath;\r
95b3580f 496\r
497 Status = SelectBootDevice (&SupportedBootDevice);\r
498 if (EFI_ERROR(Status)) {\r
499 Status = EFI_ABORTED;\r
500 goto EXIT;\r
501 }\r
502\r
503 // Create the specific device path node\r
c0658bd6 504 Status = SupportedBootDevice->Support->CreateDevicePathNode (L"FDT blob", &FdtDevicePathNode, NULL, NULL);\r
95b3580f 505 if (EFI_ERROR(Status)) {\r
506 Status = EFI_ABORTED;\r
507 goto EXIT;\r
508 }\r
509\r
510 if (FdtDevicePathNode != NULL) {\r
511 // Append the Device Path node to the select device path\r
512 FdtDevicePath = AppendDevicePathNode (SupportedBootDevice->DevicePathProtocol, FdtDevicePathNode);\r
c0658bd6 513 FdtDevicePathSize = GetDevicePathSize (FdtDevicePath);\r
514 Status = gRT->SetVariable ((CHAR16*)L"Fdt", &gEfiGlobalVariableGuid, (EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS ), FdtDevicePathSize, FdtDevicePath);\r
95b3580f 515 ASSERT_EFI_ERROR(Status);\r
516 } else {\r
c0658bd6 517 gRT->SetVariable ((CHAR16*)L"Fdt", &gEfiGlobalVariableGuid, (EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS ), 0, NULL);\r
95b3580f 518 ASSERT_EFI_ERROR(Status);\r
519 }\r
520\r
521EXIT:\r
522 if (Status == EFI_ABORTED) {\r
523 Print(L"\n");\r
524 }\r
525 FreePool(SupportedBootDevice);\r
526 return Status;\r
527}\r
528\r
ea46ebbe 529struct BOOT_MANAGER_ENTRY {\r
530 CONST CHAR16* Description;\r
531 EFI_STATUS (*Callback) (IN LIST_ENTRY *BootOptionsList);\r
532} BootManagerEntries[] = {\r
533 { L"Add Boot Device Entry", BootMenuAddBootOption },\r
534 { L"Update Boot Device Entry", BootMenuUpdateBootOption },\r
535 { L"Remove Boot Device Entry", BootMenuRemoveBootOption },\r
95b3580f 536 { L"Update FDT path", UpdateFdtPath },\r
ea46ebbe 537};\r
538\r
539EFI_STATUS\r
540BootMenuManager (\r
541 IN LIST_ENTRY *BootOptionsList\r
542 )\r
543{\r
544 UINTN Index;\r
545 UINTN OptionSelected;\r
546 UINTN BootManagerEntryCount;\r
547 EFI_STATUS Status;\r
548\r
549 BootManagerEntryCount = sizeof(BootManagerEntries) / sizeof(struct BOOT_MANAGER_ENTRY);\r
550\r
551 while (TRUE) {\r
552 // Display Boot Manager menu\r
553 for (Index = 0; Index < BootManagerEntryCount; Index++) {\r
554 Print(L"[%d] %s\n",Index+1,BootManagerEntries[Index]);\r
555 }\r
556 Print(L"[%d] Return to main menu\n",Index+1);\r
557\r
558 // Select which entry to call\r
559 Print(L"Choice: ");\r
560 Status = GetHIInputInteger (&OptionSelected);\r
561 if (EFI_ERROR(Status) || (OptionSelected == (BootManagerEntryCount+1))) {\r
326d1df9 562 if (EFI_ERROR(Status)) {\r
563 Print(L"\n");\r
564 }\r
ea46ebbe 565 return EFI_SUCCESS;\r
566 } else if ((OptionSelected > 0) && (OptionSelected <= BootManagerEntryCount)) {\r
ff7666c5 567 BootManagerEntries[OptionSelected-1].Callback (BootOptionsList);\r
ea46ebbe 568 }\r
569 }\r
11c20f4e 570 // Should never go here\r
ea46ebbe 571}\r
572\r
573EFI_STATUS\r
8213627e 574BootShell (\r
ea46ebbe 575 IN LIST_ENTRY *BootOptionsList\r
576 )\r
577{\r
578 EFI_STATUS Status;\r
579\r
580 // Start EFI Shell\r
8213627e 581 Status = BdsLoadApplication (mImageHandle, L"Shell", 0, NULL);\r
ea46ebbe 582 if (Status == EFI_NOT_FOUND) {\r
583 Print (L"Error: EFI Application not found.\n");\r
584 } else if (EFI_ERROR(Status)) {\r
585 Print (L"Error: Status Code: 0x%X\n",(UINT32)Status);\r
586 }\r
587\r
588 return Status;\r
589}\r
590\r
591struct BOOT_MAIN_ENTRY {\r
592 CONST CHAR16* Description;\r
593 EFI_STATUS (*Callback) (IN LIST_ENTRY *BootOptionsList);\r
594} BootMainEntries[] = {\r
8213627e 595 { L"Shell", BootShell },\r
ea46ebbe 596 { L"Boot Manager", BootMenuManager },\r
597};\r
598\r
599\r
600EFI_STATUS\r
601BootMenuMain (\r
602 VOID\r
603 )\r
604{\r
2ccfb71e 605 LIST_ENTRY BootOptionsList;\r
606 UINTN OptionCount;\r
607 UINTN BootOptionCount;\r
608 EFI_STATUS Status;\r
609 LIST_ENTRY* Entry;\r
610 BDS_LOAD_OPTION* BootOption;\r
611 UINTN BootOptionSelected;\r
612 UINTN Index;\r
613 UINTN BootMainEntryCount;\r
ea46ebbe 614\r
e862cd50 615 BootOption = NULL;\r
ea46ebbe 616 BootMainEntryCount = sizeof(BootMainEntries) / sizeof(struct BOOT_MAIN_ENTRY);\r
a6caee65 617\r
ea46ebbe 618 while (TRUE) {\r
a6e97d28 619 // Get Boot#### list\r
620 BootOptionList (&BootOptionsList);\r
621\r
ea46ebbe 622 OptionCount = 1;\r
623\r
624 // Display the Boot options\r
625 for (Entry = GetFirstNode (&BootOptionsList);\r
626 !IsNull (&BootOptionsList,Entry);\r
627 Entry = GetNextNode (&BootOptionsList,Entry)\r
628 )\r
629 {\r
630 BootOption = LOAD_OPTION_FROM_LINK(Entry);\r
631\r
ff7666c5 632 Print(L"[%d] %s\n", OptionCount, BootOption->Description);\r
ea46ebbe 633\r
634 DEBUG_CODE_BEGIN();\r
635 CHAR16* DevicePathTxt;\r
636 EFI_DEVICE_PATH_TO_TEXT_PROTOCOL* DevicePathToTextProtocol;\r
2ccfb71e 637 ARM_BDS_LOADER_OPTIONAL_DATA* OptionalData;\r
638 UINTN CmdLineSize;\r
3e710183 639 ARM_BDS_LOADER_TYPE LoaderType;\r
ea46ebbe 640\r
ff7666c5 641 Status = gBS->LocateProtocol (&gEfiDevicePathToTextProtocolGuid, NULL, (VOID **)&DevicePathToTextProtocol);\r
aa95e2f7 642 if (EFI_ERROR(Status)) {\r
643 // You must provide an implementation of DevicePathToTextProtocol in your firmware (eg: DevicePathDxe)\r
644 DEBUG((EFI_D_ERROR,"Error: Bds requires DevicePathToTextProtocol\n"));\r
645 return Status;\r
646 }\r
ff7666c5 647 DevicePathTxt = DevicePathToTextProtocol->ConvertDevicePathToText (BootOption->FilePathList, TRUE, TRUE);\r
ea46ebbe 648\r
649 Print(L"\t- %s\n",DevicePathTxt);\r
2ccfb71e 650\r
651 // If it is a supported BootEntry then print its details\r
652 if (IS_ARM_BDS_BOOTENTRY (BootOption)) {\r
653 OptionalData = BootOption->OptionalData;\r
654 LoaderType = (ARM_BDS_LOADER_TYPE)ReadUnaligned32 ((CONST UINT32*)&OptionalData->Header.LoaderType);\r
655 if ((LoaderType == BDS_LOADER_KERNEL_LINUX_ATAG) || (LoaderType == BDS_LOADER_KERNEL_LINUX_FDT)) {\r
656 if (ReadUnaligned16 (&OptionalData->Arguments.LinuxArguments.InitrdSize) > 0) {\r
657 CmdLineSize = ReadUnaligned16 (&OptionalData->Arguments.LinuxArguments.CmdLineSize);\r
658 DevicePathTxt = DevicePathToTextProtocol->ConvertDevicePathToText (\r
659 GetAlignedDevicePath ((EFI_DEVICE_PATH*)((UINTN)(&OptionalData->Arguments.LinuxArguments + 1) + CmdLineSize)), TRUE, TRUE);\r
660 Print(L"\t- Initrd: %s\n", DevicePathTxt);\r
661 }\r
662 Print(L"\t- Arguments: %a\n", (&OptionalData->Arguments.LinuxArguments + 1));\r
ea46ebbe 663 }\r
2ccfb71e 664 Print(L"\t- LoaderType: %d\n", LoaderType);\r
ea46ebbe 665 }\r
ea46ebbe 666 FreePool(DevicePathTxt);\r
667 DEBUG_CODE_END();\r
668\r
669 OptionCount++;\r
670 }\r
671 BootOptionCount = OptionCount-1;\r
672\r
673 // Display the hardcoded Boot entries\r
674 for (Index = 0; Index < BootMainEntryCount; Index++) {\r
675 Print(L"[%d] %s\n",OptionCount,BootMainEntries[Index]);\r
676 OptionCount++;\r
677 }\r
678\r
679 // Request the boot entry from the user\r
680 BootOptionSelected = 0;\r
681 while (BootOptionSelected == 0) {\r
682 Print(L"Start: ");\r
683 Status = GetHIInputInteger (&BootOptionSelected);\r
684 if (EFI_ERROR(Status) || (BootOptionSelected == 0) || (BootOptionSelected > OptionCount)) {\r
685 Print(L"Invalid input (max %d)\n",(OptionCount-1));\r
686 BootOptionSelected = 0;\r
687 }\r
688 }\r
689\r
690 // Start the selected entry\r
691 if (BootOptionSelected > BootOptionCount) {\r
692 // Start the hardcoded entry\r
693 Status = BootMainEntries[BootOptionSelected - BootOptionCount - 1].Callback (&BootOptionsList);\r
694 } else {\r
695 // Find the selected entry from the Boot#### list\r
696 Index = 1;\r
697 for (Entry = GetFirstNode (&BootOptionsList);\r
698 !IsNull (&BootOptionsList,Entry);\r
699 Entry = GetNextNode (&BootOptionsList,Entry)\r
700 )\r
701 {\r
702 if (Index == BootOptionSelected) {\r
703 BootOption = LOAD_OPTION_FROM_LINK(Entry);\r
704 break;\r
705 }\r
706 Index++;\r
707 }\r
708\r
709 Status = BootOptionStart (BootOption);\r
710 }\r
711 }\r
11c20f4e 712 // Should never go here\r
ea46ebbe 713}\r