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

From RidgeRun Developer Wiki
mNo edit summary
Line 7: Line 7:
-->
-->


= Compiling the kernel sources =
== Compiling the kernel sources ==
==Dependencies==
===Dependencies===
The first step is to install some important dependencies, make sure you have installed this before compile the kernel sources.  
The first step is to install some important dependencies, make sure you have installed this before compile the kernel sources.  
<pre>
<pre>
Line 14: Line 14:
</pre>
</pre>


== Environment variables ==
=== Environment variables ===
These environment variables are used to compile the kernel and belong to the L4T 32.1 release.  
These environment variables are used to compile the kernel and belong to the L4T 32.1 release.  
<syntaxhighlight lang="bash" style="background-color:cornsilk">
<syntaxhighlight lang="bash" style="background-color:cornsilk">
Line 25: Line 25:
</syntaxhighlight>
</syntaxhighlight>


== Toolchain ==
=== Toolchain ===
In order to compile the kernel sources you need to install the toolchain just running the next commands:  
In order to compile the kernel sources you need to install the toolchain just running the next commands:  
<syntaxhighlight lang="bash" style="background-color:cornsilk">
<syntaxhighlight lang="bash" style="background-color:cornsilk">
Line 39: Line 39:
</syntaxhighlight>
</syntaxhighlight>


== Downloading Kernel sources ==
=== Downloading Kernel sources ===


=== Not stable ===
==== Not stable ====


This is not stable because the source_sync.sh script, usually has to fetch inner repositories, but many times this doesn't happen as expected and several issues can be found.
This is not stable because the source_sync.sh script, usually has to fetch inner repositories, but many times this doesn't happen as expected and several issues can be found.
Line 55: Line 55:
</syntaxhighlight>
</syntaxhighlight>


=== Stable ===
==== Stable ====


With this method, you are downloading all the source at once, and you don't have to fetch inner repositories since they are downloaded at the same time.
With this method, you are downloading all the source at once, and you don't have to fetch inner repositories since they are downloaded at the same time.
Line 67: Line 67:
</syntaxhighlight>
</syntaxhighlight>


== Compiling the Kernel sources ==
=== Compiling the Kernel sources ===
Once you have downloaded the kernel sources and you have installed the toolchain you will be able to start compiling the kernel sources.  
Once you have downloaded the kernel sources and you have installed the toolchain you will be able to start compiling the kernel sources.  
<syntaxhighlight lang="bash" style="background-color:cornsilk">
<syntaxhighlight lang="bash" style="background-color:cornsilk">
Line 86: Line 86:
</syntaxhighlight>
</syntaxhighlight>


= Flashing Jetson Nano completely including FS =
== Flashing Jetson Nano completely including FS ==
With the next command you will be able to flash the kernel image, dtb and also file system.  
With the next command you will be able to flash the kernel image, dtb and also file system.  
<syntaxhighlight lang="bash" style="background-color:cornsilk">
<syntaxhighlight lang="bash" style="background-color:cornsilk">
Line 93: Line 93:
</syntaxhighlight>
</syntaxhighlight>


=Flash custom DTB on the Jetson Nano=
==Flash custom DTB on the Jetson Nano==
With the next command you will be able to flash only the device tree, excluding kernel image and filesystem, just make sure to put the board in recovery mode.
With the next command you will be able to flash only the device tree, excluding kernel image and filesystem, just make sure to put the board in recovery mode.
<syntaxhighlight lang="bash" style="background-color:cornsilk">
<syntaxhighlight lang="bash" style="background-color:cornsilk">
Line 102: Line 102:
</syntaxhighlight>
</syntaxhighlight>


==Flash DTB from the Jetson device itself==
===Flash DTB from the Jetson device itself===


The DTB file needs to be placed into a specific partition and signed as encrypted.
The DTB file needs to be placed into a specific partition and signed as encrypted.
Line 148: Line 148:
</syntaxhighlight>
</syntaxhighlight>


=Flash Custom Kernel Image =
==Flash Custom Kernel Image ==
In order to replace the kernel image you need to copy the '''Image''' file to the Jetson nano to the directory /boot/  
In order to replace the kernel image you need to copy the '''Image''' file to the Jetson nano to the directory /boot/  
send the custom kernel image binary to the Jetson Nano:  
send the custom kernel image binary to the Jetson Nano:  
Line 165: Line 165:
Reboot the system after replacing the Image is important.
Reboot the system after replacing the Image is important.


