How to compile kernel module for Pynq v3

Realize this question is 18 months old but I was having the same issue and didn’t see a reply. I tried to compile natively on the Xilinx board and got the asm/bitsperlong.h error. Also tried the sd card rebuild and chewed up my month’s ISP data allowance.

Xilinx publishes the linux distros at GitHub - Xilinx/linux-xlnx: The official Linux kernel from Xilinx After a few educated guesses I was able to find the version that matched uname -r from my Pynq Z2 (v3.0.1 in my case).

Get the linux-xlnx-xlnx_rebase_v5.15_LTS_2022.1_update2.tar.gz (or appropriate for your version) from the github repo and untar it into your desk/laptop. I am assuming you are cross-compiling.

cd into ./linux-xlnx-xlnx_rebase_v5.15_LTS_2022.1_update2
You can use make kernelversion to verify version base number.
The -xilinx-v2022.1 is a .config variable CONFIG_LOCAL_VERSION
Copy the .config from xilinx-board /lib/modules/uname -r/build to .config in this directory.

Then run:

ARCH=arm CROSS_COMPILE=arm-linux-gnueabi- make
ARCH=arm CROSS_COMPILE=arm-linux-gnueabi- make modules

You may need to install the cross compiler and build essentials… If you hit an error from that Google is your friend.

Then to make your own module, update your module’s Makefile:

KERNEL_DIR=/path/to/linux-xlnx-xlnx_rebase_v5.15_LTS_2022.1_update2


all:
        ARCH=arm CROSS_COMPILE=arm-linux-gnueabi- make -C $(KERNEL_DIR) M=$(shell pwd) modules

Hope this helps. I can’t promise you can rebuild the whole kernel this way because there may be patches for the modules.