Firmware upgrading method and electronic equipment

By backing up and updating the address information of the partition table during the firmware upgrade process, the problem of unreliable firmware upgrade in the existing technology is solved, and reliable firmware upgrades under arbitrary changes in the partition address space are realized to ensure that the equipment can still be upgraded normally in unexpected situations.

CN120276747APending Publication Date: 2025-07-08FUZHOU ROCKCHIP SEMICON
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202510289813.5
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-03-12
Publication Date
2025-07-08

AI Technical Summary

Technical Problem

In the prior art, the firmware upgrade method requires multiple upgrades and is unreliable when the existing technology does not rely on external storage media, which can easily lead to the equipment becoming bricked, especially when the equipment is difficult to get close to in special scenarios, the reliability of the upgrade process cannot be guaranteed.

Method used

In the boot bootloader firmware of the device, read the upgrade instruction information from the boot communication partition, and back up the boot bootloader firmware partition and the boot communication partition to the preset storage area of the firmware data to be upgraded. Build the backup element information and write it to the preset location of the current partition table to ensure that the start address of the boot bootloader firmware partition in the partition table is consistent with the address in the backup element information to achieve reliable firmware upgrade.

Benefits of technology

When the partition address space changes arbitrarily, ensure the reliability of the firmware upgrade process, avoid the equipment becoming bricked due to unexpected situations such as power failure, and ensure that the upgrade can continue to be completed after power-on.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120276747A_ABST
    Figure CN120276747A_ABST
Patent Text Reader

Abstract

The invention relates to a firmware upgrading method and electronic equipment. The method comprises the following steps: reading upgrade instruction information from a first preset position in a boot communication partition in boot program firmware; backing up a bootstrap program firmware partition and a bootstrap communication partition behind a preset storage area of firmware data to be upgraded, constructing backup area element information, and writing the backup area element information into a second preset position in the bootstrap communication partition of the current partition table; on the basis of the backup area element information, bootstrap program backup firmware and bootstrap communication backup partition mirror image data are started to update a current partition table; pointing an initial address of a bootstrap firmware partition in the current partition table to an initial address of bootstrap backup firmware in the backup area element information, and setting the partition size of the bootstrap firmware partition in the current partition table as the size of the bootstrap backup firmware in the backup area element information, and starting bootstrap program firmware and upgrading the new partition table, and taking the new partition table as the current partition table.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of embedded devices, and particularly to a method for upgrading firmware and an electronic device. Background Art

[0002] In the prior art, the method for upgrading firmware with changes in the partition table through the Over-The-Air (OTA) interface usually requires that some partitions of the partition table remain unchanged. For some firmware upgrade methods that support arbitrary changes in the partition table address space, it usually requires relying on external storage media (such as a USB flash drive or an SD card). However, many devices do not come with a standard external storage media. Especially for some devices deployed in special scenarios, it is usually difficult or impossible for people to access them after deployment, and thus it is impossible to configure an external storage media. But for some firmware upgrade methods that do not require an external storage media and can also support arbitrary changes in the partition table address space, it usually requires multiple upgrades and cannot guarantee the complete reliability of the upgrade process. Once an accident occurs at some special nodes, it will cause the device to become bricked. Summary of the Invention

[0003] The present invention provides a method for upgrading firmware and an electronic device, which can improve the reliability of firmware upgrade under the condition of arbitrary changes in the address space of all partitions.

[0004] In one aspect of the present invention, a method for upgrading firmware is provided. The method includes: in the bootloader firmware of the device, reading upgrade instruction information from a first preset position in the boot communication partition; backing up the bootloader firmware partition and the boot communication partition to a preset storage area behind the firmware data to be upgraded, constructing backup area meta-information, and writing the constructed backup area meta-information to a second preset position in the boot communication partition of the current partition table; updating the current partition table based on the backup area meta-information, the bootloader backup firmware, and the boot communication backup partition image data; and pointing the start address of the bootloader firmware partition in the current partition table to the start address of the bootloader backup firmware in the backup area meta-information, and setting the partition size of the bootloader firmware partition in the current partition table to the size of the bootloader backup firmware in the backup area meta-information, so as to upgrade the bootloader firmware and the new partition table, and using the new partition table as the current partition table.

[0005] In another aspect of the present invention, an electronic device is provided. The electronic device includes a memory configured to store an executable program; and a processor configured to execute the program to perform the above method for upgrading firmware.

[0006] According to the present invention, the bootloader firmware partition and the boot communication partition are backed up to a preset storage area behind the firmware data to be upgraded. The built backup area meta-information is written to a second preset position in the boot communication partition of the current partition table. The starting address of the bootloader firmware partition in the current partition table is pointed to the starting address of the bootloader backup firmware in the backup area meta-information. The partition size of the bootloader firmware partition in the current partition table is set to the size of the bootloader backup firmware in the backup area meta-information, so as to upgrade the bootloader firmware and the new partition table. This ensures that the starting address of the bootloader firmware partition in the current partition table is the same as the starting address of the bootloader backup firmware in the backup area meta-information, so as to ensure that before the upgrade of the bootloader firmware and the new partition table is completed, the bootloader firmware is always loaded from the bootloader backup firmware. Even if an accident occurs during the upgrade of the bootloader firmware, it will not affect the bootloader backup firmware. Furthermore, it can ensure that in any case of an accident (such as power failure) during the upgrade process, the device will never become bricked and can always continue to complete the upgrade after being powered on again. Thus, in the case of any arbitrary change in all partition address spaces, the reliability of the firmware upgrade is effectively improved. BRIEF DESCRIPTION OF THE DRAWINGS

[0007] Figure 1 It is a flowchart of the steps of the method for upgrading firmware according to an embodiment of the present invention; Figure 2 It is a schematic flowchart of the method for upgrading firmware according to an embodiment of the present invention; Figure 3 It is a schematic structural diagram of an electronic device according to an embodiment of the present invention. DETAILED DESCRIPTION OF THE EMBODIMENTS

[0008] To describe in detail the technical content, achieved objectives and effects of the present invention, the following is described in conjunction with the embodiments and with reference to the accompanying drawings.

[0009] In the prior art, although there are firmware upgrade methods that do not require an external storage medium and can also support arbitrary changes in the partition table address space, such methods usually require multiple upgrades and cannot guarantee the complete reliability of the upgrade process. Once an accident occurs at some special nodes, the device will become bricked.

[0010] To solve at least the above technical problems, the present disclosure provides a method for upgrading firmware. According to an embodiment of the present disclosure, the bootloader firmware partition and the boot communication partition are backed up to a preset storage area behind the firmware data to be upgraded, the built backup area meta information is written to a second preset position in the boot communication partition of the current partition table, the start address of the bootloader firmware partition in the current partition table is pointed to the start address of the bootloader backup firmware in the backup area meta information, and the partition size of the bootloader firmware partition in the current partition table is set to the size of the bootloader backup firmware in the backup area meta information to upgrade the bootloader firmware and the new partition table. In this way, it is ensured that the start address of the bootloader firmware partition in the current partition table is the same as the start address of the bootloader backup firmware in the backup area meta information, so as to ensure that before the upgrade of the bootloader firmware and the new partition table is completed, the bootloader is always loaded from the bootloader backup firmware. Even if an accident occurs during the upgrade of the bootloader firmware, it will not affect the bootloader backup firmware. Furthermore, it can ensure that in any case of an accident (such as power failure) during the upgrade process, the device will never become bricked and can always continue to complete the upgrade after being powered on again. Thus, in the case of any arbitrary change in the address space of all partitions, the reliability of firmware upgrade is effectively improved.

[0011] Embodiments of the present disclosure require that the address spaces of the bootloader firmware partition and the boot communication partition in the partition table are located before the address spaces of various system firmware partitions and the preset user data partition. At the same time, it is required that the preset user data partition is the last partition in the partition table and is non-encrypted. Finally, it is required that the length of the boot communication partition in the new partition table is not less than the length of the boot communication partition in the old partition table. The boot communication partition is a bare partition used for communication between the system, the bootloader firmware, and the recovery mode firmware.

[0012] In some embodiments, a unified upgrade file with a preset name is constructed based on the firmware upgrade package, and the constructed unified upgrade file is saved to the preset unified upgrade file path in the preset user data partition, and the unified upgrade file meta-information is saved to the preset location in the boot communication partition. Calculate the address space corresponding to the first storage area of the firmware data to be upgraded, and store the unified upgrade file with the preset name in the preset unified upgrade file path in the preset user data partition according to the unified upgrade file meta-information, and save the meta-information of the first storage area of the firmware data to be upgraded to the preset location in the boot communication partition. In addition, calculate the address space corresponding to the second storage area of the firmware data to be upgraded according to the meta-information of the first storage area of the firmware data to be upgraded and the new partition table, copy the data in the first storage area of the firmware data to be upgraded to the second storage area of the firmware data to be upgraded, and save the meta-information of the second storage area of the firmware data to be upgraded to the preset location in the boot communication partition. Through the above operations, the first storage area of the firmware data to be upgraded is positioned before the preset user data partition in the old partition table, so that the unified upgrade file in the preset user data partition can be read smoothly. Then, the second storage area of the firmware data to be upgraded is positioned within the address space of the preset user data partition in the new partition table, so that subsequent firmware upgrade can be realized according to the meta-information of the second storage area of the firmware data to be upgraded and the unified upgrade file stored in the second storage area of the firmware data to be upgraded, without relying on an external storage medium.

