]>
Commit | Line | Data |
---|---|---|
ea46ebbe | 1 | /** @file\r |
2 | *\r | |
aeaf64d6 | 3 | * Copyright (c) 2011-2013, ARM Limited. All rights reserved.\r |
ea46ebbe | 4 | *\r |
5 | * This program and the accompanying materials\r | |
6 | * are licensed and made available under the terms and conditions of the BSD License\r | |
7 | * which accompanies this distribution. The full text of the license may be found at\r | |
8 | * http://opensource.org/licenses/bsd-license.php\r | |
9 | *\r | |
10 | * THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r | |
11 | * WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r | |
12 | *\r | |
13 | **/\r | |
14 | \r | |
15 | #include "BdsInternal.h"\r | |
16 | \r | |
aeaf64d6 | 17 | #include <Guid/ArmGlobalVariableHob.h>\r |
18 | \r | |
ea46ebbe | 19 | extern EFI_HANDLE mImageHandle;\r |
20 | extern BDS_LOAD_OPTION_SUPPORT *BdsLoadOptionSupportList;\r | |
21 | \r | |
aeaf64d6 | 22 | \r |
ea46ebbe | 23 | EFI_STATUS\r |
656416bc | 24 | SelectBootDevice (\r |
25 | OUT BDS_SUPPORTED_DEVICE** SupportedBootDevice\r | |
ea46ebbe | 26 | )\r |
27 | {\r | |
656416bc | 28 | EFI_STATUS Status;\r |
ea46ebbe | 29 | LIST_ENTRY SupportedDeviceList;\r |
30 | UINTN SupportedDeviceCount;\r | |
ea46ebbe | 31 | LIST_ENTRY* Entry;\r |
32 | UINTN SupportedDeviceSelected;\r | |
ea46ebbe | 33 | UINTN Index;\r |
ea46ebbe | 34 | \r |
35 | //\r | |
36 | // List the Boot Devices supported\r | |
37 | //\r | |
38 | \r | |
39 | // Start all the drivers first\r | |
40 | BdsConnectAllDrivers ();\r | |
41 | \r | |
42 | // List the supported devices\r | |
43 | Status = BootDeviceListSupportedInit (&SupportedDeviceList);\r | |
44 | ASSERT_EFI_ERROR(Status);\r | |
45 | \r | |
46 | SupportedDeviceCount = 0;\r | |
47 | for (Entry = GetFirstNode (&SupportedDeviceList);\r | |
48 | !IsNull (&SupportedDeviceList,Entry);\r | |
49 | Entry = GetNextNode (&SupportedDeviceList,Entry)\r | |
50 | )\r | |
51 | {\r | |
656416bc | 52 | *SupportedBootDevice = SUPPORTED_BOOT_DEVICE_FROM_LINK(Entry);\r |
53 | Print(L"[%d] %s\n",SupportedDeviceCount+1,(*SupportedBootDevice)->Description);\r | |
ea46ebbe | 54 | \r |
55 | DEBUG_CODE_BEGIN();\r | |
56 | CHAR16* DevicePathTxt;\r | |
57 | EFI_DEVICE_PATH_TO_TEXT_PROTOCOL* DevicePathToTextProtocol;\r | |
58 | \r | |
ff7666c5 | 59 | Status = gBS->LocateProtocol (&gEfiDevicePathToTextProtocolGuid, NULL, (VOID **)&DevicePathToTextProtocol);\r |
ea46ebbe | 60 | ASSERT_EFI_ERROR(Status);\r |
ff7666c5 | 61 | DevicePathTxt = DevicePathToTextProtocol->ConvertDevicePathToText ((*SupportedBootDevice)->DevicePathProtocol,TRUE,TRUE);\r |
ea46ebbe | 62 | \r |
63 | Print(L"\t- %s\n",DevicePathTxt);\r | |
64 | \r | |
65 | FreePool(DevicePathTxt);\r | |
66 | DEBUG_CODE_END();\r | |
67 | \r | |
68 | SupportedDeviceCount++;\r | |
69 | }\r | |
70 | \r | |
71 | if (SupportedDeviceCount == 0) {\r | |
72 | Print(L"There is no supported device.\n");\r | |
73 | Status = EFI_ABORTED;\r | |
74 | goto EXIT;\r | |
75 | }\r | |
76 | \r | |
77 | //\r | |
78 | // Select the Boot Device\r | |
79 | //\r | |
80 | SupportedDeviceSelected = 0;\r | |
81 | while (SupportedDeviceSelected == 0) {\r | |
82 | Print(L"Select the Boot Device: ");\r | |
83 | Status = GetHIInputInteger (&SupportedDeviceSelected);\r | |
84 | if (EFI_ERROR(Status)) {\r | |
85 | Status = EFI_ABORTED;\r | |
86 | goto EXIT;\r | |
87 | } else if ((SupportedDeviceSelected == 0) || (SupportedDeviceSelected > SupportedDeviceCount)) {\r | |
ff7666c5 | 88 | Print(L"Invalid input (max %d)\n",SupportedDeviceCount);\r |
ea46ebbe | 89 | SupportedDeviceSelected = 0;\r |
90 | }\r | |
91 | }\r | |
92 | \r | |
93 | //\r | |
94 | // Get the Device Path for the selected boot device\r | |
95 | //\r | |
96 | Index = 1;\r | |
97 | for (Entry = GetFirstNode (&SupportedDeviceList);\r | |
98 | !IsNull (&SupportedDeviceList,Entry);\r | |
99 | Entry = GetNextNode (&SupportedDeviceList,Entry)\r | |
100 | )\r | |
101 | {\r | |
102 | if (Index == SupportedDeviceSelected) {\r | |
656416bc | 103 | *SupportedBootDevice = SUPPORTED_BOOT_DEVICE_FROM_LINK(Entry);\r |
ea46ebbe | 104 | break;\r |
105 | }\r | |
106 | Index++;\r | |
107 | }\r | |
aeaf64d6 | 108 | \r |
656416bc | 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 | |
2ccfb71e | 119 | EFI_STATUS Status;\r |
120 | BDS_SUPPORTED_DEVICE* SupportedBootDevice;\r | |
121 | ARM_BDS_LOADER_ARGUMENTS* BootArguments;\r | |
74b96132 | 122 | CHAR16 BootDescription[BOOT_DEVICE_DESCRIPTION_MAX];\r |
06044819 OM |
123 | CHAR8 AsciiCmdLine[BOOT_DEVICE_OPTION_MAX];\r |
124 | CHAR16 CmdLine[BOOT_DEVICE_OPTION_MAX];\r | |
2ccfb71e | 125 | UINT32 Attributes;\r |
126 | ARM_BDS_LOADER_TYPE BootType;\r | |
a6e97d28 | 127 | BDS_LOAD_OPTION_ENTRY *BdsLoadOptionEntry;\r |
2ccfb71e | 128 | EFI_DEVICE_PATH *DevicePath;\r |
ecc62d13 | 129 | EFI_DEVICE_PATH_PROTOCOL *DevicePathNodes;\r |
130 | EFI_DEVICE_PATH_PROTOCOL *InitrdPathNodes;\r | |
2ccfb71e | 131 | EFI_DEVICE_PATH_PROTOCOL *InitrdPath;\r |
132 | UINTN CmdLineSize;\r | |
22a262c8 | 133 | BOOLEAN InitrdSupport;\r |
2ccfb71e | 134 | UINTN InitrdSize;\r |
90a44ec4 OM |
135 | UINT8* OptionalData;\r |
136 | UINTN OptionalDataSize;\r | |
55a9f75d | 137 | BOOLEAN RequestBootType;\r |
656416bc | 138 | \r |
139 | Attributes = 0;\r | |
140 | SupportedBootDevice = NULL;\r | |
141 | \r | |
142 | // List the Boot Devices supported\r | |
2ccfb71e | 143 | Status = SelectBootDevice (&SupportedBootDevice);\r |
656416bc | 144 | if (EFI_ERROR(Status)) {\r |
145 | Status = EFI_ABORTED;\r | |
146 | goto EXIT;\r | |
147 | }\r | |
ea46ebbe | 148 | \r |
149 | // Create the specific device path node\r | |
55a9f75d OM |
150 | RequestBootType = TRUE;\r |
151 | Status = SupportedBootDevice->Support->CreateDevicePathNode (L"EFI Application or the kernel", &DevicePathNodes, &RequestBootType);\r | |
ea46ebbe | 152 | if (EFI_ERROR(Status)) {\r |
153 | Status = EFI_ABORTED;\r | |
154 | goto EXIT;\r | |
155 | }\r | |
ecc62d13 | 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 | |
ea46ebbe | 162 | \r |
55a9f75d OM |
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 | |
2ccfb71e | 173 | if ((BootType == BDS_LOADER_KERNEL_LINUX_ATAG) || (BootType == BDS_LOADER_KERNEL_LINUX_FDT)) {\r |
22a262c8 | 174 | Print(L"Add an initrd: ");\r |
175 | Status = GetHIInputBoolean (&InitrdSupport);\r | |
176 | if (EFI_ERROR(Status)) {\r | |
656416bc | 177 | Status = EFI_ABORTED;\r |
178 | goto EXIT;\r | |
179 | }\r | |
180 | \r | |
22a262c8 | 181 | if (InitrdSupport) {\r |
182 | // Create the specific device path node\r | |
55a9f75d | 183 | Status = SupportedBootDevice->Support->CreateDevicePathNode (L"initrd", &InitrdPathNodes, NULL);\r |
22a262c8 | 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 | |
ecc62d13 | 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 | |
22a262c8 | 196 | } else {\r |
197 | InitrdPath = NULL;\r | |
198 | }\r | |
656416bc | 199 | } else {\r |
2ccfb71e | 200 | InitrdPath = NULL;\r |
656416bc | 201 | }\r |
202 | \r | |
203 | Print(L"Arguments to pass to the binary: ");\r | |
06044819 | 204 | Status = GetHIInputAscii (AsciiCmdLine, BOOT_DEVICE_OPTION_MAX);\r |
656416bc | 205 | if (EFI_ERROR(Status)) {\r |
206 | Status = EFI_ABORTED;\r | |
207 | goto FREE_DEVICE_PATH;\r | |
208 | }\r | |
2ccfb71e | 209 | \r |
06044819 | 210 | CmdLineSize = AsciiStrSize (AsciiCmdLine);\r |
2ccfb71e | 211 | InitrdSize = GetDevicePathSize (InitrdPath);\r |
212 | \r | |
90a44ec4 OM |
213 | OptionalDataSize = sizeof(ARM_BDS_LOADER_ARGUMENTS) + CmdLineSize + InitrdSize;\r |
214 | BootArguments = (ARM_BDS_LOADER_ARGUMENTS*)AllocatePool (OptionalDataSize);\r | |
aeaf64d6 | 215 | \r |
2ccfb71e | 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 | |
90a44ec4 OM |
220 | \r |
221 | OptionalData = (UINT8*)BootArguments;\r | |
2ccfb71e | 222 | } else {\r |
06044819 OM |
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 | |
ea46ebbe | 232 | }\r |
233 | \r | |
234 | Print(L"Description for this new Entry: ");\r | |
74b96132 | 235 | Status = GetHIInputStr (BootDescription, BOOT_DEVICE_DESCRIPTION_MAX);\r |
ea46ebbe | 236 | if (EFI_ERROR(Status)) {\r |
237 | Status = EFI_ABORTED;\r | |
238 | goto FREE_DEVICE_PATH;\r | |
239 | }\r | |
240 | \r | |
ea46ebbe | 241 | // Create new entry\r |
a6e97d28 | 242 | BdsLoadOptionEntry = (BDS_LOAD_OPTION_ENTRY*)AllocatePool (sizeof(BDS_LOAD_OPTION_ENTRY));\r |
90a44ec4 | 243 | Status = BootOptionCreate (Attributes, BootDescription, DevicePath, BootType, OptionalData, OptionalDataSize, &BdsLoadOptionEntry->BdsLoadOption);\r |
ea46ebbe | 244 | if (!EFI_ERROR(Status)) {\r |
a6e97d28 | 245 | InsertTailList (BootOptionsList, &BdsLoadOptionEntry->Link);\r |
ea46ebbe | 246 | }\r |
247 | \r | |
ea46ebbe | 248 | FREE_DEVICE_PATH:\r |
249 | FreePool (DevicePath);\r | |
250 | \r | |
251 | EXIT:\r | |
656416bc | 252 | if (Status == EFI_ABORTED) {\r |
253 | Print(L"\n");\r | |
254 | }\r | |
255 | FreePool(SupportedBootDevice);\r | |
ea46ebbe | 256 | return Status;\r |
257 | }\r | |
258 | \r | |
259 | STATIC\r | |
260 | EFI_STATUS\r | |
261 | BootMenuSelectBootOption (\r | |
a6e97d28 | 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 | |
ea46ebbe | 266 | )\r |
267 | {\r | |
a6e97d28 | 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 | |
ea46ebbe | 274 | \r |
275 | // Display the list of supported boot devices\r | |
c93ab96c | 276 | BootOptionCount = 0;\r |
ea46ebbe | 277 | for (Entry = GetFirstNode (BootOptionsList);\r |
278 | !IsNull (BootOptionsList,Entry);\r | |
a6e97d28 | 279 | Entry = GetNextNode (BootOptionsList, Entry)\r |
ea46ebbe | 280 | )\r |
281 | {\r | |
a6e97d28 | 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 | |
c93ab96c | 288 | Print (L"[%d] %s\n", (BootOptionCount + 1), BdsLoadOption->Description);\r |
ea46ebbe | 289 | \r |
290 | DEBUG_CODE_BEGIN();\r | |
291 | CHAR16* DevicePathTxt;\r | |
292 | EFI_DEVICE_PATH_TO_TEXT_PROTOCOL* DevicePathToTextProtocol;\r | |
2ccfb71e | 293 | ARM_BDS_LOADER_TYPE LoaderType;\r |
a6e97d28 | 294 | ARM_BDS_LOADER_OPTIONAL_DATA* OptionalData;\r |
ea46ebbe | 295 | \r |
296 | Status = gBS->LocateProtocol(&gEfiDevicePathToTextProtocolGuid, NULL, (VOID **)&DevicePathToTextProtocol);\r | |
297 | ASSERT_EFI_ERROR(Status);\r | |
a6e97d28 | 298 | DevicePathTxt = DevicePathToTextProtocol->ConvertDevicePathToText(BdsLoadOption->FilePathList,TRUE,TRUE);\r |
ea46ebbe | 299 | \r |
300 | Print(L"\t- %s\n",DevicePathTxt);\r | |
2ccfb71e | 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 | |
ea46ebbe | 305 | }\r |
306 | \r | |
307 | FreePool(DevicePathTxt);\r | |
308 | DEBUG_CODE_END();\r | |
309 | \r | |
310 | BootOptionCount++;\r | |
311 | }\r | |
312 | \r | |
c93ab96c | 313 | // Check if a valid boot option(s) is found\r |
a6e97d28 | 314 | if (BootOptionCount == 0) {\r |
c93ab96c | 315 | if (StrCmp (InputStatement, DELETE_BOOT_ENTRY) == 0) {\r |
316 | Print (L"Nothing to remove!\n");\r | |
ecc62d13 | 317 | } else if (StrCmp (InputStatement, UPDATE_BOOT_ENTRY) == 0) {\r |
c93ab96c | 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 | |
a6e97d28 | 323 | return EFI_NOT_FOUND;\r |
324 | }\r | |
325 | \r | |
ea46ebbe | 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 | |
c93ab96c | 333 | } else if ((BootOptionSelected == 0) || (BootOptionSelected > BootOptionCount)) {\r |
334 | Print(L"Invalid input (max %d)\n",BootOptionCount);\r | |
ea46ebbe | 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 | |
ff7666c5 | 342 | !IsNull (BootOptionsList, Entry);\r |
ea46ebbe | 343 | Entry = GetNextNode (BootOptionsList,Entry)\r |
344 | )\r | |
345 | {\r | |
346 | if (Index == BootOptionSelected) {\r | |
a6e97d28 | 347 | *BdsLoadOptionEntry = LOAD_OPTION_ENTRY_FROM_LINK(Entry);\r |
ea46ebbe | 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 | |
a6e97d28 | 361 | EFI_STATUS Status;\r |
362 | BDS_LOAD_OPTION_ENTRY* BootOptionEntry;\r | |
ea46ebbe | 363 | \r |
11c20f4e | 364 | Status = BootMenuSelectBootOption (BootOptionsList, DELETE_BOOT_ENTRY, FALSE, &BootOptionEntry);\r |
ea46ebbe | 365 | if (EFI_ERROR(Status)) {\r |
366 | return Status;\r | |
367 | }\r | |
368 | \r | |
a6e97d28 | 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 | |
ea46ebbe | 375 | // Delete the BDS Load option structures\r |
a6e97d28 | 376 | BootOptionDelete (BootOptionEntry->BdsLoadOption);\r |
ea46ebbe | 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 | |
2ccfb71e | 386 | EFI_STATUS Status;\r |
a6e97d28 | 387 | BDS_LOAD_OPTION_ENTRY *BootOptionEntry;\r |
2ccfb71e | 388 | BDS_LOAD_OPTION *BootOption;\r |
389 | BDS_LOAD_OPTION_SUPPORT* DeviceSupport;\r | |
390 | ARM_BDS_LOADER_ARGUMENTS* BootArguments;\r | |
74b96132 | 391 | CHAR16 BootDescription[BOOT_DEVICE_DESCRIPTION_MAX];\r |
2ccfb71e | 392 | CHAR8 CmdLine[BOOT_DEVICE_OPTION_MAX];\r |
14238a61 | 393 | EFI_DEVICE_PATH *DevicePath;\r |
394 | EFI_DEVICE_PATH *TempInitrdPath;\r | |
2ccfb71e | 395 | ARM_BDS_LOADER_TYPE BootType;\r |
90a44ec4 | 396 | ARM_BDS_LOADER_OPTIONAL_DATA* LoaderOptionalData;\r |
2ccfb71e | 397 | ARM_BDS_LINUX_ARGUMENTS* LinuxArguments;\r |
ecc62d13 | 398 | EFI_DEVICE_PATH *InitrdPathNodes;\r |
22a262c8 | 399 | EFI_DEVICE_PATH *InitrdPath;\r |
2ccfb71e | 400 | UINTN InitrdSize;\r |
401 | UINTN CmdLineSize;\r | |
22a262c8 | 402 | BOOLEAN InitrdSupport;\r |
90a44ec4 OM |
403 | UINT8* OptionalData;\r |
404 | UINTN OptionalDataSize;\r | |
55a9f75d | 405 | BOOLEAN RequestBootType;\r |
ea46ebbe | 406 | \r |
11c20f4e | 407 | Status = BootMenuSelectBootOption (BootOptionsList, UPDATE_BOOT_ENTRY, TRUE, &BootOptionEntry);\r |
ea46ebbe | 408 | if (EFI_ERROR(Status)) {\r |
409 | return Status;\r | |
410 | }\r | |
a6e97d28 | 411 | BootOption = BootOptionEntry->BdsLoadOption;\r |
ea46ebbe | 412 | \r |
413 | // Get the device support for this Boot Option\r | |
22a262c8 | 414 | Status = BootDeviceGetDeviceSupport (BootOption->FilePathList, &DeviceSupport);\r |
ea46ebbe | 415 | if (EFI_ERROR(Status)) {\r |
ff7666c5 | 416 | Print(L"Not possible to retrieve the supported device for the update\n");\r |
ea46ebbe | 417 | return EFI_UNSUPPORTED;\r |
418 | }\r | |
419 | \r | |
55a9f75d OM |
420 | RequestBootType = TRUE;\r |
421 | Status = DeviceSupport->UpdateDevicePathNode (BootOption->FilePathList, L"EFI Application or the kernel", &DevicePath, &RequestBootType);\r | |
ea46ebbe | 422 | if (EFI_ERROR(Status)) {\r |
423 | Status = EFI_ABORTED;\r | |
424 | goto EXIT;\r | |
425 | }\r | |
426 | \r | |
55a9f75d OM |
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 | |
90a44ec4 OM |
435 | LoaderOptionalData = BootOption->OptionalData;\r |
436 | BootType = (ARM_BDS_LOADER_TYPE)ReadUnaligned32 ((UINT32 *)(&LoaderOptionalData->Header.LoaderType));\r | |
656416bc | 437 | \r |
2ccfb71e | 438 | if ((BootType == BDS_LOADER_KERNEL_LINUX_ATAG) || (BootType == BDS_LOADER_KERNEL_LINUX_FDT)) {\r |
90a44ec4 | 439 | LinuxArguments = &LoaderOptionalData->Arguments.LinuxArguments;\r |
2ccfb71e | 440 | \r |
441 | CmdLineSize = ReadUnaligned16 ((CONST UINT16*)&LinuxArguments->CmdLineSize);\r | |
2ccfb71e | 442 | \r |
3e710183 | 443 | InitrdSize = ReadUnaligned16 ((CONST UINT16*)&LinuxArguments->InitrdSize);\r |
444 | if (InitrdSize > 0) {\r | |
22a262c8 | 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 | |
55a9f75d | 458 | Status = DeviceSupport->UpdateDevicePathNode ((EFI_DEVICE_PATH*)((UINTN)(LinuxArguments + 1) + CmdLineSize), L"initrd", &InitrdPath, NULL);\r |
22a262c8 | 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 | |
55a9f75d | 467 | Status = DeviceSupport->CreateDevicePathNode (L"initrd", &InitrdPathNodes, NULL);\r |
22a262c8 | 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 | |
ecc62d13 | 473 | if (InitrdPathNodes != NULL) {\r |
22a262c8 | 474 | // Duplicate Linux kernel Device Path\r |
14238a61 | 475 | TempInitrdPath = DuplicateDevicePath (BootOption->FilePathList);\r |
22a262c8 | 476 | // Replace Linux kernel Node by EndNode\r |
14238a61 | 477 | SetDevicePathEndNode (GetLastDevicePathNode (TempInitrdPath));\r |
ecc62d13 | 478 | // Append the Device Path to the selected device path\r |
479 | InitrdPath = AppendDevicePath (TempInitrdPath, (CONST EFI_DEVICE_PATH_PROTOCOL *)InitrdPathNodes);\r | |
14238a61 | 480 | FreePool (TempInitrdPath);\r |
ecc62d13 | 481 | if (InitrdPath == NULL) {\r |
482 | Status = EFI_OUT_OF_RESOURCES;\r | |
483 | goto EXIT;\r | |
484 | }\r | |
14238a61 | 485 | InitrdSize = GetDevicePathSize (InitrdPath);\r |
22a262c8 | 486 | } else {\r |
487 | InitrdPath = NULL;\r | |
488 | }\r | |
3e710183 | 489 | }\r |
22a262c8 | 490 | } else {\r |
491 | InitrdSize = 0;\r | |
656416bc | 492 | }\r |
493 | \r | |
aeaf64d6 | 494 | Print(L"Arguments to pass to the binary: ");\r |
2ccfb71e | 495 | if (CmdLineSize > 0) {\r |
496 | AsciiStrnCpy(CmdLine, (CONST CHAR8*)(LinuxArguments + 1), CmdLineSize);\r | |
656416bc | 497 | } else {\r |
2ccfb71e | 498 | CmdLine[0] = '\0';\r |
656416bc | 499 | }\r |
2ccfb71e | 500 | Status = EditHIInputAscii (CmdLine, BOOT_DEVICE_OPTION_MAX);\r |
656416bc | 501 | if (EFI_ERROR(Status)) {\r |
502 | Status = EFI_ABORTED;\r | |
503 | goto FREE_DEVICE_PATH;\r | |
504 | }\r | |
2ccfb71e | 505 | \r |
506 | CmdLineSize = AsciiStrSize (CmdLine);\r | |
2ccfb71e | 507 | \r |
90a44ec4 OM |
508 | OptionalDataSize = sizeof(ARM_BDS_LOADER_ARGUMENTS) + CmdLineSize + InitrdSize;\r |
509 | BootArguments = (ARM_BDS_LOADER_ARGUMENTS*)AllocatePool (OptionalDataSize);\r | |
2ccfb71e | 510 | BootArguments->LinuxArguments.CmdLineSize = CmdLineSize;\r |
511 | BootArguments->LinuxArguments.InitrdSize = InitrdSize;\r | |
512 | CopyMem (&BootArguments->LinuxArguments + 1, CmdLine, CmdLineSize);\r | |
49a25d84 | 513 | CopyMem ((VOID*)((UINTN)(&BootArguments->LinuxArguments + 1) + CmdLineSize), InitrdPath, InitrdSize);\r |
90a44ec4 OM |
514 | \r |
515 | OptionalData = (UINT8*)BootArguments;\r | |
2ccfb71e | 516 | } else {\r |
90a44ec4 OM |
517 | OptionalData = NULL;\r |
518 | OptionalDataSize = 0;\r | |
ea46ebbe | 519 | }\r |
520 | \r | |
521 | Print(L"Description for this new Entry: ");\r | |
3e710183 | 522 | StrnCpy (BootDescription, BootOption->Description, BOOT_DEVICE_DESCRIPTION_MAX);\r |
74b96132 | 523 | Status = EditHIInputStr (BootDescription, BOOT_DEVICE_DESCRIPTION_MAX);\r |
ea46ebbe | 524 | if (EFI_ERROR(Status)) {\r |
525 | Status = EFI_ABORTED;\r | |
526 | goto FREE_DEVICE_PATH;\r | |
527 | }\r | |
528 | \r | |
ea46ebbe | 529 | // Update the entry\r |
90a44ec4 | 530 | Status = BootOptionUpdate (BootOption, BootOption->Attributes, BootDescription, DevicePath, BootType, OptionalData, OptionalDataSize);\r |
ea46ebbe | 531 | \r |
ea46ebbe | 532 | FREE_DEVICE_PATH:\r |
533 | FreePool (DevicePath);\r | |
534 | \r | |
535 | EXIT:\r | |
326d1df9 | 536 | if (Status == EFI_ABORTED) {\r |
537 | Print(L"\n");\r | |
538 | }\r | |
ea46ebbe | 539 | return Status;\r |
540 | }\r | |
541 | \r | |
95b3580f | 542 | EFI_STATUS\r |
543 | UpdateFdtPath (\r | |
544 | IN LIST_ENTRY *BootOptionsList\r | |
545 | )\r | |
546 | {\r | |
c0658bd6 | 547 | EFI_STATUS Status;\r |
548 | UINTN FdtDevicePathSize;\r | |
549 | BDS_SUPPORTED_DEVICE *SupportedBootDevice;\r | |
ecc62d13 | 550 | EFI_DEVICE_PATH_PROTOCOL *FdtDevicePathNodes;\r |
c0658bd6 | 551 | EFI_DEVICE_PATH_PROTOCOL *FdtDevicePath;\r |
95b3580f | 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 | |
55a9f75d | 560 | Status = SupportedBootDevice->Support->CreateDevicePathNode (L"FDT blob", &FdtDevicePathNodes, NULL);\r |
95b3580f | 561 | if (EFI_ERROR(Status)) {\r |
562 | Status = EFI_ABORTED;\r | |
563 | goto EXIT;\r | |
564 | }\r | |
565 | \r | |
ecc62d13 | 566 | if (FdtDevicePathNodes != NULL) {\r |
95b3580f | 567 | // Append the Device Path node to the select device path\r |
ecc62d13 | 568 | FdtDevicePath = AppendDevicePath (SupportedBootDevice->DevicePathProtocol, FdtDevicePathNodes);\r |
c0658bd6 | 569 | FdtDevicePathSize = GetDevicePathSize (FdtDevicePath);\r |
aeaf64d6 | 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 | |
95b3580f | 577 | ASSERT_EFI_ERROR(Status);\r |
578 | } else {\r | |
aeaf64d6 | 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 | |
95b3580f | 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 | |
ea46ebbe | 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 | |
95b3580f | 604 | { L"Update FDT path", UpdateFdtPath },\r |
ea46ebbe | 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 | |
326d1df9 | 630 | if (EFI_ERROR(Status)) {\r |
631 | Print(L"\n");\r | |
632 | }\r | |
ea46ebbe | 633 | return EFI_SUCCESS;\r |
634 | } else if ((OptionSelected > 0) && (OptionSelected <= BootManagerEntryCount)) {\r | |
ff7666c5 | 635 | BootManagerEntries[OptionSelected-1].Callback (BootOptionsList);\r |
ea46ebbe | 636 | }\r |
637 | }\r | |
11c20f4e | 638 | // Should never go here\r |
ea46ebbe | 639 | }\r |
640 | \r | |
641 | EFI_STATUS\r | |
8213627e | 642 | BootShell (\r |
ea46ebbe | 643 | IN LIST_ENTRY *BootOptionsList\r |
644 | )\r | |
645 | {\r | |
646 | EFI_STATUS Status;\r | |
647 | \r | |
648 | // Start EFI Shell\r | |
8213627e | 649 | Status = BdsLoadApplication (mImageHandle, L"Shell", 0, NULL);\r |
ea46ebbe | 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 | |
8213627e | 663 | { L"Shell", BootShell },\r |
ea46ebbe | 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 | |
2ccfb71e | 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 | |
ea46ebbe | 682 | \r |
e862cd50 | 683 | BootOption = NULL;\r |
ea46ebbe | 684 | BootMainEntryCount = sizeof(BootMainEntries) / sizeof(struct BOOT_MAIN_ENTRY);\r |
a6caee65 | 685 | \r |
ea46ebbe | 686 | while (TRUE) {\r |
a6e97d28 | 687 | // Get Boot#### list\r |
688 | BootOptionList (&BootOptionsList);\r | |
689 | \r | |
ea46ebbe | 690 | OptionCount = 1;\r |
691 | \r | |
692 | // Display the Boot options\r | |
693 | for (Entry = GetFirstNode (&BootOptionsList);\r | |
694 | !IsNull (&BootOptionsList,Entry);\r | |
695 | Entry = GetNextNode (&BootOptionsList,Entry)\r | |
696 | )\r | |
697 | {\r | |
698 | BootOption = LOAD_OPTION_FROM_LINK(Entry);\r | |
699 | \r | |
ff7666c5 | 700 | Print(L"[%d] %s\n", OptionCount, BootOption->Description);\r |
ea46ebbe | 701 | \r |
702 | DEBUG_CODE_BEGIN();\r | |
703 | CHAR16* DevicePathTxt;\r | |
704 | EFI_DEVICE_PATH_TO_TEXT_PROTOCOL* DevicePathToTextProtocol;\r | |
2ccfb71e | 705 | ARM_BDS_LOADER_OPTIONAL_DATA* OptionalData;\r |
706 | UINTN CmdLineSize;\r | |
3e710183 | 707 | ARM_BDS_LOADER_TYPE LoaderType;\r |
ea46ebbe | 708 | \r |
ff7666c5 | 709 | Status = gBS->LocateProtocol (&gEfiDevicePathToTextProtocolGuid, NULL, (VOID **)&DevicePathToTextProtocol);\r |
aa95e2f7 | 710 | if (EFI_ERROR(Status)) {\r |
711 | // You must provide an implementation of DevicePathToTextProtocol in your firmware (eg: DevicePathDxe)\r | |
712 | DEBUG((EFI_D_ERROR,"Error: Bds requires DevicePathToTextProtocol\n"));\r | |
713 | return Status;\r | |
714 | }\r | |
ff7666c5 | 715 | DevicePathTxt = DevicePathToTextProtocol->ConvertDevicePathToText (BootOption->FilePathList, TRUE, TRUE);\r |
ea46ebbe | 716 | \r |
717 | Print(L"\t- %s\n",DevicePathTxt);\r | |
2ccfb71e | 718 | \r |
719 | // If it is a supported BootEntry then print its details\r | |
720 | if (IS_ARM_BDS_BOOTENTRY (BootOption)) {\r | |
721 | OptionalData = BootOption->OptionalData;\r | |
722 | LoaderType = (ARM_BDS_LOADER_TYPE)ReadUnaligned32 ((CONST UINT32*)&OptionalData->Header.LoaderType);\r | |
723 | if ((LoaderType == BDS_LOADER_KERNEL_LINUX_ATAG) || (LoaderType == BDS_LOADER_KERNEL_LINUX_FDT)) {\r | |
724 | if (ReadUnaligned16 (&OptionalData->Arguments.LinuxArguments.InitrdSize) > 0) {\r | |
725 | CmdLineSize = ReadUnaligned16 (&OptionalData->Arguments.LinuxArguments.CmdLineSize);\r | |
726 | DevicePathTxt = DevicePathToTextProtocol->ConvertDevicePathToText (\r | |
727 | GetAlignedDevicePath ((EFI_DEVICE_PATH*)((UINTN)(&OptionalData->Arguments.LinuxArguments + 1) + CmdLineSize)), TRUE, TRUE);\r | |
728 | Print(L"\t- Initrd: %s\n", DevicePathTxt);\r | |
729 | }\r | |
730 | Print(L"\t- Arguments: %a\n", (&OptionalData->Arguments.LinuxArguments + 1));\r | |
ea46ebbe | 731 | }\r |
7135d76d | 732 | \r |
733 | switch (LoaderType) {\r | |
734 | case BDS_LOADER_EFI_APPLICATION:\r | |
735 | Print(L"\t- LoaderType: EFI Application\n");\r | |
736 | break;\r | |
737 | \r | |
738 | case BDS_LOADER_KERNEL_LINUX_ATAG:\r | |
739 | Print(L"\t- LoaderType: Linux kernel with ATAG support\n");\r | |
740 | break;\r | |
741 | \r | |
742 | case BDS_LOADER_KERNEL_LINUX_FDT:\r | |
743 | Print(L"\t- LoaderType: Linux kernel with FDT support\n");\r | |
744 | break;\r | |
745 | \r | |
746 | default:\r | |
747 | Print(L"\t- LoaderType: Not recognized (%d)\n", LoaderType);\r | |
748 | }\r | |
ea46ebbe | 749 | }\r |
ea46ebbe | 750 | FreePool(DevicePathTxt);\r |
751 | DEBUG_CODE_END();\r | |
752 | \r | |
753 | OptionCount++;\r | |
754 | }\r | |
755 | BootOptionCount = OptionCount-1;\r | |
756 | \r | |
757 | // Display the hardcoded Boot entries\r | |
758 | for (Index = 0; Index < BootMainEntryCount; Index++) {\r | |
759 | Print(L"[%d] %s\n",OptionCount,BootMainEntries[Index]);\r | |
760 | OptionCount++;\r | |
761 | }\r | |
762 | \r | |
763 | // Request the boot entry from the user\r | |
764 | BootOptionSelected = 0;\r | |
765 | while (BootOptionSelected == 0) {\r | |
766 | Print(L"Start: ");\r | |
767 | Status = GetHIInputInteger (&BootOptionSelected);\r | |
768 | if (EFI_ERROR(Status) || (BootOptionSelected == 0) || (BootOptionSelected > OptionCount)) {\r | |
769 | Print(L"Invalid input (max %d)\n",(OptionCount-1));\r | |
770 | BootOptionSelected = 0;\r | |
771 | }\r | |
772 | }\r | |
773 | \r | |
774 | // Start the selected entry\r | |
775 | if (BootOptionSelected > BootOptionCount) {\r | |
776 | // Start the hardcoded entry\r | |
777 | Status = BootMainEntries[BootOptionSelected - BootOptionCount - 1].Callback (&BootOptionsList);\r | |
778 | } else {\r | |
779 | // Find the selected entry from the Boot#### list\r | |
780 | Index = 1;\r | |
781 | for (Entry = GetFirstNode (&BootOptionsList);\r | |
782 | !IsNull (&BootOptionsList,Entry);\r | |
783 | Entry = GetNextNode (&BootOptionsList,Entry)\r | |
784 | )\r | |
785 | {\r | |
786 | if (Index == BootOptionSelected) {\r | |
787 | BootOption = LOAD_OPTION_FROM_LINK(Entry);\r | |
788 | break;\r | |
789 | }\r | |
790 | Index++;\r | |
791 | }\r | |
792 | \r | |
793 | Status = BootOptionStart (BootOption);\r | |
794 | }\r | |
795 | }\r | |
11c20f4e | 796 | // Should never go here\r |
ea46ebbe | 797 | }\r |