大家好,我的板子是AM3352,NAND Flash启动,但是发现在uboot执行saveenv时无法保存环境变量,擦除flash失败,提示:Attempt to erase non block-aligned data ,看了一下源码是在int nand_erase_opts(nand_info_t *meminfo, const nand_erase_options_t *opts)函数时出错,如下:
if ((opts->offset & (meminfo->erasesize – 1)) != 0) {
printf("Attempt to erase non block-aligned data\n");
return -1;
}
打印信息如下:
U-Boot 2016.05-00304-gad06f64-dirty (Aug 18 2017 – 18:57:40 +0800)CPU : AM335X-GP rev 2.1Model: TI AM335x HXDW Watchdog enabledI2C: readyDRAM: 256 MiBNAND: 256 MiBMMC: OMAP SD/MMC: 0, OMAP SD/MMC: 1*** Error – No Valid Environment Area found*** Warning – bad CRC, using default environment<ethaddr> not set. Validating first E-fuse MACNet: Could not get PHY for ethernet@4a100000: addr 0eth0: ethernet@4a100000Warning: usb_ether MAC addresses don't match:Address in SROM is de:ad:be:ef:00:01Address in environment is 84:eb:18:bd:a8:9e, eth1: usb_etherPress SPACE to abort autoboot in 2 secondsuboot:/>saveenvSaving Environment to NAND…Erasing redundant NAND…Attempt to erase non block-aligned dataErasing NAND…Attempt to erase non block-aligned datauboot:/>
分区如下:
uboot:/>mtddevice nand0 <nand.0>, # parts = 10 #: name size offset mask_flags 0: NAND.SPL 0x00020000 0x00000000 0 1: NAND.SPL.backup1 0x00020000 0x00020000 0 2: NAND.SPL.backup2 0x00020000 0x00040000 0 3: NAND.SPL.backup3 0x00020000 0x00060000 0 4: NAND.u-boot-spl-os 0x00040000 0x00080000 0 5: NAND.u-boot 0x00100000 0x000c0000 0 6: NAND.u-boot-env 0x00020000 0x001c0000 0 7: NAND.u-boot-env.backup10x00020000 0x001e0000 0 8: NAND.kernel 0x00800000 0x00200000 0 9: NAND.file-system 0x0f600000 0x00a00000 0active partition: nand0,0 – (NAND.SPL) 0x00020000 @ 0x00000000defaults:mtdids : nand0=nand.0mtdparts: mtdparts=nand.0:128k(NAND.SPL),128k(NAND.SPL.backup1),128k(NAND.SPL.ba
ckup2),128k(NAND.SPL.backup3),256k(NAND.u-boot-spl-os),1m(NAND.u-boot),128k(NAND
.u-boot-env),128k(NAND.u-boot-env.backup1),8m(NAND.kernel),-(NAND.file-system)uboot:/>
Eggsy Pang:
看一下:
https://e2e.ti.com/support/arm/sitara_arm/f/791/p/593562/2183742?tisearch=e2e-sitesearch&keymatch=Attempt to erase non block-aligned data#2183742
Zhihua Zhang:
回复 Eggsy Pang:
Hi,Pang,
我和这篇帖子遇到了同样的问题,但是里面好像没给出解决方案
Zhihua Zhang:
回复 Eggsy Pang:
查了之后发现env_nand.c的如下函数:
static int erase_and_write_env(const struct env_location *location, u_char *env_new){ int ret = 0;
printf("Erasing %s…\n", location->name); if (nand_erase_opts(&nand_info[0], &location->erase_opts)) return 1;
printf("Writing to %s… ", location->name); ret = writeenv(location->erase_opts.offset, env_new); puts(ret ? "FAILED!\n" : "OK\n");
return ret;}
这里的nand_info[0]为空,参数打印了一下发现nand_info[0]的值如下:
name = <NULL>,index=0,size= 0,erasesize=0
但是我直接使用nand erase 0x1c0000 0x20000擦除flash时又能够擦除成功
NAND erase: device 0 offset 0x1c0000, size 0x20000 opts->offset = 1835008,opts->length = 131072,meminfo->erasesize = 131072 Erasing at 0x1c0000 — 100% complete. OK
这是什么原因呢?
这个nand_info是什么时候初始化的呢?
Zhihua Zhang:
回复 Zhihua Zhang:
问题解决了,重新获取一下nandinfo,如下:
nand_info_t *nand;
nand = get_nand_dev_by_index(0);
但是不明白为什么原来的nand_info[0]会没有值!!!!!!!!!!!
Eggsy Pang:
回复 Zhihua Zhang:
在(drivers\mtd\nand\Nand.c),在函数nand_init_chip()里面
HG:
回复 Zhihua Zhang:
板级初始化不正确,nand flash配置错误。
user1746898:
回复 Zhihua Zhang:
遇到同样的问题,看了下源码drivers/mtd/nand/nand.c
#ifndef CONFIG_DM_NAND nand_info_t *get_nand_dev_by_index(int dev) {if (dev < 0 || dev >= CONFIG_SYS_MAX_NAND_DEVICE ||!nand_info[dev].name) {puts("No such device\n");return NULL;}return &nand_info[dev]; } #endif使用这个函数要取消定义宏CONFIG_DM_NAND
uboot配置里面取消宏CONFIG_DM_NAND,环境变量可正常操作,包括SPL和uboot
yongqing wang:
回复 user1746898:
初始化不正确