![]() A quick reference chart for the Motorola SREC format. (Note that in the record example image the word "bytes" is alternatively used to specify characters.) | |
Filename extension | |
---|---|
Developed by | Motorola |
Motorola S-record is a file format, created byMotorola in the mid-1970s, that conveys binary information ashex values inASCII text form. This file format may also be known asSRECORD,SREC,S19,S28,S37. It is commonly used for programmingflash memory in microcontrollers,EPROMs,EEPROMs, and other types of programmable logic devices. In a typical application, a compiler or assembler converts a program's source code (such as C or assembly language) to machine code and outputs it into a HEX file. The HEX file is then imported by a programmer to write the machine code intonon-volatile memory, or is transferred to the target system for loading and execution.
The S-record format was created in the mid-1970s for theMotorola 6800 processor.Software development tools for that and otherembedded processors would make executable code and data in the S-record format. PROM programmers would then read the S-record format and "burn" the data into the PROMs or EPROMs used in the embedded system. The basic S-record format was subsequently extended to handle 24- and 32-bit addresses for compatibility with theMC68000 series of microprocessors.
There are other ASCII encoding with a similar purpose.BPNF,BHLF, andB10F were early binary formats, but they are neither compact nor flexible. Hexadecimal formats are more compact because they represent 4 bits rather than 1 bit per character. Many, such as S-record, are more flexible because they include address information so they can specify just a portion of a PROM.Intel HEX format was often used with Intel processors.TekHex is another hex format that can include a symbol table for debugging.
S | Type | Byte Count | Address | Data | Checksum |
An SREC format file consists of a series ofASCII text records. The records have the following structure from left to right:
0xFF - (sum & 0xFF)
SREC records are separated by one or more ASCII line termination characters so that each record appears alone on a text line. This enhances legibility by visuallydelimiting the records and it also provides padding between records that can be used to improve machineparsing efficiency.
Programs that create HEX records typically use line termination characters that conform to the conventions of theiroperating systems. For example, Linux programs use a single LF character (line feed, 0x0A as ASCII character value) character to terminate lines, whereas Windows programs use a CR character (carriage return, 0x0D as ASCII character value) followed by a LF character.
The following table describes the 10 possible S-record types.
Record field | Record purpose | Address field | Data field | Record description |
---|---|---|---|---|
S0 | Header | — | ![]() | The data field in this record type may be empty, or may contain the hex equivalent of application-specificASCII information, often in the form of anull-terminated string.[3] In lieu of more specific information, it is common to see 48, 44, 52, which is the ASCII representation of the letters "HDR".[4] The address field will always contain the hex representation of$0000 ($ indicates a hexadecimal number in Motorola 6800 assembly language). |
S1 | Data | 16-bit address | ![]() | The data field in this record type contains data that is loaded to the 16-bit address in the address field.[3][4][5] The number of bytes of data contained in this record is "Byte Count Field" minus 3 (2 bytes for "16-bit Address Field" plus 1 byte for "Checksum Field"). This record type is typically used with eight-bit processors, such as the [[MOS Technology 6502|6502] and6800 families, the8051, theZ80, theAVR andPIC. |
S2 | Data | 24-bit address | ![]() | The data field in this record type contains data that is loaded to the 24-bit address in the address field.[3][4] The number of bytes of data contained in this record is "Byte Count Field" minus 4 (3 bytes for "24-bit Address Field" plus 1 byte for "Checksum Field"). The S2 record type was added by Motorola to support theMC68000 microprocessor, which has a 24-bit address bus.[3] This record type is also usable with the Western Design Center65C816, which emits 24-bit addresses. |
S3 | Data | 32-bit address | ![]() | The data field in this record type contains data that is loaded to the 32-bit address in the address field.[3][4] The number of bytes of data contained in this record is "Byte Count Field" minus 5 (4 bytes for "32-bit Address Field" plus 1 byte for "Checksum Field"). The S3 record type was added to support the68012 and later 68000-series microprocessors that are equipped with a 32-bit data bus.[3] This record type is also usable with non-Motorola 32-bit processors, such as theARM architecture family and theRISC-V. |
S4 | Undefined | — | — | This record type is not defined by the official S-record standard.[3] |
S5 | Count | 16-bit count | ![]() | This optional record type contains a 16-bit count of S1/S2/S3 records that have been transmitted. The data field is not used.[3][4] |
S6 | Non-standard | 24-bit count | ![]() | This record type is not defined by the official S-record standard.[3] However, some applications treat this record as an optional 24-bit count of S1/S2/S3 records that have been transmitted.[4] In such an application, the data field is not used. |
S7 | Start address (termination) | 32-bit address | ![]() | This record type contains an optional 32-bit address that is the entry point for program execution.[3][4][3] An address of$00000000 is used if no specific address is required, such as when S-records are used to burn EPROMs and the like. This record type is used to terminate a series of S3 records.[3] The data field is not used. |
S8 | Start address (termination) | 24-bit address | ![]() | This record type contains an optional 24-bit address that is the entry point for program execution.[3][4][3] An address of$000000 is used if no specific address is required. This record type is used to terminate a series of S2 records.[3] The data field is not used. |
S9 | Start address (termination) | 16-bit address | ![]() | This record type contains an optional 16-bit address that is the entry point for program execution.[3][4][3] An address of$0000 is used if no specific address is required. This record type is used to terminate a series of S1 records.[3] The data field is not used. |
Although some Unix documentation states "the order of S-records within a file is of no significance and no particular order may be assumed",[4] in practice most software has ordered the SREC records. The typical record order starts with a (sometimes optional) S0 header record, continues with a sequence of one or more S1/S2/S3 data records, may have one optional S5/S6 count record, and ends with one appropriate S7/S8/S9 termination record.
Amanual page from historicUnix O/S documentation states: "An S-record file consists of a sequence of specially formattedASCII character strings. An S-record will be less than or equal to 78 bytes in length". The manual page further limits the number of characters in the Data field to 64 (or 32 data bytes).[4] A record with an 8-hex-character address and 64 data characters would be 78 (2 + 2 + 8 + 64 + 2) characters long (this count ignores possible end-of-line or string termination characters), and fits on an 80-character wideteleprinter. A note at the bottom of the manual page states, "This manual page is the only place that a 78-byte limit on total record length or 64-byte limit on data length is documented. These values shouldn't be trusted for the general case".[4]
If the 78 byte historical limit is ignored, the maximum length of an S-record would be 514 characters. Assuming a Byte Count of 0xFF (255), it would be 2 for Record Type field + 2 for Byte Count field + (2 * 255) for Address / Data / Checksum fields. Additional buffer space may be required to hold up to two control characters (carriage return and/orline feed), and/or a NUL (0x00) string terminator for C/C++ programming languages. Using long line lengths has problems: "The Motorola S-record format definition permits up to 255 bytes of payload, or lines of 514 characters, plus the line termination. AllEPROM programmers should have sufficiently large line buffers to cope with records this big. Few do."[6]
The minimum amount of data for S0/S1/S2/S3 records is zero.
Some historical documentation recommends a maximum of 32 bytes of data (64 hex characters) in this field[4] (maybe because 32 is the largestpower of 2 of data that would fit on an80 column wideteleprinter /computer terminal /punched card).
If the 32 byte historical limit is ignored, then the maximum amount of data varies depending on the size of the address field (4 / 6 / 8). The maximum number of bytes of data is calculated by 255 (maximum for Byte Count field) minus (1 byte for Checksum field) minus (number of bytes in the Address field), thus the maximum amount of data for each record type is: 252 data bytes (504 hex characters) for S0 & S1 records, 251 data bytes (502 hex characters) for S2 records, 250 data bytes (500 hex characters) for S3 records.
Other than ASCII-to-hex converted comments in S0 header records, the SREC file format doesn't officially support human-readableASCII comments, though some software ignores all lines that don't start with "S" and/or ignores all text after the Checksum field (thus trailing text is sometimes used (incompatibly) for comments). For example, the CCS PIC compiler supports placing a ";" comment line at the top or bottom of anIntel HEX file, and its manuals states "some programmers (MPLAB in particular) do not like comments at the top of the hex file", which is why the compiler has the option of placing the comment at the bottom of the hex file.[7]
Record type Byte count Address Data Checksum
The following example record:
S1137AF00A0A0D0000000000000000000000000061
is decoded to show how the checksum value is calculated. The following example uses a dollar sign ($) to indicate a hexadecimal value (a Motorola convention):
$13 + $7A + $F0 + $0A + $0A + $0D + $00 + ... + $00 = $019E
sum.$01
) of the sum and retain the least significant byte (LSB), which is$9E
.$61
.In theC programming language, the sum is converted into the checksum by:0xFF-(sum&0xFF)
S00F000068656C6C6F202020202000003CS11F00007C0802A6900100049421FFF07C6C1B787C8C23783C6000003863000026S11F001C4BFFFFE5398000007D83637880010014382100107C0803A64E800020E9S111003848656C6C6F20776F726C642E0A0042S5030003F9S9030000FC
[…] For compatibility with teletypewriters, some programs may limit the number of [data] bytes to as few as 28 (56 printable characters in the S-record). […]