移植Linux内核到norflash.docx_第1页
移植Linux内核到norflash.docx_第2页
移植Linux内核到norflash.docx_第3页
移植Linux内核到norflash.docx_第4页
移植Linux内核到norflash.docx_第5页
已阅读5页,还剩16页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

开发板上只有NorFlash,所以为了实现层次文件系统,需要为Linux2.6.20增加NorFlashMTD驱动支持。其实工作量并不大,因为已经有现成的程序可供参考。MTD的驱动程序都集中在drivers/mtd里面。我们需要做的,仅仅是在drivers/mtd/maps下增加自己的分区表。因为有参考的代码,所以比较容易。(1)构建配置选项首先,根据edb7312.c构建自己的mtd分区表驱动(根据cfi_flagadm.c这个文件也可以奥,看情况吧!)。$cddrivers/mtd/maps/$cpedb7312.cat91rm9200.c然后,修改drivers/mtd/maps/Kconfig,增加自己的配置选项。/拷贝过EDB7312稍作修改即可configMTD_AT91RM9200tristateCFIFlashdevicemappedonAT91RM9200dependsonARM&MTD_CFIhelpThisenablesaccesstotheCFIFlashontheATMELAT91RM9200DKboard.Ifyouhavesuchaboard,sayYhere.最后,修改Makefile,增加编译项目。obj-$(CONFIG_MTD_EDB7312)+=edb7312.oobj-$(CONFIG_MTD_AT91RM9200)+=at91rm9200.o这样,自己建立的MTD分区表驱动就可以编译进内核了。(2)修改分区表信息因为第一步的工作中,at91rm9200.c实际上还是edb7312.c的内容,所以需要根据自己的开发板norflash的配置做一下修改。#include#include#include#include#include#include#include#ifdefCONFIG_MTD_PARTITIONS#include#endif#defineWINDOW_ADDR0x10000000/*physicalpropertiesofflash*/#defineWINDOW_SIZE0x00800000/*intel28F640J3A8MB*/#defineBUSWIDTH2/*databuswidth16bits*/*canbecfi_probe,jedec_probe,map_rom,NULL;*/#definePROBETYPEScfi_probe,NULL#defineMSG_PREFIXAT91RM9200-NOR:/*prefixforourprintk()s*/#defineMTDIDat91rm9200-%d/*formtdparts=partitioning*/staticstructmtd_info*mymtd;structmap_infoat91rm9200nor_map=.name=NORflashonAT91RM9200DK,.size=WINDOW_SIZE,.bankwidth=BUSWIDTH,.phys=WINDOW_ADDR,;#ifdefCONFIG_MTD_PARTITIONS/*MTDpartitioningstuff*/staticstructmtd_partitionat91rm9200nor_partitions5=/U-boot128KB.name=U-boot,.size=0x20000,.offset=0,/uImage2MB.name=Kernel,.size=0x200000,.offset=0x20000,/RootFS3MB.name=RootFS,.size=0x300000,.offset=0x220000,/UserFS.name=Jffs2,.size=0x2C0000,.offset=0x520000,/P=Parameters,.size=0x20000,.offset=0x7E0000,;staticconstchar*probes=NULL;#endifstaticintmtd_parts_nb=0;staticstructmtd_partition*mtd_parts=0;int_initinit_at91rm9200nor(void)staticconstchar*rom_probe_types=PROBETYPES;constchar*type;constchar*part_type=0;printk(KERN_NOTICEMSG_PREFIX0x%08xat0x%08xn,WINDOW_SIZE,WINDOW_ADDR);at91rm9200nor_map.virt=ioremap(WINDOW_ADDR,WINDOW_SIZE);if(!at91rm9200nor_map.virt)printk(MSG_PREFIXfailedtoioremapn);return-EIO;simple_map_init(&at91rm9200nor_map);mymtd=0;type=rom_probe_types;for(;!mymtd&*type;type+)mymtd=do_map_probe(*type,&at91rm9200nor_map);if(mymtd)mymtd-owner=THIS_MODULE;#ifdefCONFIG_MTD_PARTITIONSmtd_parts_nb=parse_mtd_partitions(mymtd,probes,&mtd_parts,0);if(mtd_parts_nb0)part_type=detected;if(mtd_parts_nb=0)mtd_parts=at91rm9200nor_partitions;mtd_parts_nb=ARRAY_SIZE(at91rm9200nor_partitions);part_type=static;#endifadd_mtd_device(mymtd);if(mtd_parts_nb=0)printk(KERN_NOTICEMSG_PREFIXnopartitioninfoavailablen);elseprintk(KERN_NOTICEMSG_PREFIXusing%spartitiondefinitionn,part_type);/mymtd为mastermtd_info它不被添加到数组mtd_table中,它只用于初始化/每一个分区的mtd_info。而后将每一个分区对应的mtd_info添加到数组mtd_table/供上层调用。MTD原始设备驱动层的主要工作就是向mtd_table中添加mtd_info。add_mtd_partitions(mymtd,mtd_parts,mtd_parts_nb);return0;iounmap(void*)at91rm9200nor_map.virt);return-ENXIO;staticvoid_exitcleanup_at91rm9200nor(void)if(mymtd)del_mtd_device(mymtd);map_destroy(mymtd);if(at91rm9200nor_map.virt)iounmap(void*)at91rm9200nor_map.virt);at91rm9200nor_map.virt=0;module_init(init_at91rm9200nor);module_exit(cleanup_at91rm9200nor);MODULE_LICENSE(GPL);MODULE_AUTHOR(MariusGroeger);MODULE_DESCRIPTION(GenericconfigurableMTDmapdriver);(3)配置内核增加MTD,和相应的文件系统的支持。DevicesDrivers-MemoryTechnologyDevices(MTD)-MemoryTechnologyDevice(MTD)supportMTDpartitioningsupportDirectchardeviceaccesstoMTDdevicesCachingblockdeviceaccesstoMTDdevicesRAM/ROM/Flashchipdrivers-DetectflashchipsbyCommonFlashInterface(CFI)probeSupportforIntel/SharpflashchipsMappingdriversforchipaccess-CFIFlashdevicemappedonAT91RM9200FileSystems-Miscellaneousfilesystems- Journalling Flash File System v2 (JFFS2) support Compressed ROM file system support (cramfs)这里选择cramfs或者Jffs2的支持。(4)编译,然后加载makeImage编译,然后制作成uImage。这是JFFS2作为根文件系统的信息:TOPDIR=$($(whichpwd)TMP=$TOPDIR/linux.binTARGET=$TOPDIR/uImagearm-linux-objcopy-Obinary-Svmlinux$TMP&gzip-v9$TMP&mkimage-nRAMdisk-Aarm-Olinux-Tkernel-Cgzip-a0x20008000-e0x20008000-d$TMP.gz$TARGET&cp$TARGET/mnt/hgfs/common&rm-f$TMP*可以看到MTD分区信息。进入shell界面,然后查看/proc/mtd,如下:AT91RM9200-NOR:0x00800000at0x10000000NORflashonAT91RM9200DK:Found1x16devicesat0x0in16-bitbankIntel/SharpExtendedQueryTableat0x0031Usingbufferwritemethodcfi_cmdset_0001:ErasesuspendonwriteenabledAT91RM9200-NOR:usingstaticpartitiondefinitionCreating5MTDpartitionsonNORflashonAT91RM9200DK:0x00000000-0x00020000:U-boot0x00020000-0x00220000:Kernel0x00220000-0x00520000:RootFS0x00520000-0x007e0000:Jffs20x007e0000-0x00800000:Parameters可以看到加载是正确的。内核:linux-nor flash芯片:SST39VF6401B网上有文章说了如何让linux内核支持nor flash。不过那些转载的文章中没有头文件(因为使用了,在一些网页中是不会显示的,详细请参考HTML相关资料)。后来研究了类似的驱动文件,发现它们都是大同小异,只是在一些参数上有改变而已。本文中源代码基于那些转载文章的代码。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之前):configMTD_S3C2440tristate“CFI Flash device mapped on S3C2440dependsonARM&MTD_CFIhelpThisenablesaccesstotheCFIFlashontheSMDK2440board.Ifyouhavesuchaboard,sayYhere.这里的MTD_S3C2440就是前面Makefile中的那个,注意,CONFIG_前缀是内核自己添加的。可以在编译内核后生成的autoconf.h文件中查看该宏定义。3、内核配置在Device Drivers Memory Technology Device (MTD) support 下面:MappingdriversforchipaccessCFIFlashdevicemappedonS3C2440RAM/ROM/Flash chip drivers DetectflashchipsbyCommonFlashInterface(CFI)probe*Flashchipdriveradvancedconfigurationoptions*SpecificCFIFlashgeometryselection*Support16-bitbuswidth*Support1-chipflashinterleave4、./driver/mtd/maps/s3c2440-flash.c代码见文章后面。这个文件主要是修改前面的几个宏定义。我特地添加一些调试语句。开始时我使用内核,驱动中使用cfi_probe接口,但是没有显示分区信息,后来我添加多几个接口才发现它是使用map_rom。这个过程花费了一些时间。在内核中,启动信息如下:S3C2440-NOR:0x00800000at0x01000000S3C2440-NOR:func:init_s3c2440nor120mymtd:0type:cfi_probeS3C2440-NOR:func:init_s3c2440nor120mymtd:0type:jedec_probeS3C2440-NOR:func:init_s3c2440nor120mymtd:c39cb600type:map_romS3C2440-NOR:usingstaticpartitiondefinitionCreating4MTDpartitionson“NOR Flash(SST39VF6401B) on S3C2440:0x000000000000-0x000000030000:“U-Boot”0x000000030000-0x000000240000:“Kernel”0x000000240000-0x0000007f0000:“RootFS(jffs2)”0x0000007f0000-0x000000800000:“Parameter”可以看到,的确是使用map_rom接口。但是,当我使用时,发现它使用的是cfi_probe接口,启动信息如下:S3C2440-NOR:0x00800000at0x01000000NORFlash(SST39VF6401B)onS3C2440:Found1x16devicesat0x0in16-bitbank.ManufacturerID0x0000bfChipID0x00236dnumberofCFIchips:1#LLdebugS3C2440-NOR:func:init_s3c2440nor121mymtd:c3a19200type:cfi_probemtd:Givingoutdevice0toNORFlash(SST39VF6401B)onS3C2440S3C2440-NOR:usingstaticpartitiondefinitionCreating4MTDpartitionson“NOR Flash(SST39VF6401B) on S3C2440:0x000000000000-0x000000030000:“U-Boot”mtd:Givingoutdevice1toU-Boot0x000000030000-0x000000240000:“Kernel”mtd:Givingoutdevice2toKernel0x000000240000-0x0000007f0000:“Rootfs(jffs2)”mtd:Givingoutdevice3toRootfs(jffs2)0x0000007f0000-0x000000800000:“Parameter”mtd:Givingoutdevice4toParameter与前面不同的是,它打印了芯片的信息,如厂商ID、芯片ID等等。这是我想不通的地方,也是我采用新内核的原因。不过,在这片nor flash上使用jffs2文件系统却不成功,出现了大量的警告信息,提示说制作根文件系统时的erase block有问题。s3c2440-flash.c源代码:/* $Id:s3c2410.c,v1.002006/12/0510:18:14gleixnerExp$* HandlemappingoftheNORflashonCogentS3C2410boards* Copyright2002SYSGOReal-TimeSolutionsGmbH* Thisprogramisfreesoftware;youcanredistributeitand/ormodify* itunderthetermsoftheGNUGeneralPublicLicenseversion2as* publishedbytheFreeSoftwareFoundation.*/* LateLee* Thisfileismodifiedandthefilenamehaschangedtos3c2440-flash.c.* TheSMDK2440boardhasonlyoneflashbankwhichisa64Mbit(4Mx16)SSTSST39VF6401B;* 128x64KiBblocks.* ThiscodeisGPLed.*/#include#include#include#include#include#include#include#include#ifdefCONFIG_MTD_PARTITIONS#include#endif#defineWINDOW_ADDR0x01000000/*physicalpropertiesofflash*/#defineWINDOW_SIZE0x800000/*8MB*/#defineBUSWIDTH2/*2*8=16*/#defineFLASH_BLOCKSIZE_MAIN0x10000/*64KB(0x10000)128blocks*/#defineFLASH_NUMBLOCKS_MAIN128/*canbe“cfi_probe”,“jedec_probe”,“map_rom”,NULL;*/#definePROBETYPES“cfi_probe”,“jedec_probe”,“map_rom”,NULL#defineMSG_PREFIX“S3C2440-NOR:”/*prefixforourprintk()s*/#defineMTDID“s3c2440-nor”/*formtdparts=partitioning*/#defineDEBUG_FLASH#ifdefDEBUG_FLASH#defineflash_debug(fmt,args)printk(KERN_NOTICE“# LL debug “MSG_PREFIXfmt,#args)#else#defineflash_debug(fmt,args)#endifstaticstructmtd_info*mymtd;structmap_infos3c2440nor_map=.name=“NOR Flash(SST39VF6401B) on S3C2440,.size=WINDOW_SIZE,.bankwidth=BUSWIDTH,.phys=WINDOW_ADDR,;#ifdefCONFIG_MTD_PARTITIONS/* MTDpartitioningstuff*/staticstructmtd_partitionstatic_partitions=/*0:U-Boot:0-0x300000x30000=192KB*/.name=“U-Boot”,.size=0x030000,.offset=0x0,/*1:Kernel:0x30000-0x2400000x210000=2112KB=2.0625MB*/.name=“Kernel”,.size=0x210000,.offset=0x30000,/*2:Rootfs(jffs2):0x240000-0x7f00000x5b0000=5824KB=5.6875MB*/.name=“Rootfs(jffs2)”,.size=0x5b0000,.offset=0x240000,/*3:U-BootParameters:0x7f0000-0x8000000x10000=64KB*/.name=“Parameter”,.size=0x010000,.offset=0x7f0000,;/static const char *probes = “RedBoot”, “cmdlinepart”, NULL ;staticconstchar*probes=NULL;#endifstaticintmtd_parts_nb=0;staticstructmtd_partition*mtd_parts=0;int_initinit_s3c2440nor(void)staticconstchar*rom_probe_types=PROBETYPES;constchar*type;constchar*part_type=0;printk(KERN_NOTICEMSG_PREFIX“0x%08x at 0x%08xn”,WINDOW_SIZE,WINDOW_ADDR);s3c2440nor_map.virt=ioremap(WINDOW_ADDR,WINDOW_SIZE);if(!s3c2440nor_map.virt)printk(MSG_PREFIX“failed to ioremapn”);return-EIO;simple_map_init(&s3c2440nor_map)

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论