Accelerate method and the device of Nand Flash write operation
Technical field
The present invention relates to embedded system field, refer to a kind of method and the device of accelerating NandFlash write operation especially.
Background technology
In embedded systems, because the size of program is considerably beyond the inner storage space of CPU (central processing unit), so generally all program is stored in the flash memory of CPU outside.NandFlash flash memory, due to advantages such as its storage space are large, cheap, is widely used in all kinds of embedded systems.
The data of NandFlash are preserved in the memory unit in the mode of bit (bit, position), in general, can only store a bit in a unit.These unit, in units of 8 or 16, are linked to be bit-rows (bitline), form so-called byte (octet is byte/16 bit byte is word), the bit wide of Here it is NandFlash.These bit-rows meeting recomposition page (page), page is blocking (block) again.
For large page NandFlash, a NandFlash is made up of several blocks that (concrete how many blocks, are determined by NandFlash storage size, storage space is larger, contained block number is also many), a block is made up of 64 pages, and a page has the storage space of 2048+64 byte; The size of a block is 128KB (block size of little page NandFlash is 16KB).
NandFlash reads and writes data in units of page, obliterated data in units of block.
Existing technology performs the method for write operation as shown in Figure 1 to NandFlash, after navigating to the block needing the address of write affiliated in NandFlash, first read the data of whole piece, then the data of whole piece are wiped, in the data of whole piece that amendment reads, amended monoblock data are finally write in this block by the data of corresponding address.
This method brings two problems:
The first, the write operation of this method to NandFlash experienced by reading, erasing, amendment, write four steps, and is the operation to whole piece.Even the data of a byte only just will be have modified, also to operate the data of whole piece, greatly reduce the speed of NandFlash write operation;
The second, frequently erase operation is carried out to NandFlash and will greatly reduce the serviceable life of NandFlash.
Summary of the invention
The invention provides a kind of method and the device of accelerating NandFlash write operation, the method accelerates the speed of NandFlash write operation, adds the serviceable life of NandFlash.
For solving the problems of the technologies described above, the invention provides technical scheme as follows:
Accelerate a method for NandFlash write operation, each page of described NandFlash is divided into several sectors according to certain byte, and described method comprises:
Step S101: according to the concordance list set up in advance, whether the identification information judging target sector is "Yes", if, then go to step S102, wherein said concordance list comprises and represents that whether current data in each sector is the identification information of 0xFF, described target sector is the sector at destination address place, and described destination address is address to be written;
Step S102: data to be written are write described target sector;
Step S103: the identification information of described target sector is set to "No".
Accelerate a device for NandFlash write operation, each page of described NandFlash is divided into several sectors according to certain byte, and described device comprises:
First judge module, for the concordance list that basis is set up in advance, whether the identification information judging target sector is "Yes", if, then go to the first writing module, wherein said concordance list comprises and represents that whether current data in each sector is the identification information of 0xFF, and described target sector is the sector at destination address place, and described destination address is address to be written;
First writing module, for writing described target sector by data to be written;
First arranges module, for the identification information of described target sector is set to "No".
The present invention has following beneficial effect:
When prior art performs write operation to NandFlash, the data first in reading object block, to buffer memory, are then wiped the data of object block in NandFlash, then are revised the data of destination address in buffer memory, finally by amended monoblock data write object block.Compared with prior art, in the method for quickening Flash write operation of the present invention, each page of NandFlash is divided into several sectors according to certain byte, take sector as the minimum unit reading and write data, when carrying out data and storing, first according to concordance list, judge that whether the identification information of target sector is "Yes" (target sector whether can write direct when not wiping data), if so, then data to be written are write target sector and the identification information of target sector is set to "No".
The write operation of prior art to NandFlash experienced by reading, erasing, amendment, write four steps, reads and write to occupy a large amount of time; And be operation to whole piece, even the data of a byte only just will be have modified, also to operate the data of whole piece, greatly reduce the speed of NandFlash write operation; Whether the method for quickening NandFlash write operation of the present invention can be written directly by each sector in concordance list interpretation NandFlash, and read operation can not be carried out to NandFlash, and only operate for sector, owing to generally reducing read-write to NandFlash, erase operation, so substantially increase the serviceable life of NandFlash.
The minimum operation unit of prior art to NandFlash is page, writes page by page, reduce the speed of NandFlash write operation in time writing data to NandFlash; The method of quickening NandFlash write operation of the present invention with sector be minimum operation unit NandFlash is read and write operation (due to all not too large to write operation data volume large absolutely time of NandFlash, general all can not more than the sector capacity of NandFlash), because the size of sector is far smaller than block, therefore the data volume of write-once NandFlash can be decreased to greatest extent, further increase the speed to NandFlash write operation.
NandFlash has the restriction of certain erase operation number of times, erasing will reduce the serviceable life of NandFlash greatly frequently, in the method for quickening NandFlash write operation of the present invention, when writing direct when not wiping data in target sector, decrease the erasing times to NandFlash, substantially increase the serviceable life of NandFlash.
Therefore the method for quickening NandFlash write operation of the present invention accelerates the speed of NandFlash write operation, adds the serviceable life of NandFlash.
Accompanying drawing explanation
Fig. 1 is the method flow diagram of NandFlash write operation in prior art;
Fig. 2 is the method flow diagram one of quickening NandFlash write operation of the present invention;
Fig. 3 is the method flow diagram two of quickening NandFlash write operation of the present invention;
Fig. 4 is the method flow diagram three of quickening NandFlash write operation of the present invention;
Fig. 5 is the method flow diagram four of quickening NandFlash write operation of the present invention;
Fig. 6 is the structure drawing of device one of quickening NandFlash write operation of the present invention;
Fig. 7 is the structure drawing of device two of quickening NandFlash write operation of the present invention;
Fig. 8 is the structure drawing of device three of quickening NandFlash write operation of the present invention;
Fig. 9 is the structure drawing of device four of quickening NandFlash write operation of the present invention.
Embodiment
For making the technical problem to be solved in the present invention, technical scheme and advantage clearly, be described in detail below in conjunction with the accompanying drawings and the specific embodiments.
On the one hand, the invention provides a kind of method accelerating NandFlash write operation, as shown in Figure 2, it is characterized in that, each page of NandFlash is divided into several sectors according to certain byte, and the method comprises:
Step S101: according to the concordance list set up in advance, whether the identification information judging target sector is "Yes", if, then go to step S102, wherein concordance list comprises and represents that whether current data in each sector is the identification information of 0xFF, target sector is the sector at destination address place, and destination address is address to be written;
This step judges whether target sector can write direct when not wiping the process of data.Concordance list can be set up in advance and be stored in NandFlash, now needs first concordance list to be read to buffer memory from NandFlash; Also can be in internal memory, set up concordance list before storage data, after completing to NandFlash write data, then concordance list is stored in NandFlash, for follow-up use; Whether identification information identifies this sector and can to write direct when not wiping data, when passable, now the data of this sector are 0xFF, namely (0xFF represents that the numerical value of each bit of this sector is 1 not write data after this sector erasing, instead of the numerical value referring to merely this sector is 0xFF, because the data length of the sector of different size is different, unification here represents with 0xFF);
Data right and wrong of can writing direct when not wiping usually are shown in, as the NandFlash after initialization of just dispatching from the factory; Or after erase operation has been carried out to certain block of NandFlash, only in some sector of this block with data, that next time just no longer needs performing erase operation to this block when carrying out write operation to other sector of this block again, and directly can perform write operation;
Step S102: by data write target sector to be written;
When data can be write direct in target sector when not wiping, directly by data write target sector to be written;
Step S103: the identification information of target sector is set to "No";
Target sector is after write data, and the update of identification information of this sector is no ".
The form of concordance list is varied, provides a specific embodiment herein:
Suppose that total block data contained in NandFlash is AL, in each piece, contained number of pages is PL, and in each page, contained sector number is SL.
Concordance list is as follows:
It is below sector auxiliary information management structure body
Wherein, sector_num represents certain concrete sector in certain page; Bytes_flag represents whether this sector can be written directly, and equals 1, and expression can be written directly; Equal 0, expression cannot be written directly, and needs the block first wiping this place, sector, then just can be written into.
Below page information management structure body:
Wherein, page_num represents certain concrete page in certain block; Each element of sector_nums [SL] is to should each sector in page.
It is below block message management structure body
Wherein, block_nb represents certain the concrete block in NandFlash; Each element of page_nums [PL] is to should each page in block.
It is below nandflash information management structure body
Wherein, flag=1 represents that concordance list is established; Flag=0 represents that concordance list is not set up.Each piece in the corresponding NandFlash of each element of block_nums [AL], the 0th block as corresponding in block_nums [0], corresponding 1st block of block_nums [1].
NandFlash belongs to flash memory, and the storage unit of flash memory is three terminal device, has identical title: source electrode, drain and gate with field effect transistor.There is silicon dioxide insulating layer between grid and silicon substrate, be used for protecting the electric charge in floating grid to leak.Adopting this structure, make storage unit be provided with charge maintenance capability, similarly is put into the water in bottle, and after you pour water into, water level just remains there, until you again pour into or pour out, so flash memory has memory capability always.
Flash memory is a kind of voltage-controlled device.The wiping of NAND flash memory and to write be all based on tunnel effect, electric current, through the insulation course floating grid and silicon base layer, charges (writing data) to floating grid or discharges (obliterated data).
From physical layer, NandFlash is write to the operation of data, essence is charged to floating grid; And the operation of obliterated data, essence is discharged to floating grid; That is before write operation (charging to floating grid) is carried out to NandFlash, first to carry out erase operation (floating grid is discharged), otherwise write operation is invalid (unit being full of electricity charges again, and it is otiose that yes).
From digital angle, when the floating grid of certain unit is full of electricity, the digital value of this unit read is exactly 0; After the floating grid of certain unit is discharged, the digital value of this unit read is exactly 1;
That is the digital value in NandFlash in certain storage unit can only become 0 (carrying out charging process to floating grid) from 1 when carrying out write operation, and 1 (this is the process of discharging to floating grid, is erase operation) can not be become from 0.
When prior art performs write operation to NandFlash, the data first in reading object block, to buffer memory, are then wiped the data of object block in NandFlash, then are revised the data of destination address in buffer memory, finally by amended monoblock data write object block.Compared with prior art, in the method for quickening Flash write operation of the present invention, each page of NandFlash is divided into several sectors according to certain byte, take sector as the minimum unit reading and write data, when carrying out data and storing, first according to concordance list, judge that whether the identification information of target sector is "Yes" (target sector whether can write direct when not wiping data), if so, then data to be written are write target sector and the identification information of target sector is set to "No".
The write operation of prior art to NandFlash experienced by reading, erasing, amendment, write four steps, reads and write to occupy a large amount of time; And be operation to whole piece, even the data of a byte only just will be have modified, also to operate the data of whole piece, greatly reduce the speed of NandFlash write operation; Whether the method for quickening NandFlash write operation of the present invention can be written directly by each sector in concordance list interpretation NandFlash, and read operation can not be carried out to NandFlash, and only operate for sector, owing to generally reducing read-write to NandFlash, erase operation, so substantially increase the serviceable life of NandFlash.
The minimum operation unit of prior art to NandFlash is page, writes page by page, reduce the speed of NandFlash write operation in time writing data to NandFlash; The method of quickening NandFlash write operation of the present invention with sector be minimum operation unit NandFlash is read and write operation (due to all not too large to write operation data volume large absolutely time of NandFlash, general all can not more than the sector capacity of NandFlash), because the size of sector is far smaller than block, therefore the data volume of write-once NandFlash can be decreased to greatest extent, further increase the speed to NandFlash write operation.
NandFlash has the restriction of certain erase operation number of times, erasing will reduce the serviceable life of NandFlash greatly frequently, in the method for quickening NandFlash write operation of the present invention, when writing direct when not wiping data in target sector, decrease the erasing times to NandFlash, substantially increase the serviceable life of NandFlash.
Therefore the method for quickening NandFlash write operation of the present invention accelerates the speed of NandFlash write operation, adds the serviceable life of NandFlash.
One as the method for quickening NandFlash write operation of the present invention is improved, and as shown in Figure 3, also comprises before step S101:
Step S100: judge whether data to be written equal 0x00, if so, go to step S102, otherwise, go to step S101;
0x00 represents that the numerical value of each bit of data to be written is 0, instead of refers to that merely data to be written are 0x00, because the data length of data to be written is different, unification here represents with 0x00;
When data to be written equal 0x00, because when write operation, the data of NandFlash can only become 0 from 1, can not become 1 from 0, no matter therefore the data in NandFlash are how many, after carrying out a write operation, will become 0x00, data write successfully, therefore when data to be written equal 0x00, can to write direct when not wiping data, and now can not use concordance list, further accelerate the speed of NandFlash write operation.
Another kind as the method for quickening NandFlash write operation of the present invention improves, and as shown in Figure 4, step S101 is further: according to the concordance list set up in advance, whether the identification information judging target sector is "Yes", if so, then goes to step S102, otherwise, go to step S301;
The method also comprises:
Step S301: from NandFlash by the digital independent in target sector to buffer memory;
Does step S302: carried out and operation by the current data ND in data DT to be written and destination address, judge whether to equal 0 (i.e. DT & ND=0?), if not, go to step S303;
Step S303: be data to be written by the data modification of destination address in the buffer;
Step S304: by the target sector of the data of sector whole in buffer memory write NandFlash.
With operation (mathematic sign is &) rule be 0 & 1=0,0 & 0=0,1 & 0=0,1 & 1=1.
Above-mentioned steps is the method judging whether further to need to carry out wiping, if the current data in destination address is ND, data to be written are DT, if DT & is ND=0, then represents and need erasing, now use the method write data of prior art, otherwise, represent and do not need erasing, directly the data of modifying target address are DT in the buffer, then by the target sector of the data write NandFlash in buffer memory.
Such as, suppose DT=0x01, binary mode is 00000001; So, the bit7 to bit1 of ND (is followed successively by bit7 from a high position to low level to meet " not wiping; the condition that directly can write " ... bit1) be 1 or 0 can, but bit0 must be 1, i.e. ND=XXXXXXX1 (binary mode), wherein X represents 1 or 0.Calculate DT & ND=0x01.
Like this, further decrease the erasing times to NandFlash entirety, improve the serviceable life of NandFlash, accelerate the speed to NandFlash write operation.
As another improvement of the method for quickening NandFlash write operation of the present invention, as shown in Figure 5, step S302 is further: carried out and operation by data DT to be written and destination address current data ND, judge whether to equal 0, if not, go to step S303, otherwise go to step S401;
The method also comprises:
Step S401: read the data of object block to buffer memory from NandFlash, wherein object block is the block at destination address place;
Step S402: the data of object block in erasing NandFlash;
Step S403: be data to be written by the data modification of destination address in the buffer;
Step S404: by buffer memory whole piece data write NandFlash object block in.
Step S401 to step S404 is the method for the write data of prior art, in the present invention, only has when needs obliterated data, just can perform the method.
Further, if the data of certain or some block of NandFlash are not written into data after being wiped free of, then the identification information of the sector in this or these block is set to "Yes".
Various in use procedure, along with the increase of data write, the identification information of each sector of NandFlash is that the quantity of "No" is increasing always, the quantity increase of the sector namely cannot write direct; Do not write data after the data erase of certain or some block by NandFlash, the identification information of the sector in this or these block can be set to "Yes", to upgrade concordance list, reach the object recycled.
Sector can be arbitrary size, and preferably, the size of sector is 256 bytes, stores the ECC proof test value for verifying the data in sector in NandFlash, and this ECC proof test value also can be stored in other storer outside NandFlash certainly.
NandFlash, due to the intrinsic characteristic of hardware own, can cause the phenomenon of appearance bit reversal once in a while.Certain referring in original NandFlash of so-called bit reversal has changed, or becomes 0 from 1, or becomes 1 from 0.
If just for the change of single position, perhaps problem seems not to be very serious.But if be by chance that certain of certain vital document has changed, so problem is just serious.
In order to solve the problem of bit reversal on NandFlash, ensureing the correctness of data, generally when use NandFlash, all can apply ECC algorithm.When for storing operating system, when configuration file and other sensitive informations, must ECC be used, to realize the verification of data, ensureing the correctness of data.
The full name of ECC is ErrorCheckingandCorrection, is a kind of error detection occurs for NandFlash and correction algorithm.If the not in-problem words of time sequential routine and circuit stability, whole piece or page can not to read or all make mistakes can not be caused time NandFlash makes mistakes, but in whole page, only have one or several position to make mistakes (i.e. bad point).ECC can correct 1 bit-errors and detect 2 bit-errors, and computing velocity is very fast, but cannot correct mistake more than 1 bit, can not ensure to detect to mistakes more than 2 bits.
For ECC checking algorithm, every 256 bytes generate the proof test value of 22, use 3 bytes store proof test values, and two unnecessary use 1 are filled.When carrying out write operation to NandFlash, the ECC proof test value of these 3 bytes of generation is saved to OOB (OutOfBand) district of the corresponding page of NandFlash, also claims redundant area.When carrying out read operation to NandFlash, the data of reading being carried out ECC verification, generating new proof test value, and then the former ECC proof test value preserved in OOB district is read, by these two proof test value step-by-step XORs, if result is 0, then represent to there is not mistake.If made mistakes, then find the position of makeing mistakes, correct.
The present invention utilizes ECC checking algorithm, and the size of sector is set to 256 bytes, and ECC checking algorithm can be used to correct each sector, improves correctness and the stability of data storage.
Corresponding with the method for above-mentioned quickening NandFlash write operation, the present invention also provides a kind of device accelerating NandFlash write operation, and as shown in Figure 6, each page of NandFlash is divided into several sectors according to certain byte, and this device comprises:
First judge module 11, for the concordance list that basis is set up in advance, whether the identification information judging target sector is "Yes", if, then go to the first writing module, wherein concordance list comprises and represents that whether current data in each sector is the identification information of 0xFF, and target sector is the sector at destination address place, and destination address is address to be written;
First writing module 12, for writing target sector by data to be written;
First arranges module 13, for the identification information of target sector is set to "No".
Corresponding with the method for above-mentioned quickening NandFlash write operation, the device of quickening NandFlash write operation of the present invention accelerates the speed of NandFlash write operation, adds the serviceable life of NandFlash.
One as the device of quickening NandFlash write operation of the present invention is improved, and as shown in Figure 7, also comprises before the first judge module 11:
Preposition judge module 10, for judging whether data to be written equal 0x00, if so, goes to the first writing module 12, otherwise, go to the first judge module 11.
Corresponding with the method for above-mentioned quickening NandFlash write operation, the device of quickening NandFlash write operation of the present invention further accelerates the speed of NandFlash write operation.
Another kind as the device of quickening NandFlash write operation of the present invention improves, as shown in Figure 8, first judge module 11 is further used for: according to the concordance list set up in advance, whether the identification information judging target sector is "Yes", if, then go to the first writing module 12, otherwise, go to the first read module 31;
This device also comprises:
First read module 31, for from NandFlash by the digital independent in target sector to buffer memory;
Second judge module 32, for being carried out and operation by the current data ND in data DT to be written and destination address, judges whether to equal 0, if not, goes to the first modified module 33;
First modified module 33, for being data to be written by the data modification of destination address in the buffer;
Second writing module 34, for writing the data of sector whole in buffer memory in the target sector of NandFlash.
Corresponding with the method for above-mentioned quickening NandFlash write operation, the device of quickening NandFlash write operation of the present invention further decreases the erasing times to NandFlash entirety, improve the serviceable life of NandFlash, accelerate the speed to NandFlash write operation.
As another improvement of the device of quickening NandFlash write operation of the present invention, as shown in Figure 9, second judge module 32 is further used for: carried out and operation by data DT to be written and destination address current data ND, judge whether to equal 0, if not, go to the first modified module 33, otherwise go to the second read module 41;
This device also comprises:
Second read module 41, for reading the data of object block to buffer memory from NandFlash, wherein object block is the block at destination address place;
First erasing module 42, for wiping the data of object block in NandFlash;
Second modified module 43, for being data to be written by the data modification of destination address in the buffer;
3rd writing module 44, for by buffer memory whole piece data write NandFlash object block in.
Only have when needs obliterated data, just can perform this above-mentioned modules.
The above is the preferred embodiment of the present invention; it should be pointed out that for those skilled in the art, under the prerequisite not departing from principle of the present invention; can also make some improvements and modifications, these improvements and modifications also should be considered as protection scope of the present invention.