summaryrefslogtreecommitdiffstats
path: root/commands
diff options
context:
space:
mode:
Diffstat (limited to 'commands')
-rw-r--r--commands/Kconfig17
-rw-r--r--commands/Makefile1
-rw-r--r--commands/digest.c3
-rw-r--r--commands/go.c2
-rw-r--r--commands/md.c14
-rw-r--r--commands/mem.c123
-rw-r--r--commands/memcmp.c16
-rw-r--r--commands/memcpy.c10
-rw-r--r--commands/memset.c2
-rw-r--r--commands/stddev.c4
10 files changed, 31 insertions, 161 deletions
diff --git a/commands/Kconfig b/commands/Kconfig
index 1de4b9d604..c14332c9d7 100644
--- a/commands/Kconfig
+++ b/commands/Kconfig
@@ -14,11 +14,6 @@ config COMPILE_HASH
help
Turns on compilation of digest.c
-config COMPILE_MEMORY
- bool
- help
- Turns on compilation of mem.c
-
menu "Commands"
@@ -1493,7 +1488,7 @@ config CMD_CRC_CMP
config CMD_MD
tristate
default y
- select COMPILE_MEMORY
+ select DEV_MEM
prompt "md"
help
Memory display
@@ -1517,7 +1512,7 @@ config CMD_MD
config CMD_MEMCMP
tristate
default y
- select COMPILE_MEMORY
+ select DEV_MEM
prompt "memcmp"
help
Memory compare
@@ -1539,7 +1534,7 @@ config CMD_MEMCMP
config CMD_MEMCPY
tristate
default y
- select COMPILE_MEMORY
+ select DEV_MEM
prompt "memcpy"
help
Memory copy
@@ -1558,7 +1553,7 @@ config CMD_MEMCPY
config CMD_MEMSET
tristate
default y
- select COMPILE_MEMORY
+ select DEV_MEM
prompt "memset"
help
Memory fill
@@ -1591,7 +1586,7 @@ config CMD_MEMTEST
config CMD_MM
tristate
- select COMPILE_MEMORY
+ select DEV_MEM
prompt "memory modify (mm)"
help
Memory modify with mask
@@ -1609,7 +1604,7 @@ config CMD_MM
config CMD_MW
tristate
default y
- select COMPILE_MEMORY
+ select DEV_MEM
prompt "mw"
help
Memory write
diff --git a/commands/Makefile b/commands/Makefile
index eb4796389e..358671bb5b 100644
--- a/commands/Makefile
+++ b/commands/Makefile
@@ -1,7 +1,6 @@
obj-$(CONFIG_STDDEV) += stddev.o
obj-$(CONFIG_CMD_DIGEST) += digest.o
obj-$(CONFIG_COMPILE_HASH) += hashsum.o
-obj-$(CONFIG_COMPILE_MEMORY) += mem.o
obj-$(CONFIG_CMD_BOOTM) += bootm.o
obj-$(CONFIG_CMD_UIMAGE) += uimage.o
obj-$(CONFIG_CMD_LINUX16) += linux16.o
diff --git a/commands/digest.c b/commands/digest.c
index 0edbbec32c..99b27dcc25 100644
--- a/commands/digest.c
+++ b/commands/digest.c
@@ -6,6 +6,7 @@
#include <common.h>
#include <command.h>
+#include <linux/pagemap.h>
#include <fs.h>
#include <fcntl.h>
#include <errno.h>
@@ -35,7 +36,7 @@ int __do_digest(struct digest *d, unsigned char *sig,
while (*argv) {
char *filename = "/dev/mem";
- loff_t start = 0, size = ~0;
+ loff_t start = 0, size = MAX_LFS_FILESIZE;
int show_area = 1;
/* arguments are either file, file+area or area */
diff --git a/commands/go.c b/commands/go.c
index fb319b320c..ecc2ceb6e4 100644
--- a/commands/go.c
+++ b/commands/go.c
@@ -45,7 +45,7 @@ static int do_go(int argc, char *argv[])
}
addr = memmap(fd, PROT_READ);
- if (addr == (void *)-1) {
+ if (addr == MAP_FAILED) {
perror("memmap");
goto out;
}
diff --git a/commands/md.c b/commands/md.c
index 3e83c723a3..2389c12d14 100644
--- a/commands/md.c
+++ b/commands/md.c
@@ -34,8 +34,6 @@
#include <linux/stat.h>
#include <xfuncs.h>
-extern char *mem_rw_buf;
-
static int do_mem_md(int argc, char *argv[])
{
loff_t start = 0, size = 0x100;
@@ -46,6 +44,7 @@ static int do_mem_md(int argc, char *argv[])
int mode = O_RWSIZE_4;
int swab = 0;
void *map;
+ void *buf = NULL;
if (argc < 2)
return COMMAND_ERROR_USAGE;
@@ -68,15 +67,17 @@ static int do_mem_md(int argc, char *argv[])
return 1;
map = memmap(fd, PROT_READ);
- if (map != (void *)-1) {
+ if (map != MAP_FAILED) {
ret = memory_display(map + start, start, size,
mode >> O_RWSIZE_SHIFT, swab);
goto out;
}
+ buf = xmalloc(RW_BUF_SIZE);
+
do {
now = min(size, (loff_t)RW_BUF_SIZE);
- r = read(fd, mem_rw_buf, now);
+ r = read(fd, buf, now);
if (r < 0) {
perror("read");
goto out;
@@ -84,8 +85,8 @@ static int do_mem_md(int argc, char *argv[])
if (!r)
goto out;
- if ((ret = memory_display(mem_rw_buf, start, r,
- mode >> O_RWSIZE_SHIFT, swab)))
+ if ((ret = memory_display(buf, start, r,
+ mode >> O_RWSIZE_SHIFT, swab)))
goto out;
start += r;
@@ -93,6 +94,7 @@ static int do_mem_md(int argc, char *argv[])
} while (size);
out:
+ free(buf);
close(fd);
return ret ? 1 : 0;
diff --git a/commands/mem.c b/commands/mem.c
deleted file mode 100644
index a9e12f3e55..0000000000
--- a/commands/mem.c
+++ /dev/null
@@ -1,123 +0,0 @@
-/*
- * 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>
-
-#ifdef CMD_MEM_DEBUG
-#define PRINTF(fmt,args...) printf (fmt ,##args)
-#else
-#define PRINTF(fmt,args...)
-#endif
-
-char *mem_rw_buf;
-
-/*
- * Common function for parsing options for the 'md', 'mw', 'memcpy', 'memcmp'
- * commands.
- */
-int mem_parse_options(int argc, char *argv[], char *optstr, int *mode,
- char **sourcefile, char **destfile, int *swab)
-{
- int opt;
-
- while((opt = getopt(argc, argv, optstr)) > 0) {
- switch(opt) {
- case 'b':
- *mode = O_RWSIZE_1;
- break;
- case 'w':
- *mode = O_RWSIZE_2;
- break;
- case 'l':
- *mode = O_RWSIZE_4;
- break;
- case 'q':
- *mode = O_RWSIZE_8;
- break;
- case 's':
- *sourcefile = optarg;
- break;
- case 'd':
- *destfile = optarg;
- break;
- case 'x':
- *swab = 1;
- break;
- default:
- return COMMAND_ERROR_USAGE;
- }
- }
-
- return 0;
-}
-
-static struct cdev_operations memops = {
- .read = mem_read,
- .write = mem_write,
- .memmap = generic_memmap_rw,
- .lseek = dev_lseek_default,
-};
-
-static int mem_probe(struct device_d *dev)
-{
- struct cdev *cdev;
-
- cdev = xzalloc(sizeof (*cdev));
- dev->priv = cdev;
-
- cdev->name = (char*)dev->resource[0].name;
- cdev->size = min_t(unsigned long long, resource_size(&dev->resource[0]),
- S64_MAX);
- cdev->ops = &memops;
- cdev->dev = dev;
-
- devfs_create(cdev);
-
- return 0;
-}
-
-static struct driver_d mem_drv = {
- .name = "mem",
- .probe = mem_probe,
-};
-
-static int mem_init(void)
-{
- mem_rw_buf = malloc(RW_BUF_SIZE);
- if(!mem_rw_buf)
- return -ENOMEM;
-
- add_mem_device("mem", 0, ~0, IORESOURCE_MEM_WRITEABLE);
- return platform_driver_register(&mem_drv);
-}
-device_initcall(mem_init);
diff --git a/commands/memcmp.c b/commands/memcmp.c
index 981c8cb38d..48957b4500 100644
--- a/commands/memcmp.c
+++ b/commands/memcmp.c
@@ -34,8 +34,6 @@
#include <linux/stat.h>
#include <xfuncs.h>
-extern char *mem_rw_buf;
-
static char *devmem = "/dev/mem";
static int do_memcmp(int argc, char *argv[])
@@ -45,7 +43,7 @@ static int do_memcmp(int argc, char *argv[])
char *sourcefile = devmem;
char *destfile = devmem;
int sourcefd, destfd;
- char *rw_buf1;
+ char *buf, *source_data, *dest_data;
int ret = 1;
int offset = 0;
struct stat statbuf;
@@ -84,20 +82,22 @@ static int do_memcmp(int argc, char *argv[])
return 1;
}
- rw_buf1 = xmalloc(RW_BUF_SIZE);
+ buf = xmalloc(RW_BUF_SIZE + RW_BUF_SIZE);
+ source_data = buf;
+ dest_data = buf + RW_BUF_SIZE;
while (count > 0) {
int now, r1, r2, i;
now = min((loff_t)RW_BUF_SIZE, count);
- r1 = read_full(sourcefd, mem_rw_buf, now);
+ r1 = read_full(sourcefd, source_data, now);
if (r1 < 0) {
perror("read");
goto out;
}
- r2 = read_full(destfd, rw_buf1, now);
+ r2 = read_full(destfd, dest_data, now);
if (r2 < 0) {
perror("read");
goto out;
@@ -109,7 +109,7 @@ static int do_memcmp(int argc, char *argv[])
}
for (i = 0; i < now; i++) {
- if (mem_rw_buf[i] != rw_buf1[i]) {
+ if (source_data[i] != dest_data[i]) {
printf("files differ at offset %d\n", offset);
goto out;
}
@@ -124,7 +124,7 @@ static int do_memcmp(int argc, char *argv[])
out:
close(sourcefd);
close(destfd);
- free(rw_buf1);
+ free(buf);
return ret;
}
diff --git a/commands/memcpy.c b/commands/memcpy.c
index 168ef3b4fc..ddaf767eac 100644
--- a/commands/memcpy.c
+++ b/commands/memcpy.c
@@ -34,8 +34,6 @@
#include <linux/stat.h>
#include <xfuncs.h>
-extern char *mem_rw_buf;
-
static char *devmem = "/dev/mem";
static int do_memcpy(int argc, char *argv[])
@@ -47,6 +45,7 @@ static int do_memcpy(int argc, char *argv[])
int mode = 0;
struct stat statbuf;
int ret = 0;
+ char *buf;
if (mem_parse_options(argc, argv, "bwlqs:d:", &mode, &sourcefile,
&destfile, NULL) < 0)
@@ -82,12 +81,14 @@ static int do_memcpy(int argc, char *argv[])
return 1;
}
+ buf = xmalloc(RW_BUF_SIZE);
+
while (count > 0) {
int now, r, w, tmp;
now = min((loff_t)RW_BUF_SIZE, count);
- r = read(sourcefd, mem_rw_buf, now);
+ r = read(sourcefd, buf, now);
if (r < 0) {
perror("read");
goto out;
@@ -99,7 +100,7 @@ static int do_memcpy(int argc, char *argv[])
tmp = 0;
now = r;
while (now) {
- w = write(destfd, mem_rw_buf + tmp, now);
+ w = write(destfd, buf + tmp, now);
if (w < 0) {
perror("write");
goto out;
@@ -123,6 +124,7 @@ static int do_memcpy(int argc, char *argv[])
}
out:
+ free(buf);
close(sourcefd);
close(destfd);
diff --git a/commands/memset.c b/commands/memset.c
index f99bf86c04..b0770159f8 100644
--- a/commands/memset.c
+++ b/commands/memset.c
@@ -34,8 +34,6 @@
#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;
diff --git a/commands/stddev.c b/commands/stddev.c
index 4d1b6f5108..2b3d084c83 100644
--- a/commands/stddev.c
+++ b/commands/stddev.c
@@ -27,7 +27,6 @@ static ssize_t zero_read(struct cdev *cdev, void *buf, size_t count, loff_t offs
static struct cdev_operations zeroops = {
.read = zero_read,
- .lseek = dev_lseek_default,
};
static int zero_init(void)
@@ -55,7 +54,6 @@ static ssize_t full_read(struct cdev *cdev, void *buf, size_t count, loff_t offs
static struct cdev_operations fullops = {
.read = full_read,
- .lseek = dev_lseek_default,
};
static int full_init(void)
@@ -82,7 +80,6 @@ static ssize_t null_write(struct cdev *cdev, const void *buf, size_t count, loff
static struct cdev_operations nullops = {
.write = null_write,
- .lseek = dev_lseek_default,
};
static int null_init(void)
@@ -110,7 +107,6 @@ static ssize_t prng_read(struct cdev *cdev, void *buf, size_t count, loff_t offs
static struct cdev_operations prngops = {
.read = prng_read,
- .lseek = dev_lseek_default,
};
static int prng_init(void)