Firmware updating method, device and equipment and readable storage medium

By using the differential method to divide and replace firmware data blocks, the problem of low firmware update efficiency is solved, and a more efficient firmware update process is achieved.

CN121579052APending Publication Date: 2026-02-27NOBO AUTOMOTIVE TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202511644962.5
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-11-11
Publication Date
2026-02-27

AI Technical Summary

Technical Problem

The current firmware update process is inefficient and takes a long time, affecting the normal use of hardware devices.

Method used

By employing a differential approach, the new firmware is divided into multiple data blocks and a checksum is generated. The differences between the new firmware and the old firmware are compared, and only the data blocks with the differences are replaced, thus reducing the amount of data to be erased and written.

Benefits of technology

It improves the efficiency of firmware updates, reduces update time, and ensures the normal operation of hardware devices.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121579052A_ABST
    Figure CN121579052A_ABST
Patent Text Reader

Abstract

The invention provides a firmware updating method, device and equipment and a readable storage medium, and is applied to the technical field of computers. The method comprises the steps that in the firmware updating process, new firmware is divided into a plurality of first data blocks in sequence, a first check code of each first data block is generated, a second check code of each second data block in old firmware is obtained at the same time, and when it is determined that the first check code of the ith first data block is different from the second check code of the ith second data block, the first data block and the second data block are updated; and replacing the ith second data block in the memory with the ith first data block, so that old firmware in the memory can be updated into new firmware. According to the method, in the firmware updating process, only part of the second data blocks of the old firmware stored in the memory need to be erased, and the corresponding part of the first data blocks in the new firmware need to be written into the memory, so that a large amount of time can be saved, and the firmware updating efficiency can be improved.
Need to check novelty before this filing date? Find Prior Art

Description

TECHNICAL FIELD

[0001] The present application relates to the technical field of computer, and more particularly, to a firmware updating method, device, equipment and readable storage medium in the technical field of computer. BACKGROUND

[0002] Firmware is a special software embedded in hardware devices, which mainly controls the basic functions and operations of hardware devices, and provides stable and reliable basic support for hardware devices to ensure normal operation of hardware devices.

[0003] In firmware updating, the common practice is to erase the old version of firmware stored in the memory first, and then write the new version of firmware into the memory. This method takes a long time, resulting in low efficiency of the entire firmware updating process. SUMMARY

[0004] The present application provides a firmware updating method, device, equipment and readable storage medium, which can improve the efficiency of firmware updating process.

[0005] In a first aspect, a firmware updating method is provided, comprising: obtaining first check codes of a plurality of first data blocks, the plurality of first data blocks being obtained by sequentially dividing a new firmware; obtaining second check codes of a plurality of second data blocks, the plurality of second data blocks being obtained by sequentially dividing an old firmware previously stored in a memory, a data length of the second data block and a data length of the first data block being N times of a minimum erasing unit of the memory, N being an integer greater than 0; determining whether the first check code of the i-th first data block is the same as the second check code of the i-th second data block, i being an integer greater than 0 if not, using the i-th first data block to replace the i-th second data block in the memory to update the old firmware in the memory to the new firmware.

[0006] In the firmware updating process, the new firmware is sequentially divided into a plurality of first data blocks, a first check code of each first data block is generated, and a second check code of each second data block in the old firmware is obtained. When the first check code of the i th first data block is determined to be different from the second check code of the i th second data block, the i th first data block is used to replace the i th second data block in the memory. In this way, the old firmware in the memory can be updated to the new firmware. In the method, only part of the second data blocks of the old firmware stored in the memory needs to be erased in the firmware updating process, and the corresponding part of the first data blocks in the new firmware is written into the memory. Compared with the prior art of erasing the entire old firmware and writing the entire new firmware into the memory, a large amount of time can be saved, thereby improving the firmware updating efficiency.

[0007] Optionally, after the i th first data block is used to replace the i th second data block in the memory, the method further includes: when a third check code is different from a fourth check code, the i th first data block is used again to replace the i th second data block in the memory, the third check code is generated according to the new firmware, and the fourth check code is generated according to the firmware currently stored in the memory.

[0008] In the embodiment of the application, when the third check code is different from the fourth check code, the i th first data block is used again to replace the i th second data block in the memory. When the new firmware is written incorrectly, the new firmware is written into the memory again, so as to improve the reliability in the firmware updating process.

[0009] Optionally, the method further includes: determining a replacement number, the replacement number being the number of times that the i th first data block is used to replace the i th second data block; when the replacement number is less than a preset number, the i th first data block is used to replace the i th second data block in the memory; and when the replacement number is greater than or equal to the preset number, the firmware currently stored in the memory is erased, and the new firmware is written into the memory.

[0010] In the embodiment of the application, after the first data block is used to replace the corresponding second data block for multiple times, if it is determined that the new firmware is still not successfully written into the memory, the firmware in the memory is erased, and the new firmware is written into the memory, so as to improve the success rate in the firmware updating process.

[0011] Optionally, before replacing the i-th second data block in the memory with the i-th first data block again when the third check code is different from the fourth check code, the method further comprises: generating the third check code according to the first data block used when replacing the second data block; and generating the fourth check code according to the third data block in the memory after being replaced.

[0012] In the embodiments of the present application, the third check code is generated according to the first data block used in the firmware updating process, and the fourth check code is generated according to the third data block actually written into the memory. By comparing the two check codes, it can be determined whether the actual data written into the memory is the same as the target data to be written, and further whether the firmware in the memory is the same as the new firmware. Moreover, compared with reading the entire firmware from the memory to generate the fourth check code, the amount of data of the third data block read from the memory is smaller, which can reduce the time, thereby improving the firmware updating efficiency.

[0013] Optionally, before determining whether the first check code of the i-th first data block is the same as the second check code of the i-th second data block, the method further comprises: obtaining first header information of the new firmware and second header information of the old firmware; and determining that the new firmware and the old firmware are different firmware according to the first header information and the second header information.

[0014] In the embodiments of the present application, when it is determined that the new firmware and the old firmware are not the same version of firmware according to the header information of the new firmware and the header information of the old firmware, the old firmware in the memory is updated to the new firmware, which can reduce unnecessary firmware updating operations.

[0015] Optionally, the determining that the new firmware and the old firmware are different firmware according to the first header information and the second header information comprises: when firmware numbers in the first header information and the second header information are inconsistent, obtaining a fifth check code of the first header information from the first header information; and determining that a sixth check code of the second header information is the same as the fifth check code.

[0016] In the embodiments of the present application, before the firmware updating, it is determined that the new firmware and the old firmware are not the same version of firmware, and it is determined that the new firmware is a safe firmware according to the fifth check code and the sixth check code, which can ensure that the new firmware used for updating is a safe firmware, avoid updating an abnormal firmware to the memory, and thereby improve the reliability of the firmware updating process.

[0017] Optionally, the replacing the i th second data block in the memory with the i th first data block comprises: when the number of the second data blocks to be replaced is less than a preset number threshold, replacing the i th second data block in the memory with the i th first data block; and when the number of the second data blocks to be replaced is greater than or equal to the preset number threshold, replacing the old firmware in the memory with the new firmware.

[0018] In the embodiments of the present application, when the number of the second data blocks to be replaced is less than a preset number threshold, the first data block is used to replace the second data blocks in the memory, and when the number of the second data blocks to be replaced is greater than or equal to the preset number threshold, the new firmware is used to replace the entire old firmware in the memory. Thus, when the difference between the new firmware and the old firmware is large, the firmware updating process can be simplified.

