Carl-Daniel Hailfinger | a84835a | 2010-01-07 03:24:05 +0000 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the flashrom project. |
| 3 | * |
| 4 | * Copyright (C) 2000 Silicon Integrated System Corporation |
| 5 | * Copyright (C) 2004 Tyan Corp <yhlu@tyan.com> |
| 6 | * Copyright (C) 2005-2008 coresystems GmbH |
| 7 | * Copyright (C) 2008,2009,2010 Carl-Daniel Hailfinger |
| 8 | * |
| 9 | * This program is free software; you can redistribute it and/or modify |
| 10 | * it under the terms of the GNU General Public License as published by |
| 11 | * the Free Software Foundation; either version 2 of the License, or |
| 12 | * (at your option) any later version. |
| 13 | * |
| 14 | * This program is distributed in the hope that it will be useful, |
| 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 17 | * GNU General Public License for more details. |
| 18 | * |
| 19 | * You should have received a copy of the GNU General Public License |
| 20 | * along with this program; if not, write to the Free Software |
| 21 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
| 22 | */ |
| 23 | |
Carl-Daniel Hailfinger | 831e8f4 | 2010-05-30 22:24:40 +0000 | [diff] [blame] | 24 | #include <stdio.h> |
Carl-Daniel Hailfinger | a84835a | 2010-01-07 03:24:05 +0000 | [diff] [blame] | 25 | #include <fcntl.h> |
Carl-Daniel Hailfinger | a84835a | 2010-01-07 03:24:05 +0000 | [diff] [blame] | 26 | #include <sys/stat.h> |
| 27 | #include <string.h> |
| 28 | #include <stdlib.h> |
| 29 | #include <getopt.h> |
| 30 | #include "flash.h" |
| 31 | #include "flashchips.h" |
Carl-Daniel Hailfinger | 5b997c3 | 2010-07-27 22:41:39 +0000 | [diff] [blame] | 32 | #include "programmer.h" |
Carl-Daniel Hailfinger | a84835a | 2010-01-07 03:24:05 +0000 | [diff] [blame] | 33 | |
Carl-Daniel Hailfinger | ad3cc55 | 2010-07-03 11:02:10 +0000 | [diff] [blame] | 34 | static void cli_classic_usage(const char *name) |
Carl-Daniel Hailfinger | a84835a | 2010-01-07 03:24:05 +0000 | [diff] [blame] | 35 | { |
Uwe Hermann | 2db77a0 | 2010-06-04 17:07:39 +0000 | [diff] [blame] | 36 | printf("Usage: flashrom [-n] [-V] [-f] [-h|-R|-L|" |
Carl-Daniel Hailfinger | 7112772 | 2010-05-31 15:27:27 +0000 | [diff] [blame] | 37 | #if CONFIG_PRINT_WIKI == 1 |
Carl-Daniel Hailfinger | 8841d3e | 2010-05-15 15:04:37 +0000 | [diff] [blame] | 38 | "-z|" |
Carl-Daniel Hailfinger | a84835a | 2010-01-07 03:24:05 +0000 | [diff] [blame] | 39 | #endif |
Carl-Daniel Hailfinger | 8841d3e | 2010-05-15 15:04:37 +0000 | [diff] [blame] | 40 | "-E|-r <file>|-w <file>|-v <file>]\n" |
| 41 | " [-c <chipname>] [-m [<vendor>:]<part>] [-l <file>]\n" |
Uwe Hermann | 2db77a0 | 2010-06-04 17:07:39 +0000 | [diff] [blame] | 42 | " [-i <image>] [-p <programmername>[:<parameters>]]\n\n"); |
Carl-Daniel Hailfinger | 8841d3e | 2010-05-15 15:04:37 +0000 | [diff] [blame] | 43 | |
| 44 | printf("Please note that the command line interface for flashrom has " |
| 45 | "changed between\n" |
| 46 | "0.9.1 and 0.9.2 and will change again before flashrom 1.0.\n" |
| 47 | "Do not use flashrom in scripts or other automated tools " |
| 48 | "without checking\n" |
| 49 | "that your flashrom version won't interpret options in a " |
| 50 | "different way.\n\n"); |
| 51 | |
| 52 | printf(" -h | --help print this help text\n" |
| 53 | " -R | --version print version (release)\n" |
| 54 | " -r | --read <file> read flash and save to " |
| 55 | "<file>\n" |
| 56 | " -w | --write <file> write <file> to flash\n" |
| 57 | " -v | --verify <file> verify flash against " |
| 58 | "<file>\n" |
| 59 | " -E | --erase erase flash device\n" |
| 60 | " -V | --verbose more verbose output\n" |
| 61 | " -c | --chip <chipname> probe only for specified " |
| 62 | "flash chip\n" |
Carl-Daniel Hailfinger | 7112772 | 2010-05-31 15:27:27 +0000 | [diff] [blame] | 63 | #if CONFIG_INTERNAL == 1 |
Carl-Daniel Hailfinger | 8841d3e | 2010-05-15 15:04:37 +0000 | [diff] [blame] | 64 | /* FIXME: --mainboard should be a programmer parameter */ |
| 65 | " -m | --mainboard <[vendor:]part> override mainboard " |
| 66 | "detection\n" |
| 67 | #endif |
| 68 | " -f | --force force specific operations " |
| 69 | "(see man page)\n" |
| 70 | " -n | --noverify don't auto-verify\n" |
| 71 | " -l | --layout <file> read ROM layout from " |
| 72 | "<file>\n" |
| 73 | " -i | --image <name> only flash image <name> " |
| 74 | "from flash layout\n" |
| 75 | " -L | --list-supported print supported devices\n" |
Carl-Daniel Hailfinger | 7112772 | 2010-05-31 15:27:27 +0000 | [diff] [blame] | 76 | #if CONFIG_PRINT_WIKI == 1 |
Carl-Daniel Hailfinger | 8841d3e | 2010-05-15 15:04:37 +0000 | [diff] [blame] | 77 | " -z | --list-supported-wiki print supported devices " |
| 78 | "in wiki syntax\n" |
| 79 | #endif |
| 80 | " -p | --programmer <name>[:<param>] specify the programmer " |
Carl-Daniel Hailfinger | a73fb49 | 2010-10-06 23:48:34 +0000 | [diff] [blame] | 81 | "device\n"); |
Carl-Daniel Hailfinger | a84835a | 2010-01-07 03:24:05 +0000 | [diff] [blame] | 82 | |
Carl-Daniel Hailfinger | a73fb49 | 2010-10-06 23:48:34 +0000 | [diff] [blame] | 83 | list_programmers_linebreak(37, 80, 1); |
Carl-Daniel Hailfinger | 8841d3e | 2010-05-15 15:04:37 +0000 | [diff] [blame] | 84 | printf("\nYou can specify one of -h, -R, -L, " |
Carl-Daniel Hailfinger | 7112772 | 2010-05-31 15:27:27 +0000 | [diff] [blame] | 85 | #if CONFIG_PRINT_WIKI == 1 |
Carl-Daniel Hailfinger | 8841d3e | 2010-05-15 15:04:37 +0000 | [diff] [blame] | 86 | "-z, " |
| 87 | #endif |
| 88 | "-E, -r, -w, -v or no operation.\n" |
| 89 | "If no operation is specified, flashrom will only probe for " |
| 90 | "flash chips.\n\n"); |
| 91 | } |
| 92 | |
Carl-Daniel Hailfinger | ad3cc55 | 2010-07-03 11:02:10 +0000 | [diff] [blame] | 93 | static void cli_classic_abort_usage(void) |
Carl-Daniel Hailfinger | 8841d3e | 2010-05-15 15:04:37 +0000 | [diff] [blame] | 94 | { |
Uwe Hermann | 2db77a0 | 2010-06-04 17:07:39 +0000 | [diff] [blame] | 95 | printf("Please run \"flashrom --help\" for usage info.\n"); |
Carl-Daniel Hailfinger | a84835a | 2010-01-07 03:24:05 +0000 | [diff] [blame] | 96 | exit(1); |
| 97 | } |
| 98 | |
Uwe Hermann | 394ee78 | 2011-08-20 14:14:22 +0000 | [diff] [blame] | 99 | int main(int argc, char *argv[]) |
Carl-Daniel Hailfinger | a84835a | 2010-01-07 03:24:05 +0000 | [diff] [blame] | 100 | { |
| 101 | unsigned long size; |
| 102 | /* Probe for up to three flash chips. */ |
Carl-Daniel Hailfinger | 4c82318 | 2011-05-04 00:39:50 +0000 | [diff] [blame] | 103 | const struct flashchip *flash; |
| 104 | struct flashchip flashes[3]; |
| 105 | struct flashchip *fill_flash; |
Carl-Daniel Hailfinger | a84835a | 2010-01-07 03:24:05 +0000 | [diff] [blame] | 106 | const char *name; |
Carl-Daniel Hailfinger | 082c8b5 | 2011-08-15 19:54:20 +0000 | [diff] [blame] | 107 | int namelen, opt, i; |
| 108 | int startchip = 0, chipcount = 0, option_index = 0, force = 0; |
Carl-Daniel Hailfinger | 7112772 | 2010-05-31 15:27:27 +0000 | [diff] [blame] | 109 | #if CONFIG_PRINT_WIKI == 1 |
Carl-Daniel Hailfinger | a84835a | 2010-01-07 03:24:05 +0000 | [diff] [blame] | 110 | int list_supported_wiki = 0; |
| 111 | #endif |
Carl-Daniel Hailfinger | 082c8b5 | 2011-08-15 19:54:20 +0000 | [diff] [blame] | 112 | int read_it = 0, write_it = 0, erase_it = 0, verify_it = 0; |
| 113 | int dont_verify_it = 0, list_supported = 0, operation_specified = 0; |
| 114 | int ret = 0; |
Carl-Daniel Hailfinger | a84835a | 2010-01-07 03:24:05 +0000 | [diff] [blame] | 115 | |
Mathias Krause | a60faab | 2011-01-17 07:50:42 +0000 | [diff] [blame] | 116 | static const char optstring[] = "r:Rw:v:nVEfc:m:l:i:p:Lzh"; |
| 117 | static const struct option long_options[] = { |
Uwe Hermann | 91f4afa | 2011-07-28 08:13:25 +0000 | [diff] [blame] | 118 | {"read", 1, NULL, 'r'}, |
| 119 | {"write", 1, NULL, 'w'}, |
| 120 | {"erase", 0, NULL, 'E'}, |
| 121 | {"verify", 1, NULL, 'v'}, |
| 122 | {"noverify", 0, NULL, 'n'}, |
| 123 | {"chip", 1, NULL, 'c'}, |
| 124 | {"mainboard", 1, NULL, 'm'}, |
| 125 | {"verbose", 0, NULL, 'V'}, |
| 126 | {"force", 0, NULL, 'f'}, |
| 127 | {"layout", 1, NULL, 'l'}, |
| 128 | {"image", 1, NULL, 'i'}, |
| 129 | {"list-supported", 0, NULL, 'L'}, |
| 130 | {"list-supported-wiki", 0, NULL, 'z'}, |
| 131 | {"programmer", 1, NULL, 'p'}, |
| 132 | {"help", 0, NULL, 'h'}, |
| 133 | {"version", 0, NULL, 'R'}, |
| 134 | {NULL, 0, NULL, 0}, |
Carl-Daniel Hailfinger | a84835a | 2010-01-07 03:24:05 +0000 | [diff] [blame] | 135 | }; |
| 136 | |
| 137 | char *filename = NULL; |
Carl-Daniel Hailfinger | a84835a | 2010-01-07 03:24:05 +0000 | [diff] [blame] | 138 | char *tempstr = NULL; |
Carl-Daniel Hailfinger | ad3cc55 | 2010-07-03 11:02:10 +0000 | [diff] [blame] | 139 | char *pparam = NULL; |
Carl-Daniel Hailfinger | a84835a | 2010-01-07 03:24:05 +0000 | [diff] [blame] | 140 | |
| 141 | print_version(); |
Carl-Daniel Hailfinger | 8841d3e | 2010-05-15 15:04:37 +0000 | [diff] [blame] | 142 | print_banner(); |
Carl-Daniel Hailfinger | a84835a | 2010-01-07 03:24:05 +0000 | [diff] [blame] | 143 | |
| 144 | if (selfcheck()) |
| 145 | exit(1); |
| 146 | |
| 147 | setbuf(stdout, NULL); |
Carl-Daniel Hailfinger | 8841d3e | 2010-05-15 15:04:37 +0000 | [diff] [blame] | 148 | /* FIXME: Delay all operation_specified checks until after command |
| 149 | * line parsing to allow --help overriding everything else. |
| 150 | */ |
Carl-Daniel Hailfinger | a84835a | 2010-01-07 03:24:05 +0000 | [diff] [blame] | 151 | while ((opt = getopt_long(argc, argv, optstring, |
| 152 | long_options, &option_index)) != EOF) { |
| 153 | switch (opt) { |
| 154 | case 'r': |
| 155 | if (++operation_specified > 1) { |
| 156 | fprintf(stderr, "More than one operation " |
| 157 | "specified. Aborting.\n"); |
Uwe Hermann | 2db77a0 | 2010-06-04 17:07:39 +0000 | [diff] [blame] | 158 | cli_classic_abort_usage(); |
Carl-Daniel Hailfinger | a84835a | 2010-01-07 03:24:05 +0000 | [diff] [blame] | 159 | } |
Carl-Daniel Hailfinger | 8841d3e | 2010-05-15 15:04:37 +0000 | [diff] [blame] | 160 | filename = strdup(optarg); |
Carl-Daniel Hailfinger | a84835a | 2010-01-07 03:24:05 +0000 | [diff] [blame] | 161 | read_it = 1; |
| 162 | break; |
| 163 | case 'w': |
| 164 | if (++operation_specified > 1) { |
| 165 | fprintf(stderr, "More than one operation " |
| 166 | "specified. Aborting.\n"); |
Uwe Hermann | 2db77a0 | 2010-06-04 17:07:39 +0000 | [diff] [blame] | 167 | cli_classic_abort_usage(); |
Carl-Daniel Hailfinger | a84835a | 2010-01-07 03:24:05 +0000 | [diff] [blame] | 168 | } |
Carl-Daniel Hailfinger | 8841d3e | 2010-05-15 15:04:37 +0000 | [diff] [blame] | 169 | filename = strdup(optarg); |
Carl-Daniel Hailfinger | a84835a | 2010-01-07 03:24:05 +0000 | [diff] [blame] | 170 | write_it = 1; |
| 171 | break; |
| 172 | case 'v': |
| 173 | //FIXME: gracefully handle superfluous -v |
| 174 | if (++operation_specified > 1) { |
| 175 | fprintf(stderr, "More than one operation " |
| 176 | "specified. Aborting.\n"); |
Uwe Hermann | 2db77a0 | 2010-06-04 17:07:39 +0000 | [diff] [blame] | 177 | cli_classic_abort_usage(); |
Carl-Daniel Hailfinger | a84835a | 2010-01-07 03:24:05 +0000 | [diff] [blame] | 178 | } |
| 179 | if (dont_verify_it) { |
| 180 | fprintf(stderr, "--verify and --noverify are" |
| 181 | "mutually exclusive. Aborting.\n"); |
Uwe Hermann | 2db77a0 | 2010-06-04 17:07:39 +0000 | [diff] [blame] | 182 | cli_classic_abort_usage(); |
Carl-Daniel Hailfinger | a84835a | 2010-01-07 03:24:05 +0000 | [diff] [blame] | 183 | } |
Carl-Daniel Hailfinger | 8841d3e | 2010-05-15 15:04:37 +0000 | [diff] [blame] | 184 | filename = strdup(optarg); |
Carl-Daniel Hailfinger | a84835a | 2010-01-07 03:24:05 +0000 | [diff] [blame] | 185 | verify_it = 1; |
| 186 | break; |
| 187 | case 'n': |
| 188 | if (verify_it) { |
| 189 | fprintf(stderr, "--verify and --noverify are" |
| 190 | "mutually exclusive. Aborting.\n"); |
Uwe Hermann | 2db77a0 | 2010-06-04 17:07:39 +0000 | [diff] [blame] | 191 | cli_classic_abort_usage(); |
Carl-Daniel Hailfinger | a84835a | 2010-01-07 03:24:05 +0000 | [diff] [blame] | 192 | } |
| 193 | dont_verify_it = 1; |
| 194 | break; |
| 195 | case 'c': |
| 196 | chip_to_probe = strdup(optarg); |
| 197 | break; |
| 198 | case 'V': |
Sean Nelson | 51e97d7 | 2010-01-07 20:09:33 +0000 | [diff] [blame] | 199 | verbose++; |
Carl-Daniel Hailfinger | a84835a | 2010-01-07 03:24:05 +0000 | [diff] [blame] | 200 | break; |
| 201 | case 'E': |
| 202 | if (++operation_specified > 1) { |
| 203 | fprintf(stderr, "More than one operation " |
| 204 | "specified. Aborting.\n"); |
Uwe Hermann | 2db77a0 | 2010-06-04 17:07:39 +0000 | [diff] [blame] | 205 | cli_classic_abort_usage(); |
Carl-Daniel Hailfinger | a84835a | 2010-01-07 03:24:05 +0000 | [diff] [blame] | 206 | } |
| 207 | erase_it = 1; |
| 208 | break; |
Carl-Daniel Hailfinger | a84835a | 2010-01-07 03:24:05 +0000 | [diff] [blame] | 209 | case 'm': |
Carl-Daniel Hailfinger | 7112772 | 2010-05-31 15:27:27 +0000 | [diff] [blame] | 210 | #if CONFIG_INTERNAL == 1 |
Carl-Daniel Hailfinger | a84835a | 2010-01-07 03:24:05 +0000 | [diff] [blame] | 211 | tempstr = strdup(optarg); |
| 212 | lb_vendor_dev_from_string(tempstr); |
Carl-Daniel Hailfinger | 8841d3e | 2010-05-15 15:04:37 +0000 | [diff] [blame] | 213 | #else |
| 214 | fprintf(stderr, "Error: Internal programmer support " |
| 215 | "was not compiled in and --mainboard only\n" |
| 216 | "applies to the internal programmer. Aborting.\n"); |
Uwe Hermann | 2db77a0 | 2010-06-04 17:07:39 +0000 | [diff] [blame] | 217 | cli_classic_abort_usage(); |
Carl-Daniel Hailfinger | a84835a | 2010-01-07 03:24:05 +0000 | [diff] [blame] | 218 | #endif |
Carl-Daniel Hailfinger | 8841d3e | 2010-05-15 15:04:37 +0000 | [diff] [blame] | 219 | break; |
Carl-Daniel Hailfinger | a84835a | 2010-01-07 03:24:05 +0000 | [diff] [blame] | 220 | case 'f': |
| 221 | force = 1; |
| 222 | break; |
| 223 | case 'l': |
| 224 | tempstr = strdup(optarg); |
| 225 | if (read_romlayout(tempstr)) |
Uwe Hermann | 2db77a0 | 2010-06-04 17:07:39 +0000 | [diff] [blame] | 226 | cli_classic_abort_usage(); |
Carl-Daniel Hailfinger | a84835a | 2010-01-07 03:24:05 +0000 | [diff] [blame] | 227 | break; |
| 228 | case 'i': |
Carl-Daniel Hailfinger | d566014 | 2011-07-15 23:47:45 +0000 | [diff] [blame] | 229 | /* FIXME: -l has to be specified before -i. */ |
Carl-Daniel Hailfinger | a84835a | 2010-01-07 03:24:05 +0000 | [diff] [blame] | 230 | tempstr = strdup(optarg); |
Stefan Tauner | 1a30d50 | 2011-07-19 07:58:06 +0000 | [diff] [blame] | 231 | if (find_romentry(tempstr) < 0) { |
Carl-Daniel Hailfinger | d566014 | 2011-07-15 23:47:45 +0000 | [diff] [blame] | 232 | fprintf(stderr, "Error: image %s not found in " |
| 233 | "layout file or -i specified before " |
| 234 | "-l\n", tempstr); |
| 235 | cli_classic_abort_usage(); |
| 236 | } |
Carl-Daniel Hailfinger | a84835a | 2010-01-07 03:24:05 +0000 | [diff] [blame] | 237 | break; |
| 238 | case 'L': |
Carl-Daniel Hailfinger | 8841d3e | 2010-05-15 15:04:37 +0000 | [diff] [blame] | 239 | if (++operation_specified > 1) { |
| 240 | fprintf(stderr, "More than one operation " |
| 241 | "specified. Aborting.\n"); |
Uwe Hermann | 2db77a0 | 2010-06-04 17:07:39 +0000 | [diff] [blame] | 242 | cli_classic_abort_usage(); |
Carl-Daniel Hailfinger | 8841d3e | 2010-05-15 15:04:37 +0000 | [diff] [blame] | 243 | } |
Carl-Daniel Hailfinger | a84835a | 2010-01-07 03:24:05 +0000 | [diff] [blame] | 244 | list_supported = 1; |
| 245 | break; |
Carl-Daniel Hailfinger | a84835a | 2010-01-07 03:24:05 +0000 | [diff] [blame] | 246 | case 'z': |
Carl-Daniel Hailfinger | 7112772 | 2010-05-31 15:27:27 +0000 | [diff] [blame] | 247 | #if CONFIG_PRINT_WIKI == 1 |
Carl-Daniel Hailfinger | 8841d3e | 2010-05-15 15:04:37 +0000 | [diff] [blame] | 248 | if (++operation_specified > 1) { |
| 249 | fprintf(stderr, "More than one operation " |
| 250 | "specified. Aborting.\n"); |
Uwe Hermann | 2db77a0 | 2010-06-04 17:07:39 +0000 | [diff] [blame] | 251 | cli_classic_abort_usage(); |
Carl-Daniel Hailfinger | 8841d3e | 2010-05-15 15:04:37 +0000 | [diff] [blame] | 252 | } |
Carl-Daniel Hailfinger | a84835a | 2010-01-07 03:24:05 +0000 | [diff] [blame] | 253 | list_supported_wiki = 1; |
Carl-Daniel Hailfinger | 8841d3e | 2010-05-15 15:04:37 +0000 | [diff] [blame] | 254 | #else |
| 255 | fprintf(stderr, "Error: Wiki output was not compiled " |
| 256 | "in. Aborting.\n"); |
Uwe Hermann | 2db77a0 | 2010-06-04 17:07:39 +0000 | [diff] [blame] | 257 | cli_classic_abort_usage(); |
Carl-Daniel Hailfinger | a84835a | 2010-01-07 03:24:05 +0000 | [diff] [blame] | 258 | #endif |
Carl-Daniel Hailfinger | 8841d3e | 2010-05-15 15:04:37 +0000 | [diff] [blame] | 259 | break; |
Carl-Daniel Hailfinger | a84835a | 2010-01-07 03:24:05 +0000 | [diff] [blame] | 260 | case 'p': |
| 261 | for (programmer = 0; programmer < PROGRAMMER_INVALID; programmer++) { |
| 262 | name = programmer_table[programmer].name; |
| 263 | namelen = strlen(name); |
| 264 | if (strncmp(optarg, name, namelen) == 0) { |
| 265 | switch (optarg[namelen]) { |
| 266 | case ':': |
Carl-Daniel Hailfinger | ad3cc55 | 2010-07-03 11:02:10 +0000 | [diff] [blame] | 267 | pparam = strdup(optarg + namelen + 1); |
| 268 | if (!strlen(pparam)) { |
| 269 | free(pparam); |
| 270 | pparam = NULL; |
Carl-Daniel Hailfinger | 2702376 | 2010-04-28 15:22:14 +0000 | [diff] [blame] | 271 | } |
Carl-Daniel Hailfinger | a84835a | 2010-01-07 03:24:05 +0000 | [diff] [blame] | 272 | break; |
| 273 | case '\0': |
| 274 | break; |
| 275 | default: |
| 276 | /* The continue refers to the |
| 277 | * for loop. It is here to be |
| 278 | * able to differentiate between |
| 279 | * foo and foobar. |
| 280 | */ |
| 281 | continue; |
| 282 | } |
| 283 | break; |
| 284 | } |
| 285 | } |
| 286 | if (programmer == PROGRAMMER_INVALID) { |
Carl-Daniel Hailfinger | 8841d3e | 2010-05-15 15:04:37 +0000 | [diff] [blame] | 287 | fprintf(stderr, "Error: Unknown programmer " |
| 288 | "%s.\n", optarg); |
Uwe Hermann | 2db77a0 | 2010-06-04 17:07:39 +0000 | [diff] [blame] | 289 | cli_classic_abort_usage(); |
Carl-Daniel Hailfinger | a84835a | 2010-01-07 03:24:05 +0000 | [diff] [blame] | 290 | } |
| 291 | break; |
| 292 | case 'R': |
| 293 | /* print_version() is always called during startup. */ |
Carl-Daniel Hailfinger | 8841d3e | 2010-05-15 15:04:37 +0000 | [diff] [blame] | 294 | if (++operation_specified > 1) { |
| 295 | fprintf(stderr, "More than one operation " |
| 296 | "specified. Aborting.\n"); |
Uwe Hermann | 2db77a0 | 2010-06-04 17:07:39 +0000 | [diff] [blame] | 297 | cli_classic_abort_usage(); |
Carl-Daniel Hailfinger | 8841d3e | 2010-05-15 15:04:37 +0000 | [diff] [blame] | 298 | } |
Carl-Daniel Hailfinger | a84835a | 2010-01-07 03:24:05 +0000 | [diff] [blame] | 299 | exit(0); |
| 300 | break; |
| 301 | case 'h': |
Carl-Daniel Hailfinger | 8841d3e | 2010-05-15 15:04:37 +0000 | [diff] [blame] | 302 | if (++operation_specified > 1) { |
| 303 | fprintf(stderr, "More than one operation " |
| 304 | "specified. Aborting.\n"); |
Uwe Hermann | 2db77a0 | 2010-06-04 17:07:39 +0000 | [diff] [blame] | 305 | cli_classic_abort_usage(); |
Carl-Daniel Hailfinger | 8841d3e | 2010-05-15 15:04:37 +0000 | [diff] [blame] | 306 | } |
Carl-Daniel Hailfinger | a84835a | 2010-01-07 03:24:05 +0000 | [diff] [blame] | 307 | cli_classic_usage(argv[0]); |
Carl-Daniel Hailfinger | 8841d3e | 2010-05-15 15:04:37 +0000 | [diff] [blame] | 308 | exit(0); |
| 309 | break; |
| 310 | default: |
Uwe Hermann | 2db77a0 | 2010-06-04 17:07:39 +0000 | [diff] [blame] | 311 | cli_classic_abort_usage(); |
Carl-Daniel Hailfinger | a84835a | 2010-01-07 03:24:05 +0000 | [diff] [blame] | 312 | break; |
| 313 | } |
| 314 | } |
| 315 | |
Carl-Daniel Hailfinger | d566014 | 2011-07-15 23:47:45 +0000 | [diff] [blame] | 316 | if (optind < argc) { |
| 317 | fprintf(stderr, "Error: Extra parameter found.\n"); |
| 318 | cli_classic_abort_usage(); |
| 319 | } |
| 320 | |
Carl-Daniel Hailfinger | 8841d3e | 2010-05-15 15:04:37 +0000 | [diff] [blame] | 321 | /* FIXME: Print the actions flashrom will take. */ |
| 322 | |
Carl-Daniel Hailfinger | a84835a | 2010-01-07 03:24:05 +0000 | [diff] [blame] | 323 | if (list_supported) { |
| 324 | print_supported(); |
| 325 | exit(0); |
| 326 | } |
| 327 | |
Carl-Daniel Hailfinger | 7112772 | 2010-05-31 15:27:27 +0000 | [diff] [blame] | 328 | #if CONFIG_PRINT_WIKI == 1 |
Carl-Daniel Hailfinger | a84835a | 2010-01-07 03:24:05 +0000 | [diff] [blame] | 329 | if (list_supported_wiki) { |
| 330 | print_supported_wiki(); |
| 331 | exit(0); |
| 332 | } |
| 333 | #endif |
| 334 | |
Carl-Daniel Hailfinger | 7112772 | 2010-05-31 15:27:27 +0000 | [diff] [blame] | 335 | #if CONFIG_INTERNAL == 1 |
Carl-Daniel Hailfinger | 8841d3e | 2010-05-15 15:04:37 +0000 | [diff] [blame] | 336 | if ((programmer != PROGRAMMER_INTERNAL) && (lb_part || lb_vendor)) { |
| 337 | fprintf(stderr, "Error: --mainboard requires the internal " |
| 338 | "programmer. Aborting.\n"); |
Uwe Hermann | 2db77a0 | 2010-06-04 17:07:39 +0000 | [diff] [blame] | 339 | cli_classic_abort_usage(); |
Carl-Daniel Hailfinger | a84835a | 2010-01-07 03:24:05 +0000 | [diff] [blame] | 340 | } |
Carl-Daniel Hailfinger | 8841d3e | 2010-05-15 15:04:37 +0000 | [diff] [blame] | 341 | #endif |
Carl-Daniel Hailfinger | a84835a | 2010-01-07 03:24:05 +0000 | [diff] [blame] | 342 | |
Carl-Daniel Hailfinger | 2702376 | 2010-04-28 15:22:14 +0000 | [diff] [blame] | 343 | if (chip_to_probe) { |
| 344 | for (flash = flashchips; flash && flash->name; flash++) |
| 345 | if (!strcmp(flash->name, chip_to_probe)) |
| 346 | break; |
| 347 | if (!flash || !flash->name) { |
| 348 | fprintf(stderr, "Error: Unknown chip '%s' specified.\n", |
| 349 | chip_to_probe); |
| 350 | printf("Run flashrom -L to view the hardware supported " |
Uwe Hermann | 91f4afa | 2011-07-28 08:13:25 +0000 | [diff] [blame] | 351 | "in this flashrom version.\n"); |
Carl-Daniel Hailfinger | 2702376 | 2010-04-28 15:22:14 +0000 | [diff] [blame] | 352 | exit(1); |
| 353 | } |
| 354 | /* Clean up after the check. */ |
| 355 | flash = NULL; |
| 356 | } |
Carl-Daniel Hailfinger | 8841d3e | 2010-05-15 15:04:37 +0000 | [diff] [blame] | 357 | |
Carl-Daniel Hailfinger | 4988420 | 2010-05-22 07:10:46 +0000 | [diff] [blame] | 358 | /* FIXME: Delay calibration should happen in programmer code. */ |
| 359 | myusec_calibrate_delay(); |
| 360 | |
Carl-Daniel Hailfinger | ad3cc55 | 2010-07-03 11:02:10 +0000 | [diff] [blame] | 361 | if (programmer_init(pparam)) { |
Carl-Daniel Hailfinger | a84835a | 2010-01-07 03:24:05 +0000 | [diff] [blame] | 362 | fprintf(stderr, "Error: Programmer initialization failed.\n"); |
Carl-Daniel Hailfinger | d566014 | 2011-07-15 23:47:45 +0000 | [diff] [blame] | 363 | ret = 1; |
| 364 | goto out_shutdown; |
Carl-Daniel Hailfinger | a84835a | 2010-01-07 03:24:05 +0000 | [diff] [blame] | 365 | } |
| 366 | |
Carl-Daniel Hailfinger | a84835a | 2010-01-07 03:24:05 +0000 | [diff] [blame] | 367 | for (i = 0; i < ARRAY_SIZE(flashes); i++) { |
Carl-Daniel Hailfinger | 4c82318 | 2011-05-04 00:39:50 +0000 | [diff] [blame] | 368 | startchip = probe_flash(startchip, &flashes[i], 0); |
| 369 | if (startchip == -1) |
| 370 | break; |
| 371 | chipcount++; |
Carl-Daniel Hailfinger | 064bbc9 | 2011-05-07 19:19:36 +0000 | [diff] [blame] | 372 | startchip++; |
Carl-Daniel Hailfinger | a84835a | 2010-01-07 03:24:05 +0000 | [diff] [blame] | 373 | } |
| 374 | |
Carl-Daniel Hailfinger | 4c82318 | 2011-05-04 00:39:50 +0000 | [diff] [blame] | 375 | if (chipcount > 1) { |
Stefan Tauner | 716e098 | 2011-07-25 20:38:52 +0000 | [diff] [blame] | 376 | printf("Multiple flash chips were detected: \"%s\"", |
| 377 | flashes[0].name); |
| 378 | for (i = 1; i < chipcount; i++) |
| 379 | printf(", \"%s\"", flashes[i].name); |
Uwe Hermann | 91f4afa | 2011-07-28 08:13:25 +0000 | [diff] [blame] | 380 | printf("\nPlease specify which chip to use with the " |
| 381 | "-c <chipname> option.\n"); |
Carl-Daniel Hailfinger | d566014 | 2011-07-15 23:47:45 +0000 | [diff] [blame] | 382 | ret = 1; |
| 383 | goto out_shutdown; |
Carl-Daniel Hailfinger | 4c82318 | 2011-05-04 00:39:50 +0000 | [diff] [blame] | 384 | } else if (!chipcount) { |
Carl-Daniel Hailfinger | a84835a | 2010-01-07 03:24:05 +0000 | [diff] [blame] | 385 | printf("No EEPROM/flash device found.\n"); |
| 386 | if (!force || !chip_to_probe) { |
Uwe Hermann | 91f4afa | 2011-07-28 08:13:25 +0000 | [diff] [blame] | 387 | printf("Note: flashrom can never write if the flash " |
| 388 | "chip isn't found automatically.\n"); |
Carl-Daniel Hailfinger | a84835a | 2010-01-07 03:24:05 +0000 | [diff] [blame] | 389 | } |
| 390 | if (force && read_it && chip_to_probe) { |
Uwe Hermann | 91f4afa | 2011-07-28 08:13:25 +0000 | [diff] [blame] | 391 | printf("Force read (-f -r -c) requested, pretending " |
| 392 | "the chip is there:\n"); |
Carl-Daniel Hailfinger | 4c82318 | 2011-05-04 00:39:50 +0000 | [diff] [blame] | 393 | startchip = probe_flash(0, &flashes[0], 1); |
| 394 | if (startchip == -1) { |
Uwe Hermann | 91f4afa | 2011-07-28 08:13:25 +0000 | [diff] [blame] | 395 | printf("Probing for flash chip '%s' failed.\n", |
| 396 | chip_to_probe); |
Carl-Daniel Hailfinger | d566014 | 2011-07-15 23:47:45 +0000 | [diff] [blame] | 397 | ret = 1; |
| 398 | goto out_shutdown; |
Carl-Daniel Hailfinger | a84835a | 2010-01-07 03:24:05 +0000 | [diff] [blame] | 399 | } |
Uwe Hermann | 91f4afa | 2011-07-28 08:13:25 +0000 | [diff] [blame] | 400 | printf("Please note that forced reads most likely " |
| 401 | "contain garbage.\n"); |
Carl-Daniel Hailfinger | 4c82318 | 2011-05-04 00:39:50 +0000 | [diff] [blame] | 402 | return read_flash_to_file(&flashes[0], filename); |
Carl-Daniel Hailfinger | a84835a | 2010-01-07 03:24:05 +0000 | [diff] [blame] | 403 | } |
Carl-Daniel Hailfinger | d566014 | 2011-07-15 23:47:45 +0000 | [diff] [blame] | 404 | ret = 1; |
| 405 | goto out_shutdown; |
Carl-Daniel Hailfinger | a84835a | 2010-01-07 03:24:05 +0000 | [diff] [blame] | 406 | } |
| 407 | |
Carl-Daniel Hailfinger | 4c82318 | 2011-05-04 00:39:50 +0000 | [diff] [blame] | 408 | fill_flash = &flashes[0]; |
Carl-Daniel Hailfinger | a84835a | 2010-01-07 03:24:05 +0000 | [diff] [blame] | 409 | |
Carl-Daniel Hailfinger | 4c82318 | 2011-05-04 00:39:50 +0000 | [diff] [blame] | 410 | check_chip_supported(fill_flash); |
Carl-Daniel Hailfinger | a84835a | 2010-01-07 03:24:05 +0000 | [diff] [blame] | 411 | |
Carl-Daniel Hailfinger | 4c82318 | 2011-05-04 00:39:50 +0000 | [diff] [blame] | 412 | size = fill_flash->total_size * 1024; |
| 413 | if (check_max_decode((buses_supported & fill_flash->bustype), size) && |
Carl-Daniel Hailfinger | a84835a | 2010-01-07 03:24:05 +0000 | [diff] [blame] | 414 | (!force)) { |
| 415 | fprintf(stderr, "Chip is too big for this programmer " |
| 416 | "(-V gives details). Use --force to override.\n"); |
Carl-Daniel Hailfinger | d566014 | 2011-07-15 23:47:45 +0000 | [diff] [blame] | 417 | ret = 1; |
| 418 | goto out_shutdown; |
Carl-Daniel Hailfinger | a84835a | 2010-01-07 03:24:05 +0000 | [diff] [blame] | 419 | } |
| 420 | |
| 421 | if (!(read_it | write_it | verify_it | erase_it)) { |
| 422 | printf("No operations were specified.\n"); |
Carl-Daniel Hailfinger | d566014 | 2011-07-15 23:47:45 +0000 | [diff] [blame] | 423 | goto out_shutdown; |
Carl-Daniel Hailfinger | a84835a | 2010-01-07 03:24:05 +0000 | [diff] [blame] | 424 | } |
| 425 | |
| 426 | if (!filename && !erase_it) { |
| 427 | printf("Error: No filename specified.\n"); |
Carl-Daniel Hailfinger | d566014 | 2011-07-15 23:47:45 +0000 | [diff] [blame] | 428 | ret = 1; |
| 429 | goto out_shutdown; |
Carl-Daniel Hailfinger | a84835a | 2010-01-07 03:24:05 +0000 | [diff] [blame] | 430 | } |
| 431 | |
| 432 | /* Always verify write operations unless -n is used. */ |
| 433 | if (write_it && !dont_verify_it) |
| 434 | verify_it = 1; |
| 435 | |
Carl-Daniel Hailfinger | 9ad4255 | 2010-09-15 10:20:16 +0000 | [diff] [blame] | 436 | /* FIXME: We should issue an unconditional chip reset here. This can be |
| 437 | * done once we have a .reset function in struct flashchip. |
| 438 | * Give the chip time to settle. |
| 439 | */ |
| 440 | programmer_delay(100000); |
Carl-Daniel Hailfinger | 4c82318 | 2011-05-04 00:39:50 +0000 | [diff] [blame] | 441 | return doit(fill_flash, force, filename, read_it, write_it, erase_it, verify_it); |
Carl-Daniel Hailfinger | d566014 | 2011-07-15 23:47:45 +0000 | [diff] [blame] | 442 | |
| 443 | out_shutdown: |
| 444 | programmer_shutdown(); |
| 445 | return ret; |
Carl-Daniel Hailfinger | a84835a | 2010-01-07 03:24:05 +0000 | [diff] [blame] | 446 | } |