diff mbox series

[v2,06/10] configs: chromebook_coral: Build TPMV1 library routines

Message ID 20220228120638.678137-7-sughosh.ganu@linaro.org
State New
Headers show
Series tpm: rng: Move TPM RNG functionality to driver model | expand

Commit Message

Sughosh Ganu Feb. 28, 2022, 12:06 p.m. UTC
The TPM code currently does a runtime detection of the TPM version and
calls appropriate functions. Chromebook Coral is one of the platforms
where the TPMV1 code is disabled at build time. With this, calling TPM
api's from the TPM uclass driver results in link errors. Enable TPMV1
library routines and determine the TPM version at runtime like other
platforms.

Signed-off-by: Sughosh Ganu <sughosh.ganu@linaro.org>
---

Changes since V1: None

 configs/chromebook_coral_defconfig | 1 -
 1 file changed, 1 deletion(-)

Comments

Simon Glass March 1, 2022, 2:58 p.m. UTC | #1
Hi Sughosh,

On Mon, 28 Feb 2022 at 05:07, Sughosh Ganu <sughosh.ganu@linaro.org> wrote:
>
> The TPM code currently does a runtime detection of the TPM version and
> calls appropriate functions. Chromebook Coral is one of the platforms
> where the TPMV1 code is disabled at build time. With this, calling TPM
> api's from the TPM uclass driver results in link errors. Enable TPMV1
> library routines and determine the TPM version at runtime like other
> platforms.
>
> Signed-off-by: Sughosh Ganu <sughosh.ganu@linaro.org>
> ---
>
> Changes since V1: None
>
>  configs/chromebook_coral_defconfig | 1 -
>  1 file changed, 1 deletion(-)
>
> diff --git a/configs/chromebook_coral_defconfig b/configs/chromebook_coral_defconfig
> index 0cd8f39aa3..4704ce25c8 100644
> --- a/configs/chromebook_coral_defconfig
> +++ b/configs/chromebook_coral_defconfig
> @@ -104,7 +104,6 @@ CONFIG_SPI=y
>  CONFIG_ICH_SPI=y
>  # CONFIG_SYSINFO_SMBIOS is not set
>  CONFIG_TPL_SYSRESET=y
> -# CONFIG_TPM_V1 is not set
>  CONFIG_TPM2_CR50_I2C=y
>  CONFIG_USB_XHCI_HCD=y
>  CONFIG_USB_STORAGE=y
> --
> 2.25.1

This board does not have a v1 TPM so we don't want to waste code space
adding it.

The current code works fine and supports both a build-time and
run-time check. What has gone wrong?

Regards,
Simon
Sughosh Ganu March 2, 2022, 4:50 a.m. UTC | #2
hi Simon,

On Tue, 1 Mar 2022 at 20:29, Simon Glass <sjg@chromium.org> wrote:
>
> Hi Sughosh,
>
> On Mon, 28 Feb 2022 at 05:07, Sughosh Ganu <sughosh.ganu@linaro.org> wrote:
> >
> > The TPM code currently does a runtime detection of the TPM version and
> > calls appropriate functions. Chromebook Coral is one of the platforms
> > where the TPMV1 code is disabled at build time. With this, calling TPM
> > api's from the TPM uclass driver results in link errors. Enable TPMV1
> > library routines and determine the TPM version at runtime like other
> > platforms.
> >
> > Signed-off-by: Sughosh Ganu <sughosh.ganu@linaro.org>
> > ---
> >
> > Changes since V1: None
> >
> >  configs/chromebook_coral_defconfig | 1 -
> >  1 file changed, 1 deletion(-)
> >
> > diff --git a/configs/chromebook_coral_defconfig b/configs/chromebook_coral_defconfig
> > index 0cd8f39aa3..4704ce25c8 100644
> > --- a/configs/chromebook_coral_defconfig
> > +++ b/configs/chromebook_coral_defconfig
> > @@ -104,7 +104,6 @@ CONFIG_SPI=y
> >  CONFIG_ICH_SPI=y
> >  # CONFIG_SYSINFO_SMBIOS is not set
> >  CONFIG_TPL_SYSRESET=y
> > -# CONFIG_TPM_V1 is not set
> >  CONFIG_TPM2_CR50_I2C=y
> >  CONFIG_USB_XHCI_HCD=y
> >  CONFIG_USB_STORAGE=y
> > --
> > 2.25.1
>
> This board does not have a v1 TPM so we don't want to waste code space
> adding it.

Yes, but because the version detection is happening at runtime, we
need both the files to be compiled if we call any of the tpm api from
outside lib/tpm. When I call the tpm_startup function from the
child_pre_probe callback in tpm-uclass.c, I get link errors for the
TPM v2 functions. Similarly for Gazerbeam board.

>
> The current code works fine and supports both a build-time and
> run-time check. What has gone wrong?

Does not work when an api is called from the tpm uclass driver.

-sughosh

>
> Regards,
> Simon
Simon Glass March 2, 2022, 3:32 p.m. UTC | #3
Hi Sughosh,

On Tue, 1 Mar 2022 at 21:50, Sughosh Ganu <sughosh.ganu@linaro.org> wrote:
>
> hi Simon,
>
> On Tue, 1 Mar 2022 at 20:29, Simon Glass <sjg@chromium.org> wrote:
> >
> > Hi Sughosh,
> >
> > On Mon, 28 Feb 2022 at 05:07, Sughosh Ganu <sughosh.ganu@linaro.org> wrote:
> > >
> > > The TPM code currently does a runtime detection of the TPM version and
> > > calls appropriate functions. Chromebook Coral is one of the platforms
> > > where the TPMV1 code is disabled at build time. With this, calling TPM
> > > api's from the TPM uclass driver results in link errors. Enable TPMV1
> > > library routines and determine the TPM version at runtime like other
> > > platforms.
> > >
> > > Signed-off-by: Sughosh Ganu <sughosh.ganu@linaro.org>
> > > ---
> > >
> > > Changes since V1: None
> > >
> > >  configs/chromebook_coral_defconfig | 1 -
> > >  1 file changed, 1 deletion(-)
> > >
> > > diff --git a/configs/chromebook_coral_defconfig b/configs/chromebook_coral_defconfig
> > > index 0cd8f39aa3..4704ce25c8 100644
> > > --- a/configs/chromebook_coral_defconfig
> > > +++ b/configs/chromebook_coral_defconfig
> > > @@ -104,7 +104,6 @@ CONFIG_SPI=y
> > >  CONFIG_ICH_SPI=y
> > >  # CONFIG_SYSINFO_SMBIOS is not set
> > >  CONFIG_TPL_SYSRESET=y
> > > -# CONFIG_TPM_V1 is not set
> > >  CONFIG_TPM2_CR50_I2C=y
> > >  CONFIG_USB_XHCI_HCD=y
> > >  CONFIG_USB_STORAGE=y
> > > --
> > > 2.25.1
> >
> > This board does not have a v1 TPM so we don't want to waste code space
> > adding it.
>
> Yes, but because the version detection is happening at runtime, we
> need both the files to be compiled if we call any of the tpm api from
> outside lib/tpm. When I call the tpm_startup function from the
> child_pre_probe callback in tpm-uclass.c, I get link errors for the
> TPM v2 functions. Similarly for Gazerbeam board.
>
> >
> > The current code works fine and supports both a build-time and
> > run-time check. What has gone wrong?
>
> Does not work when an api is called from the tpm uclass driver.

OK, I see, then the tpm_is_v1() functions need to stay in the header
file, to fix that.

Regards,
Simon
Sughosh Ganu March 2, 2022, 6:12 p.m. UTC | #4
hi Simon,

On Wed, 2 Mar 2022 at 21:02, Simon Glass <sjg@chromium.org> wrote:
>
> Hi Sughosh,
>
> On Tue, 1 Mar 2022 at 21:50, Sughosh Ganu <sughosh.ganu@linaro.org> wrote:
> >
> > hi Simon,
> >
> > On Tue, 1 Mar 2022 at 20:29, Simon Glass <sjg@chromium.org> wrote:
> > >
> > > Hi Sughosh,
> > >
> > > On Mon, 28 Feb 2022 at 05:07, Sughosh Ganu <sughosh.ganu@linaro.org> wrote:
> > > >
> > > > The TPM code currently does a runtime detection of the TPM version and
> > > > calls appropriate functions. Chromebook Coral is one of the platforms
> > > > where the TPMV1 code is disabled at build time. With this, calling TPM
> > > > api's from the TPM uclass driver results in link errors. Enable TPMV1
> > > > library routines and determine the TPM version at runtime like other
> > > > platforms.
> > > >
> > > > Signed-off-by: Sughosh Ganu <sughosh.ganu@linaro.org>
> > > > ---
> > > >
> > > > Changes since V1: None
> > > >
> > > >  configs/chromebook_coral_defconfig | 1 -
> > > >  1 file changed, 1 deletion(-)
> > > >
> > > > diff --git a/configs/chromebook_coral_defconfig b/configs/chromebook_coral_defconfig
> > > > index 0cd8f39aa3..4704ce25c8 100644
> > > > --- a/configs/chromebook_coral_defconfig
> > > > +++ b/configs/chromebook_coral_defconfig
> > > > @@ -104,7 +104,6 @@ CONFIG_SPI=y
> > > >  CONFIG_ICH_SPI=y
> > > >  # CONFIG_SYSINFO_SMBIOS is not set
> > > >  CONFIG_TPL_SYSRESET=y
> > > > -# CONFIG_TPM_V1 is not set
> > > >  CONFIG_TPM2_CR50_I2C=y
> > > >  CONFIG_USB_XHCI_HCD=y
> > > >  CONFIG_USB_STORAGE=y
> > > > --
> > > > 2.25.1
> > >
> > > This board does not have a v1 TPM so we don't want to waste code space
> > > adding it.
> >
> > Yes, but because the version detection is happening at runtime, we
> > need both the files to be compiled if we call any of the tpm api from
> > outside lib/tpm. When I call the tpm_startup function from the
> > child_pre_probe callback in tpm-uclass.c, I get link errors for the
> > TPM v2 functions. Similarly for Gazerbeam board.
> >
> > >
> > > The current code works fine and supports both a build-time and
> > > run-time check. What has gone wrong?
> >
> > Does not work when an api is called from the tpm uclass driver.
>
> OK, I see, then the tpm_is_v1() functions need to stay in the header
> file, to fix that.

The link errors are not for the tpm_is_v{1,2} functions -- I had
already moved them to the tpm uclass driver in a previous patch of my
patchset. The link errors are for the tpm{1,2}_startup functions being
undefined for the chromebook_coral and gazerboam platforms. I think
when the tpm_startup function is getting called from within the same
module(lib/tpm) the compiler optimises out the calls to the
non-existing functions. But when called from a different directory,
like the tpm uclass driver in my case, we get link errors.

-sughosh

>
> Regards,
> Simon
Simon Glass March 3, 2022, 3:47 a.m. UTC | #5
Hi Sughosh,

On Wed, 2 Mar 2022 at 11:12, Sughosh Ganu <sughosh.ganu@linaro.org> wrote:
>
> hi Simon,
>
> On Wed, 2 Mar 2022 at 21:02, Simon Glass <sjg@chromium.org> wrote:
> >
> > Hi Sughosh,
> >
> > On Tue, 1 Mar 2022 at 21:50, Sughosh Ganu <sughosh.ganu@linaro.org> wrote:
> > >
> > > hi Simon,
> > >
> > > On Tue, 1 Mar 2022 at 20:29, Simon Glass <sjg@chromium.org> wrote:
> > > >
> > > > Hi Sughosh,
> > > >
> > > > On Mon, 28 Feb 2022 at 05:07, Sughosh Ganu <sughosh.ganu@linaro.org> wrote:
> > > > >
> > > > > The TPM code currently does a runtime detection of the TPM version and
> > > > > calls appropriate functions. Chromebook Coral is one of the platforms
> > > > > where the TPMV1 code is disabled at build time. With this, calling TPM
> > > > > api's from the TPM uclass driver results in link errors. Enable TPMV1
> > > > > library routines and determine the TPM version at runtime like other
> > > > > platforms.
> > > > >
> > > > > Signed-off-by: Sughosh Ganu <sughosh.ganu@linaro.org>
> > > > > ---
> > > > >
> > > > > Changes since V1: None
> > > > >
> > > > >  configs/chromebook_coral_defconfig | 1 -
> > > > >  1 file changed, 1 deletion(-)
> > > > >
> > > > > diff --git a/configs/chromebook_coral_defconfig b/configs/chromebook_coral_defconfig
> > > > > index 0cd8f39aa3..4704ce25c8 100644
> > > > > --- a/configs/chromebook_coral_defconfig
> > > > > +++ b/configs/chromebook_coral_defconfig
> > > > > @@ -104,7 +104,6 @@ CONFIG_SPI=y
> > > > >  CONFIG_ICH_SPI=y
> > > > >  # CONFIG_SYSINFO_SMBIOS is not set
> > > > >  CONFIG_TPL_SYSRESET=y
> > > > > -# CONFIG_TPM_V1 is not set
> > > > >  CONFIG_TPM2_CR50_I2C=y
> > > > >  CONFIG_USB_XHCI_HCD=y
> > > > >  CONFIG_USB_STORAGE=y
> > > > > --
> > > > > 2.25.1
> > > >
> > > > This board does not have a v1 TPM so we don't want to waste code space
> > > > adding it.
> > >
> > > Yes, but because the version detection is happening at runtime, we
> > > need both the files to be compiled if we call any of the tpm api from
> > > outside lib/tpm. When I call the tpm_startup function from the
> > > child_pre_probe callback in tpm-uclass.c, I get link errors for the
> > > TPM v2 functions. Similarly for Gazerbeam board.
> > >
> > > >
> > > > The current code works fine and supports both a build-time and
> > > > run-time check. What has gone wrong?
> > >
> > > Does not work when an api is called from the tpm uclass driver.
> >
> > OK, I see, then the tpm_is_v1() functions need to stay in the header
> > file, to fix that.
>
> The link errors are not for the tpm_is_v{1,2} functions -- I had
> already moved them to the tpm uclass driver in a previous patch of my
> patchset. The link errors are for the tpm{1,2}_startup functions being
> undefined for the chromebook_coral and gazerboam platforms. I think
> when the tpm_startup function is getting called from within the same
> module(lib/tpm) the compiler optimises out the calls to the
> non-existing functions. But when called from a different directory,
> like the tpm uclass driver in my case, we get link errors.

I don't think that is right, sorry.

Regards,
Simon
diff mbox series

Patch

diff --git a/configs/chromebook_coral_defconfig b/configs/chromebook_coral_defconfig
index 0cd8f39aa3..4704ce25c8 100644
--- a/configs/chromebook_coral_defconfig
+++ b/configs/chromebook_coral_defconfig
@@ -104,7 +104,6 @@  CONFIG_SPI=y
 CONFIG_ICH_SPI=y
 # CONFIG_SYSINFO_SMBIOS is not set
 CONFIG_TPL_SYSRESET=y
-# CONFIG_TPM_V1 is not set
 CONFIG_TPM2_CR50_I2C=y
 CONFIG_USB_XHCI_HCD=y
 CONFIG_USB_STORAGE=y