mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH] Allow configuration from the devicetree
@ 2013-07-10 10:51 Sascha Hauer
  2013-07-10 10:52 ` [PATCH 1/9] devfs: let devfs_add_partition return the new partition Sascha Hauer
                   ` (9 more replies)
  0 siblings, 10 replies; 19+ messages in thread
From: Sascha Hauer @ 2013-07-10 10:51 UTC (permalink / raw)
  To: barebox

Currently even the devicetree enabled boards need C code to
configure where to store the environment. The following series
makes this configurable via devicetree to further reduce the
need of C code for boards.

As I often point out that the devicetree is for hardware description
rather than for configuration, the configuration is done in the
node explicitly intended for configuration: /chosen.

We add a hierarchy /chosen/barebox/ in the devicetree on which
of_platform_populate is called. This allows us to do the configuration
as regular drivers and to reuse a lot of infrastructure. Implementing
this as drivers also has the advantage that the known mechanisms can
be used to consistently change the behaviour of different boards
without breaking old boards.

Sascha

----------------------------------------------------------------
Sascha Hauer (9):
      devfs: let devfs_add_partition return the new partition
      of: export of_default_bus_match_table
      of: partitions: factor out function to parse a single partition
      cdev: introduce partition names
      cdev: allow to open a struct cdev
      cdev: add device_find_partition
      mci: set partnames of eMMC boot partitions
      Add configurability via devicetree
      ARM: i.MX Datamodul edmqx6: configure environment from devicetree

 Documentation/devicetree/bindings/barebox.txt      |  10 ++
 .../bindings/barebox/barebox,environment.txt       |  24 +++
 .../bindings/barebox/barebox,partition.txt         |  42 +++++
 arch/arm/boards/dmo-mx6-realq7/board.c             |  16 --
 arch/arm/configs/dmo-realq7_defconfig              |   1 +
 arch/arm/dts/imx6q-dmo-realq7.dts                  |  24 +++
 arch/x86/boards/x86_generic/generic_pc.c           |   6 +-
 commands/partition.c                               |  11 +-
 common/environment.c                               |  10 +-
 common/partitions.c                                |  12 +-
 drivers/mci/mci-core.c                             |  12 +-
 drivers/of/Kconfig                                 |   9 +
 drivers/of/Makefile                                |   1 +
 drivers/of/barebox.c                               | 191 +++++++++++++++++++++
 drivers/of/of_path.c                               | 155 +++++++++++++++++
 drivers/of/partition.c                             |  58 ++++---
 fs/devfs-core.c                                    |  60 +++++--
 include/driver.h                                   |  14 +-
 include/of.h                                       |  14 ++
 19 files changed, 600 insertions(+), 70 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/barebox.txt
 create mode 100644 Documentation/devicetree/bindings/barebox/barebox,environment.txt
 create mode 100644 Documentation/devicetree/bindings/barebox/barebox,partition.txt
 create mode 100644 drivers/of/barebox.c
 create mode 100644 drivers/of/of_path.c

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

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

* [PATCH 1/9] devfs: let devfs_add_partition return the new partition
  2013-07-10 10:51 [PATCH] Allow configuration from the devicetree Sascha Hauer
@ 2013-07-10 10:52 ` Sascha Hauer
  2013-07-10 10:52 ` [PATCH 2/9] of: export of_default_bus_match_table Sascha Hauer
                   ` (8 subsequent siblings)
  9 siblings, 0 replies; 19+ messages in thread
From: Sascha Hauer @ 2013-07-10 10:52 UTC (permalink / raw)
  To: barebox

Useful for unregistering later or for adding addional flags.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 arch/x86/boards/x86_generic/generic_pc.c |  6 ++++--
 commands/partition.c                     | 11 ++++++++---
 common/environment.c                     | 10 ++++++++--
 common/partitions.c                      | 12 ++++++++----
 fs/devfs-core.c                          | 12 ++++++------
 include/driver.h                         |  2 +-
 6 files changed, 35 insertions(+), 18 deletions(-)

diff --git a/arch/x86/boards/x86_generic/generic_pc.c b/arch/x86/boards/x86_generic/generic_pc.c
index e49354b..9d37069 100644
--- a/arch/x86/boards/x86_generic/generic_pc.c
+++ b/arch/x86/boards/x86_generic/generic_pc.c
@@ -25,6 +25,7 @@
 #include <init.h>
 #include <asm/syslib.h>
 #include <ns16550.h>
+#include <linux/err.h>
 
 /*
  * These datas are from the MBR, created by the linker and filled by the
@@ -43,6 +44,7 @@ extern uint8_t pers_env_drive;
 static int devices_init(void)
 {
 	int rc;
+	struct cdev *cdev;
 
 	/* extended memory only */
 	add_mem_device("ram0", 0x0, bios_get_memsize() << 10,
@@ -51,11 +53,11 @@ static int devices_init(void)
 			NULL);
 
 	if (pers_env_size != PATCH_AREA_PERS_SIZE_UNUSED) {
-		rc = devfs_add_partition("biosdisk0",
+		cdev = devfs_add_partition("biosdisk0",
 				pers_env_storage * 512,
 				(unsigned)pers_env_size * 512,
 				DEVFS_PARTITION_FIXED, "env0");
-		printf("Partition: %d\n", rc);
+		printf("Partition: %d\n", IS_ERR(cdev) ? PTR_ERR(cdev) : 0);
 	} else
 		printf("No persistent storage defined\n");
 
diff --git a/commands/partition.c b/commands/partition.c
index 6f8d634..6d37471 100644
--- a/commands/partition.c
+++ b/commands/partition.c
@@ -35,6 +35,7 @@
 #include <linux/stat.h>
 #include <libgen.h>
 #include <getopt.h>
+#include <linux/err.h>
 
 #define SIZE_REMAINING ((ulong)-1)
 
@@ -48,7 +49,8 @@ static int mtd_part_do_parse_one(char *devname, const char *partstr,
 	char *end;
 	char buf[PATH_MAX] = {};
 	unsigned long flags = 0;
-	int ret;
+	int ret = 0;
+	struct cdev *cdev;
 
 	memset(buf, 0, PATH_MAX);
 
@@ -99,9 +101,12 @@ static int mtd_part_do_parse_one(char *devname, const char *partstr,
 
 	*retsize = size;
 
-	ret = devfs_add_partition(devname, *offset, size, flags, buf);
-	if (ret)
+	cdev = devfs_add_partition(devname, *offset, size, flags, buf);
+	if (IS_ERR(cdev)) {
+		ret = PTR_ERR(cdev);
 		printf("cannot create %s: %s\n", buf, strerror(-ret));
+	}
+
 	return ret;
 }
 
diff --git a/common/environment.c b/common/environment.c
index 78cd45c..2448777 100644
--- a/common/environment.c
+++ b/common/environment.c
@@ -379,7 +379,7 @@ out:
 
 int envfs_register_partition(const char *devname, unsigned int partnr)
 {
-	struct cdev *cdev;
+	struct cdev *cdev, *part;
 	char *partname;
 
 	if (!devname)
@@ -398,8 +398,14 @@ int envfs_register_partition(const char *devname, unsigned int partnr)
 		return -ENODEV;
 	}
 
-	return devfs_add_partition(partname, 0, cdev->size,
+	part = devfs_add_partition(partname, 0, cdev->size,
 						DEVFS_PARTITION_FIXED, "env0");
+	if (part)
+		return 0;
+
+	free(partname);
+
+	return -EINVAL;
 }
 EXPORT_SYMBOL(envfs_register_partition);
 #endif
diff --git a/common/partitions.c b/common/partitions.c
index 35a604c..38032a3 100644
--- a/common/partitions.c
+++ b/common/partitions.c
@@ -29,6 +29,7 @@
 #include <disks.h>
 #include <filetype.h>
 #include <dma.h>
+#include <linux/err.h>
 
 #include "partitions/parser.h"
 
@@ -48,16 +49,19 @@ static int register_one_partition(struct block_device *blk,
 	int ret;
 	uint64_t start = part->first_sec * SECTOR_SIZE;
 	uint64_t size = part->size * SECTOR_SIZE;
+	struct cdev *cdev;
 
 	partition_name = asprintf("%s.%d", blk->cdev.name, no);
 	if (!partition_name)
 		return -ENOMEM;
 	dev_dbg(blk->dev, "Registering partition %s on drive %s\n",
 				partition_name, blk->cdev.name);
-	ret = devfs_add_partition(blk->cdev.name,
+	cdev = devfs_add_partition(blk->cdev.name,
 				start, size, 0, partition_name);
-	if (ret)
+	if (IS_ERR(cdev)) {
+		ret = PTR_ERR(cdev);
 		goto out;
+	}
 
 	free(partition_name);
 
@@ -70,10 +74,10 @@ static int register_one_partition(struct block_device *blk,
 
 	dev_dbg(blk->dev, "Registering partition %s on drive %s\n",
 				partition_name, blk->cdev.name);
-	ret = devfs_add_partition(blk->cdev.name,
+	cdev = devfs_add_partition(blk->cdev.name,
 				start, size, 0, partition_name);
 
-	if (ret)
+	if (IS_ERR(cdev))
 		dev_warn(blk->dev, "Registering partition %s on drive %s failed\n",
 				partition_name, blk->cdev.name);
 
diff --git a/fs/devfs-core.c b/fs/devfs-core.c
index 262e0a2..a16866e 100644
--- a/fs/devfs-core.c
+++ b/fs/devfs-core.c
@@ -226,21 +226,21 @@ int devfs_remove(struct cdev *cdev)
 	return 0;
 }
 
-int devfs_add_partition(const char *devname, loff_t offset, loff_t size,
+struct cdev *devfs_add_partition(const char *devname, loff_t offset, loff_t size,
 		int flags, const char *name)
 {
 	struct cdev *cdev, *new;
 
 	cdev = cdev_by_name(name);
 	if (cdev)
-		return -EEXIST;
+		return ERR_PTR(-EEXIST);
 
 	cdev = cdev_by_name(devname);
 	if (!cdev)
-		return -ENOENT;
+		return ERR_PTR(-ENOENT);
 
 	if (offset + size > cdev->size)
-		return -EINVAL;
+		return ERR_PTR(-EINVAL);
 
 	new = xzalloc(sizeof (*new));
 	new->name = strdup(name);
@@ -257,14 +257,14 @@ int devfs_add_partition(const char *devname, loff_t offset, loff_t size,
 		if (IS_ERR(new->mtd)) {
 			int ret = PTR_ERR(new->mtd);
 			free(new);
-			return ret;
+			return ERR_PTR(ret);
 		}
 	}
 #endif
 
 	devfs_create(new);
 
-	return 0;
+	return new;
 }
 
 int devfs_del_partition(const char *name)
diff --git a/include/driver.h b/include/driver.h
index b18318f..9f114ff 100644
--- a/include/driver.h
+++ b/include/driver.h
@@ -469,7 +469,7 @@ int cdev_erase(struct cdev *cdev, size_t count, loff_t offset);
 #define DEVFS_IS_PARTITION		(1 << 2)
 #define DEVFS_IS_CHARACTER_DEV		(1 << 3)
 
-int devfs_add_partition(const char *devname, loff_t offset, loff_t size,
+struct cdev *devfs_add_partition(const char *devname, loff_t offset, loff_t size,
 		int flags, const char *name);
 int devfs_del_partition(const char *name);
 
-- 
1.8.3.2


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

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

* [PATCH 2/9] of: export of_default_bus_match_table
  2013-07-10 10:51 [PATCH] Allow configuration from the devicetree Sascha Hauer
  2013-07-10 10:52 ` [PATCH 1/9] devfs: let devfs_add_partition return the new partition Sascha Hauer
