Acidanthera UEFI Development Kit based on EDK II edk2-stable202311
Go to file
Michael Kinney fd0597aa9c BaseTools/Scripts: Add BinToPcd utility
https://bugzilla.tianocore.org/show_bug.cgi?id=228

Add a utility that converts a binary file into a VOID* PCD value
or a full DSC file VOID* PCD statement with support for all the
DSC supported PCD sections.

usage: BinToPcd [-h] [--version] -i INPUTFILE [-o OUTPUTFILE] [-p PCDNAME]
                [-t {VPD,HII}] [-m MAXSIZE] [-f OFFSET] [-n VARIABLENAME]
                [-g VARIABLEGUID] [-v] [-q] [--debug [0-9]]

Convert a binary file to a VOID* PCD value or DSC file VOID* PCD statement.
Copyright (c) 2016, Intel Corporation. All rights reserved.

optional arguments:
  -h, --help        show this help message and exit
  --version         show program's version number and exit
  -i INPUTFILE, --input INPUTFILE
                    Input binary filename
  -o OUTPUTFILE, --output OUTPUTFILE
                    Output filename for PCD value or PCD statement
  -p PCDNAME, --pcd PCDNAME
                    Name of the PCD in the form
                    <PcdTokenSpaceGuidCName>.<PcdCName>
  -t {VPD,HII}, --type {VPD,HII}
                    PCD statement type (HII or VPD). Default is standard.
  -m MAXSIZE, --max-size MAXSIZE
                    Maximum size of the PCD. Ignored with --type HII.
  -f OFFSET, --offset OFFSET
                    VPD offset if --type is VPD. UEFI Variable offset if
                    --type is HII.
  -n VARIABLENAME, --variable-name VARIABLENAME
                    UEFI variable name. Only used with --type HII.
  -g VARIABLEGUID, --variable-guid VARIABLEGUID
                    UEFI variable GUID C name. Only used with --type HII.
  -v, --verbose     Increase output messages
  -q, --quiet       Reduce output messages
  --debug [0-9]     Set debug level

This utility can be used in PCD value mode to convert a binary
file into a string that can then be copied into the PCD value field
of a VOID* PCD.  The following is an example of PCD value mode on
an 8 byte test.bin file.

  BinToPcd.py -i test.bin

  {0x48, 0x65, 0x6c, 0x6c, 0x6f, 0x20, 0x0d, 0x0a}

The DSC file VOID* PCD statement mode can be used to generate a
complete PCD statement for the PCD section types that a DSC file
supports:

  [PcdsFixedAtBuild]
  [PcdsPatchableInModule]
  [PcdsDynamicDefault]
  [PcdsDynamicExDefault]
  [PcdsDynamicVpd]
  [PcdsDynamicExVpd]
  [PcdsDynamicHii]
  [PcdsDynamicExHii]

The PCD statement mode is useful when combined with a !include
statement in a DSC file.  BinToPcd.py can be used to convert a
binary file to a PCD statement in an output file, and that output
file can be included into a DSC file in the matching PCD section
to set the value of the PCD to the value from the binary file
without having to copy the value into the DSC file.  Updates can be
made to the included file without editing the DSC file.  Some
example use cases are the setting the public key PCDs such as:

  gEfiSecurityPkgTokenSpaceGuid.PcdRsa2048Sha256PublicKeyBuffer
  gEfiSecurityPkgTokenSpaceGuid.PcdPkcs7CertBuffer

The following example converts a public key binary file to a
[PcdsFixedAtBuild] compatible PCD statement:

  BinToPcd.py -i PublicKey.bin -o PublicKey.pcd
    --pcd gEfiSecurityPkgTokenSpaceGuid.PcdPkcs7CertBufferkenSpaceGuid

The PublicKey.pcd output file contains a single line:

  gEfiSecurityPkgTokenSpaceGuid.PcdPkcs7CertBuffer|{0x48, ...}

A DSC file can be updated to include the PublicKey.pcd file:

  [PcdsFixedAtBuild]
  !include PublicKey.pcd

Value examples
===============
  BinToPcd.py -i test.bin
    {0x68, 0x65, 0x6c, 0x6c, 0x6f, 0x20, 0x0d, 0x0a}

