blob: bd3d42f32ea0ee466232607ba57c7f28ee3c757a [file] [log] [blame]
# -*- mode: python -*-
# virtme-configkernel: Configure a kernel for virtme
# Copyright © 2014 Andy Lutomirski
# Licensed under the GPLv2, which is available in the virtme distribution
# as a file called LICENSE with SHA-256 hash:
# 8177f97513213526df2cf6184d8ff986c675afb514d4e68a404010521b880643
import argparse
import tempfile
import os
import shutil
import subprocess
import multiprocessing
from .. import architectures
uname = os.uname()
def make_parser():
parser = argparse.ArgumentParser(
description='Configure a kernel for virtme',
parser.add_argument('--arch', action='store', metavar='ARCHITECTURE',
help='Target architecture')
g = parser.add_argument_group(title='Mode').add_mutually_exclusive_group()
g.add_argument('--allnoconfig', action='store_true',
help='Overwrite configuration with a virtme-suitable allnoconfig (unlikely to work)')
g.add_argument('--defconfig', action='store_true',
help='Overwrite configuration with a virtme-suitable defconfig')
g.add_argument('--update', action='store_true',
help='Update existing config for virtme')
return parser
_ARGPARSER = make_parser()
def arg_fail(message):
'# Generic',
'CONFIG_UEVENT_HELPER=n', # Obsolete and slow
'# virtio-scsi support',
'# virt-serial support',
'# watchdog (useful for test scripts)',
def main():
args = _ARGPARSER.parse_args()
if not os.path.isfile('scripts/kconfig/'):
print('virtme-configkernel must be run in a kernel source directory')
return 1
arch = architectures.get(args.arch)
['# Arch-specific options'] +
if shutil.which('%s-linux-gnu-gcc' % arch.gccname):
conf.append('CONFIG_CROSS_COMPILE="%s-linux-gnu-"' % arch.gccname)
if args.allnoconfig:
maketarget = 'allnoconfig'
updatetarget = 'silentoldconfig'
elif args.defconfig:
maketarget = arch.defconfig_target
updatetarget = 'olddefconfig'
elif args.update:
maketarget = None
updatetarget = 'olddefconfig'
arg_fail('No mode selected')
# TODO: Get rid of most of the noise and check the result.
# Set up an initial config
if maketarget:
subprocess.check_call(['make', 'ARCH=%s' % arch.linuxname, maketarget])
config = '.config'
# Check if KBUILD_OUTPUT is defined and if it's a directory
config_dir = os.environ.get('KBUILD_OUTPUT', '')
if config_dir and os.path.isdir(config_dir):
config = os.path.join(config_dir, config)
with open(config, 'ab') as conffile:
subprocess.check_call(['make', 'ARCH=%s' % arch.linuxname, updatetarget])
print("Configured. Build with 'make ARCH=%s -j%d'" %
(arch.linuxname, multiprocessing.cpu_count()))
return 0
if __name__ == '__main__':