]> git.proxmox.com Git - mirror_edk2.git/blobdiff - ShellPkg/Library/UefiHandleParsingLib/UefiHandleParsingLib.c
ShellPkg/HandleParsingLib: Show LoadedImageProtocol file name
[mirror_edk2.git] / ShellPkg / Library / UefiHandleParsingLib / UefiHandleParsingLib.c
index c96f6dd157684c91e4db5ea4e505d139bb221627..d3ee068ebaf62711ad22455c7b3fb4b4ac001d6f 100644 (file)
 \r
 #include "UefiHandleParsingLib.h"\r
 #include "IndustryStandard/Acpi10.h"\r
+#include <PiDxe.h>\r
+#include <Protocol/FirmwareVolume2.h>\r
 \r
 EFI_HANDLE        mHandleParsingHiiHandle = NULL;\r
 HANDLE_INDEX_LIST mHandleList = {{{NULL,NULL},0,0},0};\r
 GUID_INFO_BLOCK   *mGuidList;\r
 UINTN             mGuidListCount;\r
+\r
+/**\r
+  Function to find the file name associated with a LoadedImageProtocol.\r
+\r
+  @param[in] LoadedImage     An instance of LoadedImageProtocol.\r
+\r
+  @retval                    A string representation of the file name associated\r
+                             with LoadedImage, or NULL if no name can be found.\r
+**/\r
+CHAR16*\r
+FindLoadedImageFileName (\r
+  IN EFI_LOADED_IMAGE_PROTOCOL *LoadedImage\r
+  )\r
+{\r
+  EFI_GUID                       *NameGuid;\r
+  EFI_STATUS                     Status;\r
+  EFI_FIRMWARE_VOLUME2_PROTOCOL  *Fv;\r
+  VOID                           *Buffer;\r
+  UINTN                          BufferSize;\r
+  UINT32                         AuthenticationStatus;\r
+\r
+  if ((LoadedImage == NULL) || (LoadedImage->FilePath == NULL)) {\r
+    return NULL;\r
+  }\r
+\r
+  NameGuid = EfiGetNameGuidFromFwVolDevicePathNode((MEDIA_FW_VOL_FILEPATH_DEVICE_PATH *)LoadedImage->FilePath);\r
+\r
+  if (NameGuid == NULL) {\r
+    return NULL;\r
+  }\r
+\r
+  //\r
+  // Get the FirmwareVolume2Protocol of the device handle that this image was loaded from.\r
+  //\r
+  Status = gBS->HandleProtocol (LoadedImage->DeviceHandle, &gEfiFirmwareVolume2ProtocolGuid, (VOID**) &Fv);\r
+\r
+  //\r
+  // FirmwareVolume2Protocol is PI, and is not required to be available.\r
+  //\r
+  if (EFI_ERROR (Status)) {\r
+    return NULL;\r
+  }\r
+\r
+  //\r
+  // Read the user interface section of the image.\r
+  //\r
+  Buffer = NULL;\r
+  Status = Fv->ReadSection(Fv, NameGuid, EFI_SECTION_USER_INTERFACE, 0, &Buffer, &BufferSize, &AuthenticationStatus);\r
+\r
+  if (EFI_ERROR (Status)) {\r
+    return NULL;\r
+  }\r
+\r
+  //\r
+  // ReadSection returns just the section data, without any section header. For\r
+  // a user interface section, the only data is the file name.\r
+  //\r
+  return Buffer;\r
+}\r
+\r
 /**\r
   Function to translate the EFI_MEMORY_TYPE into a string.\r
 \r
@@ -169,6 +231,7 @@ LoadedImageProtocolDumpInformation(
   EFI_STATUS                        Status;\r
   CHAR16                            *RetVal;\r
   CHAR16                            *Temp;\r
+  CHAR16                            *FileName;\r
   CHAR16                            *FilePath;\r
   CHAR16                            *CodeType;\r
   CHAR16                            *DataType;\r
@@ -192,6 +255,20 @@ LoadedImageProtocolDumpInformation(
 \r
   HandleParsingHiiInit();\r
 \r
+  FileName = FindLoadedImageFileName(LoadedImage);\r
+\r
+  RetVal = NULL;\r
+  if (FileName != NULL) {\r
+    Temp = HiiGetString(mHandleParsingHiiHandle, STRING_TOKEN(STR_LI_DUMP_NAME), NULL);\r
+\r
+    if (Temp != NULL) {\r
+      RetVal = CatSPrint(NULL, Temp, FileName);\r
+    }\r
+\r
+    SHELL_FREE_NON_NULL(Temp);\r
+    SHELL_FREE_NON_NULL(FileName);\r
+  }\r
+\r
   Temp = HiiGetString(mHandleParsingHiiHandle, STRING_TOKEN(STR_LI_DUMP_MAIN), NULL);\r
   if (Temp == NULL) {\r
     return NULL;\r
@@ -203,7 +280,7 @@ LoadedImageProtocolDumpInformation(
   CodeType = ConvertMemoryType(LoadedImage->ImageCodeType);\r
 \r
   RetVal = CatSPrint(\r
-             NULL,\r
+             RetVal,\r
              Temp,\r
              LoadedImage->Revision,\r
              LoadedImage->ParentHandle,\r