= SDcard Image Clone =
== SDcard Image Clone ==
In order to clone a SDcard Image with all the partitions required by the Jetson Nano run the following command:  
In order to clone a SDcard Image with all the partitions required by the Jetson Nano run the following command:  
<syntaxhighlight lang="bash" style="background-color:cornsilk">
<syntaxhighlight lang="bash" style="background-color:cornsilk">

Revision as of 19:01, 3 February 2020



Previous: Introduction/Getting_Started Index Next: GStreamer/Accelerated_Elements





Compiling the kernel sources

Dependencies

The first step is to install some important dependencies, make sure you have installed this before compile the kernel sources.

sudo apt install build-essential bc bzip2 xz-utils git-core vim-common

Environment variables

These environment variables are used to compile the kernel and belong to the L4T 32.1 release.

VERSION=32-1-0
TOOLCHAIN_SRC=kernel-gcc-6-4-tool-chain
TOOLCHAIN_DIR=gcc-linaro-6.4.1-2017.08-x86_64_aarch64-linux-gnu
KERNEL_SRC=l4t-sources-32-1-0
KERNEL_DIR=kernel-4.9
CC_PREFIX=aarch64-linux-gnu-

Toolchain

In order to compile the kernel sources you need to install the toolchain just running the next commands:

cd ~
mkdir -p toolchain_bin_$VERSION
cd toolchain_bin_$VERSION

# Reuse existing download, if any
if ! test -e ${TOOLCHAIN_SRC}.tar.gz; then 
wget -O ${TOOLCHAIN_SRC}.tar.gz https://developer.nvidia.com/embedded/dlc/${TOOLCHAIN_SRC}
tar -xf ${TOOLCHAIN_SRC}.tar.gz
fi

Downloading Kernel sources

Not stable

This is not stable because the source_sync.sh script, usually has to fetch inner repositories, but many times this doesn't happen as expected and several issues can be found. In this step you need to have installed JetPack 4.2 for nano boards.

JETPACK=~/JetPack-L4T-4.2
cd ${JETPACK}/JetPack_4.2_Linux_P3448/Linux_for_Tegra/
./source_sync.sh

##
# When prompted, use: tegra-l4t-r32.1 as the tag (change accordingly)
##

Stable

With this method, you are downloading all the source at once, and you don't have to fetch inner repositories since they are downloaded at the same time.

JETSON_NANO_SOURCES=$(pwd)
wget https://developer.download.nvidia.com/embedded/L4T/r32_Release_v1.0/jetson-nano/BSP/Jetson-Nano-public_sources.tbz2
tar -xvf Jetson-Nano-public_sources.tbz2 
cd public_sources/
tar -xvf kernel_src.tbz2

Compiling the Kernel sources

Once you have downloaded the kernel sources and you have installed the toolchain you will be able to start compiling the kernel sources.

JETPACK=~/JetPack-L4T-4.2
CROSS_COMPILE=${HOME}/toolchain_bin_${VERSION}/${TOOLCHAIN_DIR}/bin/$CC_PREFIX
KERNEL_OUT=${JETPACK}/JetPack_4.2_Linux_P3448/Linux_for_Tegra/sources/kernel/${KERNEL_DIR}/build
KERNEL_MODULES_OUT=${JETPACK}/JetPack_4.2_Linux_P3448/Linux_for_Tegra/rootfs

cd ${JETPACK}/JetPack_4.2_Linux_P3448/Linux_for_Tegra/sources/kernel/${KERNEL_DIR}
mkdir -p $KERNEL_OUT

# Create the .config file
make ARCH=arm64 O=$KERNEL_OUT tegra_defconfig
make ARCH=arm64 O=$KERNEL_OUT menuconfig

# Build the kernel and DTBs
make ARCH=arm64 O=$KERNEL_OUT CROSS_COMPILE=${CROSS_COMPILE} -j4

Flashing Jetson Nano completely including FS

With the next command you will be able to flash the kernel image, dtb and also file system.

# flash whole file system
sudo ./flash.sh jetson-nano-qspi-sd mmcblk0p1

Flash custom DTB on the Jetson Nano

With the next command you will be able to flash only the device tree, excluding kernel image and filesystem, just make sure to put the board in recovery mode.

#flash just DTB 
cd ${JETPACK}/JetPack_4.2_Linux_P3448/Linux_for_Tegra/
cp sources/kernel/kernel-4.9/build/arch/arm64/boot/dts/tegra210-p3448-0000-p3449-0000-a02.dtb kernel/dtb/
sudo ./flash.sh -r -k DTB jetson-nano-qspi-sd mmcblk0p1

