From a5410dc450ec0272e578bdc7d0a33983c94aed0b Mon Sep 17 00:00:00 2001 From: Alexander Couzens Date: Mon, 2 Feb 2015 08:51:30 +0100 Subject: [PATCH] ectool: add write support Use `ectool -w -z ` to write into ec ram Change-Id: Id4aca045f6b7c2343be96ea474ee74033897b8b7 Signed-off-by: Alexander Couzens Reviewed-on: http://review.coreboot.org/8323 Tested-by: build bot (Jenkins) Reviewed-by: Nicolas Reinecke Reviewed-by: Peter Stuge --- util/ectool/ectool.c | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/util/ectool/ectool.c b/util/ectool/ectool.c index ab7728238f..da5143ab85 100644 --- a/util/ectool/ectool.c +++ b/util/ectool/ectool.c @@ -24,6 +24,7 @@ #include #include #include +#include #define ECTOOL_VERSION "0.1" @@ -45,12 +46,14 @@ void print_version(void) void print_usage(const char *name) { - printf("usage: %s [-vh?Vi]\n", name); + printf("usage: %s [-vh?Vi] [-w 0x -z 0x]\n", name); printf("\n" " -v | --version: print the version\n" " -h | --help: print this help\n\n" " -V | --verbose: print debug information\n" " -i | --idx: print IDX RAM\n" + " -w write to addr\n" + " -z write to data\n" "\n"); exit(1); } @@ -60,6 +63,8 @@ int verbose = 0, dump_idx = 0; int main(int argc, char *argv[]) { int i, opt, option_index = 0; + long write_data = -1; + long write_addr = -1; static struct option long_options[] = { {"version", 0, 0, 'v'}, @@ -69,7 +74,7 @@ int main(int argc, char *argv[]) {0, 0, 0, 0} }; - while ((opt = getopt_long(argc, argv, "vh?Vi", + while ((opt = getopt_long(argc, argv, "vh?Viw:z:", long_options, &option_index)) != EOF) { switch (opt) { case 'v': @@ -82,6 +87,12 @@ int main(int argc, char *argv[]) case 'i': dump_idx = 1; break; + case 'w': + write_addr = strtol(optarg , NULL, 16); + break; + case 'z': + write_data = strtol(optarg , NULL, 16); + break; case 'h': case '?': default: @@ -95,6 +106,12 @@ int main(int argc, char *argv[]) printf("You need to be root.\n"); exit(1); } + if (write_addr >= 0 && write_data >= 0) { + write_addr &= 0xff; + write_data &= 0xff; + printf("\nWriting ec %02lx = %02lx\n", write_addr & 0xff, write_data & 0xff); + ec_write(write_addr & 0xff, write_data & 0xff); + } printf("EC RAM:\n"); for (i = 0; i < 0x100; i++) {