diff options
Diffstat (limited to 'arch/sandbox/board')
-rw-r--r-- | arch/sandbox/board/Makefile | 1 | ||||
-rw-r--r-- | arch/sandbox/board/board.c | 7 | ||||
-rw-r--r-- | arch/sandbox/board/dev-random.c | 24 |
3 files changed, 32 insertions, 0 deletions
diff --git a/arch/sandbox/board/Makefile b/arch/sandbox/board/Makefile index b6c271c858..26f6cb1922 100644 --- a/arch/sandbox/board/Makefile +++ b/arch/sandbox/board/Makefile @@ -5,5 +5,6 @@ obj-y += console.o obj-y += devices.o obj-y += dtb.o obj-y += poweroff.o +obj-y += dev-random.o extra-y += barebox.lds diff --git a/arch/sandbox/board/board.c b/arch/sandbox/board/board.c index 1f6392d15e..ad2bc910c3 100644 --- a/arch/sandbox/board/board.c +++ b/arch/sandbox/board/board.c @@ -42,6 +42,11 @@ static struct device_d sdl_device = { .platform_data = &mode, }; +static struct device_d devrandom_device = { + .id = DEVICE_ID_DYNAMIC, + .name = "devrandom", +}; + static int devices_init(void) { platform_device_register(&tap_device); @@ -54,6 +59,8 @@ static int devices_init(void) platform_device_register(&sdl_device); + platform_device_register(&devrandom_device); + return 0; } diff --git a/arch/sandbox/board/dev-random.c b/arch/sandbox/board/dev-random.c new file mode 100644 index 0000000000..f65e5ef6e5 --- /dev/null +++ b/arch/sandbox/board/dev-random.c @@ -0,0 +1,24 @@ +#include <common.h> +#include <mach/linux.h> + +devrandom_t *devrandom_init(void) { + devrandom_t *fds = xzalloc(sizeof(*fds)); + + fds->randomfd = linux_open("/dev/random", false); + if (fds->randomfd < 0) + return ERR_PTR(-EPERM); + + fds->urandomfd = linux_open("/dev/urandom", false); + if (fds->urandomfd < 0) + return ERR_PTR(-EPERM); + + return fds; +} + +int devrandom_read(devrandom_t *devrandom, void *buf, size_t len, int wait) +{ + if (wait) + return linux_read(devrandom->randomfd, buf, len); + + return linux_read(devrandom->urandomfd, buf, len); +} |