Questions about MTD subpartitioning

Miquel Raynal miquel.raynal at bootlin.com
Tue Apr 29 01:51:25 PDT 2025


Hi Roland,

On 24/04/2025 at 14:21:49 GMT, Roland Kovács <roland.kovacs at est.tech> wrote:

> Many thanks for your response Miquel,
>
>> But if you have partitions in you DT, the
>> master device is not kept (for historical reasons).
>
> In our case, we don't have DT as the platform is x86.

To be very transparent, I am not familiar enough with x86 to be helpful
here.

> We are using the bog-standard spi-nor flash driver, the only extra we have is
> an additional driver that reads the predefined regions from the SPI controller,
> and registers them under the MTD master as partitions, some of them with write
> protection.
>
>> But if you need it you may select CONFIG_MTD_PARTITIONED_MASTER.
>
> Enabling the above *does* allow adding more partitions, however one issue I
> see with that is any new partition created will take its flags (including
> MTD_WRITEABLE) from the master device. So if we were to create partitions that
> overlap a predefined partition to emulate subpartitions that way we will have
> writable access over an otherwise read-only marked area.

AFAIU MTD_WRITEABLE is not a protection mechanism. It just tells
userspace if the type of underlying device is writeable, it does not
indicate anything about any type of write protection on top.

> Some partitions do have hardware write protection, but on some we enforce it
> in software, but I can't seem to find a way to do this in userspace.
>
> Is there a way to change write protection that I perhaps missed?

There is a MEMLOCK ioctl, but only a single spi nor manufacturer driver
implements it.

> Unless there's already an option for it would adding support for BLKROSET and
> BLKROGET make sense?

This would be at the block level, I have no objection myself but my
opinion would not be super relevant there, as you would have to involve
block folks in the discussion :)

Cheers,
Miquèl

> Regards,
> Roland
> -------------------------------------------------------------------------------------------------------------------------
> From: Miquel Raynal <miquel.raynal at bootlin.com>
> Sent: 18 April 2025 09:16
> To: Roland Kovács <roland.kovacs at est.tech>
> Cc: linux-mtd at lists.infradead.org <linux-mtd at lists.infradead.org>; Malin Jonsson <malin.jonsson at est.tech>
> Subject: Re: Questions about MTD subpartitioning 
>  
> Hi Roland,
>
> On 17/04/2025 at 12:08:42 GMT, Roland Kovács <roland.kovacs at est.tech> wrote:
>
>> Hi, 
>>
>> I'd like to ask some questions regarding mtdchar device driver.
>> We'd like to add subpartitions to the PDR region of a NOR-flash device from userspace, but we hit a check in the BLKPG
>> ioctl call which prevents subpartitioning.
>> As far as I can tell, this check predates the support for subpartitions in mtdpart.c and I couldn't find information on
>> why this is the case.
>>
>> Is there a particular reason why subpartitions through BLKPG is not allowed? 
>> Or do you have any other recommended way of doing subpartitions from
>> userspace?
>
> In general I do not use subpartitioning from userspace, so I must admit
> this is going to be a blind advise.
>
> Looking at the code I see that partitioning is only allowed on master
> devices, not partitions. But if you have partitions in you DT, the
> master device is not kept (for historical reasons). But if you need it
> you may select CONFIG_MTD_PARTITIONED_MASTER.
>
> If that does not help, please give more details about the command
> attempted, the device identification and geometry as well as the errors
> you get.
>
> Thanks,
> Miquèl



More information about the linux-mtd mailing list