Add 'install' target for ectool (trivial).
[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?V]\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                "\n");
54         exit(1);
55 }
56
57 int verbose = 0;
58
59 int main(int argc, char *argv[])
60 {
61         int i, opt, option_index = 0;
62
63         static struct option long_options[] = {
64                 {"version", 0, 0, 'v'},
65                 {"help", 0, 0, 'h'},
66                 {"verbose", 0, 0, 'V'},
67                 {0, 0, 0, 0}
68         };
69
70         while ((opt = getopt_long(argc, argv, "vh?V",
71                                   long_options, &option_index)) != EOF) {
72                 switch (opt) {
73                 case 'v':
74                         print_version();
75                         exit(0);
76                         break;
77                 case 'V':
78                         verbose = 1;
79                         break;
80                 case 'h':
81                 case '?':
82                 default:
83                         print_usage(argv[0]);
84                         exit(0);
85                         break;
86                 }
87         }
88
89         if (iopl(3)) {
90                 printf("You need to be root.\n");
91                 exit(1);
92         }
93
94         printf("EC RAM:\n");
95         for (i = 0; i < 0x100; i++) {
96                 if ((i % 0x10) == 0)
97                         printf("\n%02x: ", i);
98                 printf("%02x ", ec_read(i));
99         }
100         printf("\n\n");
101
102         return 0;
103 }