
On Fri, 27 Dec 2019 at 12:29, Heinrich Schuchardt xypron.glpk@gmx.de wrote:
On 12/26/19 6:25 PM, Sughosh Ganu wrote:
Add a sandbox driver for random number generation. Mostly aimed at providing a unit test for rng uclass.
Signed-off-by: Sughosh Ganu sughosh.ganu@linaro.org Reviewed-by: Patrice Chotard patrice.chotard@st.com
Changes since V4:
Return number of bytes read on a successful read, and a -ve value on error.
Modify the logic of sandbox_rng_read function to use rand and srand functions to return random data, based on feedback from Heinrich Schuchardt.
arch/sandbox/dts/test.dts | 4 ++++ drivers/rng/Kconfig | 8 +++++++ drivers/rng/Makefile | 1 + drivers/rng/sandbox_rng.c | 56
+++++++++++++++++++++++++++++++++++++++++++++++
4 files changed, 69 insertions(+) create mode 100644 drivers/rng/sandbox_rng.c
<snip>
diff --git a/drivers/rng/sandbox_rng.c b/drivers/rng/sandbox_rng.c
new file mode 100644 index 0000000..5de1799 --- /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) +{
int nbytes;
unsigned int i, seed;
unsigned int *buf = data;
You assume here that data is 4 byte aligned which may not hold true and hence may lead to a crash on ARM.
Will fix.
-sughosh