Embodiment
1, according to the real needs of upper layer application such as the requirement of memory contents security, be whole nand flash memory spatial division several different zones, a plurality of physical planes may be crossed in a zone, even a plurality of nand flash memory chip.Each zone of dividing like this all manages by a MTD.MTD need write down the physical plane that first physical block was positioned at number of its management area and this physical block side-play amount with respect to this physical plane.Fig. 1 is the dividing condition of two nand flash memory chips, and two physical planes are divided in the address, front and back, and three logic plane Plane0, Plane1 and the common part that constitutes of Plane2 are exactly a zone that MTD will administer.Three column of figures on this left side, zone from left to right as shown in the figure, represent physical block number, pseudo-physical block number and logical block number (LBN) respectively, each column of figure all is to be each defined among three logic plane Plane0, Plane1 and the Plane2, for example, the logical block number (LBN) 0 of logic plane Plane0 is different from the logical block number (LBN) 0 among the logic plane Plane1.There is not this piece number in "--" presentation logic piece number.The beginning in whole nand flash memory space partly can be used as specific use, and such as the bad block message of depositing nand flash memory, it can not return any MTD management.If be divided into last physical plane, the also not enough piece number that distributes the district of its remaining number, then these pieces are discarded can not use.2 nand flash memory chip CHIP0 and CHIP1 have been crossed in this zone, totally 3 physical plane CHIP0_LANE0, CHIP0_PLANE1 and CHIP1_PLANE0, as seen from Figure 1, first physical plane of MTD management is CHIP0_PLANE0, and first physical block is 4 with respect to the side-play amount of this physical plane.
2, the physical plane number of crossing over according to the zone, the part that each physical plane is positioned at this zone all is abstracted into a logic plane, as 3 logic plane: Plane0 among Fig. 1, Plane1, Plane2.Each logic plane writes down each self-contained number, and keeps the invalid block of some, and invalid block is not deposit the piece of valid data, their not corresponding any logical block number (LBN)s, and the set of these pieces is called and distributes the district.For each physical block, select the additional zone of its some page or leaf to write down its logical block number (LBN) with respect to this logic plane, for the piece that distributes in the district, the logical block number (LBN) of its record is invalid.
3, the set meeting of the logical block number (LBN) of MTD upper strata use is less than the set of pseudo-physical block number composition, because distribute the piece in the district and do not correspond to any logical block number (LBN).Scanning whole zone just can set up logical block number (LBN) to the mapping relations of pseudo-physical block number.Each logic plane records this mapping relations among its mapping table Log2Fake that has separately, as shown in Figure 2.Mapping table Log2Fake can be an array, the subscript presentation logic piece of array number, and the corresponding pseudo-physical block number of its content representation so just can promptly be found out the pseudo-physical block number of its correspondence by logical block number (LBN).
4, in fact, reading and writing data is substantially all carried out by logic sector number SectorNum in the MTD upper strata.According to the size of the physical plane of regional starting position, area size and the nand flash memory of MTD record, can calculate and the corresponding logical block number (LBN) of logic sector number SectorNum and logic plane number.Computing method are as follows:
At first be offset 1 LogOffset1 with regard to representing this piece with respect to the logic of whole nand flash memory address space divided by the merchant of sector that piece comprised sum gained by logic sector number SectorNum; And then be offset 1 LogOffset1 according to logic, be offset 2 LogOffset2 by each regional reference position and size just can calculate that this sector is positioned at regional and with respect to this regional logic; Be offset 2 LogOffset2 by logic then, the number of the logical block number (LBN) that comprises according to the size of distributing the district and each logic plane is again tried to achieve logic plane that this piece is positioned at number and corresponding logical block number (LBN); At last,, just can directly obtain out pseudo-physical block number, change by mapping table Log2Fake to the conversion in middle layer as the superiors among Fig. 2 according to this logic plane corresponding mapping table Log2Fake.
5, the needed address of visit nand flash memory is the skew page number Page in phy chip Chip, physical block number and the piece, and they can obtain by corresponding mapping algorithm Fake2Rea1.Pseudo-code with the C language provides 4 kinds of mapping algorithm Fake2Rea1 that divide the physical plane method corresponding to difference respectively below, this algorithm is the universal law that obtains by each piece corresponding relation among summary Fig. 1, Fig. 3, Fig. 4 and Fig. 5 respectively, and the mode of being divided physical plane by area dividing and nand flash memory determines.
The implication that the variable that pseudo-code is used is represented is as follows:
Chip is a phy chip number;
FstPlane represents the physical plane that first physical block was positioned at number of MTD management;
StartBlkOfFstPlane represents the side-play amount of first physical block of MTD management with respect to this physical block of FstPlane;
PlaneNum presentation logic plane number;
Fake represents pseudo-physical block number;
Phy represents physical block number;
PlanePerChip represents the physical plane number that each phy chip is divided;
BlockPerPlane represents the total block data that a physical plane comprises;
Page is the skew page number in the piece;
SecPerBlk represents the sector sum in the physical block.
Wherein, the logic plane PlaneNum of logic sector number SectorNum correspondence and pseudo-physical block number Fake are calculated by the method in above-mentioned the 4th step.
No matter the method for the skew page number Page in the division methods of any physical plane, computational physics chip Chip and piece is:
Chip=(PlaneNum+FstPlane)/PlanePerChip;
Page=SectorNum%SecPerBlk;
In addition, computational physics piece Phy need be different and different at the mode of concrete division physical plane: the 1) situation of single physical plane, as shown in Figure 3:
If (PlaneNum equals 0) // whether be positioned at first logic plane in this zone
{
Fake=Fake+StartBlkOfFstPlane;
}
Phy=Fake;
2) situation of physical plane is divided in the address before and after, as shown in Figure 1:
If (PlaneNum equals 0) // whether be positioned at first logic plane in this zone
{
Fake=Fake+StartBlkOfFstPlane; // need increase this regional side-play amount
}
PlaneNum=(PlaneNum+FstPlane)%PlanePerChip;
Phy=Fake+PlaneNum*BlockPerPlane;
3) situation of physical plane is divided in the odd even address, as shown in Figure 4:
If (PlaneNum equals 0) // whether be positioned at first logic plane in this zone
{
Fake=Fake+StartBlkOfFstPlane; // need increase this regional side-play amount
}
PlaneNum=(PlaneNum+FstPlane)%PlanePerChip;
Phy=Fake*PlanePerChip+PlaneNum;
4) situation that physical plane was divided in the address before and after existing odd even had again, as shown in Figure 5:
If (PlaneNum equals 0) // whether be positioned at first logic plane in this zone
{
Fake=Fake+StartBlkOfFstPlane; // need increase this regional side-play amount
}
PlaneNum=(PlaneNum+FstPlane)%PlanePerChip;
Phy=Fake*2+(PlaneNum/2)*BlockPerPlane*2+(PlaneNum%2);
According to the area dividing of Fig. 1, illustrate the process of two-layer map addresses below.
Among Fig. 1, the total block data that the zone is comprised is: 37, and wherein logic plane Plane0 comprises 12, and logic plane Plane1 comprises 16, and logic plane Plane2 comprises 9.The logical block number of depositing valid data is total up to: 25, because three logic planes all contain the distribution district of 4 pieces.The piece of supposing this nand flash memory comprises 128 pages or leaves, and each page or leaf has only a sector, and promptly the block size of nand flash memory is 128 sectors, and PlanePerChip equals 2.Wherein FstPlane equals 0, and StartBlkOfFstPlane equals 4.The logic sector SectorNum that present upper strata need be visited is 3002, at this moment Plane1_Log2Fake[10]=5, Plane1_Log2Fake[11]=13, Plane1_Log2Fake[12]=15.
At first according to the 4th computing method that provide of step, be not difficult to obtain this logic sector SectorNum and be positioned at the zone, and try to achieve logic skew 1LogOffsetl and equal 23, promptly 3002 divided by 128 merchants that obtain, and logic skew 2LogOffset2 equals 19.Because the distribution district of each logic plane is 4, promptly the logical block number of the valid data deposited that comprise of Plane0, Plane1 and Plane2 is respectively 8,12 and 5, so the position of LogOffset2 is arranged in logic plane Plane1, and LogAddr equals 11.
Can directly obtain pseudo-physical block number by the mapping table of this logic plane Plane1 and just equal 13 (Plane1_Log2Fake[11]), as one of the input in the 5th step.Divide physical plane because this nand flash memory is the address, front and back, second layer mapping relations are by the 2nd in the 5th step) decision of kind situation.All of mapping relations are input as: PlanePerChip=2, SecPerBlk=128, plane=1, Fake=13, StartBlkOfFstPlane=4, FstPlane=0, so SectorNum=3002., bring for the 2nd in top the 5th step into) plant the computing method of situation, can obtain: Chip=0, Page=58, Phy=29.The result who calculates is consistent with the corresponding relation of Fig. 1 synoptic diagram.
Fig. 3, Fig. 4, Fig. 5 corresponding respectively single physical plane, odd even address divide physical plane and existing odd even have again before and after the address area dividing and the address mapping relation example of dividing the nand flash memory of physical plane.Can be for these three kinds of its account forms of situation with reference to above-mentioned illustrating about Fig. 1.When actual Project Realization, in fact the piece number in the distribution district is far smaller than the total block data of each physical plane, this information is not depicted for convenience of description in the diagram.