Method and device for recovering abnormal state of Nand Flash and electronic equipment

By pre-storing the initial mapping table in Nand Flash and rewrite it in an abnormal state, the problem of difficulty in recovering the abnormal state of Nand Flash is solved, and data security and recovery efficiency are achieved.

CN119883738APending Publication Date: 2025-04-25SHENZHEN CITY TECHWIN SEMICONDUCTOR COMPANY LIMITED
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202411973675.4
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-12-30
Publication Date
2025-04-25

AI Technical Summary

Technical Problem

When an abnormal state occurs in Nand Flash, the user can only restore it through formatting, which will cause the data to be unable to be restored, and it may not be formatted when facing special abnormal states, resulting in the inability to effectively restore the abnormal state of Nand Flash.

Method used

By pre-stored the initial mapping table in the backup area and table area of ​​Nand Flash, when an exception state is detected, the initial mapping table in the backup area is read and rewrite to the table area, and format Nand Flash when a format command is received to restore factory settings.

Benefits of technology

It effectively avoids data loss and realizes effective recovery of Nand Flash exception status, avoiding users' faces inability to format.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119883738A_ABST
    Figure CN119883738A_ABST
Patent Text Reader

Abstract

The invention provides a method and device for recovering an abnormal state of a Nand Flash and electronic equipment. An initial mapping table is pre-stored in a backup area and a table area of the Nand Flash; after a first command sent by an upper computer is received, if it is detected that the Nand Flash is in an abnormal state, reading the initial mapping table in the backup area, and rewriting the initial mapping table into the table area; and receiving a formatting command sent by the upper computer, and formatting the Nand Flash. According to the mode, the initial mapping table is pre-stored in the backup area, and when the Nand Flash enters the abnormal state, the initial mapping table in the backup area is rewritten into the table area, so that data loss can be avoided, and the abnormal state of the Nand Flash can be effectively recovered.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of Nand Flash abnormal state recovery, and in particular to a method, a device and an electronic device for recovering Nand Flash abnormal state. Background Art

[0002] Nand Flash, as a portable data storage medium, is widely used in various electronic devices. During the use of Nand Flash, various abnormal states may be encountered. When Nand Flash is in an abnormal state, the user can only restore the abnormal state by formatting. At this time, the data cannot be restored, resulting in data loss. In addition, in the face of some special abnormal states, it may even be impossible to format, resulting in the inability to effectively restore the abnormal state of Nand Flash. Summary of the invention

[0003] The object of the present invention is to provide a method, a device and an electronic device for recovering the abnormal state of Nand Flash, so as to avoid data loss and effectively recover the abnormal state of Nand Flash.

[0004] The present invention provides a method for restoring an abnormal state of Nand Flash, which is applied to Nand Flash, and Nand Flash is connected to a host computer; an initial mapping table is pre-stored in a backup area and a table area of ​​the Nand Flash; when data is written into the Nand Flash, the initial mapping table in the table area is continuously updated as the data is written, and a first mapping table is obtained after each update;

[0005] Methods include:

[0006] After receiving the first command sent by the host computer, if it is detected that the Nand Flash is in an abnormal state, the initial mapping table in the backup area is read, and the read initial mapping table is rewritten into the table area;

[0007] Receive the format command sent by the host computer, and format the Nand Flash according to the format command to restore the Nand Flash to factory settings.

[0008] Furthermore, the backup area of ​​the Nand Flash includes at least one free page of a boot block; and the table area of ​​the Nand Flash includes free pages of a mapping block.

[0009] Furthermore, the host computer is connected to the Nand Flash through a preset tool; the initial mapping table is pre-stored in the backup area and the table area of ​​the Nand Flash in the following manner:

[0010] An initial mapping table sent by the host computer through a preset tool is received, and the initial mapping table is written into an idle page of a mapping block and an idle page of at least one boot block, so that the initial mapping table and the boot code share the boot block.

[0011] Further, the abnormal state includes an emergency abnormal state and a non-emergency abnormal state; after receiving the first command sent by the host computer, if it is detected that the Nand Flash is in an abnormal state, the steps of reading the initial mapping table in the backup area and rewriting the read initial mapping table into the table area include:

[0012] After receiving the first command sent by the host computer, if it is detected that Nand Flash is in a non-emergency abnormal state and receives a second command sent by the host computer, the initial mapping table in the backup area is read and the read initial mapping table is rewritten into the table area; the non-emergency abnormal state includes a write protection state.

[0013] Furthermore, the method also includes:

[0014] After receiving the first command sent by the host computer, if it is detected that the Nand Flash is in an emergency abnormal state, the target first mapping table obtained by the last update in the table area is read;

[0015] If the target first mapping table can be read normally, the read target first mapping table is rewritten into the table area.

[0016] Furthermore, the method also includes:

[0017] If the target first mapping table cannot be read normally, the initial mapping table in the backup area is read, and the read initial mapping table is rewritten into the table area.

[0018] Further, after receiving the first command sent by the host computer, if it is detected that the Nand Flash is in a non-emergency abnormal state, and the host computer receives a second command sent, the initial mapping table in the backup area is read, and the read initial mapping table is rewritten into the table area. The step also includes:

[0019] After receiving the first command sent by the host computer, if it is detected that the Nand Flash is in a non-emergency abnormal state, the data in the Nand Flash is read and the data in the Nand Flash is transmitted to the host computer for backup;

[0020] A second command sent by the host computer is received, the initial mapping table in the backup area is read, and the read initial mapping table is rewritten into the table area.

[0021] The present invention also provides a device for recovering the abnormal state of Nand Flash, the device is arranged in Nand Flash, and Nand Flash is connected to a host computer; an initial mapping table is pre-stored in a backup area and a table area of ​​Nand Flash; wherein, when data is written into Nand Flash, the initial mapping table in the table area is continuously updated as the data is written, and a first mapping table is obtained after each update;

[0022] The device includes:

[0023] The detection module is used for, if it detects that the Nand Flash is in an abnormal state after receiving the first command sent by the host computer, reading the initial mapping table in the backup area and rewriting the read initial mapping table into the table area;

[0024] The formatting module is used to receive the formatting command sent by the host computer and format the Nand Flash according to the formatting command to restore the Nand Flash to factory settings.

[0025] An electronic device provided by the present invention comprises a memory and a processor. The memory stores a computer program that can be run on the processor. When the processor executes the computer program, the steps of any one of the above methods for restoring the abnormal state of Nand Flash are implemented.

[0026] The present invention provides a computer-readable medium having a non-volatile program code executable by a processor, wherein the program code enables the processor to execute any of the steps of the above-mentioned method for restoring the abnormal state of Nand Flash.

[0027] The present invention provides a method, device and electronic device for restoring the abnormal state of Nand Flash. The method is applied to Nand Flash, Nand Flash is connected to a host computer; an initial mapping table is pre-stored in the backup area and table area of ​​Nand Flash; when data is written to Nand Flash, the initial mapping table in the table area is continuously updated as the data is written, and a first mapping table is obtained after each update; the method includes: after receiving a first command sent by the host computer, if it is detected that Nand Flash is in an abnormal state, the initial mapping table in the backup area is read, and the read initial mapping table is re-written into the table area; a formatting command sent by the host computer is received, and Nand Flash is formatted according to the formatting command, so that Nand Flash is restored to factory settings. In this way, the backup area and the table area of ​​Nand Flash are pre-stored with the initial mapping table, and when Nand Flash enters an abnormal state, the initial mapping table in the backup area is re-written into the table area of ​​Nand Flash, so that data loss can be avoided and the abnormal state of Nand Flash can be effectively restored. BRIEF DESCRIPTION OF THE DRAWINGS

[0028] In order to more clearly illustrate the specific implementation methods of the present invention or the technical solutions in the prior art, the drawings required for use in the specific implementation methods or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are some implementation methods of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.

[0029] Figure 1 A flowchart of a method for restoring a Nand Flash abnormal state provided by an embodiment of the present invention;

[0030] Figure 2 A schematic diagram of updating an initial mapping table provided by an embodiment of the present invention;

[0031] Figure 3 A schematic diagram of storing a first mapping table provided by an embodiment of the present invention;

[0032] Figure 4 A flowchart of another method for restoring a Nand Flash abnormal state provided by an embodiment of the present invention;

[0033] Figure 5 A schematic diagram of a boot block storing an initial mapping table provided by an embodiment of the present invention;

[0034] Figure 6A schematic diagram of a process for quickly recovering a Nand Flash abnormal state provided by an embodiment of the present invention;

[0035] Figure 7 A schematic diagram of a table area provided in an embodiment of the present invention;

[0036] Figure 8 A schematic diagram of the structure of a device for recovering an abnormal state of Nand Flash provided by an embodiment of the present invention;

[0037] Fig. 9 A schematic diagram of the structure of an electronic device provided by an embodiment of the present invention. DETAILED DESCRIPTION

[0038] The technical solution of the present invention will be clearly and completely described below in conjunction with the embodiments. Obviously, the described embodiments are part of the embodiments of the present invention, rather than 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.

[0039] In modern society, data storage and data recovery technology have become necessities for people's lives and work. With the development of technology, Nand Flash (flash memory, also known as flash memory card) as a portable data storage medium is widely used in various electronic devices, such as cameras, mobile phones, computers, etc. In the process of using Nand Flash, various abnormal states may be encountered, such as write protection state. Write protection state refers to the state where Nand Flash cannot perform write operations, which may cause the device to malfunction.

