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