mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH] barebox-environment: Use default mount path
@ 2025-02-28  8:02 Sascha Hauer
  2025-02-28  8:19 ` Alexander Shiyan
  2025-03-11  8:50 ` Sascha Hauer
  0 siblings, 2 replies; 3+ messages in thread
From: Sascha Hauer @ 2025-02-28  8:02 UTC (permalink / raw)
  To: Barebox List; +Cc: Alexander Shiyan

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




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

* Re: [PATCH] barebox-environment: Use default mount path
  2025-02-28  8:02 [PATCH] barebox-environment: Use default mount path Sascha Hauer
@ 2025-02-28  8:19 ` Alexander Shiyan
  2025-03-11  8:50 ` Sascha Hauer
  1 sibling, 0 replies; 3+ messages in thread
From: Alexander Shiyan @ 2025-02-28  8:19 UTC (permalink / raw)
  To: Sascha Hauer; +Cc: Barebox List

Tested-by: Alexander Shiyan <eagle.alexander923@gmail.com>

пт, 28 февр. 2025 г. в 11:02, Sascha Hauer <s.hauer@pengutronix.de>:
>
> 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
>



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

* Re: [PATCH] barebox-environment: Use default mount path
  2025-02-28  8:02 [PATCH] barebox-environment: Use default mount path Sascha Hauer
  2025-02-28  8:19 ` Alexander Shiyan
@ 2025-03-11  8:50 ` Sascha Hauer
  1 sibling, 0 replies; 3+ messages in thread
From: Sascha Hauer @ 2025-03-11  8:50 UTC (permalink / raw)
  To: Barebox List, Sascha Hauer; +Cc: Alexander Shiyan


On Fri, 28 Feb 2025 09:02:14 +0100, Sascha Hauer wrote:
> 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.
> 
> 

Applied, thanks!

[1/1] barebox-environment: Use default mount path
      https://git.pengutronix.de/cgit/barebox/commit/?id=4042480fc709 (link may not be stable)

Best regards,
-- 
Sascha Hauer <s.hauer@pengutronix.de>




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

end of thread, other threads:[~2025-03-11  8:51 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-02-28  8:02 [PATCH] barebox-environment: Use default mount path Sascha Hauer
2025-02-28  8:19 ` Alexander Shiyan
2025-03-11  8:50 ` Sascha Hauer

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