blob: 36fe9adfdbacd3a14c2f1ba2e07f7272d76533a4 [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;
106 int startchip = 0;
107 int chipcount = 0;
Carl-Daniel Hailfingera84835a2010-01-07 03:24:05 +0000108 const char *name;
109 int namelen;
110 int opt;
111 int option_index = 0;
112 int force = 0;
113 int read_it = 0, write_it = 0, erase_it = 0, verify_it = 0;
114 int dont_verify_it = 0, list_supported = 0;
Carl-Daniel Hailfinger71127722010-05-31 15:27:27 +0000115#if CONFIG_PRINT_WIKI == 1
Carl-Daniel Hailfingera84835a2010-01-07 03:24:05 +0000116 int list_supported_wiki = 0;
117#endif
118 int operation_specified = 0;
119 int i;
Carl-Daniel Hailfingerd5660142011-07-15 23:47:45 +0000120 int ret = 0;
Carl-Daniel Hailfingera84835a2010-01-07 03:24:05 +0000121
Mathias Krausea60faab2011-01-17 07:50:42 +0000122 static const char optstring[] = "r:Rw:v:nVEfc:m:l:i:p:Lzh";
123 static const struct option long_options[] = {
Peter Huewe73f8ec82011-01-24 19:15:51 +0000124 {"read", 1, NULL, 'r'},
125 {"write", 1, NULL, 'w'},
126 {"erase", 0, NULL, 'E'},
127 {"verify", 1, NULL, 'v'},
128 {"noverify", 0, NULL, 'n'},
129 {"chip", 1, NULL, 'c'},
130 {"mainboard", 1, NULL, 'm'},
131 {"verbose", 0, NULL, 'V'},
132 {"force", 0, NULL, 'f'},
133 {"layout", 1, NULL, 'l'},
134 {"image", 1, NULL, 'i'},
135 {"list-supported", 0, NULL, 'L'},
136 {"list-supported-wiki", 0, NULL, 'z'},
137 {"programmer", 1, NULL, 'p'},
138 {"help", 0, NULL, 'h'},
139 {"version", 0, NULL, 'R'},
140 {NULL, 0, NULL, 0}
Carl-Daniel Hailfingera84835a2010-01-07 03:24:05 +0000141 };
142
143 char *filename = NULL;
144
145 char *tempstr = NULL;
Carl-Daniel Hailfingerad3cc552010-07-03 11:02:10 +0000146 char *pparam = NULL;
Carl-Daniel Hailfingera84835a2010-01-07 03:24:05 +0000147
148 print_version();
Carl-Daniel Hailfinger8841d3e2010-05-15 15:04:37 +0000149 print_banner();
Carl-Daniel Hailfingera84835a2010-01-07 03:24:05 +0000150
151 if (selfcheck())
152 exit(1);
153
154 setbuf(stdout, NULL);
Carl-Daniel Hailfinger8841d3e2010-05-15 15:04:37 +0000155 /* FIXME: Delay all operation_specified checks until after command
156 * line parsing to allow --help overriding everything else.
157 */
Carl-Daniel Hailfingera84835a2010-01-07 03:24:05 +0000158 while ((opt = getopt_long(argc, argv, optstring,
159 long_options, &option_index)) != EOF) {
160 switch (opt) {
161 case 'r':
162 if (++operation_specified > 1) {
163 fprintf(stderr, "More than one operation "
164 "specified. Aborting.\n");
Uwe Hermann2db77a02010-06-04 17:07:39 +0000165 cli_classic_abort_usage();
Carl-Daniel Hailfingera84835a2010-01-07 03:24:05 +0000166 }
Carl-Daniel Hailfinger8841d3e2010-05-15 15:04:37 +0000167 filename = strdup(optarg);
Carl-Daniel Hailfingera84835a2010-01-07 03:24:05 +0000168 read_it = 1;
169 break;
170 case 'w':
171 if (++operation_specified > 1) {
172 fprintf(stderr, "More than one operation "
173 "specified. Aborting.\n");
Uwe Hermann2db77a02010-06-04 17:07:39 +0000174 cli_classic_abort_usage();
Carl-Daniel Hailfingera84835a2010-01-07 03:24:05 +0000175 }
Carl-Daniel Hailfinger8841d3e2010-05-15 15:04:37 +0000176 filename = strdup(optarg);
Carl-Daniel Hailfingera84835a2010-01-07 03:24:05 +0000177 write_it = 1;
178 break;
179 case 'v':
180 //FIXME: gracefully handle superfluous -v
181 if (++operation_specified > 1) {
182 fprintf(stderr, "More than one operation "
183 "specified. Aborting.\n");
Uwe Hermann2db77a02010-06-04 17:07:39 +0000184 cli_classic_abort_usage();
Carl-Daniel Hailfingera84835a2010-01-07 03:24:05 +0000185 }
186 if (dont_verify_it) {
187 fprintf(stderr, "--verify and --noverify are"
188 "mutually exclusive. Aborting.\n");
Uwe Hermann2db77a02010-06-04 17:07:39 +0000189 cli_classic_abort_usage();
Carl-Daniel Hailfingera84835a2010-01-07 03:24:05 +0000190 }
Carl-Daniel Hailfinger8841d3e2010-05-15 15:04:37 +0000191 filename = strdup(optarg);
Carl-Daniel Hailfingera84835a2010-01-07 03:24:05 +0000192 verify_it = 1;
193 break;
194 case 'n':
195 if (verify_it) {
196 fprintf(stderr, "--verify and --noverify are"
197 "mutually exclusive. Aborting.\n");
Uwe Hermann2db77a02010-06-04 17:07:39 +0000198 cli_classic_abort_usage();
Carl-Daniel Hailfingera84835a2010-01-07 03:24:05 +0000199 }
200 dont_verify_it = 1;
201 break;
202 case 'c':
203 chip_to_probe = strdup(optarg);
204 break;
205 case 'V':
Sean Nelson51e97d72010-01-07 20:09:33 +0000206 verbose++;
Carl-Daniel Hailfingera84835a2010-01-07 03:24:05 +0000207 break;
208 case 'E':
209 if (++operation_specified > 1) {
210 fprintf(stderr, "More than one operation "
211 "specified. Aborting.\n");
Uwe Hermann2db77a02010-06-04 17:07:39 +0000212 cli_classic_abort_usage();
Carl-Daniel Hailfingera84835a2010-01-07 03:24:05 +0000213 }
214 erase_it = 1;
215 break;
Carl-Daniel Hailfingera84835a2010-01-07 03:24:05 +0000216 case 'm':
Carl-Daniel Hailfinger71127722010-05-31 15:27:27 +0000217#if CONFIG_INTERNAL == 1
Carl-Daniel Hailfingera84835a2010-01-07 03:24:05 +0000218 tempstr = strdup(optarg);
219 lb_vendor_dev_from_string(tempstr);
Carl-Daniel Hailfinger8841d3e2010-05-15 15:04:37 +0000220#else
221 fprintf(stderr, "Error: Internal programmer support "
222 "was not compiled in and --mainboard only\n"
223 "applies to the internal programmer. Aborting.\n");
Uwe Hermann2db77a02010-06-04 17:07:39 +0000224 cli_classic_abort_usage();
Carl-Daniel Hailfingera84835a2010-01-07 03:24:05 +0000225#endif
Carl-Daniel Hailfinger8841d3e2010-05-15 15:04:37 +0000226 break;
Carl-Daniel Hailfingera84835a2010-01-07 03:24:05 +0000227 case 'f':
228 force = 1;
229 break;
230 case 'l':
231 tempstr = strdup(optarg);
232 if (read_romlayout(tempstr))
Uwe Hermann2db77a02010-06-04 17:07:39 +0000233 cli_classic_abort_usage();
Carl-Daniel Hailfingera84835a2010-01-07 03:24:05 +0000234 break;
235 case 'i':
Carl-Daniel Hailfingerd5660142011-07-15 23:47:45 +0000236 /* FIXME: -l has to be specified before -i. */
Carl-Daniel Hailfingera84835a2010-01-07 03:24:05 +0000237 tempstr = strdup(optarg);
Stefan Tauner1a30d502011-07-19 07:58:06 +0000238 if (find_romentry(tempstr) < 0) {
Carl-Daniel Hailfingerd5660142011-07-15 23:47:45 +0000239 fprintf(stderr, "Error: image %s not found in "
240 "layout file or -i specified before "
241 "-l\n", tempstr);
242 cli_classic_abort_usage();
243 }
Carl-Daniel Hailfingera84835a2010-01-07 03:24:05 +0000244 break;
245 case 'L':
Carl-Daniel Hailfinger8841d3e2010-05-15 15:04:37 +0000246 if (++operation_specified > 1) {
247 fprintf(stderr, "More than one operation "
248 "specified. Aborting.\n");
Uwe Hermann2db77a02010-06-04 17:07:39 +0000249 cli_classic_abort_usage();
Carl-Daniel Hailfinger8841d3e2010-05-15 15:04:37 +0000250 }
Carl-Daniel Hailfingera84835a2010-01-07 03:24:05 +0000251 list_supported = 1;
252 break;
Carl-Daniel Hailfingera84835a2010-01-07 03:24:05 +0000253 case 'z':
Carl-Daniel Hailfinger71127722010-05-31 15:27:27 +0000254#if CONFIG_PRINT_WIKI == 1
Carl-Daniel Hailfinger8841d3e2010-05-15 15:04:37 +0000255 if (++operation_specified > 1) {
256 fprintf(stderr, "More than one operation "
257 "specified. Aborting.\n");
Uwe Hermann2db77a02010-06-04 17:07:39 +0000258 cli_classic_abort_usage();
Carl-Daniel Hailfinger8841d3e2010-05-15 15:04:37 +0000259 }
Carl-Daniel Hailfingera84835a2010-01-07 03:24:05 +0000260 list_supported_wiki = 1;
Carl-Daniel Hailfinger8841d3e2010-05-15 15:04:37 +0000261#else
262 fprintf(stderr, "Error: Wiki output was not compiled "
263 "in. Aborting.\n");
Uwe Hermann2db77a02010-06-04 17:07:39 +0000264 cli_classic_abort_usage();
Carl-Daniel Hailfingera84835a2010-01-07 03:24:05 +0000265#endif
Carl-Daniel Hailfinger8841d3e2010-05-15 15:04:37 +0000266 break;
Carl-Daniel Hailfingera84835a2010-01-07 03:24:05 +0000267 case 'p':
268 for (programmer = 0; programmer < PROGRAMMER_INVALID; programmer++) {
269 name = programmer_table[programmer].name;
270 namelen = strlen(name);
271 if (strncmp(optarg, name, namelen) == 0) {
272 switch (optarg[namelen]) {
273 case ':':
Carl-Daniel Hailfingerad3cc552010-07-03 11:02:10 +0000274 pparam = strdup(optarg + namelen + 1);
275 if (!strlen(pparam)) {
276 free(pparam);
277 pparam = NULL;
Carl-Daniel Hailfinger27023762010-04-28 15:22:14 +0000278 }
Carl-Daniel Hailfingera84835a2010-01-07 03:24:05 +0000279 break;
280 case '\0':
281 break;
282 default:
283 /* The continue refers to the
284 * for loop. It is here to be
285 * able to differentiate between
286 * foo and foobar.
287 */
288 continue;
289 }
290 break;
291 }
292 }
293 if (programmer == PROGRAMMER_INVALID) {
Carl-Daniel Hailfinger8841d3e2010-05-15 15:04:37 +0000294 fprintf(stderr, "Error: Unknown programmer "
295 "%s.\n", optarg);
Uwe Hermann2db77a02010-06-04 17:07:39 +0000296 cli_classic_abort_usage();
Carl-Daniel Hailfingera84835a2010-01-07 03:24:05 +0000297 }
298 break;
299 case 'R':
300 /* print_version() is always called during startup. */
Carl-Daniel Hailfinger8841d3e2010-05-15 15:04:37 +0000301 if (++operation_specified > 1) {
302 fprintf(stderr, "More than one operation "
303 "specified. Aborting.\n");
Uwe Hermann2db77a02010-06-04 17:07:39 +0000304 cli_classic_abort_usage();
Carl-Daniel Hailfinger8841d3e2010-05-15 15:04:37 +0000305 }
Carl-Daniel Hailfingera84835a2010-01-07 03:24:05 +0000306 exit(0);
307 break;
308 case 'h':
Carl-Daniel Hailfinger8841d3e2010-05-15 15:04:37 +0000309 if (++operation_specified > 1) {
310 fprintf(stderr, "More than one operation "
311 "specified. Aborting.\n");
Uwe Hermann2db77a02010-06-04 17:07:39 +0000312 cli_classic_abort_usage();
Carl-Daniel Hailfinger8841d3e2010-05-15 15:04:37 +0000313 }
Carl-Daniel Hailfingera84835a2010-01-07 03:24:05 +0000314 cli_classic_usage(argv[0]);
Carl-Daniel Hailfinger8841d3e2010-05-15 15:04:37 +0000315 exit(0);
316 break;
317 default:
Uwe Hermann2db77a02010-06-04 17:07:39 +0000318 cli_classic_abort_usage();
Carl-Daniel Hailfingera84835a2010-01-07 03:24:05 +0000319 break;
320 }
321 }
322
Carl-Daniel Hailfingerd5660142011-07-15 23:47:45 +0000323 if (optind < argc) {
324 fprintf(stderr, "Error: Extra parameter found.\n");
325 cli_classic_abort_usage();
326 }
327
Carl-Daniel Hailfinger8841d3e2010-05-15 15:04:37 +0000328 /* FIXME: Print the actions flashrom will take. */
329
Carl-Daniel Hailfingera84835a2010-01-07 03:24:05 +0000330 if (list_supported) {
331 print_supported();
332 exit(0);
333 }
334
Carl-Daniel Hailfinger71127722010-05-31 15:27:27 +0000335#if CONFIG_PRINT_WIKI == 1
Carl-Daniel Hailfingera84835a2010-01-07 03:24:05 +0000336 if (list_supported_wiki) {
337 print_supported_wiki();
338 exit(0);
339 }
340#endif
341
Carl-Daniel Hailfinger71127722010-05-31 15:27:27 +0000342#if CONFIG_INTERNAL == 1
Carl-Daniel Hailfinger8841d3e2010-05-15 15:04:37 +0000343 if ((programmer != PROGRAMMER_INTERNAL) && (lb_part || lb_vendor)) {
344 fprintf(stderr, "Error: --mainboard requires the internal "
345 "programmer. Aborting.\n");
Uwe Hermann2db77a02010-06-04 17:07:39 +0000346 cli_classic_abort_usage();
Carl-Daniel Hailfingera84835a2010-01-07 03:24:05 +0000347 }
Carl-Daniel Hailfinger8841d3e2010-05-15 15:04:37 +0000348#endif
Carl-Daniel Hailfingera84835a2010-01-07 03:24:05 +0000349
Carl-Daniel Hailfinger27023762010-04-28 15:22:14 +0000350 if (chip_to_probe) {
351 for (flash = flashchips; flash && flash->name; flash++)
352 if (!strcmp(flash->name, chip_to_probe))
353 break;
354 if (!flash || !flash->name) {
355 fprintf(stderr, "Error: Unknown chip '%s' specified.\n",
356 chip_to_probe);
357 printf("Run flashrom -L to view the hardware supported "
358 "in this flashrom version.\n");
359 exit(1);
360 }
361 /* Clean up after the check. */
362 flash = NULL;
363 }
Carl-Daniel Hailfinger8841d3e2010-05-15 15:04:37 +0000364
Carl-Daniel Hailfinger49884202010-05-22 07:10:46 +0000365 /* FIXME: Delay calibration should happen in programmer code. */
366 myusec_calibrate_delay();
367
Carl-Daniel Hailfingerad3cc552010-07-03 11:02:10 +0000368 if (programmer_init(pparam)) {
Carl-Daniel Hailfingera84835a2010-01-07 03:24:05 +0000369 fprintf(stderr, "Error: Programmer initialization failed.\n");
Carl-Daniel Hailfingerd5660142011-07-15 23:47:45 +0000370 ret = 1;
371 goto out_shutdown;
Carl-Daniel Hailfingera84835a2010-01-07 03:24:05 +0000372 }
373
Carl-Daniel Hailfingera84835a2010-01-07 03:24:05 +0000374 for (i = 0; i < ARRAY_SIZE(flashes); i++) {
Carl-Daniel Hailfinger4c823182011-05-04 00:39:50 +0000375 startchip = probe_flash(startchip, &flashes[i], 0);
376 if (startchip == -1)
377 break;
378 chipcount++;
Carl-Daniel Hailfinger064bbc92011-05-07 19:19:36 +0000379 startchip++;
Carl-Daniel Hailfingera84835a2010-01-07 03:24:05 +0000380 }
381
Carl-Daniel Hailfinger4c823182011-05-04 00:39:50 +0000382 if (chipcount > 1) {
Stefan Tauner716e0982011-07-25 20:38:52 +0000383 printf("Multiple flash chips were detected: \"%s\"",
384 flashes[0].name);
385 for (i = 1; i < chipcount; i++)
386 printf(", \"%s\"", flashes[i].name);
Carl-Daniel Hailfingera84835a2010-01-07 03:24:05 +0000387 printf("\nPlease specify which chip to use with the -c <chipname> option.\n");
Carl-Daniel Hailfingerd5660142011-07-15 23:47:45 +0000388 ret = 1;
389 goto out_shutdown;
Carl-Daniel Hailfinger4c823182011-05-04 00:39:50 +0000390 } else if (!chipcount) {
Carl-Daniel Hailfingera84835a2010-01-07 03:24:05 +0000391 printf("No EEPROM/flash device found.\n");
392 if (!force || !chip_to_probe) {
Carl-Daniel Hailfinger27023762010-04-28 15:22:14 +0000393 printf("Note: flashrom can never write if the flash chip isn't found automatically.\n");
Carl-Daniel Hailfingera84835a2010-01-07 03:24:05 +0000394 }
395 if (force && read_it && chip_to_probe) {
Carl-Daniel Hailfinger27023762010-04-28 15:22:14 +0000396 printf("Force read (-f -r -c) requested, pretending the chip is there:\n");
Carl-Daniel Hailfinger4c823182011-05-04 00:39:50 +0000397 startchip = probe_flash(0, &flashes[0], 1);
398 if (startchip == -1) {
Carl-Daniel Hailfinger27023762010-04-28 15:22:14 +0000399 printf("Probing for flash chip '%s' failed.\n", chip_to_probe);
Carl-Daniel Hailfingerd5660142011-07-15 23:47:45 +0000400 ret = 1;
401 goto out_shutdown;
Carl-Daniel Hailfingera84835a2010-01-07 03:24:05 +0000402 }
403 printf("Please note that forced reads most likely contain garbage.\n");
Carl-Daniel Hailfinger4c823182011-05-04 00:39:50 +0000404 return read_flash_to_file(&flashes[0], filename);
Carl-Daniel Hailfingera84835a2010-01-07 03:24:05 +0000405 }
Carl-Daniel Hailfingerd5660142011-07-15 23:47:45 +0000406 ret = 1;
407 goto out_shutdown;
Carl-Daniel Hailfingera84835a2010-01-07 03:24:05 +0000408 }
409
Carl-Daniel Hailfinger4c823182011-05-04 00:39:50 +0000410 fill_flash = &flashes[0];
Carl-Daniel Hailfingera84835a2010-01-07 03:24:05 +0000411
Carl-Daniel Hailfinger4c823182011-05-04 00:39:50 +0000412 check_chip_supported(fill_flash);
Carl-Daniel Hailfingera84835a2010-01-07 03:24:05 +0000413
Carl-Daniel Hailfinger4c823182011-05-04 00:39:50 +0000414 size = fill_flash->total_size * 1024;
415 if (check_max_decode((buses_supported & fill_flash->bustype), size) &&
Carl-Daniel Hailfingera84835a2010-01-07 03:24:05 +0000416 (!force)) {
417 fprintf(stderr, "Chip is too big for this programmer "
418 "(-V gives details). Use --force to override.\n");
Carl-Daniel Hailfingerd5660142011-07-15 23:47:45 +0000419 ret = 1;
420 goto out_shutdown;
Carl-Daniel Hailfingera84835a2010-01-07 03:24:05 +0000421 }
422
423 if (!(read_it | write_it | verify_it | erase_it)) {
424 printf("No operations were specified.\n");
Carl-Daniel Hailfingerd5660142011-07-15 23:47:45 +0000425 goto out_shutdown;
Carl-Daniel Hailfingera84835a2010-01-07 03:24:05 +0000426 }
427
428 if (!filename && !erase_it) {
429 printf("Error: No filename specified.\n");
Carl-Daniel Hailfingerd5660142011-07-15 23:47:45 +0000430 ret = 1;
431 goto out_shutdown;
Carl-Daniel Hailfingera84835a2010-01-07 03:24:05 +0000432 }
433
434 /* Always verify write operations unless -n is used. */
435 if (write_it && !dont_verify_it)
436 verify_it = 1;
437
Carl-Daniel Hailfinger9ad42552010-09-15 10:20:16 +0000438 /* FIXME: We should issue an unconditional chip reset here. This can be
439 * done once we have a .reset function in struct flashchip.
440 * Give the chip time to settle.
441 */
442 programmer_delay(100000);
Carl-Daniel Hailfinger4c823182011-05-04 00:39:50 +0000443 return doit(fill_flash, force, filename, read_it, write_it, erase_it, verify_it);
Carl-Daniel Hailfingerd5660142011-07-15 23:47:45 +0000444
445out_shutdown:
446 programmer_shutdown();
447 return ret;
Carl-Daniel Hailfingera84835a2010-01-07 03:24:05 +0000448}