Ran a couple of tests:
U-boot is not causing the problem. I can enter the U-boot console and reset and NAND still boots fine. I do had the āwrspimnandā variable set, but deleting it with uEnv.txt did not change anything.
Maybe the kernel itself is to blame. This is the log from the first Debian boot:
[ 0.754965] spi-nand spi0.0: Winbond SPI NAND was found.
[ 0.760303] spi-nand spi0.0: 128 MiB, block size: 128 KiB, page size: 2048, OOB size: 64
[ 0.768501] 2 fixed-partitions partitions found on MTD device spi0.0
[ 0.774865] OF: Bad cell count for /soc/spi@11007000/spi_nand@0/partitions
[ 0.781745] OF: Bad cell count for /soc/spi@11007000/spi_nand@0/partitions
[ 0.788911] Creating 2 MTD partitions on "spi0.0":
[ 0.793697] 0x000000000000-0x000000200000 : "bl2"
[ 0.800283] 0x000000200000-0x000008000000 : "ubi"
[ 0.880974] ubi0: attaching mtd1
[ 1.499194] ubi0: scanning is finished
[ 1.529628] ubi0: volume 2 ("rootfs_data") re-sized from 9 to 498 LEBs
[ 1.536560] ubi0: attached mtd1 (name "ubi", size 126 MiB)
[ 1.542047] ubi0: PEB size: 131072 bytes (128 KiB), LEB size: 126976 bytes
[ 1.548910] ubi0: min./max. I/O unit sizes: 2048/2048, sub-page size 2048
[ 1.555683] ubi0: VID header offset: 2048 (aligned 2048), data offset: 4096
[ 1.562631] ubi0: good PEBs: 1007, bad PEBs: 1, corrupted PEBs: 0
[ 1.568712] ubi0: user volume: 3, internal volumes: 1, max. volumes count: 128
[ 1.575919] ubi0: max/mean erase counter: 0/0, WL threshold: 4096, image sequence number: 1697192243
[ 1.585036] ubi0: available PEBs: 0, total reserved PEBs: 1007, PEBs reserved for bad PEB handling: 19
[ 1.594332] ubi0: background thread "ubi_bgt0d" started, PID 855
So itās doing something to the NAND.
And this is the log after a reboot. Clearly some corruption has happened between the first boot and the second boot. If U-boot was to blame the errors should already appear in the first boot.
[ 0.751984] spi-nand spi0.0: Winbond SPI NAND was found.
[ 0.757296] spi-nand spi0.0: 128 MiB, block size: 128 KiB, page size: 2048, OOB size: 64
[ 0.765642] 2 fixed-partitions partitions found on MTD device spi0.0
[ 0.772025] OF: Bad cell count for /soc/spi@11007000/spi_nand@0/partitions
[ 0.778900] OF: Bad cell count for /soc/spi@11007000/spi_nand@0/partitions
[ 0.786052] Creating 2 MTD partitions on "spi0.0":
[ 0.790833] 0x000000000000-0x000000200000 : "bl2"
[ 0.797484] 0x000000200000-0x000008000000 : "ubi"
[ 0.880410] ubi0: attaching mtd1
[ 1.320050] ubi0: fixable bit-flip detected at PEB 533
[ 1.350570] ubi0 warning: ubi_io_read: error -74 (ECC error) while reading 126976 bytes from PEB 533:4096, read only 126976 bytes, retry
[ 1.388231] ubi0 warning: ubi_io_read: error -74 (ECC error) while reading 126976 bytes from PEB 533:4096, read only 126976 bytes, retry
[ 1.425889] ubi0 warning: ubi_io_read: error -74 (ECC error) while reading 126976 bytes from PEB 533:4096, read only 126976 bytes, retry
[ 1.463452] ubi0 error: ubi_io_read: error -74 (ECC error) while reading 126976 bytes from PEB 533:4096, read 126976 bytes
[ 1.474488] CPU: 0 PID: 1 Comm: swapper/0 Not tainted 6.8.0-rc3-next-20240207-bpi-r4-dango #1
[ 1.482999] Hardware name: Banana Pi BPI-R4 (DT)
[ 1.487602] Call trace:
[ 1.490036] dump_backtrace+0x98/0x118
[ 1.493777] show_stack+0x18/0x24
[ 1.497079] dump_stack_lvl+0x48/0x60
[ 1.500732] dump_stack+0x18/0x24
[ 1.504035] ubi_io_read+0x2c4/0x3e8
[ 1.507598] ubi_attach+0xb28/0x13a0
[ 1.511163] ubi_attach_mtd_dev+0x564/0xd84
[ 1.515333] ubi_notify_add+0x80/0xb4
[ 1.518984] add_mtd_device+0x4a0/0x670
[ 1.522811] add_mtd_partitions+0xfc/0x254
[ 1.526895] parse_mtd_partitions+0x2d0/0x590
[ 1.531238] mtd_device_parse_register+0x16c/0x374
[ 1.536017] spinand_probe+0x5ec/0x674
[ 1.539755] spi_mem_probe+0x6c/0xbc
[ 1.543320] spi_probe+0x84/0xe4
[ 1.546538] really_probe+0x184/0x3c8
[ 1.550190] __driver_probe_device+0x7c/0x16c
[ 1.554535] driver_probe_device+0x3c/0x110
[ 1.558707] __device_attach_driver+0xbc/0x158
[ 1.563138] bus_for_each_drv+0x80/0xdc
[ 1.566962] __device_attach+0x9c/0x1ac
[ 1.570786] device_initial_probe+0x14/0x20
[ 1.574957] bus_probe_device+0xac/0xb0
[ 1.578781] device_add+0x5d0/0x7c0
[ 1.582257] __spi_add_device+0x1a4/0x248
[ 1.586254] spi_add_device+0x4c/0x6c
[ 1.589904] of_register_spi_device+0x468/0x734
[ 1.594422] spi_register_controller+0x4f4/0x744
[ 1.599026] devm_spi_register_controller+0x4c/0xa4
[ 1.603892] mtk_spi_probe+0x508/0x698
[ 1.607630] platform_probe+0x68/0xc4
[ 1.611281] really_probe+0x184/0x3c8
[ 1.614932] __driver_probe_device+0x7c/0x16c
[ 1.619278] driver_probe_device+0x3c/0x110
[ 1.623448] __driver_attach+0xf4/0x1fc
[ 1.627271] bus_for_each_dev+0x74/0xd0
[ 1.631094] driver_attach+0x24/0x30
[ 1.634658] bus_add_driver+0x110/0x214
[ 1.638482] driver_register+0x60/0x128
[ 1.642305] __platform_driver_register+0x28/0x34
[ 1.646998] mtk_spi_driver_init+0x1c/0x28
[ 1.651085] do_one_initcall+0x44/0x260
[ 1.654909] kernel_init_freeable+0x200/0x3e4
[ 1.659255] kernel_init+0x20/0x1d4
[ 1.662733] ret_from_fork+0x10/0x20
[ 1.667142] ubi0 warning: ubi_io_read: error -74 (ECC error) while reading 64 bytes from PEB 534:2048, read only 64 bytes, retry
[ 1.679118] ubi0 warning: ubi_io_read: error -74 (ECC error) while reading 64 bytes from PEB 534:2048, read only 64 bytes, retry
[ 1.691090] ubi0 warning: ubi_io_read: error -74 (ECC error) while reading 64 bytes from PEB 534:2048, read only 64 bytes, retry
[ 1.703059] ubi0 error: ubi_io_read: error -74 (ECC error) while reading 64 bytes from PEB 534:2048, read 64 bytes
[ 1.713399] CPU: 0 PID: 1 Comm: swapper/0 Not tainted 6.8.0-rc3-next-20240207-bpi-r4-dango #1
[ 1.721908] Hardware name: Banana Pi BPI-R4 (DT)
[ 1.726510] Call trace:
[ 1.728943] dump_backtrace+0x98/0x118
[ 1.732680] show_stack+0x18/0x24
[ 1.735982] dump_stack_lvl+0x48/0x60
[ 1.739631] dump_stack+0x18/0x24
[ 1.742934] ubi_io_read+0x2c4/0x3e8
[ 1.746497] ubi_io_read_vid_hdr+0x58/0x310
[ 1.750667] ubi_attach+0x4a8/0x13a0
[ 1.754232] ubi_attach_mtd_dev+0x564/0xd84
[ 1.758402] ubi_notify_add+0x80/0xb4
[ 1.762052] add_mtd_device+0x4a0/0x670
[ 1.765876] add_mtd_partitions+0xfc/0x254
[ 1.769959] parse_mtd_partitions+0x2d0/0x590
[ 1.774302] mtd_device_parse_register+0x16c/0x374
[ 1.779082] spinand_probe+0x5ec/0x674
[ 1.782818] spi_mem_probe+0x6c/0xbc
[ 1.786382] spi_probe+0x84/0xe4
[ 1.789599] really_probe+0x184/0x3c8
[ 1.793249] __driver_probe_device+0x7c/0x16c
[ 1.797594] driver_probe_device+0x3c/0x110
[ 1.801765] __device_attach_driver+0xbc/0x158
[ 1.806196] bus_for_each_drv+0x80/0xdc
[ 1.810019] __device_attach+0x9c/0x1ac
[ 1.813842] device_initial_probe+0x14/0x20
[ 1.818013] bus_probe_device+0xac/0xb0
[ 1.821837] device_add+0x5d0/0x7c0
[ 1.825312] __spi_add_device+0x1a4/0x248
[ 1.829309] spi_add_device+0x4c/0x6c
[ 1.832958] of_register_spi_device+0x468/0x734
[ 1.837477] spi_register_controller+0x4f4/0x744
[ 1.842082] devm_spi_register_controller+0x4c/0xa4
[ 1.846947] mtk_spi_probe+0x508/0x698
[ 1.850684] platform_probe+0x68/0xc4
[ 1.854334] really_probe+0x184/0x3c8
[ 1.857985] __driver_probe_device+0x7c/0x16c
[ 1.862329] driver_probe_device+0x3c/0x110
[ 1.866500] __driver_attach+0xf4/0x1fc
[ 1.870323] bus_for_each_dev+0x74/0xd0
[ 1.874147] driver_attach+0x24/0x30
[ 1.877710] bus_add_driver+0x110/0x214
[ 1.881534] driver_register+0x60/0x128
[ 1.885357] __platform_driver_register+0x28/0x34
[ 1.890050] mtk_spi_driver_init+0x1c/0x28
[ 1.894136] do_one_initcall+0x44/0x260
[ 1.897959] kernel_init_freeable+0x200/0x3e4
[ 1.902303] kernel_init+0x20/0x1d4
[ 1.905781] ret_from_fork+0x10/0x20
[ 2.295314] ubi0: scanning is finished
[ 2.303606] ubi0 warning: ubi_io_read: error -74 (ECC error) while reading 22528 bytes from PEB 534:4096, read only 22528 bytes, retry
[ 2.320203] ubi0 warning: ubi_io_read: error -74 (ECC error) while reading 22528 bytes from PEB 534:4096, read only 22528 bytes, retry
[ 2.336812] ubi0 warning: ubi_io_read: error -74 (ECC error) while reading 22528 bytes from PEB 534:4096, read only 22528 bytes, retry
[ 2.353400] ubi0 error: ubi_io_read: error -74 (ECC error) while reading 22528 bytes from PEB 534:4096, read 22528 bytes
[ 2.364260] CPU: 0 PID: 1 Comm: swapper/0 Not tainted 6.8.0-rc3-next-20240207-bpi-r4-dango #1
[ 2.372769] Hardware name: Banana Pi BPI-R4 (DT)
[ 2.377372] Call trace:
[ 2.379805] dump_backtrace+0x98/0x118
[ 2.383543] show_stack+0x18/0x24
[ 2.386846] dump_stack_lvl+0x48/0x60
[ 2.390496] dump_stack+0x18/0x24
[ 2.393799] ubi_io_read+0x2c4/0x3e8
[ 2.397363] ubi_read_volume_table+0x104/0xaa0
[ 2.401794] ubi_attach+0x390/0x13a0
[ 2.405358] ubi_attach_mtd_dev+0x564/0xd84
[ 2.409527] ubi_notify_add+0x80/0xb4
[ 2.413176] add_mtd_device+0x4a0/0x670
[ 2.417001] add_mtd_partitions+0xfc/0x254
[ 2.421085] parse_mtd_partitions+0x2d0/0x590
[ 2.425428] mtd_device_parse_register+0x16c/0x374
[ 2.430207] spinand_probe+0x5ec/0x674
[ 2.433944] spi_mem_probe+0x6c/0xbc
[ 2.437509] spi_probe+0x84/0xe4
[ 2.440726] really_probe+0x184/0x3c8
[ 2.444376] __driver_probe_device+0x7c/0x16c
[ 2.448721] driver_probe_device+0x3c/0x110
[ 2.452892] __device_attach_driver+0xbc/0x158
[ 2.457323] bus_for_each_drv+0x80/0xdc
[ 2.461147] __device_attach+0x9c/0x1ac
[ 2.464970] device_initial_probe+0x14/0x20
[ 2.469141] bus_probe_device+0xac/0xb0
[ 2.472965] device_add+0x5d0/0x7c0
[ 2.476440] __spi_add_device+0x1a4/0x248
[ 2.480437] spi_add_device+0x4c/0x6c
[ 2.484087] of_register_spi_device+0x468/0x734
[ 2.488604] spi_register_controller+0x4f4/0x744
[ 2.493209] devm_spi_register_controller+0x4c/0xa4
[ 2.498073] mtk_spi_probe+0x508/0x698
[ 2.501810] platform_probe+0x68/0xc4
[ 2.505461] really_probe+0x184/0x3c8
[ 2.509111] __driver_probe_device+0x7c/0x16c
[ 2.513455] driver_probe_device+0x3c/0x110
[ 2.517625] __driver_attach+0xf4/0x1fc
[ 2.521449] bus_for_each_dev+0x74/0xd0
[ 2.525272] driver_attach+0x24/0x30
[ 2.528834] bus_add_driver+0x110/0x214
[ 2.532658] driver_register+0x60/0x128
[ 2.536481] __platform_driver_register+0x28/0x34
[ 2.541174] mtk_spi_driver_init+0x1c/0x28
[ 2.545259] do_one_initcall+0x44/0x260
[ 2.549082] kernel_init_freeable+0x200/0x3e4
[ 2.553427] kernel_init+0x20/0x1d4
[ 2.556904] ret_from_fork+0x10/0x20
[ 2.560483] ubi0 error: vtbl_check: bad CRC at record 1: 0x3d80bad4, not 0xe1f998b4
[ 2.568138] Volume table record 1 dump:
[ 2.571965] reserved_pebs 453
[ 2.575179] alignment 1
[ 2.578219] data_pad 0
[ 2.581263] vol_type 1
[ 2.584304] upd_marker 0
[ 2.587344] name_len 6
[ 2.590384] name rootfs
[ 2.593862] crc 0xe1f998b4
[ 2.597684] ubi0 error: ubi_read_volume_table: both volume tables are corrupted
[ 2.605074] ubi0 error: ubi_attach_mtd_dev: failed to attach mtd1, error -22
@frank-w I used you bookworm image ābpi-r4_bookworm_nokernel.imgā as a base with a self-compiled 6.8-dango kernel from your Github-page.