Linux2.6内核移植NOR FLASH 驱动

一、分区信息
HHARM2410-STUDY开发板使用16bit 8M NOR FLASH,分区信息如下:
0x00000000-0x00040000 : "bootloader"
0x00040000-0x00140000 : "kernel"
0x00140000-0x00540000 : "ramdisk"
0x00540000-0x00740000 : "cramfs"
0x00740000-0x00800000 : "jffs2"
二、添加配置项
1、修改 drivers/mtd/maps/Kconfig文件,添加如下内容:
config MTD_S3C2410
tristate "CFI Flash device mapped on S3C2410"
depends on ARM && MTD_CFI
help
This enables access to the CFI Flash on the Cogent S3C2410 board.
If you have such a board, say 'Y' here.
2、修改 drivers/mtd/maps/Makefile文件,添加如下内容:
obj-$(CONFIG_MTD_S3C2410)+= s3c2410.o
3、复制驱动文件s3c2410.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
Mapping drivers for chip access-->
<*>CFI flash device mapped on S3C2410
Miscellaneous filesystems-->
<*>Journalling Flash File System v2 (JFFS2) support
<*>Compressed ROM file system support (cramfs)
# make zImage
四、建立设备文件
# mknod -m 666 mtd0 c 90 0
# mknod -m 666 mtd1 c 90 2
# mknod -m 666 mtd2 c 90 4
# mknod -m 666 mtd3 c 90 6
# mknod -m 666 mtd4 c 90 8
# mknod -m 666 mtd5 c 90 10
# mknod -m 666 mtdblock0 b 31 0
# mknod -m 666 mtdblock1 b 31 1
# mknod -m 666 mtdblock2 b 31 2
# mknod -m 666 mtdblock3 b 31 3
# mknod -m 666 mtdblock4 b 31 4
# mknod -m 666 mtdblock5 b 31 5
五、驱动文件s3c2410.c
#include
#include
#include
#include
#include
#include
#include
#include
#ifdef CONFIG_MTD_PARTITIONS
#include
#endif
#define WINDOW_ADDR 0x01000000
#define WINDOW_SIZE 0x800000
#define BUSWIDTH 2
#define FLASH_BLOCKSIZE_MAIN0x20000
#define FLASH_NUMBLOCKS_MAIN128

#define PROBETYPES { "cfi_probe", NULL }
#define MSG_PREFIX "S3C2410-NOR:"
#define MTDID "s3c2410-nor"
static struct mtd_info *mymtd;
struct map_info s3c2410nor_map = {
.name = "NOR flash on S3C2410",
.size = WINDOW_SIZE,
.bankwidth = BUSWIDTH,
.phys = WINDOW_ADDR,
};
#ifdef CONFIG_MTD_PARTITIONS

static struct mtd_partition static_partitions[] =
{
{
.name = "BootLoader",
.size = 0x040000,
.offset = 0x0
},
{
.name = "Kernel",
.size = 0x0100000,
.offset = 0x40000
},
{
.name = "RamDisk",
.size = 0x400000,
.offset = 0x140000
},
{
.name = "cramfs(2MB)",
.size = 0x200000,
.offset = 0x540000
},
{
.name = "jffs2(0.75MB)",
.size = 0xc0000,
.offset = 0x740000
},
};
//static const char *probes[] = { "RedBoot", "cmdlinepart", NULL };
static const char *probes[] = { NULL };
#endif
static int mtd_parts_nb = 0;
static struct mtd_partition *mtd_parts = 0;
int __init init_s3c2410nor(void)
{
static const char *rom_probe_types[] = PROBETYPES;
const char **type;
const char *part_type = 0;
printk(KERN_NOTICE MSG_PREFIX "0xx at 0xx\n",
WINDOW_SIZE, WINDOW_ADDR);
s3c2410nor_map.virt = ioremap(WINDOW_ADDR, WINDOW_SIZE);
if (!s3c2410nor_map.virt) {
printk(MSG_PREFIX "failed to ioremap\n");
return -EIO;
}
simple_map_init(&s3c2410nor_map);
mymtd = 0;
type = rom_probe_types;
for(; !mymtd && *type; type++) {
mymtd = do_map_probe(*type, &s3c2410nor_map);
}
if (mymtd) {
mymtd->owner = THIS_MODULE;
#ifdef CONFIG_MTD_PARTITIONS
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";
}
#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);
add_mtd_partitions(mymtd, mtd_parts, mtd_parts_nb);
}
return 0;
}
iounmap((void *)s3c2410nor_map.virt);
return -ENXIO;
}
static void __exit cleanup_s3c2410nor(void)
{
if (mymtd) {
del_mtd_device(mymtd);
map_destroy(mymtd);
}
if (s3c2410nor_map.virt) {
iounmap((void *)s3c2410nor_map.virt);
s3c2410nor_map.virt = 0;
}
}
module_init(init_s3c2410nor);
module_exit(cleanup_s3c2410nor);
MODULE_LICENSE("GPL");
MODULE_AUTHOR("GengYaoJun ");
MODULE_DESCRIPTION("Generic configurable MTD map driver");

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值