Token values are not produced for PCDs under 'PcdsDynamic' section


Konstantin Aladyshev <aladyshev22@...>
 

Hello!

I'm trying to understand dynamic PCDs in EDK2.

I've added this code to my package DEC file:
```
[PcdsDynamic]
  gMyPkgTokenSpaceGuid.PcdMyDynamicVar32|42|UINT32|0x00000004
```
And have added this code to my app INF file:
```
[Pcd]
  gMyPkgTokenSpaceGuid.PcdMyDynamicVar32
```

I'm trying to use PCD in my application like this:
```
Print(L"PcdMyDynamicVar32=%d\n", PcdGet32(PcdMyDynamicVar32));
PcdSet32S(PcdMyDynamicVar32, 52);
Print(L"PcdMyDynamicVar32=%d\n", PcdGet32(PcdMyDynamicVar32));
```

But when I try to compile, the token number is not populated to the AutoGen.h:
```
#define _PCD_TOKEN_PcdMyDynamicVar32  0U
#define _PCD_GET_MODE_32_PcdMyDynamicVar32  LibPcdGet32(_PCD_TOKEN_PcdMyDynamicVar32)
#define _PCD_GET_MODE_SIZE_PcdMyDynamicVar32  LibPcdGetSize(_PCD_TOKEN_PcdMyDynamicVar32)
#define _PCD_SET_MODE_32_PcdMyDynamicVar32(Value)  LibPcdSet32(_PCD_TOKEN_PcdMyDynamicVar32, (Value))
#define _PCD_SET_MODE_32_S_PcdMyDynamicVar32(Value)  LibPcdSet32S(_PCD_TOKEN_PcdMyDynamicVar32, (Value))
```
Because of that I get 0 in the first `PcdGet32` call and my application freezes at the `PcdSet32S` call.


But if I change `[PcdsDynamic]` to [PcdsDynamicEx] in my package DEC file token value will be populated:
```
#define _PCD_TOKEN_gMyPkgTokenSpaceGuid_PcdMyDynamicVar32  1073741828U
#define _PCD_TOKEN_PcdMyDynamicVar32  _PCD_TOKEN_gMyPkgTokenSpaceGuid_PcdMyDynamicVar32
#define _PCD_GET_MODE_32_PcdMyDynamicVar32  LibPcdGetEx32(&gMyPkgTokenSpaceGuid, _PCD_TOKEN_PcdMyDynamicVar32)
#define _PCD_GET_MODE_SIZE_PcdMyDynamicVar32 LibPcdGetExSize(&gMyPkgTokenSpaceGuid, _PCD_TOKEN_PcdMyDynamicVar32)
#define _PCD_SET_MODE_32_PcdMyDynamicVar32(Value)  LibPcdSetEx32(&gMyPkgTokenSpaceGuid, _PCD_TOKEN_PcdMyDynamicVar32, (Value))
#define _PCD_SET_MODE_32_S_PcdMyDynamicVar32(Value)  LibPcdSetEx32S(&gMyPkgTokenSpaceGuid, _PCD_TOKEN_PcdMyDynamicVar32, (Value))
```

What is my mistake? Why is the token value not populated when `[PcdsDynamic]` is used?


Best regards,
Konstantin Aladyshev


Guomin Jiang
 

Hi

This should be compiled into PCD PEIMs and PCD DXE Drivers.

It will be contained by firmware eventually.

It seem that you haven’t changed the firmware, so the firmware can’t get the value and freeze.

Thanks
From: discuss@edk2.groups.io <discuss@edk2.groups.io> On Behalf Of Konstantin Aladyshev
Sent: Tuesday, June 29, 2021 1:00 AM
To: discuss@edk2.groups.io
Subject: [edk2-discuss] Token values are not produced for PCDs under 'PcdsDynamic' section

Hello!

I'm trying to understand dynamic PCDs in EDK2.

