Skip to content
Liming Gao edited this page Apr 28, 2021 · 4 revisions
  1. Define C Structure in C Header file. This structure has bit field, union and flexible array. It defines MACROs. C structure and MACROs can be referred in DEC/DSC for structure PCD.

    Example in Guid/Test.h:
    #define MACRO_A 0xA
    #define MACRO_B 0xB
    typedef struct {
      BOOLEAN  Bool;
      UINT8    A:4;
      UINT8    B:4;
      UINT16   C;
      UINT8    E[10];
      union {
        UINT8   Foo[8];
        UINT64  Bar;
      } Array[0x8];
      UINT8    Guid[16];
      UINT8    FlexibleArray[];
    } TEST;
  2. Define PCD with C structure in DEC. Structure name, header file and the dependency package dec files are required.

    Example in TestPkg.dec:
    [PcdsFixedAtBuild, PcdsPatchableInModule, PcdsDynamic, PcdsDynamicEx]
      gStructuredPcdPkgTokenSpaceGuid.PcdTest|{0x0}|TEST|0x00010080 {
        <HeaderFiles>
          Guid/Test.h
        <Packages>
          MdePkg/MdePkg.dec
          TestPkg/TestPkg.dec
      }
  3. Assign PCD field value in DEC/DSC

    Example in TestPkg.dec or TestPkg.dsc:
    gStructuredPcdPkgTokenSpaceGuid.PcdTest.Bool|TRUE
    gStructuredPcdPkgTokenSpaceGuid.PcdTest.A|MACRO_A
    gStructuredPcdPkgTokenSpaceGuid.PcdTest.C|0xFEDC
    gStructuredPcdPkgTokenSpaceGuid.PcdTest.E|{'&','*'}
    gStructuredPcdPkgTokenSpaceGuid.PcdTest.Guid|{GUID("6F08F62E-5C19-498E-9157-B59CE6F362F1")}
    gStructuredPcdPkgTokenSpaceGuid.PcdTest.Array[1].Foo|"ABC"
    gStructuredPcdPkgTokenSpaceGuid.PcdTest.FlexibleArray|"PcdTest"
  4. Access PCD in module source files

    Module.inf
    [Pcd]
    gStructuredPcdPkgTokenSpaceGuid.PcdTest
    Module.c
    #include <Guid/Test.h>
    VOID Test () {
      TEST *TestBuffer;
      TestBuffer = (TEST *) PcdGetPtr (PcdTest);
      TestBuffer->A = 5;
      TestBuffer->Array[0].Bar = 0xE0000000;
      ZeroMem (TestBuffer->E, sizeof (TestBuffer->E));
      AsciiStrnCpyS (TestBuffer->E, sizeof (TestBuffer->E), “Test”, 5);
      PcdSetPtrS (PcdTest, PcdGetSize (PcdTest), TestBuffer);
    }
Clone this wiki locally