Summary of the invention
Technical matters to be solved by this invention provides a kind of nonvolatile memory and data guard method thereof, to prevent that program stored is plagiarized in the nonvolatile memory.
For solving the problems of the technologies described above, it is as follows to the invention provides technical scheme:
A kind of nonvolatile memory; comprise; sightless first memory block, visible second memory block, control logic module and protected code are provided with module; be provided with at least one zone bit in described first memory block; whether each zone bit is used to identify corresponding protected code and is provided with; described protected code is used for indicating the protected field of described second memory block, wherein:
Described protected code is provided with module, be used for when receiving the instruction of write protection sign indicating number, read the zone bit of the instruction correspondence of said write protected code, whether the zone bit of judging described correspondence is preset value, if, do not carry out the instruction of said write protected code, otherwise, the corresponding protection sign indicating number is written to described first memory block, and the zone bit of described correspondence is set to preset value;
Described control logic module; be used for determining to be wiped in described second memory block first protected location of protection and second protected location that is subjected to write protection according to the protected code that store described first memory block; and when receiving the instruction that the storage unit in described first protected location is wiped; do not carry out this erasing instruction; when receiving the instruction that the storage unit in described second protected location is write, do not carry out this and write instruction.
Above-mentioned nonvolatile memory, wherein, described second memory block comprises m block, m is a positive integer; Described protected code comprises 2m bit, and each bit in the described 2m bit is used to indicate corresponding block whether to be wiped protection or write protection.
Above-mentioned nonvolatile memory, wherein, described protected code is the set of the address of protected block in second memory block.
Above-mentioned nonvolatile memory, wherein, the coded system of described protected code is: each is encoded corresponding to the continuous a plurality of protected block in address in second memory block.
Above-mentioned nonvolatile memory; wherein; store trap routine and effective procedure in described second memory block; include the instruction of the storage unit of described first protected location being carried out erase operation in the described trap routine; and/or, the storage unit of described second protected location is carried out the instruction of write operation.
Above-mentioned nonvolatile memory is flash memory (flash).
A kind of data guard method of nonvolatile memory comprises sightless first memory block, visible second memory block in the described nonvolatile memory, described method comprises the steps:
A, in described first memory block protected code is set, described protected code is used for indicating the protected field of described second memory block;
B, in described second memory block storage trap routine and effective procedure, include in the described trap routine storage unit of being wiped protection in the described protected field is carried out the instruction of erase operation, and/or, the storage unit that is subjected to write protection in the described protected field is carried out the instruction of write operation;
C, when the storage unit of being wiped protection when program run in to described protected field is carried out the instruction of erase operation, do not carry out this erasing instruction; When program run is subjected to the storage unit of write protection to carry out the instruction of write operation in to described protected field, does not carry out this and write instruction.
Above-mentioned method wherein, also comprises before the steps A: in described first memory block at least one zone bit is set, whether each zone bit is used to identify corresponding protected code and is provided with; Steps A specifically comprises: receive the instruction of write protection sign indicating number; read the zone bit of the instruction correspondence of said write protected code; whether the zone bit of judging described correspondence is preset value; if; do not carry out the instruction of said write protected code; otherwise, the corresponding protection sign indicating number is written to described first memory block, and the zone bit of described correspondence is set to preset value.
In the present invention, protected code is stored in user's invisible area, and the plagiarism person can not read; The protection combination of protected code correspondence can reach very big quantity, and this carries out Brute Force to the plagiarism person and brings difficulty.And effective instruction and trap instruction in the program are made up voluntarily by the user, and the number of combinations of instruction also can be very big, and the plagiarism person wants to carry out very difficulty of Brute Force.So, original system manufacturer increases trap routine after only need setting protected code in program stored, just can protect program effectively, and can not produce extra-pay.In addition, if the system development merchant does not add trap routine in program, also nonvolatile memory can be regarded as and have general storer with wiping/write-protect function.
Embodiment
For making the purpose, technical solutions and advantages of the present invention clearer, describe the present invention below in conjunction with the accompanying drawings and the specific embodiments.
With reference to Fig. 1, the nonvolatile memory of the embodiment of the invention mainly comprises: invisible memory block, visible memory block, protected code are provided with module and control logic module.
Invisible memory block is meant the sightless memory block to the user, is called black box again.In the present embodiment, use it for the memory protection sign indicating number, this protected code is used for indicating the protected field of described visible memory block.Described protected code can be one or more, and also is provided with at least one zone bit in this invisible memory block, and whether the corresponding protected code of each zone bit is used to identify corresponding protected code and is provided with.
As seen the memory block is meant the visible memory block to the user, and the user can be with program and other data storage in wherein.How being provided with the visible and sightless memory block of user in nonvolatile memory is prior art, does not give unnecessary details here.
Protected code is provided with module, is used to be provided with protected code, and this protected code is used for indicating the protected field of visible memory block, and described protected field comprises: wiped first protected location of protection and second protected location that is subjected to write protection.What is called is wiped protection, is meant to carry out erase operation to this first protected location; What is called is subjected to write protection, is meant to carry out write operation to this second protected location.Need to prove that described first protected location and second protected location can be partly or entirely overlapping, that is, some block in the visible memory block might both be wiped protection, was subjected to write protection simultaneously again.
In general, storage array (the visible memory block in the present embodiment) comprises some blocks, and each block comprises some sectors again.If the block counts that described visible memory block comprises is m, the total sector number that comprises is n.Then can indicate shielded block, perhaps, indicate shielded sector by protected code by protected code.Particularly; if protection is block; then described protected code can comprise 2m bit; each bit in the described 2m bit is used to indicate corresponding block whether to be wiped protection or write protection; the set of being wiped the block of protection constitutes described first protected location, is subjected to the set of the block of write protection to constitute described second protected location.Perhaps; if protection is the sector; then described protected code can comprise 2n bit; each bit in the described 2n bit is used to indicate corresponding sector whether to be wiped protection or write protection; the set of being wiped the sector of protection constitutes described first protected location, is subjected to the set of the sector of write protection to constitute described second protected location.
Below only be a kind of preferable coded system (mode 1) of protected code, described protected code also can adopt other coded systems.
For example, protected code is designed to the set (mode 2) of the address of protected block in the described visible memory block.Suppose that the block counts that described visible memory block comprises is many, 1024 to be example, then the address width of block is 10 bits.Under this kind mode, if desired 4 blocks are protected, then situation is with 40 bits (4 block address) expression write protection at most, uses 40 bits (4 block address) expression to wipe protection again, amounts to 80 bits and just can finish.Limited block of protection in more block sum, then the coded system of this protected code has been saved the storage space of protected code greatly for mode 1.
Again for example, the coded system of the protected code of design is: each is encoded corresponding to the continuous a plurality of protected block (mode 3) in address in the described visible memory block, and following table is depicted as a kind of realization of mode 3:
Obviously, coded system 3 has further been saved the storage space of protected code for mode 2.
Protected code is provided with module and (is for example receiving the outside; microcontroller in the applied electronic circuit system of this nonvolatile memory) during the instruction of write protection sign indicating number; read the zone bit of the instruction correspondence of this write protection sign indicating number earlier from described invisible memory block, determine whether to carry out the instruction of this write protection sign indicating number according to the value of zone bit.If zone bit is preset value, for example 0, then the corresponding protected code of explanation is provided with, and does not carry out the instruction of this write protection sign indicating number; If zone bit be preset value, for example 1, the protected code setting as yet of correspondence be described, carry out the instruction of this write protection sign indicating number, protected code is written to described invisible memory block.
In embodiments of the present invention; after protected code is provided with module protected code is written to invisible memory block, also with the mark position 0 of correspondence, like this; when receiving the instruction of the write protection sign indicating number corresponding more later, just can not carry out the instruction of this write protection sign indicating number again with this zone bit.So, realized the user to a writable disposable of each protected code in the described invisible memory block, can not wipe, can not rewrite, not can read.
Control logic module is used to receive the operational order to visible memory block, carries out corresponding operation according to this instruction.Unlike the prior art be; control logic module in the embodiment of the invention; when receiving erasing instruction or write instruction; also, determine to be wiped in the visible memory block first protected location of protection and second protected location that is subjected to write protection according to described protected code from invisible memory block fetch protection sign indicating number.If the operand of described erasing instruction is the storage unit in described first protected location, then do not carry out this erasing instruction; If the operand of said write instruction is the storage unit in described second protected location, does not then carry out this and write instruction.
Utilize the nonvolatile memory of the embodiment of the invention to store data, for example, storage developer's program that solution transformed and critical data can be protected data effectively, prevent plagiarism person's bootlegging.Particularly, be with described procedure stores in the visible memory block of described nonvolatile memory; In the described program except that comprising effective procedure; also comprise trap routine; include in the described trap routine storage unit in described first protected location is carried out the instruction of erase operation, and/or, the destructive procedures such as instruction that the storage unit in described second protected location is carried out write operation.Wherein, described trap routine is made of normal wiping/write command, and the plagiarism person can't distinguish.
Like this, when the trap routine, control logic module can receive the instruction that the protected location is wiped or write in program run, and according to the present invention, refusal is carried out the described instruction of wiping or write, thus the data on can protected storage.And after plagiarism person's plagiarism, when on other storer, moving, when running to trap routine, can carry out destructive procedure, and wipe as described and write operation, the data on the storer are destroyed, do not realize the normal function of program.
Below provide the application example of a flash.
Flash can be divided into several blocks on storage organization, be example with 8Mb flash, if every block can be stored 512K bit, then always has 16 blocks: block 0~block 15.Each block can be divided into several sectors again, for example every sector storage 32K bit, and then every block comprises 16 sectors: 0~sector, sector 15.
A storage area and a register-bit (register bit) that is used for the memory protection sign indicating number is set in flash.Protected code storage area and register-bit constitute by the storage unit (cell) of flash, and they are sightless black boxs to the user, can not be wiped and read by the user.
During original state, protected code memory block and register-bit storing value are 1, and the user can write the protected code storage area by instruction, address and data, and the block that need wipe protection/write protection is set.After flash receives the instruction of user's write protection sign indicating number, can at first inquire about the value of register-bit, as be 1, then carry out write operation the protected code memory block.In write-protect sign indicating number memory block, flash can be written as 0 with register-bit automatically.After if flash receives the instruction of write protection sign indicating number again, inquiry register place value is 0, and then refusal is carried out the instruction of write protection sign indicating number.Realized like this user to a writable disposable of each protected code in the described invisible memory block, can not wipe, can not rewrite, not can read.
Join protection sign indicating number and address decoding algorithm can be realized protection or write protection are wiped in the block/sector of protected code correspondence.To contain 16 block 8Mb flash chips is example, only needs the protected code of 32bit just can realize the wiping and write protection of each block, wherein before 16bit be used to wipe protection, back 16bit is used for write protection.For example: 1111_1111_1111_1110_0111_1111_1111_1111 represents that block 15 is wiped free of protection, and block 0 is written into protection.As can be seen, even only consider with the block to be that unit protects, had 2
32=4294967296 kinds of protection combinations, this carries out Brute Force to the plagiarism person and brings very big difficulty; And if be that unit protects with the sector, then the protection combination can be more.
When flash receives erase blocks 15, or during any one sector of 15 li of blocks, flash is the inquiry protected code earlier, if block 15 is subjected to wiping protection, then the flash refusal is carried out the instruction of erase blocks 15; When flash received the instruction of wiping full sheet, flash is the inquiry protected code earlier, only wipes the block that those are not subjected to wiping protection.Because storage array, protected code memory block, control circuit are integrated in the chips; the user can't fetch protection sign indicating number memory block content; also can't obtain protected code information by I/O is sampled, the plagiarism person will be difficult to obtain the information that storage array is protected.
After setting protected code, the user just can write storage array with effective procedure and trap routine and suffer.Wherein trap routine can be wiped the block of being wiped protection, or the block that is subjected to write protection is write.The plagiarism person is under the situation of not obtaining protected code information, and the program of the original manufacturer of directly transplanting when carrying out trap routine, will wipe mistakenly or write, thereby data are damaged canned data.
The embodiment of the invention also provides a kind of method of utilizing above-mentioned nonvolatile memory to realize data protection.
Fig. 2 is the process flow diagram of the data guard method of the embodiment of the invention, sees figures.1.and.2, and described method mainly comprises the steps:
Step 201: during user's input protection sign indicating number, nonvolatile memory receives the instruction of write protection sign indicating number, and described protected code is used for indicating the protected field of visible memory;
Step 202: read zone bit from invisible memory block, the corresponding protected code of this zone bit write instruction;
Step 203~205: judge whether described zone bit is preset value, if, then the corresponding protected code of explanation is provided with, do not carry out the instruction of this write protection sign indicating number, otherwise, illustrate that corresponding protected code is provided with as yet, the protected code of importing is written to described invisible memory block, and the zone bit of described correspondence is set to preset value;
Step 206: storage trap routine and effective procedure in visible memory block, include in the described trap routine storage unit of being wiped protection in the described protected field is carried out the instruction of erase operation, and/or, the storage unit that is subjected to write protection in the described protected field is carried out the instruction of write operation;
Step 207: working procedure;
Step 208~209: when the storage unit of being wiped protection when program run in to described protected field is carried out the instruction of erase operation, do not carry out this erasing instruction;
Step 210~211: when program run is subjected to the storage unit of write protection to carry out the instruction of write operation in to described protected field, does not carry out this and write instruction.
Should be noted that at last, above embodiment is only unrestricted in order to technical scheme of the present invention to be described, those of ordinary skill in the art is to be understood that, can make amendment or be equal to replacement technical scheme of the present invention, and not breaking away from the spiritual scope of technical solution of the present invention, it all should be encompassed in the middle of the claim scope of the present invention.