kernel headers are outdated in jetson tx2

on my custom built kernel , im not able to load my driver

insmod mydriver.ko
error : coud not load : invalid exe format

that means the kernel headers (source code) is old one & present booted kernel is different.

i followed this link for building kernel
https://developer.ridgerun.com/wiki/index.php?title=Compiling_Jetson_TX1/TX2_source_code#Build_Kernel

one thing i observed is :- in kernel build steps, we are copying same kernel header to newly built image which is wrong because of which exe format error we are getting.

please tell me how to create proper kernel headers for which kernel source the image is built

If you are building on another architecture, e.g., if you are building arm64/aarch64/ARMv8-a from a desktop PC (amd64/x86_64), then you have to cross compile. Native compiling builds for the wrong architecture and won’t work on the Jetson. The documents which come with the particular L4T release (see “head -n 1 /etc/nv_tegra_release”, then log in at https://developer.nvidia.com/linux-tegra and click the link a second time since redirect doesn’t work) will show the cross compile steps in the kernel customization section.

If you would rather compile natively on the Jetson, then see this:
https://devtalk.nvidia.com/default/topic/1051980/jetson-tx2/how-to-upgrade-linux-headers-4-4-38-tegra-to-latest-kernel-and-headers/post/5339991/#5339991

Beware though that you have to adjust for your L4T release version…the URL is probably using a different version than what you are using, e.g., you might use “./source_sync.sh -k tegra-l4t-r32.2.0” if you are at R32.2.0. “source_sync.sh” is used for downloading not only the source which is within the kernel tree, but also some source related to the board support package which is “out of tree”. The “source_sync.sh” script creates a “sources/” subdirectory, and within that the actual kernel source is the “sources/kernel/kernel-4.9/” (or kernel-4.4 in older releases) content.

NOTE: source_sync.sh downloads the valid source regardless of whether you are on a host PC cross compiling or doing native compile from the TX2.