Nothing Special   »   [go: up one dir, main page]

CN111737058B - IC card and anti-power-down data backup method or data recovery method thereof - Google Patents

IC card and anti-power-down data backup method or data recovery method thereof Download PDF

Info

Publication number
CN111737058B
CN111737058B CN202010603726.XA CN202010603726A CN111737058B CN 111737058 B CN111737058 B CN 111737058B CN 202010603726 A CN202010603726 A CN 202010603726A CN 111737058 B CN111737058 B CN 111737058B
Authority
CN
China
Prior art keywords
data
page
partition
mark
area
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Active
Application number
CN202010603726.XA
Other languages
Chinese (zh)
Other versions
CN111737058A (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.)
Jiangsu Hengbao Intelligent System Technology Co Ltd
Original Assignee
Jiangsu Hengbao Intelligent System 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 Jiangsu Hengbao Intelligent System Technology Co Ltd filed Critical Jiangsu Hengbao Intelligent System Technology Co Ltd
Priority to CN202010603726.XA priority Critical patent/CN111737058B/en
Publication of CN111737058A publication Critical patent/CN111737058A/en
Application granted granted Critical
Publication of CN111737058B publication Critical patent/CN111737058B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F11/00Error detection; Error correction; Monitoring
    • G06F11/07Responding to the occurrence of a fault, e.g. fault tolerance
    • G06F11/14Error detection or correction of the data by redundancy in operation
    • G06F11/1402Saving, restoring, recovering or retrying
    • G06F11/1446Point-in-time backing up or restoration of persistent data
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06KGRAPHICAL DATA READING; PRESENTATION OF DATA; RECORD CARRIERS; HANDLING RECORD CARRIERS
    • G06K19/00Record carriers for use with machines and with at least a part designed to carry digital markings
    • G06K19/06Record carriers for use with machines and with at least a part designed to carry digital markings characterised by the kind of the digital marking, e.g. shape, nature, code
    • G06K19/067Record carriers with conductive marks, printed circuits or semiconductor circuit elements, e.g. credit or identity cards also with resonating or responding marks without active components
    • G06K19/07Record carriers with conductive marks, printed circuits or semiconductor circuit elements, e.g. credit or identity cards also with resonating or responding marks without active components with integrated circuit chips

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • General Physics & Mathematics (AREA)
  • Quality & Reliability (AREA)
  • General Engineering & Computer Science (AREA)
  • Computer Hardware Design (AREA)
  • Microelectronics & Electronic Packaging (AREA)
  • Information Retrieval, Db Structures And Fs Structures Therefor (AREA)
  • Techniques For Improving Reliability Of Storages (AREA)

Abstract

The application relates to the technical field of IC cards, in particular to an IC card, an IC card power-down prevention data backup method and an IC card power-down prevention data recovery method, wherein the backup of front E page data adopts the whole page protection of a protection page of an anti-pulling area, so that the time for recording backup records to a backup area is saved, and when the data is recovered, the last page data and the front E page data can be recovered in the whole page.

Description

