LINUX operating system-based bad block management method for NANDFLASH file-free system

文档序号:1921462 发布日期:2021-12-03 浏览:14次 中文

阅读说明:本技术 一种基于linux操作系统的nandflash无文件系统的坏块管理方法 (LINUX operating system-based bad block management method for NANDFLASH file-free system ) 是由 张泽坤 于 2021-07-20 设计创作,主要内容包括:本发明提供一种基于LINUX操作系统的NANDFLASH无文件系统的坏块管理方法,所述坏块管理方法包括:在LINUX操作系统下,通过修改NANDFLASH的驱动程序,使在对块读、写和擦除时自动跳过坏块。本发明利用LINUX操作系统内核源码可修改的特性,对NANDFLASH的驱动程序进行特定的修改,使其具有自动跳过坏块的功能。从而使应用程序在无文件系统的情况下无感的,连续读、写、擦除NANDFLASH的空间,无需担心坏块的问题。(The invention provides a method for managing bad blocks of a NANDFLASH file-free system based on a LINUX operating system, which comprises the following steps: under the LINUX operating system, the driver of NANDFLASH is modified, so that the bad block is automatically skipped when the block is read, written and erased. The invention utilizes the characteristic that the kernel source code of the LINUX operating system can be modified to specifically modify the driver program of the NANDFLASH, so that the NANDFLASH has the function of automatically skipping bad blocks. Therefore, the application program is insensible under the condition of no file system, the space of the NANDFLASH is continuously read, written and erased, and the problem of bad blocks is not needed to be worried about.)

1. A bad block management method of a NANDFLASH file-free system based on a LINUX operating system is characterized by comprising the following steps: under the LINUX operating system, the driver of NANDFLASH is modified, so that the bad block is automatically skipped when the block is read, written and erased.

2. The method of claim 1, wherein the bad block management method comprises the steps of:

s1, obtaining a bad block of the NANDFLASH;

s2, designing an algorithm for automatically skipping bad blocks according to the obtained bad blocks;

s3, modifying a driver of the NANDFLASH based on the designed algorithm for automatically skipping the bad blocks;

s4, recompiling the kernel of the LINUX operating system after modifying the driver of the NANDFLASH.

3. The method of claim 2, wherein the step S1 of obtaining the bad blocks of the NANDFLASH comprises the following sub-steps:

s11, defining a shaping array and a shaping variable in the kernel file nand _ bbt.c file; the shaping array is used for storing the bad block ID of the NANDFLASH; the shaping variable is used for recording the total number of the bad blocks;

s12, storing the bad block ID scanned by the create _ bbt () function into a shaping array, and recording the total number of bad blocks by using a shaping variable;

s13, using the kernel EXPORT _ SYMBOL macro to derive the total number of the shaping array and the bad blocks.

4. The method of claim 3, wherein the bad block IDs stored in the shaping array are arranged from small to large.

5. The method for managing bad blocks of the LINUX operating system-based NANDFLASH file-free system of claim 1, wherein the method for designing the algorithm for automatically skipping the bad blocks according to the obtained bad blocks in step S2 comprises the following sub-steps:

s21, judging whether the input block ID is smaller than the smallest bad block ID in the shaping array:

if yes, the fact that no bad block exists in front of the input block ID is indicated, the bad block does not need to be skipped, namely the operated block is the current block and the ID of the current block is returned;

if not, go to step S22;

s22, judging whether the total number of the input block ID + bad blocks is larger than the maximum bad block ID in the shaping array:

if so, returning block _ ID + nandflash _ bbt _ cnt as a new block ID; wherein, block _ ID represents the input block ID, and nandflash _ bbt _ cnt represents the total number of bad blocks;

if not, go to step S23;

s23, judging whether the input ID is in the shaping array:

if yes, acquiring the number of bad blocks smaller than the input block ID as bcnt, and the number of continuous bad blocks starting from the input ID as ccnt1, wherein the new block ID is new _ ID ═ block _ ID + bcnt + ccnt 1;

if not, the new block ID is new _ ID ═ block _ ID + bcnt, and then step S24 is performed;

s24, judging whether the new block ID obtained in step S23 is in the shaping array:

if yes, acquiring the number ccnt2 of the continuous bad blocks in the shaping array, and acquiring new _ ID which is new _ ID + ccnt2+ 1;

repeating the step S24 until the new block ID is not in the shaping array, executing the step S25;