[0019] In a second aspect, a firmware updating apparatus is provided, and the apparatus comprises: a obtaining module, configured to obtain a first check code of a plurality of first data blocks, the plurality of first data blocks being sequentially divided by a new firmware; and obtain a second check code of a plurality of second data blocks, the plurality of second data blocks being sequentially divided by an old firmware previously stored in a memory, a data length of the second data blocks and a data length of the first data blocks being N times of a minimum erasing unit of the memory, N being an integer greater than 0; a determining module, configured to determine whether the first check code of an i th first data block is same as the second check code of an i th second data block, i being an integer greater than 0 a replacing module, configured to, if not, replace the i th second data block in the memory with the i th first data block, so as to update the old firmware in the memory to the new firmware.

[0020] In a third aspect, an apparatus is provided, and the apparatus comprises: a memory, configured to store program code; a processor, configured to invoke and run the program code from the memory, so that the apparatus executes the method in any possible implementation manner of the first aspect.

[0021] In a fourth aspect, a program product is provided, and the program product comprises program code, which, when executed on an apparatus, causes the apparatus to execute the method in any possible implementation manner of the first aspect.

[0022] In a fifth aspect, a readable storage medium is provided, and the readable storage medium stores program code, which, when executed on an apparatus, causes the apparatus to execute the method in any possible implementation manner of the first aspect. BRIEF DESCRIPTION OF DRAWINGS

[0023] Figure 1 is an application scenario of a firmware updating method provided by an embodiment of the present application; Figure 2 is a step flowchart of a firmware updating method provided by an embodiment of the present application; Figure 3 shows a comparison diagram of a firmware updating method provided by an embodiment of the present application and a firmware updating method in the related art; Figure 4 is a flowchart of another firmware updating method provided by an embodiment of the present application; Figure 5 is a flowchart of a firmware updating process provided by an embodiment of the present application; Figure 6 is a flowchart of a firmware recovery method provided by an embodiment of the present application; Figure 7 is a diagram of a firmware loading method provided by an embodiment of the present application; Figure 8 is a structural diagram of a firmware updating device provided by an embodiment of the present application; Figure 9 is a structural diagram of a device provided by an embodiment of the present application. DETAILED DESCRIPTION

[0024] The technical solutions in the present application will be described in detail below with reference to the drawings. In the description of the embodiments of the present application, unless otherwise specified, " / " represents the meaning of or, for example, A / B can represent A or B: "and / or" in the text only describes the association relationship of the associated objects, which means that there can be three relationships, for example, A and / or B, which means that there are three cases of A alone, A and B together, and B alone. In addition, in the description of the embodiments of the present application, "multiple" means two or more than two.

[0025] Hereinafter, the terms "first" and "second" are used for descriptive purposes only, and cannot be understood as implying or suggesting relative importance or implicitly indicating the number of indicated technical features. Therefore, the features defined with "first" and "second" can explicitly or implicitly include one or more features.

[0026] Firmware is the basis for ensuring the stable and reliable operation of hardware devices. The updating frequency of firmware is generally low, but when updating the firmware, the firmware also needs to be backed up, so the efficiency during the updating process needs to be ensured to avoid low efficiency affecting the normal use of the hardware device.

[0027] It is a common practice to first erase the old version of firmware (hereinafter referred to as old firmware) stored in the non-volatile memory (hereinafter referred to as memory) and then write the new version of firmware (hereinafter referred to as new firmware) into the memory. Both erasing and writing take a certain amount of time, so the efficiency of the entire firmware updating process is low.

[0028] To solve the above technical problems, the present application provides a firmware updating method, which uses the difference idea to compare the difference between the new firmware and the old firmware when updating the firmware, and only replaces the difference between the new firmware and the old firmware, so that the firmware in the memory is consistent with the new firmware, thereby realizing the replacement of the new firmware to the old firmware. Since only the difference between the new firmware and the old firmware is replaced, only a small amount of data in the memory needs to be erased and a small amount of data needs to be written into the memory, so the entire updating process takes a shorter time and the updating efficiency is higher.

[0029] Referring to Figure 1 , Figure 1 is a schematic diagram of an application scenario of a firmware updating method provided by an embodiment of the present application. The scenario includes a microcontroller unit (MCU) 101, a controller 102 and a first memory 103, and one or more second memories 104. The controller is, for example, a hardware device that needs firmware support, such as a central processing unit (CPU), an electronic control unit (ECU), a timing controller (TCON), etc., but is not limited thereto.

[0030] The first memory 103 and the second memory 104 can be non-volatile memories such as erasable programmable read-only memories (EPROM) and flash memories. The first memory 103 and the second memory 104 are both used to store the firmware of the controller 102, the firmware in the first memory 103 is used to support the normal operation of the controller 102, and the firmware in the second memory 104 is used as a backup to support the operation of the controller 102 when the firmware in the first memory 103 is faulty.

[0031] The microcontroller unit 101 is used to control the updating of the firmware, that is, when the firmware needs to be updated, the microcontroller unit 101 can obtain the new firmware and write the new firmware into the first memory 103 and the second memory 104.

[0032] The firmware updating method provided by the application can be executed by the micro control unit 101, and the micro control unit 101 can update the firmware in the first memory 103 by using the method, and can also update the firmware in each second memory 104 by using the method. The firmware in the second memory 104 is updated, that is, the backup of the firmware is realized.

[0033] It should be understood that, Figure 1 For example, the application scenario of the firmware updating method provided by the application can include but is not limited to Figure 1 as shown.

[0034] Referring to Figure 2 , Figure 2 is a step flow chart of a firmware updating method provided by an embodiment of the application. The execution subject of the method can be the MCU shown in the figure, or other hardware with the same type of function. The method can include the following steps: Figure 1 Step 201, obtaining a first check code of a plurality of first data blocks.

[0035] The plurality of first data blocks are obtained by sequentially dividing the new firmware, the new firmware refers to the firmware that needs to be written into the memory, the data length of the first data block is N times of the minimum erasing unit of the memory, the minimum erasing unit refers to the minimum data block that can be erased at one time in the erasing operation, and N is an integer greater than 0.

[0036] In an embodiment, when the firmware needs to be updated, the host computer can first divide the data in the new firmware into a plurality of data blocks (hereinafter referred to as first data blocks) in a fixed data length, the data length is N times of the minimum erasing unit of the memory, and a fixed check code (hereinafter referred to as first check code) is generated according to each data block.

[0037] For example, the data length of the data included in the new firmware is 128K, the minimum erasing unit of the memory is 4K, the length of each first data block can be set to 4K (that is, the data length of the first data block is 1 times of the minimum erasing unit), and the data in the new firmware is divided in the order from front to back, that is, every 4K data is divided into a first data block, and the new firmware can be divided into 32 first data blocks. It should be noted that when the minimum erasing unit of the memory is 4K, the data length of each first data block can also be 8K, 16K, 24K, etc. integer times of the minimum erasing unit.

[0038] ​For each first data block, the host computer can generate a first check code of the first data block according to the data in the first data block. The first check code is used to check whether other data blocks are the same as the first data block. When the check code (the check code is generated according to the data block, and the generation method of the check code is the same as the first check code) of a certain data block is the same as the first check code, it can be determined that the data in the data block is the same as the first data block.

[0039] For example, for each first data block, the host computer can generate a first check code of the first data block according to the data in the first data block by using a cyclic redundancy check (CRC) method. In this way, a first check code of each first data block can be obtained. It should be understood that the check method can be CRC, CRC8, CRC16, and CRC32, and of course, a hash check method can also be used to generate a first check code of each first data block.

