diff --git a/host/Makefile b/host/Makefile index bf34299..2de3b3d 100644 --- a/host/Makefile +++ b/host/Makefile @@ -3,14 +3,10 @@ ccflags-y := -Wno-declaration-after-statement -std=gnu99 .PHONY: all clean -all: hello.ko ins_rm_mod.out +all: hello.ko hello.ko: hello.c make -C '/lib/modules/$(shell uname -r)/build' M='$(PWD)' modules clean: make -C '/lib/modules/$(shell uname -r)/build' M='$(PWD)' clean - rm -f ins_rm_mod.out - -ins_rm_mod.out: ins_rm_mod.c hello.c - gcc -Wall -std=gnu99 -o ins_rm_mod.out ins_rm_mod.c diff --git a/host/README.md b/host/README.md index 5e084e1..d603ce0 100644 --- a/host/README.md +++ b/host/README.md @@ -3,7 +3,6 @@ Simple things that can be demonstrated by inserting a module into the currently running host. Tested on Ubuntu 16.04. 1. [hello](hello.c) -1. [ins_rm_mod.c](ins_rm_mod.c) ## Rationale @@ -34,7 +33,3 @@ Build, insert and remove a hello world module: # Last message should be: cleanup_module dmest -T - -Insert and remove the `hello.ko` module from a C program with system calls: - - sudo ./ins_rm_mod.out diff --git a/kernel_module/Makefile b/kernel_module/Makefile index 87d35c0..2eca9b8 100644 --- a/kernel_module/Makefile +++ b/kernel_module/Makefile @@ -1,10 +1,13 @@ obj-m += $(addsuffix .o, $(notdir $(basename $(wildcard $(BR2_EXTERNAL_KERNEL_MODULE_PATH)/*.c)))) ccflags-y := -Wno-declaration-after-statement -std=gnu99 -.PHONY: all clean +.PHONY: all clean test -all: +all: test $(MAKE) -C '$(LINUX_DIR)' M='$(PWD)' modules clean: $(MAKE) -C '$(LINUX_DIR)' M='$(PWD)' clean + +test: + $(MAKE) -C '$(PWD)/test' diff --git a/kernel_module/delay.c b/kernel_module/delay.c index 90ac0f4..a1fa527 100644 --- a/kernel_module/delay.c +++ b/kernel_module/delay.c @@ -43,7 +43,9 @@ void cleanup_module(void) { /* This waits for the work to finish. From docstring: */ /* > Cancel @work and wait for its execution to finish. */ - cancel_work_sync(&work); + cancel_work(&work); + + /*cancel_work(&work);*/ destroy_workqueue(queue); } diff --git a/kernel_module/external.mk b/kernel_module/external.mk index a26eb55..476e933 100644 --- a/kernel_module/external.mk +++ b/kernel_module/external.mk @@ -13,7 +13,8 @@ define KERNEL_MODULE_BUILD_CMDS endef define KERNEL_MODULE_INSTALL_TARGET_CMDS - $(INSTALL) -D -m 0755 $(@D)/*.ko '$(TARGET_DIR)' + $(INSTALL) -D -m 0655 $(@D)/*.ko '$(TARGET_DIR)' + $(INSTALL) -D -m 0755 $(@D)/test/ins_rm_mod '$(TARGET_DIR)' endef $(eval $(kernel-module)) diff --git a/kernel_module/test/Makefile b/kernel_module/test/Makefile new file mode 100644 index 0000000..967dd33 --- /dev/null +++ b/kernel_module/test/Makefile @@ -0,0 +1,9 @@ +CC = gcc + +.PHONY: clean + +ins_rm_mod: ins_rm_mod.c + $(CC) -o '$@' '$<' + +clean: + rm ins_rm_mod diff --git a/kernel_module/test/README.md b/kernel_module/test/README.md new file mode 100644 index 0000000..10ee2a8 --- /dev/null +++ b/kernel_module/test/README.md @@ -0,0 +1,9 @@ +# Test + +Userland C programs used to test our kernel module. + +`sh` programs are simpler, and installed copied directly with an overlay. + +C programs require cross compiling, but give us more control over system calls. + +These programs can also be compiled and used on host. diff --git a/kernel_module/test/ins_rm_mod b/kernel_module/test/ins_rm_mod new file mode 100755 index 0000000..c4f7df7 Binary files /dev/null and b/kernel_module/test/ins_rm_mod differ diff --git a/host/ins_rm_mod.c b/kernel_module/test/ins_rm_mod.c similarity index 100% rename from host/ins_rm_mod.c rename to kernel_module/test/ins_rm_mod.c