]> git.proxmox.com Git - mirror_edk2.git/blob - IntelFrameworkModulePkg/Library/GenericBdsLib/BdsBoot.c
Use default boot file name from UefiSpec.h and retired related PCDs
[mirror_edk2.git] / IntelFrameworkModulePkg / Library / GenericBdsLib / BdsBoot.c
1 /** @file
2 BDS Lib functions which relate with create or process the boot option.
3
4 Copyright (c) 2004 - 2008, Intel Corporation. <BR>
5 All rights reserved. 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 "InternalBdsLib.h"
16
17 BOOLEAN mEnumBootDevice = FALSE;
18
19 ///
20 /// This GUID is used for an EFI Variable that stores the front device pathes
21 /// for a partial device path that starts with the HD node.
22 ///
23 EFI_GUID mHdBootVariablePrivateGuid = { 0xfab7e9e1, 0x39dd, 0x4f2b, { 0x84, 0x8, 0xe2, 0xe, 0x90, 0x6c, 0xb6, 0xde } };
24
25
26
27 /**
28 Boot the legacy system with the boot option
29
30 @param Option The legacy boot option which have BBS device path
31
32 @retval EFI_UNSUPPORTED There is no legacybios protocol, do not support
33 legacy boot.
34 @retval EFI_STATUS Return the status of LegacyBios->LegacyBoot ().
35
36 **/
37 EFI_STATUS
38 BdsLibDoLegacyBoot (
39 IN BDS_COMMON_OPTION *Option
40 )
41 {
42 EFI_STATUS Status;
43 EFI_LEGACY_BIOS_PROTOCOL *LegacyBios;
44
45 Status = gBS->LocateProtocol (&gEfiLegacyBiosProtocolGuid, NULL, (VOID **) &LegacyBios);
46 if (EFI_ERROR (Status)) {
47 //
48 // If no LegacyBios protocol we do not support legacy boot
49 //
50 return EFI_UNSUPPORTED;
51 }
52 //
53 // Notes: if we separate the int 19, then we don't need to refresh BBS
54 //
55 BdsRefreshBbsTableForBoot (Option);
56
57 //
58 // Write boot to OS performance data to a file
59 //
60 PERF_CODE (
61 WriteBootToOsPerformanceData ();
62 );
63
64 DEBUG ((DEBUG_INFO | DEBUG_LOAD, "Legacy Boot: %S\n", Option->Description));
65 return LegacyBios->LegacyBoot (
66 LegacyBios,
67 (BBS_BBS_DEVICE_PATH *) Option->DevicePath,
68 Option->LoadOptionsSize,
69 Option->LoadOptions
70 );
71 }
72
73 /**
74 Internal function to check if the input boot option is a valid EFI NV Boot####.
75
76 @param OptionToCheck Boot option to be checked.
77
78 @retval TRUE This boot option matches a valid EFI NV Boot####.
79 @retval FALSE If not.
80
81 **/
82
83 BOOLEAN
84 IsBootOptionValidNVVarialbe (
85 IN BDS_COMMON_OPTION *OptionToCheck
86 )
87 {
88 LIST_ENTRY TempList;
89 BDS_COMMON_OPTION *BootOption;
90 BOOLEAN Valid;
91 CHAR16 OptionName[20];
92
93 Valid = FALSE;
94
95 InitializeListHead (&TempList);
96 UnicodeSPrint (OptionName, sizeof (OptionName), L"Boot%04x", OptionToCheck->BootCurrent);
97
98 BootOption = BdsLibVariableToOption (&TempList, OptionName);
99 if (BootOption == NULL) {
100 return FALSE;
101 }
102
103 //
104 // If the Boot Option Number and Device Path matches, OptionToCheck matches a
105 // valid EFI NV Boot####.
106 //
107 if ((OptionToCheck->BootCurrent == BootOption->BootCurrent) &&
108 (CompareMem (OptionToCheck->DevicePath, BootOption->DevicePath, GetDevicePathSize (OptionToCheck->DevicePath)) == 0))
109 {
110 Valid = TRUE;
111 }
112
113 FreePool (BootOption);
114
115 return Valid;
116 }
117 /**
118 Process the boot option follow the UEFI specification and
119 special treat the legacy boot option with BBS_DEVICE_PATH.
120
121 @param Option The boot option need to be processed
122 @param DevicePath The device path which describe where to load the
123 boot image or the legacy BBS device path to boot
124 the legacy OS
125 @param ExitDataSize The size of exit data.
126 @param ExitData Data returned when Boot image failed.
127
128 @retval EFI_SUCCESS Boot from the input boot option successfully.
129 @retval EFI_NOT_FOUND If the Device Path is not found in the system
130
131 **/
132 EFI_STATUS
133 EFIAPI
134 BdsLibBootViaBootOption (
135 IN BDS_COMMON_OPTION *Option,
136 IN EFI_DEVICE_PATH_PROTOCOL *DevicePath,
137 OUT UINTN *ExitDataSize,
138 OUT CHAR16 **ExitData OPTIONAL
139 )
140 {
141 EFI_STATUS Status;
142 EFI_HANDLE Handle;
143 EFI_HANDLE ImageHandle;
144 EFI_DEVICE_PATH_PROTOCOL *FilePath;
145 EFI_LOADED_IMAGE_PROTOCOL *ImageInfo;
146 EFI_DEVICE_PATH_PROTOCOL *WorkingDevicePath;
147 EFI_ACPI_S3_SAVE_PROTOCOL *AcpiS3Save;
148 LIST_ENTRY TempBootLists;
149
150 //
151 // Record the performance data for End of BDS
152 //
153 PERF_END (0, "BDS", NULL, 0);
154
155 *ExitDataSize = 0;
156 *ExitData = NULL;
157
158 //
159 // Notes: put EFI64 ROM Shadow Solution
160 //
161 EFI64_SHADOW_ALL_LEGACY_ROM ();
162
163 //
164 // Notes: this code can be remove after the s3 script table
165 // hook on the event EVT_SIGNAL_READY_TO_BOOT or
166 // EVT_SIGNAL_LEGACY_BOOT
167 //
168 Status = gBS->LocateProtocol (&gEfiAcpiS3SaveProtocolGuid, NULL, (VOID **) &AcpiS3Save);
169 if (!EFI_ERROR (Status)) {
170 AcpiS3Save->S3Save (AcpiS3Save, NULL);
171 }
172 //
173 // If it's Device Path that starts with a hard drive path, append it with the front part to compose a
174 // full device path
175 //
176 WorkingDevicePath = NULL;
177 if ((DevicePathType (DevicePath) == MEDIA_DEVICE_PATH) &&
178 (DevicePathSubType (DevicePath) == MEDIA_HARDDRIVE_DP)) {
179 WorkingDevicePath = BdsExpandPartitionPartialDevicePathToFull (
180 (HARDDRIVE_DEVICE_PATH *)DevicePath
181 );
182 if (WorkingDevicePath != NULL) {
183 DevicePath = WorkingDevicePath;
184 }
185 }
186 //
187 // Signal the EVT_SIGNAL_READY_TO_BOOT event
188 //
189 EfiSignalEventReadyToBoot();
190
191
192 //
193 // Set Boot Current
194 //
195 if (IsBootOptionValidNVVarialbe (Option)) {
196 //
197 // For a temporary boot (i.e. a boot by selected a EFI Shell using "Boot From File"), Boot Current is actually not valid.
198 // In this case, "BootCurrent" is not created.
199 // Only create the BootCurrent variable when it points to a valid Boot#### variable.
200 //
201 gRT->SetVariable (
202 L"BootCurrent",
203 &gEfiGlobalVariableGuid,
204 EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS,
205 sizeof (UINT16),
206 &Option->BootCurrent
207 );
208 }
209
210 ASSERT (Option->DevicePath != NULL);
211 if ((DevicePathType (Option->DevicePath) == BBS_DEVICE_PATH) &&
212 (DevicePathSubType (Option->DevicePath) == BBS_BBS_DP)
213 ) {
214 //
215 // Check to see if we should legacy BOOT. If yes then do the legacy boot
216 //
217 return BdsLibDoLegacyBoot (Option);
218 }
219
220 //
221 // If the boot option point to Internal FV shell, make sure it is valid
222 //
223 Status = BdsLibUpdateFvFileDevicePath (&DevicePath, &gEfiShellFileGuid);
224 if (!EFI_ERROR(Status)) {
225 if (Option->DevicePath != NULL) {
226 FreePool(Option->DevicePath);
227 }
228 Option->DevicePath = AllocateZeroPool (GetDevicePathSize (DevicePath));
229 ASSERT(Option->DevicePath != NULL);
230 CopyMem (Option->DevicePath, DevicePath, GetDevicePathSize (DevicePath));
231 //
232 // Update the shell boot option
233 //
234 InitializeListHead (&TempBootLists);
235 BdsLibRegisterNewOption (&TempBootLists, DevicePath, L"EFI Internal Shell", L"BootOrder");
236
237 //
238 // free the temporary device path created by BdsLibUpdateFvFileDevicePath()
239 //
240 FreePool (DevicePath);
241 DevicePath = Option->DevicePath;
242 }
243
244 DEBUG ((DEBUG_INFO | DEBUG_LOAD, "Booting %S\n", Option->Description));
245
246 Status = gBS->LoadImage (
247 TRUE,
248 mBdsImageHandle,
249 DevicePath,
250 NULL,
251 0,
252 &ImageHandle
253 );
254
255 //
256 // If we didn't find an image directly, we need to try as if it is a removable device boot opotion
257 // and load the image according to the default boot behavior for removable device.
258 //
259 if (EFI_ERROR (Status)) {
260 //
261 // check if there is a bootable removable media could be found in this device path ,
262 // and get the bootable media handle
263 //
264 Handle = BdsLibGetBootableHandle(DevicePath);
265 if (Handle == NULL) {
266 goto Done;
267 }
268 //
269 // Load the default boot file \EFI\BOOT\boot{machinename}.EFI from removable Media
270 // machinename is ia32, ia64, x64, ...
271 //
272 FilePath = FileDevicePath (Handle, EFI_REMOVABLE_MEDIA_FILE_NAME);
273 if (FilePath != NULL) {
274 Status = gBS->LoadImage (
275 TRUE,
276 mBdsImageHandle,
277 FilePath,
278 NULL,
279 0,
280 &ImageHandle
281 );
282 if (EFI_ERROR (Status)) {
283 //
284 // The DevicePath failed, and it's not a valid
285 // removable media device.
286 //
287 goto Done;
288 }
289 }
290 }
291
292 if (EFI_ERROR (Status)) {
293 //
294 // It there is any error from the Boot attempt exit now.
295 //
296 goto Done;
297 }
298 //
299 // Provide the image with it's load options
300 //
301 Status = gBS->HandleProtocol (ImageHandle, &gEfiLoadedImageProtocolGuid, (VOID **) &ImageInfo);
302 ASSERT_EFI_ERROR (Status);
303
304 if (Option->LoadOptionsSize != 0) {
305 ImageInfo->LoadOptionsSize = Option->LoadOptionsSize;
306 ImageInfo->LoadOptions = Option->LoadOptions;
307 }
308 //
309 // Before calling the image, enable the Watchdog Timer for
310 // the 5 Minute period
311 //
312 gBS->SetWatchdogTimer (5 * 60, 0x0000, 0x00, NULL);
313
314 Status = gBS->StartImage (ImageHandle, ExitDataSize, ExitData);
315 DEBUG ((DEBUG_INFO | DEBUG_LOAD, "Image Return Status = %r\n", Status));
316
317 //
318 // Clear the Watchdog Timer after the image returns
319 //
320 gBS->SetWatchdogTimer (0x0000, 0x0000, 0x0000, NULL);
321
322 Done:
323 //
324 // Clear Boot Current
325 //
326 gRT->SetVariable (
327 L"BootCurrent",
328 &gEfiGlobalVariableGuid,
329 EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS,
330 0,
331 &Option->BootCurrent
332 );
333
334 return Status;
335 }
336
337
338 /**
339 Expand a device path that starts with a hard drive media device path node to be a
340 full device path that includes the full hardware path to the device. We need
341 to do this so it can be booted. As an optimization the front match (the part point
342 to the partition node. E.g. ACPI() /PCI()/ATA()/Partition() ) is saved in a variable
343 so a connect all is not required on every boot. All successful history device path
344 which point to partition node (the front part) will be saved.
345
346 @param HardDriveDevicePath EFI Device Path to boot, if it starts with a hard
347 drive media device path.
348 @return A Pointer to the full device path or NULL if a valid Hard Drive devic path
349 cannot be found.
350
351 **/
352 EFI_DEVICE_PATH_PROTOCOL *
353 EFIAPI
354 BdsExpandPartitionPartialDevicePathToFull (
355 IN HARDDRIVE_DEVICE_PATH *HardDriveDevicePath
356 )
357 {
358 EFI_STATUS Status;
359 UINTN BlockIoHandleCount;
360 EFI_HANDLE *BlockIoBuffer;
361 EFI_DEVICE_PATH_PROTOCOL *FullDevicePath;
362 EFI_DEVICE_PATH_PROTOCOL *BlockIoDevicePath;
363 EFI_DEVICE_PATH_PROTOCOL *DevicePath;
364 UINTN Index;
365 UINTN InstanceNum;
366 EFI_DEVICE_PATH_PROTOCOL *CachedDevicePath;
367 EFI_DEVICE_PATH_PROTOCOL *TempNewDevicePath;
368 UINTN CachedDevicePathSize;
369 BOOLEAN DeviceExist;
370 BOOLEAN NeedAdjust;
371 EFI_DEVICE_PATH_PROTOCOL *Instance;
372 UINTN Size;
373
374 FullDevicePath = NULL;
375 //
376 // Check if there is prestore 'HDDP' variable.
377 // If exist, search the front path which point to partition node in the variable instants.
378 // If fail to find or 'HDDP' not exist, reconnect all and search in all system
379 //
380 CachedDevicePath = BdsLibGetVariableAndSize (
381 L"HDDP",
382 &mHdBootVariablePrivateGuid,
383 &CachedDevicePathSize
384 );
385
386 if (CachedDevicePath != NULL) {
387 TempNewDevicePath = CachedDevicePath;
388 DeviceExist = FALSE;
389 NeedAdjust = FALSE;
390 do {
391 //
392 // Check every instance of the variable
393 // First, check whether the instance contain the partition node, which is needed for distinguishing multi
394 // partial partition boot option. Second, check whether the instance could be connected.
395 //
396 Instance = GetNextDevicePathInstance (&TempNewDevicePath, &Size);
397 if (MatchPartitionDevicePathNode (Instance, HardDriveDevicePath)) {
398 //
399 // Connect the device path instance, the device path point to hard drive media device path node
400 // e.g. ACPI() /PCI()/ATA()/Partition()
401 //
402 Status = BdsLibConnectDevicePath (Instance);
403 if (!EFI_ERROR (Status)) {
404 DeviceExist = TRUE;
405 break;
406 }
407 }
408 //
409 // Come here means the first instance is not matched
410 //
411 NeedAdjust = TRUE;
412 FreePool(Instance);
413 } while (TempNewDevicePath != NULL);
414
415 if (DeviceExist) {
416 //
417 // Find the matched device path.
418 // Append the file path information from the boot option and return the fully expanded device path.
419 //
420 DevicePath = NextDevicePathNode ((EFI_DEVICE_PATH_PROTOCOL *) HardDriveDevicePath);
421 FullDevicePath = AppendDevicePath (Instance, DevicePath);
422
423 //
424 // Adjust the 'HDDP' instances sequence if the matched one is not first one.
425 //
426 if (NeedAdjust) {
427 //
428 // First delete the matched instance.
429 //
430 TempNewDevicePath = CachedDevicePath;
431 CachedDevicePath = BdsLibDelPartMatchInstance (CachedDevicePath, Instance );
432 FreePool (TempNewDevicePath);
433
434 //
435 // Second, append the remaining path after the matched instance
436 //
437 TempNewDevicePath = CachedDevicePath;
438 CachedDevicePath = AppendDevicePathInstance (Instance, CachedDevicePath );
439 FreePool (TempNewDevicePath);
440 //
441 // Save the matching Device Path so we don't need to do a connect all next time
442 //
443 Status = gRT->SetVariable (
444 L"HDDP",
445 &mHdBootVariablePrivateGuid,
446 EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE,
447 GetDevicePathSize (CachedDevicePath),
448 CachedDevicePath
449 );
450 }
451
452 FreePool (Instance);
453 FreePool (CachedDevicePath);
454 return FullDevicePath;
455 }
456 }
457
458 //
459 // If we get here we fail to find or 'HDDP' not exist, and now we need
460 // to search all devices in the system for a matched partition
461 //
462 BdsLibConnectAllDriversToAllControllers ();
463 Status = gBS->LocateHandleBuffer (ByProtocol, &gEfiBlockIoProtocolGuid, NULL, &BlockIoHandleCount, &BlockIoBuffer);
464 if (EFI_ERROR (Status) || BlockIoHandleCount == 0 || BlockIoBuffer == NULL) {
465 //
466 // If there was an error or there are no device handles that support
467 // the BLOCK_IO Protocol, then return.
468 //
469 return NULL;
470 }
471 //
472 // Loop through all the device handles that support the BLOCK_IO Protocol
473 //
474 for (Index = 0; Index < BlockIoHandleCount; Index++) {
475
476 Status = gBS->HandleProtocol (BlockIoBuffer[Index], &gEfiDevicePathProtocolGuid, (VOID *) &BlockIoDevicePath);
477 if (EFI_ERROR (Status) || BlockIoDevicePath == NULL) {
478 continue;
479 }
480
481 if (MatchPartitionDevicePathNode (BlockIoDevicePath, HardDriveDevicePath)) {
482 //
483 // Find the matched partition device path
484 //
485 DevicePath = NextDevicePathNode ((EFI_DEVICE_PATH_PROTOCOL *) HardDriveDevicePath);
486 FullDevicePath = AppendDevicePath (BlockIoDevicePath, DevicePath);
487
488 //
489 // Save the matched partition device path in 'HDDP' variable
490 //
491 if (CachedDevicePath != NULL) {
492 //
493 // Save the matched partition device path as first instance of 'HDDP' variable
494 //
495 if (BdsLibMatchDevicePaths (CachedDevicePath, BlockIoDevicePath)) {
496 TempNewDevicePath = CachedDevicePath;
497 CachedDevicePath = BdsLibDelPartMatchInstance (CachedDevicePath, BlockIoDevicePath);
498 FreePool(TempNewDevicePath);
499
500 TempNewDevicePath = CachedDevicePath;
501 CachedDevicePath = AppendDevicePathInstance (BlockIoDevicePath, CachedDevicePath);
502 FreePool(TempNewDevicePath);
503 } else {
504 TempNewDevicePath = CachedDevicePath;
505 CachedDevicePath = AppendDevicePathInstance (BlockIoDevicePath, CachedDevicePath);
506 FreePool(TempNewDevicePath);
507 }
508 //
509 // Here limit the device path instance number to 12, which is max number for a system support 3 IDE controller
510 // If the user try to boot many OS in different HDs or partitions, in theory, the 'HDDP' variable maybe become larger and larger.
511 //
512 InstanceNum = 0;
513 ASSERT (CachedDevicePath != NULL);
514 TempNewDevicePath = CachedDevicePath;
515 while (!IsDevicePathEnd (TempNewDevicePath)) {
516 TempNewDevicePath = NextDevicePathNode (TempNewDevicePath);
517 //
518 // Parse one instance
519 //
520 while (!IsDevicePathEndType (TempNewDevicePath)) {
521 TempNewDevicePath = NextDevicePathNode (TempNewDevicePath);
522 }
523 InstanceNum++;
524 //
525 // If the CachedDevicePath variable contain too much instance, only remain 12 instances.
526 //
527 if (InstanceNum >= 12) {
528 SetDevicePathEndNode (TempNewDevicePath);
529 break;
530 }
531 }
532 } else {
533 CachedDevicePath = DuplicateDevicePath (BlockIoDevicePath);
534 }
535
536 //
537 // Save the matching Device Path so we don't need to do a connect all next time
538 //
539 Status = gRT->SetVariable (
540 L"HDDP",
541 &mHdBootVariablePrivateGuid,
542 EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE,
543 GetDevicePathSize (CachedDevicePath),
544 CachedDevicePath
545 );
546
547 break;
548 }
549 }
550
551 FreePool (CachedDevicePath);
552 if (BlockIoBuffer != NULL) {
553 FreePool (BlockIoBuffer);
554 }
555 return FullDevicePath;
556 }
557
558 /**
559 Check whether there is a instance in BlockIoDevicePath, which contain multi device path
560 instances, has the same partition node with HardDriveDevicePath device path
561
562 @param BlockIoDevicePath Multi device path instances which need to check
563 @param HardDriveDevicePath A device path which starts with a hard drive media
564 device path.
565
566 @retval TRUE There is a matched device path instance.
567 @retval FALSE There is no matched device path instance.
568
569 **/
570 BOOLEAN
571 EFIAPI
572 MatchPartitionDevicePathNode (
573 IN EFI_DEVICE_PATH_PROTOCOL *BlockIoDevicePath,
574 IN HARDDRIVE_DEVICE_PATH *HardDriveDevicePath
575 )
576 {
577 HARDDRIVE_DEVICE_PATH *TmpHdPath;
578 EFI_DEVICE_PATH_PROTOCOL *DevicePath;
579 BOOLEAN Match;
580 EFI_DEVICE_PATH_PROTOCOL *BlockIoHdDevicePathNode;
581
582 if ((BlockIoDevicePath == NULL) || (HardDriveDevicePath == NULL)) {
583 return FALSE;
584 }
585
586 //
587 // Make PreviousDevicePath == the device path node before the end node
588 //
589 DevicePath = BlockIoDevicePath;
590 BlockIoHdDevicePathNode = NULL;
591
592 //
593 // find the partition device path node
594 //
595 while (!IsDevicePathEnd (DevicePath)) {
596 if ((DevicePathType (DevicePath) == MEDIA_DEVICE_PATH) &&
597 (DevicePathSubType (DevicePath) == MEDIA_HARDDRIVE_DP)
598 ) {
599 BlockIoHdDevicePathNode = DevicePath;
600 break;
601 }
602
603 DevicePath = NextDevicePathNode (DevicePath);
604 }
605
606 if (BlockIoHdDevicePathNode == NULL) {
607 return FALSE;
608 }
609 //
610 // See if the harddrive device path in blockio matches the orig Hard Drive Node
611 //
612 TmpHdPath = (HARDDRIVE_DEVICE_PATH *) BlockIoHdDevicePathNode;
613 Match = FALSE;
614
615 //
616 // Check for the match
617 //
618 if ((TmpHdPath->MBRType == HardDriveDevicePath->MBRType) &&
619 (TmpHdPath->SignatureType == HardDriveDevicePath->SignatureType)) {
620 switch (TmpHdPath->SignatureType) {
621 case SIGNATURE_TYPE_GUID:
622 Match = CompareGuid ((EFI_GUID *)TmpHdPath->Signature, (EFI_GUID *)HardDriveDevicePath->Signature);
623 break;
624 case SIGNATURE_TYPE_MBR:
625 Match = (BOOLEAN)(*((UINT32 *)(&(TmpHdPath->Signature[0]))) == ReadUnaligned32((UINT32 *)(&(HardDriveDevicePath->Signature[0]))));
626 break;
627 default:
628 Match = FALSE;
629 break;
630 }
631 }
632
633 return Match;
634 }
635
636 /**
637 Delete the boot option associated with the handle passed in.
638
639 @param Handle The handle which present the device path to create
640 boot option
641
642 @retval EFI_SUCCESS Delete the boot option success
643 @retval EFI_NOT_FOUND If the Device Path is not found in the system
644 @retval EFI_OUT_OF_RESOURCES Lack of memory resource
645 @retval Other Error return value from SetVariable()
646
647 **/
648 EFI_STATUS
649 BdsLibDeleteOptionFromHandle (
650 IN EFI_HANDLE Handle
651 )
652 {
653 UINT16 *BootOrder;
654 UINT8 *BootOptionVar;
655 UINTN BootOrderSize;
656 UINTN BootOptionSize;
657 EFI_STATUS Status;
658 UINTN Index;
659 UINT16 BootOption[BOOT_OPTION_MAX_CHAR];
660 UINTN DevicePathSize;
661 UINTN OptionDevicePathSize;
662 EFI_DEVICE_PATH_PROTOCOL *DevicePath;
663 EFI_DEVICE_PATH_PROTOCOL *OptionDevicePath;
664 UINT8 *TempPtr;
665
666 Status = EFI_SUCCESS;
667 BootOrder = NULL;
668 BootOrderSize = 0;
669
670 //
671 // Check "BootOrder" variable, if no, means there is no any boot order.
672 //
673 BootOrder = BdsLibGetVariableAndSize (
674 L"BootOrder",
675 &gEfiGlobalVariableGuid,
676 &BootOrderSize
677 );
678 if (BootOrder == NULL) {
679 return EFI_NOT_FOUND;
680 }
681
682 //
683 // Convert device handle to device path protocol instance
684 //
685 DevicePath = DevicePathFromHandle (Handle);
686 if (DevicePath == NULL) {
687 return EFI_NOT_FOUND;
688 }
689 DevicePathSize = GetDevicePathSize (DevicePath);
690
691 //
692 // Loop all boot order variable and find the matching device path
693 //
694 Index = 0;
695 while (Index < BootOrderSize / sizeof (UINT16)) {
696 UnicodeSPrint (BootOption, sizeof (BootOption), L"Boot%04x", BootOrder[Index]);
697 BootOptionVar = BdsLibGetVariableAndSize (
698 BootOption,
699 &gEfiGlobalVariableGuid,
700 &BootOptionSize
701 );
702
703 if (BootOptionVar == NULL) {
704 FreePool (BootOrder);
705 return EFI_OUT_OF_RESOURCES;
706 }
707
708 TempPtr = BootOptionVar;
709 TempPtr += sizeof (UINT32) + sizeof (UINT16);
710 TempPtr += StrSize ((CHAR16 *) TempPtr);
711 OptionDevicePath = (EFI_DEVICE_PATH_PROTOCOL *) TempPtr;
712 OptionDevicePathSize = GetDevicePathSize (OptionDevicePath);
713
714 //
715 // Check whether the device path match
716 //
717 if ((OptionDevicePathSize == DevicePathSize) &&
718 (CompareMem (DevicePath, OptionDevicePath, DevicePathSize) == 0)) {
719 BdsDeleteBootOption (BootOrder[Index], BootOrder, &BootOrderSize);
720 FreePool (BootOptionVar);
721 break;
722 }
723
724 FreePool (BootOptionVar);
725 Index++;
726 }
727
728 //
729 // Adjust number of boot option for "BootOrder" variable.
730 //
731 Status = gRT->SetVariable (
732 L"BootOrder",
733 &gEfiGlobalVariableGuid,
734 EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE,
735 BootOrderSize,
736 BootOrder
737 );
738
739 FreePool (BootOrder);
740
741 return Status;
742 }
743
744
745 /**
746 Delete all invalid EFI boot options. The probable invalid boot option could
747 be Removable media or Network boot device.
748
749 @retval EFI_SUCCESS Delete all invalid boot option success
750 @retval EFI_NOT_FOUND Variable "BootOrder" is not found
751 @retval EFI_OUT_OF_RESOURCES Lack of memory resource
752 @retval Other Error return value from SetVariable()
753
754 **/
755 EFI_STATUS
756 BdsDeleteAllInvalidEfiBootOption (
757 VOID
758 )
759 {
760 UINT16 *BootOrder;
761 UINT8 *BootOptionVar;
762 UINTN BootOrderSize;
763 UINTN BootOptionSize;
764 EFI_STATUS Status;
765 UINTN Index;
766 UINTN Index2;
767 UINT16 BootOption[BOOT_OPTION_MAX_CHAR];
768 EFI_DEVICE_PATH_PROTOCOL *OptionDevicePath;
769 UINT8 *TempPtr;
770
771 Status = EFI_SUCCESS;
772 BootOrder = NULL;
773 BootOrderSize = 0;
774
775 //
776 // Check "BootOrder" variable firstly, this variable hold the number of boot options
777 //
778 BootOrder = BdsLibGetVariableAndSize (
779 L"BootOrder",
780 &gEfiGlobalVariableGuid,
781 &BootOrderSize
782 );
783 if (NULL == BootOrder) {
784 return EFI_NOT_FOUND;
785 }
786
787 Index = 0;
788 while (Index < BootOrderSize / sizeof (UINT16)) {
789 UnicodeSPrint (BootOption, sizeof (BootOption), L"Boot%04x", BootOrder[Index]);
790 BootOptionVar = BdsLibGetVariableAndSize (
791 BootOption,
792 &gEfiGlobalVariableGuid,
793 &BootOptionSize
794 );
795 if (NULL == BootOptionVar) {
796 FreePool (BootOrder);
797 return EFI_OUT_OF_RESOURCES;
798 }
799
800 TempPtr = BootOptionVar;
801 TempPtr += sizeof (UINT32) + sizeof (UINT16);
802 TempPtr += StrSize ((CHAR16 *) TempPtr);
803 OptionDevicePath = (EFI_DEVICE_PATH_PROTOCOL *) TempPtr;
804
805 //
806 // Skip legacy boot option (BBS boot device)
807 //
808 if ((DevicePathType (OptionDevicePath) == BBS_DEVICE_PATH) &&
809 (DevicePathSubType (OptionDevicePath) == BBS_BBS_DP)) {
810 FreePool (BootOptionVar);
811 Index++;
812 continue;
813 }
814
815 if (!BdsLibIsValidEFIBootOptDevicePath (OptionDevicePath, FALSE)) {
816 //
817 // Delete this invalid boot option "Boot####"
818 //
819 Status = gRT->SetVariable (
820 BootOption,
821 &gEfiGlobalVariableGuid,
822 EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE,
823 0,
824 NULL
825 );
826 //
827 // Mark this boot option in boot order as deleted
828 //
829 BootOrder[Index] = 0xffff;
830 }
831
832 FreePool (BootOptionVar);
833 Index++;
834 }
835
836 //
837 // Adjust boot order array
838 //
839 Index2 = 0;
840 for (Index = 0; Index < BootOrderSize / sizeof (UINT16); Index++) {
841 if (BootOrder[Index] != 0xffff) {
842 BootOrder[Index2] = BootOrder[Index];
843 Index2 ++;
844 }
845 }
846 Status = gRT->SetVariable (
847 L"BootOrder",
848 &gEfiGlobalVariableGuid,
849 EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE,
850 Index2 * sizeof (UINT16),
851 BootOrder
852 );
853
854 FreePool (BootOrder);
855
856 return Status;
857 }
858
859
860 /**
861 This function will enumerate all possible boot device in the system,
862 it will only execute once of every boot.
863
864 @param BdsBootOptionList The header of the link list which indexed all
865 current boot options
866
867 @retval EFI_SUCCESS Finished all the boot device enumerate and create
868 the boot option base on that boot device
869
870 **/
871 EFI_STATUS
872 EFIAPI
873 BdsLibEnumerateAllBootOption (
874 IN OUT LIST_ENTRY *BdsBootOptionList
875 )
876 {
877 EFI_STATUS Status;
878 UINT16 FloppyNumber;
879 UINT16 CdromNumber;
880 UINT16 UsbNumber;
881 UINT16 MiscNumber;
882 UINT16 NonBlockNumber;
883 UINTN NumberBlockIoHandles;
884 EFI_HANDLE *BlockIoHandles;
885 EFI_BLOCK_IO_PROTOCOL *BlkIo;
886 UINTN Index;
887 UINTN NumberSimpleNetworkHandles;
888 EFI_HANDLE *SimpleNetworkHandles;
889 UINTN FvHandleCount;
890 EFI_HANDLE *FvHandleBuffer;
891 EFI_FV_FILETYPE Type;
892 UINTN Size;
893 EFI_FV_FILE_ATTRIBUTES Attributes;
894 UINT32 AuthenticationStatus;
895 EFI_FIRMWARE_VOLUME2_PROTOCOL *Fv;
896 EFI_DEVICE_PATH_PROTOCOL *DevicePath;
897 UINTN DevicePathType;
898 CHAR16 Buffer[40];
899 EFI_HANDLE *FileSystemHandles;
900 UINTN NumberFileSystemHandles;
901 BOOLEAN NeedDelete;
902 EFI_IMAGE_DOS_HEADER DosHeader;
903 EFI_IMAGE_OPTIONAL_HEADER_UNION HdrData;
904 EFI_IMAGE_OPTIONAL_HEADER_PTR_UNION Hdr;
905
906 FloppyNumber = 0;
907 CdromNumber = 0;
908 UsbNumber = 0;
909 MiscNumber = 0;
910 ZeroMem (Buffer, sizeof (Buffer));
911
912 //
913 // If the boot device enumerate happened, just get the boot
914 // device from the boot order variable
915 //
916 if (mEnumBootDevice) {
917 BdsLibBuildOptionFromVar (BdsBootOptionList, L"BootOrder");
918 return EFI_SUCCESS;
919 }
920
921 //
922 // Notes: this dirty code is to get the legacy boot option from the
923 // BBS table and create to variable as the EFI boot option, it should
924 // be removed after the CSM can provide legacy boot option directly
925 //
926 REFRESH_LEGACY_BOOT_OPTIONS;
927
928 //
929 // Delete invalid boot option
930 //
931 BdsDeleteAllInvalidEfiBootOption ();
932
933 //
934 // Parse removable media
935 //
936 gBS->LocateHandleBuffer (
937 ByProtocol,
938 &gEfiBlockIoProtocolGuid,
939 NULL,
940 &NumberBlockIoHandles,
941 &BlockIoHandles
942 );
943
944 for (Index = 0; Index < NumberBlockIoHandles; Index++) {
945 Status = gBS->HandleProtocol (
946 BlockIoHandles[Index],
947 &gEfiBlockIoProtocolGuid,
948 (VOID **) &BlkIo
949 );
950 if (!EFI_ERROR (Status)) {
951 if (!BlkIo->Media->RemovableMedia) {
952 //
953 // skip the non-removable block devices
954 //
955 continue;
956 }
957 }
958 DevicePath = DevicePathFromHandle (BlockIoHandles[Index]);
959 DevicePathType = BdsGetBootTypeFromDevicePath (DevicePath);
960
961 switch (DevicePathType) {
962 case BDS_EFI_ACPI_FLOPPY_BOOT:
963 if (FloppyNumber == 0) {
964 UnicodeSPrint (Buffer, sizeof (Buffer), L"EFI Floppy");
965 } else {
966 UnicodeSPrint (Buffer, sizeof (Buffer), L"EFI Floppy %d", FloppyNumber);
967 }
968 BdsLibBuildOptionFromHandle (BlockIoHandles[Index], BdsBootOptionList, Buffer);
969 FloppyNumber++;
970 break;
971
972 case BDS_EFI_MESSAGE_ATAPI_BOOT:
973 if (CdromNumber == 0) {
974 UnicodeSPrint (Buffer, sizeof (Buffer), L"EFI DVD/CDROM");
975 } else {
976 UnicodeSPrint (Buffer, sizeof (Buffer), L"EFI DVD/CDROM %d", CdromNumber);
977 }
978 BdsLibBuildOptionFromHandle (BlockIoHandles[Index], BdsBootOptionList, Buffer);
979 CdromNumber++;
980 break;
981
982 case BDS_EFI_MESSAGE_USB_DEVICE_BOOT:
983 if (UsbNumber == 0) {
984 UnicodeSPrint (Buffer, sizeof (Buffer), L"EFI USB Device");
985 } else {
986 UnicodeSPrint (Buffer, sizeof (Buffer), L"EFI USB Device %d", UsbNumber);
987 }
988 BdsLibBuildOptionFromHandle (BlockIoHandles[Index], BdsBootOptionList, Buffer);
989 UsbNumber++;
990 break;
991
992 case BDS_EFI_MESSAGE_SCSI_BOOT:
993 if (UsbNumber == 0) {
994 UnicodeSPrint (Buffer, sizeof (Buffer), L"EFI SCSI Device");
995 } else {
996 UnicodeSPrint (Buffer, sizeof (Buffer), L"EFI SCSI Device %d", UsbNumber);
997 }
998 BdsLibBuildOptionFromHandle (BlockIoHandles[Index], BdsBootOptionList, Buffer);
999 UsbNumber++;
1000 break;
1001
1002 case BDS_EFI_MESSAGE_MISC_BOOT:
1003 if (MiscNumber == 0) {
1004 UnicodeSPrint (Buffer, sizeof (Buffer), L"EFI Misc Device");
1005 } else {
1006 UnicodeSPrint (Buffer, sizeof (Buffer), L"EFI Misc Device %d", MiscNumber);
1007 }
1008 BdsLibBuildOptionFromHandle (BlockIoHandles[Index], BdsBootOptionList, Buffer);
1009 MiscNumber++;
1010 break;
1011
1012 default:
1013 break;
1014 }
1015 }
1016
1017 if (NumberBlockIoHandles != 0) {
1018 FreePool (BlockIoHandles);
1019 }
1020
1021 //
1022 // If there is simple file protocol which does not consume block Io protocol, create a boot option for it here.
1023 //
1024 NonBlockNumber = 0;
1025 gBS->LocateHandleBuffer (
1026 ByProtocol,
1027 &gEfiSimpleFileSystemProtocolGuid,
1028 NULL,
1029 &NumberFileSystemHandles,
1030 &FileSystemHandles
1031 );
1032 for (Index = 0; Index < NumberFileSystemHandles; Index++) {
1033 Status = gBS->HandleProtocol (
1034 FileSystemHandles[Index],
1035 &gEfiBlockIoProtocolGuid,
1036 (VOID **) &BlkIo
1037 );
1038 if (!EFI_ERROR (Status)) {
1039 //
1040 // Skip if the file system handle supports a BlkIo protocol,
1041 //
1042 continue;
1043 }
1044
1045 //
1046 // Do the removable Media thing. \EFI\BOOT\boot{machinename}.EFI
1047 // machinename is ia32, ia64, x64, ...
1048 //
1049 Hdr.Union = &HdrData;
1050 NeedDelete = TRUE;
1051 Status = BdsLibGetImageHeader (
1052 FileSystemHandles[Index],
1053 EFI_REMOVABLE_MEDIA_FILE_NAME,
1054 &DosHeader,
1055 Hdr
1056 );
1057 if (!EFI_ERROR (Status) &&
1058 EFI_IMAGE_MACHINE_TYPE_SUPPORTED (Hdr.Pe32->FileHeader.Machine) &&
1059 Hdr.Pe32->OptionalHeader.Subsystem == EFI_IMAGE_SUBSYSTEM_EFI_APPLICATION) {
1060 NeedDelete = FALSE;
1061 }
1062
1063 if (NeedDelete) {
1064 //
1065 // No such file or the file is not a EFI application, delete this boot option
1066 //
1067 BdsLibDeleteOptionFromHandle (FileSystemHandles[Index]);
1068 } else {
1069 if (NonBlockNumber == 0) {
1070 UnicodeSPrint (Buffer, sizeof (Buffer), L"EFI Non-Block Boot Device");
1071 } else {
1072 UnicodeSPrint (Buffer, sizeof (Buffer), L"EFI Non-Block Boot Device %d", NonBlockNumber);
1073 }
1074 BdsLibBuildOptionFromHandle (FileSystemHandles[Index], BdsBootOptionList, Buffer);
1075 NonBlockNumber++;
1076 }
1077 }
1078
1079 if (NumberFileSystemHandles != 0) {
1080 FreePool (FileSystemHandles);
1081 }
1082
1083 //
1084 // Parse Network Boot Device
1085 //
1086 gBS->LocateHandleBuffer (
1087 ByProtocol,
1088 &gEfiSimpleNetworkProtocolGuid,
1089 NULL,
1090 &NumberSimpleNetworkHandles,
1091 &SimpleNetworkHandles
1092 );
1093 for (Index = 0; Index < NumberSimpleNetworkHandles; Index++) {
1094 if (Index == 0) {
1095 UnicodeSPrint (Buffer, sizeof (Buffer), L"EFI Network");
1096 } else {
1097 UnicodeSPrint (Buffer, sizeof (Buffer), L"EFI Network %d", Index);
1098 }
1099 BdsLibBuildOptionFromHandle (SimpleNetworkHandles[Index], BdsBootOptionList, Buffer);
1100 }
1101
1102 if (NumberSimpleNetworkHandles != 0) {
1103 FreePool (SimpleNetworkHandles);
1104 }
1105
1106 //
1107 // Check if we have on flash shell
1108 //
1109 gBS->LocateHandleBuffer (
1110 ByProtocol,
1111 &gEfiFirmwareVolume2ProtocolGuid,
1112 NULL,
1113 &FvHandleCount,
1114 &FvHandleBuffer
1115 );
1116 for (Index = 0; Index < FvHandleCount; Index++) {
1117 gBS->HandleProtocol (
1118 FvHandleBuffer[Index],
1119 &gEfiFirmwareVolume2ProtocolGuid,
1120 (VOID **) &Fv
1121 );
1122
1123 Status = Fv->ReadFile (
1124 Fv,
1125 &gEfiShellFileGuid,
1126 NULL,
1127 &Size,
1128 &Type,
1129 &Attributes,
1130 &AuthenticationStatus
1131 );
1132 if (EFI_ERROR (Status)) {
1133 //
1134 // Skip if no shell file in the FV
1135 //
1136 continue;
1137 }
1138 //
1139 // Build the shell boot option
1140 //
1141 BdsLibBuildOptionFromShell (FvHandleBuffer[Index], BdsBootOptionList);
1142 }
1143
1144 if (FvHandleCount != 0) {
1145 FreePool (FvHandleBuffer);
1146 }
1147 //
1148 // Make sure every boot only have one time
1149 // boot device enumerate
1150 //
1151 BdsLibBuildOptionFromVar (BdsBootOptionList, L"BootOrder");
1152 mEnumBootDevice = TRUE;
1153
1154 return EFI_SUCCESS;
1155 }
1156
1157 /**
1158 Build the boot option with the handle parsed in
1159
1160 @param Handle The handle which present the device path to create
1161 boot option
1162 @param BdsBootOptionList The header of the link list which indexed all
1163 current boot options
1164 @param String The description of the boot option.
1165
1166 **/
1167 VOID
1168 EFIAPI
1169 BdsLibBuildOptionFromHandle (
1170 IN EFI_HANDLE Handle,
1171 IN LIST_ENTRY *BdsBootOptionList,
1172 IN CHAR16 *String
1173 )
1174 {
1175 EFI_DEVICE_PATH_PROTOCOL *DevicePath;
1176
1177 DevicePath = DevicePathFromHandle (Handle);
1178
1179 //
1180 // Create and register new boot option
1181 //
1182 BdsLibRegisterNewOption (BdsBootOptionList, DevicePath, String, L"BootOrder");
1183 }
1184
1185
1186 /**
1187 Build the on flash shell boot option with the handle parsed in.
1188
1189 @param Handle The handle which present the device path to create
1190 on flash shell boot option
1191 @param BdsBootOptionList The header of the link list which indexed all
1192 current boot options
1193
1194 **/
1195 VOID
1196 EFIAPI
1197 BdsLibBuildOptionFromShell (
1198 IN EFI_HANDLE Handle,
1199 IN OUT LIST_ENTRY *BdsBootOptionList
1200 )
1201 {
1202 EFI_DEVICE_PATH_PROTOCOL *DevicePath;
1203 MEDIA_FW_VOL_FILEPATH_DEVICE_PATH ShellNode;
1204
1205 DevicePath = DevicePathFromHandle (Handle);
1206
1207 //
1208 // Build the shell device path
1209 //
1210 EfiInitializeFwVolDevicepathNode (&ShellNode, &gEfiShellFileGuid);
1211
1212 DevicePath = AppendDevicePathNode (DevicePath, (EFI_DEVICE_PATH_PROTOCOL *) &ShellNode);
1213
1214 //
1215 // Create and register the shell boot option
1216 //
1217 BdsLibRegisterNewOption (BdsBootOptionList, DevicePath, L"EFI Internal Shell", L"BootOrder");
1218
1219 }
1220
1221 /**
1222 Boot from the UEFI spec defined "BootNext" variable.
1223
1224 **/
1225 VOID
1226 EFIAPI
1227 BdsLibBootNext (
1228 VOID
1229 )
1230 {
1231 UINT16 *BootNext;
1232 UINTN BootNextSize;
1233 CHAR16 Buffer[20];
1234 BDS_COMMON_OPTION *BootOption;
1235 LIST_ENTRY TempList;
1236 UINTN ExitDataSize;
1237 CHAR16 *ExitData;
1238
1239 //
1240 // Init the boot option name buffer and temp link list
1241 //
1242 InitializeListHead (&TempList);
1243 ZeroMem (Buffer, sizeof (Buffer));
1244
1245 BootNext = BdsLibGetVariableAndSize (
1246 L"BootNext",
1247 &gEfiGlobalVariableGuid,
1248 &BootNextSize
1249 );
1250
1251 //
1252 // Clear the boot next variable first
1253 //
1254 if (BootNext != NULL) {
1255 gRT->SetVariable (
1256 L"BootNext",
1257 &gEfiGlobalVariableGuid,
1258 EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE,
1259 0,
1260 BootNext
1261 );
1262
1263 //
1264 // Start to build the boot option and try to boot
1265 //
1266 UnicodeSPrint (Buffer, sizeof (Buffer), L"Boot%04x", *BootNext);
1267 BootOption = BdsLibVariableToOption (&TempList, Buffer);
1268 ASSERT (BootOption != NULL);
1269 BdsLibConnectDevicePath (BootOption->DevicePath);
1270 BdsLibBootViaBootOption (BootOption, BootOption->DevicePath, &ExitDataSize, &ExitData);
1271 }
1272
1273 }
1274
1275 /**
1276 Return the bootable media handle.
1277 First, check the device is connected
1278 Second, check whether the device path point to a device which support SimpleFileSystemProtocol,
1279 Third, detect the the default boot file in the Media, and return the removable Media handle.
1280
1281 @param DevicePath Device Path to a bootable device
1282
1283 @retval NULL The media on the DevicePath is not bootable
1284
1285 **/
1286 EFI_HANDLE
1287 EFIAPI
1288 BdsLibGetBootableHandle (
1289 IN EFI_DEVICE_PATH_PROTOCOL *DevicePath
1290 )
1291 {
1292 EFI_STATUS Status;
1293 EFI_DEVICE_PATH_PROTOCOL *UpdatedDevicePath;
1294 EFI_DEVICE_PATH_PROTOCOL *DupDevicePath;
1295 EFI_HANDLE Handle;
1296 EFI_BLOCK_IO_PROTOCOL *BlockIo;
1297 VOID *Buffer;
1298 EFI_DEVICE_PATH_PROTOCOL *TempDevicePath;
1299 UINTN Size;
1300 UINTN TempSize;
1301 EFI_HANDLE ReturnHandle;
1302 EFI_HANDLE *SimpleFileSystemHandles;
1303
1304 UINTN NumberSimpleFileSystemHandles;
1305 UINTN Index;
1306 EFI_IMAGE_DOS_HEADER DosHeader;
1307 EFI_IMAGE_OPTIONAL_HEADER_UNION HdrData;
1308 EFI_IMAGE_OPTIONAL_HEADER_PTR_UNION Hdr;
1309
1310 UpdatedDevicePath = DevicePath;
1311
1312 //
1313 // Check whether the device is connected
1314 //
1315 Status = gBS->LocateDevicePath (&gEfiBlockIoProtocolGuid, &UpdatedDevicePath, &Handle);
1316 if (EFI_ERROR (Status)) {
1317 //
1318 // Skip the case that the boot option point to a simple file protocol which does not consume block Io protocol,
1319 //
1320 Status = gBS->LocateDevicePath (&gEfiSimpleFileSystemProtocolGuid, &UpdatedDevicePath, &Handle);
1321 if (EFI_ERROR (Status)) {
1322 //
1323 // Fail to find the proper BlockIo and simple file protocol, maybe because device not present, we need to connect it firstly
1324 //
1325 UpdatedDevicePath = DevicePath;
1326 Status = gBS->LocateDevicePath (&gEfiDevicePathProtocolGuid, &UpdatedDevicePath, &Handle);
1327 gBS->ConnectController (Handle, NULL, NULL, TRUE);
1328 }
1329 } else {
1330 //
1331 // Get BlockIo protocol and check removable attribute
1332 //
1333 Status = gBS->HandleProtocol (Handle, &gEfiBlockIoProtocolGuid, (VOID **)&BlockIo);
1334 //
1335 // Issue a dummy read to the device to check for media change.
1336 // When the removable media is changed, any Block IO read/write will
1337 // cause the BlockIo protocol be reinstalled and EFI_MEDIA_CHANGED is
1338 // returned. After the Block IO protocol is reinstalled, subsequent
1339 // Block IO read/write will success.
1340 //
1341 Buffer = AllocatePool (BlockIo->Media->BlockSize);
1342 if (Buffer != NULL) {
1343 BlockIo->ReadBlocks (
1344 BlockIo,
1345 BlockIo->Media->MediaId,
1346 0,
1347 BlockIo->Media->BlockSize,
1348 Buffer
1349 );
1350 FreePool(Buffer);
1351 }
1352 }
1353
1354 //
1355 // Detect the the default boot file from removable Media
1356 //
1357
1358 //
1359 // If fail to get bootable handle specified by a USB boot option, the BDS should try to find other bootable device in the same USB bus
1360 // Try to locate the USB node device path first, if fail then use its previous PCI node to search
1361 //
1362 DupDevicePath = DuplicateDevicePath (DevicePath);
1363 ASSERT (DupDevicePath != NULL);
1364
1365 UpdatedDevicePath = DupDevicePath;
1366 Status = gBS->LocateDevicePath (&gEfiDevicePathProtocolGuid, &UpdatedDevicePath, &Handle);
1367 //
1368 // if the resulting device path point to a usb node, and the usb node is a dummy node, should only let device path only point to the previous Pci node
1369 // Acpi()/Pci()/Usb() --> Acpi()/Pci()
1370 //
1371 if ((DevicePathType (UpdatedDevicePath) == MESSAGING_DEVICE_PATH) &&
1372 (DevicePathSubType (UpdatedDevicePath) == MSG_USB_DP)) {
1373 //
1374 // Remove the usb node, let the device path only point to PCI node
1375 //
1376 SetDevicePathEndNode (UpdatedDevicePath);
1377 UpdatedDevicePath = DupDevicePath;
1378 } else {
1379 UpdatedDevicePath = DevicePath;
1380 }
1381
1382 //
1383 // Get the device path size of boot option
1384 //
1385 Size = GetDevicePathSize(UpdatedDevicePath) - sizeof (EFI_DEVICE_PATH_PROTOCOL); // minus the end node
1386 ReturnHandle = NULL;
1387 gBS->LocateHandleBuffer (
1388 ByProtocol,
1389 &gEfiSimpleFileSystemProtocolGuid,
1390 NULL,
1391 &NumberSimpleFileSystemHandles,
1392 &SimpleFileSystemHandles
1393 );
1394 for (Index = 0; Index < NumberSimpleFileSystemHandles; Index++) {
1395 //
1396 // Get the device path size of SimpleFileSystem handle
1397 //
1398 TempDevicePath = DevicePathFromHandle (SimpleFileSystemHandles[Index]);
1399 TempSize = GetDevicePathSize (TempDevicePath)- sizeof (EFI_DEVICE_PATH_PROTOCOL); // minus the end node
1400 //
1401 // Check whether the device path of boot option is part of the SimpleFileSystem handle's device path
1402 //
1403 if (Size <= TempSize && CompareMem (TempDevicePath, UpdatedDevicePath, Size)==0) {
1404 //
1405 // Load the default boot file \EFI\BOOT\boot{machinename}.EFI from removable Media
1406 // machinename is ia32, ia64, x64, ...
1407 //
1408 Hdr.Union = &HdrData;
1409 Status = BdsLibGetImageHeader (
1410 SimpleFileSystemHandles[Index],
1411 EFI_REMOVABLE_MEDIA_FILE_NAME,
1412 &DosHeader,
1413 Hdr
1414 );
1415 if (!EFI_ERROR (Status) &&
1416 EFI_IMAGE_MACHINE_TYPE_SUPPORTED (Hdr.Pe32->FileHeader.Machine) &&
1417 Hdr.Pe32->OptionalHeader.Subsystem == EFI_IMAGE_SUBSYSTEM_EFI_APPLICATION) {
1418 ReturnHandle = SimpleFileSystemHandles[Index];
1419 break;
1420 }
1421 }
1422 }
1423
1424 FreePool(DupDevicePath);
1425
1426 if (SimpleFileSystemHandles != NULL) {
1427 FreePool(SimpleFileSystemHandles);
1428 }
1429
1430 return ReturnHandle;
1431 }
1432
1433 /**
1434 Check to see if the network cable is plugged in. If the DevicePath is not
1435 connected it will be connected.
1436
1437 @param DevicePath Device Path to check
1438
1439 @retval TRUE DevicePath points to an Network that is connected
1440 @retval FALSE DevicePath does not point to a bootable network
1441
1442 **/
1443 BOOLEAN
1444 BdsLibNetworkBootWithMediaPresent (
1445 IN EFI_DEVICE_PATH_PROTOCOL *DevicePath
1446 )
1447 {
1448 EFI_STATUS Status;
1449 EFI_DEVICE_PATH_PROTOCOL *UpdatedDevicePath;
1450 EFI_HANDLE Handle;
1451 EFI_SIMPLE_NETWORK_PROTOCOL *Snp;
1452 BOOLEAN MediaPresent;
1453
1454 MediaPresent = FALSE;
1455
1456 UpdatedDevicePath = DevicePath;
1457 Status = gBS->LocateDevicePath (&gEfiSimpleNetworkProtocolGuid, &UpdatedDevicePath, &Handle);
1458 if (EFI_ERROR (Status)) {
1459 //
1460 // Device not present so see if we need to connect it
1461 //
1462 Status = BdsLibConnectDevicePath (DevicePath);
1463 if (!EFI_ERROR (Status)) {
1464 //
1465 // This one should work after we did the connect
1466 //
1467 Status = gBS->LocateDevicePath (&gEfiSimpleNetworkProtocolGuid, &UpdatedDevicePath, &Handle);
1468 }
1469 }
1470
1471 if (!EFI_ERROR (Status)) {
1472 Status = gBS->HandleProtocol (Handle, &gEfiSimpleNetworkProtocolGuid, (VOID **)&Snp);
1473 if (!EFI_ERROR (Status)) {
1474 if (Snp->Mode->MediaPresentSupported) {
1475 if (Snp->Mode->State == EfiSimpleNetworkInitialized) {
1476 //
1477 // In case some one else is using the SNP check to see if it's connected
1478 //
1479 MediaPresent = Snp->Mode->MediaPresent;
1480 } else {
1481 //
1482 // No one is using SNP so we need to Start and Initialize so
1483 // MediaPresent will be valid.
1484 //
1485 Status = Snp->Start (Snp);
1486 if (!EFI_ERROR (Status)) {
1487 Status = Snp->Initialize (Snp, 0, 0);
1488 if (!EFI_ERROR (Status)) {
1489 MediaPresent = Snp->Mode->MediaPresent;
1490 Snp->Shutdown (Snp);
1491 }
1492 Snp->Stop (Snp);
1493 }
1494 }
1495 } else {
1496 MediaPresent = TRUE;
1497 }
1498 }
1499 }
1500
1501 return MediaPresent;
1502 }
1503
1504 /**
1505 For a bootable Device path, return its boot type.
1506
1507 @param DevicePath The bootable device Path to check
1508
1509 @retval BDS_EFI_MEDIA_HD_BOOT If the device path contains any media device path node, it is media boot type
1510 For the floppy node, handle it as media node
1511 @retval BDS_EFI_MEDIA_CDROM_BOOT If the device path contains any media device path node, it is media boot type
1512 For the floppy node, handle it as media node
1513 @retval BDS_EFI_ACPI_FLOPPY_BOOT If the device path contains any media device path node, it is media boot type
1514 For the floppy node, handle it as media node
1515 @retval BDS_EFI_MESSAGE_ATAPI_BOOT If the device path not contains any media device path node, and
1516 its last device path node point to a message device path node, it is
1517
1518 @retval BDS_EFI_MESSAGE_SCSI_BOOT If the device path not contains any media device path node, and
1519 its last device path node point to a message device path node, it is
1520 @retval BDS_EFI_MESSAGE_USB_DEVICE_BOOT If the device path not contains any media device path node, and
1521 its last device path node point to a message device path node, it is
1522 @retval BDS_EFI_MESSAGE_MISC_BOOT If the device path not contains any media device path node, and
1523 its last device path node point to a message device path node, it is
1524 @retval BDS_LEGACY_BBS_BOOT Legacy boot type
1525 @retval BDS_EFI_UNSUPPORT An EFI Removable BlockIO device path not point to a media and message device,
1526
1527 **/
1528 UINT32
1529 EFIAPI
1530 BdsGetBootTypeFromDevicePath (
1531 IN EFI_DEVICE_PATH_PROTOCOL *DevicePath
1532 )
1533 {
1534 ACPI_HID_DEVICE_PATH *Acpi;
1535 EFI_DEVICE_PATH_PROTOCOL *TempDevicePath;
1536 EFI_DEVICE_PATH_PROTOCOL *LastDeviceNode;
1537
1538
1539 if (NULL == DevicePath) {
1540 return BDS_EFI_UNSUPPORT;
1541 }
1542
1543 TempDevicePath = DevicePath;
1544
1545 while (!IsDevicePathEndType (TempDevicePath)) {
1546 switch (DevicePathType (TempDevicePath)) {
1547 case BBS_DEVICE_PATH:
1548 return BDS_LEGACY_BBS_BOOT;
1549 case MEDIA_DEVICE_PATH:
1550 if (DevicePathSubType (TempDevicePath) == MEDIA_HARDDRIVE_DP) {
1551 return BDS_EFI_MEDIA_HD_BOOT;
1552 } else if (DevicePathSubType (TempDevicePath) == MEDIA_CDROM_DP) {
1553 return BDS_EFI_MEDIA_CDROM_BOOT;
1554 }
1555 break;
1556 case ACPI_DEVICE_PATH:
1557 Acpi = (ACPI_HID_DEVICE_PATH *) TempDevicePath;
1558 if (EISA_ID_TO_NUM (Acpi->HID) == 0x0604) {
1559 return BDS_EFI_ACPI_FLOPPY_BOOT;
1560 }
1561 break;
1562 case MESSAGING_DEVICE_PATH:
1563 //
1564 // Get the last device path node
1565 //
1566 LastDeviceNode = NextDevicePathNode (TempDevicePath);
1567 if (DevicePathSubType(LastDeviceNode) == MSG_DEVICE_LOGICAL_UNIT_DP) {
1568 //
1569 // if the next node type is Device Logical Unit, which specify the Logical Unit Number (LUN),
1570 // skit it
1571 //
1572 LastDeviceNode = NextDevicePathNode (LastDeviceNode);
1573 }
1574 //
1575 // if the device path not only point to driver device, it is not a messaging device path,
1576 //
1577 if (!IsDevicePathEndType (LastDeviceNode)) {
1578 break;
1579 }
1580
1581 if (DevicePathSubType(TempDevicePath) == MSG_ATAPI_DP) {
1582 return BDS_EFI_MESSAGE_ATAPI_BOOT;
1583 } else if (DevicePathSubType(TempDevicePath) == MSG_USB_DP) {
1584 return BDS_EFI_MESSAGE_USB_DEVICE_BOOT;
1585 } else if (DevicePathSubType(TempDevicePath) == MSG_SCSI_DP) {
1586 return BDS_EFI_MESSAGE_SCSI_BOOT;
1587 }
1588 return BDS_EFI_MESSAGE_MISC_BOOT;
1589 default:
1590 break;
1591 }
1592 TempDevicePath = NextDevicePathNode (TempDevicePath);
1593 }
1594
1595 return BDS_EFI_UNSUPPORT;
1596 }
1597
1598 /**
1599 Check whether the Device path in a boot option point to a valid bootable device,
1600 And if CheckMedia is true, check the device is ready to boot now.
1601
1602 @param DevPath the Device path in a boot option
1603 @param CheckMedia if true, check the device is ready to boot now.
1604
1605 @retval TRUE the Device path is valid
1606 @retval FALSE the Device path is invalid .
1607
1608 **/
1609 BOOLEAN
1610 EFIAPI
1611 BdsLibIsValidEFIBootOptDevicePath (
1612 IN EFI_DEVICE_PATH_PROTOCOL *DevPath,
1613 IN BOOLEAN CheckMedia
1614 )
1615 {
1616 EFI_STATUS Status;
1617 EFI_HANDLE Handle;
1618 EFI_DEVICE_PATH_PROTOCOL *TempDevicePath;
1619 EFI_DEVICE_PATH_PROTOCOL *LastDeviceNode;
1620 EFI_BLOCK_IO_PROTOCOL *BlockIo;
1621
1622 TempDevicePath = DevPath;
1623 LastDeviceNode = DevPath;
1624
1625 //
1626 // Check if it's a valid boot option for network boot device
1627 // Only check if there is SimpleNetworkProtocol installed. If yes, that means
1628 // there is the network card there.
1629 //
1630 Status = gBS->LocateDevicePath (
1631 &gEfiSimpleNetworkProtocolGuid,
1632 &TempDevicePath,
1633 &Handle
1634 );
1635 if (EFI_ERROR (Status)) {
1636 //
1637 // Device not present so see if we need to connect it
1638 //
1639 TempDevicePath = DevPath;
1640 BdsLibConnectDevicePath (TempDevicePath);
1641 Status = gBS->LocateDevicePath (
1642 &gEfiSimpleNetworkProtocolGuid,
1643 &TempDevicePath,
1644 &Handle
1645 );
1646 }
1647
1648 if (!EFI_ERROR (Status)) {
1649 if (CheckMedia) {
1650 //
1651 // Test if it is ready to boot now
1652 //
1653 if (BdsLibNetworkBootWithMediaPresent(DevPath)) {
1654 return TRUE;
1655 }
1656 } else {
1657 return TRUE;
1658 }
1659 }
1660
1661 //
1662 // If the boot option point to a file, it is a valid EFI boot option,
1663 // and assume it is ready to boot now
1664 //
1665 while (!IsDevicePathEnd (TempDevicePath)) {
1666 LastDeviceNode = TempDevicePath;
1667 TempDevicePath = NextDevicePathNode (TempDevicePath);
1668 }
1669 if ((DevicePathType (LastDeviceNode) == MEDIA_DEVICE_PATH) &&
1670 (DevicePathSubType (LastDeviceNode) == MEDIA_FILEPATH_DP)) {
1671 return TRUE;
1672 }
1673
1674 //
1675 // Check if it's a valid boot option for internal Shell
1676 //
1677 if (EfiGetNameGuidFromFwVolDevicePathNode ((MEDIA_FW_VOL_FILEPATH_DEVICE_PATH *) LastDeviceNode) != NULL) {
1678 //
1679 // If the boot option point to Internal FV shell, make sure it is valid
1680 //
1681 TempDevicePath = DevPath;
1682 Status = BdsLibUpdateFvFileDevicePath (&TempDevicePath, &gEfiShellFileGuid);
1683 if (Status == EFI_ALREADY_STARTED) {
1684 return TRUE;
1685 } else {
1686 if (Status == EFI_SUCCESS) {
1687 FreePool (TempDevicePath);
1688 }
1689 return FALSE;
1690 }
1691 }
1692
1693 //
1694 // If the boot option point to a blockIO device, no matter whether or not it is a removeable device, it is a valid EFI boot option
1695 //
1696 TempDevicePath = DevPath;
1697 Status = gBS->LocateDevicePath (&gEfiBlockIoProtocolGuid, &TempDevicePath, &Handle);
1698 if (EFI_ERROR (Status)) {
1699 //
1700 // Device not present so see if we need to connect it
1701 //
1702 Status = BdsLibConnectDevicePath (DevPath);
1703 if (!EFI_ERROR (Status)) {
1704 //
1705 // Try again to get the Block Io protocol after we did the connect
1706 //
1707 TempDevicePath = DevPath;
1708 Status = gBS->LocateDevicePath (&gEfiBlockIoProtocolGuid, &TempDevicePath, &Handle);
1709 }
1710 }
1711
1712 if (!EFI_ERROR (Status)) {
1713 Status = gBS->HandleProtocol (Handle, &gEfiBlockIoProtocolGuid, (VOID **)&BlockIo);
1714 if (!EFI_ERROR (Status)) {
1715 if (CheckMedia) {
1716 //
1717 // Test if it is ready to boot now
1718 //
1719 if (BdsLibGetBootableHandle (DevPath) != NULL) {
1720 return TRUE;
1721 }
1722 } else {
1723 return TRUE;
1724 }
1725 }
1726 } else {
1727 //
1728 // if the boot option point to a simple file protocol which does not consume block Io protocol, it is also a valid EFI boot option,
1729 //
1730 Status = gBS->LocateDevicePath (&gEfiSimpleFileSystemProtocolGuid, &TempDevicePath, &Handle);
1731 if (!EFI_ERROR (Status)) {
1732 if (CheckMedia) {
1733 //
1734 // Test if it is ready to boot now
1735 //
1736 if (BdsLibGetBootableHandle (DevPath) != NULL) {
1737 return TRUE;
1738 }
1739 } else {
1740 return TRUE;
1741 }
1742 }
1743 }
1744
1745 return FALSE;
1746 }
1747
1748
1749 /**
1750 According to a file guild, check a Fv file device path is valid. If it is invalid,
1751 try to return the valid device path.
1752 FV address maybe changes for memory layout adjust from time to time, use this function
1753 could promise the Fv file device path is right.
1754
1755 @param DevicePath on input, the Fv file device path need to check on
1756 output, the updated valid Fv file device path
1757 @param FileGuid the Fv file guild
1758
1759 @retval EFI_INVALID_PARAMETER the input DevicePath or FileGuid is invalid
1760 parameter
1761 @retval EFI_UNSUPPORTED the input DevicePath does not contain Fv file
1762 guild at all
1763 @retval EFI_ALREADY_STARTED the input DevicePath has pointed to Fv file, it is
1764 valid
1765 @retval EFI_SUCCESS has successfully updated the invalid DevicePath,
1766 and return the updated device path in DevicePath
1767
1768 **/
1769 EFI_STATUS
1770 EFIAPI
1771 BdsLibUpdateFvFileDevicePath (
1772 IN OUT EFI_DEVICE_PATH_PROTOCOL ** DevicePath,
1773 IN EFI_GUID *FileGuid
1774 )
1775 {
1776 EFI_DEVICE_PATH_PROTOCOL *TempDevicePath;
1777 EFI_DEVICE_PATH_PROTOCOL *LastDeviceNode;
1778 EFI_STATUS Status;
1779 EFI_GUID *GuidPoint;
1780 UINTN Index;
1781 UINTN FvHandleCount;
1782 EFI_HANDLE *FvHandleBuffer;
1783 EFI_FV_FILETYPE Type;
1784 UINTN Size;
1785 EFI_FV_FILE_ATTRIBUTES Attributes;
1786 UINT32 AuthenticationStatus;
1787 BOOLEAN FindFvFile;
1788 EFI_LOADED_IMAGE_PROTOCOL *LoadedImage;
1789 EFI_FIRMWARE_VOLUME2_PROTOCOL *Fv;
1790 MEDIA_FW_VOL_FILEPATH_DEVICE_PATH FvFileNode;
1791 EFI_HANDLE FoundFvHandle;
1792 EFI_DEVICE_PATH_PROTOCOL *NewDevicePath;
1793
1794 if ((DevicePath == NULL) || (*DevicePath == NULL)) {
1795 return EFI_INVALID_PARAMETER;
1796 }
1797 if (FileGuid == NULL) {
1798 return EFI_INVALID_PARAMETER;
1799 }
1800
1801 //
1802 // Check whether the device path point to the default the input Fv file
1803 //
1804 TempDevicePath = *DevicePath;
1805 LastDeviceNode = TempDevicePath;
1806 while (!IsDevicePathEnd (TempDevicePath)) {
1807 LastDeviceNode = TempDevicePath;
1808 TempDevicePath = NextDevicePathNode (TempDevicePath);
1809 }
1810 GuidPoint = EfiGetNameGuidFromFwVolDevicePathNode (
1811 (MEDIA_FW_VOL_FILEPATH_DEVICE_PATH *) LastDeviceNode
1812 );
1813 if (GuidPoint == NULL) {
1814 //
1815 // if this option does not points to a Fv file, just return EFI_UNSUPPORTED
1816 //
1817 return EFI_UNSUPPORTED;
1818 }
1819 if (!CompareGuid (GuidPoint, FileGuid)) {
1820 //
1821 // If the Fv file is not the input file guid, just return EFI_UNSUPPORTED
1822 //
1823 return EFI_UNSUPPORTED;
1824 }
1825
1826 //
1827 // Check whether the input Fv file device path is valid
1828 //
1829 TempDevicePath = *DevicePath;
1830 FoundFvHandle = NULL;
1831 Status = gBS->LocateDevicePath (
1832 &gEfiFirmwareVolume2ProtocolGuid,
1833 &TempDevicePath,
1834 &FoundFvHandle
1835 );
1836 if (!EFI_ERROR (Status)) {
1837 Status = gBS->HandleProtocol (
1838 FoundFvHandle,
1839 &gEfiFirmwareVolume2ProtocolGuid,
1840 (VOID **) &Fv
1841 );
1842 if (!EFI_ERROR (Status)) {
1843 //
1844 // Set FV ReadFile Buffer as NULL, only need to check whether input Fv file exist there
1845 //
1846 Status = Fv->ReadFile (
1847 Fv,
1848 FileGuid,
1849 NULL,
1850 &Size,
1851 &Type,
1852 &Attributes,
1853 &AuthenticationStatus
1854 );
1855 if (!EFI_ERROR (Status)) {
1856 return EFI_ALREADY_STARTED;
1857 }
1858 }
1859 }
1860
1861 //
1862 // Look for the input wanted FV file in current FV
1863 // First, try to look for in Bds own FV. Bds and input wanted FV file usually are in the same FV
1864 //
1865 FindFvFile = FALSE;
1866 FoundFvHandle = NULL;
1867 Status = gBS->HandleProtocol (
1868 mBdsImageHandle,
1869 &gEfiLoadedImageProtocolGuid,
1870 (VOID **) &LoadedImage
1871 );
1872 if (!EFI_ERROR (Status)) {
1873 Status = gBS->HandleProtocol (
1874 LoadedImage->DeviceHandle,
1875 &gEfiFirmwareVolume2ProtocolGuid,
1876 (VOID **) &Fv
1877 );
1878 if (!EFI_ERROR (Status)) {
1879 Status = Fv->ReadFile (
1880 Fv,
1881 FileGuid,
1882 NULL,
1883 &Size,
1884 &Type,
1885 &Attributes,
1886 &AuthenticationStatus
1887 );
1888 if (!EFI_ERROR (Status)) {
1889 FindFvFile = TRUE;
1890 FoundFvHandle = LoadedImage->DeviceHandle;
1891 }
1892 }
1893 }
1894 //
1895 // Second, if fail to find, try to enumerate all FV
1896 //
1897 if (!FindFvFile) {
1898 FvHandleBuffer = NULL;
1899 gBS->LocateHandleBuffer (
1900 ByProtocol,
1901 &gEfiFirmwareVolume2ProtocolGuid,
1902 NULL,
1903 &FvHandleCount,
1904 &FvHandleBuffer
1905 );
1906 for (Index = 0; Index < FvHandleCount; Index++) {
1907 gBS->HandleProtocol (
1908 FvHandleBuffer[Index],
1909 &gEfiFirmwareVolume2ProtocolGuid,
1910 (VOID **) &Fv
1911 );
1912
1913 Status = Fv->ReadFile (
1914 Fv,
1915 FileGuid,
1916 NULL,
1917 &Size,
1918 &Type,
1919 &Attributes,
1920 &AuthenticationStatus
1921 );
1922 if (EFI_ERROR (Status)) {
1923 //
1924 // Skip if input Fv file not in the FV
1925 //
1926 continue;
1927 }
1928 FindFvFile = TRUE;
1929 FoundFvHandle = FvHandleBuffer[Index];
1930 break;
1931 }
1932
1933 if (FvHandleBuffer != NULL) {
1934 FreePool (FvHandleBuffer);
1935 }
1936 }
1937
1938 if (FindFvFile) {
1939 //
1940 // Build the shell device path
1941 //
1942 NewDevicePath = DevicePathFromHandle (FoundFvHandle);
1943 EfiInitializeFwVolDevicepathNode (&FvFileNode, FileGuid);
1944 NewDevicePath = AppendDevicePathNode (NewDevicePath, (EFI_DEVICE_PATH_PROTOCOL *) &FvFileNode);
1945 *DevicePath = NewDevicePath;
1946 return EFI_SUCCESS;
1947 }
1948 return EFI_NOT_FOUND;
1949 }