网普技术论坛 网普科技  
» 游客:   网普主页 | 注册 | 登录 | 帮助
 

作者:
标题: [翻译]什么是Intel HEX文件格式? 上一主题 | 下一主题
网普科技
网普管理员

网普科技人民公仆


积分 3079
发贴 2862
注册 2004-6-26
来自 网普科技
状态 离线
#1  [翻译]什么是Intel HEX文件格式?

http://www.netpu.net
网普科技版权所有,转载请注明作者和出处并保持文章原貌
(网普科技优质廉价美国主机、美国LINUX虚拟主机服务)

原文地址
http://bbs.netpu.net/viewthread.php?tid=1690

说明:
以前做格式转换的时候翻译的一篇文章。那时候对这些东西了解不够深入,所以翻译的不好。大概3、4年没有接触这方面的信息,所以即便有错误,现在也无法修正了。整理电脑的时候无意中看到,贴出来,但愿不会遭到嘲笑。欢迎批评指正。


问题:
什么是Intel HEX文件格式?

回答:

Intel HEX文件是由一行行符合Intel HEX文件格式的文本所构成的ASCII文本文件。在Intel HEX文件中,每一行包含一个HEX记录。这些记录由对应机器语言码和/或常量数据的十六进制编码数字组成。Intel HEX文件通常用于传输将被存于ROM或者EPROM中的程序和数据。大多数EPROM编程器或模拟器使用Intel HEX文件。

记录格式
Intel HEX由任意数量的十六进制记录组成。每个记录包含5个域,它们按以下格式排列:
:llaaaatt[dd...]cc
每一组字母对应一个不同的域,每一个字母对应一个十六进制编码的数字。每一个域由至少两个十六进制编码数字组成,它们构成一个字节,就像以下描述的那样:
: 每个Intel HEX记录都由冒号开头.
ll 是数据长度域,它代表记录当中数据字节(dd)的数量.
aaaa 是地址域,它代表记录当中数据的起始地址.
tt 是代表HEX记录类型的域,它可能是以下数据当中的一个:
00 – 数据记录
01 – 文件结束记录
02 – 扩展段地址记录
04 – 扩展线性地址记录
dd 是数据域,它代表一个字节的数据.一个记录可以有许多数据字节.记录当中数据字节的数量必须和数据长度域(ll)中指定的数字相符.
cc 是校验和域,它表示这个记录的校验和.校验和的计算是通过将记录当中所有十六进制编码数字对的值相加,以256为模进行以下补足.

数据记录
Intel HEX文件由任意数量以回车换行符结束的数据记录组成.数据记录外观如下:
:10246200464C5549442050524F46494C4500464C33
其中:
10 是这个记录当中数据字节的数量.
2462 是数据将被下载到存储器当中的地址.
00 是记录类型(数据记录)
464C…464C是数据.
33 是这个记录的校验和.

扩展线性地址记录(HEX386)
扩展线性地址记录也叫作32位地址记录或HEX386记录.这些记录包含数据地址的高16位.扩展线性地址记录总是有两个数据字节,外观如下:
:02000004FFFFFC
其中:
02 是这个记录当中数据字节的数量.
0000 是地址域,对于扩展线性地址记录,这个域总是0000.
04 是记录类型 04(扩展线性地址记录)
FFFF 是地址的高16位.
FC 是这个记录的校验和,计算方法如下:
01h + NOT(02h + 00h + 00h + 04h + FFh + FFh).
当一个扩展线性地址记录被读取,存储于数据域的扩展线性地址被保存,它被应用于从Intel HEX文件读取来的随后的记录.线性地址保持有效,直到它被另外一个扩展地址记录所改变.
通过把记录当中的地址域与被移位的来自扩展线性地址记录的地址数据相加获得数据记录的绝对存储器地址.
以下的例子演示了这个过程..
来自数据记录地址域的地址                              2462
扩展线性地址记录的数据域                      + FFFF
                                  ------------
绝对存储器地址                               FFFF2462

扩展段地址记录(HEX86)
扩展段地址记录也叫HEX86记录,它包括4-19位数据地址段.扩展段地址记录总是有两个数据字节,外观如下:
:020000021200EA
其中:
02 是记录当中数据字节的数量.
0000 是地址域.对于扩展段地址记录,这个域总是0000.
02 是记录类型 02(扩展段地址记录)
1200 是地址段.
EA 是这个记录的校验和,计算方法如下:
01h + NOT(02h + 00h + 00h + 02h + 12h + 00h).
当一个扩展段地址记录被读取,存储于数据域的扩展段地址被保存,它被应用于从Intel HEX文件读取来的随后的记录.段地址保持有效,直到它被另外一个扩展地址记录所改变.
通过把记录当中的地址域与被移位的来自扩展段地址记录的地址数据相加获得数据记录的绝对存储器地址.
以下的例子演示了这个过程..
来自数据记录地址域的地址                             2462
扩展段地址记录数据域                      +  1200
                                 ---------
绝对存储器地址                    00014462

文件结束(EOF)记录
Intel HEX文件必须以文件结束(EOF)记录结束.这个记录的记录类型域的值必须是01.EOF记录外观总是如下:
:00000001FF
其中:
00 是记录当中数据字节的数量.
0000 是数据被下载到存储器当中的地址.在文件结束记录当中地址是没有意义被忽略的.0000h是典型的地址.
01 是记录类型 01(文件结束记录)
FF 是这个记录的校验和,计算方法如下:
01h + NOT(00h + 00h + 00h + 01h).

Intel HEX文件例子:
下面是一个完整的Intel HEX文件的例子:
:10001300AC12AD13AE10AF1112002F8E0E8F0F2244
:10000300E50B250DF509E50A350CF5081200132259
:03000000020023D8
:0C002300787FE4F6D8FD7581130200031D
:10002F00EFF88DF0A4FFEDC5F0CEA42EFEEC88F016
:04003F00A42EFE22CB
:00000001FF


总结
如果您有问题,请与tech[AT]netpu.net联系。{ 请将[AT]替换成@ }

http://www.netpu.net
网普科技版权所有,转载请注明作者和出处并保持文章原貌
(网普科技优质廉价美国主机、美国LINUX虚拟主机服务)


附:英文原文
QUESTION
What is the Intel HEX file format?
ANSWER
The Intel HEX file is an ASCII text file with lines of text that follow the
Intel HEX file format. Each line in an Intel HEX file contains one HEX record.
These records are made up of hexadecimal numbers that represent machine
language code and/or constant data. Intel HEX files are often used to transfer
the program and data that would be stored in a ROM or EPROM. Most EPROM
programmers or emulators can use Intel HEX files.
Record Format
An Intel HEX file is composed of any number of HEX records. Each record is made
up of five fields that are arranged in the following format:
:llaaaatt[dd...]cc
Each group of letters corresponds to a different field, and each letter
represents a single hexadecimal digit. Each field is composed of at least two
hexadecimal digits-which make up a byte-as described below:
: is the colon that starts every Intel HEX record.
ll is the record-length field that represents the number of data bytes (dd) in
the record.
aaaa is the address field that represents the starting address for subsequent
data in the record.
tt is the field that represents the HEX record type, which may be one of the
following:
00 - data record
01 - end-of-file record
02 - extended segment address record
04 - extended linear address record
dd is a data field that represents one byte of data. A record may have multiple
data bytes. The number of data bytes in the record must match the number
specified by the ll field.
cc is the checksum field that represents the checksum of the record. The
checksum is calculated by summing the values of all hexadecimal digit pairs in
the record modulo 256 and taking the two's complement.
Data Records
The Intel HEX file is made up of any number of data records that are terminated
with a carriage return and a linefeed. Data records appear as follows:
:10246200464C5549442050524F46494C4500464C33
where:
10 is the number of data bytes in the record.
2462 is the address where the data are to be located in memory.
00 is the record type 00 (a data record).
464C...464C is the data.
33 is the checksum of the record.
Extended Linear Address Records (HEX386)
Extended linear address records are also known as 32-bit address records and
HEX386 records. These records contain the upper 16 bits (bits 16-31) of the
data address. The extended linear address record always has two data bytes and
appears as follows:
:02000004FFFFFC
where:
02 is the number of data bytes in the record.
0000 is the address field. For the extended linear address record, this field
is always 0000.
04 is the record type 04 (an extended linear address record).
FFFF is the upper 16 bits of the address.
FC is the checksum of the record and is calculated as
01h + NOT(02h + 00h + 00h + 04h + FFh + FFh).
When an extended linear address record is read, the extended linear address
stored in the data field is saved and is applied to subsequent records read
from the Intel HEX file. The linear address remains effective until changed by
another extended address record.
The absolute-memory address of a data record is obtained by adding the address
field in the record to the shifted address data from the extended linear
address record. The following example illustrates this process..
Address from the data record's address field      2462
Extended linear address record data field     FFFF
                                              --------
Absolute-memory address                       FFFF2462
Extended Segment Address Records (HEX86)
Extended segment address records-also known as HEX86 records-contain bits 4-19
of the data address segment. The extended segment address record always has two
data bytes and appears as follows:
:020000021200EA
where:
02 is the number of data bytes in the record.
0000 is the address field. For the extended segment address record, this field
is always 0000.
02 is the record type 02 (an extended segment address record).
1200 is the segment of the address.
EA is the checksum of the record and is calculated as
01h + NOT(02h + 00h + 00h + 02h + 12h + 00h).
When an extended segment address record is read, the extended segment address
stored in the data field is saved and is applied to subsequent records read
from the Intel HEX file. The segment address remains effective until changed by
another extended address record.
The absolute-memory address of a data record is obtained by adding the address
field in the record to the shifted-address data from the extended segment
address record. The following example illustrates this process.
Address from the data record's address field     2462
Extended segment address record data field      1200
                                             --------
Absolute memory address                      00014462
End-of-File (EOF) Records
An Intel HEX file must end with an end-of-file (EOF) record. This record must
have the value 01 in the record type field. An EOF record always appears as
follows:
:00000001FF
where:
00 is the number of data bytes in the record.
0000 is the address where the data are to be located in memory. The address in
end-of-file records is meaningless and is ignored. An address of 0000h is
typical.
01 is the record type 01 (an end-of-file record).
FF is the checksum of the record and is calculated as
01h + NOT(00h + 00h + 00h + 01h).
Example Intel HEX File
Following is an example of a complete Intel HEX file:
:10001300AC12AD13AE10AF1112002F8E0E8F0F2244
:10000300E50B250DF509E50A350CF5081200132259
:03000000020023D8
:0C002300787FE4F6D8FD7581130200031D
:10002F00EFF88DF0A4FFEDC5F0CEA42EFEEC88F016
:04003F00A42EFE22CB
:00000001FF



天理路上甚宽,稍游心,胸中便觉广大宏朗;
人欲路上甚窄,才寄迹,眼前俱是荆棘泥涂。



网普科技,优质美国主机服务!
美国Linux主机,美国虚拟主机
支持PHP+MYSQL+cPanel+EMAIL
为用户负责,拒绝反动、赌博及色情内容! QQ:126818

发送QQ消息
2005-10-29 09:09 AM
查看资料  访问主页  发短消息  QQ   编辑帖子  引用回复 顶部
vfdff
网普朋友





积分 3
发贴 3
注册 2007-7-25
状态 离线
#2  什么是Intel HEX文件格式?

02 – 扩展段地址记录
04 – 扩展线性地址记录

为什么 上面的两种类型怎么很少看到呀?

2007-7-25 09:10 PM
查看资料  发送邮件  发短消息   编辑帖子  引用回复 顶部
vfdff
网普朋友





积分 3
发贴 3
注册 2007-7-25
状态 离线
#3  

哪位高手能根据上面的规则写一个程序判断某文件是不是符合 Intel HEX 文件结构?

2007-7-25 09:13 PM
查看资料  发送邮件  发短消息   编辑帖子  引用回复 顶部
网普科技
网普管理员

网普科技人民公仆


积分 3079
发贴 2862
注册 2004-6-26
来自 网普科技
状态 离线
#4  

这个不是很难啊
读取每一行,判断一下就可以了



天理路上甚宽,稍游心,胸中便觉广大宏朗;
人欲路上甚窄,才寄迹,眼前俱是荆棘泥涂。



网普科技,优质美国主机服务!
美国Linux主机,美国虚拟主机
支持PHP+MYSQL+cPanel+EMAIL
为用户负责,拒绝反动、赌博及色情内容! QQ:126818

发送QQ消息
2007-7-25 11:05 PM
查看资料  访问主页  发短消息  QQ   编辑帖子  引用回复 顶部
茱莉娅
THE BODY SHOP美容顾问

茱莉娅美体小铺


积分 3079
发贴 2862
注册 2009-5-21
来自 茱莉娅美体小铺
状态 离线
#4  赞助商信息The body shop

茱莉娅美体小铺
茱莉娅美体小铺淘宝店
茱莉娅美体小铺


茱莉娅美体小铺淘宝店
2007-7-25 11:05 PM
查看资料  访问主页  发短消息  QQ   编辑帖子  引用回复 顶部


可打印版本 | 推荐给朋友 | 订阅主题 | 收藏主题



论坛跳转:  




Powered by Discuz! 2.5 © 2001-2005 Comsenz Technology Ltd.
Processed in 0.023349 second(s), 5 queries, Gzip enabled
------------------------------------------------------------------------------
本论坛属网普科技交流与技术支持论坛!
拒绝任何人以任何形式在本论坛发表与中华人民共和国法律相抵触的言论!
美国主机, 美国虚拟主机, cPanel+PHP+Mysql+Ftp+Email+Zend+GD2+国际域名支持
技术支持 QQ: 126818 EMail & MSN: support[AT]netpu.net
[ 联系我们 ] - [ 网普科技 ]