s25, acquiring the number of bad blocks smaller than the new block ID as m, and acquiring the number of bad blocks smaller than the input block ID as n; if m > n, new _ id is block _ id + m, and step S26 is executed;

s26, repeating the steps S24-S25 to generate a final new block ID;

s27, the process returns to the final new block ID generated in step S26.

6. The method for managing bad blocks of the NANDFLASH no-file system based on the LINUX OS of claim 5, wherein the method for modifying the driver of the NANDFLASH based on the designed algorithm for automatically skipping the bad blocks in step S3 comprises the following sub-steps:

for read and write operations, two functions of spin _ read _ page () and spin _ program _ page () in a kernel file nand _ spi.c file are modified, and an incoming page ID is converted into a corresponding block ID; then, calling an algorithm designed in the step S2 for automatically skipping bad blocks to obtain a new block ID, and converting the obtained new block ID into a new page ID; finally, the new page ID is used to operate NANDFLASH.

For the erasing operation, the spinand _ erase _ block () function directly calls the algorithm designed in step S2 to automatically skip the bad block to obtain a new ID, and then performs block erasing on the new ID.

Technical Field

The invention relates to the technical field of security management of a file system, in particular to a bad block management method of a NANDFLASH non-file system based on a LINUX operating system.

Background

Due to the NANDFLASH process, the manufacturer can only ensure that block 0 is not a bad block when the chip leaves the factory. It is possible for other blocks to be bad. Therefore, the bad blocks need to be managed when the NANDFLASH is read and written, and the bad blocks in read-write operation are avoided. In the linux operating system, bad blocks are managed through file systems which are specially directed to NANDFLASH, such as JFFS2, YAFFS2 and FlashFx. After the file system exists, a user only needs to call an interface of the file system to perform operations such as reading, writing and erasing on the NANDFLASH without paying attention to the management problem of specific blocks and bad blocks of the operations. However, if the data (i.e., the file) stored in the NANDFLASH is to be deleted after the file system is available, the information of the data (i.e., the file) is simply deleted from the file allocation table of the file system by calling the deletion interface of the file system. While the data on the block where the data is actually stored is not deleted. The data on the block can then be read out by a corresponding programming tool or program. Data leakage is easily caused in the special field, and the safety is lacked. The application layer may operate the NANDFLASH through a device node (e.g./dev/mtd 0) of the NANDFLASH if a corresponding file system is not used. But the bad blocks can not be judged and the corresponding bad blocks can not be skipped. If the bad block is operated on, the data cannot be stored correctly.

Disclosure of Invention

The invention aims to provide a NANDFLASH non-file system bad block management method based on a LINUX operating system, and aims to solve the problems that the NANDFLASH managed by using the file system cannot truly delete data when the NANDFLASH is deleted, data leakage is easy to cause, the security is lack, and the NANDFLASH cannot be avoided when the NANDFLASH is not operated by using the file system.

The invention provides a NANDFLASH file system bad block management method based on a LINUX operating system, which comprises the following steps: under the LINUX operating system, the driver of NANDFLASH is modified, so that the bad block is automatically skipped when the block is read, written and erased.

Further, the bad block management method includes the following steps:

s1, obtaining a bad block of the NANDFLASH;

s2, designing an algorithm for automatically skipping bad blocks according to the obtained bad blocks;

s3, modifying a driver of the NANDFLASH based on the designed algorithm for automatically skipping the bad blocks;

s4, recompiling the kernel of the LINUX operating system after modifying the driver of the NANDFLASH.

Further, the method for obtaining the bad block of the NANDFLASH in step S1 includes the following sub-steps:

s11, defining a shaping array with the length of 32 and a shaping variable in the kernel file nand _ bbt.c file; the shaping array is used for storing the bad block ID of the NANDFLASH; the shaping variables are used for recording the total number of the bad blocks;

s12, storing the bad block ID scanned by the create _ bbt () function into a shaping array, and recording the total number of bad blocks by using a shaping variable;

s13, using the kernel EXPORT _ SYMBOL macro to derive the total number of the shaping array and the bad blocks.

Further, the bad block IDs stored in the shaping array are arranged from small to large.

Further, the method for designing an algorithm for automatically skipping a bad block according to the obtained bad block in step S2 includes the following sub-steps:

s21, judging whether the input block ID is smaller than the smallest bad block ID in the shaping array:

if yes, the fact that no bad block exists in front of the input block ID is indicated, the bad block does not need to be skipped, namely the operated block is the current block and the ID of the current block is returned;

