我不知道友善linux2.6.32的内核是否支持了mini2440的norflash,我在这里还是亲自的把mini2440的norflash支持上。移植过程分享如下: ????????????
一.添加配置项 1、修改?drivers/mtd/maps/Kconfig文件,在config_EDB7312配置项下添加如下内容: config?MTD_MINI2440 tristate"CFIFlashdevicemappedonMINI2440" dependsARM&&MTD_CFI help ThisenablesaccesstotheCFICogent2440board. Ifyouhavesuchaboard,say'Y'here. 2drivers/mtd/maps/Makefileobj-$(CONFIG_MTD_EDB7312)+= edb7312.o下: obj-$(CONFIG_MTD_MINI2440)+=mini2440.o 3、复制驱动文件mini2440.c到drivers/mtd/maps目录下
二.配置编译内核 #makemenuconfig 以下内容必选: MemoryTechnologyDevices(MTD)--> <*>MemoryDevice(MTD)support [*]MTDpartitioningsupport ?? <*>DirectcharMTDdevices ?? <*>Cachingblockdevices RAM/ROM/Flashchipdrivers--> ?? <*>DetectflashchipsbyCommonInterface(CFI)probe ?? <*>SupportforInter/Sharpchips
? ?<*>
Supportfor AMD/Fujitsu/Sp
ansion flash chips
? ?<*>CFImini2440
下列内容(在flash上架fat16/fat32/ntfs/ext2等文件系统时才需要选上)不要选,否则会出现加载驱动模块时会出现ftl_cs:FTL header not found. DeviceDrivers -> ??Memory Technology Devices (MTD) -> ??????<>FTL (Flash Translation Layer) support ?????? <> NFTL(NAND Flash Translation Layer) support ?????? <>INFTL(Inverse NAND Flash Translation Layer) support
三.根据edb7312单板的norflash驱动(linux/mtd/maps/edb7312.c)来写mini2440的norflash驱动
代码在中(带详细注释)
- /*支持单板:mini2440
- ?*支持内核:3.1.2版本
- ?*模仿驱动:/linux/drivers/mtd/maps/edb7312.c
- ?*/
-
- #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>
- #include <linux/mtd/partitions.h>
- #define WINDOW_ADDR 0x00000000 ? ? /* NOR FLASH物理地址 */
- #define WINDOW_SIZE 0x00200000 ? ? ? ? /* NOR FLASH大小 */
- #define BUSWIDTH ? ?2 /*估计是2Byte*/
- /* 探测的接口类型,可以是"cfi_probe","jedec_probe","map_rom",NULL }; */
- #define PROBETYPES { "cfi_probe",NULL }
- #define MSG_PREFIX "MINI2440-NOR:" ? /*printk的前缀 */
- #define MTDID ? ? ?"mini2440-nor" ? ?/*MTD驱动*/
- static struct mtd_info *mymtd;
- /*定义一个map_info,代表一块norflash*/
- struct map_info mini2440nor_map =
- {
- ? ? ? ? .name = "NOR flash on MINI2440",
- ? ? ? ? .size = WINDOW_SIZE,serif; list-style-type:decimal-leading-zero; padding-right:1em"> ? ? ? ? .bankwidth = BUSWIDTH,serif; list-style-type:decimal-leading-zero; padding-right:1em"> ? ? ? ? .phys = WINDOW_ADDR,serif; list-style-type:decimal-leading-zero; padding-right:1em"> };
- /* 默认分区信息*/
- static struct mtd_partition static_partitions[3] =
- .name = "bootloader",serif; list-style-type:decimal-leading-zero; padding-right:1em"> .size = 0x40000,//256K
- .offset = 0
- },serif; list-style-type:decimal-leading-zero; padding-right:1em"> .name = "Kernel",serif; list-style-type:decimal-leading-zero; padding-right:1em"> .size = 0x100000,//1M
- .offset = 0x40000
- .name = "RootFS",serif; list-style-type:decimal-leading-zero; padding-right:1em"> .size = 0xC0000,//768K
- .offset = 0x140000
- static const char *probes[] = {NULL};
- static int mtd_parts_nb = 0;
- static struct mtd_partition *mtd_parts = 0;
- /*Norflash模型初始化函数
- ?*<1>物理地址映射为虚拟地址: mini2440nor_map.virt = ioremap(WINDOW_ADDR,WINDOW_SIZE);
- ?*<2>探测norflash芯片,得到map_info:do_map_probe();
- ?*<3>探测分区信息,得到mtd_partition:parse_mtd_partitions();
- ?*<4>利用map_info和mtd_partition注册设备:mtd_device_register();
- int __init init_mini2440nor(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%08xn",WINDOW_SIZE,WINDOW_ADDR);
- ? ? ? ? /*物理地址映射为虚拟地址*/
- ? ? ? ? mini2440nor_map.virt = ioremap(WINDOW_ADDR,serif; list-style-type:decimal-leading-zero; padding-right:1em"> ? ? ? ? if (!mini2440nor_map.virt)
- ? ? ? ? {
- ? ? ? ? ? ? ? ? printk(MSG_PREFIX "failed to ioremapn");
- ? ? ? ? ? ? ? ? return ?-EIO;
- ? ? ? ? }
- ? ? ? ? simple_map_init(&mini2440nor_map);
- ? ? ? ? mymtd = 0;
- ? ? ? ? type = rom_probe_types;
- ? ? ? ? for (; !mymtd && ?*type; type++)
- ? ? ? ? ? ? ? ? /*根据map_info探测norflash芯片,若成功则返回mtd_info*/
- ? ? ? ? ? ? ? ? mymtd = do_map_probe(*type,&mini2440nor_map);
- ? ? ? ? if (mymtd)
- ? ? ? ? ? ? ? ? mymtd->owner = THIS_MODULE;
- ? ? ? ? ? ? ? ? /*探测分区信息,若探测成功,则mtd_parts中保存了分区信息;若探测失败,使用数组定义的默认分区信息*/
- ? ? ? ? ? ? ? ? mtd_parts_nb = parse_mtd_partitions(mymtd,probes,&mtd_parts,MTDID);
- ? ? ? ? ? ? ? ? if (mtd_parts_nb > 0)
- ? ? ? ? ? ? ? ? ? ? ? ? part_type = "detected";
- ? ? ? ? ? ? ? ? if (mtd_parts_nb == 0)
- ? ? ? ? ? ? ? ? {
- ? ? ? ? ? ? ? ? ? ? ? ? mtd_parts = static_partitions;
- ? ? ? ? ? ? ? ? ? ? ? ? mtd_parts_nb = ARRAY_SIZE(static_partitions);
- ? ? ? ? ? ? ? ? ? ? ? ? part_type = "static";
- ? ? ? ? ? ? ? ? }
- ? ? ? ? ? ? ? ? ? ? ? ? printk(KERN_NOTICE MSG_PREFIX "no partition info availablen");
- ? ? ? ? ? ? ? ? else
- ? ? ? ? ? ? ? ? ? ? ? ? printk(KERN_NOTICE MSG_PREFIX "using %s partition definitionn",serif; list-style-type:decimal-leading-zero; padding-right:1em"> ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?part_type);
- ? ? ? ? ? ? ? ? /*注册设备*/
- ? ? ? ? ? ? ? ? mtd_device_register(mymtd,NULL,0);
- ? ? ? ? ? ? ? ? return 0;
- ? ? ? ? iounmap((void *)mini2440nor_map.virt);
- ? ? ? ? return -ENXIO;
- }
- /*Norflash模块卸载函数
- ?*<1>注销设备:mtd_device_unregister();
- ?*<2>销毁map_info:map_destroy();
- ?*<3>取消映射:iounmap();
- static void __exit cleanup_mini2440nor(void)
- ? ? ? ? ? ? ? ? /*注销设备*/
- ? ? ? ? ? ? ? ? mtd_device_unregister(mymtd);
- ? ? ? ? ? ? ? ? /*销毁map_info*/
- ? ? ? ? ? ? ? ? map_destroy(mymtd);
- ? ? ? ? if (mini2440nor_map.virt)
- ? ? ? ? ? ? ? ? iounmap((void*)mini2440nor_map.virt);
- ? ? ? ? ? ? ? ? mini2440nor_map.virt = 0;
- module_init(init_mini2440nor);
- module_exit(cleanup_mini2440nor);
-
- MODULE_LICENSE("GPL");
- MODULE_AUTHOR("WeiDong Wu <625769020@qq.com>");
- MODULE_DESCRIPTION("Generic configurable MTD map driver");
(编辑:李大同)
【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!
|