Commit 61304dbec36dc445bbe7d2c19b4da0695861e0a8

Authored by Masahiro Yamada
Committed by Tom Rini
1 parent 6fb631ecde

cmd: add a new command "config" to show .config contents

This feature is inspired by /proc/config.gz of Linux.  In Linux,
if CONFIG_IKCONFIG is enabled, the ".config" file contents are
embedded in the kernel image.  If CONFIG_IKCONFIG_PROC is also
enabled, the ".config" contents are exposed to /proc/config.gz.
Users can do "zcat /proc/config.gz" to check which config options
are enabled on the running kernel image.

The idea is almost the same here; if CONFIG_CMD_CONFIG is enabled,
the ".config" contents are compressed and saved in the U-Boot image,
then printed by the new command "config".

The usage is quite simple.  Enable CONFIG_CMD_CONFIG, then run
 > config
from the command line interface.  The ".config" contents will be
printed on the console.

This feature increases the U-Boot image size by about 4KB (this is
mostly due to the gzip-compressed .config file).  By default, it is
enabled only for Sandbox because we do not care about the memory
footprint on it.  Of course, this feature is architecture agnostic,
so you can enable it on any board if the image size increase is
acceptable for you.

Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

Showing 9 changed files with 97 additions and 5 deletions Side-by-side Diff

... ... @@ -325,4 +325,6 @@
325 325 source "lib/Kconfig"
326 326  
327 327 source "test/Kconfig"
  328 +
  329 +source "scripts/Kconfig"
... ... @@ -482,6 +482,13 @@
482 482 # Build targets only - this includes vmlinux, arch specific targets, clean
483 483 # targets and others. In general all targets except *config targets.
484 484  
  485 +# Additional helpers built in scripts/
  486 +# Carefully list dependencies so we do not try to build scripts twice
  487 +# in parallel
  488 +PHONY += scripts
  489 +scripts: scripts_basic include/config/auto.conf
  490 + $(Q)$(MAKE) $(build)=$(@)
  491 +
485 492 ifeq ($(dot-config),1)
486 493 # Read in config
487 494 -include include/config/auto.conf
... ... @@ -1538,11 +1545,6 @@
1538 1545 %docs: scripts_basic FORCE
1539 1546 $(Q)$(MAKE) $(build)=scripts build_docproc
1540 1547 $(Q)$(MAKE) $(build)=doc/DocBook $@
1541   -
1542   -# Dummies...
1543   -PHONY += prepare scripts
1544   -prepare: ;
1545   -scripts: ;
1546 1548  
1547 1549 endif #ifeq ($(config-targets),1)
1548 1550 endif #ifeq ($(mixed-targets),1)
  1 +config_data.gz
  2 +config_data_gz.h
  3 +config_data_size.h
... ... @@ -126,6 +126,18 @@
126 126 help
127 127 Print board info
128 128  
  129 +config CMD_CONFIG
  130 + bool "config"
  131 + select BUILD_BIN2C
  132 + default SANDBOX
  133 + help
  134 + Print ".config" contents.
  135 +
  136 + If this option is enabled, the ".config" file contents are embedded
  137 + in the U-Boot image and can be printed on the console by the "config"
  138 + command. This provides information of which options are enabled on
  139 + the running U-Boot.
  140 +
129 141 config CMD_CONSOLE
130 142 bool "coninfo"
131 143 default y
... ... @@ -31,6 +31,7 @@
31 31 obj-$(CONFIG_CMD_CACHE) += cache.o
32 32 obj-$(CONFIG_CMD_CBFS) += cbfs.o
33 33 obj-$(CONFIG_CMD_CLK) += clk.o
  34 +obj-$(CONFIG_CMD_CONFIG) += config.o
34 35 obj-$(CONFIG_CMD_CONSOLE) += console.o
35 36 obj-$(CONFIG_CMD_CPLBINFO) += cplbinfo.o
36 37 obj-$(CONFIG_CMD_CPU) += cpu.o
... ... @@ -165,4 +166,25 @@
165 166 obj-y += nvedit.o
166 167  
167 168 obj-$(CONFIG_ARCH_MVEBU) += mvebu/
  169 +
  170 +filechk_data_gz = (echo "static const char data_gz[] ="; cat $< | scripts/bin2c; echo ";")
  171 +
  172 +filechk_data_size = \
  173 + (echo "static const size_t data_size = "; \
  174 + cat $< | wc -c; echo ";")
  175 +
  176 +# "config" command
  177 +$(obj)/config.o: $(obj)/config_data_gz.h $(obj)/config_data_size.h
  178 +
  179 +targets += config_data.gz
  180 +$(obj)/config_data.gz: $(KCONFIG_CONFIG) FORCE
  181 + $(call if_changed,gzip)
  182 +
  183 +targets += config_data_gz.h
  184 +$(obj)/config_data_gz.h: $(obj)/config_data.gz FORCE
  185 + $(call filechk,data_gz)
  186 +
  187 +targets += config_data_size.h
  188 +$(obj)/config_data_size.h: $(KCONFIG_CONFIG) FORCE
  189 + $(call filechk,data_size)
  1 +/*
  2 + * Copyright (C) 2017 Masahiro Yamada <yamada.masahiro@socionext.com>
  3 + *
  4 + * SPDX-License-Identifier: GPL-2.0+
  5 + */
  6 +
  7 +#include <common.h>
  8 +#include <command.h>
  9 +#include <malloc.h>
  10 +
  11 +#include "config_data_gz.h"
  12 +#include "config_data_size.h"
  13 +
  14 +static int do_config(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
  15 +{
  16 + char *dst;
  17 + unsigned long len = data_size;
  18 + int ret = CMD_RET_SUCCESS;
  19 +
  20 + dst = malloc(data_size + 1);
  21 + if (!dst)
  22 + return CMD_RET_FAILURE;
  23 +
  24 + ret = gunzip(dst, data_size, (unsigned char *)data_gz, &len);
  25 + if (ret) {
  26 + printf("failed to uncompress .config data\n");
  27 + ret = CMD_RET_FAILURE;
  28 + goto free;
  29 + }
  30 +
  31 + dst[data_size] = 0;
  32 + puts(dst);
  33 +
  34 +free:
  35 + free(dst);
  36 +
  37 + return ret;
  38 +}
  39 +
  40 +U_BOOT_CMD(
  41 + config, 1, 1, do_config,
  42 + "print .config",
  43 + ""
  44 +);
1 1 #
2 2 # Generated files
3 3 #
  4 +bin2c
4 5 docproc
  1 +config BUILD_BIN2C
  2 + bool
... ... @@ -7,6 +7,10 @@
7 7 # SPDX-License-Identifier: GPL-2.0
8 8 #
9 9  
  10 +hostprogs-$(CONFIG_BUILD_BIN2C) += bin2c
  11 +
  12 +always := $(hostprogs-y)
  13 +
10 14 # The following hostprogs-y programs are only build on demand
11 15 hostprogs-y += docproc
12 16