I've added this code to my package DEC file:
```
[PcdsDynamic]
gMyPkgTokenSpaceGuid.PcdMyDynamicVar32|42|UINT32|0x00000004
```
And have added this code to my app INF file:
```
[Pcd]
gMyPkgTokenSpaceGuid.PcdMyDynamicVar32
```

I'm trying to use PCD in my application like this:
```
Print(L"PcdMyDynamicVar32=%d\n", PcdGet32(PcdMyDynamicVar32));
PcdSet32S(PcdMyDynamicVar32, 52);
Print(L"PcdMyDynamicVar32=%d\n", PcdGet32(PcdMyDynamicVar32));
```

But when I try to compile, the token number is not populated to the AutoGen.h:
```
#define _PCD_TOKEN_PcdMyDynamicVar32 0U
#define _PCD_GET_MODE_32_PcdMyDynamicVar32 LibPcdGet32(_PCD_TOKEN_PcdMyDynamicVar32)
#define _PCD_GET_MODE_SIZE_PcdMyDynamicVar32 LibPcdGetSize(_PCD_TOKEN_PcdMyDynamicVar32)
#define _PCD_SET_MODE_32_PcdMyDynamicVar32(Value) LibPcdSet32(_PCD_TOKEN_PcdMyDynamicVar32, (Value))
#define _PCD_SET_MODE_32_S_PcdMyDynamicVar32(Value) LibPcdSet32S(_PCD_TOKEN_PcdMyDynamicVar32, (Value))
```
Because of that I get 0 in the first `PcdGet32` call and my application freezes at the `PcdSet32S` call.


But if I change `[PcdsDynamic]` to [PcdsDynamicEx] in my package DEC file token value will be populated:
```
#define _PCD_TOKEN_gMyPkgTokenSpaceGuid_PcdMyDynamicVar32 1073741828U
#define _PCD_TOKEN_PcdMyDynamicVar32 _PCD_TOKEN_gMyPkgTokenSpaceGuid_PcdMyDynamicVar32
#define _PCD_GET_MODE_32_PcdMyDynamicVar32 LibPcdGetEx32(&gMyPkgTokenSpaceGuid, _PCD_TOKEN_PcdMyDynamicVar32)
#define _PCD_GET_MODE_SIZE_PcdMyDynamicVar32 LibPcdGetExSize(&gMyPkgTokenSpaceGuid, _PCD_TOKEN_PcdMyDynamicVar32)
#define _PCD_SET_MODE_32_PcdMyDynamicVar32(Value) LibPcdSetEx32(&gMyPkgTokenSpaceGuid, _PCD_TOKEN_PcdMyDynamicVar32, (Value))
#define _PCD_SET_MODE_32_S_PcdMyDynamicVar32(Value) LibPcdSetEx32S(&gMyPkgTokenSpaceGuid, _PCD_TOKEN_PcdMyDynamicVar32, (Value))
```

What is my mistake? Why is the token value not populated when `[PcdsDynamic]` is used?


Best regards,
Konstantin Aladyshev


Guomin Jiang
 

You need add your PCD into OVMF and make sure the OVMF.fd include it.

You can check the code in MdeModulePkg\Universal\PCD\Dxe\Service.c for detail.

-----Original Message-----
From: Konstantin Aladyshev <aladyshev22@gmail.com>
Sent: Tuesday, June 29, 2021 5:47 PM
To: Jiang, Guomin <guomin.jiang@intel.com>
Cc: discuss@edk2.groups.io
Subject: Re: [edk2-discuss] Token values are not produced for PCDs under
'PcdsDynamic' section

Sorry, I didn't understand your answer. Could you please elaborate it for me.

I'm trying to write `UEFI_APPLICATION` and test its execution in UEFI Shell in
QEMU running OVMF.
I also use `DxePcdLib` as PcdLib in my package DSC file:
```
[LibraryClasses]
...
PcdLib|MdePkg/Library/DxePcdLib/DxePcdLib.inf
```
In this library LibPcdGet32 is translate to:
```
UINT32
EFIAPI
LibPcdGet32 (
IN UINTN TokenNumber
)
{
return GetPcdProtocol()->Get32 (TokenNumber); } ``` So the correct
`TokenNumber` should be passed for this to work correctly.

But as I said Token for my variable is set to 0 for some reason in AutoGen.h:
```
#define _PCD_TOKEN_PcdMyDynamicVar32 0U ```

On Tue, Jun 29, 2021 at 12:25 PM Jiang, Guomin <guomin.jiang@intel.com>
wrote:

Hi



This should be compiled into PCD PEIMs and PCD DXE Drivers.



It will be contained by firmware eventually.



It seem that you haven’t changed the firmware, so the firmware can’t get
the value and freeze.



Thanks

From: discuss@edk2.groups.io <discuss@edk2.groups.io> On Behalf Of
Konstantin Aladyshev
Sent: Tuesday, June 29, 2021 1:00 AM
To: discuss@edk2.groups.io
Subject: [edk2-discuss] Token values are not produced for PCDs under
'PcdsDynamic' section



Hello!



I'm trying to understand dynamic PCDs in EDK2.



I've added this code to my package DEC file:

```

[PcdsDynamic]
gMyPkgTokenSpaceGuid.PcdMyDynamicVar32|42|UINT32|0x00000004

```

And have added this code to my app INF file:

```

[Pcd]
gMyPkgTokenSpaceGuid.PcdMyDynamicVar32

```



I'm trying to use PCD in my application like this:

```
Print(L"PcdMyDynamicVar32=%d\n", PcdGet32(PcdMyDynamicVar32));
PcdSet32S(PcdMyDynamicVar32, 52); Print(L"PcdMyDynamicVar32=%d\n",
PcdGet32(PcdMyDynamicVar32));

```



But when I try to compile, the token number is not populated to the
AutoGen.h:

```

#define _PCD_TOKEN_PcdMyDynamicVar32 0U #define
_PCD_GET_MODE_32_PcdMyDynamicVar32
LibPcdGet32(_PCD_TOKEN_PcdMyDynamicVar32)
#define _PCD_GET_MODE_SIZE_PcdMyDynamicVar32
LibPcdGetSize(_PCD_TOKEN_PcdMyDynamicVar32)
#define _PCD_SET_MODE_32_PcdMyDynamicVar32(Value)
LibPcdSet32(_PCD_TOKEN_PcdMyDynamicVar32, (Value)) #define
_PCD_SET_MODE_32_S_PcdMyDynamicVar32(Value)
LibPcdSet32S(_PCD_TOKEN_PcdMyDynamicVar32, (Value))

```

Because of that I get 0 in the first `PcdGet32` call and my application freezes
at the `PcdSet32S` call.





But if I change `[PcdsDynamic]` to [PcdsDynamicEx] in my package DEC file
token value will be populated:

```

#define _PCD_TOKEN_gMyPkgTokenSpaceGuid_PcdMyDynamicVar32
1073741828U
#define _PCD_TOKEN_PcdMyDynamicVar32
_PCD_TOKEN_gMyPkgTokenSpaceGuid_PcdMyDynamicVar32
#define _PCD_GET_MODE_32_PcdMyDynamicVar32
LibPcdGetEx32(&gMyPkgTokenSpaceGuid,
_PCD_TOKEN_PcdMyDynamicVar32)
#define _PCD_GET_MODE_SIZE_PcdMyDynamicVar32
LibPcdGetExSize(&gMyPkgTokenSpaceGuid,
_PCD_TOKEN_PcdMyDynamicVar32)
#define _PCD_SET_MODE_32_PcdMyDynamicVar32(Value)
LibPcdSetEx32(&gMyPkgTokenSpaceGuid,
_PCD_TOKEN_PcdMyDynamicVar32,
(Value)) #define _PCD_SET_MODE_32_S_PcdMyDynamicVar32(Value)
LibPcdSetEx32S(&gMyPkgTokenSpaceGuid,
_PCD_TOKEN_PcdMyDynamicVar32,
(Value))

```



What is my mistake? Why is the token value not populated when
`[PcdsDynamic]` is used?





