linux内核驱动移植手册,Linux3.4内核Nand Flash驱动的移植

【实验目的】

Nand flash 是嵌入式系统常用的内部存储设备,通过移植Nand flash驱动,了解Linux内核Nand Flash的实现。

说明:在本系统移植课程实验中命令行提示符“$”表示是在主机上执行,“#”表示在目标板执行。

【实验环境】

● 主机:Ubuntu 10.10 (64bit);

● 目标机:FS_S5PC100平台;

● 交叉编译工具链:arm-eabi-4.4.0(Android4.0.4自带交叉工具链);

【实验步骤】

1.添加驱动文件

添加针对我们平台的Nand flash驱动。

● 拷贝s3c_nand.c到drivers/mtd/nand下;

● 拷贝regs-nand.h到arch/arm/mach-s5pc100/include/mach下;

cp s3c_nand.c drivers/mtd/nand

cpregs-nand.h arch/arm/mach-s5pc100/include/mach

2.修改文件

针对平台上的nand flash设备,修改drivers/mtd/nand/nand_base.c第2975行。

for (i = 0; i< 5; i++)

3.配置文件修改

● 修改drivers/mtd/nand/Kconfig,在if mtd_nand(216行)下面添加如下内容:

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 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

● 修改drivers/mtd/nand/Makefile添加如下内容(19行):

obj-$(CONFIG_MTD_NAND_S3C) += s3c_nand.o

4.平台代码修改

修改arch/arm/mach-s5pc100/mach-smdkc100.c添加如下内容:

● 添加头文件

1 #if defined (CONFIG_MTD_NAND_S3C)

2 #include

3 #include

4 #include

5 #endif

● 添加平台设备

01 #if defined(CONFIG_MTD_NAND_S3C)

02 /* Nand Flash Support */

03 static struct mtd_partition s5pc100_nand_part[] = {

04        [0] = {

05                .name = "bootloader",

06                .size = SZ_1M,

07                .offset = 0,

08        },

09        [1] = {

10                .name = "kernel",

11                .offset = MTDPART_OFS_APPEND,

12                .size = SZ_1M*3,

13        },

14        [2] = {

15                .name = "rootfs",

16                .offset = MTDPART_OFS_APPEND,

17                .size = MTDPART_SIZ_FULL,

18        },

19 };

20

21 struct s3c_nand_mtd_info s5pc100_nand_mtd_part_info = {

22        .chip_nr = 1,

23        .mtd_part_nr = ARRAY_SIZE(s5pc100_nand_part),

24        .partition = s5pc100_nand_part,

25 };

26

27 static struct resource s5pc100_nand_resource[] = {

28        [0] = {

29                .start = 0xE7200000,

30                .end = 0xE7200000 + SZ_1M,

31                .flags = IORESOURCE_MEM,

32        }

33 };

34

35 struct platform_device s5pc100_device_nand = {

36        .name = "s5pc100-nand",

37        .id = -1,

38        .num_resources = ARRAY_SIZE(s5pc100_nand_resource),

39        .resource = s5pc100_nand_resource,

40        .dev = {

41                .platform_data = &s5pc100_nand_mtd_part_info,

42        }

43 };

44#endif

● 添加平台设备列表

在smdkc100_device[]结构体数组中添加如下内容:

1 #if defined(CONFIG_MTD_NAND_S3C)

2        &s5pc100_device_nand,

3 #endif

5.相关头文件修改

修改arch/arm/plat-samsung/include/plat/nand.h添加如下内容:

1 #if defined(CONFIG_MTD_NAND_S3C)

2 struct s3c_nand_mtd_info {

3        uint chip_nr;

4        uint mtd_part_nr;

5        struct mtd_partition *partition;

6 };

7#endif

6.配置内核

$ make menuconfig

Device Drivers --->

Memory Technology Device (MTD) support --->

Caching block device access to MTD devices

NAND Device Support --->

NAND Flash support for S3C SoC

[*] S3C NAND Hardware ECC

-*- Enable the block layer --->

Partition Types --->

[*] Advanced partition selection

[*] PC BIOS (MSDOS partition tables) support

[*] BSD disklabel (FreeBSD partition tables) support

7.编译内核

编译内核并拷贝到tftpboot下。

$ make zImage

$ cp arch/arm/boot/zImage /tftpboot

8.测试

启动目标板,在目标板上完成如下操作:

# cat /proc/mtd

可以看到之前内核对Nand Flash的分区表。

dev: size erasesize name

mtd0: 00100000 00020000 "bootloader"

mtd1: 00300000 00020000 "kernel"

mtd2: 0fc00000 00020000 "rootfs"

717d26eeac9325132c04517780da6d59.png

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值