[RFC PATCH 1/1] mtd: block2mtd: add support for an optional custom MTD label

Joachim Wiberg troglobit at gmail.com
Wed Sep 29 08:27:20 PDT 2021


Hi Miquel!

On Tue, Sep 28, 2021 at 18:05, Miquel Raynal <miquel.raynal at bootlin.com> wrote:
> Hi Joachim,
> troglobit at gmail.com wrote on Tue, 28 Sep 2021 17:49:38 +0200:
>> This patch adds support for an optional MTD label for mtd2block emulated
>> MTD devices.  Useful when, e.g. testing device images using Qemu.  The
>> following /etc/fstab line in can then be used to mount a file system
>> regardless of the actual MTD partition number:
>> 
>>     mtd:Config  /mnt    jffs2   noatime,nodiratime      0    0
>> 
>> Kernel command line syntax:
>> 
>>     block2mtd.block2mtd=/dev/sda,,Config
>> 
>> The ',,' is the optional erase_size, which like before this patch,
>> defaults to PAGE_SIZE when omitted.
> We already have a label property that can be added in the DT, isn't
> it enough?

Unless I'm missing something, no.  Sorry if if the description was a bit
unclear.  Let me try expanding on it a bit.

The block2mtd driver is used a lot when emulating proper MTDs, I'm sure
we are not alone in building system images that a flashed to an MTD
device, which we want to be able to test in Qemu before deploying.

So what we typically do is have a read-only rootfs (squashfs) on one
partition, and another for config data that uses overlayfs to get a
writable /etc, for instance.  This is a reduced example, and the order
of parititions sometimes differ, so we use parition labels. When we test
in Qemu there's only the automatic DTB from Qemu itself that's injected,
e.g.

  qemu-system-aarch64 -M virt -cpu cortex-a53 -nographic       \
	-kernel Image -initrd rootfs.img -append               \
          "root=/dev/ram block2mtd.block2mtd=/dev/vda"         \
        -drive file=config.img,if=none,format=raw,id=hd0       \
        -device virtio-blk-device,drive=hd0

With the default blockt2mtd args we convert the emulated disk to be
used as an MTD partition, but the name we get in Linux is not the
name we have in our /etc/fstab on a real target.

  # cat /proc/mtd 
  dev:    size   erasesize  name
  mtd0: 00f00000 00001000 "block2mtd: /dev/vda"

With the patch we can align the two cases; the embedded system and the
emulated one, by using the same paritition label.  I.e., with the patch
and the new argument to the kernel cmdline:

  qemu-system-aarch64 -M virt -cpu cortex-a53 -nographic       \
	-kernel Image -initrd rootfs.img -append               \
          "root=/dev/ram block2mtd.block2mtd=/dev/vda,,Config" \
        -drive file=config.img,if=none,format=raw,id=hd0       \
        -device virtio-blk-device,drive=hd0

Linux gives the emulated MTD the same partition name we use in the
real embedded system:

  # cat /proc/mtd 
  dev:    size   erasesize  name
  mtd0: 00f00000 00001000 "Config"


Best regards
 /Joachim



More information about the linux-mtd mailing list