host kernel module works

This commit is contained in:
Ciro Santilli 六四事件 法轮功
2018-10-31 23:00:01 +00:00
parent 911dd8be32
commit 65a103d6c1
4 changed files with 28 additions and 24 deletions

10
.gitignore vendored
View File

@@ -21,3 +21,13 @@ __pycache__
/m5out
*.o
*.out
# Kernel modules.
.cache.mk
*.ko.cmd
*.o.cmd
.tmp_versions
Module.symvers
*.ko
*.mod.c
modules.order

View File

@@ -701,7 +701,7 @@ mv broken.c broken.c~
Once you manage to compile, and have come to terms with the fact that this may blow up your host, try it out with:
....
cd "$(./getvar kernel_modules_build_host_dir)"
cd "$(./getvar kernel_modules_build_host_subdir)"
sudo insmod hello.ko
# Our module is there.
@@ -726,9 +726,9 @@ Minimal host build system example:
....
cd hello_host_kernel_module
make
insmod hello.ko
sudo insmod hello.ko
dmesg
rmmod hello.ko
sudo rmmod hello.ko
dmesg
....
@@ -861,17 +861,6 @@ echo "$(./getvar --arch arm --baremetal prompt --gem5 --machine RealViewPBX
But just stick to newer and better `VExpress_GEM5_V1` unless you have a good reason to use `RealViewPBX`.
This patch is required only for baremetal because the Linux bootloader enters 32 bit mode and switches to 64 for us, but the in the baremetal system we use our own bootloader.
Therefore we must tell gem5 to start the system in aarch64 mode for us with the options:
....
highest_el_is_64 = True
auto_reset_addr_64 = True
....
That patch breaks `--arch arm`, so don't forget to remove it if you want to go back to it.
When doing bare metal programming, it is likely that you will want to learn assembly language basics. Have a look at these tutorials for the userland part:
* https://github.com/cirosantilli/x86-assembly-cheat

View File

@@ -3,6 +3,7 @@
import distutils.dir_util
import os
import platform
import shlex
import shutil
import common
@@ -10,9 +11,8 @@ import common
class ModulesComponent(common.Component):
def add_parser_arguments(self, parser):
parser.add_argument(
'extra_make_args',
default=[],
metavar='extra-make-args',
'--make-args',
default='',
nargs='*'
)
parser.add_argument(
@@ -65,8 +65,10 @@ class ModulesComponent(common.Component):
tool = 'gcc'
if args.host:
allowed_toolchains = ['host']
build_subdir = common.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)
prefix = gcc[:-len(tool)]
ccache = shutil.which('ccache')
@@ -91,18 +93,20 @@ class ModulesComponent(common.Component):
'CC={}'.format(cc),
'CROSS_COMPILE={}'.format(prefix),
'LINUX_DIR={}'.format(linux_dir),
'M={}'.format(common.kernel_modules_build_subdir),
'M={}'.format(build_subdir),
'OBJECT_FILES={}'.format(' '.join(object_files)),
] +
shlex.split(args.make_args) +
verbose
),
cwd=os.path.join(build_subdir),
)
common.copy_dir_if_update_non_recursive(
srcdir=build_subdir,
destdir=common.out_rootfs_overlay_dir,
filter_ext=common.kernel_module_ext,
cwd=os.path.join(common.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,
)
def get_argparse_args(self):
return {

View File

@@ -804,6 +804,7 @@ def setup(parser):
this_module.kernel_modules_build_dir = os.path.join(this_module.kernel_modules_build_base_dir, args.arch)
this_module.kernel_modules_build_subdir = os.path.join(this_module.kernel_modules_build_dir, kernel_modules_subdir)
this_module.kernel_modules_build_host_dir = os.path.join(this_module.kernel_modules_build_base_dir, 'host')
this_module.kernel_modules_build_host_subdir = os.path.join(this_module.kernel_modules_build_host_dir, kernel_modules_subdir)
this_module.userland_build_dir = os.path.join(this_module.out_dir, 'userland', args.userland_build_id, args.arch)
this_module.out_rootfs_overlay_dir = os.path.join(this_module.out_dir, 'rootfs_overlay', args.arch)
this_module.out_rootfs_overlay_bin_dir = os.path.join(this_module.out_rootfs_overlay_dir, 'bin')