From patchwork Wed Mar 9 12:27:52 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sughosh Ganu X-Patchwork-Id: 549703 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:6713:0:0:0:0 with SMTP id u19csp3514085mag; Wed, 9 Mar 2022 04:28:47 -0800 (PST) X-Google-Smtp-Source: ABdhPJy4WpOe9ylfLunumoXwHB5RTQpGE5ceLyHdGgpmjCniXk/PO+9D3+v0WZrA4Ra5Ec/MY999 X-Received: by 2002:a05:6402:1c02:b0:415:f555:38ba with SMTP id ck2-20020a0564021c0200b00415f55538bamr20620893edb.357.1646828926808; Wed, 09 Mar 2022 04:28:46 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1646828926; cv=none; d=google.com; s=arc-20160816; b=cWkBUn4h3niPLwjpNRcoQ4fjHyGRvlI4tHjUzR9OY8L0npyLtqtt+CjGv45NW7L1sY VpBK/6q1N0zTROJ4/Enrdl4ApinBV/sOW4S8dFy5ewxp9uj5d7QH+4L5xjI61sfy0INF DzEktD+p44Upqdo/O9W6dIiiuF9TJ7N2zKOlVACpMtNj+SF/EfoUdnEDC0o2ztm6qDfg oe17mEoiA9+Bl496sqt/CYWopscaV0JTXCmlP52A1aFTSxzYxP8VSHhxQzm81bjhXAjL rin2WAQTT6sOrjK86DFze8XNLJ6QYZOYz9JFOoBUYCNynARzDA/6zzOFLmhQf0c0fUhO gdjw== 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=PjS9MnQQ25epsxSHDrd4NqEKQ/26zfEqGzPrgOe8lG4=; b=UI+xkfDtkTv0FLAeGXMQCdsVlukU+LW/E66ogo1Bg0t4oJDmBuGJ0tj5jqL51VHAPk k7HeWPGCcaGkG9Ma5jDw6LmJD8lTro+TvYeTibLMNnDMIAjBQpSf6aMv6CuQU48j2EPC 0t8iviQyg+Q7psSfxtvJgxTE4e1YbCmJi2V3Ohf34WCqE793nZ1+GCkxgFRP35gJbGA0 NX/rOb7cMAMhAEaZSNtxd8dqXOtJ6Rmm9OPTme0Qtb/s55hFmtmc047543C6yVGlX/3w 92I70B583DCQ5G/wPnX/kqFWNTU0Avg/NlzH4vyMq2/Sy0J03albD/8CnWUmPElpIJ5t pbMA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 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. [2a01:238:438b:c500:173d:9f52:ddab:ee01]) by mx.google.com with ESMTPS id j20-20020a05640211d400b0041638ad0d45si1417215edw.331.2022.03.09.04.28.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 09 Mar 2022 04:28:46 -0800 (PST) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; Authentication-Results: mx.google.com; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 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 8632783937; Wed, 9 Mar 2022 13:28:40 +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 3E69F8393F; Wed, 9 Mar 2022 13:28:37 +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 4EA6983829 for ; Wed, 9 Mar 2022 13:28:33 +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 85C601688; Wed, 9 Mar 2022 04:28:32 -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 02B463FA4D; Wed, 9 Mar 2022 04:28:30 -0800 (PST) From: Sughosh Ganu To: u-boot@lists.denx.de Cc: Ilias Apalodimas , Simon Glass , Heinrich Schuchardt Subject: [PATCH v4 0/8] tpm: rng: Move TPM RNG functionality to driver model Date: Wed, 9 Mar 2022 17:57:52 +0530 Message-Id: <20220309122800.3940001-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. [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