serprog-protocol.txt 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. Serial Flasher Protocol Specification - version 1 (0x01 return value == 1)
  2. Command And Answer Sequence - all commands give an answer.
  3. PC: COMMAND(8bit) <parameters determined by opcode>
  4. DEV: ACK/NAK(8bit) <OPTIONAL RETURN BYTES (only if ACK)> / nothing
  5. Command 0x10 (SYNCNOP) has a special return of NAK+ACK for synchronization.
  6. ACK = 0x06
  7. NAK = 0x15
  8. All multibyte values are little-endian. Addresses and lengths are 24-bit.
  9. COMMAND Description Parameters Return Value
  10. 0x00 NOP none ACK
  11. 0x01 Query programmer iface version none ACK + 16bit version (nonzero)
  12. 0x02 Query supported commands bitmap none ACK + 32 bytes (256 bits) of supported cmds flags
  13. 0x03 Query programmer name none ACK + 16 bytes string (null padding) / NAK
  14. 0x04 Query serial buffer size none ACK + 16bit size / NAK
  15. 0x05 Query supported bustypes none ACK + 8-bit flags (as per flashrom) / NAK
  16. 0x06 Query connected address lines none ACK + 8bit line count / NAK
  17. 0x07 Query operation buffer size none ACK + 16bit size / NAK
  18. 0x08 Query maximum write-n length none ACK + 24bit length (0==2^24) / NAK
  19. 0x09 Read byte 24-bit addr ACK + BYTE / NAK
  20. 0x0A Read n bytes 24-bit addr + 24-bit length ACK + length bytes / NAK
  21. 0x0B Initialize operation buffer none ACK / NAK
  22. 0x0C Write to opbuf: Write byte 24-bit addr + 8-bit byte ACK / NAK (NOTE: takes 5 bytes in opbuf)
  23. 0x0D Write to opbuf: Write n 24-bit length + 24-bit addr + ACK / NAK (NOTE: takes 7+n bytes in opbuf)
  24. + length bytes of data
  25. 0x0E Write to opbuf: delay 32-bit usecs ACK / NAK (NOTE: takes 5 bytes in opbuf)
  26. 0x0F Execute operation buffer none ACK / NAK
  27. 0x10 Sync NOP none NAK + ACK (for synchronization)
  28. 0x11 Query maximum read-n length none ACK + 24-bit length (0==2^24) / NAK
  29. 0x12 Set used bustype 8-bit flags (as with 0x05) ACK / NAK
  30. 0x13 Perform SPI operation 24-bit slen + 24-bit rlen ACK + rlen bytes of data / NAK
  31. + slen bytes of data
  32. 0x?? unimplemented command - invalid.
  33. Additional information of the above commands:
  34. About unimplemented commands / startup sequence:
  35. Only commands allowed to be used without checking anything are 0x00,0x10 and 0x01 (NOP,SYNCNOP,Q_IFACE).
  36. If 0x01 doesn't return 1, dont do anything if you dont support a newer protocol.
  37. Then, check support for any other opcode (except 0x02) by using 0x02 (Q_CMDMAP).
  38. 0x02 (Q_CMDMAP):
  39. The map's bits are mapped as follows:
  40. cmd 0 support: byte 0 bit 0
  41. cmd 1 support: byte 0 bit 1
  42. cmd 7 support: byte 0 bit 7
  43. cmd 8 support: byte 1 bit 0, and so on.
  44. 0x04 (Q_SERBUF):
  45. If the programmer has a guaranteed working flow control,
  46. it should return a big bogus value - eg 0xFFFF.
  47. 0x05 (Q_BUSTYPE):
  48. The bit's are defined as follows:
  49. bit 0: PARALLEL, bit 1: LPC, bit 2: FWH, bit 3: SPI.
  50. 0x06 (Q_CHIPSIZE):
  51. Only applicable to parallel programmers.
  52. An LPC/FWH/SPI-programmer can report this as not supported in the command bitmap.
  53. 0x08 (Q_WRNMAXLEN):
  54. If a programmer reports a bigger maximum write-n length than the serial buffer size,
  55. it is assumed that the programmer can process the data fast enough to take in the
  56. reported maximum write-n without problems.
  57. 0x0F (O_EXEC):
  58. Execute operation buffer will also clear it, regardless of the return value.
  59. 0x11 (Q_RDNMAXLEN):
  60. If this command is not supported, assume return of 0 (2^24).
  61. 0x12 (S_BUSTYPE):
  62. Set's the used bustype if the programmer can support more than one flash protocol.
  63. Sending a byte with more than 1 bit set will make the programmer decide among them
  64. on it's own. Bit values as with Q_BUSTYPE.
  65. 0x13 (O_SPIOP):
  66. Send and receive bytes via SPI.
  67. Maximum slen is Q_WRNMAXLEN in case Q_BUSTYPE returns SPI only or S_BUSTYPE was used
  68. to set SPI exclusively before. Same for rlen and Q_RDNMAXLEN.
  69. This operation is immediate, meaning it doesnt use the operation buffer.
  70. About mandatory commands:
  71. The only truly mandatory commands for any device are 0x00, 0x01, 0x02 and 0x10,
  72. but one can't really do anything with these commands.
  73. Support for the following commands is necessary for flashrom to operate properly:
  74. S_CMD_Q_SERBUF, S_CMD_Q_OPBUF, S_CMD_Q_WRNMAXLEN, S_CMD_R_BYTE,
  75. S_CMD_R_NBYTES, S_CMD_O_INIT, S_CMD_O_WRITEB, S_CMD_O_WRITEN,
  76. S_CMD_O_DELAY, S_CMD_O_EXEC.
  77. In addition, support for these commands is recommended:
  78. S_CMD_Q_PGMNAME, S_CMD_Q_BUSTYPE, S_CMD_Q_CHIPSIZE (if parallel).
  79. This define listing should help C coders - (it's here to be the single source for copying - will be a .h someday i think)
  80. #define S_ACK 0x06
  81. #define S_NAK 0x15
  82. #define S_CMD_NOP 0x00 /* No operation */
  83. #define S_CMD_Q_IFACE 0x01 /* Query interface version */
  84. #define S_CMD_Q_CMDMAP 0x02 /* Query supported commands bitmap */
  85. #define S_CMD_Q_PGMNAME 0x03 /* Query programmer name */
  86. #define S_CMD_Q_SERBUF 0x04 /* Query Serial Buffer Size */
  87. #define S_CMD_Q_BUSTYPE 0x05 /* Query supported bustypes */
  88. #define S_CMD_Q_CHIPSIZE 0x06 /* Query supported chipsize (2^n format) */
  89. #define S_CMD_Q_OPBUF 0x07 /* Query operation buffer size */
  90. #define S_CMD_Q_WRNMAXLEN 0x08 /* Query Write to opbuf: Write-N maximum length */
  91. #define S_CMD_R_BYTE 0x09 /* Read a single byte */
  92. #define S_CMD_R_NBYTES 0x0A /* Read n bytes */
  93. #define S_CMD_O_INIT 0x0B /* Initialize operation buffer */
  94. #define S_CMD_O_WRITEB 0x0C /* Write opbuf: Write byte with address */
  95. #define S_CMD_O_WRITEN 0x0D /* Write to opbuf: Write-N */
  96. #define S_CMD_O_DELAY 0x0E /* Write opbuf: udelay */
  97. #define S_CMD_O_EXEC 0x0F /* Execute operation buffer */
  98. #define S_CMD_SYNCNOP 0x10 /* Special no-operation that returns NAK+ACK */
  99. #define S_CMD_Q_RDNMAXLEN 0x11 /* Query read-n maximum length */
  100. #define S_CMD_S_BUSTYPE 0x12 /* Set used bustype(s). */
  101. #define S_CMD_O_SPIOP 0x13 /* Perform SPI operation. */