mhm, using the image-builder makes it hard fixing this as you cannot change dts-code here.
which exact board do you have? we need to find a way to select the nand size somehow
mhm, using the image-builder makes it hard fixing this as you cannot change dts-code here.
which exact board do you have? we need to find a way to select the nand size somehow
Yes it is the 8G DDR variant with 2 sfp ports.
ok, are you able to compile image yourself?
basicly this part has to be changed in linux:
&spi_nand {
partitions {
compatible = "fixed-partitions";
#address-cells = <1>;
#size-cells = <1>;
...
partition@200000 {
compatible = "linux,ubi";
reg = <0x200000 0xfe00000>;
label = "ubi";
};
};
maybe we can do it via overlay in openwrt, @dangowrt what do you think? as far as i see the mainline dts only defined the bl2 partition, so ubi seems to be added only in openwrt
something like this:
// SPDX-License-Identifier: (GPL-2.0 OR MIT)
/*
* Copyright (C) 2025 MediaTek Inc.
* Author: Frank Wunderlich <[email protected]>
*/
/* This updates NAND size to 256MB on BPI-R4-8G */
/dts-v1/;
/plugin/;
/ {
compatible = "bananapi,bpi-r4", "mediatek,mt7988a";
};
&{/soc/spi@11007000/flash@0/partitions/partition@200000} {
reg = <0x200000 0xfe00000>;
};
I’m happy to update the source and compile, but I would likely need some help. I’ve compiled simple things for my desktop but setting the complier up for NAND is next level.
I’m up for it, but I’d need some resources and likely some message board support. That kind of thing…
What are the risks? I don’t want to brick the device.
imho there are no risks if you select the right board in openwrt, basicly clone openwrt source and install all needed packages in your build-host, the run “make menuconfig” and select the right board (Target System (MediaTek ARM), Subtarget (Filogic 8x0 (MT798x)), Target Profile (Bananapi BPi-R4)). let it compile completely and for quick test modify source and recompile
build_dir/target-aarch64_cortex-a53_musl/linux-mediatek_filogic/linux-6.18.28/arch/arm64/boot/dts/mediatek/mt7988a-bananapi-bpi-r4.dtsi
&spi_nand {
partitions {
compatible = "fixed-partitions";
#address-cells = <1>;
#size-cells = <1>;
partition@0 {
label = "bl2";
reg = <0x0 0x200000>;
read-only;
};
partition@200000 {
label = "ubi";
reg = <0x200000 0x7e00000>; //change this to <0x200000 0xfe00000>;
compatible = "linux,ubi";
If the device tree overlay is enough, my method, which I am using with the vanilla OpenWrt to add extra LEDs and to modify the CPU VRM to always-on (instead of only boot-on) to prevent turning off the power, is working fine without needing anything to recompile.
I simply created a “magic_bootm” variable in UBoot which contains all the required things which I mentioned in the post, then replaced the bootm command with the execution of the “magic_bootm” in the “boot_production”.
Yes yes yes, It worked.
[ 1.185065] spi-nand spi0.0: Winbond SPI NAND was found.
[ 1.190381] spi-nand spi0.0: 256 MiB, block size: 128 KiB, page size: 2048, OOB size: 128
.
.
.
[ 1.903846] ubi0: attached mtd1 (name "ubi", size 254 MiB)
[ 1.909328] ubi0: PEB size: 131072 bytes (128 KiB), LEB size: 126976 bytes
[ 1.916199] ubi0: min./max. I/O unit sizes: 2048/2048, sub-page size 2048
[ 1.922974] ubi0: VID header offset: 2048 (aligned 2048), data offset: 4096
[ 1.929927] ubi0: good PEBs: 2032, bad PEBs: 0, corrupted PEBs: 0
… at 254MB I’m still 2M shy of 256… but no more messages.
FWIW, the “Bad EC magic in block” messages appeared after the first boot, but the next boot went off without a hitch.
Thanks to you Frank, and to @ericwoud… and @czo for your suggestion… and @Xiaomi_ax3600 - I hope you are able to resolve your issue.
@frank-w or whoever. Should I submit an issue with OpenWRT? Be nice to have any future updates work for people with my species of board “out of the box”.
How exactly do you apply the overlay without recompiling the fit/itb? Is it exactly the overlay i’ve posted above?
or do you manually modify dt and use different adresse by hacking into the bootm-chain (like described here)?
fdt set /chosen u-boot,bootconf $bootconf#$bootconf_emmc#$bootconf_extra
only with the reg entry instead of choosen node
Yes first boot has the errors in uboot as initialization of ubi is done in linux later and only next bootup is clean.
The 2m missing are for the bl2 partition,so ubi is 2m less than nand size.
And yes,please make issue on openwrt and link to here for solution…maybe there is another way
I needed to keep it simple so I recompiled everything, not following @czo’s suggestion.
I made your update to build_dir/target-aarch64_cortex-a53_musl/linux-mediatek_filogic/linux-6.18.28/arch/arm64/boot/dts/mediatek/mt7988a-bananapi-bpi-r4.dtsi
… changing [email protected] = <0x200000 0xfe00000>.
Afterwards I flashed the sdcard with the new openwrt-mediatek-filogic-bananapi_bpi-r4-sdcard_8g.img and took it from there.
I hope that answers your question.
ok, but this is only temporary quick&dirty change…when you do a clean build this gets lost…
so now we know that it fixes the issue you have and we need to think about it how to make it right. I try to make a PR with the overlay, but i’m no expert with the openwrt build-system.
added the overlay here:
can you test it please?
you can apply the overlay by setting bootconf_extra=mt7988a-bananapi-bpi-r4-nand in uboot environment
Please erase your nand before and then bootup sd with the overlay active
Happy to test it. I don’t know how though.
I’ve cloned your repo. I see the bootconf_extra parameter in /package/boot/uboot-mediatek/patches/450-add-bpi-r4.patch do I just set that? or is it a command I need to run?
either
setenv bootconf_extra mt7988a-bananapi-bpi-r4-nand
saveenv
Or using fw_setenv in linux
You can also patch the env file in source,but you have to use the right file (sdmmc) or all.
As it happens my system doesn’t have setenv or fw_setenv. NOTE these aren’t advertised in the apt repositories. Consequently I just did export bootconf_extra=mt7988a-bananapi-bpi-r4-nand.
Your repo compiled but I couldn’t see anything about the patch in,
$ make -j1 V=s > makedump && grep -E "bpi-r4-nand" makedump
Anyhow, it doesn’t look like your build worked,
root@OpenWrt:~# dmesg
[ 1.153758] spi-nand spi0.0: Winbond SPI NAND was found.
[ 1.159073] spi-nand spi0.0: 256 MiB, block size: 128 KiB, page size: 2048, OOB size: 128
[ 1.173815] OF: Bad cell count for /soc/spi@11007000/spi_nand@0/partitions
[ 1.180686] OF: Bad cell count for /soc/spi@11007000/spi_nand@0/partitions
[ 2.140401] OF: Bad cell count for /soc/spi@11007000/spi_nand@0/partitions
[ 2.153269] OF: Bad cell count for /soc/spi@11007000/spi_nand@0/partitions
.
.
.
[ 1.286590] ubi0: default fastmap pool size: 50
[ 1.291118] ubi0: default fastmap WL pool size: 25
[ 1.295905] ubi0: attaching mtd1
[ 2.070253] ubi0: scanning is finished
[ 2.083305] ubi0: attached mtd1 (name "ubi", size 126 MiB)
[ 2.088802] ubi0: PEB size: 131072 bytes (128 KiB), LEB size: 126976 bytes
[ 2.095667] ubi0: min./max. I/O unit sizes: 2048/2048, sub-page size 2048
[ 2.102442] ubi0: VID header offset: 2048 (aligned 2048), data offset: 4096
[ 2.109395] ubi0: good PEBs: 1008, bad PEBs: 0, corrupted PEBs: 0
[ 2.115478] ubi0: user volume: 7, internal volumes: 1, max. volumes count: 128
[ 2.122687] ubi0: max/mean erase counter: 2/1, WL threshold: 4096, image sequence number: 0
[ 2.131026] ubi0: available PEBs: 0, total reserved PEBs: 1008, PEBs reserved for bad PEB handling: 40
[ 2.140325] ubi0: background thread "ubi_bgt0d" started, PID 245
root@OpenWrt:~#
But I don’t think my testing skills are up to par.
Happy to take another run at it. If you have any other things you want to try let me know.
Setenv is uboot command,fw_setwnv is from openwrt linux.
You should see the dt overlays applied just before linux starts.
You could dump initramfs.itb with dumpinage -l which overlays are present
$ dumpimage -l bin/targets/mediatek/filogic/openwrt-mediatek-filogic-bananapi_bpi-r4-initramfs-recovery.itb
...
Configuration 5 (mt7988a-bananapi-bpi-r4-nand)
Description: OpenWrt bananapi_bpi-r4 overlay mt7988a-bananapi-bpi-r4-nand
Kernel: unavailable
FDT: fdt-mt7988a-bananapi-bpi-r4-nand
so overlay is there
if your itb also shows this and you have flashed the image, exit the bootmenu and run the setenv command and then the default menuentry (bootmenu shows the menu again). and then post full log as file
I was able to find uboot tools for my distro.
It looks like my compile is missing the crucial overlay.
$ dumpimage -l bin/targets/mediatek/filogic/openwrt-mediatek-filogic-bananapi_bpi-r4-8g-initramfs-recovery.itb
FIT description: ARM64 OpenWrt FIT (Flattened Image Tree)
Created: Tue Oct 21 16:46:13 2025
Image 0 (kernel-1)
Description: ARM64 OpenWrt Linux-6.6.110
Created: Tue Oct 21 16:46:13 2025
.
.
.
Image 5 (fdt-mt7988a-bananapi-bpi-r4-sd)
Description: ARM64 OpenWrt bananapi_bpi-r4-8g device tree overlay mt7988a-bananapi-bpi-r4-sd
Created: Tue Oct 21 16:46:13 2025
Type: Flat Device Tree
Compression: uncompressed
Data Size: 1474 Bytes = 1.44 KiB = 0.00 MiB
Architecture: AArch64
Hash algo: crc32
Hash value: 992dc95a
Hash algo: sha1
Hash value: d8c80e86d46ccac204bdcf81feb9ca2802402042
.
.
.
Configuration 0 (config-mt7988a-bananapi-bpi-r4)
Description: OpenWrt bananapi_bpi-r4-8g
Kernel: kernel-1
Init Ramdisk: initrd-1
FDT: fdt-1
Configuration 1 (mt7988a-bananapi-bpi-r4-emmc)
Description: OpenWrt bananapi_bpi-r4-8g overlay mt7988a-bananapi-bpi-r4-emmc
Kernel: unavailable
FDT: fdt-mt7988a-bananapi-bpi-r4-emmc
Configuration 2 (mt7988a-bananapi-bpi-r4-rtc)
Description: OpenWrt bananapi_bpi-r4-8g overlay mt7988a-bananapi-bpi-r4-rtc
Kernel: unavailable
FDT: fdt-mt7988a-bananapi-bpi-r4-rtc
Configuration 3 (mt7988a-bananapi-bpi-r4-sd)
Description: OpenWrt bananapi_bpi-r4-8g overlay mt7988a-bananapi-bpi-r4-sd
Kernel: unavailable
FDT: fdt-mt7988a-bananapi-bpi-r4-sd
Configuration 4 (mt7988a-bananapi-bpi-r4-wifi-mt7996a)
Description: OpenWrt bananapi_bpi-r4-8g overlay mt7988a-bananapi-bpi-r4-wifi-mt7996a
Kernel: unavailable
FDT: fdt-mt7988a-bananapi-bpi-r4-wifi-mt7996a
Also,
root@OpenWrt:~# dmesg | grep -E 'mtd|nand'
[ 1.170202] spi-nand spi0.0: Winbond SPI NAND was found.
[ 1.175542] spi-nand spi0.0: 256 MiB, block size: 128 KiB, page size: 2048, OOB size: 128
[ 1.556460] OF: Bad cell count for /soc/spi@11007000/spi_nand@0/partitions
[ 1.563336] OF: Bad cell count for /soc/spi@11007000/spi_nand@0/partitions
[ 1.678903] ubi0: attaching mtd1
[ 2.467256] ubi0: attached mtd1 (name "ubi", size 126 MiB)
[ 2.524347] OF: Bad cell count for /soc/spi@11007000/spi_nand@0/partitions
[ 2.537212] OF: Bad cell count for /soc/spi@11007000/spi_nand@0/partitions
Note, I didn’t get any of the original error messages when I booted for whatever reason.
I’m just figuring out what uboot is btw. I will need time to understand the commands I’m running.
Are you sure you checked out my nand tree and cleaned the image before building? Look at buildzine of the files (itb when dumping it).
I did not checkout your nand tree.
Do you mean https://github.com/frank-w/u-boot?
If yes, I cloned the above linked u-boot repo, ran make clean and updated the build.conf file,
$ cat build.conf
uploaduser=$USER
uploadserver=r2
uploaddir=/var/lib/tftp
#board=bpi-r2
#board=bpi-r64
#board=bpi-r2pro
#board=bpi-r3
#board=bpi-r3mini
board=bpi-r4
#board=bpi-r4lite
#board=bpi-r4pro
#device=emmc
device=spi-nand
#device=spi-nor
but ./build.sh fails early on at …
Address in memory to use by default (SYS_LOAD_ADDR) [] (NEW)
I ran menuconfig (without making any changes) just to generate a .config file.
The build still fails as above… all assuming I’m in the right place doing the right things.
That said, even after a successful build I’m not sure how to mix the “nand tree” with an openwrt build. Sorry, my compling knowledge is pretty basic. I want to test this but I’ll need some “hand holding” if you have the time.
We are talking about openwrt…my uboot repo is standalone
Please clone my openwrt repo and switch to the bpi-r4-nand branch
Then make menuconfig,select board and your packages and then make to build
Thanks, I have it now.
fw_setenv bootconf_extra mt7988a-bananapi-bpi-r4-nandroot@OpenWrt:~# dmesg | grep -E 'mtd|nand'
[ 1.180925] spi-nand spi0.0: Winbond SPI NAND was found.
[ 1.186269] spi-nand spi0.0: 256 MiB, block size: 128 KiB, page size: 2048, OOB size: 128
[ 1.294131] ubi0: attaching mtd1
[ 1.686520] ubi0: attached mtd1 (name "ubi", size 126 MiB)
[ 1.956502] FIT: flat_dt sub-image 0x00628000..0x00628112 "fdt-mt7988a-bananapi-bpi-r4-nand" (ARM64 OpenWrt bananapi_bpi-r4 device tree overlay mt7988a-bananapi-bpi-r4-nand)
root@OpenWrt:~# dmesg | grep -E 'nand|mtd'
[ 1.180521] spi-nand spi0.0: Winbond SPI NAND was found.
[ 1.185864] spi-nand spi0.0: 256 MiB, block size: 128 KiB, page size: 2048, OOB size: 128
[ 1.362444] ubi0: attaching mtd1
[ 2.078494] ubi0: attached mtd1 (name "ubi", size 254 MiB)
[ 2.345772] FIT: flat_dt sub-image 0x00628000..0x00628112 "fdt-mt7988a-bananapi-bpi-r4-nand" (ARM64 OpenWrt bananapi_bpi-r4 device tree overlay mt7988a-bananapi-bpi-r4-nand)
That looks like good news to me ![]()
Note, there was a lot of missteps getting here. Just to be clear,
dumpimage -l openwrt-mediatek-filogic-bananapi_bpi-r4-initramfs-recovery.itb 22:47:10
FIT description: ARM64 OpenWrt FIT (Flattened Image Tree)
Created: Sun May 24 11:04:31 2026
Image 0 (kernel-1)
Description: ARM64 OpenWrt Linux-6.18.31
Created: Sun May 24 11:04:31 2026
.
.
.
Image 7 (fdt-mt7988a-bananapi-bpi-r4-nand)
Description: ARM64 OpenWrt bananapi_bpi-r4 device tree overlay mt7988a-bananapi-bpi-r4-nand
Created: Sun May 24 11:04:31 2026
Type: Flat Device Tree
Compression: uncompressed
Data Size: 275 Bytes = 0.27 KiB = 0.00 MiB
Architecture: AArch64
Hash algo: crc32
Hash value: 9fc80998
Hash algo: sha1
Hash value: eafc7c33f378a0770c9d7d6445619c9f7ac357dd
Default Configuration: 'config-mt7988a-bananapi-bpi-r4'
Opah!
Thanks for your help and patience.