mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH 1/4] partitions/efi: Add partuuid to partition description
@ 2015-12-17  0:48 Trent Piepho
  2015-12-17  0:52 ` [PATCH 2/4] of_path: Fix bug with partitions, simply code Trent Piepho
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Trent Piepho @ 2015-12-17  0:48 UTC (permalink / raw)
  To: barebox

In commit bc31d85c6e23d724664e76bcfc3b2eda778012a3 the partition UUID
was added to the partition struct and thence to the cdev(s) for the
partition.  But just for DOS partitions.  Do this for GPT aka EFI
partitions too.

Signed-off-by: Trent Piepho <tpiepho@kymetacorp.com>
---
 common/partitions/Kconfig | 1 +
 common/partitions/efi.c   | 1 +
 2 files changed, 2 insertions(+)

diff --git a/common/partitions/Kconfig b/common/partitions/Kconfig
index 90238ad..be9405a 100644
--- a/common/partitions/Kconfig
+++ b/common/partitions/Kconfig
@@ -16,6 +16,7 @@ config PARTITION_DISK_DOS
 config PARTITION_DISK_EFI
 	depends on PARTITION_DISK
 	select CRC32
+	select PRINTF_UUID
 	bool "EFI: GPT partition support"
 	help
 	  Add support to handle partitions in GUID Partition Table style.
diff --git a/common/partitions/efi.c b/common/partitions/efi.c
index 61abf00..a9945dd 100644
--- a/common/partitions/efi.c
+++ b/common/partitions/efi.c
@@ -457,6 +457,7 @@ static void efi_partition(void *buf, struct block_device *blk,
 		pentry->size = le64_to_cpu(ptes[i].ending_lba) - pentry->first_sec;
 		pentry->size++;
 		part_set_efi_name(&ptes[i], pentry->name);
+		snprintf(pentry->partuuid, sizeof(pentry->partuuid), "%pUl", &ptes[i].unique_partition_guid);
 		pd->used_entries++;
 	}
 
-- 
1.8.3.1


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

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

* [PATCH 2/4] of_path: Fix bug with partitions, simply code
  2015-12-17  0:48 [PATCH 1/4] partitions/efi: Add partuuid to partition description Trent Piepho
@ 2015-12-17  0:52 ` Trent Piepho
  2015-12-17  0:52 ` [PATCH 3/4] environment: Support env from file in a file-system via device tree Trent Piepho
  2015-12-17  0:53 ` [PATCH 4/4] socfpga: Find partition with environment " Trent Piepho
  2 siblings, 0 replies; 7+ messages in thread
From: Trent Piepho @ 2015-12-17  0:52 UTC (permalink / raw)
  To: barebox

In commit 75b682795eafb2385556a9642f09e0af96a1264a using a path that
has a partition description broke.

Fix this and simpfy the code some.

There is no need to loop over each string in the path property:  it's
defined to have at most one parition description, no extant dts has
more than one, and how it would handle more than one didn't make sense
anyway.

Once not looping, __of_find_path() just needs the partition
description text, not both the original node and property name to look
it up from.

When using a partition description, don't lookup the cdev of the node
just to replace it with the partition's cdev.

Signed-off-by: Trent Piepho <tpiepho@kymetacorp.com>
---
 drivers/of/of_path.c | 47 +++++++++++++++++++++++++++++------------------
 1 file changed, 29 insertions(+), 18 deletions(-)

diff --git a/drivers/of/of_path.c b/drivers/of/of_path.c
index 6903905..9016147 100644
--- a/drivers/of/of_path.c
+++ b/drivers/of/of_path.c
@@ -106,12 +106,22 @@ out:
 	return ret;
 }
 
-static int __of_find_path(struct device_node *node, const char *propname, char **outpath, unsigned flags)
+/**
+ * __of_find_path
+ *
+ * @node: The node to find the cdev for, can be the device or a
+ *        partition in the device
+ * @part: Optionally, a description of a parition of @node.  See of_find_path
+ * @outpath: if this function returns 0 outpath will contain the path belonging
+ *           to the input path description. Must be freed with free().
+ * @flags: use OF_FIND_PATH_FLAGS_BB to return the .bb device if available
+ *
+ */
+static int __of_find_path(struct device_node *node, const char *part, char **outpath, unsigned flags)
 {
-	struct of_path op = {};
-	const char *str;
+	struct of_path op;
 	bool add_bb = false;
-	int i, ret;
+	int ret;
 
 	op.dev = of_find_device_by_node_path(node->full_name);
 	if (!op.dev) {
@@ -122,23 +132,18 @@ static int __of_find_path(struct device_node *node, const char *propname, char *
 
 	device_detect(op.dev);
 
-	op.cdev = cdev_by_device_node(node);
-
-	i = 1;
-
-	while (propname) {
-		ret = of_property_read_string_index(node, propname, i++, &str);
-		if (ret)
-			break;
-
-		ret = of_path_parse_one(&op, str);
+	if (part) {
+		/* Find a partition inside op.dev */
+		ret = of_path_parse_one(&op, part);
 		if (ret)
 			return ret;
+	} else {
+		/* node points directly to device */
+		op.cdev = cdev_by_device_node(node);
+		if (!op.cdev)
+			return -ENOENT;
 	}
 
-	if (!op.cdev)
-		return -ENOENT;
-
 	if ((flags & OF_FIND_PATH_FLAGS_BB) && op.cdev->mtd &&
 	    mtd_can_have_bb(op.cdev->mtd))
 		add_bb = true;
@@ -193,6 +198,8 @@ int of_find_path(struct device_node *node, const char *propname, char **outpath,
 {
 	struct device_node *rnode;
 	const char *path;
+	const char *part;
+	int ret;
 
 	path = of_get_property(node, propname, NULL);
 	if (!path)
@@ -202,5 +209,9 @@ int of_find_path(struct device_node *node, const char *propname, char **outpath,
 	if (!rnode)
 		return -ENODEV;
 
-	return __of_find_path(rnode, propname, outpath, flags);
+	ret = of_property_read_string_index(node, propname, 1, &part);
+	if (ret)
+		part = NULL;
+
+	return __of_find_path(rnode, part, outpath, flags);
 }
-- 
1.8.3.1


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

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

* [PATCH 3/4] environment: Support env from file in a file-system via device tree
  2015-12-17  0:48 [PATCH 1/4] partitions/efi: Add partuuid to partition description Trent Piepho
  2015-12-17  0:52 ` [PATCH 2/4] of_path: Fix bug with partitions, simply code Trent Piepho
@ 2015-12-17  0:52 ` Trent Piepho
  2015-12-17  0:53 ` [PATCH 4/4] socfpga: Find partition with environment " Trent Piepho
  2 siblings, 0 replies; 7+ messages in thread
From: Trent Piepho @ 2015-12-17  0:52 UTC (permalink / raw)
  To: barebox

Current barebox,environment node only allows specifying a raw device or
partition to load an environment from.  Some boards, like OMAP and
SoCFPGA, instead want to use a file located in a FAT filesystem.
Extend the device tree bindings with a new property 'file-path' that
will trigger this behavior.

This allows any board using this driver to get the env from a file or
from a raw device, instead of each machine type being either raw
device only or file only.

Signed-off-by: Trent Piepho <tpiepho@kymetacorp.com>
---
 .../bindings/barebox/barebox,environment.rst       | 15 ++++++-
 drivers/of/Kconfig                                 |  7 ++++
 drivers/of/barebox.c                               | 47 +++++++++++++++++++++-
 3 files changed, 66 insertions(+), 3 deletions(-)

diff --git a/Documentation/devicetree/bindings/barebox/barebox,environment.rst b/Documentation/devicetree/bindings/barebox/barebox,environment.rst
index d5e52ea..12b103b 100644
--- a/Documentation/devicetree/bindings/barebox/barebox,environment.rst
+++ b/Documentation/devicetree/bindings/barebox/barebox,environment.rst
@@ -6,7 +6,10 @@ This driver provides an environment for barebox from the devicetree.
 Required properties:
 
 * ``compatible``: should be ``barebox,environment``
-* ``device-path``: path to the environment
+* ``device-path``: path to the device environment is on
+
+Optional properties:
+* ``file-path``: path to a file in the device named by device-path
 
 The device-path is a multistring property. The first string should contain
 a nodepath to the node containing the physical device of the environment or
@@ -19,9 +22,19 @@ the path to the environment. Supported values for <type>:
   be the label for MTD partitions, the number for DOS
   partitions (beginning with 0) or the name for GPT partitions.
 
+The file-path is the name of a file located in a FAT filesystem on the
+device named in device-path.  This filesystem will be mounted and the
+environment loaded from the file's location in the directory tree.
+
 Example::
 
   environment@0 {
   	compatible = "barebox,environment";
   	device-path = &flash, "partname:barebox-environment";
   };
+
+  environment@1 {
+  	compatible = "barebox,environment";
+  	device-path = &mmc, "partname:1";
+  	file-path = "barebox.env";
+  };
diff --git a/drivers/of/Kconfig b/drivers/of/Kconfig
index 90475cf..d0a62bd 100644
--- a/drivers/of/Kconfig
+++ b/drivers/of/Kconfig
@@ -43,3 +43,10 @@ config OF_BAREBOX_DRIVERS
 	  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.
+
+config OF_BAREBOX_ENV_IN_FS
+	depends on OF_BAREBOX_DRIVERS
+	bool "Allow environment to come from file"
+	help
+	  Allow the devie tree configuration of the barebox environment path
+	  to specify a file in filesystem, which will be mounted.
diff --git a/drivers/of/barebox.c b/drivers/of/barebox.c
index 1b3078e..125feef 100644
--- a/drivers/of/barebox.c
+++ b/drivers/of/barebox.c
@@ -24,7 +24,46 @@
 #include <malloc.h>
 #include <partition.h>
 #include <envfs.h>
-#include <linux/mtd/mtd.h>
+#include <fs.h>
+
+#define ENV_MNT_DIR "/boot"	/* If env on filesystem, where to mount */
+
+/* If dev describes a file on a fs, mount the fs and change devpath to
+ * point to the file's path.  Otherwise leave devpath alone.  Does
+ * nothing in env in a file support isn't enabled.  */
+static int environment_check_mount(struct device_d *dev, char **devpath)
+{
+	const char *filepath;
+	int ret;
+
+	if (!IS_ENABLED(CONFIG_OF_BAREBOX_ENV_IN_FS))
+		return 0;
+
+	ret = of_property_read_string(dev->device_node, "file-path", &filepath);
+	if (ret == -EINVAL) {
+		/* No file-path so just use device-path */
+		return 0;
+	} else if (ret) {
+		/* file-path property exists, but has error */
+		dev_err(dev, "Problem with file-path property\n");
+		return ret;
+	}
+
+	/* Get device env is on and mount it */
+	mkdir(ENV_MNT_DIR, 0777);
+	ret = mount(*devpath, "fat", ENV_MNT_DIR, NULL);
+	if (ret) {
+		dev_err(dev, "Failed to load environment: mount %s failed (%d)\n",
+			*devpath, ret);
+		return ret;
+	}
+
+	/* Set env to be in a file on the now mounted device */
+	dev_dbg(dev, "Loading default env from %s on device %s\n",
+		filepath, *devpath);
+	*devpath = asprintf("%s/%s", ENV_MNT_DIR, filepath);
+	return 0;
+}
 
 static int environment_probe(struct device_d *dev)
 {
@@ -35,8 +74,12 @@ static int environment_probe(struct device_d *dev)
 	if (ret)
 		return ret;
 
-	dev_info(dev, "setting default environment path to %s\n", path);
+	/* Do we need to mount a fs and find env there? */
+	ret = environment_check_mount(dev, &path);
+	if (ret)
+		return ret;
 
+	dev_dbg(dev, "Setting default environment path to %s\n", path);
 	default_environment_path_set(path);
 
 	return 0;
-- 
1.8.3.1


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

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

* [PATCH 4/4] socfpga: Find partition with environment via device tree
  2015-12-17  0:48 [PATCH 1/4] partitions/efi: Add partuuid to partition description Trent Piepho
  2015-12-17  0:52 ` [PATCH 2/4] of_path: Fix bug with partitions, simply code Trent Piepho
  2015-12-17  0:52 ` [PATCH 3/4] environment: Support env from file in a file-system via device tree Trent Piepho
@ 2015-12-17  0:53 ` Trent Piepho
  2015-12-17 10:07   ` Sascha Hauer
  2 siblings, 1 reply; 7+ messages in thread
From: Trent Piepho @ 2015-12-17  0:53 UTC (permalink / raw)
  To: barebox

socfpga would load the environment from a file named "barebox.env"
located on the device "/dev/mmc0.1".  Both those names are hard-coded
in the socfpga code and can't be changed.

Barebox supports selecting the location of the environment using a
"barebox,environment" node in device tree's "chosen" node.  And
recently supports specifying that the env should come from a file on
this device.

Change socfpga to use this mechanism by adding the appropriate device
node.

Signed-off-by: Trent Piepho <tpiepho@kymetacorp.com>
---
 arch/arm/configs/socfpga_defconfig |  1 +
 arch/arm/dts/socfpga.dtsi          |  8 ++++++++
 arch/arm/mach-socfpga/generic.c    | 38 --------------------------------------
 3 files changed, 9 insertions(+), 38 deletions(-)

diff --git a/arch/arm/configs/socfpga_defconfig b/arch/arm/configs/socfpga_defconfig
index 0a31de5..7fbe045 100644
--- a/arch/arm/configs/socfpga_defconfig
+++ b/arch/arm/configs/socfpga_defconfig
@@ -67,6 +67,7 @@ CONFIG_NET=y
 CONFIG_NET_NETCONSOLE=y
 CONFIG_NET_RESOLV=y
 CONFIG_OF_BAREBOX_DRIVERS=y
+CONFIG_OF_BAREBOX_ENV_IN_FS=y
 CONFIG_DRIVER_SERIAL_NS16550=y
 CONFIG_DRIVER_NET_DESIGNWARE=y
 CONFIG_MCI=y
diff --git a/arch/arm/dts/socfpga.dtsi b/arch/arm/dts/socfpga.dtsi
index d4d498b..d16758f 100644
--- a/arch/arm/dts/socfpga.dtsi
+++ b/arch/arm/dts/socfpga.dtsi
@@ -1,4 +1,12 @@
 / {
+	chosen {
+		environment@0 {
+			compatible = "barebox,environment";
+			device-path = &mmc, "partname:1";
+			file-path = "barebox.env";
+		};
+	};
+
 	aliases {
 		mmc0 = &mmc;
 	};
diff --git a/arch/arm/mach-socfpga/generic.c b/arch/arm/mach-socfpga/generic.c
index 2d4afd0..906bc63 100644
--- a/arch/arm/mach-socfpga/generic.c
+++ b/arch/arm/mach-socfpga/generic.c
@@ -103,41 +103,3 @@ static int socfpga_init(void)
 	return 0;
 }
 core_initcall(socfpga_init);
-
-#if defined(CONFIG_ENV_HANDLING)
-#define ENV_PATH "/boot/barebox.env"
-static int socfpga_env_init(void)
-{
-	struct stat s;
-	char *diskdev, *partname;
-	int ret;
-
-	diskdev = "mmc0";
-
-	device_detect_by_name(diskdev);
-
-	partname = asprintf("/dev/%s.1", diskdev);
-
-	ret = stat(partname, &s);
-
-	if (ret) {
-		pr_err("Failed to load environment: no device '%s'\n", diskdev);
-		goto out_free;
-	}
-
-	mkdir("/boot", 0666);
-	ret = mount(partname, "fat", "/boot", NULL);
-	if (ret) {
-		pr_err("Failed to load environment: mount %s failed (%d)\n", partname, ret);
-		goto out_free;
-	}
-
-	pr_debug("Loading default env from %s on device %s\n", ENV_PATH, diskdev);
-	default_environment_path_set(ENV_PATH);
-
-out_free:
-	free(partname);
-	return 0;
-}
-late_initcall(socfpga_env_init);
-#endif
-- 
1.8.3.1


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

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

* Re: [PATCH 4/4] socfpga: Find partition with environment via device tree
  2015-12-17  0:53 ` [PATCH 4/4] socfpga: Find partition with environment " Trent Piepho
@ 2015-12-17 10:07   ` Sascha Hauer
  2015-12-17 21:13     ` Trent Piepho
  0 siblings, 1 reply; 7+ messages in thread
From: Sascha Hauer @ 2015-12-17 10:07 UTC (permalink / raw)
  To: Trent Piepho; +Cc: barebox

On Thu, Dec 17, 2015 at 12:53:59AM +0000, Trent Piepho wrote:
> socfpga would load the environment from a file named "barebox.env"
> located on the device "/dev/mmc0.1".  Both those names are hard-coded
> in the socfpga code and can't be changed.
> 
> Barebox supports selecting the location of the environment using a
> "barebox,environment" node in device tree's "chosen" node.  And
> recently supports specifying that the env should come from a file on
> this device.
> 
> Change socfpga to use this mechanism by adding the appropriate device
> node.
> 
> Signed-off-by: Trent Piepho <tpiepho@kymetacorp.com>
> ---
>  arch/arm/configs/socfpga_defconfig |  1 +
>  arch/arm/dts/socfpga.dtsi          |  8 ++++++++
>  arch/arm/mach-socfpga/generic.c    | 38 --------------------------------------
>  3 files changed, 9 insertions(+), 38 deletions(-)
> 
> diff --git a/arch/arm/configs/socfpga_defconfig b/arch/arm/configs/socfpga_defconfig
> index 0a31de5..7fbe045 100644
> --- a/arch/arm/configs/socfpga_defconfig
> +++ b/arch/arm/configs/socfpga_defconfig
> @@ -67,6 +67,7 @@ CONFIG_NET=y
>  CONFIG_NET_NETCONSOLE=y
>  CONFIG_NET_RESOLV=y
>  CONFIG_OF_BAREBOX_DRIVERS=y
> +CONFIG_OF_BAREBOX_ENV_IN_FS=y
>  CONFIG_DRIVER_SERIAL_NS16550=y
>  CONFIG_DRIVER_NET_DESIGNWARE=y
>  CONFIG_MCI=y
> diff --git a/arch/arm/dts/socfpga.dtsi b/arch/arm/dts/socfpga.dtsi
> index d4d498b..d16758f 100644
> --- a/arch/arm/dts/socfpga.dtsi
> +++ b/arch/arm/dts/socfpga.dtsi
> @@ -1,4 +1,12 @@
>  / {
> +	chosen {
> +		environment@0 {
> +			compatible = "barebox,environment";
> +			device-path = &mmc, "partname:1";
> +			file-path = "barebox.env";
> +		};
> +	};
> +

I applied this series as is. We might have to move this to the board dts
files later as putting this into the SoC dtsi file does not allow the
boards to put the environment somewhere else. That was not possible
before this patch either, so this doesn't change much at the moment.

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] 7+ messages in thread

* Re: [PATCH 4/4] socfpga: Find partition with environment via device tree
  2015-12-17 10:07   ` Sascha Hauer
@ 2015-12-17 21:13     ` Trent Piepho
  2015-12-18  7:32       ` Sascha Hauer
  0 siblings, 1 reply; 7+ messages in thread
From: Trent Piepho @ 2015-12-17 21:13 UTC (permalink / raw)
  To: Sascha Hauer; +Cc: barebox

On Thu, 2015-12-17 at 11:07 +0100, Sascha Hauer wrote:
> >  / {
> > +	chosen {
> > +		environment@0 {
> > +			compatible = "barebox,environment";
> > +			device-path = &mmc, "partname:1";
> > +			file-path = "barebox.env";
> > +		};
> > +	};
> > +
> 
> I applied this series as is. We might have to move this to the board dts
> files later as putting this into the SoC dtsi file does not allow the
> boards to put the environment somewhere else. That was not possible
> before this patch either, so this doesn't change much at the moment.

It's possible to change in the board dts by adding a
"/chosen/environment@0" node to the dts with whatever properties should
be overridden from the dtsi file's values.  Like how status = "disabled"
in dtsi is changed to status = "okay" in the board file.  I do this for
my board as "partname:1" isn't correct for me.
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

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

* Re: [PATCH 4/4] socfpga: Find partition with environment via device tree
  2015-12-17 21:13     ` Trent Piepho
@ 2015-12-18  7:32       ` Sascha Hauer
  0 siblings, 0 replies; 7+ messages in thread
From: Sascha Hauer @ 2015-12-18  7:32 UTC (permalink / raw)
  To: Trent Piepho; +Cc: barebox

On Thu, Dec 17, 2015 at 09:13:25PM +0000, Trent Piepho wrote:
> On Thu, 2015-12-17 at 11:07 +0100, Sascha Hauer wrote:
> > >  / {
> > > +	chosen {
> > > +		environment@0 {
> > > +			compatible = "barebox,environment";
> > > +			device-path = &mmc, "partname:1";
> > > +			file-path = "barebox.env";
> > > +		};
> > > +	};
> > > +
> > 
> > I applied this series as is. We might have to move this to the board dts
> > files later as putting this into the SoC dtsi file does not allow the
> > boards to put the environment somewhere else. That was not possible
> > before this patch either, so this doesn't change much at the moment.
> 
> It's possible to change in the board dts by adding a
> "/chosen/environment@0" node to the dts with whatever properties should
> be overridden from the dtsi file's values.  Like how status = "disabled"
> in dtsi is changed to status = "okay" in the board file.  I do this for
> my board as "partname:1" isn't correct for me.

We might also have to delete the file-path property in a board dts. I
just learned that this indeed works with /delete-property/ in dtc, but I
am not sure if we should really use this, the deep levels of device tree
includes are already hard enough to track (Not necessarily for socfpga,
but have a look at some i.MX6 SoMs)

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] 7+ messages in thread

end of thread, other threads:[~2015-12-18  7:32 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-12-17  0:48 [PATCH 1/4] partitions/efi: Add partuuid to partition description Trent Piepho
2015-12-17  0:52 ` [PATCH 2/4] of_path: Fix bug with partitions, simply code Trent Piepho
2015-12-17  0:52 ` [PATCH 3/4] environment: Support env from file in a file-system via device tree Trent Piepho
2015-12-17  0:53 ` [PATCH 4/4] socfpga: Find partition with environment " Trent Piepho
2015-12-17 10:07   ` Sascha Hauer
2015-12-17 21:13     ` Trent Piepho
2015-12-18  7:32       ` Sascha Hauer

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