Skip to contentSkip to conversation

block: partition table OF support

RFC PATCH Superseded Christian Marangi 4 participants 16 messages Sep 23, 2024 – Oct 2, 2024

Subsystems (4)

v1 of 6 Superseded Latest is v6 →

lore
Share & tools
lore
#0 lore raw

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.

Christian Marangi (4):
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: mmc: Document support for partition table in mmc-card

 Documentation/block/cmdline-partition.rst     |  5 +-
 .../devicetree/bindings/mmc/mmc-card.yaml     | 75 ++++++++++++++++
 block/blk.h                                   |  1 +
 block/partitions/Kconfig                      |  8 ++
 block/partitions/Makefile                     |  1 +
 block/partitions/cmdline.c                    |  3 +
 block/partitions/core.c                       |  3 +
 block/partitions/of.c                         | 85 +++++++++++++++++++
 8 files changed, 180 insertions(+), 1 deletion(-)
 create mode 100644 block/partitions/of.c
Signature · 1 line
2.45.2
#1 lore raw

RFC PATCH 1/4 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
index c718e4291db0..f300212d3e98 100644
@@ -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	4
 int 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
index 152c85df92b2..da3e719d8e51 100644
@@ -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
index ab76e64f0f6c..abad6c83db8f 100644
@@ -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
#3 lore raw

RFC PATCH 2/4 docs: block: Document support for read-only partition in cmdline part

In reply to Christian Marangi

Document 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
index 530bedff548a..526ba201dddc 100644
@@ -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
#4 lore raw

RFC PATCH 3/4 block: add support for partition table defined in OF

In reply to Christian Marangi

Add 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.

The 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 or UFS devices in general. If this suffix is detected, "partitions-boot0" or "partitions-boot1" are used instead of the generic "partitions"

---
 block/partitions/Kconfig  |  8 ++++
 block/partitions/Makefile |  1 +
 block/partitions/of.c     | 85 +++++++++++++++++++++++++++++++++++++++
 3 files changed, 94 insertions(+)
 create mode 100644 block/partitions/of.c
block/partitions/Kconfig +8 -0
index 7aff4eb81c60..8534f7544f26 100644
@@ -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
index a7f05cdb02a8..25d424922c6e 100644
@@ -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/of.c new file +85 -0

85 lines not on this page · raw message

Signature · 1 line
2.45.2
#5 lore raw

Re: [RFC PATCH 3/4] block: add support for partition table defined in OF

block/partitions/of.c line 9

Quoted 3 lines · Christian Marangi
block/partitions/of.c new file +3 -0
+#define BOOT0_STR	"boot0"
+#define BOOT1_STR	"boot1"
+

This boot0/1 stuff looks like black magic, so it should probably be documented at very least.

block/partitions/of.c line 69

Quoted 2 lines
block/partitions/of.c new file +2 -0
+	partitions_np = get_partitions_node(disk_np,
+					    state->disk->disk_name);

disk->disk_name is not a stable identifier and can change from boot to boot due to async probing. You'll need to check a uuid or label instead.

#6 lore raw

Re: [RFC PATCH 3/4] block: add support for partition table defined in OF

Quoted 8 lines · Christoph Hellwig

block/partitions/of.c line 9

Quoted 3 lines · Christian Marangi
block/partitions/of.c new file +3 -0
+#define BOOT0_STR	"boot0"
+#define BOOT1_STR	"boot1"
+

This boot0/1 stuff looks like black magic, so it should probably be documented at very least.

It is but from what I have read in the spec for flash in general (this is not limited to eMMC but also apply to UFS) these are hardware partition. If the version is high enough these are always present and have boot0 and boot1 name hardcoded by the driver.

Quoted 5 lines

block/partitions/of.c line 69

Quoted 2 lines
block/partitions/of.c new file +2 -0
+	partitions_np = get_partitions_node(disk_np,
+					    state->disk->disk_name);

disk->disk_name is not a stable identifier and can change from boot to boot due to async probing. You'll need to check a uuid or label instead.