if not, go to step S22;

s22, judging whether the total number of the input block ID + bad blocks is larger than the maximum bad block ID in the shaping array:

if so, returning block _ ID + nandflash _ bbt _ cnt as a new block ID; wherein, block _ ID represents the input block ID, and nandflash _ bbt _ cnt represents the total number of bad blocks;

if not, go to step S23;

s23, judging whether the input ID is in the shaping array:

if yes, acquiring the number of bad blocks smaller than the input block ID as bcnt, and the number of continuous bad blocks starting from the input ID as ccnt1, wherein the new block ID is new _ ID ═ block _ ID + bcnt + ccnt 1;

if not, the new block ID is new _ ID ═ block _ ID + bcnt, and then step S24 is performed;

s24, judging whether the new block ID obtained in step S23 is in the shaping array:

if yes, acquiring the number ccnt2 of the continuous bad blocks in the shaping array, and acquiring new _ ID which is new _ ID + ccnt2+ 1;

repeating the step S24 until the new block ID is not in the shaping array, executing the step S25;

s25, acquiring the number of bad blocks smaller than the new block ID as m, and acquiring the number of bad blocks smaller than the input block ID as n; if m > n, new _ id is block _ id + m, and step S26 is executed;

s26, repeating the steps S24-S25 to generate a final new block ID;

s27, the process returns to the final new block ID generated in step S26.

Further, the method for modifying the driver of the NANDFLASH based on the designed algorithm for automatically skipping the bad block in step S3 includes the following sub-steps:

for read and write operations, two functions of spin _ read _ page () and spin _ program _ page () in a kernel file nand _ spi.c file are modified, and an incoming page ID is converted into a corresponding block ID; then, calling an algorithm designed in the step S2 for automatically skipping bad blocks to obtain a new block ID, and converting the obtained new block ID into a new page ID; finally, the new page ID is used to operate NANDFLASH.

For the erasing operation, the spinand _ erase _ block () function directly calls the algorithm designed in step S2 to automatically skip the bad block to obtain a new ID, and then performs block erasing on the new ID.

In summary, due to the adoption of the technical scheme, the invention has the beneficial effects that:

the invention utilizes the characteristic that the kernel source code of the LINUX operating system can be modified to specifically modify the driver program of the NANDFLASH, so that the NANDFLASH has the function of automatically skipping bad blocks. Therefore, the application program is insensible under the condition of no file system, the space of the NANDFLASH is continuously read, written and erased, and the problem of bad blocks is not needed to be worried about.

Drawings

In order to more clearly illustrate the technical solutions of the embodiments of the present invention, the drawings in the embodiments will be briefly described below, it should be understood that the following drawings only illustrate some embodiments of the present invention, and therefore should not be considered as limiting the scope, and for those skilled in the art, other related drawings can be obtained according to the drawings without inventive efforts.

Fig. 1 is a flowchart of a bad block management method of a LINUX operating system-based NANDFLASH file-free system according to an embodiment of the present invention.

Detailed Description

In order to make the objects, technical solutions and advantages of the embodiments of the present invention clearer, the technical solutions in the embodiments of the present invention will be clearly and completely described below with reference to the drawings in the embodiments of the present invention, and it is obvious that the described embodiments are some, but not all, embodiments of the present invention. The components of embodiments of the present invention generally described and illustrated in the figures herein may be arranged and designed in a wide variety of different configurations.

Thus, the following detailed description of the embodiments of the present invention, presented in the figures, is not intended to limit the scope of the invention, as claimed, but is merely representative of selected embodiments of the invention. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present invention.

Examples

The embodiment provides a bad block management method for a NANDFLASH file-free system based on a LINUX operating system, which comprises the following steps: under the LINUX operating system, the driver of NANDFLASH is modified, so that the bad block is automatically skipped when the block is read, written and erased. Therefore, the application program can perform operations such as reading, writing and erasing of the continuous space under the condition that the NANDFLASH does not use a file system, and the safety of data is further improved.

As shown in fig. 1, the bad block management method specifically includes the following steps:

s1, obtaining a bad block of NANDFLASH:

s11, defining a shaping array with the length of 32 and a shaping variable in the kernel file nand _ bbt.c file; the shaping array is used for storing the bad block ID of the NANDFLASH; the shaping variables are used for recording the total number of the bad blocks; as follows:

int nandflash _ bbt [32] ═ {0 }; nandflash _ bbt is the defined shaping array;

