A kind of method by I2C updating apparatus firmware
Technical field
The present invention relates to embedded device design field, the invention discloses a kind of method by I2C updating apparatus firmware.
Background technology
IIC, also known as I2C, both Inter-IntegratedCircuit, Integration Bus circuit, this bus type by Philips Semiconductor Co., Ltd. 20th century early eighties design.This bus two line compositions: data line (SDA) and clock line (SCL), an iic bus can connect multiple IIC from equipment, and these are from different the distinguishing from address of equipment use.
In system, there is a kind of single main control equipment and multiple structure from equipment or module (being referred to as from equipment below).Wherein main control equipment feature richness, supports multiple way to manage; And more single from functions of the equipments, adopt the common single-chip microcomputer of relative inexpensiveness just can realize its function, and these single-chip microcomputers all support IIC interface usually.
But the system resource that the chip of relative inexpensiveness provides is often limited, more resource usually cannot be provided for the upgrading of equipment; And most device program operates in Rom, also cannot directly upgrade to equipment.
CN200510002062.7 discloses a kind of SCM online loading and updating method and system, for carrying out on-line loaded upgrading to as the single-chip microcomputer worked from CPU, the method comprises: by the internal processes memory block of the BOOT software of single-chip microcomputer write single-chip microcomputer, and keeps in medium by the outer power down of its application program write sheet; When single-chip microcomputer needs upgrading, be operated in by host CPU control single chip computer and run BOOT application state in sheet, and loading code is write in its sheet outer power down maintenance medium by BOOT software; To be resetted single-chip microcomputer by host CPU, and control to be operated in after it is restarted and run the outer Application Status of sheet, complete loading upgrading process.Present system, based on existing master and slave cpu system basis, adds the control circuit of host CPU to single-chip microcomputer mode of operation, and the outer power down of the sheet storing singlechip application programs keeps medium.Utilize the present invention, can realize simply and easily upgrading to the on-line loaded of single-chip microcomputer, be convenient to system maintenance.But the method needs many communication buss or control line, need outer power down to keep medium, design relative complex, and design cost is relatively high simultaneously; Bus and control line more, it is more to consume the resource of host CPU, is not suitable for the design that single CPU connects multiple single chip microcomputer.
Summary of the invention
For the problems referred to above being difficult to upgrade from equipment of the prior art, the invention discloses a kind of method by I2C updating apparatus firmware.
Technical scheme of the present invention is as follows:
The invention discloses a kind of method by I2C updating apparatus firmware, it specifically comprises the following steps: step one, is connected to main control equipment from equipment by an I2C bus by N number of, and each system from equipment comprises boot district, system facilities district and system upgrade program area; Step 2, when from device start, boot select need load system facilities, when loading successfully, system facilities startup; When loading unsuccessfully, wait for main control equipment upgrading; After step 3, main control equipment get and need the instruction of upgrading from equipment, download this from the firmware of equipment from the information of equipment send upgrade to this from equipment according to this, after equipment receives upgrade, state is switched to upgrade mode, in escalation process, be state machine from plant maintenance, record the current upgrade status from equipment, main control equipment reads the upgrade status from equipment; Step 4, after switching to upgrade mode from equipment, firmware information is handed down to from equipment by main control equipment, and after receiving firmware information from equipment, system upgrade program is write the position of specifying; Step 5, after complete from all write instructions of equipment, main control equipment issues instruction of restarting, restarts from equipment, and boot selects the system facilities needing to load.Realize upgrading from the automatic on-line of equipment by main control equipment and I2C bus.
Further, above-mentioned main control equipment gets needs the instruction of upgrading specifically to comprise from equipment: when loading unsuccessfully from equipment, write a zone bit from equipment, and main control equipment should from equipment the need of upgrading by reading the judgement of this zone bit.Quick obtaining to the information needing upgrading from equipment, thus improves upgrading efficiency.
Further, above-mentioned main control equipment gets needs the instruction of upgrading specifically to comprise from equipment: main control equipment is by I2C bus, read or the running status of HRP-configured slave device and parameter, by judging from equipment the need of upgrading from the running status of equipment and parameter.Quick obtaining to the information needing upgrading from equipment, thus improves upgrading efficiency.
Further, the above-mentioned system from equipment can also comprise function program backup area, after function program is impaired, gets the backup of this program from function program backup area.Thus realize fast quick-recovery.
Further, above-mentioned main control equipment is when issuing data or instruction, and its header information comprises the converse value of order number and order number, ensures the correctness of Type.
Further, above-mentioned main control equipment is when issuing data or instruction, and its trailer information is check sum.The correctness of all data is ensured by check information.
Further, above-mentioned main control equipment, when issuing firmware, first by firmware burst, and sends firmware burst information, after receiving firmware burst information, records and the data of wait-receiving mode firmware from equipment; Then main control equipment issues the burst information of firmware successively, and receive the burst information of firmware from equipment after, record current information the data of burst before wait-receiving mode list, to the last a fragment data sends and finishes receiving.First by firmware burst, and send overall information to from equipment, be convenient to the numbering understanding firmware burst from equipment, whether all sheets the content such as all send.
Further, said method also comprises main control equipment from host computer download from the firmware of equipment, and when downloading successfully, verify, after verification succeeds, main control equipment issues from device upgrade pattern switching command.
Further, in transmitting procedure, network bytes sequence is adopted to transmit.
By adopting above technical scheme, beneficial effect of the present invention comprises: realize the online upgrading from equipment by main control equipment and I2C bus, simple and convenient from the escalation process of equipment, whole process realizes automatically, without any need for artificial participation, convenient for users to use, achieve the automatic detection of system and automatic online upgrading.The present invention does not need external storage medium, only needs an iic bus to connect multiple from equipment simultaneously, and method of attachment is simple, both simplifies design process, and also saves design cost.
Accompanying drawing explanation
Fig. 1 is that general frame designs a model.
Fig. 2 is from device systems structure.
Fig. 3 is data and order format.
Fig. 4 is master and slave device upgrade constitutional diagram.
Fig. 5 is main control equipment end operational flowchart.
Fig. 6 is from equipment end upgrading process flow diagram.
Embodiment
In order to make object of the present invention, technical scheme and advantage clearly understand, below in conjunction with drawings and Examples, the present invention is described in more detail.Should be appreciated that specific embodiment described herein only in order to explain the present invention, be not intended to limit the present invention.
The invention discloses a kind of method by I2C updating apparatus firmware, it specifically comprises the following steps: step one, is connected to main control equipment from equipment by an I2C bus by N number of, and each system from equipment comprises boot district, system facilities district and system upgrade program area; Step 2, when from device start, boot select need load system facilities, when loading successfully, system facilities startup; When loading unsuccessfully, wait for main control equipment upgrading; After step 3, main control equipment get and need the instruction of upgrading from equipment, download this from the firmware of equipment from the information of equipment send upgrade to this from equipment according to this, after equipment receives upgrade, state is switched to upgrade mode, in escalation process, be state machine from plant maintenance, record the current upgrade status from equipment, main control equipment reads the upgrade status from equipment; Step 4, after switching to upgrade mode from equipment, firmware information is handed down to from equipment by main control equipment, and after receiving firmware information from equipment, system upgrade program is write the position of specifying; Step 5, after complete from all write instructions of equipment, main control equipment issues instruction of restarting, restarts from equipment, and boot selects the system facilities needing to load.Realize upgrading from the automatic on-line of equipment by main control equipment and I2C bus.
Further, above-mentioned main control equipment gets needs the instruction of upgrading specifically to comprise from equipment: when loading unsuccessfully from equipment, write a zone bit from equipment, and main control equipment should from equipment the need of upgrading by reading the judgement of this zone bit.Such as zone bit is 1 is needs upgradings, and zone bit is 0 is do not need upgrading, and time initial, zone bit is 0.Quick obtaining to the information needing upgrading from equipment, thus improves upgrading efficiency.
Further, above-mentioned main control equipment gets needs the instruction of upgrading specifically to comprise from equipment: main control equipment is by I2C bus, read or the running status of HRP-configured slave device and parameter, by judging from equipment the need of upgrading from the running status of equipment and parameter.When normally running from equipment, main control equipment can pass through I2C bus, the running status of reading or HRP-configured slave device and parameter.Quick obtaining to the information needing upgrading from equipment, thus improves upgrading efficiency.
Further, the above-mentioned system from equipment also comprises function program backup area, after function program is impaired, gets the backup of this program from function program backup area.Thus realize fast quick-recovery.According to the characteristic of IIC, following scheme can be adopted: as shown in Figure 1 in the design of embedded device, an iic bus of main control equipment connects the space that PCB layout had both been saved in multiple from equipment, such designs, also facilitates main control equipment to manage safely and effectively from equipment.Establish from the system of equipment and be divided into load, update, app, appbackup tetra-parts, as shown in Figure 2.Load is boot, the app that load loads according to rules selection, if app loads unsuccessfully, load then loads update program; Update is ROMPaq; App is the normal function program from equipment; Appbackup is the backup of app, and according to the resource distribution of system, appbackup is optional.
Further, above-mentioned main control equipment is when issuing data or instruction, and its header information comprises the converse value of order number and order number.During from device upgrade, main control equipment issues the form of data and instruction as shown in Figure 3, and wherein Type is the numbering of instruction, and ~ Type is the converse value of Type; Data_Len is the length of these data or instruction.Type and the ~ mutual negate of Type, ensure the correctness of Type.
Further, above-mentioned main control equipment is when issuing data or instruction, and its trailer information is check sum.The correctness of all data is ensured by check information.
Further, above-mentioned main control equipment, when issuing firmware, first by firmware burst, and sends firmware burst information, after receiving firmware burst information, records and the data of wait-receiving mode firmware from equipment; Then main control equipment issues the burst information of firmware successively, and receive the burst information of firmware from equipment after, record current information the data of burst before wait-receiving mode list, to the last a fragment data sends and finishes receiving.First by firmware burst, and send overall information to from equipment, be convenient to understand one from equipment and meet together and send out how many slice, whether all sheets the content such as all send.Data in data layout is firmware fragment data, length optional; Rsev is reserved field, facilitates instruction extension; Seg_Num is the numbering of firmware burst; Seg_Len is the data length that this burst transmits altogether; Len in fileinfo form is firmware information total length; Magic in order format is the special magic number of each instruction, confirms the correctness of this instruction by proofreading this Magic.Before all data or instruction, the header information form of nybble is identical, and wherein Type and the ~ mutual negate of Type, ensure the correctness of Type; 2, end byte is check sum, ensures the correctness of all data like this; Sampling network syllable sequence transmission in transmitting procedure, to keep main control equipment consistent with the data byte sequence from equipment.Network bytes sequence is a kind of general data layout provided in TCP/IP, has nothing to do, ensure correctly to be explained when transmitting data between different main frame with CPU and operating system.Use large end data pattern, data high byte is kept in low address.
Further, said method also comprises main control equipment from host computer download from the firmware of equipment, and when downloading successfully, verify, after verification succeeds, main control equipment issues from device upgrade pattern switching command.Download the firmware from equipment from host computer, then increase the program of verification, improve the security of system.
Coefficient given in the above embodiments and parameter; be available to those skilled in the art to realize or use invention; invention does not limit only gets aforementioned disclosed numerical value; when not departing from the thought of invention; those skilled in the art can make various modifications or adjustment to above-described embodiment; thus the protection domain invented not limit by above-described embodiment, and should be the maximum magnitude meeting the inventive features that claims are mentioned.