Best regards,

Konstantin Aladyshev


Konstantin Aladyshev
 

Sorry, I didn't understand your answer. Could you please elaborate it for me.

I'm trying to write `UEFI_APPLICATION` and test its execution in UEFI
Shell in QEMU running OVMF.
I also use `DxePcdLib` as PcdLib in my package DSC file:
```
[LibraryClasses]
...
PcdLib|MdePkg/Library/DxePcdLib/DxePcdLib.inf
```
In this library LibPcdGet32 is translate to:
```
UINT32
EFIAPI
LibPcdGet32 (
IN UINTN TokenNumber
)
{
return GetPcdProtocol()->Get32 (TokenNumber);
}
```
So the correct `TokenNumber` should be passed for this to work correctly.

But as I said Token for my variable is set to 0 for some reason in AutoGen.h:
```
#define _PCD_TOKEN_PcdMyDynamicVar32 0U
```

On Tue, Jun 29, 2021 at 12:25 PM Jiang, Guomin <guomin.jiang@intel.com> wrote:

Hi



This should be compiled into PCD PEIMs and PCD DXE Drivers.



It will be contained by firmware eventually.



It seem that you haven’t changed the firmware, so the firmware can’t get the value and freeze.



Thanks

From: discuss@edk2.groups.io <discuss@edk2.groups.io> On Behalf Of Konstantin Aladyshev
Sent: Tuesday, June 29, 2021 1:00 AM
To: discuss@edk2.groups.io
Subject: [edk2-discuss] Token values are not produced for PCDs under 'PcdsDynamic' section



Hello!



I'm trying to understand dynamic PCDs in EDK2.



I've added this code to my package DEC file:

```

[PcdsDynamic]
gMyPkgTokenSpaceGuid.PcdMyDynamicVar32|42|UINT32|0x00000004

```

And have added this code to my app INF file:

```

[Pcd]
gMyPkgTokenSpaceGuid.PcdMyDynamicVar32

```



I'm trying to use PCD in my application like this:

```
Print(L"PcdMyDynamicVar32=%d\n", PcdGet32(PcdMyDynamicVar32));
PcdSet32S(PcdMyDynamicVar32, 52);
Print(L"PcdMyDynamicVar32=%d\n", PcdGet32(PcdMyDynamicVar32));

```



But when I try to compile, the token number is not populated to the AutoGen.h:

```

#define _PCD_TOKEN_PcdMyDynamicVar32 0U
#define _PCD_GET_MODE_32_PcdMyDynamicVar32 LibPcdGet32(_PCD_TOKEN_PcdMyDynamicVar32)
#define _PCD_GET_MODE_SIZE_PcdMyDynamicVar32 LibPcdGetSize(_PCD_TOKEN_PcdMyDynamicVar32)
#define _PCD_SET_MODE_32_PcdMyDynamicVar32(Value) LibPcdSet32(_PCD_TOKEN_PcdMyDynamicVar32, (Value))
#define _PCD_SET_MODE_32_S_PcdMyDynamicVar32(Value) LibPcdSet32S(_PCD_TOKEN_PcdMyDynamicVar32, (Value))

```

Because of that I get 0 in the first `PcdGet32` call and my application freezes at the `PcdSet32S` call.





But if I change `[PcdsDynamic]` to [PcdsDynamicEx] in my package DEC file token value will be populated:

```

#define _PCD_TOKEN_gMyPkgTokenSpaceGuid_PcdMyDynamicVar32 1073741828U
#define _PCD_TOKEN_PcdMyDynamicVar32 _PCD_TOKEN_gMyPkgTokenSpaceGuid_PcdMyDynamicVar32
#define _PCD_GET_MODE_32_PcdMyDynamicVar32 LibPcdGetEx32(&gMyPkgTokenSpaceGuid, _PCD_TOKEN_PcdMyDynamicVar32)
#define _PCD_GET_MODE_SIZE_PcdMyDynamicVar32 LibPcdGetExSize(&gMyPkgTokenSpaceGuid, _PCD_TOKEN_PcdMyDynamicVar32)
#define _PCD_SET_MODE_32_PcdMyDynamicVar32(Value) LibPcdSetEx32(&gMyPkgTokenSpaceGuid, _PCD_TOKEN_PcdMyDynamicVar32, (Value))
#define _PCD_SET_MODE_32_S_PcdMyDynamicVar32(Value) LibPcdSetEx32S(&gMyPkgTokenSpaceGuid, _PCD_TOKEN_PcdMyDynamicVar32, (Value))

```



