A software upgrade method based on the IIC protocol

Through the software upgrade method based on the IIC protocol, the problem of inconvenience in upgrading low-end chips is solved, a convenient and reliable upgrade process is achieved, ensuring that the basic chip can be successfully upgraded, and a fault tolerance mechanism is provided to deal with failures.

CN118689515BActive Publication Date: 2024-11-15SHENZHEN C-DATA TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202411170054.2
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-08-26
Publication Date
2024-11-15
Estimated Expiration
2044-08-26

AI Technical Summary

Technical Problem

Low-end chips lack convenient upgrade methods when upgrading software, and the assembled equipment update program needs to be disassembled, which is very inconvenient.

Method used

Using the software upgrade method based on the IIC protocol, the bin file is sent to the host through the PC. The host verifies the file and divides it into flash packets, communicates with the slave according to the defined protocol to ensure the correctness and reliability of the upgrade process. , add complete package structure to process data packets, and provide fault tolerance mechanisms to achieve flexible upgrades.

Benefits of technology

It realizes convenient software upgrades for low-end chips, reduces the need for equipment disassembly, improves the reliability and flexibility of upgrades, ensures that the basic chips can successfully handle upgrades, and provides a fault tolerance mechanism to deal with failures.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118689515B_ABST
    Figure CN118689515B_ABST
Patent Text Reader

Abstract

The invention discloses a software upgrade method based on IIC protocol, comprising the following steps: S1: PC adds 64-byte version information to the slave software to be upgraded and converts it into bin file format, and then sends the bin file to the host through the network port; S2: the host calculates how many flash packages the actual software data in the bin file needs to be divided into, and forms an information package with the total number of divided flash packages and the 64-byte version information; S3: the host sends an upgrade command to the slave, and when the host receives a response returned by the slave, it sends an information package to the slave; S4: the host sends a flash package to the slave; S5: after the host sends all flash packages, the slave performs CRC check, and if the check passes and successfully jumps back to the app, it is considered that the upgrade is successful. The invention does not need to construct a communication method separately, and can update the slave program according to a defined protocol, and is easy to use.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of single chip microcomputers, and in particular to a software upgrading method based on an IIC protocol. Background Art

[0002] Bootloader, also known as boot loader, is the first piece of software code that runs after the system is powered on. It can realize two functions: booting the user program and self-updating the firmware. Among them, the firmware self-update needs to provide an additional data transmission medium to the chip so that the chip can write the received machine code into its own Flash. Common communications include serial ports, networks, etc. This is no problem for some highly functional chips, but for low-end chips, there may not be so many functions, and there are fewer opportunities to upgrade; at the same time, if the device has been assembled and needs to be updated, the device must be disassembled, which is very inconvenient. Summary of the invention

[0003] The purpose of the present invention is to provide a software upgrade method based on the IIC protocol to overcome the problem that low-end chips are inconvenient to upgrade.

[0004] To achieve the above objectives, the following technical solutions are adopted:

[0005] A software upgrade method based on the IIC protocol comprises the following steps:

[0006] S1: The PC adds 64 bytes of version information to the slave software to be upgraded and converts it into a bin file format, and then sends the bin file to the host through the network port, wherein the bin file includes encryption information, version number, version information, length, and CRC information;

[0007] S2: The host performs information verification on the received bin file, and calculates how many flash packages the actual software data in the bin file needs to be divided into, and combines the total number of divided flash packages and 64 bytes of version information into an information package, where each flash package is 512 bytes in size, and the information verification includes CRC information verification, length verification, and encryption information verification;

[0008] S3: After the bin file information is verified to be correct, the host sends an upgrade command to the slave. When the host receives a response from the slave, it sends an information packet to the slave.

[0009] S4: The host queries the slave status. After receiving the correct reply packet from the slave, the host sends a flash packet to the slave.

[0010] S5: After the host sends all flash packets, the slave performs a CRC check. If the check passes and the slave successfully jumps back to the app, the upgrade is considered successful.

[0011] Furthermore, the information packet size in S2 is 66 bytes, of which 0~1 bytes are the number of packets, 2~6 bytes are the upgrade key, 14~17 bytes are the upgrade version number, 58~61 bytes are the CRC information of the flash packet, 62~65 bytes are the length of the flash packet, and the remaining bytes are reserved or other keys are added as needed.

[0012] Furthermore, in S3, after the host receives the response from the slave, it will query the value of register address 0 to confirm whether the slave has entered the upgrade process. When the host confirms that the slave has entered the upgrade process, it will send an information packet to the slave. Otherwise, the host will resend the upgrade command to the slave.

