Program upgrading method based on BootLoader
By using CRC verification code to verify handshake, erase and file information index instructions in the BootLoader protocol, the problem of insufficient anti-interference during file transfer is solved, and higher transmission stability and success rate are achieved.
Patent Information
- Application Number
- CN202411399418.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-10-09
- Publication Date
- 2024-12-27
- Estimated Expiration
- Not applicable · inactive patent
AI Technical Summary
The existing BootLoader protocol is insufficiently anti-interference during file transfer, and is susceptible to external interference and data transmission errors, resulting in transmission failure.
CRC verification code is used to verify in handshake, erase and file information index instructions to ensure the correctness of each step of operation, and feedback the host through the reply instruction to improve the reliability and stability of transmission.
It improves the anti-interference of data transmission in complex environments, ensures the stability and success rate of file transfer processes, and prevents illegal instruction execution caused by transmission errors or malicious attacks.
Smart Images

Figure CN119201177A_ABST
Abstract
Description
Technical Field
[0001] The invention belongs to the technical field of Internet applications, and in particular relates to a program upgrading method based on BootLoader. Background Art
[0002] Conventional BootLoader protocols use the YModem protocol; although the YModem protocol is a very efficient file transfer protocol, the YModem protocol retransmission mechanism has a delay. The YModem protocol will initiate a retransmission when the data packet is lost or damaged. If the retransmission mechanism does not respond in time or has problems, data transmission may fail; as a serial communication protocol, the YModem protocol is susceptible to external interference, such as electromagnetic interference and noise, which may cause errors in data transmission; in addition, as a relatively simple protocol, the YModem protocol may not take into account some complex interference situations in its design, resulting in certain deficiencies in its anti-interference ability. Therefore, due to the delay of the retransmission mechanism and the characteristics of serial communication, the YModem protocol has low anti-interference ability in the process of transferring files using the YModem protocol. Summary of the invention
[0003] The invention provides a BootLoader-based program upgrade method, aiming to solve the problem of insufficient anti-interference performance in an upgrade file transmission process in the prior art.
[0004] In order to solve the above technical problems, the technical solution adopted by the present invention is: The present invention provides a BootLoader-based program upgrade method, the steps comprising: S100, receiving a handshake instruction sent by a host, wherein the handshake instruction includes a CRC check code; S110, verifying the CRC check code in the handshake instruction, and sending a response instruction to the host, wherein the response instruction includes a CRC check code, and verifying the response instruction; S120, determining whether to execute step S200 according to the first response instruction verification rule; S200, receiving an erase instruction sent by the host, wherein the erase instruction includes a CRC check code; S210, verifying the CRC check code in the erase instruction, and sending a response instruction to the host, wherein the response instruction includes a CRC check code, and verifying the response instruction; S220, determining whether to execute step S300 according to the second response instruction verification rule; S300, receiving file information and a file information index sent by the host, wherein the file information index includes a CRC checksum; and the host writes the file information; S310, verifying the CRC check code in the file information index, and sending a response instruction to the host, wherein the response instruction includes the CRC check code, and verifying the response instruction; If the response instruction indicates that the verification fails, the process returns to step S200; If the response instruction is a successful verification, the file information index and the file information are erased, and the process returns to step S100 to receive the next file information written by the host until the file information is written; the program upgrade is successful.
[0005] Further solution: In step S120, the first response instruction verification rule is: If the response instruction fails to be verified, the handshake instruction sent by the host is received again, and the CRC check code in the handshake instruction is verified. If the verification still fails after executing three times, the BootLoader is exited; If the response instruction indicates that the verification is successful, the process proceeds to step S200.
[0006] Further solution: In step S220, the second response instruction verification rule is: If the response instruction fails to be verified, the erase instruction sent by the host is received again, and the CRC check code in the erase instruction is verified. If the verification fails after three executions, the process returns to step S100; If the response instruction indicates that the verification is successful, the process proceeds to step S300 .
[0007] A further solution: the file information index also includes a write address; In the step S300, the host writes the file information according to the write address; In the step S310, if the response instruction is verified successfully, the file information index and the file information are erased, and the length of the write address is increased by the length of the file information.
[0008] Further solution: the formats of the handshake instruction, the erase instruction and the file information index are all device ID+command CMD+address ADDR+CRC check code; The length of the device ID is 1 byte, the length of the command CMD is 1 byte, the length of the address ADDR is 4 bytes, and the length of the CRC check code is 2 bytes.
[0009] Based on the above scheme, the formats of the handshake instruction, the erase instruction and the file information index are all device ID+command CMD+address ADDR+CRC check code. The CRC check code can help check whether an error occurs during command transmission and improve the reliability of the transmission process. In addition, the length of each part of the instruction is fixed, which is convenient for parsing the instruction.
[0010] A further solution: in the handshake instruction, the command CMD is 0×21; the address ADDR is 0×12345678;
[0011] In the erase instruction, the command CMD is 0×22; the address ADDR is the storage size of the receiving end;
[0012] In the file information index, the command CMD is 0×23; the address ADDR is the first address of the receiving end.
[0013] Based on the above scheme, the different commands CMD are helpful to identify and distinguish different instructions. The address ADDR in the handshake instruction, erase instruction and file information index can reduce the possibility of errors and avoid mistakes or confusion when transmitting address information. In addition, the address ADDR in the instruction also makes the meaning of the instruction clearer and more direct, without the need for additional instruction addresses, simplifying the operation process.
[0014] Further solution: the format of the response instruction sent to the host in step S110, the format of the response instruction sent to the host in step S210, and the format of the response instruction sent to the host in step S310 are all device ID+command CMD+execution status+CRC check code; Among them, the length of the device ID is 1 byte, the length of the command CMD is 1 byte, the length of the execution status is 4 bytes, and the length of the CRC check code is 2 bytes.
[0015] Based on the above scheme, the execution status in the response instruction can convey information about the execution of the instruction, helping the host to understand the execution status and perform corresponding error handling or subsequent operations; in addition, the response instruction uses a fixed-length field to reduce ambiguity and errors in communication and improve the reliability and stability of instruction transmission.
[0016] A further solution: in the response instruction sent to the host when checking the CRC check code in the handshake instruction, the command CMD is 0×21; In the response instruction sent to the host when checking the CRC check code in the erase instruction, the command CMD is 0×22; In the response instruction sent to the host when checking the CRC check code in the file information index, the command CMD is 0×23.
[0017] Based on the above solution, the different commands CMD in the response instruction are helpful to identify and distinguish the instruction type of the response instruction reply.
[0018] Further solution: the format of the response instruction includes the execution status; when verifying the response instruction, When the response instruction is verified successfully, the execution status in the response instruction sent to the host is 0×0000; When the response instruction fails to verify, the execution status in the response instruction sent to the host is 0×0001.
[0019] Based on the above solution, by using a specific execution status field in the response instruction, the verification result can be clearly conveyed to the host, so that the host can accurately understand the execution status of the operation.
[0020] A further solution: the device ID is 0×A0.
[0021] The beneficial effects of the present invention are: In the present invention, the handshake instructions, erase instructions and file information indexes received in sequence from the host all contain CRC check codes. By verifying the CRC check codes, it is checked whether errors occur in the handshake instructions, erase instructions and file information indexes during transmission, thereby improving the anti-interference performance of data transmission in complex environments. In addition, a response instruction is sent to the host based on the verification result, and the response instruction also contains a CRC check code. The response instruction ensures that each step of the operation is successfully completed, further improving the anti-interference performance and ensuring the stability of the receiving end during the upgrade or update process.
[0022] The CRC check code in each instruction ensures that only verified instructions will be executed, preventing the execution of illegal instructions due to transmission errors or malicious attacks, protecting instructions or files during the transmission process, and also improving the success rate of program upgrades. BRIEF DESCRIPTION OF THE DRAWINGS
[0023] In order to more clearly illustrate the technical solutions of the embodiments of the present invention, the drawings required for use in the embodiments are briefly introduced below. It should be understood that the following drawings only show certain embodiments of the present invention and therefore should not be regarded as limiting the scope. For ordinary technicians in this field, other relevant drawings can be obtained based on these drawings without paying creative work.
[0024] Figure 1It is a flowchart of a BootLoader-based program upgrade method of the present invention; Figure 2 This is a schematic diagram of the interface of FUV v1.42 in a specific case; Figure 3 This is a schematic diagram of the interface for selecting and opening the file to be updated in a specific case; Figure 4 This is a schematic diagram of the interface of the handshake command in a specific case; Figure 5 This is a schematic diagram of the interface of the erase command in a specific case; Figure 6 This is a schematic diagram of the interface for writing files to be updated in a specific case; Figure 7 This is a schematic diagram of the interface after the file to be updated is written in a specific case. DETAILED DESCRIPTION
[0025] The following will be combined with the accompanying drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. It should be understood that the specific embodiments described herein are only used to explain the present invention and are not used to limit the present invention. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative work belong to the protection scope of the present invention.
[0026] like Figure 1 As shown, this embodiment provides a BootLoader-based program upgrade method, the steps comprising: S100, receiving a handshake instruction sent by a host, wherein the handshake instruction includes a CRC check code; S110, verifying the CRC check code in the handshake instruction, and sending a response instruction to the host, wherein the response instruction includes a CRC check code, and verifying the response instruction; S120, determining whether to execute step S200 according to the first response instruction verification rule; Wherein, the first response instruction verification rule is: If the response instruction fails to verify, the handshake instruction sent by the host is received again, and the CRC check code in the handshake instruction is verified. If the verification fails after executing three times, the BootLoader is exited. It should be noted that the BootLoader is exited because the verification fails after executing three times, indicating that the program upgrade fails. If the response instruction is verified successfully, proceed to step S200; S200, receiving an erase instruction sent by the host, wherein the erase instruction includes a CRC check code; S210, verifying the CRC check code in the erase instruction, and sending a response instruction to the host, wherein the response instruction includes a CRC check code, and verifying the response instruction; S220, determining whether to execute step S300 according to the second response instruction verification rule; Among them, the second response instruction verification rule is: If the response instruction fails to be verified, the erase instruction sent by the host is received again, and the CRC check code in the erase instruction is verified. If the verification fails after three executions, the process returns to step S100; If the response instruction is verified successfully, proceed to step S300; S300, receiving file information and a file information index sent by the host, wherein the file information index includes a CRC checksum; and the host writes the file information; S310, verifying the CRC check code in the file information index, and sending a response instruction to the host, wherein the response instruction includes the CRC check code, and verifying the response instruction; If the response instruction indicates that the verification fails, the process returns to step S200; If the response instruction is a successful verification, the file information index and the file information are erased, and the process returns to step S100 to receive the next file information written by the host until the file information is written; the program upgrade is successful.
[0027] Based on the above solution, the file information index also includes a write address; In the step S300, the host writes the file information according to the write address; In the step S310, if the response instruction is verified successfully, the file information index and the file information are erased, and the length of the write address is increased by the length of the file information.
[0028] The BootLoader is a key software component used to boot an operating system or application in an embedded system or computer system. Its main task is to initialize the hardware and load the operating system kernel or application into the memory. The BootLoader runs when the system starts and provides the necessary support for the normal startup of the system.
[0029] The CRC check code is used to check whether errors occur during data transmission. It generates a CRC check value by executing a specific algorithm on the instruction. When the receiving end receives the instruction, it can use the same algorithm to recalculate the CRC check value and compare it with the received CRC check value to check whether the data has been tampered with or damaged during transmission.
[0030] It should be noted that the length of the file information may be 512 bytes. When the length of the file information is 512 bytes, in step S300, only 512 bytes of file information sent by the host can be received at one time. Considering that the total size of the file information may be greater than 512 bytes, it is necessary to receive 512 bytes of file information sent by the host multiple times until the file information is written.
[0031] In addition, after the program is successfully upgraded, a jump instruction sent by the host is received to exit the BootLoader.
[0032] A more specific example of the above solution is: The formats of the handshake instruction, the erase instruction and the file information index are all device ID+command CMD+address ADDR+CRC check code; The length of the device ID is 1 byte, the length of the command CMD is 1 byte, the length of the address ADDR is 4 bytes, and the length of the CRC check code is 2 bytes.
[0033] Specifically, the device ID is 0×A0.
[0034] In the handshake instruction, the command CMD is 0×21; the address ADDR is 0×12345678.
[0035] In the erase instruction, the command CMD is 0×22; the address ADDR is the storage size of the receiving end.
[0036] In the file information index, the command CMD is 0×23; the address ADDR is the first address of the receiving end.
[0037] Therefore, the handshake instruction is A02112345678+CRC check code; the erase instruction is A022+storage size of the receiving end+CRC check code; the file information index is A023+first address of the receiving end+CRC check code.
[0038] On the basis of the above scheme, the format of the response instruction sent to the host in step S110, the format of the response instruction sent to the host in step S210, and the format of the response instruction sent to the host in step S310 are all device ID+command CMD+execution status+CRC check code; Among them, the length of the device ID is 1 byte, the length of the command CMD is 1 byte, the length of the execution status is 4 bytes, and the length of the CRC check code is 2 bytes.
[0039] Specifically, the device ID is 0×A0.
[0040] In the response instruction sent to the host when checking the CRC check code in the handshake instruction, the command CMD is 0×21; In the response instruction sent to the host when checking the CRC check code in the erase instruction, the command CMD is 0×22; In the response instruction sent to the host when checking the CRC check code in the file information index, the command CMD is 0×23.
[0041] In addition, when the response instruction is verified successfully, the execution status in the response instruction sent to the host is 0×0000; When the response instruction fails to verify, the execution status in the response instruction sent to the host is 0×0001.
[0042] Therefore, the CRC check code in the handshake instruction is checked; if the check is successful, the response instruction is A0210000+CRC check code; if the check fails, the response instruction is A0210001+CRC check code.
[0043] The CRC check code in the erase instruction is checked; if the check is successful, the response instruction is A0220000+CRC check code; if the check fails, the response instruction is A0220001+CRC check code.
[0044] The CRC check code in the file information index is checked; if the check succeeds, the response instruction is A0230000+CRC check code; if the check fails, the response instruction is A0230001+CRC check code.
[0045] Based on the above scheme, the field of the jump instruction is A025.
[0046] Based on the above scheme, when a handshake instruction, erase instruction or file information index is received from the host, it will be judged whether the received command is a normal command. If the received command is judged to be an abnormal command, an error code instruction will be returned to the host.
[0047] A more specific example of the above solution is: the format of the error code instruction is 0×01+0×83+error code type+CRC_L+CRC_H. Among them, CRC_L represents the low byte part of the CRC check code, that is, the low 8 bits of the CRC value; CRC_H represents the high byte part of the CRC check code, that is, the high 8 bits of the CRC value.
[0048] The error code type can be 0×02, and the error code instruction means that the address of the instruction sent by the host is wrong; the error code type can be 0×03, and the error code instruction means that the erase timeout has occurred; the error code type can be 0×04, and the error code instruction means that the CRC check code in the received instruction is wrong; the error code type can be 0×05, and the error code instruction means that the address ADDR in the received file information index is wrong.
[0049] It should be noted that: the program upgrade method based on BootLoader in this embodiment is applied to the upgrade of digital sensor programs in industrial environments.
[0050] In an industrial environment, interference factors and their intensity are stronger than in a normal environment. Some sensors (e.g., full-spectrum sensors) have a higher frequency of program algorithm upgrades than traditional sensors. If the method of this embodiment is not adopted, people need to go to the site to salvage the equipment (sensor), disassemble it and update it. With the method of this embodiment, the program upgrade can be directly realized by connecting to the device through a cable.
[0051] The present invention is further described below with reference to a specific case: Case content: Upgrade the program in the COD sensor. Figure 2 As shown, open FUV v1.42 (equivalent to the host) and configure the serial port, select "Open File", and select the file to be updated, such as Figure 3 As shown, Figure 3 The displayed file is EUV-408-S_0_500_20240429_v1.1.5.bin (COD sensor) to be updated. The steps to download and update the file EUV-408-S_0_500_20240429_v1.1.5.bin through FUV v1.42 include: Step 1: If Figure 4As shown, the handshake instruction sent by FUV v1.42 is received, wherein the handshake instruction is A02112345678DF88 (CRC check code is DF88); the CRC check code in the handshake instruction is checked; if the check is successful, a response instruction is responded, wherein the response instruction is A0210000722E (CRC check code is 722E). Figure 4 As shown, the handshake command and response command are transmitted normally, and "Handshake successful!" will be displayed; Step 2: If Figure 5 As shown, the erase command sent by FUV v1.42 is received, wherein the erase command is A0220000AE289CC2 (CRC check code is 9CC2); the CRC check code in the erase command is checked; if the check is successful, a response command is responded, wherein the response command is A0220000822E (CRC check code is 822E). Figure 5 As shown, the erase command and response command are transmitted normally, and "Erase Successful!" will be displayed; Step 3: If Figure 6 As shown, the file information index sent by FUV v1.42 and the writing of the 512-byte file information are received, wherein the file information index is A02312345678A648 (CRC check code is A648), and the 512-byte file information is the 512-byte file EUV-408-S_0_500_20240429_v1.1.5.bin; as shown Figure 6 As shown, while the 512-byte file information is being written, "Data downloading" will be displayed; After the writing of the 512-byte file information is completed, Figure 7 As shown, the CRC check code (A648) in A02312345678A648 is checked; if the check succeeds, a response instruction is sent, where the response instruction is A0230000D3EE (the CRC check code is D3EE). Figure 7 As shown, the file information index and response command transmission are normal, and "Download Successful!" will be displayed, indicating that the file upgrade is successful.
[0052] The present invention is not limited to the above-mentioned optional implementation modes. Anyone can derive other various forms of products under the inspiration of the present invention. However, no matter what changes are made in the shape or structure, all technical solutions that fall within the scope defined by the claims of the present invention fall within the protection scope of the present invention.
Claims
1. A method for program upgrade based on BootLoader, characterized in that the steps include: S100, receiving a handshake instruction sent by a host, wherein the handshake instruction includes a CRC check code; S110, verifying the CRC check code in the handshake instruction, and sending a response instruction to the host, wherein the response instruction includes a CRC check code, and verifying the response instruction; S120, determining whether to execute step S200 according to the first response instruction verification rule; S200, receiving an erase instruction sent by the host, wherein the erase instruction includes a CRC check code; S210, verifying the CRC check code in the erase instruction, and sending a response instruction to the host, wherein the response instruction includes a CRC check code, and verifying the response instruction; S220, determining whether to execute step S300 according to the second response instruction verification rule; S300, receiving file information and a file information index sent by the host, wherein the file information index includes a CRC checksum; and the host writes the file information; S310, verifying the CRC check code in the file information index, and sending a response instruction to the host, wherein the response instruction includes the CRC check code, and verifying the response instruction; If the response instruction indicates that the verification fails, the process returns to step S200; If the response instruction is a verification success, the file information index and the file information are erased, and the process returns to step S100 to receive the next file information written by the host until the file information is written completely; The program was successfully upgraded.
2. The method for upgrading a program based on BootLoader according to claim 1, characterized in that: In step S120, the first response instruction verification rule is: If the response instruction fails to be verified, the handshake instruction sent by the host is received again, and the CRC check code in the handshake instruction is verified. If the verification still fails after executing three times, the BootLoader is exited; If the response instruction indicates that the verification is successful, the process proceeds to step S200.
3. The method for upgrading a program based on BootLoader according to claim 1, characterized in that: In step S220, the second response instruction verification rule is: If the response instruction fails to be verified, the erase instruction sent by the host is received again, and the CRC check code in the erase instruction is verified. If the verification fails after three executions, the process returns to step S100; If the response instruction indicates that the verification is successful, the process proceeds to step S300 .
4. The method for upgrading a program based on BootLoader according to claim 1, characterized in that: The file information index also includes a write address; In the step S300, the host writes the file information according to the write address; In the step S310, if the response instruction is verified successfully, the file information index and the file information are erased, and the length of the write address is increased by the length of the file information.
5. The method for upgrading a program based on BootLoader according to claim 1, characterized in that: The formats of the handshake instruction, the erase instruction and the file information index are all device ID+command CMD+address ADDR+CRC check code; Among them, the length of the device ID is 1 byte, the length of the command CMD is 1 byte, the length of the address ADDR is 4 bytes, and the length of the CRC check code is 2 bytes.
6. The method for upgrading a program based on BootLoader according to claim 5, characterized in that: In the handshake instruction, the command CMD is 0×21; the address ADDR is 0×12345678; In the erase instruction, the command CMD is 0×22; the address ADDR is the storage size of the receiving end; In the file information index, the command CMD is 0×23; the address ADDR is the first address of the receiving end.
7. The method for upgrading a program based on BootLoader according to claim 1, characterized in that: The format of the response instruction sent to the host in step S110, the format of the response instruction sent to the host in step S210, and the format of the response instruction sent to the host in step S310 are all device ID+command CMD+execution status+CRC check code; Among them, the length of the device ID is 1 byte, the length of the command CMD is 1 byte, the length of the execution status is 4 bytes, and the length of the CRC check code is 2 bytes.
8. The method for upgrading a program based on BootLoader according to claim 7, characterized in that: In the response instruction sent to the host when checking the CRC check code in the handshake instruction, the command CMD is 0×21; In the response instruction sent to the host when checking the CRC check code in the erase instruction, the command CMD is 0×22; In the response instruction sent to the host when checking the CRC check code in the file information index, the command CMD is 0×23.
9. A BootLoader-based program upgrade method according to claim 1, 2 or 3, characterized in that: The format of the response instruction includes the execution status; when verifying the response instruction, When the response instruction is verified successfully, the execution status in the response instruction sent to the host is 0×0000; When the response instruction fails to verify, the execution status in the response instruction sent to the host is 0×0001.
10. A BootLoader-based program upgrade method according to claim 5 or 7, characterized in that: The device ID is 0xA0.
Citation Information
Patent Citations
File storage method and terminal
CN111190869A
Method for upgrading firmware based on chip usbhid, terminal equipment and computer readable storage medium
CN112947978A
SOC remote program updating method and device based on serial port
CN116301959A
Online upgrading configuration method and device for DSP (Digital Signal Processor)
CN117687664A