Changeset 1442
- Timestamp:
- 09/16/11 01:38:14 (8 months ago)
- Location:
- trunk
- Files:
-
- 3 edited
-
programmer.h (modified) (2 diffs)
-
serprog-protocol.txt (modified) (4 diffs)
-
serprog.c (modified) (10 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/programmer.h
r1433 r1442 546 546 SPI_CONTROLLER_LINUX, 547 547 #endif 548 #if CONFIG_SERPROG == 1 549 SPI_CONTROLLER_SERPROG, 550 #endif 548 551 }; 549 552 extern const int spi_programmer_count; … … 606 609 void serprog_chip_readn(uint8_t *buf, const chipaddr addr, size_t len); 607 610 void serprog_delay(int delay); 611 int serprog_spi_send_command(unsigned int writecnt, unsigned int readcnt, 612 const unsigned char *writearr, unsigned char *readarr); 613 int serprog_spi_read(struct flashchip *flash, uint8_t *buf, int start, int len); 608 614 #endif 609 615 -
trunk/serprog-protocol.txt
r1367 r1442 32 32 0x11 Query maximum read-n length none ACK + 24-bit length (0==2^24) / NAK 33 33 0x12 Set used bustype 8-bit flags (as with 0x05) ACK / NAK 34 0x13 Perform SPI operation 24-bit slen + 24-bit rlen ACK + rlen bytes of data / NAK 35 + slen bytes of data 34 36 0x?? unimplemented command - invalid. 35 37 … … 51 53 0x05 (Q_BUSTYPE): 52 54 The bit's are defined as follows: 53 bit 0: PARALLEL, bit 1: LPC, bit 2: FWH, bit 3: SPI (if ever supported).55 bit 0: PARALLEL, bit 1: LPC, bit 2: FWH, bit 3: SPI. 54 56 0x06 (Q_CHIPSIZE): 55 57 Only applicable to parallel programmers. … … 67 69 Sending a byte with more than 1 bit set will make the programmer decide among them 68 70 on it's own. Bit values as with Q_BUSTYPE. 71 0x13 (O_SPIOP): 72 Send and receive bytes via SPI. 73 Maximum slen is Q_WRNMAXLEN in case Q_BUSTYPE returns SPI only or S_BUSTYPE was used 74 to set SPI exclusively before. Same for rlen and Q_RDNMAXLEN. 75 This operation is immediate, meaning it doesnt use the operation buffer. 69 76 About mandatory commands: 70 77 The only truly mandatory commands for any device are 0x00, 0x01, 0x02 and 0x10, … … 100 107 #define S_CMD_Q_RDNMAXLEN 0x11 /* Query read-n maximum length */ 101 108 #define S_CMD_S_BUSTYPE 0x12 /* Set used bustype(s). */ 109 #define S_CMD_O_SPIOP 0x13 /* Perform SPI operation. */ -
trunk/serprog.c
r1396 r1442 2 2 * This file is part of the flashrom project. 3 3 * 4 * Copyright (C) 2009 Urja Rannikko <urjaman@gmail.com>4 * Copyright (C) 2009, 2011 Urja Rannikko <urjaman@gmail.com> 5 5 * Copyright (C) 2009 Carl-Daniel Hailfinger 6 6 * … … 37 37 #include "flash.h" 38 38 #include "programmer.h" 39 #include "chipdrivers.h" 39 40 40 41 #define MSGHEADER "serprog:" … … 68 69 #define S_CMD_Q_RDNMAXLEN 0x11 /* Query read-n maximum length */ 69 70 #define S_CMD_S_BUSTYPE 0x12 /* Set used bustype(s). */ 71 #define S_CMD_O_SPIOP 0x13 /* Perform SPI operation. */ 70 72 71 73 static uint16_t sp_device_serbuf_size = 16; … … 303 305 } 304 306 307 static struct spi_programmer spi_programmer_serprog = { 308 .type = SPI_CONTROLLER_SERPROG, 309 .max_data_read = MAX_DATA_READ_UNLIMITED, 310 .max_data_write = MAX_DATA_WRITE_UNLIMITED, 311 .command = serprog_spi_send_command, 312 .multicommand = default_spi_send_multicommand, 313 .read = serprog_spi_read, 314 .write_256 = default_spi_write_256, 315 }; 316 305 317 int serprog_init(void) 306 318 { … … 326 338 "Use flashrom -p serprog:dev=/dev/device:baud\n"); 327 339 free(device); 328 return 1; 340 return 1; 329 341 } 330 342 if (strlen(device)) { … … 359 371 "Use flashrom -p serprog:ip=ipaddr:port\n"); 360 372 free(device); 361 return 1; 373 return 1; 362 374 } 363 375 if (strlen(device)) { … … 411 423 sp_check_avail_automatic = 1; 412 424 413 /* Check for the minimum operational set of commands */ 414 if (sp_check_commandavail(S_CMD_R_BYTE) == 0) { 415 msg_perr("Error: Single byte read not supported\n"); 416 exit(1); 417 } 418 /* This could be translated to single byte reads (if missing), * 419 * but now we dont support that. */ 420 if (sp_check_commandavail(S_CMD_R_NBYTES) == 0) { 421 msg_perr("Error: Read n bytes not supported\n"); 422 exit(1); 423 } 424 /* In the future one could switch to read-only mode if these * 425 * are not available. */ 426 if (sp_check_commandavail(S_CMD_O_INIT) == 0) { 427 msg_perr("Error: Initialize operation buffer not supported\n"); 428 exit(1); 429 } 430 if (sp_check_commandavail(S_CMD_O_WRITEB) == 0) { 431 msg_perr("Error: Write to opbuf: write byte not supported\n"); 432 exit(1); 433 } 434 if (sp_check_commandavail(S_CMD_O_DELAY) == 0) { 435 msg_perr("Error: Write to opbuf: delay not supported\n"); 436 exit(1); 437 } 438 if (sp_check_commandavail(S_CMD_O_EXEC) == 0) { 439 msg_perr( 440 "Error: Execute operation buffer not supported\n"); 441 exit(1); 425 426 if (sp_docommand(S_CMD_Q_BUSTYPE, 0, NULL, 1, &c)) { 427 msg_perr("Warning: NAK to query supported buses\n"); 428 c = BUS_NONSPI; /* A reasonable default for now. */ 429 } 430 buses_supported = c; 431 /* Check for the minimum operational set of commands. */ 432 if (buses_supported & BUS_SPI) { 433 uint8_t bt = BUS_SPI; 434 if (sp_check_commandavail(S_CMD_O_SPIOP) == 0) { 435 msg_perr("Error: SPI operation not supported while the " 436 "bustype is SPI\n"); 437 exit(1); 438 } 439 /* Success of any of these commands is optional. We don't need 440 the programmer to tell us its limits, but if it doesn't, we 441 will assume stuff, so it's in the programmers best interest 442 to tell us. */ 443 sp_docommand(S_CMD_S_BUSTYPE, 1, &bt, 0, NULL); 444 if (!sp_docommand(S_CMD_Q_WRNMAXLEN, 0, NULL, 3, rbuf)) { 445 uint32_t v; 446 v = ((unsigned int)(rbuf[0]) << 0); 447 v |= ((unsigned int)(rbuf[1]) << 8); 448 v |= ((unsigned int)(rbuf[2]) << 16); 449 if (v == 0) 450 v = (1 << 24) - 1; /* SPI-op maximum. */ 451 spi_programmer_serprog.max_data_write = v; 452 msg_pdbg(MSGHEADER "Maximum write-n length is %d\n", v); 453 } 454 if (!sp_docommand(S_CMD_Q_RDNMAXLEN, 0, NULL, 3, rbuf)) { 455 uint32_t v; 456 v = ((unsigned int)(rbuf[0]) << 0); 457 v |= ((unsigned int)(rbuf[1]) << 8); 458 v |= ((unsigned int)(rbuf[2]) << 16); 459 if (v == 0) 460 v = (1 << 24) - 1; /* SPI-op maximum. */ 461 spi_programmer_serprog.max_data_read = v; 462 msg_pdbg(MSGHEADER "Maximum read-n length is %d\n", v); 463 } 464 bt = buses_supported; 465 sp_docommand(S_CMD_S_BUSTYPE, 1, &bt, 0, NULL); 466 register_spi_programmer(&spi_programmer_serprog); 467 } 468 469 if (buses_supported & BUS_NONSPI) { 470 if (sp_check_commandavail(S_CMD_O_INIT) == 0) { 471 msg_perr("Error: Initialize operation buffer " 472 "not supported\n"); 473 exit(1); 474 } 475 476 if (sp_check_commandavail(S_CMD_O_DELAY) == 0) { 477 msg_perr("Error: Write to opbuf: " 478 "delay not supported\n"); 479 exit(1); 480 } 481 482 /* S_CMD_O_EXEC availability checked later. */ 483 484 if (sp_check_commandavail(S_CMD_R_BYTE) == 0) { 485 msg_perr("Error: Single byte read not supported\n"); 486 exit(1); 487 } 488 /* This could be translated to single byte reads (if missing), 489 * but now we don't support that. */ 490 if (sp_check_commandavail(S_CMD_R_NBYTES) == 0) { 491 msg_perr("Error: Read n bytes not supported\n"); 492 exit(1); 493 } 494 if (sp_check_commandavail(S_CMD_O_WRITEB) == 0) { 495 msg_perr("Error: Write to opbuf: " 496 "write byte not supported\n"); 497 exit(1); 498 } 499 500 if (sp_docommand(S_CMD_Q_WRNMAXLEN, 0, NULL, 3, rbuf)) { 501 msg_pdbg(MSGHEADER "Write-n not supported"); 502 sp_max_write_n = 0; 503 } else { 504 sp_max_write_n = ((unsigned int)(rbuf[0]) << 0); 505 sp_max_write_n |= ((unsigned int)(rbuf[1]) << 8); 506 sp_max_write_n |= ((unsigned int)(rbuf[2]) << 16); 507 if (!sp_max_write_n) { 508 sp_max_write_n = (1 << 24); 509 } 510 msg_pdbg(MSGHEADER "Maximum write-n length is %d\n", 511 sp_max_write_n); 512 sp_write_n_buf = malloc(sp_max_write_n); 513 if (!sp_write_n_buf) { 514 msg_perr("Error: cannot allocate memory for " 515 "Write-n buffer\n"); 516 exit(1); 517 } 518 sp_write_n_bytes = 0; 519 } 520 521 if (sp_check_commandavail(S_CMD_Q_RDNMAXLEN) && 522 (sp_docommand(S_CMD_Q_RDNMAXLEN, 0, NULL, 3, rbuf) == 0)) { 523 sp_max_read_n = ((unsigned int)(rbuf[0]) << 0); 524 sp_max_read_n |= ((unsigned int)(rbuf[1]) << 8); 525 sp_max_read_n |= ((unsigned int)(rbuf[2]) << 16); 526 msg_pdbg(MSGHEADER "Maximum read-n length is %d\n", 527 sp_max_read_n ? sp_max_read_n : (1 << 24)); 528 } else { 529 msg_pdbg(MSGHEADER "Maximum read-n length " 530 "not reported\n"); 531 sp_max_read_n = 0; 532 } 533 442 534 } 443 535 … … 455 547 sp_device_serbuf_size); 456 548 457 if (sp_docommand(S_CMD_Q_OPBUF, 0, NULL, 2, &sp_device_opbuf_size)) { 458 msg_perr("Warning: NAK to query operation buffer size\n"); 459 } 460 msg_pdbg(MSGHEADER "operation buffer size %d\n", 461 sp_device_opbuf_size); 462 463 if (sp_docommand(S_CMD_Q_BUSTYPE, 0, NULL, 1, &c)) { 464 msg_perr("Warning: NAK to query supported buses\n"); 465 c = BUS_NONSPI; /* A reasonable default for now. */ 466 } 467 buses_supported = c; 468 469 if (sp_docommand(S_CMD_O_INIT, 0, NULL, 0, NULL)) { 470 msg_perr("Error: NAK to initialize operation buffer\n"); 471 exit(1); 472 } 473 474 if (sp_docommand(S_CMD_Q_WRNMAXLEN, 0, NULL, 3, rbuf)) { 475 msg_pdbg(MSGHEADER "Write-n not supported"); 476 sp_max_write_n = 0; 477 } else { 478 sp_max_write_n = ((unsigned int)(rbuf[0]) << 0); 479 sp_max_write_n |= ((unsigned int)(rbuf[1]) << 8); 480 sp_max_write_n |= ((unsigned int)(rbuf[2]) << 16); 481 msg_pdbg(MSGHEADER "Maximum write-n length %d\n", 482 sp_max_write_n); 483 sp_write_n_buf = malloc(sp_max_write_n); 484 if (!sp_write_n_buf) { 485 msg_perr("Error: cannot allocate memory for Write-n buffer\n"); 549 if (sp_check_commandavail(S_CMD_O_INIT)) { 550 /* This would be inconsistent. */ 551 if (sp_check_commandavail(S_CMD_O_EXEC) == 0) { 552 msg_perr("Error: Execute operation buffer not " 553 "supported\n"); 486 554 exit(1); 487 555 } 488 sp_write_n_bytes = 0; 489 }490 491 if ((sp_check_commandavail(S_CMD_Q_RDNMAXLEN))492 &&((sp_docommand(S_CMD_Q_RDNMAXLEN,0,NULL, 3, rbuf) == 0))) {493 sp_max_read_n = ((unsigned int)(rbuf[0]) << 0); 494 sp_max_read_n |= ((unsigned int)(rbuf[1]) << 8);495 sp_max_read_n |= ((unsigned int)(rbuf[2]) << 16);496 msg_pdbg(MSGHEADER "Maximum read-n length %d\n",497 sp_max_read_n ? sp_max_read_n : (1<<24));498 } else {499 msg_pdbg(MSGHEADER " Maximum read-n length not reported\n");500 sp_max_read_n = 0;501 }556 557 if (sp_docommand(S_CMD_O_INIT, 0, NULL, 0, NULL)) { 558 msg_perr("Error: NAK to initialize operation buffer\n"); 559 exit(1); 560 } 561 562 if (sp_docommand(S_CMD_Q_OPBUF, 0, NULL, 2, 563 &sp_device_opbuf_size)) { 564 msg_perr("Warning: NAK to query operation buffer " 565 "size\n"); 566 } 567 msg_pdbg(MSGHEADER "operation buffer size %d\n", 568 sp_device_opbuf_size); 569 } 502 570 503 571 sp_prev_was_write = 0; … … 680 748 unsigned char buf[4]; 681 749 msg_pspew("%s\n", __func__); 750 if (!sp_check_commandavail(S_CMD_O_DELAY)) { 751 internal_delay(delay); 752 msg_pdbg("Note: serprog_delay used, but the programmer doesn't " 753 "support delay\n"); 754 return; 755 } 682 756 if ((sp_max_write_n) && (sp_write_n_bytes)) 683 757 sp_pass_writen(); … … 691 765 sp_prev_was_write = 0; 692 766 } 767 768 int serprog_spi_send_command(unsigned int writecnt, unsigned int readcnt, 769 const unsigned char *writearr, 770 unsigned char *readarr) 771 { 772 unsigned char *parmbuf; 773 int ret; 774 msg_pspew("%s, writecnt=%i, readcnt=%i\n", __func__, writecnt, readcnt); 775 if ((sp_opbuf_usage) || (sp_max_write_n && sp_write_n_bytes)) 776 sp_execute_opbuf(); 777 parmbuf = malloc(writecnt + 6); 778 if (!parmbuf) 779 sp_die("Error: cannot malloc SPI send param buffer"); 780 parmbuf[0] = (writecnt >> 0) & 0xFF; 781 parmbuf[1] = (writecnt >> 8) & 0xFF; 782 parmbuf[2] = (writecnt >> 16) & 0xFF; 783 parmbuf[3] = (readcnt >> 0) & 0xFF; 784 parmbuf[4] = (readcnt >> 8) & 0xFF; 785 parmbuf[5] = (readcnt >> 16) & 0xFF; 786 memcpy(parmbuf + 6, writearr, writecnt); 787 ret = sp_docommand(S_CMD_O_SPIOP, writecnt + 6, parmbuf, readcnt, 788 readarr); 789 free(parmbuf); 790 return ret; 791 } 792 793 /* FIXME: This function is optimized so that it does not split each transaction 794 * into chip page_size long blocks unnecessarily like spi_read_chunked. This has 795 * the advantage that it is much faster for most chips, but breaks those with 796 * non-contiguous address space (like AT45DB161D). When spi_read_chunked is 797 * fixed this method can be removed. */ 798 int serprog_spi_read(struct flashchip *flash, uint8_t *buf, int start, int len) 799 { 800 int i; 801 int cur_len; 802 const int max_read = spi_programmer_serprog.max_data_read; 803 for (i = 0; i < len; i += cur_len) { 804 int ret; 805 cur_len = min(max_read, (len - i)); 806 ret = spi_nbyte_read(start + i, buf + i, cur_len); 807 if (ret) 808 return ret; 809 } 810 return 0; 811 }
Note: See TracChangeset
for help on using the changeset viewer.