[0013] In some embodiments, after backing up the bootloader firmware partition and the boot communication partition to the second storage area of the firmware data to be upgraded, save the backup area meta-information to the preset locations in the boot communication partition and the boot communication backup partition. Before upgrading the bootloader firmware and the new partition table, ensure that the start address of the bootloader firmware partition in the current partition table is the same as the start address of the bootloader backup firmware in the backup area meta-information, so as to ensure that before the upgrade of the bootloader firmware and the new partition table is completed, the bootloader firmware is always loaded from the bootloader backup firmware, so that an accident during the upgrade of the bootloader firmware will not affect the bootloader backup firmware, and it can be ensured that in any case of an accident (such as power failure) during the upgrade process, the device will not become bricked and can always continue the upgrade after being powered on again.

[0014] In the following, the technical solutions according to the present disclosure will be described with reference to specific embodiments and in conjunction with the accompanying drawings.

[0015] Figure 1 is a flowchart showing a method 100 for upgrading firmware according to an embodiment of the present disclosure. Refer to Figure 1 , the method 100 includes the following steps 102 to step 108.

[0016] In step 102, in the device's bootloader firmware, read the upgrade instruction information from the first preset position in the boot communication partition.

[0017] In some embodiments, before step 102, the method 100 may further include: obtaining a firmware upgrade package to be upgraded, and saving the firmware upgrade package to the preset firmware upgrade package path in the preset user data partition; if the firmware upgrade package under the preset firmware upgrade package path in the preset user data partition is legal, constructing the unified upgrade file according to the firmware upgrade package in the preset firmware upgrade package path, and saving the unified upgrade file to the preset unified upgrade file path in the preset user data partition; constructing unified upgrade file meta-information, and saving it to the sixth preset position in the boot communication partition; writing the first-stage upgrade instruction to the first preset position in the boot communication partition; and restarting the device.

[0018] In this way, after constructing the unified upgrade file and the unified upgrade file meta-information, write the first-stage upgrade instruction to the first preset position in the boot communication partition and restart the device, then the first-stage upgrade can be performed to enter the subsequent firmware upgrade process.

[0019] In step 104, back up the bootloader firmware partition and the boot communication partition behind the preset storage area of the firmware to be upgraded, construct backup area meta-information, and write the constructed backup area meta-information to the second preset position in the boot communication partition of the current partition table.

[0020] In some embodiments, read the backup area meta-information from the second preset position in the boot communication partition; check the legality of the backup area meta-information, the bootloader backup firmware, and the boot communication backup partition image data to obtain a first check result; if the first check result is all legal, perform the step of updating the current partition table based on the backup area meta-information, the bootloader backup firmware, and the boot communication backup partition image data; if the first check result is not all legal, back up the bootloader firmware partition according to the free area address space meta-information, and obtain a new partition table from the second storage area; if the address space of the boot communication partition changes in the new partition table, back up the boot communication partition according to the free area address space meta-information, and construct backup area meta-information; write the constructed backup area meta-information to the second preset position in the boot communication partition of the current partition table; and write the updated free area address space meta-information to the fifth preset position in the boot communication partition of the current partition table.

[0021] In this way, the legality of the backup area meta-information, the bootloader backup firmware, and the boot communication backup partition image data is checked. When all are legal, the current partition table is directly updated based on the backup area meta-information, the bootloader backup firmware, and the boot communication backup partition image data. When not all are legal, the backup area meta-information is reconstructed to ensure the reliability of the firmware upgrade.

[0022] In step 106, the current partition table is updated based on the backup area meta-information, the bootloader backup firmware, and the boot communication backup partition image data.

[0023] In some embodiments, the starting address of the bootloader firmware partition in the current partition table is pointed to the starting address of the bootloader backup firmware in the backup area meta-information; the partition size of the bootloader firmware partition in the current partition table is set to the size of the bootloader backup firmware in the backup area meta-information; if the backup flag of the boot communication partition in the backup area meta-information is true, the starting address of the boot communication partition in the current partition table is pointed to the starting address of the boot communication backup partition in the backup area meta-information, and the partition size of the boot communication partition in the current partition table is set to the size of the boot communication backup partition in the backup area meta-information; the updated current partition table is written into the address space corresponding to the partition table to complete the upgrade of the updated current partition table; and the updated current partition table is used as the current partition table.

[0024] In this way, based on the backup area meta-information, the bootloader backup firmware, and the boot communication backup partition image data, the upgrade of the updated current partition table is achieved, and the firmware upgrade can also be achieved when the address spaces of all partitions in the new partition table change.

[0025] In some embodiments, after step 106, the method 100 may further include: writing the fourth-stage upgrade instruction into a first preset position in the boot communication partition of the current partition table; and executing the fourth-stage upgrade instruction. In this way, the fourth-stage upgrade instruction can be executed after the third-stage upgrade instruction is executed, and the fourth stage is entered.

[0026] In step 108, the starting address of the bootloader firmware partition in the current partition table is pointed to the starting address of the bootloader backup firmware in the backup area meta-information, and the partition size of the bootloader firmware partition in the current partition table is set to the size of the bootloader backup firmware in the backup area meta-information to upgrade the bootloader firmware and the new partition table, and the new partition table is used as the current partition table.

[0027] In some embodiments, the backup area meta information is read from a second preset position in the boot communication partition, and the legality of the backup area meta information, the bootloader backup firmware, and the boot communication backup partition image data is checked to obtain a second check result. If the second check result is all legal, the partition table is obtained from the address space where the device partition table is located as the current partition table. If the start address of the bootloader firmware partition in the current partition table is different from the start address of the bootloader backup firmware in the backup area meta information, the start address of the bootloader firmware partition in the current partition table is pointed to the start address of the bootloader backup firmware in the backup area meta information, and the partition size of the bootloader firmware partition in the current partition table is set to the size of the bootloader backup firmware in the backup area meta information. If the backup flag of the boot communication partition in the backup area meta information is true, the start address of the boot communication partition in the current partition table is pointed to the start address of the boot communication backup partition in the backup area meta information, and the partition size of the boot communication partition in the current partition table is set to the size of the boot communication backup partition in the backup area meta information. The updated current partition table is written into the address space corresponding to the partition table to complete the upgrade of the updated current partition table. The updated current partition table is used as the current partition table. A new partition table is obtained from the second storage area. The bootloader firmware image data to be upgraded is obtained from the second storage area and written into the address space corresponding to the bootloader firmware partition in the new partition table. If the backup flag of the boot communication partition in the backup area meta information is true, the boot communication backup partition image data is upgraded to the address space corresponding to the boot communication partition in the new partition table according to the backup area meta information. The new partition table is written into the address space corresponding to the partition table to complete the upgrade of the new partition table. The new partition table is used as the current partition table. A fifth-stage upgrade instruction is written into a first preset position in the boot communication partition of the current partition table. The fifth-stage upgrade instruction is executed. And if the second check result is not all legal, the firmware upgrade process is exited.

[0028] In this way, it is ensured that the start address of the bootloader firmware partition in the current partition table is the same as the start address of the bootloader backup firmware in the backup area meta information. Before the upgrade of the bootloader firmware and the new partition table is completed, the bootloader is always loaded from the bootloader backup firmware. An accident during the upgrade of the bootloader firmware will not affect the bootloader backup firmware, and the upgrade can always continue after a power-on reset, thereby improving the reliability and stability of the firmware upgrade.

[0029] In some embodiments, the method 100 may further include: if the upgrade instruction information includes a first-stage upgrade instruction, obtaining a unified upgrade file from a preset unified upgrade file path in a preset user data partition; calculating an address space corresponding to a first storage area of the firmware data to be upgraded, and storing the unified upgrade file in the first storage area according to the address space corresponding to the first storage area; constructing meta information of the first storage area of the firmware data to be upgraded, and writing the meta information of the first storage area into a third preset position in the boot communication partition; writing a second-stage upgrade instruction into a first preset position in the boot communication partition; and executing the second-stage upgrade instruction.

