mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Sascha Hauer <s.hauer@pengutronix.de>
To: Barebox List <barebox@lists.infradead.org>
Cc: Alexander Shiyan <eagle.alexander923@gmail.com>
Subject: [PATCH] barebox-environment: Use default mount path
Date: Fri, 28 Feb 2025 09:02:14 +0100	[thread overview]
Message-ID: <20250228080214.1319495-1-s.hauer@pengutronix.de> (raw)

When using a file inside a partition for the barebox environment we
mount the partition to a non standard path ("/boot") which can cause
problems with autmounting. Mount the partition to the standard location
and create a symlink from /boot to the mounted path.

Reported-by: Alexander Shiyan <eagle.alexander923@gmail.com>
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 drivers/of/barebox.c | 25 ++++++++++++++++++-------
 1 file changed, 18 insertions(+), 7 deletions(-)

diff --git a/drivers/of/barebox.c b/drivers/of/barebox.c
index e6bcff7116..e52cdcf52a 100644
--- a/drivers/of/barebox.c
+++ b/drivers/of/barebox.c
@@ -35,7 +35,9 @@ static char *environment_probe_2node_binding(struct device *dev)
 {
 	const char *filepath;
 	char *devpath = NULL;
+	const char *path = NULL;
 	int ret;
+	struct cdev *cdev;
 
 	ret = of_find_path(dev->of_node, "device-path", &devpath,
 			   OF_FIND_PATH_FLAGS_BB);
@@ -55,22 +57,31 @@ static char *environment_probe_2node_binding(struct device *dev)
 		goto out;
 	}
 
-	/* 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);
+	cdev = cdev_by_name(kbasename(devpath));
+	if (!cdev) {
+		dev_err(dev, "Cannot find device for %s\n", devpath);
+		ret = -ENOENT;
 		goto out;
 	}
 
+	path = cdev_mount_default(cdev, NULL);
+	if (IS_ERR(path)) {
+		dev_err(dev, "Cannot mount %s\n", devpath);
+		ret = PTR_ERR(path);
+		goto out;
+	}
+
+	symlink(path, ENV_MNT_DIR);
+
 	/* 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);
 
+	ret = 0;
+
 out:
 	free(devpath);
-	return ret ? ERR_PTR(ret) : basprintf("%s/%s", ENV_MNT_DIR, filepath);
+	return ret ? ERR_PTR(ret) : basprintf("%s/%s", path, filepath);
 }
 
 static int environment_probe(struct device *dev)
-- 
2.39.5




             reply	other threads:[~2025-02-28  8:02 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-02-28  8:02 Sascha Hauer [this message]
2025-02-28  8:19 ` Alexander Shiyan
2025-03-11  8:50 ` Sascha Hauer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250228080214.1319495-1-s.hauer@pengutronix.de \
    --to=s.hauer@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    --cc=eagle.alexander923@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox