Embedded devices, controllers, chips, and storage media for firmware upgrades

By employing multiple redundant storage blocks and a three-level arbitration method in embedded devices, the problem of firmware upgrade control information being damaged on non-volatile storage media is solved. This enables accurate recovery of the upgrade state after power failure and avoids repeated upgrades, thereby improving the reliability and stability of the device.

CN123067908APending Publication Date: 2026-11-10SHANGHAI BANING TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202611576327.2
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2026-10-13
Publication Date
2026-11-10

AI Technical Summary

Technical Problem

In the prior art, the firmware upgrade control information of embedded devices is easily damaged on unreliable non-volatile storage media. After a power outage, it is difficult to accurately restore the upgrade state, which can cause the device to fail to start normally. Furthermore, when upgrading multiple components, it is impossible to distinguish between completed and incomplete components, which may lead to repeated upgrades.

Method used

The upgrade control information is upgraded by using multiple redundant storage blocks. The processor reads the upgrade control information of multiple backup blocks, performs validity verification and three-level arbitration to determine the target upgrade control information, and continues the upgrade from the completed components after an abnormal power failure, thus avoiding duplicate upgrades.

Benefits of technology

It improves the reliability of upgrade control information storage on unreliable storage media, ensures that the device can start normally after an abnormal power outage, avoids repeated upgrades, and reduces the maintenance overhead of multi-copy consistency.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN123067908A_ABST
    Figure CN123067908A_ABST
Patent Text Reader

Abstract

This application discloses an embedded device, control unit, chip, and storage medium for firmware upgrades, relating to the field of firmware upgrade technology. The embedded device includes a processor and a storage medium. The storage medium is divided into an upgrade partition and an upgrade control partition (MISC). The upgrade partition stores upgrade packages, and the MISC is divided into multiple blocks, each storing upgrade control information for the upgrade package. After the processor starts and runs the bootloader GSL, it reads the upgrade control information stored in each of the multiple backup blocks in the upgrade control partition; it verifies the validity of the multiple backup blocks; for valid backup blocks, it sequentially performs status filtering, progress comparison, and status comparison to determine the target upgrade control information; based on the target upgrade control information, it guides the execution of the firmware upgrade, writes upgrade data for incomplete components according to the completion status indicated by the progress field, and writes back to each backup block. This improves the reliability of firmware upgrades.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of firmware upgrade technology, and in particular to embedded devices, control devices, chips and storage media for firmware upgrades. Background Technology

[0002] Currently, firmware upgrades for embedded devices are typically completed collaboratively by the operating system-side upgrade application and the bootloader: the upgrade application writes the upgrade package to the upgrade partition on a non-volatile storage medium and writes the upgrade control information to a separately configured upgrade control partition; the bootloader reads the upgrade control partition each time the system starts and, based on the information recorded therein, such as the upgrade status, upgrade progress, remaining retries, and upgrade package parameters, decides whether to enter the upgrade process and from where to continue the upgrade.

[0003] However, storage media can suffer from factory-installed bad blocks, newly added bad blocks during operation, and data corruption due to unexpected power outages during the write / erase process. Existing upgrade control information is mostly stored in a single copy in a fixed physical location. If the physical block where it is stored is damaged or a power outage occurs during the write process, the upgrade status will be lost, and the device may not be able to start normally. Some solutions use dual backups, but there is a lack of a consistent mechanism for identifying old and new copies. Relying on a fixed reading order may result in reading the old status, while relying on explicit sequence numbers or timestamps increases storage and consistency maintenance overhead. At the same time, if the completed and incomplete components cannot be distinguished after a power outage during a multi-component upgrade, the completed components will be upgraded repeatedly.

[0004] Therefore, a firmware upgrade scheme is needed that can reliably store upgrade control information without adding an extra version identifier field, accurately identify the latest valid upgrade status after a power outage, continue the upgrade from the disconnected position, and avoid repeated upgrades. Summary of the Invention

[0005] This application provides an embedded device, control unit, chip, and storage medium for firmware upgrades, relating to the field of embedded system firmware upgrade technology. It addresses the problems of upgrade control information being easily damaged on unreliable non-volatile storage media and the difficulty in accurately restoring the upgrade state after power failure. The specific technical solution is as follows: In a first aspect, an embedded device is provided, including a storage medium and a processor. The storage medium is divided into an upgrade partition and an upgrade control partition (MISC). The upgrade partition stores an upgrade package, and the MISC is divided into multiple blocks. The multiple blocks are written sequentially according to a first write order and each block stores upgrade control information of the upgrade package. The upgrade control information includes a status field, a progress field, and a retry count field. The processor is used to start and run the bootloader GSL, thereby performing the following steps: reading the upgrade control information stored in each of the multiple blocks; performing three-level arbitration on the multiple blocks based on the status field and progress field in the upgrade control information to obtain a target block; updating the upgrade control information in the target block, including updating the status field to the upgrade in progress state and decrementing the retry count. The system includes a retry count field. When the firmware upgrade fails and the retry count field reaches zero, the status field is updated to a failure status. Updated upgrade control information is written back to multiple blocks in a second write order, the reverse of the first write order. The upgrade package is read and multiple checks are performed. Based on the progress field indicating the firmware upgrade completion status, corresponding upgrade data is written to the upgrade package for firmware that has not yet completed the upgrade. The progress field is updated based on the current firmware upgrade completion status. After multiple checks pass and all firmware that has not yet completed the upgrade has had its upgrade data written, the status field is updated to a completion status. Updated upgrade control information is written back to multiple blocks in the second write order. After the GSL firmware upgrade is successful or fails, the data in the MISC is erased, ending the current GSL firmware upgrade.

[0006] In conjunction with the first aspect, the processor performs three-level arbitration on multiple blocks based on the status and progress fields in the upgrade control information to obtain the target block. Specifically, this is used to: filter the status of multiple blocks, and determine the blocks whose status fields indicate a state of pending upgrade or in progress as candidate blocks; from the candidate blocks, select the candidate block with the largest value in the progress field as the target block; when there are at least two candidate blocks whose progress field values ​​are the same maximum value, determine the candidate block with the largest value in the status field as the target block; wherein, the value of the state of in progress is greater than the value of the state of pending upgrade.

[0007] In conjunction with the first aspect, the processor is also used to perform validity checks on multiple blocks before performing three-level arbitration on multiple blocks based on the status field and progress field in the upgrade control information, to obtain at least one valid block, and then perform three-level arbitration on the at least one valid block; wherein, the validity check includes: for each block, checking the identifier field, format version field and verification field of the upgrade control information in the block; and determining the block that matches the identifier field, format version field and verification field as a valid block.

[0008] In conjunction with the first aspect, the upgrade package includes a first signature area located before the upgrade data and a second signature area located after the upgrade data. The signature data stored in the first signature area and the second signature area are the same. The processor reads the upgrade package and performs multiple verifications, specifically for: performing signature consistency verification on the upgrade package, which is used to compare whether the signature data in the first signature area and the second signature area are consistent.

