Date   

Re: Stack unwinding in SMM

Andrew Fish
 

On Jul 1, 2021, at 4:08 AM, mick21@live.nl wrote:

Hello everyone,

At the moment I'm trying to perform some form of stack unwinding in SMM, but I'm failing to successfully do that at the moment. I tried to use LLVM's __builtin_return_address(), but this only returns the return address for entry 0. Looking at the assembly, it seems that sometimes function epilogues start with "lea 0x8(%rbp),%rsp" and then a certain amount of pop instructions, while other times the function epilogue starts with "add $0x20,%rsp" and then a certain amount of pop instructions. This seems to indicate that manually performing the stack unwinding is cumbersome, as there are a lot of cases to cover.
Mick,

It might be possible to turn on frame pointers via: -fno-omit-frame-pointer

The Xcode flavor of clang defaults to emitting the frame pointer so __builtin_return_address() works as expected for N levels, and you can manually walk the stack in code.

The other option is to use the debugger to walk the unwind + debug info to get stack frames….

FYI for Xcode the pattern is:

pushq %rbp
movq %rsp, %rbp

popq %rbp
retq

So %rbp is a frame pointer, and the return address is on the stack from the call.

I was wondering whether there are better ways to perform this task, where I want to retrieve a call stack from arbitrary places in an SMM driver. I'm not sure where to start, I have looked online but I would likely need unwind tables (which seem to be enabled in EDK II https://github.com/tianocore/edk2/commit/77b738b36f5f19b33a77ff74ce822c9c5a050876), but I'm not sure how I should use them in the EDK II project or whether they are even present in my .efi file. The sections available in my .efi file are .text, .rdata, .data, and .reloc.
Caveat emptor I’m speculating here…..

I’m not sure the unwind tables are part of the ABI, they are likely treated more like debugging info. I did find this [1]. In olden time the MSFT PDB was a moving target and you needed a DLL to parse it, it might have gotten more stable over the years.

I think the unwind tables are to support partial debugging (walking a stack frame), but the unwind info is processed by something in the runtime or debugger. I don’t know of any edk2 to unwind. I did notice this [2], so you may want to look at that?

[1] https://docs.microsoft.com/en-us/cpp/build/exception-handling-x64?view=msvc-160
[2] https://www.nongnu.org/libunwind/

Thanks,

Andrew Fish

Kind regards,

Mick





QEMU failed to emulate MMIO Access when -accel whpx

tbtbfaker@...
 

I have built a OVMF based on EDK2, but when tried to run with QEMU -accel whpx, it gave the error of
qemu-system-x86_64.exe: WHPX: Failed to emulate MMIO access with EmulatorReturnStatus: 2
qemu-system-x86_64.exe: WHPX: Failed to exec a virtual processor

Without -accel whpx as an option in QEMU, it would work. However, I would need whpx as when using OVMF to boot into Windows, it would be very slow.


Re: EFI Network drivers being disabled when booting with Grub via PXE

Laszlo Ersek
 

On 06/30/21 19:42, gustavohenriquesm@gmail.com wrote:
Hello all,
I am facing an issue, if anyone can help me with this, I would appreciate a lot.
When I boot directly on Grub via USB drive then select UEFI Shell .efi (also in USB drive) to boot, the network drivers work fine, I can list them using drivers command as shown bellow (just some examples, not all network drivers are listed):

19E 0000000A D N N 1 0 Simple Network Protocol Driver Fv(AF4A9118-29A7-4F62-BB8C-E5B79013CB2E)/FvFile(A2F436EA-A127-4EF8-957C-8048606FF670)
1A3 0000000A B N N 2 11 IP4 Network Service Driver Fv(AF4A9118-29A7-4F62-BB8C-E5B79013CB2E)/FvFile(9FB1A1F3-3B71-4324-B39A-745CBB015FFF)
1AA 0000000A B N N 2 2 TCP Network Service Driver Fv(AF4A9118-29A7-4F62-BB8C-E5B79013CB2E)/FvFile(1A7E4468-2F55-4A56-903C-01265EB7622B)
1AC 0000000A B N N 8 1 UEFI PXE Base Code Driver Fv(AF4A9118-29A7-4F62-BB8C-E5B79013CB2E)/FvFile(B95E9FDA-26DE-48D2-8807-1F9107AC5E3A)

