def __init__(self):
     """Scan all the Kconfig files and create a Config object."""
     # Define environment variables referenced from Kconfig
     os.environ['srctree'] = os.getcwd()
     os.environ['UBOOTVERSION'] = 'dummy'
     os.environ['KCONFIG_OBJDIR'] = ''
     self._conf = kconfiglib.Config()
Beispiel #2
0
 def __init__(self, screen, cfgfile):
     self.screen = screen
     # Load the root Kconfig (this will load all sourced files also)
     self.conf = kconfiglib.Config(cfgfile)
     # Also load any existing generated configuration
     if os.path.exists(".config"):
         self.conf.load_config(".config")
     # Initialize curses screen
     curses.curs_set(0)
     # Create main menu
     main_menu = Menu(screen, "Top", self.conf.get_top_level_items())
     main_menu.display()
     self.conf.write_config(".config")
    def __init__(self):
        self.base_dir = os.environ.get("TOPDIR")
        self.output_dir = os.environ.get("O")
        self.package_dir = os.path.join(self.base_dir, self.package_dirname)
        self.config = kconfiglib.Config(
            os.path.join(self.base_dir, self.root_config), self.base_dir)
        self._deprecated = self.config.get_symbol(self.deprecated_symbol)

        self.gen_date = datetime.datetime.utcnow()
        self.br_version_full = os.environ.get("BR2_VERSION_FULL")
        if self.br_version_full and self.br_version_full.endswith("-git"):
            self.br_version_full = self.br_version_full[:-4]
        if not self.br_version_full:
            self.br_version_full = "undefined"
Beispiel #4
0
    def __init__(self):
        self.base_dir = os.environ.get("TOPDIR")
        self.output_dir = os.environ.get("O")
        self.package_dir = os.path.join(self.base_dir, self.package_dirname)
        # The kconfiglib requires an environment variable named "srctree" to
        # load the configuration, so set it.
        os.environ.update({'srctree': self.base_dir})
        self.config = kconfiglib.Config(
            os.path.join(self.base_dir, self.root_config))
        self._deprecated = self.config.get_symbol(self.deprecated_symbol)

        self.gen_date = datetime.datetime.utcnow()
        self.br_version_full = os.environ.get("BR2_VERSION_FULL")
        if self.br_version_full and self.br_version_full.endswith("-git"):
            self.br_version_full = self.br_version_full[:-4]
        if not self.br_version_full:
            self.br_version_full = "undefined"
Beispiel #5
0
def write_wikified_sysctl_opts(kern_src_dir, out_file_name):
    """
    Writes a categorized list of sysctl variables wrapped in MediaWiki links
    construct.
 
    Parameters:
    kern_src_dir    (string) Absolute path to a kernel source directory
                    (e.g. /usr/src/linux-3.2.48.)
 
    out_file_name   (string) Path and file name or just the file name of the
                    output file.
 
    The links point to anchors on the Grsecurity and PaX Configuration Options
    page. The links are written in alphabetical order by the sysctl variable.
    """
    sysctl_opts = get_sysctl_opts(kern_src_dir)
    categorized_opts = get_categorized_sysctl_opts(sysctl_opts)
    kconfig_path = os.path.join(kern_src_dir, "security", "Kconfig")
    conf = kconfiglib.Config(kconfig_path, kern_src_dir)
    link_fmt = "* [[Grsecurity/Appendix/Grsecurity_and_PaX"\
        "_Configuration_Options#{0}|{1}]]\n"

    with codecs.open(out_file_name, 'w', "utf-8") as f:
        f.write("| style=\"border:1px solid gray;\"|\n")
        for opt in categorized_opts[0]:
            symbol = conf.get_symbol(opt[1])
            prompt = get_prompt(symbol)
            f.write(link_fmt.format(prompt, opt[0]))

        f.write("| style=\"border:1px solid gray;\"|\n")
        for opt in categorized_opts[1]:
            symbol = conf.get_symbol(opt[1])
            prompt = get_prompt(symbol)
            f.write(link_fmt.format(prompt, opt[0]))

        f.write("| style=\"border:1px solid gray;\"|\n")
        for opt in categorized_opts[2]:
            symbol = conf.get_symbol(opt[1])
            prompt = get_prompt(symbol)
            f.write(link_fmt.format(prompt, opt[0]))

        f.write("| style=\"border:1px solid gray;\"|\n")
        for opt in categorized_opts[3]:
            symbol = conf.get_symbol(opt[1])
            prompt = get_prompt(symbol)
            f.write(link_fmt.format(prompt, opt[0]))
