Jetson Nano/Development/Building the Kernel from Source: Difference between revisions
No edit summary |
|||
Line 27: | Line 27: | ||
== 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"> | ||
cd ~ | cd ~ | ||
mkdir -p toolchain_bin_$VERSION | mkdir -p toolchain_bin_$VERSION | ||
Line 37: | Line 37: | ||
tar -xf ${TOOLCHAIN_SRC}.tar.gz | tar -xf ${TOOLCHAIN_SRC}.tar.gz | ||
fi | fi | ||
</ | </syntaxhighlight> | ||
== Downloading Kernel sources == | == Downloading Kernel sources == | ||
In this step you need to have installed JetPack 4.2 for nano boards. | In this step you need to have installed JetPack 4.2 for nano boards. | ||
< | <syntaxhighlight lang="bash" style="background-color:cornsilk"> | ||
JETPACK=~/JetPack-L4T-4.2 | JETPACK=~/JetPack-L4T-4.2 | ||
cd ${JETPACK}/JetPack_4.2_Linux_P3448/Linux_for_Tegra/ | cd ${JETPACK}/JetPack_4.2_Linux_P3448/Linux_for_Tegra/ | ||
Line 49: | Line 49: | ||
# When prompted, use: tegra-l4t-r32.1 as the tag (change accordingly) | # When prompted, use: tegra-l4t-r32.1 as the tag (change accordingly) | ||
## | ## | ||
</ | </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"> | ||
JETPACK=~/JetPack-L4T-4.2 | JETPACK=~/JetPack-L4T-4.2 | ||
CROSS_COMPILE=${HOME}/toolchain_bin_${VERSION}/${TOOLCHAIN_DIR}/bin/$CC_PREFIX | CROSS_COMPILE=${HOME}/toolchain_bin_${VERSION}/${TOOLCHAIN_DIR}/bin/$CC_PREFIX | ||
Line 67: | Line 68: | ||
# Build the kernel and DTBs | # Build the kernel and DTBs | ||
make ARCH=arm64 O=$KERNEL_OUT CROSS_COMPILE=${CROSS_COMPILE} -j4 | make ARCH=arm64 O=$KERNEL_OUT CROSS_COMPILE=${CROSS_COMPILE} -j4 | ||
</ | </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"> | ||
# flash whole file system | # flash whole file system | ||
sudo ./flash.sh jetson-nano-qspi-sd mmcblk0p1 | sudo ./flash.sh jetson-nano-qspi-sd mmcblk0p1 | ||
</ | </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"> | ||
#flash just DTB | #flash just DTB | ||
cd ${JETPACK}/JetPack_4.2_Linux_P3448/Linux_for_Tegra/ | 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/ | 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 | sudo ./flash.sh -r -k DTB jetson-nano-qspi-sd mmcblk0p1 | ||
</ | </syntaxhighlight> | ||
==Flash DTB from the Jetson device itself== | ==Flash DTB from the Jetson device itself== | ||
Line 90: | Line 91: | ||
* Generate the encrypted DTB: | * Generate the encrypted DTB: | ||
< | <syntaxhighlight lang="bash" style="background-color:cornsilk"> | ||
cp sources/kernel/kernel-4.9/build/arch/arm64/boot/dts/tegra210-p3448-0000-p3449-0000-a02.dtb kernel/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 | 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: | # 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 | # ${JETPACK}/JetPack_4.2_Linux_P3448/Linux_for_Tegra/bootloader/signed/tegra210-p3448-0000-p3449-0000-a02.dtb.encrypt | ||
</ | </syntaxhighlight> | ||
* Flash the encrypted DTB to the DTB partition: | * Flash the encrypted DTB to the DTB partition: | ||
< | <syntaxhighlight lang="bash" style="background-color:cornsilk"> | ||
# Pull the SD card out of the Nano and put into your Linux machine | # 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> | 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> | ||
Line 129: | Line 130: | ||
#Reboot board | #Reboot board | ||
sudo reboot | sudo reboot | ||
</ | </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: | ||
< | <syntaxhighlight lang="bash" style="background-color:cornsilk"> | ||
NANO_IP=10.251.101.144 | NANO_IP=10.251.101.144 | ||
scp sources/kernel/kernel-4.9/build/arch/arm64/boot/Image nvidia@<$NANO_IP>: | scp sources/kernel/kernel-4.9/build/arch/arm64/boot/Image nvidia@<$NANO_IP>: | ||
</ | </syntaxhighlight> | ||
Then in the Jetson Nano board replace the file as: | Then in the Jetson Nano board replace the file as: | ||
< | <syntaxhighlight lang="bash" style="background-color:cornsilk"> | ||
cd ~/ | cd ~/ | ||
sudo cp Image /boot/ | sudo cp Image /boot/ | ||
sudo mv /lib/modules/4.9.140-tegra/ /lib/modules/4.9.140 | sudo mv /lib/modules/4.9.140-tegra/ /lib/modules/4.9.140 | ||
sudo reboot | sudo reboot | ||
</ | </syntaxhighlight> | ||
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"> | ||
sudo dd if=/dev/mmcblk0 of=sdimage-jetson-nano.img bs=4M | sudo dd if=/dev/mmcblk0 of=sdimage-jetson-nano.img bs=4M | ||
</ | </syntaxhighlight> | ||
To flash the SDcard with the previous content run the following command: | To flash the SDcard with the previous content run the following command: | ||
< | <syntaxhighlight lang="bash" style="background-color:cornsilk"> | ||
sudo dd if=sdimage-jetson-nano.img of=/dev/mmcblk0 bs=1M | sudo dd if=sdimage-jetson-nano.img of=/dev/mmcblk0 bs=1M | ||
</ | </syntaxhighlight> | ||
<noinclude> | <noinclude> |
Revision as of 18:33, 27 January 2020
NVIDIA®Jetson Nano™ | |||
---|---|---|---|
Introduction | |||
|
|||
Development | |||
|
|||
GStreamer | |||
|
|||
Contact Us |
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
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) ##
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