再议 NAND READ/WRITE 的功能

老古董一枚,但勇气可嘉。

打算用UBOOT USB/NAND命令来复制一枚板子,有成功的但更多的是失败。原来考虑有NAND READ/WRITE命令,把嵌入式分区搞好,再把ROOTFS放进去就好了。在UBOOT、LINUX、DTB阶段还一切顺利,得意满满,这不就是GHOST吗。

到了ROOTFS,问题就来了。不是无法找到文件,就是文件错误等。而且他还是一个UBI的ROOTFS,无法用虚拟机加挂。

失败了两天,反而心静了,满满看说明书,看文档。终于在优班图虚拟机上裁剪了自己的ROOTFS,放进去好用了,为此要纪念一下。

drivers/mtd/nand/spi/winbond.c:185:2: warning: braces around scalar initializer 185 | SPINAND_INFO("W25N02KV", /* 3.3V */ | ^~~~~~~~~~~~ drivers/mtd/nand/spi/winbond.c:185:2: note: (near initialization for ‘winbond_spinand_table[1].devid’) In file included from drivers/mtd/nand/spi/winbond.c:16: include/linux/mtd/spinand.h:301:3: error: field name not in record or union initializer 301 | .id = (const u8[]){ __VA_ARGS__ }, \ | ^ include/linux/mtd/spinand.h:326:12: note: in definition of macro ‘SPINAND_INFO’ 326 | .devid = __id, \ | ^~~~ drivers/mtd/nand/spi/winbond.c:186:8: note: in expansion of macro ‘SPINAND_ID’ 186 | SPINAND_ID(SPINAND_READID_METHOD_OPCODE_DUMMY, 0xaa, 0x22), | ^~~~~~~~~~ include/linux/mtd/spinand.h:301:3: note: (near initialization for ‘winbond_spinand_table[1].devid’) 301 | .id = (const u8[]){ __VA_ARGS__ }, \ | ^ include/linux/mtd/spinand.h:326:12: note: in definition of macro ‘SPINAND_INFO’ 326 | .devid = __id, \ | ^~~~ drivers/mtd/nand/spi/winbond.c:186:8: note: in expansion of macro ‘SPINAND_ID’ 186 | SPINAND_ID(SPINAND_READID_METHOD_OPCODE_DUMMY, 0xaa, 0x22), | ^~~~~~~~~~ include/linux/mtd/spinand.h:301:9: warning: initialization of ‘u8’ {aka ‘unsigned char’} from ‘const u8 *’ {aka ‘const unsigned char *’} makes integer from pointer without a cast [-Wint-conversion] 301 | .id = (const u8[]){ __VA_ARGS__ }, \ | ^ include/linux/mtd/spinand.h:326:12: note: in definition of macro ‘SPINAND_INFO’ 326 | .devid = __id, \ | ^~~~ drivers/mtd/nand/spi/winbond.c:186:8: note: in expansion of macro ‘SPINAND_ID’ 186 | SPINAND_ID(SPINAND_READID_METHOD_OPCODE_DUMMY, 0xaa, 0x22), | ^~~~~~~~~~ include/linux/mtd/spinand.h:301:9: note: (near initialization for ‘winbond_spinand_table[1].devid’) 301 | .id = (const u8[]){ __VA_ARGS__ }, \ | ^ include/linux/mtd/spinand.h:326:12: note: in definition of macro ‘SPINAND_INFO’ 326 | .devid = __id, \ | ^~~~ drivers/mtd/nand/spi/winbond.c:186:8: note: in expansion of macro ‘SPINAND_ID’ 186 | SPINAND_ID(SPINAND_READID_METHOD_OPCODE_DUMMY, 0xaa, 0x22), | ^~~~~~~~~~ include/linux/mtd/spinand.h:301:9: error: initializer element is not computable at load time 301 | .id = (const u8[]){ __VA_ARGS__ }, \ | ^ include/linux/mtd/spinand.h:326:12: note: in definition of macro ‘SPINAND_INFO’ 326 | .devid = __id, \ | ^~~~ drivers/mtd/nand/spi/winbond.c:186:8: note: in expansion of macro ‘SPINAND_ID’ 186 | SPINAND_ID(SPINAND_READID_METHOD_OPCODE_DUMMY, 0xaa, 0x22), | ^~~~~~~~~~ include/linux/mtd/spinand.h:301:9: note: (near initialization for ‘winbond_spinand_table[1].devid’) 301 | .id = (const u8[]){ __VA_ARGS__ }, \ | ^ include/linux/mtd/spinand.h:326:12: note: in definition of macro ‘SPINAND_INFO’ 326 | .devid = __id, \ | ^~~~ drivers/mtd/nand/spi/winbond.c:186:8: note: in expansion of macro ‘SPINAND_ID’ 186 | SPINAND_ID(SPINAND_READID_METHOD_OPCODE_DUMMY, 0xaa, 0x22), | ^~~~~~~~~~ include/linux/mtd/spinand.h:302:3: error: field name not in record or union initializer 302 | .len = sizeof((u8[]){ __VA_ARGS__ }), \ | ^ include/linux/mtd/spinand.h:326:12: note: in definition of macro ‘SPINAND_INFO’ 326 | .devid = __id, \ | ^~~~ drivers/mtd/nand/spi/winbond.c:186:8: note: in expansion of macro ‘SPINAND_ID’ 186 | SPINAND_ID(SPINAND_READID_METHOD_OPCODE_DUMMY, 0xaa, 0x22), | ^~~~~~~~~~ include/linux/mtd/spinand.h:302:3: note: (near initialization for ‘winbond_spinand_table[1].devid’) 302 | .len = sizeof((u8[]){ __VA_ARGS__ }), \ | ^ include/linux/mtd/spinand.h:326:12: note: in definition of macro ‘SPINAND_INFO’ 326 | .devid = __id, \ | ^~~~ drivers/mtd/nand/spi/winbond.c:186:8: note: in expansion of macro ‘SPINAND_ID’ 186 | SPINAND_ID(SPINAND_READID_METHOD_OPCODE_DUMMY, 0xaa, 0x22), | ^~~~~~~~~~ include/linux/mtd/spinand.h:302:10: warning: excess elements in scalar initializer 302 | .len = sizeof((u8[]){ __VA_ARGS__ }), \ | ^~~~~~ include/linux/mtd/spinand.h:326:12: note: in definition of macro ‘SPINAND_INFO’ 326 | .devid = __id, \ | ^~~~ drivers/mtd/nand/spi/winbond.c:186:8: note: in expansion of macro ‘SPINAND_ID’ 186 | SPINAND_ID(SPINAND_READID_METHOD_OPCODE_DUMMY, 0xaa, 0x22), | ^~~~~~~~~~ include/linux/mtd/spinand.h:302:10: note: (near initialization for ‘winbond_spinand_table[1].devid’) 302 | .len = sizeof((u8[]){ __VA_ARGS__ }), \ | ^~~~~~ include/linux/mtd/spinand.h:326:12: note: in definition of macro ‘SPINAND_INFO’ 326 | .devid = __id, \ | ^~~~ drivers/mtd/nand/spi/winbond.c:186:8: note: in expansion of macro ‘SPINAND_ID’ 186 | SPINAND_ID(SPINAND_READID_METHOD_OPCODE_DUMMY, 0xaa, 0x22), | ^~~~~~~~~~ include/linux/mtd/spinand.h:303:3: error: field name not in record or union initializer 303 | .method = __method, \ | ^ include/linux/mtd/spinand.h:326:12: note: in definition of macro ‘SPINAND_INFO’ 326 | .devid = __id, \ | ^~~~ drivers/mtd/nand/spi/winbond.c:186:8: note: in expansion of macro ‘SPINAND_ID’ 186 | SPINAND_ID(SPINAND_READID_METHOD_OPCODE_DUMMY, 0xaa, 0x22), | ^~~~~~~~~~ include/linux/mtd/spinand.h:303:3: note: (near initialization for ‘winbond_spinand_table[1].devid’) 303 | .method = __method, \ | ^ include/linux/mtd/spinand.h:326:12: note: in definition of macro ‘SPINAND_INFO’ 326 | .devid = __id, \ | ^~~~ drivers/mtd/nand/spi/winbond.c:186:8: note: in expansion of macro ‘SPINAND_ID’ 186 | SPINAND_ID(SPINAND_READID_METHOD_OPCODE_DUMMY, 0xaa, 0x22), | ^~~~~~~~~~ drivers/mtd/nand/spi/winbond.c:186:19: warning: excess elements in scalar initializer 186 | SPINAND_ID(SPINAND_READID_METHOD_OPCODE_DUMMY, 0xaa, 0x22), | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ include/linux/mtd/spinand.h:326:12: note: in definition of macro ‘SPINAND_INFO’ 326 | .devid = __id, \ | ^~~~ drivers/mtd/nand/spi/winbond.c:186:8: note: in expansion of macro ‘SPINAND_ID’ 186 | SPINAND_ID(SPINAND_READID_METHOD_OPCODE_DUMMY, 0xaa, 0x22), | ^~~~~~~~~~ drivers/mtd/nand/spi/winbond.c:186:19: note: (near initialization for ‘winbond_spinand_table[1].devid’) 186 | SPINAND_ID(SPINAND_READID_METHOD_OPCODE_DUMMY, 0xaa, 0x22), | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ include/linux/mtd/spinand.h:326:12: note: in definition of macro ‘SPINAND_INFO’ 326 | .devid = __id, \ | ^~~~ drivers/mtd/nand/spi/winbond.c:186:8: note: in expansion of macro ‘SPINAND_ID’ 186 | SPINAND_ID(SPINAND_READID_METHOD_OPCODE_DUMMY, 0xaa, 0x22), | ^~~~~~~~~~ CC drivers/net/netfactory/umdk/lsw/source/sal/sal_log.o make[5]: *** [scripts/Makefile.build:257: drivers/mtd/nand/spi/winbond.o] Error 1 make[5]: *** Waiting for unfinished jobs.... 代码: // SPDX-License-Identifier: GPL-2.0 /* * Copyright (c) 2017 exceet electronics GmbH * * Authors: * Frieder Schrempf <frieder.schrempf@exceet.de> * Boris Brezillon <boris.brezillon@bootlin.com> */ #ifndef __UBOOT__ #include <malloc.h> #include <linux/device.h> #include <linux/kernel.h> #endif #include <linux/bitops.h> #include <linux/mtd/spinand.h> #include <linux/bitfield.h> #include <linux/bug.h> #include <linux/delay.h> #define HZ_PER_MHZ 1000000UL #define SPINAND_MFR_WINBOND 0xEF #define WINBOND_CFG_BUF_READ BIT(3) #define W25N04KV_STATUS_ECC_5_8_BITFLIPS (3 << 4) #define W25N0XJW_SR4 0xD0 #define W25N0XJW_SR4_HS BIT(2) #define W35N01JW_VCR_IO_MODE 0x00 #define W35N01JW_VCR_IO_MODE_SINGLE_SDR 0xFF #define W35N01JW_VCR_IO_MODE_OCTAL_SDR 0xDF #define W35N01JW_VCR_IO_MODE_OCTAL_DDR_DS 0xE7 #define W35N01JW_VCR_IO_MODE_OCTAL_DDR 0xC7 #define W35N01JW_VCR_DUMMY_CLOCK_REG 0x01 static SPINAND_OP_VARIANTS(read_cache_variants, SPINAND_PAGE_READ_FROM_CACHE_QUADIO_OP(0, 2, NULL, 0), SPINAND_PAGE_READ_FROM_CACHE_X4_OP(0, 1, NULL, 0), SPINAND_PAGE_READ_FROM_CACHE_DUALIO_OP(0, 1, NULL, 0), SPINAND_PAGE_READ_FROM_CACHE_X2_OP(0, 1, NULL, 0), SPINAND_PAGE_READ_FROM_CACHE_OP(true, 0, 1, NULL, 0), SPINAND_PAGE_READ_FROM_CACHE_OP(false, 0, 1, NULL, 0)); static SPINAND_OP_VARIANTS(write_cache_variants, SPINAND_PROG_LOAD_X4(true, 0, NULL, 0), SPINAND_PROG_LOAD(true, 0, NULL, 0)); static SPINAND_OP_VARIANTS(update_cache_variants, SPINAND_PROG_LOAD_X4(false, 0, NULL, 0), SPINAND_PROG_LOAD(false, 0, NULL, 0)); static int w25m02gv_ooblayout_ecc(struct mtd_info *mtd, int section, struct mtd_oob_region *region) { if (section > 3) return -ERANGE; region->offset = (16 * section) + 8; region->length = 8; return 0; } static int w25m02gv_ooblayout_free(struct mtd_info *mtd, int section, struct mtd_oob_region *region) { if (section > 3) return -ERANGE; region->offset = (16 * section) + 2; region->length = 6; return 0; } static const struct mtd_ooblayout_ops w25m02gv_ooblayout = { .ecc = w25m02gv_ooblayout_ecc, .rfree = w25m02gv_ooblayout_free, }; static int w25m02gv_select_target(struct spinand_device *spinand, unsigned int target) { struct spi_mem_op op = SPI_MEM_OP(SPI_MEM_OP_CMD(0xc2, 1), SPI_MEM_OP_NO_ADDR, SPI_MEM_OP_NO_DUMMY, SPI_MEM_OP_DATA_OUT(1, spinand->scratchbuf, 1)); *spinand->scratchbuf = target; return spi_mem_exec_op(spinand->slave, &op); } static int w25n02kv_ooblayout_ecc(struct mtd_info *mtd, int section, struct mtd_oob_region *region) { if (section > 3) return -ERANGE; region->offset = 64 + (16 * section); region->length = 13; return 0; } static int w25n02kv_ooblayout_free(struct mtd_info *mtd, int section, struct mtd_oob_region *region) { if (section > 3) return -ERANGE; region->offset = (16 * section) + 2; region->length = 14; return 0; } static const struct mtd_ooblayout_ops w25n02kv_ooblayout = { .ecc = w25n02kv_ooblayout_ecc, .rfree = w25n02kv_ooblayout_free, }; static int w25n02kv_ecc_get_status(struct spinand_device *spinand, u8 status) { struct nand_device *nand = spinand_to_nand(spinand); u8 mbf = 0; struct spi_mem_op op = SPINAND_GET_FEATURE_1S_1S_1S_OP(0x30, spinand->scratchbuf); switch (status & STATUS_ECC_MASK) { case STATUS_ECC_NO_BITFLIPS: return 0; case STATUS_ECC_UNCOR_ERROR: return -EBADMSG; case STATUS_ECC_HAS_BITFLIPS: case W25N04KV_STATUS_ECC_5_8_BITFLIPS: /* * Let's try to retrieve the real maximum number of bitflips * in order to avoid forcing the wear-leveling layer to move * data around if it's not necessary. */ if (spi_mem_exec_op(spinand->slave, &op)) return nand->eccreq.strength; mbf = *(spinand->scratchbuf) >> 4; if (WARN_ON(mbf > nand->eccreq.strength || !mbf)) return nand->eccreq.strength; return mbf; default: break; } return -EINVAL; } static const struct spinand_info winbond_spinand_table[] = { SPINAND_INFO("W25M02GV", 0xAB, NAND_MEMORG(1, 2048, 64, 64, 1024, 1, 1, 2), NAND_ECCREQ(1, 512), SPINAND_INFO_OP_VARIANTS(&read_cache_variants, &write_cache_variants, &update_cache_variants), 0, SPINAND_ECCINFO(&w25m02gv_ooblayout, NULL), SPINAND_SELECT_TARGET(w25m02gv_select_target)), /* SPINAND_INFO("W25N01GV", 0xAA, NAND_MEMORG(1, 2048, 64, 64, 1024, 1, 1, 1), NAND_ECCREQ(1, 512), SPINAND_INFO_OP_VARIANTS(&read_cache_variants, &write_cache_variants, &update_cache_variants), 0, SPINAND_ECCINFO(&w25m02gv_ooblayout, NULL)), */ SPINAND_INFO("W25N02KV", /* 3.3V */ SPINAND_ID(SPINAND_READID_METHOD_OPCODE_DUMMY, 0xaa, 0x22), NAND_MEMORG(1, 2048, 128, 64, 2048, 1, 1, 1), NAND_ECCREQ(8, 512), SPINAND_INFO_OP_VARIANTS(&read_cache_variants, &write_cache_variants, &update_cache_variants), 0, SPINAND_ECCINFO(&w25n02kv_ooblayout, w25n02kv_ecc_get_status)), }; static int winbond_spinand_init(struct spinand_device *spinand) { struct nand_device *nand = spinand_to_nand(spinand); unsigned int i; /* * Make sure all dies are in buffer read mode and not continuous read * mode. */ for (i = 0; i < nand->memorg.ntargets; i++) { spinand_select_target(spinand, i); spinand_upd_cfg(spinand, WINBOND_CFG_BUF_READ, WINBOND_CFG_BUF_READ); } return 0; } static const struct spinand_manufacturer_ops winbond_spinand_manuf_ops = { .init = winbond_spinand_init, }; const struct spinand_manufacturer winbond_spinand_manufacturer = { .id = SPINAND_MFR_WINBOND, .name = "Winbond", .chips = winbond_spinand_table, .nchips = ARRAY_SIZE(winbond_spinand_table), .ops = &winbond_spinand_manuf_ops, };
最新发布
11-06
<think> 首先,用户的问题是:“我想获取NAND write的解释 请问NAND write的解释”,这表示他们想要了解“NAND write”的解释。 从系统级指令看,我需要: - 所有行内数学表达式使用$...$格式。 - 独立公式使用$$...$$格式单独成段。 - LaTeX语法正确。 - 使用中文回答。 - 生成相关问题。 - 回答中引用的段落末尾自然地添加引用标识,如[^1]。 - 参考站内引用,但用户提供了引用[1]到[4],我需要尽可能参考用户上一次的问题和我的回答,但这是第一个交互,所以没有历史。 用户提供的引用: - [^1]: 关于VIVADO版本选择问题,涉及NAND write错误。 - [^2]: 介绍nandwrite命令在Linux中的使用,用于向NAND Flash写入数据。 - [^3]: nandwrite命令的参数说明。 - [^4]: 关于在UBOOT中使用NAND READ/WRITE命令的经历。 用户的问题焦点是“NAND write的解释”,所以我应该集中于解释什么是NAND write。 关键点: - NAND write 通常指的是向NAND Flash存储器写入数据的操作。 - 从引用[2]中,nandwrite是Linux中的一个工具,用于写入NAND设备。 - 一般背景:NAND Flash是一种非易失性存储器,常用于嵌入式系统、SD卡、USB驱动器等。 解释NAND write: - NAND write 涉及将数据写入NAND Flash的特定地址。 - 由于NAND Flash的特性,写入操作需要小心处理,比如需要擦除块后才能写入,ECC校验等。 - 在软件层面,命令如nandwrite用于执行此操作。 在回答中,我需要: 1. 使用中文。 2. 结构清晰,逐步解释。 3. 自然地引用提供的参考资料。 4. 生成相关问题。 步骤: 1. 介绍NAND Flash基础。 2. 解释NAND write操作。 3. 提及相关工具或命令,如nandwrite。 4. 引用相关部分来支持解释。 5. 结尾生成相关问题。 数学表达式:用户问题中没有数学内容,但如果有变量等,需要用$...$。例如,地址偏移可能用$x$表示,但保持简洁。 最终回答大纲: - 开头:解释NAND write是什么。 - 主体:详细说明过程、挑战(如ECC、擦除要求)。 - 参考引用:例如,提到引用[2]和[3]中的nandwrite命令。 - 结尾:生成相关问题。 相关问题示例: 1. NAND write操作的常见错误有哪些? 2. 如何优化NAND write性能? 3. NAND Flash在嵌入式系统中的应用场景? </think> ### NAND Write的解释 NAND write是一项针对NAND Flash存储器的数据写入操作。NAND Flash是一种非易失性存储器,广泛应用于嵌入式系统、固态硬盘(SSD)、USB驱动器等设备中,其特点是高密度、低成本,但写入操作比读取更复杂。以下是逐步解释: 1. **NAND Flash的基础特性** NAND Flash由多个擦除块(每个块大小通常为128KB-256KB)组成,每个块又被划分为页(每页大小通常为2KB-4KB)。写入数据时,必须遵循特定规则: - **擦除前写入**:NAND Flash不允许直接覆写数据。在写入新数据前,必须先将目标块擦除为全1状态,然后才能写入(将某些位从1改为0)。这避免了数据冲突,但增加了操作开销。 - **页面级操作**:写入以页为单位进行,一次写入不能超过页的大小(例如,$4 \text{KB}$)。 - **ECC校验**:NAND Flash容易产生位错误,因此写入时通常需要附加ECC(Error-Correcting Code)数据来校验和纠正错误。如果ECC校验失败,可能会导致写入失败或数据损坏[^2][^3]。 2. **NAND write的操作过程** 典型的NAND write操作包括以下步骤: - **指定目标地址**:写入数据到NAND设备的具体偏移位置,例如从地址$x=0\text{x}1000$开始。 - **数据准备**:将输入文件或数据流转换为适合NAND页对齐的模式。如果数据不足一页,可能需要填充(padding)。 - **执行写入**:通过硬件控制器或软件工具将数据写入NAND设备,同时处理OOB(Out-Of-Band)区域(用于存储ECC元数据)。 - **错误处理**:如果写入失败(如因坏块),系统可能会标记坏块或重试操作[^3][^4]。 在软件层面,Linux系统中的`nandwrite`命令是常用工具,属于mtd-utils包。示例命令为: ```bash nandwrite -s 0 /dev/mtd0 firmware.bin ``` 这里: - `-s 0` 表示从地址0开始写入。 - `/dev/mtd0` 是目标NAND设备。 - `firmware.bin` 是输入数据文件。 该命令支持选项如ECC控制(`-n` 禁用ECC)或坏块处理(`-m` 标记坏块)[^2][^3]。 3. **常见挑战与局限性** - **性能瓶颈**:擦除操作耗时(毫秒级),导致写入速度慢于读取。 - **错误代码**:写入失败时可能报错(如`NAND write to offset x failed -12`,表示地址$x$的写入失败),这通常由软件配置错误、坏块或ECC问题引起。例如,在嵌入式开发中,使用不兼容的软件版本(如Vivado 2019.1)可能导致此类错误[^1]。 - **应用场景**:主要用于固件更新、系统修复或嵌入式设备克隆(如在UBOOT中使用NAND READ/WRITE命令进行备份),但需谨慎处理文件系统对齐问题(如UBI根文件系统可能导致失败)[^4]。 总结来说,NAND write是一个低级别的物理写入过程,涉及地址管理、擦除循环和错误校验。在开发中,正确选择工具和版本(如优先使用Linux的nandwrite或稳定IDE版本)可减少错误风险[^1][^2]。 相关问题: 1. NAND write操作中ECC的作用是什么?如何配置? 2. 在嵌入式系统中,如何避免NAND write的常见错误? 3. NAND Flash与NOR Flash在写入操作上有何区别?
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值