[0013] Furthermore, in S3, the host sends an information packet to the slave starting from register address 2 to register address 6, with a maximum of 16 bytes sent to each register address; at the same time, after sending the information packet, the host sends a 5-byte completion packet to the slave through register address 1 to notify the slave that the information packet has been sent; the slave will verify whether the encryption information, the size of the information packet, the address of the information packet and the length of the information packet are correct.

[0014] Furthermore, in S4, the host determines the slave state by querying the value of register address 1 after delaying for a predetermined first time value.

[0015] Furthermore, the first time value is 60ms.

[0016] Furthermore, in S4, the specific steps of the host sending the flash package to the slave are as follows:

[0017] S41: The host sends a flash packet to the slave starting from register address 2 to register address 33, with a maximum of 16 bytes sent per register address.

[0018] S42: After the host sends a flash packet, the host sends a completion packet of 5 bytes to the slave through register address 1 to notify the slave that the flash packet is sent.

[0019] S43: The slave checks the length of the flash packet and the address of the flash packet. After the verification passes, the data in the flash packet is written into the Flash memory of the slave.

[0020] S44: After a delay of a predetermined second time value, the host queries the status of the slave, and after receiving a reply from the slave that the flash packet is correct, repeats steps S41 to S44 until the host sends all flash packets to the slave.

[0021] Furthermore, in S44, the second time value is 60ms; in S44, the host determines the slave state by querying the value of register address 1.

[0022] By adopting the above scheme, the beneficial effects of the present invention are:

[0023] 1) There is a common IIC communication method between the host and the slave. There is no need to build another communication method. The slave program can be updated according to the defined protocol, which is easy to use;

[0024] 2) Add the structure of the completion packet so that both the host and the slave have enough time to process the received data packets. The slave receives the data packets using an interrupt processing mechanism. Before receiving the completion packet, the slave can concentrate on receiving the packets to reduce errors. Finally, the host will delay the processing time according to the time required for the slave processing. This flexible and free time determination allows basic chips to achieve upgraded processing.

[0025] 3) Equipped with a fault-tolerant mechanism, the upgrade can be resent when the upgrade fails. BRIEF DESCRIPTION OF THE DRAWINGS

[0026] Figure 1 It is a principle block diagram of the present invention;

[0027] Figure 2 It is a flow chart of the present invention;

[0028] Figure 3 A flowchart of the host operation of the present invention;

[0029] Figure 4 Flowchart of the slave update program of the present invention. DETAILED DESCRIPTION

[0030] The present invention is described in detail below in conjunction with the accompanying drawings and specific embodiments.

[0031] Reference Figures 1 to 4 As shown, the present invention provides a software upgrade method based on the IIC protocol, comprising the following steps:

[0032] S1: The PC adds 64 bytes of version information to the slave software to be upgraded and converts it into a bin file format, and then sends the bin file to the host through the network port, wherein the bin file includes encryption information, version number, version information, length, and CRC information.

[0033] In this step, the host first communicates with the slave to ensure that there is no problem with the hardware link. The PC and the host are connected via a network cable (using the TFTP protocol), and the host and the slave are connected via the IIC protocol. Subsequently, the PC adds 64 bytes of version information to the slave software to be upgraded and converts it into a bin file format, which mainly includes encryption information, version number, version information, length, and CRC information. Finally, the PC sends this bin file to the host via the network cable.

[0034] S2: The host performs information verification on the received bin file, and calculates how many flash packages the actual software data in the bin file needs to be divided into, and combines the total number of divided flash packages and 64 bytes of version information into an information package, where each flash package is 512 bytes in size, and the information verification includes CRC information verification, length verification, and encryption information verification.

[0035] In this step, the host verifies the CRC, length, and encryption information of the received bin file. The upgrade can only be performed if the verification is correct. The host also calculates how many 512 bytes of actual software data in the bin file need to be sent to the slave. Each 512 bytes is a flash package and is marked with two bytes, which are marked as an information package together with the 64-byte version information.

[0036] The purpose of the information package is to encrypt and prevent malicious upgrades. Its size is 66 bytes, of which:

[0037] 0~1 byte is the number of packets. The specific number of bytes for the number of packets can be determined according to the size of your own flash;

[0038] Bytes 2 to 6 are the upgrade key. The slave will receive the message from the host only when it detects that the key is consistent with the program setting, which effectively reduces random upgrades.

[0039] Bytes 14 to 17 are the upgrade version number, which is used to detect whether the version number of the slave is consistent with that of the master, so as to detect whether the upgrade is successful;

[0040] Bytes 58 to 61 are the CRC information of the flash packet;

