* [PATCH 1/2] environment: Support env from file in a file-system via device tree
@ 2015-12-11 22:32 Trent Piepho
2015-12-11 22:37 ` Trent Piepho
0 siblings, 1 reply; 5+ messages in thread
From: Trent Piepho @ 2015-12-11 22:32 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] 5+ messages in thread
* Re: [PATCH 1/2] environment: Support env from file in a file-system via device tree
2015-12-11 22:32 [PATCH 1/2] environment: Support env from file in a file-system via device tree Trent Piepho
@ 2015-12-11 22:37 ` Trent Piepho
2015-12-16 10:52 ` Sascha Hauer
0 siblings, 1 reply; 5+ messages in thread
From: Trent Piepho @ 2015-12-11 22:37 UTC (permalink / raw)
To: barebox
From d8f4428244b3c7009a6ef7d5a97a00747cd19472 Mon Sep 17 00:00:00 2001
From: Trent Piepho <tpiepho@kymetacorp.com>
Date: Fri, 11 Dec 2015 14:19:34 -0800
Subject: [PATCH 2/2] socfpga: Find partition with environment via device tree
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] 5+ messages in thread
* Re: [PATCH 1/2] environment: Support env from file in a file-system via device tree
2015-12-11 22:37 ` Trent Piepho
@ 2015-12-16 10:52 ` Sascha Hauer
2015-12-17 0:31 ` Trent Piepho
0 siblings, 1 reply; 5+ messages in thread
From: Sascha Hauer @ 2015-12-16 10:52 UTC (permalink / raw)
To: Trent Piepho; +Cc: barebox
On Fri, Dec 11, 2015 at 10:37:34PM +0000, Trent Piepho wrote:
> From d8f4428244b3c7009a6ef7d5a97a00747cd19472 Mon Sep 17 00:00:00 2001
> From: Trent Piepho <tpiepho@kymetacorp.com>
> Date: Fri, 11 Dec 2015 14:19:34 -0800
> Subject: [PATCH 2/2] socfpga: Find partition with environment via device tree
The subject in this mail is wrong. The correct subject is here, but 'git
am' takes the one from the mail.
I thought over it and I am fine with the approach of putting the
filename as an additional property into the barebox,environment node.
Also I am fine with the "of_path: Fix bug with partitions, simply code"
patch, only I can not find the commitish that broke the partition code.
I somewhat lost track over your outstanding patches. Could you resend
all of them in a single series?
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] 5+ messages in thread
* Re: [PATCH 1/2] environment: Support env from file in a file-system via device tree
2015-12-16 10:52 ` Sascha Hauer
@ 2015-12-17 0:31 ` Trent Piepho
2015-12-17 10:12 ` Sascha Hauer
0 siblings, 1 reply; 5+ messages in thread
From: Trent Piepho @ 2015-12-17 0:31 UTC (permalink / raw)
To: Sascha Hauer; +Cc: barebox
On Wed, 2015-12-16 at 11:52 +0100, Sascha Hauer wrote:
> On Fri, Dec 11, 2015 at 10:37:34PM +0000, Trent Piepho wrote:
> > From d8f4428244b3c7009a6ef7d5a97a00747cd19472 Mon Sep 17 00:00:00 2001
> > From: Trent Piepho <tpiepho@kymetacorp.com>
> > Date: Fri, 11 Dec 2015 14:19:34 -0800
> > Subject: [PATCH 2/2] socfpga: Find partition with environment via device tree
>
> The subject in this mail is wrong. The correct subject is here, but 'git
> am' takes the one from the mail.
IMAP and POP aren't supported at work so I can't use git send-email and
must instead manually import the patches into a mailer that supports
EWS. I must have forgotten to copy the subject on that one.
> I thought over it and I am fine with the approach of putting the
> filename as an additional property into the barebox,environment node.
>
> Also I am fine with the "of_path: Fix bug with partitions, simply code"
> patch, only I can not find the commitish that broke the partition code.
I used my local rebased branch by mistake, it should have been
75b682795eafb2385556a9642f09e0af96a1264a
> I somewhat lost track over your outstanding patches. Could you resend
> all of them in a single series?
Ok. Have you considered using patchwork for this list? I've found it
pretty useful for keeping track of patches.
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH 1/2] environment: Support env from file in a file-system via device tree
2015-12-17 0:31 ` Trent Piepho
@ 2015-12-17 10:12 ` Sascha Hauer
0 siblings, 0 replies; 5+ messages in thread
From: Sascha Hauer @ 2015-12-17 10:12 UTC (permalink / raw)
To: Trent Piepho; +Cc: barebox
On Thu, Dec 17, 2015 at 12:31:55AM +0000, Trent Piepho wrote:
> On Wed, 2015-12-16 at 11:52 +0100, Sascha Hauer wrote:
> > On Fri, Dec 11, 2015 at 10:37:34PM +0000, Trent Piepho wrote:
> > > From d8f4428244b3c7009a6ef7d5a97a00747cd19472 Mon Sep 17 00:00:00 2001
> > > From: Trent Piepho <tpiepho@kymetacorp.com>
> > > Date: Fri, 11 Dec 2015 14:19:34 -0800
> > > Subject: [PATCH 2/2] socfpga: Find partition with environment via device tree
> >
> > The subject in this mail is wrong. The correct subject is here, but 'git
> > am' takes the one from the mail.
>
> IMAP and POP aren't supported at work so I can't use git send-email and
> must instead manually import the patches into a mailer that supports
> EWS. I must have forgotten to copy the subject on that one.
>
> > I thought over it and I am fine with the approach of putting the
> > filename as an additional property into the barebox,environment node.
> >
> > Also I am fine with the "of_path: Fix bug with partitions, simply code"
> > patch, only I can not find the commitish that broke the partition code.
>
> I used my local rebased branch by mistake, it should have been
> 75b682795eafb2385556a9642f09e0af96a1264a
>
> > I somewhat lost track over your outstanding patches. Could you resend
> > all of them in a single series?
>
> Ok. Have you considered using patchwork for this list? I've found it
> pretty useful for keeping track of patches.
I have tried it a few years ago, but never got really warm with it.
patchwork requires some maintenance and usually I am quite happy with my
workflow. Only sometimes when there are several updates to a patch,
patches that do not really depend on each other but are still somehow
related with each other it feels better when everything is resent
freshly.
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] 5+ messages in thread
end of thread, other threads:[~2015-12-17 10:13 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-12-11 22:32 [PATCH 1/2] environment: Support env from file in a file-system via device tree Trent Piepho
2015-12-11 22:37 ` Trent Piepho
2015-12-16 10:52 ` Sascha Hauer
2015-12-17 0:31 ` Trent Piepho
2015-12-17 10:12 ` Sascha Hauer
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox