]> git.proxmox.com Git - mirror_edk2.git/blobdiff - ShellPkg/Library/UefiDpLib/DpUtilities.c
ShellPkg/tftp: Convert from NULL class library to Dynamic Command
[mirror_edk2.git] / ShellPkg / Library / UefiDpLib / DpUtilities.c
index 89c9919e037a4ed7944a2f967fe08f465c35b10d..c60d27d8613f0572ee13ead10644c71423138f53 100644 (file)
@@ -1,7 +1,8 @@
 /** @file\r
   Utility functions used by the Dp application.\r
 \r
-  Copyright (c) 2009 - 2013, Intel Corporation. All rights reserved.\r
+  Copyright (c) 2009 - 2017, Intel Corporation. All rights reserved.\r
+  (C) Copyright 2015-2016 Hewlett Packard Enterprise Development LP<BR>\r
   This program and the accompanying materials\r
   are licensed and made available under the terms and conditions of the BSD License\r
   which accompanies this distribution.  The full text of the license may be found at\r
 #include <Library/MemoryAllocationLib.h>\r
 #include <Library/DebugLib.h>\r
 #include <Library/UefiBootServicesTableLib.h>\r
-#include <Library/TimerLib.h>\r
 #include <Library/PeCoffGetEntryPointLib.h>\r
 #include <Library/PrintLib.h>\r
 #include <Library/HiiLib.h>\r
 #include <Library/PcdLib.h>\r
 #include <Library/UefiLib.h>\r
 #include <Library/DevicePathLib.h>\r
+#include <Library/HandleParsingLib.h>\r
 \r
 #include <Pi/PiFirmwareFile.h>\r
 #include <Library/DxeServicesLib.h>\r
@@ -31,7 +32,6 @@
 #include <Protocol/DriverBinding.h>\r
 #include <Protocol/ComponentName2.h>\r
 #include <Protocol/DevicePath.h>\r
-#include <Protocol/DevicePathToText.h>\r
 \r
 #include <Guid/Performance.h>\r
 \r
@@ -67,6 +67,10 @@ GetDuration (
   UINT64    Duration;\r
   BOOLEAN   Error;\r
 \r
+  if (Measurement->EndTimeStamp == 0) {\r
+    return 0;\r
+  }\r
+\r
   // PERF_START macros are called with a value of 1 to indicate\r
   // the beginning of time.  So, adjust the start ticker value\r
   // to the real beginning of time.\r
@@ -131,7 +135,7 @@ IsPhase(
   \r
 **/\r
 VOID\r
