[PATCH 1/2] mci: parse upstream boot/gp partition binding

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Linux recently added support for device tree partition binding for
SD/eMMC devices. Linux supports partitioning the main area as well as
the boot and gp areas. This adds support for the same binding to
barebox.

barebox already had support for partitioning the eMMC boot partitions,
unfortunately with different node names. Try the upstream binding first
and fall back to the barebox binding if upstream compatible nodes are
not found.

Note that not only the node names for the boot partitions differ in
both bindings, but also the numbering. "boot0-partitions" in the
barebox binding matches "partitions-boot1" in the upstream binding.

Signed-off-by: Sascha Hauer <s.hauer@xxxxxxxxxxxxxx>
---
 .../devicetree/bindings/mtd/partition.rst     |  3 +
 drivers/mci/mci-core.c                        | 62 ++++++++++++-------
 2 files changed, 43 insertions(+), 22 deletions(-)

diff --git a/Documentation/devicetree/bindings/mtd/partition.rst b/Documentation/devicetree/bindings/mtd/partition.rst
index 0ba117dffc..fb228c63a3 100644
--- a/Documentation/devicetree/bindings/mtd/partition.rst
+++ b/Documentation/devicetree/bindings/mtd/partition.rst
@@ -23,6 +23,9 @@ the partition table node is named appropriately:
 * ``boot0-partitions`` : boot0 partition
 * ``boot1-partitions`` : boot1 partition
 
+``boot0-partitions`` and ``boot1-partitions`` are deprecated. Use ``partitions-boot1``
+and ``partitions-boot2`` instead which is supported under Linux as well.
+
 Examples:
 
 .. code-block:: none
diff --git a/drivers/mci/mci-core.c b/drivers/mci/mci-core.c
index 48a3df9ec9..eb723a2711 100644
--- a/drivers/mci/mci-core.c
+++ b/drivers/mci/mci-core.c
@@ -2582,11 +2582,49 @@ static const char *mci_boot_names[] = {
 	"user",
 };
 
+static struct device_node *mci_get_partition_node(struct device_node *hwnode,
+						  unsigned int type,
+						  unsigned int index)
+{
+	struct device_node *np;
+	char partnodename[sizeof("bootx-partitions")];
+
+	if (index > 8)
+		return NULL;
+
+	switch (type) {
+	case MMC_BLK_DATA_AREA_BOOT:
+		sprintf(partnodename, "partitions-boot%u", index + 1);
+		break;
+	case MMC_BLK_DATA_AREA_MAIN:
+		return hwnode;
+	case MMC_BLK_DATA_AREA_GP:
+		sprintf(partnodename, "partitions-gp%u", index + 1);
+		break;
+	default:
+		return NULL;
+	}
+
+	np = of_get_child_by_name(hwnode, partnodename);
+	if (np)
+		return np;
+
+	if (type != MMC_BLK_DATA_AREA_BOOT)
+		return NULL;
+
+	/*
+	 * barebox historically understands "bootx-partitions" with x starting
+	 * at zero.
+	 */
+	sprintf(partnodename, "boot%u-partitions", index);
+
+	return of_get_child_by_name(hwnode, partnodename);
+}
+
 static int mci_register_partition(struct mci_part *part)
 {
 	struct mci *mci = part->mci;
 	struct mci_host *host = mci->host;
-	const char *partnodename = NULL;
 	struct device_node *np;
 	int rc;
 
@@ -2605,27 +2643,7 @@ static int mci_register_partition(struct mci_part *part)
 	}
 	dev_info(&mci->dev, "registered %s\n", part->blk.cdev.name);
 
-	np = host->hw_dev->of_node;
-
-	/* create partitions on demand */
-	switch (part->area_type) {
-	case MMC_BLK_DATA_AREA_BOOT:
-		if (part->idx == 0)
-			partnodename = "boot0-partitions";
-		else
-			partnodename = "boot1-partitions";
-
-		np = of_get_child_by_name(host->hw_dev->of_node,
-					  partnodename);
-		break;
-	case MMC_BLK_DATA_AREA_MAIN:
-		break;
-	case MMC_BLK_DATA_AREA_GP:
-		break;
-	default:
-		return 0;
-	}
-
+	np = mci_get_partition_node(host->hw_dev->of_node, part->area_type, part->idx);
 	if (np) {
 		of_parse_partitions(&part->blk.cdev, np);
 
-- 
2.39.5





[Index of Archives]     [Linux Embedded]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [XFree86]

  Powered by Linux