Add constants for fast path resume copying
[coreboot.git] / util / ectool / ectool.c
1 /*
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
8  * published by the Free Software Foundation; version 2 of the License.
9  *
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
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18  */
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
30 void print_version(void)
31 {
32         printf("ectool v%s -- ", ECTOOL_VERSION);
33         printf("Copyright (C) 2008-2009 coresystems GmbH\n\n");
34         printf(
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"
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");
44 }
45
46 void print_usage(const char *name)
47 {
48         printf("usage: %s [-vh?Vi]\n", name);
49         printf("\n"
50                "   -v | --version:                   print the version\n"
51                "   -h | --help:                      print this help\n\n"
52                "   -V | --verbose:                   print debug information\n"
53                "   -i | --idx:                       print IDX RAM\n"
54                "\n");
55         exit(1);
56 }
57
58 int verbose = 0, dump_idx = 0;
59
60 int 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'},
68                 {"idx", 0, 0, 'i'},
69                 {0, 0, 0, 0}
70         };
71
72         while ((opt = getopt_long(argc, argv, "vh?Vi",
73                                   long_options, &option_index)) != EOF) {
74                 switch (opt) {
75                 case 'v':
76                         print_version();
77                         exit(0);
78                         break;
79                 case 'V':
80                         verbose = 1;
81                         break;
82                 case 'i':
83                         dump_idx = 1;
84                         break;
85                 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");
100         for (i = 0; i < 0x100; i++) {
101                 if ((i % 0x10) == 0)
102                         printf("\n%02x: ", i);
103                 printf("%02x ", ec_read(i));
104         }
105         printf("\n\n");
106
107         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");
117         }
118
119         return 0;
120 }