[coreboot-gerrit] Change in coreboot[master]: ectool: Add an option to get and use EC ports from /proc/ioports

Iru Cai (Code Review) gerrit at coreboot.org
Thu Jan 25 15:02:52 CET 2018


Iru Cai has uploaded this change for review. ( https://review.coreboot.org/23430


Change subject: ectool: Add an option to get and use EC ports from /proc/ioports
......................................................................

ectool: Add an option to get and use EC ports from /proc/ioports

There are boards that don't use ports 0x62 and 0x66 for EC, e.g. Dell
Latitude E6230 uses 0x930 and 0x934.

Change-Id: Ie3005f5cd6e37206ef187267b0542efdeb26b3af
Signed-off-by: Iru Cai <mytbk920423 at gmail.com>
---
M util/ectool/ec.c
M util/ectool/ec.h
M util/ectool/ectool.c
3 files changed, 39 insertions(+), 3 deletions(-)



  git pull ssh://review.coreboot.org:29418/coreboot refs/changes/30/23430/1

diff --git a/util/ectool/ec.c b/util/ectool/ec.c
index 53a5360..f162911 100644
--- a/util/ectool/ec.c
+++ b/util/ectool/ec.c
@@ -16,12 +16,16 @@
 #include <stdio.h>
 #include <stdint.h>
 #include <stdlib.h>
+#include <string.h>
 #include <unistd.h>
 #if !(defined __NetBSD__ || defined __OpenBSD__)
 #include <sys/io.h>
 #endif
 #include "ec.h"
 
+int EC_DATA = 0x62;
+int EC_SC = 0x66;
+
 #if defined __NetBSD__ || defined __OpenBSD__
 #include <machine/sysarch.h>
 static uint8_t inb(unsigned port)
@@ -165,3 +169,29 @@
 	send_ec_command(QR_EC);
 	return recv_ec_data();
 }
+
+void get_ec_ports(void)
+{
+	FILE *fp = fopen("/proc/ioports", "r");
+	int ec_data = 0, ec_cmd = 0;
+	char line[100];
+
+	while (!feof(fp) && (ec_data == 0 || ec_cmd == 0)) {
+		fgets(line, sizeof(line), fp);
+		if (strstr(line, "EC data") != NULL)
+			ec_data = strtol(line, NULL, 16);
+
+		if (strstr(line, "EC cmd") != NULL)
+			ec_cmd = strtol(line, NULL, 16);
+	}
+
+	fclose(fp);
+	if (ec_data != 0 && ec_cmd != 0) {
+		printf("EC data = 0x%x, EC cmd = 0x%x\n", ec_data, ec_cmd);
+		EC_DATA = ec_data;
+		EC_SC = ec_cmd;
+	} else {
+		puts("No EC ports found!");
+		exit(1);
+	}
+}
diff --git a/util/ectool/ec.h b/util/ectool/ec.h
index 4f65f60..5e32233 100644
--- a/util/ectool/ec.h
+++ b/util/ectool/ec.h
@@ -16,8 +16,8 @@
 #ifndef _EC_H
 #define _EC_H
 
-#define EC_DATA		0x62
-#define EC_SC		0x66
+extern int EC_DATA;
+extern int EC_SC;
 
 /* EC_SC input */
 #define   EC_SMI_EVT	(1 << 6)	// 1: SMI event pending
@@ -47,4 +47,5 @@
 int ec_ext_write(uint16_t addr, uint8_t data);
 uint8_t ec_idx_read(uint16_t addr);
 uint8_t ec_query(void);
+void get_ec_ports(void);
 #endif
diff --git a/util/ectool/ectool.c b/util/ectool/ectool.c
index dcf1728..3a5cd89 100644
--- a/util/ectool/ectool.c
+++ b/util/ectool/ectool.c
@@ -62,6 +62,7 @@
 	       "   -v | --version:                   print the version\n"
 	       "   -h | --help:                      print this help\n\n"
 	       "   -V | --verbose:                   print debug information\n"
+	       "   -p | --getports:                  print and use EC data and cmd ports from /proc/ioports\n"
 	       "   -d | --dump:                      print RAM\n"
 	       "   -i | --idx:                       print IDX RAM & RAM\n"
 	       "   -q | --query:                     print query byte\n"
@@ -85,10 +86,11 @@
 		{"verbose", 0, 0, 'V'},
 		{"idx", 0, 0, 'i'},
 		{"query", 0, 0, 'q'},
+		{"getports", 0, 0, 'p'},
 		{0, 0, 0, 0}
 	};
 
-	while ((opt = getopt_long(argc, argv, "vh?Vidqw:z:",
+	while ((opt = getopt_long(argc, argv, "vh?Vidqpw:z:",
 				  long_options, &option_index)) != EOF) {
 		switch (opt) {
 		case 'v':
@@ -114,6 +116,9 @@
 		case 'q':
 			dump_query = 1;
 			break;
+		case 'p':
+			get_ec_ports();
+			break;
 		case 'h':
 		case '?':
 		default:

-- 
To view, visit https://review.coreboot.org/23430
To unsubscribe, or for help writing mail filters, visit https://review.coreboot.org/settings

Gerrit-Project: coreboot
Gerrit-Branch: master
Gerrit-MessageType: newchange
Gerrit-Change-Id: Ie3005f5cd6e37206ef187267b0542efdeb26b3af
Gerrit-Change-Number: 23430
Gerrit-PatchSet: 1
Gerrit-Owner: Iru Cai <mytbk920423 at gmail.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.coreboot.org/pipermail/coreboot-gerrit/attachments/20180125/a66ba925/attachment.html>


More information about the coreboot-gerrit mailing list