Jetson Nano/Development/Building the Kernel from Source: Difference between revisions

From RidgeRun Developer Wiki
No edit summary
 
(4 intermediate revisions by the same user not shown)
Line 1: Line 1:
<noinclude>
<noinclude>
{{JetsonNano/Head|previous=Development/Getting_into_the_Board|next=GStreamer/Accelerated_Elements|keywords=jetson nano kernel, DTB, build, compile, flashing, clone,clonning the image,compiling the kernel,downloading the kernel source,downloading the kernel,kernel source,source code|title=How to build NVIDIA Jetson Nano kernel|description=This page provides the steps to compile,build and flashing the kernel,DTBs and to clone a sdcard image}}
{{JetsonNano/Head|previous=Development/Getting_into_the_Board|next=GStreamer/Accelerated_Elements|metakeywords=jetson nano kernel, DTB, build, compile, flashing, clone, cloning the image, compiling the kernel, downloading the kernel source, downloading the kernel, kernel source, source code|title=How to build NVIDIA Jetson Nano kernel|metadescription=This page provides the steps to compile, build and flashing the kernel, DTBs and to clone a sdcard image}}
</noinclude>
</noinclude>


Line 15: Line 15:
Previous versions:
Previous versions:


* [https://developer.ridgerun.com/wiki/index.php?title=Compiling_Jetson_Nano_source_code_L4T_32.2.1 Compiling Jetson Nano source code L4T 32.2.1]
* [[Compiling_Jetson_Nano_source_code_L4T_32.2.1 | Compiling Jetson Nano source code L4T 32.2.1]]
* [https://developer.ridgerun.com/wiki/index.php?title=Compiling_Jetson_Nano_source_code_L4T_32.1 Compiling Jetson Nano source code L4T 32.1]
* [[Compiling_Jetson_Nano_source_code_L4T_32.1 | Compiling Jetson Nano source code L4T 32.1]]


==Build Kernel==
==Build Kernel==
Line 27: Line 27:
Download the pre-built toolchain binaries from: http://releases.linaro.org/components/toolchain/binaries/7.3-2018.05/aarch64-linux-gnu/gcc-linaro-7.3.1-2018.05-x86_64_aarch64-linux-gnu.tar.xz
Download the pre-built toolchain binaries from: http://releases.linaro.org/components/toolchain/binaries/7.3-2018.05/aarch64-linux-gnu/gcc-linaro-7.3.1-2018.05-x86_64_aarch64-linux-gnu.tar.xz


<source lang="bash">
<syntaxhighlight lang="bash">
wget http://releases.linaro.org/components/toolchain/binaries/7.3-2018.05/aarch64-linux-gnu/gcc-linaro-7.3.1-2018.05-x86_64_aarch64-linux-gnu.tar.xz
wget http://releases.linaro.org/components/toolchain/binaries/7.3-2018.05/aarch64-linux-gnu/gcc-linaro-7.3.1-2018.05-x86_64_aarch64-linux-gnu.tar.xz
</source>
</syntaxhighlight>


Execute the following commands to extract the toolchain:
Execute the following commands to extract the toolchain:
<source lang="bash">
<syntaxhighlight lang="bash">
mkdir $HOME/l4t-gcc
mkdir $HOME/l4t-gcc
cd $HOME/l4t-gcc
cd $HOME/l4t-gcc
tar xf gcc-linaro-7.3.1-2018.05-x86_64_aarch64-linux-gnu.tar.xz
tar xf gcc-linaro-7.3.1-2018.05-x86_64_aarch64-linux-gnu.tar.xz
</source>
</syntaxhighlight>


===2. Download the kernel sources===
===2. Download the kernel sources===
Line 43: Line 43:
In a browser, navigate to: https://developer.nvidia.com/embedded/downloads. Locate and download the L4T Sources for your release. (L4T Sources 32.3.1 2019/12/17) or run the command below:
In a browser, navigate to: https://developer.nvidia.com/embedded/downloads. Locate and download the L4T Sources for your release. (L4T Sources 32.3.1 2019/12/17) or run the command below:


<source lang="bash">
<syntaxhighlight lang="bash">
wget https://developer.download.nvidia.com/embedded/L4T/r32-3-1_Release_v1.0/Sources/T210/public_sources.tbz2
wget https://developer.download.nvidia.com/embedded/L4T/r32-3-1_Release_v1.0/Sources/T210/public_sources.tbz2
</source>
</syntaxhighlight>
Execute the following commands to extract the kernel:
Execute the following commands to extract the kernel:
<source lang="bash">
<syntaxhighlight lang="bash">
tar -xvf public_sources.tbz2
tar -xvf public_sources.tbz2
cd Linux_for_Tegra/source/public
cd Linux_for_Tegra/source/public
JETSON_NANO_KERNEL_SOURCE=$(pwd)
JETSON_NANO_KERNEL_SOURCE=$(pwd)
tar -xf kernel_src.tbz2
tar -xf kernel_src.tbz2
</source>
</syntaxhighlight>


===3. Compile kernel and dtb===
===3. Compile kernel and dtb===
Follow the steps:
Follow the steps:


<source lang="bash">
<syntaxhighlight lang="bash">
cd $JETSON_NANO_KERNEL_SOURCE
cd $JETSON_NANO_KERNEL_SOURCE
TOOLCHAIN_PREFIX=$HOME/l4t-gcc/gcc-linaro-7.3.1-2018.05-x86_64_aarch64-linux-gnu/bin/aarch64-linux-gnu-
TOOLCHAIN_PREFIX=$HOME/l4t-gcc/gcc-linaro-7.3.1-2018.05-x86_64_aarch64-linux-gnu/bin/aarch64-linux-gnu-
Line 67: Line 67:
make -C kernel/kernel-4.9/ ARCH=arm64 O=$TEGRA_KERNEL_OUT LOCALVERSION=-tegra CROSS_COMPILE=${TOOLCHAIN_PREFIX} -j8 --output-sync=target dtbs
make -C kernel/kernel-4.9/ ARCH=arm64 O=$TEGRA_KERNEL_OUT LOCALVERSION=-tegra CROSS_COMPILE=${TOOLCHAIN_PREFIX} -j8 --output-sync=target dtbs
make -C kernel/kernel-4.9/ ARCH=arm64 O=$TEGRA_KERNEL_OUT LOCALVERSION=-tegra INSTALL_MOD_PATH=$KERNEL_MODULES_OUT modules_install
make -C kernel/kernel-4.9/ ARCH=arm64 O=$TEGRA_KERNEL_OUT LOCALVERSION=-tegra INSTALL_MOD_PATH=$KERNEL_MODULES_OUT modules_install
</source>
</syntaxhighlight>


==Flash Jetson NANO==
==Flash Jetson NANO==
This guide assumes that the user already has sdk-manager installed. This link contains details about how to install sdk-manager: https://developer.nvidia.com/nvidia-sdk-manager https://docs.nvidia.com/sdk-manager/download-run-sdkm/index.html
This guide assumes that the user already has sdk-manager installed. This link contains details about how to install sdk-manager: https://developer.nvidia.com/nvidia-sdk-manager https://docs.nvidia.com/sdk-manager/download-run-sdkm/index.html


NVIDIA_SDK_MANAGER contains the directory where Nvidia SDK manager was installed. For example.
NVIDIA_SDK_MANAGER contains the directory where NVIDIA SDK manager was installed. For example.
<source lang="bash">
<syntaxhighlight lang="bash">
export NVIDIA_SDK_MANAGER=$HOME/nvidia/nvidia_sdk/
export NVIDIA_SDK_MANAGER=$HOME/nvidia/nvidia_sdk/
</source>
</syntaxhighlight>
===Select DTB and directory based on Jetson Nano module type===
===Select DTB and directory based on Jetson Nano module type===


====Production module (P3448-0020)====
====Production module (P3448-0020)====
<source lang="bash">
<syntaxhighlight lang="bash">
export DTB=tegra210-p3448-0002-p3449-0000-b00.dtb
export DTB=tegra210-p3448-0002-p3449-0000-b00.dtb
JETPACK_4_3_P3448=${NVIDIA_SDK_MANAGER}/JetPack_4.3_Linux_P3448-0020/Linux_for_Tegra
JETPACK_4_3_P3448=${NVIDIA_SDK_MANAGER}/JetPack_4.3_Linux_P3448-0020/Linux_for_Tegra
</source>
</syntaxhighlight>


====Devkit module (P3448)====
====Devkit module (P3448)====
<source lang="bash">
<syntaxhighlight lang="bash">
export DTB=tegra210-p3448-0000-p3449-0000-a02.dtb
export DTB=tegra210-p3448-0000-p3449-0000-a02.dtb
JETPACK_4_3_P3448=${NVIDIA_SDK_MANAGER}/JetPack_4.3_Linux_P3448/Linux_for_Tegra
JETPACK_4_3_P3448=${NVIDIA_SDK_MANAGER}/JetPack_4.3_Linux_P3448/Linux_for_Tegra
</source>
</syntaxhighlight>
Make sure the Jetson Nano is in recovery mode
Make sure the Jetson Nano is in recovery mode


===Copy kernel, device tree and modules into jetpack===
===Copy kernel, device tree and modules into jetpack===


 
<syntaxhighlight lang="bash">
<source lang="bash">
cd ${JETPACK_4_3_P3448}
cd ${JETPACK_4_3_P3448}
# Copy kernel generated
# Copy kernel generated
Line 100: Line 99:
# Copy device tree generated
# Copy device tree generated
cp $JETSON_NANO_KERNEL_SOURCE/build/arch/arm64/boot/dts/${DTB} kernel/dtb/
cp $JETSON_NANO_KERNEL_SOURCE/build/arch/arm64/boot/dts/${DTB} kernel/dtb/
</source>
</syntaxhighlight>


===Apply root filesystem patch===
===Apply root filesystem patch===


With the default root file system the changes in the device tree are lost when the board is power off. This is a known issue (https://devtalk.nvidia.com/default/topic/1072091/jetson-nano/how-to-modify-the-dts-file-for-jetson-nano-board/)
With the default root file system, the changes in the device tree are lost when the board is powered off. This is a known issue (https://devtalk.nvidia.com/default/topic/1072091/jetson-nano/how-to-modify-the-dts-file-for-jetson-nano-board/)
Apply this patch to avoid losing the changes added in the device tree.
Apply this patch to avoid losing the changes added to the device tree.


====Create patch file====
====Create patch file====


Patch: fix_dtb_lost.patch
Patch: fix_dtb_lost.patch
<source lang="diff">
<syntaxhighlight lang="diff">
diff --git a/rootfs/opt/nvidia/l4t-bootloader-config/nv-l4t-bootloader-config.sh b/rootfs/opt/nvidia/l4t-bootloader-config/nv-l4t-bootloader-config.sh
diff --git a/rootfs/opt/nvidia/l4t-bootloader-config/nv-l4t-bootloader-config.sh b/rootfs/opt/nvidia/l4t-bootloader-config/nv-l4t-bootloader-config.sh
index 921efc2..fe60093 100755
index 921efc2..fe60093 100755
Line 124: Line 123:
                                 # sys_maj_rev == qspi_maj_rev
                                 # sys_maj_rev == qspi_maj_rev
                                 # sys_min_rev >= qspi_min_rev
                                 # sys_min_rev >= qspi_min_rev
</source>
</syntaxhighlight>


====Apply the patch====
====Apply the patch====


<source lang="bash">
<syntaxhighlight lang="bash">
cd ${JETPACK_4_3_P3448}
cd ${JETPACK_4_3_P3448}
sudo patch -p 1 < fix_dtb_lost.patch
sudo patch -p 1 < fix_dtb_lost.patch
</source>
</syntaxhighlight>


===Flash memory===
===Flash memory===
Line 137: Line 136:


====Flash production module====
====Flash production module====
<source lang="bash">
<syntaxhighlight lang="bash">
sudo ./flash.sh jetson-nano-emmc mmcblk0p1
sudo ./flash.sh jetson-nano-emmc mmcblk0p1
</source>
</syntaxhighlight>


====Flash Devkit module====
====Flash Devkit module====
<source lang="bash">
<syntaxhighlight lang="bash">
sudo ./flash.sh jetson-nano-qspi-sd mmcblk0p1
sudo ./flash.sh jetson-nano-qspi-sd mmcblk0p1
</source>
</syntaxhighlight>


====Flash device tree only====
====Flash device tree only====
This command flashes only the device tree, excluding the kernel image and filesystem. Make sure the Jetson NANO is in recovery mode.
This command flashes only the device tree, excluding the kernel image and filesystem. Make sure the Jetson NANO is in recovery mode.


<source lang="bash">
<syntaxhighlight lang="bash">
cd ${JETPACK_4_3_P3448}
cd ${JETPACK_4_3_P3448}
# Copy device tree generated
# Copy device tree generated
cp $JETSON_NANO_KERNEL_SOURCE/build/arch/arm64/boot/dts/${DTB} kernel/dtb/
cp $JETSON_NANO_KERNEL_SOURCE/build/arch/arm64/boot/dts/${DTB} kernel/dtb/
</source>
</syntaxhighlight>


=====Flash production module DTB=====
=====Flash production module DTB=====
<source lang="bash">
<syntaxhighlight lang="bash">
sudo ./flash.sh -r -k DTB jetson-nano-emmc mmcblk0p1
sudo ./flash.sh -r -k DTB jetson-nano-emmc mmcblk0p1
</source>
</syntaxhighlight>


=====Flash Devkit module DTB=====
=====Flash Devkit module DTB=====
<source lang="bash">
<syntaxhighlight lang="bash">
sudo ./flash.sh -r -k DTB jetson-nano-qspi-sd mmcblk0p1
sudo ./flash.sh -r -k DTB jetson-nano-qspi-sd mmcblk0p1
</source>
</syntaxhighlight>


<noinclude>
<noinclude>

Latest revision as of 12:30, 8 May 2024



Previous: Development/Getting_into_the_Board Index Next: GStreamer/Accelerated_Elements





Introduction

This wiki page contains instructions to download and build kernel source code for Jetson Nano, several parts of this wiki were based in the document: NVIDIA Tegra Linux Driver Package Development Guide 32.3.1.

L4T 32.3.1 is used by JetPack 4.3 (You can get more information from jetpack-archive).

Previous versions:

Build Kernel

Follow these instructions to build and install the kernel image and device tree.

1. Download and install the Toolchain

NVIDIA recommends using the Linaro 7.3.1 2018.05 toolchain for L4T 32.3 (Toolchain)

Download the pre-built toolchain binaries from: http://releases.linaro.org/components/toolchain/binaries/7.3-2018.05/aarch64-linux-gnu/gcc-linaro-7.3.1-2018.05-x86_64_aarch64-linux-gnu.tar.xz

wget http://releases.linaro.org/components/toolchain/binaries/7.3-2018.05/aarch64-linux-gnu/gcc-linaro-7.3.1-2018.05-x86_64_aarch64-linux-gnu.tar.xz

Execute the following commands to extract the toolchain:

mkdir $HOME/l4t-gcc
cd $HOME/l4t-gcc
tar xf gcc-linaro-7.3.1-2018.05-x86_64_aarch64-linux-gnu.tar.xz

2. Download the kernel sources

You can download the kernel source files and then manually extract them. it is recommended to instead sync with git.

In a browser, navigate to: https://developer.nvidia.com/embedded/downloads. Locate and download the L4T Sources for your release. (L4T Sources 32.3.1 2019/12/17) or run the command below:

wget https://developer.download.nvidia.com/embedded/L4T/r32-3-1_Release_v1.0/Sources/T210/public_sources.tbz2

Execute the following commands to extract the kernel:

tar -xvf public_sources.tbz2
cd Linux_for_Tegra/source/public
JETSON_NANO_KERNEL_SOURCE=$(pwd)
tar -xf kernel_src.tbz2

3. Compile kernel and dtb

Follow the steps:

cd $JETSON_NANO_KERNEL_SOURCE
TOOLCHAIN_PREFIX=$HOME/l4t-gcc/gcc-linaro-7.3.1-2018.05-x86_64_aarch64-linux-gnu/bin/aarch64-linux-gnu-
TEGRA_KERNEL_OUT=$JETSON_NANO_KERNEL_SOURCE/build
KERNEL_MODULES_OUT=$JETSON_NANO_KERNEL_SOURCE/modules
make -C kernel/kernel-4.9/ ARCH=arm64 O=$TEGRA_KERNEL_OUT LOCALVERSION=-tegra CROSS_COMPILE=${TOOLCHAIN_PREFIX} tegra_defconfig
make -C kernel/kernel-4.9/ ARCH=arm64 O=$TEGRA_KERNEL_OUT LOCALVERSION=-tegra CROSS_COMPILE=${TOOLCHAIN_PREFIX} -j8 --output-sync=target zImage
make -C kernel/kernel-4.9/ ARCH=arm64 O=$TEGRA_KERNEL_OUT LOCALVERSION=-tegra CROSS_COMPILE=${TOOLCHAIN_PREFIX} -j8 --output-sync=target modules
make -C kernel/kernel-4.9/ ARCH=arm64 O=$TEGRA_KERNEL_OUT LOCALVERSION=-tegra CROSS_COMPILE=${TOOLCHAIN_PREFIX} -j8 --output-sync=target dtbs
make -C kernel/kernel-4.9/ ARCH=arm64 O=$TEGRA_KERNEL_OUT LOCALVERSION=-tegra INSTALL_MOD_PATH=$KERNEL_MODULES_OUT modules_install

Flash Jetson NANO

This guide assumes that the user already has sdk-manager installed. This link contains details about how to install sdk-manager: https://developer.nvidia.com/nvidia-sdk-manager https://docs.nvidia.com/sdk-manager/download-run-sdkm/index.html

NVIDIA_SDK_MANAGER contains the directory where NVIDIA SDK manager was installed. For example.

export NVIDIA_SDK_MANAGER=$HOME/nvidia/nvidia_sdk/

Select DTB and directory based on Jetson Nano module type

Production module (P3448-0020)

export DTB=tegra210-p3448-0002-p3449-0000-b00.dtb
JETPACK_4_3_P3448=${NVIDIA_SDK_MANAGER}/JetPack_4.3_Linux_P3448-0020/Linux_for_Tegra

Devkit module (P3448)

export DTB=tegra210-p3448-0000-p3449-0000-a02.dtb
JETPACK_4_3_P3448=${NVIDIA_SDK_MANAGER}/JetPack_4.3_Linux_P3448/Linux_for_Tegra

Make sure the Jetson Nano is in recovery mode

Copy kernel, device tree and modules into jetpack

cd ${JETPACK_4_3_P3448}
# Copy kernel generated
cp $JETSON_NANO_KERNEL_SOURCE/build/arch/arm64/boot/Image kernel/
# Copy device tree generated
cp $JETSON_NANO_KERNEL_SOURCE/build/arch/arm64/boot/dts/${DTB} kernel/dtb/

Apply root filesystem patch

With the default root file system, the changes in the device tree are lost when the board is powered off. This is a known issue (https://devtalk.nvidia.com/default/topic/1072091/jetson-nano/how-to-modify-the-dts-file-for-jetson-nano-board/) Apply this patch to avoid losing the changes added to the device tree.

Create patch file

Patch: fix_dtb_lost.patch

diff --git a/rootfs/opt/nvidia/l4t-bootloader-config/nv-l4t-bootloader-config.sh b/rootfs/opt/nvidia/l4t-bootloader-config/nv-l4t-bootloader-config.sh
index 921efc2..fe60093 100755
--- a/rootfs/opt/nvidia/l4t-bootloader-config/nv-l4t-bootloader-config.sh
+++ b/rootfs/opt/nvidia/l4t-bootloader-config/nv-l4t-bootloader-config.sh
@@ -123,7 +123,7 @@ t210ref_update_qspi_check () {
                        # need to update QSPI
                        return 0
                elif (( "${sys_maj_rev}" == "${qspi_maj_rev}" )); then
-                       if (( "${sys_min_rev}" >= "${qspi_min_rev}" )); then
+                       if (( "${sys_min_rev}" > "${qspi_min_rev}" )); then
                                # sys_rel == qspi_rel
                                # sys_maj_rev == qspi_maj_rev
                                # sys_min_rev >= qspi_min_rev

Apply the patch

cd ${JETPACK_4_3_P3448}
sudo patch -p 1 < fix_dtb_lost.patch

Flash memory

Make sure the Jetson NANO is in recovery mode.

Flash production module

sudo ./flash.sh jetson-nano-emmc mmcblk0p1

Flash Devkit module

sudo ./flash.sh jetson-nano-qspi-sd mmcblk0p1

Flash device tree only

This command flashes only the device tree, excluding the kernel image and filesystem. Make sure the Jetson NANO is in recovery mode.

cd ${JETPACK_4_3_P3448}
# Copy device tree generated
cp $JETSON_NANO_KERNEL_SOURCE/build/arch/arm64/boot/dts/${DTB} kernel/dtb/
Flash production module DTB
sudo ./flash.sh -r -k DTB jetson-nano-emmc mmcblk0p1
Flash Devkit module DTB
sudo ./flash.sh -r -k DTB jetson-nano-qspi-sd mmcblk0p1


Previous: Development/Getting_into_the_Board Index Next: GStreamer/Accelerated_Elements