So, the problem isn't with Grub itself. The problem happens when I boot via PXE. The server sends the Grub .efi file, that is loaded with no problems, and then I boot the UEFI Shell. Then, all the network drivers seems to be disabled, take a look to drivers command:

19E 0000000A D N N 1 0 Simple Network Protocol Driver Fv(AF4A9118-29A7-4F62-BB8C-E5B79013CB2E)/FvFile(A2F436EA-A127-4EF8-957C-8048606FF670)
1A3 0000000A ? N N 0 0 IP4 Network Service Driver Fv(AF4A9118-29A7-4F62-BB8C-E5B79013CB2E)/FvFile(9FB1A1F3-3B71-4324-B39A-745CBB015FFF)
1AA 0000000A ? N N 0 0 TCP Network Service Driver Fv(AF4A9118-29A7-4F62-BB8C-E5B79013CB2E)/FvFile(1A7E4468-2F55-4A56-903C-01265EB7622B)
1AC 0000000A ? N N 0 0 UEFI PXE Base Code Driver Fv(AF4A9118-29A7-4F62-BB8C-E5B79013CB2E)/FvFile(B95E9FDA-26DE-48D2-8807-1F9107AC5E3A)

As you can see, except for the Simple Network Protocol Driver, all network drivers are shown as "?" type and no devices are managed by them (they look all disabled). I try to connect them using "connect -r" command, it does nothing. Tried also "reconnect" command, but it hangs forever with the prompt cursor blinking.
Do you know why it's happening and how I can bypass it?

PS.: Booting directly on UEFI Shell via PXE this issue does not reproduce, the drivers are ok, the problem is the combination PXE + Grub.

Thanks in advance!
When you boot grub via PXE, grub will open the SNP interface (IIRC) in
exclusive driver mode, to force off all other (dependent) drivers, such
as MNP, ARP, IP, TCP, and so on. This is in preparation for grub itself
netbooting the next stages (kernel + initrd) via TFTP, if I understand
correctly, for which grub wants to use SNP without interference from
other drivers. Netbooting grub, then launching the UEFI shell *from*
grub, is a really strange use case, AFAICT, and grub might not release SNP.

Just a guess.
Laszlo


Stack unwinding in SMM

mick21@...
 

Hello everyone,

At the moment I'm trying to perform some form of stack unwinding in SMM, but I'm failing to successfully do that at the moment. I tried to use LLVM's __builtin_return_address(), but this only returns the return address for entry 0. Looking at the assembly, it seems that sometimes function epilogues start with "lea 0x8(%rbp),%rsp" and then a certain amount of pop instructions, while other times the function epilogue starts with "add $0x20,%rsp" and then a certain amount of pop instructions. This seems to indicate that manually performing the stack unwinding is cumbersome, as there are a lot of cases to cover.

I was wondering whether there are better ways to perform this task, where I want to retrieve a call stack from arbitrary places in an SMM driver. I'm not sure where to start, I have looked online but I would likely need unwind tables (which seem to be enabled in EDK II https://github.com/tianocore/edk2/commit/77b738b36f5f19b33a77ff74ce822c9c5a050876), but I'm not sure how I should use them in the EDK II project or whether they are even present in my .efi file. The sections available in my .efi file are .text, .rdata, .data, and .reloc.

Kind regards,

Mick


Re: Does data constraint comments affect the build?

Andrew Fish
 

On Jun 30, 2021, at 5:17 AM, Konstantin Aladyshev <aladyshev22@gmail.com> wrote:

Is there any value in data constraint comments in the INF file? I mean
these:
```
## SOMETIMES_PRODUCES
## CONSUMES
## SOMETIMES_PRODUCES
## PRODUCES
## TO_START
## BY_START
```
Are they purely informational? Do they affect the build process in any way?
Can they break the build somehow?
They are not used by the build process, so for that they are comments. I think they are used for package management, so they are meta data for managing packages.

Thanks,

Andrew Fish





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

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!


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

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



EFI Network drivers being disabled when booting with Grub via PXE

gustavohenriquesm@...
 

Hello all,
I am facing an issue, if anyone can help me with this, I would appreciate a lot.
When I boot directly on Grub via USB drive then select UEFI Shell .efi (also in USB drive) to boot, the network drivers work fine, I can list them using drivers command as shown bellow (just some examples, not all network drivers are listed):

19E 0000000A D N N 1 0 Simple Network Protocol Driver Fv(AF4A9118-29A7-4F62-BB8C-E5B79013CB2E)/FvFile(A2F436EA-A127-4EF8-957C-8048606FF670)
1A3 0000000A B N N 2 11 IP4 Network Service Driver Fv(AF4A9118-29A7-4F62-BB8C-E5B79013CB2E)/FvFile(9FB1A1F3-3B71-4324-B39A-745CBB015FFF)
1AA 0000000A B N N 2 2 TCP Network Service Driver Fv(AF4A9118-29A7-4F62-BB8C-E5B79013CB2E)/FvFile(1A7E4468-2F55-4A56-903C-01265EB7622B)
1AC 0000000A B N N 8 1 UEFI PXE Base Code Driver Fv(AF4A9118-29A7-4F62-BB8C-E5B79013CB2E)/FvFile(B95E9FDA-26DE-48D2-8807-1F9107AC5E3A)

So, the problem isn't with Grub itself. The problem happens when I boot via PXE. The server sends the Grub .efi file, that is loaded with no problems, and then I boot the UEFI Shell. Then, all the network drivers seems to be disabled, take a look to drivers command:

19E 0000000A D N N 1 0 Simple Network Protocol Driver Fv(AF4A9118-29A7-4F62-BB8C-E5B79013CB2E)/FvFile(A2F436EA-A127-4EF8-957C-8048606FF670)
1A3 0000000A ? N N 0 0 IP4 Network Service Driver Fv(AF4A9118-29A7-4F62-BB8C-E5B79013CB2E)/FvFile(9FB1A1F3-3B71-4324-B39A-745CBB015FFF)
1AA 0000000A ? N N 0 0 TCP Network Service Driver Fv(AF4A9118-29A7-4F62-BB8C-E5B79013CB2E)/FvFile(1A7E4468-2F55-4A56-903C-01265EB7622B)
1AC 0000000A ? N N 0 0 UEFI PXE Base Code Driver Fv(AF4A9118-29A7-4F62-BB8C-E5B79013CB2E)/FvFile(B95E9FDA-26DE-48D2-8807-1F9107AC5E3A)

As you can see, except for the Simple Network Protocol Driver, all network drivers are shown as "?" type and no devices are managed by them (they look all disabled). I try to connect them using "connect -r" command, it does nothing. Tried also "reconnect" command, but it hangs forever with the prompt cursor blinking.
Do you know why it's happening and how I can bypass it?

PS.: Booting directly on UEFI Shell via PXE this issue does not reproduce, the drivers are ok, the problem is the combination PXE + Grub.

Thanks in advance!


Does data constraint comments affect the build?

Konstantin Aladyshev
 

Is there any value in data constraint comments in the INF file? I mean
these:
```
## SOMETIMES_PRODUCES
## CONSUMES
## SOMETIMES_PRODUCES
## PRODUCES
## TO_START
## BY_START
```
Are they purely informational? Do they affect the build process in any way?
Can they break the build somehow?


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

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?


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


回复: [edk2-discuss] Difference between boolean PCD fixed at build and a PCD feature flag

gaoliming
 

Yes. Feature PCD is same to Boolean fixed at build PCD.



Thanks

Liming

发件人: discuss@edk2.groups.io <discuss@edk2.groups.io> 代表 Konstantin Aladyshev
发送时间: 2021年6月29日 4:46
收件人: discuss@edk2.groups.io
主题: [edk2-discuss] Difference between boolean PCD fixed at build and a PCD feature flag



What is the difference between boolean PCD fixed at build and a PCD feature flag?

