CN113785275B - Flash data power-down protection method and device - Google Patents

Flash data power-down protection method and device Download PDF

Info

Publication number
CN113785275B
CN113785275B CN202080026922.3A CN202080026922A CN113785275B CN 113785275 B CN113785275 B CN 113785275B CN 202080026922 A CN202080026922 A CN 202080026922A CN 113785275 B CN113785275 B CN 113785275B
Authority
CN
China
Prior art keywords
data
page
area
backup area
storage area
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
CN202080026922.3A
Other languages
Chinese (zh)
Other versions
CN113785275A (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.)
Shenzhen Jetlink Technology Co ltd
Original Assignee
Shenzhen Jetlink Technology Co ltd
Priority date (The priority date 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 date listed.)
Filing date
Publication date
Application filed by Shenzhen Jetlink Technology Co ltd filed Critical Shenzhen Jetlink Technology Co ltd
Publication of CN113785275A publication Critical patent/CN113785275A/en
Application granted granted Critical
Publication of CN113785275B publication Critical patent/CN113785275B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F11/00Error detection; Error correction; Monitoring
    • G06F11/07Responding to the occurrence of a fault, e.g. fault tolerance
    • G06F11/14Error detection or correction of the data by redundancy in operation
    • G06F11/1402Saving, restoring, recovering or retrying
    • G06F11/1446Point-in-time backing up or restoration of persistent data
    • G06F11/1448Management of the data involved in backup or backup restore
    • G06F11/1451Management of the data involved in backup or backup restore by selection of backup contents
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F12/00Accessing, addressing or allocating within memory systems or architectures
    • G06F12/02Addressing or allocation; Relocation
    • G06F12/08Addressing or allocation; Relocation in hierarchically structured memory systems, e.g. virtual memory systems
    • G06F12/0802Addressing of a memory level in which the access to the desired data or data block requires associative addressing means, e.g. caches
    • G06F12/0877Cache access modes
    • G06F12/0882Page mode
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F3/00Input arrangements for transferring data to be processed into a form capable of being handled by the computer; Output arrangements for transferring data from processing unit to output unit, e.g. interface arrangements
    • G06F3/06Digital input from, or digital output to, record carriers, e.g. RAID, emulated record carriers or networked record carriers
    • G06F3/0601Interfaces specially adapted for storage systems
    • G06F3/0602Interfaces specially adapted for storage systems specifically adapted to achieve a particular effect
    • G06F3/0614Improving the reliability of storage systems
    • G06F3/0616Improving the reliability of storage systems in relation to life time, e.g. increasing Mean Time Between Failures [MTBF]
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F3/00Input arrangements for transferring data to be processed into a form capable of being handled by the computer; Output arrangements for transferring data from processing unit to output unit, e.g. interface arrangements
    • G06F3/06Digital input from, or digital output to, record carriers, e.g. RAID, emulated record carriers or networked record carriers
    • G06F3/0601Interfaces specially adapted for storage systems
    • G06F3/0628Interfaces specially adapted for storage systems making use of a particular technique
    • G06F3/0646Horizontal data movement in storage systems, i.e. moving data in between storage devices or systems
    • G06F3/0652Erasing, e.g. deleting, data cleaning, moving of data to a wastebasket
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F3/00Input arrangements for transferring data to be processed into a form capable of being handled by the computer; Output arrangements for transferring data from processing unit to output unit, e.g. interface arrangements
    • G06F3/06Digital input from, or digital output to, record carriers, e.g. RAID, emulated record carriers or networked record carriers
    • G06F3/0601Interfaces specially adapted for storage systems
    • G06F3/0668Interfaces specially adapted for storage systems adopting a particular infrastructure
    • G06F3/0671In-line storage system
    • G06F3/0673Single storage device
    • G06F3/0679Non-volatile semiconductor memory device, e.g. flash memory, one time programmable memory [OTP]
    • YGENERAL TAGGING OF NEW TECHNOLOGICAL DEVELOPMENTS; GENERAL TAGGING OF CROSS-SECTIONAL TECHNOLOGIES SPANNING OVER SEVERAL SECTIONS OF THE IPC; TECHNICAL SUBJECTS COVERED BY FORMER USPC CROSS-REFERENCE ART COLLECTIONS [XRACs] AND DIGESTS
    • Y02TECHNOLOGIES OR APPLICATIONS FOR MITIGATION OR ADAPTATION AGAINST CLIMATE CHANGE
    • Y02DCLIMATE CHANGE MITIGATION TECHNOLOGIES IN INFORMATION AND COMMUNICATION TECHNOLOGIES [ICT], I.E. INFORMATION AND COMMUNICATION TECHNOLOGIES AIMING AT THE REDUCTION OF THEIR OWN ENERGY USE
    • Y02D10/00Energy efficient computing, e.g. low power processors, power management or thermal management

Abstract

A Flash data power-down protection method and device, the method includes: when the electronic equipment is powered on, traversing the power-down protection area, and searching a data page meeting a preset condition, wherein the data page meeting the preset condition is a starting page of the backup area; if the data page meeting the preset conditions exists, carrying out data recovery according to the backup area indicated by the data page meeting the preset conditions, removing the data backed up in the current backup area, and taking the logical next page of the termination page of the current backup area as the initial page of the backup area of the next writing operation; if the data page meeting the preset condition does not exist, generating a random number, and selecting one page from the power-down protection area according to the generated random number as a starting page of a backup area of the next writing operation. On the premise of ensuring the data integrity, the erasing times of all data pages in the power-down protection area tend to be the same, the service efficiency of the power-down protection area is improved, and the service life of products is prolonged.

Description

