diff --git a/scripts/kconfig/LICENSE.kconfiglib b/scripts/kconfig/LICENSE.kconfiglib new file mode 100644 index 000000000..6bcdb3572 --- /dev/null +++ b/scripts/kconfig/LICENSE.kconfiglib @@ -0,0 +1,5 @@ +Copyright (c) 2011-2018, Ulf Magnusson + +Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies. + +THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. diff --git a/scripts/kconfig/defconfig.py b/scripts/kconfig/defconfig.py new file mode 100644 index 000000000..855561d8f --- /dev/null +++ b/scripts/kconfig/defconfig.py @@ -0,0 +1,39 @@ +# Copyright (C) 2018 Intel Corporation. +# SPDX-License-Identifier: BSD-3-Clause + +# This script takes a Kconfig and a defconfig file, and expands it to a .config +# with all default values listed explicitly. + +import sys, os + +# Kconfiglib: Copyright (c) 2011-2018, Ulf Magnusson +# SPDX-License-Identifier: ISC +# Refer to scripts/kconfig/LICENSE.kconfiglib for the permission notice. +import kconfiglib + +def usage(): + sys.stdout.write("%s: \n" % sys.argv[0]) + +def main(): + if len(sys.argv) < 4: + usage() + sys.exit(1) + + kconfig_path = sys.argv[1] + if not os.path.isfile(kconfig_path): + sys.stderr.write("Cannot find file %s\n" % kconfig_path) + sys.exit(1) + + defconfig_path = sys.argv[2] + if not os.path.isfile(defconfig_path): + sys.stderr.write("Cannot find file %s\n" % defconfig_path) + sys.exit(1) + + sys.stdout.write("Default configuration based on %s.\n" % defconfig_path) + kconfig = kconfiglib.Kconfig(kconfig_path) + kconfig.load_config(defconfig_path) + kconfig.write_config(sys.argv[3]) + sys.stdout.write("Configuration written to %s.\n" % sys.argv[3]) + +if __name__ == "__main__": + main() diff --git a/scripts/kconfig/generate_header.py b/scripts/kconfig/generate_header.py new file mode 100644 index 000000000..6afec0a31 --- /dev/null +++ b/scripts/kconfig/generate_header.py @@ -0,0 +1,38 @@ +# Copyright (C) 2018 Intel Corporation. +# SPDX-License-Identifier: BSD-3-Clause + +# This script takes a Kconfig and a .config, and generates a C header file with +# all the configuration data defined as object-like macros. + +import sys, os + +# Kconfiglib: Copyright (c) 2011-2018, Ulf Magnusson +# SPDX-License-Identifier: ISC +# Refer to scripts/kconfig/LICENSE.kconfiglib for the permission notice. +import kconfiglib + +def usage(): + sys.stdout.write("%s: <.config file> \n" % sys.argv[0]) + +def main(): + if len(sys.argv) < 4: + usage() + sys.exit(1) + + kconfig_path = sys.argv[1] + if not os.path.isfile(kconfig_path): + sys.stderr.write("Cannot find file %s\n" % kconfig_path) + sys.exit(1) + + config_path = sys.argv[2] + if not os.path.isfile(config_path): + sys.stderr.write("Cannot find file %s\n" % config_path) + sys.exit(1) + + kconfig = kconfiglib.Kconfig(kconfig_path) + kconfig.load_config(config_path) + kconfig.write_autoconf(sys.argv[3]) + sys.stdout.write("Configuration header written to %s.\n" % sys.argv[3]) + +if __name__ == "__main__": + main() diff --git a/scripts/kconfig/minimalconfig.py b/scripts/kconfig/minimalconfig.py new file mode 100644 index 000000000..23a0b7c0c --- /dev/null +++ b/scripts/kconfig/minimalconfig.py @@ -0,0 +1,39 @@ +# Copyright (C) 2018 Intel Corporation. +# SPDX-License-Identifier: BSD-3-Clause + +# Given a Kconfig, this script minimize a given .config by removing the symbols +# having the default values. The minimized config can act as a defconfig for +# future use. + +import sys, os + +# Kconfiglib: Copyright (c) 2011-2018, Ulf Magnusson +# SPDX-License-Identifier: ISC +# Refer to scripts/kconfig/LICENSE.kconfiglib for the permission notice. +import kconfiglib + +def usage(): + sys.stdout.write("%s: <.config file> \n" % sys.argv[0]) + +def main(): + if len(sys.argv) < 4: + usage() + sys.exit(1) + + kconfig_path = sys.argv[1] + if not os.path.isfile(kconfig_path): + sys.stderr.write("Cannot find file %s\n" % kconfig_path) + sys.exit(1) + + config_path = sys.argv[2] + if not os.path.isfile(config_path): + sys.stderr.write("Cannot find file %s\n" % config_path) + sys.exit(1) + + kconfig = kconfiglib.Kconfig(kconfig_path) + kconfig.load_config(config_path) + kconfig.write_min_config(sys.argv[3]) + sys.stdout.write("Minimized configuration written to %s.\n" % sys.argv[3]) + +if __name__ == "__main__": + main() diff --git a/scripts/kconfig/silentoldconfig.py b/scripts/kconfig/silentoldconfig.py new file mode 100644 index 000000000..691980b44 --- /dev/null +++ b/scripts/kconfig/silentoldconfig.py @@ -0,0 +1,71 @@ +# Copyright (C) 2018 Intel Corporation. +# SPDX-License-Identifier: BSD-3-Clause + +# This script +# +# 1. takes a Kconfig and a .config and an optional list of symbol-value pairs, +# 2. checks whether the specified symbols have the specified values in the +# given .config, and +# 3. reconstruct .config with the given list of symbol-value pairs if there +# is any disagreement. + +import sys, os + +# Kconfiglib: Copyright (c) 2011-2018, Ulf Magnusson +# SPDX-License-Identifier: ISC +# Refer to scripts/kconfig/LICENSE.kconfiglib for the permission notice. +import kconfiglib + +def usage(): + sys.stdout.write("%s: <.config file> [= ...]\n" % sys.argv[0]) + +def main(): + if len(sys.argv) < 3: + usage() + sys.exit(1) + + kconfig_path = sys.argv[1] + if not os.path.isfile(kconfig_path): + sys.stderr.write("Cannot find file %s\n" % kconfig_path) + sys.exit(1) + + kconfig = kconfiglib.Kconfig(kconfig_path) + + config_path = sys.argv[2] + has_old_config = False + if os.path.isfile(config_path): + kconfig.load_config(config_path) + has_old_config = True + + # Parse the configs specified on cmdline + + cmdline_conf = {} + for sym_val in sys.argv[3:]: + if sym_val.find("=") == -1: + continue + sym_name, val = sym_val.split("=")[:2] + if sym_name in kconfig.syms.keys(): + cmdline_conf[sym_name] = val + + # Check if the old .config conflicts with those specified on cmdline + + has_conflict = False + for sym_name, val in cmdline_conf.items(): + sym = kconfig.syms[sym_name] + if sym.str_value and sym.str_value != val: + has_conflict = True + break + + # If there's any conflict, reconfigure using those from the cmdline. The + # default values are used for unspecified symbols. + + if not has_old_config or has_conflict: + kconfig.unset_values() + for sym_name, val in cmdline_conf.items(): + kconfig.syms[sym_name].set_value(val) + + kconfig.write_config(config_path) + sys.stdout.write("Configuration written to %s.\n" % config_path) + +if __name__ == "__main__": + main()