blob: c4448a5a6b0167ad0de42ab0a40b349a415cbbff [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
Patrick Georgi0a9533a2017-02-03 19:28:38 +0100130static const 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
Simon Glassd2c64a22013-07-03 22:05:21 +0900163/* Values for the 'size' parameter */
164enum {
165 SIZE_UNKNOWN = -1,
166 SIZE_AUTO = -2,
167};
168
David Hendricksac1d25c2016-08-09 17:00:58 -0700169int dummy_init(void)
hailfingera9df33c2009-05-09 00:54:55 +0000170{
hailfinger1ef766d2010-07-06 09:55:48 +0000171 char *bustext = NULL;
hailfinger6ead7222010-11-01 22:07:04 +0000172 char *tmp = NULL;
Edward O'Callaghanec8b0d92020-09-17 17:27:45 +1000173 unsigned int i;
Louis Yung-Chieh Loe53fa0f2011-04-11 17:18:41 +0800174#if EMULATE_SPI_CHIP
Edward O'Callaghanec8b0d92020-09-17 17:27:45 +1000175 char *status = NULL;
Simon Glassd2c64a22013-07-03 22:05:21 +0900176 int size = SIZE_UNKNOWN; /* size for generic chip */
Louis Yung-Chieh Loe53fa0f2011-04-11 17:18:41 +0800177#endif
Edward O'Callaghanec8b0d92020-09-17 17:27:45 +1000178#if EMULATE_CHIP
179 struct stat image_stat;
hailfinger6ead7222010-11-01 22:07:04 +0000180#endif
Simon Glassd2c64a22013-07-03 22:05:21 +0900181 int image_size = SIZE_UNKNOWN;
hailfinger1ef766d2010-07-06 09:55:48 +0000182
Lachlan Bishopbf1476e2020-09-10 14:57:05 +1000183 struct emu_data *data = calloc(1, sizeof(struct emu_data));
184 if (!data) {
185 msg_perr("Out of memory!\n");
186 return 1;
187 }
188 data->emu_chip = EMULATE_NONE;
Edward O'Callaghan0037f452020-09-17 13:32:00 +1000189 data->delay_us = 0;
Lachlan Bishopbf1476e2020-09-10 14:57:05 +1000190 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));
Edward O'Callaghan0037f452020-09-17 13:32:00 +1000316 free(tmp);
317 return 1;
David Hendricks84377002014-09-09 16:09:31 -0700318 }
319
320 if ((units > tmp) && (units < end)) {
321 int units_valid = 0;
322
323 if (units < end - 3) {
324 ;
325 } else if (units == end - 2) {
326 if (!strcasecmp(units, "hz"))
327 units_valid = 1;
328 } else if (units == end - 3) {
329 if (!strcasecmp(units, "khz")) {
330 freq *= 1000;
331 units_valid = 1;
332 } else if (!strcasecmp(units, "mhz")) {
333 freq *= 1000000;
334 units_valid = 1;
335 }
336 }
337
338 if (!units_valid) {
339 msg_perr("Invalid units: %s\n", units);
Edward O'Callaghan0037f452020-09-17 13:32:00 +1000340 free(tmp);
David Hendricks84377002014-09-09 16:09:31 -0700341 return 1;
342 }
343 }
344
345 /* Assume we only work with bytes and transfer at 1 bit/Hz */
Edward O'Callaghan0037f452020-09-17 13:32:00 +1000346 data->delay_us = (1000000 * 8) / freq;
David Hendricks84377002014-09-09 16:09:31 -0700347 }
Edward O'Callaghan0037f452020-09-17 13:32:00 +1000348 free(tmp);
David Hendricks84377002014-09-09 16:09:31 -0700349
hailfinger6ead7222010-11-01 22:07:04 +0000350#if EMULATE_CHIP
Louis Yung-Chieh Loe53fa0f2011-04-11 17:18:41 +0800351#if EMULATE_SPI_CHIP
352 tmp = extract_programmer_param("size");
353 if (tmp) {
Simon Glassd2c64a22013-07-03 22:05:21 +0900354 if (!strcmp(tmp, "auto"))
355 size = SIZE_AUTO;
Edward O'Callaghancb6f2112020-11-23 13:09:47 +1100356 else if (strlen(tmp))
357 size = atoi(tmp);
Edward O'Callaghanec8b0d92020-09-17 17:27:45 +1000358 free(tmp);
Louis Yung-Chieh Loe53fa0f2011-04-11 17:18:41 +0800359 }
360#endif
361
hailfinger6ead7222010-11-01 22:07:04 +0000362 tmp = extract_programmer_param("emulate");
363 if (!tmp) {
364 msg_pdbg("Not emulating any flash chip.\n");
365 /* Nothing else to do. */
dhendrix0ffc2eb2011-06-14 01:35:36 +0000366 goto dummy_init_out;
hailfinger6ead7222010-11-01 22:07:04 +0000367 }
368#if EMULATE_SPI_CHIP
369 if (!strcmp(tmp, "M25P10.RES")) {
Lachlan Bishopbf1476e2020-09-10 14:57:05 +1000370 data->emu_chip = EMULATE_ST_M25P10_RES;
371 data->emu_chip_size = 128 * 1024;
372 data->emu_max_byteprogram_size = 128;
373 data->emu_max_aai_size = 0;
374 data->emu_jedec_se_size = 0;
375 data->emu_jedec_be_52_size = 0;
376 data->emu_jedec_be_d8_size = 32 * 1024;
377 data->emu_jedec_ce_60_size = 0;
378 data->emu_jedec_ce_c7_size = data->emu_chip_size;
hailfinger6ead7222010-11-01 22:07:04 +0000379 msg_pdbg("Emulating ST M25P10.RES SPI flash chip (RES, page "
380 "write)\n");
381 }
382 if (!strcmp(tmp, "SST25VF040.REMS")) {
Lachlan Bishopbf1476e2020-09-10 14:57:05 +1000383 data->emu_chip = EMULATE_SST_SST25VF040_REMS;
384 data->emu_chip_size = 512 * 1024;
385 data->emu_max_byteprogram_size = 1;
386 data->emu_max_aai_size = 0;
387 data->emu_jedec_se_size = 4 * 1024;
388 data->emu_jedec_be_52_size = 32 * 1024;
389 data->emu_jedec_be_d8_size = 0;
390 data->emu_jedec_ce_60_size = data->emu_chip_size;
391 data->emu_jedec_ce_c7_size = 0;
hailfinger6ead7222010-11-01 22:07:04 +0000392 msg_pdbg("Emulating SST SST25VF040.REMS SPI flash chip (REMS, "
393 "byte write)\n");
394 }
395 if (!strcmp(tmp, "SST25VF032B")) {
Lachlan Bishopbf1476e2020-09-10 14:57:05 +1000396 data->emu_chip = EMULATE_SST_SST25VF032B;
397 data->emu_chip_size = 4 * 1024 * 1024;
398 data->emu_max_byteprogram_size = 1;
399 data->emu_max_aai_size = 2;
400 data->emu_jedec_se_size = 4 * 1024;
401 data->emu_jedec_be_52_size = 32 * 1024;
402 data->emu_jedec_be_d8_size = 64 * 1024;
403 data->emu_jedec_ce_60_size = data->emu_chip_size;
404 data->emu_jedec_ce_c7_size = data->emu_chip_size;
hailfinger6ead7222010-11-01 22:07:04 +0000405 msg_pdbg("Emulating SST SST25VF032B SPI flash chip (RDID, AAI "
406 "write)\n");
407 }
Stuart Langley78cacf72020-04-23 11:48:01 +1000408 if (!strcmp(tmp, "MX25L6436")) {
Lachlan Bishopbf1476e2020-09-10 14:57:05 +1000409 data->emu_chip = EMULATE_MACRONIX_MX25L6436;
410 data->emu_chip_size = 8 * 1024 * 1024;
411 data->emu_max_byteprogram_size = 256;
412 data->emu_max_aai_size = 0;
413 data->emu_jedec_se_size = 4 * 1024;
414 data->emu_jedec_be_52_size = 32 * 1024;
415 data->emu_jedec_be_d8_size = 64 * 1024;
416 data->emu_jedec_ce_60_size = data->emu_chip_size;
417 data->emu_jedec_ce_c7_size = data->emu_chip_size;
Stuart Langley78cacf72020-04-23 11:48:01 +1000418 msg_pdbg("Emulating Macronix MX25L6436 SPI flash chip (RDID, "
419 "SFDP)\n");
420 }
Edward O'Callaghanec8b0d92020-09-17 17:27:45 +1000421 if (!strcmp(tmp, "W25Q128FV")) {
Lachlan Bishopbf1476e2020-09-10 14:57:05 +1000422 data->emu_chip = EMULATE_WINBOND_W25Q128FV;
423 data->emu_chip_size = 16 * 1024 * 1024;
424 data->emu_max_byteprogram_size = 256;
425 data->emu_max_aai_size = 0;
426 data->emu_jedec_se_size = 4 * 1024;
427 data->emu_jedec_be_52_size = 32 * 1024;
428 data->emu_jedec_be_d8_size = 64 * 1024;
429 data->emu_jedec_ce_60_size = data->emu_chip_size;
430 data->emu_jedec_ce_c7_size = data->emu_chip_size;
Edward O'Callaghanec8b0d92020-09-17 17:27:45 +1000431 msg_pdbg("Emulating Winbond W25Q128FV SPI flash chip (RDID)\n");
432 }
Lachlan Bishopbf1476e2020-09-10 14:57:05 +1000433 data->emu_persistent_image = extract_programmer_param("image");
434 if (!stat(data->emu_persistent_image, &image_stat))
Simon Glassd2c64a22013-07-03 22:05:21 +0900435 image_size = image_stat.st_size;
436
Edward O'Callaghanec8b0d92020-09-17 17:27:45 +1000437 /* The name of variable-size virtual chip. A 4 MiB flash example:
438 * flashrom -p dummy:emulate=VARIABLE_SIZE,size=4194304
439 */
440 if (!strcmp(tmp, "VARIABLE_SIZE")) {
Simon Glassd2c64a22013-07-03 22:05:21 +0900441 if (size == SIZE_UNKNOWN) {
Lachlan Bishopbf1476e2020-09-10 14:57:05 +1000442 msg_perr("%s: the size parameter is not given.\n", __func__);
Louis Yung-Chieh Loe53fa0f2011-04-11 17:18:41 +0800443 free(tmp);
444 return 1;
Simon Glassd2c64a22013-07-03 22:05:21 +0900445 } else if (size == SIZE_AUTO) {
446 if (image_size == SIZE_UNKNOWN) {
Lachlan Bishopbf1476e2020-09-10 14:57:05 +1000447 msg_perr("%s: no image so cannot use automatic size.\n", __func__);
Simon Glassd2c64a22013-07-03 22:05:21 +0900448 free(tmp);
449 return 1;
450 }
451 size = image_size;
Louis Yung-Chieh Loe53fa0f2011-04-11 17:18:41 +0800452 }
Lachlan Bishopbf1476e2020-09-10 14:57:05 +1000453 data->emu_chip = EMULATE_VARIABLE_SIZE;
454 data->emu_chip_size = size;
455 data->emu_max_byteprogram_size = 256;
456 data->emu_max_aai_size = 0;
457 data->emu_jedec_se_size = 4 * 1024;
458 data->emu_jedec_be_52_size = 32 * 1024;
459 data->emu_jedec_be_d8_size = 64 * 1024;
460 data->emu_jedec_ce_60_size = data->emu_chip_size;
461 data->emu_jedec_ce_c7_size = data->emu_chip_size;
Louis Yung-Chieh Loe53fa0f2011-04-11 17:18:41 +0800462 msg_pdbg("Emulating generic SPI flash chip (size=%d bytes)\n",
Lachlan Bishopbf1476e2020-09-10 14:57:05 +1000463 data->emu_chip_size);
Louis Yung-Chieh Loe53fa0f2011-04-11 17:18:41 +0800464 }
hailfinger6ead7222010-11-01 22:07:04 +0000465#endif
Lachlan Bishopbf1476e2020-09-10 14:57:05 +1000466 if (data->emu_chip == EMULATE_NONE) {
hailfinger6ead7222010-11-01 22:07:04 +0000467 msg_perr("Invalid chip specified for emulation: %s\n", tmp);
468 free(tmp);
469 return 1;
470 }
David Hendricks0eda2a82014-09-12 16:32:05 -0700471
472 /* Should emulated flash erase to zero (yes/no)? */
473 tmp = extract_programmer_param("erase_to_zero");
474 if (tmp) {
475 if (!strcmp(tmp, "yes")) {
476 msg_pdbg("Emulated chip will erase to 0x00\n");
Lachlan Bishopbf1476e2020-09-10 14:57:05 +1000477 data->erase_to_zero = 1;
David Hendricks0eda2a82014-09-12 16:32:05 -0700478 } else if (!strcmp(tmp, "no")) {
479 msg_pdbg("Emulated chip will erase to 0xff\n");
480 } else {
481 msg_perr("erase_to_zero can be \"yes\" or \"no\"\n");
482 return 1;
483 }
484 }
485
hailfinger6ead7222010-11-01 22:07:04 +0000486 free(tmp);
Lachlan Bishopbf1476e2020-09-10 14:57:05 +1000487 flashchip_contents = malloc(data->emu_chip_size);
hailfinger6ead7222010-11-01 22:07:04 +0000488 if (!flashchip_contents) {
489 msg_perr("Out of memory!\n");
490 return 1;
491 }
dhendrix0ffc2eb2011-06-14 01:35:36 +0000492
Edward O'Callaghanec8b0d92020-09-17 17:27:45 +1000493#ifdef EMULATE_SPI_CHIP
494 status = extract_programmer_param("spi_status");
495 if (status) {
496 char *endptr;
497 errno = 0;
Lachlan Bishopbf1476e2020-09-10 14:57:05 +1000498 data->emu_status = strtoul(status, &endptr, 0);
Edward O'Callaghanec8b0d92020-09-17 17:27:45 +1000499 free(status);
500 if (errno != 0 || status == endptr) {
501 msg_perr("Error: initial status register specified, "
502 "but the value could not be converted.\n");
503 return 1;
504 }
505 msg_pdbg("Initial status register is set to 0x%02x.\n",
Lachlan Bishopbf1476e2020-09-10 14:57:05 +1000506 data->emu_status);
Edward O'Callaghanec8b0d92020-09-17 17:27:45 +1000507 }
508#endif
509
Lachlan Bishopbf1476e2020-09-10 14:57:05 +1000510 msg_pdbg("Filling fake flash chip with 0x%02x, size %i\n",
511 data->erase_to_zero ? 0x00 : 0xff, data->emu_chip_size);
512 memset(flashchip_contents, data->erase_to_zero ? 0x00 : 0xff, data->emu_chip_size);
513
514 /* Will be freed by shutdown function if necessary. */
515 if (!data->emu_persistent_image) {
hailfinger6ead7222010-11-01 22:07:04 +0000516 /* Nothing else to do. */
dhendrix0ffc2eb2011-06-14 01:35:36 +0000517 goto dummy_init_out;
hailfinger6ead7222010-11-01 22:07:04 +0000518 }
Edward O'Callaghanec8b0d92020-09-17 17:27:45 +1000519
520 /* We will silently (in default verbosity) ignore the file if it does not exist (yet) or the size does
521 * not match the emulated chip. */
Lachlan Bishopbf1476e2020-09-10 14:57:05 +1000522 if (!stat(data->emu_persistent_image, &image_stat)) {
Edward O'Callaghanec8b0d92020-09-17 17:27:45 +1000523 msg_pdbg("Found persistent image %s, %jd B ",
Lachlan Bishopbf1476e2020-09-10 14:57:05 +1000524 data->emu_persistent_image, (intmax_t)image_stat.st_size);
525 if ((uintmax_t)image_stat.st_size == data->emu_chip_size) {
hailfinger6ead7222010-11-01 22:07:04 +0000526 msg_pdbg("matches.\n");
Lachlan Bishopbf1476e2020-09-10 14:57:05 +1000527 msg_pdbg("Reading %s\n", data->emu_persistent_image);
528 if (read_buf_from_file(flashchip_contents, data->emu_chip_size,
529 data->emu_persistent_image)) {
530 msg_perr("Unable to read %s\n", data->emu_persistent_image);
Edward O'Callaghanec8b0d92020-09-17 17:27:45 +1000531 free(flashchip_contents);
532 return 1;
533 }
hailfinger6ead7222010-11-01 22:07:04 +0000534 } else {
535 msg_pdbg("doesn't match.\n");
536 }
537 }
538#endif
hailfingera9df33c2009-05-09 00:54:55 +0000539
dhendrix0ffc2eb2011-06-14 01:35:36 +0000540dummy_init_out:
Lachlan Bishopbf1476e2020-09-10 14:57:05 +1000541 if (register_shutdown(dummy_shutdown, data)) {
hailfinger6ead7222010-11-01 22:07:04 +0000542 free(flashchip_contents);
Lachlan Bishopbf1476e2020-09-10 14:57:05 +1000543 free(data);
dhendrix0ffc2eb2011-06-14 01:35:36 +0000544 return 1;
hailfinger6ead7222010-11-01 22:07:04 +0000545 }
hailfinger76bb7e92011-11-09 23:40:00 +0000546 if (dummy_buses_supported & (BUS_PARALLEL | BUS_LPC | BUS_FWH))
Patrick Georgi0a9533a2017-02-03 19:28:38 +0100547 register_par_master(&par_master_dummy,
Stuart langleyc98e43f2020-03-26 20:27:36 +1100548 dummy_buses_supported & (BUS_PARALLEL | BUS_LPC | BUS_FWH));
hailfinger76bb7e92011-11-09 23:40:00 +0000549 if (dummy_buses_supported & BUS_SPI)
Patrick Georgif4f1e2f2017-03-10 17:38:40 +0100550 register_spi_master(&spi_master_dummyflasher);
hailfinger76bb7e92011-11-09 23:40:00 +0000551
hailfingera9df33c2009-05-09 00:54:55 +0000552 return 0;
553}
554
Patrick Georgi4befc162017-02-03 18:32:01 +0100555void *dummy_map(const char *descr, uintptr_t phys_addr, size_t len)
hailfinger11ae3c42009-05-11 14:13:25 +0000556{
Stuart langleyc98e43f2020-03-26 20:27:36 +1100557 msg_pspew("%s: Mapping %s, 0x%zx bytes at 0x%0*" PRIxPTR "\n",
558 __func__, descr, len, PRIxPTR_WIDTH, phys_addr);
hailfinger11ae3c42009-05-11 14:13:25 +0000559 return (void *)phys_addr;
560}
561
562void dummy_unmap(void *virt_addr, size_t len)
563{
Stuart langleyc98e43f2020-03-26 20:27:36 +1100564 msg_pspew("%s: Unmapping 0x%zx bytes at %p\n", __func__, len, virt_addr);
hailfinger11ae3c42009-05-11 14:13:25 +0000565}
566
Stuart langleyc98e43f2020-03-26 20:27:36 +1100567static void dummy_chip_writeb(const struct flashctx *flash, uint8_t val, chipaddr addr)
hailfingera9df33c2009-05-09 00:54:55 +0000568{
Kangheui Won4974cc12019-10-18 12:59:01 +1100569 msg_pspew("%s: addr=0x%" PRIxPTR ", val=0x%02x\n", __func__, addr, val);
hailfingera9df33c2009-05-09 00:54:55 +0000570}
571
Stuart langleyc98e43f2020-03-26 20:27:36 +1100572static void dummy_chip_writew(const struct flashctx *flash, uint16_t val, chipaddr addr)
hailfingera9df33c2009-05-09 00:54:55 +0000573{
Kangheui Won4974cc12019-10-18 12:59:01 +1100574 msg_pspew("%s: addr=0x%" PRIxPTR ", val=0x%04x\n", __func__, addr, val);
hailfingera9df33c2009-05-09 00:54:55 +0000575}
576
Stuart langleyc98e43f2020-03-26 20:27:36 +1100577static void dummy_chip_writel(const struct flashctx *flash, uint32_t val, chipaddr addr)
hailfingera9df33c2009-05-09 00:54:55 +0000578{
Kangheui Won4974cc12019-10-18 12:59:01 +1100579 msg_pspew("%s: addr=0x%" PRIxPTR ", val=0x%08x\n", __func__, addr, val);
hailfingera9df33c2009-05-09 00:54:55 +0000580}
581
Stuart langleyc98e43f2020-03-26 20:27:36 +1100582static void dummy_chip_writen(const struct flashctx *flash, const uint8_t *buf, chipaddr addr, size_t len)
hailfinger9d987ef2009-06-05 18:32:07 +0000583{
584 size_t i;
Stuart langleyc98e43f2020-03-26 20:27:36 +1100585 msg_pspew("%s: addr=0x%" PRIxPTR ", len=0x%zx, writing data (hex):", __func__, addr, len);
hailfinger9d987ef2009-06-05 18:32:07 +0000586 for (i = 0; i < len; i++) {
587 if ((i % 16) == 0)
hailfinger50c335f2010-01-09 04:32:23 +0000588 msg_pspew("\n");
589 msg_pspew("%02x ", buf[i]);
hailfinger9d987ef2009-06-05 18:32:07 +0000590 }
591}
592
Stuart langleyc98e43f2020-03-26 20:27:36 +1100593static uint8_t dummy_chip_readb(const struct flashctx *flash, const chipaddr addr)
hailfingera9df33c2009-05-09 00:54:55 +0000594{
Kangheui Won4974cc12019-10-18 12:59:01 +1100595 msg_pspew("%s: addr=0x%" PRIxPTR ", returning 0xff\n", __func__, addr);
hailfingera9df33c2009-05-09 00:54:55 +0000596 return 0xff;
597}
598
Stuart langleyc98e43f2020-03-26 20:27:36 +1100599static uint16_t dummy_chip_readw(const struct flashctx *flash, const chipaddr addr)
hailfingera9df33c2009-05-09 00:54:55 +0000600{
Kangheui Won4974cc12019-10-18 12:59:01 +1100601 msg_pspew("%s: addr=0x%" PRIxPTR ", returning 0xffff\n", __func__, addr);
hailfingera9df33c2009-05-09 00:54:55 +0000602 return 0xffff;
603}
604
Stuart langleyc98e43f2020-03-26 20:27:36 +1100605static uint32_t dummy_chip_readl(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 0xffffffff\n", __func__, addr);
hailfingera9df33c2009-05-09 00:54:55 +0000608 return 0xffffffff;
609}
610
Stuart langleyc98e43f2020-03-26 20:27:36 +1100611static void dummy_chip_readn(const struct flashctx *flash, uint8_t *buf, const chipaddr addr, size_t len)
hailfinger9d987ef2009-06-05 18:32:07 +0000612{
Stuart langleyc98e43f2020-03-26 20:27:36 +1100613 msg_pspew("%s: addr=0x%" PRIxPTR ", len=0x%zx, returning array of 0xff\n", __func__, addr, len);
hailfinger9d987ef2009-06-05 18:32:07 +0000614 memset(buf, 0xff, len);
615 return;
616}
617
hailfinger6ead7222010-11-01 22:07:04 +0000618#if EMULATE_SPI_CHIP
Edward O'Callaghanec8b0d92020-09-17 17:27:45 +1000619static int emulate_spi_chip_response(unsigned int writecnt,
620 unsigned int readcnt,
621 const unsigned char *writearr,
Lachlan Bishopbf1476e2020-09-10 14:57:05 +1000622 unsigned char *readarr,
623 struct emu_data *data)
hailfinger6ead7222010-11-01 22:07:04 +0000624{
Stuart Langley78cacf72020-04-23 11:48:01 +1000625 unsigned int offs, i, toread;
stefanctc5eb8a92011-11-23 09:13:48 +0000626 static int unsigned aai_offs;
Carl-Daniel Hailfinger7a4c0472012-08-30 21:41:00 +0000627 const unsigned char sst25vf040_rems_response[2] = {0xbf, 0x44};
628 const unsigned char sst25vf032b_rems_response[2] = {0xbf, 0x4a};
629 const unsigned char mx25l6436_rems_response[2] = {0xc2, 0x16};
Edward O'Callaghanec8b0d92020-09-17 17:27:45 +1000630 const unsigned char w25q128fv_rems_response[2] = {0xef, 0x17};
hailfinger6ead7222010-11-01 22:07:04 +0000631
632 if (writecnt == 0) {
633 msg_perr("No command sent to the chip!\n");
634 return 1;
635 }
Stefan Tauner718d1eb2016-08-18 18:00:53 -0700636 /* spi_blacklist has precedence over spi_ignorelist. */
Lachlan Bishopbf1476e2020-09-10 14:57:05 +1000637 for (i = 0; i < data->spi_blacklist_size; i++) {
638 if (writearr[0] == data->spi_blacklist[i]) {
Carl-Daniel Hailfingerc49783d2016-08-05 10:52:06 -0700639 msg_pdbg("Refusing blacklisted SPI command 0x%02x\n",
Lachlan Bishopbf1476e2020-09-10 14:57:05 +1000640 data->spi_blacklist[i]);
Carl-Daniel Hailfingerc49783d2016-08-05 10:52:06 -0700641 return SPI_INVALID_OPCODE;
642 }
643 }
Lachlan Bishopbf1476e2020-09-10 14:57:05 +1000644 for (i = 0; i < data->spi_ignorelist_size; i++) {
645 if (writearr[0] == data->spi_ignorelist[i]) {
Carl-Daniel Hailfingerc49783d2016-08-05 10:52:06 -0700646 msg_cdbg("Ignoring ignorelisted SPI command 0x%02x\n",
Lachlan Bishopbf1476e2020-09-10 14:57:05 +1000647 data->spi_ignorelist[i]);
Carl-Daniel Hailfingerc49783d2016-08-05 10:52:06 -0700648 /* Return success because the command does not fail,
649 * it is simply ignored.
650 */
651 return 0;
652 }
653 }
Edward O'Callaghanec8b0d92020-09-17 17:27:45 +1000654
Lachlan Bishopbf1476e2020-09-10 14:57:05 +1000655 if (data->emu_max_aai_size && (data->emu_status & SPI_SR_AAI)) {
Edward O'Callaghanec8b0d92020-09-17 17:27:45 +1000656 if (writearr[0] != JEDEC_AAI_WORD_PROGRAM &&
657 writearr[0] != JEDEC_WRDI &&
658 writearr[0] != JEDEC_RDSR) {
659 msg_perr("Forbidden opcode (0x%02x) attempted during "
660 "AAI sequence!\n", writearr[0]);
661 return 0;
662 }
663 }
664
hailfinger6ead7222010-11-01 22:07:04 +0000665 switch (writearr[0]) {
666 case JEDEC_RES:
Carl-Daniel Hailfinger7a4c0472012-08-30 21:41:00 +0000667 if (writecnt < JEDEC_RES_OUTSIZE)
hailfinger6ead7222010-11-01 22:07:04 +0000668 break;
Carl-Daniel Hailfinger7a4c0472012-08-30 21:41:00 +0000669 /* offs calculation is only needed for SST chips which treat RES like REMS. */
670 offs = writearr[1] << 16 | writearr[2] << 8 | writearr[3];
671 offs += writecnt - JEDEC_REMS_OUTSIZE;
Lachlan Bishopbf1476e2020-09-10 14:57:05 +1000672 switch (data->emu_chip) {
Carl-Daniel Hailfinger7a4c0472012-08-30 21:41:00 +0000673 case EMULATE_ST_M25P10_RES:
674 if (readcnt > 0)
675 memset(readarr, 0x10, readcnt);
676 break;
677 case EMULATE_SST_SST25VF040_REMS:
678 for (i = 0; i < readcnt; i++)
679 readarr[i] = sst25vf040_rems_response[(offs + i) % 2];
680 break;
681 case EMULATE_SST_SST25VF032B:
682 for (i = 0; i < readcnt; i++)
683 readarr[i] = sst25vf032b_rems_response[(offs + i) % 2];
684 break;
685 case EMULATE_MACRONIX_MX25L6436:
686 if (readcnt > 0)
687 memset(readarr, 0x16, readcnt);
688 break;
Edward O'Callaghanec8b0d92020-09-17 17:27:45 +1000689 case EMULATE_WINBOND_W25Q128FV:
690 if (readcnt > 0)
691 memset(readarr, 0x17, readcnt);
692 break;
Carl-Daniel Hailfinger7a4c0472012-08-30 21:41:00 +0000693 default: /* ignore */
694 break;
695 }
hailfinger6ead7222010-11-01 22:07:04 +0000696 break;
697 case JEDEC_REMS:
Carl-Daniel Hailfinger7a4c0472012-08-30 21:41:00 +0000698 /* REMS response has wraparound and uses an address parameter. */
699 if (writecnt < JEDEC_REMS_OUTSIZE)
hailfinger6ead7222010-11-01 22:07:04 +0000700 break;
Carl-Daniel Hailfinger7a4c0472012-08-30 21:41:00 +0000701 offs = writearr[1] << 16 | writearr[2] << 8 | writearr[3];
702 offs += writecnt - JEDEC_REMS_OUTSIZE;
Lachlan Bishopbf1476e2020-09-10 14:57:05 +1000703 switch (data->emu_chip) {
Carl-Daniel Hailfinger7a4c0472012-08-30 21:41:00 +0000704 case EMULATE_SST_SST25VF040_REMS:
705 for (i = 0; i < readcnt; i++)
706 readarr[i] = sst25vf040_rems_response[(offs + i) % 2];
707 break;
708 case EMULATE_SST_SST25VF032B:
709 for (i = 0; i < readcnt; i++)
710 readarr[i] = sst25vf032b_rems_response[(offs + i) % 2];
711 break;
712 case EMULATE_MACRONIX_MX25L6436:
713 for (i = 0; i < readcnt; i++)
714 readarr[i] = mx25l6436_rems_response[(offs + i) % 2];
715 break;
Edward O'Callaghanec8b0d92020-09-17 17:27:45 +1000716 case EMULATE_WINBOND_W25Q128FV:
717 for (i = 0; i < readcnt; i++)
718 readarr[i] = w25q128fv_rems_response[(offs + i) % 2];
719 break;
Carl-Daniel Hailfinger7a4c0472012-08-30 21:41:00 +0000720 default: /* ignore */
721 break;
722 }
hailfinger6ead7222010-11-01 22:07:04 +0000723 break;
724 case JEDEC_RDID:
Lachlan Bishopbf1476e2020-09-10 14:57:05 +1000725 switch (data->emu_chip) {
Stuart Langley78cacf72020-04-23 11:48:01 +1000726 case EMULATE_SST_SST25VF032B:
Louis Yung-Chieh Loe53fa0f2011-04-11 17:18:41 +0800727 if (readcnt > 0)
728 readarr[0] = 0xbf;
729 if (readcnt > 1)
730 readarr[1] = 0x25;
731 if (readcnt > 2)
732 readarr[2] = 0x4a;
Stuart Langley78cacf72020-04-23 11:48:01 +1000733 break;
734 case EMULATE_MACRONIX_MX25L6436:
735 if (readcnt > 0)
736 readarr[0] = 0xc2;
737 if (readcnt > 1)
738 readarr[1] = 0x20;
739 if (readcnt > 2)
740 readarr[2] = 0x17;
741 break;
Edward O'Callaghanec8b0d92020-09-17 17:27:45 +1000742 case EMULATE_WINBOND_W25Q128FV:
743 if (readcnt > 0)
744 readarr[0] = 0xef;
745 if (readcnt > 1)
746 readarr[1] = 0x40;
747 if (readcnt > 2)
748 readarr[2] = 0x18;
749 break;
Edward O'Callaghane0772312020-09-16 17:57:19 +1000750 case EMULATE_VARIABLE_SIZE:
751 if (readcnt > 0)
752 readarr[0] = (PROGMANUF_ID >> 8) & 0xff;
753 if (readcnt > 1)
754 readarr[1] = PROGMANUF_ID & 0xff;
755 if (readcnt > 2)
756 readarr[2] = (PROGDEV_ID >> 8) & 0xff;
757 if (readcnt > 3)
758 readarr[3] = PROGDEV_ID & 0xff;
Stuart Langley78cacf72020-04-23 11:48:01 +1000759 break;
Stuart Langley78cacf72020-04-23 11:48:01 +1000760 default: /* ignore */
761 break;
Louis Yung-Chieh Loe53fa0f2011-04-11 17:18:41 +0800762 }
hailfinger6ead7222010-11-01 22:07:04 +0000763 break;
764 case JEDEC_RDSR:
Lachlan Bishopbf1476e2020-09-10 14:57:05 +1000765 memset(readarr, data->emu_status, readcnt);
Edward O'Callaghanec8b0d92020-09-17 17:27:45 +1000766 break;
767 /* FIXME: this should be chip-specific. */
768 case JEDEC_EWSR:
769 case JEDEC_WREN:
Lachlan Bishopbf1476e2020-09-10 14:57:05 +1000770 data->emu_status |= SPI_SR_WEL;
Edward O'Callaghanec8b0d92020-09-17 17:27:45 +1000771 break;
772 case JEDEC_WRSR:
Lachlan Bishopbf1476e2020-09-10 14:57:05 +1000773 if (!(data->emu_status & SPI_SR_WEL)) {
Edward O'Callaghanec8b0d92020-09-17 17:27:45 +1000774 msg_perr("WRSR attempted, but WEL is 0!\n");
775 break;
776 }
777 /* FIXME: add some reasonable simulation of the busy flag */
Lachlan Bishopbf1476e2020-09-10 14:57:05 +1000778 data->emu_status = writearr[1] & ~SPI_SR_WIP;
779 msg_pdbg2("WRSR wrote 0x%02x.\n", data->emu_status);
hailfinger6ead7222010-11-01 22:07:04 +0000780 break;
781 case JEDEC_READ:
782 offs = writearr[1] << 16 | writearr[2] << 8 | writearr[3];
783 /* Truncate to emu_chip_size. */
Lachlan Bishopbf1476e2020-09-10 14:57:05 +1000784 offs %= data->emu_chip_size;
hailfinger6ead7222010-11-01 22:07:04 +0000785 if (readcnt > 0)
786 memcpy(readarr, flashchip_contents + offs, readcnt);
787 break;
Namyoon Woob71a2962020-08-27 16:27:49 -0700788 case JEDEC_READ_4BA:
789 offs = writearr[1] << 24 | writearr[2] << 16 | writearr[3] << 8 | writearr[4];
790 /* Truncate to emu_chip_size. */
Lachlan Bishopbf1476e2020-09-10 14:57:05 +1000791 offs %= data->emu_chip_size;
Namyoon Woob71a2962020-08-27 16:27:49 -0700792 if (readcnt > 0)
793 memcpy(readarr, flashchip_contents + offs, readcnt);
794 break;
hailfinger6ead7222010-11-01 22:07:04 +0000795 case JEDEC_BYTE_PROGRAM:
796 offs = writearr[1] << 16 | writearr[2] << 8 | writearr[3];
797 /* Truncate to emu_chip_size. */
Lachlan Bishopbf1476e2020-09-10 14:57:05 +1000798 offs %= data->emu_chip_size;
hailfinger6ead7222010-11-01 22:07:04 +0000799 if (writecnt < 5) {
800 msg_perr("BYTE PROGRAM size too short!\n");
801 return 1;
802 }
Lachlan Bishopbf1476e2020-09-10 14:57:05 +1000803 if (writecnt - 4 > data->emu_max_byteprogram_size) {
hailfinger6ead7222010-11-01 22:07:04 +0000804 msg_perr("Max BYTE PROGRAM size exceeded!\n");
805 return 1;
806 }
807 memcpy(flashchip_contents + offs, writearr + 4, writecnt - 4);
Lachlan Bishopbf1476e2020-09-10 14:57:05 +1000808 data->emu_modified = 1;
hailfinger6ead7222010-11-01 22:07:04 +0000809 break;
Namyoon Woob71a2962020-08-27 16:27:49 -0700810 case JEDEC_BYTE_PROGRAM_4BA:
811 offs = writearr[1] << 24 | writearr[2] << 16 | writearr[3] << 8 | writearr[4];
812 /* Truncate to emu_chip_size. */
Lachlan Bishopbf1476e2020-09-10 14:57:05 +1000813 offs %= data->emu_chip_size;
Namyoon Woob71a2962020-08-27 16:27:49 -0700814 if (writecnt < 6) {
815 msg_perr("BYTE PROGRAM size too short!\n");
816 return 1;
817 }
Lachlan Bishopbf1476e2020-09-10 14:57:05 +1000818 if (writecnt - 5 > data->emu_max_byteprogram_size) {
Namyoon Woob71a2962020-08-27 16:27:49 -0700819 msg_perr("Max BYTE PROGRAM size exceeded!\n");
820 return 1;
821 }
822 memcpy(flashchip_contents + offs, writearr + 5, writecnt - 5);
Lachlan Bishopbf1476e2020-09-10 14:57:05 +1000823 data->emu_modified = 1;
Namyoon Woob71a2962020-08-27 16:27:49 -0700824 break;
hailfinger6ead7222010-11-01 22:07:04 +0000825 case JEDEC_AAI_WORD_PROGRAM:
Lachlan Bishopbf1476e2020-09-10 14:57:05 +1000826 if (!data->emu_max_aai_size)
hailfinger6ead7222010-11-01 22:07:04 +0000827 break;
Lachlan Bishopbf1476e2020-09-10 14:57:05 +1000828 if (!(data->emu_status & SPI_SR_AAI)) {
hailfinger6ead7222010-11-01 22:07:04 +0000829 if (writecnt < JEDEC_AAI_WORD_PROGRAM_OUTSIZE) {
830 msg_perr("Initial AAI WORD PROGRAM size too "
831 "short!\n");
832 return 1;
833 }
834 if (writecnt > JEDEC_AAI_WORD_PROGRAM_OUTSIZE) {
835 msg_perr("Initial AAI WORD PROGRAM size too "
836 "long!\n");
837 return 1;
838 }
Lachlan Bishopbf1476e2020-09-10 14:57:05 +1000839 data->emu_status |= SPI_SR_AAI;
hailfinger6ead7222010-11-01 22:07:04 +0000840 aai_offs = writearr[1] << 16 | writearr[2] << 8 |
841 writearr[3];
842 /* Truncate to emu_chip_size. */
Lachlan Bishopbf1476e2020-09-10 14:57:05 +1000843 aai_offs %= data->emu_chip_size;
hailfinger6ead7222010-11-01 22:07:04 +0000844 memcpy(flashchip_contents + aai_offs, writearr + 4, 2);
845 aai_offs += 2;
846 } else {
847 if (writecnt < JEDEC_AAI_WORD_PROGRAM_CONT_OUTSIZE) {
848 msg_perr("Continuation AAI WORD PROGRAM size "
849 "too short!\n");
850 return 1;
851 }
852 if (writecnt > JEDEC_AAI_WORD_PROGRAM_CONT_OUTSIZE) {
853 msg_perr("Continuation AAI WORD PROGRAM size "
854 "too long!\n");
855 return 1;
856 }
857 memcpy(flashchip_contents + aai_offs, writearr + 1, 2);
858 aai_offs += 2;
859 }
Lachlan Bishopbf1476e2020-09-10 14:57:05 +1000860 data->emu_modified = 1;
hailfinger6ead7222010-11-01 22:07:04 +0000861 break;
862 case JEDEC_WRDI:
Lachlan Bishopbf1476e2020-09-10 14:57:05 +1000863 if (data->emu_max_aai_size)
864 data->emu_status &= ~SPI_SR_AAI;
hailfinger6ead7222010-11-01 22:07:04 +0000865 break;
866 case JEDEC_SE:
Lachlan Bishopbf1476e2020-09-10 14:57:05 +1000867 if (!data->emu_jedec_se_size)
hailfinger6ead7222010-11-01 22:07:04 +0000868 break;
869 if (writecnt != JEDEC_SE_OUTSIZE) {
870 msg_perr("SECTOR ERASE 0x20 outsize invalid!\n");
871 return 1;
872 }
873 if (readcnt != JEDEC_SE_INSIZE) {
874 msg_perr("SECTOR ERASE 0x20 insize invalid!\n");
875 return 1;
876 }
877 offs = writearr[1] << 16 | writearr[2] << 8 | writearr[3];
Lachlan Bishopbf1476e2020-09-10 14:57:05 +1000878 if (offs & (data->emu_jedec_se_size - 1))
hailfingere53f5e42011-02-04 22:52:04 +0000879 msg_pdbg("Unaligned SECTOR ERASE 0x20: 0x%x\n", offs);
Lachlan Bishopbf1476e2020-09-10 14:57:05 +1000880 offs &= ~(data->emu_jedec_se_size - 1);
881 memset(flashchip_contents + offs, 0xff, data->emu_jedec_se_size);
882 data->emu_modified = 1;
hailfinger6ead7222010-11-01 22:07:04 +0000883 break;
884 case JEDEC_BE_52:
Lachlan Bishopbf1476e2020-09-10 14:57:05 +1000885 if (!data->emu_jedec_be_52_size)
hailfinger6ead7222010-11-01 22:07:04 +0000886 break;
887 if (writecnt != JEDEC_BE_52_OUTSIZE) {
888 msg_perr("BLOCK ERASE 0x52 outsize invalid!\n");
889 return 1;
890 }
891 if (readcnt != JEDEC_BE_52_INSIZE) {
892 msg_perr("BLOCK ERASE 0x52 insize invalid!\n");
893 return 1;
894 }
895 offs = writearr[1] << 16 | writearr[2] << 8 | writearr[3];
Lachlan Bishopbf1476e2020-09-10 14:57:05 +1000896 if (offs & (data->emu_jedec_be_52_size - 1))
hailfingere53f5e42011-02-04 22:52:04 +0000897 msg_pdbg("Unaligned BLOCK ERASE 0x52: 0x%x\n", offs);
Lachlan Bishopbf1476e2020-09-10 14:57:05 +1000898 offs &= ~(data->emu_jedec_be_52_size - 1);
899 memset(flashchip_contents + offs, 0xff, data->emu_jedec_be_52_size);
900 data->emu_modified = 1;
hailfinger6ead7222010-11-01 22:07:04 +0000901 break;
902 case JEDEC_BE_D8:
Lachlan Bishopbf1476e2020-09-10 14:57:05 +1000903 if (!data->emu_jedec_be_d8_size)
hailfinger6ead7222010-11-01 22:07:04 +0000904 break;
905 if (writecnt != JEDEC_BE_D8_OUTSIZE) {
906 msg_perr("BLOCK ERASE 0xd8 outsize invalid!\n");
907 return 1;
908 }
909 if (readcnt != JEDEC_BE_D8_INSIZE) {
910 msg_perr("BLOCK ERASE 0xd8 insize invalid!\n");
911 return 1;
912 }
913 offs = writearr[1] << 16 | writearr[2] << 8 | writearr[3];
Lachlan Bishopbf1476e2020-09-10 14:57:05 +1000914 if (offs & (data->emu_jedec_be_d8_size - 1))
hailfingere53f5e42011-02-04 22:52:04 +0000915 msg_pdbg("Unaligned BLOCK ERASE 0xd8: 0x%x\n", offs);
Lachlan Bishopbf1476e2020-09-10 14:57:05 +1000916 offs &= ~(data->emu_jedec_be_d8_size - 1);
917 memset(flashchip_contents + offs, 0xff, data->emu_jedec_be_d8_size);
918 data->emu_modified = 1;
hailfinger6ead7222010-11-01 22:07:04 +0000919 break;
920 case JEDEC_CE_60:
Lachlan Bishopbf1476e2020-09-10 14:57:05 +1000921 if (!data->emu_jedec_ce_60_size)
hailfinger6ead7222010-11-01 22:07:04 +0000922 break;
923 if (writecnt != JEDEC_CE_60_OUTSIZE) {
924 msg_perr("CHIP ERASE 0x60 outsize invalid!\n");
925 return 1;
926 }
927 if (readcnt != JEDEC_CE_60_INSIZE) {
928 msg_perr("CHIP ERASE 0x60 insize invalid!\n");
929 return 1;
930 }
hailfingere53f5e42011-02-04 22:52:04 +0000931 /* JEDEC_CE_60_OUTSIZE is 1 (no address) -> no offset. */
hailfinger6ead7222010-11-01 22:07:04 +0000932 /* emu_jedec_ce_60_size is emu_chip_size. */
Lachlan Bishopbf1476e2020-09-10 14:57:05 +1000933 memset(flashchip_contents, 0xff, data->emu_jedec_ce_60_size);
934 data->emu_modified = 1;
hailfinger6ead7222010-11-01 22:07:04 +0000935 break;
936 case JEDEC_CE_C7:
Lachlan Bishopbf1476e2020-09-10 14:57:05 +1000937 if (!data->emu_jedec_ce_c7_size)
hailfinger6ead7222010-11-01 22:07:04 +0000938 break;
939 if (writecnt != JEDEC_CE_C7_OUTSIZE) {
940 msg_perr("CHIP ERASE 0xc7 outsize invalid!\n");
941 return 1;
942 }
943 if (readcnt != JEDEC_CE_C7_INSIZE) {
944 msg_perr("CHIP ERASE 0xc7 insize invalid!\n");
945 return 1;
946 }
hailfingere53f5e42011-02-04 22:52:04 +0000947 /* JEDEC_CE_C7_OUTSIZE is 1 (no address) -> no offset. */
hailfinger6ead7222010-11-01 22:07:04 +0000948 /* emu_jedec_ce_c7_size is emu_chip_size. */
Lachlan Bishopbf1476e2020-09-10 14:57:05 +1000949 memset(flashchip_contents, 0xff, data->emu_jedec_ce_c7_size);
950 data->emu_modified = 1;
hailfinger6ead7222010-11-01 22:07:04 +0000951 break;
Stuart Langley78cacf72020-04-23 11:48:01 +1000952 case JEDEC_SFDP:
Lachlan Bishopbf1476e2020-09-10 14:57:05 +1000953 if (data->emu_chip != EMULATE_MACRONIX_MX25L6436)
Stuart Langley78cacf72020-04-23 11:48:01 +1000954 break;
955 if (writecnt < 4)
956 break;
957 offs = writearr[1] << 16 | writearr[2] << 8 | writearr[3];
958
959 /* SFDP expects one dummy byte after the address. */
960 if (writecnt == 4) {
961 /* The dummy byte was not written, make sure it is read instead.
962 * Shifting and shortening the read array does achieve this goal.
963 */
964 readarr++;
965 readcnt--;
966 } else {
967 /* The response is shifted if more than 5 bytes are written, because SFDP data is
968 * already shifted out by the chip while those superfluous bytes are written. */
969 offs += writecnt - 5;
970 }
971
972 /* The SFDP spec implies that the start address of an SFDP read may be truncated to fit in the
973 * SFDP table address space, i.e. the start address may be wrapped around at SFDP table size.
974 * This is a reasonable implementation choice in hardware because it saves a few gates. */
975 if (offs >= sizeof(sfdp_table)) {
976 msg_pdbg("Wrapping the start address around the SFDP table boundary (using 0x%x "
977 "instead of 0x%x).\n", (unsigned int)(offs % sizeof(sfdp_table)), offs);
978 offs %= sizeof(sfdp_table);
979 }
980 toread = min(sizeof(sfdp_table) - offs, readcnt);
981 memcpy(readarr, sfdp_table + offs, toread);
982 if (toread < readcnt)
983 msg_pdbg("Crossing the SFDP table boundary in a single "
984 "continuous chunk produces undefined results "
985 "after that point.\n");
986 break;
hailfinger6ead7222010-11-01 22:07:04 +0000987 default:
988 /* No special response. */
989 break;
990 }
Edward O'Callaghanec8b0d92020-09-17 17:27:45 +1000991 if (writearr[0] != JEDEC_WREN && writearr[0] != JEDEC_EWSR)
Lachlan Bishopbf1476e2020-09-10 14:57:05 +1000992 data->emu_status &= ~SPI_SR_WEL;
hailfinger6ead7222010-11-01 22:07:04 +0000993 return 0;
994}
995#endif
996
Lachlan Bishopbf1476e2020-09-10 14:57:05 +1000997static struct emu_data* get_data_from_context(const struct flashctx *flash)
998{
999 if (dummy_buses_supported & (BUS_PARALLEL | BUS_LPC | BUS_FWH))
1000 return (struct emu_data *)flash->mst->par.data;
1001 else if (dummy_buses_supported & BUS_SPI)
1002 return (struct emu_data *)flash->mst->spi.data;
1003
1004 return NULL; /* buses was set to BUS_NONE. */
1005}
1006
Stuart langleyc98e43f2020-03-26 20:27:36 +11001007static int dummy_spi_send_command(const struct flashctx *flash, unsigned int writecnt,
1008 unsigned int readcnt,
1009 const unsigned char *writearr,
1010 unsigned char *readarr)
hailfingerf91e3b52009-05-14 12:59:36 +00001011{
Edward O'Callaghanec8b0d92020-09-17 17:27:45 +10001012 unsigned int i;
Lachlan Bishopbf1476e2020-09-10 14:57:05 +10001013 struct emu_data *emu_data = get_data_from_context(flash);
1014 if (!emu_data) {
1015 msg_perr("No data in flash context!\n");
1016 return 1;
1017 }
hailfingerf91e3b52009-05-14 12:59:36 +00001018
hailfinger50c335f2010-01-09 04:32:23 +00001019 msg_pspew("%s:", __func__);
hailfingerf91e3b52009-05-14 12:59:36 +00001020
hailfinger50c335f2010-01-09 04:32:23 +00001021 msg_pspew(" writing %u bytes:", writecnt);
hailfingerf91e3b52009-05-14 12:59:36 +00001022 for (i = 0; i < writecnt; i++)
hailfinger50c335f2010-01-09 04:32:23 +00001023 msg_pspew(" 0x%02x", writearr[i]);
hailfingerf91e3b52009-05-14 12:59:36 +00001024
hailfinger6ead7222010-11-01 22:07:04 +00001025 /* Response for unknown commands and missing chip is 0xff. */
1026 memset(readarr, 0xff, readcnt);
1027#if EMULATE_SPI_CHIP
Lachlan Bishopbf1476e2020-09-10 14:57:05 +10001028 switch (emu_data->emu_chip) {
hailfinger6ead7222010-11-01 22:07:04 +00001029 case EMULATE_ST_M25P10_RES:
1030 case EMULATE_SST_SST25VF040_REMS:
1031 case EMULATE_SST_SST25VF032B:
Stuart Langley78cacf72020-04-23 11:48:01 +10001032 case EMULATE_MACRONIX_MX25L6436:
Edward O'Callaghanec8b0d92020-09-17 17:27:45 +10001033 case EMULATE_WINBOND_W25Q128FV:
Louis Yung-Chieh Loe53fa0f2011-04-11 17:18:41 +08001034 case EMULATE_VARIABLE_SIZE:
Edward O'Callaghanec8b0d92020-09-17 17:27:45 +10001035 if (emulate_spi_chip_response(writecnt, readcnt, writearr,
Lachlan Bishopbf1476e2020-09-10 14:57:05 +10001036 readarr, emu_data)) {
Carl-Daniel Hailfingerc49783d2016-08-05 10:52:06 -07001037 msg_pdbg("Invalid command sent to flash chip!\n");
hailfinger6ead7222010-11-01 22:07:04 +00001038 return 1;
1039 }
1040 break;
1041 default:
1042 break;
1043 }
1044#endif
hailfinger50c335f2010-01-09 04:32:23 +00001045 msg_pspew(" reading %u bytes:", readcnt);
uwe8d342eb2011-07-28 08:13:25 +00001046 for (i = 0; i < readcnt; i++)
hailfinger6ead7222010-11-01 22:07:04 +00001047 msg_pspew(" 0x%02x", readarr[i]);
hailfinger50c335f2010-01-09 04:32:23 +00001048 msg_pspew("\n");
David Hendricks84377002014-09-09 16:09:31 -07001049
Edward O'Callaghan0037f452020-09-17 13:32:00 +10001050 programmer_delay((writecnt + readcnt) * emu_data->delay_us);
hailfingerf91e3b52009-05-14 12:59:36 +00001051 return 0;
1052}
hailfingera8727712010-06-20 10:58:32 +00001053
Stuart langleyc98e43f2020-03-26 20:27:36 +11001054static int dummy_spi_write_256(struct flashctx *flash, const uint8_t *buf, unsigned int start, unsigned int len)
hailfingerc7d06c62010-07-14 16:19:05 +00001055{
hailfinger6ead7222010-11-01 22:07:04 +00001056 return spi_write_chunked(flash, buf, start, len,
1057 spi_write_256_chunksize);
hailfingerc7d06c62010-07-14 16:19:05 +00001058}
Louis Yung-Chieh Loe53fa0f2011-04-11 17:18:41 +08001059
1060#if EMULATE_CHIP && EMULATE_SPI_CHIP
Souvik Ghoshd75cd672016-06-17 14:21:39 -07001061int probe_variable_size(struct flashctx *flash)
Louis Yung-Chieh Loe53fa0f2011-04-11 17:18:41 +08001062{
Edward O'Callaghanec8b0d92020-09-17 17:27:45 +10001063 unsigned int i;
Lachlan Bishopbf1476e2020-09-10 14:57:05 +10001064 const struct emu_data *emu_data = get_data_from_context(flash);
Louis Yung-Chieh Loe53fa0f2011-04-11 17:18:41 +08001065
1066 /* Skip the probing if we don't emulate this chip. */
Angel Pons7971a732020-10-17 15:20:27 +02001067 if (!emu_data || emu_data->emu_chip != EMULATE_VARIABLE_SIZE)
Louis Yung-Chieh Loe53fa0f2011-04-11 17:18:41 +08001068 return 0;
1069
1070 /*
Souvik Ghoshd75cd672016-06-17 14:21:39 -07001071 * This will break if one day flashctx becomes read-only.
Louis Yung-Chieh Loe53fa0f2011-04-11 17:18:41 +08001072 * Once that happens, we need to have special hacks in functions:
1073 *
1074 * erase_and_write_flash() in flashrom.c
1075 * read_flash_to_file()
1076 * handle_romentries()
1077 * ...
1078 *
1079 * Search "total_size * 1024" in code.
1080 */
Lachlan Bishopbf1476e2020-09-10 14:57:05 +10001081 flash->chip->total_size = emu_data->emu_chip_size / 1024;
Louis Yung-Chieh Loe53fa0f2011-04-11 17:18:41 +08001082 msg_cdbg("%s: set flash->total_size to %dK bytes.\n", __func__,
Patrick Georgif3fa2992017-02-02 16:24:44 +01001083 flash->chip->total_size);
Louis Yung-Chieh Loe53fa0f2011-04-11 17:18:41 +08001084
Lachlan Bishopbf1476e2020-09-10 14:57:05 +10001085 if (emu_data->erase_to_zero)
Alan Greendbeec2b2019-09-16 14:36:52 +10001086 flash->chip->feature_bits |= FEATURE_ERASED_ZERO;
David Hendricks0eda2a82014-09-12 16:32:05 -07001087
Edward O'Callaghanec8b0d92020-09-17 17:27:45 +10001088 /* Update the first count of each of the block_erasers. */
Louis Yung-Chieh Loe53fa0f2011-04-11 17:18:41 +08001089 for (i = 0; i < NUM_ERASEFUNCTIONS; i++) {
Patrick Georgif3fa2992017-02-02 16:24:44 +01001090 struct block_eraser *eraser = &flash->chip->block_erasers[i];
Edward O'Callaghanec8b0d92020-09-17 17:27:45 +10001091 if (!eraser->block_erase)
Louis Yung-Chieh Loe53fa0f2011-04-11 17:18:41 +08001092 break;
1093
Namyoon Woob71a2962020-08-27 16:27:49 -07001094 eraser->eraseblocks[0].count = 1;
Lachlan Bishopbf1476e2020-09-10 14:57:05 +10001095 eraser->eraseblocks[0].size = emu_data->emu_chip_size;
Louis Yung-Chieh Loe53fa0f2011-04-11 17:18:41 +08001096 msg_cdbg("%s: eraser.size=%d, .count=%d\n",
1097 __func__, eraser->eraseblocks[0].size,
1098 eraser->eraseblocks[0].count);
1099 }
1100
1101 return 1;
1102}
1103#endif