mbox series

[v2,00/10] tpm: rng: Move TPM RNG functionality to driver model

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

Message

Sughosh Ganu Feb. 28, 2022, 12:06 p.m. UTC
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.

Changes since V1:
* Added existing copyrights for the rng functions taken from the tpm
  library routines
* Return -EIO for TPM command returning an error
* Simplify the logic in tpm_get_random based on the review comments
  from Ilias
* Changed the help text to show order of the parameters passed
  to the rng command, based on review comment from Heinrich


[1] - https://lore.kernel.org/u-boot/20220103120738.47835-1-ilias.apalodimas@linaro.org/


Sughosh Ganu (10):
  tpm: Move tpm-utils header under the include directory
  tpm: rng: Change tpm_get_random to return an int
  tpm: Fix the return type of tpm_startup
  tpm: Move the TPM version detection functions to the uclass driver
  configs: gazerbeam: Build TPMV2 library routines
  configs: chromebook_coral: Build TPMV1 library routines
  tpm: rng: Move the TPM RNG functionality to driver model
  tpm: Add the RNG child device
  qemu: arm: Remove platform specific function to get RNG device
  cmd: rng: Add support for selecting RNG device

 board/emulation/qemu-arm/qemu-arm.c | 42 --------------
 cmd/rng.c                           | 31 +++++++---
 configs/chromebook_coral_defconfig  |  1 -
 configs/gazerbeam_defconfig         |  1 -
 drivers/rng/Makefile                |  1 +
 drivers/rng/tpm1_rng.c              | 87 +++++++++++++++++++++++++++++
 drivers/rng/tpm2_rng.c              | 86 ++++++++++++++++++++++++++++
 drivers/tpm/tpm-uclass.c            | 69 +++++++++++++++++++++--
 {lib => include}/tpm-utils.h        |  0
 include/tpm_api.h                   | 26 ++++++++-
 lib/tpm-common.c                    |  2 +-
 lib/tpm-v1.c                        | 46 +--------------
 lib/tpm-v2.c                        | 46 +--------------
 lib/tpm_api.c                       | 37 ++++++------
 14 files changed, 309 insertions(+), 166 deletions(-)
 create mode 100644 drivers/rng/tpm1_rng.c
 create mode 100644 drivers/rng/tpm2_rng.c
 rename {lib => include}/tpm-utils.h (100%)