Summary of the invention
For existing jumbo FLASH chip space management mechanism existing for problem, the object of the present invention is to provide a kind of space management of high capability flash chip of optimization, to solve the problem existing for prior art.
In order to achieve the above object, the present invention adopts following technical scheme:
A space management for high capability flash chip, the space of Flash chip is divided into system directorial area and user area by this management method;
Described system directorial area comprises two management page, and each management page is divided into two parts: configuration information district and logical address map information district;
Described user area comprises blocks of files and free block;
When revising blocks of files content, first finding a free block to wipe its data, then writing this free block, final updating management page.
In such scheme, mutually alternately upgrade between described two management page.
Further, the configuration information district in described management page is 32 bytes, comprises the physical block using state information of the serial number of 4 bytes, the mapping block counts of 2 bytes, the file block counts of 2 bytes, reserved 8 byte RFU and 16 bytes.
Further, described logical address map information district 112 byte.
Further, the logical page (LPAGE) first address in file district of logical address map information district and the mapping equation of Physical Page first address as follows:
Logical page (LPAGE) first addressphysical Page first address
Specific as follows:
LogAddress [i](physical base address+MAParray [i] * page unit) (0=<i<111),
Wherein:
I presentation logic page number, value [0,111], obtains logical page (LPAGE) first address by logic number * page unit.
LogAddress [i]=logical page number (LPN) (i) * page unit.
correspond to or be mapped in;
Physical base address: the first address in FLASH space can be used in user area;
MAParray: logical mappings array, totally 112 bytes.MAParray [i] gets unique value in 0 ~ 127;
Page unit: the size representing page.
Further, the blocks of files in described user area is 112, and free block is 16.
Further, the detailed process of described amendment blocks of files content is as follows:
(1) first according to physical block using state information, a free block is found;
(2) legacy data of this free block is wiped clean;
(3) according to the offset content of internal memory logical mappings array, the free block of write Physical Page;
(4) offset content of internal memory logical mappings array is upgraded;
(5) internal memory serial number is upgraded;
(6) physical block using state information in internal memory is upgraded;
(7) management page is upgraded.
Further, the detailed process of described step (3) is as follows:
First, mapping value corresponding to address, respective logic beginning of the page is read from physical mappings table district;
Then, the mapping value corresponding according to logical page (LPAGE) first address, calculates corresponding Physical Page first address;
Again then, the number of physical pages of its correspondence is read according to the Physical Page first address calculated according to putting into buffer memory;
Finally, tissue is for the new data of amendment in the buffer, writes the Physical Page calculated.
Scheme provided by the invention can not only the memory space of effective leading subscriber, but also can improve efficiency and the security of system, reduces the development difficulty of system, reduces maintenance cost.The effect specifically reached is as follows:
(1) the mode management document block adopting logical address to map, file system does not have continuity in physical space, not easily its file content analyzed, improves efficiency and the security of system.
(2) there is no independent power down protection system, reduce development difficulty, improve running efficiency of system; The alternately amendment of management page simultaneously, the large person of serial number is effective, can prevent the destruction that power down brings.
(3) can according to the size of different chip space, flexible configuration management page structure, project of being convenient to is transplanted and is safeguarded.
Embodiment
The technological means realized to make the present invention, creation characteristic, reaching object and effect is easy to understand, below in conjunction with concrete diagram, setting forth the present invention further.
For high capability flash chip, the space of Flash chip is divided into system directorial area and user area two parts by the space management mechanism that this programme provides.Wherein, system directorial area comprises two management page, mutually alternately upgrades between these two management page; Each management page is divided into two parts successively simultaneously: configuration information district and logical address map information district.
For user area, it comprises blocks of files and free block.
Based on above-mentioned administrative mechanism, when revising blocks of files content, first finding a free block to wipe its data, then writing this free block, final updating management page.
Based on above-mentioned principle scheme, further illustrate this programme below by way of an embody rule example:
In this example, the space of Flash chip is divided into system directorial area and user area two parts.Wherein directorial area comprises two management page, management page 1 and management page 2.Management page is divided into two parts: 32 byte configuration informations and 112 byte logical address map informations, and amounting to 144 bytes is an administrative unit, as shown in Figure 1.
This example illustrates with management page 1, and as shown in Figure 2, this management page comprises 32 byte configuration information districts and 112 byte logical address map information districts successively to initial configuration from start address.
Wherein, 32 byte configuration information districts comprise the physical block using state of the serial number of 4 bytes, the mapping block counts of 2 bytes, the file block counts of 2 bytes, reserved 8 byte RFU, 16 bytes successively.
Serial number: the amendment number of times of management page, initial value is 0, and often amendment adds 11 time.Management page has two, and each management page size is 2K, alternately amendment, and the management page that serial number is large is effective.
Map block counts: the available FLASH block number representing user area.Block number is also number of pages, and this programme is general, totally 128 pieces.
File block counts: represent that file system can use FLASH block number.
Free block number: map the difference that block counts deducts file block counts, as the intermediate data of file modification.
Physical block using state: the service condition in recording user district.Suppose that the physics first address 30000H of user area starts, totally 128 pages, user area, 112 pages, file area, 16 pages, free area.The physical block using state 128bit position altogether of 16 bytes, represents the user area service condition of 128 pages from 30000H.Bit=1, represents that this block is taken by file area; Bit=0, represents that this block is idle.In any moment, 1 takies 112bit, and 0 takies 16bit.Initial value is FFFFFFFFFFFFFFFF FFFFFFFFFFFF0000, and represent that 112 pages from 30000H are blocks of files, afterwards 16 pieces is free block.
Physical mappings table district: 112 byte spaces in this region, represent the logical address space of 112 pages from address 0000.The Physical Page first address that every logical page (LPAGE) first address is corresponding, shown in following formula
Logical page (LPAGE) first addressphysical Page first address.Its initial value as shown in Figure 2, the corresponding physical address space of 112 pages from 30000 of the logical address space of 112 pages from address 0000.
The size of mapping block counts, file block counts, physical block using state can according to the space size flexible configuration of concrete chip.
Thus, management threshold page content is as shown in Figure 2 formed.
For the mapping relations of logical page (LPAGE) first address and Physical Page first address, the space of 112 bytes in this example, address 0x20020 started is considered as spatial mappings data, MAParray [112].
Thus, the logical page (LPAGE) first address of file area and the mapping equation of Physical Page first address as follows:
LogAddress [i](physical base address+MAParray [i] * page unit) (0=<i<111), wherein:
LogAddress [i]=logic number (i) * page unit;
represent " correspond to or be mapped in ";
Physical base address: the first address in FLASH space can be used in user area, as 30000H;
MAParray: logical mappings array, totally 112 bytes, get unique value in 0 ~ 127;
Page unit: the size (page size of herein illustrating is 2K) representing page;
I presentation logic page number, value [0,111], obtains logical page (LPAGE) first address by logic number * page size.
As i=0,
Logical page (LPAGE) first address LogAddress [0]=0*800H=0000H
Corresponding physical address=30000H+MAParray [0] * 800H (MAParray [0] initial value is 0)
=30000H。
The initial mapping relation determined according to this above-mentioned formula as shown in Figure 3.
Below illustrate this example approach and carry out the process of file area amendment:
In order to coordinate above-mentioned directorial area, totally 128 pieces, user area in this example, 112 blocks of files, 16 free blocks.
In conjunction with above-mentioned administrative mechanism, the high capability flash chip-stored space performance determined is as follows:
The exercisable minimum unit of Flash is 2K (in units of page/block), whole page erasing, whole page write;
Flash mapping space is 256K, i.e. 128 pages/block;
The physical start address of Flash mapping space is 0x30000 (physical base address), and end address is 0x6FFFF;
The physical space of Flash directorial area is 0x20000 (management page 1) and 0x20800 (management page 2);
For preventing power-off from destroying, require that management page 1 and management page 2 need alternately upgrade;
As long as the content of amendment blocks of files, must upgrade the relevant configuration of management page afterwards immediately;
The block number of file area 112, the i.e. file space of 224K;
The block number of free area 16, i.e. the backup space of 32K.
First wipe the characteristic write afterwards for Flash chip, this example utilizes free block to realize the amendment of file data, if need the content of an amendment blocks of files, first must find a free block erasing, write this free block afterwards, final updating management page.
For this high capability flash chip-stored space, if desired revise homepage (the i.e. logical address 00000) content of file area, its detailed process is as follows.
1., according to 16 byte physical block using state information: FF FF FF FF FF FF FF FF FF FF FF FF FF FF 0000, find a free block.Find that the 112 to 127 piece for continuous print free block, Stochastic choice one piece (as the 112nd piece is the 0x70 of 16 systems).This randomness is the random number num by producing 0 ~ 15, selects the n-th um free block to be used.
2. wipe clean the free block i.e. legacy data (free block legacy data is unpredictable, nonsensical) of the 112nd piece.
3. according to the offset content of internal memory MAParray [0], write Physical Page 112 pieces.
The data of this MAParray are 112 byte datas read from physical mappings table district, i=0 herein, read the mapping value of logical page (LPAGE) first address 00000 correspondence, then the Physical Page first address corresponding according to above-mentioned " logical address of file area and the mapping equation of Physical Page first address " computational logic address 00000 is 00*800+30000 and 0x30000; Then read this number of physical pages and put into buffer memory according to (namely calculating address 0x30000 page data).Tissue is for the new data of amendment in the buffer afterwards, and write Physical Page (namely calculating address 0x30000 page), this stylish file data has write free page that is 112 pages; Next need the information revising management page, make new data come into force (namely the 112nd page becomes blocks of files, and blocks of files originally becomes free block)
4. the offset content upgrading internal memory MAParray [0] is 0x70 (namely the 112nd piece is the 0x70 of 16 systems, and content is the block number of new blocks of files).
5. upgrade internal memory serial number and add 1 for 0x00000001.
6. upgrade internal memory 16 byte physical block using state FEFFFFFFFFFFFFFFFFFFFFFFFFFF0100 (namely the 112nd page becomes blocks of files, and blocks of files originally becomes free block).
7. upgrading management page 2 is new content, and concrete data as shown in Figure 4.
The Physical Page first address that now logical page (LPAGE) first address 0x00000 is corresponding is:
MAParray[0]*0x800+0x30000=0x68000。(MAParray[0]=0x70)。
Now according to 16 byte physical block using state information:
FEFFFFFFFFFFFFFFFFFFFFFFFFFF0100 can know that current free block is the 0th piece and the 113 to 127 continuous print 15 pieces, amounts to 16 pieces.0th piece is recovered as free block, and 0x70 block is used as blocks of files.The sum of free block is 16 pieces all the time.
Also just achieve the amendment of blocks of files by upgrading management page, the object of renewal management page is remap (the changing location) in order to achieve blocks of files, realizes the object of amendment blocks of files content.
More than show and describe ultimate principle of the present invention, principal character and advantage of the present invention.The technician of the industry should understand; the present invention is not restricted to the described embodiments; what describe in above-described embodiment and instructions just illustrates principle of the present invention; without departing from the spirit and scope of the present invention; the present invention also has various changes and modifications, and these changes and improvements all fall in the claimed scope of the invention.Application claims protection domain is defined by appending claims and equivalent thereof.