From patchwork Sun Mar 13 14:47:53 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sughosh Ganu X-Patchwork-Id: 550920 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:6713:0:0:0:0 with SMTP id u19csp1825882mag; Sun, 13 Mar 2022 07:48:59 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwbXtmb4lYba3inSTugOyO/f3vBVkNv94cgKfvULnJ0hLCGDwqaLZwtuJ9G6B/4t1dslqM3 X-Received: by 2002:a17:907:168f:b0:6da:b548:4f9f with SMTP id hc15-20020a170907168f00b006dab5484f9fmr15275044ejc.666.1647182938801; Sun, 13 Mar 2022 07:48:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1647182938; cv=none; d=google.com; s=arc-20160816; b=hZqcTLL/AcFo+6iqSES+521dKcPouuvooGh+gzyNW67dUJu32wjgqGuu5Kx8cTvU4P 8msav4dgn8pA067++lxfrbhjttRFIWi+j40/57yHPQ+R0v2ADub2K+bAzQJrRPapEeDX gG8ViuNsu4601TsR/GjOUAmn+xbQF23/ZOSdaPFYSU2j5SH2E9JQPfWoZnbCsX/p5Qoj mKbGbjZj2JvkEAB/NHRz5/HFesfB+86pFIN6n5Lq9WIDRAaIhm3YzDBFf925vPbH6Ggg roYVraCYSfnEb1KdFrcAF4UZp3H3yZTtckp0UDJpAvXrf23ItYtYCxtKfpZSqV87V+jW n4IQ== 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=ttiFabP1loaupExPLPTjJsSqV4dyy4ruH67ZHmXadmM=; b=zUb3O0INXPToif4WB9gCOuubUQA5XGU6QD6TvCVnSZwS0zeH9tzQtehcwQrrPlGBEr sF2NlAYoggtSr0fOFO1+3YuUUTvZxL64G6+TgB5s/QDuRJZ8y/YrMFeu+RpDM10cJLib K5BoMC97kU1qmN+lTA/+Rg7b5oXDAfmIRLtI1WaWbDpNUezBj79J4fbeGnff6OHTL7Bh 0IS9live/qSu9jnVoOSKq9Eeqq092Q9LQ7DwSnIRDkI8Oa+IF3HPz4zk1qAoS1U2AzmU zWOi+BghsshteZFznInbMiQ3uU+U+iDkWYM1C1dim7mEHPboFznXwCyzDdNfwsj+yhW2 ZK+w== 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 d4-20020a1709063ec400b006b534e7543dsi8087944ejj.105.2022.03.13.07.48.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 13 Mar 2022 07:48:58 -0700 (PDT) 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 656D182DD7; Sun, 13 Mar 2022 15:48:54 +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 E064C8301F; Sun, 13 Mar 2022 15:48:51 +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 048ED80F47 for ; Sun, 13 Mar 2022 15:48:48 +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 DC8C51042; Sun, 13 Mar 2022 07:48:46 -0700 (PDT) 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 53E783F7D7; Sun, 13 Mar 2022 07:48:45 -0700 (PDT) From: Sughosh Ganu To: u-boot@lists.denx.de Cc: Ilias Apalodimas , Simon Glass , Heinrich Schuchardt Subject: [PATCH v5 0/9] tpm: rng: Move TPM RNG functionality to driver model Date: Sun, 13 Mar 2022 20:17:53 +0530 Message-Id: <20220313144802.65687-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 V4: * Call the existing tpm_get_random API function from the TPM RNG driver, instead of the tpm{1,2}_get_random API's * Introduce a new Kconfig symbol TPM_RNG and build the corresponding driver if the symbol is enabled * Change the last parameter of the tpm_get_random API to have a data type of size_t instead of u32 to comply with the RNG driver model API * Put a check for CONFIG_TPM_RNG for binding the RNG device with it's driver in the post_probe callback instead of putting CONFIG_{SPL,TPL}_BUILD guards * Use uclass_get_device_by_seq API to get the RNG device as suggested by Simon * Add a new patch based on review comments from Simon to not use the malloc call * Reflect the fact that a maximum of 64 bytes can be read on each invocation of the 'rng' command in the rng document Sughosh Ganu (9): 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 cmd: rng: Use a statically allocated array for random bytes 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 | 42 ++++++++++++++++++----------- doc/usage/index.rst | 1 + doc/usage/rng.rst | 26 ++++++++++++++++++ drivers/rng/Kconfig | 7 +++++ drivers/rng/Makefile | 1 + drivers/rng/tpm_rng.c | 23 ++++++++++++++++ drivers/tpm/tpm-uclass.c | 29 +++++++++++++++++--- 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 | 19 ++++++++----- test/dm/rng.c | 29 ++++++++++++++++++++ 17 files changed, 175 insertions(+), 85 deletions(-) create mode 100644 doc/usage/rng.rst create mode 100644 drivers/rng/tpm_rng.c