我不知道友善linux2.6.32的内核是否支持了mini2440的norflash,我在这里还是亲自的把mini2440的norflash支持上。移植过程分享如下:
一.添加配置项
1、修改 drivers/mtd/maps/Kconfig文件,在config_EDB7312配置项下添加如下内容:
config MTD_MINI2440
tristate "CFI Flash device mapped onMINI2440"
depends on ARM && MTD_CFI
help
This enables access to the CFI Flash on the CogentMINI2440 board.
If you have such a board, say 'Y' here.
2、修改 drivers/mtd/maps/Makefile文件,在obj-$(CONFIG_MTD_EDB7312)+= edb7312.o下添加如下内容:
obj-$(CONFIG_MTD_MINI2440)+= mini2440.o
3、复制驱动文件mini2440.c到drivers/mtd/maps目录下
1、修改 drivers/mtd/maps/Kconfig文件,在config_EDB7312配置项下添加如下内容:
config MTD_MINI2440
tristate "CFI Flash device mapped onMINI2440"
depends on ARM && MTD_CFI
help
This enables access to the CFI Flash on the CogentMINI2440 board.
If you have such a board, say 'Y' here.
2、修改 drivers/mtd/maps/Makefile文件,在obj-$(CONFIG_MTD_EDB7312)+= edb7312.o下添加如下内容:
obj-$(CONFIG_MTD_MINI2440)+= mini2440.o
3、复制驱动文件mini2440.c到drivers/mtd/maps目录下
二.配置编译内核
# make menuconfig
以下内容必选:
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 Inter/Sharp flash chips
# make menuconfig
以下内容必选:
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 Inter/Sharp flash chips
<*>Supportfor AMD/Fujitsu/Spansion flash chips
<*>CFI flash device mapped on mini2440
下列内容(在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
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.c中(带详细注释)
- /*支持单板: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,
- .bankwidth = BUSWIDTH,
- .phys = WINDOW_ADDR,
- };
- /* 默认分区信息*/
- static struct mtd_partition static_partitions[3] =
- {
- {
- .name = "bootloader",
- .size = 0x40000,//256K
- .offset = 0
- },
- {
- .name = "Kernel",
- .size = 0x100000,//1M
- .offset = 0x40000
- },
- {
- .name = "RootFS",
- .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(); //应该是mtd_info,而不是map_info,转载者注释
- *<3>探测分区信息,得到mtd_partition:parse_mtd_partitions();
- *<4>利用map_info和mtd_partition注册设备:mtd_device_register();//应该是mtd_info,而不是map_info,转载者注释
- */
- 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%08x\n", WINDOW_SIZE, WINDOW_ADDR);
- /*物理地址映射为虚拟地址*/
- mini2440nor_map.virt = ioremap(WINDOW_ADDR, WINDOW_SIZE);
- if (!mini2440nor_map.virt)
- {
- printk(MSG_PREFIX "failed to ioremap\n");
- 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";
- }
- 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);
- /*注册设备*/
- mtd_device_register(mymtd, NULL, 0);
- mtd_device_register(mymtd, mtd_parts, mtd_parts_nb);
- 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)
- {
- if (mymtd)
- {
- /*注销设备*/
- 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");