summaryrefslogtreecommitdiffstats
path: root/commands
diff options
context:
space:
mode:
authorSascha Hauer <s.hauer@pengutronix.de>2017-04-07 09:59:29 +0200
committerSascha Hauer <s.hauer@pengutronix.de>2017-04-07 09:59:29 +0200
commit4ef8ec1a48e2d4e459d4b2232970026bffaeb4aa (patch)
tree06c13993a65284257e8365e2b60b0c7cba93d930 /commands
parentf07295645358b59a7446421bb5c74a69d41fc96a (diff)
parentb0a0d7c05dde1476b249aa8d6d36de0189e9eeab (diff)
downloadbarebox-4ef8ec1a48e2d4e459d4b2232970026bffaeb4aa.tar.gz
barebox-4ef8ec1a48e2d4e459d4b2232970026bffaeb4aa.tar.xz
Merge branch 'for-next/hwrng'
Diffstat (limited to 'commands')
-rw-r--r--commands/Kconfig6
-rw-r--r--commands/Makefile1
-rw-r--r--commands/seed.c44
-rw-r--r--commands/stddev.c29
4 files changed, 80 insertions, 0 deletions
diff --git a/commands/Kconfig b/commands/Kconfig
index bc0885c69d..ab8e09aa45 100644
--- a/commands/Kconfig
+++ b/commands/Kconfig
@@ -2115,6 +2115,12 @@ config CMD_SPD_DECODE
help
decode spd eeprom
+config CMD_SEED
+ tristate
+ prompt "seed"
+ help
+ Seed the pseudo random number generator (PRNG)
+
# end Miscellaneous commands
endmenu
diff --git a/commands/Makefile b/commands/Makefile
index 601f15fc38..ab59021562 100644
--- a/commands/Makefile
+++ b/commands/Makefile
@@ -120,3 +120,4 @@ obj-$(CONFIG_CMD_DHRYSTONE) += dhrystone.o
obj-$(CONFIG_CMD_SPD_DECODE) += spd_decode.o
obj-$(CONFIG_CMD_MMC_EXTCSD) += mmc_extcsd.o
obj-$(CONFIG_CMD_NAND_BITFLIP) += nand-bitflip.o
+obj-$(CONFIG_CMD_SEED) += seed.o
diff --git a/commands/seed.c b/commands/seed.c
new file mode 100644
index 0000000000..e378cd7635
--- /dev/null
+++ b/commands/seed.c
@@ -0,0 +1,44 @@
+/*
+ * (c) 2017 Oleksij Rempel <kernel@pengutronix.de>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ */
+
+#include <common.h>
+#include <command.h>
+#include <stdlib.h>
+#include <linux/ctype.h>
+
+static int do_seed(int argc, char *argv[])
+{
+ if (argc < 2)
+ return COMMAND_ERROR_USAGE;
+
+ if (isdigit(*argv[1])) {
+ srand(simple_strtoul(argv[1], NULL, 0));
+ return 0;
+ }
+
+ printf("numerical parameter expected\n");
+ return 1;
+}
+
+BAREBOX_CMD_HELP_START(seed)
+BAREBOX_CMD_HELP_TEXT("Seed the pseudo random number generator")
+BAREBOX_CMD_HELP_END
+
+BAREBOX_CMD_START(seed)
+ .cmd = do_seed,
+ BAREBOX_CMD_DESC("seed the PRNG")
+ BAREBOX_CMD_OPTS("VALUE")
+ BAREBOX_CMD_GROUP(CMD_GRP_MISC)
+ BAREBOX_CMD_HELP(cmd_seed_help)
+BAREBOX_CMD_END
diff --git a/commands/stddev.c b/commands/stddev.c
index 318d057417..93da2c7398 100644
--- a/commands/stddev.c
+++ b/commands/stddev.c
@@ -17,6 +17,7 @@
#include <common.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)
{
@@ -100,3 +101,31 @@ static int null_init(void)
}
device_initcall(null_init);
+
+static ssize_t prng_read(struct cdev *cdev, void *buf, size_t count, loff_t offset, ulong flags)
+{
+ get_random_bytes(buf, count);
+ return count;
+}
+
+static struct file_operations prngops = {
+ .read = prng_read,
+ .lseek = dev_lseek_default,
+};
+
+static int prng_init(void)
+{
+ struct cdev *cdev;
+
+ cdev = xzalloc(sizeof (*cdev));
+
+ cdev->name = "prng";
+ cdev->flags = DEVFS_IS_CHARACTER_DEV;
+ cdev->ops = &prngops;
+
+ devfs_create(cdev);
+
+ return 0;
+}
+
+device_initcall(prng_init);