Beispiel #6
0
    def update_defconfig(self):
        "Applies the configuration settings to the defconfig"
        os.environ['APPSDIR'] = '../apps' # TODO: fixme

        # load the Kconfig tree
        conf = kconfiglib.Config(os.path.join(self.nuttx_path, 'Kconfig'), base_dir=self.nuttx_path)

        # load our default defconfig
        conf.load_config(self.path_to_abs_target('nuttx/configs/$board/$target/defconfig'))
        for k in self.configs:
            # allow for variable names in the values of config entries
            # MANIFEST=$board-$target is the only case at the time of
            # writing.
            d = { '$board' : self.board, '$target' : self.target, }
            v = multiple_replace(d, str(self.configs[k]))
            print(k, v)
            try:
                conf.get_symbol(k).set_user_value(v)
            except AttributeError:
                print(k, v)
        # write the output
        conf.write_config(self.path_to_abs_target('nuttx/configs/$board/$target/defconfig'))
Beispiel #7
0
def write_wikified_kconfig(kern_src_dir, out_file_name):
    """
    Create a MediaWiki-formatted version of the Kconfig file found in
    the kern_src_dir/security/ directory and write the output to the
    given file.
 
    Parameters:
    kern_src_dir    (string) Absolute path to a kernel source directory
                    (e.g. /usr/src/linux-3.2.48.)
 
    out_file_name   (string) Path and file name or just the file name of the
                    output file.
    """
    security_kconfig = os.path.join(kern_src_dir, "security", "Kconfig")
    conf = kconfiglib.Config(security_kconfig, kern_src_dir)
    if conf is not None:
        for menu in conf.get_menus():
            if menu.get_title() == "Grsecurity":
                with codecs.open(out_file_name, 'w', "utf-8") as f:
                    sysctl_opts = get_sysctl_opts(kern_src_dir)
                    write_wikified_item(f, sysctl_opts, menu, 1)
                break
Beispiel #8
0
os.environ["ARCH"] = arch
os.environ["KERNELVERSION"] = version

# Creating output_dir if not there.
try:
    os.makedirs(output_dir)
except OSError as exc:
    if exc.errno == errno.EEXIST and os.path.isdir(output_dir):
        pass
    else:
        raise

############################
# Loading the Kconfig tree #
############################
feature_model = kconfiglib.Config(kconfig_name, dirname)

# Loading the allnoconfig #
min_k_dict = {}
if not debugging:
    min_k = open(min_k_file)
    min_k = [i.strip().split("=") for i in min_k]
    for key, value in min_k:
        min_k_dict[key] = value

types = ["unknown", "bool", "tristate", "string", "hex", "int"]
yesno = ['y', 'n']


# This will take all the features NOT in the allnoconfig, and randomize their
# values. Many of the configurations will be invalid.
        sys.exit(1)

if not os.getenv("ARCH"):
    print("ERROR: arch must be set (via ARCH environment variable")
    sys.exit(1)

kconf = ksrc + "/Kconfig"
if not os.path.exists(kconf):
    print(
        "ERROR: kernel source directory '%s' does not contain a top level Kconfig file"
        % ksrc)
    sys.exit(1)

# Create a Config object representing a Kconfig configuration. (Any number of
# these can be created -- the library has no global state.)
conf = kconfiglib.Config(kconf)

# Load values from a .config file.
conf.load_config(dotconfig)

opt = conf[option]

if show_summary:
    print(conf[option])

if show_vars:
    print("")
    print("Variables that depend on '%s':" % option)

    for sym in conf:
        if opt in sym.get_referenced_symbols():
def process_kconfig_file(kconfig_file, heading_level, breadcrumbs):
    if os.path.exists(kconfig_file):
        cfg = kconfiglib.Config(kconfig_file, print_warnings=True)
        print_menu_contents(None, cfg.get_top_level_items(), heading_level,
                            breadcrumbs)
Beispiel #11
0
# Prints the names of all symbols that reference a particular symbol. (There's
# also a method get_selected_symbols() for determining just selection
# relations.)

import kconfiglib
import sys

conf = kconfiglib.Config(sys.argv[1], sys.argv[2])

for sym in conf:
    print sym.get_name() + " " + str(sym.get_type())
Beispiel #12
0
import kconfiglib

conf = kconfiglib.Config("linux-3.19/Kconfig_concat", "linux-3.19")
# conf.load_config("/tmp/randconfigs/7")

top = conf.get_top_level_items()
syms = conf.get_symbols()

print len(syms)

for sym in syms:
    pass

print len(syms)
Beispiel #13
0
                                 formatter_class=argparse.RawTextHelpFormatter)
parser.add_argument('-s',
                    '--subdir',
                    action='store',
                    dest='subdir',
                    default="",
                    help='sub directory to be scanned')
parser.add_argument('-c',
                    '--complete-log',
                    action='store_true',
                    dest='completelog',
                    default=False,
                    help='Prints all the kconfigs found')
parser.add_argument('-e',
                    '--exclude',
                    action='append',
                    dest='exclude',
                    default=["doc", "sanity-out", "outdir"],
                    help='Dirs to be excluded for verification')

args = parser.parse_args()
if args.completelog:
    print('sub dir      = ', os.path.join(ugelisbase + args.subdir))
    print('complete-log = ', args.completelog)
    print('exclude dirs = ', args.exclude)

conf = kconfiglib.Config(os.path.join(ugelisbase, 'Kconfig'))
search_config_in_file(os.path.join(ugelisbase + os.path.sep + args.subdir),
                      conf.get_top_level_items(), args.completelog,
                      args.exclude)

# Usage
if len(sys.arg) < 4:
    print "Usage: python2 generate_n_filter.py <kernel dir> <arch> [-s]"
    print ""
    print "-s  Will output all the string symbols and their possible values"


# Setting system environment variables
os.environ["SRCARCH"] = sys.argv[2]
os.environ["ARCH"] = sys.argv[2]
os.environ["KERNELVERSION"] = version

# Loading the Kconfig tree
feature_model = kconfiglib.Config(dirname+"/"+kconfig_name, dirname)

types = ["unknown", "bool", "tristate", "string", "hex", "int"]

def scramble(fm):
    output = {}
    choices_taken = []
    for feature in fm:
        type = types[feature.type]
        ischoice = feature.is_choice_symbol()
        if ischoice:
            choice = feature.get_parent()
            choices = choice.get_symbols()
            rnd = random.randrange(len(choices))
            if choice in choices_taken:
                value = "n"
Beispiel #15
0
 def __init__(self, cloud_provider):
     self.cloud_provider = cloud_provider
     self.cloud_config = 'phase1/{}/Kconfig'.format(self.cloud_provider)
     self.conf = kc.Config()
     self.print_config = True
Beispiel #16
0
                                 formatter_class=argparse.RawTextHelpFormatter)
parser.add_argument('-s',
                    '--subdir',
                    action='store',
                    dest='subdir',
                    default="",
                    help='sub directory to be scanned')
parser.add_argument('-c',
                    '--complete-log',
                    action='store_true',
                    dest='completelog',
                    default=False,
                    help='Prints all the kconfigs found')
parser.add_argument('-e',
                    '--exclude',
                    action='append',
                    dest='exclude',
                    default=["doc", "sanity-out", "outdir"],
                    help='Dirs to be excluded for verification')

args = parser.parse_args()
if args.completelog:
    print('sub dir      = ', os.path.join(zephyrbase + args.subdir))
    print('complete-log = ', args.completelog)
    print('exclude dirs = ', args.exclude)

conf = kconfiglib.Config(os.path.join(zephyrbase, 'Kconfig'))
search_config_in_file(os.path.join(zephyrbase + os.path.sep + args.subdir),
                      conf.get_top_level_items(), args.completelog,
                      args.exclude)
Beispiel #17
0
The Kconfig files are distributed across the build directory tree. The files
are organized based on their common characteristics and on what new symbols
they add to the configuration menus.

The configuration options' information below is extracted directly from
:program:`Kconfig` using the :file:`~/doc/scripts/genrest/genrest.py` script.
Click on the option name in the table below for detailed information about
each option.


Supported Options
*****************

.. list-table:: Alphabetized Index of Configuration Options
   :header-rows: 1

   * - Kconfig Symbol
     - Description
""")
conf = kconfiglib.Config(sys.argv[1])
print_items(conf.get_top_level_items(), sys.argv[2], 0)

# print_items created separate .rst files for each configuration option as
# well as filling itemIndex with all these options (and their descriptions).
# Now we can print out the accumulated config symbols in alphabetic order.

for item in sorted(itemIndex):
    f.write(itemIndex[item])

f.close()
Beispiel #18
0
# Usage:
if len(sys.argv) < 3:
    print "Usage: python2 get_minimum.py <kernel dir> <arch>"
    sys.exit(0)

# Setting system environment variables
arch = sys.argv[2]
dirname = sys.argv[1]
os.environ["SRCARCH"] = arch
os.environ["ARCH"] = arch
os.environ["KERNELVERSION"] = dirname[6:]

# Auto configuration
kconfig_name = "Kconfig"
allno = kconfiglib.Config(dirname + "/" + kconfig_name, dirname)
allno.load_config(output_dir + arch + "_allnoconfig")


def in_allno(name):
    if allno[name].get_user_value() != None:
        if allno[name].get_type() in [3, 4, 5]:
            if not allno[name].get_value() == "":
                return True
        if allno[name].get_type() in [1, 2]:
            if allno[name].get_value() == "y":
                return True
    return False


for i in allno: