Carl-Daniel Hailfinger | c312920 | 2009-05-09 00:54:55 +0000 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the flashrom project. |
| 3 | * |
Carl-Daniel Hailfinger | f68aa8a | 2010-11-01 22:07:04 +0000 | [diff] [blame] | 4 | * Copyright (C) 2009,2010 Carl-Daniel Hailfinger |
Carl-Daniel Hailfinger | c312920 | 2009-05-09 00:54:55 +0000 | [diff] [blame] | 5 | * |
| 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 Hailfinger | f68aa8a | 2010-11-01 22:07:04 +0000 | [diff] [blame] | 8 | * the Free Software Foundation; version 2 of the License. |
Carl-Daniel Hailfinger | c312920 | 2009-05-09 00:54:55 +0000 | [diff] [blame] | 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | * GNU General Public License for more details. |
| 14 | * |
| 15 | * You should have received a copy of the GNU General Public License |
| 16 | * along with this program; if not, write to the Free Software |
| 17 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
| 18 | */ |
| 19 | |
Carl-Daniel Hailfinger | c312920 | 2009-05-09 00:54:55 +0000 | [diff] [blame] | 20 | #include <string.h> |
| 21 | #include <stdlib.h> |
Carl-Daniel Hailfinger | 1b83be5 | 2012-02-08 23:28:54 +0000 | [diff] [blame] | 22 | #include <stdio.h> |
| 23 | #include <ctype.h> |
Carl-Daniel Hailfinger | c312920 | 2009-05-09 00:54:55 +0000 | [diff] [blame] | 24 | #include "flash.h" |
Carl-Daniel Hailfinger | 1b0ba89 | 2010-06-20 10:58:32 +0000 | [diff] [blame] | 25 | #include "chipdrivers.h" |
Carl-Daniel Hailfinger | 5b997c3 | 2010-07-27 22:41:39 +0000 | [diff] [blame] | 26 | #include "programmer.h" |
Carl-Daniel Hailfinger | c312920 | 2009-05-09 00:54:55 +0000 | [diff] [blame] | 27 | |
Carl-Daniel Hailfinger | f68aa8a | 2010-11-01 22:07:04 +0000 | [diff] [blame] | 28 | /* Remove the #define below if you don't want SPI flash chip emulation. */ |
| 29 | #define EMULATE_SPI_CHIP 1 |
| 30 | |
| 31 | #if EMULATE_SPI_CHIP |
| 32 | #define EMULATE_CHIP 1 |
| 33 | #include "spi.h" |
| 34 | #endif |
| 35 | |
| 36 | #if EMULATE_CHIP |
| 37 | #include <sys/types.h> |
| 38 | #include <sys/stat.h> |
| 39 | #endif |
| 40 | |
| 41 | #if EMULATE_CHIP |
| 42 | static uint8_t *flashchip_contents = NULL; |
| 43 | enum emu_chip { |
| 44 | EMULATE_NONE, |
| 45 | EMULATE_ST_M25P10_RES, |
| 46 | EMULATE_SST_SST25VF040_REMS, |
| 47 | EMULATE_SST_SST25VF032B, |
| 48 | }; |
| 49 | static enum emu_chip emu_chip = EMULATE_NONE; |
| 50 | static char *emu_persistent_image = NULL; |
Stefan Tauner | c69c9c8 | 2011-11-23 09:13:48 +0000 | [diff] [blame] | 51 | static unsigned int emu_chip_size = 0; |
Carl-Daniel Hailfinger | f68aa8a | 2010-11-01 22:07:04 +0000 | [diff] [blame] | 52 | #if EMULATE_SPI_CHIP |
Stefan Tauner | c69c9c8 | 2011-11-23 09:13:48 +0000 | [diff] [blame] | 53 | static unsigned int emu_max_byteprogram_size = 0; |
| 54 | static unsigned int emu_max_aai_size = 0; |
| 55 | static unsigned int emu_jedec_se_size = 0; |
| 56 | static unsigned int emu_jedec_be_52_size = 0; |
| 57 | static unsigned int emu_jedec_be_d8_size = 0; |
| 58 | static unsigned int emu_jedec_ce_60_size = 0; |
| 59 | static unsigned int emu_jedec_ce_c7_size = 0; |
Carl-Daniel Hailfinger | 1b83be5 | 2012-02-08 23:28:54 +0000 | [diff] [blame] | 60 | unsigned char spi_blacklist[256]; |
| 61 | unsigned char spi_ignorelist[256]; |
| 62 | int spi_blacklist_size = 0; |
| 63 | int spi_ignorelist_size = 0; |
Carl-Daniel Hailfinger | f68aa8a | 2010-11-01 22:07:04 +0000 | [diff] [blame] | 64 | #endif |
| 65 | #endif |
| 66 | |
Stefan Tauner | c69c9c8 | 2011-11-23 09:13:48 +0000 | [diff] [blame] | 67 | static unsigned int spi_write_256_chunksize = 256; |
Carl-Daniel Hailfinger | f68aa8a | 2010-11-01 22:07:04 +0000 | [diff] [blame] | 68 | |
Carl-Daniel Hailfinger | 8a3c60c | 2011-12-18 15:01:24 +0000 | [diff] [blame] | 69 | static int dummy_spi_send_command(struct flashctx *flash, unsigned int writecnt, |
| 70 | unsigned int readcnt, |
| 71 | const unsigned char *writearr, |
| 72 | unsigned char *readarr); |
Carl-Daniel Hailfinger | 63fd902 | 2011-12-14 22:25:15 +0000 | [diff] [blame] | 73 | static int dummy_spi_write_256(struct flashctx *flash, uint8_t *buf, |
Stefan Tauner | c69c9c8 | 2011-11-23 09:13:48 +0000 | [diff] [blame] | 74 | unsigned int start, unsigned int len); |
Carl-Daniel Hailfinger | 8a3c60c | 2011-12-18 15:01:24 +0000 | [diff] [blame] | 75 | static void dummy_chip_writeb(const struct flashctx *flash, uint8_t val, |
| 76 | chipaddr addr); |
| 77 | static void dummy_chip_writew(const struct flashctx *flash, uint16_t val, |
| 78 | chipaddr addr); |
| 79 | static void dummy_chip_writel(const struct flashctx *flash, uint32_t val, |
| 80 | chipaddr addr); |
| 81 | static void dummy_chip_writen(const struct flashctx *flash, uint8_t *buf, |
| 82 | chipaddr addr, size_t len); |
| 83 | static uint8_t dummy_chip_readb(const struct flashctx *flash, |
| 84 | const chipaddr addr); |
| 85 | static uint16_t dummy_chip_readw(const struct flashctx *flash, |
| 86 | const chipaddr addr); |
| 87 | static uint32_t dummy_chip_readl(const struct flashctx *flash, |
| 88 | const chipaddr addr); |
| 89 | static void dummy_chip_readn(const struct flashctx *flash, uint8_t *buf, |
| 90 | const chipaddr addr, size_t len); |
Michael Karcher | b9dbe48 | 2011-05-11 17:07:07 +0000 | [diff] [blame] | 91 | |
| 92 | static const struct spi_programmer spi_programmer_dummyflasher = { |
Uwe Hermann | 91f4afa | 2011-07-28 08:13:25 +0000 | [diff] [blame] | 93 | .type = SPI_CONTROLLER_DUMMY, |
| 94 | .max_data_read = MAX_DATA_READ_UNLIMITED, |
| 95 | .max_data_write = MAX_DATA_UNSPECIFIED, |
| 96 | .command = dummy_spi_send_command, |
| 97 | .multicommand = default_spi_send_multicommand, |
| 98 | .read = default_spi_read, |
| 99 | .write_256 = dummy_spi_write_256, |
Michael Karcher | b9dbe48 | 2011-05-11 17:07:07 +0000 | [diff] [blame] | 100 | }; |
David Hendricks | 8bb2021 | 2011-06-14 01:35:36 +0000 | [diff] [blame] | 101 | |
Carl-Daniel Hailfinger | eaacd2d | 2011-11-09 23:40:00 +0000 | [diff] [blame] | 102 | static const struct par_programmer par_programmer_dummy = { |
| 103 | .chip_readb = dummy_chip_readb, |
| 104 | .chip_readw = dummy_chip_readw, |
| 105 | .chip_readl = dummy_chip_readl, |
| 106 | .chip_readn = dummy_chip_readn, |
| 107 | .chip_writeb = dummy_chip_writeb, |
| 108 | .chip_writew = dummy_chip_writew, |
| 109 | .chip_writel = dummy_chip_writel, |
| 110 | .chip_writen = dummy_chip_writen, |
| 111 | }; |
| 112 | |
| 113 | enum chipbustype dummy_buses_supported = BUS_NONE; |
| 114 | |
David Hendricks | 8bb2021 | 2011-06-14 01:35:36 +0000 | [diff] [blame] | 115 | static int dummy_shutdown(void *data) |
| 116 | { |
| 117 | msg_pspew("%s\n", __func__); |
| 118 | #if EMULATE_CHIP |
| 119 | if (emu_chip != EMULATE_NONE) { |
| 120 | if (emu_persistent_image) { |
| 121 | msg_pdbg("Writing %s\n", emu_persistent_image); |
| 122 | write_buf_to_file(flashchip_contents, emu_chip_size, |
| 123 | emu_persistent_image); |
| 124 | } |
| 125 | free(flashchip_contents); |
| 126 | } |
| 127 | #endif |
| 128 | return 0; |
| 129 | } |
| 130 | |
Carl-Daniel Hailfinger | c312920 | 2009-05-09 00:54:55 +0000 | [diff] [blame] | 131 | int dummy_init(void) |
| 132 | { |
Carl-Daniel Hailfinger | 744132a | 2010-07-06 09:55:48 +0000 | [diff] [blame] | 133 | char *bustext = NULL; |
Carl-Daniel Hailfinger | f68aa8a | 2010-11-01 22:07:04 +0000 | [diff] [blame] | 134 | char *tmp = NULL; |
Carl-Daniel Hailfinger | 1b83be5 | 2012-02-08 23:28:54 +0000 | [diff] [blame] | 135 | int i; |
Carl-Daniel Hailfinger | f68aa8a | 2010-11-01 22:07:04 +0000 | [diff] [blame] | 136 | #if EMULATE_CHIP |
| 137 | struct stat image_stat; |
| 138 | #endif |
Carl-Daniel Hailfinger | 744132a | 2010-07-06 09:55:48 +0000 | [diff] [blame] | 139 | |
Carl-Daniel Hailfinger | 3ac101c | 2010-01-09 04:32:23 +0000 | [diff] [blame] | 140 | msg_pspew("%s\n", __func__); |
Carl-Daniel Hailfinger | 3504b53 | 2009-06-01 00:02:11 +0000 | [diff] [blame] | 141 | |
Carl-Daniel Hailfinger | 2b6dcb3 | 2010-07-08 10:13:37 +0000 | [diff] [blame] | 142 | bustext = extract_programmer_param("bus"); |
Carl-Daniel Hailfinger | 744132a | 2010-07-06 09:55:48 +0000 | [diff] [blame] | 143 | msg_pdbg("Requested buses are: %s\n", bustext ? bustext : "default"); |
| 144 | if (!bustext) |
| 145 | bustext = strdup("parallel+lpc+fwh+spi"); |
Carl-Daniel Hailfinger | 3504b53 | 2009-06-01 00:02:11 +0000 | [diff] [blame] | 146 | /* Convert the parameters to lowercase. */ |
Carl-Daniel Hailfinger | 744132a | 2010-07-06 09:55:48 +0000 | [diff] [blame] | 147 | tolower_string(bustext); |
Carl-Daniel Hailfinger | 3504b53 | 2009-06-01 00:02:11 +0000 | [diff] [blame] | 148 | |
Carl-Daniel Hailfinger | eaacd2d | 2011-11-09 23:40:00 +0000 | [diff] [blame] | 149 | dummy_buses_supported = BUS_NONE; |
Carl-Daniel Hailfinger | 744132a | 2010-07-06 09:55:48 +0000 | [diff] [blame] | 150 | if (strstr(bustext, "parallel")) { |
Carl-Daniel Hailfinger | eaacd2d | 2011-11-09 23:40:00 +0000 | [diff] [blame] | 151 | dummy_buses_supported |= BUS_PARALLEL; |
Carl-Daniel Hailfinger | 3ac101c | 2010-01-09 04:32:23 +0000 | [diff] [blame] | 152 | msg_pdbg("Enabling support for %s flash.\n", "parallel"); |
Carl-Daniel Hailfinger | 3504b53 | 2009-06-01 00:02:11 +0000 | [diff] [blame] | 153 | } |
Carl-Daniel Hailfinger | 744132a | 2010-07-06 09:55:48 +0000 | [diff] [blame] | 154 | if (strstr(bustext, "lpc")) { |
Carl-Daniel Hailfinger | eaacd2d | 2011-11-09 23:40:00 +0000 | [diff] [blame] | 155 | dummy_buses_supported |= BUS_LPC; |
Carl-Daniel Hailfinger | 3ac101c | 2010-01-09 04:32:23 +0000 | [diff] [blame] | 156 | msg_pdbg("Enabling support for %s flash.\n", "LPC"); |
Carl-Daniel Hailfinger | 3504b53 | 2009-06-01 00:02:11 +0000 | [diff] [blame] | 157 | } |
Carl-Daniel Hailfinger | 744132a | 2010-07-06 09:55:48 +0000 | [diff] [blame] | 158 | if (strstr(bustext, "fwh")) { |
Carl-Daniel Hailfinger | eaacd2d | 2011-11-09 23:40:00 +0000 | [diff] [blame] | 159 | dummy_buses_supported |= BUS_FWH; |
Carl-Daniel Hailfinger | 3ac101c | 2010-01-09 04:32:23 +0000 | [diff] [blame] | 160 | msg_pdbg("Enabling support for %s flash.\n", "FWH"); |
Carl-Daniel Hailfinger | 3504b53 | 2009-06-01 00:02:11 +0000 | [diff] [blame] | 161 | } |
Carl-Daniel Hailfinger | 744132a | 2010-07-06 09:55:48 +0000 | [diff] [blame] | 162 | if (strstr(bustext, "spi")) { |
Carl-Daniel Hailfinger | eaacd2d | 2011-11-09 23:40:00 +0000 | [diff] [blame] | 163 | dummy_buses_supported |= BUS_SPI; |
Carl-Daniel Hailfinger | 3ac101c | 2010-01-09 04:32:23 +0000 | [diff] [blame] | 164 | msg_pdbg("Enabling support for %s flash.\n", "SPI"); |
Carl-Daniel Hailfinger | 3504b53 | 2009-06-01 00:02:11 +0000 | [diff] [blame] | 165 | } |
Carl-Daniel Hailfinger | eaacd2d | 2011-11-09 23:40:00 +0000 | [diff] [blame] | 166 | if (dummy_buses_supported == BUS_NONE) |
Carl-Daniel Hailfinger | 3ac101c | 2010-01-09 04:32:23 +0000 | [diff] [blame] | 167 | msg_pdbg("Support for all flash bus types disabled.\n"); |
Carl-Daniel Hailfinger | 744132a | 2010-07-06 09:55:48 +0000 | [diff] [blame] | 168 | free(bustext); |
Carl-Daniel Hailfinger | f68aa8a | 2010-11-01 22:07:04 +0000 | [diff] [blame] | 169 | |
| 170 | tmp = extract_programmer_param("spi_write_256_chunksize"); |
| 171 | if (tmp) { |
| 172 | spi_write_256_chunksize = atoi(tmp); |
| 173 | free(tmp); |
| 174 | if (spi_write_256_chunksize < 1) { |
| 175 | msg_perr("invalid spi_write_256_chunksize\n"); |
| 176 | return 1; |
| 177 | } |
| 178 | } |
| 179 | |
Carl-Daniel Hailfinger | 1b83be5 | 2012-02-08 23:28:54 +0000 | [diff] [blame] | 180 | tmp = extract_programmer_param("spi_blacklist"); |
| 181 | if (tmp) { |
| 182 | i = strlen(tmp); |
| 183 | if (!strncmp(tmp, "0x", 2)) { |
| 184 | i -= 2; |
| 185 | memmove(tmp, tmp + 2, i + 1); |
| 186 | } |
| 187 | if ((i > 512) || (i % 2)) { |
| 188 | msg_perr("Invalid SPI command blacklist length\n"); |
| 189 | free(tmp); |
| 190 | return 1; |
| 191 | } |
| 192 | spi_blacklist_size = i / 2; |
| 193 | for (i = 0; i < spi_blacklist_size * 2; i++) { |
| 194 | if (!isxdigit((unsigned char)tmp[i])) { |
| 195 | msg_perr("Invalid char \"%c\" in SPI command " |
| 196 | "blacklist\n", tmp[i]); |
| 197 | free(tmp); |
| 198 | return 1; |
| 199 | } |
| 200 | } |
| 201 | for (i = 0; i < spi_blacklist_size; i++) { |
Carl-Daniel Hailfinger | 5b55471 | 2012-02-16 01:43:06 +0000 | [diff] [blame] | 202 | unsigned int tmp2; |
| 203 | /* SCNx8 is apparently not supported by MSVC (and thus |
| 204 | * MinGW), so work around it with an extra variable |
| 205 | */ |
| 206 | sscanf(tmp + i * 2, "%2x", &tmp2); |
| 207 | spi_blacklist[i] = (uint8_t)tmp2; |
Carl-Daniel Hailfinger | 1b83be5 | 2012-02-08 23:28:54 +0000 | [diff] [blame] | 208 | } |
| 209 | msg_pdbg("SPI blacklist is "); |
| 210 | for (i = 0; i < spi_blacklist_size; i++) |
| 211 | msg_pdbg("%02x ", spi_blacklist[i]); |
| 212 | msg_pdbg(", size %i\n", spi_blacklist_size); |
| 213 | } |
| 214 | free(tmp); |
| 215 | |
| 216 | tmp = extract_programmer_param("spi_ignorelist"); |
| 217 | if (tmp) { |
| 218 | i = strlen(tmp); |
| 219 | if (!strncmp(tmp, "0x", 2)) { |
| 220 | i -= 2; |
| 221 | memmove(tmp, tmp + 2, i + 1); |
| 222 | } |
| 223 | if ((i > 512) || (i % 2)) { |
| 224 | msg_perr("Invalid SPI command ignorelist length\n"); |
| 225 | free(tmp); |
| 226 | return 1; |
| 227 | } |
| 228 | spi_ignorelist_size = i / 2; |
| 229 | for (i = 0; i < spi_ignorelist_size * 2; i++) { |
| 230 | if (!isxdigit((unsigned char)tmp[i])) { |
| 231 | msg_perr("Invalid char \"%c\" in SPI command " |
| 232 | "ignorelist\n", tmp[i]); |
| 233 | free(tmp); |
| 234 | return 1; |
| 235 | } |
| 236 | } |
| 237 | for (i = 0; i < spi_ignorelist_size; i++) { |
Carl-Daniel Hailfinger | 5b55471 | 2012-02-16 01:43:06 +0000 | [diff] [blame] | 238 | unsigned int tmp2; |
| 239 | /* SCNx8 is apparently not supported by MSVC (and thus |
| 240 | * MinGW), so work around it with an extra variable |
| 241 | */ |
| 242 | sscanf(tmp + i * 2, "%2x", &tmp2); |
| 243 | spi_ignorelist[i] = (uint8_t)tmp2; |
Carl-Daniel Hailfinger | 1b83be5 | 2012-02-08 23:28:54 +0000 | [diff] [blame] | 244 | } |
| 245 | msg_pdbg("SPI ignorelist is "); |
| 246 | for (i = 0; i < spi_ignorelist_size; i++) |
| 247 | msg_pdbg("%02x ", spi_ignorelist[i]); |
| 248 | msg_pdbg(", size %i\n", spi_ignorelist_size); |
| 249 | } |
| 250 | free(tmp); |
| 251 | |
Carl-Daniel Hailfinger | f68aa8a | 2010-11-01 22:07:04 +0000 | [diff] [blame] | 252 | #if EMULATE_CHIP |
| 253 | tmp = extract_programmer_param("emulate"); |
| 254 | if (!tmp) { |
| 255 | msg_pdbg("Not emulating any flash chip.\n"); |
| 256 | /* Nothing else to do. */ |
David Hendricks | 8bb2021 | 2011-06-14 01:35:36 +0000 | [diff] [blame] | 257 | goto dummy_init_out; |
Carl-Daniel Hailfinger | f68aa8a | 2010-11-01 22:07:04 +0000 | [diff] [blame] | 258 | } |
| 259 | #if EMULATE_SPI_CHIP |
| 260 | if (!strcmp(tmp, "M25P10.RES")) { |
| 261 | emu_chip = EMULATE_ST_M25P10_RES; |
| 262 | emu_chip_size = 128 * 1024; |
| 263 | emu_max_byteprogram_size = 128; |
| 264 | emu_max_aai_size = 0; |
| 265 | emu_jedec_se_size = 0; |
| 266 | emu_jedec_be_52_size = 0; |
| 267 | emu_jedec_be_d8_size = 32 * 1024; |
| 268 | emu_jedec_ce_60_size = 0; |
| 269 | emu_jedec_ce_c7_size = emu_chip_size; |
| 270 | msg_pdbg("Emulating ST M25P10.RES SPI flash chip (RES, page " |
| 271 | "write)\n"); |
| 272 | } |
| 273 | if (!strcmp(tmp, "SST25VF040.REMS")) { |
| 274 | emu_chip = EMULATE_SST_SST25VF040_REMS; |
| 275 | emu_chip_size = 512 * 1024; |
| 276 | emu_max_byteprogram_size = 1; |
| 277 | emu_max_aai_size = 0; |
| 278 | emu_jedec_se_size = 4 * 1024; |
| 279 | emu_jedec_be_52_size = 32 * 1024; |
| 280 | emu_jedec_be_d8_size = 0; |
| 281 | emu_jedec_ce_60_size = emu_chip_size; |
| 282 | emu_jedec_ce_c7_size = 0; |
| 283 | msg_pdbg("Emulating SST SST25VF040.REMS SPI flash chip (REMS, " |
| 284 | "byte write)\n"); |
| 285 | } |
| 286 | if (!strcmp(tmp, "SST25VF032B")) { |
| 287 | emu_chip = EMULATE_SST_SST25VF032B; |
| 288 | emu_chip_size = 4 * 1024 * 1024; |
| 289 | emu_max_byteprogram_size = 1; |
| 290 | emu_max_aai_size = 2; |
| 291 | emu_jedec_se_size = 4 * 1024; |
| 292 | emu_jedec_be_52_size = 32 * 1024; |
| 293 | emu_jedec_be_d8_size = 64 * 1024; |
| 294 | emu_jedec_ce_60_size = emu_chip_size; |
| 295 | emu_jedec_ce_c7_size = emu_chip_size; |
| 296 | msg_pdbg("Emulating SST SST25VF032B SPI flash chip (RDID, AAI " |
| 297 | "write)\n"); |
| 298 | } |
| 299 | #endif |
| 300 | if (emu_chip == EMULATE_NONE) { |
| 301 | msg_perr("Invalid chip specified for emulation: %s\n", tmp); |
| 302 | free(tmp); |
| 303 | return 1; |
| 304 | } |
| 305 | free(tmp); |
| 306 | flashchip_contents = malloc(emu_chip_size); |
| 307 | if (!flashchip_contents) { |
| 308 | msg_perr("Out of memory!\n"); |
| 309 | return 1; |
| 310 | } |
David Hendricks | 8bb2021 | 2011-06-14 01:35:36 +0000 | [diff] [blame] | 311 | |
Carl-Daniel Hailfinger | f68aa8a | 2010-11-01 22:07:04 +0000 | [diff] [blame] | 312 | msg_pdbg("Filling fake flash chip with 0xff, size %i\n", emu_chip_size); |
| 313 | memset(flashchip_contents, 0xff, emu_chip_size); |
| 314 | |
| 315 | emu_persistent_image = extract_programmer_param("image"); |
| 316 | if (!emu_persistent_image) { |
| 317 | /* Nothing else to do. */ |
David Hendricks | 8bb2021 | 2011-06-14 01:35:36 +0000 | [diff] [blame] | 318 | goto dummy_init_out; |
Carl-Daniel Hailfinger | f68aa8a | 2010-11-01 22:07:04 +0000 | [diff] [blame] | 319 | } |
| 320 | if (!stat(emu_persistent_image, &image_stat)) { |
| 321 | msg_pdbg("Found persistent image %s, size %li ", |
| 322 | emu_persistent_image, (long)image_stat.st_size); |
| 323 | if (image_stat.st_size == emu_chip_size) { |
| 324 | msg_pdbg("matches.\n"); |
| 325 | msg_pdbg("Reading %s\n", emu_persistent_image); |
| 326 | read_buf_from_file(flashchip_contents, emu_chip_size, |
| 327 | emu_persistent_image); |
| 328 | } else { |
| 329 | msg_pdbg("doesn't match.\n"); |
| 330 | } |
| 331 | } |
| 332 | #endif |
Carl-Daniel Hailfinger | c312920 | 2009-05-09 00:54:55 +0000 | [diff] [blame] | 333 | |
David Hendricks | 8bb2021 | 2011-06-14 01:35:36 +0000 | [diff] [blame] | 334 | dummy_init_out: |
| 335 | if (register_shutdown(dummy_shutdown, NULL)) { |
Carl-Daniel Hailfinger | f68aa8a | 2010-11-01 22:07:04 +0000 | [diff] [blame] | 336 | free(flashchip_contents); |
David Hendricks | 8bb2021 | 2011-06-14 01:35:36 +0000 | [diff] [blame] | 337 | return 1; |
Carl-Daniel Hailfinger | f68aa8a | 2010-11-01 22:07:04 +0000 | [diff] [blame] | 338 | } |
Carl-Daniel Hailfinger | eaacd2d | 2011-11-09 23:40:00 +0000 | [diff] [blame] | 339 | if (dummy_buses_supported & (BUS_PARALLEL | BUS_LPC | BUS_FWH)) |
| 340 | register_par_programmer(&par_programmer_dummy, |
| 341 | dummy_buses_supported & |
| 342 | (BUS_PARALLEL | BUS_LPC | |
| 343 | BUS_FWH)); |
| 344 | if (dummy_buses_supported & BUS_SPI) |
| 345 | register_spi_programmer(&spi_programmer_dummyflasher); |
| 346 | |
Carl-Daniel Hailfinger | c312920 | 2009-05-09 00:54:55 +0000 | [diff] [blame] | 347 | return 0; |
| 348 | } |
| 349 | |
Carl-Daniel Hailfinger | 1455b2b | 2009-05-11 14:13:25 +0000 | [diff] [blame] | 350 | void *dummy_map(const char *descr, unsigned long phys_addr, size_t len) |
| 351 | { |
Carl-Daniel Hailfinger | 3ac101c | 2010-01-09 04:32:23 +0000 | [diff] [blame] | 352 | msg_pspew("%s: Mapping %s, 0x%lx bytes at 0x%08lx\n", |
| 353 | __func__, descr, (unsigned long)len, phys_addr); |
Carl-Daniel Hailfinger | 1455b2b | 2009-05-11 14:13:25 +0000 | [diff] [blame] | 354 | return (void *)phys_addr; |
| 355 | } |
| 356 | |
| 357 | void dummy_unmap(void *virt_addr, size_t len) |
| 358 | { |
Carl-Daniel Hailfinger | 3ac101c | 2010-01-09 04:32:23 +0000 | [diff] [blame] | 359 | msg_pspew("%s: Unmapping 0x%lx bytes at %p\n", |
| 360 | __func__, (unsigned long)len, virt_addr); |
Carl-Daniel Hailfinger | 1455b2b | 2009-05-11 14:13:25 +0000 | [diff] [blame] | 361 | } |
| 362 | |
Carl-Daniel Hailfinger | 8a3c60c | 2011-12-18 15:01:24 +0000 | [diff] [blame] | 363 | static void dummy_chip_writeb(const struct flashctx *flash, uint8_t val, |
| 364 | chipaddr addr) |
Carl-Daniel Hailfinger | c312920 | 2009-05-09 00:54:55 +0000 | [diff] [blame] | 365 | { |
Carl-Daniel Hailfinger | 3ac101c | 2010-01-09 04:32:23 +0000 | [diff] [blame] | 366 | msg_pspew("%s: addr=0x%lx, val=0x%02x\n", __func__, addr, val); |
Carl-Daniel Hailfinger | c312920 | 2009-05-09 00:54:55 +0000 | [diff] [blame] | 367 | } |
| 368 | |
Carl-Daniel Hailfinger | 8a3c60c | 2011-12-18 15:01:24 +0000 | [diff] [blame] | 369 | static void dummy_chip_writew(const struct flashctx *flash, uint16_t val, |
| 370 | chipaddr addr) |
Carl-Daniel Hailfinger | c312920 | 2009-05-09 00:54:55 +0000 | [diff] [blame] | 371 | { |
Carl-Daniel Hailfinger | 3ac101c | 2010-01-09 04:32:23 +0000 | [diff] [blame] | 372 | msg_pspew("%s: addr=0x%lx, val=0x%04x\n", __func__, addr, val); |
Carl-Daniel Hailfinger | c312920 | 2009-05-09 00:54:55 +0000 | [diff] [blame] | 373 | } |
| 374 | |
Carl-Daniel Hailfinger | 8a3c60c | 2011-12-18 15:01:24 +0000 | [diff] [blame] | 375 | static void dummy_chip_writel(const struct flashctx *flash, uint32_t val, |
| 376 | chipaddr addr) |
Carl-Daniel Hailfinger | c312920 | 2009-05-09 00:54:55 +0000 | [diff] [blame] | 377 | { |
Carl-Daniel Hailfinger | 3ac101c | 2010-01-09 04:32:23 +0000 | [diff] [blame] | 378 | msg_pspew("%s: addr=0x%lx, val=0x%08x\n", __func__, addr, val); |
Carl-Daniel Hailfinger | c312920 | 2009-05-09 00:54:55 +0000 | [diff] [blame] | 379 | } |
| 380 | |
Carl-Daniel Hailfinger | 8a3c60c | 2011-12-18 15:01:24 +0000 | [diff] [blame] | 381 | static void dummy_chip_writen(const struct flashctx *flash, uint8_t *buf, |
| 382 | chipaddr addr, size_t len) |
Carl-Daniel Hailfinger | 0bd2a2b | 2009-06-05 18:32:07 +0000 | [diff] [blame] | 383 | { |
| 384 | size_t i; |
Carl-Daniel Hailfinger | 3ac101c | 2010-01-09 04:32:23 +0000 | [diff] [blame] | 385 | msg_pspew("%s: addr=0x%lx, len=0x%08lx, writing data (hex):", |
| 386 | __func__, addr, (unsigned long)len); |
Carl-Daniel Hailfinger | 0bd2a2b | 2009-06-05 18:32:07 +0000 | [diff] [blame] | 387 | for (i = 0; i < len; i++) { |
| 388 | if ((i % 16) == 0) |
Carl-Daniel Hailfinger | 3ac101c | 2010-01-09 04:32:23 +0000 | [diff] [blame] | 389 | msg_pspew("\n"); |
| 390 | msg_pspew("%02x ", buf[i]); |
Carl-Daniel Hailfinger | 0bd2a2b | 2009-06-05 18:32:07 +0000 | [diff] [blame] | 391 | } |
| 392 | } |
| 393 | |
Carl-Daniel Hailfinger | 8a3c60c | 2011-12-18 15:01:24 +0000 | [diff] [blame] | 394 | static uint8_t dummy_chip_readb(const struct flashctx *flash, |
| 395 | const chipaddr addr) |
Carl-Daniel Hailfinger | c312920 | 2009-05-09 00:54:55 +0000 | [diff] [blame] | 396 | { |
Carl-Daniel Hailfinger | 3ac101c | 2010-01-09 04:32:23 +0000 | [diff] [blame] | 397 | msg_pspew("%s: addr=0x%lx, returning 0xff\n", __func__, addr); |
Carl-Daniel Hailfinger | c312920 | 2009-05-09 00:54:55 +0000 | [diff] [blame] | 398 | return 0xff; |
| 399 | } |
| 400 | |
Carl-Daniel Hailfinger | 8a3c60c | 2011-12-18 15:01:24 +0000 | [diff] [blame] | 401 | static uint16_t dummy_chip_readw(const struct flashctx *flash, |
| 402 | const chipaddr addr) |
Carl-Daniel Hailfinger | c312920 | 2009-05-09 00:54:55 +0000 | [diff] [blame] | 403 | { |
Carl-Daniel Hailfinger | 3ac101c | 2010-01-09 04:32:23 +0000 | [diff] [blame] | 404 | msg_pspew("%s: addr=0x%lx, returning 0xffff\n", __func__, addr); |
Carl-Daniel Hailfinger | c312920 | 2009-05-09 00:54:55 +0000 | [diff] [blame] | 405 | return 0xffff; |
| 406 | } |
| 407 | |
Carl-Daniel Hailfinger | 8a3c60c | 2011-12-18 15:01:24 +0000 | [diff] [blame] | 408 | static uint32_t dummy_chip_readl(const struct flashctx *flash, |
| 409 | const chipaddr addr) |
Carl-Daniel Hailfinger | c312920 | 2009-05-09 00:54:55 +0000 | [diff] [blame] | 410 | { |
Carl-Daniel Hailfinger | 3ac101c | 2010-01-09 04:32:23 +0000 | [diff] [blame] | 411 | msg_pspew("%s: addr=0x%lx, returning 0xffffffff\n", __func__, addr); |
Carl-Daniel Hailfinger | c312920 | 2009-05-09 00:54:55 +0000 | [diff] [blame] | 412 | return 0xffffffff; |
| 413 | } |
| 414 | |
Carl-Daniel Hailfinger | 8a3c60c | 2011-12-18 15:01:24 +0000 | [diff] [blame] | 415 | static void dummy_chip_readn(const struct flashctx *flash, uint8_t *buf, |
| 416 | const chipaddr addr, size_t len) |
Carl-Daniel Hailfinger | 0bd2a2b | 2009-06-05 18:32:07 +0000 | [diff] [blame] | 417 | { |
Carl-Daniel Hailfinger | 3ac101c | 2010-01-09 04:32:23 +0000 | [diff] [blame] | 418 | msg_pspew("%s: addr=0x%lx, len=0x%lx, returning array of 0xff\n", |
| 419 | __func__, addr, (unsigned long)len); |
Carl-Daniel Hailfinger | 0bd2a2b | 2009-06-05 18:32:07 +0000 | [diff] [blame] | 420 | memset(buf, 0xff, len); |
| 421 | return; |
| 422 | } |
| 423 | |
Carl-Daniel Hailfinger | f68aa8a | 2010-11-01 22:07:04 +0000 | [diff] [blame] | 424 | #if EMULATE_SPI_CHIP |
Carl-Daniel Hailfinger | 8a3c60c | 2011-12-18 15:01:24 +0000 | [diff] [blame] | 425 | static int emulate_spi_chip_response(unsigned int writecnt, |
| 426 | unsigned int readcnt, |
| 427 | const unsigned char *writearr, |
| 428 | unsigned char *readarr) |
Carl-Daniel Hailfinger | f68aa8a | 2010-11-01 22:07:04 +0000 | [diff] [blame] | 429 | { |
Carl-Daniel Hailfinger | 1b83be5 | 2012-02-08 23:28:54 +0000 | [diff] [blame] | 430 | unsigned int offs, i; |
Stefan Tauner | c69c9c8 | 2011-11-23 09:13:48 +0000 | [diff] [blame] | 431 | static int unsigned aai_offs; |
Carl-Daniel Hailfinger | f68aa8a | 2010-11-01 22:07:04 +0000 | [diff] [blame] | 432 | static int aai_active = 0; |
| 433 | |
| 434 | if (writecnt == 0) { |
| 435 | msg_perr("No command sent to the chip!\n"); |
| 436 | return 1; |
| 437 | } |
Paul Menzel | ac427b2 | 2012-02-16 21:07:07 +0000 | [diff] [blame] | 438 | /* spi_blacklist has precedence over spi_ignorelist. */ |
Carl-Daniel Hailfinger | 1b83be5 | 2012-02-08 23:28:54 +0000 | [diff] [blame] | 439 | for (i = 0; i < spi_blacklist_size; i++) { |
| 440 | if (writearr[0] == spi_blacklist[i]) { |
| 441 | msg_pdbg("Refusing blacklisted SPI command 0x%02x\n", |
| 442 | spi_blacklist[i]); |
| 443 | return SPI_INVALID_OPCODE; |
| 444 | } |
| 445 | } |
| 446 | for (i = 0; i < spi_ignorelist_size; i++) { |
| 447 | if (writearr[0] == spi_ignorelist[i]) { |
| 448 | msg_cdbg("Ignoring ignorelisted SPI command 0x%02x\n", |
| 449 | spi_ignorelist[i]); |
| 450 | /* Return success because the command does not fail, |
| 451 | * it is simply ignored. |
| 452 | */ |
| 453 | return 0; |
| 454 | } |
| 455 | } |
Carl-Daniel Hailfinger | f68aa8a | 2010-11-01 22:07:04 +0000 | [diff] [blame] | 456 | switch (writearr[0]) { |
| 457 | case JEDEC_RES: |
| 458 | if (emu_chip != EMULATE_ST_M25P10_RES) |
| 459 | break; |
| 460 | /* Respond with ST_M25P10_RES. */ |
| 461 | if (readcnt > 0) |
| 462 | readarr[0] = 0x10; |
| 463 | break; |
| 464 | case JEDEC_REMS: |
| 465 | if (emu_chip != EMULATE_SST_SST25VF040_REMS) |
| 466 | break; |
| 467 | /* Respond with SST_SST25VF040_REMS. */ |
| 468 | if (readcnt > 0) |
| 469 | readarr[0] = 0xbf; |
| 470 | if (readcnt > 1) |
| 471 | readarr[1] = 0x44; |
| 472 | break; |
| 473 | case JEDEC_RDID: |
| 474 | if (emu_chip != EMULATE_SST_SST25VF032B) |
| 475 | break; |
| 476 | /* Respond with SST_SST25VF032B. */ |
| 477 | if (readcnt > 0) |
| 478 | readarr[0] = 0xbf; |
| 479 | if (readcnt > 1) |
| 480 | readarr[1] = 0x25; |
| 481 | if (readcnt > 2) |
| 482 | readarr[2] = 0x4a; |
| 483 | break; |
| 484 | case JEDEC_RDSR: |
| 485 | memset(readarr, 0, readcnt); |
| 486 | if (aai_active) |
| 487 | memset(readarr, 1 << 6, readcnt); |
| 488 | break; |
| 489 | case JEDEC_READ: |
| 490 | offs = writearr[1] << 16 | writearr[2] << 8 | writearr[3]; |
| 491 | /* Truncate to emu_chip_size. */ |
| 492 | offs %= emu_chip_size; |
| 493 | if (readcnt > 0) |
| 494 | memcpy(readarr, flashchip_contents + offs, readcnt); |
| 495 | break; |
| 496 | case JEDEC_BYTE_PROGRAM: |
| 497 | offs = writearr[1] << 16 | writearr[2] << 8 | writearr[3]; |
| 498 | /* Truncate to emu_chip_size. */ |
| 499 | offs %= emu_chip_size; |
| 500 | if (writecnt < 5) { |
| 501 | msg_perr("BYTE PROGRAM size too short!\n"); |
| 502 | return 1; |
| 503 | } |
| 504 | if (writecnt - 4 > emu_max_byteprogram_size) { |
| 505 | msg_perr("Max BYTE PROGRAM size exceeded!\n"); |
| 506 | return 1; |
| 507 | } |
| 508 | memcpy(flashchip_contents + offs, writearr + 4, writecnt - 4); |
| 509 | break; |
| 510 | case JEDEC_AAI_WORD_PROGRAM: |
| 511 | if (!emu_max_aai_size) |
| 512 | break; |
| 513 | if (!aai_active) { |
| 514 | if (writecnt < JEDEC_AAI_WORD_PROGRAM_OUTSIZE) { |
| 515 | msg_perr("Initial AAI WORD PROGRAM size too " |
| 516 | "short!\n"); |
| 517 | return 1; |
| 518 | } |
| 519 | if (writecnt > JEDEC_AAI_WORD_PROGRAM_OUTSIZE) { |
| 520 | msg_perr("Initial AAI WORD PROGRAM size too " |
| 521 | "long!\n"); |
| 522 | return 1; |
| 523 | } |
| 524 | aai_active = 1; |
| 525 | aai_offs = writearr[1] << 16 | writearr[2] << 8 | |
| 526 | writearr[3]; |
| 527 | /* Truncate to emu_chip_size. */ |
| 528 | aai_offs %= emu_chip_size; |
| 529 | memcpy(flashchip_contents + aai_offs, writearr + 4, 2); |
| 530 | aai_offs += 2; |
| 531 | } else { |
| 532 | if (writecnt < JEDEC_AAI_WORD_PROGRAM_CONT_OUTSIZE) { |
| 533 | msg_perr("Continuation AAI WORD PROGRAM size " |
| 534 | "too short!\n"); |
| 535 | return 1; |
| 536 | } |
| 537 | if (writecnt > JEDEC_AAI_WORD_PROGRAM_CONT_OUTSIZE) { |
| 538 | msg_perr("Continuation AAI WORD PROGRAM size " |
| 539 | "too long!\n"); |
| 540 | return 1; |
| 541 | } |
| 542 | memcpy(flashchip_contents + aai_offs, writearr + 1, 2); |
| 543 | aai_offs += 2; |
| 544 | } |
| 545 | break; |
| 546 | case JEDEC_WRDI: |
| 547 | if (!emu_max_aai_size) |
| 548 | break; |
| 549 | aai_active = 0; |
| 550 | break; |
| 551 | case JEDEC_SE: |
| 552 | if (!emu_jedec_se_size) |
| 553 | break; |
| 554 | if (writecnt != JEDEC_SE_OUTSIZE) { |
| 555 | msg_perr("SECTOR ERASE 0x20 outsize invalid!\n"); |
| 556 | return 1; |
| 557 | } |
| 558 | if (readcnt != JEDEC_SE_INSIZE) { |
| 559 | msg_perr("SECTOR ERASE 0x20 insize invalid!\n"); |
| 560 | return 1; |
| 561 | } |
| 562 | offs = writearr[1] << 16 | writearr[2] << 8 | writearr[3]; |
| 563 | if (offs & (emu_jedec_se_size - 1)) |
Carl-Daniel Hailfinger | 146b77d | 2011-02-04 22:52:04 +0000 | [diff] [blame] | 564 | msg_pdbg("Unaligned SECTOR ERASE 0x20: 0x%x\n", offs); |
Carl-Daniel Hailfinger | f68aa8a | 2010-11-01 22:07:04 +0000 | [diff] [blame] | 565 | offs &= ~(emu_jedec_se_size - 1); |
| 566 | memset(flashchip_contents + offs, 0xff, emu_jedec_se_size); |
| 567 | break; |
| 568 | case JEDEC_BE_52: |
| 569 | if (!emu_jedec_be_52_size) |
| 570 | break; |
| 571 | if (writecnt != JEDEC_BE_52_OUTSIZE) { |
| 572 | msg_perr("BLOCK ERASE 0x52 outsize invalid!\n"); |
| 573 | return 1; |
| 574 | } |
| 575 | if (readcnt != JEDEC_BE_52_INSIZE) { |
| 576 | msg_perr("BLOCK ERASE 0x52 insize invalid!\n"); |
| 577 | return 1; |
| 578 | } |
| 579 | offs = writearr[1] << 16 | writearr[2] << 8 | writearr[3]; |
| 580 | if (offs & (emu_jedec_be_52_size - 1)) |
Carl-Daniel Hailfinger | 146b77d | 2011-02-04 22:52:04 +0000 | [diff] [blame] | 581 | msg_pdbg("Unaligned BLOCK ERASE 0x52: 0x%x\n", offs); |
Carl-Daniel Hailfinger | f68aa8a | 2010-11-01 22:07:04 +0000 | [diff] [blame] | 582 | offs &= ~(emu_jedec_be_52_size - 1); |
| 583 | memset(flashchip_contents + offs, 0xff, emu_jedec_be_52_size); |
| 584 | break; |
| 585 | case JEDEC_BE_D8: |
| 586 | if (!emu_jedec_be_d8_size) |
| 587 | break; |
| 588 | if (writecnt != JEDEC_BE_D8_OUTSIZE) { |
| 589 | msg_perr("BLOCK ERASE 0xd8 outsize invalid!\n"); |
| 590 | return 1; |
| 591 | } |
| 592 | if (readcnt != JEDEC_BE_D8_INSIZE) { |
| 593 | msg_perr("BLOCK ERASE 0xd8 insize invalid!\n"); |
| 594 | return 1; |
| 595 | } |
| 596 | offs = writearr[1] << 16 | writearr[2] << 8 | writearr[3]; |
| 597 | if (offs & (emu_jedec_be_d8_size - 1)) |
Carl-Daniel Hailfinger | 146b77d | 2011-02-04 22:52:04 +0000 | [diff] [blame] | 598 | msg_pdbg("Unaligned BLOCK ERASE 0xd8: 0x%x\n", offs); |
Carl-Daniel Hailfinger | f68aa8a | 2010-11-01 22:07:04 +0000 | [diff] [blame] | 599 | offs &= ~(emu_jedec_be_d8_size - 1); |
| 600 | memset(flashchip_contents + offs, 0xff, emu_jedec_be_d8_size); |
| 601 | break; |
| 602 | case JEDEC_CE_60: |
| 603 | if (!emu_jedec_ce_60_size) |
| 604 | break; |
| 605 | if (writecnt != JEDEC_CE_60_OUTSIZE) { |
| 606 | msg_perr("CHIP ERASE 0x60 outsize invalid!\n"); |
| 607 | return 1; |
| 608 | } |
| 609 | if (readcnt != JEDEC_CE_60_INSIZE) { |
| 610 | msg_perr("CHIP ERASE 0x60 insize invalid!\n"); |
| 611 | return 1; |
| 612 | } |
Carl-Daniel Hailfinger | 146b77d | 2011-02-04 22:52:04 +0000 | [diff] [blame] | 613 | /* JEDEC_CE_60_OUTSIZE is 1 (no address) -> no offset. */ |
Carl-Daniel Hailfinger | f68aa8a | 2010-11-01 22:07:04 +0000 | [diff] [blame] | 614 | /* emu_jedec_ce_60_size is emu_chip_size. */ |
Carl-Daniel Hailfinger | 146b77d | 2011-02-04 22:52:04 +0000 | [diff] [blame] | 615 | memset(flashchip_contents, 0xff, emu_jedec_ce_60_size); |
Carl-Daniel Hailfinger | f68aa8a | 2010-11-01 22:07:04 +0000 | [diff] [blame] | 616 | break; |
| 617 | case JEDEC_CE_C7: |
| 618 | if (!emu_jedec_ce_c7_size) |
| 619 | break; |
| 620 | if (writecnt != JEDEC_CE_C7_OUTSIZE) { |
| 621 | msg_perr("CHIP ERASE 0xc7 outsize invalid!\n"); |
| 622 | return 1; |
| 623 | } |
| 624 | if (readcnt != JEDEC_CE_C7_INSIZE) { |
| 625 | msg_perr("CHIP ERASE 0xc7 insize invalid!\n"); |
| 626 | return 1; |
| 627 | } |
Carl-Daniel Hailfinger | 146b77d | 2011-02-04 22:52:04 +0000 | [diff] [blame] | 628 | /* JEDEC_CE_C7_OUTSIZE is 1 (no address) -> no offset. */ |
Carl-Daniel Hailfinger | f68aa8a | 2010-11-01 22:07:04 +0000 | [diff] [blame] | 629 | /* emu_jedec_ce_c7_size is emu_chip_size. */ |
| 630 | memset(flashchip_contents, 0xff, emu_jedec_ce_c7_size); |
| 631 | break; |
| 632 | default: |
| 633 | /* No special response. */ |
| 634 | break; |
| 635 | } |
| 636 | return 0; |
| 637 | } |
| 638 | #endif |
| 639 | |
Carl-Daniel Hailfinger | 8a3c60c | 2011-12-18 15:01:24 +0000 | [diff] [blame] | 640 | static int dummy_spi_send_command(struct flashctx *flash, unsigned int writecnt, |
| 641 | unsigned int readcnt, |
| 642 | const unsigned char *writearr, |
| 643 | unsigned char *readarr) |
Carl-Daniel Hailfinger | bfe2e0c | 2009-05-14 12:59:36 +0000 | [diff] [blame] | 644 | { |
| 645 | int i; |
| 646 | |
Carl-Daniel Hailfinger | 3ac101c | 2010-01-09 04:32:23 +0000 | [diff] [blame] | 647 | msg_pspew("%s:", __func__); |
Carl-Daniel Hailfinger | bfe2e0c | 2009-05-14 12:59:36 +0000 | [diff] [blame] | 648 | |
Carl-Daniel Hailfinger | 3ac101c | 2010-01-09 04:32:23 +0000 | [diff] [blame] | 649 | msg_pspew(" writing %u bytes:", writecnt); |
Carl-Daniel Hailfinger | bfe2e0c | 2009-05-14 12:59:36 +0000 | [diff] [blame] | 650 | for (i = 0; i < writecnt; i++) |
Carl-Daniel Hailfinger | 3ac101c | 2010-01-09 04:32:23 +0000 | [diff] [blame] | 651 | msg_pspew(" 0x%02x", writearr[i]); |
Carl-Daniel Hailfinger | bfe2e0c | 2009-05-14 12:59:36 +0000 | [diff] [blame] | 652 | |
Carl-Daniel Hailfinger | f68aa8a | 2010-11-01 22:07:04 +0000 | [diff] [blame] | 653 | /* Response for unknown commands and missing chip is 0xff. */ |
| 654 | memset(readarr, 0xff, readcnt); |
| 655 | #if EMULATE_SPI_CHIP |
| 656 | switch (emu_chip) { |
| 657 | case EMULATE_ST_M25P10_RES: |
| 658 | case EMULATE_SST_SST25VF040_REMS: |
| 659 | case EMULATE_SST_SST25VF032B: |
| 660 | if (emulate_spi_chip_response(writecnt, readcnt, writearr, |
| 661 | readarr)) { |
Carl-Daniel Hailfinger | 1b83be5 | 2012-02-08 23:28:54 +0000 | [diff] [blame] | 662 | msg_pdbg("Invalid command sent to flash chip!\n"); |
Carl-Daniel Hailfinger | f68aa8a | 2010-11-01 22:07:04 +0000 | [diff] [blame] | 663 | return 1; |
| 664 | } |
| 665 | break; |
| 666 | default: |
| 667 | break; |
| 668 | } |
| 669 | #endif |
Carl-Daniel Hailfinger | 3ac101c | 2010-01-09 04:32:23 +0000 | [diff] [blame] | 670 | msg_pspew(" reading %u bytes:", readcnt); |
Uwe Hermann | 91f4afa | 2011-07-28 08:13:25 +0000 | [diff] [blame] | 671 | for (i = 0; i < readcnt; i++) |
Carl-Daniel Hailfinger | f68aa8a | 2010-11-01 22:07:04 +0000 | [diff] [blame] | 672 | msg_pspew(" 0x%02x", readarr[i]); |
Carl-Daniel Hailfinger | 3ac101c | 2010-01-09 04:32:23 +0000 | [diff] [blame] | 673 | msg_pspew("\n"); |
Carl-Daniel Hailfinger | bfe2e0c | 2009-05-14 12:59:36 +0000 | [diff] [blame] | 674 | return 0; |
| 675 | } |
Carl-Daniel Hailfinger | 1b0ba89 | 2010-06-20 10:58:32 +0000 | [diff] [blame] | 676 | |
Carl-Daniel Hailfinger | 63fd902 | 2011-12-14 22:25:15 +0000 | [diff] [blame] | 677 | static int dummy_spi_write_256(struct flashctx *flash, uint8_t *buf, |
Stefan Tauner | c69c9c8 | 2011-11-23 09:13:48 +0000 | [diff] [blame] | 678 | unsigned int start, unsigned int len) |
Carl-Daniel Hailfinger | 9a795d8 | 2010-07-14 16:19:05 +0000 | [diff] [blame] | 679 | { |
Carl-Daniel Hailfinger | f68aa8a | 2010-11-01 22:07:04 +0000 | [diff] [blame] | 680 | return spi_write_chunked(flash, buf, start, len, |
| 681 | spi_write_256_chunksize); |
Carl-Daniel Hailfinger | 9a795d8 | 2010-07-14 16:19:05 +0000 | [diff] [blame] | 682 | } |