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