From patchwork Fri Mar 4 13:34:22 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sughosh Ganu X-Patchwork-Id: 548112 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:6713:0:0:0:0 with SMTP id u19csp21589mag; Fri, 4 Mar 2022 05:35:35 -0800 (PST) X-Google-Smtp-Source: ABdhPJw0q3ffw4vyfCDMG/Wdpr5VGa4kiUwt8WvaNBFz2kZzFuCsfTYXK7pyDwvdQto+fQ7zUaMd X-Received: by 2002:aa7:c687:0:b0:415:eb43:8ff5 with SMTP id n7-20020aa7c687000000b00415eb438ff5mr6161277edq.74.1646400934865; Fri, 04 Mar 2022 05:35:34 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1646400934; cv=none; d=google.com; s=arc-20160816; b=G8Bt8o7mH/E6x5n2lJoJJTC/WAGQQQDSwfN8/3r3kmxTkm0uoYaQccQa8vL8FR21RB Q12M1n8Sim0F6xAhCIcw4gXi62DOuhNaANY7LisYHdXRWoFiONjoq2l7WeqeOrQYLrVf sbTz6X2BPiVAyar6FWCVJGKY36If0DFvY54rbPovf7n57C9/SURKtGV9pzivOB2tWifP InaXAzIIpk9U7xAOitOtHbabENG6MuRGy4DT3g+ekFOAqsXlIwfCJdvi3HkCbnmj6f56 h+Igc6ZmkJ+KsXG16W2eykkHbWc2du6CWrbY+lcREHOvQB1Px2Fnddr5nYFo0pHPo1yx CHUg== 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:references:in-reply-to:message-id:date:subject:cc:to :from; bh=0qRbX1HZpHkNcjxdv/2LII3ImJrqt3SThpAUHHPQbhU=; b=m1AuZCIIJu9Hj+vJJkFMI9g4pfBGr0Il4ocD2IeYeWs05rS6oKyIyqYpWyqYnkNfED XGM2T0RGTJNzKpKrLjz3j/yyQ4B6X0//UMHkni9o7KjtNSJBPOLmX59x0F1CNjpnmKgj Yhl26HLGUMvCbUjy8GKh+rPTNugh8k8s8PP64dTpVQsSJFWr0/J23MKXQTyMFSSoUmog rDiXg656QRiKnk4DhW+rLJ1d3rhJUv16QdoBWlZzLdRGTWwHZ73I7l4IltROELHC5U4w hIbGsDDIxk44+YXpOKqZ8YBBExJGCbBlhFquowgJ7h1IfcLWhcM6a+hHH2zvmdzi3+1U MgZg== 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 10-20020a170906318a00b006d1ddb409bdsi3188698ejy.32.2022.03.04.05.35.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Mar 2022 05:35:34 -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 6FA6E83D3D; Fri, 4 Mar 2022 14:35:17 +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 785BE83B6C; Fri, 4 Mar 2022 14:35:08 +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 16DC483CB4 for ; Fri, 4 Mar 2022 14:35:03 +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 647841396; Fri, 4 Mar 2022 05:35:02 -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 B89183F70D; Fri, 4 Mar 2022 05:35:00 -0800 (PST) From: Sughosh Ganu To: u-boot@lists.denx.de Cc: Ilias Apalodimas , Simon Glass , Heinrich Schuchardt , Sughosh Ganu Subject: [PATCH v3 1/8] tpm: rng: Change tpm_get_random to return an int Date: Fri, 4 Mar 2022 19:04:22 +0530 Message-Id: <20220304133429.1047752-2-sughosh.ganu@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220304133429.1047752-1-sughosh.ganu@linaro.org> References: <20220304133429.1047752-1-sughosh.ganu@linaro.org> 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 random number generation functionality will be moved to the driver model. With that, the tpm_get_random function will call the common driver model api instead of separate functions for tpmv1 and tpmv2. Return an int instead of a u32 to comply with the return value of the driver model function. Signed-off-by: Sughosh Ganu Reviewed-by: Heinrich Schuchardt Reviewed-by: Simon Glass Reviewed-by: Ilias Apalodimas --- Changes since V2: None include/tpm_api.h | 4 ++-- lib/tpm_api.c | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/include/tpm_api.h b/include/tpm_api.h index 11aa14eb79..249a966942 100644 --- a/include/tpm_api.h +++ b/include/tpm_api.h @@ -274,9 +274,9 @@ u32 tpm_find_key_sha1(struct udevice *dev, const u8 auth[20], * @param dev TPM device * @param data output buffer for the random bytes * @param count size of output buffer - * Return: return code of the operation + * Return: 0 if OK, -ve on error */ -u32 tpm_get_random(struct udevice *dev, void *data, u32 count); +int tpm_get_random(struct udevice *dev, void *data, u32 count); /** * tpm_finalise_physical_presence() - Finalise physical presence diff --git a/lib/tpm_api.c b/lib/tpm_api.c index 4ac4612c81..7d26ea2c3a 100644 --- a/lib/tpm_api.c +++ b/lib/tpm_api.c @@ -264,7 +264,7 @@ u32 tpm_get_permissions(struct udevice *dev, u32 index, u32 *perm) return -ENOSYS; } -u32 tpm_get_random(struct udevice *dev, void *data, u32 count) +int tpm_get_random(struct udevice *dev, void *data, u32 count) { if (tpm_is_v1(dev)) return tpm1_get_random(dev, data, count); From patchwork Fri Mar 4 13:34:23 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sughosh Ganu X-Patchwork-Id: 548113 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:6713:0:0:0:0 with SMTP id u19csp21788mag; Fri, 4 Mar 2022 05:35:46 -0800 (PST) X-Google-Smtp-Source: ABdhPJzb60Ds0jZVIpUbqX8XXHFnzEcIvDPDkg5Lp52ZjsYBvwcBzeyDyRrU7Y36lcYXBiDyw8SB X-Received: by 2002:a05:6402:84f:b0:412:d1ef:c7df with SMTP id b15-20020a056402084f00b00412d1efc7dfmr39872364edz.210.1646400946502; Fri, 04 Mar 2022 05:35:46 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1646400946; cv=none; d=google.com; s=arc-20160816; b=JB7RozdiS4vk2x5oss0q7A9QhEk5OosmcrhEstZW7ATYo08QB7PEVAUH6kzezHs1JT lmK1zrz4Znp9BxAL7VGA8QVeCPhpTA0nBSChQu1O3IwViioT8a6Wu0+ys1C4aoppIL2a ZoNYbMR0B95lZQxa9/VEub0PEShiZNFvazWiJtftYCO6rU5CyW9Il+ex96uBUdgLHwGi Qkg8jH58rkdMxbxQJyebrHe6+L6m91SJXo90cKTJcyOt/1W3vs/vC9Z7zzOK2WloQyDv W0ZFKXja1HBSJsKQm51vqn7dO5SSNdUvsHEZ1yhEA6gy1A+H8ULXuFEG6PbCv2wHe+9s 1Z5A== 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:references:in-reply-to:message-id:date:subject:cc:to :from; bh=ukbRuYO5rmZo3A18+kzf4mMnK3pbCb6Jg9nYCLyYcfM=; b=LKLx4vMALuhfJ1c8tLvdz9vCeXGGhHtZYOPi8zSTPf2QqX/NnGc1gkd1zTLAVMR/rw LHVi5bx0MYjlmSckDtc6JqLx1VteSeuJwVasLW2NrepjXWMruV1PeJU/1Q2iCxuASQkB wIkSg9KwdPXbdltXO32fjrnzrZA04RawiIcCEA72Mrf+9Du7cvmg+3Ah5XdMv0KQZGVh UgH5pU7IGCsoRUEd5vKifJKsQSptua2E67MBxJlSGV40QnQiL1tco2pSe0/ZjR+JImcl 1BeLsX5/tm0vjZC1iXGht/0SaIR+VPI4a/+8XTMke7jXRpzV32WZxfjQGQjgA5WiMLsa ZQXQ== 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 z12-20020a056402274c00b0041397b4abf4si4704577edd.404.2022.03.04.05.35.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Mar 2022 05:35: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 7608083D40; Fri, 4 Mar 2022 14:35:24 +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 7946283D40; Fri, 4 Mar 2022 14:35:17 +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 34A6283CFE for ; Fri, 4 Mar 2022 14:35:05 +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 80E2A1396; Fri, 4 Mar 2022 05:35:04 -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 D50E13F70D; Fri, 4 Mar 2022 05:35:02 -0800 (PST) From: Sughosh Ganu To: u-boot@lists.denx.de Cc: Ilias Apalodimas , Simon Glass , Heinrich Schuchardt , Sughosh Ganu Subject: [PATCH v3 2/8] tpm: Fix the return type of tpm_startup Date: Fri, 4 Mar 2022 19:04:23 +0530 Message-Id: <20220304133429.1047752-3-sughosh.ganu@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220304133429.1047752-1-sughosh.ganu@linaro.org> References: <20220304133429.1047752-1-sughosh.ganu@linaro.org> 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_startup function returns negative values for error conditions. Fix the return type of the function to a signed int instead of a u32. Signed-off-by: Sughosh Ganu Reviewed-by: Simon Glass Reviewed-by: Ilias Apalodimas --- Changes since V2: None include/tpm_api.h | 2 +- lib/tpm_api.c | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/include/tpm_api.h b/include/tpm_api.h index 249a966942..4d77a49719 100644 --- a/include/tpm_api.h +++ b/include/tpm_api.h @@ -18,7 +18,7 @@ * @param mode TPM startup mode * Return: return code of the operation */ -u32 tpm_startup(struct udevice *dev, enum tpm_startup_type mode); +int tpm_startup(struct udevice *dev, enum tpm_startup_type mode); /** * Issue a TPM_SelfTestFull command. diff --git a/lib/tpm_api.c b/lib/tpm_api.c index 7d26ea2c3a..da48058abe 100644 --- a/lib/tpm_api.c +++ b/lib/tpm_api.c @@ -11,7 +11,8 @@ #include #include -u32 tpm_startup(struct udevice *dev, enum tpm_startup_type mode) + +int tpm_startup(struct udevice *dev, enum tpm_startup_type mode) { if (tpm_is_v1(dev)) { return tpm1_startup(dev, mode); From patchwork Fri Mar 4 13:34:24 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sughosh Ganu X-Patchwork-Id: 548114 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:6713:0:0:0:0 with SMTP id u19csp21941mag; Fri, 4 Mar 2022 05:35:58 -0800 (PST) X-Google-Smtp-Source: ABdhPJwNLXUtHC8A6sRScYK4ut/EYyaDTIp5QbTmi/S2ytObxsgKp17BND90zxw3K5PVGeN6we/3 X-Received: by 2002:a17:907:60d6:b0:6da:a020:332f with SMTP id hv22-20020a17090760d600b006daa020332fmr4946266ejc.8.1646400958540; Fri, 04 Mar 2022 05:35:58 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1646400958; cv=none; d=google.com; s=arc-20160816; b=0Y1NZo06Y7xjlkRMtxna8Sou4NaMyQ5TPovMPCDl42zCBi5eaLpoO3YveqXzweU//x eohTtrS3NB+cjbCjdAX5OZr/4JzLx4GAvgSvDtBjsHbLQMYibpsnhMn4XkwdAuOdC8J5 0dFwLGfsnMA1/8yHc9WQD7lid2xayBM55Wj96HaZJN9CstL4Erd5M+b/iZDZ16LN406S qex6htQ7DDnI7526KAJHxsNxBg6Tn0vojdGLg0+lyh8SsVA7q6agWijCQdw9qEZDAy5h 5HFXim9jalfsvIEGQgQ4y4Cuh+/MKltxpbz2CNygilPArXogo0yUjj68KoadCGv2Ig45 piJA== 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:references:in-reply-to:message-id:date:subject:cc:to :from; bh=QHyr8bJ/y4BUpHeQ7fv0+pZHmyfNl7bqZpQteNd6k6k=; b=Fex5ANbFtQrUiz8vc86HdbwlEEbhqZQ3/wn1f4rvIXjmTCITxZkVm9F0x76q8WsTqU g8hgr9EYoiVnO31uJW+tK0MPWSYjX9TJ1ejj8hAmJHagbk1o7GV8doKBsSo+qKI2s6PG NATUucM4L97uQty2QUt4yUHR/RHmhexJC5T1KhhYBipjc8l1HwhyxUJxLCNDEhFwhRXK wi4j9u5R7LOfaMo075Ky845Bskb9RzYyaZcRuIkWMPgT95NNARmPQSDC7SPpN7afiPU5 j7dKViQaCZg5LWMmtj6sKpUwa8OXz0/zOjgGp5T6kIbCJMKDRsDbtIy4HKuUgEjlbCyg 926g== 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 e3-20020a170906044300b006d04882ef1bsi2862356eja.696.2022.03.04.05.35.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Mar 2022 05:35:58 -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 E7FCB83CE4; Fri, 4 Mar 2022 14:35:31 +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 DA2B583CFE; Fri, 4 Mar 2022 14:35:19 +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.9 required=5.0 tests=BAYES_00,SPF_HELO_NONE, T_SCC_BODY_TEXT_LINE,T_SPF_TEMPERROR autolearn=ham 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 4398F83CBF for ; Fri, 4 Mar 2022 14:35:07 +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 9C7191396; Fri, 4 Mar 2022 05:35:06 -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 F072B3F70D; Fri, 4 Mar 2022 05:35:04 -0800 (PST) From: Sughosh Ganu To: u-boot@lists.denx.de Cc: Ilias Apalodimas , Simon Glass , Heinrich Schuchardt , Sughosh Ganu Subject: [PATCH v3 3/8] tpm: rng: Add driver model interface for TPM RNG device Date: Fri, 4 Mar 2022 19:04:24 +0530 Message-Id: <20220304133429.1047752-4-sughosh.ganu@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220304133429.1047752-1-sughosh.ganu@linaro.org> References: <20220304133429.1047752-1-sughosh.ganu@linaro.org> 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 has a builtin random number generator(RNG) functionality. Expose the RNG functions of the TPM device to the driver model so that they can be used by the EFI_RNG_PROTOCOL if the protocol is installed. Also change the function arguments and return type of the random number functions to comply with the driver model api. Signed-off-by: Sughosh Ganu --- Changes since V2: * Export the existing tpm*_get_random functions to the driver model instead of moving them to the drivers/rng/ directory. include/tpm-v1.h | 4 ++-- include/tpm-v2.h | 4 ++-- lib/tpm-v1.c | 28 ++++++++++++++++++++-------- lib/tpm-v2.c | 21 ++++++++++++++++----- lib/tpm_api.c | 23 +++++++++++++++++++---- 5 files changed, 59 insertions(+), 21 deletions(-) diff --git a/include/tpm-v1.h b/include/tpm-v1.h index 33d53fb695..d2ff8b446d 100644 --- a/include/tpm-v1.h +++ b/include/tpm-v1.h @@ -555,9 +555,9 @@ u32 tpm1_find_key_sha1(struct udevice *dev, const u8 auth[20], * @param dev TPM device * @param data output buffer for the random bytes * @param count size of output buffer - * Return: return code of the operation + * Return: 0 if OK, -ve on error */ -u32 tpm1_get_random(struct udevice *dev, void *data, u32 count); +int tpm1_get_random(struct udevice *dev, void *data, size_t count); /** * tpm_finalise_physical_presence() - Finalise physical presence diff --git a/include/tpm-v2.h b/include/tpm-v2.h index e79c90b939..4fb1e7a948 100644 --- a/include/tpm-v2.h +++ b/include/tpm-v2.h @@ -619,9 +619,9 @@ u32 tpm2_pcr_setauthvalue(struct udevice *dev, const char *pw, * @param data output buffer for the random bytes * @param count size of output buffer * - * Return: return code of the operation + * Return: 0 if OK, -ve on error */ -u32 tpm2_get_random(struct udevice *dev, void *data, u32 count); +int tpm2_get_random(struct udevice *dev, void *data, size_t count); /** * Lock data in the TPM diff --git a/lib/tpm-v1.c b/lib/tpm-v1.c index 22a769c587..57bb4a39cb 100644 --- a/lib/tpm-v1.c +++ b/lib/tpm-v1.c @@ -9,12 +9,14 @@ #include #include #include -#include -#include +#include #include #include #include "tpm-utils.h" +#include +#include + #ifdef CONFIG_TPM_AUTH_SESSIONS #ifndef CONFIG_SHA1 @@ -869,7 +871,7 @@ u32 tpm1_find_key_sha1(struct udevice *dev, const u8 auth[20], #endif /* CONFIG_TPM_AUTH_SESSIONS */ -u32 tpm1_get_random(struct udevice *dev, void *data, u32 count) +int tpm1_get_random(struct udevice *dev, void *data, size_t count) { const u8 command[14] = { 0x0, 0xc1, /* TPM_TAG */ @@ -892,19 +894,19 @@ u32 tpm1_get_random(struct udevice *dev, void *data, u32 count) if (pack_byte_string(buf, sizeof(buf), "sd", 0, command, sizeof(command), length_offset, this_bytes)) - return TPM_LIB_ERROR; - err = tpm_sendrecv_command(dev, buf, response, + return -EIO; + err = tpm_sendrecv_command(dev->parent, buf, response, &response_length); if (err) return err; if (unpack_byte_string(response, response_length, "d", data_size_offset, &data_size)) - return TPM_LIB_ERROR; + return -EIO; if (data_size > count) - return TPM_LIB_ERROR; + return -EIO; if (unpack_byte_string(response, response_length, "s", data_offset, out, data_size)) - return TPM_LIB_ERROR; + return -EIO; count -= data_size; out += data_size; @@ -912,3 +914,13 @@ u32 tpm1_get_random(struct udevice *dev, void *data, u32 count) return 0; } + +static const struct dm_rng_ops tpm1_rng_ops = { + .read = tpm1_get_random, +}; + +U_BOOT_DRIVER(tpm1_rng) = { + .name = "tpm1-rng", + .id = UCLASS_RNG, + .ops = &tpm1_rng_ops, +}; diff --git a/lib/tpm-v2.c b/lib/tpm-v2.c index 1bf627853a..18f64f0886 100644 --- a/lib/tpm-v2.c +++ b/lib/tpm-v2.c @@ -6,6 +6,7 @@ #include #include +#include #include #include #include @@ -562,7 +563,7 @@ u32 tpm2_pcr_setauthvalue(struct udevice *dev, const char *pw, return tpm_sendrecv_command(dev, command_v2, NULL, NULL); } -u32 tpm2_get_random(struct udevice *dev, void *data, u32 count) +int tpm2_get_random(struct udevice *dev, void *data, size_t count) { const u8 command_v2[10] = { tpm_u16(TPM2_ST_NO_SESSIONS), @@ -585,19 +586,19 @@ u32 tpm2_get_random(struct udevice *dev, void *data, u32 count) if (pack_byte_string(buf, sizeof(buf), "sw", 0, command_v2, sizeof(command_v2), sizeof(command_v2), this_bytes)) - return TPM_LIB_ERROR; - err = tpm_sendrecv_command(dev, buf, response, + return -EIO; + err = tpm_sendrecv_command(dev->parent, buf, response, &response_length); if (err) return err; if (unpack_byte_string(response, response_length, "w", data_size_offset, &data_size)) - return TPM_LIB_ERROR; + return -EIO; if (data_size > this_bytes) return TPM_LIB_ERROR; if (unpack_byte_string(response, response_length, "s", data_offset, out, data_size)) - return TPM_LIB_ERROR; + return -EIO; count -= data_size; out += data_size; @@ -669,3 +670,13 @@ u32 tpm2_submit_command(struct udevice *dev, const u8 *sendbuf, { return tpm_sendrecv_command(dev, sendbuf, recvbuf, recv_size); } + +static const struct dm_rng_ops tpm2_rng_ops = { + .read = tpm2_get_random, +}; + +U_BOOT_DRIVER(tpm2_rng) = { + .name = "tpm2-rng", + .id = UCLASS_RNG, + .ops = &tpm2_rng_ops, +}; diff --git a/lib/tpm_api.c b/lib/tpm_api.c index da48058abe..3584fda98c 100644 --- a/lib/tpm_api.c +++ b/lib/tpm_api.c @@ -6,6 +6,7 @@ #include #include #include +#include #include #include #include @@ -265,12 +266,26 @@ u32 tpm_get_permissions(struct udevice *dev, u32 index, u32 *perm) return -ENOSYS; } +#if CONFIG_IS_ENABLED(DM_RNG) int tpm_get_random(struct udevice *dev, void *data, u32 count) { + int ret = -ENOSYS; + struct udevice *rng_dev; + if (tpm_is_v1(dev)) - return tpm1_get_random(dev, data, count); + ret = uclass_get_device_by_driver(UCLASS_RNG, + DM_DRIVER_GET(tpm1_rng), + &rng_dev); else if (tpm_is_v2(dev)) - return -ENOSYS; /* not implemented yet */ - else - return -ENOSYS; + ret = uclass_get_device_by_driver(UCLASS_RNG, + DM_DRIVER_GET(tpm1_rng), + &rng_dev); + + if (ret) { + log_err("Getting tpm rng device failed\n"); + return ret; + } + + return dm_rng_read(rng_dev, data, (size_t)count); } +#endif /* DM_RNG */ From patchwork Fri Mar 4 13:34:25 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sughosh Ganu X-Patchwork-Id: 548117 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:6713:0:0:0:0 with SMTP id u19csp22369mag; Fri, 4 Mar 2022 05:36:29 -0800 (PST) X-Google-Smtp-Source: ABdhPJwhwYNm3Ce6Gjfk07vi/kTdzKW4Fvs8X0V++o9uQyppgjCVVjgrqNdJWa8ZHkn4eN5CKyTs X-Received: by 2002:a17:907:d92:b0:6da:7ac4:533c with SMTP id go18-20020a1709070d9200b006da7ac4533cmr9233899ejc.234.1646400989538; Fri, 04 Mar 2022 05:36:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1646400989; cv=none; d=google.com; s=arc-20160816; b=TkzjAaOYRjgeiDinQDbcapglcEziWv4Pnd7Z+Yrf3USMpkdhamQQmEzDuCTaME+VSj vLtVANP3Fq2/21w65TbrjXA4n6QuPqat0YKGPasNtWjh7otR0I8eyYNLoMtYvWytVRjT I6vU8MCvwv7Dn8qDZjtvu2+PePFiHp4eD/yOXhNP4F2+pHIb7ufhmERnzfy1fLAfOPrB c9GuFw+Og6xLOaaU4oT3MfmxqkAr1NdSlBukEXuzquugtGMK/CFJWCZF2h75z71emlA9 8AtXmiLfK0XvV9qf6wzDSXJUc26ZVkMtcCCRhuU33UIFhoMc3UBojTt6bOLvlB68yiZo gdSw== 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:references:in-reply-to:message-id:date:subject:cc:to :from; bh=+beEPOWulrMaXXwAVGHA5PyJ6uOPk70fvF9TUuqbYek=; b=rr2WNNlEBZZq2vSdwDFZyKphF1uDK//OZa0r5XAPLkbqO6wM3OK+yWfKzTmka3CNaq r7c1Ijv0wpxkhIxf5W8pRkShIEo6J9gySQLz3AV1cMK3K1PUTsnLBH3NlilNjGBULGfO Et+uS7NalHNXti224O3thJ3loVcWxQuFvxNCwK6XGOQO99CZ6TMD77vBz2xObkjXmRof CpxCspec0bFnMTXb6Pa+UFSgVZiF5SFjrXN0ENwtd6GJGYB1eO0iSj5uSGR3WhZSwF8Z MSpN7yL68sRcmSytp57ZotKxRE3JWaj0S3k1y+WEVzR5qKSs0fsNlm8f91sQ9p1NA5i+ ytbQ== 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 w16-20020a1709061f1000b006d1240c3431si3050607ejj.896.2022.03.04.05.36.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Mar 2022 05:36:29 -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 BB31183D3E; Fri, 4 Mar 2022 14:35:47 +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 D732F83D48; Fri, 4 Mar 2022 14:35:24 +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 938DC83CB4 for ; Fri, 4 Mar 2022 14:35:09 +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 B7ED41396; Fri, 4 Mar 2022 05:35:08 -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 1804B3F70D; Fri, 4 Mar 2022 05:35:06 -0800 (PST) From: Sughosh Ganu To: u-boot@lists.denx.de Cc: Ilias Apalodimas , Simon Glass , Heinrich Schuchardt , Sughosh Ganu Subject: [PATCH v3 4/8] tpm: Add the RNG child device Date: Fri, 4 Mar 2022 19:04:25 +0530 Message-Id: <20220304133429.1047752-5-sughosh.ganu@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220304133429.1047752-1-sughosh.ganu@linaro.org> References: <20220304133429.1047752-1-sughosh.ganu@linaro.org> 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 comes with the random number generator(RNG) functionality which is built into the TPM device. Add logic to add the RNG child device in the TPM uclass post probe callback. The RNG device can then be used to pass a set of random bytes to the linux kernel, need for address space randomisation through the EFI_RNG_PROTOCOL interface. Signed-off-by: Sughosh Ganu --- Changes since V2: * Enable DM_RNG when CONFIG_TPM is enabled to build the RNG uclass code drivers/tpm/tpm-uclass.c | 60 +++++++++++++++++++++++++++++++++++++--- lib/Kconfig | 1 + 2 files changed, 57 insertions(+), 4 deletions(-) diff --git a/drivers/tpm/tpm-uclass.c b/drivers/tpm/tpm-uclass.c index f67fe1019b..d1b9e0a757 100644 --- a/drivers/tpm/tpm-uclass.c +++ b/drivers/tpm/tpm-uclass.c @@ -11,10 +11,16 @@ #include #include #include +#include #include #include #include "tpm_internal.h" +#include + +#define TPM_RNG1_DRV_NAME "tpm1-rng" +#define TPM_RNG2_DRV_NAME "tpm2-rng" + int tpm_open(struct udevice *dev) { struct tpm_ops *ops = tpm_get_ops(dev); @@ -136,12 +142,58 @@ int tpm_xfer(struct udevice *dev, const uint8_t *sendbuf, size_t send_size, return 0; } +#if IS_ENABLED(CONFIG_TPM) +static int tpm_uclass_post_probe(struct udevice *dev) +{ + int ret; + const char *drv = tpm_is_v1(dev) ? + TPM_RNG1_DRV_NAME : TPM_RNG2_DRV_NAME; + struct udevice *child; + + ret = device_bind_driver(dev, drv, "tpm-rng0", &child); + if (ret == -ENOENT) { + log_err("No driver configured for tpm-rng device\n"); + return 0; + } + + if (ret) { + log_err("Unable to bind rng driver with the tpm-rng device\n"); + return ret; + } + + return 0; +} + +static int tpm_uclass_child_pre_probe(struct udevice *dev) +{ + int ret; + + ret = tpm_open(dev->parent); + if (ret == -EBUSY) { + log_info("TPM device already opened\n"); + } else if (ret) { + log_err("Unable to open TPM device\n"); + return ret; + } + + ret = tpm_startup(dev->parent, TPM_ST_CLEAR); + if (ret) + log_err("Unable to start TPM device\n"); + + return ret; +} +#endif /* CONFIG_TPM */ + UCLASS_DRIVER(tpm) = { - .id = UCLASS_TPM, - .name = "tpm", - .flags = DM_UC_FLAG_SEQ_ALIAS, + .id = UCLASS_TPM, + .name = "tpm", + .flags = DM_UC_FLAG_SEQ_ALIAS, #if CONFIG_IS_ENABLED(OF_REAL) - .post_bind = dm_scan_fdt_dev, + .post_bind = dm_scan_fdt_dev, +#endif +#if IS_ENABLED(CONFIG_TPM) + .post_probe = tpm_uclass_post_probe, + .child_pre_probe = tpm_uclass_child_pre_probe, #endif .per_device_auto = sizeof(struct tpm_chip_priv), }; diff --git a/lib/Kconfig b/lib/Kconfig index 3c6fa99b1a..0f05c97afc 100644 --- a/lib/Kconfig +++ b/lib/Kconfig @@ -341,6 +341,7 @@ source lib/crypt/Kconfig config TPM bool "Trusted Platform Module (TPM) Support" depends on DM + select DM_RNG help This enables support for TPMs which can be used to provide security features for your board. The TPM can be connected via LPC or I2C From patchwork Fri Mar 4 13:34:26 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sughosh Ganu X-Patchwork-Id: 548115 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:6713:0:0:0:0 with SMTP id u19csp22073mag; Fri, 4 Mar 2022 05:36:09 -0800 (PST) X-Google-Smtp-Source: ABdhPJyBIQaY3+Nh/On+QwafYHr0B6YHpqaHsTKglcXMbVoQJx2NtGVpFQzaxSLczmYDAnw14IvB X-Received: by 2002:a17:907:9713:b0:6da:7d49:a61 with SMTP id jg19-20020a170907971300b006da7d490a61mr9618761ejc.555.1646400968913; Fri, 04 Mar 2022 05:36:08 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1646400968; cv=none; d=google.com; s=arc-20160816; b=MQIMZaZsrT5B/STxTKdYp3YeCfL4gvFoqv/OS0afSRP6BfHDwnyQCgJHIHV2SF2M5o E9DO+ukPx0uTV4iAxb3QQRNkunrcv1W1lq12+nnUo19LN4LYOhrfQBNm1eGzOfM31DEK J7K//pF6DDtWz/jh31epvdJYdWiEaiAcFa+GT/s3bZCLOuP9XjzrRErheDE0gezMxs95 dADAWIGH0NPu5UFQkwQMnyncxq81WAKBvlnQKB5QhK9Qp4k7wivLAwBE06KQIcHy+rQH cBP64ii7fQbI8JDsG984UgTbmISgjHUjLtu/Q3zwCkBTfdoLbxuTpKIOD8EvL26wQA5F 6j+A== 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:references:in-reply-to:message-id:date:subject:cc:to :from; bh=ggqCrRmZNCmOuhDbTMcb+HYAKqyFami70/Y7CLEs+0w=; b=KoBHzR/Lsozah8rn2Hqrw9iHIKXig7TjdRhd4ojfV3mFI24RoOElDwV/NXKxo6HM9M 2Xsk2GX0RSaJuelXq6UwlrvUkF9RqSFmHF5oOeXpZ/VyOOyI8vELDFxksAbbMqCzPFy6 gYVJMwp4qRN25gY0HPHn9HAy9DfTUSHjbxI+WlFqXea2Fas94+OAhPDWXEMVYgJKL5nq HHoz5NeiG4a4KQ2KI6b5FF0IIXSuXBQRDwYTsgsl7c3EQJCDPn+IrSY+UJMilF/NFN1B enD7Jtjh1ba3jMwLvAxoLulZAKug0olVIFucAzlpDbSHfxPP7PnxdxEeZMcbwspsXDaN NfKg== 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 l17-20020a056402255100b0041290fa3b94si4770162edb.424.2022.03.04.05.36.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Mar 2022 05:36:08 -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 0917E83B8A; Fri, 4 Mar 2022 14:35:38 +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 2A0FD83CE4; Fri, 4 Mar 2022 14:35:24 +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 6EBDD83B6C for ; Fri, 4 Mar 2022 14:35:11 +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 D42F11396; Fri, 4 Mar 2022 05:35:10 -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 342183F70D; Fri, 4 Mar 2022 05:35:08 -0800 (PST) From: Sughosh Ganu To: u-boot@lists.denx.de Cc: Ilias Apalodimas , Simon Glass , Heinrich Schuchardt , Sughosh Ganu Subject: [PATCH v3 5/8] qemu: arm: Remove platform specific function to get RNG device Date: Fri, 4 Mar 2022 19:04:26 +0530 Message-Id: <20220304133429.1047752-6-sughosh.ganu@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220304133429.1047752-1-sughosh.ganu@linaro.org> References: <20220304133429.1047752-1-sughosh.ganu@linaro.org> 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 Qemu platform has a function defined to get the random number generator(RNG) device. However, the RNG device can be obtained simply by searching for a device belonging to the RNG uclass. Remove the superfluous platform function defined for the Qemu platform for getting the RNG device. Signed-off-by: Sughosh Ganu Tested-by: Heinrich Schuchardt Reviewed-by: Simon Glass Reviewed-by: Ilias Apalodimas --- Changes since V2: None board/emulation/qemu-arm/qemu-arm.c | 42 ----------------------------- 1 file changed, 42 deletions(-) diff --git a/board/emulation/qemu-arm/qemu-arm.c b/board/emulation/qemu-arm/qemu-arm.c index 16d5a97167..c9e886e44a 100644 --- a/board/emulation/qemu-arm/qemu-arm.c +++ b/board/emulation/qemu-arm/qemu-arm.c @@ -107,48 +107,6 @@ void enable_caches(void) dcache_enable(); } -#if defined(CONFIG_EFI_RNG_PROTOCOL) -#include -#include - -#include - -efi_status_t platform_get_rng_device(struct udevice **dev) -{ - int ret; - efi_status_t status = EFI_DEVICE_ERROR; - struct udevice *bus, *devp; - - for (uclass_first_device(UCLASS_VIRTIO, &bus); bus; - uclass_next_device(&bus)) { - for (device_find_first_child(bus, &devp); devp; - device_find_next_child(&devp)) { - if (device_get_uclass_id(devp) == UCLASS_RNG) { - *dev = devp; - status = EFI_SUCCESS; - break; - } - } - } - - if (status != EFI_SUCCESS) { - debug("No rng device found\n"); - return EFI_DEVICE_ERROR; - } - - if (*dev) { - ret = device_probe(*dev); - if (ret) - return EFI_DEVICE_ERROR; - } else { - debug("Couldn't get child device\n"); - return EFI_DEVICE_ERROR; - } - - return EFI_SUCCESS; -} -#endif /* CONFIG_EFI_RNG_PROTOCOL */ - #ifdef CONFIG_ARM64 #define __W "w" #else From patchwork Fri Mar 4 13:34:27 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sughosh Ganu X-Patchwork-Id: 548119 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:6713:0:0:0:0 with SMTP id u19csp22660mag; Fri, 4 Mar 2022 05:36:50 -0800 (PST) X-Google-Smtp-Source: ABdhPJyzTNYoyH7S7xp5VR3H1p86akF6e7BjdCN1Fz6r70tGc42VL5P83xtoC9FjNq9u8gsUwtBG X-Received: by 2002:a17:907:1b08:b0:6da:b62a:762a with SMTP id mp8-20020a1709071b0800b006dab62a762amr2717005ejc.60.1646401010192; Fri, 04 Mar 2022 05:36:50 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1646401010; cv=none; d=google.com; s=arc-20160816; b=NSmh70iPgbo7mdB/jidPBLzeHncjJeVgU2cB15+TOzQZ/BRCSYUQUx13hxrronz4qB nvrNrK/iEvrzmIPb6S/ynOAxy8Z4ZAXZk//YQuw3FGXHJzdJJaDNURa+Y7i61JQREFmJ ZeXsCs84rb3e3USSx2l0vTQCZyjp462y0EG2FgxJ8lb1zvPng4kZKlWgiiVmVoea6cE5 q+A6Ca8gvme9RBpdNK1N8I4R32/7+NDg5gLfoQ71akj//8LSZqnWLyhRlPhc8VmkH1DY GNeFpsoIcJKNwelSqg0ELBwpxTGvnDFcnriGfbe6tTNoMPSBsWDnJCFLU82GHk5XPFPn NtyA== 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:references:in-reply-to:message-id:date:subject:cc:to :from; bh=vbh6rd3v/VVnlgV7NVfmpDlDvNYYCzz68k/71I5AiMk=; b=Bu92Ul2wFhrUd/feOKMiGxAo1R9K2LRjTLFcPfQj8H3kpDATcNiIP7nmwh6YG78l4A Ga5WnWL2hO893sVFk0tkzOm3oMuGxjhAggXQfckqvTEuQBO/QA0SIeHMkz9Tp1RBCJ51 mo86MMfMZcK4xv5uImDe9A6o9zJs7mqmJXT7isrvWaY16+eXEOyRM53dPxE16pttVuIV ZVmCsNwncibpdYqOgLdEjqL6u+WTHBMDAfekuODVF0JB4IfZ1rwvqMuksTcsy85n8eUc HbBX13dvOw25x0v/d6YOUgi98voDxxTSoV5U/XQ4hXr+AlyxoJUPFnMt1Dngrt5X/nb2 8xiA== 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 go9-20020a1709070d8900b006da97b3f433si2452051ejc.654.2022.03.04.05.36.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Mar 2022 05:36:50 -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 693F183D5A; Fri, 4 Mar 2022 14:35:57 +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 75F6683CE4; Fri, 4 Mar 2022 14:35:27 +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 B5E5F83D38 for ; Fri, 4 Mar 2022 14:35:13 +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 F01571396; Fri, 4 Mar 2022 05:35:12 -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 504053F70D; Fri, 4 Mar 2022 05:35:11 -0800 (PST) From: Sughosh Ganu To: u-boot@lists.denx.de Cc: Ilias Apalodimas , Simon Glass , Heinrich Schuchardt , Sughosh Ganu Subject: [PATCH v3 6/8] cmd: rng: Add support for selecting RNG device Date: Fri, 4 Mar 2022 19:04:27 +0530 Message-Id: <20220304133429.1047752-7-sughosh.ganu@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220304133429.1047752-1-sughosh.ganu@linaro.org> References: <20220304133429.1047752-1-sughosh.ganu@linaro.org> 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 'rng' u-boot command is used for printing a select number of random bytes on the console. Currently, the RNG device from which the random bytes are read is fixed. However, a platform can have multiple RNG devices, one example being qemu, which has a virtio RNG device and the RNG pseudo device through the TPM chip. Extend the 'rng' command so that the user can provide the RNG device number from which the random bytes are to be read. This will be the device index under the RNG uclass. Signed-off-by: Sughosh Ganu Tested-by: Heinrich Schuchardt Reviewed-by: Ilias Apalodimas --- Changes since V2: None cmd/rng.c | 31 +++++++++++++++++++++++-------- 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/cmd/rng.c b/cmd/rng.c index 1ad5a096c0..bb89cfa784 100644 --- a/cmd/rng.c +++ b/cmd/rng.c @@ -13,19 +13,34 @@ static int do_rng(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) { - size_t n = 0x40; + size_t n; struct udevice *dev; void *buf; + int devnum; int ret = CMD_RET_SUCCESS; - if (uclass_get_device(UCLASS_RNG, 0, &dev) || !dev) { + switch (argc) { + case 1: + devnum = 0; + n = 0x40; + break; + case 2: + devnum = hextoul(argv[1], NULL); + n = 0x40; + break; + case 3: + devnum = hextoul(argv[1], NULL); + n = hextoul(argv[2], NULL); + break; + default: + return CMD_RET_USAGE; + } + + if (uclass_get_device(UCLASS_RNG, devnum, &dev) || !dev) { printf("No RNG device\n"); return CMD_RET_FAILURE; } - if (argc >= 2) - n = hextoul(argv[1], NULL); - buf = malloc(n); if (!buf) { printf("Out of memory\n"); @@ -46,12 +61,12 @@ static int do_rng(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) #ifdef CONFIG_SYS_LONGHELP static char rng_help_text[] = - "[n]\n" - " - print n random bytes\n"; + "[dev [n]]\n" + " - print n random bytes read from dev\n"; #endif U_BOOT_CMD( - rng, 2, 0, do_rng, + rng, 3, 0, do_rng, "print bytes from the hardware random number generator", rng_help_text ); From patchwork Fri Mar 4 13:34: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: 548116 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:6713:0:0:0:0 with SMTP id u19csp22225mag; Fri, 4 Mar 2022 05:36:19 -0800 (PST) X-Google-Smtp-Source: ABdhPJyRUiRY+Hgvo41kT9mhxrEMl9gdIed105I2Uowkh0zPs+hu0LZEBj/H9naNKsGjLa6tr+pH X-Received: by 2002:a05:6402:55:b0:413:2822:2928 with SMTP id f21-20020a056402005500b0041328222928mr38807503edu.174.1646400979248; Fri, 04 Mar 2022 05:36:19 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1646400979; cv=none; d=google.com; s=arc-20160816; b=VIly6G04hj3s8aiaXZQcgjzte+VB+drrCiAAaz7JeNKlsg+BQaT6Z+iyAzBbJ+0/TY DuZdfFCpQ6h8UkSKxTXKKfEIeKJgTOBeaIA7swJjrVTFW9R6s+gS87ENbVqclARlJMKk IwLDb/OLBVyh1PfM5MZ0wo14uKT8DDCDAC8Za1RtKjJa8pP6U7Xm8to3UBfqrTKBpyDY aIPYINSe2CY+uum0y3XOtcAETshweS3fUuitlxdSmUC+odbfmQHgkg59SqH2aUnbsUHt bMNYl8UZdxxeic2SjGZVfm9zsJ7ADjYJdm3TGo6vkrpetknPVCSgcwYtaFV8OZaFC9RG sFtg== 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:references:in-reply-to:message-id:date:subject:cc:to :from; bh=M5jLkL1REBj0BUO6BR9istMx4IxNzzuk+GY+eT+vqoU=; b=MGGpcC3FbXFDBFs0ciyH56E9uJDXEMIuuh+d7VuwShfzFqbPtNmqMyItShnnoG8kLh S2CFcIRInyq8OoY+mNtN+nF0v1ARIp6Puko1eORg3v7m0Hlrp8WVq2sx2IO0y0yRXsx5 51aBc43a4LxXTBRa2sPdUoR/HZrsv3Lj0CSDqrR/x6KFDFxeb4KzFVs3QOs2Zqx4Okzg AGL79VldN6HT7I9CZiYBiC4Dt9ce6tMISxUYLuLnvKTUG2qg0ryhf9U5PPS+wDN92BH4 UtsHv/54ICOZtVOUjKLkHhWXRSLLg3X/tBmixIfKud/ylfVQDCBANoj6HwkbaHHYg50c pI1g== 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 gb21-20020a170907961500b006d8fa778e5asi3577295ejc.149.2022.03.04.05.36.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Mar 2022 05:36:19 -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 67CB883D0B; Fri, 4 Mar 2022 14:35:42 +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 7F2EE83CBF; Fri, 4 Mar 2022 14:35:22 +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 B1BCF83D45 for ; Fri, 4 Mar 2022 14:35:15 +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 180621396; Fri, 4 Mar 2022 05:35:15 -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 6C9113F70D; Fri, 4 Mar 2022 05:35:13 -0800 (PST) From: Sughosh Ganu To: u-boot@lists.denx.de Cc: Ilias Apalodimas , Simon Glass , Heinrich Schuchardt , Sughosh Ganu Subject: [PATCH v3 7/8] doc: rng: Add documentation for the rng command Date: Fri, 4 Mar 2022 19:04:28 +0530 Message-Id: <20220304133429.1047752-8-sughosh.ganu@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220304133429.1047752-1-sughosh.ganu@linaro.org> References: <20220304133429.1047752-1-sughosh.ganu@linaro.org> 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 Add a usage document for the 'rng' u-boot command. Signed-off-by: Sughosh Ganu Reviewed-by: Simon Glass Reviewed-by: Ilias Apalodimas --- Changes since V2: None doc/usage/index.rst | 1 + doc/usage/rng.rst | 25 +++++++++++++++++++++++++ 2 files changed, 26 insertions(+) create mode 100644 doc/usage/rng.rst diff --git a/doc/usage/index.rst b/doc/usage/index.rst index 0aacf531b2..5712a924ae 100644 --- a/doc/usage/index.rst +++ b/doc/usage/index.rst @@ -45,6 +45,7 @@ Shell commands pstore qfw reset + rng sbi sf scp03 diff --git a/doc/usage/rng.rst b/doc/usage/rng.rst new file mode 100644 index 0000000000..87758f7d66 --- /dev/null +++ b/doc/usage/rng.rst @@ -0,0 +1,25 @@ +.. SPDX-License-Identifier: GPL-2.0+ + +rng command +=========== + +Synopsis +-------- + +:: + + rng [devnum [n]] + +Description +----------- + +The *rng* command reads the random number generator(RNG) device and +prints the random bytes read on the console. + +devnum + The RNG device from which the random bytes are to be + read. Defaults to 0. + +n + Number of random bytes to be read and displayed on the + console. Default value is 0x40. From patchwork Fri Mar 4 13:34:29 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sughosh Ganu X-Patchwork-Id: 548118 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:6713:0:0:0:0 with SMTP id u19csp22519mag; Fri, 4 Mar 2022 05:36:40 -0800 (PST) X-Google-Smtp-Source: ABdhPJyZYv7DAWgjbEnNTRnlJ7+VwTRHI0prmI0qkcDo5kMtmVOaqeq7iGC+iIjREW3nqo9bXy+8 X-Received: by 2002:a05:6402:90b:b0:412:e7f8:6de6 with SMTP id g11-20020a056402090b00b00412e7f86de6mr39340961edz.182.1646401000140; Fri, 04 Mar 2022 05:36:40 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1646401000; cv=none; d=google.com; s=arc-20160816; b=qh9/UYF0OsNFcJpwcwqKitS4SPLY7DEbugs91u72WeD4xtktAP6nNcZYwO1ms8Wywv I/+SSrbXJOF4w+dwKead6N0MUr1oDaxZuOGdIyEJfCOyyY6zSHB12e00abQ97glxWRoa yXggx4KD80d2XOsM3lDwIyvqFsj7ykYEviXppL1m5DQSVm4b1VNCAx0c8YO0tuC+vkZS MOJg9k2LjREPNxmcbL4sUKhA7RjN+9eLgdoTKhQ0m/jBijbB2r76DLph697RSCgBAQ1x SpxaDez8kpA/zl4HvR1N23QbY4c2hwDeTItR2yW9LxoYho1Jxw7f3Yy22FS8FiLyJrIr 8P+g== 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:references:in-reply-to:message-id:date:subject:cc:to :from; bh=4q6dTFZS0V0wA/W73sHv/mFBZc4hYhVjXKWp7px/oH4=; b=pUmf+hfndXvKYbWuZCLkqTmVAJGKw0Uq6Iftt238Xmmqu5pdxP0wp4u32lII8XUt+z qs9HYGIOzEOQkJ5Kq7hIAxCfKsSmoe7rayyUSGJv0zCrcvdU1WaejlwJzvJRfwYHWucj bl/x/ACfPkwpQ/KjtRzhw1baS8/AwZtOhyIVA405iGmdSsefjgmBo70yOkoZrlXbpGJ4 NOuEc3RPOt5JKczPqiSzFHYXsktju+lbnaAb6iyLa2zD61xsAW5powDoj4Yv6eyGUTsi mu+hLJrldpAG6phboEhAlqufYCMivCKbIL6w6jUjnh5Xb71wASDVurjXwRAccH371Pzu I/yg== 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 kz2-20020a17090777c200b006d0adc95b44si3021947ejc.525.2022.03.04.05.36.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Mar 2022 05:36:39 -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 C2CEA83D4D; Fri, 4 Mar 2022 14:35:52 +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 4300283B6C; Fri, 4 Mar 2022 14:35:26 +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 DCD7183D32 for ; Fri, 4 Mar 2022 14:35:17 +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 33A021396; Fri, 4 Mar 2022 05:35:17 -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 882093F70D; Fri, 4 Mar 2022 05:35:15 -0800 (PST) From: Sughosh Ganu To: u-boot@lists.denx.de Cc: Ilias Apalodimas , Simon Glass , Heinrich Schuchardt , Sughosh Ganu Subject: [PATCH v3 8/8] test: rng: Add a UT testcase for the rng command Date: Fri, 4 Mar 2022 19:04:29 +0530 Message-Id: <20220304133429.1047752-9-sughosh.ganu@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220304133429.1047752-1-sughosh.ganu@linaro.org> References: <20220304133429.1047752-1-sughosh.ganu@linaro.org> 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 'rng' command dumps a number of random bytes on the console. Add a set of tests for the 'rng' command. The test function performs basic sanity testing of the command. Since a unit test is being added for the command, enable it by default in the sandbox platforms. Signed-off-by: Sughosh Ganu Reviewed-by: Simon Glass --- Changes since V2: None cmd/Kconfig | 1 + test/dm/rng.c | 29 +++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/cmd/Kconfig b/cmd/Kconfig index 5e25e45fd2..47f1e23ef0 100644 --- a/cmd/Kconfig +++ b/cmd/Kconfig @@ -1810,6 +1810,7 @@ config CMD_GETTIME config CMD_RNG bool "rng command" depends on DM_RNG + default y if SANDBOX select HEXDUMP help Print bytes from the hardware random number generator. diff --git a/test/dm/rng.c b/test/dm/rng.c index 5b34c93ed6..6d1f68848d 100644 --- a/test/dm/rng.c +++ b/test/dm/rng.c @@ -25,3 +25,32 @@ static int dm_test_rng_read(struct unit_test_state *uts) return 0; } DM_TEST(dm_test_rng_read, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT); + +/* Test the rng command */ +static int dm_test_rng_cmd(struct unit_test_state *uts) +{ + struct udevice *dev; + + ut_assertok(uclass_get_device(UCLASS_RNG, 0, &dev)); + ut_assertnonnull(dev); + + ut_assertok(console_record_reset_enable()); + + run_command("rng", 0); + ut_assert_nextlinen("00000000:"); + ut_assert_nextlinen("00000010:"); + ut_assert_nextlinen("00000020:"); + ut_assert_nextlinen("00000030:"); + ut_assert_console_end(); + + run_command("rng 0 10", 0); + ut_assert_nextlinen("00000000:"); + ut_assert_console_end(); + + run_command("rng 20", 0); + ut_assert_nextlinen("No RNG device"); + ut_assert_console_end(); + + return 0; +} +DM_TEST(dm_test_rng_cmd, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT | UT_TESTF_CONSOLE_REC);