Storage device and control method thereof

By setting multiple working blocks and upgrade blocks in the storage device, efficient and stable firmware upgrades are achieved under limited resources, solving the failure problem caused by abnormal power outage during the firmware upgrade process, ensuring data stability and Anti-interference ability.

CN118426815BActive Publication Date: 2024-09-27合肥康芯威存储技术有限公司
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202410874318.6
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-07-02
Publication Date
2024-09-27
Estimated Expiration
2044-07-02

AI Technical Summary

Technical Problem

Existing storage devices are prone to upgrade failures due to abnormal power outages or unstable voltage during the firmware upgrade process, and consume a lot of resources, affecting overall functions.

Method used

A storage device is designed, including a main controller, memory and flash memory. Multiple working blocks, encoding blocks and upgrade blocks are set up in the flash memory. By calling the startup firmware in the firmware upgrade mode, the old and new firmware are distinguished and data verified. Ensure stable upgrades with limited resources.

Benefits of technology

It realizes efficient and anti-interference firmware upgrade with less resource usage, ensures the stability of new and old firmware and data stability, and can be efficiently re-upgraded under abnormal circumstances.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118426815B
    Figure CN118426815B
Patent Text Reader

Abstract

The present invention provides a storage device and a control method thereof, wherein the storage device has a firmware upgrade mode and a working mode, and the storage device comprises: a main controller electrically connected to a host; a memory electrically connected to the main controller, wherein a startup firmware is stored in the memory, and in the firmware upgrade mode, the main controller calls the startup firmware; and a flash memory electrically connected to the main controller, wherein the flash memory comprises a plurality of working blocks, at least two coding blocks and at least two upgrading blocks, wherein the first version of the firmware is stored in the coding block, and the new version of the firmware is stored in the upgrading block; wherein the page architecture of the coding block and the upgrading block is the same, and before the first firmware upgrade, the address information of the coding block is stored in the coding block, and after the first firmware upgrade, the address information of the upgrading block is respectively stored in the coding block and the upgrading block, and in the coding block, the address information of the upgrading block replaces the address information of the coding block. The present invention can prevent the abnormal state during the firmware upgrade from causing the firmware to be lost.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of storage technology, and in particular to a storage device and a control method thereof. Background Art

[0002] Read-Only Memory (ROM) works in a non-destructive read mode, and can only read information but not write it. Once the information is written, it is fixed, and even if the power is cut off, the information will not be lost, so it is also called a fixed storage device. The data stored in ROM is written before it is installed in the whole machine, and can only be read out during the operation of the whole machine, unlike random access memory devices that can quickly and easily rewrite the storage content. The data stored in ROM is stable, and the stored data will not change after power failure. It also has a simple structure and is easy to use, so it is often used to store various fixed programs and data. ROM resources are limited, and when formulating the working strategy of the storage device, it is necessary to confirm the code content in the ROM.

[0003] When the firmware upgrade encounters abnormal power failure or voltage instability, the upgrade will fail. Although it is possible to force the firmware upgrade process to not lose power, it is difficult to completely control the abnormal sudden problems during the firmware upgrade process in actual applications. Therefore, to complete the firmware upgrade, the ROM must be able to distinguish between the new and old firmware. In this way, more blocks need to be traversed and checked each time the power is turned on again, and the algorithm is complex. However, ROM resources are limited, and excessive use of resources will affect the overall function of the storage device. Summary of the invention

[0004] The object of the present invention is to provide a storage device and a control method thereof, which can complete firmware upgrade with less resource occupation and prevent firmware loss caused by abnormal conditions during firmware upgrade.

[0005] In order to solve the above technical problems, the present invention is achieved through the following technical solutions:

[0006] The present invention provides a storage device, the storage device having a firmware upgrade mode and an operating mode, and the storage device comprises:

[0007] A main controller, electrically connected to the host;

[0008] a memory electrically connected to the main controller, wherein the memory stores a startup firmware, and in the firmware upgrade mode, the main controller calls the startup firmware; and

[0009] A flash memory electrically connected to the main controller, the flash memory comprising a plurality of working blocks, at least two encoding blocks and at least two upgrading blocks, wherein the encoding blocks store the first version of the firmware, and the upgrading blocks store the new version of the firmware;

[0010] Among them, the page architecture of the coding block and the upgrade block is the same. Before the first firmware upgrade, the address information of the coding block is stored in the coding block. After the first firmware upgrade, the address information of the upgrade block is stored in the coding block and the upgrade block respectively. In the coding block, the address information of the upgrade block replaces the address information of the coding block.

[0011] In one embodiment of the present invention, the first version of firmware is the program code recorded into the coding block before the storage device is activated, and the new version of firmware is the program code written into the upgrade block during the most recent firmware upgrade.

[0012] In one embodiment of the present invention, the flash memory includes a system block, in which address information of the encoding block, address information of the upgrade block and address information of the working block are recorded. During the first firmware upgrade, the main controller queries the upgrade block based on the address information in the system block.

[0013] In one embodiment of the present invention, the upgrade block includes:

[0014] A plurality of firmware storage pages, wherein the firmware storage pages store program code files of the firmware;

[0015] a plurality of address storage pages, wherein the address storage pages store configuration information of the storage device and address information of the plurality of upgrade blocks, wherein the configuration information is preset information set when the storage device is powered on; and

[0016] A plurality of filling data pages are provided, wherein the filling data pages store spare data, wherein the spare data is invalid data automatically generated by the system.

[0017] In one embodiment of the present invention, the startup firmware includes a first update module. In the firmware upgrade mode, the first update module receives the file package of the new version of the firmware, the configuration information in the coding block and the address information of the upgrade block, and stores the new version of the firmware in the firmware storage pages of multiple upgrade blocks, and stores the configuration information and the address information of the upgrade block in the address storage page of the upgrade block.

[0018] In one embodiment of the present invention, the startup firmware includes a second update module, and the update process of the second update module is located after the update process of the first update module. In the firmware upgrade mode, the second update module classifies multiple coding blocks into first-category coding blocks and second-category coding blocks, wherein the first-category coding blocks are error-free coding blocks, and the second-category coding blocks are abnormal blocks or error-free coding blocks.

[0019] In one embodiment of the present invention, the startup firmware includes a verification module. After an abnormal power failure occurs during the firmware upgrade process, the verification module verifies the coding block and classifies the coding block into the abnormal block or the non-error coding block based on the verification information, wherein the verification information includes data missing information, data error information and metadata matching information of the coding block.

[0020] The present invention provides a storage device control method. Based on the storage device as described above, the storage device control method comprises the following steps:

[0021] When an abnormal power failure occurs during the firmware upgrade process, after power is restored, the stored data of multiple coding blocks are read in sequence, and the stored data of the coding blocks are checked for errors;

[0022] When any of the coding blocks is not faulty, acquiring the address information of the upgrade block from the system block or the coding block that is not faulty;

[0023] According to the address information of the upgrade block, find the upgrade block, and erase the storage data of a plurality of the upgrade blocks;

[0024] Writing a new version of firmware to the upgrade block; and

[0025] The address information in the encoding block is updated to the address information of the upgrade block.

[0026] In an embodiment of the present invention, the control method of the storage device includes obtaining the error-free coding block, and the steps are as follows:

[0027] Reading multiple coding blocks in sequence, and determining in sequence whether the coding blocks are missing data, whether the data stored in the coding blocks are erroneous, and whether the metadata of the coding blocks match;

[0028] If the coding block is missing data, or the data stored in the coding block is erroneous, or the metadata of the coding block does not match, classifying the coding block as an abnormal block; and

[0029] If the stored data of the coding block is complete, the data stored in the coding block is correct, and the metadata of the coding block matches, the coding block is classified as an error-free coding block.

[0030] In one embodiment of the present invention, the step of writing a new version of firmware to the upgrade block includes:

[0031] erasing a plurality of the upgrade blocks;

[0032] Download the file package of the new version of the firmware, and write the file package of the new version of the firmware into the firmware storage page of the upgrade block;

[0033] Acquire configuration information of the storage device from the address storage page of the coding block, acquire address information of the upgrade block from the address storage page of the coding block or the system block, and write the configuration information and the address information of the upgrade block into the address storage page of the upgrade block; and

[0034] The blank storage pages of the upgrade block are filled with spare data until the upgrade block is filled.

[0035] As described above, the present invention provides a storage device and a control method thereof, which can realize firmware upgrade efficiently and anti-interference with less resource occupation, and even if abnormal power failure occurs, the firmware can be re-upgraded in a highly stable manner after power is restored. The storage device and the control method thereof provided by the present invention have good stability of both the new and old firmware even in the absence of interference intervention, and can always maintain good data stability and anti-interference capability in the case of multiple upgrades of the same firmware.

[0036] Of course, any product implementing the present invention does not necessarily need to achieve all of the advantages described above at the same time. BRIEF DESCRIPTION OF THE DRAWINGS

[0037] In order to more clearly illustrate the technical solutions of the embodiments of the present invention, the accompanying drawings required for describing the embodiments will be briefly introduced below. Obviously, the accompanying drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other accompanying drawings can be obtained based on these accompanying drawings without paying creative work.

[0038] Figure 1 FIG. 4 is a schematic diagram of the structure of a storage device in an embodiment of the present invention.

[0039] Figure 2 FIG. 4 is a schematic diagram of the structure of a flash memory in an embodiment of the present invention.

[0040] Figure 3 A schematic diagram of storage block types of a flash memory in an embodiment of the present invention.

[0041] Figure 4 Schematic diagram of the structure of the upgrade block in one embodiment of the present invention.

[0042] Figure 5 FIG. 1 is a schematic diagram of the structure of the startup firmware in an embodiment of the present invention.

[0043] Figure 6 The figure is a flowchart of a method for controlling a storage device in one embodiment of the present invention.

[0044] Figure 7FIG. 1 is a flow chart of step S30 and step S40 in one embodiment of the present invention.

[0045] Figure 8 FIG. 1 is a flow chart of step S31 in an embodiment of the present invention.

[0046] Fig. 9 FIG. 1 is a flow chart of step S10 in an embodiment of the present invention.

[0047] Fig.10 FIG. 5 is a flow chart of step S50 in an embodiment of the present invention. DETAILED DESCRIPTION

[0048] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.

[0049] Firmware is a program written into an Erasable Programmable Read Only Memory (EPROM) or an Electrically Erasable Programmable Read-Only Memory (EEPROM). When upgrading the firmware, there is a difference between the new version of the firmware and the old version of the firmware, and the difference lies in the content of the firmware. If problems such as power failure occur during the upgrade process, there is also a difference between the old firmware before the power failure and the new firmware written after the power failure, and the difference lies in the time when the firmware is written. In the normal firmware upgrade process and the firmware upgrade process with abnormal power failure, the ROM needs to distinguish between the new and old firmware as mentioned above, so more code instructions will be set to traverse the physical blocks and even physical pages of the flash memory. The present invention provides a storage device and a control method thereof, which can reduce the resource occupation of the ROM on the basis of performing firmware upgrades and solving abnormal power failures during firmware upgrades.

