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

Flash data power-down protection method and device Download PDF

Info

Publication number
CN113785275A
CN113785275A CN202080026922.3A CN202080026922A CN113785275A CN 113785275 A CN113785275 A CN 113785275A CN 202080026922 A CN202080026922 A CN 202080026922A CN 113785275 A CN113785275 A CN 113785275A
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.)
Granted
Application number
CN202080026922.3A
Other languages
Chinese (zh)
Other versions
CN113785275B (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

Images

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 equipment are provided, and the method comprises the following steps: when the electronic equipment is powered on, traversing the power failure protection area, searching a data page meeting preset conditions, wherein the data page meeting the preset conditions is a starting page of the backup area; if the data page meeting the preset condition exists, performing data recovery according to the backup area indicated by the data page meeting the preset condition, clearing 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 starting page of the backup area for the next write operation; and 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 the initial page of the backup area of the next writing operation according to the generated random number. On the premise of ensuring the integrity of data, the erasing times of each data page 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 a product 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 widely used as a Non-Volatile Memory (NVM) with the advantages of large capacity, low price, etc., and most of bottom chips of a smart Card Operating System (COS) use Flash as a storage medium. Most of the Flash only supports page erasing writing, which means that all data must be erased before writing, and then new data can be written in, and if new data needs to be written in again, the whole page needs to be erased again. If unexpected power loss occurs during erasing or writing, the data may be in a partially erased or partially written incomplete state, and the integrity of the data cannot be ensured.
In order to ensure the integrity of data, a space is allocated in the Flash memory as a power-down protection area for recording backup data of related write operations, so as to restore the related backup data after power failure. The existing power-fail protection area usually adopts a page backup operation mechanism, relevant backup data is written into a fixed Flash page in advance when NVM operation is carried out, then the Flash page where target data is located is erased, and then the relevant data page of the backup area is erased after the target data is completed. Limited by the technology, the erase lifetime of Flash pages is limited. The power-down protection area is used as an area common to all NVM operation, the erasing times are the most, and the erasing pressure is the greatest, so that the service life of the whole Flash memory is basically limited by the service life of the power-down protection area.
In conclusion, the conventional Flash data power-down protection method greatly reduces the actual service life of the product.
Disclosure of Invention
The invention mainly provides a Flash data power-down protection method and device, 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, an embodiment provides a Flash data power-down protection method, which is used for an electronic device, wherein the electronic device comprises a Flash memory, a code area, a data area and a power-down protection area are divided in 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 failure protection area, and searching a data page meeting a preset condition, wherein the data page meeting the preset condition is a starting page of a backup area;
if the data page meeting the preset condition exists, performing data recovery according to the backup area indicated by the data page meeting the preset condition, clearing the data backed up in the current backup area, and taking a logic next page of a termination page of the current backup area as a starting page of the backup area of the next writing operation;
and 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 an initial page of a backup area for the next writing operation according to the generated random number.
Optionally, the method further includes:
receiving a target address, content and length of data to be written;
determining 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 ending page of the current backup area as the starting page of the backup area for the next write operation.
Optionally, if the write operation is an atomic write, 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, a target address pointed by the atomic write operation, and an affected data range, the second storage area is used to backup page data affected by the atomic write operation, and the first preset mark is used to indicate that the write operation is an atomic write; the writing the data to be backed up into the current backup area includes:
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 to 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 write operation is a transaction write, 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 mark, the fourth storage area is used to record all target page addresses that need to be backed up in the transaction write operation, the fifth storage area is used to backup page data affected by the transaction write operation, the second preset mark is used to indicate that the write operation is the transaction write, and the fourth storage area includes multiple parameter pages; the writing the data to be backed up into the current backup area includes:
writing the data to be backed up into a fifth storage area of the backup area;
determining a target parameter page from the plurality of parameter pages according to the number counter;
writing all target addresses in the current and previous transaction writing process into the target parameter page, and updating the frequency 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 a latest parameter page from a plurality of parameter pages included in a fourth storage area of the backup area;
taking out the target addresses of the corresponding target pages one by one from the latest parameter pages;
and restoring the backup data stored in the fifth storage area of the backup area to a target page corresponding to the target address page by page.
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 an embodiment an electronic device comprising:
a memory for storing a program;
and the processor is used for implementing the Flash data power-fail protection method of any one of the first aspect by executing the program stored in the memory.
According to a third aspect, an embodiment provides a computer-readable storage medium, which includes a program, where the program is executable by a processor to implement the Flash data power-fail protection method of any one of the above first aspects.
According to the Flash data power-down protection method and the device of the embodiment, the method comprises the following steps: when the electronic equipment is powered on, traversing the power failure protection area, searching a data page meeting preset conditions, wherein the data page meeting the preset conditions is a starting page of the backup area; if the data page meeting the preset condition exists, performing data recovery according to the backup area indicated by the data page meeting the preset condition, clearing 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 starting page of the backup area for the next write operation; and 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 the initial page of the backup area of the next writing operation according to the generated random number. On the premise of ensuring the integrity of data, the erasing times of each data page 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 a product is prolonged.
Drawings
Fig. 1 is a schematic flow chart of a first embodiment of a Flash data power-down protection method according to an embodiment of the present 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 flowchart of a second embodiment of a Flash data power-down protection method according to an 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 flowchart of a third embodiment of a Flash data power-down protection method according to an 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 schematic flowchart of a fourth embodiment of a Flash data power-down protection method according to an embodiment of the present invention.
Detailed Description
The present invention will be described in further detail with reference to the following detailed description and accompanying drawings. Wherein like elements in different embodiments are numbered with like associated elements. In the following description, numerous details are set forth in order to provide a better understanding of the present application. However, those skilled in the art will readily recognize that some of the features may be omitted or replaced with other elements, materials, methods in different instances. In some instances, certain operations related to the present application have not been shown or described in detail in order to avoid obscuring the core of the present application from excessive description, and it is not necessary for those skilled in the art to describe these operations in detail, so that they may be fully understood from the description in the specification and the general knowledge in the art.
Furthermore, the features, operations, or characteristics described in the specification may be combined in any suitable manner to form various embodiments. Also, the various steps or actions in the method descriptions may be transposed or transposed in order, as will be apparent to one of ordinary skill in the art. Thus, the various sequences in the specification and drawings are for the purpose of describing certain embodiments only and are not intended to imply a required sequence unless otherwise indicated where such sequence must be followed.
The numbering of the components as such, e.g., "first", "second", etc., is used herein only to distinguish the objects as described, and does not have any sequential or technical meaning. The term "connected" and "coupled" when used in this application, unless otherwise indicated, includes both direct and indirect connections (couplings).
Because the existing power-fail protection area usually adopts a page backup operation mechanism, relevant backup data is written into a fixed Flash page in advance when NVM operation is carried out, then the Flash page where target data is located is erased, and then the relevant data page of the backup area is erased after the target data is completely erased. Limited by the technology, the erase lifetime of Flash pages is limited. The power-down protection area is used as an area common to all NVM operation, the erasing times are the most, and the erasing pressure is the greatest, so that the service life of the whole Flash memory is basically limited by the service life of the power-down protection area. 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, embodiments of the present invention provide a Flash data power-down protection method and device, which are described in detail below.
First, some terms involved in the present invention are briefly described:
COS: the Card operation System refers to a smart Card operating System directly developed on a security chip, and generally refers to a general or industrial operating System developed based on the capabilities and interfaces of a bottom chip in the embedded security chip industry, such as the telecommunication industry, the financial industry, and the like, or a general version can be well expanded.
RAM: random Access Memory, also called main Memory, is an internal Memory that exchanges data directly with the CPU. It can be read and written at any time (except for refreshing), and has high speed, and is usually used as a temporary data storage medium of an operating system or other programs in operation. The RAM can write (store) or read (take out) information from any one of designated addresses at any time when it is operated. The biggest difference between the Read-Only Memory (ROM) and the Read-Only Memory is the volatility of data, namely, the stored data is lost when power is cut off. RAM is used in computers and digital systems to temporarily store programs, data, and intermediate results. Here, the operating memory provided in the secure chip is mainly referred to.
NVM: non-volatile Memory, which has the characteristics of Non-volatility, Access by bytes, high storage density, low energy consumption and the like, has read-write performance close to that of Dynamic Random Access Memory (DRAM), but has asymmetric read-write speed and limited service life. Mainly referred to herein as storage provided by the secure chip that allows for data persistence.
Flash: a nonvolatile memory, which can maintain data for years even without power, is mainly divided into two types of NAND/NOR. Generally, data is written in by erasing operation, which is mostly a page erasing and page writing mechanism, and part of the mechanisms supports page erasing and writing or byte writing. However, the erasing times of each page are protected by the lowest times, and the data can not be normally erased and written when the erasing times exceed the protection times, so that the service life of the Flash page is directly limited by the characteristic. The upper layer application must consider both the page erase mechanism and lifetime limitation characteristics when 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 strong function, simplicity and easiness in use. The Java language, which is representative of the static object-oriented programming language, excellently implements object-oriented theory, allowing programmers to perform complex programming in an elegant, mental manner. Java has the characteristics of simplicity, object-oriented property, distribution, robustness, safety, platform independence and portability, multithreading, dynamicity and the like. Java may write desktop applications, Web site applications, distributed system and embedded system applications, etc.
JavaCard technique: a secure environment is provided for applications that run on smart cards (secure chips) and other devices that have very limited memory and processing power. Multiple applications can be deployed on a card, and new applications can be added to the card even after it is distributed to end users. Applications written in the Java programming language can run securely on cards of different vendors. Is a leading open interoperation platform applicable to smart cards and security tokens. Various JavaCard specifications provide the basis for cross-platform and cross-vendor applet interoperability.
Native: generally refers to the technical design and implementation which is realized by C language and is independent of Java, JavaCard and JavaApplet.
Fig. 1 is a schematic flow diagram of a first embodiment of a Flash data power-down protection method provided in an embodiment of the present invention, and as shown in fig. 1, the method of this embodiment may include:
s101, when the electronic equipment is powered on, traversing the power failure protection area, and searching a data page meeting preset conditions.
The electronic device comprises a Flash memory, wherein the Flash memory can be divided into a code area, a data area and a power-down protection area, 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 condition is a starting page of the backup area, and the functions of atomic write and transaction write can be compatible. The atomic write means that the operation result of performing a single write operation is in a state of successfully completing write or in a state of not writing, and other intermediate states are not allowed to occur; the transactional write means that after the start of the transactional protection and before the end of the transactional protection, the write data operation in this period is in a state of being completely written or in a state of being completely unwritten, and partial data is not allowed to be rewritten.
And S102, if the data page meeting the preset condition exists, performing data recovery according to the backup area indicated by the data page meeting the preset condition, clearing the data backed up in the current backup area, and taking the logic next page of the termination page of the current backup area as the start page of the backup area of the next writing operation.
If the data page meeting the preset condition exists, the representation backup area stores the last unfinished data operation content, so that data recovery needs to be performed on the backup area indicated by the data page meeting the preset condition, where data recovery is performed on current backup data included in a start page of the backup area to an end page of the backup area, that is, data recovery of the backup area is completed once. After the data is restored, the data backed up in the current backup area is removed, so that the current backup area can be reused later.
And taking the logical next page of the ending page of the current backup area as the starting page of the backup area for the next write operation, wherein the logical next page refers to the head-to-tail connection position of the current backup area and the backup area for the next write 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 a backup area 1 in fig. 2, a logical next page of an end page of the backup area 1 is used as a starting page of a backup area 2 for a next write 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 start page of the backup area 3 for the next write operation; if the current backup area is the backup area 3 in fig. 2, the logical next page of the ending page of the backup area 3 is used as the starting page of the backup area 4 for the next write operation; if the current backup area is the backup area 4 in fig. 2, the logical next page of the ending page of the backup area 4 is used as the starting page of the 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 thousand times, and for the power-down protection area shown in fig. 2, after the power-down protection area is divided into four backup areas, the erase life of each backup area is ten thousand times, the erase life of the power-down protection area is four thousand times.
S103, if the data page meeting the preset condition does not exist, a random number is generated, and a page is selected from the power-down protection area as the initial page of the 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 representation backup area does not store legal backup data, so that the backup area of the next write operation needs to be determined in the power failure protection area. Specifically, the random number generator may be started or a related random number generation algorithm interface may be called to generate a random number, and a page may be selected from the power-down protection area as an initial page of the backup area for the next write operation according to the generated random number, so that the backup area for the next write operation may be 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 condition exists, performing data recovery according to the backup area indicated by the data page meeting the preset condition, clearing 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 starting page of the backup area for the next write operation; and 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 the initial page of the backup area of the next writing operation according to the generated random number. On the premise of ensuring the integrity of data, the erasing times of each data page 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 a product is prolonged.
Through the first embodiment, the electronic device completes the power down protection start operation, and on the basis of the first embodiment, fig. 3 is a schematic flow diagram of a second embodiment of a method for power down protection of Flash data according to an embodiment of the present invention, as shown in fig. 3, after executing S102 or S103, the method of this 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 transmitted 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 starting page address and range 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 specific implementation, the data to be backed up may be written into the current backup area page by page, or the data to be backed up may be written into the current backup area in a page erase writing manner.
S204, writing the content of the data to be written into the target address.
In specific implementation, the content of the data to be written can be written into 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 ending page of the current backup area as the starting page of the backup area of the next write operation.
The Flash data power-fail protection method provided by the embodiment of the invention receives the target address, the content and the length of the data to be written; determining 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 a target address; and clearing the data backed up in the current backup area, and taking the logic next page of the termination page of the current backup area as the initial page of the backup area for the next write operation, so that the write 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 a product is prolonged.
Fig. 4 is a schematic structural diagram of another power down protection area according to an embodiment of the present invention, and 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 to store a first preset mark, a target address pointed by the atomic write operation, and an affected data range, the second storage area is used to backup page data affected by the atomic write operation, and the first preset mark is used to indicate 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 method for power down protection of Flash data according to an 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.
S303, writing the data to be backed up into the second storage area of the backup area.
In specific implementation, the data to be backed up may be written into the second storage area of the backup area page by page, or the data to be backed up may be written into the second storage area of the backup area in a page erase writing manner. As shown in fig. 4, for example, data to be backed up may be written page by page in 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 a specific implementation, the first preset mark, the target address and the length may be written into the first storage area of the backup area by a page erase writing method. As shown in fig. 4, for example, a first preset mark, a target address and a length may be written in 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 content of the data to be written may be written to the target address page by page.
S306, clearing the data backed up in the current backup area, and taking the logical next page of the ending page of the current backup area as the starting page of the backup area of the next writing operation.
The purpose of clearing 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, that is, after the content of the data to be written is written into the target address, the target address pointed by the first preset mark and the atomic write operation and the affected data range are erased. And, as shown in fig. 4, the logical next page of the ending page of the current backup area 1 is taken as the starting page of the backup area 2 for the next write operation.
According to the Flash data power-down protection method provided by the embodiment of the invention, when the writing operation is atomic writing, 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 cleared, and the logical next page of the ending page of the current backup area is used as the starting page of the backup area for the next write operation, so that the write 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 a product is prolonged.
The following description will be made by taking an example in which the CIU98M25 chip is included in the electronic device. The Flash has a page size of 512 bytes, realizes a Native COS platform, and can provide an atomic write function, namely, protect single write operation. Because the Flash page data can be in a partial erasing or partial writing incomplete state if unexpected power failure occurs during erasing or writing, the integrity and correctness of the data cannot be ensured. In order to ensure that data is successfully written, how the electronic device recovers the data in the event of unexpected power loss during the execution of the steps in the third embodiment will be described below:
when the electronic device unexpectedly loses power in any step of S301-S303, no operation is performed on the data to be written yet, so that the data to be written is not affected by the power loss of the electronic device, and data recovery is not needed.
When the electronic device is powered off unexpectedly when 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, the target address and the length may be acquired from the first storage area of the backup area after the electronic device is powered on again; 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 to 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 termination page of the current backup area as the starting page of the backup area of the next write 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, a page is selected from the power-down protection area as an initial page of the backup area of the next write operation according to the generated random number, and the newly determined backup area can be used for storing backup data of the next write operation.
When the electronic device is powered off unexpectedly during S305, 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; restoring the backup data stored in the second storage area of the backup area to 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 ending page of the current backup area as the starting page of the backup area of the next write operation.
Fig. 6 is a schematic structural diagram of another power down protection area according to an embodiment of the present invention, and 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 to store a second preset mark, the fourth storage area is used to record all target page addresses that need to be backed up in the transaction write operation, the fifth storage area is used to backup page data affected by the transaction write operation, the second preset mark is used to indicate that the write operation is the 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 method for power down protection of Flash data according to an embodiment of the present invention, and as shown in fig. 7, the method according to the embodiment may include:
s401, receiving the target address, the content and the length of the 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.
And S403, writing the data to be backed up into a fifth storage area of the backup area.
In specific implementation, the data to be backed up may be written into the fifth storage area of the backup area page by page, or the data to be backed up may be written into the fifth storage area of the backup area in a page erase writing manner. As shown in fig. 6, for example, data to be backed up may be written page by page in the fifth storage area of the backup area 1.
S404, determining a target parameter page from the 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 can be used as the parameter page: the two pages can be used alternately, and each page can include: valid flag, update times counter, the number of current backup addresses N, target address 1, target address 2 … …, target address N, check bits, etc. For example, when the current update number counter is odd, the parameter page 1 is taken as the target parameter page; when the current update time counter is an even number, the parameter page 2 is set as the target parameter page.
S405, all target addresses in the current and previous transaction writing process are written into a target parameter page, and a number counter is updated.
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 page writing mode, so that when the electronic equipment is powered off unexpectedly, all target addresses in the previous transaction writing process can be at least acquired from the parameter page. As shown in fig. 6, for example, all target addresses currently and previously in the process of the transaction writing may be written into the fourth storage area of the backup area 1.
S406, writing the second preset mark into the third storage area of the backup area.
In a specific implementation, the second preset mark may be written in the third storage area of the backup area in a page erasing and writing manner. As shown in fig. 6, for example, a second preset mark may be written in 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 content of the data to be written may be written to the target address page by page.
S408, clearing the data backed up in the current backup area, and taking the logical next page of the ending page of the current backup area as the starting page of the backup area of the next writing operation.
The purpose of clearing 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, that is, 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 ending page of the current backup area 1 is taken as the starting page of the backup area 2 for 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 transaction write, data to be backed up is written into a fifth storage area of a backup area, a target parameter page is determined from a plurality of parameter pages according to a frequency counter, all target addresses in the current and previous transaction write processes are written into the target parameter page, the frequency counter is updated, and a second preset mark is written into a third storage area of the backup area. By dividing the backup area, the data to be backed up, all target addresses and the second preset marks in the current and previous transaction writing processes 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 cleared, and the logical next page of the ending page of the current backup area is used as the starting page of the backup area for the next write operation, so that the write 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 a product is prolonged.
The following description will be made by taking an example in which the CIU98M25 chip is included in the electronic device. The Flash has a page size of 512 bytes, realizes a JavaCard COS platform, and can provide atomic write and transaction write functions. The atomic write operation is implemented in the same way as the Native platform, and is not described again here. The implementation of transactional writes is primarily described herein. Since there is no atomic write once the transaction protection is enabled for the write operation of the upper layer application, the transaction protection and the atomic write share the same power down protection region.
While in the transaction initiation process, the application layer may invoke the NVM management layer interface to initiate a transaction protection operation, with the NVM management layer storing the transaction initiation state with RAM variables.
When the transaction is in the process of committing, the NVM management layer erases the content and the related RAM state in the third storage area.
When the transaction abandoning process is in progress, the latest parameter page (target parameter page) can be determined from a plurality of parameter pages included in the fourth storage area of the backup area; taking out the target addresses of the corresponding target pages one by one from the latest parameter pages; restoring the backup data stored in the fifth storage area of the backup area to 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 a logical next page of an ending page of the current backup area as a starting page of the backup area for the next write operation. Among the plurality of parameter pages included in the fourth storage area of the backup area, the parameter page with the largest data amount may be determined as the latest parameter page, or the last written parameter page may be determined as the latest parameter page.
In order to ensure that data is successfully written, how the electronic device recovers the data in the event of unexpected power loss during the execution of the steps in the fourth embodiment will be described as follows: when the electronic device unexpectedly loses power while executing any step in S401-S403, at this time, since no operation has been performed on the data to be written, the power loss of the electronic device does not affect the data to be written, and data recovery is not required. When the electronic device is unexpectedly powered down while executing any step of S404-S407, at this time, the latest parameter page may be determined from a plurality of parameter pages included in the fourth storage area of the backup area; taking out the target addresses of the corresponding target pages one by one from the latest parameter pages; restoring the backup data stored in the fifth storage area of the backup area to 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 a logical next page of an ending page of the current backup area as a starting page of the backup area for the next write operation.
In addition, corresponding to the Flash data power-down protection method provided by the above embodiment, an 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 implementing the Flash data power-fail protection method provided by the embodiment of the invention by executing the program stored in the memory.
In addition, corresponding to the Flash data power-fail protection method provided by the above embodiment, an 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-fail protection method provided by the embodiment of the present invention.
Reference is made herein to various exemplary embodiments. However, those skilled in the art will recognize that changes and modifications may be made to the exemplary embodiments without departing from the scope hereof. For example, the various operational steps, as well as the components used to perform the operational steps, may be implemented in differing ways depending upon the particular application or consideration of any number of cost functions associated with operation of the system (e.g., one or more steps may be deleted, modified or incorporated into other steps).
Additionally, as will be appreciated by one skilled in the art, the principles herein may be reflected in a computer program product on a computer readable storage medium, which is pre-loaded 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 for implementing 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 illustrated in various embodiments, many modifications of structure, arrangement, proportions, elements, materials, and components particularly adapted to specific environments and operative requirements may be employed 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, one 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 disclosure is to be considered in an illustrative and not a restrictive sense, 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. However, the benefits, advantages, solutions to problems, and any element(s) that may cause any element(s) to occur or become more pronounced are not to be construed as a critical, required, or essential feature or element of any or all the claims. As used herein, 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 "coupled," and any other variation thereof, as used herein, refers to a physical connection, an electrical connection, a magnetic connection, an optical connection, a communicative connection, a functional connection, 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. A 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 in 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 failure protection area, and searching a data page meeting a preset condition, wherein the data page meeting the preset condition is a starting page of a backup area;
if the data page meeting the preset condition exists, performing data recovery according to the backup area indicated by the data page meeting the preset condition, clearing the data backed up in the current backup area, and taking a logic next page of a termination page of the current backup area as a starting page of the backup area of the next writing operation;
and 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 an initial page of a backup area for the next writing operation according to the generated random number.
2. The method of claim 1, wherein the method further comprises:
receiving a target address, content and length of data to be written;
determining 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 ending page of the current backup area as the starting page of the backup area for the next write operation.
3. The method of claim 2, wherein if the write operation is an atomic write, the backup area includes a first storage area and a second storage area, the first storage area is used for storing a first preset mark and 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 mark is used for indicating that the write operation is the atomic write; the writing the data to be backed up into the current backup area includes:
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 predetermined condition is a data page in which the first predetermined flag exists, and the performing data recovery according to the backup area indicated by the data page meeting the predetermined 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 to the target page by page.
5. The method of claim 3 or 4, wherein the clearing of 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 according to 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 required 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 the 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 includes:
writing the data to be backed up into a fifth storage area of the backup area;
determining a target parameter page from the plurality of parameter pages according to the number counter;
writing all target addresses in the current and previous transaction writing process into the target parameter page, and updating the frequency 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 predetermined condition is a data page in which the second predetermined flag exists, and the performing data recovery according to the backup area indicated by the data page meeting the predetermined condition includes:
determining a latest parameter page from a plurality of parameter pages included in a fourth storage area of the backup area;
taking out the target addresses of the corresponding target pages one by one from the latest parameter pages;
and restoring the backup data stored in the fifth storage area of the backup area to a target page corresponding to the target address page by page.
8. The method of claim 6 or 7, wherein the clearing of 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 by the memory.
10. A computer-readable storage medium, characterized by 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 true CN113785275A (en) 2021-12-10
CN113785275B 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)

Cited By (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN114428588A (en) * 2021-12-17 2022-05-03 深圳市拔超科技股份有限公司 Flash power-down data storage method and system
US20220155974A1 (en) * 2020-11-18 2022-05-19 Electronics And Telecommunications Research Institute Device with flash memory and method for writing/erasing/updating data in flash memory thereof
CN117112310A (en) * 2023-10-18 2023-11-24 苏州元脑智能科技有限公司 Background task progress saving and restoring method, device, equipment and storage medium
CN117251116A (en) * 2023-11-14 2023-12-19 苏州元脑智能科技有限公司 Erasing and writing method and device of nonvolatile memory

Families Citing this family (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN116795297B (en) * 2023-08-18 2023-11-17 江苏云途半导体有限公司 Storage device, storage method and device

Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20070011416A1 (en) * 2005-07-08 2007-01-11 Lee Sung-Woo Data storage device and medium and related method of storing backup data
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 (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
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 (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20070011416A1 (en) * 2005-07-08 2007-01-11 Lee Sung-Woo Data storage device and medium and related method of storing backup data
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

Cited By (7)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20220155974A1 (en) * 2020-11-18 2022-05-19 Electronics And Telecommunications Research Institute Device with flash memory and method for writing/erasing/updating data in flash memory thereof
US11726668B2 (en) * 2020-11-18 2023-08-15 Electronics And Telecommunications Research Institute Device with flash memory and 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
CN117112310A (en) * 2023-10-18 2023-11-24 苏州元脑智能科技有限公司 Background task progress saving and restoring method, device, equipment and storage medium
CN117112310B (en) * 2023-10-18 2024-02-20 苏州元脑智能科技有限公司 Background task progress saving and restoring method, device, equipment and storage medium
CN117251116A (en) * 2023-11-14 2023-12-19 苏州元脑智能科技有限公司 Erasing and writing method and device of nonvolatile memory
CN117251116B (en) * 2023-11-14 2024-02-20 苏州元脑智能科技有限公司 Erasing and writing method and device of nonvolatile memory

Also Published As

Publication number Publication date
CN113785275B (en) 2024-03-05
WO2022126470A1 (en) 2022-06-23

Similar Documents

Publication Publication Date Title
CN113785275B (en) Flash data power-down protection method and device
US9104329B2 (en) Mount-time reconciliation of data availability
US20180260132A1 (en) Data Storage Device and Operating Method Thereof
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
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
US8775758B2 (en) Memory device and method for performing a write-abort-safe firmware update
EP2366152A2 (en) Ruggedized memory device
CN104516959A (en) Method and device for managing database logs
CN103996412A (en) Power-fail protection method applied to intelligent-card nonvolatile memories
US20150074336A1 (en) Memory system, controller and method of controlling memory system
KR20080104815A (en) Apparatus and method of processing data of non-volatile memory
CN110032526B (en) Page caching method, system and equipment based on nonvolatile medium
CN110287695A (en) A kind of management method of Java card and its temporary object
US20090024810A1 (en) Memory area management method
KR100622113B1 (en) Flash memory storing system for database system and method therefor
US20130080690A1 (en) Method to emulate eeprom using flash memory
KR20150094292A (en) Method and apparatus for recovering metadata in electronic device based on non-volatile memeory
EP2267725A1 (en) Memory device for managing the recovery of a non volatile memory
CN111142792B (en) Power-down protection method of storage device
CN110471626B (en) Nor Flash management layer and method applied to Java Card
EP1344224B1 (en) Method for the secure updating of data areas in a non volatile memory and device to perform such a method
KR101545077B1 (en) Method and apparatus for recovering metadata in electronic device based on non-volatile memeory
US10817215B2 (en) Data storage system and control method for non-volatile memory

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