I try to link some assembler into my kernel module. Later I need to read/write some registers. But already the make fails.
Here is the Makefile, I also have done a Makefile only for the asm which worked.
obj-m := test.o
test-objs := main.o module.o
main.o: main.s
as -o $@ $^
build:
make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules
main.s
.text
.global init
init:
mov r0, #1
ldr r1, =msg
ldr r2, =len
mov r7, #4
swi 0
mov r7, #1
swi 0
.data
msg:
.asciz "hello world\n"
len = .-msg
module.c
#include <linux/module.h>
#include <linux/init.h>
extern int init(void);
extern int cleanup(void);
static int __init main_init(void)
{
return init();
}
static void __exit main_cleanup(void)
{
cleanup();
}
module_init(main_init);
module_exit(main_cleanup);
So when I run the make:
$ make build
make -C /lib/modules/5.10.17-v7l+/build M=/home/pi/test_asm_kmodule2 modules
make[1]: Entering directory '/usr/src/linux-headers-5.10.17-v7l+'
make[2]: *** No rule to make target '/home/pi/test_asm_kmodule2/main.o', needed by '/home/pi/test_asm_kmodule2/test.o'. Stop.
make[1]: *** [Makefile:1804: /home/pi/test_asm_kmodule2] Error 2
make[1]: Leaving directory '/usr/src/linux-headers-5.10.17-v7l+'
make: *** [Makefile:7: build] Error 2