再议 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
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值