How to link DXE_DRIVER from UEFI_APPLICATION?


joseph@...
 

Hi,

I want to include Tcg2PhysicalPresenceLib in my UEFI Application.

Tcg2PhysicalPresenceLib is located in SecurityPkg/Library/Tpm2DeviceLibTcg2/Tpm2DeviceLibTcg2.inf in EDK2.

========================================
This is what I tried:

Package dsc:
[LibraryClasses.common]
Tpm2DeviceLibTcg2|SecurityPkg/Library/Tpm2DeviceLibTcg2/Tpm2DeviceLibTcg2.inf

Application inf:
[LibraryClasses]
Tcg2PhysicalPresenceLib
========================================

If you do the above, you will get this error.

.../edk2/MyPkg/MyPkg.dsc(...): error 1001: Module type [UEFI_APPLICATION] is not supported by library instance [.../edk2/MdePkg/Library/UefiDriverEntryPoint/UefiDriverEntryPoint.inf]
consumed by [.../edk2/MyPkg/MyApp/MyApp.inf]

How do I use Tcg2PhysicalPresenceLib in Application?

Kind regards,
Joseph


Laszlo Ersek
 

On 02/05/21 07:59, joseph via groups.io wrote:
Hi,

I want to include Tcg2PhysicalPresenceLib in my UEFI Application.

Tcg2PhysicalPresenceLib is located in SecurityPkg/Library/Tpm2DeviceLibTcg2/Tpm2DeviceLibTcg2.inf in EDK2.

========================================
This is what I tried:

Package dsc:
[LibraryClasses.common]
Tpm2DeviceLibTcg2|SecurityPkg/Library/Tpm2DeviceLibTcg2/Tpm2DeviceLibTcg2.inf

Application inf:
[LibraryClasses]
Tcg2PhysicalPresenceLib
========================================

If you do the above, you will get this error.

.../edk2/MyPkg/MyPkg.dsc(...): error 1001: Module type [UEFI_APPLICATION] is not supported by library instance [.../edk2/MdePkg/Library/UefiDriverEntryPoint/UefiDriverEntryPoint.inf]
consumed by [.../edk2/MyPkg/MyApp/MyApp.inf]

How do I use Tcg2PhysicalPresenceLib in Application?
"SecurityPkg/Library/Tpm2DeviceLibTcg2/Tpm2DeviceLibTcg2.inf" already
permits UEFI_APPLICATION, so that's not the problem.

The issue is that you're trying to link UefiDriverEntryPoint into your
application -- that's wrong. UEFI_APPLICATION modules have different
entry points / depend on different entry point lib classes, namely one
of the following:

- "UefiApplicationEntryPoint" if the application is stand-alone (for
example, bootable as a UEFI boot option)

- "ShellCEntryLib" if the application is a shell application (= it can,
and needs to, be started from the UEFI shell only)

- "LibC" if the application consumes the edk2-libc project for a
standard C library implementation, and starts with a main() function.

Laszlo


joseph@...
 

Hi, Laszlo

Thank you for reply.

My app does not use UefiDriverEntryPoint.
UefiDriverEntryPoint exists in DxeTcg2PhysicalPresenceLib.inf.
If forcibly delete UefiDriverEntryPoint from DxeTcg2PhysicalPresenceLib.inf, Another error occurs.
Instance of library class [Tcg2PpVendorLib] is not found
Adding the Tcg2PpVendorLib again gives me the "error 1001" error.

========== MyApp.inf =========
[LibraryClasses]
UefiApplicationEntryPoint
UefiLib
PcdLib
OpensslLib
Tpm2DeviceLibTcg2
Tcg2PhysicalPresenceLib

========== DxeTcg2PhysicalPresenceLib.inf =========
[LibraryClasses]
MemoryAllocationLib
UefiLib
UefiBootServicesTableLib
UefiDriverEntryPoint
UefiRuntimeServicesTableLib
BaseMemoryLib
DebugLib
PrintLib
HiiLib
HobLib
Tpm2CommandLib
Tcg2PpVendorLib