[0040] At present, when Nand Flash is in abnormal state, users can only restore the abnormal state by formatting. During the reformatting process, all data stored in the Nand Flash will be cleared, which may cause the loss of important data and the dilemma of data being unable to be restored. When the Nand Flash enters the write-protected state, it may even be impossible to format. At this time, users cannot use this memory card. In addition, in the face of some complex and special abnormal states, it may even be impossible to format, resulting in the inability to effectively restore the abnormal state of the Nand Flash, which requires professional personnel to handle.

[0041] Based on this, the present application provides a method, device and electronic device for recovering the abnormal state of Nand Flash, so as to avoid data loss and effectively recover the abnormal state of Nand Flash.

[0042] To facilitate understanding of the present embodiment, a method for recovering an abnormal state of Nand Flash disclosed in an embodiment of the present invention is first described in detail. The method is applied to Nand Flash, and Nand Flash is connected to a host computer. An initial mapping table is pre-stored in a backup area and a table area of ​​Nand Flash. When data is written into Nand Flash, the initial mapping table in the table area is continuously updated as the data is written, and a first mapping table is obtained after each update. Figure 1 As shown, the method comprises the following steps:

[0043] Step S102: after receiving the first command sent by the host computer, if it is detected that the Nand Flash is in an abnormal state, the initial mapping table in the backup area is read, and the read initial mapping table is rewritten into the table area.

[0044] The above-mentioned Nand Flash is a type of flash memory, which uses a nonlinear macro unit mode internally, providing a cheap and effective solution for the realization of solid-state large-capacity memory. Nand-flash memory has the advantages of large capacity and fast rewriting speed, and is suitable for storing large amounts of data. Therefore, it has been increasingly widely used in the industry.

[0045] The above-mentioned upper computer generally refers to a computer that can directly issue control commands, usually a PC / hostcomputer / master computer / upper computer.

[0046] The above-mentioned initial mapping table can be understood as a mapping table (logical-physical mapping table) written into the backup area and table area of ​​Nand Flash during the mass production stage before leaving the factory. This initial mapping table contains the initial logical-physical mapping relationship of the data in Nand Flash, that is, the mapping relationship between the initial logical address of the data and the physical address.

[0047] The backup area of ​​the Nand Flash mentioned above can be understood as the available page of the Nand Flash boot block;

[0048] The above-mentioned Nand Flash table area can be understood as an available page of the Nand Flash mapping block.

[0049] In actual implementation, after the initial mapping table is written into the backup area and the table area of ​​the Nand Flash at the same time, as user data is continuously written into the Nand Flash, the initial mapping table in the backup area remains unchanged as a backup; and the initial mapping table in the table area is continuously updated as user data is continuously written, and a first mapping table is obtained after each update; for details, please refer to Figure 2 A schematic diagram of an initial mapping table update is shown, T1 represents the time when the initial mapping table saved in the table area starts to be updated, LP1 represents the first mapping table saved in the table area after the initial mapping table is updated; T2 represents the update time of the first mapping table LP1 saved in the table area, LP2 represents the new first mapping table saved in the table area after the first mapping table LP1 is updated, when user data is written, the initial mapping table starts to be updated to obtain LP1, when user data continues to be written, LP1 starts to be updated to obtain LP2, when user data continues to be written, LP2 starts to be updated to obtain LP3, and so on, and no further details are given.

[0050] In fact, the first mapping table obtained after each update should be saved in a new available page (free page) of the mapping block storing the initial mapping table. For details, see Figure 3 A schematic diagram of saving a first mapping table is shown. It is assumed that the initial mapping table is stored in Page X. At this time, Page Y is a new available page. Then, when the initial mapping table is updated, the first mapping table LP1 obtained is stored in Page Y. At this time, Page Z is a new available page. Then, when the first mapping table LP1 is updated, the first mapping table LP2 obtained is stored in Page Z.

[0051] The first command may be a read command or a write command, and the abnormal state may be a corresponding read abnormal state or write abnormal state (a write operation cannot be performed, that is, data cannot be written).

[0052] In the specific implementation process, the user can first send a read command to Nand Flash through the host computer to read the currently updated first mapping table. If the read fails, that is, the latest updated first mapping table cannot be read normally, it is determined that the Nand Flash is in an abnormal state; if the read is successful, that is, the latest updated first mapping table can be read normally, the host computer can continue to send a write command to Nand Flash to write data to Nand Flash, but if the write fails, that is, the data cannot be written to Nand Flash normally, it can be determined that the Nand Flash is in an abnormal state.

[0053] When it is determined that the Nand Flash is in an abnormal state, the Nand Flash may read the initial mapping table in the backup area (ie, the backup initial mapping table) and rewrite it into a new available page (free page) of the mapping block.

[0054] Step S104, receiving a format command sent by the host computer, and formatting the Nand Flash according to the format command to restore the Nand Flash to factory settings.

[0055] In the specific implementation process, after executing the above step S102 and rewriting the backed up initial mapping table into the new available page of the mapping block, the user can first send a format command to the Nand Flash through the host computer to let the Nand Flash perform the formatting operation. After the Nand Flash completes the formatting operation, it is restored to the factory settings.

[0056] The above embodiment provides a method for restoring the abnormal state of Nand Flash, the method is applied to Nand Flash, Nand Flash is connected to a host computer; the backup area and the table area of ​​Nand Flash pre-store an initial mapping table; when data is written to Nand Flash, the initial mapping table in the table area is continuously updated as the data is written, and a first mapping table is obtained after each update; the method includes: after receiving a first command sent by the host computer, if it is detected that Nand Flash is in an abnormal state, the initial mapping table in the backup area is read, and the read initial mapping table is rewritten into the table area; receiving a formatting command sent by the host computer, and formatting Nand Flash according to the formatting command, so that Nand Flash is restored to factory settings. In this way, the backup area and the table of Nand Flash pre-store an initial mapping table, and when Nand Flash enters an abnormal state, by rewriting the initial mapping table in the backup area into the table area of ​​Nand Flash, data loss can be avoided and the abnormal state of Nand Flash can be effectively restored.

[0057] The embodiment of the present invention also provides another method for recovering the abnormal state of Nand Flash. The method is implemented on the basis of the method of the above embodiment. The backup area of ​​Nand Flash includes at least one free page of the boot block; the table area of ​​Nand Flash includes the free page of the mapping block, and the host computer is connected to Nand Flash through a preset tool; the abnormal state includes an emergency abnormal state and a non-emergency abnormal state; Figure 4 As shown, the method comprises the following steps:

[0058] Step S202, receiving an initial mapping table sent by the host computer through a preset tool, and writing the initial mapping table into a free page of a mapping block and a free page of at least one boot block, so that the initial mapping table and the boot code share the boot block.

[0059] In fact, there can be multiple flash blocks in Nand Flash, and each flash block can have multiple flash pages. The above-mentioned boot block can be understood as a flash block in Nand Flash used to store boot code; the above-mentioned mapping block can be understood as a flash block in Nand Flash used to store the initial mapping table and the updated first mapping table.

[0060] The preset tool may be a mass production tool, through which the host computer is connected to the Nand Flash, and the mass production tool is used to transmit commands or data (user data, initial mapping table, etc.) sent by the host computer to the Nand Flash.

[0061] In the specific implementation process, during the mass production stage before Nand Flash leaves the factory, the manufacturer can use the mass production tool to burn the initial mapping table into the backup area of ​​Nand Flash and the table area of ​​Nand Flash during the mass production process. That is, during the mass production stage before the flash memory card leaves the factory, the initial mapping table inside Nand Flash is stored as a backup. The initial mapping table backup can be written into the available page of the Nand Flash boot block through the mass production tool, and share a block with the boot code. Because the boot block itself has no other use except writing the boot code, this can reduce the extra space waste caused by the backup mapping table.

[0062] In fact, if the backup initial mapping table is only written to an available page of a boot block, then after writing, when the boot block fails and becomes unavailable, the backup initial mapping table cannot be read from the boot block, and cannot be rewritten into the table area, resulting in the inability to restore the abnormal state of the Nand Flash. Therefore, in order to avoid this situation, the backup initial mapping table is generally written to the available pages of multiple boot blocks. For details, see Figure 5 The schematic diagram of a boot block storing an initial mapping table is shown, and the backup initial mapping table (ie Figure 5 The backup mapping table in the Figure 5 The available pages (i.e., blocks 0, 1, 2, and 3) in Figure 5 In Page 0 of block 0, block 1, block 2 and block 3).

[0063] Step S204, after receiving the first command sent by the host computer, if it is detected that the Nand Flash is in a non-emergency abnormal state and the host computer sends a second command, the initial mapping table in the backup area is read and the read initial mapping table is rewritten into the table area;

[0064] Specifically, the above step S204 can be implemented by following the steps 1 to 2:

[0065] Step 1: After receiving the first command sent by the host computer, if it is detected that the Nand Flash is in a non-emergency abnormal state, the data in the Nand Flash is read and the data in the Nand Flash is transferred to the host computer for backup;

[0066] The non-emergency abnormal state may be a write protection state (equivalent to a write abnormal state), that is, a state in which normal reading is possible but normal writing is not possible.

[0067] The first command includes a read command and a write command.

[0068] Step 2: Receive the second command sent by the host computer, read the initial mapping table in the backup area, and rewrite the read initial mapping table into the table area.

[0069] When Nand Flash enters a non-emergency abnormal state, that is, after Nand Flash receives the read command and write command sent by the host computer, it detects through the detection mechanism of the internal firmware (such as the register) of Nand Flash that the current latest first mapping table can be read normally, but data cannot be written normally. At this time, the user can choose to first read out and back up the existing data in Nand Flash (including data stored in the mapping block, data stored in the boot block, etc.), and then trigger the recovery process for the non-emergency abnormal state through a specific command (equivalent to the above-mentioned second command). After receiving the second command, the internal firmware will read the backed-up initial mapping table from the internal backup area of ​​Nand Flash and rewrite it to the latest free page of the mapping block.

[0070] Step S206: after receiving the first command sent by the host computer, if it is detected that the Nand Flash is in an emergency abnormal state, the target first mapping table obtained by the last update in the table area is read.

[0071] The above emergency abnormal state can be understood as a state in which the latest first mapping table cannot be read normally.

[0072] Step S208: if the target first mapping table can be read normally, the read target first mapping table is rewritten into the table area.

[0073] In step S210 , if the target first mapping table cannot be read normally, the initial mapping table in the backup area is read, and the read initial mapping table is rewritten into the table area.

[0074] When Nand Flash enters a non-emergency exception state, that is, after Nand Flash receives the read command and write command sent by the host computer, when an error in reading the mapping table, etc. (that is, the current latest first mapping table cannot be read normally) is detected through the detection mechanism of the internal firmware (such as the register) of the Nand Flash, the recovery process for the emergency exception state can be triggered, and the previous (previous) first mapping table (that is, the target first mapping table) of the latest first mapping table with error is read. If the previous first mapping table can be read normally, the previous first mapping table is written to the latest free page of the mapping block; if the previous first mapping table cannot be read normally (a normal mapping table cannot be searched), the backup initial mapping table is read from the backup area and written to the latest free page of the mapping area.

[0075] Step S212, receiving a format command sent by the host computer, and formatting the Nand Flash according to the format command to restore the Nand Flash to factory settings.

[0076] For a better understanding of the above embodiments, please refer to Figure 6 A schematic diagram of a process for quickly recovering a Nand Flash abnormal state is shown.

[0077] In the specific implementation process, when the firmware logic inside Nand Flash detects that it has entered an abnormal state, the firmware will detect whether the abnormal state is fatal and determine the current abnormal type (that is, whether it is an emergency abnormal state or a non-emergency abnormal state), such as whether it can still be read and written normally, or whether the table can no longer be read normally. When a fatal error is detected that the latest first mapping table cannot be read normally (that is, the mapping table read is abnormal), the automatic recovery process for the emergency abnormal state will be triggered. Otherwise, choose whether to trigger the automatic recovery process for the non-emergency abnormal state to recover the table according to user needs.

[0078] If the automatic recovery process for emergency abnormal state is triggered, the previous data of the error mapping table (the latest first mapping table) (that is, the previous first mapping table of the latest first mapping table) will be read, because the previous data will retain the existing physical and logical mapping relationship to the greatest extent, and determine whether the previous data can be read normally (that is, determine whether the previous data read is normal). If it is normal, it will be based on this read data first, and the newly read data will be restored to the latest free page of the current mapping block (equivalent to directly restoring the current data to the table area), and Nand Flash will return to normal. At this time, the mapping relationship will retain the largest valid data. However, if the previous data also has a read error, that is, the previous data read is abnormal, the data (initial mapping table) backed up in the Nand Flash startup block will be read out, and the current data will be directly restored to the table area (equivalent to rewriting the initial mapping table into the free page of the mapping block) to ensure that the Nand Flash can be loaded into the correct initial mapping table when it is powered on again. After that, the Nand Flash can be restored to the factory settings after reformatting, and the Nand Flash will return to normal.

[0079] If the automatic recovery process for the emergency abnormal state is not triggered, for example, Nand Flash enters the write-protected state, the user can only read the data in the flash card and cannot perform other operations. At this time, the user can choose to read the data in the existing Nand Flash for backup first. When the user needs to restore, the automatic recovery process for the non-emergency abnormal state is triggered by a specific command. After the trigger, the internal firmware will read the data (initial mapping table) backed up in the Nand Flash boot block and restore the current data directly to the table area (equivalent to rewriting the initial mapping table into the free page of the mapping block). After that, the Nand Flash can be restored to the factory settings after reformatting, and the Nand Flash returns to normal.

[0080] In the prior art, after the Nand Flash enters an abnormal state, such as failure to read the mapping table, the user cannot normally read the data in the Nand Flash, nor can he perform regular formatting operations, such as Figure 7A schematic diagram of a table area is shown, where Page X, Page Y, and Page Z are mapping tables stored in free pages in a mapping block; assuming that the mapping block Page Z is read abnormally, Nand Flash makes Nand Flash into a virtual read-write mode due to the protection mechanism, and the user cannot use additional tools to obtain information in the solid-state drive; and in this application, assuming that the latest updated first mapping table Page Z is read abnormally, and the latest mapping relationship cannot be obtained, the previous mapping relationship can be obtained by reading the previous mapping table of Page Z (that is, Page Y). At this time, the mapping of Page Y is the mapping table that is closest to the current Nand Flash logical and physical data mapping relationship, and the mapping of Page Y can be written to the latest free page (that is, the next free page of the free page storing Page Z), thereby playing a role in restoring the mapping relationship.

[0081] In actual implementation, if Nand Flash enters the write protection state, the Nand Flash card cannot perform operations such as writing, and can only perform read operations. The user can first back up the data in the Nand Flash, so as to ensure the integrity and reliability of the data, and then trigger the SD command CMD56 (equivalent to the second command) to trigger the recovery process. At this time, the firmware will read the initial mapping table backed up in the boot block, and restore the initial mapping table that has passed the verification to the table area at the corresponding position, thereby realizing the factory settings of the Nand Flash. At this time, the Nand Flash is released from the write protection state, and can be formatted normally, and the Nand Flash is restored to the factory settings.

[0082] The method for recovering the abnormal state of Nand Flash provided in the above embodiment backs up the initial mapping table before leaving the factory. When Nand Flash enters the abnormal state, the recovery process is triggered to rewrite the current backup initial mapping table into the table area. At this time, the Nand Flash is reformatted and restored from the abnormal state to the normal state, thereby avoiding the problem of data loss.

[0083] Secondly, the method for recovering the abnormal state of Nand Flash provided in the above embodiment can effectively solve the recovery problem when Nand Flash enters an abnormal state by backing up and restoring the initial mapping table inside Nand Flash, thereby reducing the need for professional personnel to handle it, and does not need to rely on any tools. In any environment, as long as a fatal abnormality is detected, the process can be automatically triggered, which solves the problem that the existing recovery method may not be able to fully and effectively solve some complex abnormal states and requires professional personnel to handle it.

[0084] Furthermore, the method for recovering the abnormal state of Nand Flash provided in the above embodiment can complete the recovery operation of Nand Flash in a relatively short time by backing up and restoring the initial mapping table inside Nand Flash, thereby improving the recovery efficiency and reducing the user's recovery cost.

[0085] The embodiment of the present invention also provides a device for recovering the abnormal state of Nand Flash, the device is arranged in a host computer, the device is arranged in Nand Flash, and Nand Flash is connected to the host computer; an initial mapping table is pre-stored in the backup area and the table area of ​​Nand Flash; wherein, when data is written into Nand Flash, the initial mapping table in the table area is continuously updated as the data is written, and a first mapping table is obtained after each update; Figure 8 As shown, the device includes: a detection module 80, which is used to detect that the Nand Flash is in an abnormal state after receiving the first command sent by the host computer, read the initial mapping table in the backup area, and rewrite the read initial mapping table into the table area; a formatting module 81, which is used to receive the formatting command sent by the host computer, and format the Nand Flash according to the formatting command to restore the Nand Flash to the factory settings.

[0086] The device for restoring the abnormal state of Nand Flash provided in the above embodiment is arranged in a host computer, and the host computer is connected to Nand Flash; the backup area and the table area of ​​Nand Flash pre-store an initial mapping table; when data is written into Nand Flash, the initial mapping table in the table area is continuously updated as the data is written, and a first mapping table is obtained after each update; the device comprises: if it is detected that Nand Flash is in an abnormal state, a first command is sent to Nand Flash to make Nand Flash read the initial mapping table in the backup area, and re-write the read initial mapping table into the table area of ​​Nand Flash; a second command is sent to Nand Flash to format Nand Flash, so that Nand Flash is restored to factory settings. In the device, the backup area and the table of Nand Flash pre-store an initial mapping table, and when Nand Flash enters an abnormal state, by re-writing the initial mapping table in the backup area into the table area of ​​Nand Flash, data loss can be avoided, and the abnormal state of Nand Flash can be effectively restored.

[0087] Furthermore, the backup area of ​​the Nand Flash includes at least one free page of a boot block; and the table area of ​​the Nand Flash includes free pages of a mapping block.

[0088] Furthermore, the host computer is connected to the Nand Flash through a preset tool; the above-mentioned device also includes a receiving module, which is used to receive the initial mapping table sent by the host computer through the preset tool, and write the initial mapping table into the free page of the mapping block and the free page of at least one startup block, so that the initial mapping table and the startup code share the startup block.

[0089] Furthermore, the abnormal state includes an emergency abnormal state and a non-emergency abnormal state; the detection module is also used for:

[0090] After receiving the first command sent by the host computer, if it is detected that Nand Flash is in a non-emergency abnormal state and receives a second command sent by the host computer, the initial mapping table in the backup area is read and the read initial mapping table is rewritten into the table area; the non-emergency abnormal state includes a write protection state.

[0091] Furthermore, the detection module is also used to:

[0092] After receiving the first command sent by the host computer, if it is detected that the Nand Flash is in an emergency abnormal state, the target first mapping table obtained by the last update in the table area is read;

[0093] If the target first mapping table can be read normally, the read target first mapping table is rewritten into the table area.

[0094] Furthermore, the detection module is also used to:

[0095] If the target first mapping table cannot be read normally, the initial mapping table in the backup area is read, and the read initial mapping table is rewritten into the table area.

[0096] Furthermore, the detection module is also used to:

[0097] After receiving the first command sent by the host computer, if it is detected that the Nand Flash is in a non-emergency abnormal state, the data in the Nand Flash is read and the data in the Nand Flash is transmitted to the host computer for backup;

[0098] A second command sent by the host computer is received, the initial mapping table in the backup area is read, and the read initial mapping table is rewritten into the table area.

[0099] The implementation principle and technical effects of the device for recovering the abnormal state of Nand Flash provided in the embodiment of the present invention are the same as those of the method for recovering the abnormal state of Nand Flash in the aforementioned embodiment. For the embodiment of the device for recovering the abnormal state of Nand Flash, reference may be made to the corresponding contents in the method for recovering the abnormal state of Nand Flash in the aforementioned embodiment.

[0100] The embodiment of the present invention further provides an electronic device, see Fig. 9 As shown, the electronic device includes a processor 130 and a memory 131 , wherein the memory 131 stores machine executable instructions that can be executed by the processor 130 , and the processor 130 executes the machine executable instructions to implement the above method for restoring the abnormal state of Nand Flash.

[0101] Further, Fig. 9 The electronic device shown further includes a bus 132 and a communication interface 133 , and the processor 130 , the communication interface 133 and the memory 131 are connected via the bus 132 .

[0102] The memory 131 may include a high-speed random access memory (RAM), and may also include a non-volatile memory, such as at least one disk storage. The communication connection between the system network element and at least one other network element is realized through at least one communication interface 133 (which may be wired or wireless), and the Internet, wide area network, local area network, metropolitan area network, etc. may be used. The bus 132 may be an ISA bus, a PCI bus, or an EISA bus, etc. The bus may be divided into an address bus, a data bus, a control bus, etc. For ease of representation, Fig. 9 Only one bidirectional arrow is used in the diagram, but this does not mean that there is only one bus or only one type of bus.

[0103] The processor 130 may be an integrated circuit chip with signal processing capabilities. In the implementation process, each step of the above method can be completed by the hardware integrated logic circuit or software instructions in the processor 130. The above processor 130 can be a general-purpose processor, including a central processing unit (CPU), a network processor (NP), etc.; it can also be a digital signal processor (DSP), an application-specific integrated circuit (ASIC), a field-programmable gate array (FPGA) or other programmable logic devices, discrete gates or transistor logic devices, discrete hardware components. The methods, steps and logic block diagrams disclosed in the embodiments of the present invention can be implemented or executed. The general-purpose processor can be a microprocessor or the processor can also be any conventional processor, etc. The steps of the method disclosed in conjunction with the embodiments of the present invention can be directly embodied as a hardware decoding processor for execution, or a combination of hardware and software modules in the decoding processor for execution. The software module may be located in a storage medium mature in the art, such as a random access memory, a flash memory, a read-only memory, a programmable read-only memory, or an electrically erasable programmable memory, a register, etc. The storage medium is located in the memory 131, and the processor 130 reads the information in the memory 131 and completes the steps of the method of the above embodiment in combination with its hardware.

[0104] An embodiment of the present invention further provides a computer-readable storage medium, which stores computer-executable instructions. When the computer-executable instructions are called and executed by a processor, the computer-executable instructions prompt the processor to implement the above-mentioned method for recovering the abnormal state of Nand Flash. The specific implementation can be found in the method embodiment, which will not be repeated here.

[0105] The method, device and electronic device for recovering the abnormal state of Nand Flash provided in the embodiments of the present invention include a computer-readable storage medium storing program code. The instructions included in the program code can be used to execute the method described in the previous method embodiment. The specific implementation can be referred to the method embodiment, which will not be repeated here.

