From patchwork Mon Feb 28 12:06:28 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sughosh Ganu X-Patchwork-Id: 1598824 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=85.214.62.61; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4K6fJv5fqkz9s0r for ; Mon, 28 Feb 2022 23:07:41 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 4D1B183A9B; Mon, 28 Feb 2022 13:07:33 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Received: by phobos.denx.de (Postfix, from userid 109) id 8B1D1838D6; Mon, 28 Feb 2022 13:07:31 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-1.2 required=5.0 tests=BAYES_00,SPF_HELO_NONE, SPF_SOFTFAIL,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.2 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by phobos.denx.de (Postfix) with ESMTP id 2432F81DD0 for ; Mon, 28 Feb 2022 13:07:27 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=fail smtp.mailfrom=sughosh.ganu@linaro.org Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 1E837ED1; Mon, 28 Feb 2022 04:07:26 -0800 (PST) Received: from a076522.blr.arm.com (a076522.blr.arm.com [10.162.16.44]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 712BB3F73D; Mon, 28 Feb 2022 04:07:24 -0800 (PST) From: Sughosh Ganu To: u-boot@lists.denx.de Cc: Ilias Apalodimas , Simon Glass , Heinrich Schuchardt , Mario Six Subject: [PATCH v2 00/10] tpm: rng: Move TPM RNG functionality to driver model Date: Mon, 28 Feb 2022 17:36:28 +0530 Message-Id: <20220228120638.678137-1-sughosh.ganu@linaro.org> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.5 at phobos.denx.de X-Virus-Status: Clean 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%)