您的位置:首页 > 其它

2.6内核移植NOR FLASH 驱动

2007-04-26 21:02 369 查看
<SCRIPT type=text/javascript><!--
google_ad_client = "pub-2132256014190581";
/* 160x600, 创建于 09-1-4 */
google_ad_slot = "4461398019";
google_ad_width = 160;
google_ad_height = 600;
//-->
</SCRIPT>

<SCRIPT src="http://pagead2.googlesyndication.com/pagead/show_ads.js" type=text/javascript>
</SCRIPT>
一、分区信息
   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
/*
* $Id: s3c2410.c,v 1.00 2006/12/05 10:18:14 gleixner Exp $
*
* Handle mapping of the NOR flash on Cogent S3C2410 boards
*
* Copyright 2002 SYSGO Real-Time Solutions GmbH
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*/

#include
#include
#include
#include
#include
#include
#include
#include

#ifdef CONFIG_MTD_PARTITIONS
#include
#endif

#define WINDOW_ADDR 0x01000000      /* physical properties of flash */
#define WINDOW_SIZE 0x800000
#define BUSWIDTH    2
#define FLASH_BLOCKSIZE_MAIN0x20000
#define FLASH_NUMBLOCKS_MAIN128
/* can be "cfi_probe", "jedec_probe", "map_rom", NULL }; */
#define PROBETYPES { "cfi_probe", NULL }

#define MSG_PREFIX "S3C2410-NOR:"   /* prefix for our printk()'s */
#define MTDID      "s3c2410-nor"    /* for mtdparts= partitioning */

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

/*
* MTD partitioning stuff
*/
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 "0x%08x at 0x%08x/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");

 
<SCRIPT type=text/javascript><!--
google_ad_client = "pub-2132256014190581";
/* 160x600, 创建于 09-1-4 */
google_ad_slot = "4461398019";
google_ad_width = 160;
google_ad_height = 600;
//-->
</SCRIPT>

<SCRIPT src="http://pagead2.googlesyndication.com/pagead/show_ads.js" type=text/javascript>
</SCRIPT>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  flash module struct c access null