[0030] In some embodiments, the method 100 may further include: if the upgrade instruction information includes a second-stage upgrade instruction, calculating an address space corresponding to a second storage area of the firmware data to be upgraded according to the meta information of the first storage area and the new partition table, and copying the data in the first storage area to the second storage area according to the address space corresponding to the second storage area; constructing meta information of the second storage area of the firmware data to be upgraded, and writing the meta information of the second storage area into a fourth preset position in the boot communication partition; constructing meta information of an address space of the free area, and writing the meta information of the address space of the free area into a fifth preset position in the boot communication partition; writing a third-stage upgrade instruction into a first preset position in the boot communication partition; and executing the third-stage upgrade instruction.

[0031] In some embodiments, the method 100 may further include: if the upgrade instruction information includes a third-stage upgrade instruction, backing up the bootloader firmware partition and the boot communication partition behind the second storage area of the firmware data to be upgraded.

[0032] In some embodiments, the method 100 may further include: if the upgrade instruction information includes a fourth-stage upgrade instruction, pointing the start address of the bootloader firmware partition in the current partition table to the start address of the bootloader backup firmware in the backup area meta information.

[0033] In this way, when executing the first-stage upgrade instruction, the unified upgrade file is obtained from the preset unified upgrade file path of the preset user data partition, the address space corresponding to the first storage area of the firmware data to be upgraded is calculated, and the unified upgrade file is stored in the first storage area. The metadata of the first storage area for constructing the firmware data to be upgraded is written to the third preset position in the boot communication partition. When executing the second-stage upgrade instruction, the address space corresponding to the second storage area of the firmware data to be upgraded is calculated according to the metadata of the first storage area and the new partition table, and the data in the first storage area is copied to the second storage area. The metadata of the constructed second storage area is written to the fourth preset position in the boot communication partition. In this way, the first storage area of the firmware data to be upgraded can be located before the preset user data partition in the old partition table, and the unified upgrade file in the preset user data partition can be successfully read. Then, the second storage area is located within the address space of the preset user data partition in the new partition table. Subsequently, the firmware upgrade can be implemented according to the metadata of the second storage area and the unified upgrade file stored in the second storage area. Even if the address spaces of all partitions in the new partition table change, there is no need to rely on an external storage medium.

[0034] In some embodiments, before calculating the address space corresponding to the first storage area of the firmware data to be upgraded and storing the unified upgrade file in the first storage area according to the address space corresponding to the first storage area, it may further include: reading the unified upgrade file metadata from the fifth preset position in the boot communication partition, and verifying the unified upgrade file according to the unified upgrade file metadata to obtain a verification result. Calculating the address space corresponding to the first storage area of the firmware data to be upgraded and storing the unified upgrade file in the first storage area according to the address space corresponding to the first storage area includes: if the verification result is passed, calculating the address space corresponding to the first storage area of the firmware data to be upgraded and storing the unified upgrade file in the first storage area according to the address space corresponding to the first storage area.

[0035] In this way, the unified upgrade file is verified first, and after the verification is passed, the unified upgrade file is stored in the first storage area to ensure the security of subsequent upgrades.

[0036] In some embodiments, the method 100 may further include: if the upgrade instruction information includes the fifth-stage upgrade instruction, obtaining the partition table as the current partition table from the address space where the device partition table is located; sequentially obtaining, from the second storage area, other firmware image data except the new partition table and the bootloader firmware image data to be upgraded, and writing the other firmware image data into the address space corresponding to the firmware partition in the current partition table; writing all preset erasable partition instructions into a first preset position in the boot communication partition of the current partition table; and executing all the preset erasable partition instructions.

[0037] In this way, when executing the fifth-stage upgrade instruction, other firmware except the new partition table and the bootloader firmware to be upgraded is upgraded, so that when the address spaces of all partitions in the new partition table change, firmware upgrade can be reliably realized without relying on an external storage medium.

[0038] In some embodiments, the method 100 may further include: if the upgrade instruction information includes all the preset erasable partition instructions, performing an erasing operation on all preset erasable partitions; if there is an erasable partition with a file system, re-creating the file system; sequentially clearing the upgrade instruction information in the first preset position in the boot communication partition, the unified upgrade file meta-information in the sixth preset position, the first storage area meta-information of the firmware to be upgraded in the third preset position, the second storage area meta-information of the firmware to be upgraded in the fourth preset position, the free area address space meta-information in the fifth preset position, and the backup area meta-information in the second preset position; and restarting the device to enter the upgraded system.

[0039] In this way, after all upgrades are completed, an erasing operation is performed on all preset erasable partitions, the information in the boot communication partition is cleared, and the device is restarted to enter the upgraded system, ensuring the smooth completion of the upgrade.

[0040] In some embodiments, the address spaces of the bootloader firmware partition and the boot communication partition in the partition table are located before the address spaces of various system firmware partitions (such as super or system) and the preset user data partition (such as data). At the same time, the preset user data partition is the last partition in the partition table and is not encrypted, and the length of the boot communication partition in the new partition table is not less than the length of the boot communication partition in the old partition table. The boot communication partition is a bare partition used for communication between the system, the bootloader firmware, and the recovery mode firmware.

[0041] Hereinafter, application scenarios of the method and device for upgrading firmware according to embodiments of the present invention will be described by way of examples.

[0042] Figure 2 is a flowchart showing a method for upgrading firmware according to an embodiment of the present invention. As Figure 2 shown, the method includes the following steps 201 to step 233.

[0043] In step 201, a firmware upgrade package is constructed, which includes a partition table file with a preset name and all firmware image files to be upgraded.

[0044] In some embodiments, the firmware image file to be upgraded uses the partition name corresponding to the image file as the prefix of the name of the firmware image file. For example, the prefix "uboot" of the firmware image file uboot.img represents that the partition name corresponding to the image file is uboot.

[0045] In step 202, the firmware upgrade package to be upgraded is obtained and saved to the preset firmware upgrade package path in the preset user data partition.

[0046] In step 203, if the firmware upgrade package under the preset firmware upgrade package path in the preset user data partition is illegal, the firmware upgrade package is deleted and the firmware upgrade process is exited.

[0047] In step 204, if the firmware upgrade package under the preset firmware upgrade package path in the preset user data partition is legal, a unified upgrade file is constructed according to the firmware upgrade package in the preset firmware upgrade package path and saved to the preset unified upgrade file path in the preset user data partition.

[0048] In some embodiments, the unified upgrade file consists of a header of a preset size and a file body. The header of the unified upgrade file consists of a preset magic number and a file item list. The file item list is a list composed of file items, and each file item is composed of a partition name, the offset address of the data of the file to be upgraded in the unified upgrade file, the length of the file to be upgraded, the digital digest algorithm type, and the digital digest value. Each file in the firmware upgrade package corresponds to a file item, and the file item corresponding to the partition table is called the partition table file item, and the file item corresponding to the bootloader firmware image file is called the bootloader firmware file item.

[0049] Step 204 specifically includes the following (1) to (3).

[0050] (1) Set the magic number of the header of the unified upgrade file to an error magic number different from the preset magic number of the unified upgrade file. Create an empty unified upgrade file with a preset name under the preset unified upgrade file path in the preset user data partition, and write the header of the unified upgrade file at the starting position of the unified upgrade file.

[0051] (2)Read each file in sequence from the firmware upgrade packages under the preset firmware upgrade package path of the preset user data partition according to the preset order.

[0052] For each file read, first allocate an unused file entry as the current file entry starting from the starting position of the file entry list in the unified upgrade file header, use the previous used file entry of the current file entry as the previous file entry of the current file entry, and use the current file read from the firmware upgrade package as the file to be upgraded corresponding to the current file entry; then set the current file entry according to the file to be upgraded corresponding to the current file entry and the previous file entry of the current file entry, and write all the content in the file to be upgraded corresponding to the current file entry to the offset address of the data of the file to be upgraded in the unified upgrade file in the current file entry, and the written data size is the length of the file to be upgraded in the current file entry.

[0053] Step (2) specifically includes the following (2-1) to (2-6).

[0054] (2-1)Set the partition name in the current file entry as the prefix of the name of the file to be upgraded corresponding to the current file entry.

[0055] (2-2)If the current file entry is the first file entry in the file entry list of the unified upgrade file header, set the offset address of the data of the file to be upgraded in the unified upgrade file in the current file entry as the size of the unified upgrade file header; otherwise, set the offset address of the data of the file to be upgraded in the unified upgrade file in the current file entry as: the offset address of the data of the file to be upgraded in the previous file entry of the current file entry + the length of the file to be upgraded in the previous file entry of the current file entry.

[0056] (2-3)Set the length of the file to be upgraded in the current file entry as the size of the file to be upgraded corresponding to the current file entry.

[0057] (2-4)Set the digital digest algorithm type in the current file entry as the preset digital digest algorithm.

[0058] (2-5)Calculate the digital digest of the file to be upgraded corresponding to the current file entry according to the digital digest algorithm type in the current file entry, and save the calculated digital digest to the digital digest value in the current file entry.

[0059] (2-6)Write all the content in the file to be upgraded corresponding to the current file entry to the offset address of the data of the file to be upgraded in the unified upgrade file in the current file entry, and the written data size is the length of the file to be upgraded in the current file entry.

[0060] (3) Set the magic number of the unified upgrade file header to the preset unified upgrade file magic number, and write the unified upgrade file header to the starting position of the unified upgrade file to complete the construction of the unified upgrade file.

[0061] In step 205, construct the unified upgrade file meta-information and save the unified upgrade file meta-information to the sixth preset position in the boot communication partition.

[0062] In some embodiments, the unified upgrade file meta-information is jointly composed of a preset magic number, the partition name of the partition where the unified upgrade file is located, the file system type of the partition where the unified upgrade file is located, the path of the unified upgrade file, and the unified upgrade file checksum.

[0063] Step 205 specifically includes the following (1) to (6).

[0064] (1) Set the magic number of the unified upgrade file meta-information to the preset unified upgrade file meta-information magic number.

[0065] (2) Set the partition name of the partition where the unified upgrade file is located in the unified upgrade file meta-information to the preset user data partition.

[0066] (3) Set the file system type of the partition where the unified upgrade file is located in the unified upgrade file meta-information to the file system type of the preset user data partition.

[0067] (4) Set the path of the unified upgrade file in the unified upgrade file meta-information to the preset unified upgrade file path.

[0068] (5) Calculate the checksum of the unified upgrade file with the preset name under the preset unified upgrade file path of the preset user data partition according to the preset checksum algorithm (such as CRC32), and save the calculated checksum to the unified upgrade file checksum in the unified upgrade file meta-information.

[0069] (6) Write the constructed unified upgrade file meta-information to the first preset position in the boot communication partition.

[0070] In step 206, write the first-stage upgrade instruction to the first preset position in the boot communication partition.

[0071] In step 207, restart the device.

[0072] In step 208, in the device's bootloader firmware, read the upgrade instruction information from the first preset position in the boot communication partition.

[0073] In step 209, if the upgrade instruction information is not the first-stage upgrade instruction, the second-stage upgrade instruction, the third-stage upgrade instruction, the fourth-stage upgrade instruction, the fifth-stage upgrade instruction, or the preset all-readable / writable partition erasure instruction, the device is guided according to the preset process.

[0074] In step 210, if the upgrade instruction information includes the first-stage upgrade instruction, the unified upgrade file is obtained from the preset unified upgrade file path of the preset user data partition.

[0075] In step 211, the unified upgrade file meta-information is read from the fifth preset position in the boot communication partition, and the unified upgrade file is verified according to the unified upgrade file meta-information to obtain the verification result. Specifically, it includes the following (1) to (5).

[0076] (1) Read the unified upgrade file meta-information from the fifth preset position in the boot communication partition, and determine whether the magic number of the unified upgrade file meta-information is the preset magic number of the unified upgrade file meta-information. If not, determine that the verification result is not passed. If so, execute step (2).

[0077] (2) Obtain the partition table as the current partition table from the address space where the device partition table is located, and check whether there is a partition corresponding to the partition name of the unified upgrade file in the unified upgrade file meta-information in the current partition table. If not, determine that the verification result is not passed. If so, obtain the starting address of the partition corresponding to the partition name of the unified upgrade file in the unified upgrade file meta-information as the starting address of the unified upgrade file partition.

[0078] (3) Mount the unified upgrade file partition according to the partition name of the unified upgrade file in the unified upgrade file meta-information and the file system type of the unified upgrade file partition. If the mount fails, determine that the verification result is not passed. If the mount is successful, execute step (4).

[0079] (4) According to the path of the unified upgrade file in the unified upgrade file meta-information, check whether there is a unified upgrade file with a preset name in the path of the unified upgrade file partition. If not, determine that the verification result is not passed. If so, execute the following step (5).

[0080] (5) Calculate the checksum of the unified upgrade file with a preset name in the unified upgrade file path of the partition where the unified upgrade file is located according to a preset verification algorithm (such as CRC32), and compare the calculated checksum with the unified upgrade file checksum in the unified upgrade file metadata. If the comparison result is consistent, calculate the size of the unified upgrade file with a preset name in the unified upgrade file path of the partition where the unified upgrade file is located as the unified upgrade file size, and determine that the verification result passes. If the comparison result is inconsistent, determine that the verification result fails.

[0081] In step 212, if the verification result fails, the upgrade fails, and the firmware upgrade process exits.

[0082] In step 213, if the verification result passes, calculate the address space corresponding to the first storage area of the firmware data to be upgraded, and store the unified upgrade file in the first storage area according to the address space corresponding to the first storage area. Specifically, it includes the following (1) to (3).

[0083] (1) Check whether there is a partition in the current partition table whose size is greater than or equal to the unified upgrade file size and whose partition name is not the preset user data partition, bootloader firmware partition, and boot communication partition. If there is, use the first found partition that meets the conditions as the first storage area of the firmware data to be upgraded, and use the start address of this partition as the start address of the first storage area of the firmware data to be upgraded, and then execute (3). Otherwise, execute step (2).

[0084] (2) Use the first partition after the bootloader firmware partition and the boot communication partition in the current partition table as the candidate area for the firmware data to be upgraded, and obtain the start address of the candidate area for the firmware data to be upgraded as the start address of the candidate area for the firmware data to be upgraded; and determine whether the space size between "the start address of the partition where the unified upgrade file is located - the start address of the candidate area for the firmware data to be upgraded" is greater than or equal to the unified upgrade file size. If it is, use the start address of the candidate area for the firmware data to be upgraded as the start address of the first storage area of the firmware data to be upgraded, and then execute (3). Otherwise, the upgrade fails, and the firmware upgrade process exits.

[0085] (3) Use the unified upgrade file size as the data size of the first storage area of the firmware data to be upgraded, and use the address space determined by the start address of the first storage area of the firmware data to be upgraded and the data size of the first storage area of the firmware data to be upgraded as the first storage area of the firmware data to be upgraded; and save the unified upgrade file with a preset name in the unified upgrade file path of the partition where the unified upgrade file is located to the first storage area of the firmware data to be upgraded.

[0086] In step 214, construct the first storage area meta-information of the firmware data to be upgraded, and write the first storage area meta-information to the third preset position in the boot communication partition.

[0087] In some embodiments, the first storage area meta-information of the firmware data to be upgraded is jointly composed of a preset magic number, the starting address of the first storage area, and the data length of the first storage area.

[0088] Step 214 specifically includes the following (1) to (4).

[0089] (1) Set the magic number of the first storage area meta-information of the firmware data to be upgraded to the preset first storage area meta-information magic number.

[0090] (2) Set the starting address of the first storage area of the first storage area meta-information of the firmware data to be upgraded to the starting address of the first storage area of the firmware data to be upgraded.

[0091] (3) Set the data length of the first storage area of the first storage area meta-information of the firmware data to be upgraded to the data size of the first storage area of the firmware data to be upgraded.

[0092] (4) Write the constructed first storage area meta-information of the firmware data to be upgraded to the third preset position in the boot communication partition.

[0093] In step 215, write the second-stage upgrade instruction to the first preset position in the boot communication partition, and execute the second-stage upgrade instruction.

[0094] In step 216, if the upgrade instruction information includes the second-stage upgrade instruction, calculate the address space corresponding to the second storage area of the firmware data to be upgraded according to the first storage area meta-information and the new partition table, and copy the data in the first storage area to the second storage area according to the address space corresponding to the second storage area. Specifically includes the following (1) to (6).

[0095] (1) Read the first storage area meta-information from the third preset position in the boot communication partition, and check whether the magic number in the first storage area meta-information is the preset first storage area meta-information magic number. If so, execute step (2); otherwise, the upgrade fails and the firmware upgrade process exits.

[0096] (2) Read a unified upgrade file header of a preset size from the starting address of the first storage area in the first storage area meta-information, and check whether the magic number in the unified upgrade file header is the preset unified upgrade file magic number. If so, execute step (3); otherwise, the upgrade fails and the firmware upgrade process exits.

[0097] (3) Find the corresponding partition table file entry by comparing whether the partition name of each file entry in the file entry list in the unified upgrade file header is the preset name of the partition table file. Read the data of the length of the file to be upgraded in the partition table file entry as the new partition table from the address of "starting address of the first storage area + offset address of the file to be upgraded data in the unified upgrade file in the partition table file entry"; calculate the digital digest of the new partition table according to the digital digest algorithm type in the partition table file entry, and compare the calculated digital digest with the digital digest value in the partition table file entry. If the comparison is consistent, execute step (4); otherwise, the upgrade fails and the firmware upgrade process exits.