[0050] See also Figure 1As shown, in one embodiment of the present invention, the present invention shows a storage device 10, which includes a main controller 20, a flash memory 30 and a memory 40. The main controller 20 includes a microprocessor 201, a host interface controller 202, a cache controller 203, a buffer 204 and a flash memory controller 205, and an error correction module 206. The microprocessor 201 is a Reduced Instruction System Computer (RISC), and is specifically an ARM processor. The microprocessor 201 is electrically connected to the host interface controller 202, the cache controller 203 and the flash memory controller 205. The host interface controller 202 is electrically connected to the host 60 through an interface to receive instructions and data from the host 60 and feedback data from the main controller 20. The connection interface between the host 60 and the main controller 20 can be a SATA hard disk, a high-speed serial computer expansion bus interface (Peripheral Component Interconnect express, PCIe), and a SAS interface. The cache controller 203 is electrically connected to the memory 40 and the buffer 204 to control the transfer and storage of data. In this embodiment, the flash memory controller 205 is electrically connected to the error correction module 206 to perform error correction on the data read out of the flash memory 30 during the reading process of the flash memory 30. The error correction module 206 can complete the error checking and correction of the flash memory 30 through the low density parity check code (Low Density Parity-Check Code, LDPC). In the present invention, the flash memory 30 is a NAND flash memory particle. The flash memory controller 205 is electrically connected to the flash memory 30 to realize data writing and reading. The memory 40 is a read-only storage device ROM. It should be noted that the present invention only shows the structure of a storage device. The memory provided by the present invention includes a storage device of the flash memory 30, such as an SM flash card, a CF card, a Multi Media Card (Multi Media Card, MMC), a Secure Digital Card (Secure Digital Card, SD card), a memory stick and a micro hard disk, etc.

[0051] See also Figure 1 and Figure 2 As shown, in one embodiment of the present invention, the flash memory 30 includes at least two encoding blocks 310, at least two upgrade blocks 320 and a plurality of working blocks 330. Figure 2As shown, in this embodiment, there are, for example, two encoding blocks 310, which are the first encoding block and the second encoding block. There are, for example, two upgrade blocks 320, which are the first upgrade block and the second upgrade block. There are, for example, n working blocks 330, which are the first working block, the second working block to the nth working block. The present invention does not limit the number of working blocks 330. In this embodiment, the first version of firmware is stored in the encoding block 310. The first version of firmware is the program code written into the storage device 10 during the card opening stage. The new version of firmware is stored in the upgrade block 320. The new version of firmware refers to the program code written into the upgrade block 320 during the firmware upgrade process. In this embodiment, the new version of firmware in the upgrade block 320 is the program code downloaded to the upgrade block 320 during the most recent firmware upgrade. The working block 330 is used to store user data.

[0052] See also Figure 1 and Figure 2 As shown, it should be noted that the control method of the storage device provided by the present invention is a strategy of the storage device. This strategy is formulated in the design stage of the storage device 10, and the control method provided by the present invention is written into a code statement. Next is the mass production stage of the storage device 10, and the strategy of the code statement is formulated before the mass production stage of the storage device 10. The step of writing into the memory 40 is performed after the mass production stage of the storage device 10 and before the card opening stage of the storage device 10. In the present invention, the selection of the coding block 310 and the upgrade block 320 is performed in the card opening stage of the storage device 10. It should also be noted that the step of writing the first version of the firmware into the coding block 310 is performed after the card opening stage and before the storage device 10 leaves the factory. The firmware upgrade process is performed after the first version of the firmware is written, and the firmware upgrade process can be performed before the storage device 10 leaves the factory, or after the storage device 10 leaves the factory.

[0053] See also Figures 1 to 3 As shown, in one embodiment of the present invention, the flash memory 30 includes a plurality of storage modules 301, the storage module 301 includes a plurality of storage blocks 302, and the storage block 302 includes a plurality of storage pages 303. The storage block 302 is a physical block of the flash memory 30, the storage page 303 is a physical page of the flash memory 30, and the storage module 301 refers to the plane of the flash memory 30. In the present invention, the encoding block 310, the upgrade block 320 and the working block 330 all refer to the storage block 302. It should be noted that in the flash memory 30, each storage page 303 has a unique device number. In the physical structure of the flash memory 30, the storage page 303 device number is assigned in sequence according to the physical order of the storage page 303. Therefore, the device number of the storage page 303 can reflect the physical position order of the storage page 303, a physical page, in the flash memory 30. Similarly, the storage block 302 and the storage module 301 page have a unique device number.

[0054] See also Figures 1 to 3 As shown, in one embodiment of the present invention, in the card opening stage of the storage device 10, some blocks are selected from the multiple storage blocks 302 in the flash memory 30 as coding blocks 310 and upgrade blocks 320, and the blocks other than the coding blocks 310 and upgrade blocks 320 are used as working blocks 330. In this embodiment, the coding blocks 310 and upgrade blocks 320 are obtained in sequence according to the numbers of the storage blocks 302. Specifically, the number of coding blocks 310 and upgrade blocks 320 is first determined. In this embodiment, the number of coding blocks 310 and upgrade blocks 320 is, for example, 2. Then, the storage blocks 302 are read in sequence according to the numbering order of the storage blocks 302. When the storage block 302 is not a bad block, the current storage block 302 is recorded as a coding block 310 or an upgrade block 320 until a preset number of coding blocks 310 and upgrade blocks 320 are obtained. Therefore, the coding blocks 310 and upgrade blocks 320 are the top-ranked storage blocks 302, and specifically the top-ranked good blocks. In the present invention, if the current storage block 302 is a bad block, the current storage block 302 is skipped and the next sorted storage block 302 is read continuously until a preset number of encoding blocks 310 and upgrading blocks 320 are obtained.

[0055] See also Figures 1 to 3 As shown, in one embodiment of the present invention, it should be noted that in one embodiment of the present invention, in the step of confirming whether the current storage block is bad, the flash memory 30 has a bad block table. Before the card opening stage, the bad block position and the number of bad blocks in the flash memory 30 are confirmed by checking, and the address information of the bad block is stored in the bad block table. When confirming whether the current block is a bad block, if the current storage block 302 is not recorded in the bad block table, the current storage block 302 is a good block, and the current storage block 302 can be recorded as a coding block 310 or an upgrade block 320. In another embodiment of the present invention, data is written to the current storage block 302. If the data can be read correctly, the current storage block 302 is a good block. If the data cannot be read accurately after writing the data, the current storage block 302 is a bad block.

[0056] See also Figures 1 to 4 As shown, in one embodiment of the present invention, the page structures of the encoding block 310 and the upgrading block 320 are the same. Figure 4A schematic diagram of the structure of the upgrade block 320 in an embodiment is shown. The upgrade block 320 includes an address storage page 340, a firmware storage page 350, and a fill data page 360. Similarly, the coding block 310 includes an address storage page 340, a firmware storage page 350, and a fill data page 360. The address storage page 340 stores the address information of the special block and the configuration information of the storage device 10. In this embodiment, the special block refers to the coding block 310 or the upgrade block 320. Specifically, before the first firmware upgrade, the address storage page 340 of the coding block 310 stores the address information of the coding block 310 itself and the configuration information of the storage device 10. After the first firmware upgrade, the address storage page 340 of the coding block 310 stores the address information of the upgrade block 310 and the configuration information of the storage device 10. The configuration information is the system information determined in the card opening stage, and the present invention does not limit the configuration information of the storage device 10. It should be noted that, in this embodiment, two address storage pages 340 are shown. In other embodiments of the present invention, the number of address storage pages 340 may be, for example, 1, 3, etc. The present invention does not limit the number of address storage pages 340.

[0057] See also Figures 1 to 4 As shown, in one embodiment of the present invention, the firmware storage page 350 stores the code file of the firmware. The code file is a bin file. In this embodiment, the firmware storage page 350 of the coding block 310 stores the code file of the first version of the firmware. The firmware storage page 350 of the upgrade block 320 stores the code file of the new version of the firmware. It should be noted that in this embodiment, after the card opening stage, the first version of the firmware is always stored in the coding block 310. In this embodiment, before the first firmware upgrade, the firmware storage page 350 of the upgrade block 320 stores spare data to improve the stability of the upgrade block 320. In other embodiments of the present invention, before the first firmware upgrade, the firmware storage page 350 of the upgrade block 320 may not store any data. After the first firmware upgrade, the firmware storage page 350 of the upgrade block 320 stores the new version of the firmware. It should be noted that storing the new version of the firmware refers to the end of the firmware upgrade process, and during the firmware upgrade process, the new version of the firmware is written into the upgrade block 320 one after another, and the present invention does not limit this state. During the firmware upgrade process, since it is unknown when the abnormal power failure occurs, it is also unknown what task the storage device 10 is executing when the abnormal power failure occurs. Therefore, when the abnormal power failure occurs and the power is turned on again, the status of the upgrade block 320 and the encoding block 310 is unknown. The firmware storage page 350 of the upgrade block 320 may store a complete new version of the firmware, or may not store any data, or may only store some code statements of the new version of the firmware.

[0058] See also Figures 1 to 4As shown, in one embodiment of the present invention, the spare data is stored in the fill data page 360. In this embodiment, the spare data is invalid data automatically generated by the main controller 20. Invalid data means that the address information of the spare data does not have corresponding address mapping information. Specifically, in any working cycle of the upgrade block 320, the spare data is used to fill the remaining storage space of the upgrade block 320 to improve the stability of block data storage. In this embodiment, before the first firmware upgrade, the spare data can be filled in the firmware storage page 350 and the fill data page. After the first firmware upgrade, the spare data can be filled in the firmware storage page 350 and the fill data page.

[0059] See also Figures 1 to 4 As shown, it should be noted that, in this embodiment, the storage space of the upgrade block 320 is planned, and the firmware storage page 350 and the address storage page 340 are part of the storage page 303 with fixed encoding. For example, the storage page 303 numbered 0 is used as the address storage page 340, and the storage pages 303 numbered 1 to 12 are used as the firmware storage page 350. The number and position of the firmware storage page 350 are fixed. When the size of the code file exceeds the storage capacity of the firmware storage page 350, before writing the code file, the code file is compressed until the code file is less than or equal to the storage capacity of the firmware storage page 350. When the code file is less than or equal to the storage capacity of the firmware storage page 350, spare data is written to the firmware storage page 350 until all the firmware storage pages 350 are filled. Therefore, the structural stability of the upgrade block 320 and the encoding block 310 is strong, and clear addressing is achieved with less resource occupation. Specifically, the present invention achieves addressing without traversing the storage block 302.

