blob: 5d3573808aa1865d47ec2f0c2b4797dd80c08118 [file] [log] [blame]
Carl-Daniel Hailfingera84835a2010-01-07 03:24:05 +00001/*
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 Hailfinger831e8f42010-05-30 22:24:40 +000024#include <stdio.h>
Carl-Daniel Hailfingera84835a2010-01-07 03:24:05 +000025#include <fcntl.h>
Carl-Daniel Hailfingera84835a2010-01-07 03:24:05 +000026#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 Hailfinger5b997c32010-07-27 22:41:39 +000032#include "programmer.h"
Carl-Daniel Hailfingera84835a2010-01-07 03:24:05 +000033
Carl-Daniel Hailfingerad3cc552010-07-03 11:02:10 +000034static void cli_classic_usage(const char *name)
Carl-Daniel Hailfingera84835a2010-01-07 03:24:05 +000035{
Uwe Hermann2db77a02010-06-04 17:07:39 +000036 printf("Usage: flashrom [-n] [-V] [-f] [-h|-R|-L|"
Carl-Daniel Hailfinger71127722010-05-31 15:27:27 +000037#if CONFIG_PRINT_WIKI == 1
Carl-Daniel Hailfinger8841d3e2010-05-15 15:04:37 +000038 "-z|"
Carl-Daniel Hailfingera84835a2010-01-07 03:24:05 +000039#endif
Carl-Daniel Hailfinger8841d3e2010-05-15 15:04:37 +000040 "-E|-r <file>|-w <file>|-v <file>]\n"
41 " [-c <chipname>] [-m [<vendor>:]<part>] [-l <file>]\n"
Uwe Hermann2db77a02010-06-04 17:07:39 +000042 " [-i <image>] [-p <programmername>[:<parameters>]]\n\n");
Carl-Daniel Hailfinger8841d3e2010-05-15 15:04:37 +000043
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 Hailfinger71127722010-05-31 15:27:27 +000063#if CONFIG_INTERNAL == 1
Carl-Daniel Hailfinger8841d3e2010-05-15 15:04:37 +000064 /* 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 Hailfinger71127722010-05-31 15:27:27 +000076#if CONFIG_PRINT_WIKI == 1
Carl-Daniel Hailfinger8841d3e2010-05-15 15:04:37 +000077 " -z | --list-supported-wiki print supported devices "
78 "in wiki syntax\n"
79#endif
80 " -p | --programmer <name>[:<param>] specify the programmer "
Carl-Daniel Hailfingera73fb492010-10-06 23:48:34 +000081 "device\n");
Carl-Daniel Hailfingera84835a2010-01-07 03:24:05 +000082
Carl-Daniel Hailfingera73fb492010-10-06 23:48:34 +000083 list_programmers_linebreak(37, 80, 1);
Carl-Daniel Hailfinger8841d3e2010-05-15 15:04:37 +000084 printf("\nYou can specify one of -h, -R, -L, "
Carl-Daniel Hailfinger71127722010-05-31 15:27:27 +000085#if CONFIG_PRINT_WIKI == 1
Carl-Daniel Hailfinger8841d3e2010-05-15 15:04:37 +000086 "-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 Hailfingerad3cc552010-07-03 11:02:10 +000093static void cli_classic_abort_usage(void)
Carl-Daniel Hailfinger8841d3e2010-05-15 15:04:37 +000094{
Uwe Hermann2db77a02010-06-04 17:07:39 +000095 printf("Please run \"flashrom --help\" for usage info.\n");
Carl-Daniel Hailfingera84835a2010-01-07 03:24:05 +000096 exit(1);
97}
98
99int cli_classic(int argc, char *argv[])
100{
101 unsigned long size;
102 /* Probe for up to three flash chips. */
Carl-Daniel Hailfinger4c823182011-05-04 00:39:50 +0000103 const struct flashchip *flash;
104 struct flashchip flashes[3];
105 struct flashchip *fill_flash;
Carl-Daniel Hailfingera84835a2010-01-07 03:24:05 +0000106 const char *name;
Carl-Daniel Hailfinger082c8b52011-08-15 19:54:20 +0000107 int namelen, opt, i;
108 int startchip = 0, chipcount = 0, option_index = 0, force = 0;
Carl-Daniel Hailfinger71127722010-05-31 15:27:27 +0000109#if CONFIG_PRINT_WIKI == 1
Carl-Daniel Hailfingera84835a2010-01-07 03:24:05 +0000110 int list_supported_wiki = 0;
111#endif
Carl-Daniel Hailfinger082c8b52011-08-15 19:54:20 +0000112 int read_it = 0, write_it = 0, erase_it = 0, verify_it = 0;
113 int dont_verify_it = 0, list_supported = 0, operation_specified = 0;
114 int ret = 0;
Carl-Daniel Hailfingera84835a2010-01-07 03:24:05 +0000115
Mathias Krausea60faab2011-01-17 07:50:42 +0000116 static const char optstring[] = "r:Rw:v:nVEfc:m:l:i:p:Lzh";
117 static const struct option long_options[] = {
Uwe Hermann91f4afa2011-07-28 08:13:25 +0000118 {"read", 1, NULL, 'r'},
119 {"write", 1, NULL, 'w'},
120 {"erase", 0, NULL, 'E'},
121 {"verify", 1, NULL, 'v'},
122 {"noverify", 0, NULL, 'n'},
123 {"chip", 1, NULL, 'c'},
124 {"mainboard", 1, NULL, 'm'},
125 {"verbose", 0, NULL, 'V'},
126 {"force", 0, NULL, 'f'},
127 {"layout", 1, NULL, 'l'},
128 {"image", 1, NULL, 'i'},
129 {"list-supported", 0, NULL, 'L'},
130 {"list-supported-wiki", 0, NULL, 'z'},
131 {"programmer", 1, NULL, 'p'},
132 {"help", 0, NULL, 'h'},
133 {"version", 0, NULL, 'R'},
134 {NULL, 0, NULL, 0},
Carl-Daniel Hailfingera84835a2010-01-07 03:24:05 +0000135 };
136
137 char *filename = NULL;
Carl-Daniel Hailfingera84835a2010-01-07 03:24:05 +0000138 char *tempstr = NULL;
Carl-Daniel Hailfingerad3cc552010-07-03 11:02:10 +0000139 char *pparam = NULL;
Carl-Daniel Hailfingera84835a2010-01-07 03:24:05 +0000140
141 print_version();
Carl-Daniel Hailfinger8841d3e2010-05-15 15:04:37 +0000142 print_banner();
Carl-Daniel Hailfingera84835a2010-01-07 03:24:05 +0000143
144 if (selfcheck())
145 exit(1);
146
147 setbuf(stdout, NULL);
Carl-Daniel Hailfinger8841d3e2010-05-15 15:04:37 +0000148 /* FIXME: Delay all operation_specified checks until after command
149 * line parsing to allow --help overriding everything else.
150 */
Carl-Daniel Hailfingera84835a2010-01-07 03:24:05 +0000151 while ((opt = getopt_long(argc, argv, optstring,
152 long_options, &option_index)) != EOF) {
153 switch (opt) {
154 case 'r':
155 if (++operation_specified > 1) {
156 fprintf(stderr, "More than one operation "
157 "specified. Aborting.\n");
Uwe Hermann2db77a02010-06-04 17:07:39 +0000158 cli_classic_abort_usage();
Carl-Daniel Hailfingera84835a2010-01-07 03:24:05 +0000159 }
Carl-Daniel Hailfinger8841d3e2010-05-15 15:04:37 +0000160 filename = strdup(optarg);
Carl-Daniel Hailfingera84835a2010-01-07 03:24:05 +0000161 read_it = 1;
162 break;
163 case 'w':
164 if (++operation_specified > 1) {
165 fprintf(stderr, "More than one operation "
166 "specified. Aborting.\n");
Uwe Hermann2db77a02010-06-04 17:07:39 +0000167 cli_classic_abort_usage();
Carl-Daniel Hailfingera84835a2010-01-07 03:24:05 +0000168 }
Carl-Daniel Hailfinger8841d3e2010-05-15 15:04:37 +0000169 filename = strdup(optarg);
Carl-Daniel Hailfingera84835a2010-01-07 03:24:05 +0000170 write_it = 1;
171 break;
172 case 'v':
173 //FIXME: gracefully handle superfluous -v
174 if (++operation_specified > 1) {
175 fprintf(stderr, "More than one operation "
176 "specified. Aborting.\n");
Uwe Hermann2db77a02010-06-04 17:07:39 +0000177 cli_classic_abort_usage();
Carl-Daniel Hailfingera84835a2010-01-07 03:24:05 +0000178 }
179 if (dont_verify_it) {
180 fprintf(stderr, "--verify and --noverify are"
181 "mutually exclusive. Aborting.\n");
Uwe Hermann2db77a02010-06-04 17:07:39 +0000182 cli_classic_abort_usage();
Carl-Daniel Hailfingera84835a2010-01-07 03:24:05 +0000183 }
Carl-Daniel Hailfinger8841d3e2010-05-15 15:04:37 +0000184 filename = strdup(optarg);
Carl-Daniel Hailfingera84835a2010-01-07 03:24:05 +0000185 verify_it = 1;
186 break;
187 case 'n':
188 if (verify_it) {
189 fprintf(stderr, "--verify and --noverify are"
190 "mutually exclusive. Aborting.\n");
Uwe Hermann2db77a02010-06-04 17:07:39 +0000191 cli_classic_abort_usage();
Carl-Daniel Hailfingera84835a2010-01-07 03:24:05 +0000192 }
193 dont_verify_it = 1;
194 break;
195 case 'c':
196 chip_to_probe = strdup(optarg);
197 break;
198 case 'V':
Sean Nelson51e97d72010-01-07 20:09:33 +0000199 verbose++;
Carl-Daniel Hailfingera84835a2010-01-07 03:24:05 +0000200 break;
201 case 'E':
202 if (++operation_specified > 1) {
203 fprintf(stderr, "More than one operation "
204 "specified. Aborting.\n");
Uwe Hermann2db77a02010-06-04 17:07:39 +0000205 cli_classic_abort_usage();
Carl-Daniel Hailfingera84835a2010-01-07 03:24:05 +0000206 }
207 erase_it = 1;
208 break;
Carl-Daniel Hailfingera84835a2010-01-07 03:24:05 +0000209 case 'm':
Carl-Daniel Hailfinger71127722010-05-31 15:27:27 +0000210#if CONFIG_INTERNAL == 1
Carl-Daniel Hailfingera84835a2010-01-07 03:24:05 +0000211 tempstr = strdup(optarg);
212 lb_vendor_dev_from_string(tempstr);
Carl-Daniel Hailfinger8841d3e2010-05-15 15:04:37 +0000213#else
214 fprintf(stderr, "Error: Internal programmer support "
215 "was not compiled in and --mainboard only\n"
216 "applies to the internal programmer. Aborting.\n");
Uwe Hermann2db77a02010-06-04 17:07:39 +0000217 cli_classic_abort_usage();
Carl-Daniel Hailfingera84835a2010-01-07 03:24:05 +0000218#endif
Carl-Daniel Hailfinger8841d3e2010-05-15 15:04:37 +0000219 break;
Carl-Daniel Hailfingera84835a2010-01-07 03:24:05 +0000220 case 'f':
221 force = 1;
222 break;
223 case 'l':
224 tempstr = strdup(optarg);
225 if (read_romlayout(tempstr))
Uwe Hermann2db77a02010-06-04 17:07:39 +0000226 cli_classic_abort_usage();
Carl-Daniel Hailfingera84835a2010-01-07 03:24:05 +0000227 break;
228 case 'i':
Carl-Daniel Hailfingerd5660142011-07-15 23:47:45 +0000229 /* FIXME: -l has to be specified before -i. */
Carl-Daniel Hailfingera84835a2010-01-07 03:24:05 +0000230 tempstr = strdup(optarg);
Stefan Tauner1a30d502011-07-19 07:58:06 +0000231 if (find_romentry(tempstr) < 0) {
Carl-Daniel Hailfingerd5660142011-07-15 23:47:45 +0000232 fprintf(stderr, "Error: image %s not found in "
233 "layout file or -i specified before "
234 "-l\n", tempstr);
235 cli_classic_abort_usage();
236 }
Carl-Daniel Hailfingera84835a2010-01-07 03:24:05 +0000237 break;
238 case 'L':
Carl-Daniel Hailfinger8841d3e2010-05-15 15:04:37 +0000239 if (++operation_specified > 1) {
240 fprintf(stderr, "More than one operation "
241 "specified. Aborting.\n");
Uwe Hermann2db77a02010-06-04 17:07:39 +0000242 cli_classic_abort_usage();
Carl-Daniel Hailfinger8841d3e2010-05-15 15:04:37 +0000243 }
Carl-Daniel Hailfingera84835a2010-01-07 03:24:05 +0000244 list_supported = 1;
245 break;
Carl-Daniel Hailfingera84835a2010-01-07 03:24:05 +0000246 case 'z':
Carl-Daniel Hailfinger71127722010-05-31 15:27:27 +0000247#if CONFIG_PRINT_WIKI == 1
Carl-Daniel Hailfinger8841d3e2010-05-15 15:04:37 +0000248 if (++operation_specified > 1) {
249 fprintf(stderr, "More than one operation "
250 "specified. Aborting.\n");
Uwe Hermann2db77a02010-06-04 17:07:39 +0000251 cli_classic_abort_usage();
Carl-Daniel Hailfinger8841d3e2010-05-15 15:04:37 +0000252 }
Carl-Daniel Hailfingera84835a2010-01-07 03:24:05 +0000253 list_supported_wiki = 1;
Carl-Daniel Hailfinger8841d3e2010-05-15 15:04:37 +0000254#else
255 fprintf(stderr, "Error: Wiki output was not compiled "
256 "in. Aborting.\n");
Uwe Hermann2db77a02010-06-04 17:07:39 +0000257 cli_classic_abort_usage();
Carl-Daniel Hailfingera84835a2010-01-07 03:24:05 +0000258#endif
Carl-Daniel Hailfinger8841d3e2010-05-15 15:04:37 +0000259 break;
Carl-Daniel Hailfingera84835a2010-01-07 03:24:05 +0000260 case 'p':
261 for (programmer = 0; programmer < PROGRAMMER_INVALID; programmer++) {
262 name = programmer_table[programmer].name;
263 namelen = strlen(name);
264 if (strncmp(optarg, name, namelen) == 0) {
265 switch (optarg[namelen]) {
266 case ':':
Carl-Daniel Hailfingerad3cc552010-07-03 11:02:10 +0000267 pparam = strdup(optarg + namelen + 1);
268 if (!strlen(pparam)) {
269 free(pparam);
270 pparam = NULL;
Carl-Daniel Hailfinger27023762010-04-28 15:22:14 +0000271 }
Carl-Daniel Hailfingera84835a2010-01-07 03:24:05 +0000272 break;
273 case '\0':
274 break;
275 default:
276 /* The continue refers to the
277 * for loop. It is here to be
278 * able to differentiate between
279 * foo and foobar.
280 */
281 continue;
282 }
283 break;
284 }
285 }
286 if (programmer == PROGRAMMER_INVALID) {
Carl-Daniel Hailfinger8841d3e2010-05-15 15:04:37 +0000287 fprintf(stderr, "Error: Unknown programmer "
288 "%s.\n", optarg);
Uwe Hermann2db77a02010-06-04 17:07:39 +0000289 cli_classic_abort_usage();
Carl-Daniel Hailfingera84835a2010-01-07 03:24:05 +0000290 }
291 break;
292 case 'R':
293 /* print_version() is always called during startup. */
Carl-Daniel Hailfinger8841d3e2010-05-15 15:04:37 +0000294 if (++operation_specified > 1) {
295 fprintf(stderr, "More than one operation "
296 "specified. Aborting.\n");
Uwe Hermann2db77a02010-06-04 17:07:39 +0000297 cli_classic_abort_usage();
Carl-Daniel Hailfinger8841d3e2010-05-15 15:04:37 +0000298 }
Carl-Daniel Hailfingera84835a2010-01-07 03:24:05 +0000299 exit(0);
300 break;
301 case 'h':
Carl-Daniel Hailfinger8841d3e2010-05-15 15:04:37 +0000302 if (++operation_specified > 1) {
303 fprintf(stderr, "More than one operation "
304 "specified. Aborting.\n");
Uwe Hermann2db77a02010-06-04 17:07:39 +0000305 cli_classic_abort_usage();
Carl-Daniel Hailfinger8841d3e2010-05-15 15:04:37 +0000306 }
Carl-Daniel Hailfingera84835a2010-01-07 03:24:05 +0000307 cli_classic_usage(argv[0]);
Carl-Daniel Hailfinger8841d3e2010-05-15 15:04:37 +0000308 exit(0);
309 break;
310 default:
Uwe Hermann2db77a02010-06-04 17:07:39 +0000311 cli_classic_abort_usage();
Carl-Daniel Hailfingera84835a2010-01-07 03:24:05 +0000312 break;
313 }
314 }
315
Carl-Daniel Hailfingerd5660142011-07-15 23:47:45 +0000316 if (optind < argc) {
317 fprintf(stderr, "Error: Extra parameter found.\n");
318 cli_classic_abort_usage();
319 }
320
Carl-Daniel Hailfinger8841d3e2010-05-15 15:04:37 +0000321 /* FIXME: Print the actions flashrom will take. */
322
Carl-Daniel Hailfingera84835a2010-01-07 03:24:05 +0000323 if (list_supported) {
324 print_supported();
325 exit(0);
326 }
327
Carl-Daniel Hailfinger71127722010-05-31 15:27:27 +0000328#if CONFIG_PRINT_WIKI == 1
Carl-Daniel Hailfingera84835a2010-01-07 03:24:05 +0000329 if (list_supported_wiki) {
330 print_supported_wiki();
331 exit(0);
332 }
333#endif
334
Carl-Daniel Hailfinger71127722010-05-31 15:27:27 +0000335#if CONFIG_INTERNAL == 1
Carl-Daniel Hailfinger8841d3e2010-05-15 15:04:37 +0000336 if ((programmer != PROGRAMMER_INTERNAL) && (lb_part || lb_vendor)) {
337 fprintf(stderr, "Error: --mainboard requires the internal "
338 "programmer. Aborting.\n");
Uwe Hermann2db77a02010-06-04 17:07:39 +0000339 cli_classic_abort_usage();
Carl-Daniel Hailfingera84835a2010-01-07 03:24:05 +0000340 }
Carl-Daniel Hailfinger8841d3e2010-05-15 15:04:37 +0000341#endif
Carl-Daniel Hailfingera84835a2010-01-07 03:24:05 +0000342
Carl-Daniel Hailfinger27023762010-04-28 15:22:14 +0000343 if (chip_to_probe) {
344 for (flash = flashchips; flash && flash->name; flash++)
345 if (!strcmp(flash->name, chip_to_probe))
346 break;
347 if (!flash || !flash->name) {
348 fprintf(stderr, "Error: Unknown chip '%s' specified.\n",
349 chip_to_probe);
350 printf("Run flashrom -L to view the hardware supported "
Uwe Hermann91f4afa2011-07-28 08:13:25 +0000351 "in this flashrom version.\n");
Carl-Daniel Hailfinger27023762010-04-28 15:22:14 +0000352 exit(1);
353 }
354 /* Clean up after the check. */
355 flash = NULL;
356 }
Carl-Daniel Hailfinger8841d3e2010-05-15 15:04:37 +0000357
Carl-Daniel Hailfinger49884202010-05-22 07:10:46 +0000358 /* FIXME: Delay calibration should happen in programmer code. */
359 myusec_calibrate_delay();
360
Carl-Daniel Hailfingerad3cc552010-07-03 11:02:10 +0000361 if (programmer_init(pparam)) {
Carl-Daniel Hailfingera84835a2010-01-07 03:24:05 +0000362 fprintf(stderr, "Error: Programmer initialization failed.\n");
Carl-Daniel Hailfingerd5660142011-07-15 23:47:45 +0000363 ret = 1;
364 goto out_shutdown;
Carl-Daniel Hailfingera84835a2010-01-07 03:24:05 +0000365 }
366
Carl-Daniel Hailfingera84835a2010-01-07 03:24:05 +0000367 for (i = 0; i < ARRAY_SIZE(flashes); i++) {
Carl-Daniel Hailfinger4c823182011-05-04 00:39:50 +0000368 startchip = probe_flash(startchip, &flashes[i], 0);
369 if (startchip == -1)
370 break;
371 chipcount++;
Carl-Daniel Hailfinger064bbc92011-05-07 19:19:36 +0000372 startchip++;
Carl-Daniel Hailfingera84835a2010-01-07 03:24:05 +0000373 }
374
Carl-Daniel Hailfinger4c823182011-05-04 00:39:50 +0000375 if (chipcount > 1) {
Stefan Tauner716e0982011-07-25 20:38:52 +0000376 printf("Multiple flash chips were detected: \"%s\"",
377 flashes[0].name);
378 for (i = 1; i < chipcount; i++)
379 printf(", \"%s\"", flashes[i].name);
Uwe Hermann91f4afa2011-07-28 08:13:25 +0000380 printf("\nPlease specify which chip to use with the "
381 "-c <chipname> option.\n");
Carl-Daniel Hailfingerd5660142011-07-15 23:47:45 +0000382 ret = 1;
383 goto out_shutdown;
Carl-Daniel Hailfinger4c823182011-05-04 00:39:50 +0000384 } else if (!chipcount) {
Carl-Daniel Hailfingera84835a2010-01-07 03:24:05 +0000385 printf("No EEPROM/flash device found.\n");
386 if (!force || !chip_to_probe) {
Uwe Hermann91f4afa2011-07-28 08:13:25 +0000387 printf("Note: flashrom can never write if the flash "
388 "chip isn't found automatically.\n");
Carl-Daniel Hailfingera84835a2010-01-07 03:24:05 +0000389 }
390 if (force && read_it && chip_to_probe) {
Uwe Hermann91f4afa2011-07-28 08:13:25 +0000391 printf("Force read (-f -r -c) requested, pretending "
392 "the chip is there:\n");
Carl-Daniel Hailfinger4c823182011-05-04 00:39:50 +0000393 startchip = probe_flash(0, &flashes[0], 1);
394 if (startchip == -1) {
Uwe Hermann91f4afa2011-07-28 08:13:25 +0000395 printf("Probing for flash chip '%s' failed.\n",
396 chip_to_probe);
Carl-Daniel Hailfingerd5660142011-07-15 23:47:45 +0000397 ret = 1;
398 goto out_shutdown;
Carl-Daniel Hailfingera84835a2010-01-07 03:24:05 +0000399 }
Uwe Hermann91f4afa2011-07-28 08:13:25 +0000400 printf("Please note that forced reads most likely "
401 "contain garbage.\n");
Carl-Daniel Hailfinger4c823182011-05-04 00:39:50 +0000402 return read_flash_to_file(&flashes[0], filename);
Carl-Daniel Hailfingera84835a2010-01-07 03:24:05 +0000403 }
Carl-Daniel Hailfingerd5660142011-07-15 23:47:45 +0000404 ret = 1;
405 goto out_shutdown;
Carl-Daniel Hailfingera84835a2010-01-07 03:24:05 +0000406 }
407
Carl-Daniel Hailfinger4c823182011-05-04 00:39:50 +0000408 fill_flash = &flashes[0];
Carl-Daniel Hailfingera84835a2010-01-07 03:24:05 +0000409
Carl-Daniel Hailfinger4c823182011-05-04 00:39:50 +0000410 check_chip_supported(fill_flash);
Carl-Daniel Hailfingera84835a2010-01-07 03:24:05 +0000411
Carl-Daniel Hailfinger4c823182011-05-04 00:39:50 +0000412 size = fill_flash->total_size * 1024;
413 if (check_max_decode((buses_supported & fill_flash->bustype), size) &&
Carl-Daniel Hailfingera84835a2010-01-07 03:24:05 +0000414 (!force)) {
415 fprintf(stderr, "Chip is too big for this programmer "
416 "(-V gives details). Use --force to override.\n");
Carl-Daniel Hailfingerd5660142011-07-15 23:47:45 +0000417 ret = 1;
418 goto out_shutdown;
Carl-Daniel Hailfingera84835a2010-01-07 03:24:05 +0000419 }
420
421 if (!(read_it | write_it | verify_it | erase_it)) {
422 printf("No operations were specified.\n");
Carl-Daniel Hailfingerd5660142011-07-15 23:47:45 +0000423 goto out_shutdown;
Carl-Daniel Hailfingera84835a2010-01-07 03:24:05 +0000424 }
425
426 if (!filename && !erase_it) {
427 printf("Error: No filename specified.\n");
Carl-Daniel Hailfingerd5660142011-07-15 23:47:45 +0000428 ret = 1;
429 goto out_shutdown;
Carl-Daniel Hailfingera84835a2010-01-07 03:24:05 +0000430 }
431
432 /* Always verify write operations unless -n is used. */
433 if (write_it && !dont_verify_it)
434 verify_it = 1;
435
Carl-Daniel Hailfinger9ad42552010-09-15 10:20:16 +0000436 /* FIXME: We should issue an unconditional chip reset here. This can be
437 * done once we have a .reset function in struct flashchip.
438 * Give the chip time to settle.
439 */
440 programmer_delay(100000);
Carl-Daniel Hailfinger4c823182011-05-04 00:39:50 +0000441 return doit(fill_flash, force, filename, read_it, write_it, erase_it, verify_it);
Carl-Daniel Hailfingerd5660142011-07-15 23:47:45 +0000442
443out_shutdown:
444 programmer_shutdown();
445 return ret;
Carl-Daniel Hailfingera84835a2010-01-07 03:24:05 +0000446}