blob: ab7728238f3d3d2c52346e5feb3a219e067c2ccd [file] [log] [blame]
Stefan Reinauerb5ab3232009-04-22 07:23:00 +00001/*
2 * This file is part of the ectool project.
3 *
4 * Copyright (C) 2008-2009 coresystems GmbH
5 *
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
Uwe Hermann257ae3f2009-04-22 12:28:14 +00008 * published by the Free Software Foundation; version 2 of the License.
Stefan Reinauerb5ab3232009-04-22 07:23:00 +00009 *
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.
14 *
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
Uwe Hermann257ae3f2009-04-22 12:28:14 +000017 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Stefan Reinauerb5ab3232009-04-22 07:23:00 +000018 */
19
20#include <stdio.h>
21#include <stdint.h>
22#include <stdlib.h>
23#include <unistd.h>
24#include <getopt.h>
25#include <sys/io.h>
26#include <ec.h>
27
28#define ECTOOL_VERSION "0.1"
29
30void print_version(void)
31{
32 printf("ectool v%s -- ", ECTOOL_VERSION);
33 printf("Copyright (C) 2008-2009 coresystems GmbH\n\n");
34 printf(
Uwe Hermann257ae3f2009-04-22 12:28:14 +000035 "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"
42 "You should have received a copy of the GNU General Public License\n"
43 "along with this program. If not, see <http://www.gnu.org/licenses/>.\n\n");
Stefan Reinauerb5ab3232009-04-22 07:23:00 +000044}
45
46void print_usage(const char *name)
47{
Anton Kochkov7e59f7692010-06-29 21:13:20 +000048 printf("usage: %s [-vh?Vi]\n", name);
Stefan Reinauerb5ab3232009-04-22 07:23:00 +000049 printf("\n"
Uwe Hermann257ae3f2009-04-22 12:28:14 +000050 " -v | --version: print the version\n"
51 " -h | --help: print this help\n\n"
52 " -V | --verbose: print debug information\n"
Anton Kochkov7e59f7692010-06-29 21:13:20 +000053 " -i | --idx: print IDX RAM\n"
Uwe Hermann257ae3f2009-04-22 12:28:14 +000054 "\n");
Stefan Reinauerb5ab3232009-04-22 07:23:00 +000055 exit(1);
56}
57
Anton Kochkov7e59f7692010-06-29 21:13:20 +000058int verbose = 0, dump_idx = 0;
Stefan Reinauerb5ab3232009-04-22 07:23:00 +000059
60int main(int argc, char *argv[])
61{
62 int i, opt, option_index = 0;
63
64 static struct option long_options[] = {
65 {"version", 0, 0, 'v'},
66 {"help", 0, 0, 'h'},
67 {"verbose", 0, 0, 'V'},
Anton Kochkov7e59f7692010-06-29 21:13:20 +000068 {"idx", 0, 0, 'i'},
Stefan Reinauerb5ab3232009-04-22 07:23:00 +000069 {0, 0, 0, 0}
70 };
71
Anton Kochkov7e59f7692010-06-29 21:13:20 +000072 while ((opt = getopt_long(argc, argv, "vh?Vi",
Uwe Hermann257ae3f2009-04-22 12:28:14 +000073 long_options, &option_index)) != EOF) {
Stefan Reinauerb5ab3232009-04-22 07:23:00 +000074 switch (opt) {
75 case 'v':
76 print_version();
77 exit(0);
78 break;
79 case 'V':
80 verbose = 1;
81 break;
Anton Kochkov7e59f7692010-06-29 21:13:20 +000082 case 'i':
83 dump_idx = 1;
Peter Stuge11abcc0a2010-10-25 02:12:04 +000084 break;
Stefan Reinauerb5ab3232009-04-22 07:23:00 +000085 case 'h':
86 case '?':
87 default:
88 print_usage(argv[0]);
89 exit(0);
90 break;
91 }
92 }
93
94 if (iopl(3)) {
95 printf("You need to be root.\n");
96 exit(1);
97 }
98
99 printf("EC RAM:\n");
Uwe Hermann257ae3f2009-04-22 12:28:14 +0000100 for (i = 0; i < 0x100; i++) {
101 if ((i % 0x10) == 0)
102 printf("\n%02x: ", i);
Stefan Reinauerb5ab3232009-04-22 07:23:00 +0000103 printf("%02x ", ec_read(i));
104 }
105 printf("\n\n");
Uwe Hermann257ae3f2009-04-22 12:28:14 +0000106
Anton Kochkov7e59f7692010-06-29 21:13:20 +0000107 if (dump_idx) {
108 printf("EC IDX RAM:\n");
109 for (i = 0; i < 0x10000; i++) {
110 if ((i % 0x10) == 0)
111 printf("\n%04x: ", i);
112 printf("%02x ", ec_idx_read(i));
113 }
114 printf("\n\n");
115 } else {
116 printf("Not dumping EC IDX RAM.\n");
Stefan Reinauer984e0f32010-01-16 17:50:55 +0000117 }
Stefan Reinauer984e0f32010-01-16 17:50:55 +0000118
Stefan Reinauerb5ab3232009-04-22 07:23:00 +0000119 return 0;
120}