blob: 92c30ee27f7f1821a65cddaf7f9a6b476706d8e0 [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.
hailfingera9df33c2009-05-09 00:54:55 +000014 */
15
hailfingera9df33c2009-05-09 00:54:55 +000016#include <string.h>
17#include <stdlib.h>
Carl-Daniel Hailfingerc49783d2016-08-05 10:52:06 -070018#include <stdio.h>
19#include <ctype.h>
Edward O'Callaghanec8b0d92020-09-17 17:27:45 +100020#include <errno.h>
hailfingera9df33c2009-05-09 00:54:55 +000021#include "flash.h"
hailfingera8727712010-06-20 10:58:32 +000022#include "chipdrivers.h"
hailfinger428f6852010-07-27 22:41:39 +000023#include "programmer.h"
Louis Yung-Chieh Loe53fa0f2011-04-11 17:18:41 +080024#include "flashchips.h"
hailfingera9df33c2009-05-09 00:54:55 +000025
hailfinger6ead7222010-11-01 22:07:04 +000026/* Remove the #define below if you don't want SPI flash chip emulation. */
27#define EMULATE_SPI_CHIP 1
28
29#if EMULATE_SPI_CHIP
30#define EMULATE_CHIP 1
31#include "spi.h"
32#endif
33
34#if EMULATE_CHIP
35#include <sys/types.h>
36#include <sys/stat.h>
37#endif
38
39#if EMULATE_CHIP
40static uint8_t *flashchip_contents = NULL;
41enum emu_chip {
42 EMULATE_NONE,
43 EMULATE_ST_M25P10_RES,
44 EMULATE_SST_SST25VF040_REMS,
45 EMULATE_SST_SST25VF032B,
Stuart Langley78cacf72020-04-23 11:48:01 +100046 EMULATE_MACRONIX_MX25L6436,
Edward O'Callaghanec8b0d92020-09-17 17:27:45 +100047 EMULATE_WINBOND_W25Q128FV,
Louis Yung-Chieh Loe53fa0f2011-04-11 17:18:41 +080048 EMULATE_VARIABLE_SIZE,
hailfinger6ead7222010-11-01 22:07:04 +000049};
Stuart Langley78cacf72020-04-23 11:48:01 +100050
Lachlan Bishopbf1476e2020-09-10 14:57:05 +100051struct emu_data {
52 enum emu_chip emu_chip;
53 char *emu_persistent_image;
54 unsigned int emu_chip_size;
55 int erase_to_zero;
56 int emu_modified; /* is the image modified since reading it? */
57 uint8_t emu_status;
Edward O'Callaghan0037f452020-09-17 13:32:00 +100058 /* If "freq" parameter is passed in from command line, commands will delay
59 * for this period before returning. */
60 unsigned long int delay_us;
Lachlan Bishopbf1476e2020-09-10 14:57:05 +100061 unsigned int emu_max_byteprogram_size;
62 unsigned int emu_max_aai_size;
63 unsigned int emu_jedec_se_size;
64 unsigned int emu_jedec_be_52_size;
65 unsigned int emu_jedec_be_d8_size;
66 unsigned int emu_jedec_ce_60_size;
67 unsigned int emu_jedec_ce_c7_size;
68 unsigned char spi_blacklist[256];
69 unsigned char spi_ignorelist[256];
70 unsigned int spi_blacklist_size;
71 unsigned int spi_ignorelist_size;
72};
73
74#if EMULATE_SPI_CHIP
Stuart Langley78cacf72020-04-23 11:48:01 +100075/* A legit complete SFDP table based on the MX25L6436E (rev. 1.8) datasheet. */
76static const uint8_t sfdp_table[] = {
77 0x53, 0x46, 0x44, 0x50, // @0x00: SFDP signature
78 0x00, 0x01, 0x01, 0xFF, // @0x04: revision 1.0, 2 headers
79 0x00, 0x00, 0x01, 0x09, // @0x08: JEDEC SFDP header rev. 1.0, 9 DW long
80 0x1C, 0x00, 0x00, 0xFF, // @0x0C: PTP0 = 0x1C (instead of 0x30)
81 0xC2, 0x00, 0x01, 0x04, // @0x10: Macronix header rev. 1.0, 4 DW long
82 0x48, 0x00, 0x00, 0xFF, // @0x14: PTP1 = 0x48 (instead of 0x60)
83 0xFF, 0xFF, 0xFF, 0xFF, // @0x18: hole.
84 0xE5, 0x20, 0xC9, 0xFF, // @0x1C: SFDP parameter table start
85 0xFF, 0xFF, 0xFF, 0x03, // @0x20
86 0x00, 0xFF, 0x08, 0x6B, // @0x24
87 0x08, 0x3B, 0x00, 0xFF, // @0x28
88 0xEE, 0xFF, 0xFF, 0xFF, // @0x2C
89 0xFF, 0xFF, 0x00, 0x00, // @0x30
90 0xFF, 0xFF, 0x00, 0xFF, // @0x34
91 0x0C, 0x20, 0x0F, 0x52, // @0x38
92 0x10, 0xD8, 0x00, 0xFF, // @0x3C: SFDP parameter table end
93 0xFF, 0xFF, 0xFF, 0xFF, // @0x40: hole.
94 0xFF, 0xFF, 0xFF, 0xFF, // @0x44: hole.
95 0x00, 0x36, 0x00, 0x27, // @0x48: Macronix parameter table start
96 0xF4, 0x4F, 0xFF, 0xFF, // @0x4C
97 0xD9, 0xC8, 0xFF, 0xFF, // @0x50
98 0xFF, 0xFF, 0xFF, 0xFF, // @0x54: Macronix parameter table end
99};
100
hailfinger6ead7222010-11-01 22:07:04 +0000101#endif
102#endif
103
stefanctc5eb8a92011-11-23 09:13:48 +0000104static unsigned int spi_write_256_chunksize = 256;
hailfinger6ead7222010-11-01 22:07:04 +0000105
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700106static int dummy_spi_send_command(const struct flashctx *flash, unsigned int writecnt, unsigned int readcnt,
Stuart langleyc98e43f2020-03-26 20:27:36 +1100107 const unsigned char *writearr, unsigned char *readarr);
Patrick Georgiab8353e2017-02-03 18:32:01 +0100108static int dummy_spi_write_256(struct flashctx *flash, const uint8_t *buf,
stefanctc5eb8a92011-11-23 09:13:48 +0000109 unsigned int start, unsigned int len);
Stuart langleyc98e43f2020-03-26 20:27:36 +1100110static void dummy_chip_writeb(const struct flashctx *flash, uint8_t val, chipaddr addr);
111static void dummy_chip_writew(const struct flashctx *flash, uint16_t val, chipaddr addr);
112static void dummy_chip_writel(const struct flashctx *flash, uint32_t val, chipaddr addr);
113static void dummy_chip_writen(const struct flashctx *flash, const uint8_t *buf, chipaddr addr, size_t len);
114static uint8_t dummy_chip_readb(const struct flashctx *flash, const chipaddr addr);
115static uint16_t dummy_chip_readw(const struct flashctx *flash, const chipaddr addr);
116static uint32_t dummy_chip_readl(const struct flashctx *flash, const chipaddr addr);
117static void dummy_chip_readn(const struct flashctx *flash, uint8_t *buf, const chipaddr addr, size_t len);
mkarcherd264e9e2011-05-11 17:07:07 +0000118
Lachlan Bishopbf1476e2020-09-10 14:57:05 +1000119static struct spi_master spi_master_dummyflasher = {
Edward O'Callaghana6673bd2019-06-24 15:22:28 +1000120 .features = SPI_MASTER_4BA,
uwe8d342eb2011-07-28 08:13:25 +0000121 .max_data_read = MAX_DATA_READ_UNLIMITED,
122 .max_data_write = MAX_DATA_UNSPECIFIED,
123 .command = dummy_spi_send_command,
124 .multicommand = default_spi_send_multicommand,
125 .read = default_spi_read,
126 .write_256 = dummy_spi_write_256,
Edward O'Callaghaneeaac6b2020-10-12 19:51:56 +1100127 .write_aai = default_spi_write_aai,
mkarcherd264e9e2011-05-11 17:07:07 +0000128};
dhendrix0ffc2eb2011-06-14 01:35:36 +0000129
Namyoon Wooc429efb2020-10-17 20:25:15 -0700130static struct par_master par_master_dummy = {
hailfinger76bb7e92011-11-09 23:40:00 +0000131 .chip_readb = dummy_chip_readb,
132 .chip_readw = dummy_chip_readw,
133 .chip_readl = dummy_chip_readl,
134 .chip_readn = dummy_chip_readn,
135 .chip_writeb = dummy_chip_writeb,
136 .chip_writew = dummy_chip_writew,
137 .chip_writel = dummy_chip_writel,
138 .chip_writen = dummy_chip_writen,
139};
140
Edward O'Callaghanef4e28b2019-06-28 13:18:41 +1000141static enum chipbustype dummy_buses_supported = BUS_NONE;
hailfinger76bb7e92011-11-09 23:40:00 +0000142
David Hendricks93784b42016-08-09 17:00:38 -0700143static int dummy_shutdown(void *data)
dhendrix0ffc2eb2011-06-14 01:35:36 +0000144{
145 msg_pspew("%s\n", __func__);
146#if EMULATE_CHIP
Lachlan Bishopbf1476e2020-09-10 14:57:05 +1000147 struct emu_data *emu_data = (struct emu_data *)data;
148 if (emu_data->emu_chip != EMULATE_NONE) {
149 if (emu_data->emu_persistent_image && emu_data->emu_modified) {
150 msg_pdbg("Writing %s\n", emu_data->emu_persistent_image);
151 write_buf_to_file(flashchip_contents,
152 emu_data->emu_chip_size,
153 emu_data->emu_persistent_image);
154 free(emu_data->emu_persistent_image);
155 emu_data->emu_persistent_image = NULL;
dhendrix0ffc2eb2011-06-14 01:35:36 +0000156 }
157 free(flashchip_contents);
158 }
159#endif
160 return 0;
161}
162
David Hendricksac1d25c2016-08-09 17:00:58 -0700163int dummy_init(void)
hailfingera9df33c2009-05-09 00:54:55 +0000164{
hailfinger1ef766d2010-07-06 09:55:48 +0000165 char *bustext = NULL;
hailfinger6ead7222010-11-01 22:07:04 +0000166 char *tmp = NULL;
Edward O'Callaghanec8b0d92020-09-17 17:27:45 +1000167 unsigned int i;
Louis Yung-Chieh Loe53fa0f2011-04-11 17:18:41 +0800168#if EMULATE_SPI_CHIP
Edward O'Callaghanec8b0d92020-09-17 17:27:45 +1000169 char *status = NULL;
Edward O'Callaghan602fbab2020-11-23 12:27:57 +1100170 int size = -1; /* size for VARIABLE_SIZE chip device */
Louis Yung-Chieh Loe53fa0f2011-04-11 17:18:41 +0800171#endif
Edward O'Callaghanec8b0d92020-09-17 17:27:45 +1000172#if EMULATE_CHIP
173 struct stat image_stat;
hailfinger6ead7222010-11-01 22:07:04 +0000174#endif
hailfinger1ef766d2010-07-06 09:55:48 +0000175
Lachlan Bishopbf1476e2020-09-10 14:57:05 +1000176 struct emu_data *data = calloc(1, sizeof(struct emu_data));
177 if (!data) {
178 msg_perr("Out of memory!\n");
179 return 1;
180 }
181 data->emu_chip = EMULATE_NONE;
Edward O'Callaghan0037f452020-09-17 13:32:00 +1000182 data->delay_us = 0;
Lachlan Bishopbf1476e2020-09-10 14:57:05 +1000183 spi_master_dummyflasher.data = data;
Namyoon Wooc429efb2020-10-17 20:25:15 -0700184 par_master_dummy.data = data;
Lachlan Bishopbf1476e2020-09-10 14:57:05 +1000185
hailfinger50c335f2010-01-09 04:32:23 +0000186 msg_pspew("%s\n", __func__);
hailfinger668f3502009-06-01 00:02:11 +0000187
hailfingerddeb4ac2010-07-08 10:13:37 +0000188 bustext = extract_programmer_param("bus");
hailfinger1ef766d2010-07-06 09:55:48 +0000189 msg_pdbg("Requested buses are: %s\n", bustext ? bustext : "default");
190 if (!bustext)
191 bustext = strdup("parallel+lpc+fwh+spi");
hailfinger668f3502009-06-01 00:02:11 +0000192 /* Convert the parameters to lowercase. */
hailfinger1ef766d2010-07-06 09:55:48 +0000193 tolower_string(bustext);
hailfinger668f3502009-06-01 00:02:11 +0000194
hailfinger76bb7e92011-11-09 23:40:00 +0000195 dummy_buses_supported = BUS_NONE;
hailfinger1ef766d2010-07-06 09:55:48 +0000196 if (strstr(bustext, "parallel")) {
hailfinger76bb7e92011-11-09 23:40:00 +0000197 dummy_buses_supported |= BUS_PARALLEL;
hailfinger50c335f2010-01-09 04:32:23 +0000198 msg_pdbg("Enabling support for %s flash.\n", "parallel");
hailfinger668f3502009-06-01 00:02:11 +0000199 }
hailfinger1ef766d2010-07-06 09:55:48 +0000200 if (strstr(bustext, "lpc")) {
hailfinger76bb7e92011-11-09 23:40:00 +0000201 dummy_buses_supported |= BUS_LPC;
hailfinger50c335f2010-01-09 04:32:23 +0000202 msg_pdbg("Enabling support for %s flash.\n", "LPC");
hailfinger668f3502009-06-01 00:02:11 +0000203 }
hailfinger1ef766d2010-07-06 09:55:48 +0000204 if (strstr(bustext, "fwh")) {
hailfinger76bb7e92011-11-09 23:40:00 +0000205 dummy_buses_supported |= BUS_FWH;
hailfinger50c335f2010-01-09 04:32:23 +0000206 msg_pdbg("Enabling support for %s flash.\n", "FWH");
hailfinger668f3502009-06-01 00:02:11 +0000207 }
hailfinger1ef766d2010-07-06 09:55:48 +0000208 if (strstr(bustext, "spi")) {
hailfinger76bb7e92011-11-09 23:40:00 +0000209 dummy_buses_supported |= BUS_SPI;
hailfinger50c335f2010-01-09 04:32:23 +0000210 msg_pdbg("Enabling support for %s flash.\n", "SPI");
hailfinger668f3502009-06-01 00:02:11 +0000211 }
hailfinger76bb7e92011-11-09 23:40:00 +0000212 if (dummy_buses_supported == BUS_NONE)
hailfinger50c335f2010-01-09 04:32:23 +0000213 msg_pdbg("Support for all flash bus types disabled.\n");
hailfinger1ef766d2010-07-06 09:55:48 +0000214 free(bustext);
hailfinger6ead7222010-11-01 22:07:04 +0000215
216 tmp = extract_programmer_param("spi_write_256_chunksize");
217 if (tmp) {
218 spi_write_256_chunksize = atoi(tmp);
219 free(tmp);
220 if (spi_write_256_chunksize < 1) {
221 msg_perr("invalid spi_write_256_chunksize\n");
222 return 1;
223 }
224 }
225
Carl-Daniel Hailfingerc49783d2016-08-05 10:52:06 -0700226 tmp = extract_programmer_param("spi_blacklist");
227 if (tmp) {
228 i = strlen(tmp);
229 if (!strncmp(tmp, "0x", 2)) {
230 i -= 2;
231 memmove(tmp, tmp + 2, i + 1);
232 }
233 if ((i > 512) || (i % 2)) {
234 msg_perr("Invalid SPI command blacklist length\n");
235 free(tmp);
236 return 1;
237 }
Lachlan Bishopbf1476e2020-09-10 14:57:05 +1000238 data->spi_blacklist_size = i / 2;
239 for (i = 0; i < data->spi_blacklist_size * 2; i++) {
Carl-Daniel Hailfingerc49783d2016-08-05 10:52:06 -0700240 if (!isxdigit((unsigned char)tmp[i])) {
241 msg_perr("Invalid char \"%c\" in SPI command "
242 "blacklist\n", tmp[i]);
243 free(tmp);
244 return 1;
245 }
246 }
Lachlan Bishopbf1476e2020-09-10 14:57:05 +1000247 for (i = 0; i < data->spi_blacklist_size; i++) {
Carl-Daniel Hailfingerc49783d2016-08-05 10:52:06 -0700248 unsigned int tmp2;
249 /* SCNx8 is apparently not supported by MSVC (and thus
250 * MinGW), so work around it with an extra variable
251 */
252 sscanf(tmp + i * 2, "%2x", &tmp2);
Lachlan Bishopbf1476e2020-09-10 14:57:05 +1000253 data->spi_blacklist[i] = (uint8_t)tmp2;
Carl-Daniel Hailfingerc49783d2016-08-05 10:52:06 -0700254 }
255 msg_pdbg("SPI blacklist is ");
Lachlan Bishopbf1476e2020-09-10 14:57:05 +1000256 for (i = 0; i < data->spi_blacklist_size; i++)
257 msg_pdbg("%02x ", data->spi_blacklist[i]);
258 msg_pdbg(", size %u\n", data->spi_blacklist_size);
Carl-Daniel Hailfingerc49783d2016-08-05 10:52:06 -0700259 }
260 free(tmp);
261
262 tmp = extract_programmer_param("spi_ignorelist");
263 if (tmp) {
264 i = strlen(tmp);
265 if (!strncmp(tmp, "0x", 2)) {
266 i -= 2;
267 memmove(tmp, tmp + 2, i + 1);
268 }
269 if ((i > 512) || (i % 2)) {
270 msg_perr("Invalid SPI command ignorelist length\n");
271 free(tmp);
272 return 1;
273 }
Lachlan Bishopbf1476e2020-09-10 14:57:05 +1000274 data->spi_ignorelist_size = i / 2;
275 for (i = 0; i < data->spi_ignorelist_size * 2; i++) {
Carl-Daniel Hailfingerc49783d2016-08-05 10:52:06 -0700276 if (!isxdigit((unsigned char)tmp[i])) {
277 msg_perr("Invalid char \"%c\" in SPI command "
278 "ignorelist\n", tmp[i]);
279 free(tmp);
280 return 1;
281 }
282 }
Lachlan Bishopbf1476e2020-09-10 14:57:05 +1000283 for (i = 0; i < data->spi_ignorelist_size; i++) {
Carl-Daniel Hailfingerc49783d2016-08-05 10:52:06 -0700284 unsigned int tmp2;
285 /* SCNx8 is apparently not supported by MSVC (and thus
286 * MinGW), so work around it with an extra variable
287 */
288 sscanf(tmp + i * 2, "%2x", &tmp2);
Lachlan Bishopbf1476e2020-09-10 14:57:05 +1000289 data->spi_ignorelist[i] = (uint8_t)tmp2;
Carl-Daniel Hailfingerc49783d2016-08-05 10:52:06 -0700290 }
291 msg_pdbg("SPI ignorelist is ");
Lachlan Bishopbf1476e2020-09-10 14:57:05 +1000292 for (i = 0; i < data->spi_ignorelist_size; i++)
293 msg_pdbg("%02x ", data->spi_ignorelist[i]);
294 msg_pdbg(", size %u\n", data->spi_ignorelist_size);
Carl-Daniel Hailfingerc49783d2016-08-05 10:52:06 -0700295 }
296 free(tmp);
297
David Hendricks84377002014-09-09 16:09:31 -0700298 /* frequency to emulate in Hz (default), KHz, or MHz */
299 tmp = extract_programmer_param("freq");
300 if (tmp) {
301 unsigned long int freq;
302 char *units = tmp;
303 char *end = tmp + strlen(tmp);
304
305 errno = 0;
306 freq = strtoul(tmp, &units, 0);
307 if (errno) {
308 msg_perr("Invalid frequency \"%s\", %s\n",
309 tmp, strerror(errno));
Edward O'Callaghan0037f452020-09-17 13:32:00 +1000310 free(tmp);
311 return 1;
David Hendricks84377002014-09-09 16:09:31 -0700312 }
313
314 if ((units > tmp) && (units < end)) {
315 int units_valid = 0;
316
317 if (units < end - 3) {
318 ;
319 } else if (units == end - 2) {
320 if (!strcasecmp(units, "hz"))
321 units_valid = 1;
322 } else if (units == end - 3) {
323 if (!strcasecmp(units, "khz")) {
324 freq *= 1000;
325 units_valid = 1;
326 } else if (!strcasecmp(units, "mhz")) {
327 freq *= 1000000;
328 units_valid = 1;
329 }
330 }
331
332 if (!units_valid) {
333 msg_perr("Invalid units: %s\n", units);
Edward O'Callaghan0037f452020-09-17 13:32:00 +1000334 free(tmp);
David Hendricks84377002014-09-09 16:09:31 -0700335 return 1;
336 }
337 }
338
339 /* Assume we only work with bytes and transfer at 1 bit/Hz */
Edward O'Callaghan0037f452020-09-17 13:32:00 +1000340 data->delay_us = (1000000 * 8) / freq;
David Hendricks84377002014-09-09 16:09:31 -0700341 }
Edward O'Callaghan0037f452020-09-17 13:32:00 +1000342 free(tmp);
David Hendricks84377002014-09-09 16:09:31 -0700343
hailfinger6ead7222010-11-01 22:07:04 +0000344#if EMULATE_CHIP
Louis Yung-Chieh Loe53fa0f2011-04-11 17:18:41 +0800345#if EMULATE_SPI_CHIP
346 tmp = extract_programmer_param("size");
347 if (tmp) {
Edward O'Callaghan602fbab2020-11-23 12:27:57 +1100348 size = strtol(tmp, NULL, 10);
349 if (size <= 0 || (size % 1024 != 0)) {
350 msg_perr("%s: Chip size is not a multipler of 1024: %s\n",
351 __func__, tmp);
352 free(tmp);
353 return 1;
Namyoon Wooc429efb2020-10-17 20:25:15 -0700354 }
Edward O'Callaghanec8b0d92020-09-17 17:27:45 +1000355 free(tmp);
Louis Yung-Chieh Loe53fa0f2011-04-11 17:18:41 +0800356 }
357#endif
358
hailfinger6ead7222010-11-01 22:07:04 +0000359 tmp = extract_programmer_param("emulate");
360 if (!tmp) {
361 msg_pdbg("Not emulating any flash chip.\n");
362 /* Nothing else to do. */
dhendrix0ffc2eb2011-06-14 01:35:36 +0000363 goto dummy_init_out;
hailfinger6ead7222010-11-01 22:07:04 +0000364 }
365#if EMULATE_SPI_CHIP
366 if (!strcmp(tmp, "M25P10.RES")) {
Lachlan Bishopbf1476e2020-09-10 14:57:05 +1000367 data->emu_chip = EMULATE_ST_M25P10_RES;
368 data->emu_chip_size = 128 * 1024;
369 data->emu_max_byteprogram_size = 128;
370 data->emu_max_aai_size = 0;
371 data->emu_jedec_se_size = 0;
372 data->emu_jedec_be_52_size = 0;
373 data->emu_jedec_be_d8_size = 32 * 1024;
374 data->emu_jedec_ce_60_size = 0;
375 data->emu_jedec_ce_c7_size = data->emu_chip_size;
hailfinger6ead7222010-11-01 22:07:04 +0000376 msg_pdbg("Emulating ST M25P10.RES SPI flash chip (RES, page "
377 "write)\n");
378 }
379 if (!strcmp(tmp, "SST25VF040.REMS")) {
Lachlan Bishopbf1476e2020-09-10 14:57:05 +1000380 data->emu_chip = EMULATE_SST_SST25VF040_REMS;
381 data->emu_chip_size = 512 * 1024;
382 data->emu_max_byteprogram_size = 1;
383 data->emu_max_aai_size = 0;
384 data->emu_jedec_se_size = 4 * 1024;
385 data->emu_jedec_be_52_size = 32 * 1024;
386 data->emu_jedec_be_d8_size = 0;
387 data->emu_jedec_ce_60_size = data->emu_chip_size;
388 data->emu_jedec_ce_c7_size = 0;
hailfinger6ead7222010-11-01 22:07:04 +0000389 msg_pdbg("Emulating SST SST25VF040.REMS SPI flash chip (REMS, "
390 "byte write)\n");
391 }
392 if (!strcmp(tmp, "SST25VF032B")) {
Lachlan Bishopbf1476e2020-09-10 14:57:05 +1000393 data->emu_chip = EMULATE_SST_SST25VF032B;
394 data->emu_chip_size = 4 * 1024 * 1024;
395 data->emu_max_byteprogram_size = 1;
396 data->emu_max_aai_size = 2;
397 data->emu_jedec_se_size = 4 * 1024;
398 data->emu_jedec_be_52_size = 32 * 1024;
399 data->emu_jedec_be_d8_size = 64 * 1024;
400 data->emu_jedec_ce_60_size = data->emu_chip_size;
401 data->emu_jedec_ce_c7_size = data->emu_chip_size;
hailfinger6ead7222010-11-01 22:07:04 +0000402 msg_pdbg("Emulating SST SST25VF032B SPI flash chip (RDID, AAI "
403 "write)\n");
404 }
Stuart Langley78cacf72020-04-23 11:48:01 +1000405 if (!strcmp(tmp, "MX25L6436")) {
Lachlan Bishopbf1476e2020-09-10 14:57:05 +1000406 data->emu_chip = EMULATE_MACRONIX_MX25L6436;
407 data->emu_chip_size = 8 * 1024 * 1024;
408 data->emu_max_byteprogram_size = 256;
409 data->emu_max_aai_size = 0;
410 data->emu_jedec_se_size = 4 * 1024;
411 data->emu_jedec_be_52_size = 32 * 1024;
412 data->emu_jedec_be_d8_size = 64 * 1024;
413 data->emu_jedec_ce_60_size = data->emu_chip_size;
414 data->emu_jedec_ce_c7_size = data->emu_chip_size;
Stuart Langley78cacf72020-04-23 11:48:01 +1000415 msg_pdbg("Emulating Macronix MX25L6436 SPI flash chip (RDID, "
416 "SFDP)\n");
417 }
Edward O'Callaghanec8b0d92020-09-17 17:27:45 +1000418 if (!strcmp(tmp, "W25Q128FV")) {
Lachlan Bishopbf1476e2020-09-10 14:57:05 +1000419 data->emu_chip = EMULATE_WINBOND_W25Q128FV;
420 data->emu_chip_size = 16 * 1024 * 1024;
421 data->emu_max_byteprogram_size = 256;
422 data->emu_max_aai_size = 0;
423 data->emu_jedec_se_size = 4 * 1024;
424 data->emu_jedec_be_52_size = 32 * 1024;
425 data->emu_jedec_be_d8_size = 64 * 1024;
426 data->emu_jedec_ce_60_size = data->emu_chip_size;
427 data->emu_jedec_ce_c7_size = data->emu_chip_size;
Edward O'Callaghanec8b0d92020-09-17 17:27:45 +1000428 msg_pdbg("Emulating Winbond W25Q128FV SPI flash chip (RDID)\n");
429 }
Simon Glassd2c64a22013-07-03 22:05:21 +0900430
Edward O'Callaghanec8b0d92020-09-17 17:27:45 +1000431 /* The name of variable-size virtual chip. A 4 MiB flash example:
432 * flashrom -p dummy:emulate=VARIABLE_SIZE,size=4194304
433 */
434 if (!strcmp(tmp, "VARIABLE_SIZE")) {
Edward O'Callaghan602fbab2020-11-23 12:27:57 +1100435 if (size == -1) {
Lachlan Bishopbf1476e2020-09-10 14:57:05 +1000436 msg_perr("%s: the size parameter is not given.\n", __func__);
Louis Yung-Chieh Loe53fa0f2011-04-11 17:18:41 +0800437 free(tmp);
438 return 1;
439 }
Lachlan Bishopbf1476e2020-09-10 14:57:05 +1000440 data->emu_chip = EMULATE_VARIABLE_SIZE;
441 data->emu_chip_size = size;
442 data->emu_max_byteprogram_size = 256;
443 data->emu_max_aai_size = 0;
444 data->emu_jedec_se_size = 4 * 1024;
445 data->emu_jedec_be_52_size = 32 * 1024;
446 data->emu_jedec_be_d8_size = 64 * 1024;
447 data->emu_jedec_ce_60_size = data->emu_chip_size;
448 data->emu_jedec_ce_c7_size = data->emu_chip_size;
Louis Yung-Chieh Loe53fa0f2011-04-11 17:18:41 +0800449 msg_pdbg("Emulating generic SPI flash chip (size=%d bytes)\n",
Lachlan Bishopbf1476e2020-09-10 14:57:05 +1000450 data->emu_chip_size);
Louis Yung-Chieh Loe53fa0f2011-04-11 17:18:41 +0800451 }
hailfinger6ead7222010-11-01 22:07:04 +0000452#endif
Lachlan Bishopbf1476e2020-09-10 14:57:05 +1000453 if (data->emu_chip == EMULATE_NONE) {
hailfinger6ead7222010-11-01 22:07:04 +0000454 msg_perr("Invalid chip specified for emulation: %s\n", tmp);
455 free(tmp);
456 return 1;
457 }
Edward O'Callaghan1b267722020-11-23 22:35:20 +1100458 free(tmp);
David Hendricks0eda2a82014-09-12 16:32:05 -0700459
460 /* Should emulated flash erase to zero (yes/no)? */
461 tmp = extract_programmer_param("erase_to_zero");
462 if (tmp) {
463 if (!strcmp(tmp, "yes")) {
464 msg_pdbg("Emulated chip will erase to 0x00\n");
Lachlan Bishopbf1476e2020-09-10 14:57:05 +1000465 data->erase_to_zero = 1;
David Hendricks0eda2a82014-09-12 16:32:05 -0700466 } else if (!strcmp(tmp, "no")) {
467 msg_pdbg("Emulated chip will erase to 0xff\n");
468 } else {
469 msg_perr("erase_to_zero can be \"yes\" or \"no\"\n");
Edward O'Callaghan1b267722020-11-23 22:35:20 +1100470 free(tmp);
David Hendricks0eda2a82014-09-12 16:32:05 -0700471 return 1;
472 }
473 }
hailfinger6ead7222010-11-01 22:07:04 +0000474 free(tmp);
Edward O'Callaghan1b267722020-11-23 22:35:20 +1100475
Lachlan Bishopbf1476e2020-09-10 14:57:05 +1000476 flashchip_contents = malloc(data->emu_chip_size);
hailfinger6ead7222010-11-01 22:07:04 +0000477 if (!flashchip_contents) {
478 msg_perr("Out of memory!\n");
479 return 1;
480 }
dhendrix0ffc2eb2011-06-14 01:35:36 +0000481
Edward O'Callaghanec8b0d92020-09-17 17:27:45 +1000482#ifdef EMULATE_SPI_CHIP
483 status = extract_programmer_param("spi_status");
484 if (status) {
485 char *endptr;
486 errno = 0;
Lachlan Bishopbf1476e2020-09-10 14:57:05 +1000487 data->emu_status = strtoul(status, &endptr, 0);
Edward O'Callaghanec8b0d92020-09-17 17:27:45 +1000488 free(status);
489 if (errno != 0 || status == endptr) {
490 msg_perr("Error: initial status register specified, "
491 "but the value could not be converted.\n");
492 return 1;
493 }
494 msg_pdbg("Initial status register is set to 0x%02x.\n",
Lachlan Bishopbf1476e2020-09-10 14:57:05 +1000495 data->emu_status);
Edward O'Callaghanec8b0d92020-09-17 17:27:45 +1000496 }
497#endif
498
Lachlan Bishopbf1476e2020-09-10 14:57:05 +1000499 msg_pdbg("Filling fake flash chip with 0x%02x, size %i\n",
500 data->erase_to_zero ? 0x00 : 0xff, data->emu_chip_size);
501 memset(flashchip_contents, data->erase_to_zero ? 0x00 : 0xff, data->emu_chip_size);
502
503 /* Will be freed by shutdown function if necessary. */
Edward O'Callaghan602fbab2020-11-23 12:27:57 +1100504 data->emu_persistent_image = extract_programmer_param("image");
Lachlan Bishopbf1476e2020-09-10 14:57:05 +1000505 if (!data->emu_persistent_image) {
hailfinger6ead7222010-11-01 22:07:04 +0000506 /* Nothing else to do. */
dhendrix0ffc2eb2011-06-14 01:35:36 +0000507 goto dummy_init_out;
hailfinger6ead7222010-11-01 22:07:04 +0000508 }
Edward O'Callaghanec8b0d92020-09-17 17:27:45 +1000509 /* We will silently (in default verbosity) ignore the file if it does not exist (yet) or the size does
510 * not match the emulated chip. */
Lachlan Bishopbf1476e2020-09-10 14:57:05 +1000511 if (!stat(data->emu_persistent_image, &image_stat)) {
Edward O'Callaghanec8b0d92020-09-17 17:27:45 +1000512 msg_pdbg("Found persistent image %s, %jd B ",
Lachlan Bishopbf1476e2020-09-10 14:57:05 +1000513 data->emu_persistent_image, (intmax_t)image_stat.st_size);
514 if ((uintmax_t)image_stat.st_size == data->emu_chip_size) {
hailfinger6ead7222010-11-01 22:07:04 +0000515 msg_pdbg("matches.\n");
Lachlan Bishopbf1476e2020-09-10 14:57:05 +1000516 msg_pdbg("Reading %s\n", data->emu_persistent_image);
517 if (read_buf_from_file(flashchip_contents, data->emu_chip_size,
518 data->emu_persistent_image)) {
519 msg_perr("Unable to read %s\n", data->emu_persistent_image);
Edward O'Callaghanec8b0d92020-09-17 17:27:45 +1000520 free(flashchip_contents);
521 return 1;
522 }
hailfinger6ead7222010-11-01 22:07:04 +0000523 } else {
524 msg_pdbg("doesn't match.\n");
525 }
526 }
527#endif
hailfingera9df33c2009-05-09 00:54:55 +0000528
dhendrix0ffc2eb2011-06-14 01:35:36 +0000529dummy_init_out:
Lachlan Bishopbf1476e2020-09-10 14:57:05 +1000530 if (register_shutdown(dummy_shutdown, data)) {
hailfinger6ead7222010-11-01 22:07:04 +0000531 free(flashchip_contents);
Lachlan Bishopbf1476e2020-09-10 14:57:05 +1000532 free(data);
dhendrix0ffc2eb2011-06-14 01:35:36 +0000533 return 1;
hailfinger6ead7222010-11-01 22:07:04 +0000534 }
hailfinger76bb7e92011-11-09 23:40:00 +0000535 if (dummy_buses_supported & (BUS_PARALLEL | BUS_LPC | BUS_FWH))
Patrick Georgi0a9533a2017-02-03 19:28:38 +0100536 register_par_master(&par_master_dummy,
Stuart langleyc98e43f2020-03-26 20:27:36 +1100537 dummy_buses_supported & (BUS_PARALLEL | BUS_LPC | BUS_FWH));
hailfinger76bb7e92011-11-09 23:40:00 +0000538 if (dummy_buses_supported & BUS_SPI)
Patrick Georgif4f1e2f2017-03-10 17:38:40 +0100539 register_spi_master(&spi_master_dummyflasher);
hailfinger76bb7e92011-11-09 23:40:00 +0000540
hailfingera9df33c2009-05-09 00:54:55 +0000541 return 0;
542}
543
Patrick Georgi4befc162017-02-03 18:32:01 +0100544void *dummy_map(const char *descr, uintptr_t phys_addr, size_t len)
hailfinger11ae3c42009-05-11 14:13:25 +0000545{
Stuart langleyc98e43f2020-03-26 20:27:36 +1100546 msg_pspew("%s: Mapping %s, 0x%zx bytes at 0x%0*" PRIxPTR "\n",
547 __func__, descr, len, PRIxPTR_WIDTH, phys_addr);
hailfinger11ae3c42009-05-11 14:13:25 +0000548 return (void *)phys_addr;
549}
550
551void dummy_unmap(void *virt_addr, size_t len)
552{
Stuart langleyc98e43f2020-03-26 20:27:36 +1100553 msg_pspew("%s: Unmapping 0x%zx bytes at %p\n", __func__, len, virt_addr);
hailfinger11ae3c42009-05-11 14:13:25 +0000554}
555
Stuart langleyc98e43f2020-03-26 20:27:36 +1100556static void dummy_chip_writeb(const struct flashctx *flash, uint8_t val, chipaddr addr)
hailfingera9df33c2009-05-09 00:54:55 +0000557{
Kangheui Won4974cc12019-10-18 12:59:01 +1100558 msg_pspew("%s: addr=0x%" PRIxPTR ", val=0x%02x\n", __func__, addr, val);
hailfingera9df33c2009-05-09 00:54:55 +0000559}
560
Stuart langleyc98e43f2020-03-26 20:27:36 +1100561static void dummy_chip_writew(const struct flashctx *flash, uint16_t val, chipaddr addr)
hailfingera9df33c2009-05-09 00:54:55 +0000562{
Kangheui Won4974cc12019-10-18 12:59:01 +1100563 msg_pspew("%s: addr=0x%" PRIxPTR ", val=0x%04x\n", __func__, addr, val);
hailfingera9df33c2009-05-09 00:54:55 +0000564}
565
Stuart langleyc98e43f2020-03-26 20:27:36 +1100566static void dummy_chip_writel(const struct flashctx *flash, uint32_t val, chipaddr addr)
hailfingera9df33c2009-05-09 00:54:55 +0000567{
Kangheui Won4974cc12019-10-18 12:59:01 +1100568 msg_pspew("%s: addr=0x%" PRIxPTR ", val=0x%08x\n", __func__, addr, val);
hailfingera9df33c2009-05-09 00:54:55 +0000569}
570
Stuart langleyc98e43f2020-03-26 20:27:36 +1100571static void dummy_chip_writen(const struct flashctx *flash, const uint8_t *buf, chipaddr addr, size_t len)
hailfinger9d987ef2009-06-05 18:32:07 +0000572{
573 size_t i;
Stuart langleyc98e43f2020-03-26 20:27:36 +1100574 msg_pspew("%s: addr=0x%" PRIxPTR ", len=0x%zx, writing data (hex):", __func__, addr, len);
hailfinger9d987ef2009-06-05 18:32:07 +0000575 for (i = 0; i < len; i++) {
576 if ((i % 16) == 0)
hailfinger50c335f2010-01-09 04:32:23 +0000577 msg_pspew("\n");
578 msg_pspew("%02x ", buf[i]);
hailfinger9d987ef2009-06-05 18:32:07 +0000579 }
580}
581
Stuart langleyc98e43f2020-03-26 20:27:36 +1100582static uint8_t dummy_chip_readb(const struct flashctx *flash, const chipaddr addr)
hailfingera9df33c2009-05-09 00:54:55 +0000583{
Kangheui Won4974cc12019-10-18 12:59:01 +1100584 msg_pspew("%s: addr=0x%" PRIxPTR ", returning 0xff\n", __func__, addr);
hailfingera9df33c2009-05-09 00:54:55 +0000585 return 0xff;
586}
587
Stuart langleyc98e43f2020-03-26 20:27:36 +1100588static uint16_t dummy_chip_readw(const struct flashctx *flash, const chipaddr addr)
hailfingera9df33c2009-05-09 00:54:55 +0000589{
Kangheui Won4974cc12019-10-18 12:59:01 +1100590 msg_pspew("%s: addr=0x%" PRIxPTR ", returning 0xffff\n", __func__, addr);
hailfingera9df33c2009-05-09 00:54:55 +0000591 return 0xffff;
592}
593
Stuart langleyc98e43f2020-03-26 20:27:36 +1100594static uint32_t dummy_chip_readl(const struct flashctx *flash, const chipaddr addr)
hailfingera9df33c2009-05-09 00:54:55 +0000595{
Kangheui Won4974cc12019-10-18 12:59:01 +1100596 msg_pspew("%s: addr=0x%" PRIxPTR ", returning 0xffffffff\n", __func__, addr);
hailfingera9df33c2009-05-09 00:54:55 +0000597 return 0xffffffff;
598}
599
Stuart langleyc98e43f2020-03-26 20:27:36 +1100600static void dummy_chip_readn(const struct flashctx *flash, uint8_t *buf, const chipaddr addr, size_t len)
hailfinger9d987ef2009-06-05 18:32:07 +0000601{
Stuart langleyc98e43f2020-03-26 20:27:36 +1100602 msg_pspew("%s: addr=0x%" PRIxPTR ", len=0x%zx, returning array of 0xff\n", __func__, addr, len);
hailfinger9d987ef2009-06-05 18:32:07 +0000603 memset(buf, 0xff, len);
604 return;
605}
606
hailfinger6ead7222010-11-01 22:07:04 +0000607#if EMULATE_SPI_CHIP
Edward O'Callaghanec8b0d92020-09-17 17:27:45 +1000608static int emulate_spi_chip_response(unsigned int writecnt,
609 unsigned int readcnt,
610 const unsigned char *writearr,
Lachlan Bishopbf1476e2020-09-10 14:57:05 +1000611 unsigned char *readarr,
612 struct emu_data *data)
hailfinger6ead7222010-11-01 22:07:04 +0000613{
Stuart Langley78cacf72020-04-23 11:48:01 +1000614 unsigned int offs, i, toread;
stefanctc5eb8a92011-11-23 09:13:48 +0000615 static int unsigned aai_offs;
Carl-Daniel Hailfinger7a4c0472012-08-30 21:41:00 +0000616 const unsigned char sst25vf040_rems_response[2] = {0xbf, 0x44};
617 const unsigned char sst25vf032b_rems_response[2] = {0xbf, 0x4a};
618 const unsigned char mx25l6436_rems_response[2] = {0xc2, 0x16};
Edward O'Callaghanec8b0d92020-09-17 17:27:45 +1000619 const unsigned char w25q128fv_rems_response[2] = {0xef, 0x17};
hailfinger6ead7222010-11-01 22:07:04 +0000620
621 if (writecnt == 0) {
622 msg_perr("No command sent to the chip!\n");
623 return 1;
624 }
Stefan Tauner718d1eb2016-08-18 18:00:53 -0700625 /* spi_blacklist has precedence over spi_ignorelist. */
Lachlan Bishopbf1476e2020-09-10 14:57:05 +1000626 for (i = 0; i < data->spi_blacklist_size; i++) {
627 if (writearr[0] == data->spi_blacklist[i]) {
Carl-Daniel Hailfingerc49783d2016-08-05 10:52:06 -0700628 msg_pdbg("Refusing blacklisted SPI command 0x%02x\n",
Lachlan Bishopbf1476e2020-09-10 14:57:05 +1000629 data->spi_blacklist[i]);
Carl-Daniel Hailfingerc49783d2016-08-05 10:52:06 -0700630 return SPI_INVALID_OPCODE;
631 }
632 }
Lachlan Bishopbf1476e2020-09-10 14:57:05 +1000633 for (i = 0; i < data->spi_ignorelist_size; i++) {
634 if (writearr[0] == data->spi_ignorelist[i]) {
Carl-Daniel Hailfingerc49783d2016-08-05 10:52:06 -0700635 msg_cdbg("Ignoring ignorelisted SPI command 0x%02x\n",
Lachlan Bishopbf1476e2020-09-10 14:57:05 +1000636 data->spi_ignorelist[i]);
Carl-Daniel Hailfingerc49783d2016-08-05 10:52:06 -0700637 /* Return success because the command does not fail,
638 * it is simply ignored.
639 */
640 return 0;
641 }
642 }
Edward O'Callaghanec8b0d92020-09-17 17:27:45 +1000643
Lachlan Bishopbf1476e2020-09-10 14:57:05 +1000644 if (data->emu_max_aai_size && (data->emu_status & SPI_SR_AAI)) {
Edward O'Callaghanec8b0d92020-09-17 17:27:45 +1000645 if (writearr[0] != JEDEC_AAI_WORD_PROGRAM &&
646 writearr[0] != JEDEC_WRDI &&
647 writearr[0] != JEDEC_RDSR) {
648 msg_perr("Forbidden opcode (0x%02x) attempted during "
649 "AAI sequence!\n", writearr[0]);
650 return 0;
651 }
652 }
653
hailfinger6ead7222010-11-01 22:07:04 +0000654 switch (writearr[0]) {
655 case JEDEC_RES:
Carl-Daniel Hailfinger7a4c0472012-08-30 21:41:00 +0000656 if (writecnt < JEDEC_RES_OUTSIZE)
hailfinger6ead7222010-11-01 22:07:04 +0000657 break;
Carl-Daniel Hailfinger7a4c0472012-08-30 21:41:00 +0000658 /* offs calculation is only needed for SST chips which treat RES like REMS. */
659 offs = writearr[1] << 16 | writearr[2] << 8 | writearr[3];
660 offs += writecnt - JEDEC_REMS_OUTSIZE;
Lachlan Bishopbf1476e2020-09-10 14:57:05 +1000661 switch (data->emu_chip) {
Carl-Daniel Hailfinger7a4c0472012-08-30 21:41:00 +0000662 case EMULATE_ST_M25P10_RES:
663 if (readcnt > 0)
664 memset(readarr, 0x10, readcnt);
665 break;
666 case EMULATE_SST_SST25VF040_REMS:
667 for (i = 0; i < readcnt; i++)
668 readarr[i] = sst25vf040_rems_response[(offs + i) % 2];
669 break;
670 case EMULATE_SST_SST25VF032B:
671 for (i = 0; i < readcnt; i++)
672 readarr[i] = sst25vf032b_rems_response[(offs + i) % 2];
673 break;
674 case EMULATE_MACRONIX_MX25L6436:
675 if (readcnt > 0)
676 memset(readarr, 0x16, readcnt);
677 break;
Edward O'Callaghanec8b0d92020-09-17 17:27:45 +1000678 case EMULATE_WINBOND_W25Q128FV:
679 if (readcnt > 0)
680 memset(readarr, 0x17, readcnt);
681 break;
Carl-Daniel Hailfinger7a4c0472012-08-30 21:41:00 +0000682 default: /* ignore */
683 break;
684 }
hailfinger6ead7222010-11-01 22:07:04 +0000685 break;
686 case JEDEC_REMS:
Carl-Daniel Hailfinger7a4c0472012-08-30 21:41:00 +0000687 /* REMS response has wraparound and uses an address parameter. */
688 if (writecnt < JEDEC_REMS_OUTSIZE)
hailfinger6ead7222010-11-01 22:07:04 +0000689 break;
Carl-Daniel Hailfinger7a4c0472012-08-30 21:41:00 +0000690 offs = writearr[1] << 16 | writearr[2] << 8 | writearr[3];
691 offs += writecnt - JEDEC_REMS_OUTSIZE;
Lachlan Bishopbf1476e2020-09-10 14:57:05 +1000692 switch (data->emu_chip) {
Carl-Daniel Hailfinger7a4c0472012-08-30 21:41:00 +0000693 case EMULATE_SST_SST25VF040_REMS:
694 for (i = 0; i < readcnt; i++)
695 readarr[i] = sst25vf040_rems_response[(offs + i) % 2];
696 break;
697 case EMULATE_SST_SST25VF032B:
698 for (i = 0; i < readcnt; i++)
699 readarr[i] = sst25vf032b_rems_response[(offs + i) % 2];
700 break;
701 case EMULATE_MACRONIX_MX25L6436:
702 for (i = 0; i < readcnt; i++)
703 readarr[i] = mx25l6436_rems_response[(offs + i) % 2];
704 break;
Edward O'Callaghanec8b0d92020-09-17 17:27:45 +1000705 case EMULATE_WINBOND_W25Q128FV:
706 for (i = 0; i < readcnt; i++)
707 readarr[i] = w25q128fv_rems_response[(offs + i) % 2];
708 break;
Carl-Daniel Hailfinger7a4c0472012-08-30 21:41:00 +0000709 default: /* ignore */
710 break;
711 }
hailfinger6ead7222010-11-01 22:07:04 +0000712 break;
713 case JEDEC_RDID:
Lachlan Bishopbf1476e2020-09-10 14:57:05 +1000714 switch (data->emu_chip) {
Stuart Langley78cacf72020-04-23 11:48:01 +1000715 case EMULATE_SST_SST25VF032B:
Louis Yung-Chieh Loe53fa0f2011-04-11 17:18:41 +0800716 if (readcnt > 0)
717 readarr[0] = 0xbf;
718 if (readcnt > 1)
719 readarr[1] = 0x25;
720 if (readcnt > 2)
721 readarr[2] = 0x4a;
Stuart Langley78cacf72020-04-23 11:48:01 +1000722 break;
723 case EMULATE_MACRONIX_MX25L6436:
724 if (readcnt > 0)
725 readarr[0] = 0xc2;
726 if (readcnt > 1)
727 readarr[1] = 0x20;
728 if (readcnt > 2)
729 readarr[2] = 0x17;
730 break;
Edward O'Callaghanec8b0d92020-09-17 17:27:45 +1000731 case EMULATE_WINBOND_W25Q128FV:
732 if (readcnt > 0)
733 readarr[0] = 0xef;
734 if (readcnt > 1)
735 readarr[1] = 0x40;
736 if (readcnt > 2)
737 readarr[2] = 0x18;
738 break;
Edward O'Callaghane0772312020-09-16 17:57:19 +1000739 case EMULATE_VARIABLE_SIZE:
740 if (readcnt > 0)
741 readarr[0] = (PROGMANUF_ID >> 8) & 0xff;
742 if (readcnt > 1)
743 readarr[1] = PROGMANUF_ID & 0xff;
744 if (readcnt > 2)
745 readarr[2] = (PROGDEV_ID >> 8) & 0xff;
746 if (readcnt > 3)
747 readarr[3] = PROGDEV_ID & 0xff;
Stuart Langley78cacf72020-04-23 11:48:01 +1000748 break;
Stuart Langley78cacf72020-04-23 11:48:01 +1000749 default: /* ignore */
750 break;
Louis Yung-Chieh Loe53fa0f2011-04-11 17:18:41 +0800751 }
hailfinger6ead7222010-11-01 22:07:04 +0000752 break;
753 case JEDEC_RDSR:
Lachlan Bishopbf1476e2020-09-10 14:57:05 +1000754 memset(readarr, data->emu_status, readcnt);
Edward O'Callaghanec8b0d92020-09-17 17:27:45 +1000755 break;
756 /* FIXME: this should be chip-specific. */
757 case JEDEC_EWSR:
758 case JEDEC_WREN:
Lachlan Bishopbf1476e2020-09-10 14:57:05 +1000759 data->emu_status |= SPI_SR_WEL;
Edward O'Callaghanec8b0d92020-09-17 17:27:45 +1000760 break;
761 case JEDEC_WRSR:
Lachlan Bishopbf1476e2020-09-10 14:57:05 +1000762 if (!(data->emu_status & SPI_SR_WEL)) {
Edward O'Callaghanec8b0d92020-09-17 17:27:45 +1000763 msg_perr("WRSR attempted, but WEL is 0!\n");
764 break;
765 }
766 /* FIXME: add some reasonable simulation of the busy flag */
Lachlan Bishopbf1476e2020-09-10 14:57:05 +1000767 data->emu_status = writearr[1] & ~SPI_SR_WIP;
768 msg_pdbg2("WRSR wrote 0x%02x.\n", data->emu_status);
hailfinger6ead7222010-11-01 22:07:04 +0000769 break;
770 case JEDEC_READ:
771 offs = writearr[1] << 16 | writearr[2] << 8 | writearr[3];
772 /* Truncate to emu_chip_size. */
Lachlan Bishopbf1476e2020-09-10 14:57:05 +1000773 offs %= data->emu_chip_size;
hailfinger6ead7222010-11-01 22:07:04 +0000774 if (readcnt > 0)
775 memcpy(readarr, flashchip_contents + offs, readcnt);
776 break;
Namyoon Woob71a2962020-08-27 16:27:49 -0700777 case JEDEC_READ_4BA:
778 offs = writearr[1] << 24 | writearr[2] << 16 | writearr[3] << 8 | writearr[4];
779 /* Truncate to emu_chip_size. */
Lachlan Bishopbf1476e2020-09-10 14:57:05 +1000780 offs %= data->emu_chip_size;
Namyoon Woob71a2962020-08-27 16:27:49 -0700781 if (readcnt > 0)
782 memcpy(readarr, flashchip_contents + offs, readcnt);
783 break;
hailfinger6ead7222010-11-01 22:07:04 +0000784 case JEDEC_BYTE_PROGRAM:
785 offs = writearr[1] << 16 | writearr[2] << 8 | writearr[3];
786 /* Truncate to emu_chip_size. */
Lachlan Bishopbf1476e2020-09-10 14:57:05 +1000787 offs %= data->emu_chip_size;
hailfinger6ead7222010-11-01 22:07:04 +0000788 if (writecnt < 5) {
789 msg_perr("BYTE PROGRAM size too short!\n");
790 return 1;
791 }
Lachlan Bishopbf1476e2020-09-10 14:57:05 +1000792 if (writecnt - 4 > data->emu_max_byteprogram_size) {
hailfinger6ead7222010-11-01 22:07:04 +0000793 msg_perr("Max BYTE PROGRAM size exceeded!\n");
794 return 1;
795 }
796 memcpy(flashchip_contents + offs, writearr + 4, writecnt - 4);
Lachlan Bishopbf1476e2020-09-10 14:57:05 +1000797 data->emu_modified = 1;
hailfinger6ead7222010-11-01 22:07:04 +0000798 break;
Namyoon Woob71a2962020-08-27 16:27:49 -0700799 case JEDEC_BYTE_PROGRAM_4BA:
800 offs = writearr[1] << 24 | writearr[2] << 16 | writearr[3] << 8 | writearr[4];
801 /* Truncate to emu_chip_size. */
Lachlan Bishopbf1476e2020-09-10 14:57:05 +1000802 offs %= data->emu_chip_size;
Namyoon Woob71a2962020-08-27 16:27:49 -0700803 if (writecnt < 6) {
804 msg_perr("BYTE PROGRAM size too short!\n");
805 return 1;
806 }
Lachlan Bishopbf1476e2020-09-10 14:57:05 +1000807 if (writecnt - 5 > data->emu_max_byteprogram_size) {
Namyoon Woob71a2962020-08-27 16:27:49 -0700808 msg_perr("Max BYTE PROGRAM size exceeded!\n");
809 return 1;
810 }
811 memcpy(flashchip_contents + offs, writearr + 5, writecnt - 5);
Lachlan Bishopbf1476e2020-09-10 14:57:05 +1000812 data->emu_modified = 1;
Namyoon Woob71a2962020-08-27 16:27:49 -0700813 break;
hailfinger6ead7222010-11-01 22:07:04 +0000814 case JEDEC_AAI_WORD_PROGRAM:
Lachlan Bishopbf1476e2020-09-10 14:57:05 +1000815 if (!data->emu_max_aai_size)
hailfinger6ead7222010-11-01 22:07:04 +0000816 break;
Lachlan Bishopbf1476e2020-09-10 14:57:05 +1000817 if (!(data->emu_status & SPI_SR_AAI)) {
hailfinger6ead7222010-11-01 22:07:04 +0000818 if (writecnt < JEDEC_AAI_WORD_PROGRAM_OUTSIZE) {
819 msg_perr("Initial AAI WORD PROGRAM size too "
820 "short!\n");
821 return 1;
822 }
823 if (writecnt > JEDEC_AAI_WORD_PROGRAM_OUTSIZE) {
824 msg_perr("Initial AAI WORD PROGRAM size too "
825 "long!\n");
826 return 1;
827 }
Lachlan Bishopbf1476e2020-09-10 14:57:05 +1000828 data->emu_status |= SPI_SR_AAI;
hailfinger6ead7222010-11-01 22:07:04 +0000829 aai_offs = writearr[1] << 16 | writearr[2] << 8 |
830 writearr[3];
831 /* Truncate to emu_chip_size. */
Lachlan Bishopbf1476e2020-09-10 14:57:05 +1000832 aai_offs %= data->emu_chip_size;
hailfinger6ead7222010-11-01 22:07:04 +0000833 memcpy(flashchip_contents + aai_offs, writearr + 4, 2);
834 aai_offs += 2;
835 } else {
836 if (writecnt < JEDEC_AAI_WORD_PROGRAM_CONT_OUTSIZE) {
837 msg_perr("Continuation AAI WORD PROGRAM size "
838 "too short!\n");
839 return 1;
840 }
841 if (writecnt > JEDEC_AAI_WORD_PROGRAM_CONT_OUTSIZE) {
842 msg_perr("Continuation AAI WORD PROGRAM size "
843 "too long!\n");
844 return 1;
845 }
846 memcpy(flashchip_contents + aai_offs, writearr + 1, 2);
847 aai_offs += 2;
848 }
Lachlan Bishopbf1476e2020-09-10 14:57:05 +1000849 data->emu_modified = 1;
hailfinger6ead7222010-11-01 22:07:04 +0000850 break;
851 case JEDEC_WRDI:
Lachlan Bishopbf1476e2020-09-10 14:57:05 +1000852 if (data->emu_max_aai_size)
853 data->emu_status &= ~SPI_SR_AAI;
hailfinger6ead7222010-11-01 22:07:04 +0000854 break;
855 case JEDEC_SE:
Lachlan Bishopbf1476e2020-09-10 14:57:05 +1000856 if (!data->emu_jedec_se_size)
hailfinger6ead7222010-11-01 22:07:04 +0000857 break;
858 if (writecnt != JEDEC_SE_OUTSIZE) {
859 msg_perr("SECTOR ERASE 0x20 outsize invalid!\n");
860 return 1;
861 }
862 if (readcnt != JEDEC_SE_INSIZE) {
863 msg_perr("SECTOR ERASE 0x20 insize invalid!\n");
864 return 1;
865 }
866 offs = writearr[1] << 16 | writearr[2] << 8 | writearr[3];
Lachlan Bishopbf1476e2020-09-10 14:57:05 +1000867 if (offs & (data->emu_jedec_se_size - 1))
hailfingere53f5e42011-02-04 22:52:04 +0000868 msg_pdbg("Unaligned SECTOR ERASE 0x20: 0x%x\n", offs);
Lachlan Bishopbf1476e2020-09-10 14:57:05 +1000869 offs &= ~(data->emu_jedec_se_size - 1);
870 memset(flashchip_contents + offs, 0xff, data->emu_jedec_se_size);
871 data->emu_modified = 1;
hailfinger6ead7222010-11-01 22:07:04 +0000872 break;
873 case JEDEC_BE_52:
Lachlan Bishopbf1476e2020-09-10 14:57:05 +1000874 if (!data->emu_jedec_be_52_size)
hailfinger6ead7222010-11-01 22:07:04 +0000875 break;
876 if (writecnt != JEDEC_BE_52_OUTSIZE) {
877 msg_perr("BLOCK ERASE 0x52 outsize invalid!\n");
878 return 1;
879 }
880 if (readcnt != JEDEC_BE_52_INSIZE) {
881 msg_perr("BLOCK ERASE 0x52 insize invalid!\n");
882 return 1;
883 }
884 offs = writearr[1] << 16 | writearr[2] << 8 | writearr[3];
Lachlan Bishopbf1476e2020-09-10 14:57:05 +1000885 if (offs & (data->emu_jedec_be_52_size - 1))
hailfingere53f5e42011-02-04 22:52:04 +0000886 msg_pdbg("Unaligned BLOCK ERASE 0x52: 0x%x\n", offs);
Lachlan Bishopbf1476e2020-09-10 14:57:05 +1000887 offs &= ~(data->emu_jedec_be_52_size - 1);
888 memset(flashchip_contents + offs, 0xff, data->emu_jedec_be_52_size);
889 data->emu_modified = 1;
hailfinger6ead7222010-11-01 22:07:04 +0000890 break;
891 case JEDEC_BE_D8:
Lachlan Bishopbf1476e2020-09-10 14:57:05 +1000892 if (!data->emu_jedec_be_d8_size)
hailfinger6ead7222010-11-01 22:07:04 +0000893 break;
894 if (writecnt != JEDEC_BE_D8_OUTSIZE) {
895 msg_perr("BLOCK ERASE 0xd8 outsize invalid!\n");
896 return 1;
897 }
898 if (readcnt != JEDEC_BE_D8_INSIZE) {
899 msg_perr("BLOCK ERASE 0xd8 insize invalid!\n");
900 return 1;
901 }
902 offs = writearr[1] << 16 | writearr[2] << 8 | writearr[3];
Lachlan Bishopbf1476e2020-09-10 14:57:05 +1000903 if (offs & (data->emu_jedec_be_d8_size - 1))
hailfingere53f5e42011-02-04 22:52:04 +0000904 msg_pdbg("Unaligned BLOCK ERASE 0xd8: 0x%x\n", offs);
Lachlan Bishopbf1476e2020-09-10 14:57:05 +1000905 offs &= ~(data->emu_jedec_be_d8_size - 1);
906 memset(flashchip_contents + offs, 0xff, data->emu_jedec_be_d8_size);
907 data->emu_modified = 1;
hailfinger6ead7222010-11-01 22:07:04 +0000908 break;
909 case JEDEC_CE_60:
Lachlan Bishopbf1476e2020-09-10 14:57:05 +1000910 if (!data->emu_jedec_ce_60_size)
hailfinger6ead7222010-11-01 22:07:04 +0000911 break;
912 if (writecnt != JEDEC_CE_60_OUTSIZE) {
913 msg_perr("CHIP ERASE 0x60 outsize invalid!\n");
914 return 1;
915 }
916 if (readcnt != JEDEC_CE_60_INSIZE) {
917 msg_perr("CHIP ERASE 0x60 insize invalid!\n");
918 return 1;
919 }
hailfingere53f5e42011-02-04 22:52:04 +0000920 /* JEDEC_CE_60_OUTSIZE is 1 (no address) -> no offset. */
hailfinger6ead7222010-11-01 22:07:04 +0000921 /* emu_jedec_ce_60_size is emu_chip_size. */
Lachlan Bishopbf1476e2020-09-10 14:57:05 +1000922 memset(flashchip_contents, 0xff, data->emu_jedec_ce_60_size);
923 data->emu_modified = 1;
hailfinger6ead7222010-11-01 22:07:04 +0000924 break;
925 case JEDEC_CE_C7:
Lachlan Bishopbf1476e2020-09-10 14:57:05 +1000926 if (!data->emu_jedec_ce_c7_size)
hailfinger6ead7222010-11-01 22:07:04 +0000927 break;
928 if (writecnt != JEDEC_CE_C7_OUTSIZE) {
929 msg_perr("CHIP ERASE 0xc7 outsize invalid!\n");
930 return 1;
931 }
932 if (readcnt != JEDEC_CE_C7_INSIZE) {
933 msg_perr("CHIP ERASE 0xc7 insize invalid!\n");
934 return 1;
935 }
hailfingere53f5e42011-02-04 22:52:04 +0000936 /* JEDEC_CE_C7_OUTSIZE is 1 (no address) -> no offset. */
hailfinger6ead7222010-11-01 22:07:04 +0000937 /* emu_jedec_ce_c7_size is emu_chip_size. */
Lachlan Bishopbf1476e2020-09-10 14:57:05 +1000938 memset(flashchip_contents, 0xff, data->emu_jedec_ce_c7_size);
939 data->emu_modified = 1;
hailfinger6ead7222010-11-01 22:07:04 +0000940 break;
Stuart Langley78cacf72020-04-23 11:48:01 +1000941 case JEDEC_SFDP:
Lachlan Bishopbf1476e2020-09-10 14:57:05 +1000942 if (data->emu_chip != EMULATE_MACRONIX_MX25L6436)
Stuart Langley78cacf72020-04-23 11:48:01 +1000943 break;
944 if (writecnt < 4)
945 break;
946 offs = writearr[1] << 16 | writearr[2] << 8 | writearr[3];
947
948 /* SFDP expects one dummy byte after the address. */
949 if (writecnt == 4) {
950 /* The dummy byte was not written, make sure it is read instead.
951 * Shifting and shortening the read array does achieve this goal.
952 */
953 readarr++;
954 readcnt--;
955 } else {
956 /* The response is shifted if more than 5 bytes are written, because SFDP data is
957 * already shifted out by the chip while those superfluous bytes are written. */
958 offs += writecnt - 5;
959 }
960
961 /* The SFDP spec implies that the start address of an SFDP read may be truncated to fit in the
962 * SFDP table address space, i.e. the start address may be wrapped around at SFDP table size.
963 * This is a reasonable implementation choice in hardware because it saves a few gates. */
964 if (offs >= sizeof(sfdp_table)) {
965 msg_pdbg("Wrapping the start address around the SFDP table boundary (using 0x%x "
966 "instead of 0x%x).\n", (unsigned int)(offs % sizeof(sfdp_table)), offs);
967 offs %= sizeof(sfdp_table);
968 }
969 toread = min(sizeof(sfdp_table) - offs, readcnt);
970 memcpy(readarr, sfdp_table + offs, toread);
971 if (toread < readcnt)
972 msg_pdbg("Crossing the SFDP table boundary in a single "
973 "continuous chunk produces undefined results "
974 "after that point.\n");
975 break;
hailfinger6ead7222010-11-01 22:07:04 +0000976 default:
977 /* No special response. */
978 break;
979 }
Edward O'Callaghanec8b0d92020-09-17 17:27:45 +1000980 if (writearr[0] != JEDEC_WREN && writearr[0] != JEDEC_EWSR)
Lachlan Bishopbf1476e2020-09-10 14:57:05 +1000981 data->emu_status &= ~SPI_SR_WEL;
hailfinger6ead7222010-11-01 22:07:04 +0000982 return 0;
983}
984#endif
985
Lachlan Bishopbf1476e2020-09-10 14:57:05 +1000986static struct emu_data* get_data_from_context(const struct flashctx *flash)
987{
988 if (dummy_buses_supported & (BUS_PARALLEL | BUS_LPC | BUS_FWH))
989 return (struct emu_data *)flash->mst->par.data;
990 else if (dummy_buses_supported & BUS_SPI)
991 return (struct emu_data *)flash->mst->spi.data;
992
993 return NULL; /* buses was set to BUS_NONE. */
994}
995
Stuart langleyc98e43f2020-03-26 20:27:36 +1100996static int dummy_spi_send_command(const struct flashctx *flash, unsigned int writecnt,
997 unsigned int readcnt,
998 const unsigned char *writearr,
999 unsigned char *readarr)
hailfingerf91e3b52009-05-14 12:59:36 +00001000{
Edward O'Callaghanec8b0d92020-09-17 17:27:45 +10001001 unsigned int i;
Lachlan Bishopbf1476e2020-09-10 14:57:05 +10001002 struct emu_data *emu_data = get_data_from_context(flash);
1003 if (!emu_data) {
1004 msg_perr("No data in flash context!\n");
1005 return 1;
1006 }
hailfingerf91e3b52009-05-14 12:59:36 +00001007
hailfinger50c335f2010-01-09 04:32:23 +00001008 msg_pspew("%s:", __func__);
hailfingerf91e3b52009-05-14 12:59:36 +00001009
hailfinger50c335f2010-01-09 04:32:23 +00001010 msg_pspew(" writing %u bytes:", writecnt);
hailfingerf91e3b52009-05-14 12:59:36 +00001011 for (i = 0; i < writecnt; i++)
hailfinger50c335f2010-01-09 04:32:23 +00001012 msg_pspew(" 0x%02x", writearr[i]);
hailfingerf91e3b52009-05-14 12:59:36 +00001013
hailfinger6ead7222010-11-01 22:07:04 +00001014 /* Response for unknown commands and missing chip is 0xff. */
1015 memset(readarr, 0xff, readcnt);
1016#if EMULATE_SPI_CHIP
Lachlan Bishopbf1476e2020-09-10 14:57:05 +10001017 switch (emu_data->emu_chip) {
hailfinger6ead7222010-11-01 22:07:04 +00001018 case EMULATE_ST_M25P10_RES:
1019 case EMULATE_SST_SST25VF040_REMS:
1020 case EMULATE_SST_SST25VF032B:
Stuart Langley78cacf72020-04-23 11:48:01 +10001021 case EMULATE_MACRONIX_MX25L6436:
Edward O'Callaghanec8b0d92020-09-17 17:27:45 +10001022 case EMULATE_WINBOND_W25Q128FV:
Louis Yung-Chieh Loe53fa0f2011-04-11 17:18:41 +08001023 case EMULATE_VARIABLE_SIZE:
Edward O'Callaghanec8b0d92020-09-17 17:27:45 +10001024 if (emulate_spi_chip_response(writecnt, readcnt, writearr,
Lachlan Bishopbf1476e2020-09-10 14:57:05 +10001025 readarr, emu_data)) {
Carl-Daniel Hailfingerc49783d2016-08-05 10:52:06 -07001026 msg_pdbg("Invalid command sent to flash chip!\n");
hailfinger6ead7222010-11-01 22:07:04 +00001027 return 1;
1028 }
1029 break;
1030 default:
1031 break;
1032 }
1033#endif
hailfinger50c335f2010-01-09 04:32:23 +00001034 msg_pspew(" reading %u bytes:", readcnt);
uwe8d342eb2011-07-28 08:13:25 +00001035 for (i = 0; i < readcnt; i++)
hailfinger6ead7222010-11-01 22:07:04 +00001036 msg_pspew(" 0x%02x", readarr[i]);
hailfinger50c335f2010-01-09 04:32:23 +00001037 msg_pspew("\n");
David Hendricks84377002014-09-09 16:09:31 -07001038
Edward O'Callaghan0037f452020-09-17 13:32:00 +10001039 programmer_delay((writecnt + readcnt) * emu_data->delay_us);
hailfingerf91e3b52009-05-14 12:59:36 +00001040 return 0;
1041}
hailfingera8727712010-06-20 10:58:32 +00001042
Stuart langleyc98e43f2020-03-26 20:27:36 +11001043static int dummy_spi_write_256(struct flashctx *flash, const uint8_t *buf, unsigned int start, unsigned int len)
hailfingerc7d06c62010-07-14 16:19:05 +00001044{
hailfinger6ead7222010-11-01 22:07:04 +00001045 return spi_write_chunked(flash, buf, start, len,
1046 spi_write_256_chunksize);
hailfingerc7d06c62010-07-14 16:19:05 +00001047}
Louis Yung-Chieh Loe53fa0f2011-04-11 17:18:41 +08001048
1049#if EMULATE_CHIP && EMULATE_SPI_CHIP
Souvik Ghoshd75cd672016-06-17 14:21:39 -07001050int probe_variable_size(struct flashctx *flash)
Louis Yung-Chieh Loe53fa0f2011-04-11 17:18:41 +08001051{
Edward O'Callaghanec8b0d92020-09-17 17:27:45 +10001052 unsigned int i;
Lachlan Bishopbf1476e2020-09-10 14:57:05 +10001053 const struct emu_data *emu_data = get_data_from_context(flash);
Louis Yung-Chieh Loe53fa0f2011-04-11 17:18:41 +08001054
1055 /* Skip the probing if we don't emulate this chip. */
Angel Pons7971a732020-10-17 15:20:27 +02001056 if (!emu_data || emu_data->emu_chip != EMULATE_VARIABLE_SIZE)
Louis Yung-Chieh Loe53fa0f2011-04-11 17:18:41 +08001057 return 0;
1058
1059 /*
Souvik Ghoshd75cd672016-06-17 14:21:39 -07001060 * This will break if one day flashctx becomes read-only.
Louis Yung-Chieh Loe53fa0f2011-04-11 17:18:41 +08001061 * Once that happens, we need to have special hacks in functions:
1062 *
1063 * erase_and_write_flash() in flashrom.c
1064 * read_flash_to_file()
1065 * handle_romentries()
1066 * ...
1067 *
1068 * Search "total_size * 1024" in code.
1069 */
Lachlan Bishopbf1476e2020-09-10 14:57:05 +10001070 flash->chip->total_size = emu_data->emu_chip_size / 1024;
Louis Yung-Chieh Loe53fa0f2011-04-11 17:18:41 +08001071 msg_cdbg("%s: set flash->total_size to %dK bytes.\n", __func__,
Patrick Georgif3fa2992017-02-02 16:24:44 +01001072 flash->chip->total_size);
Louis Yung-Chieh Loe53fa0f2011-04-11 17:18:41 +08001073
Lachlan Bishopbf1476e2020-09-10 14:57:05 +10001074 if (emu_data->erase_to_zero)
Alan Greendbeec2b2019-09-16 14:36:52 +10001075 flash->chip->feature_bits |= FEATURE_ERASED_ZERO;
David Hendricks0eda2a82014-09-12 16:32:05 -07001076
Edward O'Callaghanec8b0d92020-09-17 17:27:45 +10001077 /* Update the first count of each of the block_erasers. */
Louis Yung-Chieh Loe53fa0f2011-04-11 17:18:41 +08001078 for (i = 0; i < NUM_ERASEFUNCTIONS; i++) {
Patrick Georgif3fa2992017-02-02 16:24:44 +01001079 struct block_eraser *eraser = &flash->chip->block_erasers[i];
Edward O'Callaghanec8b0d92020-09-17 17:27:45 +10001080 if (!eraser->block_erase)
Louis Yung-Chieh Loe53fa0f2011-04-11 17:18:41 +08001081 break;
1082
Namyoon Woob71a2962020-08-27 16:27:49 -07001083 eraser->eraseblocks[0].count = 1;
Lachlan Bishopbf1476e2020-09-10 14:57:05 +10001084 eraser->eraseblocks[0].size = emu_data->emu_chip_size;
Louis Yung-Chieh Loe53fa0f2011-04-11 17:18:41 +08001085 msg_cdbg("%s: eraser.size=%d, .count=%d\n",
1086 __func__, eraser->eraseblocks[0].size,
1087 eraser->eraseblocks[0].count);
1088 }
1089
1090 return 1;
1091}
1092#endif