blob: 3090197c1d7a01ab4576548cbe088bd123b8015f [file] [log] [blame]
Carl-Daniel Hailfingerc3129202009-05-09 00:54:55 +00001/*
2 * This file is part of the flashrom project.
3 *
Carl-Daniel Hailfingerf68aa8a2010-11-01 22:07:04 +00004 * Copyright (C) 2009,2010 Carl-Daniel Hailfinger
Carl-Daniel Hailfingerc3129202009-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
Carl-Daniel Hailfingerf68aa8a2010-11-01 22:07:04 +00008 * the Free Software Foundation; version 2 of the License.
Carl-Daniel Hailfingerc3129202009-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.
Carl-Daniel Hailfingerc3129202009-05-09 00:54:55 +000014 */
15
Sergii Dmytruk2ac444f2021-11-08 00:05:12 +020016#include <assert.h>
Carl-Daniel Hailfingerc3129202009-05-09 00:54:55 +000017#include <string.h>
18#include <stdlib.h>
Carl-Daniel Hailfinger1b83be52012-02-08 23:28:54 +000019#include <stdio.h>
20#include <ctype.h>
Stefan Tauner5e695ab2012-05-06 17:03:40 +000021#include <errno.h>
Nico Huber81d3f3e2021-06-09 18:10:07 +020022#include <sys/types.h>
23#include <sys/stat.h>
Carl-Daniel Hailfingerc3129202009-05-09 00:54:55 +000024#include "flash.h"
Carl-Daniel Hailfinger1b0ba892010-06-20 10:58:32 +000025#include "chipdrivers.h"
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +000026#include "programmer.h"
Carl-Daniel Hailfingerc3129202009-05-09 00:54:55 +000027
Carl-Daniel Hailfingerf68aa8a2010-11-01 22:07:04 +000028#include "spi.h"
Carl-Daniel Hailfingerf68aa8a2010-11-01 22:07:04 +000029
Carl-Daniel Hailfingerf68aa8a2010-11-01 22:07:04 +000030enum emu_chip {
31 EMULATE_NONE,
32 EMULATE_ST_M25P10_RES,
33 EMULATE_SST_SST25VF040_REMS,
34 EMULATE_SST_SST25VF032B,
Stefan Tauner0b9df972012-05-07 22:12:16 +000035 EMULATE_MACRONIX_MX25L6436,
Nico Huberf9632d82019-01-20 11:23:49 +010036 EMULATE_WINBOND_W25Q128FV,
Carl-Daniel Hailfingerf68aa8a2010-11-01 22:07:04 +000037};
Stefan Tauner0b9df972012-05-07 22:12:16 +000038
Lachlan Bishopc753c402020-09-10 14:57:05 +100039struct emu_data {
40 enum emu_chip emu_chip;
41 char *emu_persistent_image;
42 unsigned int emu_chip_size;
Sergii Dmytruk2ac444f2021-11-08 00:05:12 +020043 /* Note: W25Q128FV doesn't change value of SR2 if it's not provided, but
44 * even its previous generations do, so don't forget to update
45 * WRSR code on enabling WRSR_EXT for more chips. */
46 bool emu_wrsr_ext;
Lachlan Bishopc753c402020-09-10 14:57:05 +100047 int emu_modified; /* is the image modified since reading it? */
Sergii Dmytruk2ac444f2021-11-08 00:05:12 +020048 uint8_t emu_status[3];
49 uint8_t emu_status_len; /* number of emulated status registers */
Lachlan Bishopc753c402020-09-10 14:57:05 +100050 unsigned int emu_max_byteprogram_size;
51 unsigned int emu_max_aai_size;
52 unsigned int emu_jedec_se_size;
53 unsigned int emu_jedec_be_52_size;
54 unsigned int emu_jedec_be_d8_size;
55 unsigned int emu_jedec_ce_60_size;
56 unsigned int emu_jedec_ce_c7_size;
57 unsigned char spi_blacklist[256];
58 unsigned char spi_ignorelist[256];
59 unsigned int spi_blacklist_size;
60 unsigned int spi_ignorelist_size;
Edward O'Callaghanb1a51ab2021-05-20 20:34:02 +100061
62 uint8_t *flashchip_contents;
Lachlan Bishopc753c402020-09-10 14:57:05 +100063};
64
Stefan Tauner0b9df972012-05-07 22:12:16 +000065/* A legit complete SFDP table based on the MX25L6436E (rev. 1.8) datasheet. */
Stefan Tauner67d163d2013-01-15 17:37:48 +000066static const uint8_t sfdp_table[] = {
Stefan Tauner0b9df972012-05-07 22:12:16 +000067 0x53, 0x46, 0x44, 0x50, // @0x00: SFDP signature
68 0x00, 0x01, 0x01, 0xFF, // @0x04: revision 1.0, 2 headers
69 0x00, 0x00, 0x01, 0x09, // @0x08: JEDEC SFDP header rev. 1.0, 9 DW long
70 0x1C, 0x00, 0x00, 0xFF, // @0x0C: PTP0 = 0x1C (instead of 0x30)
71 0xC2, 0x00, 0x01, 0x04, // @0x10: Macronix header rev. 1.0, 4 DW long
72 0x48, 0x00, 0x00, 0xFF, // @0x14: PTP1 = 0x48 (instead of 0x60)
73 0xFF, 0xFF, 0xFF, 0xFF, // @0x18: hole.
74 0xE5, 0x20, 0xC9, 0xFF, // @0x1C: SFDP parameter table start
75 0xFF, 0xFF, 0xFF, 0x03, // @0x20
76 0x00, 0xFF, 0x08, 0x6B, // @0x24
77 0x08, 0x3B, 0x00, 0xFF, // @0x28
78 0xEE, 0xFF, 0xFF, 0xFF, // @0x2C
79 0xFF, 0xFF, 0x00, 0x00, // @0x30
80 0xFF, 0xFF, 0x00, 0xFF, // @0x34
81 0x0C, 0x20, 0x0F, 0x52, // @0x38
82 0x10, 0xD8, 0x00, 0xFF, // @0x3C: SFDP parameter table end
83 0xFF, 0xFF, 0xFF, 0xFF, // @0x40: hole.
84 0xFF, 0xFF, 0xFF, 0xFF, // @0x44: hole.
85 0x00, 0x36, 0x00, 0x27, // @0x48: Macronix parameter table start
86 0xF4, 0x4F, 0xFF, 0xFF, // @0x4C
87 0xD9, 0xC8, 0xFF, 0xFF, // @0x50
88 0xFF, 0xFF, 0xFF, 0xFF, // @0x54: Macronix parameter table end
89};
90
Carl-Daniel Hailfingerf68aa8a2010-11-01 22:07:04 +000091
Stefan Taunerc69c9c82011-11-23 09:13:48 +000092static unsigned int spi_write_256_chunksize = 256;
Carl-Daniel Hailfingerf68aa8a2010-11-01 22:07:04 +000093
Edward O'Callaghan5eca4272020-04-12 17:27:53 +100094static int dummy_spi_send_command(const struct flashctx *flash, unsigned int writecnt, unsigned int readcnt,
Mark Marshallf20b7be2014-05-09 21:16:21 +000095 const unsigned char *writearr, unsigned char *readarr);
96static int dummy_spi_write_256(struct flashctx *flash, const uint8_t *buf,
Stefan Taunerc69c9c82011-11-23 09:13:48 +000097 unsigned int start, unsigned int len);
Mark Marshallf20b7be2014-05-09 21:16:21 +000098static void dummy_chip_writeb(const struct flashctx *flash, uint8_t val, chipaddr addr);
99static void dummy_chip_writew(const struct flashctx *flash, uint16_t val, chipaddr addr);
100static void dummy_chip_writel(const struct flashctx *flash, uint32_t val, chipaddr addr);
101static void dummy_chip_writen(const struct flashctx *flash, const uint8_t *buf, chipaddr addr, size_t len);
102static uint8_t dummy_chip_readb(const struct flashctx *flash, const chipaddr addr);
103static uint16_t dummy_chip_readw(const struct flashctx *flash, const chipaddr addr);
104static uint32_t dummy_chip_readl(const struct flashctx *flash, const chipaddr addr);
105static void dummy_chip_readn(const struct flashctx *flash, uint8_t *buf, const chipaddr addr, size_t len);
Michael Karcherb9dbe482011-05-11 17:07:07 +0000106
Lachlan Bishopc753c402020-09-10 14:57:05 +1000107static struct spi_master spi_master_dummyflasher = {
Nico Huber1cf407b2017-11-10 20:18:23 +0100108 .features = SPI_MASTER_4BA,
Uwe Hermann91f4afa2011-07-28 08:13:25 +0000109 .max_data_read = MAX_DATA_READ_UNLIMITED,
110 .max_data_write = MAX_DATA_UNSPECIFIED,
111 .command = dummy_spi_send_command,
112 .multicommand = default_spi_send_multicommand,
113 .read = default_spi_read,
114 .write_256 = dummy_spi_write_256,
Nico Huber7bca1262012-06-15 22:28:12 +0000115 .write_aai = default_spi_write_aai,
Michael Karcherb9dbe482011-05-11 17:07:07 +0000116};
David Hendricks8bb20212011-06-14 01:35:36 +0000117
Lachlan Bishopc753c402020-09-10 14:57:05 +1000118static struct par_master par_master_dummy = {
Carl-Daniel Hailfingereaacd2d2011-11-09 23:40:00 +0000119 .chip_readb = dummy_chip_readb,
120 .chip_readw = dummy_chip_readw,
121 .chip_readl = dummy_chip_readl,
122 .chip_readn = dummy_chip_readn,
123 .chip_writeb = dummy_chip_writeb,
124 .chip_writew = dummy_chip_writew,
125 .chip_writel = dummy_chip_writel,
126 .chip_writen = dummy_chip_writen,
127};
128
David Hendricks8bb20212011-06-14 01:35:36 +0000129static int dummy_shutdown(void *data)
130{
131 msg_pspew("%s\n", __func__);
Lachlan Bishopc753c402020-09-10 14:57:05 +1000132 struct emu_data *emu_data = (struct emu_data *)data;
133 if (emu_data->emu_chip != EMULATE_NONE) {
134 if (emu_data->emu_persistent_image && emu_data->emu_modified) {
135 msg_pdbg("Writing %s\n", emu_data->emu_persistent_image);
Edward O'Callaghanb1a51ab2021-05-20 20:34:02 +1000136 write_buf_to_file(emu_data->flashchip_contents,
Lachlan Bishopc753c402020-09-10 14:57:05 +1000137 emu_data->emu_chip_size,
138 emu_data->emu_persistent_image);
David Hendricks8bb20212011-06-14 01:35:36 +0000139 }
Angel Pons86975952021-05-25 12:46:43 +0200140 free(emu_data->emu_persistent_image);
Edward O'Callaghanb1a51ab2021-05-20 20:34:02 +1000141 free(emu_data->flashchip_contents);
David Hendricks8bb20212011-06-14 01:35:36 +0000142 }
Lachlan Bishopc753c402020-09-10 14:57:05 +1000143 free(data);
David Hendricks8bb20212011-06-14 01:35:36 +0000144 return 0;
145}
146
Anastasia Klimchuka9f2dca2021-05-31 09:42:36 +1000147static int init_data(struct emu_data *data, enum chipbustype *dummy_buses_supported)
Carl-Daniel Hailfingerc3129202009-05-09 00:54:55 +0000148{
Carl-Daniel Hailfinger744132a2010-07-06 09:55:48 +0000149 char *bustext = NULL;
Carl-Daniel Hailfingerf68aa8a2010-11-01 22:07:04 +0000150 char *tmp = NULL;
Nico Huber519be662018-12-23 20:03:35 +0100151 unsigned int i;
Anastasia Klimchuka9f2dca2021-05-31 09:42:36 +1000152 char *endptr;
Stefan Tauner5e695ab2012-05-06 17:03:40 +0000153 char *status = NULL;
Carl-Daniel Hailfinger3504b532009-06-01 00:02:11 +0000154
Carl-Daniel Hailfinger2b6dcb32010-07-08 10:13:37 +0000155 bustext = extract_programmer_param("bus");
Carl-Daniel Hailfinger744132a2010-07-06 09:55:48 +0000156 msg_pdbg("Requested buses are: %s\n", bustext ? bustext : "default");
157 if (!bustext)
158 bustext = strdup("parallel+lpc+fwh+spi");
Carl-Daniel Hailfinger3504b532009-06-01 00:02:11 +0000159 /* Convert the parameters to lowercase. */
Carl-Daniel Hailfinger744132a2010-07-06 09:55:48 +0000160 tolower_string(bustext);
Carl-Daniel Hailfinger3504b532009-06-01 00:02:11 +0000161
Anastasia Klimchuka9f2dca2021-05-31 09:42:36 +1000162 *dummy_buses_supported = BUS_NONE;
Carl-Daniel Hailfinger744132a2010-07-06 09:55:48 +0000163 if (strstr(bustext, "parallel")) {
Anastasia Klimchuka9f2dca2021-05-31 09:42:36 +1000164 *dummy_buses_supported |= BUS_PARALLEL;
Carl-Daniel Hailfinger3ac101c2010-01-09 04:32:23 +0000165 msg_pdbg("Enabling support for %s flash.\n", "parallel");
Carl-Daniel Hailfinger3504b532009-06-01 00:02:11 +0000166 }
Carl-Daniel Hailfinger744132a2010-07-06 09:55:48 +0000167 if (strstr(bustext, "lpc")) {
Anastasia Klimchuka9f2dca2021-05-31 09:42:36 +1000168 *dummy_buses_supported |= BUS_LPC;
Carl-Daniel Hailfinger3ac101c2010-01-09 04:32:23 +0000169 msg_pdbg("Enabling support for %s flash.\n", "LPC");
Carl-Daniel Hailfinger3504b532009-06-01 00:02:11 +0000170 }
Carl-Daniel Hailfinger744132a2010-07-06 09:55:48 +0000171 if (strstr(bustext, "fwh")) {
Anastasia Klimchuka9f2dca2021-05-31 09:42:36 +1000172 *dummy_buses_supported |= BUS_FWH;
Carl-Daniel Hailfinger3ac101c2010-01-09 04:32:23 +0000173 msg_pdbg("Enabling support for %s flash.\n", "FWH");
Carl-Daniel Hailfinger3504b532009-06-01 00:02:11 +0000174 }
Carl-Daniel Hailfinger744132a2010-07-06 09:55:48 +0000175 if (strstr(bustext, "spi")) {
Anastasia Klimchuka9f2dca2021-05-31 09:42:36 +1000176 *dummy_buses_supported |= BUS_SPI;
Carl-Daniel Hailfinger3ac101c2010-01-09 04:32:23 +0000177 msg_pdbg("Enabling support for %s flash.\n", "SPI");
Carl-Daniel Hailfinger3504b532009-06-01 00:02:11 +0000178 }
Anastasia Klimchuka9f2dca2021-05-31 09:42:36 +1000179 if (*dummy_buses_supported == BUS_NONE)
Carl-Daniel Hailfinger3ac101c2010-01-09 04:32:23 +0000180 msg_pdbg("Support for all flash bus types disabled.\n");
Carl-Daniel Hailfinger744132a2010-07-06 09:55:48 +0000181 free(bustext);
Carl-Daniel Hailfingerf68aa8a2010-11-01 22:07:04 +0000182
183 tmp = extract_programmer_param("spi_write_256_chunksize");
184 if (tmp) {
Edward O'Callaghan28868fd2021-05-23 22:14:36 +1000185 spi_write_256_chunksize = strtoul(tmp, &endptr, 0);
186 if (*endptr != '\0' || spi_write_256_chunksize < 1) {
Carl-Daniel Hailfingerf68aa8a2010-11-01 22:07:04 +0000187 msg_perr("invalid spi_write_256_chunksize\n");
Edward O'Callaghan28868fd2021-05-23 22:14:36 +1000188 free(tmp);
Carl-Daniel Hailfingerf68aa8a2010-11-01 22:07:04 +0000189 return 1;
190 }
Edward O'Callaghan28868fd2021-05-23 22:14:36 +1000191 free(tmp);
Carl-Daniel Hailfingerf68aa8a2010-11-01 22:07:04 +0000192 }
193
Carl-Daniel Hailfinger1b83be52012-02-08 23:28:54 +0000194 tmp = extract_programmer_param("spi_blacklist");
195 if (tmp) {
196 i = strlen(tmp);
197 if (!strncmp(tmp, "0x", 2)) {
198 i -= 2;
199 memmove(tmp, tmp + 2, i + 1);
200 }
201 if ((i > 512) || (i % 2)) {
202 msg_perr("Invalid SPI command blacklist length\n");
203 free(tmp);
204 return 1;
205 }
Lachlan Bishopc753c402020-09-10 14:57:05 +1000206 data->spi_blacklist_size = i / 2;
207 for (i = 0; i < data->spi_blacklist_size * 2; i++) {
Carl-Daniel Hailfinger1b83be52012-02-08 23:28:54 +0000208 if (!isxdigit((unsigned char)tmp[i])) {
209 msg_perr("Invalid char \"%c\" in SPI command "
210 "blacklist\n", tmp[i]);
211 free(tmp);
212 return 1;
213 }
214 }
Lachlan Bishopc753c402020-09-10 14:57:05 +1000215 for (i = 0; i < data->spi_blacklist_size; i++) {
Carl-Daniel Hailfinger5b554712012-02-16 01:43:06 +0000216 unsigned int tmp2;
217 /* SCNx8 is apparently not supported by MSVC (and thus
218 * MinGW), so work around it with an extra variable
219 */
220 sscanf(tmp + i * 2, "%2x", &tmp2);
Lachlan Bishopc753c402020-09-10 14:57:05 +1000221 data->spi_blacklist[i] = (uint8_t)tmp2;
Carl-Daniel Hailfinger1b83be52012-02-08 23:28:54 +0000222 }
223 msg_pdbg("SPI blacklist is ");
Lachlan Bishopc753c402020-09-10 14:57:05 +1000224 for (i = 0; i < data->spi_blacklist_size; i++)
225 msg_pdbg("%02x ", data->spi_blacklist[i]);
226 msg_pdbg(", size %u\n", data->spi_blacklist_size);
Carl-Daniel Hailfinger1b83be52012-02-08 23:28:54 +0000227 }
228 free(tmp);
229
230 tmp = extract_programmer_param("spi_ignorelist");
231 if (tmp) {
232 i = strlen(tmp);
233 if (!strncmp(tmp, "0x", 2)) {
234 i -= 2;
235 memmove(tmp, tmp + 2, i + 1);
236 }
237 if ((i > 512) || (i % 2)) {
238 msg_perr("Invalid SPI command ignorelist length\n");
239 free(tmp);
240 return 1;
241 }
Lachlan Bishopc753c402020-09-10 14:57:05 +1000242 data->spi_ignorelist_size = i / 2;
243 for (i = 0; i < data->spi_ignorelist_size * 2; i++) {
Carl-Daniel Hailfinger1b83be52012-02-08 23:28:54 +0000244 if (!isxdigit((unsigned char)tmp[i])) {
245 msg_perr("Invalid char \"%c\" in SPI command "
246 "ignorelist\n", tmp[i]);
247 free(tmp);
248 return 1;
249 }
250 }
Lachlan Bishopc753c402020-09-10 14:57:05 +1000251 for (i = 0; i < data->spi_ignorelist_size; i++) {
Carl-Daniel Hailfinger5b554712012-02-16 01:43:06 +0000252 unsigned int tmp2;
253 /* SCNx8 is apparently not supported by MSVC (and thus
254 * MinGW), so work around it with an extra variable
255 */
256 sscanf(tmp + i * 2, "%2x", &tmp2);
Lachlan Bishopc753c402020-09-10 14:57:05 +1000257 data->spi_ignorelist[i] = (uint8_t)tmp2;
Carl-Daniel Hailfinger1b83be52012-02-08 23:28:54 +0000258 }
259 msg_pdbg("SPI ignorelist is ");
Lachlan Bishopc753c402020-09-10 14:57:05 +1000260 for (i = 0; i < data->spi_ignorelist_size; i++)
261 msg_pdbg("%02x ", data->spi_ignorelist[i]);
262 msg_pdbg(", size %u\n", data->spi_ignorelist_size);
Carl-Daniel Hailfinger1b83be52012-02-08 23:28:54 +0000263 }
264 free(tmp);
265
Carl-Daniel Hailfingerf68aa8a2010-11-01 22:07:04 +0000266 tmp = extract_programmer_param("emulate");
267 if (!tmp) {
268 msg_pdbg("Not emulating any flash chip.\n");
269 /* Nothing else to do. */
Anastasia Klimchuka9f2dca2021-05-31 09:42:36 +1000270 return 0;
Carl-Daniel Hailfingerf68aa8a2010-11-01 22:07:04 +0000271 }
Anastasia Klimchuka9f2dca2021-05-31 09:42:36 +1000272
Carl-Daniel Hailfingerf68aa8a2010-11-01 22:07:04 +0000273 if (!strcmp(tmp, "M25P10.RES")) {
Lachlan Bishopc753c402020-09-10 14:57:05 +1000274 data->emu_chip = EMULATE_ST_M25P10_RES;
275 data->emu_chip_size = 128 * 1024;
276 data->emu_max_byteprogram_size = 128;
277 data->emu_max_aai_size = 0;
Sergii Dmytruk2ac444f2021-11-08 00:05:12 +0200278 data->emu_status_len = 1;
Lachlan Bishopc753c402020-09-10 14:57:05 +1000279 data->emu_jedec_se_size = 0;
280 data->emu_jedec_be_52_size = 0;
281 data->emu_jedec_be_d8_size = 32 * 1024;
282 data->emu_jedec_ce_60_size = 0;
283 data->emu_jedec_ce_c7_size = data->emu_chip_size;
Carl-Daniel Hailfingerf68aa8a2010-11-01 22:07:04 +0000284 msg_pdbg("Emulating ST M25P10.RES SPI flash chip (RES, page "
285 "write)\n");
286 }
287 if (!strcmp(tmp, "SST25VF040.REMS")) {
Lachlan Bishopc753c402020-09-10 14:57:05 +1000288 data->emu_chip = EMULATE_SST_SST25VF040_REMS;
289 data->emu_chip_size = 512 * 1024;
290 data->emu_max_byteprogram_size = 1;
291 data->emu_max_aai_size = 0;
Sergii Dmytruk2ac444f2021-11-08 00:05:12 +0200292 data->emu_status_len = 1;
Lachlan Bishopc753c402020-09-10 14:57:05 +1000293 data->emu_jedec_se_size = 4 * 1024;
294 data->emu_jedec_be_52_size = 32 * 1024;
295 data->emu_jedec_be_d8_size = 0;
296 data->emu_jedec_ce_60_size = data->emu_chip_size;
297 data->emu_jedec_ce_c7_size = 0;
Carl-Daniel Hailfingerf68aa8a2010-11-01 22:07:04 +0000298 msg_pdbg("Emulating SST SST25VF040.REMS SPI flash chip (REMS, "
299 "byte write)\n");
300 }
301 if (!strcmp(tmp, "SST25VF032B")) {
Lachlan Bishopc753c402020-09-10 14:57:05 +1000302 data->emu_chip = EMULATE_SST_SST25VF032B;
303 data->emu_chip_size = 4 * 1024 * 1024;
304 data->emu_max_byteprogram_size = 1;
305 data->emu_max_aai_size = 2;
Sergii Dmytruk2ac444f2021-11-08 00:05:12 +0200306 data->emu_status_len = 1;
Lachlan Bishopc753c402020-09-10 14:57:05 +1000307 data->emu_jedec_se_size = 4 * 1024;
308 data->emu_jedec_be_52_size = 32 * 1024;
309 data->emu_jedec_be_d8_size = 64 * 1024;
310 data->emu_jedec_ce_60_size = data->emu_chip_size;
311 data->emu_jedec_ce_c7_size = data->emu_chip_size;
Carl-Daniel Hailfingerf68aa8a2010-11-01 22:07:04 +0000312 msg_pdbg("Emulating SST SST25VF032B SPI flash chip (RDID, AAI "
313 "write)\n");
314 }
Stefan Tauner0b9df972012-05-07 22:12:16 +0000315 if (!strcmp(tmp, "MX25L6436")) {
Lachlan Bishopc753c402020-09-10 14:57:05 +1000316 data->emu_chip = EMULATE_MACRONIX_MX25L6436;
317 data->emu_chip_size = 8 * 1024 * 1024;
318 data->emu_max_byteprogram_size = 256;
319 data->emu_max_aai_size = 0;
Sergii Dmytruk2ac444f2021-11-08 00:05:12 +0200320 data->emu_status_len = 1;
Lachlan Bishopc753c402020-09-10 14:57:05 +1000321 data->emu_jedec_se_size = 4 * 1024;
322 data->emu_jedec_be_52_size = 32 * 1024;
323 data->emu_jedec_be_d8_size = 64 * 1024;
324 data->emu_jedec_ce_60_size = data->emu_chip_size;
325 data->emu_jedec_ce_c7_size = data->emu_chip_size;
Stefan Tauner0b9df972012-05-07 22:12:16 +0000326 msg_pdbg("Emulating Macronix MX25L6436 SPI flash chip (RDID, "
327 "SFDP)\n");
328 }
Nico Huberf9632d82019-01-20 11:23:49 +0100329 if (!strcmp(tmp, "W25Q128FV")) {
Lachlan Bishopc753c402020-09-10 14:57:05 +1000330 data->emu_chip = EMULATE_WINBOND_W25Q128FV;
Sergii Dmytruk97ad2642021-11-08 00:06:33 +0200331 data->emu_wrsr_ext = true;
Lachlan Bishopc753c402020-09-10 14:57:05 +1000332 data->emu_chip_size = 16 * 1024 * 1024;
333 data->emu_max_byteprogram_size = 256;
334 data->emu_max_aai_size = 0;
Sergii Dmytruk97ad2642021-11-08 00:06:33 +0200335 data->emu_status_len = 3;
Lachlan Bishopc753c402020-09-10 14:57:05 +1000336 data->emu_jedec_se_size = 4 * 1024;
337 data->emu_jedec_be_52_size = 32 * 1024;
338 data->emu_jedec_be_d8_size = 64 * 1024;
339 data->emu_jedec_ce_60_size = data->emu_chip_size;
340 data->emu_jedec_ce_c7_size = data->emu_chip_size;
Nico Huberf9632d82019-01-20 11:23:49 +0100341 msg_pdbg("Emulating Winbond W25Q128FV SPI flash chip (RDID)\n");
342 }
Lachlan Bishopc753c402020-09-10 14:57:05 +1000343 if (data->emu_chip == EMULATE_NONE) {
Carl-Daniel Hailfingerf68aa8a2010-11-01 22:07:04 +0000344 msg_perr("Invalid chip specified for emulation: %s\n", tmp);
345 free(tmp);
346 return 1;
347 }
348 free(tmp);
David Hendricks8bb20212011-06-14 01:35:36 +0000349
Stefan Tauner5e695ab2012-05-06 17:03:40 +0000350 status = extract_programmer_param("spi_status");
351 if (status) {
Sergii Dmytruk2ac444f2021-11-08 00:05:12 +0200352 unsigned int emu_status;
353
Stefan Tauner5e695ab2012-05-06 17:03:40 +0000354 errno = 0;
Sergii Dmytruk2ac444f2021-11-08 00:05:12 +0200355 emu_status = strtoul(status, &endptr, 0);
Stefan Tauner5e695ab2012-05-06 17:03:40 +0000356 if (errno != 0 || status == endptr) {
Angel Ponsd377fe52021-05-25 13:03:24 +0200357 free(status);
Stefan Tauner5e695ab2012-05-06 17:03:40 +0000358 msg_perr("Error: initial status register specified, "
359 "but the value could not be converted.\n");
360 return 1;
361 }
Angel Ponsd377fe52021-05-25 13:03:24 +0200362 free(status);
Sergii Dmytruk2ac444f2021-11-08 00:05:12 +0200363
364 data->emu_status[0] = emu_status;
365 data->emu_status[1] = emu_status >> 8;
366 data->emu_status[2] = emu_status >> 16;
367
368 if (data->emu_status_len == 3) {
369 msg_pdbg("Initial status registers:\n"
370 "\tSR1 is set to 0x%02x\n"
371 "\tSR2 is set to 0x%02x\n"
372 "\tSR3 is set to 0x%02x\n",
373 data->emu_status[0], data->emu_status[1], data->emu_status[2]);
374 } else if (data->emu_status_len == 2) {
375 msg_pdbg("Initial status registers:\n"
376 "\tSR1 is set to 0x%02x\n"
377 "\tSR2 is set to 0x%02x\n",
378 data->emu_status[0], data->emu_status[1]);
379 } else {
380 msg_pdbg("Initial status register is set to 0x%02x.\n",
381 data->emu_status[0]);
382 }
Stefan Tauner5e695ab2012-05-06 17:03:40 +0000383 }
Stefan Tauner5e695ab2012-05-06 17:03:40 +0000384
Angel Ponsbb3e4e22021-05-25 12:56:18 +0200385 data->flashchip_contents = malloc(data->emu_chip_size);
386 if (!data->flashchip_contents) {
387 msg_perr("Out of memory!\n");
388 return 1;
389 }
390
Anastasia Klimchuka9f2dca2021-05-31 09:42:36 +1000391
392 return 0;
393}
394
Thomas Heijligenddfaff02021-05-04 15:32:17 +0200395static int dummy_init(void)
Anastasia Klimchuka9f2dca2021-05-31 09:42:36 +1000396{
Anastasia Klimchuka9f2dca2021-05-31 09:42:36 +1000397 struct stat image_stat;
Anastasia Klimchuka9f2dca2021-05-31 09:42:36 +1000398
399 struct emu_data *data = calloc(1, sizeof(struct emu_data));
400 if (!data) {
401 msg_perr("Out of memory!\n");
402 return 1;
403 }
404 data->emu_chip = EMULATE_NONE;
405 spi_master_dummyflasher.data = data;
406 par_master_dummy.data = data;
407
408 msg_pspew("%s\n", __func__);
409
410 enum chipbustype dummy_buses_supported;
411 if (init_data(data, &dummy_buses_supported)) {
412 free(data);
413 return 1;
414 }
415
Anastasia Klimchuka9f2dca2021-05-31 09:42:36 +1000416 if (data->emu_chip == EMULATE_NONE) {
417 msg_pdbg("Not emulating any flash chip.\n");
418 /* Nothing else to do. */
419 goto dummy_init_out;
420 }
421
Lachlan Bishopc753c402020-09-10 14:57:05 +1000422 msg_pdbg("Filling fake flash chip with 0xff, size %i\n", data->emu_chip_size);
Edward O'Callaghanb1a51ab2021-05-20 20:34:02 +1000423 memset(data->flashchip_contents, 0xff, data->emu_chip_size);
Carl-Daniel Hailfingerf68aa8a2010-11-01 22:07:04 +0000424
Stefan Taunerc2eec2c2014-05-03 21:33:01 +0000425 /* Will be freed by shutdown function if necessary. */
Lachlan Bishopc753c402020-09-10 14:57:05 +1000426 data->emu_persistent_image = extract_programmer_param("image");
427 if (!data->emu_persistent_image) {
Carl-Daniel Hailfingerf68aa8a2010-11-01 22:07:04 +0000428 /* Nothing else to do. */
David Hendricks8bb20212011-06-14 01:35:36 +0000429 goto dummy_init_out;
Carl-Daniel Hailfingerf68aa8a2010-11-01 22:07:04 +0000430 }
Stefan Taunerc2eec2c2014-05-03 21:33:01 +0000431 /* We will silently (in default verbosity) ignore the file if it does not exist (yet) or the size does
432 * not match the emulated chip. */
Lachlan Bishopc753c402020-09-10 14:57:05 +1000433 if (!stat(data->emu_persistent_image, &image_stat)) {
Stefan Tauner23e10b82016-01-23 16:16:49 +0000434 msg_pdbg("Found persistent image %s, %jd B ",
Lachlan Bishopc753c402020-09-10 14:57:05 +1000435 data->emu_persistent_image, (intmax_t)image_stat.st_size);
436 if ((uintmax_t)image_stat.st_size == data->emu_chip_size) {
Carl-Daniel Hailfingerf68aa8a2010-11-01 22:07:04 +0000437 msg_pdbg("matches.\n");
Lachlan Bishopc753c402020-09-10 14:57:05 +1000438 msg_pdbg("Reading %s\n", data->emu_persistent_image);
Edward O'Callaghanb1a51ab2021-05-20 20:34:02 +1000439 if (read_buf_from_file(data->flashchip_contents, data->emu_chip_size,
Lachlan Bishopc753c402020-09-10 14:57:05 +1000440 data->emu_persistent_image)) {
441 msg_perr("Unable to read %s\n", data->emu_persistent_image);
Angel Pons86975952021-05-25 12:46:43 +0200442 free(data->emu_persistent_image);
Edward O'Callaghanb1a51ab2021-05-20 20:34:02 +1000443 free(data->flashchip_contents);
Anastasia Klimchuka9f2dca2021-05-31 09:42:36 +1000444 free(data);
Jacob Garberca598da2019-08-12 10:44:17 -0600445 return 1;
446 }
Carl-Daniel Hailfingerf68aa8a2010-11-01 22:07:04 +0000447 } else {
448 msg_pdbg("doesn't match.\n");
449 }
450 }
Carl-Daniel Hailfingerc3129202009-05-09 00:54:55 +0000451
David Hendricks8bb20212011-06-14 01:35:36 +0000452dummy_init_out:
Lachlan Bishopc753c402020-09-10 14:57:05 +1000453 if (register_shutdown(dummy_shutdown, data)) {
Angel Pons86975952021-05-25 12:46:43 +0200454 free(data->emu_persistent_image);
Edward O'Callaghanb1a51ab2021-05-20 20:34:02 +1000455 free(data->flashchip_contents);
Lachlan Bishopc753c402020-09-10 14:57:05 +1000456 free(data);
David Hendricks8bb20212011-06-14 01:35:36 +0000457 return 1;
Carl-Daniel Hailfingerf68aa8a2010-11-01 22:07:04 +0000458 }
Edward O'Callaghancd9d6462021-05-17 20:01:27 +1000459 if (dummy_buses_supported & BUS_NONSPI)
Carl-Daniel Hailfingera5bcbce2014-07-19 22:03:29 +0000460 register_par_master(&par_master_dummy,
Edward O'Callaghancd9d6462021-05-17 20:01:27 +1000461 dummy_buses_supported & BUS_NONSPI);
Carl-Daniel Hailfingereaacd2d2011-11-09 23:40:00 +0000462 if (dummy_buses_supported & BUS_SPI)
Carl-Daniel Hailfingera5bcbce2014-07-19 22:03:29 +0000463 register_spi_master(&spi_master_dummyflasher);
Carl-Daniel Hailfingereaacd2d2011-11-09 23:40:00 +0000464
Carl-Daniel Hailfingerc3129202009-05-09 00:54:55 +0000465 return 0;
466}
467
Thomas Heijligenddfaff02021-05-04 15:32:17 +0200468static void *dummy_map(const char *descr, uintptr_t phys_addr, size_t len)
Carl-Daniel Hailfinger1455b2b2009-05-11 14:13:25 +0000469{
Stefan Taunerc2eec2c2014-05-03 21:33:01 +0000470 msg_pspew("%s: Mapping %s, 0x%zx bytes at 0x%0*" PRIxPTR "\n",
Stefan Tauner0554ca52013-07-25 22:54:25 +0000471 __func__, descr, len, PRIxPTR_WIDTH, phys_addr);
Carl-Daniel Hailfinger1455b2b2009-05-11 14:13:25 +0000472 return (void *)phys_addr;
473}
474
Thomas Heijligenddfaff02021-05-04 15:32:17 +0200475static void dummy_unmap(void *virt_addr, size_t len)
Carl-Daniel Hailfinger1455b2b2009-05-11 14:13:25 +0000476{
Stefan Tauner0554ca52013-07-25 22:54:25 +0000477 msg_pspew("%s: Unmapping 0x%zx bytes at %p\n", __func__, len, virt_addr);
Carl-Daniel Hailfinger1455b2b2009-05-11 14:13:25 +0000478}
479
Mark Marshallf20b7be2014-05-09 21:16:21 +0000480static void dummy_chip_writeb(const struct flashctx *flash, uint8_t val, chipaddr addr)
Carl-Daniel Hailfingerc3129202009-05-09 00:54:55 +0000481{
Stefan Taunerc2333752013-07-13 23:31:37 +0000482 msg_pspew("%s: addr=0x%" PRIxPTR ", val=0x%02x\n", __func__, addr, val);
Carl-Daniel Hailfingerc3129202009-05-09 00:54:55 +0000483}
484
Mark Marshallf20b7be2014-05-09 21:16:21 +0000485static void dummy_chip_writew(const struct flashctx *flash, uint16_t val, chipaddr addr)
Carl-Daniel Hailfingerc3129202009-05-09 00:54:55 +0000486{
Stefan Taunerc2333752013-07-13 23:31:37 +0000487 msg_pspew("%s: addr=0x%" PRIxPTR ", val=0x%04x\n", __func__, addr, val);
Carl-Daniel Hailfingerc3129202009-05-09 00:54:55 +0000488}
489
Mark Marshallf20b7be2014-05-09 21:16:21 +0000490static void dummy_chip_writel(const struct flashctx *flash, uint32_t val, chipaddr addr)
Carl-Daniel Hailfingerc3129202009-05-09 00:54:55 +0000491{
Stefan Taunerc2333752013-07-13 23:31:37 +0000492 msg_pspew("%s: addr=0x%" PRIxPTR ", val=0x%08x\n", __func__, addr, val);
Carl-Daniel Hailfingerc3129202009-05-09 00:54:55 +0000493}
494
Mark Marshallf20b7be2014-05-09 21:16:21 +0000495static void dummy_chip_writen(const struct flashctx *flash, const uint8_t *buf, chipaddr addr, size_t len)
Carl-Daniel Hailfinger0bd2a2b2009-06-05 18:32:07 +0000496{
497 size_t i;
Stefan Tauner0554ca52013-07-25 22:54:25 +0000498 msg_pspew("%s: addr=0x%" PRIxPTR ", len=0x%zx, writing data (hex):", __func__, addr, len);
Carl-Daniel Hailfinger0bd2a2b2009-06-05 18:32:07 +0000499 for (i = 0; i < len; i++) {
500 if ((i % 16) == 0)
Carl-Daniel Hailfinger3ac101c2010-01-09 04:32:23 +0000501 msg_pspew("\n");
502 msg_pspew("%02x ", buf[i]);
Carl-Daniel Hailfinger0bd2a2b2009-06-05 18:32:07 +0000503 }
504}
505
Mark Marshallf20b7be2014-05-09 21:16:21 +0000506static uint8_t dummy_chip_readb(const struct flashctx *flash, const chipaddr addr)
Carl-Daniel Hailfingerc3129202009-05-09 00:54:55 +0000507{
Stefan Taunerc2333752013-07-13 23:31:37 +0000508 msg_pspew("%s: addr=0x%" PRIxPTR ", returning 0xff\n", __func__, addr);
Carl-Daniel Hailfingerc3129202009-05-09 00:54:55 +0000509 return 0xff;
510}
511
Mark Marshallf20b7be2014-05-09 21:16:21 +0000512static uint16_t dummy_chip_readw(const struct flashctx *flash, const chipaddr addr)
Carl-Daniel Hailfingerc3129202009-05-09 00:54:55 +0000513{
Stefan Taunerc2333752013-07-13 23:31:37 +0000514 msg_pspew("%s: addr=0x%" PRIxPTR ", returning 0xffff\n", __func__, addr);
Carl-Daniel Hailfingerc3129202009-05-09 00:54:55 +0000515 return 0xffff;
516}
517
Mark Marshallf20b7be2014-05-09 21:16:21 +0000518static uint32_t dummy_chip_readl(const struct flashctx *flash, const chipaddr addr)
Carl-Daniel Hailfingerc3129202009-05-09 00:54:55 +0000519{
Stefan Taunerc2333752013-07-13 23:31:37 +0000520 msg_pspew("%s: addr=0x%" PRIxPTR ", returning 0xffffffff\n", __func__, addr);
Carl-Daniel Hailfingerc3129202009-05-09 00:54:55 +0000521 return 0xffffffff;
522}
523
Mark Marshallf20b7be2014-05-09 21:16:21 +0000524static void dummy_chip_readn(const struct flashctx *flash, uint8_t *buf, const chipaddr addr, size_t len)
Carl-Daniel Hailfinger0bd2a2b2009-06-05 18:32:07 +0000525{
Stefan Tauner0554ca52013-07-25 22:54:25 +0000526 msg_pspew("%s: addr=0x%" PRIxPTR ", len=0x%zx, returning array of 0xff\n", __func__, addr, len);
Carl-Daniel Hailfinger0bd2a2b2009-06-05 18:32:07 +0000527 memset(buf, 0xff, len);
528 return;
529}
530
Sergii Dmytruk97ad2642021-11-08 00:06:33 +0200531static uint8_t get_reg_ro_bit_mask(const struct emu_data *data, enum flash_reg reg)
Sergii Dmytruk2ac444f2021-11-08 00:05:12 +0200532{
533 /* Whoever adds a new register must not forget to update this function
534 or at least shouldn't use it incorrectly. */
535 assert(reg == STATUS1 || reg == STATUS2 || reg == STATUS3);
536
Sergii Dmytruk97ad2642021-11-08 00:06:33 +0200537 uint8_t ro_bits = reg == STATUS1 ? SPI_SR_WIP : 0;
538
539 if (data->emu_chip == EMULATE_WINBOND_W25Q128FV) {
540 if (reg == STATUS2) {
541 /* SUS (bit_7) and (R) (bit_2). */
542 ro_bits = 0x84;
543 /* Once any of the lock bits (LB[1..3]) are set, they
544 can't be unset. */
545 ro_bits |= data->emu_status[1] & (1 << 3);
546 ro_bits |= data->emu_status[1] & (1 << 4);
547 ro_bits |= data->emu_status[1] & (1 << 5);
548 } else if (reg == STATUS3) {
549 /* Four reserved bits. */
550 ro_bits = 0x1b;
551 }
552 }
553
554 return ro_bits;
Sergii Dmytruk2ac444f2021-11-08 00:05:12 +0200555}
556
Carl-Daniel Hailfinger8a3c60c2011-12-18 15:01:24 +0000557static int emulate_spi_chip_response(unsigned int writecnt,
558 unsigned int readcnt,
559 const unsigned char *writearr,
Lachlan Bishopc753c402020-09-10 14:57:05 +1000560 unsigned char *readarr,
561 struct emu_data *data)
Carl-Daniel Hailfingerf68aa8a2010-11-01 22:07:04 +0000562{
Stefan Tauner0b9df972012-05-07 22:12:16 +0000563 unsigned int offs, i, toread;
Sergii Dmytruk2ac444f2021-11-08 00:05:12 +0200564 uint8_t ro_bits;
565 bool wrsr_ext;
Stefan Taunerc69c9c82011-11-23 09:13:48 +0000566 static int unsigned aai_offs;
Carl-Daniel Hailfingeraf2cac02012-08-30 21:41:00 +0000567 const unsigned char sst25vf040_rems_response[2] = {0xbf, 0x44};
568 const unsigned char sst25vf032b_rems_response[2] = {0xbf, 0x4a};
569 const unsigned char mx25l6436_rems_response[2] = {0xc2, 0x16};
Nico Huberf9632d82019-01-20 11:23:49 +0100570 const unsigned char w25q128fv_rems_response[2] = {0xef, 0x17};
Carl-Daniel Hailfingerf68aa8a2010-11-01 22:07:04 +0000571
572 if (writecnt == 0) {
573 msg_perr("No command sent to the chip!\n");
574 return 1;
575 }
Paul Menzelac427b22012-02-16 21:07:07 +0000576 /* spi_blacklist has precedence over spi_ignorelist. */
Lachlan Bishopc753c402020-09-10 14:57:05 +1000577 for (i = 0; i < data->spi_blacklist_size; i++) {
578 if (writearr[0] == data->spi_blacklist[i]) {
Carl-Daniel Hailfinger1b83be52012-02-08 23:28:54 +0000579 msg_pdbg("Refusing blacklisted SPI command 0x%02x\n",
Lachlan Bishopc753c402020-09-10 14:57:05 +1000580 data->spi_blacklist[i]);
Carl-Daniel Hailfinger1b83be52012-02-08 23:28:54 +0000581 return SPI_INVALID_OPCODE;
582 }
583 }
Lachlan Bishopc753c402020-09-10 14:57:05 +1000584 for (i = 0; i < data->spi_ignorelist_size; i++) {
585 if (writearr[0] == data->spi_ignorelist[i]) {
Carl-Daniel Hailfinger1b83be52012-02-08 23:28:54 +0000586 msg_cdbg("Ignoring ignorelisted SPI command 0x%02x\n",
Lachlan Bishopc753c402020-09-10 14:57:05 +1000587 data->spi_ignorelist[i]);
Carl-Daniel Hailfinger1b83be52012-02-08 23:28:54 +0000588 /* Return success because the command does not fail,
589 * it is simply ignored.
590 */
591 return 0;
592 }
593 }
Stefan Tauner5e695ab2012-05-06 17:03:40 +0000594
Sergii Dmytruk2ac444f2021-11-08 00:05:12 +0200595 if (data->emu_max_aai_size && (data->emu_status[0] & SPI_SR_AAI)) {
Stefan Tauner5e695ab2012-05-06 17:03:40 +0000596 if (writearr[0] != JEDEC_AAI_WORD_PROGRAM &&
597 writearr[0] != JEDEC_WRDI &&
598 writearr[0] != JEDEC_RDSR) {
599 msg_perr("Forbidden opcode (0x%02x) attempted during "
600 "AAI sequence!\n", writearr[0]);
601 return 0;
602 }
603 }
604
Carl-Daniel Hailfingerf68aa8a2010-11-01 22:07:04 +0000605 switch (writearr[0]) {
606 case JEDEC_RES:
Carl-Daniel Hailfingeraf2cac02012-08-30 21:41:00 +0000607 if (writecnt < JEDEC_RES_OUTSIZE)
Carl-Daniel Hailfingerf68aa8a2010-11-01 22:07:04 +0000608 break;
Carl-Daniel Hailfingeraf2cac02012-08-30 21:41:00 +0000609 /* offs calculation is only needed for SST chips which treat RES like REMS. */
610 offs = writearr[1] << 16 | writearr[2] << 8 | writearr[3];
611 offs += writecnt - JEDEC_REMS_OUTSIZE;
Lachlan Bishopc753c402020-09-10 14:57:05 +1000612 switch (data->emu_chip) {
Carl-Daniel Hailfingeraf2cac02012-08-30 21:41:00 +0000613 case EMULATE_ST_M25P10_RES:
614 if (readcnt > 0)
615 memset(readarr, 0x10, readcnt);
616 break;
617 case EMULATE_SST_SST25VF040_REMS:
618 for (i = 0; i < readcnt; i++)
619 readarr[i] = sst25vf040_rems_response[(offs + i) % 2];
620 break;
621 case EMULATE_SST_SST25VF032B:
622 for (i = 0; i < readcnt; i++)
623 readarr[i] = sst25vf032b_rems_response[(offs + i) % 2];
624 break;
625 case EMULATE_MACRONIX_MX25L6436:
626 if (readcnt > 0)
627 memset(readarr, 0x16, readcnt);
628 break;
Nico Huberf9632d82019-01-20 11:23:49 +0100629 case EMULATE_WINBOND_W25Q128FV:
630 if (readcnt > 0)
631 memset(readarr, 0x17, readcnt);
632 break;
Carl-Daniel Hailfingeraf2cac02012-08-30 21:41:00 +0000633 default: /* ignore */
634 break;
635 }
Carl-Daniel Hailfingerf68aa8a2010-11-01 22:07:04 +0000636 break;
637 case JEDEC_REMS:
Carl-Daniel Hailfingeraf2cac02012-08-30 21:41:00 +0000638 /* REMS response has wraparound and uses an address parameter. */
639 if (writecnt < JEDEC_REMS_OUTSIZE)
Carl-Daniel Hailfingerf68aa8a2010-11-01 22:07:04 +0000640 break;
Carl-Daniel Hailfingeraf2cac02012-08-30 21:41:00 +0000641 offs = writearr[1] << 16 | writearr[2] << 8 | writearr[3];
642 offs += writecnt - JEDEC_REMS_OUTSIZE;
Lachlan Bishopc753c402020-09-10 14:57:05 +1000643 switch (data->emu_chip) {
Carl-Daniel Hailfingeraf2cac02012-08-30 21:41:00 +0000644 case EMULATE_SST_SST25VF040_REMS:
645 for (i = 0; i < readcnt; i++)
646 readarr[i] = sst25vf040_rems_response[(offs + i) % 2];
647 break;
648 case EMULATE_SST_SST25VF032B:
649 for (i = 0; i < readcnt; i++)
650 readarr[i] = sst25vf032b_rems_response[(offs + i) % 2];
651 break;
652 case EMULATE_MACRONIX_MX25L6436:
653 for (i = 0; i < readcnt; i++)
654 readarr[i] = mx25l6436_rems_response[(offs + i) % 2];
655 break;
Nico Huberf9632d82019-01-20 11:23:49 +0100656 case EMULATE_WINBOND_W25Q128FV:
657 for (i = 0; i < readcnt; i++)
658 readarr[i] = w25q128fv_rems_response[(offs + i) % 2];
659 break;
Carl-Daniel Hailfingeraf2cac02012-08-30 21:41:00 +0000660 default: /* ignore */
661 break;
662 }
Carl-Daniel Hailfingerf68aa8a2010-11-01 22:07:04 +0000663 break;
664 case JEDEC_RDID:
Lachlan Bishopc753c402020-09-10 14:57:05 +1000665 switch (data->emu_chip) {
Stefan Tauner0b9df972012-05-07 22:12:16 +0000666 case EMULATE_SST_SST25VF032B:
667 if (readcnt > 0)
668 readarr[0] = 0xbf;
669 if (readcnt > 1)
670 readarr[1] = 0x25;
671 if (readcnt > 2)
672 readarr[2] = 0x4a;
Carl-Daniel Hailfingerf68aa8a2010-11-01 22:07:04 +0000673 break;
Stefan Tauner0b9df972012-05-07 22:12:16 +0000674 case EMULATE_MACRONIX_MX25L6436:
675 if (readcnt > 0)
676 readarr[0] = 0xc2;
677 if (readcnt > 1)
678 readarr[1] = 0x20;
679 if (readcnt > 2)
680 readarr[2] = 0x17;
681 break;
Nico Huberf9632d82019-01-20 11:23:49 +0100682 case EMULATE_WINBOND_W25Q128FV:
683 if (readcnt > 0)
684 readarr[0] = 0xef;
685 if (readcnt > 1)
686 readarr[1] = 0x40;
687 if (readcnt > 2)
688 readarr[2] = 0x18;
689 break;
Stefan Tauner0b9df972012-05-07 22:12:16 +0000690 default: /* ignore */
691 break;
692 }
Carl-Daniel Hailfingerf68aa8a2010-11-01 22:07:04 +0000693 break;
Stefan Tauner0b9df972012-05-07 22:12:16 +0000694 case JEDEC_RDSR:
Sergii Dmytruk2ac444f2021-11-08 00:05:12 +0200695 memset(readarr, data->emu_status[0], readcnt);
696 break;
697 case JEDEC_RDSR2:
698 if (data->emu_status_len >= 2)
699 memset(readarr, data->emu_status[1], readcnt);
700 break;
701 case JEDEC_RDSR3:
702 if (data->emu_status_len >= 3)
703 memset(readarr, data->emu_status[2], readcnt);
Stefan Tauner5e695ab2012-05-06 17:03:40 +0000704 break;
Stefan Tauner5e695ab2012-05-06 17:03:40 +0000705 /* FIXME: this should be chip-specific. */
706 case JEDEC_EWSR:
707 case JEDEC_WREN:
Sergii Dmytruk2ac444f2021-11-08 00:05:12 +0200708 data->emu_status[0] |= SPI_SR_WEL;
Stefan Tauner5e695ab2012-05-06 17:03:40 +0000709 break;
710 case JEDEC_WRSR:
Sergii Dmytruk2ac444f2021-11-08 00:05:12 +0200711 if (!(data->emu_status[0] & SPI_SR_WEL)) {
Stefan Tauner5e695ab2012-05-06 17:03:40 +0000712 msg_perr("WRSR attempted, but WEL is 0!\n");
713 break;
714 }
Sergii Dmytruk2ac444f2021-11-08 00:05:12 +0200715
716 wrsr_ext = (writecnt == 3 && data->emu_wrsr_ext);
717
Stefan Tauner5e695ab2012-05-06 17:03:40 +0000718 /* FIXME: add some reasonable simulation of the busy flag */
Sergii Dmytruk2ac444f2021-11-08 00:05:12 +0200719
Sergii Dmytruk97ad2642021-11-08 00:06:33 +0200720 ro_bits = get_reg_ro_bit_mask(data, STATUS1);
Sergii Dmytruk2ac444f2021-11-08 00:05:12 +0200721 data->emu_status[0] &= ro_bits;
722 data->emu_status[0] |= writearr[1] & ~ro_bits;
723 if (wrsr_ext) {
Sergii Dmytruk97ad2642021-11-08 00:06:33 +0200724 ro_bits = get_reg_ro_bit_mask(data, STATUS2);
Sergii Dmytruk2ac444f2021-11-08 00:05:12 +0200725 data->emu_status[1] &= ro_bits;
726 data->emu_status[1] |= writearr[2] & ~ro_bits;
727 }
728
729 if (wrsr_ext)
730 msg_pdbg2("WRSR wrote 0x%02x%02x.\n", data->emu_status[1], data->emu_status[0]);
731 else
732 msg_pdbg2("WRSR wrote 0x%02x.\n", data->emu_status[0]);
733 break;
734 case JEDEC_WRSR2:
735 if (data->emu_status_len < 2)
736 break;
737 if (!(data->emu_status[0] & SPI_SR_WEL)) {
738 msg_perr("WRSR2 attempted, but WEL is 0!\n");
739 break;
740 }
741
Sergii Dmytruk97ad2642021-11-08 00:06:33 +0200742 ro_bits = get_reg_ro_bit_mask(data, STATUS2);
Sergii Dmytruk2ac444f2021-11-08 00:05:12 +0200743 data->emu_status[1] &= ro_bits;
744 data->emu_status[1] |= (writearr[1] & ~ro_bits);
745
746 msg_pdbg2("WRSR2 wrote 0x%02x.\n", data->emu_status[1]);
747 break;
748 case JEDEC_WRSR3:
749 if (data->emu_status_len < 3)
750 break;
751 if (!(data->emu_status[0] & SPI_SR_WEL)) {
752 msg_perr("WRSR3 attempted, but WEL is 0!\n");
753 break;
754 }
755
Sergii Dmytruk97ad2642021-11-08 00:06:33 +0200756 ro_bits = get_reg_ro_bit_mask(data, STATUS3);
Sergii Dmytruk2ac444f2021-11-08 00:05:12 +0200757 data->emu_status[2] &= ro_bits;
758 data->emu_status[2] |= (writearr[1] & ~ro_bits);
759
760 msg_pdbg2("WRSR3 wrote 0x%02x.\n", data->emu_status[2]);
Carl-Daniel Hailfingerf68aa8a2010-11-01 22:07:04 +0000761 break;
762 case JEDEC_READ:
763 offs = writearr[1] << 16 | writearr[2] << 8 | writearr[3];
764 /* Truncate to emu_chip_size. */
Lachlan Bishopc753c402020-09-10 14:57:05 +1000765 offs %= data->emu_chip_size;
Carl-Daniel Hailfingerf68aa8a2010-11-01 22:07:04 +0000766 if (readcnt > 0)
Edward O'Callaghanb1a51ab2021-05-20 20:34:02 +1000767 memcpy(readarr, data->flashchip_contents + offs, readcnt);
Carl-Daniel Hailfingerf68aa8a2010-11-01 22:07:04 +0000768 break;
769 case JEDEC_BYTE_PROGRAM:
770 offs = writearr[1] << 16 | writearr[2] << 8 | writearr[3];
771 /* Truncate to emu_chip_size. */
Lachlan Bishopc753c402020-09-10 14:57:05 +1000772 offs %= data->emu_chip_size;
Carl-Daniel Hailfingerf68aa8a2010-11-01 22:07:04 +0000773 if (writecnt < 5) {
774 msg_perr("BYTE PROGRAM size too short!\n");
775 return 1;
776 }
Lachlan Bishopc753c402020-09-10 14:57:05 +1000777 if (writecnt - 4 > data->emu_max_byteprogram_size) {
Carl-Daniel Hailfingerf68aa8a2010-11-01 22:07:04 +0000778 msg_perr("Max BYTE PROGRAM size exceeded!\n");
779 return 1;
780 }
Edward O'Callaghanb1a51ab2021-05-20 20:34:02 +1000781 memcpy(data->flashchip_contents + offs, writearr + 4, writecnt - 4);
Lachlan Bishopc753c402020-09-10 14:57:05 +1000782 data->emu_modified = 1;
Carl-Daniel Hailfingerf68aa8a2010-11-01 22:07:04 +0000783 break;
784 case JEDEC_AAI_WORD_PROGRAM:
Lachlan Bishopc753c402020-09-10 14:57:05 +1000785 if (!data->emu_max_aai_size)
Carl-Daniel Hailfingerf68aa8a2010-11-01 22:07:04 +0000786 break;
Sergii Dmytruk2ac444f2021-11-08 00:05:12 +0200787 if (!(data->emu_status[0] & SPI_SR_AAI)) {
Carl-Daniel Hailfingerf68aa8a2010-11-01 22:07:04 +0000788 if (writecnt < JEDEC_AAI_WORD_PROGRAM_OUTSIZE) {
789 msg_perr("Initial AAI WORD PROGRAM size too "
790 "short!\n");
791 return 1;
792 }
793 if (writecnt > JEDEC_AAI_WORD_PROGRAM_OUTSIZE) {
794 msg_perr("Initial AAI WORD PROGRAM size too "
795 "long!\n");
796 return 1;
797 }
Sergii Dmytruk2ac444f2021-11-08 00:05:12 +0200798 data->emu_status[0] |= SPI_SR_AAI;
Carl-Daniel Hailfingerf68aa8a2010-11-01 22:07:04 +0000799 aai_offs = writearr[1] << 16 | writearr[2] << 8 |
800 writearr[3];
801 /* Truncate to emu_chip_size. */
Lachlan Bishopc753c402020-09-10 14:57:05 +1000802 aai_offs %= data->emu_chip_size;
Edward O'Callaghanb1a51ab2021-05-20 20:34:02 +1000803 memcpy(data->flashchip_contents + aai_offs, writearr + 4, 2);
Carl-Daniel Hailfingerf68aa8a2010-11-01 22:07:04 +0000804 aai_offs += 2;
805 } else {
806 if (writecnt < JEDEC_AAI_WORD_PROGRAM_CONT_OUTSIZE) {
807 msg_perr("Continuation AAI WORD PROGRAM size "
808 "too short!\n");
809 return 1;
810 }
811 if (writecnt > JEDEC_AAI_WORD_PROGRAM_CONT_OUTSIZE) {
812 msg_perr("Continuation AAI WORD PROGRAM size "
813 "too long!\n");
814 return 1;
815 }
Edward O'Callaghanb1a51ab2021-05-20 20:34:02 +1000816 memcpy(data->flashchip_contents + aai_offs, writearr + 1, 2);
Carl-Daniel Hailfingerf68aa8a2010-11-01 22:07:04 +0000817 aai_offs += 2;
818 }
Lachlan Bishopc753c402020-09-10 14:57:05 +1000819 data->emu_modified = 1;
Carl-Daniel Hailfingerf68aa8a2010-11-01 22:07:04 +0000820 break;
821 case JEDEC_WRDI:
Lachlan Bishopc753c402020-09-10 14:57:05 +1000822 if (data->emu_max_aai_size)
Sergii Dmytruk2ac444f2021-11-08 00:05:12 +0200823 data->emu_status[0] &= ~SPI_SR_AAI;
Carl-Daniel Hailfingerf68aa8a2010-11-01 22:07:04 +0000824 break;
825 case JEDEC_SE:
Lachlan Bishopc753c402020-09-10 14:57:05 +1000826 if (!data->emu_jedec_se_size)
Carl-Daniel Hailfingerf68aa8a2010-11-01 22:07:04 +0000827 break;
828 if (writecnt != JEDEC_SE_OUTSIZE) {
829 msg_perr("SECTOR ERASE 0x20 outsize invalid!\n");
830 return 1;
831 }
832 if (readcnt != JEDEC_SE_INSIZE) {
833 msg_perr("SECTOR ERASE 0x20 insize invalid!\n");
834 return 1;
835 }
836 offs = writearr[1] << 16 | writearr[2] << 8 | writearr[3];
Lachlan Bishopc753c402020-09-10 14:57:05 +1000837 if (offs & (data->emu_jedec_se_size - 1))
Carl-Daniel Hailfinger146b77d2011-02-04 22:52:04 +0000838 msg_pdbg("Unaligned SECTOR ERASE 0x20: 0x%x\n", offs);
Lachlan Bishopc753c402020-09-10 14:57:05 +1000839 offs &= ~(data->emu_jedec_se_size - 1);
Edward O'Callaghanb1a51ab2021-05-20 20:34:02 +1000840 memset(data->flashchip_contents + offs, 0xff, data->emu_jedec_se_size);
Lachlan Bishopc753c402020-09-10 14:57:05 +1000841 data->emu_modified = 1;
Carl-Daniel Hailfingerf68aa8a2010-11-01 22:07:04 +0000842 break;
843 case JEDEC_BE_52:
Lachlan Bishopc753c402020-09-10 14:57:05 +1000844 if (!data->emu_jedec_be_52_size)
Carl-Daniel Hailfingerf68aa8a2010-11-01 22:07:04 +0000845 break;
846 if (writecnt != JEDEC_BE_52_OUTSIZE) {
847 msg_perr("BLOCK ERASE 0x52 outsize invalid!\n");
848 return 1;
849 }
850 if (readcnt != JEDEC_BE_52_INSIZE) {
851 msg_perr("BLOCK ERASE 0x52 insize invalid!\n");
852 return 1;
853 }
854 offs = writearr[1] << 16 | writearr[2] << 8 | writearr[3];
Lachlan Bishopc753c402020-09-10 14:57:05 +1000855 if (offs & (data->emu_jedec_be_52_size - 1))
Carl-Daniel Hailfinger146b77d2011-02-04 22:52:04 +0000856 msg_pdbg("Unaligned BLOCK ERASE 0x52: 0x%x\n", offs);
Lachlan Bishopc753c402020-09-10 14:57:05 +1000857 offs &= ~(data->emu_jedec_be_52_size - 1);
Edward O'Callaghanb1a51ab2021-05-20 20:34:02 +1000858 memset(data->flashchip_contents + offs, 0xff, data->emu_jedec_be_52_size);
Lachlan Bishopc753c402020-09-10 14:57:05 +1000859 data->emu_modified = 1;
Carl-Daniel Hailfingerf68aa8a2010-11-01 22:07:04 +0000860 break;
861 case JEDEC_BE_D8:
Lachlan Bishopc753c402020-09-10 14:57:05 +1000862 if (!data->emu_jedec_be_d8_size)
Carl-Daniel Hailfingerf68aa8a2010-11-01 22:07:04 +0000863 break;
864 if (writecnt != JEDEC_BE_D8_OUTSIZE) {
865 msg_perr("BLOCK ERASE 0xd8 outsize invalid!\n");
866 return 1;
867 }
868 if (readcnt != JEDEC_BE_D8_INSIZE) {
869 msg_perr("BLOCK ERASE 0xd8 insize invalid!\n");
870 return 1;
871 }
872 offs = writearr[1] << 16 | writearr[2] << 8 | writearr[3];
Lachlan Bishopc753c402020-09-10 14:57:05 +1000873 if (offs & (data->emu_jedec_be_d8_size - 1))
Carl-Daniel Hailfinger146b77d2011-02-04 22:52:04 +0000874 msg_pdbg("Unaligned BLOCK ERASE 0xd8: 0x%x\n", offs);
Lachlan Bishopc753c402020-09-10 14:57:05 +1000875 offs &= ~(data->emu_jedec_be_d8_size - 1);
Edward O'Callaghanb1a51ab2021-05-20 20:34:02 +1000876 memset(data->flashchip_contents + offs, 0xff, data->emu_jedec_be_d8_size);
Lachlan Bishopc753c402020-09-10 14:57:05 +1000877 data->emu_modified = 1;
Carl-Daniel Hailfingerf68aa8a2010-11-01 22:07:04 +0000878 break;
879 case JEDEC_CE_60:
Lachlan Bishopc753c402020-09-10 14:57:05 +1000880 if (!data->emu_jedec_ce_60_size)
Carl-Daniel Hailfingerf68aa8a2010-11-01 22:07:04 +0000881 break;
882 if (writecnt != JEDEC_CE_60_OUTSIZE) {
883 msg_perr("CHIP ERASE 0x60 outsize invalid!\n");
884 return 1;
885 }
886 if (readcnt != JEDEC_CE_60_INSIZE) {
887 msg_perr("CHIP ERASE 0x60 insize invalid!\n");
888 return 1;
889 }
Carl-Daniel Hailfinger146b77d2011-02-04 22:52:04 +0000890 /* JEDEC_CE_60_OUTSIZE is 1 (no address) -> no offset. */
Carl-Daniel Hailfingerf68aa8a2010-11-01 22:07:04 +0000891 /* emu_jedec_ce_60_size is emu_chip_size. */
Edward O'Callaghanb1a51ab2021-05-20 20:34:02 +1000892 memset(data->flashchip_contents, 0xff, data->emu_jedec_ce_60_size);
Lachlan Bishopc753c402020-09-10 14:57:05 +1000893 data->emu_modified = 1;
Carl-Daniel Hailfingerf68aa8a2010-11-01 22:07:04 +0000894 break;
895 case JEDEC_CE_C7:
Lachlan Bishopc753c402020-09-10 14:57:05 +1000896 if (!data->emu_jedec_ce_c7_size)
Carl-Daniel Hailfingerf68aa8a2010-11-01 22:07:04 +0000897 break;
898 if (writecnt != JEDEC_CE_C7_OUTSIZE) {
899 msg_perr("CHIP ERASE 0xc7 outsize invalid!\n");
900 return 1;
901 }
902 if (readcnt != JEDEC_CE_C7_INSIZE) {
903 msg_perr("CHIP ERASE 0xc7 insize invalid!\n");
904 return 1;
905 }
Carl-Daniel Hailfinger146b77d2011-02-04 22:52:04 +0000906 /* JEDEC_CE_C7_OUTSIZE is 1 (no address) -> no offset. */
Carl-Daniel Hailfingerf68aa8a2010-11-01 22:07:04 +0000907 /* emu_jedec_ce_c7_size is emu_chip_size. */
Edward O'Callaghanb1a51ab2021-05-20 20:34:02 +1000908 memset(data->flashchip_contents, 0xff, data->emu_jedec_ce_c7_size);
Lachlan Bishopc753c402020-09-10 14:57:05 +1000909 data->emu_modified = 1;
Carl-Daniel Hailfingerf68aa8a2010-11-01 22:07:04 +0000910 break;
Stefan Tauner0b9df972012-05-07 22:12:16 +0000911 case JEDEC_SFDP:
Lachlan Bishopc753c402020-09-10 14:57:05 +1000912 if (data->emu_chip != EMULATE_MACRONIX_MX25L6436)
Stefan Tauner0b9df972012-05-07 22:12:16 +0000913 break;
914 if (writecnt < 4)
915 break;
916 offs = writearr[1] << 16 | writearr[2] << 8 | writearr[3];
917
918 /* SFDP expects one dummy byte after the address. */
919 if (writecnt == 4) {
920 /* The dummy byte was not written, make sure it is read instead.
921 * Shifting and shortening the read array does achieve this goal.
922 */
923 readarr++;
924 readcnt--;
925 } else {
926 /* The response is shifted if more than 5 bytes are written, because SFDP data is
927 * already shifted out by the chip while those superfluous bytes are written. */
928 offs += writecnt - 5;
929 }
930
931 /* The SFDP spec implies that the start address of an SFDP read may be truncated to fit in the
932 * SFDP table address space, i.e. the start address may be wrapped around at SFDP table size.
933 * This is a reasonable implementation choice in hardware because it saves a few gates. */
934 if (offs >= sizeof(sfdp_table)) {
935 msg_pdbg("Wrapping the start address around the SFDP table boundary (using 0x%x "
936 "instead of 0x%x).\n", (unsigned int)(offs % sizeof(sfdp_table)), offs);
937 offs %= sizeof(sfdp_table);
938 }
939 toread = min(sizeof(sfdp_table) - offs, readcnt);
940 memcpy(readarr, sfdp_table + offs, toread);
941 if (toread < readcnt)
942 msg_pdbg("Crossing the SFDP table boundary in a single "
943 "continuous chunk produces undefined results "
944 "after that point.\n");
945 break;
Carl-Daniel Hailfingerf68aa8a2010-11-01 22:07:04 +0000946 default:
947 /* No special response. */
948 break;
949 }
Stefan Tauner5e695ab2012-05-06 17:03:40 +0000950 if (writearr[0] != JEDEC_WREN && writearr[0] != JEDEC_EWSR)
Sergii Dmytruk2ac444f2021-11-08 00:05:12 +0200951 data->emu_status[0] &= ~SPI_SR_WEL;
Carl-Daniel Hailfingerf68aa8a2010-11-01 22:07:04 +0000952 return 0;
953}
Carl-Daniel Hailfingerf68aa8a2010-11-01 22:07:04 +0000954
Edward O'Callaghan5eca4272020-04-12 17:27:53 +1000955static int dummy_spi_send_command(const struct flashctx *flash, unsigned int writecnt,
Carl-Daniel Hailfinger8a3c60c2011-12-18 15:01:24 +0000956 unsigned int readcnt,
957 const unsigned char *writearr,
958 unsigned char *readarr)
Carl-Daniel Hailfingerbfe2e0c2009-05-14 12:59:36 +0000959{
Nico Huber519be662018-12-23 20:03:35 +0100960 unsigned int i;
Lachlan Bishopc753c402020-09-10 14:57:05 +1000961 struct emu_data *emu_data = flash->mst->spi.data;
962 if (!emu_data) {
963 msg_perr("No data in flash context!\n");
964 return 1;
965 }
Carl-Daniel Hailfingerbfe2e0c2009-05-14 12:59:36 +0000966
Carl-Daniel Hailfinger3ac101c2010-01-09 04:32:23 +0000967 msg_pspew("%s:", __func__);
Carl-Daniel Hailfingerbfe2e0c2009-05-14 12:59:36 +0000968
Carl-Daniel Hailfinger3ac101c2010-01-09 04:32:23 +0000969 msg_pspew(" writing %u bytes:", writecnt);
Carl-Daniel Hailfingerbfe2e0c2009-05-14 12:59:36 +0000970 for (i = 0; i < writecnt; i++)
Carl-Daniel Hailfinger3ac101c2010-01-09 04:32:23 +0000971 msg_pspew(" 0x%02x", writearr[i]);
Carl-Daniel Hailfingerbfe2e0c2009-05-14 12:59:36 +0000972
Carl-Daniel Hailfingerf68aa8a2010-11-01 22:07:04 +0000973 /* Response for unknown commands and missing chip is 0xff. */
974 memset(readarr, 0xff, readcnt);
Lachlan Bishopc753c402020-09-10 14:57:05 +1000975 switch (emu_data->emu_chip) {
Carl-Daniel Hailfingerf68aa8a2010-11-01 22:07:04 +0000976 case EMULATE_ST_M25P10_RES:
977 case EMULATE_SST_SST25VF040_REMS:
978 case EMULATE_SST_SST25VF032B:
Stefan Tauner0b9df972012-05-07 22:12:16 +0000979 case EMULATE_MACRONIX_MX25L6436:
Nico Huberf9632d82019-01-20 11:23:49 +0100980 case EMULATE_WINBOND_W25Q128FV:
Carl-Daniel Hailfingerf68aa8a2010-11-01 22:07:04 +0000981 if (emulate_spi_chip_response(writecnt, readcnt, writearr,
Lachlan Bishopc753c402020-09-10 14:57:05 +1000982 readarr, emu_data)) {
Carl-Daniel Hailfinger1b83be52012-02-08 23:28:54 +0000983 msg_pdbg("Invalid command sent to flash chip!\n");
Carl-Daniel Hailfingerf68aa8a2010-11-01 22:07:04 +0000984 return 1;
985 }
986 break;
987 default:
988 break;
989 }
Carl-Daniel Hailfinger3ac101c2010-01-09 04:32:23 +0000990 msg_pspew(" reading %u bytes:", readcnt);
Uwe Hermann91f4afa2011-07-28 08:13:25 +0000991 for (i = 0; i < readcnt; i++)
Carl-Daniel Hailfingerf68aa8a2010-11-01 22:07:04 +0000992 msg_pspew(" 0x%02x", readarr[i]);
Carl-Daniel Hailfinger3ac101c2010-01-09 04:32:23 +0000993 msg_pspew("\n");
Carl-Daniel Hailfingerbfe2e0c2009-05-14 12:59:36 +0000994 return 0;
995}
Carl-Daniel Hailfinger1b0ba892010-06-20 10:58:32 +0000996
Mark Marshallf20b7be2014-05-09 21:16:21 +0000997static int dummy_spi_write_256(struct flashctx *flash, const uint8_t *buf, unsigned int start, unsigned int len)
Carl-Daniel Hailfinger9a795d82010-07-14 16:19:05 +0000998{
Carl-Daniel Hailfingerf68aa8a2010-11-01 22:07:04 +0000999 return spi_write_chunked(flash, buf, start, len,
1000 spi_write_256_chunksize);
Carl-Daniel Hailfinger9a795d82010-07-14 16:19:05 +00001001}
Thomas Heijligenddfaff02021-05-04 15:32:17 +02001002
1003const struct programmer_entry programmer_dummy = {
1004 .name = "dummy",
1005 .type = OTHER,
1006 /* FIXME */
1007 .devs.note = "Dummy device, does nothing and logs all accesses\n",
1008 .init = dummy_init,
1009 .map_flash_region = dummy_map,
1010 .unmap_flash_region = dummy_unmap,
1011 .delay = internal_delay,
1012};