diff options
| author | ruki <[email protected]> | 2021-12-11 00:41:41 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2021-12-11 00:41:41 +0800 |
| commit | 349a22942e600821aa72424bbfa58f021357b1cf (patch) | |
| tree | 5df337d32f9e4dd8464becb82771dc762a04a8a2 | |
| parent | 7908560287910061c942125db6f76884aa2e51b2 (diff) | |
improve module tests
| -rw-r--r-- | tests/projects/linux/driver/hello/Makefile | 4 | ||||
| -rw-r--r-- | tests/projects/linux/driver/hello/src/add.c | 3 | ||||
| -rw-r--r-- | tests/projects/linux/driver/hello/src/hello.c | 4 | ||||
| -rw-r--r-- | xmake/rules/platform/linux/driver/driver_modules.lua | 33 | ||||
| -rw-r--r-- | xmake/rules/platform/linux/driver/xmake.lua | 1 |
5 files changed, 43 insertions, 2 deletions
diff --git a/tests/projects/linux/driver/hello/Makefile b/tests/projects/linux/driver/hello/Makefile index 0cac0535c..1d5aa92b4 100644 --- a/tests/projects/linux/driver/hello/Makefile +++ b/tests/projects/linux/driver/hello/Makefile @@ -1,5 +1,6 @@ ifneq ($(KERNELRELEASE),) - obj-m := src/hello.o + obj-m := hello.o + hello-objs := ./src/hello.o ./src/add.o else KERN_DIR ?= /usr/src/linux-headers-5.11.0-41-generic/ PWD := $(shell pwd) @@ -10,4 +11,5 @@ endif clean: rm -rf *.o *~ core .depend .*.cmd *.ko *.mod.c .tmp_versions + rm -rf src/*.o src/*~ core src/.depend src/.*.cmd src/*.ko src/*.mod.c src/.tmp_versions diff --git a/tests/projects/linux/driver/hello/src/add.c b/tests/projects/linux/driver/hello/src/add.c new file mode 100644 index 000000000..59aab4983 --- /dev/null +++ b/tests/projects/linux/driver/hello/src/add.c @@ -0,0 +1,3 @@ +int add(int a, int b) { + return a + b; +} diff --git a/tests/projects/linux/driver/hello/src/hello.c b/tests/projects/linux/driver/hello/src/hello.c index 2614fb2cc..414a03bb2 100644 --- a/tests/projects/linux/driver/hello/src/hello.c +++ b/tests/projects/linux/driver/hello/src/hello.c @@ -6,9 +6,11 @@ MODULE_AUTHOR("Ruki"); MODULE_DESCRIPTION("A simple Hello World Module"); MODULE_ALIAS("a simplest module"); +int add(int a, int b); + int hello_init(void) { - printk(KERN_INFO "Hello World\n"); + printk(KERN_INFO "Hello World: %d\n", add(1, 2)); return 0; } diff --git a/xmake/rules/platform/linux/driver/driver_modules.lua b/xmake/rules/platform/linux/driver/driver_modules.lua index a94319e8e..a4a4f8691 100644 --- a/xmake/rules/platform/linux/driver/driver_modules.lua +++ b/xmake/rules/platform/linux/driver/driver_modules.lua @@ -18,6 +18,12 @@ -- @file driver_modules.lua -- +-- imports +import("core.base.option") +import("core.project.depend") +import("utils.progress") +import("private.tools.ccache") + -- get linux-headers sdk function _get_linux_headers_sdk(target) local linux_headers = assert(target:pkg("linux-headers"), "please add `add_requires(\"linux-headers\", {configs = {driver_modules = true}})` and `add_packages(\"linux-headers\")` to the given target!") @@ -96,5 +102,32 @@ function load(target) target:add("cflags", "--param asan-globals=1", "--param asan-instrumentation-with-call-threshold=0", "--param asan-stack=1", "--param asan-instrument-allocas=1") end +--[[ +function after_build_file(target, sourcefile, opt) + + -- get modepost + local modpost + local linux_headers = target:data("linux.driver.linux_headers") + if linux_headers then + modpost = path.join(linux_headers.sdkdir, "scripts", "mod", "modpost") + end + assert(modpost and os.isfile(modpost), "modpost not found!") + + -- compile .mod.c file + local objectfile = target:objectfile(sourcefile) + local modfile = objectfile:gsub("%.o$", ".mod") + local modfile_c = objectfile:gsub("%.o$", ".mod.c") + local modfile_o = objectfile:gsub("%.o$", ".mod.o") + local dependfile = target:dependfile(modfile_o) + local exists_ccache = ccache.exists() + depend.on_changed(function () + progress.show(opt.progress, "${color.build.object}%scompiling.mod.$(mode) %s", exists_ccache and "ccache " or "", modfile_c) + os.vrunv(modpost, {"-m", "-a", "-o", }) + end, {dependfile = dependfile, files = {sourcefile}}) + + -- echo build/.objs/hello/linux/x86_64/release/src/hello.c.o | + -- scripts/mod/modpost -m -a -o /tmp/Module.symvers -e -N -T - +end]] + function link(target, opt) end diff --git a/xmake/rules/platform/linux/driver/xmake.lua b/xmake/rules/platform/linux/driver/xmake.lua index 84960049d..78ba6d089 100644 --- a/xmake/rules/platform/linux/driver/xmake.lua +++ b/xmake/rules/platform/linux/driver/xmake.lua @@ -20,6 +20,7 @@ -- build linux driver module rule("platform.linux.driver") + set_sourcekinds("cc") on_load(function (target) import("driver_modules").load(target) end) |
