mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Fabian Pflug <f.pflug@pengutronix.de>
To: barebox@lists.infradead.org
Cc: Fabian Pflug <f.pflug@pengutronix.de>,
	Ahmad Fatoum <a.fatoum@pengutronix.de>
Subject: [PATCH v5 3/4] bootm: use new api to get kernel command line params
Date: Mon,  1 Dec 2025 08:20:59 +0100	[thread overview]
Message-ID: <20251201072452.1829564-4-f.pflug@pengutronix.de> (raw)
In-Reply-To: <20251201072452.1829564-1-f.pflug@pengutronix.de>

Getting root device and root kernel options seperatly and combining
them in this function instead of getting the full string from the helper
functions. This is in preparation for replacing the root= string in the
kernel commandline with something defined during runtime.

Signed-off-by: Fabian Pflug <f.pflug@pengutronix.de>
Reviewed-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 common/bootm.c | 23 +++++++++++++++++------
 fs/fs.c        | 26 --------------------------
 include/fs.h   |  1 -
 3 files changed, 17 insertions(+), 33 deletions(-)

diff --git a/common/bootm.c b/common/bootm.c
index 17792b2a1d..adc76eba64 100644
--- a/common/bootm.c
+++ b/common/bootm.c
@@ -1,9 +1,11 @@
 // SPDX-License-Identifier: GPL-2.0-or-later
 
 #include <common.h>
+#include <bootargs.h>
 #include <bootm.h>
 #include <bootm-overrides.h>
 #include <fs.h>
+#include <fcntl.h>
 #include <malloc.h>
 #include <memory.h>
 #include <block.h>