[0106] If the functions are implemented in the form of software functional units and sold or used as independent products, they can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present invention, or the part that contributes to the prior art or the part of the technical solution, can be embodied in the form of a software product. The computer software product is stored in a storage medium, including several instructions for a computer device (which can be a personal computer, a server, or a network device, etc.) to perform all or part of the steps of the methods described in each embodiment of the present invention. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (ROM, Read-Only Memory), random access memory (RAM, Random Access Memory), disk or optical disk, etc., which can store program codes.

[0107] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, rather than to limit it. Although the present invention has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or replace some or all of the technical features therein with equivalents. However, these modifications or replacements do not cause the essence of the corresponding technical solutions to deviate from the scope of the technical solutions of the embodiments of the present invention.

Claims

1. A method for recovering Nand Flash abnormal state, characterized in that: The method is applied to Nand Flash, which is connected to a host computer; an initial mapping table is pre-stored in a backup area and a table area of ​​the Nand Flash; when data is written into the Nand Flash, the initial mapping table in the table area is continuously updated as the data is written, and a first mapping table is obtained after each update; The method comprises: After receiving the first command sent by the host computer, if it is detected that the Nand Flash is in an abnormal state, the initial mapping table in the backup area is read, and the read initial mapping table is rewritten into the table area; A formatting command sent by the host computer is received, and the Nand Flash is formatted according to the formatting command, so that the Nand Flash is restored to factory settings.

2. The method according to claim 1, characterized in that The backup area of ​​the Nand Flash includes at least one free page of a boot block; and the table area of ​​the Nand Flash includes free pages of a mapping block.

3. The method according to claim 2, characterized in that The host computer is connected to the Nand Flash through a preset tool; the initial mapping table is pre-stored in the backup area and the table area of ​​the Nand Flash in the following manner: An initial mapping table sent by the host computer through the preset tool is received, and the initial mapping table is written into an idle page of the mapping block and an idle page of at least one of the startup blocks, so that the initial mapping table and the startup code share the startup block.

4. The method according to claim 1, characterized in that: The abnormal state includes an emergency abnormal state and a non-emergency abnormal state; after receiving the first command sent by the host computer, if it is detected that the Nand Flash is in an abnormal state, the steps of reading the initial mapping table in the backup area and rewriting the read initial mapping table into the table area include: After receiving the first command sent by the host computer, if it is detected that the Nand Flash is in a non-emergency abnormal state and a second command is received from the host computer, the initial mapping table in the backup area is read and the read initial mapping table is rewritten into the table area; the non-emergency abnormal state includes a write protection state.

5. The method according to claim 4, characterized in that The method further comprises: After receiving the first command sent by the host computer, if it is detected that the Nand Flash is in an emergency abnormal state, reading the target first mapping table last updated in the table area; If the target first mapping table can be read normally, the read target first mapping table is rewritten into the table area.

6. The method according to claim 5, characterized in that The method further comprises: If the target first mapping table cannot be read normally, the initial mapping table in the backup area is read, and the read initial mapping table is rewritten into the table area.

7. The method according to claim 4, characterized in that After receiving the first command sent by the host computer, if it is detected that the Nand Flash is in a non-emergency abnormal state, and the host computer receives a second command sent, the initial mapping table in the backup area is read, and the read initial mapping table is rewritten into the table area. The step also includes: After receiving the first command sent by the host computer, if it is detected that the Nand Flash is in a non-emergency abnormal state, reading the data in the Nand Flash and transferring the data in the Nand Flash to the host computer for backup; A second command sent by the host computer is received, the initial mapping table in the backup area is read, and the read initial mapping table is rewritten into the table area.

8. A device for recovering Nand Flash abnormal state, characterized in that: The device is arranged in Nand Flash, and the Nand Flash is connected to a host computer; an initial mapping table is pre-stored in a backup area and a table area of ​​the Nand Flash; wherein, when data is written into the Nand Flash, the initial mapping table in the table area is continuously updated as the data is written, and a first mapping table is obtained after each update; The device comprises: A detection module, configured to read the initial mapping table in the backup area and rewrite the read initial mapping table into the table area if it is detected that the Nand Flash is in an abnormal state after receiving the first command sent by the host computer; The formatting module is used to receive a formatting command sent by the host computer, and format the Nand Flash according to the formatting command to restore the Nand Flash to factory settings.

9. An electronic device comprising a memory and a processor, wherein the memory stores a computer program that can be run on the processor, characterized in that: When the processor executes the computer program, the steps of the method for recovering the abnormal state of Nand Flash according to any one of claims 1 to 7 are implemented.

10. A computer readable medium having a non-volatile program code executable by a processor, characterized in that: The program code enables the processor to execute the steps of the method for restoring the abnormal state of Nand Flash according to any one of claims 1 to 7.