Linux Kernel Building in Native

Hello All,

What are the steps to build the Linux Kernel in Native mode, i.e. Xavier Nx board itself.


This assumes 6 cores (thus “-j 6”). Also assumes “${HOME}” is where your output will go, and that the source itself is located at “/usr/src/sources/kernel/kernel-4.9” (adjust for your situation). Something like this:

# --- Setting Up: -------------------------------------------------------
# DO NOT BUILD AS ROOT/SUDO!!! You might need to install source code as root/sudo.
mkdir -p "${HOME}/build/kernel"
mkdir -p "${HOME}/build/modules"
mkdir -p "${HOME}/build/firmware"

export TOP="/usr/src/sources/kernel/kernel-4.9"
export TEGRA_KERNEL_OUT="${HOME}/build/kernel"
export TEGRA_MODULES_OUT="${HOME}/build/modules"
export TEGRA_FIRMWARE_OUT="${HOME}/build/firmware"
export TEGRA_BUILD="${HOME}/build"

# --- Notes: ------------------------------------------------------------
# It is assumed kernel source is at "/usr/src/sources/kernel/kernel-4.9".
# Check if you have 6 CPU cores, e.g., via "htop".
# If you are missing cores, then experiment with "sudo nvpmodel -m 0, -m 1, and -m 2".
# Perhaps use "htop" to see core counts.
# Using "-j 6" in hints below because of assumption of 6 cores.
# -----------------------------------------------------------------------

# Compile commands start in $TOP, thus:
cd $TOP

# Do not forget to provide a starting configuration. Probably copy of "/proc/config.gz",
# to $TEGRA_KERNEL_OUT, but also perhaps via:
make O=$TEGRA_KERNEL_OUT nconfig

# If building the kernel Image:
make -j 6 O=$TEGRA_KERNEL_OUT Image

# If you did not build Image, but are building modules:
make -j 6 O=$TEGRA_KERNEL_OUT modules_prepare

# To build modules:
make -j 6 O=$TEGRA_KERNEL_OUT modules

# To build device tree content:
make -j 6 O=$TEGRA_KERNEL_OUT dtbs

# To put modules in "$TEGRA_MODULES_OUT":

# To put firmware and device trees in "$TEGRA_FIRMWARE_OUT":

Note that:

  • Most people won’t build firmware.
  • There are a number of ways to configure prior to build, so adjust for your case.
  • The modules_prepare target is only needed if you don’t build the Image first.
  • If your configuration has the same CONFIG_LOCALVERSION, and thus the same “uname -r”, then you might not need to build modules. Or perhaps you would build just a single module for whatever you’ve added.
  • I consider building the Image target at least once even if you are not installing a new base kernel. Think of it as an “acid test” for configuration.
  • Consider never “replacing” your current kernel with a new kernel unless you’ve first tested with an alternate entry in “/boot/extlinux/extlinux.conf” which you’ve picked via serial console at boot time.
1 Like

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.