int nandflash _ bbt _ cnt is 0; nandflash _ bbt _ cnt is the defined shaping variable.

S12, storing the bad block ID scanned by the create _ bbt () function into a shaping array (nandflash _ bbt), and recording the total number of bad blocks by using a shaping variable (nandflash _ bbt _ cnt); and the bad block IDs stored in the shaping array are arranged from small to large.

S13, using the kernel EXPORT _ SYMBOL macro to derive the total number of the shaping array and the bad blocks. As follows:

EXPORT_SYMBOL(nandflash_bbt);

EXPORT_SYMBOL(nandflash_bbt_cnt)。

s2, designing an algorithm for automatically skipping the bad blocks according to the obtained bad blocks:

s21, judging whether the input block ID (represented as block _ ID) is smaller than the smallest bad block ID in the shaping array:

if yes, the fact that no bad block exists in front of the input block ID is indicated, the bad block does not need to be skipped, namely the operated block is the current block and the ID of the current block is returned;

if not, go to step S22;

s22, determining whether the total number of the input block ID + bad blocks (i.e., block _ ID + nandflash _ bbt _ cnt) is greater than the largest bad block ID in the shaping array:

if so, returning block _ ID + nandflash _ bbt _ cnt as a new block ID;

if not, go to step S23;

s23, judging whether the input ID is in the shaping array:

if yes, acquiring the number of bad blocks smaller than the input block ID as bcnt, and the number of continuous bad blocks starting from the input ID as ccnt1, wherein the new block ID is new _ ID ═ block _ ID + bcnt + ccnt 1; it should be noted that: (1) if the input block is a bad block, the number of the bad blocks smaller than the ID of the block itself comprises the bad block; (2) the number of the continuous bad blocks is the number of the bad blocks continuous to the bad block ID, and if the bad block ID is 3, 6, 7, 8 and 12. The number of the continuous bad blocks with the bad block ID of 6 is 7 and 8, namely the number of the continuous bad blocks is 2);

if not, the new block ID is new _ ID ═ block _ ID + bcnt, and then step S24 is performed;

s24, judging whether the new block ID obtained in step S23 is in the shaping array:

if yes, acquiring the number ccnt2 of the continuous bad blocks in the shaping array, and acquiring new _ ID which is new _ ID + ccnt2+ 1;

repeating the step S24 until the new block ID is not in the shaping array, executing the step S25;

s25, acquiring the number of bad blocks smaller than the new block ID as m, and acquiring the number of bad blocks smaller than the input block ID as n; if m > n, new _ id is block _ id + m, and step S26 is executed;

s26, repeating the steps S24-S25 to generate a final new block ID;

s27, the process returns to the final new block ID generated in step S26.

S3, modifying a driver of the NANDFLASH based on the designed algorithm for automatically skipping the bad blocks:

for read and write operations, two functions of spin _ read _ page () and spin _ program _ page () in a kernel file nand _ spi.c file are modified, and an incoming page ID is converted into a corresponding block ID; then, calling an algorithm designed in the step S2 for automatically skipping bad blocks to obtain a new block ID, and converting the obtained new block ID into a new page ID; finally, the new page ID is used to operate NANDFLASH.

For the erasing operation, the spinand _ erase _ block () function directly calls the algorithm designed in step S2 to automatically skip the bad block to obtain a new ID, and then performs block erasing on the new ID.

S4, recompiling the kernel of the LINUX operating system after modifying the driver of the NANDFLASH.

Therefore, the invention realizes the bad block management method of the NANDFLASH file-free system based on the LINUX operating system, and the method specifically modifies the driving program of the NANDFLASH by utilizing the characteristic that the kernel source code of the LINUX operating system can be modified, so that the NANDFLASH has the function of automatically skipping the bad blocks. Therefore, the application program is insensible under the condition of no file system, the space of the NANDFLASH is continuously read, written and erased, and the problem of bad blocks is not needed to be worried about.

The above description is only a preferred embodiment of the present invention and is not intended to limit the present invention, and various modifications and changes may be made by those skilled in the art. Any modification, equivalent replacement, or improvement made within the spirit and principle of the present invention should be included in the protection scope of the present invention.

8页详细技术资料下载
上一篇:一种医用注射器针头装配设备
下一篇:一种基于Java将OFD文件转换为图片的方法及系统

网友询问留言

已有0条留言

还没有人留言评论。精彩留言会获得点赞!

精彩留言,会给你点赞!