Building new module without petalinux

I have the pynq and linux package installed on ZCU104 and running well, and I could build a simple helloworld.c file with either gcc or aarch64-linux-gnu-gcc, both can build and run. However, when I tried to build a very simple kernel module (just init and exit), it always fail with errors below:

make -C /lib/modules/5.4.0-xilinx-v2020.1/build M=/home/xilinx/code/pli2c modules
make[1]: Entering directory ‘/lib/modules/5.4.0-xilinx-v2020.1/build’
arch/arm64/Makefile:52: Detected assembler with broken .inst; disassembly will be unreliable
CC [M] /home/xilinx/code/pli2c/mymodule.o
aarch64-linux-gnu-gcc: error: unrecognized command line option ‘-mstack-protector-guard=sysreg’; did you mean ‘-fstack-protector-strong’?
aarch64-linux-gnu-gcc: error: unrecognized command line option ‘-mstack-protector-guard-reg=sp_el0’; did you mean ‘-fstack-protector-all’?
aarch64-linux-gnu-gcc: error: unrecognized command line option ‘-mstack-protector-guard-offset=1064’; did you mean ‘-fstack-protector-strong’?
scripts/Makefile.build:265: recipe for target ‘/home/xilinx/code/pli2c/mymodule.o’ failed
make[2]: *** [/home/xilinx/code/pli2c/mymodule.o] Error 1
Makefile:1652: recipe for target ‘/home/xilinx/code/pli2c’ failed
make[1]: *** [/home/xilinx/code/pli2c] Error 2
make[1]: Leaving directory ‘/lib/modules/5.4.0-xilinx-v2020.1/build’
Makefile:13: recipe for target ‘all’ failed
make: *** [all] Error 2

here’s the makefile:

export ARCH:=arm64
export CROSS_COMPILE:=aarch64-linux-gnu-
CC=$(CROSS_COMPILE)gcc
KERNEL_SRC=/lib/modules/$(shell uname -r)/build
obj-m += mymodule.o
all:
make -C ${KERNEL_SRC} M=$(PWD) modules
clean:
make -C ${KERNEL_SRC} M=$(PWD) clean

I spend a lot of time but still could not figure out why it cannot build. Could someone help to take a look and give some hint of the possible cause? Is any linux files missing? neither petalinux nor vitis is installed on the linux.

Thanks very much!

1 Like