1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Copyright (c) 2019, Linaro Limited
10 #include <linux/string.h>
12 static int sandbox_rng_read(struct udevice
*dev
, void *data
, size_t len
)
14 unsigned int i
, seed
, random
;
15 unsigned char *buf
= data
;
21 nloops
= len
/ sizeof(random
);
22 seed
= get_timer(0) ^ rand();
25 for (i
= 0, nrem
= len
; i
< nloops
; i
++) {
27 memcpy(buf
, &random
, sizeof(random
));
28 buf
+= sizeof(random
);
29 nrem
-= sizeof(random
);
34 memcpy(buf
, &random
, nrem
);
40 static const struct dm_rng_ops sandbox_rng_ops
= {
41 .read
= sandbox_rng_read
,
44 static const struct udevice_id sandbox_rng_match
[] = {
46 .compatible
= "sandbox,sandbox-rng",
51 U_BOOT_DRIVER(sandbox_rng
) = {
52 .name
= "sandbox-rng",
54 .of_match
= sandbox_rng_match
,
55 .ops
= &sandbox_rng_ops
,