2 * This file is part of the ectool project.
4 * Copyright (C) 2008-2009 coresystems GmbH
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License as
8 * published by the Free Software Foundation; version 2 of the License.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
21 #if !(defined __NetBSD__ || defined __OpenBSD__)
27 #if defined __NetBSD__ || defined __OpenBSD__
29 #include <machine/sysarch.h>
32 # define iopl i386_iopl
33 # elif defined __NetBSD__
34 # define iopl x86_64_iopl
36 # define iopl amd64_iopl
42 #define ECTOOL_VERSION "0.1"
44 void print_version(void)
46 printf("ectool v%s -- ", ECTOOL_VERSION
);
47 printf("Copyright (C) 2008-2009 coresystems GmbH\n\n");
49 "This program is free software: you can redistribute it and/or modify\n"
50 "it under the terms of the GNU General Public License as published by\n"
51 "the Free Software Foundation, version 2 of the License.\n\n"
52 "This program is distributed in the hope that it will be useful,\n"
53 "but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
54 "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n"
55 "GNU General Public License for more details.\n\n");
58 void print_usage(const char *name
)
60 printf("usage: %s [-vh?Vidq] [-w 0x<addr> -z 0x<data>]\n", name
);
62 " -v | --version: print the version\n"
63 " -h | --help: print this help\n\n"
64 " -V | --verbose: print debug information\n"
65 " -p | --getports: get EC data & cmd ports from /proc/ioports\n"
66 " -d | --dump: print RAM\n"
67 " -i | --idx: print IDX RAM & RAM\n"
68 " -q | --query: print query byte\n"
69 " -w <addr in hex> write to addr\n"
70 " -z <data in hex> write to data\n"
75 int verbose
= 0, dump_idx
= 0, dump_ram
= 0, dump_query
= 0, get_ports
= 0;
77 int main(int argc
, char *argv
[])
79 int i
, opt
, option_index
= 0;
83 static struct option long_options
[] = {
84 {"version", 0, 0, 'v'},
86 {"verbose", 0, 0, 'V'},
89 {"getports", 0, 0, 'p'},
93 if (argv
[1] == NULL
) {
98 while ((opt
= getopt_long(argc
, argv
, "vh?Vidqpw:z:",
99 long_options
, &option_index
)) != EOF
) {
113 write_addr
= strtol(optarg
, NULL
, 16);
116 write_data
= strtol(optarg
, NULL
, 16);
130 print_usage(argv
[0]);
137 fprintf(stderr
, "Error: Extra parameter found.\n");
138 print_usage(argv
[0]);
142 if (get_ports
&& get_ec_ports() != 0)
143 fprintf(stderr
, "Cannot get EC ports from /proc/ioports, "
144 "fallback to default.");
147 printf("You need to be root.\n");
150 if (write_addr
>= 0 && write_data
>= 0) {
153 printf("\nWriting ec %02lx = %02lx\n", write_addr
& 0xff, write_data
& 0xff);
154 ec_write(write_addr
& 0xff, write_data
& 0xff);
157 /* preserve default - dump_ram if nothing selected */
158 if (!dump_ram
&& !dump_idx
&& !dump_query
&& (write_addr
== -1))
163 for (i
= 0; i
< 0x100; i
++) {
165 printf("\n%02x: ", i
);
166 printf("%02x ", ec_read(i
));
172 printf("EC QUERY %02x\n", ec_query());
176 printf("EC IDX RAM:\n");
177 for (i
= 0; i
< 0x10000; i
++) {
179 printf("\n%04x: ", i
);
180 printf("%02x ", ec_idx_read(i
));