What is my mistake? Why is the token value not populated when `[PcdsDynamic]` is used?





Best regards,

Konstantin Aladyshev


Konstantin Aladyshev
 

Thanks Guomin! I've managed to get PcdMyDynamicExVar32 working, but I still have troubles with PcdMyDynamicVar32...

MyPkg/MyPkg.dec:
```
[PcdsDynamic]
gMyPkgTokenSpaceGuid.PcdMyDynamicVar32|0x31313131|UINT32|0x30000001

[PcdsDynamicEx]
gMyPkgTokenSpaceGuid.PcdMyDynamicExVar32|0x32323232|UINT32|0x40000001
```

MyPkg/Myapp/Myapp.inf:
```
[Pcd]
gUefiLessonsPkgTokenSpaceGuid.PcdMyDynamicVar32

[PcdEx]
gUefiLessonsPkgTokenSpaceGuid.PcdMyDynamicExVar32
```

MyPkg/Myapp/Myapp.c:
```
Print(L"PcdMyDynamicExVar32=%x\n", PcdGet32(PcdMyDynamicExVar32));
PcdSet32S(PcdMyDynamicExVar32, 52);
Print(L"PcdMyDynamicExVar32=%x\n", PcdGet32(PcdMyDynamicExVar32));

Print(L"PcdMyDynamicVar32=%x\n", PcdGet32(PcdMyDynamicVar32));
PcdSet32S(PcdMyDynamicVar32, 52);
Print(L"PcdMyDynamicVar32=%x\n", PcdGet32(PcdMyDynamicVar32));
```

Also I've modified OvmfPkg source:
OvmfPkg/OvmfPkgX64.fdf
```
[FV.DXEFV]
...
+ INF MyPkg/MyApp/MyApp.inf
```
OvmfPkg/OvmfPkgX64.dsc
```
+ [PcdsDynamicExDefault]
+ gUefiLessonsPkgTokenSpaceGuid.PcdMyDynamicExVar32

[PcdsDynamicDefault]
+ gUefiLessonsPkgTokenSpaceGuid.PcdMyDynamicVar32
...
```


After OVMF recompilation I see both variables in a PCD database:
hexeditor Build/OvmfX64/RELEASE_GCC5/FV/Ffs/80CF7257-87AB-47f9-A3FE-D50B76D89541PcdDxe/DXEPcdDataBaseSec.raw

However only `PcdMyDynamicExVar32` works correctly in my app. I think it is because of the fact that Token value for PcdMyDynamicVar32 is still 0 in `Build/UefiLessonsPkg/RELEASE_GCC5/X64/UefiLessonsPkg/PCDLesson/PCDLesson/DEBUG/AutoGen.h`
```
#define _PCD_TOKEN_PcdMyDynamicVar32_1 0U
#define _PCD_GET_MODE_32_PcdMyDynamicVar32_1 LibPcdGet32(_PCD_TOKEN_PcdMyDynamicVar32_1)
#define _PCD_GET_MODE_SIZE_PcdMyDynamicVar32_1 LibPcdGetSize(_PCD_TOKEN_PcdMyDynamicVar32_1)
#define _PCD_SET_MODE_32_PcdMyDynamicVar32_1(Value) LibPcdSet32(_PCD_TOKEN_PcdMyDynamicVar32_1, (Value))
#define _PCD_SET_MODE_32_S_PcdMyDynamicVar32_1(Value) LibPcdSet32S(_PCD_TOKEN_PcdMyDynamicVar32_1, (Value))

#define _PCD_TOKEN_gUefiLessonsPkgTokenSpaceGuid_PcdMyDynamicExVar32 1073741825U
#define _PCD_TOKEN_PcdMyDynamicExVar32 _PCD_TOKEN_gUefiLessonsPkgTokenSpaceGuid_PcdMyDynamicExVar32
#define _PCD_GET_MODE_32_PcdMyDynamicExVar32 LibPcdGetEx32(&gUefiLessonsPkgTokenSpaceGuid, _PCD_TOKEN_PcdMyDynamicExVar32)
#define _PCD_GET_MODE_SIZE_PcdMyDynamicExVar32 LibPcdGetExSize(&gUefiLessonsPkgTokenSpaceGuid, _PCD_TOKEN_PcdMyDynamicExVar32)
#define _PCD_SET_MODE_32_PcdMyDynamicExVar32(Value) LibPcdSetEx32(&gUefiLessonsPkgTokenSpaceGuid, _PCD_TOKEN_PcdMyDynamicExVar32, (Value))
#define _PCD_SET_MODE_32_S_PcdMyDynamicExVar32(Value) LibPcdSetEx32S(&gUefiLessonsPkgTokenSpaceGuid, _PCD_TOKEN_PcdMyDynamicExVar32, (Value)
```

What am I doing wrong?


Andrew Fish
 

The default PCD namespace is for code that is built together. The token ids (TokenName) are build generated and can move around.

If you want to do PCD from an App (or any binary that is not built with the EFI Firmware) you need to use the *Ex() [1] form of the PCD functions. The *Ex form uses a Guid (UUID) and fixed TokenName


[1] https://github.com/tianocore/edk2/blob/master/MdePkg/Include/Library/PcdLib.h#L593

Thanks,

Andrew Fish

On Jun 29, 2021, at 2:46 AM, Konstantin Aladyshev <aladyshev22@gmail.com> wrote:

Sorry, I didn't understand your answer. Could you please elaborate it for me.

I'm trying to write `UEFI_APPLICATION` and test its execution in UEFI
Shell in QEMU running OVMF.
I also use `DxePcdLib` as PcdLib in my package DSC file:
```
[LibraryClasses]
...
PcdLib|MdePkg/Library/DxePcdLib/DxePcdLib.inf
```
In this library LibPcdGet32 is translate to:
```
UINT32
EFIAPI
LibPcdGet32 (
IN UINTN TokenNumber
)
{
return GetPcdProtocol()->Get32 (TokenNumber);
}
```
So the correct `TokenNumber` should be passed for this to work correctly.

But as I said Token for my variable is set to 0 for some reason in AutoGen.h:
```
#define _PCD_TOKEN_PcdMyDynamicVar32 0U
```

On Tue, Jun 29, 2021 at 12:25 PM Jiang, Guomin <guomin.jiang@intel.com <mailto:guomin.jiang@intel.com>> wrote:

Hi



This should be compiled into PCD PEIMs and PCD DXE Drivers.



It will be contained by firmware eventually.



It seem that you haven’t changed the firmware, so the firmware can’t get the value and freeze.



Thanks

From: discuss@edk2.groups.io <discuss@edk2.groups.io> On Behalf Of Konstantin Aladyshev
Sent: Tuesday, June 29, 2021 1:00 AM
To: discuss@edk2.groups.io
Subject: [edk2-discuss] Token values are not produced for PCDs under 'PcdsDynamic' section



Hello!



I'm trying to understand dynamic PCDs in EDK2.



I've added this code to my package DEC file:

```

[PcdsDynamic]
gMyPkgTokenSpaceGuid.PcdMyDynamicVar32|42|UINT32|0x00000004

```

And have added this code to my app INF file:

```

[Pcd]
gMyPkgTokenSpaceGuid.PcdMyDynamicVar32

```



I'm trying to use PCD in my application like this:

