[PATCH v10 1/2] dt-bindings: mtd: fixed-partitions: Add alignment properties

Add three properties for controlling alignment of partitions, aka 'entries' in fixed-partition.
For now there is no explicit mention of hierarchy, so a 'section' is just the 'fixed-partitions' node.
These new properties are inputs to the Binman packaging process, but are also needed if the firmware is repacked, to ensure that alignment constraints are not violated. Therefore they are provided as part of the schema.
Signed-off-by: Simon Glass sjg@chromium.org Reviewed-by: Rob Herring robh@kernel.org ---
Changes in v10: - Update the minimum to 2
Changes in v9: - Move binding example to next batch to avoid build error
Changes in v7: - Drop patch 'Add binman compatible' - Put the alignment properties into the fixed-partition binding
Changes in v6: - Correct schema-validation errors missed due to older dt-schema (enum fix and reg addition)
Changes in v5: - Add value ranges - Consistently mention alignment must be power-of-2 - Mention that alignment refers to bytes
Changes in v2: - Fix 'a' typo in commit message
.../bindings/mtd/partitions/partition.yaml | 51 +++++++++++++++++++ 1 file changed, 51 insertions(+)
diff --git a/Documentation/devicetree/bindings/mtd/partitions/partition.yaml b/Documentation/devicetree/bindings/mtd/partitions/partition.yaml index 1ebe9e2347ea..656ca3db1762 100644 --- a/Documentation/devicetree/bindings/mtd/partitions/partition.yaml +++ b/Documentation/devicetree/bindings/mtd/partitions/partition.yaml @@ -57,6 +57,57 @@ properties: user space from type: boolean
+ align: + $ref: /schemas/types.yaml#/definitions/uint32 + minimum: 2 + maximum: 0x80000000 + multipleOf: 2 + description: + This sets the alignment of the entry in bytes. + + The entry offset is adjusted so that the entry starts on an aligned + boundary within the containing section or image. For example ‘align = + <16>’ means that the entry will start on a 16-byte boundary. This may + mean that padding is added before the entry. The padding is part of + the containing section but is not included in the entry, meaning that + an empty space may be created before the entry starts. Alignment + must be a power of 2. If ‘align’ is not provided, no alignment is + performed. + + align-size: + $ref: /schemas/types.yaml#/definitions/uint32 + minimum: 2 + maximum: 0x80000000 + multipleOf: 2 + description: + This sets the alignment of the entry size in bytes. It must be a power + of 2. + + For example, to ensure that the size of an entry is a multiple of 64 + bytes, set this to 64. While this does not affect the contents of the + entry within binman itself (the padding is performed only when its + parent section is assembled), the end result is that the entry ends + with the padding bytes, so may grow. If ‘align-size’ is not provided, + no alignment is performed. + + align-end: + $ref: /schemas/types.yaml#/definitions/uint32 + minimum: 2 + maximum: 0x80000000 + multipleOf: 2 + description: + This sets the alignment (in bytes) of the end of an entry with respect + to the containing section. It must be a power of 2. + + Some entries require that they end on an alignment boundary, + regardless of where they start. This does not move the start of the + entry, so the contents of the entry will still start at the beginning. + But there may be padding at the end. While this does not affect the + contents of the entry within binman itself (the padding is performed + only when its parent section is assembled), the end result is that the + entry ends with the padding bytes, so may grow. If ‘align-end’ is not + provided, no alignment is performed. + if: not: required: [ reg ]

