Changeset 1490
- Timestamp:
- Feb 9, 2012 12:28:54 AM (17 months ago)
- Location:
- trunk
- Files:
-
- 2 edited
-
dummyflasher.c (modified) (7 diffs)
-
flashrom.8 (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/dummyflasher.c
r1474 r1490 20 20 #include <string.h> 21 21 #include <stdlib.h> 22 #include <stdio.h> 23 #include <ctype.h> 22 24 #include "flash.h" 23 25 #include "chipdrivers.h" … … 56 58 static unsigned int emu_jedec_ce_60_size = 0; 57 59 static unsigned int emu_jedec_ce_c7_size = 0; 60 unsigned char spi_blacklist[256]; 61 unsigned char spi_ignorelist[256]; 62 int spi_blacklist_size = 0; 63 int spi_ignorelist_size = 0; 58 64 #endif 59 65 #endif … … 127 133 char *bustext = NULL; 128 134 char *tmp = NULL; 135 int i; 129 136 #if EMULATE_CHIP 130 137 struct stat image_stat; … … 170 177 } 171 178 } 179 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++) { 202 sscanf(tmp + i * 2, "%2hhx", &spi_blacklist[i]); 203 } 204 msg_pdbg("SPI blacklist is "); 205 for (i = 0; i < spi_blacklist_size; i++) 206 msg_pdbg("%02x ", spi_blacklist[i]); 207 msg_pdbg(", size %i\n", spi_blacklist_size); 208 } 209 free(tmp); 210 211 tmp = extract_programmer_param("spi_ignorelist"); 212 if (tmp) { 213 i = strlen(tmp); 214 if (!strncmp(tmp, "0x", 2)) { 215 i -= 2; 216 memmove(tmp, tmp + 2, i + 1); 217 } 218 if ((i > 512) || (i % 2)) { 219 msg_perr("Invalid SPI command ignorelist length\n"); 220 free(tmp); 221 return 1; 222 } 223 spi_ignorelist_size = i / 2; 224 for (i = 0; i < spi_ignorelist_size * 2; i++) { 225 if (!isxdigit((unsigned char)tmp[i])) { 226 msg_perr("Invalid char \"%c\" in SPI command " 227 "ignorelist\n", tmp[i]); 228 free(tmp); 229 return 1; 230 } 231 } 232 for (i = 0; i < spi_ignorelist_size; i++) { 233 sscanf(tmp + i * 2, "%2hhx", &spi_ignorelist[i]); 234 } 235 msg_pdbg("SPI ignorelist is "); 236 for (i = 0; i < spi_ignorelist_size; i++) 237 msg_pdbg("%02x ", spi_ignorelist[i]); 238 msg_pdbg(", size %i\n", spi_ignorelist_size); 239 } 240 free(tmp); 172 241 173 242 #if EMULATE_CHIP … … 349 418 unsigned char *readarr) 350 419 { 351 unsigned int offs ;420 unsigned int offs, i; 352 421 static int unsigned aai_offs; 353 422 static int aai_active = 0; … … 357 426 return 1; 358 427 } 359 /* TODO: Implement command blacklists here. */ 428 /* spi_blacklist has precedence before spi_ignorelist. */ 429 for (i = 0; i < spi_blacklist_size; i++) { 430 if (writearr[0] == spi_blacklist[i]) { 431 msg_pdbg("Refusing blacklisted SPI command 0x%02x\n", 432 spi_blacklist[i]); 433 return SPI_INVALID_OPCODE; 434 } 435 } 436 for (i = 0; i < spi_ignorelist_size; i++) { 437 if (writearr[0] == spi_ignorelist[i]) { 438 msg_cdbg("Ignoring ignorelisted SPI command 0x%02x\n", 439 spi_ignorelist[i]); 440 /* Return success because the command does not fail, 441 * it is simply ignored. 442 */ 443 return 0; 444 } 445 } 360 446 switch (writearr[0]) { 361 447 case JEDEC_RES: … … 564 650 if (emulate_spi_chip_response(writecnt, readcnt, writearr, 565 651 readarr)) { 566 msg_p err("Invalid command sent to flash chip!\n");652 msg_pdbg("Invalid command sent to flash chip!\n"); 567 653 return 1; 568 654 } -
trunk/flashrom.8
r1483 r1490 422 422 .sp 423 423 .B " flashrom -p dummy:emulate=M25P10.RES,spi_write_256_chunksize=5" 424 .sp 425 To simulate a programmer which refuses to send certain SPI commands to the 426 flash chip, you can specify a blacklist of SPI commands with the 427 .sp 428 .B " flashrom -p dummy:spi_blacklist=commandlist" 429 .sp 430 syntax where commandlist is a list of two-digit hexadecimal representations of 431 SPI commands. If commandlist is e.g. 0302, flashrom will behave as if the SPI 432 controller refuses to run command 0x03 (READ) and command 0x02 (WRITE). 433 commandlist may be up to 512 characters (256 commands) long. 434 Implementation note: flashrom will detect an error during command execution. 435 .sp 436 To simulate a flash chip which ignores (doesn't support) certain SPI commands, 437 you can specify an ignorelist of SPI commands with the 438 .sp 439 .B " flashrom -p dummy:spi_ignorelist=commandlist" 440 .sp 441 syntax where commandlist is a list of two-digit hexadecimal representations of 442 SPI commands. If commandlist is e.g. 0302, the emulated flash chip will ignore 443 command 0x03 (READ) and command 0x02 (WRITE). commandlist may be up to 512 444 characters (256 commands) long. 445 Implementation note: flashrom won't detect an error during command execution. 424 446 .TP 425 447 .BR "nic3com" , " nicrealtek" , " nicsmc1211" , " nicnatsemi" , " nicintel\
Note: See TracChangeset
for help on using the changeset viewer.
