mtd 分区一般采用3种方式实现
1、内核写死 mtd_partition
2、u-boot 传参
为了使kernel能够解析mtdparts信息,我们需要将内核中的Device Drivers -> Memory Technology Device (MTD) support ->Command line partition table parsing选项开启
3、dts 传参
1296的实现方式是u-boot传参
linux 调用 parse_mtd_partitions (注意part_probes参数)和 add_mtd_partitions实现
具体代码如下:linux-4.4.18/drivers/mtd$ vi chips/rtk_sfc.c
static const char * const part_probes[] = { "cmdlinepart", "RedBoot", NULL };
#ifdef CONFIG_MTD_CMDLINE_PARTS
printk("[%s]descriptor size 0x%x\n",__FUNCTION__,(unsigned int)descriptor.size);
nr_parts = parse_mtd_partitions(&descriptor, part_probes, &parts, 0);
#endif
if(nr_parts <= 0) {
printk(KERN_NOTICE "Rtk SFC: using single partition\n");
if(add_mtd_device(&descriptor)) {
printk(KERN_WARNING "Rtk SFC: (for SST/SPANSION/MXIC/WINBOND SPI-Flash) Failed to register new device\n");
return -EAGAIN;
}
}
else {
printk(KERN_NOTICE "Rtk SFC: using dynamic partition\n");
add_mtd_partitions(&descriptor, parts, nr_parts);
}
另外,发现rtd1296会多一个disc分区,原来是他修改了add_mtd_partitions函数,把整个设备作为一个完整的分区添加了。
代码如下:
linux-4.4.18/drivers/mtd$ vi mtdpart.c
add_mtd_partitions函数最后:
//#ifdef CONFIG_MTD_NAND_DISC
#if defined(CONFIG_ARCH_RTD129X) || defined(CONFIG_ARCH_RTD119X)
struct mtd_partition partDISC = {0};
// The name that represents the whole MTD Flash device
partDISC.name = "disc";
partDISC.size = master->size;
partDISC.offset = 0;
slave = allocate_partition(master, &partDISC, nbparts, 0);
if (IS_ERR(slave))
return PTR_ERR(slave);
mutex_lock(&mtd_partitions_mutex);
list_add(&slave->list, &mtd_partitions);
mutex_unlock(&mtd_partitions_mutex);
add_mtd_device(&slave->mtd);
#endif