Flash data power-down protection method and device
Technical Field
The invention relates to the technical field of storage, in particular to a Flash data power-down protection method and device.
Background
Flash Memory (Flash) is used as a Non-Volatile Memory (NVM), and is widely used with the advantages of large capacity, low price and the like, for example, most of bottom chips of an operating system (Card Operate System, COS) of a smart card adopt Flash as a storage medium. Most Flash only supports page erasing writing, namely, all data must be erased before writing, then new data can be written, and if new data needs to be written again, the whole page needs to be erased again. If accidental power failure occurs during erasing or writing, the data may be in an incomplete state of partial erasing or partial writing, and the integrity of the data cannot be ensured.
In order to ensure the integrity of the data, a space is allocated in the Flash memory as a power-down protection area for recording the backup data of the related write operation so as to restore the related backup data after power-down. The existing power-down protection area usually adopts a page backup operation mechanism, related backup data is written into a fixed Flash page in advance when the NVM operation is carried out, then the Flash page where target data is located is erased, and after the erasing of the related data page of the backup area is completed. While limited by the process, the erase life of the Flash page is limited. The power-down protection region is the common region for all NVM operations, with the maximum number of erasures and the maximum erase pressure, which will substantially limit the lifetime of the entire Flash memory to that of the power-down protection region.
In conclusion, the actual service life of the product is greatly reduced by the existing Flash data power-down protection method.
Disclosure of Invention
The invention mainly provides a Flash data power-down protection method and equipment, which are used for solving the problem that the actual service life of a product is reduced due to the existing Flash data power-down protection method.
According to a first aspect, in one embodiment, a method for protecting Flash data from power failure is provided, the method is used for an electronic device, the electronic device includes a Flash memory, a code area, a data area and a power failure protection area are divided into the Flash memory, the code area is used for storing code data, the data area is used for storing file system data and user data, and the power failure protection area is used for backing up data; the method comprises the following steps:
when the electronic equipment is powered on, traversing the power-down protection area, and searching a data page meeting preset conditions, wherein the data page meeting the preset conditions is a starting page of a backup area;
if the data page meeting the preset conditions exists, carrying out data recovery according to the backup area indicated by the data page meeting the preset conditions, removing the backup data in the current backup area, and taking the logical next page of the termination page of the current backup area as the initial page of the backup area of the next writing operation;
if the data page meeting the preset condition does not exist, generating a random number, and selecting one page from the power-down protection area according to the generated random number as a starting page of a backup area of the next writing operation.
Optionally, the method further comprises:
receiving a target address, content and length of data to be written;
determining the data to be backed up according to the target address and the length of the data to be written;
writing the data to be backed up into a current backup area;
writing the content of the data to be written into the target address;
and clearing the data backed up in the current backup area, and taking the logical next page of the end page of the current backup area as the initial page of the backup area of the next writing operation.
Optionally, if the writing operation is atomic writing, the backup area includes a first storage area and a second storage area, where the first storage area is used to store a first preset mark and a target address pointed by the atomic writing operation and an affected data range, and the second storage area is used to backup page data affected by the atomic writing operation, and the first preset mark is used to indicate that the writing operation is atomic writing; the writing the data to be backed up into the current backup area comprises the following steps:
writing the data to be backed up into a second storage area of the backup area;
and writing the first preset mark, the target address and the length into a first storage area of the backup area.
Optionally, the data page meeting the preset condition is a data page with the first preset mark, and the performing data recovery according to the backup area indicated by the data page meeting the preset condition includes:
acquiring the target address and the length from a first storage area of the backup area;
determining a target page according to the target address and the length;
and restoring the backup data stored in the second storage area of the backup area into the target page by page.
Optionally, the clearing the data backed up in the current backup area includes: and erasing the content in the first storage area of the current backup area.
Optionally, if the writing operation is transaction writing, the backup area includes a third storage area, a fourth storage area and a fifth storage area, where the third storage area is used to store a second preset flag, the fourth storage area is used to record all target page addresses that need to be backed up in the transaction writing operation, the fifth storage area is used to backup page data affected by the transaction writing operation, the second preset flag is used to indicate that the writing operation is transaction writing, and the fourth storage area includes multiple parameter pages; the writing the data to be backed up into the current backup area comprises the following steps:
writing the data to be backed up into a fifth storage area of the backup area;
determining a target parameter page from a plurality of parameter pages according to the number counter;
writing all target addresses in the current and previous transaction writing processes into the target parameter page, and updating the number counter;
and writing the second preset mark into a third storage area of the backup area.
Optionally, the data page meeting the preset condition is a data page with the second preset mark, and the performing data recovery according to the backup area indicated by the data page meeting the preset condition includes:
determining the latest parameter page from a plurality of parameter pages included in a fourth storage area of the backup area;
the target addresses of the corresponding target pages are taken out one by one from the latest parameter pages;
and restoring the backup data stored in the fifth storage area of the backup area page by page into a target page corresponding to the target address.
Optionally, the clearing the data backed up in the current backup area includes: and erasing the content in the third storage area of the current backup area.
According to a second aspect, there is provided in one embodiment an electronic device comprising:
a memory for storing a program;
and the processor is used for executing the program stored in the memory to realize the Flash data power-down protection method according to any one of the first aspect.
According to a third aspect, an embodiment provides a computer readable storage medium, including a program executable by a processor to implement the Flash data power-down protection method of any one of the first aspects above.
According to the Flash data power-down protection method and the device, the method comprises the following steps: when the electronic equipment is powered on, traversing the power-down protection area, and searching a data page meeting a preset condition, wherein the data page meeting the preset condition is a starting page of the backup area; if the data page meeting the preset conditions exists, carrying out data recovery according to the backup area indicated by the data page meeting the preset conditions, removing the data backed up in the current backup area, and taking the logical next page of the termination page of the current backup area as the initial page of the backup area of the next writing operation; if the data page meeting the preset condition does not exist, generating a random number, and selecting one page from the power-down protection area according to the generated random number as a starting page of a backup area of the next writing operation. On the premise of ensuring the data integrity, the erasing times of all data pages in the power-down protection area tend to be the same, the service efficiency of the power-down protection area is improved, and the service life of products is prolonged.
Drawings
Fig. 1 is a schematic flow chart of an embodiment one of a Flash data power-down protection method provided by the embodiment of the invention;
fig. 2 is a schematic structural diagram of a power-down protection area according to an embodiment of the present invention;
fig. 3 is a schematic flow chart of a second embodiment of a Flash data power-down protection method according to the embodiment of the present invention;
fig. 4 is a schematic structural diagram of another power-down protection area according to an embodiment of the present invention;
fig. 5 is a schematic flow chart of a third embodiment of a Flash data power-down protection method according to the embodiment of the present invention;
fig. 6 is a schematic structural diagram of another power-down protection area according to an embodiment of the present invention;
fig. 7 is a flowchart of a fourth embodiment of a Flash data power-down protection method according to an embodiment of the present invention.
Detailed Description
The invention will be described in further detail below with reference to the drawings by means of specific embodiments. Wherein like elements in different embodiments are numbered alike in association. In the following embodiments, numerous specific details are set forth in order to provide a better understanding of the present application. However, one skilled in the art will readily recognize that some of the features may be omitted, or replaced by other elements, materials, or methods in different situations. In some instances, some operations associated with the present application have not been shown or described in the specification to avoid obscuring the core portions of the present application, and may not be necessary for a person skilled in the art to describe in detail the relevant operations based on the description herein and the general knowledge of one skilled in the art.
Furthermore, the described features, operations, or characteristics of the description may be combined in any suitable manner in various embodiments. Also, various steps or acts in the method descriptions may be interchanged or modified in a manner apparent to those of ordinary skill in the art. Thus, the various orders in the description and drawings are for clarity of description of only certain embodiments, and are not meant to be required orders unless otherwise indicated.
The numbering of the components itself, e.g. "first", "second", etc., is used herein merely to distinguish between the described objects and does not have any sequential or technical meaning. The terms "coupled" and "connected," as used herein, are intended to encompass both direct and indirect coupling (coupling), unless otherwise indicated.
Because the existing power-down protection area usually adopts a page backup operation mechanism, related backup data is written into a fixed Flash page in advance when the NVM operation is carried out, then the Flash page where target data is located is erased, and after the erasing of the related data page of the backup area is completed. While limited by the process, the erase life of the Flash page is limited. The power-down protection region is the common region for all NVM operations, with the maximum number of erasures and the maximum erase pressure, which will substantially limit the lifetime of the entire Flash memory to that of the power-down protection region. In order to solve the problem that the actual service life of a product is reduced due to the existing Flash data power-down protection method, the embodiment of the invention provides a Flash data power-down protection method and equipment, and the method and the equipment are respectively described in detail below.
First, some terms involved in the present invention will be briefly described:
COS: card Operate System, which refers to a smart card operating system developed directly on a secure chip, generally refers to a general-purpose or industrial operating system developed on the embedded secure chip industry based on the capabilities and interfaces of the underlying chip, such as the telecommunications industry, the financial industry, etc., or a general-purpose version can be well expanded.
RAM: random Access Memory the RAM, also called the main memory, is the internal memory that exchanges data directly with the CPU. It can be read and written at any time (except when refreshed) and is fast, often as a temporary data storage medium for an operating system or other program in operation. RAM can write (store) or read (retrieve) information from any designated address at any time during operation. The biggest difference from Read-Only Memory (ROM) is the volatility of data, i.e. the stored data will be lost upon power-down. RAM is used in computer and digital systems to temporarily store programs, data, and intermediate results. Here mainly referred to as running memory provided in the security chip.
NVM: non-volatile memory has the characteristics of Non-volatile, byte-by-byte access, high storage density, low energy consumption and the like, and has read-write performance similar to that of a dynamic random access memory (Dynamic Random Access Memory, DRAM), but has asymmetric read-write speed and limited service life. Here mainly the storage provided by the security chip that can be made data persistent.
Flash: a nonvolatile memory, in which data can be held for many years even in a passive state, is mainly classified into NAND/NOR. Generally, the data to be written needs to be erased firstly, and most of the data are page erasing and page writing mechanisms, so that page erasing writing or byte writing is partially supported. However, the erasing times of each page have the minimum times of protection, and whether the data can be normally erased and written or not cannot be ensured if the times of protection are exceeded, and the characteristic directly limits the service life of the Flash pages. The upper layer application must consider both the page erase mechanism and life limitation characteristics in designing the storage scheme.
Java: the Java language is an object-oriented programming language, not only absorbs various advantages of the C++ language, but also abandons concepts such as multiple inheritance, pointers and the like which are difficult to understand in the C++, so that the Java language has two characteristics of powerful functions, simplicity and easiness in use. The Java language, as a representation of the static object-oriented programming language, excellently implements object-oriented theory, allowing programmers to program in a sophisticated way of thinking. Java has the characteristics of simplicity, object-oriented, distributed, robustness, security, platform independence and portability, multithreading, dynamics and the like. Java may write desktop applications, web site applications, distributed and embedded system applications, and the like.
JavaCard technology: a secure environment is provided for applications running on smart cards (secure chips) and other devices with very limited memory and processing capabilities. Multiple applications may be deployed on a card, and new applications may be added to the card even after it is sold to an end user. Applications written using the Java programming language can run securely on different vendor cards. Is the leading open interoperable platform for smart cards and security tokens. The various JavaCard specifications provide a basis for cross-platform and cross-vendor applet interoperability.
Native: generally refers to a technical design and implementation that is independent of Java, javaCard, javaApplet implemented in the C language.
Fig. 1 is a schematic flow chart of an embodiment one of a Flash data power-down protection method provided by the embodiment of the present invention, as shown in fig. 1, the method of the embodiment may include:
s101, when the electronic equipment is powered on, traversing the power-down protection area, and searching for a data page meeting preset conditions.
The execution main body of the embodiment of the invention is an electronic device, and specifically, the electronic device can comprise a Flash memory, wherein a code area, a data area and a power-down protection area can be divided into the Flash memory, the code area is used for storing code data, the data area is used for storing file system data and user data, and the power-down protection area is used for backing up data.
The data page meeting the preset conditions is the initial page of the backup area, and can be compatible with the functions of atomic writing and transactional writing. The atomic write refers to that the operation result of performing a single data writing operation is in a state of successfully completing writing or in an unwritten state, and other intermediate states are not allowed to occur; the transaction write refers to a case where the write data operation is in a state of being written entirely or in a state of being not rewritten entirely after the start of the transaction protection and before the end of the transaction protection, and the partial data is not allowed to be rewritten.
S102, if the data page meeting the preset condition exists, carrying out data recovery according to the backup area indicated by the data page meeting the preset condition, clearing the backup data in the current backup area, and taking the logical next page of the termination page of the current backup area as the initial page of the backup area of the next writing operation.
If the data page meeting the preset condition exists, the fact that the last unfinished data operation content is stored in the backup area is characterized, so that data recovery needs to be conducted on the backup area indicated by the data page meeting the preset condition, and data recovery is conducted on current backup data from the initial page of the backup area to the end page of the backup area, namely, data recovery of the backup area is completed once. After the data is restored, the data backed up in the current backup area is cleared so as to be reused for the current backup area later.
And taking the logic next page of the end page of the current backup area as the initial page of the backup area of the next writing operation, wherein the logic next page refers to the end-to-end connection position of the current backup area and the backup area of the next writing operation. For example, fig. 2 is a schematic structural diagram of a power-down protection area according to an embodiment of the present invention, as shown in fig. 2, if a current backup area is the backup area 1 in fig. 2, a logical next page of a termination page of the backup area 1 is used as a start page of the backup area 2 for a next writing operation; if the current backup area is the backup area 2 in fig. 2, the logical next page of the end page of the backup area 2 is used as the initial page of the backup area 3 of the next writing operation; if the current backup area is the backup area 3 in fig. 2, the logical next page of the end page of the backup area 3 is used as the initial page of the backup area 4 of the next writing operation; if the current backup area is backup area 4 in fig. 2, the logical next page of the end page of backup area 4 is the start page of backup area 1 for the next write operation. Assuming that the erase life of the power-down protection area in the prior art is ten thousands times, and for the power-down protection area shown in fig. 2, after dividing the power-down protection area into four backup areas, the erase life of each backup area is ten thousands times, then the erase life of the power-down protection area is forty thousands times.
And S103, if the data page meeting the preset condition does not exist, generating a random number, and selecting one page from the power-down protection area as a starting page of a backup area of the next writing operation according to the generated random number.
If the data page meeting the preset condition does not exist, the fact that the backup area does not store legal backup data is characterized, and therefore the backup area of the next writing operation needs to be determined in the power-down protection area. Specifically, a random number can be generated by starting a random number generator or calling a related random number generation algorithm interface, and a page is selected from the power-down protection area according to the generated random number to serve as a starting page of a backup area of the next writing operation, so that the backup area of the next writing operation is selected from the power-down protection area with the same probability.
According to the Flash data power-down protection method provided by the embodiment of the invention, when the electronic equipment is powered on, the power-down protection area is traversed, the data page meeting the preset condition is searched, and the data page meeting the preset condition is the initial page of the backup area; if the data page meeting the preset conditions exists, carrying out data recovery according to the backup area indicated by the data page meeting the preset conditions, removing the data backed up in the current backup area, and taking the logical next page of the termination page of the current backup area as the initial page of the backup area of the next writing operation; if the data page meeting the preset condition does not exist, generating a random number, and selecting one page from the power-down protection area according to the generated random number as a starting page of a backup area of the next writing operation. On the premise of ensuring the data integrity, the erasing times of all data pages in the power-down protection area tend to be the same, the service efficiency of the power-down protection area is improved, and the service life of products is prolonged.
Through the first embodiment, the electronic device completes the power-down protection starting operation, and on the basis of the first embodiment, fig. 3 is a schematic flow diagram of a second embodiment of a Flash data power-down protection method according to the embodiment of the present invention, as shown in fig. 3, after executing S102 or S103, the method of the embodiment may include:
s201, receiving a target address, content and length of data to be written.
In specific implementation, the target address, content and length of the data to be written can be input through the application layer.
S202, determining the data to be backed up according to the target address and the length of the data to be written.
Specifically, the address and range of the initial page of the backup area are calculated according to the target address and length of the data to be written.
And S203, writing the data to be backed up into the current backup area.
In particular, when the method is implemented, the data to be backed up can be written into the current backup area page by page, or can be written into the current backup area in a page erasing and page writing mode.
S204, writing the content of the data to be written into the target address.
In particular, the contents of the data to be written may be written to the target address page by page.
S205, clearing the data backed up in the current backup area, and taking the logical next page of the end page of the current backup area as the initial page of the backup area of the next writing operation.
According to the Flash data power-down protection method provided by the embodiment of the invention, the target address, the content and the length of the data to be written are received; determining the data to be backed up according to the target address and the length of the data to be written; writing the data to be backed up into the current backup area; writing the content of the data to be written into the target address; the backup data in the current backup area is cleared, and the logical next page of the termination page of the current backup area is used as the initial page of the backup area for the next writing operation, so that the writing operation times of all data pages in the power-down protection area tend to be the same, the service efficiency of the power-down protection area is improved, and the service life of products is prolonged.
Fig. 4 is a schematic structural diagram of another power-down protection area according to an embodiment of the present invention, where, as shown in fig. 4, if the write operation is atomic write, the backup area includes a first storage area and a second storage area, where the first storage area is used for storing a first preset flag, a target address pointed by the atomic write operation, and an affected data range, the second storage area is used for backing up page data affected by the atomic write operation, and the first preset flag is used for indicating that the write operation is atomic write.
With reference to the power-down protection area shown in fig. 4, fig. 5 is a schematic flow chart of a third embodiment of a Flash data power-down protection method provided by the embodiment of the present invention, and as shown in fig. 5, the method of this embodiment may include:
s301, receiving a target address, content and length of data to be written.
S302, determining the data to be backed up according to the target address and the length of the data to be written.
And S303, writing the data to be backed up into a second storage area of the backup area.
In particular, the data to be backed up can be written into the second storage area of the backup area page by page, or can be written into the second storage area of the backup area in a page erasing and page writing manner. As shown in fig. 4, for example, data to be backed up may be written page by page to the second storage area of the backup area 1.
S304, writing the first preset mark, the target address and the length into a first storage area of the backup area.
In particular, the first preset mark, the target address and the length can be written into the first storage area of the backup area in a page erasing and page writing mode. As shown in fig. 4, for example, a first preset flag, a target address, and a length may be written into the first storage area of the backup area 1.
S305, writing the content of the data to be written into the target address.
Specifically, the contents of the data to be written may be written into the target address page by page.
S306, the data backed up in the current backup area is cleared, and the logical next page of the end page of the current backup area is used as the initial page of the backup area of the next writing operation.
The purpose of removing the data backed up in the current backup area can be achieved by erasing the content in the first storage area of the current backup area, namely, after the content of the data to be written is written into the target address, the first preset mark, the target address pointed by the atomic write operation and the affected data range are erased. And, as shown in fig. 4, the logical next page of the end page of the current backup area 1 is taken as the start page of the backup area 2 of the next write operation.
According to the Flash data power-down protection method provided by the embodiment of the invention, when the write operation is atomic write, the data to be backed up is written into the second storage area of the backup area, and the first preset mark, the target address and the length are written into the first storage area of the backup area. By dividing the backup area, the data to be backed up, the first preset mark, the target address and the length can be written into different storage areas of the backup area. And after the content of the data to be written is written into the target address, the data backed up in the current backup area is removed, and the logical next page of the termination page of the current backup area is used as the initial page of the backup area for the next writing operation, so that the writing operation times of all data pages in the power-down protection area tend to be the same, the use efficiency of the power-down protection area is improved, and the service life of products is prolonged.
The following description will take an example of the electronic device including the CIU98M25 chip. The Flash page size is 512 bytes, the Native COS platform is realized, and an atomic write function can be provided, namely, single write operation is protected. Because Flash page data is in incomplete state of partial erasure or partial writing if accidental power failure occurs during erasure or writing, the integrity and the correctness of the data cannot be ensured. In order to ensure that the data is successfully written, a description will be given below of how the electronic device recovers the data when the electronic device is accidentally powered down in the step of executing the third embodiment described above:
when the electronic device is powered down accidentally in any step of executing S301-S303, at this time, since no operation has been performed on the data to be written, the power down of the electronic device does not affect the data to be written, and data recovery is not required.
When the electronic device is powered down accidentally while executing S304, if the first preset mark, the target address and the length are completely written into the first storage area of the backup area, after the electronic device is powered up again, the target address and the length can be acquired from the first storage area of the backup area; determining a target page according to the target address and the length; restoring the backup data stored in the second storage area of the backup area into a target page by page, erasing the content in the first storage area of the current backup area, and taking the logical next page of the end page of the current backup area as the initial page of the backup area of the next writing operation; if the first preset mark, the target address and the length are not completely written into the first storage area of the backup area, a random number can be generated, one page is selected from the power-down protection area according to the generated random number to serve as a starting page of the backup area of the next writing operation, and the redetermined backup area can be used for storing backup data of the next writing operation.
When the electronic device is powered down accidentally during execution of S305, at this time, the target address and the length may be obtained from the first storage area of the backup area; determining a target page according to the target address and the length; and restoring the backup data stored in the second storage area of the backup area into the target page by page, erasing the content in the first storage area of the current backup area, and taking the logical next page of the end page of the current backup area as the initial page of the backup area of the next writing operation.
Fig. 6 is a schematic structural diagram of a power-down protection area according to another embodiment of the present invention, where, as shown in fig. 6, if a write operation is a transaction write, a backup area includes a third storage area, a fourth storage area and a fifth storage area, where the third storage area is used for storing a second preset flag, the fourth storage area is used for recording all target page addresses that need to be backed up in the transaction write operation, the fifth storage area is used for backing up page data affected by the transaction write operation, the second preset flag is used for indicating that the write operation is a transaction write, and the fourth storage area includes a plurality of parameter pages.
With reference to the power-down protection area shown in fig. 6, fig. 7 is a schematic flow chart of a fourth embodiment of a Flash data power-down protection method according to an embodiment of the present invention, and as shown in fig. 7, the method of this embodiment may include:
s401, receiving a target address, content and length of data to be written.
S402, determining the data to be backed up according to the target address and the length of the data to be written.
S403, writing the data to be backed up into a fifth storage area of the backup area.
In particular, when the method is implemented, the data to be backed up can be written into the fifth storage area of the backup area page by page, or can be written into the fifth storage area of the backup area in a page erasing and page writing mode. As shown in fig. 6, for example, data to be backed up may be written page by page to the fifth storage area of the backup area 1.
S404, determining a target parameter page from a plurality of parameter pages according to the number counter.
In a specific implementation, the parameter page included in the fourth storage area is a multi-backup mechanism, for example, 2 pages may be used as parameter pages: the parameter pages 1 and 2 are alternatively used, and each page of content may include: valid flag, update times counter, number of current backup addresses N, destination address 1, destination address 2 … … destination address N, check bits, etc. For example, when the current update number counter is odd, parameter page 1 is taken as the target parameter page; when the current update count counter is even, the parameter page 2 is set as the target parameter page.
S405, writing all target addresses in the current and previous transaction writing processes into the target parameter page, and updating the time counter.
After the parameter page is determined, all target addresses in the current and previous transaction writing processes can be written into the target parameter page in a page erasing writing mode, so that when unexpected power failure occurs to the electronic equipment, at least all target addresses in the previous transaction writing processes can be acquired from the parameter page. As shown in fig. 6, for example, all target addresses in the current and previous transaction writing processes may be written to the fourth storage area of the backup area 1.
S406, writing the second preset mark into a third storage area of the backup area.
In particular, the second preset mark may be written into the third storage area of the backup area by using a page erasing and page writing manner. As shown in fig. 6, for example, a second preset mark may be written to the third storage area of the backup area 1.
S407, writing the content of the data to be written into the target address.
Specifically, the contents of the data to be written may be written into the target address page by page.
S408, the data backed up in the current backup area is cleared, and the logical next page of the end page of the current backup area is used as the initial page of the backup area of the next writing operation.
The purpose of removing the data backed up in the current backup area can be achieved by erasing the content in the third storage area of the current backup area, namely, after the content of the data to be written is written into the target address, the second preset mark is erased. And, as shown in fig. 6, the logical next page of the end page of the current backup area 1 is taken as the start page of the backup area 2 of the next write operation.
When the write operation is transaction write, the data to be backed up is written into the fifth storage area of the backup area, the target parameter page is determined from a plurality of parameter pages according to the number counter, all target addresses in the current and previous transaction write processes are written into the target parameter page, the number counter is updated, and the second preset mark is written into the third storage area of the backup area. By dividing the backup area, the data to be backed up, all target addresses in the current and previous transaction writing processes and the second preset mark can be written into different storage areas of the backup area. And after the content of the data to be written is written into the target address, the data backed up in the current backup area is removed, and the logical next page of the termination page of the current backup area is used as the initial page of the backup area for the next writing operation, so that the writing operation times of all data pages in the power-down protection area tend to be the same, the use efficiency of the power-down protection area is improved, and the service life of products is prolonged.
The following description will take an example of the electronic device including the CIU98M25 chip. The Flash page size is 512 bytes, the Java card COS platform is realized, and the atomic write and transaction write functions can be provided. The atomic write operation is the same as the Native platform, and is not repeated herein. The implementation of transactional writes is primarily described herein. Since the write operation of the upper layer application has no atomic write once transaction protection is enabled, the transaction protection shares the same piece of power down protection area as the atomic write.
When in the process of starting the transaction, the application layer can call the NVM management layer interface to start the transaction protection operation, and the NVM management layer uses the RAM variable to store the starting state of the transaction.
When the transaction is in the process of submitting, the NVM management layer can erase the content in the third storage area and the related RAM state.
When in the transaction abort process, the latest parameter page (target parameter page) may be determined from among the plurality of parameter pages included in the fourth storage area of the backup area; the target addresses of the corresponding target pages are taken out one by one from the latest parameter pages; and restoring the backup data stored in the fifth storage area of the backup area into a target page corresponding to the target address page by page, erasing a second preset mark in the third storage area of the current backup area, and taking the logical next page of the end page of the current backup area as the initial page of the backup area of the next writing operation. Among the plurality of parameter pages included in the fourth storage area of the backup area, the parameter page having the largest data amount may be determined as the latest parameter page, or the last parameter page written may be determined as the latest parameter page.
In order to ensure that the data is successfully written, the following will describe how the electronic device recovers the data when the electronic device performs the steps in the fourth embodiment described above. When the electronic device is powered down accidentally while executing any step of S401-S403, at this time, since no operation has been performed on the data to be written, the power down of the electronic device does not affect the data to be written, and data recovery is not required. When the electronic equipment is powered down accidentally during executing any step of S404-S407, determining the latest parameter page from a plurality of parameter pages in a fourth storage area of the backup area; the target addresses of the corresponding target pages are taken out one by one from the latest parameter pages; and restoring the backup data stored in the fifth storage area of the backup area into a target page corresponding to the target address page by page, erasing a second preset mark in the third storage area of the current backup area, and taking the logical next page of the end page of the current backup area as the initial page of the backup area of the next writing operation.
In addition, corresponding to the Flash data power-down protection method provided in the above embodiment, the embodiment of the present invention further provides an electronic device, where the electronic device may include: a memory for storing a program; and the processor is used for executing the program stored in the memory to realize the Flash data power-down protection method provided by the embodiment of the invention.
In addition, corresponding to the Flash data power-down protection method provided in the above embodiment, the embodiment of the present invention further provides a computer readable storage medium, where the computer readable storage medium includes a program, and the program can be executed by a processor to implement the Flash data power-down protection method provided in the embodiment of the present invention.
Reference is made to various exemplary embodiments herein. However, those skilled in the art will recognize that changes and modifications may be made to the exemplary embodiments without departing from the scope herein. For example, the various operational steps and components used to perform the operational steps may be implemented in different ways (e.g., one or more steps may be deleted, modified, or combined into other steps) depending on the particular application or taking into account any number of cost functions associated with the operation of the system.
Additionally, as will be appreciated by one of skill in the art, the principles herein may be reflected in a computer program product on a computer readable storage medium preloaded with computer readable program code. Any tangible, non-transitory computer readable storage medium may be used, including magnetic storage devices (hard disks, floppy disks, etc.), optical storage devices (CD-ROMs, DVDs, blu-Ray disks, etc.), flash memory, and/or the like. These computer program instructions may be loaded onto a general purpose computer, special purpose computer, or other programmable data processing apparatus to produce a machine, such that the instructions which execute on the computer or other programmable data processing apparatus create means for implementing the functions specified. These computer program instructions may also be stored in a computer-readable memory that can direct a computer or other programmable data processing apparatus to function in a particular manner, such that the instructions stored in the computer-readable memory produce an article of manufacture including means which implement the function specified. The computer program instructions may also be loaded onto a computer or other programmable data processing apparatus to cause a series of operational steps to be performed on the computer or other programmable apparatus to produce a computer implemented process such that the instructions which execute on the computer or other programmable apparatus provide steps for implementing the functions specified.
While the principles herein have been shown in various embodiments, many modifications of structure, arrangement, proportions, elements, materials, and components, which are particularly adapted to specific environments and operative requirements, may be used without departing from the principles and scope of the present disclosure. The above modifications and other changes or modifications are intended to be included within the scope of this document.
The foregoing detailed description has been described with reference to various embodiments. However, those skilled in the art will recognize that various modifications and changes may be made without departing from the scope of the present disclosure. Accordingly, the present disclosure is to be considered as illustrative and not restrictive in character, and all such modifications are intended to be included within the scope thereof. Also, advantages, other advantages, and solutions to problems have been described above with regard to various embodiments. The benefits, advantages, solutions to problems, and any element(s) that may cause any benefit, advantage, or solution to occur or become more pronounced are not to be construed as a critical, required, or essential feature. The terms "comprises," "comprising," or any other variation thereof, are intended to cover a non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements does not include only those elements but may include other elements not expressly listed or inherent to such process, method, system, article, or apparatus. Furthermore, the term "couple" and any other variants thereof are used herein to refer to physical connections, electrical connections, magnetic connections, optical connections, communication connections, functional connections, and/or any other connection.
Those skilled in the art will recognize that many changes may be made to the details of the above-described embodiments without departing from the underlying principles of the invention. Accordingly, the scope of the invention should be determined from the following claims.

Claims (10)

1. The Flash data power-down protection method is characterized by being used for electronic equipment, wherein the electronic equipment comprises a Flash memory, a code area, a data area and a power-down protection area are divided into the Flash memory, the code area is used for storing code data, the data area is used for storing file system data and user data, and the power-down protection area is used for backing up data; the method comprises the following steps:
when the electronic equipment is powered on, traversing the power-down protection area, and searching a data page meeting preset conditions, wherein the data page meeting the preset conditions is a starting page of a backup area;
if the data page meeting the preset conditions exists, carrying out data recovery according to the backup area indicated by the data page meeting the preset conditions, removing the backup data in the current backup area, and taking the logical next page of the termination page of the current backup area as the initial page of the backup area of the next writing operation;
if the data page meeting the preset condition does not exist, generating a random number, and selecting one page from the power-down protection area according to the generated random number as a starting page of a backup area of the next writing operation.
2. The method of claim 1, wherein the method further comprises:
receiving a target address, content and length of data to be written;
determining the data to be backed up according to the target address and the length of the data to be written;
writing the data to be backed up into a current backup area;
writing the content of the data to be written into the target address;
and clearing the data backed up in the current backup area, and taking the logical next page of the end page of the current backup area as the initial page of the backup area of the next writing operation.
3. The method of claim 2, wherein if the write operation is an atomic write, the backup area includes a first storage area for storing a first preset flag and a target address to which the atomic write operation is directed and an affected data range, and a second storage area for backing up page data affected by the atomic write operation, the first preset flag being used to indicate that the write operation is an atomic write; the writing the data to be backed up into the current backup area comprises the following steps:
writing the data to be backed up into a second storage area of the backup area;
and writing the first preset mark, the target address and the length into a first storage area of the backup area.
4. The method as claimed in claim 3, wherein the data page meeting the preset condition is a data page in which the first preset mark exists, and the performing data recovery according to the backup area indicated by the data page meeting the preset condition includes:
acquiring the target address and the length from a first storage area of the backup area;
determining a target page according to the target address and the length;
and restoring the backup data stored in the second storage area of the backup area into the target page by page.
5. The method of claim 3 or 4, wherein the clearing the data backed up in the current backup area comprises:
and erasing the content in the first storage area of the current backup area.
6. The method of claim 2, wherein if the write operation is a transactional write, the backup area includes a third storage area, a fourth storage area, and a fifth storage area, the third storage area is used for storing a second preset flag, the fourth storage area is used for recording all target page addresses that need to be backed up in the transactional write operation, the fifth storage area is used for backing up page data affected by the transactional write operation, the second preset flag is used for indicating that the write operation is a transactional write, and the fourth storage area includes a plurality of parameter pages; the writing the data to be backed up into the current backup area comprises the following steps:
writing the data to be backed up into a fifth storage area of the backup area;
determining a target parameter page from a plurality of parameter pages according to the number counter;
writing all target addresses in the current and previous transaction writing processes into the target parameter page, and updating the number counter;
and writing the second preset mark into a third storage area of the backup area.
7. The method as claimed in claim 6, wherein the data page meeting the preset condition is a data page in which the second preset mark exists, and the performing data recovery according to the backup area indicated by the data page meeting the preset condition includes:
determining the latest parameter page from a plurality of parameter pages included in a fourth storage area of the backup area;
the target addresses of the corresponding target pages are taken out one by one from the latest parameter pages;
and restoring the backup data stored in the fifth storage area of the backup area page by page into a target page corresponding to the target address.
8. The method of claim 6 or 7, wherein the clearing the data backed up in the current backup area comprises:
and erasing the content in the third storage area of the current backup area.
9. An electronic device, comprising:
a memory for storing a program;
a processor for implementing the method of any one of claims 1-8 by executing a program stored in the memory.
10. A computer readable storage medium comprising a program executable by a processor to implement the method of any one of claims 1-8.
CN202080026922.3A 2020-12-17 2020-12-17 Flash data power-down protection method and device Active CN113785275B (en)

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
PCT/CN2020/137133 WO2022126470A1 (en) 2020-12-17 2020-12-17 Flash data power failure protection method and device

Publications (2)

Publication Number Publication Date
CN113785275A CN113785275A (en) 2021-12-10
CN113785275B true CN113785275B (en) 2024-03-05

Family

ID=78835354

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202080026922.3A Active CN113785275B (en) 2020-12-17 2020-12-17 Flash data power-down protection method and device

Country Status (2)

Country Link
CN (1) CN113785275B (en)
WO (1) WO2022126470A1 (en)

Families Citing this family (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
KR20220067921A (en) * 2020-11-18 2022-05-25 한국전자통신연구원 Device with Flash-Memory, Method for Writing/Erasing/Updating Data in Flash Memory Thereof
CN114428588A (en) * 2021-12-17 2022-05-03 深圳市拔超科技股份有限公司 Flash power-down data storage method and system
CN116795297B (en) * 2023-08-18 2023-11-17 江苏云途半导体有限公司 Storage device, storage method and device
CN117112310B (en) * 2023-10-18 2024-02-20 苏州元脑智能科技有限公司 Background task progress saving and restoring method, device, equipment and storage medium
CN117251116B (en) * 2023-11-14 2024-02-20 苏州元脑智能科技有限公司 Erasing and writing method and device of nonvolatile memory

Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN103617101A (en) * 2013-12-12 2014-03-05 北京旋极信息技术股份有限公司 Power fail safeguard method and device
CN108108271A (en) * 2017-12-25 2018-06-01 飞天诚信科技股份有限公司 It is a kind of to realize affairs and the method and device of power down protection unified management
CN111427726A (en) * 2020-03-27 2020-07-17 江苏恒宝智能系统技术有限公司 IC card and power-down prevention data backup method or data recovery method thereof
CN111737058A (en) * 2020-06-29 2020-10-02 江苏恒宝智能系统技术有限公司 IC card and power-down prevention data backup method or data recovery method thereof

Family Cites Families (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
KR100746198B1 (en) * 2005-07-08 2007-08-06 삼성전자주식회사 Apparatus and method for storing data, and readable recording medium thereof
CN103793337B (en) * 2013-11-12 2016-08-24 飞天诚信科技股份有限公司 A kind of data guard method of power down preventing
US9684360B2 (en) * 2014-10-30 2017-06-20 Intel Corporation Dynamically controlling power management of an on-die memory of a processor
CN109685190B (en) * 2018-12-28 2022-04-12 江苏恒宝智能系统技术有限公司 Power-down protection method and device for IC card

Patent Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN103617101A (en) * 2013-12-12 2014-03-05 北京旋极信息技术股份有限公司 Power fail safeguard method and device
CN108108271A (en) * 2017-12-25 2018-06-01 飞天诚信科技股份有限公司 It is a kind of to realize affairs and the method and device of power down protection unified management
CN111427726A (en) * 2020-03-27 2020-07-17 江苏恒宝智能系统技术有限公司 IC card and power-down prevention data backup method or data recovery method thereof
CN111737058A (en) * 2020-06-29 2020-10-02 江苏恒宝智能系统技术有限公司 IC card and power-down prevention data backup method or data recovery method thereof

Also Published As

Publication number Publication date
CN113785275A (en) 2021-12-10
WO2022126470A1 (en) 2022-06-23

Similar Documents

Publication Publication Date Title
CN113785275B (en) Flash data power-down protection method and device
US7694094B2 (en) Transaction method for managing the storing of persistent data in a transaction stack
US20180275887A1 (en) Data Storage Device and Operating Method of Data Storage Device
CN110347332B (en) Garbage collection policy for memory system and method for performing the garbage collection
US8756458B2 (en) Mount-time reconciliation of data availability
US20150186224A1 (en) Data storage device and flash memory control method
US20080005510A1 (en) Compression Method for Managing the Storing of Persistent Data From a Non-Volatile Memory to a Backup Buffer
US20090172252A1 (en) Memory device and method for performing a write-abort-safe firmware update
CN103996412A (en) Power-fail protection method applied to intelligent-card nonvolatile memories
CN104516959A (en) Method and device for managing database logs
KR20150039742A (en) System and method for object deletion in persistent memory using bitmap windows
CN110032526B (en) Page caching method, system and equipment based on nonvolatile medium
JP5464226B2 (en) Information processing apparatus, information processing apparatus control method, and information processing apparatus control program
CN110989931A (en) Bad block processing method, device and equipment for storage equipment and storage medium
CN110287695A (en) A kind of management method of Java card and its temporary object
CN107341049B (en) Transaction optimization processing method and device
KR101548452B1 (en) Method and apparatus for recovering metadata in electronic device based on non-volatile memeory
US20090024810A1 (en) Memory area management method
US20130080690A1 (en) Method to emulate eeprom using flash memory
CN111008159B (en) Data protection method, device, equipment and storage medium for storage equipment
CN110471626B (en) Nor Flash management layer and method applied to Java Card
CN109960611B (en) Data recovery method and device, electronic equipment and machine-readable storage medium
US7861016B2 (en) Transaction stack for electronic devices including non volatile memory with limited amount of writing cycle
CN110597458A (en) NAND FLASH bad block processing method
KR101545077B1 (en) Method and apparatus for recovering metadata in electronic device based on non-volatile memeory

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant