频道栏目
首页 > 资讯 > Linux > 正文

linux-2.6.35内核移植——Nand flash驱动的移植

12-07-06        来源:[db:作者]  
收藏   我要投稿

linux-2.6.35内核移植——Nand flash驱动的移植
 
Nand flash 是嵌入式系统最常用的外部存储设备,这里介绍Nand flash驱动移植的过程。
一、移植环境:
1、  Ubuntu 10.10发行版
2、  u-boot.bin
3、  FS_S5PC100平台
4、  交叉编译器: arm-cortex_a8-linux-gnueabi-gcc
---------------------------------------------------------------------
二、移植步骤
 
       在linux-2.6.35.2的内核中已经包含了s3c2410的nand flash控制器的驱动,但是需要我们正确配置后才能正常工作。
 
1、添加针对FS_S5PC100平台上的Nand flash驱动
  拷贝 s3c_nand.c  http://download.csdn.net/detail/baby_afu/4412870到drivers/mtd/nand下
  拷贝 regs-nand.h  http://download.csdn.net/detail/baby_afu/4412873到 arch/arm/mach-s5pc100/include/mach下
2、针对FS_S5PC100平台上的nand flash 设备,修改driver/mtd/nand/nand_base.c
  第2812行  www.2cto.com  
/* Read entire ID string */
for (i = 0; i < 8; i++)
/* Read entire ID string */
for (i = 0; i < 5; i++)
 
3、添加内核配置选项
修改driver/mtd/nand/Kconfig添加如下内容:
 
config MTD_NAND_S3C
    tristate "NAND Flash support for S3C Soc"
    depends on (ARCH_S3C64XX || ARCH_S5P64XX || ARCH_S5PC1XX || ARCH_S5PC100) && MTD_NAND
    help
    This enables the NAND flash controller on the S3C.
    No board specfic support is done by this driver , each board
    must advertise a platform_device for the driver to attach.
 
config MTD_NAND_S3C_DEBUG
    bool "S3C NAND driver debug"
    depends on MTD_NAND_S3C
    help
    Enable debugging of the S3C NAND driver
 
config MTD_NAND_S3C_HWECC
    bool "S3C NAND Hardware ECC"
    depends on MTD_NAND_S3C
    help  www.2cto.com  
    Enable the use of the S3C's internal ECC generator when 
    using NAND. Early versons of the chip have had problems with
    incorrect ECC generation, and if using these, the default of
    software ECC is preferable
 
    If you lay down a device with the hardware ECC, the you will
    currently not be able to switch to software, as there is no
    implementation for ECC method used by the S3C
 
 修改drivers/mtd/nand/Makefile添加如下内容:
obj-$(CONFIG_MTD_NAND_S3C)        += s3c_nand.o
4、修改平台代码
修改arch/arm/mach-s5pc100/mach-smdkc100.c添加如下内容:
添加头文件
#if defined(CONFIG_MTD_NAND_S3C)
#include <linux/mtd/partitions.h>
#include <linux/mtd/mtd.h>
#include <plat/nand.h>
#endif
添加平台设备
 
/** Nand flash Support **/
#if defined(CONFIG_MTD_NAND_S3C)
static struct mtd_partition s5pc100_nand_part[] = {
    [0] = {
        .name   = "bootloader",
        .size   = SZ_1M,
        .offset = 0,
    },
    [1] = {
        .name   = "kernel",
        .offset = MTDPART_OFS_APPEND,
        .size   = SZ_1M*3,
    },  www.2cto.com  
    [2] = {
        .name   = "roorfs",
        .offset = MTDPART_OFS_APPEND,
        .size   = SZ_1M * 100,
    },
    [3] = {
        .name   = "usrfs",
        .offset = MTDPART_OFS_APPEND,
        .size   = MTDPART_SIZ_FULL,
    },
};
struct s3c_nand_mtd_info s5pc100_nand_mtd_part_info = {
    .chip_nr    = 1,
    .mtd_part_nr = ARRAY_SIZE(s5pc100_nand_part),
    .partition  = s5pc100_nand_part,
};
 
static struct resource s5pc100_nand_resource[] = {
    [0] = {
        .start  = 0xE7200000,
        .end    = 0xE7200000 + SZ_1M,
        .flags  = IORESOURCE_MEM,
    },
};
 
struct platform_device s5pc100_device_nand = {
    .name   = "s5pc100-nand",
    .id = -1,
    .num_resources  = ARRAY_SIZE(s5pc100_nand_resource),
    .resource   = s5pc100_nand_resource,
    .dev = {
        .platform_data = &s5pc100_nand_mtd_part_info,
    },
};
#endif
 
添加平台设备列表
在smdkc100_device[]结构体数组中添加如下内容:
#if defined(CONFIG_MTD_NAND_S3C)
    &s5pc100_device_nand,
#endif    www.2cto.com  
修改 arch/arm/plat-samsung/include/plat/nand.h 添加如下内容:
struct s3c_nand_mtd_info {
    uint chip_nr;
    uint mtd_part_nr;
    struct matd_partition *partition;
};
5、 配置内核
$ make menuconfig
修改
 
Device Drivers --->
        <*> Memory Technology Device (MTD) support --->
               [*]   MTD partitioning support
               <*>   Caching block device access to MTD devices
               <*>   NAND Device Support --->
                      <*>   NAND Flash support for S3C SoCs
                      [*]   S3C NAND Hardware ECC
 
File System --->
        Partition Types --->
               [*]   Advanced partitioin selection
               [*]   PC BIOS (MSDOS partition tables) support
               [*]   BSD disklabel (FreeBSD partition tables) support
 
---------------------------------------------------------------------
三、编译内核并拷贝到tftpboot下
$ make zImage  www.2cto.com  
$ cp arch/arm/boot/zImage /tftpboot
---------------------------------------------------------------------
四、测试
启动目标板,查看系统信息:
# cat /proc/mtd
dev:  size  erasesize  name
mtd0: 00100000 00020000 "bootloader"
mtd1: 00300000 00020000 "kernel"
mtd2: 00400000 00020000 "rootfs"
mtd3: 0f800000 00020000 "usrfs"
 
 
作者 lr_ting
相关TAG标签
上一篇:js ide WebStorm 使用总结
下一篇:JAVA中List、Map、Set的区别与选用
相关文章
图文推荐

关于我们 | 联系我们 | 广告服务 | 投资合作 | 版权申明 | 在线帮助 | 网站地图 | 作品发布 | Vip技术培训 | 举报中心

版权所有: 红黑联盟--致力于做实用的IT技术学习网站