A FLASH chip storage area and its high-performance power-off protection reading and writing method
By adopting the design of alternately used erasing and writing record pages and erasing and writing operation recording areas in the FLASH chip storage area, the problem of low erasing and writing efficiency in the existing technology is solved, efficient data protection and writing are realized, and high-efficiency data protection and writing are achieved. Transaction time requirements in performance business scenarios.
Patent Information
- Application Number
- CN202110558676.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-05-21
- Publication Date
- 2024-09-17
- Estimated Expiration
- 2041-05-21
AI Technical Summary
Due to the low efficiency of the power loss protection mechanism of the existing FLASH chip storage area during erasing and writing, the chip cannot meet the transaction time requirements in high-performance business scenarios, and erasing and writing efficiency is low and takes a long time.
Adopting a FLASH chip storage area design, including the first data area, the second data area and the erase and write operation record area, by rotating the erase and write record pages to avoid backup, and determine the data writing page according to the content of the erase and write record unit , and write the record page when the erasing transaction is completed to improve erasing efficiency.
It has implemented an efficient erasure and write protection mechanism, which can not only protect the original page data, but also write new data efficiently, significantly improving the erasure and write performance of the chip and shortening the transaction time.
Smart Images

Figure CN113190470B
Abstract
Description
Technical Field
[0001] The present invention relates to the field of chip power-off protection, and in particular to a FLASH chip storage area and a high-performance power-off protection reading and writing method thereof. Background Art
[0002] For the FLASH chip storage area, there are more or less differences in erasing and reading data due to different designs and processes. However, the storage area is in pages, which allow programming and erasing. Erasing a page requires erasing all data in the page and then writing new data. If power is lost during this process, the original data may be lost, and the chip cannot guarantee the integrity and validity of the data in the storage area. Therefore, a power failure protection mechanism is designed in the prior art to ensure that the original data is not lost when erasing data, or that the new data can be completely and effectively written to the page.
[0003] In the prior art, there are two schemes for power failure protection mechanism. One is to back up the original old data. When the page erase fails, the original data of the page can be restored. The other scheme is to back up the new data. Before writing the new data to the first data area, write it into a backup page. After the erase transaction operation record is successfully submitted, the data of the backup page is written into the user data page. In this process, if the power fails before the erase operation transaction is submitted, the user data page will still be the original old data. If the power fails after the erase operation transaction is submitted, the backup page data can be written into the user data page by querying the erase transaction every time the chip is powered on. Both of the above schemes can ensure that the data of the erased FLASH page is not lost due to power failure, but the timing of the successful submission of the erase transaction operation record is different, the efficiency of completing the erase page is different, and each has its own advantages and disadvantages:
[0004] The first type of power-off protection mechanism requires completing the backup of old data, submitting the erase transaction operation record, and writing the new data to the user data page before reading the new data. The erase efficiency is low, but the data reading efficiency is high.
[0005] The second type of power-off protection mechanism only requires that new data be written to the backup page before new data can be read. There is no need to successfully submit the erase transaction operation record. However, reading data requires querying the erase transaction operation record. It is necessary to ensure that the new data has been written to the backup page before reading the new data from the backup page. The erase efficiency is higher than backing up old data, but the data reading efficiency is relatively low.
[0006] For example, if it takes 3ms to erase a page, to complete erasing N pages, for the old data backup solution, (2*N+N) pages need to be erased, which takes ((2*N+N)*3)ms. For the new data backup solution, (2*N+1) pages need to be erased, which takes ((2*N+1)*3)ms. This time is more than twice that of erasing only user pages without power failure protection.
[0007] However, in order to meet the needs of users for a good experience in existing businesses, chips are often required to execute efficiently. For example, cash business requires 500ms to complete transactions, and wallet transactions are within 300ms. From the perspective of optimizing performance, the longest time is spent on erasing FLASH pages. The more you erase, the lower the efficiency. The two existing power-off protection mechanisms cannot meet the needs of existing businesses in terms of efficiency. Therefore, there is an urgent need for a power-off protection method that can improve the high performance of FLASH chip erasing. Summary of the invention
[0008] The present invention provides a FLASH chip storage area, including a first data area, a second data area and an erase operation record area; the first data area is used to store user data, the second data area is used to store new data of the erased page, and the erase operation record area records the erase records of the FLASH page, and the erase is performed by page, and is used in rotation without backup, and it is required that the erase record page currently written cannot be the same as the erase record page written before; each erase record unit corresponds to a page in the second data area or the first data area;
[0009] When erasing a page, a page belonging to the first data area or the second data area is determined based on the content in the erase record page in the erase operation record area, and then the new data is written to the page; if multiple pages are to be erased, multiple pages are determined based on the content in the erase record page, and then the new data is written to each page, and the erase record is written to the erase record page when the erase transaction is completed.
[0010] In the FLASH chip storage area as described above, the erase operation recording area is allocated with at least two erase recording pages, which are a valid recording page and an invalid recording page.
[0011] As described above, in the FLASH chip storage area, the erase record page is composed of records with 2 bytes as units; the first two bytes are record information, the last two bytes are checksums of all valid records, and all bytes in between are erase record units.
[0012] As described above, in the FLASH chip storage area, in the first two bytes, the first byte records the erase record number, the maximum value is the latest erase sequence number, and the second byte records the number of valid records in the erase record unit, including the number of erase record units in the transaction.
[0013] In the FLASH chip storage area as described above, each erase and write record unit records the backup data available page identifier, and determines whether the page belongs to the first data area or the second data area according to the value of the backup data available page identifier.
[0014] As described above, in the FLASH chip storage area, when the pages in the second data area are used up or other services in the existing services do not require performance, the user data in the second data area is written back to the first data area according to the erase record unit encoding, and the corresponding erase record unit is released for subsequent erase page protection.
[0015] The FLASH chip storage area as described above, wherein the erasure record unit is checked when the chip is powered on, and the erasure record unit with the correct check core and the largest erasure record number in the erasure record unit is found, and the largest erasure record unit is used as a valid erasure record unit for subsequent reading or erasing of valid data.
[0016] The present application also provides a high-performance anti-power-off erasing method, which is applied to the FLASH chip storage area described in any one of the above items, and the method comprises:
[0017] Step 11, according to the address A of the data to be written, check whether the data in address A is in the cache, if yes, execute step 14, otherwise execute step 12;
[0018] Step 12, determine whether the record corresponding to address A can be found in the erase record page, if yes, execute step 13, otherwise allocate a new record unit position in the erase record page, encode the address into a record unit and write it into the record unit position, and then execute step 13;
[0019] Step 13, according to the cache address, find the corresponding erasure record unit in the erasure page record table, decode the address B according to the erasure record unit, write the data in the cache to the address B, encode the address A into the erasure record unit and write it into the erasure page record table;
[0020] Step 14, write the data to be written to address A into the cache, and continue to determine whether there is new data that needs to be written. If so, return to execute Step 11, otherwise write the erase page record table into the erase record page, and the data erase is completed.
[0021] The present application also provides a chip storage area page data reading method, which is applied to any of the above-mentioned FLASH chip storage areas, and the method comprises:
[0022] Step 21, according to the address C to be read, check whether the data at address C has been cached, if so, read the data from the cache and execute step 24, otherwise execute step 22;
[0023] Step 22, check whether address C has been recorded in the erase page record table. If not, execute Step 23. If recorded, decode the page address D where the data of address C is located from the erase record unit, read the data from address D, and execute Step 24;
[0024] Step 23, read data directly from address C;
[0025] Step 24, check whether it is necessary to continue reading other page data, if so, return to execute Step 21, otherwise the data reading ends.
[0026] The present application also provides a computer-readable storage medium, characterized in that it includes at least one memory and at least one processor;
[0027] The memory is used to store one or more program instructions;
[0028] The processor is used to run one or more program instructions to execute a high-performance anti-power-off erasing method and a high-performance anti-power-off reading method.
[0029] The beneficial effects achieved by the present invention are as follows: by adopting the technical solution of the present application, an efficient erasure protection mechanism is realized, which can not only protect the original page data but also efficiently write new data. BRIEF DESCRIPTION OF THE DRAWINGS
[0030] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments recorded in the present invention. For ordinary technicians in this field, other drawings can also be obtained based on these drawings.
[0031] Figure 1 This is a schematic diagram of the FLASH chip storage area;
[0032] Figure 2 It is a schematic diagram of the erasure record byte encoding;
[0033] Figure 3 It is a schematic diagram of the bit encoding of the erasable recording unit;
[0034] Figure 4 It is a flow chart of a high-performance power-off protection erasing method;
[0035] Figure 5 The invention is a flow chart of a method for reading page data of a chip storage area. DETAILED DESCRIPTION
[0036] The following is a clear and complete description of the technical solutions in the embodiments of the present invention in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative work are within the scope of protection of the present invention.
[0037] Embodiment 1
[0038] From a performance perspective, the time consumed in erasing is much longer than the time consumed in querying and reading data. In other words, improving the performance of the FLASH page protection mechanism can improve the performance of the overall business. Based on this, an embodiment of the present invention provides a FLASH chip storage area that can implement an efficient erasing protection mechanism, so that the FLASH chip can both protect the original page data and efficiently write new data.
[0039] like Figure 1 As shown, the FLASH chip storage area includes three areas, namely the first data area, the second data area and the erase operation record area, wherein the first data area is used to store user data, the second data area is used to store new data of the erased page, and the erase operation record area records the erase records of the FLASH page, and erases by page, rotates and uses, does not need backup, and requires that the erase record page currently written cannot be the same as the erase record page written before; each erase record unit corresponds to a page in the second data area or the first data area. When erasing a page, a page is determined according to the content in the erase record page, and the determined page may be in the first data area or the second data area, and then the new data is written to the page; if multiple pages are to be erased, it is also necessary to determine multiple pages according to the erase record content in the erase record page, and then write new data to each page, and write all erase records into the erase record page after completing the erase transaction.
[0040] Figure 2 This is a schematic diagram of the erase record byte encoding. The erase record page is composed of records with 2 bytes as units. Among them, the first two bytes are record information (the information used to record the sequence number and the number of records can be greater than 2 bytes, taking the first two bytes as an example), the first byte ( Figure 2 1, 2) record the erase record number, the value range is 0 to 255, the maximum value is the latest erase number, the second byte ( Figure 2 3 and 4) record the number of valid records in the erase record, that is, the number of record units in the transaction; the last two bytes (or 4 bytes, taking two bytes as an example, Figure 2 x, y) in the above are the checksums of all valid records. The calculation of the checksum can adopt the existing CRC / SHA / DES / AES algorithms. All the bytes in the middle ( Figure 2 5, 6...n-1, n) in the figure are erasable recording units.
[0041] Each erasable recording unit corresponds to a page in the second data area or the first data area. Specifically, the backup data available page identifier is recorded in each erasable recording unit, and the page is determined to belong to the first data area or the second data area according to the value of the backup data available page identifier. Figure 3 The bit encoding of the erasable recording unit is shown as an example. Each erasable recording unit is also composed of a record of 2 bytes, including Figure 3 Bit 0 to bit 15 shown (it should be noted that the following is only an example of the bit setting of the erase record unit, and the bit attribute can be randomly set according to actual needs):
[0042] Bit0 to bit12 are the bit encodings of the page address after alignment with the page size;
[0043] Bit13 records the available page identifier of the backup data. When bit13 is 0, it indicates that the page corresponding to the erasable recording unit is in the second data area. The page address is the product of the serial number of the erasable recording unit and the page size plus the starting address of the second data area. When bit13 is 1, it indicates that the page corresponding to the erasable recording unit is in the first data area. The page address is obtained by removing the high 3 bits of the erasable recording unit and shifting it left by 8 bits.
[0044] Bit14 records whether the current flag is in a backup transaction. When bit14 is 1, it indicates that the erase record unit is in an erase transaction. When bit14 is 0, it indicates that the erase record unit is not in the current erase transaction, and the data in the corresponding page is the latest data.
[0045] Bit15 records whether the current page is non-atomic write after backup is enabled. When bit15 is 1, it indicates non-atomic write, and when bit15 is 0, it indicates atomic write.
[0046] It should be noted that, theoretically, the sizes of the first data area and the second data area can be equal, and the erasure efficiency is the highest at this time. However, considering that the space of the chip's erasable storage area is limited, protecting a large number of pages in the first data area through a limited second data area is an actual need of existing services. Therefore, when the pages in the second data area are used up or other services that do not require performance are being carried out in the existing services, the user data in the second data area is written back to the first data area according to the erasure record unit encoding, and the corresponding erasure record unit is released for subsequent erasure page protection.
[0047] Since valid user data may exist in the second data area, the erasure record unit is checked when the chip is powered on to find the erasure record page with the correct checksum and the largest erasure record number in the erasure record unit, and the data in the page is used as a valid erasure record unit for subsequent valid data reading or erasing.
[0048] Embodiment 2
[0049] The second embodiment of the present application provides a high-performance power-off protection erasing method, which is applied to the FLASH chip storage area designed in the first embodiment. Figure 4 As shown, the erasing method comprises the following steps:
[0050] Step 410: Check whether the data in address A is in the cache according to the address A of the data to be written. If yes, execute step 440; otherwise, execute step 420;
[0051] Step 420, determine whether the record corresponding to address A can be found in the erase record page, if yes, execute step 430, otherwise allocate a new record unit position in the erase record page, encode the address into a record unit and write it into the record unit position, and then execute step 430;
[0052] Step 430: search for a corresponding erasure record unit in the erasure record page according to the cache address, decode address B according to the erasure record unit, write the data in the cache to the address B, encode address A into an erasure record unit and write it into the erasure record page;
[0053] Step 440, write the data to be written at address A into the cache, and continue to determine whether there is new data that needs to be written. If yes, return to step 410, otherwise the data erasing is completed.
[0054] Embodiment 3
[0055] The third embodiment of the present application provides a method for reading page data in a chip storage area, which is applied to the FLASH chip storage area designed in the first embodiment. Figure 5 As shown, the reading and writing method comprises the following steps:
[0056] Step 510: Check whether the data at address C has been cached according to the address C to be read. If so, read the data from the cache and execute step 540; otherwise, execute step 520;
[0057] Step 520, searching in the erase page record table whether address C has been recorded, if not recorded, executing step 530, if recorded, decoding from the erase record unit to obtain the page address D where the data of address C is located, reading data from address D, and executing step 540;
[0058] Step 530, directly read data from address C;
[0059] Step 540 , check whether it is necessary to continue reading other page data, if yes, return to step 510 , otherwise the data reading ends.
[0060] This application applies the above design to chip erase page protection. When the backup data page is not full, the existing business needs to erase N pages, and a total of N+1 pages need to be written to complete the erase protection of these N pages. Compared with the existing erase protection mechanism, the performance is nearly doubled.
[0061] Corresponding to the above embodiment, an embodiment of the present invention provides a FLASH chip storage area, including: at least one memory and at least one processor;
[0062] The memory is used to store one or more program instructions;
[0063] The processor is used to run one or more program instructions to execute a high-performance anti-power-off reading and writing method, including the high-performance anti-power-off erasing method described in Example 2 and a chip storage area page data reading method described in Example 3.
[0064] Corresponding to the above-mentioned embodiment, an embodiment of the present invention provides a computer-readable storage medium, wherein the computer storage medium contains one or more program instructions, and the one or more program instructions are used by a processor to execute a high-performance anti-power-off reading and writing method.
[0065] The embodiments disclosed in the present invention provide a computer-readable storage medium, in which computer program instructions are stored. When the computer program instructions are executed on a computer, the computer executes the above method.
[0066] In the embodiment of the present invention, the processor may be an integrated circuit chip having the ability to process signals. The processor may be a general-purpose processor, a digital signal processor (DSP), an application-specific integrated circuit (ASIC), a field programmable gate array (FPGA), or other programmable logic devices, discrete gate or transistor logic devices, or discrete hardware components.
[0067] The methods, steps and logic block diagrams disclosed in the embodiments of the present invention can be implemented or executed. The general processor can be a microprocessor or the processor can also be any conventional processor, etc. The steps of the method disclosed in the embodiments of the present invention can be directly embodied as a hardware decoding processor for execution, or can be executed by a combination of hardware and software modules in the decoding processor. The software module can be located in a mature storage medium in the field such as a random access memory, a flash memory, a read-only memory, a programmable read-only memory or an electrically erasable programmable memory, a register, etc. The processor reads the information in the storage medium and completes the steps of the above method in combination with its hardware.
[0068] The storage medium may be a memory, which may be, for example, a volatile memory or a nonvolatile memory, or may include both volatile and nonvolatile memory.
[0069] Among them, the non-volatile memory can be a read-only memory (ROM), a programmable ROM (PROM), an erasable programmable read-only memory (EPROM), an electrically erasable programmable read-only memory (EEPROM), or a flash memory.
[0070] The volatile memory may be a random access memory (RAM) which is used as an external cache. By way of example and not limitation, many forms of RAM are available, such as static RAM (SRAM), dynamic RAM (DRAM), synchronous DRAM (SDRAM), double data rate synchronous DRAM (DDRSDRAM), enhanced synchronous DRAM (ESDRAM), synchronous link DRAM (SLDRAM), and direct RAM bus DRAM (DRRAM).
[0071] The storage media described in the embodiments of the present invention are intended to include, but are not limited to, these and any other suitable types of memory.
[0072] Those skilled in the art will appreciate that in one or more of the above examples, the functions described in the present invention can be implemented using a combination of hardware and software. When software is used, the corresponding functions can be stored in a computer-readable medium or transmitted as one or more instructions or codes on a computer-readable medium. Computer-readable media include computer storage media and communication media, wherein communication media include any media that facilitates the transmission of computer programs from one place to another. Storage media can be any available media that can be accessed by general or special-purpose computers.
[0073] The specific implementation methods described above further illustrate the objectives, technical solutions and beneficial effects of the present invention in detail. It should be understood that the above description is only a specific implementation method of the present invention and is not intended to limit the scope of protection of the present invention. Any modifications, equivalent substitutions, improvements, etc. made on the basis of the technical solution of the present invention should be included in the scope of protection of the present invention.
Claims
1. A FLASH chip storage area, characterized in that: It includes a first data area, a second data area and an erase operation record area; the first data area is used to store user data, the second data area is used to store new data of the erased page, and the erase operation record area records the erase records of the FLASH page. The erase is performed by page and is used in rotation without backup, and it is required that the erase record page currently written cannot be the same as the erase record page written before; each erase record unit corresponds to a page in the second data area or the first data area; The erase operation record area is allocated with at least two erase record pages, namely, a valid record page and an invalid record page; the erase record page is composed of records with 2 bytes as units; the first two bytes are record information, the last two bytes are checksums of all valid records, and all bytes in between are erase record units; Each erasable recording unit corresponds to a page in the second data area or the first data area; a backup data available page identifier is recorded in each erasable recording unit, and it is determined whether the page belongs to the first data area or the second data area according to the value of the backup data available page identifier; When erasing a page, a page belonging to the first data area or the second data area is determined based on the content in the erase record page in the erase operation record area, and then the new data is written to the page; if multiple pages are to be erased, multiple pages are determined based on the content in the erase record page, and then the new data is written to each page, and the erase record is written to the erase record page when the erase transaction is completed.
2. The FLASH chip storage area as claimed in claim 1, characterized in that: In the first two bytes, the first byte records the erase record number, the maximum value is the latest erase sequence number, and the second byte records the number of valid records in the erase record unit, including the number of erase record units in the transaction.
3. The FLASH chip storage area as claimed in claim 1, characterized in that: When the pages in the second data area are used up or other services in the existing services do not require performance, the user data in the second data area is written back to the first data area according to the erasure record unit encoding, and the corresponding erasure record unit is released for subsequent erasure page protection.
4. The FLASH chip storage area as claimed in claim 3, characterized in that: When the chip is powered on, the erasable recording unit is checked to find the erasable recording unit with the correct check core and the largest erasable recording sequence number, and the largest erasable recording unit is used as a valid erasable recording unit for subsequent reading or erasing of valid data.
5. A high-performance power-off protection erasing method, applied to the FLASH chip storage area as described in any one of claims 1 to 4, characterized in that: The method comprises: Step 11, according to the address A of the data to be written, check whether the data in address A is in the cache, if yes, execute step 14, otherwise execute step 12; Step 12, determine whether the record corresponding to address A can be found in the erase record page, if yes, execute step 13, otherwise allocate a new record unit position in the erase record page, encode the address into a record unit and write it into the record unit position, and then execute step 13; Step 13, according to the cache address, find the corresponding erasure record unit in the erasure page record table, decode the address B according to the erasure record unit, write the data in the cache to the address B, encode the address A into the erasure record unit and write it into the erasure page record table; Step 14, write the data to be written to address A into the cache, and continue to determine whether there is new data that needs to be written. If so, return to execute Step 11, otherwise write the erase page record table into the erase record page, and the data erase is completed.
6. A method for reading page data in a chip storage area, applied to the FLASH chip storage area as claimed in any one of claims 1 to 4, characterized in that: The method comprises: Step 21, according to the address C to be read, check whether the data at address C has been cached, if so, read the data from the cache and execute step 24, otherwise execute step 22; Step 22, check whether address C has been recorded in the erase page record table. If not, execute Step 23. If recorded, decode the page address D where the data of address C is located from the erase record unit, read the data from address D, and execute Step 24; Step 23, read data directly from address C; Step 24, check whether it is necessary to continue reading other page data, if so, return to execute Step 21, otherwise the data reading ends.
7. A computer-readable storage medium, characterized in that: comprising at least one memory and at least one processor; The memory is used to store one or more program instructions; A processor is used to run one or more program instructions to execute a high-performance power-off protection erasing method as claimed in claim 5 and a chip storage area page data reading method as claimed in claim 6.
