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