devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v4 0/5] block: partition table OF support
@ 2024-09-30 11:30 Christian Marangi
  2024-09-30 11:30 ` [PATCH v4 1/5] block: add support for defining read-only partitions Christian Marangi
                   ` (5 more replies)
  0 siblings, 6 replies; 16+ messages in thread
From: Christian Marangi @ 2024-09-30 11:30 UTC (permalink / raw)
  To: Jens Axboe, Jonathan Corbet, Ulf Hansson, Rob Herring,
	Krzysztof Kozlowski, Conor Dooley, Kees Cook, Andy Shevchenko,
	Christian Marangi, Daniel Golle, INAGAKI Hiroshi,
	Christian Brauner, Al Viro, Li Lingfeng, Ming Lei,
	Christian Heusel, linux-block, linux-doc, linux-kernel, linux-mmc,
	devicetree, linux-hardening, Miquel Raynal, Lorenzo Bianconi,
	upstream

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 v4:
- Fix wrong description and title in Kconfig
- Validate reg len with addr and size cells
- Drop offset 0 constraint (not needed)
- Rework bytes to sector conversion
- Follow common logic with ignore partitions after state->limit
- Better handle device_node put
- Add suggested strends string helper
Changes v3:
- Out of RFC
- Drop partition schema generalization and simplify it
- Require fixed-partitions compatible to adapt to MTD schema
- Make label property optional and fallback to node name
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
  string: add strends() helper to check if a string ends with a suffix
  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     |  52 ++++++
 block/blk.h                                   |   1 +
 block/partitions/Kconfig                      |   9 ++
 block/partitions/Makefile                     |   1 +
 block/partitions/check.h                      |   1 +
 block/partitions/cmdline.c                    |   3 +
 block/partitions/core.c                       |   6 +
 block/partitions/of.c                         | 151 ++++++++++++++++++
 include/linux/string.h                        |  13 ++
 10 files changed, 241 insertions(+), 1 deletion(-)
 create mode 100644 block/partitions/of.c

-- 
2.45.2


^ permalink raw reply	[flat|nested] 16+ messages in thread

* [PATCH v4 1/5] block: add support for defining read-only partitions
  2024-09-30 11:30 [PATCH v4 0/5] block: partition table OF support Christian Marangi
@ 2024-09-30 11:30 ` Christian Marangi
  2024-09-30 11:30 ` [PATCH v4 2/5] docs: block: Document support for read-only partition in cmdline part Christian Marangi
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 16+ messages in thread
From: Christian Marangi @ 2024-09-30 11:30 UTC (permalink / raw)
  To: Jens Axboe, Jonathan Corbet, Ulf Hansson, Rob Herring,
	Krzysztof Kozlowski, Conor Dooley, Kees Cook, Andy Shevchenko,
	Christian Marangi, Daniel Golle, INAGAKI Hiroshi,
	Christian Brauner, Al Viro, Li Lingfeng, Ming Lei,
	Christian Heusel, linux-block, linux-doc, linux-kernel, linux-mmc,
	devicetree, linux-hardening, Miquel Raynal, Lorenzo Bianconi,
	upstream
  Cc: Christoph Hellwig

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.

Signed-off-by: Christian Marangi <ansuelsmth@gmail.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
---
 block/blk.h                | 1 +
 block/partitions/cmdline.c | 3 +++
 block/partitions/core.c    | 3 +++
 3 files changed, 7 insertions(+)

diff --git a/block/blk.h b/block/blk.h
index c718e4291db0..f300212d3e98 100644
--- a/block/blk.h
+++ b/block/blk.h
@@ -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);
diff --git a/block/partitions/cmdline.c b/block/partitions/cmdline.c
index 152c85df92b2..da3e719d8e51 100644
--- a/block/partitions/cmdline.c
+++ b/block/partitions/cmdline.c
@@ -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));
diff --git a/block/partitions/core.c b/block/partitions/core.c
index ab76e64f0f6c..abad6c83db8f 100644
--- a/block/partitions/core.c
+++ b/block/partitions/core.c
@@ -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)
-- 
2.45.2


^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [PATCH v4 2/5] docs: block: Document support for read-only partition in cmdline part
  2024-09-30 11:30 [PATCH v4 0/5] block: partition table OF support Christian Marangi
  2024-09-30 11:30 ` [PATCH v4 1/5] block: add support for defining read-only partitions Christian Marangi
@ 2024-09-30 11:30 ` Christian Marangi
  2024-09-30 11:30 ` [PATCH v4 3/5] string: add strends() helper to check if a string ends with a suffix Christian Marangi
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 16+ messages in thread
From: Christian Marangi @ 2024-09-30 11:30 UTC (permalink / raw)
  To: Jens Axboe, Jonathan Corbet, Ulf Hansson, Rob Herring,
	Krzysztof Kozlowski, Conor Dooley, Kees Cook, Andy Shevchenko,
	Christian Marangi, Daniel Golle, INAGAKI Hiroshi,
	Christian Brauner, Al Viro, Li Lingfeng, Ming Lei,
	Christian Heusel, linux-block, linux-doc, linux-kernel, linux-mmc,
	devicetree, linux-hardening, Miquel Raynal, Lorenzo Bianconi,
	upstream

Document support for read-only partition in cmdline partition for block
devices by appending "ro" after the (partition name).

Signed-off-by: Christian Marangi <ansuelsmth@gmail.com>
---
 Documentation/block/cmdline-partition.rst | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/Documentation/block/cmdline-partition.rst b/Documentation/block/cmdline-partition.rst
index 530bedff548a..526ba201dddc 100644
--- a/Documentation/block/cmdline-partition.rst
+++ b/Documentation/block/cmdline-partition.rst
@@ -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::
 
-- 
2.45.2


^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [PATCH v4 3/5] string: add strends() helper to check if a string ends with a suffix
  2024-09-30 11:30 [PATCH v4 0/5] block: partition table OF support Christian Marangi
  2024-09-30 11:30 ` [PATCH v4 1/5] block: add support for defining read-only partitions Christian Marangi
  2024-09-30 11:30 ` [PATCH v4 2/5] docs: block: Document support for read-only partition in cmdline part Christian Marangi
@ 2024-09-30 11:30 ` Christian Marangi
  2024-09-30 12:45   ` Andy Shevchenko
                     ` (2 more replies)
  2024-09-30 11:30 ` [PATCH v4 4/5] block: add support for partition table defined in OF Christian Marangi
                   ` (2 subsequent siblings)
  5 siblings, 3 replies; 16+ messages in thread
From: Christian Marangi @ 2024-09-30 11:30 UTC (permalink / raw)
  To: Jens Axboe, Jonathan Corbet, Ulf Hansson, Rob Herring,
	Krzysztof Kozlowski, Conor Dooley, Kees Cook, Andy Shevchenko,
	Christian Marangi, Daniel Golle, INAGAKI Hiroshi,
	Christian Brauner, Al Viro, Li Lingfeng, Ming Lei,
	Christian Heusel, linux-block, linux-doc, linux-kernel, linux-mmc,
	devicetree, linux-hardening, Miquel Raynal, Lorenzo Bianconi,
	upstream
  Cc: Rasmus Villemoes

Add strends() helper to check if a string ends with a suffix. The
unreadable strends is chosen to keep consistency with the parallel
strstarts helper used to check if a string starts with a prefix.

To prevent out-of-bounds read, len of string is checked against the
prefix length before comparing the 2 string at the offset.

Suggested-by: Rasmus Villemoes <linux@rasmusvillemoes.dk>
Signed-off-by: Christian Marangi <ansuelsmth@gmail.com>
---
 include/linux/string.h | 13 +++++++++++++
 1 file changed, 13 insertions(+)

diff --git a/include/linux/string.h b/include/linux/string.h
index 0dd27afcfaf7..2c3df6ffb326 100644
--- a/include/linux/string.h
+++ b/include/linux/string.h
@@ -353,6 +353,19 @@ static inline bool strstarts(const char *str, const char *prefix)
 	return strncmp(str, prefix, strlen(prefix)) == 0;
 }
 
+/**
+ * strends - does @str end with @suffix?
+ * @str: string to examine
+ * @suffix: suffix to look for.
+ */
+static inline bool strends(const char *str, const char *suffix)
+{
+	size_t n = strlen(str);
+	size_t m = strlen(suffix);
+
+	return n >= m && !memcmp(str + n - m, suffix, m);
+}
+
 size_t memweight(const void *ptr, size_t bytes);
 
 /**
-- 
2.45.2


^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [PATCH v4 4/5] block: add support for partition table defined in OF
  2024-09-30 11:30 [PATCH v4 0/5] block: partition table OF support Christian Marangi
                   ` (2 preceding siblings ...)
  2024-09-30 11:30 ` [PATCH v4 3/5] string: add strends() helper to check if a string ends with a suffix Christian Marangi
@ 2024-09-30 11:30 ` Christian Marangi
  2024-09-30 12:49   ` Andy Shevchenko
  2024-09-30 11:30 ` [PATCH v4 5/5] dt-bindings: mmc: Document support for partition table in mmc-card Christian Marangi
  2024-09-30 12:54 ` [PATCH v4 0/5] block: partition table OF support Andy Shevchenko
  5 siblings, 1 reply; 16+ messages in thread
From: Christian Marangi @ 2024-09-30 11:30 UTC (permalink / raw)
  To: Jens Axboe, Jonathan Corbet, Ulf Hansson, Rob Herring,
	Krzysztof Kozlowski, Conor Dooley, Kees Cook, Andy Shevchenko,
	Christian Marangi, Daniel Golle, INAGAKI Hiroshi,
	Christian Brauner, Al Viro, Li Lingfeng, Ming Lei,
	Christian Heusel, linux-block, linux-doc, linux-kernel, linux-mmc,
	devicetree, linux-hardening, Miquel Raynal, Lorenzo Bianconi,
	upstream

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 with
"fixed-partitions" compatible 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. If label is not declared, the node name
is used as fallback. 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.

Signed-off-by: Christian Marangi <ansuelsmth@gmail.com>
---
 block/partitions/Kconfig  |   9 +++
 block/partitions/Makefile |   1 +
 block/partitions/check.h  |   1 +
 block/partitions/core.c   |   3 +
 block/partitions/of.c     | 151 ++++++++++++++++++++++++++++++++++++++
 5 files changed, 165 insertions(+)
 create mode 100644 block/partitions/of.c

diff --git a/block/partitions/Kconfig b/block/partitions/Kconfig
index 7aff4eb81c60..ce17e41451af 100644
--- a/block/partitions/Kconfig
+++ b/block/partitions/Kconfig
@@ -270,4 +270,13 @@ 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 "Device Tree 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 device tree node is just like MTD fixed-partition
+	  schema.
+
 endmenu
diff --git a/block/partitions/Makefile b/block/partitions/Makefile
index a7f05cdb02a8..25d424922c6e 100644
--- a/block/partitions/Makefile
+++ b/block/partitions/Makefile
@@ -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
diff --git a/block/partitions/check.h b/block/partitions/check.h
index 8d70a880c372..e5c1c61eb353 100644
--- a/block/partitions/check.h
+++ b/block/partitions/check.h
@@ -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);
diff --git a/block/partitions/core.c b/block/partitions/core.c
index abad6c83db8f..dc21734b00ec 100644
--- a/block/partitions/core.c
+++ b/block/partitions/core.c
@@ -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
diff --git a/block/partitions/of.c b/block/partitions/of.c
new file mode 100644
index 000000000000..d5b53f00af5c
--- /dev/null
+++ b/block/partitions/of.c
@@ -0,0 +1,151 @@
+// SPDX-License-Identifier: GPL-2.0
+
+#include <linux/blkdev.h>
+#include <linux/major.h>
+#include <linux/of.h>
+#include <linux/string.h>
+#include "check.h"
+
+static struct device_node *get_partitions_node(struct device_node *disk_np,
+					       struct gendisk *disk)
+{
+	const char *node_name = "partitions";
+
+	/*
+	 * JEDEC specification 4.4 for eMMC introduced 3 additional partition
+	 * present on every eMMC. These additional partition are always hardcoded
+	 * from the eMMC driver as boot0, boot1 and rpmb. While rpmb is used to
+	 * store keys and exposed as a char device, the other 2 are exposed as
+	 * real separate disk with the boot0/1 appended to the disk name.
+	 *
+	 * Here we parse the disk_name in search for such suffix and select
+	 * the correct partition node.
+	 */
+	if (disk->major == MMC_BLOCK_MAJOR) {
+		const char *disk_name = disk->disk_name;
+
+		if (strends(disk_name, "boot0"))
+			node_name = "partitions-boot0";
+		if (strends(disk_name, "boot1"))
+			node_name = "partitions-boot1";
+	}
+
+	return of_get_child_by_name(disk_np, node_name);
+}
+
+static int validate_of_partition(struct device_node *np, int slot)
+{
+	int a_cells, s_cells;
+	const __be32 *reg;
+	u64 offset, size;
+	int len;
+
+	reg = of_get_property(np, "reg", &len);
+
+	a_cells = of_n_addr_cells(np);
+	s_cells = of_n_size_cells(np);
+
+	/* Make sure reg len match the expected addr and size cells */
+	if (len / sizeof(*reg) != a_cells + s_cells)
+		return -EINVAL;
+
+	/* Validate offset conversion from bytes to sectors */
+	offset = of_read_number(reg, a_cells);
+	if (offset % SECTOR_SIZE)
+		return -EINVAL;
+
+	/* Validate size conversion from bytes to sectors */
+	size = of_read_number(reg + a_cells, s_cells);
+	if (!size || size % SECTOR_SIZE)
+		return -EINVAL;
+
+	return 0;
+}
+
+static void add_of_partition(struct parsed_partitions *state, int slot,
+			     struct device_node *np)
+{
+	struct partition_meta_info *info;
+	char tmp[sizeof(info->volname) + 4];
+	int a_cells, s_cells;
+	const char *partname;
+	const __be32 *reg;
+	u64 offset, size;
+	int len;
+
+	reg = of_get_property(np, "reg", &len);
+
+	a_cells = of_n_addr_cells(np);
+	s_cells = of_n_size_cells(np);
+
+	/* Convert bytes to sector size */
+	offset = of_read_number(reg, a_cells) / SECTOR_SIZE;
+	size = of_read_number(reg + a_cells, s_cells) / SECTOR_SIZE;
+
+	put_partition(state, slot, offset, size);
+
+	if (of_property_read_bool(np, "read-only"))
+		state->parts[slot].flags |= ADDPART_FLAG_READONLY;
+
+	/*
+	 * Follow MTD label logic, search for label property,
+	 * fallback to node name if not found.
+	 */
+	info = &state->parts[slot].info;
+	partname = of_get_property(np, "label", &len);
+	if (!partname)
+		partname = of_get_property(np, "name", &len);
+	strscpy(info->volname, partname, sizeof(info->volname));
+
+	snprintf(tmp, sizeof(tmp), "(%s)", info->volname);
+	strlcat(state->pp_buf, tmp, PAGE_SIZE);
+}
+
+int of_partition(struct parsed_partitions *state)
+{
+	struct device_node *disk_np, *partitions_np, *np;
+	struct device *ddev = disk_to_dev(state->disk);
+	int slot, ret = 1;
+
+	disk_np = of_node_get(ddev->parent->of_node);
+	if (!disk_np)
+		return 0;
+
+	partitions_np = get_partitions_node(disk_np, state->disk);
+	if (!partitions_np ||
+	    !of_device_is_compatible(partitions_np, "fixed-partitions")) {
+		of_node_put(disk_np);
+		return 0;
+	}
+
+	slot = 1;
+	/* Validate parition offset and size */
+	for_each_child_of_node(partitions_np, np) {
+		if (validate_of_partition(np, slot)) {
+			of_node_put(np);
+			ret = -1;
+			goto exit;
+		}
+
+		slot++;
+	}
+
+	slot = 1;
+	for_each_child_of_node(partitions_np, np) {
+		if (slot >= state->limit) {
+			of_node_put(np);
+			break;
+		}
+
+		add_of_partition(state, slot, np);
+
+		slot++;
+	}
+
+	strlcat(state->pp_buf, "\n", PAGE_SIZE);
+
+exit:
+	of_node_put(partitions_np);
+	of_node_put(disk_np);
+	return ret;
+}
-- 
2.45.2


^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [PATCH v4 5/5] dt-bindings: mmc: Document support for partition table in mmc-card
  2024-09-30 11:30 [PATCH v4 0/5] block: partition table OF support Christian Marangi
                   ` (3 preceding siblings ...)
  2024-09-30 11:30 ` [PATCH v4 4/5] block: add support for partition table defined in OF Christian Marangi
@ 2024-09-30 11:30 ` Christian Marangi
  2024-09-30 12:18   ` Rasmus Villemoes
  2024-09-30 12:54 ` [PATCH v4 0/5] block: partition table OF support Andy Shevchenko
  5 siblings, 1 reply; 16+ messages in thread
From: Christian Marangi @ 2024-09-30 11:30 UTC (permalink / raw)
  To: Jens Axboe, Jonathan Corbet, Ulf Hansson, Rob Herring,
	Krzysztof Kozlowski, Conor Dooley, Kees Cook, Andy Shevchenko,
	Christian Marangi, Daniel Golle, INAGAKI Hiroshi,
	Christian Brauner, Al Viro, Li Lingfeng, Ming Lei,
	Christian Heusel, linux-block, linux-doc, linux-kernel, linux-mmc,
	devicetree, linux-hardening, Miquel Raynal, Lorenzo Bianconi,
	upstream

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 <ansuelsmth@gmail.com>
---
 .../devicetree/bindings/mmc/mmc-card.yaml     | 52 +++++++++++++++++++
 1 file changed, 52 insertions(+)

diff --git a/Documentation/devicetree/bindings/mmc/mmc-card.yaml b/Documentation/devicetree/bindings/mmc/mmc-card.yaml
index fd347126449a..5f93bb77f246 100644
--- a/Documentation/devicetree/bindings/mmc/mmc-card.yaml
+++ b/Documentation/devicetree/bindings/mmc/mmc-card.yaml
@@ -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,24 @@ properties:
       Use this to indicate that the mmc-card has a broken hpi
       implementation, and that hpi should not be used.
 
+patternProperties:
+  "^partitions(-boot[01])?$":
+    $ref: /schemas/mtd/partitions/partitions.yaml
+
+    patternProperties:
+      "^partition@[0-9a-f]+$":
+        $ref: /schemas/mtd/partitions/partition.yaml
+
+        properties:
+          reg:
+            description: Must be multiple of 512 as it's converted
+              internally from bytes to SECTOR_SIZE (512 bytes)
+
+        required:
+          - reg
+
+        unevaluatedProperties: false
+
 required:
   - compatible
   - reg
@@ -42,6 +64,36 @@ examples:
             compatible = "mmc-card";
             reg = <0>;
             broken-hpi;
+
+            partitions {
+                compatible = "fixed-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 {
+                compatible = "fixed-partitions";
+
+                #address-cells = <1>;
+                #size-cells = <1>;
+
+                partition@0 {
+                    label = "bl";
+                    reg = <0x0 0x2000000>; /* 32MB */
+                    read-only;
+                };
+            };
         };
     };
 
-- 
2.45.2


^ permalink raw reply related	[flat|nested] 16+ messages in thread

* Re: [PATCH v4 5/5] dt-bindings: mmc: Document support for partition table in mmc-card
  2024-09-30 11:30 ` [PATCH v4 5/5] dt-bindings: mmc: Document support for partition table in mmc-card Christian Marangi
@ 2024-09-30 12:18   ` Rasmus Villemoes
  2024-09-30 12:22     ` Christian Marangi
  0 siblings, 1 reply; 16+ messages in thread
From: Rasmus Villemoes @ 2024-09-30 12:18 UTC (permalink / raw)
  To: Christian Marangi
  Cc: Jens Axboe, Jonathan Corbet, Ulf Hansson, Rob Herring,
	Krzysztof Kozlowski, Conor Dooley, Kees Cook, Andy Shevchenko,
	Daniel Golle, INAGAKI Hiroshi, Christian Brauner, Al Viro,
	Li Lingfeng, Ming Lei, Christian Heusel, linux-block, linux-doc,
	linux-kernel, linux-mmc, devicetree, linux-hardening,
	Miquel Raynal, Lorenzo Bianconi, upstream

Christian Marangi <ansuelsmth@gmail.com> writes:

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

This looks quite useful.

Could this be extended to also be applicable to the four "general
purpose" hardware partitions, i.e. what is exposed as /dev/mmcblkXgpY ?
These would often also contain some fundamental boot data at various
offsets but also, as for the boot partitions, often without a regular
partition table.

The eMMC spec consistently refers to the boot partitions as "boot
partition 1" and "boot partition 2"; the boot0/boot1 naming is kind of a
linux'ism. Similarly, the general purpose partitions are _almost_
exclusively referred to as 1 through 4, except (at least in my copy),
the heading for 7.4.89 says GP_SIZE_MULT_GP0 - GP_SIZE_MULT_GP3, but
then goes on to describe GP_SIZE_MULT_1_y through GP_SIZE_MULT_4_y. So I
wonder if on the binding level one should use partitions-{boot1,boot2}
and, if implemented, partitions-{gp1,gp2,gp3,gp4} ?