[0060] See also Figures 1 to 4As shown, it should be noted that the address information mentioned in this embodiment is address mapping information. The data written to the storage device 10 includes a logical address and a physical address, wherein the physical address is the storage location of the written data in the storage device 10. While writing the data, an address mapping relationship is established between the logical address and the physical address of the written data, so that when the written data is retrieved, the physical address of the written data can be found according to the address mapping relationship. Among them, the address mapping relationship of the written data can be stored in a specific position of the storage device 10 in the form of a linked list. The linked list reflecting the mapping relationship between the physical address and the logical address of the written data is the address mapping information, which is also the address information mentioned in this embodiment. The present invention does not show the cache area, and the address information of the data is stored in the cache area or the flash memory 30. In the present invention, the storage device 10 includes a system block, and the address mapping information of the encoding block 310 and the upgrade block 320 is stored in the system block. The system block also includes the front-end configuration information and the back-end configuration information of the storage device 10. The present invention does not limit the method for controlling the address mapping information of the working block 330.

[0061] See also Figure 1 , Figure 2 and Figure 5 As shown, in one embodiment of the present invention, the boot firmware 50 is stored in the memory 40. After the storage device 10 enters the firmware upgrade mode, the main controller 20 calls the boot firmware 50 to implement the firmware upgrade function. In this embodiment, the boot firmware 50 includes a first update module 510, a second update module 520 and a verification module 530. The verification module 530 runs after an abnormal power failure occurs and the power is re-on. The first update module 510 and the second update module 520 run in both the normal firmware upgrade process and the abnormal upgrade process. The abnormal upgrade process refers to the process of abnormal power failure during the normal firmware upgrade process and then re-powering on. In this embodiment, the first update module 510 is used to write a new version of the firmware to the upgrade block 320. The second update module 520 is used to update the storage data of the encoding block 310. The verification module 530 is used to implement a verification operation after an abnormal power failure occurs.

[0062] See also Figures 1 to 6 As shown, the present invention provides a control method for a storage device 10, which is used to implement a firmware upgrade of the storage device 10. The control method includes steps S10 to S50.

[0063] Step S10: When an abnormal power failure occurs during the firmware upgrade process, after power is restored, the stored data of the plurality of coding blocks are read in sequence, and the stored data of the coding blocks are checked for errors.

[0064] Step S20: When any coding block is not faulty, the address information of the upgrade block is obtained from the system block or the coding block that is not faulty.

[0065] Step S30: Find the upgrade block according to the address information of the upgrade block, and erase the storage data of multiple upgrade blocks.

[0066] Step S40: writing the new version of the firmware into the upgrade block.

[0067] Step S50: Update the address information in the encoding block to the address information of the upgrade block, and end the firmware upgrade process.

[0068] See also Figure 1 and Figure 2 , Figure 6 and Figure 7 As shown, in one embodiment of the present invention, steps S10 to S50 are steps implemented by the storage device 10 after an abnormal power failure occurs during a normal firmware upgrade process. Before step S10, when the main controller 20 receives a firmware upgrade indication signal from the host 60, the main controller 20 switches from the working mode to the firmware upgrade mode. In the firmware upgrade mode, the main controller 20 suspends the ongoing reading, writing and checking tasks of the storage device 10, and updates the upgrade block 320 through the first update module 510, and updates the encoding block 310 through the second update module 520. Specifically, the working steps of the first update module 510 are consistent with step S30 and step S40. The working steps of the second update module 250 are consistent with step S50. Step S30 includes step S31 and step S32.

[0069] Step S31: Acquire the address information of the upgrade block from the system block or any coding block.

[0070] Step S32: Find the corresponding upgrade block and erase the stored data of the upgrade block.

[0071] See also Figure 1 and Figure 2 , Figure 6 and Figure 7 As shown, in one embodiment of the present invention, the number of coding blocks 310 and upgrade blocks 320 is at least two. In this embodiment, each coding block 310 stores the address information of all upgrade blocks 320. Therefore, in step S31, by reading the address information of the upgrade block 310 from any coding block 310, the addressing of the upgrade block 310 can be completed. Then, step S32 is executed, and according to the obtained address information, multiple upgrade blocks 320 corresponding to the address information are found, and the storage data of multiple upgrade blocks 320 are erased. It should be noted that step S31 includes steps S311 to S311 to S313.

[0072] Step S311: Determine whether the address information stored in the address storage page of the coding block is the address information of the coding block.

[0073] Step S312: When the address storage page of the coding block stores the address information of the coding block, the address information of the upgrade block is obtained from the system block.

[0074] Step S313: When the address storage page of the coding block does not store the address information of the coding block, directly obtain the address information of the upgrade block from the coding block.

[0075] See also Figure 1 and Figure 2 , Figure 6 and Figure 7 As shown, in one embodiment of the present invention, before the first firmware upgrade, the address information of the coding block 310 is stored in the coding block 310, and each coding block 310 stores the address information of all coding blocks 310. Therefore, in step S311, according to the storage object in the address storage page of the coding block 310, it can be confirmed whether the current firmware upgrade process is the first time, without the need to traverse and read the storage block, and without the need to set the flag and query. In the first firmware upgrade process, the address information of the coding block 310 is stored in the coding block 310. In this embodiment, the address information of the upgrade block 320 is obtained from the system block of the storage device 10 only in the first firmware upgrade process. In the second and subsequent firmware upgrade processes, the address information of the upgrade block 320 is stored in the coding block 310, so the address information of the upgrade block 320 is directly obtained from the coding block 310. After erasing multiple upgrade blocks 320, step S40 is then executed, wherein step S40 includes steps S41 to S43.

[0076] Step S41: adjust the size of the new version of the firmware, and write the new version of the firmware into the firmware storage page of the upgrade block.

[0077] Step S42: Obtain configuration information of the storage device from the coding block, and write the configuration information and address information of the upgrade block into the address storage page of the upgrade block.

