35#define MAJOR_VERSION 1
36#define MINOR_VERSION 0
43static CHAR16 *mTempPcdNameBuffer =
NULL;
44static UINTN mTempPcdNameBufferSize = 0;
46static CONST CHAR8 mHex[] = {
'0',
'1',
'2',
'3',
'4',
'5',
'6',
'7',
'8',
'9',
'A',
'B',
'C',
'D',
'E',
'F' };
66 Status =
gBS->HandleProtocol (
68 &gEfiShellParametersProtocolGuid,
69 (VOID **)&ShellParameters
71 if (EFI_ERROR (Status)) {
75 Argc = ShellParameters->Argc;
76 Argv = ShellParameters->Argv;
88 Print (L
"DumpDynPcd Version %d.%02d\n", MAJOR_VERSION, MINOR_VERSION);
99 Print (L
"Dump dynamic[ex] PCD info.\n");
101 Print (L
"DumpDynPcd [PcdName]\n");
103 Print (L
" PcdName Specifies the name of PCD.\n");
104 Print (L
" A literal[or partial] name or a pattern as specified in\n");
105 Print (L
" the MetaiMatch() function of the EFI_UNICODE_COLLATION2_PROCOOL.\n");
106 Print (L
" If it is absent, dump all PCDs' info.\n");
107 Print (L
"The PCD data is printed as hexadecimal dump.\n");
138 while (DataSize != 0) {
140 if (Size > DataSize) {
144 for (Index = 0; Index < Size; Index += 1) {
145 TempByte = Data[Index];
146 Val[Index * 3 + 0] = mHex[TempByte >> 4];
147 Val[Index * 3 + 1] = mHex[TempByte & 0xF];
148 Val[Index * 3 + 2] = (CHAR8)((Index == 7) ?
'-' :
' ');
149 Str[Index] = (CHAR8)((TempByte <
' ' || TempByte >
'z') ?
'.' : TempByte);
154 Print (L
"%*a%08X: %-48a *%a*\r\n", Indent,
"", Offset, Val, Str);
195 IN OUT CHAR16 **Destination,
200 UINTN DestinationStartSize;
204 SourceLen =
StrLen (Source);
209 ASSERT (Destination !=
NULL);
214 if (Source ==
NULL) {
215 return (*Destination);
221 if ((CurrentSize !=
NULL) && (*CurrentSize == 0)) {
228 if (*Destination !=
NULL) {
229 ASSERT (CurrentSize != 0);
230 DestinationStartSize =
StrSize (*Destination);
231 ASSERT (DestinationStartSize <= *CurrentSize);
233 DestinationStartSize = 0;
239 if (CurrentSize !=
NULL) {
240 NewSize = *CurrentSize;
241 if (NewSize < DestinationStartSize + (SourceLen *
sizeof (CHAR16))) {
242 while (NewSize < (DestinationStartSize + (SourceLen*
sizeof (CHAR16)))) {
243 NewSize += 2 * SourceLen *
sizeof (CHAR16);
246 *Destination =
ReallocatePool (*CurrentSize, NewSize, *Destination);
247 *CurrentSize = NewSize;
250 NewSize = (SourceLen + 1)*
sizeof (CHAR16);
257 if (*Destination ==
NULL) {
261 StrnCatS (*Destination, NewSize/
sizeof (CHAR16), Source, SourceLen);
277 IN EFI_PCD_TYPE PcdType
288 InternalStrnCatGrow (&RetString, &BufLen, L
"UINT8");
290 case EFI_PCD_TYPE_16:
291 InternalStrnCatGrow (&RetString, &BufLen, L
"UINT16");
293 case EFI_PCD_TYPE_32:
294 InternalStrnCatGrow (&RetString, &BufLen, L
"UINT32");
296 case EFI_PCD_TYPE_64:
297 InternalStrnCatGrow (&RetString, &BufLen, L
"UINT64");
299 case EFI_PCD_TYPE_BOOL:
300 InternalStrnCatGrow (&RetString, &BufLen, L
"BOOLEAN");
302 case EFI_PCD_TYPE_PTR:
303 InternalStrnCatGrow (&RetString, &BufLen, L
"POINTER");
306 InternalStrnCatGrow (&RetString, &BufLen, L
"UNKNOWN");
310 if (TokenSpace ==
NULL) {
311 InternalStrnCatGrow (&RetString, &BufLen, L
":DYNAMIC");
313 InternalStrnCatGrow (&RetString, &BufLen, L
":DYNAMICEX");
344 if (PcdInfo->PcdName !=
NULL) {
345 Print (L
"%a\n", PcdInfo->PcdName);
347 if (TokenSpace ==
NULL) {
348 Print (L
"Default Token Space\n");
350 Print (L
"%g\n", TokenSpace);
354 RetString = GetPcdTypeString (TokenSpace, PcdInfo->PcdType);
356 switch (PcdInfo->PcdType) {
358 if (TokenSpace ==
NULL) {
359 Uint8 = mPcd->Get8 (TokenNumber);
361 Uint8 = mPiPcd->Get8 (TokenSpace, TokenNumber);
364 Print (L
" Token = 0x%08x - Type = %-17s - Size = 0x%x - Value = 0x%x\n", TokenNumber, RetString, PcdInfo->PcdSize, Uint8);
366 case EFI_PCD_TYPE_16:
367 if (TokenSpace ==
NULL) {
368 Uint16 = mPcd->Get16 (TokenNumber);
370 Uint16 = mPiPcd->Get16 (TokenSpace, TokenNumber);
373 Print (L
" Token = 0x%08x - Type = %-17s - Size = 0x%x - Value = 0x%x\n", TokenNumber, RetString, PcdInfo->PcdSize, Uint16);
375 case EFI_PCD_TYPE_32:
376 if (TokenSpace ==
NULL) {
377 Uint32 = mPcd->Get32 (TokenNumber);
379 Uint32 = mPiPcd->Get32 (TokenSpace, TokenNumber);
382 Print (L
" Token = 0x%08x - Type = %-17s - Size = 0x%x - Value = 0x%x\n", TokenNumber, RetString, PcdInfo->PcdSize, Uint32);
384 case EFI_PCD_TYPE_64:
385 if (TokenSpace ==
NULL) {
386 Uint64 = mPcd->Get64 (TokenNumber);
388 Uint64 = mPiPcd->Get64 (TokenSpace, TokenNumber);
391 Print (L
" Token = 0x%08x - Type = %-17s - Size = 0x%x - Value = 0x%lx\n", TokenNumber, RetString, PcdInfo->PcdSize, Uint64);
393 case EFI_PCD_TYPE_BOOL:
394 if (TokenSpace ==
NULL) {
395 Boolean = mPcd->GetBool (TokenNumber);
397 Boolean = mPiPcd->GetBool (TokenSpace, TokenNumber);
400 Print (L
" Token = 0x%08x - Type = %-17s - Size = 0x%x - Value = %a\n", TokenNumber, RetString, PcdInfo->PcdSize, Boolean ?
"TRUE" :
"FALSE");
402 case EFI_PCD_TYPE_PTR:
403 if (TokenSpace ==
NULL) {
404 PcdData = mPcd->GetPtr (TokenNumber);
406 PcdData = mPiPcd->GetPtr (TokenSpace, TokenNumber);
409 Print (L
" Token = 0x%08x - Type = %-17s - Size = 0x%x\n", TokenNumber, RetString, PcdInfo->PcdSize);
410 DumpHex (2, 0, PcdInfo->PcdSize, PcdData);
416 if (RetString !=
NULL) {
436 IN CHAR16 *InputPcdName
451 Print (L
"Current system SKU ID: 0x%x\n\n", mPiPcdInfo->
GetSku ());
457 Status = mPiPcd->GetNextToken (TokenSpace, &TokenNumber);
458 if (!EFI_ERROR (Status) && (TokenNumber != 0)) {
459 if (TokenSpace ==
NULL) {
463 mPcdInfo->
GetInfo (TokenNumber, &PcdInfo);
465 mPiPcdInfo->
GetInfo (TokenSpace, TokenNumber, &PcdInfo);
468 if (InputPcdName !=
NULL) {
474 if (mTempPcdNameBuffer ==
NULL) {
475 mTempPcdNameBufferSize = PcdNameSize;
476 mTempPcdNameBuffer =
AllocatePool (mTempPcdNameBufferSize);
477 }
else if (mTempPcdNameBufferSize < PcdNameSize) {
478 mTempPcdNameBuffer =
ReallocatePool (mTempPcdNameBufferSize, PcdNameSize, mTempPcdNameBuffer);
479 mTempPcdNameBufferSize = PcdNameSize;
482 if (mTempPcdNameBuffer ==
NULL) {
483 return EFI_OUT_OF_RESOURCES;
490 if ((
StrStr (mTempPcdNameBuffer, InputPcdName) !=
NULL) ||
491 ((mUnicodeCollation !=
NULL) && mUnicodeCollation->MetaiMatch (mUnicodeCollation, mTempPcdNameBuffer, InputPcdName)))
496 DumpPcdInfo (TokenSpace, TokenNumber, &PcdInfo);
500 DumpPcdInfo (TokenSpace, TokenNumber, &PcdInfo);
503 }
while (!EFI_ERROR (Status) && TokenNumber != 0);
505 Status = mPiPcd->GetNextTokenSpace ((
CONST EFI_GUID **)&TokenSpace);
506 }
while (!EFI_ERROR (Status) && TokenSpace !=
NULL);
508 if ((InputPcdName !=
NULL) && !Found) {
512 Print (L
"Error. No matching PCD found: %s.\n", InputPcdName);
513 return EFI_NOT_FOUND;
540 CHAR16 *InputPcdName;
544 Status =
gBS->LocateProtocol (&gEfiUnicodeCollation2ProtocolGuid,
NULL, (VOID **)&mUnicodeCollation);
545 if (EFI_ERROR (Status)) {
546 mUnicodeCollation =
NULL;
549 Status =
gBS->LocateProtocol (&gEfiPcdProtocolGuid,
NULL, (VOID **)&mPiPcd);
550 if (EFI_ERROR (Status)) {
551 Print (L
"DumpDynPcd: Error. PI PCD protocol is not present.\n");
555 Status =
gBS->LocateProtocol (&gEfiGetPcdInfoProtocolGuid,
NULL, (VOID **)&mPiPcdInfo);
556 if (EFI_ERROR (Status)) {
557 Print (L
"DumpDynPcd: Error. PI PCD info protocol is not present.\n");
561 Status =
gBS->LocateProtocol (&gPcdProtocolGuid,
NULL, (VOID **)&mPcd);
562 if (EFI_ERROR (Status)) {
563 Print (L
"DumpDynPcd: Error. PCD protocol is not present.\n");
567 Status =
gBS->LocateProtocol (&gGetPcdInfoProtocolGuid,
NULL, (VOID **)&mPcdInfo);
568 if (EFI_ERROR (Status)) {
569 Print (L
"DumpDynPcd: Error. PCD info protocol is not present.\n");
577 if (EFI_ERROR (Status)) {
578 Print (L
"DumpDynPcd: Error. The input parameters are not recognized.\n");
579 Status = EFI_INVALID_PARAMETER;
584 Print (L
"DumpDynPcd: Error. Too many arguments specified.\n");
585 Status = EFI_INVALID_PARAMETER;
590 Status = ProcessPcd (InputPcdName);
594 if ((
StrCmp (Argv[1], L
"-?") == 0) || (
StrCmp (Argv[1], L
"-h") == 0) || (
StrCmp (Argv[1], L
"-H") == 0)) {
598 if ((
StrCmp (Argv[1], L
"-v") == 0) || (
StrCmp (Argv[1], L
"-V") == 0)) {
603 Print (L
"DumpDynPcd: Error. The argument '%s' is invalid.\n", Argv[1]);
609 InputPcdName = Argv[1];
610 Status = ProcessPcd (InputPcdName);
614 if (mTempPcdNameBuffer !=
NULL) {
UINTN EFIAPI StrSize(IN CONST CHAR16 *String)
INTN EFIAPI StrCmp(IN CONST CHAR16 *FirstString, IN CONST CHAR16 *SecondString)
RETURN_STATUS EFIAPI StrnCatS(IN OUT CHAR16 *Destination, IN UINTN DestMax, IN CONST CHAR16 *Source, IN UINTN Length)
RETURN_STATUS EFIAPI AsciiStrToUnicodeStrS(IN CONST CHAR8 *Source, OUT CHAR16 *Destination, IN UINTN DestMax)
UINTN EFIAPI AsciiStrSize(IN CONST CHAR8 *String)
UINTN EFIAPI StrLen(IN CONST CHAR16 *String)
CHAR16 *EFIAPI StrStr(IN CONST CHAR16 *String, IN CONST CHAR16 *SearchString)
EFI_STATUS EFIAPI DumpDynPcdMain(IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable)
VOID *EFIAPI ReallocatePool(IN UINTN OldSize, IN UINTN NewSize, IN VOID *OldBuffer OPTIONAL)
VOID *EFIAPI AllocateZeroPool(IN UINTN AllocationSize)
VOID EFIAPI FreePool(IN VOID *Buffer)
#define GLOBAL_REMOVE_IF_UNREFERENCED
VOID *EFIAPI AllocatePool(IN UINTN AllocationSize)
UINTN EFIAPI Print(IN CONST CHAR16 *Format,...)
EFI_GET_PCD_INFO_PROTOCOL_GET_SKU GetSku
EFI_GET_PCD_INFO_PROTOCOL_GET_INFO GetInfo
GET_PCD_INFO_PROTOCOL_GET_INFO GetInfo