Jetson Nano - 编译内核&烧录DTB和内核Image

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
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)
##

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
  • 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.
#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 without using flash.sh script:
#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/sdx10

# This will program the DTB file into the 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/

#Verify which is your DTB partition from your Nano board
  • 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=192.168.1.100
scp sources/kernel/kernel-4.9/build/arch/arm64/boot/Image nvidia@<$NANO_IP>:

#my example
scp out/kernel_out/arch/arm64/boot/Image [email protected]:/home/jetbot

Then in the Jetson Nano board replace the file as:

cd ~/
sudo cp Image /boot/
sudo reboot

Reboot the system after replacing the Image is important.

参考:
Ridgerun NVIDIA_Jetson_Nano_-_Building_the_Kernel_from_Source

你可能感兴趣的:(Jetson Nano - 编译内核&烧录DTB和内核Image)