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. Reviewed-by: Simon Glass <sjg@chromium.org> Signed-off-by: Rasmus Villemoes <rv@rasmusvillemoes.dk>
65 lines
1.1 KiB
C
65 lines
1.1 KiB
C
// SPDX-License-Identifier: GPL-2.0+
|
|
/*
|
|
* Copyright (C) 2017 Masahiro Yamada <yamada.masahiro@socionext.com>
|
|
*/
|
|
|
|
#include <command.h>
|
|
#include <gzip.h>
|
|
#include <malloc.h>
|
|
#include <linux/string.h>
|
|
|
|
#include "config_data_gz.h"
|
|
#include "config_data_size.h"
|
|
|
|
static int do_config(struct cmd_tbl *cmdtp, int flag, int argc,
|
|
char *const argv[])
|
|
{
|
|
char *dst;
|
|
unsigned long len = data_size;
|
|
int ret = CMD_RET_SUCCESS;
|
|
|
|
dst = malloc(data_size + 1);
|
|
if (!dst)
|
|
return CMD_RET_FAILURE;
|
|
|
|
ret = gunzip(dst, data_size, (unsigned char *)data_gz, &len);
|
|
if (ret) {
|
|
printf("failed to uncompress .config data\n");
|
|
ret = CMD_RET_FAILURE;
|
|
goto free;
|
|
}
|
|
|
|
dst[data_size] = 0;
|
|
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);
|
|
|
|
return ret;
|
|
}
|
|
|
|
U_BOOT_CMD(
|
|
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."
|
|
);
|