Embodiment
Because the electric charge-discharge characteristic of flash memory, make its read-write number of times that restriction physically be arranged.To the read-write of a flash memory block, manufacturer can realize the counting of read-write number of times at internal firmware, reaches the high reps of read-write appointment, will demarcate unit for not re-using to that block.So flash memory might shorten the serviceable life of flash memory under extremely frequent use.The present invention provides a kind of recovery method for flash memory, and the position record of bad block is reformed.Before carrying out recovery method, need determine that the data in flash memory have been temporary in the extra storage medium (for example hard disc of computer or portable electron device), can in the recovery method process, not lose to guarantee the data in the flash memory.The embodiment of this recovery method is as follows.
Fig. 1 is the workflow diagram of first embodiment of the invention.
As shown in Figure 1, at first, the distribution situation of bad block in the step 101 scanning flash memory; Behind the completing steps 101, step 102 checks whether the bad block quantity in flash memory surpasses the bad block that is located at the flash memory internal firmware and limit to a number or amount, and advances to step 103; If surpassing the bad block that is located at the flash memory internal firmware, the bad block quantity in flash memory limits to a number or amount, to there be bad block to surpass 85% storage unit deletion (that is to say this storage unit is denoted as the storage unit that does not re-use) in step 103, advance to step 104, if the bad block of this storage unit distributes and do not limit to a number or amount above bad block in step 102, advance to step 106; In step 104, reexamine the distribution situation of bad block, check again whether the bad block quantity in flash memory limits to a number or amount above the bad block that is located at the flash memory internal firmware, limit to a number or amount if the bad block quantity in flash memory still surpasses the bad block that is located at the flash memory internal firmware, advance to step 105; Redistribute the storage unit of flash memory in step 105, bad block is concentrated be divided into a new storage unit, repeating step 103 surpasses bad block the deletion of the block sum 85% of storage unit; If the bad block of this storage unit distributes and do not limit to a number or amount above bad block in step 102, advance to step 106; The distributing position of record bad block is stored in the flash memory in step 106, advances to step 107; In step 107, the reformatting flash memory writes flash memory with USB (universal serial bus) (USB) configuration data, Main Boot Record (MBR) and file allocation table (FAT).
Fig. 2 is the workflow diagram of second embodiment of the invention.
As shown in Figure 2, the distribution situation of bad block in the step 201 scanning flash memory; Behind the completing steps 201, check that in step 202 whether the bad block quantity in the flash memory limits to a number or amount above the bad block that is located at the flash memory internal firmware, advances to step 203; If surpassing the bad block that is located at the flash memory internal firmware, the bad block quantity in the flash memory limits to a number or amount, again plan the capacity of storage unit in step 203, bad block is concentrated on same storage unit, advance to step 204, do not limit to a number or amount if the bad block quantity in the flash memory has to surpass the bad block that is located at the flash memory internal firmware, advance to step 207; In step 204, bad block is surpassed the zone deletion (that is to say this storage unit is denoted as useless storage unit) of the block sum 85% of storage unit, advance to step 205; In step 205, reexamine the distribution situation of bad block, check again whether the bad block quantity in flash memory limits to a number or amount above the bad block that is located at the flash memory internal firmware, limit to a number or amount if the bad block quantity in flash memory still surpasses the bad block that is located at the flash memory internal firmware, advance to step 206; Redistribute the storage unit of flash memory in step 206, bad block is concentrated be divided into a new storage unit, repeating step 204 is with the element deletion of bad block above the block sum 85% of storage unit; If the bad block of this storage unit distributes and do not limit to a number or amount above bad block in step 205, advance to step 207; In step 207, will write down the bad block distributing position, be stored in the flash memory; In step 208, the reformatting flash memory writes flash memory with universal serial bus configuration data, Main Boot Record and file allocation table.
Fig. 3 introduces block diagram how to delete the storage unit of bad block dense distribution in the flash memory of the present invention in detail.
As shown in Figure 3, at first scan the distribution situation of bad block in the flash memory, first flash memory 301 has 5 bad blocks, second flash memory 302 has 10 bad blocks, the 3rd flash memory 303 has 4 bad blocks, the 4th flash memory 304 has 12 bad blocks, and manufacturer to be located at the bad block quantity of flash memory internal firmware restriction be 8; In the 3rd storage unit of second flash memory 302, in six blocks of this storage unit five bad blocks are arranged, meet the state that has bad block to surpass the block sum 85% in memory zone, with this storage unit deletion, same in the 3rd storage unit of the 4th flash memory 304, in 6 blocks of this storage unit 5 bad blocks are arranged, with this storage unit deletion, therefore after carrying out recovery method, the bad block of second flash memory 302 only has 5, the bad block of the 4th flash memory 304 only has 7, and both all are lower than 8 of the bad block quantity of flash memory internal firmware restriction.By the above, the capacity of second flash memory 302 and the 4th flash memory 304 can diminish because of recovery method, but the process of process recovery method, the term of life that can prolong flash memory; Only need to sacrifice a small amount of cost, can reach the function that increases the service life with the raising fiduciary level.
Fig. 4 introduces the block diagram of planning again in the embodiment of the invention that bad block distributes in the storage unit, flash memory 40 has first storage unit 401, second storage unit 402, the 3rd storage unit 403 and the 4th storage unit 404, it is capable and B is capable that first storage unit 401 is divided into A, it is capable and D is capable that second storage unit 402 is divided into C, it is capable and F is capable that the 3rd storage unit 403 is divided into E, and the 4th storage unit 404 to divide into G capable and H is capable, this flash memory 40 always has 10 bad blocks, and as can be known by figure, the densely distributed district of E behavior bad block of and three storage unit 403 capable at the D of second storage unit 402, when planning storage unit again, this two row is divided in same storage unit, again after planning storage unit, first storage unit, 401 districts are that A is capable and B is capable, second storage unit, 402 districts are that C is capable and F is capable, the 3rd storage unit 403 districts are that D is capable and E is capable, and the 4th storage unit 404 to divide into G capable and H is capable, by figure as can be known, the 3rd storage unit 403 is the bad block concentrated area, the 3rd storage unit is deleted, the bad block of this flash memory 40 is increasing the service life and the function that improves fiduciary level through only remaining 5 after the process of recovery method, can reaching equally.
Fig. 5 introduces the block diagram of planning the memory field capacity in the embodiment of the invention again.According to Fig. 5, this flash memory 50 has first storage unit 501, second storage unit 502, the 3rd storage unit 503 and the 4th storage unit 504, it is capable and B is capable that first storage unit 501 is divided into A, it is capable and D is capable that second storage unit 502 is divided into C, it is capable and F is capable that the 3rd storage unit 503 is divided into E, and the 4th storage unit 504 to divide into G capable and H is capable, this flash memory 50 always has 10 bad blocks, selection is capable with the D of second storage unit, the E of the 3rd storage unit is capable, the F of the 3rd storage unit G capable and storage unit is capable when planning the storage unit amount of capacity again, this four lines is divided in same storage unit, through after planning the storage unit amount of capacity again, form the first new storage unit 505 and second storage unit 506, again many bad blocks are concentrated second storage unit, 506 deletions that distribute, the bad block of this flash memory 50 is increasing the service life and the function that improves fiduciary level through only remaining 2 after the process of recovery method, can reaching equally.
Fig. 6 is the workflow diagram of third embodiment of the invention.
As shown in Figure 6, the distribution situation of bad block in the step 601 scanning flash memory; Behind the completing steps 601, check the bad block that whether has in the flash memory in step 602; Do not limit to a number or amount if the bad block in the flash memory surpasses the bad block of internal firmware, advance to step 603, the bad block that will not change the flash memory internal firmware in step 603 limits to a number or amount; In step 602, if surpassing the bad block of internal firmware, the bad block in the flash memory limits to a number or amount, advance to step 604, the bad block that bad block in the flash memory is surpassed internal firmware limits to a number or amount and resets, and the bad block of setting each storage unit in a dynamic way limits to a number or amount, and it is stored in the internal firmware of flash memory, advance to step 605; In step 605, the reformatting flash memory writes flash memory with universal serial bus configuration data, Main Boot Record and file allocation table.
Fig. 7 introduces third embodiment of the invention to set the block diagram that the bad block of each storage unit limits to a number or amount with dynamical fashion.
As shown in Figure 7, limit to a number or amount, can set with an equation at the bad block of setting each storage unit with dynamical fashion of Fig. 6 explanation; First storage unit 7011 with first flash memory 701 is an example, the bad block of supposing first flash memory, 701 internal firmwares limits to a number or amount and is X=20, the quantity the Y=0 whether storage unit of bad block existence is arranged in first flash memory 701, bad block sum Z=5 at first flash memory 701, first storage unit 7011 W=2 bad block arranged, the bad block restriction of dynamically setting this storage unit with equation is ((X-Y*2)/Z) * W=((20-0*2)/5) * 2=8 of F=, equation can be limited to 8 on these first storage unit, 7011 receivable bad blocks thus, it is 4 that the bad block that in like manner can obtain second storage unit 7012 limits to a number or amount, the bad block quantity of the 3rd storage unit 7013 is 4, the bad block quantity of the 4th storage unit 7014 is 4, and total bad block of this first flash memory 701 limits to a number or amount and is 8+4+4+4=20.First storage unit 7021, second area 7022, the 3rd storage unit 7023 and the 4th storage unit 7024 receivable bad block upper limits of utilizing identical equation can obtain at second flash memory 702 are respectively 8,2,2 and 8.
The number of blocks of number of blocks in the above-described embodiments, storage area quantity, storage unit, bad block quantity, bad block distribution proportion or to limit to a number or amount at the bad block of flash memory internal firmware only be an example, can allow those skilled in the art understand easily, these quantity can be according to the settings of the amount of capacity of flash memory or different vendor and are different, do not limit to usable range of the present invention at this.
Flash memory of the present invention can be one to be the flash memory at interface with the universal serial bus; Or this flash memory is used in general on the market CF (compact flash), MMC (multimedia card), MSC (memory stick card), SMC (smart media card) or SD flash memories such as (smart cards).This flash memory can be single level cell flash memory, multi-level unit flash memory or nand flash memory or NOR flash memory, can utilize recovery method of the present invention to reach and increase the service life and the function that improves fiduciary level.
Explanation described above and diagram, be for the ease of illustrating technology contents of the present invention and technological means, the part of disclosed preferred embodiment, not thereby limit its scope, those skilled in the art should be by the concrete open possible variation of making of the present invention.All local modification at technological means of the present invention, device, change, or the equivalent substitution of assembly, displacement should not break away from the spirit and the scope of invention of the present invention, and its scope will be defined by the scope of following claim.