IC card and anti-power-down data backup method or data recovery method thereof
Technical Field
The application relates to the technical field of IC cards, in particular to an IC card, an IC card power-down prevention data backup method and an IC card power-down prevention data recovery method.
Background
The IC card is a card using a chip as a medium, has the characteristics of safety, convenience, expandability and the like, and can be used as a bank card, a security card, a management card and the like. The memory of the IC card has an EEPROM, a ROM, a Flash (Flash english name is Flash memory, which is a nonvolatile memory), and the like. Flash is widely used as a memory of an IC card at present because Flash can not only keep stored information for a long time without power connection, but also has the characteristics of ROM (read only memory) and has very high storage speed, and is easy to erase and rewrite and relatively small in power consumption.
When the data stored in the Flash data area needs to be updated, the data in the data area is erased and then written, so that the Flash also has the problem of power failure in the erasing and writing process, and the problem of data loss stored in the Flash caused by power failure exists.
Therefore, how to protect the Flash memory in the IC card from power failure to avoid data loss in the Flash memory of the IC card is a technical problem that needs to be solved by those skilled in the art.
Disclosure of Invention
The application provides an IC card, an IC card power-down prevention data backup method and an IC card power-down prevention data recovery method, which are used for carrying out power-down protection on a Flash memory in the IC card, so that the data loss stored in the Flash memory of the IC card is avoided, and the speed of backing up the data of the Flash memory of the IC card is also improved.
In order to solve the technical problems, the application provides the following technical scheme:
A method for preventing power failure data backup of an IC card comprises the following steps: step S210, backing up the whole data page in the first page to be backed up in the data area to the first protection page of the first partition, increasing the backup identification, and writing a valid mark into the first mark area of the mark page of the first partition; step S220, repeating the step S210 until the whole data page in the nth page to be backed up in the data area is backed up to the nth protection page of the first partition, increasing the backup mark, and writing the effective mark into the nth mark area of the mark page of the first partition to finish the data backup; step S230, in response to the completion of data updating, writing a failure mark in an nth mark area of a mark page of the first partition, and setting a backup mark to zero; wherein n is the number of pages related to the data to be backed up in the data area, 0<n is less than or equal to E, and E is the number of protection pages in the first partition.
The above-mentioned method for backup of data against power failure of an IC card, preferably further comprises, before step S210: step S209 sets the backup flag to zero, and erases the data in the first partition and the second partition for initialization.
A method for preventing power failure data backup of an IC card comprises the following steps: step S310, backing up the whole data page in the first page to be backed up in the data area to the first protection page of the first partition, increasing the backup identification, and writing the effective mark into the first mark area of the mark page of the first partition; step S320, repeating the step S310 until the whole page of the data in the E-th page to be backed up in the data area is backed up to the E-th protection page of the first partition, increasing the backup mark, and writing a valid mark into the E-th mark area of the mark page of the first partition; step S330, backing up the backup record of the data in the E+1th page to be backed up in the data area to the backup area, backing up the whole page of the data in the E+1th page to be backed up in the data area to the first protection page of the second partition, and sequentially and circularly writing effective marks into mark areas of idle pages of the first partition and the second partition according to the sequence from the first partition to the second partition; step S340, repeating the step S330 until the backup record of the data in the nth page to be backed up in the data area is backed up in the backup area, and backing up the whole page of the data in the nth page to be backed up in the data area into the n-E protection page of the second partition, and writing effective marks into the mark areas of the idle pages of the first partition and the second partition in sequence from the first partition to the second partition to finish the data backup; step S350, in response to the completion of data updating, writing a failure mark in an E mark area of a mark page of the first partition, and setting a backup mark to zero; wherein n is the number of pages related to the data to be backed up in the data area, E < n is less than or equal to E+F, E is the number of protection pages in the first partition, and F is the data of the protection pages in the second partition.
A method for preventing power failure data backup of an IC card comprises the following steps: step S410, backing up the whole data page in the first page to be backed up in the data area to the first protection page of the first partition, increasing the backup identification, and writing the effective mark into the first mark area of the mark page of the first partition; step S420, repeating the step S410 until the whole page of the data in the E-th page to be backed up in the data area is backed up to the E-th protection page of the first partition, increasing the backup mark, and writing the effective mark into the E-th mark area of the mark page of the first partition; step S430, backing up the backup record of the data in the E+1th page to be backed up in the data area to the backup area, backing up the whole page of the data in the E+1th page to be backed up in the data area to the first protection page of the second partition, and writing effective marks into mark areas of idle pages of the first partition and the second partition in sequence from the first partition to the second partition; step S440, repeating the step S430 until the backup record of the data in the E+F page to be backed up in the data area is backed up to the backup area, and backing up the whole data page in the E+F page to be backed up in the data area to the F protection page of the second partition, and writing effective marks into the mark areas of the idle pages of the first partition and the second partition in sequence from the first partition to the second partition; step S450, repeating the step S430 and the step S440 until the backup record of the data in the nth page to be backed up in the data area is backed up in the backup area, and the whole page of the data in the nth page to be backed up in the data area is backed up in the nth-E-aF protection page of the second partition, and writing effective marks into mark areas of idle pages of the first partition and the second partition in sequence from the first partition to the second partition, so as to finish the data backup, wherein a is the number of times that all protection pages of the second partition are used; step S460, in response to the completion of the data updating, writing a failure flag in an E-th flag area of a flag page of the first partition, and setting a backup flag to zero; wherein n is the number of pages related to the data to be backed up in the data area, E+F < n, E is the number of protection pages in the first partition, and F is the data of the protection pages in the second partition.
A method for recovering power failure prevention data of an IC card comprises the following steps: step S510, inquiring whether a failure mark exists in a mark area of the mark page, if so, not needing to carry out data recovery, and if not, carrying out step S520; step S520, checking the valid flags in the flag areas from the second partition to the first partition from the back to the front until the valid flags are checked to pass, and performing step S530; step S530, if the backup mark is smaller than E, the effective marks in the mark areas of the mark pages of the first partition are compared, and the whole page data backed up in the first partition protection page is sequentially restored to the data area from back to front; where E is the number of guard pages in the first partition.
The method for recovering the power failure prevention data of the IC card, as described above, preferably further comprises the following steps: and S540, checking the mark areas of the idle pages of the second partition and the first partition from the back to the front if the backup mark is a preset value, and recovering the data backed up by the E protection pages of the first partition from the back to the front to the data area sequentially.
The method for recovering the power failure prevention data of the IC card, as described above, preferably further comprises the following steps: step S550, if the mark area of the idle page is not empty, checking whether the last valid mark recorded in the mark area of the idle page is valid, and if so, restoring the whole data page backed up in the protection page of the second partition corresponding to the last valid mark to the data area; step S560, checking the backup records in the backup area in turn, and recovering the data to the data area from the back to the front through the backup records in turn; step 570, restore the data backed up in the E protection pages in the first partition to the data area from the back to the front.
An IC card, comprising: the device comprises a processor and a memory, wherein the memory comprises a data area, a backup area and an anti-pulling area; the anti-pulling area comprises: the system comprises a first partition and a second partition, wherein the first partition is provided with a protection page, a sign page and a free page, and the second partition is provided with a protection page, a sign page and a free page; the processor executes the method for backing up the power-down prevention data of the IC card described above, or the processor executes the method for recovering the power-down prevention data of the IC card described above.
The IC card as described above, wherein it is preferable that the first partition and the second partition are each one sector size.
The IC card as described above, wherein it is preferable that the first partition has 12 protection pages, 3 flag pages, and 1 free page, and the second partition has 12 protection pages, 3 flag pages, and 1 free page.
Compared with the background technology, the IC card power-down prevention data backup method and the IC card power-down prevention data recovery method provided by the application adopt the whole page protection of the front E pages (such as the front 12 pages of the example) data, save the time of recording backup records to the backup area, and restore the last page data and the front E pages of data when restoring the data, so that the application can protect the power-down of the Flash memory in the IC card, avoid the data loss stored in the Flash memory of the IC card, and simultaneously improve the speed of the backup data of the Flash memory of the IC card.
Drawings
In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings used in the embodiments or the description of the prior art will be briefly described below, and it is obvious that the drawings in the following description are only some embodiments described in the present invention, and other drawings may be obtained according to these drawings for a person having ordinary skill in the art.
Fig. 1 is a schematic diagram of the structure of an IC card according to an embodiment of the present application;
FIG. 2 is a flowchart of a method for backup of power-down prevention data of an IC card according to an embodiment of the present application;
FIG. 3 is a flowchart of a method for backup of power-down prevention data of an IC card according to another embodiment of the present application;
FIG. 4 is a flowchart of a method for backup of power-down prevention data of an IC card according to still another embodiment of the present application;
FIG. 5 is a flowchart of an IC card power-down prevention data recovery method provided by an embodiment of the application;
Fig. 6 is a schematic diagram showing the comparison of the performance of an IC card according to an embodiment of the present application with the performance of an existing IC card.
Detailed Description
Embodiments of the present invention are described in detail below, examples of which are illustrated in the accompanying drawings, wherein like or similar reference numerals refer to like or similar elements or elements having like or similar functions throughout. The embodiments described below by referring to the drawings are illustrative only and are not to be construed as limiting the invention.
Example 1
Referring to fig. 1, fig. 1 is a schematic diagram of an IC card according to an embodiment of the present application;
The present application provides an IC card, wherein the IC card has a processor and a memory; the processor is used for receiving the IO command and controlling the memory to store data according to the IO command; the memory may be a Flash memory, and of course, may also be a memory having the same data storage method as the Flash memory. Specifically, the memory has a data area 110, a backup area 120, and a pull-out prevention area 130.
The data area 110 is used to store user data, for example: data such as user name, user phone, services enjoyed by the user (storing or retrieving notifications), account amount, transaction records, etc.
The backup area 120 is used for storing backup records of data to be updated in the data area 110, and is mainly used for protecting the data to be updated in the data area 110 in atomic write, and once a power failure occurs in the process, a recovery operation can be performed on the data to be updated in the data area 110 through the backup records of the data to be updated stored in the backup area 120.
The anti-pull area 130 is used for storing the whole page of data to be updated in the data area 110, that is, the anti-pull area 130 stores the original data to be updated in the data area 110. Specifically, during data backup, the whole page data to be updated in the data area 110 is copied to the protection page of the anti-pulling area 130, the valid mark is written to the mark page of the anti-pulling area or the mark area of the idle page, and when the data backup is completed, the invalid mark is written to the mark area of the mark page of the anti-pulling area.
Specifically, the anti-pull out region 130 includes: a first partition 131 and a second partition 132, the first partition 131 having a protection page, a logo page, and a free page, the second partition 132 having a protection page, a logo page, and a free page; the number of the protection pages of the first partition is E, and the number of the protection pages of the second partition is F; the marking page in each partition is provided with a plurality of marking areas, and the marking areas in each partition are in one-to-one correspondence with the protection pages of the partition; the free page of each partition also has a plurality of flag fields. On the basis of the above, preferably, e=f, more preferably, e=f=12. In addition, the first partition 131 may have 12 protection pages, 3 flag pages, and 1 free page, and the second partition 132 may also have 12 protection pages, 3 flag pages, and 1 free page.
For example: the anti-pull area has two sectors, 1st sector and 2nd sector, respectively, which may typically be 0x2000 in size, each sector having 12 guard pages, 3 flag pages and 1 free page. The two sectors have 24 protection pages (marked as P1-P24, wherein P1-P12 are the protection pages of the first sector, and P13-P24 are the protection pages of the second sector), 6 mark pages and 2 idle pages; wherein each flag page has 4 flag areas, then the 3 flag pages of each sector have 12 flag areas, the two sectors have 24 flag areas (marked as A1-A24, wherein A1-A12 are the flag areas of the first sector, and the flag areas of the second sector of A13-A24), and the 12 protection pages of each sector are in one-to-one correspondence with the 12 flag areas of the sector for placing valid flags and invalid flags; each free page has 8 flag fields, then two sectors together have 16 flag fields (labeled B1-B16, where B1-B8 are the flag fields of the first sector and B9-B16 are the flag fields of the second sector) for placing valid flags, and the last valid flag placed in the flag fields within the default free page is valid.
Since the flag area in the flag page is for placing the valid flag and the invalid flag, and the flag area in the free page is for placing only the valid flag, the size of the flag area in the flag page is 2 times that in the free page.
Because the anti-pulling areas are partitioned by taking the integer multiple of the sector as a unit, the size of each partition is one sector, so that the characteristic of the sector can be utilized to erase pages into the sector, further the sector is erased, the 16 pages of each sector can be simultaneously erased, further the time for erasing the 16 pages of each sector is the same as the time for erasing one page, and the time occupied by erasing the backed-up data in the anti-pulling areas is effectively reduced.
Example two
The embodiment provides a method for backing up data of an IC card against power failure, specifically, the number of pages related to data to be backed up in a data area is set to n, if 0<n is less than or equal to E, when the data is backed up, as shown in fig. 2, the following steps are executed:
Step S210, backing up the whole data page in the first page to be backed up in the data area to the first protection page of the first partition, increasing the backup identification, and writing a valid mark into the first mark area of the mark page of the first partition;
When a transaction is carried out, the data to be updated in the transaction is required to be backed up, after the data backup is completed, the corresponding data is updated, and if the power-down phenomenon occurs in the process of data update, after the power-up is carried out again, the data recovery is carried out according to the backed-up data.
Step S209 may be further included before the data backup, the backup identifier is set to zero, and the data in the first partition and the second partition are erased to perform initialization, and step S210 is performed after the initialization is completed.
For example: firstly, when a transaction starts, namely before data backup, a backup initialization flow is carried out, which is specifically as follows:
If the variable bac_flag=0, the data erasing step is directly performed, and if the variable bac_flag is not equal to 0, the bac_flag=0 is set, and then the data erasing step is performed, wherein the variable bac_flag is a parameter for marking the current backup page as the page of the pages related to the data to be backed up of the transaction.
And checking whether the 12 th protection page in the first sector of the anti-pulling area is in an erased state, if not, erasing the data in the first sector, and if the second sector stores the data, erasing the data in the second sector, and after the data in the two sectors are erased, entering a backup flow.
The first step of the backup process:
Backing up the whole data page in the page 1 to be backed up in the data area to the protection page P1 of the anti-pulling area, organizing the effective mark (CRC+effective mark A5A5A5A 5+target page address+BAC_FLAG+anti-pulling area page header address), and writing the effective mark into the mark area A1.
Step S220, repeating the step S210 until the whole data page in the nth page to be backed up in the data area is backed up to the nth protection page of the first partition, increasing the backup mark, and writing the effective mark into the nth mark area of the mark page of the first partition to finish the data backup;
for example: the second step of the backup flow:
Comparing the page address of the data in the page 2 to be backed up in the data area with the recording address in the mark area A1, if the address recorded in the mark area A1 already contains the page address of the data in the page 2 to be backed up, not repeating the backup, namely not backing up the data in the page 2 to be backed up, otherwise, backing up the whole page of the data in the page 2 to be backed up in the protection page P2 of the anti-pulling area, organizing the effective mark, and writing the effective mark into the mark area A2;
and the third step to the n-1 step of the backup flow are performed by analogy;
The n-th step of the backup flow:
Comparing the page address of the data in the page n to be backed up with the addresses recorded in the mark areas A1-A (n-1), if the addresses recorded in the mark areas A1-A (n-1) already contain the page address of the data in the page n to be backed up, not repeating the backup, namely not backing up the data in the page n to be backed up, otherwise, backing up the whole page of the data in the page n to be backed up in the protection page P (n) of the anti-pulling area, organizing the effective mark, and writing the effective mark into the mark area A (n) to finish the data backup of the transaction.
After the data backup to be updated is completed, the corresponding data is updated, and after the data update is completed, step S230 is performed.
Step S230, in response to the completion of data updating, writing a failure mark in an nth mark area of a mark page of the first partition, and setting a backup mark to zero;
for example: after the transaction is completed, a commit flow is performed, wherein the commit is used for saving the modification made by the transaction to the database, and the specific commit flow is as follows:
organizing the failure FLAG, writing the failure FLAG into the FLAG area a (n), and setting bac_flag=0; on the basis, whether the twelfth protection page of the first sector of the anti-pulling area is in an erased state or not can be checked, if not, the data in the first sector is erased, and whether the second sector has data or not is checked, if so, the data in the second sector is also erased, and then the identification of the transaction processed in the backup area is updated.
Example III
The embodiment provides a I C card power-down prevention data backup method, if E < n is less than or equal to E+F, when data backup is performed, as shown in fig. 3, the following steps are executed:
step S310, backing up the whole data page in the first page to be backed up in the data area to the first protection page of the first partition, increasing the backup identification, and writing the effective mark into the first mark area of the mark page of the first partition;
For example: first, at the beginning of a transaction, i.e., before data backup, a backup initialization procedure, specifically, a backup initialization procedure as described in the second embodiment above, is performed, and the first step of the backup procedure as described in the second embodiment above is also performed.
Step S320, repeating the step S310 until the whole page of the data in the E-th page to be backed up in the data area is backed up to the E-th protection page of the first partition, increasing the backup mark, and writing a valid mark into the E-th mark area of the mark page of the first partition;
for example: the second step of the backup process described in the second embodiment is performed, and so on, until the eleventh step, and then the twelfth step of the backup process is performed.
The twelfth step of the backup process:
Comparing the page address of the data in the page 12 to be backed up in the data area with the record addresses in the mark areas A1 to A11, if the addresses recorded in the mark areas A1 to A11 already contain the page address of the data in the page 12 to be backed up, not repeating the backup, namely not backing up the data in the page 12 to be backed up, otherwise, backing up the whole page of the data in the page 12 to be backed up in the protection page P12 of the anti-pulling area, setting BAC_flag=0xFF, organizing the effective mark, and writing the effective mark into the mark area A12;
Step S330, backing up the backup record of the data in the E+1th page to be backed up in the data area to the backup area, backing up the whole page of the data in the E+1th page to be backed up in the data area to the first protection page of the second partition, and sequentially and circularly writing effective marks into mark areas of idle pages of the first partition and the second partition according to the sequence from the first partition to the second partition;
For example: thirteenth step of backup flow:
Organizing the data in the page 13 to be backed up in the data area and the corresponding address, length, check byte and the like into a backup record, and backing up the backup record into a backup area to be recorded as E1; backing up the whole data page in the page 13 to be backed up in the data area to the protection page P13 of the anti-pulling area, organizing the effective mark, and writing the effective mark into the mark area B1;
step S340, repeating the step S330 until the backup record of the data in the nth page to be backed up in the data area is backed up in the backup area, and the whole page of the data in the nth page to be backed up in the data area is backed up in the nth-E protection page of the second partition, and writing effective marks into the mark areas of the idle pages of the first partition and the second partition in sequence according to the sequence from the first partition to the second partition, so as to finish data updating;
For example: fourteenth step of backup procedure:
organizing the data in the page 14 to be backed up in the data area and the corresponding address, length, check byte and the like into a backup record, backing up the backup record into a backup area, and recording as E2; backing up the whole data page in the page 14 to be backed up in the data area to the protection page P14 of the anti-pulling area, organizing the effective mark, and writing the effective mark into the mark area B2;
the fifteenth to twentieth steps of the backup process are performed by analogy;
Twenty-first step of backup procedure:
organizing the data in the page 21 to be backed up in the data area and the corresponding address, length, check byte and the like into a backup record, and backing up the backup record into a backup area to be recorded as E9; backing up the whole data page in the page 21 to be backed up in the data area to the protection page P21 of the anti-pulling area, organizing the effective mark, and writing the effective mark into the mark area B9;
The second twelve steps of the backup flow are performed by analogy to the n-1 steps;
The n-th step of the backup flow:
Organizing data in a page n to be backed up in a data area and corresponding addresses, lengths, check bytes and the like into backup records, backing up the backup records into a backup area, and recording the backup records as E (n-12); and backing up the whole data page in the page n to be backed up in the data area to the protection page P (n-12) of the anti-pulling area, organizing the effective mark, and writing the effective mark into the mark area B [ (n-12)% 16 ].
After the data backup to be updated is completed, the corresponding data is updated, and after the data update is completed, step S350 is performed.
Step S350, in response to the completion of data updating, writing a failure mark in an E mark area of a mark page of the first partition, and setting a backup mark to zero;
for example: as in the second embodiment.
Example IV
The embodiment provides a method for backing up data of an IC card against power failure, if e+f < n, when backing up data, as shown in fig. 4, the following steps are executed:
step S410, backing up the whole data page in the first page to be backed up in the data area to the first protection page of the first partition, increasing the backup identification, and writing the effective mark into the first mark area of the mark page of the first partition;
For example: first, at the start of a transaction, i.e., before data backup, a backup initialization flow, specifically, a backup initialization flow as described in the third embodiment above, is performed, and the first step of the backup flow as described in the third embodiment above is also performed.
Step S420, repeating the step S410 until the whole page of the data in the E-th page to be backed up in the data area is backed up to the E-th protection page of the first partition, increasing the backup mark, and writing the effective mark into the E-th mark area of the mark page of the first partition;
for example: the second to twelfth steps of the backup procedure described in the third embodiment above are performed.
Step S430, backing up the backup record of the data in the E+1th page to be backed up in the data area to the backup area, backing up the whole page of the data in the E+1th page to be backed up in the data area to the first protection page of the second partition, and writing effective marks into mark areas of idle pages of the first partition and the second partition in sequence from the first partition to the second partition;
for example: a thirteenth step of the backup procedure described in the third embodiment above is performed.
Step S440, repeating the step S430 until the backup record of the data in the E+F page to be backed up in the data area is backed up to the backup area, and backing up the whole data page in the E+F page to be backed up in the data area to the F protection page of the second partition, and writing effective marks into the mark areas of the idle pages of the first partition and the second partition in sequence from the first partition to the second partition;
For example: performing the fourteenth step of the backup process described in the third embodiment, and so on to perform the fifteenth to twenty-fourth steps of the backup process, until all 24 protection pages in the anti-pulling area are used once, in the data backup of the transaction, 12 protection pages in the first sector are not reused, and 12 protection pages in the second sector are recycled;
Step S450, repeating step S430 and step S440 until the backup record of the data in the nth page to be backed up in the data area is backed up in the backup area, and backing up the whole data page in the nth page to be backed up in the data area into the protection pages n-E-aF of the second partition, and writing effective marks into the mark areas of the idle pages of the first partition and the second partition in sequence from the first partition to the second partition in a circulating way to finish data updating, wherein a is the number of times that all the protection pages of the second partition are used, and a is the number of times that all the protection pages in the second partition are used in a circulating way;
for example: twenty-fifth step of backup procedure:
organizing the data in the page 25 to be backed up in the data area and the corresponding address, length, check byte and the like into a backup record, and backing up the backup record into a backup area to be recorded as E13; backing up the whole data page in the page 25 to be backed up in the data area to the protection page P13 of the anti-pulling area, organizing the effective mark, and writing the effective mark into the mark area B13;
Twenty-sixth step of backup procedure:
Organizing the data in the page 26 to be backed up in the data area and the corresponding address, length, check byte and the like into a backup record, backing up the backup record into a backup area, and recording as E14; backing up the whole data page in the page 26 to be backed up in the data area to the protection page P14 of the anti-pulling area, organizing the effective mark, and writing the effective mark into the mark area B14;
and the n-th step of the backup flow is performed by analogy:
Organizing data in a page n to be backed up in a data area and corresponding addresses, lengths, check bytes and the like into backup records, backing up the backup records into a backup area, and recording the backup records as E (n-12); and backing up the whole data page in the page n to be backed up in the data area to the protection page P (n percent 12+12) of the anti-pulling area, organizing the effective mark, and writing the effective mark into the mark area B [ (n-12)% 16], wherein the percentage is the remainder.
After the data backup to be updated is completed, the corresponding data is updated, and after the data update is completed, step S460 is performed.
Step S460, in response to the completion of the data updating, writing a failure flag in an E-th flag area of a flag page of the first partition, and setting a backup flag to zero;
for example: a specific commit procedure was performed as described in example three above.
In the application, when data is backed up, the front E page (such as the front 12 pages of the example) is backed up, the whole page protection of the anti-pulling area protection page is adopted, and the backup of the subsequent data is simultaneously protected by adopting the backup area and the anti-pulling area.
Example five
The embodiment provides a method for recovering power failure prevention data of an IC card, when power failure and the like occur in the process of data backup and update in the second to fourth embodiments, after the power is turned on again, a recovery flow is entered, and the recovery flow has the following steps:
Step S510, inquiring whether a failure mark exists in a mark area of the mark page, if so, not needing to carry out data recovery, and if not, carrying out step S520;
For example: if 0<n is less than or equal to E, if a failure mark exists in the nth mark area of the mark page of the first partition or E < n is less than or equal to E+ F, E +F < n, the fact that the transaction is executed and completed before power failure is performed is indicated, and data recovery is not needed through the whole page data backed up to the anti-pulling area or the whole page data backed up to the anti-pulling area and the backup record of the backup area.
Step S520, checking the valid flags in the flag areas from the second partition to the first partition from the back to the front until the valid flags are checked to pass, and performing step S530 or step S540;
For example: in the second sector to the first sector, the valid flag written in the flag area is checked from the back to the front, that is, the valid flags are checked from the flag areas B16 to B1, and then the valid flags are checked from the flag areas a12 to A1, if the check is not passed, the previous valid flag is continuously checked forward until the check is passed, and step S530 or step S540 is performed.
Step S530, if the backup mark is smaller than E, the effective marks in the mark areas of the mark pages of the first partition are compared, and the whole page data backed up in the first partition protection page is sequentially restored to the data area from back to front;
For example: if the variable BAC_Flag is smaller than 12, the valid flags in the Flag areas A (BAC_Flag) to A1 are compared, and the whole data backed up in the protection pages P (BAC_Flag) to P1 are restored to the data area from back to front.
Step S540, checking the mark areas of the idle pages of the second partition and the first partition from the back to the front if the backup mark is a preset value, and recovering the data backed up by the E protection pages of the first partition from the back to the front to the data area sequentially;
For example: bac_flag=0xff, checking from the back to the front whether the valid Flag is recorded in the Flag areas B1 to B16 of the free pages, and if no valid Flag is recorded, indicating that data is not backed up to the protection page of the second sector, restoring the data backed up to the protection page of the first sector to the data area in sequence of P12 to P1.
Step S550, if the mark area of the idle page is not empty, checking whether the last valid mark recorded in the mark area of the idle page is valid, and if so, restoring the whole data page backed up in the protection page of the second partition corresponding to the last valid mark to the data area;
for example: taking the mark area B10 of the last effective mark as an example, checking whether the effective mark in the mark area B10 is effective, and if so, restoring the whole data page backed up in the protection page of the second partition corresponding to the mark area B10 to the data area.
Step S560, checking the backup records in the backup area in turn, and recovering the data to the data area from the back to the front through the backup records in turn;
For example: and after the whole data page backed up in the protection page of the second partition corresponding to the last effective mark recorded in the mark area of the idle page is restored to the data area, sequentially restoring the data to the data area from back to front through E (n-12) backup records recorded in the backup area.
Step 570, restore the data backed up in the E protection pages in the first partition to the data area from the back to the front.
For example: and after E (n-12) backup records recorded by the backup area are sequentially restored to the data area from back to front, sequentially restoring the data in the 12 protection pages in the first sector to the data area in the whole pages according to the sequence of P12-P1.
When the application recovers the data, the last page data and the front E page data can realize the whole page recovery, thereby further improving the time of data recovery.
As shown in fig. 6, the performance of the IC card of the present application is compared with that of the existing IC card (regardless of the time of updating the target area):
Let 1 erase time=2 ms,1 block (block) write time=0.2 ms, and the valid flag and the invalid flag occupy 1 block write time, respectively.
When 1< = n <12 times, t=2×2+ (9n+1) ×0.2=4.2+1.8n
When n=12, t=6.2+1.8×12=27.8 ms
When 24= > n >12 times,
The minimum time is: t=4.2+9×12+ (9×12) +1) ×0.2+4 (without wiping)
The maximum time is as follows: t=4.2+9×12+ (9×12) +1) ×2.2+4 (required to be rubbed)
T=t+ (n-12) operation time of backup record +4.
When n >24 times, t=t+9 is (n-24) + (n-12) the operating time of the backup stack +4.
The time theoretical result occupied by the application is compared with the time theoretical result occupied in the prior art, so that the performance is greatly improved. In the application process, the application and the prior art two IC card power-down prevention data backup method and the data recovery method are respectively adopted for testing, the average is carried out after 10 times of testing, qpboc performances are optimized for 20ms, and the advanced is optimized for 10ms.
It will be evident to those skilled in the art that the invention is not limited to the details of the foregoing illustrative embodiments, and that the present invention may be embodied in other specific forms without departing from the spirit or essential characteristics thereof. The present embodiments are, therefore, to be considered in all respects as illustrative and not restrictive, the scope of the invention being indicated by the appended claims rather than by the foregoing description, and all changes which come within the meaning and range of equivalency of the claims are therefore intended to be embraced therein. Any reference sign in a claim should not be construed as limiting the claim concerned.
Furthermore, it should be understood that although the present disclosure describes embodiments, not every embodiment is provided with a separate embodiment, and that this description is provided for clarity only, and that the disclosure is not limited to the embodiments described in detail below, and that the embodiments described in the examples may be combined as appropriate to form other embodiments that will be apparent to those skilled in the art.

Claims (8)

1. The power-down prevention data backup method for the IC card is characterized by comprising the following steps of:
step S310, backing up the whole data page in the first page to be backed up in the data area to the first protection page of the first partition, increasing the backup identification, and writing the effective mark into the first mark area of the mark page of the first partition;
Step S320, repeating the step S310 until the whole page of the data in the E-th page to be backed up in the data area is backed up to the E-th protection page of the first partition, increasing the backup mark, and writing a valid mark into the E-th mark area of the mark page of the first partition;
Step S330, backing up the backup record of the data in the E+1th page to be backed up in the data area to the backup area, backing up the whole page of the data in the E+1th page to be backed up in the data area to the first protection page of the second partition, and sequentially and circularly writing effective marks into mark areas of idle pages of the first partition and the second partition according to the sequence from the first partition to the second partition;
Step S340, repeating the step S330 until the backup record of the data in the nth page to be backed up in the data area is backed up in the backup area, and the whole page of the data in the nth page to be backed up in the data area is backed up in the nth-E protection page of the second partition, so that the data backup is completed;
step S350, in response to the completion of data updating, writing a failure mark in an E mark area of a mark page of the first partition, and setting a backup mark to zero;
Wherein n is the number of pages related to the data to be backed up in the data area, E < n is less than or equal to E+F, E is the number of protection pages in the first partition, and F is the data of the protection pages in the second partition.
2. The power-down prevention data backup method for the IC card is characterized by comprising the following steps of:
step S410, backing up the whole data page in the first page to be backed up in the data area to the first protection page of the first partition, increasing the backup identification, and writing the effective mark into the first mark area of the mark page of the first partition;
Step S420, repeating the step S410 until the whole page of the data in the E-th page to be backed up in the data area is backed up to the E-th protection page of the first partition, increasing the backup mark, and writing the effective mark into the E-th mark area of the mark page of the first partition;
Step S430, backing up the backup record of the data in the E+1th page to be backed up in the data area to the backup area, backing up the whole page of the data in the E+1th page to be backed up in the data area to the first protection page of the second partition, and writing effective marks into mark areas of idle pages of the first partition and the second partition in sequence from the first partition to the second partition;
Step S440, repeating the step S430 until the backup record of the data in the E+F page to be backed up in the data area is backed up to the backup area, and backing up the whole data page in the E+F page to be backed up in the data area to the F protection page of the second partition;
step S450, repeating the step S430 and the step S440 until the backup record of the data in the nth page to be backed up in the data area is backed up in the backup area, and the whole page of the data in the nth page to be backed up in the data area is backed up in the nth-E-aF protection page of the second partition, and writing effective marks into mark areas of idle pages of the first partition and the second partition in sequence from the first partition to the second partition, so as to finish the data backup, wherein a is the number of times that all protection pages of the second partition are used;
step S460, in response to the completion of the data updating, writing a failure flag in an E-th flag area of a flag page of the first partition, and setting a backup flag to zero;
wherein n is the number of pages related to the data to be backed up in the data area, E+F < n, E is the number of protection pages in the first partition, and F is the data of the protection pages in the second partition.
3. The method for recovering the power-down prevention data of the IC card is characterized in that when the power-down condition occurs in the process of backing up and updating the data according to claim 1 or claim 2, after the power-up is restarted, a recovery flow is entered, and the recovery flow comprises the following steps:
Step S510, inquiring whether a failure mark exists in a mark area of the mark page, if so, not needing to carry out data recovery, and if not, carrying out step S520;
Step S520, checking the valid flags in the flag areas from the second partition to the first partition from the back to the front until the valid flags are checked to pass, and performing step S530;
step S530, if the backup mark is smaller than E, the effective marks in the mark areas of the mark pages of the first partition are compared, and the whole page data backed up in the first partition protection page is sequentially restored to the data area from back to front;
where E is the number of guard pages in the first partition.
4. The IC card power-down prevention data recovery method according to claim 3, further comprising the steps of:
And S540, checking the mark areas of the idle pages of the second partition and the first partition from the back to the front if the backup mark is a preset value, and recovering the data backed up by the E protection pages of the first partition from the back to the front to the data area sequentially.
5. The IC card power-down prevention data recovery method according to claim 4, further comprising the steps of:
step S550, if the mark area of the idle page is not empty, checking whether the last valid mark recorded in the mark area of the idle page is valid, and if so, restoring the whole data page backed up in the protection page of the second partition corresponding to the last valid mark to the data area;
Step S560, checking the backup records in the backup area in turn, and recovering the data to the data area from the back to the front through the backup records in turn;
Step 570, restore the data backed up in the E protection pages in the first partition to the data area from the back to the front.
6. An IC card, comprising: the device comprises a processor and a memory, wherein the memory comprises a data area, a backup area and an anti-pulling area;
the anti-pulling area comprises: the system comprises a first partition and a second partition, wherein the first partition is provided with a protection page, a sign page and a free page, and the second partition is provided with a protection page, a sign page and a free page;
the processor executes the method for backup of power failure prevention data of the IC card according to any one of claims 1 to 2, or
The processor executes the IC card power-down prevention data recovery method of any one of the above claims 3 to 5.
7. The IC card of claim 6, wherein the first partition and the second partition are each one sector size.
8. The IC card according to claim 6, wherein the first partition has 12 protection pages, 3 flag pages, and 1 free page, and the second partition has 12 protection pages, 3 flag pages, and 1 free page.
CN202010603726.XA 2020-06-29 2020-06-29 IC card and anti-power-down data backup method or data recovery method thereof Active CN111737058B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202010603726.XA CN111737058B (en) 2020-06-29 2020-06-29 IC card and anti-power-down data backup method or data recovery method thereof

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202010603726.XA CN111737058B (en) 2020-06-29 2020-06-29 IC card and anti-power-down data backup method or data recovery method thereof

Publications (2)

Publication Number Publication Date
CN111737058A CN111737058A (en) 2020-10-02
CN111737058B true CN111737058B (en) 2024-05-28

Family

ID=72651712

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202010603726.XA Active CN111737058B (en) 2020-06-29 2020-06-29 IC card and anti-power-down data backup method or data recovery method thereof

Country Status (1)

Country Link
CN (1) CN111737058B (en)

Families Citing this family (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN113785275B (en) * 2020-12-17 2024-03-05 深圳杰睿联科技有限公司 Flash data power-down protection method and device
CN114356792B (en) * 2021-11-18 2023-03-10 国电南瑞三能电力仪表(南京)有限公司 Electric energy meter frozen data storage method based on FLASH pre-erasing technology and electric energy meter

Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
JP2005302226A (en) * 2004-04-15 2005-10-27 Funai Electric Co Ltd Optical disk recorder
CN102789404A (en) * 2011-05-20 2012-11-21 北京同方微电子有限公司 Method for storing anti-dropping data during updating of integrated circuit (IC) card data
CN104461770A (en) * 2014-10-31 2015-03-25 上海动联信息技术股份有限公司 Power-off protection method of Flash chip
CN111104253A (en) * 2019-11-22 2020-05-05 江苏恒宝智能系统技术有限公司 Power-down protection smart card and working method thereof

Patent Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
JP2005302226A (en) * 2004-04-15 2005-10-27 Funai Electric Co Ltd Optical disk recorder
CN102789404A (en) * 2011-05-20 2012-11-21 北京同方微电子有限公司 Method for storing anti-dropping data during updating of integrated circuit (IC) card data
CN104461770A (en) * 2014-10-31 2015-03-25 上海动联信息技术股份有限公司 Power-off protection method of Flash chip
CN111104253A (en) * 2019-11-22 2020-05-05 江苏恒宝智能系统技术有限公司 Power-down protection smart card and working method thereof

Also Published As

Publication number Publication date
CN111737058A (en) 2020-10-02

Similar Documents

Publication Publication Date Title
US7639537B2 (en) Method for writing data in a non volatile memory unit
CN102081577B (en) Data storage structure of Flash memory and data manipulation mode thereof
US6839568B2 (en) User setting information management method and management system for portable telephone
CN101344868B (en) Data backup and acquiring method and device
CN101251826B (en) Flash memory, method and apparatus for data management of flash memory
US8046530B2 (en) Process and method for erase strategy in solid state disks
US7725646B2 (en) Method of using a flash memory for a circular buffer
CN111737058B (en) IC card and anti-power-down data backup method or data recovery method thereof
JP2846739B2 (en) Method for safely updating EEPROM memory
CN102999564B (en) Write the method for data, device and equipment
CN113785275A (en) Flash data power-down protection method and device
CN109614055B (en) Snapshot creating method and device, electronic equipment and machine-readable storage medium
CN106227680A (en) A kind of data process and power fail preventing data guard method
CN100437504C (en) Hard disc data backup system and method
CN111104253B (en) Smart card for power failure protection and working method thereof
CN109685190B (en) Power-down protection method and device for IC card
CN116088770B (en) Data management method, device, system, electronic equipment and storage medium
CN111666046B (en) Data storage method, device and equipment
US11726668B2 (en) Device with flash memory and method for writing/erasing/updating data in flash memory thereof
CN109960611B (en) Data recovery method and device, electronic equipment and machine-readable storage medium
JP3494676B2 (en) Nonvolatile semiconductor memory device and data rewriting / reading method
WO2010145967A1 (en) Memory device for managing the recovery of a non volatile memory
JP2001084180A (en) File managing device
CN116027973A (en) Data writing method and device based on flash memory
JP3978720B2 (en) Data storage method

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