blob: 19c50002ccd72e3db9faaf71ee1e392e8e160cf5 [file] [log] [blame]
hailfingera9df33c2009-05-09 00:54:55 +00001/*
2 * This file is part of the flashrom project.
3 *
hailfinger6ead7222010-11-01 22:07:04 +00004 * Copyright (C) 2009,2010 Carl-Daniel Hailfinger
hailfingera9df33c2009-05-09 00:54:55 +00005 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
hailfinger6ead7222010-11-01 22:07:04 +00008 * the Free Software Foundation; version 2 of the License.
hailfingera9df33c2009-05-09 00:54:55 +00009 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18 */
19
David Hendricks84377002014-09-09 16:09:31 -070020#include <errno.h>
hailfingera9df33c2009-05-09 00:54:55 +000021#include <string.h>
22#include <stdlib.h>
Carl-Daniel Hailfingerc49783d2016-08-05 10:52:06 -070023#include <stdio.h>
24#include <ctype.h>
Patrick Georgi4befc162017-02-03 18:32:01 +010025#include <inttypes.h>
hailfingera9df33c2009-05-09 00:54:55 +000026#include "flash.h"
hailfingera8727712010-06-20 10:58:32 +000027#include "chipdrivers.h"
hailfinger428f6852010-07-27 22:41:39 +000028#include "programmer.h"
Louis Yung-Chieh Loe53fa0f2011-04-11 17:18:41 +080029#include "flashchips.h"
hailfingera9df33c2009-05-09 00:54:55 +000030
hailfinger6ead7222010-11-01 22:07:04 +000031/* Remove the #define below if you don't want SPI flash chip emulation. */
32#define EMULATE_SPI_CHIP 1
33
34#if EMULATE_SPI_CHIP
35#define EMULATE_CHIP 1
36#include "spi.h"
37#endif
38
39#if EMULATE_CHIP
40#include <sys/types.h>
41#include <sys/stat.h>
Louis Yung-Chieh Loe53fa0f2011-04-11 17:18:41 +080042
43#if EMULATE_SPI_CHIP
44/* The name of variable-size virtual chip. A 4MB flash example:
45 * flashrom -p dummy:emulate=VARIABLE_SIZE,size=4194304
46 */
47#define VARIABLE_SIZE_CHIP_NAME "VARIABLE_SIZE"
Carl-Daniel Hailfingerc49783d2016-08-05 10:52:06 -070048unsigned char spi_blacklist[256];
49unsigned char spi_ignorelist[256];
50int spi_blacklist_size = 0;
51int spi_ignorelist_size = 0;
Louis Yung-Chieh Loe53fa0f2011-04-11 17:18:41 +080052#endif
hailfinger6ead7222010-11-01 22:07:04 +000053#endif
54
55#if EMULATE_CHIP
56static uint8_t *flashchip_contents = NULL;
57enum emu_chip {
58 EMULATE_NONE,
59 EMULATE_ST_M25P10_RES,
60 EMULATE_SST_SST25VF040_REMS,
61 EMULATE_SST_SST25VF032B,
Louis Yung-Chieh Loe53fa0f2011-04-11 17:18:41 +080062 EMULATE_VARIABLE_SIZE,
hailfinger6ead7222010-11-01 22:07:04 +000063};
64static enum emu_chip emu_chip = EMULATE_NONE;
65static char *emu_persistent_image = NULL;
stefanctc5eb8a92011-11-23 09:13:48 +000066static unsigned int emu_chip_size = 0;
Simon Glasscf253a72013-07-10 21:10:11 -070067static int emu_modified; /* is the image modified since reading it? */
David Hendricks0eda2a82014-09-12 16:32:05 -070068static int erase_to_zero;
hailfinger6ead7222010-11-01 22:07:04 +000069#if EMULATE_SPI_CHIP
stefanctc5eb8a92011-11-23 09:13:48 +000070static unsigned int emu_max_byteprogram_size = 0;
71static unsigned int emu_max_aai_size = 0;
72static unsigned int emu_jedec_se_size = 0;
73static unsigned int emu_jedec_be_52_size = 0;
74static unsigned int emu_jedec_be_d8_size = 0;
75static unsigned int emu_jedec_ce_60_size = 0;
76static unsigned int emu_jedec_ce_c7_size = 0;
hailfinger6ead7222010-11-01 22:07:04 +000077#endif
78#endif
79
stefanctc5eb8a92011-11-23 09:13:48 +000080static unsigned int spi_write_256_chunksize = 256;
hailfinger6ead7222010-11-01 22:07:04 +000081
David Hendricks84377002014-09-09 16:09:31 -070082/* If "freq" parameter is passed in from command line, commands will delay
83 * for this period before returning. */
84static unsigned long int delay_us = 0;
85
Souvik Ghoshd75cd672016-06-17 14:21:39 -070086static int dummy_spi_send_command(const struct flashctx *flash, unsigned int writecnt, unsigned int readcnt,
mkarcherd264e9e2011-05-11 17:07:07 +000087 const unsigned char *writearr, unsigned char *readarr);
Patrick Georgiab8353e2017-02-03 18:32:01 +010088static int dummy_spi_write_256(struct flashctx *flash, const uint8_t *buf,
stefanctc5eb8a92011-11-23 09:13:48 +000089 unsigned int start, unsigned int len);
Souvik Ghoshd75cd672016-06-17 14:21:39 -070090static void dummy_chip_writeb(const struct flashctx *flash, uint8_t val,
91 chipaddr addr);
92static void dummy_chip_writew(const struct flashctx *flash, uint16_t val,
93 chipaddr addr);
94static void dummy_chip_writel(const struct flashctx *flash, uint32_t val,
95 chipaddr addr);
96static void dummy_chip_writen(const struct flashctx *flash, uint8_t *buf,
97 chipaddr addr, size_t len);
98static uint8_t dummy_chip_readb(const struct flashctx *flash,
99 const chipaddr addr);
100static uint16_t dummy_chip_readw(const struct flashctx *flash,
101 const chipaddr addr);
102static uint32_t dummy_chip_readl(const struct flashctx *flash,
103 const chipaddr addr);
104static void dummy_chip_readn(const struct flashctx *flash, uint8_t *buf,
105 const chipaddr addr, size_t len);
mkarcherd264e9e2011-05-11 17:07:07 +0000106
Patrick Georgif4f1e2f2017-03-10 17:38:40 +0100107static const struct spi_master spi_master_dummyflasher = {
uwe8d342eb2011-07-28 08:13:25 +0000108 .type = SPI_CONTROLLER_DUMMY,
109 .max_data_read = MAX_DATA_READ_UNLIMITED,
110 .max_data_write = MAX_DATA_UNSPECIFIED,
111 .command = dummy_spi_send_command,
112 .multicommand = default_spi_send_multicommand,
113 .read = default_spi_read,
114 .write_256 = dummy_spi_write_256,
mkarcherd264e9e2011-05-11 17:07:07 +0000115};
dhendrix0ffc2eb2011-06-14 01:35:36 +0000116
Patrick Georgi0a9533a2017-02-03 19:28:38 +0100117static const struct par_master par_master_dummy = {
hailfinger76bb7e92011-11-09 23:40:00 +0000118 .chip_readb = dummy_chip_readb,
119 .chip_readw = dummy_chip_readw,
120 .chip_readl = dummy_chip_readl,
121 .chip_readn = dummy_chip_readn,
122 .chip_writeb = dummy_chip_writeb,
123 .chip_writew = dummy_chip_writew,
124 .chip_writel = dummy_chip_writel,
125 .chip_writen = dummy_chip_writen,
126};
127
128enum chipbustype dummy_buses_supported = BUS_NONE;
129
David Hendricks93784b42016-08-09 17:00:38 -0700130static int dummy_shutdown(void *data)
dhendrix0ffc2eb2011-06-14 01:35:36 +0000131{
132 msg_pspew("%s\n", __func__);
133#if EMULATE_CHIP
134 if (emu_chip != EMULATE_NONE) {
Simon Glasscf253a72013-07-10 21:10:11 -0700135 if (emu_persistent_image && emu_modified) {
dhendrix0ffc2eb2011-06-14 01:35:36 +0000136 msg_pdbg("Writing %s\n", emu_persistent_image);
137 write_buf_to_file(flashchip_contents, emu_chip_size,
138 emu_persistent_image);
139 }
140 free(flashchip_contents);
141 }
142#endif
143 return 0;
144}
145
Simon Glassd2c64a22013-07-03 22:05:21 +0900146/* Values for the 'size' parameter */
147enum {
148 SIZE_UNKNOWN = -1,
149 SIZE_AUTO = -2,
150};
151
David Hendricksac1d25c2016-08-09 17:00:58 -0700152int dummy_init(void)
hailfingera9df33c2009-05-09 00:54:55 +0000153{
hailfinger1ef766d2010-07-06 09:55:48 +0000154 char *bustext = NULL;
hailfinger6ead7222010-11-01 22:07:04 +0000155 char *tmp = NULL;
Carl-Daniel Hailfingerc49783d2016-08-05 10:52:06 -0700156 int i;
hailfinger6ead7222010-11-01 22:07:04 +0000157#if EMULATE_CHIP
158 struct stat image_stat;
Louis Yung-Chieh Loe53fa0f2011-04-11 17:18:41 +0800159#if EMULATE_SPI_CHIP
Simon Glassd2c64a22013-07-03 22:05:21 +0900160 int size = SIZE_UNKNOWN; /* size for generic chip */
Louis Yung-Chieh Loe53fa0f2011-04-11 17:18:41 +0800161#endif
hailfinger6ead7222010-11-01 22:07:04 +0000162#endif
Simon Glassd2c64a22013-07-03 22:05:21 +0900163 int image_size = SIZE_UNKNOWN;
hailfinger1ef766d2010-07-06 09:55:48 +0000164
hailfinger50c335f2010-01-09 04:32:23 +0000165 msg_pspew("%s\n", __func__);
hailfinger668f3502009-06-01 00:02:11 +0000166
hailfingerddeb4ac2010-07-08 10:13:37 +0000167 bustext = extract_programmer_param("bus");
hailfinger1ef766d2010-07-06 09:55:48 +0000168 msg_pdbg("Requested buses are: %s\n", bustext ? bustext : "default");
169 if (!bustext)
170 bustext = strdup("parallel+lpc+fwh+spi");
hailfinger668f3502009-06-01 00:02:11 +0000171 /* Convert the parameters to lowercase. */
hailfinger1ef766d2010-07-06 09:55:48 +0000172 tolower_string(bustext);
hailfinger668f3502009-06-01 00:02:11 +0000173
hailfinger76bb7e92011-11-09 23:40:00 +0000174 dummy_buses_supported = BUS_NONE;
hailfinger1ef766d2010-07-06 09:55:48 +0000175 if (strstr(bustext, "parallel")) {
hailfinger76bb7e92011-11-09 23:40:00 +0000176 dummy_buses_supported |= BUS_PARALLEL;
hailfinger50c335f2010-01-09 04:32:23 +0000177 msg_pdbg("Enabling support for %s flash.\n", "parallel");
hailfinger668f3502009-06-01 00:02:11 +0000178 }
hailfinger1ef766d2010-07-06 09:55:48 +0000179 if (strstr(bustext, "lpc")) {
hailfinger76bb7e92011-11-09 23:40:00 +0000180 dummy_buses_supported |= BUS_LPC;
hailfinger50c335f2010-01-09 04:32:23 +0000181 msg_pdbg("Enabling support for %s flash.\n", "LPC");
hailfinger668f3502009-06-01 00:02:11 +0000182 }
hailfinger1ef766d2010-07-06 09:55:48 +0000183 if (strstr(bustext, "fwh")) {
hailfinger76bb7e92011-11-09 23:40:00 +0000184 dummy_buses_supported |= BUS_FWH;
hailfinger50c335f2010-01-09 04:32:23 +0000185 msg_pdbg("Enabling support for %s flash.\n", "FWH");
hailfinger668f3502009-06-01 00:02:11 +0000186 }
hailfinger1ef766d2010-07-06 09:55:48 +0000187 if (strstr(bustext, "spi")) {
hailfinger76bb7e92011-11-09 23:40:00 +0000188 dummy_buses_supported |= BUS_SPI;
hailfinger50c335f2010-01-09 04:32:23 +0000189 msg_pdbg("Enabling support for %s flash.\n", "SPI");
hailfinger668f3502009-06-01 00:02:11 +0000190 }
hailfinger76bb7e92011-11-09 23:40:00 +0000191 if (dummy_buses_supported == BUS_NONE)
hailfinger50c335f2010-01-09 04:32:23 +0000192 msg_pdbg("Support for all flash bus types disabled.\n");
hailfinger1ef766d2010-07-06 09:55:48 +0000193 free(bustext);
hailfinger6ead7222010-11-01 22:07:04 +0000194
195 tmp = extract_programmer_param("spi_write_256_chunksize");
196 if (tmp) {
197 spi_write_256_chunksize = atoi(tmp);
198 free(tmp);
199 if (spi_write_256_chunksize < 1) {
200 msg_perr("invalid spi_write_256_chunksize\n");
201 return 1;
202 }
203 }
204
Carl-Daniel Hailfingerc49783d2016-08-05 10:52:06 -0700205 tmp = extract_programmer_param("spi_blacklist");
206 if (tmp) {
207 i = strlen(tmp);
208 if (!strncmp(tmp, "0x", 2)) {
209 i -= 2;
210 memmove(tmp, tmp + 2, i + 1);
211 }
212 if ((i > 512) || (i % 2)) {
213 msg_perr("Invalid SPI command blacklist length\n");
214 free(tmp);
215 return 1;
216 }
217 spi_blacklist_size = i / 2;
218 for (i = 0; i < spi_blacklist_size * 2; i++) {
219 if (!isxdigit((unsigned char)tmp[i])) {
220 msg_perr("Invalid char \"%c\" in SPI command "
221 "blacklist\n", tmp[i]);
222 free(tmp);
223 return 1;
224 }
225 }
226 for (i = 0; i < spi_blacklist_size; i++) {
227 unsigned int tmp2;
228 /* SCNx8 is apparently not supported by MSVC (and thus
229 * MinGW), so work around it with an extra variable
230 */
231 sscanf(tmp + i * 2, "%2x", &tmp2);
232 spi_blacklist[i] = (uint8_t)tmp2;
233 }
234 msg_pdbg("SPI blacklist is ");
235 for (i = 0; i < spi_blacklist_size; i++)
236 msg_pdbg("%02x ", spi_blacklist[i]);
237 msg_pdbg(", size %i\n", spi_blacklist_size);
238 }
239 free(tmp);
240
241 tmp = extract_programmer_param("spi_ignorelist");
242 if (tmp) {
243 i = strlen(tmp);
244 if (!strncmp(tmp, "0x", 2)) {
245 i -= 2;
246 memmove(tmp, tmp + 2, i + 1);
247 }
248 if ((i > 512) || (i % 2)) {
249 msg_perr("Invalid SPI command ignorelist length\n");
250 free(tmp);
251 return 1;
252 }
253 spi_ignorelist_size = i / 2;
254 for (i = 0; i < spi_ignorelist_size * 2; i++) {
255 if (!isxdigit((unsigned char)tmp[i])) {
256 msg_perr("Invalid char \"%c\" in SPI command "
257 "ignorelist\n", tmp[i]);
258 free(tmp);
259 return 1;
260 }
261 }
262 for (i = 0; i < spi_ignorelist_size; i++) {
263 unsigned int tmp2;
264 /* SCNx8 is apparently not supported by MSVC (and thus
265 * MinGW), so work around it with an extra variable
266 */
267 sscanf(tmp + i * 2, "%2x", &tmp2);
268 spi_ignorelist[i] = (uint8_t)tmp2;
269 }
270 msg_pdbg("SPI ignorelist is ");
271 for (i = 0; i < spi_ignorelist_size; i++)
272 msg_pdbg("%02x ", spi_ignorelist[i]);
273 msg_pdbg(", size %i\n", spi_ignorelist_size);
274 }
275 free(tmp);
276
David Hendricks84377002014-09-09 16:09:31 -0700277 /* frequency to emulate in Hz (default), KHz, or MHz */
278 tmp = extract_programmer_param("freq");
279 if (tmp) {
280 unsigned long int freq;
281 char *units = tmp;
282 char *end = tmp + strlen(tmp);
283
284 errno = 0;
285 freq = strtoul(tmp, &units, 0);
286 if (errno) {
287 msg_perr("Invalid frequency \"%s\", %s\n",
288 tmp, strerror(errno));
289 goto dummy_init_out;
290 }
291
292 if ((units > tmp) && (units < end)) {
293 int units_valid = 0;
294
295 if (units < end - 3) {
296 ;
297 } else if (units == end - 2) {
298 if (!strcasecmp(units, "hz"))
299 units_valid = 1;
300 } else if (units == end - 3) {
301 if (!strcasecmp(units, "khz")) {
302 freq *= 1000;
303 units_valid = 1;
304 } else if (!strcasecmp(units, "mhz")) {
305 freq *= 1000000;
306 units_valid = 1;
307 }
308 }
309
310 if (!units_valid) {
311 msg_perr("Invalid units: %s\n", units);
312 return 1;
313 }
314 }
315
316 /* Assume we only work with bytes and transfer at 1 bit/Hz */
317 delay_us = (1000000 * 8) / freq;
318 }
319
hailfinger6ead7222010-11-01 22:07:04 +0000320#if EMULATE_CHIP
Louis Yung-Chieh Loe53fa0f2011-04-11 17:18:41 +0800321#if EMULATE_SPI_CHIP
322 tmp = extract_programmer_param("size");
323 if (tmp) {
324 int multiplier = 1;
Simon Glassd2c64a22013-07-03 22:05:21 +0900325 if (!strcmp(tmp, "auto"))
326 size = SIZE_AUTO;
327 else if (strlen(tmp)) {
Louis Yung-Chieh Loe53fa0f2011-04-11 17:18:41 +0800328 int remove_last_char = 1;
329 switch (tmp[strlen(tmp) - 1]) {
330 case 'k': case 'K':
331 multiplier = 1024;
332 break;
333 case 'm': case 'M':
334 multiplier = 1024 * 1024;
335 break;
336 default:
337 remove_last_char = 0;
338 break;
339 }
340 if (remove_last_char) tmp[strlen(tmp) - 1] = '\0';
Simon Glassd2c64a22013-07-03 22:05:21 +0900341 size = atoi(tmp) * multiplier;
Louis Yung-Chieh Loe53fa0f2011-04-11 17:18:41 +0800342 }
Louis Yung-Chieh Loe53fa0f2011-04-11 17:18:41 +0800343 }
344#endif
345
hailfinger6ead7222010-11-01 22:07:04 +0000346 tmp = extract_programmer_param("emulate");
347 if (!tmp) {
348 msg_pdbg("Not emulating any flash chip.\n");
349 /* Nothing else to do. */
dhendrix0ffc2eb2011-06-14 01:35:36 +0000350 goto dummy_init_out;
hailfinger6ead7222010-11-01 22:07:04 +0000351 }
David Hendricks84377002014-09-09 16:09:31 -0700352
hailfinger6ead7222010-11-01 22:07:04 +0000353#if EMULATE_SPI_CHIP
354 if (!strcmp(tmp, "M25P10.RES")) {
355 emu_chip = EMULATE_ST_M25P10_RES;
356 emu_chip_size = 128 * 1024;
357 emu_max_byteprogram_size = 128;
358 emu_max_aai_size = 0;
359 emu_jedec_se_size = 0;
360 emu_jedec_be_52_size = 0;
361 emu_jedec_be_d8_size = 32 * 1024;
362 emu_jedec_ce_60_size = 0;
363 emu_jedec_ce_c7_size = emu_chip_size;
364 msg_pdbg("Emulating ST M25P10.RES SPI flash chip (RES, page "
365 "write)\n");
366 }
367 if (!strcmp(tmp, "SST25VF040.REMS")) {
368 emu_chip = EMULATE_SST_SST25VF040_REMS;
369 emu_chip_size = 512 * 1024;
370 emu_max_byteprogram_size = 1;
371 emu_max_aai_size = 0;
372 emu_jedec_se_size = 4 * 1024;
373 emu_jedec_be_52_size = 32 * 1024;
374 emu_jedec_be_d8_size = 0;
375 emu_jedec_ce_60_size = emu_chip_size;
376 emu_jedec_ce_c7_size = 0;
377 msg_pdbg("Emulating SST SST25VF040.REMS SPI flash chip (REMS, "
378 "byte write)\n");
379 }
380 if (!strcmp(tmp, "SST25VF032B")) {
381 emu_chip = EMULATE_SST_SST25VF032B;
382 emu_chip_size = 4 * 1024 * 1024;
383 emu_max_byteprogram_size = 1;
384 emu_max_aai_size = 2;
385 emu_jedec_se_size = 4 * 1024;
386 emu_jedec_be_52_size = 32 * 1024;
387 emu_jedec_be_d8_size = 64 * 1024;
388 emu_jedec_ce_60_size = emu_chip_size;
389 emu_jedec_ce_c7_size = emu_chip_size;
390 msg_pdbg("Emulating SST SST25VF032B SPI flash chip (RDID, AAI "
391 "write)\n");
392 }
Simon Glassd2c64a22013-07-03 22:05:21 +0900393 emu_persistent_image = extract_programmer_param("image");
394 if (!stat(emu_persistent_image, &image_stat))
395 image_size = image_stat.st_size;
396
Louis Yung-Chieh Loe53fa0f2011-04-11 17:18:41 +0800397 if (!strncmp(tmp, VARIABLE_SIZE_CHIP_NAME,
398 strlen(VARIABLE_SIZE_CHIP_NAME))) {
Simon Glassd2c64a22013-07-03 22:05:21 +0900399 if (size == SIZE_UNKNOWN) {
Louis Yung-Chieh Loe53fa0f2011-04-11 17:18:41 +0800400 msg_perr("%s: the size parameter is not given.\n",
401 __func__);
402 free(tmp);
403 return 1;
Simon Glassd2c64a22013-07-03 22:05:21 +0900404 } else if (size == SIZE_AUTO) {
405 if (image_size == SIZE_UNKNOWN) {
406 msg_perr("%s: no image so cannot use automatic size.\n",
407 __func__);
408 free(tmp);
409 return 1;
410 }
411 size = image_size;
Louis Yung-Chieh Loe53fa0f2011-04-11 17:18:41 +0800412 }
413 emu_chip = EMULATE_VARIABLE_SIZE;
414 emu_chip_size = size;
415 emu_max_byteprogram_size = 256;
416 emu_max_aai_size = 0;
417 emu_jedec_se_size = 4 * 1024;
418 emu_jedec_be_52_size = 32 * 1024;
419 emu_jedec_be_d8_size = 64 * 1024;
420 emu_jedec_ce_60_size = emu_chip_size;
421 emu_jedec_ce_c7_size = emu_chip_size;
422 msg_pdbg("Emulating generic SPI flash chip (size=%d bytes)\n",
423 emu_chip_size);
424 }
hailfinger6ead7222010-11-01 22:07:04 +0000425#endif
426 if (emu_chip == EMULATE_NONE) {
427 msg_perr("Invalid chip specified for emulation: %s\n", tmp);
428 free(tmp);
429 return 1;
430 }
David Hendricks0eda2a82014-09-12 16:32:05 -0700431
432 /* Should emulated flash erase to zero (yes/no)? */
433 tmp = extract_programmer_param("erase_to_zero");
434 if (tmp) {
435 if (!strcmp(tmp, "yes")) {
436 msg_pdbg("Emulated chip will erase to 0x00\n");
437 erase_to_zero = 1;
438 } else if (!strcmp(tmp, "no")) {
439 msg_pdbg("Emulated chip will erase to 0xff\n");
440 } else {
441 msg_perr("erase_to_zero can be \"yes\" or \"no\"\n");
442 return 1;
443 }
444 }
445
hailfinger6ead7222010-11-01 22:07:04 +0000446 free(tmp);
447 flashchip_contents = malloc(emu_chip_size);
448 if (!flashchip_contents) {
449 msg_perr("Out of memory!\n");
450 return 1;
451 }
dhendrix0ffc2eb2011-06-14 01:35:36 +0000452
David Hendricks0eda2a82014-09-12 16:32:05 -0700453 msg_pdbg("Filling fake flash chip with 0x%02x, size %i\n",
454 erase_to_zero ? 0x00 : 0xff, emu_chip_size);
455 memset(flashchip_contents, erase_to_zero ? 0x00 : 0xff, emu_chip_size);
hailfinger6ead7222010-11-01 22:07:04 +0000456
hailfinger6ead7222010-11-01 22:07:04 +0000457 if (!emu_persistent_image) {
458 /* Nothing else to do. */
dhendrix0ffc2eb2011-06-14 01:35:36 +0000459 goto dummy_init_out;
hailfinger6ead7222010-11-01 22:07:04 +0000460 }
461 if (!stat(emu_persistent_image, &image_stat)) {
462 msg_pdbg("Found persistent image %s, size %li ",
463 emu_persistent_image, (long)image_stat.st_size);
464 if (image_stat.st_size == emu_chip_size) {
465 msg_pdbg("matches.\n");
466 msg_pdbg("Reading %s\n", emu_persistent_image);
467 read_buf_from_file(flashchip_contents, emu_chip_size,
468 emu_persistent_image);
469 } else {
470 msg_pdbg("doesn't match.\n");
471 }
472 }
473#endif
hailfingera9df33c2009-05-09 00:54:55 +0000474
dhendrix0ffc2eb2011-06-14 01:35:36 +0000475dummy_init_out:
476 if (register_shutdown(dummy_shutdown, NULL)) {
hailfinger6ead7222010-11-01 22:07:04 +0000477 free(flashchip_contents);
dhendrix0ffc2eb2011-06-14 01:35:36 +0000478 return 1;
hailfinger6ead7222010-11-01 22:07:04 +0000479 }
hailfinger76bb7e92011-11-09 23:40:00 +0000480 if (dummy_buses_supported & (BUS_PARALLEL | BUS_LPC | BUS_FWH))
Patrick Georgi0a9533a2017-02-03 19:28:38 +0100481 register_par_master(&par_master_dummy,
hailfinger76bb7e92011-11-09 23:40:00 +0000482 dummy_buses_supported &
483 (BUS_PARALLEL | BUS_LPC |
484 BUS_FWH));
485 if (dummy_buses_supported & BUS_SPI)
Patrick Georgif4f1e2f2017-03-10 17:38:40 +0100486 register_spi_master(&spi_master_dummyflasher);
hailfinger76bb7e92011-11-09 23:40:00 +0000487
hailfingera9df33c2009-05-09 00:54:55 +0000488 return 0;
489}
490
Patrick Georgi4befc162017-02-03 18:32:01 +0100491void *dummy_map(const char *descr, uintptr_t phys_addr, size_t len)
hailfinger11ae3c42009-05-11 14:13:25 +0000492{
Patrick Georgi4befc162017-02-03 18:32:01 +0100493 msg_pspew("%s: Mapping %s, 0x%lx bytes at %" PRIxPTR "\n",
hailfinger50c335f2010-01-09 04:32:23 +0000494 __func__, descr, (unsigned long)len, phys_addr);
hailfinger11ae3c42009-05-11 14:13:25 +0000495 return (void *)phys_addr;
496}
497
498void dummy_unmap(void *virt_addr, size_t len)
499{
hailfinger50c335f2010-01-09 04:32:23 +0000500 msg_pspew("%s: Unmapping 0x%lx bytes at %p\n",
501 __func__, (unsigned long)len, virt_addr);
hailfinger11ae3c42009-05-11 14:13:25 +0000502}
503
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700504void dummy_chip_writeb(const struct flashctx *flash, uint8_t val, chipaddr addr)
hailfingera9df33c2009-05-09 00:54:55 +0000505{
hailfinger50c335f2010-01-09 04:32:23 +0000506 msg_pspew("%s: addr=0x%lx, val=0x%02x\n", __func__, addr, val);
hailfingera9df33c2009-05-09 00:54:55 +0000507}
508
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700509void dummy_chip_writew(const struct flashctx *flash, uint16_t val, chipaddr addr)
hailfingera9df33c2009-05-09 00:54:55 +0000510{
hailfinger50c335f2010-01-09 04:32:23 +0000511 msg_pspew("%s: addr=0x%lx, val=0x%04x\n", __func__, addr, val);
hailfingera9df33c2009-05-09 00:54:55 +0000512}
513
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700514void dummy_chip_writel(const struct flashctx *flash, uint32_t val, chipaddr addr)
hailfingera9df33c2009-05-09 00:54:55 +0000515{
hailfinger50c335f2010-01-09 04:32:23 +0000516 msg_pspew("%s: addr=0x%lx, val=0x%08x\n", __func__, addr, val);
hailfingera9df33c2009-05-09 00:54:55 +0000517}
518
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700519void dummy_chip_writen(const struct flashctx *flash, uint8_t *buf, chipaddr addr, size_t len)
hailfinger9d987ef2009-06-05 18:32:07 +0000520{
521 size_t i;
hailfinger50c335f2010-01-09 04:32:23 +0000522 msg_pspew("%s: addr=0x%lx, len=0x%08lx, writing data (hex):",
523 __func__, addr, (unsigned long)len);
hailfinger9d987ef2009-06-05 18:32:07 +0000524 for (i = 0; i < len; i++) {
525 if ((i % 16) == 0)
hailfinger50c335f2010-01-09 04:32:23 +0000526 msg_pspew("\n");
527 msg_pspew("%02x ", buf[i]);
hailfinger9d987ef2009-06-05 18:32:07 +0000528 }
529}
530
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700531uint8_t dummy_chip_readb(const struct flashctx *flash, const chipaddr addr)
hailfingera9df33c2009-05-09 00:54:55 +0000532{
hailfinger50c335f2010-01-09 04:32:23 +0000533 msg_pspew("%s: addr=0x%lx, returning 0xff\n", __func__, addr);
hailfingera9df33c2009-05-09 00:54:55 +0000534 return 0xff;
535}
536
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700537uint16_t dummy_chip_readw(const struct flashctx *flash, const chipaddr addr)
hailfingera9df33c2009-05-09 00:54:55 +0000538{
hailfinger50c335f2010-01-09 04:32:23 +0000539 msg_pspew("%s: addr=0x%lx, returning 0xffff\n", __func__, addr);
hailfingera9df33c2009-05-09 00:54:55 +0000540 return 0xffff;
541}
542
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700543uint32_t dummy_chip_readl(const struct flashctx *flash, const chipaddr addr)
hailfingera9df33c2009-05-09 00:54:55 +0000544{
hailfinger50c335f2010-01-09 04:32:23 +0000545 msg_pspew("%s: addr=0x%lx, returning 0xffffffff\n", __func__, addr);
hailfingera9df33c2009-05-09 00:54:55 +0000546 return 0xffffffff;
547}
548
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700549void dummy_chip_readn(const struct flashctx *flash, uint8_t *buf, const chipaddr addr, size_t len)
hailfinger9d987ef2009-06-05 18:32:07 +0000550{
hailfinger50c335f2010-01-09 04:32:23 +0000551 msg_pspew("%s: addr=0x%lx, len=0x%lx, returning array of 0xff\n",
552 __func__, addr, (unsigned long)len);
hailfinger9d987ef2009-06-05 18:32:07 +0000553 memset(buf, 0xff, len);
554 return;
555}
556
hailfinger6ead7222010-11-01 22:07:04 +0000557#if EMULATE_SPI_CHIP
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700558static int emulate_spi_chip_response(const struct flashctx *flash, unsigned int writecnt, unsigned int readcnt,
hailfinger6ead7222010-11-01 22:07:04 +0000559 const unsigned char *writearr, unsigned char *readarr)
560{
Carl-Daniel Hailfingerc49783d2016-08-05 10:52:06 -0700561 unsigned int offs, i;
stefanctc5eb8a92011-11-23 09:13:48 +0000562 static int unsigned aai_offs;
hailfinger6ead7222010-11-01 22:07:04 +0000563 static int aai_active = 0;
564
565 if (writecnt == 0) {
566 msg_perr("No command sent to the chip!\n");
567 return 1;
568 }
Stefan Tauner718d1eb2016-08-18 18:00:53 -0700569 /* spi_blacklist has precedence over spi_ignorelist. */
Carl-Daniel Hailfingerc49783d2016-08-05 10:52:06 -0700570 for (i = 0; i < spi_blacklist_size; i++) {
571 if (writearr[0] == spi_blacklist[i]) {
572 msg_pdbg("Refusing blacklisted SPI command 0x%02x\n",
573 spi_blacklist[i]);
574 return SPI_INVALID_OPCODE;
575 }
576 }
577 for (i = 0; i < spi_ignorelist_size; i++) {
578 if (writearr[0] == spi_ignorelist[i]) {
579 msg_cdbg("Ignoring ignorelisted SPI command 0x%02x\n",
580 spi_ignorelist[i]);
581 /* Return success because the command does not fail,
582 * it is simply ignored.
583 */
584 return 0;
585 }
586 }
hailfinger6ead7222010-11-01 22:07:04 +0000587 switch (writearr[0]) {
588 case JEDEC_RES:
589 if (emu_chip != EMULATE_ST_M25P10_RES)
590 break;
591 /* Respond with ST_M25P10_RES. */
592 if (readcnt > 0)
593 readarr[0] = 0x10;
594 break;
595 case JEDEC_REMS:
596 if (emu_chip != EMULATE_SST_SST25VF040_REMS)
597 break;
598 /* Respond with SST_SST25VF040_REMS. */
599 if (readcnt > 0)
600 readarr[0] = 0xbf;
601 if (readcnt > 1)
602 readarr[1] = 0x44;
603 break;
604 case JEDEC_RDID:
Louis Yung-Chieh Loe53fa0f2011-04-11 17:18:41 +0800605 if (emu_chip == EMULATE_SST_SST25VF032B) {
606 /* Respond with SST_SST25VF032B. */
607 if (readcnt > 0)
608 readarr[0] = 0xbf;
609 if (readcnt > 1)
610 readarr[1] = 0x25;
611 if (readcnt > 2)
612 readarr[2] = 0x4a;
613 } else if (emu_chip == EMULATE_VARIABLE_SIZE) {
614 const uint16_t man_id = VARIABLE_SIZE_MANUF_ID;
615 const uint16_t dev_id = VARIABLE_SIZE_DEVICE_ID;
616 if (readcnt > 0) readarr[0] = man_id >> 8;
617 if (readcnt > 1) readarr[1] = man_id & 0xff;
618 if (readcnt > 2) readarr[2] = dev_id >> 8;
619 if (readcnt > 3) readarr[3] = dev_id & 0xff;
620 }
hailfinger6ead7222010-11-01 22:07:04 +0000621 break;
622 case JEDEC_RDSR:
623 memset(readarr, 0, readcnt);
624 if (aai_active)
625 memset(readarr, 1 << 6, readcnt);
626 break;
627 case JEDEC_READ:
628 offs = writearr[1] << 16 | writearr[2] << 8 | writearr[3];
629 /* Truncate to emu_chip_size. */
630 offs %= emu_chip_size;
631 if (readcnt > 0)
632 memcpy(readarr, flashchip_contents + offs, readcnt);
633 break;
634 case JEDEC_BYTE_PROGRAM:
635 offs = writearr[1] << 16 | writearr[2] << 8 | writearr[3];
636 /* Truncate to emu_chip_size. */
637 offs %= emu_chip_size;
638 if (writecnt < 5) {
639 msg_perr("BYTE PROGRAM size too short!\n");
640 return 1;
641 }
642 if (writecnt - 4 > emu_max_byteprogram_size) {
643 msg_perr("Max BYTE PROGRAM size exceeded!\n");
644 return 1;
645 }
646 memcpy(flashchip_contents + offs, writearr + 4, writecnt - 4);
Simon Glasscf253a72013-07-10 21:10:11 -0700647 emu_modified = 1;
hailfinger6ead7222010-11-01 22:07:04 +0000648 break;
649 case JEDEC_AAI_WORD_PROGRAM:
650 if (!emu_max_aai_size)
651 break;
652 if (!aai_active) {
653 if (writecnt < JEDEC_AAI_WORD_PROGRAM_OUTSIZE) {
654 msg_perr("Initial AAI WORD PROGRAM size too "
655 "short!\n");
656 return 1;
657 }
658 if (writecnt > JEDEC_AAI_WORD_PROGRAM_OUTSIZE) {
659 msg_perr("Initial AAI WORD PROGRAM size too "
660 "long!\n");
661 return 1;
662 }
663 aai_active = 1;
664 aai_offs = writearr[1] << 16 | writearr[2] << 8 |
665 writearr[3];
666 /* Truncate to emu_chip_size. */
667 aai_offs %= emu_chip_size;
668 memcpy(flashchip_contents + aai_offs, writearr + 4, 2);
669 aai_offs += 2;
670 } else {
671 if (writecnt < JEDEC_AAI_WORD_PROGRAM_CONT_OUTSIZE) {
672 msg_perr("Continuation AAI WORD PROGRAM size "
673 "too short!\n");
674 return 1;
675 }
676 if (writecnt > JEDEC_AAI_WORD_PROGRAM_CONT_OUTSIZE) {
677 msg_perr("Continuation AAI WORD PROGRAM size "
678 "too long!\n");
679 return 1;
680 }
681 memcpy(flashchip_contents + aai_offs, writearr + 1, 2);
682 aai_offs += 2;
683 }
Simon Glasscf253a72013-07-10 21:10:11 -0700684 emu_modified = 1;
hailfinger6ead7222010-11-01 22:07:04 +0000685 break;
686 case JEDEC_WRDI:
687 if (!emu_max_aai_size)
688 break;
689 aai_active = 0;
690 break;
691 case JEDEC_SE:
692 if (!emu_jedec_se_size)
693 break;
694 if (writecnt != JEDEC_SE_OUTSIZE) {
695 msg_perr("SECTOR ERASE 0x20 outsize invalid!\n");
696 return 1;
697 }
698 if (readcnt != JEDEC_SE_INSIZE) {
699 msg_perr("SECTOR ERASE 0x20 insize invalid!\n");
700 return 1;
701 }
702 offs = writearr[1] << 16 | writearr[2] << 8 | writearr[3];
703 if (offs & (emu_jedec_se_size - 1))
hailfingere53f5e42011-02-04 22:52:04 +0000704 msg_pdbg("Unaligned SECTOR ERASE 0x20: 0x%x\n", offs);
hailfinger6ead7222010-11-01 22:07:04 +0000705 offs &= ~(emu_jedec_se_size - 1);
706 memset(flashchip_contents + offs, 0xff, emu_jedec_se_size);
Simon Glasscf253a72013-07-10 21:10:11 -0700707 emu_modified = 1;
hailfinger6ead7222010-11-01 22:07:04 +0000708 break;
709 case JEDEC_BE_52:
710 if (!emu_jedec_be_52_size)
711 break;
712 if (writecnt != JEDEC_BE_52_OUTSIZE) {
713 msg_perr("BLOCK ERASE 0x52 outsize invalid!\n");
714 return 1;
715 }
716 if (readcnt != JEDEC_BE_52_INSIZE) {
717 msg_perr("BLOCK ERASE 0x52 insize invalid!\n");
718 return 1;
719 }
720 offs = writearr[1] << 16 | writearr[2] << 8 | writearr[3];
721 if (offs & (emu_jedec_be_52_size - 1))
hailfingere53f5e42011-02-04 22:52:04 +0000722 msg_pdbg("Unaligned BLOCK ERASE 0x52: 0x%x\n", offs);
hailfinger6ead7222010-11-01 22:07:04 +0000723 offs &= ~(emu_jedec_be_52_size - 1);
724 memset(flashchip_contents + offs, 0xff, emu_jedec_be_52_size);
Simon Glasscf253a72013-07-10 21:10:11 -0700725 emu_modified = 1;
hailfinger6ead7222010-11-01 22:07:04 +0000726 break;
727 case JEDEC_BE_D8:
728 if (!emu_jedec_be_d8_size)
729 break;
730 if (writecnt != JEDEC_BE_D8_OUTSIZE) {
731 msg_perr("BLOCK ERASE 0xd8 outsize invalid!\n");
732 return 1;
733 }
734 if (readcnt != JEDEC_BE_D8_INSIZE) {
735 msg_perr("BLOCK ERASE 0xd8 insize invalid!\n");
736 return 1;
737 }
738 offs = writearr[1] << 16 | writearr[2] << 8 | writearr[3];
739 if (offs & (emu_jedec_be_d8_size - 1))
hailfingere53f5e42011-02-04 22:52:04 +0000740 msg_pdbg("Unaligned BLOCK ERASE 0xd8: 0x%x\n", offs);
hailfinger6ead7222010-11-01 22:07:04 +0000741 offs &= ~(emu_jedec_be_d8_size - 1);
742 memset(flashchip_contents + offs, 0xff, emu_jedec_be_d8_size);
743 break;
744 case JEDEC_CE_60:
745 if (!emu_jedec_ce_60_size)
746 break;
747 if (writecnt != JEDEC_CE_60_OUTSIZE) {
748 msg_perr("CHIP ERASE 0x60 outsize invalid!\n");
749 return 1;
750 }
751 if (readcnt != JEDEC_CE_60_INSIZE) {
752 msg_perr("CHIP ERASE 0x60 insize invalid!\n");
753 return 1;
754 }
hailfingere53f5e42011-02-04 22:52:04 +0000755 /* JEDEC_CE_60_OUTSIZE is 1 (no address) -> no offset. */
hailfinger6ead7222010-11-01 22:07:04 +0000756 /* emu_jedec_ce_60_size is emu_chip_size. */
hailfingere53f5e42011-02-04 22:52:04 +0000757 memset(flashchip_contents, 0xff, emu_jedec_ce_60_size);
Simon Glasscf253a72013-07-10 21:10:11 -0700758 emu_modified = 1;
hailfinger6ead7222010-11-01 22:07:04 +0000759 break;
760 case JEDEC_CE_C7:
761 if (!emu_jedec_ce_c7_size)
762 break;
763 if (writecnt != JEDEC_CE_C7_OUTSIZE) {
764 msg_perr("CHIP ERASE 0xc7 outsize invalid!\n");
765 return 1;
766 }
767 if (readcnt != JEDEC_CE_C7_INSIZE) {
768 msg_perr("CHIP ERASE 0xc7 insize invalid!\n");
769 return 1;
770 }
hailfingere53f5e42011-02-04 22:52:04 +0000771 /* JEDEC_CE_C7_OUTSIZE is 1 (no address) -> no offset. */
hailfinger6ead7222010-11-01 22:07:04 +0000772 /* emu_jedec_ce_c7_size is emu_chip_size. */
773 memset(flashchip_contents, 0xff, emu_jedec_ce_c7_size);
Simon Glasscf253a72013-07-10 21:10:11 -0700774 emu_modified = 1;
hailfinger6ead7222010-11-01 22:07:04 +0000775 break;
776 default:
777 /* No special response. */
778 break;
779 }
780 return 0;
781}
782#endif
783
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700784static int dummy_spi_send_command(const struct flashctx *flash, unsigned int writecnt, unsigned int readcnt,
hailfingerf91e3b52009-05-14 12:59:36 +0000785 const unsigned char *writearr, unsigned char *readarr)
786{
787 int i;
788
hailfinger50c335f2010-01-09 04:32:23 +0000789 msg_pspew("%s:", __func__);
hailfingerf91e3b52009-05-14 12:59:36 +0000790
hailfinger50c335f2010-01-09 04:32:23 +0000791 msg_pspew(" writing %u bytes:", writecnt);
hailfingerf91e3b52009-05-14 12:59:36 +0000792 for (i = 0; i < writecnt; i++)
hailfinger50c335f2010-01-09 04:32:23 +0000793 msg_pspew(" 0x%02x", writearr[i]);
hailfingerf91e3b52009-05-14 12:59:36 +0000794
hailfinger6ead7222010-11-01 22:07:04 +0000795 /* Response for unknown commands and missing chip is 0xff. */
796 memset(readarr, 0xff, readcnt);
797#if EMULATE_SPI_CHIP
798 switch (emu_chip) {
799 case EMULATE_ST_M25P10_RES:
800 case EMULATE_SST_SST25VF040_REMS:
801 case EMULATE_SST_SST25VF032B:
Louis Yung-Chieh Loe53fa0f2011-04-11 17:18:41 +0800802 case EMULATE_VARIABLE_SIZE:
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700803 if (emulate_spi_chip_response(flash, writecnt, readcnt, writearr,
hailfinger6ead7222010-11-01 22:07:04 +0000804 readarr)) {
Carl-Daniel Hailfingerc49783d2016-08-05 10:52:06 -0700805 msg_pdbg("Invalid command sent to flash chip!\n");
hailfinger6ead7222010-11-01 22:07:04 +0000806 return 1;
807 }
808 break;
809 default:
810 break;
811 }
812#endif
hailfinger50c335f2010-01-09 04:32:23 +0000813 msg_pspew(" reading %u bytes:", readcnt);
uwe8d342eb2011-07-28 08:13:25 +0000814 for (i = 0; i < readcnt; i++)
hailfinger6ead7222010-11-01 22:07:04 +0000815 msg_pspew(" 0x%02x", readarr[i]);
hailfinger50c335f2010-01-09 04:32:23 +0000816 msg_pspew("\n");
David Hendricks84377002014-09-09 16:09:31 -0700817
818 programmer_delay((writecnt + readcnt) * delay_us);
hailfingerf91e3b52009-05-14 12:59:36 +0000819 return 0;
820}
hailfingera8727712010-06-20 10:58:32 +0000821
Patrick Georgiab8353e2017-02-03 18:32:01 +0100822static int dummy_spi_write_256(struct flashctx *flash, const uint8_t *buf,
stefanctc5eb8a92011-11-23 09:13:48 +0000823 unsigned int start, unsigned int len)
hailfingerc7d06c62010-07-14 16:19:05 +0000824{
hailfinger6ead7222010-11-01 22:07:04 +0000825 return spi_write_chunked(flash, buf, start, len,
826 spi_write_256_chunksize);
hailfingerc7d06c62010-07-14 16:19:05 +0000827}
Louis Yung-Chieh Loe53fa0f2011-04-11 17:18:41 +0800828
829#if EMULATE_CHIP && EMULATE_SPI_CHIP
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700830int probe_variable_size(struct flashctx *flash)
Louis Yung-Chieh Loe53fa0f2011-04-11 17:18:41 +0800831{
832 int i;
833
834 /* Skip the probing if we don't emulate this chip. */
835 if (emu_chip != EMULATE_VARIABLE_SIZE)
836 return 0;
837
838 /*
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700839 * This will break if one day flashctx becomes read-only.
Louis Yung-Chieh Loe53fa0f2011-04-11 17:18:41 +0800840 * Once that happens, we need to have special hacks in functions:
841 *
842 * erase_and_write_flash() in flashrom.c
843 * read_flash_to_file()
844 * handle_romentries()
845 * ...
846 *
847 * Search "total_size * 1024" in code.
848 */
849 if (emu_chip_size % 1024)
850 msg_perr("%s: emu_chip_size is not multipler of 1024.\n",
851 __func__);
Patrick Georgif3fa2992017-02-02 16:24:44 +0100852 flash->chip->total_size = emu_chip_size / 1024;
Louis Yung-Chieh Loe53fa0f2011-04-11 17:18:41 +0800853 msg_cdbg("%s: set flash->total_size to %dK bytes.\n", __func__,
Patrick Georgif3fa2992017-02-02 16:24:44 +0100854 flash->chip->total_size);
Louis Yung-Chieh Loe53fa0f2011-04-11 17:18:41 +0800855
David Hendricks0eda2a82014-09-12 16:32:05 -0700856 if (erase_to_zero)
Patrick Georgif3fa2992017-02-02 16:24:44 +0100857 flash->chip->feature_bits |= FEATURE_ERASE_TO_ZERO;
David Hendricks0eda2a82014-09-12 16:32:05 -0700858
Louis Yung-Chieh Loe53fa0f2011-04-11 17:18:41 +0800859 /* Update eraser count */
860 for (i = 0; i < NUM_ERASEFUNCTIONS; i++) {
Patrick Georgif3fa2992017-02-02 16:24:44 +0100861 struct block_eraser *eraser = &flash->chip->block_erasers[i];
Louis Yung-Chieh Loe53fa0f2011-04-11 17:18:41 +0800862 if (eraser->block_erase == NULL)
863 break;
864
865 eraser->eraseblocks[0].count = emu_chip_size /
866 eraser->eraseblocks[0].size;
867 msg_cdbg("%s: eraser.size=%d, .count=%d\n",
868 __func__, eraser->eraseblocks[0].size,
869 eraser->eraseblocks[0].count);
870 }
871
872 return 1;
873}
874#endif