Laszlo Ersek
 

On 02/05/21 15:44, joseph via [] wrote:
Hi, Laszlo

Thank you for reply.

My app does not use UefiDriverEntryPoint.
UefiDriverEntryPoint exists in DxeTcg2PhysicalPresenceLib.inf.
Ouch. That's a bug in "DxeTcg2PhysicalPresenceLib.inf", no doubt.

Let's see if there are some other library INF files that have a similar issue:

$ git grep -l -w UefiDriverEntryPoint -- '*inf' \
| xargs grep -l -w LIBRARY_CLASS

MdeModulePkg/Library/CustomizedDisplayLib/CustomizedDisplayLib.inf
MdePkg/Library/UefiDriverEntryPoint/UefiDriverEntryPoint.inf
SecurityPkg/Library/DxeTcg2PhysicalPresenceLib/DxeTcg2PhysicalPresenceLib.inf
SecurityPkg/Library/DxeTcgPhysicalPresenceLib/DxeTcgPhysicalPresenceLib.inf

OK, so the bugged library INF files are:
- CustomizedDisplayLib.inf
- DxeTcg2PhysicalPresenceLib.inf
- DxeTcgPhysicalPresenceLib.inf

Can you please file a bugzilla ticket at <https://bugzilla.tianocore.org/>, about this? Those library instances should not depend on the UefiDriverEntryPoint class.


If forcibly delete UefiDriverEntryPoint from DxeTcg2PhysicalPresenceLib.inf, Another error occurs.
Instance of library class [Tcg2PpVendorLib] is not found
Wait, that's a different case.

When you delete UefiDriverEntryPoint from DxeTcg2PhysicalPresenceLib.inf, you actually fix a bug. And therefore the build process advances a bit further, before it runs into *another* problem.

This particular (new) problem is that your platform DSC file does not resolve the Tcg2PpVendorLib class to a library instance. DxeTcg2PhysicalPresenceLib depends on Tcg2PpVendorLib, but the build process doesn't know what instance of Tcg2PpVendorLib to use. Edk2 offers a Null instance of this library:

SecurityPkg/Library/Tcg2PpVendorLibNull/Tcg2PpVendorLibNull.inf

So in your DSC file, you could use:

[LibraryClasses]
Tcg2PpVendorLib|SecurityPkg/Library/Tcg2PpVendorLibNull/Tcg2PpVendorLibNull.inf

Hope this helps,
Laszlo

Adding the Tcg2PpVendorLib again gives me the "error 1001" error.

========== MyApp.inf =========
[LibraryClasses]
UefiApplicationEntryPoint
UefiLib
PcdLib
OpensslLib
Tpm2DeviceLibTcg2
Tcg2PhysicalPresenceLib

========== DxeTcg2PhysicalPresenceLib.inf =========
[LibraryClasses]
MemoryAllocationLib
UefiLib
UefiBootServicesTableLib
UefiDriverEntryPoint
UefiRuntimeServicesTableLib
BaseMemoryLib
DebugLib
PrintLib
HiiLib
HobLib
Tpm2CommandLib
Tcg2PpVendorLib


joseph@...
 

Hi Laszlo,

Thank you. But the problem is still not solved.

.../edk2/MyPkg/MyPkg.dsc(...): error 1001: Module type [UEFI_APPLICATION] is not supported by
library instance [.../edk2/SecurityPkg/Library/Tcg2PpVendorLibNull/Tcg2PpVendorLibNull.inf]
consumed by [.../edk2/MyPkg/MyApp/MyApp.inf]
After modifying several more steps through the method you suggested, the build was completed.
https://github.com/jc-lab/temp-edk2-tpm2-problem/commit/d9afc8f562d1bda190b27ac8db67df3b0a5bb24a
But I get the error like below.