[0040] In this embodiment, the host computer can add the first check code of each first data block to the firmware header information (hereinafter referred to as first header information) of the new firmware, and package the first header information and the new firmware as a firmware data packet. The MCU can obtain the firmware data packet of the new firmware from the host computer, and after obtaining the firmware data packet, analyze the firmware data packet to obtain the first check code of each first data block from the firmware data packet.

[0041] For example, the entire firmware data can include two parts of data, the first part of data is the first header information, and the second part of data is the new firmware itself. In addition to the first check code of each first data block, the first header information can also include some other related information of the new firmware. For example, the data length of the first header information can be 86 bytes. From front to back in the first header information, the first 4 bytes are used to store the firmware header of the new firmware, the next 4 bytes are used to store the firmware number of the new firmware, the next 4 bytes are used to store the starting address of the new firmware in the memory, the next 4 bytes are used to store the firmware length of the new firmware, the next 4 bytes are used to store the check code of the first header information, the next 64 bytes are used to store 32 first check codes of 32 first data blocks, the next 2 bytes are used to store the check code of the new firmware itself, and the next 10 bytes are reserved.

[0042] In the new firmware, the firmware header is used to indicate that the data packet is a firmware data packet of the new firmware. The check code of the first header information can be generated based on the firmware header by using the check method in the above example, or based on the firmware header, the firmware number, the starting address, and the firmware length by using the check method in the above example. For convenience of distinction, the check code of the first header information is referred to as the fifth check code.

[0043] The check code of the new firmware can be generated based on the data in the new firmware by using the check method exemplified above. For the sake of distinction, the check code of the new firmware is referred to as a third check code below.

[0044] In the first header information, the 32 first check codes can be sequentially stored in the 64 bytes according to the order of the 32 first data blocks in the new firmware. In this way, the MCU can determine the first data block to which each first check code belongs according to the storage position of the first check code in the first header information.

[0045] The MCU is in communication connection with the host computer. During the firmware updating process, the MCU can obtain the firmware data packet of the new firmware from the host computer, parse the firmware data packet, obtain the first header information from the firmware data packet, and obtain the 32 first check codes from the first header information.

[0046] As described above, the 32 first check codes are sequentially stored in the 64 bytes of the first header information. The MCU can determine the first data block corresponding to each first check code according to the storage position of each first check code in the first header information. For example, the first check code of the first first data block is the first first check code of the 32 first check codes, and the first first check code extracted by the MCU from the first header information is the first check code of the first first data block. The first check code of the 16th first data block is the 16th first check code of the 32 first check codes, and the 16th first check code extracted by the MCU from the first header information is the first check code of the 16th first data block.

[0047] In step 202, the second check codes of the plurality of second data blocks are obtained.

[0048] The plurality of second data blocks are sequentially divided from the old firmware pre-stored in the memory, and the data length of the second data block is the same as that of the first data block. For example, when the data length of the first data block in the new firmware is 4K, the data length of the second data block in the old firmware is also 4K.

[0049] It can be understood that the new firmware and the old firmware are two different versions of firmware of the same hardware device, and therefore the firmware length of the old firmware is the same as that of the new firmware, for example, both are 128K. Similar to the new firmware, the old firmware is sequentially divided into a plurality of second data blocks when being written into the memory, and a second check code of each second data block is generated. The data length of the second data block is the same as that of the first data block, and therefore the number of the second data blocks is the same as that of the first data blocks.

[0050] The firmware data packet storing the old firmware in the memory includes two parts of data, one part is the firmware header information of the old firmware (hereinafter referred to as second header information), and the other part is the old component itself. Similar to the first header information, the second header information stores the firmware header and firmware number of the old firmware, the starting address of the old firmware in the memory, the data length of the old firmware, the check code of the firmware header of the old firmware (hereinafter referred to as the sixth check code), and the 32 second check codes of the 32 second data blocks, and the check code of the old firmware itself (hereinafter referred to as the fourth check code) and the reserved position of 10 bytes.

[0051] Among them, the first check code and the second check code are generated by the same check method, for example, when the first check code is generated by CRC16, the second check code is also generated by CRC16. Similarly, the third check code and the fourth check code are generated by the same check method, and the fifth check code and the sixth check code are generated by the same check method.

[0052] It can be understood that the first check code of the first data block and the second check code of the second data block are generated by the same check method, so when the first check code of the first data block and the second check code of the second data block are the same, the first data block and the second data block are the same data block.

[0053] In this embodiment, during the firmware updating process, the MCU can read the second check code of each second data block stored in the second header information from the memory to obtain a plurality of second check codes.

[0054] Step 203, determine whether the first check code of the i-th first data block is the same as the second check code of the i-th second data block.

[0055] Step 204, if not, replace the i-th second data block in the memory with the i-th first data block to update the old firmware in the memory to the new firmware.

[0056] Among them, i is an integer greater than 0.

[0057] In one embodiment, the MCU can read all the first check codes from the first header information at one time, and read all the second check codes from the second header information at one time. As mentioned above, the position of the first check code in the first header information indicates the position of the first data block to which the first check code belongs in the new firmware, and the position of the second check code in the second header information indicates the position of the second data block to which the second check code belongs in the old firmware. Based on this, after obtaining the plurality of first check codes and the plurality of second check codes, for the 1st first check code obtained from the first header information, the 1st first check code obtained from the first header information is compared with the 1st second check code obtained from the second header information. If the two check codes are the same, it is determined that the 1st first data block in the new firmware is the same as the 1st second data block in the old firmware. If the two check codes are different, it is determined that the 1st first data block in the new firmware is different from the 1st second data block in the old firmware.

[0058] Similarly, for the 2nd first check code obtained from the first header information, the 2nd first check code obtained from the first header information is compared with the 2nd second check code obtained from the second header information. If the two check codes are the same, it is determined that the 2nd first data block in the new firmware is the same as the 2nd second data block in the old firmware. If the two check codes are different, it is determined that the 2nd first data block in the new firmware is different from the 2nd second data block in the old firmware.

[0059] By analogy, all different first data blocks and second data blocks located at the same position, and all same first data blocks and second data blocks located at the same position, can be determined from the plurality of first data blocks of the new firmware and the plurality of second data blocks of the old firmware.

[0060] For different first data blocks and second data blocks, the MCU can erase the second data block stored in the memory and write the first data block to the position after erasing, so as to replace the second data block in the memory with the first data block. For the same first data block and second data block, the MCU does not process. In this way, the second data block different from the first data block at the same position in the memory can be replaced. After replacing all different second data blocks, the firmware in the memory is consistent with the new firmware, and the purpose of updating the old firmware in the memory to the new firmware can be achieved.

[0061] In one embodiment, the MCU sequentially obtains each first check code from the first header information and each second check code from the second header information. After obtaining the first check code from the first header information and the second check code from the second header information, the obtained first check code and second check code are compared. If the two check codes are the same, the first second data block in the old firmware stored in the memory is erased first, and then the first first data block in the new firmware is written into the position of the first second data block.

[0062] Then, the second first check code in the first header information and the second second check code in the second header information are obtained, and the two obtained check codes are compared. If the two check codes are the same, the second second data block in the old firmware stored in the memory is erased first, and then the second first data block in the new firmware is written into the position of the second second data block.

[0063] By analogy, after the comparison of all the first check codes and the second check codes is completed, the second data blocks different from the first data blocks in the same position in the memory can be replaced. After all the different second data blocks are replaced, the firmware in the memory is consistent with the new firmware, and the purpose of updating the old firmware in the memory to the new firmware can be achieved.

[0064] After the old firmware in the memory is updated to the new firmware, the second header information in the memory can be erased first, and then the first header information of the new firmware is written into the position of the second header information.

[0065] Generally, the new firmware and the old firmware are generally two consecutive versions of firmware, and therefore there are some same first data blocks and second data blocks between the new firmware and the old firmware. When the firmware is updated by using the firmware updating method provided in the present application, the part of the second data blocks and the part of the first data blocks do not need to be erased and written, respectively, and a large amount of time can be saved.

[0066] In actual application, more than 50% of the data between the new firmware and the old firmware is the same. Taking the new firmware and the old firmware with a data length of 128K as an example, about 12-15 first data blocks and second data blocks are the same. Therefore, when the firmware is updated by using the method provided in the present application, about 37%-46% of the second data blocks do not need to be erased, and about 37%-46% of the first data blocks do not need to be written, and a large amount of time can be saved.

[0067] In the embodiment of the present application, in the firmware updating process, the new firmware is sequentially divided into a plurality of first data blocks, the first check code of each first data block is generated, and the second check code of each second data block in the old firmware is obtained. When the first check code of the i th first data block is different from the second check code of the i th second data block, the i th first data block is used to replace the i th second data block in the memory. In this way, the old firmware in the memory can be updated to the new firmware. In the method, in the firmware updating process, only part of the second data blocks of the old firmware stored in the memory need to be erased, and the corresponding part of the first data blocks in the new firmware is written into the memory. Compared with the prior art of erasing the entire old firmware and writing the entire new firmware into the memory, a large amount of time can be saved, thereby improving the firmware updating efficiency.

[0068] Referring to Figure 3 , Figure 3 A comparison diagram of the firmware updating method provided by the embodiment of the present application and the firmware updating method in the related art is shown. Figure 3 The horizontal coordinate is the data length of the firmware, and the unit is KB. The vertical coordinate is the time, and the unit is millisecond. The curve 302 is a relationship curve of the data length of the firmware and the time used in the updating process when the firmware is updated by using the method provided by the present application. The curve 301 is a relationship curve of the data length of the firmware and the time used in the updating process when the firmware is updated by using the firmware updating method in the related art. It can be known from the comparison of the curve 301 and the curve 302 that, for any data length of the firmware, the method provided by the embodiment of the present application uses less time than the method in the related art.

[0069] Table 1

[0070] Referring to Table 1, Table 1 is a comparison diagram of the time used by the firmware updating method provided by the embodiment of the present application and the time used by the firmware updating method in the related art when the data length of the firmware is 128K and the memory used for backup is two flash.

[0071] In the second column of data, the time used in each operation in the updating process when the firmware is updated by using the firmware updating method provided by the present application is shown. In the third column of data, the time used in each operation in the updating process when the firmware is updated by using the firmware updating method in the related art is shown.

[0072] As shown in Table 1, in the firmware backup process, the method provided in the application and the method in the related art have little difference in the time used in the firmware check and CRC check process. In the erasing and writing stage, since the method provided in the application needs to erase and write less data in the firmware backup process, the method provided in the application consumes less time, while the method in the related art consumes more time. Therefore, in the whole firmware update process, the total time used by the method provided in the application is 1906.7 milliseconds, while the total time used by the method in the related art is 2869.7 milliseconds, and the total time used by the method provided in the application is much less than that of the method in the related art.

[0073] Optionally, replacing the i-th second data block in the memory with the i-th first data block comprises: When the number of the second data blocks to be replaced is less than the preset number threshold, replacing the i-th second data block in the memory with the i-th first data block; When the number of the second data blocks to be replaced is greater than or equal to the preset number threshold, replacing the old firmware in the memory with the new firmware.

[0074] In an implementation, after obtaining the plurality of first check codes and the plurality of second check codes, the number of the second data blocks to be replaced can be determined according to the plurality of first check codes and the plurality of second check codes. When the number is less than the preset number threshold, it is determined that the difference between the new firmware and the old firmware is small, and the first data block is used to replace the second data block at the corresponding position in the memory. On the contrary, when the number is greater than or equal to the preset number threshold, it is determined that the difference between the new firmware and the old firmware is large, and the old firmware in the memory is directly erased, and then the new firmware is written into the memory.

[0075] In combination with the above example, after the MCU obtains the firmware data packet of the new firmware from the host computer, 32 first check codes are extracted from the firmware data packet, and 32 second check codes are read from the memory. Then, each first check code and the corresponding second check code are compared in turn to determine the different first data block and the second data block. After comparing all the first check codes and the second check codes, all the second check codes different from the corresponding first check codes can be determined, and the second data block to which the second check code belongs is the second data block to be replaced.

[0076] Then, the MCU counts the number of second check codes that are different from the corresponding first check code, which is the number of all second data blocks to be replaced. In the case that the number is less than a preset number threshold, each corresponding second data block in the memory is erased, and the corresponding first data block is written into the position where the corresponding second data block is located, so as to update the old firmware in the memory to the new firmware. At the same time, the second header information in the memory is erased, and the first header information is written into the position where the second header information is located.

[0077] On the contrary, in the case that the number is greater than or equal to the preset number threshold, all second data blocks in the memory are directly erased, that is, the entire old firmware is erased. After the entire old firmware is erased, the new firmware is written into the memory. At the same time, the second header information in the memory is erased, and the first header information is written into the position where the second header information is located.

[0078] In the embodiments of the present application, when the number of second data blocks to be replaced is less than the preset number threshold, the first data block is used to replace the second data block in the memory, and when the number of second data blocks to be replaced is greater than or equal to the preset number threshold, the new firmware is used to replace the entire old firmware in the memory. Therefore, when the difference between the new firmware and the old firmware is large, the firmware update process can be simplified.

[0079] Optionally, after the i th first data block is used to replace the i th second data block in the memory, the method can further include: When the third check code is different from the fourth check code, the i th first data block is used to replace the i th second data block in the memory again, the third check code is generated according to the new firmware, and the fourth check code is generated according to the firmware currently stored in the memory.

[0080] As described above, the third check code is generated according to the new firmware and can be stored in the first header information. After all second data blocks that are different from the corresponding first data block are erased and the corresponding first data block is written into the memory, the MCU can extract the third check code from the first header information. At the same time, the MCU can generate the fourth check code based on the firmware currently stored in the memory.

[0081] Then, the MCU compares the third check code with the fourth check code. If the third check code is the same as the fourth check code, it indicates that the firmware currently stored in the memory is the same as the new firmware, and the firmware in the memory has been updated to the new firmware. If the third check code is different from the fourth check code, it indicates that an abnormality occurs when the new firmware is written into the memory. At this time, step 204 can be executed again to erase the second data block that is different from the first data block again and write the first data block into the memory, so as to update the firmware in the memory again.

[0082] It can be understood that the comparison of the third check code and the fourth check code is different, that is, it is determined whether the new firmware has an exception when being written into the memory. When the third check code and the fourth check code are the same, it is determined that the new firmware has no exception when being written into the memory, and the firmware in the updated memory has no exception and can be normally used. When the third check code and the fourth check code are different, it is determined that the new firmware has an exception when being written into the memory, and the firmware in the updated memory has an exception and cannot be normally used.

[0083] In the embodiment of the application, when the third check code and the fourth check code are different, the ith first data block is used to replace the ith second data block in the memory again, and the new firmware is written into the memory again when the new firmware is written with an error, so as to improve the reliability in the firmware updating process.