[0009] In conjunction with the first aspect, if the signature data in the first signature area and the second signature area are consistent, it is confirmed that the upgrade package has not been damaged during storage in the upgrade partition; if the signature data in the first signature area and the second signature area are inconsistent, the firmware upgrade is terminated, and the device system is started according to the startup process.

[0010] In conjunction with the first aspect, the upgrade control information includes a first upgrade package parameter group, and the upgrade package includes a second upgrade package parameter group located in the header region. The processor is further configured to, after performing signature consistency verification on the upgrade package, obtain the first upgrade package parameter group from the upgrade control information of the target block, and the second upgrade package parameter group in the header region of the upgrade package. The first upgrade package parameter group includes a first upgrade package size, a first version information, and a first checksum, and the second upgrade package parameter group includes a second upgrade package size, a second version information, and a second checksum. The processor performs a fast verification on the upgrade package based on the first checksum and performs a signature consistency verification on the upgrade package based on the signature data. When the corresponding parameters in the first upgrade package parameter group and the second upgrade package parameter group are consistent, it is confirmed that the upgrade package matches the upgrade control information of the target block, and the firmware upgrade continues.

[0011] In conjunction with the first aspect, multiple blocks in MISC have different numbers arranged from low to high. The first writing order is the order in which multiple blocks are written from low to high number, and the second writing order is the order in which multiple blocks are written from high to low number. The storage medium consists of multiple independent storage units, and multiple blocks are located on their respective storage units. The upgrade status can be determined if at least one of the multiple blocks can be read.

[0012] It should be noted that, in the absence of conflict, the features in the various embodiments of the first aspect can be combined with each other, and any combination of features in different embodiments is also within the protection scope of this application. That is to say, the various embodiments described above can also be arbitrarily combined according to actual needs.

[0013] Secondly, a control device for firmware upgrades is provided, comprising a storage medium divided into an upgrade partition and a MISC. The upgrade partition stores an upgrade package, and the MISC is divided into multiple blocks. These blocks are sequentially written in a first writing order and each block stores upgrade control information of the upgrade package. The blocks are also sequentially written back in a second writing order, the second writing order being the reverse of the first writing order. The upgrade control information includes a status field, a progress field, and a retry count field. The device includes: an information acquisition module for reading the upgrade control information stored in each of the multiple blocks after GSL is started; an information arbitration module for performing three-level arbitration on the multiple blocks based on the status field and progress field in the upgrade control information to obtain a target block; and an upgrade guidance module for updating the upgrade control information in the target block, including... The status field is updated to "Upgrading in Progress" and the retry count field is decremented. When the firmware upgrade fails and the retry count field reaches zero, the status field is updated to "Failure." The updated upgrade control information is written back to multiple blocks in the second write order. The upgrade update module reads the upgrade package and performs multiple checks. Based on the progress field indicating the firmware upgrade completion status, it writes the corresponding upgrade data to the upgrade package for firmware that has not yet been upgraded, and updates the progress field based on the current firmware upgrade completion status. After multiple checks pass and all firmware that has not yet been upgraded has had its upgrade data written, the status field is updated to "Completed." The updated upgrade control information is written back to multiple blocks in the second write order. The information erasure module erases the data in the MISC after a successful or failed firmware upgrade in GSL, ending the current GSL firmware upgrade.

[0014] Thirdly, a chip for firmware upgrade is provided. The chip is used to run a bootloader and includes a storage unit and a processing unit. The storage unit is divided into an upgrade partition and a MISC. The upgrade partition stores an upgrade package. The MISC is divided into multiple blocks. The multiple blocks are written sequentially in a first writing order and each block stores upgrade control information of the upgrade package. The upgrade control information includes a status field, a progress field, and a retry count field. The processing unit includes one or more processors. The processors are used to call computer instructions to execute the firmware upgrade method executed by the processor in the embedded device as described in any one of the first aspects.

[0015] Fourthly, a storage medium for firmware upgrade is provided. The storage medium is divided into an upgrade partition and a MISC. The upgrade partition stores an upgrade package. The MISC is divided into multiple blocks. The multiple blocks are written sequentially in a first writing order and each block stores upgrade control information of the upgrade package. The upgrade control information includes a status field, a progress field, and a retry count field. The storage medium stores computer instructions. When the computer instructions are executed by a processor, they implement the firmware upgrade method performed by the embedded device as described in any of the first aspects.

[0016] Compared to existing technologies that store upgrade control information in a single copy and rely on explicit version identifiers or fixed reading order to distinguish between old and new copies, the embedded device provided in this application, after the processor starts GSL, first reads the upgrade control information stored in multiple backup blocks in the upgrade control partition of the non-volatile storage medium, then verifies the validity of the multiple backup blocks to obtain at least one valid backup block, then performs three-level arbitration on the at least one valid backup block to determine the target upgrade control information, then updates the status field to the upgrade in progress status and decrements the retry count field based on the target upgrade control information, reads the upgrade package in the upgrade partition and verifies the upgrade package, then writes the upgrade data corresponding to the incomplete components in the upgrade package to the target partition according to the completion status indicated by the progress field, and updates the progress field after the components are written, and finally writes the updated upgrade control information back to the multiple backup blocks. Because this application redundantly stores upgrade control information in multiple independent backup blocks and determines the target upgrade control information from multiple copies through validity verification and three-level arbitration, the upgrade state can be restored as long as any backup block is valid. No additional version identifier field is needed to distinguish between the latest valid copy and the expired copy. This allows the upgrade to continue from the completed components after an abnormal power outage, without repeatedly upgrading completed components. This improves the storage reliability of upgrade control information on unreliable storage media, avoids the device from failing to start normally due to the loss of upgrade state, and reduces the maintenance overhead of multi-copy consistency. Attached Figure Description

[0017] To more clearly illustrate the technical solutions in the embodiments of this application, the accompanying drawings used in the description of the embodiments will be briefly introduced below. Obviously, the accompanying drawings described below are only some embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.

[0018] Figure 1 This is a schematic diagram of the firmware upgrade architecture of the embedded device provided in the embodiments of this application; Figure 2 This is a schematic diagram of an embedded device firmware upgrade application scenario provided in an embodiment of this application; Figure 3This is a schematic diagram of the upgrade control partition address division provided in an embodiment of this application; Figure 4 This is a schematic diagram of the upgrade control information structure provided in an embodiment of this application; Figure 5 This is a schematic diagram of the upgrade package structure provided in an embodiment of this application; Figure 6 This is a schematic diagram of the three-level arbitration process provided in the embodiments of this application; Figure 7 This is a schematic diagram illustrating the differentiated write order provided in the embodiments of this application; Figure 8 This is a flowchart of the firmware upgrade method provided in the embodiments of this application; Figure 9 This is a schematic diagram of the upgrade state transition provided in the embodiments of this application; Figure 10 This is a schematic diagram of the firmware upgrade control device provided in the embodiments of this application. Detailed Implementation

[0019] To make the objectives, technical solutions, and advantages of this application clearer, the embodiments of this application will be described in further detail below with reference to the accompanying drawings.

[0020] It should be understood that the term "multiple" in this application refers to two or more. In the description of this application, for the purpose of clearly describing the technical solution, the terms "first," "second," etc., are used to distinguish identical or similar items with substantially the same function and effect. Those skilled in the art will understand that the terms "first," "second," etc., do not limit the quantity or execution order, and that "first," "second," etc., do not necessarily imply differences.

[0021] The phrases such as "some embodiments" described in this application mean that one or more embodiments of this application include the specific features, structures, or characteristics described in that embodiment. Therefore, phrases such as "in some embodiments," "in other embodiments," etc., appearing in different parts of this application do not necessarily refer to the same embodiments, but rather mean "one or more, but not all, embodiments," unless otherwise specifically emphasized. Furthermore, the terms "comprising," "including," "having," and variations thereof mean "including but not limited to," unless otherwise specifically emphasized.

[0022] Example 1: Embedded device system architecture and application scenarios.

[0023] Figure 1 This is a schematic diagram of the firmware upgrade architecture of the embedded device provided in an embodiment of this application. Figure 1As shown, the embedded device 100 includes an upgrade application 101, a bootloader module 102, a storage medium 103, target firmware 104, and a processor 105. The storage medium 103 is divided into an upgrade control partition 1031 (a miscellaneous (MISC) partition) and an upgrade partition 1032. The upgrade control partition 1031 is further divided into multiple backup blocks, for example... Figure 1 The four backup blocks shown are (Block0, Block1, Block2 and Block3); the processor 105 is used to start and run the bootloader GSL (i.e. bootloader module 102) and complete the read, arbitration, update and erase operations in the firmware upgrade process in this embodiment.

[0024] In this embodiment, the upgrade application 101 runs on the operating system side (e.g., the user space of a Linux operating system), and is used to obtain and verify the upgrade package, write the upgrade package to the upgrade partition 1032 in the storage medium 103, and write the upgrade control information generated according to the upgrade package to the blocks in the upgrade control partition 1031. Multiple blocks in the upgrade control partition 1031 store upgrade control information, for example... Figure 1 Block 0, Block 1, Block 2, and Block 3 all store their respective upgrade control information. The bootloader module 102 (e.g., Generic Second-stage Loader, GSL) runs during the system startup phase. It reads the upgrade control information in the upgrade control partition 1031, performs validity verification and three-level arbitration on multiple blocks, and guides the firmware upgrade based on the upgrade control information of the target block obtained from the arbitration. It writes the upgrade data in the upgrade package into the target firmware 104. The storage medium 103, for example, is a NotAND Flash (NAND Flash), which is internally divided into an upgrade control partition 1031 and an upgrade partition 1032. Multiple blocks in the upgrade control partition 1031 are used to redundantly store upgrade control information. The target firmware 104 is the firmware component to be upgraded.

[0025] For example, the bootloaders that run sequentially after the embedded device 100 is powered on include: a memory bootloader (bootrom), a hardware-side bootloader (GSL), and a system-side bootloader (uboot); the GSL runs after the bootrom and before the uboot, and completes the reading, validity verification, and three-level arbitration of the aforementioned upgrade control information during the system startup phase, while the operating system is booted by the uboot.

[0026] In some implementations, the storage medium 103 consists of multiple independent storage units, each storage unit having a corresponding block. The multiple blocks are located on their respective storage units, and the upgrade status can be determined by reading at least one of the multiple blocks.

[0027] like Figure 1 As shown, the data flow between the upgrade application 101 and the storage medium 103 includes: the upgrade application 101 writes the upgrade package to the upgrade partition 1032 and writes upgrade control information to the upgrade control partition 1031; the data flow between the bootloader module 102 and the storage medium 103 includes: the bootloader module 102 reads upgrade control information from the upgrade control partition 1031, reads the upgrade package from the upgrade partition 1032, and writes upgrade data to the target firmware 104. The two execution entities work serially: after the upgrade application 101 completes the writing on the operating system side, it triggers a system restart; the bootloader module 102 completes the reading and upgrade execution during the system startup phase. Neither of them accesses the storage medium 103 simultaneously.

[0028] Figure 2 This is a schematic diagram illustrating an application scenario for firmware upgrades in embedded devices provided in an embodiment of this application. For example... Figure 2 As shown, firmware upgrades are implemented in the following scenario: The upgrade server 201 generates and maintains the upgrade package, and distributes the upgrade package to the embedded device 100 via a communication network 202 (e.g., a wired network or a wireless network). The embedded device 100, for example, is a smart home appliance, an IoT terminal, or other similar product. After receiving the upgrade package, it writes the upgrade package to the upgrade partition 1032 in the storage medium 103 (e.g., ...). Figure 2 As shown, the upgrade package points to the upgrade partition 1032 through the entry point of storage medium 103, and writes the corresponding upgrade control information to the upgrade control partition 1031; subsequently, the embedded device 100 restarts according to the instructions of the upgrade application 101, enters the system startup phase, and the upgrade is executed by the bootloader module 102. Since the upgrade package includes signature data for cryptographic verification, the trustworthiness of the upgrade package during transmission through the communication network 202 and writing to the storage medium 103 is confirmed by the upgrade application 101 on the operating system side through cryptographic verification before writing to the upgrade partition 1032; the bootloader module 102 performs a fast verification of the upgrade package during the system startup phase and compares the consistency of the signature data. The upgrade server 201 is, for example, a firmware management platform deployed in the cloud, which can manage the version information and upgrade policies of multiple embedded devices 100 simultaneously; the communication network 202 is, for example, a wired link, a wireless link, or a combination thereof in a local area network or a wide area network.

[0029] Example 2: Upgrade control information through multi-block redundant storage.

[0030] In this embodiment, the specific size and partitioning method of the upgrade control partition 1031 can be referred to Figure 3 .

[0031] Figure 3 This is a schematic diagram of the upgrade control partition address allocation provided in an embodiment of this application. For example... Figure 3 As shown, the upgrade control partition 1031 is 512 kilobytes in size and is divided into four independent blocks located at different physical addresses: Block0, Block1, Block2, and Block3. Each block is located at a relative offset address within the upgrade control partition 1031, for example, 0x00000, 0x20000, 0x40000, and 0x60000. Each block is 128 kilobytes in size. When the storage medium 103 is NAND Flash, each block is the same size as the erase block of the storage medium 103 and its boundaries are aligned, meaning each block occupies one erase block. This limits the impact of a single block's failure on the upgrade control information to its corresponding copy. A 64-byte copy of upgrade control information is stored at the beginning of each block, with the remaining space reserved. In this embodiment, multiple blocks in the upgrade control partition 1031 only need to be independent of each other and physically located at different physical addresses. This application does not impose specific restrictions on the specific storage size of the upgrade control partition 1031, the number and size of blocks.

