Linux3.4内核Nand Flash驱动的移植
作者:网络转载 发布时间:[ 2014/4/14 9:14:10 ] 推荐标签:Linux Flash 驱动
● 修改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 <linux/mtd/partitions.h>
3 #include <linux/mtd/mtd.h>
4 #include <plat/nand.h>
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"


sales@spasvo.com