From 7ce6cc6ac9288235994b478003aff08ff8e7a5ea Mon Sep 17 00:00:00 2001 From: Luke Craig Date: Tue, 14 Jul 2026 22:38:52 -0400 Subject: [PATCH] portal_mtd: set writebufsize so UBI can attach to hyperfile MTD handle_op_mtd_create() configured size/erasesize/writesize/oobsize but left mtd->writebufsize at 0. UBI's ubi_attach_mtd_dev() (drivers/mtd/ubi/build.c) validates max_write_size and rejects the device with 'bad write buffer size 0 for N min. I/O unit', so ubiattach + mount -t ubifs failed on any portal MTD device. Set writebufsize to the write (page) size, satisfying UBI's >= writesize / multiple / power-of-2 requirement, which lets UBI and UBIFS attach to hyperfile-backed MTD partitions. --- src/portal/portal_mtd.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/portal/portal_mtd.c b/src/portal/portal_mtd.c index fc550a5..f7d4ef8 100644 --- a/src/portal/portal_mtd.c +++ b/src/portal/portal_mtd.c @@ -199,6 +199,17 @@ void handle_op_mtd_create(portal_region *mem_region) mtd->size = req_total_size; mtd->erasesize = req_erasesize; mtd->writesize = req_writesize; + /* + * UBI validates the write-buffer size (max_write_size): it must be + * >= min_io_size (writesize), a multiple of it, and a power of 2 + * (see ubi_attach_mtd_dev() in drivers/mtd/ubi/build.c). We previously + * left writebufsize at 0, so attaching UBI to one of these devices failed + * with "ubi_attach_mtd_dev: bad write buffer size 0 for N min. I/O unit". + * Setting it to the write (page) size lets UBI/UBIFS attach to + * hyperfile-backed MTD partitions, which vendor firmware relies on for + * UBI-mounted nvram/config partitions. + */ + mtd->writebufsize = req_writesize; mtd->oobsize = req->is_nand ? req->oob_size : 0; mtd->owner = THIS_MODULE; mtd->priv = entry;