* [PATCH 1/2] nvmem: u-boot-env: support specifying the env storage size
@ 2025-07-30 13:17 Shiji Yang
2025-07-30 13:17 ` [PATCH 2/2] dt-bindings: nvmem: add env-size property for u-boot env layout Shiji Yang
0 siblings, 1 reply; 5+ messages in thread
From: Shiji Yang @ 2025-07-30 13:17 UTC (permalink / raw)
To: devicetree, linux-kernel
Cc: Rafał Miłecki, Srinivas Kandagatla, Rob Herring,
Krzysztof Kozlowski, Conor Dooley, Shiji Yang
In the current code, we always assume that the env storage size is
the same as the mtd partition size. U-boot supports customizing the
size of the environment area. If its size is different from the MTD
partition size. This will result in CRC32 verification error. This
patch will introduce a new property env-size to give users a chance
to configure the correct env storage size.
Signed-off-by: Shiji Yang <yangshiji66@outlook.com>
---
drivers/nvmem/u-boot-env.c | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)
diff --git a/drivers/nvmem/u-boot-env.c b/drivers/nvmem/u-boot-env.c
index ced414fc9..ac9858010 100644
--- a/drivers/nvmem/u-boot-env.c
+++ b/drivers/nvmem/u-boot-env.c
@@ -52,6 +52,7 @@ static int u_boot_env_probe(struct platform_device *pdev)
struct device *dev = &pdev->dev;
struct device_node *np = dev->of_node;
struct u_boot_env *priv;
+ u32 env_size;
priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
if (!priv)
@@ -68,7 +69,12 @@ static int u_boot_env_probe(struct platform_device *pdev)
config.dev = dev;
config.priv = priv;
- config.size = priv->mtd->size;
+
+ if (!of_property_read_u32(np, "env-size", &env_size) &&
+ env_size <= priv->mtd->size)
+ config.size = env_size;
+ else
+ config.size = priv->mtd->size;
priv->nvmem = devm_nvmem_register(dev, &config);
if (IS_ERR(priv->nvmem))
--
2.50.0
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH 2/2] dt-bindings: nvmem: add env-size property for u-boot env layout
2025-07-30 13:17 [PATCH 1/2] nvmem: u-boot-env: support specifying the env storage size Shiji Yang
@ 2025-07-30 13:17 ` Shiji Yang
2025-07-30 13:20 ` Krzysztof Kozlowski
2025-07-30 23:52 ` Rob Herring
0 siblings, 2 replies; 5+ messages in thread
From: Shiji Yang @ 2025-07-30 13:17 UTC (permalink / raw)
To: devicetree, linux-kernel
Cc: Rafał Miłecki, Srinivas Kandagatla, Rob Herring,
Krzysztof Kozlowski, Conor Dooley, Shiji Yang
This newly introduced property allows users to declare the size of
the environment storage area.
Signed-off-by: Shiji Yang <yangshiji66@outlook.com>
---
.../devicetree/bindings/nvmem/layouts/u-boot,env.yaml | 7 +++++++
1 file changed, 7 insertions(+)
diff --git a/Documentation/devicetree/bindings/nvmem/layouts/u-boot,env.yaml b/Documentation/devicetree/bindings/nvmem/layouts/u-boot,env.yaml
index 56a8f55d4..e0b65a53e 100644
--- a/Documentation/devicetree/bindings/nvmem/layouts/u-boot,env.yaml
+++ b/Documentation/devicetree/bindings/nvmem/layouts/u-boot,env.yaml
@@ -46,6 +46,12 @@ properties:
type: object
description: Command to use for automatic booting
+ env-size:
+ $ref: /schemas/types.yaml#/definitions/uint32
+ description:
+ Size of the environment storage area in bytes. If this property
+ is not defined, the default size is the partition size.
+
ethaddr:
type: object
description: Ethernet interfaces base MAC address.
@@ -85,6 +91,7 @@ examples:
env: partition@40000 {
compatible = "u-boot,env";
reg = <0x40000 0x10000>;
+ env-size = <0x1000>;
mac: ethaddr {
#nvmem-cell-cells = <1>;
--
2.50.0
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH 2/2] dt-bindings: nvmem: add env-size property for u-boot env layout
2025-07-30 13:17 ` [PATCH 2/2] dt-bindings: nvmem: add env-size property for u-boot env layout Shiji Yang
@ 2025-07-30 13:20 ` Krzysztof Kozlowski
2025-07-30 23:52 ` Rob Herring
1 sibling, 0 replies; 5+ messages in thread
From: Krzysztof Kozlowski @ 2025-07-30 13:20 UTC (permalink / raw)
To: Shiji Yang, devicetree, linux-kernel
Cc: Rafał Miłecki, Srinivas Kandagatla, Rob Herring,
Krzysztof Kozlowski, Conor Dooley
On 30/07/2025 15:17, Shiji Yang wrote:
> This newly introduced property allows users to declare the size of
> the environment storage area.
Bindings come before the user.
Your commit msg should explain WHY you are doing this, not what you did
here. I see from the diff everything what you said above. I don't see
the reason to limit the env size.
Best regards,
Krzysztof
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH 2/2] dt-bindings: nvmem: add env-size property for u-boot env layout
2025-07-30 13:17 ` [PATCH 2/2] dt-bindings: nvmem: add env-size property for u-boot env layout Shiji Yang
2025-07-30 13:20 ` Krzysztof Kozlowski
@ 2025-07-30 23:52 ` Rob Herring
2025-07-31 8:33 ` Alexander Dahl
1 sibling, 1 reply; 5+ messages in thread
From: Rob Herring @ 2025-07-30 23:52 UTC (permalink / raw)
To: Shiji Yang
Cc: devicetree, linux-kernel, Rafał Miłecki,
Srinivas Kandagatla, Krzysztof Kozlowski, Conor Dooley
On Wed, Jul 30, 2025 at 09:17:47PM +0800, Shiji Yang wrote:
> This newly introduced property allows users to declare the size of
> the environment storage area.
Why do you need it to be less than the partition size? They commit msg
needs to explain that.
The partition size for fixed partitions in particular are purely a DT
construct. No reason the partition size can't always be the env size.
> Signed-off-by: Shiji Yang <yangshiji66@outlook.com>
> ---
> .../devicetree/bindings/nvmem/layouts/u-boot,env.yaml | 7 +++++++
> 1 file changed, 7 insertions(+)
>
> diff --git a/Documentation/devicetree/bindings/nvmem/layouts/u-boot,env.yaml b/Documentation/devicetree/bindings/nvmem/layouts/u-boot,env.yaml
> index 56a8f55d4..e0b65a53e 100644
> --- a/Documentation/devicetree/bindings/nvmem/layouts/u-boot,env.yaml
> +++ b/Documentation/devicetree/bindings/nvmem/layouts/u-boot,env.yaml
> @@ -46,6 +46,12 @@ properties:
> type: object
> description: Command to use for automatic booting
>
> + env-size:
> + $ref: /schemas/types.yaml#/definitions/uint32
> + description:
> + Size of the environment storage area in bytes. If this property
> + is not defined, the default size is the partition size.
> +
> ethaddr:
> type: object
> description: Ethernet interfaces base MAC address.
> @@ -85,6 +91,7 @@ examples:
> env: partition@40000 {
> compatible = "u-boot,env";
> reg = <0x40000 0x10000>;
> + env-size = <0x1000>;
>
> mac: ethaddr {
> #nvmem-cell-cells = <1>;
> --
> 2.50.0
>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH 2/2] dt-bindings: nvmem: add env-size property for u-boot env layout
2025-07-30 23:52 ` Rob Herring
@ 2025-07-31 8:33 ` Alexander Dahl
0 siblings, 0 replies; 5+ messages in thread
From: Alexander Dahl @ 2025-07-31 8:33 UTC (permalink / raw)
To: Rob Herring
Cc: Shiji Yang, devicetree, linux-kernel, Rafał Miłecki,
Srinivas Kandagatla, Krzysztof Kozlowski, Conor Dooley
Hei hei,
just hooking in, because it relates to a U-Boot feature I'm using, too.
Am Wed, Jul 30, 2025 at 06:52:14PM -0500 schrieb Rob Herring:
> On Wed, Jul 30, 2025 at 09:17:47PM +0800, Shiji Yang wrote:
> > This newly introduced property allows users to declare the size of
> > the environment storage area.
>
> Why do you need it to be less than the partition size? They commit msg
> needs to explain that.
+1
> The partition size for fixed partitions in particular are purely a DT
> construct. No reason the partition size can't always be the env size.
You can set CONFIG_ENV_RANGE and CONFIG_ENV_SIZE to different values
in U-Boot to allow bad block handling. I have a board here where the
U-Boot env is stored directly in NAND flash. The mtd partition size
is 2 times the nand block size (ENV_RANGE=0x40000) while the env size
is exactly one nand block size (ENV_SIZE=0x20000). So the partition
is 2 blocks, but the env size is only 1 block. This way the first
block can become bad and U-Boot will skip it and use the second block.
This would not be possible if the env would always use the whole
partition. The usable size of the partition would be too small to
keep the env then.
The help text for this is present in U-Boot since 2010, so I guess the
feature is there even longer:
- CONFIG_ENV_RANGE (optional):
Specifies the length of the region in which the environment
can be written. This should be a multiple of the NAND device's
block size. Specifying a range with more erase blocks than
are needed to hold CONFIG_ENV_SIZE allows bad blocks within
the range to be avoided.
HTH & Greets
Alex
>
> > Signed-off-by: Shiji Yang <yangshiji66@outlook.com>
> > ---
> > .../devicetree/bindings/nvmem/layouts/u-boot,env.yaml | 7 +++++++
> > 1 file changed, 7 insertions(+)
> >
> > diff --git a/Documentation/devicetree/bindings/nvmem/layouts/u-boot,env.yaml b/Documentation/devicetree/bindings/nvmem/layouts/u-boot,env.yaml
> > index 56a8f55d4..e0b65a53e 100644
> > --- a/Documentation/devicetree/bindings/nvmem/layouts/u-boot,env.yaml
> > +++ b/Documentation/devicetree/bindings/nvmem/layouts/u-boot,env.yaml
> > @@ -46,6 +46,12 @@ properties:
> > type: object
> > description: Command to use for automatic booting
> >
> > + env-size:
> > + $ref: /schemas/types.yaml#/definitions/uint32
> > + description:
> > + Size of the environment storage area in bytes. If this property
> > + is not defined, the default size is the partition size.
> > +
> > ethaddr:
> > type: object
> > description: Ethernet interfaces base MAC address.
> > @@ -85,6 +91,7 @@ examples:
> > env: partition@40000 {
> > compatible = "u-boot,env";
> > reg = <0x40000 0x10000>;
> > + env-size = <0x1000>;
> >
> > mac: ethaddr {
> > #nvmem-cell-cells = <1>;
> > --
> > 2.50.0
> >
>
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2025-07-31 8:39 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-07-30 13:17 [PATCH 1/2] nvmem: u-boot-env: support specifying the env storage size Shiji Yang
2025-07-30 13:17 ` [PATCH 2/2] dt-bindings: nvmem: add env-size property for u-boot env layout Shiji Yang
2025-07-30 13:20 ` Krzysztof Kozlowski
2025-07-30 23:52 ` Rob Herring
2025-07-31 8:33 ` Alexander Dahl
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).