[PATCH 8/8] cmd: config: allow simple filtering of output

Rasmus Villemoes rv at rasmusvillemoes.dk
Wed Jul 1 19:15:35 CEST 2026


When doing development, it can be quite useful to enable
CONFIG_CMD_CONFIG, so that one can always check whether a config knob
one has just enabled has actually made it to target.

Because sometimes, one doesn't flash the right binary, or maybe one
has just done CONFIG_FOO=y in some config fragment, but that had no
effect because one would also have to do CONFIG_BAR=y.

However, 2400+ lines of text are rather hard to read through. One
probably uses a terminal emulator with capturing enabled, but
searching back through the capture file is a little tedious, and one
easily ends up finding something that doesn't pertain to the most
recent 'config' command invocation.

So make it possible to limit the output to those lines containing a
given string. Like the search functionality in menuconfig, make it
case insensitive, because it is much more convenient to type "config
pinctrl" than "config PINCTRL".

Since enabling CONFIG_CMD_CONFIG by itself adds over 10K of data, and
that increases with every U-Boot release even if one doesn't add any
new features to one's own defconfig (because the .config grows lots of
"is not set"), I don't see any point in guarding this by some
CONFIG_CMD_CONFIG_GREP.

Signed-off-by: Rasmus Villemoes <rv at rasmusvillemoes.dk>
---
 cmd/config.c | 25 ++++++++++++++++++++++---
 1 file changed, 22 insertions(+), 3 deletions(-)

diff --git a/cmd/config.c b/cmd/config.c
index f0d2033c61f..3a6da55b0ef 100644
--- a/cmd/config.c
+++ b/cmd/config.c
@@ -29,7 +29,23 @@ static int do_config(struct cmd_tbl *cmdtp, int flag, int argc,
 	}
 
 	dst[data_size] = 0;
-	puts(dst);
+	if (argc > 1) {
+		const char *s = argv[1];
+		char *b = dst, *e = dst + data_size, *n;
+
+		while (b < e) {
+			n = strchrnul(b, '\n');
+			*n = '\0';
+
+			if (strcasestr(b, s)) {
+				puts(b);
+				puts("\n");
+			}
+			b = n + 1;
+		}
+	} else {
+		puts(dst);
+	}
 
 free:
 	free(dst);
@@ -38,7 +54,10 @@ free:
 }
 
 U_BOOT_CMD(
-	config, 1, 1, do_config,
+	config, 2, 1, do_config,
 	"print .config",
-	""
+	"[str]\n"
+	"\n"
+	"When the optional argument is given, only lines containing\n"
+	"that string are printed. Matching is case-insensitive."
 );
-- 
2.54.0



More information about the U-Boot mailing list