Linux 烧写文件到Nand Flash

主要是设置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
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值