blob: 732cbc02a58299036d1b604bd80fb0008047eb5e [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;
58 unsigned int emu_max_byteprogram_size;
59 unsigned int emu_max_aai_size;
60 unsigned int emu_jedec_se_size;
61 unsigned int emu_jedec_be_52_size;
62 unsigned int emu_jedec_be_d8_size;
63 unsigned int emu_jedec_ce_60_size;
64 unsigned int emu_jedec_ce_c7_size;
65 unsigned char spi_blacklist[256];
66 unsigned char spi_ignorelist[256];
67 unsigned int spi_blacklist_size;
68 unsigned int spi_ignorelist_size;
69};
70
71#if EMULATE_SPI_CHIP
Stuart Langley78cacf72020-04-23 11:48:01 +100072/* A legit complete SFDP table based on the MX25L6436E (rev. 1.8) datasheet. */
73static const uint8_t sfdp_table[] = {
74 0x53, 0x46, 0x44, 0x50, // @0x00: SFDP signature
75 0x00, 0x01, 0x01, 0xFF, // @0x04: revision 1.0, 2 headers
76 0x00, 0x00, 0x01, 0x09, // @0x08: JEDEC SFDP header rev. 1.0, 9 DW long
77 0x1C, 0x00, 0x00, 0xFF, // @0x0C: PTP0 = 0x1C (instead of 0x30)
78 0xC2, 0x00, 0x01, 0x04, // @0x10: Macronix header rev. 1.0, 4 DW long
79 0x48, 0x00, 0x00, 0xFF, // @0x14: PTP1 = 0x48 (instead of 0x60)
80 0xFF, 0xFF, 0xFF, 0xFF, // @0x18: hole.
81 0xE5, 0x20, 0xC9, 0xFF, // @0x1C: SFDP parameter table start
82 0xFF, 0xFF, 0xFF, 0x03, // @0x20
83 0x00, 0xFF, 0x08, 0x6B, // @0x24
84 0x08, 0x3B, 0x00, 0xFF, // @0x28
85 0xEE, 0xFF, 0xFF, 0xFF, // @0x2C
86 0xFF, 0xFF, 0x00, 0x00, // @0x30
87 0xFF, 0xFF, 0x00, 0xFF, // @0x34
88 0x0C, 0x20, 0x0F, 0x52, // @0x38
89 0x10, 0xD8, 0x00, 0xFF, // @0x3C: SFDP parameter table end
90 0xFF, 0xFF, 0xFF, 0xFF, // @0x40: hole.
91 0xFF, 0xFF, 0xFF, 0xFF, // @0x44: hole.
92 0x00, 0x36, 0x00, 0x27, // @0x48: Macronix parameter table start
93 0xF4, 0x4F, 0xFF, 0xFF, // @0x4C
94 0xD9, 0xC8, 0xFF, 0xFF, // @0x50
95 0xFF, 0xFF, 0xFF, 0xFF, // @0x54: Macronix parameter table end
96};
97
hailfinger6ead7222010-11-01 22:07:04 +000098#endif
99#endif
100
stefanctc5eb8a92011-11-23 09:13:48 +0000101static unsigned int spi_write_256_chunksize = 256;
hailfinger6ead7222010-11-01 22:07:04 +0000102
David Hendricks84377002014-09-09 16:09:31 -0700103/* If "freq" parameter is passed in from command line, commands will delay
104 * for this period before returning. */
105static unsigned long int delay_us = 0;
106
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700107static int dummy_spi_send_command(const struct flashctx *flash, unsigned int writecnt, unsigned int readcnt,
Stuart langleyc98e43f2020-03-26 20:27:36 +1100108 const unsigned char *writearr, unsigned char *readarr);
Patrick Georgiab8353e2017-02-03 18:32:01 +0100109static int dummy_spi_write_256(struct flashctx *flash, const uint8_t *buf,
stefanctc5eb8a92011-11-23 09:13:48 +0000110 unsigned int start, unsigned int len);
Stuart langleyc98e43f2020-03-26 20:27:36 +1100111static void dummy_chip_writeb(const struct flashctx *flash, uint8_t val, chipaddr addr);
112static void dummy_chip_writew(const struct flashctx *flash, uint16_t val, chipaddr addr);
113static void dummy_chip_writel(const struct flashctx *flash, uint32_t val, chipaddr addr);
114static void dummy_chip_writen(const struct flashctx *flash, const uint8_t *buf, chipaddr addr, size_t len);
115static uint8_t dummy_chip_readb(const struct flashctx *flash, const chipaddr addr);
116static uint16_t dummy_chip_readw(const struct flashctx *flash, const chipaddr addr);
117static uint32_t dummy_chip_readl(const struct flashctx *flash, const chipaddr addr);
118static void dummy_chip_readn(const struct flashctx *flash, uint8_t *buf, const chipaddr addr, size_t len);
mkarcherd264e9e2011-05-11 17:07:07 +0000119
Lachlan Bishopbf1476e2020-09-10 14:57:05 +1000120static struct spi_master spi_master_dummyflasher = {
Edward O'Callaghana6673bd2019-06-24 15:22:28 +1000121 .features = SPI_MASTER_4BA,
uwe8d342eb2011-07-28 08:13:25 +0000122 .max_data_read = MAX_DATA_READ_UNLIMITED,
123 .max_data_write = MAX_DATA_UNSPECIFIED,
124 .command = dummy_spi_send_command,
125 .multicommand = default_spi_send_multicommand,
126 .read = default_spi_read,
127 .write_256 = dummy_spi_write_256,
Edward O'Callaghaneeaac6b2020-10-12 19:51:56 +1100128 .write_aai = default_spi_write_aai,
mkarcherd264e9e2011-05-11 17:07:07 +0000129};
dhendrix0ffc2eb2011-06-14 01:35:36 +0000130
Patrick Georgi0a9533a2017-02-03 19:28:38 +0100131static const struct par_master par_master_dummy = {
hailfinger76bb7e92011-11-09 23:40:00 +0000132 .chip_readb = dummy_chip_readb,
133 .chip_readw = dummy_chip_readw,
134 .chip_readl = dummy_chip_readl,
135 .chip_readn = dummy_chip_readn,
136 .chip_writeb = dummy_chip_writeb,
137 .chip_writew = dummy_chip_writew,
138 .chip_writel = dummy_chip_writel,
139 .chip_writen = dummy_chip_writen,
140};
141
Edward O'Callaghanef4e28b2019-06-28 13:18:41 +1000142static enum chipbustype dummy_buses_supported = BUS_NONE;
hailfinger76bb7e92011-11-09 23:40:00 +0000143
David Hendricks93784b42016-08-09 17:00:38 -0700144static int dummy_shutdown(void *data)
dhendrix0ffc2eb2011-06-14 01:35:36 +0000145{
146 msg_pspew("%s\n", __func__);
147#if EMULATE_CHIP
Lachlan Bishopbf1476e2020-09-10 14:57:05 +1000148 struct emu_data *emu_data = (struct emu_data *)data;
149 if (emu_data->emu_chip != EMULATE_NONE) {
150 if (emu_data->emu_persistent_image && emu_data->emu_modified) {
151 msg_pdbg("Writing %s\n", emu_data->emu_persistent_image);
152 write_buf_to_file(flashchip_contents,
153 emu_data->emu_chip_size,
154 emu_data->emu_persistent_image);
155 free(emu_data->emu_persistent_image);
156 emu_data->emu_persistent_image = NULL;
dhendrix0ffc2eb2011-06-14 01:35:36 +0000157 }
158 free(flashchip_contents);
159 }
160#endif
161 return 0;
162}
163
Simon Glassd2c64a22013-07-03 22:05:21 +0900164/* Values for the 'size' parameter */
165enum {
166 SIZE_UNKNOWN = -1,
167 SIZE_AUTO = -2,
168};
169
David Hendricksac1d25c2016-08-09 17:00:58 -0700170int dummy_init(void)
hailfingera9df33c2009-05-09 00:54:55 +0000171{
hailfinger1ef766d2010-07-06 09:55:48 +0000172 char *bustext = NULL;
hailfinger6ead7222010-11-01 22:07:04 +0000173 char *tmp = NULL;
Edward O'Callaghanec8b0d92020-09-17 17:27:45 +1000174 unsigned int i;
Louis Yung-Chieh Loe53fa0f2011-04-11 17:18:41 +0800175#if EMULATE_SPI_CHIP
Edward O'Callaghanec8b0d92020-09-17 17:27:45 +1000176 char *status = NULL;
Simon Glassd2c64a22013-07-03 22:05:21 +0900177 int size = SIZE_UNKNOWN; /* size for generic chip */
Louis Yung-Chieh Loe53fa0f2011-04-11 17:18:41 +0800178#endif
Edward O'Callaghanec8b0d92020-09-17 17:27:45 +1000179#if EMULATE_CHIP
180 struct stat image_stat;
hailfinger6ead7222010-11-01 22:07:04 +0000181#endif
Simon Glassd2c64a22013-07-03 22:05:21 +0900182 int image_size = SIZE_UNKNOWN;
hailfinger1ef766d2010-07-06 09:55:48 +0000183
Lachlan Bishopbf1476e2020-09-10 14:57:05 +1000184 struct emu_data *data = calloc(1, sizeof(struct emu_data));
185 if (!data) {
186 msg_perr("Out of memory!\n");
187 return 1;
188 }
189 data->emu_chip = EMULATE_NONE;
190 spi_master_dummyflasher.data = data;
191
hailfinger50c335f2010-01-09 04:32:23 +0000192 msg_pspew("%s\n", __func__);
hailfinger668f3502009-06-01 00:02:11 +0000193
hailfingerddeb4ac2010-07-08 10:13:37 +0000194 bustext = extract_programmer_param("bus");
hailfinger1ef766d2010-07-06 09:55:48 +0000195 msg_pdbg("Requested buses are: %s\n", bustext ? bustext : "default");
196 if (!bustext)
197 bustext = strdup("parallel+lpc+fwh+spi");
hailfinger668f3502009-06-01 00:02:11 +0000198 /* Convert the parameters to lowercase. */
hailfinger1ef766d2010-07-06 09:55:48 +0000199 tolower_string(bustext);
hailfinger668f3502009-06-01 00:02:11 +0000200
hailfinger76bb7e92011-11-09 23:40:00 +0000201 dummy_buses_supported = BUS_NONE;
hailfinger1ef766d2010-07-06 09:55:48 +0000202 if (strstr(bustext, "parallel")) {
hailfinger76bb7e92011-11-09 23:40:00 +0000203 dummy_buses_supported |= BUS_PARALLEL;
hailfinger50c335f2010-01-09 04:32:23 +0000204 msg_pdbg("Enabling support for %s flash.\n", "parallel");
hailfinger668f3502009-06-01 00:02:11 +0000205 }
hailfinger1ef766d2010-07-06 09:55:48 +0000206 if (strstr(bustext, "lpc")) {
hailfinger76bb7e92011-11-09 23:40:00 +0000207 dummy_buses_supported |= BUS_LPC;
hailfinger50c335f2010-01-09 04:32:23 +0000208 msg_pdbg("Enabling support for %s flash.\n", "LPC");
hailfinger668f3502009-06-01 00:02:11 +0000209 }
hailfinger1ef766d2010-07-06 09:55:48 +0000210 if (strstr(bustext, "fwh")) {
hailfinger76bb7e92011-11-09 23:40:00 +0000211 dummy_buses_supported |= BUS_FWH;
hailfinger50c335f2010-01-09 04:32:23 +0000212 msg_pdbg("Enabling support for %s flash.\n", "FWH");
hailfinger668f3502009-06-01 00:02:11 +0000213 }
hailfinger1ef766d2010-07-06 09:55:48 +0000214 if (strstr(bustext, "spi")) {
hailfinger76bb7e92011-11-09 23:40:00 +0000215 dummy_buses_supported |= BUS_SPI;
hailfinger50c335f2010-01-09 04:32:23 +0000216 msg_pdbg("Enabling support for %s flash.\n", "SPI");
hailfinger668f3502009-06-01 00:02:11 +0000217 }
hailfinger76bb7e92011-11-09 23:40:00 +0000218 if (dummy_buses_supported == BUS_NONE)
hailfinger50c335f2010-01-09 04:32:23 +0000219 msg_pdbg("Support for all flash bus types disabled.\n");
hailfinger1ef766d2010-07-06 09:55:48 +0000220 free(bustext);
hailfinger6ead7222010-11-01 22:07:04 +0000221
222 tmp = extract_programmer_param("spi_write_256_chunksize");
223 if (tmp) {
224 spi_write_256_chunksize = atoi(tmp);
225 free(tmp);
226 if (spi_write_256_chunksize < 1) {
227 msg_perr("invalid spi_write_256_chunksize\n");
228 return 1;
229 }
230 }
231
Carl-Daniel Hailfingerc49783d2016-08-05 10:52:06 -0700232 tmp = extract_programmer_param("spi_blacklist");
233 if (tmp) {
234 i = strlen(tmp);
235 if (!strncmp(tmp, "0x", 2)) {
236 i -= 2;
237 memmove(tmp, tmp + 2, i + 1);
238 }
239 if ((i > 512) || (i % 2)) {
240 msg_perr("Invalid SPI command blacklist length\n");
241 free(tmp);
242 return 1;
243 }
Lachlan Bishopbf1476e2020-09-10 14:57:05 +1000244 data->spi_blacklist_size = i / 2;
245 for (i = 0; i < data->spi_blacklist_size * 2; i++) {
Carl-Daniel Hailfingerc49783d2016-08-05 10:52:06 -0700246 if (!isxdigit((unsigned char)tmp[i])) {
247 msg_perr("Invalid char \"%c\" in SPI command "
248 "blacklist\n", tmp[i]);
249 free(tmp);
250 return 1;
251 }
252 }
Lachlan Bishopbf1476e2020-09-10 14:57:05 +1000253 for (i = 0; i < data->spi_blacklist_size; i++) {
Carl-Daniel Hailfingerc49783d2016-08-05 10:52:06 -0700254 unsigned int tmp2;
255 /* SCNx8 is apparently not supported by MSVC (and thus
256 * MinGW), so work around it with an extra variable
257 */
258 sscanf(tmp + i * 2, "%2x", &tmp2);
Lachlan Bishopbf1476e2020-09-10 14:57:05 +1000259 data->spi_blacklist[i] = (uint8_t)tmp2;
Carl-Daniel Hailfingerc49783d2016-08-05 10:52:06 -0700260 }
261 msg_pdbg("SPI blacklist is ");
Lachlan Bishopbf1476e2020-09-10 14:57:05 +1000262 for (i = 0; i < data->spi_blacklist_size; i++)
263 msg_pdbg("%02x ", data->spi_blacklist[i]);
264 msg_pdbg(", size %u\n", data->spi_blacklist_size);
Carl-Daniel Hailfingerc49783d2016-08-05 10:52:06 -0700265 }
266 free(tmp);
267
268 tmp = extract_programmer_param("spi_ignorelist");
269 if (tmp) {
270 i = strlen(tmp);
271 if (!strncmp(tmp, "0x", 2)) {
272 i -= 2;
273 memmove(tmp, tmp + 2, i + 1);
274 }
275 if ((i > 512) || (i % 2)) {
276 msg_perr("Invalid SPI command ignorelist length\n");
277 free(tmp);
278 return 1;
279 }
Lachlan Bishopbf1476e2020-09-10 14:57:05 +1000280 data->spi_ignorelist_size = i / 2;
281 for (i = 0; i < data->spi_ignorelist_size * 2; i++) {
Carl-Daniel Hailfingerc49783d2016-08-05 10:52:06 -0700282 if (!isxdigit((unsigned char)tmp[i])) {
283 msg_perr("Invalid char \"%c\" in SPI command "
284 "ignorelist\n", tmp[i]);
285 free(tmp);
286 return 1;
287 }
288 }
Lachlan Bishopbf1476e2020-09-10 14:57:05 +1000289 for (i = 0; i < data->spi_ignorelist_size; i++) {
Carl-Daniel Hailfingerc49783d2016-08-05 10:52:06 -0700290 unsigned int tmp2;
291 /* SCNx8 is apparently not supported by MSVC (and thus
292 * MinGW), so work around it with an extra variable
293 */
294 sscanf(tmp + i * 2, "%2x", &tmp2);
Lachlan Bishopbf1476e2020-09-10 14:57:05 +1000295 data->spi_ignorelist[i] = (uint8_t)tmp2;
Carl-Daniel Hailfingerc49783d2016-08-05 10:52:06 -0700296 }
297 msg_pdbg("SPI ignorelist is ");
Lachlan Bishopbf1476e2020-09-10 14:57:05 +1000298 for (i = 0; i < data->spi_ignorelist_size; i++)
299 msg_pdbg("%02x ", data->spi_ignorelist[i]);
300 msg_pdbg(", size %u\n", data->spi_ignorelist_size);
Carl-Daniel Hailfingerc49783d2016-08-05 10:52:06 -0700301 }
302 free(tmp);
303
David Hendricks84377002014-09-09 16:09:31 -0700304 /* frequency to emulate in Hz (default), KHz, or MHz */
305 tmp = extract_programmer_param("freq");
306 if (tmp) {
307 unsigned long int freq;
308 char *units = tmp;
309 char *end = tmp + strlen(tmp);
310
311 errno = 0;
312 freq = strtoul(tmp, &units, 0);
313 if (errno) {
314 msg_perr("Invalid frequency \"%s\", %s\n",
315 tmp, strerror(errno));
316 goto dummy_init_out;
317 }
318
319 if ((units > tmp) && (units < end)) {
320 int units_valid = 0;
321
322 if (units < end - 3) {
323 ;
324 } else if (units == end - 2) {
325 if (!strcasecmp(units, "hz"))
326 units_valid = 1;
327 } else if (units == end - 3) {
328 if (!strcasecmp(units, "khz")) {
329 freq *= 1000;
330 units_valid = 1;
331 } else if (!strcasecmp(units, "mhz")) {
332 freq *= 1000000;
333 units_valid = 1;
334 }
335 }
336
337 if (!units_valid) {
338 msg_perr("Invalid units: %s\n", units);
339 return 1;
340 }
341 }
342
343 /* Assume we only work with bytes and transfer at 1 bit/Hz */
344 delay_us = (1000000 * 8) / freq;
345 }
346
hailfinger6ead7222010-11-01 22:07:04 +0000347#if EMULATE_CHIP
Louis Yung-Chieh Loe53fa0f2011-04-11 17:18:41 +0800348#if EMULATE_SPI_CHIP
349 tmp = extract_programmer_param("size");
350 if (tmp) {
351 int multiplier = 1;
Simon Glassd2c64a22013-07-03 22:05:21 +0900352 if (!strcmp(tmp, "auto"))
353 size = SIZE_AUTO;
354 else if (strlen(tmp)) {
Louis Yung-Chieh Loe53fa0f2011-04-11 17:18:41 +0800355 int remove_last_char = 1;
356 switch (tmp[strlen(tmp) - 1]) {
357 case 'k': case 'K':
358 multiplier = 1024;
359 break;
360 case 'm': case 'M':
361 multiplier = 1024 * 1024;
362 break;
363 default:
364 remove_last_char = 0;
365 break;
366 }
367 if (remove_last_char) tmp[strlen(tmp) - 1] = '\0';
Simon Glassd2c64a22013-07-03 22:05:21 +0900368 size = atoi(tmp) * multiplier;
Louis Yung-Chieh Loe53fa0f2011-04-11 17:18:41 +0800369 }
Edward O'Callaghanec8b0d92020-09-17 17:27:45 +1000370 free(tmp);
Louis Yung-Chieh Loe53fa0f2011-04-11 17:18:41 +0800371 }
372#endif
373
hailfinger6ead7222010-11-01 22:07:04 +0000374 tmp = extract_programmer_param("emulate");
375 if (!tmp) {
376 msg_pdbg("Not emulating any flash chip.\n");
377 /* Nothing else to do. */
dhendrix0ffc2eb2011-06-14 01:35:36 +0000378 goto dummy_init_out;
hailfinger6ead7222010-11-01 22:07:04 +0000379 }
380#if EMULATE_SPI_CHIP
381 if (!strcmp(tmp, "M25P10.RES")) {
Lachlan Bishopbf1476e2020-09-10 14:57:05 +1000382 data->emu_chip = EMULATE_ST_M25P10_RES;
383 data->emu_chip_size = 128 * 1024;
384 data->emu_max_byteprogram_size = 128;
385 data->emu_max_aai_size = 0;
386 data->emu_jedec_se_size = 0;
387 data->emu_jedec_be_52_size = 0;
388 data->emu_jedec_be_d8_size = 32 * 1024;
389 data->emu_jedec_ce_60_size = 0;
390 data->emu_jedec_ce_c7_size = data->emu_chip_size;
hailfinger6ead7222010-11-01 22:07:04 +0000391 msg_pdbg("Emulating ST M25P10.RES SPI flash chip (RES, page "
392 "write)\n");
393 }
394 if (!strcmp(tmp, "SST25VF040.REMS")) {
Lachlan Bishopbf1476e2020-09-10 14:57:05 +1000395 data->emu_chip = EMULATE_SST_SST25VF040_REMS;
396 data->emu_chip_size = 512 * 1024;
397 data->emu_max_byteprogram_size = 1;
398 data->emu_max_aai_size = 0;
399 data->emu_jedec_se_size = 4 * 1024;
400 data->emu_jedec_be_52_size = 32 * 1024;
401 data->emu_jedec_be_d8_size = 0;
402 data->emu_jedec_ce_60_size = data->emu_chip_size;
403 data->emu_jedec_ce_c7_size = 0;
hailfinger6ead7222010-11-01 22:07:04 +0000404 msg_pdbg("Emulating SST SST25VF040.REMS SPI flash chip (REMS, "
405 "byte write)\n");
406 }
407 if (!strcmp(tmp, "SST25VF032B")) {
Lachlan Bishopbf1476e2020-09-10 14:57:05 +1000408 data->emu_chip = EMULATE_SST_SST25VF032B;
409 data->emu_chip_size = 4 * 1024 * 1024;
410 data->emu_max_byteprogram_size = 1;
411 data->emu_max_aai_size = 2;
412 data->emu_jedec_se_size = 4 * 1024;
413 data->emu_jedec_be_52_size = 32 * 1024;
414 data->emu_jedec_be_d8_size = 64 * 1024;
415 data->emu_jedec_ce_60_size = data->emu_chip_size;
416 data->emu_jedec_ce_c7_size = data->emu_chip_size;
hailfinger6ead7222010-11-01 22:07:04 +0000417 msg_pdbg("Emulating SST SST25VF032B SPI flash chip (RDID, AAI "
418 "write)\n");
419 }
Stuart Langley78cacf72020-04-23 11:48:01 +1000420 if (!strcmp(tmp, "MX25L6436")) {
Lachlan Bishopbf1476e2020-09-10 14:57:05 +1000421 data->emu_chip = EMULATE_MACRONIX_MX25L6436;
422 data->emu_chip_size = 8 * 1024 * 1024;
423 data->emu_max_byteprogram_size = 256;
424 data->emu_max_aai_size = 0;
425 data->emu_jedec_se_size = 4 * 1024;
426 data->emu_jedec_be_52_size = 32 * 1024;
427 data->emu_jedec_be_d8_size = 64 * 1024;
428 data->emu_jedec_ce_60_size = data->emu_chip_size;
429 data->emu_jedec_ce_c7_size = data->emu_chip_size;
Stuart Langley78cacf72020-04-23 11:48:01 +1000430 msg_pdbg("Emulating Macronix MX25L6436 SPI flash chip (RDID, "
431 "SFDP)\n");
432 }
Edward O'Callaghanec8b0d92020-09-17 17:27:45 +1000433 if (!strcmp(tmp, "W25Q128FV")) {
Lachlan Bishopbf1476e2020-09-10 14:57:05 +1000434 data->emu_chip = EMULATE_WINBOND_W25Q128FV;
435 data->emu_chip_size = 16 * 1024 * 1024;
436 data->emu_max_byteprogram_size = 256;
437 data->emu_max_aai_size = 0;
438 data->emu_jedec_se_size = 4 * 1024;
439 data->emu_jedec_be_52_size = 32 * 1024;
440 data->emu_jedec_be_d8_size = 64 * 1024;
441 data->emu_jedec_ce_60_size = data->emu_chip_size;
442 data->emu_jedec_ce_c7_size = data->emu_chip_size;
Edward O'Callaghanec8b0d92020-09-17 17:27:45 +1000443 msg_pdbg("Emulating Winbond W25Q128FV SPI flash chip (RDID)\n");
444 }
Lachlan Bishopbf1476e2020-09-10 14:57:05 +1000445 data->emu_persistent_image = extract_programmer_param("image");
446 if (!stat(data->emu_persistent_image, &image_stat))
Simon Glassd2c64a22013-07-03 22:05:21 +0900447 image_size = image_stat.st_size;
448
Edward O'Callaghanec8b0d92020-09-17 17:27:45 +1000449 /* The name of variable-size virtual chip. A 4 MiB flash example:
450 * flashrom -p dummy:emulate=VARIABLE_SIZE,size=4194304
451 */
452 if (!strcmp(tmp, "VARIABLE_SIZE")) {
Simon Glassd2c64a22013-07-03 22:05:21 +0900453 if (size == SIZE_UNKNOWN) {
Lachlan Bishopbf1476e2020-09-10 14:57:05 +1000454 msg_perr("%s: the size parameter is not given.\n", __func__);
Louis Yung-Chieh Loe53fa0f2011-04-11 17:18:41 +0800455 free(tmp);
456 return 1;
Simon Glassd2c64a22013-07-03 22:05:21 +0900457 } else if (size == SIZE_AUTO) {
458 if (image_size == SIZE_UNKNOWN) {
Lachlan Bishopbf1476e2020-09-10 14:57:05 +1000459 msg_perr("%s: no image so cannot use automatic size.\n", __func__);
Simon Glassd2c64a22013-07-03 22:05:21 +0900460 free(tmp);
461 return 1;
462 }
463 size = image_size;
Louis Yung-Chieh Loe53fa0f2011-04-11 17:18:41 +0800464 }
Lachlan Bishopbf1476e2020-09-10 14:57:05 +1000465 data->emu_chip = EMULATE_VARIABLE_SIZE;
466 data->emu_chip_size = size;
467 data->emu_max_byteprogram_size = 256;
468 data->emu_max_aai_size = 0;
469 data->emu_jedec_se_size = 4 * 1024;
470 data->emu_jedec_be_52_size = 32 * 1024;
471 data->emu_jedec_be_d8_size = 64 * 1024;
472 data->emu_jedec_ce_60_size = data->emu_chip_size;
473 data->emu_jedec_ce_c7_size = data->emu_chip_size;
Louis Yung-Chieh Loe53fa0f2011-04-11 17:18:41 +0800474 msg_pdbg("Emulating generic SPI flash chip (size=%d bytes)\n",
Lachlan Bishopbf1476e2020-09-10 14:57:05 +1000475 data->emu_chip_size);
Louis Yung-Chieh Loe53fa0f2011-04-11 17:18:41 +0800476 }
hailfinger6ead7222010-11-01 22:07:04 +0000477#endif
Lachlan Bishopbf1476e2020-09-10 14:57:05 +1000478 if (data->emu_chip == EMULATE_NONE) {
hailfinger6ead7222010-11-01 22:07:04 +0000479 msg_perr("Invalid chip specified for emulation: %s\n", tmp);
480 free(tmp);
481 return 1;
482 }
David Hendricks0eda2a82014-09-12 16:32:05 -0700483
484 /* Should emulated flash erase to zero (yes/no)? */
485 tmp = extract_programmer_param("erase_to_zero");
486 if (tmp) {
487 if (!strcmp(tmp, "yes")) {
488 msg_pdbg("Emulated chip will erase to 0x00\n");
Lachlan Bishopbf1476e2020-09-10 14:57:05 +1000489 data->erase_to_zero = 1;
David Hendricks0eda2a82014-09-12 16:32:05 -0700490 } else if (!strcmp(tmp, "no")) {
491 msg_pdbg("Emulated chip will erase to 0xff\n");
492 } else {
493 msg_perr("erase_to_zero can be \"yes\" or \"no\"\n");
494 return 1;
495 }
496 }
497
hailfinger6ead7222010-11-01 22:07:04 +0000498 free(tmp);
Lachlan Bishopbf1476e2020-09-10 14:57:05 +1000499 flashchip_contents = malloc(data->emu_chip_size);
hailfinger6ead7222010-11-01 22:07:04 +0000500 if (!flashchip_contents) {
501 msg_perr("Out of memory!\n");
502 return 1;
503 }
dhendrix0ffc2eb2011-06-14 01:35:36 +0000504
Edward O'Callaghanec8b0d92020-09-17 17:27:45 +1000505#ifdef EMULATE_SPI_CHIP
506 status = extract_programmer_param("spi_status");
507 if (status) {
508 char *endptr;
509 errno = 0;
Lachlan Bishopbf1476e2020-09-10 14:57:05 +1000510 data->emu_status = strtoul(status, &endptr, 0);
Edward O'Callaghanec8b0d92020-09-17 17:27:45 +1000511 free(status);
512 if (errno != 0 || status == endptr) {
513 msg_perr("Error: initial status register specified, "
514 "but the value could not be converted.\n");
515 return 1;
516 }
517 msg_pdbg("Initial status register is set to 0x%02x.\n",
Lachlan Bishopbf1476e2020-09-10 14:57:05 +1000518 data->emu_status);
Edward O'Callaghanec8b0d92020-09-17 17:27:45 +1000519 }
520#endif
521
Lachlan Bishopbf1476e2020-09-10 14:57:05 +1000522 msg_pdbg("Filling fake flash chip with 0x%02x, size %i\n",
523 data->erase_to_zero ? 0x00 : 0xff, data->emu_chip_size);
524 memset(flashchip_contents, data->erase_to_zero ? 0x00 : 0xff, data->emu_chip_size);
525
526 /* Will be freed by shutdown function if necessary. */
527 if (!data->emu_persistent_image) {
hailfinger6ead7222010-11-01 22:07:04 +0000528 /* Nothing else to do. */
dhendrix0ffc2eb2011-06-14 01:35:36 +0000529 goto dummy_init_out;
hailfinger6ead7222010-11-01 22:07:04 +0000530 }
Edward O'Callaghanec8b0d92020-09-17 17:27:45 +1000531
532 /* We will silently (in default verbosity) ignore the file if it does not exist (yet) or the size does
533 * not match the emulated chip. */
Lachlan Bishopbf1476e2020-09-10 14:57:05 +1000534 if (!stat(data->emu_persistent_image, &image_stat)) {
Edward O'Callaghanec8b0d92020-09-17 17:27:45 +1000535 msg_pdbg("Found persistent image %s, %jd B ",
Lachlan Bishopbf1476e2020-09-10 14:57:05 +1000536 data->emu_persistent_image, (intmax_t)image_stat.st_size);
537 if ((uintmax_t)image_stat.st_size == data->emu_chip_size) {
hailfinger6ead7222010-11-01 22:07:04 +0000538 msg_pdbg("matches.\n");
Lachlan Bishopbf1476e2020-09-10 14:57:05 +1000539 msg_pdbg("Reading %s\n", data->emu_persistent_image);
540 if (read_buf_from_file(flashchip_contents, data->emu_chip_size,
541 data->emu_persistent_image)) {
542 msg_perr("Unable to read %s\n", data->emu_persistent_image);
Edward O'Callaghanec8b0d92020-09-17 17:27:45 +1000543 free(flashchip_contents);
544 return 1;
545 }
hailfinger6ead7222010-11-01 22:07:04 +0000546 } else {
547 msg_pdbg("doesn't match.\n");
548 }
549 }
550#endif
hailfingera9df33c2009-05-09 00:54:55 +0000551
dhendrix0ffc2eb2011-06-14 01:35:36 +0000552dummy_init_out:
Lachlan Bishopbf1476e2020-09-10 14:57:05 +1000553 if (register_shutdown(dummy_shutdown, data)) {
hailfinger6ead7222010-11-01 22:07:04 +0000554 free(flashchip_contents);
Lachlan Bishopbf1476e2020-09-10 14:57:05 +1000555 free(data);
dhendrix0ffc2eb2011-06-14 01:35:36 +0000556 return 1;
hailfinger6ead7222010-11-01 22:07:04 +0000557 }
hailfinger76bb7e92011-11-09 23:40:00 +0000558 if (dummy_buses_supported & (BUS_PARALLEL | BUS_LPC | BUS_FWH))
Patrick Georgi0a9533a2017-02-03 19:28:38 +0100559 register_par_master(&par_master_dummy,
Stuart langleyc98e43f2020-03-26 20:27:36 +1100560 dummy_buses_supported & (BUS_PARALLEL | BUS_LPC | BUS_FWH));
hailfinger76bb7e92011-11-09 23:40:00 +0000561 if (dummy_buses_supported & BUS_SPI)
Patrick Georgif4f1e2f2017-03-10 17:38:40 +0100562 register_spi_master(&spi_master_dummyflasher);
hailfinger76bb7e92011-11-09 23:40:00 +0000563
hailfingera9df33c2009-05-09 00:54:55 +0000564 return 0;
565}
566
Patrick Georgi4befc162017-02-03 18:32:01 +0100567void *dummy_map(const char *descr, uintptr_t phys_addr, size_t len)
hailfinger11ae3c42009-05-11 14:13:25 +0000568{
Stuart langleyc98e43f2020-03-26 20:27:36 +1100569 msg_pspew("%s: Mapping %s, 0x%zx bytes at 0x%0*" PRIxPTR "\n",
570 __func__, descr, len, PRIxPTR_WIDTH, phys_addr);
hailfinger11ae3c42009-05-11 14:13:25 +0000571 return (void *)phys_addr;
572}
573
574void dummy_unmap(void *virt_addr, size_t len)
575{
Stuart langleyc98e43f2020-03-26 20:27:36 +1100576 msg_pspew("%s: Unmapping 0x%zx bytes at %p\n", __func__, len, virt_addr);
hailfinger11ae3c42009-05-11 14:13:25 +0000577}
578
Stuart langleyc98e43f2020-03-26 20:27:36 +1100579static void dummy_chip_writeb(const struct flashctx *flash, uint8_t val, chipaddr addr)
hailfingera9df33c2009-05-09 00:54:55 +0000580{
Kangheui Won4974cc12019-10-18 12:59:01 +1100581 msg_pspew("%s: addr=0x%" PRIxPTR ", val=0x%02x\n", __func__, addr, val);
hailfingera9df33c2009-05-09 00:54:55 +0000582}
583
Stuart langleyc98e43f2020-03-26 20:27:36 +1100584static void dummy_chip_writew(const struct flashctx *flash, uint16_t val, chipaddr addr)
hailfingera9df33c2009-05-09 00:54:55 +0000585{
Kangheui Won4974cc12019-10-18 12:59:01 +1100586 msg_pspew("%s: addr=0x%" PRIxPTR ", val=0x%04x\n", __func__, addr, val);
hailfingera9df33c2009-05-09 00:54:55 +0000587}
588
Stuart langleyc98e43f2020-03-26 20:27:36 +1100589static void dummy_chip_writel(const struct flashctx *flash, uint32_t val, chipaddr addr)
hailfingera9df33c2009-05-09 00:54:55 +0000590{
Kangheui Won4974cc12019-10-18 12:59:01 +1100591 msg_pspew("%s: addr=0x%" PRIxPTR ", val=0x%08x\n", __func__, addr, val);
hailfingera9df33c2009-05-09 00:54:55 +0000592}
593
Stuart langleyc98e43f2020-03-26 20:27:36 +1100594static void dummy_chip_writen(const struct flashctx *flash, const uint8_t *buf, chipaddr addr, size_t len)
hailfinger9d987ef2009-06-05 18:32:07 +0000595{
596 size_t i;
Stuart langleyc98e43f2020-03-26 20:27:36 +1100597 msg_pspew("%s: addr=0x%" PRIxPTR ", len=0x%zx, writing data (hex):", __func__, addr, len);
hailfinger9d987ef2009-06-05 18:32:07 +0000598 for (i = 0; i < len; i++) {
599 if ((i % 16) == 0)
hailfinger50c335f2010-01-09 04:32:23 +0000600 msg_pspew("\n");
601 msg_pspew("%02x ", buf[i]);
hailfinger9d987ef2009-06-05 18:32:07 +0000602 }
603}
604
Stuart langleyc98e43f2020-03-26 20:27:36 +1100605static uint8_t dummy_chip_readb(const struct flashctx *flash, const chipaddr addr)
hailfingera9df33c2009-05-09 00:54:55 +0000606{
Kangheui Won4974cc12019-10-18 12:59:01 +1100607 msg_pspew("%s: addr=0x%" PRIxPTR ", returning 0xff\n", __func__, addr);
hailfingera9df33c2009-05-09 00:54:55 +0000608 return 0xff;
609}
610
Stuart langleyc98e43f2020-03-26 20:27:36 +1100611static uint16_t dummy_chip_readw(const struct flashctx *flash, const chipaddr addr)
hailfingera9df33c2009-05-09 00:54:55 +0000612{
Kangheui Won4974cc12019-10-18 12:59:01 +1100613 msg_pspew("%s: addr=0x%" PRIxPTR ", returning 0xffff\n", __func__, addr);
hailfingera9df33c2009-05-09 00:54:55 +0000614 return 0xffff;
615}
616
Stuart langleyc98e43f2020-03-26 20:27:36 +1100617static uint32_t dummy_chip_readl(const struct flashctx *flash, const chipaddr addr)
hailfingera9df33c2009-05-09 00:54:55 +0000618{
Kangheui Won4974cc12019-10-18 12:59:01 +1100619 msg_pspew("%s: addr=0x%" PRIxPTR ", returning 0xffffffff\n", __func__, addr);
hailfingera9df33c2009-05-09 00:54:55 +0000620 return 0xffffffff;
621}
622
Stuart langleyc98e43f2020-03-26 20:27:36 +1100623static void dummy_chip_readn(const struct flashctx *flash, uint8_t *buf, const chipaddr addr, size_t len)
hailfinger9d987ef2009-06-05 18:32:07 +0000624{
Stuart langleyc98e43f2020-03-26 20:27:36 +1100625 msg_pspew("%s: addr=0x%" PRIxPTR ", len=0x%zx, returning array of 0xff\n", __func__, addr, len);
hailfinger9d987ef2009-06-05 18:32:07 +0000626 memset(buf, 0xff, len);
627 return;
628}
629
hailfinger6ead7222010-11-01 22:07:04 +0000630#if EMULATE_SPI_CHIP
Edward O'Callaghanec8b0d92020-09-17 17:27:45 +1000631static int emulate_spi_chip_response(unsigned int writecnt,
632 unsigned int readcnt,
633 const unsigned char *writearr,
Lachlan Bishopbf1476e2020-09-10 14:57:05 +1000634 unsigned char *readarr,
635 struct emu_data *data)
hailfinger6ead7222010-11-01 22:07:04 +0000636{
Stuart Langley78cacf72020-04-23 11:48:01 +1000637 unsigned int offs, i, toread;
stefanctc5eb8a92011-11-23 09:13:48 +0000638 static int unsigned aai_offs;
Carl-Daniel Hailfinger7a4c0472012-08-30 21:41:00 +0000639 const unsigned char sst25vf040_rems_response[2] = {0xbf, 0x44};
640 const unsigned char sst25vf032b_rems_response[2] = {0xbf, 0x4a};
641 const unsigned char mx25l6436_rems_response[2] = {0xc2, 0x16};
Edward O'Callaghanec8b0d92020-09-17 17:27:45 +1000642 const unsigned char w25q128fv_rems_response[2] = {0xef, 0x17};
hailfinger6ead7222010-11-01 22:07:04 +0000643
644 if (writecnt == 0) {
645 msg_perr("No command sent to the chip!\n");
646 return 1;
647 }
Stefan Tauner718d1eb2016-08-18 18:00:53 -0700648 /* spi_blacklist has precedence over spi_ignorelist. */
Lachlan Bishopbf1476e2020-09-10 14:57:05 +1000649 for (i = 0; i < data->spi_blacklist_size; i++) {
650 if (writearr[0] == data->spi_blacklist[i]) {
Carl-Daniel Hailfingerc49783d2016-08-05 10:52:06 -0700651 msg_pdbg("Refusing blacklisted SPI command 0x%02x\n",
Lachlan Bishopbf1476e2020-09-10 14:57:05 +1000652 data->spi_blacklist[i]);
Carl-Daniel Hailfingerc49783d2016-08-05 10:52:06 -0700653 return SPI_INVALID_OPCODE;
654 }
655 }
Lachlan Bishopbf1476e2020-09-10 14:57:05 +1000656 for (i = 0; i < data->spi_ignorelist_size; i++) {
657 if (writearr[0] == data->spi_ignorelist[i]) {
Carl-Daniel Hailfingerc49783d2016-08-05 10:52:06 -0700658 msg_cdbg("Ignoring ignorelisted SPI command 0x%02x\n",
Lachlan Bishopbf1476e2020-09-10 14:57:05 +1000659 data->spi_ignorelist[i]);
Carl-Daniel Hailfingerc49783d2016-08-05 10:52:06 -0700660 /* Return success because the command does not fail,
661 * it is simply ignored.
662 */
663 return 0;
664 }
665 }
Edward O'Callaghanec8b0d92020-09-17 17:27:45 +1000666
Lachlan Bishopbf1476e2020-09-10 14:57:05 +1000667 if (data->emu_max_aai_size && (data->emu_status & SPI_SR_AAI)) {
Edward O'Callaghanec8b0d92020-09-17 17:27:45 +1000668 if (writearr[0] != JEDEC_AAI_WORD_PROGRAM &&
669 writearr[0] != JEDEC_WRDI &&
670 writearr[0] != JEDEC_RDSR) {
671 msg_perr("Forbidden opcode (0x%02x) attempted during "
672 "AAI sequence!\n", writearr[0]);
673 return 0;
674 }
675 }
676
hailfinger6ead7222010-11-01 22:07:04 +0000677 switch (writearr[0]) {
678 case JEDEC_RES:
Carl-Daniel Hailfinger7a4c0472012-08-30 21:41:00 +0000679 if (writecnt < JEDEC_RES_OUTSIZE)
hailfinger6ead7222010-11-01 22:07:04 +0000680 break;
Carl-Daniel Hailfinger7a4c0472012-08-30 21:41:00 +0000681 /* offs calculation is only needed for SST chips which treat RES like REMS. */
682 offs = writearr[1] << 16 | writearr[2] << 8 | writearr[3];
683 offs += writecnt - JEDEC_REMS_OUTSIZE;
Lachlan Bishopbf1476e2020-09-10 14:57:05 +1000684 switch (data->emu_chip) {
Carl-Daniel Hailfinger7a4c0472012-08-30 21:41:00 +0000685 case EMULATE_ST_M25P10_RES:
686 if (readcnt > 0)
687 memset(readarr, 0x10, readcnt);
688 break;
689 case EMULATE_SST_SST25VF040_REMS:
690 for (i = 0; i < readcnt; i++)
691 readarr[i] = sst25vf040_rems_response[(offs + i) % 2];
692 break;
693 case EMULATE_SST_SST25VF032B:
694 for (i = 0; i < readcnt; i++)
695 readarr[i] = sst25vf032b_rems_response[(offs + i) % 2];
696 break;
697 case EMULATE_MACRONIX_MX25L6436:
698 if (readcnt > 0)
699 memset(readarr, 0x16, readcnt);
700 break;
Edward O'Callaghanec8b0d92020-09-17 17:27:45 +1000701 case EMULATE_WINBOND_W25Q128FV:
702 if (readcnt > 0)
703 memset(readarr, 0x17, readcnt);
704 break;
Carl-Daniel Hailfinger7a4c0472012-08-30 21:41:00 +0000705 default: /* ignore */
706 break;
707 }
hailfinger6ead7222010-11-01 22:07:04 +0000708 break;
709 case JEDEC_REMS:
Carl-Daniel Hailfinger7a4c0472012-08-30 21:41:00 +0000710 /* REMS response has wraparound and uses an address parameter. */
711 if (writecnt < JEDEC_REMS_OUTSIZE)
hailfinger6ead7222010-11-01 22:07:04 +0000712 break;
Carl-Daniel Hailfinger7a4c0472012-08-30 21:41:00 +0000713 offs = writearr[1] << 16 | writearr[2] << 8 | writearr[3];
714 offs += writecnt - JEDEC_REMS_OUTSIZE;
Lachlan Bishopbf1476e2020-09-10 14:57:05 +1000715 switch (data->emu_chip) {
Carl-Daniel Hailfinger7a4c0472012-08-30 21:41:00 +0000716 case EMULATE_SST_SST25VF040_REMS:
717 for (i = 0; i < readcnt; i++)
718 readarr[i] = sst25vf040_rems_response[(offs + i) % 2];
719 break;
720 case EMULATE_SST_SST25VF032B:
721 for (i = 0; i < readcnt; i++)
722 readarr[i] = sst25vf032b_rems_response[(offs + i) % 2];
723 break;
724 case EMULATE_MACRONIX_MX25L6436:
725 for (i = 0; i < readcnt; i++)
726 readarr[i] = mx25l6436_rems_response[(offs + i) % 2];
727 break;
Edward O'Callaghanec8b0d92020-09-17 17:27:45 +1000728 case EMULATE_WINBOND_W25Q128FV:
729 for (i = 0; i < readcnt; i++)
730 readarr[i] = w25q128fv_rems_response[(offs + i) % 2];
731 break;
Carl-Daniel Hailfinger7a4c0472012-08-30 21:41:00 +0000732 default: /* ignore */
733 break;
734 }
hailfinger6ead7222010-11-01 22:07:04 +0000735 break;
736 case JEDEC_RDID:
Lachlan Bishopbf1476e2020-09-10 14:57:05 +1000737 switch (data->emu_chip) {
Stuart Langley78cacf72020-04-23 11:48:01 +1000738 case EMULATE_SST_SST25VF032B:
Louis Yung-Chieh Loe53fa0f2011-04-11 17:18:41 +0800739 if (readcnt > 0)
740 readarr[0] = 0xbf;
741 if (readcnt > 1)
742 readarr[1] = 0x25;
743 if (readcnt > 2)
744 readarr[2] = 0x4a;
Stuart Langley78cacf72020-04-23 11:48:01 +1000745 break;
746 case EMULATE_MACRONIX_MX25L6436:
747 if (readcnt > 0)
748 readarr[0] = 0xc2;
749 if (readcnt > 1)
750 readarr[1] = 0x20;
751 if (readcnt > 2)
752 readarr[2] = 0x17;
753 break;
Edward O'Callaghanec8b0d92020-09-17 17:27:45 +1000754 case EMULATE_WINBOND_W25Q128FV:
755 if (readcnt > 0)
756 readarr[0] = 0xef;
757 if (readcnt > 1)
758 readarr[1] = 0x40;
759 if (readcnt > 2)
760 readarr[2] = 0x18;
761 break;
Edward O'Callaghane0772312020-09-16 17:57:19 +1000762 case EMULATE_VARIABLE_SIZE:
763 if (readcnt > 0)
764 readarr[0] = (PROGMANUF_ID >> 8) & 0xff;
765 if (readcnt > 1)
766 readarr[1] = PROGMANUF_ID & 0xff;
767 if (readcnt > 2)
768 readarr[2] = (PROGDEV_ID >> 8) & 0xff;
769 if (readcnt > 3)
770 readarr[3] = PROGDEV_ID & 0xff;
Stuart Langley78cacf72020-04-23 11:48:01 +1000771 break;
Stuart Langley78cacf72020-04-23 11:48:01 +1000772 default: /* ignore */
773 break;
Louis Yung-Chieh Loe53fa0f2011-04-11 17:18:41 +0800774 }
hailfinger6ead7222010-11-01 22:07:04 +0000775 break;
776 case JEDEC_RDSR:
Lachlan Bishopbf1476e2020-09-10 14:57:05 +1000777 memset(readarr, data->emu_status, readcnt);
Edward O'Callaghanec8b0d92020-09-17 17:27:45 +1000778 break;
779 /* FIXME: this should be chip-specific. */
780 case JEDEC_EWSR:
781 case JEDEC_WREN:
Lachlan Bishopbf1476e2020-09-10 14:57:05 +1000782 data->emu_status |= SPI_SR_WEL;
Edward O'Callaghanec8b0d92020-09-17 17:27:45 +1000783 break;
784 case JEDEC_WRSR:
Lachlan Bishopbf1476e2020-09-10 14:57:05 +1000785 if (!(data->emu_status & SPI_SR_WEL)) {
Edward O'Callaghanec8b0d92020-09-17 17:27:45 +1000786 msg_perr("WRSR attempted, but WEL is 0!\n");
787 break;
788 }
789 /* FIXME: add some reasonable simulation of the busy flag */
Lachlan Bishopbf1476e2020-09-10 14:57:05 +1000790 data->emu_status = writearr[1] & ~SPI_SR_WIP;
791 msg_pdbg2("WRSR wrote 0x%02x.\n", data->emu_status);
hailfinger6ead7222010-11-01 22:07:04 +0000792 break;
793 case JEDEC_READ:
794 offs = writearr[1] << 16 | writearr[2] << 8 | writearr[3];
795 /* Truncate to emu_chip_size. */
Lachlan Bishopbf1476e2020-09-10 14:57:05 +1000796 offs %= data->emu_chip_size;
hailfinger6ead7222010-11-01 22:07:04 +0000797 if (readcnt > 0)
798 memcpy(readarr, flashchip_contents + offs, readcnt);
799 break;
Namyoon Woob71a2962020-08-27 16:27:49 -0700800 case JEDEC_READ_4BA:
801 offs = writearr[1] << 24 | writearr[2] << 16 | writearr[3] << 8 | writearr[4];
802 /* Truncate to emu_chip_size. */
Lachlan Bishopbf1476e2020-09-10 14:57:05 +1000803 offs %= data->emu_chip_size;
Namyoon Woob71a2962020-08-27 16:27:49 -0700804 if (readcnt > 0)
805 memcpy(readarr, flashchip_contents + offs, readcnt);
806 break;
hailfinger6ead7222010-11-01 22:07:04 +0000807 case JEDEC_BYTE_PROGRAM:
808 offs = writearr[1] << 16 | writearr[2] << 8 | writearr[3];
809 /* Truncate to emu_chip_size. */
Lachlan Bishopbf1476e2020-09-10 14:57:05 +1000810 offs %= data->emu_chip_size;
hailfinger6ead7222010-11-01 22:07:04 +0000811 if (writecnt < 5) {
812 msg_perr("BYTE PROGRAM size too short!\n");
813 return 1;
814 }
Lachlan Bishopbf1476e2020-09-10 14:57:05 +1000815 if (writecnt - 4 > data->emu_max_byteprogram_size) {
hailfinger6ead7222010-11-01 22:07:04 +0000816 msg_perr("Max BYTE PROGRAM size exceeded!\n");
817 return 1;
818 }
819 memcpy(flashchip_contents + offs, writearr + 4, writecnt - 4);
Lachlan Bishopbf1476e2020-09-10 14:57:05 +1000820 data->emu_modified = 1;
hailfinger6ead7222010-11-01 22:07:04 +0000821 break;
Namyoon Woob71a2962020-08-27 16:27:49 -0700822 case JEDEC_BYTE_PROGRAM_4BA:
823 offs = writearr[1] << 24 | writearr[2] << 16 | writearr[3] << 8 | writearr[4];
824 /* Truncate to emu_chip_size. */
Lachlan Bishopbf1476e2020-09-10 14:57:05 +1000825 offs %= data->emu_chip_size;
Namyoon Woob71a2962020-08-27 16:27:49 -0700826 if (writecnt < 6) {
827 msg_perr("BYTE PROGRAM size too short!\n");
828 return 1;
829 }
Lachlan Bishopbf1476e2020-09-10 14:57:05 +1000830 if (writecnt - 5 > data->emu_max_byteprogram_size) {
Namyoon Woob71a2962020-08-27 16:27:49 -0700831 msg_perr("Max BYTE PROGRAM size exceeded!\n");
832 return 1;
833 }
834 memcpy(flashchip_contents + offs, writearr + 5, writecnt - 5);
Lachlan Bishopbf1476e2020-09-10 14:57:05 +1000835 data->emu_modified = 1;
Namyoon Woob71a2962020-08-27 16:27:49 -0700836 break;
hailfinger6ead7222010-11-01 22:07:04 +0000837 case JEDEC_AAI_WORD_PROGRAM:
Lachlan Bishopbf1476e2020-09-10 14:57:05 +1000838 if (!data->emu_max_aai_size)
hailfinger6ead7222010-11-01 22:07:04 +0000839 break;
Lachlan Bishopbf1476e2020-09-10 14:57:05 +1000840 if (!(data->emu_status & SPI_SR_AAI)) {
hailfinger6ead7222010-11-01 22:07:04 +0000841 if (writecnt < JEDEC_AAI_WORD_PROGRAM_OUTSIZE) {
842 msg_perr("Initial AAI WORD PROGRAM size too "
843 "short!\n");
844 return 1;
845 }
846 if (writecnt > JEDEC_AAI_WORD_PROGRAM_OUTSIZE) {
847 msg_perr("Initial AAI WORD PROGRAM size too "
848 "long!\n");
849 return 1;
850 }
Lachlan Bishopbf1476e2020-09-10 14:57:05 +1000851 data->emu_status |= SPI_SR_AAI;
hailfinger6ead7222010-11-01 22:07:04 +0000852 aai_offs = writearr[1] << 16 | writearr[2] << 8 |
853 writearr[3];
854 /* Truncate to emu_chip_size. */
Lachlan Bishopbf1476e2020-09-10 14:57:05 +1000855 aai_offs %= data->emu_chip_size;
hailfinger6ead7222010-11-01 22:07:04 +0000856 memcpy(flashchip_contents + aai_offs, writearr + 4, 2);
857 aai_offs += 2;
858 } else {
859 if (writecnt < JEDEC_AAI_WORD_PROGRAM_CONT_OUTSIZE) {
860 msg_perr("Continuation AAI WORD PROGRAM size "
861 "too short!\n");
862 return 1;
863 }
864 if (writecnt > JEDEC_AAI_WORD_PROGRAM_CONT_OUTSIZE) {
865 msg_perr("Continuation AAI WORD PROGRAM size "
866 "too long!\n");
867 return 1;
868 }
869 memcpy(flashchip_contents + aai_offs, writearr + 1, 2);
870 aai_offs += 2;
871 }
Lachlan Bishopbf1476e2020-09-10 14:57:05 +1000872 data->emu_modified = 1;
hailfinger6ead7222010-11-01 22:07:04 +0000873 break;
874 case JEDEC_WRDI:
Lachlan Bishopbf1476e2020-09-10 14:57:05 +1000875 if (data->emu_max_aai_size)
876 data->emu_status &= ~SPI_SR_AAI;
hailfinger6ead7222010-11-01 22:07:04 +0000877 break;
878 case JEDEC_SE:
Lachlan Bishopbf1476e2020-09-10 14:57:05 +1000879 if (!data->emu_jedec_se_size)
hailfinger6ead7222010-11-01 22:07:04 +0000880 break;
881 if (writecnt != JEDEC_SE_OUTSIZE) {
882 msg_perr("SECTOR ERASE 0x20 outsize invalid!\n");
883 return 1;
884 }
885 if (readcnt != JEDEC_SE_INSIZE) {
886 msg_perr("SECTOR ERASE 0x20 insize invalid!\n");
887 return 1;
888 }
889 offs = writearr[1] << 16 | writearr[2] << 8 | writearr[3];
Lachlan Bishopbf1476e2020-09-10 14:57:05 +1000890 if (offs & (data->emu_jedec_se_size - 1))
hailfingere53f5e42011-02-04 22:52:04 +0000891 msg_pdbg("Unaligned SECTOR ERASE 0x20: 0x%x\n", offs);
Lachlan Bishopbf1476e2020-09-10 14:57:05 +1000892 offs &= ~(data->emu_jedec_se_size - 1);
893 memset(flashchip_contents + offs, 0xff, data->emu_jedec_se_size);
894 data->emu_modified = 1;
hailfinger6ead7222010-11-01 22:07:04 +0000895 break;
896 case JEDEC_BE_52:
Lachlan Bishopbf1476e2020-09-10 14:57:05 +1000897 if (!data->emu_jedec_be_52_size)
hailfinger6ead7222010-11-01 22:07:04 +0000898 break;
899 if (writecnt != JEDEC_BE_52_OUTSIZE) {
900 msg_perr("BLOCK ERASE 0x52 outsize invalid!\n");
901 return 1;
902 }
903 if (readcnt != JEDEC_BE_52_INSIZE) {
904 msg_perr("BLOCK ERASE 0x52 insize invalid!\n");
905 return 1;
906 }
907 offs = writearr[1] << 16 | writearr[2] << 8 | writearr[3];
Lachlan Bishopbf1476e2020-09-10 14:57:05 +1000908 if (offs & (data->emu_jedec_be_52_size - 1))
hailfingere53f5e42011-02-04 22:52:04 +0000909 msg_pdbg("Unaligned BLOCK ERASE 0x52: 0x%x\n", offs);
Lachlan Bishopbf1476e2020-09-10 14:57:05 +1000910 offs &= ~(data->emu_jedec_be_52_size - 1);
911 memset(flashchip_contents + offs, 0xff, data->emu_jedec_be_52_size);
912 data->emu_modified = 1;
hailfinger6ead7222010-11-01 22:07:04 +0000913 break;
914 case JEDEC_BE_D8:
Lachlan Bishopbf1476e2020-09-10 14:57:05 +1000915 if (!data->emu_jedec_be_d8_size)
hailfinger6ead7222010-11-01 22:07:04 +0000916 break;
917 if (writecnt != JEDEC_BE_D8_OUTSIZE) {
918 msg_perr("BLOCK ERASE 0xd8 outsize invalid!\n");
919 return 1;
920 }
921 if (readcnt != JEDEC_BE_D8_INSIZE) {
922 msg_perr("BLOCK ERASE 0xd8 insize invalid!\n");
923 return 1;
924 }
925 offs = writearr[1] << 16 | writearr[2] << 8 | writearr[3];
Lachlan Bishopbf1476e2020-09-10 14:57:05 +1000926 if (offs & (data->emu_jedec_be_d8_size - 1))
hailfingere53f5e42011-02-04 22:52:04 +0000927 msg_pdbg("Unaligned BLOCK ERASE 0xd8: 0x%x\n", offs);
Lachlan Bishopbf1476e2020-09-10 14:57:05 +1000928 offs &= ~(data->emu_jedec_be_d8_size - 1);
929 memset(flashchip_contents + offs, 0xff, data->emu_jedec_be_d8_size);
930 data->emu_modified = 1;
hailfinger6ead7222010-11-01 22:07:04 +0000931 break;
932 case JEDEC_CE_60:
Lachlan Bishopbf1476e2020-09-10 14:57:05 +1000933 if (!data->emu_jedec_ce_60_size)
hailfinger6ead7222010-11-01 22:07:04 +0000934 break;
935 if (writecnt != JEDEC_CE_60_OUTSIZE) {
936 msg_perr("CHIP ERASE 0x60 outsize invalid!\n");
937 return 1;
938 }
939 if (readcnt != JEDEC_CE_60_INSIZE) {
940 msg_perr("CHIP ERASE 0x60 insize invalid!\n");
941 return 1;
942 }
hailfingere53f5e42011-02-04 22:52:04 +0000943 /* JEDEC_CE_60_OUTSIZE is 1 (no address) -> no offset. */
hailfinger6ead7222010-11-01 22:07:04 +0000944 /* emu_jedec_ce_60_size is emu_chip_size. */
Lachlan Bishopbf1476e2020-09-10 14:57:05 +1000945 memset(flashchip_contents, 0xff, data->emu_jedec_ce_60_size);
946 data->emu_modified = 1;
hailfinger6ead7222010-11-01 22:07:04 +0000947 break;
948 case JEDEC_CE_C7:
Lachlan Bishopbf1476e2020-09-10 14:57:05 +1000949 if (!data->emu_jedec_ce_c7_size)
hailfinger6ead7222010-11-01 22:07:04 +0000950 break;
951 if (writecnt != JEDEC_CE_C7_OUTSIZE) {
952 msg_perr("CHIP ERASE 0xc7 outsize invalid!\n");
953 return 1;
954 }
955 if (readcnt != JEDEC_CE_C7_INSIZE) {
956 msg_perr("CHIP ERASE 0xc7 insize invalid!\n");
957 return 1;
958 }
hailfingere53f5e42011-02-04 22:52:04 +0000959 /* JEDEC_CE_C7_OUTSIZE is 1 (no address) -> no offset. */
hailfinger6ead7222010-11-01 22:07:04 +0000960 /* emu_jedec_ce_c7_size is emu_chip_size. */
Lachlan Bishopbf1476e2020-09-10 14:57:05 +1000961 memset(flashchip_contents, 0xff, data->emu_jedec_ce_c7_size);
962 data->emu_modified = 1;
hailfinger6ead7222010-11-01 22:07:04 +0000963 break;
Stuart Langley78cacf72020-04-23 11:48:01 +1000964 case JEDEC_SFDP:
Lachlan Bishopbf1476e2020-09-10 14:57:05 +1000965 if (data->emu_chip != EMULATE_MACRONIX_MX25L6436)
Stuart Langley78cacf72020-04-23 11:48:01 +1000966 break;
967 if (writecnt < 4)
968 break;
969 offs = writearr[1] << 16 | writearr[2] << 8 | writearr[3];
970
971 /* SFDP expects one dummy byte after the address. */
972 if (writecnt == 4) {
973 /* The dummy byte was not written, make sure it is read instead.
974 * Shifting and shortening the read array does achieve this goal.
975 */
976 readarr++;
977 readcnt--;
978 } else {
979 /* The response is shifted if more than 5 bytes are written, because SFDP data is
980 * already shifted out by the chip while those superfluous bytes are written. */
981 offs += writecnt - 5;
982 }
983
984 /* The SFDP spec implies that the start address of an SFDP read may be truncated to fit in the
985 * SFDP table address space, i.e. the start address may be wrapped around at SFDP table size.
986 * This is a reasonable implementation choice in hardware because it saves a few gates. */
987 if (offs >= sizeof(sfdp_table)) {
988 msg_pdbg("Wrapping the start address around the SFDP table boundary (using 0x%x "
989 "instead of 0x%x).\n", (unsigned int)(offs % sizeof(sfdp_table)), offs);
990 offs %= sizeof(sfdp_table);
991 }
992 toread = min(sizeof(sfdp_table) - offs, readcnt);
993 memcpy(readarr, sfdp_table + offs, toread);
994 if (toread < readcnt)
995 msg_pdbg("Crossing the SFDP table boundary in a single "
996 "continuous chunk produces undefined results "
997 "after that point.\n");
998 break;
hailfinger6ead7222010-11-01 22:07:04 +0000999 default:
1000 /* No special response. */
1001 break;
1002 }
Edward O'Callaghanec8b0d92020-09-17 17:27:45 +10001003 if (writearr[0] != JEDEC_WREN && writearr[0] != JEDEC_EWSR)
Lachlan Bishopbf1476e2020-09-10 14:57:05 +10001004 data->emu_status &= ~SPI_SR_WEL;
hailfinger6ead7222010-11-01 22:07:04 +00001005 return 0;
1006}
1007#endif
1008
Lachlan Bishopbf1476e2020-09-10 14:57:05 +10001009static struct emu_data* get_data_from_context(const struct flashctx *flash)
1010{
1011 if (dummy_buses_supported & (BUS_PARALLEL | BUS_LPC | BUS_FWH))
1012 return (struct emu_data *)flash->mst->par.data;
1013 else if (dummy_buses_supported & BUS_SPI)
1014 return (struct emu_data *)flash->mst->spi.data;
1015
1016 return NULL; /* buses was set to BUS_NONE. */
1017}
1018
Stuart langleyc98e43f2020-03-26 20:27:36 +11001019static int dummy_spi_send_command(const struct flashctx *flash, unsigned int writecnt,
1020 unsigned int readcnt,
1021 const unsigned char *writearr,
1022 unsigned char *readarr)
hailfingerf91e3b52009-05-14 12:59:36 +00001023{
Edward O'Callaghanec8b0d92020-09-17 17:27:45 +10001024 unsigned int i;
Lachlan Bishopbf1476e2020-09-10 14:57:05 +10001025 struct emu_data *emu_data = get_data_from_context(flash);
1026 if (!emu_data) {
1027 msg_perr("No data in flash context!\n");
1028 return 1;
1029 }
hailfingerf91e3b52009-05-14 12:59:36 +00001030
hailfinger50c335f2010-01-09 04:32:23 +00001031 msg_pspew("%s:", __func__);
hailfingerf91e3b52009-05-14 12:59:36 +00001032
hailfinger50c335f2010-01-09 04:32:23 +00001033 msg_pspew(" writing %u bytes:", writecnt);
hailfingerf91e3b52009-05-14 12:59:36 +00001034 for (i = 0; i < writecnt; i++)
hailfinger50c335f2010-01-09 04:32:23 +00001035 msg_pspew(" 0x%02x", writearr[i]);
hailfingerf91e3b52009-05-14 12:59:36 +00001036
hailfinger6ead7222010-11-01 22:07:04 +00001037 /* Response for unknown commands and missing chip is 0xff. */
1038 memset(readarr, 0xff, readcnt);
1039#if EMULATE_SPI_CHIP
Lachlan Bishopbf1476e2020-09-10 14:57:05 +10001040 switch (emu_data->emu_chip) {
hailfinger6ead7222010-11-01 22:07:04 +00001041 case EMULATE_ST_M25P10_RES:
1042 case EMULATE_SST_SST25VF040_REMS:
1043 case EMULATE_SST_SST25VF032B:
Stuart Langley78cacf72020-04-23 11:48:01 +10001044 case EMULATE_MACRONIX_MX25L6436:
Edward O'Callaghanec8b0d92020-09-17 17:27:45 +10001045 case EMULATE_WINBOND_W25Q128FV:
Louis Yung-Chieh Loe53fa0f2011-04-11 17:18:41 +08001046 case EMULATE_VARIABLE_SIZE:
Edward O'Callaghanec8b0d92020-09-17 17:27:45 +10001047 if (emulate_spi_chip_response(writecnt, readcnt, writearr,
Lachlan Bishopbf1476e2020-09-10 14:57:05 +10001048 readarr, emu_data)) {
Carl-Daniel Hailfingerc49783d2016-08-05 10:52:06 -07001049 msg_pdbg("Invalid command sent to flash chip!\n");
hailfinger6ead7222010-11-01 22:07:04 +00001050 return 1;
1051 }
1052 break;
1053 default:
1054 break;
1055 }
1056#endif
hailfinger50c335f2010-01-09 04:32:23 +00001057 msg_pspew(" reading %u bytes:", readcnt);
uwe8d342eb2011-07-28 08:13:25 +00001058 for (i = 0; i < readcnt; i++)
hailfinger6ead7222010-11-01 22:07:04 +00001059 msg_pspew(" 0x%02x", readarr[i]);
hailfinger50c335f2010-01-09 04:32:23 +00001060 msg_pspew("\n");
David Hendricks84377002014-09-09 16:09:31 -07001061
1062 programmer_delay((writecnt + readcnt) * delay_us);
hailfingerf91e3b52009-05-14 12:59:36 +00001063 return 0;
1064}
hailfingera8727712010-06-20 10:58:32 +00001065
Stuart langleyc98e43f2020-03-26 20:27:36 +11001066static int dummy_spi_write_256(struct flashctx *flash, const uint8_t *buf, unsigned int start, unsigned int len)
hailfingerc7d06c62010-07-14 16:19:05 +00001067{
hailfinger6ead7222010-11-01 22:07:04 +00001068 return spi_write_chunked(flash, buf, start, len,
1069 spi_write_256_chunksize);
hailfingerc7d06c62010-07-14 16:19:05 +00001070}
Louis Yung-Chieh Loe53fa0f2011-04-11 17:18:41 +08001071
1072#if EMULATE_CHIP && EMULATE_SPI_CHIP
Souvik Ghoshd75cd672016-06-17 14:21:39 -07001073int probe_variable_size(struct flashctx *flash)
Louis Yung-Chieh Loe53fa0f2011-04-11 17:18:41 +08001074{
Edward O'Callaghanec8b0d92020-09-17 17:27:45 +10001075 unsigned int i;
Lachlan Bishopbf1476e2020-09-10 14:57:05 +10001076 const struct emu_data *emu_data = get_data_from_context(flash);
1077 if (!emu_data) {
1078 msg_perr("No data in flash context!\n");
1079 return 0;
1080 }
Louis Yung-Chieh Loe53fa0f2011-04-11 17:18:41 +08001081
1082 /* Skip the probing if we don't emulate this chip. */
Lachlan Bishopbf1476e2020-09-10 14:57:05 +10001083 if (emu_data->emu_chip != EMULATE_VARIABLE_SIZE)
Louis Yung-Chieh Loe53fa0f2011-04-11 17:18:41 +08001084 return 0;
1085
1086 /*
Souvik Ghoshd75cd672016-06-17 14:21:39 -07001087 * This will break if one day flashctx becomes read-only.
Louis Yung-Chieh Loe53fa0f2011-04-11 17:18:41 +08001088 * Once that happens, we need to have special hacks in functions:
1089 *
1090 * erase_and_write_flash() in flashrom.c
1091 * read_flash_to_file()
1092 * handle_romentries()
1093 * ...
1094 *
1095 * Search "total_size * 1024" in code.
1096 */
Lachlan Bishopbf1476e2020-09-10 14:57:05 +10001097 flash->chip->total_size = emu_data->emu_chip_size / 1024;
Louis Yung-Chieh Loe53fa0f2011-04-11 17:18:41 +08001098 msg_cdbg("%s: set flash->total_size to %dK bytes.\n", __func__,
Patrick Georgif3fa2992017-02-02 16:24:44 +01001099 flash->chip->total_size);
Louis Yung-Chieh Loe53fa0f2011-04-11 17:18:41 +08001100
Lachlan Bishopbf1476e2020-09-10 14:57:05 +10001101 if (emu_data->erase_to_zero)
Alan Greendbeec2b2019-09-16 14:36:52 +10001102 flash->chip->feature_bits |= FEATURE_ERASED_ZERO;
David Hendricks0eda2a82014-09-12 16:32:05 -07001103
Edward O'Callaghanec8b0d92020-09-17 17:27:45 +10001104 /* Update the first count of each of the block_erasers. */
Louis Yung-Chieh Loe53fa0f2011-04-11 17:18:41 +08001105 for (i = 0; i < NUM_ERASEFUNCTIONS; i++) {
Patrick Georgif3fa2992017-02-02 16:24:44 +01001106 struct block_eraser *eraser = &flash->chip->block_erasers[i];
Edward O'Callaghanec8b0d92020-09-17 17:27:45 +10001107 if (!eraser->block_erase)
Louis Yung-Chieh Loe53fa0f2011-04-11 17:18:41 +08001108 break;
1109
Namyoon Woob71a2962020-08-27 16:27:49 -07001110 eraser->eraseblocks[0].count = 1;
Lachlan Bishopbf1476e2020-09-10 14:57:05 +10001111 eraser->eraseblocks[0].size = emu_data->emu_chip_size;
Louis Yung-Chieh Loe53fa0f2011-04-11 17:18:41 +08001112 msg_cdbg("%s: eraser.size=%d, .count=%d\n",
1113 __func__, eraser->eraseblocks[0].size,
1114 eraser->eraseblocks[0].count);
1115 }
1116
1117 return 1;
1118}
1119#endif