[0032] It should be noted that, Figure 3The selection of the number and size of the blocks shown takes into account both fault tolerance and space overhead: each of the four blocks is an independent physical block, and as long as at least one of the four blocks is in good physical condition, the upgrade control information can be read correctly, thus tolerating the simultaneous failure of the physical blocks in which the blocks are located. Specifically, the upgrade control information has at least two (four in this embodiment) independent copies in the upgrade control partition 1031, and the upgrade status can be determined by correctly reading any copy; at the same time, the upgrade control partition 1031 accounts for a very small proportion of the overall capacity of the storage medium 103, and the probability of adding bad blocks in the upgrade control partition 1031 during operation is low. Therefore, this application embodiment adopts a fixed physical address design and fixed offset addressing for the upgrade control partition 1031, which does not require maintaining a dynamic bad block table and can also avoid marking bad blocks during operation: if a block is located at a bad block at the factory, the starting offset of the upgrade control partition 1031 can be adjusted to the adjacent good block area by the burning tool; when a single block is located at a bad block during operation, the writing of that block is silently skipped, and the other blocks continue to provide copies; only in the extreme case where the physical blocks where four blocks are located are damaged at the same time, the upgrade control information is completely unavailable. At this time, the boot loading module 102 regards it as an idle state, the device starts normally with the current firmware, does not enter the upgrade process, and retains the ability to initiate firmware upgrades again.

[0033] Figure 4 This is a schematic diagram of the upgrade control information structure provided in an embodiment of this application. For example... Figure 4 As shown, the upgrade control information consists of 64 bytes, starting from the beginning of the block and including the following: The identifier field 401 (a numerical constant, such as the preset constant 0x55504752) is used to identify whether the Block carries upgrade control information and participate in the Block's validity verification. The format version field 402 is used to indicate the format version of the upgrade control information structure, and together with the identification field 401 and the verification field 413, it is used to verify the validity of the block. The status field 403 is used to indicate the status of the upgrade cycle. The values ​​0, 1, 2, 3, and 4 correspond to the five statuses: Idle, PENDING, RUNNING, DONE, and FAILED, respectively. Upgrade package storage offset 404 is used to indicate the storage offset of the upgrade package in storage medium 103; The upgrade package size is 405, which is used to record the size of the upgrade package and cross-compare it with the total size in the upgrade package header. The upgrade package checksum 406 is used to record the checksum of the upgrade package and cross-compare it with the package checksum in the upgrade package header. Component marker bit 407 is used to indicate the set of components to be upgraded contained in the upgrade package, with each bit corresponding to one component; The retry count field 408 is used to record the remaining number of startup retries in the current upgrade cycle. Together with the transition of the status field 403, it ensures that the old upgrade cycle is forced to converge to the final state. New version information 409 and old version information 410 are used to record the target version and the current version of this upgrade, respectively. The new version information 409 is cross-compared with the firmware version information in the header of the upgrade package to prevent version rollback and cross-version errors. The progress field 411 records the completion status of each component in the upgrade package in bitmap form. Within the same upgrade cycle, its value increases monotonically as the components are completed in sequence. It is used to indicate the upgrade progress and to skip completed components after a power outage. Reserved area 412 is used for structural expansion; Verification field 413 is located in the last 4 bytes of the upgrade control information. It is the verification value of the first 60 bytes of data in the upgrade control information. Together with the identification field 401 and the format version field 402, it is used to determine whether the block is valid.

[0034] Among the above fields, the status field 403, the progress field 411, and the retry count field 408 are the core basis for the three-level arbitration during reading. The upgrade package size 405, the upgrade package verification value 406, and the new version information 409 are the first upgrade package size, the first verification value, and the first version information, respectively, and are used for cross-validation with the upgrade package header fields.

[0035] Example 3: Dual signature area and cross-verification of the upgrade package.

[0036] Figure 5 This is a schematic diagram of the upgrade package structure provided in an embodiment of this application. Figure 5 As shown, the upgrade package includes the following items sequentially from the beginning: The packet header 501 is used to record the upgrade package's identifier, format version, total size, number of components, package checksum, firmware version information, etc. Among them, the total size, firmware version information, and package checksum in the packet header 501 are the second upgrade package size, second version information, and second checksum. The first signature area 502, located after the packet header 501 and before the upgrade data in the data area 504, stores signature data, such as signature data generated by the Elliptic Curve Digital Signature Algorithm (ECDSA-P256). The component table 503 consists of multiple component description entries. Each entry records information such as the component's identifier, offset, size, and the location to be written to the target firmware 104. Data area 504 stores the upgrade data corresponding to each component; The second signature area 505 is located after the upgrade data in the data area 504, and its stored content is the same as that of the first signature area 502. The first signature area 502 and the second signature area 505 are located at the beginning and end of the upgrade package, respectively, forming a double redundant storage of signature data: that is, if either copy is damaged due to reasons such as bit flipping of the storage medium, the other copy still retains complete signature data.

[0037] In this embodiment, the coverage of the packet verification value is separated from the coverage of the signature data: the packet verification value covers the identifier, format version, total size and component quantity fields in the packet header 501, and also covers the component table 503 and the data area 504, but does not cover the first signature area 502, the second signature area 505 and the fields where the packet verification value itself is located. The firmware version information in the packet header 501 is covered by the signature data and is not covered by the packet verification value; the signature data covers all packet content except for the first signature area 502 and the second signature area 505. The two form a layered verification: the packet verification value is used by the bootloader module 102 to quickly detect storage corruption such as random bit flipping; the signature data is used at the cryptographic level to detect malicious tampering and source forgery. The tampering verification of the signature data is completed by the upgrade application 101 on the operating system side before the upgrade package is written to the upgrade partition 1032. The bootloader module 102 compares the contents of the first signature area 502 and the second signature area 505 to quickly detect storage integrity. Since the signature data also covers the field where the packet verification value is located, tampering of the packet verification value field can also be detected by the tampering verification of the upgrade application 101.

[0038] Before the upgrade package is written to the upgrade partition 1032, the upgrade application 101 verifies the signature data in the first signature area 502 and the second signature area 505 respectively. Only after the signature data in both signature areas has been verified is the upgrade package written to the upgrade partition 1032. After the upgrade package is written, the upgrade control information is written. This writing order ensures that if there is an unexpected power failure during the upgrade package writing process and the upgrade control information has not yet been written, the bootloader module 102 will start normally in the old state, and there will be no inconsistent state where the upgrade control information points to an invalid upgrade package. After the upgrade package is written, the package verification value can be calculated in streaming mode according to the same coverage area as mentioned above (i.e., the identifier, format version, total size and component quantity fields in the package header 501, as well as the component table 503 and data area 504), and recorded in the upgrade package verification value 406 of the upgrade control information.

[0039] During the system startup phase, the bootloader module 102 performs a quick verification of the upgrade package based on the upgrade package verification value 406 (i.e., the first verification value) in the upgrade control information. The verification covers the identifier, format version, total size, and component quantity fields in the package header 501, as well as the component table 503 and data area 504. At the same time, it performs a pre-check on the identifier and format version of the upgrade package, and then compares the contents of the first signature area 502 and the second signature area 505: if they match, it indicates that the upgrade package has not been corrupted during storage in the upgrade partition 1032 (the signature data in the two signature areas has been cryptographically verified by the upgrade application 101 before being written, and the double consistency indicates that the storage is complete), and the upgrade can continue. If they do not match, it indicates that at least one signature area has been corrupted during storage, and the bootloader module 102 abandons this upgrade boot and enters the system according to the normal startup process. The upgrade application 101 then retrieves the upgrade package again and triggers a new upgrade cycle.

[0040] Simultaneously, the bootloader module 102 compares the upgrade package size 405, upgrade package checksum 406, and new version information 409 (i.e., the first upgrade package size, first checksum, and first version information) in the upgrade control information with the total size, package checksum, and firmware version information (i.e., the second upgrade package size, second checksum, and second version information) in the package header 501 item by item. If all three items match, the upgrade package is confirmed to match the upgrade control information, and the upgrade continues; if any item does not match, the current upgrade boot is abandoned. Since the cross-comparison involves two physically independent areas, upgrade control partition 1031 and upgrade partition 1032, an attacker must simultaneously tamper with the corresponding fields in both areas and keep the data consistent in order to bypass the detection.

[0041] Example 4: Three-level arbitration and differentiated writing order.

[0042] Figure 6 This is a schematic diagram of the three-level arbitration process provided in the embodiments of this application. Figure 6 As shown, the bootloader module 102 performs the three-level arbitration shown in steps S101 to S105 on multiple blocks.

[0043] S101. Perform validity checks on multiple blocks to obtain at least one valid block.

[0044] In this embodiment, the bootloader module 102 can read the upgrade control information of each of the multiple blocks and perform validity verification to obtain a valid block. The validity verification involves checking the identifier field 401, the format version field 402, and the verification field 413 of each block's upgrade control information. A block that matches all three is considered a valid block, thus excluding blocks that have failed due to write interruptions, bit flips, or other reasons.

[0045] S102. Valid blocks whose status field indicates they are pending upgrade or in the process of upgrade are identified as candidate blocks.

[0046] In this embodiment, the bootloader module 102 performs status filtering: excluding blocks whose status field 403 indicates idle, completed, or failed, and obtaining candidate blocks. Idle indicates that there is currently no firmware upgrade cycle, while completed or failed indicates that the firmware upgrade cycle has ended. This status filtering is the first level of arbitration. If the number of candidate blocks is zero, it means that a firmware upgrade cannot be performed at present, and the current firmware upgrade cycle ends. If the number of candidate blocks is one, then that candidate block is the target block. If the number of candidate blocks is greater than or equal to two, these candidate blocks need to continue to execute the subsequent step S103 to determine the target block.

[0047] S103. From the candidate blocks, select the candidate block with the largest value in the progress field as the target block.

[0048] In this embodiment, the bootloader module 102 performs a progress comparison: selecting the candidate Block with the largest progress field 411 value as the target Block. Since the progress field 411 monotonically increases with the completion status of components within the same upgrade cycle, a larger value indicates a newer progress. This progress comparison is a second-level arbitration; when at least two candidate Blocks have the same maximum progress field value, these candidate Blocks need to continue with the subsequent step S104 to determine the target Block.

[0049] S104. The candidate Block with the largest value in the status field is determined as the target Block.

[0050] In this embodiment, the bootloader module 102 performs a status comparison: when at least two candidate blocks have the same progress field 411 value, both being the maximum value, the candidate block with the larger status field 403 value is selected. Since the value of the "Upgrading in Progress" status in status field 403 is greater than the value of the "Waiting to Upgrade" status, the upgrade control information in the "Upgrading in Progress" status takes precedence over the upgrade control information in the "Waiting to Upgrade" status, and the target block can ultimately be determined. This status comparison is a third-level arbitration.

[0051] S105. Obtain the target block.

[0052] In this embodiment of the application, the target upgrade control information is determined according to the above three-level arbitration, so that the target upgrade control information uniquely corresponds to a latest and valid upgrade control information, and instructs the target Block.

[0053] It should be noted that the reliability of the status filtering in step S102 of this application relies on the forced convergence mechanism of the retry count field 408: when the upgrade control information is written, the retry count field 408 is initialized to a preset value; the bootloader module 102 decrements it once before each boot upgrade, and each round of "from system startup to determining whether the upgrade is successful or failed" consumes one count, rather than each component consuming one; when the firmware upgrade fails and the retry count field 408 is greater than zero, the status field 403 is written back to pending upgrade and the decremented count is retained, waiting for the next startup to retry; when the firmware upgrade fails and the retry count field 408 returns to zero, the status field 403 is forcibly changed to failure. Therefore, the old upgrade cycle either completes naturally and turns to the completed state, or exhausts the number of retries and turns to the failure state. It is impossible for the upgraded state to remain indefinitely, and the status filtering will not misjudge the expired cycle as an active cycle.

[0054] It should be noted that the state comparison method provided in this application embodiment embodies a design strategy of prioritizing older cycles: In extreme cases (such as multiple power outages and interruption before the retry count is exhausted), there may be a coexistence of the upgrade copy in the old upgrade cycle and the upgrade copy to be upgraded in the new upgrade cycle. In this case, the copy of the old upgrade cycle is selected first, and the old upgrade that has been partially executed is completed first. The reason is that: on the one hand, some component data of the old upgrade cycle has been written, and abandoning it will cause the written data to be invalid; on the other hand, the upgrade package corresponding to the new upgrade cycle may not have been written or only partially written, and the probability of continuing the old upgrade is higher; at the same time, through cross-validation of the new version information 409 and the old version information 410, upgrade packages with inconsistent versions can be prevented from being executed. Combining the above mechanism, the semantic reuse of the status field 403 and the progress field 411 can complete cross-cycle identification and breakpoint resumption, without the need to set an additional explicit cycle number field.

[0055] Figure 7 This is a schematic diagram illustrating the differentiated write order provided in an embodiment of this application. For example... Figure 7 As shown, the upgrade application 101 updates multiple blocks in the upgrade control partition 1031 according to the first write order 701 (ascending order, from Block0 to Block3); the bootloader module 102 updates multiple blocks according to the second write order 702 (reverse order, from Block3 to Block0); the first write order 701 and the second write order 702 are opposite, the sets of blocks that the two write subjects prioritize writing to are staggered, and at the same time, only the target block is erased before each write.

[0056] It should be noted that the purpose of using the first write order 701 in the opposite order to the second write order 702 includes: differentiated writing makes the number of erases and writes of the four blocks more uniform, avoiding repeated erases and writes of the same block and thus accelerating wear; since the write operation does not require all blocks to be written successfully, as long as at least one block is written successfully, the upgrade control information can be read correctly. Therefore, no matter when the power failure occurs during the execution of which writing subject, or which subject continues writing after restarting, some blocks will always retain the valid data written by the previous writer and will not be overwritten by the new write, ensuring that the three-level arbitration always has enough candidate blocks for evaluation.

[0057] After the upgrade cycle ends (status field 403 indicates completion or failure), all blocks are erased, restoring them to a fully invalid state. For example, if a power outage occurs during the erasure process, the identifier field 401 of erased blocks becomes invalid and will be excluded from validity checks; the status field 403 of unerased blocks indicates completion or failure and will be excluded from the first-level arbitration status filtering; after two rounds of filtering, no candidate blocks exist, the arbitration result is idle, the system starts normally, and there will be no situation where an old completed state is mistakenly selected as the latest state.

