生活随笔
收集整理的這篇文章主要介紹了
Nor flash 驱动和移植
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
??開發板上只有Nor?Flash,所以為了實現層次文件系統,需要為Linux2.6.20增加Nor?Flash?MTD驅動支持。其實工作量并不大,因為已經有現成的程序可供參考。
?
????MTD的驅動程序都集中在drivers/mtd里面。我們需要做的,僅僅是在drivers/mtd/maps下增加自己的分區表。因為有參考的代碼,所以比較容易。
?
(1)構建配置選項
?
????首先,根據edb7312.c構建自己的mtd分區表驅動。
?
| $cd?drivers/mtd/maps/ $cp?edb7312.c?at91rm9200.c |
?
????然后,修改Kconfig,增加自己的配置選項。
?
| //拷貝過EDB7312稍作修改即可 config?MTD_AT91RM9200 ????????tristate?"CFI?Flash?device?mapped?on?AT91RM9200" ????????depends?on?ARM?&&?MTD_CFI ????????help ??????????This?enables?access?to?the?CFI?Flash?on?the?ATMEL?AT91RM9200DK?board. ??????????If?you?have?such?a?board,?say?'Y'?here. |
?
????最后,修改Makefile,增加編譯項目。
?
?
????這樣,自己建立的MTD分區表驅動就可以編譯進內核了。
?
(2)修改分區表信息
?
????因為第一步的工作中,at91rm9200.c實際上還是edb7312.c的內容,所以需要根據自己的開發板nor?flash的配置做一下修改。
?
| obj-$(CONFIG_MTD_EDB7312)?+=?edb7312.o obj-$(CONFIG_MTD_AT91RM9200)?+=?at91rm9200.o |
| #include?<linux/module.h> #include?<linux/types.h> #include?<linux/kernel.h> #include?<linux/init.h> #include?<asm/io.h> #include?<linux/mtd/mtd.h> #include?<linux/mtd/map.h> #ifdef?CONFIG_MTD_PARTITIONS #include?<linux/mtd/partitions.h> #endif #define?WINDOW_ADDR?0x10000000?/*?physical?properties?of?flash?*/ #define?WINDOW_SIZE?0x00800000?/*?intel?28F640J3A?8MB?*/ #define?BUSWIDTH?2?/*?data?bus?width?16bits?*/ /*?can?be?"cfi_probe",?"jedec_probe",?"map_rom",?NULL?};?*/ #define?PROBETYPES?{?"cfi_probe",?NULL?} #define?MSG_PREFIX?"AT91RM9200-NOR:"?/*?prefix?for?our?printk()'s?*/ #define?MTDID?"at91rm9200-%d"?/*?for?mtdparts=?partitioning?*/ static?struct?mtd_info?*mymtd; struct?map_info?at91rm9200nor_map?=?{ ????????.name?=?"NOR?flash?on?AT91RM9200DK", ????????.size?=?WINDOW_SIZE, ????????.bankwidth?=?BUSWIDTH, ????????.phys?=?WINDOW_ADDR, }; #ifdef?CONFIG_MTD_PARTITIONS /* ?*?MTD?partitioning?stuff ?*/ static?struct?mtd_partition?at91rm9200nor_partitions[5]?= { ????????{ ????????????????//?U-boot?128KB ????????????????.name?=?"U-boot", ????????????????.size?=?0x20000, ????????????????.offset?=?0 ????????}, ????????{ ????????????????//?uImage?2MB ????????????????.name?=?"Kernel", ????????????????.size?=?0x200000, ????????????????.offset?=?0x20000 ????????}, ????????{ ????????????????//?RootFS?3MB ????????????????.name?=?"RootFS", ????????????????.size?=?0x300000, ????????????????.offset?=?0x220000 ????????}, ????????{ ????????????????//?UserFS ????????????????.name?=?"Jffs2", ????????????????.size?=?0x2C0000, ????????????????.offset?=?0x520000 ????????}, ????????{ ????????????????//?Parameters ????????????????.name?=?"Parameters", ????????????????.size?=?0x20000, ????????????????.offset?=?0x7E0000 ????????}, }; static?const?char?*probes[]?=?{?NULL?}; #endif static?int?mtd_parts_nb?=?0; static?struct?mtd_partition?*mtd_parts?=?0; int?__init?init_at91rm9200nor(void) { ????????static?const?char?*rom_probe_types[]?=?PROBETYPES; ????????const?char?**type; ????????const?char?*part_type?=?0; ????????printk(KERN_NOTICE?MSG_PREFIX?"0x%08x?at?0x%08x\n", ???????????????WINDOW_SIZE,?WINDOW_ADDR); ????????at91rm9200nor_map.virt?=?ioremap(WINDOW_ADDR,?WINDOW_SIZE); ????????if?(!at91rm9200nor_map.virt)?{ ????????????????printk(MSG_PREFIX?"failed?to?ioremap\n"); ????????????????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; #ifdef?CONFIG_MTD_PARTITIONS ????????????????mtd_parts_nb?=?parse_mtd_partitions(mymtd,?probes,?&mtd_parts,?0); ????????????????if?(mtd_parts_nb?>?0) ??????????????????part_type?=?"detected"; ????????????????if?(mtd_parts_nb?==?0) ????????????????{ ????????????????????????mtd_parts?=?at91rm9200nor_partitions; ????????????????????????mtd_parts_nb?=?ARRAY_SIZE(at91rm9200nor_partitions); ????????????????????????part_type?=?"static"; ????????????????} #endif ????????????????add_mtd_device(mymtd); ????????????????if?(mtd_parts_nb?==?0) ??????????????????printk(KERN_NOTICE?MSG_PREFIX?"no?partition?info?available\n"); ????????????????else ????????????????{ ????????????????????????printk(KERN_NOTICE?MSG_PREFIX ???????????????????????????????"using?%s?partition?definition\n",?part_type); ?//mymtd為master?mtd_info它不被添加到數組mtd_table[]中,它只用于初始化 ?//每一個分區的mtd_info。而后將每一個分區對應的mtd_info添加到數組mtd_table[] ?//供上層調用。MTD原始設備驅動層的主要工作就是向?mtd_table[]中添加mtd_info。? ????????????????????????add_mtd_partitions(mymtd,?mtd_parts,?mtd_parts_nb); ????????????????} ????????????????return?0; ????????} ????????iounmap((void?*)at91rm9200nor_map.virt); ????????return?-ENXIO; } static?void?__exit?cleanup_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("Marius?Groeger?<mag@sysgo.de>"); MODULE_DESCRIPTION("Generic?configurable?MTD?map?driver"); |
?
(3)配置內核
?
????增加MTD,和相應的文件系統的支持。
?
????Devices?Drivers?--->
????????????Memory?Technology?Devices?(MTD)?--->
?????????????????<*>?Memory?Technology?Device(MTD)?support
?????????????????<*>?MTD?partitioning?support
?????????????????<*>?Direct?char?device?access?to?MTD?devices
?????????????????<*>?Caching?block?device?access?to?MTD?devices
?????????????????RAM/ROM/Flash?chip?drivers?--->
?????????????????????<*>?Detect?flash?chips?by?Common?Flash?Interface(CFI)?probe
?????????????????????<*>?Support?for?Intel/Sharp?flash?chips
?????????????????Mapping?drivers?for?chip?access?--->
?????????????????????<*>?CFI?Flash?device?mapped?on?AT91RM9200
????File?Systems?--->
???????????Miscellaneous?filesystems?--->
????????????????這里選擇cramfs或者Jffs2的支持。
?
(4)編譯,然后加載
?
????make?Image編譯,然后制作成uImage。
?
?
????這是JFFS2作為根文件系統的信息:
?
?
| TOPDIR=$($(which?pwd)) TMP=$TOPDIR/linux.bin TARGET=$TOPDIR/uImage arm-linux-objcopy?-O?binary?-S?vmlinux?$TMP?&&?gzip?-v9?$TMP?&&?\ mkimage?-n?'RAM?disk'?-A?arm?-O?linux?-T?kernel?-C?gzip?\ ????????-a?0x20008000?-e?0x20008000?-d?$TMP.gz?$TARGET?&&?\ cp?$TARGET?/mnt/hgfs/common?&&?\ rm?-f?$TMP* |
?
????可以看到MTD分區信息。進入shell界面,然后查看/proc/mtd,如下:
?
| AT91RM9200-NOR:0x00800000?at?0x10000000 NOR?flash?on?AT91RM9200DK:?Found?1?x16?devices?at?0x0?in?16-bit?bank ?Intel/Sharp?Extended?Query?Table?at?0x0031 Using?buffer?write?method cfi_cmdset_0001:?Erase?suspend?on?write?enabled AT91RM9200-NOR:using?static?partition?definition Creating?5?MTD?partitions?on?"NOR?flash?on?AT91RM9200DK": 0x00000000-0x00020000?:?"U-boot" 0x00020000-0x00220000?:?"Kernel" 0x00220000-0x00520000?:?"RootFS" 0x00520000-0x007e0000?:?"Jffs2" 0x007e0000-0x00800000?:?"Parameters" |
?
????可以看到加載是正確的。
總結
以上是生活随笔為你收集整理的Nor flash 驱动和移植的全部內容,希望文章能夠幫你解決所遇到的問題。
如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。