[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <878qilbes9.fsf@bootlin.com>
Date: Thu, 11 Sep 2025 09:59:34 +0200
From: Miquel Raynal <miquel.raynal@...tlin.com>
To: Cheng Ming Lin <linchengming884@...il.com>
Cc: richard@....at, vigneshr@...com, robh@...nel.org, krzk+dt@...nel.org,
conor+dt@...nel.org, tudor.ambarus@...aro.org,
mmkurbanov@...utedevices.com, Takahiro.Kuwano@...ineon.com,
pratyush@...nel.org, linux-mtd@...ts.infradead.org,
devicetree@...r.kernel.org, linux-kernel@...r.kernel.org,
alvinzhou@...c.com.tw, Cheng Ming Lin <chengminglin@...c.com.tw>
Subject: Re: [PATCH v2 1/3] dt-bindings: mtd: spi-nand: Add
enable-randomizer-otp property
Hi Cheng Ming,
On 11/09/2025 at 15:24:35 +08, Cheng Ming Lin <linchengming884@...il.com> wrote:
> Hi Miquel,
>
> Miquel Raynal <miquel.raynal@...tlin.com> 於 2025年9月10日 週三 下午5:10寫道:
>>
>> Hello Cheng Ming,
>>
>> On 10/09/2025 at 11:02:59 +08, Cheng Ming Lin <linchengming884@...il.com> wrote:
>>
>> > From: Cheng Ming Lin <chengminglin@...c.com.tw>
>> >
>> > Add a new boolean property "enable-randomizer-otp" to enable the
>> > randomizer feature on supported SPI-NAND devices.
>> >
>> > Signed-off-by: Cheng Ming Lin <chengminglin@...c.com.tw>
>> > ---
>> > Documentation/devicetree/bindings/mtd/spi-nand.yaml | 4 ++++
>> > 1 file changed, 4 insertions(+)
>> >
>> > diff --git a/Documentation/devicetree/bindings/mtd/spi-nand.yaml b/Documentation/devicetree/bindings/mtd/spi-nand.yaml
>> > index 77a8727c7..432bc79e9 100644
>> > --- a/Documentation/devicetree/bindings/mtd/spi-nand.yaml
>> > +++ b/Documentation/devicetree/bindings/mtd/spi-nand.yaml
>> > @@ -21,6 +21,10 @@ properties:
>> > description: Encode the chip-select line on the SPI bus
>> > maxItems: 1
>> >
>> > + enable-randomizer-otp:
>>
>> This is a NAND wide feature, so we should probably add a prefix, such as
>> "nand,".
>>
>> Now, what about this "otp" suffix? Many (if not all) chips have a
>> volatile setting for that. About the naming, "otp" often reflects to the
>> OTP area, which is not what you imply here, as you want to insist
>> (rightfully) on the fact that this feature cannot be disabled.
>
> Yes, my intention is that once the randomizer feature is enabled, it
> should not be disabled again.
I believe the motivation behind this choice is incorrect and does not
fit such an OS as Linux. We want to give the system administrator the
choice to select and unselect features as it sees fit. So if there is a
volatile way to enable something, we should go for it and we will pay
the extra penalty of a set_feature() (or whatever) command after each
boot. Making this type of change permanent makes development and
debugging much more painful. There are plenty of configurations that we
refuse to apply with non volatile configurations. In general, stateful
modes are problematic if they are kept after a reboot and we try our
best to avoid them.
Once this feature is enabled, for the lifetime of "a product", it does
not make sense to disable it indeed. And the DT must remain correct, if
it is changed in a non compatible way, that's the administrator
responsibility.
So are there ways to enable this feature in a way that returns to the
default state after a reset?
> You are correct that this bit does not
> belong to the OTP area, but rather to the v2 volatile register. The v2
> volatile register has a default value that can be changed through a
> special OTP configuration register program operation. Regarding the
> "otp" suffix, I will remove it to avoid misunderstanding.
>
>>
>> Also, this is a per-chip configuration, while I would have welcomed a
>> per-partition configuration. I can easily imagine two cases:
>>
>> - The boot ROM, for longevity purposes, expects the first blocks
>> containing the bootloader to be scrambled. However the rest of the
>> system does not really care and disables randomization.
>>
>> - The boot ROM is not capable of de-scrambling, however the rest of the
>> system relies on the (probably) more robust scrambling feature.
>>
>> In both cases a chip wide variable is not relevant.
>
> The scrambling and descrambling are handled by the NAND flash hardware
> itself. Therefore, the boot ROM does not need to support a descrambling
> feature.
>
> In the case of Macronix parts, the randomizer is controlled through a
> configuration register, and once it is enabled it covers the entire chip
> (main and/or spare depending on the randopt bit). There is no hardware
> mechanism to enable it only on certain ranges.
After thinking once again, I am no longer aligned with myself from the
past. This is perhaps too Macronix specific in the end and if it is a
fully transparent feature, then why not.
Are there any ways we can read the raw data (unscrambled) once
scrambling has been enabled? (I mean, without changing the user default
OTP state). Maybe one big difference with the raw NAND world that needs
to be taken into account is that the chip itself always return
unscrambled data, hence we probably do not care much, from a Linux
perspective.
Thanks,
Miquèl
Powered by blists - more mailing lists