[0058] Example 5: Firmware upgrade method.

[0059] Figure 8 This is a flowchart of the firmware upgrade method provided in an embodiment of this application. Figure 8 As shown, the method is executed by the processor 105 of the embedded device 100 running the bootloader module 102, and consists of the following steps S201 to S207.

[0060] S201. Start GSL and read the upgrade control information stored in each of the multiple blocks.

[0061] In this embodiment, the GSL reads the upgrade control information stored in each of the multiple blocks in the upgrade control partition 1031 of the storage medium 103, providing data for subsequent validity verification and three-level arbitration.

[0062] S202. Based on the status and progress fields in the upgrade control information, perform three-level arbitration on multiple blocks to obtain the target block.

[0063] In this embodiment, each block is first validated for validity by verifying the identifier field 401, format version field 402, and verification field 413 of the upgrade control information. Blocks that match all three are determined to be valid blocks. Blocks damaged due to write interruption, bit flip, or other reasons are excluded. Then, a three-level arbitration is performed on the valid blocks to determine the target upgrade control information: first, candidate blocks to be upgraded or in the process of upgrading are filtered by the status field 403; then, the block with the largest progress field 411 value is selected. If there are multiple candidate blocks with the same progress, the block with the larger status field 403 value is selected. The specific rules of the three-level arbitration can be found in the aforementioned embodiment four, and will not be repeated here.

[0064] S203. Update the upgrade control information in the target block, including updating the status field to the upgrade in progress status and decrementing the retry count field.

[0065] In this embodiment, the status field 403 in the target upgrade control information is updated to the upgrade in progress state, and the retry count field 408 is decremented. Specifically, when the firmware upgrade fails and the retry count field 408 reaches zero, the status field 403 is updated to the failure state. Subsequently, the updated upgrade control information is written back to all blocks according to the second write order 702, so that the copies in each block synchronously enter the upgrade in progress state.

[0066] For example, during the write-back process in step S203 above, if a power outage occurs at Block 2: after restarting, Block 3 becomes the new state copy in the upgrade process, Block 2 may become invalid due to write interruption, and Blocks 0 and 1 become the old state copies to be upgraded. The first-level state filtering retains Blocks 3, 0, and 1. During the second-level progress comparison, the progress field 411 value of Block 3 is not less than that of Blocks 0 and 1. During the third-level state comparison, the value of the upgrade-in-progress state is greater than the value of the state to be upgraded. Therefore, the upgrade-in-progress copy carried by Block 3 is selected to continue execution, and the completed components indicated by its progress field 411 are skipped, and incomplete components are written. In the case of multiple power outages and interruptions before the retry count is exhausted, if the upgrade-in-progress copy of the old upgrade cycle and the expected upgrade copy of the new upgrade cycle coexist, the old upgrade cycle copy is selected first during the third-level state comparison until the retry count field 408 is exhausted and the old upgrade cycle enters the failure state. Only then will the new upgrade cycle be taken over, thereby ensuring the convergence of the upgrade process.

[0067] S204. Read the upgrade package and perform multiple verifications.

[0068] In this embodiment, the upgrade package is first quickly verified based on the upgrade package verification value 406 in the upgrade control information (the verification scope includes the identifier, format version, total size, and component quantity fields in the package header 501, as well as the component table 503 and data area 504), and the identifier and format version of the upgrade package are pre-checked; then, the signature data in the first signature area 502 and the second signature area 505 are compared to see if they are consistent. If they are consistent, it indicates that the upgrade package has not been damaged during storage and can continue; if they are inconsistent, the upgrade boot is terminated, and the system is entered according to the normal startup process, and the upgrade application 101 re-acquires and distributes the upgrade package; then, the upgrade package size 405, upgrade package verification value 406, and new version information 409 in the upgrade control information are compared item by item with the total size, package verification value, and firmware version information in the package header 501 of the upgrade package. Only if all three items are consistent can the upgrade continue. The specific verification mechanism can be found in the aforementioned embodiment three, which will not be repeated here.

[0069] S205. Based on the progress field indicating the completion status of the firmware upgrade, write the corresponding upgrade data into the upgrade package for firmware that has not been upgraded.

[0070] In this embodiment, based on the completion flag of the progress field 411, components with completed flags are skipped, and only components with incomplete flags are written with corresponding upgrade data to the target firmware 104; after each component is written, the progress field 411 is updated based on the current firmware upgrade completion status, wherein, after multiple verifications pass and all firmware that has not completed the upgrade has been written with upgrade data, the status field 403 is updated to the completion status.

[0071] S206. Write back the updated upgrade control information to multiple blocks in the second write order.

[0072] In this embodiment of the application, after each update of the progress field 411, the updated upgrade control information is written back to all blocks in the second writing order 702, so that the upgrade control information in each block remains synchronized.

[0073] S207. After the firmware upgrade in GSL is successful or fails, erase the data in MISC and end the firmware upgrade in GSL.

[0074] In this embodiment, after all components are written, GSL updates the status field 403 to "complete" and ends the current upgrade cycle. Then, it erases all data in the upgrade control partition 1031 (i.e., MISC), and the system starts normally. If the firmware upgrade fails and the retry count field 408 is greater than zero, the status field 403 is written back to "pending upgrade" and the remaining count is retained, waiting for the next startup to retry. If the firmware upgrade fails and the retry count field 408 returns to zero, the status field 403 is forcibly changed to "failure" and the upgrade cycle ends.

[0075] It should be noted that if a power outage occurs during any of the above steps, the method will be re-executed after the system restarts: Blocks successfully written before the power outage will retain the latest progress; Blocks whose writing was interrupted may be excluded due to the failure of the identification field 401 or the verification field 413; Due to the differentiated writing order and the fault-tolerant design that at least one Block can be read after successful writing, there will always be a valid Block after the power outage. The three-level arbitration selects the one with the latest progress from the remaining valid Blocks, and the bootloader module 102 can continue to upgrade the unfinished components from the disconnection position indicated by the progress field 411. Completed components will not be upgraded repeatedly.

[0076] Figure 9 This is a schematic diagram of the upgrade state transition provided in an embodiment of this application. For example... Figure 9 As shown, the status field 403 in the upgrade control information can be converted in the following order during the upgrade cycle.

[0077] Idle state S1 indicates no upgrade cycle is currently in progress. Upon writing upgrade control information, it enters the pending upgrade state S2. After the upgrade application 101 writes the upgrade package to the upgrade partition 1032 and the upgrade control information on the operating system side, it triggers a system restart. During the startup phase, the bootloader module 102 updates the pending upgrade state S2 to the upgrading in progress state S3 and decrements the retry count field 408, corresponding to the above... Figure 8 Steps S201 to S203 are performed as follows: When multiple checks pass and all components are written, the upgrade status S3 is updated to the completed status S4, corresponding to step S207; when a failure occurs during the upgrade process and the retry count field 408 is greater than zero, the upgrade status S3 is written back to the pending upgrade status S2, and the decremented remaining count is retained to wait for the next restart retry; when a failure occurs during the upgrade process and the retry count field 408 returns to zero, the upgrade status S3 is forcibly updated to the failure status S5; after the upgrade cycle ends (i.e., the upgrade status S3 is updated to the completed status S4 or the failure status S5), all blocks are erased, and the upgrade control information is restored to the idle status S1.

[0078] In this embodiment, the pending upgrade state S2 and the upgrading in progress state S3 are active upgrade states, while the completed state S4 and the failed state S5 are terminated states. In the three-level arbitration, the state filtering only retains blocks with state field 403 as either pending upgrade state S2 or upgrading in progress state S3; therefore, blocks in terminated states do not participate in arbitration. The values ​​of idle state S1, pending upgrade state S2, upgrading in progress state S3, completed state S4, and failed state S5 are 0, 1, 2, 3, and 4, respectively. When the progress is the same, the state comparison selects the one with the larger value of state field 403, i.e., upgrading in progress state S3 takes priority over pending upgrade state S2. This, combined with the decrementing and zeroing of the retry count field 408, ensures that the old upgrade cycle is forcibly converged to the completed state S4 or the failed state S5, and will not remain in the upgrading in progress state S3 for a long time, so that the new upgrade cycle can be taken over. This state transition logic corresponds one-to-one with the three-level arbitration shown in Embodiment 4 and steps S201 to S207 of this embodiment.

[0079] Example 6: Firmware upgrade control device.

[0080] Figure 10 This is a schematic diagram of the firmware upgrade control device provided in an embodiment of this application. Figure 10 As shown, the firmware upgrade control device 1000 includes, as follows: Figure 1 The storage medium 103 shown, the firmware upgrade control device 1000 includes the following modules.

[0081] The information acquisition module 1010 is used to read the upgrade control information stored in each of the multiple blocks after GSL is started.

[0082] The information arbitration module 1020 is used to perform three-level arbitration on multiple blocks based on the status and progress fields in the upgrade control information to obtain the target block.

[0083] The upgrade guidance module 1030 is used to update the upgrade control information in the target block, including updating the status field to the upgrade in progress status and decrementing the retry count field. When the firmware upgrade fails and the retry count field reaches zero, the status field is updated to the failure status. The updated upgrade control information is written back to multiple blocks in the second write order.

[0084] The upgrade update module 1040 is used to read the upgrade package and perform multiple verifications. Based on the progress field indicating the completion status of the firmware upgrade, it writes the corresponding upgrade data into the upgrade package for firmware that has not been upgraded and updates the progress field based on the current completion status of the firmware upgrade. After the multiple verifications pass and all firmware that has not been upgraded has been written with upgrade data, the status field is updated to the completion status. The updated upgrade control information is written back to multiple blocks in the second writing order.

[0085] The information erasure module 1050 is used to erase the data in MISC after the firmware upgrade of GSL is successful or unsuccessful, and end the firmware upgrade of GSL.

[0086] Among them, the information acquisition module 1010 reads upgrade control information from the storage medium 103, the upgrade update module 1040 writes upgrade data into the target firmware, and the data flow between the modules is as follows: Figure 8 The steps shown correspond to the method.

[0087] It should be noted that the above embodiments are described using NAND flash memory as an example; for NOR flash memory, it does not have the bad block characteristics of NAND flash memory, and the upgrade control information can be simply stored in a single erase block, without the need for multiple redundant blocks. In addition, the upgrade package can also be stored in the upgrade partition 1032 via an Unsorted Block Image (UBI) static volume. After the upgrade is completed, the static volume is erased, and after the system restarts, it is converted into a UBI dynamic volume and mounted for use, so that the upgrade partition 1032 can be reused as a daily writable storage space.

[0088] It should be noted that the technical features provided in this application embodiment can all be detected and used for evidence collection, including: the values ​​of multiple blocks in the upgrade control partition 1031 and their respective stored upgrade control information, the values ​​of the identifier field 401, format version field 402, status field 403, progress field 411, and retry count field 408 in each block, the structure of the first signature area 502 and the second signature area 505 in the upgrade package and whether their contents are consistent, and the cross-comparison relationship between the upgrade package parameter group in the upgrade control partition 1031 and the corresponding parameters in the package header 501 in the upgrade package, all of which can be directly determined by reading the corresponding data in the device storage medium; in addition, after an abnormal power outage and power-on during the firmware upgrade process, it can be observed that the components that have been written with upgrade data are not written again, and the current firmware upgrade continues from the disconnection position indicated by the progress field 411.

[0089] The various embodiments of this application can be combined arbitrarily to achieve different technical effects.

[0090] This application also provides a chip for running a bootloader, including a storage unit and a processing unit; the storage unit is divided into an upgrade partition and a MISC, the upgrade partition stores an upgrade package, the MISC is divided into multiple blocks, the multiple blocks are written sequentially according to a first writing order and each stores upgrade control information of the upgrade package; the upgrade control information includes a status field, a progress field and a retry count field; the processing unit includes one or more processors, the processors are used to call computer instructions to execute the functions involved in the firmware upgrade method executed by the processor 105 of the embedded device 100 running GSL in any of the above embodiments.

[0091] In some implementations, the chip may contain one or more processors. These processors can be implemented in hardware or software. When implemented in hardware, the processor can be a logic circuit, an integrated circuit, etc. When implemented in software, the processor can be a general-purpose processor that reads software code stored in memory.

[0092] In some implementations, the chip may contain one or more memories. The memories may be integrated with the processor or disposed separately from it; this application does not limit this. Exemplarily, the memories may be integrated with the processor on the same chip or disposed on different chips. This application does not specifically limit the type of memory or the arrangement of the memories and the processor.

[0093] For example, the chip may be a field programmable gate array (FPGA), application specific integrated circuit (ASIC), system on chip (SoC), central processor (CPU), network processor (NP), digital signal processor (DSP), micro controller unit (MCU), programmable logic device (PLD), or other integrated chip.

[0094] This application also provides a storage medium, which is divided into an upgrade partition and a MISC. The upgrade partition stores an upgrade package, and the MISC is divided into multiple blocks. The multiple blocks are written sequentially in a first writing order and each block stores upgrade control information of the upgrade package. The upgrade control information includes a status field, a progress field, and a retry count field. The storage medium stores computer instructions, which, when executed by a processor, implement the firmware upgrade method executed by the processor 105 of the embedded device 100 in any of the above embodiments.

[0095] In the embodiments provided in this application, implementation can be achieved, in whole or in part, through software, hardware, firmware, or any combination thereof. When implemented using software, it can be implemented, in whole or in part, in the form of a computer program product.

[0096] The computer program product includes one or more computer instructions. When these computer program instructions are loaded and executed on a computer, all or part of the processes or functions described in this application are generated. The computer may be a general-purpose computer, a special-purpose computer, a computer network, or other programmable device.

[0097] Those skilled in the art will understand that implementing all or part of the processes in the methods of the foregoing embodiments can be accomplished by a computer program instructing related hardware. The program can be stored in a computer-readable storage medium, and when executed, it can include the processes of the foregoing method embodiments.

