Xavier交叉编译环境搭建,编译及刷机全过程

目录

1、源码下载 L4T R32.5.1为例

1)、kernel

2)、root filesystem

3)、cboot

2、打包环境

1)、配置root file system

2)、copy the rootfs to the device

3、交叉编译工具

1)、gcc

2)、cuda

4、交叉编译环境配置

5、编译kernel

1)、解压内核

2)、编译内核

3)、生成Image和dtb,替换并安装

4)、(可选)在rootfs路径下

5)、烧录

6、编译外部kernel modules

1)、在jetson上

2)、交叉编译

7、安装packages到文件系统

8、编译bootloader

9、打包镜像

10、刷机脚本



1、源码下载 L4T R32.5.1为例

1)、kernel

L4T R32.5.1 Release Page | NVIDIA Developer

L4T Driver Package (BSP) Sources

2)、root filesystem

L4T R32.5.1 Release Page | NVIDIA Developer

Sample Root Filesystem Sources

3)、cboot

L4T R32.5.1 Release Page | NVIDIA Developer

Cboot Sources T194

2、打包环境

1)、配置root file system

$ sudo apt-get install qemu-user-static
$ tar -xvjf Tegra186_Linux_R32.5.1_aarch64.tbz2
$ cd Linux_for_Tegra/rootfs
$ sudo tar -jxpf ../../Tegra-Linux-Sample-Root-Filesystem_<release_type>.tbz2
$ cd ..
$ sudo ./apply_binaries.sh

2)、copy the rootfs to the device

1.Pick a device to place your rootfs.
•If you are using the internal EMMC, skip ahead to Flashing and Booting the Target Device.
2.If you prefer to use an external storage device for the root filesystem, use the following procedure.
To copy the file system to an external storage device
1.Plug your rootfs device into the host system.
2.If your device is not formatted as Ext4, enter the following command to format it with an Ext4 file system:
$ sudo mkfs.ext4 /dev/sd<port><device_number>
Where:
•<port> is the port to which your device is mounted.
•<device_number> is the device number of the device attached to the port. You can use the dmesg command to determine the port.
3.If needed, mount your device with the following command:
$ sudo mount /dev/sdX1 <mntpoint>
Where <mntpoint> is the mount point on the host system for your rootfs device.
4.Copy the file system. If LDK_ROOTFS_DIR is set, execute these commands:
$ cd ${LDK_ROOTFS_DIR}
$ sudo cp –a * <mntpoint> && sync
5.If it is not set, copy the rootfs directory that is included in the release by executing the following commands:
$ cd <your_L4T_root>/Linux_for_Tegra/rootfs
$ sudo cp –a * <mntpoint> && sync
6.After copying the content to the external disk or device, unmount the disk and connect it to the target SoC device.

3、交叉编译工具

1)、gcc

L4T R32.5.1 Release Page | NVIDIA Developer

GCC 7.3.1 for 64 bit BSP and Kernel (gcc-linaro-7.3.1-2018.05-x86_64_aarch64-linux-gnu.tar.xz) 

http://releases.linaro.org/components/toolchain/binaries/7.3-2018.05/aarch64-linux-gnu/gcc-linaro-7.3.1-2018.05-x86_64_aarch64-linux-gnu.tar.xz

Sources for the GCC 7.3.1 Tool Chain for 64-bit BSP and Kernel

2)、cuda

L4T R32.5.1 Release Page | NVIDIA Developer

CUDA Tools

4、交叉编译环境配置

$ mkdir $HOME/l4t-gcc
$ cd $HOME/l4t-gcc
$ tar xf gcc-linaro-7.3.1-2018.05-x86_64_aarch64-linux-gnu.tar.xz

5、编译kernel

1)、解压内核

$ tar -xvjf public_sources.tbz2 
$ cd Linux_for_Tegra/source/public
$ tar -xvjf kernel_src.tbz2

2)、编译内核

编译依赖工具 sudo apt install build-essential bc
$ mkdir src_out
$ TEGRA_KERNEL_OUT=~/Work/Linux_for_Tegra/source/src_out/
$ export CROSS_COMPILE=/opt/gcc-linaro-7.3.1-2018.05-x86_64_aarch64-linux-gnu/bin/aarch64-linux-gnu-
$ export LOCALVERSION=-tegra
$ mkdir -p $TEGRA_KERNEL_OUT
进入kernel源码下
$ cd public/kernel/kernel-4.9
$ make ARCH=arm64 O=$TEGRA_KERNEL_OUT tegra_defconfig
$ make ARCH=arm64 O=$TEGRA_KERNEL_OUT -j10

3)、生成Image和dtb,替换并安装

~/Work/Linux_for_Tegra/source/src_out/arch/arm64/boot/Image 替换<release_packagep>/Linux_for_Tegra/kernel/Image

~/Work/Linux_for_Tegra/source/src_out/arch/arm64/boot/dts/ 替换Linux_for_Tegra/kernel/dtb/

安装内核模块 sudo make ARCH=arm64 O=$TEGRA_KERNEL_OUT modules_install INSTALL_MOD_PATH=<top>/Linux_for_Tegra/rootfs/

4)、(可选)在rootfs路径下

$ cd <modules_install_path>
$ tar --owner root --group root -cjf kernel_supplements.tbz2 \
lib/modules
将 “kernel_supplements.tbz2”替换到Linux_for_Tegra/kernel$路径下 执行 apply_binaries.sh 脚本

5)、烧录

进入recovery模式,sudo ./flash.sh p3449-0000+p3668-0001-qspi-emmc mmcblk0p1

6、编译外部kernel modules

1)、在jetson上

To prepare the L4T kernel headers on a Jetson system
•On a Jetson system you can use the files in this directory to build out-of-tree modules without further action:
/usr/src/linux-headers-$(uname -r)-ubuntu18.04_aarch64
•To build out-of-tree modules, specify the kernel directory as:
/usr/src/linux-headers-$(uname -r)-ubuntu18.04_aarch64
or
/lib/modules/$(uname -r)/build

2)、交叉编译

To prepare the Jetson Linux kernel headers on a non-Jetson system
•Extract the following archive and place it in a local directory with the commands:
$ cd <local_src_dir>
$ tar -xjf <top>/Linux_for_Tegra/kernel/kernel_headers.tbz2
•You can use the files in this directory to build out-of-tree modules without further action:
<local_src_dir>/linux-headers-$(uname -r)-linux_x86_64
•To build out-of-tree modules, specify the kernel directory as:
<local src dir>/linux-headers-$(uname -r)-linux_x86_64
$ make ARCH=arm64 O=$TEGRA_KERNEL_OUT -j<n> modules_prepare


Execute the following commands to build an out-of-tree kernel module:
$ cd <path_to_module_source>
$ make ARCH=arm64 –C <kernel_directory> M=$(pwd)
Execute the following commands to strip unneeded symbols from the kernel module:
$ <tool_chain_path>/aarch64-linux-gnu-strip -–strip-unneeded <path-of-kernel-module.ko>

7、安装packages到文件系统

