]>
Commit | Line | Data |
---|---|---|
1 | /** @file\r | |
2 | *\r | |
3 | * Copyright (c) 2011-2013, 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 | |
19 | extern EFI_HANDLE mImageHandle;\r | |
20 | extern BDS_LOAD_OPTION_SUPPORT *BdsLoadOptionSupportList;\r | |
21 | \r | |
22 | \r | |
23 | EFI_STATUS\r | |
24 | SelectBootDevice (\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 | |
109 | EXIT:\r | |
110 | BootDeviceListSupportedFree (&SupportedDeviceList, *SupportedBootDevice);\r | |
111 | return Status;\r | |
112 | }\r | |
113 | \r | |
114 | EFI_STATUS\r | |
115 | BootMenuAddBootOption (\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), CmdLine, 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 | |
248 | FREE_DEVICE_PATH:\r | |
249 | FreePool (DevicePath);\r | |
250 | \r | |
251 | EXIT:\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 | |
259 | STATIC\r | |
260 | EFI_STATUS\r | |
261 | BootMenuSelectBootOption (\r | |
262 | IN LIST_ENTRY* BootOptionsList,\r | |
263 | IN CONST CHAR16* InputStatement,\r | |
264 | IN BOOLEAN OnlyArmBdsBootEntry,\r | |
265 | OUT BDS_LOAD_OPTION_ENTRY** BdsLoadOptionEntry\r | |
266 | )\r | |
267 | {\r | |
268 | EFI_STATUS Status;\r | |
269 | LIST_ENTRY* Entry;\r | |
270 | BDS_LOAD_OPTION* BdsLoadOption;\r | |
271 | UINTN BootOptionSelected;\r | |
272 | UINTN BootOptionCount;\r | |
273 | UINTN Index;\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 | if (OnlyArmBdsBootEntry && !IS_ARM_BDS_BOOTENTRY (BdsLoadOption)) {\r | |
285 | continue;\r | |
286 | }\r | |
287 | \r | |
288 | Print (L"[%d] %s\n", (BootOptionCount + 1), BdsLoadOption->Description);\r | |
289 | \r | |
290 | DEBUG_CODE_BEGIN();\r | |
291 | CHAR16* DevicePathTxt;\r | |
292 | EFI_DEVICE_PATH_TO_TEXT_PROTOCOL* DevicePathToTextProtocol;\r | |
293 | ARM_BDS_LOADER_TYPE LoaderType;\r | |
294 | ARM_BDS_LOADER_OPTIONAL_DATA* OptionalData;\r | |
295 | \r | |
296 | Status = gBS->LocateProtocol(&gEfiDevicePathToTextProtocolGuid, NULL, (VOID **)&DevicePathToTextProtocol);\r | |
297 | ASSERT_EFI_ERROR(Status);\r | |
298 | DevicePathTxt = DevicePathToTextProtocol->ConvertDevicePathToText(BdsLoadOption->FilePathList,TRUE,TRUE);\r | |
299 | \r | |
300 | Print(L"\t- %s\n",DevicePathTxt);\r | |
301 | OptionalData = BdsLoadOption->OptionalData;\r | |
302 | LoaderType = (ARM_BDS_LOADER_TYPE)ReadUnaligned32 ((CONST UINT32*)&OptionalData->Header.LoaderType);\r | |
303 | if ((LoaderType == BDS_LOADER_KERNEL_LINUX_ATAG) || (LoaderType == BDS_LOADER_KERNEL_LINUX_FDT)) {\r | |
304 | Print (L"\t- Arguments: %a\n",&OptionalData->Arguments.LinuxArguments + 1);\r | |
305 | }\r | |
306 | \r | |
307 | FreePool(DevicePathTxt);\r | |
308 | DEBUG_CODE_END();\r | |
309 | \r | |
310 | BootOptionCount++;\r | |
311 | }\r | |
312 | \r | |
313 | // Check if a valid boot option(s) is found\r | |
314 | if (BootOptionCount == 0) {\r | |
315 | if (StrCmp (InputStatement, DELETE_BOOT_ENTRY) == 0) {\r | |
316 | Print (L"Nothing to remove!\n");\r | |
317 | } else if (StrCmp (InputStatement, UPDATE_BOOT_ENTRY) == 0) {\r | |
318 | Print (L"Couldn't find valid boot entries\n");\r | |
319 | } else{\r | |
320 | Print (L"No supported Boot Entry.\n");\r | |
321 | }\r | |
322 | \r | |
323 | return EFI_NOT_FOUND;\r | |
324 | }\r | |
325 | \r | |
326 | // Get the index of the boot device to delete\r | |
327 | BootOptionSelected = 0;\r | |
328 | while (BootOptionSelected == 0) {\r | |
329 | Print(InputStatement);\r | |
330 | Status = GetHIInputInteger (&BootOptionSelected);\r | |
331 | if (EFI_ERROR(Status)) {\r | |
332 | return Status;\r | |
333 | } else if ((BootOptionSelected == 0) || (BootOptionSelected > BootOptionCount)) {\r | |
334 | Print(L"Invalid input (max %d)\n",BootOptionCount);\r | |
335 | BootOptionSelected = 0;\r | |
336 | }\r | |
337 | }\r | |
338 | \r | |
339 | // Get the structure of the Boot device to delete\r | |
340 | Index = 1;\r | |
341 | for (Entry = GetFirstNode (BootOptionsList);\r | |
342 | !IsNull (BootOptionsList, Entry);\r | |
343 | Entry = GetNextNode (BootOptionsList,Entry)\r | |
344 | )\r | |
345 | {\r | |
346 | if (Index == BootOptionSelected) {\r | |
347 | *BdsLoadOptionEntry = LOAD_OPTION_ENTRY_FROM_LINK(Entry);\r | |
348 | break;\r | |
349 | }\r | |
350 | Index++;\r | |
351 | }\r | |
352 | \r | |
353 | return EFI_SUCCESS;\r | |
354 | }\r | |
355 | \r | |
356 | EFI_STATUS\r | |
357 | BootMenuRemoveBootOption (\r | |
358 | IN LIST_ENTRY *BootOptionsList\r | |
359 | )\r | |
360 | {\r | |
361 | EFI_STATUS Status;\r | |
362 | BDS_LOAD_OPTION_ENTRY* BootOptionEntry;\r | |
363 | \r | |
364 | Status = BootMenuSelectBootOption (BootOptionsList, DELETE_BOOT_ENTRY, FALSE, &BootOptionEntry);\r | |
365 | if (EFI_ERROR(Status)) {\r | |
366 | return Status;\r | |
367 | }\r | |
368 | \r | |
369 | // If the Boot Option was attached to a list remove it\r | |
370 | if (!IsListEmpty (&BootOptionEntry->Link)) {\r | |
371 | // Remove the entry from the list\r | |
372 | RemoveEntryList (&BootOptionEntry->Link);\r | |
373 | }\r | |
374 | \r | |
375 | // Delete the BDS Load option structures\r | |
376 | BootOptionDelete (BootOptionEntry->BdsLoadOption);\r | |
377 | \r | |
378 | return EFI_SUCCESS;\r | |
379 | }\r | |
380 | \r | |
381 | EFI_STATUS\r | |
382 | BootMenuUpdateBootOption (\r | |
383 | IN LIST_ENTRY *BootOptionsList\r | |
384 | )\r | |
385 | {\r | |
386 | EFI_STATUS Status;\r | |
387 | BDS_LOAD_OPTION_ENTRY *BootOptionEntry;\r | |
388 | BDS_LOAD_OPTION *BootOption;\r | |
389 | BDS_LOAD_OPTION_SUPPORT* DeviceSupport;\r | |
390 | ARM_BDS_LOADER_ARGUMENTS* BootArguments;\r | |
391 | CHAR16 BootDescription[BOOT_DEVICE_DESCRIPTION_MAX];\r | |
392 | CHAR8 CmdLine[BOOT_DEVICE_OPTION_MAX];\r | |
393 | EFI_DEVICE_PATH *DevicePath;\r | |
394 | EFI_DEVICE_PATH *TempInitrdPath;\r | |
395 | ARM_BDS_LOADER_TYPE BootType;\r | |
396 | ARM_BDS_LOADER_OPTIONAL_DATA* LoaderOptionalData;\r | |
397 | ARM_BDS_LINUX_ARGUMENTS* LinuxArguments;\r | |
398 | EFI_DEVICE_PATH *InitrdPathNodes;\r | |
399 | EFI_DEVICE_PATH *InitrdPath;\r | |
400 | UINTN InitrdSize;\r | |
401 | UINTN CmdLineSize;\r | |
402 | BOOLEAN InitrdSupport;\r | |
403 | UINT8* OptionalData;\r | |
404 | UINTN OptionalDataSize;\r | |
405 | BOOLEAN RequestBootType;\r | |
406 | \r | |
407 | Status = BootMenuSelectBootOption (BootOptionsList, UPDATE_BOOT_ENTRY, TRUE, &BootOptionEntry);\r | |
408 | if (EFI_ERROR(Status)) {\r | |
409 | return Status;\r | |
410 | }\r | |
411 | BootOption = BootOptionEntry->BdsLoadOption;\r | |
412 | \r | |
413 | // Get the device support for this Boot Option\r | |
414 | Status = BootDeviceGetDeviceSupport (BootOption->FilePathList, &DeviceSupport);\r | |
415 | if (EFI_ERROR(Status)) {\r | |
416 | Print(L"Not possible to retrieve the supported device for the update\n");\r | |
417 | return EFI_UNSUPPORTED;\r | |
418 | }\r | |
419 | \r | |
420 | RequestBootType = TRUE;\r | |
421 | Status = DeviceSupport->UpdateDevicePathNode (BootOption->FilePathList, L"EFI Application or the kernel", &DevicePath, &RequestBootType);\r | |
422 | if (EFI_ERROR(Status)) {\r | |
423 | Status = EFI_ABORTED;\r | |
424 | goto EXIT;\r | |
425 | }\r | |
426 | \r | |
427 | if (RequestBootType) {\r | |
428 | Status = BootDeviceGetType (DevicePath, &BootType, &BootOption->Attributes);\r | |
429 | if (EFI_ERROR(Status)) {\r | |
430 | Status = EFI_ABORTED;\r | |
431 | goto EXIT;\r | |
432 | }\r | |
433 | }\r | |
434 | \r | |
435 | LoaderOptionalData = BootOption->OptionalData;\r | |
436 | BootType = (ARM_BDS_LOADER_TYPE)ReadUnaligned32 ((UINT32 *)(&LoaderOptionalData->Header.LoaderType));\r | |
437 | \r | |
438 | if ((BootType == BDS_LOADER_KERNEL_LINUX_ATAG) || (BootType == BDS_LOADER_KERNEL_LINUX_FDT)) {\r | |
439 | LinuxArguments = &LoaderOptionalData->Arguments.LinuxArguments;\r | |
440 | \r | |
441 | CmdLineSize = ReadUnaligned16 ((CONST UINT16*)&LinuxArguments->CmdLineSize);\r | |
442 | \r | |
443 | InitrdSize = ReadUnaligned16 ((CONST UINT16*)&LinuxArguments->InitrdSize);\r | |
444 | if (InitrdSize > 0) {\r | |
445 | Print(L"Keep the initrd: ");\r | |
446 | } else {\r | |
447 | Print(L"Add an initrd: ");\r | |
448 | }\r | |
449 | Status = GetHIInputBoolean (&InitrdSupport);\r | |
450 | if (EFI_ERROR(Status)) {\r | |
451 | Status = EFI_ABORTED;\r | |
452 | goto EXIT;\r | |
453 | }\r | |
454 | \r | |
455 | if (InitrdSupport) {\r | |
456 | if (InitrdSize > 0) {\r | |
457 | // Case we update the initrd device path\r | |
458 | Status = DeviceSupport->UpdateDevicePathNode ((EFI_DEVICE_PATH*)((UINTN)(LinuxArguments + 1) + CmdLineSize), L"initrd", &InitrdPath, NULL);\r | |
459 | 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 | |
460 | Status = EFI_ABORTED;\r | |
461 | goto EXIT;\r | |
462 | }\r | |
463 | InitrdSize = GetDevicePathSize (InitrdPath);\r | |
464 | } else {\r | |
465 | // Case we create the initrd device path\r | |
466 | \r | |
467 | Status = DeviceSupport->CreateDevicePathNode (L"initrd", &InitrdPathNodes, NULL);\r | |
468 | 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 | |
469 | Status = EFI_ABORTED;\r | |
470 | goto EXIT;\r | |
471 | }\r | |
472 | \r | |
473 | if (InitrdPathNodes != NULL) {\r | |
474 | // Duplicate Linux kernel Device Path\r | |
475 | TempInitrdPath = DuplicateDevicePath (BootOption->FilePathList);\r | |
476 | // Replace Linux kernel Node by EndNode\r | |
477 | SetDevicePathEndNode (GetLastDevicePathNode (TempInitrdPath));\r | |
478 | // Append the Device Path to the selected device path\r | |
479 | InitrdPath = AppendDevicePath (TempInitrdPath, (CONST EFI_DEVICE_PATH_PROTOCOL *)InitrdPathNodes);\r | |
480 | FreePool (TempInitrdPath);\r | |
481 | if (InitrdPath == NULL) {\r | |
482 | Status = EFI_OUT_OF_RESOURCES;\r | |
483 | goto EXIT;\r | |
484 | }\r | |
485 | InitrdSize = GetDevicePathSize (InitrdPath);\r | |
486 | } else {\r | |
487 | InitrdPath = NULL;\r | |
488 | }\r | |
489 | }\r | |
490 | } else {\r | |
491 | InitrdSize = 0;\r | |
492 | }\r | |
493 | \r | |
494 | Print(L"Arguments to pass to the binary: ");\r | |
495 | if (CmdLineSize > 0) {\r | |
496 | AsciiStrnCpy(CmdLine, (CONST CHAR8*)(LinuxArguments + 1), CmdLineSize);\r | |
497 | } else {\r | |
498 | CmdLine[0] = '\0';\r | |
499 | }\r | |
500 | Status = EditHIInputAscii (CmdLine, BOOT_DEVICE_OPTION_MAX);\r | |
501 | if (EFI_ERROR(Status)) {\r | |
502 | Status = EFI_ABORTED;\r | |
503 | goto FREE_DEVICE_PATH;\r | |
504 | }\r | |
505 | \r | |
506 | CmdLineSize = AsciiStrSize (CmdLine);\r | |
507 | \r | |
508 | OptionalDataSize = sizeof(ARM_BDS_LOADER_ARGUMENTS) + CmdLineSize + InitrdSize;\r | |
509 | BootArguments = (ARM_BDS_LOADER_ARGUMENTS*)AllocatePool (OptionalDataSize);\r | |
510 | BootArguments->LinuxArguments.CmdLineSize = CmdLineSize;\r | |
511 | BootArguments->LinuxArguments.InitrdSize = InitrdSize;\r | |
512 | CopyMem (&BootArguments->LinuxArguments + 1, CmdLine, CmdLineSize);\r | |
513 | CopyMem ((VOID*)((UINTN)(&BootArguments->LinuxArguments + 1) + CmdLineSize), InitrdPath, InitrdSize);\r | |
514 | \r | |
515 | OptionalData = (UINT8*)BootArguments;\r | |
516 | } else {\r | |
517 | OptionalData = NULL;\r | |
518 | OptionalDataSize = 0;\r | |
519 | }\r | |
520 | \r | |
521 | Print(L"Description for this new Entry: ");\r | |
522 | StrnCpy (BootDescription, BootOption->Description, BOOT_DEVICE_DESCRIPTION_MAX);\r | |
523 | Status = EditHIInputStr (BootDescription, BOOT_DEVICE_DESCRIPTION_MAX);\r | |
524 | if (EFI_ERROR(Status)) {\r | |
525 | Status = EFI_ABORTED;\r | |
526 | goto FREE_DEVICE_PATH;\r | |
527 | }\r | |
528 | \r | |
529 | // Update the entry\r | |
530 | Status = BootOptionUpdate (BootOption, BootOption->Attributes, BootDescription, DevicePath, BootType, OptionalData, OptionalDataSize);\r | |
531 | \r | |
532 | FREE_DEVICE_PATH:\r | |
533 | FreePool (DevicePath);\r | |
534 | \r | |
535 | EXIT:\r | |
536 | if (Status == EFI_ABORTED) {\r | |
537 | Print(L"\n");\r | |
538 | }\r | |
539 | return Status;\r | |
540 | }\r | |
541 | \r | |
542 | EFI_STATUS\r | |
543 | UpdateFdtPath (\r | |
544 | IN LIST_ENTRY *BootOptionsList\r | |
545 | )\r | |
546 | {\r | |
547 | EFI_STATUS Status;\r | |
548 | UINTN FdtDevicePathSize;\r | |
549 | BDS_SUPPORTED_DEVICE *SupportedBootDevice;\r | |
550 | EFI_DEVICE_PATH_PROTOCOL *FdtDevicePathNodes;\r | |
551 | EFI_DEVICE_PATH_PROTOCOL *FdtDevicePath;\r | |
552 | \r | |
553 | Status = SelectBootDevice (&SupportedBootDevice);\r | |
554 | if (EFI_ERROR(Status)) {\r | |
555 | Status = EFI_ABORTED;\r | |
556 | goto EXIT;\r | |
557 | }\r | |
558 | \r | |
559 | // Create the specific device path node\r | |
560 | Status = SupportedBootDevice->Support->CreateDevicePathNode (L"FDT blob", &FdtDevicePathNodes, NULL);\r | |
561 | if (EFI_ERROR(Status)) {\r | |
562 | Status = EFI_ABORTED;\r | |
563 | goto EXIT;\r | |
564 | }\r | |
565 | \r | |
566 | if (FdtDevicePathNodes != NULL) {\r | |
567 | // Append the Device Path node to the select device path\r | |
568 | FdtDevicePath = AppendDevicePath (SupportedBootDevice->DevicePathProtocol, FdtDevicePathNodes);\r | |
569 | FdtDevicePathSize = GetDevicePathSize (FdtDevicePath);\r | |
570 | Status = gRT->SetVariable (\r | |
571 | (CHAR16*)L"Fdt",\r | |
572 | &gArmGlobalVariableGuid,\r | |
573 | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS,\r | |
574 | FdtDevicePathSize,\r | |
575 | FdtDevicePath\r | |
576 | );\r | |
577 | ASSERT_EFI_ERROR(Status);\r | |
578 | } else {\r | |
579 | gRT->SetVariable (\r | |
580 | (CHAR16*)L"Fdt",\r | |
581 | &gArmGlobalVariableGuid,\r | |
582 | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS,\r | |
583 | 0,\r | |
584 | NULL\r | |
585 | );\r | |
586 | ASSERT_EFI_ERROR(Status);\r | |
587 | }\r | |
588 | \r | |
589 | EXIT:\r | |
590 | if (Status == EFI_ABORTED) {\r | |
591 | Print(L"\n");\r | |
592 | }\r | |
593 | FreePool(SupportedBootDevice);\r | |
594 | return Status;\r | |
595 | }\r | |
596 | \r | |
597 | struct BOOT_MANAGER_ENTRY {\r | |
598 | CONST CHAR16* Description;\r | |
599 | EFI_STATUS (*Callback) (IN LIST_ENTRY *BootOptionsList);\r | |
600 | } BootManagerEntries[] = {\r | |
601 | { L"Add Boot Device Entry", BootMenuAddBootOption },\r | |
602 | { L"Update Boot Device Entry", BootMenuUpdateBootOption },\r | |
603 | { L"Remove Boot Device Entry", BootMenuRemoveBootOption },\r | |
604 | { L"Update FDT path", UpdateFdtPath },\r | |
605 | };\r | |
606 | \r | |
607 | EFI_STATUS\r | |
608 | BootMenuManager (\r | |
609 | IN LIST_ENTRY *BootOptionsList\r | |
610 | )\r | |
611 | {\r | |
612 | UINTN Index;\r | |
613 | UINTN OptionSelected;\r | |
614 | UINTN BootManagerEntryCount;\r | |
615 | EFI_STATUS Status;\r | |
616 | \r | |
617 | BootManagerEntryCount = sizeof(BootManagerEntries) / sizeof(struct BOOT_MANAGER_ENTRY);\r | |
618 | \r | |
619 | while (TRUE) {\r | |
620 | // Display Boot Manager menu\r | |
621 | for (Index = 0; Index < BootManagerEntryCount; Index++) {\r | |
622 | Print(L"[%d] %s\n",Index+1,BootManagerEntries[Index]);\r | |
623 | }\r | |
624 | Print(L"[%d] Return to main menu\n",Index+1);\r | |
625 | \r | |
626 | // Select which entry to call\r | |
627 | Print(L"Choice: ");\r | |
628 | Status = GetHIInputInteger (&OptionSelected);\r | |
629 | if (EFI_ERROR(Status) || (OptionSelected == (BootManagerEntryCount+1))) {\r | |
630 | if (EFI_ERROR(Status)) {\r | |
631 | Print(L"\n");\r | |
632 | }\r | |
633 | return EFI_SUCCESS;\r | |
634 | } else if ((OptionSelected > 0) && (OptionSelected <= BootManagerEntryCount)) {\r | |
635 | BootManagerEntries[OptionSelected-1].Callback (BootOptionsList);\r | |
636 | }\r | |
637 | }\r | |
638 | // Should never go here\r | |
639 | }\r | |
640 | \r | |
641 | EFI_STATUS\r | |
642 | BootShell (\r | |
643 | IN LIST_ENTRY *BootOptionsList\r | |
644 | )\r | |
645 | {\r | |
646 | EFI_STATUS Status;\r | |
647 | \r | |
648 | // Start EFI Shell\r | |
649 | Status = BdsLoadApplication (mImageHandle, L"Shell", 0, NULL);\r | |
650 | if (Status == EFI_NOT_FOUND) {\r | |
651 | Print (L"Error: EFI Application not found.\n");\r | |
652 | } else if (EFI_ERROR(Status)) {\r | |
653 | Print (L"Error: Status Code: 0x%X\n",(UINT32)Status);\r | |
654 | }\r | |
655 | \r | |
656 | return Status;\r | |
657 | }\r | |
658 | \r | |
659 | struct BOOT_MAIN_ENTRY {\r | |
660 | CONST CHAR16* Description;\r | |
661 | EFI_STATUS (*Callback) (IN LIST_ENTRY *BootOptionsList);\r | |
662 | } BootMainEntries[] = {\r | |
663 | { L"Shell", BootShell },\r | |
664 | { L"Boot Manager", BootMenuManager },\r | |
665 | };\r | |
666 | \r | |
667 | \r | |
668 | EFI_STATUS\r | |
669 | BootMenuMain (\r | |
670 | VOID\r | |
671 | )\r | |
672 | {\r | |
673 | LIST_ENTRY BootOptionsList;\r | |
674 | UINTN OptionCount;\r | |
675 | UINTN BootOptionCount;\r | |
676 | EFI_STATUS Status;\r | |
677 | LIST_ENTRY* Entry;\r | |
678 | BDS_LOAD_OPTION* BootOption;\r | |
679 | UINTN BootOptionSelected;\r | |
680 | UINTN Index;\r | |
681 | UINTN BootMainEntryCount;\r | |
682 | BOOLEAN IsUnicode;\r | |
683 | \r | |
684 | BootOption = NULL;\r | |
685 | BootMainEntryCount = sizeof(BootMainEntries) / sizeof(struct BOOT_MAIN_ENTRY);\r | |
686 | \r | |
687 | while (TRUE) {\r | |
688 | // Get Boot#### list\r | |
689 | BootOptionList (&BootOptionsList);\r | |
690 | \r | |
691 | OptionCount = 1;\r | |
692 | \r | |
693 | // Display the Boot options\r | |
694 | for (Entry = GetFirstNode (&BootOptionsList);\r | |
695 | !IsNull (&BootOptionsList,Entry);\r | |
696 | Entry = GetNextNode (&BootOptionsList,Entry)\r | |
697 | )\r | |
698 | {\r | |
699 | BootOption = LOAD_OPTION_FROM_LINK(Entry);\r | |
700 | \r | |
701 | Print(L"[%d] %s\n", OptionCount, BootOption->Description);\r | |
702 | \r | |
703 | DEBUG_CODE_BEGIN();\r | |
704 | CHAR16* DevicePathTxt;\r | |
705 | EFI_DEVICE_PATH_TO_TEXT_PROTOCOL* DevicePathToTextProtocol;\r | |
706 | ARM_BDS_LOADER_OPTIONAL_DATA* OptionalData;\r | |
707 | UINTN CmdLineSize;\r | |
708 | ARM_BDS_LOADER_TYPE LoaderType;\r | |
709 | \r | |
710 | Status = gBS->LocateProtocol (&gEfiDevicePathToTextProtocolGuid, NULL, (VOID **)&DevicePathToTextProtocol);\r | |
711 | if (EFI_ERROR(Status)) {\r | |
712 | // You must provide an implementation of DevicePathToTextProtocol in your firmware (eg: DevicePathDxe)\r | |
713 | DEBUG((EFI_D_ERROR,"Error: Bds requires DevicePathToTextProtocol\n"));\r | |
714 | return Status;\r | |
715 | }\r | |
716 | DevicePathTxt = DevicePathToTextProtocol->ConvertDevicePathToText (BootOption->FilePathList, TRUE, TRUE);\r | |
717 | \r | |
718 | Print(L"\t- %s\n",DevicePathTxt);\r | |
719 | \r | |
720 | // If it is a supported BootEntry then print its details\r | |
721 | if (IS_ARM_BDS_BOOTENTRY (BootOption)) {\r | |
722 | OptionalData = BootOption->OptionalData;\r | |
723 | LoaderType = (ARM_BDS_LOADER_TYPE)ReadUnaligned32 ((CONST UINT32*)&OptionalData->Header.LoaderType);\r | |
724 | if ((LoaderType == BDS_LOADER_KERNEL_LINUX_ATAG) || (LoaderType == BDS_LOADER_KERNEL_LINUX_FDT)) {\r | |
725 | if (ReadUnaligned16 (&OptionalData->Arguments.LinuxArguments.InitrdSize) > 0) {\r | |
726 | CmdLineSize = ReadUnaligned16 (&OptionalData->Arguments.LinuxArguments.CmdLineSize);\r | |
727 | DevicePathTxt = DevicePathToTextProtocol->ConvertDevicePathToText (\r | |
728 | GetAlignedDevicePath ((EFI_DEVICE_PATH*)((UINTN)(&OptionalData->Arguments.LinuxArguments + 1) + CmdLineSize)), TRUE, TRUE);\r | |
729 | Print(L"\t- Initrd: %s\n", DevicePathTxt);\r | |
730 | }\r | |
731 | Print(L"\t- Arguments: %a\n", (&OptionalData->Arguments.LinuxArguments + 1));\r | |
732 | }\r | |
733 | \r | |
734 | switch (LoaderType) {\r | |
735 | case BDS_LOADER_EFI_APPLICATION:\r | |
736 | Print(L"\t- LoaderType: EFI Application\n");\r | |
737 | break;\r | |
738 | \r | |
739 | case BDS_LOADER_KERNEL_LINUX_ATAG:\r | |
740 | Print(L"\t- LoaderType: Linux kernel with ATAG support\n");\r | |
741 | break;\r | |
742 | \r | |
743 | case BDS_LOADER_KERNEL_LINUX_FDT:\r | |
744 | Print(L"\t- LoaderType: Linux kernel with FDT support\n");\r | |
745 | break;\r | |
746 | \r | |
747 | default:\r | |
748 | Print(L"\t- LoaderType: Not recognized (%d)\n", LoaderType);\r | |
749 | }\r | |
750 | } else if (BootOption->OptionalData != NULL) {\r | |
751 | if (IsPrintableString (BootOption->OptionalData, &IsUnicode)) {\r | |
752 | if (IsUnicode) {\r | |
753 | Print (L"\t- Arguments: %s\n", BootOption->OptionalData);\r | |
754 | } else {\r | |
755 | AsciiPrint ("\t- Arguments: %a\n", BootOption->OptionalData);\r | |
756 | }\r | |
757 | }\r | |
758 | }\r | |
759 | FreePool(DevicePathTxt);\r | |
760 | DEBUG_CODE_END();\r | |
761 | \r | |
762 | OptionCount++;\r | |
763 | }\r | |
764 | BootOptionCount = OptionCount-1;\r | |
765 | \r | |
766 | // Display the hardcoded Boot entries\r | |
767 | for (Index = 0; Index < BootMainEntryCount; Index++) {\r | |
768 | Print(L"[%d] %s\n",OptionCount,BootMainEntries[Index]);\r | |
769 | OptionCount++;\r | |
770 | }\r | |
771 | \r | |
772 | // Request the boot entry from the user\r | |
773 | BootOptionSelected = 0;\r | |
774 | while (BootOptionSelected == 0) {\r | |
775 | Print(L"Start: ");\r | |
776 | Status = GetHIInputInteger (&BootOptionSelected);\r | |
777 | if (EFI_ERROR(Status) || (BootOptionSelected == 0) || (BootOptionSelected > OptionCount)) {\r | |
778 | Print(L"Invalid input (max %d)\n",(OptionCount-1));\r | |
779 | BootOptionSelected = 0;\r | |
780 | }\r | |
781 | }\r | |
782 | \r | |
783 | // Start the selected entry\r | |
784 | if (BootOptionSelected > BootOptionCount) {\r | |
785 | // Start the hardcoded entry\r | |
786 | Status = BootMainEntries[BootOptionSelected - BootOptionCount - 1].Callback (&BootOptionsList);\r | |
787 | } else {\r | |
788 | // Find the selected entry from the Boot#### list\r | |
789 | Index = 1;\r | |
790 | for (Entry = GetFirstNode (&BootOptionsList);\r | |
791 | !IsNull (&BootOptionsList,Entry);\r | |
792 | Entry = GetNextNode (&BootOptionsList,Entry)\r | |
793 | )\r | |
794 | {\r | |
795 | if (Index == BootOptionSelected) {\r | |
796 | BootOption = LOAD_OPTION_FROM_LINK(Entry);\r | |
797 | break;\r | |
798 | }\r | |
799 | Index++;\r | |
800 | }\r | |
801 | \r | |
802 | Status = BootOptionStart (BootOption);\r | |
803 | }\r | |
804 | }\r | |
805 | // Should never go here\r | |
806 | }\r |