[0098] In summary, the above description is merely an embodiment of the technical solution of this application and is not intended to limit the scope of protection of this application. Any modifications, equivalent substitutions, improvements, etc., made based on the disclosure of this application should be included within the scope of protection of this application.

Claims

1. An embedded device for firmware upgrades, characterized in that, The system includes a storage medium and a processor. The storage medium is divided into an upgrade partition and an upgrade control partition (MISC). The upgrade partition stores upgrade packages. The MISC is divided into multiple blocks, which are written sequentially in a first write order and each block stores upgrade control information of the upgrade package. The upgrade control information includes a status field, a progress field, and a retry count field. The processor is used to start and run the bootloader GSL, thereby performing the following steps: Read the upgrade control information stored in each of the multiple blocks; Based on the status field and the progress field in the upgrade control information, the multiple blocks are arbitrated at three levels to obtain the target block; Updating the upgrade control information in the target block includes updating the status field to an upgrade in progress state and decrementing the retry count field, wherein when the firmware upgrade fails and the retry count field reaches zero, the status field is updated to a failure state; the updated upgrade control information is written back to the plurality of blocks in a second write order, the second write order being the reverse of the first write order; The upgrade package is read and multiple verifications are performed. Based on the progress field indicating the completion status of the firmware upgrade, the corresponding upgrade data for firmware that has not been upgraded is written into the upgrade package. The progress field is updated based on the current completion status of the firmware upgrade. After the multiple verifications pass and all firmware that has not been upgraded is written into the upgrade data, the status field is updated to the completion status. The updated upgrade control information is written back to the multiple blocks in the second writing order. After the firmware upgrade of GSL is successful or fails, the data in MISC is erased, and the firmware upgrade of GSL ends.

2. The embedded device according to claim 1, characterized in that, The processor performs three-level arbitration on the multiple blocks based on the status field and the progress field in the upgrade control information to obtain the target block, specifically for: The status of the multiple blocks is filtered, and the blocks whose status field indicates a state of pending upgrade or in the process of upgrade are identified as candidate blocks. From the candidate Blocks, select the candidate Block with the largest value in the progress field as the target Block; When at least two candidate blocks have the same maximum value in their progress field, the candidate block with the largest value in its status field is determined as the target block. The value of the upgrade-in-progress state is greater than the value of the state to be upgraded.

3. The embedded device according to claim 1, characterized in that, The processor is further configured to perform validity verification on the plurality of blocks before performing three-level arbitration on the plurality of blocks based on the status field and the progress field in the upgrade control information, to obtain at least one valid block, and then perform the three-level arbitration on the at least one valid block; The validity verification includes: for each block, verifying the identifier field, format version field, and verification field of the upgrade control information in the block; and determining the block that matches the identifier field, the format version field, and the verification field as a valid block.

4. The embedded device according to claim 1, characterized in that, The upgrade package includes a first signature area before the upgrade data and a second signature area after the upgrade data, wherein the signature data stored in the first signature area and the second signature area are the same; The processor reads the upgrade package and performs multiple verifications, specifically for: The upgrade package is subjected to a signature consistency check, which is used to compare whether the signature data in the first signature area and the second signature area are consistent.

5. The embedded device according to claim 4, characterized in that, When the signature data in the first signature area is consistent with that in the second signature area, it is confirmed that the upgrade package was not damaged during storage in the upgrade partition; When the signature data in the first signature area and the second signature area are inconsistent, the firmware upgrade is terminated, and the device system is started according to the startup process.

6. The embedded device according to claim 5, characterized in that, The upgrade control information includes a first upgrade package parameter group, the upgrade package includes a second upgrade package parameter group located in the header region, and the processor is further configured to: Obtain the first upgrade package parameter group from the upgrade control information of the target block, and the second upgrade package parameter group from the upgrade package header area; the first upgrade package parameter group includes the first upgrade package size, the first version information and the first check value, and the second upgrade package parameter group includes the second upgrade package size, the second version information and the second check value; The upgrade package is quickly verified based on the first verification value, and the signature consistency is verified based on the signature data. When the corresponding parameters in the first upgrade package parameter group and the second upgrade package parameter group are consistent, it is confirmed that the upgrade package matches the upgrade control information of the target block, and the firmware upgrade continues.

7. The embedded device according to claim 1, characterized in that, The plurality of blocks in the MISC have different numbers arranged from low to high. The first writing order is the order in which the plurality of blocks are written from low to high number, and the second writing order is the order in which the plurality of blocks are written from high to low number. The storage medium consists of multiple independent storage units, each of which is located on its own storage unit. The upgrade status can be determined by reading at least one of the multiple blocks.

8. A control device for firmware upgrades, characterized in that, The storage medium includes an upgrade partition and a MISC. The upgrade partition stores an upgrade package. The MISC is divided into multiple blocks. The multiple blocks are written sequentially in a first write order and each block stores the upgrade control information of the upgrade package. The multiple blocks are written back sequentially in a second write order, which is the reverse of the first write order. The upgrade control information includes a status field, a progress field, and a retry count field; the device includes: The information acquisition module is used to read the upgrade control information stored in each of the multiple blocks after GSL is started; The information arbitration module is used to perform three-level arbitration on the multiple blocks based on the status field and the progress field in the upgrade control information to obtain the target block; An upgrade guidance module is used to update the upgrade control information in the target block, including updating the status field to the upgrade in progress state and decrementing the retry count field, wherein when the firmware upgrade fails and the retry count field reaches zero, the status field is updated to the failure state; and the updated upgrade control information is written back to the multiple blocks in a second writing order. The upgrade and update module is used to read the upgrade package and perform multiple verifications, and according to the progress field indicating the completion status of the firmware upgrade, write the corresponding upgrade data in the upgrade package for firmware that has not been upgraded, and update the progress field based on the current completion status of the firmware upgrade. After the multiple verifications pass and all firmware that has not been upgraded has been written with the upgrade data, the status field is updated to a completed status. The updated upgrade control information is then written back to the multiple blocks according to the second writing order. The information erasure module is used to erase the data in the MISC after the firmware upgrade of the GSL is successful or unsuccessful, thereby ending the firmware upgrade of the GSL.

9. A chip for firmware upgrades, the chip being used to run a bootloader, characterized in that, The chip includes a storage unit and a processing unit; The storage unit is divided into an upgrade partition and a MISC. The upgrade partition stores the upgrade package. The MISC is divided into multiple blocks. The multiple blocks are written sequentially according to a first write order and each block stores the upgrade control information of the upgrade package. The upgrade control information includes a status field, a progress field, and a retry count field. The processing unit includes one or more processors, which are configured to invoke computer instructions to execute the firmware upgrade method performed by the processor in the embedded device as described in any one of claims 1-7.

10. A storage medium for firmware upgrades, characterized in that, The storage medium is divided into an upgrade partition and a MISC. The upgrade partition stores the upgrade package. The MISC is divided into multiple blocks. The multiple blocks are written sequentially in a first writing order and each block stores the upgrade control information of the upgrade package. The upgrade control information includes a status field, a progress field, and a retry count field; The storage medium stores computer instructions, which, when executed by a processor, implement the firmware upgrade method performed by the embedded device as described in any one of claims 1-7.