]> git.proxmox.com Git - mirror_edk2.git/blobdiff - ShellPkg/Library/UefiHandleParsingLib/UefiHandleParsingLib.c
ShellPkg/dh: Modify the dump of "ImageDevicePath" and "DevicePath"
[mirror_edk2.git] / ShellPkg / Library / UefiHandleParsingLib / UefiHandleParsingLib.c
index 780c4587b821a1bc20b61f76576ebe62756b897b..1f2ca92bddbe6bd6420c9af1df80208d77343e2a 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,8 @@ LoadedImageProtocolDumpInformation(
   EFI_STATUS                        Status;\r
   CHAR16                            *RetVal;\r
   CHAR16                            *Temp;\r
+  CHAR16                            *FileName;\r
+  CHAR16                            *FilePath;\r
   CHAR16                            *CodeType;\r
   CHAR16                            *DataType;\r
 \r
@@ -176,13 +240,6 @@ LoadedImageProtocolDumpInformation(
     return (CatSPrint(NULL, L"LoadedImage"));\r
   }\r
 \r
-  HandleParsingHiiInit();\r
-\r
-  Temp = HiiGetString(mHandleParsingHiiHandle, STRING_TOKEN(STR_LI_DUMP_MAIN), NULL);\r
-  if (Temp == NULL) {\r
-    return NULL;\r
-  }\r
-\r
   Status = gBS->OpenProtocol (\r
                 TheHandle,\r
                 &gEfiLoadedImageProtocolGuid,\r
@@ -193,21 +250,43 @@ LoadedImageProtocolDumpInformation(
                );\r
 \r
   if (EFI_ERROR (Status)) {\r
-    SHELL_FREE_NON_NULL (Temp);\r
     return NULL;\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
+  }\r
+\r
+  FilePath = ConvertDevicePathToText(LoadedImage->FilePath, TRUE, TRUE);\r
+\r
   DataType = ConvertMemoryType(LoadedImage->ImageDataType);\r
   CodeType = ConvertMemoryType(LoadedImage->ImageCodeType);\r
 \r
   RetVal = CatSPrint(\r
-             NULL,\r
+             RetVal,\r
              Temp,\r
              LoadedImage->Revision,\r
              LoadedImage->ParentHandle,\r
              LoadedImage->SystemTable,\r
              LoadedImage->DeviceHandle,\r
-             LoadedImage->FilePath,\r
+             FilePath,\r
              LoadedImage->LoadOptionsSize,\r
              LoadedImage->LoadOptions,\r
              LoadedImage->ImageBase,\r
@@ -219,6 +298,7 @@ LoadedImageProtocolDumpInformation(
 \r
 \r
   SHELL_FREE_NON_NULL(Temp);\r
+  SHELL_FREE_NON_NULL(FilePath);\r
   SHELL_FREE_NON_NULL(CodeType);\r
   SHELL_FREE_NON_NULL(DataType);\r
 \r
@@ -767,6 +847,50 @@ ConvertDevicePathToShortText(
   return (Temp);\r
 }\r
 \r
+/**\r
+  Function to dump protocol information.\r
+\r
+  This will allocate the return buffer from boot services pool.\r
+\r
+  @param[in] TheHandle      The handle that has the protocol installed.\r
+  @param[in] Verbose        TRUE for additional information, FALSE otherwise.\r
+  @param[in] Protocol       The protocol is needed to dump.\r
+\r
+  @retval A pointer to a string containing the information.\r
+**/\r
+STATIC CHAR16*\r
+EFIAPI\r
+DevicePathProtocolDumpInformationEx (\r
+  IN CONST EFI_HANDLE   TheHandle,\r
+  IN CONST BOOLEAN      Verbose,\r
+  IN       EFI_GUID     *Protocol\r
+)\r
+{\r
+  EFI_DEVICE_PATH_PROTOCOL          *DevPath;\r
+  CHAR16                            *DevPathStr;\r
+  CHAR16                            *DevPathStrTemp;\r
+  UINTN                             Size;\r
+  EFI_STATUS                        Status;\r
+  DevPathStr     = NULL;\r
+  DevPathStrTemp = NULL;\r
+  Status = gBS->OpenProtocol(TheHandle, Protocol, (VOID**)&DevPath, gImageHandle, NULL, EFI_OPEN_PROTOCOL_GET_PROTOCOL);\r
+  if (!EFI_ERROR(Status)) {\r
+    DevPathStr = ConvertDevicePathToShortText (DevPath, Verbose, 30);\r
+    if (Verbose) {\r
+      Size = StrSize(DevPathStr) + sizeof(CHAR16) * 2;\r
+      DevPathStrTemp = AllocateZeroPool (Size);\r
+      if (DevPathStrTemp != NULL) {\r
+        StrnCatS (DevPathStrTemp, Size/sizeof(CHAR16), L"  ", 2);\r
+        StrnCatS (DevPathStrTemp, Size/sizeof(CHAR16), DevPathStr, StrLen (DevPathStr));\r
+      }\r
+      FreePool (DevPathStr);\r
+      DevPathStr = DevPathStrTemp;\r
+    }\r
+    gBS->CloseProtocol(TheHandle, Protocol, gImageHandle, NULL);\r
+  }\r
+  return DevPathStr;\r
+}\r
+\r
 /**\r
   Function to dump information about DevicePath protocol.\r
 \r
@@ -784,17 +908,7 @@ DevicePathProtocolDumpInformation(
   IN CONST BOOLEAN    Verbose\r
   )\r
 {\r
-  EFI_DEVICE_PATH_PROTOCOL          *DevPath;\r
-  CHAR16                            *Temp;\r
-  EFI_STATUS                        Status;\r
-  Temp = NULL;\r
-\r
-  Status = gBS->OpenProtocol(TheHandle, &gEfiDevicePathProtocolGuid, (VOID**)&DevPath, gImageHandle, NULL, EFI_OPEN_PROTOCOL_GET_PROTOCOL);\r
-  if (!EFI_ERROR(Status)) {\r
-    Temp = ConvertDevicePathToShortText (DevPath, Verbose, 30);\r
-    gBS->CloseProtocol(TheHandle, &gEfiDevicePathProtocolGuid, gImageHandle, NULL);\r
-  }\r
-  return (Temp);\r
+  return DevicePathProtocolDumpInformationEx (TheHandle, Verbose, &gEfiDevicePathProtocolGuid);\r
 }\r
 \r
 /**\r
@@ -814,17 +928,7 @@ LoadedImageDevicePathProtocolDumpInformation(
   IN CONST BOOLEAN    Verbose\r
   )\r
 {\r
-  EFI_DEVICE_PATH_PROTOCOL          *DevPath;\r
-  CHAR16                            *Temp;\r
-  EFI_STATUS                        Status;\r
-  Temp = NULL;\r
-\r
-  Status = gBS->OpenProtocol(TheHandle, &gEfiLoadedImageDevicePathProtocolGuid, (VOID**)&DevPath, gImageHandle, NULL, EFI_OPEN_PROTOCOL_GET_PROTOCOL);\r
-  if (!EFI_ERROR(Status)) {\r
-    Temp = ConvertDevicePathToShortText (DevPath, Verbose, 30);\r
-    gBS->CloseProtocol(TheHandle, &gEfiDevicePathProtocolGuid, gImageHandle, NULL);\r
-  }\r
-  return (Temp);\r
+  return DevicePathProtocolDumpInformationEx (TheHandle, Verbose, &gEfiLoadedImageDevicePathProtocolGuid);\r
 }\r
 \r
 /**\r
@@ -2331,7 +2435,9 @@ ConvertHandleIndexToHandle(
       // Verify that LinkWalker->TheHandle is valid handle\r
       //\r
       Status = gBS->ProtocolsPerHandle(ListWalker->TheHandle, &ProtocolBuffer, &ProtocolCount);\r
-      if (EFI_ERROR (Status)) {\r
+      if (!EFI_ERROR (Status)) {\r
+        FreePool (ProtocolBuffer);\r
+      } else {\r
         //\r
         // TheHandle is not valid, so do not add to handle list\r
         //\r
@@ -3079,3 +3185,55 @@ GetHandleListByProtocolList (
 \r
   return (HandleList);\r
 }\r
+\r
+/**\r
+  Return all supported GUIDs.\r
+\r
+  @param[out]     Guids  The buffer to return all supported GUIDs.\r
+  @param[in, out] Count  On input, the count of GUIDs the buffer can hold,\r
+                         On output, the count of GUIDs to return.\r
+\r
+  @retval EFI_INVALID_PARAMETER Count is NULL.\r
+  @retval EFI_BUFFER_TOO_SMALL  Buffer is not enough to hold all GUIDs.\r
+  @retval EFI_SUCCESS           GUIDs are returned successfully.\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+GetAllMappingGuids (\r
+  OUT EFI_GUID *Guids,\r
+  IN OUT UINTN *Count\r
+  )\r
+{\r
+  UINTN GuidCount;\r
+  UINTN NtGuidCount;\r
+  UINTN Index;\r
+\r
+  if (Count == NULL) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  NtGuidCount = 0;\r
+  if (PcdGetBool (PcdShellIncludeNtGuids)) {\r
+    NtGuidCount = ARRAY_SIZE (mGuidStringListNT) - 1;\r
+  }\r
+  GuidCount   = ARRAY_SIZE (mGuidStringList) - 1;\r
+\r
+  if (*Count < NtGuidCount + GuidCount + mGuidListCount) {\r
+    *Count = NtGuidCount + GuidCount + mGuidListCount;\r
+    return EFI_BUFFER_TOO_SMALL;\r
+  }\r
+\r
+  for (Index = 0; Index < NtGuidCount; Index++) {\r
+    CopyGuid (&Guids[Index], mGuidStringListNT[Index].GuidId);\r
+  }\r
+\r
+  for (Index = 0; Index < GuidCount; Index++) {\r
+    CopyGuid (&Guids[NtGuidCount + Index], mGuidStringList[Index].GuidId);\r
+  }\r
+\r
+  for (Index = 0; Index < mGuidListCount; Index++) {\r
+    CopyGuid (&Guids[NtGuidCount + GuidCount + Index], mGuidList[Index].GuidId);\r
+  }\r
+\r
+  return EFI_SUCCESS;\r
+}\r