Motorola created the S-record format in the mid-1970s for its 6800 processor: its development tools wrote S-record files and PROM programmers read them to burn EPROMs. The S2 record was added for the 68000 and S3 for the 68012 and later 68000-series chips. This page follows the descriptions in Wikipedia and the SRecord package’s manual page; Motorola’s original document was not among the sources read.
Record layout
Each record is a line of ASCII text. Records are separated by one or more line ends (LF, or CR LF), so each one sits alone on its line.
| Characters | Field | Meaning |
|---|---|---|
| 1 | Start | An upper-case S (0x53). |
| 1 | Type | One digit, 0 to 9; see record types. |
| 2 | Byte count | Number of bytes that follow: address, data and checksum. At least 3, at most 255 (00, 01 and 02 are illegal). |
| 4, 6 or 8 | Address | 2, 3 or 4 bytes depending on the type, big-endian. |
| 2 × n | Data | n bytes as hexadecimal digit pairs. |
| 2 | Checksum | See checksum. |
Record types
| Type | Name | Address | Data | Meaning |
|---|---|---|---|---|
S0 | Header | 2 bytes, 0000 | any | Descriptive information about the block of records that follows, often a NUL-terminated text; HDR (48 44 52) is common when there is nothing more specific. |
S1 | Data | 2 bytes | count − 3 bytes | Data to be placed at a 16-bit address. |
S2 | Data | 3 bytes | count − 4 bytes | Data to be placed at a 24-bit address. |
S3 | Data | 4 bytes | count − 5 bytes | Data to be placed at a 32-bit address. |
S4 | — | — | — | Not defined by the S-record standard. |
S5 | Count | 2 bytes: the count | none | Optional: the number of S1, S2 and S3 records sent in the block, held in the address field. |
S6 | Count | 3 bytes: the count | none | Optional and not in the original standard: the same count as a 24-bit number, for blocks with more than 65 535 data records. |
S7 | Termination | 4 bytes | none | Ends a block of S3 records. The address may give the 32-bit entry point; 00000000 if none is needed. |
S8 | Termination | 3 bytes | none | Ends a block of S2 records, with an optional 24-bit entry point. |
S9 | Termination | 2 bytes | none | Ends a block of S1 records, with an optional 16-bit entry point. |
The SRecord manual notes open questions that the original description leaves:
whether a file may hold more than one count record, whether the count restarts after
each, and what happens when S5 and S6 are mixed. Its own srec_cat writes
at most one, using S6 only when the count does not fit in 16 bits.
Record order and file styles
Some Unix documentation says the order of records is of no significance, but most software writes them in this order, and names the style by its data record type:
| Style | Addresses | Records |
|---|---|---|
| S19 | 16-bit | S0, one or more S1, optional S5, S9 |
| S28 | 24-bit | S0, one or more S2, optional S5, S8 |
| S37 | 32-bit | S0, one or more S3, optional S5, S7 |
Line length
A byte count of 255 allows lines of up to 514 characters, so a record can carry at
most 252 data bytes (S1), 251 (S2) or 250 (S3). An old Unix manual page limited records
to 78 characters and 32 data bytes, and many sources still suggest 32 or 16 data bytes
per record. There is no comment syntax: some programs skip lines that do not start with
S or ignore text after the checksum, but other programs reject such
files.
Checksum
Add the byte count, the address bytes and the data bytes, keep the least significant
byte of the sum, and take its ones’ complement (0xFF − (sum AND 0xFF)).
S1137AF00A0A0D0000000000000000000000000061
13 + 7A + F0 + 0A + 0A + 0D + 00 × 13 = 019E
low byte 9E, ones’ complement 61 checksum 61
0x7AF0 and its checksum.Examples of every type
| Record | Meaning and checksum |
|---|---|
S00600004844521B | S0 header HDR. 06 + 48 + 44 + 52 = 0xE4; complement 1B. |
S111003848656C6C6F20776F726C642E0A0042 | S1: 14 bytes (Hello world., a line feed and a NUL) at 0x0038. 11 + 00 + 38 = 0x49, data 0x474, total 0x4BD; complement of BD is 42. |
S20801000001020304EC | S2: bytes 01 02 03 04 at 0x010000. 08 + 01 + 01 + 02 + 03 + 04 = 0x13; complement EC. |
S3090001000001020304EB | S3: the same bytes at 0x00010000. Sum 0x14; complement EB. |
S5030001FB | S5: one data record in the block. Sum 0x04; complement FB. |
S604000001FA | S6: the same count in 24 bits. Sum 0x05; complement FA. |
S70500000000FA | S7: end of an S3 block, entry point 0. Sum 0x05; complement FA. |
S804000000FB | S8: end of an S2 block, entry point 0. Sum 0x04; complement FB. |
S9030000FC | S9: end of an S1 block, entry point 0. Sum 0x03; complement FC. |
File names
Extensions in use include .s19, .s28, .s37
(after the styles above), .s, .s1, .s2,
.s3, .sx, .srec, .exo,
.mot and .mxt. Nothing inside the file depends on the
name.
Sources
- SREC (file format) – Wikipedia: history, record fields and types, order, line lengths, checksum example, extensions
- srec_motorola(5) – the SRecord package’s description of each record type, the checksum and the count-record questions
Unknown: the field layout some older Motorola documents gave for the S0 header’s data (module name, version and so on) was not in the sources read. The checksums of the examples were worked out by hand for this page.