ectool: add write support

Use `ectool -w <addr> -z <data>` to write into ec ram

Change-Id: Id4aca045f6b7c2343be96ea474ee74033897b8b7
Signed-off-by: Alexander Couzens <lynxis@fe80.eu>
Reviewed-on: http://review.coreboot.org/8323
Tested-by: build bot (Jenkins)
Reviewed-by: Nicolas Reinecke <nr@das-labor.org>
Reviewed-by: Peter Stuge <peter@stuge.se>
This commit is contained in:
Alexander Couzens 2015-02-02 08:51:30 +01:00 committed by Peter Stuge
parent 754fac4346
commit a5410dc450
1 changed files with 19 additions and 2 deletions

View File

@ -24,6 +24,7 @@
#include <getopt.h> #include <getopt.h>
#include <sys/io.h> #include <sys/io.h>
#include <ec.h> #include <ec.h>
#include <stdlib.h>
#define ECTOOL_VERSION "0.1" #define ECTOOL_VERSION "0.1"
@ -45,12 +46,14 @@ void print_version(void)
void print_usage(const char *name) void print_usage(const char *name)
{ {
printf("usage: %s [-vh?Vi]\n", name); printf("usage: %s [-vh?Vi] [-w 0x<addr> -z 0x<data>]\n", name);
printf("\n" printf("\n"
" -v | --version: print the version\n" " -v | --version: print the version\n"
" -h | --help: print this help\n\n" " -h | --help: print this help\n\n"
" -V | --verbose: print debug information\n" " -V | --verbose: print debug information\n"
" -i | --idx: print IDX RAM\n" " -i | --idx: print IDX RAM\n"
" -w <addr in hex> write to addr\n"
" -z <data in hex> write to data\n"
"\n"); "\n");
exit(1); exit(1);
} }
@ -60,6 +63,8 @@ int verbose = 0, dump_idx = 0;
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
int i, opt, option_index = 0; int i, opt, option_index = 0;
long write_data = -1;
long write_addr = -1;
static struct option long_options[] = { static struct option long_options[] = {
{"version", 0, 0, 'v'}, {"version", 0, 0, 'v'},
@ -69,7 +74,7 @@ int main(int argc, char *argv[])
{0, 0, 0, 0} {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) { long_options, &option_index)) != EOF) {
switch (opt) { switch (opt) {
case 'v': case 'v':
@ -82,6 +87,12 @@ int main(int argc, char *argv[])
case 'i': case 'i':
dump_idx = 1; dump_idx = 1;
break; break;
case 'w':
write_addr = strtol(optarg , NULL, 16);
break;
case 'z':
write_data = strtol(optarg , NULL, 16);
break;
case 'h': case 'h':
case '?': case '?':
default: default:
@ -95,6 +106,12 @@ int main(int argc, char *argv[])
printf("You need to be root.\n"); printf("You need to be root.\n");
exit(1); 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"); printf("EC RAM:\n");
for (i = 0; i < 0x100; i++) { for (i = 0; i < 0x100; i++) {