[0041] Bytes 62 to 65 are the length of the flash packet, and the remaining bytes are reserved or other keys are added as needed.

[0042] At the same time, in the present invention, the information packet is sent first, and then the flash packet is sent, wherein:

[0043] The read-only status of register address 0 is used to confirm the current status of the slave. If the slave is not in the upgrade status, it cannot send packets.

[0044] Register address 1 reads and writes the status. The read status is used to query the status of the slave receiving the packet, and the write status tells the slave which packet has been sent, and the slave can process which packet it has received.

[0045] Register address 2 starts sending the contents of the packet. For example, if a packet contains 512 bytes and one address sends 16 bytes, it needs to be sent 32 times.

[0046] When the information packet is verified to be correct, the host sends the contents of the flash packet, and the slave can receive the flash packet and write it to the memory. This is how many packets the flash should be divided into to send to the slave. For example, if the flash is 12k and one packet is 512 bytes, then 24 packets need to be sent. After the reception is completed and the CRC is verified, the slave successfully jumps to the app and successfully replies to the software version number query of the host.

[0047] Specifically, S3: after the bin file information is verified to be correct, the host sends an upgrade command to the slave, and when the host receives a response returned by the slave, it sends an information packet to the slave.

[0048] In S3, after the host receives the response from the slave, it will query the value of register address 0 to confirm whether the slave has entered the upgrade process. When the host confirms that the slave has entered the upgrade process, it will send an information packet to the slave. Otherwise, the host will resend the upgrade command to the slave.

[0049] In S3, the host sends information packets to the slave starting from register address 2 to register address 6, with each register address sending only 16 bytes at most; at the same time, after sending the information packet, the host sends a 5-byte completion packet to the slave through register address 1 to notify the slave that the information packet has been sent; the slave will verify whether the encrypted information, the size of the information packet, the address of the information packet and the length of the information packet are correct.

[0050] The host will send an upgrade command to the slave, and the host will confirm whether the slave has entered the upgrade process by querying the value status of register address 0. Figure 3 As shown in the figure, after the host receives the response from the slave, it delays 3s to send a command to query whether the slave has entered the boot upgrade mode. The host will confirm whether the received reply is 0X55 (the preset return value or status code). If so, the host will send an information packet to the slave, otherwise it will resend the upgrade command. When the number of retransmissions exceeds three times, it means that the upgrade has failed.

[0051] When the host sends a packet to the slave, it starts sending the content from register address 2. One address can only send 16 bytes at most. A 66-byte packet requires 5 addresses, from register address 2 to register address 6. For details, please refer to Figure 3As shown in step 1 in , after the host sends the information packet, it sends a 5-byte completion packet through register address 1 to notify the slave that the 0th packet has been sent and the length is 66 bytes, so as to notify the slave that it can process the received data; the slave will check whether the encryption information, flash size, packet address and packet length are reasonable.

[0052] S4: The host queries the slave status. After receiving the correct reply packet from the slave, the host sends a flash packet to the slave.

[0053] In S4, the host determines the slave state by querying the value of register address 1 after delaying for a predetermined first time value.

[0054] The first time value is 60ms.

[0055] In S4, the specific steps of the host sending the flash package to the slave are as follows:

[0056] S41: The host sends a flash packet to the slave starting from register address 2 to register address 33, with a maximum of 16 bytes sent per register address.

[0057] S42: After the host sends a flash packet, the host sends a completion packet of 5 bytes to the slave through register address 1 to notify the slave that the flash packet is sent.

[0058] S43: The slave checks the length of the flash packet and the address of the flash packet. After the verification passes, the data in the flash packet is written into the Flash memory of the slave.

[0059] S44: After a delay of a predetermined second time value, the host queries the status of the slave, and after receiving a reply from the slave that the flash packet is correct, repeats steps S41 to S44 until the host sends all flash packets to the slave.

[0060] In the S44, the second time value is 60ms; in the S44, the host determines the slave state by querying the value of register address 1.

[0061] The master will query the slave status after a preset delay (60ms). The status integrity is as follows: Figure 3 As shown in step 2 of the above, I will not repeat it here; after the host receives the correct reply packet from the slave, the host can send a flash packet, starting from register address 2, sending 16 bytes per address, and a total of up to 512 bytes. The specific content is as follows Figure 3As shown in step 3 in the figure; after sending the first flash packet, the host sends a 5-byte completion packet through register address 1 to notify the slave that the first packet has been sent and the length is 512 bytes. This notifies the slave that it can process the received data, and the slave will check the length and address of the packet. After the check passes, it will be written to the flash. The host queries the slave status after a predetermined delay (the second time value). The status integrity interpretation is as follows Figure 3 Step 4 in the above will not be repeated here. Finally, after the host receives the reply from the slave that the first flash packet is correct, the host repeats the process of sending the first flash packet until all flash packets are sent to the slave.