[0078] Step S43: write the spare data into the padding data page and the blank firmware storage page of the upgrade block.

[0079] See also Figure 1 and Figure 2 , Figures 6 to 8As shown, in one embodiment of the present invention, the firmware storage page 350 is set to a storage page 303 with a fixed number of pages and a fixed physical position. Therefore, in the firmware upgrade mode, if the new version of the firmware is larger than the storage capacity of the firmware storage page 350, then in step S41, the new version of the firmware is first compressed until the volume of the new version of the firmware is less than or equal to the storage capacity of the firmware storage page 350. In this embodiment, the processing and adjustment method for the new version of the firmware also includes methods such as deletion and reprogramming. In step S41, the new version of the firmware is written to the firmware storage page 350 of the upgrade block 320. In step S42, the configuration information of the storage device 10 and the address information of the upgrade block 320 are read from the address storage page 340 of the encoding block 310, and the configuration information and the address information of the upgrade block 320 are written into the address storage page 340 of the upgrade block 320. In step S43, spare data is written to the fill data page 360 ​​of the upgrade block 320. If there are blank firmware storage pages 350 after the new version of the firmware is written, the spare data is written to the blank firmware storage pages 350. If all firmware storage pages 350 of the upgrade block 320 are occupied after the new version of the firmware is written, there is no need to write spare data to the firmware storage pages 350.

[0080] See also Figure 1 and Figure 2 , Figures 6 to 8 As shown, in one embodiment of the present invention, regarding step S50, it should be noted that step S50 performs a firmware upgrade process in the event of an abnormal power failure. In a normal firmware upgrade process, step S50 can be executed, or the stored data in multiple coding blocks 310 can be directly updated through the second update module 520. In this embodiment, in the step of directly updating the stored data in multiple coding blocks 310, any coding block 310 is selected to be erased, and the data of another coding block 310 is transferred to the erased coding block 310. It should be noted that in step S311, when the address storage page 340 of the coding block 310 stores the address information of the coding block 310, in the process of transferring the data of another coding block 310 to the erased coding block 310, the address information of the coding block 310 in the address storage page 340 is replaced with the address information of the upgrade block 320. In step S311, when the address storage page of the coding block does not store the address information of the coding block, in the step of transferring the data of another coding block 310 to the erased coding block 310, the stored data of another coding block 310 is directly and completely transferred to the erased data coding block 310. Then, the other coding block 310 is erased, and the information in the first erased coding block 310 is transferred to the other coding block 310, thereby realizing the update of the stored data and improving the security of data update.

[0081] See also Figure 1 and Figure 2 , Figures 6 to 9As shown, in one embodiment of the present invention, during the firmware upgrade process, if an abnormal power failure occurs, steps S10 to S50 are executed. In this embodiment, step S10 is implemented by the verification module 530. Step S10 includes steps S11 to S17.

[0082] Step S11: Acquire a storage page to be verified as the storage page to be verified.

[0083] Step S12: read the storage pages to be verified in sequence.

[0084] Step S13, determine whether the storage page to be verified is blank, if the storage page to be verified is blank, execute step S17, if the storage page to be verified is not empty, execute step S14.

[0085] Step S14, determine whether the number of error bits read from the storage page to be verified exceeds a threshold value, if the number of error bits is greater than the threshold value, execute step S17, if the number of error bits is less than or equal to the threshold value, execute step S15.

[0086] Step S15, determine whether the metadata of the storage page to be verified matches. If the metadata of the storage page to be verified matches, execute step S17; if the metadata of the storage page to be verified does not match, execute step S16.

[0087] Step S16: The current coding block is normal, and the current coding block is used as the information update basis.

[0088] Step S17: The current coding block is abnormal, and the next coding block is checked.

[0089] See also Figure 1 and Figure 2 , Figures 6 to 9As shown, in one embodiment of the present invention, in step S11, the storage page to be checked is all the storage pages 303 of the coding block 310. In this embodiment, multiple coding blocks 310 are checked in sequence. In step S12, the storage pages to be checked are read in sequence, and through steps S13 to S15, it is confirmed in sequence whether the storage page to be checked is blank, whether the number of error bits of the storage page to be checked exceeds the threshold, and whether the metadata of the storage page to be checked matches. If any of the verification items fails, the current coding block 310 is determined to be abnormal, and the next coding block 310 is checked. Among them, in step S13, the storage page 303 of the non-critical data in the coding block 310 also stores spare data. The spare data can not only improve the stability of data storage, but also when an abnormal power failure occurs, if the abnormal power failure affects the coding block 310, there is a high probability of data loss. Therefore, by directly checking whether the storage page to be checked is empty, it is possible to determine whether the coding block 310 is affected by the abnormal power failure with as few steps and resource occupation as possible. In step S14, if the data is not empty, it is determined whether the number of error bits exceeds the threshold value, and it can be determined whether the stored data is wrong. The present invention does not limit the value of the threshold value, and it can be set according to the capability of the error correction module 206. In step S15, metadata is used to describe the information of data attributes, and is used to support functions such as indicating storage location, historical data, resource search, and file records. The present invention does not limit the content of metadata. By matching metadata, it can be determined whether the current coding block 310 can support the update process provided by the present invention. In step S16, if the current coding block 310 is a normal block, the current storage block 310 can be used as the basis for update in subsequent information acquisition, such as acquisition of configuration information, acquisition of address information of the upgrade block 320, and data update of the coding block 310. If the current coding block 310 is an abnormal block, the next coding block 310 is checked until a normal coding block 310 is obtained.

