]> git.proxmox.com Git - mirror_edk2.git/blob - ArmPlatformPkg/Bds/BootMenu.c
ArmPkg/BdsLib: Move the Generic BDS_LOAD_OPTION structure from Armplatform/Pkg to...
[mirror_edk2.git] / ArmPlatformPkg / Bds / BootMenu.c
1 /** @file
2 *
3 * Copyright (c) 2011, ARM Limited. All rights reserved.
4 *
5 * This program and the accompanying materials
6 * are licensed and made available under the terms and conditions of the BSD License
7 * which accompanies this distribution. The full text of the license may be found at
8 * http://opensource.org/licenses/bsd-license.php
9 *
10 * THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
12 *
13 **/
14
15 #include "BdsInternal.h"
16
17 extern EFI_HANDLE mImageHandle;
18 extern BDS_LOAD_OPTION_SUPPORT *BdsLoadOptionSupportList;
19
20 EFI_STATUS
21 SelectBootDevice (
22 OUT BDS_SUPPORTED_DEVICE** SupportedBootDevice
23 )
24 {
25 EFI_STATUS Status;
26 LIST_ENTRY SupportedDeviceList;
27 UINTN SupportedDeviceCount;
28 LIST_ENTRY* Entry;
29 UINTN SupportedDeviceSelected;
30 UINTN Index;
31
32 //
33 // List the Boot Devices supported
34 //
35
36 // Start all the drivers first
37 BdsConnectAllDrivers ();
38
39 // List the supported devices
40 Status = BootDeviceListSupportedInit (&SupportedDeviceList);
41 ASSERT_EFI_ERROR(Status);
42
43 SupportedDeviceCount = 0;
44 for (Entry = GetFirstNode (&SupportedDeviceList);
45 !IsNull (&SupportedDeviceList,Entry);
46 Entry = GetNextNode (&SupportedDeviceList,Entry)
47 )
48 {
49 *SupportedBootDevice = SUPPORTED_BOOT_DEVICE_FROM_LINK(Entry);
50 Print(L"[%d] %s\n",SupportedDeviceCount+1,(*SupportedBootDevice)->Description);
51
52 DEBUG_CODE_BEGIN();
53 CHAR16* DevicePathTxt;
54 EFI_DEVICE_PATH_TO_TEXT_PROTOCOL* DevicePathToTextProtocol;
55
56 Status = gBS->LocateProtocol(&gEfiDevicePathToTextProtocolGuid, NULL, (VOID **)&DevicePathToTextProtocol);
57 ASSERT_EFI_ERROR(Status);
58 DevicePathTxt = DevicePathToTextProtocol->ConvertDevicePathToText((*SupportedBootDevice)->DevicePathProtocol,TRUE,TRUE);
59
60 Print(L"\t- %s\n",DevicePathTxt);
61
62 FreePool(DevicePathTxt);
63 DEBUG_CODE_END();
64
65 SupportedDeviceCount++;
66 }
67
68 if (SupportedDeviceCount == 0) {
69 Print(L"There is no supported device.\n");
70 Status = EFI_ABORTED;
71 goto EXIT;
72 }
73
74 //
75 // Select the Boot Device
76 //
77 SupportedDeviceSelected = 0;
78 while (SupportedDeviceSelected == 0) {
79 Print(L"Select the Boot Device: ");
80 Status = GetHIInputInteger (&SupportedDeviceSelected);
81 if (EFI_ERROR(Status)) {
82 Status = EFI_ABORTED;
83 goto EXIT;
84 } else if ((SupportedDeviceSelected == 0) || (SupportedDeviceSelected > SupportedDeviceCount)) {
85 Print(L"Invalid input (max %d)\n",SupportedDeviceSelected);
86 SupportedDeviceSelected = 0;
87 }
88 }
89
90 //
91 // Get the Device Path for the selected boot device
92 //
93 Index = 1;
94 for (Entry = GetFirstNode (&SupportedDeviceList);
95 !IsNull (&SupportedDeviceList,Entry);
96 Entry = GetNextNode (&SupportedDeviceList,Entry)
97 )
98 {
99 if (Index == SupportedDeviceSelected) {
100 *SupportedBootDevice = SUPPORTED_BOOT_DEVICE_FROM_LINK(Entry);
101 break;
102 }
103 Index++;
104 }
105
106 EXIT:
107 BootDeviceListSupportedFree (&SupportedDeviceList, *SupportedBootDevice);
108 return Status;
109 }
110
111 EFI_STATUS
112 BootMenuAddBootOption (
113 IN LIST_ENTRY *BootOptionsList
114 )
115 {
116 EFI_STATUS Status;
117 BDS_SUPPORTED_DEVICE* SupportedBootDevice;
118 ARM_BDS_LOADER_ARGUMENTS* BootArguments;
119 CHAR16 BootDescription[BOOT_DEVICE_DESCRIPTION_MAX];
120 CHAR8 CmdLine[BOOT_DEVICE_OPTION_MAX];
121 UINT32 Attributes;
122 ARM_BDS_LOADER_TYPE BootType;
123 BDS_LOAD_OPTION_ENTRY *BdsLoadOptionEntry;
124 EFI_DEVICE_PATH *DevicePath;
125 EFI_DEVICE_PATH_PROTOCOL *DevicePathNode;
126 EFI_DEVICE_PATH_PROTOCOL *InitrdPathNode;
127 EFI_DEVICE_PATH_PROTOCOL *InitrdPath;
128 UINTN CmdLineSize;
129 UINTN InitrdSize;
130
131 Attributes = 0;
132 SupportedBootDevice = NULL;
133
134 // List the Boot Devices supported
135 Status = SelectBootDevice (&SupportedBootDevice);
136 if (EFI_ERROR(Status)) {
137 Status = EFI_ABORTED;
138 goto EXIT;
139 }
140
141 // Create the specific device path node
142 Print(L"File path of the EFI Application or the kernel: ");
143 Status = SupportedBootDevice->Support->CreateDevicePathNode (SupportedBootDevice, &DevicePathNode, &BootType, &Attributes);
144 if (EFI_ERROR(Status)) {
145 Status = EFI_ABORTED;
146 goto EXIT;
147 }
148 // Append the Device Path node to the select device path
149 DevicePath = AppendDevicePathNode (SupportedBootDevice->DevicePathProtocol, (CONST EFI_DEVICE_PATH_PROTOCOL *)DevicePathNode);
150
151 if ((BootType == BDS_LOADER_KERNEL_LINUX_ATAG) || (BootType == BDS_LOADER_KERNEL_LINUX_FDT)) {
152 // Create the specific device path node
153 Print(L"File path of the initrd: ");
154 Status = SupportedBootDevice->Support->CreateDevicePathNode (SupportedBootDevice, &InitrdPathNode, NULL, NULL);
155 if (EFI_ERROR(Status) && Status != EFI_NOT_FOUND) { // EFI_NOT_FOUND is returned on empty input string, but we can boot without an initrd
156 Status = EFI_ABORTED;
157 goto EXIT;
158 }
159
160 if (InitrdPathNode != NULL) {
161 // Append the Device Path node to the select device path
162 InitrdPath = AppendDevicePathNode (SupportedBootDevice->DevicePathProtocol, (CONST EFI_DEVICE_PATH_PROTOCOL *)InitrdPathNode);
163 } else {
164 InitrdPath = NULL;
165 }
166
167 Print(L"Arguments to pass to the binary: ");
168 Status = GetHIInputAscii (CmdLine,BOOT_DEVICE_OPTION_MAX);
169 if (EFI_ERROR(Status)) {
170 Status = EFI_ABORTED;
171 goto FREE_DEVICE_PATH;
172 }
173
174 CmdLineSize = AsciiStrSize (CmdLine);
175 InitrdSize = GetDevicePathSize (InitrdPath);
176
177 BootArguments = (ARM_BDS_LOADER_ARGUMENTS*)AllocatePool (sizeof(ARM_BDS_LOADER_ARGUMENTS) + CmdLineSize + InitrdSize);
178
179 BootArguments->LinuxArguments.CmdLineSize = CmdLineSize;
180 BootArguments->LinuxArguments.InitrdSize = InitrdSize;
181 CopyMem ((VOID*)(&BootArguments->LinuxArguments + 1), CmdLine, CmdLineSize);
182 CopyMem ((VOID*)((UINTN)(&BootArguments->LinuxArguments + 1) + CmdLineSize), InitrdPath, InitrdSize);
183 } else {
184 BootArguments = NULL;
185 }
186
187 Print(L"Description for this new Entry: ");
188 Status = GetHIInputStr (BootDescription, BOOT_DEVICE_DESCRIPTION_MAX);
189 if (EFI_ERROR(Status)) {
190 Status = EFI_ABORTED;
191 goto FREE_DEVICE_PATH;
192 }
193
194 // Create new entry
195 BdsLoadOptionEntry = (BDS_LOAD_OPTION_ENTRY*)AllocatePool (sizeof(BDS_LOAD_OPTION_ENTRY));
196 Status = BootOptionCreate (Attributes, BootDescription, DevicePath, BootType, BootArguments, &BdsLoadOptionEntry->BdsLoadOption);
197 if (!EFI_ERROR(Status)) {
198 InsertTailList (BootOptionsList, &BdsLoadOptionEntry->Link);
199 }
200
201 FREE_DEVICE_PATH:
202 FreePool (DevicePath);
203
204
205 EXIT:
206 if (Status == EFI_ABORTED) {
207 Print(L"\n");
208 }
209 FreePool(SupportedBootDevice);
210 return Status;
211 }
212
213 STATIC
214 EFI_STATUS
215 BootMenuSelectBootOption (
216 IN LIST_ENTRY* BootOptionsList,
217 IN CONST CHAR16* InputStatement,
218 IN BOOLEAN OnlyArmBdsBootEntry,
219 OUT BDS_LOAD_OPTION_ENTRY** BdsLoadOptionEntry
220 )
221 {
222 EFI_STATUS Status;
223 LIST_ENTRY* Entry;
224 BDS_LOAD_OPTION* BdsLoadOption;
225 UINTN BootOptionSelected;
226 UINTN BootOptionCount;
227 UINTN Index;
228
229 // Display the list of supported boot devices
230 BootOptionCount = 1;
231 for (Entry = GetFirstNode (BootOptionsList);
232 !IsNull (BootOptionsList,Entry);
233 Entry = GetNextNode (BootOptionsList, Entry)
234 )
235 {
236 BdsLoadOption = LOAD_OPTION_FROM_LINK(Entry);
237
238 if (OnlyArmBdsBootEntry && !IS_ARM_BDS_BOOTENTRY (BdsLoadOption)) {
239 continue;
240 }
241
242 Print (L"[%d] %s\n", BootOptionCount, BdsLoadOption->Description);
243
244 DEBUG_CODE_BEGIN();
245 CHAR16* DevicePathTxt;
246 EFI_DEVICE_PATH_TO_TEXT_PROTOCOL* DevicePathToTextProtocol;
247 ARM_BDS_LOADER_TYPE LoaderType;
248 ARM_BDS_LOADER_OPTIONAL_DATA* OptionalData;
249
250 Status = gBS->LocateProtocol(&gEfiDevicePathToTextProtocolGuid, NULL, (VOID **)&DevicePathToTextProtocol);
251 ASSERT_EFI_ERROR(Status);
252 DevicePathTxt = DevicePathToTextProtocol->ConvertDevicePathToText(BdsLoadOption->FilePathList,TRUE,TRUE);
253
254 Print(L"\t- %s\n",DevicePathTxt);
255 OptionalData = BdsLoadOption->OptionalData;
256 LoaderType = (ARM_BDS_LOADER_TYPE)ReadUnaligned32 ((CONST UINT32*)&OptionalData->Header.LoaderType);
257 if ((LoaderType == BDS_LOADER_KERNEL_LINUX_ATAG) || (LoaderType == BDS_LOADER_KERNEL_LINUX_FDT)) {
258 Print (L"\t- Arguments: %a\n",&OptionalData->Arguments.LinuxArguments + 1);
259 }
260
261 FreePool(DevicePathTxt);
262 DEBUG_CODE_END();
263
264 BootOptionCount++;
265 }
266
267 if (BootOptionCount == 0) {
268 Print (L"No supported Boot Entry.\n");
269 return EFI_NOT_FOUND;
270 }
271
272 // Get the index of the boot device to delete
273 BootOptionSelected = 0;
274 while (BootOptionSelected == 0) {
275 Print(InputStatement);
276 Status = GetHIInputInteger (&BootOptionSelected);
277 if (EFI_ERROR(Status)) {
278 return Status;
279 } else if ((BootOptionSelected == 0) || (BootOptionSelected >= BootOptionCount)) {
280 Print(L"Invalid input (max %d)\n",BootOptionCount-1);
281 BootOptionSelected = 0;
282 }
283 }
284
285 // Get the structure of the Boot device to delete
286 Index = 1;
287 for (Entry = GetFirstNode (BootOptionsList);
288 !IsNull (BootOptionsList,Entry);
289 Entry = GetNextNode (BootOptionsList,Entry)
290 )
291 {
292 if (Index == BootOptionSelected) {
293 *BdsLoadOptionEntry = LOAD_OPTION_ENTRY_FROM_LINK(Entry);
294 break;
295 }
296 Index++;
297 }
298
299 return EFI_SUCCESS;
300 }
301
302 EFI_STATUS
303 BootMenuRemoveBootOption (
304 IN LIST_ENTRY *BootOptionsList
305 )
306 {
307 EFI_STATUS Status;
308 BDS_LOAD_OPTION_ENTRY* BootOptionEntry;
309
310 Status = BootMenuSelectBootOption (BootOptionsList, L"Delete entry: ", FALSE, &BootOptionEntry);
311 if (EFI_ERROR(Status)) {
312 return Status;
313 }
314
315 // If the Boot Option was attached to a list remove it
316 if (!IsListEmpty (&BootOptionEntry->Link)) {
317 // Remove the entry from the list
318 RemoveEntryList (&BootOptionEntry->Link);
319 }
320
321 // Delete the BDS Load option structures
322 BootOptionDelete (BootOptionEntry->BdsLoadOption);
323
324 return EFI_SUCCESS;
325 }
326
327 EFI_STATUS
328 BootMenuUpdateBootOption (
329 IN LIST_ENTRY *BootOptionsList
330 )
331 {
332 EFI_STATUS Status;
333 BDS_LOAD_OPTION_ENTRY *BootOptionEntry;
334 BDS_LOAD_OPTION *BootOption;
335 BDS_LOAD_OPTION_SUPPORT* DeviceSupport;
336 ARM_BDS_LOADER_ARGUMENTS* BootArguments;
337 CHAR16 BootDescription[BOOT_DEVICE_DESCRIPTION_MAX];
338 CHAR8 CmdLine[BOOT_DEVICE_OPTION_MAX];
339 EFI_DEVICE_PATH* DevicePath;
340 ARM_BDS_LOADER_TYPE BootType;
341 ARM_BDS_LOADER_OPTIONAL_DATA* OptionalData;
342 ARM_BDS_LINUX_ARGUMENTS* LinuxArguments;
343 EFI_DEVICE_PATH* InitrdPathList;
344 UINTN InitrdSize;
345 UINTN CmdLineSize;
346
347 Status = BootMenuSelectBootOption (BootOptionsList, L"Update entry: ", TRUE, &BootOptionEntry);
348 if (EFI_ERROR(Status)) {
349 return Status;
350 }
351 BootOption = BootOptionEntry->BdsLoadOption;
352
353 // Get the device support for this Boot Option
354 Status = BootDeviceGetDeviceSupport (BootOption,&DeviceSupport);
355 if (EFI_ERROR(Status)) {
356 Print(L"Impossible to retrieve the supported device for the update\n");
357 return EFI_UNSUPPORTED;
358 }
359
360 Print(L"File path of the EFI Application or the kernel: ");
361 Status = DeviceSupport->UpdateDevicePathNode (BootOption->FilePathList, &DevicePath, NULL, NULL);
362 if (EFI_ERROR(Status)) {
363 Status = EFI_ABORTED;
364 goto EXIT;
365 }
366
367 OptionalData = BootOption->OptionalData;
368 BootType = (ARM_BDS_LOADER_TYPE)ReadUnaligned32 ((UINT32 *)(&OptionalData->Header.LoaderType));
369
370 // TODO: Allow adding an initrd to a boot entry without one
371 if ((BootType == BDS_LOADER_KERNEL_LINUX_ATAG) || (BootType == BDS_LOADER_KERNEL_LINUX_FDT)) {
372 LinuxArguments = &OptionalData->Arguments.LinuxArguments;
373
374 CmdLineSize = ReadUnaligned16 ((CONST UINT16*)&LinuxArguments->CmdLineSize);
375 InitrdSize = GetUnalignedDevicePathSize ((EFI_DEVICE_PATH*)((LinuxArguments + 1) + CmdLineSize));
376
377 Print(L"File path of the initrd: ");
378 Status = DeviceSupport->UpdateDevicePathNode (
379 (EFI_DEVICE_PATH_PROTOCOL *)((UINTN)(LinuxArguments + 1) + CmdLineSize), &InitrdPathList, NULL, NULL);
380 if (EFI_ERROR(Status) && Status != EFI_NOT_FOUND) {// EFI_NOT_FOUND is returned on empty input string, but we can boot without an initrd
381 Status = EFI_ABORTED;
382 goto EXIT;
383 }
384
385 Print(L"Arguments to pass to the binary: ");
386 if (CmdLineSize > 0) {
387 AsciiStrnCpy(CmdLine, (CONST CHAR8*)(LinuxArguments + 1), CmdLineSize);
388 } else {
389 CmdLine[0] = '\0';
390 }
391 Status = EditHIInputAscii (CmdLine, BOOT_DEVICE_OPTION_MAX);
392 if (EFI_ERROR(Status)) {
393 Status = EFI_ABORTED;
394 goto FREE_DEVICE_PATH;
395 }
396
397 CmdLineSize = AsciiStrSize (CmdLine);
398 InitrdSize = GetDevicePathSize (InitrdPathList);
399
400 BootArguments = (ARM_BDS_LOADER_ARGUMENTS*)AllocatePool(sizeof(ARM_BDS_LOADER_ARGUMENTS) + CmdLineSize + InitrdSize);
401 BootArguments->LinuxArguments.CmdLineSize = CmdLineSize;
402 BootArguments->LinuxArguments.InitrdSize = InitrdSize;
403 CopyMem (&BootArguments->LinuxArguments + 1, CmdLine, CmdLineSize);
404 CopyMem ((UINTN)(&BootArguments->LinuxArguments + 1) + CmdLine, InitrdPathList, InitrdSize);
405 } else {
406 BootArguments = NULL;
407 }
408
409 Print(L"Description for this new Entry: ");
410 Status = EditHIInputStr (BootDescription, BOOT_DEVICE_DESCRIPTION_MAX);
411 if (EFI_ERROR(Status)) {
412 Status = EFI_ABORTED;
413 goto FREE_DEVICE_PATH;
414 }
415
416 // Update the entry
417 Status = BootOptionUpdate (BootOption, BootOption->Attributes, BootDescription, DevicePath, BootType, BootArguments);
418
419 FREE_DEVICE_PATH:
420 FreePool (DevicePath);
421
422 EXIT:
423 if (Status == EFI_ABORTED) {
424 Print(L"\n");
425 }
426 return Status;
427 }
428
429 struct BOOT_MANAGER_ENTRY {
430 CONST CHAR16* Description;
431 EFI_STATUS (*Callback) (IN LIST_ENTRY *BootOptionsList);
432 } BootManagerEntries[] = {
433 { L"Add Boot Device Entry", BootMenuAddBootOption },
434 { L"Update Boot Device Entry", BootMenuUpdateBootOption },
435 { L"Remove Boot Device Entry", BootMenuRemoveBootOption },
436 };
437
438 EFI_STATUS
439 BootMenuManager (
440 IN LIST_ENTRY *BootOptionsList
441 )
442 {
443 UINTN Index;
444 UINTN OptionSelected;
445 UINTN BootManagerEntryCount;
446 EFI_STATUS Status;
447
448 BootManagerEntryCount = sizeof(BootManagerEntries) / sizeof(struct BOOT_MANAGER_ENTRY);
449
450 while (TRUE) {
451 // Display Boot Manager menu
452 for (Index = 0; Index < BootManagerEntryCount; Index++) {
453 Print(L"[%d] %s\n",Index+1,BootManagerEntries[Index]);
454 }
455 Print(L"[%d] Return to main menu\n",Index+1);
456
457 // Select which entry to call
458 Print(L"Choice: ");
459 Status = GetHIInputInteger (&OptionSelected);
460 if (EFI_ERROR(Status) || (OptionSelected == (BootManagerEntryCount+1))) {
461 if (EFI_ERROR(Status)) {
462 Print(L"\n");
463 }
464 return EFI_SUCCESS;
465 } else if ((OptionSelected > 0) && (OptionSelected <= BootManagerEntryCount)) {
466 Status = BootManagerEntries[OptionSelected-1].Callback (BootOptionsList);
467 }
468 }
469
470 return EFI_SUCCESS;
471 }
472
473 EFI_STATUS
474 BootEBL (
475 IN LIST_ENTRY *BootOptionsList
476 )
477 {
478 EFI_STATUS Status;
479
480 // Start EFI Shell
481 Status = BdsLoadApplication(mImageHandle, L"Ebl");
482 if (Status == EFI_NOT_FOUND) {
483 Print (L"Error: EFI Application not found.\n");
484 } else if (EFI_ERROR(Status)) {
485 Print (L"Error: Status Code: 0x%X\n",(UINT32)Status);
486 }
487
488 return Status;
489 }
490
491 struct BOOT_MAIN_ENTRY {
492 CONST CHAR16* Description;
493 EFI_STATUS (*Callback) (IN LIST_ENTRY *BootOptionsList);
494 } BootMainEntries[] = {
495 { L"EBL", BootEBL },
496 { L"Boot Manager", BootMenuManager },
497 };
498
499
500 EFI_STATUS
501 BootMenuMain (
502 VOID
503 )
504 {
505 LIST_ENTRY BootOptionsList;
506 UINTN OptionCount;
507 UINTN BootOptionCount;
508 EFI_STATUS Status;
509 LIST_ENTRY* Entry;
510 BDS_LOAD_OPTION* BootOption;
511 UINTN BootOptionSelected;
512 UINTN Index;
513 UINTN BootMainEntryCount;
514
515 BootOption = NULL;
516 BootMainEntryCount = sizeof(BootMainEntries) / sizeof(struct BOOT_MAIN_ENTRY);
517
518 while (TRUE) {
519 // Get Boot#### list
520 BootOptionList (&BootOptionsList);
521
522 OptionCount = 1;
523
524 // Display the Boot options
525 for (Entry = GetFirstNode (&BootOptionsList);
526 !IsNull (&BootOptionsList,Entry);
527 Entry = GetNextNode (&BootOptionsList,Entry)
528 )
529 {
530 BootOption = LOAD_OPTION_FROM_LINK(Entry);
531
532 Print(L"[%d] %s\n",OptionCount,BootOption->Description);
533
534 DEBUG_CODE_BEGIN();
535 CHAR16* DevicePathTxt;
536 EFI_DEVICE_PATH_TO_TEXT_PROTOCOL* DevicePathToTextProtocol;
537 ARM_BDS_LOADER_OPTIONAL_DATA* OptionalData;
538 UINTN CmdLineSize;
539 ARM_BDS_LOADER_TYPE LoaderType;
540
541 Status = gBS->LocateProtocol(&gEfiDevicePathToTextProtocolGuid, NULL, (VOID **)&DevicePathToTextProtocol);
542 if (EFI_ERROR(Status)) {
543 // You must provide an implementation of DevicePathToTextProtocol in your firmware (eg: DevicePathDxe)
544 DEBUG((EFI_D_ERROR,"Error: Bds requires DevicePathToTextProtocol\n"));
545 return Status;
546 }
547 DevicePathTxt = DevicePathToTextProtocol->ConvertDevicePathToText(BootOption->FilePathList,TRUE,TRUE);
548
549 Print(L"\t- %s\n",DevicePathTxt);
550
551 // If it is a supported BootEntry then print its details
552 if (IS_ARM_BDS_BOOTENTRY (BootOption)) {
553 OptionalData = BootOption->OptionalData;
554 LoaderType = (ARM_BDS_LOADER_TYPE)ReadUnaligned32 ((CONST UINT32*)&OptionalData->Header.LoaderType);
555 if ((LoaderType == BDS_LOADER_KERNEL_LINUX_ATAG) || (LoaderType == BDS_LOADER_KERNEL_LINUX_FDT)) {
556 if (ReadUnaligned16 (&OptionalData->Arguments.LinuxArguments.InitrdSize) > 0) {
557 CmdLineSize = ReadUnaligned16 (&OptionalData->Arguments.LinuxArguments.CmdLineSize);
558 DevicePathTxt = DevicePathToTextProtocol->ConvertDevicePathToText (
559 GetAlignedDevicePath ((EFI_DEVICE_PATH*)((UINTN)(&OptionalData->Arguments.LinuxArguments + 1) + CmdLineSize)), TRUE, TRUE);
560 Print(L"\t- Initrd: %s\n", DevicePathTxt);
561 }
562 Print(L"\t- Arguments: %a\n", (&OptionalData->Arguments.LinuxArguments + 1));
563 }
564 Print(L"\t- LoaderType: %d\n", LoaderType);
565 }
566 FreePool(DevicePathTxt);
567 DEBUG_CODE_END();
568
569 OptionCount++;
570 }
571 BootOptionCount = OptionCount-1;
572
573 // Display the hardcoded Boot entries
574 for (Index = 0; Index < BootMainEntryCount; Index++) {
575 Print(L"[%d] %s\n",OptionCount,BootMainEntries[Index]);
576 OptionCount++;
577 }
578
579 // Request the boot entry from the user
580 BootOptionSelected = 0;
581 while (BootOptionSelected == 0) {
582 Print(L"Start: ");
583 Status = GetHIInputInteger (&BootOptionSelected);
584 if (EFI_ERROR(Status) || (BootOptionSelected == 0) || (BootOptionSelected > OptionCount)) {
585 Print(L"Invalid input (max %d)\n",(OptionCount-1));
586 BootOptionSelected = 0;
587 }
588 }
589
590 // Start the selected entry
591 if (BootOptionSelected > BootOptionCount) {
592 // Start the hardcoded entry
593 Status = BootMainEntries[BootOptionSelected - BootOptionCount - 1].Callback (&BootOptionsList);
594 } else {
595 // Find the selected entry from the Boot#### list
596 Index = 1;
597 for (Entry = GetFirstNode (&BootOptionsList);
598 !IsNull (&BootOptionsList,Entry);
599 Entry = GetNextNode (&BootOptionsList,Entry)
600 )
601 {
602 if (Index == BootOptionSelected) {
603 BootOption = LOAD_OPTION_FROM_LINK(Entry);
604 break;
605 }
606 Index++;
607 }
608
609 Status = BootOptionStart (BootOption);
610 }
611 }
612
613 return Status;
614 }