Hex文件校驗(yàn)生成和驗(yàn)證
時間:2021-08-18 10:19:16
手機(jī)看文章
掃描二維碼
隨時隨地手機(jī)看文章
[導(dǎo)讀]關(guān)注星標(biāo)公眾號,不錯過精彩內(nèi)容編排?|strongerHuang微信公眾號|?嵌入式專欄手機(jī)升級系統(tǒng),下載完系統(tǒng)都會存在一個校驗(yàn)過程:其實(shí),在MCU升級過程中,也是需要校驗(yàn)hex文件,如果要想升級更可靠,還可以在hex或bin升級文件后再增加校驗(yàn)信息。我們之前公司做的一個遠(yuǎn)程升級...
關(guān)注 星標(biāo)公眾號,不錯過精彩內(nèi)容編排?| strongerHuang微信公眾號 |?嵌入式專欄
手機(jī)升級系統(tǒng),下載完系統(tǒng)都會存在一個校驗(yàn)過程:
其實(shí),在MCU升級過程中,也是需要校驗(yàn)hex文件,如果要想升級更可靠,還可以在hex或bin升級文件后再增加校驗(yàn)信息。
我們之前公司做的一個遠(yuǎn)程升級的產(chǎn)品,就是在升級文件之后增加了CRC16校驗(yàn)信息,在接收完整個升級文件之后,進(jìn)行校驗(yàn),這樣做的目的就是使升級更可靠。
今天來講講hex文件的校驗(yàn)和驗(yàn)證校驗(yàn)的內(nèi)容。
關(guān)于Hexhex 格式文件由 Intel 制定的一種十六進(jìn)制標(biāo)準(zhǔn)文件格式,是由編譯器轉(zhuǎn)換而成的一種用于下載到處理器里面的ASCII文本文件。
1.解釋維基百科解釋https://en.wikipedia.org/wiki/Intel_HEXIntel HEX?is a file format that conveys binary information in ASCII text form. It is commonly used for programming microcontrollers, EPROMs, and other types of?programmable logic devices. In a typical application, a compiler or assembler converts a program's source code (such as in 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 a ROM, or is transferred to the target system for loading and?execution.
Keil官網(wǎng)解釋https://www.keil.com/support/docs/1584/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.
2.格式hex行格式::BBAAAATT 【D···D】CC
其中::?代表行開始,固定為冒號:
BB代表Bytes,數(shù)據(jù)長度AAAA代表Address,地址TT代表Type,數(shù)據(jù)類型(標(biāo)識)D···D代表Date,數(shù)據(jù)
CC代表CheckSum,校驗(yàn)和
說明:BB數(shù)據(jù)長度,也就是D···D這個字段的數(shù)據(jù)長度;
AAAA地址,起始地址、偏移地址,根據(jù)數(shù)據(jù)類型(TT)有關(guān);
TT數(shù)據(jù)類型(標(biāo)識):
CC校驗(yàn)和計(jì)算公式:
手機(jī)升級系統(tǒng),下載完系統(tǒng)都會存在一個校驗(yàn)過程:
其實(shí),在MCU升級過程中,也是需要校驗(yàn)hex文件,如果要想升級更可靠,還可以在hex或bin升級文件后再增加校驗(yàn)信息。
我們之前公司做的一個遠(yuǎn)程升級的產(chǎn)品,就是在升級文件之后增加了CRC16校驗(yàn)信息,在接收完整個升級文件之后,進(jìn)行校驗(yàn),這樣做的目的就是使升級更可靠。
今天來講講hex文件的校驗(yàn)和驗(yàn)證校驗(yàn)的內(nèi)容。
關(guān)于Hexhex 格式文件由 Intel 制定的一種十六進(jìn)制標(biāo)準(zhǔn)文件格式,是由編譯器轉(zhuǎn)換而成的一種用于下載到處理器里面的ASCII文本文件。
1.解釋維基百科解釋https://en.wikipedia.org/wiki/Intel_HEXIntel HEX?is a file format that conveys binary information in ASCII text form. It is commonly used for programming microcontrollers, EPROMs, and other types of?programmable logic devices. In a typical application, a compiler or assembler converts a program's source code (such as in 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 a ROM, or is transferred to the target system for loading and?execution.
Keil官網(wǎng)解釋https://www.keil.com/support/docs/1584/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.
2.格式hex行格式::BBAAAATT 【D···D】CC
其中::?代表行開始,固定為冒號:
BB代表Bytes,數(shù)據(jù)長度AAAA代表Address,地址TT代表Type,數(shù)據(jù)類型(標(biāo)識)D···D代表Date,數(shù)據(jù)
CC代表CheckSum,校驗(yàn)和
說明:BB數(shù)據(jù)長度,也就是D···D這個字段的數(shù)據(jù)長度;
AAAA地址,起始地址、偏移地址,根據(jù)數(shù)據(jù)類型(TT)有關(guān);
TT數(shù)據(jù)類型(標(biāo)識):
- 00:數(shù)據(jù)標(biāo)識
- 01:文件結(jié)束標(biāo)識
- 02:擴(kuò)展段地址
- 04:線性地址
- 05:線性開始地址
CC校驗(yàn)和計(jì)算公式:
CheckSum = 0x100 - (Sum