How do I build a kernel on my Jetson Nano?

I’m trying to follow these instructions.

How to build NVIDIA Jetson Nano kernel
https://developer.ridgerun.com/wiki/index.php?title=Jetson_Nano/Development/Building_the_Kernel_from_Source

But, unfortunately it wants me to download x86-64 compiler binaries. The Jetson Nano is not an x86-64 system. I can’t seem to find the right binaries anywhere.

Following the instructions with a few changes I got all the way to the step where I run:

Then I see these errors:

Assuming you are cross compiling on the host PC:

You do want x86_64 binaries…with arm64/aarch64/ARMv8-a output. Exec format error means the program is designed to run on a different architecture, but your host PC won’t run aarch64 programs. The code which is produced by the compiler is normally the same as the architecture the compiler runs on (a native compiler), but as soon as you talk about cross compile (a cross compiler), then you have to specify an x86_64 package with aarch64 output.

Assuming you are natively compiling directly on the Jetson:

You wouldn’t need to specify “ARCH=…” if you are building kernels directly on the Jetson (nor would you specify “CROSS_COMPILE=…”). Native compile skips that.

Here is the official documentation from Nvidia on the toolchain. I wasn’t able to find aarch64 binaries for that exact version, but you could build the compiler from source:

https://releases.linaro.org/components/toolchain/gcc-linaro/7.3-2018.05/

It will probably take quite a while to do that on a Nano. You could use the default gcc that’s included and see how it goes (as linuxdev says, just omit the cross compiling bits), though cross compiling with the recommended toolchain is going to be a lot faster and is what Nvidia tests.

Although “ARCH=…” is not necessary, it doesn’t hurt. It is necessary, though, to remove “CROSS_COMPILE=…” to get it to use the local native compiler to build the kernel.

My hope was to use a different compiler than the native compiler so I could use a different version of the compiler than whatever happens to be installed on the system. But this works, so thanks.

Note that CROSS_COMPILE is only used if the architecture output is non-native. You can use a different C compiler, but that’d be “CC=/where/ever/it/is/gcc” (or similar…not sure how many other compilers work on the Linux kernel…“CC” implies a way to name the path to the native compiler).