portal_mtd: set writebufsize so UBI can attach to hyperfile MTD#90
Merged
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
handle_op_mtd_create()insrc/portal/portal_mtd.csetsmtd->size,mtd->erasesize,mtd->writesize, andmtd->oobsize, but leavesmtd->writebufsizeat its zero-initialized value.UBI validates the write-buffer size when attaching a device
(
ubi_attach_mtd_dev()indrivers/mtd/ubi/build.c):max_write_sizemust be>= min_io_size(writesize), a multiple of it, and a power of 2. Withwritebufsize == 0, attach fails immediately:So
ubiattach+mount -t ubifscannot succeed on any portal/hyperfile-backedMTD device, even with correct geometry.
Fix
Set
mtd->writebufsize = req_writesize;(the page/write size), which satisfiesUBI'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 amkfs.ubifs+ubinizeimage. Before: attach failed with the "bad write buffersize 0" error above. After:
ubiattachsucceeds, 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 thegenuine UBIFS → UBI → MTD path.