Linux driver module compile needs Linux headers

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Linux driver module compile needs Linux headers

2,841 Views
penman
Contributor II

I need to compile a Linux driver and it depends on Linux headers which are not installed in the LSDK generated base filesystem (Ubuntu based).

Ideally, one could request appropriate Linux headers with 'sudo apt-get install linux-headers-$(uname -r)',  however the LSDK does not make this package available.

What is the recommended way to make header files available to compile a Linux driver in LSDK?

Labels (1)
0 Kudos
Reply
5 Replies

2,502 Views
bpe
NXP Employee
NXP Employee

The suggested steps are:

1. Build the LSDK kernel in any recommended way:

    a) by hand;
    
    b) with LSDK automation tool called flex-builder;

3. Follow the instructions in this file to build an external kernel module

0 Kudos
Reply

2,502 Views
penman
Contributor II

In the file referenced in the previous message:

https://community.nxp.com/external-link.jspa?url=https%3A%2F%2Fsource.codeaurora.org%2Fexternal%2Fqo... 

Step 2.1 and 2.2 refer to a <path_to_kernel_src> and ($KDIR refers to the path of the kernel source directory.)

A kernel source directory is not present in the filesystem generated by LSDK.

What is the recommended way to get the kernel source directory into the filesystem?

(I've tried several methods that do not work, including 'sudo apt-get install linux-headers-$(uname -r)' and copying directories from the packages and build directories.)

0 Kudos
Reply

2,502 Views
bpe
NXP Employee
NXP Employee

Are you trying to build your module directly on the target? Otherwise, you do not need kernel sources or headers in the

target filesystem. Note, all my suggestions above are for building the kernel and modules for your target system on a

system where your LSDK is installed, which should be an x86 Linux machine. That is the recommended method.

0 Kudos
Reply

2,502 Views
penman
Contributor II

Yes, we are building the module on the target, common for chip vendors supplying Linux drivers that depend on a running target, evidenced in the call to 'uname -r' of section 2.1 in the how to build an external kernel module above. 

Similarly, for cross compilation, reference in section 2.2, also depends on a valid $KDIR.

 I don't see where/how the LSDK has or can generate this directory.

I've tried following the docs/flexbuild_usage.txt section 'Build Distro Root Filesystem'

sudo chroot build/rfs/rootfs_lsdk_19.03_LS_arm64/ apt install linux-headers-4.19.26
[sudo] password for username:
Reading package lists... Done
Building dependency tree      
Reading state information... Done
E: Unable to locate package linux-headers-4.19.26
E: Couldn't find any package by glob 'linux-headers-4.19.26'
E: Couldn't find any package by regex 'linux-headers-4.19.26'

Also,

LSDK/build/Linux/Linux/arm64/LS/output/LSDK-19.03-V4.19

and

LSDK/package/Linux/Linux 

,neither are to be a valid $KDIR as needed for section 2.2.

What directory should be used for $KDIR?

0 Kudos
Reply

2,502 Views
bpe
NXP Employee
NXP Employee

On my machine, the directory valid for KDIR is <LSDK_INSTALL_DIR>/build/linux/linux/arm64/LS/output/LSDK-19.06-V4.19. I've tried it with several off-kernel modules before posting this and all of them succeeded . I do not have LSDK 19.03

by hand but it should be similar. If that doesn't work for you, make sure flex-builder builds the kernel successfully (flex-builder -c linux ). Also, after a successful kernel build, there should be kernel headers under build/images/

0 Kudos
Reply