[PATCH] Add -b option to mmio_dump

1 view
Skip to first unread message

adu...@google.com

unread,
Nov 20, 2008, 11:50:51 AM11/20/08
to iotool...@googlegroups.com
Add '-b' option to mmio_dump.

Appending '-b' to the mmio_dump command will output the memory range specified
in binary format to stdout. This is useful for taking snapshots of ACPI tables,
SMBIOS tables, etc.

diff --git a/Makefile b/Makefile
index 8b18891..c8dd66d 100644
--- a/Makefile
+++ b/Makefile
@@ -33,7 +33,7 @@ else
IOTOOLS_DEBUG = -O2 -DNDEBUG
endif

-CFLAGS = -Wall -Werror $(DEFS) $(ARCHFLAGS) $(IOTOOLS_STATIC) $(IOTOOLS_DEBUG)
+CFLAGS = -m32 -Wall -Werror $(DEFS) $(ARCHFLAGS) $(IOTOOLS_STATIC) $(IOTOOLS_DEBUG)
DEFS = -D_GNU_SOURCE -DVER_MAJOR=$(VER_MAJOR) -DVER_MINOR=$(VER_MINOR)
SBINDIR ?= /usr/local/sbin

diff --git a/mmio_rw.c b/mmio_rw.c
index e6be63d..8b39ed2 100644
--- a/mmio_rw.c
+++ b/mmio_rw.c
@@ -180,15 +180,32 @@ mmio_dump(int argc, const char *argv[], const struct cmd_info *info)
uint32_t *addr;
uint64_t desired_addr;
int fields_on_line;
+ int write_binary;

desired_addr = strtoull(argv[1], NULL, 0);
bytes_to_dump = strtoul(argv[2], NULL, 0);

+ write_binary = 0;
+ if (argc == 4) {
+ if (!strcmp(argv[3], "-b")) {
+ write_binary = 1;
+ } else {
+ return -1;
+ }
+ }
+
mmap_addr.addr = desired_addr;
if (open_mapping(&mmap_addr, O_RDONLY, bytes_to_dump) < 0) {
return -1;
}

+ if (write_binary) {
+ void *buffer_to_write = (void *)mmap_addr.mem + mmap_addr.off;
+ fwrite(buffer_to_write, bytes_to_dump, 1, stdout);
+ close_mapping(&mmap_addr);
+ return 0;
+ }
+
addr = (void *)mmap_addr.mem + mmap_addr.off;
bytes_left = bytes_to_dump;

@@ -237,7 +254,7 @@ mmio_dump(int argc, const char *argv[], const struct cmd_info *info)

MAKE_PREREQ_PARAMS_FIXED_ARGS(rd_params, 2, "<addr>", 0);
MAKE_PREREQ_PARAMS_FIXED_ARGS(wr_params, 3, "<addr> <value>", 0);
-MAKE_PREREQ_PARAMS_FIXED_ARGS(dump_params, 3, "<addr> <num_bytes>", 0);
+MAKE_PREREQ_PARAMS_VAR_ARGS(dump_params, 3, 4, "<addr> <num_bytes> [-b]", 0);

#define MAKE_MMIO_READ_CMD(size_) \
MAKE_CMD_WITH_PARAMS(mmio_read ##size_, &mmio_read_x, &size ##size_, \

adu...@google.com

unread,
Nov 20, 2008, 12:24:40 PM11/20/08
to iotool...@googlegroups.com
Add '-b' option to mmio_dump.

Appending '-b' to the mmio_dump command will output the memory range specified
in binary format to stdout. This is useful for taking snapshots of ACPI tables,
SMBIOS tables, etc.

diff --git a/mmio_rw.c b/mmio_rw.c

Aaron Durbin

unread,
Nov 20, 2008, 12:25:25 PM11/20/08
to iotool...@googlegroups.com
This one is w/o the Makefile changes. Sorry about the first.

Tim Hockin

unread,
Nov 24, 2008, 3:28:12 PM11/24/08
to iotool...@googlegroups.com
LGTM
--
You know what I hate about people who criticize you? They criticize
what you say, but they never give you credit for how loud you say it.

-- Stephen Colbert to Bill O'Reilly
Reply all
Reply to author
Forward
0 new messages