mcu_hi3321_watch/build/script/usr_config.py
2025-06-06 15:13:55 +08:00

67 lines
2.4 KiB
Python

#!/usr/bin/env python
# -*- coding: UTF-8 -*-
# Copyright (c) @CompanyNameMagicTag 2023-2023. All rights reserved.
import os, sys
from kconfiglib import Kconfig
from menuconfig import menuconfig
def mconf_set_env(style, conf, config_header, autoheader_header, output_path = None):
"""
Set Kconfig Env
"""
os.environ["MENUCONFIG_STYLE"] = style
os.environ["KCONFIG_CONFIG"] = conf
os.environ["KCONFIG_CONFIG_HEADER"] = config_header
os.environ["KCONFIG_AUTOHEADER"] = os.path.join("." if output_path == None else output_path, "mconfig.h")
os.environ["KCONFIG_AUTOHEADER_HEADER"] = autoheader_header
os.environ["CONFIG_"] = "CONFIG_"
def mconfig(argv):
kconfig = os.path.join("config.in")
display_style = "default selection=fg:white,bg:blue"
if (len(argv) == 6):
chip = argv[2]
core = argv[3]
target = argv[4]
target = target.replace('-', "_")
output_path = argv[5]
target_conf = os.path.join(".", "build", "config", "target_config", chip, "menuconfig", core, "%s.config" % target)
else:
print("Invalid parameters")
return
config_header = '''# Generated by Kconfig Tool.
# Note: !!!This file can not be modify manually!!!
'''
autoheader_header = '''/* Copyright (c) @CompanyNameMagicTag 2022-2022. All rights reserved. */
'''
mconf_set_env(display_style, target_conf, config_header, autoheader_header, output_path)
kconf = Kconfig(filename=kconfig)
if argv[1] == 'savemenuconfig':
kconf.load_config()
print(kconf.write_autoconf()) # save menu config
elif argv[1] == 'defconfig':
kconf.load_allconfig("alldef.config")
print(kconf.write_config()) # default config
elif argv[1] == 'allyesconfig':
kconf.warn = False
for sym in kconf.unique_defined_syms:
sym.set_value(1 if sym.choice else 2)
for choice in kconf.unique_choices:
choice.set_value(2)
kconf.warn = True
kconf.load_allconfig("allyes.config")
print(kconf.write_config()) # all yes config
elif argv[1] == 'allnoconfig':
kconf.warn = False
for sym in kconf.unique_defined_syms:
sym.set_value(2 if sym.is_allnoconfig_y else 0)
kconf.warn = True
kconf.load_allconfig("allno.config")
print(kconf.write_config()) # all no config
else:
menuconfig(kconf) # menu config
if __name__ == "__main__":
mconfig(sys.argv)