starfive-tech / VisionFive2

445 stars 79 forks source link

Failed to compile standalone driver module #23

Open ZZPHUB opened 1 year ago

ZZPHUB commented 1 year ago

i use img debian 69 and the toolchain is the gcc that i installed by apt in the 69img

and i git cloned the linux source form here,then i follow this doc to build the img to configure the settings.and i use this way to build,the makefile:

ARCH = riscv
CROSS_COMPILE =

KERN_DIR =  /home/**path to linux source**/linux

all:
        make -C $(KERN_DIR) M=`pwd` modules 

clean:
        make -C $(KERN_DIR) M=`pwd` modules clean
        rm -rf modules.order

obj-m   += hello_drv.o

i can get the .ko file but i cannot insmod this file.the message is

insmod: ERROR: could not insert module hello_drv.ko: Invalid module format

when i use the commanddmesg |grep hellodev(the mode name),the message is:

hello_drv: version magic '5.15.0 SMP mod_unload riscv' should be '5.15.0-starfive SMP mod_unload riscv'

so,i change the makefile:

ARCH = riscv
CROSS_COMPILE =

KVERSION = $(shell uname -r)
KERN_DIR =  /lib/modules/$(KVERSION)/build 

all:
        make -C $(KERN_DIR) M=`pwd` modules 

clean:
        make -C $(KERN_DIR) M=`pwd` modules clean
        rm -rf modules.order

obj-m   += hello_drv.o

but the err message is :

make -C /lib/modules/5.15.0-starfive/build  M=`pwd` modules 
make[1]: 进入目录“/usr/src/linux-headers-5.15.0-starfive”
scripts/Makefile.build:44: arch/riscv/kernel/vdso/Makefile: 没有那个文件或目录
make[2]: *** 没有规则可制作目标“arch/riscv/kernel/vdso/Makefile”。 停止。
make[1]: *** [arch/riscv/Makefile:114:vdso_prepare] 错误 2
make[1]: 离开目录“/usr/src/linux-headers-5.15.0-starfive”
make: *** [Makefile:8:all] 错误 2
st3g4n0 commented 1 year ago

same here when trying to compile a kernel module:

make -C /lib/modules/5.15.0-starfive/build M=pwd modules make[1]: Entering directory '/usr/src/linux-headers-5.15.0-starfive' scripts/Makefile.build:44: arch/riscv/kernel/vdso/Makefile: No such file or directory make[2]: No rule to make target 'arch/riscv/kernel/vdso/Makefile'. Stop. make[1]: [arch/riscv/Makefile:120: vdso_prepare] Error 2 make[1]: Leaving directory '/usr/src/linux-headers-5.15.0-starfive' make: *** [Makefile:8: all] Error 2

ZZPHUB commented 1 year ago

same here when trying to compile a kernel module:

make -C /lib/modules/5.15.0-starfive/build M=pwd modules make[1]: Entering directory '/usr/src/linux-headers-5.15.0-starfive' scripts/Makefile.build:44: arch/riscv/kernel/vdso/Makefile: No such file or directory make[2]: No rule to make target 'arch/riscv/kernel/vdso/Makefile'. Stop. make[1]: [arch/riscv/Makefile:120: vdso_prepare] Error 2 make[1]: Leaving directory '/usr/src/linux-headers-5.15.0-starfive' make: *** [Makefile:8: all] Error 2

i use cross compile to solve this problem,and it can work well.but i donnot know how to build in vf2 board.