public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: Jeff Westfahl <jeff.westfahl@ni.com>
To: <edk2-devel@lists.01.org>
Cc: Jeff Westfahl <jeff.westfahl@ni.com>,
	Ruiyu Ni <ruiyu.ni@intel.com>,
	Jaben Carsey <jaben.carsey@intel.com>
Subject: [PATCH 3/3] ShellPkg/HandleParsingLib: Show LoadedImageProtocol file name
Date: Thu, 4 May 2017 16:53:04 -0500	[thread overview]
Message-ID: <1493934784-30012-4-git-send-email-jeff.westfahl@ni.com> (raw)
In-Reply-To: <1493934784-30012-1-git-send-email-jeff.westfahl@ni.com>

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>
---
 .../UefiHandleParsingLib/UefiHandleParsingLib.c    | 90 +++++++++++++++++++++-
 .../UefiHandleParsingLib/UefiHandleParsingLib.uni  |  2 +
 2 files changed, 91 insertions(+), 1 deletion(-)

diff --git a/ShellPkg/Library/UefiHandleParsingLib/UefiHandleParsingLib.c b/ShellPkg/Library/UefiHandleParsingLib/UefiHandleParsingLib.c
index c96f6dd..74934f8 100644
--- a/ShellPkg/Library/UefiHandleParsingLib/UefiHandleParsingLib.c
+++ b/ShellPkg/Library/UefiHandleParsingLib/UefiHandleParsingLib.c
@@ -16,12 +16,85 @@
 
 #include "UefiHandleParsingLib.h"
 #include "IndustryStandard/Acpi10.h"
+#include "Pi/PiFirmwareFile.h"
+#include "Pi/PiFirmwareVolume.h"
+#include "Protocol/FirmwareVolume2.h"
 
 EFI_HANDLE        mHandleParsingHiiHandle = NULL;
 HANDLE_INDEX_LIST mHandleList = {{{NULL,NULL},0,0},0};
 GUID_INFO_BLOCK   *mGuidList;
 UINTN             mGuidListCount;
 /**
+  Function to find the file name associated with a LoadedImageProtocol.
+
+  @param[in] LoadedImage     An instance of LoadedImageProtocol.
+
+  @retval                    A string representation of the file name associated
+                             with LoadedImage, or NULL if no name can be found.
+**/
+CHAR16*
+FindLoadedImageFileName (
+  IN EFI_LOADED_IMAGE_PROTOCOL *LoadedImage
+  )
+{
+  EFI_GUID                       *NameGuid;
+  EFI_STATUS                     Status;
+  EFI_FIRMWARE_VOLUME2_PROTOCOL  *Fv;
+  VOID                           *Buffer;
+  UINTN                          BufferSize;
+  UINT32                         AuthenticationStatus;
+
+  //
+  // Only subtype MEDIA_PIWG_FW_FILE_DP of type MEDIA_DEVICE_PATH is supported.
+  //
+  if (   (LoadedImage == NULL)
+      || (LoadedImage->FilePath == NULL)
+      || (LoadedImage->FilePath->Type != MEDIA_DEVICE_PATH)
+      || (LoadedImage->FilePath->SubType != MEDIA_PIWG_FW_FILE_DP)
+   ) {
+    return (NULL);
+  }
+
+  NameGuid = EfiGetNameGuidFromFwVolDevicePathNode((MEDIA_FW_VOL_FILEPATH_DEVICE_PATH *)LoadedImage->FilePath);
+
+  if (NameGuid == NULL) {
+    return (NULL);
+  }
+
+  //
+  // Get the FirmwareVolume2Protocol of the device handle that this image was
+  // loaded from.
+  //
+  Status = gBS->HandleProtocol(
+    LoadedImage->DeviceHandle,
+    &gEfiFirmwareVolume2ProtocolGuid,
+    (VOID**)&Fv);
+
+  //
+  // FirmwareVolume2Protocol is PI, and is not required to be available.
+  //
+  if (EFI_ERROR(Status)) {
+    return (NULL);
+  }
+
+  //
+  // Read the user interface section of the image.
+  //
+  Buffer = NULL;
+  Status = Fv->ReadSection(Fv, NameGuid, EFI_SECTION_USER_INTERFACE, 0, &Buffer, &BufferSize, &AuthenticationStatus);
+
+  if (EFI_ERROR(Status)) {
+    return (NULL);
+  }
+
+  //
+  // ReadSection returns just the section data, without any section header. For
+  // a user interface section, the only data is the file name.
+  //
+  return (Buffer);
+}
+
+/**
   Function to translate the EFI_MEMORY_TYPE into a string.
 
   @param[in] Memory     The memory type.
@@ -169,6 +242,7 @@ LoadedImageProtocolDumpInformation(
   EFI_STATUS                        Status;
   CHAR16                            *RetVal;
   CHAR16                            *Temp;
+  CHAR16                            *FileName;
   CHAR16                            *FilePath;
   CHAR16                            *CodeType;
   CHAR16                            *DataType;
@@ -192,6 +266,20 @@ LoadedImageProtocolDumpInformation(
 
   HandleParsingHiiInit();
 
+  FileName = FindLoadedImageFileName(LoadedImage);
+
+  RetVal = NULL;
+  if (FileName) {
+    Temp = HiiGetString(mHandleParsingHiiHandle, STRING_TOKEN(STR_LI_DUMP_NAME), NULL);
+
+    if (Temp != NULL) {
+      RetVal = CatSPrint(NULL, Temp, FileName);
+    }
+
+    SHELL_FREE_NON_NULL(Temp);
+    SHELL_FREE_NON_NULL(FileName);
+  }
+
   Temp = HiiGetString(mHandleParsingHiiHandle, STRING_TOKEN(STR_LI_DUMP_MAIN), NULL);
   if (Temp == NULL) {
     return NULL;
@@ -203,7 +291,7 @@ LoadedImageProtocolDumpInformation(
   CodeType = ConvertMemoryType(LoadedImage->ImageCodeType);
 
   RetVal = CatSPrint(
-             NULL,
+             RetVal,
              Temp,
              LoadedImage->Revision,
              LoadedImage->ParentHandle,
diff --git a/ShellPkg/Library/UefiHandleParsingLib/UefiHandleParsingLib.uni b/ShellPkg/Library/UefiHandleParsingLib/UefiHandleParsingLib.uni
index 7b3711d..e07c9a1 100644
--- a/ShellPkg/Library/UefiHandleParsingLib/UefiHandleParsingLib.uni
+++ b/ShellPkg/Library/UefiHandleParsingLib/UefiHandleParsingLib.uni
@@ -348,6 +348,8 @@
 
 
 
+#string STR_LI_DUMP_NAME          #language en-US "     Name..........: %%H%s%%N\r\n"
+
 #string STR_LI_DUMP_MAIN          #language en-US "     Revision......: %%H0x%08x%%N\r\n"
                                                   "     ParentHandle..: %%H%x%%N\r\n"
                                                   "     SystemTable...: %%H%x%%N\r\n"
-- 
2.7.4



  parent reply	other threads:[~2017-05-04 21:53 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-05-04 21:53 [PATCH 0/3] ShellPkg/HandleParsingLib: Show LoadedImageProtocol info Jeff Westfahl
2017-05-04 21:53 ` [PATCH 1/3] ShellPkg/HandleParsingLib: Show LoadedImageProtocol file path as text Jeff Westfahl
2017-05-04 21:53 ` [PATCH 2/3] ShellPkg/HandleParsingLib: Open LoadedImageProtocol first Jeff Westfahl
2017-05-04 21:53 ` Jeff Westfahl [this message]
2017-05-05  2:59 ` [PATCH 0/3] ShellPkg/HandleParsingLib: Show LoadedImageProtocol info Ni, Ruiyu
2017-05-05 12:25   ` Jeff Westfahl
2017-05-05 15:49     ` Carsey, Jaben

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-list from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1493934784-30012-4-git-send-email-jeff.westfahl@ni.com \
    --to=devel@edk2.groups.io \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox