From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 461EFC433F5 for ; Wed, 9 Mar 2022 07:43:06 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 933B58397F; Wed, 9 Mar 2022 08:43:03 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="h2/1Zrzm"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id D567F8399C; Wed, 9 Mar 2022 08:43:00 +0100 (CET) Received: from mail-ej1-x62e.google.com (mail-ej1-x62e.google.com [IPv6:2a00:1450:4864:20::62e]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 87C6F837F6 for ; Wed, 9 Mar 2022 08:42:57 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=ilias.apalodimas@linaro.org Received: by mail-ej1-x62e.google.com with SMTP id qa43so2942231ejc.12 for ; Tue, 08 Mar 2022 23:42:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=OGFPZyLZOJJicmlmxtHOoHphnROeXp9Qhh8B8lBfXx0=; b=h2/1ZrzmbtQJ0TUBLv89LB7u4C5MQgPDDm6RoismMmBEi7igzhUlHiOLLoaKdgBwfV CxBgLZvfBubImRXEJImxCNuenVaEjJQJS54/S2yjaYuFI34zPIq56ar0SHBGA176hac6 WUJYoM6OM41UdsTKN+s0HXm7Yj0ejhUTAktfKEKktInQnwP2MPrUfsbGEpGtTfoJvBCL 2MUdNfhqMde8aW8J0N56GCMymcALFVDVaGpNC8bciKULG4w3YYfvU5e6Q8aqln4l77EE Hi8osGZm/Jbk88AQfhTSyB2HcEaST8L9GoS+Kc6RKmbQjSLbC+yQkZ54XdPo2ymSGYe2 FVdQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=OGFPZyLZOJJicmlmxtHOoHphnROeXp9Qhh8B8lBfXx0=; b=nLIVPYUoO9EFm0OK220Y4NL9LaiPuMgcHlmoySz/LtKYeJXmKY8LkocdzKmISYDIkf O0GdjkLka2SrC//qX+8c0ftSLpGViUuHG6O8HF0dik7gRYZa2aKrLFRkbC2AFvX3nz0P rFfvPfBKntTiNG9CLuNhzC2a6ZPRAU2g8UNobJJXEaYVRgI61Eyf3RFiOW3cbaGuy9yF y6fBlQWHnFMGTJuP7xU0WriiJ9cd72ykdzAvOS3jsMwFPDDaCpbAhbEX2asVtrZb8I/m uhvlGNnJvvQu8YW2iUiGe1N4GAqjSosLHEeo2TZ43g7n4oyTLfsnt1BPL5rYYomIFLio qN5w== X-Gm-Message-State: AOAM5306cnUUsqkkfybaKQfUMigIzqeVMv/o1uOCmJW7rPBj0Kcayj/f 9ziNMgdmH/G84VzehdtlsTYsJA== X-Google-Smtp-Source: ABdhPJxEM5+Ju0TNLhOwVlNRbWbd/cQ6SIiK4kQKQScRTVpO/25kyw2m3n1QAW8B35qsp+RRGdW0Xw== X-Received: by 2002:a17:906:1e4d:b0:6ce:6f7b:aef2 with SMTP id i13-20020a1709061e4d00b006ce6f7baef2mr16492530ejj.130.1646811777173; Tue, 08 Mar 2022 23:42:57 -0800 (PST) Received: from hades (athedsl-4461682.home.otenet.gr. [94.71.4.98]) by smtp.gmail.com with ESMTPSA id lb10-20020a170907784a00b006db0aadcbd1sm381539ejc.219.2022.03.08.23.42.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Mar 2022 23:42:56 -0800 (PST) Date: Wed, 9 Mar 2022 09:42:54 +0200 From: Ilias Apalodimas To: Sughosh Ganu Cc: u-boot@lists.denx.de, Simon Glass , Heinrich Schuchardt Subject: Re: [PATCH v3 6/8] cmd: rng: Add support for selecting RNG device Message-ID: References: <20220304133429.1047752-1-sughosh.ganu@linaro.org> <20220304133429.1047752-7-sughosh.ganu@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220304133429.1047752-7-sughosh.ganu@linaro.org> 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 On Fri, Mar 04, 2022 at 07:04:27PM +0530, Sughosh Ganu wrote: > 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 > --- > > 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 > ); > -- > 2.25.1 > Reviewed-by: Ilias Apalodimas