Movatterモバイル変換


[0]ホーム

URL:


CN113434438A - Method for prolonging writing life of FLASH of smart card - Google Patents

Method for prolonging writing life of FLASH of smart card
Download PDF

Info

Publication number
CN113434438A
CN113434438ACN202110661150.7ACN202110661150ACN113434438ACN 113434438 ACN113434438 ACN 113434438ACN 202110661150 ACN202110661150 ACN 202110661150ACN 113434438 ACN113434438 ACN 113434438A
Authority
CN
China
Prior art keywords
block
file
polling
space
writable
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Granted
Application number
CN202110661150.7A
Other languages
Chinese (zh)
Other versions
CN113434438B (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.)
Wuhan Tianyu Information Industry Co Ltd
Original Assignee
Wuhan Tianyu Information Industry 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 Wuhan Tianyu Information Industry Co LtdfiledCriticalWuhan Tianyu Information Industry Co Ltd
Priority to CN202110661150.7ApriorityCriticalpatent/CN113434438B/en
Publication of CN113434438ApublicationCriticalpatent/CN113434438A/en
Application grantedgrantedCritical
Publication of CN113434438BpublicationCriticalpatent/CN113434438B/en
Activelegal-statusCriticalCurrent
Anticipated expirationlegal-statusCritical

Links

Images

Classifications

Landscapes

Abstract

The invention provides a method for prolonging the writing life of a FLASH of an intelligent card, which belongs to the technical field of data storage of the intelligent card, and comprises the steps that when a file system creates a file, a plurality of bytes are expanded at a file header to store the initial address and the polling page number of the file in the FLASH, a polling space comprising a plurality of physical pages is divided in the FLASH according to the initial address and the polling page number, and a file body and a mark header are written into the polling space as a data block; when the file system updates the file, the polling space is traversed by taking the block size of the data block as a unit until an effective block is found, the next continuous storage space of the effective block is judged to be a writable block, the updated file is written into the writable block, and the storage capacity of the next continuous storage space is the same as the block size of the data block. The invention can traverse the polling space by taking the block size of the data block as a unit until finding the effective block and the writable block through a polling mode in the FLASH page, and directly write new data in the writable block, thereby improving the writing efficiency and the writing life.

Description

Method for prolonging writing life of FLASH of smart card
Technical Field
The invention relates to the technical field of data storage of smart cards, in particular to a method for prolonging the FLASH write-in life of a smart card.
Background
Traditionally, the above file system is implemented in an extremely simple storage manner, and file entries and file contents are stored together and stored continuously on a physical medium. Since FLASH is generally used as the storage medium of the smart card file system, when updating the file content, the erase operation must be performed on the physical medium occupied by the file first, and then the write operation can be performed. Due to the physical limitations of FLASH, the erase operation takes a long time, thus reducing the efficiency of the file system write. Meanwhile, since the storage address of the file on the physical medium is fixed, the storage area occupied by the file is worn quickly when the file is written at a high frequency, and the service life of the storage medium is reduced.
In order to prolong the service life of the storage medium, a wear leveling algorithm is needed, specifically, writing of a file is distributed to a plurality of areas of the storage medium, rather than being fixedly stored by using the same address. At present, various different wear leveling algorithms are developed aiming at a high-capacity FLASH medium, such as NANDFlash, and the effect is also excellent enough.
However, due to the particularity of the smart card storage scenario, most current wear leveling algorithms are not applicable. For example, patent application No. CN201811530906 discloses a method for improving FLASH write lifetime of a smart card file system, where a physical block (the physical block is a minimum erase unit of a FLASH storage medium) needs to be switched to rewrite every time data is updated, that is, every time data is updated, a page needs to be changed to rewrite the data, and if the size of a file is much smaller than the size of a block (or much smaller than the size of each physical block included in a physical page of a chip), every time the file is updated, the file occupies the entire physical block, which results in low space utilization. In the limited space of the smart card, more files need to be updated, fewer idle physical blocks need to be erased frequently to update data, and therefore, the effect of improving the write life by adopting the method is smaller, and the integrity and the effectiveness of the data cannot be guaranteed by adopting the method to write the data.
Disclosure of Invention
Aiming at the defects in the prior art, the invention aims to provide a method for prolonging the writing life of a smart card FLASH, which updates file data in a FLASH page polling mode, prolongs the service life of the FLASH, and simultaneously adds a Cyclic Redundancy Check (CRC) to ensure the integrity of the data.
In order to achieve the above purposes, the technical scheme is as follows:
a method of improving smart card FLASH write life, the method comprising:
when a file system creates a file, a plurality of bytes are expanded at a file header to store the initial address and the polling page number of the file in a FLASH, a polling space comprising a plurality of physical pages is divided in the FLASH according to the initial address and the polling page number, a file body and a mark header are written into the polling space as a data block, and the mark header comprises a counter and a first CRC;
when the file system updates the file, the polling space is traversed by taking the block size of the data block as a unit until an effective block is found, the next continuous storage space of the effective block is judged to be a writable block, the updated file is written into the writable block, and the storage capacity of the next continuous storage space is the same as the block size of the data block.
Preferably, when the file system creates a file, after the file header is extended by 5 bytes, a start address of 4 bytes and the number of polling pages of 1 byte are written.
Preferably, the number of polling pages is the same as the number of physical pages in the polling space;
the storage capacity of the polling space is greater than the total number of bytes of the file.
Preferably, when the file system creates a file, a 16-byte flag header is configured for the file body, the 16-byte flag header includes a counter of 4 bytes and a first CRC of 2 bytes, and the remaining bytes are reserved.
Preferably, when the file system updates the file, the step of traversing the polling space by using the block size of the data block as a unit until a valid block is found is as follows:
a1, intercepting a current continuous storage space in the part which is not intercepted in the polling space of the file by taking the block size of the data block as a unit;
step a2, calculating a second CRC of the data stored in the current continuous storage space, and judging whether the first CRC and the second CRC in the marker header of the current continuous storage space are the same:
if yes, go to step a 3;
if not, judging that the current continuous storage space is an invalid block, and then turning to the step a 4;
step a3, judging whether the value of the counter of the current continuous storage space is larger than the value of the counter of the previous continuous storage space:
if yes, then the current continuous storage space is judged as a possible block, and then step a4 is executed;
if not, judging that the current continuous storage space is an invalid block, and then turning to the step a 4;
step a4, judging whether the storage capacity of the part which is not intercepted in the polling space of the file is larger than the block size of the data block:
if yes, go to step a 1;
and if not, the block with the maximum counter value in all the possible blocks is the valid block.
Preferably, the step of determining the next continuous storage space of the valid block as a writable block is as follows:
step b1, according to the address sequence of the polling space, judging whether the storage capacity behind the effective block in the physical page where the effective block is located is larger than the storage capacity of the effective block:
if so, taking the storage address behind the effective block in the physical page of the effective block as the initial address of the next continuous storage space, and judging the next continuous storage space as a writable block;
if not, the header address of the next physical page is used as the starting address of the next continuous storage space, and the next continuous storage space is judged to be a writable block.
Preferably, if the physical page in which the valid block is located is the last page of the polling space, and the storage capacity of the physical page in which the valid block is located after the valid block is smaller than the storage capacity of the valid block, the page head address of the start page of the polling space is used as the start address of the next continuous storage space.
Preferably, when the valid block and the writable block are located in the same physical page, if there is storage data in the writable block, the next continuous storage space of the writable block is used as the writable block and an updated file is written.
Preferably, when the valid block and the writable block are located in different physical pages, if the writable block has stored data, the physical page in which the writable block is located is subjected to data erasure and an updated file is written.
Preferably, the step of writing the updated file to the writable block is as follows:
step c1, obtaining the count value of the counter from the effective block, and writing the count value into the counter of the writable block after adding 1;
step c2, calculating CRC value for the updated file, and writing the CRC value into the first CRC of the writable block;
step c3, writing the file body of the updated file to the writable block.
The invention has the beneficial effects that: by the polling mode in the FLASH page, the polling space is traversed by taking the block size of the data block as a unit until a valid block and a writable block are found, and new data is directly written into the writable block, so that the method is much more efficient compared with the method that the page is firstly erased and then rewritten every time. The invention divides one page or a plurality of pages into a plurality of blocks, when updating the file each time, only the blocks are updated in sequence, and the blocks occupy the polling space and then are erased, so that one physical page can be repeatedly used, and the service life of the Flash is prolonged.
The CRC of the tag header and the file body is calculated before updating the file, and then the writable block is written. If the power is abnormally lost when the writable block is written, the data is not completely written, the CRC stored in the writable block is different from the CRC value calculated by actual data, and the data is treated as an invalid block because the CRC is not compared sufficiently when a valid block is searched in a subsequent traversal. At this time, the valid data of the file is still stored in the valid block, and the integrity of the file data is ensured.
Drawings
Fig. 1 is a flowchart of a method for improving the FLASH write lifetime of a smart card in an embodiment of the present invention.
FIG. 2 is a flowchart illustrating finding valid blocks when a file system updates a file according to an embodiment of the present invention.
FIG. 3 is a flowchart illustrating determining writable blocks when a file system updates a file according to an embodiment of the present invention.
FIG. 4 is a flowchart illustrating writing of an updated file into a writable block when the file system updates the file according to an embodiment of the present invention.
Detailed Description
In order to make the objects, technical solutions and advantages of the present invention more apparent, the present invention is described in further detail below with reference to the accompanying drawings and embodiments. It should be understood that the specific examples described herein are intended to be illustrative only and are not intended to be limiting. Moreover, all other embodiments that can be derived by a person skilled in the art from the embodiments of the present invention without making any creative effort belong to the protection scope of the present invention.
The present invention will be described in further detail with reference to the accompanying drawings and examples.
As shown in fig. 1, a method for improving FLASH write lifetime of a smart card includes:
step S1, when the file system creates the file, the file header extends a plurality of bytes to store the initial address and polling page number of the file in the FLASH, the polling space comprising a plurality of physical pages is divided in the FLASH according to the initial address and the polling page number, the file body and the marking header are written into the polling space as a data block, the marking header comprises a counter and a first CRC, and the first CRC is obtained by data in the calculation block.
Step S2, when the file system updates the file, the polling space is traversed by taking the block size of the data block as a unit until an effective block is found, the next continuous storage space of the effective block is judged to be a writable block, the updated file is written into the writable block, and the storage capacity of the next continuous storage space is the same as the block size of the data block.
In this embodiment, after traversing the polling space to find the valid block, it is determined whether the remaining storage space of the page where the valid block is located can form a continuous storage space with the same storage capacity as the block size of the data block, if so, a data block located behind the valid block in the page where the valid block is located is a writable block, and if not, a first database located at the head of the page in the next page where the valid block is located is a writable block. Subsequently, the updated file is written into the writable block.
By the polling mode in the FLASH page, the polling space is traversed by taking the block size of the data block as a unit until a valid block and a writable block are found, and new data is directly written into the writable block, so that the method is much more efficient compared with the method that the page is firstly erased and then rewritten every time. The invention divides one page or a plurality of pages into a plurality of blocks, when updating the file each time, only the blocks are updated in sequence, and the blocks occupy the polling space and then are erased, so that one physical page can be repeatedly used, and the service life of the Flash is prolonged.
Further, when the file system creates a file, after the file header is extended by 5 bytes, a start address of 4 bytes and the polling page number of 1 byte are written.
Further, the storage capacity of the polling space is larger than the total number of bytes of the file.
Further, when the file system creates a file, a 16-byte flag header is configured for the file body, and the 16-byte flag header includes a counter of 4 bytes and a first CRC of 2 bytes.
Further, as shown in fig. 2, when the file system updates the file, the specific steps of traversing the polling space by using the block size of the data block as a unit until a valid block is found are as follows:
a1, intercepting a current continuous storage space in the part which is not intercepted in the polling space of the file by taking the block size of the data block as a unit;
step a2, calculating a second CRC of the data stored in the current continuous storage space, and judging whether the first CRC and the second CRC in the marker header of the current continuous storage space are the same:
if yes, go to step a 3;
if not, judging that the current continuous storage space is an invalid block, and then turning to the step a 4;
step a3, judging whether the value of the counter of the current continuous storage space is larger than the value of the counter of the previous continuous storage space:
if yes, then the current continuous storage space is judged as a possible block, and then step a4 is executed;
if not, judging that the current continuous storage space is an invalid block, and then turning to the step a 4;
step a4, judging whether the storage capacity of the part which is not intercepted in the polling space of the file is larger than the block size of the data block:
if yes, go to step a 1;
and if not, the block with the maximum counter value in all the possible blocks is the valid block.
Specifically, when the file is updated every time, the file is searched from the start address backward in sequence by taking the block size of the data block as a unit according to the start address and the allocated polling page number, the second CRC of the data in the block is calculated in sequence, whether the second CRC is consistent with the first CRC in the marking head of the block where the second CRC is located is checked, and if the second CRC is consistent with the first CRC in the marking head of the block where the first CRC is located and the value of a counter in the marking head is larger than that in the previous block, the block is considered to be an effective block.
Further, as shown in fig. 3, the specific steps of determining that the next consecutive storage space of the valid block is a writable block are as follows:
step b1, according to the address sequence of the polling space, judging whether the storage capacity behind the effective block in the physical page where the effective block is located is larger than the storage capacity of the effective block:
if so, taking the storage address behind the effective block in the physical page of the effective block as the initial address of the next continuous storage space, and judging the next continuous storage space as a writable block.
If not, the header address of the next physical page is used as the starting address of the next continuous storage space, and the next continuous storage space is judged to be a writable block.
Furthermore, if the physical page in which the valid block is located is the last page of the polling space, and the storage capacity of the physical page in which the valid block is located after the valid block is smaller than the storage capacity of the valid block, the page head address of the start page of the polling space is used as the start address of the next continuous storage space.
And when the valid block and the writable block are located in the same physical page, if the writable block has stored data, using the next continuous storage space of the writable block as the writable block, and writing an updated file in the writable block.
And when the valid block and the writable block are located in different physical pages, if the writable block has stored data, performing data erasing on the physical page where the writable block is located, and writing an updated file into the writable block.
Specifically, the address of the valid block with the largest counter value is checked, the remaining space and the block size in the page where the valid block is located are checked, if the remaining space is enough, the tag head counter of the valid block is read, the counter value +1 is used for calculating the CRC of the file to be written, and then the CRC and the file body of the file to be written are written into the subsequent area of the block together, namely the writable block. And if the residual space is insufficient, checking whether a physical page of the effective block is the last page of the polling space, if so, erasing the first page of the polling space and then writing the data, if not, switching to the next page to write the data, before writing, checking whether the region can be written, and if not, searching backwards.
Further, as shown in fig. 4, the specific steps of writing the updated file into the writable block are as follows:
step c1, obtaining the counter value of the counter from the effective block, and writing the counter value into the counter of the writable block after adding 1.
Step c2, calculates a CRC value for the updated file and writes the CRC value to the first CRC of the writable block.
Step c3, writing the file body of the updated file to the writable block.
Specifically, the CRC of the file to be written is calculated and then written as the first CRC in the writable block together with the file body of the file to be written in the subsequent area of the block.
In one embodiment, 2 physical pages are divided into FLASH of the smart card as a polling space to store the file body of the file with high updating frequency, and the initial address of the polling space is set to 0x 0002000.
5 bytes (including a start address of 4 bytes and a polling page number of 1 byte) are extended in the header. And simultaneously writing data of a data block in the polling space, wherein the data block comprises a 16-byte marking head (comprising a counter of 4 bytes and a first CRC of 2 bytes, and other bytes are not written temporarily) and a file body.
When updating the file content, the initial address and polling page number of the file in the polling space are read from the file header, and are 0x0002000 and 2 pages respectively. Assuming that the block size of a data block (including a tag header and a file body) is 0x32 bytes, the page size of a physical page is 0x200 bytes, traversal is performed in units of 0x32 bytes from addresses 0x0002000 to 0x0002400, the value of a counter included in the tag header in each block is read, a second CRC of data within the block in each block is calculated and compared with a first CRC in the tag header, if the same and the value of the counter is greater than the value of a counter included in the tag header in a previous block, the current block is considered to be a valid block, the address of the current block is obtained after traversal, the current block is considered to be a valid block, and the address of the current block is the address of the valid block.
And searching the address of the next writable block backwards according to the address of the effective block, for example, if the address of the effective block is 0x00020032, the address range of the next block is 0x 00020064-0 x00020096, if the ending address of the next block is not in the same page as the starting address of the effective block, the header address of the next page is used as the starting address of the next block, and if the ending address of the next block exceeds the polling space, the header content of the polling space is erased, and the header address of the polling space is used as the address of the next block.
Checking whether the space where the address of the next block is located can be written, if the space can not be written, skipping the block, continuing to search backwards, if the space can not be written, obtaining the value of the marking head counter of the effective block, adding the value of the counter to +1, then calculating the first CRC of the data in the block which is to be updated and written into the writable block, and finally writing the file body content and the marking head content which need to be updated.
The CRC of the tag header and the file body is calculated before updating the file, and then the writable block is written. If the power is abnormally lost when the writable block is written, the data is not completely written, the CRC stored in the writable block is different from the CRC value calculated by actual data, and the data is treated as an invalid block because the CRC is not compared sufficiently when a valid block is searched in a subsequent traversal. At this time, the valid data of the file is still stored in the valid block, and the integrity of the file data is ensured.
The present invention is not limited to the above-described embodiments, and it will be apparent to those skilled in the art that various modifications and improvements can be made without departing from the principle of the present invention, and such modifications and improvements are also considered to be within the scope of the present invention. Those not described in detail in this specification are within the skill of the art.

Claims (10)

CN202110661150.7A2021-06-152021-06-15Method for prolonging FLASH write-in life of smart cardActiveCN113434438B (en)

Priority Applications (1)

Application NumberPriority DateFiling DateTitle
CN202110661150.7ACN113434438B (en)2021-06-152021-06-15Method for prolonging FLASH write-in life of smart card

Applications Claiming Priority (1)

Application NumberPriority DateFiling DateTitle
CN202110661150.7ACN113434438B (en)2021-06-152021-06-15Method for prolonging FLASH write-in life of smart card

Publications (2)

Publication NumberPublication Date
CN113434438Atrue CN113434438A (en)2021-09-24
CN113434438B CN113434438B (en)2023-03-14

Family

ID=77755865

Family Applications (1)

Application NumberTitlePriority DateFiling Date
CN202110661150.7AActiveCN113434438B (en)2021-06-152021-06-15Method for prolonging FLASH write-in life of smart card

Country Status (1)

CountryLink
CN (1)CN113434438B (en)

Cited By (1)

* Cited by examiner, † Cited by third party
Publication numberPriority datePublication dateAssigneeTitle
CN114115743A (en)*2021-11-292022-03-01苏州迅镭激光科技有限公司Method for prolonging service life of data storage chip

Citations (7)

* Cited by examiner, † Cited by third party
Publication numberPriority datePublication dateAssigneeTitle
US20050210076A1 (en)*2004-03-222005-09-22Microsoft CorporationComputing device with relatively limited storage space and operating/file system thereof
JP2012068765A (en)*2010-09-212012-04-05Tdk CorpMemory controller, flash memory system with memory controller, and control method of flash memory
CN103577121A (en)*2013-11-052014-02-12中船重工(武汉)凌久电子有限责任公司High-reliability linear file access method based on nand flash
CN105183392A (en)*2015-09-182015-12-23广州日滨科技发展有限公司Method for storing fixed-length data on FLASH
CN105677383A (en)*2015-12-282016-06-15北京华大智宝电子系统有限公司Method for updating data of smart card
CN106527969A (en)*2016-09-212017-03-22中国科学院地质与地球物理研究所NandFlash memory read-write method capable of guaranteeing service life balance
CN110515798A (en)*2019-08-082019-11-29吉林大学 SD card-based storage system with performance lifetime assessment and storage method thereof

Patent Citations (7)

* Cited by examiner, † Cited by third party
Publication numberPriority datePublication dateAssigneeTitle
US20050210076A1 (en)*2004-03-222005-09-22Microsoft CorporationComputing device with relatively limited storage space and operating/file system thereof
JP2012068765A (en)*2010-09-212012-04-05Tdk CorpMemory controller, flash memory system with memory controller, and control method of flash memory
CN103577121A (en)*2013-11-052014-02-12中船重工(武汉)凌久电子有限责任公司High-reliability linear file access method based on nand flash
CN105183392A (en)*2015-09-182015-12-23广州日滨科技发展有限公司Method for storing fixed-length data on FLASH
CN105677383A (en)*2015-12-282016-06-15北京华大智宝电子系统有限公司Method for updating data of smart card
CN106527969A (en)*2016-09-212017-03-22中国科学院地质与地球物理研究所NandFlash memory read-write method capable of guaranteeing service life balance
CN110515798A (en)*2019-08-082019-11-29吉林大学 SD card-based storage system with performance lifetime assessment and storage method thereof

