blob: 59096a02d0a0feb8e6697574efe36caf8160addc [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;
120
Mathias Krausea60faab2011-01-17 07:50:42 +0000121 static const char optstring[] = "r:Rw:v:nVEfc:m:l:i:p:Lzh";
122 static const struct option long_options[] = {
Peter Huewe73f8ec82011-01-24 19:15:51 +0000123 {"read", 1, NULL, 'r'},
124 {"write", 1, NULL, 'w'},
125 {"erase", 0, NULL, 'E'},
126 {"verify", 1, NULL, 'v'},
127 {"noverify", 0, NULL, 'n'},
128 {"chip", 1, NULL, 'c'},
129 {"mainboard", 1, NULL, 'm'},
130 {"verbose", 0, NULL, 'V'},
131 {"force", 0, NULL, 'f'},
132 {"layout", 1, NULL, 'l'},
133 {"image", 1, NULL, 'i'},
134 {"list-supported", 0, NULL, 'L'},
135 {"list-supported-wiki", 0, NULL, 'z'},
136 {"programmer", 1, NULL, 'p'},
137 {"help", 0, NULL, 'h'},
138 {"version", 0, NULL, 'R'},
139 {NULL, 0, NULL, 0}
Carl-Daniel Hailfingera84835a2010-01-07 03:24:05 +0000140 };
141
142 char *filename = NULL;
143
144 char *tempstr = NULL;
Carl-Daniel Hailfingerad3cc552010-07-03 11:02:10 +0000145 char *pparam = NULL;
Carl-Daniel Hailfingera84835a2010-01-07 03:24:05 +0000146
147 print_version();
Carl-Daniel Hailfinger8841d3e2010-05-15 15:04:37 +0000148 print_banner();
Carl-Daniel Hailfingera84835a2010-01-07 03:24:05 +0000149
150 if (selfcheck())
151 exit(1);
152
153 setbuf(stdout, NULL);
Carl-Daniel Hailfinger8841d3e2010-05-15 15:04:37 +0000154 /* FIXME: Delay all operation_specified checks until after command
155 * line parsing to allow --help overriding everything else.
156 */
Carl-Daniel Hailfingera84835a2010-01-07 03:24:05 +0000157 while ((opt = getopt_long(argc, argv, optstring,
158 long_options, &option_index)) != EOF) {
159 switch (opt) {
160 case 'r':
161 if (++operation_specified > 1) {
162 fprintf(stderr, "More than one operation "
163 "specified. Aborting.\n");
Uwe Hermann2db77a02010-06-04 17:07:39 +0000164 cli_classic_abort_usage();
Carl-Daniel Hailfingera84835a2010-01-07 03:24:05 +0000165 }
Carl-Daniel Hailfinger8841d3e2010-05-15 15:04:37 +0000166 filename = strdup(optarg);
Carl-Daniel Hailfingera84835a2010-01-07 03:24:05 +0000167 read_it = 1;
168 break;
169 case 'w':
170 if (++operation_specified > 1) {
171 fprintf(stderr, "More than one operation "
172 "specified. Aborting.\n");
Uwe Hermann2db77a02010-06-04 17:07:39 +0000173 cli_classic_abort_usage();
Carl-Daniel Hailfingera84835a2010-01-07 03:24:05 +0000174 }
Carl-Daniel Hailfinger8841d3e2010-05-15 15:04:37 +0000175 filename = strdup(optarg);
Carl-Daniel Hailfingera84835a2010-01-07 03:24:05 +0000176 write_it = 1;
177 break;
178 case 'v':
179 //FIXME: gracefully handle superfluous -v
180 if (++operation_specified > 1) {
181 fprintf(stderr, "More than one operation "
182 "specified. Aborting.\n");
Uwe Hermann2db77a02010-06-04 17:07:39 +0000183 cli_classic_abort_usage();
Carl-Daniel Hailfingera84835a2010-01-07 03:24:05 +0000184 }
185 if (dont_verify_it) {
186 fprintf(stderr, "--verify and --noverify are"
187 "mutually exclusive. Aborting.\n");
Uwe Hermann2db77a02010-06-04 17:07:39 +0000188 cli_classic_abort_usage();
Carl-Daniel Hailfingera84835a2010-01-07 03:24:05 +0000189 }
Carl-Daniel Hailfinger8841d3e2010-05-15 15:04:37 +0000190 filename = strdup(optarg);
Carl-Daniel Hailfingera84835a2010-01-07 03:24:05 +0000191 verify_it = 1;
192 break;
193 case 'n':
194 if (verify_it) {
195 fprintf(stderr, "--verify and --noverify are"
196 "mutually exclusive. Aborting.\n");
Uwe Hermann2db77a02010-06-04 17:07:39 +0000197 cli_classic_abort_usage();
Carl-Daniel Hailfingera84835a2010-01-07 03:24:05 +0000198 }
199 dont_verify_it = 1;
200 break;
201 case 'c':
202 chip_to_probe = strdup(optarg);
203 break;
204 case 'V':
Sean Nelson51e97d72010-01-07 20:09:33 +0000205 verbose++;
Carl-Daniel Hailfingera84835a2010-01-07 03:24:05 +0000206 break;
207 case 'E':
208 if (++operation_specified > 1) {
209 fprintf(stderr, "More than one operation "
210 "specified. Aborting.\n");
Uwe Hermann2db77a02010-06-04 17:07:39 +0000211 cli_classic_abort_usage();
Carl-Daniel Hailfingera84835a2010-01-07 03:24:05 +0000212 }
213 erase_it = 1;
214 break;
Carl-Daniel Hailfingera84835a2010-01-07 03:24:05 +0000215 case 'm':
Carl-Daniel Hailfinger71127722010-05-31 15:27:27 +0000216#if CONFIG_INTERNAL == 1
Carl-Daniel Hailfingera84835a2010-01-07 03:24:05 +0000217 tempstr = strdup(optarg);
218 lb_vendor_dev_from_string(tempstr);
Carl-Daniel Hailfinger8841d3e2010-05-15 15:04:37 +0000219#else
220 fprintf(stderr, "Error: Internal programmer support "
221 "was not compiled in and --mainboard only\n"
222 "applies to the internal programmer. Aborting.\n");
Uwe Hermann2db77a02010-06-04 17:07:39 +0000223 cli_classic_abort_usage();
Carl-Daniel Hailfingera84835a2010-01-07 03:24:05 +0000224#endif
Carl-Daniel Hailfinger8841d3e2010-05-15 15:04:37 +0000225 break;
Carl-Daniel Hailfingera84835a2010-01-07 03:24:05 +0000226 case 'f':
227 force = 1;
228 break;
229 case 'l':
230 tempstr = strdup(optarg);
231 if (read_romlayout(tempstr))
Uwe Hermann2db77a02010-06-04 17:07:39 +0000232 cli_classic_abort_usage();
Carl-Daniel Hailfingera84835a2010-01-07 03:24:05 +0000233 break;
234 case 'i':
235 tempstr = strdup(optarg);
236 find_romentry(tempstr);
237 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 Hailfinger8841d3e2010-05-15 15:04:37 +0000316 /* FIXME: Print the actions flashrom will take. */
317
Carl-Daniel Hailfingera84835a2010-01-07 03:24:05 +0000318 if (list_supported) {
319 print_supported();
320 exit(0);
321 }
322
Carl-Daniel Hailfinger71127722010-05-31 15:27:27 +0000323#if CONFIG_PRINT_WIKI == 1
Carl-Daniel Hailfingera84835a2010-01-07 03:24:05 +0000324 if (list_supported_wiki) {
325 print_supported_wiki();
326 exit(0);
327 }
328#endif
329
Carl-Daniel Hailfinger8841d3e2010-05-15 15:04:37 +0000330 if (optind < argc) {
331 fprintf(stderr, "Error: Extra parameter found.\n");
Uwe Hermann2db77a02010-06-04 17:07:39 +0000332 cli_classic_abort_usage();
Carl-Daniel Hailfingera84835a2010-01-07 03:24:05 +0000333 }
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 "
351 "in this flashrom version.\n");
352 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");
David Hendricks8bb20212011-06-14 01:35:36 +0000363 programmer_shutdown();
Carl-Daniel Hailfingera84835a2010-01-07 03:24:05 +0000364 exit(1);
365 }
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) {
Carl-Daniel Hailfingera84835a2010-01-07 03:24:05 +0000376 printf("Multiple flash chips were detected:");
Carl-Daniel Hailfinger4c823182011-05-04 00:39:50 +0000377 for (i = 0; i < chipcount; i++)
378 printf(" %s", flashes[i].name);
Carl-Daniel Hailfingera84835a2010-01-07 03:24:05 +0000379 printf("\nPlease specify which chip to use with the -c <chipname> option.\n");
380 programmer_shutdown();
381 exit(1);
Carl-Daniel Hailfinger4c823182011-05-04 00:39:50 +0000382 } else if (!chipcount) {
Carl-Daniel Hailfingera84835a2010-01-07 03:24:05 +0000383 printf("No EEPROM/flash device found.\n");
384 if (!force || !chip_to_probe) {
Carl-Daniel Hailfinger27023762010-04-28 15:22:14 +0000385 printf("Note: flashrom can never write if the flash chip isn't found automatically.\n");
Carl-Daniel Hailfingera84835a2010-01-07 03:24:05 +0000386 }
387 if (force && read_it && chip_to_probe) {
Carl-Daniel Hailfinger27023762010-04-28 15:22:14 +0000388 printf("Force read (-f -r -c) requested, pretending the chip is there:\n");
Carl-Daniel Hailfinger4c823182011-05-04 00:39:50 +0000389 startchip = probe_flash(0, &flashes[0], 1);
390 if (startchip == -1) {
Carl-Daniel Hailfinger27023762010-04-28 15:22:14 +0000391 printf("Probing for flash chip '%s' failed.\n", chip_to_probe);
392 programmer_shutdown();
Carl-Daniel Hailfingera84835a2010-01-07 03:24:05 +0000393 exit(1);
394 }
395 printf("Please note that forced reads most likely contain garbage.\n");
Carl-Daniel Hailfinger4c823182011-05-04 00:39:50 +0000396 return read_flash_to_file(&flashes[0], filename);
Carl-Daniel Hailfingera84835a2010-01-07 03:24:05 +0000397 }
398 // FIXME: flash writes stay enabled!
399 programmer_shutdown();
400 exit(1);
401 }
402
Carl-Daniel Hailfinger4c823182011-05-04 00:39:50 +0000403 fill_flash = &flashes[0];
Carl-Daniel Hailfingera84835a2010-01-07 03:24:05 +0000404
Carl-Daniel Hailfinger4c823182011-05-04 00:39:50 +0000405 check_chip_supported(fill_flash);
Carl-Daniel Hailfingera84835a2010-01-07 03:24:05 +0000406
Carl-Daniel Hailfinger4c823182011-05-04 00:39:50 +0000407 size = fill_flash->total_size * 1024;
408 if (check_max_decode((buses_supported & fill_flash->bustype), size) &&
Carl-Daniel Hailfingera84835a2010-01-07 03:24:05 +0000409 (!force)) {
410 fprintf(stderr, "Chip is too big for this programmer "
411 "(-V gives details). Use --force to override.\n");
412 programmer_shutdown();
413 return 1;
414 }
415
416 if (!(read_it | write_it | verify_it | erase_it)) {
417 printf("No operations were specified.\n");
418 // FIXME: flash writes stay enabled!
419 programmer_shutdown();
Carl-Daniel Hailfinger8841d3e2010-05-15 15:04:37 +0000420 exit(0);
Carl-Daniel Hailfingera84835a2010-01-07 03:24:05 +0000421 }
422
423 if (!filename && !erase_it) {
424 printf("Error: No filename specified.\n");
425 // FIXME: flash writes stay enabled!
426 programmer_shutdown();
427 exit(1);
428 }
429
430 /* Always verify write operations unless -n is used. */
431 if (write_it && !dont_verify_it)
432 verify_it = 1;
433
Carl-Daniel Hailfinger9ad42552010-09-15 10:20:16 +0000434 /* FIXME: We should issue an unconditional chip reset here. This can be
435 * done once we have a .reset function in struct flashchip.
436 * Give the chip time to settle.
437 */
438 programmer_delay(100000);
Carl-Daniel Hailfinger4c823182011-05-04 00:39:50 +0000439 return doit(fill_flash, force, filename, read_it, write_it, erase_it, verify_it);
Carl-Daniel Hailfingera84835a2010-01-07 03:24:05 +0000440}