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 | |
| 99 | int cli_classic(int argc, char *argv[]) |
| 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; |
| 106 | int startchip = 0; |
| 107 | int chipcount = 0; |
Carl-Daniel Hailfinger | a84835a | 2010-01-07 03:24:05 +0000 | [diff] [blame] | 108 | const char *name; |
| 109 | int namelen; |
| 110 | int opt; |
| 111 | int option_index = 0; |
| 112 | int force = 0; |
| 113 | int read_it = 0, write_it = 0, erase_it = 0, verify_it = 0; |
| 114 | int dont_verify_it = 0, list_supported = 0; |
Carl-Daniel Hailfinger | 7112772 | 2010-05-31 15:27:27 +0000 | [diff] [blame] | 115 | #if CONFIG_PRINT_WIKI == 1 |
Carl-Daniel Hailfinger | a84835a | 2010-01-07 03:24:05 +0000 | [diff] [blame] | 116 | int list_supported_wiki = 0; |
| 117 | #endif |
| 118 | int operation_specified = 0; |
| 119 | int i; |
| 120 | |
Mathias Krause | a60faab | 2011-01-17 07:50:42 +0000 | [diff] [blame] | 121 | static const char optstring[] = "r:Rw:v:nVEfc:m:l:i:p:Lzh"; |
| 122 | static const struct option long_options[] = { |
Peter Huewe | 73f8ec8 | 2011-01-24 19:15:51 +0000 | [diff] [blame] | 123 | {"read", 1, NULL, 'r'}, |
| 124 | {"write", 1, NULL, 'w'}, |
| 125 | {"erase", 0, NULL, 'E'}, |
| 126 | {"verify", 1, NULL, 'v'}, |
| 127 | {"noverify", 0, NULL, 'n'}, |
| 128 | {"chip", 1, NULL, 'c'}, |
| 129 | {"mainboard", 1, NULL, 'm'}, |
| 130 | {"verbose", 0, NULL, 'V'}, |
| 131 | {"force", 0, NULL, 'f'}, |
| 132 | {"layout", 1, NULL, 'l'}, |
| 133 | {"image", 1, NULL, 'i'}, |
| 134 | {"list-supported", 0, NULL, 'L'}, |
| 135 | {"list-supported-wiki", 0, NULL, 'z'}, |
| 136 | {"programmer", 1, NULL, 'p'}, |
| 137 | {"help", 0, NULL, 'h'}, |
| 138 | {"version", 0, NULL, 'R'}, |
| 139 | {NULL, 0, NULL, 0} |
Carl-Daniel Hailfinger | a84835a | 2010-01-07 03:24:05 +0000 | [diff] [blame] | 140 | }; |
| 141 | |
| 142 | char *filename = NULL; |
| 143 | |
| 144 | char *tempstr = NULL; |
Carl-Daniel Hailfinger | ad3cc55 | 2010-07-03 11:02:10 +0000 | [diff] [blame] | 145 | char *pparam = NULL; |
Carl-Daniel Hailfinger | a84835a | 2010-01-07 03:24:05 +0000 | [diff] [blame] | 146 | |
| 147 | print_version(); |
Carl-Daniel Hailfinger | 8841d3e | 2010-05-15 15:04:37 +0000 | [diff] [blame] | 148 | print_banner(); |
Carl-Daniel Hailfinger | a84835a | 2010-01-07 03:24:05 +0000 | [diff] [blame] | 149 | |
| 150 | if (selfcheck()) |
| 151 | exit(1); |
| 152 | |
| 153 | setbuf(stdout, NULL); |
Carl-Daniel Hailfinger | 8841d3e | 2010-05-15 15:04:37 +0000 | [diff] [blame] | 154 | /* FIXME: Delay all operation_specified checks until after command |
| 155 | * line parsing to allow --help overriding everything else. |
| 156 | */ |
Carl-Daniel Hailfinger | a84835a | 2010-01-07 03:24:05 +0000 | [diff] [blame] | 157 | while ((opt = getopt_long(argc, argv, optstring, |
| 158 | long_options, &option_index)) != EOF) { |
| 159 | switch (opt) { |
| 160 | case 'r': |
| 161 | if (++operation_specified > 1) { |
| 162 | fprintf(stderr, "More than one operation " |
| 163 | "specified. Aborting.\n"); |
Uwe Hermann | 2db77a0 | 2010-06-04 17:07:39 +0000 | [diff] [blame] | 164 | cli_classic_abort_usage(); |
Carl-Daniel Hailfinger | a84835a | 2010-01-07 03:24:05 +0000 | [diff] [blame] | 165 | } |
Carl-Daniel Hailfinger | 8841d3e | 2010-05-15 15:04:37 +0000 | [diff] [blame] | 166 | filename = strdup(optarg); |
Carl-Daniel Hailfinger | a84835a | 2010-01-07 03:24:05 +0000 | [diff] [blame] | 167 | read_it = 1; |
| 168 | break; |
| 169 | case 'w': |
| 170 | if (++operation_specified > 1) { |
| 171 | fprintf(stderr, "More than one operation " |
| 172 | "specified. Aborting.\n"); |
Uwe Hermann | 2db77a0 | 2010-06-04 17:07:39 +0000 | [diff] [blame] | 173 | cli_classic_abort_usage(); |
Carl-Daniel Hailfinger | a84835a | 2010-01-07 03:24:05 +0000 | [diff] [blame] | 174 | } |
Carl-Daniel Hailfinger | 8841d3e | 2010-05-15 15:04:37 +0000 | [diff] [blame] | 175 | filename = strdup(optarg); |
Carl-Daniel Hailfinger | a84835a | 2010-01-07 03:24:05 +0000 | [diff] [blame] | 176 | write_it = 1; |
| 177 | break; |
| 178 | case 'v': |
| 179 | //FIXME: gracefully handle superfluous -v |
| 180 | if (++operation_specified > 1) { |
| 181 | fprintf(stderr, "More than one operation " |
| 182 | "specified. Aborting.\n"); |
Uwe Hermann | 2db77a0 | 2010-06-04 17:07:39 +0000 | [diff] [blame] | 183 | cli_classic_abort_usage(); |
Carl-Daniel Hailfinger | a84835a | 2010-01-07 03:24:05 +0000 | [diff] [blame] | 184 | } |
| 185 | if (dont_verify_it) { |
| 186 | fprintf(stderr, "--verify and --noverify are" |
| 187 | "mutually exclusive. Aborting.\n"); |
Uwe Hermann | 2db77a0 | 2010-06-04 17:07:39 +0000 | [diff] [blame] | 188 | cli_classic_abort_usage(); |
Carl-Daniel Hailfinger | a84835a | 2010-01-07 03:24:05 +0000 | [diff] [blame] | 189 | } |
Carl-Daniel Hailfinger | 8841d3e | 2010-05-15 15:04:37 +0000 | [diff] [blame] | 190 | filename = strdup(optarg); |
Carl-Daniel Hailfinger | a84835a | 2010-01-07 03:24:05 +0000 | [diff] [blame] | 191 | verify_it = 1; |
| 192 | break; |
| 193 | case 'n': |
| 194 | if (verify_it) { |
| 195 | fprintf(stderr, "--verify and --noverify are" |
| 196 | "mutually exclusive. Aborting.\n"); |
Uwe Hermann | 2db77a0 | 2010-06-04 17:07:39 +0000 | [diff] [blame] | 197 | cli_classic_abort_usage(); |
Carl-Daniel Hailfinger | a84835a | 2010-01-07 03:24:05 +0000 | [diff] [blame] | 198 | } |
| 199 | dont_verify_it = 1; |
| 200 | break; |
| 201 | case 'c': |
| 202 | chip_to_probe = strdup(optarg); |
| 203 | break; |
| 204 | case 'V': |
Sean Nelson | 51e97d7 | 2010-01-07 20:09:33 +0000 | [diff] [blame] | 205 | verbose++; |
Carl-Daniel Hailfinger | a84835a | 2010-01-07 03:24:05 +0000 | [diff] [blame] | 206 | break; |
| 207 | case 'E': |
| 208 | if (++operation_specified > 1) { |
| 209 | fprintf(stderr, "More than one operation " |
| 210 | "specified. 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 | } |
| 213 | erase_it = 1; |
| 214 | break; |
Carl-Daniel Hailfinger | a84835a | 2010-01-07 03:24:05 +0000 | [diff] [blame] | 215 | case 'm': |
Carl-Daniel Hailfinger | 7112772 | 2010-05-31 15:27:27 +0000 | [diff] [blame] | 216 | #if CONFIG_INTERNAL == 1 |
Carl-Daniel Hailfinger | a84835a | 2010-01-07 03:24:05 +0000 | [diff] [blame] | 217 | tempstr = strdup(optarg); |
| 218 | lb_vendor_dev_from_string(tempstr); |
Carl-Daniel Hailfinger | 8841d3e | 2010-05-15 15:04:37 +0000 | [diff] [blame] | 219 | #else |
| 220 | fprintf(stderr, "Error: Internal programmer support " |
| 221 | "was not compiled in and --mainboard only\n" |
| 222 | "applies to the internal programmer. Aborting.\n"); |
Uwe Hermann | 2db77a0 | 2010-06-04 17:07:39 +0000 | [diff] [blame] | 223 | cli_classic_abort_usage(); |
Carl-Daniel Hailfinger | a84835a | 2010-01-07 03:24:05 +0000 | [diff] [blame] | 224 | #endif |
Carl-Daniel Hailfinger | 8841d3e | 2010-05-15 15:04:37 +0000 | [diff] [blame] | 225 | break; |
Carl-Daniel Hailfinger | a84835a | 2010-01-07 03:24:05 +0000 | [diff] [blame] | 226 | case 'f': |
| 227 | force = 1; |
| 228 | break; |
| 229 | case 'l': |
| 230 | tempstr = strdup(optarg); |
| 231 | if (read_romlayout(tempstr)) |
Uwe Hermann | 2db77a0 | 2010-06-04 17:07:39 +0000 | [diff] [blame] | 232 | cli_classic_abort_usage(); |
Carl-Daniel Hailfinger | a84835a | 2010-01-07 03:24:05 +0000 | [diff] [blame] | 233 | break; |
| 234 | case 'i': |
| 235 | tempstr = strdup(optarg); |
| 236 | find_romentry(tempstr); |
| 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 | 8841d3e | 2010-05-15 15:04:37 +0000 | [diff] [blame] | 316 | /* FIXME: Print the actions flashrom will take. */ |
| 317 | |
Carl-Daniel Hailfinger | a84835a | 2010-01-07 03:24:05 +0000 | [diff] [blame] | 318 | if (list_supported) { |
| 319 | print_supported(); |
| 320 | exit(0); |
| 321 | } |
| 322 | |
Carl-Daniel Hailfinger | 7112772 | 2010-05-31 15:27:27 +0000 | [diff] [blame] | 323 | #if CONFIG_PRINT_WIKI == 1 |
Carl-Daniel Hailfinger | a84835a | 2010-01-07 03:24:05 +0000 | [diff] [blame] | 324 | if (list_supported_wiki) { |
| 325 | print_supported_wiki(); |
| 326 | exit(0); |
| 327 | } |
| 328 | #endif |
| 329 | |
Carl-Daniel Hailfinger | 8841d3e | 2010-05-15 15:04:37 +0000 | [diff] [blame] | 330 | if (optind < argc) { |
| 331 | fprintf(stderr, "Error: Extra parameter found.\n"); |
Uwe Hermann | 2db77a0 | 2010-06-04 17:07:39 +0000 | [diff] [blame] | 332 | cli_classic_abort_usage(); |
Carl-Daniel Hailfinger | a84835a | 2010-01-07 03:24:05 +0000 | [diff] [blame] | 333 | } |
| 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 " |
| 351 | "in this flashrom version.\n"); |
| 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"); |
David Hendricks | 8bb2021 | 2011-06-14 01:35:36 +0000 | [diff] [blame] | 363 | programmer_shutdown(); |
Carl-Daniel Hailfinger | a84835a | 2010-01-07 03:24:05 +0000 | [diff] [blame] | 364 | exit(1); |
| 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) { |
Carl-Daniel Hailfinger | a84835a | 2010-01-07 03:24:05 +0000 | [diff] [blame] | 376 | printf("Multiple flash chips were detected:"); |
Carl-Daniel Hailfinger | 4c82318 | 2011-05-04 00:39:50 +0000 | [diff] [blame] | 377 | for (i = 0; i < chipcount; i++) |
| 378 | printf(" %s", flashes[i].name); |
Carl-Daniel Hailfinger | a84835a | 2010-01-07 03:24:05 +0000 | [diff] [blame] | 379 | printf("\nPlease specify which chip to use with the -c <chipname> option.\n"); |
| 380 | programmer_shutdown(); |
| 381 | exit(1); |
Carl-Daniel Hailfinger | 4c82318 | 2011-05-04 00:39:50 +0000 | [diff] [blame] | 382 | } else if (!chipcount) { |
Carl-Daniel Hailfinger | a84835a | 2010-01-07 03:24:05 +0000 | [diff] [blame] | 383 | printf("No EEPROM/flash device found.\n"); |
| 384 | if (!force || !chip_to_probe) { |
Carl-Daniel Hailfinger | 2702376 | 2010-04-28 15:22:14 +0000 | [diff] [blame] | 385 | 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] | 386 | } |
| 387 | if (force && read_it && chip_to_probe) { |
Carl-Daniel Hailfinger | 2702376 | 2010-04-28 15:22:14 +0000 | [diff] [blame] | 388 | printf("Force read (-f -r -c) requested, pretending the chip is there:\n"); |
Carl-Daniel Hailfinger | 4c82318 | 2011-05-04 00:39:50 +0000 | [diff] [blame] | 389 | startchip = probe_flash(0, &flashes[0], 1); |
| 390 | if (startchip == -1) { |
Carl-Daniel Hailfinger | 2702376 | 2010-04-28 15:22:14 +0000 | [diff] [blame] | 391 | printf("Probing for flash chip '%s' failed.\n", chip_to_probe); |
| 392 | programmer_shutdown(); |
Carl-Daniel Hailfinger | a84835a | 2010-01-07 03:24:05 +0000 | [diff] [blame] | 393 | exit(1); |
| 394 | } |
| 395 | printf("Please note that forced reads most likely contain garbage.\n"); |
Carl-Daniel Hailfinger | 4c82318 | 2011-05-04 00:39:50 +0000 | [diff] [blame] | 396 | return read_flash_to_file(&flashes[0], filename); |
Carl-Daniel Hailfinger | a84835a | 2010-01-07 03:24:05 +0000 | [diff] [blame] | 397 | } |
| 398 | // FIXME: flash writes stay enabled! |
| 399 | programmer_shutdown(); |
| 400 | exit(1); |
| 401 | } |
| 402 | |
Carl-Daniel Hailfinger | 4c82318 | 2011-05-04 00:39:50 +0000 | [diff] [blame] | 403 | fill_flash = &flashes[0]; |
Carl-Daniel Hailfinger | a84835a | 2010-01-07 03:24:05 +0000 | [diff] [blame] | 404 | |
Carl-Daniel Hailfinger | 4c82318 | 2011-05-04 00:39:50 +0000 | [diff] [blame] | 405 | check_chip_supported(fill_flash); |
Carl-Daniel Hailfinger | a84835a | 2010-01-07 03:24:05 +0000 | [diff] [blame] | 406 | |
Carl-Daniel Hailfinger | 4c82318 | 2011-05-04 00:39:50 +0000 | [diff] [blame] | 407 | size = fill_flash->total_size * 1024; |
| 408 | if (check_max_decode((buses_supported & fill_flash->bustype), size) && |
Carl-Daniel Hailfinger | a84835a | 2010-01-07 03:24:05 +0000 | [diff] [blame] | 409 | (!force)) { |
| 410 | fprintf(stderr, "Chip is too big for this programmer " |
| 411 | "(-V gives details). Use --force to override.\n"); |
| 412 | programmer_shutdown(); |
| 413 | return 1; |
| 414 | } |
| 415 | |
| 416 | if (!(read_it | write_it | verify_it | erase_it)) { |
| 417 | printf("No operations were specified.\n"); |
| 418 | // FIXME: flash writes stay enabled! |
| 419 | programmer_shutdown(); |
Carl-Daniel Hailfinger | 8841d3e | 2010-05-15 15:04:37 +0000 | [diff] [blame] | 420 | exit(0); |
Carl-Daniel Hailfinger | a84835a | 2010-01-07 03:24:05 +0000 | [diff] [blame] | 421 | } |
| 422 | |
| 423 | if (!filename && !erase_it) { |
| 424 | printf("Error: No filename specified.\n"); |
| 425 | // FIXME: flash writes stay enabled! |
| 426 | programmer_shutdown(); |
| 427 | exit(1); |
| 428 | } |
| 429 | |
| 430 | /* Always verify write operations unless -n is used. */ |
| 431 | if (write_it && !dont_verify_it) |
| 432 | verify_it = 1; |
| 433 | |
Carl-Daniel Hailfinger | 9ad4255 | 2010-09-15 10:20:16 +0000 | [diff] [blame] | 434 | /* FIXME: We should issue an unconditional chip reset here. This can be |
| 435 | * done once we have a .reset function in struct flashchip. |
| 436 | * Give the chip time to settle. |
| 437 | */ |
| 438 | programmer_delay(100000); |
Carl-Daniel Hailfinger | 4c82318 | 2011-05-04 00:39:50 +0000 | [diff] [blame] | 439 | return doit(fill_flash, force, filename, read_it, write_it, erase_it, verify_it); |
Carl-Daniel Hailfinger | a84835a | 2010-01-07 03:24:05 +0000 | [diff] [blame] | 440 | } |