nvidia系列教程-AGX-Orin linux源码下载编译

目录

前言

一、准备工作

二、源码下载

三、源码编译配置

总结


前言

NVIDIA AGX Orin 是一款高性能的嵌入式计算平台,广泛应用于人工智能、自动驾驶、机器人等领域。为 AGX Orin 编译定制的 Linux 内核,可以更好地适应特定应用需求,增强系统的灵活性。本文将详细介绍如何下载、配置和编译适用于 AGX Orin 的 Linux 内核源码。


一、准备工作

在开始之前,确保您的开发环境满足以下要求:

  1. 开发主机:一台运行 Ubuntu 18.04 或 20.04 的 x86_64 主机。
  2. 交叉编译工具链:NVIDIA 提供的适用于 AGX Orin 的交叉编译工具链:/opt/nvidia-toolchain-gcc-9.3
  3. AGX-Orin模组。

二、源码下载

在nvidia官网下载jetson Linux源码,下载网址为:Jetson Linux | NVIDIA Developer,下载BSP源码文件以及交叉工具链,如下所示:

  • 交叉工具链:
  • 源码:下载源码文件为public_sources.tbz2,使用

    复制代码
    tar -xjf public_sources.tbz2解压得到Linux_for_Tegra目录,源码文件在这个目录下:

进入Linux_for_Tegra/source/public目录可以看到所有源码文件,如下所示:

cpp 复制代码
cftc@cftc-virtual-machine:~/nvidia/source/Linux_for_Tegra/source/public$ ls -l
total 194048
-rw-r--r-- 1 cftc cftc      9353 2月  20 12:38 argus_cam_libavencoder_src.tbz2
-rw-r--r-- 1 cftc cftc       118 2月  20 12:38 argus_cam_libavencoder_src.tbz2.sha1sum
drwxrwxr-x 3 cftc cftc      4096 7月  16 17:07 atf_build
-rw-r--r-- 1 cftc cftc   5555212 2月  20 12:38 atf_src.tbz2
-rw-r--r-- 1 cftc cftc        99 2月  20 12:38 atf_src.tbz2.sha1sum
-rw-r--r-- 1 cftc cftc    137992 2月  20 12:38 dtc-1.4.5.tbz2
-rw-r--r-- 1 cftc cftc       101 2月  20 12:38 dtc-1.4.5.tbz2.sha1sum
-rw-r--r-- 1 cftc cftc    115445 2月  20 12:38 FreeRTOSV8.1.2_src.tbz2
-rw-r--r-- 1 cftc cftc       110 2月  20 12:38 FreeRTOSV8.1.2_src.tbz2.sha1sum
-rw-r--r-- 1 cftc cftc     48181 2月  20 12:38 gstegl_src.tbz2
-rw-r--r-- 1 cftc cftc       102 2月  20 12:38 gstegl_src.tbz2.sha1sum
-rw-r--r-- 1 cftc cftc   1413240 2月  20 12:38 gstjpeg_src.tbz2
-rw-r--r-- 1 cftc cftc       103 2月  20 12:38 gstjpeg_src.tbz2.sha1sum
-rw-r--r-- 1 cftc cftc    636651 2月  20 12:38 gst-nvarguscamera_src.tbz2
-rw-r--r-- 1 cftc cftc       113 2月  20 12:38 gst-nvarguscamera_src.tbz2.sha1sum
-rw-r--r-- 1 cftc cftc    619692 2月  20 12:38 gst-nvcompositor_src.tbz2
-rw-r--r-- 1 cftc cftc       112 2月  20 12:38 gst-nvcompositor_src.tbz2.sha1sum
-rw-r--r-- 1 cftc cftc    610662 2月  20 12:38 gst-nvtee_src.tbz2
-rw-r--r-- 1 cftc cftc       105 2月  20 12:38 gst-nvtee_src.tbz2.sha1sum
-rw-r--r-- 1 cftc cftc    616957 2月  20 12:38 gst-nvv4l2camera_src.tbz2
-rw-r--r-- 1 cftc cftc       112 2月  20 12:38 gst-nvv4l2camera_src.tbz2.sha1sum
-rw-r--r-- 1 cftc cftc    636526 2月  20 12:38 gst-nvvidconv_src.tbz2
-rw-r--r-- 1 cftc cftc       109 2月  20 12:38 gst-nvvidconv_src.tbz2.sha1sum
-rw-r--r-- 1 cftc cftc    159721 2月  20 12:38 gst-nvvideo4linux2_src.tbz2
-rw-r--r-- 1 cftc cftc       114 2月  20 12:38 gst-nvvideo4linux2_src.tbz2.sha1sum
drwxrwxr-x 3 cftc cftc      4096 7月  12 15:26 hardware
drwxrwxr-x 5 cftc cftc      4096 8月   1 14:31 kernel
-rw-r--r-- 1 cftc cftc 170607524 2月  20 12:38 kernel_src.tbz2
-rw-r--r-- 1 cftc cftc       102 2月  20 12:38 kernel_src.tbz2.sha1sum
-rw-r--r-- 1 cftc cftc      4389 2月  20 12:38 libgstnvcustomhelper_src.tbz2
-rw-r--r-- 1 cftc cftc       116 2月  20 12:38 libgstnvcustomhelper_src.tbz2.sha1sum
-rw-r--r-- 1 cftc cftc     15390 2月  20 12:38 libgstnvdrmvideosink_src.tbz2
-rw-r--r-- 1 cftc cftc       116 2月  20 12:38 libgstnvdrmvideosink_src.tbz2.sha1sum
-rw-r--r-- 1 cftc cftc     26351 2月  20 12:38 libgstnvvideosinks_src.tbz2
-rw-r--r-- 1 cftc cftc       114 2月  20 12:38 libgstnvvideosinks_src.tbz2.sha1sum
-rw-r--r-- 1 cftc cftc    777927 2月  20 12:38 libnl-3.5.0.tbz2
-rw-r--r-- 1 cftc cftc       103 2月  20 12:38 libnl-3.5.0.tbz2.sha1sum
-rw-r--r-- 1 cftc cftc     24095 2月  20 12:38 libv4l2_nvargus_src.tbz2
-rw-r--r-- 1 cftc cftc       111 2月  20 12:38 libv4l2_nvargus_src.tbz2.sha1sum
-rw-r--r-- 1 cftc cftc     55037 2月  20 12:38 nvgstapps_src.tbz2
-rw-r--r-- 1 cftc cftc       105 2月  20 12:38 nvgstapps_src.tbz2.sha1sum
-rw-r--r-- 1 cftc cftc   9449948 2月  20 12:38 nvidia-jetson-optee-source.tbz2
-rw-r--r-- 1 cftc cftc       118 2月  20 12:38 nvidia-jetson-optee-source.tbz2.sha1sum
-rw-r--r-- 1 cftc cftc   2280241 2月  20 12:38 nvidia_kernel_display_driver_source.tbz2
-rw-r--r-- 1 cftc cftc       127 2月  20 12:38 nvidia_kernel_display_driver_source.tbz2.sha1sum
-rw-r--r-- 1 cftc cftc    110427 2月  20 12:38 nvidia-xconfig_src.tbz2
-rw-r--r-- 1 cftc cftc       110 2月  20 12:38 nvidia-xconfig_src.tbz2.sha1sum
-rwxr-xr-x 1 cftc cftc      2486 2月  20 12:38 nv_public_src_build.sh
-rwxr-xr-x 1 cftc cftc      4702 2月  20 12:38 nv_public_src_build_tos.sh
-rw-r--r-- 1 cftc cftc      7197 2月  20 12:38 nvsample_cudaprocess_src.tbz2
-rw-r--r-- 1 cftc cftc       116 2月  20 12:38 nvsample_cudaprocess_src.tbz2.sha1sum
-rw-r--r-- 1 cftc cftc     61154 2月  20 12:38 nvsci_headers.tbz2
-rw-r--r-- 1 cftc cftc       105 2月  20 12:38 nvsci_headers.tbz2.sha1sum
-rw-r--r-- 1 cftc cftc     34069 2月  20 12:38 nvsci_samples_src.tbz2
-rw-r--r-- 1 cftc cftc       109 2月  20 12:38 nvsci_samples_src.tbz2.sha1sum
-rw-r--r-- 1 cftc cftc      6475 2月  20 12:38 opencv_gst_samples_src.tbz2
-rw-r--r-- 1 cftc cftc       114 2月  20 12:38 opencv_gst_samples_src.tbz2.sha1sum
-rw-r--r-- 1 cftc cftc      6428 2月  20 12:38 openwfd_headers.tbz2
-rw-r--r-- 1 cftc cftc       107 2月  20 12:38 openwfd_headers.tbz2.sha1sum
-rw-r--r-- 1 cftc cftc     10800 2月  20 12:38 openwfd_samples.tbz2
-rw-r--r-- 1 cftc cftc       107 2月  20 12:38 openwfd_samples.tbz2.sha1sum
drwxrwxr-x 3 cftc cftc      4096 7月  16 16:49 optee
-rw-r--r-- 1 cftc cftc      4381 2月  20 12:38 public_sources_sha.txt
-rw-r--r-- 1 cftc cftc   4284913 2月  20 12:38 spe-freertos-bsp.tbz2
-rw-r--r-- 1 cftc cftc       108 2月  20 12:38 spe-freertos-bsp.tbz2.sha1sum
-rw-r--r-- 1 cftc cftc    163054 2月  20 12:38 v4l2_libs_src.tbz2
-rw-r--r-- 1 cftc cftc       105 2月  20 12:38 v4l2_libs_src.tbz2.sha1sum
cftc@cftc-virtual-machine:~/nvidia/source/Linux_for_Tegra/source/public$
  • 内核源码解压:使用

    复制代码
    tar –xjf kernel_src.tbz2解压内核源码得到kernel目录,目录结构如下所示:

三、源码编译配置

  • ubuntu虚拟机环境配置:
cpp 复制代码
sudo apt install build-essential bc
  • 交叉工具链配置:设置如下两个环境变量
cpp 复制代码
export CROSS_COMPILE_AARCH64_PATH=/opt/nvidia-toolchain-gcc-9.3
export CROSS_COMPILE_AARCH64=/opt/nvidia-toolchain-gcc-9.3/bin/aarch64-buildroot-linux-gnu-
  • 建立编译输出目录:
cpp 复制代码
mkdir kernel_out
  • 内核编译:
cpp 复制代码
./nvbuild.sh -o $PWD/kernel_out

其中nvbuild.sh为自动编译脚本,执行./nvbuild.sh -h可以查看编译帮助输出:

cpp 复制代码
cftc@cftc-virtual-machine:~/nvidia/source/Linux_for_Tegra/source/public/kernel$ ./nvbuild.sh -h
Usage: ./nvbuild.sh [OPTIONS]
This script builds kernel sources in this directory.
It supports following options.
OPTIONS:
        -h              Displays this help
        -o <outdir>     Creates kernel build output in <outdir>
cftc@cftc-virtual-machine:~/nvidia/source/Linux_for_Tegra/source/public/kernel$

-o 为指定内核编译输出目录,生成的编译输出文件全部在kernel_out目录下。

nvbuild.sh脚本内容如下所示:

cpp 复制代码
#!/bin/bash

# SPDX-FileCopyrightText: Copyright (c) 2019-2021 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-License-Identifier: BSD-3-Clause
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# 1. Redistributions of source code must retain the above copyright notice, this
# list of conditions and the following disclaimer.
#
# 2. Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
#
# 3. Neither the name of the copyright holder nor the names of its
# contributors may be used to endorse or promote products derived from
# this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

# This script builds kernel sources in this directory.
# Usage: ./${SCRIPT_NAME}.sh [OPTIONS]
set -e

# shellcheck disable=SC2046
SCRIPT_DIR="$(dirname $(readlink -f "${0}"))"
SCRIPT_NAME="$(basename "${0}")"

source "${SCRIPT_DIR}/nvcommon_build.sh"

function usage {
        cat <<EOM
Usage: ./${SCRIPT_NAME} [OPTIONS]
This script builds kernel sources in this directory.
It supports following options.
OPTIONS:
        -h              Displays this help
        -o <outdir>     Creates kernel build output in <outdir>
EOM
}

# parse input parameters
function parse_input_param {
        while [ $# -gt 0 ]; do
                case ${1} in
                        -h)
                                usage
                                exit 0
                                ;;
                        -o)
                                KERNEL_OUT_DIR="${2}"
                                shift 2
                                ;;
                        *)
                                echo "Error: Invalid option ${1}"
                                usage
                                exit 1
                                ;;
                        esac
        done
}

function build_arm64_kernel_sources {
        kernel_version="${1}"
        echo "Building kernel-${kernel_version} sources"

        # execute building steps
        source_dir="${SCRIPT_DIR}/kernel/kernel-${kernel_version}/"
        config_file="tegra_defconfig"
        tegra_kernel_out="${source_dir}"

        # shellcheck disable=SC2236
        if [ ! -z "${KERNEL_OUT_DIR}" ] ; then
                O_OPT=(O="${KERNEL_OUT_DIR}")
                tegra_kernel_out="${KERNEL_OUT_DIR}"
        else
                O_OPT=()
        fi

        "${MAKE_BIN}" -C "${source_dir}" ARCH=arm64 \
                LOCALVERSION="-tegra" \
                CROSS_COMPILE="${CROSS_COMPILE_AARCH64}" \
                "${O_OPT[@]}" "${config_file}"

        "${MAKE_BIN}" -C "${source_dir}" ARCH=arm64 \
                LOCALVERSION="-tegra" \
                CROSS_COMPILE="${CROSS_COMPILE_AARCH64}" \
                "${O_OPT[@]}" -j"${NPROC}" \
                --output-sync=target Image

        "${MAKE_BIN}" -C "${source_dir}" ARCH=arm64 \
                LOCALVERSION="-tegra" \
                CROSS_COMPILE="${CROSS_COMPILE_AARCH64}" \
                "${O_OPT[@]}" -j"${NPROC}" \
                --output-sync=target dtbs

        "${MAKE_BIN}" -C "${source_dir}" ARCH=arm64 \
                LOCALVERSION="-tegra" \
                CROSS_COMPILE="${CROSS_COMPILE_AARCH64}" \
                "${O_OPT[@]}" -j"${NPROC}" \
                --output-sync=target modules

        image="${tegra_kernel_out}/arch/arm64/boot/Image"
        if [ ! -f "${image}" ]; then
                echo "Error: Missing kernel image ${image}"
                exit 1
        fi
        echo "Kernel sources compiled successfully."
}

# shellcheck disable=SC2068
parse_input_param $@

# Compile kernel sources for "arm64"
build_arm64_kernel_sources "5.10"

通过脚本文件可以确认kernel配置文件为tegra_defconfig,我们可以根据自己需求修改内核配置文件,内核编译输出如下所示:

内核文件生成如下所示:

内核设备树文件生成如下所示:

生成的Image文件和设备树文件,可以直接替换至AGX-Orin文件系统/boot/Image,/boot/dtb/kernel_tegra234-p3701-0000-p3737-0000.dtb,重启即可生效。


总结

本文介绍了如何为 NVIDIA AGX Orin 平台下载、配置和编译定制的 Linux 内核源码。通过编译和部署定制内核,您可以更好地控制系统的行为,并根据特定应用需求进行优化。定期更新内核和设备树文件可以提高系统稳定性和兼容性。希望这篇教程能为您在开发和调试 AGX Orin 系统时提供帮助。。

相关推荐
TeYiToKu43 分钟前
笔记整理—linux驱动开发部分(9)framebuffer驱动框架
linux·c语言·arm开发·驱动开发·笔记·嵌入式硬件·arm
dsywws1 小时前
Linux学习笔记之时间日期和查找和解压缩指令
linux·笔记·学习
yeyuningzi1 小时前
Debian 12环境里部署nginx步骤记录
linux·运维·服务器
上辈子杀猪这辈子学IT1 小时前
【Zookeeper集群搭建】安装zookeeper、zookeeper集群配置、zookeeper启动与关闭、zookeeper的shell命令操作
linux·hadoop·zookeeper·centos·debian
minihuabei1 小时前
linux centos 安装redis
linux·redis·centos
lldhsds2 小时前
书生大模型实战营第四期-入门岛-1. Linux前置基础
linux
wowocpp3 小时前
ubuntu 22.04 硬件配置 查看 显卡
linux·运维·ubuntu
山河君3 小时前
ubuntu使用DeepSpeech进行语音识别(包含交叉编译)
linux·ubuntu·语音识别
鹏大师运维3 小时前
【功能介绍】信创终端系统上各WPS版本的授权差异
linux·wps·授权·麒麟·国产操作系统·1024程序员节·统信uos
筱源源3 小时前
Elasticsearch-linux环境部署
linux·elasticsearch