u-boot-2016.05移植:(7)、使u-boot支持烧写文件系统

u-boot本身支持对jffs2格式文件系统的nand指令操作,但是没有支持yaffs2的格式,所以我们要修改使其支持yaffs2格式文件系统指令操作,在u-boot中搜索.yaffs,并找不到相关代码,所以我们转而搜索.jffs2 ,可以在u-boot-2016.05\cmd\nand.c:do_nand函数中发现相关代码,观察可发现u-boot关于nand的操作指令就是在u-boot-2016.05\cmd\nand.c:do_nand函数中。u-boot-2016.05中并没有像u-boot-2012.04.01一样有yaffs的一套代码,因此部分代码需借鉴u-boot-2012.04.01。
1、在u-boot-2016.05\include\configs\smdk2440.h中添加宏定义:

#define CONFIG_CMD_NAND_YAFFS

2、在u-boot-2016.05\cmd\nand.c:do_nand函数中的

#ifdef CONFIG_CMD_NAND_TRIMFFS
        } else if (!strcmp(s, ".trimffs")) {
            if (read) {
                printf("Unknown nand command suffix '%s'\n", s);
                return 1;
            }
            ret = nand_write_skip_bad(nand, off, &rwsize, NULL,
                        maxsize, (u_char *)addr,
                        WITH_DROP_FFS | WITH_WR_VERIFY);
#endif

之后添加

#ifdef CONFIG_CMD_NAND_YAFFS
        } else if (!strcmp(s, ".yaffs")) {
            if (read) {
                printf("Unknown nand command suffix '%s'.\n", s);
                return 1;
            }
            ret = nand_write_skip_bad(nand, off, &rwsize, NULL,
                        maxsize, (u_char *)addr, 
                        WITH_YAFFS_OOB);
#endif

3、在u-boot-2016.05\include\nand.h中的

#define WITH_WR_VERIFY  (1 << 1) /* verify data was written correctly */

之后添加

#define WITH_YAFFS_OOB  (1 << 0) /* whether write with yaffs format. This flag
                  * is a 'mode' meaning it cannot be mixed with
                  * other flags */

4、在u-boot-2016.05\drivers\mtd\nand\nand_util.c:nand_write_skip_bad函数中用

#ifdef CONFIG_CMD_NAND_YAFFS
        if (flags & WITH_YAFFS_OOB) {
            int page, pages;
            size_t pagesize = nand->writesize;
            size_t pagesize_oob = pagesize + nand->oobsize;
            struct mtd_oob_ops ops;

            ops.len = pagesize;
            ops.ooblen = nand->oobsize;
            ops.mode = MTD_OOB_RAW;
            ops.ooboffs = 0;

            pages = write_size / pagesize_oob;
            for (page = 0; page < pages; page++) {
                WATCHDOG_RESET();

                ops.datbuf = p_buffer;
                ops.oobbuf = ops.datbuf + pagesize;

                rval = nand->_write_oob(nand, offset, &ops);
                if (rval)
                    break;

                offset += pagesize;
                p_buffer += pagesize_oob;
            }
        }
        else
#endif
        {
        truncated_write_size = write_size;
#ifdef CONFIG_CMD_NAND_TRIMFFS
        if (flags & WITH_DROP_FFS)
            truncated_write_size = drop_ffs(nand, p_buffer,
                    &write_size);
#endif

            rval = nand_write(nand, offset, &truncated_write_size,
                    p_buffer);

            if ((flags & WITH_WR_VERIFY) && !rval)
                rval = nand_verify(nand, offset,
                    truncated_write_size, p_buffer);

            offset += write_size;
            p_buffer += write_size;
        }

来替换

        truncated_write_size = write_size;
#ifdef CONFIG_CMD_NAND_TRIMFFS
        if (flags & WITH_DROP_FFS)
            truncated_write_size = drop_ffs(nand, p_buffer,
                    &write_size);
#endif

        rval = nand_write(nand, offset, &truncated_write_size,
                p_buffer);

        if ((flags & WITH_WR_VERIFY) && !rval)
            rval = nand_verify(nand, offset,
                truncated_write_size, p_buffer);

        offset += write_size;
        p_buffer += write_size;

5、在u-boot-2016.05\include\linux\mtd\mtd.h中的

struct mtd_erase_region_info {
    uint64_t offset;        /* At which this region starts, from the beginning of the MTD */
    uint32_t erasesize;     /* For this region */
    uint32_t numblocks;     /* Number of blocks of erasesize in this region */
    unsigned long *lockmap;     /* If keeping bitmap of locks */
};

之后添加

/*
 * oob operation modes
 *
 * MTD_OOB_PLACE:   oob data are placed at the given offset
 * MTD_OOB_AUTO:    oob data are automatically placed at the free areas
 *          which are defined by the ecclayout
 * MTD_OOB_RAW:     mode to read raw data+oob in one chunk. The oob data
 *          is inserted into the data. Thats a raw image of the
 *          flash contents.
 */
typedef enum {
    MTD_OOB_PLACE,
    MTD_OOB_AUTO,
    MTD_OOB_RAW,
} mtd_oob_mode_t;
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值