A method of passing through I2C updating apparatus firmware
Technical field
The present invention relates to embedded device design fields, and the invention discloses one kind to pass through I2C updating apparatus firmware
Method.
Background technique
IIC, also known as I2C, both Inter-Integrated Circuit, Integration Bus circuit, this bus type be by
Philips Semiconductor Co., Ltd. designs in 20th century early eighties.The bus two lines composition: data line (SDA) and when
Clock line (SCL) can connect multiple IIC from equipment on an iic bus, these come area from address using different from equipment
Point.
In system design, there are a kind of single main control device and multiple knots from equipment or module (hereinafter referred to as from equipment)
Structure.Wherein main control device is feature-rich, supports a variety of way to manages;And it is more single from functions of the equipments, using relative inexpensiveness
Common single-chip microcontroller can realize its function, and these single-chip microcontrollers usually all support IIC interface.
However, the system resource that the chip of relative inexpensiveness provides is often limited, more resources can not be usually provided
Upgrading for equipment;And most of device program operates in Rom, also can not directly upgrade to equipment.
CN200510002062.7 discloses a kind of SCM online loading and updating method and system, for as from
The single-chip microcontroller of CPU work carries out on-line loaded upgrading, this method comprises: by the inside of the BOOT software write-in single-chip microcontroller of single-chip microcontroller
Program storage area, and power down outside piece is written into its application program and is kept in medium;When single-chip microcontroller needs to upgrade, by host CPU control
Single-chip microcontroller work processed BOOT application state in operation piece, and power down outside its piece is written by BOOT software in loading code and is kept
In medium;Single-chip microcontroller is resetted by host CPU, and controls the Application Status outside operation piece that works after it is restarted, load is completed and rises
Grade process.Present system increases control of the host CPU to single-chip microcontroller operating mode on the basis of being based on existing master and slave cpu system
Circuit processed, and the outer power down of piece of storage singlechip application programs keep medium.Using the present invention, can simply and easily realize
On-line loaded upgrading to single-chip microcontroller, is convenient for system maintenance.But this method needs a plurality of communication bus or control line, simultaneously
Outer power down is needed to keep medium, design is relative complex, and design cost is relatively high;Bus and control line are more, consumption master
The resource of CPU is more, is not suitable for the design of list CPU connection multiple single chip microcomputer.
Summary of the invention
For the above problem in the prior art for being difficult to from equipment to upgrade, the invention discloses one kind to pass through I2C upgrading
The method of equipment firmware.
Technical scheme is as follows:
The invention discloses a kind of methods by I2C updating apparatus firmware, specifically include following step: step
One, be connected to N number of on main control device from equipment by an I2C bus, each from the system of equipment include bootstrap area,
System facilities area and system upgrade program area;Step 2: bootstrap selection needs system to be loaded when starting from equipment
System function program, when loading successfully, system facilities starting;When loading failure, main control device upgrading is waited;Step
Three, main control device is got after the instruction that equipment needs to upgrade, and downloads the firmware from equipment from the information of equipment according to this
And upgrade command is sent to this from equipment, state is switched to upgrade mode after receiving upgrade command from equipment, was being upgraded
Cheng Zhong is state machine from plant maintenance, and for record currently from the upgrade status of equipment, main control device reads the upgrading shape from equipment
State;Step 4: firmware information is handed down to from equipment by main control device after being switched to upgrade mode from equipment, received from equipment
System upgrade program is written into specified position after firmware information;Step 5: when having been executed from all write instructions of equipment
Cheng Hou, main control device issue instruction of restarting, restart from equipment, and bootstrap selection needs system facilities to be loaded.Pass through
Main control device and I2C bus are realized to be upgraded from the automatic on-line of equipment.
Further, above-mentioned main control device, which is got from equipment, needs the instruction upgraded to specifically include: adding when from equipment
When carrying failure, a flag bit is written from equipment, main control device is by reading whether the judgement of this flag bit should need from equipment
Upgrading.Quick obtaining is to the information for needing to upgrade from equipment, to improve upgrading efficiency.
Further, above-mentioned main control device, which is got from equipment, needs the instruction upgraded to specifically include: main control device is logical
It crosses I2C bus, reads or the operating status and parameter of HRP-configured slave device, judged by operating status from equipment and parameter from setting
It is standby whether to need to upgrade.Quick obtaining is to the information for needing to upgrade from equipment, to improve upgrading efficiency.
Further, the above-mentioned system from equipment can also include function program backup area, after function program is impaired,
The backup of the program is got from function program backup area.To realize fast quick-recovery.
Further, above-mentioned main control device issue data or instruction when, header information include order number and
The converse value of order number guarantees the correctness of Type.
Further, above-mentioned main control device issue data or instruction when, trailer information be data check and.It is logical
Cross the correctness that check information guarantees all data.
Further, above-mentioned main control device is when issuing firmware, first by firmware fragment, and sends firmware fragment letter
Breath records and waits the data of firmware to be received after receiving firmware burst information from equipment;Then main control device successively issues firmware
Burst information, after the burst information that firmware is received from equipment, record current information and wait the data of fragment before list to be received, directly
Completion is sent and received to a last fragment data.First by firmware fragment, and send overall information to from equipment, convenient for from
Equipment understands the number of firmware fragment, and whether all pieces the contents such as all send.
Further, the above method further includes main control device from host computer downloading from the firmware of equipment, when downloading successfully
Afterwards, it is verified, after verifying successfully, main control device is issued to be instructed from device upgrade pattern switching.
Further, it is transmitted in transmission process using network bytes sequence.
By using above technical solution, the beneficial effect comprise that real by main control device and I2C bus
Now from the online upgrading of equipment, simple and convenient from the escalation process of equipment, whole process is realized automatically, is not needed any artificial
Participate in, it is convenient for users to use, realize system it is automatic detect and automatic online upgrading.The present invention does not need external
Storage medium, at the same it is only necessary to the connection of iic bus it is multiple from equipment, connection method is simple, not only simplify design process,
Also save design cost.
Detailed description of the invention
Fig. 1 designs a model for general frame.
Fig. 2 is from device systems structure.
Fig. 3 is data and instruction format.
Fig. 4 is master and slave device upgrade state diagram.
Fig. 5 is master control equipment end operational flowchart.
Fig. 6 is to upgrade flow chart from equipment end.
Specific embodiment
In order to make the objectives, technical solutions, and advantages of the present invention clearer, with reference to the accompanying drawings and embodiments, right
The present invention is described in more detail.It should be appreciated that the specific embodiments described herein are merely illustrative of the present invention,
It is not intended to limit the present invention.
The invention discloses a kind of methods by I2C updating apparatus firmware, specifically include following step: step
One, be connected to N number of on main control device from equipment by an I2C bus, each from the system of equipment include bootstrap area,
System facilities area and system upgrade program area;Step 2: bootstrap selection needs system to be loaded when starting from equipment
System function program, when loading successfully, system facilities starting;When loading failure, main control device upgrading is waited;Step
Three, main control device is got after the instruction that equipment needs to upgrade, and downloads the firmware from equipment from the information of equipment according to this
And upgrade command is sent to this from equipment, state is switched to upgrade mode after receiving upgrade command from equipment, was being upgraded
Cheng Zhong is state machine from plant maintenance, and for record currently from the upgrade status of equipment, main control device reads the upgrading shape from equipment
State;Step 4: firmware information is handed down to from equipment by main control device after being switched to upgrade mode from equipment, received from equipment
System upgrade program is written into specified position after firmware information;Step 5: when having been executed from all write instructions of equipment
Cheng Hou, main control device issue instruction of restarting, restart from equipment, and bootstrap selection needs system facilities to be loaded.Pass through
Main control device and I2C bus are realized to be upgraded from the automatic on-line of equipment.
Further, above-mentioned main control device, which is got from equipment, needs the instruction upgraded to specifically include: adding when from equipment
When carrying failure, a flag bit is written from equipment, main control device is by reading whether the judgement of this flag bit should need from equipment
Upgrading.For example it is to need to upgrade that flag bit, which is 1, flag bit is 0 not need to upgrade, and flag bit is 0 when initial.Quickly obtain
The information for needing to upgrade from equipment is got, to improve upgrading efficiency.
Further, above-mentioned main control device, which is got from equipment, needs the instruction upgraded to specifically include: main control device is logical
It crosses I2C bus, reads or the operating status and parameter of HRP-configured slave device, judged by operating status from equipment and parameter from setting
It is standby whether to need to upgrade.When operating normally from equipment, main control device can be by I2C bus, the fortune of reading or HRP-configured slave device
Row state and parameter.Quick obtaining is to the information for needing to upgrade from equipment, to improve upgrading efficiency.
Further, it is above-mentioned from the system of equipment further include function program backup area, after function program is impaired, from function
Energy program backup area gets the backup of the program.To realize fast quick-recovery.According to the characteristic of IIC, embedded device is set
Following scheme can be used in meter: as shown in Figure 1, connecing multiple from equipment on an iic bus of main control device, such design was both
The space for saving PCB layout, also facilitates main control device safely and effectively to manage from equipment.Set from the system of equipment be divided into load,
Update, tetra- parts app, app backup, as shown in Figure 2.Load is bootstrap, and load is according to rule selection load
App, if app load failure, load if load update program;Update is upgrade procedure;App is the normal function from equipment
It can program;App backup is the backup of app, and according to the resource distribution of system, app backup is optional.
Further, above-mentioned main control device issue data or instruction when, header information include order number and
The converse value of order number.From when device upgrade, main control device issues the format of data and instruction as shown in figure 3, wherein Type is
The number of instruction, ~ Type are the converse value of Type;Data_Len is the length of the data or instruction.Type and ~ Type mutually take
Instead, guarantee the correctness of Type.
Further, above-mentioned main control device issue data or instruction when, trailer information be data check and.It is logical
Cross the correctness that check information guarantees all data.
Further, above-mentioned main control device is when issuing firmware, first by firmware fragment, and sends firmware fragment letter
Breath records and waits the data of firmware to be received after receiving firmware burst information from equipment;Then main control device successively issues firmware
Burst information, after the burst information that firmware is received from equipment, record current information and wait the data of fragment before list to be received, directly
Completion is sent and received to a last fragment data.First by firmware fragment, and send overall information to from equipment, convenient for from
Equipment, which understands one, to be met together and sends out how many piece, the contents such as whether all pieces all send.Data in data format is firmware fragment
Data, length are optional;Rsev is reserved field, facilitates instruction extension;Seg_Num is the number of firmware fragment;Seg_Len is should
The data length that fragment transmits in total;Len in the file information format is firmware information total length;Magic in instruction format
For the special magic number of each instruction, the correctness of the instruction is confirmed by proofreading the Magic.All data or preceding four word of instruction
The header information format of section is identical, and wherein Type and ~ Type are mutually negated, and guarantees the correctness of Type;2, end byte is number
According to verification and, guarantee the correctness of all data in this way;Sampling network syllable sequence transmits in transmission process, to keep master control to set
It is standby consistent with the data byte sequence from equipment.Network bytes sequence is a kind of general data format provided in TCP/IP, with
CPU and operating system are unrelated, guarantee to be properly interpreted when transmitting data between different hosts.Using big end data pattern,
Data high byte is stored in low address.
Further, the above method further includes main control device from host computer downloading from the firmware of equipment, when downloading successfully
Afterwards, it is verified, after verifying successfully, main control device is issued to be instructed from device upgrade pattern switching.It downloads from host computer from equipment
Firmware, be further added by the program of verification, improve the safety of system.
The coefficient and parameter gone out given in the above embodiments, is available to those skilled in the art to realize or use
Invention, invention, which does not limit, only takes aforementioned disclosed numerical value, in the case where not departing from the thought of invention, the technology of this field
Personnel can make various modifications or adjustment to above-described embodiment, thus the protection scope invented is not by above-described embodiment institute
Limit, and should be the maximum magnitude for meeting the inventive features that claims are mentioned.