TianoCore EDK2 master
Loading...
Searching...
No Matches
BmBoot.c
Go to the documentation of this file.
1
11#include "InternalBm.h"
12
13EFI_RAM_DISK_PROTOCOL *mRamDisk = NULL;
14
15EFI_BOOT_MANAGER_REFRESH_LEGACY_BOOT_OPTION mBmRefreshLegacyBootOption = NULL;
17
23 0xfab7e9e1, 0x39dd, 0x4f2b, { 0x84, 0x08, 0xe2, 0x0e, 0x90, 0x6c, 0xb6, 0xde }
24};
25EFI_GUID mBmAutoCreateBootOptionGuid = {
26 0x8108ac4e, 0x9f11, 0x4d59, { 0x85, 0x0e, 0xe2, 0x1a, 0x52, 0x2c, 0x59, 0xb2 }
27};
28
37VOID
38EFIAPI
40 IN EFI_EVENT Event,
41 IN VOID *Context
42 )
43{
44 //
45 // Record the performance data for End of BDS
46 //
48
49 return;
50}
51
58VOID
59EFIAPI
61 EFI_BOOT_MANAGER_REFRESH_LEGACY_BOOT_OPTION RefreshLegacyBootOption,
63 )
64{
65 mBmRefreshLegacyBootOption = RefreshLegacyBootOption;
66 mBmLegacyBoot = LegacyBoot;
67}
68
77BOOLEAN
80 )
81{
82 if ((BootOption->OptionalDataSize == sizeof (EFI_GUID)) &&
83 CompareGuid ((EFI_GUID *)BootOption->OptionalData, &mBmAutoCreateBootOptionGuid)
84 )
85 {
86 return TRUE;
87 } else {
88 return FALSE;
89 }
90}
91
100UINTN
102 IN EFI_BOOT_MANAGER_LOAD_OPTION *OptionToFind
103 )
104{
105 EFI_STATUS Status;
107 UINTN OptionNumber;
108 CHAR16 OptionName[BM_OPTION_NAME_LEN];
109 EFI_BOOT_MANAGER_LOAD_OPTION *BootOptions;
110 UINTN BootOptionCount;
111 UINTN Index;
112
113 OptionNumber = LoadOptionNumberUnassigned;
114
115 //
116 // Try to match the variable exactly if the option number is assigned
117 //
118 if (OptionToFind->OptionNumber != LoadOptionNumberUnassigned) {
120 OptionName,
121 sizeof (OptionName),
122 L"%s%04x",
123 mBmLoadOptionName[OptionToFind->OptionType],
124 OptionToFind->OptionNumber
125 );
126 Status = EfiBootManagerVariableToLoadOption (OptionName, &BootOption);
127
128 if (!EFI_ERROR (Status)) {
129 ASSERT (OptionToFind->OptionNumber == BootOption.OptionNumber);
130 if ((OptionToFind->Attributes == BootOption.Attributes) &&
131 (StrCmp (OptionToFind->Description, BootOption.Description) == 0) &&
132 (CompareMem (OptionToFind->FilePath, BootOption.FilePath, GetDevicePathSize (OptionToFind->FilePath)) == 0) &&
133 (OptionToFind->OptionalDataSize == BootOption.OptionalDataSize) &&
134 (CompareMem (OptionToFind->OptionalData, BootOption.OptionalData, OptionToFind->OptionalDataSize) == 0)
135 )
136 {
137 OptionNumber = OptionToFind->OptionNumber;
138 }
139
140 EfiBootManagerFreeLoadOption (&BootOption);
141 }
142 }
143
144 //
145 // The option number assigned is either incorrect or unassigned.
146 //
147 if (OptionNumber == LoadOptionNumberUnassigned) {
148 BootOptions = EfiBootManagerGetLoadOptions (&BootOptionCount, LoadOptionTypeBoot);
149
150 // Only assert if the BootOption is non-zero
151 if ((BootOptions == NULL) && (BootOptionCount > 0)) {
152 ASSERT (BootOptions != NULL);
153 return LoadOptionNumberUnassigned;
154 }
155
156 Index = EfiBootManagerFindLoadOption (OptionToFind, BootOptions, BootOptionCount);
157 if (Index != -1) {
158 OptionNumber = BootOptions[Index].OptionNumber;
159 }
160
161 EfiBootManagerFreeLoadOptions (BootOptions, BootOptionCount);
162 }
163
164 return OptionNumber;
165}
166
178 )
179{
180 EFI_STATUS Status;
181 UINTN Index;
182 EFI_DEVICE_PATH_PROTOCOL *FvFileNode;
183 EFI_HANDLE FvHandle;
184 EFI_LOADED_IMAGE_PROTOCOL *LoadedImage;
185 UINTN FvHandleCount;
186 EFI_HANDLE *FvHandles;
187 EFI_DEVICE_PATH_PROTOCOL *NewDevicePath;
188 EFI_DEVICE_PATH_PROTOCOL *FullPath;
189
190 //
191 // Get the file buffer by using the exactly FilePath.
192 //
193 FvFileNode = FilePath;
194 Status = gBS->LocateDevicePath (&gEfiFirmwareVolume2ProtocolGuid, &FvFileNode, &FvHandle);
195 if (!EFI_ERROR (Status)) {
196 return DuplicateDevicePath (FilePath);
197 }
198
199 //
200 // Only wide match other FVs if it's a memory mapped FV file path.
201 //
202 if ((DevicePathType (FilePath) != HARDWARE_DEVICE_PATH) || (DevicePathSubType (FilePath) != HW_MEMMAP_DP)) {
203 return NULL;
204 }
205
206 FvFileNode = NextDevicePathNode (FilePath);
207
208 //
209 // Firstly find the FV file in current FV
210 //
211 gBS->HandleProtocol (
213 &gEfiLoadedImageProtocolGuid,
214 (VOID **)&LoadedImage
215 );
216 NewDevicePath = AppendDevicePathNode (DevicePathFromHandle (LoadedImage->DeviceHandle), FvFileNode);
217 FullPath = BmAdjustFvFilePath (NewDevicePath);
218 FreePool (NewDevicePath);
219 if (FullPath != NULL) {
220 return FullPath;
221 }
222
223 //
224 // Secondly find the FV file in all other FVs
225 //
226 gBS->LocateHandleBuffer (
228 &gEfiFirmwareVolume2ProtocolGuid,
229 NULL,
230 &FvHandleCount,
231 &FvHandles
232 );
233 for (Index = 0; Index < FvHandleCount; Index++) {
234 if (FvHandles[Index] == LoadedImage->DeviceHandle) {
235 //
236 // Skip current FV, it was handed in first step.
237 //
238 continue;
239 }
240
241 NewDevicePath = AppendDevicePathNode (DevicePathFromHandle (FvHandles[Index]), FvFileNode);
242 FullPath = BmAdjustFvFilePath (NewDevicePath);
243 FreePool (NewDevicePath);
244 if (FullPath != NULL) {
245 break;
246 }
247 }
248
249 if (FvHandles != NULL) {
250 FreePool (FvHandles);
251 }
252
253 return FullPath;
254}
255
266BOOLEAN
268 IN EFI_DEVICE_PATH_PROTOCOL *DevicePath
269 )
270{
271 EFI_STATUS Status;
272 EFI_HANDLE Handle;
274
275 Node = DevicePath;
276 Status = gBS->LocateDevicePath (&gEfiFirmwareVolume2ProtocolGuid, &Node, &Handle);
277 if (!EFI_ERROR (Status)) {
278 return TRUE;
279 }
280
281 if ((DevicePathType (DevicePath) == HARDWARE_DEVICE_PATH) && (DevicePathSubType (DevicePath) == HW_MEMMAP_DP)) {
282 DevicePath = NextDevicePathNode (DevicePath);
283 if ((DevicePathType (DevicePath) == MEDIA_DEVICE_PATH) && (DevicePathSubType (DevicePath) == MEDIA_PIWG_FW_FILE_DP)) {
284 return IsDevicePathEnd (NextDevicePathNode (DevicePath));
285 }
286 }
287
288 return FALSE;
289}
290
302BOOLEAN
304 IN EFI_USB_IO_PROTOCOL *UsbIo,
305 IN USB_CLASS_DEVICE_PATH *UsbClass
306 )
307{
308 EFI_STATUS Status;
311 UINT8 DeviceClass;
312 UINT8 DeviceSubClass;
313 UINT8 DeviceProtocol;
314
315 if ((DevicePathType (UsbClass) != MESSAGING_DEVICE_PATH) ||
316 (DevicePathSubType (UsbClass) != MSG_USB_CLASS_DP))
317 {
318 return FALSE;
319 }
320
321 //
322 // Check Vendor Id and Product Id.
323 //
324 Status = UsbIo->UsbGetDeviceDescriptor (UsbIo, &DevDesc);
325 if (EFI_ERROR (Status)) {
326 return FALSE;
327 }
328
329 if ((UsbClass->VendorId != 0xffff) &&
330 (UsbClass->VendorId != DevDesc.IdVendor))
331 {
332 return FALSE;
333 }
334
335 if ((UsbClass->ProductId != 0xffff) &&
336 (UsbClass->ProductId != DevDesc.IdProduct))
337 {
338 return FALSE;
339 }
340
341 DeviceClass = DevDesc.DeviceClass;
342 DeviceSubClass = DevDesc.DeviceSubClass;
343 DeviceProtocol = DevDesc.DeviceProtocol;
344 if (DeviceClass == 0) {
345 //
346 // If Class in Device Descriptor is set to 0, use the Class, SubClass and
347 // Protocol in Interface Descriptor instead.
348 //
349 Status = UsbIo->UsbGetInterfaceDescriptor (UsbIo, &IfDesc);
350 if (EFI_ERROR (Status)) {
351 return FALSE;
352 }
353
354 DeviceClass = IfDesc.InterfaceClass;
355 DeviceSubClass = IfDesc.InterfaceSubClass;
356 DeviceProtocol = IfDesc.InterfaceProtocol;
357 }
358
359 //
360 // Check Class, SubClass and Protocol.
361 //
362 if ((UsbClass->DeviceClass != 0xff) &&
363 (UsbClass->DeviceClass != DeviceClass))
364 {
365 return FALSE;
366 }
367
368 if ((UsbClass->DeviceSubClass != 0xff) &&
369 (UsbClass->DeviceSubClass != DeviceSubClass))
370 {
371 return FALSE;
372 }
373
374 if ((UsbClass->DeviceProtocol != 0xff) &&
375 (UsbClass->DeviceProtocol != DeviceProtocol))
376 {
377 return FALSE;
378 }
379
380 return TRUE;
381}
382
394BOOLEAN
396 IN EFI_USB_IO_PROTOCOL *UsbIo,
397 IN USB_WWID_DEVICE_PATH *UsbWwid
398 )
399{
400 EFI_STATUS Status;
403 UINT16 *LangIdTable;
404 UINT16 TableSize;
405 UINT16 Index;
406 CHAR16 *CompareStr;
407 UINTN CompareLen;
408 CHAR16 *SerialNumberStr;
409 UINTN Length;
410
411 if ((DevicePathType (UsbWwid) != MESSAGING_DEVICE_PATH) ||
412 (DevicePathSubType (UsbWwid) != MSG_USB_WWID_DP))
413 {
414 return FALSE;
415 }
416
417 //
418 // Check Vendor Id and Product Id.
419 //
420 Status = UsbIo->UsbGetDeviceDescriptor (UsbIo, &DevDesc);
421 if (EFI_ERROR (Status)) {
422 return FALSE;
423 }
424
425 if ((DevDesc.IdVendor != UsbWwid->VendorId) ||
426 (DevDesc.IdProduct != UsbWwid->ProductId))
427 {
428 return FALSE;
429 }
430
431 //
432 // Check Interface Number.
433 //
434 Status = UsbIo->UsbGetInterfaceDescriptor (UsbIo, &IfDesc);
435 if (EFI_ERROR (Status)) {
436 return FALSE;
437 }
438
439 if (IfDesc.InterfaceNumber != UsbWwid->InterfaceNumber) {
440 return FALSE;
441 }
442
443 //
444 // Check Serial Number.
445 //
446 if (DevDesc.StrSerialNumber == 0) {
447 return FALSE;
448 }
449
450 //
451 // Get all supported languages.
452 //
453 TableSize = 0;
454 LangIdTable = NULL;
455 Status = UsbIo->UsbGetSupportedLanguages (UsbIo, &LangIdTable, &TableSize);
456 if (EFI_ERROR (Status) || (TableSize == 0) || (LangIdTable == NULL)) {
457 return FALSE;
458 }
459
460 //
461 // Serial number in USB WWID device path is the last 64-or-less UTF-16 characters.
462 //
463 CompareStr = (CHAR16 *)(UINTN)(UsbWwid + 1);
464 CompareLen = (DevicePathNodeLength (UsbWwid) - sizeof (USB_WWID_DEVICE_PATH)) / sizeof (CHAR16);
465 if (CompareStr[CompareLen - 1] == L'\0') {
466 CompareLen--;
467 }
468
469 //
470 // Compare serial number in each supported language.
471 //
472 for (Index = 0; Index < TableSize / sizeof (UINT16); Index++) {
473 SerialNumberStr = NULL;
474 Status = UsbIo->UsbGetStringDescriptor (
475 UsbIo,
476 LangIdTable[Index],
477 DevDesc.StrSerialNumber,
478 &SerialNumberStr
479 );
480 if (EFI_ERROR (Status) || (SerialNumberStr == NULL)) {
481 continue;
482 }
483
484 Length = StrLen (SerialNumberStr);
485 if ((Length >= CompareLen) &&
486 (CompareMem (SerialNumberStr + Length - CompareLen, CompareStr, CompareLen * sizeof (CHAR16)) == 0))
487 {
488 FreePool (SerialNumberStr);
489 return TRUE;
490 }
491
492 FreePool (SerialNumberStr);
493 }
494
495 return FALSE;
496}
497
515 IN EFI_DEVICE_PATH_PROTOCOL *DevicePath,
516 IN UINTN ParentDevicePathSize,
517 OUT UINTN *UsbIoHandleCount
518 )
519{
520 EFI_STATUS Status;
521 EFI_HANDLE *UsbIoHandles;
522 EFI_DEVICE_PATH_PROTOCOL *UsbIoDevicePath;
523 EFI_USB_IO_PROTOCOL *UsbIo;
524 UINTN Index;
525 BOOLEAN Matched;
526
527 ASSERT (UsbIoHandleCount != NULL);
528
529 //
530 // Get all UsbIo Handles.
531 //
532 Status = gBS->LocateHandleBuffer (
534 &gEfiUsbIoProtocolGuid,
535 NULL,
536 UsbIoHandleCount,
537 &UsbIoHandles
538 );
539 if (EFI_ERROR (Status)) {
540 *UsbIoHandleCount = 0;
541 UsbIoHandles = NULL;
542 }
543
544 for (Index = 0; Index < *UsbIoHandleCount; ) {
545 //
546 // Get the Usb IO interface.
547 //
548 Status = gBS->HandleProtocol (
549 UsbIoHandles[Index],
550 &gEfiUsbIoProtocolGuid,
551 (VOID **)&UsbIo
552 );
553 UsbIoDevicePath = DevicePathFromHandle (UsbIoHandles[Index]);
554 Matched = FALSE;
555 if (!EFI_ERROR (Status) && (UsbIoDevicePath != NULL)) {
556 //
557 // Compare starting part of UsbIoHandle's device path with ParentDevicePath.
558 //
559 if (CompareMem (UsbIoDevicePath, DevicePath, ParentDevicePathSize) == 0) {
560 if (BmMatchUsbClass (UsbIo, (USB_CLASS_DEVICE_PATH *)((UINTN)DevicePath + ParentDevicePathSize)) ||
561 BmMatchUsbWwid (UsbIo, (USB_WWID_DEVICE_PATH *)((UINTN)DevicePath + ParentDevicePathSize)))
562 {
563 Matched = TRUE;
564 }
565 }
566 }
567
568 if (!Matched) {
569 (*UsbIoHandleCount)--;
570 CopyMem (&UsbIoHandles[Index], &UsbIoHandles[Index + 1], (*UsbIoHandleCount - Index) * sizeof (EFI_HANDLE));
571 } else {
572 Index++;
573 }
574 }
575
576 return UsbIoHandles;
577}
578
609 IN EFI_DEVICE_PATH_PROTOCOL *ShortformNode
610 )
611{
612 UINTN ParentDevicePathSize;
613 EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath;
614 EFI_DEVICE_PATH_PROTOCOL *NextFullPath;
615 EFI_HANDLE *Handles;
616 UINTN HandleCount;
617 UINTN Index;
618 BOOLEAN GetNext;
619
620 NextFullPath = NULL;
621 GetNext = (BOOLEAN)(FullPath == NULL);
622 ParentDevicePathSize = (UINTN)ShortformNode - (UINTN)FilePath;
623 RemainingDevicePath = NextDevicePathNode (ShortformNode);
624 Handles = BmFindUsbDevice (FilePath, ParentDevicePathSize, &HandleCount);
625
626 for (Index = 0; Index < HandleCount; Index++) {
627 FilePath = AppendDevicePath (DevicePathFromHandle (Handles[Index]), RemainingDevicePath);
628 if (FilePath == NULL) {
629 //
630 // Out of memory.
631 //
632 continue;
633 }
634
635 NextFullPath = BmGetNextLoadOptionDevicePath (FilePath, NULL);
636 FreePool (FilePath);
637 if (NextFullPath == NULL) {
638 //
639 // No BlockIo or SimpleFileSystem under FilePath.
640 //
641 continue;
642 }
643
644 if (GetNext) {
645 break;
646 } else {
647 GetNext = (BOOLEAN)(CompareMem (NextFullPath, FullPath, GetDevicePathSize (NextFullPath)) == 0);
648 FreePool (NextFullPath);
649 NextFullPath = NULL;
650 }
651 }
652
653 if (Handles != NULL) {
654 FreePool (Handles);
655 }
656
657 return NextFullPath;
658}
659
675 )
676{
677 EFI_STATUS Status;
678 UINTN Index;
679 UINTN HandleCount;
680 EFI_HANDLE *Handles;
681 EFI_BLOCK_IO_PROTOCOL *BlockIo;
682 UINTN MediaType;
683 EFI_DEVICE_PATH_PROTOCOL *NextFullPath;
684 BOOLEAN GetNext;
685
687 Status = gBS->LocateHandleBuffer (ByProtocol, &gEfiSimpleFileSystemProtocolGuid, NULL, &HandleCount, &Handles);
688 if (EFI_ERROR (Status)) {
689 HandleCount = 0;
690 Handles = NULL;
691 }
692
693 GetNext = (BOOLEAN)(FullPath == NULL);
694 NextFullPath = NULL;
695 //
696 // Enumerate all removable media devices followed by all fixed media devices,
697 // followed by media devices which don't layer on block io.
698 //
699 for (MediaType = 0; MediaType < 3; MediaType++) {
700 for (Index = 0; Index < HandleCount; Index++) {
701 Status = gBS->HandleProtocol (Handles[Index], &gEfiBlockIoProtocolGuid, (VOID *)&BlockIo);
702 if (EFI_ERROR (Status)) {
703 BlockIo = NULL;
704 }
705
706 if (((MediaType == 0) && (BlockIo != NULL) && BlockIo->Media->RemovableMedia) ||
707 ((MediaType == 1) && (BlockIo != NULL) && !BlockIo->Media->RemovableMedia) ||
708 ((MediaType == 2) && (BlockIo == NULL))
709 )
710 {
711 NextFullPath = AppendDevicePath (DevicePathFromHandle (Handles[Index]), FilePath);
712 if (GetNext) {
713 break;
714 } else {
715 GetNext = (BOOLEAN)(CompareMem (NextFullPath, FullPath, GetDevicePathSize (NextFullPath)) == 0);
716 FreePool (NextFullPath);
717 NextFullPath = NULL;
718 }
719 }
720 }
721
722 if (NextFullPath != NULL) {
723 break;
724 }
725 }
726
727 if (Handles != NULL) {
728 FreePool (Handles);
729 }
730
731 return NextFullPath;
732}
733
749 )
750{
751 EFI_STATUS Status;
752 UINTN Index;
753 UINTN HandleCount;
754 EFI_HANDLE *Handles;
755 EFI_DEVICE_PATH_PROTOCOL *NextFullPath;
756 EFI_DEVICE_PATH_PROTOCOL *RamDiskDevicePath;
757 BOOLEAN GetNext;
758
760 Status = gBS->LocateHandleBuffer (ByProtocol, &gEfiLoadFileProtocolGuid, NULL, &HandleCount, &Handles);
761 if (EFI_ERROR (Status)) {
762 HandleCount = 0;
763 Handles = NULL;
764 }
765
766 NextFullPath = NULL;
767 GetNext = (BOOLEAN)(FullPath == NULL);
768 for (Index = 0; Index < HandleCount; Index++) {
769 NextFullPath = BmExpandLoadFile (Handles[Index], FilePath);
770
771 if (NextFullPath == NULL) {
772 continue;
773 }
774
775 if (GetNext) {
776 break;
777 } else {
778 GetNext = (BOOLEAN)(CompareMem (NextFullPath, FullPath, GetDevicePathSize (NextFullPath)) == 0);
779 //
780 // Free the resource occupied by the RAM disk.
781 //
782 RamDiskDevicePath = BmGetRamDiskDevicePath (NextFullPath);
783 if (RamDiskDevicePath != NULL) {
784 BmDestroyRamDisk (RamDiskDevicePath);
785 FreePool (RamDiskDevicePath);
786 }
787
788 FreePool (NextFullPath);
789 NextFullPath = NULL;
790 }
791 }
792
793 if (Handles != NULL) {
794 FreePool (Handles);
795 }
796
797 return NextFullPath;
798}
799
806VOID
808 IN OUT EFI_DEVICE_PATH_PROTOCOL **CachedDevicePath,
809 IN EFI_DEVICE_PATH_PROTOCOL *DevicePath
810 )
811{
812 EFI_DEVICE_PATH_PROTOCOL *TempDevicePath;
813 UINTN Count;
814
815 if (BmMatchDevicePaths (*CachedDevicePath, DevicePath)) {
816 TempDevicePath = *CachedDevicePath;
817 *CachedDevicePath = BmDelPartMatchInstance (*CachedDevicePath, DevicePath);
818 FreePool (TempDevicePath);
819 }
820
821 if (*CachedDevicePath == NULL) {
822 *CachedDevicePath = DuplicateDevicePath (DevicePath);
823 return;
824 }
825
826 TempDevicePath = *CachedDevicePath;
827 *CachedDevicePath = AppendDevicePathInstance (DevicePath, *CachedDevicePath);
828 if (TempDevicePath != NULL) {
829 FreePool (TempDevicePath);
830 }
831
832 //
833 // Here limit the device path instance number to 12, which is max number for a system support 3 IDE controller
834 // If the user try to boot many OS in different HDs or partitions, in theory, the 'HDDP' variable maybe become larger and larger.
835 //
836 Count = 0;
837 TempDevicePath = *CachedDevicePath;
838 while (!IsDevicePathEnd (TempDevicePath)) {
839 TempDevicePath = NextDevicePathNode (TempDevicePath);
840 //
841 // Parse one instance
842 //
843 while (!IsDevicePathEndType (TempDevicePath)) {
844 TempDevicePath = NextDevicePathNode (TempDevicePath);
845 }
846
847 Count++;
848 //
849 // If the CachedDevicePath variable contain too much instance, only remain 12 instances.
850 //
851 if (Count == 12) {
852 SetDevicePathEndNode (TempDevicePath);
853 break;
854 }
855 }
856}
857
874 )
875{
876 EFI_STATUS Status;
877 UINTN BlockIoHandleCount;
878 EFI_HANDLE *BlockIoBuffer;
879 EFI_DEVICE_PATH_PROTOCOL *BlockIoDevicePath;
880 UINTN Index;
881 EFI_DEVICE_PATH_PROTOCOL *CachedDevicePath;
882 EFI_DEVICE_PATH_PROTOCOL *TempNewDevicePath;
883 EFI_DEVICE_PATH_PROTOCOL *TempDevicePath;
884 EFI_DEVICE_PATH_PROTOCOL *FullPath;
885 UINTN CachedDevicePathSize;
886 BOOLEAN NeedAdjust;
887 EFI_DEVICE_PATH_PROTOCOL *Instance;
888 UINTN Size;
889 BOOLEAN MatchFound;
890 BOOLEAN ConnectAllAttempted;
891
892 //
893 // Check if there is prestore 'HDDP' variable.
894 // If exist, search the front path which point to partition node in the variable instants.
895 // If fail to find or 'HDDP' not exist, reconnect all and search in all system
896 //
897 GetVariable2 (L"HDDP", &mBmHardDriveBootVariableGuid, (VOID **)&CachedDevicePath, &CachedDevicePathSize);
898
899 //
900 // Delete the invalid 'HDDP' variable.
901 //
902 if ((CachedDevicePath != NULL) && !IsDevicePathValid (CachedDevicePath, CachedDevicePathSize)) {
903 FreePool (CachedDevicePath);
904 CachedDevicePath = NULL;
905 Status = gRT->SetVariable (
906 L"HDDP",
908 0,
909 0,
910 NULL
911 );
912 ASSERT_EFI_ERROR (Status);
913 }
914
915 FullPath = NULL;
916 if (CachedDevicePath != NULL) {
917 TempNewDevicePath = CachedDevicePath;
918 NeedAdjust = FALSE;
919 do {
920 //
921 // Check every instance of the variable
922 // First, check whether the instance contain the partition node, which is needed for distinguishing multi
923 // partial partition boot option. Second, check whether the instance could be connected.
924 //
925 Instance = GetNextDevicePathInstance (&TempNewDevicePath, &Size);
926 if (BmMatchPartitionDevicePathNode (Instance, (HARDDRIVE_DEVICE_PATH *)FilePath)) {
927 //
928 // Connect the device path instance, the device path point to hard drive media device path node
929 // e.g. ACPI() /PCI()/ATA()/Partition()
930 //
931 Status = EfiBootManagerConnectDevicePath (Instance, NULL);
932 if (!EFI_ERROR (Status)) {
933 TempDevicePath = AppendDevicePath (Instance, NextDevicePathNode (FilePath));
934 //
935 // TempDevicePath = ACPI()/PCI()/ATA()/Partition()
936 // or = ACPI()/PCI()/ATA()/Partition()/.../A.EFI
937 //
938 // When TempDevicePath = ACPI()/PCI()/ATA()/Partition(),
939 // it may expand to two potienal full paths (nested partition, rarely happen):
940 // 1. ACPI()/PCI()/ATA()/Partition()/Partition(A1)/EFI/BootX64.EFI
941 // 2. ACPI()/PCI()/ATA()/Partition()/Partition(A2)/EFI/BootX64.EFI
942 // For simplicity, only #1 is returned.
943 //
944 FullPath = BmGetNextLoadOptionDevicePath (TempDevicePath, NULL);
945 FreePool (TempDevicePath);
946
947 if (FullPath != NULL) {
948 //
949 // Adjust the 'HDDP' instances sequence if the matched one is not first one.
950 //
951 if (NeedAdjust) {
952 BmCachePartitionDevicePath (&CachedDevicePath, Instance);
953 //
954 // Save the matching Device Path so we don't need to do a connect all next time
955 // Failing to save only impacts performance next time expanding the short-form device path
956 //
957 Status = gRT->SetVariable (
958 L"HDDP",
960 EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_NON_VOLATILE,
961 GetDevicePathSize (CachedDevicePath),
962 CachedDevicePath
963 );
964 }
965
966 FreePool (Instance);
967 FreePool (CachedDevicePath);
968 return FullPath;
969 }
970 }
971 }
972
973 //
974 // Come here means the first instance is not matched
975 //
976 NeedAdjust = TRUE;
977 FreePool (Instance);
978 } while (TempNewDevicePath != NULL);
979 }
980
981 //
982 // If we get here we fail to find or 'HDDP' not exist, and now we need
983 // to search all devices in the system for a matched partition
984 //
985 BlockIoBuffer = NULL;
986 MatchFound = FALSE;
987 ConnectAllAttempted = FALSE;
988 do {
989 if (BlockIoBuffer != NULL) {
990 FreePool (BlockIoBuffer);
991 }
992
993 Status = gBS->LocateHandleBuffer (ByProtocol, &gEfiBlockIoProtocolGuid, NULL, &BlockIoHandleCount, &BlockIoBuffer);
994 if (EFI_ERROR (Status)) {
995 BlockIoHandleCount = 0;
996 BlockIoBuffer = NULL;
997 }
998
999 //
1000 // Loop through all the device handles that support the BLOCK_IO Protocol
1001 //
1002 for (Index = 0; Index < BlockIoHandleCount; Index++) {
1003 BlockIoDevicePath = DevicePathFromHandle (BlockIoBuffer[Index]);
1004 if (BlockIoDevicePath == NULL) {
1005 continue;
1006 }
1007
1008 if (BmMatchPartitionDevicePathNode (BlockIoDevicePath, (HARDDRIVE_DEVICE_PATH *)FilePath)) {
1009 //
1010 // Find the matched partition device path
1011 //
1012 TempDevicePath = AppendDevicePath (BlockIoDevicePath, NextDevicePathNode (FilePath));
1013 FullPath = BmGetNextLoadOptionDevicePath (TempDevicePath, NULL);
1014 FreePool (TempDevicePath);
1015
1016 if (FullPath != NULL) {
1017 BmCachePartitionDevicePath (&CachedDevicePath, BlockIoDevicePath);
1018
1019 //
1020 // Save the matching Device Path so we don't need to do a connect all next time
1021 // Failing to save only impacts performance next time expanding the short-form device path
1022 //
1023 Status = gRT->SetVariable (
1024 L"HDDP",
1026 EFI_VARIABLE_BOOTSERVICE_ACCESS |
1028 GetDevicePathSize (CachedDevicePath),
1029 CachedDevicePath
1030 );
1031 MatchFound = TRUE;
1032 break;
1033 }
1034 }
1035 }
1036
1037 //
1038 // If we found a matching BLOCK_IO handle or we've already
1039 // tried a ConnectAll, we are done searching.
1040 //
1041 if (MatchFound || ConnectAllAttempted) {
1042 break;
1043 }
1044
1046 ConnectAllAttempted = TRUE;
1047 } while (1);
1048
1049 if (CachedDevicePath != NULL) {
1050 FreePool (CachedDevicePath);
1051 }
1052
1053 if (BlockIoBuffer != NULL) {
1054 FreePool (BlockIoBuffer);
1055 }
1056
1057 return FullPath;
1058}
1059
1073 IN EFI_DEVICE_PATH_PROTOCOL *DevicePath,
1075 )
1076{
1077 EFI_STATUS Status;
1078 EFI_HANDLE Handle;
1079 EFI_BLOCK_IO_PROTOCOL *BlockIo;
1080 VOID *Buffer;
1081 EFI_DEVICE_PATH_PROTOCOL *TempDevicePath;
1082 EFI_DEVICE_PATH_PROTOCOL *NextFullPath;
1083 UINTN Size;
1084 UINTN TempSize;
1085 EFI_HANDLE *SimpleFileSystemHandles;
1086 UINTN NumberSimpleFileSystemHandles;
1087 UINTN Index;
1088 BOOLEAN GetNext;
1089
1090 GetNext = (BOOLEAN)(FullPath == NULL);
1091 //
1092 // Check whether the device is connected
1093 //
1094 TempDevicePath = DevicePath;
1095 Status = gBS->LocateDevicePath (&gEfiSimpleFileSystemProtocolGuid, &TempDevicePath, &Handle);
1096 if (!EFI_ERROR (Status)) {
1097 ASSERT (IsDevicePathEnd (TempDevicePath));
1098
1099 NextFullPath = FileDevicePath (Handle, EFI_REMOVABLE_MEDIA_FILE_NAME);
1100 //
1101 // For device path pointing to simple file system, it only expands to one full path.
1102 //
1103 if (GetNext) {
1104 return NextFullPath;
1105 } else {
1106 FreePool (NextFullPath);
1107 return NULL;
1108 }
1109 }
1110
1111 Status = gBS->LocateDevicePath (&gEfiBlockIoProtocolGuid, &TempDevicePath, &Handle);
1112 ASSERT_EFI_ERROR (Status);
1113
1114 //
1115 // For device boot option only pointing to the removable device handle,
1116 // should make sure all its children handles (its child partion or media handles)
1117 // are created and connected.
1118 //
1119 gBS->ConnectController (Handle, NULL, NULL, TRUE);
1120
1121 //
1122 // Issue a dummy read to the device to check for media change.
1123 // When the removable media is changed, any Block IO read/write will
1124 // cause the BlockIo protocol be reinstalled and EFI_MEDIA_CHANGED is
1125 // returned. After the Block IO protocol is reinstalled, subsequent
1126 // Block IO read/write will success.
1127 //
1128 Status = gBS->HandleProtocol (Handle, &gEfiBlockIoProtocolGuid, (VOID **)&BlockIo);
1129 ASSERT_EFI_ERROR (Status);
1130 if (EFI_ERROR (Status)) {
1131 return NULL;
1132 }
1133
1134 Buffer = AllocatePool (BlockIo->Media->BlockSize);
1135 if (Buffer != NULL) {
1136 BlockIo->ReadBlocks (
1137 BlockIo,
1138 BlockIo->Media->MediaId,
1139 0,
1140 BlockIo->Media->BlockSize,
1141 Buffer
1142 );
1143 FreePool (Buffer);
1144 }
1145
1146 //
1147 // Detect the the default boot file from removable Media
1148 //
1149 NextFullPath = NULL;
1150 Size = GetDevicePathSize (DevicePath) - END_DEVICE_PATH_LENGTH;
1151 gBS->LocateHandleBuffer (
1152 ByProtocol,
1153 &gEfiSimpleFileSystemProtocolGuid,
1154 NULL,
1155 &NumberSimpleFileSystemHandles,
1156 &SimpleFileSystemHandles
1157 );
1158 for (Index = 0; Index < NumberSimpleFileSystemHandles; Index++) {
1159 //
1160 // Get the device path size of SimpleFileSystem handle
1161 //
1162 TempDevicePath = DevicePathFromHandle (SimpleFileSystemHandles[Index]);
1163 TempSize = GetDevicePathSize (TempDevicePath) - END_DEVICE_PATH_LENGTH;
1164 //
1165 // Check whether the device path of boot option is part of the SimpleFileSystem handle's device path
1166 //
1167 if ((Size <= TempSize) && (CompareMem (TempDevicePath, DevicePath, Size) == 0)) {
1168 NextFullPath = FileDevicePath (SimpleFileSystemHandles[Index], EFI_REMOVABLE_MEDIA_FILE_NAME);
1169 if (GetNext) {
1170 break;
1171 } else {
1172 GetNext = (BOOLEAN)(CompareMem (NextFullPath, FullPath, GetDevicePathSize (NextFullPath)) == 0);
1173 FreePool (NextFullPath);
1174 NextFullPath = NULL;
1175 }
1176 }
1177 }
1178
1179 if (SimpleFileSystemHandles != NULL) {
1180 FreePool (SimpleFileSystemHandles);
1181 }
1182
1183 return NextFullPath;
1184}
1185
1193BOOLEAN
1197 )
1198{
1199 for ( ; !IsDevicePathEnd (Left) && !IsDevicePathEnd (Right)
1200 ; Left = NextDevicePathNode (Left), Right = NextDevicePathNode (Right)
1201 )
1202 {
1203 if (CompareMem (Left, Right, DevicePathNodeLength (Left)) != 0) {
1205 return FALSE;
1206 }
1207
1208 if (DevicePathSubType (Left) == MSG_DNS_DP) {
1209 Left = NextDevicePathNode (Left);
1210 }
1211
1212 if (DevicePathSubType (Right) == MSG_DNS_DP) {
1213 Right = NextDevicePathNode (Right);
1214 }
1215
1216 if (((DevicePathSubType (Left) != MSG_IPv4_DP) || (DevicePathSubType (Right) != MSG_IPv4_DP)) &&
1217 ((DevicePathSubType (Left) != MSG_IPv6_DP) || (DevicePathSubType (Right) != MSG_IPv6_DP)) &&
1218 ((DevicePathSubType (Left) != MSG_URI_DP) || (DevicePathSubType (Right) != MSG_URI_DP))
1219 )
1220 {
1221 return FALSE;
1222 }
1223 }
1224 }
1225
1226 return (BOOLEAN)(IsDevicePathEnd (Left) && IsDevicePathEnd (Right));
1227}
1228
1240 IN EFI_HANDLE LoadFileHandle,
1241 OUT EFI_HANDLE *RamDiskHandle
1242 )
1243{
1244 EFI_STATUS Status;
1245 EFI_HANDLE Handle;
1246 EFI_HANDLE *Handles;
1247 UINTN HandleCount;
1248 UINTN Index;
1250
1251 Status = gBS->LocateHandleBuffer (
1252 ByProtocol,
1253 &gEfiBlockIoProtocolGuid,
1254 NULL,
1255 &HandleCount,
1256 &Handles
1257 );
1258 if (EFI_ERROR (Status)) {
1259 Handles = NULL;
1260 HandleCount = 0;
1261 }
1262
1263 Handle = NULL;
1264 for (Index = 0; Index < HandleCount; Index++) {
1265 Node = DevicePathFromHandle (Handles[Index]);
1266 Status = gBS->LocateDevicePath (&gEfiLoadFileProtocolGuid, &Node, &Handle);
1267 if (!EFI_ERROR (Status) &&
1268 (Handle == LoadFileHandle) &&
1269 (DevicePathType (Node) == MEDIA_DEVICE_PATH) && (DevicePathSubType (Node) == MEDIA_RAM_DISK_DP))
1270 {
1271 //
1272 // Find the BlockIo instance populated from the LoadFile.
1273 //
1274 Handle = Handles[Index];
1275 break;
1276 }
1277 }
1278
1279 if (Handles != NULL) {
1280 FreePool (Handles);
1281 }
1282
1283 if (Index == HandleCount) {
1284 Handle = NULL;
1285 }
1286
1287 *RamDiskHandle = Handle;
1288
1289 if (Handle != NULL) {
1290 //
1291 // Re-use BmExpandMediaDevicePath() to get the full device path of load option.
1292 // But assume only one SimpleFileSystem can be found under the BlockIo.
1293 //
1295 } else {
1296 return NULL;
1297 }
1298}
1299
1310 )
1311{
1312 EFI_STATUS Status;
1313 EFI_DEVICE_PATH_PROTOCOL *RamDiskDevicePath;
1315 EFI_HANDLE Handle;
1316
1317 Node = FilePath;
1318 Status = gBS->LocateDevicePath (&gEfiLoadFileProtocolGuid, &Node, &Handle);
1319 if (!EFI_ERROR (Status) &&
1320 (DevicePathType (Node) == MEDIA_DEVICE_PATH) &&
1322 )
1323 {
1324 //
1325 // Construct the device path pointing to RAM Disk
1326 //
1327 Node = NextDevicePathNode (Node);
1328 RamDiskDevicePath = DuplicateDevicePath (FilePath);
1329 ASSERT (RamDiskDevicePath != NULL);
1330 SetDevicePathEndNode ((VOID *)((UINTN)RamDiskDevicePath + ((UINTN)Node - (UINTN)FilePath)));
1331 return RamDiskDevicePath;
1332 }
1333
1334 return NULL;
1335}
1336
1345VOID *
1347 IN EFI_DEVICE_PATH_PROTOCOL *RamDiskDevicePath,
1348 OUT UINTN *RamDiskSizeInPages
1349 )
1350{
1351 EFI_STATUS Status;
1352 EFI_HANDLE Handle;
1353 UINT64 StartingAddr;
1354 UINT64 EndingAddr;
1355
1356 ASSERT (RamDiskDevicePath != NULL);
1357
1358 *RamDiskSizeInPages = 0;
1359
1360 //
1361 // Get the buffer occupied by RAM Disk.
1362 //
1363 Status = gBS->LocateDevicePath (&gEfiLoadFileProtocolGuid, &RamDiskDevicePath, &Handle);
1364 ASSERT_EFI_ERROR (Status);
1365 ASSERT (
1366 (DevicePathType (RamDiskDevicePath) == MEDIA_DEVICE_PATH) &&
1367 (DevicePathSubType (RamDiskDevicePath) == MEDIA_RAM_DISK_DP)
1368 );
1369 StartingAddr = ReadUnaligned64 ((UINT64 *)((MEDIA_RAM_DISK_DEVICE_PATH *)RamDiskDevicePath)->StartingAddr);
1370 EndingAddr = ReadUnaligned64 ((UINT64 *)((MEDIA_RAM_DISK_DEVICE_PATH *)RamDiskDevicePath)->EndingAddr);
1371 *RamDiskSizeInPages = EFI_SIZE_TO_PAGES ((UINTN)(EndingAddr - StartingAddr + 1));
1372 return (VOID *)(UINTN)StartingAddr;
1373}
1374
1384VOID
1386 IN EFI_DEVICE_PATH_PROTOCOL *RamDiskDevicePath
1387 )
1388{
1389 EFI_STATUS Status;
1390 VOID *RamDiskBuffer;
1391 UINTN RamDiskSizeInPages;
1392
1393 ASSERT (RamDiskDevicePath != NULL);
1394
1395 RamDiskBuffer = BmGetRamDiskMemoryInfo (RamDiskDevicePath, &RamDiskSizeInPages);
1396
1397 //
1398 // Destroy RAM Disk.
1399 //
1400 if (mRamDisk == NULL) {
1401 Status = gBS->LocateProtocol (&gEfiRamDiskProtocolGuid, NULL, (VOID *)&mRamDisk);
1402 ASSERT_EFI_ERROR (Status);
1403 }
1404
1405 Status = mRamDisk->Unregister (RamDiskDevicePath);
1406 ASSERT_EFI_ERROR (Status);
1407 FreeAlignedPages (RamDiskBuffer, RamDiskSizeInPages);
1408}
1409
1420 IN EFI_HANDLE LoadFileHandle,
1422 )
1423{
1424 EFI_STATUS Status;
1425 EFI_LOAD_FILE_PROTOCOL *LoadFile;
1426 VOID *FileBuffer;
1427 EFI_HANDLE RamDiskHandle;
1428 UINTN BufferSize;
1429 EFI_DEVICE_PATH_PROTOCOL *FullPath;
1430
1431 Status = gBS->OpenProtocol (
1432 LoadFileHandle,
1433 &gEfiLoadFileProtocolGuid,
1434 (VOID **)&LoadFile,
1436 NULL,
1437 EFI_OPEN_PROTOCOL_GET_PROTOCOL
1438 );
1439 ASSERT_EFI_ERROR (Status);
1440
1441 FileBuffer = NULL;
1442 BufferSize = 0;
1443 Status = LoadFile->LoadFile (LoadFile, FilePath, TRUE, &BufferSize, FileBuffer);
1444 if ((Status != EFI_WARN_FILE_SYSTEM) && (Status != EFI_BUFFER_TOO_SMALL)) {
1445 return NULL;
1446 }
1447
1448 if (Status == EFI_BUFFER_TOO_SMALL) {
1449 //
1450 // The load option buffer is directly returned by LoadFile.
1451 //
1452 return DuplicateDevicePath (DevicePathFromHandle (LoadFileHandle));
1453 }
1454
1455 //
1456 // The load option resides in a RAM disk.
1457 // Use a reasonable default of 2MB for alignment as the ramdisk device is
1458 // implemented as an NVDIMM persistent memory and operating systems may
1459 // wish to map this with huge page support.
1460 //
1461
1462 FileBuffer = AllocateAlignedReservedPages (EFI_SIZE_TO_PAGES (BufferSize), SIZE_2MB);
1463 if (FileBuffer == NULL) {
1465 EFI_DEVICE_PATH *LoadFilePath;
1466 CHAR16 *LoadFileText;
1467 CHAR16 *FileText;
1468
1469 LoadFilePath = DevicePathFromHandle (LoadFileHandle);
1470 if (LoadFilePath == NULL) {
1471 LoadFileText = NULL;
1472 } else {
1473 LoadFileText = ConvertDevicePathToText (LoadFilePath, FALSE, FALSE);
1474 }
1475
1476 FileText = ConvertDevicePathToText (FilePath, FALSE, FALSE);
1477
1478 DEBUG ((
1479 DEBUG_ERROR,
1480 "%a:%a: failed to allocate reserved pages: "
1481 "BufferSize=%Lu LoadFile=\"%s\" FilePath=\"%s\"\n",
1482 gEfiCallerBaseName,
1483 __func__,
1484 (UINT64)BufferSize,
1485 LoadFileText,
1486 FileText
1487 ));
1488
1489 if (FileText != NULL) {
1490 FreePool (FileText);
1491 }
1492
1493 if (LoadFileText != NULL) {
1494 FreePool (LoadFileText);
1495 }
1496
1497 DEBUG_CODE_END ();
1498 return NULL;
1499 }
1500
1501 Status = LoadFile->LoadFile (LoadFile, FilePath, TRUE, &BufferSize, FileBuffer);
1502 if (EFI_ERROR (Status)) {
1503 FreeAlignedPages (FileBuffer, EFI_SIZE_TO_PAGES (BufferSize));
1504 return NULL;
1505 }
1506
1507 FullPath = BmExpandNetworkFileSystem (LoadFileHandle, &RamDiskHandle);
1508 if (FullPath == NULL) {
1509 //
1510 // Free the memory occupied by the RAM disk if there is no BlockIo or SimpleFileSystem instance.
1511 //
1512 BmDestroyRamDisk (DevicePathFromHandle (RamDiskHandle));
1513 }
1514
1515 return FullPath;
1516}
1517
1540 )
1541{
1542 EFI_STATUS Status;
1543 EFI_HANDLE Handle;
1544 EFI_HANDLE *Handles;
1545 UINTN HandleCount;
1546 UINTN Index;
1548 EFI_DEVICE_PATH_PROTOCOL *NewDevicePath;
1549 EFI_DEVICE_PATH_PROTOCOL *HttpPath;
1550 URI_DEVICE_PATH *NullUriPath;
1551
1552 NullUriPath = NULL;
1553
1554 //
1555 // Get file buffer from load file instance.
1556 //
1557 Node = FilePath;
1558 Status = gBS->LocateDevicePath (&gEfiLoadFileProtocolGuid, &Node, &Handle);
1559 if (!EFI_ERROR (Status) && IsDevicePathEnd (Node)) {
1560 //
1561 // When wide match happens, pass full device path to LoadFile (),
1562 // otherwise, pass remaining device path to LoadFile ().
1563 //
1564 FilePath = Node;
1565 } else {
1566 Handle = NULL;
1567 //
1568 // Use wide match algorithm to find one when
1569 // cannot find a LoadFile instance to exactly match the FilePath
1570 //
1571 Status = gBS->LocateHandleBuffer (
1572 ByProtocol,
1573 &gEfiLoadFileProtocolGuid,
1574 NULL,
1575 &HandleCount,
1576 &Handles
1577 );
1578 if (EFI_ERROR (Status)) {
1579 Handles = NULL;
1580 HandleCount = 0;
1581 }
1582
1583 for (Index = 0; Index < HandleCount; Index++) {
1584 if (BmMatchHttpBootDevicePath (DevicePathFromHandle (Handles[Index]), FilePath)) {
1585 //
1586 // Matches HTTP Boot Device Path described as
1587 // ....../Mac(...)[/Vlan(...)][/Wi-Fi(...)]/IPv4(...)[/Dns(...)]/Uri(...)
1588 // ....../Mac(...)[/Vlan(...)][/Wi-Fi(...)]/IPv6(...)[/Dns(...)]/Uri(...)
1589 //
1590 Handle = Handles[Index];
1591 goto Done;
1592 }
1593 }
1594
1595 NullUriPath = (URI_DEVICE_PATH *)CreateDeviceNode (
1597 MSG_URI_DP,
1598 (UINT16)(sizeof (URI_DEVICE_PATH))
1599 );
1600 for (Index = 0; Index < HandleCount; Index++) {
1601 if ((Handles == NULL) || (Handles[Index] == NULL)) {
1602 continue;
1603 }
1604
1605 NewDevicePath = DevicePathFromHandle (Handles[Index]);
1606 if (NewDevicePath == NULL) {
1607 continue;
1608 }
1609
1610 HttpPath = AppendDevicePathNode (NewDevicePath, (EFI_DEVICE_PATH_PROTOCOL *)NullUriPath);
1611 if (HttpPath == NULL) {
1612 continue;
1613 }
1614
1615 if (BmMatchHttpBootDevicePath (HttpPath, FilePath)) {
1616 //
1617 // Matches HTTP Boot Device Path described as
1618 // ....../Mac(...)[/Vlan(...)][/Wi-Fi(...)]/IPv4(...)[/Dns(...)]/Uri(...)/Uri(...)
1619 // ....../Mac(...)[/Vlan(...)][/Wi-Fi(...)]/IPv6(...)[/Dns(...)]/Uri(...)/Uri(...)
1620 //
1621 Handle = Handles[Index];
1622 break;
1623 }
1624 }
1625
1626 FreePool (NullUriPath);
1627
1628Done:
1629 if (Handles != NULL) {
1630 FreePool (Handles);
1631 }
1632 }
1633
1634 if (Handle == NULL) {
1635 return NULL;
1636 }
1637
1638 return BmExpandLoadFile (Handle, FilePath);
1639}
1640
1653VOID *
1654EFIAPI
1656 IN EFI_DEVICE_PATH_PROTOCOL *FilePath,
1657 OUT EFI_DEVICE_PATH_PROTOCOL **FullPath,
1658 OUT UINTN *FileSize
1659 )
1660{
1661 *FullPath = NULL;
1662
1664 return BmGetNextLoadOptionBuffer (LoadOptionTypeMax, FilePath, FullPath, FileSize);
1665}
1666
1683 IN EFI_DEVICE_PATH_PROTOCOL *FilePath,
1685 )
1686{
1687 EFI_HANDLE Handle;
1689 EFI_STATUS Status;
1690
1691 ASSERT (FilePath != NULL);
1692
1693 //
1694 // Boot from media device by adding a default file name \EFI\BOOT\BOOT{machine type short-name}.EFI
1695 //
1696 Node = FilePath;
1697 Status = gBS->LocateDevicePath (&gEfiSimpleFileSystemProtocolGuid, &Node, &Handle);
1698 if (EFI_ERROR (Status)) {
1699 Status = gBS->LocateDevicePath (&gEfiBlockIoProtocolGuid, &Node, &Handle);
1700 }
1701
1702 if (!EFI_ERROR (Status) && IsDevicePathEnd (Node)) {
1703 return BmExpandMediaDevicePath (FilePath, FullPath);
1704 }
1705
1706 //
1707 // Expand the short-form device path to full device path
1708 //
1709 if ((DevicePathType (FilePath) == MEDIA_DEVICE_PATH) &&
1710 (DevicePathSubType (FilePath) == MEDIA_HARDDRIVE_DP))
1711 {
1712 //
1713 // Expand the Harddrive device path
1714 //
1715 if (FullPath == NULL) {
1716 return BmExpandPartitionDevicePath (FilePath);
1717 } else {
1718 return NULL;
1719 }
1720 } else if ((DevicePathType (FilePath) == MEDIA_DEVICE_PATH) &&
1721 (DevicePathSubType (FilePath) == MEDIA_FILEPATH_DP))
1722 {
1723 //
1724 // Expand the File-path device path
1725 //
1726 return BmExpandFileDevicePath (FilePath, FullPath);
1727 } else if ((DevicePathType (FilePath) == MESSAGING_DEVICE_PATH) &&
1728 (DevicePathSubType (FilePath) == MSG_URI_DP))
1729 {
1730 //
1731 // Expand the URI device path
1732 //
1733 return BmExpandUriDevicePath (FilePath, FullPath);
1734 } else {
1735 Node = FilePath;
1736 Status = gBS->LocateDevicePath (&gEfiUsbIoProtocolGuid, &Node, &Handle);
1737 if (EFI_ERROR (Status)) {
1738 //
1739 // Only expand the USB WWID/Class device path
1740 // when FilePath doesn't point to a physical UsbIo controller.
1741 // Otherwise, infinite recursion will happen.
1742 //
1743 for (Node = FilePath; !IsDevicePathEnd (Node); Node = NextDevicePathNode (Node)) {
1744 if ((DevicePathType (Node) == MESSAGING_DEVICE_PATH) &&
1746 {
1747 break;
1748 }
1749 }
1750
1751 //
1752 // Expand the USB WWID/Class device path
1753 //
1754 if (!IsDevicePathEnd (Node)) {
1755 if (FilePath == Node) {
1756 //
1757 // Boot Option device path starts with USB Class or USB WWID device path.
1758 // For Boot Option device path which doesn't begin with the USB Class or
1759 // USB WWID device path, it's not needed to connect again here.
1760 //
1762 }
1763
1764 return BmExpandUsbDevicePath (FilePath, FullPath, Node);
1765 }
1766 }
1767 }
1768
1769 //
1770 // For the below cases, FilePath only expands to one Full path.
1771 // So just handle the case when FullPath == NULL.
1772 //
1773 if (FullPath != NULL) {
1774 return NULL;
1775 }
1776
1777 //
1778 // Load option resides in FV.
1779 //
1780 if (BmIsFvFilePath (FilePath)) {
1781 return BmAdjustFvFilePath (FilePath);
1782 }
1783
1784 //
1785 // Load option resides in Simple File System.
1786 //
1787 Node = FilePath;
1788 Status = gBS->LocateDevicePath (&gEfiSimpleFileSystemProtocolGuid, &Node, &Handle);
1789 if (!EFI_ERROR (Status)) {
1790 return DuplicateDevicePath (FilePath);
1791 }
1792
1793 //
1794 // Last chance to try: Load option may be loaded through LoadFile.
1795 //
1796 return BmExpandLoadFiles (FilePath);
1797}
1798
1807BOOLEAN
1809 EFI_DEVICE_PATH_PROTOCOL *DevicePath
1810 )
1811{
1812 EFI_HANDLE FvHandle;
1813 VOID *NameGuid;
1814 EFI_STATUS Status;
1815
1816 Status = gBS->LocateDevicePath (&gEfiFirmwareVolume2ProtocolGuid, &DevicePath, &FvHandle);
1817 if (!EFI_ERROR (Status)) {
1819 if (NameGuid != NULL) {
1820 return CompareGuid (NameGuid, PcdGetPtr (PcdBootManagerMenuFile));
1821 }
1822 }
1823
1824 return FALSE;
1825}
1826
1841VOID
1843 IN UINT32 ErrorCode,
1844 IN EFI_STATUS FailureStatus
1845 )
1846{
1848
1849 if (!ReportErrorCodeEnabled ()) {
1850 return;
1851 }
1852
1853 ASSERT (
1854 (ErrorCode == EFI_SW_DXE_BS_EC_BOOT_OPTION_LOAD_ERROR) ||
1855 (ErrorCode == EFI_SW_DXE_BS_EC_BOOT_OPTION_FAILED)
1856 );
1857
1858 ZeroMem (&ExtendedData, sizeof (ExtendedData));
1859 ExtendedData.ReturnStatus = FailureStatus;
1860
1862 (EFI_ERROR_CODE | EFI_ERROR_MINOR),
1863 (EFI_SOFTWARE_DXE_BS_DRIVER | ErrorCode),
1864 0,
1865 NULL,
1866 NULL,
1867 &ExtendedData.DataHeader + 1,
1868 sizeof (ExtendedData) - sizeof (ExtendedData.DataHeader)
1869 );
1870}
1871
1892VOID
1893EFIAPI
1896 )
1897{
1898 EFI_STATUS Status;
1899 EFI_HANDLE ImageHandle;
1900 EFI_LOADED_IMAGE_PROTOCOL *ImageInfo;
1901 UINT16 Uint16;
1902 UINTN OptionNumber;
1903 UINTN OriginalOptionNumber;
1904 EFI_DEVICE_PATH_PROTOCOL *FilePath;
1905 EFI_DEVICE_PATH_PROTOCOL *RamDiskDevicePath;
1906 VOID *FileBuffer;
1907 UINTN FileSize;
1908 EFI_BOOT_LOGO_PROTOCOL *BootLogo;
1909 EFI_EVENT LegacyBootEvent;
1910
1911 if (BootOption == NULL) {
1912 return;
1913 }
1914
1915 if ((BootOption->FilePath == NULL) || (BootOption->OptionType != LoadOptionTypeBoot)) {
1916 BootOption->Status = EFI_INVALID_PARAMETER;
1917 return;
1918 }
1919
1920 //
1921 // 1. Create Boot#### for a temporary boot if there is no match Boot#### (i.e. a boot by selected a EFI Shell using "Boot From File")
1922 //
1923 OptionNumber = BmFindBootOptionInVariable (BootOption);
1924 if (OptionNumber == LoadOptionNumberUnassigned) {
1925 Status = BmGetFreeOptionNumber (LoadOptionTypeBoot, &Uint16);
1926 if (!EFI_ERROR (Status)) {
1927 //
1928 // Save the BootOption->OptionNumber to restore later
1929 //
1930 OptionNumber = Uint16;
1931 OriginalOptionNumber = BootOption->OptionNumber;
1932 BootOption->OptionNumber = OptionNumber;
1933 Status = EfiBootManagerLoadOptionToVariable (BootOption);
1934 BootOption->OptionNumber = OriginalOptionNumber;
1935 }
1936
1937 if (EFI_ERROR (Status)) {
1938 DEBUG ((DEBUG_ERROR, "[Bds] Failed to create Boot#### for a temporary boot - %r!\n", Status));
1939 BootOption->Status = Status;
1940 return;
1941 }
1942 }
1943
1944 //
1945 // 2. Set BootCurrent
1946 //
1947 Uint16 = (UINT16)OptionNumber;
1949 L"BootCurrent",
1950 &gEfiGlobalVariableGuid,
1951 EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS,
1952 sizeof (UINT16),
1953 &Uint16
1954 );
1955
1956 //
1957 // 3. Signal the EVT_SIGNAL_READY_TO_BOOT event when we are about to load and execute
1958 // the boot option.
1959 //
1960 if (BmIsBootManagerMenuFilePath (BootOption->FilePath)) {
1961 DEBUG ((DEBUG_INFO, "[Bds] Booting Boot Manager Menu.\n"));
1963 } else {
1965 //
1966 // Report Status Code to indicate ReadyToBoot was signalled
1967 //
1968 REPORT_STATUS_CODE (EFI_PROGRESS_CODE, (EFI_SOFTWARE_DXE_BS_DRIVER | EFI_SW_DXE_BS_PC_READY_TO_BOOT_EVENT));
1969 //
1970 // 4. Repair system through DriverHealth protocol
1971 //
1973 }
1974
1975 PERF_START_EX (gImageHandle, "BdsAttempt", NULL, 0, (UINT32)OptionNumber);
1976
1977 //
1978 // 5. Adjust the different type memory page number just before booting
1979 // and save the updated info into the variable for next boot to use
1980 //
1982 (BOOLEAN)((BootOption->Attributes & LOAD_OPTION_CATEGORY) == LOAD_OPTION_CATEGORY_BOOT)
1983 );
1984
1985 //
1986 // 6. Load EFI boot option to ImageHandle
1987 //
1989 if (BootOption->Description == NULL) {
1990 DEBUG ((DEBUG_INFO | DEBUG_LOAD, "[Bds]Booting from unknown device path\n"));
1991 } else {
1992 DEBUG ((DEBUG_INFO | DEBUG_LOAD, "[Bds]Booting %s\n", BootOption->Description));
1993 }
1994
1995 DEBUG_CODE_END ();
1996
1997 ImageHandle = NULL;
1998 RamDiskDevicePath = NULL;
1999 if (DevicePathType (BootOption->FilePath) != BBS_DEVICE_PATH) {
2000 Status = EFI_NOT_FOUND;
2001 FilePath = NULL;
2002 EfiBootManagerConnectDevicePath (BootOption->FilePath, NULL);
2003 FileBuffer = BmGetNextLoadOptionBuffer (LoadOptionTypeBoot, BootOption->FilePath, &FilePath, &FileSize);
2004 if (FileBuffer != NULL) {
2005 RamDiskDevicePath = BmGetRamDiskDevicePath (FilePath);
2006
2007 REPORT_STATUS_CODE (EFI_PROGRESS_CODE, PcdGet32 (PcdProgressCodeOsLoaderLoad));
2008 Status = gBS->LoadImage (
2009 TRUE,
2011 FilePath,
2012 FileBuffer,
2013 FileSize,
2014 &ImageHandle
2015 );
2016 }
2017
2018 if (FileBuffer != NULL) {
2019 FreePool (FileBuffer);
2020 }
2021
2022 if (FilePath != NULL) {
2023 FreePool (FilePath);
2024 }
2025
2026 if (EFI_ERROR (Status)) {
2027 //
2028 // With EFI_SECURITY_VIOLATION retval, the Image was loaded and an ImageHandle was created
2029 // with a valid EFI_LOADED_IMAGE_PROTOCOL, but the image can not be started right now.
2030 // If the caller doesn't have the option to defer the execution of an image, we should
2031 // unload image for the EFI_SECURITY_VIOLATION to avoid resource leak.
2032 //
2033 if (Status == EFI_SECURITY_VIOLATION) {
2034 gBS->UnloadImage (ImageHandle);
2035 }
2036
2037 //
2038 // Destroy the RAM disk
2039 //
2040 if (RamDiskDevicePath != NULL) {
2041 BmDestroyRamDisk (RamDiskDevicePath);
2042 FreePool (RamDiskDevicePath);
2043 }
2044
2045 //
2046 // Report Status Code with the failure status to indicate that the failure to load boot option
2047 //
2048 BmReportLoadFailure (EFI_SW_DXE_BS_EC_BOOT_OPTION_LOAD_ERROR, Status);
2049 BootOption->Status = Status;
2050 return;
2051 }
2052 }
2053
2054 //
2055 // Check to see if we should legacy BOOT. If yes then do the legacy boot
2056 // Write boot to OS performance data for Legacy boot
2057 //
2058 if ((DevicePathType (BootOption->FilePath) == BBS_DEVICE_PATH) && (DevicePathSubType (BootOption->FilePath) == BBS_BBS_DP)) {
2059 if (mBmLegacyBoot != NULL) {
2060 //
2061 // Write boot to OS performance data for legacy boot.
2062 //
2063 PERF_CODE (
2064 //
2065 // Create an event to be signalled when Legacy Boot occurs to write performance data.
2066 //
2068 TPL_NOTIFY,
2070 NULL,
2071 &LegacyBootEvent
2072 );
2073 ASSERT_EFI_ERROR (Status);
2074 );
2075
2076 mBmLegacyBoot (BootOption);
2077 } else {
2078 BootOption->Status = EFI_UNSUPPORTED;
2079 }
2080
2081 PERF_END_EX (gImageHandle, "BdsAttempt", NULL, 0, (UINT32)OptionNumber);
2082 return;
2083 }
2084
2085 //
2086 // Provide the image with its load options
2087 //
2088 Status = gBS->HandleProtocol (ImageHandle, &gEfiLoadedImageProtocolGuid, (VOID **)&ImageInfo);
2089 ASSERT_EFI_ERROR (Status);
2090
2091 if (!BmIsAutoCreateBootOption (BootOption)) {
2092 ImageInfo->LoadOptionsSize = BootOption->OptionalDataSize;
2093 ImageInfo->LoadOptions = BootOption->OptionalData;
2094 }
2095
2096 //
2097 // Clean to NULL because the image is loaded directly from the firmwares boot manager.
2098 //
2099 ImageInfo->ParentHandle = NULL;
2100
2101 //
2102 // Before calling the image, enable the Watchdog Timer for 5 minutes period
2103 //
2104 gBS->SetWatchdogTimer (5 * 60, 0x0000, 0x00, NULL);
2105
2106 //
2107 // Write boot to OS performance data for UEFI boot
2108 //
2109 PERF_CODE (
2111 );
2112
2113 REPORT_STATUS_CODE (EFI_PROGRESS_CODE, PcdGet32 (PcdProgressCodeOsLoaderStart));
2114
2115 Status = gBS->StartImage (ImageHandle, &BootOption->ExitDataSize, &BootOption->ExitData);
2116 DEBUG ((DEBUG_INFO | DEBUG_LOAD, "Image Return Status = %r\n", Status));
2117 BootOption->Status = Status;
2118
2119 //
2120 // Destroy the RAM disk
2121 //
2122 if (RamDiskDevicePath != NULL) {
2123 BmDestroyRamDisk (RamDiskDevicePath);
2124 FreePool (RamDiskDevicePath);
2125 }
2126
2127 if (EFI_ERROR (Status)) {
2128 //
2129 // Report Status Code with the failure status to indicate that boot failure
2130 //
2131 BmReportLoadFailure (EFI_SW_DXE_BS_EC_BOOT_OPTION_FAILED, Status);
2132 }
2133
2134 PERF_END_EX (gImageHandle, "BdsAttempt", NULL, 0, (UINT32)OptionNumber);
2135
2136 //
2137 // Clear the Watchdog Timer after the image returns
2138 //
2139 gBS->SetWatchdogTimer (0x0000, 0x0000, 0x0000, NULL);
2140
2141 //
2142 // Set Logo status invalid after trying one boot option
2143 //
2144 BootLogo = NULL;
2145 Status = gBS->LocateProtocol (&gEfiBootLogoProtocolGuid, NULL, (VOID **)&BootLogo);
2146 if (!EFI_ERROR (Status) && (BootLogo != NULL)) {
2147 Status = BootLogo->SetBootLogo (BootLogo, NULL, 0, 0, 0, 0);
2148 ASSERT_EFI_ERROR (Status);
2149 }
2150
2151 //
2152 // Clear Boot Current
2153 //
2154 Status = gRT->SetVariable (
2155 L"BootCurrent",
2156 &gEfiGlobalVariableGuid,
2157 0,
2158 0,
2159 NULL
2160 );
2161 //
2162 // Deleting variable with current variable implementation shouldn't fail.
2163 // When BootXXXX (e.g.: BootManagerMenu) boots BootYYYY, exiting BootYYYY causes BootCurrent deleted,
2164 // exiting BootXXXX causes deleting BootCurrent returns EFI_NOT_FOUND.
2165 //
2166 ASSERT (Status == EFI_SUCCESS || Status == EFI_NOT_FOUND);
2167}
2168
2181BOOLEAN
2183 IN EFI_DEVICE_PATH_PROTOCOL *BlockIoDevicePath,
2184 IN HARDDRIVE_DEVICE_PATH *HardDriveDevicePath
2185 )
2186{
2188
2189 if ((BlockIoDevicePath == NULL) || (HardDriveDevicePath == NULL)) {
2190 return FALSE;
2191 }
2192
2193 //
2194 // Match all the partition device path nodes including the nested partition nodes
2195 //
2196 while (!IsDevicePathEnd (BlockIoDevicePath)) {
2197 if ((DevicePathType (BlockIoDevicePath) == MEDIA_DEVICE_PATH) &&
2198 (DevicePathSubType (BlockIoDevicePath) == MEDIA_HARDDRIVE_DP)
2199 )
2200 {
2201 //
2202 // See if the harddrive device path in blockio matches the orig Hard Drive Node
2203 //
2204 Node = (HARDDRIVE_DEVICE_PATH *)BlockIoDevicePath;
2205
2206 //
2207 // Match Signature and PartitionNumber.
2208 // Unused bytes in Signature are initiaized with zeros.
2209 //
2210 if ((Node->PartitionNumber == HardDriveDevicePath->PartitionNumber) &&
2211 (Node->MBRType == HardDriveDevicePath->MBRType) &&
2212 (Node->SignatureType == HardDriveDevicePath->SignatureType) &&
2213 (CompareMem (Node->Signature, HardDriveDevicePath->Signature, sizeof (Node->Signature)) == 0))
2214 {
2215 return TRUE;
2216 }
2217 }
2218
2219 BlockIoDevicePath = NextDevicePathNode (BlockIoDevicePath);
2220 }
2221
2222 return FALSE;
2223}
2224
2244 UINTN *BootOptionCount
2245 )
2246{
2247 EFI_STATUS Status;
2248 EFI_BOOT_MANAGER_LOAD_OPTION *BootOptions;
2249 UINTN HandleCount;
2250 EFI_HANDLE *Handles;
2251 EFI_BLOCK_IO_PROTOCOL *BlkIo;
2252 UINTN Removable;
2253 UINTN Index;
2254 CHAR16 *Description;
2255
2256 ASSERT (BootOptionCount != NULL);
2257
2258 *BootOptionCount = 0;
2259 BootOptions = NULL;
2260
2261 //
2262 // Parse removable block io followed by fixed block io
2263 //
2264 gBS->LocateHandleBuffer (
2265 ByProtocol,
2266 &gEfiBlockIoProtocolGuid,
2267 NULL,
2268 &HandleCount,
2269 &Handles
2270 );
2271
2272 for (Removable = 0; Removable < 2; Removable++) {
2273 for (Index = 0; Index < HandleCount; Index++) {
2274 Status = gBS->HandleProtocol (
2275 Handles[Index],
2276 &gEfiBlockIoProtocolGuid,
2277 (VOID **)&BlkIo
2278 );
2279 if (EFI_ERROR (Status)) {
2280 continue;
2281 }
2282
2283 //
2284 // Skip the logical partitions
2285 //
2286 if (BlkIo->Media->LogicalPartition) {
2287 continue;
2288 }
2289
2290 //
2291 // Skip the fixed block io then the removable block io
2292 //
2293 if (BlkIo->Media->RemovableMedia == ((Removable == 0) ? FALSE : TRUE)) {
2294 continue;
2295 }
2296
2297 //
2298 // Skip removable media if not present
2299 //
2300 if ((BlkIo->Media->RemovableMedia == TRUE) &&
2301 (BlkIo->Media->MediaPresent == FALSE))
2302 {
2303 continue;
2304 }
2305
2306 Description = BmGetBootDescription (Handles[Index]);
2307 BootOptions = ReallocatePool (
2308 sizeof (EFI_BOOT_MANAGER_LOAD_OPTION) * (*BootOptionCount),
2309 sizeof (EFI_BOOT_MANAGER_LOAD_OPTION) * (*BootOptionCount + 1),
2310 BootOptions
2311 );
2312 ASSERT (BootOptions != NULL);
2313
2315 &BootOptions[(*BootOptionCount)++],
2316 LoadOptionNumberUnassigned,
2317 LoadOptionTypeBoot,
2318 LOAD_OPTION_ACTIVE,
2319 Description,
2320 DevicePathFromHandle (Handles[Index]),
2321 NULL,
2322 0
2323 );
2324 ASSERT_EFI_ERROR (Status);
2325
2326 FreePool (Description);
2327 }
2328 }
2329
2330 if (HandleCount != 0) {
2331 FreePool (Handles);
2332 }
2333
2334 //
2335 // Parse simple file system not based on block io
2336 //
2337 gBS->LocateHandleBuffer (
2338 ByProtocol,
2339 &gEfiSimpleFileSystemProtocolGuid,
2340 NULL,
2341 &HandleCount,
2342 &Handles
2343 );
2344 for (Index = 0; Index < HandleCount; Index++) {
2345 Status = gBS->HandleProtocol (
2346 Handles[Index],
2347 &gEfiBlockIoProtocolGuid,
2348 (VOID **)&BlkIo
2349 );
2350 if (!EFI_ERROR (Status)) {
2351 //
2352 // Skip if the file system handle supports a BlkIo protocol, which we've handled in above
2353 //
2354 continue;
2355 }
2356
2357 Description = BmGetBootDescription (Handles[Index]);
2358 BootOptions = ReallocatePool (
2359 sizeof (EFI_BOOT_MANAGER_LOAD_OPTION) * (*BootOptionCount),
2360 sizeof (EFI_BOOT_MANAGER_LOAD_OPTION) * (*BootOptionCount + 1),
2361 BootOptions
2362 );
2363 ASSERT (BootOptions != NULL);
2364
2366 &BootOptions[(*BootOptionCount)++],
2367 LoadOptionNumberUnassigned,
2368 LoadOptionTypeBoot,
2369 LOAD_OPTION_ACTIVE,
2370 Description,
2371 DevicePathFromHandle (Handles[Index]),
2372 NULL,
2373 0
2374 );
2375 ASSERT_EFI_ERROR (Status);
2376 FreePool (Description);
2377 }
2378
2379 if (HandleCount != 0) {
2380 FreePool (Handles);
2381 }
2382
2383 //
2384 // Parse load file protocol
2385 //
2386 gBS->LocateHandleBuffer (
2387 ByProtocol,
2388 &gEfiLoadFileProtocolGuid,
2389 NULL,
2390 &HandleCount,
2391 &Handles
2392 );
2393 for (Index = 0; Index < HandleCount; Index++) {
2394 //
2395 // Ignore BootManagerMenu. its boot option will be created by EfiBootManagerGetBootManagerMenu().
2396 //
2397 if (BmIsBootManagerMenuFilePath (DevicePathFromHandle (Handles[Index]))) {
2398 continue;
2399 }
2400
2401 Description = BmGetBootDescription (Handles[Index]);
2402 BootOptions = ReallocatePool (
2403 sizeof (EFI_BOOT_MANAGER_LOAD_OPTION) * (*BootOptionCount),
2404 sizeof (EFI_BOOT_MANAGER_LOAD_OPTION) * (*BootOptionCount + 1),
2405 BootOptions
2406 );
2407 ASSERT (BootOptions != NULL);
2408
2410 &BootOptions[(*BootOptionCount)++],
2411 LoadOptionNumberUnassigned,
2412 LoadOptionTypeBoot,
2413 LOAD_OPTION_ACTIVE,
2414 Description,
2415 DevicePathFromHandle (Handles[Index]),
2416 NULL,
2417 0
2418 );
2419 ASSERT_EFI_ERROR (Status);
2420 FreePool (Description);
2421 }
2422
2423 if (HandleCount != 0) {
2424 FreePool (Handles);
2425 }
2426
2427 BmMakeBootOptionDescriptionUnique (BootOptions, *BootOptionCount);
2428 return BootOptions;
2429}
2430
2434VOID
2435EFIAPI
2437 VOID
2438 )
2439{
2440 EFI_STATUS Status;
2441 EFI_BOOT_MANAGER_LOAD_OPTION *NvBootOptions;
2442 UINTN NvBootOptionCount;
2443 EFI_BOOT_MANAGER_LOAD_OPTION *BootOptions;
2444 UINTN BootOptionCount;
2445 EFI_BOOT_MANAGER_LOAD_OPTION *UpdatedBootOptions;
2446 UINTN UpdatedBootOptionCount;
2447 UINTN Index;
2448 EDKII_PLATFORM_BOOT_MANAGER_PROTOCOL *PlatformBootManager;
2449
2450 //
2451 // Optionally refresh the legacy boot option
2452 //
2453 if (mBmRefreshLegacyBootOption != NULL) {
2454 mBmRefreshLegacyBootOption ();
2455 }
2456
2457 BootOptions = BmEnumerateBootOptions (&BootOptionCount);
2458
2459 //
2460 // Mark the boot option as added by BDS by setting OptionalData to a special GUID
2461 //
2462 for (Index = 0; Index < BootOptionCount; Index++) {
2463 BootOptions[Index].OptionalData = AllocateCopyPool (sizeof (EFI_GUID), &mBmAutoCreateBootOptionGuid);
2464 BootOptions[Index].OptionalDataSize = sizeof (EFI_GUID);
2465 }
2466
2467 //
2468 // Locate Platform Boot Options Protocol
2469 //
2470 Status = gBS->LocateProtocol (
2471 &gEdkiiPlatformBootManagerProtocolGuid,
2472 NULL,
2473 (VOID **)&PlatformBootManager
2474 );
2475 if (!EFI_ERROR (Status)) {
2476 //
2477 // If found, call platform specific refresh to all auto enumerated and NV
2478 // boot options.
2479 //
2480 Status = PlatformBootManager->RefreshAllBootOptions (
2481 (CONST EFI_BOOT_MANAGER_LOAD_OPTION *)BootOptions,
2482 (CONST UINTN)BootOptionCount,
2483 &UpdatedBootOptions,
2484 &UpdatedBootOptionCount
2485 );
2486 if (!EFI_ERROR (Status)) {
2487 EfiBootManagerFreeLoadOptions (BootOptions, BootOptionCount);
2488 BootOptions = UpdatedBootOptions;
2489 BootOptionCount = UpdatedBootOptionCount;
2490 }
2491 }
2492
2493 NvBootOptions = EfiBootManagerGetLoadOptions (&NvBootOptionCount, LoadOptionTypeBoot);
2494
2495 //
2496 // Remove invalid EFI boot options from NV
2497 //
2498 for (Index = 0; Index < NvBootOptionCount; Index++) {
2499 if (((DevicePathType (NvBootOptions[Index].FilePath) != BBS_DEVICE_PATH) ||
2500 (DevicePathSubType (NvBootOptions[Index].FilePath) != BBS_BBS_DP)
2501 ) && BmIsAutoCreateBootOption (&NvBootOptions[Index])
2502 )
2503 {
2504 //
2505 // Only check those added by BDS
2506 // so that the boot options added by end-user or OS installer won't be deleted
2507 //
2508 if (EfiBootManagerFindLoadOption (&NvBootOptions[Index], BootOptions, BootOptionCount) == -1) {
2509 Status = EfiBootManagerDeleteLoadOptionVariable (NvBootOptions[Index].OptionNumber, LoadOptionTypeBoot);
2510 //
2511 // Deleting variable with current variable implementation shouldn't fail.
2512 //
2513 ASSERT_EFI_ERROR (Status);
2514 }
2515 }
2516 }
2517
2518 //
2519 // Add new EFI boot options to NV
2520 //
2521 for (Index = 0; Index < BootOptionCount; Index++) {
2522 if (EfiBootManagerFindLoadOption (&BootOptions[Index], NvBootOptions, NvBootOptionCount) == -1) {
2523 EfiBootManagerAddLoadOptionVariable (&BootOptions[Index], (UINTN)-1);
2524 //
2525 // Try best to add the boot options so continue upon failure.
2526 //
2527 }
2528 }
2529
2530 EfiBootManagerFreeLoadOptions (BootOptions, BootOptionCount);
2531 EfiBootManagerFreeLoadOptions (NvBootOptions, NvBootOptionCount);
2532}
2533
2552 )
2553{
2554 EFI_STATUS Status;
2555 CHAR16 *Description;
2556 UINTN DescriptionLength;
2557 EFI_DEVICE_PATH_PROTOCOL *DevicePath;
2558 UINTN HandleCount;
2559 EFI_HANDLE *Handles;
2560 UINTN Index;
2561
2562 DevicePath = NULL;
2563 Description = NULL;
2564 //
2565 // Try to find BootManagerMenu from LoadFile protocol
2566 //
2567 gBS->LocateHandleBuffer (
2568 ByProtocol,
2569 &gEfiLoadFileProtocolGuid,
2570 NULL,
2571 &HandleCount,
2572 &Handles
2573 );
2574 for (Index = 0; Index < HandleCount; Index++) {
2575 if (BmIsBootManagerMenuFilePath (DevicePathFromHandle (Handles[Index]))) {
2576 DevicePath = DuplicateDevicePath (DevicePathFromHandle (Handles[Index]));
2577 Description = BmGetBootDescription (Handles[Index]);
2578 break;
2579 }
2580 }
2581
2582 if (HandleCount != 0) {
2583 FreePool (Handles);
2584 }
2585
2586 if (DevicePath == NULL) {
2588 PcdGetPtr (PcdBootManagerMenuFile),
2590 0,
2591 &DevicePath
2592 );
2593 if (EFI_ERROR (Status)) {
2594 DEBUG ((DEBUG_WARN, "[Bds]BootManagerMenu FFS section can not be found, skip its boot option registration\n"));
2595 return EFI_NOT_FOUND;
2596 }
2597
2598 ASSERT (DevicePath != NULL);
2599 //
2600 // Get BootManagerMenu application's description from EFI User Interface Section.
2601 //
2602 Status = GetSectionFromAnyFv (
2603 PcdGetPtr (PcdBootManagerMenuFile),
2604 EFI_SECTION_USER_INTERFACE,
2605 0,
2606 (VOID **)&Description,
2607 &DescriptionLength
2608 );
2609 if (EFI_ERROR (Status)) {
2610 Description = NULL;
2611 }
2612 }
2613
2615 BootOption,
2616 LoadOptionNumberUnassigned,
2617 LoadOptionTypeBoot,
2618 LOAD_OPTION_CATEGORY_APP | LOAD_OPTION_ACTIVE | LOAD_OPTION_HIDDEN,
2619 (Description != NULL) ? Description : L"Boot Manager Menu",
2620 DevicePath,
2621 NULL,
2622 0
2623 );
2624 ASSERT_EFI_ERROR (Status);
2625 FreePool (DevicePath);
2626 if (Description != NULL) {
2627 FreePool (Description);
2628 }
2629
2630 DEBUG_CODE (
2631 EFI_BOOT_MANAGER_LOAD_OPTION *BootOptions;
2632 UINTN BootOptionCount;
2633
2634 BootOptions = EfiBootManagerGetLoadOptions (&BootOptionCount, LoadOptionTypeBoot);
2635 ASSERT (EfiBootManagerFindLoadOption (BootOption, BootOptions, BootOptionCount) == -1);
2636 EfiBootManagerFreeLoadOptions (BootOptions, BootOptionCount);
2637 );
2638
2639 return EfiBootManagerAddLoadOptionVariable (BootOption, (UINTN)-1);
2640}
2641
2655EFIAPI
2658 )
2659{
2660 EFI_STATUS Status;
2661 UINTN BootOptionCount;
2662 EFI_BOOT_MANAGER_LOAD_OPTION *BootOptions;
2663 UINTN Index;
2664
2665 BootOptions = EfiBootManagerGetLoadOptions (&BootOptionCount, LoadOptionTypeBoot);
2666
2667 for (Index = 0; Index < BootOptionCount; Index++) {
2668 if (BmIsBootManagerMenuFilePath (BootOptions[Index].FilePath)) {
2670 BootOption,
2671 BootOptions[Index].OptionNumber,
2672 BootOptions[Index].OptionType,
2673 BootOptions[Index].Attributes,
2674 BootOptions[Index].Description,
2675 BootOptions[Index].FilePath,
2676 BootOptions[Index].OptionalData,
2677 BootOptions[Index].OptionalDataSize
2678 );
2679 ASSERT_EFI_ERROR (Status);
2680 break;
2681 }
2682 }
2683
2684 EfiBootManagerFreeLoadOptions (BootOptions, BootOptionCount);
2685
2686 //
2687 // Automatically create the Boot#### for Boot Manager Menu when not found.
2688 //
2689 if (Index == BootOptionCount) {
2690 return BmRegisterBootManagerMenu (BootOption);
2691 } else {
2692 return EFI_SUCCESS;
2693 }
2694}
2695
2711EFIAPI
2713 IN EFI_DEVICE_PATH_PROTOCOL *FilePath,
2715 )
2716{
2717 return BmGetNextLoadOptionDevicePath (FilePath, FullPath);
2718}
2719
2727VOID
2728EFIAPI
2730 IN EFI_EVENT Event,
2731 IN VOID *Context
2732 )
2733{
2734 EFI_STATUS Status;
2735 EDKII_VARIABLE_POLICY_PROTOCOL *VariablePolicy = NULL;
2736
2737 Status = gBS->LocateProtocol (&gEdkiiVariablePolicyProtocolGuid, NULL, (VOID **)&VariablePolicy);
2738 if (!EFI_ERROR (Status)) {
2739 Status = RegisterBasicVariablePolicy (
2740 VariablePolicy,
2742 L"HDDP",
2743 sizeof (EFI_DEVICE_PATH_PROTOCOL),
2744 VARIABLE_POLICY_NO_MAX_SIZE,
2745 EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_NON_VOLATILE,
2746 (UINT32) ~(EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_NON_VOLATILE),
2747 VARIABLE_POLICY_TYPE_NO_LOCK
2748 );
2749
2750 // Multiple modules link to UefiBootManagerLib. There are a couple of cases that need to be ignored.
2751 // 1. Write Protected. Write Protected occurs after Ready to Boot. Some modules, such as the Shell, run
2752 // after Ready To Boot.
2753 // 2. Already Started. Only the first module to register a variable policy will successfully register
2754 // a policy. The subsequent modules will get EFI_ALREADY_STARTED.
2755 if (EFI_ERROR (Status) && (Status != EFI_ALREADY_STARTED) && (Status != EFI_WRITE_PROTECTED)) {
2756 DEBUG ((DEBUG_ERROR, "%a: - Error setting policy for HDDP - Status=%r\n", __func__, Status));
2757 ASSERT_EFI_ERROR (Status);
2758 }
2759
2760 if (Event != NULL) {
2761 gBS->CloseEvent (Event);
2762 }
2763 } else {
2764 DEBUG ((DEBUG_ERROR, "%a: - Unable to locate variable policy protocol - Status=%r\n", __func__, Status));
2765 }
2766}
2767
2778EFIAPI
2780 IN EFI_HANDLE ImageHandle,
2781 IN EFI_SYSTEM_TABLE *SystemTable
2782 )
2783{
2784 VOID *Registration;
2785
2787 &gEdkiiVariablePolicyProtocolGuid,
2788 TPL_CALLBACK,
2790 NULL,
2791 &Registration
2792 );
2793
2794 return EFI_SUCCESS;
2795}
UINT64 UINTN
UINT64 EFIAPI ReadUnaligned64(IN CONST VOID *Buffer)
Definition: Unaligned.c:191
INTN EFIAPI StrCmp(IN CONST CHAR16 *FirstString, IN CONST CHAR16 *SecondString)
Definition: String.c:109
UINTN EFIAPI StrLen(IN CONST CHAR16 *String)
Definition: String.c:30
INTN EFIAPI CompareMem(IN CONST VOID *DestinationBuffer, IN CONST VOID *SourceBuffer, IN UINTN Length)
VOID *EFIAPI CopyMem(OUT VOID *DestinationBuffer, IN CONST VOID *SourceBuffer, IN UINTN Length)
BOOLEAN EFIAPI CompareGuid(IN CONST GUID *Guid1, IN CONST GUID *Guid2)
Definition: MemLibGuid.c:73
VOID *EFIAPI ZeroMem(OUT VOID *Buffer, IN UINTN Length)
VOID * BmGetRamDiskMemoryInfo(IN EFI_DEVICE_PATH_PROTOCOL *RamDiskDevicePath, OUT UINTN *RamDiskSizeInPages)
Definition: BmBoot.c:1346
EFI_DEVICE_PATH_PROTOCOL * BmExpandNetworkFileSystem(IN EFI_HANDLE LoadFileHandle, OUT EFI_HANDLE *RamDiskHandle)
Definition: BmBoot.c:1239
EFI_DEVICE_PATH_PROTOCOL * BmExpandFileDevicePath(IN EFI_DEVICE_PATH_PROTOCOL *FilePath, IN EFI_DEVICE_PATH_PROTOCOL *FullPath)
Definition: BmBoot.c:672
VOID EFIAPI EfiBootManagerBoot(IN EFI_BOOT_MANAGER_LOAD_OPTION *BootOption)
Definition: BmBoot.c:1894
EFI_HANDLE * BmFindUsbDevice(IN EFI_DEVICE_PATH_PROTOCOL *DevicePath, IN UINTN ParentDevicePathSize, OUT UINTN *UsbIoHandleCount)
Definition: BmBoot.c:514
VOID *EFIAPI EfiBootManagerGetLoadOptionBuffer(IN EFI_DEVICE_PATH_PROTOCOL *FilePath, OUT EFI_DEVICE_PATH_PROTOCOL **FullPath, OUT UINTN *FileSize)
Definition: BmBoot.c:1655
BOOLEAN BmIsBootManagerMenuFilePath(EFI_DEVICE_PATH_PROTOCOL *DevicePath)
Definition: BmBoot.c:1808
VOID EFIAPI BmEndOfBdsPerfCode(IN EFI_EVENT Event, IN VOID *Context)
Definition: BmBoot.c:39
EFI_DEVICE_PATH_PROTOCOL * BmExpandUriDevicePath(IN EFI_DEVICE_PATH_PROTOCOL *FilePath, IN EFI_DEVICE_PATH_PROTOCOL *FullPath)
Definition: BmBoot.c:746
EFI_STATUS BmRegisterBootManagerMenu(OUT EFI_BOOT_MANAGER_LOAD_OPTION *BootOption)
Definition: BmBoot.c:2550
EFI_STATUS EFIAPI UefiBootManagerLibConstructor(IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable)
Definition: BmBoot.c:2779
EFI_DEVICE_PATH_PROTOCOL * BmExpandPartitionDevicePath(IN EFI_DEVICE_PATH_PROTOCOL *FilePath)
Definition: BmBoot.c:872
EFI_DEVICE_PATH_PROTOCOL *EFIAPI EfiBootManagerGetNextLoadOptionDevicePath(IN EFI_DEVICE_PATH_PROTOCOL *FilePath, IN EFI_DEVICE_PATH_PROTOCOL *FullPath)
Definition: BmBoot.c:2712
VOID EFIAPI OnVariablePolicyNotification(IN EFI_EVENT Event, IN VOID *Context)
Definition: BmBoot.c:2729
VOID EFIAPI EfiBootManagerRefreshAllBootOption(VOID)
Definition: BmBoot.c:2436
BOOLEAN BmMatchUsbClass(IN EFI_USB_IO_PROTOCOL *UsbIo, IN USB_CLASS_DEVICE_PATH *UsbClass)
Definition: BmBoot.c:303
EFI_DEVICE_PATH_PROTOCOL * BmExpandUsbDevicePath(IN EFI_DEVICE_PATH_PROTOCOL *FilePath, IN EFI_DEVICE_PATH_PROTOCOL *FullPath, IN EFI_DEVICE_PATH_PROTOCOL *ShortformNode)
Definition: BmBoot.c:606
EFI_DEVICE_PATH_PROTOCOL * BmGetNextLoadOptionDevicePath(IN EFI_DEVICE_PATH_PROTOCOL *FilePath, IN EFI_DEVICE_PATH_PROTOCOL *FullPath)
Definition: BmBoot.c:1682
EFI_DEVICE_PATH_PROTOCOL * BmExpandLoadFiles(IN EFI_DEVICE_PATH_PROTOCOL *FilePath)
Definition: BmBoot.c:1538
VOID BmReportLoadFailure(IN UINT32 ErrorCode, IN EFI_STATUS FailureStatus)
Definition: BmBoot.c:1842
VOID EFIAPI EfiBootManagerRegisterLegacyBootSupport(EFI_BOOT_MANAGER_REFRESH_LEGACY_BOOT_OPTION RefreshLegacyBootOption, EFI_BOOT_MANAGER_LEGACY_BOOT LegacyBoot)
Definition: BmBoot.c:60
EFI_BOOT_MANAGER_LOAD_OPTION * BmEnumerateBootOptions(UINTN *BootOptionCount)
Definition: BmBoot.c:2243
UINTN BmFindBootOptionInVariable(IN EFI_BOOT_MANAGER_LOAD_OPTION *OptionToFind)
Definition: BmBoot.c:101
EFI_DEVICE_PATH_PROTOCOL * BmGetRamDiskDevicePath(IN EFI_DEVICE_PATH_PROTOCOL *FilePath)
Definition: BmBoot.c:1308
EFI_GUID mBmHardDriveBootVariableGuid
Definition: BmBoot.c:22
VOID BmDestroyRamDisk(IN EFI_DEVICE_PATH_PROTOCOL *RamDiskDevicePath)
Definition: BmBoot.c:1385
BOOLEAN BmMatchUsbWwid(IN EFI_USB_IO_PROTOCOL *UsbIo, IN USB_WWID_DEVICE_PATH *UsbWwid)
Definition: BmBoot.c:395
EFI_DEVICE_PATH_PROTOCOL * BmAdjustFvFilePath(IN EFI_DEVICE_PATH_PROTOCOL *FilePath)
Definition: BmBoot.c:176
EFI_STATUS EFIAPI EfiBootManagerGetBootManagerMenu(EFI_BOOT_MANAGER_LOAD_OPTION *BootOption)
Definition: BmBoot.c:2656
BOOLEAN BmIsAutoCreateBootOption(EFI_BOOT_MANAGER_LOAD_OPTION *BootOption)
Definition: BmBoot.c:78
VOID BmCachePartitionDevicePath(IN OUT EFI_DEVICE_PATH_PROTOCOL **CachedDevicePath, IN EFI_DEVICE_PATH_PROTOCOL *DevicePath)
Definition: BmBoot.c:807
EFI_DEVICE_PATH_PROTOCOL * BmExpandMediaDevicePath(IN EFI_DEVICE_PATH_PROTOCOL *DevicePath, IN EFI_DEVICE_PATH_PROTOCOL *FullPath)
Definition: BmBoot.c:1072
BOOLEAN BmMatchPartitionDevicePathNode(IN EFI_DEVICE_PATH_PROTOCOL *BlockIoDevicePath, IN HARDDRIVE_DEVICE_PATH *HardDriveDevicePath)
Definition: BmBoot.c:2182
EFI_DEVICE_PATH_PROTOCOL * BmExpandLoadFile(IN EFI_HANDLE LoadFileHandle, IN EFI_DEVICE_PATH_PROTOCOL *FilePath)
Definition: BmBoot.c:1419
BOOLEAN BmMatchHttpBootDevicePath(IN EFI_DEVICE_PATH_PROTOCOL *Left, IN EFI_DEVICE_PATH_PROTOCOL *Right)
Definition: BmBoot.c:1194
BOOLEAN BmIsFvFilePath(IN EFI_DEVICE_PATH_PROTOCOL *DevicePath)
Definition: BmBoot.c:267
VOID BmMakeBootOptionDescriptionUnique(EFI_BOOT_MANAGER_LOAD_OPTION *BootOptions, UINTN BootOptionCount)
CHAR16 * BmGetBootDescription(IN EFI_HANDLE Handle)
EFI_STATUS BmConnectUsbShortFormDevicePath(IN EFI_DEVICE_PATH_PROTOCOL *DevicePath)
Definition: BmConnect.c:245
VOID BmRepairAllControllers(UINTN ReconnectRepairCount)
VOID EFIAPI BmStopHotkeyService(IN EFI_EVENT Event, IN VOID *Context)
Definition: BmHotkey.c:850
VOID * BmGetNextLoadOptionBuffer(IN EFI_BOOT_MANAGER_LOAD_OPTION_TYPE Type, IN EFI_DEVICE_PATH_PROTOCOL *FilePath, OUT EFI_DEVICE_PATH_PROTOCOL **FullPath, OUT UINTN *FileSize)
EFI_STATUS BmGetFreeOptionNumber(IN EFI_BOOT_MANAGER_LOAD_OPTION_TYPE LoadOptionType, OUT UINT16 *FreeOptionNumber)
Definition: BmLoadOption.c:83
VOID BmSetMemoryTypeInformationVariable(IN BOOLEAN Boot)
Definition: BmMisc.c:129
EFI_STATUS BmSetVariableAndReportStatusCodeOnError(IN CHAR16 *VariableName, IN EFI_GUID *VendorGuid, IN UINT32 Attributes, IN UINTN DataSize, IN VOID *Data)
Definition: BmMisc.c:328
EFI_DEVICE_PATH_PROTOCOL * BmDelPartMatchInstance(IN EFI_DEVICE_PATH_PROTOCOL *Multi, IN EFI_DEVICE_PATH_PROTOCOL *Single)
Definition: BmMisc.c:26
BOOLEAN BmMatchDevicePaths(IN EFI_DEVICE_PATH_PROTOCOL *Multi, IN EFI_DEVICE_PATH_PROTOCOL *Single)
Definition: BmMisc.c:82
#define BBS_BBS_DP
Definition: DevicePath.h:1238
#define MSG_IPv6_DP
Definition: DevicePath.h:607
#define MSG_IPv4_DP
Definition: DevicePath.h:566
#define MEDIA_FILEPATH_DP
Definition: DevicePath.h:1098
#define HARDWARE_DEVICE_PATH
Definition: DevicePath.h:68
#define MEDIA_RAM_DISK_DP
Definition: DevicePath.h:1205
#define MSG_URI_DP
Definition: DevicePath.h:879
#define BBS_DEVICE_PATH
Definition: DevicePath.h:1233
#define MEDIA_PIWG_FW_FILE_DP
Definition: DevicePath.h:1130
#define MEDIA_HARDDRIVE_DP
Definition: DevicePath.h:1014
#define MSG_DNS_DP
Definition: DevicePath.h:863
#define MSG_USB_WWID_DP
Definition: DevicePath.h:467
#define MSG_USB_CLASS_DP
Definition: DevicePath.h:434
#define HW_MEMMAP_DP
Definition: DevicePath.h:109
#define MESSAGING_DEVICE_PATH
Definition: DevicePath.h:321
UINT8 EFIAPI DevicePathType(IN CONST VOID *Node)
UINTN EFIAPI DevicePathNodeLength(IN CONST VOID *Node)
UINT8 EFIAPI DevicePathSubType(IN CONST VOID *Node)
EFI_DEVICE_PATH_PROTOCOL *EFIAPI AppendDevicePathNode(IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath OPTIONAL, IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePathNode OPTIONAL)
EFI_DEVICE_PATH_PROTOCOL *EFIAPI FileDevicePath(IN EFI_HANDLE Device OPTIONAL, IN CONST CHAR16 *FileName)
BOOLEAN EFIAPI IsDevicePathEnd(IN CONST VOID *Node)
EFI_DEVICE_PATH_PROTOCOL *EFIAPI NextDevicePathNode(IN CONST VOID *Node)
BOOLEAN EFIAPI IsDevicePathValid(IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath, IN UINTN MaxSize)
EFI_DEVICE_PATH_PROTOCOL *EFIAPI DevicePathFromHandle(IN EFI_HANDLE Handle)
EFI_DEVICE_PATH_PROTOCOL *EFIAPI AppendDevicePathInstance(IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath OPTIONAL, IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePathInstance OPTIONAL)
EFI_DEVICE_PATH_PROTOCOL *EFIAPI CreateDeviceNode(IN UINT8 NodeType, IN UINT8 NodeSubType, IN UINT16 NodeLength)
EFI_DEVICE_PATH_PROTOCOL *EFIAPI AppendDevicePath(IN CONST EFI_DEVICE_PATH_PROTOCOL *FirstDevicePath OPTIONAL, IN CONST EFI_DEVICE_PATH_PROTOCOL *SecondDevicePath OPTIONAL)
EFI_DEVICE_PATH_PROTOCOL *EFIAPI GetNextDevicePathInstance(IN OUT EFI_DEVICE_PATH_PROTOCOL **DevicePath, OUT UINTN *Size)
CHAR16 *EFIAPI ConvertDevicePathToText(IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath, IN BOOLEAN DisplayOnly, IN BOOLEAN AllowShortcuts)
UINTN EFIAPI GetDevicePathSize(IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath)
EFI_DEVICE_PATH_PROTOCOL *EFIAPI DuplicateDevicePath(IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath)
BOOLEAN EFIAPI IsDevicePathEndType(IN CONST VOID *Node)
VOID EFIAPI SetDevicePathEndNode(OUT VOID *Node)
BOOLEAN EFIAPI ReportErrorCodeEnabled(VOID)
EFI_STATUS EFIAPI GetFileDevicePathFromAnyFv(IN CONST EFI_GUID *NameGuid, IN EFI_SECTION_TYPE SectionType, IN UINTN SectionInstance, OUT EFI_DEVICE_PATH_PROTOCOL **FvFileDevicePath)
EFI_STATUS EFIAPI GetSectionFromAnyFv(IN CONST EFI_GUID *NameGuid, IN EFI_SECTION_TYPE SectionType, IN UINTN SectionInstance, OUT VOID **Buffer, OUT UINTN *Size)
VOID *EFIAPI ReallocatePool(IN UINTN OldSize, IN UINTN NewSize, IN VOID *OldBuffer OPTIONAL)
VOID *EFIAPI AllocateAlignedReservedPages(IN UINTN Pages, IN UINTN Alignment)
VOID EFIAPI FreePool(IN VOID *Buffer)
VOID *EFIAPI AllocateCopyPool(IN UINTN AllocationSize, IN CONST VOID *Buffer)
VOID EFIAPI FreeAlignedPages(IN VOID *Buffer, IN UINTN Pages)
UINTN EFIAPI UnicodeSPrint(OUT CHAR16 *StartOfBuffer, IN UINTN BufferSize, IN CONST CHAR16 *FormatString,...)
Definition: PrintLib.c:408
EFI_RUNTIME_SERVICES * gRT
#define NULL
Definition: Base.h:319
#define CONST
Definition: Base.h:259
#define VOID
Definition: Base.h:269
#define TRUE
Definition: Base.h:301
#define FALSE
Definition: Base.h:307
#define IN
Definition: Base.h:279
#define OUT
Definition: Base.h:284
#define ASSERT_EFI_ERROR(StatusParameter)
Definition: DebugLib.h:463
#define DEBUG_CODE_BEGIN()
Definition: DebugLib.h:565
#define DEBUG(Expression)
Definition: DebugLib.h:435
#define DEBUG_CODE_END()
Definition: DebugLib.h:579
#define DEBUG_CODE(Expression)
Definition: DebugLib.h:591
#define REPORT_STATUS_CODE_EX(Type, Value, Instance, CallerId, ExtendedDataGuid, ExtendedData, ExtendedDataSize)
#define REPORT_STATUS_CODE(Type, Value)
#define PcdGet32(TokenName)
Definition: PcdLib.h:362
#define PcdGetPtr(TokenName)
Definition: PcdLib.h:388
#define PERF_CODE(Expression)
#define PERF_START_EX(Handle, Token, Module, TimeStamp, Identifier)
#define PERF_CROSSMODULE_END(MeasurementString)
#define PERF_END_EX(Handle, Token, Module, TimeStamp, Identifier)
#define EFI_SECTION_PE32
#define EFI_ERROR_MINOR
Definition: PiStatusCode.h:59
#define EFI_PROGRESS_CODE
Definition: PiStatusCode.h:44
VOID *EFIAPI AllocatePool(IN UINTN AllocationSize)
EFI_GUID gEfiRamDiskProtocolGuid
RETURN_STATUS EFI_STATUS
Definition: UefiBaseType.h:29
VOID * EFI_EVENT
Definition: UefiBaseType.h:37
GUID EFI_GUID
Definition: UefiBaseType.h:25
#define EFI_SIZE_TO_PAGES(Size)
Definition: UefiBaseType.h:200
VOID * EFI_HANDLE
Definition: UefiBaseType.h:33
#define EFI_SUCCESS
Definition: UefiBaseType.h:112
EFI_STATUS EFIAPI EfiBootManagerLoadOptionToVariable(IN CONST EFI_BOOT_MANAGER_LOAD_OPTION *LoadOption)
Definition: BmLoadOption.c:168
EFI_STATUS EFIAPI EfiBootManagerFreeLoadOption(IN EFI_BOOT_MANAGER_LOAD_OPTION *LoadOption)
EFI_BOOT_MANAGER_LOAD_OPTION *EFIAPI EfiBootManagerGetLoadOptions(OUT UINTN *LoadOptionCount, IN EFI_BOOT_MANAGER_LOAD_OPTION_TYPE LoadOptionType)
VOID(EFIAPI * EFI_BOOT_MANAGER_LEGACY_BOOT)(IN EFI_BOOT_MANAGER_LOAD_OPTION *BootOption)
EFI_STATUS EFIAPI EfiBootManagerAddLoadOptionVariable(IN OUT EFI_BOOT_MANAGER_LOAD_OPTION *Option, IN UINTN Position)
Definition: BmLoadOption.c:365
EFI_STATUS EFIAPI EfiBootManagerFreeLoadOptions(IN EFI_BOOT_MANAGER_LOAD_OPTION *LoadOptions, IN UINTN LoadOptionCount)
EFI_STATUS EFIAPI EfiBootManagerVariableToLoadOption(IN CHAR16 *VariableName, IN OUT EFI_BOOT_MANAGER_LOAD_OPTION *LoadOption)
VOID(EFIAPI * EFI_BOOT_MANAGER_REFRESH_LEGACY_BOOT_OPTION)(VOID)
EFI_STATUS EFIAPI EfiBootManagerConnectDevicePath(IN EFI_DEVICE_PATH_PROTOCOL *DevicePathToConnect, OUT EFI_HANDLE *MatchingHandle OPTIONAL)
Definition: BmConnect.c:108
INTN EFIAPI EfiBootManagerFindLoadOption(IN CONST EFI_BOOT_MANAGER_LOAD_OPTION *Key, IN CONST EFI_BOOT_MANAGER_LOAD_OPTION *Array, IN UINTN Count)
Definition: BmLoadOption.c:550
EFI_STATUS EFIAPI EfiBootManagerDeleteLoadOptionVariable(IN UINTN OptionNumber, IN EFI_BOOT_MANAGER_LOAD_OPTION_TYPE OptionType)
Definition: BmLoadOption.c:586
VOID EFIAPI EfiBootManagerConnectAll(VOID)
Definition: BmConnect.c:67
EFI_STATUS EFIAPI EfiBootManagerInitializeLoadOption(IN OUT EFI_BOOT_MANAGER_LOAD_OPTION *Option, IN UINTN OptionNumber, IN EFI_BOOT_MANAGER_LOAD_OPTION_TYPE OptionType, IN UINT32 Attributes, IN CHAR16 *Description, IN EFI_DEVICE_PATH_PROTOCOL *FilePath, IN UINT8 *OptionalData, IN UINT32 OptionalDataSize)
EFI_HANDLE gImageHandle
EFI_BOOT_SERVICES * gBS
EFI_STATUS EFIAPI EfiCreateEventLegacyBootEx(IN EFI_TPL NotifyTpl, IN EFI_EVENT_NOTIFY NotifyFunction OPTIONAL, IN VOID *NotifyContext OPTIONAL, OUT EFI_EVENT *LegacyBootEvent)
Definition: UefiNotTiano.c:68
EFI_STATUS EFIAPI GetVariable2(IN CONST CHAR16 *Name, IN CONST EFI_GUID *Guid, OUT VOID **Value, OUT UINTN *Size OPTIONAL)
Definition: UefiLib.c:1313
VOID EFIAPI EfiSignalEventReadyToBoot(VOID)
Definition: UefiNotTiano.c:219
EFI_EVENT EFIAPI EfiCreateProtocolNotifyEvent(IN EFI_GUID *ProtocolGuid, IN EFI_TPL NotifyTpl, IN EFI_EVENT_NOTIFY NotifyFunction, IN VOID *NotifyContext OPTIONAL, OUT VOID **Registration)
Definition: UefiLib.c:130
EFI_GUID *EFIAPI EfiGetNameGuidFromFwVolDevicePathNode(IN CONST MEDIA_FW_VOL_FILEPATH_DEVICE_PATH *FvDevicePathNode)
Definition: UefiNotTiano.c:292
#define EFI_VARIABLE_NON_VOLATILE
@ ByProtocol
Definition: UefiSpec.h:1528
EFI_BLOCK_IO_MEDIA * Media
Definition: BlockIo.h:224
BOOLEAN RemovableMedia
Definition: BlockIo.h:137
UINT32 BlockSize
Definition: BlockIo.h:167
VOID * LoadOptions
A pointer to the image's binary load options.
Definition: LoadedImage.h:62
EFI_HANDLE DeviceHandle
The device handle that the EFI Image was loaded from.
Definition: LoadedImage.h:53
UINT32 LoadOptionsSize
The size in bytes of LoadOptions.
Definition: LoadedImage.h:61
Definition: Base.h:213