summaryrefslogtreecommitdiff
path: root/cmd
diff options
context:
space:
mode:
authorTom Rini <trini@konsulko.com>2022-08-05 08:01:32 -0400
committerTom Rini <trini@konsulko.com>2022-08-05 08:01:32 -0400
commit46b5c8ed017958fc387ab86c71ae6c90abb6793c (patch)
tree4162612e16af05f7ed57a461207af988fd8e5815 /cmd
parentea2997ed2d1d2a24f598f368de441530c8dba7a2 (diff)
parentde70619dd3db08e4a1ac881801d3fab979408fd3 (diff)
downloadu-boot-46b5c8ed017958fc387ab86c71ae6c90abb6793c.tar.gz
u-boot-46b5c8ed017958fc387ab86c71ae6c90abb6793c.tar.bz2
u-boot-46b5c8ed017958fc387ab86c71ae6c90abb6793c.zip
Merge tag 'tpm-030822' of https://source.denx.de/u-boot/custodians/u-boot-tpm
EFI_RNG_PROTOCOL with a TPM
Diffstat (limited to 'cmd')
-rw-r--r--cmd/Kconfig1
-rw-r--r--cmd/rng.c42
2 files changed, 28 insertions, 15 deletions
diff --git a/cmd/Kconfig b/cmd/Kconfig
index a8260aa170..3625ff2a50 100644
--- a/cmd/Kconfig
+++ b/cmd/Kconfig
@@ -1964,6 +1964,7 @@ config CMD_GETTIME
config CMD_RNG
bool "rng command"
depends on DM_RNG
+ default y if SANDBOX
select HEXDUMP
help
Print bytes from the hardware random number generator.
diff --git a/cmd/rng.c b/cmd/rng.c
index 1ad5a096c0..81a23964b8 100644
--- a/cmd/rng.c
+++ b/cmd/rng.c
@@ -13,24 +13,38 @@
static int do_rng(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
{
- size_t n = 0x40;
+ size_t n;
+ u8 buf[64];
+ int devnum;
struct udevice *dev;
- void *buf;
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_by_seq(UCLASS_RNG, devnum, &dev) || !dev) {
printf("No RNG device\n");
return CMD_RET_FAILURE;
}
- if (argc >= 2)
- n = hextoul(argv[1], NULL);
+ if (!n)
+ return 0;
- buf = malloc(n);
- if (!buf) {
- printf("Out of memory\n");
- return CMD_RET_FAILURE;
- }
+ n = min(n, sizeof(buf));
if (dm_rng_read(dev, buf, n)) {
printf("Reading RNG failed\n");
@@ -39,19 +53,17 @@ static int do_rng(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
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";
+ "[dev [n]]\n"
+ " - print n random bytes(max 64) 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
);