ShellPkg/HandleParsingLib: Show LoadedImageProtocol file name
authorJeff Westfahl <jeff.westfahl@ni.com>
Thu, 4 May 2017 21:53:04 +0000 (05:53 +0800)
committerRuiyu Ni <ruiyu.ni@intel.com>
Thu, 11 May 2017 11:14:44 +0000 (19:14 +0800)
This patch adds support for showing the file name associated with a
LoadedImageProtocol file path. This is a behavior that was present in
the old shell but has been lost in the new shell.

For example, using 'dh -v' in the old shell:

    Handle D3 (3A552218)
    Image (3A54C918)   File:MicrocodeUpdate
        ParentHandle..: 3A666398

vs. the new shell:

    D3: 3A552218
    LoadedImage
        Revision......: 0x00001000
        ParentHandle..: 3A666398

Here's what the output of 'dh -v' looks like after this patch:

    D3: 3A552218
    LoadedImage
        Name..........: MicrocodeUpdate
        Revision......: 0x00001000
        ParentHandle..: 3A666398

This seems like useful information for the shell to display.

Cc: Ruiyu Ni <ruiyu.ni@intel.com>
Cc: Jaben Carsey <jaben.carsey@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Jeff Westfahl <jeff.westfahl@ni.com>
Signed-off-by: Ruiyu Ni <ruiyu.ni@intel.com>
Reviewed-by: Ruiyu Ni <ruiyu.ni@intel.com>
Reviewed-by: Jaben Carsey <jaben.carsey@intel.com>
ShellPkg/Library/UefiHandleParsingLib/UefiHandleParsingLib.c
ShellPkg/Library/UefiHandleParsingLib/UefiHandleParsingLib.uni

index c96f6dd157684c91e4db5ea4e505d139bb221627..d3ee068ebaf62711ad22455c7b3fb4b4ac001d6f 100644 (file)
 \r
 #include "UefiHandleParsingLib.h"\r
 #include "IndustryStandard/Acpi10.h"\r
 \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
 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
 /**\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
   EFI_STATUS                        Status;\r
   CHAR16                            *RetVal;\r
   CHAR16                            *Temp;\r
+  CHAR16                            *FileName;\r
   CHAR16                            *FilePath;\r
   CHAR16                            *CodeType;\r
   CHAR16                            *DataType;\r
   CHAR16                            *FilePath;\r
   CHAR16                            *CodeType;\r
   CHAR16                            *DataType;\r
@@ -192,6 +255,20 @@ LoadedImageProtocolDumpInformation(
 \r
   HandleParsingHiiInit();\r
 \r
 \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
   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
   CodeType = ConvertMemoryType(LoadedImage->ImageCodeType);\r
 \r
   RetVal = CatSPrint(\r
-             NULL,\r
+             RetVal,\r
              Temp,\r
              LoadedImage->Revision,\r
              LoadedImage->ParentHandle,\r
              Temp,\r
              LoadedImage->Revision,\r
              LoadedImage->ParentHandle,\r
index 7b3711d741ff596413e8a3f4dc32244c347b433d..e07c9a16703b3d5c2a773632b054dbb07e8b7d50 100644 (file)
 \r
 \r
 \r
 \r
 \r
 \r
+#string STR_LI_DUMP_NAME          #language en-US "     Name..........: %%H%s%%N\r\n"\r
+\r
 #string STR_LI_DUMP_MAIN          #language en-US "     Revision......: %%H0x%08x%%N\r\n"\r
                                                   "     ParentHandle..: %%H%x%%N\r\n"\r
                                                   "     SystemTable...: %%H%x%%N\r\n"\r
 #string STR_LI_DUMP_MAIN          #language en-US "     Revision......: %%H0x%08x%%N\r\n"\r
                                                   "     ParentHandle..: %%H%x%%N\r\n"\r
                                                   "     SystemTable...: %%H%x%%N\r\n"\r