mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH] socfpga: Find partition with environment via device tree
@ 2015-12-11  2:13 Trent Piepho
  2015-12-11  9:30 ` Sascha Hauer
  0 siblings, 1 reply; 6+ messages in thread
From: Trent Piepho @ 2015-12-11  2:13 UTC (permalink / raw)
  To: barebox

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

Change socfpga to use this mechanism by looking for barebox.env in the
device or partition specified in the device tree.

The filename is still hard-coded.  Someone who wants to change it
could put that into the device tree too (new file-name property?  3rd
string in device-path?).

Remove the stat() call in socfpga_env_init(), as mount() already
checks if the device exists.  Also remove device_detect_by_name() call
as the barebox env device code now takes care of that for us.

Signed-off-by: Trent Piepho <tpiepho@kymetacorp.com>
---

OMAP could do the same thing...

 arch/arm/dts/socfpga.dtsi       |  7 +++++++
 arch/arm/mach-socfpga/generic.c | 37 +++++++++++++------------------------
 2 files changed, 20 insertions(+), 24 deletions(-)

diff --git a/arch/arm/dts/socfpga.dtsi b/arch/arm/dts/socfpga.dtsi
index d4d498b..1d0d6ff 100644
--- a/arch/arm/dts/socfpga.dtsi
+++ b/arch/arm/dts/socfpga.dtsi
@@ -1,4 +1,11 @@
 / {
+	chosen {
+                environment@0 {
+                        compatible = "barebox,environment";
+                        device-path = &mmc, "partname:1";
+                };
+	};
+
 	aliases {
 		mmc0 = &mmc;
 	};
diff --git a/arch/arm/mach-socfpga/generic.c b/arch/arm/mach-socfpga/generic.c
index 2d4afd0..46f9415 100644
--- a/arch/arm/mach-socfpga/generic.c
+++ b/arch/arm/mach-socfpga/generic.c
@@ -105,38 +105,27 @@ static int socfpga_init(void)
 core_initcall(socfpga_init);
 
 #if defined(CONFIG_ENV_HANDLING)
-#define ENV_PATH "/boot/barebox.env"
+#define ENV_PATH "/boot"		/* Where to mount env device */
+#define ENV_FILE "barebox.env"		/* File on device to use */
+
 static int socfpga_env_init(void)
 {
-	struct stat s;
-	char *diskdev, *partname;
+	const char *device;
 	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);
+	/* Get device env is on and mount it */
+	device = default_environment_path_get();
+	mkdir(ENV_PATH, 0777);
+	ret = mount(device, "fat", ENV_PATH, NULL);
 	if (ret) {
-		pr_err("Failed to load environment: mount %s failed (%d)\n", partname, ret);
-		goto out_free;
+		pr_err("Failed to load environment: mount %s failed (%d)\n", device, ret);
+		return ret;
 	}
 
-	pr_debug("Loading default env from %s on device %s\n", ENV_PATH, diskdev);
-	default_environment_path_set(ENV_PATH);
+	/* Change env to be in a file on the now mounted device */
+	pr_debug("Loading default env from %s on device %s\n", ENV_FILE, device);
+	default_environment_path_set(ENV_PATH "/" ENV_FILE);
 
-out_free:
-	free(partname);
 	return 0;
 }
 late_initcall(socfpga_env_init);
-- 
1.8.3.1


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

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

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

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-12-11  2:13 [PATCH] socfpga: Find partition with environment via device tree Trent Piepho
2015-12-11  9:30 ` Sascha Hauer
2015-12-11 20:05   ` Trent Piepho
2015-12-14 10:01     ` Sascha Hauer
2015-12-14 19:24       ` Trent Piepho
2015-12-15  7:11         ` Sascha Hauer

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