Non-Patent Citations (1)

* Cited by examiner, † Cited by third party
Title
尹伟等: "基于Flash智能卡文件系统的设计", 《微计算机信息》*

Cited By (1)

* Cited by examiner, † Cited by third party
Publication numberPriority datePublication dateAssigneeTitle
CN114115743A (en)*2021-11-292022-03-01苏州迅镭激光科技有限公司Method for prolonging service life of data storage chip

Also Published As

Publication numberPublication date
CN113434438B (en)2023-03-14

Similar Documents

PublicationPublication DateTitle
CN110347336B (en) A key-value storage system based on NVM and SSD hybrid storage structure
US6675281B1 (en)Distributed mapping scheme for mass storage system
US11726712B2 (en)Memory system with write modes based on an internal state of a memory controller
US10915475B2 (en)Methods and apparatus for variable size logical page management based on hot and cold data
US7702844B2 (en)Address mapping method and mapping information managing method for flash memory, and flash memory using the same
US6865658B2 (en)Nonvolatile data management system using data segments and link information
CN103257831B (en)The read/writing control method of memorizer and the memorizer of correspondence
US20150169465A1 (en)Method and system for dynamic compression of address tables in a memory
US20090276586A1 (en)Wrap-around sequence numbers for recovering from power-fall in non-volatile memory
CN112860594B (en) A solid-state disk address remapping method, device and solid-state disk
US6742078B1 (en)Management, data link structure and calculating method for flash memory
CN112486852A (en)Solid state disk and address mapping method thereof
CN112612418B (en)Method and system for managing large-capacity NandFlash bad blocks
CN117891415B (en)P2L data management method and device of storage device
CN105183392B (en)A kind of storage method of fixed-length data in FLASH
CN111913890B (en)Random read-write method of nonvolatile memory based on security module
CN102063380A (en)Method and device for writing data in non-volatile memory
US8261013B2 (en)Method for even utilization of a plurality of flash memory chips
CN108491290B (en)Data writing method and device
CN112597072A (en)Data updating method and device of Flash memory
CN111061649A (en)Self-adaptive allocation method for storage space of memory
CN113434438B (en)Method for prolonging FLASH write-in life of smart card
CN112527207A (en)Method and device for storing data in EEPROM
CN112100091B (en)Two-level mapping table data mapping method and device, storage medium and electronic equipment
US20090055574A1 (en)NAND Flash Memory Device And Related Method Thereof

Legal Events

DateCodeTitleDescription
PB01Publication
PB01Publication
SE01Entry into force of request for substantive examination
SE01Entry into force of request for substantive examination
GR01Patent grant
GR01Patent grant

[8]ページ先頭

©2009-2025 Movatter.jp