A firmware upgrading device and a firmware upgrading method and system thereof
Patent Information
- Application Number
- CN202211666522.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-12-23
- Publication Date
- 2026-09-15
- Estimated Expiration
- 2042-12-23
AI Technical Summary
1、有些设备在升级过程中发生断电或复位会导致数据错误,严重的可能导致固件升级设备不能使用,加大了升级的危险性
(1)本发明能够解决因升级代码导致的设备不能运行的问题。
Smart Images

Figure CN115981700B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of firmware upgrade technology, and in particular to a firmware upgrade device, firmware upgrade method and system. Background Technology
[0002] Firmware upgrades involve enhancing the functionality of a currently running chip. In today's environment, with the advancement of chip technology, more and more aspects of daily life require chip control. As the demand for chip functionality increases, but the chip's physical form factor is unsuitable for frequent replacement, firmware upgrade technology has emerged as a solution.
[0003] Currently, there are various methods for firmware upgrades, such as online upgrades and boot upgrades. These methods can upgrade the chip's original functions while maintaining compatibility with existing features and preserving original data. This ensures that user needs for chip functionality are met to the greatest extent possible.
[0004] Existing technologies have the following drawbacks in firmware upgrades: 1. Some devices may experience data errors due to power outages or resets during the upgrade process, which in severe cases may render the firmware upgrade device unusable, increasing the risk of the upgrade.
[0005] 2. If there is a power outage or reset during the upgrade process, data will be lost, and the data transfer will need to start from scratch the next time the power is restored; this increases the upgrade time and shortens the lifespan of the firmware upgrade device.
[0006] 3. For firmware upgrade devices that support resumed transmission, some data may be lost on the upgrade host or firmware upgrade device after power failure or reset, and needs to be resent subsequently; this reduces upgrade efficiency and may increase data transmission risks.
[0007] For the current SIM card service, data upgrades also involve user privacy data. In these situations, the upgrade solution must balance data integrity and security while ensuring efficient and universal firmware upgrades. Summary of the Invention
[0008] This invention provides a firmware upgrade device, comprising: a chip and a storage space. The chip runs a COS region and a user region. The COS region is divided into COSA and COSB, which share the user region and the storage space of the firmware upgrade device. COSA and COSB serve as backup areas for each other. When performing a firmware upgrade, one upgrade region runs the current code, while the other upgrade region performs the firmware upgrade. The COSA and COSB running spaces are divided into native code space and programming code space. The native code space and programming code space occupied by COSA and COSB in the storage space are not contiguous. The storage space sequentially includes the native code space of COSA, the native code space of COSB, the user data space, the programming code space of COSA, and the programming code space of COSB. The storage space is divided into a corresponding number of data blocks according to the upgrade data block number. There is a corresponding mapping relationship between the block number and the data block address. Each data block stores the corresponding upgrade data block.
[0009] The firmware upgrade method described above, when applied to the aforementioned firmware upgrade device, includes: The firmware upgrade device calculates the size and location of the COSA and COSB regions that can store upgrade code, and uses a mapping function to associate the native code region and the programming code region. In response to receiving an upgrade command from the host, the firmware upgrade device obtains the total number of blocks to be upgraded and the size of the upgrade data from the upgrade command; The firmware upgrade device determines the currently running COS region, takes another COS region as the current upgrade region, divides the storage space into n blocks according to the block number based on the data size in the upgrade command and the total number of blocks in the upgrade command, and maps the block number to the corresponding storage space address; The firmware upgrade device sequentially stores the upgrade data sent by the host into the corresponding storage space address. If the data transmission is interrupted, it resumes the transmission based on the data already stored in the storage space. After all the upgrade data has been received, it switches to the current upgrade area to run the newly downloaded code.
[0010] In the firmware upgrade method described above, the upgrade command specifically includes the upgrade version issued by the host, the upgrade data size, the total number of upgrade blocks, the upgrade block size, and the upgrade block number.
[0011] In the firmware upgrade method described above, if the firmware upgrade device experiences a transmission interruption, it informs the host of the block number u that has been downloaded and the upgrade data for this operation. When the firmware upgrade device receives the block number u+1 sent by the host, it directly maps to the upgrade address corresponding to the block number u+1 and continues the upgrade operation from this address.
[0012] In the firmware upgrade method described above, if a transmission interruption occurs on the host side, the firmware upgrade device does not process the upgrade data before the already downloaded block number u. When it receives the block number u+1 sent by the host side, it directly maps to the upgrade address corresponding to the block number u+1 and continues the upgrade operation from this address.
[0013] In the firmware upgrade method described above, if the firmware upgrade device experiences a transmission interruption, the firmware upgrade device informs the host of the size v of the downloaded data and other information about the currently upgraded version, directly receives the upgrade data after v sent by the host, and locates the address to be upgraded next based on the starting address of the current upgrade space.
[0014] In the firmware upgrade method described above, if a transmission interruption occurs on the host side, the firmware upgrade device checks whether the upgrade data is the same as the upgrade data version and upgrade data size information in the upgrade command sent by the host side. If the upgrade data is the same, the firmware upgrade device records the size v of the currently sent data and the size s of the data sent in this command. If the recorded upgrade data size (v+s)<=k, the device finds the location where the downloaded content should be stored by adding v to the starting position of the upgrade storage. It then retrieves data of length s from this location and compares it with the data sent in this command. If they are the same, the device continues to receive the next data sent by the host side. If they are different, the device needs to send data to the current storage location until u>k. At this point, the firmware upgrade device starts to directly write the data to the corresponding position calculated based on the data size until the upgrade ends.
[0015] The present invention also provides a firmware upgrade system, including a host and a firmware upgrade device, characterized in that it includes: The host prepares the necessary upgrade version and upgrade data, and organizes the upgrade commands; The host sends an upgrade command to the firmware upgrade device, informing the firmware upgrade device of the upgrade version and upgrade data size; The firmware upgrade device processes upgrade commands and prepares accordingly to receive upgrade data; The host sends upgrade data to the firmware upgrade device; The firmware upgrade device performs one of the firmware upgrade methods described above.
[0016] In the firmware upgrade system described above, during the upgrade data preparation phase, the host divides the upgrade data of size m into n upgrade blocks according to a preset data size, with each upgrade block being m / n in size. When sending the upgrade command, the host informs the firmware upgrade device of the total number of blocks n to be upgraded and the data size m.
[0017] In the firmware upgrade system described above, each upgrade data sent by the host is preceded by a block number of the upgrade data, which increases sequentially as more data is sent.
[0018] The beneficial effects achieved by this invention are as follows: (1) The present invention can solve the problem of devices not being able to operate due to upgrade code.
[0019] (2) This invention enables breakpoint resume, which can avoid the problem of device failure due to upgrade failure during the upgrade process; at the same time, because of the system's resume function, it can ensure that if a problem occurs on the host or device side during the upgrade process, the upgrade content can be quickly identified, so as to carry out subsequent upgrade operations. While saving upgrade time, it also avoids the repeated erasure and writing of flash due to repeated sending of upgrade commands, thereby shortening the lifespan of the device chip.
[0020] (3) The firmware upgrade device of the present invention has an upgrade memory function. If the upgrade host loses the resume data, it will issue a re-upgrade command. When the upgrade function version is the same as the previous upgrade function version, the device chip will check the upgraded content and quickly locate the undownloaded part by receiving data but not storing it. This can avoid the upgrade speed reduction caused by the loss of data on the upgrade host and avoid the transmission risk caused by repeated data transmission. Attached Figure Description
[0021] To more clearly illustrate the technical solutions in the embodiments of the present invention or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments recorded in the present invention. For those skilled in the art, other drawings can be obtained based on these drawings.
[0022] Figure 1 is a schematic diagram of a firmware upgrade device provided in Embodiment 1 of the present invention; Figure 2 is a flowchart of a firmware upgrade method provided in Embodiment 2 of the present invention; Figure 3 is a flowchart of the specific operation of the host sending upgrade commands to the firmware upgrade device; Figure 4 is a flowchart of the working method of the firmware upgrade system provided in Embodiment 3 of the present invention. Detailed Implementation
[0023] The technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some, not all, of the embodiments of the present invention. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.
[0024] Example 1 like Figure 1 As shown, Embodiment 1 of the present invention provides a firmware upgrade device. The firmware upgrade device includes a chip and storage space. The chip of the firmware upgrade device runs a COS region and a user region. The COS region is divided into COSA and COSB. COSA and COSB share the user region and the storage space of the firmware upgrade device. COSA and COSB serve as backup areas for each other. When performing a firmware upgrade, one upgrade region runs the current code, while the other upgrade region performs the firmware upgrade. For example, if COSA is currently the running region, when performing a firmware upgrade, the upgrade content is downloaded to COSB to prevent affecting the normal operation of COSA. This solves the problem of the firmware upgrade device failing to operate due to upgrade code.
[0025] The runtime space of COSA and COSB is divided into native code space and programming code space (such as Java code space). For the sake of unified management, the native code space and programming code space occupied by COSA and COSB in the storage space are not contiguous.
[0026] For example, in the storage space: 0x00000000-0x03000000: COSA's native code space; 0x03000000-0x06000000: COSB's native code space; 0x06000000-0x07000000: User data space; 0x07000000-0x10000000: COSA's programming code space; 0x10000000-0x13000000: COSB programming code space.
[0027] If we visualize the storage space as a linear block, it is represented as:
[0028] Figure 4 The storage space allocation structure diagram shows that the storage space is divided into a corresponding number of data blocks n according to the upgrade data block number. There is a corresponding mapping relationship between the block number and the data block address, and each data block stores the corresponding upgrade data block.
[0029] Example 2 like Figure 2 As shown, Embodiment 2 of the present invention provides a firmware upgrade method, including: Step 210: The firmware upgrade device calculates the size and location of the COSA and COSB regions that can store upgrade code, and uses a mapping function to associate the native code region and the programming code region; For example, after downloading the COSA_native code segment 0x02FFFFFF, the next address associated with the COSA code segment is the starting address of the COSA_programming code segment 0x07000000; after downloading the COSB_native code segment 0x05FFFFFF, the next address associated with the COSB code segment is the starting address of the COSA_programming code segment 0x10000000.
[0030] Step 220: In response to receiving the upgrade command sent by the host, the firmware upgrade device obtains the total number of blocks to be upgraded and the size of the upgrade data from the upgrade command; In this embodiment, during the upgrade data preparation phase, the host pre-divides the upgrade data of size m into n upgrade blocks according to a preset data size. Each upgrade block is m / n in size. When sending the upgrade command, the host informs the firmware upgrade device of the total number of blocks n to be upgraded and the data size m. Each upgrade data sent by the host is preceded by a block number, which increases sequentially as more data is sent.
[0031] See back Figure 2 Step 230: The firmware upgrade device determines the currently running COS region, takes another COS region as the current upgrade region, divides the storage space into n blocks according to the block number based on the data size in the upgrade command and the total number of blocks in the upgrade command, and maps the block number to the corresponding storage space address.
[0032] After receiving the upgrade command, the firmware upgrade device first needs to determine which region the currently running COS is in. If COSA is the currently running COS, then the space to be downloaded for the upgrade is the COSB region. Subsequently, the COS, in conjunction with its own storage space, and based on the size of the upgrade data and the total number of blocks in the upgrade command, divides the storage space into n blocks according to the block number. The block number can then be mapped to the corresponding storage space address.
[0033] For example: If the current COS is in the COSA region, the data to be upgraded is 0x6000000, and the host has divided the data into 0x66667 blocks, with each block except the last one being 0xF0, then the COSB partition is as follows: Block 0-0x33333 is located in the native code region 0x00000000-0x05FFFFCF of COSB; Block 0x33334 is composed of the native code region of COSB (0x05FFFFD0-0x05FFFFFF) and the programming code region of COSB (0x10000000-0x100000C0). Blocks 0x33335-0x66667 are located in the COSB programming code region 0x100000C0-0x12FFFFFF.
[0034] Step 240: The firmware upgrade device sequentially stores the upgrade data sent by the host into the corresponding storage space address. If the data transmission is interrupted, the device resumes the transmission based on the data already stored in the storage space. After all the upgrade data has been received, the device switches to the current upgrade area to run the newly downloaded code. Specifically, the firmware upgrade device stores the upgrade version issued by the host, the upgrade data size, the total number of upgrade blocks, and the size of each upgrade block. Additionally, the firmware upgrade device maintains a region in its storage space containing the downloaded upgrade blocks to prevent data loss in case of power failure.
[0035] Each time the firmware upgrade device receives an upgrade block from the host, it first checks whether the block number of the data sent by the host is correct (i.e., whether the number of downloaded blocks maintained by the firmware upgrade device + 1 equals the data block number sent by the host) and whether the data length is the same as the upgrade block size stored on the device. Then, the firmware upgrade device writes the received data to the storage space address corresponding to the block number. After writing, the number of downloaded blocks maintained by the firmware upgrade device is incremented by 1. For example, if the current download region is COSB and the current number of downloaded blocks is 0x08, then the starting address for writing is 0x03000690, and after writing, the number of downloaded blocks maintained by the firmware upgrade device increases to 0x09.
[0036] During the upgrade command process, the firmware upgrade device synchronously updates and stores the number of blocks *u* that have been upgraded based on the data sent by the host. The upgrade is complete when the number of upgraded blocks *u* equals the total number of blocks *n* in the upgrade command. After the upgrade is complete, the device can switch to the currently running COS space to run newly downloaded code. For example, if the currently running COS region is COSA and the region for downloading upgrade data is COSB, when switching to a new function after the download is complete, simply switch the running region to COSB.
[0037] If a transmission interruption occurs during the upgrade data transmission process, a resume operation will be performed, specifically including: ① If the firmware upgrade device experiences a transmission interruption, it will inform the host of the block number u that has been downloaded and the upgrade data for this operation. When the firmware upgrade device receives the block number u+1 from the host, it will directly map to the upgrade address corresponding to the block number u+1 and continue the upgrade operation from this address.
[0038] ② If a transmission interruption occurs on the host side, the firmware upgrade device will not process the upgrade data before block number u that has already been downloaded. When it receives block number u+1 from the host side, it will directly map to the upgrade address corresponding to block number u+1 and continue the upgrade operation from this address.
[0039] ③ If the firmware upgrade device experiences a transmission interruption, it will inform the host of the size v of the downloaded data and other information about the currently upgraded version. It will then directly receive the upgrade data after v from the host and locate the address to be upgraded next based on the starting address of the current upgrade space.
[0040] ④ If a transmission interruption occurs on the host side, the firmware upgrade device will check whether the upgrade data is the same as the upgrade data version and upgrade data size information in the upgrade command sent by the host side. If the upgrade data is the same, the firmware upgrade device will record the size v of the data already sent and the size s of the data sent in this command. If the size of the upgrade data (v+s) <= k, the device will find the location where the downloaded content should be stored by adding v to the starting position of the upgrade storage. It will then retrieve data of length s from this location and compare it with the data sent in this command. If they are the same, the device will continue to receive the next data sent by the host side. If they are different, the device will send the data to the current storage location until v > k. The firmware upgrade device will then start to write the data directly to the corresponding position calculated based on the data size until the upgrade is completed.
[0041] It should be noted that the above-mentioned breakpoint resume download solution ① has requirements for the upgrade host. When resuming the download, the block size and number of blocks of the upgrade data processed by the upgrade host must be the same as the previous upgrade command. If the host does not have a resume command, method ② can also be used directly for upgrade resume operation. Solution ③ has no special requirements for the upgrade host; the entire process is completed within the firmware upgrade device and can adapt to most upgrade processes. If the host does not have a resume function, this solution can also use method ④ to quickly traverse the upgrade data, find the missing data as soon as possible, and thus achieve the purpose of resuming the download.
[0042] The difference between schemes ① and ② and schemes ③ and ④ is that schemes ① and ② reduce the process of reading data from the storage space when resuming transmission, but the requirements for upgrading the host are more complex; schemes ③ and ④ are more accurate than the third embodiment, reduce the requirements for the host, and have higher adaptability.
[0043] Example 3 Embodiment 3 of the present invention provides a firmware upgrade system, including a host and the firmware upgrade device described in Embodiment 1, such as... Figure 4 As shown, the system operation method includes: Step 410: The host prepares the required upgrade version and upgrade data, and organizes the upgrade commands; Step 420: The host sends an upgrade command to the firmware upgrade device, informing the firmware upgrade device of the upgrade version and upgrade data size information; During the upgrade data preparation phase, the host divides the upgrade data of size m into n upgrade blocks according to the preset data size. The size of each upgrade block is m / n. When sending the upgrade command, the host informs the firmware upgrade device of the total number of blocks n to be upgraded and the data size m.
[0044] Step 430: The firmware upgrade device processes the upgrade command and prepares to receive upgrade data accordingly; Step 440: The host sends upgrade data to the firmware upgrade device; Each upgrade data sent by the host is preceded by a block number, which increases sequentially as more data is sent.
[0045] Step 450: The firmware upgrade device executes steps 210-240; After the host sends the firmware upgrade data to the firmware upgrade device, the firmware upgrade data executes the firmware upgrade method as described in Examples 2-4, which will not be repeated here.
[0046] Example 4 Embodiment 4 of this application provides a specific method for resuming interrupted downloads, when the firmware upgrade process reaches the stage of downloading upgrade data: ① If the firmware upgrade device experiences a reset or power failure, the host sends a query command to the firmware upgrade device. The firmware upgrade device checks whether it has started an upgrade operation (i.e., whether the number of downloaded blocks is greater than 0). If the upgrade operation has started, the firmware upgrade device informs the host of the block number u already downloaded, the upgrade version, upgrade data size, total number of upgrade blocks, and upgrade block size. The host uses the upgrade version, upgrade data size, total number of upgrade blocks, and upgrade block size to determine the version that needs to be continued and starts sending from the next block u+1 to be sent. When the firmware upgrade device receives the sent block number u+1, after comparing the sent data block number and data length and confirming that they are correct, it can directly map to the upgrade address corresponding to the u+1 block number and continue the upgrade operation from this address. For example, if the upgrade block storage address is 0x00000000, then after a power failure or reset, the u+1 block sent by the host can be retrieved from... The upgrade download process will continue at this location.
[0047] ② If the host experiences a transmission interruption due to a reset, power failure, or other issues, the host may have lost data. In this case, the host will directly resend the upgrade command to the firmware upgrade device. The firmware upgrade device will then verify if the upgrade data is the same as the one sent by the host, based on the upgrade data version, size, and total number of blocks. If the upgrade data is the same, and the upgrade data block number n <= u, the firmware upgrade device will receive the upgrade data sent by the host as quickly as possible without processing it. Once n = (u+1) data blocks are reached, the firmware upgrade device will begin processing the data and writing it to the appropriate location until the upgrade is complete.
[0048] It should be noted that the above-mentioned breakpoint resume download solution ① has requirements for the upgrade host. When resuming the download, the block size and number of blocks of the upgrade data processed by the upgrade host must be the same as the previous upgrade command. If the host does not have a resume command, method ② can also be used directly for the upgrade resume operation.
[0049] Example 5 Embodiment 5 of this application provides another specific method for resuming interrupted downloads. During the upgrade data preparation phase, the host needs to calculate the size *m* of the upgrade data and send it to the firmware upgrade device in the upgrade command. After receiving the upgrade data size, the firmware upgrade device compares it with its own upgrade storage space to determine if the upgrade operation can be performed. If the upgrade data *m* is less than or equal to its available upgrade space, the next upgrade operation can proceed.
[0050] During the upgrade process, the firmware upgrade device synchronously updates and stores the upgraded data size *n* based on the data sent from the host. The upgrade is complete when the upgraded data size equals the total upgrade data size. During the device upgrade, the location where the upgrade code needs to be stored is easily mapped by adding the upgraded size *n* to the initial address of the upgrade space.
[0051] When the firmware upgrade process reaches the stage of downloading upgrade data: ① If the firmware upgrade device experiences a reset or power failure, the host sends a query command to the firmware upgrade device. The firmware upgrade device informs the host of the downloaded data size 'v' and other information about the currently upgraded version. The host only needs to upgrade from the data after 'v'. When the firmware upgrade device receives the upgrade data after 'v' from the host, it can directly locate the address to be upgraded based on the starting address of the current upgrade space. For example, if the starting address of the upgrade storage is 0x00000000, then after a power failure or reset, the host sends the upgrade data after 'v', and the firmware upgrade device starts storing the upgrade data from address 0x00000000+n.
[0052] ② If the host experiences a transmission interruption due to a reset, power failure, or other issues, the host may have lost data. The host then resends the upgrade command to the firmware upgrade device. This upgrade command includes the upgrade data version, upgrade data size, and the data to be upgraded. The firmware upgrade device then uses the upgrade data version and size from the host to confirm if the data is the same. If it is, the firmware upgrade device records the size *v* of the currently sent data and the size *s* of the data sent in this command. If the recorded upgrade data size (*v* + *s*) <= *k*, then *v*, *k*, and *s* represent the data size. *k* represents the total data size received by the firmware upgrade device during the first upgrade; *v* represents the size of the data already sent by the host during the second upgrade (excluding the current command); and *s* represents the size of the data sent in the current command. After receiving the data, the firmware upgrade device finds the correct storage location by adding 'v' to the starting position of the upgrade storage. It then retrieves data of length 's' from this location and compares it with the data sent in the current command. If they match, it continues receiving the next data from the host. The host needs to receive a successful execution response (e.g., a 9000 response) from the firmware upgrade device before sending the next command. If they differ, the device writes the data to the current storage location. This process continues until 'v > k', at which point the firmware upgrade device directly writes the data to the corresponding location calculated based on the data size, until the upgrade is complete.
[0053] It should be noted that this solution has no special requirements for the upgrade host; the entire process is completed within the firmware upgrade device, making it compatible with most upgrade processes. If the host does not have a resume function, this solution can also use method ② to quickly traverse the upgrade data, accurately locate the undownloaded data as soon as possible, and thus achieve the purpose of resuming the download.
[0054] The difference between Embodiment 4 and Embodiment 5 is that Embodiment 4 reduces the process of reading data from the storage space during resume transmission, but the requirements for upgrading the host are more complex; Embodiment 5 is more accurate than Embodiment 3, reduces the requirements for the host, and has higher adaptability.
[0055] The specific embodiments described above further illustrate the purpose, technical solution, and beneficial effects of the present invention. It should be understood that the above description is only a specific embodiment of the present invention and is not intended to limit the scope of protection of the present invention. Any modifications, equivalent substitutions, improvements, etc., made on the basis of the technical solution of the present invention should be included within the scope of protection of the present invention.
Claims
1. A firmware upgrade device, characterized in that, include: The chip and storage space consist of a COS region and a user region. The COS region is divided into COSA and COSB. COSA and COSB share the user region and the storage space of the firmware upgrade device. COSA and COSB serve as backup areas for each other. When performing a firmware upgrade, one upgrade region runs the current code, while the other upgrade region performs the firmware upgrade. The COSA and COSB running space is divided into native code space and programming code space. The native code space and programming code space occupied by COSA and COSB in the storage space are not contiguous. The storage space includes, in order, the native code space of COSA, the native code space of COSB, the user data space, the programming code space of COSA, and the programming code space of COSB. The storage space is divided into a corresponding number of data blocks according to the upgrade data block number. There is a corresponding mapping relationship between the block number and the data block address. Each data block stores the corresponding upgrade data block. The firmware upgrade device calculates the size and location of the COSA and COSB regions that can store upgrade code, and uses a mapping function to associate the native code region and the programming code region. In response to receiving an upgrade command from the host, the firmware upgrade device obtains the total number of blocks to be upgraded and the size of the upgrade data from the upgrade command; The firmware upgrade device determines the currently running COS region, takes another COS region as the current upgrade region, divides the storage space into n blocks according to the block number based on the data size in the upgrade command and the total number of blocks in the upgrade command, and maps the block number to the corresponding storage space address; The firmware upgrade device sequentially stores the upgrade data sent by the host into the corresponding storage space address. If the data transmission is interrupted, it resumes the transmission based on the data already stored in the storage space. After all the upgrade data has been received, it switches to the current upgrade area to run the newly downloaded code.
2. A firmware upgrade method, applied in a firmware upgrade device, characterized in that, in, The firmware upgrade device includes a chip and storage space. The chip runs a COS region and a user region. The COS region is divided into COSA and COSB. COSA and COSB share the user region and the storage space of the firmware upgrade device. COSA and COSB serve as backup areas for each other. When performing a firmware upgrade, one upgrade region runs the current code, while the other upgrade region performs the firmware upgrade. The COSA and COSB running space is divided into native code space and programming code space. The native code space and programming code space occupied by COSA and COSB in the storage space are not contiguous. The storage space includes, in order, the native code space of COSA, the native code space of COSB, the user data space, the programming code space of COSA, and the programming code space of COSB. The storage space is divided into a corresponding number of data blocks according to the upgrade data block number. There is a corresponding mapping relationship between the block number and the data block address. Each data block stores the corresponding upgrade data block. The firmware upgrade method includes the following steps: The firmware upgrade device calculates the size and location of the COSA and COSB regions that can store upgrade code, and uses a mapping function to associate the native code region and the programming code region. In response to receiving an upgrade command from the host, the firmware upgrade device obtains the total number of blocks to be upgraded and the size of the upgrade data from the upgrade command; The firmware upgrade device determines the currently running COS region, takes another COS region as the current upgrade region, divides the storage space into n blocks according to the block number based on the data size in the upgrade command and the total number of blocks in the upgrade command, and maps the block number to the corresponding storage space address; The firmware upgrade device sequentially stores the upgrade data sent by the host into the corresponding storage space address. If the data transmission is interrupted, it resumes the transmission based on the data already stored in the storage space. After all the upgrade data has been received, it switches to the current upgrade area to run the newly downloaded code.
3. The firmware upgrade method as described in claim 2, characterized in that, The upgrade command specifically includes the upgrade version issued by the host, the upgrade data size, the total number of upgrade blocks, the upgrade block size, and the upgrade block number.
4. The firmware upgrade method as described in claim 2, characterized in that, If the firmware upgrade device experiences a transmission interruption, it informs the host of the block number u that has been downloaded and the upgrade data for this operation. When the firmware upgrade device receives the block number u+1 from the host, it directly maps to the upgrade address corresponding to the block number u+1 and continues the upgrade operation from this address.
5. A firmware upgrade method as described in claim 2, characterized in that, If a transmission interruption occurs on the host side, the firmware upgrade device will not process the upgrade data before block number u that has already been downloaded. When it receives block number u+1 from the host side, it will directly map to the upgrade address corresponding to block number u+1 and continue the upgrade operation from this address.
6. A firmware upgrade method as described in claim 2, characterized in that, If the firmware upgrade device experiences a transmission interruption, it informs the host of the size v of the downloaded data and other information about the currently upgraded version. It then directly receives the upgrade data after v from the host and locates the address to be upgraded next based on the starting address of the current upgrade space.
7. A firmware upgrade method as described in claim 2, characterized in that, If a transmission interruption occurs on the host side, the firmware upgrade device checks the upgrade data version and size information in the upgrade command sent by the host side to determine if it is the same upgrade data. If it is the same upgrade data, the firmware upgrade device records the size v of the currently sent data and the size s of the data sent in this command. If the recorded upgrade data size (v+s)<=k, the device finds the location where the downloaded content should be stored by adding v to the starting position of the upgrade storage. It then retrieves data of length s from this location and compares it with the data sent in this command. k represents the total size of the data received by the firmware upgrade device when the host side sent data for the first upgrade. If they are the same, the device continues to receive the next data sent by the host side. If they are different, the device needs to send data to the current storage location until v>k. At this point, the firmware upgrade device starts to directly write the data to the corresponding position calculated based on the data size until the upgrade ends.
8. A firmware upgrade system, comprising a host and a firmware upgrade device as described in claim 1, characterized in that, include: The host prepares the necessary upgrade version and upgrade data, and organizes the upgrade commands; The host sends an upgrade command to the firmware upgrade device, informing the firmware upgrade device of the upgrade version and upgrade data size; The firmware upgrade device processes upgrade commands and prepares accordingly to receive upgrade data; The host sends upgrade data to the firmware upgrade device; The firmware upgrade device performs a firmware upgrade method as described in any one of claims 2-7.
9. A firmware upgrade system as described in claim 8, characterized in that, During the upgrade data preparation phase, the host divides the upgrade data of size m into n upgrade blocks according to the preset data size. The size of each upgrade block is m / n. When sending the upgrade command, the host informs the firmware upgrade device of the total number of blocks n to be upgraded and the data size m.
10. A firmware upgrade system as described in claim 8, characterized in that, Each upgrade data sent by the host is preceded by a block number, which increases sequentially as more data is sent.