TianoCore EDK2 master
Loading...
Searching...
No Matches
BmLoadOption.c
Go to the documentation of this file.
1
10#include "InternalBm.h"
11
12#include <Library/VariablePolicyHelperLib.h>
13
15CHAR16 *mBmLoadOptionName[] = {
16 L"Driver",
17 L"SysPrep",
18 L"Boot",
19 L"PlatformRecovery"
20};
21
23CHAR16 *mBmLoadOptionOrderName[] = {
27 NULL // PlatformRecovery#### doesn't have associated *Order variable
28};
29
36VOID
38 BM_VARIABLE_VISITOR Visitor,
39 VOID *Context
40 )
41{
42 EFI_STATUS Status;
43 CHAR16 *Name;
44 EFI_GUID Guid;
45 UINTN NameSize;
46 UINTN NewNameSize;
47
48 NameSize = sizeof (CHAR16);
49 Name = AllocateZeroPool (NameSize);
50 ASSERT (Name != NULL);
51 while (TRUE) {
52 NewNameSize = NameSize;
53 Status = gRT->GetNextVariableName (&NewNameSize, Name, &Guid);
54 if (Status == EFI_BUFFER_TOO_SMALL) {
55 Name = ReallocatePool (NameSize, NewNameSize, Name);
56 ASSERT (Name != NULL);
57 Status = gRT->GetNextVariableName (&NewNameSize, Name, &Guid);
58 NameSize = NewNameSize;
59 }
60
61 if (Status == EFI_NOT_FOUND) {
62 break;
63 }
64
65 ASSERT_EFI_ERROR (Status);
66
67 Visitor (Name, &Guid, Context);
68 }
69
70 FreePool (Name);
71}
72
86 IN EFI_BOOT_MANAGER_LOAD_OPTION_TYPE LoadOptionType,
87 OUT UINT16 *FreeOptionNumber
88 )
89{
90 UINTN OptionNumber;
91 UINTN Index;
92 UINT16 *OptionOrder;
93 UINTN OptionOrderSize;
94 UINT16 *BootNext;
95
96 ASSERT (FreeOptionNumber != NULL);
97 ASSERT (
98 LoadOptionType == LoadOptionTypeDriver ||
99 LoadOptionType == LoadOptionTypeBoot ||
100 LoadOptionType == LoadOptionTypeSysPrep
101 );
102
103 GetEfiGlobalVariable2 (mBmLoadOptionOrderName[LoadOptionType], (VOID **)&OptionOrder, &OptionOrderSize);
104 ASSERT ((OptionOrder != NULL && OptionOrderSize != 0) || (OptionOrder == NULL && OptionOrderSize == 0));
105
106 BootNext = NULL;
107 if (LoadOptionType == LoadOptionTypeBoot) {
108 GetEfiGlobalVariable2 (L"BootNext", (VOID **)&BootNext, NULL);
109 }
110
111 for (OptionNumber = 0;
112 OptionNumber < OptionOrderSize / sizeof (UINT16)
113 + ((BootNext != NULL) ? 1 : 0);
114 OptionNumber++
115 )
116 {
117 //
118 // Search in OptionOrder whether the OptionNumber exists
119 //
120 for (Index = 0; Index < OptionOrderSize / sizeof (UINT16); Index++) {
121 if (OptionNumber == OptionOrder[Index]) {
122 break;
123 }
124 }
125
126 //
127 // We didn't find it in the ****Order array and it doesn't equal to BootNext
128 // Otherwise, OptionNumber equals to OptionOrderSize / sizeof (UINT16) + 1
129 //
130 if ((Index == OptionOrderSize / sizeof (UINT16)) &&
131 ((BootNext == NULL) || (OptionNumber != *BootNext))
132 )
133 {
134 break;
135 }
136 }
137
138 if (OptionOrder != NULL) {
139 FreePool (OptionOrder);
140 }
141
142 if (BootNext != NULL) {
143 FreePool (BootNext);
144 }
145
146 //
147 // When BootOrder & BootNext conver all numbers in the range [0 ... 0xffff],
148 // OptionNumber equals to 0x10000 which is not valid.
149 //
150 ASSERT (OptionNumber <= 0x10000);
151 if (OptionNumber == 0x10000) {
152 return EFI_OUT_OF_RESOURCES;
153 } else {
154 *FreeOptionNumber = (UINT16)OptionNumber;
155 return EFI_SUCCESS;
156 }
157}
158
169EFIAPI
172 )
173{
174 EFI_STATUS Status;
175 UINTN VariableSize;
176 UINT8 *Variable;
177 UINT8 *Ptr;
178 CHAR16 OptionName[BM_OPTION_NAME_LEN];
179 CHAR16 *Description;
180 CHAR16 NullChar;
181 EDKII_VARIABLE_POLICY_PROTOCOL *VariablePolicy;
182 UINT32 VariableAttributes;
183
184 if ((Option->OptionNumber == LoadOptionNumberUnassigned) ||
185 (Option->FilePath == NULL) ||
186 ((UINT32)Option->OptionType >= LoadOptionTypeMax)
187 )
188 {
189 return EFI_INVALID_PARAMETER;
190 }
191
192 //
193 // Convert NULL description to empty description
194 //
195 NullChar = L'\0';
196 Description = Option->Description;
197 if (Description == NULL) {
198 Description = &NullChar;
199 }
200
201 /*
202 UINT32 Attributes;
203 UINT16 FilePathListLength;
204 CHAR16 Description[];
205 EFI_DEVICE_PATH_PROTOCOL FilePathList[];
206 UINT8 OptionalData[];
207TODO: FilePathList[] IS:
208A packed array of UEFI device paths. The first element of the
209array is a device path that describes the device and location of the
210Image for this load option. The FilePathList[0] is specific
211to the device type. Other device paths may optionally exist in the
212FilePathList, but their usage is OSV specific. Each element
213in the array is variable length, and ends at the device path end
214structure.
215 */
216 VariableSize = sizeof (Option->Attributes)
217 + sizeof (UINT16)
218 + StrSize (Description)
219 + GetDevicePathSize (Option->FilePath)
220 + Option->OptionalDataSize;
221
222 Variable = AllocatePool (VariableSize);
223 ASSERT (Variable != NULL);
224
225 Ptr = Variable;
226 WriteUnaligned32 ((UINT32 *)Ptr, Option->Attributes);
227 Ptr += sizeof (Option->Attributes);
228
229 WriteUnaligned16 ((UINT16 *)Ptr, (UINT16)GetDevicePathSize (Option->FilePath));
230 Ptr += sizeof (UINT16);
231
232 CopyMem (Ptr, Description, StrSize (Description));
233 Ptr += StrSize (Description);
234
235 CopyMem (Ptr, Option->FilePath, GetDevicePathSize (Option->FilePath));
236 Ptr += GetDevicePathSize (Option->FilePath);
237
238 CopyMem (Ptr, Option->OptionalData, Option->OptionalDataSize);
239
240 UnicodeSPrint (OptionName, sizeof (OptionName), L"%s%04x", mBmLoadOptionName[Option->OptionType], Option->OptionNumber);
241
242 VariableAttributes = EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE;
243 if (Option->OptionType == LoadOptionTypePlatformRecovery) {
244 //
245 // Lock the PlatformRecovery####
246 //
247 Status = gBS->LocateProtocol (&gEdkiiVariablePolicyProtocolGuid, NULL, (VOID **)&VariablePolicy);
248 if (!EFI_ERROR (Status)) {
249 Status = RegisterBasicVariablePolicy (
250 VariablePolicy,
251 &gEfiGlobalVariableGuid,
252 OptionName,
253 VARIABLE_POLICY_NO_MIN_SIZE,
254 VARIABLE_POLICY_NO_MAX_SIZE,
255 VARIABLE_POLICY_NO_MUST_ATTR,
256 VARIABLE_POLICY_NO_CANT_ATTR,
257 VARIABLE_POLICY_TYPE_LOCK_NOW
258 );
259 ASSERT_EFI_ERROR (Status);
260 }
261
262 VariableAttributes = EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS;
263 }
264
265 Status = gRT->SetVariable (
266 OptionName,
267 &gEfiGlobalVariableGuid,
268 VariableAttributes,
269 VariableSize,
270 Variable
271 );
272 FreePool (Variable);
273
274 return Status;
275}
276
291 IN CHAR16 *OptionOrderName,
292 IN UINT16 OptionNumber,
293 IN UINTN Position
294 )
295{
296 EFI_STATUS Status;
297 UINTN Index;
298 UINT16 *OptionOrder;
299 UINT16 *NewOptionOrder;
300 UINTN OptionOrderSize;
301
302 //
303 // Update the option order variable
304 //
305 GetEfiGlobalVariable2 (OptionOrderName, (VOID **)&OptionOrder, &OptionOrderSize);
306 ASSERT ((OptionOrder != NULL && OptionOrderSize != 0) || (OptionOrder == NULL && OptionOrderSize == 0));
307
308 Status = EFI_SUCCESS;
309 for (Index = 0; Index < OptionOrderSize / sizeof (UINT16); Index++) {
310 if (OptionOrder[Index] == OptionNumber) {
311 Status = EFI_ALREADY_STARTED;
312 break;
313 }
314 }
315
316 if (!EFI_ERROR (Status)) {
317 Position = MIN (Position, OptionOrderSize / sizeof (UINT16));
318
319 NewOptionOrder = AllocatePool (OptionOrderSize + sizeof (UINT16));
320 ASSERT (NewOptionOrder != NULL);
321 if (OptionOrderSize != 0) {
322 CopyMem (NewOptionOrder, OptionOrder, Position * sizeof (UINT16));
323 CopyMem (&NewOptionOrder[Position + 1], &OptionOrder[Position], OptionOrderSize - Position * sizeof (UINT16));
324 }
325
326 NewOptionOrder[Position] = OptionNumber;
327
328 Status = gRT->SetVariable (
329 OptionOrderName,
330 &gEfiGlobalVariableGuid,
331 EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE,
332 OptionOrderSize + sizeof (UINT16),
333 NewOptionOrder
334 );
335 FreePool (NewOptionOrder);
336 }
337
338 if (OptionOrder != NULL) {
339 FreePool (OptionOrder);
340 }
341
342 return Status;
343}
344
366EFIAPI
369 IN UINTN Position
370 )
371{
372 EFI_STATUS Status;
373 UINT16 OptionNumber;
374
375 if (Option == NULL) {
376 return EFI_INVALID_PARAMETER;
377 }
378
379 if ((Option->OptionType != LoadOptionTypeDriver) &&
380 (Option->OptionType != LoadOptionTypeSysPrep) &&
381 (Option->OptionType != LoadOptionTypeBoot)
382 )
383 {
384 return EFI_INVALID_PARAMETER;
385 }
386
387 //
388 // Get the free option number if the option number is unassigned
389 //
390 if (Option->OptionNumber == LoadOptionNumberUnassigned) {
391 Status = BmGetFreeOptionNumber (Option->OptionType, &OptionNumber);
392 if (EFI_ERROR (Status)) {
393 return Status;
394 }
395
396 Option->OptionNumber = OptionNumber;
397 }
398
399 if (Option->OptionNumber >= LoadOptionNumberMax) {
400 return EFI_INVALID_PARAMETER;
401 }
402
403 Status = BmAddOptionNumberToOrderVariable (mBmLoadOptionOrderName[Option->OptionType], (UINT16)Option->OptionNumber, Position);
404 if (!EFI_ERROR (Status)) {
405 //
406 // Save the Boot#### or Driver#### variable
407 //
408 Status = EfiBootManagerLoadOptionToVariable (Option);
409 if (EFI_ERROR (Status)) {
410 //
411 // Remove the #### from *Order variable when the Driver####/SysPrep####/Boot#### cannot be saved.
412 //
413 EfiBootManagerDeleteLoadOptionVariable (Option->OptionNumber, Option->OptionType);
414 }
415 }
416
417 return Status;
418}
419
427VOID
428EFIAPI
430 EFI_BOOT_MANAGER_LOAD_OPTION_TYPE OptionType,
431 SORT_COMPARE CompareFunction
432 )
433{
434 EFI_STATUS Status;
436 UINTN LoadOptionCount;
437 UINTN Index;
438 UINT16 *OptionOrder;
439
440 LoadOption = EfiBootManagerGetLoadOptions (&LoadOptionCount, OptionType);
441
442 //
443 // Insertion sort algorithm
444 //
446 LoadOption,
447 LoadOptionCount,
449 CompareFunction
450 );
451
452 //
453 // Create new ****Order variable
454 //
455 OptionOrder = AllocatePool (LoadOptionCount * sizeof (UINT16));
456 ASSERT (OptionOrder != NULL);
457 for (Index = 0; Index < LoadOptionCount; Index++) {
458 OptionOrder[Index] = (UINT16)LoadOption[Index].OptionNumber;
459 }
460
461 Status = gRT->SetVariable (
462 mBmLoadOptionOrderName[OptionType],
463 &gEfiGlobalVariableGuid,
464 EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE,
465 LoadOptionCount * sizeof (UINT16),
466 OptionOrder
467 );
468 //
469 // Changing the *Order content without increasing its size with current variable implementation shouldn't fail.
470 //
471 ASSERT_EFI_ERROR (Status);
472
473 FreePool (OptionOrder);
474 EfiBootManagerFreeLoadOptions (LoadOption, LoadOptionCount);
475}
476
493EFIAPI
496 IN UINTN OptionNumber,
497 IN EFI_BOOT_MANAGER_LOAD_OPTION_TYPE OptionType,
498 IN UINT32 Attributes,
499 IN CHAR16 *Description,
501 IN UINT8 *OptionalData OPTIONAL,
502 IN UINT32 OptionalDataSize
503 )
504{
505 if ((Option == NULL) || (Description == NULL) || (FilePath == NULL)) {
506 return EFI_INVALID_PARAMETER;
507 }
508
509 if (((OptionalData != NULL) && (OptionalDataSize == 0)) ||
510 ((OptionalData == NULL) && (OptionalDataSize != 0)))
511 {
512 return EFI_INVALID_PARAMETER;
513 }
514
515 if ((UINT32)OptionType >= LoadOptionTypeMax) {
516 return EFI_INVALID_PARAMETER;
517 }
518
519 ZeroMem (Option, sizeof (EFI_BOOT_MANAGER_LOAD_OPTION));
520 Option->OptionNumber = OptionNumber;
521 Option->OptionType = OptionType;
522 Option->Attributes = Attributes;
523 Option->Description = AllocateCopyPool (StrSize (Description), Description);
524 Option->FilePath = DuplicateDevicePath (FilePath);
525 if (OptionalData != NULL) {
526 Option->OptionalData = AllocateCopyPool (OptionalDataSize, OptionalData);
527 Option->OptionalDataSize = OptionalDataSize;
528 }
529
530 return EFI_SUCCESS;
531}
532
546INTN
547EFIAPI
551 IN UINTN Count
552 )
553{
554 UINTN Index;
555
556 for (Index = 0; Index < Count; Index++) {
557 if ((Key->OptionType == Array[Index].OptionType) &&
558 (Key->Attributes == Array[Index].Attributes) &&
559 (StrCmp (Key->Description, Array[Index].Description) == 0) &&
560 (CompareMem (Key->FilePath, Array[Index].FilePath, GetDevicePathSize (Key->FilePath)) == 0) &&
561 (Key->OptionalDataSize == Array[Index].OptionalDataSize) &&
562 (CompareMem (Key->OptionalData, Array[Index].OptionalData, Key->OptionalDataSize) == 0))
563 {
564 return (INTN)Index;
565 }
566 }
567
568 return -1;
569}
570
583EFIAPI
585 IN UINTN OptionNumber,
586 IN EFI_BOOT_MANAGER_LOAD_OPTION_TYPE OptionType
587 )
588{
589 UINT16 *OptionOrder;
590 UINTN OptionOrderSize;
591 UINTN Index;
592 CHAR16 OptionName[BM_OPTION_NAME_LEN];
593
594 if (((UINT32)OptionType >= LoadOptionTypeMax) || (OptionNumber >= LoadOptionNumberMax)) {
595 return EFI_INVALID_PARAMETER;
596 }
597
598 if ((OptionType == LoadOptionTypeDriver) || (OptionType == LoadOptionTypeSysPrep) || (OptionType == LoadOptionTypeBoot)) {
599 //
600 // If the associated *Order exists, firstly remove the reference in *Order for
601 // Driver####, SysPrep#### and Boot####.
602 //
603 GetEfiGlobalVariable2 (mBmLoadOptionOrderName[OptionType], (VOID **)&OptionOrder, &OptionOrderSize);
604 ASSERT ((OptionOrder != NULL && OptionOrderSize != 0) || (OptionOrder == NULL && OptionOrderSize == 0));
605
606 for (Index = 0; Index < OptionOrderSize / sizeof (UINT16); Index++) {
607 if (OptionOrder[Index] == OptionNumber) {
608 OptionOrderSize -= sizeof (UINT16);
609 CopyMem (&OptionOrder[Index], &OptionOrder[Index + 1], OptionOrderSize - Index * sizeof (UINT16));
610 gRT->SetVariable (
611 mBmLoadOptionOrderName[OptionType],
612 &gEfiGlobalVariableGuid,
613 EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE,
614 OptionOrderSize,
615 OptionOrder
616 );
617 break;
618 }
619 }
620
621 if (OptionOrder != NULL) {
622 FreePool (OptionOrder);
623 }
624 }
625
626 //
627 // Remove the Driver####, SysPrep####, Boot#### or PlatformRecovery#### itself.
628 //
629 UnicodeSPrint (OptionName, sizeof (OptionName), L"%s%04x", mBmLoadOptionName[OptionType], OptionNumber);
630 return gRT->SetVariable (
631 OptionName,
632 &gEfiGlobalVariableGuid,
633 0,
634 0,
635 NULL
636 );
637}
638
655UINTN
658 IN UINTN MaxSize
659 )
660{
661 UINTN Size;
662 UINTN NodeSize;
663
664 if (DevicePath == NULL) {
665 return 0;
666 }
667
668 //
669 // Search for the end of the device path structure
670 //
671 Size = 0;
672 while (!IsDevicePathEnd (DevicePath)) {
673 NodeSize = DevicePathNodeLength (DevicePath);
674 if (NodeSize == 0) {
675 return 0;
676 }
677
678 Size += NodeSize;
679 if (Size > MaxSize) {
680 return 0;
681 }
682
683 DevicePath = NextDevicePathNode (DevicePath);
684 }
685
686 Size += DevicePathNodeLength (DevicePath);
687 if (Size > MaxSize) {
688 return 0;
689 }
690
691 return Size;
692}
693
712UINTN
714 IN CONST CHAR16 *String,
715 IN UINTN MaxStringLen
716 )
717{
718 UINTN Length;
719
720 ASSERT (String != NULL && MaxStringLen != 0);
721 ASSERT (((UINTN)String & BIT0) == 0);
722
723 for (Length = 0; *String != L'\0' && MaxStringLen != Length; String++, Length += 2) {
724 }
725
726 if ((*String != L'\0') && (MaxStringLen == Length)) {
727 return 0;
728 }
729
730 return Length + 2;
731}
732
744BOOLEAN
746 UINT8 *Variable,
747 UINTN VariableSize
748 )
749{
750 UINT16 FilePathSize;
751 EFI_DEVICE_PATH_PROTOCOL *DevicePath;
752 UINTN DescriptionSize;
753
754 if (VariableSize <= sizeof (UINT16) + sizeof (UINT32)) {
755 return FALSE;
756 }
757
758 //
759 // Skip the option attribute
760 //
761 Variable += sizeof (UINT32);
762
763 //
764 // Get the option's device path size
765 //
766 FilePathSize = ReadUnaligned16 ((UINT16 *)Variable);
767 Variable += sizeof (UINT16);
768
769 //
770 // Get the option's description string size
771 //
772 DescriptionSize = BmStrSizeEx ((CHAR16 *)Variable, VariableSize - sizeof (UINT16) - sizeof (UINT32));
773 Variable += DescriptionSize;
774
775 //
776 // Get the option's device path
777 //
778 DevicePath = (EFI_DEVICE_PATH_PROTOCOL *)Variable;
779
780 //
781 // Validation boot option variable.
782 //
783 if ((FilePathSize == 0) || (DescriptionSize == 0)) {
784 return FALSE;
785 }
786
787 if (sizeof (UINT32) + sizeof (UINT16) + DescriptionSize + FilePathSize > VariableSize) {
788 return FALSE;
789 }
790
791 return (BOOLEAN)(BmGetDevicePathSizeEx (DevicePath, FilePathSize) != 0);
792}
793
806BOOLEAN
807EFIAPI
809 IN CHAR16 *VariableName,
810 OUT EFI_BOOT_MANAGER_LOAD_OPTION_TYPE *OptionType OPTIONAL,
811 OUT UINT16 *OptionNumber OPTIONAL
812 )
813{
814 UINTN VariableNameLen;
815 UINTN Index;
816 UINTN Uint;
817 EFI_BOOT_MANAGER_LOAD_OPTION_TYPE LocalOptionType;
818 UINT16 LocalOptionNumber;
819
820 if (VariableName == NULL) {
821 return FALSE;
822 }
823
824 VariableNameLen = StrLen (VariableName);
825
826 //
827 // Return FALSE when the variable name length is too small.
828 //
829 if (VariableNameLen <= 4) {
830 return FALSE;
831 }
832
833 //
834 // Return FALSE when the variable name doesn't start with Driver/SysPrep/Boot/PlatformRecovery.
835 //
836 for (LocalOptionType = 0; LocalOptionType < ARRAY_SIZE (mBmLoadOptionName); LocalOptionType++) {
837 if ((VariableNameLen - 4 == StrLen (mBmLoadOptionName[LocalOptionType])) &&
838 (StrnCmp (VariableName, mBmLoadOptionName[LocalOptionType], VariableNameLen - 4) == 0)
839 )
840 {
841 break;
842 }
843 }
844
845 if (LocalOptionType == ARRAY_SIZE (mBmLoadOptionName)) {
846 return FALSE;
847 }
848
849 //
850 // Return FALSE when the last four characters are not hex digits.
851 //
852 LocalOptionNumber = 0;
853 for (Index = VariableNameLen - 4; Index < VariableNameLen; Index++) {
854 Uint = BmCharToUint (VariableName[Index]);
855 if (Uint == -1) {
856 break;
857 } else {
858 LocalOptionNumber = (UINT16)Uint + LocalOptionNumber * 0x10;
859 }
860 }
861
862 if (Index != VariableNameLen) {
863 return FALSE;
864 }
865
866 if (OptionType != NULL) {
867 *OptionType = LocalOptionType;
868 }
869
870 if (OptionNumber != NULL) {
871 *OptionNumber = LocalOptionNumber;
872 }
873
874 return TRUE;
875}
876
889EFIAPI
891 IN CHAR16 *VariableName,
892 IN EFI_GUID *VendorGuid,
894 )
895{
896 EFI_STATUS Status;
897 UINT32 Attribute;
898 UINT16 FilePathSize;
899 UINT8 *Variable;
900 UINT8 *VariablePtr;
901 UINTN VariableSize;
902 EFI_DEVICE_PATH_PROTOCOL *FilePath;
903 UINT8 *OptionalData;
904 UINT32 OptionalDataSize;
905 CHAR16 *Description;
906 EFI_BOOT_MANAGER_LOAD_OPTION_TYPE OptionType;
907 UINT16 OptionNumber;
908
909 if ((VariableName == NULL) || (Option == NULL)) {
910 return EFI_INVALID_PARAMETER;
911 }
912
913 if (!EfiBootManagerIsValidLoadOptionVariableName (VariableName, &OptionType, &OptionNumber)) {
914 return EFI_INVALID_PARAMETER;
915 }
916
917 //
918 // Read the variable
919 //
920 GetVariable2 (VariableName, VendorGuid, (VOID **)&Variable, &VariableSize);
921 if (Variable == NULL) {
922 return EFI_NOT_FOUND;
923 }
924
925 //
926 // Validate *#### variable data.
927 //
928 if (!BmValidateOption (Variable, VariableSize)) {
929 FreePool (Variable);
930 return EFI_INVALID_PARAMETER;
931 }
932
933 //
934 // Get the option attribute
935 //
936 VariablePtr = Variable;
937 Attribute = ReadUnaligned32 ((UINT32 *)VariablePtr);
938 VariablePtr += sizeof (UINT32);
939
940 //
941 // Get the option's device path size
942 //
943 FilePathSize = ReadUnaligned16 ((UINT16 *)VariablePtr);
944 VariablePtr += sizeof (UINT16);
945
946 //
947 // Get the option's description string
948 //
949 Description = (CHAR16 *)VariablePtr;
950
951 //
952 // Get the option's description string size
953 //
954 VariablePtr += StrSize ((CHAR16 *)VariablePtr);
955
956 //
957 // Get the option's device path
958 //
959 FilePath = (EFI_DEVICE_PATH_PROTOCOL *)VariablePtr;
960 VariablePtr += FilePathSize;
961
962 OptionalDataSize = (UINT32)(VariableSize - ((UINTN)VariablePtr - (UINTN)Variable));
963 if (OptionalDataSize == 0) {
964 OptionalData = NULL;
965 } else {
966 OptionalData = VariablePtr;
967 }
968
970 Option,
971 OptionNumber,
972 OptionType,
973 Attribute,
974 Description,
975 FilePath,
976 OptionalData,
977 OptionalDataSize
978 );
979 ASSERT_EFI_ERROR (Status);
980
981 CopyGuid (&Option->VendorGuid, VendorGuid);
982
983 FreePool (Variable);
984 return Status;
985}
986
997EFIAPI
999 IN CHAR16 *VariableName,
1001 )
1002{
1003 return EfiBootManagerVariableToLoadOptionEx (VariableName, &gEfiGlobalVariableGuid, Option);
1004}
1005
1006typedef struct {
1007 EFI_BOOT_MANAGER_LOAD_OPTION_TYPE OptionType;
1008 EFI_GUID *Guid;
1010 UINTN OptionCount;
1012
1021VOID
1023 IN CHAR16 *Name,
1024 IN EFI_GUID *Guid,
1025 IN VOID *Context
1026 )
1027{
1028 EFI_STATUS Status;
1029 EFI_BOOT_MANAGER_LOAD_OPTION_TYPE OptionType;
1030 UINT16 OptionNumber;
1032 UINTN Index;
1034
1035 Param = (BM_COLLECT_LOAD_OPTIONS_PARAM *)Context;
1036
1037 if (CompareGuid (Guid, Param->Guid) && (
1038 (Param->OptionType == LoadOptionTypePlatformRecovery) &&
1039 EfiBootManagerIsValidLoadOptionVariableName (Name, &OptionType, &OptionNumber) &&
1040 (OptionType == LoadOptionTypePlatformRecovery)
1041 ))
1042 {
1043 Status = EfiBootManagerVariableToLoadOptionEx (Name, Guid, &Option);
1044 if (!EFI_ERROR (Status)) {
1045 for (Index = 0; Index < Param->OptionCount; Index++) {
1046 if (Param->Options[Index].OptionNumber > Option.OptionNumber) {
1047 break;
1048 }
1049 }
1050
1051 Param->Options = ReallocatePool (
1052 Param->OptionCount * sizeof (EFI_BOOT_MANAGER_LOAD_OPTION),
1053 (Param->OptionCount + 1) * sizeof (EFI_BOOT_MANAGER_LOAD_OPTION),
1054 Param->Options
1055 );
1056 ASSERT (Param->Options != NULL);
1057 CopyMem (&Param->Options[Index + 1], &Param->Options[Index], (Param->OptionCount - Index) * sizeof (EFI_BOOT_MANAGER_LOAD_OPTION));
1058 CopyMem (&Param->Options[Index], &Option, sizeof (EFI_BOOT_MANAGER_LOAD_OPTION));
1059 Param->OptionCount++;
1060 }
1061 }
1062}
1063
1077EFIAPI
1079 OUT UINTN *OptionCount,
1080 IN EFI_BOOT_MANAGER_LOAD_OPTION_TYPE LoadOptionType
1081 )
1082{
1083 EFI_STATUS Status;
1084 UINT16 *OptionOrder;
1085 UINTN OptionOrderSize;
1086 UINTN Index;
1087 UINTN OptionIndex;
1089 CHAR16 OptionName[BM_OPTION_NAME_LEN];
1090 UINT16 OptionNumber;
1092
1093 *OptionCount = 0;
1094 Options = NULL;
1095
1096 if ((LoadOptionType == LoadOptionTypeDriver) || (LoadOptionType == LoadOptionTypeSysPrep) || (LoadOptionType == LoadOptionTypeBoot)) {
1097 //
1098 // Read the BootOrder, or DriverOrder variable.
1099 //
1100 GetEfiGlobalVariable2 (mBmLoadOptionOrderName[LoadOptionType], (VOID **)&OptionOrder, &OptionOrderSize);
1101 if (OptionOrder == NULL) {
1102 return NULL;
1103 }
1104
1105 *OptionCount = OptionOrderSize / sizeof (UINT16);
1106
1107 Options = AllocatePool (*OptionCount * sizeof (EFI_BOOT_MANAGER_LOAD_OPTION));
1108 ASSERT (Options != NULL);
1109
1110 OptionIndex = 0;
1111 for (Index = 0; Index < *OptionCount; Index++) {
1112 OptionNumber = OptionOrder[Index];
1113 UnicodeSPrint (OptionName, sizeof (OptionName), L"%s%04x", mBmLoadOptionName[LoadOptionType], OptionNumber);
1114
1115 Status = EfiBootManagerVariableToLoadOption (OptionName, &Options[OptionIndex]);
1116 if (EFI_ERROR (Status)) {
1117 DEBUG ((DEBUG_INFO, "[Bds] %s doesn't exist - Update ****Order variable to remove the reference!!", OptionName));
1118 EfiBootManagerDeleteLoadOptionVariable (OptionNumber, LoadOptionType);
1119 } else {
1120 ASSERT (Options[OptionIndex].OptionNumber == OptionNumber);
1121 OptionIndex++;
1122 }
1123 }
1124
1125 if (OptionOrder != NULL) {
1126 FreePool (OptionOrder);
1127 }
1128
1129 if (OptionIndex < *OptionCount) {
1130 Options = ReallocatePool (*OptionCount * sizeof (EFI_BOOT_MANAGER_LOAD_OPTION), OptionIndex * sizeof (EFI_BOOT_MANAGER_LOAD_OPTION), Options);
1131 ASSERT (Options != NULL);
1132 *OptionCount = OptionIndex;
1133 }
1134 } else if (LoadOptionType == LoadOptionTypePlatformRecovery) {
1135 Param.OptionType = LoadOptionTypePlatformRecovery;
1136 Param.Options = NULL;
1137 Param.OptionCount = 0;
1138 Param.Guid = &gEfiGlobalVariableGuid;
1139
1140 BmForEachVariable (BmCollectLoadOptions, (VOID *)&Param);
1141
1142 *OptionCount = Param.OptionCount;
1143 Options = Param.Options;
1144 }
1145
1146 return Options;
1147}
1148
1159EFIAPI
1162 )
1163{
1164 if (LoadOption == NULL) {
1165 return EFI_NOT_FOUND;
1166 }
1167
1168 if (LoadOption->Description != NULL) {
1169 FreePool (LoadOption->Description);
1170 }
1171
1172 if (LoadOption->FilePath != NULL) {
1173 FreePool (LoadOption->FilePath);
1174 }
1175
1176 if (LoadOption->OptionalData != NULL) {
1177 FreePool (LoadOption->OptionalData);
1178 }
1179
1180 return EFI_SUCCESS;
1181}
1182
1195EFIAPI
1198 IN UINTN OptionCount
1199 )
1200{
1201 UINTN Index;
1202
1203 if (Option == NULL) {
1204 return EFI_NOT_FOUND;
1205 }
1206
1207 for (Index = 0; Index < OptionCount; Index++) {
1208 EfiBootManagerFreeLoadOption (&Option[Index]);
1209 }
1210
1211 FreePool (Option);
1212
1213 return EFI_SUCCESS;
1214}
1215
1230BOOLEAN
1232 IN EFI_BOOT_MANAGER_LOAD_OPTION_TYPE Type,
1233 IN VOID *FileBuffer,
1234 IN UINTN FileSize
1235 )
1236{
1237 EFI_IMAGE_DOS_HEADER *DosHeader;
1239 EFI_IMAGE_OPTIONAL_HEADER32 *OptionalHeader;
1240 UINT16 Subsystem;
1241
1242 if ((FileBuffer == NULL) || (FileSize == 0)) {
1243 return FALSE;
1244 }
1245
1246 //
1247 // Read dos header
1248 //
1249 DosHeader = (EFI_IMAGE_DOS_HEADER *)FileBuffer;
1250 if ((FileSize >= sizeof (EFI_IMAGE_DOS_HEADER)) &&
1251 (FileSize > DosHeader->e_lfanew) && (DosHeader->e_magic == EFI_IMAGE_DOS_SIGNATURE)
1252 )
1253 {
1254 //
1255 // Read and check PE signature
1256 //
1257 PeHeader = (EFI_IMAGE_OPTIONAL_HEADER_UNION *)((UINT8 *)FileBuffer + DosHeader->e_lfanew);
1258 if ((FileSize >= DosHeader->e_lfanew + sizeof (EFI_IMAGE_OPTIONAL_HEADER_UNION)) &&
1259 (PeHeader->Pe32.Signature == EFI_IMAGE_NT_SIGNATURE)
1260 )
1261 {
1262 //
1263 // Check PE32 or PE32+ magic, and machine type
1264 //
1265 OptionalHeader = (EFI_IMAGE_OPTIONAL_HEADER32 *)&PeHeader->Pe32.OptionalHeader;
1266 if ((OptionalHeader->Magic == EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC) ||
1267 (OptionalHeader->Magic == EFI_IMAGE_NT_OPTIONAL_HDR64_MAGIC))
1268 {
1269 //
1270 // Check the Subsystem:
1271 // Driver#### must be of type BootServiceDriver or RuntimeDriver
1272 // SysPrep####, Boot####, OsRecovery####, PlatformRecovery#### must be of type Application
1273 //
1274 Subsystem = OptionalHeader->Subsystem;
1275 if ((Type == LoadOptionTypeMax) ||
1276 ((Type == LoadOptionTypeDriver) && (Subsystem == EFI_IMAGE_SUBSYSTEM_EFI_BOOT_SERVICE_DRIVER)) ||
1277 ((Type == LoadOptionTypeDriver) && (Subsystem == EFI_IMAGE_SUBSYSTEM_EFI_RUNTIME_DRIVER)) ||
1278 ((Type == LoadOptionTypeSysPrep) && (Subsystem == EFI_IMAGE_SUBSYSTEM_EFI_APPLICATION)) ||
1279 ((Type == LoadOptionTypeBoot) && (Subsystem == EFI_IMAGE_SUBSYSTEM_EFI_APPLICATION)) ||
1280 ((Type == LoadOptionTypePlatformRecovery) && (Subsystem == EFI_IMAGE_SUBSYSTEM_EFI_APPLICATION))
1281 )
1282 {
1283 return TRUE;
1284 }
1285 }
1286 }
1287 }
1288
1289 return FALSE;
1290}
1291
1312VOID *
1314 IN EFI_BOOT_MANAGER_LOAD_OPTION_TYPE Type,
1315 IN EFI_DEVICE_PATH_PROTOCOL *FilePath,
1316 OUT EFI_DEVICE_PATH_PROTOCOL **FullPath,
1317 OUT UINTN *FileSize
1318 )
1319{
1320 VOID *FileBuffer;
1321 EFI_DEVICE_PATH_PROTOCOL *PreFullPath;
1322 EFI_DEVICE_PATH_PROTOCOL *CurFullPath;
1323 UINTN LocalFileSize;
1324 UINT32 AuthenticationStatus;
1325 EFI_DEVICE_PATH_PROTOCOL *RamDiskDevicePath;
1326
1327 LocalFileSize = 0;
1328 FileBuffer = NULL;
1329 CurFullPath = *FullPath;
1330 do {
1331 PreFullPath = CurFullPath;
1332 CurFullPath = BmGetNextLoadOptionDevicePath (FilePath, CurFullPath);
1333 //
1334 // Only free the full path created *inside* this routine
1335 //
1336 if ((PreFullPath != NULL) && (PreFullPath != *FullPath)) {
1337 FreePool (PreFullPath);
1338 }
1339
1340 if (CurFullPath == NULL) {
1341 break;
1342 }
1343
1344 FileBuffer = GetFileBufferByFilePath (TRUE, CurFullPath, &LocalFileSize, &AuthenticationStatus);
1345 if ((FileBuffer != NULL) && !BmIsLoadOptionPeHeaderValid (Type, FileBuffer, LocalFileSize)) {
1346 //
1347 // Free the RAM disk file system if the load option is invalid.
1348 //
1349 RamDiskDevicePath = BmGetRamDiskDevicePath (FilePath);
1350 if (RamDiskDevicePath != NULL) {
1351 BmDestroyRamDisk (RamDiskDevicePath);
1352 FreePool (RamDiskDevicePath);
1353 }
1354
1355 //
1356 // Free the invalid load option buffer.
1357 //
1358 FreePool (FileBuffer);
1359 FileBuffer = NULL;
1360 }
1361 } while (FileBuffer == NULL);
1362
1363 if (FileBuffer == NULL) {
1364 CurFullPath = NULL;
1365 LocalFileSize = 0;
1366 }
1367
1368 DEBUG ((DEBUG_INFO, "[Bds] Expand "));
1369 BmPrintDp (FilePath);
1370 DEBUG ((DEBUG_INFO, " -> "));
1371 BmPrintDp (CurFullPath);
1372 DEBUG ((DEBUG_INFO, "\n"));
1373
1374 *FullPath = CurFullPath;
1375 *FileSize = LocalFileSize;
1376 return FileBuffer;
1377}
1378
1390EFIAPI
1393 )
1394{
1395 EFI_STATUS Status;
1396 EFI_DEVICE_PATH_PROTOCOL *PreFullPath;
1397 EFI_DEVICE_PATH_PROTOCOL *CurFullPath;
1398 EFI_HANDLE ImageHandle;
1399 EFI_LOADED_IMAGE_PROTOCOL *ImageInfo;
1400 VOID *FileBuffer;
1401 UINTN FileSize;
1402
1403 if ((UINT32)LoadOption->OptionType >= LoadOptionTypeMax) {
1404 return EFI_INVALID_PARAMETER;
1405 }
1406
1407 if (LoadOption->OptionType == LoadOptionTypeBoot) {
1408 return EFI_UNSUPPORTED;
1409 }
1410
1411 //
1412 // If a load option is not marked as LOAD_OPTION_ACTIVE,
1413 // the boot manager will not automatically load the option.
1414 //
1415 if ((LoadOption->Attributes & LOAD_OPTION_ACTIVE) == 0) {
1416 return EFI_SUCCESS;
1417 }
1418
1419 if (LoadOption->OptionType == LoadOptionTypePlatformRecovery) {
1420 //
1421 // Signal the EVT_SIGNAL_READY_TO_BOOT event when we are about to load and execute the boot option.
1422 //
1424 //
1425 // Report Status Code to indicate ReadyToBoot was signaled
1426 //
1427 REPORT_STATUS_CODE (EFI_PROGRESS_CODE, (EFI_SOFTWARE_DXE_BS_DRIVER | EFI_SW_DXE_BS_PC_READY_TO_BOOT_EVENT));
1428 }
1429
1430 //
1431 // Load and start the load option.
1432 //
1433 DEBUG ((
1434 DEBUG_INFO | DEBUG_LOAD,
1435 "Process %s%04x (%s) ...\n",
1436 mBmLoadOptionName[LoadOption->OptionType],
1437 LoadOption->OptionNumber,
1438 LoadOption->Description
1439 ));
1440 ImageHandle = NULL;
1441 CurFullPath = NULL;
1442 EfiBootManagerConnectDevicePath (LoadOption->FilePath, NULL);
1443
1444 //
1445 // while() loop is to keep starting next matched load option if the PlatformRecovery#### returns failure status.
1446 //
1447 while (TRUE) {
1448 Status = EFI_INVALID_PARAMETER;
1449 PreFullPath = CurFullPath;
1450 FileBuffer = BmGetNextLoadOptionBuffer (LoadOption->OptionType, LoadOption->FilePath, &CurFullPath, &FileSize);
1451 if (PreFullPath != NULL) {
1452 FreePool (PreFullPath);
1453 }
1454
1455 if (FileBuffer == NULL) {
1456 break;
1457 }
1458
1459 Status = gBS->LoadImage (
1460 FALSE,
1462 CurFullPath,
1463 FileBuffer,
1464 FileSize,
1465 &ImageHandle
1466 );
1467 FreePool (FileBuffer);
1468
1469 if (EFI_ERROR (Status)) {
1470 //
1471 // With EFI_SECURITY_VIOLATION retval, the Image was loaded and an ImageHandle was created
1472 // with a valid EFI_LOADED_IMAGE_PROTOCOL, but the image can not be started right now.
1473 // If the caller doesn't have the option to defer the execution of an image, we should
1474 // unload image for the EFI_SECURITY_VIOLATION to avoid resource leak.
1475 //
1476 if (Status == EFI_SECURITY_VIOLATION) {
1477 gBS->UnloadImage (ImageHandle);
1478 }
1479 } else {
1480 Status = gBS->HandleProtocol (ImageHandle, &gEfiLoadedImageProtocolGuid, (VOID **)&ImageInfo);
1481 ASSERT_EFI_ERROR (Status);
1482
1483 ImageInfo->LoadOptionsSize = LoadOption->OptionalDataSize;
1484 ImageInfo->LoadOptions = LoadOption->OptionalData;
1485 //
1486 // Before calling the image, enable the Watchdog Timer for the 5-minute period
1487 //
1488 gBS->SetWatchdogTimer (5 * 60, 0, 0, NULL);
1489
1490 LoadOption->Status = gBS->StartImage (ImageHandle, &LoadOption->ExitDataSize, &LoadOption->ExitData);
1491 DEBUG ((
1492 DEBUG_INFO | DEBUG_LOAD,
1493 "%s%04x Return Status = %r\n",
1494 mBmLoadOptionName[LoadOption->OptionType],
1495 LoadOption->OptionNumber,
1496 LoadOption->Status
1497 ));
1498
1499 //
1500 // Clear the Watchdog Timer after the image returns
1501 //
1502 gBS->SetWatchdogTimer (0, 0, 0, NULL);
1503
1504 if ((LoadOption->OptionType != LoadOptionTypePlatformRecovery) || (LoadOption->Status == EFI_SUCCESS)) {
1505 break;
1506 }
1507 }
1508 }
1509
1510 if (CurFullPath != NULL) {
1511 FreePool (CurFullPath);
1512 }
1513
1514 return Status;
1515}
UINT64 UINTN
INT64 INTN
UINTN EFIAPI StrSize(IN CONST CHAR16 *String)
Definition: String.c:72
INTN EFIAPI StrCmp(IN CONST CHAR16 *FirstString, IN CONST CHAR16 *SecondString)
Definition: String.c:109
UINT16 EFIAPI ReadUnaligned16(IN CONST UINT16 *Buffer)
Definition: Unaligned.c:29
INTN EFIAPI StrnCmp(IN CONST CHAR16 *FirstString, IN CONST CHAR16 *SecondString, IN UINTN Length)
Definition: String.c:162
UINT32 EFIAPI WriteUnaligned32(OUT UINT32 *Buffer, IN UINT32 Value)
Definition: Unaligned.c:177
UINT16 EFIAPI WriteUnaligned16(OUT UINT16 *Buffer, IN UINT16 Value)
Definition: Unaligned.c:61
UINTN EFIAPI StrLen(IN CONST CHAR16 *String)
Definition: String.c:30
UINT32 EFIAPI ReadUnaligned32(IN CONST UINT32 *Buffer)
Definition: Unaligned.c:145
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
GUID *EFIAPI CopyGuid(OUT GUID *DestinationGuid, IN CONST GUID *SourceGuid)
Definition: MemLibGuid.c:39
VOID *EFIAPI ZeroMem(OUT VOID *Buffer, IN UINTN Length)
EFI_DEVICE_PATH_PROTOCOL * BmGetNextLoadOptionDevicePath(IN EFI_DEVICE_PATH_PROTOCOL *FilePath, IN EFI_DEVICE_PATH_PROTOCOL *FullPath)
Definition: BmBoot.c:1634
EFI_DEVICE_PATH_PROTOCOL * BmGetRamDiskDevicePath(IN EFI_DEVICE_PATH_PROTOCOL *FilePath)
Definition: BmBoot.c:1308
VOID BmDestroyRamDisk(IN EFI_DEVICE_PATH_PROTOCOL *RamDiskDevicePath)
Definition: BmBoot.c:1385
VOID BmForEachVariable(BM_VARIABLE_VISITOR Visitor, VOID *Context)
Definition: BmLoadOption.c:37
EFI_STATUS EFIAPI EfiBootManagerFreeLoadOption(IN EFI_BOOT_MANAGER_LOAD_OPTION *LoadOption)
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)
BOOLEAN BmValidateOption(UINT8 *Variable, UINTN VariableSize)
Definition: BmLoadOption.c:745
UINTN BmGetDevicePathSizeEx(IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath, IN UINTN MaxSize)
Definition: BmLoadOption.c:656
EFI_STATUS EFIAPI EfiBootManagerAddLoadOptionVariable(IN OUT EFI_BOOT_MANAGER_LOAD_OPTION *Option, IN UINTN Position)
Definition: BmLoadOption.c:367
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:548
VOID EFIAPI EfiBootManagerSortLoadOptionVariable(EFI_BOOT_MANAGER_LOAD_OPTION_TYPE OptionType, SORT_COMPARE CompareFunction)
Definition: BmLoadOption.c:429
EFI_STATUS BmAddOptionNumberToOrderVariable(IN CHAR16 *OptionOrderName, IN UINT16 OptionNumber, IN UINTN Position)
Definition: BmLoadOption.c:290
EFI_BOOT_MANAGER_LOAD_OPTION *EFIAPI EfiBootManagerGetLoadOptions(OUT UINTN *OptionCount, IN EFI_BOOT_MANAGER_LOAD_OPTION_TYPE LoadOptionType)
EFI_STATUS EFIAPI EfiBootManagerDeleteLoadOptionVariable(IN UINTN OptionNumber, IN EFI_BOOT_MANAGER_LOAD_OPTION_TYPE OptionType)
Definition: BmLoadOption.c:584
EFI_STATUS EFIAPI EfiBootManagerVariableToLoadOptionEx(IN CHAR16 *VariableName, IN EFI_GUID *VendorGuid, IN OUT EFI_BOOT_MANAGER_LOAD_OPTION *Option)
Definition: BmLoadOption.c:890
BOOLEAN EFIAPI EfiBootManagerIsValidLoadOptionVariableName(IN CHAR16 *VariableName, OUT EFI_BOOT_MANAGER_LOAD_OPTION_TYPE *OptionType OPTIONAL, OUT UINT16 *OptionNumber OPTIONAL)
Definition: BmLoadOption.c:808
EFI_STATUS EFIAPI EfiBootManagerVariableToLoadOption(IN CHAR16 *VariableName, IN OUT EFI_BOOT_MANAGER_LOAD_OPTION *Option)
Definition: BmLoadOption.c:998
EFI_STATUS EFIAPI EfiBootManagerProcessLoadOption(IN EFI_BOOT_MANAGER_LOAD_OPTION *LoadOption)
UINTN BmStrSizeEx(IN CONST CHAR16 *String, IN UINTN MaxStringLen)
Definition: BmLoadOption.c:713
VOID BmCollectLoadOptions(IN CHAR16 *Name, IN EFI_GUID *Guid, IN VOID *Context)
EFI_STATUS EFIAPI EfiBootManagerLoadOptionToVariable(IN CONST EFI_BOOT_MANAGER_LOAD_OPTION *Option)
Definition: BmLoadOption.c:170
EFI_STATUS EFIAPI EfiBootManagerFreeLoadOptions(IN EFI_BOOT_MANAGER_LOAD_OPTION *Option, IN UINTN OptionCount)
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 OPTIONAL, IN UINT32 OptionalDataSize)
Definition: BmLoadOption.c:494
EFI_STATUS BmGetFreeOptionNumber(IN EFI_BOOT_MANAGER_LOAD_OPTION_TYPE LoadOptionType, OUT UINT16 *FreeOptionNumber)
Definition: BmLoadOption.c:85
BOOLEAN BmIsLoadOptionPeHeaderValid(IN EFI_BOOT_MANAGER_LOAD_OPTION_TYPE Type, IN VOID *FileBuffer, IN UINTN FileSize)
VOID BmPrintDp(EFI_DEVICE_PATH_PROTOCOL *DevicePath)
Definition: BmMisc.c:382
UINTN BmCharToUint(IN CHAR16 Char)
Definition: BmMisc.c:404
UINTN EFIAPI DevicePathNodeLength(IN CONST VOID *Node)
BOOLEAN EFIAPI IsDevicePathEnd(IN CONST VOID *Node)
EFI_DEVICE_PATH_PROTOCOL *EFIAPI NextDevicePathNode(IN CONST VOID *Node)
UINTN EFIAPI GetDevicePathSize(IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath)
EFI_DEVICE_PATH_PROTOCOL *EFIAPI DuplicateDevicePath(IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath)
VOID *EFIAPI GetFileBufferByFilePath(IN BOOLEAN BootPolicy, IN CONST EFI_DEVICE_PATH_PROTOCOL *FilePath, OUT UINTN *FileSize, OUT UINT32 *AuthenticationStatus)
VOID *EFIAPI ReallocatePool(IN UINTN OldSize, IN UINTN NewSize, IN VOID *OldBuffer OPTIONAL)
VOID *EFIAPI AllocateZeroPool(IN UINTN AllocationSize)
VOID EFIAPI FreePool(IN VOID *Buffer)
VOID *EFIAPI AllocateCopyPool(IN UINTN AllocationSize, IN CONST VOID *Buffer)
#define EFI_BOOT_ORDER_VARIABLE_NAME
#define EFI_SYS_PREP_ORDER_VARIABLE_NAME
#define EFI_DRIVER_ORDER_VARIABLE_NAME
VOID(* BM_VARIABLE_VISITOR)(CHAR16 *Name, EFI_GUID *Guid, VOID *Context)
Definition: InternalBm.h:125
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 MIN(a, b)
Definition: Base.h:1007
#define TRUE
Definition: Base.h:301
#define FALSE
Definition: Base.h:307
#define ARRAY_SIZE(Array)
Definition: Base.h:1393
#define IN
Definition: Base.h:279
#define OUT
Definition: Base.h:284
#define GLOBAL_REMOVE_IF_UNREFERENCED
Definition: Base.h:48
#define ASSERT_EFI_ERROR(StatusParameter)
Definition: DebugLib.h:462
#define DEBUG(Expression)
Definition: DebugLib.h:434
#define REPORT_STATUS_CODE(Type, Value)
#define EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC
Definition: PeImage.h:143
#define EFI_IMAGE_NT_OPTIONAL_HDR64_MAGIC
Definition: PeImage.h:194
#define EFI_PROGRESS_CODE
Definition: PiStatusCode.h:43
VOID *EFIAPI AllocatePool(IN UINTN AllocationSize)
VOID EFIAPI PerformQuickSort(IN OUT VOID *BufferToSort, IN CONST UINTN Count, IN CONST UINTN ElementSize, IN SORT_COMPARE CompareFunction)
Definition: BaseSortLib.c:36
RETURN_STATUS EFI_STATUS
Definition: UefiBaseType.h:29
VOID * EFI_HANDLE
Definition: UefiBaseType.h:33
#define EFI_SUCCESS
Definition: UefiBaseType.h:112
EFI_STATUS EFIAPI EfiBootManagerConnectDevicePath(IN EFI_DEVICE_PATH_PROTOCOL *DevicePathToConnect, OUT EFI_HANDLE *MatchingHandle OPTIONAL)
Definition: BmConnect.c:108
EFI_HANDLE gImageHandle
EFI_BOOT_SERVICES * gBS
EFI_STATUS EFIAPI GetEfiGlobalVariable2(IN CONST CHAR16 *Name, OUT VOID **Value, OUT UINTN *Size OPTIONAL)
Definition: UefiLib.c:1470
EFI_STATUS EFIAPI GetVariable2(IN CONST CHAR16 *Name, IN CONST EFI_GUID *Guid, OUT VOID **Value, OUT UINTN *Size OPTIONAL)
Definition: UefiLib.c:1317
VOID EFIAPI EfiSignalEventReadyToBoot(VOID)
Definition: UefiNotTiano.c:219
#define EFI_VARIABLE_NON_VOLATILE
UINT32 e_lfanew
File address of new exe header.
Definition: PeImage.h:76
UINT16 e_magic
Magic number.
Definition: PeImage.h:58
Definition: Base.h:213