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

Join discuss@edk2.groups.io to automatically receive all group messages.