CN113126916B - Data restoration method and device after abnormal power failure - Google Patents

Data restoration method and device after abnormal power failure Download PDF

Info

Publication number
CN113126916B
CN113126916B CN202110333293.5A CN202110333293A CN113126916B CN 113126916 B CN113126916 B CN 113126916B CN 202110333293 A CN202110333293 A CN 202110333293A CN 113126916 B CN113126916 B CN 113126916B
Authority
CN
China
Prior art keywords
data
block
page
reading
read
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Active
Application number
CN202110333293.5A
Other languages
Chinese (zh)
Other versions
CN113126916A (en
Inventor
黎兴建
胡胜发
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Guangzhou Ankai Microelectronics Co ltd
Original Assignee
Guangzhou Ankai Microelectronics Co ltd
Filing date
Publication date
Application filed by Guangzhou Ankai Microelectronics Co ltd filed Critical Guangzhou Ankai Microelectronics Co ltd
Priority to CN202110333293.5A priority Critical patent/CN113126916B/en
Publication of CN113126916A publication Critical patent/CN113126916A/en
Application granted granted Critical
Publication of CN113126916B publication Critical patent/CN113126916B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Abstract

The invention discloses a data restoration method after abnormal power failure, which comprises the following steps: scanning all blocks on the partition when the equipment is powered on again to acquire all data blocks in the partition; and reading all the data pages in the data block, and deleting the data pages which are failed to read. By implementing the embodiment of the invention, the problem of data restoration after abnormal power failure of the equipment can be solved on the premise of not backing up the system files, so that the equipment can be started normally after being powered on again, and the storage space of the equipment is saved.

Description

Data restoration method and device after abnormal power failure
Technical Field
The present invention relates to the field of computer technologies, and in particular, to a method and an apparatus for repairing data after abnormal power failure.
Background
For current consumer electronics, SPI NAND FLASH is often used as a storage medium; the file system based on SPI NAND FLASH storage medium basically has garbage collection design, the garbage collection is a thread executed in the background, as long as the background is free or available data blocks are small, the garbage collection thread can execute the operation of moving the data on SPINAND, if abnormal break points occur at this time, the possibility of abnormal power failure always happens in the consumed electrical products, if the files just happen to be written to another block in the process of executing garbage collection by the system, the page can possibly have the problem that ECC errors are caused if the data is not completely written, such as the ECC data of OOB is not written down, so that the file is damaged, the damaged file can be read and abnormal starting cannot be performed normally when the file is powered up again.
In order to solve the problems, the prior art adopts a file backup mode to repair damaged data when abnormal power failure occurs, and the specific method comprises the following steps: when the system is powered on again after the abnormal power failure is carried out on all the files, if the system finds that the file data is damaged in the process of scanning the files, the corresponding backed-up files are copied to the damaged files, and then the files are read again; however, this method needs to occupy twice more storage space, which easily causes the problem of insufficient storage space of the device.
Disclosure of Invention
The embodiment of the invention provides a data restoration method and device for abnormal power failure, which can restore data after abnormal power failure to enable equipment to normally operate on the premise of not carrying out data backup.
An embodiment of the present invention provides a method for repairing data after abnormal power failure, which is suitable for a device provided with SPI NAND FLASH, and is characterized in that the method includes:
Scanning all blocks on the partition when the equipment is powered on again to acquire all data blocks in the partition;
and reading all the data pages in the data block, and deleting the data pages which are failed to read.
Further, the scanning all the blocks on the partition to obtain all the data blocks in the partition specifically includes:
Scanning a block, and reading OOB data in a data page from an initial data page of the scanned block;
Judging whether the scanned block is a data block according to the read OOB data when the reading is successful; if yes, the scanned block is marked as a data block;
when the reading fails, judging whether the current read data page is the last page in the scanned block, if so, erasing the scanned block; if not, reading the OOB data of the next data page of the currently read data page;
And after all the blocks in the partition are scanned, acquiring all the data blocks in the partition.
Further, reading all the data pages in the data block, and deleting the data page with failed reading, which specifically includes:
reading a data page in a data block from a last data page in the data block;
when the current data page is successfully read, judging whether all the data pages in the current data block are read completely; if yes, reading the next data block, and if not, reading the last data page of the current read data page;
When the current data page fails to be read, deleting the current read data page, and then reading the last data page of the current read data page;
And finishing the data restoration of the equipment when the data pages of all the data blocks are read.
Further, the method further comprises the following steps: if the scanned block is not the data block according to the read OOB data, continuing to judge whether the scanned block is a bad block, if so, marking the scanned block as a bad block, and if not, judging the scanned block as a null block and marking the scanned block as a null block.
On the basis of the method item embodiments, the invention correspondingly provides device item embodiments;
The embodiment of the invention provides a data repairing device after abnormal power failure, which comprises a data block identification module and a data page deletion module;
The data block identification module is used for scanning all blocks on the partition to acquire all data blocks in the partition when the equipment is powered on again;
and the data page deleting module is used for reading all the data pages in the data block and deleting the data pages which are failed to read.
Further, the data block identification module scans all the blocks on the partition to obtain all the data blocks in the partition, and specifically includes:
Scanning a block, and reading OOB data in a data page from an initial data page of the scanned block;
Judging whether the scanned block is a data block according to the read OOB data when the reading is successful; if yes, the scanned block is marked as a data block;
when the reading fails, judging whether the current read data page is the last page in the scanned block, if so, erasing the scanned block; if not, reading the OOB data of the next data page of the currently read data page;
And after all the blocks in the partition are scanned, acquiring all the data blocks in the partition.
Further, the data page deleting module reads all the data pages in the data block, and deletes the data page with failed reading, which specifically includes:
reading a data page in a data block from a last data page in the data block;
when the current data page is successfully read, judging whether all the data pages in the current data block are read completely; if yes, reading the next data block, and if not, reading the last data page of the current read data page;
When the current data page fails to be read, deleting the current read data page, and then reading the last data page of the current read data page;
And finishing the data restoration of the equipment when the data pages of all the data blocks are read.
The invention has the following beneficial effects:
The embodiment of the invention provides a data restoration method and a device after abnormal power failure, wherein the method scans all blocks on a partition when equipment is powered on again, acquires all data blocks in the partition, reads all data pages in all the data blocks, and deletes the data pages which are failed to read in the reading process, thereby completing data restoration. In the process of reading the data page, if the reading fails, the reason that the data is abnormally powered down is indicated, so that the file is not completely written when the moving data is written to the page in the process of recovering garbage by the system, ECC errors occur and the data page cannot be read, and the data page is deleted at the moment, so that the system file is restored to a state before the data is not moved before the power down, the restoration of the data is completed, and the equipment can be started normally. Compared with the prior art, the invention does not need to carry out file backup, reduces the waste of storage space and can also realize data restoration after power failure.
Drawings
Fig. 1 is a flow chart of a method for repairing data after abnormal power failure according to an embodiment of the present invention.
Fig. 2 is a schematic structural diagram of a data repairing device after abnormal power failure according to an embodiment of the present invention.
Detailed Description
The following description of the embodiments of the present invention will be made clearly and completely with reference to the accompanying drawings, in which it is apparent that the embodiments described are only some embodiments of the present invention, but not all embodiments. All other embodiments, which can be made by those skilled in the art based on the embodiments of the invention without making any inventive effort, are intended to be within the scope of the invention.
As shown in fig. 1, an embodiment of the present invention provides a method for repairing data after abnormal power failure, which is suitable for a device provided with SPI NAND FLASH, and includes:
Step S101: and when the equipment is powered on again, scanning all the blocks on the partition to acquire all the data blocks in the partition.
Step S102: and reading all the data pages in the data block, and deleting the data pages which are failed to read.
For step S101, in a preferred embodiment, the scanning all the blocks on the partition to obtain all the data blocks in the partition specifically includes: scanning a block, and reading OOB data in a data page from an initial data page of the scanned block; judging whether the scanned block is a data block according to the read OOB data when the reading is successful; if yes, the scanned block is marked as a data block; when the reading fails, judging whether the current read data page is the last page in the scanned block, if so, erasing the scanned block; if not, reading the OOB data of the next data page of the currently read data page; and after all the blocks in the partition are scanned, acquiring all the data blocks in the partition.
Firstly, the 'blocks' on the partition in SPI NAND FLASH are mainly divided into three types, one type is a 'bad block' which can not store data, the other type is a 'empty block' which does not store data, and the other type is a 'data block' which stores data; SPI NAND FLASH, when available data blocks are relatively small, executing garbage collection actions, when garbage collection is performed, firstly reading data of one page, then writing the data on a new page of another block, and if all pages of an old data block are read, wiping the old data block to complete garbage collection actions once; because of the SPI NAND FLASH nature, it is necessary to erase the page of each block before writing the data correctly. If the system is performing garbage collection operation during abnormal power down, there are two cases where the page SPINAND has ECC error, the first is just power down when the data block is being erased, then all pages on the block or individual pages will have ECC error, the second is just power down when garbage is collected to move data to a new data page, so the page being written will have ECC error. When the equipment is powered on again, starting abnormality can occur due to the fact that data pages with ECC errors exist when the system performs file configuration; in one embodiment of the present invention, when the device is powered on again, initializing the file system, scanning all blocks on the SPI NAND FLASH partitions, and when each block is scanned, firstly reading an initial data page of the scanned block, namely OOB data of page 0, if the reading is successful, judging whether the scanned block is a data block according to the OOB data, if so, marking, and marking as the data block; if not, further determining whether the space-time block or the bad block according to the OOB data; and corresponding marking is carried out. If the reading fails, judging whether the page read currently is the last page, if so, indicating that all data pages of the block are misplaced, and directly erasing the whole block; if the data of the next page is not read, if the data of the next page is read successfully, the judging operation of whether the data is the data block is repeated, if the data is read successfully, whether the data is the last page is judged again, after all the data pages of one block are read completely in the above mode, scanning of one block is completed, then the next data block is scanned immediately until all the blocks in the partition are scanned completely. After the scanning is finished, all the data blocks in the partition can be acquired.
For step S102, in a preferred embodiment, reading all the data pages in the data block, and deleting the data page that fails to be read specifically includes:
Reading a data page in a data block from a last data page in the data block; when the current data page is successfully read, judging whether all the data pages in the current data block are read completely; if yes, reading the next data block, and if not, reading the last data page of the current read data page; when the current data page fails to be read, deleting the current read data page, and then reading the last data page of the current read data page;
specifically, after all the data blocks are acquired in the step 1, reading all pages of the data blocks is started; the reading for a block of data is as follows:
Reading from the last data page of a data block; when reading, if the current data page is read and weighed, judging whether all the data pages of the data block are read completely, if so, reading the next data block, and if not, reading the last page of the current read page; if the reading fails, the data page is abnormal because of ECC error, and the last page is read after the currently read data page is deleted; repeating the above operation until the data pages of all the data blocks are read, finishing the data repairing process after the equipment is abnormally powered down, and then starting the equipment normally.
On the basis of the method item embodiments, the invention correspondingly provides device item embodiments;
As shown in fig. 2, another embodiment of the present invention provides a device for repairing data after abnormal power failure, including a data block identification module and a data page deletion module;
The data block identification module is used for scanning all blocks on the partition to acquire all data blocks in the partition when the equipment is powered on again;
and the data page deleting module is used for reading all the data pages in the data block and deleting the data pages which are failed to read.
In a preferred embodiment, the data block identification module scans all the blocks on the partition to obtain all the data blocks in the partition, and specifically includes:
Scanning a block, and reading OOB data in a data page from an initial data page of the scanned block;
Judging whether the scanned block is a data block according to the read OOB data when the reading is successful; if yes, the scanned block is marked as a data block;
when the reading fails, judging whether the current read data page is the last page in the scanned block, if so, erasing the scanned block; if not, reading the OOB data of the next data page of the currently read data page;
And after all the blocks in the partition are scanned, acquiring all the data blocks in the partition.
In a preferred embodiment, the data page deleting module reads all the data pages in the data block, and deletes the data page that fails to be read, which specifically includes:
reading a data page in a data block from a last data page in the data block;
when the current data page is successfully read, judging whether all the data pages in the current data block are read completely; if yes, reading the next data block, and if not, reading the last data page of the current read data page;
When the current data page fails to be read, deleting the current read data page, and then reading the last data page of the current read data page;
And finishing the data restoration of the equipment when the data pages of all the data blocks are read.
It should be noted that the above-described apparatus embodiments are merely illustrative, and the units described as separate units may or may not be physically separate, and units shown as units may or may not be physical units, may be located in one place, or may be distributed over a plurality of network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the solution of this embodiment. In addition, in the drawings of the embodiment of the device provided by the invention, the connection relation between the modules represents that the modules have communication connection, and can be specifically implemented as one or more communication buses or signal lines. Those of ordinary skill in the art will understand and implement the present invention without undue burden.
By implementing the embodiment of the invention, the problem of data restoration after abnormal power failure of the equipment can be solved on the premise of not backing up the system files, so that the equipment can be started normally after being powered on again.
While the foregoing is directed to the preferred embodiments of the present invention, it will be appreciated by those skilled in the art that changes and modifications may be made without departing from the principles of the invention, such changes and modifications are also intended to be within the scope of the invention.

Claims (5)

1. The data restoration method after abnormal power failure is suitable for the equipment provided with SPI NAND FLASH, and is characterized by comprising the following steps:
Scanning all blocks on the partition when the equipment is powered on again to acquire all data blocks in the partition;
Reading all the data pages in the data block, and deleting the data pages which are failed to read; the reading of the data pages in all the data blocks and the deletion of the data pages with failed reading specifically include: reading a data page in a data block from a last data page in the data block; when the current data page is successfully read, judging whether all the data pages in the current data block are read completely; if yes, reading the next data block, and if not, reading the last data page of the current read data page; when the current data page fails to be read, deleting the current read data page, and then reading the last data page of the current read data page; and finishing the data restoration of the equipment when the data pages of all the data blocks are read.
2. The method for repairing data after abnormal power failure according to claim 1, wherein the scanning all blocks on the partition to obtain all data blocks in the partition specifically comprises:
Scanning a block, and reading OOB data in a data page from an initial data page of the scanned block;
Judging whether the scanned block is a data block according to the read OOB data when the reading is successful; if yes, the scanned block is marked as a data block;
when the reading fails, judging whether the current read data page is the last page in the scanned block, if so, erasing the scanned block; if not, reading the OOB data of the next data page of the currently read data page;
And after all the blocks in the partition are scanned, acquiring all the data blocks in the partition.
3. The method for repairing data after abnormal power failure according to claim 2, further comprising: if the scanned block is not the data block according to the read OOB data, continuing to judge whether the scanned block is a bad block, if so, marking the scanned block as a bad block, and if not, judging the scanned block as a null block and marking the scanned block as a null block.
4. The data repairing device after abnormal power failure is characterized by comprising a data block identification module and a data page deletion module;
The data block identification module is used for scanning all blocks on the partition to acquire all data blocks in the partition when the equipment is powered on again;
the data page deleting module is used for reading all the data pages in the data block and deleting the data pages which are failed to read; the data page deleting module reads all the data pages in the data block and deletes the data page with failed reading, and specifically includes: reading a data page in a data block from a last data page in the data block; when the current data page is successfully read, judging whether all the data pages in the current data block are read completely; if yes, reading the next data block, and if not, reading the last data page of the current read data page; when the current data page fails to be read, deleting the current read data page, and then reading the last data page of the current read data page; and finishing the data restoration of the equipment when the data pages of all the data blocks are read.
5. The device for repairing abnormal power-down data according to claim 4, wherein the data block identification module scans all blocks on the partition to obtain all data blocks in the partition, and specifically comprises:
Scanning a block, and reading OOB data in a data page from an initial data page of the scanned block;
Judging whether the scanned block is a data block according to the read OOB data when the reading is successful; if yes, the scanned block is marked as a data block;
when the reading fails, judging whether the current read data page is the last page in the scanned block, if so, erasing the scanned block; if not, reading the OOB data of the next data page of the currently read data page;
And after all the blocks in the partition are scanned, acquiring all the data blocks in the partition.
CN202110333293.5A 2021-03-29 Data restoration method and device after abnormal power failure Active CN113126916B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202110333293.5A CN113126916B (en) 2021-03-29 Data restoration method and device after abnormal power failure

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202110333293.5A CN113126916B (en) 2021-03-29 Data restoration method and device after abnormal power failure

Publications (2)

Publication Number Publication Date
CN113126916A CN113126916A (en) 2021-07-16
CN113126916B true CN113126916B (en) 2024-06-25

Family

ID=

Citations (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN102609334A (en) * 2012-01-09 2012-07-25 晨星软件研发(深圳)有限公司 Method for restoring abnormal-erasure storage blocks of NAND flash and corresponding device

Patent Citations (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN102609334A (en) * 2012-01-09 2012-07-25 晨星软件研发(深圳)有限公司 Method for restoring abnormal-erasure storage blocks of NAND flash and corresponding device

Similar Documents

Publication Publication Date Title
CN103136116B (en) Storage system and control device, management method and power interruption recovering method
CN101477482B (en) Method for recovering flash memory data at power-off of built-in Linux system
CN101923448B (en) Method for reading and writing conversion layer of NAND flash memory
CN108646982B (en) Automatic data restoration method and device based on UBIFS
CN103700387B (en) Bad track of hard disk monitor and repairing device and method
CN109032632A (en) A kind of FOTA upgrade method, wireless communication terminal and storage medium
CN101216789A (en) Data update method, device and system
CN101593157A (en) The bad block management method of nandflash and device
CN102117234A (en) Method for recovering original software by mobile terminal in software upgrading failure
CN101482837B (en) Error correction method and apparatus for flash memory file system
CN103077100B (en) Fro backing-up non-volatile data and restoration methods
CN110188068B (en) Volume-level backup method and device for guaranteeing consistency of file system data
CN101281452A (en) Method for automatically rebuilding hard disk
CN101231617A (en) Method for processing data of flash memory equipment
CN111143132A (en) BIOS recovery method, device, equipment and readable storage medium
CN1924821A (en) Firmware renewing system and method
CN114968066A (en) Method and apparatus for fault block management in flash memory
CN103064752A (en) Method and device of repairing document
CN103019969A (en) Flash memory storage device and determination method of bad storage area thereof
CN104714757A (en) Refresh Apparatus and Electronic Device
CN113126916B (en) Data restoration method and device after abnormal power failure
CN102237143A (en) Reconstruction method, system and reconstruction device for block information provided in flash memory
CN116974961A (en) Firmware changing method, system and device
CN112579179A (en) Partition mounting method of embedded system
CN113126916A (en) Data restoration method and device after abnormal power failure

Legal Events

Date Code Title Description
PB01 Publication
SE01 Entry into force of request for substantive examination
CB02 Change of applicant information

Country or region after: China

Address after: 510555 No. 107 Bowen Road, Huangpu District, Guangzhou, Guangdong

Applicant after: Guangzhou Ankai Microelectronics Co.,Ltd.

Address before: Unit 301, 302, 303, 3 / F, C1 area, 182 science Avenue, Science City, Guangzhou hi tech Industrial Development Zone, Guangzhou, Guangdong 510000

Applicant before: Guangzhou Ankai Microelectronics Co.,Ltd.

Country or region before: China

GR01 Patent grant