summaryrefslogtreecommitdiffstats
path: root/commands/mem.c
diff options
context:
space:
mode:
authorSascha Hauer <s.hauer@pengutronix.de>2009-07-31 15:09:28 +0200
committerSascha Hauer <s.hauer@pengutronix.de>2009-07-31 15:09:28 +0200
commiteca9aba2cfe26e9509cce58c7f696604ae0091b9 (patch)
treefd38e43b792e14642150bb2141a10bb91f791fde /commands/mem.c
parentce0d6995f6a38db81391ae913cc11580ceca0951 (diff)
downloadbarebox-eca9aba2cfe26e9509cce58c7f696604ae0091b9.tar.gz
barebox-eca9aba2cfe26e9509cce58c7f696604ae0091b9.tar.xz
add memset command to u-boot
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'commands/mem.c')
-rw-r--r--commands/mem.c68
1 files changed, 68 insertions, 0 deletions
diff --git a/commands/mem.c b/commands/mem.c
index 2f91ff3cea..6b3165950f 100644
--- a/commands/mem.c
+++ b/commands/mem.c
@@ -518,6 +518,74 @@ U_BOOT_CMD_START(memcpy)
U_BOOT_CMD_HELP(cmd_memcpy_help)
U_BOOT_CMD_END
+static int do_memset(cmd_tbl_t *cmdtp, int argc, char *argv[])
+{
+ ulong s, c, n;
+ int fd;
+ char *buf;
+ int mode = O_RWSIZE_1;
+ int ret = 1;
+ char *file = DEVMEM;
+
+ if (mem_parse_options(argc, argv, "bwld:", &mode, NULL, &file) < 0)
+ return 1;
+
+ if (optind + 3 > argc) {
+ u_boot_cmd_usage(cmdtp);
+ return 1;
+ }
+
+ s = strtoul_suffix(argv[optind], NULL, 0);
+ c = strtoul_suffix(argv[optind + 1], NULL, 0);
+ n = strtoul_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(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] <src> <c> <n>\n"
+"\n"
+"options:\n"
+" -b, -w, -l use byte, halfword, or word accesses\n"
+" -s <file> source file (default /dev/mem)\n"
+" -d <file> destination file (default /dev/mem)\n"
+"\n"
+"Fill the first n bytes of area with byte c\n";
+
+U_BOOT_CMD_START(memset)
+ .maxargs = CONFIG_MAXARGS,
+ .cmd = do_memset,
+ .usage = "memory fill",
+ U_BOOT_CMD_HELP(cmd_memset_help)
+U_BOOT_CMD_END
+
static struct file_operations memops = {
.read = mem_read,
.write = mem_write,