Flash DTB from the Jetson device itself

The DTB file needs to be placed into a specific partition and signed as encrypted.

  • Generate the encrypted DTB:
cp sources/kernel/kernel-4.9/build/arch/arm64/boot/dts/tegra210-p3448-0000-p3449-0000-a02.dtb kernel/dtb/
sudo ./create-jetson-nano-sd-card-image.sh -o sd-blob.img -s 4G -r 200
# The above command will generate the encrypted dtb on the following path:
# ${JETPACK}/JetPack_4.2_Linux_P3448/Linux_for_Tegra/bootloader/signed/tegra210-p3448-0000-p3449-0000-a02.dtb.encrypt
  • Flash the encrypted DTB to the DTB partition:
# Pull the SD card out of the Nano and put into your Linux machine
sudo dd if=${JETPACK}/JetPack_4.2_Linux_P3448/Linux_for_Tegra/bootloader/signed/tegra210-p3448-0000-p3449-0000-a02.dtb.encrypt of=/dev/<DTB_PARTITION>
# This will program the DTB file into the DTB partition. Use the "ls -al /dev/disk/by-partlabel" command on your Linux host machine to check for the NANO SD card DTB partition.
# Put the SD card back in the Nano and reboot

#Also, you could transfer the tegra210-p3448-0000-p3449-0000-a02.dtb.encrypt file to the nano board and flash it from the Nano board itself.
sudo dd if=tegra210-p3448-0000-p3449-0000-a02.dtb.encrypt of=/dev/<DTB_PARTITION>

#Verify which is your JETSON NANO DTB partition
nvidia@nvidia:~$ ls -al /dev/disk/by-partlabel
total 0
drwxr-xr-x 2 root root 320 jun 21 08:16 .
drwxr-xr-x 8 root root 160 jun 21 08:16 ..
lrwxrwxrwx 1 root root  15 jun 21 08:16 APP -> ../../mmcblk0p1
lrwxrwxrwx 1 root root  16 jun 21 08:16 BMP -> ../../mmcblk0p13
lrwxrwxrwx 1 root root  15 jun 21 08:16 BPF -> ../../mmcblk0p6
lrwxrwxrwx 1 root root  15 jun 21 08:16 BPF-DTB -> ../../mmcblk0p7
lrwxrwxrwx 1 root root  16 jun 21 08:16 DTB -> ../../mmcblk0p10    # This is the DTB PARTITION WERE THE ENCRYPTED DTB FILE SHOULD BE FLASHED
lrwxrwxrwx 1 root root  15 jun 21 08:16 EBT -> ../../mmcblk0p4
lrwxrwxrwx 1 root root  16 jun 21 08:16 EKS -> ../../mmcblk0p12
lrwxrwxrwx 1 root root  15 jun 21 08:16 FX -> ../../mmcblk0p8
lrwxrwxrwx 1 root root  16 jun 21 08:16 LNX -> ../../mmcblk0p11
lrwxrwxrwx 1 root root  15 jun 21 08:16 RP1 -> ../../mmcblk0p3
lrwxrwxrwx 1 root root  16 jun 21 08:16 RP4 -> ../../mmcblk0p14
lrwxrwxrwx 1 root root  15 jun 21 08:16 TBC -> ../../mmcblk0p2
lrwxrwxrwx 1 root root  15 jun 21 08:16 TOS -> ../../mmcblk0p9
lrwxrwxrwx 1 root root  15 jun 21 08:16 WB0 -> ../../mmcblk0p5

#Reboot board
sudo reboot

Flash Custom Kernel Image

In order to replace the kernel image you need to copy the Image file to the Jetson nano to the directory /boot/ send the custom kernel image binary to the Jetson Nano:

NANO_IP=10.251.101.144
scp sources/kernel/kernel-4.9/build/arch/arm64/boot/Image nvidia@<$NANO_IP>:

Then in the Jetson Nano board replace the file as:

cd ~/
sudo cp Image /boot/
sudo mv /lib/modules/4.9.140-tegra/ /lib/modules/4.9.140
sudo reboot

Reboot the system after replacing the Image is important.

SDcard Image Clone

In order to clone a SDcard Image with all the partitions required by the Jetson Nano run the following command:

sudo dd if=/dev/mmcblk0 of=sdimage-jetson-nano.img bs=4M

To flash the SDcard with the previous content run the following command:

sudo dd if=sdimage-jetson-nano.img of=/dev/mmcblk0 bs=1M


Previous: Introduction/Getting_Started Index Next: GStreamer/Accelerated_Elements