1 /* This file is part of the ectool project. */
2 /* SPDX-License-Identifier: GPL-2.0-only */
9 #if !(defined __NetBSD__ || defined __OpenBSD__)
14 #if defined __NetBSD__ || defined __OpenBSD__
16 #include <machine/sysarch.h>
19 # define iopl i386_iopl
20 # elif defined __NetBSD__
21 # define iopl x86_64_iopl
23 # define iopl amd64_iopl
29 #define ECTOOL_VERSION "0.1"
31 void print_version(void)
33 printf("ectool v%s -- ", ECTOOL_VERSION
);
34 printf("Copyright (C) 2008-2009 coresystems GmbH\n\n");
36 "This program is free software: you can redistribute it and/or modify\n"
37 "it under the terms of the GNU General Public License as published by\n"
38 "the Free Software Foundation, version 2 of the License.\n\n"
39 "This program is distributed in the hope that it will be useful,\n"
40 "but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
41 "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n"
42 "GNU General Public License for more details.\n\n");
45 void print_usage(const char *name
)
47 printf("usage: %s [-vh?Vidq] [-w 0x<addr> -z 0x<data>]\n", name
);
49 " -v | --version: print the version\n"
50 " -h | --help: print this help\n\n"
51 " -V | --verbose: print debug information\n"
52 " -p | --getports: get EC data & cmd ports from /proc/ioports\n"
53 " -d | --dump: print RAM\n"
54 " -i | --idx: print IDX RAM & RAM\n"
55 " -q | --query: print query byte\n"
56 " -w <addr in hex> write to addr\n"
57 " -z <data in hex> write to data\n"
62 int verbose
= 0, dump_idx
= 0, dump_ram
= 0, dump_query
= 0, get_ports
= 0;
64 int main(int argc
, char *argv
[])
66 int i
, opt
, option_index
= 0;
70 static struct option long_options
[] = {
71 {"version", 0, 0, 'v'},
73 {"verbose", 0, 0, 'V'},
76 {"getports", 0, 0, 'p'},
80 if (argv
[1] == NULL
) {
85 while ((opt
= getopt_long(argc
, argv
, "vh?Vidqpw:z:",
86 long_options
, &option_index
)) != EOF
) {
100 write_addr
= strtol(optarg
, NULL
, 16);
103 write_data
= strtol(optarg
, NULL
, 16);
117 print_usage(argv
[0]);
124 fprintf(stderr
, "Error: Extra parameter found.\n");
125 print_usage(argv
[0]);
129 if (get_ports
&& get_ec_ports() != 0)
130 fprintf(stderr
, "Cannot get EC ports from /proc/ioports, "
131 "fallback to default.");
134 printf("You need to be root.\n");
137 if (write_addr
>= 0 && write_data
>= 0) {
140 printf("\nWriting ec %02lx = %02lx\n", write_addr
& 0xff, write_data
& 0xff);
141 ec_write(write_addr
& 0xff, write_data
& 0xff);
144 /* preserve default - dump_ram if nothing selected */
145 if (!dump_ram
&& !dump_idx
&& !dump_query
&& (write_addr
== -1))
150 for (i
= 0; i
< 0x100; i
++) {
152 printf("\n%02x: ", i
);
153 printf("%02x ", ec_read(i
));
159 printf("EC QUERY %02x\n", ec_query());
163 printf("EC IDX RAM:\n");
164 for (i
= 0; i
< 0x10000; i
++) {
166 printf("\n%04x: ", i
);
167 printf("%02x ", ec_idx_read(i
));