[PATCH v5 0/9] tpm: rng: Move TPM RNG functionality to driver model

Sughosh Ganu sughosh.ganu at linaro.org
Sun Mar 13 15:47:53 CET 2022


The TPM device provides the random number generator(RNG)
functionality, whereby sending a command to the TPM device results in
the TPM device responding with random bytes.

There was a discussion on the mailing list earlier[1], where it was
explained that platforms with a TPM device can install the
EFI_RNG_PROTOCOL for getting the random bytes instead of populating
the dtb with the kaslr-seed property. That would make it possible to
measure the dtb.

This patchset moves the already existing functions for getting random
bytes from the TPM device to drivers complying with the RNG
uclass. This is done since the EFI_RNG_PROTOCOL's get_rng routine uses
the RNG uclass's dm_rng_read api to get the random bytes.

The TPM uclass driver adds the RNG child device as part of it's
post_probe function. The TPM uclass driver's child_pre_probe function
initialises the TPM parent device for use -- this enables the RNG
child device to be used subsequently.

Some additional changes have also been made to facilitate the
use of the RNG devices, including extending the 'rng' command to take
the RNG device as one of the command-line parameters.

This series depends on a patch[2] from Simon Glass for moving the TPM
device version detection functions to the tpm_api.h header as static
inline functions.
[1] - https://lore.kernel.org/u-boot/20220103120738.47835-1-ilias.apalodimas@linaro.org/
[2] - https://lore.kernel.org/u-boot/20220301001125.1554442-2-sjg@chromium.org/T/#u

Changes since V4:

* Call the existing tpm_get_random API function from the TPM RNG
  driver, instead of the tpm{1,2}_get_random API's
* Introduce a new Kconfig symbol TPM_RNG and build the corresponding
  driver if the symbol is enabled
* Change the last parameter of the tpm_get_random API to have a data
  type of size_t instead of u32 to comply with the RNG driver model
  API
* Put a check for CONFIG_TPM_RNG for binding the RNG device with it's
  driver in the post_probe callback instead of putting
  CONFIG_{SPL,TPL}_BUILD guards
* Use uclass_get_device_by_seq API to get the RNG device as suggested
  by Simon
* Add a new patch based on review comments from Simon to not use the
  malloc call
* Reflect the fact that a maximum of 64 bytes can be read on each
  invocation of the 'rng' command in the rng document


Sughosh Ganu (9):
  tpm: rng: Change tpm_get_random to return an int
  tpm: Fix the return type of tpm_startup
  tpm: rng: Add driver model interface for TPM RNG device
  tpm: Add the RNG child device
  qemu: arm: Remove platform specific function to get RNG device
  cmd: rng: Add support for selecting RNG device
  cmd: rng: Use a statically allocated array for random bytes
  doc: rng: Add documentation for the rng command
  test: rng: Add a UT testcase for the rng command

 board/emulation/qemu-arm/qemu-arm.c | 42 -----------------------------
 cmd/Kconfig                         |  1 +
 cmd/rng.c                           | 42 ++++++++++++++++++-----------
 doc/usage/index.rst                 |  1 +
 doc/usage/rng.rst                   | 26 ++++++++++++++++++
 drivers/rng/Kconfig                 |  7 +++++
 drivers/rng/Makefile                |  1 +
 drivers/rng/tpm_rng.c               | 23 ++++++++++++++++
 drivers/tpm/tpm-uclass.c            | 29 +++++++++++++++++---
 include/tpm-v1.h                    |  4 +--
 include/tpm-v2.h                    |  4 +--
 include/tpm_api.h                   |  6 ++---
 lib/Kconfig                         |  1 +
 lib/tpm-v1.c                        | 16 ++++++-----
 lib/tpm-v2.c                        |  9 ++++---
 lib/tpm_api.c                       | 19 ++++++++-----
 test/dm/rng.c                       | 29 ++++++++++++++++++++
 17 files changed, 175 insertions(+), 85 deletions(-)
 create mode 100644 doc/usage/rng.rst
 create mode 100644 drivers/rng/tpm_rng.c

-- 
2.25.1




More information about the U-Boot mailing list