/usr/bin/ld: Tpm2DeviceLibTcg2.obj (symbol from plugin): in function `mTcg2Protocol':
(.text+0x0): multiple definition of `Tpm2SubmitCommand'; Tpm2DeviceLibDTpm.obj (symbol from plugin):(.text+0x0): first defined here
/usr/bin/ld: Tpm2DeviceLibTcg2.obj (symbol from plugin): in function `mTcg2Protocol':
(.text+0x0): multiple definition of `Tpm2RequestUseTpm'; Tpm2DeviceLibDTpm.obj (symbol from plugin):(.text+0x0): first defined here
/usr/bin/ld: Tpm2DeviceLibTcg2.obj (symbol from plugin): in function `mTcg2Protocol':
(.text+0x0): multiple definition of `Tpm2RegisterTpm2DeviceLib'; Tpm2DeviceLibDTpm.obj (symbol from plugin):(.text+0x0): first defined here
collect2: error: ld returned 1 exit status
make: *** [GNUmakefile:375: ...MyApp.dll] Error 1
Can you help me a little more?
I will also create a Bugzilla ticket soon.

Kind regards,
Joseph


joseph@...
 

Oh, this was my mistake.
The above error was because the Tpm2DeviceLib and Tpm2DeviceLibTcg2 libraries were linked both.

Tpm2DeviceLib|SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2DeviceLibDTpm.inf
Tpm2DeviceLibTcg2|SecurityPkg/Library/Tpm2DeviceLibTcg2/Tpm2DeviceLibTcg2.inf
This discussion seems to be resolved.
I need to go to Bugzilla.

Thanks.


Laszlo Ersek
 

On 02/06/21 05:49, joseph via [] wrote:
Hi Laszlo,

Thank you. But the problem is still not solved.

.../edk2/MyPkg/MyPkg.dsc(...): error 1001: Module type [UEFI_APPLICATION] is not supported by
library instance [.../edk2/SecurityPkg/Library/Tcg2PpVendorLibNull/Tcg2PpVendorLibNull.inf]
consumed by [.../edk2/MyPkg/MyApp/MyApp.inf]
After modifying several more steps through the method you suggested, the build was completed.
https://github.com/jc-lab/temp-edk2-tpm2-problem/commit/d9afc8f562d1bda190b27ac8db67df3b0a5bb24a
This is the bug (or, at least "one" bug) in your platform DSC file:

# TPM 2
Tpm2DeviceLib|SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2DeviceLibDTpm.inf
Tpm2DeviceLibTcg2|SecurityPkg/Library/Tpm2DeviceLibTcg2/Tpm2DeviceLibTcg2.inf

There is no such library class as "Tpm2DeviceLibTcg2".


Please refer to the commit message in the following commit:

https://github.com/tianocore/edk2/commit/0c0a50d6b3ff

Specifically, please see the part that starts with "Laszlo Ersek explained on the list why Tpm2DeviceLib..."

Thanks,
Laszlo

But I get the error like below.

/usr/bin/ld: Tpm2DeviceLibTcg2.obj (symbol from plugin): in function `mTcg2Protocol':
(.text+0x0): multiple definition of `Tpm2SubmitCommand'; Tpm2DeviceLibDTpm.obj (symbol from plugin):(.text+0x0): first defined here
/usr/bin/ld: Tpm2DeviceLibTcg2.obj (symbol from plugin): in function `mTcg2Protocol':
(.text+0x0): multiple definition of `Tpm2RequestUseTpm'; Tpm2DeviceLibDTpm.obj (symbol from plugin):(.text+0x0): first defined here
/usr/bin/ld: Tpm2DeviceLibTcg2.obj (symbol from plugin): in function `mTcg2Protocol':
(.text+0x0): multiple definition of `Tpm2RegisterTpm2DeviceLib'; Tpm2DeviceLibDTpm.obj (symbol from plugin):(.text+0x0): first defined here
collect2: error: ld returned 1 exit status
make: *** [GNUmakefile:375: ...MyApp.dll] Error 1
Can you help me a little more?