2.6核心移植NOR FLASH 驅動

來源:互聯網
上載者:User
一、分區資訊
   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");

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.