1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Copyright (c) 2019, Linaro Limited
11 #include <linux/string.h>
13 static int sandbox_rng_read(struct udevice *dev, void *data, size_t len)
15 unsigned int i, seed, random;
16 unsigned char *buf = data;
22 nloops = len / sizeof(random);
23 seed = get_timer(0) ^ rand();
26 for (i = 0, nrem = len; i < nloops; i++) {
28 memcpy(buf, &random, sizeof(random));
29 buf += sizeof(random);
30 nrem -= sizeof(random);
35 memcpy(buf, &random, nrem);
41 static const struct dm_rng_ops sandbox_rng_ops = {
42 .read = sandbox_rng_read,
45 static const struct udevice_id sandbox_rng_match[] = {
47 .compatible = "sandbox,sandbox-rng",
52 U_BOOT_DRIVER(sandbox_rng) = {
53 .name = "sandbox-rng",
55 .of_match = sandbox_rng_match,
56 .ops = &sandbox_rng_ops,