|
How Do I Interpret Motorola
S & Intel HEX Formatted Data Records?
Question:
This frequently asked question is intended as a handy general reference
to
common formatted records. Be aware that the particular formatted
record you are using may have differences.
Answer:
(Date: Feb 10, 1999) This is a quick reference for data
records that I find especially
handy.
This includes:
- A small very basic example of a s and hex record.
- A brief description of most of the records and their fields
that you will encounter.
- An example of record formatting by other than 8 bit.
Small example of Motorola s record:
S00B00004441544120492F4FF3
S113000000FF0004000400040004000400040004D1
S113001000040004000400040004000400040004BC
S113002000040004000400040004000400040004AC
S1130030000400040004000400040004000400049C
S1130040000400040004000400040004000400048C
S1130050000400040004000400040004000400047C
S1130060000400040004000400040004000400046C
S1130070000400040004000400040004000400045C
S1130080000400040004000400040004000400044C
S1130090000400040004000400040004000400043C
S11300A0000400040004000400040004000400042C
S11300B0000400040004000400040004000400041C
S11300C0000400040004000400040004000400040C
S11300D000040004000400040004000400040004FC
S11300E000040004000400040004000400040004EC
S11300F000040004000400040004000400040004DC
Small example of Intel Hex record (33 I believe)
:020000020000FC
:020000040000FA
:1000000000FF0004000400040004000400040004D5
:1000100000040004000400040004000400040004C0
:1000200000040004000400040004000400040004B0
:1000300000040004000400040004000400040004A0
:100040000004000400040004000400040004000490
:100050000004000400040004000400040004000480
:100060000004000400040004000400040004000470
:100070000004000400040004000400040004000460
:100080000004000400040004000400040004000450
:100090000004000400040004000400040004000440
:1000A0000004000400040004000400040004000430
:1000B0000004000400040004000400040004000420
:1000C0000004000400040004000400040004000410
:1000D0000004000400040004000400040004000400
:1000E00000040004000400040004000400040004F0
:1000F00000040004000400040004000400040004E0
:020000020010EC
:1000000000040004000400040004000400040004D0
:1000100000040004000400040004000400040004C0
Motorola S-Records
1.0 Introduction
The Motorola S-Record Object file record format has a 4-character,
3 field prefix that defines
the start of record, record type and byte count. This prefix is
followed by a load address field
consisting of 4, 6 or 8 characters. Optional data follows the address
field. The record format
also has a 2-character suffix containing a checksum.
2.0 Record Types
The Motorola S-Record format record type is indicated by a capital
S followed by a
1-character record type. The Agilent 3070 software recognizes the
following 7 record types.
S0 Start Record
S1 Data Record (4-character address, 2 byte, 16 bit)
S2 Data Record (6-character address, 3 byte, 24 bit)
S3 Data Record (8-character address, 4 byte, 32 bit)
S7 End Record (used with 8-character address)
S8 End Record (used with 6-character address)
S9 End Record (used with 4-character address)
2.1 Start Record
Record type S0, the start record is normally used to signal that
other data records follow.
It may be used to store additional information in the object file
in the data field. The start
record begins with the capital S start character ("S")
followed by the 2-character byte count,
a 4-character address ("0000") and a 2-character checksum.
The byte count is the total
number of bytes used by the address, data and checksum fields. This
is the number of bytes
and NOT the number of characters; each byte is represented
by 2-characters. The
checksum is formed by taking the sum of the all the bytes in the
length address and data
fields and then taking the one's complement. The following
is an example of the simplest
start record (spaces are included for clarity only and are
not present in a real object file).
S0 03 0000 FC
2.2 Data Record
The record types S1, S2, S3 are virtually identical and are the
records which contain the
actual data of the object file. The record begins with the start
character ("S") followed by the 2-character byte count
and the appropriately sized address field. The data bytes follow
the
address field and the record is terminated with the 2-character
checksum.
S1 07 1FF0 1B2C3E4F 7F
S2 0B 002FF0 1B2C3E4F506172 8E
S3 15 FFFF0010 000102030405060708090A0B0C0D0E0F FF
2.3 End Record
The record types S7, S8 and S9 are also identical and are records
used to indicate the
end of data if the address is 0 and the start address if the address
is non zero. The three
different record types are required for the 3 different address
field sizes. The record begins
with the start character ("S") followed by the 2-character
byte count and the appropriately
sized address field. There are generally no data bytes in an end
record. The record is
terminated with the 2-character checksum.
S7 05 00000000 FA
S8 04 000000 FB
S9 03 0000 FC
3.0 Example
The following is an example of a Motorola S-Record Object file.
It contains a start record, a 6-character address data record and
the appropriate end record.
S0030000FC
S2081000F001020304ED
S804000000FB
1. Which gives us the following
1000F0 01
1000F1 02
1000F2 03
1000F3 04
4.0 Notes
- Checksum values are ignored.
- All values are hexadecimal
- Record types S0, S7, S8 and S9 are ignored
- Lines not starting with a ("S") raise an exception
- Unknown record types are ignored
Intel Hex-32, Code 99
1.0 Introduction
The Intel 32-bit Hexadecimal Object file record format has a 9-character,
4 field, prefix that
defines the start of record, byte count, load address and
record type. The record format also has a 2-character suffix containing
a checksum.
2.0 Record Types
The Intel 32-bit Hexadecimal Object file record format contains
six record types
00 Data Record
01 End Record
02 Extended Segment Address Record
03 Start Segment Address Record
04 Extended Linear Address Record
05 Start Linear Address Record
2.1 Data Record
Record type 00, the data record, is the record which contains the
data of the file. The data
record begins with the colon start character (":")
followed by the byte count, the address
of the first byte and the record type ("00"). Following
the record type are the data bytes. The
checksum follows the data bytes and is the 2's compliment
of the preceding bytes in the
record, excluding the start character. The following are examples
of data records (spaces
are included for clarity only and should not be found in a real
object file).
:10 0000 00 FFFEFDFCFBFAF9F8F7F6F5F4F3F2F1F0 FF
:05 0010 00 0102030405 AA
2.2 End Record
Record type 01, the end record, signals the end of the data file.
The end record starts with
the colon start character (":") followed by the byte count
("00"), the address ("0000"), the
record type ("01") and the checksum ("FF").
:00 0000 01 FF
2.3 Extended Segment Address Record
Record type 02, the extended segment address record, defines bits
4 through 19 of the segment base address. It can appear anywhere
within the object file and it affects the absolute memory address
of all subsequent data records in the file until it is changed.
The extended segment address record starts with the colon start
character (":") followed by the byte count ("02"),
the address ("0000"), the record type ("02"),
the 4 character ASCII representation of the hexadecimal number represented
by bits 4 through 19 of the segment base address and the 2 character
checksum.
:02 0000 02 1000 55
2.4 Start Segment Address Record
Record type 03, the start segment address record, defines bits
4 through 19 of the execution start segment base address for the
object file. This record is currently ignored.
:02 0000 03 0000 55
2.5 Extended Linear Address Record
Record type 04, the extended linear address record, defines bits
16 through 31 of the destination address. It can appear anywhere
in within the object file and it affects the absolute memory address
of all subsequent data records in the file until it is changed.
The extended linear address record starts with the colon start character
(":") followed by the byte count ("02"), the
address ("0000"), the record type ("04"),the
4 character ASCII representation of the hexadecimal number represented
by bits 16 through 31 of the destination address and the 2 character
checksum.
:02 0000 04 FFFF 55
2.6 Start Linear Address Record
Record type 05, the start linear address record, defines bits 16
through 31 of the execution start address for the object file. This
record is currently ignored.
:02 0000 05 0000 55
3.0 Example
The following is an example of an Intel Hexadecimal Object file
record. It contains the following records: extended linear address,extended
segment address, data and end.
:020000040108EA
:0200000212FFBD
:0401000090FFAA5502
:00000001FF
1. Determine the extended linear address offset for the data record.
(0108 in this example)
:02 0000 04 0108 EA
2. Determine the extended segment address for the data record.
(12FF in this example)
:02 0000 02 12FF BD
>3. Determine the address offset for the data in the data record.
(0100 in this example)
:04 0100 00 90FFAA55 02
4. Calculate the absolute address for the first byte of the data
record.
0108 0000 linear address offset shifted left 16 bits
+ 0001 2FF0 segment address offset shifted left 4 bits
+ 0000 0100 address offset from data record
= 0109 30F0 32 bit address for first data byte
5. Which gives us the following
010930F0 90
010930F1 FF
010930F2 AA
010930F3 55
4.0 Notes
- Checksum values are ignored.
- All values are hexadecimal
- Record types 03 and 05 are ignored
- Lines not starting with a colon (":") raise an exception
- Unknown record types are ignored
Details on files formatted for other than 8 bits:
This is a brief discussion of a Motorola s record with formatting
other than by 8 bits. The concepts also apply to the Intel Hex records.
These are the first two lines of an s record formated by 8 bits.
The address and data fields have a relationship of 1 address for
every 8 bits of data.
S224000000767B78B07E8612BD4A9F49EC2EB26ACE2
1906E95061D5DD607E51E8179452ACAFF
S22400002018293EAF53187F6F4AFE6C010EF977721E
0F75B7479471493DB703AF466254C7FF
Note that the address field for the first line is 000000 and the
second line is 000020. With the default format option which is 8,
the Agilent 3070 software interprets the first line as containing
address/data pairs:
00 76
01 7B
02 78
.. ..
.. ..
1E 2A
1F CA
The second line is interpreted as containing address/data pairs:
20 18
21 29
22 3E
.. ..
.. ..
2E 54
2F C7
This is the same file formated by 16 bits.
Each address is referenced to 16 bits of data:
S224000000767B78B07E8612BD4A9F49EC2EB26AC
E21906E95061D5DD607E51E8179452ACAFF
S22400001018293EAF53187F6F4AFE6C010EF97772
1E0F75B7479471493DB703AF466254C7FF
Note that the address field for the first line is 000000 and the
second line is 000010. So with the default format option, which
is 8, the Agilent 3070 software interprets the first line the same:
00 76
01 7B
02 78
.. ..
.. ..
1E 2A
1F CA
The second line starts to cause a problem because it contains overlapping
address/data pairs:
10 18
11 29
12 3E
.. ..
.. ..
1E 54
1F C7
Both the first and the second line have addresses 10 through 1F,
but the data for these addresses is different. This will cause data
corruption unless the Agilent 3070 software is flagged to interpret
this record as being referenced by 16.
To correctly interpret this file use the 'format 16 bit' option
to the file statement in the data block construct. If the format
16 option is used, then the address/data pairs for the second file
look like:
First line:
00 767B
01 78B0
02 7E86
.. . .
.. . .
0E 7945
0F 2ACA
Second line:
10 2ACA
11 3EAF
12 5318
.. . .
.. . .
1E 4662
1F 54C7
If you are familiar with the step option, this will seem very familiar.
This is not the same as the already existing step option to the
file statement. The step option allows you to manipulate the way
that the data file is applied to the address and data pins, but
it will not correctly interpret this type of record with formatting
other than 8 bit. The step option allows you to control the way
that the address information is mapped to the address pins in the
assign statement. The step option may be used in conjunction with
the format options on a chip with a multi-byte data bus and a file
with the individual addresses referenced to more than 8 bits of
data.
|