mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH] ARM: k3: implement environment handling
@ 2024-11-12  9:01 Sascha Hauer
  2024-11-13 11:33 ` Sascha Hauer
  0 siblings, 1 reply; 2+ messages in thread
From: Sascha Hauer @ 2024-11-12  9:01 UTC (permalink / raw)
  To: Barebox List

When booting from SD/eMMC TI SoCs start from a FAT partition. mount this
partition to /boot and put the barebox environment there.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 arch/arm/mach-k3/common.c | 60 +++++++++++++++++++++++++++++++++++++++
 1 file changed, 60 insertions(+)

diff --git a/arch/arm/mach-k3/common.c b/arch/arm/mach-k3/common.c
index 0da6f76ae4..13f3f5e169 100644
--- a/arch/arm/mach-k3/common.c
+++ b/arch/arm/mach-k3/common.c
@@ -3,6 +3,10 @@
 #include <io.h>
 #include <deep-probe.h>
 #include <init.h>
+#include <envfs.h>
+#include <fs.h>
+#include <xfuncs.h>
+#include <malloc.h>
 #include <pm_domain.h>
 #include <bootsource.h>
 #include <linux/bits.h>
@@ -183,3 +187,59 @@ static int am625_init(void)
 	return 0;
 }
 postcore_initcall(am625_init);
+
+#if defined(CONFIG_ENV_HANDLING)
+static int omap_env_init(void)
+{
+	char *partname, *cdevname, *envpath;
+	struct cdev *cdev;
+	const char *rootpath;
+	int instance;
+
+	if (!of_machine_is_compatible("ti,am625"))
+		return 0;
+
+	if (bootsource_get() != BOOTSOURCE_MMC)
+		return 0;
+
+	instance = bootsource_get_instance();
+
+	cdevname = xasprintf("mmc%d", instance);
+	partname = xasprintf("mmc%d.0", instance);
+
+	device_detect_by_name(cdevname);
+
+	cdev = cdev_open_by_name(partname, O_RDONLY);
+	if (!cdev) {
+		pr_err("Failed to get device %s\n", partname);
+		goto out;
+	}
+
+	rootpath = cdev_mount_default(cdev, NULL);
+
+	cdev_close(cdev);
+
+	if (IS_ERR(rootpath)) {
+		pr_err("Failed to load environment: mount %s failed (%ld)\n",
+						cdev->name, PTR_ERR(rootpath));
+		goto out;
+	}
+
+	symlink(rootpath, "/boot");
+
+	envpath = xasprintf("%s/barebox.env", rootpath);
+
+	pr_debug("Loading default env from %s on device %s\n",
+		 envpath, partname);
+
+	default_environment_path_set(envpath);
+
+	free(envpath);
+out:
+	free(partname);
+	free(cdevname);
+
+	return 0;
+}
+late_initcall(omap_env_init);
+#endif
-- 
2.39.5




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

end of thread, other threads:[~2024-11-13 11:34 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-11-12  9:01 [PATCH] ARM: k3: implement environment handling Sascha Hauer
2024-11-13 11:33 ` Sascha Hauer

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