WO2022126470A1 - Flash数据掉电保护方法及设备 - Google Patents

Flash数据掉电保护方法及设备 Download PDF

Info

Publication number
WO2022126470A1
WO2022126470A1 PCT/CN2020/137133 CN2020137133W WO2022126470A1 WO 2022126470 A1 WO2022126470 A1 WO 2022126470A1 CN 2020137133 W CN2020137133 W CN 2020137133W WO 2022126470 A1 WO2022126470 A1 WO 2022126470A1
Authority
WO
WIPO (PCT)
Prior art keywords
data
page
backup area
area
storage area
Prior art date
Application number
PCT/CN2020/137133
Other languages
English (en)
French (fr)
Inventor
金辉
邓世荣
Original Assignee
深圳杰睿联科技有限公司
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 深圳杰睿联科技有限公司 filed Critical 深圳杰睿联科技有限公司
Priority to CN202080026922.3A priority Critical patent/CN113785275B/zh
Priority to PCT/CN2020/137133 priority patent/WO2022126470A1/zh
Publication of WO2022126470A1 publication Critical patent/WO2022126470A1/zh

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

Definitions

  • the invention relates to the technical field of storage, in particular to a method and device for power-down protection of Flash data.
  • Flash memory Flash as a non-volatile memory (Non-Volatile Memory, NVM)
  • NVM Non-Volatile Memory
  • Smart card operating system Carl Most of the underlying chips of Operate System, COS
  • page erasing page writing means that all data must be erased before writing the original entire page of Flash data, and then new data can be written. If new data needs to be written again Then the entire page needs to be erased again. If an 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 guaranteed.
  • a space is allocated in the Flash memory as a power-off protection zone, which is used to record the backup data of the relevant write operations, so as to restore the relevant backup data after the power is turned off.
  • the existing power-down protection area often adopts the page backup operation mechanism.
  • the relevant backup data is written to the fixed Flash page in advance, and then the Flash page where the target data is located is erased and written, and then the relevant data page of the backup area is executed after completion. erasure.
  • the power-down protection zone has the largest number of erasures and the largest erasing pressure, which will limit the service life of the entire Flash memory to the service life of the power-down protection zone.
  • the present invention mainly provides a flash data power-down protection method and device, which are used to solve the problem that the actual service life of a product is reduced due to the existing Flash data power-down protection method.
  • an embodiment provides a flash data power-down protection method for an electronic device, the electronic device includes a Flash memory, and the Flash memory is divided into a code area, a data area, and a power-down protection area, the code area is used to store code data, the data area is used to store file system data and user data, and the power-down protection zone is used to back up data; the method includes:
  • a random number is generated, and according to the generated random number, a page is selected from the power-down protected area as the starting page of the backup area for the next write operation.
  • the method further includes:
  • 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 start page of the backup area for the next write operation.
  • the backup area includes a first storage area and a second storage area, and the first storage area is used to store the first preset mark and the target address pointed to by the atomic write operation and The affected data range, the second storage area is used to back up the page data affected by the atomic write operation, the first preset mark is used to indicate that the write operation is an atomic write; the data to be backed up is written into the current Backup area, including:
  • the data page that meets the preset condition is a data page with the first preset mark
  • performing data recovery according to the backup area indicated by the data page that meets the preset condition includes:
  • the backup data stored in the second storage area of the backup area is restored page by page to the target page.
  • the clearing the data backed up in the current backup area includes: erasing the content in the first storage area of the current backup area.
  • the backup area includes a third storage area, a fourth storage area, and a fifth storage area
  • the third storage area is used to store the second preset mark
  • the third storage area is used to store the second preset mark.
  • the four storage areas are used to record all target page addresses that need to be backed up in the transactional write operation
  • the fifth storage area is used to back up the page data affected by the transactional write operation
  • the second preset mark is used to indicate that the write operation is a transactional write operation
  • the fourth storage area includes a plurality of parameter pages
  • the writing the data to be backed up into the current backup area includes:
  • the data page that meets the preset condition is a data page with the second preset mark
  • performing data recovery according to the backup area indicated by the data page that meets the preset condition includes:
  • the backup data stored in the fifth storage area of the backup area is restored page by page to the target page corresponding to the target address.
  • the clearing the data backed up in the current backup area includes: erasing the content in the third storage area of the current backup area.
  • an embodiment provides an electronic device, comprising:
  • the processor is configured to implement the Flash data power failure protection method according to any one of the first aspect above by executing the program stored in the memory.
  • an embodiment provides a computer-readable storage medium, including a program that can be executed by a processor to implement the Flash data power failure protection method according to any one of the above-mentioned first aspect.
  • the method includes: when the electronic device is powered on, traversing the power failure protection zone, searching for data pages that meet preset conditions, and the data pages that meet the preset conditions are backup areas If there is a data page that meets the preset conditions, data recovery is performed according to the backup area indicated by the data page that meets the preset conditions, the data backed up in the current backup area is cleared, and the current backup area is terminated.
  • the logical next page is used as the starting page of the backup area for the next write operation; if there is no data page that meets the preset conditions, a random number is generated, and a page is selected from the power-down protection area as the next page according to the generated random number.
  • the starting page of the backup area for write operations On the premise of ensuring data integrity, the erasing times of each data page in the power-off protection zone tend to be the same, which improves the use efficiency of the power-off protection zone and helps to improve the service life of the product.
  • Embodiment 1 is a schematic flowchart of Embodiment 1 of a Flash data power-down protection method provided by an embodiment of the present invention
  • FIG. 2 is a schematic structural diagram of a power-down protection zone provided by an embodiment of the present invention.
  • Embodiment 3 is a schematic flowchart of Embodiment 2 of a Flash data power-down protection method provided by an embodiment of the present invention
  • FIG. 4 is a schematic structural diagram of another power-down protection zone provided by an embodiment of the present invention.
  • Embodiment 3 is a schematic flowchart of Embodiment 3 of a flash data power-down protection method provided by an embodiment of the present invention
  • FIG. 6 is a schematic structural diagram of another power-down protection zone provided by an embodiment of the present invention.
  • FIG. 7 is a schematic flowchart of Embodiment 4 of a flash data power-down protection method provided by an embodiment of the present invention.
  • connection and “connection” mentioned in this application, unless otherwise specified, include both direct and indirect connections (connections).
  • the existing power-down protection area often adopts the page backup operation mechanism, when the NVM operation is performed, the relevant backup data is written to the fixed Flash page in advance, and then the Flash page where the target data is located is erased and written, and then the backup area related data is completed. Erase of pages. However, limited by the process, the erasing life of the Flash page is limited. As a common area for all NVM operations, the power-down protection zone has the largest number of erasures and the largest erasing pressure, which will limit the service life of the entire Flash memory to the service life of the power-down protection zone. In order to solve the problem of reducing the actual service life of the product caused by the existing Flash data power-down protection method, embodiments of the present invention provide a Flash data power-down protection method and device, which will be described in detail below.
  • COS Card Operate System
  • COS Card Operate System
  • the smart card operating system developed directly on the security chip usually refers to the general or industrial operating system developed based on the underlying chip capabilities and interfaces in the embedded security chip industry, such as the telecommunications industry, the financial industry, etc., Or a generic version that scales well.
  • RAM Random Access Memory
  • main memory is the internal memory that directly exchanges data with the CPU. It can be read and written at any time (except when flushing), is fast, and is often used as a temporary data storage medium for the operating system or other running programs. When RAM is working, information can be written (stored in) or read out (extracted) from any specified address at any time.
  • Read-Only Memory, ROM read-only memory
  • RAM is used in computers and digital systems to temporarily store programs, data, and intermediate results. This mainly refers to the running memory provided in the security chip.
  • NVM Non-volatile memory, non-volatile memory, has the characteristics of non-volatile, byte-by-byte access, high storage density, low energy consumption, and its read and write performance is close to dynamic random access memory (Dynamic random access memory). Random Access Memory, DRAM), but the read and write speed is asymmetric and the life is limited. This mainly refers to the storage provided by the security chip that can perform data persistence.
  • Flash A kind of non-volatile memory, data can be maintained for many years in the case of passive, mainly divided into NAND/NOR two. Generally, data writing needs to be erased first. Most of them are page-erase and page-write mechanisms, and some support page-erase word writing or byte writing. However, the number of erasing of each page is protected by a minimum number of times. Exceeding the number of protection times cannot ensure whether the data can be erased and written normally. This feature directly limits the life of the Flash page. Upper-layer applications must consider two characteristics of page erasure mechanism and life limit when designing storage solutions.
  • Java It is an object-oriented programming language. It not only absorbs various advantages of C++ language, but also abandons the incomprehensible concepts of multiple inheritance and pointers in C++. Therefore, Java language has two characteristics of powerful functions and ease of use. As a representative of static object-oriented programming language, Java language perfectly implements object-oriented theory, allowing programmers to perform complex programming in an elegant way of thinking. Java has the characteristics of simplicity, object orientation, distribution, robustness, security, platform independence and portability, multithreading, and dynamism. Java can write desktop applications, Web site applications, distributed systems and embedded system applications.
  • JavaCard Technology Provides a secure environment for applications running on smart cards (security chips) and other devices with very limited memory and processing power. Multiple applications can be deployed on a single card, and new applications can be added to the end user even after the card is released. Applications written in the Java programming language can run securely on cards from different vendors. is the leading open interoperable platform for 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 of C language that has nothing to do with Java, JavaCard, and JavaApplet.
  • FIG. 1 is a schematic flowchart of Embodiment 1 of a flash data power-down protection method provided by an embodiment of the present invention. As shown in FIG. 1 , the method of this embodiment may include:
  • the execution subject of the embodiment of the present invention is an electronic device.
  • the electronic device may include a Flash memory, and the Flash memory may be divided into a code area, a data area, and a power-down protection area, wherein the code area is used to store code data, The data area is used to store file system data and user data, and the power-down protection area is used to back up data.
  • the above-mentioned data pages that meet the preset conditions are the starting pages of the backup area, and are compatible with atomic write and transactional write functions.
  • the so-called atomic write means that the operation result of a single data write operation is either in the state of successful completion of the write, or in the state of unwritten, and other intermediate states are not allowed; the so-called transaction write refers to the end of the transaction protection.
  • the write data operations during this period are either in a state of being completely written or in a state of not being rewritten, and some data is not allowed to be rewritten.
  • the backup area stores the data operation content that was not completed last time, so it is necessary to perform data recovery on the backup area indicated by the data page that meets the preset condition.
  • the current backup data included in the start page of the backup area to the end page of the backup area is restored, that is, a data restoration of the backup area is completed. After the data is restored, the data backed up in the current backup area is cleared so that the current backup area can be used again later.
  • FIG. 2 is a schematic structural diagram of a power-down protection area provided by an embodiment of the present invention. As shown in FIG. 2 , if the current backup area is the backup area 1 in FIG. 2 , the logical next page of the termination page of the backup area 1 The page is used as the starting page of the backup area 2 of the next write operation; if the current backup area is the backup area 2 in FIG.
  • the logical next page of the end page of the backup area 2 is used as the starting page of the backup area 3 of the next write operation.
  • the logical next page of the end page of backup area 4 is used as the start page of backup area 1 for the next write operation.
  • the erasing life of the power-off protection zone in the prior art is 10,000 times
  • the power-off protection zone shown in Figure 2 after the power-off protection zone is divided into four backup zones, the The erasing life is 10,000 times, then the erasing life of the power-off protection zone is 40,000 times.
  • a random number can be generated by starting the random number generator or calling the relevant random number generating algorithm interface, and selecting a page from the power-off protection zone according to the generated random number as the starting page of the backup area for the next write operation , so that the backup area for the next write operation is selected from the power-off protection zone with the same probability.
  • the flash data power-down protection method traverses the power-down protection zone when the electronic device is powered on, and searches for data pages that meet the preset conditions, and the data pages that meet the preset conditions are the starting pages of the backup area. ; If there are data pages that meet the preset conditions, data recovery is performed according to the backup area indicated by the data pages that meet the preset conditions, the data backed up in the current backup area is cleared, and the logical next page of the current backup area is terminated.
  • FIG. 3 is a schematic flowchart of the second embodiment of a method for power-down protection of Flash data provided by the embodiment of the present invention. As shown in FIG. 3, after performing S102 or S103, the method of this embodiment may include:
  • the target address, content and length of the data to be written can be passed in through the application layer.
  • S202 Determine the data to be backed up according to the target address and length of the data to be written.
  • 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.
  • 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 by page erasing.
  • the content of the data to be written may be written into the target address page by page.
  • S205 Clear the data backed up in the current backup area, and use the logical next page of the end page of the current backup area as the start page of the backup area for the next write operation.
  • the flash data power-down protection method receives the target address, content and length of the data to be written; determines the data to be backed up according to the target address and length of the data to be written; writes the data to be backed up Current backup area; write the content of the data to be written into the target address; clear the data backed up in the current backup area, and use the logical next page of the current backup area termination page as the start page of the backup area for the next write operation,
  • the number of write operations of each data page in the power-off protection zone tends to be the same, which improves the use efficiency of the power-off protection zone and helps to improve the service life of the product.
  • FIG. 4 is a schematic structural diagram of another power-down protection area provided by an embodiment of the present invention.
  • the backup area includes a first storage area and a second storage area.
  • a storage area is used to store the first preset mark, the target address pointed to by the atomic write operation and the affected data range, the second storage area is used to back up the page data affected by the atomic write operation, and the first preset mark is used to indicate the write operation.
  • FIG. 5 is a schematic flowchart of Embodiment 3 of a flash data power-down protection method provided by an embodiment of the present invention. As shown in FIG. 5 , the method in this embodiment may include: :
  • S302 Determine the data to be backed up according to the target address and length of the data to be written.
  • 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 by page-erase page writing. As shown in FIG. 4 , for example, the data to be backed up may be written into the second storage area of the backup area 1 page by page.
  • the first preset mark, the target address and the length may be written into the first storage area of the backup area by means of page erasing and page writing. As shown in FIG. 4 , for example, the first preset mark, the target address and the length can be written into the first storage area of the backup area 1 .
  • the content of the data to be written may be written into the target address page by page.
  • S306 Clear the data backed up in the current backup area, and use the logical next page of the end page of the current backup area as the start page of the backup area for the next write 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 writing the content of the data to be written into the target address, erase the first preset The tag and the target address pointed to by the atomic write operation and the range of data affected. 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.
  • the write operation is atomic write
  • the data to be backed up is written into the second storage area of the backup area
  • the first preset mark, the target address and the length are written into The first storage area of the backup area.
  • the data backed up 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 starting page of the backup area for the next write operation, so that The number of write operations of each data page in the power-off protection zone tends to be the same, which improves the use efficiency of the power-off protection zone and helps to improve the service life of the product.
  • Flash page is 512 bytes, which implements the Native COS platform and can provide the atomic write function, that is, to protect a single write operation. If the flash page data is accidentally powered off during erasing or writing, the data may be in an incomplete state of partial erasing or partial writing, and the integrity and correctness of the data cannot be guaranteed. In order to ensure that the data is successfully written, the following will describe how to restore the data when the electronic device accidentally loses power during the steps in the third embodiment:
  • the The first storage area of the backup area obtains the target address and length; the target page is determined according to the target address and length; the backup data stored in the second storage area of the backup area is restored page by page to the target page, and the first storage area of the current backup area is erased.
  • a random number can be generated, and according to the generated random number, a page is selected from the power-down protection area as the starting page of the backup area for the next write operation, and the re-determined backup area can be used to store the next page. Backup data for write operations.
  • the target address and length can be obtained from the first storage area of the backup area; the target page is determined according to the target address and length; the data stored in the second storage area of the backup area The backup data is restored page by page to the target page, the content in the first storage area of the current backup area is erased, and the logical next page of the end page of the current backup area is used as the start page of the backup area for the next write operation.
  • FIG. 6 is a schematic structural diagram of another power-down protection area provided by an embodiment of the present invention.
  • the backup area includes a third storage area, a fourth storage area, and a fifth storage area. area, where the third storage area is used to store the 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, and the fifth storage area is used to back up the page data affected by the transaction write operation , the second preset flag is used to indicate that the write operation is a transactional write, and the fourth storage area includes multiple parameter pages
  • FIG. 7 is a schematic flowchart of Embodiment 4 of a flash data power-down protection method provided by an embodiment of the present invention. As shown in FIG. 7 , the method in this embodiment may include :
  • S402 Determine the data to be backed up according to the target address and length of the data to be written.
  • 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 by page-erase page writing. As shown in FIG. 6 , for example, the data to be backed up may be written into the fifth storage area of the backup area 1 page by page.
  • S404 Determine the target parameter page from the plurality of parameter pages according to the times counter.
  • the parameter page included in the fourth storage area is a multi-backup mechanism.
  • two pages can be used as parameter pages: denoted as parameter page 1 and parameter page 2.
  • the two pages can be used alternately, and the content of each page can include: effective Mark, update times counter, number N of current backup addresses, target address 1, target address 2... target address N, check digit, etc.
  • the current update times counter is odd
  • parameter page 1 is used as the target parameter page
  • parameter page 2 is used as the target parameter page.
  • all target addresses in the current and previous writing process of the transaction can be written into the target parameter page by page erasing, so that when the electronic device is accidentally powered off, at least the parameter page can be obtained. All target addresses in the previous write process of this transaction. As shown in FIG. 6 , for example, all target addresses in the current and previous writing process of the transaction can be written into the fourth storage area of the backup area 1 .
  • the second preset mark may be written into the third storage area of the backup area by means of page erasing and page writing. As shown in FIG. 6 , for example, the second preset mark may be written into the third storage area of the backup area 1 .
  • the content of the data to be written may be written into the target address page by page.
  • S408 Clear the data backed up in the current backup area, and use the logical next page of the end page of the current backup area as the start page of the backup area for the next write 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 writing the content of the data to be written into the target address, erase the second preset mark. And, as shown in FIG. 6 , the logical next page of the end page of the current backup area 1 is used as the start page of the backup area 2 for the next write operation.
  • the flash data power-down protection method provided by the embodiment of the present invention, when the write operation is a transaction write, the data to be backed up is written into the fifth storage area of the backup area, and the target parameter page is determined from a plurality of parameter pages according to the times counter, Write all target addresses in the current and previous writing process of the transaction into the target parameter page, update the times counter, and write the second preset mark into the third storage area of the backup area.
  • the data to be backed up all target addresses in the current and previous writing process of the transaction, and the second preset mark can be written into different storage areas of the backup area.
  • the data backed up 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 starting page of the backup area for the next write operation, so that The number of write operations of each data page in the power-off protection zone tends to be the same, which improves the use efficiency of the power-off protection zone and helps to improve the service life of the product.
  • the size of a Flash page is 512 bytes, which implements the JavaCard COS platform and can provide atomic write and transaction write functions. Among them, the atomic write operation is implemented in the same way as the aforementioned Native platform, and will not be repeated here. The implementation process of transaction writing is mainly described here. Because the write operation of the upper-layer application has no atomic write once the transaction protection is enabled, the transaction protection and the atomic write share the same power-down protection area.
  • 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 transaction initiation state.
  • the NVM management layer can just erase the content in the third storage area and the related RAM state.
  • the latest parameter page can be determined from the multiple parameter pages included in the fourth storage area of the backup area; the target address corresponding to the target page is taken out one by one from the latest parameter page;
  • the backup data stored in the fifth storage area of the backup area is restored page by page to the target page corresponding to the target address, the second preset mark in the third storage area of the current backup area is erased, and the terminating page of the current backup area is deleted.
  • the logical next page is used as the starting page of the backup area for the next write operation.
  • the parameter page with the largest amount of data may be determined as the latest parameter page from the plurality of parameter pages included in the fourth storage area of the backup area, or the last written parameter page may be determined as the latest parameter page.
  • the latest parameter page can be determined from the multiple parameter pages included in the fourth storage area of the backup area; from the latest parameter page Take out the target addresses corresponding to the target pages one by one; restore the backup data stored in the fifth storage area of the backup area to the target page corresponding to the target address one by one, and erase the second preset mark in the third storage area of the current backup area , and the logical next page of the end page of the current backup area is used as the start page of the backup area for the next write operation.
  • the embodiment of the present invention also provides an electronic device, the electronic device may include: a memory for storing a program; a processor for executing the The program stored in the memory is used to implement the Flash data power-down protection method provided by the embodiment of the present invention.
  • the embodiment of the present invention further provides a computer-readable storage medium, the computer-readable storage medium includes a program, and the program can be executed by a processor to The Flash data power-down protection method provided by the embodiment of the present invention is implemented.
  • 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 on a general purpose computer, special purpose computer or other programmable data processing apparatus to form a machine such that the instructions executed on the computer or other programmable data processing apparatus may generate means for implementing the specified functions.
  • Computer program instructions may also be stored in a computer-readable memory that instructs a computer or other programmable data processing device to operate in a particular manner, such that the instructions stored in the computer-readable memory form a piece of Articles of manufacture, including implementing means for implementing specified functions.
  • Computer program instructions may also be loaded on a computer or other programmable data processing device to perform a series of operational steps on the computer or other programmable device to produce a computer-implemented process such that a process executed on the computer or other programmable device Instructions may provide steps for implementing specified functions.
  • the term “comprising” and any other variations thereof are non-exclusive inclusion, such that a process, method, article or device that includes a list of elements includes not only those elements, but also not expressly listed or part of the process , method, system, article or other elements of a device.
  • the term “coupled” and any other variations thereof refer to physical connections, electrical connections, magnetic connections, optical connections, communication connections, functional connections, and/or any other connection.

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Human Computer Interaction (AREA)
  • Quality & Reliability (AREA)
  • Techniques For Improving Reliability Of Storages (AREA)

Abstract

一种Flash数据掉电保护方法及设备,该方法包括:在电子设备上电时,遍历掉电保护区,查找符合预设条件的数据页,符合预设条件的数据页为备份区的起始页;若存在符合预设条件的数据页,则根据符合预设条件的数据页所指示的备份区进行数据恢复,清除当前备份区中备份的数据,并将当前备份区终止页的逻辑下一页作为下次写操作的备份区的起始页;若不存在符合预设条件的数据页,则生成随机数,并依据生成的随机数从掉电保护区选取一页作为下次写操作的备份区的起始页。在确保数据完整性的前提下,使得掉电保护区内各数据页的擦除次数趋于相同,提高了掉电保护区的使用效率,有助于提高产品的使用寿命。

Description

Flash数据掉电保护方法及设备 技术领域
本发明涉及存储技术领域,具体涉及一种Flash数据掉电保护方法及设备。
背景技术
闪存(Flash)作为一种非易失性存储器(Non-Volatile Memory,NVM),以容量大、价格低廉等优势得到了广泛的应用,如智能卡操作系统(Card Operate System,COS)的大部分底层芯片都采用Flash作为存储介质。而大部分Flash只支持页擦页写,所谓页擦页写就是所有数据在写入前都必须将原有整页Flash数据擦除,然后才能将新数据写入,如果需要再次写入新数据则需要整页再次擦除。若在擦除或写入时发生意外掉电,则数据可能处于部分擦除或部分写入的不完整态,无法确保数据的完整性。
为了确保数据的完整性,在Flash存储器中分配一块空间作为掉电保护区,用于记录相关写操作的备份数据,以便在掉电后用于恢复相关备份数据。现有掉电保护区常采用页备份操作机制,在进行NVM操作时对固定Flash页提前写入相关备份数据,然后再对目标数据所在Flash页进行擦写,完成后再进行备份区相关数据页的擦除。而受限于工艺,Flash页的擦除寿命都是有限的。掉电保护区作为所有NVM操作公用的区域,其擦除次数是最多的,擦除压力是最大的,这将使得整个Flash存储器的使用寿命基本受限于掉电保护区的寿命。
综上所述,现有Flash数据掉电保护方法大大降低了产品的实际使用寿命。
技术问题
本发明主要提供一种Flash数据掉电保护方法及设备,用于解决现有Flash数据掉电保护方法导致产品的实际使用寿命降低的问题。
技术解决方案
根据第一方面,一种实施例中提供一种Flash数据掉电保护方法,用于电子设备,所述电子设备中包括Flash存储器,所述Flash存储器内划分有代码区、数据区及掉电保护区,所述代码区用于存放代码数据,所述数据区用于存放文件系统数据及用户数据,所述掉电保护区用于备份数据;所述方法包括:
在所述电子设备上电时,遍历所述掉电保护区,查找符合预设条件的数据页,所述符合预设条件的数据页为备份区的起始页;
若存在符合预设条件的数据页,则根据所述符合预设条件的数据页所指示的备份区进行数据恢复,清除当前备份区中备份的数据,并将当前备份区终止页的逻辑下一页作为下次写操作的备份区的起始页;
若不存在符合预设条件的数据页,则生成随机数,并依据生成的随机数从所述掉电保护区选取一页作为下次写操作的备份区的起始页。
可选的,所述方法还包括:
接收待写入数据的目标地址、内容及长度;
根据所述待写入数据的目标地址及长度确定待备份的数据;
将所述待备份的数据写入当前备份区;
将所述待写入数据的内容写入所述目标地址;
清除当前备份区中备份的数据,并将当前备份区终止页的逻辑下一页作为下次写操作的备份区的起始页。
可选的,若写操作为原子写,则所述备份区包括第一存储区域和第二存储区域,所述第一存储区域用于存储第一预设标记以及原子写操作指向的目标地址以及影响的数据范围,所述第二存储区域用于备份原子写操作影响的页数据,所述第一预设标记用于指示写操作为原子写;所述将所述待备份的数据写入当前备份区,包括:
将所述待备份的数据写入所述备份区的第二存储区域;
将所述第一预设标记、所述目标地址及所述长度写入所述备份区的第一存储区域。
可选的,所述符合预设条件的数据页为存在所述第一预设标记的数据页,所述根据所述符合预设条件的数据页所指示的备份区进行数据恢复,包括:
从所述备份区的第一存储区域获取所述目标地址及所述长度;
根据所述目标地址及所述长度确定目标页;
将所述备份区的第二存储区域中存储的备份数据逐页还原到所述目标页中。
可选的,所述清除当前备份区中备份的数据,包括:擦除当前备份区第一存储区域中的内容。
可选的,若写操作为事务写,则所述备份区包括第三存储区域、第四存储区域和第五存储区域,所述第三存储区域用于存储第二预设标记,所述第四存储区域用于记录事务写操作中所有需要备份的目标页地址,所述第五存储区域用于备份事务写操作影响的页数据,所述第二预设标记用于指示写操作为事务写,所述第四存储区域包括多个参数页;所述将所述待备份的数据写入当前备份区包括:
将所述待备份的数据写入所述备份区的第五存储区域;
根据次数计数器从多个参数页中确定目标参数页;
将当前以及之前该事务写过程中的所有目标地址写入所述目标参数页,并更新所述次数计数器;
将所述第二预设标记写入所述备份区的第三存储区域。
可选的,所述符合预设条件的数据页为存在所述第二预设标记的数据页,所述根据所述符合预设条件的数据页所指示的备份区进行数据恢复,包括:
从所述备份区的第四存储区域包括的多个参数页中确定出最新的参数页;
从所述最新的参数页中逐一取出对应目标页的目标地址;
将所述备份区的第五存储区域中存储的备份数据逐页还原到所述目标地址对应的目标页中。
可选的,所述清除当前备份区中备份的数据,包括:擦除当前备份区第三存储区域中的内容。
根据第二方面,一种实施例中提供一种电子设备,包括:
存储器,用于存储程序;
处理器,用于通过执行所述存储器存储的程序以实现上述第一方面任一项所述的Flash数据掉电保护方法。
根据第三方面,一种实施例中提供一种计算机可读存储介质,包括程序,所述程序能够被处理器执行以实现上述第一方面任一项所述的Flash数据掉电保护方法。
有益效果
依据上述实施例的Flash数据掉电保护方法及设备,该方法包括:在电子设备上电时,遍历掉电保护区,查找符合预设条件的数据页,符合预设条件的数据页为备份区的起始页;若存在符合预设条件的数据页,则根据符合预设条件的数据页所指示的备份区进行数据恢复,清除当前备份区中备份的数据,并将当前备份区终止页的逻辑下一页作为下次写操作的备份区的起始页;若不存在符合预设条件的数据页,则生成随机数,并依据生成的随机数从掉电保护区选取一页作为下次写操作的备份区的起始页。在确保数据完整性的前提下,使得掉电保护区内各数据页的擦除次数趋于相同,提高了掉电保护区的使用效率,有助于提高产品的使用寿命。
附图说明
图1为本发明实施例提供的一种Flash数据掉电保护方法的实施例一的流程示意图;
图2为本发明实施例提供的一种掉电保护区的结构示意图;
图3为本发明实施例提供的一种Flash数据掉电保护方法的实施例二的流程示意图;
图4为本发明实施例提供的另一种掉电保护区的结构示意图;
图5为本发明实施例提供的一种Flash数据掉电保护方法的实施例三的流程示意图;
图6为本发明实施例提供的又一种掉电保护区的结构示意图;
图7为本发明实施例提供的一种Flash数据掉电保护方法的实施例四的流程示意图。
本发明的实施方式
下面通过具体实施方式结合附图对本发明作进一步详细说明。其中不同实施方式中类似元件采用了相关联的类似的元件标号。在以下的实施方式中,很多细节描述是为了使得本申请能被更好的理解。然而,本领域技术人员可以毫不费力的认识到,其中部分特征在不同情况下是可以省略的,或者可以由其他元件、材料、方法所替代。在某些情况下,本申请相关的一些操作并没有在说明书中显示或者描述,这是为了避免本申请的核心部分被过多的描述所淹没,而对于本领域技术人员而言,详细描述这些相关操作并不是必要的,他们根据说明书中的描述以及本领域的一般技术知识即可完整了解相关操作。
另外,说明书中所描述的特点、操作或者特征可以以任意适当的方式结合形成各种实施方式。同时,方法描述中的各步骤或者动作也可以按照本领域技术人员所能显而易见的方式进行顺序调换或调整。因此,说明书和附图中的各种顺序只是为了清楚描述某一个实施例,并不意味着是必须的顺序,除非另有说明其中某个顺序是必须遵循的。
本文中为部件所编序号本身,例如“第一”、“第二”等,仅用于区分所描述的对象,不具有任何顺序或技术含义。而本申请所说“连接”、“联接”,如无特别说明,均包括直接和间接连接(联接)。
由于现有掉电保护区常采用页备份操作机制,在进行NVM操作时对固定Flash页提前写入相关备份数据,然后再对目标数据所在Flash页进行擦写,完成后再进行备份区相关数据页的擦除。而受限于工艺,Flash页的擦除寿命都是有限的。掉电保护区作为所有NVM操作公用的区域,其擦除次数是最多的,擦除压力是最大的,这将使得整个Flash存储器的使用寿命基本受限于掉电保护区的寿命。为了解决现有Flash数据掉电保护方法导致产品的实际使用寿命降低的问题,本发明实施例提供了一种Flash数据掉电保护方法及设备,以下分别进行详细说明。
首先,对于本发明中所涉及到的一些术语进行简单说明:
COS:Card Operate System,指在安全芯片上直接进行开发的智能卡操作系统,通常指嵌入式安全芯片行业上基于底层芯片能力和接口开发的通用或者行业性操作系统,例如电信行业、金融行业等,或者通用版本可以进行良好扩展。
RAM:Random Access Memory,随机存取存储器,也叫主存,是与CPU直接交换数据的内部存储器。它可以随时读写(刷新时除外),而且速度很快,通常作为操作系统或其他正在运行中的程序的临时数据存储介质。RAM工作时可以随时从任何一个指定的地址写入(存入)或读出(取出)信息。它与只读存储器(Read-Only Memory,ROM)的最大区别是数据的易失性,即一旦断电所存储的数据将随之丢失。RAM在计算机和数字系统中用来暂时存储程序、数据和中间结果。这里主要指安全芯片中提供的运行内存。
NVM:Non-volatile memory,非易失存储器,具有非易失、按字节存取、存储密度高、低能耗等特性,其读写性能接近动态随机存取存储器(Dynamic Random Access Memory,DRAM),但读写速度不对称,寿命有限。这里主要指安全芯片提供的可以进行数据持久化的存储。
Flash:一种非易失性存储器,数据在无源的情况下也可保持多年,主要分为NAND/NOR两种。一般写入数据都需要先进行擦除操作,多为页擦页写机制,部分支持页擦字写或字节写入。但每页的擦除次数有最低次数保护,超出保护次数无法确保数据是否能正常擦除和写入,这一特性直接限制了Flash页寿命。上层应用在设计存储方案时必须考虑页擦机制和寿命限制两个特性。
Java:是一门面向对象编程语言,不仅吸收了C++语言的各种优点,还摒弃了C++里难以理解的多继承、指针等概念,因此Java语言具有功能强大和简单易用两个特征。Java语言作为静态面向对象编程语言的代表,极好地实现了面向对象理论,允许程序员以优雅的思维方式进行复杂的编程。Java具有简单性、面向对象、分布式、健壮性、安全性、平台独立与可移植性、多线程、动态性等特点。Java可以编写桌面应用程序、Web网站应用程序、分布式系统和嵌入式系统应用程序等。
JavaCard技术:为那些在智能卡(安全芯片)以及其他内存和处理能力非常有限的设备上运行的应用程序提供了一个安全的环境。一张卡上可以部署多个应用程序,甚至在卡发售给最终用户后还可以向其添加新应用程序。使用Java编程语言编写的应用程序可以在不同供应商的卡上安全运行。是适用于智能卡和安全令牌的领先的开放互操作平台。各种JavaCard规范为跨平台和跨供应商的小程序互操作性提供了基础。
Native:一般指用C语言实现和Java、JavaCard、JavaApplet无关的技术设计和实现。
图1为本发明实施例提供的一种Flash数据掉电保护方法的实施例一的流程示意图,如图1所示,本实施例的方法可以包括:
S101,在电子设备上电时,遍历掉电保护区,查找符合预设条件的数据页。
本发明实施例的执行主体为电子设备,具体的,该电子设备中可以包括Flash存储器,Flash存储器内可以划分有代码区、数据区及掉电保护区,其中,代码区用于存放代码数据,数据区用于存放文件系统数据及用户数据,掉电保护区用于备份数据。
上述符合预设条件的数据页为备份区的起始页,可以兼容原子写和事务写的功能。所谓原子写是指进行单次写数据操作的操作结果要么处于成功完成写入的状态,要么处于未写入的状态,不允许出现其他中间状态;所谓事务写是指在启动事务保护后到结束事务保护前,这个期间的写数据操作要么处于全部被写入的状态,要么全部处于未改写的状态,不允许出现部分数据被改写的情况。
S102,若存在符合预设条件的数据页,则根据符合预设条件的数据页所指示的备份区进行数据恢复,清除当前备份区中备份的数据,并将当前备份区终止页的逻辑下一页作为下次写操作的备份区的起始页。
其中,若存在符合预设条件的数据页,则表征备份区存储着上次未完成的数据操作内容,因此需要对符合预设条件的数据页所指示的备份区进行数据恢复,这里对备份区的起始页到备份区的终止页所包括的当前备份数据进行数据恢复,即完成了一次备份区的数据恢复。待数据恢复后,将当前备份区中备份的数据清除,以便之后对于该当前备份区的再次使用。
并且,将当前备份区终止页的逻辑下一页作为下次写操作的备份区的起始页,这里逻辑下一页指的是当前备份区与下一次进行写操作的备份区的首尾相接处。例如,图2为本发明实施例提供的一种掉电保护区的结构示意图,如图2所示,若当前备份区为图2中的备份区1,则备份区1终止页的逻辑下一页作为下次写操作的备份区2的起始页;若当前备份区为图2中的备份区2,则备份区2终止页的逻辑下一页作为下次写操作的备份区3的起始页;若当前备份区为图2中的备份区3,则备份区3终止页的逻辑下一页作为下次写操作的备份区4的起始页;若当前备份区为图2中的备份区4,则备份区4终止页的逻辑下一页作为下次写操作的备份区1的起始页。假设现有技术中的掉电保护区的擦除寿命是一万次,而对于图2所示的掉电保护区,将掉电保护区划分为四个备份区后,每一备份区的擦除寿命是一万次,那么该掉电保护区的擦除寿命即为四万次。
S103,若不存在符合预设条件的数据页,则生成随机数,并依据生成的随机数从掉电保护区选取一页作为下次写操作的备份区的起始页。
若不存在符合预设条件的数据页,则表征备份区未存储合法的备份数据,因此需要在掉电保护区中确定出下次写操作的备份区。具体的,可以通过启动随机数发生器或者调用相关的随机数生成算法接口,生成随机数,并依据生成的随机数从掉电保护区选取一页作为下次写操作的备份区的起始页,使得从掉电保护区中以相同的概率选取下次写操作的备份区。
本发明实施例提供的Flash数据掉电保护方法,通过在电子设备上电时,遍历掉电保护区,查找符合预设条件的数据页,符合预设条件的数据页为备份区的起始页;若存在符合预设条件的数据页,则根据符合预设条件的数据页所指示的备份区进行数据恢复,清除当前备份区中备份的数据,并将当前备份区终止页的逻辑下一页作为下次写操作的备份区的起始页;若不存在符合预设条件的数据页,则生成随机数,并依据生成的随机数从掉电保护区选取一页作为下次写操作的备份区的起始页。在确保数据完整性的前提下,使得掉电保护区内各数据页的擦除次数趋于相同,提高了掉电保护区的使用效率,有助于提高产品的使用寿命。
通过上述实施例一,电子设备完成了掉电保护启动操作,在上述实施例一的基础上,图3为本发明实施例提供的一种Flash数据掉电保护方法的实施例二的流程示意图,如图3所示,在执行S102或者S103之后,本实施例的方法可以包括:
S201,接收待写入数据的目标地址、内容及长度。
具体实现时,可以通过应用层传入待写入数据的目标地址、内容及长度。
S202,根据待写入数据的目标地址及长度确定待备份的数据。
具体的,根据待写入数据的目标地址及长度计算出备份区的起始页地址及范围。
S203,将待备份的数据写入当前备份区。
具体实现时,可以将待备份的数据逐页写入当前备份区,也可以采用页擦页写的方式将待备份的数据写入当前备份区。
S204,将待写入数据的内容写入目标地址。
具体实现时,可以将待写入数据的内容逐页写入目标地址。
S205,清除当前备份区中备份的数据,并将当前备份区终止页的逻辑下一页作为下次写操作的备份区的起始页。
本发明实施例提供的Flash数据掉电保护方法,通过接收待写入数据的目标地址、内容及长度;根据待写入数据的目标地址及长度确定待备份的数据;将待备份的数据写入当前备份区;将待写入数据的内容写入目标地址;清除当前备份区中备份的数据,并将当前备份区终止页的逻辑下一页作为下次写操作的备份区的起始页,使得掉电保护区内各数据页的写操作次数趋于相同,提高了掉电保护区的使用效率,有助于提高产品的使用寿命。
图4为本发明实施例提供的另一种掉电保护区的结构示意图,如图4所示,若写操作为原子写,则备份区包括第一存储区域和第二存储区域,其中,第一存储区域用于存储第一预设标记以及原子写操作指向的目标地址以及影响的数据范围,第二存储区域用于备份原子写操作影响的页数据,第一预设标记用于指示写操作为原子写。
结合上述图4所示的掉电保护区,图5为本发明实施例提供的一种Flash数据掉电保护方法的实施例三的流程示意图,如图5所示,本实施例的方法可以包括:
S301,接收待写入数据的目标地址、内容及长度。
S302,根据待写入数据的目标地址及长度确定待备份的数据。
S303,将待备份的数据写入备份区的第二存储区域。
具体实现时,可以将待备份的数据逐页写入备份区的第二存储区域,也可以采用页擦页写的方式将待备份的数据写入备份区的第二存储区域。如图4所示,例如可以将待备份的数据逐页写入备份区1的第二存储区域。
S304,将第一预设标记、目标地址及长度写入备份区的第一存储区域。
具体实现时,可以采用页擦页写的方式将第一预设标记、目标地址及长度写入备份区的第一存储区域。如图4所示,例如可以将第一预设标记、目标地址及长度写入备份区1的第一存储区域。
S305,将待写入数据的内容写入目标地址。
具体的,可以将待写入数据的内容逐页写入目标地址。
S306,清除当前备份区中备份的数据,并将当前备份区终止页的逻辑下一页作为下次写操作的备份区的起始页。
其中,可以通过擦除当前备份区第一存储区域中的内容,达到清除当前备份区中备份的数据的目的,即,将待写入数据的内容写入目标地址后,擦除第一预设标记以及原子写操作指向的目标地址以及影响的数据范围。并且,如图4所示,将当前备份区1终止页的逻辑下一页作为下次写操作的备份区2的起始页。
本发明实施例提供的Flash数据掉电保护方法,当写操作为原子写时,将待备份的数据写入备份区的第二存储区域,并将第一预设标记、目标地址及长度写入备份区的第一存储区域。通过对备份区进行划分,可以将待备份的数据、第一预设标记、目标地址及长度写入备份区的不同存储区域。并且,将待写入数据的内容写入目标地址后,清除当前备份区中备份的数据,并将当前备份区终止页的逻辑下一页作为下次写操作的备份区的起始页,使得掉电保护区内各数据页的写操作次数趋于相同,提高了掉电保护区的使用效率,有助于提高产品的使用寿命。
下面以电子设备中包括CIU98M25芯片为例进行说明。Flash一页大小为512字节,实现Native COS平台,可以提供原子写功能,即保护单次写操作。由于Flash页数据在擦除或写入时如果发生意外掉电,数据可能处于部分擦除或部分写入的不完整态,无法确保数据的完整及正确性。为了确保数据被成功写入,下面将对电子设备在执行上述实施例三中的步骤发生意外掉电如何恢复数据进行说明:
当电子设备在执行S301-S303中任一步骤发生意外掉电,此时,由于尚未对待写入数据进行任何操作,因此电子设备的掉电不会影响到待写入数据,无需进行数据恢复。
当电子设备在执行S304时发生意外掉电,此时,若已将第一预设标记、目标地址及长度完整写入备份区的第一存储区域,则待电子设备重新上电后,可以从备份区的第一存储区域获取目标地址及长度;根据目标地址及长度确定目标页;将备份区的第二存储区域中存储的备份数据逐页还原到目标页中,擦除当前备份区第一存储区域中的内容,并将当前备份区终止页的逻辑下一页作为下次写操作的备份区的起始页;若未完整将第一预设标记、目标地址及长度写入备份区的第一存储区域,则可以生成随机数,并依据生成的随机数从掉电保护区选取一页作为下次写操作的备份区的起始页,该重新确定的备份区可以用于存储下次写操作的备份数据。
当电子设备在执行S305时发生意外掉电,此时,可以从备份区的第一存储区域获取目标地址及长度;根据目标地址及长度确定目标页;将备份区的第二存储区域中存储的备份数据逐页还原到目标页中,擦除当前备份区第一存储区域中的内容,并将当前备份区终止页的逻辑下一页作为下次写操作的备份区的起始页。
图6为本发明实施例提供的又一种掉电保护区的结构示意图,如图6所示,若写操作为事务写,则备份区包括第三存储区域、第四存储区域和第五存储区域,其中,第三存储区域用于存储第二预设标记,第四存储区域用于记录事务写操作中所有需要备份的目标页地址,第五存储区域用于备份事务写操作影响的页数据,第二预设标记用于指示写操作为事务写,第四存储区域包括多个参数页
结合上述图6所示的掉电保护区,图7为本发明实施例提供的一种Flash数据掉电保护方法的实施例四的流程示意图,如图7所示,本实施例的方法可以包括:
S401,接收待写入数据的目标地址、内容及长度。
S402,根据待写入数据的目标地址及长度确定待备份的数据。
S403,将待备份的数据写入备份区的第五存储区域。
具体实现时,可以将待备份的数据逐页写入备份区的第五存储区域,也可以采用页擦页写的方式将待备份的数据写入备份区的第五存储区域。如图6所示,例如可以将待备份的数据逐页写入备份区1的第五存储区域。
S404,根据次数计数器从多个参数页中确定目标参数页。
具体实现时,第四存储区域所包括的参数页为多备份机制,比如可以使用2页做参数页:记为参数页1、参数页2,两页可以交替使用,每页内容可以包含:有效标记、更新次数计数器、当前备份地址的个数N、目标地址1、目标地址2……目标地址N、校验位等。例如,当前更新次数计数器为奇数时,将参数页1作为目标参数页;当前更新次数计数器为偶数时,将参数页2作为目标参数页。
S405,将当前以及之前该事务写过程中的所有目标地址写入目标参数页,并更新次数计数器。
确定参数页后,可以将当前以及之前该事务写过程中的所有目标地址通过页擦页写的方式写入目标参数页,以便当电子设备发生意外掉电时,可以从参数页中至少获取到之前该事务写过程中的所有目标地址。如图6所示,例如可以将当前以及之前该事务写过程中的所有目标地址写入备份区1的第四存储区域。
S406,将第二预设标记写入备份区的第三存储区域。
具体实现时,可以采用页擦页写的方式将第二预设标记写入备份区的第三存储区域。如图6所示,例如可以将第二预设标记写入备份区1的第三存储区域。
S407,将待写入数据的内容写入目标地址。
具体的,可以将待写入数据的内容逐页写入目标地址。
S408,清除当前备份区中备份的数据,并将当前备份区终止页的逻辑下一页作为下次写操作的备份区的起始页。
其中,可以通过擦除当前备份区第三存储区域中的内容,达到清除当前备份区中备份的数据的目的,即,将待写入数据的内容写入目标地址后,擦除第二预设标记。并且,如图6所示,将当前备份区1终止页的逻辑下一页作为下次写操作的备份区2的起始页。
本发明实施例提供的Flash数据掉电保护方法,当写操作为事务写时,将待备份的数据写入备份区的第五存储区域,根据次数计数器从多个参数页中确定目标参数页,将当前以及之前该事务写过程中的所有目标地址写入目标参数页,并更新次数计数器,将第二预设标记写入备份区的第三存储区域。通过对备份区进行划分,可以将待备份的数据、当前以及之前该事务写过程中的所有目标地址和第二预设标记写入备份区的不同存储区域。并且,将待写入数据的内容写入目标地址后,清除当前备份区中备份的数据,并将当前备份区终止页的逻辑下一页作为下次写操作的备份区的起始页,使得掉电保护区内各数据页的写操作次数趋于相同,提高了掉电保护区的使用效率,有助于提高产品的使用寿命。
下面以电子设备中包括CIU98M25芯片为例进行说明。Flash一页大小为512字节,实现JavaCard COS平台,可以提供原子写和事务写功能。其中,原子写操作与前述Native平台相同实现,在次不再赘述。这里主要描述事务写的实现过程。由于上层应用的写操作一旦启用了事务保护则不再有原子写,所以事务保护与原子写共用同一片掉电保护区。
当处于事务启动过程时,应用层可以调用NVM管理层接口启动事务保护操作,NVM管理层用RAM变量存储事务启动状态。
当处于事务提交过程时,NVM管理层擦除第三存储区域中的内容及相关RAM状态即可。
当处于事务放弃过程时,可以从备份区的第四存储区域包括的多个参数页中确定出最新的参数页(目标参数页);从最新的参数页中逐一取出对应目标页的目标地址;将备份区的第五存储区域中存储的备份数据逐页还原到目标地址对应的目标页中,擦除当前备份区第三存储区域中的第二预设标记,并将当前备份区终止页的逻辑下一页作为下次写操作的备份区的起始页。其中,可以从备份区的第四存储区域包括的多个参数页中,将数据量最大的参数页确定为最新的参数页,也可以将最后一个写入的参数页确定为最新的参数页。
为了确保数据被成功写入,下面将对电子设备在执行上述实施例四中的步骤发生意外掉电如何恢复数据进行说明:当电子设备在执行S401-S403中任一步骤时发生意外掉电,此时,由于尚未对待写入数据进行任何操作,因此电子设备的掉电不会影响到待写入数据,无需进行数据恢复。当电子设备在执行S404-S407中任一步骤时发生意外掉电,此时,可以从备份区的第四存储区域包括的多个参数页中确定出最新的参数页;从最新的参数页中逐一取出对应目标页的目标地址;将备份区的第五存储区域中存储的备份数据逐页还原到目标地址对应的目标页中,擦除当前备份区第三存储区域中的第二预设标记,并将当前备份区终止页的逻辑下一页作为下次写操作的备份区的起始页。
另外,相应于上述实施例所提供的Flash数据掉电保护方法,本发明实施例还提供了一种电子设备,该电子设备可以包括:存储器,用于存储程序;处理器,用于通过执行所述存储器存储的程序以实现本发明实施例的提供的Flash数据掉电保护方法。
另外,相应于上述实施例所提供的Flash数据掉电保护方法,本发明实施例还提供了一种计算机可读存储介质,该计算机可读存储介质包括程序,所述程序能够被处理器执行以实现本发明实施例的提供的Flash数据掉电保护方法。
本文参照了各种示范实施例进行说明。然而,本领域的技术人员将认识到,在不脱离本文范围的情况下,可以对示范性实施例做出改变和修正。例如,各种操作步骤以及用于执行操作步骤的组件,可以根据特定的应用或考虑与系统的操作相关联的任何数量的成本函数以不同的方式实现(例如一个或多个步骤可以被删除、修改或结合到其他步骤中)。
另外,如本领域技术人员所理解的,本文的原理可以反映在计算机可读存储介质上的计算机程序产品中,该可读存储介质预装有计算机可读程序代码。任何有形的、非暂时性的计算机可读存储介质皆可被使用,包括磁存储设备(硬盘、软盘等)、光学存储设备(CD-ROM、DVD、Blu Ray盘等)、闪存和/或诸如此类。这些计算机程序指令可被加载到通用计算机、专用计算机或其他可编程数据处理设备上以形成机器,使得这些在计算机上或其他可编程数据处理装置上执行的指令可以生成实现指定的功能的装置。这些计算机程序指令也可以存储在计算机可读存储器中,该计算机可读存储器可以指示计算机或其他可编程数据处理设备以特定的方式运行,这样存储在计算机可读存储器中的指令就可以形成一件制造品,包括实现指定功能的实现装置。计算机程序指令也可以加载到计算机或其他可编程数据处理设备上,从而在计算机或其他可编程设备上执行一系列操作步骤以产生一个计算机实现的进程,使得在计算机或其他可编程设备上执行的指令可以提供用于实现指定功能的步骤。
虽然在各种实施例中已经示出了本文的原理,但是许多特别适用于特定环境和操作要求的结构、布置、比例、元件、材料和部件的修改可以在不脱离本披露的原则和范围内使用。以上修改和其他改变或修正将被包含在本文的范围之内。
前述具体说明已参照各种实施例进行了描述。然而,本领域技术人员将认识到,可以在不脱离本披露的范围的情况下进行各种修正和改变。因此,对于本披露的考虑将是说明性的而非限制性的意义上的,并且所有这些修改都将被包含在其范围内。同样,有关于各种实施例的优点、其他优点和问题的解决方案已如上所述。然而,益处、优点、问题的解决方案以及任何能产生这些的要素,或使其变得更明确的解决方案都不应被解释为关键的、必需的或必要的。本文中所用的术语“包括”和其任何其他变体,皆属于非排他性包含,这样包括要素列表的过程、方法、文章或设备不仅包括这些要素,还包括未明确列出的或不属于该过程、方法、系统、文章或设备的其他要素。此外,本文中所使用的术语“耦合”和其任何其他变体都是指物理连接、电连接、磁连接、光连接、通信连接、功能连接和/或任何其他连接。
具有本领域技术的人将认识到,在不脱离本发明的基本原理的情况下,可以对上述实施例的细节进行许多改变。因此,本发明的范围应根据以下权利要求确定。

Claims (10)

  1. 一种Flash数据掉电保护方法,其特征在于,用于电子设备,所述电子设备中包括Flash存储器,所述Flash存储器内划分有代码区、数据区及掉电保护区,所述代码区用于存放代码数据,所述数据区用于存放文件系统数据及用户数据,所述掉电保护区用于备份数据;所述方法包括:
    在所述电子设备上电时,遍历所述掉电保护区,查找符合预设条件的数据页,所述符合预设条件的数据页为备份区的起始页;
    若存在符合预设条件的数据页,则根据所述符合预设条件的数据页所指示的备份区进行数据恢复,清除当前备份区中备份的数据,并将当前备份区终止页的逻辑下一页作为下次写操作的备份区的起始页;
    若不存在符合预设条件的数据页,则生成随机数,并依据生成的随机数从所述掉电保护区选取一页作为下次写操作的备份区的起始页。
  2. 如权利要求1所述的方法,其特征在于,所述方法还包括:
    接收待写入数据的目标地址、内容及长度;
    根据所述待写入数据的目标地址及长度确定待备份的数据;
    将所述待备份的数据写入当前备份区;
    将所述待写入数据的内容写入所述目标地址;
    清除当前备份区中备份的数据,并将当前备份区终止页的逻辑下一页作为下次写操作的备份区的起始页。
  3. 如权利要求2所述的方法,其特征在于,若写操作为原子写,则所述备份区包括第一存储区域和第二存储区域,所述第一存储区域用于存储第一预设标记以及原子写操作指向的目标地址以及影响的数据范围,所述第二存储区域用于备份原子写操作影响的页数据,所述第一预设标记用于指示写操作为原子写;所述将所述待备份的数据写入当前备份区,包括:
    将所述待备份的数据写入所述备份区的第二存储区域;
    将所述第一预设标记、所述目标地址及所述长度写入所述备份区的第一存储区域。
  4. 如权利要求3所述的方法,其特征在于,所述符合预设条件的数据页为存在所述第一预设标记的数据页,所述根据所述符合预设条件的数据页所指示的备份区进行数据恢复,包括:
    从所述备份区的第一存储区域获取所述目标地址及所述长度;
    根据所述目标地址及所述长度确定目标页;
    将所述备份区的第二存储区域中存储的备份数据逐页还原到所述目标页中。
  5. 如权利要求3或4所述的方法,其特征在于,所述清除当前备份区中备份的数据,包括:
    擦除当前备份区第一存储区域中的内容。
  6. 如权利要求2所述的方法,其特征在于,若写操作为事务写,则所述备份区包括第三存储区域、第四存储区域和第五存储区域,所述第三存储区域用于存储第二预设标记,所述第四存储区域用于记录事务写操作中所有需要备份的目标页地址,所述第五存储区域用于备份事务写操作影响的页数据,所述第二预设标记用于指示写操作为事务写,所述第四存储区域包括多个参数页;所述将所述待备份的数据写入当前备份区包括:
    将所述待备份的数据写入所述备份区的第五存储区域;
    根据次数计数器从多个参数页中确定目标参数页;
    将当前以及之前该事务写过程中的所有目标地址写入所述目标参数页,并更新所述次数计数器;
    将所述第二预设标记写入所述备份区的第三存储区域。
  7. 如权利要求6所述的方法,其特征在于,所述符合预设条件的数据页为存在所述第二预设标记的数据页,所述根据所述符合预设条件的数据页所指示的备份区进行数据恢复,包括:
    从所述备份区的第四存储区域包括的多个参数页中确定出最新的参数页;
    从所述最新的参数页中逐一取出对应目标页的目标地址;
    将所述备份区的第五存储区域中存储的备份数据逐页还原到所述目标地址对应的目标页中。
  8. 如权利要求6或7所述的方法,其特征在于,所述清除当前备份区中备份的数据,包括:
    擦除当前备份区第三存储区域中的内容。
  9. 一种电子设备,其特征在于,包括:
    存储器,用于存储程序;
    处理器,用于通过执行所述存储器存储的程序以实现如权利要求1-8中任一项所述的方法。
  10. 一种计算机可读存储介质,其特征在于,包括程序,所述程序能够被处理器执行以实现如权利要求1-8中任一项所述的方法。
PCT/CN2020/137133 2020-12-17 2020-12-17 Flash数据掉电保护方法及设备 WO2022126470A1 (zh)

Priority Applications (2)

Application Number Priority Date Filing Date Title
CN202080026922.3A CN113785275B (zh) 2020-12-17 2020-12-17 Flash数据掉电保护方法及设备
PCT/CN2020/137133 WO2022126470A1 (zh) 2020-12-17 2020-12-17 Flash数据掉电保护方法及设备

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
PCT/CN2020/137133 WO2022126470A1 (zh) 2020-12-17 2020-12-17 Flash数据掉电保护方法及设备

Publications (1)

Publication Number Publication Date
WO2022126470A1 true WO2022126470A1 (zh) 2022-06-23

Family

ID=78835354

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2020/137133 WO2022126470A1 (zh) 2020-12-17 2020-12-17 Flash数据掉电保护方法及设备

Country Status (2)

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

Cited By (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN116795297A (zh) * 2023-08-18 2023-09-22 苏州云途半导体有限公司 一种存储设备、存储方法及装置
CN117112310A (zh) * 2023-10-18 2023-11-24 苏州元脑智能科技有限公司 后台任务进度保存和恢复方法、装置、设备及存储介质
CN117707434A (zh) * 2024-02-02 2024-03-15 深圳曦华科技有限公司 一种Flash的数据写入方法、装置、车辆以及存储介质

Families Citing this family (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
KR20220067921A (ko) * 2020-11-18 2022-05-25 한국전자통신연구원 플래시 메모리를 구비한 디바이스 및 그 디바이스에서의 플래시 메모리에 데이터 쓰기/삭제/갱신 방법
CN114428588A (zh) * 2021-12-17 2022-05-03 深圳市拔超科技股份有限公司 一种Flash掉电数据存储方法及系统
CN118069404A (zh) * 2023-09-20 2024-05-24 南宁清智电子科技有限公司 一种掉电不丢失存储方法及相关装置
CN117251116B (zh) * 2023-11-14 2024-02-20 苏州元脑智能科技有限公司 非易失性存储器的擦写方法及装置

Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN103793337A (zh) * 2013-11-12 2014-05-14 飞天诚信科技股份有限公司 一种防掉电的数据保护方法
US9684360B2 (en) * 2014-10-30 2017-06-20 Intel Corporation Dynamically controlling power management of an on-die memory of a processor
CN109685190A (zh) * 2018-12-28 2019-04-26 江苏恒宝智能系统技术有限公司 一种ic卡掉电保护方法及装置
CN111427726A (zh) * 2020-03-27 2020-07-17 江苏恒宝智能系统技术有限公司 Ic卡及其防掉电数据备份方法或数据恢复方法
CN111737058A (zh) * 2020-06-29 2020-10-02 江苏恒宝智能系统技术有限公司 Ic卡及其防掉电数据备份方法或数据恢复方法

Family Cites Families (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
KR100746198B1 (ko) * 2005-07-08 2007-08-06 삼성전자주식회사 데이터 저장장치, 데이터 저장방법, 및 그 기록매체
CN103617101A (zh) * 2013-12-12 2014-03-05 北京旋极信息技术股份有限公司 一种掉电保护方法及装置
CN108108271B (zh) * 2017-12-25 2020-11-03 飞天诚信科技股份有限公司 一种实现事务与掉电保护统一管理的方法及装置

Patent Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN103793337A (zh) * 2013-11-12 2014-05-14 飞天诚信科技股份有限公司 一种防掉电的数据保护方法
US9684360B2 (en) * 2014-10-30 2017-06-20 Intel Corporation Dynamically controlling power management of an on-die memory of a processor
CN109685190A (zh) * 2018-12-28 2019-04-26 江苏恒宝智能系统技术有限公司 一种ic卡掉电保护方法及装置
CN111427726A (zh) * 2020-03-27 2020-07-17 江苏恒宝智能系统技术有限公司 Ic卡及其防掉电数据备份方法或数据恢复方法
CN111737058A (zh) * 2020-06-29 2020-10-02 江苏恒宝智能系统技术有限公司 Ic卡及其防掉电数据备份方法或数据恢复方法

Cited By (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN116795297A (zh) * 2023-08-18 2023-09-22 苏州云途半导体有限公司 一种存储设备、存储方法及装置
CN116795297B (zh) * 2023-08-18 2023-11-17 江苏云途半导体有限公司 一种存储设备、存储方法及装置
CN117112310A (zh) * 2023-10-18 2023-11-24 苏州元脑智能科技有限公司 后台任务进度保存和恢复方法、装置、设备及存储介质
CN117112310B (zh) * 2023-10-18 2024-02-20 苏州元脑智能科技有限公司 后台任务进度保存和恢复方法、装置、设备及存储介质
CN117707434A (zh) * 2024-02-02 2024-03-15 深圳曦华科技有限公司 一种Flash的数据写入方法、装置、车辆以及存储介质
CN117707434B (zh) * 2024-02-02 2024-05-17 深圳曦华科技有限公司 一种Flash的数据写入方法、装置、车辆以及存储介质

Also Published As

Publication number Publication date
CN113785275B (zh) 2024-03-05
CN113785275A (zh) 2021-12-10

Similar Documents

Publication Publication Date Title
WO2022126470A1 (zh) Flash数据掉电保护方法及设备
US10642729B2 (en) Data storage device and operating method thereof wherein update to physical-to-logical mapping of destination block is restarted when closing active block
US9104329B2 (en) Mount-time reconciliation of data availability
US10606513B2 (en) Volatility management for non-volatile memory device
US11163679B2 (en) Garbage collection strategy for memory system and method of executing such garbage collection
US20130326121A1 (en) Data-storage device and flash memory control method
US10168940B2 (en) Data storage using SLC and TLC memory banks and data maintenance method thereof
JP6163551B2 (ja) ビットマップウインドウを用いて永続メモリにおけるオブジェクトを削除するためのシステムおよび方法
KR20120135103A (ko) 비휘발성 메모리 시스템 내의 미사용 논리 어드레스들의 마운트 시간 맵핑 해제
US20180150390A1 (en) Data Storage Device and Operating Method Therefor
US20150074336A1 (en) Memory system, controller and method of controlling memory system
US20090172252A1 (en) Memory device and method for performing a write-abort-safe firmware update
CN103996412A (zh) 一种用于智能卡非易失性存储器的掉电保护方法
KR20080104815A (ko) 비휘발성 메모리의 데이터 처리 장치 및 방법
CN111666046B (zh) 一种数据存储方法、装置及设备
CN108694101B (zh) 存储器侧高速缓存内容的持久性高速缓存
CN110032526B (zh) 一种基于非易失性介质的页缓存方法、系统及设备
WO2018103010A1 (zh) 一种存储设备管理方法及用户终端
JP2013214154A (ja) 情報処理装置、情報処理装置制御方法及び情報処理装置制御プログラム
KR20150094292A (ko) 비휘발성 메모리 기반의 전자 장치의 메타 데이터 복원 방법 및 장치
CN111008159B (zh) 存储设备数据保护方法、装置、设备及存储介质
TWI354892B (en) Method of immediate data update with flash memory
US12039193B2 (en) Apparatus, method and computer program for managing memory page updates within non-volatile memory
CN110874273A (zh) 一种数据处理方法及装置
US20220164135A1 (en) Apparatus, method and computer program for managing memory page updates within non-volatile memory

Legal Events

Date Code Title Description
121 Ep: the epo has been informed by wipo that ep was designated in this application

Ref document number: 20965487

Country of ref document: EP

Kind code of ref document: A1

NENP Non-entry into the national phase

Ref country code: DE

122 Ep: pct application non-entry in european phase

Ref document number: 20965487

Country of ref document: EP

Kind code of ref document: A1