High-fault-tolerance online upgrading method and system based on dynamic partition
The online upgrade method using dynamic partitioning and double verification mechanism solves the problem of data and storage anomalies during IAP upgrade, achieving higher fault tolerance and reliability.
Patent Information
- Application Number
- CN202510800370.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-06-16
- Publication Date
- 2025-09-12
AI Technical Summary
Existing IAP online upgrade technology cannot effectively handle data anomalies and storage anomalies, resulting in upgrade failure.
A high-fault-tolerant online upgrade method with dynamic partitioning is adopted. The integrity and correctness of the firmware slices are ensured through dynamic redundant transmission and double verification mechanism. The firmware slices are alternately stored and decrypted in the buffer, and the backup area of the boot program area is used to ensure the reliability of the upgrade process.
The reliability of the online upgrade process is improved, which avoids upgrade failures caused by storage anomalies and data reception anomalies, and ensures the smooth progress of the upgrade process.
Smart Images

Figure CN120631401A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of online upgrade, and in particular to a high fault-tolerance online upgrade method and system based on dynamic partitioning. Background Art
[0002] IAP (In Application Programming) online upgrade technology is widely used in the firmware update process of embedded systems, MCUs and MPUs because it can complete program upgrades without physical connection.
[0003] When upgrading the firmware based on the IAP online upgrade technology, the main steps include the following: First, before the program runs, the upgrade flag is detected based on the user boot program; second, if the upgrade flag is valid, it is determined that there is firmware that needs to be updated, and the firmware to be upgraded will be received and decrypted in turn; then, the decrypted firmware to be upgraded is used to overwrite the original program, and the program is reset to realize the online operation of the new program corresponding to the firmware to be upgraded.
[0004] To prevent upgrade failures during the IAP upgrade process, which could cause the corresponding system's running program to enter an infinite loop, current IAP technology considers designing both an application area and an application mirror area. The application area is used to store user applications, while the application mirror area is used to store older versions of applications. If the new version of the application fails to upgrade, the bootloader will use the application mirror area as the main firmware area for the next boot cycle and automatically roll back to the older version of the application in the application mirror area.
[0005] The design of the optional application mirror area mentioned above avoids the program from falling into an infinite loop from an overall perspective, but it is unable to handle the corresponding exceptions during the upgrade process. Specifically, it includes the following two aspects: (1) Data anomaly: During the transmission and reception of the firmware data packet, the reliability of the firmware data packet cannot be verified, resulting in defects in the data in the firmware data packet after decryption or even in the process of overwriting the original program. This will cause the upgrade to fail and roll back to the original program, and the firmware data packet needs to be retransmitted. (2) Storage anomaly: The available data space in the application mirror area is valid, and thus each group of firmware data packets cannot be effectively stored, resulting in the inability to implement program upgrades even if the data is normal. Summary of the Invention
[0006] The present invention aims to provide a high fault-tolerant online upgrade method and system based on dynamic partitioning, so as to solve the technical problem that data anomalies and storage anomalies cannot be effectively handled during the existing IAP upgrade process.
[0007] To achieve the above objectives, the present invention proposes the following technical solutions:
[0008] In a first aspect, this technical solution provides a highly fault-tolerant online upgrade method based on dynamic partitioning, comprising:
[0009] The Flash memory obtains the firmware upgrade instruction issued by the host computer and parses it to obtain the firmware header information carried therein; wherein the firmware header information includes the firmware name and the number of firmware bytes;
[0010] Merge some free blocks in the Flash memory to obtain a buffer corresponding to the number of firmware bytes, and name the buffer with the firmware name in the partition table;
[0011] Receive encrypted firmware slices sent using the dynamic redundancy principle, group them into groups according to the same firmware slices, verify the quick check code carried in each firmware slice, and verify the integrity check code carried in each firmware slice after all firmware slices in the same group have passed the quick verification; wherein, several firmware slices constitute a firmware data packet, and all firmware data packets constitute the firmware to be upgraded; the quick check code is set based on the parity check principle to confirm whether the firmware slice is damaged, and the integrity check code is set based on the cyclic check principle to confirm whether the data in the firmware slice is correct;
[0012] The current verification pass rate is calculated and fed back to the host computer so that it can dynamically adjust the number of redundant transmissions of the firmware fragments; at the same time, the firmware fragments that have passed the verification are stored in the corresponding position of the buffer based on the firmware name, and a first retransmission request is sent to the host computer to retransmit the firmware fragments that have not passed the verification; at the same time, when it is determined that all encrypted firmware fragments have been received and stored in the buffer after verification, the program upgrade flag in the boot program area is modified to true;
[0013] Restart and under the guidance of the modified boot program, decrypt the encrypted firmware fragments in the buffer to obtain a new application, and store it in the application image area in an overwritten manner; then use the application image area as the main program area and run the new application therein.
[0014] Furthermore, the buffer includes a first buffer and a second buffer, and each encrypted firmware fragment is alternately stored in the first buffer and the second buffer;
[0015] Correspondingly, decrypting each encrypted firmware fragment in the buffer to obtain a new application includes:
[0016] When decrypting a firmware fragment encrypted in the first buffer, another decrypted firmware fragment in the second buffer is stored in the application mirror area based on the built-in DMA controller;
[0017] Repeat the previous step until all encrypted firmware slices are decrypted and stored in the application image area, and then calculate the total number of bytes of all encrypted firmware slices;
[0018] After determining that the total number of bytes is consistent with the number of bytes of the firmware, the programs corresponding to all the encrypted firmware segments are used as new application programs.
[0019] Furthermore, the boot program area includes: a main boot area and a backup area;
[0020] Correspondingly, the decrypting of each encrypted firmware fragment in the buffer to obtain a new application program and storing the new application program in the application image area in an overwritten manner includes:
[0021] Decrypt the encrypted firmware slice corresponding to the new boot program and store it in the backup area in an overwritten manner; decrypt the encrypted firmware slice corresponding to the new application and store it in the application image area in an overwritten manner;
[0022] When it is determined that the overwriting process is interrupted, the program overwriting and storage in the backup area or application mirror area will continue after power is cut off and restarted.
[0023] Furthermore, the receiving of each encrypted firmware fragment sent by the dynamic redundancy principle, grouping the same firmware fragments, verifying the quick check code carried in each firmware fragment, and verifying the integrity check code carried in each firmware fragment after all the firmware fragments in the same group have passed the quick verification; includes:
[0024] Synchronously update and store the current status of each firmware slice in the partition table of the buffer;
[0025] The data storage rules for each storage space corresponding to the buffer in the partition table are as follows: the firmware slice name is used as the vertical data, and the current status of the firmware slice is used as the horizontal data; the firmware slice name is hierarchically divided into: firmware name, firmware package number, firmware slice number; the current status is: waiting to be received, received, reception error, verification passed, or verification failed;
[0026] If a power outage occurs during transmission, power off and restart the system and obtain the name of the firmware shard in the partition table that is currently receiving abnormally, and write it into the second retransmission request;
[0027] Send a second retransmission request to the host computer to request to continue retransmission from the firmware segment that received the exception.
[0028] Further, including:
[0029] After each firmware segment is divided into segments according to the preset length, the AES algorithm is used for sequential block encryption;
[0030] When it is determined that the byte length of the last group of data in any firmware segment is less than a preset length, an identifier and a number of invalid data are sequentially added to the end of the last group of data so that the final byte length thereof is consistent with the preset length;
[0031] Each firmware slice is decrypted, and when it is determined that an identifier exists, the identifier and invalid data after the identifier in the decrypted firmware slice are deleted.
[0032] In a second aspect, this technical solution provides a highly fault-tolerant online upgrade system based on dynamic partitioning, including:
[0033] The instruction acquisition module is used to control the Flash memory to obtain the firmware upgrade instruction issued by the host computer and parse the firmware header information carried therein; wherein the firmware header information includes the firmware name and the number of firmware bytes;
[0034] A dynamic buffer module is used to merge some free blocks in the Flash memory to obtain a buffer corresponding to the number of firmware bytes, and name the buffer with the firmware name in the partition table;
[0035] The firmware receiving module is configured to receive encrypted firmware fragments sent using the dynamic redundancy principle, group the identical firmware fragments, verify the quick check codes carried in each firmware fragment, and verify the integrity check codes carried in each firmware fragment after all the firmware fragments in the same group have passed the quick check. Several firmware fragments form a firmware data packet, and all firmware data packets constitute the firmware to be upgraded. The quick check code is set based on the parity check principle to confirm whether the firmware fragments are damaged, and the integrity check code is set based on the cyclic check principle to confirm whether the data in the firmware fragments is correct.
[0036] The abnormal retransmission module is used to calculate the current verification pass rate and feed it back to the host computer so that it can dynamically adjust the number of redundant transmissions of the firmware fragments; at the same time, based on the firmware name, the firmware fragments that have passed the verification are stored in the corresponding position of the buffer, and a first retransmission request is sent to the host computer to retransmit the firmware fragments that have not passed the verification; at the same time, when it is determined that all encrypted firmware fragments have been received and stored in the buffer after verification, the program upgrade flag in the boot program area is modified to true;
[0037] The program upgrade module is used to restart and, under the guidance of the modified boot program, decrypt the encrypted firmware fragments in the buffer to obtain a new application, and store it in the application image area in an overwritten manner; then use the application image area as the main program area and run the new application therein.
[0038] Furthermore, the buffer includes a first buffer and a second buffer, and each encrypted firmware fragment is alternately stored in the first buffer and the second buffer;
[0039] The corresponding program upgrade modules include:
[0040] A decryption and storage unit, configured to decrypt a firmware segment encrypted in the first buffer and store another decrypted firmware segment in the second buffer into the application image area based on a built-in DMA controller;
[0041] a repeating execution unit, configured to repeatedly execute the previous step until all encrypted firmware fragments are decrypted and stored in the application image area, and calculate the total number of bytes of all encrypted firmware fragments;
[0042] The judging and running unit is configured to, after judging that the total number of bytes is consistent with the number of bytes of the firmware, use the programs corresponding to all the encrypted firmware segments as new application programs.
[0043] Furthermore, the boot program area includes: a main boot area and a backup area;
[0044] The corresponding program upgrade module includes:
[0045] The boot storage unit is used to decrypt the encrypted firmware fragment corresponding to the new boot program and store it in the backup area in an overwritten manner, and decrypt the encrypted firmware fragment corresponding to the new application program and store it in the application image area in an overwritten manner;
[0046] When it is determined that the overwriting process is interrupted, the program overwriting and storage in the backup area or application mirror area will continue after power is cut off and restarted.
[0047] According to a third aspect, an electronic device is provided, comprising at least one processor, wherein the processor is coupled to a memory, wherein a computer program is stored in the memory, and wherein the computer program is configured to execute the method when executed by the processor.
[0048] In a fourth aspect, a computer-readable storage medium stores a computer program thereon, wherein the computer program is configured to be executed by a processor to implement the method described.
[0049] Beneficial effects:
[0050] It can be seen from the above technical solutions that the technical solution of the present invention provides a high fault-tolerant online upgrade method based on dynamic partitioning to solve the technical defect of low fault tolerance in current online upgrades.
[0051] First, the firmware byte count is included in the firmware upgrade instruction issued by the host computer, allowing the Flash memory to pre-allocate storage space for the firmware to be upgraded based on its size. When continuous space is insufficient, storage space is allocated based on free block merging. This avoids reception anomalies caused by insufficient space during subsequent firmware reception. The corresponding allocated buffers are named in the partition table to ensure the accuracy of subsequent storage. To improve data reception accuracy, a dynamic redundant transmission mechanism and a dual verification mechanism are introduced. At this point, the Flash memory performs rapid verification and integrity verification on consecutively received firmware fragments to confirm that the firmware fragments are intact and the data within them is complete. This avoids update anomalies caused by data anomalies. Furthermore, the firmware fragments are smaller components of the firmware data packet. Therefore, if data reception is abnormal (i.e., verification fails), the firmware fragments that failed verification can be directly retransmitted based on the first retransmission request and stored in the corresponding storage area. This avoids retransmitting the entire firmware data packet, which is not only inefficient but also difficult to identify the location of the anomaly.
[0052] At this time, the above process can effectively avoid upgrade failures caused by storage anomalies and data reception anomalies during the online upgrade process, thereby improving the reliability of the entire upgrade process.
[0053] It should be appreciated that all combinations of the foregoing concepts, as well as additional concepts described in greater detail below, to the extent such concepts are not mutually inconsistent, can be considered to be part of the inventive subject matter of this disclosure.
[0054] The foregoing and other aspects, embodiments, and features of the present invention will be more fully understood from the following description in conjunction with the accompanying drawings. Other additional aspects of the present invention, such as features and / or beneficial effects of the exemplary embodiments, will become apparent from the following description or through practice of specific embodiments according to the present invention. BRIEF DESCRIPTION OF THE DRAWINGS
[0055] The accompanying drawings are not intended to be drawn to scale. In the drawings, each identical or nearly identical component shown in various figures may be represented by the same reference numeral. For the sake of clarity, not every component is labeled in every figure. Embodiments of various aspects of the present invention will now be described by way of example and with reference to the accompanying drawings, in which:
[0056] Figure 1 This is a flow chart of the high fault-tolerant online upgrade method based on dynamic partitioning described in this embodiment;
[0057] Figure 2 This is a flowchart of power-off retransmission in this embodiment;
[0058] Figure 3This is a flow chart of data reception and decryption based on the double buffering mechanism of this embodiment;
[0059] Figure 4 This is a flowchart of the process of handling program overwriting exceptions during power outages in this embodiment;
[0060] Figure 5 This is a flowchart of firmware fragment encryption and decryption in this embodiment;
[0061] Figure 6 This is a structural block diagram of the high fault-tolerant online upgrade system based on dynamic partitioning described in this embodiment;
[0062] Figure 7 This is a structural block diagram of the electronic device described in this embodiment. DETAILED DESCRIPTION
[0063] In order to make the purpose, technical solutions and advantages of the embodiments of the present invention clearer, the technical solutions of the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings of the embodiments of the present invention. Obviously, the described embodiments are part of the embodiments of the present invention, not all of the embodiments. Based on the described embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention. Unless otherwise defined, the technical terms or scientific terms used herein should be the common meanings understood by people with ordinary skills in the field to which the present invention belongs.
[0064] The words “first”, “second” and similar terms used in the specification and claims of this application do not indicate any order, quantity or importance, but are only used to distinguish different components. Similarly, unless the context clearly indicates otherwise, the singular forms of “a”, “an” or “the” and similar words do not indicate a quantitative limitation, but rather indicate the presence of at least one. Words such as “include” or “comprise” mean that the elements or objects appearing before “include” or “comprises” cover the features, wholes, steps, operations, elements and / or components listed after “include” or “comprises”, and do not exclude the existence or addition of one or more other features, wholes, steps, operations, elements, components and / or their collections. “Up”, “down”, “left”, “right” and the like are only used to indicate relative positional relationships. When the absolute position of the described object changes, the relative positional relationship may also change accordingly.
[0065] While firmware upgrades based on IAP online upgrade technology, including application mirroring, can prevent the system from falling into an infinite loop when the upgrade fails, they cannot effectively address storage and data reception anomalies during the upgrade process, inevitably leading to system upgrade failures. Therefore, this embodiment aims to provide a highly fault-tolerant online upgrade method based on dynamic partitioning to simultaneously address the aforementioned technical issues.
[0066] The following is a detailed introduction to the high fault-tolerance online upgrade method based on dynamic partitioning described in this embodiment with reference to the accompanying drawings.
[0067] Combine Figure 1 As shown, the method includes:
[0068] Step S202: The Flash memory obtains the firmware upgrade instruction sent by the host computer, and parses it to obtain the firmware header information carried therein.
[0069] In this embodiment, the firmware header information includes the firmware name, firmware byte count, and encryption mode. Different encryption algorithms can be used to encrypt the firmware to be upgraded according to actual needs to improve data transmission security.
[0070] Step S204: Merge some free blocks in the Flash memory to obtain a buffer corresponding to the number of firmware bytes, and name the buffer using the firmware name in the partition table.
[0071] In a specific application, if there is a continuous storage space of corresponding length in the Flash memory, it is allocated to the buffer zone. Otherwise, defragmentation is triggered based on the method described in step S204 to merge free blocks and allocate them to the buffer zone.
[0072] In specific implementation, the dynamic partitioning process of the buffer zone in step S204 includes the following contents:
[0073] (1) Partition table storage:
[0074] A fixed 4KB area is reserved at the beginning of the Flash memory for storing partition tables, which are used to write partition information. Each partition includes a starting address, partition size, partition type (boot parameters, application), and reserved fields. Each partition table header contains fixed information, including a checksum to verify the integrity of the partition table data; and a partition identifier to verify the validity of the partition table, the number of partitions, the starting address, and the size of the partition.
[0075] (2) Dynamic configuration:
[0076] Generate the partition table through the script during compilation, define the partition parameters through macros in the makefile to perform partitioning, and write the generated partition table binary file to the header of the Flash before the firmware is burned.
[0077] (3) Partition table verification and fault tolerance
[0078] Verification at startup: read the partition table header, check the partition identifier, recalculate the CRC of the partition table data, and compare it with the CRC stored in the header. If the verification fails, restore from the backup partition table. If the backup partition table is also damaged, you need to receive a new partition table through the serial port or network.
[0079] Partition table update: When upgrading the partition table, the backup data area is erased, the new partition table data is written to the backup area, the CRC is calculated, and after verifying that the backup partition table is correct, the main data area is erased and the new data is written. If the power is cut off in the middle, the system will detect that the data area is damaged after restart and automatically switch to the backup data area.
[0080] Step S206: Receive the encrypted firmware slices sent by the dynamic redundancy principle, group them into the same firmware slices, verify the quick check code carried in each firmware slice, and verify the integrity check code carried in each firmware slice after all the firmware slices in the same group pass the quick verification.
[0081] In this embodiment, the firmware to be upgraded is divided into several firmware data packets, each of which is further divided into several firmware slices. A fast checksum based on the parity check principle is used to determine whether the firmware slices are corrupted, and an integrity checksum (CRC16) based on the cyclic check principle is used to confirm whether the data within the firmware slices is correct. This embodiment ensures the accuracy of data reception through dynamic redundant transmission and a double-check mechanism.
[0082] When a firmware fragment is damaged or lacks integrity during transmission, only the firmware fragment can be retransmitted without retransmitting the entire firmware data packet, thereby reducing the amount of retransmitted data. Specifically, in this embodiment, the number of bytes of each firmware fragment is 512 bytes.
[0083] As a preferred embodiment, in order to handle the data reception abnormality caused by the power failure abnormality, combined with Figure 2 As shown, the following steps are also included:
[0084] Step S20602: Synchronously update and store the current status of each firmware slice in the partition table of the buffer.
[0085] At this time, correspondingly, the data storage rules of each storage space corresponding to the buffer zone in the partition table also include: the firmware slice name is used as the vertical data, and the current status of the firmware slice is used as the horizontal data; wherein, the firmware slice name is divided into levels in sequence including: firmware name, firmware package number, firmware slice number; the current status is: to be received, received, reception exception, verification passed, or verification failed.
[0086] Step S20604: If a power outage occurs during transmission, power off and restart the system and obtain the name of the firmware slice in the partition table that is currently in a reception abnormality state, and write it into the second retransmission request.
[0087] Step S20606: Send a second retransmission request to the host computer to request to continue retransmission from the firmware segment that received the exception.
[0088] Furthermore, the operations of step S206 to step S210 are explained based on the following example. The firmware to be upgraded is: including 10 firmware data packets, each firmware data includes 8 firmware fragments. Assume that the power is cut off at the 4th firmware fragment included in the 6th firmware data, and the following operations are performed: (1) After restarting, the current state corresponding to the firmware fragment with the buffer number of firmware XX-6-4 is a reception exception. (2) A second retransmission request is sent to the upper computer, and the retransmission continues from packet 6 fragment 4. (3) Each time a firmware fragment is received, the fragment flag is recorded and a quick check and integrity check are performed. After completion, the group sequence number is incremented and stored.
[0089] Step S208: Calculate the current verification pass rate and feed it back to the host computer so that it can dynamically adjust the number of redundant transmissions of the firmware fragments; at the same time, store the firmware fragments that have passed the verification into the corresponding position of the buffer based on the firmware name, and send a first retransmission request to the host computer to retransmit the firmware fragments that have not passed the verification; at the same time, when it is determined that all encrypted firmware fragments are received and stored in the buffer after verification, modify the program upgrade flag in the boot program area to true.
[0090] As a specific implementation, during dynamic redundant transmission, each firmware fragment is sent twice. The Flash memory compares the two firmware fragments for consistency. If they both pass the verification, they are directly accepted; if they do not, a request is made to retransmit the different firmware fragments. During the dynamic retransmission process, if the current pass rate is at least the pass rate threshold, redundant transmission is reduced. For example, if a fragment is sent twice, it is directly sent once to increase the transmission rate. Otherwise, redundant transmission is enabled.
[0091] Step S210: Restart and, under the guidance of the modified boot program, decrypt each encrypted firmware fragment in the buffer to obtain a new application, and store it in the application image area in an overwritten manner; then use the application image area as the main program area and run the new application therein.
[0092] In specific implementation, based on the above partition table design, the following partition table processing is also included during the operation of steps S206 to S210: (1) At startup, check whether the partition table identifier is a legal value, calculate the CRC32 of the main table and compare it with the main table CRC32 stored during the transmission process. If they are consistent, load the main partition table. If they are inconsistent, load the backup partition table and repair the main table. (2) Determine whether an abnormality has occurred based on the status flags of each partition in the partition table, then request the host computer to continue sending firmware fragments based on the recorded packet sequence number. Update the fragment CRC16 and fragment flag for each firmware fragment received. Update the packet sequence number and current write status for each completed group. Calculate and update the CRC32 value of the partition table in real time. (3) After all fragments are received, verify the integrity of the data based on the CRC16 of the fragment. If all fragments pass the verification, mark the partition status as verified and back up the partition table.
[0093] As a preferred embodiment, in order to increase the data receiving and decryption speed, so as to increase the upgrade speed, the buffer is set to include a first buffer and a second buffer, and each encrypted firmware fragment is alternately stored in the first buffer and the second buffer. Figure 3 As shown, step S210 further includes the following steps:
[0094] Step S21002: When decrypting a firmware segment encrypted in the first buffer, another decrypted firmware segment in the second buffer is stored in the application mirror area based on the built-in DMA controller.
[0095] Step S21004: Repeat the previous step until all encrypted firmware fragments are decrypted and stored in the application image area, and calculate the total number of bytes of all encrypted firmware fragments.
[0096] Step S21006: After determining that the total number of bytes is consistent with the number of bytes of the firmware, the programs corresponding to all encrypted firmware fragments are used as new application programs.
[0097] At the same time, in order to further improve the efficiency of program overwriting and avoid the need to restart the decryption overwriting of the entire firmware when overwriting fails, the boot program area is set to include the main boot area and the backup area. Figure 4 As shown, step S210 further includes the following steps:
[0098] Step S21022: decrypt the encrypted firmware fragment corresponding to the new boot program and store it in the backup area in an overwritten manner; decrypt the encrypted firmware fragment corresponding to the new application and store it in the application image area in an overwritten manner.
[0099] In specific implementation, if the overwriting process is interrupted, the program in the backup area or application mirror area will be overwritten after power off and restart. This can avoid re-decrypting and overwriting the entire firmware when the overwriting fails; instead, re-decrypting and overwriting can be performed only on the abnormal part.
[0100] As another preferred embodiment, considering that the current encryption of the firmware to be upgraded is performed using the AES algorithm (specifically the AES-NI algorithm), it can only encrypt 16 bytes of data at a time. When the data is less than 16 bytes, the remaining bits need to be padded. However, at this time, the data padding may contain the same sequence as the actual transmitted data, resulting in the accidental deletion of valid data during decryption. Therefore, this embodiment improves this defect. Specific combination Figure 5 As shown, the following steps are included:
[0101] Step S102: After dividing each firmware segment into segments according to a preset length, the segments are encrypted sequentially using the AES algorithm.
[0102] In this embodiment, the preset length is 16 bytes.
[0103] Step S104: when it is determined that the byte length of the last group of data in any firmware segment is less than the preset length, an identifier and some invalid data are sequentially added to the end of the last group of data to make the final byte length consistent with the preset length.
[0104] Step S106: decrypt each firmware slice, and when it is determined that an identifier exists, delete the identifier and invalid data after the identifier in the decrypted firmware slice.
[0105] At this time, in steps S102 to S106, the padding portion can be accurately removed according to the identifier during decryption to avoid misjudgment.
[0106] In summary, this embodiment introduces dynamic buffer allocation to address storage anomalies during firmware upgrade reception. Dynamic redundant transmission of smaller firmware fragments and a dual verification mechanism address data reception anomalies and ensure data transmission efficiency. During firmware upgrade decryption, a double buffering mechanism is introduced to improve data transmission efficiency. An identifier-based encryption mechanism is also designed to prevent accidental data deletion. This effectively improves the overall fault tolerance of the upgrade process, ensuring a smooth upgrade while also effectively guaranteeing the upgrade rate.
[0107] The above program can be executed in a processor or stored in a memory (or computer-readable storage medium). Computer-readable media include permanent and non-permanent, removable and non-removable media that can implement information storage by any method or technology. Information can be computer-readable instructions, data structures, program modules, or other data. Examples of computer storage media include, but are not limited to, phase change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other memory technology, compact disc read-only memory (CD-ROM), digital versatile disc (DVD) or other optical storage, magnetic cassettes, magnetic tape, disk storage or other magnetic storage devices, or any other non-transmission medium that can be used to store information that can be accessed by a computing device. As defined herein, computer-readable media does not include temporary computer-readable media such as modulated data signals and carrier waves.
[0108] These computer programs can also be loaded onto a computer or other programmable data processing device so that a series of operational steps are executed on the computer or other programmable device to produce a computer-implemented process, thereby providing instructions for executing on the computer or other programmable device to implement the process. Figure 1 a process or multiple processes and / or boxes Figure 1 The steps of the functions specified in one or more blocks can be implemented by different modules corresponding to different steps.
[0109] This embodiment also provides a high fault tolerance online upgrade system based on dynamic partitioning. Figure 6 As shown, the system includes:
[0110] The instruction acquisition module is used to control the Flash memory to obtain the firmware upgrade instruction issued by the host computer and parse the firmware header information carried therein. The firmware header information includes the firmware name and the number of firmware bytes.
[0111] The dynamic buffer module is used to merge some free blocks in the Flash memory to obtain a buffer corresponding to the number of firmware bytes, and name the buffer with the firmware name in the partition table.
[0112] The firmware receiving module is used to receive encrypted firmware fragments sent through the dynamic redundancy principle, group them into groups according to the same firmware fragments, verify the quick check code carried in each firmware fragment, and verify the integrity check code carried in each firmware fragment after all firmware fragments in the same group have passed the quick verification; wherein, several firmware fragments constitute a firmware data packet, and all firmware data packets constitute the firmware to be upgraded; the quick check code is set based on the parity check principle to confirm whether the firmware fragment is damaged, and the integrity check code is set based on the cyclic check principle to confirm whether the data in the firmware fragment is correct.
[0113] The abnormal retransmission module is used to calculate the current verification pass rate and feed it back to the host computer so that it can dynamically adjust the number of redundant transmissions of the firmware fragments; at the same time, based on the firmware name, the firmware fragments that have passed the verification are stored in the corresponding position of the buffer, and the first retransmission request is sent to the host computer to retransmit the firmware fragments that have not passed the verification; at the same time, when it is determined that all encrypted firmware fragments have been received and stored in the buffer after verification, the program upgrade flag in the boot program area is modified to true.
[0114] The program upgrade module is used to restart and, under the guidance of the modified boot program, decrypt the encrypted firmware fragments in the buffer to obtain a new application, and store it in the application image area in an overwritten manner; then use the application image area as the main program area and run the new application therein.
[0115] Since the system is built based on the method, the above description will not be repeated here.
[0116] For example, the buffer includes a first buffer and a second buffer, and each encrypted firmware fragment is alternately stored in the first buffer and the second buffer. The corresponding program upgrade module includes:
[0117] The decryption and storage unit is configured to, when decrypting an encrypted firmware fragment in the first buffer, store another decrypted firmware fragment in the second buffer into the application image area based on the built-in DMA controller. The repetition unit is configured to repeatedly execute the previous step until all encrypted firmware fragments are decrypted and stored in the application image area, and calculate the total number of bytes of all encrypted firmware fragments.
[0118] The judging and running unit is configured to, after judging that the total number of bytes is consistent with the number of bytes of the firmware, use the programs corresponding to all the encrypted firmware segments as new application programs.
[0119] For another example, the boot program area includes: a main boot area and a backup area. At this time, the corresponding program upgrade module includes:
[0120] The boot storage unit is configured to decrypt the encrypted firmware fragment corresponding to the new boot program and store it in the backup area as an overwrite. It also decrypts the encrypted firmware fragment corresponding to the new application program and stores it in the application mirror area as an overwrite. If the overwriting process is interrupted, the overwriting of the program in the backup area or application mirror area will continue after power is turned off and restarted.
[0121] Combine Figure 7 As shown, this embodiment further provides an electronic device, including at least one processor, wherein the processor is coupled to a memory, wherein a computer program is stored in the memory, and the computer program is configured to execute the method when executed by the processor.
[0122] At the same time, this embodiment also provides a computer-readable storage medium on which a computer program is stored. The computer program is used to be executed by a processor to implement the method described.
[0123] Since the system, electronic device and storage medium are all built based on the method and used to implement the method, in actual application, they can also effectively deal with storage anomalies and data reception anomalies that exist during the upgrade; thereby improving the fault tolerance of the online upgrade process and improving the reliability of the online upgrade.
[0124] While the present invention has been disclosed above with reference to preferred embodiments, this is not intended to limit the present invention. Persons skilled in the art will readily appreciate that various modifications and variations can be made without departing from the spirit and scope of the present invention. Therefore, the scope of protection of the present invention shall be determined by the claims.
Claims
1. A high fault-tolerant online upgrade method based on dynamic partitioning, characterized in that: include: The Flash memory obtains the firmware upgrade instruction issued by the host computer and parses it to obtain the firmware header information carried therein; wherein the firmware header information includes the firmware name and the number of firmware bytes; Merge some free blocks in the Flash memory to obtain a buffer corresponding to the number of firmware bytes, and name the buffer with the firmware name in the partition table; Receive encrypted firmware slices sent using the dynamic redundancy principle, group them into groups according to the same firmware slices, verify the quick check code carried in each firmware slice, and verify the integrity check code carried in each firmware slice after all firmware slices in the same group have passed the quick verification; wherein, several firmware slices constitute a firmware data packet, and all firmware data packets constitute the firmware to be upgraded; the quick check code is set based on the parity check principle to confirm whether the firmware slice is damaged, and the integrity check code is set based on the cyclic check principle to confirm whether the data in the firmware slice is correct; The current verification pass rate is calculated and fed back to the host computer so that it can dynamically adjust the number of redundant transmissions of the firmware fragments; at the same time, the firmware fragments that have passed the verification are stored in the corresponding position of the buffer based on the firmware name, and a first retransmission request is sent to the host computer to retransmit the firmware fragments that have not passed the verification; at the same time, when it is determined that all encrypted firmware fragments have been received and stored in the buffer after verification, the program upgrade flag in the boot program area is modified to true; Restart and under the guidance of the modified boot program, decrypt the encrypted firmware fragments in the buffer to obtain a new application, and store it in the application image area in an overwritten manner; then use the application image area as the main program area and run the new application therein.
2. The high fault-tolerant online upgrade method based on dynamic partitioning according to claim 1, characterized in that: The buffer includes a first buffer and a second buffer, and each encrypted firmware fragment is alternately stored in the first buffer and the second buffer; Correspondingly, decrypting each encrypted firmware fragment in the buffer to obtain a new application includes: When decrypting a firmware fragment encrypted in the first buffer, another decrypted firmware fragment in the second buffer is stored in the application mirror area based on the built-in DMA controller; Repeat the previous step until all encrypted firmware slices are decrypted and stored in the application image area, and then calculate the total number of bytes of all encrypted firmware slices; After determining that the total number of bytes is consistent with the number of bytes of the firmware, the programs corresponding to all the encrypted firmware segments are used as new application programs.
3. The high fault-tolerant online upgrade method based on dynamic partitioning according to claim 1, characterized in that: The boot program area includes: the main boot area and the backup area; Correspondingly, the decrypting of each encrypted firmware fragment in the buffer to obtain a new application program and storing the new application program in the application image area in an overwritten manner includes: Decrypt the encrypted firmware slice corresponding to the new boot program and store it in the backup area in an overwritten manner; decrypt the encrypted firmware slice corresponding to the new application and store it in the application image area in an overwritten manner; When it is determined that the overwriting process is interrupted, the program overwriting and storage in the backup area or application mirror area will continue after power is cut off and restarted.
4. The high fault-tolerant online upgrade method based on dynamic partitioning according to claim 1, characterized in that: The receiving of each encrypted firmware fragment sent by the dynamic redundancy principle, grouping the same firmware fragments, verifying the quick check code carried in each firmware fragment, and verifying the integrity check code carried in each firmware fragment after all the firmware fragments in the same group have passed the quick verification; including: Synchronously update and store the current status of each firmware slice in the partition table of the buffer; The data storage rules for each storage space corresponding to the buffer in the partition table are as follows: the firmware slice name is used as the vertical data, and the current status of the firmware slice is used as the horizontal data; the firmware slice name is hierarchically divided into: firmware name, firmware package number, firmware slice number; the current status is: waiting to be received, received, reception error, verification passed, or verification failed; If a power outage occurs during transmission, power off and restart the system and obtain the name of the firmware shard in the partition table that is currently receiving abnormally, and write it into the second retransmission request; Send a second retransmission request to the host computer to request to continue retransmission from the firmware segment that received the exception.
5. The high fault-tolerant online upgrade method based on dynamic partitioning according to claim 1, characterized in that: include: After each firmware segment is divided into segments according to the preset length, the AES algorithm is used for sequential block encryption; When it is determined that the byte length of the last group of data in any firmware segment is less than a preset length, an identifier and a number of invalid data are sequentially added to the end of the last group of data so that the final byte length thereof is consistent with the preset length; Each firmware slice is decrypted, and when it is determined that an identifier exists, the identifier and invalid data after the identifier in the decrypted firmware slice are deleted.
6. A high fault-tolerant online upgrade system based on dynamic partitioning, characterized in that: include: The instruction acquisition module is used to control the Flash memory to obtain the firmware upgrade instruction issued by the host computer and parse the firmware header information carried therein; wherein the firmware header information includes the firmware name and the number of firmware bytes; A dynamic buffer module is used to merge some free blocks in the Flash memory to obtain a buffer corresponding to the number of firmware bytes, and name the buffer with the firmware name in the partition table; The firmware receiving module is configured to receive encrypted firmware fragments sent using the dynamic redundancy principle, group the identical firmware fragments, verify the quick check codes carried in each firmware fragment, and verify the integrity check codes carried in each firmware fragment after all the firmware fragments in the same group have passed the quick check. Several firmware fragments form a firmware data packet, and all firmware data packets constitute the firmware to be upgraded. The quick check code is set based on the parity check principle to confirm whether the firmware fragments are damaged, and the integrity check code is set based on the cyclic check principle to confirm whether the data in the firmware fragments is correct. The abnormal retransmission module is used to calculate the current verification pass rate and feed it back to the host computer so that it can dynamically adjust the number of redundant transmissions of the firmware fragments; at the same time, based on the firmware name, the firmware fragments that have passed the verification are stored in the corresponding position of the buffer, and a first retransmission request is sent to the host computer to retransmit the firmware fragments that have not passed the verification; at the same time, when it is determined that all encrypted firmware fragments have been received and stored in the buffer after verification, the program upgrade flag in the boot program area is modified to true; The program upgrade module is used to restart and, under the guidance of the modified boot program, decrypt the encrypted firmware fragments in the buffer to obtain a new application, and store it in the application image area in an overwritten manner; then use the application image area as the main program area and run the new application therein.
7. The high fault-tolerant online upgrade system based on dynamic partitioning according to claim 6, characterized in that: The buffer includes a first buffer and a second buffer, and each encrypted firmware fragment is alternately stored in the first buffer and the second buffer; The corresponding program upgrade modules include: A decryption and storage unit, configured to decrypt a firmware segment encrypted in the first buffer and store another decrypted firmware segment in the second buffer into the application image area based on a built-in DMA controller; a repeating execution unit, configured to repeatedly execute the previous step until all encrypted firmware fragments are decrypted and stored in the application image area, and calculate the total number of bytes of all encrypted firmware fragments; The judging and running unit is configured to, after judging that the total number of bytes is consistent with the number of bytes of the firmware, use the programs corresponding to all the encrypted firmware segments as new application programs.
8. The high fault-tolerant online upgrade system based on dynamic partitioning according to claim 6, characterized in that: The boot program area includes: the main boot area and the backup area; The corresponding program upgrade module includes: The boot storage unit is used to decrypt the encrypted firmware fragment corresponding to the new boot program and store it in the backup area in an overwritten manner, and decrypt the encrypted firmware fragment corresponding to the new application program and store it in the application image area in an overwritten manner; When it is determined that the overwriting process is interrupted, the program overwriting and storage in the backup area or application mirror area will continue after power is cut off and restarted.
9. An electronic device, characterized in that: The method comprises at least one processor coupled to a memory, wherein a computer program is stored in the memory, and the computer program is configured to execute the method according to any one of claims 1 to 5 when executed by the processor.
10. A computer-readable storage medium, characterized in that A computer program is stored thereon, and the computer program is used to be executed by a processor to implement the method according to any one of claims 1 to 5.