Rasmus

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH v4 5/5] dt-bindings: mmc: Document support for partition table in mmc-card
  2024-09-30 12:18   ` Rasmus Villemoes
@ 2024-09-30 12:22     ` Christian Marangi
  2024-09-30 14:00       ` Rasmus Villemoes
  0 siblings, 1 reply; 16+ messages in thread
From: Christian Marangi @ 2024-09-30 12:22 UTC (permalink / raw)
  To: Rasmus Villemoes
  Cc: Jens Axboe, Jonathan Corbet, Ulf Hansson, Rob Herring,
	Krzysztof Kozlowski, Conor Dooley, Kees Cook, Andy Shevchenko,
	Daniel Golle, INAGAKI Hiroshi, Christian Brauner, Al Viro,
	Li Lingfeng, Ming Lei, Christian Heusel, linux-block, linux-doc,
	linux-kernel, linux-mmc, devicetree, linux-hardening,
	Miquel Raynal, Lorenzo Bianconi, upstream

On Mon, Sep 30, 2024 at 02:18:14PM +0200, Rasmus Villemoes wrote:
> Christian Marangi <ansuelsmth@gmail.com> writes:
> 
> > 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.
> >
> 
> This looks quite useful.
> 
> Could this be extended to also be applicable to the four "general
> purpose" hardware partitions, i.e. what is exposed as /dev/mmcblkXgpY ?
> These would often also contain some fundamental boot data at various
> offsets but also, as for the boot partitions, often without a regular
> partition table.
> 
> The eMMC spec consistently refers to the boot partitions as "boot
> partition 1" and "boot partition 2"; the boot0/boot1 naming is kind of a
> linux'ism. Similarly, the general purpose partitions are _almost_
> exclusively referred to as 1 through 4, except (at least in my copy),
> the heading for 7.4.89 says GP_SIZE_MULT_GP0 - GP_SIZE_MULT_GP3, but
> then goes on to describe GP_SIZE_MULT_1_y through GP_SIZE_MULT_4_y. So I
> wonder if on the binding level one should use partitions-{boot1,boot2}
> and, if implemented, partitions-{gp1,gp2,gp3,gp4} ?
>

Just to make sure, they are exposed as disk or char device? This is the
case of rpmb.

Adding support for this should be no-brainer as it's just a matter of
more case of the strends and more regex case on the binding.

I also notice the conflicting names, to adapt to JEDEC naming I will rename
the property to boot1 and boot2.

-- 
	Ansuel

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH v4 3/5] string: add strends() helper to check if a string ends with a suffix
  2024-09-30 11:30 ` [PATCH v4 3/5] string: add strends() helper to check if a string ends with a suffix Christian Marangi
@ 2024-09-30 12:45   ` Andy Shevchenko
  2024-10-01 14:33   ` kernel test robot
  2024-10-01 21:47   ` kernel test robot
  2 siblings, 0 replies; 16+ messages in thread
From: Andy Shevchenko @ 2024-09-30 12:45 UTC (permalink / raw)
  To: Christian Marangi
  Cc: Jens Axboe, Jonathan Corbet, Ulf Hansson, Rob Herring,
	Krzysztof Kozlowski, Conor Dooley, Kees Cook, Daniel Golle,
	INAGAKI Hiroshi, Christian Brauner, Al Viro, Li Lingfeng,
	Ming Lei, Christian Heusel, linux-block, linux-doc, linux-kernel,
	linux-mmc, devicetree, linux-hardening, Miquel Raynal,
	Lorenzo Bianconi, upstream, Rasmus Villemoes

On Mon, Sep 30, 2024 at 01:30:10PM +0200, Christian Marangi wrote:
> Add strends() helper to check if a string ends with a suffix. The
> unreadable strends is chosen to keep consistency with the parallel
> strstarts helper used to check if a string starts with a prefix.

strstarts()

> To prevent out-of-bounds read, len of string is checked against the
> prefix length before comparing the 2 string at the offset.

...

> +/**
> + * strends - does @str end with @suffix?
> + * @str: string to examine
> + * @suffix: suffix to look for.

Please, run kernel doc validator

	scripts/kernel-doc -Wall -none ...

and fix the warning.

> + */

-- 
With Best Regards,
Andy Shevchenko



^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH v4 4/5] block: add support for partition table defined in OF
  2024-09-30 11:30 ` [PATCH v4 4/5] block: add support for partition table defined in OF Christian Marangi
@ 2024-09-30 12:49   ` Andy Shevchenko
  0 siblings, 0 replies; 16+ messages in thread
From: Andy Shevchenko @ 2024-09-30 12:49 UTC (permalink / raw)
  To: Christian Marangi
  Cc: Jens Axboe, Jonathan Corbet, Ulf Hansson, Rob Herring,
	Krzysztof Kozlowski, Conor Dooley, Kees Cook, Daniel Golle,
	INAGAKI Hiroshi, Christian Brauner, Al Viro, Li Lingfeng,
	Ming Lei, Christian Heusel, linux-block, linux-doc, linux-kernel,
	linux-mmc, devicetree, linux-hardening, Miquel Raynal,
	Lorenzo Bianconi, upstream

On Mon, Sep 30, 2024 at 01:30:11PM +0200, Christian Marangi wrote:
> 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 with
> "fixed-partitions" compatible 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. If label is not declared, the node name
> is used as fallback. 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.

...

> +	strscpy(info->volname, partname, sizeof(info->volname));

We have 2-arguments strscpy(), please use that.

> +	strlcat(state->pp_buf, tmp, PAGE_SIZE);

In new code we should not use strl*(). They are subject to remove.
And actually why? You have used strscpy() a few lines above...

...

> +	for_each_child_of_node(partitions_np, np) {

Use _scoped() variant.

> +		if (validate_of_partition(np, slot)) {
> +			of_node_put(np);
> +			ret = -1;
> +			goto exit;
> +		}
> +
> +		slot++;
> +	}

...

> +	for_each_child_of_node(partitions_np, np) {

Ditto.

> +		if (slot >= state->limit) {
> +			of_node_put(np);
> +			break;
> +		}
> +
> +		add_of_partition(state, slot, np);
> +
> +		slot++;
> +	}

...

> +	strlcat(state->pp_buf, "\n", PAGE_SIZE);

Why strl*()?

-- 
With Best Regards,
Andy Shevchenko



^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH v4 0/5] block: partition table OF support
  2024-09-30 11:30 [PATCH v4 0/5] block: partition table OF support Christian Marangi
                   ` (4 preceding siblings ...)
  2024-09-30 11:30 ` [PATCH v4 5/5] dt-bindings: mmc: Document support for partition table in mmc-card Christian Marangi
@ 2024-09-30 12:54 ` Andy Shevchenko
  2024-10-02  9:20   ` Rasmus Villemoes
  5 siblings, 1 reply; 16+ messages in thread
From: Andy Shevchenko @ 2024-09-30 12:54 UTC (permalink / raw)
  To: Christian Marangi
  Cc: Jens Axboe, Jonathan Corbet, Ulf Hansson, Rob Herring,
	Krzysztof Kozlowski, Conor Dooley, Kees Cook, Daniel Golle,
	INAGAKI Hiroshi, Christian Brauner, Al Viro, Li Lingfeng,
	Ming Lei, Christian Heusel, linux-block, linux-doc, linux-kernel,
	linux-mmc, devicetree, linux-hardening, Miquel Raynal,
	Lorenzo Bianconi, upstream

On Mon, Sep 30, 2024 at 01:30:07PM +0200, Christian Marangi wrote:
> 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.


I'm not sure I fully understood the problem you are trying to solve.
I have a device at hand that uses eMMC (and was produced almost ten years ago).
This device has a regular GPT on eMMC and no kernel needs to be patched for that.
So, why is it a problem for the mentioned OEMs to use standard GPT approach?

-- 
With Best Regards,
Andy Shevchenko



^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH v4 5/5] dt-bindings: mmc: Document support for partition table in mmc-card
  2024-09-30 12:22     ` Christian Marangi
@ 2024-09-30 14:00       ` Rasmus Villemoes
  0 siblings, 0 replies; 16+ messages in thread
From: Rasmus Villemoes @ 2024-09-30 14:00 UTC (permalink / raw)
  To: Christian Marangi
  Cc: Rasmus Villemoes, Jens Axboe, Jonathan Corbet, Ulf Hansson,
	Rob Herring, Krzysztof Kozlowski, Conor Dooley, Kees Cook,
	Andy Shevchenko, Daniel Golle, INAGAKI Hiroshi, Christian Brauner,
	Al Viro, Li Lingfeng, Ming Lei, Christian Heusel, linux-block,
	linux-doc, linux-kernel, linux-mmc, devicetree, linux-hardening,
	Miquel Raynal, Lorenzo Bianconi, upstream

Christian Marangi <ansuelsmth@gmail.com> writes:

> On Mon, Sep 30, 2024 at 02:18:14PM +0200, Rasmus Villemoes wrote:
>> Christian Marangi <ansuelsmth@gmail.com> writes:
>> 
>> > 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.
>> >
>> 
>> This looks quite useful.
>> 
>> Could this be extended to also be applicable to the four "general
>> purpose" hardware partitions, i.e. what is exposed as /dev/mmcblkXgpY ?
>> These would often also contain some fundamental boot data at various
>> offsets but also, as for the boot partitions, often without a regular
>> partition table.
>> 
>> The eMMC spec consistently refers to the boot partitions as "boot
>> partition 1" and "boot partition 2"; the boot0/boot1 naming is kind of a
>> linux'ism. Similarly, the general purpose partitions are _almost_
>> exclusively referred to as 1 through 4, except (at least in my copy),
>> the heading for 7.4.89 says GP_SIZE_MULT_GP0 - GP_SIZE_MULT_GP3, but
>> then goes on to describe GP_SIZE_MULT_1_y through GP_SIZE_MULT_4_y. So I
>> wonder if on the binding level one should use partitions-{boot1,boot2}
>> and, if implemented, partitions-{gp1,gp2,gp3,gp4} ?
>>
>
> Just to make sure, they are exposed as disk or char device? This is the
> case of rpmb.
>

They are block devices, just as the so-called "user area" (the main
mmcblkX) and the boot partitions.

> Adding support for this should be no-brainer as it's just a matter of
> more case of the strends and more regex case on the binding.

Yes, that's what I thought as well.

> I also notice the conflicting names, to adapt to JEDEC naming I will rename
> the property to boot1 and boot2.

Thanks,
Rasmus

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH v4 3/5] string: add strends() helper to check if a string ends with a suffix
  2024-09-30 11:30 ` [PATCH v4 3/5] string: add strends() helper to check if a string ends with a suffix Christian Marangi
  2024-09-30 12:45   ` Andy Shevchenko
@ 2024-10-01 14:33   ` kernel test robot
  2024-10-01 21:47   ` kernel test robot
  2 siblings, 0 replies; 16+ messages in thread
From: kernel test robot @ 2024-10-01 14:33 UTC (permalink / raw)
  To: Christian Marangi, Jens Axboe, Jonathan Corbet, Ulf Hansson,
	Rob Herring, Krzysztof Kozlowski, Conor Dooley, Kees Cook,
	Andy Shevchenko, Daniel Golle, INAGAKI Hiroshi, Christian Brauner,
	Al Viro, Li Lingfeng, Ming Lei, Christian Heusel, linux-block,
	linux-doc, linux-kernel, linux-mmc, devicetree, linux-hardening,
	Miquel Raynal, Lorenzo Bianconi, upstream
  Cc: oe-kbuild-all, Rasmus Villemoes

Hi Christian,

kernel test robot noticed the following build errors:

[auto build test ERROR on axboe-block/for-next]
[also build test ERROR on kees/for-next/hardening robh/for-next lwn/docs-next linus/master v6.12-rc1 next-20241001]
[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/20240930-193609
base:   https://git.kernel.org/pub/scm/linux/kernel/git/axboe/linux-block.git for-next
patch link:    https://lore.kernel.org/r/20240930113045.28616-4-ansuelsmth%40gmail.com
patch subject: [PATCH v4 3/5] string: add strends() helper to check if a string ends with a suffix
config: s390-randconfig-001-20241001 (https://download.01.org/0day-ci/archive/20241001/202410012202.g0GogVZR-lkp@intel.com/config)
compiler: s390-linux-gcc (GCC) 14.1.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20241001/202410012202.g0GogVZR-lkp@intel.com/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 <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202410012202.g0GogVZR-lkp@intel.com/

All errors (new ones prefixed by >>):

   In file included from arch/s390/purgatory/../lib/string.c:16,
                    from arch/s390/purgatory/string.c:3:
   include/linux/string.h: In function 'strends':
>> include/linux/string.h:366:27: error: implicit declaration of function 'memcmp' [-Wimplicit-function-declaration]
     366 |         return n >= m && !memcmp(str + n - m, suffix, m);
         |                           ^~~~~~
   include/linux/string.h:65:1: note: 'memcmp' is defined in header '<string.h>'; this is probably fixable by adding '#include <string.h>'
      64 | #include <asm/string.h>
     +++ |+#include <string.h>
      65 | 


vim +/memcmp +366 include/linux/string.h

   355	
   356	/**
   357	 * strends - does @str end with @suffix?
   358	 * @str: string to examine
   359	 * @suffix: suffix to look for.
   360	 */
   361	static inline bool strends(const char *str, const char *suffix)
   362	{
   363		size_t n = strlen(str);
   364		size_t m = strlen(suffix);
   365	
 > 366		return n >= m && !memcmp(str + n - m, suffix, m);
   367	}
   368	

-- 
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH v4 3/5] string: add strends() helper to check if a string ends with a suffix
  2024-09-30 11:30 ` [PATCH v4 3/5] string: add strends() helper to check if a string ends with a suffix Christian Marangi
  2024-09-30 12:45   ` Andy Shevchenko
  2024-10-01 14:33   ` kernel test robot