-GetShortPdbFileName (\r
+DpGetShortPdbFileName (\r
   IN  CHAR8     *PdbFileName,\r
   OUT CHAR16    *UnicodeBuffer\r
   )\r
@@ -141,16 +145,16 @@ GetShortPdbFileName (
   UINTN StartIndex;\r
   UINTN EndIndex;\r
 \r
-  ZeroMem (UnicodeBuffer, DXE_PERFORMANCE_STRING_LENGTH * sizeof (CHAR16));\r
+  ZeroMem (UnicodeBuffer, (DP_GAUGE_STRING_LENGTH + 1) * sizeof (CHAR16));\r
 \r
   if (PdbFileName == NULL) {\r
-    StrCpy (UnicodeBuffer, L" ");\r
+    StrnCpyS (UnicodeBuffer, DP_GAUGE_STRING_LENGTH + 1, L" ", 1);\r
   } else {\r
     StartIndex = 0;\r
     for (EndIndex = 0; PdbFileName[EndIndex] != 0; EndIndex++)\r
       ;\r
     for (IndexA = 0; PdbFileName[IndexA] != 0; IndexA++) {\r
-      if (PdbFileName[IndexA] == '\\') {\r
+      if ((PdbFileName[IndexA] == '\\') || (PdbFileName[IndexA] == '/')) {\r
         StartIndex = IndexA + 1;\r
       }\r
 \r
@@ -163,8 +167,8 @@ GetShortPdbFileName (
     for (IndexA = StartIndex; IndexA < EndIndex; IndexA++) {\r
       UnicodeBuffer[IndexU] = (CHAR16) PdbFileName[IndexA];\r
       IndexU++;\r
-      if (IndexU >= DXE_PERFORMANCE_STRING_LENGTH) {\r
-        UnicodeBuffer[DXE_PERFORMANCE_STRING_LENGTH] = 0;\r
+      if (IndexU >= DP_GAUGE_STRING_LENGTH) {\r
+        UnicodeBuffer[DP_GAUGE_STRING_LENGTH] = 0;\r
         break;\r
       }\r
     }\r
@@ -188,7 +192,7 @@ GetShortPdbFileName (
 \r
 **/\r
 VOID\r
-GetNameFromHandle (\r
+DpGetNameFromHandle (\r
   IN EFI_HANDLE   Handle\r
   )\r
 {\r
@@ -204,7 +208,10 @@ GetNameFromHandle (
   UINTN                       StringSize;\r
   CHAR8                       *PlatformLanguage;\r
   EFI_COMPONENT_NAME2_PROTOCOL      *ComponentName2;\r
-  EFI_DEVICE_PATH_TO_TEXT_PROTOCOL  *DevicePathToText;\r
+\r
+  Image = NULL;\r
+  LoadedImageDevicePath = NULL;\r
+  DevicePath = NULL;\r
 \r
   //\r
   // Method 1: Get the name string from image PDB\r
@@ -237,7 +244,7 @@ GetNameFromHandle (
     PdbFileName = PeCoffLoaderGetPdbPointer (Image->ImageBase);\r
 \r
     if (PdbFileName != NULL) {\r
-      GetShortPdbFileName (PdbFileName, mGaugeString);\r
+      DpGetShortPdbFileName (PdbFileName, mGaugeString);\r
       return;\r
     }\r
   }\r
@@ -254,7 +261,7 @@ GetNameFromHandle (
     //\r
     // Get the current platform language setting\r
     //\r
-    GetEfiGlobalVariable2 (L"PlatformLang", (VOID**)&PlatformLanguage, NULL);\r
+    PlatformLanguage = GetBestLanguageForDriver(ComponentName2->SupportedLanguages, NULL, FALSE);\r
     Status = ComponentName2->GetDriverName (\r
                                ComponentName2,\r
                                PlatformLanguage != NULL ? PlatformLanguage : "en-US",\r
@@ -262,7 +269,7 @@ GetNameFromHandle (
                                );\r
     if (!EFI_ERROR (Status)) {\r
       SHELL_FREE_NON_NULL (PlatformLanguage);\r
-      StrnCpy (mGaugeString, StringPtr, DP_GAUGE_STRING_LENGTH);\r
+      StrnCpyS (mGaugeString, DP_GAUGE_STRING_LENGTH + 1, StringPtr, DP_GAUGE_STRING_LENGTH);\r
       mGaugeString[DP_GAUGE_STRING_LENGTH] = 0;\r
       return;\r
     }\r
@@ -275,9 +282,13 @@ GetNameFromHandle (
                   );\r
   if (!EFI_ERROR (Status) && (LoadedImageDevicePath != NULL)) {\r
     DevicePath = LoadedImageDevicePath;\r
+  } else if (Image != NULL) {\r
+    DevicePath = Image->FilePath;\r
+  }\r
 \r
+  if (DevicePath != NULL) {\r
     //\r
-    // Try to get image GUID from LoadedImageDevicePath protocol\r
+    // Try to get image GUID from image DevicePath\r
     //\r
     NameGuid = NULL;\r
     while (!IsDevicePathEndType (DevicePath)) {\r
@@ -306,7 +317,7 @@ GetNameFromHandle (
         //\r
         // Method 3. Get the name string from FFS UI section\r
         //\r
-        StrnCpy (mGaugeString, NameString, DP_GAUGE_STRING_LENGTH);\r
+        StrnCpyS (mGaugeString, DP_GAUGE_STRING_LENGTH + 1, NameString, DP_GAUGE_STRING_LENGTH);\r
         mGaugeString[DP_GAUGE_STRING_LENGTH] = 0;\r
         FreePool (NameString);\r
       } else {\r
@@ -320,19 +331,12 @@ GetNameFromHandle (
       //\r
       // Method 5: Get the name string from image DevicePath\r
       //\r
-      Status = gBS->LocateProtocol (\r
-                      &gEfiDevicePathToTextProtocolGuid,\r
-                      NULL,\r
-                      (VOID **) &DevicePathToText\r
-                      );\r
-      if (!EFI_ERROR (Status)) {\r
-        NameString = DevicePathToText->ConvertDevicePathToText (LoadedImageDevicePath, TRUE, FALSE);\r
-        if (NameString != NULL) {\r
-          StrnCpy (mGaugeString, NameString, DP_GAUGE_STRING_LENGTH);\r
-          mGaugeString[DP_GAUGE_STRING_LENGTH] = 0;\r
-          FreePool (NameString);\r
-          return;\r
-        }\r
+      NameString = ConvertDevicePathToText (DevicePath, TRUE, FALSE);\r
+      if (NameString != NULL) {\r
+        StrnCpyS (mGaugeString, DP_GAUGE_STRING_LENGTH + 1, NameString, DP_GAUGE_STRING_LENGTH);\r
+        mGaugeString[DP_GAUGE_STRING_LENGTH] = 0;\r
+        FreePool (NameString);\r
+        return;\r
       }\r
     }\r
   }\r
@@ -342,7 +346,7 @@ GetNameFromHandle (
   //\r
   StringPtr = HiiGetString (gDpHiiHandle, STRING_TOKEN (STR_DP_ERROR_NAME), NULL);\r
   ASSERT (StringPtr != NULL);\r
-  StrCpy (mGaugeString, StringPtr);\r
+  StrnCpyS (mGaugeString, DP_GAUGE_STRING_LENGTH + 1, StringPtr, DP_GAUGE_STRING_LENGTH);\r
   FreePool (StringPtr);\r
 }\r
 \r