2.2 Nand flash驱动移植--分区

注意:

  1. 如果要将所有镜像烧录到开发板的nandflash, 就必须移植nandflash驱动Nand flash驱动的移植
  2. 移植最后一层nandflash特定硬件驱动,驱动一般放在drivers/mtd/nand目录下

  3. 为nand特定硬件驱动提供平台资源,nandflash控制寄存器的基地值,还有一个分区表

作用:
 1. 可以把u-boot、uImage、rootfs烧录到nand flash中去。
    0x0000000-0x00100000    : "u-boot"
    0x0100000-0x00500000    : "kernel-uImage"
    0x0500000-0x01500000    : "myrootfs"
    0x1500000-0x02500000    : "userdata"
    0x2500000-0x40000000    : "rest"

 2. 建立 Flash针对Linux的统一抽象的接口,对于不同的flash设备,比如NAND, OneNAND, NOR, AG-  
    AND,ECC'd NOR用户不用去理会是哪种,对每种的flash的操作都变成一样的
 3. 文件系统与底层Flash存储器进行了隔离。
 4. 无需关注是字符设备或者块设备。
 5. 引入MTD后,驱动工程师直接与MTD原始设备层打交道,利用其提供的接口注册设备和分区

 注意: mtd不适用mmc,sd卡等块设备
1. 添加针对我们平台的Nand flash驱动

   1.1 拷贝nand flash驱动\s3c_nand.c到drivers/mtd/nand下,此文件是基于mtd的s5pv210 
       nandflash的设备驱动层的初始化代码,

   1.2 拷贝regs-nand.h到arch/arm/mach-s5pv210/include/mach下
2. 添加内核配置选项,修改Kconfig的目的就是为了将s3c_nand.c编译进内核。修改   
   drivers/mtd/nand/Kconfig添加如下内容:

   config  MTD_NAND_S3C
        tristate "NAND Flash support for S3C SoC"
        depends on   MTD_NAND && (ARCH_S5PV210)
        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
          Enable the use of the S3C's internal ECC generator when
          using NAND. Early versions 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, then you will
          currently not be able to switch to software, as there is no
          implementation for ECC method used by the S3C

3. 修改drivers/mtd/nand/Makefile添加如下内容:

   obj-$(CONFIG_MTD_NAND_S3C)  +=  s3c_nand.o
4. 修改平台代码,修改arch/arm/mach-s5pv210/mach-smdkv210.c添加如下内容:

   4.1 添加头文件
       #if defined (CONFIG_MTD_NAND_S3C)
           #include <linux/mtd/mtd.h>
           #include <linux/mtd/nand.h>
           #include <linux/mtd/nand_ecc.h>
           #include <linux/mtd/partitions.h>
           #include <plat/nand.h>
       #endif

   4.2 添加分区大小
   #if defined(CONFIG_MTD_NAND_S3C)
       /* Nand Flash Support */
       static struct mtd_partition s5pv210_nand_part[] = {
           [0] ={
                   .name = "myuboot",
                   .offset = 0x0,
                   .size = SZ_1M,  
             },
           [1] ={
                   .name = "kernel",
                   .offset = MTDPART_OFS_APPEND,
                   .size = SZ_1M * 4,  
           },
           [2] ={
                   .name = "rootfs",
                   .offset = MTDPART_OFS_APPEND,
                   .size = SZ_1M * 16,  
           },
           [3] ={
                   .name = "userdata",
                   .offset = MTDPART_OFS_APPEND,
                   .size = SZ_1M * 16,  
           },
           [4] ={
                   .name = "usr spec",
                   .offset = MTDPART_OFS_APPEND,
                   .size = MTDPART_SIZ_FULL,  
           },
        };

    4.3 添加平台的设备
         struct s3c_nand_mtd_info s5pv210_nand_mtd_part_info = {

            .chip_nr = 1,

            .mtd_part_nr = ARRAY_SIZE(s5pv210_nand_part),

            .partition =  s5pv210_nand_part,

         };

         static struct resource s5pv210_nand_resource[] = {

             [0] = {

              .start  = 0xB0E00000,
              .end = 0xB0E00000 + SZ_1M,
              .flags = IORESOURCE_MEM,
             }
         };

         struct platform_device s5pv210_device_nand = {
            .name                  = "s5pv210-nand",
            .id                  = -1,
            .num_resources          = ARRAY_SIZE(s5pv210_nand_resource),
            .resource          = s5pv210_nand_resource,  //nand控制寄存器的地址资源
            .dev = {
                .platform_data = &s5pv210_nand_mtd_part_info,  // 特殊的平台数据,分区表
            }
         };
    #endif
         4.4 添加平台设备列表,在smdkv210_device[]结构体数组中添加如下内容:
             #if defined(CONFIG_MTD_NAND_S3C)
                 &s5pv210_device_nand,
             #endif

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

         4.6 修改include/linux/mtd/partitions.h添加如下内容:
             int add_mtd_partitions(struct mtd_info *, const struct mtd_partition *, int);

         4.7 修改arch/arm/mach-s5pv210/clock.c中的struct clk init_clocks_off[]结构体添加如下代码:
             static struct clk init_clocks_off[] = {
             {
                       ……
                       .ctrlbit = (1 << 0),
                 },{ 
                       .name  = "nandxl",
                       .id  = -1,
                       .parent  = &clk_hclk_psys.clk,
                       .enable  = s5pv210_clk_ip1_ctrl,
                       .ctrlbit = (1 << 24),
                 }, 
             }; 
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 SoC
                     [*]     S3C NAND Hardware EC
               File Systems  --->
                     Partition  Types  --->
                     [*]    Advanced partition selection
                     [*]    PC  BIOS  (MSDOS  partition  tables)  support
                     [*]         BSD  disklabel  (FreeBSD  partition  tables)  support
6. 编译内核并拷贝到tftpboot下
   $ make  zImage
   $ cp  arch/arm/boot/zImage  /tftpboot
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值