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