[coreboot] [flashrom] [PATCH] external serial flasher protocol support

Urja Rannikko urjaman at gmail.com
Wed Jun 10 00:11:10 CEST 2009

Support for an external serial flasher protocol.
Supports RS-232, USB serial converters (untested) and TCP streams.

Signed-off-by: Urja Rannikko <urjaman at gmail.com>

Please commit my jedec.c readb to readn patch (or carldani's version
that i've only heard of in IRC) before this
 - they're not dependent but without that patch this protocol is awfully slow.

Also attached is a simple specification of the protocol this code
implements, it hasnt changed much from my last mail,
but i attach it here so it's readily available in the same mail with
the implementation.

I also have the implementation of this protocol on the device side for
an Atmel AVR ATmega168 microcontroller, it is
also included just for an idea of how i implemented the device side
parser - it has GPL headers added to all files and COPYING
included to make it GPLv2+ for real, but has not otherwise been looked
at for release - the device it runs on is in a way very special,
so i think compiling that directly would be of little use to anyone atm.

-------------- next part --------------
Serial Flasher Protocol Specification - version 1 (0x01 return value == 1)

Command And Answer Sequence - not all commands give an answer
PC: COMMAND(8bit) <parameters determined by opcode>
DEV: ACK/NAK(8bit) <OPTIONAL RETURN BYTES (only if ACK)> or nothing

ACK = 0x10
NAK = 0xBA

All multibyte values are little-endian.

COMMAND	Description			Parameters			Return Value
0x00	NOP (to synchronize)		none				NAK + ACK (a special sequence for easier sync)
0x01	Query programmer iface version	none				ACK + 16bit version (nonzero)
0x02	Query supported commands bitmap	none				ACK + 32 bytes (256 bits) of supported cmds flags
									eg. cmd 0 support: byte 0 bit 0
									cmd 1 support: byte 0 bit 1
									cmd 7 support: byte 0 bit 7
									cmd 8 support: byte 1 bit 0
0x03	Query programmer name		none				ACK + 16 bytes string (null padding) / NAK
0x04	Query serial buffer size	none				ACK + 16bit size / NAK
0x05	Query supported bustypes	none				ACK + 8-bit flags (as per flashrom) / NAK
									bit 0: PARALLEL
									bit 1: LPC
									bit 2: FWH
									bit 3: SPI if ever supported
0x06	Query supported chip size	none				ACK + 8bit power of two / NAK
0x07	Query operation buffer size	none				ACK + 16bit size / NAK
0x08	Query write-n maximum data len	none				ACK + 24bit maximum length / NAK
0x00	Read byte			24-bit addr			ACK + BYTE / NAK
0x0A	Read n bytes			24-bit addr + 24-bit length	ACK + length bytes / NAK
0x0B	Initialize operation buffer	none				ACK / NAK
0x0C	Write to opbuf: Write byte	24-bit addr + 8-bit byte	ACK / NAK (NOTE: takes 6 bytes in opbuf)
0x0D	Write to opbuf: Write n		24-bit length + 24-bit addr +	ACK / NAK (NOTE: takes 7+n bytes in opbuf)
					 + length bytes of data
0x0E	Write to opbuf: delay		32-bit usecs			ACK / NAK (NOTE: takes 5 bytes in opbuf)
0x0F	Execute operation buffer	none				ACK / NAK
		- Execute operation buffer will also clear it, regardless of the return value
0x??	unimplemented command - dont do, dangerous, check for support with 0x02 before using any opcode exept 0x00, 0x01 and 0x02.
				if 0x01 doesn't return 1, dont do anything if you dont support a newer protocol.

This define listing should help C coders - (it's here to be the single source for copying - will be a .h someday i think)
#define S_ACK 0x10
#define S_NAK 0xBA
#define S_CMD_SYNCNOP		0x00            /* No operation                                 */
#define S_CMD_Q_IFACE           0x01            /* Query interface version                      */
#define S_CMD_Q_CMDMAP		0x02		/* Query supported commands bitmap		*/
#define S_CMD_Q_PGMNAME         0x03            /* Query programmer name                        */
#define S_CMD_Q_SERBUF          0x04            /* Query Serial Buffer Size                     */
#define S_CMD_Q_BUSTYPE         0x05            /* Query supported bustypes                     */
#define S_CMD_Q_CHIPSIZE        0x06            /* Query supported chipsize (2^n format)        */
#define S_CMD_Q_OPBUF           0x07            /* Query operation buffer size                  */
#define S_CMD_Q_WRNMAXLEN	0x08		/* Query Write to opbuf: Write-N maximum lenght */
#define S_CMD_R_BYTE            0x09            /* Read a single byte                           */
#define S_CMD_R_NBYTES          0x0A            /* Read n bytes                                 */
#define S_CMD_O_INIT            0x0B            /* Initialize operation buffer                  */
#define S_CMD_O_WRITEB          0x0C            /* Write opbuf: Write byte with address         */
#define S_CMD_O_WRITEN		0x0D		/* Write to opbuf: Write-N			*/
#define S_CMD_O_DELAY           0x0E            /* Write opbuf: udelay                          */
#define S_CMD_O_EXEC            0x0F            /* Execute operation buffer                     */
-------------- next part --------------
A non-text attachment was scrubbed...
Name: serprog.patch
Type: application/octet-stream
Size: 22579 bytes
Desc: not available
URL: <http://www.coreboot.org/pipermail/coreboot/attachments/20090610/4ee6e683/attachment.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: frser-avr.tar.bz2
Type: application/x-bzip2
Size: 11784 bytes
Desc: not available
URL: <http://www.coreboot.org/pipermail/coreboot/attachments/20090610/4ee6e683/attachment.bin>

More information about the coreboot mailing list