@ 2024-10-01 21:47   ` kernel test robot
  2 siblings, 0 replies; 16+ messages in thread
From: kernel test robot @ 2024-10-01 21:47 UTC (permalink / raw)
  To: Christian Marangi, Jens Axboe, Jonathan Corbet, Ulf Hansson,
	Rob Herring, Krzysztof Kozlowski, Conor Dooley, Kees Cook,
	Andy Shevchenko, Daniel Golle, INAGAKI Hiroshi, Christian Brauner,
	Al Viro, Li Lingfeng, Ming Lei, Christian Heusel, linux-block,
	linux-doc, linux-kernel, linux-mmc, devicetree, linux-hardening,
	Miquel Raynal, Lorenzo Bianconi, upstream
  Cc: oe-kbuild-all, Rasmus Villemoes

Hi Christian,

kernel test robot noticed the following build errors:

[auto build test ERROR on axboe-block/for-next]
[also build test ERROR on kees/for-next/hardening robh/for-next lwn/docs-next linus/master v6.12-rc1 next-20241001]
[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/20240930-193609
base:   https://git.kernel.org/pub/scm/linux/kernel/git/axboe/linux-block.git for-next
patch link:    https://lore.kernel.org/r/20240930113045.28616-4-ansuelsmth%40gmail.com
patch subject: [PATCH v4 3/5] string: add strends() helper to check if a string ends with a suffix
config: s390-randconfig-r061-20241001 (https://download.01.org/0day-ci/archive/20241002/202410020546.DL6BnsOs-lkp@intel.com/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/20241002/202410020546.DL6BnsOs-lkp@intel.com/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 <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202410020546.DL6BnsOs-lkp@intel.com/

All errors (new ones prefixed by >>):

   In file included from arch/s390/purgatory/string.c:3:
   In file included from arch/s390/purgatory/../lib/string.c:16:
>> include/linux/string.h:366:20: error: call to undeclared function 'memcmp'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
     366 |         return n >= m && !memcmp(str + n - m, suffix, m);
         |                           ^
   1 error generated.


vim +/memcmp +366 include/linux/string.h

   355	
   356	/**
   357	 * strends - does @str end with @suffix?
   358	 * @str: string to examine
   359	 * @suffix: suffix to look for.
   360	 */
   361	static inline bool strends(const char *str, const char *suffix)
   362	{
   363		size_t n = strlen(str);
   364		size_t m = strlen(suffix);
   365	
 > 366		return n >= m && !memcmp(str + n - m, suffix, m);
   367	}
   368	

-- 
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH v4 0/5] block: partition table OF support
  2024-09-30 12:54 ` [PATCH v4 0/5] block: partition table OF support Andy Shevchenko
@ 2024-10-02  9:20   ` Rasmus Villemoes
  2024-10-03  9:59     ` Andy Shevchenko
  0 siblings, 1 reply; 16+ messages in thread
From: Rasmus Villemoes @ 2024-10-02  9:20 UTC (permalink / raw)
  To: Andy Shevchenko
  Cc: Christian Marangi, Jens Axboe, Jonathan Corbet, Ulf Hansson,
	Rob Herring, Krzysztof Kozlowski, Conor Dooley, Kees Cook,
	Daniel Golle, INAGAKI Hiroshi, Christian Brauner, Al Viro,
	Li Lingfeng, Ming Lei, Christian Heusel, linux-block, linux-doc,
	linux-kernel, linux-mmc, devicetree, linux-hardening,
	Miquel Raynal, Lorenzo Bianconi, upstream

Andy Shevchenko <andy@kernel.org> writes:

> On Mon, Sep 30, 2024 at 01:30:07PM +0200, Christian Marangi wrote:
>> Hi,
>> this is an initial proposal to complete support for manually defining
>> partition table.
>> 
>> 
>> 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.
>
>
> I'm not sure I fully understood the problem you are trying to solve.
> I have a device at hand that uses eMMC (and was produced almost ten years ago).
> This device has a regular GPT on eMMC and no kernel needs to be patched for that.
> So, why is it a problem for the mentioned OEMs to use standard GPT approach?

For the user area (main block device), yes, a GPT can often be used, but
not always. For the boot partitions, the particular SOC/cpu/bootrom may
make it impossible to use a standard partition table, because the
bootrom expects to find a bootloader at offset 0 on the active boot
partition. In such a case, there's no way you can write a regular MBR or
GPT, but it is nevertheless nice to have a machine-readable definition
of which data goes where in the boot partitions. With these patches, one
can do

  partitions-boot0 {
    partition@0 {
      label = "bootloader";
      reg = <0 0x...>; // 2 MB
    }
    partition@... {
      label = "device-data";
      reg = <...> // 4 MB
    }
  }

and describe that layout.

Rasmus

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH v4 0/5] block: partition table OF support
  2024-10-02  9:20   ` Rasmus Villemoes
@ 2024-10-03  9:59     ` Andy Shevchenko
  0 siblings, 0 replies; 16+ messages in thread
From: Andy Shevchenko @ 2024-10-03  9:59 UTC (permalink / raw)
  To: Rasmus Villemoes
  Cc: Christian Marangi, Jens Axboe, Jonathan Corbet, Ulf Hansson,
	Rob Herring, Krzysztof Kozlowski, Conor Dooley, Kees Cook,
	Daniel Golle, INAGAKI Hiroshi, Christian Brauner, Al Viro,
	Li Lingfeng, Ming Lei, Christian Heusel, linux-block, linux-doc,
	linux-kernel, linux-mmc, devicetree, linux-hardening,
	Miquel Raynal, Lorenzo Bianconi, upstream

On Wed, Oct 02, 2024 at 11:20:37AM +0200, Rasmus Villemoes wrote:
> Andy Shevchenko <andy@kernel.org> writes:
> > On Mon, Sep 30, 2024 at 01:30:07PM +0200, Christian Marangi wrote:

...

> >> this is an initial proposal to complete support for manually defining
> >> partition table.
> >> 
> >> 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.
> >
> > I'm not sure I fully understood the problem you are trying to solve.
> > I have a device at hand that uses eMMC (and was produced almost ten years ago).
> > This device has a regular GPT on eMMC and no kernel needs to be patched for that.
> > So, why is it a problem for the mentioned OEMs to use standard GPT approach?
> 
> For the user area (main block device), yes, a GPT can often be used, but
> not always. For the boot partitions, the particular SOC/cpu/bootrom may
> make it impossible to use a standard partition table, because the
> bootrom expects to find a bootloader at offset 0 on the active boot
> partition. In such a case, there's no way you can write a regular MBR or
> GPT, but it is nevertheless nice to have a machine-readable definition
> of which data goes where in the boot partitions. With these patches, one
> can do
> 
>   partitions-boot0 {
>     partition@0 {
>       label = "bootloader";
>       reg = <0 0x...>; // 2 MB
>     }
>     partition@... {
>       label = "device-data";
>       reg = <...> // 4 MB
>     }
>   }
> 
> and describe that layout.

I see now, on the device I mentioned the firmware is located on a boot
partition, so the user ones are being used for bootloader and the OS.

-- 
With Best Regards,
Andy Shevchenko



^ permalink raw reply	[flat|nested] 16+ messages in thread

end of thread, other threads:[~2024-10-03  9:59 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-09-30 11:30 [PATCH v4 0/5] block: partition table OF support Christian Marangi
2024-09-30 11:30 ` [PATCH v4 1/5] block: add support for defining read-only partitions Christian Marangi
2024-09-30 11:30 ` [PATCH v4 2/5] docs: block: Document support for read-only partition in cmdline part Christian Marangi
2024-09-30 11:30 ` [PATCH v4 3/5] string: add strends() helper to check if a string ends with a suffix Christian Marangi
2024-09-30 12:45   ` Andy Shevchenko
2024-10-01 14:33   ` kernel test robot
2024-10-01 21:47   ` kernel test robot
2024-09-30 11:30 ` [PATCH v4 4/5] block: add support for partition table defined in OF Christian Marangi
2024-09-30 12:49   ` Andy Shevchenko
2024-09-30 11:30 ` [PATCH v4 5/5] dt-bindings: mmc: Document support for partition table in mmc-card Christian Marangi
2024-09-30 12:18   ` Rasmus Villemoes
2024-09-30 12:22     ` Christian Marangi
2024-09-30 14:00       ` Rasmus Villemoes
2024-09-30 12:54 ` [PATCH v4 0/5] block: partition table OF support Andy Shevchenko
2024-10-02  9:20   ` Rasmus Villemoes
2024-10-03  9:59     ` Andy Shevchenko

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