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


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

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