mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH] Add /dev/urandom device.
@ 2012-07-19  8:33 Juergen Kilb
  2012-07-19  8:33 ` [PATCH] add possibility to mark blocks as bad during write Juergen Kilb
  2012-07-27  8:30 ` [PATCH] Add /dev/urandom device Sascha Hauer
  0 siblings, 2 replies; 4+ messages in thread
From: Juergen Kilb @ 2012-07-19  8:33 UTC (permalink / raw)
  To: barebox

Nice for testing purposes.

Signed-off-by: Juergen Kilb <J.Kilb@phytec.de>
---
 commands/stddev.c |   39 +++++++++++++++++++++++++++++++++++++++
 1 files changed, 39 insertions(+), 0 deletions(-)

diff --git a/commands/stddev.c b/commands/stddev.c
index 098aea8..b807df6 100644
--- a/commands/stddev.c
+++ b/commands/stddev.c
@@ -20,7 +20,9 @@
  */
 
 #include <common.h>
+#include <clock.h>
 #include <init.h>
+#include <stdlib.h>
 
 static ssize_t zero_read(struct cdev *cdev, void *buf, size_t count, loff_t offset, ulong flags)
 {
@@ -104,3 +106,40 @@ static int null_init(void)
 }
 
 device_initcall(null_init);
+
+static ssize_t urandom_read(struct cdev *cdev, void *buf, size_t count, loff_t offset, ulong flags)
+{
+	size_t i;
+	unsigned int *buffer;
+
+	buffer = (unsigned int *) buf;
+
+	for (i = 0; i < (count / sizeof(size_t)); i++)
+		buffer[i] = rand() | rand() << 16;
+
+	return count;
+}
+
+static struct file_operations urandomops = {
+	.read  = urandom_read,
+	.lseek = dev_lseek_default,
+};
+
+static int urandom_init(void)
+{
+	struct cdev *cdev;
+
+	cdev = xzalloc(sizeof(*cdev));
+
+	cdev->name = "urandom";
+	cdev->size = ~0;
+	cdev->ops = &urandomops;
+
+	devfs_create(cdev);
+
+	srand(get_time_ns());
+
+	return 0;
+}
+
+device_initcall(urandom_init);
-- 
1.7.0.4


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2012-07-27  8:31 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-07-19  8:33 [PATCH] Add /dev/urandom device Juergen Kilb
2012-07-19  8:33 ` [PATCH] add possibility to mark blocks as bad during write Juergen Kilb
2012-07-19 14:14   ` Jean-Christophe PLAGNIOL-VILLARD
2012-07-27  8:30 ` [PATCH] Add /dev/urandom device Sascha Hauer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox