blob: a6d441b3106b55e71bcdc58b63c54ca790a01247 [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,
Edward O'Callaghana6673bd2019-06-24 15:22:28 +1000106 .features = SPI_MASTER_4BA,
uwe8d342eb2011-07-28 08:13:25 +0000107 .max_data_read = MAX_DATA_READ_UNLIMITED,
108 .max_data_write = MAX_DATA_UNSPECIFIED,
109 .command = dummy_spi_send_command,
110 .multicommand = default_spi_send_multicommand,
111 .read = default_spi_read,
112 .write_256 = dummy_spi_write_256,
mkarcherd264e9e2011-05-11 17:07:07 +0000113};
dhendrix0ffc2eb2011-06-14 01:35:36 +0000114
Patrick Georgi0a9533a2017-02-03 19:28:38 +0100115static const struct par_master par_master_dummy = {
hailfinger76bb7e92011-11-09 23:40:00 +0000116 .chip_readb = dummy_chip_readb,
117 .chip_readw = dummy_chip_readw,
118 .chip_readl = dummy_chip_readl,
119 .chip_readn = dummy_chip_readn,
120 .chip_writeb = dummy_chip_writeb,
121 .chip_writew = dummy_chip_writew,
122 .chip_writel = dummy_chip_writel,
123 .chip_writen = dummy_chip_writen,
124};
125
Edward O'Callaghanef4e28b2019-06-28 13:18:41 +1000126static enum chipbustype dummy_buses_supported = BUS_NONE;
hailfinger76bb7e92011-11-09 23:40:00 +0000127
David Hendricks93784b42016-08-09 17:00:38 -0700128static int dummy_shutdown(void *data)
dhendrix0ffc2eb2011-06-14 01:35:36 +0000129{
130 msg_pspew("%s\n", __func__);
131#if EMULATE_CHIP
132 if (emu_chip != EMULATE_NONE) {
Simon Glasscf253a72013-07-10 21:10:11 -0700133 if (emu_persistent_image && emu_modified) {
dhendrix0ffc2eb2011-06-14 01:35:36 +0000134 msg_pdbg("Writing %s\n", emu_persistent_image);
135 write_buf_to_file(flashchip_contents, emu_chip_size,
136 emu_persistent_image);
137 }
138 free(flashchip_contents);
139 }
140#endif
141 return 0;
142}
143
Simon Glassd2c64a22013-07-03 22:05:21 +0900144/* Values for the 'size' parameter */
145enum {
146 SIZE_UNKNOWN = -1,
147 SIZE_AUTO = -2,
148};
149
David Hendricksac1d25c2016-08-09 17:00:58 -0700150int dummy_init(void)
hailfingera9df33c2009-05-09 00:54:55 +0000151{
hailfinger1ef766d2010-07-06 09:55:48 +0000152 char *bustext = NULL;
hailfinger6ead7222010-11-01 22:07:04 +0000153 char *tmp = NULL;
Carl-Daniel Hailfingerc49783d2016-08-05 10:52:06 -0700154 int i;
hailfinger6ead7222010-11-01 22:07:04 +0000155#if EMULATE_CHIP
156 struct stat image_stat;
Louis Yung-Chieh Loe53fa0f2011-04-11 17:18:41 +0800157#if EMULATE_SPI_CHIP
Simon Glassd2c64a22013-07-03 22:05:21 +0900158 int size = SIZE_UNKNOWN; /* size for generic chip */
Louis Yung-Chieh Loe53fa0f2011-04-11 17:18:41 +0800159#endif
hailfinger6ead7222010-11-01 22:07:04 +0000160#endif
Simon Glassd2c64a22013-07-03 22:05:21 +0900161 int image_size = SIZE_UNKNOWN;
hailfinger1ef766d2010-07-06 09:55:48 +0000162
hailfinger50c335f2010-01-09 04:32:23 +0000163 msg_pspew("%s\n", __func__);
hailfinger668f3502009-06-01 00:02:11 +0000164
hailfingerddeb4ac2010-07-08 10:13:37 +0000165 bustext = extract_programmer_param("bus");
hailfinger1ef766d2010-07-06 09:55:48 +0000166 msg_pdbg("Requested buses are: %s\n", bustext ? bustext : "default");
167 if (!bustext)
168 bustext = strdup("parallel+lpc+fwh+spi");
hailfinger668f3502009-06-01 00:02:11 +0000169 /* Convert the parameters to lowercase. */
hailfinger1ef766d2010-07-06 09:55:48 +0000170 tolower_string(bustext);
hailfinger668f3502009-06-01 00:02:11 +0000171
hailfinger76bb7e92011-11-09 23:40:00 +0000172 dummy_buses_supported = BUS_NONE;
hailfinger1ef766d2010-07-06 09:55:48 +0000173 if (strstr(bustext, "parallel")) {
hailfinger76bb7e92011-11-09 23:40:00 +0000174 dummy_buses_supported |= BUS_PARALLEL;
hailfinger50c335f2010-01-09 04:32:23 +0000175 msg_pdbg("Enabling support for %s flash.\n", "parallel");
hailfinger668f3502009-06-01 00:02:11 +0000176 }
hailfinger1ef766d2010-07-06 09:55:48 +0000177 if (strstr(bustext, "lpc")) {
hailfinger76bb7e92011-11-09 23:40:00 +0000178 dummy_buses_supported |= BUS_LPC;
hailfinger50c335f2010-01-09 04:32:23 +0000179 msg_pdbg("Enabling support for %s flash.\n", "LPC");
hailfinger668f3502009-06-01 00:02:11 +0000180 }
hailfinger1ef766d2010-07-06 09:55:48 +0000181 if (strstr(bustext, "fwh")) {
hailfinger76bb7e92011-11-09 23:40:00 +0000182 dummy_buses_supported |= BUS_FWH;
hailfinger50c335f2010-01-09 04:32:23 +0000183 msg_pdbg("Enabling support for %s flash.\n", "FWH");
hailfinger668f3502009-06-01 00:02:11 +0000184 }
hailfinger1ef766d2010-07-06 09:55:48 +0000185 if (strstr(bustext, "spi")) {
hailfinger76bb7e92011-11-09 23:40:00 +0000186 dummy_buses_supported |= BUS_SPI;
hailfinger50c335f2010-01-09 04:32:23 +0000187 msg_pdbg("Enabling support for %s flash.\n", "SPI");
hailfinger668f3502009-06-01 00:02:11 +0000188 }
hailfinger76bb7e92011-11-09 23:40:00 +0000189 if (dummy_buses_supported == BUS_NONE)
hailfinger50c335f2010-01-09 04:32:23 +0000190 msg_pdbg("Support for all flash bus types disabled.\n");
hailfinger1ef766d2010-07-06 09:55:48 +0000191 free(bustext);
hailfinger6ead7222010-11-01 22:07:04 +0000192
193 tmp = extract_programmer_param("spi_write_256_chunksize");
194 if (tmp) {
195 spi_write_256_chunksize = atoi(tmp);
196 free(tmp);
197 if (spi_write_256_chunksize < 1) {
198 msg_perr("invalid spi_write_256_chunksize\n");
199 return 1;
200 }
201 }
202
Carl-Daniel Hailfingerc49783d2016-08-05 10:52:06 -0700203 tmp = extract_programmer_param("spi_blacklist");
204 if (tmp) {
205 i = strlen(tmp);
206 if (!strncmp(tmp, "0x", 2)) {
207 i -= 2;
208 memmove(tmp, tmp + 2, i + 1);
209 }
210 if ((i > 512) || (i % 2)) {
211 msg_perr("Invalid SPI command blacklist length\n");
212 free(tmp);
213 return 1;
214 }
215 spi_blacklist_size = i / 2;
216 for (i = 0; i < spi_blacklist_size * 2; i++) {
217 if (!isxdigit((unsigned char)tmp[i])) {
218 msg_perr("Invalid char \"%c\" in SPI command "
219 "blacklist\n", tmp[i]);
220 free(tmp);
221 return 1;
222 }
223 }
224 for (i = 0; i < spi_blacklist_size; i++) {
225 unsigned int tmp2;
226 /* SCNx8 is apparently not supported by MSVC (and thus
227 * MinGW), so work around it with an extra variable
228 */
229 sscanf(tmp + i * 2, "%2x", &tmp2);
230 spi_blacklist[i] = (uint8_t)tmp2;
231 }
232 msg_pdbg("SPI blacklist is ");
233 for (i = 0; i < spi_blacklist_size; i++)
234 msg_pdbg("%02x ", spi_blacklist[i]);
235 msg_pdbg(", size %i\n", spi_blacklist_size);
236 }
237 free(tmp);
238
239 tmp = extract_programmer_param("spi_ignorelist");
240 if (tmp) {
241 i = strlen(tmp);
242 if (!strncmp(tmp, "0x", 2)) {
243 i -= 2;
244 memmove(tmp, tmp + 2, i + 1);
245 }
246 if ((i > 512) || (i % 2)) {
247 msg_perr("Invalid SPI command ignorelist length\n");
248 free(tmp);
249 return 1;
250 }
251 spi_ignorelist_size = i / 2;
252 for (i = 0; i < spi_ignorelist_size * 2; i++) {
253 if (!isxdigit((unsigned char)tmp[i])) {
254 msg_perr("Invalid char \"%c\" in SPI command "
255 "ignorelist\n", tmp[i]);
256 free(tmp);
257 return 1;
258 }
259 }
260 for (i = 0; i < spi_ignorelist_size; i++) {
261 unsigned int tmp2;
262 /* SCNx8 is apparently not supported by MSVC (and thus
263 * MinGW), so work around it with an extra variable
264 */
265 sscanf(tmp + i * 2, "%2x", &tmp2);
266 spi_ignorelist[i] = (uint8_t)tmp2;
267 }
268 msg_pdbg("SPI ignorelist is ");
269 for (i = 0; i < spi_ignorelist_size; i++)
270 msg_pdbg("%02x ", spi_ignorelist[i]);
271 msg_pdbg(", size %i\n", spi_ignorelist_size);
272 }
273 free(tmp);
274
David Hendricks84377002014-09-09 16:09:31 -0700275 /* frequency to emulate in Hz (default), KHz, or MHz */
276 tmp = extract_programmer_param("freq");
277 if (tmp) {
278 unsigned long int freq;
279 char *units = tmp;
280 char *end = tmp + strlen(tmp);
281
282 errno = 0;
283 freq = strtoul(tmp, &units, 0);
284 if (errno) {
285 msg_perr("Invalid frequency \"%s\", %s\n",
286 tmp, strerror(errno));
287 goto dummy_init_out;
288 }
289
290 if ((units > tmp) && (units < end)) {
291 int units_valid = 0;
292
293 if (units < end - 3) {
294 ;
295 } else if (units == end - 2) {
296 if (!strcasecmp(units, "hz"))
297 units_valid = 1;
298 } else if (units == end - 3) {
299 if (!strcasecmp(units, "khz")) {
300 freq *= 1000;
301 units_valid = 1;
302 } else if (!strcasecmp(units, "mhz")) {
303 freq *= 1000000;
304 units_valid = 1;
305 }
306 }
307
308 if (!units_valid) {
309 msg_perr("Invalid units: %s\n", units);
310 return 1;
311 }
312 }
313
314 /* Assume we only work with bytes and transfer at 1 bit/Hz */
315 delay_us = (1000000 * 8) / freq;
316 }
317
hailfinger6ead7222010-11-01 22:07:04 +0000318#if EMULATE_CHIP
Louis Yung-Chieh Loe53fa0f2011-04-11 17:18:41 +0800319#if EMULATE_SPI_CHIP
320 tmp = extract_programmer_param("size");
321 if (tmp) {
322 int multiplier = 1;
Simon Glassd2c64a22013-07-03 22:05:21 +0900323 if (!strcmp(tmp, "auto"))
324 size = SIZE_AUTO;
325 else if (strlen(tmp)) {
Louis Yung-Chieh Loe53fa0f2011-04-11 17:18:41 +0800326 int remove_last_char = 1;
327 switch (tmp[strlen(tmp) - 1]) {
328 case 'k': case 'K':
329 multiplier = 1024;
330 break;
331 case 'm': case 'M':
332 multiplier = 1024 * 1024;
333 break;
334 default:
335 remove_last_char = 0;
336 break;
337 }
338 if (remove_last_char) tmp[strlen(tmp) - 1] = '\0';
Simon Glassd2c64a22013-07-03 22:05:21 +0900339 size = atoi(tmp) * multiplier;
Louis Yung-Chieh Loe53fa0f2011-04-11 17:18:41 +0800340 }
Louis Yung-Chieh Loe53fa0f2011-04-11 17:18:41 +0800341 }
342#endif
343
hailfinger6ead7222010-11-01 22:07:04 +0000344 tmp = extract_programmer_param("emulate");
345 if (!tmp) {
346 msg_pdbg("Not emulating any flash chip.\n");
347 /* Nothing else to do. */
dhendrix0ffc2eb2011-06-14 01:35:36 +0000348 goto dummy_init_out;
hailfinger6ead7222010-11-01 22:07:04 +0000349 }
David Hendricks84377002014-09-09 16:09:31 -0700350
hailfinger6ead7222010-11-01 22:07:04 +0000351#if EMULATE_SPI_CHIP
352 if (!strcmp(tmp, "M25P10.RES")) {
353 emu_chip = EMULATE_ST_M25P10_RES;
354 emu_chip_size = 128 * 1024;
355 emu_max_byteprogram_size = 128;
356 emu_max_aai_size = 0;
357 emu_jedec_se_size = 0;
358 emu_jedec_be_52_size = 0;
359 emu_jedec_be_d8_size = 32 * 1024;
360 emu_jedec_ce_60_size = 0;
361 emu_jedec_ce_c7_size = emu_chip_size;
362 msg_pdbg("Emulating ST M25P10.RES SPI flash chip (RES, page "
363 "write)\n");
364 }
365 if (!strcmp(tmp, "SST25VF040.REMS")) {
366 emu_chip = EMULATE_SST_SST25VF040_REMS;
367 emu_chip_size = 512 * 1024;
368 emu_max_byteprogram_size = 1;
369 emu_max_aai_size = 0;
370 emu_jedec_se_size = 4 * 1024;
371 emu_jedec_be_52_size = 32 * 1024;
372 emu_jedec_be_d8_size = 0;
373 emu_jedec_ce_60_size = emu_chip_size;
374 emu_jedec_ce_c7_size = 0;
375 msg_pdbg("Emulating SST SST25VF040.REMS SPI flash chip (REMS, "
376 "byte write)\n");
377 }
378 if (!strcmp(tmp, "SST25VF032B")) {
379 emu_chip = EMULATE_SST_SST25VF032B;
380 emu_chip_size = 4 * 1024 * 1024;
381 emu_max_byteprogram_size = 1;
382 emu_max_aai_size = 2;
383 emu_jedec_se_size = 4 * 1024;
384 emu_jedec_be_52_size = 32 * 1024;
385 emu_jedec_be_d8_size = 64 * 1024;
386 emu_jedec_ce_60_size = emu_chip_size;
387 emu_jedec_ce_c7_size = emu_chip_size;
388 msg_pdbg("Emulating SST SST25VF032B SPI flash chip (RDID, AAI "
389 "write)\n");
390 }
Simon Glassd2c64a22013-07-03 22:05:21 +0900391 emu_persistent_image = extract_programmer_param("image");
392 if (!stat(emu_persistent_image, &image_stat))
393 image_size = image_stat.st_size;
394
Louis Yung-Chieh Loe53fa0f2011-04-11 17:18:41 +0800395 if (!strncmp(tmp, VARIABLE_SIZE_CHIP_NAME,
396 strlen(VARIABLE_SIZE_CHIP_NAME))) {
Simon Glassd2c64a22013-07-03 22:05:21 +0900397 if (size == SIZE_UNKNOWN) {
Louis Yung-Chieh Loe53fa0f2011-04-11 17:18:41 +0800398 msg_perr("%s: the size parameter is not given.\n",
399 __func__);
400 free(tmp);
401 return 1;
Simon Glassd2c64a22013-07-03 22:05:21 +0900402 } else if (size == SIZE_AUTO) {
403 if (image_size == SIZE_UNKNOWN) {
404 msg_perr("%s: no image so cannot use automatic size.\n",
405 __func__);
406 free(tmp);
407 return 1;
408 }
409 size = image_size;
Louis Yung-Chieh Loe53fa0f2011-04-11 17:18:41 +0800410 }
411 emu_chip = EMULATE_VARIABLE_SIZE;
412 emu_chip_size = size;
413 emu_max_byteprogram_size = 256;
414 emu_max_aai_size = 0;
415 emu_jedec_se_size = 4 * 1024;
416 emu_jedec_be_52_size = 32 * 1024;
417 emu_jedec_be_d8_size = 64 * 1024;
418 emu_jedec_ce_60_size = emu_chip_size;
419 emu_jedec_ce_c7_size = emu_chip_size;
420 msg_pdbg("Emulating generic SPI flash chip (size=%d bytes)\n",
421 emu_chip_size);
422 }
hailfinger6ead7222010-11-01 22:07:04 +0000423#endif
424 if (emu_chip == EMULATE_NONE) {
425 msg_perr("Invalid chip specified for emulation: %s\n", tmp);
426 free(tmp);
427 return 1;
428 }
David Hendricks0eda2a82014-09-12 16:32:05 -0700429
430 /* Should emulated flash erase to zero (yes/no)? */
431 tmp = extract_programmer_param("erase_to_zero");
432 if (tmp) {
433 if (!strcmp(tmp, "yes")) {
434 msg_pdbg("Emulated chip will erase to 0x00\n");
435 erase_to_zero = 1;
436 } else if (!strcmp(tmp, "no")) {
437 msg_pdbg("Emulated chip will erase to 0xff\n");
438 } else {
439 msg_perr("erase_to_zero can be \"yes\" or \"no\"\n");
440 return 1;
441 }
442 }
443
hailfinger6ead7222010-11-01 22:07:04 +0000444 free(tmp);
445 flashchip_contents = malloc(emu_chip_size);
446 if (!flashchip_contents) {
447 msg_perr("Out of memory!\n");
448 return 1;
449 }
dhendrix0ffc2eb2011-06-14 01:35:36 +0000450
David Hendricks0eda2a82014-09-12 16:32:05 -0700451 msg_pdbg("Filling fake flash chip with 0x%02x, size %i\n",
452 erase_to_zero ? 0x00 : 0xff, emu_chip_size);
453 memset(flashchip_contents, erase_to_zero ? 0x00 : 0xff, emu_chip_size);
hailfinger6ead7222010-11-01 22:07:04 +0000454
hailfinger6ead7222010-11-01 22:07:04 +0000455 if (!emu_persistent_image) {
456 /* Nothing else to do. */
dhendrix0ffc2eb2011-06-14 01:35:36 +0000457 goto dummy_init_out;
hailfinger6ead7222010-11-01 22:07:04 +0000458 }
459 if (!stat(emu_persistent_image, &image_stat)) {
460 msg_pdbg("Found persistent image %s, size %li ",
461 emu_persistent_image, (long)image_stat.st_size);
462 if (image_stat.st_size == emu_chip_size) {
463 msg_pdbg("matches.\n");
464 msg_pdbg("Reading %s\n", emu_persistent_image);
465 read_buf_from_file(flashchip_contents, emu_chip_size,
466 emu_persistent_image);
467 } else {
468 msg_pdbg("doesn't match.\n");
469 }
470 }
471#endif
hailfingera9df33c2009-05-09 00:54:55 +0000472
dhendrix0ffc2eb2011-06-14 01:35:36 +0000473dummy_init_out:
474 if (register_shutdown(dummy_shutdown, NULL)) {
hailfinger6ead7222010-11-01 22:07:04 +0000475 free(flashchip_contents);
dhendrix0ffc2eb2011-06-14 01:35:36 +0000476 return 1;
hailfinger6ead7222010-11-01 22:07:04 +0000477 }
hailfinger76bb7e92011-11-09 23:40:00 +0000478 if (dummy_buses_supported & (BUS_PARALLEL | BUS_LPC | BUS_FWH))
Patrick Georgi0a9533a2017-02-03 19:28:38 +0100479 register_par_master(&par_master_dummy,
hailfinger76bb7e92011-11-09 23:40:00 +0000480 dummy_buses_supported &
481 (BUS_PARALLEL | BUS_LPC |
482 BUS_FWH));
483 if (dummy_buses_supported & BUS_SPI)
Patrick Georgif4f1e2f2017-03-10 17:38:40 +0100484 register_spi_master(&spi_master_dummyflasher);
hailfinger76bb7e92011-11-09 23:40:00 +0000485
hailfingera9df33c2009-05-09 00:54:55 +0000486 return 0;
487}
488
Patrick Georgi4befc162017-02-03 18:32:01 +0100489void *dummy_map(const char *descr, uintptr_t phys_addr, size_t len)
hailfinger11ae3c42009-05-11 14:13:25 +0000490{
Patrick Georgi4befc162017-02-03 18:32:01 +0100491 msg_pspew("%s: Mapping %s, 0x%lx bytes at %" PRIxPTR "\n",
hailfinger50c335f2010-01-09 04:32:23 +0000492 __func__, descr, (unsigned long)len, phys_addr);
hailfinger11ae3c42009-05-11 14:13:25 +0000493 return (void *)phys_addr;
494}
495
496void dummy_unmap(void *virt_addr, size_t len)
497{
hailfinger50c335f2010-01-09 04:32:23 +0000498 msg_pspew("%s: Unmapping 0x%lx bytes at %p\n",
499 __func__, (unsigned long)len, virt_addr);
hailfinger11ae3c42009-05-11 14:13:25 +0000500}
501
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700502void dummy_chip_writeb(const struct flashctx *flash, uint8_t val, chipaddr addr)
hailfingera9df33c2009-05-09 00:54:55 +0000503{
hailfinger50c335f2010-01-09 04:32:23 +0000504 msg_pspew("%s: addr=0x%lx, val=0x%02x\n", __func__, addr, val);
hailfingera9df33c2009-05-09 00:54:55 +0000505}
506
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700507void dummy_chip_writew(const struct flashctx *flash, uint16_t val, chipaddr addr)
hailfingera9df33c2009-05-09 00:54:55 +0000508{
hailfinger50c335f2010-01-09 04:32:23 +0000509 msg_pspew("%s: addr=0x%lx, val=0x%04x\n", __func__, addr, val);
hailfingera9df33c2009-05-09 00:54:55 +0000510}
511
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700512void dummy_chip_writel(const struct flashctx *flash, uint32_t val, chipaddr addr)
hailfingera9df33c2009-05-09 00:54:55 +0000513{
hailfinger50c335f2010-01-09 04:32:23 +0000514 msg_pspew("%s: addr=0x%lx, val=0x%08x\n", __func__, addr, val);
hailfingera9df33c2009-05-09 00:54:55 +0000515}
516
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700517void dummy_chip_writen(const struct flashctx *flash, uint8_t *buf, chipaddr addr, size_t len)
hailfinger9d987ef2009-06-05 18:32:07 +0000518{
519 size_t i;
hailfinger50c335f2010-01-09 04:32:23 +0000520 msg_pspew("%s: addr=0x%lx, len=0x%08lx, writing data (hex):",
521 __func__, addr, (unsigned long)len);
hailfinger9d987ef2009-06-05 18:32:07 +0000522 for (i = 0; i < len; i++) {
523 if ((i % 16) == 0)
hailfinger50c335f2010-01-09 04:32:23 +0000524 msg_pspew("\n");
525 msg_pspew("%02x ", buf[i]);
hailfinger9d987ef2009-06-05 18:32:07 +0000526 }
527}
528
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700529uint8_t dummy_chip_readb(const struct flashctx *flash, const chipaddr addr)
hailfingera9df33c2009-05-09 00:54:55 +0000530{
hailfinger50c335f2010-01-09 04:32:23 +0000531 msg_pspew("%s: addr=0x%lx, returning 0xff\n", __func__, addr);
hailfingera9df33c2009-05-09 00:54:55 +0000532 return 0xff;
533}
534
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700535uint16_t dummy_chip_readw(const struct flashctx *flash, const chipaddr addr)
hailfingera9df33c2009-05-09 00:54:55 +0000536{
hailfinger50c335f2010-01-09 04:32:23 +0000537 msg_pspew("%s: addr=0x%lx, returning 0xffff\n", __func__, addr);
hailfingera9df33c2009-05-09 00:54:55 +0000538 return 0xffff;
539}
540
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700541uint32_t dummy_chip_readl(const struct flashctx *flash, const chipaddr addr)
hailfingera9df33c2009-05-09 00:54:55 +0000542{
hailfinger50c335f2010-01-09 04:32:23 +0000543 msg_pspew("%s: addr=0x%lx, returning 0xffffffff\n", __func__, addr);
hailfingera9df33c2009-05-09 00:54:55 +0000544 return 0xffffffff;
545}
546
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700547void dummy_chip_readn(const struct flashctx *flash, uint8_t *buf, const chipaddr addr, size_t len)
hailfinger9d987ef2009-06-05 18:32:07 +0000548{
hailfinger50c335f2010-01-09 04:32:23 +0000549 msg_pspew("%s: addr=0x%lx, len=0x%lx, returning array of 0xff\n",
550 __func__, addr, (unsigned long)len);
hailfinger9d987ef2009-06-05 18:32:07 +0000551 memset(buf, 0xff, len);
552 return;
553}
554
hailfinger6ead7222010-11-01 22:07:04 +0000555#if EMULATE_SPI_CHIP
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700556static int emulate_spi_chip_response(const struct flashctx *flash, unsigned int writecnt, unsigned int readcnt,
hailfinger6ead7222010-11-01 22:07:04 +0000557 const unsigned char *writearr, unsigned char *readarr)
558{
Carl-Daniel Hailfingerc49783d2016-08-05 10:52:06 -0700559 unsigned int offs, i;
stefanctc5eb8a92011-11-23 09:13:48 +0000560 static int unsigned aai_offs;
hailfinger6ead7222010-11-01 22:07:04 +0000561 static int aai_active = 0;
562
563 if (writecnt == 0) {
564 msg_perr("No command sent to the chip!\n");
565 return 1;
566 }
Stefan Tauner718d1eb2016-08-18 18:00:53 -0700567 /* spi_blacklist has precedence over spi_ignorelist. */
Carl-Daniel Hailfingerc49783d2016-08-05 10:52:06 -0700568 for (i = 0; i < spi_blacklist_size; i++) {
569 if (writearr[0] == spi_blacklist[i]) {
570 msg_pdbg("Refusing blacklisted SPI command 0x%02x\n",
571 spi_blacklist[i]);
572 return SPI_INVALID_OPCODE;
573 }
574 }
575 for (i = 0; i < spi_ignorelist_size; i++) {
576 if (writearr[0] == spi_ignorelist[i]) {
577 msg_cdbg("Ignoring ignorelisted SPI command 0x%02x\n",
578 spi_ignorelist[i]);
579 /* Return success because the command does not fail,
580 * it is simply ignored.
581 */
582 return 0;
583 }
584 }
hailfinger6ead7222010-11-01 22:07:04 +0000585 switch (writearr[0]) {
586 case JEDEC_RES:
587 if (emu_chip != EMULATE_ST_M25P10_RES)
588 break;
589 /* Respond with ST_M25P10_RES. */
590 if (readcnt > 0)
591 readarr[0] = 0x10;
592 break;
593 case JEDEC_REMS:
594 if (emu_chip != EMULATE_SST_SST25VF040_REMS)
595 break;
596 /* Respond with SST_SST25VF040_REMS. */
597 if (readcnt > 0)
598 readarr[0] = 0xbf;
599 if (readcnt > 1)
600 readarr[1] = 0x44;
601 break;
602 case JEDEC_RDID:
Louis Yung-Chieh Loe53fa0f2011-04-11 17:18:41 +0800603 if (emu_chip == EMULATE_SST_SST25VF032B) {
604 /* Respond with SST_SST25VF032B. */
605 if (readcnt > 0)
606 readarr[0] = 0xbf;
607 if (readcnt > 1)
608 readarr[1] = 0x25;
609 if (readcnt > 2)
610 readarr[2] = 0x4a;
611 } else if (emu_chip == EMULATE_VARIABLE_SIZE) {
612 const uint16_t man_id = VARIABLE_SIZE_MANUF_ID;
613 const uint16_t dev_id = VARIABLE_SIZE_DEVICE_ID;
614 if (readcnt > 0) readarr[0] = man_id >> 8;
615 if (readcnt > 1) readarr[1] = man_id & 0xff;
616 if (readcnt > 2) readarr[2] = dev_id >> 8;
617 if (readcnt > 3) readarr[3] = dev_id & 0xff;
618 }
hailfinger6ead7222010-11-01 22:07:04 +0000619 break;
620 case JEDEC_RDSR:
621 memset(readarr, 0, readcnt);
622 if (aai_active)
623 memset(readarr, 1 << 6, readcnt);
624 break;
625 case JEDEC_READ:
626 offs = writearr[1] << 16 | writearr[2] << 8 | writearr[3];
627 /* Truncate to emu_chip_size. */
628 offs %= emu_chip_size;
629 if (readcnt > 0)
630 memcpy(readarr, flashchip_contents + offs, readcnt);
631 break;
632 case JEDEC_BYTE_PROGRAM:
633 offs = writearr[1] << 16 | writearr[2] << 8 | writearr[3];
634 /* Truncate to emu_chip_size. */
635 offs %= emu_chip_size;
636 if (writecnt < 5) {
637 msg_perr("BYTE PROGRAM size too short!\n");
638 return 1;
639 }
640 if (writecnt - 4 > emu_max_byteprogram_size) {
641 msg_perr("Max BYTE PROGRAM size exceeded!\n");
642 return 1;
643 }
644 memcpy(flashchip_contents + offs, writearr + 4, writecnt - 4);
Simon Glasscf253a72013-07-10 21:10:11 -0700645 emu_modified = 1;
hailfinger6ead7222010-11-01 22:07:04 +0000646 break;
647 case JEDEC_AAI_WORD_PROGRAM:
648 if (!emu_max_aai_size)
649 break;
650 if (!aai_active) {
651 if (writecnt < JEDEC_AAI_WORD_PROGRAM_OUTSIZE) {
652 msg_perr("Initial AAI WORD PROGRAM size too "
653 "short!\n");
654 return 1;
655 }
656 if (writecnt > JEDEC_AAI_WORD_PROGRAM_OUTSIZE) {
657 msg_perr("Initial AAI WORD PROGRAM size too "
658 "long!\n");
659 return 1;
660 }
661 aai_active = 1;
662 aai_offs = writearr[1] << 16 | writearr[2] << 8 |
663 writearr[3];
664 /* Truncate to emu_chip_size. */
665 aai_offs %= emu_chip_size;
666 memcpy(flashchip_contents + aai_offs, writearr + 4, 2);
667 aai_offs += 2;
668 } else {
669 if (writecnt < JEDEC_AAI_WORD_PROGRAM_CONT_OUTSIZE) {
670 msg_perr("Continuation AAI WORD PROGRAM size "
671 "too short!\n");
672 return 1;
673 }
674 if (writecnt > JEDEC_AAI_WORD_PROGRAM_CONT_OUTSIZE) {
675 msg_perr("Continuation AAI WORD PROGRAM size "
676 "too long!\n");
677 return 1;
678 }
679 memcpy(flashchip_contents + aai_offs, writearr + 1, 2);
680 aai_offs += 2;
681 }
Simon Glasscf253a72013-07-10 21:10:11 -0700682 emu_modified = 1;
hailfinger6ead7222010-11-01 22:07:04 +0000683 break;
684 case JEDEC_WRDI:
685 if (!emu_max_aai_size)
686 break;
687 aai_active = 0;
688 break;
689 case JEDEC_SE:
690 if (!emu_jedec_se_size)
691 break;
692 if (writecnt != JEDEC_SE_OUTSIZE) {
693 msg_perr("SECTOR ERASE 0x20 outsize invalid!\n");
694 return 1;
695 }
696 if (readcnt != JEDEC_SE_INSIZE) {
697 msg_perr("SECTOR ERASE 0x20 insize invalid!\n");
698 return 1;
699 }
700 offs = writearr[1] << 16 | writearr[2] << 8 | writearr[3];
701 if (offs & (emu_jedec_se_size - 1))
hailfingere53f5e42011-02-04 22:52:04 +0000702 msg_pdbg("Unaligned SECTOR ERASE 0x20: 0x%x\n", offs);
hailfinger6ead7222010-11-01 22:07:04 +0000703 offs &= ~(emu_jedec_se_size - 1);
704 memset(flashchip_contents + offs, 0xff, emu_jedec_se_size);
Simon Glasscf253a72013-07-10 21:10:11 -0700705 emu_modified = 1;
hailfinger6ead7222010-11-01 22:07:04 +0000706 break;
707 case JEDEC_BE_52:
708 if (!emu_jedec_be_52_size)
709 break;
710 if (writecnt != JEDEC_BE_52_OUTSIZE) {
711 msg_perr("BLOCK ERASE 0x52 outsize invalid!\n");
712 return 1;
713 }
714 if (readcnt != JEDEC_BE_52_INSIZE) {
715 msg_perr("BLOCK ERASE 0x52 insize invalid!\n");
716 return 1;
717 }
718 offs = writearr[1] << 16 | writearr[2] << 8 | writearr[3];
719 if (offs & (emu_jedec_be_52_size - 1))
hailfingere53f5e42011-02-04 22:52:04 +0000720 msg_pdbg("Unaligned BLOCK ERASE 0x52: 0x%x\n", offs);
hailfinger6ead7222010-11-01 22:07:04 +0000721 offs &= ~(emu_jedec_be_52_size - 1);
722 memset(flashchip_contents + offs, 0xff, emu_jedec_be_52_size);
Simon Glasscf253a72013-07-10 21:10:11 -0700723 emu_modified = 1;
hailfinger6ead7222010-11-01 22:07:04 +0000724 break;
725 case JEDEC_BE_D8:
726 if (!emu_jedec_be_d8_size)
727 break;
728 if (writecnt != JEDEC_BE_D8_OUTSIZE) {
729 msg_perr("BLOCK ERASE 0xd8 outsize invalid!\n");
730 return 1;
731 }
732 if (readcnt != JEDEC_BE_D8_INSIZE) {
733 msg_perr("BLOCK ERASE 0xd8 insize invalid!\n");
734 return 1;
735 }
736 offs = writearr[1] << 16 | writearr[2] << 8 | writearr[3];
737 if (offs & (emu_jedec_be_d8_size - 1))
hailfingere53f5e42011-02-04 22:52:04 +0000738 msg_pdbg("Unaligned BLOCK ERASE 0xd8: 0x%x\n", offs);
hailfinger6ead7222010-11-01 22:07:04 +0000739 offs &= ~(emu_jedec_be_d8_size - 1);
740 memset(flashchip_contents + offs, 0xff, emu_jedec_be_d8_size);
741 break;
742 case JEDEC_CE_60:
743 if (!emu_jedec_ce_60_size)
744 break;
745 if (writecnt != JEDEC_CE_60_OUTSIZE) {
746 msg_perr("CHIP ERASE 0x60 outsize invalid!\n");
747 return 1;
748 }
749 if (readcnt != JEDEC_CE_60_INSIZE) {
750 msg_perr("CHIP ERASE 0x60 insize invalid!\n");
751 return 1;
752 }
hailfingere53f5e42011-02-04 22:52:04 +0000753 /* JEDEC_CE_60_OUTSIZE is 1 (no address) -> no offset. */
hailfinger6ead7222010-11-01 22:07:04 +0000754 /* emu_jedec_ce_60_size is emu_chip_size. */
hailfingere53f5e42011-02-04 22:52:04 +0000755 memset(flashchip_contents, 0xff, emu_jedec_ce_60_size);
Simon Glasscf253a72013-07-10 21:10:11 -0700756 emu_modified = 1;
hailfinger6ead7222010-11-01 22:07:04 +0000757 break;
758 case JEDEC_CE_C7:
759 if (!emu_jedec_ce_c7_size)
760 break;
761 if (writecnt != JEDEC_CE_C7_OUTSIZE) {
762 msg_perr("CHIP ERASE 0xc7 outsize invalid!\n");
763 return 1;
764 }
765 if (readcnt != JEDEC_CE_C7_INSIZE) {
766 msg_perr("CHIP ERASE 0xc7 insize invalid!\n");
767 return 1;
768 }
hailfingere53f5e42011-02-04 22:52:04 +0000769 /* JEDEC_CE_C7_OUTSIZE is 1 (no address) -> no offset. */
hailfinger6ead7222010-11-01 22:07:04 +0000770 /* emu_jedec_ce_c7_size is emu_chip_size. */
771 memset(flashchip_contents, 0xff, emu_jedec_ce_c7_size);
Simon Glasscf253a72013-07-10 21:10:11 -0700772 emu_modified = 1;
hailfinger6ead7222010-11-01 22:07:04 +0000773 break;
774 default:
775 /* No special response. */
776 break;
777 }
778 return 0;
779}
780#endif
781
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700782static int dummy_spi_send_command(const struct flashctx *flash, unsigned int writecnt, unsigned int readcnt,
hailfingerf91e3b52009-05-14 12:59:36 +0000783 const unsigned char *writearr, unsigned char *readarr)
784{
785 int i;
786
hailfinger50c335f2010-01-09 04:32:23 +0000787 msg_pspew("%s:", __func__);
hailfingerf91e3b52009-05-14 12:59:36 +0000788
hailfinger50c335f2010-01-09 04:32:23 +0000789 msg_pspew(" writing %u bytes:", writecnt);
hailfingerf91e3b52009-05-14 12:59:36 +0000790 for (i = 0; i < writecnt; i++)
hailfinger50c335f2010-01-09 04:32:23 +0000791 msg_pspew(" 0x%02x", writearr[i]);
hailfingerf91e3b52009-05-14 12:59:36 +0000792
hailfinger6ead7222010-11-01 22:07:04 +0000793 /* Response for unknown commands and missing chip is 0xff. */
794 memset(readarr, 0xff, readcnt);
795#if EMULATE_SPI_CHIP
796 switch (emu_chip) {
797 case EMULATE_ST_M25P10_RES:
798 case EMULATE_SST_SST25VF040_REMS:
799 case EMULATE_SST_SST25VF032B:
Louis Yung-Chieh Loe53fa0f2011-04-11 17:18:41 +0800800 case EMULATE_VARIABLE_SIZE:
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700801 if (emulate_spi_chip_response(flash, writecnt, readcnt, writearr,
hailfinger6ead7222010-11-01 22:07:04 +0000802 readarr)) {
Carl-Daniel Hailfingerc49783d2016-08-05 10:52:06 -0700803 msg_pdbg("Invalid command sent to flash chip!\n");
hailfinger6ead7222010-11-01 22:07:04 +0000804 return 1;
805 }
806 break;
807 default:
808 break;
809 }
810#endif
hailfinger50c335f2010-01-09 04:32:23 +0000811 msg_pspew(" reading %u bytes:", readcnt);
uwe8d342eb2011-07-28 08:13:25 +0000812 for (i = 0; i < readcnt; i++)
hailfinger6ead7222010-11-01 22:07:04 +0000813 msg_pspew(" 0x%02x", readarr[i]);
hailfinger50c335f2010-01-09 04:32:23 +0000814 msg_pspew("\n");
David Hendricks84377002014-09-09 16:09:31 -0700815
816 programmer_delay((writecnt + readcnt) * delay_us);
hailfingerf91e3b52009-05-14 12:59:36 +0000817 return 0;
818}
hailfingera8727712010-06-20 10:58:32 +0000819
Patrick Georgiab8353e2017-02-03 18:32:01 +0100820static int dummy_spi_write_256(struct flashctx *flash, const uint8_t *buf,
stefanctc5eb8a92011-11-23 09:13:48 +0000821 unsigned int start, unsigned int len)
hailfingerc7d06c62010-07-14 16:19:05 +0000822{
hailfinger6ead7222010-11-01 22:07:04 +0000823 return spi_write_chunked(flash, buf, start, len,
824 spi_write_256_chunksize);
hailfingerc7d06c62010-07-14 16:19:05 +0000825}
Louis Yung-Chieh Loe53fa0f2011-04-11 17:18:41 +0800826
827#if EMULATE_CHIP && EMULATE_SPI_CHIP
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700828int probe_variable_size(struct flashctx *flash)
Louis Yung-Chieh Loe53fa0f2011-04-11 17:18:41 +0800829{
830 int i;
831
832 /* Skip the probing if we don't emulate this chip. */
833 if (emu_chip != EMULATE_VARIABLE_SIZE)
834 return 0;
835
836 /*
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700837 * This will break if one day flashctx becomes read-only.
Louis Yung-Chieh Loe53fa0f2011-04-11 17:18:41 +0800838 * Once that happens, we need to have special hacks in functions:
839 *
840 * erase_and_write_flash() in flashrom.c
841 * read_flash_to_file()
842 * handle_romentries()
843 * ...
844 *
845 * Search "total_size * 1024" in code.
846 */
847 if (emu_chip_size % 1024)
848 msg_perr("%s: emu_chip_size is not multipler of 1024.\n",
849 __func__);
Patrick Georgif3fa2992017-02-02 16:24:44 +0100850 flash->chip->total_size = emu_chip_size / 1024;
Louis Yung-Chieh Loe53fa0f2011-04-11 17:18:41 +0800851 msg_cdbg("%s: set flash->total_size to %dK bytes.\n", __func__,
Patrick Georgif3fa2992017-02-02 16:24:44 +0100852 flash->chip->total_size);
Louis Yung-Chieh Loe53fa0f2011-04-11 17:18:41 +0800853
David Hendricks0eda2a82014-09-12 16:32:05 -0700854 if (erase_to_zero)
Patrick Georgif3fa2992017-02-02 16:24:44 +0100855 flash->chip->feature_bits |= FEATURE_ERASE_TO_ZERO;
David Hendricks0eda2a82014-09-12 16:32:05 -0700856
Louis Yung-Chieh Loe53fa0f2011-04-11 17:18:41 +0800857 /* Update eraser count */
858 for (i = 0; i < NUM_ERASEFUNCTIONS; i++) {
Patrick Georgif3fa2992017-02-02 16:24:44 +0100859 struct block_eraser *eraser = &flash->chip->block_erasers[i];
Louis Yung-Chieh Loe53fa0f2011-04-11 17:18:41 +0800860 if (eraser->block_erase == NULL)
861 break;
862
863 eraser->eraseblocks[0].count = emu_chip_size /
864 eraser->eraseblocks[0].size;
865 msg_cdbg("%s: eraser.size=%d, .count=%d\n",
866 __func__, eraser->eraseblocks[0].size,
867 eraser->eraseblocks[0].count);
868 }
869
870 return 1;
871}
872#endif