zoukankan      html  css  js  c++  java
  • nand驱动移植

    首先下载nand flash驱动 s3c_nand.c ,此文件包含着nand flash驱动具体的实现,将其复制到drivers/mtd/nand下;

     s3c_nand.c 下载地址 s3c_nand.c

    s3c_nand.c中添加nand flash分区信息,分区内容可以自由设定。

    #if defined(CONFIG_ARCH_S5PV210)

    struct mtd_partition s3c_partition_info[] = {

    {

    .name= "misc",

    .offset= (768*SZ_1K),          /* for bootloader */

    .size= (256*SZ_1K),

    .mask_flags= MTD_CAP_NANDFLASH,

    },

    {

    .name= "recovery",

    .offset= MTDPART_OFS_APPEND,

    .size= (5*SZ_1M),

    },

    {

    .name= "kernel",

    .offset= MTDPART_OFS_APPEND,

    .size= (5*SZ_1M),

    },

    {

    .name= "ramdisk",

    .offset= MTDPART_OFS_APPEND,

    .size= (3*SZ_1M),

    },


    {

    .name= "system",

    .offset= MTDPART_OFS_APPEND,

    .size= MTDPART_SIZ_FULL,

    }


    {

    .name= "system",

    .offset= MTDPART_OFS_APPEND,

    .size= (110*SZ_1M),

    },

    {

    .name= "cache",

    .offset= MTDPART_OFS_APPEND,

    .size= (80*SZ_1M),

    },

    {

    .name= "userdata",

    .offset= MTDPART_OFS_APPEND,

    .size= MTDPART_SIZ_FULL,

    }

    #endif

    };


    struct s3c_nand_mtd_info s3c_nand_mtd_part_info = {

    .chip_nr = 1,

    .mtd_part_nr = ARRAY_SIZE(s3c_partition_info),

    .partition = s3c_partition_info,

    };

     

    结构体s3c_nand_mtd_info在源代码是没有的,所以要将其添加进去;

    修改 arch/arm/plat-samsung/include/plat/nand.h 添加如下内容:
    struct s3c_nand_mtd_info {
    uint chip_nr;
    uint mtd_part_nr;
    struct matd_partition *partition;
    };

     

    为了能使s3c_nand.c正确编译,还要修改该目录下,也就是的drivers/mtd/nand的Makefile和Kconfig:

    修改driver/mtd/nand/Kconfig添加如下内容:
    config MTD_NAND_S3C
      tristate "NAND Flash support for S3C Soc"
      depends on ARCH_S5PV210 && 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


     在Mach-smdkv210.c (archarmmach-s5pv210) 中添加nand flash source,platform_device,需要头文件map.h map.h下载,下载将其放在(archarmmach-s5pv210includemach),在Mach-smdkv210.c中加入#include <asm/mach/map.h>。替换掉map.h文件

     

    添加nand flash source

    /* NAND Controller */

    static struct resource s3c_nand_resource[] = {

    [0] = {

    .start= S5PV210_PA_NAND,

    .end= S5PV210_PA_NAND + S5PV210_SZ_NAND - 1,

    .flags= IORESOURCE_MEM,

    }

    };


    struct platform_device s3c_device_nand = {

    .name= "s5pv210-nand",

    .id= -1,

    .num_resources= ARRAY_SIZE(s3c_nand_resource),

    .resource= s3c_nand_resource,

    };

     

    添加platform_device

     找到static struct platform_device *smdkv210_devices[] __initdata

     添加

    #if defined(CONFIG_MTD_NAND_S3C)
    &s3c_device_nand,
    #endif

     

     添加时钟信息

    在Clock.c (archarmmach-s5pv210) 中找到static struct clk init_clocks_off[],添加

    {
      .name  = "nand",
      .id  = -1,
      .parent  = &clk_hclk_psys.clk,
      .enable  = s5pv210_clk_ip1_ctrl,
      .ctrlbit = ((1 << 28) | (1 << 24)),
     },

    添加之后,nand flash驱动才能正确获取时钟。

     

    以上操作完成后,开始配置内核

    根目录下make menuconfig

     

    Device Drivers --->
    <*> Memory Technology Device (MTD) support --->
    <*> Caching block device access to MTD devices
    <*> NAND Device Support --->
    <*> NAND Flash support for S3C SoCs
    [*] S3C NAND Hardware ECC

     

    到了这里,开发板已经支持nand flash驱动。

    接下来

    配置后保存,make clean ,make zImage

    将zImage下载进开发板。从串口信息可以看出nand flash驱动是否完成:

     

    S3C NAND Driver, (c) 2008 Samsung Electronics
    S3C NAND Driver is using hardware ECC.
    NAND device: Manufacturer ID: 0xec, Chip ID: 0xda (Samsung NAND 256MiB 3,3V 8-bit)
    Creating 5 MTD partitions on "s5pv210-nand":
    0x0000000c0000-0x000000100000 : "misc"
    0x000000100000-0x000000600000 : "recovery"
    0x000000600000-0x000000b00000 : "kernel"
    0x000000b00000-0x000000e00000 : "ramdisk"
    0x000000e00000-0x000010000000 : "system"

  • 相关阅读:
    Python 模块,数据类型,元组
    Python条件循环判断
    Python简介
    File对象的基本操作学习
    File对象的基本操作学习
    sublime学习心得
    sublime学习心得
    IO学习
    IO学习
    Emacs学习
  • 原文地址:https://www.cnblogs.com/hei-da-mi/p/4784659.html
Copyright © 2011-2022 走看看