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; |
Carl-Daniel Hailfinger | d566014 | 2011-07-15 23:47:45 +0000 | [diff] [blame^] | 120 | int ret = 0; |
Carl-Daniel Hailfinger | a84835a | 2010-01-07 03:24:05 +0000 | [diff] [blame] | 121 | |
Mathias Krause | a60faab | 2011-01-17 07:50:42 +0000 | [diff] [blame] | 122 | static const char optstring[] = "r:Rw:v:nVEfc:m:l:i:p:Lzh"; |
| 123 | static const struct option long_options[] = { |
Peter Huewe | 73f8ec8 | 2011-01-24 19:15:51 +0000 | [diff] [blame] | 124 | {"read", 1, NULL, 'r'}, |
| 125 | {"write", 1, NULL, 'w'}, |
| 126 | {"erase", 0, NULL, 'E'}, |
| 127 | {"verify", 1, NULL, 'v'}, |
| 128 | {"noverify", 0, NULL, 'n'}, |
| 129 | {"chip", 1, NULL, 'c'}, |
| 130 | {"mainboard", 1, NULL, 'm'}, |
| 131 | {"verbose", 0, NULL, 'V'}, |
| 132 | {"force", 0, NULL, 'f'}, |
| 133 | {"layout", 1, NULL, 'l'}, |
| 134 | {"image", 1, NULL, 'i'}, |
| 135 | {"list-supported", 0, NULL, 'L'}, |
| 136 | {"list-supported-wiki", 0, NULL, 'z'}, |
| 137 | {"programmer", 1, NULL, 'p'}, |
| 138 | {"help", 0, NULL, 'h'}, |
| 139 | {"version", 0, NULL, 'R'}, |
| 140 | {NULL, 0, NULL, 0} |
Carl-Daniel Hailfinger | a84835a | 2010-01-07 03:24:05 +0000 | [diff] [blame] | 141 | }; |
| 142 | |
| 143 | char *filename = NULL; |
| 144 | |
| 145 | char *tempstr = NULL; |
Carl-Daniel Hailfinger | ad3cc55 | 2010-07-03 11:02:10 +0000 | [diff] [blame] | 146 | char *pparam = NULL; |
Carl-Daniel Hailfinger | a84835a | 2010-01-07 03:24:05 +0000 | [diff] [blame] | 147 | |
| 148 | print_version(); |
Carl-Daniel Hailfinger | 8841d3e | 2010-05-15 15:04:37 +0000 | [diff] [blame] | 149 | print_banner(); |
Carl-Daniel Hailfinger | a84835a | 2010-01-07 03:24:05 +0000 | [diff] [blame] | 150 | |
| 151 | if (selfcheck()) |
| 152 | exit(1); |
| 153 | |
| 154 | setbuf(stdout, NULL); |
Carl-Daniel Hailfinger | 8841d3e | 2010-05-15 15:04:37 +0000 | [diff] [blame] | 155 | /* FIXME: Delay all operation_specified checks until after command |
| 156 | * line parsing to allow --help overriding everything else. |
| 157 | */ |
Carl-Daniel Hailfinger | a84835a | 2010-01-07 03:24:05 +0000 | [diff] [blame] | 158 | while ((opt = getopt_long(argc, argv, optstring, |
| 159 | long_options, &option_index)) != EOF) { |
| 160 | switch (opt) { |
| 161 | case 'r': |
| 162 | if (++operation_specified > 1) { |
| 163 | fprintf(stderr, "More than one operation " |
| 164 | "specified. Aborting.\n"); |
Uwe Hermann | 2db77a0 | 2010-06-04 17:07:39 +0000 | [diff] [blame] | 165 | cli_classic_abort_usage(); |
Carl-Daniel Hailfinger | a84835a | 2010-01-07 03:24:05 +0000 | [diff] [blame] | 166 | } |
Carl-Daniel Hailfinger | 8841d3e | 2010-05-15 15:04:37 +0000 | [diff] [blame] | 167 | filename = strdup(optarg); |
Carl-Daniel Hailfinger | a84835a | 2010-01-07 03:24:05 +0000 | [diff] [blame] | 168 | read_it = 1; |
| 169 | break; |
| 170 | case 'w': |
| 171 | if (++operation_specified > 1) { |
| 172 | fprintf(stderr, "More than one operation " |
| 173 | "specified. Aborting.\n"); |
Uwe Hermann | 2db77a0 | 2010-06-04 17:07:39 +0000 | [diff] [blame] | 174 | cli_classic_abort_usage(); |
Carl-Daniel Hailfinger | a84835a | 2010-01-07 03:24:05 +0000 | [diff] [blame] | 175 | } |
Carl-Daniel Hailfinger | 8841d3e | 2010-05-15 15:04:37 +0000 | [diff] [blame] | 176 | filename = strdup(optarg); |
Carl-Daniel Hailfinger | a84835a | 2010-01-07 03:24:05 +0000 | [diff] [blame] | 177 | write_it = 1; |
| 178 | break; |
| 179 | case 'v': |
| 180 | //FIXME: gracefully handle superfluous -v |
| 181 | if (++operation_specified > 1) { |
| 182 | fprintf(stderr, "More than one operation " |
| 183 | "specified. Aborting.\n"); |
Uwe Hermann | 2db77a0 | 2010-06-04 17:07:39 +0000 | [diff] [blame] | 184 | cli_classic_abort_usage(); |
Carl-Daniel Hailfinger | a84835a | 2010-01-07 03:24:05 +0000 | [diff] [blame] | 185 | } |
| 186 | if (dont_verify_it) { |
| 187 | fprintf(stderr, "--verify and --noverify are" |
| 188 | "mutually exclusive. Aborting.\n"); |
Uwe Hermann | 2db77a0 | 2010-06-04 17:07:39 +0000 | [diff] [blame] | 189 | cli_classic_abort_usage(); |
Carl-Daniel Hailfinger | a84835a | 2010-01-07 03:24:05 +0000 | [diff] [blame] | 190 | } |
Carl-Daniel Hailfinger | 8841d3e | 2010-05-15 15:04:37 +0000 | [diff] [blame] | 191 | filename = strdup(optarg); |
Carl-Daniel Hailfinger | a84835a | 2010-01-07 03:24:05 +0000 | [diff] [blame] | 192 | verify_it = 1; |
| 193 | break; |
| 194 | case 'n': |
| 195 | if (verify_it) { |
| 196 | fprintf(stderr, "--verify and --noverify are" |
| 197 | "mutually exclusive. Aborting.\n"); |
Uwe Hermann | 2db77a0 | 2010-06-04 17:07:39 +0000 | [diff] [blame] | 198 | cli_classic_abort_usage(); |
Carl-Daniel Hailfinger | a84835a | 2010-01-07 03:24:05 +0000 | [diff] [blame] | 199 | } |
| 200 | dont_verify_it = 1; |
| 201 | break; |
| 202 | case 'c': |
| 203 | chip_to_probe = strdup(optarg); |
| 204 | break; |
| 205 | case 'V': |
Sean Nelson | 51e97d7 | 2010-01-07 20:09:33 +0000 | [diff] [blame] | 206 | verbose++; |
Carl-Daniel Hailfinger | a84835a | 2010-01-07 03:24:05 +0000 | [diff] [blame] | 207 | break; |
| 208 | case 'E': |
| 209 | if (++operation_specified > 1) { |
| 210 | fprintf(stderr, "More than one operation " |
| 211 | "specified. Aborting.\n"); |
Uwe Hermann | 2db77a0 | 2010-06-04 17:07:39 +0000 | [diff] [blame] | 212 | cli_classic_abort_usage(); |
Carl-Daniel Hailfinger | a84835a | 2010-01-07 03:24:05 +0000 | [diff] [blame] | 213 | } |
| 214 | erase_it = 1; |
| 215 | break; |
Carl-Daniel Hailfinger | a84835a | 2010-01-07 03:24:05 +0000 | [diff] [blame] | 216 | case 'm': |
Carl-Daniel Hailfinger | 7112772 | 2010-05-31 15:27:27 +0000 | [diff] [blame] | 217 | #if CONFIG_INTERNAL == 1 |
Carl-Daniel Hailfinger | a84835a | 2010-01-07 03:24:05 +0000 | [diff] [blame] | 218 | tempstr = strdup(optarg); |
| 219 | lb_vendor_dev_from_string(tempstr); |
Carl-Daniel Hailfinger | 8841d3e | 2010-05-15 15:04:37 +0000 | [diff] [blame] | 220 | #else |
| 221 | fprintf(stderr, "Error: Internal programmer support " |
| 222 | "was not compiled in and --mainboard only\n" |
| 223 | "applies to the internal programmer. Aborting.\n"); |
Uwe Hermann | 2db77a0 | 2010-06-04 17:07:39 +0000 | [diff] [blame] | 224 | cli_classic_abort_usage(); |
Carl-Daniel Hailfinger | a84835a | 2010-01-07 03:24:05 +0000 | [diff] [blame] | 225 | #endif |
Carl-Daniel Hailfinger | 8841d3e | 2010-05-15 15:04:37 +0000 | [diff] [blame] | 226 | break; |
Carl-Daniel Hailfinger | a84835a | 2010-01-07 03:24:05 +0000 | [diff] [blame] | 227 | case 'f': |
| 228 | force = 1; |
| 229 | break; |
| 230 | case 'l': |
| 231 | tempstr = strdup(optarg); |
| 232 | if (read_romlayout(tempstr)) |
Uwe Hermann | 2db77a0 | 2010-06-04 17:07:39 +0000 | [diff] [blame] | 233 | cli_classic_abort_usage(); |
Carl-Daniel Hailfinger | a84835a | 2010-01-07 03:24:05 +0000 | [diff] [blame] | 234 | break; |
| 235 | case 'i': |
Carl-Daniel Hailfinger | d566014 | 2011-07-15 23:47:45 +0000 | [diff] [blame^] | 236 | /* FIXME: -l has to be specified before -i. */ |
Carl-Daniel Hailfinger | a84835a | 2010-01-07 03:24:05 +0000 | [diff] [blame] | 237 | tempstr = strdup(optarg); |
Carl-Daniel Hailfinger | d566014 | 2011-07-15 23:47:45 +0000 | [diff] [blame^] | 238 | if (find_romentry(tempstr)) { |
| 239 | fprintf(stderr, "Error: image %s not found in " |
| 240 | "layout file or -i specified before " |
| 241 | "-l\n", tempstr); |
| 242 | cli_classic_abort_usage(); |
| 243 | } |
Carl-Daniel Hailfinger | a84835a | 2010-01-07 03:24:05 +0000 | [diff] [blame] | 244 | break; |
| 245 | case 'L': |
Carl-Daniel Hailfinger | 8841d3e | 2010-05-15 15:04:37 +0000 | [diff] [blame] | 246 | if (++operation_specified > 1) { |
| 247 | fprintf(stderr, "More than one operation " |
| 248 | "specified. Aborting.\n"); |
Uwe Hermann | 2db77a0 | 2010-06-04 17:07:39 +0000 | [diff] [blame] | 249 | cli_classic_abort_usage(); |
Carl-Daniel Hailfinger | 8841d3e | 2010-05-15 15:04:37 +0000 | [diff] [blame] | 250 | } |
Carl-Daniel Hailfinger | a84835a | 2010-01-07 03:24:05 +0000 | [diff] [blame] | 251 | list_supported = 1; |
| 252 | break; |
Carl-Daniel Hailfinger | a84835a | 2010-01-07 03:24:05 +0000 | [diff] [blame] | 253 | case 'z': |
Carl-Daniel Hailfinger | 7112772 | 2010-05-31 15:27:27 +0000 | [diff] [blame] | 254 | #if CONFIG_PRINT_WIKI == 1 |
Carl-Daniel Hailfinger | 8841d3e | 2010-05-15 15:04:37 +0000 | [diff] [blame] | 255 | if (++operation_specified > 1) { |
| 256 | fprintf(stderr, "More than one operation " |
| 257 | "specified. Aborting.\n"); |
Uwe Hermann | 2db77a0 | 2010-06-04 17:07:39 +0000 | [diff] [blame] | 258 | cli_classic_abort_usage(); |
Carl-Daniel Hailfinger | 8841d3e | 2010-05-15 15:04:37 +0000 | [diff] [blame] | 259 | } |
Carl-Daniel Hailfinger | a84835a | 2010-01-07 03:24:05 +0000 | [diff] [blame] | 260 | list_supported_wiki = 1; |
Carl-Daniel Hailfinger | 8841d3e | 2010-05-15 15:04:37 +0000 | [diff] [blame] | 261 | #else |
| 262 | fprintf(stderr, "Error: Wiki output was not compiled " |
| 263 | "in. Aborting.\n"); |
Uwe Hermann | 2db77a0 | 2010-06-04 17:07:39 +0000 | [diff] [blame] | 264 | cli_classic_abort_usage(); |
Carl-Daniel Hailfinger | a84835a | 2010-01-07 03:24:05 +0000 | [diff] [blame] | 265 | #endif |
Carl-Daniel Hailfinger | 8841d3e | 2010-05-15 15:04:37 +0000 | [diff] [blame] | 266 | break; |
Carl-Daniel Hailfinger | a84835a | 2010-01-07 03:24:05 +0000 | [diff] [blame] | 267 | case 'p': |
| 268 | for (programmer = 0; programmer < PROGRAMMER_INVALID; programmer++) { |
| 269 | name = programmer_table[programmer].name; |
| 270 | namelen = strlen(name); |
| 271 | if (strncmp(optarg, name, namelen) == 0) { |
| 272 | switch (optarg[namelen]) { |
| 273 | case ':': |
Carl-Daniel Hailfinger | ad3cc55 | 2010-07-03 11:02:10 +0000 | [diff] [blame] | 274 | pparam = strdup(optarg + namelen + 1); |
| 275 | if (!strlen(pparam)) { |
| 276 | free(pparam); |
| 277 | pparam = NULL; |
Carl-Daniel Hailfinger | 2702376 | 2010-04-28 15:22:14 +0000 | [diff] [blame] | 278 | } |
Carl-Daniel Hailfinger | a84835a | 2010-01-07 03:24:05 +0000 | [diff] [blame] | 279 | break; |
| 280 | case '\0': |
| 281 | break; |
| 282 | default: |
| 283 | /* The continue refers to the |
| 284 | * for loop. It is here to be |
| 285 | * able to differentiate between |
| 286 | * foo and foobar. |
| 287 | */ |
| 288 | continue; |
| 289 | } |
| 290 | break; |
| 291 | } |
| 292 | } |
| 293 | if (programmer == PROGRAMMER_INVALID) { |
Carl-Daniel Hailfinger | 8841d3e | 2010-05-15 15:04:37 +0000 | [diff] [blame] | 294 | fprintf(stderr, "Error: Unknown programmer " |
| 295 | "%s.\n", optarg); |
Uwe Hermann | 2db77a0 | 2010-06-04 17:07:39 +0000 | [diff] [blame] | 296 | cli_classic_abort_usage(); |
Carl-Daniel Hailfinger | a84835a | 2010-01-07 03:24:05 +0000 | [diff] [blame] | 297 | } |
| 298 | break; |
| 299 | case 'R': |
| 300 | /* print_version() is always called during startup. */ |
Carl-Daniel Hailfinger | 8841d3e | 2010-05-15 15:04:37 +0000 | [diff] [blame] | 301 | if (++operation_specified > 1) { |
| 302 | fprintf(stderr, "More than one operation " |
| 303 | "specified. Aborting.\n"); |
Uwe Hermann | 2db77a0 | 2010-06-04 17:07:39 +0000 | [diff] [blame] | 304 | cli_classic_abort_usage(); |
Carl-Daniel Hailfinger | 8841d3e | 2010-05-15 15:04:37 +0000 | [diff] [blame] | 305 | } |
Carl-Daniel Hailfinger | a84835a | 2010-01-07 03:24:05 +0000 | [diff] [blame] | 306 | exit(0); |
| 307 | break; |
| 308 | case 'h': |
Carl-Daniel Hailfinger | 8841d3e | 2010-05-15 15:04:37 +0000 | [diff] [blame] | 309 | if (++operation_specified > 1) { |
| 310 | fprintf(stderr, "More than one operation " |
| 311 | "specified. Aborting.\n"); |
Uwe Hermann | 2db77a0 | 2010-06-04 17:07:39 +0000 | [diff] [blame] | 312 | cli_classic_abort_usage(); |
Carl-Daniel Hailfinger | 8841d3e | 2010-05-15 15:04:37 +0000 | [diff] [blame] | 313 | } |
Carl-Daniel Hailfinger | a84835a | 2010-01-07 03:24:05 +0000 | [diff] [blame] | 314 | cli_classic_usage(argv[0]); |
Carl-Daniel Hailfinger | 8841d3e | 2010-05-15 15:04:37 +0000 | [diff] [blame] | 315 | exit(0); |
| 316 | break; |
| 317 | default: |
Uwe Hermann | 2db77a0 | 2010-06-04 17:07:39 +0000 | [diff] [blame] | 318 | cli_classic_abort_usage(); |
Carl-Daniel Hailfinger | a84835a | 2010-01-07 03:24:05 +0000 | [diff] [blame] | 319 | break; |
| 320 | } |
| 321 | } |
| 322 | |
Carl-Daniel Hailfinger | d566014 | 2011-07-15 23:47:45 +0000 | [diff] [blame^] | 323 | if (optind < argc) { |
| 324 | fprintf(stderr, "Error: Extra parameter found.\n"); |
| 325 | cli_classic_abort_usage(); |
| 326 | } |
| 327 | |
Carl-Daniel Hailfinger | 8841d3e | 2010-05-15 15:04:37 +0000 | [diff] [blame] | 328 | /* FIXME: Print the actions flashrom will take. */ |
| 329 | |
Carl-Daniel Hailfinger | a84835a | 2010-01-07 03:24:05 +0000 | [diff] [blame] | 330 | if (list_supported) { |
| 331 | print_supported(); |
| 332 | exit(0); |
| 333 | } |
| 334 | |
Carl-Daniel Hailfinger | 7112772 | 2010-05-31 15:27:27 +0000 | [diff] [blame] | 335 | #if CONFIG_PRINT_WIKI == 1 |
Carl-Daniel Hailfinger | a84835a | 2010-01-07 03:24:05 +0000 | [diff] [blame] | 336 | if (list_supported_wiki) { |
| 337 | print_supported_wiki(); |
| 338 | exit(0); |
| 339 | } |
| 340 | #endif |
| 341 | |
Carl-Daniel Hailfinger | 7112772 | 2010-05-31 15:27:27 +0000 | [diff] [blame] | 342 | #if CONFIG_INTERNAL == 1 |
Carl-Daniel Hailfinger | 8841d3e | 2010-05-15 15:04:37 +0000 | [diff] [blame] | 343 | if ((programmer != PROGRAMMER_INTERNAL) && (lb_part || lb_vendor)) { |
| 344 | fprintf(stderr, "Error: --mainboard requires the internal " |
| 345 | "programmer. Aborting.\n"); |
Uwe Hermann | 2db77a0 | 2010-06-04 17:07:39 +0000 | [diff] [blame] | 346 | cli_classic_abort_usage(); |
Carl-Daniel Hailfinger | a84835a | 2010-01-07 03:24:05 +0000 | [diff] [blame] | 347 | } |
Carl-Daniel Hailfinger | 8841d3e | 2010-05-15 15:04:37 +0000 | [diff] [blame] | 348 | #endif |
Carl-Daniel Hailfinger | a84835a | 2010-01-07 03:24:05 +0000 | [diff] [blame] | 349 | |
Carl-Daniel Hailfinger | 2702376 | 2010-04-28 15:22:14 +0000 | [diff] [blame] | 350 | if (chip_to_probe) { |
| 351 | for (flash = flashchips; flash && flash->name; flash++) |
| 352 | if (!strcmp(flash->name, chip_to_probe)) |
| 353 | break; |
| 354 | if (!flash || !flash->name) { |
| 355 | fprintf(stderr, "Error: Unknown chip '%s' specified.\n", |
| 356 | chip_to_probe); |
| 357 | printf("Run flashrom -L to view the hardware supported " |
| 358 | "in this flashrom version.\n"); |
| 359 | exit(1); |
| 360 | } |
| 361 | /* Clean up after the check. */ |
| 362 | flash = NULL; |
| 363 | } |
Carl-Daniel Hailfinger | 8841d3e | 2010-05-15 15:04:37 +0000 | [diff] [blame] | 364 | |
Carl-Daniel Hailfinger | 4988420 | 2010-05-22 07:10:46 +0000 | [diff] [blame] | 365 | /* FIXME: Delay calibration should happen in programmer code. */ |
| 366 | myusec_calibrate_delay(); |
| 367 | |
Carl-Daniel Hailfinger | ad3cc55 | 2010-07-03 11:02:10 +0000 | [diff] [blame] | 368 | if (programmer_init(pparam)) { |
Carl-Daniel Hailfinger | a84835a | 2010-01-07 03:24:05 +0000 | [diff] [blame] | 369 | fprintf(stderr, "Error: Programmer initialization failed.\n"); |
Carl-Daniel Hailfinger | d566014 | 2011-07-15 23:47:45 +0000 | [diff] [blame^] | 370 | ret = 1; |
| 371 | goto out_shutdown; |
Carl-Daniel Hailfinger | a84835a | 2010-01-07 03:24:05 +0000 | [diff] [blame] | 372 | } |
| 373 | |
Carl-Daniel Hailfinger | a84835a | 2010-01-07 03:24:05 +0000 | [diff] [blame] | 374 | for (i = 0; i < ARRAY_SIZE(flashes); i++) { |
Carl-Daniel Hailfinger | 4c82318 | 2011-05-04 00:39:50 +0000 | [diff] [blame] | 375 | startchip = probe_flash(startchip, &flashes[i], 0); |
| 376 | if (startchip == -1) |
| 377 | break; |
| 378 | chipcount++; |
Carl-Daniel Hailfinger | 064bbc9 | 2011-05-07 19:19:36 +0000 | [diff] [blame] | 379 | startchip++; |
Carl-Daniel Hailfinger | a84835a | 2010-01-07 03:24:05 +0000 | [diff] [blame] | 380 | } |
| 381 | |
Carl-Daniel Hailfinger | 4c82318 | 2011-05-04 00:39:50 +0000 | [diff] [blame] | 382 | if (chipcount > 1) { |
Carl-Daniel Hailfinger | a84835a | 2010-01-07 03:24:05 +0000 | [diff] [blame] | 383 | printf("Multiple flash chips were detected:"); |
Carl-Daniel Hailfinger | 4c82318 | 2011-05-04 00:39:50 +0000 | [diff] [blame] | 384 | for (i = 0; i < chipcount; i++) |
| 385 | printf(" %s", flashes[i].name); |
Carl-Daniel Hailfinger | a84835a | 2010-01-07 03:24:05 +0000 | [diff] [blame] | 386 | printf("\nPlease specify which chip to use with the -c <chipname> option.\n"); |
Carl-Daniel Hailfinger | d566014 | 2011-07-15 23:47:45 +0000 | [diff] [blame^] | 387 | ret = 1; |
| 388 | goto out_shutdown; |
Carl-Daniel Hailfinger | 4c82318 | 2011-05-04 00:39:50 +0000 | [diff] [blame] | 389 | } else if (!chipcount) { |
Carl-Daniel Hailfinger | a84835a | 2010-01-07 03:24:05 +0000 | [diff] [blame] | 390 | printf("No EEPROM/flash device found.\n"); |
| 391 | if (!force || !chip_to_probe) { |
Carl-Daniel Hailfinger | 2702376 | 2010-04-28 15:22:14 +0000 | [diff] [blame] | 392 | 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] | 393 | } |
| 394 | if (force && read_it && chip_to_probe) { |
Carl-Daniel Hailfinger | 2702376 | 2010-04-28 15:22:14 +0000 | [diff] [blame] | 395 | 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] | 396 | startchip = probe_flash(0, &flashes[0], 1); |
| 397 | if (startchip == -1) { |
Carl-Daniel Hailfinger | 2702376 | 2010-04-28 15:22:14 +0000 | [diff] [blame] | 398 | printf("Probing for flash chip '%s' failed.\n", chip_to_probe); |
Carl-Daniel Hailfinger | d566014 | 2011-07-15 23:47:45 +0000 | [diff] [blame^] | 399 | ret = 1; |
| 400 | goto out_shutdown; |
Carl-Daniel Hailfinger | a84835a | 2010-01-07 03:24:05 +0000 | [diff] [blame] | 401 | } |
| 402 | printf("Please note that forced reads most likely contain garbage.\n"); |
Carl-Daniel Hailfinger | 4c82318 | 2011-05-04 00:39:50 +0000 | [diff] [blame] | 403 | return read_flash_to_file(&flashes[0], filename); |
Carl-Daniel Hailfinger | a84835a | 2010-01-07 03:24:05 +0000 | [diff] [blame] | 404 | } |
Carl-Daniel Hailfinger | d566014 | 2011-07-15 23:47:45 +0000 | [diff] [blame^] | 405 | ret = 1; |
| 406 | goto out_shutdown; |
Carl-Daniel Hailfinger | a84835a | 2010-01-07 03:24:05 +0000 | [diff] [blame] | 407 | } |
| 408 | |
Carl-Daniel Hailfinger | 4c82318 | 2011-05-04 00:39:50 +0000 | [diff] [blame] | 409 | fill_flash = &flashes[0]; |
Carl-Daniel Hailfinger | a84835a | 2010-01-07 03:24:05 +0000 | [diff] [blame] | 410 | |
Carl-Daniel Hailfinger | 4c82318 | 2011-05-04 00:39:50 +0000 | [diff] [blame] | 411 | check_chip_supported(fill_flash); |
Carl-Daniel Hailfinger | a84835a | 2010-01-07 03:24:05 +0000 | [diff] [blame] | 412 | |
Carl-Daniel Hailfinger | 4c82318 | 2011-05-04 00:39:50 +0000 | [diff] [blame] | 413 | size = fill_flash->total_size * 1024; |
| 414 | if (check_max_decode((buses_supported & fill_flash->bustype), size) && |
Carl-Daniel Hailfinger | a84835a | 2010-01-07 03:24:05 +0000 | [diff] [blame] | 415 | (!force)) { |
| 416 | fprintf(stderr, "Chip is too big for this programmer " |
| 417 | "(-V gives details). Use --force to override.\n"); |
Carl-Daniel Hailfinger | d566014 | 2011-07-15 23:47:45 +0000 | [diff] [blame^] | 418 | ret = 1; |
| 419 | goto out_shutdown; |
Carl-Daniel Hailfinger | a84835a | 2010-01-07 03:24:05 +0000 | [diff] [blame] | 420 | } |
| 421 | |
| 422 | if (!(read_it | write_it | verify_it | erase_it)) { |
| 423 | printf("No operations were specified.\n"); |
Carl-Daniel Hailfinger | d566014 | 2011-07-15 23:47:45 +0000 | [diff] [blame^] | 424 | goto out_shutdown; |
Carl-Daniel Hailfinger | a84835a | 2010-01-07 03:24:05 +0000 | [diff] [blame] | 425 | } |
| 426 | |
| 427 | if (!filename && !erase_it) { |
| 428 | printf("Error: No filename specified.\n"); |
Carl-Daniel Hailfinger | d566014 | 2011-07-15 23:47:45 +0000 | [diff] [blame^] | 429 | ret = 1; |
| 430 | goto out_shutdown; |
Carl-Daniel Hailfinger | a84835a | 2010-01-07 03:24:05 +0000 | [diff] [blame] | 431 | } |
| 432 | |
| 433 | /* Always verify write operations unless -n is used. */ |
| 434 | if (write_it && !dont_verify_it) |
| 435 | verify_it = 1; |
| 436 | |
Carl-Daniel Hailfinger | 9ad4255 | 2010-09-15 10:20:16 +0000 | [diff] [blame] | 437 | /* FIXME: We should issue an unconditional chip reset here. This can be |
| 438 | * done once we have a .reset function in struct flashchip. |
| 439 | * Give the chip time to settle. |
| 440 | */ |
| 441 | programmer_delay(100000); |
Carl-Daniel Hailfinger | 4c82318 | 2011-05-04 00:39:50 +0000 | [diff] [blame] | 442 | 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^] | 443 | |
| 444 | out_shutdown: |
| 445 | programmer_shutdown(); |
| 446 | return ret; |
Carl-Daniel Hailfinger | a84835a | 2010-01-07 03:24:05 +0000 | [diff] [blame] | 447 | } |