~/Work/Linux_for_Tegra$ sudo ./apply_binaries.sh 
Using rootfs directory of: /home/charle/Work/Linux_for_Tegra/rootfs
Installing extlinux.conf into /boot/extlinux in target rootfs
/home/charle/Work/Linux_for_Tegra/nv_tegra/nv-apply-debs.sh
Root file system directory is /home/charle/Work/Linux_for_Tegra/rootfs
Copying public debian packages to rootfs
Start L4T BSP package installation
QEMU binary is not available, looking for QEMU from host system
Found /usr/bin/qemu-aarch64-static
Installing QEMU binary in rootfs
~/Work/Linux_for_Tegra/rootfs ~/Work/Linux_for_Tegra
Installing BSP Debian packages in /home/charle/Work/Linux_for_Tegra/rootfs
(Reading database ... 160747 files and directories currently installed.)
Preparing to unpack .../nvidia-l4t-core_32.6.1-20210726122859_arm64.deb ...
Pre-installing... skip compatibility checking.
Unpacking nvidia-l4t-core (32.6.1-20210726122859) over (32.6.1-20210726122859) ...
Setting up nvidia-l4t-core (32.6.1-20210726122859) ...
(Reading database ... 160747 files and directories currently installed.)
Preparing to unpack .../jetson-gpio-common_2.0.17_arm64.deb ...
Unpacking jetson-gpio-common (2.0.17) over (2.0.17) ...
Preparing to unpack .../python3-jetson-gpio_2.0.17_arm64.deb ...
Unpacking python3-jetson-gpio (2.0.17) over (2.0.17) ...
Preparing to unpack .../python-jetson-gpio_2.0.17_arm64.deb ...
Unpacking python-jetson-gpio (2.0.17) over (2.0.17) ...
Preparing to unpack .../nvidia-l4t-3d-core_32.6.1-20210726122859_arm64.deb ...
Unpacking nvidia-l4t-3d-core (32.6.1-20210726122859) over (32.6.1-20210726122859) ...
Preparing to unpack .../nvidia-l4t-apt-source_32.6.1-20210726122859_arm64.deb ...
Unpacking nvidia-l4t-apt-source (32.6.1-20210726122859) over (32.6.1-20210726122859) ...
Preparing to unpack .../nvidia-l4t-camera_32.6.1-20210726122859_arm64.deb ...
Unpacking nvidia-l4t-camera (32.6.1-20210726122859) over (32.6.1-20210726122859) ...
Preparing to unpack .../nvidia-l4t-configs_32.6.1-20210726122859_arm64.deb ...
Unpacking nvidia-l4t-configs (32.6.1-20210726122859) over (32.6.1-20210726122859) ...
Preparing to unpack .../nvidia-l4t-cuda_32.6.1-20210726122859_arm64.deb ...
Unpacking nvidia-l4t-cuda (32.6.1-20210726122859) over (32.6.1-20210726122859) ...
Preparing to unpack .../nvidia-l4t-firmware_32.6.1-20210726122859_arm64.deb ...
Unpacking nvidia-l4t-firmware (32.6.1-20210726122859) over (32.6.1-20210726122859) ...
Preparing to unpack .../nvidia-l4t-gputools_32.6.1-20210726122859_arm64.deb ...
Unpacking nvidia-l4t-gputools (32.6.1-20210726122859) over (32.6.1-20210726122859) ...
Preparing to unpack .../nvidia-l4t-graphics-demos_32.6.1-20210726122859_arm64.deb ...
Unpacking nvidia-l4t-graphics-demos (32.6.1-20210726122859) over (32.6.1-20210726122859) ...
Preparing to unpack .../nvidia-l4t-gstreamer_32.6.1-20210726122859_arm64.deb ...
Unpacking nvidia-l4t-gstreamer (32.6.1-20210726122859) over (32.6.1-20210726122859) ...
Preparing to unpack .../nvidia-l4t-init_32.6.1-20210726122859_arm64.deb ...
Unpacking nvidia-l4t-init (32.6.1-20210726122859) over (32.6.1-20210726122859) ...
Preparing to unpack .../nvidia-l4t-initrd_32.6.1-20210726122859_arm64.deb ...
Unpacking nvidia-l4t-initrd (32.6.1-20210726122859) over (32.6.1-20210726122859) ...
Preparing to unpack .../nvidia-l4t-jetson-io_32.6.1-20210726122859_arm64.deb ...
Unpacking nvidia-l4t-jetson-io (32.6.1-20210726122859) over (32.6.1-20210726122859) ...
Preparing to unpack .../nvidia-l4t-libvulkan_32.6.1-20210726122859_arm64.deb ...
Unpacking nvidia-l4t-libvulkan (32.6.1-20210726122859) over (32.6.1-20210726122859) ...
Preparing to unpack .../nvidia-l4t-multimedia_32.6.1-20210726122859_arm64.deb ...
Unpacking nvidia-l4t-multimedia (32.6.1-20210726122859) over (32.6.1-20210726122859) ...
Preparing to unpack .../nvidia-l4t-multimedia-utils_32.6.1-20210726122859_arm64.deb ...
Unpacking nvidia-l4t-multimedia-utils (32.6.1-20210726122859) over (32.6.1-20210726122859) ...
Preparing to unpack .../nvidia-l4t-oem-config_32.6.1-20210726122859_arm64.deb ...
Unpacking nvidia-l4t-oem-config (32.6.1-20210726122859) over (32.6.1-20210726122859) ...
Preparing to unpack .../nvidia-l4t-tools_32.6.1-20210726122859_arm64.deb ...
Unpacking nvidia-l4t-tools (32.6.1-20210726122859) over (32.6.1-20210726122859) ...
Preparing to unpack .../nvidia-l4t-wayland_32.6.1-20210726122859_arm64.deb ...
Unpacking nvidia-l4t-wayland (32.6.1-20210726122859) over (32.6.1-20210726122859) ...
Preparing to unpack .../nvidia-l4t-weston_32.6.1-20210726122859_arm64.deb ...
Unpacking nvidia-l4t-weston (32.6.1-20210726122859) over (32.6.1-20210726122859) ...
Preparing to unpack .../nvidia-l4t-x11_32.6.1-20210726122859_arm64.deb ...
Unpacking nvidia-l4t-x11 (32.6.1-20210726122859) over (32.6.1-20210726122859) ...
Preparing to unpack .../nvidia-l4t-xusb-firmware_32.6.1-20210726122859_arm64.deb ...
Unpacking nvidia-l4t-xusb-firmware (32.6.1-20210726122859) over (32.6.1-20210726122859) ...
Preparing to unpack .../nvidia-l4t-kernel_4.9.253-tegra-32.6.1-20210726122859_arm64.deb ...
Unpacking nvidia-l4t-kernel (4.9.253-tegra-32.6.1-20210726122859) over (4.9.253-tegra-32.6.1-20210726122859) ...
Preparing to unpack .../nvidia-l4t-kernel-dtbs_4.9.253-tegra-32.6.1-20210726122859_arm64.deb ...
Unpacking nvidia-l4t-kernel-dtbs (4.9.253-tegra-32.6.1-20210726122859) over (4.9.253-tegra-32.6.1-20210726122859) ...
Preparing to unpack .../nvidia-l4t-kernel-headers_4.9.253-tegra-32.6.1-20210726122859_arm64.deb ...
Unpacking nvidia-l4t-kernel-headers (4.9.253-tegra-32.6.1-20210726122859) over (4.9.253-tegra-32.6.1-20210726122859) ...
Preparing to unpack .../nvidia-l4t-bootloader_32.6.1-20210726122859_arm64.deb ...
Unpacking nvidia-l4t-bootloader (32.6.1-20210726122859) over (32.6.1-20210726122859) ...
Setting up jetson-gpio-common (2.0.17) ...
Setting up python3-jetson-gpio (2.0.17) ...
Setting up python-jetson-gpio (2.0.17) ...
Setting up nvidia-l4t-apt-source (32.6.1-20210726122859) ...
Pre-installing... skip changing source list.
Setting up nvidia-l4t-configs (32.6.1-20210726122859) ...
Setting up nvidia-l4t-firmware (32.6.1-20210726122859) ...
Setting up nvidia-l4t-gputools (32.6.1-20210726122859) ...
Setting up nvidia-l4t-init (32.6.1-20210726122859) ...
Setting up nvidia-l4t-libvulkan (32.6.1-20210726122859) ...
Setting up nvidia-l4t-multimedia-utils (32.6.1-20210726122859) ...
Setting up nvidia-l4t-oem-config (32.6.1-20210726122859) ...
Setting up nvidia-l4t-tools (32.6.1-20210726122859) ...
Setting up nvidia-l4t-wayland (32.6.1-20210726122859) ...
Setting up nvidia-l4t-weston (32.6.1-20210726122859) ...
Setting up nvidia-l4t-x11 (32.6.1-20210726122859) ...
Setting up nvidia-l4t-xusb-firmware (32.6.1-20210726122859) ...
Pre-installing xusb firmware package, skip flashing
Setting up nvidia-l4t-kernel (4.9.253-tegra-32.6.1-20210726122859) ...
Using the existing boot entry 'primary'
Pre-installing kernel package, skip flashing
Setting up nvidia-l4t-kernel-dtbs (4.9.253-tegra-32.6.1-20210726122859) ...
Pre-installing kernel-dtbs package, skip flashing
Setting up nvidia-l4t-kernel-headers (4.9.253-tegra-32.6.1-20210726122859) ...
Setting up nvidia-l4t-bootloader (32.6.1-20210726122859) ...
Pre-installing bootloader package, skip flashing
Setting up nvidia-l4t-3d-core (32.6.1-20210726122859) ...
Setting up nvidia-l4t-cuda (32.6.1-20210726122859) ...
Setting up nvidia-l4t-graphics-demos (32.6.1-20210726122859) ...
Setting up nvidia-l4t-initrd (32.6.1-20210726122859) ...
Pre-installing initrd package, skip flashing
Setting up nvidia-l4t-jetson-io (32.6.1-20210726122859) ...
Setting up nvidia-l4t-multimedia (32.6.1-20210726122859) ...
Setting up nvidia-l4t-camera (32.6.1-20210726122859) ...
Setting up nvidia-l4t-gstreamer (32.6.1-20210726122859) ...
Processing triggers for nvidia-l4t-kernel (4.9.253-tegra-32.6.1-20210726122859) ...
Processing triggers for libc-bin (2.27-3ubuntu1.4) ...
~/Work/Linux_for_Tegra
Removing QEMU binary from rootfs
Removing stashed Debian packages from rootfs
L4T BSP package installation completed!
Rename ubuntu.desktop --> ux-ubuntu.desktop
Disabling NetworkManager-wait-online.service
Disable the ondemand service by changing the runlevels to 'K'
Success!

8、编译bootloader

1. Extract the CBoot-standalone source with the command:
   mkdir cboot
   tar -xjf cboot_src_t194.tbz2 -C cboot
   cd cboot

2. Export the cross compiler tools with the following enviroment variables:
   export CROSS_COMPILE=<your_64-bit_ARM_toolchain_triple>

   Where: <your_64-bit_ARM_toolchain_triple> can be: 'aarch64-linux-gnu-'

3. Set the TEGRA_TOP and TOP environment variables:
   export TEGRA_TOP=$PWD
   export TOP=$PWD

4. Build the T194 CBoot binary, lk.bin, with the command:
   make -C ./bootloader/partner/t18x/cboot PROJECT=t194 TOOLCHAIN_PREFIX="${CROSS_COMPILE}" DEBUG=2 BUILDROOT="${PWD}"/out NV_TARGET_BOARD=t194ref NV_BUILD_SYSTEM_TYPE=l4t NOECHO=@

   The binary is located at: './out/build-t194/...':

   cboot/out/build-t194/lk.bin

5. Rename the binary lk.bin to cboot_t194.bin to use with the Jetson Xavier (T194)
   Linux for Tegra Board Support Package.

   This CBoot binary replaces the one provided at: Linux_for_Tegra/bootloader/cboot_t194.bin.

9、打包镜像


sudo ./flash.sh --no-flash jetson-xavier-as-8gb mmcblk0p1

10、刷机脚本

系统镜像生成并升级(把机器中的所有内容擦除并刷机,重新制作system.img)
$sudo ./flash.sh jetson-xavier mmcblk0p1 

系统完整升级但不生成system.img镜像(把机器中的所有内容擦除并刷机)
$sudo ./flash.sh -r jetson-xavier mmcblk0p1 

更新DTB 设备树(涉及外设驱动)
将新的DTB文件"tegra194-p2888-0001-p2822-0000.dtb"复制到目录Linux_for_Tegra/kernel/dtb
$sudo ./flash.sh -r -k kernel-dtb jetson-xavier mmcblk0p1

更新内核镜像(kernel/Image 涉及外设驱动)
Xavier检索内核先判断根目录下/boot/Image 文件,此时只需要把新的内核Image文件复制到 Xavier开机后的/boot/ 目录后再重启即可,通过uname -a 查看内核信息如日期时间是否为更新的内核
$sudo ./flash.sh -r -k kernel jetson-xavier mmcblk0p1

系统备份(备份Xavier机器中的系统及全部文件至当前目录的backup.img)
$sudo ./flash.sh -r -k APP -G backup.img jetson-xavier mmcblk0p1
如何恢复使用备份的镜像:
1、上面步骤备份会生出两个文件,把其中的backup.img.raw 重新命名到bootloader/system.img(软件镜像包含用户空间的所有文件信息),backup.img 文件不被使用可以删除掉
2、运行命令重新升级机器:
$sudo ./flash.sh -r jetson-xavier mmcblk0p1 

  • 1
    点赞
  • 23
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值