Jetson-TX2 Linux开发环境搭建

Jetson-TX2 Linux开发环境搭建

  • 1. 开发环境
  • 2. 安装 SDK Manager 工具
  • 2. 安装编译工具链
  • 4. 下载源码
  • 4. 编译内核源码
  • 6. 编译Uboot源码
  • 参考资料

1. 开发环境

硬件平台	:Jetson-TX2
系统版本	:Ubuntu 18.04.4 LTS (GNU/Linux 4.9.140-tegra aarch64)
虚拟机Ubuntu系统版本: 
18.04.1-Ubuntu SMP Sat Sep 5 14:35:50 UTC 2020

2. 安装 SDK Manager 工具

  1. 到NVIDIA官网SDK Manager工具,将其 sdkmanager_1.3.0-7105_amd64.deb 复制到TX2 Ubuntu中或是虚拟机Ubuntu中。
  2. 安装 sdkmanager_1.3.0-7105_amd64.deb
$ sudo apt install ./sdkmanager_1.2.0-6733_amd64.deb 
  1. 运行 sdkmanager
$ sdkmanager

Jetson-TX2 Linux开发环境搭建_第1张图片

  1. 使用 sdkmanager 软件下载sdk或刷机
    请参考官方文档

  2. 获取SDK源码
    上面的步骤中会设置SDK的下载目录,进入下载目录,获取源码文件及手册。

主要用到下面3个压缩包
Jetson_Linux_R32.4.3_aarch64.tbz2        // 使用其中 source_sync.sh 可以从Git上下载uboot、kernel等源码,便于管理
NVIDIA_Jetson_Linux_Driver_Package.tar   // Linux Developer Guide
NVIDIA_VisionWorks_References.zip        // NVIDIA 各种 API 说明

若SDK下载目录里没有找到,可以到官网里下载对应的SDK包。

Tegra186_Linux_R32.4.3_aarch64.tbz2       // 与Jetson_Linux_R32.4.3_aarch64.tbz2一样
public_sources.tbz2                       // 已经包含了相关源码,可以直接使用

2. 安装编译工具链

  1. 若使用 Jetson-TX2 板子编译,刷机到对应的 JetPack 版本,本身的Ubuntu系统已经配置好了编译工具链,可以直接使用
$ gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/aarch64-linux-gnu/7/lto-wrapper
Target: aarch64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu/Linaro 7.5.0-3ubuntu1~18.04' --with-bugurl=file:///usr/share/doc/gcc-7/README.Bugs --enable-languages=c,ada,c++,go,d,fortran,objc,obj-c++ --prefix=/usr --with-gcc-major-version-only --program-suffix=-7 --program-prefix=aarch64-linux-gnu- --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --libdir=/usr/lib --enable-nls --enable-bootstrap --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new --enable-gnu-unique-object --disable-libquadmath --disable-libquadmath-support --enable-plugin --enable-default-pie --with-system-zlib --enable-multiarch --enable-fix-cortex-a53-843419 --disable-werror --enable-checking=release --build=aarch64-linux-gnu --host=aarch64-linux-gnu --target=aarch64-linux-gnu
Thread model: posix
gcc version 7.5.0 (Ubuntu/Linaro 7.5.0-3ubuntu1~18.04)
  1. 使用虚拟机的Ubuntu系统,需要安装编译工具链

(1)下载编译工具链
gcc-linaro-7.3.1-2018.05-x86_64_aarch64-linux-gnu.tar.xz
(2)安装编译链
a. 解压编译链安装包

$ sudo tar xvf gcc-linaro-7.3.1-2018.05-x86_64_aarch64-linux-gnu.tar.x

b. 修改.bashrc文件,在最后添加下面3行export内容。

sudo vi ~/.bashrc
export ARCH=arm64
export CROSS_COMPILE=aarch64-linux-gnu-
export PATH=$PATH:/home/book/gcc/gcc-linaro-7.3.1-2018.05-x86_64_aarch64-linux-gnu/bin

c. 使.bashrc文件生效

source ~/.bashrc

b. 查看编译链是否生效

$ aarch64-linux-gnu-gcc -v
Using built-in specs.
COLLECT_GCC=aarch64-linux-gnu-gcc
COLLECT_LTO_WRAPPER=/home/book/gcc/gcc-linaro-7.3.1-2018.05-x86_64_aarch64-linux-gnu/bin/../libexec/gcc/aarch64-linux-gnu/7.3.1/lto-wrapper
Target: aarch64-linux-gnu
Configured with: '/home/tcwg-buildslave/workspace/tcwg-make-release/builder_arch/amd64/label/tcwg-x86_64-build/target/aarch64-linux-gnu/snapshots/gcc.git~linaro-7.3-2018.05/configure' SHELL=/bin/bash --with-mpc=/home/tcwg-buildslave/workspace/tcwg-make-release/builder_arch/amd64/label/tcwg-x86_64-build/target/aarch64-linux-gnu/_build/builds/destdir/x86_64-unknown-linux-gnu --with-mpfr=/home/tcwg-buildslave/workspace/tcwg-make-release/builder_arch/amd64/label/tcwg-x86_64-build/target/aarch64-linux-gnu/_build/builds/destdir/x86_64-unknown-linux-gnu --with-gmp=/home/tcwg-buildslave/workspace/tcwg-make-release/builder_arch/amd64/label/tcwg-x86_64-build/target/aarch64-linux-gnu/_build/builds/destdir/x86_64-unknown-linux-gnu --with-gnu-as --with-gnu-ld --disable-libmudflap --enable-lto --enable-shared --without-included-gettext --enable-nls --with-system-zlib --disable-sjlj-exceptions --enable-gnu-unique-object --enable-linker-build-id --disable-libstdcxx-pch --enable-c99 --enable-clocale=gnu --enable-libstdcxx-debug --enable-long-long --with-cloog=no --with-ppl=no --with-isl=no --disable-multilib --enable-fix-cortex-a53-835769 --enable-fix-cortex-a53-843419 --with-arch=armv8-a --enable-threads=posix --enable-multiarch --enable-libstdcxx-time=yes --enable-gnu-indirect-function --with-build-sysroot=/home/tcwg-buildslave/workspace/tcwg-make-release/builder_arch/amd64/label/tcwg-x86_64-build/target/aarch64-linux-gnu/_build/sysroots/aarch64-linux-gnu --with-sysroot=/home/tcwg-buildslave/workspace/tcwg-make-release/builder_arch/amd64/label/tcwg-x86_64-build/target/aarch64-linux-gnu/_build/builds/destdir/x86_64-unknown-linux-gnu/aarch64-linux-gnu/libc --enable-checking=release --disable-bootstrap --enable-languages=c,c++,fortran,lto --build=x86_64-unknown-linux-gnu --host=x86_64-unknown-linux-gnu --target=aarch64-linux-gnu --prefix=/home/tcwg-buildslave/workspace/tcwg-make-release/builder_arch/amd64/label/tcwg-x86_64-build/target/aarch64-linux-gnu/_build/builds/destdir/x86_64-unknown-linux-gnu
Thread model: posix
gcc version 7.3.1 20180425 [linaro-7.3-2018.05 revision d29120a424ecfbc167ef90065c0eeb7f91977701] (Linaro GCC 7.3-2018.05)

Jetson-TX2 板子Ubuntu系统中的编译工具链版本版比官方提供的编译工具链版本版高,应该都是可以使用的。

4. 下载源码

  1. 确定 kernel 的版本
$ cat /etc/nv_tegra_release
# R32 (release), REVISION: 4.3, GCID: 21589087, BOARD: t186ref, EABI: aarch64, DATE: Fri Jun 26 04:34:27 UTC 2020

uname -r
4.9.140-tegra
  1. 手动下载源码

(1)下载 public_sources.tbz2 压缩包
(2)解压 public_sources.tbz2 压缩包

