原文地址:http://blog.chinaunix.net/uid-26009923-id-4067430.html
一.分区的定义
1. 定义分区信息
在arch/arm/mach-s3c64xx/mach-smdk6410.c中
-
struct mtd_partition ok6410_nand_part[] = {
-
{
-
.name = "Bootloader",
-
.offset = 0,
-
.size = (1 * SZ_1M),
-
.mask_flags = MTD_CAP_NANDFLASH,
-
},
-
{
-
.name = "Kernel",
-
.offset = (1 * SZ_1M),
-
.size = (5*SZ_1M) ,
-
.mask_flags = MTD_CAP_NANDFLASH,
-
},
-
-
{
-
.name = "User",
-
.offset = (6 * SZ_1M),
-
.size = (200*SZ_1M) ,
-
},
-
{
-
.name = "File System",
-
.offset = MTDPART_OFS_APPEND,
-
.size = MTDPART_SIZ_FULL,
-
}
-
};
2.将mtd_partition封装在s3c2410_nand中
在arch/arm/mach-s3c64xx/mach-smdk6410.c中
-
static struct s3c2410_nand_set ok6410_nand_sets[] = {
-
[0] = {
-
.name = "nand",
-
.nr_chips = 1,
-
.nr_partitions = ARRAY_SIZE(ok6410_nand_part),
-
.partitions = ok6410_nand_part,
-
},
-
};
3.将s3c2410_nand封装在s3c2410_platform_nand中
在arch/arm/mach-s3c64xx/mach-smdk6410.c中
-
static struct s3c2410_platform_nand ok6410_nand_info = {
-
.tacls = 25,
-
.twrph0 = 55,
-
.twrph1 = 40,
-
.nr_sets = ARRAY_SIZE(ok6410_nand_sets),
-
.sets = ok6410_nand_sets,
-
};
4. 将定义的分区信息写入到全局变量中
在arch/arm/mach-s3c64xx/mach-smdk6410.c中
-
static void __init smdk6410_machine_init(void)
-
{
-
s3c_nand_set_platdata(&ok6410_nand_info);
-
}
结构体的包含如下:
s3c2410_platform_nand -->
-->
-->sets: s3c2410_nand_set -->
--> mtd_partition
在arch/arm/plat-samsung/dev-nand.c中
-
void __init s3c_nand_set_platdata(struct s3c2410_platform_nand *nand)
-
{
-
struct s3c2410_platform_nand * npd = kmemdup(nand, sizeof(struct s3c2410_platform_nand), GFP_KERNEL);
-
int size = sizeof(struct s3c2410_nand_set) * npd->nr_sets; //nr_sets=1
-
-
struct s3c2410_nand_set *from = npd->sets;
-
struct s3c2410_nand_set *to;
-
-
to = kmemdup(from, size, GFP_KERNEL); //将
-
npd->sets = to;
-
-
for (int i = 0; i < npd->nr_sets; i++) {
-
ret = s3c_nand_copy_set(to);
-
to++;
-
}
-
s3c_device_nand.dev.platform_data = npd;
-
}
这个函数就是把以前定义的东东重新copy了一份给npd,这儿完全没有必要这么做
改成如下,简单明了
-
void __init s3c_nand_set_platdata(struct s3c2410_platform_nand *nand)
-
{
-
s3c_device_nand.dev.platform_data = nand;
-
}
5. 分区信息在驱动中的获取
-
static int s3c_nand_probe(struct platform_device *pdev, enum s3c_cpu_type cpu_type)
-
{
-
struct s3c2410_platform_nand *plat = pdev->dev.platform_data;
-
}
这个地方就可以通过
plat->sets->partitions->offset,
plat->sets->partitions->size,
plat->sets->partitions->name
找到所对应的分区信息
6. 在驱动中的probe函数中添加partition
s3c_nand_probe
--> add_mtd_partitions
-
int add_mtd_partitions(struct mtd_info *master, const struct mtd_partition *parts, int nbparts)
-
{
-
struct mtd_part *slave;
-
uint64_t cur_offset = 0;
-
-
for (i = 0; i < nbparts; i++) {
-
slave = add_one_partition(master, parts + i, i, cur_offset);
-
cur_offset = slave->offset + slave->mtd.size;
-
}
-
return 0;
-
}
阅读(752) | 评论(0) | 转发(0) |