Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add feature to generate config for kernel #2

Open
metaspace opened this issue Oct 31, 2024 · 2 comments
Open

Add feature to generate config for kernel #2

metaspace opened this issue Oct 31, 2024 · 2 comments

Comments

@metaspace
Copy link
Owner

Add config subcommand to generate a kernel config from a set of fragments like the ones in here.

The generated config should include configuration to boot the vm with the configured debian features.

The command should check that all requested config items are set accordingly similar to this:

#!/usr/bin/env python3

import argparse
import re
import sys
from itertools import combinations

parser = argparse.ArgumentParser()
parser.add_argument("--config", type=argparse.FileType('rt'))
parser.add_argument("fragments", metavar='FRAGMENT', type=argparse.FileType('rt'), nargs="+")

args = parser.parse_args()

input_fragments = dict()
output_configs = dict()
matcher = re.compile(r"""^(CONFIG_\w+)=([nym])""")

def get_configs(file):
    configs = dict()
    for line in file.readlines():
        matches = matcher.match(line)
        if matches:
            configs[matches.group(1)] = matches.group(2)
    return configs

for fragment in args.fragments:
    input_fragments[fragment.name] = get_configs(fragment)

ok = True

for (key_a, key_b) in combinations(input_fragments.keys(), 2):
    fragment_a = input_fragments[key_a]
    fragment_b = input_fragments[key_b]

    common_configs = set(fragment_a.keys()).intersection(set(fragment_b.keys()))

    for config in common_configs:
        value_a = fragment_a[config]
        value_b = fragment_b[config]
        if value_a != value_b:
            print(f"ERROR: {config} has conflicting values {key_a}:{value_a} and {key_b}:{value_b}")
            ok = False

output_configs |= get_configs(args.config)


input_configs = dict()

for fragment_name,configs in input_fragments.items():
    input_configs |= configs

for key,value in input_configs.items():
    check_failed = \
        (value != 'n' \
         and output_configs.get(key) != value) or \
        (value == 'n' \
         and key in output_configs and output_configs.get(key) != value)
    if check_failed:
        ok = False
        print(f"ERROR: {key}={value}")

if not ok:
    sys.exit(-1)
@metaspace
Copy link
Owner Author

Maybe do something semantically like this:

    #!/bin/bash
    set -e
    set -x
    rm -f {{path}}-build/.config
    version="$({{path}}/scripts/min-tool-version.sh bindgen)"
    export PATH="{{top}}/bindgen-$version/bin:$PATH"
    (cd {{path}} && make -j $(nproc) O={{top}}/{{path}}-build LLVM=1 \
      allnoconfig)
      {{path}}/scripts/kconfig/merge_config.sh -m -O {{path}}-build {{path}}-build/.config \
      config/default.fragment \
      `echo "{{FRAGMENTS}}" | sed -E 's#([^[:space:]]+)#config/\1.fragment#g'`
      (cd {{path}} && make -j $(nproc) O={{top}}/{{path}}-build LLVM=1 \
      olddefconfig)
    ./config-test.py --config {{path}}-build/.config config/default.fragment `echo "{{FRAGMENTS}}" | sed -E 's#([^[:space:]]+)#config/\1.fragment#g'`

@metaspace
Copy link
Owner Author

Or use scripts/config

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant