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[])
19 int ret = CMD_RET_SUCCESS;
21 if (uclass_get_device(UCLASS_RNG, 0, &dev) || !dev) {
22 printf("No RNG device\n");
23 return CMD_RET_FAILURE;
27 n = hextoul(argv[1], NULL);
31 printf("Out of memory\n");
32 return CMD_RET_FAILURE;
35 if (dm_rng_read(dev, buf, n)) {
36 printf("Reading RNG failed\n");
37 ret = CMD_RET_FAILURE;
39 print_hex_dump_bytes("", DUMP_PREFIX_OFFSET, buf, n);
47 #ifdef CONFIG_SYS_LONGHELP
48 static char rng_help_text[] =
50 " - print n random bytes\n";
55 "print bytes from the hardware random number generator",