# How to compile kernel module for Pynq v3

**URL:** <https://discuss.pynq.io/t/how-to-compile-kernel-module-for-pynq-v3/5870>\
**Category:** Support\
**Created:** [July 25, 2023, 8:17am UTC](https://discuss.pynq.io/t/how-to-compile-kernel-module-for-pynq-v3/5870 "2023-07-25T08:17:33Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![RogerPease](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.pynq.io/rogerpease/32/6592_2.png) [@RogerPease](https://discuss.pynq.io/u/RogerPease)\
**Post date:** [January 15, 2025, 8:45pm UTC](https://discuss.pynq.io/t/how-to-compile-kernel-module-for-pynq-v3/5870/2 "2025-01-15T20:45:07Z")

</div>

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](https://github.com/Xilinx/linux-xlnx/) 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:

```auto
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.

---

_[View the full topic](https://discuss.pynq.io/t/how-to-compile-kernel-module-for-pynq-v3/5870)._