This is really for the 2 special partition up to check the suffix, we don't really care about the name. I guess it's acceptable to use unstable identifier?

Thanks a lot for the review!

Signature · 1 line
	Ansuel
#7 lore raw

Re: [RFC PATCH 3/4] block: add support for partition table defined in OF

Quoted 10 lines · Christian Marangi
Quoted 8 lines · Christoph Hellwig

block/partitions/of.c line 9

Quoted 3 lines · Christian Marangi
block/partitions/of.c new file +3 -0
+#define BOOT0_STR	"boot0"
+#define BOOT1_STR	"boot1"
+

This boot0/1 stuff looks like black magic, so it should probably be documented at very least.

Quoted 4 lines

It is but from what I have read in the spec for flash in general (this is not limited to eMMC but also apply to UFS) these are hardware partition. If the version is high enough these are always present and have boot0 and boot1 name hardcoded by the driver.

How does this belong into generic block layer code?

Quoted 9 lines
Quoted 5 lines

block/partitions/of.c line 69

Quoted 2 lines
block/partitions/of.c new file +2 -0
+	partitions_np = get_partitions_node(disk_np,
+					    state->disk->disk_name);

disk->disk_name is not a stable identifier and can change from boot to boot due to async probing. You'll need to check a uuid or label instead.

This is really for the 2 special partition up to check the suffix, we don't really care about the name. I guess it's acceptable to use unstable identifier?

No. ->disk_name is in no way reliable, we can't hardcode that into a partition parser.

#8 lore raw

Re: [RFC PATCH 3/4] block: add support for partition table defined in OF

Quoted 11 lines · Christoph Hellwig
Quoted 10 lines · Christian Marangi
Quoted 8 lines · Christoph Hellwig

block/partitions/of.c line 9

Quoted 3 lines · Christian Marangi
block/partitions/of.c new file +3 -0
+#define BOOT0_STR	"boot0"
+#define BOOT1_STR	"boot1"
+

This boot0/1 stuff looks like black magic, so it should probably be documented at very least.

Quoted 7 lines
Quoted 4 lines

It is but from what I have read in the spec for flash in general (this is not limited to eMMC but also apply to UFS) these are hardware partition. If the version is high enough these are always present and have boot0 and boot1 name hardcoded by the driver.

How does this belong into generic block layer code?

(just as an info, we are at v4 where I added more info about this)

The cmdline partition parser supports this already, just not clearly stated in the code but described in the Documentation example and info.

Quoted 6 lines
Quoted 6 lines
Quoted 5 lines

block/partitions/of.c line 69

Quoted 2 lines
block/partitions/of.c new file +2 -0
+	partitions_np = get_partitions_node(disk_np,
+					    state->disk->disk_name);

disk->disk_name is not a stable identifier and can change from boot to boot due to async probing. You'll need to check a uuid or label instead.

Quoted 7 lines
Quoted 3 lines

This is really for the 2 special partition up to check the suffix, we don't really care about the name. I guess it's acceptable to use unstable identifier?

No. ->disk_name is in no way reliable, we can't hardcode that into a partition parser.

Then any hint on this or alternative way?
Again this is how it's done with cmdline partition so I'm just following how it's already done.

Also I feel it's not clear enough that we really don't care about the identifier, eMMC driver hardcode and always append to disk_name boot0, boot1, the fact that one disk or another might have a different identifier and they change on different boot is not important for the task needed here.

I can drop this thing entirely and make the implementation very simple but there are already request and happy dev that would benefits for the additional hardware partition supported by this.

Signature · 1 line
	Ansuel
#9 lore raw

Re: [RFC PATCH 3/4] block: add support for partition table defined in OF

Quoted 5 lines · Christian Marangi
Quoted 3 lines

No. ->disk_name is in no way reliable, we can't hardcode that into a partition parser.

Then any hint on this or alternative way?

The normal way would be to use eui/ngui/uuid provided by the storage device. We have a interface for that in the block layer support by scsi and nvme, but I don't know how to wire that up for eMMC which I suspect is what you care about.

