[PATCH v2 3/3] commands: devlookup: add option to print kernel root option
Ahmad Fatoum
a.fatoum at pengutronix.de
Fri Apr 4 11:23:45 PDT 2025
There exists currently no way to view the kernel root option that
barebox would generate when instructed to via global.bootm.root_dev,
but without actually mounting the file system.
Add a new -k option that can print this. This can be useful in scripts
that want to fixup the root line, so it's interpreted by the rdinit, but
not by the kernel.
Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
---
commands/devlookup.c | 38 ++++++++++++++++++++++++++++----------
1 file changed, 28 insertions(+), 10 deletions(-)
diff --git a/commands/devlookup.c b/commands/devlookup.c
index 4a2c9b773661..0d4c6e808b60 100644
--- a/commands/devlookup.c
+++ b/commands/devlookup.c
@@ -8,26 +8,36 @@
#include <linux/stat.h>
#include <linux/ctype.h>
#include <environment.h>
+#include <block.h>
static int do_devlookup(int argc, char *argv[])
{
const char *variable = NULL, *devicefile, *paramname;
struct cdev *cdev;
int opt, ret;
+ bool kernelopt = false;
+ const char *val;
+ char *buf = NULL;
- while ((opt = getopt(argc, argv, "v:")) > 0) {
+ while ((opt = getopt(argc, argv, "v:k")) > 0) {
switch(opt) {
case 'v':
variable = optarg;
break;
+ case 'k':
+ kernelopt = true;
+ break;
}
}
- if (argc - optind == 0 || argc - optind > 2)
+ argv += optind;
+ argc -= optind;
+
+ if (argc == 0 || argc > 2 || (kernelopt && argc != 1))
return COMMAND_ERROR_USAGE;
- devicefile = argv[optind];
- paramname = argv[optind + 1];
+ devicefile = argv[0];
+ paramname = argv[1];
devicefile = devpath_to_name(devicefile);
@@ -43,11 +53,16 @@ static int do_devlookup(int argc, char *argv[])
goto out;
}
- if (paramname)
- ret = cmd_export_val(variable, dev_get_param(cdev->dev, paramname));
+ if (kernelopt)
+ val = buf = cdev_get_linux_rootarg(cdev);
+ else if (paramname)
+ val = dev_get_param(cdev->dev, paramname);
else
- ret = cmd_export_val(variable, dev_name(cdev->dev));
+ val = dev_name(cdev->dev);
+
+ ret = cmd_export_val(variable, val);
out:
+ free(buf);
cdev_close(cdev);
return ret;
@@ -56,14 +71,17 @@ static int do_devlookup(int argc, char *argv[])
BAREBOX_CMD_HELP_START(devlookup)
BAREBOX_CMD_HELP_TEXT("Detects the device behind a device file and outputs it,")
BAREBOX_CMD_HELP_TEXT("unless a second argument is given. In that case the device")
-BAREBOX_CMD_HELP_TEXT("parameter with that name is looked up. Specifying -v VARIABLE")
-BAREBOX_CMD_HELP_TEXT("will write output to VARIABLE instead of printing it")
+BAREBOX_CMD_HELP_TEXT("parameter with that name is looked up.")
+BAREBOX_CMD_HELP_TEXT("")
+BAREBOX_CMD_HELP_TEXT("Options:")
+BAREBOX_CMD_HELP_OPT ("-v", "write output to VARIABLE instead of printing it")
+BAREBOX_CMD_HELP_OPT ("-k", "output kernel rootarg line")
BAREBOX_CMD_HELP_END
BAREBOX_CMD_START(devlookup)
.cmd = do_devlookup,
BAREBOX_CMD_DESC("look up device behind device file and its parameters")
- BAREBOX_CMD_OPTS("[-v VAR] /dev/DEVICE [parameter]")
+ BAREBOX_CMD_OPTS("[-v VAR] [-k] /dev/DEVICE [parameter]")
BAREBOX_CMD_GROUP(CMD_GRP_SCRIPT)
BAREBOX_CMD_HELP(cmd_devlookup_help)
BAREBOX_CMD_END
--
2.39.5
More information about the barebox
mailing list