SREC (file format): Difference between revisions

From Darren's Wiki
m (1 revision imported)
No edit summary
 
(12 intermediate revisions by the same user not shown)
Line 1: Line 1:
{{Confuse|Motorola hexadecimal notation}}
'''Motorola S-record''' is a file format, created by [[Motorola]], that conveys binary information as [[hexadecimal|hex]] values in [[ASCII]] text form. This file format may also be known as '''SRECORD''', '''SREC''', '''S19''', '''S28''', '''S37'''. It is commonly used for programming [[flash memory]] in microcontrollers, [[EPROM]]s, [[EEPROM]]s, 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 "burn" the machine code into [[non-volatile memory]], or is transferred to the target system for loading and execution.
{{Use dmy dates|date=March 2020|cs1-dates=y}}
[[File:Motorola SREC Chart.png|thumb|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.)
{{Infobox file format
{| class="wikitable"
|name      = S-record
!Filename extension
|icon      =
|<code>.s19</code>, <code>.s28</code>, <code>.s37</code>, <code>.s</code>, <code>.s1</code>, <code>.s2</code>, <code>.s3</code>, <code>.sx</code>, <code>.srec</code>, <code>.exo</code>, <code>.mot</code>, <code>.mxt</code>
|screenshot = [[File:Motorola SREC Chart.png|border|230px]]
|-
|caption    = 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.)
!Developed by
|extension  = <tt>.s19</tt>, <tt>.s28</tt>, <tt>.s37</tt>, <tt>.s</tt>, <tt>.s1</tt>, <tt>.s2</tt>, <tt>.s3</tt>, <tt>.sx</tt>, <tt>.srec</tt>, <tt>.exo</tt>,<ref name="Xilinx_2010_EXO"/> <tt>.mot</tt>, <tt>.mxt</tt>
|Motorola
|mime      =
|}
|developer  = Motorola
]]
|type      =
|url        =
}}
 
'''Motorola S-record''' is a file format, created by [[Motorola]], that conveys binary information as [[hexadecimal|hex]] values in [[ASCII]] text form. This file format may also be known as '''SRECORD''', '''SREC''', '''S19''', '''S28''', '''S37'''. It is commonly used for programming [[flash memory]] in microcontrollers, [[EPROM]]s, [[EEPROM]]s, 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 "burn" the machine code into [[non-volatile memory]], or is transferred to the target system for loading and execution.
 
==Overview==
==Overview==
===History===
===History===
The S-record format was created in the mid-1970s for the [[Motorola 6800]] processor. [[Programming tool|Software development tools]] for that and other [[embedded processor]]s 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 S-record format was created in the mid-1970s for the [[Motorola 6800]] processor. [[Programming tool|Software development tools]] for that and other [[embedded processor]]s 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.
===Other hex formats===
===Other hex formats===
There are other ASCII encoding with a similar purpose. [[BPNF]], [[BHLF]], and [[B10F]] 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.
There are other ASCII encoding with a similar purpose. [[BPNF]], [[BHLF]], and [[B10F]] 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.
==Format==
==Format==
===Record structure===
===Record structure===
{| class="wikitable" style="text-align:center"
{| class="wikitable" style="text-align:center"
Line 29: Line 20:
| style='background: #FFCCCC' | S || style='background: #FFCCCC' | Type || style='background: #CCFFCC' | Byte Count || style='background: #CCCCFF' | Address || style='background: #CCFFFF' | Data || style='background: #CCCCCC' | Checksum
| style='background: #FFCCCC' | S || style='background: #FFCCCC' | Type || style='background: #CCFFCC' | Byte Count || style='background: #CCCCFF' | Address || style='background: #CCFFFF' | Data || style='background: #CCCCCC' | Checksum
|}
|}
An SREC format file consists of a series of ASCII text records. The records have the following structure from left to right:
An SREC format file consists of a series of ASCII text records. The records have the following structure from left to right:
# ''Record start'' - each record begins with an uppercase letter "S" character (ASCII 0x53) which stands for "Start-of-Record".<ref>{{cite book |title=MCM6830L7 MIKBUG / MINIBUG ROM |author-first1=Mike |author-last1=Wiles |author-first2=Andre |author-last2=Felix |editor-first=Michael |editor-last=Holley |date=2000-10-21 |orig-year=1975 |type=Engineering note |id=Note 100 |publisher=[[Motorola Semiconductor Products, Inc.]] |url=http://www.swtpc.com/mholley/MP_A/MikbugEn100.pdf |access-date=2019-06-16 |url-status=dead |archive-url=https://web.archive.org/web/20190616115550/http://www.swtpc.com/mholley/MP_A/MikbugEn100.pdf |archive-date=2019-06-16}} (23 pages)</ref>
# ''Record start'' - each record begins with an uppercase letter "S" character (ASCII 0x53) which stands for "Start-of-Record".
# ''Record type'' - single numeric digit "0" to "9", defining the type of record.
# ''Record type'' - single numeric digit "0" to "9", defining the type of record.
# ''Byte count'' - two hex digits, indicating the number of bytes (hex digit pairs) that follow in the rest of the record (address + data + checksum). This field has a minimum value of 3 for 16-bit address field plus 1 checksum byte, and a maximum value of 255 (0xFF).
# ''Byte count'' - two hex digits, indicating the number of bytes (hex digit pairs) that follow in the rest of the record (address + data + checksum). This field has a minimum value of 3 for 16-bit address field plus 1 checksum byte, and a maximum value of 255 (0xFF).
# ''Address'' - four / six / eight hex digits as determined by the record type. The address bytes are arranged in [[Endianness|big endian]] format.
# ''Address'' - four / six / eight hex digits as determined by the record type. The address bytes are arranged in [[Endianness|big endian]] format.
# ''Data'' - a sequence of 2''n'' hex digits, for ''n'' bytes of the data. For S1/S2/S3 records, a maximum of 32 bytes per record is typical since it will fit on an 80 character wide terminal screen, though 16 bytes would be easier to visually decode each byte at a specific address.
# ''Data'' - a sequence of 2''n'' hex digits, for ''n'' bytes of the data. For S1/S2/S3 records, a maximum of 32 bytes per record is typical since it will fit on an 80 character wide terminal screen, though 16 bytes would be easier to visually decode each byte at a specific address.
# ''Checksum'' - two hex digits, the [[least significant byte]] of [[ones' complement]] of the sum of the values represented by the two hex digit pairs for the byte count, address and data fields. See example section for a detailed checksum example.
# ''Checksum'' - two hex digits, the [[least significant byte]] of [[ones' complement]] of the sum of the values represented by the two hex digit pairs for the byte count, address and data fields. See example section for a detailed checksum example.
 
===Text line terminators===
===Text line terminators===
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 visually [[delimiter|delimiting]] the records and it also provides padding between records that can be used to improve machine [[parsing]] efficiency.
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 visually [[delimiter|delimiting]] the records and it also provides padding between records that can be used to improve machine [[parsing]] efficiency.


Programs that create HEX records typically use line termination characters that conform to the conventions of their [[operating system]]s. For example, Linux programs use a single LF character ([[Newline|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.
Programs that create HEX records typically use line termination characters that conform to the conventions of their [[operating system]]s. For example, Linux programs use a single LF character ([[Newline|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.
===Record types===
===Record types===
The following table describes 10 possible S-records. S4 is reserved and not currently defined. S6 was originally reserved but was later redefined.
The following table describes 10 possible S-records. S4 is reserved and not currently defined. S6 was originally reserved but was later redefined.
{| class="wikitable"
{| class="wikitable"
|-
|-
Line 57: Line 45:
| 16-bit<br>"0000"
| 16-bit<br>"0000"
| {{Na}}
| {{Na}}
| This record contains vendor specific ASCII text comment represented as a series of hex digit pairs. It is common to see the data for this record in the format of a [[null-terminated string]]. The text data can be anything including a mixture of the following information: file/module name, version/revision number, date/time, product name, vendor name, memory designator on PCB, copyright notice. It is common to see: 48 44 52 which is the ASCII H, D, and R - "HDR".<ref name="Tareski_2018"/>
| This record contains vendor specific ASCII text comment represented as a series of hex digit pairs. It is common to see the data for this record in the format of a [[null-terminated string]]. The text data can be anything including a mixture of the following information: file/module name, version/revision number, date/time, product name, vendor name, memory designator on PCB, copyright notice. It is common to see: 48 44 52 which is the ASCII H, D, and R - "HDR".
|-
|-
| align="center" | ''S1''
| align="center" | ''S1''
Line 63: Line 51:
| 16-bit<br>Address
| 16-bit<br>Address
| {{Ya}}
| {{Ya}}
| This record contains data that starts at the 16-bit address field.<ref name="SREC-Unix"/> This record is typically used for 8-bit microcontrollers, such as AVR, PIC, 8051, 68xx, 6502, 80xx, Z80. The number of bytes of data contained in this record is "Byte Count Field" minus 3 (that is, 2 bytes for "16-bit Address Field" and 1 byte for "Checksum Field").
| This record contains data that starts at the 16-bit address field. This record is typically used for 8-bit microcontrollers, such as AVR, PIC, 8051, 68xx, 6502, 80xx, Z80. The number of bytes of data contained in this record is "Byte Count Field" minus 3 (that is, 2 bytes for "16-bit Address Field" and 1 byte for "Checksum Field").
|-
|-
| align="center" | ''S2''
| align="center" | ''S2''
Line 69: Line 57:
| 24-bit<br>Address
| 24-bit<br>Address
| {{Ya}}
| {{Ya}}
| This record contains data that starts at a 24-bit address.<ref name="SREC-Unix"/>  The number of bytes of data contained in this record is "Byte Count Field" minus 4 (that is, 3 bytes for "24-bit Address Field" and 1 byte for "Checksum Field").
| This record contains data that starts at a 24-bit address. The number of bytes of data contained in this record is "Byte Count Field" minus 4 (that is, 3 bytes for "24-bit Address Field" and 1 byte for "Checksum Field").
|-
|-
| align="center" | ''S3''
| align="center" | ''S3''
Line 75: Line 63:
| 32-bit<br>Address
| 32-bit<br>Address
| {{Ya}}
| {{Ya}}
| This record contains data that starts at a 32-bit address.<ref name="SREC-Unix"/> This record is typically used for 32-bit microcontrollers, such as ARM and 680x0. The number of bytes of data contained in this record is "Byte Count Field" minus 5 (that is, 4 bytes for "32-bit Address Field" and 1 byte for "Checksum Field").
| This record contains data that starts at a 32-bit address. This record is typically used for 32-bit microcontrollers, such as ARM and 680x0. The number of bytes of data contained in this record is "Byte Count Field" minus 5 (that is, 4 bytes for "32-bit Address Field" and 1 byte for "Checksum Field").
|-
|-
| align="center" | ''S4''
| align="center" | ''S4''
Line 87: Line 75:
| 16-bit<br>Count
| 16-bit<br>Count
| {{Na}}
| {{Na}}
| This optional record contains a 16-bit count of S1/S2/S3 records.<ref name="SREC-Unix"/> This record is used if the record count is less than or equal to 65,535 (0xFFFF), otherwise S6 record would be used.
| This optional record contains a 16-bit count of S1/S2/S3 records. This record is used if the record count is less than or equal to 65,535 (0xFFFF), otherwise S6 record would be used.
|-
|-
| align="center" | ''S6''
| align="center" | ''S6''
Line 93: Line 81:
| 24-bit<br>Count
| 24-bit<br>Count
| {{Na}}
| {{Na}}
| This optional record contains a 24-bit count of S1/S2/S3 records. This record is used if the record count is less than or equal to 16,777,215 (0xFFFFFF). If less than 65,536 (0x10000), then S5 record would be used. '''NOTE:''' This newer record is the most recent change (it may not be official).<ref name="SREC-Unix"/>
| This optional record contains a 24-bit count of S1/S2/S3 records. This record is used if the record count is less than or equal to 16,777,215 (0xFFFFFF). If less than 65,536 (0x10000), then S5 record would be used. '''NOTE:''' This newer record is the most recent change (it may not be official).
|-
|-
| align="center" | ''S7''
| align="center" | ''S7''
Line 99: Line 87:
| 32-bit<br>Address
| 32-bit<br>Address
| {{Na}}
| {{Na}}
| This record contains the starting execution location at a 32-bit address.<ref name="SREC-Unix"/><ref name="SREC-term"/> This is used to terminate a series of S3 records. If a SREC file is only used to program a memory device and the execution location is ignored, then an address of zero could be used.
| This record contains the starting execution location at a 32-bit address. This is used to terminate a series of S3 records. If a SREC file is only used to program a memory device and the execution location is ignored, then an address of zero could be used.
|-
|-
| align="center" | ''S8''
| align="center" | ''S8''
Line 105: Line 93:
| 24-bit<br>Address
| 24-bit<br>Address
| {{Na}}
| {{Na}}
| This record contains the starting execution location at a 24-bit address.<ref name="SREC-Unix"/><ref name="SREC-term"/> This is used to terminate a series of S2 records. If a SREC file is only used to program a memory device and the execution location is ignored, then an address of zero could be used.
| This record contains the starting execution location at a 24-bit address. This is used to terminate a series of S2 records. If a SREC file is only used to program a memory device and the execution location is ignored, then an address of zero could be used.
|-
|-
| align="center" | ''S9''
| align="center" | ''S9''
Line 111: Line 99:
| 16-bit<br>Address
| 16-bit<br>Address
| {{Na}}
| {{Na}}
| This record contains the starting execution location at a 16-bit address.<ref name="SREC-Unix"/><ref name="SREC-term"/> This is used to terminate a series of S1 records. If a SREC file is only used to program a memory device and the execution location is ignored, then an address of zero could be used.
| This record contains the starting execution location at a 16-bit address. This is used to terminate a series of S1 records. If a SREC file is only used to program a memory device and the execution location is ignored, then an address of zero could be used.
|}
|}
===Record order===
===Record order===
Although some Unix documentation states "the order of S-records within a file is of no significance and no particular order may be assumed",<ref name="SREC-Unix"/> 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.
Although some Unix documentation states "the order of S-records within a file is of no significance and no particular order may be assumed", 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.
 
; S19-style 16-bit address records
; S19-style 16-bit address records
# S0
# S0
Line 122: Line 108:
# S5 (optional record)
# S5 (optional record)
# S9
# S9
; S28-style 24-bit address records
; S28-style 24-bit address records
# S0
# S0
Line 128: Line 113:
# S5 (optional record)
# S5 (optional record)
# S8
# S8
; S37-style 32-bit address records
; S37-style 32-bit address records
# S0
# S0
Line 134: Line 118:
# S5 (optional record)
# S5 (optional record)
# S7
# S7
===Limitations===
===Limitations===
''Record length'' - Unix manual page documentation states, "An S-record file consists of a sequence of specially formatted ASCII 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).<ref name="SREC-Unix"/> 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). The file could be printed on an 80-character wide teleprinter. 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".<ref name="SREC-Unix"/> If that limitation is ignored, the maximum length of an S-record is 514 characters: 2 for Record Type field + 2 for Byte Count field (whose value would be 0xFF=255) + 2 * 255 for Address, Data, and Checksum fields. Additional buffer space may be required for the line and string terminators. 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. All EPROM programmers should have sufficiently large line buffers to cope with records this big. Few do."<ref name="sf"/>
''Record length'' - Unix manual page documentation states, "An S-record file consists of a sequence of specially formatted ASCII 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). 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). The file could be printed on an 80-character wide teleprinter. 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". If that limitation is ignored, the maximum length of an S-record is 514 characters: 2 for Record Type field + 2 for Byte Count field (whose value would be 0xFF=255) + 2 * 255 for Address, Data, and Checksum fields. Additional buffer space may be required for the line and string terminators. 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. All EPROM programmers should have sufficiently large line buffers to cope with records this big. Few do."
 
''Data field'' - Some documentation recommends a maximum of 32 bytes of data (64 hex characters) in this field.<ref name="SREC-Unix"/> The minimum amount of data for S0/S1/S2/S3 records is zero. The maximum amount of data varies depending on the size of the address field. Since the Byte Count field can't be higher than 255 (0xFF), then the maximum number of bytes of data is calculated by 255 minus (1 byte for checksum field) minus (number of bytes in the address field). S0/S1 records support up to 252 bytes of data. S2 record supports up to 251 bytes of data. S3 record supports up to 250 bytes of data.


''Comments'' - The SREC file format does not support comments. Some software ignores all text lines that do not start with "S" and ignores all text after the checksum field; that extra text is sometimes used (incompatibly) for comments. For example, the CCS PIC compiler supports placing a ";" comment line at the top or bottom of an [[Intel 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.<ref name="CCS_2014"/>
''Data field'' - Some documentation recommends a maximum of 32 bytes of data (64 hex characters) in this field. The minimum amount of data for S0/S1/S2/S3 records is zero. The maximum amount of data varies depending on the size of the address field. Since the Byte Count field can't be higher than 255 (0xFF), then the maximum number of bytes of data is calculated by 255 minus (1 byte for checksum field) minus (number of bytes in the address field). S0/S1 records support up to 252 bytes of data. S2 record supports up to 251 bytes of data. S3 record supports up to 250 bytes of data.


''Comments'' - The SREC file format does not support comments. Some software ignores all text lines that do not start with "S" and ignores all text after the checksum field; that extra text is sometimes used (incompatibly) for comments. For example, the CCS PIC compiler supports placing a ";" comment line at the top or bottom of an [[Intel 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.
==Examples==
==Examples==
; Color legend
; Color legend
{{legend inline| #FFCCCC |Record type}}
{| class="wikitable" style="text-align:center"
{{legend inline| #CCFFCC |Byte count}}
|-
{{legend inline| #CCCCFF |Address}}
| style='background: #FFCCCC' | Record Type || style='background: #CCFFCC' | Byte Count || style='background: #CCCCFF' | Address || style='background: #CCFFFF' | Data || style='background: #CCCCCC' | Checksum
{{legend inline| #CCFFFF |Data}}
|}
{{legend inline| #CCCCCC |Checksum}}
 
===Checksum calculation===
===Checksum calculation===
The following example record:
The following example record:
  {{SREC HEX|1|13|7AF0|0A0A0D00000000000000000000000000|61}}
  {{SREC HEX|1|13|7AF0|0A0A0D00000000000000000000000000|61}}
is decoded to show how the checksum value is calculated as follows:
is decoded to show how the checksum value is calculated as follows:
# Add: Add each byte 0x13 + 0x7A + 0xF0 + 0x0A + 0x0A + 0x0D + 0x00 + ... + 0x00 = 0x19E total.
# Add: Add each byte 0x13 + 0x7A + 0xF0 + 0x0A + 0x0A + 0x0D + 0x00 + ... + 0x00 = 0x19E total.
# Mask: Keep the least significant byte of the total = 0x9E.
# Mask: Keep the least significant byte of the total = 0x9E.
# Complement: Compute [[ones' complement]] of least significant byte = 0x61.
# Complement: Compute [[ones' complement]] of least significant byte = 0x61.
===16-bit memory address===
===16-bit memory address===
  {{SREC HEX|0|0F|0000|68656C6C6F20202020200000|3C}}
  {{SREC HEX|0|0F|0000|68656C6C6F20202020200000|3C}}
Line 167: Line 144:
  {{SREC HEX|5|03|0003||F9}}
  {{SREC HEX|5|03|0003||F9}}
  {{SREC HEX|9|03|0000||FC}}
  {{SREC HEX|9|03|0000||FC}}
==See also==
==See also==
* [[Binary-to-text encoding]], a survey and comparison of encoding algorithms
* [[Binary-to-text encoding]], a survey and comparison of encoding algorithms
Line 173: Line 149:
* [[MOS Technology file format]]
* [[MOS Technology file format]]
* [[Tektronix hex format]]
* [[Tektronix hex format]]
==References==
{{Reflist|refs=
<ref name="Tareski_2018">{{Cite web |title=Motorola S-record description |author-last=Tareski |author-first=Val |website=www.amelek.gda.pl |url=http://www.amelek.gda.pl/avr/uisp/srecord.htm |access-date=2018-06-26}}</ref>
<ref name="SREC-Unix">{{cite web |title=Motorola S-records from Unix man pages |url=http://www.amelek.gda.pl/avr/uisp/srecord.htm |access-date=2014-06-30}}</ref>
<ref name="SREC-term">{{cite book |title=M68000 Family Programmer's Reference Manual |version=Revision 1 |publisher=[[Motorola]] ([[Freescale]]) |date=1992 |pages=C-1–C-5 |chapter=Appendix C |isbn=978-0-13723289-5 |url=http://www.freescale.com/files/archives/doc/ref_manual/M68000PRM.pdf}}</ref>
<ref name="sf">{{cite web |title=srec_examples |work=sourceforge.net |url=http://srecord.sourceforge.net/man/man1/srec_examples.html}}</ref>
<ref name="CCS_2014">{{citation |title=CCS Compiler Reference Manual PCB/PCM/PCH |publisher=[[Custom Computer Services, Inc.]] |date=May 2014 |page=107 |url=http://www.ccsinfo.com/downloads/ccs_c_manual.pdf |access-date=2015-02-08}}</ref>
<ref name="Xilinx_2010_EXO">{{cite web |title=AR#476 PROMGen - Description of PROM/EEPROM file formats: MCS, EXO, HEX, and others |at=Motorola EXORmacs - File Format Code 87 |date=2010-03-08 |publisher=[[Xilinx]] |url=https://www.xilinx.com/support/answers/476.html |access-date=2020-03-03 |url-status=live |archive-url=https://web.archive.org/web/20200303085851/https://www.xilinx.com/support/answers/476.html |archive-date=2020-03-03}}</ref>
}}
==Further reading==
* {{cite book |title=Operator Guide To Serial I/O Capabilities of Data I/O Programmers - Translation Format Package |chapter=2.8. Microprocessor Formats 2.8.1. Input Requirements: Motorola Exorciser Format. Select Code 82 |id=055-1901 |version=Revision C |date=October 1980 |publisher=[[Data I/O Corporation]] |page=2-9 |url=http://bitsavers.trailing-edge.com/test_equipment/dataIO/055-1901_System19_transPkg.pdf |access-date=2020-03-01 |url-status=live |archive-url=https://web.archive.org/web/20200301134810/http://bitsavers.trailing-edge.com/test_equipment/dataIO/055-1901_System19_transPkg.pdf |archive-date=2020-03-01}}
* {{cite book |title=M1468705EVM Evaluation Module User's Manual |edition=1 |id=M1468705EVM/Dl |publisher=[[Motorola Inc.]] |date=December 1983 |url=https://archive.org/details/bitsavers_motorola68ionModuleUsersManualDec83_3216374 |access-date=2020-03-01}} [https://archive.org/stream/bitsavers_motorola68ionModuleUsersManualDec83_3216374/M146805EVM_Evaluation_Module_Users_Manual_Dec83_djvu.txt][https://archive.org/download/bitsavers_motorola68ionModuleUsersManualDec83_3216374/M146805EVM_Evaluation_Module_Users_Manual_Dec83.pdf]<!-- The manual for this board https://archive.org/details/bitsavers_motorola68_219174 -->
* {{cite book |title=Translation File Formats |date=1987-09-03<!-- or 1987-03-09? --> |publisher=[[Data I/O Corporation]] |url=http://webcache.googleusercontent.com/search?q=cache:wC7iuE425G4J:ftp://ftp.dataio.com/main/Manuals/UniFam/Translation%252520Formats.pdf+&cd=21&hl=de&ct=clnk&gl=de&client=firefox-b-d |access-date=2020-03-01 |url-status=live |archive-url=https://web.archive.org/web/20200301114550/http://webcache.googleusercontent.com/search?q=cache:wC7iuE425G4J:ftp://ftp.dataio.com/main/Manuals/UniFam/Translation%252520Formats.pdf+&cd=21&hl=de&ct=clnk&gl=de&client=firefox-b-d |archive-date=2020-03-01}} [ftp://ftp.dataio.com/main/Manuals/UniFam/Translation%252520Formats.pdf] (56 pages)
* {{cite book |author-first=Herwig |author-last=Feichtinger |title=Arbeitsbuch Mikrocomputer |trans-title=Microcomputer work book |chapter=1.8.5. Lochstreifen-Datenformate: Das Motorola-S-Format |trans-chapter=1.8.5. Paper tape data formats |language=de |location=Munich, Germany |publisher=[[Franzis Verlag|Franzis-Verlag GmbH]] |isbn=3-7723-8022-0 |date=1987 |edition=2 |pages=240–243 [242<!-- relevant page -->]}}
* {{cite book |title=M68HC05EVM Evaluation Module User's Manual |edition=4 |publisher=[[Motorola]] |date=1990 |chapter=Appendix A. S Record Information |page=A-1 |url=http://www.68bits.com/M68HC05EVM.pdf |url-status=dead |archive-url=<!-- https://web.archive.org/web/20150211202356/http://www.68bits.com/M68HC05EVM.pdf --> |quote=[…] 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). […]}}
* {{cite web |title=How Do I Interpret Motorola S & Intel HEX Formatted Data? Motorola S-Records |work=Home > Hardware > … > In-circuit Test Systems > Automated Test Equipment [Discontinued] > Details |publisher=[[Keysight Technologies]] |url=https://www.keysight.com/main/editorial.jspx?ckey=25084%3Aatg%3Afaq&id=25084%3Aatg%3Afaq&nid=-35181.0.00&lc=ger&cc=DE |access-date=2020-03-01 |url-status=live |archive-url=https://web.archive.org/web/20200301171624/https://www.keysight.com/main/editorial.jspx?ckey=25084%3Aatg%3Afaq&id=25084%3Aatg%3Afaq&nid=-35181.0.00&lc=ger&cc=DE |archive-date=2020-03-01}}
* {{cite web |title=Motorola S-record Format |author-first=Brian |author-last=Beard |date=2016 |orig-year=20 |work=Lucid Technologies |url=http://www.lucidtechnologies.info/moto.htm |access-date=2020-02-28 |url-status=live |archive-url=https://web.archive.org/web/20200228153613/http://www.lucidtechnologies.info/moto.htm |archive-date=2020-02-28}}
* {{cite web |title=The S Hexdump Format |author-first1=Joachim |author-last1=Strombergson |author-first2=Linus |author-last2=Walleij |author-first3=Patrik |author-last3=Faltstrom |date=October 2005 |id={{IETF-RFC|4194}} |publisher=[[IETF]] |url=https://tools.ietf.org/html/rfc4194 |access-date=2020-03-01 |url-status=live |archive-url=https://web.archive.org/web/20200301225557/https://tools.ietf.org/html/rfc4194 |archive-date=2020-03-01}}
== External links ==
== External links ==
* [http://srecord.sourceforge.net/ SRecord] is a collection of tools for manipulating SREC format files.
* [http://srecord.sourceforge.net/ SRecord] is a collection of tools for manipulating SREC format files.
Line 200: Line 155:
* [https://pypi.python.org/pypi/bincopy bincopy] is a Python package for manipulating SREC format files.
* [https://pypi.python.org/pypi/bincopy bincopy] is a Python package for manipulating SREC format files.
* [https://github.com/arkku/srec kk_srec] is a C library and program for reading the SREC format.
* [https://github.com/arkku/srec kk_srec] is a C library and program for reading the SREC format.
{{DEFAULTSORT:Srec (File Format)}}
[[Category:Binary-to-text encoding formats]]
[[Category:Embedded systems]]
[[Category:Computer file formats]]

Latest revision as of 10:58, 26 April 2021

Motorola S-record is a file format, created by Motorola, that conveys binary information as hex values in ASCII text form. This file format may also be known as SRECORD, SREC, S19, S28, S37. It is commonly used for programming flash 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 "burn" the machine code into non-volatile memory, or is transferred to the target system for loading and execution.

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 .s19, .s28, .s37, .s, .s1, .s2, .s3, .sx, .srec, .exo, .mot, .mxt
Developed by Motorola

Overview[edit | edit source]

History[edit | edit source]

The S-record format was created in the mid-1970s for the Motorola 6800 processor. Software development tools for that and other embedded 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.

Other hex formats[edit | edit source]

There are other ASCII encoding with a similar purpose. BPNF, BHLF, and B10F 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.

Format[edit | edit source]

Record structure[edit | edit source]

S Type Byte Count Address Data Checksum

An SREC format file consists of a series of ASCII text records. The records have the following structure from left to right:

  1. Record start - each record begins with an uppercase letter "S" character (ASCII 0x53) which stands for "Start-of-Record".
  2. Record type - single numeric digit "0" to "9", defining the type of record.
  3. Byte count - two hex digits, indicating the number of bytes (hex digit pairs) that follow in the rest of the record (address + data + checksum). This field has a minimum value of 3 for 16-bit address field plus 1 checksum byte, and a maximum value of 255 (0xFF).
  4. Address - four / six / eight hex digits as determined by the record type. The address bytes are arranged in big endian format.
  5. Data - a sequence of 2n hex digits, for n bytes of the data. For S1/S2/S3 records, a maximum of 32 bytes per record is typical since it will fit on an 80 character wide terminal screen, though 16 bytes would be easier to visually decode each byte at a specific address.
  6. Checksum - two hex digits, the least significant byte of ones' complement of the sum of the values represented by the two hex digit pairs for the byte count, address and data fields. See example section for a detailed checksum example.

Text line terminators[edit | edit source]

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 visually delimiting the records and it also provides padding between records that can be used to improve machine parsing efficiency.

Programs that create HEX records typically use line termination characters that conform to the conventions of their operating 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.

Record types[edit | edit source]

The following table describes 10 possible S-records. S4 is reserved and not currently defined. S6 was originally reserved but was later redefined.

Record
field
Record
purpose
Address
field
Data
field
Record
description
S0 Header 16-bit
"0000"
No This record contains vendor specific ASCII text comment represented as a series of hex digit pairs. It is common to see the data for this record in the format of a null-terminated string. The text data can be anything including a mixture of the following information: file/module name, version/revision number, date/time, product name, vendor name, memory designator on PCB, copyright notice. It is common to see: 48 44 52 which is the ASCII H, D, and R - "HDR".
S1 Data 16-bit
Address
Yes This record contains data that starts at the 16-bit address field. This record is typically used for 8-bit microcontrollers, such as AVR, PIC, 8051, 68xx, 6502, 80xx, Z80. The number of bytes of data contained in this record is "Byte Count Field" minus 3 (that is, 2 bytes for "16-bit Address Field" and 1 byte for "Checksum Field").
S2 Data 24-bit
Address
Yes This record contains data that starts at a 24-bit address. The number of bytes of data contained in this record is "Byte Count Field" minus 4 (that is, 3 bytes for "24-bit Address Field" and 1 byte for "Checksum Field").
S3 Data 32-bit
Address
Yes This record contains data that starts at a 32-bit address. This record is typically used for 32-bit microcontrollers, such as ARM and 680x0. The number of bytes of data contained in this record is "Byte Count Field" minus 5 (that is, 4 bytes for "32-bit Address Field" and 1 byte for "Checksum Field").
S4 Reserved N/A N/A This record is reserved.
S5 Count 16-bit
Count
No This optional record contains a 16-bit count of S1/S2/S3 records. This record is used if the record count is less than or equal to 65,535 (0xFFFF), otherwise S6 record would be used.
S6 Count 24-bit
Count
No This optional record contains a 24-bit count of S1/S2/S3 records. This record is used if the record count is less than or equal to 16,777,215 (0xFFFFFF). If less than 65,536 (0x10000), then S5 record would be used. NOTE: This newer record is the most recent change (it may not be official).
S7 Start Address
(Termination)
32-bit
Address
No This record contains the starting execution location at a 32-bit address. This is used to terminate a series of S3 records. If a SREC file is only used to program a memory device and the execution location is ignored, then an address of zero could be used.
S8 Start Address
(Termination)
24-bit
Address
No This record contains the starting execution location at a 24-bit address. This is used to terminate a series of S2 records. If a SREC file is only used to program a memory device and the execution location is ignored, then an address of zero could be used.
S9 Start Address
(Termination)
16-bit
Address
No This record contains the starting execution location at a 16-bit address. This is used to terminate a series of S1 records. If a SREC file is only used to program a memory device and the execution location is ignored, then an address of zero could be used.

Record order[edit | edit source]

Although some Unix documentation states "the order of S-records within a file is of no significance and no particular order may be assumed", 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.

S19-style 16-bit address records
  1. S0
  2. S1 (one or more records)
  3. S5 (optional record)
  4. S9
S28-style 24-bit address records
  1. S0
  2. S2 (one or more records)
  3. S5 (optional record)
  4. S8
S37-style 32-bit address records
  1. S0
  2. S3 (one or more records)
  3. S5 (optional record)
  4. S7

Limitations[edit | edit source]

Record length - Unix manual page documentation states, "An S-record file consists of a sequence of specially formatted ASCII 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). 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). The file could be printed on an 80-character wide teleprinter. 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". If that limitation is ignored, the maximum length of an S-record is 514 characters: 2 for Record Type field + 2 for Byte Count field (whose value would be 0xFF=255) + 2 * 255 for Address, Data, and Checksum fields. Additional buffer space may be required for the line and string terminators. 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. All EPROM programmers should have sufficiently large line buffers to cope with records this big. Few do."

Data field - Some documentation recommends a maximum of 32 bytes of data (64 hex characters) in this field. The minimum amount of data for S0/S1/S2/S3 records is zero. The maximum amount of data varies depending on the size of the address field. Since the Byte Count field can't be higher than 255 (0xFF), then the maximum number of bytes of data is calculated by 255 minus (1 byte for checksum field) minus (number of bytes in the address field). S0/S1 records support up to 252 bytes of data. S2 record supports up to 251 bytes of data. S3 record supports up to 250 bytes of data.

Comments - The SREC file format does not support comments. Some software ignores all text lines that do not start with "S" and ignores all text after the checksum field; that extra text is sometimes used (incompatibly) for comments. For example, the CCS PIC compiler supports placing a ";" comment line at the top or bottom of an Intel 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.

Examples[edit | edit source]

Color legend
Record Type Byte Count Address Data Checksum

Checksum calculation[edit | edit source]

The following example record:

S1137AF00A0A0D0000000000000000000000000061

is decoded to show how the checksum value is calculated as follows:

  1. Add: Add each byte 0x13 + 0x7A + 0xF0 + 0x0A + 0x0A + 0x0D + 0x00 + ... + 0x00 = 0x19E total.
  2. Mask: Keep the least significant byte of the total = 0x9E.
  3. Complement: Compute ones' complement of least significant byte = 0x61.

16-bit memory address[edit | edit source]

S00F000068656C6C6F202020202000003C
S11F00007C0802A6900100049421FFF07C6C1B787C8C23783C6000003863000026
S11F001C4BFFFFE5398000007D83637880010014382100107C0803A64E800020E9
S111003848656C6C6F20776F726C642E0A0042
S5030003F9
S9030000FC

See also[edit | edit source]

External links[edit | edit source]

  • SRecord is a collection of tools for manipulating SREC format files.
  • BIN2MOT, BINARY to Motorola S-Record file converter utility.
  • SRecordizer is a tool for viewing, editing, and error checking S19 format files.
  • bincopy is a Python package for manipulating SREC format files.
  • kk_srec is a C library and program for reading the SREC format.