#10 lore raw

Re: [RFC PATCH 3/4] block: add support for partition table defined in OF

Quoted 5 lines · Christoph Hellwig
Quoted 4 lines · Christian Marangi
Quoted 3 lines

No. ->disk_name is in no way reliable, we can't hardcode that into a partition parser.

Quoted 7 lines
Quoted 1 line

Then any hint on this or alternative way?

The normal way would be to use eui/ngui/uuid provided by the storage device. We have a interface for that in the block layer support by scsi and nvme, but I don't know how to wire that up for eMMC which I suspect is what you care about.

I think I have found a better way to handle it, please check v5, did you receive the series?

The new series just make the driver pass the partition node and the OF code just take it and use it.

This way we don't have to parse the disk name at all and it's driver specific work to select the "partitions" node if multiple are present.

I feel your hint produced a much better implementation without having to pollute the block code with specific case.

Signature · 1 line
	Ansuel
#11 lore raw

Re: [RFC PATCH 3/4] block: add support for partition table defined in OF

In reply to Christian Marangi
kernel test robot noticed the following build errors:

Hi Christian,

[This is a private test report for your RFC patch.] kernel test robot noticed the following build errors:

[auto build test ERROR on axboe-block/for-next]
[also build test ERROR on robh/for-next lwn/docs-next linus/master v6.11 next-20240925] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Christian-Marangi/block-add-support-for-defining-read-only-partitions/20240923-190251
base:   https://git.kernel.org/pub/scm/linux/kernel/git/axboe/linux-block.git for-next
patch link:    https://lore.kernel.org/r/20240923105937.4374-4-ansuelsmth%40gmail.com
patch subject: [RFC PATCH 3/4] block: add support for partition table defined in OF
config: sh-allmodconfig (https://download.01.org/0day-ci/archive/20240925/[email protected]/config)
compiler: sh4-linux-gcc (GCC) 14.1.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20240925/[email protected]/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

All error/warnings (new ones prefixed by >>):

block/partitions/of.c: In function 'add_of_partition':

>> block/partitions/of.c:47:35: error: 'pp' undeclared (first use in this function); did you mean 'np'?
      47 |         if (of_property_read_bool(pp, "read-only"))
         |                                   ^~
         |                                   np
   block/partitions/of.c:47:35: note: each undeclared identifier is reported only once for each function it appears in
   block/partitions/of.c: At top level:
>> block/partitions/of.c:58:5: warning: no previous prototype for 'of_partition' [-Wmissing-prototypes]

58 | int of_partition(struct parsed_partitions *state)
| ^~~~~~~~~~~~

vim +47 block/partitions/of.c

    25	
    26	static void add_of_partition(struct parsed_partitions *state, int slot,
    27				     struct device_node *np)
    28	{
    29		struct partition_meta_info *info;
    30		char tmp[sizeof(info->volname) + 4];
    31		int a_cells, s_cells;
    32		const char *partname;
    33		const __be32 *reg;
    34		u64 offset, size;
    35		int len;
    36	
    37		reg = of_get_property(np, "reg", &len);
    38	
    39		a_cells = of_n_addr_cells(np);
    40		s_cells = of_n_size_cells(np);
    41	
    42		offset = of_read_number(reg, a_cells);
    43		size = of_read_number(reg + a_cells, s_cells);
    44	
    45		put_partition(state, slot, offset, size);
    46	
  > 47		if (of_property_read_bool(pp, "read-only"))
    48			state->parts[slot].flags |= ADDPART_FLAG_READONLY;
    49	
    50		info = &state->parts[slot].info;
    51		partname = of_get_property(np, "label", &len);
    52		strscpy(info->volname, partname, sizeof(info->volname));
    53	
    54		snprintf(tmp, sizeof(tmp), "(%s)", info->volname);
    55		strlcat(state->pp_buf, tmp, PAGE_SIZE);
    56	}
    57	
  > 58	int of_partition(struct parsed_partitions *state)
Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
#12 lore raw

Re: [RFC PATCH 3/4] block: add support for partition table defined in OF

In reply to Christian Marangi
kernel test robot noticed the following build errors:

Hi Christian,

[This is a private test report for your RFC patch.] kernel test robot noticed the following build errors:

[auto build test ERROR on axboe-block/for-next]
[also build test ERROR on robh/for-next lwn/docs-next linus/master v6.11 next-20240925] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Christian-Marangi/block-add-support-for-defining-read-only-partitions/20240923-190251
base:   https://git.kernel.org/pub/scm/linux/kernel/git/axboe/linux-block.git for-next
patch link:    https://lore.kernel.org/r/20240923105937.4374-4-ansuelsmth%40gmail.com
patch subject: [RFC PATCH 3/4] block: add support for partition table defined in OF
config: s390-allmodconfig (https://download.01.org/0day-ci/archive/20240925/[email protected]/config)
compiler: clang version 20.0.0git (https://github.com/llvm/llvm-project 7773243d9916f98ba0ffce0c3a960e4aa9f03e81)
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20240925/[email protected]/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

All error/warnings (new ones prefixed by >>):

In file included from block/partitions/of.c:3:
In file included from include/linux/blkdev.h:9:
In file included from include/linux/blk_types.h:10:
In file included from include/linux/bvec.h:10:
In file included from include/linux/highmem.h:10:
In file included from include/linux/mm.h:2237:
include/linux/vmstat.h:503:43: warning: arithmetic between different enumeration types ('enum zone_stat_item' and 'enum numa_stat_item') [-Wenum-enum-conversion]

     503 |         return vmstat_text[NR_VM_ZONE_STAT_ITEMS +
         |                            ~~~~~~~~~~~~~~~~~~~~~ ^
     504 |                            item];
         |                            ~~~~
   include/linux/vmstat.h:510:43: warning: arithmetic between different enumeration types ('enum zone_stat_item' and 'enum numa_stat_item') [-Wenum-enum-conversion]
     510 |         return vmstat_text[NR_VM_ZONE_STAT_ITEMS +
         |                            ~~~~~~~~~~~~~~~~~~~~~ ^
     511 |                            NR_VM_NUMA_EVENT_ITEMS +
         |                            ~~~~~~~~~~~~~~~~~~~~~~
   include/linux/vmstat.h:517:36: warning: arithmetic between different enumeration types ('enum node_stat_item' and 'enum lru_list') [-Wenum-enum-conversion]
     517 |         return node_stat_name(NR_LRU_BASE + lru) + 3; // skip "nr_"
         |                               ~~~~~~~~~~~ ^ ~~~
   include/linux/vmstat.h:523:43: warning: arithmetic between different enumeration types ('enum zone_stat_item' and 'enum numa_stat_item') [-Wenum-enum-conversion]
     523 |         return vmstat_text[NR_VM_ZONE_STAT_ITEMS +
         |                            ~~~~~~~~~~~~~~~~~~~~~ ^
     524 |                            NR_VM_NUMA_EVENT_ITEMS +
         |                            ~~~~~~~~~~~~~~~~~~~~~~
   In file included from block/partitions/of.c:5:
   In file included from block/partitions/check.h:4:
   In file included from block/partitions/../blk.h:7:
   In file included from include/linux/memblock.h:13:
   In file included from arch/s390/include/asm/dma.h:5:
   In file included from include/linux/io.h:14:
   In file included from arch/s390/include/asm/io.h:93:
   include/asm-generic/io.h:548:31: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
     548 |         val = __raw_readb(PCI_IOBASE + addr);
         |                           ~~~~~~~~~~ ^
   include/asm-generic/io.h:561:61: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
     561 |         val = __le16_to_cpu((__le16 __force)__raw_readw(PCI_IOBASE + addr));
         |                                                         ~~~~~~~~~~ ^
   include/uapi/linux/byteorder/big_endian.h:37:59: note: expanded from macro '__le16_to_cpu'
      37 | #define __le16_to_cpu(x) __swab16((__force __u16)(__le16)(x))
         |                                                           ^
   include/uapi/linux/swab.h:102:54: note: expanded from macro '__swab16'
     102 | #define __swab16(x) (__u16)__builtin_bswap16((__u16)(x))
         |                                                      ^
   In file included from block/partitions/of.c:5:
   In file included from block/partitions/check.h:4:
   In file included from block/partitions/../blk.h:7:
   In file included from include/linux/memblock.h:13:
   In file included from arch/s390/include/asm/dma.h:5:
   In file included from include/linux/io.h:14:
   In file included from arch/s390/include/asm/io.h:93:
   include/asm-generic/io.h:574:61: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
     574 |         val = __le32_to_cpu((__le32 __force)__raw_readl(PCI_IOBASE + addr));
         |                                                         ~~~~~~~~~~ ^
   include/uapi/linux/byteorder/big_endian.h:35:59: note: expanded from macro '__le32_to_cpu'
      35 | #define __le32_to_cpu(x) __swab32((__force __u32)(__le32)(x))
         |                                                           ^
   include/uapi/linux/swab.h:115:54: note: expanded from macro '__swab32'
     115 | #define __swab32(x) (__u32)__builtin_bswap32((__u32)(x))
         |                                                      ^
   In file included from block/partitions/of.c:5:
   In file included from block/partitions/check.h:4:
   In file included from block/partitions/../blk.h:7:
   In file included from include/linux/memblock.h:13:
   In file included from arch/s390/include/asm/dma.h:5:
   In file included from include/linux/io.h:14:
   In file included from arch/s390/include/asm/io.h:93:
   include/asm-generic/io.h:585:33: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
     585 |         __raw_writeb(value, PCI_IOBASE + addr);
         |                             ~~~~~~~~~~ ^
   include/asm-generic/io.h:595:59: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
     595 |         __raw_writew((u16 __force)cpu_to_le16(value), PCI_IOBASE + addr);
         |                                                       ~~~~~~~~~~ ^
   include/asm-generic/io.h:605:59: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
     605 |         __raw_writel((u32 __force)cpu_to_le32(value), PCI_IOBASE + addr);
         |                                                       ~~~~~~~~~~ ^
   include/asm-generic/io.h:693:20: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
     693 |         readsb(PCI_IOBASE + addr, buffer, count);
         |                ~~~~~~~~~~ ^
   include/asm-generic/io.h:701:20: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
     701 |         readsw(PCI_IOBASE + addr, buffer, count);
         |                ~~~~~~~~~~ ^
   include/asm-generic/io.h:709:20: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
     709 |         readsl(PCI_IOBASE + addr, buffer, count);
         |                ~~~~~~~~~~ ^
   include/asm-generic/io.h:718:21: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
     718 |         writesb(PCI_IOBASE + addr, buffer, count);
         |                 ~~~~~~~~~~ ^
   include/asm-generic/io.h:727:21: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
     727 |         writesw(PCI_IOBASE + addr, buffer, count);
         |                 ~~~~~~~~~~ ^
   include/asm-generic/io.h:736:21: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
     736 |         writesl(PCI_IOBASE + addr, buffer, count);
         |                 ~~~~~~~~~~ ^
>> block/partitions/of.c:47:28: error: use of undeclared identifier 'pp'
      47 |         if (of_property_read_bool(pp, "read-only"))
         |                                   ^
>> block/partitions/of.c:58:5: warning: no previous prototype for function 'of_partition' [-Wmissing-prototypes]
      58 | int of_partition(struct parsed_partitions *state)
         |     ^
   block/partitions/of.c:58:1: note: declare 'static' if the function is not intended to be used outside of this translation unit
      58 | int of_partition(struct parsed_partitions *state)
         | ^
         | static 

17 warnings and 1 error generated.

vim +/pp +47 block/partitions/of.c

    25	
    26	static void add_of_partition(struct parsed_partitions *state, int slot,
    27				     struct device_node *np)
    28	{
    29		struct partition_meta_info *info;
    30		char tmp[sizeof(info->volname) + 4];
    31		int a_cells, s_cells;
    32		const char *partname;
    33		const __be32 *reg;
    34		u64 offset, size;
    35		int len;
    36	
    37		reg = of_get_property(np, "reg", &len);
    38	
    39		a_cells = of_n_addr_cells(np);
    40		s_cells = of_n_size_cells(np);
    41	
    42		offset = of_read_number(reg, a_cells);
    43		size = of_read_number(reg + a_cells, s_cells);
    44	
    45		put_partition(state, slot, offset, size);
    46	
  > 47		if (of_property_read_bool(pp, "read-only"))
    48			state->parts[slot].flags |= ADDPART_FLAG_READONLY;
    49	
    50		info = &state->parts[slot].info;
    51		partname = of_get_property(np, "label", &len);
    52		strscpy(info->volname, partname, sizeof(info->volname));
    53	
    54		snprintf(tmp, sizeof(tmp), "(%s)", info->volname);
    55		strlcat(state->pp_buf, tmp, PAGE_SIZE);
    56	}
    57	
  > 58	int of_partition(struct parsed_partitions *state)
Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
#13 lore raw

RFC PATCH 4/4 dt-bindings: mmc: Document support for partition table in mmc-card

In reply to 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.

eMMC provide a generic disk for user data and if supported also provide one or 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     | 75 +++++++++++++++++++
 1 file changed, 75 insertions(+)
Documentation/devicetree/bindings/mmc/mmc-card.yaml +75 -0
index fd347126449a..fab9fa5c170a 100644
@@ -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,48 @@ properties:
       Use this to indicate that the mmc-card has a broken hpi
       implementation, and that hpi should not be used.
 
+  "#address-cells": true
+
+  "#size-cells": true
+
+patternProperties:
+  "^partitions(-boot[01])?$":
+    type: object
+
+    properties:
+      "#address-cells": true
+
+      "#size-cells": true
+
+    patternProperties:
+      "@[0-9a-f]+$":
+        type: object
+
+        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
+
+        required:
+          - reg
+          - label
+
+        additionalProperties: false
+
+    additionalProperties: false
+
 required:
   - compatible
   - reg
@@ -42,6 +88,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 0x10000>; /* 32 MB */
+                };
+
+                partition@3400 {
+                    label = "rootfs";
+                    reg = <0x3400 0x200000>; /* 1GB */
+                };
+            };
+
+            partitions-boot0 {
+                #address-cells = <1>;
+                #size-cells = <1>;
+
+                partition@0 {
+                    label = "bl";
+                    reg = <0x0 0x10000>; /* 32MB */
+                    read-only;
+                };
+            };
         };
     };
 
Signature · 1 line
2.45.2
maintainer
#14 lore raw

Re: [RFC PATCH 4/4] dt-bindings: mmc: Document support for partition table in mmc-card

Quoted 6 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.

What if the partition table is written? What does one use? One of them or both and merge them?

Quoted 25 lines

eMMC provide a generic disk for user data and if supported also provide one or 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     | 75 +++++++++++++++++++
 1 file changed, 75 insertions(+)
Documentation/devicetree/bindings/mmc/mmc-card.yaml +4 -0
index fd347126449a..fab9fa5c170a 100644
@@ -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 39

Quoted 10 lines
Documentation/devicetree/bindings/mmc/mmc-card.yaml +7 -0
@@ -26,6 +30,48 @@ properties:
       Use this to indicate that the mmc-card has a broken hpi
       implementation, and that hpi should not be used.
 
+  "#address-cells": true
+
+  "#size-cells": true
+
+patternProperties:
+  "^partitions(-boot[01])?$":
+    type: object

You don't define this is fixed partitions with a fixed-partitions compatible. Why not reuse that? Then this all goes away with a reference to it.

Quoted 4 lines
Documentation/devicetree/bindings/mmc/mmc-card.yaml +4 -0
+
+    properties:
+      "#address-cells": true
+

Documentation/devicetree/bindings/mmc/mmc-card.yaml properties: · line 53

Quoted 10 lines
Documentation/devicetree/bindings/mmc/mmc-card.yaml +10 -0
+      "#size-cells": true
+
+    patternProperties:
+      "@[0-9a-f]+$":
+        type: object
+
+        properties:
+          reg:
+            description: partition's offset and size within the flash (in sector
+              block, 512byte)

