2 Internal file explorer functions for SecureBoot configuration module.
4 Copyright (c) 2012 - 2014, Intel Corporation. All rights reserved.<BR>
5 This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
15 #include "SecureBootConfigImpl.h"
18 /// File system selection menu
20 SECUREBOOT_MENU_OPTION FsOptionMenu
= {
21 SECUREBOOT_MENU_OPTION_SIGNATURE
,
27 /// Files and sub-directories in current directory menu
29 SECUREBOOT_MENU_OPTION DirectoryMenu
= {
30 SECUREBOOT_MENU_OPTION_SIGNATURE
,
35 VOID
*mStartOpCodeHandle
= NULL
;
36 VOID
*mEndOpCodeHandle
= NULL
;
37 EFI_IFR_GUID_LABEL
*mStartLabel
= NULL
;
38 EFI_IFR_GUID_LABEL
*mEndLabel
= NULL
;
43 @param[in] Src The source string.
45 @return A new string which is duplicated copy of the source,
46 or NULL if there is not enough memory.
58 Dest
= AllocateZeroPool (Size
);
59 ASSERT (Dest
!= NULL
);
61 CopyMem (Dest
, Src
, Size
);
68 Helper function called as part of the code needed to allocate
69 the proper sized buffer for various EFI interfaces.
71 @param[in, out] Status Current status
72 @param[in, out] Buffer Current allocated buffer, or NULL
73 @param[in] BufferSize Current buffer size needed
75 @retval TRUE If the buffer was reallocated and the caller
76 should try the API again.
77 @retval FALSE The caller should not call this function again.
82 IN OUT EFI_STATUS
*Status
,
90 // If this is an initial request, buffer will be null with a new buffer size
92 if ((*Buffer
== NULL
) && (BufferSize
!= 0)) {
93 *Status
= EFI_BUFFER_TOO_SMALL
;
96 // If the status code is "buffer too small", resize the buffer
99 if (*Status
== EFI_BUFFER_TOO_SMALL
) {
101 if (*Buffer
!= NULL
) {
105 *Buffer
= AllocateZeroPool (BufferSize
);
107 if (*Buffer
!= NULL
) {
110 *Status
= EFI_OUT_OF_RESOURCES
;
114 // If there's an error, free the buffer
116 if (!TryAgain
&& EFI_ERROR (*Status
) && (*Buffer
!= NULL
)) {
125 Append file name to existing file name, and allocate a new buffer
126 to hold the appended result.
128 @param[in] Str1 The existing file name
129 @param[in] Str2 The file name to be appended
131 @return A new string with appended result.
147 Size1
= StrSize (Str1
);
148 Size2
= StrSize (Str2
);
149 Str
= AllocateZeroPool (Size1
+ Size2
+ sizeof (CHAR16
));
150 ASSERT (Str
!= NULL
);
152 TmpStr
= AllocateZeroPool (Size1
+ Size2
+ sizeof (CHAR16
));
153 ASSERT (TmpStr
!= NULL
);
156 if (!((*Str
== '\\') && (*(Str
+ 1) == 0))) {
165 if (*Ptr
== '\\' && *(Ptr
+ 1) == '.' && *(Ptr
+ 2) == '.' && *(Ptr
+ 3) == L
'\\') {
167 // Convert "\Name\..\" to "\"
168 // DO NOT convert the .. if it is at the end of the string. This will
169 // break the .. behavior in changing directories.
173 // Use TmpStr as a backup, as StrCpy in BaseLib does not handle copy of two strings
176 StrCpy (TmpStr
, Ptr
+ 3);
177 StrCpy (LastSlash
, TmpStr
);
179 } else if (*Ptr
== '\\' && *(Ptr
+ 1) == '.' && *(Ptr
+ 2) == '\\') {
181 // Convert a "\.\" to a "\"
185 // Use TmpStr as a backup, as StrCpy in BaseLib does not handle copy of two strings
188 StrCpy (TmpStr
, Ptr
+ 2);
189 StrCpy (Ptr
, TmpStr
);
191 } else if (*Ptr
== '\\') {
204 Create a SECUREBOOT_MENU_ENTRY, and stores it in a buffer allocated from the pool.
206 @return The new menu entry or NULL of error happens.
209 SECUREBOOT_MENU_ENTRY
*
214 SECUREBOOT_MENU_ENTRY
*MenuEntry
;
218 // Create new menu entry
220 MenuEntry
= AllocateZeroPool (sizeof (SECUREBOOT_MENU_ENTRY
));
221 if (MenuEntry
== NULL
) {
225 ContextSize
= sizeof (SECUREBOOT_FILE_CONTEXT
);
226 MenuEntry
->FileContext
= AllocateZeroPool (ContextSize
);
227 if (MenuEntry
->FileContext
== NULL
) {
228 FreePool (MenuEntry
);
232 MenuEntry
->Signature
= SECUREBOOT_MENU_ENTRY_SIGNATURE
;
238 Get Menu Entry from the Menu Entry List by MenuNumber.
240 If MenuNumber is great or equal to the number of Menu
241 Entry in the list, then ASSERT.
243 @param[in] MenuOption The Menu Entry List to read the menu entry.
244 @param[in] MenuNumber The index of Menu Entry.
246 @return The Menu Entry.
249 SECUREBOOT_MENU_ENTRY
*
251 IN SECUREBOOT_MENU_OPTION
*MenuOption
,
255 SECUREBOOT_MENU_ENTRY
*NewMenuEntry
;
259 ASSERT (MenuNumber
< MenuOption
->MenuNumber
);
261 List
= MenuOption
->Head
.ForwardLink
;
262 for (Index
= 0; Index
< MenuNumber
; Index
++) {
263 List
= List
->ForwardLink
;
266 NewMenuEntry
= CR (List
, SECUREBOOT_MENU_ENTRY
, Link
, SECUREBOOT_MENU_ENTRY_SIGNATURE
);
272 Create string tokens for a menu from its help strings and display strings.
274 @param[in] HiiHandle Hii Handle of the package to be updated.
275 @param[in] MenuOption The Menu whose string tokens need to be created.
279 CreateMenuStringToken (
280 IN EFI_HII_HANDLE HiiHandle
,
281 IN SECUREBOOT_MENU_OPTION
*MenuOption
284 SECUREBOOT_MENU_ENTRY
*NewMenuEntry
;
287 for (Index
= 0; Index
< MenuOption
->MenuNumber
; Index
++) {
288 NewMenuEntry
= GetMenuEntry (MenuOption
, Index
);
290 NewMenuEntry
->DisplayStringToken
= HiiSetString (
293 NewMenuEntry
->DisplayString
,
297 if (NewMenuEntry
->HelpString
== NULL
) {
298 NewMenuEntry
->HelpStringToken
= NewMenuEntry
->DisplayStringToken
;
300 NewMenuEntry
->HelpStringToken
= HiiSetString (
303 NewMenuEntry
->HelpString
,
311 Free up all resources allocated for a SECUREBOOT_MENU_ENTRY.
313 @param[in, out] MenuEntry A pointer to SECUREBOOT_MENU_ENTRY.
318 IN OUT SECUREBOOT_MENU_ENTRY
*MenuEntry
321 SECUREBOOT_FILE_CONTEXT
*FileContext
;
324 FileContext
= (SECUREBOOT_FILE_CONTEXT
*) MenuEntry
->FileContext
;
326 if (!FileContext
->IsRoot
&& FileContext
->DevicePath
!= NULL
) {
327 FreePool (FileContext
->DevicePath
);
329 if (FileContext
->FHandle
!= NULL
) {
330 FileContext
->FHandle
->Close (FileContext
->FHandle
);
334 if (FileContext
->FileName
!= NULL
) {
335 FreePool (FileContext
->FileName
);
337 if (FileContext
->Info
!= NULL
) {
338 FreePool (FileContext
->Info
);
341 FreePool (FileContext
);
343 if (MenuEntry
->DisplayString
!= NULL
) {
344 FreePool (MenuEntry
->DisplayString
);
346 if (MenuEntry
->HelpString
!= NULL
) {
347 FreePool (MenuEntry
->HelpString
);
350 FreePool (MenuEntry
);
354 Free resources allocated in Allocate Rountine.
356 @param[in, out] MenuOption Menu to be freed
361 IN OUT SECUREBOOT_MENU_OPTION
*MenuOption
364 SECUREBOOT_MENU_ENTRY
*MenuEntry
;
365 while (!IsListEmpty (&MenuOption
->Head
)) {
367 MenuOption
->Head
.ForwardLink
,
368 SECUREBOOT_MENU_ENTRY
,
370 SECUREBOOT_MENU_ENTRY_SIGNATURE
372 RemoveEntryList (&MenuEntry
->Link
);
373 DestroyMenuEntry (MenuEntry
);
375 MenuOption
->MenuNumber
= 0;
379 This function gets the file information from an open file descriptor, and stores it
380 in a buffer allocated from pool.
382 @param[in] FHand File Handle.
384 @return A pointer to a buffer with file information or NULL is returned
389 IN EFI_FILE_HANDLE FHand
393 EFI_FILE_INFO
*Buffer
;
397 // Initialize for GrowBuffer loop
400 BufferSize
= SIZE_OF_EFI_FILE_INFO
+ 200;
403 // Call the real function
405 while (GrowBuffer (&Status
, (VOID
**) &Buffer
, BufferSize
)) {
406 Status
= FHand
->GetInfo (
418 This function gets the file system information from an open file descriptor,
419 and stores it in a buffer allocated from pool.
421 @param[in] FHand The file handle.
423 @return A pointer to a buffer with file information.
424 @retval NULL is returned if failed to get Vaolume Label Info.
427 EFI_FILE_SYSTEM_VOLUME_LABEL
*
428 FileSystemVolumeLabelInfo (
429 IN EFI_FILE_HANDLE FHand
433 EFI_FILE_SYSTEM_VOLUME_LABEL
*Buffer
;
436 // Initialize for GrowBuffer loop
439 BufferSize
= SIZE_OF_EFI_FILE_SYSTEM_VOLUME_LABEL
+ 200;
442 // Call the real function
444 while (GrowBuffer (&Status
, (VOID
**) &Buffer
, BufferSize
)) {
445 Status
= FHand
->GetInfo (
447 &gEfiFileSystemVolumeLabelInfoIdGuid
,
457 This function will open a file or directory referenced by DevicePath.
459 This function opens a file with the open mode according to the file path. The
460 Attributes is valid only for EFI_FILE_MODE_CREATE.
462 @param[in, out] FilePath On input, the device path to the file.
463 On output, the remaining device path.
464 @param[out] FileHandle Pointer to the file handle.
465 @param[in] OpenMode The mode to open the file with.
466 @param[in] Attributes The file's file attributes.
468 @retval EFI_SUCCESS The information was set.
469 @retval EFI_INVALID_PARAMETER One of the parameters has an invalid value.
470 @retval EFI_UNSUPPORTED Could not open the file path.
471 @retval EFI_NOT_FOUND The specified file could not be found on the
472 device or the file system could not be found on
474 @retval EFI_NO_MEDIA The device has no medium.
475 @retval EFI_MEDIA_CHANGED The device has a different medium in it or the
476 medium is no longer supported.
477 @retval EFI_DEVICE_ERROR The device reported an error.
478 @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted.
479 @retval EFI_WRITE_PROTECTED The file or medium is write protected.
480 @retval EFI_ACCESS_DENIED The file was opened read only.
481 @retval EFI_OUT_OF_RESOURCES Not enough resources were available to open the
483 @retval EFI_VOLUME_FULL The volume is full.
487 OpenFileByDevicePath(
488 IN OUT EFI_DEVICE_PATH_PROTOCOL
**FilePath
,
489 OUT EFI_FILE_HANDLE
*FileHandle
,
495 EFI_SIMPLE_FILE_SYSTEM_PROTOCOL
*EfiSimpleFileSystemProtocol
;
496 EFI_FILE_PROTOCOL
*Handle1
;
497 EFI_FILE_PROTOCOL
*Handle2
;
498 EFI_HANDLE DeviceHandle
;
500 if ((FilePath
== NULL
|| FileHandle
== NULL
)) {
501 return EFI_INVALID_PARAMETER
;
504 Status
= gBS
->LocateDevicePath (
505 &gEfiSimpleFileSystemProtocolGuid
,
509 if (EFI_ERROR (Status
)) {
513 Status
= gBS
->OpenProtocol(
515 &gEfiSimpleFileSystemProtocolGuid
,
516 (VOID
**)&EfiSimpleFileSystemProtocol
,
519 EFI_OPEN_PROTOCOL_GET_PROTOCOL
521 if (EFI_ERROR (Status
)) {
525 Status
= EfiSimpleFileSystemProtocol
->OpenVolume(EfiSimpleFileSystemProtocol
, &Handle1
);
526 if (EFI_ERROR (Status
)) {
532 // go down directories one node at a time.
534 while (!IsDevicePathEnd (*FilePath
)) {
536 // For file system access each node should be a file path component
538 if (DevicePathType (*FilePath
) != MEDIA_DEVICE_PATH
||
539 DevicePathSubType (*FilePath
) != MEDIA_FILEPATH_DP
542 return (EFI_INVALID_PARAMETER
);
545 // Open this file path node
551 // Try to test opening an existing file
553 Status
= Handle2
->Open (
556 ((FILEPATH_DEVICE_PATH
*)*FilePath
)->PathName
,
557 OpenMode
&~EFI_FILE_MODE_CREATE
,
562 // see if the error was that it needs to be created
564 if ((EFI_ERROR (Status
)) && (OpenMode
!= (OpenMode
&~EFI_FILE_MODE_CREATE
))) {
565 Status
= Handle2
->Open (
568 ((FILEPATH_DEVICE_PATH
*)*FilePath
)->PathName
,
574 // Close the last node
576 Handle2
->Close (Handle2
);
578 if (EFI_ERROR(Status
)) {
585 *FilePath
= NextDevicePathNode (*FilePath
);
589 // This is a weak spot since if the undefined SHELL_FILE_HANDLE format changes this must change also!
591 *FileHandle
= (VOID
*)Handle1
;
596 Function opens and returns a file handle to the root directory of a volume.
598 @param[in] DeviceHandle A handle for a device
600 @return A valid file handle or NULL if error happens.
605 IN EFI_HANDLE DeviceHandle
609 EFI_SIMPLE_FILE_SYSTEM_PROTOCOL
*Volume
;
610 EFI_FILE_HANDLE File
;
615 // File the file system interface to the device
617 Status
= gBS
->HandleProtocol (
619 &gEfiSimpleFileSystemProtocolGuid
,
624 // Open the root directory of the volume
626 if (!EFI_ERROR (Status
)) {
627 Status
= Volume
->OpenVolume (
635 return EFI_ERROR (Status
) ? NULL
: File
;
639 This function builds the FsOptionMenu list which records all
640 available file system in the system. They include all instances
641 of EFI_SIMPLE_FILE_SYSTEM_PROTOCOL, all instances of EFI_LOAD_FILE_SYSTEM
642 and all type of legacy boot device.
644 @retval EFI_SUCCESS Success find the file system
645 @retval EFI_OUT_OF_RESOURCES Can not create menu entry
653 UINTN NoBlkIoHandles
;
654 UINTN NoSimpleFsHandles
;
655 EFI_HANDLE
*BlkIoHandle
;
656 EFI_HANDLE
*SimpleFsHandle
;
658 EFI_BLOCK_IO_PROTOCOL
*BlkIo
;
661 SECUREBOOT_MENU_ENTRY
*MenuEntry
;
662 SECUREBOOT_FILE_CONTEXT
*FileContext
;
667 BOOLEAN RemovableMedia
;
670 NoSimpleFsHandles
= 0;
672 InitializeListHead (&FsOptionMenu
.Head
);
675 // Locate Handles that support BlockIo protocol
677 Status
= gBS
->LocateHandleBuffer (
679 &gEfiBlockIoProtocolGuid
,
684 if (!EFI_ERROR (Status
)) {
686 for (Index
= 0; Index
< NoBlkIoHandles
; Index
++) {
687 Status
= gBS
->HandleProtocol (
689 &gEfiBlockIoProtocolGuid
,
693 if (EFI_ERROR (Status
)) {
698 // Issue a dummy read to trigger reinstall of BlockIo protocol for removable media
700 if (BlkIo
->Media
->RemovableMedia
) {
701 Buffer
= AllocateZeroPool (BlkIo
->Media
->BlockSize
);
702 if (NULL
== Buffer
) {
703 FreePool (BlkIoHandle
);
704 return EFI_OUT_OF_RESOURCES
;
709 BlkIo
->Media
->MediaId
,
711 BlkIo
->Media
->BlockSize
,
717 FreePool (BlkIoHandle
);
721 // Locate Handles that support Simple File System protocol
723 Status
= gBS
->LocateHandleBuffer (
725 &gEfiSimpleFileSystemProtocolGuid
,
730 if (!EFI_ERROR (Status
)) {
732 // Find all the instances of the File System prototocol
734 for (Index
= 0; Index
< NoSimpleFsHandles
; Index
++) {
735 Status
= gBS
->HandleProtocol (
736 SimpleFsHandle
[Index
],
737 &gEfiBlockIoProtocolGuid
,
740 if (EFI_ERROR (Status
)) {
742 // If no block IO exists assume it's NOT a removable media
744 RemovableMedia
= FALSE
;
747 // If block IO exists check to see if it's remobable media
749 RemovableMedia
= BlkIo
->Media
->RemovableMedia
;
753 // Allocate pool for this instance.
755 MenuEntry
= CreateMenuEntry ();
756 if (NULL
== MenuEntry
) {
757 FreePool (SimpleFsHandle
);
758 return EFI_OUT_OF_RESOURCES
;
761 FileContext
= (SECUREBOOT_FILE_CONTEXT
*) MenuEntry
->FileContext
;
763 FileContext
->Handle
= SimpleFsHandle
[Index
];
764 MenuEntry
->OptionNumber
= Index
;
765 FileContext
->FHandle
= OpenRoot (FileContext
->Handle
);
766 if (FileContext
->FHandle
== NULL
) {
767 DestroyMenuEntry (MenuEntry
);
771 MenuEntry
->HelpString
= DevicePathToStr (DevicePathFromHandle (FileContext
->Handle
));
772 FileContext
->Info
= FileSystemVolumeLabelInfo (FileContext
->FHandle
);
773 FileContext
->FileName
= StrDuplicate (L
"\\");
774 FileContext
->DevicePath
= FileDevicePath (
776 FileContext
->FileName
778 FileContext
->IsDir
= TRUE
;
779 FileContext
->IsRoot
= TRUE
;
780 FileContext
->IsRemovableMedia
= RemovableMedia
;
781 FileContext
->IsLoadFile
= FALSE
;
784 // Get current file system's Volume Label
786 if (FileContext
->Info
== NULL
) {
787 VolumeLabel
= L
"NO FILE SYSTEM INFO";
789 if (FileContext
->Info
->VolumeLabel
== NULL
) {
790 VolumeLabel
= L
"NULL VOLUME LABEL";
792 VolumeLabel
= FileContext
->Info
->VolumeLabel
;
793 if (*VolumeLabel
== 0x0000) {
794 VolumeLabel
= L
"NO VOLUME LABEL";
799 TempStr
= MenuEntry
->HelpString
;
800 MenuEntry
->DisplayString
= AllocateZeroPool (MAX_CHAR
);
801 ASSERT (MenuEntry
->DisplayString
!= NULL
);
803 MenuEntry
->DisplayString
,
810 InsertTailList (&FsOptionMenu
.Head
, &MenuEntry
->Link
);
814 if (NoSimpleFsHandles
!= 0) {
815 FreePool (SimpleFsHandle
);
819 // Remember how many file system options are here
821 FsOptionMenu
.MenuNumber
= OptionNumber
;
827 Find files under the current directory. All files and sub-directories
828 in current directory will be stored in DirectoryMenu for future use.
830 @param[in] MenuEntry The Menu Entry.
832 @retval EFI_SUCCESS Get files from current dir successfully.
833 @return Other Can't get files from current dir.
838 IN SECUREBOOT_MENU_ENTRY
*MenuEntry
841 EFI_FILE_HANDLE NewDir
;
843 EFI_FILE_INFO
*DirInfo
;
846 SECUREBOOT_MENU_ENTRY
*NewMenuEntry
;
847 SECUREBOOT_FILE_CONTEXT
*FileContext
;
848 SECUREBOOT_FILE_CONTEXT
*NewFileContext
;
853 FileContext
= (SECUREBOOT_FILE_CONTEXT
*) MenuEntry
->FileContext
;
854 Dir
= FileContext
->FHandle
;
857 // Open current directory to get files from it
862 FileContext
->FileName
,
866 if (!FileContext
->IsRoot
) {
870 if (EFI_ERROR (Status
)) {
874 DirInfo
= FileInfo (NewDir
);
875 if (DirInfo
== NULL
) {
876 return EFI_NOT_FOUND
;
879 if ((DirInfo
->Attribute
& EFI_FILE_DIRECTORY
) == 0) {
880 return EFI_INVALID_PARAMETER
;
883 FileContext
->DevicePath
= FileDevicePath (
885 FileContext
->FileName
888 DirBufferSize
= sizeof (EFI_FILE_INFO
) + 1024;
889 DirInfo
= AllocateZeroPool (DirBufferSize
);
890 if (DirInfo
== NULL
) {
891 return EFI_OUT_OF_RESOURCES
;
895 // Get all files in current directory
896 // Pass 1 to get Directories
897 // Pass 2 to get files that are EFI images
899 for (Pass
= 1; Pass
<= 2; Pass
++) {
900 NewDir
->SetPosition (NewDir
, 0);
902 BufferSize
= DirBufferSize
;
903 Status
= NewDir
->Read (NewDir
, &BufferSize
, DirInfo
);
904 if (EFI_ERROR (Status
) || BufferSize
== 0) {
908 if (((DirInfo
->Attribute
& EFI_FILE_DIRECTORY
) != 0 && Pass
== 2) ||
909 ((DirInfo
->Attribute
& EFI_FILE_DIRECTORY
) == 0 && Pass
== 1)
912 // Pass 1 is for Directories
913 // Pass 2 is for file names
918 NewMenuEntry
= CreateMenuEntry ();
919 if (NULL
== NewMenuEntry
) {
920 return EFI_OUT_OF_RESOURCES
;
923 NewFileContext
= (SECUREBOOT_FILE_CONTEXT
*) NewMenuEntry
->FileContext
;
924 NewFileContext
->Handle
= FileContext
->Handle
;
925 NewFileContext
->FileName
= AppendFileName (
926 FileContext
->FileName
,
929 NewFileContext
->FHandle
= NewDir
;
930 NewFileContext
->DevicePath
= FileDevicePath (
931 NewFileContext
->Handle
,
932 NewFileContext
->FileName
934 NewMenuEntry
->HelpString
= NULL
;
936 NewFileContext
->IsDir
= (BOOLEAN
) ((DirInfo
->Attribute
& EFI_FILE_DIRECTORY
) == EFI_FILE_DIRECTORY
);
937 if (NewFileContext
->IsDir
) {
938 BufferSize
= StrLen (DirInfo
->FileName
) * 2 + 6;
939 NewMenuEntry
->DisplayString
= AllocateZeroPool (BufferSize
);
942 NewMenuEntry
->DisplayString
,
949 NewMenuEntry
->DisplayString
= StrDuplicate (DirInfo
->FileName
);
952 NewFileContext
->IsRoot
= FALSE
;
953 NewFileContext
->IsLoadFile
= FALSE
;
954 NewFileContext
->IsRemovableMedia
= FALSE
;
956 NewMenuEntry
->OptionNumber
= OptionNumber
;
958 InsertTailList (&DirectoryMenu
.Head
, &NewMenuEntry
->Link
);
962 DirectoryMenu
.MenuNumber
= OptionNumber
;
968 Refresh the global UpdateData structure.
977 // Free current updated date
979 if (mStartOpCodeHandle
!= NULL
) {
980 HiiFreeOpCodeHandle (mStartOpCodeHandle
);
984 // Create new OpCode Handle
986 mStartOpCodeHandle
= HiiAllocateOpCodeHandle ();
989 // Create Hii Extend Label OpCode as the start opcode
991 mStartLabel
= (EFI_IFR_GUID_LABEL
*) HiiCreateGuidOpCode (
995 sizeof (EFI_IFR_GUID_LABEL
)
997 mStartLabel
->ExtendOpCode
= EFI_IFR_EXTEND_OP_LABEL
;
1001 Update the File Explore page.
1003 @param[in] HiiHandle Hii Handle of the package to be updated.
1004 @param[in] MenuOption The Menu whose string tokens need to be updated.
1005 @param[in] FeCurrentState Current file explorer state.
1009 UpdateFileExplorePage (
1010 IN EFI_HII_HANDLE HiiHandle
,
1011 IN SECUREBOOT_MENU_OPTION
*MenuOption
,
1012 IN FILE_EXPLORER_STATE FeCurrentState
1016 SECUREBOOT_MENU_ENTRY
*NewMenuEntry
;
1017 SECUREBOOT_FILE_CONTEXT
*NewFileContext
;
1019 EFI_FORM_ID FileFormId
;
1021 if (FeCurrentState
== FileExplorerStateEnrollPkFile
) {
1022 FormId
= SECUREBOOT_ADD_PK_FILE_FORM_ID
;
1023 FileFormId
= FORM_FILE_EXPLORER_ID_PK
;
1024 } else if (FeCurrentState
== FileExplorerStateEnrollKekFile
) {
1025 FormId
= FORMID_ENROLL_KEK_FORM
;
1026 FileFormId
= FORM_FILE_EXPLORER_ID_KEK
;
1027 } else if (FeCurrentState
== FileExplorerStateEnrollSignatureFileToDb
) {
1028 FormId
= SECUREBOOT_ENROLL_SIGNATURE_TO_DB
;
1029 FileFormId
= FORM_FILE_EXPLORER_ID_DB
;
1030 } else if (FeCurrentState
== FileExplorerStateEnrollSignatureFileToDbx
) {
1031 FormId
= SECUREBOOT_ENROLL_SIGNATURE_TO_DBX
;
1032 FileFormId
= FORM_FILE_EXPLORER_ID_DBX
;
1033 } else if (FeCurrentState
== FileExplorerStateEnrollSignatureFileToDbt
) {
1034 FormId
= SECUREBOOT_ENROLL_SIGNATURE_TO_DBT
;
1035 FileFormId
= FORM_FILE_EXPLORER_ID_DBT
;
1040 NewMenuEntry
= NULL
;
1041 NewFileContext
= NULL
;
1043 RefreshUpdateData ();
1044 mStartLabel
->Number
= FORM_FILE_EXPLORER_ID
;
1046 for (Index
= 0; Index
< MenuOption
->MenuNumber
; Index
++) {
1047 NewMenuEntry
= GetMenuEntry (MenuOption
, Index
);
1048 NewFileContext
= (SECUREBOOT_FILE_CONTEXT
*) NewMenuEntry
->FileContext
;
1050 if (NewFileContext
->IsDir
) {
1052 // Create Text opcode for directory.
1054 HiiCreateActionOpCode (
1056 (UINT16
) (FILE_OPTION_OFFSET
+ Index
),
1057 NewMenuEntry
->DisplayStringToken
,
1058 STRING_TOKEN (STR_NULL
),
1059 EFI_IFR_FLAG_CALLBACK
,
1065 // Create Goto opcode for file.
1067 HiiCreateGotoOpCode (
1070 NewMenuEntry
->DisplayStringToken
,
1071 STRING_TOKEN (STR_NULL
),
1072 EFI_IFR_FLAG_CALLBACK
,
1073 (UINT16
) (FILE_OPTION_GOTO_OFFSET
+ Index
)
1080 &gSecureBootConfigFormSetGuid
,
1082 mStartOpCodeHandle
, // Label FORM_FILE_EXPLORER_ID
1083 mEndOpCodeHandle
// LABEL_END
1088 Update the file explorer page with the refreshed file system.
1090 @param[in] PrivateData Module private data.
1091 @param[in] KeyValue Key value to identify the type of data to expect.
1093 @retval TRUE Inform the caller to create a callback packet to exit file explorer.
1094 @retval FALSE Indicate that there is no need to exit file explorer.
1098 UpdateFileExplorer (
1099 IN SECUREBOOT_CONFIG_PRIVATE_DATA
*PrivateData
,
1103 UINT16 FileOptionMask
;
1104 SECUREBOOT_MENU_ENTRY
*NewMenuEntry
;
1105 SECUREBOOT_FILE_CONTEXT
*NewFileContext
;
1107 BOOLEAN ExitFileExplorer
;
1109 EFI_DEVICE_PATH_PROTOCOL
*TmpDevicePath
;
1111 NewMenuEntry
= NULL
;
1112 NewFileContext
= NULL
;
1113 ExitFileExplorer
= FALSE
;
1114 FileOptionMask
= (UINT16
) (FILE_OPTION_MASK
& KeyValue
);
1116 if (PrivateData
->FeDisplayContext
== FileExplorerDisplayUnknown
) {
1118 // First in, display file system.
1120 FreeMenu (&FsOptionMenu
);
1123 CreateMenuStringToken (PrivateData
->HiiHandle
, &FsOptionMenu
);
1124 UpdateFileExplorePage (PrivateData
->HiiHandle
, &FsOptionMenu
, PrivateData
->FeCurrentState
);
1126 PrivateData
->FeDisplayContext
= FileExplorerDisplayFileSystem
;
1128 if (PrivateData
->FeDisplayContext
== FileExplorerDisplayFileSystem
) {
1129 NewMenuEntry
= GetMenuEntry (&FsOptionMenu
, FileOptionMask
);
1130 } else if (PrivateData
->FeDisplayContext
== FileExplorerDisplayDirectory
) {
1131 NewMenuEntry
= GetMenuEntry (&DirectoryMenu
, FileOptionMask
);
1134 NewFileContext
= (SECUREBOOT_FILE_CONTEXT
*) NewMenuEntry
->FileContext
;
1136 if (NewFileContext
->IsDir
) {
1137 PrivateData
->FeDisplayContext
= FileExplorerDisplayDirectory
;
1139 RemoveEntryList (&NewMenuEntry
->Link
);
1140 FreeMenu (&DirectoryMenu
);
1141 Status
= FindFiles (NewMenuEntry
);
1142 if (EFI_ERROR (Status
)) {
1143 ExitFileExplorer
= TRUE
;
1146 CreateMenuStringToken (PrivateData
->HiiHandle
, &DirectoryMenu
);
1147 DestroyMenuEntry (NewMenuEntry
);
1149 UpdateFileExplorePage (PrivateData
->HiiHandle
, &DirectoryMenu
, PrivateData
->FeCurrentState
);
1152 if (PrivateData
->FeCurrentState
== FileExplorerStateEnrollPkFile
) {
1153 FormId
= SECUREBOOT_ADD_PK_FILE_FORM_ID
;
1154 } else if (PrivateData
->FeCurrentState
== FileExplorerStateEnrollKekFile
) {
1155 FormId
= FORMID_ENROLL_KEK_FORM
;
1156 } else if (PrivateData
->FeCurrentState
== FileExplorerStateEnrollSignatureFileToDb
) {
1157 FormId
= SECUREBOOT_ENROLL_SIGNATURE_TO_DB
;
1158 } else if (PrivateData
->FeCurrentState
== FileExplorerStateEnrollSignatureFileToDbx
) {
1159 FormId
= SECUREBOOT_ENROLL_SIGNATURE_TO_DBX
;
1160 } else if (PrivateData
->FeCurrentState
== FileExplorerStateEnrollSignatureFileToDbt
) {
1161 FormId
= SECUREBOOT_ENROLL_SIGNATURE_TO_DBT
;
1166 PrivateData
->MenuEntry
= NewMenuEntry
;
1167 PrivateData
->FileContext
->FileName
= NewFileContext
->FileName
;
1169 TmpDevicePath
= NewFileContext
->DevicePath
;
1170 OpenFileByDevicePath (
1172 &PrivateData
->FileContext
->FHandle
,
1178 // Create Subtitle op-code for the display string of the option.
1180 RefreshUpdateData ();
1181 mStartLabel
->Number
= FormId
;
1183 HiiCreateSubTitleOpCode (
1185 NewMenuEntry
->DisplayStringToken
,
1192 PrivateData
->HiiHandle
,
1193 &gSecureBootConfigFormSetGuid
,
1195 mStartOpCodeHandle
, // Label FormId
1196 mEndOpCodeHandle
// LABEL_END
1202 return ExitFileExplorer
;
1206 Clean up the dynamic opcode at label and form specified by both LabelId.
1208 @param[in] LabelId It is both the Form ID and Label ID for opcode deletion.
1209 @param[in] PrivateData Module private data.
1215 IN SECUREBOOT_CONFIG_PRIVATE_DATA
*PrivateData
1218 RefreshUpdateData ();
1221 // Remove all op-codes from dynamic page
1223 mStartLabel
->Number
= LabelId
;
1225 PrivateData
->HiiHandle
,
1226 &gSecureBootConfigFormSetGuid
,
1228 mStartOpCodeHandle
, // Label LabelId
1229 mEndOpCodeHandle
// LABEL_END