Hi,
I am trying to format and flash the iMX7 Solo custom board having NAND flash with MFGTool.
This is my mtdparts command output.
U-boot> mtdparts
device nand0 <gpmi-nand>, # parts = 5
#: name size offset mask_flags
0: boot 0x04000000 0x00000000 0
1: kernel 0x01000000 0x04000000 0
2: dtb 0x01000000 0x05000000 0
3: initrd 0x00400000 0x06000000 0
4: rootfs 0x79c00000 0x06400000 0
active partition: nand0,0 - (boot) 0x04000000 @ 0x00000000
defaults:
mtdids : nand0=gpmi-nand
mtdparts: mtdparts=gpmi-nand:64m(boot),16m(kernel),16m(dtb),4m(initrd),-(rootfs)
While erasing the rootfs partition using flash_erase command(flash_erase /dev/mtd4 0 0) using MFGTool, some bad blocks are skipped as shown below.
LOG:
flash_erase /dev/mtd4 0 0
Erasing 512 Kibyte @ 79980000 -- 99 % complete flash_erase: Skipping bad block at 79a00000
flash_erase: Skipping bad block at 79a80000
flash_erase: Skipping bad block at 79b00000
flash_erase: Skipping bad block at 79b80000
Erasing 512 Kibyte @ 79b80000 -- 100 % complete
To erase those bad blocks, I added the option -N as per the flash_erase command help (flash_erase -N /dev/mtd4 0 0). But it throws the following error.
LOG:
% nand: nand_erase_nand: attempt to erase a bad block at page 0x0007fe00
Erasing 512 Kibyte @ 78nand: nand_erase_nand: attempt to erase a bad block at page 0x0007fe80
Erasing 512 Kibyte @ 78400000 -- 98 % conand: nand_erase_nand: attempt to erase a bad block at page 0x0007ff00
Erasing 512 Kibyte @ 7848nand: nand_erase_nand: attempt to erase a bad block at page 0x0007ff80
Erasing 512 Kibyte @ 79a00000 -- 99 % complete libmtd: error!: MEMERASE64 ioctl failed for eraseblock 3892 (mtd4)
error 5 (Input/output error)
flash_erase: error!: /dev/mtd4: MTD Erase failure
error 5 (Input/output error)
Erasing 512 Kibyte @ 79a80000 -- 99 % complete libmtd: error!: MEMERASE64 ioctl failed for eraseblock 3893 (mtd4)
error 5 (Input/output error)
flash_erase: error!: /dev/mtd4: MTD Erase failure
error 5 (Input/output error)
Erasing 512 Kibyte @ 79b00000 -- 99 % complete libmtd: error!: MEMERASE64 ioctl failed for eraseblock 3894 (mtd4)
error 5 (Input/output error)
flash_erase: error!: /dev/mtd4: MTD Erase failure
error 5 (Input/output error)
Erasing 512 Kibyte @ 79b80000 -- 99 % complete libmtd: error!: MEMERASE64 ioctl failed for eraseblock 3895 (mtd4)
error 5 (Input/output error)
flash_erase: error!: /dev/mtd4: MTD Erase failure
error 5 (Input/output error)
Erasing 512 Kibyte @ 79b80000 -- 100 % complete
I need to erase those bad blocks also. Because I added UBI command support to my Uboot. While trying to attach with rootfs partition using "ubi part ${partition_name}" command, Attaching fails due to the bad Physical Erase Blocks(PEB) containing the bad image sequence number. The exact error message from U-Boot can be given as follows,
LOG:
scan_peb:bad image sequence number 1583579994 in PEB 3892, expected 220897030
scan_peb:bad image sequence number 1583579994 in PEB 3893, expected 220897030
These Physical Erase Blocks are not correctly erased during MFGTool flashing.
Also another important thing is that, from uboot if we erase the rootfs partition using "U-Boot> nand erase.part rootfs" command and then flashed the images using MFGTool. Now if we try to attach with the given partition using "ubi part ${partition_name}" command there is no issue. And the above the mentioned uboot error didn't appear due to proper erasing of all the PEBs. But the issue occurs if we don't use the "nand erase" command.
Please help me to achieve this clean erase while flashing with MFGTools itself.
Thanks,
Koil Arul Raj S
Hi All,
I could able to fix the UBI partition attaching issue using "ubi part ${partition_name}" command in uboot.
The issue was not due to improper flash as I initially suspected. It was due to U-Boot don't know the information about the bad blocks present in bad block table which is stored in NAND flash. In kernel, the information about bad block table's presence in NAND flash is mentioned in the device tree itself as follows,
&gpmi {
pinctrl-names = "default", "sleep";
pinctrl-0 = <&pinctrl_gpmi_nand_1>;
pinctrl-1 = <&pinctrl_gpmi_nand_1>;
status = "okay";
nand-on-flash-bbt;
};
But by default in uboot it is not configured. So Uboot tried to access the bad blocks and failed to attach with the given partition.
To solve the issue, I added,
1. "#define CONFIG_SYS_NAND_USE_FLASH_BBT" in my board.h file to indicate uboot about bad block table in NAND flash.
2. Added following codes inside "board_nand_init(struct nand_chip *nand)" function present in "/drivers/mtd/nand/mxs_nand.c" file.
#ifdef CONFIG_SYS_NAND_USE_FLASH_BBT
nand->bbt_options |= NAND_BBT_USE_FLASH | NAND_BBT_NO_OOB;
#endif
This helps the uboot to find the bad block table information present in the flash.
Thanks,
Koil Arul Raj S
Hi Koil
thank for sharing your findings. You are right, usually nxp uboot is not used
for operations with nand, so uboot may not properly configured, such operations usually
are performed in linux/mfg tool.
Best regards
igor
Hi,
Is there any update on this issue. Any replies would be highly appreciated.
Thanks,
Koil Arul Raj S
Hi,
After few days of debugging few more inputs to the above stated issue. It may help to understand the issue better.
The log when executing "ubiattach" command in kernel:
--------------------------------------------------------------------------
ubi0: scanning is finished
ubi0: attached mtd4 (name "rootfs", size 1948 MiB)
ubi0: PEB size: 524288 bytes (512 KiB), LEB size: 516096 bytes
ubi0: min./max. I/O unit sizes: 4096/4096, sub-page size 4096
ubi0: VID header offset: 4096 (aligned 4096), data offset: 8192
ubi0: good PEBs: 3892, bad PEBs: 4, corrupted PEBs: 0
ubi0: user volume: 1, internal volumes: 1, max. volumes count: 128
ubi0: max/mean erase counter: 1/0, WL threshold: 4096, image sequence number: 289220316
ubi0: available PEBs: 0, total reserved PEBs: 3892, PEBs reserved for bad PEB handling: 76
ubi0: background thread "ubi_bgt0d" started, PID 115
Here the bad PEBs(in BOLD) found as 4.
The log when executing "ubi part ${partition_name}" command in uboot.
----------------------------------------------------------------------------------------------
The log when executing "ubi part ${partition_name}" command in uboot.
ubi0: attached mtd1 (name "mtd=4", size 1948 MiB)
ubi0: PEB size: 524288 bytes (512 KiB), LEB size: 516096 bytes
ubi0: min./max. I/O unit sizes: 4096/4096, sub-page size 4096
ubi0: VID header offset: 4096 (aligned 4096), data offset: 8192
ubi0: good PEBs: 3896, bad PEBs: 0, corrupted PEBs: 0
ubi0: user volume: 1, internal volumes: 1, max. volumes count: 128
ubi0: max/mean erase counter: 1/0, WL threshold: 4096, image sequence number: 289220316
ubi0: available PEBs: 0, total reserved PEBs: 3896, PEBs reserved for bad PEB handling: 80
Here the bad PEBs(in BOLD) found as 0.
So, whenever the uboot scans or checks for the bad block using bad block table in the NAND flash, it always return there is no bad blocks. This is the reason why "ubi erase.part" command clears the whole rootfs partition. But uboot should find the bad blocks present in the NAND flash right?
I guess Uboot couldn't able to find the bad block table(BBT) generated by kernel. But I am not sure about this process.
These are the configurations I added extra to support UBI command in UBOOT.
/* UBI */
#ifdef CONFIG_CMD_UBI
#define CONFIG_CMD_UBIFS
#define CONFIG_CMD_MTDPARTS
#define CONFIG_RBTREE
#define CONFIG_LZO
#define CONFIG_MTD_DEVICE
#define CONFIG_MTD_PARTITIONS
#define MTDIDS_DEFAULT "nand0=gpmi-nand"
#define MTDPARTS_DEFAULT \
"mtdparts=gpmi-nand:" \
"64m(boot)," \
"16m(kernel)," \
"16m(dtb)," \
"4m(initrd)," \
"-(rootfs)"
#endif
#define CONFIG_SYS_NAND_USE_FLASH_BBT
Is there anything I need to add more? Am I going in right direction?
Kindly help to understand this situation better.
Thanks,
Koil Arul Raj S