Add two compatibles for binman entries, as a starting point for the schema.
Note that, after discussion on v2, we decided to keep the existing meaning of label so as not to require changes to existing userspace software when moving to use binman nodes to specify the firmware layout.
Note also that, after discussion on v6, we decided to use the same 'fixed-partition' schema for the binman features, so this version adds a new 'binman.yaml' file providing the new compatibles to the existing partition.yaml binding.
Signed-off-by: Simon Glass sjg@chromium.org ---
Changes in v10: - Drop binman,entry since it is likely not necessary - Put the description back
Changes in v8: - Switch the patch ordering so the partition change comes first
Changes in v7: - Adjust MAINTAINERS entry - Put compatible strings into the 'fixed-partition' binding
Changes in v5: - Add mention of why 'binman' is the vendor - Drop 'select: false' - Tidy up the compatible setings - Use 'tfa-bl31' instead of 'atf-bl31'
Changes in v4: - Correct selection of multiple compatible strings
Changes in v3: - Drop fixed-partitions from the example - Use compatible instead of label
Changes in v2: - Use plain partition@xxx for the node name
.../bindings/mtd/partitions/binman.yaml | 53 +++++++++++++++++++ .../bindings/mtd/partitions/partition.yaml | 21 ++++++++ MAINTAINERS | 5 ++ 3 files changed, 79 insertions(+) create mode 100644 Documentation/devicetree/bindings/mtd/partitions/binman.yaml
diff --git a/Documentation/devicetree/bindings/mtd/partitions/binman.yaml b/Documentation/devicetree/bindings/mtd/partitions/binman.yaml new file mode 100644 index 000000000000..bb4b08546184 --- /dev/null +++ b/Documentation/devicetree/bindings/mtd/partitions/binman.yaml @@ -0,0 +1,53 @@ +# SPDX-License-Identifier: GPL-2.0-only OR BSD-2-Clause +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/mtd/partitions/binman.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Binman entries + +description: | + This corresponds to a binman 'entry'. It is a single partition which holds + data of a defined type. + + Binman uses the type to indicate what data file / type to place in the + partition. There are quite a number of binman-specific entry types, such as + section, fill and files, to be added later. + +maintainers: + - Simon Glass sjg@chromium.org + +allOf: + - $ref: /schemas/mtd/partitions/partition.yaml# + +properties: + compatible: + enum: + - u-boot # u-boot.bin from U-Boot project + - tfa-bl31 # bl31.bin or bl31.elf from TF-A project + +required: + - compatible + +unevaluatedProperties: false + +examples: + - | + partitions { + compatible = "fixed-partitions"; + #address-cells = <1>; + #size-cells = <1>; + + partition@100000 { + compatible = "u-boot"; + reg = <0x100000 0xf00000>; + align-size = <0x1000>; + align-end = <0x10000>; + }; + + partition@200000 { + compatible = "tfa-bl31"; + reg = <0x200000 0x100000>; + align = <0x4000>; + }; + }; diff --git a/Documentation/devicetree/bindings/mtd/partitions/partition.yaml b/Documentation/devicetree/bindings/mtd/partitions/partition.yaml index 656ca3db1762..bb3c326c6588 100644 --- a/Documentation/devicetree/bindings/mtd/partitions/partition.yaml +++ b/Documentation/devicetree/bindings/mtd/partitions/partition.yaml @@ -118,3 +118,24 @@ then:
# This is a generic file other binding inherit from and extend additionalProperties: true + +examples: + - | + partitions { + compatible = "fixed-partitions"; + #address-cells = <1>; + #size-cells = <1>; + + partition@100000 { + compatible = "u-boot"; + reg = <0x100000 0xf00000>; + align-size = <0x1000>; + align-end = <0x10000>; + }; + + partition@200000 { + compatible = "tfa-bl31"; + reg = <0x200000 0x100000>; + align = <0x4000>; + }; + }; diff --git a/MAINTAINERS b/MAINTAINERS index a848d6ca67e4..1eeb6ebde21f 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -3639,6 +3639,11 @@ F: Documentation/filesystems/bfs.rst F: fs/bfs/ F: include/uapi/linux/bfs_fs.h
+BINMAN +M: Simon Glass sjg@chromium.org +S: Supported +F: Documentation/devicetree/bindings/mtd/partitions/binman* + BITMAP API M: Yury Norov yury.norov@gmail.com R: Rasmus Villemoes linux@rasmusvillemoes.dk

On Tue, 26 Mar 2024 14:06:45 -0600, Simon Glass wrote:
Add two compatibles for binman entries, as a starting point for the schema.
Note that, after discussion on v2, we decided to keep the existing meaning of label so as not to require changes to existing userspace software when moving to use binman nodes to specify the firmware layout.
Note also that, after discussion on v6, we decided to use the same 'fixed-partition' schema for the binman features, so this version adds a new 'binman.yaml' file providing the new compatibles to the existing partition.yaml binding.
Signed-off-by: Simon Glass sjg@chromium.org
Changes in v10:
- Drop binman,entry since it is likely not necessary
- Put the description back
Changes in v8:
- Switch the patch ordering so the partition change comes first
Changes in v7:
- Adjust MAINTAINERS entry
- Put compatible strings into the 'fixed-partition' binding
Changes in v5:
- Add mention of why 'binman' is the vendor
- Drop 'select: false'
- Tidy up the compatible setings
- Use 'tfa-bl31' instead of 'atf-bl31'
Changes in v4:
- Correct selection of multiple compatible strings
Changes in v3:
- Drop fixed-partitions from the example
- Use compatible instead of label
Changes in v2:
- Use plain partition@xxx for the node name
.../bindings/mtd/partitions/binman.yaml | 53 +++++++++++++++++++ .../bindings/mtd/partitions/partition.yaml | 21 ++++++++ MAINTAINERS | 5 ++ 3 files changed, 79 insertions(+) create mode 100644 Documentation/devicetree/bindings/mtd/partitions/binman.yaml
Reviewed-by: Rob Herring robh@kernel.org

Hi Simon,
sjg@chromium.org wrote on Tue, 26 Mar 2024 14:06:44 -0600:
Add three properties for controlling alignment of partitions, aka 'entries' in fixed-partition.
For now there is no explicit mention of hierarchy, so a 'section' is just the 'fixed-partitions' node.
These new properties are inputs to the Binman packaging process, but are also needed if the firmware is repacked, to ensure that alignment constraints are not violated. Therefore they are provided as part of the schema.
Signed-off-by: Simon Glass sjg@chromium.org Reviewed-by: Rob Herring robh@kernel.org
Changes in v10:
- Update the minimum to 2
Changes in v9:
- Move binding example to next batch to avoid build error
Changes in v7:
- Drop patch 'Add binman compatible'
- Put the alignment properties into the fixed-partition binding
Changes in v6:
- Correct schema-validation errors missed due to older dt-schema (enum fix and reg addition)
Changes in v5:
- Add value ranges
- Consistently mention alignment must be power-of-2
- Mention that alignment refers to bytes
Changes in v2:
- Fix 'a' typo in commit message
.../bindings/mtd/partitions/partition.yaml | 51 +++++++++++++++++++ 1 file changed, 51 insertions(+)
diff --git a/Documentation/devicetree/bindings/mtd/partitions/partition.yaml b/Documentation/devicetree/bindings/mtd/partitions/partition.yaml index 1ebe9e2347ea..656ca3db1762 100644 --- a/Documentation/devicetree/bindings/mtd/partitions/partition.yaml +++ b/Documentation/devicetree/bindings/mtd/partitions/partition.yaml @@ -57,6 +57,57 @@ properties: user space from type: boolean
- align:
- $ref: /schemas/types.yaml#/definitions/uint32
- minimum: 2
- maximum: 0x80000000
- multipleOf: 2
- description:
This sets the alignment of the entry in bytes.
The entry offset is adjusted so that the entry starts on an aligned
boundary within the containing section or image. For example ‘align =
<16>’ means that the entry will start on a 16-byte boundary. This may
mean that padding is added before the entry. The padding is part of
the containing section but is not included in the entry, meaning that
an empty space may be created before the entry starts. Alignment
must be a power of 2. If ‘align’ is not provided, no alignment is
performed.
- align-size:
- $ref: /schemas/types.yaml#/definitions/uint32
- minimum: 2
- maximum: 0x80000000
- multipleOf: 2
- description:
This sets the alignment of the entry size in bytes. It must be a power
of 2.
For example, to ensure that the size of an entry is a multiple of 64
bytes, set this to 64. While this does not affect the contents of the
entry within binman itself (the padding is performed only when its
parent section is assembled), the end result is that the entry ends
with the padding bytes, so may grow. If ‘align-size’ is not provided,
no alignment is performed.
I don't think we should mention binman here. Can we have a software agnostic description? This should be understandable from anyone playing with mtd partitions I guess.
- align-end:
- $ref: /schemas/types.yaml#/definitions/uint32
- minimum: 2
- maximum: 0x80000000
- multipleOf: 2
seems not to perfectly match the constraint, but I don't know if there is a powerOf keyword? (same above)
- description:
This sets the alignment (in bytes) of the end of an entry with respect
to the containing section. It must be a power of 2.
Some entries require that they end on an alignment boundary,
regardless of where they start. This does not move the start of the
entry, so the contents of the entry will still start at the beginning.
But there may be padding at the end. While this does not affect the
contents of the entry within binman itself (the padding is performed
content? same comment about binman?
only when its parent section is assembled), the end result is that the
entry ends with the padding bytes, so may grow. If ‘align-end’ is not
provided, no alignment is performed.
if: not: required: [ reg ]
Thanks, Miquèl

Hi Miquel,
On Mon, 8 Apr 2024 at 07:11, Miquel Raynal miquel.raynal@bootlin.com wrote:
Hi Simon,
sjg@chromium.org wrote on Tue, 26 Mar 2024 14:06:44 -0600:
Add three properties for controlling alignment of partitions, aka 'entries' in fixed-partition.
For now there is no explicit mention of hierarchy, so a 'section' is just the 'fixed-partitions' node.
These new properties are inputs to the Binman packaging process, but are also needed if the firmware is repacked, to ensure that alignment constraints are not violated. Therefore they are provided as part of the schema.
Signed-off-by: Simon Glass sjg@chromium.org Reviewed-by: Rob Herring robh@kernel.org
Changes in v10:
- Update the minimum to 2
Changes in v9:
- Move binding example to next batch to avoid build error
Changes in v7:
- Drop patch 'Add binman compatible'
- Put the alignment properties into the fixed-partition binding
Changes in v6:
- Correct schema-validation errors missed due to older dt-schema (enum fix and reg addition)
Changes in v5:
- Add value ranges
- Consistently mention alignment must be power-of-2
- Mention that alignment refers to bytes
Changes in v2:
- Fix 'a' typo in commit message
.../bindings/mtd/partitions/partition.yaml | 51 +++++++++++++++++++ 1 file changed, 51 insertions(+)
diff --git a/Documentation/devicetree/bindings/mtd/partitions/partition.yaml b/Documentation/devicetree/bindings/mtd/partitions/partition.yaml index 1ebe9e2347ea..656ca3db1762 100644 --- a/Documentation/devicetree/bindings/mtd/partitions/partition.yaml +++ b/Documentation/devicetree/bindings/mtd/partitions/partition.yaml @@ -57,6 +57,57 @@ properties: user space from type: boolean
- align:
- $ref: /schemas/types.yaml#/definitions/uint32
- minimum: 2
- maximum: 0x80000000
- multipleOf: 2
- description:
This sets the alignment of the entry in bytes.
The entry offset is adjusted so that the entry starts on an aligned
boundary within the containing section or image. For example ‘align =
<16>’ means that the entry will start on a 16-byte boundary. This may
mean that padding is added before the entry. The padding is part of
the containing section but is not included in the entry, meaning that
an empty space may be created before the entry starts. Alignment
must be a power of 2. If ‘align’ is not provided, no alignment is
performed.
- align-size:
- $ref: /schemas/types.yaml#/definitions/uint32
- minimum: 2
- maximum: 0x80000000
- multipleOf: 2
- description:
This sets the alignment of the entry size in bytes. It must be a power
of 2.
For example, to ensure that the size of an entry is a multiple of 64
bytes, set this to 64. While this does not affect the contents of the
entry within binman itself (the padding is performed only when its
parent section is assembled), the end result is that the entry ends
with the padding bytes, so may grow. If ‘align-size’ is not provided,
no alignment is performed.
I don't think we should mention binman here. Can we have a software agnostic description? This should be understandable from anyone playing with mtd partitions I guess.
OK
- align-end:
- $ref: /schemas/types.yaml#/definitions/uint32
- minimum: 2
- maximum: 0x80000000
- multipleOf: 2
seems not to perfectly match the constraint, but I don't know if there is a powerOf keyword? (same above)
I believe this was discussed earlier. No there is no such option!
- description:
This sets the alignment (in bytes) of the end of an entry with respect
to the containing section. It must be a power of 2.
Some entries require that they end on an alignment boundary,
regardless of where they start. This does not move the start of the
entry, so the contents of the entry will still start at the beginning.
But there may be padding at the end. While this does not affect the
contents of the entry within binman itself (the padding is performed
content? same comment about binman?
OK
only when its parent section is assembled), the end result is that the
entry ends with the padding bytes, so may grow. If ‘align-end’ is not
provided, no alignment is performed.
if: not: required: [ reg ]
Regards, SImon
participants (3)
-
Miquel Raynal
-
Rob Herring
-
Simon Glass