summaryrefslogtreecommitdiff
path: root/cmd/rng.c
diff options
context:
space:
mode:
authorTom Rini <trini@konsulko.com>2020-01-08 18:57:11 -0500
committerTom Rini <trini@konsulko.com>2020-01-08 18:57:11 -0500
commit7086de4948ba2bc46cdd3001f7d845535f05f7fe (patch)
tree1689ea51d9e9cd24ba10d4dbcc590c087062911f /cmd/rng.c
parent21aede21b060661977fd3d11f96211bd4f254096 (diff)
parent7d6f16fbde9a03adc7d85b8809cb16dbc5e311f9 (diff)
Merge tag 'efi-2020-04-rc1' of https://gitlab.denx.de/u-boot/custodians/u-boot-efi
Pull request for UEFI sub-system for efi-2020-04-rc1 This pull request provides: * support for FIT images for UEFI binaries * drivers for hardware random number generators * an implementation of the EFI_RNG_PROTOCOL * a sub-command for efidebug to display configuration tables
Diffstat (limited to 'cmd/rng.c')
-rw-r--r--cmd/rng.c56
1 files changed, 56 insertions, 0 deletions
diff --git a/cmd/rng.c b/cmd/rng.c
new file mode 100644
index 00000000000..36ca7a101c1
--- /dev/null
+++ b/cmd/rng.c
@@ -0,0 +1,56 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * The 'rng' command prints bytes from the hardware random number generator.
+ *
+ * Copyright (c) 2019, Heinrich Schuchardt <xypron.glpk@gmx.de>
+ */
+#include <common.h>
+#include <command.h>
+#include <dm.h>
+#include <hexdump.h>
+#include <rng.h>
+
+static int do_rng(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+{
+ size_t n = 0x40;
+ struct udevice *dev;
+ void *buf;
+ int ret = CMD_RET_SUCCESS;
+
+ if (uclass_get_device(UCLASS_RNG, 0, &dev) || !dev) {
+ printf("No RNG device\n");
+ return CMD_RET_FAILURE;
+ }
+
+ if (argc >= 2)
+ n = simple_strtoul(argv[1], NULL, 16);
+
+ buf = malloc(n);
+ if (!buf) {
+ printf("Out of memory\n");
+ return CMD_RET_FAILURE;
+ }
+
+ if (dm_rng_read(dev, buf, n)) {
+ printf("Reading RNG failed\n");
+ ret = CMD_RET_FAILURE;
+ } else {
+ print_hex_dump_bytes("", DUMP_PREFIX_OFFSET, buf, n);
+ }
+
+ free(buf);
+
+ return ret;
+}
+
+#ifdef CONFIG_SYS_LONGHELP
+static char rng_help_text[] =
+ "[n]\n"
+ " - print n random bytes\n";
+#endif
+
+U_BOOT_CMD(
+ rng, 2, 0, do_rng,
+ "print bytes from the hardware random number generator",
+ rng_help_text
+);