```
Print(L"PcdMyDynamicVar32=%d\n", PcdGet32(PcdMyDynamicVar32));
PcdSet32S(PcdMyDynamicVar32, 52);
Print(L"PcdMyDynamicVar32=%d\n", PcdGet32(PcdMyDynamicVar32));

```



But when I try to compile, the token number is not populated to the AutoGen.h:

```

#define _PCD_TOKEN_PcdMyDynamicVar32 0U
#define _PCD_GET_MODE_32_PcdMyDynamicVar32 LibPcdGet32(_PCD_TOKEN_PcdMyDynamicVar32)
#define _PCD_GET_MODE_SIZE_PcdMyDynamicVar32 LibPcdGetSize(_PCD_TOKEN_PcdMyDynamicVar32)
#define _PCD_SET_MODE_32_PcdMyDynamicVar32(Value) LibPcdSet32(_PCD_TOKEN_PcdMyDynamicVar32, (Value))
#define _PCD_SET_MODE_32_S_PcdMyDynamicVar32(Value) LibPcdSet32S(_PCD_TOKEN_PcdMyDynamicVar32, (Value))

```

Because of that I get 0 in the first `PcdGet32` call and my application freezes at the `PcdSet32S` call.





But if I change `[PcdsDynamic]` to [PcdsDynamicEx] in my package DEC file token value will be populated:

```

#define _PCD_TOKEN_gMyPkgTokenSpaceGuid_PcdMyDynamicVar32 1073741828U
#define _PCD_TOKEN_PcdMyDynamicVar32 _PCD_TOKEN_gMyPkgTokenSpaceGuid_PcdMyDynamicVar32
#define _PCD_GET_MODE_32_PcdMyDynamicVar32 LibPcdGetEx32(&gMyPkgTokenSpaceGuid, _PCD_TOKEN_PcdMyDynamicVar32)
#define _PCD_GET_MODE_SIZE_PcdMyDynamicVar32 LibPcdGetExSize(&gMyPkgTokenSpaceGuid, _PCD_TOKEN_PcdMyDynamicVar32)
#define _PCD_SET_MODE_32_PcdMyDynamicVar32(Value) LibPcdSetEx32(&gMyPkgTokenSpaceGuid, _PCD_TOKEN_PcdMyDynamicVar32, (Value))
#define _PCD_SET_MODE_32_S_PcdMyDynamicVar32(Value) LibPcdSetEx32S(&gMyPkgTokenSpaceGuid, _PCD_TOKEN_PcdMyDynamicVar32, (Value))

```



What is my mistake? Why is the token value not populated when `[PcdsDynamic]` is used?





Best regards,

Konstantin Aladyshev



Konstantin Aladyshev
 

Thanks Andrew!

It turns out, I was looking/using wrong files. Instead of:
```
Build/MyPkg/RELEASE_GCC5/X64/MyPkg/MyApp/MyApp/DEBUG/AutoGen.h
Build/MyPkg/RELEASE_GCC5/X64/MyApp.efi
```
I should have looked at:
```
Build/OvmfX64/RELEASE_GCC5/X64/MyPkg/MyApp/MyApp/DEBUG/AutoGen.h
Build/OvmfX64/RELEASE_GCC5/X64/MyApp.efi
```

This AutoGen.h have a correct token for my dynamic variable:
```
#define _PCD_TOKEN_PcdMyDynamicVar32 38U
#define _PCD_GET_MODE_32_PcdMyDynamicVar32 LibPcdGet32(_PCD_TOKEN_PcdMyDynamicVar32)
#define _PCD_GET_MODE_SIZE_PcdMyDynamicVar32 LibPcdGetSize(_PCD_TOKEN_PcdMyDynamicVar32)
#define _PCD_SET_MODE_32_PcdMyDynamicVar32(Value) LibPcdSet32(_PCD_TOKEN_PcdMyDynamicVar32, (Value))
#define _PCD_SET_MODE_32_S_PcdMyDynamicVar32(Value) LibPcdSet32S(_PCD_TOKEN_PcdMyDynamicVar32, (Value))
```
And with the right *.efi file everything works correctly!

Thanks for the help!