diff mbox series

[2/3] Utility: detect and return root device

Message ID 20211014154637.2674613-2-sbabic@denx.de
State Accepted
Headers show
Series [1/3] cosmetic: sort entries in getopt list | expand

Commit Message

Stefano Babic Oct. 14, 2021, 3:46 p.m. UTC
This can be used in startup scripts before starting the daemon. It helps
to simplify scripts, and retrurns the device where root is mounted.

To call it:

	swupdate -g
		or
	swupdate --get-root

Signed-off-by: Stefano Babic <sbabic@denx.de>
---
 core/swupdate.c         | 12 +++++++++++-
 doc/source/swupdate.rst |  2 ++
 2 files changed, 13 insertions(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/core/swupdate.c b/core/swupdate.c
index 3ad18e2..d651f8e 100644
--- a/core/swupdate.c
+++ b/core/swupdate.c
@@ -79,6 +79,7 @@  static struct option long_options[] = {
 #endif
 	{"dry-run", no_argument, NULL, 'n'},
 	{"file", required_argument, NULL, 'f'},
+	{"get-root", no_argument, NULL, 'g'},
 	{"help", no_argument, NULL, 'h'},
 #ifdef CONFIG_HW_COMPATIBILITY
 	{"hwrevision", required_argument, NULL, 'H'},
@@ -433,7 +434,7 @@  int main(int argc, char **argv)
 #endif
 	memset(main_options, 0, sizeof(main_options));
 	memset(image_url, 0, sizeof(image_url));
-	strcpy(main_options, "vhni:e:q:l:Lcf:p:P:o:N:R:Mm");
+	strcpy(main_options, "vhni:e:gq:l:Lcf:p:P:o:N:R:Mm");
 #ifdef CONFIG_MTD
 	strcat(main_options, "b:");
 #endif
@@ -476,9 +477,18 @@  int main(int argc, char **argv)
 	while ((c = getopt_long(argc, argv, main_options,
 				long_options, NULL)) != EOF) {
 		switch (c) {
+		char *root;
 		case 'f':
 			cfgfname = sdup(optarg);
 			break;
+		case 'g':
+			root = get_root_device();
+			if (root) {
+				printf("%s\n", root);
+				free(root);
+			}
+			exit(EXIT_SUCCESS);
+			break;
 		case 'l':
 			loglevel = strtoul(optarg, NULL, 10);
 			break;
diff --git a/doc/source/swupdate.rst b/doc/source/swupdate.rst
index a81b87a..fb335ad 100644
--- a/doc/source/swupdate.rst
+++ b/doc/source/swupdate.rst
@@ -500,6 +500,8 @@  Command line parameters
 | --ca-\      | string   | Available if CONFIG_SIGNED_IMAGES is set.  |
 | path <file> |          | Path to the Certificate Authority (PEM).   |
 +-------------+----------+--------------------------------------------+
+| --get-root  |          | Detect and print the root device and exit  |
++-------------+----------+--------------------------------------------+
 | -l <level>  | int      | Set loglevel.                              |
 +-------------+----------+--------------------------------------------+
 | -L          |    -     | Send LOG output to syslog (local).         |