]> git.proxmox.com Git - mirror_edk2.git/blame_incremental - ArmPlatformPkg/Bds/BootMenu.c
ArmPkg/ArmGic: Returned the InterruptId in ArmGicAcknowledgeInterrupt()
[mirror_edk2.git] / ArmPlatformPkg / Bds / BootMenu.c
... / ...
CommitLineData
1/** @file\r
2*\r
3* Copyright (c) 2011 - 2014, 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
17#include <Guid/ArmGlobalVariableHob.h>\r
18\r
19extern EFI_HANDLE mImageHandle;\r
20extern BDS_LOAD_OPTION_SUPPORT *BdsLoadOptionSupportList;\r
21\r
22\r
23EFI_STATUS\r
24SelectBootDevice (\r
25 OUT BDS_SUPPORTED_DEVICE** SupportedBootDevice\r
26 )\r
27{\r
28 EFI_STATUS Status;\r
29 LIST_ENTRY SupportedDeviceList;\r
30 UINTN SupportedDeviceCount;\r
31 LIST_ENTRY* Entry;\r
32 UINTN SupportedDeviceSelected;\r
33 UINTN Index;\r
34\r
35 //\r
36 // List the Boot Devices supported\r
37 //\r
38\r
39 // Start all the drivers first\r
40 BdsConnectAllDrivers ();\r
41\r
42 // List the supported devices\r
43 Status = BootDeviceListSupportedInit (&SupportedDeviceList);\r
44 ASSERT_EFI_ERROR(Status);\r
45\r
46 SupportedDeviceCount = 0;\r
47 for (Entry = GetFirstNode (&SupportedDeviceList);\r
48 !IsNull (&SupportedDeviceList,Entry);\r
49 Entry = GetNextNode (&SupportedDeviceList,Entry)\r
50 )\r
51 {\r
52 *SupportedBootDevice = SUPPORTED_BOOT_DEVICE_FROM_LINK(Entry);\r
53 Print(L"[%d] %s\n",SupportedDeviceCount+1,(*SupportedBootDevice)->Description);\r
54\r
55 DEBUG_CODE_BEGIN();\r
56 CHAR16* DevicePathTxt;\r
57 EFI_DEVICE_PATH_TO_TEXT_PROTOCOL* DevicePathToTextProtocol;\r
58\r
59 Status = gBS->LocateProtocol (&gEfiDevicePathToTextProtocolGuid, NULL, (VOID **)&DevicePathToTextProtocol);\r
60 ASSERT_EFI_ERROR(Status);\r
61 DevicePathTxt = DevicePathToTextProtocol->ConvertDevicePathToText ((*SupportedBootDevice)->DevicePathProtocol,TRUE,TRUE);\r
62\r
63 Print(L"\t- %s\n",DevicePathTxt);\r
64\r
65 FreePool(DevicePathTxt);\r
66 DEBUG_CODE_END();\r
67\r
68 SupportedDeviceCount++;\r
69 }\r
70\r
71 if (SupportedDeviceCount == 0) {\r
72 Print(L"There is no supported device.\n");\r
73 Status = EFI_ABORTED;\r
74 goto EXIT;\r
75 }\r
76\r
77 //\r
78 // Select the Boot Device\r
79 //\r
80 SupportedDeviceSelected = 0;\r
81 while (SupportedDeviceSelected == 0) {\r
82 Print(L"Select the Boot Device: ");\r
83 Status = GetHIInputInteger (&SupportedDeviceSelected);\r
84 if (EFI_ERROR(Status)) {\r
85 Status = EFI_ABORTED;\r
86 goto EXIT;\r
87 } else if ((SupportedDeviceSelected == 0) || (SupportedDeviceSelected > SupportedDeviceCount)) {\r
88 Print(L"Invalid input (max %d)\n",SupportedDeviceCount);\r
89 SupportedDeviceSelected = 0;\r
90 }\r
91 }\r
92\r
93 //\r
94 // Get the Device Path for the selected boot device\r
95 //\r
96 Index = 1;\r
97 for (Entry = GetFirstNode (&SupportedDeviceList);\r
98 !IsNull (&SupportedDeviceList,Entry);\r
99 Entry = GetNextNode (&SupportedDeviceList,Entry)\r
100 )\r
101 {\r
102 if (Index == SupportedDeviceSelected) {\r
103 *SupportedBootDevice = SUPPORTED_BOOT_DEVICE_FROM_LINK(Entry);\r
104 break;\r
105 }\r
106 Index++;\r
107 }\r
108\r
109EXIT:\r
110 BootDeviceListSupportedFree (&SupportedDeviceList, *SupportedBootDevice);\r
111 return Status;\r
112}\r
113\r
114EFI_STATUS\r
115BootMenuAddBootOption (\r
116 IN LIST_ENTRY *BootOptionsList\r
117 )\r
118{\r
119 EFI_STATUS Status;\r
120 BDS_SUPPORTED_DEVICE* SupportedBootDevice;\r
121 ARM_BDS_LOADER_ARGUMENTS* BootArguments;\r
122 CHAR16 BootDescription[BOOT_DEVICE_DESCRIPTION_MAX];\r
123 CHAR8 AsciiCmdLine[BOOT_DEVICE_OPTION_MAX];\r
124 CHAR16 CmdLine[BOOT_DEVICE_OPTION_MAX];\r
125 UINT32 Attributes;\r
126 ARM_BDS_LOADER_TYPE BootType;\r
127 BDS_LOAD_OPTION_ENTRY *BdsLoadOptionEntry;\r
128 EFI_DEVICE_PATH *DevicePath;\r
129 EFI_DEVICE_PATH_PROTOCOL *DevicePathNodes;\r
130 EFI_DEVICE_PATH_PROTOCOL *InitrdPathNodes;\r
131 EFI_DEVICE_PATH_PROTOCOL *InitrdPath;\r
132 UINTN CmdLineSize;\r
133 BOOLEAN InitrdSupport;\r
134 UINTN InitrdSize;\r
135 UINT8* OptionalData;\r
136 UINTN OptionalDataSize;\r
137 BOOLEAN RequestBootType;\r
138\r
139 Attributes = 0;\r
140 SupportedBootDevice = NULL;\r
141\r
142 // List the Boot Devices supported\r
143 Status = SelectBootDevice (&SupportedBootDevice);\r
144 if (EFI_ERROR(Status)) {\r
145 Status = EFI_ABORTED;\r
146 goto EXIT;\r
147 }\r
148\r
149 // Create the specific device path node\r
150 RequestBootType = TRUE;\r
151 Status = SupportedBootDevice->Support->CreateDevicePathNode (L"EFI Application or the kernel", &DevicePathNodes, &RequestBootType);\r
152 if (EFI_ERROR(Status)) {\r
153 Status = EFI_ABORTED;\r
154 goto EXIT;\r
155 }\r
156 // Append the Device Path to the selected device path\r
157 DevicePath = AppendDevicePath (SupportedBootDevice->DevicePathProtocol, (CONST EFI_DEVICE_PATH_PROTOCOL *)DevicePathNodes);\r
158 if (DevicePath == NULL) {\r
159 Status = EFI_OUT_OF_RESOURCES;\r
160 goto EXIT;\r
161 }\r
162\r
163 if (RequestBootType) {\r
164 Status = BootDeviceGetType (DevicePath, &BootType, &Attributes);\r
165 if (EFI_ERROR(Status)) {\r
166 Status = EFI_ABORTED;\r
167 goto EXIT;\r
168 }\r
169 } else {\r
170 BootType = BDS_LOADER_EFI_APPLICATION;\r
171 }\r
172\r
173 if ((BootType == BDS_LOADER_KERNEL_LINUX_ATAG) || (BootType == BDS_LOADER_KERNEL_LINUX_FDT)) {\r
174 Print(L"Add an initrd: ");\r
175 Status = GetHIInputBoolean (&InitrdSupport);\r
176 if (EFI_ERROR(Status)) {\r
177 Status = EFI_ABORTED;\r
178 goto EXIT;\r
179 }\r
180\r
181 if (InitrdSupport) {\r
182 // Create the specific device path node\r
183 Status = SupportedBootDevice->Support->CreateDevicePathNode (L"initrd", &InitrdPathNodes, NULL);\r
184 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
185 Status = EFI_ABORTED;\r
186 goto EXIT;\r
187 }\r
188\r
189 if (InitrdPathNodes != NULL) {\r
190 // Append the Device Path to the selected device path\r
191 InitrdPath = AppendDevicePath (SupportedBootDevice->DevicePathProtocol, (CONST EFI_DEVICE_PATH_PROTOCOL *)InitrdPathNodes);\r
192 if (InitrdPath == NULL) {\r
193 Status = EFI_OUT_OF_RESOURCES;\r
194 goto EXIT;\r
195 }\r
196 } else {\r
197 InitrdPath = NULL;\r
198 }\r
199 } else {\r
200 InitrdPath = NULL;\r
201 }\r
202\r
203 Print(L"Arguments to pass to the binary: ");\r
204 Status = GetHIInputAscii (AsciiCmdLine, BOOT_DEVICE_OPTION_MAX);\r
205 if (EFI_ERROR(Status)) {\r
206 Status = EFI_ABORTED;\r
207 goto FREE_DEVICE_PATH;\r
208 }\r
209\r
210 CmdLineSize = AsciiStrSize (AsciiCmdLine);\r
211 InitrdSize = GetDevicePathSize (InitrdPath);\r
212\r
213 OptionalDataSize = sizeof(ARM_BDS_LOADER_ARGUMENTS) + CmdLineSize + InitrdSize;\r
214 BootArguments = (ARM_BDS_LOADER_ARGUMENTS*)AllocatePool (OptionalDataSize);\r
215\r
216 BootArguments->LinuxArguments.CmdLineSize = CmdLineSize;\r
217 BootArguments->LinuxArguments.InitrdSize = InitrdSize;\r
218 CopyMem ((VOID*)(&BootArguments->LinuxArguments + 1), AsciiCmdLine, CmdLineSize);\r
219 CopyMem ((VOID*)((UINTN)(&BootArguments->LinuxArguments + 1) + CmdLineSize), InitrdPath, InitrdSize);\r
220\r
221 OptionalData = (UINT8*)BootArguments;\r
222 } else {\r
223 Print (L"Arguments to pass to the EFI Application: ");\r
224 Status = GetHIInputStr (CmdLine, BOOT_DEVICE_OPTION_MAX);\r
225 if (EFI_ERROR (Status)) {\r
226 Status = EFI_ABORTED;\r
227 goto EXIT;\r
228 }\r
229\r
230 OptionalData = (UINT8*)CmdLine;\r
231 OptionalDataSize = StrSize (CmdLine);\r
232 }\r
233\r
234 Print(L"Description for this new Entry: ");\r
235 Status = GetHIInputStr (BootDescription, BOOT_DEVICE_DESCRIPTION_MAX);\r
236 if (EFI_ERROR(Status)) {\r
237 Status = EFI_ABORTED;\r
238 goto FREE_DEVICE_PATH;\r
239 }\r
240\r
241 // Create new entry\r
242 BdsLoadOptionEntry = (BDS_LOAD_OPTION_ENTRY*)AllocatePool (sizeof(BDS_LOAD_OPTION_ENTRY));\r
243 Status = BootOptionCreate (Attributes, BootDescription, DevicePath, BootType, OptionalData, OptionalDataSize, &BdsLoadOptionEntry->BdsLoadOption);\r
244 if (!EFI_ERROR(Status)) {\r
245 InsertTailList (BootOptionsList, &BdsLoadOptionEntry->Link);\r
246 }\r
247\r
248FREE_DEVICE_PATH:\r
249 FreePool (DevicePath);\r
250\r
251EXIT:\r
252 if (Status == EFI_ABORTED) {\r
253 Print(L"\n");\r
254 }\r
255 FreePool(SupportedBootDevice);\r
256 return Status;\r
257}\r
258\r
259STATIC\r
260EFI_STATUS\r
261BootMenuSelectBootOption (\r
262 IN LIST_ENTRY* BootOptionsList,\r
263 IN CONST CHAR16* InputStatement,\r
264 OUT BDS_LOAD_OPTION_ENTRY** BdsLoadOptionEntry\r
265 )\r
266{\r
267 EFI_STATUS Status;\r
268 LIST_ENTRY* Entry;\r
269 BDS_LOAD_OPTION* BdsLoadOption;\r
270 UINTN BootOptionSelected;\r
271 UINTN BootOptionCount;\r
272 UINTN Index;\r
273 BOOLEAN IsUnicode;\r
274\r
275 // Display the list of supported boot devices\r
276 BootOptionCount = 0;\r
277 for (Entry = GetFirstNode (BootOptionsList);\r
278 !IsNull (BootOptionsList,Entry);\r
279 Entry = GetNextNode (BootOptionsList, Entry)\r
280 )\r
281 {\r
282 BdsLoadOption = LOAD_OPTION_FROM_LINK(Entry);\r
283\r
284 Print (L"[%d] %s\n", (BootOptionCount + 1), BdsLoadOption->Description);\r
285\r
286 DEBUG_CODE_BEGIN();\r
287 CHAR16* DevicePathTxt;\r
288 EFI_DEVICE_PATH_TO_TEXT_PROTOCOL* DevicePathToTextProtocol;\r
289 ARM_BDS_LOADER_TYPE LoaderType;\r
290 ARM_BDS_LOADER_OPTIONAL_DATA* OptionalData;\r
291\r
292 Status = gBS->LocateProtocol(&gEfiDevicePathToTextProtocolGuid, NULL, (VOID **)&DevicePathToTextProtocol);\r
293 ASSERT_EFI_ERROR(Status);\r
294 DevicePathTxt = DevicePathToTextProtocol->ConvertDevicePathToText(BdsLoadOption->FilePathList,TRUE,TRUE);\r
295\r
296 Print(L"\t- %s\n",DevicePathTxt);\r
297 OptionalData = BdsLoadOption->OptionalData;\r
298 if (IS_ARM_BDS_BOOTENTRY (BdsLoadOption)) {\r
299 LoaderType = (ARM_BDS_LOADER_TYPE)ReadUnaligned32 ((CONST UINT32*)&OptionalData->Header.LoaderType);\r
300 if ((LoaderType == BDS_LOADER_KERNEL_LINUX_ATAG) || (LoaderType == BDS_LOADER_KERNEL_LINUX_FDT)) {\r
301 Print (L"\t- Arguments: %a\n",&OptionalData->Arguments.LinuxArguments + 1);\r
302 }\r
303 } else if (OptionalData != NULL) {\r
304 if (IsPrintableString (OptionalData, &IsUnicode)) {\r
305 if (IsUnicode) {\r
306 Print (L"\t- Arguments: %s\n", OptionalData);\r
307 } else {\r
308 AsciiPrint ("\t- Arguments: %a\n", OptionalData);\r
309 }\r
310 }\r
311 }\r
312\r
313 FreePool(DevicePathTxt);\r
314 DEBUG_CODE_END();\r
315\r
316 BootOptionCount++;\r
317 }\r
318\r
319 // Check if a valid boot option(s) is found\r
320 if (BootOptionCount == 0) {\r
321 if (StrCmp (InputStatement, DELETE_BOOT_ENTRY) == 0) {\r
322 Print (L"Nothing to remove!\n");\r
323 } else if (StrCmp (InputStatement, UPDATE_BOOT_ENTRY) == 0) {\r
324 Print (L"Couldn't find valid boot entries\n");\r
325 } else{\r
326 Print (L"No supported Boot Entry.\n");\r
327 }\r
328\r
329 return EFI_NOT_FOUND;\r
330 }\r
331\r
332 // Get the index of the boot device to delete\r
333 BootOptionSelected = 0;\r
334 while (BootOptionSelected == 0) {\r
335 Print(InputStatement);\r
336 Status = GetHIInputInteger (&BootOptionSelected);\r
337 if (EFI_ERROR(Status)) {\r
338 return Status;\r
339 } else if ((BootOptionSelected == 0) || (BootOptionSelected > BootOptionCount)) {\r
340 Print(L"Invalid input (max %d)\n",BootOptionCount);\r
341 BootOptionSelected = 0;\r
342 }\r
343 }\r
344\r
345 // Get the structure of the Boot device to delete\r
346 Index = 1;\r
347 for (Entry = GetFirstNode (BootOptionsList);\r
348 !IsNull (BootOptionsList, Entry);\r
349 Entry = GetNextNode (BootOptionsList,Entry)\r
350 )\r
351 {\r
352 if (Index == BootOptionSelected) {\r
353 *BdsLoadOptionEntry = LOAD_OPTION_ENTRY_FROM_LINK(Entry);\r
354 break;\r
355 }\r
356 Index++;\r
357 }\r
358\r
359 return EFI_SUCCESS;\r
360}\r
361\r
362EFI_STATUS\r
363BootMenuRemoveBootOption (\r
364 IN LIST_ENTRY *BootOptionsList\r
365 )\r
366{\r
367 EFI_STATUS Status;\r
368 BDS_LOAD_OPTION_ENTRY* BootOptionEntry;\r
369\r
370 Status = BootMenuSelectBootOption (BootOptionsList, DELETE_BOOT_ENTRY, &BootOptionEntry);\r
371 if (EFI_ERROR(Status)) {\r
372 return Status;\r
373 }\r
374\r
375 // If the Boot Option was attached to a list remove it\r
376 if (!IsListEmpty (&BootOptionEntry->Link)) {\r
377 // Remove the entry from the list\r
378 RemoveEntryList (&BootOptionEntry->Link);\r
379 }\r
380\r
381 // Delete the BDS Load option structures\r
382 BootOptionDelete (BootOptionEntry->BdsLoadOption);\r
383\r
384 return EFI_SUCCESS;\r
385}\r
386\r
387EFI_STATUS\r
388BootMenuUpdateBootOption (\r
389 IN LIST_ENTRY *BootOptionsList\r
390 )\r
391{\r
392 EFI_STATUS Status;\r
393 BDS_LOAD_OPTION_ENTRY *BootOptionEntry;\r
394 BDS_LOAD_OPTION *BootOption;\r
395 BDS_LOAD_OPTION_SUPPORT* DeviceSupport;\r
396 ARM_BDS_LOADER_ARGUMENTS* BootArguments;\r
397 CHAR16 BootDescription[BOOT_DEVICE_DESCRIPTION_MAX];\r
398 CHAR8 CmdLine[BOOT_DEVICE_OPTION_MAX];\r
399 CHAR16 UnicodeCmdLine[BOOT_DEVICE_OPTION_MAX];\r
400 EFI_DEVICE_PATH *DevicePath;\r
401 EFI_DEVICE_PATH *TempInitrdPath;\r
402 ARM_BDS_LOADER_TYPE BootType;\r
403 ARM_BDS_LOADER_OPTIONAL_DATA* LoaderOptionalData;\r
404 ARM_BDS_LINUX_ARGUMENTS* LinuxArguments;\r
405 EFI_DEVICE_PATH *InitrdPathNodes;\r
406 EFI_DEVICE_PATH *InitrdPath;\r
407 UINTN InitrdSize;\r
408 UINTN CmdLineSize;\r
409 BOOLEAN InitrdSupport;\r
410 UINT8* OptionalData;\r
411 UINTN OptionalDataSize;\r
412 BOOLEAN RequestBootType;\r
413 BOOLEAN IsPrintable;\r
414 BOOLEAN IsUnicode;\r
415\r
416 Status = BootMenuSelectBootOption (BootOptionsList, UPDATE_BOOT_ENTRY, &BootOptionEntry);\r
417 if (EFI_ERROR(Status)) {\r
418 return Status;\r
419 }\r
420 BootOption = BootOptionEntry->BdsLoadOption;\r
421\r
422 // Get the device support for this Boot Option\r
423 Status = BootDeviceGetDeviceSupport (BootOption->FilePathList, &DeviceSupport);\r
424 if (EFI_ERROR(Status)) {\r
425 Print(L"Not possible to retrieve the supported device for the update\n");\r
426 return EFI_UNSUPPORTED;\r
427 }\r
428\r
429 RequestBootType = TRUE;\r
430 Status = DeviceSupport->UpdateDevicePathNode (BootOption->FilePathList, L"EFI Application or the kernel", &DevicePath, &RequestBootType);\r
431 if (EFI_ERROR(Status)) {\r
432 Status = EFI_ABORTED;\r
433 goto EXIT;\r
434 }\r
435\r
436 if (RequestBootType) {\r
437 Status = BootDeviceGetType (DevicePath, &BootType, &BootOption->Attributes);\r
438 if (EFI_ERROR(Status)) {\r
439 Status = EFI_ABORTED;\r
440 goto EXIT;\r
441 }\r
442 }\r
443\r
444 LoaderOptionalData = BootOption->OptionalData;\r
445 if (LoaderOptionalData != NULL) {\r
446 BootType = (ARM_BDS_LOADER_TYPE)ReadUnaligned32 ((UINT32 *)(&LoaderOptionalData->Header.LoaderType));\r
447 } else {\r
448 BootType = BDS_LOADER_EFI_APPLICATION;\r
449 }\r
450\r
451 if ((BootType == BDS_LOADER_KERNEL_LINUX_ATAG) || (BootType == BDS_LOADER_KERNEL_LINUX_FDT)) {\r
452 LinuxArguments = &LoaderOptionalData->Arguments.LinuxArguments;\r
453\r
454 CmdLineSize = ReadUnaligned16 ((CONST UINT16*)&LinuxArguments->CmdLineSize);\r
455\r
456 InitrdSize = ReadUnaligned16 ((CONST UINT16*)&LinuxArguments->InitrdSize);\r
457 if (InitrdSize > 0) {\r
458 Print(L"Keep the initrd: ");\r
459 } else {\r
460 Print(L"Add an initrd: ");\r
461 }\r
462 Status = GetHIInputBoolean (&InitrdSupport);\r
463 if (EFI_ERROR(Status)) {\r
464 Status = EFI_ABORTED;\r
465 goto EXIT;\r
466 }\r
467\r
468 if (InitrdSupport) {\r
469 if (InitrdSize > 0) {\r
470 // Case we update the initrd device path\r
471 Status = DeviceSupport->UpdateDevicePathNode ((EFI_DEVICE_PATH*)((UINTN)(LinuxArguments + 1) + CmdLineSize), L"initrd", &InitrdPath, NULL);\r
472 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
473 Status = EFI_ABORTED;\r
474 goto EXIT;\r
475 }\r
476 InitrdSize = GetDevicePathSize (InitrdPath);\r
477 } else {\r
478 // Case we create the initrd device path\r
479\r
480 Status = DeviceSupport->CreateDevicePathNode (L"initrd", &InitrdPathNodes, NULL);\r
481 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
482 Status = EFI_ABORTED;\r
483 goto EXIT;\r
484 }\r
485\r
486 if (InitrdPathNodes != NULL) {\r
487 // Duplicate Linux kernel Device Path\r
488 TempInitrdPath = DuplicateDevicePath (BootOption->FilePathList);\r
489 // Replace Linux kernel Node by EndNode\r
490 SetDevicePathEndNode (GetLastDevicePathNode (TempInitrdPath));\r
491 // Append the Device Path to the selected device path\r
492 InitrdPath = AppendDevicePath (TempInitrdPath, (CONST EFI_DEVICE_PATH_PROTOCOL *)InitrdPathNodes);\r
493 FreePool (TempInitrdPath);\r
494 if (InitrdPath == NULL) {\r
495 Status = EFI_OUT_OF_RESOURCES;\r
496 goto EXIT;\r
497 }\r
498 InitrdSize = GetDevicePathSize (InitrdPath);\r
499 } else {\r
500 InitrdPath = NULL;\r
501 }\r
502 }\r
503 } else {\r
504 InitrdSize = 0;\r
505 }\r
506\r
507 Print(L"Arguments to pass to the binary: ");\r
508 if (CmdLineSize > 0) {\r
509 AsciiStrnCpy(CmdLine, (CONST CHAR8*)(LinuxArguments + 1), CmdLineSize);\r
510 } else {\r
511 CmdLine[0] = '\0';\r
512 }\r
513 Status = EditHIInputAscii (CmdLine, BOOT_DEVICE_OPTION_MAX);\r
514 if (EFI_ERROR(Status)) {\r
515 Status = EFI_ABORTED;\r
516 goto FREE_DEVICE_PATH;\r
517 }\r
518\r
519 CmdLineSize = AsciiStrSize (CmdLine);\r
520\r
521 OptionalDataSize = sizeof(ARM_BDS_LOADER_ARGUMENTS) + CmdLineSize + InitrdSize;\r
522 BootArguments = (ARM_BDS_LOADER_ARGUMENTS*)AllocatePool (OptionalDataSize);\r
523 BootArguments->LinuxArguments.CmdLineSize = CmdLineSize;\r
524 BootArguments->LinuxArguments.InitrdSize = InitrdSize;\r
525 CopyMem (&BootArguments->LinuxArguments + 1, CmdLine, CmdLineSize);\r
526 CopyMem ((VOID*)((UINTN)(&BootArguments->LinuxArguments + 1) + CmdLineSize), InitrdPath, InitrdSize);\r
527\r
528 OptionalData = (UINT8*)BootArguments;\r
529 } else {\r
530 Print (L"Arguments to pass to the EFI Application: ");\r
531\r
532 if (BootOption->OptionalDataSize > 0) {\r
533 IsPrintable = IsPrintableString (BootOption->OptionalData, &IsUnicode);\r
534 if (IsPrintable) {\r
535 if (IsUnicode) {\r
536 StrnCpy (UnicodeCmdLine, BootOption->OptionalData, BootOption->OptionalDataSize / 2);\r
537 } else {\r
538 AsciiStrnCpy (CmdLine, BootOption->OptionalData, BootOption->OptionalDataSize);\r
539 }\r
540 }\r
541 } else {\r
542 UnicodeCmdLine[0] = L'\0';\r
543 IsPrintable = TRUE;\r
544 IsUnicode = TRUE;\r
545 }\r
546\r
547 // We do not request arguments for OptionalData that cannot be printed\r
548 if (IsPrintable) {\r
549 if (IsUnicode) {\r
550 Status = EditHIInputStr (UnicodeCmdLine, BOOT_DEVICE_OPTION_MAX);\r
551 if (EFI_ERROR (Status)) {\r
552 Status = EFI_ABORTED;\r
553 goto FREE_DEVICE_PATH;\r
554 }\r
555\r
556 OptionalData = (UINT8*)UnicodeCmdLine;\r
557 OptionalDataSize = StrSize (UnicodeCmdLine);\r
558 } else {\r
559 Status = EditHIInputAscii (CmdLine, BOOT_DEVICE_OPTION_MAX);\r
560 if (EFI_ERROR (Status)) {\r
561 Status = EFI_ABORTED;\r
562 goto FREE_DEVICE_PATH;\r
563 }\r
564\r
565 OptionalData = (UINT8*)CmdLine;\r
566 OptionalDataSize = AsciiStrSize (CmdLine);\r
567 }\r
568 } else {\r
569 // We keep the former OptionalData\r
570 OptionalData = BootOption->OptionalData;\r
571 OptionalDataSize = BootOption->OptionalDataSize;\r
572 }\r
573 }\r
574\r
575 Print(L"Description for this new Entry: ");\r
576 StrnCpy (BootDescription, BootOption->Description, BOOT_DEVICE_DESCRIPTION_MAX);\r
577 Status = EditHIInputStr (BootDescription, BOOT_DEVICE_DESCRIPTION_MAX);\r
578 if (EFI_ERROR(Status)) {\r
579 Status = EFI_ABORTED;\r
580 goto FREE_DEVICE_PATH;\r
581 }\r
582\r
583 // Update the entry\r
584 Status = BootOptionUpdate (BootOption, BootOption->Attributes, BootDescription, DevicePath, BootType, OptionalData, OptionalDataSize);\r
585\r
586FREE_DEVICE_PATH:\r
587 FreePool (DevicePath);\r
588\r
589EXIT:\r
590 if (Status == EFI_ABORTED) {\r
591 Print(L"\n");\r
592 }\r
593 return Status;\r
594}\r
595\r
596EFI_STATUS\r
597UpdateFdtPath (\r
598 IN LIST_ENTRY *BootOptionsList\r
599 )\r
600{\r
601 EFI_STATUS Status;\r
602 UINTN FdtDevicePathSize;\r
603 BDS_SUPPORTED_DEVICE *SupportedBootDevice;\r
604 EFI_DEVICE_PATH_PROTOCOL *FdtDevicePathNodes;\r
605 EFI_DEVICE_PATH_PROTOCOL *FdtDevicePath;\r
606\r
607 Status = SelectBootDevice (&SupportedBootDevice);\r
608 if (EFI_ERROR(Status)) {\r
609 Status = EFI_ABORTED;\r
610 goto EXIT;\r
611 }\r
612\r
613 // Create the specific device path node\r
614 Status = SupportedBootDevice->Support->CreateDevicePathNode (L"FDT blob", &FdtDevicePathNodes, NULL);\r
615 if (EFI_ERROR(Status)) {\r
616 Status = EFI_ABORTED;\r
617 goto EXIT;\r
618 }\r
619\r
620 if (FdtDevicePathNodes != NULL) {\r
621 // Append the Device Path node to the select device path\r
622 FdtDevicePath = AppendDevicePath (SupportedBootDevice->DevicePathProtocol, FdtDevicePathNodes);\r
623 FdtDevicePathSize = GetDevicePathSize (FdtDevicePath);\r
624 Status = gRT->SetVariable (\r
625 (CHAR16*)L"Fdt",\r
626 &gArmGlobalVariableGuid,\r
627 EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS,\r
628 FdtDevicePathSize,\r
629 FdtDevicePath\r
630 );\r
631 ASSERT_EFI_ERROR(Status);\r
632 } else {\r
633 gRT->SetVariable (\r
634 (CHAR16*)L"Fdt",\r
635 &gArmGlobalVariableGuid,\r
636 EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS,\r
637 0,\r
638 NULL\r
639 );\r
640 ASSERT_EFI_ERROR(Status);\r
641 }\r
642\r
643EXIT:\r
644 if (Status == EFI_ABORTED) {\r
645 Print(L"\n");\r
646 }\r
647 FreePool(SupportedBootDevice);\r
648 return Status;\r
649}\r
650\r
651struct BOOT_MANAGER_ENTRY {\r
652 CONST CHAR16* Description;\r
653 EFI_STATUS (*Callback) (IN LIST_ENTRY *BootOptionsList);\r
654} BootManagerEntries[] = {\r
655 { L"Add Boot Device Entry", BootMenuAddBootOption },\r
656 { L"Update Boot Device Entry", BootMenuUpdateBootOption },\r
657 { L"Remove Boot Device Entry", BootMenuRemoveBootOption },\r
658 { L"Update FDT path", UpdateFdtPath },\r
659};\r
660\r
661EFI_STATUS\r
662BootMenuManager (\r
663 IN LIST_ENTRY *BootOptionsList\r
664 )\r
665{\r
666 UINTN Index;\r
667 UINTN OptionSelected;\r
668 UINTN BootManagerEntryCount;\r
669 EFI_STATUS Status;\r
670\r
671 BootManagerEntryCount = sizeof(BootManagerEntries) / sizeof(struct BOOT_MANAGER_ENTRY);\r
672\r
673 while (TRUE) {\r
674 // Display Boot Manager menu\r
675 for (Index = 0; Index < BootManagerEntryCount; Index++) {\r
676 Print(L"[%d] %s\n",Index+1,BootManagerEntries[Index]);\r
677 }\r
678 Print(L"[%d] Return to main menu\n",Index+1);\r
679\r
680 // Select which entry to call\r
681 Print(L"Choice: ");\r
682 Status = GetHIInputInteger (&OptionSelected);\r
683 if (EFI_ERROR(Status) || (OptionSelected == (BootManagerEntryCount+1))) {\r
684 if (EFI_ERROR(Status)) {\r
685 Print(L"\n");\r
686 }\r
687 return EFI_SUCCESS;\r
688 } else if ((OptionSelected > 0) && (OptionSelected <= BootManagerEntryCount)) {\r
689 BootManagerEntries[OptionSelected-1].Callback (BootOptionsList);\r
690 }\r
691 }\r
692 // Should never go here\r
693}\r
694\r
695EFI_STATUS\r
696BootShell (\r
697 IN LIST_ENTRY *BootOptionsList\r
698 )\r
699{\r
700 EFI_STATUS Status;\r
701\r
702 // Start EFI Shell\r
703 Status = BdsLoadApplication (mImageHandle, L"Shell", 0, NULL);\r
704 if (Status == EFI_NOT_FOUND) {\r
705 Print (L"Error: EFI Application not found.\n");\r
706 } else if (EFI_ERROR(Status)) {\r
707 Print (L"Error: Status Code: 0x%X\n",(UINT32)Status);\r
708 }\r
709\r
710 return Status;\r
711}\r
712\r
713struct BOOT_MAIN_ENTRY {\r
714 CONST CHAR16* Description;\r
715 EFI_STATUS (*Callback) (IN LIST_ENTRY *BootOptionsList);\r
716} BootMainEntries[] = {\r
717 { L"Shell", BootShell },\r
718 { L"Boot Manager", BootMenuManager },\r
719};\r
720\r
721\r
722EFI_STATUS\r
723BootMenuMain (\r
724 VOID\r
725 )\r
726{\r
727 LIST_ENTRY BootOptionsList;\r
728 UINTN OptionCount;\r
729 UINTN BootOptionCount;\r
730 EFI_STATUS Status;\r
731 LIST_ENTRY* Entry;\r
732 BDS_LOAD_OPTION* BootOption;\r
733 UINTN BootOptionSelected;\r
734 UINTN Index;\r
735 UINTN BootMainEntryCount;\r
736 BOOLEAN IsUnicode;\r
737\r
738 BootOption = NULL;\r
739 BootMainEntryCount = sizeof(BootMainEntries) / sizeof(struct BOOT_MAIN_ENTRY);\r
740\r
741 while (TRUE) {\r
742 // Get Boot#### list\r
743 BootOptionList (&BootOptionsList);\r
744\r
745 OptionCount = 1;\r
746\r
747 // Display the Boot options\r
748 for (Entry = GetFirstNode (&BootOptionsList);\r
749 !IsNull (&BootOptionsList,Entry);\r
750 Entry = GetNextNode (&BootOptionsList,Entry)\r
751 )\r
752 {\r
753 BootOption = LOAD_OPTION_FROM_LINK(Entry);\r
754\r
755 Print(L"[%d] %s\n", OptionCount, BootOption->Description);\r
756\r
757 DEBUG_CODE_BEGIN();\r
758 CHAR16* DevicePathTxt;\r
759 EFI_DEVICE_PATH_TO_TEXT_PROTOCOL* DevicePathToTextProtocol;\r
760 ARM_BDS_LOADER_OPTIONAL_DATA* OptionalData;\r
761 UINTN CmdLineSize;\r
762 ARM_BDS_LOADER_TYPE LoaderType;\r
763\r
764 Status = gBS->LocateProtocol (&gEfiDevicePathToTextProtocolGuid, NULL, (VOID **)&DevicePathToTextProtocol);\r
765 if (EFI_ERROR(Status)) {\r
766 // You must provide an implementation of DevicePathToTextProtocol in your firmware (eg: DevicePathDxe)\r
767 DEBUG((EFI_D_ERROR,"Error: Bds requires DevicePathToTextProtocol\n"));\r
768 return Status;\r
769 }\r
770 DevicePathTxt = DevicePathToTextProtocol->ConvertDevicePathToText (BootOption->FilePathList, TRUE, TRUE);\r
771\r
772 Print(L"\t- %s\n",DevicePathTxt);\r
773\r
774 // If it is a supported BootEntry then print its details\r
775 if (IS_ARM_BDS_BOOTENTRY (BootOption)) {\r
776 OptionalData = BootOption->OptionalData;\r
777 LoaderType = (ARM_BDS_LOADER_TYPE)ReadUnaligned32 ((CONST UINT32*)&OptionalData->Header.LoaderType);\r
778 if ((LoaderType == BDS_LOADER_KERNEL_LINUX_ATAG) || (LoaderType == BDS_LOADER_KERNEL_LINUX_FDT)) {\r
779 if (ReadUnaligned16 (&OptionalData->Arguments.LinuxArguments.InitrdSize) > 0) {\r
780 CmdLineSize = ReadUnaligned16 (&OptionalData->Arguments.LinuxArguments.CmdLineSize);\r
781 DevicePathTxt = DevicePathToTextProtocol->ConvertDevicePathToText (\r
782 GetAlignedDevicePath ((EFI_DEVICE_PATH*)((UINTN)(&OptionalData->Arguments.LinuxArguments + 1) + CmdLineSize)), TRUE, TRUE);\r
783 Print(L"\t- Initrd: %s\n", DevicePathTxt);\r
784 }\r
785 if (ReadUnaligned16 (&OptionalData->Arguments.LinuxArguments.CmdLineSize) > 0) {\r
786 Print(L"\t- Arguments: %a\n", (&OptionalData->Arguments.LinuxArguments + 1));\r
787 }\r
788 }\r
789\r
790 switch (LoaderType) {\r
791 case BDS_LOADER_EFI_APPLICATION:\r
792 Print(L"\t- LoaderType: EFI Application\n");\r
793 break;\r
794\r
795 case BDS_LOADER_KERNEL_LINUX_ATAG:\r
796 Print(L"\t- LoaderType: Linux kernel with ATAG support\n");\r
797 break;\r
798\r
799 case BDS_LOADER_KERNEL_LINUX_FDT:\r
800 Print(L"\t- LoaderType: Linux kernel with FDT support\n");\r
801 break;\r
802\r
803 default:\r
804 Print(L"\t- LoaderType: Not recognized (%d)\n", LoaderType);\r
805 }\r
806 } else if (BootOption->OptionalData != NULL) {\r
807 if (IsPrintableString (BootOption->OptionalData, &IsUnicode)) {\r
808 if (IsUnicode) {\r
809 Print (L"\t- Arguments: %s\n", BootOption->OptionalData);\r
810 } else {\r
811 AsciiPrint ("\t- Arguments: %a\n", BootOption->OptionalData);\r
812 }\r
813 }\r
814 }\r
815 FreePool(DevicePathTxt);\r
816 DEBUG_CODE_END();\r
817\r
818 OptionCount++;\r
819 }\r
820 BootOptionCount = OptionCount-1;\r
821\r
822 // Display the hardcoded Boot entries\r
823 for (Index = 0; Index < BootMainEntryCount; Index++) {\r
824 Print(L"[%d] %s\n",OptionCount,BootMainEntries[Index]);\r
825 OptionCount++;\r
826 }\r
827\r
828 // Request the boot entry from the user\r
829 BootOptionSelected = 0;\r
830 while (BootOptionSelected == 0) {\r
831 Print(L"Start: ");\r
832 Status = GetHIInputInteger (&BootOptionSelected);\r
833 if (EFI_ERROR(Status) || (BootOptionSelected == 0) || (BootOptionSelected > OptionCount)) {\r
834 Print(L"Invalid input (max %d)\n",(OptionCount-1));\r
835 BootOptionSelected = 0;\r
836 }\r
837 }\r
838\r
839 // Start the selected entry\r
840 if (BootOptionSelected > BootOptionCount) {\r
841 // Start the hardcoded entry\r
842 Status = BootMainEntries[BootOptionSelected - BootOptionCount - 1].Callback (&BootOptionsList);\r
843 } else {\r
844 // Find the selected entry from the Boot#### list\r
845 Index = 1;\r
846 for (Entry = GetFirstNode (&BootOptionsList);\r
847 !IsNull (&BootOptionsList,Entry);\r
848 Entry = GetNextNode (&BootOptionsList,Entry)\r
849 )\r
850 {\r
851 if (Index == BootOptionSelected) {\r
852 BootOption = LOAD_OPTION_FROM_LINK(Entry);\r
853 break;\r
854 }\r
855 Index++;\r
856 }\r
857\r
858 Status = BootOptionStart (BootOption);\r
859 }\r
860 }\r
861 // Should never go here\r
862}\r