[0062] S5: After the host sends all flash packets, the slave performs a CRC check. If the check passes and it successfully jumps back to the app, the upgrade is considered successful. After the host sends the last completion packet, the slave performs a CRC check. When the CRC check is consistent with the CRC in the information packet and it successfully jumps to the app, the upgrade is successful. In addition, the host can query the value of register address 0. If the slave responds with a non-upgrade mark, it will continue to query the software version number. If the queried version number is consistent with the information packet mark, the upgrade is successful.

[0063] In addition, the process of slave update includes:

[0064] Receive the host upgrade command and enter the upgrade mode;

[0065] The slave determines whether the information packet is received and whether the information is correct. Only when the information packet is correct will it receive the flash packet. Whether each flash packet can be processed depends on whether the slave receives the completion packet. Only when the slave receives the completion packet can it know which flash packet the current packet is, where it should be written to in the slave memory, and how long it should be written.

[0066] The slave determines whether the flash packet is normal based on whether the length of the received flash packet is the same as the length of the completion packet, and can also add a CRC check on the flash packet;

[0067] After the slave receives the last flash package and writes it into the memory, it will perform a CRC check. Only if the CRC check is consistent with the CRC of the information and it can successfully jump back to the app, the upgrade program is considered successful, otherwise the upgrade is considered failed.

[0068] The above are only preferred embodiments of the present invention and are not intended to limit the present invention. Any modifications, equivalent substitutions and improvements made within the spirit and principles of the present invention should be included in the protection scope of the present invention.

Claims

1. A software upgrade method based on the IIC protocol, characterized in that: The steps include: S1: The PC adds 64 bytes of version information to the slave software to be upgraded and converts it into a bin file format, and then sends the bin file to the host through the network port, wherein the bin file includes encryption information, version number, version information, length, and CRC information; S2: The host performs information verification on the received bin file, and calculates how many flash packages the actual software data in the bin file needs to be divided into, and combines the total number of divided flash packages and 64 bytes of version information into an information package, where each flash package is 512 bytes in size, and the information verification includes CRC information verification, length verification, and encryption information verification; S3: After the bin file information is verified to be correct, the host sends an upgrade command to the slave. When the host receives a response from the slave, it sends an information packet to the slave. S4: The host queries the slave status. After receiving the correct reply packet from the slave, the host sends a flash packet to the slave. S5: After the host sends all flash packets, the slave performs CRC check. If the check passes and the slave successfully jumps back to the app, the upgrade is considered successful. The information packet size in S2 is 66 bytes, of which 0-1 bytes are the number of packets, 2-6 bytes are the upgrade key, 14-17 bytes are the upgrade version number, 58-61 bytes are the CRC information of the flash packet, 62-65 bytes are the length of the flash packet, and the remaining bytes are reserved or other keys are added as needed; In S3, after the host receives the response from the slave, it will query the value of register address 0 to confirm whether the slave has entered the upgrade process. When the host confirms that the slave has entered the upgrade process, it will send an information packet to the slave. Otherwise, the host will resend the upgrade command to the slave. In S3, the host sends information packets to the slave starting from register address 2 to register address 6, in a manner that each register address sends only 16 bytes at most; at the same time, after sending the information packet, the host sends a completion packet of 5 bytes to the slave through register address 1 to notify the slave that the information packet has been sent; the slave will verify whether the encrypted information, the size of the information packet, the address of the information packet and the length of the information packet are correct; In S4, the host determines the slave state by querying the value of register address 1 after delaying a predetermined first time value; In S4, the specific steps of the host sending the flash package to the slave are as follows: S41: The host sends a flash packet to the slave starting from register address 2 to register address 33, with a maximum of 16 bytes sent per register address. S42: After the host sends a flash packet, the host sends a completion packet of 5 bytes to the slave through register address 1 to notify the slave that the flash packet is sent successfully; S43: The slave checks the length of the flash packet and the address of the flash packet. After the verification passes, the data in the flash packet is written into the Flash memory of the slave. S44: After a delay of a predetermined second time value, the host queries the status of the slave, and after receiving a reply from the slave that the flash packet is correct, repeats steps S41 to S44 until the host sends all flash packets to the slave.

2. The software upgrade method based on the IIC protocol according to claim 1, characterized in that: The first time value is 60ms.

3. The software upgrade method based on the IIC protocol according to claim 1, characterized in that: In the S44, the second time value is 60ms; in the S44, the host determines the slave state by querying the value of register address 1.