diff options
author | Tom Rini <trini@konsulko.com> | 2020-01-08 18:57:11 -0500 |
---|---|---|
committer | Tom Rini <trini@konsulko.com> | 2020-01-08 18:57:11 -0500 |
commit | 7086de4948ba2bc46cdd3001f7d845535f05f7fe (patch) | |
tree | 1689ea51d9e9cd24ba10d4dbcc590c087062911f /drivers/rng/sandbox_rng.c | |
parent | 21aede21b060661977fd3d11f96211bd4f254096 (diff) | |
parent | 7d6f16fbde9a03adc7d85b8809cb16dbc5e311f9 (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 'drivers/rng/sandbox_rng.c')
-rw-r--r-- | drivers/rng/sandbox_rng.c | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/drivers/rng/sandbox_rng.c b/drivers/rng/sandbox_rng.c new file mode 100644 index 00000000000..cd0b0ac77b6 --- /dev/null +++ b/drivers/rng/sandbox_rng.c @@ -0,0 +1,56 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Copyright (c) 2019, Linaro Limited + */ + +#include <common.h> +#include <dm.h> +#include <rng.h> + +#include <linux/string.h> + +static int sandbox_rng_read(struct udevice *dev, void *data, size_t len) +{ + unsigned int i, seed, random; + unsigned char *buf = data; + size_t nrem, nloops; + + if (!len) + return 0; + + nloops = len / sizeof(random); + seed = get_timer(0) ^ rand(); + srand(seed); + + for (i = 0, nrem = len; i < nloops; i++) { + random = rand(); + memcpy(buf, &random, sizeof(random)); + buf += sizeof(random); + nrem -= sizeof(random); + } + + if (nrem) { + random = rand(); + memcpy(buf, &random, nrem); + } + + return 0; +} + +static const struct dm_rng_ops sandbox_rng_ops = { + .read = sandbox_rng_read, +}; + +static const struct udevice_id sandbox_rng_match[] = { + { + .compatible = "sandbox,sandbox-rng", + }, + {}, +}; + +U_BOOT_DRIVER(sandbox_rng) = { + .name = "sandbox-rng", + .id = UCLASS_RNG, + .of_match = sandbox_rng_match, + .ops = &sandbox_rng_ops, +}; |