LKMC v3.0

This is a squash commit, the unsquashed development went through many
unstable phases which would break bisects. The unsquashed branch is:
https://github.com/cirosantilli/linux-kernel-module-cheat/tree/v3.0-unsquash

The main improvement of this release was to greatly generalize the testing system.

The key addition was cli_function.py, which allows scripts such as ./run to
be transparently called either from Python or from the command line.

New tests scripts were created using this improved framework: test-baremetal
and test-user-mode.

We were lazy to port some of less important tests to the new setup, TODO's were
added, and we need comes they will be fixed. Getting started is however sacred
as usual and should work.

Other changes include:

-   gem5: update to 7fa4c946386e7207ad5859e8ade0bbfc14000d91

-   run: --tmux-args implies --tmux

-   run: add --userland-args to make userland arguments across QEMU and gem5

    Get rid of --userland-before as a consequence.

-   bring initrd and initramfs back to life

-   build-userland: create --static to make build a bit easier

-   gem5: --gem5-worktree also set --gem5-build-id

-   remove --gem5, use --emulator gem5 everywhere

    Allow passing --emulator multiple times for transparent tests selection
    just like --arch.

-   test-userland: allow selecting just a few tests

-   linux: update to v4.20

-   buildroot: update to 2018.08

    The main motivation for this was to fix the build for Ubuntu 18.10, which
    has glibc 2.28, which broke the 2018.05 build at the m4-host package with:

        #error "Please port gnulib fseeko.c to your platform!

-   getvar --type input

-   failed xen attempt, refactor timer, failed svc attempt, aarch64 use gicv3

-   build-doc: exit 1 on error, add to release testing

-   build: add --apt option to make things easier on other distros

-   build-linux: --no-modules-install
This commit is contained in:
Ciro Santilli 六四事件 法轮功
2019-01-22 00:00:00 +00:00
parent 3b0a343647
commit da900a579c
86 changed files with 5241 additions and 3543 deletions

View File

@@ -6,32 +6,37 @@ import platform
import shutil
import common
from shell_helpers import LF
class ModulesComponent(common.Component):
def add_parser_arguments(self, parser):
parser.add_argument(
class Main(common.BuildCliFunction):
def __init__(self):
super().__init__(
description='''\
Build our Linux kernel modules without using Buildroot.
See also: https://github.com/cirosantilli/linux-kernel-module-cheat#host
''')
self.add_argument(
'--make-args',
default='',
)
parser.add_argument(
self.add_argument(
'--host',
action='store_true',
default=False,
help='''\
Build the Linux kernel modules for the host instead of guest.
Use the host packaged cross toolchain.
''',
)
parser.add_argument(
'kernel_modules',
self.add_argument(
'kernel-modules',
default=[],
help='Which kernel modules to build. Default: build all',
metavar='kernel-modules',
nargs='*',
)
def do_build(self, args):
build_dir = self.get_build_dir(args)
def build(self):
build_dir = self.get_build_dir()
os.makedirs(build_dir, exist_ok=True)
# I kid you not, out-of-tree build is not possible, O= does not work as for the kernel build:
#
@@ -42,87 +47,78 @@ Use the host packaged cross toolchain.
# This copies only modified files as per:
# https://stackoverflow.com/questions/5718899/building-an-out-of-tree-linux-kernel-module-in-a-separate-object-directory
distutils.dir_util.copy_tree(
common.kernel_modules_src_dir,
os.path.join(build_dir, common.kernel_modules_subdir),
self.env['kernel_modules_source_dir'],
os.path.join(build_dir, self.env['kernel_modules_subdir']),
update=1,
)
distutils.dir_util.copy_tree(
common.include_src_dir,
os.path.join(build_dir, common.include_subdir),
self.env['include_source_dir'],
os.path.join(build_dir, self.env['include_subdir']),
update=1,
)
all_kernel_modules = []
for basename in os.listdir(common.kernel_modules_src_dir):
src = os.path.join(common.kernel_modules_src_dir, basename)
for basename in os.listdir(self.env['kernel_modules_source_dir']):
src = os.path.join(self.env['kernel_modules_source_dir'], basename)
if os.path.isfile(src):
noext, ext = os.path.splitext(basename)
if ext == common.c_ext:
if ext == self.env['c_ext']:
all_kernel_modules.append(noext)
if args.kernel_modules == []:
if self.env['kernel_modules'] == []:
kernel_modules = all_kernel_modules
else:
kernel_modules = map(lambda x: os.path.splitext(os.path.split(x)[1])[0], args.kernel_modules)
object_files = map(lambda x: x + common.obj_ext, kernel_modules)
kernel_modules = map(lambda x: os.path.splitext(os.path.split(x)[1])[0], self.env['kernel_modules'])
object_files = map(lambda x: x + self.env['obj_ext'], kernel_modules)
tool = 'gcc'
if args.host:
if self.env['host']:
allowed_toolchains = ['host']
build_subdir = common.kernel_modules_build_host_subdir
build_subdir = self.env['kernel_modules_build_host_subdir']
else:
allowed_toolchains = None
build_subdir = common.kernel_modules_build_subdir
gcc = common.get_toolchain_tool(tool, allowed_toolchains=allowed_toolchains)
build_subdir = self.env['kernel_modules_build_subdir']
gcc = self.get_toolchain_tool(tool, allowed_toolchains=allowed_toolchains)
prefix = gcc[:-len(tool)]
ccache = shutil.which('ccache')
if ccache is not None:
cc = '{} {}'.format(ccache, gcc)
else:
cc = gcc
if args.verbose:
if self.env['verbose']:
verbose = ['V=1']
else:
verbose = []
if args.host:
if self.env['host']:
linux_dir = os.path.join('/lib', 'modules', platform.uname().release, 'build')
else:
linux_dir = common.linux_build_dir
common.run_cmd(
linux_dir = self.env['linux_build_dir']
self.sh.run_cmd(
(
[
'make', common.Newline,
'-j', str(args.nproc), common.Newline,
'ARCH={}'.format(common.linux_arch), common.Newline,
'CC={}'.format(cc), common.Newline,
'CROSS_COMPILE={}'.format(prefix), common.Newline,
'LINUX_DIR={}'.format(linux_dir), common.Newline,
'M={}'.format(build_subdir), common.Newline,
'OBJECT_FILES={}'.format(' '.join(object_files)), common.Newline,
'make', LF,
'-j', str(self.env['nproc']), LF,
'ARCH={}'.format(self.env['linux_arch']), LF,
'CC={}'.format(cc), LF,
'CROSS_COMPILE={}'.format(prefix), LF,
'LINUX_DIR={}'.format(linux_dir), LF,
'M={}'.format(build_subdir), LF,
'OBJECT_FILES={}'.format(' '.join(object_files)), LF,
] +
common.shlex_split(args.make_args) +
self.sh.shlex_split(self.env['make_args']) +
verbose
),
cwd=os.path.join(common.kernel_modules_build_subdir),
cwd=os.path.join(self.env['kernel_modules_build_subdir']),
)
if not args.host:
common.copy_dir_if_update_non_recursive(
srcdir=common.kernel_modules_build_subdir,
destdir=common.out_rootfs_overlay_dir,
filter_ext=common.kernel_module_ext,
if not self.env['host']:
self.sh.copy_dir_if_update_non_recursive(
srcdir=self.env['kernel_modules_build_subdir'],
destdir=self.env['out_rootfs_overlay_dir'],
filter_ext=self.env['kernel_module_ext'],
)
def get_argparse_args(self):
return {
'description': '''\
Build our Linux kernel modules without using Buildroot.
See also: https://github.com/cirosantilli/linux-kernel-module-cheat#host
'''
}
def get_build_dir(self, args):
if args.host:
return os.path.join(common.kernel_modules_build_host_dir)
def get_build_dir(self):
if self.env['host']:
return self.env['kernel_modules_build_host_dir']
else:
return os.path.join(common.kernel_modules_build_dir)
return self.env['kernel_modules_build_dir']
if __name__ == '__main__':
ModulesComponent().build()
Main().cli()