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