关于如何在kernel起来之后通过直接dd读写nand flash分区来更新zImage的mtd问题
主要是设置struct mtd_partition中的mask_flags标志位
具体含义为:
1. master MTD flags to mask out for this partition
2. contains flags that have to be masked (removed) from the
master MTD flag set for the corresponding MTD partition.
凡是置1的bit,相应属性将被惕掉,比如设置为MTD_WRITEABLE,那么表示剔出读写,
因此该mtd分区将只有读权限[luther.gliethttp].
static struct platform_driver pxa3xx_nand_driver = {
.driver = {
.name = "pxa3xx-nand",
},
.probe = pxa3xx_nand_probe,
.remove = pxa3xx_nand_remove,
#ifdef CONFIG_PM
.suspend = pxa3xx_nand_suspend,
.resume = pxa3xx_nand_resume,
#endif
};
pxa3xx_nand_probe
==> add_mtd_partitions(mtd, , pdata->parts, pdata->nr_parts);
===> slave->mtd.flags = master->flags & ~parts[i].mask_flags; // 取反mask_flags做掩码操作
其中pdata->parts对应struct mtd_partition结构体
drivers/mtd/mtdblock.c
// 读写mtd的fops
static struct mtd_blktrans_ops mtdblock_tr = {
.name = "mtdblock",
.major = 31,
.part_bits = 0,
.blksize = 512,
.open = mtdblock_open,
.flush = mtdblock_flush,
.release = mtdblock_release,
.readsect = mtdblock_readsect,
.writesect = mtdblock_writesect,
.add_mtd = mtdblock_add_mtd,
.remove_dev = mtdblock_remove_dev,
.owner = THIS_MODULE,
};
struct mtd_partition {
char *name; /* identifier string */
u_int32_t size; /* partition size */
u_int32_t offset; /* offset within the master MTD space */
u_int32_t mask_flags; /* master MTD flags to mask out for this partition */
struct nand_ecclayout *ecclayout; /* out of band layout for this partition (NAND only)*/
struct mtd_info **mtdp; /* pointer to store the MTD object */
};
// 如下即flash分区部分内容
static struct mtd_partition partition_info[] = {
{
name: "Bootloader",
offset: 0,
mask_flags: MTD_WRITEABLE /* force read-only */ 去掉写权限
},{
name: "Kernel",
size: 0x00200000,
mask_flags: MTD_WRITEABLE /* force read-only */ 去掉写权限
},{
name: "Filesystem",
size: 0x05000000, /* only mount 48M fs */
}, {
name: "MassStorage", 这里mask_flags为0,所以具有读写权限
size: 0x0, /* It will be set at probe function */
offset: MTDPART_OFS_APPEND /* Append after fs section */
},
......
};
0x00200000表示2M,即2097152
读mtd分区:dd if=/dev/mtdblock1 of=zImage bs=dd bs=2097152 count=1
写mtd分区:dd if=/gliethttp/zImage of=/dev/mtdblock1
阅读(8207) | 评论(5) | 转发(1) |