block: partition table OF support
Subsystems (5)
v2 cover block: partition table OF support
Hi,
this is an initial proposal to complete support for manually defining partition table.
Some background on this. Many OEM on embedded device (modem, router...) are starting to migrate from NOR/NAND flash to eMMC. The reason for this is that OEM are starting to require more and more space for the firmware and price difference is becoming so little that using eMMC is only benefits and no cons.
Given these reason, OEM are also using very custom way to provide a partition table and doesn't relay on common method like writing a table on the eMMC.
One way that is commonly used is to hardcode the partition table and pass it to the system via various way (cmdline, special glue driver, block2mtd...)
This way is also used on Android where the partition table is passed from the bootloader via cmdline.
One reason to use this method is to save space on the device and to permit more flexibility on partition handling.
What this series does is complete support for this feature. It's possible to use the cmdline to define a partition table similar to how it's done for MTD but this is problematic for a number of device where tweaking the cmdline is not possible. This series adds OF support to make it possible to define a partition table in the Device Tree.
We implement a similar schema to the MTD fixed-partition, where we define a "label" and a "reg" with "offset" and "size".
A new block partition parser is introduced that check if the block device have an OF node attached and check if a fixed-partition table is defined.
If a correct node is found, then partition table is filled. cmdline will still have priority to this new parser.
Some block device also implement boot1 and boot2 additional disk. Similar to the cmdline parser, these disk can have OF support using the "partitions-boot0" and "partitions-boot1" additional node.
It's also completed support for declaring partition as read-only as this feature was introduced but never finished in the cmdline parser.
Posting as RFC for any comments or additional checks on OF parser code.
I hope this solution is better accepted as downstream this is becoming a real problem with a growing number of strange solution for the simple task of providing a fixed partition table.
Changes v2:
- Reference bytes in DT instead of Sector Size
- Validate offset and size after Sector Size conversion
- Limit boot0 and boot1 to eMMC and add comments about JEDEC spec
- Generalize MTD partition schema and introduce block partitions schema
- Add missing code to actually attach the OF parser to block partition core
- Add reviewed by tag for read-only patch
Christian Marangi (5):
block: add support for defining read-only partitions
docs: block: Document support for read-only partition in cmdline part
block: add support for partition table defined in OF
dt-bindings: block: Generalize and introduce property for partitions
dt-bindings: mmc: Document support for partition table in mmc-card
Documentation/block/cmdline-partition.rst | 5 +- .../bindings/block/partitions/partition.yaml | 33 ++++ .../bindings/block/partitions/partitions.yaml | 27 ++++ .../devicetree/bindings/mmc/mmc-card.yaml | 57 +++++++ .../bindings/mtd/partitions/partition.yaml | 10 +- block/blk.h | 1 + block/partitions/Kconfig | 8 + block/partitions/Makefile | 1 + block/partitions/check.h | 1 + block/partitions/cmdline.c | 3 + block/partitions/core.c | 6 + block/partitions/of.c | 144 ++++++++++++++++++ 12 files changed, 287 insertions(+), 9 deletions(-) create mode 100644 Documentation/devicetree/bindings/block/partitions/partition.yaml create mode 100644 Documentation/devicetree/bindings/block/partitions/partitions.yaml create mode 100644 block/partitions/of.c
Signature · 1 line
2.45.2
RFC PATCH v2 1/5 block: add support for defining read-only partitions
Add support for defining read-only partitions and complete support for it in the cmdline partition parser as the additional "ro" after a partition is scanned but never actually applied.
--- block/blk.h | 1 + block/partitions/cmdline.c | 3 +++ block/partitions/core.c | 3 +++ 3 files changed, 7 insertions(+)
block/blk.h +1 -0
@@ -558,6 +558,7 @@ void blk_free_ext_minor(unsigned int minor);#define ADDPART_FLAG_NONE 0#define ADDPART_FLAG_RAID 1#define ADDPART_FLAG_WHOLEDISK 2 +#define ADDPART_FLAG_READONLY 4int bdev_add_partition (struct gendisk *disk,int partno,sector_t start,sector_t length);int bdev_del_partition (struct gendisk *disk,int partno);
block/partitions/cmdline.c +3 -0
@@ -237,6 +237,9 @@ static int add_part(int slot, struct cmdline_subpart *subpart,put_partition (state, slot, subpart->from >>9 , subpart->size >>9 ); +if (subpart->flags &PF_RDONLY ) + state->parts[slot].flags |=ADDPART_FLAG_READONLY ; + info = &state->parts[slot].info;strscpy (info->volname, subpart->name,sizeof (info->volname));
block/partitions/core.c +3 -0
@@ -373,6 +373,9 @@ static struct block_device *add_partition(struct gendisk *disk, int partno, goto out_del; } +if (flags &ADDPART_FLAG_READONLY ) +bdev_set_flag (bdev,BD_READ_ONLY ); +/* everything is up and running, commence */ err =xa_insert (&disk->part_tbl, partno, bdev,GFP_KERNEL );if (err)
Signature · 1 line
2.45.2
RFC PATCH v2 2/5 docs: block: Document support for read-only partition in cmdline part
In reply to Christian MarangiDocument support for read-only partition in cmdline partition for block devices by appending "ro" after the (partition name).
--- Documentation/block/cmdline-partition.rst | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
Documentation/block/cmdline-partition.rst +4 -1
@@ -39,13 +39,16 @@ blkdevparts=<blkdev-def>[;<blkdev-def>] create a link to block device partition with the name "PARTNAME". User space application can access partition by partition name. +ro + read-only. Flag the partition as read-only. + Example: eMMC disk names are "mmcblk0" and "mmcblk0boot0". bootargs:: - 'blkdevparts=mmcblk0:1G(data0),1G(data1),-;mmcblk0boot0:1m(boot),-(kernel)' + 'blkdevparts=mmcblk0:1G(data0),1G(data1),-;mmcblk0boot0:1m(boot)ro,-(kernel)' dmesg::
Signature · 1 line
2.45.2
RFC PATCH v2 3/5 block: add support for partition table defined in OF
In reply to Christian MarangiAdd support for partition table defined in Device Tree. Similar to how it's done with MTD, add support for defining a fixed partition table in device tree.
A common scenario for this is fixed block (eMMC) embedded devices that have no MBR or GPT partition table to save storage space. Bootloader access the block device with absolute address of data.
This is to complete the functionality with an equivalent implementation with providing partition table with bootargs, for case where the booargs can't be modified and tweaking the Device Tree is the only solution to have an usabe partition table.
The implementation follow the fixed-partitions parser used on MTD devices where a "partitions" node is expected to be declared in the OF node of the disk device (mmc-card for eMMC for example) and each child node declare a label and a reg with offset and size. Eventually is also possible to declare the read-only property to flag the partition as read-only.
For eMMC block, driver scan the disk name and check if it's suffixed with "boot0" or "boot1".
This is to handle the additional disk provided by eMMC as supported in JEDEC 4.4+. If this suffix is detected, "partitions-boot0" or "partitions-boot1" are used instead of the generic "partitions" for the relevant disk.
--- block/partitions/Kconfig | 8 +++ block/partitions/Makefile | 1 + block/partitions/check.h | 1 + block/partitions/core.c | 3 + block/partitions/of.c | 144 ++++++++++++++++++++++++++++++++++++++ 5 files changed, 157 insertions(+) create mode 100644 block/partitions/of.c
block/partitions/Kconfig +8 -0
@@ -270,4 +270,12 @@ config CMDLINE_PARTITION Say Y here if you want to read the partition table from bootargs. The format for the command line is just like mtdparts. +config OF_PARTITION + bool "Command line partition support" if PARTITION_ADVANCED + depends on OF + help + Say Y here if you want to enable support for partition table + defined in Device Tree. (mainly for eMMC) + The format for the command line is just like MTD fixed-partition schema. + endmenu
block/partitions/Makefile +1 -0
@@ -12,6 +12,7 @@ obj-$(CONFIG_CMDLINE_PARTITION) += cmdline.o obj-$(CONFIG_MAC_PARTITION) += mac.o obj-$(CONFIG_LDM_PARTITION) += ldm.o obj-$(CONFIG_MSDOS_PARTITION) += msdos.o +obj-$(CONFIG_OF_PARTITION) += of.o obj-$(CONFIG_OSF_PARTITION) += osf.o obj-$(CONFIG_SGI_PARTITION) += sgi.o obj-$(CONFIG_SUN_PARTITION) += sun.o
block/partitions/check.h +1 -0
@@ -62,6 +62,7 @@ int karma_partition(struct parsed_partitions *state);int ldm_partition (struct parsed_partitions *state);int mac_partition (struct parsed_partitions *state);int msdos_partition (struct parsed_partitions *state); +int of_partition (struct parsed_partitions *state);int osf_partition (struct parsed_partitions *state);int sgi_partition (struct parsed_partitions *state);int sun_partition (struct parsed_partitions *state);
block/partitions/core.c +3 -0
@@ -43,6 +43,9 @@ static int (*const check_part[])(struct parsed_partitions *) = {#ifdef CONFIG_CMDLINE_PARTITION cmdline_partition,#endif +#ifdef CONFIG_OF_PARTITION + of_partition, /* cmdline have priority to OF */ +#endif #ifdef CONFIG_EFI_PARTITION efi_partition, /* this must come before msdos */#endif
block/partitions/of.c new file +144 -0
144 lines not on this page · raw message
Signature · 1 line
2.45.2
RFC PATCH v2 4/5 dt-bindings: block: Generalize and introduce property for partitions
In reply to Christian MarangiGeneralize property from MTD partitions schema and introduce property for block partitions defined in OF.
Partition schema for block devices is a reduced schema of the MTD as only a few property are supported for it. (reg, label and read-only)
--- .../bindings/block/partitions/partition.yaml | 33 +++++++++++++++++++ .../bindings/block/partitions/partitions.yaml | 27 +++++++++++++++ .../bindings/mtd/partitions/partition.yaml | 10 ++---- 3 files changed, 62 insertions(+), 8 deletions(-) create mode 100644 Documentation/devicetree/bindings/block/partitions/partition.yaml create mode 100644 Documentation/devicetree/bindings/block/partitions/partitions.yaml
Documentation/devicetree/bindings/block/partitions/partition.yaml new file +33 -0
@@ -0,0 +1,33 @@ +# SPDX-License-Identifier: GPL-2.0-only OR BSD-2-Clause +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/block/partitions/partition.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Partition + +description: | + This binding describes a single flash partition. Each partition must have its + relative offset and size specified. Depending on partition function extra + properties can be used. + +maintainers: + - Christian Marangi <[email protected]> + +properties: + reg: + description: partition's offset and size within the flash (in sector + block, 512byte) + maxItems: 1 + + label: + description: The label / name for this partition. + + read-only: + description: This parameter, if present, is a hint that this partition + should only be mounted read-only. This is usually used for flash + partitions containing early-boot firmware images or data which should + not be clobbered. + type: boolean + +additionalProperties: true
Documentation/devicetree/bindings/block/partitions/partitions.yaml new file +27 -0
@@ -0,0 +1,27 @@ +# SPDX-License-Identifier: GPL-2.0-only OR BSD-2-Clause +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/block/partitions/partitions.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Partitions + +description: | + This binding is generic and describes the content of the partitions container + node. + +maintainers: + - Christian Marangi <[email protected]> + +properties: + '#address-cells': + enum: [1, 2] + + '#size-cells': + enum: [1, 2] + +patternProperties: + "^partition@[0-9a-f]+$": + $ref: partition.yaml + +unevaluatedProperties: false
Documentation/devicetree/bindings/mtd/partitions/partition.yaml +2 -8
@@ -6,6 +6,8 @@ $schema: http://devicetree.org/meta-schemas/core.yaml# title: Partition +$ref: /schemas/block/partitions/partition.yaml + description: | This binding describes a single flash partition. Each partition must have its relative offset and size specified. Depending on partition function extra
@@ -28,19 +30,11 @@ maintainers: properties: reg: description: partition's offset and size within the flash - maxItems: 1 label: description: The label / name for this partition. If omitted, the label is taken from the node name (excluding the unit address). - read-only: - description: This parameter, if present, is a hint that this partition - should only be mounted read-only. This is usually used for flash - partitions containing early-boot firmware images or data which should - not be clobbered. - type: boolean - lock: description: Do not unlock the partition at initialization time (not supported on all devices)
Signature · 1 line
2.45.2
Rob Herring
maintainerRe: [RFC PATCH v2 4/5] dt-bindings: block: Generalize and introduce property for partitions
Quoted 6 lines · Christian Marangi
Generalize property from MTD partitions schema and introduce property for block partitions defined in OF.
Partition schema for block devices is a reduced schema of the MTD as only a few property are supported for it. (reg, label and read-only)
Quoted 8 lines
Signed-off-by Christian Marangi <[email protected]>--- .../bindings/block/partitions/partition.yaml | 33 +++++++++++++++++++ .../bindings/block/partitions/partitions.yaml | 27 +++++++++++++++ .../bindings/mtd/partitions/partition.yaml | 10 ++---- 3 files changed, 62 insertions(+), 8 deletions(-) create mode 100644 Documentation/devicetree/bindings/block/partitions/partition.yaml create mode 100644 Documentation/devicetree/bindings/block/partitions/partitions.yaml
Partitions are partitions. We don't need them defined in both mtd and block. Could perhaps move them to bindings/partitions/, but that's not really worth it in my opinion. Just use and add to what's in mtd.
Quoted 7 lines
Documentation/devicetree/bindings/block/partitions/partition.yaml new file +0
-0
Documentation/devicetree/bindings/block/partitions/partition.yaml line 9
Quoted 9 lines
Documentation/devicetree/bindings/block/partitions/partition.yaml new file +9
-0@@ -0,0 +1,33 @@ +# SPDX-License-Identifier: GPL-2.0-only OR BSD-2-Clause +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/block/partitions/partition.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Partition + +description: |
Don't need '|' if no formatting.
Quoted 41 lines
Documentation/devicetree/bindings/block/partitions/partition.yaml new file +24
-0+ This binding describes a single flash partition. Each partition must have its + relative offset and size specified. Depending on partition function extra + properties can be used. + +maintainers: + - Christian Marangi <[email protected]> + +properties: + reg: + description: partition's offset and size within the flash (in sector + block, 512byte) + maxItems: 1 + + label: + description: The label / name for this partition. + + read-only: + description: This parameter, if present, is a hint that this partition + should only be mounted read-only. This is usually used for flash + partitions containing early-boot firmware images or data which should + not be clobbered. + type: boolean + +additionalProperties: trueDocumentation/devicetree/bindings/block/partitions/partitions.yaml new file +11
-0@@ -0,0 +1,27 @@ +# SPDX-License-Identifier: GPL-2.0-only OR BSD-2-Clause +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/block/partitions/partitions.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Partitions + +description: | + This binding is generic and describes the content of the partitions container + node.
Documentation/devicetree/bindings/block/partitions/partitions.yaml line 21
Quoted 10 lines
Documentation/devicetree/bindings/block/partitions/partitions.yaml new file +10
-0+ +maintainers: + - Christian Marangi <[email protected]> + +properties: + '#address-cells': + enum: [1, 2] + + '#size-cells': + enum: [1, 2]
Like *all* other 'partitions' nodes, you need a compatible to say what kind of partitions you have. It's conceivable that some vendor invented their own scheme just like MTD devices.
As I said before, this is just 'fixed-partitions'. If some properties aren't supported, that's fine. All the 'align' properties are for flashing tools and aren't supported in Linux.
Rob
RFC PATCH v2 5/5 dt-bindings: mmc: Document support for partition table in mmc-card
In reply to Christian MarangiDocument support for defining a partition table in the mmc-card node.
This is needed if the eMMC doesn't have a partition table written and the bootloader of the device load data by using absolute offset of the block device. This is common on embedded device that have eMMC installed to save space and have non removable block devices.
If an OF partition table is detected, any partition table written in the eMMC will be ignored and won't be parsed.
eMMC provide a generic disk for user data and if supported (JEDEC 4.4+) also provide two additional disk ("boot0" and "boot1") for special usage of boot operation where normally is stored the bootloader or boot info.
--- .../devicetree/bindings/mmc/mmc-card.yaml | 57 +++++++++++++++++++ 1 file changed, 57 insertions(+)
Documentation/devicetree/bindings/mmc/mmc-card.yaml +57 -0
@@ -13,6 +13,10 @@ description: | This documents describes the devicetree bindings for a mmc-host controller child node describing a mmc-card / an eMMC. + It's possible to define a fixed partition table for an eMMC for the user + partition and one of the 2 boot partition (boot0/boot1) if supported by the + eMMC. + properties: compatible: const: mmc-card
@@ -26,6 +30,30 @@ properties: Use this to indicate that the mmc-card has a broken hpi implementation, and that hpi should not be used. + "#address-cells": + const: 0 + + "#size-cells": + const: 0 + +patternProperties: + "^partitions(-boot[01])?$": + $ref: /schemas/block/partitions/partitions.yaml + + patternProperties: + "^partition@[0-9a-f]+$": + $ref: /schemas/block/partitions/partition.yaml + + properties: + reg: + multipleOf: 512 + + required: + - reg + - label + + unevaluatedProperties: false + required: - compatible - reg
@@ -42,6 +70,35 @@ examples: compatible = "mmc-card"; reg = <0>; broken-hpi; + + #address-cells = <0>; + #size-cells = <0>; + + partitions { + #address-cells = <1>; + #size-cells = <1>; + + partition@0 { + label = "kernel"; /* Kernel */ + reg = <0x0 0x2000000>; /* 32 MB */ + }; + + partition@2000000 { + label = "rootfs"; + reg = <0x2000000 0x40000000>; /* 1GB */ + }; + }; + + partitions-boot0 { + #address-cells = <1>; + #size-cells = <1>; + + partition@0 { + label = "bl"; + reg = <0x0 0x2000000>; /* 32MB */ + read-only; + }; + }; }; };
Signature · 1 line
2.45.2
Rob Herring
maintainerRe: [RFC PATCH v2 5/5] dt-bindings: mmc: Document support for partition table in mmc-card
Quoted 35 lines · Christian Marangi
Document support for defining a partition table in the mmc-card node.
This is needed if the eMMC doesn't have a partition table written and the bootloader of the device load data by using absolute offset of the block device. This is common on embedded device that have eMMC installed to save space and have non removable block devices.
If an OF partition table is detected, any partition table written in the eMMC will be ignored and won't be parsed.
eMMC provide a generic disk for user data and if supported (JEDEC 4.4+) also provide two additional disk ("boot0" and "boot1") for special usage of boot operation where normally is stored the bootloader or boot info.
Signed-off-by Christian Marangi <[email protected]>--- .../devicetree/bindings/mmc/mmc-card.yaml | 57 +++++++++++++++++++ 1 file changed, 57 insertions(+)Documentation/devicetree/bindings/mmc/mmc-card.yaml +4
-0@@ -13,6 +13,10 @@ description: | This documents describes the devicetree bindings for a mmc-host controller child node describing a mmc-card / an eMMC. + It's possible to define a fixed partition table for an eMMC for the user + partition and one of the 2 boot partition (boot0/boot1) if supported by the + eMMC. + properties: compatible: const: mmc-card
Documentation/devicetree/bindings/mmc/mmc-card.yaml properties: · line 37
Quoted 8 lines
Documentation/devicetree/bindings/mmc/mmc-card.yaml +5
-0@@ -26,6 +30,30 @@ properties: Use this to indicate that the mmc-card has a broken hpi implementation, and that hpi should not be used. + "#address-cells": + const: 0 + + "#size-cells": + const: 0
Don't need these properties.
Documentation/devicetree/bindings/mmc/mmc-card.yaml properties: · line 49
Quoted 12 lines
Documentation/devicetree/bindings/mmc/mmc-card.yaml +12
-0+ +patternProperties: + "^partitions(-boot[01])?$": + $ref: /schemas/block/partitions/partitions.yaml + + patternProperties: + "^partition@[0-9a-f]+$": + $ref: /schemas/block/partitions/partition.yaml + + properties: + reg: + multipleOf: 512
I was going to suggest this, but I think it won't actually work because it could be 2 cells for address and/or size.
Rob
Re: [RFC PATCH v2 5/5] dt-bindings: mmc: Document support for partition table in mmc-card
Quoted 47 lines · Rob Herring
Quoted 35 lines · Christian Marangi
Document support for defining a partition table in the mmc-card node.
This is needed if the eMMC doesn't have a partition table written and the bootloader of the device load data by using absolute offset of the block device. This is common on embedded device that have eMMC installed to save space and have non removable block devices.
If an OF partition table is detected, any partition table written in the eMMC will be ignored and won't be parsed.
eMMC provide a generic disk for user data and if supported (JEDEC 4.4+) also provide two additional disk ("boot0" and "boot1") for special usage of boot operation where normally is stored the bootloader or boot info.
Signed-off-by Christian Marangi <[email protected]>--- .../devicetree/bindings/mmc/mmc-card.yaml | 57 +++++++++++++++++++ 1 file changed, 57 insertions(+)Documentation/devicetree/bindings/mmc/mmc-card.yaml +4
-0@@ -13,6 +13,10 @@ description: | This documents describes the devicetree bindings for a mmc-host controller child node describing a mmc-card / an eMMC. + It's possible to define a fixed partition table for an eMMC for the user + partition and one of the 2 boot partition (boot0/boot1) if supported by the + eMMC. + properties: compatible: const: mmc-cardDocumentation/devicetree/bindings/mmc/mmc-card.yaml properties: · line 37
Quoted 8 lines
Documentation/devicetree/bindings/mmc/mmc-card.yaml +5
-0@@ -26,6 +30,30 @@ properties: Use this to indicate that the mmc-card has a broken hpi implementation, and that hpi should not be used. + "#address-cells": + const: 0 + + "#size-cells": + const: 0Don't need these properties.
Quoted 16 lines
Documentation/devicetree/bindings/mmc/mmc-card.yaml properties: · line 49
Quoted 12 lines
Documentation/devicetree/bindings/mmc/mmc-card.yaml +12
-0+ +patternProperties: + "^partitions(-boot[01])?$": + $ref: /schemas/block/partitions/partitions.yaml + + patternProperties: + "^partition@[0-9a-f]+$": + $ref: /schemas/block/partitions/partition.yaml + + properties: + reg: + multipleOf: 512I was going to suggest this, but I think it won't actually work because it could be 2 cells for address and/or size.
While checking I was surprised for this multipleOf and was very happy to have something like this but I also had some fear it didn't work due to the 2 cell thing... Very sad. I will add a description to it.
The driver will validate the values anyway, at least on that part we are on the safe side.
Signature · 1 line
Ansuel