[0090] It should be noted that according to the control method provided by the present invention, even if an abnormal power failure occurs, it can ensure that at least one normal coding block 310 is retained in the storage device 10. Therefore, in the step of traversing and verifying multiple coding blocks 310, at least one normal coding block 310 can be obtained. In this embodiment, in order to save resources, after obtaining a normal coding block 310, the verification can be stopped to start the firmware upgrade process as soon as possible. In other embodiments of the present invention, after obtaining a normal coding block 310, the verification can also be continued until multiple coding blocks 310 are traversed and verified.

[0091] See also Figure 1 and Figure 2 , Figures 6 to 9As shown, in one embodiment of the present invention, in step S20, the coding block 310 without error, that is, the coding block 310 that passes the verification step of step S10, is used as the reference coding block for firmware upgrade. In step S20, the address information of the upgrade block 310 is obtained from the reference coding block or the upgrade block. It should be noted that in the present invention, if the current firmware upgrade process is the first firmware upgrade, the address information of the current upgrade block 320 is obtained from the upgrade block. If the current firmware upgrade process is the second firmware upgrade process or a subsequent firmware upgrade process, the address information of the upgrade block 310 is obtained from the reference coding block. The address information of the upgrade block 320 is obtained from the system block. This step only occurs in the first firmware upgrade, which greatly reduces the number of storage pages that need to be read. And the address information of the upgrade block 320 is directly obtained from the coding block 310 storing the first version of the firmware, and the efficiency of obtaining information is greatly improved.

[0092] It should be noted that when the encoding block 310 is abnormal, the upgrade block 320 is likely to be abnormal. In this embodiment, after the verification step of the encoding block 310, the verification of the upgrade block 320 can be omitted. When the system has enough time for the firmware upgrade process, after step S20 and before step S30, the upgrade block 320 can also be verified to verify the judgment of step S10. If the firmware upgrade time margin prepared by the system is insufficient, step S30 is directly executed after step S20.

[0093] See also Figure 1 and Figure 2 , Figures 6 to 10 As shown, in one embodiment of the present invention, step S50 includes steps S51 to S56.

[0094] Step S51, determine whether any coding block is abnormal. If any coding block is abnormal, execute step S52; if no coding block is abnormal, execute step S53.

[0095] Step S52: set normal coding blocks as first-category coding blocks, and set abnormal coding blocks as second-category coding blocks.

[0096] Step S53: select any coding block as the first type of coding block, and use one or more coding blocks outside the first type of coding blocks as the second type of coding blocks.

[0097] Step S54: erase the second type of coding block, and copy the data of the first type of coding block to the second type of coding block.

[0098] Step S55: While copying the data, the address information in the copy information is updated according to whether the current firmware upgrade process is the first firmware upgrade.

[0099] Step S56: erase the first type of coding block, and copy the data of the second type of coding block to the first type of coding block.

[0100] See also Figure 1 and Figure 2 , Figures 6 to 10 As shown, in one embodiment of the present invention, in step S51, it is determined whether there is an abnormal block among the multiple coding blocks 310. The verification result of step S10 can be used in the process of verifying the coding block 310. It should be noted that in step S10, if the reference coding block is obtained by traversal verification, then in step S52, directly according to the verification result of step S10, the abnormal coding block 310 is used as the second type of coding block, and the reference coding block is used as the first type of coding block. In step S10, if the remaining coding blocks 310 are no longer verified after obtaining the reference coding block, then in step S51, the coding blocks 310 other than the reference coding block are continued to be verified. In step S51, the verification module 530 is called to implement the same verification steps as step S10 until multiple coding blocks 310 are traversed. And in step S52, according to the verification result in step S51, the abnormal coding block 310 is used as the second type of coding block, and the normal coding block 310 is used as the first type of coding block.

[0101] See also Figure 1 and Figure 2 , Figures 6 to 10 As shown, in another embodiment of the present invention, in step S51, the reference coding block is used as the first type of coding block, and the multiple coding blocks 310 other than the reference coding block are used as the second type of coding blocks. In this embodiment, according to the test result of step S10, the reference coding block obtained in step S10 is directly used as the first type of coding block. It should be noted that, in this embodiment, the second type of coding block is not necessarily an abnormal block, but may also be a normal block, and the present invention does not limit this, thereby improving the efficiency of firmware upgrade after power-on, shortening the firmware upgrade time, and reducing resource occupancy.

[0102] See also Figure 1 and Figure 2 , Figures 6 to 10As shown, in one embodiment of the present invention, in step S54 and step S55, the data reliability in the first type of coding block is higher, so the second type of coding block is erased, and the data in the first type of coding block is copied and transferred to the first type of coding block. In the process of copying data, the address information in the copied data is updated, specifically, the address information of the coding block 310 is updated to the address information of the upgrade block 320, or the address information of the upgrade block 320 is updated to the address information of the new upgrade block 320. When a bad block appears, the address information of the upgrade block 320 can be replaced, so the address information in the coding block 310 is updated in each firmware upgrade to ensure that the address information of the upgrade block 310 can be reliably obtained. It should be noted that in the process of copying data, the spare data will also be copied to the corresponding storage page 303 of the second type of coding block. After completing the information editing of the second type of coding block, the information in the second type of coding block is more accurate information, so in step S56, the first type of coding block is erased, and the data of the second type of coding block is copied to the first type of coding block. During the process of updating the coding block 310, if an abnormal power failure occurs during any process, whether after power is restored or during a normal firmware upgrade, reliable configuration information and address information can be retained in the special block, and the firmware upgrade can be achieved without reading the upgrade block.

[0103] The embodiments of the present invention disclosed above are only used to help illustrate the present invention. The embodiments do not describe all the details in detail, nor do they limit the invention to the specific embodiments described. Obviously, many modifications and changes can be made according to the content of this specification. This specification selects and specifically describes these embodiments in order to better explain the principles and practical applications of the present invention, so that those skilled in the art can understand and use the present invention well. The present invention is limited only by the claims and their full scope and equivalents.

Claims

1. A storage device, characterized in that: The storage device has a firmware upgrade mode and a working mode, and the storage device includes: A main controller, electrically connected to the host; a memory electrically connected to the main controller, wherein the memory stores a startup firmware, and in the firmware upgrade mode, the main controller calls the startup firmware; and A flash memory, electrically connected to the main controller, the flash memory comprising a plurality of working blocks, at least two coding blocks, at least two upgrading blocks and a system block, wherein the coding block stores a first version of the firmware, the upgrading block stores a new version of the firmware, the system block records address information of the coding block, address information of the upgrading block and address information of the working block, and during the first firmware upgrade, the main controller queries the upgrading block according to the address information in the system block, wherein the working block, the coding block and the upgrading block are storage blocks of the flash memory; The page architecture of the coding block and the upgrade block is the same, before the first firmware upgrade, the address information of the coding block is stored in the coding block, after the first firmware upgrade, the address information of the upgrade block is stored in the coding block and the upgrade block respectively, and in the coding block, the address information of the upgrade block replaces the address information of the coding block; Among them, when the storage device has an abnormal power failure during the firmware upgrade process, after power is restored, the storage data of multiple coding blocks are read in sequence, and the storage data of the coding blocks are checked whether they are erroneous. When any of the coding blocks is not erroneous, the address information of the upgrade block is obtained from the system block or the coding block that is not erroneous, and according to the address information of the upgrade block, the upgrade block is searched, the storage data of multiple upgrade blocks are erased, and the new version of firmware is written to the upgrade block, and the address information in the coding block is updated to the address information of the upgrade block.

2. A storage device according to claim 1, characterized in that: The first version of firmware is the program code recorded into the coding block before the storage device is activated, and the new version of firmware is the program code written into the upgrade block during the most recent firmware upgrade.

3. A storage device according to claim 1, characterized in that: The upgrade block includes: A plurality of firmware storage pages, wherein the firmware storage pages store program code files of the firmware; a plurality of address storage pages, wherein the address storage pages store configuration information of the storage device and address information of the plurality of upgrade blocks, wherein the configuration information is preset information set when the storage device is powered on; and A plurality of filling data pages are provided, wherein the filling data pages store spare data, wherein the spare data is invalid data automatically generated by the system.

4. A storage device according to claim 3, characterized in that: The startup firmware includes a first update module. In the firmware upgrade mode, the first update module receives the file package of the new version of the firmware, the configuration information in the coding block and the address information of the upgrade block, and stores the new version of the firmware in the firmware storage pages of multiple upgrade blocks, and stores the configuration information and the address information of the upgrade block in the address storage page of the upgrade block.

5. A storage device according to claim 4, characterized in that: The startup firmware includes a second update module, and the update process of the second update module is located after the update process of the first update module. In the firmware upgrade mode, the second update module classifies the multiple coding blocks into a first category of coding blocks and a second category of coding blocks, wherein the first category of coding blocks are error-free coding blocks, and the second category of coding blocks are abnormal blocks or error-free coding blocks.

6. A storage device according to claim 5, characterized in that: The startup firmware includes a verification module. After an abnormal power failure occurs during the firmware upgrade process, the verification module verifies the coding block and classifies the coding block into the abnormal block or the non-error coding block according to the verification information, wherein the verification information includes data missing information, data error information and metadata matching information of the coding block.

7. A method for controlling a storage device, based on the storage device according to claim 1, characterized in that: The control method of the storage device comprises the following steps: When an abnormal power failure occurs during the firmware upgrade process, after power is restored, the stored data of multiple coding blocks are read in sequence, and the stored data of the coding blocks are checked for errors; When any of the coding blocks is not faulty, acquiring the address information of the upgrade block from the system block or the coding block that is not faulty; According to the address information of the upgrade block, find the upgrade block, and erase the storage data of a plurality of the upgrade blocks; Writing a new version of firmware to the upgrade block; and The address information in the encoding block is updated to the address information of the upgrade block.

8. The method for controlling a storage device according to claim 7, characterized in that: The control method of the storage device includes obtaining the coding block without error, and the steps are as follows: Reading multiple coding blocks in sequence, and determining in sequence whether the coding blocks are missing data, whether the data stored in the coding blocks are erroneous, and whether the metadata of the coding blocks match; If the coding block is missing data, or the data stored in the coding block is erroneous, or the metadata of the coding block does not match, the coding block is classified as an abnormal block; as well as If the stored data of the coding block is complete, the data stored in the coding block is correct, and the metadata of the coding block matches, the coding block is classified as an error-free coding block.

9. The method for controlling a storage device according to claim 7, characterized in that: The steps of writing the new version of the firmware to the upgrade block include: erasing a plurality of the upgrade blocks; Download the file package of the new version of the firmware, and write the file package of the new version of the firmware into the firmware storage page of the upgrade block; Acquire configuration information of the storage device from the address storage page of the coding block, acquire address information of the upgrade block from the address storage page of the coding block or the system block, and write the configuration information and the address information of the upgrade block into the address storage page of the upgrade block; and The blank storage pages of the upgrade block are filled with spare data until the upgrade block is filled.