blob: 03d3bd57c4e2d877f4af0ee58e79356213cb8a77 [file] [log] [blame]
Ronald G. Minnichf4cf2ba2002-01-29 18:26:26 +00001/*
Uwe Hermannd1107642007-08-29 17:52:32 +00002 * This file is part of the flashrom project.
Ronald G. Minnichf4cf2ba2002-01-29 18:26:26 +00003 *
Uwe Hermannd22a1d42007-09-09 20:21:05 +00004 * Copyright (C) 2000 Silicon Integrated System Corporation
5 * Copyright (C) 2004 Tyan Corp <yhlu@tyan.com>
Uwe Hermannc7e8a0c2009-05-19 14:14:21 +00006 * Copyright (C) 2005-2008 coresystems GmbH
Carl-Daniel Hailfinger03b4e712009-05-08 12:49:03 +00007 * Copyright (C) 2008,2009 Carl-Daniel Hailfinger
Ronald G. Minnichf4cf2ba2002-01-29 18:26:26 +00008 *
Uwe Hermannd1107642007-08-29 17:52:32 +00009 * 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.
Ronald G. Minnichf4cf2ba2002-01-29 18:26:26 +000013 *
Uwe Hermannd1107642007-08-29 17:52:32 +000014 * 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.
Ronald G. Minnichf4cf2ba2002-01-29 18:26:26 +000018 *
Uwe Hermannd1107642007-08-29 17:52:32 +000019 * 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
Ronald G. Minnichf4cf2ba2002-01-29 18:26:26 +000022 */
23
Ronald G. Minnichf4cf2ba2002-01-29 18:26:26 +000024#include <fcntl.h>
Stefan Reinauer018aca82006-11-21 23:48:51 +000025#include <sys/types.h>
26#include <sys/stat.h>
Ronald G. Minnichceec4202003-07-25 04:37:41 +000027#include <string.h>
Ronald G. Minnicheaab50b2003-09-12 22:41:53 +000028#include <stdlib.h>
Ollie Lho184a4042005-11-26 21:55:36 +000029#include <getopt.h>
Ronald G. Minnichf4cf2ba2002-01-29 18:26:26 +000030#include "flash.h"
Carl-Daniel Hailfinger08454642009-06-15 14:14:48 +000031#include "flashchips.h"
Ronald G. Minnichf4cf2ba2002-01-29 18:26:26 +000032
Carl-Daniel Hailfingera80cfbc2009-07-22 20:13:00 +000033const char *flashrom_version = FLASHROM_VERSION;
Ronald G. Minnichceec4202003-07-25 04:37:41 +000034char *chip_to_probe = NULL;
Peter Stuge7ffbc6f2008-06-18 02:08:40 +000035int verbose = 0;
Carl-Daniel Hailfinger66ef4e52009-12-13 22:28:00 +000036
37#if INTERNAL_SUPPORT == 1
Carl-Daniel Hailfinger415e5132009-08-12 11:39:29 +000038enum programmer programmer = PROGRAMMER_INTERNAL;
Carl-Daniel Hailfinger66ef4e52009-12-13 22:28:00 +000039#elif DUMMY_SUPPORT == 1
40enum programmer programmer = PROGRAMMER_DUMMY;
41#else
Carl-Daniel Hailfinger1a1415c2010-01-10 13:28:48 +000042/* If neither internal nor dummy are selected, we must pick a sensible default.
43 * Since there is no reason to prefer a particular external programmer, we fail
44 * if more than one of them is selected. If only one is selected, it is clear
45 * that the user wants that one to become the default.
46 */
Uwe Hermannddd5c9e2010-02-21 21:17:00 +000047#if NIC3COM_SUPPORT+GFXNVIDIA_SUPPORT+DRKAISER_SUPPORT+SATASII_SUPPORT+ATAHPT_SUPPORT+FT2232_SPI_SUPPORT+SERPROG_SUPPORT+BUSPIRATE_SPI_SUPPORT+DEDIPROG_SUPPORT > 1
Carl-Daniel Hailfinger1a1415c2010-01-10 13:28:48 +000048#error Please enable either CONFIG_DUMMY or CONFIG_INTERNAL or disable support for all external programmers except one.
49#endif
50enum programmer programmer =
51#if NIC3COM_SUPPORT == 1
52 PROGRAMMER_NIC3COM
53#endif
54#if GFXNVIDIA_SUPPORT == 1
55 PROGRAMMER_GFXNVIDIA
56#endif
57#if DRKAISER_SUPPORT == 1
58 PROGRAMMER_DRKAISER
59#endif
60#if SATASII_SUPPORT == 1
61 PROGRAMMER_SATASII
62#endif
Uwe Hermannddd5c9e2010-02-21 21:17:00 +000063#if ATAHPT_SUPPORT == 1
64 PROGRAMMER_ATAHPT
65#endif
Carl-Daniel Hailfinger1a1415c2010-01-10 13:28:48 +000066#if FT2232_SPI_SUPPORT == 1
67 PROGRAMMER_FT2232SPI
68#endif
69#if SERPROG_SUPPORT == 1
70 PROGRAMMER_SERPROG
71#endif
72#if BUSPIRATE_SPI_SUPPORT == 1
73 PROGRAMMER_BUSPIRATESPI
74#endif
Carl-Daniel Hailfingerd38fac82010-01-19 11:15:48 +000075#if DEDIPROG_SUPPORT == 1
76 PROGRAMMER_DEDIPROG
77#endif
Carl-Daniel Hailfinger1a1415c2010-01-10 13:28:48 +000078;
Carl-Daniel Hailfinger66ef4e52009-12-13 22:28:00 +000079#endif
80
Carl-Daniel Hailfingeref58a9c2009-08-12 13:32:56 +000081char *programmer_param = NULL;
Stefan Reinauer70385642007-04-06 11:58:03 +000082
Carl-Daniel Hailfinger66ef4e52009-12-13 22:28:00 +000083/**
84 * flashrom defaults to Parallel/LPC/FWH flash devices. If a known host
85 * controller is found, the init routine sets the buses_supported bitfield to
86 * contain the supported buses for that controller.
87 */
88enum chipbustype buses_supported = CHIP_BUSTYPE_NONSPI;
89
90/**
91 * Programmers supporting multiple buses can have differing size limits on
92 * each bus. Store the limits for each bus in a common struct.
93 */
94struct decode_sizes max_rom_decode = {
95 .parallel = 0xffffffff,
96 .lpc = 0xffffffff,
97 .fwh = 0xffffffff,
98 .spi = 0xffffffff
99};
100
Carl-Daniel Hailfinger702218d2009-05-08 17:43:22 +0000101const struct programmer_entry programmer_table[] = {
Carl-Daniel Hailfinger66ef4e52009-12-13 22:28:00 +0000102#if INTERNAL_SUPPORT == 1
Carl-Daniel Hailfinger702218d2009-05-08 17:43:22 +0000103 {
Carl-Daniel Hailfinger37fc4692009-08-12 14:34:35 +0000104 .name = "internal",
Carl-Daniel Hailfinger1e334e62009-05-11 15:46:43 +0000105 .init = internal_init,
106 .shutdown = internal_shutdown,
Carl-Daniel Hailfinger1455b2b2009-05-11 14:13:25 +0000107 .map_flash_region = physmap,
108 .unmap_flash_region = physunmap,
Carl-Daniel Hailfinger1e334e62009-05-11 15:46:43 +0000109 .chip_readb = internal_chip_readb,
110 .chip_readw = internal_chip_readw,
111 .chip_readl = internal_chip_readl,
Carl-Daniel Hailfinger0bd2a2b2009-06-05 18:32:07 +0000112 .chip_readn = internal_chip_readn,
Carl-Daniel Hailfinger1e334e62009-05-11 15:46:43 +0000113 .chip_writeb = internal_chip_writeb,
114 .chip_writew = internal_chip_writew,
115 .chip_writel = internal_chip_writel,
Carl-Daniel Hailfinger0bd2a2b2009-06-05 18:32:07 +0000116 .chip_writen = fallback_chip_writen,
Carl-Daniel Hailfingerca8bfc62009-06-05 17:48:08 +0000117 .delay = internal_delay,
Carl-Daniel Hailfinger702218d2009-05-08 17:43:22 +0000118 },
Carl-Daniel Hailfinger66ef4e52009-12-13 22:28:00 +0000119#endif
Luc Verhaegen8e3a6002007-04-04 22:45:58 +0000120
Carl-Daniel Hailfinger4740c6f2009-09-16 10:09:21 +0000121#if DUMMY_SUPPORT == 1
Carl-Daniel Hailfingerc3129202009-05-09 00:54:55 +0000122 {
Carl-Daniel Hailfinger37fc4692009-08-12 14:34:35 +0000123 .name = "dummy",
Carl-Daniel Hailfinger1e334e62009-05-11 15:46:43 +0000124 .init = dummy_init,
125 .shutdown = dummy_shutdown,
Carl-Daniel Hailfinger1455b2b2009-05-11 14:13:25 +0000126 .map_flash_region = dummy_map,
127 .unmap_flash_region = dummy_unmap,
Carl-Daniel Hailfinger1e334e62009-05-11 15:46:43 +0000128 .chip_readb = dummy_chip_readb,
129 .chip_readw = dummy_chip_readw,
130 .chip_readl = dummy_chip_readl,
Carl-Daniel Hailfinger0bd2a2b2009-06-05 18:32:07 +0000131 .chip_readn = dummy_chip_readn,
Carl-Daniel Hailfinger1e334e62009-05-11 15:46:43 +0000132 .chip_writeb = dummy_chip_writeb,
133 .chip_writew = dummy_chip_writew,
134 .chip_writel = dummy_chip_writel,
Carl-Daniel Hailfinger0bd2a2b2009-06-05 18:32:07 +0000135 .chip_writen = dummy_chip_writen,
Carl-Daniel Hailfingerca8bfc62009-06-05 17:48:08 +0000136 .delay = internal_delay,
Carl-Daniel Hailfingerc3129202009-05-09 00:54:55 +0000137 },
Carl-Daniel Hailfinger4740c6f2009-09-16 10:09:21 +0000138#endif
Carl-Daniel Hailfingerc3129202009-05-09 00:54:55 +0000139
Carl-Daniel Hailfinger4740c6f2009-09-16 10:09:21 +0000140#if NIC3COM_SUPPORT == 1
Uwe Hermannb4dcb712009-05-13 11:36:06 +0000141 {
Carl-Daniel Hailfinger37fc4692009-08-12 14:34:35 +0000142 .name = "nic3com",
Uwe Hermannb4dcb712009-05-13 11:36:06 +0000143 .init = nic3com_init,
144 .shutdown = nic3com_shutdown,
Uwe Hermannc6915932009-05-17 23:12:17 +0000145 .map_flash_region = fallback_map,
146 .unmap_flash_region = fallback_unmap,
Uwe Hermannb4dcb712009-05-13 11:36:06 +0000147 .chip_readb = nic3com_chip_readb,
Carl-Daniel Hailfinger9ee10772009-05-16 01:23:55 +0000148 .chip_readw = fallback_chip_readw,
149 .chip_readl = fallback_chip_readl,
Carl-Daniel Hailfinger0bd2a2b2009-06-05 18:32:07 +0000150 .chip_readn = fallback_chip_readn,
Uwe Hermannb4dcb712009-05-13 11:36:06 +0000151 .chip_writeb = nic3com_chip_writeb,
Carl-Daniel Hailfinger9ee10772009-05-16 01:23:55 +0000152 .chip_writew = fallback_chip_writew,
153 .chip_writel = fallback_chip_writel,
Carl-Daniel Hailfinger0bd2a2b2009-06-05 18:32:07 +0000154 .chip_writen = fallback_chip_writen,
Carl-Daniel Hailfingerca8bfc62009-06-05 17:48:08 +0000155 .delay = internal_delay,
Uwe Hermannb4dcb712009-05-13 11:36:06 +0000156 },
Carl-Daniel Hailfinger4740c6f2009-09-16 10:09:21 +0000157#endif
Uwe Hermannb4dcb712009-05-13 11:36:06 +0000158
Uwe Hermann2bc98f62009-09-30 18:29:55 +0000159#if GFXNVIDIA_SUPPORT == 1
160 {
161 .name = "gfxnvidia",
162 .init = gfxnvidia_init,
163 .shutdown = gfxnvidia_shutdown,
164 .map_flash_region = fallback_map,
165 .unmap_flash_region = fallback_unmap,
166 .chip_readb = gfxnvidia_chip_readb,
167 .chip_readw = fallback_chip_readw,
168 .chip_readl = fallback_chip_readl,
169 .chip_readn = fallback_chip_readn,
170 .chip_writeb = gfxnvidia_chip_writeb,
171 .chip_writew = fallback_chip_writew,
172 .chip_writel = fallback_chip_writel,
173 .chip_writen = fallback_chip_writen,
174 .delay = internal_delay,
175 },
176#endif
177
Carl-Daniel Hailfinger4740c6f2009-09-16 10:09:21 +0000178#if DRKAISER_SUPPORT == 1
Rudolf Marek68720c72009-05-17 19:39:27 +0000179 {
TURBO Jb0912c02009-09-02 23:00:46 +0000180 .name = "drkaiser",
181 .init = drkaiser_init,
182 .shutdown = drkaiser_shutdown,
183 .map_flash_region = fallback_map,
184 .unmap_flash_region = fallback_unmap,
185 .chip_readb = drkaiser_chip_readb,
186 .chip_readw = fallback_chip_readw,
187 .chip_readl = fallback_chip_readl,
188 .chip_readn = fallback_chip_readn,
189 .chip_writeb = drkaiser_chip_writeb,
190 .chip_writew = fallback_chip_writew,
191 .chip_writel = fallback_chip_writel,
192 .chip_writen = fallback_chip_writen,
193 .delay = internal_delay,
194 },
Carl-Daniel Hailfinger4740c6f2009-09-16 10:09:21 +0000195#endif
TURBO Jb0912c02009-09-02 23:00:46 +0000196
Carl-Daniel Hailfinger4740c6f2009-09-16 10:09:21 +0000197#if SATASII_SUPPORT == 1
TURBO Jb0912c02009-09-02 23:00:46 +0000198 {
Carl-Daniel Hailfinger37fc4692009-08-12 14:34:35 +0000199 .name = "satasii",
Rudolf Marek68720c72009-05-17 19:39:27 +0000200 .init = satasii_init,
201 .shutdown = satasii_shutdown,
Uwe Hermannc6915932009-05-17 23:12:17 +0000202 .map_flash_region = fallback_map,
203 .unmap_flash_region = fallback_unmap,
Rudolf Marek68720c72009-05-17 19:39:27 +0000204 .chip_readb = satasii_chip_readb,
205 .chip_readw = fallback_chip_readw,
206 .chip_readl = fallback_chip_readl,
Carl-Daniel Hailfinger0bd2a2b2009-06-05 18:32:07 +0000207 .chip_readn = fallback_chip_readn,
Rudolf Marek68720c72009-05-17 19:39:27 +0000208 .chip_writeb = satasii_chip_writeb,
209 .chip_writew = fallback_chip_writew,
210 .chip_writel = fallback_chip_writel,
Carl-Daniel Hailfinger0bd2a2b2009-06-05 18:32:07 +0000211 .chip_writen = fallback_chip_writen,
Carl-Daniel Hailfingerca8bfc62009-06-05 17:48:08 +0000212 .delay = internal_delay,
Rudolf Marek68720c72009-05-17 19:39:27 +0000213 },
Carl-Daniel Hailfinger4740c6f2009-09-16 10:09:21 +0000214#endif
Rudolf Marek68720c72009-05-17 19:39:27 +0000215
Uwe Hermannddd5c9e2010-02-21 21:17:00 +0000216#if ATAHPT_SUPPORT == 1
217 {
218 .name = "atahpt",
219 .init = atahpt_init,
220 .shutdown = atahpt_shutdown,
221 .map_flash_region = fallback_map,
222 .unmap_flash_region = fallback_unmap,
223 .chip_readb = atahpt_chip_readb,
224 .chip_readw = fallback_chip_readw,
225 .chip_readl = fallback_chip_readl,
226 .chip_readn = fallback_chip_readn,
227 .chip_writeb = atahpt_chip_writeb,
228 .chip_writew = fallback_chip_writew,
229 .chip_writel = fallback_chip_writel,
230 .chip_writen = fallback_chip_writen,
231 .delay = internal_delay,
232 },
233#endif
234
Carl-Daniel Hailfinger66ef4e52009-12-13 22:28:00 +0000235#if INTERNAL_SUPPORT == 1
Carl-Daniel Hailfingerb8afecd2009-05-31 18:00:57 +0000236 {
Carl-Daniel Hailfinger37fc4692009-08-12 14:34:35 +0000237 .name = "it87spi",
Carl-Daniel Hailfingerb8afecd2009-05-31 18:00:57 +0000238 .init = it87spi_init,
Carl-Daniel Hailfinger4740c6f2009-09-16 10:09:21 +0000239 .shutdown = noop_shutdown,
Carl-Daniel Hailfinger415e5132009-08-12 11:39:29 +0000240 .map_flash_region = fallback_map,
241 .unmap_flash_region = fallback_unmap,
Carl-Daniel Hailfinger4740c6f2009-09-16 10:09:21 +0000242 .chip_readb = noop_chip_readb,
Carl-Daniel Hailfinger0bd2a2b2009-06-05 18:32:07 +0000243 .chip_readw = fallback_chip_readw,
244 .chip_readl = fallback_chip_readl,
245 .chip_readn = fallback_chip_readn,
Carl-Daniel Hailfinger4740c6f2009-09-16 10:09:21 +0000246 .chip_writeb = noop_chip_writeb,
Carl-Daniel Hailfinger0bd2a2b2009-06-05 18:32:07 +0000247 .chip_writew = fallback_chip_writew,
248 .chip_writel = fallback_chip_writel,
249 .chip_writen = fallback_chip_writen,
Carl-Daniel Hailfingerca8bfc62009-06-05 17:48:08 +0000250 .delay = internal_delay,
Carl-Daniel Hailfingerb8afecd2009-05-31 18:00:57 +0000251 },
Carl-Daniel Hailfinger66ef4e52009-12-13 22:28:00 +0000252#endif
Carl-Daniel Hailfingerb8afecd2009-05-31 18:00:57 +0000253
Carl-Daniel Hailfinger3426ef62009-08-19 13:27:58 +0000254#if FT2232_SPI_SUPPORT == 1
Paul Fox05dfbe62009-06-16 21:08:06 +0000255 {
Carl-Daniel Hailfinger37fc4692009-08-12 14:34:35 +0000256 .name = "ft2232spi",
Paul Fox05dfbe62009-06-16 21:08:06 +0000257 .init = ft2232_spi_init,
Carl-Daniel Hailfinger4740c6f2009-09-16 10:09:21 +0000258 .shutdown = noop_shutdown, /* Missing shutdown */
Carl-Daniel Hailfinger415e5132009-08-12 11:39:29 +0000259 .map_flash_region = fallback_map,
260 .unmap_flash_region = fallback_unmap,
Carl-Daniel Hailfinger4740c6f2009-09-16 10:09:21 +0000261 .chip_readb = noop_chip_readb,
Paul Fox05dfbe62009-06-16 21:08:06 +0000262 .chip_readw = fallback_chip_readw,
263 .chip_readl = fallback_chip_readl,
264 .chip_readn = fallback_chip_readn,
Carl-Daniel Hailfinger4740c6f2009-09-16 10:09:21 +0000265 .chip_writeb = noop_chip_writeb,
Paul Fox05dfbe62009-06-16 21:08:06 +0000266 .chip_writew = fallback_chip_writew,
267 .chip_writel = fallback_chip_writel,
268 .chip_writen = fallback_chip_writen,
269 .delay = internal_delay,
270 },
Carl-Daniel Hailfinger3426ef62009-08-19 13:27:58 +0000271#endif
Carl-Daniel Hailfinger415e5132009-08-12 11:39:29 +0000272
Carl-Daniel Hailfinger6be74112009-08-12 16:17:41 +0000273#if SERPROG_SUPPORT == 1
Urja Rannikko22915352009-06-23 11:33:43 +0000274 {
Carl-Daniel Hailfinger37fc4692009-08-12 14:34:35 +0000275 .name = "serprog",
Urja Rannikko22915352009-06-23 11:33:43 +0000276 .init = serprog_init,
277 .shutdown = serprog_shutdown,
278 .map_flash_region = fallback_map,
279 .unmap_flash_region = fallback_unmap,
280 .chip_readb = serprog_chip_readb,
281 .chip_readw = fallback_chip_readw,
282 .chip_readl = fallback_chip_readl,
283 .chip_readn = serprog_chip_readn,
284 .chip_writeb = serprog_chip_writeb,
285 .chip_writew = fallback_chip_writew,
286 .chip_writel = fallback_chip_writel,
287 .chip_writen = fallback_chip_writen,
288 .delay = serprog_delay,
289 },
Carl-Daniel Hailfinger6be74112009-08-12 16:17:41 +0000290#endif
Paul Fox05dfbe62009-06-16 21:08:06 +0000291
Carl-Daniel Hailfinger5cca01f2009-11-24 00:20:03 +0000292#if BUSPIRATE_SPI_SUPPORT == 1
293 {
294 .name = "buspiratespi",
295 .init = buspirate_spi_init,
296 .shutdown = buspirate_spi_shutdown,
297 .map_flash_region = fallback_map,
298 .unmap_flash_region = fallback_unmap,
299 .chip_readb = noop_chip_readb,
300 .chip_readw = fallback_chip_readw,
301 .chip_readl = fallback_chip_readl,
302 .chip_readn = fallback_chip_readn,
303 .chip_writeb = noop_chip_writeb,
304 .chip_writew = fallback_chip_writew,
305 .chip_writel = fallback_chip_writel,
306 .chip_writen = fallback_chip_writen,
307 .delay = internal_delay,
308 },
309#endif
310
Carl-Daniel Hailfingerd38fac82010-01-19 11:15:48 +0000311#if DEDIPROG_SUPPORT == 1
312 {
313 .name = "dediprog",
314 .init = dediprog_init,
315 .shutdown = dediprog_shutdown,
316 .map_flash_region = fallback_map,
317 .unmap_flash_region = fallback_unmap,
318 .chip_readb = noop_chip_readb,
319 .chip_readw = fallback_chip_readw,
320 .chip_readl = fallback_chip_readl,
321 .chip_readn = fallback_chip_readn,
322 .chip_writeb = noop_chip_writeb,
323 .chip_writew = fallback_chip_writew,
324 .chip_writel = fallback_chip_writel,
325 .chip_writen = fallback_chip_writen,
326 .delay = internal_delay,
327 },
328#endif
329
Carl-Daniel Hailfinger37fc4692009-08-12 14:34:35 +0000330 {}, /* This entry corresponds to PROGRAMMER_INVALID. */
Carl-Daniel Hailfinger702218d2009-05-08 17:43:22 +0000331};
Luc Verhaegen8e3a6002007-04-04 22:45:58 +0000332
Carl-Daniel Hailfingercc389fc2010-02-14 01:20:28 +0000333#define SHUTDOWN_MAXFN 4
334static int shutdown_fn_count = 0;
335struct shutdown_func_data {
336 void (*func) (void *data);
337 void *data;
338} shutdown_fn[SHUTDOWN_MAXFN];
339
340/* Register a function to be executed on programmer shutdown.
341 * The advantage over atexit() is that you can supply a void pointer which will
342 * be used as parameter to the registered function upon programmer shutdown.
343 * This pointer can point to arbitrary data used by said function, e.g. undo
344 * information for GPIO settings etc. If unneeded, set data=NULL.
345 * Please note that the first (void *data) belongs to the function signature of
346 * the function passed as first parameter.
347 */
348int register_shutdown(void (*function) (void *data), void *data)
349{
350 if (shutdown_fn_count >= SHUTDOWN_MAXFN) {
351 msg_perr("Tried to register more than %n shutdown functions.\n",
352 SHUTDOWN_MAXFN);
353 return 1;
354 }
355 shutdown_fn[shutdown_fn_count].func = function;
356 shutdown_fn[shutdown_fn_count].data = data;
357 shutdown_fn_count++;
358
359 return 0;
360}
361
Uwe Hermann09e04f72009-05-16 22:36:00 +0000362int programmer_init(void)
363{
364 return programmer_table[programmer].init();
365}
366
367int programmer_shutdown(void)
368{
Carl-Daniel Hailfingercc389fc2010-02-14 01:20:28 +0000369 int i;
370
371 for (i = shutdown_fn_count - 1; i >= 0; i--)
372 shutdown_fn[i].func(shutdown_fn[i].data);
Uwe Hermann09e04f72009-05-16 22:36:00 +0000373 return programmer_table[programmer].shutdown();
374}
375
376void *programmer_map_flash_region(const char *descr, unsigned long phys_addr,
377 size_t len)
378{
379 return programmer_table[programmer].map_flash_region(descr,
380 phys_addr, len);
381}
382
383void programmer_unmap_flash_region(void *virt_addr, size_t len)
384{
385 programmer_table[programmer].unmap_flash_region(virt_addr, len);
386}
387
388void chip_writeb(uint8_t val, chipaddr addr)
389{
390 programmer_table[programmer].chip_writeb(val, addr);
391}
392
393void chip_writew(uint16_t val, chipaddr addr)
394{
395 programmer_table[programmer].chip_writew(val, addr);
396}
397
398void chip_writel(uint32_t val, chipaddr addr)
399{
400 programmer_table[programmer].chip_writel(val, addr);
401}
402
Carl-Daniel Hailfinger0bd2a2b2009-06-05 18:32:07 +0000403void chip_writen(uint8_t *buf, chipaddr addr, size_t len)
404{
405 programmer_table[programmer].chip_writen(buf, addr, len);
406}
407
Uwe Hermann09e04f72009-05-16 22:36:00 +0000408uint8_t chip_readb(const chipaddr addr)
409{
410 return programmer_table[programmer].chip_readb(addr);
411}
412
413uint16_t chip_readw(const chipaddr addr)
414{
415 return programmer_table[programmer].chip_readw(addr);
416}
417
418uint32_t chip_readl(const chipaddr addr)
419{
420 return programmer_table[programmer].chip_readl(addr);
421}
422
Carl-Daniel Hailfinger0bd2a2b2009-06-05 18:32:07 +0000423void chip_readn(uint8_t *buf, chipaddr addr, size_t len)
424{
425 programmer_table[programmer].chip_readn(buf, addr, len);
Carl-Daniel Hailfinger0bd2a2b2009-06-05 18:32:07 +0000426}
427
Carl-Daniel Hailfingerca8bfc62009-06-05 17:48:08 +0000428void programmer_delay(int usecs)
429{
430 programmer_table[programmer].delay(usecs);
431}
432
Peter Stuge776d2022009-01-26 00:39:57 +0000433void map_flash_registers(struct flashchip *flash)
Stefan Reinauerff4f1972007-05-24 08:48:10 +0000434{
Stefan Reinauerff4f1972007-05-24 08:48:10 +0000435 size_t size = flash->total_size * 1024;
Carl-Daniel Hailfingerd0fc9462009-05-11 14:01:17 +0000436 /* Flash registers live 4 MByte below the flash. */
Carl-Daniel Hailfinger8ab49e72009-08-19 13:55:34 +0000437 /* FIXME: This is incorrect for nonstandard flashbase. */
Carl-Daniel Hailfinger5820f422009-05-16 21:22:56 +0000438 flash->virtual_registers = (chipaddr)programmer_map_flash_region("flash chip registers", (0xFFFFFFFF - 0x400000 - size + 1), size);
Stefan Reinauerff4f1972007-05-24 08:48:10 +0000439}
440
Carl-Daniel Hailfingercbf563c2009-06-16 08:55:44 +0000441int read_memmapped(struct flashchip *flash, uint8_t *buf, int start, int len)
Carl-Daniel Hailfinger03b4e712009-05-08 12:49:03 +0000442{
Carl-Daniel Hailfingercbf563c2009-06-16 08:55:44 +0000443 chip_readn(buf, flash->virtual_memory + start, len);
Carl-Daniel Hailfinger03b4e712009-05-08 12:49:03 +0000444
445 return 0;
446}
447
Carl-Daniel Hailfinger66ef4e52009-12-13 22:28:00 +0000448unsigned long flashbase = 0;
449
Carl-Daniel Hailfinger38a059d2009-06-13 12:04:03 +0000450int min(int a, int b)
451{
452 return (a < b) ? a : b;
453}
454
Carl-Daniel Hailfinger30f7cb22009-06-15 17:23:36 +0000455int max(int a, int b)
456{
457 return (a > b) ? a : b;
458}
459
Carl-Daniel Hailfinger115d3902009-10-31 01:53:09 +0000460int bitcount(unsigned long a)
461{
462 int i = 0;
463 for (; a != 0; a >>= 1)
464 if (a & 1)
465 i++;
466 return i;
467}
468
Carl-Daniel Hailfingerb22918c2009-06-01 02:08:58 +0000469char *strcat_realloc(char *dest, const char *src)
470{
471 dest = realloc(dest, strlen(dest) + strlen(src) + 1);
472 if (!dest)
473 return NULL;
474 strcat(dest, src);
475 return dest;
476}
477
Carl-Daniel Hailfingerd5b28fa2009-11-24 18:27:10 +0000478/* This is a somewhat hacked function similar in some ways to strtok().
479 * It will look for needle in haystack, return a copy of needle and remove
480 * everything from the first occurrence of needle to the next delimiter
481 * from haystack.
482 */
483char *extract_param(char **haystack, char *needle, char *delim)
484{
485 char *param_pos, *rest, *tmp;
486 char *dev = NULL;
487 int devlen;
488
489 param_pos = strstr(*haystack, needle);
490 do {
491 if (!param_pos)
492 return NULL;
493 /* Beginning of the string? */
494 if (param_pos == *haystack)
495 break;
496 /* After a delimiter? */
497 if (strchr(delim, *(param_pos - 1)))
498 break;
499 /* Continue searching. */
500 param_pos++;
501 param_pos = strstr(param_pos, needle);
502 } while (1);
503
504 if (param_pos) {
505 param_pos += strlen(needle);
506 devlen = strcspn(param_pos, delim);
507 if (devlen) {
508 dev = malloc(devlen + 1);
509 if (!dev) {
510 fprintf(stderr, "Out of memory!\n");
511 exit(1);
512 }
513 strncpy(dev, param_pos, devlen);
514 dev[devlen] = '\0';
515 }
516 rest = param_pos + devlen;
517 rest += strspn(rest, delim);
518 param_pos -= strlen(needle);
519 memmove(param_pos, rest, strlen(rest) + 1);
520 tmp = realloc(*haystack, strlen(*haystack) + 1);
521 if (!tmp) {
522 fprintf(stderr, "Out of memory!\n");
523 exit(1);
524 }
525 *haystack = tmp;
526 }
527
528
529 return dev;
530}
531
Carl-Daniel Hailfinger30f7cb22009-06-15 17:23:36 +0000532/* start is an offset to the base address of the flash chip */
533int check_erased_range(struct flashchip *flash, int start, int len)
534{
535 int ret;
536 uint8_t *cmpbuf = malloc(len);
537
538 if (!cmpbuf) {
539 fprintf(stderr, "Could not allocate memory!\n");
540 exit(1);
541 }
542 memset(cmpbuf, 0xff, len);
543 ret = verify_range(flash, cmpbuf, start, len, "ERASE");
544 free(cmpbuf);
545 return ret;
546}
547
548/**
Carl-Daniel Hailfingerd0250a32009-11-25 17:05:52 +0000549 * @cmpbuf buffer to compare against, cmpbuf[0] is expected to match the
550 flash content at location start
Carl-Daniel Hailfinger30f7cb22009-06-15 17:23:36 +0000551 * @start offset to the base address of the flash chip
552 * @len length of the verified area
553 * @message string to print in the "FAILED" message
554 * @return 0 for success, -1 for failure
555 */
556int verify_range(struct flashchip *flash, uint8_t *cmpbuf, int start, int len, char *message)
557{
558 int i, j, starthere, lenhere, ret = 0;
Carl-Daniel Hailfinger30f7cb22009-06-15 17:23:36 +0000559 int page_size = flash->page_size;
560 uint8_t *readbuf = malloc(page_size);
Carl-Daniel Hailfinger49b9cab2009-07-23 01:42:56 +0000561 int failcount = 0;
Carl-Daniel Hailfinger30f7cb22009-06-15 17:23:36 +0000562
563 if (!len)
564 goto out_free;
565
Carl-Daniel Hailfinger23290662009-06-24 08:20:45 +0000566 if (!flash->read) {
567 fprintf(stderr, "ERROR: flashrom has no read function for this flash chip.\n");
568 return 1;
569 }
Carl-Daniel Hailfinger30f7cb22009-06-15 17:23:36 +0000570 if (!readbuf) {
571 fprintf(stderr, "Could not allocate memory!\n");
572 exit(1);
573 }
574
575 if (start + len > flash->total_size * 1024) {
576 fprintf(stderr, "Error: %s called with start 0x%x + len 0x%x >"
577 " total_size 0x%x\n", __func__, start, len,
578 flash->total_size * 1024);
579 ret = -1;
580 goto out_free;
581 }
582 if (!message)
583 message = "VERIFY";
584
585 /* Warning: This loop has a very unusual condition and body.
586 * The loop needs to go through each page with at least one affected
587 * byte. The lowest page number is (start / page_size) since that
588 * division rounds down. The highest page number we want is the page
589 * where the last byte of the range lives. That last byte has the
590 * address (start + len - 1), thus the highest page number is
591 * (start + len - 1) / page_size. Since we want to include that last
592 * page as well, the loop condition uses <=.
593 */
594 for (i = start / page_size; i <= (start + len - 1) / page_size; i++) {
595 /* Byte position of the first byte in the range in this page. */
596 starthere = max(start, i * page_size);
597 /* Length of bytes in the range in this page. */
598 lenhere = min(start + len, (i + 1) * page_size) - starthere;
Carl-Daniel Hailfinger23290662009-06-24 08:20:45 +0000599 flash->read(flash, readbuf, starthere, lenhere);
Carl-Daniel Hailfinger30f7cb22009-06-15 17:23:36 +0000600 for (j = 0; j < lenhere; j++) {
601 if (cmpbuf[starthere - start + j] != readbuf[j]) {
Carl-Daniel Hailfinger49b9cab2009-07-23 01:42:56 +0000602 /* Only print the first failure. */
603 if (!failcount++)
604 fprintf(stderr, "%s FAILED at 0x%08x! "
605 "Expected=0x%02x, Read=0x%02x,",
606 message, starthere + j,
607 cmpbuf[starthere - start + j],
608 readbuf[j]);
Carl-Daniel Hailfinger30f7cb22009-06-15 17:23:36 +0000609 }
610 }
611 }
Carl-Daniel Hailfinger49b9cab2009-07-23 01:42:56 +0000612 if (failcount) {
613 fprintf(stderr, " failed byte count from 0x%08x-0x%08x: 0x%x\n",
614 start, start + len - 1, failcount);
615 ret = -1;
616 }
Carl-Daniel Hailfinger30f7cb22009-06-15 17:23:36 +0000617
618out_free:
619 free(readbuf);
620 return ret;
621}
622
Carl-Daniel Hailfingereaac68b2009-11-23 12:55:31 +0000623/* This function generates various test patterns useful for testing controller
624 * and chip communication as well as chip behaviour.
625 *
626 * If a byte can be written multiple times, each time keeping 0-bits at 0
627 * and changing 1-bits to 0 if the new value for that bit is 0, the effect
628 * is essentially an AND operation. That's also the reason why this function
629 * provides the result of AND between various patterns.
630 *
631 * Below is a list of patterns (and their block length).
632 * Pattern 0 is 05 15 25 35 45 55 65 75 85 95 a5 b5 c5 d5 e5 f5 (16 Bytes)
633 * Pattern 1 is 0a 1a 2a 3a 4a 5a 6a 7a 8a 9a aa ba ca da ea fa (16 Bytes)
634 * Pattern 2 is 50 51 52 53 54 55 56 57 58 59 5a 5b 5c 5d 5e 5f (16 Bytes)
635 * Pattern 3 is a0 a1 a2 a3 a4 a5 a6 a7 a8 a9 aa ab ac ad ae af (16 Bytes)
636 * Pattern 4 is 00 10 20 30 40 50 60 70 80 90 a0 b0 c0 d0 e0 f0 (16 Bytes)
637 * Pattern 5 is 00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f (16 Bytes)
638 * Pattern 6 is 00 (1 Byte)
639 * Pattern 7 is ff (1 Byte)
640 * Patterns 0-7 have a big-endian block number in the last 2 bytes of each 256
641 * byte block.
642 *
643 * Pattern 8 is 00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f 10 11... (256 B)
644 * Pattern 9 is ff fe fd fc fb fa f9 f8 f7 f6 f5 f4 f3 f2 f1 f0 ef ee... (256 B)
645 * Pattern 10 is 00 00 00 01 00 02 00 03 00 04... (128 kB big-endian counter)
646 * Pattern 11 is ff ff ff fe ff fd ff fc ff fb... (128 kB big-endian downwards)
647 * Pattern 12 is 00 (1 Byte)
648 * Pattern 13 is ff (1 Byte)
649 * Patterns 8-13 have no block number.
650 *
651 * Patterns 0-3 are created to detect and efficiently diagnose communication
652 * slips like missed bits or bytes and their repetitive nature gives good visual
653 * cues to the person inspecting the results. In addition, the following holds:
654 * AND Pattern 0/1 == Pattern 4
655 * AND Pattern 2/3 == Pattern 5
656 * AND Pattern 0/1/2/3 == AND Pattern 4/5 == Pattern 6
657 * A weakness of pattern 0-5 is the inability to detect swaps/copies between
658 * any two 16-byte blocks except for the last 16-byte block in a 256-byte bloc.
659 * They work perfectly for detecting any swaps/aliasing of blocks >= 256 bytes.
660 * 0x5 and 0xa were picked because they are 0101 and 1010 binary.
661 * Patterns 8-9 are best for detecting swaps/aliasing of blocks < 256 bytes.
662 * Besides that, they provide for bit testing of the last two bytes of every
663 * 256 byte block which contains the block number for patterns 0-6.
664 * Patterns 10-11 are special purpose for detecting subblock aliasing with
665 * block sizes >256 bytes (some Dataflash chips etc.)
666 * AND Pattern 8/9 == Pattern 12
667 * AND Pattern 10/11 == Pattern 12
668 * Pattern 13 is the completely erased state.
669 * None of the patterns can detect aliasing at boundaries which are a multiple
670 * of 16 MBytes (but such chips do not exist anyway for Parallel/LPC/FWH/SPI).
671 */
672int generate_testpattern(uint8_t *buf, uint32_t size, int variant)
673{
674 int i;
675
676 if (!buf) {
677 fprintf(stderr, "Invalid buffer!\n");
678 return 1;
679 }
680
681 switch (variant) {
682 case 0:
683 for (i = 0; i < size; i++)
684 buf[i] = (i & 0xf) << 4 | 0x5;
685 break;
686 case 1:
687 for (i = 0; i < size; i++)
688 buf[i] = (i & 0xf) << 4 | 0xa;
689 break;
690 case 2:
691 for (i = 0; i < size; i++)
692 buf[i] = 0x50 | (i & 0xf);
693 break;
694 case 3:
695 for (i = 0; i < size; i++)
696 buf[i] = 0xa0 | (i & 0xf);
697 break;
698 case 4:
699 for (i = 0; i < size; i++)
700 buf[i] = (i & 0xf) << 4;
701 break;
702 case 5:
703 for (i = 0; i < size; i++)
704 buf[i] = i & 0xf;
705 break;
706 case 6:
707 memset(buf, 0x00, size);
708 break;
709 case 7:
710 memset(buf, 0xff, size);
711 break;
712 case 8:
713 for (i = 0; i < size; i++)
714 buf[i] = i & 0xff;
715 break;
716 case 9:
717 for (i = 0; i < size; i++)
718 buf[i] = ~(i & 0xff);
719 break;
720 case 10:
721 for (i = 0; i < size % 2; i++) {
722 buf[i * 2] = (i >> 8) & 0xff;
723 buf[i * 2 + 1] = i & 0xff;
724 }
725 if (size & 0x1)
726 buf[i * 2] = (i >> 8) & 0xff;
727 break;
728 case 11:
729 for (i = 0; i < size % 2; i++) {
730 buf[i * 2] = ~((i >> 8) & 0xff);
731 buf[i * 2 + 1] = ~(i & 0xff);
732 }
733 if (size & 0x1)
734 buf[i * 2] = ~((i >> 8) & 0xff);
735 break;
736 case 12:
737 memset(buf, 0x00, size);
738 break;
739 case 13:
740 memset(buf, 0xff, size);
741 break;
742 }
743
744 if ((variant >= 0) && (variant <= 7)) {
745 /* Write block number in the last two bytes of each 256-byte
746 * block, big endian for easier reading of the hexdump.
747 * Note that this wraps around for chips larger than 2^24 bytes
748 * (16 MB).
749 */
750 for (i = 0; i < size / 256; i++) {
751 buf[i * 256 + 254] = (i >> 8) & 0xff;
752 buf[i * 256 + 255] = i & 0xff;
753 }
754 }
755
756 return 0;
757}
758
Carl-Daniel Hailfinger115d3902009-10-31 01:53:09 +0000759int check_max_decode(enum chipbustype buses, uint32_t size)
760{
761 int limitexceeded = 0;
762 if ((buses & CHIP_BUSTYPE_PARALLEL) &&
763 (max_rom_decode.parallel < size)) {
764 limitexceeded++;
765 printf_debug("Chip size %u kB is bigger than supported "
766 "size %u kB of chipset/board/programmer "
767 "for %s interface, "
768 "probe/read/erase/write may fail. ", size / 1024,
769 max_rom_decode.parallel / 1024, "Parallel");
770 }
771 if ((buses & CHIP_BUSTYPE_LPC) && (max_rom_decode.lpc < size)) {
772 limitexceeded++;
773 printf_debug("Chip size %u kB is bigger than supported "
774 "size %u kB of chipset/board/programmer "
775 "for %s interface, "
776 "probe/read/erase/write may fail. ", size / 1024,
777 max_rom_decode.lpc / 1024, "LPC");
778 }
779 if ((buses & CHIP_BUSTYPE_FWH) && (max_rom_decode.fwh < size)) {
780 limitexceeded++;
781 printf_debug("Chip size %u kB is bigger than supported "
782 "size %u kB of chipset/board/programmer "
783 "for %s interface, "
784 "probe/read/erase/write may fail. ", size / 1024,
785 max_rom_decode.fwh / 1024, "FWH");
786 }
787 if ((buses & CHIP_BUSTYPE_SPI) && (max_rom_decode.spi < size)) {
788 limitexceeded++;
789 printf_debug("Chip size %u kB is bigger than supported "
790 "size %u kB of chipset/board/programmer "
791 "for %s interface, "
792 "probe/read/erase/write may fail. ", size / 1024,
793 max_rom_decode.spi / 1024, "SPI");
794 }
795 if (!limitexceeded)
796 return 0;
797 /* Sometimes chip and programmer have more than one bus in common,
798 * and the limit is not exceeded on all buses. Tell the user.
799 */
800 if (bitcount(buses) > limitexceeded)
Carl-Daniel Hailfingera84835a2010-01-07 03:24:05 +0000801 /* FIXME: This message is designed towards CLI users. */
Carl-Daniel Hailfinger115d3902009-10-31 01:53:09 +0000802 printf_debug("There is at least one common chip/programmer "
803 "interface which can support a chip of this size. "
804 "You can try --force at your own risk.\n");
805 return 1;
806}
807
Peter Stuge483b8f02008-09-03 23:10:05 +0000808struct flashchip *probe_flash(struct flashchip *first_flash, int force)
Ronald G. Minnichf4cf2ba2002-01-29 18:26:26 +0000809{
Peter Stuge483b8f02008-09-03 23:10:05 +0000810 struct flashchip *flash;
Carl-Daniel Hailfinger115d3902009-10-31 01:53:09 +0000811 unsigned long base = 0;
812 uint32_t size;
813 enum chipbustype buses_common;
Carl-Daniel Hailfingerb22918c2009-06-01 02:08:58 +0000814 char *tmp;
Ronald G. Minnichf4cf2ba2002-01-29 18:26:26 +0000815
Peter Stuge483b8f02008-09-03 23:10:05 +0000816 for (flash = first_flash; flash && flash->name; flash++) {
Peter Stuge27c3e2d2008-07-02 17:15:47 +0000817 if (chip_to_probe && strcmp(flash->name, chip_to_probe) != 0)
Ollie Lhocbbf1252004-03-17 22:22:08 +0000818 continue;
Stefan Reinauerac378972008-03-17 22:59:40 +0000819 printf_debug("Probing for %s %s, %d KB: ",
820 flash->vendor, flash->name, flash->total_size);
Peter Stuge7ffbc6f2008-06-18 02:08:40 +0000821 if (!flash->probe && !force) {
Peter Stugef31104c2008-04-28 14:47:30 +0000822 printf_debug("failed! flashrom has no probe function for this flash chip.\n");
Peter Stugef31104c2008-04-28 14:47:30 +0000823 continue;
824 }
Carl-Daniel Hailfinger115d3902009-10-31 01:53:09 +0000825 buses_common = buses_supported & flash->bustype;
826 if (!buses_common) {
Carl-Daniel Hailfingerb22918c2009-06-01 02:08:58 +0000827 tmp = flashbuses_to_text(buses_supported);
828 printf_debug("skipped. Host bus type %s ", tmp);
829 free(tmp);
830 tmp = flashbuses_to_text(flash->bustype);
831 printf_debug("and chip bus type %s are incompatible.\n", tmp);
832 free(tmp);
833 continue;
834 }
Stefan Reinauer70385642007-04-06 11:58:03 +0000835
Ollie Lhocbbf1252004-03-17 22:22:08 +0000836 size = flash->total_size * 1024;
Carl-Daniel Hailfinger115d3902009-10-31 01:53:09 +0000837 check_max_decode(buses_common, size);
Stefan Reinauer70385642007-04-06 11:58:03 +0000838
Carl-Daniel Hailfinger97d6b092009-05-09 07:27:23 +0000839 base = flashbase ? flashbase : (0xffffffff - size + 1);
Carl-Daniel Hailfinger5820f422009-05-16 21:22:56 +0000840 flash->virtual_memory = (chipaddr)programmer_map_flash_region("flash chip", base, size);
Ronald G. Minnichf4cf2ba2002-01-29 18:26:26 +0000841
Peter Stuge27c3e2d2008-07-02 17:15:47 +0000842 if (force)
843 break;
Stefan Reinauerfcb63682006-03-16 16:57:41 +0000844
Peter Stuge483b8f02008-09-03 23:10:05 +0000845 if (flash->probe(flash) != 1)
846 goto notfound;
847
Uwe Hermann394131e2008-10-18 21:14:13 +0000848 if (first_flash == flashchips
849 || flash->model_id != GENERIC_DEVICE_ID)
Peter Stuge27c3e2d2008-07-02 17:15:47 +0000850 break;
851
Peter Stuge483b8f02008-09-03 23:10:05 +0000852notfound:
Carl-Daniel Hailfinger5820f422009-05-16 21:22:56 +0000853 programmer_unmap_flash_region((void *)flash->virtual_memory, size);
Ronald G. Minnichf4cf2ba2002-01-29 18:26:26 +0000854 }
Uwe Hermannffec5f32007-08-23 16:08:21 +0000855
Peter Stuge27c3e2d2008-07-02 17:15:47 +0000856 if (!flash || !flash->name)
857 return NULL;
858
Uwe Hermann9899cad2009-06-28 21:47:57 +0000859 printf("Found chip \"%s %s\" (%d KB, %s) at physical address 0x%lx.\n",
860 flash->vendor, flash->name, flash->total_size,
861 flashbuses_to_text(flash->bustype), base);
862
Sean Nelson6e0b9122010-02-19 00:52:10 +0000863 if (flash->printlock)
864 flash->printlock(flash);
865
Peter Stuge27c3e2d2008-07-02 17:15:47 +0000866 return flash;
Ronald G. Minnichf4cf2ba2002-01-29 18:26:26 +0000867}
868
Stefan Reinauere3705282005-12-18 16:41:10 +0000869int verify_flash(struct flashchip *flash, uint8_t *buf)
Ronald G. Minnichf4cf2ba2002-01-29 18:26:26 +0000870{
Carl-Daniel Hailfinger23290662009-06-24 08:20:45 +0000871 int ret;
Ollie Lho761bf1b2004-03-20 16:46:10 +0000872 int total_size = flash->total_size * 1024;
Ronald G. Minnichf4cf2ba2002-01-29 18:26:26 +0000873
Uwe Hermanna502dce2007-10-17 23:55:15 +0000874 printf("Verifying flash... ");
Uwe Hermanna7e05482007-05-09 10:17:44 +0000875
Carl-Daniel Hailfinger23290662009-06-24 08:20:45 +0000876 ret = verify_range(flash, buf, 0, total_size, NULL);
Uwe Hermanna7e05482007-05-09 10:17:44 +0000877
Carl-Daniel Hailfinger23290662009-06-24 08:20:45 +0000878 if (!ret)
879 printf("VERIFIED. \n");
Stefan Reinauerfcb63682006-03-16 16:57:41 +0000880
Carl-Daniel Hailfinger23290662009-06-24 08:20:45 +0000881 return ret;
Ronald G. Minnichf4cf2ba2002-01-29 18:26:26 +0000882}
883
Carl-Daniel Hailfinger49eb4dd2009-06-19 11:23:57 +0000884int read_flash(struct flashchip *flash, char *filename)
Carl-Daniel Hailfinger7314cc32009-01-28 00:27:54 +0000885{
886 unsigned long numbytes;
887 FILE *image;
888 unsigned long size = flash->total_size * 1024;
889 unsigned char *buf = calloc(size, sizeof(char));
Stephan Guilloux21dd55b2009-06-01 22:07:52 +0000890
891 if (!filename) {
892 printf("Error: No filename specified.\n");
893 return 1;
894 }
Patrick Georgi0bf842d2010-01-25 22:55:33 +0000895 if ((image = fopen(filename, "wb")) == NULL) {
Carl-Daniel Hailfinger7314cc32009-01-28 00:27:54 +0000896 perror(filename);
897 exit(1);
898 }
899 printf("Reading flash... ");
Carl-Daniel Hailfinger03b4e712009-05-08 12:49:03 +0000900 if (!flash->read) {
901 printf("FAILED!\n");
902 fprintf(stderr, "ERROR: flashrom has no read function for this flash chip.\n");
903 return 1;
904 } else
Carl-Daniel Hailfingercbf563c2009-06-16 08:55:44 +0000905 flash->read(flash, buf, 0, size);
Carl-Daniel Hailfinger7314cc32009-01-28 00:27:54 +0000906
Carl-Daniel Hailfinger7314cc32009-01-28 00:27:54 +0000907 numbytes = fwrite(buf, 1, size, image);
908 fclose(image);
Stephan Guilloux5a8b2442009-06-01 21:37:00 +0000909 free(buf);
Carl-Daniel Hailfinger7314cc32009-01-28 00:27:54 +0000910 printf("%s.\n", numbytes == size ? "done" : "FAILED");
911 if (numbytes != size)
912 return 1;
913 return 0;
914}
915
Carl-Daniel Hailfinger415afcf2010-01-19 06:42:46 +0000916/* This function shares a lot of its structure with erase_flash().
917 * Even if an error is found, the function will keep going and check the rest.
918 */
Carl-Daniel Hailfinger293adf02010-01-18 08:14:43 +0000919int selfcheck_eraseblocks(struct flashchip *flash)
920{
Carl-Daniel Hailfinger415afcf2010-01-19 06:42:46 +0000921 int i, j, k;
922 int ret = 0;
Carl-Daniel Hailfinger293adf02010-01-18 08:14:43 +0000923
924 for (k = 0; k < NUM_ERASEFUNCTIONS; k++) {
925 unsigned int done = 0;
926 struct block_eraser eraser = flash->block_erasers[k];
927
928 for (i = 0; i < NUM_ERASEREGIONS; i++) {
929 /* Blocks with zero size are bugs in flashchips.c. */
930 if (eraser.eraseblocks[i].count &&
931 !eraser.eraseblocks[i].size) {
932 msg_gerr("ERROR: Flash chip %s erase function "
933 "%i region %i has size 0. Please report"
934 " a bug at flashrom@flashrom.org\n",
935 flash->name, k, i);
Carl-Daniel Hailfinger415afcf2010-01-19 06:42:46 +0000936 ret = 1;
Carl-Daniel Hailfinger293adf02010-01-18 08:14:43 +0000937 }
938 /* Blocks with zero count are bugs in flashchips.c. */
939 if (!eraser.eraseblocks[i].count &&
940 eraser.eraseblocks[i].size) {
941 msg_gerr("ERROR: Flash chip %s erase function "
942 "%i region %i has count 0. Please report"
943 " a bug at flashrom@flashrom.org\n",
944 flash->name, k, i);
Carl-Daniel Hailfinger415afcf2010-01-19 06:42:46 +0000945 ret = 1;
Carl-Daniel Hailfinger293adf02010-01-18 08:14:43 +0000946 }
947 done += eraser.eraseblocks[i].count *
948 eraser.eraseblocks[i].size;
949 }
Carl-Daniel Hailfinger415afcf2010-01-19 06:42:46 +0000950 /* Empty eraseblock definition with erase function. */
951 if (!done && eraser.block_erase)
952 msg_pspew("Strange: Empty eraseblock definition with "
953 "non-empty erase function. Not an error.\n");
Carl-Daniel Hailfinger293adf02010-01-18 08:14:43 +0000954 if (!done)
955 continue;
956 if (done != flash->total_size * 1024) {
957 msg_gerr("ERROR: Flash chip %s erase function %i "
958 "region walking resulted in 0x%06x bytes total,"
959 " expected 0x%06x bytes. Please report a bug at"
960 " flashrom@flashrom.org\n", flash->name, k,
961 done, flash->total_size * 1024);
Carl-Daniel Hailfinger415afcf2010-01-19 06:42:46 +0000962 ret = 1;
Carl-Daniel Hailfinger293adf02010-01-18 08:14:43 +0000963 }
Carl-Daniel Hailfinger415afcf2010-01-19 06:42:46 +0000964 if (!eraser.block_erase)
965 continue;
966 /* Check if there are identical erase functions for different
967 * layouts. That would imply "magic" erase functions. The
968 * easiest way to check this is with function pointers.
969 */
970 for (j = k + 1; j < NUM_ERASEFUNCTIONS; j++)
971 if (eraser.block_erase ==
972 flash->block_erasers[j].block_erase) {
973 msg_gerr("ERROR: Flash chip %s erase function "
974 "%i and %i are identical. Please report"
975 " a bug at flashrom@flashrom.org\n",
976 flash->name, k, j);
977 ret = 1;
978 }
Carl-Daniel Hailfinger293adf02010-01-18 08:14:43 +0000979 }
Carl-Daniel Hailfinger415afcf2010-01-19 06:42:46 +0000980 return ret;
Carl-Daniel Hailfinger293adf02010-01-18 08:14:43 +0000981}
982
Carl-Daniel Hailfinger7314cc32009-01-28 00:27:54 +0000983int erase_flash(struct flashchip *flash)
984{
Carl-Daniel Hailfingerf38431a2009-09-05 02:30:58 +0000985 int i, j, k, ret = 0, found = 0;
Carl-Daniel Hailfinger9d489162009-12-14 04:04:18 +0000986 unsigned int start, len;
Carl-Daniel Hailfingerf38431a2009-09-05 02:30:58 +0000987
Carl-Daniel Hailfinger7314cc32009-01-28 00:27:54 +0000988 printf("Erasing flash chip... ");
Carl-Daniel Hailfingerf38431a2009-09-05 02:30:58 +0000989 for (k = 0; k < NUM_ERASEFUNCTIONS; k++) {
Carl-Daniel Hailfinger9d489162009-12-14 04:04:18 +0000990 unsigned int done = 0;
Carl-Daniel Hailfingerf38431a2009-09-05 02:30:58 +0000991 struct block_eraser eraser = flash->block_erasers[k];
992
993 printf_debug("Looking at blockwise erase function %i... ", k);
994 if (!eraser.block_erase && !eraser.eraseblocks[0].count) {
995 printf_debug("not defined. "
996 "Looking for another erase function.\n");
997 continue;
998 }
999 if (!eraser.block_erase && eraser.eraseblocks[0].count) {
1000 printf_debug("eraseblock layout is known, but no "
1001 "matching block erase function found. "
1002 "Looking for another erase function.\n");
1003 continue;
1004 }
1005 if (eraser.block_erase && !eraser.eraseblocks[0].count) {
1006 printf_debug("block erase function found, but "
1007 "eraseblock layout is unknown. "
1008 "Looking for another erase function.\n");
1009 continue;
1010 }
1011 found = 1;
1012 printf_debug("trying... ");
1013 for (i = 0; i < NUM_ERASEREGIONS; i++) {
1014 /* count==0 for all automatically initialized array
1015 * members so the loop below won't be executed for them.
1016 */
1017 for (j = 0; j < eraser.eraseblocks[i].count; j++) {
Carl-Daniel Hailfinger9d489162009-12-14 04:04:18 +00001018 start = done + eraser.eraseblocks[i].size * j;
1019 len = eraser.eraseblocks[i].size;
1020 printf_debug("0x%06x-0x%06x, ", start,
1021 start + len - 1);
1022 ret = eraser.block_erase(flash, start, len);
Carl-Daniel Hailfingerf38431a2009-09-05 02:30:58 +00001023 if (ret)
1024 break;
1025 }
1026 if (ret)
1027 break;
Carl-Daniel Hailfinger9d489162009-12-14 04:04:18 +00001028 done += eraser.eraseblocks[i].count *
1029 eraser.eraseblocks[i].size;
Carl-Daniel Hailfingerf38431a2009-09-05 02:30:58 +00001030 }
Carl-Daniel Hailfinger9d489162009-12-14 04:04:18 +00001031 printf_debug("\n");
Carl-Daniel Hailfingerf38431a2009-09-05 02:30:58 +00001032 /* If everything is OK, don't try another erase function. */
1033 if (!ret)
1034 break;
1035 }
Carl-Daniel Hailfingerf38431a2009-09-05 02:30:58 +00001036 if (!found) {
Carl-Daniel Hailfinger7314cc32009-01-28 00:27:54 +00001037 fprintf(stderr, "ERROR: flashrom has no erase function for this flash chip.\n");
1038 return 1;
1039 }
Carl-Daniel Hailfingerf160a122009-05-08 17:15:15 +00001040
Carl-Daniel Hailfingerf38431a2009-09-05 02:30:58 +00001041 if (ret) {
1042 fprintf(stderr, "FAILED!\n");
1043 } else {
1044 printf("SUCCESS.\n");
1045 }
1046 return ret;
Carl-Daniel Hailfinger7314cc32009-01-28 00:27:54 +00001047}
1048
Uwe Hermannc67d0372009-10-01 18:40:02 +00001049void emergency_help_message(void)
Carl-Daniel Hailfinger8ab49e72009-08-19 13:55:34 +00001050{
1051 fprintf(stderr, "Your flash chip is in an unknown state.\n"
Uwe Hermannc67d0372009-10-01 18:40:02 +00001052 "Get help on IRC at irc.freenode.net (channel #flashrom) or\n"
1053 "mail flashrom@flashrom.org!\n--------------------"
1054 "-----------------------------------------------------------\n"
Carl-Daniel Hailfinger8ab49e72009-08-19 13:55:34 +00001055 "DO NOT REBOOT OR POWEROFF!\n");
1056}
1057
Carl-Daniel Hailfinger552420b2009-12-24 02:15:55 +00001058/* The way to go if you want a delimited list of programmers*/
1059void list_programmers(char *delim)
1060{
1061 enum programmer p;
1062 for (p = 0; p < PROGRAMMER_INVALID; p++) {
1063 printf("%s", programmer_table[p].name);
1064 if (p < PROGRAMMER_INVALID - 1)
1065 printf("%s", delim);
1066 }
1067 printf("\n");
1068}
1069
Bernhard Walle201bde32008-01-21 15:24:22 +00001070void print_version(void)
1071{
Carl-Daniel Hailfingera80cfbc2009-07-22 20:13:00 +00001072 printf("flashrom v%s\n", flashrom_version);
Bernhard Walle201bde32008-01-21 15:24:22 +00001073}
1074
Carl-Daniel Hailfinger552420b2009-12-24 02:15:55 +00001075int selfcheck(void)
1076{
Carl-Daniel Hailfinger293adf02010-01-18 08:14:43 +00001077 int ret = 0;
1078 struct flashchip *flash;
1079
1080 /* Safety check. Instead of aborting after the first error, check
1081 * if more errors exist.
1082 */
Carl-Daniel Hailfinger552420b2009-12-24 02:15:55 +00001083 if (ARRAY_SIZE(programmer_table) - 1 != PROGRAMMER_INVALID) {
1084 fprintf(stderr, "Programmer table miscompilation!\n");
Carl-Daniel Hailfinger293adf02010-01-18 08:14:43 +00001085 ret = 1;
Carl-Daniel Hailfinger552420b2009-12-24 02:15:55 +00001086 }
1087 if (spi_programmer_count - 1 != SPI_CONTROLLER_INVALID) {
1088 fprintf(stderr, "SPI programmer table miscompilation!\n");
Carl-Daniel Hailfinger293adf02010-01-18 08:14:43 +00001089 ret = 1;
Carl-Daniel Hailfinger552420b2009-12-24 02:15:55 +00001090 }
1091#if BITBANG_SPI_SUPPORT == 1
1092 if (bitbang_spi_master_count - 1 != BITBANG_SPI_INVALID) {
1093 fprintf(stderr, "Bitbanging SPI master table miscompilation!\n");
Carl-Daniel Hailfinger293adf02010-01-18 08:14:43 +00001094 ret = 1;
Carl-Daniel Hailfinger552420b2009-12-24 02:15:55 +00001095 }
1096#endif
Carl-Daniel Hailfinger293adf02010-01-18 08:14:43 +00001097 for (flash = flashchips; flash && flash->name; flash++)
1098 if (selfcheck_eraseblocks(flash))
1099 ret = 1;
1100 return ret;
Carl-Daniel Hailfinger552420b2009-12-24 02:15:55 +00001101}
1102
1103void check_chip_supported(struct flashchip *flash)
1104{
1105 if (TEST_OK_MASK != (flash->tested & TEST_OK_MASK)) {
1106 printf("===\n");
1107 if (flash->tested & TEST_BAD_MASK) {
1108 printf("This flash part has status NOT WORKING for operations:");
1109 if (flash->tested & TEST_BAD_PROBE)
1110 printf(" PROBE");
1111 if (flash->tested & TEST_BAD_READ)
1112 printf(" READ");
1113 if (flash->tested & TEST_BAD_ERASE)
1114 printf(" ERASE");
1115 if (flash->tested & TEST_BAD_WRITE)
1116 printf(" WRITE");
1117 printf("\n");
1118 }
1119 if ((!(flash->tested & TEST_BAD_PROBE) && !(flash->tested & TEST_OK_PROBE)) ||
1120 (!(flash->tested & TEST_BAD_READ) && !(flash->tested & TEST_OK_READ)) ||
1121 (!(flash->tested & TEST_BAD_ERASE) && !(flash->tested & TEST_OK_ERASE)) ||
1122 (!(flash->tested & TEST_BAD_WRITE) && !(flash->tested & TEST_OK_WRITE))) {
1123 printf("This flash part has status UNTESTED for operations:");
1124 if (!(flash->tested & TEST_BAD_PROBE) && !(flash->tested & TEST_OK_PROBE))
1125 printf(" PROBE");
1126 if (!(flash->tested & TEST_BAD_READ) && !(flash->tested & TEST_OK_READ))
1127 printf(" READ");
1128 if (!(flash->tested & TEST_BAD_ERASE) && !(flash->tested & TEST_OK_ERASE))
1129 printf(" ERASE");
1130 if (!(flash->tested & TEST_BAD_WRITE) && !(flash->tested & TEST_OK_WRITE))
1131 printf(" WRITE");
1132 printf("\n");
1133 }
Carl-Daniel Hailfingera84835a2010-01-07 03:24:05 +00001134 /* FIXME: This message is designed towards CLI users. */
Carl-Daniel Hailfinger552420b2009-12-24 02:15:55 +00001135 printf("Please email a report to flashrom@flashrom.org if any "
1136 "of the above operations\nwork correctly for you with "
1137 "this flash part. Please include the flashrom\noutput "
1138 "with the additional -V option for all operations you "
1139 "tested (-V, -rV,\n-wV, -EV), and mention which "
1140 "mainboard or programmer you tested. Thanks for your "
1141 "help!\n===\n");
1142 }
1143}
1144
Ollie Lho761bf1b2004-03-20 16:46:10 +00001145int main(int argc, char *argv[])
Ronald G. Minnichf4cf2ba2002-01-29 18:26:26 +00001146{
Carl-Daniel Hailfingera84835a2010-01-07 03:24:05 +00001147 return cli_classic(argc, argv);
Carl-Daniel Hailfinger552420b2009-12-24 02:15:55 +00001148}
1149
1150/* This function signature is horrible. We need to design a better interface,
1151 * but right now it allows us to split off the CLI code.
1152 */
1153int doit(struct flashchip *flash, int force, char *filename, int read_it, int write_it, int erase_it, int verify_it)
1154{
1155 uint8_t *buf;
1156 unsigned long numbytes;
1157 FILE *image;
1158 int ret = 0;
1159 unsigned long size;
1160
1161 size = flash->total_size * 1024;
Ollie Lho184a4042005-11-26 21:55:36 +00001162 buf = (uint8_t *) calloc(size, sizeof(char));
Uwe Hermanna7e05482007-05-09 10:17:44 +00001163
Ollie Lhoefa28582004-12-08 20:10:01 +00001164 if (erase_it) {
Carl-Daniel Hailfinger8ab49e72009-08-19 13:55:34 +00001165 if (flash->tested & TEST_BAD_ERASE) {
1166 fprintf(stderr, "Erase is not working on this chip. ");
1167 if (!force) {
1168 fprintf(stderr, "Aborting.\n");
Uwe Hermann2bc98f62009-09-30 18:29:55 +00001169 programmer_shutdown();
Carl-Daniel Hailfinger8ab49e72009-08-19 13:55:34 +00001170 return 1;
1171 } else {
1172 fprintf(stderr, "Continuing anyway.\n");
1173 }
1174 }
Sean Nelson6e0b9122010-02-19 00:52:10 +00001175 if (flash->unlock)
1176 flash->unlock(flash);
1177
Carl-Daniel Hailfinger8ab49e72009-08-19 13:55:34 +00001178 if (erase_flash(flash)) {
1179 emergency_help_message();
Uwe Hermann2bc98f62009-09-30 18:29:55 +00001180 programmer_shutdown();
Peter Stugef31104c2008-04-28 14:47:30 +00001181 return 1;
Carl-Daniel Hailfinger8ab49e72009-08-19 13:55:34 +00001182 }
Ollie Lhoefa28582004-12-08 20:10:01 +00001183 } else if (read_it) {
Sean Nelson6e0b9122010-02-19 00:52:10 +00001184 if (flash->unlock)
1185 flash->unlock(flash);
1186
Uwe Hermann2bc98f62009-09-30 18:29:55 +00001187 if (read_flash(flash, filename)) {
1188 programmer_shutdown();
Peter Stuge1fec0f32009-01-12 21:00:35 +00001189 return 1;
Uwe Hermann2bc98f62009-09-30 18:29:55 +00001190 }
Ollie Lhocbbf1252004-03-17 22:22:08 +00001191 } else {
Stefan Reinauer018aca82006-11-21 23:48:51 +00001192 struct stat image_stat;
1193
Sean Nelson6e0b9122010-02-19 00:52:10 +00001194 if (flash->unlock)
1195 flash->unlock(flash);
1196
Carl-Daniel Hailfinger8ab49e72009-08-19 13:55:34 +00001197 if (flash->tested & TEST_BAD_ERASE) {
1198 fprintf(stderr, "Erase is not working on this chip "
1199 "and erase is needed for write. ");
1200 if (!force) {
1201 fprintf(stderr, "Aborting.\n");
Uwe Hermann2bc98f62009-09-30 18:29:55 +00001202 programmer_shutdown();
Carl-Daniel Hailfinger8ab49e72009-08-19 13:55:34 +00001203 return 1;
1204 } else {
1205 fprintf(stderr, "Continuing anyway.\n");
1206 }
1207 }
1208 if (flash->tested & TEST_BAD_WRITE) {
1209 fprintf(stderr, "Write is not working on this chip. ");
1210 if (!force) {
1211 fprintf(stderr, "Aborting.\n");
Uwe Hermann2bc98f62009-09-30 18:29:55 +00001212 programmer_shutdown();
Carl-Daniel Hailfinger8ab49e72009-08-19 13:55:34 +00001213 return 1;
1214 } else {
1215 fprintf(stderr, "Continuing anyway.\n");
1216 }
1217 }
Patrick Georgi0bf842d2010-01-25 22:55:33 +00001218 if ((image = fopen(filename, "rb")) == NULL) {
Ollie Lhocbbf1252004-03-17 22:22:08 +00001219 perror(filename);
Uwe Hermann2bc98f62009-09-30 18:29:55 +00001220 programmer_shutdown();
Ollie Lhocbbf1252004-03-17 22:22:08 +00001221 exit(1);
1222 }
Stefan Reinauer018aca82006-11-21 23:48:51 +00001223 if (fstat(fileno(image), &image_stat) != 0) {
1224 perror(filename);
Uwe Hermann2bc98f62009-09-30 18:29:55 +00001225 programmer_shutdown();
Stefan Reinauer018aca82006-11-21 23:48:51 +00001226 exit(1);
1227 }
Uwe Hermanna7e05482007-05-09 10:17:44 +00001228 if (image_stat.st_size != flash->total_size * 1024) {
Uwe Hermann793bdcd2008-05-22 22:47:04 +00001229 fprintf(stderr, "Error: Image size doesn't match\n");
Uwe Hermann2bc98f62009-09-30 18:29:55 +00001230 programmer_shutdown();
Stefan Reinauer018aca82006-11-21 23:48:51 +00001231 exit(1);
1232 }
1233
Peter Stuge1fec0f32009-01-12 21:00:35 +00001234 numbytes = fread(buf, 1, size, image);
Carl-Daniel Hailfinger66ef4e52009-12-13 22:28:00 +00001235#if INTERNAL_SUPPORT == 1
Peter Stuge7ffbc6f2008-06-18 02:08:40 +00001236 show_id(buf, size, force);
Carl-Daniel Hailfinger66ef4e52009-12-13 22:28:00 +00001237#endif
Ollie Lhocbbf1252004-03-17 22:22:08 +00001238 fclose(image);
Peter Stuge1fec0f32009-01-12 21:00:35 +00001239 if (numbytes != size) {
1240 fprintf(stderr, "Error: Failed to read file. Got %ld bytes, wanted %ld!\n", numbytes, size);
Uwe Hermann2bc98f62009-09-30 18:29:55 +00001241 programmer_shutdown();
Peter Stuge1fec0f32009-01-12 21:00:35 +00001242 return 1;
1243 }
Ollie Lhocbbf1252004-03-17 22:22:08 +00001244 }
1245
Ollie Lho184a4042005-11-26 21:55:36 +00001246 // This should be moved into each flash part's code to do it
1247 // cleanly. This does the job.
Carl-Daniel Hailfingerf5fb51c2009-08-19 15:19:18 +00001248 handle_romentries(buf, flash);
Uwe Hermanna7e05482007-05-09 10:17:44 +00001249
Ollie Lho184a4042005-11-26 21:55:36 +00001250 // ////////////////////////////////////////////////////////////
Uwe Hermanna7e05482007-05-09 10:17:44 +00001251
Peter Stugef31104c2008-04-28 14:47:30 +00001252 if (write_it) {
Paul Foxd51410c2009-06-12 08:04:08 +00001253 printf("Writing flash chip... ");
Peter Stugef31104c2008-04-28 14:47:30 +00001254 if (!flash->write) {
1255 fprintf(stderr, "Error: flashrom has no write function for this flash chip.\n");
Uwe Hermann2bc98f62009-09-30 18:29:55 +00001256 programmer_shutdown();
Peter Stugef31104c2008-04-28 14:47:30 +00001257 return 1;
1258 }
Carl-Daniel Hailfinger0a3e5ae2009-07-24 12:18:54 +00001259 ret = flash->write(flash, buf);
1260 if (ret) {
1261 fprintf(stderr, "FAILED!\n");
Carl-Daniel Hailfinger8ab49e72009-08-19 13:55:34 +00001262 emergency_help_message();
Uwe Hermann2bc98f62009-09-30 18:29:55 +00001263 programmer_shutdown();
Carl-Daniel Hailfinger0a3e5ae2009-07-24 12:18:54 +00001264 return 1;
1265 } else {
1266 printf("COMPLETE.\n");
1267 }
Peter Stugef31104c2008-04-28 14:47:30 +00001268 }
Ollie Lho184a4042005-11-26 21:55:36 +00001269
Carl-Daniel Hailfinger8ab49e72009-08-19 13:55:34 +00001270 if (verify_it) {
1271 /* Work around chips which need some time to calm down. */
1272 if (write_it)
1273 programmer_delay(1000*1000);
Carl-Daniel Hailfinger0a3e5ae2009-07-24 12:18:54 +00001274 ret = verify_flash(flash, buf);
Carl-Daniel Hailfingerf5292052009-11-17 09:57:34 +00001275 /* If we tried to write, and verification now fails, we
Carl-Daniel Hailfinger8ab49e72009-08-19 13:55:34 +00001276 * might have an emergency situation.
1277 */
1278 if (ret && write_it)
1279 emergency_help_message();
1280 }
Ollie Lho184a4042005-11-26 21:55:36 +00001281
Carl-Daniel Hailfinger702218d2009-05-08 17:43:22 +00001282 programmer_shutdown();
1283
Stefan Reinauer143da0b2006-01-04 16:42:57 +00001284 return ret;
Ronald G. Minnichf4cf2ba2002-01-29 18:26:26 +00001285}