summaryrefslogtreecommitdiffstats
path: root/commands/memset.c
diff options
context:
space:
mode:
authorSascha Hauer <s.hauer@pengutronix.de>2013-04-17 11:10:43 +0200
committerSascha Hauer <s.hauer@pengutronix.de>2013-04-17 13:36:31 +0200
commite10c1845b2351099c2097fe29629983002b63a37 (patch)
tree5def9d940a6553f02b01c9eb09fb3575a80037bc /commands/memset.c
parent81c118aa9e2090d7bca7f164c6917ae2912d31ff (diff)
downloadbarebox-e10c1845b2351099c2097fe29629983002b63a37.tar.gz
barebox-e10c1845b2351099c2097fe29629983002b63a37.tar.xz
memory commands: separate into one file per command
Normally in commands we have one file per command which is named like the command itself. The memory commands are an exception to this. This patch changes this by separating the memory commands. This also has the effect that the memory commands can now be selected individually. Along the way we add some Kconfig help text for the commmands. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'commands/memset.c')
-rw-r--r--commands/memset.c101
1 files changed, 101 insertions, 0 deletions
diff --git a/commands/memset.c b/commands/memset.c
new file mode 100644
index 0000000000..48e55bc68e
--- /dev/null
+++ b/commands/memset.c
@@ -0,0 +1,101 @@
+/*
+ * Copyright (c) 2011 Sascha Hauer <s.hauer@pengutronix.de>, Pengutronix
+ *
+ * See file CREDITS for list of people who contributed to this
+ * project.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2
+ * as published by the Free Software Foundation.
+ *
+ * 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.
+ *
+ */
+
+/*
+ * Memory Functions
+ *
+ * Copied from FADS ROM, Dan Malek (dmalek@jlc.net)
+ */
+
+#include <common.h>
+#include <command.h>
+#include <init.h>
+#include <driver.h>
+#include <malloc.h>
+#include <errno.h>
+#include <fs.h>
+#include <fcntl.h>
+#include <getopt.h>
+#include <linux/stat.h>
+#include <xfuncs.h>
+
+extern char *mem_rw_buf;
+
+static int do_memset(int argc, char *argv[])
+{
+ loff_t s, c, n;
+ int fd;
+ char *buf;
+ int mode = O_RWSIZE_1;
+ int ret = 1;
+ char *file = "/dev/mem";
+
+ if (mem_parse_options(argc, argv, "bwld:", &mode, NULL, &file,
+ NULL) < 0)
+ return 1;
+
+ if (optind + 3 > argc)
+ return COMMAND_ERROR_USAGE;
+
+ s = strtoull_suffix(argv[optind], NULL, 0);
+ c = strtoull_suffix(argv[optind + 1], NULL, 0);
+ n = strtoull_suffix(argv[optind + 2], NULL, 0);
+
+ fd = open_and_lseek(file, mode | O_WRONLY, s);
+ if (fd < 0)
+ return 1;
+
+ buf = xmalloc(RW_BUF_SIZE);
+ memset(buf, c, RW_BUF_SIZE);
+
+ while (n > 0) {
+ int now;
+
+ now = min((loff_t)RW_BUF_SIZE, n);
+
+ ret = write(fd, buf, now);
+ if (ret < 0) {
+ perror("write");
+ ret = 1;
+ goto out;
+ }
+
+ n -= now;
+ }
+
+ ret = 0;
+out:
+ close(fd);
+ free(buf);
+
+ return ret;
+}
+
+static const __maybe_unused char cmd_memset_help[] =
+"Usage: memset [OPTIONS] <addr> <c> <n>\n"
+"\n"
+"options:\n"
+" -b, -w, -l use byte, halfword, or word accesses\n"
+" -d <file> destination file (default /dev/mem)\n"
+"\n"
+"Fill the first <n> bytes at offset <addr> with byte <c>\n";
+
+BAREBOX_CMD_START(memset)
+ .cmd = do_memset,
+ .usage = "memory fill",
+ BAREBOX_CMD_HELP(cmd_memset_help)
+BAREBOX_CMD_END