@@ -841,33 +843,42 @@ int bootm_boot(struct bootm_data *bootm_data)
 	}
 
 	if (bootm_data->appendroot) {
-		char *rootarg;
+		char *root = NULL;
+		char *rootopts = NULL;
 
 		if (bootm_data->root_dev) {
 			const char *root_dev_name = devpath_to_name(bootm_data->root_dev);
 			struct cdev *root_cdev = cdev_open_by_name(root_dev_name, O_RDONLY);
 
-			rootarg = cdev_get_linux_rootarg(root_cdev);
-			if (!rootarg) {
-				rootarg = ERR_PTR(-EINVAL);
+			ret = cdev_get_linux_root_and_opts(root_cdev, &root, &rootopts);
 
+			if (ret) {
 				if (!root_cdev)
 					pr_err("no cdev found for %s, cannot set root= option\n",
 						root_dev_name);
 				else if (!root_cdev->partuuid[0])
 					pr_err("%s doesn't have a PARTUUID, cannot set root= option\n",
 						root_dev_name);
+				else
+					pr_err("could not determine root= from %s\n",
+						root_dev_name);
 			}
 
 			if (root_cdev)
 				cdev_close(root_cdev);
 		} else {
-			rootarg = path_get_linux_rootarg(data->os_file);
+			struct fs_device *fsdev = get_fsdevice_by_path(AT_FDCWD, data->os_file);
+			if (fsdev)
+				fsdev_get_linux_root_options(fsdev, &root, &rootopts);
+			else
+				pr_err("no fsdevice under path: %s\n", data->os_file);
 		}
 
-		if (IS_ERR(rootarg)) {
+		if (!root) {
 			pr_err("Failed to append kernel cmdline parameter 'root='\n");
 		} else {
+			char *rootarg;
+			rootarg = format_root_bootarg("root", root, rootopts);
 			pr_info("Adding \"%s\" to Kernel commandline\n", rootarg);
 			globalvar_add_simple("linux.bootargs.bootm.appendroot",
 					     rootarg);
diff --git a/fs/fs.c b/fs/fs.c
index 0f27879395..ae6a776b2b 100644
--- a/fs/fs.c
+++ b/fs/fs.c
@@ -1257,32 +1257,6 @@ char *format_root_bootarg(const char *root_arg, char *root, char *rootopts) {
 	return bootarg;
 }
 
-/**
- * path_get_linux_rootarg() - Given a path return a suitable root= option for
- *                            Linux
- * @path: The path
- *
- * Return: A string containing the root= option or an ERR_PTR. the returned
- *         string must be freed by the caller.
- */
-char *path_get_linux_rootarg(const char *path)
-{
-	struct fs_device *fsdev;
-	char *root = NULL;
-	char *rootopts = NULL;
-
-	fsdev = get_fsdevice_by_path(AT_FDCWD, path);
-	if (!fsdev)
-		return ERR_PTR(-ENOSYS);
-
-	fsdev_get_linux_root_options(fsdev, &root, &rootopts);
-
-	if (!root)
-		return ERR_PTR(-ENOSYS);
-
-	return format_root_bootarg("root", root, rootopts);
-}
-
 /**
  * __is_tftp_fs() - return true when path is mounted on TFTP
  * @path: The path
diff --git a/include/fs.h b/include/fs.h
index c50437d609..ddd93e93ec 100644
--- a/include/fs.h
+++ b/include/fs.h
@@ -162,7 +162,6 @@ void mount_all(void);
 
 void fsdev_set_linux_root_options(struct fs_device *fsdev, const char *root, const char* rootopts);
 void fsdev_get_linux_root_options(struct fs_device *fsdev, char **root, char **rootopts);
-char *path_get_linux_rootarg(const char *path);
 
 static inline const char *devpath_to_name(const char *devpath)
 {
-- 
2.47.3




  parent reply	other threads:[~2025-12-01  7:25 UTC|newest]

Thread overview: 41+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-11-24 10:16 [PATCH] common: setting the root= command line parameter Fabian Pflug
2025-11-24 12:00 ` Ahmad Fatoum
2025-11-25 10:22   ` Fabian Pflug
2025-11-25 19:13     ` Ahmad Fatoum
2025-11-26  6:42   ` [PATCH 0/4] make the root= command line parameter variable Fabian Pflug
2025-11-26  6:42     ` [PATCH 1/4] block.h: renamed get_rootargs to get_root Fabian Pflug
2025-11-26  9:50       ` Ahmad Fatoum
2025-11-26  6:42     ` [PATCH 2/4] fs: split rootargs into root and options Fabian Pflug
2025-11-26 10:13       ` Ahmad Fatoum
2025-11-26 10:31       ` Ahmad Fatoum
2025-11-26  6:42     ` [PATCH 3/4] bootm: use new api to get kernel command line params Fabian Pflug
2025-11-26 10:25       ` Ahmad Fatoum
2025-11-26 11:29         ` Fabian Pflug
2025-11-26 11:33           ` Ahmad Fatoum
2025-11-26  6:42     ` [PATCH 4/4] bootm: introduce bootm.root_arg variable Fabian Pflug
2025-11-26 10:28       ` Ahmad Fatoum
2025-11-27 10:57     ` [PATCH v2 0/4] make the root= command line parameter variable Fabian Pflug
2025-11-27 10:57       ` [PATCH v2 1/4] block.h: renamed get_rootargs to get_root Fabian Pflug
2025-11-27 11:08         ` Ahmad Fatoum
2025-11-27 10:57       ` [PATCH v2 2/4] fs: split rootargs into root and options Fabian Pflug
2025-11-27 10:57       ` [PATCH v2 3/4] bootm: use new api to get kernel command line params Fabian Pflug
2025-11-27 10:57       ` [PATCH v2 4/4] bootm: introduce bootm.root_arg variable Fabian Pflug
2025-11-27 14:25       ` [PATCH v3 0/4] make the root= command line parameter variable Fabian Pflug
2025-11-27 14:25         ` [PATCH v3 1/4] block.h: renamed get_rootargs to get_root Fabian Pflug
2025-11-28  9:45           ` Ahmad Fatoum
2025-11-27 14:25         ` [PATCH v3 2/4] fs: split rootargs into root and options Fabian Pflug
2025-11-28 10:01           ` Ahmad Fatoum
2025-11-27 14:25         ` [PATCH v3 3/4] bootm: use new api to get kernel command line params Fabian Pflug
2025-11-28 10:04           ` Ahmad Fatoum
2025-11-27 14:25         ` [PATCH v3 4/4] bootm: introduce bootm.root_arg variable Fabian Pflug
2025-11-28 10:07           ` Ahmad Fatoum
2025-11-28 14:58         ` [PATCH v4 0/4] make the root= command line parameter variable Fabian Pflug
2025-11-28 14:59           ` [PATCH v4 1/4] block.h: renamed get_rootargs to get_root Fabian Pflug
2025-11-28 14:59           ` [PATCH 2/4] fs: split rootargs into root and options Fabian Pflug
2025-11-28 14:59           ` [PATCH v4 3/4] bootm: use new api to get kernel command line params Fabian Pflug
2025-11-28 14:59           ` [PATCH v4 4/4] bootm: introduce bootm.root_arg variable Fabian Pflug
2025-12-01  7:20           ` [PATCH v5 0/4] make the root= command line parameter variable Fabian Pflug
2025-12-01  7:20             ` [PATCH v5 1/4] block.h: renamed get_rootargs to get_root Fabian Pflug
2025-12-01  7:20             ` [PATCH v5 2/4] fs: split rootargs into root and options Fabian Pflug
2025-12-01  7:20             ` Fabian Pflug [this message]
2025-12-01  7:21             ` [PATCH v5 4/4] bootm: introduce bootm.root_param variable Fabian Pflug

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=20251201072452.1829564-4-f.pflug@pengutronix.de \
    --to=f.pflug@pengutronix.de \
    --cc=a.fatoum@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    /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