[PATCH] rng: tpm_rng: start TPM before reading random numbers

Ilias Apalodimas ilias.apalodimas at linaro.org
Tue Jun 9 12:36:08 CEST 2026


Hi Padmarao


On Tue, 9 Jun 2026 at 13:10, Padmarao Begari <padmarao.begari at amd.com> wrote:
>
> The tpm-rng driver calls tpm_get_random() without first ensuring the
> TPM device is opened and started. When systemd-boot or fdt_fixup_kaslr
> triggers an RNG read early in boot, the TPM2 device hasn't been
> initialized yet, causing the command to fail:

Is systemd_boot called via EFI? If so the TPM should be up already.
About fdt_fixup_kaslr(), why do you need this? We specifically clear
the kaslr-seed when booting via EFI and EFI_RNG is installed, since
the kernel ignores it.

Thanks
/Ilias
>
>   tpm-rng tpm-rng: dm_rng_read failed: -1
>
> Fix this by calling tpm_auto_start() on the parent TPM device before
> tpm_get_random(). This ensures the TPM is initialized before use.
>
> Fixes: e67ffb5aa5ab ("tpm: rng: Add driver model interface for TPM RNG device")
> Signed-off-by: Padmarao Begari <padmarao.begari at amd.com>
> ---
>  drivers/rng/tpm_rng.c | 10 +++++++++-
>  1 file changed, 9 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/rng/tpm_rng.c b/drivers/rng/tpm_rng.c
> index 1a5e9e2e4b4..374e0ac1ff8 100644
> --- a/drivers/rng/tpm_rng.c
> +++ b/drivers/rng/tpm_rng.c
> @@ -4,12 +4,20 @@
>   */
>
>  #include <dm.h>
> +#include <log.h>
>  #include <rng.h>
>  #include <tpm_api.h>
>
>  static int rng_tpm_random_read(struct udevice *dev, void *data, size_t count)
>  {
> -       return tpm_get_random(dev_get_parent(dev), data, count);
> +       struct udevice *tpm_dev = dev_get_parent(dev);
> +       u32 rc;
> +
> +       rc = tpm_auto_start(tpm_dev);
> +       if (rc)
> +               return log_msg_ret("start", -EIO);
> +
> +       return tpm_get_random(tpm_dev, data, count);
>  }
>
>  static const struct dm_rng_ops tpm_rng_ops = {
> --
> 2.34.1
>


More information about the U-Boot mailing list