1 // SPDX-License-Identifier: GPL-2.0+
3 * The 'rng' command prints bytes from the hardware random number generator.
5 * Copyright (c) 2019, Heinrich Schuchardt <xypron.glpk@gmx.de>
14 static int do_rng(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
20 int ret = CMD_RET_SUCCESS;
28 devnum = hextoul(argv[1], NULL);
32 devnum = hextoul(argv[1], NULL);
33 n = hextoul(argv[2], NULL);
39 if (uclass_get_device_by_seq(UCLASS_RNG, devnum, &dev) || !dev) {
40 printf("No RNG device\n");
41 return CMD_RET_FAILURE;
47 n = min(n, sizeof(buf));
49 if (dm_rng_read(dev, buf, n)) {
50 printf("Reading RNG failed\n");
51 ret = CMD_RET_FAILURE;
53 print_hex_dump_bytes("", DUMP_PREFIX_OFFSET, buf, n);
59 #ifdef CONFIG_SYS_LONGHELP
60 static char rng_help_text[] =
62 " - print n random bytes(max 64) read from dev\n";
67 "print bytes from the hardware random number generator",