[PATCH v4 0/8] tpm: rng: Move TPM RNG functionality to driver model
Sughosh Ganu
sughosh.ganu at linaro.org
Wed Mar 9 13:27:52 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 V3:
* Move back the driver model interface for the TPM RNG devices under
drivers/rng/ directory.
* Add a rng read function for the tpm devices which calls the
tpm*_get_random API's.
* Pass the TPM device pointer to the tpm*_get_random API's from the
TPM RNG drivers as suggested by Simon.
* Build the RNG child addition only for the u-boot proper stage using
the CONFIG_{SPL,TPL}_BUILD guards instead of CONFIG_TPM config which
gets included in all stages.
* Remove the child_pre_probe callback which was starting the TPM
device based on review from Simon.
Sughosh Ganu (8):
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
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 | 31 +++++++++++++++------
doc/usage/index.rst | 1 +
doc/usage/rng.rst | 25 +++++++++++++++++
drivers/rng/Makefile | 2 ++
drivers/rng/tpm1_rng.c | 24 +++++++++++++++++
drivers/rng/tpm2_rng.c | 23 ++++++++++++++++
drivers/tpm/tpm-uclass.c | 40 ++++++++++++++++++++++++---
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 | 28 ++++++++++++++-----
test/dm/rng.c | 29 ++++++++++++++++++++
17 files changed, 208 insertions(+), 78 deletions(-)
create mode 100644 doc/usage/rng.rst
create mode 100644 drivers/rng/tpm1_rng.c
create mode 100644 drivers/rng/tpm2_rng.c
--
2.25.1
More information about the U-Boot
mailing list