/** @file\r
- * Utility functions used by the Dp application.\r
- *\r
- * Copyright (c) 2009 - 2010, Intel Corporation. All rights reserved.<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
- * http://opensource.org/licenses/bsd-license.php\r
- *\r
- * THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+ Utility functions used by the Dp application.\r
+\r
+ Copyright (c) 2009 - 2015, Intel Corporation. All rights reserved.<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
+ http://opensource.org/licenses/bsd-license.php\r
+\r
+ THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
**/\r
\r
#include <Library/BaseLib.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
+\r
+#include <Pi/PiFirmwareFile.h>\r
+#include <Library/DxeServicesLib.h>\r
\r
#include <Protocol/LoadedImage.h>\r
#include <Protocol/DriverBinding.h>\r
+#include <Protocol/ComponentName2.h>\r
+#include <Protocol/DevicePath.h>\r
\r
#include <Guid/Performance.h>\r
\r
#include "Literals.h"\r
#include "DpInternal.h"\r
\r
+/**\r
+ Wrap original FreePool to check NULL pointer first.\r
+\r
+ @param[in] Buffer The pointer to the buffer to free.\r
+\r
+**/\r
+VOID\r
+SafeFreePool (\r
+ IN VOID *Buffer\r
+ )\r
+{\r
+ if (Buffer != NULL) {\r
+ FreePool (Buffer);\r
+ }\r
+}\r
+\r
/** \r
Calculate an event's duration in timer ticks.\r
\r
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
+ StrCpyS (UnicodeBuffer, DP_GAUGE_STRING_LENGTH + 1, L" ");\r
} else {\r
StartIndex = 0;\r
for (EndIndex = 0; PdbFileName[EndIndex] != 0; EndIndex++)\r
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
\r
/** \r
Get a human readable name for an image handle.\r
- \r
+ The following methods will be tried orderly:\r
+ 1. Image PDB\r
+ 2. ComponentName2 protocol\r
+ 3. FFS UI section\r
+ 4. Image GUID\r
+ 5. Image DevicePath\r
+ 6. Unknown Driver Name\r
+\r
@param[in] Handle\r
- \r
+\r
@post The resulting Unicode name string is stored in the\r
mGaugeString global array.\r
- \r
+\r
**/\r
VOID\r
GetNameFromHandle (\r
CHAR8 *PdbFileName;\r
EFI_DRIVER_BINDING_PROTOCOL *DriverBinding;\r
EFI_STRING StringPtr;\r
+ EFI_DEVICE_PATH_PROTOCOL *LoadedImageDevicePath;\r
+ EFI_DEVICE_PATH_PROTOCOL *DevicePath;\r
+ EFI_GUID *NameGuid;\r
+ CHAR16 *NameString;\r
+ UINTN StringSize;\r
+ CHAR8 *PlatformLanguage;\r
+ CHAR8 *BestLanguage;\r
+ EFI_COMPONENT_NAME2_PROTOCOL *ComponentName2;\r
\r
- // Proactively get the error message so it will be ready if needed\r
- StringPtr = HiiGetString (gHiiHandle, STRING_TOKEN (STR_DP_ERROR_NAME), NULL);\r
- ASSERT (StringPtr != NULL);\r
+ BestLanguage = NULL;\r
+ PlatformLanguage = NULL;\r
\r
- // Get handle name from image protocol\r
+ //\r
+ // Method 1: Get the name string from image PDB\r
//\r
Status = gBS->HandleProtocol (\r
- Handle,\r
- &gEfiLoadedImageProtocolGuid,\r
- (VOID**) &Image\r
- );\r
+ Handle,\r
+ &gEfiLoadedImageProtocolGuid,\r
+ (VOID **) &Image\r
+ );\r
\r
if (EFI_ERROR (Status)) {\r
Status = gBS->OpenProtocol (\r
+ Handle,\r
+ &gEfiDriverBindingProtocolGuid,\r
+ (VOID **) &DriverBinding,\r
+ NULL,\r
+ NULL,\r
+ EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
+ );\r
+ if (!EFI_ERROR (Status)) {\r
+ Status = gBS->HandleProtocol (\r
+ DriverBinding->ImageHandle,\r
+ &gEfiLoadedImageProtocolGuid,\r
+ (VOID **) &Image\r
+ );\r
+ }\r
+ }\r
+\r
+ if (!EFI_ERROR (Status)) {\r
+ PdbFileName = PeCoffLoaderGetPdbPointer (Image->ImageBase);\r
+\r
+ if (PdbFileName != NULL) {\r
+ GetShortPdbFileName (PdbFileName, mGaugeString);\r
+ return;\r
+ }\r
+ }\r
+\r
+ //\r
+ // Method 2: Get the name string from ComponentName2 protocol\r
+ //\r
+ Status = gBS->HandleProtocol (\r
Handle,\r
- &gEfiDriverBindingProtocolGuid,\r
- (VOID **) &DriverBinding,\r
- NULL,\r
- NULL,\r
- EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
+ &gEfiComponentName2ProtocolGuid,\r
+ (VOID **) &ComponentName2\r
);\r
- if (EFI_ERROR (Status)) {\r
- StrCpy (mGaugeString, StringPtr);\r
- FreePool (StringPtr);\r
- return ;\r
+ if (!EFI_ERROR (Status)) {\r
+ //\r
+ // Get the current platform language setting\r
+ //\r
+ GetEfiGlobalVariable2 (L"PlatformLang", (VOID**)&PlatformLanguage, NULL);\r
+\r
+ BestLanguage = GetBestLanguage(\r
+ ComponentName2->SupportedLanguages,\r
+ FALSE,\r
+ PlatformLanguage,\r
+ ComponentName2->SupportedLanguages,\r
+ NULL\r
+ );\r
+\r
+ SafeFreePool (PlatformLanguage);\r
+ Status = ComponentName2->GetDriverName (\r
+ ComponentName2,\r
+ BestLanguage,\r
+ &StringPtr\r
+ );\r
+ SafeFreePool (BestLanguage);\r
+ if (!EFI_ERROR (Status)) {\r
+ StrCpyS (\r
+ mGaugeString,\r
+ DP_GAUGE_STRING_LENGTH + 1,\r
+ StringPtr\r
+ );\r
+ return;\r
}\r
+ }\r
\r
- // Get handle name from image protocol\r
- //\r
- Status = gBS->HandleProtocol (\r
- DriverBinding->ImageHandle,\r
- &gEfiLoadedImageProtocolGuid,\r
- (VOID**) &Image\r
+ Status = gBS->HandleProtocol (\r
+ Handle,\r
+ &gEfiLoadedImageDevicePathProtocolGuid,\r
+ (VOID **) &LoadedImageDevicePath\r
);\r
- }\r
+ if (!EFI_ERROR (Status) && (LoadedImageDevicePath != NULL)) {\r
+ DevicePath = LoadedImageDevicePath;\r
\r
- PdbFileName = PeCoffLoaderGetPdbPointer (Image->ImageBase);\r
+ //\r
+ // Try to get image GUID from LoadedImageDevicePath protocol\r
+ //\r
+ NameGuid = NULL;\r
+ while (!IsDevicePathEndType (DevicePath)) {\r
+ NameGuid = EfiGetNameGuidFromFwVolDevicePathNode ((MEDIA_FW_VOL_FILEPATH_DEVICE_PATH *) DevicePath);\r
+ if (NameGuid != NULL) {\r
+ break;\r
+ }\r
+ DevicePath = NextDevicePathNode (DevicePath);\r
+ }\r
\r
- if (PdbFileName != NULL) {\r
- GetShortPdbFileName (PdbFileName, mGaugeString);\r
- } else {\r
- StrCpy (mGaugeString, StringPtr);\r
+ if (NameGuid != NULL) {\r
+ //\r
+ // Try to get the image's FFS UI section by image GUID\r
+ //\r
+ NameString = NULL;\r
+ StringSize = 0;\r
+ Status = GetSectionFromAnyFv (\r
+ NameGuid,\r
+ EFI_SECTION_USER_INTERFACE,\r
+ 0,\r
+ (VOID **) &NameString,\r
+ &StringSize\r
+ );\r
+\r
+ if (!EFI_ERROR (Status)) {\r
+ //\r
+ // Method 3. Get the name string from FFS UI section\r
+ //\r
+ StrCpyS (\r
+ mGaugeString,\r
+ DP_GAUGE_STRING_LENGTH + 1,\r
+ NameString\r
+ );\r
+ FreePool (NameString);\r
+ } else {\r
+ //\r
+ // Method 4: Get the name string from image GUID\r
+ //\r
+ UnicodeSPrint (mGaugeString, sizeof (mGaugeString), L"%g", NameGuid);\r
+ }\r
+ return;\r
+ } else {\r
+ //\r
+ // Method 5: Get the name string from image DevicePath\r
+ //\r
+ NameString = ConvertDevicePathToText (LoadedImageDevicePath, TRUE, FALSE);\r
+ if (NameString != NULL) {\r
+ StrCpyS (\r
+ mGaugeString,\r
+ DP_GAUGE_STRING_LENGTH + 1,\r
+ NameString\r
+ );\r
+ FreePool (NameString);\r
+ return;\r
+ }\r
+ }\r
}\r
+\r
+ //\r
+ // Method 6: Unknown Driver Name\r
+ //\r
+ StringPtr = HiiGetString (gHiiHandle, STRING_TOKEN (STR_DP_ERROR_NAME), NULL);\r
+ ASSERT (StringPtr != NULL);\r
+ StrCpyS (mGaugeString, DP_GAUGE_STRING_LENGTH + 1, StringPtr);\r
FreePool (StringPtr);\r
- return ;\r
+ return;\r
}\r
\r
/** \r
\r
**/\r
UINTN\r
+EFIAPI\r
PrintToken (\r
IN UINT16 Token,\r
...\r
SetMem( mPrintTokenBuffer, BufferSize, 0);\r
\r
Return = UnicodeVSPrint (mPrintTokenBuffer, BufferSize, StringPtr, Marker);\r
+ VA_END (Marker);\r
+ \r
if (Return > 0 && gST->ConOut != NULL) {\r
gST->ConOut->OutputString (gST->ConOut, mPrintTokenBuffer);\r
}\r