"mtd: command not found"

i searched everywhere, including long minutes of websearches, and i have no idea where the mtd binary should be coming from.

i have a BPI-R4. i have flashed the debian 11 image on an sd card, and i have working a serial console to a working debian.

i want to install OpenWrt into the NAND as per the instructions at Getting Started with BPI-R4 - Banana Pi Wiki.

i’m supposed to:

mtd erase /dev/mtd0

but:

mtd: command not found

any hints?

the mtd-utils package doesn’t contain an mtd binary. it has a flash_erase binary, though. but then the wiki instructs to:

dd if=mtk-bpi-r4-NAND-20231030.img of=/dev/mtdblock0

but the large mtd partition is mtd2, not mtd0?! (wild guess: maybe /dev/mtd0 just serves as a starting point for the write, which silently overflows into the later regions?)

# cat /proc/mtd 
dev:    size   erasesize  name
mtd0: 00100000 00020000 "bl2"
mtd1: 00100000 00020000 "reserved"
mtd2: 07e00000 00020000 "ubi"

mtd-utils also containing tools for flashing

The stock openwrt from the wiki does not use ubi afair,but if the NAND.img is full image you can flash the full nand not only one partition. Partitions on nand/nor are defined by kernel device tree unlike partitiontable on sd/emmc/usb-storage and similar.

Those instructions belong to the “stock” image form SinoVoip – unfortunately SinoVoip/BananaPi also calls that “OpenWrt” despite it being a downstream fork. Calling it BananaWrt or “our inhouse operating system based on OpenWrt” or something like that would make things a lot easier…

tl;dr: The instructions you quote only apply when running SinoVoip’s stock image. They do not apply when running OpenWrt (as in: the free open source software router OS you can download from openwrt.org). This is because SinoVoip’s stock image exposes an MTD device (/dev/mtd0) which covers the whole flash, while OpenWrt always only exposes individual partitions.