]>
Commit | Line | Data |
---|---|---|
ea46ebbe | 1 | /** @file\r |
2 | *\r | |
3b3b72d6 | 3 | * Copyright (c) 2011 - 2014, 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 | 19 | extern BDS_LOAD_OPTION_SUPPORT *BdsLoadOptionSupportList;\r |
20 | \r | |
019680b3 RC |
21 | /**\r |
22 | Worker function that displays the list of boot options that is passed in.\r | |
23 | \r | |
24 | The function loops over the entries of the list of boot options that is passed\r | |
25 | in. For each entry, the boot option description is displayed on a single line\r | |
26 | along with the position of the option in the list. In debug mode, the UEFI\r | |
27 | device path and the arguments of the boot option are displayed as well in\r | |
28 | subsequent lines.\r | |
29 | \r | |
30 | @param[in] BootOptionsList List of the boot options\r | |
31 | \r | |
32 | **/\r | |
33 | STATIC\r | |
34 | VOID\r | |
35 | DisplayBootOptions (\r | |
36 | IN LIST_ENTRY* BootOptionsList\r | |
37 | )\r | |
38 | {\r | |
39 | EFI_STATUS Status;\r | |
40 | UINTN BootOptionCount;\r | |
41 | LIST_ENTRY *Entry;\r | |
42 | BDS_LOAD_OPTION *BdsLoadOption;\r | |
43 | BOOLEAN IsUnicode;\r | |
44 | \r | |
45 | BootOptionCount = 0 ;\r | |
46 | for (Entry = GetFirstNode (BootOptionsList);\r | |
47 | !IsNull (BootOptionsList, Entry);\r | |
48 | Entry = GetNextNode (BootOptionsList, Entry)\r | |
49 | ) {\r | |
50 | \r | |
51 | BdsLoadOption = LOAD_OPTION_FROM_LINK (Entry);\r | |
52 | Print (L"[%d] %s\n", ++BootOptionCount, BdsLoadOption->Description);\r | |
53 | \r | |
54 | DEBUG_CODE_BEGIN ();\r | |
55 | CHAR16* DevicePathTxt;\r | |
56 | EFI_DEVICE_PATH_TO_TEXT_PROTOCOL* DevicePathToTextProtocol;\r | |
57 | ARM_BDS_LOADER_TYPE LoaderType;\r | |
58 | ARM_BDS_LOADER_OPTIONAL_DATA* OptionalData;\r | |
59 | \r | |
60 | Status = gBS->LocateProtocol (\r | |
61 | &gEfiDevicePathToTextProtocolGuid,\r | |
62 | NULL,\r | |
63 | (VOID **)&DevicePathToTextProtocol\r | |
64 | );\r | |
65 | ASSERT_EFI_ERROR (Status);\r | |
66 | DevicePathTxt = DevicePathToTextProtocol->ConvertDevicePathToText (\r | |
67 | BdsLoadOption->FilePathList,\r | |
68 | TRUE,\r | |
69 | TRUE\r | |
70 | );\r | |
71 | Print (L"\t- %s\n", DevicePathTxt);\r | |
72 | \r | |
73 | OptionalData = BdsLoadOption->OptionalData;\r | |
74 | if (IS_ARM_BDS_BOOTENTRY (BdsLoadOption)) {\r | |
75 | LoaderType = (ARM_BDS_LOADER_TYPE)ReadUnaligned32 ((CONST UINT32*)&OptionalData->Header.LoaderType);\r | |
76 | if ((LoaderType == BDS_LOADER_KERNEL_LINUX_ATAG) ||\r | |
77 | (LoaderType == BDS_LOADER_KERNEL_LINUX_FDT ) ) {\r | |
78 | Print (L"\t- Arguments: %a\n", &OptionalData->Arguments.LinuxArguments + 1);\r | |
79 | }\r | |
80 | } else if (OptionalData != NULL) {\r | |
81 | if (IsPrintableString (OptionalData, &IsUnicode)) {\r | |
82 | if (IsUnicode) {\r | |
83 | Print (L"\t- Arguments: %s\n", OptionalData);\r | |
84 | } else {\r | |
85 | AsciiPrint ("\t- Arguments: %a\n", OptionalData);\r | |
86 | }\r | |
87 | }\r | |
88 | }\r | |
89 | \r | |
90 | FreePool (DevicePathTxt);\r | |
91 | DEBUG_CODE_END ();\r | |
92 | }\r | |
93 | }\r | |
94 | \r | |
95 | /**\r | |
96 | Worker function that asks for a boot option to be selected and returns a\r | |
97 | pointer to the structure describing the selected boot option.\r | |
98 | \r | |
99 | @param[in] BootOptionsList List of the boot options\r | |
100 | \r | |
101 | @retval EFI_SUCCESS Selection succeeded\r | |
102 | @retval !EFI_SUCCESS Input error or input cancelled\r | |
103 | \r | |
104 | **/\r | |
105 | STATIC\r | |
106 | EFI_STATUS\r | |
107 | SelectBootOption (\r | |
108 | IN LIST_ENTRY* BootOptionsList,\r | |
109 | IN CONST CHAR16* InputStatement,\r | |
110 | OUT BDS_LOAD_OPTION_ENTRY** BdsLoadOptionEntry\r | |
111 | )\r | |
112 | {\r | |
113 | EFI_STATUS Status;\r | |
114 | UINTN BootOptionCount;\r | |
115 | UINT16 *BootOrder;\r | |
116 | LIST_ENTRY* Entry;\r | |
117 | UINTN BootOptionSelected;\r | |
118 | UINTN Index;\r | |
119 | \r | |
120 | // Get the number of boot options\r | |
121 | Status = GetGlobalEnvironmentVariable (\r | |
122 | L"BootOrder", NULL, &BootOptionCount, (VOID**)&BootOrder\r | |
123 | );\r | |
124 | if (EFI_ERROR (Status)) {\r | |
125 | goto ErrorExit;\r | |
126 | }\r | |
127 | FreePool (BootOrder);\r | |
128 | BootOptionCount /= sizeof (UINT16);\r | |
129 | \r | |
130 | // Check if a valid boot option(s) is found\r | |
131 | if (BootOptionCount == 0) {\r | |
132 | if (StrCmp (InputStatement, DELETE_BOOT_ENTRY) == 0) {\r | |
133 | Print (L"Nothing to remove!\n");\r | |
134 | } else if (StrCmp (InputStatement, UPDATE_BOOT_ENTRY) == 0) {\r | |
135 | Print (L"Nothing to update!\n");\r | |
136 | } else if (StrCmp (InputStatement, MOVE_BOOT_ENTRY) == 0) {\r | |
137 | Print (L"Nothing to move!\n");\r | |
138 | } else {\r | |
139 | Print (L"No supported Boot Entry.\n");\r | |
140 | }\r | |
141 | return EFI_NOT_FOUND;\r | |
142 | }\r | |
143 | \r | |
144 | // Get the index of the boot device to delete\r | |
145 | BootOptionSelected = 0;\r | |
146 | while (BootOptionSelected == 0) {\r | |
147 | Print (InputStatement);\r | |
148 | Status = GetHIInputInteger (&BootOptionSelected);\r | |
149 | if (EFI_ERROR (Status)) {\r | |
150 | Print (L"\n");\r | |
151 | goto ErrorExit;\r | |
152 | } else if ((BootOptionSelected == 0) || (BootOptionSelected > BootOptionCount)) {\r | |
153 | Print (L"Invalid input (max %d)\n", BootOptionCount);\r | |
154 | BootOptionSelected = 0;\r | |
155 | }\r | |
156 | }\r | |
157 | \r | |
158 | // Get the structure of the Boot device to delete\r | |
159 | Index = 1;\r | |
160 | for (Entry = GetFirstNode (BootOptionsList);\r | |
161 | !IsNull (BootOptionsList, Entry);\r | |
162 | Entry = GetNextNode (BootOptionsList,Entry)\r | |
163 | )\r | |
164 | {\r | |
165 | if (Index == BootOptionSelected) {\r | |
166 | *BdsLoadOptionEntry = LOAD_OPTION_ENTRY_FROM_LINK (Entry);\r | |
167 | break;\r | |
168 | }\r | |
169 | Index++;\r | |
170 | }\r | |
aeaf64d6 | 171 | \r |
019680b3 RC |
172 | ErrorExit:\r |
173 | return Status;\r | |
174 | }\r | |
175 | \r | |
176 | STATIC\r | |
ea46ebbe | 177 | EFI_STATUS\r |
656416bc | 178 | SelectBootDevice (\r |
179 | OUT BDS_SUPPORTED_DEVICE** SupportedBootDevice\r | |
ea46ebbe | 180 | )\r |
181 | {\r | |
656416bc | 182 | EFI_STATUS Status;\r |
ea46ebbe | 183 | LIST_ENTRY SupportedDeviceList;\r |
184 | UINTN SupportedDeviceCount;\r | |
ea46ebbe | 185 | LIST_ENTRY* Entry;\r |
186 | UINTN SupportedDeviceSelected;\r | |
ea46ebbe | 187 | UINTN Index;\r |
ea46ebbe | 188 | \r |
189 | //\r | |
190 | // List the Boot Devices supported\r | |
191 | //\r | |
192 | \r | |
193 | // Start all the drivers first\r | |
194 | BdsConnectAllDrivers ();\r | |
195 | \r | |
196 | // List the supported devices\r | |
197 | Status = BootDeviceListSupportedInit (&SupportedDeviceList);\r | |
198 | ASSERT_EFI_ERROR(Status);\r | |
199 | \r | |
200 | SupportedDeviceCount = 0;\r | |
201 | for (Entry = GetFirstNode (&SupportedDeviceList);\r | |
202 | !IsNull (&SupportedDeviceList,Entry);\r | |
203 | Entry = GetNextNode (&SupportedDeviceList,Entry)\r | |
204 | )\r | |
205 | {\r | |
656416bc | 206 | *SupportedBootDevice = SUPPORTED_BOOT_DEVICE_FROM_LINK(Entry);\r |
207 | Print(L"[%d] %s\n",SupportedDeviceCount+1,(*SupportedBootDevice)->Description);\r | |
ea46ebbe | 208 | \r |
209 | DEBUG_CODE_BEGIN();\r | |
210 | CHAR16* DevicePathTxt;\r | |
211 | EFI_DEVICE_PATH_TO_TEXT_PROTOCOL* DevicePathToTextProtocol;\r | |
212 | \r | |
ff7666c5 | 213 | Status = gBS->LocateProtocol (&gEfiDevicePathToTextProtocolGuid, NULL, (VOID **)&DevicePathToTextProtocol);\r |
ea46ebbe | 214 | ASSERT_EFI_ERROR(Status);\r |
ff7666c5 | 215 | DevicePathTxt = DevicePathToTextProtocol->ConvertDevicePathToText ((*SupportedBootDevice)->DevicePathProtocol,TRUE,TRUE);\r |
ea46ebbe | 216 | \r |
217 | Print(L"\t- %s\n",DevicePathTxt);\r | |
218 | \r | |
219 | FreePool(DevicePathTxt);\r | |
220 | DEBUG_CODE_END();\r | |
221 | \r | |
222 | SupportedDeviceCount++;\r | |
223 | }\r | |
224 | \r | |
225 | if (SupportedDeviceCount == 0) {\r | |
226 | Print(L"There is no supported device.\n");\r | |
227 | Status = EFI_ABORTED;\r | |
228 | goto EXIT;\r | |
229 | }\r | |
230 | \r | |
231 | //\r | |
232 | // Select the Boot Device\r | |
233 | //\r | |
234 | SupportedDeviceSelected = 0;\r | |
235 | while (SupportedDeviceSelected == 0) {\r | |
236 | Print(L"Select the Boot Device: ");\r | |
237 | Status = GetHIInputInteger (&SupportedDeviceSelected);\r | |
238 | if (EFI_ERROR(Status)) {\r | |
239 | Status = EFI_ABORTED;\r | |
240 | goto EXIT;\r | |
241 | } else if ((SupportedDeviceSelected == 0) || (SupportedDeviceSelected > SupportedDeviceCount)) {\r | |
ff7666c5 | 242 | Print(L"Invalid input (max %d)\n",SupportedDeviceCount);\r |
ea46ebbe | 243 | SupportedDeviceSelected = 0;\r |
244 | }\r | |
245 | }\r | |
246 | \r | |
247 | //\r | |
248 | // Get the Device Path for the selected boot device\r | |
249 | //\r | |
250 | Index = 1;\r | |
251 | for (Entry = GetFirstNode (&SupportedDeviceList);\r | |
252 | !IsNull (&SupportedDeviceList,Entry);\r | |
253 | Entry = GetNextNode (&SupportedDeviceList,Entry)\r | |
254 | )\r | |
255 | {\r | |
256 | if (Index == SupportedDeviceSelected) {\r | |
656416bc | 257 | *SupportedBootDevice = SUPPORTED_BOOT_DEVICE_FROM_LINK(Entry);\r |
ea46ebbe | 258 | break;\r |
259 | }\r | |
260 | Index++;\r | |
261 | }\r | |
aeaf64d6 | 262 | \r |
656416bc | 263 | EXIT:\r |
264 | BootDeviceListSupportedFree (&SupportedDeviceList, *SupportedBootDevice);\r | |
265 | return Status;\r | |
266 | }\r | |
267 | \r | |
268 | EFI_STATUS\r | |
269 | BootMenuAddBootOption (\r | |
270 | IN LIST_ENTRY *BootOptionsList\r | |
271 | )\r | |
272 | {\r | |
2ccfb71e | 273 | EFI_STATUS Status;\r |
274 | BDS_SUPPORTED_DEVICE* SupportedBootDevice;\r | |
275 | ARM_BDS_LOADER_ARGUMENTS* BootArguments;\r | |
74b96132 | 276 | CHAR16 BootDescription[BOOT_DEVICE_DESCRIPTION_MAX];\r |
06044819 OM |
277 | CHAR8 AsciiCmdLine[BOOT_DEVICE_OPTION_MAX];\r |
278 | CHAR16 CmdLine[BOOT_DEVICE_OPTION_MAX];\r | |
2ccfb71e | 279 | UINT32 Attributes;\r |
280 | ARM_BDS_LOADER_TYPE BootType;\r | |
a6e97d28 | 281 | BDS_LOAD_OPTION_ENTRY *BdsLoadOptionEntry;\r |
2ccfb71e | 282 | EFI_DEVICE_PATH *DevicePath;\r |
ecc62d13 | 283 | EFI_DEVICE_PATH_PROTOCOL *DevicePathNodes;\r |
284 | EFI_DEVICE_PATH_PROTOCOL *InitrdPathNodes;\r | |
2ccfb71e | 285 | EFI_DEVICE_PATH_PROTOCOL *InitrdPath;\r |
286 | UINTN CmdLineSize;\r | |
22a262c8 | 287 | BOOLEAN InitrdSupport;\r |
2ccfb71e | 288 | UINTN InitrdSize;\r |
90a44ec4 OM |
289 | UINT8* OptionalData;\r |
290 | UINTN OptionalDataSize;\r | |
656416bc | 291 | \r |
292 | Attributes = 0;\r | |
293 | SupportedBootDevice = NULL;\r | |
294 | \r | |
295 | // List the Boot Devices supported\r | |
2ccfb71e | 296 | Status = SelectBootDevice (&SupportedBootDevice);\r |
656416bc | 297 | if (EFI_ERROR(Status)) {\r |
298 | Status = EFI_ABORTED;\r | |
299 | goto EXIT;\r | |
300 | }\r | |
ea46ebbe | 301 | \r |
302 | // Create the specific device path node\r | |
889ac6a8 | 303 | Status = SupportedBootDevice->Support->CreateDevicePathNode (L"EFI Application or the kernel", &DevicePathNodes);\r |
ea46ebbe | 304 | if (EFI_ERROR(Status)) {\r |
305 | Status = EFI_ABORTED;\r | |
306 | goto EXIT;\r | |
307 | }\r | |
ecc62d13 | 308 | // Append the Device Path to the selected device path\r |
309 | DevicePath = AppendDevicePath (SupportedBootDevice->DevicePathProtocol, (CONST EFI_DEVICE_PATH_PROTOCOL *)DevicePathNodes);\r | |
310 | if (DevicePath == NULL) {\r | |
311 | Status = EFI_OUT_OF_RESOURCES;\r | |
312 | goto EXIT;\r | |
313 | }\r | |
ea46ebbe | 314 | \r |
889ac6a8 | 315 | if (SupportedBootDevice->Support->RequestBootType) {\r |
55a9f75d OM |
316 | Status = BootDeviceGetType (DevicePath, &BootType, &Attributes);\r |
317 | if (EFI_ERROR(Status)) {\r | |
318 | Status = EFI_ABORTED;\r | |
319 | goto EXIT;\r | |
320 | }\r | |
321 | } else {\r | |
322 | BootType = BDS_LOADER_EFI_APPLICATION;\r | |
323 | }\r | |
324 | \r | |
2ccfb71e | 325 | if ((BootType == BDS_LOADER_KERNEL_LINUX_ATAG) || (BootType == BDS_LOADER_KERNEL_LINUX_FDT)) {\r |
22a262c8 | 326 | Print(L"Add an initrd: ");\r |
327 | Status = GetHIInputBoolean (&InitrdSupport);\r | |
328 | if (EFI_ERROR(Status)) {\r | |
656416bc | 329 | Status = EFI_ABORTED;\r |
330 | goto EXIT;\r | |
331 | }\r | |
332 | \r | |
22a262c8 | 333 | if (InitrdSupport) {\r |
334 | // Create the specific device path node\r | |
889ac6a8 | 335 | Status = SupportedBootDevice->Support->CreateDevicePathNode (L"initrd", &InitrdPathNodes);\r |
22a262c8 | 336 | 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 |
337 | Status = EFI_ABORTED;\r | |
338 | goto EXIT;\r | |
339 | }\r | |
340 | \r | |
ecc62d13 | 341 | if (InitrdPathNodes != NULL) {\r |
342 | // Append the Device Path to the selected device path\r | |
343 | InitrdPath = AppendDevicePath (SupportedBootDevice->DevicePathProtocol, (CONST EFI_DEVICE_PATH_PROTOCOL *)InitrdPathNodes);\r | |
344 | if (InitrdPath == NULL) {\r | |
345 | Status = EFI_OUT_OF_RESOURCES;\r | |
346 | goto EXIT;\r | |
347 | }\r | |
22a262c8 | 348 | } else {\r |
349 | InitrdPath = NULL;\r | |
350 | }\r | |
656416bc | 351 | } else {\r |
2ccfb71e | 352 | InitrdPath = NULL;\r |
656416bc | 353 | }\r |
354 | \r | |
355 | Print(L"Arguments to pass to the binary: ");\r | |
06044819 | 356 | Status = GetHIInputAscii (AsciiCmdLine, BOOT_DEVICE_OPTION_MAX);\r |
656416bc | 357 | if (EFI_ERROR(Status)) {\r |
358 | Status = EFI_ABORTED;\r | |
359 | goto FREE_DEVICE_PATH;\r | |
360 | }\r | |
2ccfb71e | 361 | \r |
06044819 | 362 | CmdLineSize = AsciiStrSize (AsciiCmdLine);\r |
2ccfb71e | 363 | InitrdSize = GetDevicePathSize (InitrdPath);\r |
364 | \r | |
90a44ec4 OM |
365 | OptionalDataSize = sizeof(ARM_BDS_LOADER_ARGUMENTS) + CmdLineSize + InitrdSize;\r |
366 | BootArguments = (ARM_BDS_LOADER_ARGUMENTS*)AllocatePool (OptionalDataSize);\r | |
aeaf64d6 | 367 | \r |
2ccfb71e | 368 | BootArguments->LinuxArguments.CmdLineSize = CmdLineSize;\r |
369 | BootArguments->LinuxArguments.InitrdSize = InitrdSize;\r | |
5382a857 | 370 | CopyMem ((VOID*)(&BootArguments->LinuxArguments + 1), AsciiCmdLine, CmdLineSize);\r |
2ccfb71e | 371 | CopyMem ((VOID*)((UINTN)(&BootArguments->LinuxArguments + 1) + CmdLineSize), InitrdPath, InitrdSize);\r |
90a44ec4 OM |
372 | \r |
373 | OptionalData = (UINT8*)BootArguments;\r | |
2ccfb71e | 374 | } else {\r |
06044819 OM |
375 | Print (L"Arguments to pass to the EFI Application: ");\r |
376 | Status = GetHIInputStr (CmdLine, BOOT_DEVICE_OPTION_MAX);\r | |
377 | if (EFI_ERROR (Status)) {\r | |
378 | Status = EFI_ABORTED;\r | |
379 | goto EXIT;\r | |
380 | }\r | |
381 | \r | |
382 | OptionalData = (UINT8*)CmdLine;\r | |
383 | OptionalDataSize = StrSize (CmdLine);\r | |
ea46ebbe | 384 | }\r |
385 | \r | |
386 | Print(L"Description for this new Entry: ");\r | |
74b96132 | 387 | Status = GetHIInputStr (BootDescription, BOOT_DEVICE_DESCRIPTION_MAX);\r |
ea46ebbe | 388 | if (EFI_ERROR(Status)) {\r |
389 | Status = EFI_ABORTED;\r | |
390 | goto FREE_DEVICE_PATH;\r | |
391 | }\r | |
392 | \r | |
ea46ebbe | 393 | // Create new entry\r |
a6e97d28 | 394 | BdsLoadOptionEntry = (BDS_LOAD_OPTION_ENTRY*)AllocatePool (sizeof(BDS_LOAD_OPTION_ENTRY));\r |
90a44ec4 | 395 | Status = BootOptionCreate (Attributes, BootDescription, DevicePath, BootType, OptionalData, OptionalDataSize, &BdsLoadOptionEntry->BdsLoadOption);\r |
ea46ebbe | 396 | if (!EFI_ERROR(Status)) {\r |
a6e97d28 | 397 | InsertTailList (BootOptionsList, &BdsLoadOptionEntry->Link);\r |
ea46ebbe | 398 | }\r |
399 | \r | |
ea46ebbe | 400 | FREE_DEVICE_PATH:\r |
401 | FreePool (DevicePath);\r | |
402 | \r | |
403 | EXIT:\r | |
656416bc | 404 | if (Status == EFI_ABORTED) {\r |
405 | Print(L"\n");\r | |
406 | }\r | |
407 | FreePool(SupportedBootDevice);\r | |
ea46ebbe | 408 | return Status;\r |
409 | }\r | |
410 | \r | |
ea46ebbe | 411 | EFI_STATUS\r |
412 | BootMenuRemoveBootOption (\r | |
413 | IN LIST_ENTRY *BootOptionsList\r | |
414 | )\r | |
415 | {\r | |
a6e97d28 | 416 | EFI_STATUS Status;\r |
417 | BDS_LOAD_OPTION_ENTRY* BootOptionEntry;\r | |
ea46ebbe | 418 | \r |
019680b3 RC |
419 | DisplayBootOptions (BootOptionsList);\r |
420 | Status = SelectBootOption (BootOptionsList, DELETE_BOOT_ENTRY, &BootOptionEntry);\r | |
421 | if (EFI_ERROR (Status)) {\r | |
ea46ebbe | 422 | return Status;\r |
423 | }\r | |
424 | \r | |
a6e97d28 | 425 | // If the Boot Option was attached to a list remove it\r |
426 | if (!IsListEmpty (&BootOptionEntry->Link)) {\r | |
427 | // Remove the entry from the list\r | |
428 | RemoveEntryList (&BootOptionEntry->Link);\r | |
429 | }\r | |
430 | \r | |
ea46ebbe | 431 | // Delete the BDS Load option structures\r |
a6e97d28 | 432 | BootOptionDelete (BootOptionEntry->BdsLoadOption);\r |
ea46ebbe | 433 | \r |
434 | return EFI_SUCCESS;\r | |
435 | }\r | |
436 | \r | |
437 | EFI_STATUS\r | |
438 | BootMenuUpdateBootOption (\r | |
439 | IN LIST_ENTRY *BootOptionsList\r | |
440 | )\r | |
441 | {\r | |
2ccfb71e | 442 | EFI_STATUS Status;\r |
a6e97d28 | 443 | BDS_LOAD_OPTION_ENTRY *BootOptionEntry;\r |
2ccfb71e | 444 | BDS_LOAD_OPTION *BootOption;\r |
445 | BDS_LOAD_OPTION_SUPPORT* DeviceSupport;\r | |
446 | ARM_BDS_LOADER_ARGUMENTS* BootArguments;\r | |
74b96132 | 447 | CHAR16 BootDescription[BOOT_DEVICE_DESCRIPTION_MAX];\r |
2ccfb71e | 448 | CHAR8 CmdLine[BOOT_DEVICE_OPTION_MAX];\r |
3b3b72d6 | 449 | CHAR16 UnicodeCmdLine[BOOT_DEVICE_OPTION_MAX];\r |
14238a61 | 450 | EFI_DEVICE_PATH *DevicePath;\r |
451 | EFI_DEVICE_PATH *TempInitrdPath;\r | |
2ccfb71e | 452 | ARM_BDS_LOADER_TYPE BootType;\r |
90a44ec4 | 453 | ARM_BDS_LOADER_OPTIONAL_DATA* LoaderOptionalData;\r |
2ccfb71e | 454 | ARM_BDS_LINUX_ARGUMENTS* LinuxArguments;\r |
ecc62d13 | 455 | EFI_DEVICE_PATH *InitrdPathNodes;\r |
22a262c8 | 456 | EFI_DEVICE_PATH *InitrdPath;\r |
2ccfb71e | 457 | UINTN InitrdSize;\r |
458 | UINTN CmdLineSize;\r | |
22a262c8 | 459 | BOOLEAN InitrdSupport;\r |
90a44ec4 OM |
460 | UINT8* OptionalData;\r |
461 | UINTN OptionalDataSize;\r | |
3b3b72d6 OM |
462 | BOOLEAN IsPrintable;\r |
463 | BOOLEAN IsUnicode;\r | |
ea46ebbe | 464 | \r |
019680b3 RC |
465 | DisplayBootOptions (BootOptionsList);\r |
466 | Status = SelectBootOption (BootOptionsList, UPDATE_BOOT_ENTRY, &BootOptionEntry);\r | |
467 | if (EFI_ERROR (Status)) {\r | |
ea46ebbe | 468 | return Status;\r |
469 | }\r | |
a6e97d28 | 470 | BootOption = BootOptionEntry->BdsLoadOption;\r |
ea46ebbe | 471 | \r |
472 | // Get the device support for this Boot Option\r | |
22a262c8 | 473 | Status = BootDeviceGetDeviceSupport (BootOption->FilePathList, &DeviceSupport);\r |
ea46ebbe | 474 | if (EFI_ERROR(Status)) {\r |
ff7666c5 | 475 | Print(L"Not possible to retrieve the supported device for the update\n");\r |
ea46ebbe | 476 | return EFI_UNSUPPORTED;\r |
477 | }\r | |
478 | \r | |
889ac6a8 | 479 | Status = DeviceSupport->UpdateDevicePathNode (BootOption->FilePathList, L"EFI Application or the kernel", &DevicePath);\r |
ea46ebbe | 480 | if (EFI_ERROR(Status)) {\r |
481 | Status = EFI_ABORTED;\r | |
482 | goto EXIT;\r | |
483 | }\r | |
484 | \r | |
889ac6a8 | 485 | if (DeviceSupport->RequestBootType) {\r |
55a9f75d OM |
486 | Status = BootDeviceGetType (DevicePath, &BootType, &BootOption->Attributes);\r |
487 | if (EFI_ERROR(Status)) {\r | |
488 | Status = EFI_ABORTED;\r | |
489 | goto EXIT;\r | |
490 | }\r | |
491 | }\r | |
492 | \r | |
90a44ec4 | 493 | LoaderOptionalData = BootOption->OptionalData;\r |
3b3b72d6 OM |
494 | if (LoaderOptionalData != NULL) {\r |
495 | BootType = (ARM_BDS_LOADER_TYPE)ReadUnaligned32 ((UINT32 *)(&LoaderOptionalData->Header.LoaderType));\r | |
496 | } else {\r | |
497 | BootType = BDS_LOADER_EFI_APPLICATION;\r | |
498 | }\r | |
656416bc | 499 | \r |
2ccfb71e | 500 | if ((BootType == BDS_LOADER_KERNEL_LINUX_ATAG) || (BootType == BDS_LOADER_KERNEL_LINUX_FDT)) {\r |
90a44ec4 | 501 | LinuxArguments = &LoaderOptionalData->Arguments.LinuxArguments;\r |
2ccfb71e | 502 | \r |
503 | CmdLineSize = ReadUnaligned16 ((CONST UINT16*)&LinuxArguments->CmdLineSize);\r | |
2ccfb71e | 504 | \r |
3e710183 | 505 | InitrdSize = ReadUnaligned16 ((CONST UINT16*)&LinuxArguments->InitrdSize);\r |
506 | if (InitrdSize > 0) {\r | |
22a262c8 | 507 | Print(L"Keep the initrd: ");\r |
508 | } else {\r | |
509 | Print(L"Add an initrd: ");\r | |
510 | }\r | |
511 | Status = GetHIInputBoolean (&InitrdSupport);\r | |
512 | if (EFI_ERROR(Status)) {\r | |
513 | Status = EFI_ABORTED;\r | |
514 | goto EXIT;\r | |
515 | }\r | |
516 | \r | |
517 | if (InitrdSupport) {\r | |
518 | if (InitrdSize > 0) {\r | |
519 | // Case we update the initrd device path\r | |
889ac6a8 | 520 | Status = DeviceSupport->UpdateDevicePathNode ((EFI_DEVICE_PATH*)((UINTN)(LinuxArguments + 1) + CmdLineSize), L"initrd", &InitrdPath);\r |
22a262c8 | 521 | 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 |
522 | Status = EFI_ABORTED;\r | |
523 | goto EXIT;\r | |
524 | }\r | |
525 | InitrdSize = GetDevicePathSize (InitrdPath);\r | |
526 | } else {\r | |
527 | // Case we create the initrd device path\r | |
528 | \r | |
889ac6a8 | 529 | Status = DeviceSupport->CreateDevicePathNode (L"initrd", &InitrdPathNodes);\r |
22a262c8 | 530 | 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 |
531 | Status = EFI_ABORTED;\r | |
532 | goto EXIT;\r | |
533 | }\r | |
534 | \r | |
ecc62d13 | 535 | if (InitrdPathNodes != NULL) {\r |
22a262c8 | 536 | // Duplicate Linux kernel Device Path\r |
14238a61 | 537 | TempInitrdPath = DuplicateDevicePath (BootOption->FilePathList);\r |
22a262c8 | 538 | // Replace Linux kernel Node by EndNode\r |
14238a61 | 539 | SetDevicePathEndNode (GetLastDevicePathNode (TempInitrdPath));\r |
ecc62d13 | 540 | // Append the Device Path to the selected device path\r |
541 | InitrdPath = AppendDevicePath (TempInitrdPath, (CONST EFI_DEVICE_PATH_PROTOCOL *)InitrdPathNodes);\r | |
14238a61 | 542 | FreePool (TempInitrdPath);\r |
ecc62d13 | 543 | if (InitrdPath == NULL) {\r |
544 | Status = EFI_OUT_OF_RESOURCES;\r | |
545 | goto EXIT;\r | |
546 | }\r | |
14238a61 | 547 | InitrdSize = GetDevicePathSize (InitrdPath);\r |
22a262c8 | 548 | } else {\r |
549 | InitrdPath = NULL;\r | |
550 | }\r | |
3e710183 | 551 | }\r |
22a262c8 | 552 | } else {\r |
553 | InitrdSize = 0;\r | |
656416bc | 554 | }\r |
555 | \r | |
aeaf64d6 | 556 | Print(L"Arguments to pass to the binary: ");\r |
2ccfb71e | 557 | if (CmdLineSize > 0) {\r |
558 | AsciiStrnCpy(CmdLine, (CONST CHAR8*)(LinuxArguments + 1), CmdLineSize);\r | |
656416bc | 559 | } else {\r |
2ccfb71e | 560 | CmdLine[0] = '\0';\r |
656416bc | 561 | }\r |
2ccfb71e | 562 | Status = EditHIInputAscii (CmdLine, BOOT_DEVICE_OPTION_MAX);\r |
656416bc | 563 | if (EFI_ERROR(Status)) {\r |
564 | Status = EFI_ABORTED;\r | |
565 | goto FREE_DEVICE_PATH;\r | |
566 | }\r | |
2ccfb71e | 567 | \r |
568 | CmdLineSize = AsciiStrSize (CmdLine);\r | |
2ccfb71e | 569 | \r |
90a44ec4 OM |
570 | OptionalDataSize = sizeof(ARM_BDS_LOADER_ARGUMENTS) + CmdLineSize + InitrdSize;\r |
571 | BootArguments = (ARM_BDS_LOADER_ARGUMENTS*)AllocatePool (OptionalDataSize);\r | |
2ccfb71e | 572 | BootArguments->LinuxArguments.CmdLineSize = CmdLineSize;\r |
573 | BootArguments->LinuxArguments.InitrdSize = InitrdSize;\r | |
574 | CopyMem (&BootArguments->LinuxArguments + 1, CmdLine, CmdLineSize);\r | |
49a25d84 | 575 | CopyMem ((VOID*)((UINTN)(&BootArguments->LinuxArguments + 1) + CmdLineSize), InitrdPath, InitrdSize);\r |
90a44ec4 OM |
576 | \r |
577 | OptionalData = (UINT8*)BootArguments;\r | |
2ccfb71e | 578 | } else {\r |
3b3b72d6 OM |
579 | Print (L"Arguments to pass to the EFI Application: ");\r |
580 | \r | |
581 | if (BootOption->OptionalDataSize > 0) {\r | |
582 | IsPrintable = IsPrintableString (BootOption->OptionalData, &IsUnicode);\r | |
583 | if (IsPrintable) {\r | |
584 | if (IsUnicode) {\r | |
585 | StrnCpy (UnicodeCmdLine, BootOption->OptionalData, BootOption->OptionalDataSize / 2);\r | |
586 | } else {\r | |
587 | AsciiStrnCpy (CmdLine, BootOption->OptionalData, BootOption->OptionalDataSize);\r | |
588 | }\r | |
589 | }\r | |
590 | } else {\r | |
591 | UnicodeCmdLine[0] = L'\0';\r | |
592 | IsPrintable = TRUE;\r | |
593 | IsUnicode = TRUE;\r | |
594 | }\r | |
595 | \r | |
596 | // We do not request arguments for OptionalData that cannot be printed\r | |
597 | if (IsPrintable) {\r | |
598 | if (IsUnicode) {\r | |
599 | Status = EditHIInputStr (UnicodeCmdLine, BOOT_DEVICE_OPTION_MAX);\r | |
600 | if (EFI_ERROR (Status)) {\r | |
601 | Status = EFI_ABORTED;\r | |
602 | goto FREE_DEVICE_PATH;\r | |
603 | }\r | |
604 | \r | |
605 | OptionalData = (UINT8*)UnicodeCmdLine;\r | |
606 | OptionalDataSize = StrSize (UnicodeCmdLine);\r | |
607 | } else {\r | |
608 | Status = EditHIInputAscii (CmdLine, BOOT_DEVICE_OPTION_MAX);\r | |
609 | if (EFI_ERROR (Status)) {\r | |
610 | Status = EFI_ABORTED;\r | |
611 | goto FREE_DEVICE_PATH;\r | |
612 | }\r | |
613 | \r | |
614 | OptionalData = (UINT8*)CmdLine;\r | |
615 | OptionalDataSize = AsciiStrSize (CmdLine);\r | |
616 | }\r | |
617 | } else {\r | |
618 | // We keep the former OptionalData\r | |
619 | OptionalData = BootOption->OptionalData;\r | |
620 | OptionalDataSize = BootOption->OptionalDataSize;\r | |
621 | }\r | |
ea46ebbe | 622 | }\r |
623 | \r | |
624 | Print(L"Description for this new Entry: ");\r | |
3e710183 | 625 | StrnCpy (BootDescription, BootOption->Description, BOOT_DEVICE_DESCRIPTION_MAX);\r |
74b96132 | 626 | Status = EditHIInputStr (BootDescription, BOOT_DEVICE_DESCRIPTION_MAX);\r |
ea46ebbe | 627 | if (EFI_ERROR(Status)) {\r |
628 | Status = EFI_ABORTED;\r | |
629 | goto FREE_DEVICE_PATH;\r | |
630 | }\r | |
631 | \r | |
ea46ebbe | 632 | // Update the entry\r |
90a44ec4 | 633 | Status = BootOptionUpdate (BootOption, BootOption->Attributes, BootDescription, DevicePath, BootType, OptionalData, OptionalDataSize);\r |
ea46ebbe | 634 | \r |
ea46ebbe | 635 | FREE_DEVICE_PATH:\r |
636 | FreePool (DevicePath);\r | |
637 | \r | |
638 | EXIT:\r | |
326d1df9 | 639 | if (Status == EFI_ABORTED) {\r |
640 | Print(L"\n");\r | |
641 | }\r | |
ea46ebbe | 642 | return Status;\r |
643 | }\r | |
644 | \r | |
019680b3 RC |
645 | /**\r |
646 | Reorder boot options\r | |
647 | \r | |
648 | Ask for the boot option to move and then move it when up or down arrows\r | |
649 | are pressed. This function is called when the user selects the "Reorder Boot\r | |
650 | Device Entries" entry in the boot manager menu.\r | |
651 | The order of the boot options in BootOptionList and in the UEFI BootOrder\r | |
652 | global variable are kept coherent until the user confirm his reordering (ie:\r | |
653 | he does not exit by pressing escape).\r | |
654 | \r | |
655 | @param[in] BootOptionsList List of the boot devices constructed in\r | |
656 | BootMenuMain()\r | |
657 | \r | |
658 | @retval EFI_SUCCESS No error encountered.\r | |
659 | @retval !EFI_SUCCESS An error has occured either in the selection of the\r | |
660 | boot option to move or while interacting with the user.\r | |
661 | \r | |
662 | **/\r | |
663 | STATIC\r | |
664 | EFI_STATUS\r | |
665 | BootMenuReorderBootOptions (\r | |
666 | IN LIST_ENTRY *BootOptionsList\r | |
667 | )\r | |
668 | {\r | |
669 | EFI_STATUS Status;\r | |
670 | BDS_LOAD_OPTION_ENTRY *BootOptionEntry;\r | |
671 | LIST_ENTRY *SelectedEntry;\r | |
672 | LIST_ENTRY *PrevEntry;\r | |
673 | BOOLEAN Move;\r | |
674 | BOOLEAN Save;\r | |
675 | BOOLEAN Cancel;\r | |
676 | UINTN WaitIndex;\r | |
677 | EFI_INPUT_KEY Key;\r | |
678 | LIST_ENTRY *SecondEntry;\r | |
679 | UINTN BootOrderSize;\r | |
680 | UINT16 *BootOrder;\r | |
681 | LIST_ENTRY *Entry;\r | |
682 | UINTN Index;\r | |
683 | \r | |
684 | DisplayBootOptions (BootOptionsList);\r | |
685 | \r | |
686 | // Ask to select the boot option to move\r | |
687 | while (TRUE) {\r | |
688 | Status = SelectBootOption (BootOptionsList, MOVE_BOOT_ENTRY, &BootOptionEntry);\r | |
689 | if (EFI_ERROR (Status)) {\r | |
690 | goto ErrorExit;\r | |
691 | }\r | |
692 | \r | |
693 | SelectedEntry = &BootOptionEntry->Link;\r | |
749d91f7 | 694 | SecondEntry = NULL;\r |
019680b3 RC |
695 | // Note down the previous entry in the list to be able to cancel changes\r |
696 | PrevEntry = GetPreviousNode (BootOptionsList, SelectedEntry);\r | |
697 | \r | |
698 | // Start of interaction\r | |
699 | while (TRUE) {\r | |
700 | Print (\r | |
701 | L"* Use up/down arrows to move the entry '%s'",\r | |
702 | BootOptionEntry->BdsLoadOption->Description\r | |
703 | );\r | |
704 | \r | |
705 | // Wait for a move, save or cancel request\r | |
706 | Move = FALSE;\r | |
707 | Save = FALSE;\r | |
708 | Cancel = FALSE;\r | |
709 | do {\r | |
710 | Status = gBS->WaitForEvent (1, &gST->ConIn->WaitForKey, &WaitIndex);\r | |
711 | if (!EFI_ERROR (Status)) {\r | |
712 | Status = gST->ConIn->ReadKeyStroke (gST->ConIn, &Key);\r | |
713 | }\r | |
714 | if (EFI_ERROR (Status)) {\r | |
715 | Print (L"\n");\r | |
716 | goto ErrorExit;\r | |
717 | }\r | |
718 | \r | |
719 | switch (Key.ScanCode) {\r | |
720 | case SCAN_NULL:\r | |
721 | Save = (Key.UnicodeChar == CHAR_LINEFEED) ||\r | |
722 | (Key.UnicodeChar == CHAR_CARRIAGE_RETURN) ||\r | |
723 | (Key.UnicodeChar == 0x7f);\r | |
724 | break;\r | |
725 | \r | |
726 | case SCAN_UP:\r | |
727 | SecondEntry = GetPreviousNode (BootOptionsList, SelectedEntry);\r | |
728 | Move = SecondEntry != BootOptionsList;\r | |
729 | break;\r | |
730 | \r | |
731 | case SCAN_DOWN:\r | |
732 | SecondEntry = GetNextNode (BootOptionsList, SelectedEntry);\r | |
733 | Move = SecondEntry != BootOptionsList;\r | |
734 | break;\r | |
735 | \r | |
736 | case SCAN_ESC:\r | |
737 | Cancel = TRUE;\r | |
738 | break;\r | |
739 | }\r | |
740 | } while ((!Move) && (!Save) && (!Cancel));\r | |
741 | \r | |
742 | if (Move) {\r | |
749d91f7 HL |
743 | if ((SelectedEntry != NULL) && (SecondEntry != NULL)) {\r |
744 | SwapListEntries (SelectedEntry, SecondEntry);\r | |
745 | }\r | |
019680b3 RC |
746 | } else {\r |
747 | if (Save) {\r | |
748 | Status = GetGlobalEnvironmentVariable (\r | |
749 | L"BootOrder", NULL, &BootOrderSize, (VOID**)&BootOrder\r | |
750 | );\r | |
751 | BootOrderSize /= sizeof (UINT16);\r | |
752 | \r | |
753 | if (!EFI_ERROR (Status)) {\r | |
754 | // The order of the boot options in the 'BootOptionsList' is the\r | |
755 | // new order that has been just defined by the user. Save this new\r | |
756 | // order in "BootOrder" UEFI global variable.\r | |
757 | Entry = GetFirstNode (BootOptionsList);\r | |
758 | for (Index = 0; Index < BootOrderSize; Index++) {\r | |
759 | BootOrder[Index] = (LOAD_OPTION_FROM_LINK (Entry))->LoadOptionIndex;\r | |
760 | Entry = GetNextNode (BootOptionsList, Entry);\r | |
761 | }\r | |
762 | Status = gRT->SetVariable (\r | |
763 | (CHAR16*)L"BootOrder",\r | |
764 | &gEfiGlobalVariableGuid,\r | |
765 | EFI_VARIABLE_NON_VOLATILE |\r | |
766 | EFI_VARIABLE_BOOTSERVICE_ACCESS |\r | |
767 | EFI_VARIABLE_RUNTIME_ACCESS,\r | |
768 | BootOrderSize * sizeof (UINT16),\r | |
769 | BootOrder\r | |
770 | );\r | |
771 | FreePool (BootOrder);\r | |
772 | }\r | |
773 | \r | |
774 | if (EFI_ERROR (Status)) {\r | |
775 | Print (L"\nAn error occurred, move not completed!\n");\r | |
776 | Cancel = TRUE;\r | |
777 | }\r | |
778 | }\r | |
779 | \r | |
780 | if (Cancel) {\r | |
781 | //\r | |
782 | // Restore initial position of the selected boot option\r | |
783 | //\r | |
784 | RemoveEntryList (SelectedEntry);\r | |
785 | InsertHeadList (PrevEntry, SelectedEntry);\r | |
786 | }\r | |
787 | }\r | |
788 | \r | |
789 | Print (L"\n");\r | |
790 | DisplayBootOptions (BootOptionsList);\r | |
791 | // Saved or cancelled, back to the choice of boot option to move\r | |
792 | if (!Move) {\r | |
793 | break;\r | |
794 | }\r | |
795 | }\r | |
796 | }\r | |
797 | \r | |
798 | ErrorExit:\r | |
799 | return Status ;\r | |
800 | }\r | |
801 | \r | |
95b3580f | 802 | EFI_STATUS\r |
803 | UpdateFdtPath (\r | |
804 | IN LIST_ENTRY *BootOptionsList\r | |
805 | )\r | |
806 | {\r | |
c0658bd6 | 807 | EFI_STATUS Status;\r |
808 | UINTN FdtDevicePathSize;\r | |
809 | BDS_SUPPORTED_DEVICE *SupportedBootDevice;\r | |
ecc62d13 | 810 | EFI_DEVICE_PATH_PROTOCOL *FdtDevicePathNodes;\r |
c0658bd6 | 811 | EFI_DEVICE_PATH_PROTOCOL *FdtDevicePath;\r |
95b3580f | 812 | \r |
813 | Status = SelectBootDevice (&SupportedBootDevice);\r | |
814 | if (EFI_ERROR(Status)) {\r | |
815 | Status = EFI_ABORTED;\r | |
816 | goto EXIT;\r | |
817 | }\r | |
818 | \r | |
819 | // Create the specific device path node\r | |
889ac6a8 | 820 | Status = SupportedBootDevice->Support->CreateDevicePathNode (L"FDT blob", &FdtDevicePathNodes);\r |
95b3580f | 821 | if (EFI_ERROR(Status)) {\r |
822 | Status = EFI_ABORTED;\r | |
823 | goto EXIT;\r | |
824 | }\r | |
825 | \r | |
ecc62d13 | 826 | if (FdtDevicePathNodes != NULL) {\r |
95b3580f | 827 | // Append the Device Path node to the select device path\r |
ecc62d13 | 828 | FdtDevicePath = AppendDevicePath (SupportedBootDevice->DevicePathProtocol, FdtDevicePathNodes);\r |
c0658bd6 | 829 | FdtDevicePathSize = GetDevicePathSize (FdtDevicePath);\r |
aeaf64d6 | 830 | Status = gRT->SetVariable (\r |
831 | (CHAR16*)L"Fdt",\r | |
832 | &gArmGlobalVariableGuid,\r | |
833 | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS,\r | |
834 | FdtDevicePathSize,\r | |
835 | FdtDevicePath\r | |
836 | );\r | |
95b3580f | 837 | ASSERT_EFI_ERROR(Status);\r |
838 | } else {\r | |
aeaf64d6 | 839 | gRT->SetVariable (\r |
840 | (CHAR16*)L"Fdt",\r | |
841 | &gArmGlobalVariableGuid,\r | |
842 | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS,\r | |
843 | 0,\r | |
844 | NULL\r | |
845 | );\r | |
95b3580f | 846 | ASSERT_EFI_ERROR(Status);\r |
847 | }\r | |
848 | \r | |
849 | EXIT:\r | |
850 | if (Status == EFI_ABORTED) {\r | |
851 | Print(L"\n");\r | |
852 | }\r | |
853 | FreePool(SupportedBootDevice);\r | |
854 | return Status;\r | |
855 | }\r | |
856 | \r | |
42de0937 RC |
857 | /**\r |
858 | Set boot timeout\r | |
859 | \r | |
860 | Ask for the boot timeout in seconds and if the input succeeds assign the\r | |
861 | input value to the UEFI global variable "Timeout". This function is called\r | |
862 | when the user selects the "Set Boot Timeout" of the boot manager menu.\r | |
863 | \r | |
864 | @param[in] BootOptionsList List of the boot devices, not used here\r | |
865 | \r | |
866 | @retval EFI_SUCCESS Boot timeout in second retrieved from the standard\r | |
867 | input and assigned to the UEFI "Timeout" global\r | |
868 | variable\r | |
869 | @retval !EFI_SUCCESS Either the input or the setting of the UEFI global\r | |
870 | variable "Timeout" has failed.\r | |
871 | **/\r | |
872 | EFI_STATUS\r | |
873 | STATIC\r | |
874 | BootMenuSetBootTimeout (\r | |
875 | IN LIST_ENTRY *BootOptionsList\r | |
876 | )\r | |
877 | {\r | |
878 | EFI_STATUS Status;\r | |
879 | UINTN Input;\r | |
880 | UINT16 Timeout;\r | |
881 | \r | |
882 | Print (L"Timeout duration (in seconds): ");\r | |
883 | Status = GetHIInputInteger (&Input);\r | |
884 | if (EFI_ERROR (Status)) {\r | |
885 | Print (L"\n");\r | |
886 | goto ErrorExit;\r | |
887 | }\r | |
888 | \r | |
889 | Timeout = Input;\r | |
890 | Status = gRT->SetVariable (\r | |
891 | (CHAR16*)L"Timeout",\r | |
892 | &gEfiGlobalVariableGuid,\r | |
893 | EFI_VARIABLE_NON_VOLATILE |\r | |
894 | EFI_VARIABLE_BOOTSERVICE_ACCESS |\r | |
895 | EFI_VARIABLE_RUNTIME_ACCESS,\r | |
896 | sizeof (UINT16),\r | |
897 | &Timeout\r | |
898 | );\r | |
899 | ASSERT_EFI_ERROR (Status);\r | |
900 | \r | |
901 | ErrorExit:\r | |
902 | return Status;\r | |
903 | }\r | |
904 | \r | |
ea46ebbe | 905 | struct BOOT_MANAGER_ENTRY {\r |
906 | CONST CHAR16* Description;\r | |
907 | EFI_STATUS (*Callback) (IN LIST_ENTRY *BootOptionsList);\r | |
908 | } BootManagerEntries[] = {\r | |
909 | { L"Add Boot Device Entry", BootMenuAddBootOption },\r | |
910 | { L"Update Boot Device Entry", BootMenuUpdateBootOption },\r | |
911 | { L"Remove Boot Device Entry", BootMenuRemoveBootOption },\r | |
019680b3 | 912 | { L"Reorder Boot Device Entries", BootMenuReorderBootOptions },\r |
95b3580f | 913 | { L"Update FDT path", UpdateFdtPath },\r |
42de0937 | 914 | { L"Set Boot Timeout", BootMenuSetBootTimeout },\r |
ea46ebbe | 915 | };\r |
916 | \r | |
917 | EFI_STATUS\r | |
918 | BootMenuManager (\r | |
919 | IN LIST_ENTRY *BootOptionsList\r | |
920 | )\r | |
921 | {\r | |
922 | UINTN Index;\r | |
923 | UINTN OptionSelected;\r | |
924 | UINTN BootManagerEntryCount;\r | |
925 | EFI_STATUS Status;\r | |
926 | \r | |
927 | BootManagerEntryCount = sizeof(BootManagerEntries) / sizeof(struct BOOT_MANAGER_ENTRY);\r | |
928 | \r | |
929 | while (TRUE) {\r | |
930 | // Display Boot Manager menu\r | |
931 | for (Index = 0; Index < BootManagerEntryCount; Index++) {\r | |
932 | Print(L"[%d] %s\n",Index+1,BootManagerEntries[Index]);\r | |
933 | }\r | |
934 | Print(L"[%d] Return to main menu\n",Index+1);\r | |
935 | \r | |
936 | // Select which entry to call\r | |
937 | Print(L"Choice: ");\r | |
938 | Status = GetHIInputInteger (&OptionSelected);\r | |
939 | if (EFI_ERROR(Status) || (OptionSelected == (BootManagerEntryCount+1))) {\r | |
326d1df9 | 940 | if (EFI_ERROR(Status)) {\r |
941 | Print(L"\n");\r | |
942 | }\r | |
ea46ebbe | 943 | return EFI_SUCCESS;\r |
944 | } else if ((OptionSelected > 0) && (OptionSelected <= BootManagerEntryCount)) {\r | |
ff7666c5 | 945 | BootManagerEntries[OptionSelected-1].Callback (BootOptionsList);\r |
ea46ebbe | 946 | }\r |
947 | }\r | |
11c20f4e | 948 | // Should never go here\r |
ea46ebbe | 949 | }\r |
950 | \r | |
951 | EFI_STATUS\r | |
8213627e | 952 | BootShell (\r |
ea46ebbe | 953 | IN LIST_ENTRY *BootOptionsList\r |
954 | )\r | |
955 | {\r | |
956 | EFI_STATUS Status;\r | |
957 | \r | |
958 | // Start EFI Shell\r | |
c3b6d975 | 959 | Status = BdsLoadApplication (gImageHandle, L"Shell", 0, NULL);\r |
ea46ebbe | 960 | if (Status == EFI_NOT_FOUND) {\r |
961 | Print (L"Error: EFI Application not found.\n");\r | |
962 | } else if (EFI_ERROR(Status)) {\r | |
963 | Print (L"Error: Status Code: 0x%X\n",(UINT32)Status);\r | |
964 | }\r | |
965 | \r | |
966 | return Status;\r | |
967 | }\r | |
968 | \r | |
969 | struct BOOT_MAIN_ENTRY {\r | |
970 | CONST CHAR16* Description;\r | |
971 | EFI_STATUS (*Callback) (IN LIST_ENTRY *BootOptionsList);\r | |
972 | } BootMainEntries[] = {\r | |
8213627e | 973 | { L"Shell", BootShell },\r |
ea46ebbe | 974 | { L"Boot Manager", BootMenuManager },\r |
975 | };\r | |
976 | \r | |
977 | \r | |
978 | EFI_STATUS\r | |
979 | BootMenuMain (\r | |
980 | VOID\r | |
981 | )\r | |
982 | {\r | |
2ccfb71e | 983 | LIST_ENTRY BootOptionsList;\r |
984 | UINTN OptionCount;\r | |
985 | UINTN BootOptionCount;\r | |
986 | EFI_STATUS Status;\r | |
987 | LIST_ENTRY* Entry;\r | |
988 | BDS_LOAD_OPTION* BootOption;\r | |
989 | UINTN BootOptionSelected;\r | |
990 | UINTN Index;\r | |
991 | UINTN BootMainEntryCount;\r | |
5389972a | 992 | BOOLEAN IsUnicode;\r |
ea46ebbe | 993 | \r |
5389972a | 994 | BootOption = NULL;\r |
ea46ebbe | 995 | BootMainEntryCount = sizeof(BootMainEntries) / sizeof(struct BOOT_MAIN_ENTRY);\r |
a6caee65 | 996 | \r |
ea46ebbe | 997 | while (TRUE) {\r |
a6e97d28 | 998 | // Get Boot#### list\r |
999 | BootOptionList (&BootOptionsList);\r | |
1000 | \r | |
ea46ebbe | 1001 | OptionCount = 1;\r |
1002 | \r | |
1003 | // Display the Boot options\r | |
1004 | for (Entry = GetFirstNode (&BootOptionsList);\r | |
1005 | !IsNull (&BootOptionsList,Entry);\r | |
1006 | Entry = GetNextNode (&BootOptionsList,Entry)\r | |
1007 | )\r | |
1008 | {\r | |
1009 | BootOption = LOAD_OPTION_FROM_LINK(Entry);\r | |
1010 | \r | |
ff7666c5 | 1011 | Print(L"[%d] %s\n", OptionCount, BootOption->Description);\r |
ea46ebbe | 1012 | \r |
1013 | DEBUG_CODE_BEGIN();\r | |
1014 | CHAR16* DevicePathTxt;\r | |
1015 | EFI_DEVICE_PATH_TO_TEXT_PROTOCOL* DevicePathToTextProtocol;\r | |
2ccfb71e | 1016 | ARM_BDS_LOADER_OPTIONAL_DATA* OptionalData;\r |
1017 | UINTN CmdLineSize;\r | |
3e710183 | 1018 | ARM_BDS_LOADER_TYPE LoaderType;\r |
ea46ebbe | 1019 | \r |
ff7666c5 | 1020 | Status = gBS->LocateProtocol (&gEfiDevicePathToTextProtocolGuid, NULL, (VOID **)&DevicePathToTextProtocol);\r |
aa95e2f7 | 1021 | if (EFI_ERROR(Status)) {\r |
1022 | // You must provide an implementation of DevicePathToTextProtocol in your firmware (eg: DevicePathDxe)\r | |
1023 | DEBUG((EFI_D_ERROR,"Error: Bds requires DevicePathToTextProtocol\n"));\r | |
1024 | return Status;\r | |
1025 | }\r | |
ff7666c5 | 1026 | DevicePathTxt = DevicePathToTextProtocol->ConvertDevicePathToText (BootOption->FilePathList, TRUE, TRUE);\r |
ea46ebbe | 1027 | \r |
1028 | Print(L"\t- %s\n",DevicePathTxt);\r | |
2ccfb71e | 1029 | \r |
1030 | // If it is a supported BootEntry then print its details\r | |
1031 | if (IS_ARM_BDS_BOOTENTRY (BootOption)) {\r | |
1032 | OptionalData = BootOption->OptionalData;\r | |
1033 | LoaderType = (ARM_BDS_LOADER_TYPE)ReadUnaligned32 ((CONST UINT32*)&OptionalData->Header.LoaderType);\r | |
1034 | if ((LoaderType == BDS_LOADER_KERNEL_LINUX_ATAG) || (LoaderType == BDS_LOADER_KERNEL_LINUX_FDT)) {\r | |
1035 | if (ReadUnaligned16 (&OptionalData->Arguments.LinuxArguments.InitrdSize) > 0) {\r | |
1036 | CmdLineSize = ReadUnaligned16 (&OptionalData->Arguments.LinuxArguments.CmdLineSize);\r | |
1037 | DevicePathTxt = DevicePathToTextProtocol->ConvertDevicePathToText (\r | |
1038 | GetAlignedDevicePath ((EFI_DEVICE_PATH*)((UINTN)(&OptionalData->Arguments.LinuxArguments + 1) + CmdLineSize)), TRUE, TRUE);\r | |
1039 | Print(L"\t- Initrd: %s\n", DevicePathTxt);\r | |
1040 | }\r | |
5aecd343 OM |
1041 | if (ReadUnaligned16 (&OptionalData->Arguments.LinuxArguments.CmdLineSize) > 0) {\r |
1042 | Print(L"\t- Arguments: %a\n", (&OptionalData->Arguments.LinuxArguments + 1));\r | |
1043 | }\r | |
ea46ebbe | 1044 | }\r |
7135d76d | 1045 | \r |
1046 | switch (LoaderType) {\r | |
1047 | case BDS_LOADER_EFI_APPLICATION:\r | |
1048 | Print(L"\t- LoaderType: EFI Application\n");\r | |
1049 | break;\r | |
1050 | \r | |
1051 | case BDS_LOADER_KERNEL_LINUX_ATAG:\r | |
1052 | Print(L"\t- LoaderType: Linux kernel with ATAG support\n");\r | |
1053 | break;\r | |
1054 | \r | |
1055 | case BDS_LOADER_KERNEL_LINUX_FDT:\r | |
1056 | Print(L"\t- LoaderType: Linux kernel with FDT support\n");\r | |
1057 | break;\r | |
1058 | \r | |
1059 | default:\r | |
1060 | Print(L"\t- LoaderType: Not recognized (%d)\n", LoaderType);\r | |
1061 | }\r | |
5389972a OM |
1062 | } else if (BootOption->OptionalData != NULL) {\r |
1063 | if (IsPrintableString (BootOption->OptionalData, &IsUnicode)) {\r | |
1064 | if (IsUnicode) {\r | |
1065 | Print (L"\t- Arguments: %s\n", BootOption->OptionalData);\r | |
1066 | } else {\r | |
1067 | AsciiPrint ("\t- Arguments: %a\n", BootOption->OptionalData);\r | |
1068 | }\r | |
1069 | }\r | |
ea46ebbe | 1070 | }\r |
ea46ebbe | 1071 | FreePool(DevicePathTxt);\r |
1072 | DEBUG_CODE_END();\r | |
1073 | \r | |
1074 | OptionCount++;\r | |
1075 | }\r | |
1076 | BootOptionCount = OptionCount-1;\r | |
1077 | \r | |
1078 | // Display the hardcoded Boot entries\r | |
1079 | for (Index = 0; Index < BootMainEntryCount; Index++) {\r | |
1080 | Print(L"[%d] %s\n",OptionCount,BootMainEntries[Index]);\r | |
1081 | OptionCount++;\r | |
1082 | }\r | |
1083 | \r | |
1084 | // Request the boot entry from the user\r | |
1085 | BootOptionSelected = 0;\r | |
1086 | while (BootOptionSelected == 0) {\r | |
1087 | Print(L"Start: ");\r | |
1088 | Status = GetHIInputInteger (&BootOptionSelected);\r | |
1089 | if (EFI_ERROR(Status) || (BootOptionSelected == 0) || (BootOptionSelected > OptionCount)) {\r | |
1090 | Print(L"Invalid input (max %d)\n",(OptionCount-1));\r | |
1091 | BootOptionSelected = 0;\r | |
1092 | }\r | |
1093 | }\r | |
1094 | \r | |
1095 | // Start the selected entry\r | |
1096 | if (BootOptionSelected > BootOptionCount) {\r | |
1097 | // Start the hardcoded entry\r | |
1098 | Status = BootMainEntries[BootOptionSelected - BootOptionCount - 1].Callback (&BootOptionsList);\r | |
1099 | } else {\r | |
1100 | // Find the selected entry from the Boot#### list\r | |
1101 | Index = 1;\r | |
1102 | for (Entry = GetFirstNode (&BootOptionsList);\r | |
1103 | !IsNull (&BootOptionsList,Entry);\r | |
1104 | Entry = GetNextNode (&BootOptionsList,Entry)\r | |
1105 | )\r | |
1106 | {\r | |
1107 | if (Index == BootOptionSelected) {\r | |
1108 | BootOption = LOAD_OPTION_FROM_LINK(Entry);\r | |
1109 | break;\r | |
1110 | }\r | |
1111 | Index++;\r | |
1112 | }\r | |
1113 | \r | |
1114 | Status = BootOptionStart (BootOption);\r | |
1115 | }\r | |
1116 | }\r | |
11c20f4e | 1117 | // Should never go here\r |
ea46ebbe | 1118 | }\r |