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: 546686 Delivered-To: patch@linaro.org Received: by 2002:ac0:9f50:0:0:0:0:0 with SMTP id l16csp2674570imf; Mon, 28 Feb 2022 04:07:38 -0800 (PST) X-Google-Smtp-Source: ABdhPJxROhQJovgZgPfLcOSjWs6LtdSTf3GWvzkioJda+t88bu/WLOWD288otzm5fSScsAVN69dU X-Received: by 2002:a50:cfc4:0:b0:413:b19d:d9c0 with SMTP id i4-20020a50cfc4000000b00413b19dd9c0mr5681736edk.384.1646050058068; Mon, 28 Feb 2022 04:07:38 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1646050058; cv=none; d=google.com; s=arc-20160816; b=OEBI8YS7CJlU/gpdM3Q1UdOYT8oD2BFTMALPXunKPGDvZiPODbU/iaPyw9rSo/rEA1 7F1VhKGjNoLfqT94mBNIfbHlP8abxW1smmcDejYCx0koCT7QJI0l/XKZyzC0yAf81CtH w7EQWQGkDZOme1FaVlpwoUtHDNQmYUb9Pqsr43xwuu6aztCAKkZp0ZUvp6NSfcoqvOl0 icM0kh08lf3cQh4NzYCeAYZxl6gI5+jNEsqOSsAruW/Lo1E9O4Y/yO1G7yxb06wkDtsO SEi76zJH5K/PK45yVnVpPOIwH09kARv9QOoPB5IG5J/ykW6fKrlXM2NzYn3sLp8oyo6V KcNQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:message-id:date:subject:cc:to:from; bh=6p7IFNA7CGT0lAypFyf+MGTGxyJL/n6puDqU6Z76LU8=; b=Ijgb+/B6sOoA/DfwK6fQi+7uhmEjiWdwQ0GPNjpyYXudvTBlj/jMaIt4yj1/7kOarO MrHfXc9B83Bd/1CrWBRROyszEKqwrf14130T2/CsuD/weR3gDasmTq+M8xNDtQrrJgsV B2NClROHNmuK5JBXXB9dsNWtoe5Jltl07rL0G9LjmkpUqw69REPlBMxVSGxLatUGcY2i 0sq3ViOjOyIx7VlVkR3g3Z8NVBqlApcqserrwCS9a8Ewyw9lr942AauP6aLxyM5bD8vk WrPvEk/2ihyw53lZ8JDcwe+iPwyBYOdgwjuvwOlTdw7GhqwLXttSZWgI7F8dkiR0XSJK K0XA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from phobos.denx.de (phobos.denx.de. [85.214.62.61]) by mx.google.com with ESMTPS id o3-20020a50fd83000000b00413532cec03si6269052edt.492.2022.02.28.04.07.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 28 Feb 2022 04:07:38 -0800 (PST) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) client-ip=85.214.62.61; Authentication-Results: mx.google.com; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org 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%)