[coreboot-gerrit] Change in coreboot[master]: add util/iotool: a simple tool to do inb/outb calls

Alexander Couzens (Code Review) gerrit at coreboot.org
Thu Sep 7 15:25:58 CEST 2017


Alexander Couzens has uploaded this change for review. ( https://review.coreboot.org/21438


Change subject: add util/iotool: a simple tool to do inb/outb calls
......................................................................

add util/iotool: a simple tool to do inb/outb calls

Change-Id: I4bc8501a355b76a47df7619c4cae22f76c8f5927
Signed-off-by: Alexander Couzens <lynxis at fe80.eu>
---
A util/iotool/Makefile
A util/iotool/iob.c
2 files changed, 94 insertions(+), 0 deletions(-)



  git pull ssh://review.coreboot.org:29418/coreboot refs/changes/38/21438/1

diff --git a/util/iotool/Makefile b/util/iotool/Makefile
new file mode 100644
index 0000000..7dae3f1
--- /dev/null
+++ b/util/iotool/Makefile
@@ -0,0 +1,5 @@
+
+CFLAGS ?= -Wall -Werror -g -static
+
+iob: iob.c
+	$(CC) $(CFLAGS) -o iob iob.c
diff --git a/util/iotool/iob.c b/util/iotool/iob.c
new file mode 100644
index 0000000..2d31070
--- /dev/null
+++ b/util/iotool/iob.c
@@ -0,0 +1,89 @@
+
+#include <stdlib.h>
+#include <stdio.h>
+
+#include <string.h>
+#include <sys/io.h>
+
+void usage() {
+	fprintf(stderr, "iob r|w address value\n");
+}
+
+void request_perm() {
+	int ret;
+
+	ret = iopl(3);
+	if (ret) {
+		fprintf(stderr, "iopl failed\n");
+		exit(2);
+	}
+}
+
+int readio(const char *saddr) {
+	char *endptr;
+	unsigned short int addr = 0;
+	unsigned short int value = 0;
+
+	addr = strtol(saddr, &endptr, 0);
+	if (endptr != NULL && *endptr != '\0') {
+		fprintf(stderr, "Invalid address '%s'\n", saddr);
+		return 1;
+	}
+
+	request_perm();
+	value = inb(addr);
+	printf("read %04x = %02x\n", addr, value);
+
+	return 0;
+}
+
+int writeio(const char *saddr, const char *svalue) {
+	char *endptr;
+	unsigned short int addr = 0;
+	unsigned short int value = 0;
+
+	addr = strtol(saddr, &endptr, 0) & 0xffff;
+	if (endptr != NULL && *endptr != '\0') {
+		fprintf(stderr, "Invalid address '%s'\n", saddr);
+		return 1;
+	}
+
+	value = strtol(svalue, &endptr, 0) & 0xffff;
+	if (endptr != NULL && *endptr != '\0') {
+		fprintf(stderr, "Invalid value '%s'\n", svalue);
+		return 1;
+	}
+
+	request_perm();
+	outb(value, addr);
+	fprintf(stderr, "written %02x = %02x\n", addr, value);
+
+	return 0;
+}
+
+int main(int argc, const char *argv[]) {
+	if (argc <= 2 || argc > 4) {
+		usage();
+		exit(1);
+	}
+
+	if (argv[1][0] == 'r' && argv[1][1] == '\0') {
+		/* read */
+		if (argc != 3) {
+			usage();
+			exit(1);
+		}
+		return readio(argv[2]);
+	} else if (argv[1][0] == 'w' && argv[1][1] == '\0') {
+		/* write */
+		if (argc != 4) {
+			usage();
+			exit(1);
+		}
+		return writeio(argv[2], argv[3]);
+	} else {
+		usage();
+		exit(1);
+	}
+	return 0;
+}

-- 
To view, visit https://review.coreboot.org/21438
To unsubscribe, visit https://review.coreboot.org/settings

Gerrit-Project: coreboot
Gerrit-Branch: master
Gerrit-MessageType: newchange
Gerrit-Change-Id: I4bc8501a355b76a47df7619c4cae22f76c8f5927
Gerrit-Change-Number: 21438
Gerrit-PatchSet: 1
Gerrit-Owner: Alexander Couzens <lynxis at fe80.eu>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.coreboot.org/pipermail/coreboot-gerrit/attachments/20170907/ffbe29fa/attachment.html>


More information about the coreboot-gerrit mailing list