22.10.28 当前官方版本是R32.7.1 jetpack6.3,如果有新版本,请去nvidia的下载中心找新的
https://developer.nvidia.com/embedded/downloads
1,我的硬件
jetson nano b001,就是官方16G emmc的模块,+ 国产 图为科技的底板
2,我的目的:
要安装linux preempt rt实时补丁,所以需要重新编译内核源码
3,说明:
jetson nano从r35开始,官方已经带preempt的补丁配置程序了,但是没有编译,没有安装,所以默认你能看到下面信息,但是实际上RT没有运行,没有安装
~$ uname -a
Linux ubuntu 4.9.253-tegra #1 SMP PREEMPT Wed Apr 20 14:25:12 PDT 2022 aarch64 aarch64 aarch64 GNU/Linux
4,开始步骤:
0,重点说明
全程按照下面操作,不要改目录,容易弄错
下面操作内容是在PC电脑的ubuntu上进行的,不是在jetson板子里面。
1,编译需要
# Install required packages
sudo apt-get update
sudo apt-get install libncurses5-dev
sudo apt-get install build-essential bc
sudo apt-get install lbzip2
sudo apt-get install qemu-user-static
2,程序包下载
# L4T Jetson Driver Package
wget https://developer.nvidia.com/embedded/l4t/r32_release_v7.1/t210/jetson-210_linux_r32.7.1_aarch64.tbz2
# L4T Sample Root File System
wget https://developer.nvidia.com/embedded/l4t/r32_release_v7.1/t210/tegra_linux_sample-root-filesystem_r32.7.1_aarch64.tbz2
# L4T Sources:
wget https://developer.nvidia.com/embedded/l4t/r32_release_v7.1/sources/t210/public_sources.tbz2
# GCC Tool Chain for 64-bit BSP
#使用浏览器下载得到gcc开头压缩包
https://developer.nvidia.com/embedded/dlc/l4t-gcc-7-3-1-toolchain-64-bit
3,打补丁
# Create build folder
mkdir $HOME/jetson_nano
cd $HOME/jetson_nano
# Extract files
sudo tar xpf jetson-210_linux_r32.7.1_aarch64.tbz2
cd Linux_for_Tegra/rootfs/
sudo tar xpf ../../tegra_linux_sample-root-filesystem_r32.7.1_aarch64.tbz2
cd ../../
tar -xvf gcc-linaro-7.3.1-2018.05-x86_64_aarch64-linux-gnu.tar.xz
sudo tar -xjf public_sources.tbz2
tar -xjf Linux_for_Tegra/source/public/kernel_src.tbz2
# Apply PREEMPT-RT patches
cd kernel/kernel-4.9/
./scripts/rt-patch.sh apply-patches
4,编译
# Compile kernel
TEGRA_KERNEL_OUT=jetson_nano_kernel
mkdir $TEGRA_KERNEL_OUT
export CROSS_COMPILE=$HOME/jetson_nano/gcc-linaro-7.3.1-2018.05-x86_64_aarch64-linux-gnu/bin/aarch64-linux-gnu-
make ARCH=arm64 O=$TEGRA_KERNEL_OUT tegra_defconfig
make ARCH=arm64 O=$TEGRA_KERNEL_OUT menuconfig
保证如下两条正确
# This option should already be selected: Kernel Features -> Preemption Model: Fully Preemptible Kernel (RT)
# You can modify other options for your kernel, like the timer frequency (or anything you need): Kernel Features -> Timer frequency: 1000 HZ
# After saving the configuration and exiting, start the kernel compilation
make ARCH=arm64 O=$TEGRA_KERNEL_OUT -j16
# Copy results
sudo cp jetson_nano_kernel/arch/arm64/boot/Image $HOME/jetson_nano/Linux_for_Tegra/kernel/Image
sudo cp -r jetson_nano_kernel/arch/arm64/boot/dts/* $HOME/jetson_nano/Linux_for_Tegra/kernel/dtb/
sudo make ARCH=arm64 O=$TEGRA_KERNEL_OUT modules_install INSTALL_MOD_PATH=$HOME/jetson_nano/Linux_for_Tegra/rootfs/
cd $HOME/jetson_nano/Linux_for_Tegra/rootfs/
sudo tar --owner root --group root -cjf kernel_supplements.tbz2 lib/modules
sudo mv kernel_supplements.tbz2 ../kernel/
# Apply binaries
cd ..
sudo ./apply_binaries.sh
5,烧写
(1)如果是sd卡的jetson nano,执行如下
cd tools
#可以打开这个sh文件,看参数介绍
sudo ./jetson-disk-image-creator.sh -o jetson_nano.img -b jetson-nano -r 100
(2)如果是emmc 16G的jetson nano,执行如下
- 断电jetson nano
- 先连jetson nano usb到PC Ubuntu电脑(可以是虚拟机)
- 然后短接jetson nano板子的REC-GND
- 然后上电
cd $HOME/jetson_nano/Linux_for_Tegra
sudo ./flash.sh jetson-nano-emmc mmcblk0p1
5,延迟测试
sudo apt-get install rt-tests
运行cyclictest程序进行实时性测试:
sudo cyclictest -t 5 -p 80 -n #运行五个线程,线程优先级为80
b@jetson:~uname -a
Linux jetson 4.9.253-rt168 #1 SMP PREEMPT RT Fri Oct 28 09:36:04 CST 2022 aarch64 aarch64 aarch64 GNU/Linux
b@jetson:~$ sudo cyclictest -t 5 -p 80 -n
[sudo] password for b:
# /dev/cpu_dma_latency set to 0us
policy: fifo: loadavg: 0.16 0.16 0.23 1/621 19140
T: 0 (19046) P:80 I:1000 C: 15300 Min: 5 Act: 6 Avg: 7 Max: 20
T: 1 (19047) P:80 I:1500 C: 10200 Min: 5 Act: 6 Avg: 6 Max: 25
T: 2 (19048) P:80 I:2000 C: 7650 Min: 5 Act: 6 Avg: 6 Max: 19
T: 3 (19049) P:80 I:2500 C: 6120 Min: 5 Act: 6 Avg: 7 Max: 24
T: 4 (19050) P:80 I:3000 C: 5100 Min: 5 Act: 7 Avg: 6 Max: 18
参考链接:
https://forums.developer.nvidia.com/t/preempt-rt-patches-for-jetson-nano/72941/25
本文地址: jetson nano编译kernel内核源码,打preempt rt补丁,烧写