[0098] (4) Obtain the starting address of the preset user data partition from the new partition table, and determine the size of the preset user data partition, which are used as the starting address of the new user data partition and the size of the new user data partition respectively; at the same time, check whether the size of the new user data partition is greater than the data length of the first storage area. If so, execute step (5); otherwise, the upgrade fails and the firmware upgrade process exits.

[0099] (5) Check whether "starting address of the first storage area + data length of the first storage area" is greater than the starting address of the new user data partition. If so, use "starting address of the first storage area + data length of the first storage area" as the starting address of the second storage area of the firmware data to be upgraded; otherwise, use the starting address of the new user data partition as the starting address of the second storage area of the firmware data to be upgraded.

[0100] Check whether "(starting address of the new user data partition + size of the new user data partition - starting address of the second storage area of the firmware data to be upgraded)" is greater than the data length of the first storage area. If so, execute step (6); otherwise, the upgrade fails and the firmware upgrade process exits.

[0101] (6) Use the data length of the first storage area as the data size of the second storage area of the firmware data to be upgraded, use the address space determined by the starting address of the second storage area of the firmware data to be upgraded and the data size of the second storage area of the firmware data to be upgraded as the second storage area of the firmware data to be upgraded, and copy the data in the first storage area of the firmware data to be upgraded to the second storage area of the firmware data to be upgraded.

[0102] In step 217, construct the meta information of the second storage area of the firmware data to be upgraded, and write the meta information of the second storage area into the fourth preset position in the boot communication partition.

[0103] In some embodiments, the meta information of the second storage area of the firmware data to be upgraded is jointly composed of a preset magic number, the starting address of the second storage area, and the data length of the second storage area.

[0104] Step 217 specifically includes the following (1) to (4).

[0105] (1)Set the magic number of the second storage area meta - information of the firmware data to be upgraded to the preset second storage area meta - information magic number.

[0106] (2)Set the starting address of the second storage area of the second storage area meta - information of the firmware data to be upgraded to the starting address of the second storage area of the firmware data to be upgraded.

[0107] (3)Set the data length of the second storage area of the second storage area meta - information of the firmware data to be upgraded to the data size of the second storage area of the firmware data to be upgraded.

[0108] (4)Write the constructed second storage area meta - information of the firmware data to be upgraded to the fourth preset position in the boot communication partition.

[0109] In step 218, construct the free area address space meta - information and write the free area address space meta - information to the fifth preset position in the boot communication partition.

[0110] In some embodiments, the free area address space meta - information is composed of a preset magic number, digital digest algorithm type, digital digest value, starting address of the free area, and length of the free area.

[0111] Step 218 specifically includes the following (1) to (5): (1)Set the magic number of the free area address space meta - information to the preset free area address space meta - information magic number.

[0112] (2)Set the digital digest algorithm type of the free area address space meta - information to the preset digital digest algorithm type.

[0113] (3)Set the starting address of the free area of the free area address space meta - information to "starting address of the second storage area of the firmware data to be upgraded + data size of the second storage area of the firmware data to be upgraded".

[0114] (4)Set the length of the free area of the free area address space meta - information to "starting address of the new user data partition + size of the new user data partition - starting address of the free area of the free area address space meta - information".

[0115] (5)Calculate the digital digest of the content composed of the starting address of the free area and the length of the free area of the free area address space meta - information according to the digital digest algorithm type of the free area address space meta - information, and save it to the digital digest value of the free area address space meta - information.

[0116] In step 219, write the third - stage upgrade instruction to the first preset position in the boot communication partition and execute the third - stage upgrade instruction.

[0117] In step 220, if the upgrade instruction information includes the third-stage upgrade instruction, read the backup area meta information from the second preset position in the boot communication partition.

[0118] In some embodiments, the backup area meta information includes a preset magic number, a digital digest algorithm type, a meta information digest value, the starting address of the backup firmware of the bootloader, the size of the backup firmware of the bootloader, the digest value of the backup firmware of the bootloader, a flag indicating whether the boot communication partition is backed up, the starting address of the boot communication backup partition, the size of the boot communication backup partition, and the digest value of the boot communication backup partition.

[0119] Specifically, obtain the partition table from the address space where the device partition table is located as the current partition table, and read the backup area meta information from the second preset position in the boot communication partition of the current partition table.

[0120] In step 221, check the legality of the backup area meta information, the backup firmware of the bootloader, and the mirror data of the boot communication backup partition to obtain a first check result. Specifically, it includes the following (1) to (4).

[0121] (1) Check whether the magic number of the backup area meta information is the preset magic number of the backup area meta information. If so, execute step (2); otherwise, determine that the first check result is not all legal.

[0122] (2) Calculate the digital digest of the content composed of the starting address of the backup firmware of the bootloader, the size of the backup firmware of the bootloader, the digest value of the backup firmware of the bootloader, the flag indicating whether the boot communication partition is backed up, the starting address of the boot communication backup partition, the size of the boot communication backup partition, and the digest value of the boot communication backup partition in the backup area meta information according to the digital digest algorithm type of the backup area meta information, and compare the calculated digital digest with the meta information digest value of the backup area meta information. If they are consistent, execute step (3); otherwise, determine that the first check result is not all legal.

[0123] (3) Read the data with a length equal to the size of the backup firmware of the bootloader from the starting address of the backup firmware of the bootloader in the backup area meta information as the backup firmware of the bootloader, calculate the digital digest value of the backup firmware of the bootloader according to the digital digest algorithm type of the backup area meta information, and compare the calculated digital digest value with the digest value of the backup firmware of the bootloader in the backup area meta information. If they are consistent, execute the following step (4); otherwise, determine that the first check result is not all legal.

[0124] (4) Check whether the backup flag in the boot communication partition of the backup area metadata is true. If it is, read data with a length equal to the size of the boot communication backup partition from the starting address of the boot communication backup partition in the backup area metadata as the boot communication backup partition image data. Calculate the digital digest value of the boot communication backup partition image data according to the digital digest algorithm type in the backup area metadata, and compare the calculated digital digest value with the boot communication backup partition digest value in the backup area metadata. If they are consistent, determine that the first check result is all legal; otherwise, determine that the first check result is not all legal.

[0125] In step 222, if the first check result is all legal, then execute step 227.

[0126] In step 223, if the first check result is not all legal, then back up the startup bootloader firmware partition according to the free area address space metadata, and obtain a new partition table from the second storage area. Specifically, it includes the following (1) to (5).

[0127] (1) Obtain the partition table from the address space where the device partition table is located as the current partition table. Read the free area address space metadata from the fifth preset position in the boot communication partition of the current partition table, and check whether the magic number of the free area address space metadata is the preset magic number of the free area address space metadata. If it is, then execute step (2); otherwise, the upgrade fails and the firmware upgrade process exits.

[0128] (2) Calculate the digital digest of the content composed of the starting address and length of the free area in the free area address space metadata according to the digital digest algorithm type in the free area address space metadata, and compare the calculated digital digest with the digital digest value of the free area address space metadata. If they are consistent, then execute step (3); otherwise, the upgrade fails and the firmware upgrade process exits.

[0129] (3) Obtain the starting address and partition size of the startup bootloader firmware partition in the current partition table. Use the starting address of the free area in the free area address space metadata as the starting address of the startup bootloader firmware backup area, and use the partition size of the startup bootloader firmware partition in the current partition table as the size of the startup bootloader firmware backup area. Check whether the size of the startup bootloader firmware backup area is greater than the length of the free area in the free area address space metadata. If it is, then the upgrade fails and the firmware upgrade process exits; otherwise, execute step (4).

[0130] (4)Read data with a length equal to the partition size of the bootloader firmware partition in the current partition table from the starting address of the bootloader firmware partition as the bootloader firmware data, and write the bootloader firmware data to the starting address of the bootloader firmware backup area, with the written data size equal to the size of the bootloader firmware backup area.

[0131] Update the starting address of the free area in the free area address space metadata to: the original starting address of the free area + the size of the bootloader firmware backup area, and update the length of the free area in the free area address space metadata to: the original length of the free area - the size of the bootloader firmware backup area.

[0132] (5)Obtain the new partition table from the second storage area, specifically including the following (5-1) to (5-3).

[0133] (5-1)Read the metadata of the second storage area for the firmware data to be upgraded from the fourth preset position in the boot communication partition of the current partition table, and check whether the magic number in the metadata of the second storage area is the preset magic number for the metadata of the second storage area. If so, perform step (5-2); otherwise, the upgrade fails and the firmware upgrade process exits.

[0134] (5-2)Read the unified upgrade file header of a preset size from the starting address of the second storage area in the metadata of the second storage area, and check whether the magic number in the unified upgrade file header is the preset magic number for the unified upgrade file. If so, perform step (5-3); otherwise, the upgrade fails and the firmware upgrade process exits.

[0135] (5-3)Find the corresponding partition table file entry by comparing whether the partition name of each file entry in the file entry list in the unified upgrade file header is the preset name of the partition table file; read data with a length equal to the length of the file to be upgraded in the partition table file entry from the position of "the starting address of the second storage area + the offset address of the file data to be upgraded in the unified upgrade file in the partition table file entry" as the new partition table; calculate the digital digest of the new partition table according to the digital digest algorithm type in the partition table file entry, and compare the calculated digital digest with the digital digest value in the partition table file entry. If they are consistent, perform step 224; otherwise, the upgrade fails and the firmware upgrade process exits.

[0136] In step 224, if the address space of the boot communication partition changes in the new partition table, back up the boot communication partition according to the free area address space metadata and construct the backup area metadata. Specifically, it includes the following (1) to (3).

[0137] (1)Obtain the start address and partition size of the boot communication partition from the new partition table, and use them as the start address and size of the new boot communication partition respectively; obtain the start address and partition size of the boot communication partition from the current partition table, and use them as the start address and size of the current boot communication partition respectively; check whether the address space of the new boot communication partition is the same as that of the current boot communication partition (that is, check whether the start address and size of the new boot communication partition are exactly the same as the start address and size of the current boot communication partition respectively). If they are not the same, set the boot communication partition address space change flag to true; otherwise, set the boot communication partition address space change flag to false.

[0138] (2)If the boot communication partition address space change flag is true, back up the boot communication partition. Specifically, it includes the following (2-1) to (2-3).

[0139] (2-1)Check whether the boot communication partition address space change flag is false. If it is, execute step (3); otherwise, execute step (2-2).

[0140] (2-2)Use the start address of the free area in the free area address space meta-information as the start address of the boot communication partition backup area, and use the partition size of the boot communication partition in the current partition table as the size of the boot communication partition backup area. Then check whether the size of the boot communication partition backup area is greater than the length of the free area in the free area address space meta-information. If it is, an upgrade error occurs and the firmware upgrade process is exited; otherwise, execute step (2-3).

[0141] (2-3)Read data with a length equal to the partition size of the boot communication partition in the current partition table from the start address of the boot communication partition in the current partition table as the boot communication partition mirror data, and write the boot communication partition mirror data to the start address of the boot communication partition backup area, with the written data size equal to the size of the boot communication partition backup area; update the start address of the free area in the free area address space meta-information to: the original start address of the free area + the size of the boot communication partition backup area; update the length of the free area in the free area address space meta-information to: the original length of the free area - the size of the boot communication partition backup area.

[0142] (3)Construct the backup area meta-information. Specifically, it includes the following (3-1) to (3-9).

[0143] (3-1)Set the magic number of the backup area meta-information to the preset magic number of the backup area meta-information.

[0144] (3-2)Set the digital digest algorithm type of the backup area meta-information to the preset digital digest algorithm type.

[0145] (3-3) Set the boot program backup firmware start address of the backup area meta-information to the boot program firmware backup area start address.

[0146] (3-4) Set the boot program backup firmware size of the backup area meta-information to the boot program firmware backup area size.

[0147] (3-5) Read data of the same length as the size of the boot program backup firmware in the backup zone meta-information from the starting address of the boot program backup firmware in the backup zone meta-information as the boot program backup firmware, calculate the digital summary value of the boot program backup firmware according to the digital summary algorithm type of the backup zone meta-information, and save the calculated digital summary value to the boot program backup firmware summary value of the backup zone meta-information.

[0148] (3-6) Check whether the boot communication partition address space change flag is true. If so, set the boot communication partition backup flag of the backup area meta-information to true. Otherwise, set the boot communication partition backup flag of the backup area meta-information to false.

[0149] (3-7) If the backup flag of the boot communication partition in the backup area meta-information is true, then the boot communication backup partition starting address of the backup area meta-information is set to the boot communication partition backup area starting address, and the boot communication backup partition size of the backup area meta-information is set to the boot communication partition backup area size; from the boot communication backup partition starting address of the backup area meta-information, data with a length of the boot communication backup partition size is read as the boot communication backup partition mirror data, and the digital summary value of the boot communication backup partition mirror data is calculated according to the digital summary algorithm type of the backup area meta-information, and the calculated digital summary value is saved to the boot communication backup partition summary value of the backup area meta-information.

[0150] (3-8) If the boot communication partition backup flag of the backup area meta-information is false, the boot communication backup partition start address of the backup area meta-information is set to a preset empty address, the boot communication backup partition size of the backup area meta-information is set to zero, and the boot communication backup partition summary value of the backup area meta-information is set to zero.

[0151] (3-9) Calculate a digital summary of the contents consisting of the boot program backup firmware starting address, boot program backup firmware size, boot program backup firmware summary value, boot communication partition backup flag, boot communication backup partition starting address, boot communication backup partition size and boot communication backup partition summary value in the backup area meta-information according to the digital summary algorithm type of the backup area meta-information, and save the calculated digital summary to the meta-information summary value of the backup area meta-information.

[0152] In step 225, write the constructed backup area meta information to the second preset position in the boot communication partition of the current partition table.

[0153] In step 226, write the updated free area address space meta information to the fifth preset position in the boot communication partition of the current partition table.

[0154] In step 227, update the current partition table based on the backup area meta information, the bootloader backup firmware, and the boot communication backup partition image data. Specifically, it includes the following (1) to (4).

[0155] (1) According to the backup area meta information, set the start address of the bootloader firmware partition in the current partition table to the start address of the bootloader backup firmware in the backup area meta information, and set the partition size of the bootloader firmware partition in the current partition table to the size of the bootloader backup firmware in the backup area meta information.

[0156] (2) If the backup flag of the boot communication partition in the backup area meta information is true, set the start address of the boot communication partition in the current partition table to the start address of the boot communication backup partition in the backup area meta information, and set the partition size of the boot communication partition in the current partition table to the size of the boot communication backup partition in the backup area meta information.

[0157] (3) Write the updated current partition table to the address space corresponding to the partition table to complete the upgrade of the updated current partition table.

[0158] (4) Use the updated current partition table as the current partition table.

[0159] In step 228, write the fourth-stage upgrade instruction to the first preset position in the boot communication partition of the current partition table and execute the fourth-stage upgrade instruction.

[0160] In step 229, if the upgrade instruction information includes the fourth-stage upgrade instruction, set the start address of the bootloader firmware partition in the current partition table to the start address of the bootloader backup firmware in the backup area meta information, and set the partition size of the bootloader firmware partition in the current partition table to the size of the bootloader backup firmware in the backup area meta information to upgrade the bootloader firmware and the new partition table, and use the new partition table as the current partition table. Specifically, it includes the following (1) to (5).

[0161] (1) Read the backup area meta information from the second preset position in the boot communication partition, and check the legality of the backup area meta information, the bootloader backup firmware, and the boot communication backup partition image data to obtain the second check result.

[0162] If the second inspection result is all legal, execute step (2); otherwise, the upgrade fails and the firmware upgrade process exits.

[0163] (2) Obtain the partition table from the address space where the device partition table is located as the current partition table, and check whether the starting address of the bootloader firmware partition in the current partition table is the same as the starting address of the bootloader backup firmware in the backup area metadata. If they are the same, execute step (3); if they are different, point the starting address of the bootloader firmware partition in the current partition table to the starting address of the bootloader backup firmware in the backup area metadata, and set the partition size of the bootloader firmware partition in the current partition table to the size of the bootloader backup firmware in the backup area metadata; if the backup flag of the boot communication partition in the backup area metadata is true, point the starting address of the boot communication partition in the current partition table to the starting address of the boot communication backup partition in the backup area metadata, and set the partition size of the boot communication partition in the current partition table to the size of the boot communication backup partition in the backup area metadata; write the updated current partition table to the address space corresponding to the partition table to complete the upgrade of the updated current partition table; use the updated current partition table as the current partition table and execute step (3).

[0164] (3) Obtain the new partition table from the second storage area of the firmware to be upgraded, obtain the bootloader firmware image data to be upgraded from the second storage area, and write the bootloader firmware image data to be upgraded to the address space corresponding to the bootloader firmware partition in the new partition table. Specifically, it includes the following (3-1) to (3-5).

[0165] (3-1) Read the second storage area metadata of the firmware to be upgraded from the fourth preset position in the boot communication partition of the current partition table, and check whether the magic number in the second storage area metadata is the preset magic number of the second storage area metadata. If it is, execute step (3-2); otherwise, the upgrade fails and the firmware upgrade process exits.

[0166] (3-2) Read a unified upgrade file header of a preset size from the starting address of the second storage area in the second storage area metadata, and check whether the magic number in the unified upgrade file header is the preset magic number of the unified upgrade file. If it is, execute step (3-3); otherwise, the upgrade fails and the firmware upgrade process exits.

[0167] (3-3) Find the corresponding partition table file entry by comparing whether the partition name of each file entry in the file entry list in the unified upgrade file header is the preset name of the partition table file; read the data of the length of the file to be upgraded in the partition table file entry as the new partition table from the address "the start address of the second storage area + the offset address of the file data to be upgraded in the unified upgrade file in the partition table file entry"; calculate the digital digest of the new partition table according to the digital digest algorithm type in the partition table file entry, and compare the calculated digital digest with the digital digest value in the partition table file entry. If they are consistent, execute step (3-4); otherwise, the upgrade fails and the firmware upgrade process exits.

[0168] (3-4) Find the corresponding bootloader firmware file entry by comparing whether the partition name of each file entry in the file entry list in the unified upgrade file header is the preset name of the bootloader firmware partition; read the data of the length of the file to be upgraded in the bootloader firmware file entry as the bootloader firmware image data to be upgraded from the address "the start address of the second storage area + the offset address of the file data to be upgraded in the unified upgrade file in the bootloader firmware file entry"; calculate the digital digest of the bootloader firmware image data to be upgraded according to the digital digest algorithm type in the bootloader firmware file entry, and compare the calculated digital digest with the digital digest value in the bootloader firmware file entry. If they are consistent, execute step (3-5); otherwise, the upgrade fails and the firmware upgrade process exits.

[0169] (3-5) Write the bootloader firmware image data to be upgraded into the address space corresponding to the bootloader firmware partition in the new partition table to complete the upgrade of the bootloader firmware.

[0170] (4) If the backup mark of the boot communication partition in the backup area meta information is false, execute step (5); otherwise, upgrade the boot communication backup partition image data to the address space corresponding to the boot communication partition in the new partition table according to the backup area meta information, and execute the following step (5). Specifically, it includes the following (1) to (2).

[0171] (1) If the backup mark of the boot communication partition in the backup area meta information is false, execute step (5); otherwise, execute step (2).

[0172] (2) Read the data with a length equal to the size of the boot communication backup partition in the backup area meta information as the boot communication backup partition image data from the start address of the boot communication backup partition in the backup area meta information, and write the read boot communication backup partition image data into the address space corresponding to the boot communication partition in the new partition table, and execute the following step (5).

[0173] (5) Write the new partition table to the address space corresponding to the partition table to complete the upgrade of the new partition table, and use the new partition table as the current partition table.

[0174] In step 230, write the fifth-stage upgrade instruction to the first preset position in the boot communication partition of the current partition table, and execute the fifth-stage upgrade instruction.

[0175] In step 231, if the upgrade instruction information includes the fifth-stage upgrade instruction, obtain the partition table from the address space where the device partition table is located as the current partition table; sequentially obtain other firmware image data except the new partition table and the bootloader firmware image data to be upgraded from the second storage area, and write the other firmware image data to the address space corresponding to the corresponding firmware partition in the current partition table. Specifically, it includes the following (1) to (3).

[0176] (1) Read the second storage area metadata of the firmware to be upgraded from the fourth preset position in the boot communication partition of the current partition table, and check whether the magic number in the second storage area metadata is the preset second storage area metadata magic number. If so, execute step (2); otherwise, the upgrade fails and the firmware upgrade process exits.

[0177] (2) Read a unified upgrade file header of a preset size from the start address of the second storage area in the second storage area metadata, and check whether the magic number in the unified upgrade file header is the preset unified upgrade file magic number. If so, execute step (3); otherwise, the upgrade fails and the firmware upgrade process exits.

[0178] (3) Sequentially obtain other firmware file items to be upgraded except the partition table file item and the bootloader firmware file item from the file item list in the unified upgrade file header; for each corresponding firmware file item to be upgraded except the partition table file item and the bootloader firmware file item, read data with the size of the length of the firmware file to be upgraded in the firmware file item to be upgraded from the position of "start address of the second storage area + offset address of the firmware file data to be upgraded in the unified upgrade file" as the firmware image data to be upgraded; calculate the digital digest of the firmware image data to be upgraded according to the digital digest algorithm type in the firmware file item to be upgraded, and compare the calculated digital digest with the digital digest value in the firmware file item to be upgraded. If they are consistent, write the firmware image data to be upgraded to the address space corresponding to the corresponding firmware partition in the current partition table to complete the upgrade of the corresponding firmware; otherwise, the upgrade fails and the firmware upgrade process exits; after completing the upgrade of all firmware to be upgraded, execute step 232.

[0179] In step 232, write the preset all-readable and writable partition erase instructions to the first preset position in the boot communication partition of the current partition table, and execute the preset all-readable and writable partition erase instructions.

[0180] In step 233, if the upgrade instruction information includes all the preset read / write partition erasure instructions, then perform an erasure operation on all the preset read / write partitions; if there is a read / write partition with a file system, then re - establish the file system; sequentially clear the upgrade instruction information in the first preset location in the boot communication partition, the unified upgrade file meta - information in the sixth preset location, the first storage area meta - information of the firmware to be upgraded in the third preset location, the second storage area meta - information of the firmware to be upgraded in the fourth preset location, the free area address space meta - information in the fifth preset location, and the backup area meta - information in the second preset location; restart the device to enter the upgraded system.

[0181] According to another aspect of the present invention, Figure 3 is a schematic diagram showing an electronic device 300 according to an embodiment of the present invention. Refer to Figure 3 , the electronic device 300 includes a memory 302 and a processor 304. The memory 302 is configured to store a computer program that can run on the processor 304. When the processor 304 executes the computer program, it implements each step of the method for upgrading the firmware as described above.

[0182] In summary, for the method and electronic device for upgrading firmware provided by the present invention, the bootloader firmware partition and the boot communication partition are backed up to a preset storage area behind the firmware data to be upgraded. The backup area meta-information constructed is written to a second preset position in the boot communication partition of the current partition table. The starting address of the bootloader firmware partition in the current partition table is pointed to the starting address of the bootloader backup firmware in the backup area meta-information, and the partition size of the bootloader firmware partition in the current partition table is set to the size of the bootloader backup firmware in the backup area meta-information, so as to upgrade the bootloader firmware and the new partition table. This ensures that the starting address of the bootloader firmware partition in the current partition table is the same as the starting address of the bootloader backup firmware in the backup area meta-information, thereby ensuring that before the upgrade of the bootloader firmware and the new partition table is completed, the bootloader is always loaded from the bootloader backup firmware. Even if an accident occurs during the upgrade of the bootloader firmware, it will not affect the bootloader backup firmware. Furthermore, it can ensure that in any case of an accident (such as power failure) during the upgrade process, the device will never become bricked and can always continue to complete the upgrade after being powered on again. Thus, in the case of any arbitrary change in the address space of all partitions, the reliability of firmware upgrade is effectively improved. Additionally, when executing the first-stage upgrade instruction, a unified upgrade file is obtained from a preset unified upgrade file path in the preset user data partition, the address space corresponding to the first storage area of the firmware data to be upgraded is calculated, and the unified upgrade file is stored in the first storage area. The meta-information of the first storage area for constructing the firmware data to be upgraded is written to a third preset position in the boot communication partition. When executing the second-stage upgrade instruction, the address space corresponding to the second storage area of the firmware data to be upgraded is calculated according to the meta-information of the first storage area and the new partition table, and the data in the first storage area is copied to the second storage area. The constructed meta-information of the second storage area is written to a fourth preset position in the boot communication partition. In this way, the first storage area of the firmware data to be upgraded can be located before the preset user data partition in the old partition table, and the unified upgrade file in the preset user data partition can be successfully read. Then, the second storage area is located within the address space of the preset user data partition in the new partition table. Subsequently, firmware upgrade can be achieved according to the meta-information of the second storage area and the unified upgrade file stored in the second storage area. Even if the address space of all partitions in the new partition table changes, it does not require an external storage medium.

[0183] The above are only the embodiments of the present invention, and thus do not limit the patent scope of the present invention. Any equivalent transformation made by using the content of the specification and drawings of the present invention, or directly or indirectly applied in the relevant technical fields, shall be equally included in the patent protection scope of the present invention.

Claims

1. A method for upgrading firmware, characterized in that, Including: In the device's bootloader firmware, read the upgrade instruction information from the first preset position in the boot communication partition; Back up the bootloader firmware partition and the boot communication partition to the back of the preset storage area of the firmware to be upgraded, construct the backup area meta information, and write the constructed backup area meta information to the second preset position in the boot communication partition of the current partition table; Update the current partition table based on the backup area meta information, the bootloader backup firmware, and the boot communication backup partition image data; And Point the start address of the bootloader firmware partition in the current partition table to the start address of the bootloader backup firmware in the backup area meta information, and set the partition size of the bootloader firmware partition in the current partition table to the size of the bootloader backup firmware in the backup area meta information to upgrade the bootloader firmware and the new partition table, and use the new partition table as the current partition table.

