blob: e37624c51c4c7c7a265c19aeea0443a61c60ae8f [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 *
hailfingera9df33c2009-05-09 00:54:55 +000015 */
16
David Hendricks84377002014-09-09 16:09:31 -070017#include <errno.h>
hailfingera9df33c2009-05-09 00:54:55 +000018#include <string.h>
19#include <stdlib.h>
Carl-Daniel Hailfingerc49783d2016-08-05 10:52:06 -070020#include <stdio.h>
21#include <ctype.h>
Patrick Georgi4befc162017-02-03 18:32:01 +010022#include <inttypes.h>
hailfingera9df33c2009-05-09 00:54:55 +000023#include "flash.h"
hailfingera8727712010-06-20 10:58:32 +000024#include "chipdrivers.h"
hailfinger428f6852010-07-27 22:41:39 +000025#include "programmer.h"
Louis Yung-Chieh Loe53fa0f2011-04-11 17:18:41 +080026#include "flashchips.h"
hailfingera9df33c2009-05-09 00:54:55 +000027
hailfinger6ead7222010-11-01 22:07:04 +000028/* Remove the #define below if you don't want SPI flash chip emulation. */
29#define EMULATE_SPI_CHIP 1
30
31#if EMULATE_SPI_CHIP
32#define EMULATE_CHIP 1
33#include "spi.h"
34#endif
35
36#if EMULATE_CHIP
37#include <sys/types.h>
38#include <sys/stat.h>
Louis Yung-Chieh Loe53fa0f2011-04-11 17:18:41 +080039
40#if EMULATE_SPI_CHIP
41/* The name of variable-size virtual chip. A 4MB flash example:
42 * flashrom -p dummy:emulate=VARIABLE_SIZE,size=4194304
43 */
44#define VARIABLE_SIZE_CHIP_NAME "VARIABLE_SIZE"
Edward O'Callaghanef4e28b2019-06-28 13:18:41 +100045static unsigned char spi_blacklist[256];
46static unsigned char spi_ignorelist[256];
47static int spi_blacklist_size = 0;
48static int spi_ignorelist_size = 0;
Louis Yung-Chieh Loe53fa0f2011-04-11 17:18:41 +080049#endif
hailfinger6ead7222010-11-01 22:07:04 +000050#endif
51
52#if EMULATE_CHIP
53static uint8_t *flashchip_contents = NULL;
54enum emu_chip {
55 EMULATE_NONE,
56 EMULATE_ST_M25P10_RES,
57 EMULATE_SST_SST25VF040_REMS,
58 EMULATE_SST_SST25VF032B,
Louis Yung-Chieh Loe53fa0f2011-04-11 17:18:41 +080059 EMULATE_VARIABLE_SIZE,
hailfinger6ead7222010-11-01 22:07:04 +000060};
61static enum emu_chip emu_chip = EMULATE_NONE;
62static char *emu_persistent_image = NULL;
stefanctc5eb8a92011-11-23 09:13:48 +000063static unsigned int emu_chip_size = 0;
Simon Glasscf253a72013-07-10 21:10:11 -070064static int emu_modified; /* is the image modified since reading it? */
David Hendricks0eda2a82014-09-12 16:32:05 -070065static int erase_to_zero;
hailfinger6ead7222010-11-01 22:07:04 +000066#if EMULATE_SPI_CHIP
stefanctc5eb8a92011-11-23 09:13:48 +000067static unsigned int emu_max_byteprogram_size = 0;
68static unsigned int emu_max_aai_size = 0;
69static unsigned int emu_jedec_se_size = 0;
70static unsigned int emu_jedec_be_52_size = 0;
71static unsigned int emu_jedec_be_d8_size = 0;
72static unsigned int emu_jedec_ce_60_size = 0;
73static unsigned int emu_jedec_ce_c7_size = 0;
hailfinger6ead7222010-11-01 22:07:04 +000074#endif
75#endif
76
stefanctc5eb8a92011-11-23 09:13:48 +000077static unsigned int spi_write_256_chunksize = 256;
hailfinger6ead7222010-11-01 22:07:04 +000078
David Hendricks84377002014-09-09 16:09:31 -070079/* If "freq" parameter is passed in from command line, commands will delay
80 * for this period before returning. */
81static unsigned long int delay_us = 0;
82
Souvik Ghoshd75cd672016-06-17 14:21:39 -070083static int dummy_spi_send_command(const struct flashctx *flash, unsigned int writecnt, unsigned int readcnt,
mkarcherd264e9e2011-05-11 17:07:07 +000084 const unsigned char *writearr, unsigned char *readarr);
Patrick Georgiab8353e2017-02-03 18:32:01 +010085static int dummy_spi_write_256(struct flashctx *flash, const uint8_t *buf,
stefanctc5eb8a92011-11-23 09:13:48 +000086 unsigned int start, unsigned int len);
Souvik Ghoshd75cd672016-06-17 14:21:39 -070087static void dummy_chip_writeb(const struct flashctx *flash, uint8_t val,
88 chipaddr addr);
89static void dummy_chip_writew(const struct flashctx *flash, uint16_t val,
90 chipaddr addr);
91static void dummy_chip_writel(const struct flashctx *flash, uint32_t val,
92 chipaddr addr);
93static void dummy_chip_writen(const struct flashctx *flash, uint8_t *buf,
94 chipaddr addr, size_t len);
95static uint8_t dummy_chip_readb(const struct flashctx *flash,
96 const chipaddr addr);
97static uint16_t dummy_chip_readw(const struct flashctx *flash,
98 const chipaddr addr);
99static uint32_t dummy_chip_readl(const struct flashctx *flash,
100 const chipaddr addr);
101static void dummy_chip_readn(const struct flashctx *flash, uint8_t *buf,
102 const chipaddr addr, size_t len);
mkarcherd264e9e2011-05-11 17:07:07 +0000103
Patrick Georgif4f1e2f2017-03-10 17:38:40 +0100104static const struct spi_master spi_master_dummyflasher = {
uwe8d342eb2011-07-28 08:13:25 +0000105 .type = SPI_CONTROLLER_DUMMY,
106 .max_data_read = MAX_DATA_READ_UNLIMITED,
107 .max_data_write = MAX_DATA_UNSPECIFIED,
108 .command = dummy_spi_send_command,
109 .multicommand = default_spi_send_multicommand,
110 .read = default_spi_read,
111 .write_256 = dummy_spi_write_256,
mkarcherd264e9e2011-05-11 17:07:07 +0000112};
dhendrix0ffc2eb2011-06-14 01:35:36 +0000113
Patrick Georgi0a9533a2017-02-03 19:28:38 +0100114static const struct par_master par_master_dummy = {
hailfinger76bb7e92011-11-09 23:40:00 +0000115 .chip_readb = dummy_chip_readb,
116 .chip_readw = dummy_chip_readw,
117 .chip_readl = dummy_chip_readl,
118 .chip_readn = dummy_chip_readn,
119 .chip_writeb = dummy_chip_writeb,
120 .chip_writew = dummy_chip_writew,
121 .chip_writel = dummy_chip_writel,
122 .chip_writen = dummy_chip_writen,
123};
124
Edward O'Callaghanef4e28b2019-06-28 13:18:41 +1000125static enum chipbustype dummy_buses_supported = BUS_NONE;
hailfinger76bb7e92011-11-09 23:40:00 +0000126
David Hendricks93784b42016-08-09 17:00:38 -0700127static int dummy_shutdown(void *data)
dhendrix0ffc2eb2011-06-14 01:35:36 +0000128{
129 msg_pspew("%s\n", __func__);
130#if EMULATE_CHIP
131 if (emu_chip != EMULATE_NONE) {
Simon Glasscf253a72013-07-10 21:10:11 -0700132 if (emu_persistent_image && emu_modified) {
dhendrix0ffc2eb2011-06-14 01:35:36 +0000133 msg_pdbg("Writing %s\n", emu_persistent_image);
134 write_buf_to_file(flashchip_contents, emu_chip_size,
135 emu_persistent_image);
136 }
137 free(flashchip_contents);
138 }
139#endif
140 return 0;
141}
142
Simon Glassd2c64a22013-07-03 22:05:21 +0900143/* Values for the 'size' parameter */
144enum {
145 SIZE_UNKNOWN = -1,
146 SIZE_AUTO = -2,
147};
148
David Hendricksac1d25c2016-08-09 17:00:58 -0700149int dummy_init(void)
hailfingera9df33c2009-05-09 00:54:55 +0000150{
hailfinger1ef766d2010-07-06 09:55:48 +0000151 char *bustext = NULL;
hailfinger6ead7222010-11-01 22:07:04 +0000152 char *tmp = NULL;
Carl-Daniel Hailfingerc49783d2016-08-05 10:52:06 -0700153 int i;
hailfinger6ead7222010-11-01 22:07:04 +0000154#if EMULATE_CHIP
155 struct stat image_stat;
Louis Yung-Chieh Loe53fa0f2011-04-11 17:18:41 +0800156#if EMULATE_SPI_CHIP
Simon Glassd2c64a22013-07-03 22:05:21 +0900157 int size = SIZE_UNKNOWN; /* size for generic chip */
Louis Yung-Chieh Loe53fa0f2011-04-11 17:18:41 +0800158#endif
hailfinger6ead7222010-11-01 22:07:04 +0000159#endif
Simon Glassd2c64a22013-07-03 22:05:21 +0900160 int image_size = SIZE_UNKNOWN;
hailfinger1ef766d2010-07-06 09:55:48 +0000161
hailfinger50c335f2010-01-09 04:32:23 +0000162 msg_pspew("%s\n", __func__);
hailfinger668f3502009-06-01 00:02:11 +0000163
hailfingerddeb4ac2010-07-08 10:13:37 +0000164 bustext = extract_programmer_param("bus");
hailfinger1ef766d2010-07-06 09:55:48 +0000165 msg_pdbg("Requested buses are: %s\n", bustext ? bustext : "default");
166 if (!bustext)
167 bustext = strdup("parallel+lpc+fwh+spi");
hailfinger668f3502009-06-01 00:02:11 +0000168 /* Convert the parameters to lowercase. */
hailfinger1ef766d2010-07-06 09:55:48 +0000169 tolower_string(bustext);
hailfinger668f3502009-06-01 00:02:11 +0000170
hailfinger76bb7e92011-11-09 23:40:00 +0000171 dummy_buses_supported = BUS_NONE;
hailfinger1ef766d2010-07-06 09:55:48 +0000172 if (strstr(bustext, "parallel")) {
hailfinger76bb7e92011-11-09 23:40:00 +0000173 dummy_buses_supported |= BUS_PARALLEL;
hailfinger50c335f2010-01-09 04:32:23 +0000174 msg_pdbg("Enabling support for %s flash.\n", "parallel");
hailfinger668f3502009-06-01 00:02:11 +0000175 }
hailfinger1ef766d2010-07-06 09:55:48 +0000176 if (strstr(bustext, "lpc")) {
hailfinger76bb7e92011-11-09 23:40:00 +0000177 dummy_buses_supported |= BUS_LPC;
hailfinger50c335f2010-01-09 04:32:23 +0000178 msg_pdbg("Enabling support for %s flash.\n", "LPC");
hailfinger668f3502009-06-01 00:02:11 +0000179 }
hailfinger1ef766d2010-07-06 09:55:48 +0000180 if (strstr(bustext, "fwh")) {
hailfinger76bb7e92011-11-09 23:40:00 +0000181 dummy_buses_supported |= BUS_FWH;
hailfinger50c335f2010-01-09 04:32:23 +0000182 msg_pdbg("Enabling support for %s flash.\n", "FWH");
hailfinger668f3502009-06-01 00:02:11 +0000183 }
hailfinger1ef766d2010-07-06 09:55:48 +0000184 if (strstr(bustext, "spi")) {
hailfinger76bb7e92011-11-09 23:40:00 +0000185 dummy_buses_supported |= BUS_SPI;
hailfinger50c335f2010-01-09 04:32:23 +0000186 msg_pdbg("Enabling support for %s flash.\n", "SPI");
hailfinger668f3502009-06-01 00:02:11 +0000187 }
hailfinger76bb7e92011-11-09 23:40:00 +0000188 if (dummy_buses_supported == BUS_NONE)
hailfinger50c335f2010-01-09 04:32:23 +0000189 msg_pdbg("Support for all flash bus types disabled.\n");
hailfinger1ef766d2010-07-06 09:55:48 +0000190 free(bustext);
hailfinger6ead7222010-11-01 22:07:04 +0000191
192 tmp = extract_programmer_param("spi_write_256_chunksize");
193 if (tmp) {
194 spi_write_256_chunksize = atoi(tmp);
195 free(tmp);
196 if (spi_write_256_chunksize < 1) {
197 msg_perr("invalid spi_write_256_chunksize\n");
198 return 1;
199 }
200 }
201
Carl-Daniel Hailfingerc49783d2016-08-05 10:52:06 -0700202 tmp = extract_programmer_param("spi_blacklist");
203 if (tmp) {
204 i = strlen(tmp);
205 if (!strncmp(tmp, "0x", 2)) {
206 i -= 2;
207 memmove(tmp, tmp + 2, i + 1);
208 }
209 if ((i > 512) || (i % 2)) {
210 msg_perr("Invalid SPI command blacklist length\n");
211 free(tmp);
212 return 1;
213 }
214 spi_blacklist_size = i / 2;
215 for (i = 0; i < spi_blacklist_size * 2; i++) {
216 if (!isxdigit((unsigned char)tmp[i])) {
217 msg_perr("Invalid char \"%c\" in SPI command "
218 "blacklist\n", tmp[i]);
219 free(tmp);
220 return 1;
221 }
222 }
223 for (i = 0; i < spi_blacklist_size; i++) {
224 unsigned int tmp2;
225 /* SCNx8 is apparently not supported by MSVC (and thus
226 * MinGW), so work around it with an extra variable
227 */
228 sscanf(tmp + i * 2, "%2x", &tmp2);
229 spi_blacklist[i] = (uint8_t)tmp2;
230 }
231 msg_pdbg("SPI blacklist is ");
232 for (i = 0; i < spi_blacklist_size; i++)
233 msg_pdbg("%02x ", spi_blacklist[i]);
234 msg_pdbg(", size %i\n", spi_blacklist_size);
235 }
236 free(tmp);
237
238 tmp = extract_programmer_param("spi_ignorelist");
239 if (tmp) {
240 i = strlen(tmp);
241 if (!strncmp(tmp, "0x", 2)) {
242 i -= 2;
243 memmove(tmp, tmp + 2, i + 1);
244 }
245 if ((i > 512) || (i % 2)) {
246 msg_perr("Invalid SPI command ignorelist length\n");
247 free(tmp);
248 return 1;
249 }
250 spi_ignorelist_size = i / 2;
251 for (i = 0; i < spi_ignorelist_size * 2; i++) {
252 if (!isxdigit((unsigned char)tmp[i])) {
253 msg_perr("Invalid char \"%c\" in SPI command "
254 "ignorelist\n", tmp[i]);
255 free(tmp);
256 return 1;
257 }
258 }
259 for (i = 0; i < spi_ignorelist_size; i++) {
260 unsigned int tmp2;
261 /* SCNx8 is apparently not supported by MSVC (and thus
262 * MinGW), so work around it with an extra variable
263 */
264 sscanf(tmp + i * 2, "%2x", &tmp2);
265 spi_ignorelist[i] = (uint8_t)tmp2;
266 }
267 msg_pdbg("SPI ignorelist is ");
268 for (i = 0; i < spi_ignorelist_size; i++)
269 msg_pdbg("%02x ", spi_ignorelist[i]);
270 msg_pdbg(", size %i\n", spi_ignorelist_size);
271 }
272 free(tmp);
273
David Hendricks84377002014-09-09 16:09:31 -0700274 /* frequency to emulate in Hz (default), KHz, or MHz */
275 tmp = extract_programmer_param("freq");
276 if (tmp) {
277 unsigned long int freq;
278 char *units = tmp;
279 char *end = tmp + strlen(tmp);
280
281 errno = 0;
282 freq = strtoul(tmp, &units, 0);
283 if (errno) {
284 msg_perr("Invalid frequency \"%s\", %s\n",
285 tmp, strerror(errno));
286 goto dummy_init_out;
287 }
288
289 if ((units > tmp) && (units < end)) {
290 int units_valid = 0;
291
292 if (units < end - 3) {
293 ;
294 } else if (units == end - 2) {
295 if (!strcasecmp(units, "hz"))
296 units_valid = 1;
297 } else if (units == end - 3) {
298 if (!strcasecmp(units, "khz")) {
299 freq *= 1000;
300 units_valid = 1;
301 } else if (!strcasecmp(units, "mhz")) {
302 freq *= 1000000;
303 units_valid = 1;
304 }
305 }
306
307 if (!units_valid) {
308 msg_perr("Invalid units: %s\n", units);
309 return 1;
310 }
311 }
312
313 /* Assume we only work with bytes and transfer at 1 bit/Hz */
314 delay_us = (1000000 * 8) / freq;
315 }
316
hailfinger6ead7222010-11-01 22:07:04 +0000317#if EMULATE_CHIP
Louis Yung-Chieh Loe53fa0f2011-04-11 17:18:41 +0800318#if EMULATE_SPI_CHIP
319 tmp = extract_programmer_param("size");
320 if (tmp) {
321 int multiplier = 1;
Simon Glassd2c64a22013-07-03 22:05:21 +0900322 if (!strcmp(tmp, "auto"))
323 size = SIZE_AUTO;
324 else if (strlen(tmp)) {
Louis Yung-Chieh Loe53fa0f2011-04-11 17:18:41 +0800325 int remove_last_char = 1;
326 switch (tmp[strlen(tmp) - 1]) {
327 case 'k': case 'K':
328 multiplier = 1024;
329 break;
330 case 'm': case 'M':
331 multiplier = 1024 * 1024;
332 break;
333 default:
334 remove_last_char = 0;
335 break;
336 }
337 if (remove_last_char) tmp[strlen(tmp) - 1] = '\0';
Simon Glassd2c64a22013-07-03 22:05:21 +0900338 size = atoi(tmp) * multiplier;
Louis Yung-Chieh Loe53fa0f2011-04-11 17:18:41 +0800339 }
Louis Yung-Chieh Loe53fa0f2011-04-11 17:18:41 +0800340 }
341#endif
342
hailfinger6ead7222010-11-01 22:07:04 +0000343 tmp = extract_programmer_param("emulate");
344 if (!tmp) {
345 msg_pdbg("Not emulating any flash chip.\n");
346 /* Nothing else to do. */
dhendrix0ffc2eb2011-06-14 01:35:36 +0000347 goto dummy_init_out;
hailfinger6ead7222010-11-01 22:07:04 +0000348 }
David Hendricks84377002014-09-09 16:09:31 -0700349
hailfinger6ead7222010-11-01 22:07:04 +0000350#if EMULATE_SPI_CHIP
351 if (!strcmp(tmp, "M25P10.RES")) {
352 emu_chip = EMULATE_ST_M25P10_RES;
353 emu_chip_size = 128 * 1024;
354 emu_max_byteprogram_size = 128;
355 emu_max_aai_size = 0;
356 emu_jedec_se_size = 0;
357 emu_jedec_be_52_size = 0;
358 emu_jedec_be_d8_size = 32 * 1024;
359 emu_jedec_ce_60_size = 0;
360 emu_jedec_ce_c7_size = emu_chip_size;
361 msg_pdbg("Emulating ST M25P10.RES SPI flash chip (RES, page "
362 "write)\n");
363 }
364 if (!strcmp(tmp, "SST25VF040.REMS")) {
365 emu_chip = EMULATE_SST_SST25VF040_REMS;
366 emu_chip_size = 512 * 1024;
367 emu_max_byteprogram_size = 1;
368 emu_max_aai_size = 0;
369 emu_jedec_se_size = 4 * 1024;
370 emu_jedec_be_52_size = 32 * 1024;
371 emu_jedec_be_d8_size = 0;
372 emu_jedec_ce_60_size = emu_chip_size;
373 emu_jedec_ce_c7_size = 0;
374 msg_pdbg("Emulating SST SST25VF040.REMS SPI flash chip (REMS, "
375 "byte write)\n");
376 }
377 if (!strcmp(tmp, "SST25VF032B")) {
378 emu_chip = EMULATE_SST_SST25VF032B;
379 emu_chip_size = 4 * 1024 * 1024;
380 emu_max_byteprogram_size = 1;
381 emu_max_aai_size = 2;
382 emu_jedec_se_size = 4 * 1024;
383 emu_jedec_be_52_size = 32 * 1024;
384 emu_jedec_be_d8_size = 64 * 1024;
385 emu_jedec_ce_60_size = emu_chip_size;
386 emu_jedec_ce_c7_size = emu_chip_size;
387 msg_pdbg("Emulating SST SST25VF032B SPI flash chip (RDID, AAI "
388 "write)\n");
389 }
Simon Glassd2c64a22013-07-03 22:05:21 +0900390 emu_persistent_image = extract_programmer_param("image");
391 if (!stat(emu_persistent_image, &image_stat))
392 image_size = image_stat.st_size;
393
Louis Yung-Chieh Loe53fa0f2011-04-11 17:18:41 +0800394 if (!strncmp(tmp, VARIABLE_SIZE_CHIP_NAME,
395 strlen(VARIABLE_SIZE_CHIP_NAME))) {
Simon Glassd2c64a22013-07-03 22:05:21 +0900396 if (size == SIZE_UNKNOWN) {
Louis Yung-Chieh Loe53fa0f2011-04-11 17:18:41 +0800397 msg_perr("%s: the size parameter is not given.\n",
398 __func__);
399 free(tmp);
400 return 1;
Simon Glassd2c64a22013-07-03 22:05:21 +0900401 } else if (size == SIZE_AUTO) {
402 if (image_size == SIZE_UNKNOWN) {
403 msg_perr("%s: no image so cannot use automatic size.\n",
404 __func__);
405 free(tmp);
406 return 1;
407 }
408 size = image_size;
Louis Yung-Chieh Loe53fa0f2011-04-11 17:18:41 +0800409 }
410 emu_chip = EMULATE_VARIABLE_SIZE;
411 emu_chip_size = size;
412 emu_max_byteprogram_size = 256;
413 emu_max_aai_size = 0;
414 emu_jedec_se_size = 4 * 1024;
415 emu_jedec_be_52_size = 32 * 1024;
416 emu_jedec_be_d8_size = 64 * 1024;
417 emu_jedec_ce_60_size = emu_chip_size;
418 emu_jedec_ce_c7_size = emu_chip_size;
419 msg_pdbg("Emulating generic SPI flash chip (size=%d bytes)\n",
420 emu_chip_size);
421 }
hailfinger6ead7222010-11-01 22:07:04 +0000422#endif
423 if (emu_chip == EMULATE_NONE) {
424 msg_perr("Invalid chip specified for emulation: %s\n", tmp);
425 free(tmp);
426 return 1;
427 }
David Hendricks0eda2a82014-09-12 16:32:05 -0700428
429 /* Should emulated flash erase to zero (yes/no)? */
430 tmp = extract_programmer_param("erase_to_zero");
431 if (tmp) {
432 if (!strcmp(tmp, "yes")) {
433 msg_pdbg("Emulated chip will erase to 0x00\n");
434 erase_to_zero = 1;
435 } else if (!strcmp(tmp, "no")) {
436 msg_pdbg("Emulated chip will erase to 0xff\n");
437 } else {
438 msg_perr("erase_to_zero can be \"yes\" or \"no\"\n");
439 return 1;
440 }
441 }
442
hailfinger6ead7222010-11-01 22:07:04 +0000443 free(tmp);
444 flashchip_contents = malloc(emu_chip_size);
445 if (!flashchip_contents) {
446 msg_perr("Out of memory!\n");
447 return 1;
448 }
dhendrix0ffc2eb2011-06-14 01:35:36 +0000449
David Hendricks0eda2a82014-09-12 16:32:05 -0700450 msg_pdbg("Filling fake flash chip with 0x%02x, size %i\n",
451 erase_to_zero ? 0x00 : 0xff, emu_chip_size);
452 memset(flashchip_contents, erase_to_zero ? 0x00 : 0xff, emu_chip_size);
hailfinger6ead7222010-11-01 22:07:04 +0000453
hailfinger6ead7222010-11-01 22:07:04 +0000454 if (!emu_persistent_image) {
455 /* Nothing else to do. */
dhendrix0ffc2eb2011-06-14 01:35:36 +0000456 goto dummy_init_out;
hailfinger6ead7222010-11-01 22:07:04 +0000457 }
458 if (!stat(emu_persistent_image, &image_stat)) {
459 msg_pdbg("Found persistent image %s, size %li ",
460 emu_persistent_image, (long)image_stat.st_size);
461 if (image_stat.st_size == emu_chip_size) {
462 msg_pdbg("matches.\n");
463 msg_pdbg("Reading %s\n", emu_persistent_image);
464 read_buf_from_file(flashchip_contents, emu_chip_size,
465 emu_persistent_image);
466 } else {
467 msg_pdbg("doesn't match.\n");
468 }
469 }
470#endif
hailfingera9df33c2009-05-09 00:54:55 +0000471
dhendrix0ffc2eb2011-06-14 01:35:36 +0000472dummy_init_out:
473 if (register_shutdown(dummy_shutdown, NULL)) {
hailfinger6ead7222010-11-01 22:07:04 +0000474 free(flashchip_contents);
dhendrix0ffc2eb2011-06-14 01:35:36 +0000475 return 1;
hailfinger6ead7222010-11-01 22:07:04 +0000476 }
hailfinger76bb7e92011-11-09 23:40:00 +0000477 if (dummy_buses_supported & (BUS_PARALLEL | BUS_LPC | BUS_FWH))
Patrick Georgi0a9533a2017-02-03 19:28:38 +0100478 register_par_master(&par_master_dummy,
hailfinger76bb7e92011-11-09 23:40:00 +0000479 dummy_buses_supported &
480 (BUS_PARALLEL | BUS_LPC |
481 BUS_FWH));
482 if (dummy_buses_supported & BUS_SPI)
Patrick Georgif4f1e2f2017-03-10 17:38:40 +0100483 register_spi_master(&spi_master_dummyflasher);
hailfinger76bb7e92011-11-09 23:40:00 +0000484
hailfingera9df33c2009-05-09 00:54:55 +0000485 return 0;
486}
487
Patrick Georgi4befc162017-02-03 18:32:01 +0100488void *dummy_map(const char *descr, uintptr_t phys_addr, size_t len)
hailfinger11ae3c42009-05-11 14:13:25 +0000489{
Patrick Georgi4befc162017-02-03 18:32:01 +0100490 msg_pspew("%s: Mapping %s, 0x%lx bytes at %" PRIxPTR "\n",
hailfinger50c335f2010-01-09 04:32:23 +0000491 __func__, descr, (unsigned long)len, phys_addr);
hailfinger11ae3c42009-05-11 14:13:25 +0000492 return (void *)phys_addr;
493}
494
495void dummy_unmap(void *virt_addr, size_t len)
496{
hailfinger50c335f2010-01-09 04:32:23 +0000497 msg_pspew("%s: Unmapping 0x%lx bytes at %p\n",
498 __func__, (unsigned long)len, virt_addr);
hailfinger11ae3c42009-05-11 14:13:25 +0000499}
500
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700501void dummy_chip_writeb(const struct flashctx *flash, uint8_t val, chipaddr addr)
hailfingera9df33c2009-05-09 00:54:55 +0000502{
hailfinger50c335f2010-01-09 04:32:23 +0000503 msg_pspew("%s: addr=0x%lx, val=0x%02x\n", __func__, addr, val);
hailfingera9df33c2009-05-09 00:54:55 +0000504}
505
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700506void dummy_chip_writew(const struct flashctx *flash, uint16_t val, chipaddr addr)
hailfingera9df33c2009-05-09 00:54:55 +0000507{
hailfinger50c335f2010-01-09 04:32:23 +0000508 msg_pspew("%s: addr=0x%lx, val=0x%04x\n", __func__, addr, val);
hailfingera9df33c2009-05-09 00:54:55 +0000509}
510
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700511void dummy_chip_writel(const struct flashctx *flash, uint32_t val, chipaddr addr)
hailfingera9df33c2009-05-09 00:54:55 +0000512{
hailfinger50c335f2010-01-09 04:32:23 +0000513 msg_pspew("%s: addr=0x%lx, val=0x%08x\n", __func__, addr, val);
hailfingera9df33c2009-05-09 00:54:55 +0000514}
515
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700516void dummy_chip_writen(const struct flashctx *flash, uint8_t *buf, chipaddr addr, size_t len)
hailfinger9d987ef2009-06-05 18:32:07 +0000517{
518 size_t i;
hailfinger50c335f2010-01-09 04:32:23 +0000519 msg_pspew("%s: addr=0x%lx, len=0x%08lx, writing data (hex):",
520 __func__, addr, (unsigned long)len);
hailfinger9d987ef2009-06-05 18:32:07 +0000521 for (i = 0; i < len; i++) {
522 if ((i % 16) == 0)
hailfinger50c335f2010-01-09 04:32:23 +0000523 msg_pspew("\n");
524 msg_pspew("%02x ", buf[i]);
hailfinger9d987ef2009-06-05 18:32:07 +0000525 }
526}
527
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700528uint8_t dummy_chip_readb(const struct flashctx *flash, const chipaddr addr)
hailfingera9df33c2009-05-09 00:54:55 +0000529{
hailfinger50c335f2010-01-09 04:32:23 +0000530 msg_pspew("%s: addr=0x%lx, returning 0xff\n", __func__, addr);
hailfingera9df33c2009-05-09 00:54:55 +0000531 return 0xff;
532}
533
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700534uint16_t dummy_chip_readw(const struct flashctx *flash, const chipaddr addr)
hailfingera9df33c2009-05-09 00:54:55 +0000535{
hailfinger50c335f2010-01-09 04:32:23 +0000536 msg_pspew("%s: addr=0x%lx, returning 0xffff\n", __func__, addr);
hailfingera9df33c2009-05-09 00:54:55 +0000537 return 0xffff;
538}
539
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700540uint32_t dummy_chip_readl(const struct flashctx *flash, const chipaddr addr)
hailfingera9df33c2009-05-09 00:54:55 +0000541{
hailfinger50c335f2010-01-09 04:32:23 +0000542 msg_pspew("%s: addr=0x%lx, returning 0xffffffff\n", __func__, addr);
hailfingera9df33c2009-05-09 00:54:55 +0000543 return 0xffffffff;
544}
545
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700546void dummy_chip_readn(const struct flashctx *flash, uint8_t *buf, const chipaddr addr, size_t len)
hailfinger9d987ef2009-06-05 18:32:07 +0000547{
hailfinger50c335f2010-01-09 04:32:23 +0000548 msg_pspew("%s: addr=0x%lx, len=0x%lx, returning array of 0xff\n",
549 __func__, addr, (unsigned long)len);
hailfinger9d987ef2009-06-05 18:32:07 +0000550 memset(buf, 0xff, len);
551 return;
552}
553
hailfinger6ead7222010-11-01 22:07:04 +0000554#if EMULATE_SPI_CHIP
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700555static int emulate_spi_chip_response(const struct flashctx *flash, unsigned int writecnt, unsigned int readcnt,
hailfinger6ead7222010-11-01 22:07:04 +0000556 const unsigned char *writearr, unsigned char *readarr)
557{
Carl-Daniel Hailfingerc49783d2016-08-05 10:52:06 -0700558 unsigned int offs, i;
stefanctc5eb8a92011-11-23 09:13:48 +0000559 static int unsigned aai_offs;
hailfinger6ead7222010-11-01 22:07:04 +0000560 static int aai_active = 0;
561
562 if (writecnt == 0) {
563 msg_perr("No command sent to the chip!\n");
564 return 1;
565 }
Stefan Tauner718d1eb2016-08-18 18:00:53 -0700566 /* spi_blacklist has precedence over spi_ignorelist. */
Carl-Daniel Hailfingerc49783d2016-08-05 10:52:06 -0700567 for (i = 0; i < spi_blacklist_size; i++) {
568 if (writearr[0] == spi_blacklist[i]) {
569 msg_pdbg("Refusing blacklisted SPI command 0x%02x\n",
570 spi_blacklist[i]);
571 return SPI_INVALID_OPCODE;
572 }
573 }
574 for (i = 0; i < spi_ignorelist_size; i++) {
575 if (writearr[0] == spi_ignorelist[i]) {
576 msg_cdbg("Ignoring ignorelisted SPI command 0x%02x\n",
577 spi_ignorelist[i]);
578 /* Return success because the command does not fail,
579 * it is simply ignored.
580 */
581 return 0;
582 }
583 }
hailfinger6ead7222010-11-01 22:07:04 +0000584 switch (writearr[0]) {
585 case JEDEC_RES:
586 if (emu_chip != EMULATE_ST_M25P10_RES)
587 break;
588 /* Respond with ST_M25P10_RES. */
589 if (readcnt > 0)
590 readarr[0] = 0x10;
591 break;
592 case JEDEC_REMS:
593 if (emu_chip != EMULATE_SST_SST25VF040_REMS)
594 break;
595 /* Respond with SST_SST25VF040_REMS. */
596 if (readcnt > 0)
597 readarr[0] = 0xbf;
598 if (readcnt > 1)
599 readarr[1] = 0x44;
600 break;
601 case JEDEC_RDID:
Louis Yung-Chieh Loe53fa0f2011-04-11 17:18:41 +0800602 if (emu_chip == EMULATE_SST_SST25VF032B) {
603 /* Respond with SST_SST25VF032B. */
604 if (readcnt > 0)
605 readarr[0] = 0xbf;
606 if (readcnt > 1)
607 readarr[1] = 0x25;
608 if (readcnt > 2)
609 readarr[2] = 0x4a;
610 } else if (emu_chip == EMULATE_VARIABLE_SIZE) {
611 const uint16_t man_id = VARIABLE_SIZE_MANUF_ID;
612 const uint16_t dev_id = VARIABLE_SIZE_DEVICE_ID;
613 if (readcnt > 0) readarr[0] = man_id >> 8;
614 if (readcnt > 1) readarr[1] = man_id & 0xff;
615 if (readcnt > 2) readarr[2] = dev_id >> 8;
616 if (readcnt > 3) readarr[3] = dev_id & 0xff;
617 }
hailfinger6ead7222010-11-01 22:07:04 +0000618 break;
619 case JEDEC_RDSR:
620 memset(readarr, 0, readcnt);
621 if (aai_active)
622 memset(readarr, 1 << 6, readcnt);
623 break;
624 case JEDEC_READ:
625 offs = writearr[1] << 16 | writearr[2] << 8 | writearr[3];
626 /* Truncate to emu_chip_size. */
627 offs %= emu_chip_size;
628 if (readcnt > 0)
629 memcpy(readarr, flashchip_contents + offs, readcnt);
630 break;
631 case JEDEC_BYTE_PROGRAM:
632 offs = writearr[1] << 16 | writearr[2] << 8 | writearr[3];
633 /* Truncate to emu_chip_size. */
634 offs %= emu_chip_size;
635 if (writecnt < 5) {
636 msg_perr("BYTE PROGRAM size too short!\n");
637 return 1;
638 }
639 if (writecnt - 4 > emu_max_byteprogram_size) {
640 msg_perr("Max BYTE PROGRAM size exceeded!\n");
641 return 1;
642 }
643 memcpy(flashchip_contents + offs, writearr + 4, writecnt - 4);
Simon Glasscf253a72013-07-10 21:10:11 -0700644 emu_modified = 1;
hailfinger6ead7222010-11-01 22:07:04 +0000645 break;
646 case JEDEC_AAI_WORD_PROGRAM:
647 if (!emu_max_aai_size)
648 break;
649 if (!aai_active) {
650 if (writecnt < JEDEC_AAI_WORD_PROGRAM_OUTSIZE) {
651 msg_perr("Initial AAI WORD PROGRAM size too "
652 "short!\n");
653 return 1;
654 }
655 if (writecnt > JEDEC_AAI_WORD_PROGRAM_OUTSIZE) {
656 msg_perr("Initial AAI WORD PROGRAM size too "
657 "long!\n");
658 return 1;
659 }
660 aai_active = 1;
661 aai_offs = writearr[1] << 16 | writearr[2] << 8 |
662 writearr[3];
663 /* Truncate to emu_chip_size. */
664 aai_offs %= emu_chip_size;
665 memcpy(flashchip_contents + aai_offs, writearr + 4, 2);
666 aai_offs += 2;
667 } else {
668 if (writecnt < JEDEC_AAI_WORD_PROGRAM_CONT_OUTSIZE) {
669 msg_perr("Continuation AAI WORD PROGRAM size "
670 "too short!\n");
671 return 1;
672 }
673 if (writecnt > JEDEC_AAI_WORD_PROGRAM_CONT_OUTSIZE) {
674 msg_perr("Continuation AAI WORD PROGRAM size "
675 "too long!\n");
676 return 1;
677 }
678 memcpy(flashchip_contents + aai_offs, writearr + 1, 2);
679 aai_offs += 2;
680 }
Simon Glasscf253a72013-07-10 21:10:11 -0700681 emu_modified = 1;
hailfinger6ead7222010-11-01 22:07:04 +0000682 break;
683 case JEDEC_WRDI:
684 if (!emu_max_aai_size)
685 break;
686 aai_active = 0;
687 break;
688 case JEDEC_SE:
689 if (!emu_jedec_se_size)
690 break;
691 if (writecnt != JEDEC_SE_OUTSIZE) {
692 msg_perr("SECTOR ERASE 0x20 outsize invalid!\n");
693 return 1;
694 }
695 if (readcnt != JEDEC_SE_INSIZE) {
696 msg_perr("SECTOR ERASE 0x20 insize invalid!\n");
697 return 1;
698 }
699 offs = writearr[1] << 16 | writearr[2] << 8 | writearr[3];
700 if (offs & (emu_jedec_se_size - 1))
hailfingere53f5e42011-02-04 22:52:04 +0000701 msg_pdbg("Unaligned SECTOR ERASE 0x20: 0x%x\n", offs);
hailfinger6ead7222010-11-01 22:07:04 +0000702 offs &= ~(emu_jedec_se_size - 1);
703 memset(flashchip_contents + offs, 0xff, emu_jedec_se_size);
Simon Glasscf253a72013-07-10 21:10:11 -0700704 emu_modified = 1;
hailfinger6ead7222010-11-01 22:07:04 +0000705 break;
706 case JEDEC_BE_52:
707 if (!emu_jedec_be_52_size)
708 break;
709 if (writecnt != JEDEC_BE_52_OUTSIZE) {
710 msg_perr("BLOCK ERASE 0x52 outsize invalid!\n");
711 return 1;
712 }
713 if (readcnt != JEDEC_BE_52_INSIZE) {
714 msg_perr("BLOCK ERASE 0x52 insize invalid!\n");
715 return 1;
716 }
717 offs = writearr[1] << 16 | writearr[2] << 8 | writearr[3];
718 if (offs & (emu_jedec_be_52_size - 1))
hailfingere53f5e42011-02-04 22:52:04 +0000719 msg_pdbg("Unaligned BLOCK ERASE 0x52: 0x%x\n", offs);
hailfinger6ead7222010-11-01 22:07:04 +0000720 offs &= ~(emu_jedec_be_52_size - 1);
721 memset(flashchip_contents + offs, 0xff, emu_jedec_be_52_size);
Simon Glasscf253a72013-07-10 21:10:11 -0700722 emu_modified = 1;
hailfinger6ead7222010-11-01 22:07:04 +0000723 break;
724 case JEDEC_BE_D8:
725 if (!emu_jedec_be_d8_size)
726 break;
727 if (writecnt != JEDEC_BE_D8_OUTSIZE) {
728 msg_perr("BLOCK ERASE 0xd8 outsize invalid!\n");
729 return 1;
730 }
731 if (readcnt != JEDEC_BE_D8_INSIZE) {
732 msg_perr("BLOCK ERASE 0xd8 insize invalid!\n");
733 return 1;
734 }
735 offs = writearr[1] << 16 | writearr[2] << 8 | writearr[3];
736 if (offs & (emu_jedec_be_d8_size - 1))
hailfingere53f5e42011-02-04 22:52:04 +0000737 msg_pdbg("Unaligned BLOCK ERASE 0xd8: 0x%x\n", offs);
hailfinger6ead7222010-11-01 22:07:04 +0000738 offs &= ~(emu_jedec_be_d8_size - 1);
739 memset(flashchip_contents + offs, 0xff, emu_jedec_be_d8_size);
740 break;
741 case JEDEC_CE_60:
742 if (!emu_jedec_ce_60_size)
743 break;
744 if (writecnt != JEDEC_CE_60_OUTSIZE) {
745 msg_perr("CHIP ERASE 0x60 outsize invalid!\n");
746 return 1;
747 }
748 if (readcnt != JEDEC_CE_60_INSIZE) {
749 msg_perr("CHIP ERASE 0x60 insize invalid!\n");
750 return 1;
751 }
hailfingere53f5e42011-02-04 22:52:04 +0000752 /* JEDEC_CE_60_OUTSIZE is 1 (no address) -> no offset. */
hailfinger6ead7222010-11-01 22:07:04 +0000753 /* emu_jedec_ce_60_size is emu_chip_size. */
hailfingere53f5e42011-02-04 22:52:04 +0000754 memset(flashchip_contents, 0xff, emu_jedec_ce_60_size);
Simon Glasscf253a72013-07-10 21:10:11 -0700755 emu_modified = 1;
hailfinger6ead7222010-11-01 22:07:04 +0000756 break;
757 case JEDEC_CE_C7:
758 if (!emu_jedec_ce_c7_size)
759 break;
760 if (writecnt != JEDEC_CE_C7_OUTSIZE) {
761 msg_perr("CHIP ERASE 0xc7 outsize invalid!\n");
762 return 1;
763 }
764 if (readcnt != JEDEC_CE_C7_INSIZE) {
765 msg_perr("CHIP ERASE 0xc7 insize invalid!\n");
766 return 1;
767 }
hailfingere53f5e42011-02-04 22:52:04 +0000768 /* JEDEC_CE_C7_OUTSIZE is 1 (no address) -> no offset. */
hailfinger6ead7222010-11-01 22:07:04 +0000769 /* emu_jedec_ce_c7_size is emu_chip_size. */
770 memset(flashchip_contents, 0xff, emu_jedec_ce_c7_size);
Simon Glasscf253a72013-07-10 21:10:11 -0700771 emu_modified = 1;
hailfinger6ead7222010-11-01 22:07:04 +0000772 break;
773 default:
774 /* No special response. */
775 break;
776 }
777 return 0;
778}
779#endif
780
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700781static int dummy_spi_send_command(const struct flashctx *flash, unsigned int writecnt, unsigned int readcnt,
hailfingerf91e3b52009-05-14 12:59:36 +0000782 const unsigned char *writearr, unsigned char *readarr)
783{
784 int i;
785
hailfinger50c335f2010-01-09 04:32:23 +0000786 msg_pspew("%s:", __func__);
hailfingerf91e3b52009-05-14 12:59:36 +0000787
hailfinger50c335f2010-01-09 04:32:23 +0000788 msg_pspew(" writing %u bytes:", writecnt);
hailfingerf91e3b52009-05-14 12:59:36 +0000789 for (i = 0; i < writecnt; i++)
hailfinger50c335f2010-01-09 04:32:23 +0000790 msg_pspew(" 0x%02x", writearr[i]);
hailfingerf91e3b52009-05-14 12:59:36 +0000791
hailfinger6ead7222010-11-01 22:07:04 +0000792 /* Response for unknown commands and missing chip is 0xff. */
793 memset(readarr, 0xff, readcnt);
794#if EMULATE_SPI_CHIP
795 switch (emu_chip) {
796 case EMULATE_ST_M25P10_RES:
797 case EMULATE_SST_SST25VF040_REMS:
798 case EMULATE_SST_SST25VF032B:
Louis Yung-Chieh Loe53fa0f2011-04-11 17:18:41 +0800799 case EMULATE_VARIABLE_SIZE:
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700800 if (emulate_spi_chip_response(flash, writecnt, readcnt, writearr,
hailfinger6ead7222010-11-01 22:07:04 +0000801 readarr)) {
Carl-Daniel Hailfingerc49783d2016-08-05 10:52:06 -0700802 msg_pdbg("Invalid command sent to flash chip!\n");
hailfinger6ead7222010-11-01 22:07:04 +0000803 return 1;
804 }
805 break;
806 default:
807 break;
808 }
809#endif
hailfinger50c335f2010-01-09 04:32:23 +0000810 msg_pspew(" reading %u bytes:", readcnt);
uwe8d342eb2011-07-28 08:13:25 +0000811 for (i = 0; i < readcnt; i++)
hailfinger6ead7222010-11-01 22:07:04 +0000812 msg_pspew(" 0x%02x", readarr[i]);
hailfinger50c335f2010-01-09 04:32:23 +0000813 msg_pspew("\n");
David Hendricks84377002014-09-09 16:09:31 -0700814
815 programmer_delay((writecnt + readcnt) * delay_us);
hailfingerf91e3b52009-05-14 12:59:36 +0000816 return 0;
817}
hailfingera8727712010-06-20 10:58:32 +0000818
Patrick Georgiab8353e2017-02-03 18:32:01 +0100819static int dummy_spi_write_256(struct flashctx *flash, const uint8_t *buf,
stefanctc5eb8a92011-11-23 09:13:48 +0000820 unsigned int start, unsigned int len)
hailfingerc7d06c62010-07-14 16:19:05 +0000821{
hailfinger6ead7222010-11-01 22:07:04 +0000822 return spi_write_chunked(flash, buf, start, len,
823 spi_write_256_chunksize);
hailfingerc7d06c62010-07-14 16:19:05 +0000824}
Louis Yung-Chieh Loe53fa0f2011-04-11 17:18:41 +0800825
826#if EMULATE_CHIP && EMULATE_SPI_CHIP
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700827int probe_variable_size(struct flashctx *flash)
Louis Yung-Chieh Loe53fa0f2011-04-11 17:18:41 +0800828{
829 int i;
830
831 /* Skip the probing if we don't emulate this chip. */
832 if (emu_chip != EMULATE_VARIABLE_SIZE)
833 return 0;
834
835 /*
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700836 * This will break if one day flashctx becomes read-only.
Louis Yung-Chieh Loe53fa0f2011-04-11 17:18:41 +0800837 * Once that happens, we need to have special hacks in functions:
838 *
839 * erase_and_write_flash() in flashrom.c
840 * read_flash_to_file()
841 * handle_romentries()
842 * ...
843 *
844 * Search "total_size * 1024" in code.
845 */
846 if (emu_chip_size % 1024)
847 msg_perr("%s: emu_chip_size is not multipler of 1024.\n",
848 __func__);
Patrick Georgif3fa2992017-02-02 16:24:44 +0100849 flash->chip->total_size = emu_chip_size / 1024;
Louis Yung-Chieh Loe53fa0f2011-04-11 17:18:41 +0800850 msg_cdbg("%s: set flash->total_size to %dK bytes.\n", __func__,
Patrick Georgif3fa2992017-02-02 16:24:44 +0100851 flash->chip->total_size);
Louis Yung-Chieh Loe53fa0f2011-04-11 17:18:41 +0800852
David Hendricks0eda2a82014-09-12 16:32:05 -0700853 if (erase_to_zero)
Patrick Georgif3fa2992017-02-02 16:24:44 +0100854 flash->chip->feature_bits |= FEATURE_ERASE_TO_ZERO;
David Hendricks0eda2a82014-09-12 16:32:05 -0700855
Louis Yung-Chieh Loe53fa0f2011-04-11 17:18:41 +0800856 /* Update eraser count */
857 for (i = 0; i < NUM_ERASEFUNCTIONS; i++) {
Patrick Georgif3fa2992017-02-02 16:24:44 +0100858 struct block_eraser *eraser = &flash->chip->block_erasers[i];
Louis Yung-Chieh Loe53fa0f2011-04-11 17:18:41 +0800859 if (eraser->block_erase == NULL)
860 break;
861
862 eraser->eraseblocks[0].count = emu_chip_size /
863 eraser->eraseblocks[0].size;
864 msg_cdbg("%s: eraser.size=%d, .count=%d\n",
865 __func__, eraser->eraseblocks[0].size,
866 eraser->eraseblocks[0].count);
867 }
868
869 return 1;
870}
871#endif