1 /* SPDX-License-Identifier: GPL-2.0-only */
8 #if !(defined __NetBSD__ || defined __OpenBSD__)
13 #if defined __NetBSD__ || defined __OpenBSD__
15 #include <machine/sysarch.h>
18 # define iopl i386_iopl
19 # elif defined __NetBSD__
20 # define iopl x86_64_iopl
22 # define iopl amd64_iopl
28 #define ECTOOL_VERSION "0.1"
30 void print_version(void)
32 printf("ectool v%s -- ", ECTOOL_VERSION
);
33 printf("Copyright (C) 2008-2009 coresystems GmbH\n\n");
35 "This program is free software: you can redistribute it and/or modify\n"
36 "it under the terms of the GNU General Public License as published by\n"
37 "the Free Software Foundation, version 2 of the License.\n\n"
38 "This program is distributed in the hope that it will be useful,\n"
39 "but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
40 "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n"
41 "GNU General Public License for more details.\n\n");
44 void print_usage(const char *name
)
46 printf("usage: %s [-vh?Vidq] [-w 0x<addr> -z 0x<data>]\n", name
);
48 " -v | --version: print the version\n"
49 " -h | --help: print this help\n\n"
50 " -V | --verbose: print debug information\n"
51 " -p | --getports: get EC data & cmd ports from /proc/ioports\n"
52 " -d | --dump: print RAM\n"
53 " -i | --idx: print IDX RAM & RAM\n"
54 " -q | --query: print query byte\n"
55 " -w <addr in hex> write to addr\n"
56 " -z <data in hex> write to data\n"
61 int verbose
= 0, dump_idx
= 0, dump_ram
= 0, dump_query
= 0, get_ports
= 0;
63 int main(int argc
, char *argv
[])
65 int i
, opt
, option_index
= 0;
69 static struct option long_options
[] = {
70 {"version", 0, 0, 'v'},
72 {"verbose", 0, 0, 'V'},
75 {"getports", 0, 0, 'p'},
79 if (argv
[1] == NULL
) {
84 while ((opt
= getopt_long(argc
, argv
, "vh?Vidqpw:z:",
85 long_options
, &option_index
)) != EOF
) {
99 write_addr
= strtol(optarg
, NULL
, 16);
102 write_data
= strtol(optarg
, NULL
, 16);
116 print_usage(argv
[0]);
123 fprintf(stderr
, "Error: Extra parameter found.\n");
124 print_usage(argv
[0]);
128 if (get_ports
&& get_ec_ports() != 0)
129 fprintf(stderr
, "Cannot get EC ports from /proc/ioports, "
130 "fallback to default.\n");
133 printf("You need to be root.\n");
136 if (write_addr
>= 0 && write_data
>= 0) {
139 printf("\nWriting ec %02lx = %02lx\n", write_addr
& 0xff, write_data
& 0xff);
140 ec_write(write_addr
& 0xff, write_data
& 0xff);
143 /* preserve default - dump_ram if nothing selected */
144 if (!dump_ram
&& !dump_idx
&& !dump_query
&& (write_addr
== -1))
149 for (i
= 0; i
< 0x100; i
++) {
151 printf("\n%02x: ", i
);
152 printf("%02x ", ec_read(i
));
158 printf("EC QUERY %02x\n", ec_query());
162 printf("EC IDX RAM:\n");
163 for (i
= 0; i
< 0x10000; i
++) {
165 printf("\n%04x: ", i
);
166 printf("%02x ", ec_idx_read(i
));