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>
13 static int do_rng(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
18 int ret = CMD_RET_SUCCESS;
20 if (uclass_get_device(UCLASS_RNG, 0, &dev) || !dev) {
21 printf("No RNG device\n");
22 return CMD_RET_FAILURE;
26 n = simple_strtoul(argv[1], NULL, 16);
30 printf("Out of memory\n");
31 return CMD_RET_FAILURE;
34 if (dm_rng_read(dev, buf, n)) {
35 printf("Reading RNG failed\n");
36 ret = CMD_RET_FAILURE;
38 print_hex_dump_bytes("", DUMP_PREFIX_OFFSET, buf, n);
46 #ifdef CONFIG_SYS_LONGHELP
47 static char rng_help_text[] =
49 " - print n random bytes\n";
54 "print bytes from the hardware random number generator",