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.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
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"
43 "You should have received a copy of the GNU General Public License\n"
44 "along with this program. If not, see <http://www.gnu.org/licenses/>.\n\n");
47 void print_usage(const char *name
)
49 printf("usage: %s [-vh?Vidq] [-w 0x<addr> -z 0x<data>]\n", name
);
51 " -v | --version: print the version\n"
52 " -h | --help: print this help\n\n"
53 " -V | --verbose: print debug information\n"
54 " -d | --dump: print RAM\n"
55 " -i | --idx: print IDX RAM & RAM\n"
56 " -q | --query: print query byte\n"
57 " -w <addr in hex> write to addr\n"
58 " -z <data in hex> write to data\n"
63 int verbose
= 0, dump_idx
= 0, dump_ram
= 0, dump_query
= 0;
65 int main(int argc
, char *argv
[])
67 int i
, opt
, option_index
= 0;
71 static struct option long_options
[] = {
72 {"version", 0, 0, 'v'},
74 {"verbose", 0, 0, 'V'},
80 while ((opt
= getopt_long(argc
, argv
, "vh?Vidqw:z:",
81 long_options
, &option_index
)) != EOF
) {
95 write_addr
= strtol(optarg
, NULL
, 16);
98 write_data
= strtol(optarg
, NULL
, 16);
109 print_usage(argv
[0]);
116 printf("You need to be root.\n");
119 if (write_addr
>= 0 && write_data
>= 0) {
122 printf("\nWriting ec %02lx = %02lx\n", write_addr
& 0xff, write_data
& 0xff);
123 ec_write(write_addr
& 0xff, write_data
& 0xff);
126 /* preserve default - dump_ram if nothing selected */
127 if (!dump_ram
&& !dump_idx
&& !dump_query
) {
133 for (i
= 0; i
< 0x100; i
++) {
135 printf("\n%02x: ", i
);
136 printf("%02x ", ec_read(i
));
142 printf("EC QUERY %02x\n", ec_query());
146 printf("EC IDX RAM:\n");
147 for (i
= 0; i
< 0x10000; i
++) {
149 printf("\n%04x: ", i
);
150 printf("%02x ", ec_idx_read(i
));