Skip to content

portal_mtd: set writebufsize so UBI can attach to hyperfile MTD#90

Merged
lacraig2 merged 1 commit into
mainfrom
fix-mtd-ubi-writebufsize
Jul 15, 2026
Merged

portal_mtd: set writebufsize so UBI can attach to hyperfile MTD#90
lacraig2 merged 1 commit into
mainfrom
fix-mtd-ubi-writebufsize

Conversation

@lacraig2

Copy link
Copy Markdown
Contributor

Problem

handle_op_mtd_create() in src/portal/portal_mtd.c sets mtd->size,
mtd->erasesize, mtd->writesize, and mtd->oobsize, but leaves
mtd->writebufsize at its zero-initialized value.

UBI validates the write-buffer size when attaching a device
(ubi_attach_mtd_dev() in drivers/mtd/ubi/build.c): max_write_size must be
>= min_io_size (writesize), a multiple of it, and a power of 2. With
writebufsize == 0, attach fails immediately:

ubi0 error: ubi_attach_mtd_dev: bad write buffer size 0 for 2048 min. I/O unit

So ubiattach + mount -t ubifs cannot succeed on any portal/hyperfile-backed
MTD device, even with correct geometry.

Fix

Set mtd->writebufsize = req_writesize; (the page/write size), which satisfies
UBI's requirement. This lets UBI and UBIFS attach to hyperfile-backed MTD
partitions — needed to model firmware that stores nvram/config on a UBI-mounted
MTD partition.

Testing

Validated end-to-end against a kernel built with CONFIG_MTD_UBI +
CONFIG_UBIFS_FS: a NAND MTD device (128 KiB PEB / 2 KiB page) backed by a
mkfs.ubifs+ubinize image. Before: attach failed with the "bad write buffer
size 0" error above. After: ubiattach succeeds, UBI scans and attaches
(attached mtd0 ... size 16 MiB), and the guest mounts the UBIFS volume
(UBIFS: mounted UBI device 0, volume 0), reading its contents through the
genuine UBIFS → UBI → MTD path.

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.
@lacraig2
lacraig2 merged commit be6dee1 into main Jul 15, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant