Urja Rannikko | f3196df | 2009-07-21 13:02:59 +0000 | [diff] [blame] | 1 | Serial Flasher Protocol Specification - version 1 (0x01 return value == 1) |
| 2 | |
| 3 | Command And Answer Sequence - all commands give an answer. |
| 4 | PC: COMMAND(8bit) <parameters determined by opcode> |
| 5 | DEV: ACK/NAK(8bit) <OPTIONAL RETURN BYTES (only if ACK)> / nothing |
| 6 | Command 0x10 (SYNCNOP) has a special return of NAK+ACK for synchronization. |
| 7 | |
| 8 | ACK = 0x06 |
| 9 | NAK = 0x15 |
| 10 | |
| 11 | All multibyte values are little-endian. Addresses and lengths are 24-bit. |
| 12 | |
| 13 | COMMAND Description Parameters Return Value |
| 14 | 0x00 NOP none ACK |
| 15 | 0x01 Query programmer iface version none ACK + 16bit version (nonzero) |
| 16 | 0x02 Query supported commands bitmap none ACK + 32 bytes (256 bits) of supported cmds flags |
| 17 | 0x03 Query programmer name none ACK + 16 bytes string (null padding) / NAK |
| 18 | 0x04 Query serial buffer size none ACK + 16bit size / NAK |
Nico Huber | c3b02dc | 2023-08-12 01:13:45 +0200 | [diff] [blame] | 19 | 0x05 Query supported bustypes none ACK + 8-bit flags / NAK |
Urja Rannikko | f3196df | 2009-07-21 13:02:59 +0000 | [diff] [blame] | 20 | 0x06 Query connected address lines none ACK + 8bit line count / NAK |
| 21 | 0x07 Query operation buffer size none ACK + 16bit size / NAK |
Stefan Tauner | 31019d4 | 2011-10-22 21:45:27 +0000 | [diff] [blame] | 22 | 0x08 Query maximum write-n length none ACK + 24bit length (0==2^24) / NAK |
Urja Rannikko | f3196df | 2009-07-21 13:02:59 +0000 | [diff] [blame] | 23 | 0x09 Read byte 24-bit addr ACK + BYTE / NAK |
| 24 | 0x0A Read n bytes 24-bit addr + 24-bit length ACK + length bytes / NAK |
| 25 | 0x0B Initialize operation buffer none ACK / NAK |
| 26 | 0x0C Write to opbuf: Write byte 24-bit addr + 8-bit byte ACK / NAK (NOTE: takes 5 bytes in opbuf) |
| 27 | 0x0D Write to opbuf: Write n 24-bit length + 24-bit addr + ACK / NAK (NOTE: takes 7+n bytes in opbuf) |
| 28 | + length bytes of data |
| 29 | 0x0E Write to opbuf: delay 32-bit usecs ACK / NAK (NOTE: takes 5 bytes in opbuf) |
| 30 | 0x0F Execute operation buffer none ACK / NAK |
| 31 | 0x10 Sync NOP none NAK + ACK (for synchronization) |
| 32 | 0x11 Query maximum read-n length none ACK + 24-bit length (0==2^24) / NAK |
| 33 | 0x12 Set used bustype 8-bit flags (as with 0x05) ACK / NAK |
Urja Rannikko | c93f5f1 | 2011-09-15 23:38:14 +0000 | [diff] [blame] | 34 | 0x13 Perform SPI operation 24-bit slen + 24-bit rlen ACK + rlen bytes of data / NAK |
| 35 | + slen bytes of data |
Stefan Tauner | b98f6eb | 2012-08-13 16:33:04 +0000 | [diff] [blame] | 36 | 0x14 Set SPI clock frequency in Hz 32-bit requested frequency ACK + 32-bit set frequency / NAK |
Stefan Tauner | 92fefc9 | 2012-10-27 00:34:23 +0000 | [diff] [blame] | 37 | 0x15 Toggle flash chip pin drivers 8-bit (0 disable, else enable) ACK / NAK |
Riku Viitanen | ddb6d92 | 2024-01-15 19:15:49 +0200 | [diff] [blame] | 38 | 0x16 Set SPI Chip Select 8-bit ACK / NAK |
Urja Rannikko | f3196df | 2009-07-21 13:02:59 +0000 | [diff] [blame] | 39 | 0x?? unimplemented command - invalid. |
| 40 | |
| 41 | |
| 42 | Additional information of the above commands: |
| 43 | About unimplemented commands / startup sequence: |
| 44 | Only commands allowed to be used without checking anything are 0x00,0x10 and 0x01 (NOP,SYNCNOP,Q_IFACE). |
| 45 | If 0x01 doesn't return 1, dont do anything if you dont support a newer protocol. |
| 46 | Then, check support for any other opcode (except 0x02) by using 0x02 (Q_CMDMAP). |
| 47 | 0x02 (Q_CMDMAP): |
| 48 | The map's bits are mapped as follows: |
| 49 | cmd 0 support: byte 0 bit 0 |
| 50 | cmd 1 support: byte 0 bit 1 |
| 51 | cmd 7 support: byte 0 bit 7 |
| 52 | cmd 8 support: byte 1 bit 0, and so on. |
| 53 | 0x04 (Q_SERBUF): |
Uwe Hermann | 4e3d0b3 | 2010-03-25 23:18:41 +0000 | [diff] [blame] | 54 | If the programmer has a guaranteed working flow control, |
Urja Rannikko | f3196df | 2009-07-21 13:02:59 +0000 | [diff] [blame] | 55 | it should return a big bogus value - eg 0xFFFF. |
| 56 | 0x05 (Q_BUSTYPE): |
| 57 | The bit's are defined as follows: |
Urja Rannikko | c93f5f1 | 2011-09-15 23:38:14 +0000 | [diff] [blame] | 58 | bit 0: PARALLEL, bit 1: LPC, bit 2: FWH, bit 3: SPI. |
Urja Rannikko | f3196df | 2009-07-21 13:02:59 +0000 | [diff] [blame] | 59 | 0x06 (Q_CHIPSIZE): |
| 60 | Only applicable to parallel programmers. |
Uwe Hermann | 4e3d0b3 | 2010-03-25 23:18:41 +0000 | [diff] [blame] | 61 | An LPC/FWH/SPI-programmer can report this as not supported in the command bitmap. |
Urja Rannikko | f3196df | 2009-07-21 13:02:59 +0000 | [diff] [blame] | 62 | 0x08 (Q_WRNMAXLEN): |
| 63 | If a programmer reports a bigger maximum write-n length than the serial buffer size, |
| 64 | it is assumed that the programmer can process the data fast enough to take in the |
| 65 | reported maximum write-n without problems. |
| 66 | 0x0F (O_EXEC): |
| 67 | Execute operation buffer will also clear it, regardless of the return value. |
| 68 | 0x11 (Q_RDNMAXLEN): |
| 69 | If this command is not supported, assume return of 0 (2^24). |
| 70 | 0x12 (S_BUSTYPE): |
| 71 | Set's the used bustype if the programmer can support more than one flash protocol. |
| 72 | Sending a byte with more than 1 bit set will make the programmer decide among them |
| 73 | on it's own. Bit values as with Q_BUSTYPE. |
Urja Rannikko | c93f5f1 | 2011-09-15 23:38:14 +0000 | [diff] [blame] | 74 | 0x13 (O_SPIOP): |
| 75 | Send and receive bytes via SPI. |
| 76 | Maximum slen is Q_WRNMAXLEN in case Q_BUSTYPE returns SPI only or S_BUSTYPE was used |
| 77 | to set SPI exclusively before. Same for rlen and Q_RDNMAXLEN. |
Stefan Tauner | 6697f71 | 2014-08-06 15:09:15 +0000 | [diff] [blame] | 78 | This operation is immediate, meaning it doesn't use the operation buffer. |
Stefan Tauner | b98f6eb | 2012-08-13 16:33:04 +0000 | [diff] [blame] | 79 | 0x14 (S_SPI_FREQ): |
| 80 | Set the SPI clock frequency. The 32-bit value indicates the |
| 81 | requested frequency in Hertz. Value 0 is reserved and should |
| 82 | be NAKed by the programmer. The requested frequency should be |
| 83 | mapped by the programmer software to a supported frequency |
| 84 | lower than the one requested. If there is no lower frequency |
| 85 | available the lowest possible should be used. The value |
| 86 | chosen is sent back in the reply with an ACK. |
Riku Viitanen | 182229d | 2024-01-15 20:10:40 +0200 | [diff] [blame] | 87 | 0x15 (S_PIN_STATE): |
Stefan Tauner | 92fefc9 | 2012-10-27 00:34:23 +0000 | [diff] [blame] | 88 | Sets the state of the pin drivers connected to the flash chip. Disabling them allows other |
| 89 | devices (e.g. a mainboard's chipset) to access the chip. This way the serprog controller can |
| 90 | remain attached to the flash chip even when the board is running. The user is responsible to |
| 91 | NOT connect VCC and other permanently externally driven signals to the programmer as needed. |
| 92 | If the value is 0, then the drivers should be disabled, otherwise they should be enabled. |
Riku Viitanen | ddb6d92 | 2024-01-15 19:15:49 +0200 | [diff] [blame] | 93 | 0x16 (S_SPI_CS): |
| 94 | Set which SPI Chip Select pin to use. This operation is immediate, |
| 95 | meaning it doesn't use the operation buffer. |
Urja Rannikko | f3196df | 2009-07-21 13:02:59 +0000 | [diff] [blame] | 96 | About mandatory commands: |
| 97 | The only truly mandatory commands for any device are 0x00, 0x01, 0x02 and 0x10, |
| 98 | but one can't really do anything with these commands. |
Nico Huber | c3b02dc | 2023-08-12 01:13:45 +0200 | [diff] [blame] | 99 | Support for the following commands is necessary for flashprog to operate properly: |
Urja Rannikko | f3196df | 2009-07-21 13:02:59 +0000 | [diff] [blame] | 100 | S_CMD_Q_SERBUF, S_CMD_Q_OPBUF, S_CMD_Q_WRNMAXLEN, S_CMD_R_BYTE, |
| 101 | S_CMD_R_NBYTES, S_CMD_O_INIT, S_CMD_O_WRITEB, S_CMD_O_WRITEN, |
| 102 | S_CMD_O_DELAY, S_CMD_O_EXEC. |
| 103 | In addition, support for these commands is recommended: |
| 104 | S_CMD_Q_PGMNAME, S_CMD_Q_BUSTYPE, S_CMD_Q_CHIPSIZE (if parallel). |