From patchwork Mon Jul 4 13:34:41 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sughosh Ganu X-Patchwork-Id: 587142 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:1ec:0:0:0:0 with SMTP id 12csp839798map; Mon, 4 Jul 2022 06:36:03 -0700 (PDT) X-Google-Smtp-Source: AGRyM1uWSroxnWoTVIaKSeiN3yD32zmgGhXbAI6st7OwZGqxdSoOVzaRnr2PzntXSU42tRhxyEnk X-Received: by 2002:a19:ee0e:0:b0:481:4727:be80 with SMTP id g14-20020a19ee0e000000b004814727be80mr16963786lfb.162.1656941763319; Mon, 04 Jul 2022 06:36:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1656941763; cv=none; d=google.com; s=arc-20160816; b=nKQHChlJyCaKEeREpl0JNpN491b7jpCadHW7bCU/WipLNdVICL9xvI4+UAKMhr5sfA wxG36Lx4XlFV6K1CWOgAANaTO5uRepUMZdFluQ/DeCK3gUzTY7ECeVDhRhN+TSfjwdxn L1lrEInpg7mORnM8Dw/eFwfV7VMCd0/2ISgtRVCYQuzbEyF02QUSjuPbPejTTA/d2s4X qimEwkOIj1PaP1Vxnt6Kffb3BWFK3zt59kYgQ5nQcw8gkdY1lBtif2BStwcTvBqvyRPr /PGc3U2CKda8y4fjBvXXDvIBaHZD/Kpx0Uv8HKqRrJaoNZ49zCywuwEW5R4WKcJrYka4 ab0w== 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=Merauy5FzUzqyHNlodO9glQweghwtkB3IIBk4ECId04=; b=b6WbOdcSebWutEUR8eKtWWWN9NAUbr9fwuoNq0cbOeEIbGW4hUrV0TEhlgKThGZUdP VbAq14mtdvjQ9Rw+JxEJXKLOrzP0I/8/Yt/F75DXpCbj565nmtbHV/uMIwxN4XIIfYdT r2ykOmaaK6t4dKQWw0BldP8Jfty4zN0Ewf3JnbhlU5vW3mo9sutLGYE69kebBODOOpYM on961v3yFu5hGcOiT0D5PRU3WHw3T3TcdkYkqCkTd2X2JYq/X57OcQSy6dgvFP1uOHEF SP6rVAXIqKJBz4xsFy0/beGM4BP1BjppmQMAHQen7jN8pugkvIjnlaRsy1HEHrjiZZh6 dVNA== 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 b24-20020a0565120b9800b00478efadf891si15668042lfv.434.2022.07.04.06.36.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Jul 2022 06:36:03 -0700 (PDT) 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 E9CC6844CB; Mon, 4 Jul 2022 15:35:25 +0200 (CEST) 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 6FD1D844C7; Mon, 4 Jul 2022 15:35:24 +0200 (CEST) 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 EBB23844AE for ; Mon, 4 Jul 2022 15:35:21 +0200 (CEST) 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 B02D223A; Mon, 4 Jul 2022 06:35:21 -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 8290A3F66F; Mon, 4 Jul 2022 06:35:19 -0700 (PDT) From: Sughosh Ganu To: u-boot@lists.denx.de Cc: Heinrich Schuchardt , Ilias Apalodimas , Simon Glass , Tom Rini , Sughosh Ganu Subject: [PATCH v6 4/7] cmd: rng: Add support for selecting RNG device Date: Mon, 4 Jul 2022 19:04:41 +0530 Message-Id: <20220704133444.1110715-5-sughosh.ganu@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220704133444.1110715-1-sughosh.ganu@linaro.org> References: <20220704133444.1110715-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.6 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. Tested-by: Heinrich Schuchardt Reviewed-by: Ilias Apalodimas Signed-off-by: Sughosh Ganu --- Changes since V5: None cmd/rng.c | 31 +++++++++++++++++++++++-------- 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/cmd/rng.c b/cmd/rng.c index 1ad5a096c0..2ddf27545f 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_by_seq(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 );