From patchwork Fri Mar 4 13:34:21 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sughosh Ganu X-Patchwork-Id: 548111 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:6713:0:0:0:0 with SMTP id u19csp21356mag; Fri, 4 Mar 2022 05:35:18 -0800 (PST) X-Google-Smtp-Source: ABdhPJytzIKSkn4jUhTB76KRDAJ+r1vX31yUlKkGs/ar1cQrvo/k9/yBpEmo0gsZuvPC4e777l2B X-Received: by 2002:a17:906:1193:b0:6cf:cf06:3f7d with SMTP id n19-20020a170906119300b006cfcf063f7dmr31374780eja.177.1646400917949; Fri, 04 Mar 2022 05:35:17 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1646400917; cv=none; d=google.com; s=arc-20160816; b=uayG2ZZ+RBz4QieJnTq5a2jzaQJRELvZyxno16LjYPLBgOjgMRpgo+jcTXaVAIrwoj uQacu5JtqbIs5rcppurvE//xVfFitfAEx7v9pxqV+rAuzUwANiTa+DkWEGpKFBW6Wijg dppcNg49YeqjSf2ldGJVoG8AdhIMr4/Dz2Mj1g9Bwcu7MqJFWoj2rSzCuLKbjEkqvUr7 mAgS3uS+UAgCJQqoZDdtuV2AW0JVgpc5X7thdYBEuHhavmo1hxBKgJxqj6Xmum7Rv/+r pQm+/BV1Vo+ABTW4qFugDTvi8Z1Hj7ttiCui2wjfYeYV/yZtbYxLDy0msnRkLw1JVaC+ al1g== 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=AWrN16QjmQJFduK+8KJ9hWtkAKXuXxpZE1hMouYuvtg=; b=p6aZRWL7DI0WFSVqLRkw34vHMFyCaDeVf1ElAre82cyb3aa4chyIKExf2SPCudGUyT N9ZIbOwUxvTEz5xIzGuqEzqSH9Z94kg4q5gg2/gnp3qwwuUAC69bc57ttrRCo/B5qAcf 3UeOx4acGo7uJhJzeSM8ZnwmZwM24oUErXh7usUVY4p7xnSRAP8PpLCYyE+maSJRnoqI GnYZjYEV4XE6RDTJOGXTIco3fcA/mpbk02Zuxc+7UUjjzgliHMoNVpGtLp4JrlvPZGHD gAD0JGtdg8JOTSfnSRaDXcWlQMcvETY6tQqFtJn7pLz8FkVLSoogG8mFVTxL0S2qQXWd zltw== 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 nb37-20020a1709071ca500b006d879078330si4117117ejc.246.2022.03.04.05.35.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Mar 2022 05:35:17 -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 9393583D17; Fri, 4 Mar 2022 14:35:12 +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 E50C483D05; Fri, 4 Mar 2022 14:35:05 +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 2B34B83B6C for ; Fri, 4 Mar 2022 14:35:01 +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 493211396; Fri, 4 Mar 2022 05:35:00 -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 D56A23F70D; Fri, 4 Mar 2022 05:34:58 -0800 (PST) From: Sughosh Ganu To: u-boot@lists.denx.de Cc: Ilias Apalodimas , Simon Glass , Heinrich Schuchardt Subject: [PATCH v3 0/8] tpm: rng: Move TPM RNG functionality to driver model Date: Fri, 4 Mar 2022 19:04:21 +0530 Message-Id: <20220304133429.1047752-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. 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. Using this patch, a couple of patches[3][4] from the series are no longer needed. [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 [3] - https://lore.kernel.org/u-boot/20220228120638.678137-7-sughosh.ganu@linaro.org/T/#u [4] - https://lore.kernel.org/u-boot/20220228120638.678137-6-sughosh.ganu@linaro.org/T/#u Changes since V2: * Export the existing tpm*_get_random functions to the driver model instead of moving them to the drivers/rng/ directory. * Enable DM_RNG when CONFIG_TPM is enabled to build the RNG uclass code * Additional patch for a document for the 'rng' command as suggested by Simon Glass * Additional patch for unit test for the 'rng' command as suggested by Simon Glass 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/tpm/tpm-uclass.c | 60 +++++++++++++++++++++++++++-- include/tpm-v1.h | 4 +- include/tpm-v2.h | 4 +- include/tpm_api.h | 6 +-- lib/Kconfig | 1 + lib/tpm-v1.c | 28 ++++++++++---- lib/tpm-v2.c | 21 +++++++--- lib/tpm_api.c | 28 +++++++++++--- test/dm/rng.c | 29 ++++++++++++++ 14 files changed, 201 insertions(+), 80 deletions(-) create mode 100644 doc/usage/rng.rst