How to rebuild kernel for Jetson Linux 35.2.1

I have a Jetson AGX ORIN developer kit and I want to rebuild the kernel and root file system. I followed the “Kernel Customization” section in the DeveloperGuide and proceeded to the next step, which is building the kernel using the following command:

$ ./nvbuild.sh -o $PWD/kernel_out

However, searching through all of the source code. I did find a file named nvbuild.sh in Linux_for_Tegra/sources/tegra/optee-src/atf/ but when I tried to execute the command, it didn’t work.

Is there a more detailed tutorial on how to rebuild the kernel?

Hi,

You could try with the detailed steps here: NVIDIA Jetson Orin - Compiling Code - RidgeRun Developer Connection

Additionally a more “manual” approach could be as follows (just make sure to change the paths according to your system):

SOURCES=`pwd`/kernel_src
TOOLCHAIN_PREFIX=/opt/l4t-gcc/aarch64--glibc--stable-2020.08-1/bin/aarch64-buildroot-linux-gnu-
TEGRA_KERNEL_OUT=`pwd`/kernel_build/jetson_linux_35.2.1_image
KERNEL_MODULES_OUT=`pwd`/kernel_build/jetson_linux_35.2.1_modules

mkdir -p $TEGRA_KERNEL_OUT
mkdir -p $KERNEL_MODULES_OUT

make -C $SOURCES/kernel/kernel-5.10/ ARCH=arm64 O=$TEGRA_KERNEL_OUT LOCALVERSION=-tegra CROSS_COMPILE=${TOOLCHAIN_PREFIX} tegra_defconfig
make -C $SOURCES/kernel/kernel-5.10/ ARCH=arm64 O=$TEGRA_KERNEL_OUT LOCALVERSION=-tegra CROSS_COMPILE=${TOOLCHAIN_PREFIX} -j$(nproc) Image
make -C $SOURCES/kernel/kernel-5.10/ ARCH=arm64 O=$TEGRA_KERNEL_OUT LOCALVERSION=-tegra CROSS_COMPILE=${TOOLCHAIN_PREFIX} -j$(nproc) dtbs
make -C $SOURCES/kernel/kernel-5.10/ ARCH=arm64 O=$TEGRA_KERNEL_OUT LOCALVERSION=-tegra CROSS_COMPILE=${TOOLCHAIN_PREFIX} -j$(nproc) modules
make -C $SOURCES/kernel/kernel-5.10/ ARCH=arm64 O=$TEGRA_KERNEL_OUT LOCALVERSION=-tegra INSTALL_MOD_PATH=$KERNEL_MODULES_OUT modules_install

cp -rfv ${TEGRA_KERNEL_OUT}/arch/arm64/boot/Image kernel/
cp -rfv ${TEGRA_KERNEL_OUT}/arch/arm64/boot/dts/nvidia/* kernel/dtb/
sudo rsync -azPu ${KERNEL_MODULES_OUT}/lib/modules/5.10.104-tegra rootfs/lib/modules/
sudo ./apply_binaries.sh

Jafet Chaves,
Embedded SW Engineer at RidgeRun
Contact us: support@ridgerun.com
Developers wiki: https://developer.ridgerun.com/
Website: www.ridgerun.com

2 Likes

The official documents for kernel customization are included with the particular L4T release (in your case R35.2.1). You can go here to reach that:
https://developer.nvidia.com/linux-tegra

The URL above would also be able to reach the correct kernel source download.

These are more for native compile, not cross compile, but still apply if you are manually configuring and building a kernel (you’d have to adjust to use a cross compiler and such if working on a PC):

In terms of “rebuild the…root filesystem”, what are you actually changing? On the host PC most of the rootfs is generated verbatim from the host PC’s “Linux_for_Tegra/rootfs/” content. The kernel, device tree, and extlinux.conf are updated into that location first, and then a partition image is generated. The particular kernel/device tree/extlinux.conf depends on the chosen target board. If you were to flash on command line, then you would use a command something like this for a dev kit:
sudo ./flash.sh jetson-agx-orin-devkit mmcblk0p1

The target always corresponds to a “.conf” file. For example, “jetson-agx-orin-devkit” is provided by “jetson-agx-orin-devkit.conf”. This is human-readable, and might include other human-readable files. Usually it is a symbolic link (alias) pointing at the same file which is named after the part number of the module and carrier board. You can copy those files to a new name, and edit to have your own custom flash target if you wish. From there you can find out what kernel and other content is copied into “rootfs/” before the image is generated. An example to flash on command line which also saves a log of the flash is this:
sudo ./flash.sh jetson-agx-orin-devkit mmcblk0p1 2>&1 | tee log_flash.txt

If you flash and save a log, then you can go over that log to see which files are copied from where prior to the rootfs being generated.

Of course, I have been assuming that you want to know how to create a rootfs image based on some modification of “rootfs/”, and not generating an entirely new rootfs. If you want something like the latter, then you will probably need to state your use-case (there won’t be many people who have used alternate rootfs other than minor changes, but some have made more extensive changes and could possibly help).

1 Like

Is there a more detailed tutorial on how to rebuild the all of images (bootloader, kernel) on PC side?

Most of the rootfs is purely Ubuntu. You’d have to find Ubuntu instructions to build those parts from source. So far as the rest goes, including the parts of boot which are available as source, each will have its own documentation. Kernel and boot content are “bare metal”, and so they are easier procedure-wise, but perhaps require specific tools. All I can suggest is to look up the documentation for the specific release. Kernel cross compile is described well. You’ll probably end up having to make a separate topic for different parts, e.g., one thread for UEFI build, another one for building NVIDIA-provided software (e.g., multimedia, although the sample applications are in general the way to do this and they do get cross compiled on the host PC).

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