歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux編程 >> Linux編程 >> Linux-2.6.35內核移植——Nand flash 驅動的移植

Linux-2.6.35內核移植——Nand flash 驅動的移植

日期:2017/3/1 10:17:32   编辑:Linux編程
Nand flash 是嵌入式系統最常用的外部存儲設備,這裡介紹Nand flash驅動移植的過程。

一、移植環境:

1、 Ubuntu 10.10發行版

2、 u-boot.bin (下載見 http://www.linuxidc.com/Linux/2012-07/64775.htm )

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 到drivers/mtd/nand下

  拷貝 regs-nand.h 到arch/arm/mach-s5pc100/include/mach下

s3c_nand.c 與 regs-nand.h 下載地址

免費下載地址在 http://linux.linuxidc.com/

用戶名與密碼都是www.linuxidc.com

具體下載目錄在 /2012年資料/7月/9日/Linux-2.6.35內核移植——Nand flash 驅動的移植/

2、針對FS_S5PC100平台上的nand flash 設備,修改driver/mtd/nand/nand_base.c

  第2812行

/* 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
    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,
    },
    [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
Copyright © Linux教程網 All Rights Reserved