summaryrefslogtreecommitdiff
path: root/util/kconfig
diff options
context:
space:
mode:
authorStefan Reinauer <stefan.reinauer@coreboot.org>2015-03-24 21:46:52 +0100
committerStefan Reinauer <stefan.reinauer@coreboot.org>2015-03-26 03:06:54 +0100
commit172d33594e233edb4c283bd08ea701986aa01d7a (patch)
treead485a37b10e38043377178f33437245d8b2dd1f /util/kconfig
parent0e99044aabcca418bba48e2b1d93d0e4e4a38b47 (diff)
util: Add miniconfig, a script to minimize coreboot configurations
This script produces a "minimal" configuration from a full coreboot configuration, e.g. a configuration file that only contains the differences between the default configuration of a board and the input configuration file. Usage: util/kconfig/miniconfig config.big config.mini This will read config.big and produce config.mini. If you omit config.mini, config.big will be changed in place. Minimal configurations are easier to read and more robust when reusing them among different versions of coreboot as they reflect exactly the changes made to the default configuration instead of a full snapshot of all configuration options. Change-Id: Ifbee49e0192c2c557b18bcc1a92fe2a5d5164a3a Signed-off-by: Stefan Reinauer <stefan.reinauer@coreboot.org> Reviewed-on: http://review.coreboot.org/8974 Tested-by: build bot (Jenkins) Reviewed-by: Aaron Durbin <adurbin@google.com>
Diffstat (limited to 'util/kconfig')
-rwxr-xr-xutil/kconfig/miniconfig88
1 files changed, 88 insertions, 0 deletions
diff --git a/util/kconfig/miniconfig b/util/kconfig/miniconfig
new file mode 100755
index 0000000000..a10501a886
--- /dev/null
+++ b/util/kconfig/miniconfig
@@ -0,0 +1,88 @@
+#!/bin/bash
+#
+# miniconfig - utility to minimize your coreboot config files
+#
+# Copyright 2015 Google Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; version 2 of the License.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+
+CONFIG=$1
+NEWCONFIG=$2
+
+CONF=build/util/kconfig/conf
+KCONFIG=src/Kconfig
+DOTCONFIG=.config
+PREVCONFIG=.config.prev
+TMPCONFIG=.config.mini
+
+recreate_config()
+{
+ $CONF --olddefconfig $KCONFIG &> /dev/null
+}
+
+if [ "$CONFIG" == "" ]; then
+ printf "usage: util/miniconfig/miniconfig [path to config file] <path to new config file>\n"
+ exit 0
+fi
+
+if [ ! -r "$CONFIG" ]; then
+ printf "Can't read $CONFIG.\n"
+ exit 1
+fi
+
+if [ "$CONFIG" == .config ]; then
+ printf "Can't use .config, it's overwritten. Make a backup.\n"
+ exit 1
+fi
+
+if [ ! -x "$CONF" ]; then
+ printf "conf utility at $CONF not available.\n"
+ exit 1
+fi
+
+# Start out by creating a default config file for a mainboard
+VENDOR=$( grep ^CONFIG_VENDOR "$CONFIG" )
+BOARD=$( grep ^CONFIG_BOARD "$CONFIG" | grep -v ROMSIZE | grep -v SPECIFIC_OPTIONS )
+
+printf "$VENDOR\n$BOARD\n" > "$TMPCONFIG"
+cp "$TMPCONFIG" "$DOTCONFIG"
+recreate_config
+
+LINES=$( cat "$CONFIG" | wc -l )
+CUR=1
+
+# Now go through each line of the existing, large config file, add it to our
+# new minimal config file, and see if it makes a difference when running "make
+# olddefconfig". If it does, keep the line, otherwise discard it.
+
+cat "$CONFIG" | while read L; do
+ printf "\rProcessing $CONFIG - $CUR / $LINES (%d%%)" $(( $CUR * 100 / $LINES))
+ mv "$DOTCONFIG" "$PREVCONFIG"
+ cp "$TMPCONFIG" "$DOTCONFIG"
+ echo "$L" >> "$DOTCONFIG"
+ recreate_config
+
+ if ! diff -q "$DOTCONFIG" "$PREVCONFIG" > /dev/null; then
+ echo "$L" >> "$TMPCONFIG"
+ fi
+ CUR=$(( $CUR + 1 ))
+done
+
+echo
+
+if [ "$NEWCONFIG" != "" ]; then
+ printf "Writing new, minimized config to $NEWCONFIG\n"
+ mv "$TMPCONFIG" "$NEWCONFIG"
+else
+ printf "Overwriting $CONFIG with new, minimized config.\n"
+ mv "$TMPCONFIG" "$CONFIG"
+fi
+