2. The method according to claim 1, characterized in that, Also including: If the upgrade instruction information includes the first-stage upgrade instruction, obtain the unified upgrade file from the preset unified upgrade file path in the preset user data partition; Calculate the address space corresponding to the first storage area of the firmware to be upgraded, and store the unified upgrade file in the first storage area according to the address space corresponding to the first storage area; Construct the first storage area meta information of the firmware to be upgraded, and write the first storage area meta information to the third preset position in the boot communication partition; Write the second-stage upgrade instruction to the first preset position in the boot communication partition; Execute the second-stage upgrade instruction.

3. The method according to claim 1, characterized in that, Also including: If the upgrade instruction information includes the second-stage upgrade instruction, calculate the address space corresponding to the second storage area of the firmware to be upgraded according to the first storage area meta information and the new partition table, and copy the data in the first storage area to the second storage area according to the address space corresponding to the second storage area; Construct the second storage area meta information of the firmware to be upgraded, and write the second storage area meta information to the fourth preset position in the boot communication partition; Construct the free area address space meta information, and write the free area address space meta information to the fifth preset position in the boot communication partition; Write the third-stage upgrade instruction to the first preset position in the boot communication partition; And Execute the third-stage upgrade instruction.

4. The method according to claim 1, characterized in that, If the upgrade instruction information includes the third-stage upgrade instruction, back up the bootloader firmware partition and the boot communication partition to the back of the second storage area of the firmware to be upgraded.

5. The method according to claim 1, characterized in that, After updating the current partition table based on the backup area meta information, the bootloader backup firmware, and the boot communication backup partition image data, it also includes: Write the fourth-stage upgrade instruction to the first preset position in the boot communication partition of the current partition table; and Execute the fourth-stage upgrade instruction.

6. The method according to claim 1, characterized in that, If the upgrade instruction information includes the fourth-stage upgrade instruction, then the starting address of the bootloader firmware partition in the current partition table is pointed to the starting address of the bootloader backup firmware in the backup area meta-information.

7. The method according to claim 2, wherein Before calculating the address space corresponding to the first storage area for the firmware data to be upgraded and storing the unified upgrade file in the first storage area according to the address space corresponding to the first storage area, it further includes: Reading the unified upgrade file meta-information from the fifth preset position in the boot communication partition and verifying the unified upgrade file according to the unified upgrade file meta-information to obtain a verification result; The calculating the address space corresponding to the first storage area for the firmware data to be upgraded and storing the unified upgrade file in the first storage area according to the address space corresponding to the first storage area includes: If the verification result is passed, calculate the address space corresponding to the first storage area for the firmware data to be upgraded and store the unified upgrade file in the first storage area according to the address space corresponding to the first storage area.

8. The method according to claim 3, wherein Backing up the bootloader firmware partition and the boot communication partition to the back of the preset storage area for the firmware data to be upgraded, constructing the backup area meta-information, and writing the constructed backup area meta-information to the second preset position in the boot communication partition of the current partition table includes: Reading the backup area meta-information from the second preset position in the boot communication partition; Checking the legality of the backup area meta-information, the bootloader backup firmware, and the boot communication backup partition image data to obtain a first check result; If the first check result is all legal, execute the step of updating the current partition table based on the backup area meta-information, the bootloader backup firmware, and the boot communication backup partition image data; If the first check result is not all legal, back up the bootloader firmware partition according to the free area address space meta-information and obtain a new partition table from the second storage area; If the address space of the boot communication partition changes in the new partition table, back up the boot communication partition according to the free area address space meta-information and construct the backup area meta-information; Writing the constructed backup area meta-information to the second preset position in the boot communication partition of the current partition table; and Writing the updated free area address space meta-information to the fifth preset position in the boot communication partition of the current partition table.

9. The method according to claim 1, wherein Updating the current partition table based on the backup area meta-information, the bootloader backup firmware, and the boot communication backup partition image data includes: Pointing the starting address of the bootloader firmware partition in the current partition table to the starting address of the bootloader backup firmware in the backup area meta-information; Setting the partition size of the bootloader firmware partition in the current partition table to the size of the bootloader backup firmware in the backup area meta-information; If the backup flag of the boot communication partition in the backup area metadata is true, then set the starting address of the boot communication partition in the current partition table to the starting address of the boot communication backup partition in the backup area metadata, and set the partition size of the boot communication partition in the current partition table to the size of the boot communication backup partition in the backup area metadata; Write the updated current partition table to the address space corresponding to the partition table to complete the upgrade of the updated current partition table; and Use the updated current partition table as the current partition table.

10. The method according to claim 1, wherein Set the starting address of the bootloader firmware partition in the current partition table to the starting address of the bootloader backup firmware in the backup area metadata, and set the partition size of the bootloader firmware partition in the current partition table to the size of the bootloader backup firmware in the backup area metadata to upgrade the bootloader firmware and the new partition table, and using the new partition table as the current partition table includes: Read the backup area metadata from the second preset position in the boot communication partition, and check the legality of the backup area metadata, the bootloader backup firmware, and the boot communication backup partition image data to obtain a second check result; If the second check result is all legal, then obtain the partition table from the address space where the device partition table is located as the current partition table; If the starting address of the bootloader firmware partition in the current partition table is different from the starting address of the bootloader backup firmware in the backup area metadata, then set the starting address of the bootloader firmware partition in the current partition table to the starting address of the bootloader backup firmware in the backup area metadata, and set the partition size of the bootloader firmware partition in the current partition table to the size of the bootloader backup firmware in the backup area metadata; If the backup flag of the boot communication partition in the backup area metadata is true, then set the starting address of the boot communication partition in the current partition table to the starting address of the boot communication backup partition in the backup area metadata, and set the partition size of the boot communication partition in the current partition table to the size of the boot communication backup partition in the backup area metadata; Write the updated current partition table to the address space corresponding to the partition table to complete the upgrade of the updated current partition table; Use the updated current partition table as the current partition table; Obtain a new partition table from the second storage area; Obtain the bootloader firmware image data to be upgraded from the second storage area, and write the bootloader firmware image data to be upgraded to the address space corresponding to the bootloader firmware partition in the new partition table; If the backup flag of the boot communication partition in the backup area metadata is true, then upgrade the boot communication backup partition image data to the address space corresponding to the boot communication partition in the new partition table according to the backup area metadata; Write the new partition table to the address space corresponding to the partition table to complete the upgrade of the new partition table; Use the new partition table as the current partition table; Write the fifth-stage upgrade instruction to the first preset position in the boot communication partition of the current partition table; Execute the fifth-stage upgrade instruction; and If the second check result is not all legal, exit the firmware upgrade process.

11. The method according to claim 10, wherein It further includes: If the upgrade instruction information includes the fifth-stage upgrade instruction, obtain the partition table from the address space where the device partition table is located as the current partition table; Obtain other firmware image data except the new partition table and the bootloader firmware image data to be upgraded from the second storage area in sequence, and write the other firmware image data to the address space corresponding to the firmware partition in the current partition table; Write the preset all-readable and writable partition erasure instructions to the first preset position in the boot communication partition of the current partition table; And Execute the preset all-readable and writable partition erasure instructions.

12. The method according to claim 11, wherein It further includes: If the upgrade instruction information includes the preset all-readable and writable partition erasure instructions, perform an erasure operation on all preset readable and writable partitions; If there is a readable and writable partition with a file system, re-establish the file system; Clear the upgrade instruction information in the first preset position in the boot communication partition, the unified upgrade file meta-information in the sixth preset position, the first storage area meta-information of the firmware data to be upgraded in the third preset position, the second storage area meta-information of the firmware data to be upgraded in the fourth preset position, the free area address space meta-information in the fifth preset position, and the backup area meta-information in the second preset position in sequence; And Restart the device to enter the upgraded system.

13. The method according to claim 2, wherein Before reading the upgrade instruction information from the first preset position in the boot communication partition in the device's bootloader firmware, it further includes: Obtain the firmware upgrade package to be upgraded and save the firmware upgrade package to the preset firmware upgrade package path in the preset user data partition; If the firmware upgrade package under the preset firmware upgrade package path in the preset user data partition is legal, construct the unified upgrade file according to the firmware upgrade package in the preset firmware upgrade package path, and save the unified upgrade file to the preset unified upgrade file path in the preset user data partition; Construct the unified upgrade file meta-information and save it to the sixth preset position in the boot communication partition; Write the first-stage upgrade instruction to the first preset position in the boot communication partition; and Restart the device.

14. An electronic device, characterized in that, It includes: A memory configured to store an executable program; And A processor configured to execute the program to perform the method according to any one of claims 1 to 13.