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