$ tar xjvf public_sources.tbz2

(3)提取kernel和uboot源码

$ cd Linux_for_Tegra/source/public/
$ tar xjvf kernel_src.tbz2
$ tar xjvf u-boot_src.tbz2
  1. 从Git上获取源码

(1)下载Tegra186_Linux_R32.4.3_aarch64.tbz2或Jetson_Linux_R32.4.3_aarch64.tbz2
(2)解压 Tegra186_Linux_R32.4.3_aarch64.tbz2 压缩包

$ tar xjvf Tegra186_Linux_R32.4.3_aarch64.tbz2

(3)下kernel、uboot等源码

$ cd Linux_for_Tegra/
./source_sync.sh -h                          // 查看帮助信息
./source_sync.sh -t tegra-l4t-r32.4.3        // sync all the sources
./source_sync.sh -k tegra-l4t-r32.4.3        // Download kernel/kernel-4.9 source 等
./source_sync.sh -u tegra-l4t-r32.4.3        // Download u-boot source

4. 编译内核源码

  1. 设置环境变量
$ TEGRA_KERNEL_OUT=<kernel_source>/out/   // 指定编译内核生成各种文件的目录
$ mkdir -p $TEGRA_KERNEL_OUT
// export中已经存在的可以不设置
$ export CROSS_COMPILE=<cross_prefix>
$ export ARCH=arm64
$ export LOCALVERSION=-tegra
  1. 生成.config文件
$ cd <kernel_source>
$ make mrproper
$ make O=$TEGRA_KERNEL_OUT tegra_defconfig
$ make O=$TEGRA_KERNEL_OUT menuconfig
  1. 编译内核
$ make O=$TEGRA_KERNEL_OUT -j4
  1. 单独内核,编译设备树,驱动模块
$ make O=$TEGRA_KERNEL_OUT Image
$ make O=$TEGRA_KERNEL_OUT zImage
$ make O=$TEGRA_KERNEL_OUT dtbs
$ make O=$TEGRA_KERNEL_OUT modules       // 编译所有的驱动模块
$ make -C /lib/modules/`uname -r`/build M=`pwd`/drivers/usb/serial obj-m=qcserial.o modules 				 // 编译单独的驱动模块
  1. 更新内核
$ cd $TEGRA_KERNEL_OUT
$ sudo cp arch/arm64/boot/Image /boot/
$ sudo reboot

/boot 目录下还有设备树dtb文件,估计将新编译的设备文件替换原始的设备树,新设备树文件也会生效,暂时没有测试。

  1. 更新驱动模块
// 如,移植4G网口驱动,需要加载 qcserial.ko
$ cd $TEGRA_KERNEL_OUT
$ sudo cp drivers/usb/serial/qcserial.ko /lib/modules/`uname -r`/kernel/drivers/usb/serial
$ sudo depmod
$ sudo reboot

注意: NVIDIA recommends using the Linaro 7.3.1 2018.05 toolchain.

6. 编译Uboot源码

  1. 设置环境变量
$ export CROSS_COMPILE=<cross_prefix>
  1. 编译Uboot
$ make distclean
$ make <board_and_rev>_defconfig
$ make
………………
  SHIPPED dts/dt.dtb
  CAT     u-boot-dtb.bin
  COPY    u-boot.bin
  SYM     u-boot.sym
  CFG     u-boot.cfg
  COPY    u-boot.dtb
Platform
Jetson Nano p3450-porg p3450-porg
Jetson TX2 series devices p2771-0000 p2771-0000-500
Jetson TX1 p2371-2180 p2371-2180

根据上表选择硬件对应的

注意: NVIDIA recommends using the Linaro 7.3.1 2018.05 toolchain.

  1. 更新Uboot
$ sudo ./flash.sh -k EBT <platform> mmcblk0p1

更新Uboot 暂未测试,后续补充完成

参考资料

NVIDIA Jetson Linux Developer Guide

你可能感兴趣的:(tx2,linux,内核,ubuntu)