Mot file

From SEGGER Knowledge Base
Jump to navigation Jump to search

Motorola S-Record (SREC) is a file format commonly used to represent binary data in an ASCII text format that people can read. It was originally developed by Motorola for their line of microcontrollers, and it has since become a widely adopted standard for exchanging binary data between devices in a form that people can read. A Motorola file is ASCII encoded and can be opened and even modified in a regular text editor. This can be useful when looking at a particular address range or when eliminating a certain address range manually.

Because the respective data is represented in HEX form, 2 bytes describe 1 byte. In addition to the address information, "code density" is only about 40%, meaning that a 100 KB .mot file contains about 40 KB of actual data.

Overview

History

The S-record format was created by Motorola in the mid-1970s for its 6800 processor. Software development tools for that and other CPUs would generate executable code and data in this format. PROM and EPROM programmers would then read the S-record format and "burn" the data into the chips used as read-only data in these early day embedded systems.

The initial version of the S-record format (otherwise known as a "Motorola file") had only one type of data record: the S1 data record with a 16-bit address field. As processors with increased address space were introduced, there was also a need for larger address fields, so the S2 and S3 data records were introduced.

Similar file types

The only similar file type that comes to mind is Intel HEX format. This format was defined by Intel at about the same time as S-record, and it uses a similar HEX/Ascii representation to describe data bytes and their location in the address space.

On account of Intel's 8086 CPU with segmentation, the Intel HEX format is not as straightforward as the Motorola format, hence Motorola is generally preferred.

Binary files

Binary files represent binary data, so one byte of data is represented by one byte in the file. They do not contain address information or checksums, and they also cannot contain gaps since they lack address information.

File structure

A Motorola file consists of individual lines, terminated by either LF or CR LF. Every line contains one record. Typical files have a structure as shown below:

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

In todays's world of 32-bit CPUs, 32-bit address records are most common. However, software needs to be able to read and understand 16- and 24-bit address records as well. Using 16- or 24-bit address records (S1, S2) is advantageous as the files are smaller, so it is beneficial to use them where they are sufficient.

Record structure

Each record in the file begins with an "S" character followed by a record-type identifier (S0 through S9), which specifies the record's purpose. An S-record can store actual data, vendor-specific information, and information about the starting address or the number of records.

Record structures consist of fields such as record length, memory address, data in hexadecimal format, and a checksum for data integrity. SREC files are generated by development tools, the format used is readable by people and facilitates debugging and manual editing, and checksums ensure accuracy in the transferred data during programming.

Application

The SREC file format is frequently used for programming memory devices like microcontrollers, EEPROMs, and flash memory. It is employed when transferring machine code or firmware updates from a development environment (such as a compiler or assembler) to the target device.

Click here for more information.