summaryrefslogtreecommitdiff
path: root/MdeModulePkg/Application/DumpDynPcd/DumpDynPcd.c
diff options
context:
space:
mode:
Diffstat (limited to 'MdeModulePkg/Application/DumpDynPcd/DumpDynPcd.c')
-rw-r--r--MdeModulePkg/Application/DumpDynPcd/DumpDynPcd.c223
1 files changed, 116 insertions, 107 deletions
diff --git a/MdeModulePkg/Application/DumpDynPcd/DumpDynPcd.c b/MdeModulePkg/Application/DumpDynPcd/DumpDynPcd.c
index 96b35d3..b8571c4 100644
--- a/MdeModulePkg/Application/DumpDynPcd/DumpDynPcd.c
+++ b/MdeModulePkg/Application/DumpDynPcd/DumpDynPcd.c
@@ -14,7 +14,6 @@
#include <Library/UefiBootServicesTableLib.h>
#include <Library/UefiLib.h>
-
#include <Protocol/UnicodeCollation.h>
#include <Protocol/PiPcd.h>
#include <Protocol/Pcd.h>
@@ -23,7 +22,6 @@
#include <Protocol/ShellParameters.h>
#include <Protocol/Shell.h>
-
//
// String token ID of help message text.
// Shell supports to find help message in the resource section of an application image if
@@ -32,24 +30,23 @@
// the resource section. Thus the application can use '-?' option to show help message in
// Shell.
//
-GLOBAL_REMOVE_IF_UNREFERENCED EFI_STRING_ID mStrDumpDynPcdHelpTokenId = STRING_TOKEN (STR_DUMP_DYN_PCD_HELP_INFORMATION);
-
-#define MAJOR_VERSION 1
-#define MINOR_VERSION 0
+GLOBAL_REMOVE_IF_UNREFERENCED EFI_STRING_ID mStrDumpDynPcdHelpTokenId = STRING_TOKEN (STR_DUMP_DYN_PCD_HELP_INFORMATION);
-static EFI_UNICODE_COLLATION_PROTOCOL *mUnicodeCollation = NULL;
-static EFI_PCD_PROTOCOL *mPiPcd = NULL;
-static PCD_PROTOCOL *mPcd = NULL;
-static EFI_GET_PCD_INFO_PROTOCOL *mPiPcdInfo = NULL;
-static GET_PCD_INFO_PROTOCOL *mPcdInfo = NULL;
-static CHAR16 *mTempPcdNameBuffer = NULL;
-static UINTN mTempPcdNameBufferSize = 0;
+#define MAJOR_VERSION 1
+#define MINOR_VERSION 0
-static CONST CHAR8 mHex[] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'};
+static EFI_UNICODE_COLLATION_PROTOCOL *mUnicodeCollation = NULL;
+static EFI_PCD_PROTOCOL *mPiPcd = NULL;
+static PCD_PROTOCOL *mPcd = NULL;
+static EFI_GET_PCD_INFO_PROTOCOL *mPiPcdInfo = NULL;
+static GET_PCD_INFO_PROTOCOL *mPcdInfo = NULL;
+static CHAR16 *mTempPcdNameBuffer = NULL;
+static UINTN mTempPcdNameBufferSize = 0;
-static UINTN Argc;
-static CHAR16 **Argv;
+static CONST CHAR8 mHex[] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' };
+static UINTN Argc;
+static CHAR16 **Argv;
/**
@@ -63,15 +60,15 @@ GetArg (
VOID
)
{
- EFI_STATUS Status;
- EFI_SHELL_PARAMETERS_PROTOCOL *ShellParameters;
+ EFI_STATUS Status;
+ EFI_SHELL_PARAMETERS_PROTOCOL *ShellParameters;
Status = gBS->HandleProtocol (
gImageHandle,
&gEfiShellParametersProtocolGuid,
- (VOID**)&ShellParameters
+ (VOID **)&ShellParameters
);
- if (EFI_ERROR(Status)) {
+ if (EFI_ERROR (Status)) {
return Status;
}
@@ -121,21 +118,21 @@ ShowHelp (
static
VOID
DumpHex (
- IN UINTN Indent,
- IN UINTN Offset,
- IN UINTN DataSize,
- IN VOID *UserData
+ IN UINTN Indent,
+ IN UINTN Offset,
+ IN UINTN DataSize,
+ IN VOID *UserData
)
{
- UINT8 *Data;
+ UINT8 *Data;
- CHAR8 Val[50];
+ CHAR8 Val[50];
- CHAR8 Str[20];
+ CHAR8 Str[20];
- UINT8 TempByte;
- UINTN Size;
- UINTN Index;
+ UINT8 TempByte;
+ UINTN Size;
+ UINTN Index;
Data = UserData;
while (DataSize != 0) {
@@ -145,24 +142,23 @@ DumpHex (
}
for (Index = 0; Index < Size; Index += 1) {
- TempByte = Data[Index];
- Val[Index * 3 + 0] = mHex[TempByte >> 4];
- Val[Index * 3 + 1] = mHex[TempByte & 0xF];
- Val[Index * 3 + 2] = (CHAR8) ((Index == 7) ? '-' : ' ');
- Str[Index] = (CHAR8) ((TempByte < ' ' || TempByte > 'z') ? '.' : TempByte);
+ TempByte = Data[Index];
+ Val[Index * 3 + 0] = mHex[TempByte >> 4];
+ Val[Index * 3 + 1] = mHex[TempByte & 0xF];
+ Val[Index * 3 + 2] = (CHAR8)((Index == 7) ? '-' : ' ');
+ Str[Index] = (CHAR8)((TempByte < ' ' || TempByte > 'z') ? '.' : TempByte);
}
- Val[Index * 3] = 0;
- Str[Index] = 0;
+ Val[Index * 3] = 0;
+ Str[Index] = 0;
Print (L"%*a%08X: %-48a *%a*\r\n", Indent, "", Offset, Val, Str);
- Data += Size;
- Offset += Size;
+ Data += Size;
+ Offset += Size;
DataSize -= Size;
}
}
-
/**
Safely append with automatic string resizing given length of Destination and
desired length of copy from Source.
@@ -194,23 +190,23 @@ DumpHex (
@return Destination return the resultant string.
**/
static
-CHAR16*
+CHAR16 *
InternalStrnCatGrow (
- IN OUT CHAR16 **Destination,
- IN OUT UINTN *CurrentSize,
- IN CONST CHAR16 *Source
+ IN OUT CHAR16 **Destination,
+ IN OUT UINTN *CurrentSize,
+ IN CONST CHAR16 *Source
)
{
- UINTN DestinationStartSize;
- UINTN NewSize;
- UINTN SourceLen;
+ UINTN DestinationStartSize;
+ UINTN NewSize;
+ UINTN SourceLen;
- SourceLen = StrLen(Source);
+ SourceLen = StrLen (Source);
//
// ASSERTs
//
- ASSERT(Destination != NULL);
+ ASSERT (Destination != NULL);
//
// If there's nothing to do then just return Destination
@@ -222,7 +218,7 @@ InternalStrnCatGrow (
//
// allow for un-initialized pointers, based on size being 0
//
- if (CurrentSize != NULL && *CurrentSize == 0) {
+ if ((CurrentSize != NULL) && (*CurrentSize == 0)) {
*Destination = NULL;
}
@@ -230,9 +226,9 @@ InternalStrnCatGrow (
// allow for NULL pointers address as Destination
//
if (*Destination != NULL) {
- ASSERT(CurrentSize != 0);
- DestinationStartSize = StrSize(*Destination);
- ASSERT(DestinationStartSize <= *CurrentSize);
+ ASSERT (CurrentSize != 0);
+ DestinationStartSize = StrSize (*Destination);
+ ASSERT (DestinationStartSize <= *CurrentSize);
} else {
DestinationStartSize = 0;
}
@@ -242,16 +238,17 @@ InternalStrnCatGrow (
//
if (CurrentSize != NULL) {
NewSize = *CurrentSize;
- if (NewSize < DestinationStartSize + (SourceLen * sizeof(CHAR16))) {
- while (NewSize < (DestinationStartSize + (SourceLen*sizeof(CHAR16)))) {
- NewSize += 2 * SourceLen * sizeof(CHAR16);
+ if (NewSize < DestinationStartSize + (SourceLen * sizeof (CHAR16))) {
+ while (NewSize < (DestinationStartSize + (SourceLen*sizeof (CHAR16)))) {
+ NewSize += 2 * SourceLen * sizeof (CHAR16);
}
- *Destination = ReallocatePool(*CurrentSize, NewSize, *Destination);
+
+ *Destination = ReallocatePool (*CurrentSize, NewSize, *Destination);
*CurrentSize = NewSize;
}
} else {
- NewSize = (SourceLen + 1)*sizeof(CHAR16);
- *Destination = AllocateZeroPool(NewSize);
+ NewSize = (SourceLen + 1)*sizeof (CHAR16);
+ *Destination = AllocateZeroPool (NewSize);
}
//
@@ -261,7 +258,7 @@ InternalStrnCatGrow (
return (NULL);
}
- StrnCatS(*Destination, NewSize/sizeof(CHAR16), Source, SourceLen);
+ StrnCatS (*Destination, NewSize/sizeof (CHAR16), Source, SourceLen);
return *Destination;
}
@@ -276,15 +273,15 @@ InternalStrnCatGrow (
static
CHAR16 *
GetPcdTypeString (
- IN CONST EFI_GUID *TokenSpace,
- IN EFI_PCD_TYPE PcdType
+ IN CONST EFI_GUID *TokenSpace,
+ IN EFI_PCD_TYPE PcdType
)
{
- UINTN BufLen;
- CHAR16 *RetString;
+ UINTN BufLen;
+ CHAR16 *RetString;
- BufLen = 0;
- RetString = NULL;
+ BufLen = 0;
+ RetString = NULL;
switch (PcdType) {
case EFI_PCD_TYPE_8:
@@ -329,18 +326,18 @@ GetPcdTypeString (
static
VOID
DumpPcdInfo (
- IN CONST EFI_GUID *TokenSpace,
- IN UINTN TokenNumber,
- IN EFI_PCD_INFO *PcdInfo
+ IN CONST EFI_GUID *TokenSpace,
+ IN UINTN TokenNumber,
+ IN EFI_PCD_INFO *PcdInfo
)
{
- CHAR16 *RetString;
- UINT8 Uint8;
- UINT16 Uint16;
- UINT32 Uint32;
- UINT64 Uint64;
- BOOLEAN Boolean;
- VOID *PcdData;
+ CHAR16 *RetString;
+ UINT8 Uint8;
+ UINT16 Uint16;
+ UINT32 Uint32;
+ UINT64 Uint64;
+ BOOLEAN Boolean;
+ VOID *PcdData;
RetString = NULL;
@@ -363,6 +360,7 @@ DumpPcdInfo (
} else {
Uint8 = mPiPcd->Get8 (TokenSpace, TokenNumber);
}
+
Print (L" Token = 0x%08x - Type = %H%-17s%N - Size = 0x%x - Value = 0x%x\n", TokenNumber, RetString, PcdInfo->PcdSize, Uint8);
break;
case EFI_PCD_TYPE_16:
@@ -371,6 +369,7 @@ DumpPcdInfo (
} else {
Uint16 = mPiPcd->Get16 (TokenSpace, TokenNumber);
}
+
Print (L" Token = 0x%08x - Type = %H%-17s%N - Size = 0x%x - Value = 0x%x\n", TokenNumber, RetString, PcdInfo->PcdSize, Uint16);
break;
case EFI_PCD_TYPE_32:
@@ -379,6 +378,7 @@ DumpPcdInfo (
} else {
Uint32 = mPiPcd->Get32 (TokenSpace, TokenNumber);
}
+
Print (L" Token = 0x%08x - Type = %H%-17s%N - Size = 0x%x - Value = 0x%x\n", TokenNumber, RetString, PcdInfo->PcdSize, Uint32);
break;
case EFI_PCD_TYPE_64:
@@ -387,6 +387,7 @@ DumpPcdInfo (
} else {
Uint64 = mPiPcd->Get64 (TokenSpace, TokenNumber);
}
+
Print (L" Token = 0x%08x - Type = %H%-17s%N - Size = 0x%x - Value = 0x%lx\n", TokenNumber, RetString, PcdInfo->PcdSize, Uint64);
break;
case EFI_PCD_TYPE_BOOL:
@@ -395,6 +396,7 @@ DumpPcdInfo (
} else {
Boolean = mPiPcd->GetBool (TokenSpace, TokenNumber);
}
+
Print (L" Token = 0x%08x - Type = %H%-17s%N - Size = 0x%x - Value = %a\n", TokenNumber, RetString, PcdInfo->PcdSize, Boolean ? "TRUE" : "FALSE");
break;
case EFI_PCD_TYPE_PTR:
@@ -403,6 +405,7 @@ DumpPcdInfo (
} else {
PcdData = mPiPcd->GetPtr (TokenSpace, TokenNumber);
}
+
Print (L" Token = 0x%08x - Type = %H%-17s%N - Size = 0x%x\n", TokenNumber, RetString, PcdInfo->PcdSize);
DumpHex (2, 0, PcdInfo->PcdSize, PcdData);
break;
@@ -413,6 +416,7 @@ DumpPcdInfo (
if (RetString != NULL) {
FreePool (RetString);
}
+
Print (L"\n");
}
@@ -429,20 +433,20 @@ DumpPcdInfo (
static
EFI_STATUS
ProcessPcd (
- IN CHAR16 *InputPcdName
+ IN CHAR16 *InputPcdName
)
{
- EFI_STATUS Status;
- EFI_GUID *TokenSpace;
- UINTN TokenNumber;
- EFI_PCD_INFO PcdInfo;
- BOOLEAN Found;
- UINTN PcdNameSize;
+ EFI_STATUS Status;
+ EFI_GUID *TokenSpace;
+ UINTN TokenNumber;
+ EFI_PCD_INFO PcdInfo;
+ BOOLEAN Found;
+ UINTN PcdNameSize;
PcdInfo.PcdName = NULL;
PcdInfo.PcdSize = 0;
PcdInfo.PcdType = 0xFF;
- Found = FALSE;
+ Found = FALSE;
Print (L"Current system SKU ID: 0x%x\n\n", mPiPcdInfo->GetSku ());
@@ -451,7 +455,7 @@ ProcessPcd (
TokenNumber = 0;
do {
Status = mPiPcd->GetNextToken (TokenSpace, &TokenNumber);
- if (!EFI_ERROR (Status) && TokenNumber != 0) {
+ if (!EFI_ERROR (Status) && (TokenNumber != 0)) {
if (TokenSpace == NULL) {
//
// PCD in default Token Space.
@@ -460,27 +464,32 @@ ProcessPcd (
} else {
mPiPcdInfo->GetInfo (TokenSpace, TokenNumber, &PcdInfo);
}
+
if (InputPcdName != NULL) {
if (PcdInfo.PcdName == NULL) {
continue;
}
+
PcdNameSize = AsciiStrSize (PcdInfo.PcdName) * sizeof (CHAR16);
if (mTempPcdNameBuffer == NULL) {
mTempPcdNameBufferSize = PcdNameSize;
- mTempPcdNameBuffer = AllocatePool (mTempPcdNameBufferSize);
+ mTempPcdNameBuffer = AllocatePool (mTempPcdNameBufferSize);
} else if (mTempPcdNameBufferSize < PcdNameSize) {
- mTempPcdNameBuffer = ReallocatePool (mTempPcdNameBufferSize, PcdNameSize, mTempPcdNameBuffer);
+ mTempPcdNameBuffer = ReallocatePool (mTempPcdNameBufferSize, PcdNameSize, mTempPcdNameBuffer);
mTempPcdNameBufferSize = PcdNameSize;
}
+
if (mTempPcdNameBuffer == NULL) {
return EFI_OUT_OF_RESOURCES;
}
+
AsciiStrToUnicodeStrS (PcdInfo.PcdName, mTempPcdNameBuffer, mTempPcdNameBufferSize / sizeof (CHAR16));
//
// Compare the input PCD name with the PCD name in PCD database.
//
if ((StrStr (mTempPcdNameBuffer, InputPcdName) != NULL) ||
- (mUnicodeCollation != NULL && mUnicodeCollation->MetaiMatch (mUnicodeCollation, mTempPcdNameBuffer, InputPcdName))) {
+ ((mUnicodeCollation != NULL) && mUnicodeCollation->MetaiMatch (mUnicodeCollation, mTempPcdNameBuffer, InputPcdName)))
+ {
//
// Found matched PCD.
//
@@ -493,7 +502,7 @@ ProcessPcd (
}
} while (!EFI_ERROR (Status) && TokenNumber != 0);
- Status = mPiPcd->GetNextTokenSpace ((CONST EFI_GUID **) &TokenSpace);
+ Status = mPiPcd->GetNextTokenSpace ((CONST EFI_GUID **)&TokenSpace);
} while (!EFI_ERROR (Status) && TokenSpace != NULL);
if ((InputPcdName != NULL) && !Found) {
@@ -503,6 +512,7 @@ ProcessPcd (
Print (L"%EError. %NNo matching PCD found: %s.\n", InputPcdName);
return EFI_NOT_FOUND;
}
+
return EFI_SUCCESS;
}
@@ -526,35 +536,35 @@ DumpDynPcdMain (
IN EFI_SYSTEM_TABLE *SystemTable
)
{
- EFI_STATUS Status;
- CHAR16 *InputPcdName;
+ EFI_STATUS Status;
+ CHAR16 *InputPcdName;
- InputPcdName = NULL;
+ InputPcdName = NULL;
- Status = gBS->LocateProtocol(&gEfiUnicodeCollation2ProtocolGuid, NULL, (VOID **) &mUnicodeCollation);
+ Status = gBS->LocateProtocol (&gEfiUnicodeCollation2ProtocolGuid, NULL, (VOID **)&mUnicodeCollation);
if (EFI_ERROR (Status)) {
mUnicodeCollation = NULL;
}
- Status = gBS->LocateProtocol (&gEfiPcdProtocolGuid, NULL, (VOID **) &mPiPcd);
+ Status = gBS->LocateProtocol (&gEfiPcdProtocolGuid, NULL, (VOID **)&mPiPcd);
if (EFI_ERROR (Status)) {
Print (L"DumpDynPcd: %EError. %NPI PCD protocol is not present.\n");
return Status;
}
- Status = gBS->LocateProtocol (&gEfiGetPcdInfoProtocolGuid, NULL, (VOID **) &mPiPcdInfo);
+ Status = gBS->LocateProtocol (&gEfiGetPcdInfoProtocolGuid, NULL, (VOID **)&mPiPcdInfo);
if (EFI_ERROR (Status)) {
Print (L"DumpDynPcd: %EError. %NPI PCD info protocol is not present.\n");
return Status;
}
- Status = gBS->LocateProtocol (&gPcdProtocolGuid, NULL, (VOID **) &mPcd);
+ Status = gBS->LocateProtocol (&gPcdProtocolGuid, NULL, (VOID **)&mPcd);
if (EFI_ERROR (Status)) {
Print (L"DumpDynPcd: %EError. %NPCD protocol is not present.\n");
return Status;
}
- Status = gBS->LocateProtocol (&gGetPcdInfoProtocolGuid, NULL, (VOID **) &mPcdInfo);
+ Status = gBS->LocateProtocol (&gGetPcdInfoProtocolGuid, NULL, (VOID **)&mPcdInfo);
if (EFI_ERROR (Status)) {
Print (L"DumpDynPcd: %EError. %NPCD info protocol is not present.\n");
return Status;
@@ -563,33 +573,33 @@ DumpDynPcdMain (
//
// get the command line arguments
//
- Status = GetArg();
- if (EFI_ERROR(Status)){
+ Status = GetArg ();
+ if (EFI_ERROR (Status)) {
Print (L"DumpDynPcd: %EError. %NThe input parameters are not recognized.\n");
Status = EFI_INVALID_PARAMETER;
return Status;
}
- if (Argc > 2){
+ if (Argc > 2) {
Print (L"DumpDynPcd: %EError. %NToo many arguments specified.\n");
Status = EFI_INVALID_PARAMETER;
return Status;
}
- if (Argc == 1){
+ if (Argc == 1) {
Status = ProcessPcd (InputPcdName);
goto Done;
}
- if ((StrCmp(Argv[1], L"-?") == 0)||(StrCmp(Argv[1], L"-h") == 0)||(StrCmp(Argv[1], L"-H") == 0)){
+ if ((StrCmp (Argv[1], L"-?") == 0) || (StrCmp (Argv[1], L"-h") == 0) || (StrCmp (Argv[1], L"-H") == 0)) {
ShowHelp ();
goto Done;
} else {
- if ((StrCmp(Argv[1], L"-v") == 0)||(StrCmp(Argv[1], L"-V") == 0)){
+ if ((StrCmp (Argv[1], L"-v") == 0) || (StrCmp (Argv[1], L"-V") == 0)) {
ShowVersion ();
goto Done;
} else {
- if (StrStr(Argv[1], L"-") != NULL){
+ if (StrStr (Argv[1], L"-") != NULL) {
Print (L"DumpDynPcd: %EError. %NThe argument '%B%s%N' is invalid.\n", Argv[1]);
goto Done;
}
@@ -597,9 +607,9 @@ DumpDynPcdMain (
}
InputPcdName = Argv[1];
- Status = ProcessPcd (InputPcdName);
+ Status = ProcessPcd (InputPcdName);
- Done:
+Done:
if (mTempPcdNameBuffer != NULL) {
FreePool (mTempPcdNameBuffer);
@@ -607,4 +617,3 @@ DumpDynPcdMain (
return Status;
}
-