@ 2013-07-10 10:52 ` Sascha Hauer
  2013-07-10 10:52 ` [PATCH 3/9] of: partitions: factor out function to parse a single partition Sascha Hauer
                   ` (7 subsequent siblings)
  9 siblings, 0 replies; 19+ messages in thread
From: Sascha Hauer @ 2013-07-10 10:52 UTC (permalink / raw)
  To: barebox

For code which wants to call of_platform_populate.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 include/of.h | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/include/of.h b/include/of.h
index ebe8e39..0d8f6b3 100644
--- a/include/of.h
+++ b/include/of.h
@@ -679,4 +679,6 @@ static inline int of_property_write_u64(struct device_node *np,
 	return of_property_write_u64_array(np, propname, &value, 1);
 }
 
+extern const struct of_device_id of_default_bus_match_table[];
+
 #endif /* __OF_H */
-- 
1.8.3.2


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

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

* [PATCH 3/9] of: partitions: factor out function to parse a single partition
  2013-07-10 10:51 [PATCH] Allow configuration from the devicetree Sascha Hauer
  2013-07-10 10:52 ` [PATCH 1/9] devfs: let devfs_add_partition return the new partition Sascha Hauer
  2013-07-10 10:52 ` [PATCH 2/9] of: export of_default_bus_match_table Sascha Hauer
@ 2013-07-10 10:52 ` Sascha Hauer
  2013-07-10 10:52 ` [PATCH 4/9] cdev: introduce partition names Sascha Hauer
                   ` (6 subsequent siblings)
  9 siblings, 0 replies; 19+ messages in thread
From: Sascha Hauer @ 2013-07-10 10:52 UTC (permalink / raw)
  To: barebox

To make it usable for other code.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 drivers/of/partition.c | 58 ++++++++++++++++++++++++++++----------------------
 include/of.h           |  1 +
 2 files changed, 34 insertions(+), 25 deletions(-)

diff --git a/drivers/of/partition.c b/drivers/of/partition.c
index e4b7d1e..d69251e 100644
--- a/drivers/of/partition.c
+++ b/drivers/of/partition.c
@@ -23,44 +23,52 @@
 #include <linux/mtd/mtd.h>
 #include <nand.h>
 
-int of_parse_partitions(struct cdev *cdev, struct device_node *node)
+struct cdev *of_parse_partition(struct cdev *cdev, struct device_node *node)
 {
-	struct device_node *n;
 	const char *partname;
 	char *filename;
+	struct cdev *new;
+	const __be32 *reg;
+	unsigned long offset, size;
+	const char *name;
+	int len;
+	unsigned long flags = 0;
 
-	for_each_child_of_node(node, n) {
-		const __be32 *reg;
-		unsigned long offset, size;
-		const char *name;
-		int len;
-		unsigned long flags = 0;
+	reg = of_get_property(node, "reg", &len);
+	if (!reg)
+		return NULL;
+
+	offset = be32_to_cpu(reg[0]);
+	size = be32_to_cpu(reg[1]);
+
+	partname = of_get_property(node, "label", &len);
+	if (!partname)
+		partname = of_get_property(node, "name", &len);
+	name = (char *)partname;
 
-		reg = of_get_property(n, "reg", &len);
-		if (!reg)
-			continue;
+	debug("add partition: %s.%s 0x%08lx 0x%08lx\n", cdev->name, partname, offset, size);
 
-		offset = be32_to_cpu(reg[0]);
-		size = be32_to_cpu(reg[1]);
+	if (of_get_property(node, "read-only", &len))
+		flags = DEVFS_PARTITION_READONLY;
 
-		partname = of_get_property(n, "label", &len);
-		if (!partname)
-			partname = of_get_property(n, "name", &len);
-		name = (char *)partname;
+	filename = asprintf("%s.%s", cdev->name, partname);
 
-		debug("add partition: %s.%s 0x%08lx 0x%08lx\n", cdev->name, partname, offset, size);
+	new = devfs_add_partition(cdev->name, offset, size, flags, filename);
 
-		if (of_get_property(n, "read-only", &len))
-			flags = DEVFS_PARTITION_READONLY;
+	if (cdev->mtd && cdev->mtd->type == MTD_NANDFLASH)
+		dev_add_bb_dev(filename, NULL);
 
-		filename = asprintf("%s.%s", cdev->name, partname);
+	free(filename);
 
-		devfs_add_partition(cdev->name, offset, size, flags, filename);
+	return new;
+}
 
-		if (cdev->mtd && cdev->mtd->type == MTD_NANDFLASH)
-			dev_add_bb_dev(filename, NULL);
+int of_parse_partitions(struct cdev *cdev, struct device_node *node)
+{
+	struct device_node *n;
 
-		free(filename);
+	for_each_child_of_node(node, n) {
+		of_parse_partition(cdev, n);
 	}
 
 	return 0;
diff --git a/include/of.h b/include/of.h
index 0d8f6b3..710383c 100644
--- a/include/of.h
+++ b/include/of.h
@@ -221,6 +221,7 @@ extern int of_platform_populate(struct device_node *root,
 				struct device_d *parent);
 extern struct device_d *of_find_device_by_node(struct device_node *np);
 
+struct cdev *of_parse_partition(struct cdev *cdev, struct device_node *node);
 int of_parse_partitions(struct cdev *cdev, struct device_node *node);
 int of_device_is_stdout_path(struct device_d *dev);
 const char *of_get_model(void);
-- 
1.8.3.2


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

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

* [PATCH 4/9] cdev: introduce partition names
  2013-07-10 10:51 [PATCH] Allow configuration from the devicetree Sascha Hauer
                   ` (2 preceding siblings ...)
  2013-07-10 10:52 ` [PATCH 3/9] of: partitions: factor out function to parse a single partition Sascha Hauer
@ 2013-07-10 10:52 ` Sascha Hauer
  2013-07-10 10:52 ` [PATCH 5/9] cdev: allow to open a struct cdev Sascha Hauer
                   ` (5 subsequent siblings)
  9 siblings, 0 replies; 19+ messages in thread
From: Sascha Hauer @ 2013-07-10 10:52 UTC (permalink / raw)
  To: barebox

currently most partition cdevs have the name <devname>.<partname>
This makes it hard to find a partition by <partname>. This introduces
a partname field in struct cdev so that.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 fs/devfs-core.c  | 3 +++
 include/driver.h | 5 ++++-
 2 files changed, 7 insertions(+), 1 deletion(-)

diff --git a/fs/devfs-core.c b/fs/devfs-core.c
index a16866e..a2bea93 100644
--- a/fs/devfs-core.c
+++ b/fs/devfs-core.c
@@ -244,6 +244,8 @@ struct cdev *devfs_add_partition(const char *devname, loff_t offset, loff_t size
 
 	new = xzalloc(sizeof (*new));
 	new->name = strdup(name);
+	if (!strncmp(devname, name, strlen(devname)))
+		new->partname = xstrdup(name + strlen(devname) + 1);
 	new->ops = cdev->ops;
 	new->priv = cdev->priv;
 	new->size = size;
@@ -291,6 +293,7 @@ int devfs_del_partition(const char *name)
 		return ret;
 
 	free(cdev->name);
+	free(cdev->partname);
 	free(cdev);
 
 	return 0;
diff --git a/include/driver.h b/include/driver.h
index 9f114ff..353af3a 100644
--- a/include/driver.h
+++ b/include/driver.h
@@ -444,7 +444,10 @@ struct cdev {
 	struct device_d *dev;
 	struct list_head list;
 	struct list_head devices_list;
-	char *name;
+	char *name; /* filename under /dev/ */
+	char *partname; /* the partition name, usually the above without the
+			 * device part, i.e. name = "nand0.barebox" -> partname = "barebox"
+			 */
 	loff_t offset;
 	loff_t size;
 	unsigned int flags;
-- 
1.8.3.2


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

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

* [PATCH 5/9] cdev: allow to open a struct cdev
  2013-07-10 10:51 [PATCH] Allow configuration from the devicetree Sascha Hauer
                   ` (3 preceding siblings ...)
  2013-07-10 10:52 ` [PATCH 4/9] cdev: introduce partition names Sascha Hauer
@ 2013-07-10 10:52 ` Sascha Hauer
  2013-07-10 10:52 ` [PATCH 6/9] cdev: add device_find_partition Sascha Hauer
                   ` (4 subsequent siblings)
  9 siblings, 0 replies; 19+ messages in thread
From: Sascha Hauer @ 2013-07-10 10:52 UTC (permalink / raw)
  To: barebox

cdev_open() opens a cdev by name. This introduces cdev_do_open which
allows to open a cdev when the cdev is already found by other means.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 fs/devfs-core.c  | 16 +++++++++++-----
 include/driver.h |  1 +
 2 files changed, 12 insertions(+), 5 deletions(-)

diff --git a/fs/devfs-core.c b/fs/devfs-core.c
index a2bea93..816f244 100644
--- a/fs/devfs-core.c
+++ b/fs/devfs-core.c
@@ -70,6 +70,14 @@ int cdev_find_free_index(const char *basename)
 	return -EBUSY;	/* all indexes are used */
 }
 
+int cdev_do_open(struct cdev *cdev, unsigned long flags)
+{
+	if (cdev->ops->open)
+		return cdev->ops->open(cdev, flags);
+
+	return 0;
+}
+
 struct cdev *cdev_open(const char *name, unsigned long flags)
 {
 	struct cdev *cdev = cdev_by_name(name);
@@ -78,11 +86,9 @@ struct cdev *cdev_open(const char *name, unsigned long flags)
 	if (!cdev)
 		return NULL;
 
-	if (cdev->ops->open) {
-		ret = cdev->ops->open(cdev, flags);
-		if (ret)
-			return NULL;
-	}
+	ret = cdev_do_open(cdev, flags);
+	if (ret)
+		return NULL;
 
 	return cdev;
 }
diff --git a/include/driver.h b/include/driver.h
index 353af3a..7ac2eef 100644
--- a/include/driver.h
+++ b/include/driver.h
@@ -460,6 +460,7 @@ int devfs_remove(struct cdev *);
 int cdev_find_free_index(const char *);
 struct cdev *cdev_by_name(const char *filename);
 struct cdev *cdev_open(const char *name, unsigned long flags);
+int cdev_do_open(struct cdev *, unsigned long flags);
 void cdev_close(struct cdev *cdev);
 int cdev_flush(struct cdev *cdev);
 ssize_t cdev_read(struct cdev *cdev, void *buf, size_t count, loff_t offset, ulong flags);
-- 
1.8.3.2


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

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

* [PATCH 6/9] cdev: add device_find_partition
  2013-07-10 10:51 [PATCH] Allow configuration from the devicetree Sascha Hauer
                   ` (4 preceding siblings ...)
  2013-07-10 10:52 ` [PATCH 5/9] cdev: allow to open a struct cdev Sascha Hauer
@ 2013-07-10 10:52 ` Sascha Hauer
  2013-07-10 10:52 ` [PATCH 7/9] mci: set partnames of eMMC boot partitions Sascha Hauer
                   ` (3 subsequent siblings)
  9 siblings, 0 replies; 19+ messages in thread
From: Sascha Hauer @ 2013-07-10 10:52 UTC (permalink / raw)
  To: barebox

device_find_partition allows to find a partition of a device with
a particular name.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 fs/devfs-core.c  | 27 +++++++++++++++++++++++++++
 include/driver.h |  1 +
 2 files changed, 28 insertions(+)

diff --git a/fs/devfs-core.c b/fs/devfs-core.c
index 816f244..a92d434 100644
--- a/fs/devfs-core.c
+++ b/fs/devfs-core.c
@@ -56,6 +56,33 @@ struct cdev *cdev_by_name(const char *filename)
 	return NULL;
 }
 
+/**
+ * device_find_partition - find a partition belonging to a physical device
+ *
+ * @dev: the device which should be searched for partitions
+ * @name: the partition name
+ */
+struct cdev *device_find_partition(struct device_d *dev, const char *name)
+{
+	struct cdev *cdev;
+	struct device_d *child;
+
+	list_for_each_entry(cdev, &dev->cdevs, devices_list) {
+		if (!cdev->partname)
+			continue;
+		if (!strcmp(cdev->partname, name))
+			return cdev;
+	}
+
+	device_for_each_child(dev, child) {
+		cdev = device_find_partition(child, name);
+		if (cdev)
+			return cdev;
+	}
+
+	return NULL;
+}
+
 int cdev_find_free_index(const char *basename)
 {
 	int i;
diff --git a/include/driver.h b/include/driver.h
index 7ac2eef..f95c93c 100644
--- a/include/driver.h
+++ b/include/driver.h
@@ -458,6 +458,7 @@ struct cdev {
 int devfs_create(struct cdev *);
 int devfs_remove(struct cdev *);
 int cdev_find_free_index(const char *);
+struct cdev *device_find_partition(struct device_d *dev, const char *name);
 struct cdev *cdev_by_name(const char *filename);
 struct cdev *cdev_open(const char *name, unsigned long flags);
 int cdev_do_open(struct cdev *, unsigned long flags);
-- 
1.8.3.2


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

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

* [PATCH 7/9] mci: set partnames of eMMC boot partitions
  2013-07-10 10:51 [PATCH] Allow configuration from the devicetree Sascha Hauer
                   ` (5 preceding siblings ...)
  2013-07-10 10:52 ` [PATCH 6/9] cdev: add device_find_partition Sascha Hauer
@ 2013-07-10 10:52 ` Sascha Hauer
  2013-07-10 10:52 ` [PATCH 8/9] Add configurability via devicetree Sascha Hauer
                   ` (2 subsequent siblings)
  9 siblings, 0 replies; 19+ messages in thread
From: Sascha Hauer @ 2013-07-10 10:52 UTC (permalink / raw)
  To: barebox

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 drivers/mci/mci-core.c | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)