Normal examples:
=================
  BinToPcd.py -i test.bin -p Guid.Token
    Guid.Token|{0x68, 0x65, 0x6c, 0x6c, 0x6f, 0x20, 0x0d, 0x0a}

  BinToPcd.py -i test.bin -p Guid.Token -m 20
    Guid.Token|{0x68, 0x65, 0x6c, 0x6c, 0x6f, 0x20, 0x0d, 0x0a}|VOID*|20

VPD examples:
=============
  BinToPcd.py -i test.bin -p Guid.Token -t VPD
    Guid.Name|*|8|{0x48, 0x65, 0x6c, 0x6c, 0x6f, 0x20, 0x0d, 0x0a}

  BinToPcd.py -i test.bin -p Guid.Token -t VPD -f 20
    Guid.Name|20|8|{0x48, 0x65, 0x6c, 0x6c, 0x6f, 0x20, 0x0d, 0x0a}

  BinToPcd.py -i test.bin -p Guid.Token -t VPD -m 10
    Guid.Name|*|10|{0x48, 0x65, 0x6c, 0x6c, 0x6f, 0x20, 0x0d, 0x0a}

  BinToPcd.py -i test.bin -p Guid.Token -t VPD -f 20 -m 10
    Guid.Name|20|10|{0x48, 0x65, 0x6c, 0x6c, 0x6f, 0x20, 0x0d, 0x0a}

HII examples:
=============
  BinToPcd.py -i test.bin -p Guid.Token -t HII -g VarGuid -n VarName
    Guid.Name|L"VarName"|VarGuid|0|{0x48, 0x65, 0x6c, 0x6c}

  BinToPcd.py -i test.bin -p Guid.Token -t HII -g VarGuid -n VarName -f 8
    Guid.Name|L"VarName"|VarGuid|8|{0x48, 0x65, 0x6c, 0x6c}

Cc: Yonghong Zhu <yonghong.zhu@intel.com>
Cc: Liming Gao <liming.gao@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Michael Kinney <michael.d.kinney@intel.com>
Reviewed-by: Liming Gao <liming.gao@intel.com>
Reviewed-by: Yonghong Zhu <yonghong.zhu@intel.com>
2016-11-14 08:40:41 -08:00
AppPkg AppPkg: Update email and URL. 2016-10-26 09:34:34 -07:00
ArmPkg ArmPkg/CpuDxe: set DmaBufferAlignment according to CWG 2016-11-02 16:22:48 +00:00
ArmPlatformPkg ArmPlatformPkg/ArmVExpressFastBootDxe: eliminate deprecated string functions 2016-10-28 16:26:50 +01:00
ArmVirtPkg ArmVirPkg/PlatformBds: Dispatch deferred images after EndOfDxe 2016-11-10 15:58:04 +08:00
BaseTools BaseTools/Scripts: Add BinToPcd utility 2016-11-14 08:40:41 -08:00
BeagleBoardPkg BeagleBoardPkg: enable -DDISABLE_NEW_DEPRECATED_INTERFACES 2016-10-28 15:55:53 +01:00
Conf
CorebootModulePkg CorebootModulePkgPkg: Expose FindCbTag API from CbParseLib 2016-10-27 09:51:16 -07:00
CorebootPayloadPkg CorebootPayload/PlatformBds: Dispatch deferred images after EndOfDxe 2016-11-10 15:58:31 +08:00
CryptoPkg CryptoPkg/BaseCryptLib: Make comments consistent with the function 2016-11-11 13:46:04 +08:00
DuetPkg DuetPkg: Add POSTBUILD in DSC files to run post-build automatically 2016-11-14 19:33:11 +08:00
EdkCompatibilityPkg EdkCompatibilityPkg/PrintLite: Fix ErrorPrint() wrong NULL char check 2016-11-03 10:28:47 +08:00
EdkShellBinPkg
EdkShellPkg
EmbeddedPkg EmbeddedPkg: MmcDxe: add SPEC_VERS field in CSD structure 2016-11-14 15:45:49 +00:00
EmulatorPkg EmulatorPkg: Fix typos in comments and variables 2016-10-19 13:32:20 -07:00
FatBinPkg FatBinPkg: Change to 2-clause BSD license 2016-04-22 00:55:21 -07:00
FatPkg FatPkg/EnhancedFatDxe: rebase to ARRAY_SIZE() 2016-10-27 11:10:54 +02:00
IntelFrameworkModulePkg IntelFrameworkModulePkg/LegacyBios: Fix legacy serial redirection bug 2016-11-10 10:19:54 +08:00
IntelFrameworkPkg IntelFrameworkPkg: Fix typos in comments 2016-10-24 09:09:26 +08:00
IntelFsp2Pkg IntelFsp2Pkg: Support to return error status from FSP API done 2016-11-14 12:11:05 +08:00
IntelFsp2WrapperPkg IntelFsp2WrapperPkg: Add a PCD to control if signaling PciEnumerationComplete. 2016-10-28 07:46:42 +08:00
IntelFspPkg IntelFspPkg: Fix typos in comments 2016-10-24 09:26:28 +08:00
IntelFspWrapperPkg IntelFspWrapperPkg: Fix typos in comments 2016-10-24 09:26:30 +08:00
IntelSiliconPkg IntelSiliconPkg: Add SMBIOS data HOB GUID 2016-11-01 20:14:09 +08:00
MdeModulePkg MdeModulePkg/UsbMass: Revert changes of removing retry logic 2016-11-14 14:10:30 +08:00
MdePkg MdePkg: Fix spec mismatch in string representation of EMMC dev node 2016-11-14 11:08:41 +08:00
NetworkPkg NetworkPkg: Check for NULL pointer before dereference it. 2016-10-31 16:04:02 +08:00
Nt32Pkg Nt32Pkg/PlatformBds: Dispatch deferred images after EndOfDxe 2016-11-10 15:58:38 +08:00
Omap35xxPkg EmbeddedPkg: remove unused PrePiHobListPointerLib 2016-10-28 13:51:35 +01:00
OptionRomPkg OptionRomPkg/AtapiPassThruDxe: rebase to ARRAY_SIZE() 2016-10-27 11:10:58 +02:00
OvmfPkg OvmfPkg/PlatformBds: Dispatch deferred images after EndOfDxe 2016-11-10 15:58:27 +08:00
PcAtChipsetPkg PcAtChipsetPkg/HpetTimerDxe: Fix race condition in SetTimerPeriod() 2016-10-27 21:46:42 -07:00
PerformancePkg PerformancePkg/Dp_App: rebase to ARRAY_SIZE() 2016-10-27 11:10:59 +02:00
QuarkPlatformPkg QuarkPlatformPkg/PlatformBds: Dispatch deferred images after EndOfDxe 2016-11-10 15:58:35 +08:00
QuarkSocPkg QuarkSocPkg/Library: Remove extra UefiBaseType.h includes 2016-10-27 21:32:46 -07:00
SecurityPkg SecurityPkg/SecurityPkg.dsc: Add FmpAuthenticationLib*. 2016-11-08 22:37:19 +08:00
ShellBinPkg ShellBinPkg Arm/AArch64 Shell binary update 2016-08-02 12:25:13 +02:00
ShellPkg ShellPkg/ShellCommandLib: Add missing EFIAPI for public library APIs 2016-11-11 10:59:39 +08:00
SignedCapsulePkg SignedCapsulePkg/CapsulePkg.dsc: Add capsule related component. 2016-11-11 15:28:11 +08:00
SourceLevelDebugPkg SourceLevelDebugPkg: Fix typos in comments 2016-10-24 09:10:15 +08:00
StdLib StdLib/LibC ARM AARCH64: do not redefine compiler intrinsics 2016-08-09 10:10:12 +02:00
StdLibPrivateInternalFiles
UefiCpuPkg UefiCpuPkg/DxeMpLib: Place APs to suitable state on Legacy OS boot 2016-11-14 09:56:59 +08:00
UnixPkg
Vlv2DeviceRefCodePkg Vlv2DeviceRefCodePkg/ValleyView2Soc: Remove the unused code 2016-08-03 11:02:19 +08:00
Vlv2TbltDevicePkg Vlv2TbltDevicePkg/Build: Add capsule/recovery in help info. 2016-11-08 22:49:57 +08:00
.gitignore
BuildNotes2.txt BaseTools: Updated BuildNotes URLs 2016-03-25 09:46:44 +08:00
Edk2Setup.bat Edk2Setup.bat: Fix build errors from VS tools PREFIX ENV missing 2016-11-05 09:10:58 +08:00
Maintainers.txt Maintainers.txt: Change maintainer of VLV2 packages. 2016-10-27 21:08:23 +08:00
edksetup.bat edksetup.bat: make sure BASE_TOOLS_PATH be set correctly 2016-10-26 13:45:45 +08:00
edksetup.sh edksetup.sh, BaseTools/BuildEnv: add --reconfig support 2016-10-24 13:53:16 +01:00