Stefan Reinauer | b5ab323 | 2009-04-22 07:23:00 +0000 | [diff] [blame] | 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 |
Uwe Hermann | 257ae3f | 2009-04-22 12:28:14 +0000 | [diff] [blame] | 8 | * published by the Free Software Foundation; version 2 of the License. |
Stefan Reinauer | b5ab323 | 2009-04-22 07:23:00 +0000 | [diff] [blame] | 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 |
Uwe Hermann | 257ae3f | 2009-04-22 12:28:14 +0000 | [diff] [blame] | 17 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
Stefan Reinauer | b5ab323 | 2009-04-22 07:23:00 +0000 | [diff] [blame] | 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( |
Uwe Hermann | 257ae3f | 2009-04-22 12:28:14 +0000 | [diff] [blame] | 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"); |
Stefan Reinauer | b5ab323 | 2009-04-22 07:23:00 +0000 | [diff] [blame] | 44 | } |
| 45 | |
| 46 | void print_usage(const char *name) |
| 47 | { |
Anton Kochkov | 7e59f769 | 2010-06-29 21:13:20 +0000 | [diff] [blame] | 48 | printf("usage: %s [-vh?Vi]\n", name); |
Stefan Reinauer | b5ab323 | 2009-04-22 07:23:00 +0000 | [diff] [blame] | 49 | printf("\n" |
Uwe Hermann | 257ae3f | 2009-04-22 12:28:14 +0000 | [diff] [blame] | 50 | " -v | --version: print the version\n" |
| 51 | " -h | --help: print this help\n\n" |
| 52 | " -V | --verbose: print debug information\n" |
Anton Kochkov | 7e59f769 | 2010-06-29 21:13:20 +0000 | [diff] [blame] | 53 | " -i | --idx: print IDX RAM\n" |
Uwe Hermann | 257ae3f | 2009-04-22 12:28:14 +0000 | [diff] [blame] | 54 | "\n"); |
Stefan Reinauer | b5ab323 | 2009-04-22 07:23:00 +0000 | [diff] [blame] | 55 | exit(1); |
| 56 | } |
| 57 | |
Anton Kochkov | 7e59f769 | 2010-06-29 21:13:20 +0000 | [diff] [blame] | 58 | int verbose = 0, dump_idx = 0; |
Stefan Reinauer | b5ab323 | 2009-04-22 07:23:00 +0000 | [diff] [blame] | 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'}, |
Anton Kochkov | 7e59f769 | 2010-06-29 21:13:20 +0000 | [diff] [blame] | 68 | {"idx", 0, 0, 'i'}, |
Stefan Reinauer | b5ab323 | 2009-04-22 07:23:00 +0000 | [diff] [blame] | 69 | {0, 0, 0, 0} |
| 70 | }; |
| 71 | |
Anton Kochkov | 7e59f769 | 2010-06-29 21:13:20 +0000 | [diff] [blame] | 72 | while ((opt = getopt_long(argc, argv, "vh?Vi", |
Uwe Hermann | 257ae3f | 2009-04-22 12:28:14 +0000 | [diff] [blame] | 73 | long_options, &option_index)) != EOF) { |
Stefan Reinauer | b5ab323 | 2009-04-22 07:23:00 +0000 | [diff] [blame] | 74 | switch (opt) { |
| 75 | case 'v': |
| 76 | print_version(); |
| 77 | exit(0); |
| 78 | break; |
| 79 | case 'V': |
| 80 | verbose = 1; |
| 81 | break; |
Anton Kochkov | 7e59f769 | 2010-06-29 21:13:20 +0000 | [diff] [blame] | 82 | case 'i': |
| 83 | dump_idx = 1; |
Peter Stuge | 11abcc0a | 2010-10-25 02:12:04 +0000 | [diff] [blame] | 84 | break; |
Stefan Reinauer | b5ab323 | 2009-04-22 07:23:00 +0000 | [diff] [blame] | 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"); |
Uwe Hermann | 257ae3f | 2009-04-22 12:28:14 +0000 | [diff] [blame] | 100 | for (i = 0; i < 0x100; i++) { |
| 101 | if ((i % 0x10) == 0) |
| 102 | printf("\n%02x: ", i); |
Stefan Reinauer | b5ab323 | 2009-04-22 07:23:00 +0000 | [diff] [blame] | 103 | printf("%02x ", ec_read(i)); |
| 104 | } |
| 105 | printf("\n\n"); |
Uwe Hermann | 257ae3f | 2009-04-22 12:28:14 +0000 | [diff] [blame] | 106 | |
Anton Kochkov | 7e59f769 | 2010-06-29 21:13:20 +0000 | [diff] [blame] | 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"); |
Stefan Reinauer | 984e0f3 | 2010-01-16 17:50:55 +0000 | [diff] [blame] | 117 | } |
Stefan Reinauer | 984e0f3 | 2010-01-16 17:50:55 +0000 | [diff] [blame] | 118 | |
Stefan Reinauer | b5ab323 | 2009-04-22 07:23:00 +0000 | [diff] [blame] | 119 | return 0; |
| 120 | } |