Linux移植随笔:让内核支持nor flash


内核:linux-2.6.37.3

nor flash芯片:SST39VF6401B

网上有文章说了如何让linux内核支持nor flash。不过那些转载的文章中没有头文件(因为使用了<尖括号>,在HTML语言中是注释的意思)。后来研究了类似的驱动文件,发现它们都是大同小异,只是在一些参数上有改变而已。本文中源代码基于那些转载文章的代码。

基于嵌入式Linux平台的最小文件系统的制作

MTD设备驱动程序在./driver/mtd下面,分为nor flash和nand flash两种。在chips中定义了几种访问nor的接口,包括cfi、jedec、map_ram和map_rom,而实际芯片所要添加的“驱动程序”放到maps目录下(比如本文使用的s3c2440-flash.c文件,详见文章后面)。从map这个单词来看,它描述的是一些映射信息,当然也包括了芯片信息,如总大小、块总数、访问接口等等。

这个过程其实是在内核代码树中添加自己的驱动的过程,当然是一些“标准”步骤了:在对应的代码树目录下,添加驱动源代码文件、在Makefile添加内容、在Kconfig添加内容,当然,还需要在make menuconfig里配置。

1、./driver/mtd/maps/Makefile

在这个Makefile最后添加:

obj-$(CONFIG_MTD_S3C2440) += s3c2440-flash.o

这个CONFIG_MTD_S3C2440由内核配置所得。

2、./driver/mtd/maps/Kconfig

在这个Kconfig文件最后添加(但在endmenu之前):

config MTD_S3C2440
 tristate "CFI Flash device mapped on S3C2440"
 depends on ARM && MTD_CFI
 help
   This enables access to the CFI Flash on the SMDK2440 board.
   If you have such a board, say 'Y' here.

这里的MTD_S3C2440就是前面Makefile中的那个,注意,CONFIG_前缀是内核自己添加的。可以在编译内核后生成的autoconf.h文件中查看该宏定义。

3、内核配置

在Device Drivers  --->   <*> Memory Technology Device (MTD) support  ---> 下面:

  1. Mapping drivers for chip access  --->    
  2.   
  3.  <*> CFI Flash device mapped on S3C2440      
  4.   
  5. RAM/ROM/Flash chip drivers  --->    
  6.   
  7.  <*> Detect flash chips by Common Flash Interface (CFI) probe   
  8.   
  9. [*] Flash chip driver advanced configuration options    
  10.   
  11. [*]   Specific CFI Flash geometry selection    
  12.   
  13. [*]     Support 16-bit buswidth   
  14.   
  15. [*]     Support 1-chip flash interleave    

4、./driver/mtd/maps/s3c2440-flash.c

代码见文章后面。

这个文件主要是修改前面的几个宏定义。我特地添加一些调试语句。开始时我使用2.6.30.2内核,驱动中使用cfi_probe接口,但是没有显示分区信息,后来我添加多几个接口才发现它是使用map_rom。这个过程花费了一些时间。

在2.6.30.2内核中,启动信息如下:
 

  1. S3C2440-NOR:0x00800000 at 0x01000000   
  2. S3C2440-NOR:func:init_s3c2440nor[120] mymtd:0 type:cfi_probe   
  3. S3C2440-NOR:func:init_s3c2440nor[120] mymtd:0 type:jedec_probe   
  4. S3C2440-NOR:func:init_s3c2440nor[120] mymtd:c39cb600 type:map_rom   
  5. S3C2440-NOR:using static partition definition   
  6. Creating 4 MTD partitions on "NOR Flash(SST39VF6401B) on S3C2440":   
  7. 0x000000000000-0x000000030000 : "U-Boot"  
  8. 0x000000030000-0x000000240000 : "Kernel"  
  9. 0x000000240000-0x0000007f0000 : "RootFS(jffs2)"  
  10. 0x0000007f0000-0x000000800000 : "Parameter"  

可以看到,的确是使用map_rom接口。但是,当我使用2.6.37.2时,发现它使用的是cfi_probe接口,启动信息如下:

  1. S3C2440-NOR:0x00800000 at 0x01000000   
  2. NOR Flash(SST39VF6401B) on S3C2440: Found 1 x16 devices at 0x0 in 16-bit bank.    
  3.   
  4. Manufacturer ID 0x0000bf Chip ID 0x00236d   
  5. number of CFI chips: 1   
  6. ## LL debug S3C2440-NOR:func:init_s3c2440nor[121] mymtd:c3a19200 type:cfi_probe   
  7. mtd: Giving out device 0 to NOR Flash(SST39VF6401B) on S3C2440   
  8. S3C2440-NOR:using static partition definition   
  9. Creating 4 MTD partitions on "NOR Flash(SST39VF6401B) on S3C2440":   
  10. 0x000000000000-0x000000030000 : "U-Boot"  
  11. mtd: Giving out device 1 to U-Boot   
  12. 0x000000030000-0x000000240000 : "Kernel"  
  13. mtd: Giving out device 2 to Kernel   
  14. 0x000000240000-0x0000007f0000 : "Rootfs(jffs2)"  
  15. mtd: Giving out device 3 to Rootfs(jffs2)   
  16. 0x0000007f0000-0x000000800000 : "Parameter"  
  17. mtd: Giving out device 4 to Parameter  
  • 1
  • 2
  • 下一页

相关内容