[0084] Optionally, the using of the ith first data block to replace the ith second data block in the memory again includes: determining a replacement number of times, the replacement number of times being the number of times of using the ith first data block to replace the ith second data block; in a case where the replacement number of times is less than a preset number of times, using the ith first data block to replace the ith second data block in the memory; in a case where the replacement number of times is greater than or equal to the preset number of times, erasing the firmware currently stored in the memory, and writing the new firmware into the memory.

[0085] In an implementation, when starting to update the firmware in the memory, the replacement number of times is initialized to 0, and the replacement number of times is increased by 1 after each execution of the steps 203-204. Then, the third check code and the fourth check code are compared, and in a case where the third check code and the fourth check code are the same, it is determined that the new firmware is updated, and the updating process is ended.

[0086] In a case where the third check code and the fourth check code are different, it is determined that the current new firmware updating fails, and at this time, it is determined whether the replacement number of times at the current time is greater than or equal to the preset number of times. If the replacement number of times is less than the preset number of times, the steps 203-204 are executed again, that is, the ith first data block is used to replace the ith second data block in the memory again, and the replacement number of times is increased by 1. On the contrary, if the replacement number of times at the current time is greater than or equal to the preset number of times, the entire firmware currently stored in the memory is erased, and after the entire firmware currently stored in the memory is erased, the entire new firmware is written into the memory.

[0087] In the case that the replacement times are less than the preset times, the i-th first data block is used to replace the i-th second data block in the memory, and in the case that the replacement times are greater than or equal to the preset times, the whole new firmware is written into the memory after erasing the whole firmware currently stored in the memory. It can be understood that when the firmware is updated for multiple times by using steps 201-204, if the update still fails, the whole firmware in the memory is erased and the new firmware is written into the memory.

[0088] In the embodiment of the present application, after the first data block is used to replace the corresponding second data block for multiple times, if it is determined that the new firmware is still not successfully written into the memory, the firmware in the memory is erased and the new firmware is written into the memory, which can improve the success rate in the firmware update process.

[0089] Optionally, before the i-th first data block is used to replace the i-th second data block in the memory again when the third check code is different from the fourth check code, the method can further comprise: generating a third check code according to the first data block used to replace the second data block; generating a fourth check code according to the third data block after being replaced in the memory.

[0090] The first data block used to replace the second data block refers to the target data to be written into the memory, that is, the first data block different from the second data block at the same position. The third data block after being replaced refers to the actual data written into the memory, that is, the data written into the position of the erased second data block.

[0091] In an embodiment, when checking whether the firmware currently stored in the memory is the same as the new firmware, a third check code can be generated according to one or more first data blocks written into the memory, a fourth check code can be generated according to one or more third data blocks actually stored in the memory after the first data blocks are written, if the third check code is the same as the fourth check code, it is determined that the firmware currently stored in the memory is the same as the new firmware, and the new firmware is successfully updated to the memory. Otherwise, it is determined that the new firmware fails to be updated.

[0092] For example, in the update process, if it is determined that the 1st first data block is different from the 1st second data block, the 5th first data block is different from the 5th second data block, and the 20th first data block is different from the 20th second data block, the MCU can obtain the 1st first data block, the 5th first data block and the 20th first data block, combine the 1st first data block, the 5th first data block and the 20th first data block into one data in the order of the positions of the 1st first data block, the 5th first data block and the 20th first data block in the new firmware, and generate a third check code based on the data by using a CRC16 check method.

[0093] After step 204 is performed, the MCU can acquire the third data block currently stored at the position of the erased first second data block from the memory, acquire the third data block currently stored at the position of the erased fifth second data block, acquire the third data block currently stored at the position of the erased twentieth second data block, sequentially combine the three third data blocks into one data according to the positions of the three third data blocks in the memory, and generate a fourth check code based on the data by using a CRC16 check method.

[0094] Then, the third check code and the fourth check code are compared. If the third check code is the same as the fourth check code, it is determined that the firmware currently stored in the memory is the same as the new firmware, the new firmware is successfully updated into the memory, and the updating process is ended. Otherwise, it is determined that the new firmware fails to be updated, and steps 203-204 are performed again.

[0095] In actual application, the third check code is generated according to the first data block to be written into the memory, the fourth check code is generated according to the third data block actually written into the memory, and whether the actual data written into the memory is the same as the target data to be written is determined by comparing the two check codes. Thus, whether the firmware currently stored in the memory is the same as the new firmware can be determined accurately.

[0096] In the embodiment of the application, the third check code is generated according to the first data block used in the firmware updating process, the fourth check code is generated according to the third data block actually written into the memory, and whether the actual data written into the memory is the same as the target data to be written is determined by comparing the two check codes. Thus, whether the firmware currently stored in the memory is the same as the new firmware can be determined accurately. Moreover, compared with reading the entire firmware from the memory to generate the fourth check code, the amount of data of the third data block read from the memory is smaller, time can be saved, and thus the firmware updating efficiency can be improved.

[0097] Optionally, before determining whether the first check code of the ith first data block is the same as the second check code of the ith second data block, the method can further include: acquiring first header information of the new firmware and second header information of the old firmware; determining that the new firmware and the old firmware are different firmware according to the first header information and the second header information.

[0098] In an implementation, before the old firmware in the memory is updated, the first header information of the new firmware can be acquired first, the second header information of the old firmware is acquired, whether the new firmware and the old firmware are the same firmware is determined according to the first header information and the second header information, if they are the same firmware, the process is ended. If they are different firmware, steps 201-204 are performed to update the new firmware into the memory.

[0099] As described above, after the MCU obtains the firmware data packet of the new firmware from the host computer, the MCU can extract the firmware number of the new firmware from the first header information included in the firmware data packet, read the firmware number of the old component from the memory, and then compare the two firmware numbers. If the two firmware numbers are the same, it is determined that the new firmware and the old firmware are the same version of firmware, and the firmware in the memory does not need to be updated, and the updating process is directly ended. On the contrary, if it is determined that the two firmware numbers are not the same firmware number, it is determined that the new firmware and the old firmware are not the same version of firmware, and steps 201-204 are executed to update the old firmware in the memory to the new firmware.

[0100] In the embodiment of the application, when it is determined according to the header information of the new firmware and the header information of the old firmware that the new firmware and the old firmware are not the same version of firmware, the old firmware in the memory is updated to the new firmware, which can reduce unnecessary firmware updating operations.

[0101] Optionally, determining that the new firmware and the old firmware are different firmware according to the first header information and the second header information comprises: When the firmware number in the first header information is inconsistent with the firmware number in the second header information, obtaining a fifth check code of the first header information from the first header information; determining that a sixth check code of the second header information is the same as the fifth check code.

[0102] In an embodiment, when the firmware number of the new firmware is inconsistent with the firmware number of the old firmware, it can be determined that the new firmware and the old firmware are not the same version of firmware; and when the fifth check code of the first header information and the sixth check code of the second header information are the same, it is determined that the first header information of the new firmware and the header information of the old firmware are the same, and the new firmware is a safe new firmware.

[0103] In combination with the above example, after the MCU obtains the firmware data packet of the new firmware from the host computer, the MCU can extract the firmware number and the fifth check code of the new firmware from the first header information in the firmware data packet, and read the firmware number and the sixth check code of the old firmware from the memory. Then, it is first determined whether the firmware number of the new firmware is the same as the firmware number of the old firmware, and in the case that the firmware number of the new firmware is different from the firmware number of the old firmware, it is further determined whether the fifth check code is the same as the sixth check code, and in the case that the fifth check code is the same as the sixth check code, it is determined that the new firmware is a safe firmware. At this time, steps 201-204 can be executed to update the old firmware in the memory to the new firmware.

[0104] On the contrary, in the case that the firmware number of the new firmware is different from that of the old firmware and the fifth check code is different from the sixth check code, it is determined that the new firmware is abnormal firmware, at this time, prompt information is directly outputted, the user is prompted that the new firmware is abnormal firmware, and the firmware updating process is ended. In the case that the firmware number of the new firmware is same as that of the old firmware, prompt information is outputted, the user is prompted that the new firmware and the old firmware are the same version of firmware, and the firmware updating process is ended.

[0105] In the embodiment of the application, before the firmware updating, it is determined that the new firmware and the old firmware are not the same version of firmware, and the new firmware is determined to be safe firmware according to the fifth check code and the sixth check code, which can guarantee that the new firmware used for updating is safe firmware, avoid updating abnormal firmware to the memory, and thus the reliability of the firmware updating process can be improved.

[0106] For the convenience of understanding, the method provided by the application is introduced below in the firmware updating process in the firmware backup.

[0107] Referring to Figure 4 , Figure 4 is a flowchart of another firmware updating method provided by the embodiment of the application. The method is applied to the MCU shown in Figure 1 , the number of the second memories is 2, and the method can include the following steps: Step 401, the firmware data packet of the new firmware is acquired.

[0108] Step 402, whether to update the firmware is determined according to the first header information and the second header information.

[0109] In the embodiment, in the firmware updating process, the MCU first acquires the firmware data packet of the new firmware from the host computer, then acquires the firmware number and the fifth check code of the new firmware from the first header information included in the firmware data packet, and reads the firmware number and the sixth check code of the old firmware from the first memory. If the firmware number of the new firmware is different from that of the old firmware and the fifth check code is same as the sixth check code, step 403 is executed. If the firmware number of the new firmware is same as that of the old firmware or the fifth check code is different from the sixth check code, the firmware updating process is directly ended.

[0110] Step 403, the new firmware is updated to the first second memory.

[0111] Step 404, whether the updating is successful.

[0112] In this embodiment, in the firmware updating process, the MCU first updates the new firmware into the first memory, and in the updating process, the method shown in steps 201-204 is used to update the new firmware into the first memory. After each updating is completed, the third check code and the fourth check code are obtained, and in the case that the third check code is the same as the fourth check code, step 405 is executed. In the case that the third check code is different from the fourth check code, step 403 is returned to be executed.

[0113] In this embodiment, in the firmware updating process, the MCU first updates the new firmware into the first memory, and in the updating process, the method shown in steps 201-204 is used to update the new firmware into the first memory. After each updating is completed, the third check code and the fourth check code are obtained, and in the case that the third check code is the same as the fourth check code, step 405 is executed. In the case that the third check code is different from the fourth check code, step 403 is returned to be executed.

[0114] Alternatively, after the firmware data packet is obtained, the MCU can start timing, and in the process of repeatedly executing step 403, if the timing duration reaches the preset duration, it is determined that the firmware updating is timed out, and the firmware updating process is ended. When the timing duration is less than the preset duration, step 403 is returned to be executed until the new firmware is updated into the first memory.

[0115] Step 405, updating the new firmware into the second memory.

[0116] Step 406, whether the updating is successful.

[0117] In this embodiment, in the firmware updating process, the MCU first updates the new firmware into the first memory, and in the updating process, the method shown in steps 201-204 is used to update the new firmware into the first memory. After each updating is completed, the third check code and the fourth check code are obtained, and in the case that the third check code is the same as the fourth check code, step 405 is executed. In the case that the third check code is different from the fourth check code, step 403 is returned to be executed.

[0118] In this embodiment, in the firmware updating process, the MCU first updates the new firmware into the first memory, and in the updating process, the method shown in steps 201-204 is used to update the new firmware into the first memory. After each updating is completed, the third check code and the fourth check code are obtained, and in the case that the third check code is the same as the fourth check code, step 405 is executed. In the case that the third check code is different from the fourth check code, step 403 is returned to be executed.

[0119] Alternatively, after the firmware data packet is obtained, the MCU can start timing, and in the process of repeatedly executing step 405, if the timing duration reaches the preset duration, it is determined that the firmware updating is timed out, and the firmware updating process is ended. When the timing duration is less than the preset duration, step 405 is returned to be executed until the new firmware is updated into the second memory.

[0120] See Figure 5 , Figure 5 This is a flowchart illustrating a firmware update process provided in an embodiment of this application. Figure 5 for Figure 4 The specific execution process of steps 403 and 405 is as follows: Figure 5 As shown, the method includes the following steps: Step 501: Obtain the i-th first checksum from the first header information.

[0121] Step 502: Obtain the i-th second checksum from the second header information.

[0122] Step 503: Determine whether the two obtained verification codes are the same.

[0123] Step 504: Record the current i.

[0124] Step 505, i plus 1.

[0125] In this embodiment, during the execution of steps 403 and 405, the MCU first initializes i to 1, then obtains the i-th first checksum from the first header information of the new firmware, and obtains the i-th second checksum from the second header information stored in the memory. Then, the two obtained checksums are compared. If the two checksums are the same, step 505 is executed; if the two checksums are different, step 504 is executed. In step 504, the current i is recorded. In step 505, i is incremented by 1 to obtain the updated i, and then step 506 is executed.

[0126] Step 506: Determine whether i is greater than the maximum value.

[0127] After obtaining the updated i, the MCU determines whether the updated i is greater than the maximum value. For example, when the number of the first data block and the second data block is 32, it determines whether the updated i is greater than 32. If the updated i is greater than 32, steps 507 and 508 are executed; if the updated i is less than or equal to 32, it returns to execute step 501.

[0128] Step 507: Erase the i-th second data block of the record.

[0129] Step 508: Write the i-th first data block of the record.

[0130] In this embodiment, when the updated i is determined to be greater than 32, for each recorded i, the i-th second data block recorded in the memory is first erased, and then the i-th first data block is written to the location of the i-th second data block. After processing all recorded i, the firmware in the memory can be made consistent with the new firmware. Afterwards, the MCU can execute step 404 or step 406.

[0131] Referring to Figure 6 , Figure 6 is a flowchart of a firmware recovery method provided by an embodiment of the present application. The method is applied to a controller as shown in Figure 1 The number of the second memories is 2, and the method can include the following steps: Step 601, monitoring whether the firmware in the first memory is faulty.

[0132] In combination with Figure 1 , the controller periodically detects whether the firmware in the first memory is faulty during operation, and after detecting that the firmware in the first memory is faulty, step 602 is performed.

[0133] Step 602, determining whether the firmware in the first second memory is faulty.

[0134] After the controller determines that the firmware in the first memory is faulty, it first determines whether the firmware in the first second memory is faulty, and in the case that the firmware in the first second memory is not faulty, step 605 is performed. In the case that the firmware in the first second memory is faulty, step 603 is performed.

[0135] Step 603, switching to the second second memory.

[0136] Step 604, determining whether the firmware in the second second memory is faulty.

[0137] After the controller determines that the firmware in the first second memory is faulty, it first determines whether the firmware in the second second memory is faulty, and in the case that the firmware in the second second memory is faulty, the firmware loading flow ends. In the case that the firmware in the second second memory is not faulty, step 605 is performed.

[0138] Step 605, loading the backup firmware from the second memory.

[0139] In the case that the firmware in the first second memory is not faulty, the controller loads the backup firmware from the first second memory. In the case that the firmware in the first second memory is faulty and the firmware in the second second memory is not faulty, the controller loads the backup firmware from the second second memory.

[0140] Referring to Figure 7 , Figure 7 is a flowchart of a firmware loading method provided by an embodiment of the present application. As Figure 7As shown, the scenario includes a micro control unit 701, a controller 704, a first memory 705, a second memory 702 and a third memory 703, and a selection circuit composed of a first resistor 706, a second resistor 707, a first switch element 708 and a second switch element 709. The second memory 702 and the third memory 703 are used to store backup firmware of the controller 704, and the first memory 705 is used to store firmware required during operation of the controller 704.

[0141] As shown, the micro control unit 701 is communicatively connected with the first controller 705, the second memory 702 and the third memory 703 respectively. The controller 704 is communicatively connected with the first controller 705, the second memory 702 and the third memory 703 respectively. During firmware updating, the micro control unit 701 updates firmware into the first controller 705, the second memory 702 and the third memory 703. Figure 7

[0142] The first switch element 708 is a PNP transistor, the collector of the first switch element 708 is connected with a power supply end VCC through the first resistor 706, the emitter of the first switch element 708 is connected with a pin of the controller 704, and the base of the first switch element 708 is connected with a pin of the micro control unit 701. The second switch element 709 is an NPN transistor, the collector of the second switch element 709 is connected with the power supply end VCC through the second resistor 707, the emitter of the second switch element 709 is connected with a pin of the controller 704, and the base of the second switch element 709 is connected with a pin of the micro control unit 701. Meanwhile, the collector of the first switch element 708 is connected with an enable end of the second memory 702, and the collector of the second switch element 709 is connected with an enable end of the third memory 703.

[0143] When the firmware in the first memory 705 fails, the controller 704 pulls down the voltage of the emitters of the first switch element 708 and the second switch element 709. At this time, if it is required to load the backup firmware in the second memory 702 into the first memory 705, the micro control unit 701 can pull up the voltage of the bases of the first switch element 708 and the second switch element 709, so that the first switch element 708 is turned on and the second switch element 709 is turned off.

[0144] At this time, when the first switch element 708 is turned on and the second switch element 709 is turned off, the voltage of the enable end of the second memory 702 is pulled up, the second memory 702 is in an active state, the voltage of the enable end of the third memory 703 is pulled down, the third memory 703 is in an inactive state, and the controller downloads the backup firmware from the second memory 702 and stores the downloaded firmware into the first memory 705.

[0145] ​Similarly, if the firmware backed up in the third memory 703 needs to be loaded into the first memory 705, the micro control unit 701 can pull the voltage of the base of the first switch element 708 and the second switch element 709 low, so that the first switch element 708 is turned off and the second switch element 709 is turned on. At this time, the first switch element 708 is turned off, the second switch element 709 is turned on, the voltage of the enable end of the second memory 702 is pulled low, the second memory 702 is in an invalid state, the voltage of the enable end of the third memory 703 is pulled high, the third memory 703 is in an active state, and the controller downloads the backed up firmware from the third memory 703 and stores the downloaded firmware into the first memory 705.

[0146] Similarly, when the firmware needs to be written into the second memory 702, the selection circuit can also be controlled to make the second memory 702 active and the third memory 703 invalid, and the micro control unit 701 updates the new firmware into the second memory 702. When the firmware needs to be written into the third memory 703, the selection circuit can also be controlled to make the second memory 702 invalid and the third memory 703 active, and the micro control unit 701 updates the new firmware into the third memory 703. The firmware updating method can refer to the above examples, and this embodiment will not be described here.

[0147] It can be understood that during the firmware updating process, the selection circuit can control one of the plurality of memories for storing the backup firmware to be active and the other memories to be invalid, and update the firmware in the active memory. During the firmware loading process, the selection circuit can control one of the plurality of memories for storing the backup firmware to be active and the other memories to be invalid, and load the backup firmware from the active memory.

[0148] Table 2

[0149] Referring to Table 2, when the data length of the firmware is 128K and the memory for backup is two flash, Figure 7 The time used by the firmware loading method shown in the table is compared with the time used by the firmware loading method in the related art.

[0150] The second column of data is the time used by the firmware loading method shown in the table, and the third column of data is the time used by the firmware loading method in the related art. Figure 7 The time used by the firmware loading method shown in the table is compared with the time used by the firmware loading method in the related art.

[0151] As shown in Table 2, during the firmware loading process, the time difference between the method provided in this application and the methods in related technologies in checking the firmware and downloading backup firmware is not significant and can be ignored. However, the time difference is more obvious when switching Flash. The method provided in this application consumes less time, while the methods in related technologies take longer.

[0152] Therefore, the total time taken by the method provided in this application during the entire firmware loading process is 1283.7 milliseconds, while the time taken by the methods in related technologies is 1501.2 milliseconds. The time taken by the method provided in this application is much shorter than that of the methods in related technologies. Since the total firmware loading time is relatively short, the speed advantage brought by hardware switching is more obvious. Taking 128K as an example, the loading speed is improved by approximately 15%.

[0153] The above text combined Figures 1 to 3 The firmware update method provided in the embodiments of this application is described in detail below; the following will be combined with Figure 4 and Figure 5 The apparatus embodiments of this application are described in detail below. It should be understood that the apparatus in the embodiments of this application can perform the various methods described in the foregoing embodiments of this application, that is, the specific working processes of the various products described below can be referred to the corresponding processes in the foregoing method embodiments.

[0154] See Figure 8 , Figure 8 This is a schematic diagram of the structure of a firmware update device provided in an embodiment of this application. Figure 8 As shown, the firmware update device 800 may include: The acquisition module 801 is used to acquire the first check code of multiple first data blocks, which are obtained by the new firmware in sequence; and to acquire the second check code of multiple second data blocks, which are obtained by the old firmware pre-stored in the memory in sequence, wherein the data length of the second data block and the data length of the first data block are N times the minimum erase unit of the memory, where N is an integer greater than 0. The determining module 802 is used to determine whether the first checksum of the i-th first data block is the same as the second checksum of the i-th second data block, where i is an integer greater than 0. Replacement module 803 is configured to, if not, replace the i-th second data block in the memory with the i-th first data block to update the old firmware in the memory to the new firmware.

[0155] Optionally, the replacing module 803 is further configured to, after the i th first data block is used to replace the i th second data block in the memory, and when the third check code is different from the fourth check code, replace the i th second data block in the memory with the i th first data block again, wherein the third check code is generated according to the new firmware, and the fourth check code is generated according to the firmware currently stored in the memory.

[0156] Optionally, the replacing module 803 is specifically configured to determine a replacement number, the replacement number being the number of times that the i th first data block is used to replace the i th second data block; when the replacement number is less than a preset number, replace the i th second data block in the memory with the i th first data block; and when the replacement number is greater than or equal to the preset number, erase the firmware currently stored in the memory, and write the new firmware into the memory.

[0157] Optionally, the replacing module 803 is further configured to, before the i th first data block is used to replace the i th second data block in the memory again when the third check code is different from the fourth check code, generate the third check code according to the first data block used to replace the second data block; and generate the fourth check code according to the third data block in the memory after being replaced.

[0158] Optionally, the determining module 802 is further configured to, before determining whether the first check code of the i th first data block is the same as the second check code of the i th second data block, acquire first header information of the new firmware and second header information of the old firmware; and determine that the new firmware and the old firmware are different firmware according to the first header information and the second header information.

[0159] Optionally, the determining module 802 is specifically configured to, when a firmware number in the first header information is inconsistent with a firmware number in the second header information, acquire a fifth check code of the first header information from the first header information; and determine that a sixth check code of the second header information is the same as the fifth check code.

[0160] Optionally, the replacing module 803 is specifically configured to, when the number of the second data blocks to be replaced is less than a preset number threshold, replace the i th second data block in the memory with the i th first data block; and when the number of the second data blocks to be replaced is greater than or equal to the preset number threshold, replace the old firmware in the memory with the new firmware.

[0161] Referring to Figure 9 , Figure 9 is a structural schematic diagram of an apparatus provided by an embodiment of the present application. As shown inFigure 9 As shown in the figure, the device 900 includes a memory 901 and a processor 902, wherein the memory 901 stores program code 9011, and the processor 902 is configured to invoke and execute the program code 9011 to execute a firmware updating method.

[0162] In addition, the embodiment of the present application also protects a firmware updating device, which can include a memory and a processor, wherein the memory stores program code, and the processor is configured to invoke and execute the program code to execute a firmware updating method provided by the embodiment of the present application.

[0163] The embodiment can divide the device into functional modules according to the above method examples, for example, corresponding to each functional module, or two or more functions can be integrated into one processing module, and the integrated module can be realized in the form of hardware. It should be noted that the division of modules in the embodiment is illustrative, and is only a logical function division, and another division mode can be used in actual implementation.

[0164] In the case of dividing each functional module corresponding to each function, the device can also include a determination module, a replacement module, and a control module, etc. It should be noted that all related contents of each step involved in the above method embodiments can be referred to the function description of the corresponding functional module, which will not be repeated here.

[0165] It should be understood that the device provided by the embodiment is used to execute the above-mentioned firmware updating method, and thus the same effect as the above-mentioned implementation method can be achieved.

[0166] In the case of using an integrated unit, the device can include a determination module and a control module. When the device is applied to a device, the processing module can be used to control and manage the actions of the device. The storage module can be used to support the device to execute related program codes, etc.

[0167] The processing module can be a processor or a vehicle body setting module, which can realize or execute various exemplary logical blocks, modules and circuits shown in combination with the disclosure of the present application. The processor can also be a combination of computing functions, such as one or more microprocessor combinations, combinations of digital signal processing and microprocessors, etc., and the storage module can be a memory.

[0168] The embodiment also provides a readable storage medium, which stores program code, and when the program code runs on a device, the device executes the above-mentioned related method steps to realize the firmware updating method provided by the above-mentioned embodiment.

[0169] The embodiment also provides a program product, which, when running on a device, causes the device to perform the above related steps to implement the firmware updating method provided by the above embodiment.

[0170] The device, the readable storage medium, the program product or the chip provided by the embodiment are used to execute the corresponding method provided above, and thus the beneficial effects thereof can refer to the beneficial effects of the corresponding method provided above, which will not be repeated here.

[0171] Through the description of the above embodiments, those skilled in the art can understand that, for the convenience and brevity, only the above division of functional modules is taken as an example, and in actual application, the above functions can be completed by different functional modules according to needs, that is, the internal structure of the device is divided into different functional modules to complete all or part of the functions described above.

[0172] In the embodiments provided by the present application, it should be understood that the disclosed device and method can be implemented in other ways. For example, the device embodiments described above are only schematic, and the division of the modules or units is only a logical function division, and there can be another division way in actual implementation. For example, a plurality of units or components can be combined or integrated into another device, or some features can be ignored or not executed. In addition, the displayed or discussed mutual couplings or direct couplings or communication connections between different units, or the indirect coupling or communication connection through some interfaces, devices or units, can be implemented in electrical, mechanical or other forms.

[0173] The above only describes the specific embodiments of the present application, but the protection scope of the present application is not limited thereto, and any person skilled in the art can easily think of changes or replacements within the technical range disclosed by the present application, which should be covered by the protection scope of the present application. Therefore, the protection scope of the present application should be subject to the protection scope of the claims.

Claims

1. A firmware update method, characterized in that, The method includes: Obtain the first checksum of multiple first data blocks, wherein the multiple first data blocks are obtained sequentially by the new firmware; Obtain the second checksum of multiple second data blocks, which are obtained by sequentially dividing old firmware pre-stored in the memory. The data length of the second data block and the data length of the first data block are N times the minimum erase unit of the memory, where N is an integer greater than 0. Determine whether the first checksum of the i-th first data block is the same as the second checksum of the i-th second data block, where i is an integer greater than 0. If not, the i-th second data block in the memory is replaced with the i-th first data block to update the old firmware in the memory to the new firmware.

2. The method as described in claim 1, characterized in that, After replacing the i-th second data block in the memory with the i-th first data block, the method further includes: When the third check code and the fourth check code are different, the i-th second data block in the memory is replaced again with the i-th first data block. The third check code is generated according to the new firmware, and the fourth check code is generated according to the firmware currently stored in the memory.

3. The method as described in claim 2, characterized in that, The step of replacing the i-th second data block in the memory with the i-th first data block again includes: The number of replacements is determined as the number of times the i-th first data block replaces the i-th second data block; If the number of replacements is less than a preset number, the i-th first data block in the memory is used to replace the i-th second data block. If the number of replacements is greater than or equal to the preset number, the new firmware is written to the memory after erasing the currently stored firmware in the memory.

4. The method as described in claim 2, characterized in that, Before replacing the i-th second data block in the memory with the i-th first data block again when the third checksum and the fourth checksum are different, the method further includes: The third checksum is generated based on the first data block used when replacing the second data block; The fourth check code is generated based on the replaced third data block in the memory.

5. The method as described in claim 1, characterized in that, Before determining whether the first checksum of the i-th first data block is the same as the second checksum of the i-th second data block, the method further includes: Obtain the first header information of the new firmware and the second header information of the old firmware; Based on the first header information and the second header information, it is determined that the new firmware is different from the old firmware.

6. The method as described in claim 5, characterized in that, The step of determining that the new firmware and the old firmware are different firmware based on the first header information and the second header information includes: When the firmware number in the first header information is inconsistent with the firmware number in the second header information, the fifth verification code of the first header information is obtained from the first header information; It is determined that the sixth check code of the second header information is the same as the fifth check code.

7. The method according to any one of claims 1-6, characterized in that, The step of replacing the i-th second data block in the memory with the i-th first data block includes: When the number of the second data blocks to be replaced is less than a preset threshold, the i-th first data block is used to replace the i-th second data block in the memory; When the number of the second data blocks to be replaced is greater than or equal to the preset number threshold, the new firmware replaces the old firmware in the memory.

8. A firmware update device, characterized in that, The device includes: The acquisition module is used to acquire the first check code of multiple first data blocks, which are obtained by the new firmware in sequence; and to acquire the second check code of multiple second data blocks, which are obtained by the old firmware pre-stored in the memory in sequence, wherein the data length of the second data block and the data length of the first data block are N times the minimum erase unit of the memory, where N is an integer greater than 0. The determining module is used to determine whether the first checksum of the i-th first data block is the same as the second checksum of the i-th second data block, where i is an integer greater than 0. A replacement module is configured to, if not, replace the i-th second data block in the memory with the i-th first data block to update the old firmware in the memory to the new firmware.

9. A device, characterized in that, The device includes: Memory, used to store program code; A processor for calling and running the program code from the memory, causing the device to perform the method as described in any one of claims 1 to 7.

10. A readable storage medium, characterized in that, The readable storage medium stores program code that, when executed on the device, causes the device to perform the method as described in any one of claims 1 to 7.