diff --git a/drivers/mci/mci-core.c b/drivers/mci/mci-core.c
index 67668d5..02e6216 100644
--- a/drivers/mci/mci-core.c
+++ b/drivers/mci/mci-core.c
@@ -406,7 +406,7 @@ static int mci_calc_blk_cnt(uint64_t cap, unsigned shift)
 }
 
 static void mci_part_add(struct mci *mci, uint64_t size,
-                        unsigned int part_cfg, char *name, int idx, bool ro,
+                        unsigned int part_cfg, char *name, char *partname, int idx, bool ro,
                         int area_type)
 {
 	struct mci_part *part = &mci->part[mci->nr_parts];
@@ -414,6 +414,7 @@ static void mci_part_add(struct mci *mci, uint64_t size,
 	part->mci = mci;
 	part->size = size;
 	part->blk.cdev.name = name;
+	part->blk.cdev.partname = partname;
 	part->blk.blockbits = SECTOR_SHIFT;
 	part->blk.num_blocks = mci_calc_blk_cnt(size, part->blk.blockbits);
 	part->area_type = area_type;
@@ -482,13 +483,14 @@ static int mmc_change_freq(struct mci *mci)
 		unsigned int part_size;
 
 		for (idx = 0; idx < MMC_NUM_BOOT_PARTITION; idx++) {
-			char *name;
+			char *name, *partname;
 			part_size = mci->ext_csd[EXT_CSD_BOOT_MULT] << 17;
 
-			name = asprintf("%s.boot%d", mci->cdevname, idx);
+			partname = asprintf("boot%d", idx);
+			name = asprintf("%s.%s", mci->cdevname, partname);
 			mci_part_add(mci, part_size,
 					EXT_CSD_PART_CONFIG_ACC_BOOT0 + idx,
-					name, idx, true,
+					name, partname, idx, true,
 					MMC_BLK_DATA_AREA_BOOT);
 		}
 
@@ -1104,7 +1106,7 @@ static int mci_startup(struct mci *mci)
 	err = mci_set_blocklen(mci, mci->read_bl_len);
 
 	mci_part_add(mci, mci->capacity, 0,
-			mci->cdevname, 0, true,
+			mci->cdevname, NULL, 0, true,
 			MMC_BLK_DATA_AREA_MAIN);
 
 	return err;
-- 
1.8.3.2


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

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

* [PATCH 8/9] Add configurability via devicetree
  2013-07-10 10:51 [PATCH] Allow configuration from the devicetree Sascha Hauer
                   ` (6 preceding siblings ...)
  2013-07-10 10:52 ` [PATCH 7/9] mci: set partnames of eMMC boot partitions Sascha Hauer
@ 2013-07-10 10:52 ` Sascha Hauer
  2013-07-10 13:17   ` Jean-Christophe PLAGNIOL-VILLARD
  2013-07-10 10:52 ` [PATCH 9/9] ARM: i.MX Datamodul edmqx6: configure environment from devicetree Sascha Hauer
  2013-07-11  7:37 ` [PATCH] Allow configuration from the devicetree Sascha Hauer
  9 siblings, 1 reply; 19+ messages in thread
From: Sascha Hauer @ 2013-07-10 10:52 UTC (permalink / raw)
  To: barebox

This adds the possibility to configure the place for the environment
from the devicetree and to partition devices from the devicetree.

Configuration has the general form of devices with a regular compatible
property. This allows to later add additional drivers or drivers with
different behaviour (for example to add support for redundant environment).

The configuration is all in the /chosen/barebox/ hierarchy of the
devicetree. This separates the configuration from the hardware
description. Also it makes it possible to store the configuration
in a completely separate devicetree (or devicetree overlay). For
the same reason all configuration is done using nodepathes rather
than phandles.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 Documentation/devicetree/bindings/barebox.txt      |  10 ++
 .../bindings/barebox/barebox,environment.txt       |  24 +++
 .../bindings/barebox/barebox,partition.txt         |  42 +++++
 drivers/of/Kconfig                                 |   9 +
 drivers/of/Makefile                                |   1 +
 drivers/of/barebox.c                               | 191 +++++++++++++++++++++
 drivers/of/of_path.c                               | 155 +++++++++++++++++
 fs/devfs-core.c                                    |   2 +
 include/driver.h                                   |   5 +
 include/of.h                                       |  11 ++
 10 files changed, 450 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/barebox.txt
 create mode 100644 Documentation/devicetree/bindings/barebox/barebox,environment.txt
 create mode 100644 Documentation/devicetree/bindings/barebox/barebox,partition.txt
 create mode 100644 drivers/of/barebox.c
 create mode 100644 drivers/of/of_path.c

diff --git a/Documentation/devicetree/bindings/barebox.txt b/Documentation/devicetree/bindings/barebox.txt
new file mode 100644
index 0000000..906c4bc
--- /dev/null
+++ b/Documentation/devicetree/bindings/barebox.txt
@@ -0,0 +1,10 @@
+barebox specific devicetree bindings
+====================================
+
+barebox uses some barebox specific devicetree bindings. All of these
+are under the /chosen/barebox/ hierarchy in the devicetree.
+
+The bindings have the form of a device with regular 'compatible' properties.
+drivers matching these devices do not handle physical devices but instead
+influence / configure certain behaviours of barebox like the place where to
+find the persistent environment or the partitioning of devices.
diff --git a/Documentation/devicetree/bindings/barebox/barebox,environment.txt b/Documentation/devicetree/bindings/barebox/barebox,environment.txt
new file mode 100644
index 0000000..48fd376
--- /dev/null
+++ b/Documentation/devicetree/bindings/barebox/barebox,environment.txt
@@ -0,0 +1,24 @@
+barebox environment
+
+This driver provides an environment for barebox from the devicetree.
+
+Required properties:
+- compatible: should be "barebox,environment"
+- device-path: path to the environment
+
+The device-path is a multistring property. The first string should be a
+nodepath to the node containing the physical device of the environment.
+The subsequent strings are of the form <type>:<options> to further describe
+the path to the environment. Supported values for <type>:
+
+partname:<partname>  This describes a partition on a device. <partname> can
+                     be the label for mtd partitions, the number for DOS
+		     partitions (beginning with 0) or the name for GPT
+		     partitions
+
+Example:
+
+environment@0 {
+	compatible = "barebox,environment";
+	device-path = &flash, "partname:barebox-environment";
+};
diff --git a/Documentation/devicetree/bindings/barebox/barebox,partition.txt b/Documentation/devicetree/bindings/barebox/barebox,partition.txt
new file mode 100644
index 0000000..f38e76d
--- /dev/null
+++ b/Documentation/devicetree/bindings/barebox/barebox,partition.txt
@@ -0,0 +1,42 @@
+partition provider
+
+Driver to provide a partitioning for mtd devices. barebox provides a
+separate driver for this instead of positioning the partitions under
+the devicenode which actually provides the partitions. The reason for
+this is that the devicetree contains the hardware description whereas
+the partitioning of a device is not hardware specific. Having a separate
+driver makes it possible to separate the hardware devicetree from the
+configuration.
+
+Required properties:
+
+- compatible: should be "barebox,partition"
+- device-path: should contain a nodepath to the physical device for which
+               this device provides a partitioning
+- #address-cells, #size-cells: number of cells for size/addresses in the
+                               partitions
+
+Partition properties:
+
+- reg: The partition's offset and size
+- label: The label/name for this partition
+- read-only: if present, the partition is read-only
+
+Example:
+
+nor-partitions {
+	compatible = "barebox,partition";
+	device-path = &flash;
+	#address-cells = <1>;
+	#size-cells = <1>;
+
+	partition@0 {
+		label = "barebox";
+		reg = <0x0 0x80000>;
+	};
+
+	partition@1 {
+		label = "barebox-environment";
+		reg = <0x80000 0x80000>;
+	};
+};
diff --git a/drivers/of/Kconfig b/drivers/of/Kconfig
index 03ae599..ab5eac8 100644
--- a/drivers/of/Kconfig
+++ b/drivers/of/Kconfig
@@ -18,3 +18,12 @@ config OFDEVICE
 config OF_NET
 	depends on NET
 	def_bool y
+
+config OF_BAREBOX_DRIVERS
+	depends on OFDEVICE
+	bool "Enable barebox specific devicetree configuration drivers"
+	help
+	  barebox supports being configured from devicetree. This enables
+	  support for this feature. This currently allows to configure the
+	  environment path from devicetree and to partition devices. See
+	  Documentation/devicetree/bindings/barebox/ for more information.
diff --git a/drivers/of/Makefile b/drivers/of/Makefile
index e7d0733..97fea9d 100644
--- a/drivers/of/Makefile
+++ b/drivers/of/Makefile
@@ -3,3 +3,4 @@ obj-$(CONFIG_OFTREE_MEM_GENERIC) += mem_generic.o
 obj-$(CONFIG_GPIOLIB) += of_gpio.o
 obj-y += partition.o
 obj-y += of_net.o
+obj-$(CONFIG_OF_BAREBOX_DRIVERS) += barebox.o of_path.o
diff --git a/drivers/of/barebox.c b/drivers/of/barebox.c
new file mode 100644
index 0000000..4d178a8
--- /dev/null
+++ b/drivers/of/barebox.c
@@ -0,0 +1,191 @@
+/*
+ * barebox.c
+ *
+ * Copyright (c) 2013 Sascha Hauer <s.hauer@pengutronix.de>, Pengutronix
+ *
+ * See file CREDITS for list of people who contributed to this
+ * project.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ */
+
+#include <common.h>
+#include <init.h>
+#include <io.h>
+#include <of.h>
+#include <malloc.h>
+#include <partition.h>
+#include <envfs.h>
+
+struct of_partition {
+	struct list_head list;
+	char *nodepath;
+	struct device_d *dev;
+};
+
+static LIST_HEAD(of_partition_list);
+
+static struct device_node *cdev_find_node(struct cdev *cdev)
+{
+	struct device_d *dev = cdev->dev;
+
+	while (dev) {
+		if (dev->device_node)
+			return dev->device_node;
+
+		dev = dev->parent;
+	}
+
+	return NULL;
+}
+
+void of_cdev_register(struct cdev *cdev)
+{
+	struct device_node *np, *child;
+	struct of_partition *op;
+
+	if (cdev->flags & DEVFS_IS_PARTITION)
+		return;
+
+	if (cdev->partname)
+		return;
+
+	np = cdev_find_node(cdev);
+	if (!np)
+		return;
+
+	list_for_each_entry(op, &of_partition_list, list)
+		if (!strcmp(np->full_name, op->nodepath))
+			goto found;
+
+	return;
+
+found:
+	for_each_child_of_node(op->dev->device_node, child) {
+		dev_dbg(op->dev, "adding partition %s to %s\n", child->name,
+				cdev->name);
+		of_parse_partition(cdev, child);
+	}
+
+	list_del(&op->list);
+	free(op);
+}
+
+struct device_d *of_find_device_by_node_path(const char *path)
+{
+	struct device_d *dev;
+
+	for_each_device(dev) {
+		if (!dev->device_node)
+			continue;
+		if (!strcmp(path, dev->device_node->full_name))
+			return dev;
+	}
+
+	return NULL;
+}
+
+static int partition_probe(struct device_d *dev)
+{
+	const char *path;
+	struct device_node *node = dev->device_node;
+	int len;
+	struct of_partition *op;
+	struct cdev *cdev;
+
+	path = of_get_property(node, "device-path", &len);
+	if (!path) {
+		dev_err(dev, "cannot find 'device-path' property\n");
+		return -EINVAL;
+	}
+
+	node = of_find_node_by_path(path);
+	if (!node) {
+		dev_err(dev, "cannot find node with path '%s'\n", path);
+		return -ENODEV;
+	}
+
+	op = xzalloc(sizeof(*op));
+	op->nodepath = xstrdup(path);
+	op->dev = dev;
+
+	list_add_tail(&op->list, &of_partition_list);
+
+	cdev_for_each(cdev)
+		of_cdev_register(cdev);
+
+	return 0;
+}
+
+static struct of_device_id partition_dt_ids[] = {
+	{
+		.compatible = "barebox,partition",
+	}, {
+		/* sentinel */
+	}
+};
+
+static struct driver_d partition_driver = {
+	.name		= "barebox-partition",
+	.probe		= partition_probe,
+	.of_compatible	= partition_dt_ids,
+};
+
+static int environment_probe(struct device_d *dev)
+{
+	char *path;
+	int ret;
+
+	ret = of_find_path(dev->device_node, "device-path", &path);
+	if (ret)
+		return ret;
+
+	dev_info(dev, "setting default environment path to %s\n", path);
+
+	default_environment_path = path;
+
+	return 0;
+}
+
+static struct of_device_id environment_dt_ids[] = {
+	{
+		.compatible = "barebox,environment",
+	}, {
+		/* sentinel */
+	}
+};
+
+static struct driver_d environment_driver = {
+	.name		= "barebox-environment",
+	.probe		= environment_probe,
+	.of_compatible	= environment_dt_ids,
+};
+
+static int barebox_of_driver_init(void)
+{
+	struct device_node *node;
+
+	node = of_get_root_node();
+	if (!node)
+		return 0;
+
+	node = of_find_node_by_path("/chosen/barebox");
+	if (!node)
+		return 0;
+
+	of_platform_populate(node, of_default_bus_match_table, NULL);
+
+	platform_driver_register(&partition_driver);
+	platform_driver_register(&environment_driver);
+
+	return 0;
+}
+late_initcall(barebox_of_driver_init);
diff --git a/drivers/of/of_path.c b/drivers/of/of_path.c
new file mode 100644
index 0000000..ab8618e
--- /dev/null
+++ b/drivers/of/of_path.c
@@ -0,0 +1,155 @@
+/*
+ * of_path.c
+ *
+ * Copyright (c) 2013 Sascha Hauer <s.hauer@pengutronix.de>, Pengutronix
+ *
+ * See file CREDITS for list of people who contributed to this
+ * project.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ */
+
+#include <common.h>
+#include <malloc.h>
+#include <of.h>
+
+struct of_path {
+	struct cdev *cdev;
+	struct device_d *dev;
+};
+
+struct of_path_type {
+	const char *name;
+	int (*parse)(struct of_path *op, const char *str);
+};
+
+/**
+ * of_path_type_partname - find a partition based on physical device and
+ *                         partition name
+ * @op: of_path context
+ * @name: the partition name to find
+ */
+static int of_path_type_partname(struct of_path *op, const char *name)
+{
+	if (!op->dev)
+		return -EINVAL;
+
+	op->cdev = device_find_partition(op->dev, name);
+	if (op->cdev) {
+		pr_debug("%s: found part '%s'\n", __func__, name);
+		return 0;
+	} else {
+		pr_debug("%s: cannot find part '%s'\n", __func__, name);
+		return -ENODEV;
+	}
+}
+
+static struct of_path_type of_path_types[] = {
+	{
+		.name = "partname",
+		.parse = of_path_type_partname,
+	},
+};
+
+static int of_path_parse_one(struct of_path *op, const char *str)
+{
+	int i, ret;
+	char *name, *desc;
+
+	pr_debug("parsing: %s\n", str);
+
+	name = xstrdup(str);
+	desc = strchr(name, ':');
+	if (!desc) {
+		free(name);
+		return -EINVAL;
+	}
+
+	*desc = 0;
+	desc++;
+
+	for (i = 0; i < ARRAY_SIZE(of_path_types); i++) {
+		if (!strcmp(of_path_types[i].name, name)) {
+			ret = of_path_types[i].parse(op, desc);
+			goto out;
+		}
+	}
+
+	ret = -EINVAL;
+out:
+	free(name);
+
+	return ret;
+}
+
+/**
+ * of_find_path - translate a path description in the devicetree to a barebox
+ *                path
+ *
+ * @node: the node containing the property with the path description
+ * @propname: the property name of the path description
+ * @outpath: if this function returns 0 outpath will contain the path belonging
+ *           to the input path description. Must be freed with free().
+ *
+ * pathes in the devicetree have the form of a multistring property. The first
+ * string contains the full path to the physical device containing the path.
+ * The remaining strings have the form "<type>:<options>". Currently supported
+ * for <type> are:
+ *
+ * partname:<partname> - find a partition by its partition name. For mtd
+ *                       partitions this is the label. For DOS partitions
+ *                       this is the number beginning with 0.
+ *
+ * examples:
+ *
+ * device-path = &mmc0, "partname:0";
+ * device-path = &norflash, "partname:barebox-environment";
+ */
+int of_find_path(struct device_node *node, const char *propname, char **outpath)
+{
+	struct of_path op = {};
+	struct device_node *rnode;
+	const char *path, *str;
+	int i, len, ret;
+
+	path = of_get_property(node, propname, &len);
+	if (!path)
+		return -EINVAL;
+
+	rnode = of_find_node_by_path(path);
+	if (!rnode)
+		return -ENODEV;
+
+	op.dev = of_find_device_by_node_path(rnode->full_name);
+	if (!op.dev)
+		return -ENODEV;
+
+	device_detect(op.dev);
+
+	i = 1;
+
+	while (1) {
+		ret = of_property_read_string_index(node, propname, i++, &str);
+		if (ret)
+			break;
+
+		ret = of_path_parse_one(&op, str);
+		if (ret)
+			return ret;
+	}
+
+	if (!op.cdev)
+		return -ENOENT;
+
+	*outpath = asprintf("/dev/%s", op.cdev->name);
+
+	return 0;
+}
diff --git a/fs/devfs-core.c b/fs/devfs-core.c
index a92d434..b41ae53 100644
--- a/fs/devfs-core.c
+++ b/fs/devfs-core.c
@@ -244,6 +244,8 @@ int devfs_create(struct cdev *new)
 	if (new->dev)
 		list_add_tail(&new->devices_list, &new->dev->cdevs);
 
+	of_cdev_register(new);
+
 	return 0;
 }
 
diff --git a/include/driver.h b/include/driver.h
index f95c93c..9abd41c 100644
--- a/include/driver.h
+++ b/include/driver.h
@@ -455,6 +455,11 @@ struct cdev {
 	struct mtd_info *mtd;
 };
 
+extern struct list_head cdev_list;
+
+#define cdev_for_each(cdev) \
+	list_for_each_entry(cdev, &cdev_list, list)
+
 int devfs_create(struct cdev *);
 int devfs_remove(struct cdev *);
 int cdev_find_free_index(const char *);
diff --git a/include/of.h b/include/of.h
index 710383c..e977e23 100644
--- a/include/of.h
+++ b/include/of.h
@@ -229,6 +229,8 @@ void *of_flatten_dtb(struct device_node *node);
 int of_add_memory(struct device_node *node, bool dump);
 void of_add_memory_bank(struct device_node *node, bool dump, int r,
 		u64 base, u64 size);
+struct device_d *of_find_device_by_node_path(const char *path);
+int of_find_path(struct device_node *node, const char *propname, char **outpath);
 #else
 static inline int of_parse_partitions(struct cdev *cdev,
 					  struct device_node *node)
@@ -560,6 +562,7 @@ static inline struct device_d *of_find_device_by_node(struct device_node *np)
 {
 	return NULL;
 }
+
 #endif
 
 #define for_each_node_by_name(dn, name) \
@@ -682,4 +685,12 @@ static inline int of_property_write_u64(struct device_node *np,
 
 extern const struct of_device_id of_default_bus_match_table[];
 
+#ifdef CONFIG_OF_BAREBOX_DRIVERS
+void of_cdev_register(struct cdev *cdev);
+#else
+static inline void of_cdev_register(struct cdev *cdev)
+{
+}
+#endif
+
 #endif /* __OF_H */
-- 
1.8.3.2


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

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

* [PATCH 9/9] ARM: i.MX Datamodul edmqx6: configure environment from devicetree
  2013-07-10 10:51 [PATCH] Allow configuration from the devicetree Sascha Hauer
                   ` (7 preceding siblings ...)
  2013-07-10 10:52 ` [PATCH 8/9] Add configurability via devicetree Sascha Hauer
@ 2013-07-10 10:52 ` Sascha Hauer
  2013-07-11  7:37 ` [PATCH] Allow configuration from the devicetree Sascha Hauer
  9 siblings, 0 replies; 19+ messages in thread
From: Sascha Hauer @ 2013-07-10 10:52 UTC (permalink / raw)
  To: barebox

This drops support for storing the environment in the eMMC,
but the standard bootsource is the SPI NOR flash.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 arch/arm/boards/dmo-mx6-realq7/board.c | 16 ----------------
 arch/arm/configs/dmo-realq7_defconfig  |  1 +
 arch/arm/dts/imx6q-dmo-realq7.dts      | 24 ++++++++++++++++++++++++
 3 files changed, 25 insertions(+), 16 deletions(-)

diff --git a/arch/arm/boards/dmo-mx6-realq7/board.c b/arch/arm/boards/dmo-mx6-realq7/board.c
index 9cf6c31..95371e7 100644
--- a/arch/arm/boards/dmo-mx6-realq7/board.c
+++ b/arch/arm/boards/dmo-mx6-realq7/board.c
@@ -114,22 +114,6 @@ static int realq7_env_init(void)
 		BBU_HANDLER_FLAG_DEFAULT, NULL, 0, 0x00907000);
 	imx6_bbu_internal_mmc_register_handler("mmc", "/dev/mmc3.barebox",
 		0, NULL, 0, 0x00907000);
-
-	switch (bootsource_get()) {
-	case BOOTSOURCE_MMC:
-		device_detect_by_name("mmc3");
-		devfs_add_partition("mmc3", 0, SZ_1M, DEVFS_PARTITION_FIXED, "mmc3.barebox");
-		devfs_add_partition("mmc3", SZ_1M, SZ_1M, DEVFS_PARTITION_FIXED, "mmc3.bareboxenv");
-		default_environment_path = "/dev/mmc3.bareboxenv";
-		break;
-	default:
-	case BOOTSOURCE_SPI:
-		devfs_add_partition("m25p0", 0, SZ_256K, DEVFS_PARTITION_FIXED, "m25p0.barebox");
-		devfs_add_partition("m25p0", SZ_256K, SZ_256K, DEVFS_PARTITION_FIXED, "m25p0.bareboxenv");
-		default_environment_path = "/dev/m25p0.bareboxenv";
-		break;
-	}
-
 	return 0;
 }
 late_initcall(realq7_env_init);
diff --git a/arch/arm/configs/dmo-realq7_defconfig b/arch/arm/configs/dmo-realq7_defconfig
index ab8aa43..501a182 100644
--- a/arch/arm/configs/dmo-realq7_defconfig
+++ b/arch/arm/configs/dmo-realq7_defconfig
@@ -71,6 +71,7 @@ CONFIG_NET_NFS=y
 CONFIG_NET_PING=y
 CONFIG_NET_RESOLV=y
 CONFIG_OFDEVICE=y
+CONFIG_OF_BAREBOX_DRIVERS=y
 CONFIG_DRIVER_NET_FEC_IMX=y
 CONFIG_DRIVER_SPI_IMX=y
 CONFIG_I2C=y
diff --git a/arch/arm/dts/imx6q-dmo-realq7.dts b/arch/arm/dts/imx6q-dmo-realq7.dts
index a33a700..d8675e5 100644
--- a/arch/arm/dts/imx6q-dmo-realq7.dts
+++ b/arch/arm/dts/imx6q-dmo-realq7.dts
@@ -19,6 +19,30 @@
 
 	chosen {
 		linux,stdout-path = "/soc/aips-bus@02100000/serial@021e8000";
+
+		barebox {
+			environment@0 {
+				compatible = "barebox,environment";
+				device-path = &flash, "partname:barebox-environment";
+			};
+
+			nor-partitions {
+				compatible = "barebox,partition";
+				device-path = &flash;
+				#address-cells = <1>;
+				#size-cells = <1>;
+
+				partition@0 {
+					label = "barebox";
+					reg = <0x0 0x80000>;
+				};
+
+				partition@1 {
+					label = "barebox-environment";
+					reg = <0x80000 0x20000>;
+				};
+			};
+		};
 	};
 
 	aliases {
-- 
1.8.3.2


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

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

* Re: [PATCH 8/9] Add configurability via devicetree
  2013-07-10 10:52 ` [PATCH 8/9] Add configurability via devicetree Sascha Hauer
@ 2013-07-10 13:17   ` Jean-Christophe PLAGNIOL-VILLARD
  2013-07-10 13:34     ` Sascha Hauer
  0 siblings, 1 reply; 19+ messages in thread
From: Jean-Christophe PLAGNIOL-VILLARD @ 2013-07-10 13:17 UTC (permalink / raw)
  To: Sascha Hauer; +Cc: barebox


On Jul 10, 2013, at 6:52 PM, Sascha Hauer <s.hauer@pengutronix.de> wrote:

> This adds the possibility to configure the place for the environment
> from the devicetree and to partition devices from the devicetree.
> 
> Configuration has the general form of devices with a regular compatible
> property. This allows to later add additional drivers or drivers with
> different behaviour (for example to add support for redundant environment).
> 
> The configuration is all in the /chosen/barebox/ hierarchy of the
> devicetree. This separates the configuration from the hardware
> description. Also it makes it possible to store the configuration
> in a completely separate devicetree (or devicetree overlay). For
> the same reason all configuration is done using nodepathes rather
> than phandles.
> 
> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
> ---
> Documentation/devicetree/bindings/barebox.txt      |  10 ++
> .../bindings/barebox/barebox,environment.txt       |  24 +++
> .../bindings/barebox/barebox,partition.txt         |  42 +++++
> drivers/of/Kconfig                                 |   9 +
> drivers/of/Makefile                                |   1 +
> drivers/of/barebox.c                               | 191 +++++++++++++++++++++
> drivers/of/of_path.c                               | 155 +++++++++++++++++
> fs/devfs-core.c                                    |   2 +
> include/driver.h                                   |   5 +
> include/of.h                                       |  11 ++
> 10 files changed, 450 insertions(+)
> create mode 100644 Documentation/devicetree/bindings/barebox.txt
> create mode 100644 Documentation/devicetree/bindings/barebox/barebox,environment.txt
> create mode 100644 Documentation/devicetree/bindings/barebox/barebox,partition.txt
> create mode 100644 drivers/of/barebox.c
> create mode 100644 drivers/of/of_path.c
> 
> diff --git a/Documentation/devicetree/bindings/barebox.txt b/Documentation/devicetree/bindings/barebox.txt
> new file mode 100644
> index 0000000..906c4bc
> --- /dev/null
> +++ b/Documentation/devicetree/bindings/barebox.txt
> @@ -0,0 +1,10 @@
> +barebox specific devicetree bindings
> +====================================
> +
> +barebox uses some barebox specific devicetree bindings. All of these
> +are under the /chosen/barebox/ hierarchy in the devicetree.
> +
> +The bindings have the form of a device with regular 'compatible' properties.
> +drivers matching these devices do not handle physical devices but instead
> +influence / configure certain behaviours of barebox like the place where to
> +find the persistent environment or the partitioning of devices.
> diff --git a/Documentation/devicetree/bindings/barebox/barebox,environment.txt b/Documentation/devicetree/bindings/barebox/barebox,environment.txt
> new file mode 100644
> index 0000000..48fd376
> --- /dev/null
> +++ b/Documentation/devicetree/bindings/barebox/barebox,environment.txt
> @@ -0,0 +1,24 @@
> +barebox environment
> +
> +This driver provides an environment for barebox from the devicetree.
> +
> +Required properties:
> +- compatible: should be "barebox,environment"
> +- device-path: path to the environment
> +
> +The device-path is a multistring property. The first string should be a
> +nodepath to the node containing the physical device of the environment.
> +The subsequent strings are of the form <type>:<options> to further describe
> +the path to the environment. Supported values for <type>:
> +
> +partname:<partname>  This describes a partition on a device. <partname> can
> +                     be the label for mtd partitions, the number for DOS
> +		     partitions (beginning with 0) or the name for GPT
> +		     partitions
> +
> +Example:
> +
> +environment@0 {
> +	compatible = "barebox,environment";
> +	device-path = &flash, "partname:barebox-environment";
> +};
> diff --git a/Documentation/devicetree/bindings/barebox/barebox,partition.txt b/Documentation/devicetree/bindings/barebox/barebox,partition.txt
> new file mode 100644
> index 0000000..f38e76d
> --- /dev/null
> +++ b/Documentation/devicetree/bindings/barebox/barebox,partition.txt
> @@ -0,0 +1,42 @@
> +partition provider
> +
> +Driver to provide a partitioning for mtd devices. barebox provides a
> +separate driver for this instead of positioning the partitions under
> +the devicenode which actually provides the partitions. The reason for
> +this is that the devicetree contains the hardware description whereas
> +the partitioning of a device is not hardware specific. Having a separate
> +driver makes it possible to separate the hardware devicetree from the
> +configuration.
> +
> +Required properties:
> +
> +- compatible: should be "barebox,partition"
> +- device-path: should contain a nodepath to the physical device for which
> +               this device provides a partitioning
> +- #address-cells, #size-cells: number of cells for size/addresses in the
> +                               partitions
> +
> +Partition properties:
> +
> +- reg: The partition's offset and size
> +- label: The label/name for this partition
> +- read-only: if present, the partition is read-only
> +
> +Example:
> +
> +nor-partitions {
> +	compatible = "barebox,partition";
> +	device-path = &flash;
> +	#address-cells = <1>;
> +	#size-cells = <1>;
> +
> +	partition@0 {
> +		label = "barebox";
> +		reg = <0x0 0x80000>;
> +	};
> +
> +	partition@1 {
> +		label = "barebox-environment";
> +		reg = <0x80000 0x80000>;
> +	};
> +};

This is duplicate with the mtd partition, isn't?

Best Regards,
J.

> diff --git a/drivers/of/Kconfig b/drivers/of/Kconfig
> index 03ae599..ab5eac8 100644
> --- a/drivers/of/Kconfig
> +++ b/drivers/of/Kconfig
> @@ -18,3 +18,12 @@ config OFDEVICE
> config OF_NET
> 	depends on NET
> 	def_bool y
> +
> +config OF_BAREBOX_DRIVERS
> +	depends on OFDEVICE
> +	bool "Enable barebox specific devicetree configuration drivers"
> +	help
> +	  barebox supports being configured from devicetree. This enables
> +	  support for this feature. This currently allows to configure the
> +	  environment path from devicetree and to partition devices. See
> +	  Documentation/devicetree/bindings/barebox/ for more information.
> diff --git a/drivers/of/Makefile b/drivers/of/Makefile
> index e7d0733..97fea9d 100644
> --- a/drivers/of/Makefile
> +++ b/drivers/of/Makefile
> @@ -3,3 +3,4 @@ obj-$(CONFIG_OFTREE_MEM_GENERIC) += mem_generic.o
> obj-$(CONFIG_GPIOLIB) += of_gpio.o
> obj-y += partition.o
> obj-y += of_net.o
> +obj-$(CONFIG_OF_BAREBOX_DRIVERS) += barebox.o of_path.o
> diff --git a/drivers/of/barebox.c b/drivers/of/barebox.c
> new file mode 100644
> index 0000000..4d178a8
> --- /dev/null
> +++ b/drivers/of/barebox.c
> @@ -0,0 +1,191 @@
> +/*
> + * barebox.c
> + *
> + * Copyright (c) 2013 Sascha Hauer <s.hauer@pengutronix.de>, Pengutronix
> + *
> + * See file CREDITS for list of people who contributed to this
> + * project.
> + *
> + * This program is free software; you can redistribute it and/or modify
> + * it under the terms of the GNU General Public License version 2
> + * as published by the Free Software Foundation.
> + *
> + * This program is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> + * GNU General Public License for more details.
> + *
> + */
> +
> +#include <common.h>
> +#include <init.h>
> +#include <io.h>
> +#include <of.h>
> +#include <malloc.h>
> +#include <partition.h>
> +#include <envfs.h>
> +
> +struct of_partition {
> +	struct list_head list;
> +	char *nodepath;
> +	struct device_d *dev;
> +};
> +
> +static LIST_HEAD(of_partition_list);
> +
> +static struct device_node *cdev_find_node(struct cdev *cdev)
> +{
> +	struct device_d *dev = cdev->dev;
> +
> +	while (dev) {
> +		if (dev->device_node)
> +			return dev->device_node;
> +
> +		dev = dev->parent;
> +	}
> +
> +	return NULL;
> +}
> +
> +void of_cdev_register(struct cdev *cdev)
> +{
> +	struct device_node *np, *child;
> +	struct of_partition *op;
> +
> +	if (cdev->flags & DEVFS_IS_PARTITION)
> +		return;
> +
> +	if (cdev->partname)
> +		return;
> +
> +	np = cdev_find_node(cdev);
> +	if (!np)
> +		return;
> +
> +	list_for_each_entry(op, &of_partition_list, list)
> +		if (!strcmp(np->full_name, op->nodepath))
> +			goto found;
> +
> +	return;
> +
> +found:
> +	for_each_child_of_node(op->dev->device_node, child) {
> +		dev_dbg(op->dev, "adding partition %s to %s\n", child->name,
> +				cdev->name);
> +		of_parse_partition(cdev, child);
> +	}
> +
> +	list_del(&op->list);
> +	free(op);
> +}
> +
> +struct device_d *of_find_device_by_node_path(const char *path)
> +{
> +	struct device_d *dev;
> +
> +	for_each_device(dev) {
> +		if (!dev->device_node)
> +			continue;
> +		if (!strcmp(path, dev->device_node->full_name))
> +			return dev;
> +	}
> +
> +	return NULL;
> +}
> +
> +static int partition_probe(struct device_d *dev)
> +{
> +	const char *path;
> +	struct device_node *node = dev->device_node;
> +	int len;
> +	struct of_partition *op;
> +	struct cdev *cdev;
> +
> +	path = of_get_property(node, "device-path", &len);
> +	if (!path) {
> +		dev_err(dev, "cannot find 'device-path' property\n");
> +		return -EINVAL;
> +	}
> +
> +	node = of_find_node_by_path(path);
> +	if (!node) {
> +		dev_err(dev, "cannot find node with path '%s'\n", path);
> +		return -ENODEV;
> +	}
> +
> +	op = xzalloc(sizeof(*op));
> +	op->nodepath = xstrdup(path);
> +	op->dev = dev;
> +
> +	list_add_tail(&op->list, &of_partition_list);
> +
> +	cdev_for_each(cdev)
> +		of_cdev_register(cdev);
> +
> +	return 0;
> +}
> +
> +static struct of_device_id partition_dt_ids[] = {
> +	{
> +		.compatible = "barebox,partition",
> +	}, {
> +		/* sentinel */
> +	}
> +};
> +
> +static struct driver_d partition_driver = {
> +	.name		= "barebox-partition",
> +	.probe		= partition_probe,
> +	.of_compatible	= partition_dt_ids,
> +};
> +
> +static int environment_probe(struct device_d *dev)
> +{
> +	char *path;
> +	int ret;
> +
> +	ret = of_find_path(dev->device_node, "device-path", &path);
> +	if (ret)
> +		return ret;
> +
> +	dev_info(dev, "setting default environment path to %s\n", path);
> +
> +	default_environment_path = path;
> +
> +	return 0;
> +}
> +
> +static struct of_device_id environment_dt_ids[] = {
> +	{
> +		.compatible = "barebox,environment",
> +	}, {
> +		/* sentinel */
> +	}
> +};
> +
> +static struct driver_d environment_driver = {
> +	.name		= "barebox-environment",
> +	.probe		= environment_probe,
> +	.of_compatible	= environment_dt_ids,
> +};
> +
> +static int barebox_of_driver_init(void)
> +{
> +	struct device_node *node;
> +
> +	node = of_get_root_node();
> +	if (!node)
> +		return 0;
> +
> +	node = of_find_node_by_path("/chosen/barebox");
> +	if (!node)
> +		return 0;
> +
> +	of_platform_populate(node, of_default_bus_match_table, NULL);
> +
> +	platform_driver_register(&partition_driver);
> +	platform_driver_register(&environment_driver);
> +
> +	return 0;
> +}
> +late_initcall(barebox_of_driver_init);
> diff --git a/drivers/of/of_path.c b/drivers/of/of_path.c
> new file mode 100644
> index 0000000..ab8618e
> --- /dev/null
> +++ b/drivers/of/of_path.c
> @@ -0,0 +1,155 @@
> +/*
> + * of_path.c
> + *
> + * Copyright (c) 2013 Sascha Hauer <s.hauer@pengutronix.de>, Pengutronix
> + *
> + * See file CREDITS for list of people who contributed to this
> + * project.
> + *
> + * This program is free software; you can redistribute it and/or modify
> + * it under the terms of the GNU General Public License version 2
> + * as published by the Free Software Foundation.
> + *
> + * This program is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> + * GNU General Public License for more details.
> + *
> + */
> +
> +#include <common.h>
> +#include <malloc.h>
> +#include <of.h>
> +
> +struct of_path {
> +	struct cdev *cdev;
> +	struct device_d *dev;
> +};
> +
> +struct of_path_type {
> +	const char *name;
> +	int (*parse)(struct of_path *op, const char *str);
> +};
> +
> +/**
> + * of_path_type_partname - find a partition based on physical device and
> + *                         partition name
> + * @op: of_path context
> + * @name: the partition name to find
> + */
> +static int of_path_type_partname(struct of_path *op, const char *name)
> +{
> +	if (!op->dev)
> +		return -EINVAL;
> +
> +	op->cdev = device_find_partition(op->dev, name);
> +	if (op->cdev) {
> +		pr_debug("%s: found part '%s'\n", __func__, name);
> +		return 0;
> +	} else {
> +		pr_debug("%s: cannot find part '%s'\n", __func__, name);
> +		return -ENODEV;
> +	}
> +}
> +
> +static struct of_path_type of_path_types[] = {
> +	{
> +		.name = "partname",
> +		.parse = of_path_type_partname,
> +	},
> +};
> +
> +static int of_path_parse_one(struct of_path *op, const char *str)
> +{
> +	int i, ret;
> +	char *name, *desc;
> +
> +	pr_debug("parsing: %s\n", str);
> +
> +	name = xstrdup(str);
> +	desc = strchr(name, ':');
> +	if (!desc) {
> +		free(name);
> +		return -EINVAL;
> +	}
> +
> +	*desc = 0;
> +	desc++;
> +
> +	for (i = 0; i < ARRAY_SIZE(of_path_types); i++) {
> +		if (!strcmp(of_path_types[i].name, name)) {
> +			ret = of_path_types[i].parse(op, desc);
> +			goto out;
> +		}
> +	}
> +
> +	ret = -EINVAL;
> +out:
> +	free(name);
> +
> +	return ret;
> +}
> +
> +/**
> + * of_find_path - translate a path description in the devicetree to a barebox
> + *                path
> + *
> + * @node: the node containing the property with the path description
> + * @propname: the property name of the path description
> + * @outpath: if this function returns 0 outpath will contain the path belonging
> + *           to the input path description. Must be freed with free().
> + *
> + * pathes in the devicetree have the form of a multistring property. The first
> + * string contains the full path to the physical device containing the path.
> + * The remaining strings have the form "<type>:<options>". Currently supported
> + * for <type> are:
> + *
> + * partname:<partname> - find a partition by its partition name. For mtd
> + *                       partitions this is the label. For DOS partitions
> + *                       this is the number beginning with 0.
> + *
> + * examples:
> + *
> + * device-path = &mmc0, "partname:0";
> + * device-path = &norflash, "partname:barebox-environment";
> + */
> +int of_find_path(struct device_node *node, const char *propname, char **outpath)
> +{
> +	struct of_path op = {};
> +	struct device_node *rnode;
> +	const char *path, *str;
> +	int i, len, ret;
> +
> +	path = of_get_property(node, propname, &len);
> +	if (!path)
> +		return -EINVAL;
> +
> +	rnode = of_find_node_by_path(path);
> +	if (!rnode)
> +		return -ENODEV;
> +
> +	op.dev = of_find_device_by_node_path(rnode->full_name);
> +	if (!op.dev)
> +		return -ENODEV;
> +
> +	device_detect(op.dev);
> +
> +	i = 1;
> +
> +	while (1) {
> +		ret = of_property_read_string_index(node, propname, i++, &str);
> +		if (ret)
> +			break;
> +
> +		ret = of_path_parse_one(&op, str);
> +		if (ret)
> +			return ret;
> +	}
> +
> +	if (!op.cdev)
> +		return -ENOENT;
> +
> +	*outpath = asprintf("/dev/%s", op.cdev->name);
> +
> +	return 0;
> +}
> diff --git a/fs/devfs-core.c b/fs/devfs-core.c
> index a92d434..b41ae53 100644
> --- a/fs/devfs-core.c
> +++ b/fs/devfs-core.c
> @@ -244,6 +244,8 @@ int devfs_create(struct cdev *new)
> 	if (new->dev)
> 		list_add_tail(&new->devices_list, &new->dev->cdevs);
> 
> +	of_cdev_register(new);
> +
> 	return 0;
> }
> 
> diff --git a/include/driver.h b/include/driver.h
> index f95c93c..9abd41c 100644
> --- a/include/driver.h
> +++ b/include/driver.h
> @@ -455,6 +455,11 @@ struct cdev {
> 	struct mtd_info *mtd;
> };
> 
> +extern struct list_head cdev_list;
> +
> +#define cdev_for_each(cdev) \
> +	list_for_each_entry(cdev, &cdev_list, list)
> +
> int devfs_create(struct cdev *);
> int devfs_remove(struct cdev *);
> int cdev_find_free_index(const char *);
> diff --git a/include/of.h b/include/of.h
> index 710383c..e977e23 100644
> --- a/include/of.h
> +++ b/include/of.h
> @@ -229,6 +229,8 @@ void *of_flatten_dtb(struct device_node *node);
> int of_add_memory(struct device_node *node, bool dump);
> void of_add_memory_bank(struct device_node *node, bool dump, int r,
> 		u64 base, u64 size);
> +struct device_d *of_find_device_by_node_path(const char *path);
> +int of_find_path(struct device_node *node, const char *propname, char **outpath);
> #else
> static inline int of_parse_partitions(struct cdev *cdev,
> 					  struct device_node *node)
> @@ -560,6 +562,7 @@ static inline struct device_d *of_find_device_by_node(struct device_node *np)
> {
> 	return NULL;
> }
> +
> #endif
> 
> #define for_each_node_by_name(dn, name) \
> @@ -682,4 +685,12 @@ static inline int of_property_write_u64(struct device_node *np,
> 
> extern const struct of_device_id of_default_bus_match_table[];
> 
> +#ifdef CONFIG_OF_BAREBOX_DRIVERS
> +void of_cdev_register(struct cdev *cdev);
> +#else
> +static inline void of_cdev_register(struct cdev *cdev)
> +{
> +}
> +#endif
> +
> #endif /* __OF_H */
> -- 
> 1.8.3.2
> 
> 
> _______________________________________________
> barebox mailing list
> barebox@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/barebox


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

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

* Re: [PATCH 8/9] Add configurability via devicetree
  2013-07-10 13:17   ` Jean-Christophe PLAGNIOL-VILLARD
@ 2013-07-10 13:34     ` Sascha Hauer
  2013-07-10 14:33       ` Jean-Christophe PLAGNIOL-VILLARD
  0 siblings, 1 reply; 19+ messages in thread
From: Sascha Hauer @ 2013-07-10 13:34 UTC (permalink / raw)
  To: Jean-Christophe PLAGNIOL-VILLARD; +Cc: barebox

On Wed, Jul 10, 2013 at 09:17:03PM +0800, Jean-Christophe PLAGNIOL-VILLARD wrote:
> 
> > +Required properties:
> > +
> > +- compatible: should be "barebox,partition"
> > +- device-path: should contain a nodepath to the physical device for which
> > +               this device provides a partitioning
> > +- #address-cells, #size-cells: number of cells for size/addresses in the
> > +                               partitions
> > +
> > +Partition properties:
> > +
> > +- reg: The partition's offset and size
> > +- label: The label/name for this partition
> > +- read-only: if present, the partition is read-only
> > +
> > +Example:
> > +
> > +nor-partitions {
> > +	compatible = "barebox,partition";
> > +	device-path = &flash;
> > +	#address-cells = <1>;
> > +	#size-cells = <1>;
> > +
> > +	partition@0 {
> > +		label = "barebox";
> > +		reg = <0x0 0x80000>;
> > +	};
> > +
> > +	partition@1 {
> > +		label = "barebox-environment";
> > +		reg = <0x80000 0x80000>;
> > +	};
> > +};
> 
> This is duplicate with the mtd partition, isn't?

It's the same binding, yes.

Sascha

-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

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

* Re: [PATCH 8/9] Add configurability via devicetree
  2013-07-10 13:34     ` Sascha Hauer
@ 2013-07-10 14:33       ` Jean-Christophe PLAGNIOL-VILLARD
  2013-07-10 14:42         ` Sascha Hauer
  0 siblings, 1 reply; 19+ messages in thread
From: Jean-Christophe PLAGNIOL-VILLARD @ 2013-07-10 14:33 UTC (permalink / raw)
  To: Sascha Hauer; +Cc: barebox

On 15:34 Wed 10 Jul     , Sascha Hauer wrote:
> On Wed, Jul 10, 2013 at 09:17:03PM +0800, Jean-Christophe PLAGNIOL-VILLARD wrote:
> > 
> > > +Required properties:
> > > +
> > > +- compatible: should be "barebox,partition"
> > > +- device-path: should contain a nodepath to the physical device for which
> > > +               this device provides a partitioning
> > > +- #address-cells, #size-cells: number of cells for size/addresses in the
> > > +                               partitions
> > > +
> > > +Partition properties:
> > > +
> > > +- reg: The partition's offset and size
> > > +- label: The label/name for this partition
> > > +- read-only: if present, the partition is read-only
> > > +
> > > +Example:
> > > +
> > > +nor-partitions {
> > > +	compatible = "barebox,partition";
> > > +	device-path = &flash;
> > > +	#address-cells = <1>;
> > > +	#size-cells = <1>;
> > > +
> > > +	partition@0 {
> > > +		label = "barebox";
> > > +		reg = <0x0 0x80000>;
> > > +	};
> > > +
> > > +	partition@1 {
> > > +		label = "barebox-environment";
> > > +		reg = <0x80000 0x80000>;
> > > +	};
> > > +};
> > 
> > This is duplicate with the mtd partition, isn't?
> 
> It's the same binding, yes.

I do not like to duplicate the information can de avoid this

Best Regards,
J.
> 
> Sascha
> 
> -- 
> Pengutronix e.K.                           |                             |
> Industrial Linux Solutions                 | http://www.pengutronix.de/  |
> Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
> Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

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

* Re: [PATCH 8/9] Add configurability via devicetree
  2013-07-10 14:33       ` Jean-Christophe PLAGNIOL-VILLARD
@ 2013-07-10 14:42         ` Sascha Hauer
  2013-07-10 15:50           ` Jean-Christophe PLAGNIOL-VILLARD
  0 siblings, 1 reply; 19+ messages in thread
From: Sascha Hauer @ 2013-07-10 14:42 UTC (permalink / raw)
  To: Jean-Christophe PLAGNIOL-VILLARD; +Cc: barebox

On Wed, Jul 10, 2013 at 04:33:49PM +0200, Jean-Christophe PLAGNIOL-VILLARD wrote:
> On 15:34 Wed 10 Jul     , Sascha Hauer wrote:
> > On Wed, Jul 10, 2013 at 09:17:03PM +0800, Jean-Christophe PLAGNIOL-VILLARD wrote:
> > > 
> > > > +Required properties:
> > > > +
> > > > +- compatible: should be "barebox,partition"
> > > > +- device-path: should contain a nodepath to the physical device for which
> > > > +               this device provides a partitioning
> > > > +- #address-cells, #size-cells: number of cells for size/addresses in the
> > > > +                               partitions
> > > > +
> > > > +Partition properties:
> > > > +
> > > > +- reg: The partition's offset and size
> > > > +- label: The label/name for this partition
> > > > +- read-only: if present, the partition is read-only
> > > > +
> > > > +Example:
> > > > +
> > > > +nor-partitions {
> > > > +	compatible = "barebox,partition";
> > > > +	device-path = &flash;
> > > > +	#address-cells = <1>;
> > > > +	#size-cells = <1>;
> > > > +
> > > > +	partition@0 {
> > > > +		label = "barebox";
> > > > +		reg = <0x0 0x80000>;
> > > > +	};
> > > > +
> > > > +	partition@1 {
> > > > +		label = "barebox-environment";
> > > > +		reg = <0x80000 0x80000>;
> > > > +	};
> > > > +};
> > > 
> > > This is duplicate with the mtd partition, isn't?
> > 
> > It's the same binding, yes.
> 
> I do not like to duplicate the information can de avoid this

Which information? The Documentation?

Sascha

-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

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

* Re: [PATCH 8/9] Add configurability via devicetree
  2013-07-10 14:42         ` Sascha Hauer
@ 2013-07-10 15:50           ` Jean-Christophe PLAGNIOL-VILLARD
  2013-07-10 20:17             ` Sascha Hauer
  0 siblings, 1 reply; 19+ messages in thread
From: Jean-Christophe PLAGNIOL-VILLARD @ 2013-07-10 15:50 UTC (permalink / raw)
  To: Sascha Hauer; +Cc: barebox

On 16:42 Wed 10 Jul     , Sascha Hauer wrote:
> On Wed, Jul 10, 2013 at 04:33:49PM +0200, Jean-Christophe PLAGNIOL-VILLARD wrote:
> > On 15:34 Wed 10 Jul     , Sascha Hauer wrote:
> > > On Wed, Jul 10, 2013 at 09:17:03PM +0800, Jean-Christophe PLAGNIOL-VILLARD wrote:
> > > > 
> > > > > +Required properties:
> > > > > +
> > > > > +- compatible: should be "barebox,partition"
> > > > > +- device-path: should contain a nodepath to the physical device for which
> > > > > +               this device provides a partitioning
> > > > > +- #address-cells, #size-cells: number of cells for size/addresses in the
> > > > > +                               partitions
> > > > > +
> > > > > +Partition properties:
> > > > > +
> > > > > +- reg: The partition's offset and size
> > > > > +- label: The label/name for this partition
> > > > > +- read-only: if present, the partition is read-only
> > > > > +
> > > > > +Example:
> > > > > +
> > > > > +nor-partitions {
> > > > > +	compatible = "barebox,partition";
> > > > > +	device-path = &flash;
> > > > > +	#address-cells = <1>;
> > > > > +	#size-cells = <1>;
> > > > > +
> > > > > +	partition@0 {
> > > > > +		label = "barebox";
> > > > > +		reg = <0x0 0x80000>;
> > > > > +	};
> > > > > +
> > > > > +	partition@1 {
> > > > > +		label = "barebox-environment";
> > > > > +		reg = <0x80000 0x80000>;
> > > > > +	};
> > > > > +};
> > > > 
> > > > This is duplicate with the mtd partition, isn't?
> > > 
> > > It's the same binding, yes.
> > 
> > I do not like to duplicate the information can de avoid this
> 
> Which information? The Documentation?

no the fact we need to describe the nor-partitions twice, for barebox and for
linux in the DTB

Best Regards,
J.
> 
> Sascha
> 
> -- 
> Pengutronix e.K.                           |                             |
> Industrial Linux Solutions                 | http://www.pengutronix.de/  |
> Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
> Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

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

* Re: [PATCH 8/9] Add configurability via devicetree
  2013-07-10 15:50           ` Jean-Christophe PLAGNIOL-VILLARD
@ 2013-07-10 20:17             ` Sascha Hauer
  2013-07-15 10:11               ` Jean-Christophe PLAGNIOL-VILLARD
  0 siblings, 1 reply; 19+ messages in thread
From: Sascha Hauer @ 2013-07-10 20:17 UTC (permalink / raw)
  To: Jean-Christophe PLAGNIOL-VILLARD; +Cc: barebox

On Wed, Jul 10, 2013 at 05:50:28PM +0200, Jean-Christophe PLAGNIOL-VILLARD wrote:
> > > > It's the same binding, yes.
> > > 
> > > I do not like to duplicate the information can de avoid this
> > 
> > Which information? The Documentation?
> 
> no the fact we need to describe the nor-partitions twice, for barebox and for
> linux in the DTB

No, barebox should copy (or move) the partition nodes to where Linux
finds them before starting the kernel. This is not yet implemented
though.

Another option of course is to do the obvious and put the partitions
under the mtd device in the first place. I decided against this since
I have the strong feeling that the hardware description should be
separated from clearly board (or project or usecase) specific partition
descriptions.

Sascha

-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

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

* Re: [PATCH] Allow configuration from the devicetree
  2013-07-10 10:51 [PATCH] Allow configuration from the devicetree Sascha Hauer
                   ` (8 preceding siblings ...)
  2013-07-10 10:52 ` [PATCH 9/9] ARM: i.MX Datamodul edmqx6: configure environment from devicetree Sascha Hauer
@ 2013-07-11  7:37 ` Sascha Hauer
  9 siblings, 0 replies; 19+ messages in thread
From: Sascha Hauer @ 2013-07-11  7:37 UTC (permalink / raw)
  To: barebox

On Wed, Jul 10, 2013 at 12:51:59PM +0200, Sascha Hauer wrote:
> Currently even the devicetree enabled boards need C code to
> configure where to store the environment. The following series
> makes this configurable via devicetree to further reduce the
> need of C code for boards.
> 
> As I often point out that the devicetree is for hardware description
> rather than for configuration, the configuration is done in the
> node explicitly intended for configuration: /chosen.
> 
> We add a hierarchy /chosen/barebox/ in the devicetree on which
> of_platform_populate is called.

As discussed with Jan and Philipp Will change this to /chosen/ in
the next round.

Sascha

-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

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

* Re: [PATCH 8/9] Add configurability via devicetree
  2013-07-10 20:17             ` Sascha Hauer
@ 2013-07-15 10:11               ` Jean-Christophe PLAGNIOL-VILLARD
  2013-07-16 14:27                 ` Sascha Hauer
  0 siblings, 1 reply; 19+ messages in thread
From: Jean-Christophe PLAGNIOL-VILLARD @ 2013-07-15 10:11 UTC (permalink / raw)
  To: Sascha Hauer; +Cc: barebox

On 22:17 Wed 10 Jul     , Sascha Hauer wrote:
> On Wed, Jul 10, 2013 at 05:50:28PM +0200, Jean-Christophe PLAGNIOL-VILLARD wrote:
> > > > > It's the same binding, yes.
> > > > 
> > > > I do not like to duplicate the information can de avoid this
> > > 
> > > Which information? The Documentation?
> > 
> > no the fact we need to describe the nor-partitions twice, for barebox and for
> > linux in the DTB
> 
> No, barebox should copy (or move) the partition nodes to where Linux
> finds them before starting the kernel. This is not yet implemented
> though.
> 
> Another option of course is to do the obvious and put the partitions
> under the mtd device in the first place. I decided against this since
> I have the strong feeling that the hardware description should be
> separated from clearly board (or project or usecase) specific partition
> descriptions.

here we need to be more generic as it's booloader specific not really barebox
> 
> Sascha
> 
> -- 
> Pengutronix e.K.                           |                             |
> Industrial Linux Solutions                 | http://www.pengutronix.de/  |
> Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
> Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

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

* Re: [PATCH 8/9] Add configurability via devicetree
  2013-07-15 10:11               ` Jean-Christophe PLAGNIOL-VILLARD
@ 2013-07-16 14:27                 ` Sascha Hauer
  0 siblings, 0 replies; 19+ messages in thread
From: Sascha Hauer @ 2013-07-16 14:27 UTC (permalink / raw)
  To: Jean-Christophe PLAGNIOL-VILLARD; +Cc: barebox

On Mon, Jul 15, 2013 at 12:11:19PM +0200, Jean-Christophe PLAGNIOL-VILLARD wrote:
> On 22:17 Wed 10 Jul     , Sascha Hauer wrote:
> > On Wed, Jul 10, 2013 at 05:50:28PM +0200, Jean-Christophe PLAGNIOL-VILLARD wrote:
> > > > > > It's the same binding, yes.
> > > > > 
> > > > > I do not like to duplicate the information can de avoid this
> > > > 
> > > > Which information? The Documentation?
> > > 
> > > no the fact we need to describe the nor-partitions twice, for barebox and for
> > > linux in the DTB
> > 
> > No, barebox should copy (or move) the partition nodes to where Linux
> > finds them before starting the kernel. This is not yet implemented
> > though.
> > 
> > Another option of course is to do the obvious and put the partitions
> > under the mtd device in the first place. I decided against this since
> > I have the strong feeling that the hardware description should be
> > separated from clearly board (or project or usecase) specific partition
> > descriptions.
> 
> here we need to be more generic as it's booloader specific not really barebox

As mentioned I moved from /chosen/barebox to /chosen. I'd like to keep
the "barebox," prefixes in the compatible strings as long as barebox is
the only bootloader doing such stuff. It's more convenient to drop the
prefix later than it is to realize that we introduced a too generic
binding.

Sascha

-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

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

end of thread, other threads:[~2013-07-16 14:27 UTC | newest]

Thread overview: 19+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-07-10 10:51 [PATCH] Allow configuration from the devicetree Sascha Hauer
2013-07-10 10:52 ` [PATCH 1/9] devfs: let devfs_add_partition return the new partition Sascha Hauer
2013-07-10 10:52 ` [PATCH 2/9] of: export of_default_bus_match_table Sascha Hauer
2013-07-10 10:52 ` [PATCH 3/9] of: partitions: factor out function to parse a single partition Sascha Hauer
2013-07-10 10:52 ` [PATCH 4/9] cdev: introduce partition names Sascha Hauer
2013-07-10 10:52 ` [PATCH 5/9] cdev: allow to open a struct cdev Sascha Hauer
2013-07-10 10:52 ` [PATCH 6/9] cdev: add device_find_partition Sascha Hauer
2013-07-10 10:52 ` [PATCH 7/9] mci: set partnames of eMMC boot partitions Sascha Hauer
2013-07-10 10:52 ` [PATCH 8/9] Add configurability via devicetree Sascha Hauer
2013-07-10 13:17   ` Jean-Christophe PLAGNIOL-VILLARD
2013-07-10 13:34     ` Sascha Hauer
2013-07-10 14:33       ` Jean-Christophe PLAGNIOL-VILLARD
2013-07-10 14:42         ` Sascha Hauer
2013-07-10 15:50           ` Jean-Christophe PLAGNIOL-VILLARD
2013-07-10 20:17             ` Sascha Hauer
2013-07-15 10:11               ` Jean-Christophe PLAGNIOL-VILLARD
2013-07-16 14:27                 ` Sascha Hauer
2013-07-10 10:52 ` [PATCH 9/9] ARM: i.MX Datamodul edmqx6: configure environment from devicetree Sascha Hauer
2013-07-11  7:37 ` [PATCH] Allow configuration from the devicetree Sascha Hauer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox