Install kernel-headers on target - flexbuild Linux Debian 6.12.49

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

Install kernel-headers on target - flexbuild Linux Debian 6.12.49

Jump to solution
95 Views
sombreminjaben
Contributor I

Hi,

I am developing a custom out-of-tree Linux module for my IMX8MP-EVK board running Debian Linux (built using the latest version of flexbuild). Currently, to build my module, I added it to the Linux sources, modifying the corresponding Kconfig and Makefile. However, I would like to be able to build my module on-target to make the process faster but there are no kernel-headers installed and I can't seem to find how to get them on target. 

Could anyone guide me on how to build my Debian Linux with kernel-headers installed ?

Thanks.

Benjamin.

Labels (1)
0 Kudos
Reply
1 Solution
66 Views
yipingwang
NXP TechSupport
NXP TechSupport

For the i.MX8MP-EVK Debian image built with Flexbuild, the practical answer is: do not rely on apt install linux-headers-$(uname -r) on the target . The retrieved NXP material shows Flexbuild builds the kernel, DTBs, modules, boot image, and rootfs, but I did not find an i.MX8MP-specific Flexbuild option that generates and preinstalls a matching linux-headers-* package into the Debian rootfs. The supported/clean workflow is to build your out-of-tree module against the same compiled kernel tree used by Flexbuild, then copy the .ko to the board.

Recommended workflow:

cd flexbuild

. setup.env

bld docker

. setup.env

bld host-dep

 

# Full image, or at least the kernel

LOG_LEVEL=0 bld -m imx8mpevk

# or:

LOG_LEVEL=0 bld linux -m imx8mpevk

The Debian SDK guide lists bld -m imx8mpevk as the full build command and bld linux -m imx8mpevk as the separate kernel build command; it also says the kernel-related source is under components_lsdk2512/linux/ , and the compiled output is under build_lsdk2512/linux/linux/arm64/IMX for the i.MX platform example.

Then build your external module on the host against that compiled/prepared kernel tree, for example:

obj-m += my_driver.o

 

KERNEL_SRC ?= /path/to/flexbuild/components_lsdk2512/linux

 

all:

              $(MAKE) -C $(KERNEL_SRC) M=$(PWD) modules

 

clean:

              $(MAKE) -C $(KERNEL_SRC) M=$(PWD) clean

For external modules, NXP’s current i.MX Linux 6.12 guide says the requirements are a compiled kernel, a board running the same kernel version, and a toolchain; it also notes that a full kernel compilation is required to generate the headers and symbol files needed for external module compilation. The same guide uses the standard external-module form:

make -C $(KERNEL_SRC) M=$(PWD) modules

and then copies the resulting .ko to the board for insmod .

If you specifically want on-target builds, you can manually install a matching prepared kernel tree on the target, but treat it as a manual workaround rather than a documented i.MX8MP Flexbuild “install headers” feature:

# on target

sudo mkdir -p /usr/src/linux-headers-$(uname -r)

sudo ln -sfn /usr/src/linux-headers-$(uname -r) /lib/modules/$(uname -r)/build

Copy the matching Flexbuild kernel source/build artifacts from the host into that directory, including the generated files and Module.symvers . Then on the target:

cd /usr/src/linux-headers-$(uname -r)

make oldconfig

make prepare

# or, for module builds:

make modules_prepare

The important points are:

  • The kernel source/build tree must match the exact kernel running on the board: check uname -r .
  • Module.symvers should be present; otherwise module versioning/dependency information may be missing.
  • make oldconfig && make prepare / make modules_prepare is the usual step to prepare the tree for external module builds.
  • Native builds on the board are usually slower; NXP guidance generally recommends host-side cross-compilation for i.MX external modules.

So the short answer is: Flexbuild can build the matching kernel, but for i.MX8MP Debian I would build the module on the host against the Flexbuild kernel tree, not try to install distro-style linux-headers on the board. If you need on-target iteration, copy the matching prepared kernel tree to /usr/src/linux-headers-$(uname -r) and point /lib/modules/$(uname -r)/build at it.

Use the Flexbuild-compiled kernel tree as your “headers” source; a packaged, apt-installable linux-headers-$(uname -r) flow is not documented for i.MX8MP Flexbuild Debian in the material retrieved.

 

View solution in original post

0 Kudos
Reply
2 Replies
56 Views
sombreminjaben
Contributor I

Hi,

Yes I quickly figured that trying apt install linux-headers-$(uname -r) would not give me the right headers.

Thank you for your quick response, I should be able to adopt a workflow that works for me.

0 Kudos
Reply
67 Views
yipingwang
NXP TechSupport
NXP TechSupport

For the i.MX8MP-EVK Debian image built with Flexbuild, the practical answer is: do not rely on apt install linux-headers-$(uname -r) on the target . The retrieved NXP material shows Flexbuild builds the kernel, DTBs, modules, boot image, and rootfs, but I did not find an i.MX8MP-specific Flexbuild option that generates and preinstalls a matching linux-headers-* package into the Debian rootfs. The supported/clean workflow is to build your out-of-tree module against the same compiled kernel tree used by Flexbuild, then copy the .ko to the board.

Recommended workflow:

cd flexbuild

. setup.env

bld docker

. setup.env

bld host-dep

 

# Full image, or at least the kernel

LOG_LEVEL=0 bld -m imx8mpevk

# or:

LOG_LEVEL=0 bld linux -m imx8mpevk

The Debian SDK guide lists bld -m imx8mpevk as the full build command and bld linux -m imx8mpevk as the separate kernel build command; it also says the kernel-related source is under components_lsdk2512/linux/ , and the compiled output is under build_lsdk2512/linux/linux/arm64/IMX for the i.MX platform example.

Then build your external module on the host against that compiled/prepared kernel tree, for example:

obj-m += my_driver.o

 

KERNEL_SRC ?= /path/to/flexbuild/components_lsdk2512/linux

 

all:

              $(MAKE) -C $(KERNEL_SRC) M=$(PWD) modules

 

clean:

              $(MAKE) -C $(KERNEL_SRC) M=$(PWD) clean

For external modules, NXP’s current i.MX Linux 6.12 guide says the requirements are a compiled kernel, a board running the same kernel version, and a toolchain; it also notes that a full kernel compilation is required to generate the headers and symbol files needed for external module compilation. The same guide uses the standard external-module form:

make -C $(KERNEL_SRC) M=$(PWD) modules

and then copies the resulting .ko to the board for insmod .

If you specifically want on-target builds, you can manually install a matching prepared kernel tree on the target, but treat it as a manual workaround rather than a documented i.MX8MP Flexbuild “install headers” feature:

# on target

sudo mkdir -p /usr/src/linux-headers-$(uname -r)

sudo ln -sfn /usr/src/linux-headers-$(uname -r) /lib/modules/$(uname -r)/build

Copy the matching Flexbuild kernel source/build artifacts from the host into that directory, including the generated files and Module.symvers . Then on the target:

cd /usr/src/linux-headers-$(uname -r)

make oldconfig

make prepare

# or, for module builds:

make modules_prepare

The important points are:

  • The kernel source/build tree must match the exact kernel running on the board: check uname -r .
  • Module.symvers should be present; otherwise module versioning/dependency information may be missing.
  • make oldconfig && make prepare / make modules_prepare is the usual step to prepare the tree for external module builds.
  • Native builds on the board are usually slower; NXP guidance generally recommends host-side cross-compilation for i.MX external modules.

So the short answer is: Flexbuild can build the matching kernel, but for i.MX8MP Debian I would build the module on the host against the Flexbuild kernel tree, not try to install distro-style linux-headers on the board. If you need on-target iteration, copy the matching prepared kernel tree to /usr/src/linux-headers-$(uname -r) and point /lib/modules/$(uname -r)/build at it.

Use the Flexbuild-compiled kernel tree as your “headers” source; a packaged, apt-installable linux-headers-$(uname -r) flow is not documented for i.MX8MP Flexbuild Debian in the material retrieved.

 

0 Kudos
Reply
%3CLINGO-SUB%20id%3D%22lingo-sub-2410357%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3EInstall%20kernel-headers%20on%20target%20-%20flexbuild%20Linux%20Debian%206.12.49%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2410357%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CP%3EHi%2C%3C%2FP%3E%3CP%3EI%20am%20developing%20a%20custom%20out-of-tree%20Linux%20module%20for%20my%20IMX8MP-EVK%20board%20running%20Debian%20Linux%20(built%20using%20the%20latest%20version%20of%20flexbuild).%20Currently%2C%20to%20build%20my%20module%2C%20I%20added%20it%20to%20the%20Linux%20sources%2C%20modifying%20the%20corresponding%20Kconfig%20and%20Makefile.%20However%2C%20I%20would%20like%20to%20be%20able%20to%20build%20my%20module%20on-target%20to%20make%20the%20process%20faster%20but%20there%20are%20no%20kernel-headers%20installed%20and%20I%20can't%20seem%20to%20find%20how%20to%20get%20them%20on%20target.%26nbsp%3B%3C%2FP%3E%3CP%3ECould%20anyone%20guide%20me%20on%20how%20to%20build%20my%20Debian%20Linux%20with%20kernel-headers%20installed%20%3F%3C%2FP%3E%3CP%3EThanks.%3C%2FP%3E%3CP%3EBenjamin.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-2410357%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CLINGO-LABEL%3Ei.MX%208M%20%7C%20i.MX%208M%20Mini%20%7C%20i.MX%208M%20Nano%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2410566%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%20translate%3D%22no%22%3ERe%3A%20Install%20kernel-headers%20on%20target%20-%20flexbuild%20Linux%20Debian%206.12.49%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2410566%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CP%3EHi%2C%3C%2FP%3E%3CP%3EYes%20I%20quickly%20figured%20that%20trying%26nbsp%3B%3CSTRONG%3Eapt%20install%20linux-headers-%24(uname%20-r)%26nbsp%3B%3C%2FSTRONG%3Ewould%20not%20give%20me%20the%20right%20headers.%3C%2FP%3E%3CP%3EThank%20you%20for%20your%20quick%20response%2C%20I%20should%20be%20able%20to%20adopt%20a%20workflow%20that%20works%20for%20me.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2410476%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%20translate%3D%22no%22%3ERe%3A%20Install%20kernel-headers%20on%20target%20-%20flexbuild%20Linux%20Debian%206.12.49%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2410476%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CP%3EFor%20the%20i.MX8MP-EVK%20Debian%20image%20built%20with%20Flexbuild%2C%20the%20practical%20answer%20is%3A%26nbsp%3B%3CSTRONG%3Edo%20not%20rely%20on%26nbsp%3Bapt%20install%20linux-headers-%24(uname%20-r)%26nbsp%3Bon%20the%20target%3C%2FSTRONG%3E%26nbsp%3B.%20The%20retrieved%20NXP%20material%20shows%20Flexbuild%20builds%20the%20kernel%2C%20DTBs%2C%20modules%2C%20boot%20image%2C%20and%20rootfs%2C%20but%20I%20did%20not%20find%20an%20i.MX8MP-specific%20Flexbuild%20option%20that%20generates%20and%20preinstalls%20a%20matching%26nbsp%3Blinux-headers-*%26nbsp%3Bpackage%20into%20the%20Debian%20rootfs.%20The%20supported%2Fclean%20workflow%20is%20to%20build%20your%20out-of-tree%20module%20against%20the%26nbsp%3B%3CSTRONG%3Esame%20compiled%20kernel%20tree%3C%2FSTRONG%3E%26nbsp%3Bused%20by%20Flexbuild%2C%20then%20copy%20the%26nbsp%3B.ko%26nbsp%3Bto%20the%20board.%3C%2FP%3E%0A%3CP%3ERecommended%20workflow%3A%3C%2FP%3E%0A%3CP%3Ecd%20flexbuild%3C%2FP%3E%0A%3CP%3E.%20setup.env%3C%2FP%3E%0A%3CP%3Ebld%20docker%3C%2FP%3E%0A%3CP%3E.%20setup.env%3C%2FP%3E%0A%3CP%3Ebld%20host-dep%3C%2FP%3E%0A%3CBR%20%2F%3E%0A%3CP%3E%23%20Full%20image%2C%20or%20at%20least%20the%20kernel%3C%2FP%3E%0A%3CP%3ELOG_LEVEL%3D0%20bld%20-m%20imx8mpevk%3C%2FP%3E%0A%3CP%3E%23%20or%3A%3C%2FP%3E%0A%3CP%3ELOG_LEVEL%3D0%20bld%20linux%20-m%20imx8mpevk%3C%2FP%3E%0A%3CP%3EThe%20Debian%20SDK%20guide%20lists%26nbsp%3Bbld%20-m%20imx8mpevk%26nbsp%3Bas%20the%20full%20build%20command%20and%26nbsp%3Bbld%20linux%20-m%20imx8mpevk%26nbsp%3Bas%20the%20separate%20kernel%20build%20command%3B%20it%20also%20says%20the%20kernel-related%20source%20is%20under%26nbsp%3Bcomponents_lsdk2512%2Flinux%2F%26nbsp%3B%2C%20and%20the%20compiled%20output%20is%20under%26nbsp%3Bbuild_lsdk2512%2Flinux%2Flinux%2Farm64%2FIMX%26nbsp%3Bfor%20the%20i.MX%20platform%20example.%3C%2FP%3E%0A%3CP%3EThen%20build%20your%20external%20module%20on%20the%20host%20against%20that%20compiled%2Fprepared%20kernel%20tree%2C%20for%20example%3A%3C%2FP%3E%0A%3CP%3Eobj-m%20%2B%3D%20my_driver.o%3C%2FP%3E%0A%3CBR%20%2F%3E%0A%3CP%3EKERNEL_SRC%20%3F%3D%20%2Fpath%2Fto%2Fflexbuild%2Fcomponents_lsdk2512%2Flinux%3C%2FP%3E%0A%3CBR%20%2F%3E%0A%3CP%3Eall%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%24(MAKE)%20-C%20%24(KERNEL_SRC)%20M%3D%24(PWD)%20modules%3C%2FP%3E%0A%3CBR%20%2F%3E%0A%3CP%3Eclean%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%24(MAKE)%20-C%20%24(KERNEL_SRC)%20M%3D%24(PWD)%20clean%3C%2FP%3E%0A%3CP%3EFor%20external%20modules%2C%20NXP%E2%80%99s%20current%20i.MX%20Linux%206.12%20guide%20says%20the%20requirements%20are%20a%20compiled%20kernel%2C%20a%20board%20running%20the%20same%20kernel%20version%2C%20and%20a%20toolchain%3B%20it%20also%20notes%20that%20a%20full%20kernel%20compilation%20is%20required%20to%20generate%20the%20headers%20and%20symbol%20files%20needed%20for%20external%20module%20compilation.%26nbsp%3BThe%20same%20guide%20uses%20the%20standard%20external-module%20form%3A%3C%2FP%3E%0A%3CP%3Emake%20-C%20%24(KERNEL_SRC)%20M%3D%24(PWD)%20modules%3C%2FP%3E%0A%3CP%3Eand%20then%20copies%20the%20resulting%26nbsp%3B.ko%26nbsp%3Bto%20the%20board%20for%26nbsp%3Binsmod%26nbsp%3B.%3C%2FP%3E%0A%3CP%3EIf%20you%20specifically%20want%26nbsp%3B%3CSTRONG%3Eon-target%3C%2FSTRONG%3E%26nbsp%3Bbuilds%2C%20you%20can%20manually%20install%20a%20matching%20prepared%20kernel%20tree%20on%20the%20target%2C%20but%20treat%20it%20as%20a%20manual%20workaround%20rather%20than%20a%20documented%20i.MX8MP%20Flexbuild%20%E2%80%9Cinstall%20headers%E2%80%9D%20feature%3A%3C%2FP%3E%0A%3CP%3E%23%20on%20target%3C%2FP%3E%0A%3CP%3Esudo%20mkdir%20-p%20%2Fusr%2Fsrc%2Flinux-headers-%24(uname%20-r)%3C%2FP%3E%0A%3CP%3Esudo%20ln%20-sfn%20%2Fusr%2Fsrc%2Flinux-headers-%24(uname%20-r)%20%2Flib%2Fmodules%2F%24(uname%20-r)%2Fbuild%3C%2FP%3E%0A%3CP%3ECopy%20the%20matching%20Flexbuild%20kernel%20source%2Fbuild%20artifacts%20from%20the%20host%20into%20that%20directory%2C%20including%20the%20generated%20files%20and%26nbsp%3BModule.symvers%26nbsp%3B.%20Then%20on%20the%20target%3A%3C%2FP%3E%0A%3CP%3Ecd%20%2Fusr%2Fsrc%2Flinux-headers-%24(uname%20-r)%3C%2FP%3E%0A%3CP%3Emake%20oldconfig%3C%2FP%3E%0A%3CP%3Emake%20prepare%3C%2FP%3E%0A%3CP%3E%23%20or%2C%20for%20module%20builds%3A%3C%2FP%3E%0A%3CP%3Emake%20modules_prepare%3C%2FP%3E%0A%3CP%3EThe%20important%20points%20are%3A%3C%2FP%3E%0A%3CUL%3E%0A%3CLI%3EThe%20kernel%20source%2Fbuild%20tree%20must%20match%20the%20exact%20kernel%20running%20on%20the%20board%3A%20check%26nbsp%3Buname%20-r%26nbsp%3B.%3C%2FLI%3E%0A%3CLI%3EModule.symvers%26nbsp%3Bshould%20be%20present%3B%20otherwise%20module%20versioning%2Fdependency%20information%20may%20be%20missing.%3C%2FLI%3E%0A%3CLI%3Emake%20oldconfig%20%26amp%3B%26amp%3B%20make%20prepare%26nbsp%3B%2F%26nbsp%3Bmake%20modules_prepare%26nbsp%3Bis%20the%20usual%20step%20to%20prepare%20the%20tree%20for%20external%20module%20builds.%3C%2FLI%3E%0A%3CLI%3ENative%20builds%20on%20the%20board%20are%20usually%20slower%3B%20NXP%20guidance%20generally%20recommends%20host-side%20cross-compilation%20for%20i.MX%20external%20modules.%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3CP%3ESo%20the%20short%20answer%20is%3A%26nbsp%3B%3CSTRONG%3EFlexbuild%20can%20build%20the%20matching%20kernel%2C%20but%20for%20i.MX8MP%20Debian%20I%20would%20build%20the%20module%20on%20the%20host%20against%20the%20Flexbuild%20kernel%20tree%2C%20not%20try%20to%20install%20distro-style%26nbsp%3Blinux-headers%26nbsp%3Bon%20the%20board.%3C%2FSTRONG%3E%26nbsp%3BIf%20you%20need%20on-target%20iteration%2C%20copy%20the%20matching%20prepared%20kernel%20tree%20to%26nbsp%3B%2Fusr%2Fsrc%2Flinux-headers-%24(uname%20-r)%26nbsp%3Band%20point%26nbsp%3B%2Flib%2Fmodules%2F%24(uname%20-r)%2Fbuild%26nbsp%3Bat%20it.%3C%2FP%3E%0A%3CP%3EUse%20the%20Flexbuild-compiled%20kernel%20tree%20as%20your%20%E2%80%9Cheaders%E2%80%9D%20source%3B%20a%20packaged%2C%20apt-installable%26nbsp%3Blinux-headers-%24(uname%20-r)%26nbsp%3Bflow%20is%20not%20documented%20for%20i.MX8MP%20Flexbuild%20Debian%20in%20the%20material%20retrieved.%3C%2FP%3E%0A%3CBR%20%2F%3E%3C%2FLINGO-BODY%3E