Units are sectors? Use bytes instead because everything else does in DT.

Quoted 10 lines
Documentation/devicetree/bindings/mmc/mmc-card.yaml +10 -0
+            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

Documentation/devicetree/bindings/mmc/mmc-card.yaml properties: · line 73

Quoted 10 lines
Documentation/devicetree/bindings/mmc/mmc-card.yaml +10 -0
+              not be clobbered.
+            type: boolean
+
+        required:
+          - reg
+          - label
+
+        additionalProperties: false
+
+    additionalProperties: false

Put the indented cases of additionalProperties/unevaluatedProperties before 'properties'. Easier to see what they apply to that way.

Rob

#15 lore raw

Re: [RFC PATCH 4/4] dt-bindings: mmc: Document support for partition table in mmc-card

Quoted 11 lines · Rob Herring
Quoted 6 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.

What if the partition table is written? What does one use? One of them or both and merge them?

Hi Rob,
thanks a lot for the review!

The block code parse partition table with some kind of priority system.

Example if cmdline is found, then anything else is ignored. (simple logic, first parser that match an expected structure win)

We apply the same logic. So with partition table defined in OF, then anything written will be ignored.

Quoted 28 lines
Quoted 28 lines

eMMC provide a generic disk for user data and if supported also provide one or 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     | 75 +++++++++++++++++++
 1 file changed, 75 insertions(+)
Documentation/devicetree/bindings/mmc/mmc-card.yaml +4 -0
index fd347126449a..fab9fa5c170a 100644
@@ -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,48 @@ properties:
       Use this to indicate that the mmc-card has a broken hpi
       implementation, and that hpi should not be used.
 
Quoted 12 lines

Documentation/devicetree/bindings/mmc/mmc-card.yaml properties: · line 39

Quoted 7 lines
Documentation/devicetree/bindings/mmc/mmc-card.yaml +7 -0
+  "#address-cells": true
+
+  "#size-cells": true
+
+patternProperties:
+  "^partitions(-boot[01])?$":
+    type: object

You don't define this is fixed partitions with a fixed-partitions compatible. Why not reuse that? Then this all goes away with a reference to it.

My problem is that the fixed-partition schema in MTD have some additional property that can't be supported.

Ideally I should define a generic schema that can be shared and then expand it in MTD. Any hint on the directory structure tho?

Where should I put this generic schema?

Quoted 8 lines
Quoted 8 lines
Documentation/devicetree/bindings/mmc/mmc-card.yaml +8 -0
+
+    properties:
+      "#address-cells": true
+
+      "#size-cells": true
+
+    patternProperties:
+      "@[0-9a-f]+$":
Quoted 9 lines

Documentation/devicetree/bindings/mmc/mmc-card.yaml properties: · line 53

Quoted 6 lines
Documentation/devicetree/bindings/mmc/mmc-card.yaml +6 -0
+        type: object
+
+        properties:
+          reg:
+            description: partition's offset and size within the flash (in sector
+              block, 512byte)

Units are sectors? Use bytes instead because everything else does in DT.

Ok will try to convert value to bytes internally.

Quoted 15 lines
Quoted 15 lines
Documentation/devicetree/bindings/mmc/mmc-card.yaml +15 -0
+            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
+
+        required:
+          - reg
Quoted 9 lines

Documentation/devicetree/bindings/mmc/mmc-card.yaml properties: · line 73

Quoted 5 lines
Documentation/devicetree/bindings/mmc/mmc-card.yaml +5 -0
+          - label
+
+        additionalProperties: false
+
+    additionalProperties: false

Put the indented cases of additionalProperties/unevaluatedProperties before 'properties'. Easier to see what they apply to that way.

ack.

Signature · 1 line
	Ansuel