```

[PcdsFixedAtBuild]
gMyPkgTokenSpaceGuid.PcdMyVarBool|FALSE|BOOLEAN|0x00000004

[PcdsFeatureFlag]
gMyPkgTokenSpaceGuid.PcdMyFeatureFlagVar|FALSE|BOOLEAN|0x20000001

```

I'm looking at the AutoGen files and the result from both of these PCDs is practically the same.



AutoGen.c
```
GLOBAL_REMOVE_IF_UNREFERENCED const BOOLEAN _gPcd_FixedAtBuild_PcdMyVarBool = _PCD_VALUE_PcdMyVarBool;
GLOBAL_REMOVE_IF_UNREFERENCED const BOOLEAN _gPcd_FixedAtBuild_PcdMyFeatureFlagVar = _PCD_VALUE_PcdMyFeatureFlagVar;
```
AutoGen.h
```
#define _PCD_TOKEN_PcdMyVarBool 0U
#define _PCD_SIZE_PcdMyVarBool 1
#define _PCD_GET_MODE_SIZE_PcdMyVarBool _PCD_SIZE_PcdMyVarBool
#define _PCD_VALUE_PcdMyVarBool 0U
extern const BOOLEAN _gPcd_FixedAtBuild_PcdMyVarBool;
#define _PCD_GET_MODE_BOOL_PcdMyVarBool _gPcd_FixedAtBuild_PcdMyVarBool
//#define _PCD_SET_MODE_BOOL_PcdMyVarBool ASSERT(FALSE) // It is not allowed to set value for a FIXED_AT_BUILD PCD

#define _PCD_TOKEN_PcdMyFeatureFlagVar 0U
#define _PCD_SIZE_PcdMyFeatureFlagVar 1
#define _PCD_GET_MODE_SIZE_PcdMyFeatureFlagVar _PCD_SIZE_PcdMyFeatureFlagVar
#define _PCD_VALUE_PcdMyFeatureFlagVar ((BOOLEAN)0U)
extern const BOOLEAN _gPcd_FixedAtBuild_PcdMyFeatureFlagVar;
#define _PCD_GET_MODE_BOOL_PcdMyFeatureFlagVar _gPcd_FixedAtBuild_PcdMyFeatureFlagVar
//#define _PCD_SET_MODE_BOOL_PcdMyFeatureFlagVar ASSERT(FALSE) // It is not allowed to set value for a FIXED_AT_BUILD PCD
```



Are there any actual differences between those two methods of defining a PCD? Or is `PcdsFeatureFlag` simply a syntactic sugar?


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

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


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

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


Difference between boolean PCD fixed at build and a PCD feature flag

Konstantin Aladyshev <aladyshev22@...>
 

What is the difference between boolean PCD fixed at build and a PCD feature flag?
```
[PcdsFixedAtBuild]
  gMyPkgTokenSpaceGuid.PcdMyVarBool|FALSE|BOOLEAN|0x00000004

[PcdsFeatureFlag]
  gMyPkgTokenSpaceGuid.PcdMyFeatureFlagVar|FALSE|BOOLEAN|0x20000001
```
I'm looking at the AutoGen files and the result from both of these PCDs is practically the same.

AutoGen.c
```
GLOBAL_REMOVE_IF_UNREFERENCED const BOOLEAN _gPcd_FixedAtBuild_PcdMyVarBool = _PCD_VALUE_PcdMyVarBool;
GLOBAL_REMOVE_IF_UNREFERENCED const BOOLEAN _gPcd_FixedAtBuild_PcdMyFeatureFlagVar = _PCD_VALUE_PcdMyFeatureFlagVar;
```
AutoGen.h
```
#define _PCD_TOKEN_PcdMyVarBool  0U
#define _PCD_SIZE_PcdMyVarBool 1
#define _PCD_GET_MODE_SIZE_PcdMyVarBool  _PCD_SIZE_PcdMyVarBool
#define _PCD_VALUE_PcdMyVarBool  0U
extern const  BOOLEAN  _gPcd_FixedAtBuild_PcdMyVarBool;
#define _PCD_GET_MODE_BOOL_PcdMyVarBool  _gPcd_FixedAtBuild_PcdMyVarBool
//#define _PCD_SET_MODE_BOOL_PcdMyVarBool  ASSERT(FALSE)  // It is not allowed to set value for a FIXED_AT_BUILD PCD

#define _PCD_TOKEN_PcdMyFeatureFlagVar  0U
#define _PCD_SIZE_PcdMyFeatureFlagVar 1
#define _PCD_GET_MODE_SIZE_PcdMyFeatureFlagVar  _PCD_SIZE_PcdMyFeatureFlagVar
#define _PCD_VALUE_PcdMyFeatureFlagVar  ((BOOLEAN)0U)
extern const  BOOLEAN  _gPcd_FixedAtBuild_PcdMyFeatureFlagVar;
#define _PCD_GET_MODE_BOOL_PcdMyFeatureFlagVar  _gPcd_FixedAtBuild_PcdMyFeatureFlagVar
//#define _PCD_SET_MODE_BOOL_PcdMyFeatureFlagVar  ASSERT(FALSE)  // It is not allowed to set value for a FIXED_AT_BUILD PCD
```

Are there any actual differences between those two methods of defining a PCD? Or is `PcdsFeatureFlag` simply a syntactic sugar?


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


Enable UART CTS and RTS in edk2

Antony Abee
 

Hi,

We are developing edk2 bios image for our custom board which is based on Ampere SOC.

Custom board has Uart connections as below:
Uart0

* DB9 connector (Uefi console)
* CTS/RTS signals from SOC

Uart3

* DB9 connector
* CTS/RTS signals from GPIO

We have following queries:

1. CTS/RTS signals have usage in edk2 ? or this is useful in OS level only ?
2. Where to enable CTS/RTS control register bits in edk2 source for ampere platform ?
3. Where to configure GPIO's for Uart3 CTS and RTS signals in edk2 source for ampere platform ?
4. Not able to find gpio pad configuration for ampere platform in edk2 source.
5. Could you please help to clarify the above queries ?

Thanks & Regards,
Antony


Re: How to build your own firmware based upon EDK2 for Windows 10 QEMU

Andrew Fish
 

Wong,

If you are building OvmfPkgX64.dsc then you can add driver or apps to OvmfPkgX64.dsc [1] to get it to build, and add it to OvmfPkgX64.fdf [2] to get it in the ROM.

[1] https://github.com/tianocore/edk2/blob/master/OvmfPkg/OvmfPkgX64.dsc
[2] https://github.com/tianocore/edk2/blob/master/OvmfPkg/OvmfPkgX64.fdf

Thanks,

Andrew Fish

On Jun 12, 2021, at 6:59 AM, tbtbfaker@gmail.com wrote:

Hi,

I am currently working on a project where I would have to customize the EFI ROM file for my Windows 10. To emulate firmware, I have built latest edk2 as well as OVMF. I am able to run OVMF using QEMU but I have no clue on the next step in order to make custom firmware to run Windows 10 in QEMU.

Can anyone advise on what I should look at next?

Regards,
Wong





Enabling UART CTS / RTS support in edk2

Antony Abee
 

Hi All,

We are developing an edk2 bios image for our custom board which is based on Ampere SOC.

Our custom board has
Uart0 - uefi logs
Uart3 - Connected to DB9 connector.

For uart0 the cts and rts signals are from SOC itself. Whereas for Uart3, cts and rts signals are from GPIO.

Uart Driver used: ARM PL011 UART driver.

We have below queries.
1. Does CTS and RTS signals have usage in edk2 ? or this will be taken care in OS level ?
2. Where to enable CTS/RTS bits of uart control registers in edk2 ?
3. Where to configure the GPIO's as CTS and RTS functionality in edk2 ?

Could anyone help on this ?

Thanks.


How to build your own firmware based upon EDK2 for Windows 10 QEMU

tbtbfaker@...
 

Hi,

I am currently working on a project where I would have to customize the EFI ROM file for my Windows 10. To emulate firmware, I have built latest edk2 as well as OVMF. I am able to run OVMF using QEMU but I have no clue on the next step in order to make custom firmware to run Windows 10 in QEMU.

Can anyone advise on what I should look at next?

Regards,
Wong

121 - 140 of 888