public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: Ilias Apalodimas <ilias.apalodimas@linaro.org>
To: Sughosh Ganu <sughosh.ganu@linaro.org>
Cc: u-boot@lists.denx.de, Simon Glass <sjg@chromium.org>,
	Heinrich Schuchardt <xypron.glpk@gmx.de>
Subject: Re: [PATCH v3 6/8] cmd: rng: Add support for selecting RNG device
Date: Wed, 9 Mar 2022 09:42:54 +0200	[thread overview]
Message-ID: <Yihafp7zYh7Oh+9H@hades> (raw)
In-Reply-To: <20220304133429.1047752-7-sughosh.ganu@linaro.org>

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 <sughosh.ganu@linaro.org>
> Tested-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
> ---
> 
> 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 <ilias.apalodimas@linaro.org>

  parent reply	other threads:[~2022-03-09  7:43 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-03-04 13:34 [PATCH v3 0/8] tpm: rng: Move TPM RNG functionality to driver model Sughosh Ganu
2022-03-04 13:34 ` [PATCH v3 1/8] tpm: rng: Change tpm_get_random to return an int Sughosh Ganu
2022-03-09  7:36   ` Ilias Apalodimas
2022-03-04 13:34 ` [PATCH v3 2/8] tpm: Fix the return type of tpm_startup Sughosh Ganu
2022-03-09  7:37   ` Ilias Apalodimas
2022-03-04 13:34 ` [PATCH v3 3/8] tpm: rng: Add driver model interface for TPM RNG device Sughosh Ganu
2022-03-09  2:35   ` Simon Glass
2022-03-09  6:00     ` Sughosh Ganu
2022-03-09 11:18       ` Sughosh Ganu
2022-03-12 17:59         ` Simon Glass
2022-03-04 13:34 ` [PATCH v3 4/8] tpm: Add the RNG child device Sughosh Ganu
2022-03-09  2:35   ` Simon Glass
2022-03-09  6:02     ` Sughosh Ganu
2022-03-04 13:34 ` [PATCH v3 5/8] qemu: arm: Remove platform specific function to get RNG device Sughosh Ganu
2022-03-09  2:35   ` Simon Glass
2022-03-09  7:47     ` Ilias Apalodimas
2022-03-04 13:34 ` [PATCH v3 6/8] cmd: rng: Add support for selecting " Sughosh Ganu
2022-03-09  2:35   ` Simon Glass
2022-03-09  6:04     ` Sughosh Ganu
2022-03-09  7:42   ` Ilias Apalodimas [this message]
2022-03-09 15:32   ` Simon Glass
2022-03-10 12:42     ` Sughosh Ganu
2022-03-12 17:59       ` Simon Glass
2022-03-04 13:34 ` [PATCH v3 7/8] doc: rng: Add documentation for the rng command Sughosh Ganu
2022-03-09  2:35   ` Simon Glass
2022-03-09  7:39   ` Ilias Apalodimas
2022-03-04 13:34 ` [PATCH v3 8/8] test: rng: Add a UT testcase " Sughosh Ganu
2022-03-09  2:35   ` Simon Glass
2022-03-09  6:18     ` Sughosh Ganu
2022-03-12  2:43       ` Simon Glass
2022-03-13 11:07         ` Sughosh Ganu
2022-03-13 22:23           ` Simon Glass
2022-03-24 16:22   ` Sughosh Ganu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=Yihafp7zYh7Oh+9H@hades \
    --to=ilias.apalodimas@linaro.org \
    --cc=sjg@chromium.org \
    --cc=sughosh.ganu@linaro.org \
    --cc=u-boot@lists.denx.de \
    --cc=xypron.glpk@gmx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox