├── .github └── ISSUE_TEMPLATE │ └── bug_report.md ├── LICENSE ├── README.md ├── copyImage.sh ├── editConfig.sh ├── example └── build-module.sh ├── getKernelSources.sh ├── makeKernel.sh ├── makeModules.sh ├── removeAllKernelSources.sh └── scripts ├── copyImage.sh ├── getKernelSources.sh ├── jetson_variables ├── makeKernel.sh ├── makeModules.sh └── removeAllKernelSources.sh /.github/ISSUE_TEMPLATE/bug_report.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Issue report 3 | about: Create a report to help us improve 4 | title: "[BUG]" 5 | labels: bug 6 | assignees: '' 7 | 8 | --- 9 | 10 | **Describe the issue** 11 | Please describe the issue 12 | 13 | **Which version of Ubuntu on the Host machine** 14 | Ubuntu version: 15 | 16 | **What version of L4T/JetPack** 17 | L4T/JetPack version: 18 | 19 | **Which Jetson** 20 | Jetson: 21 | 22 | **To Reproduce** 23 | Steps to reproduce the behavior: 24 | For example, what command line did you run? 25 | 26 | **Expected behavior** 27 | A clear and concise description of what you expected to happen. 28 | 29 | **Additional context** 30 | Add any other context about the problem here. 31 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2016-2021 Jetsonhacks 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | 23 | ### For the jetson_variables script 24 | 25 | This file is part of the jetson_stats package (https://github.com/rbonghi/jetson_stats or http://rnext.it). 26 | # Copyright (c) 2020 Raffaello Bonghi. 27 | # 28 | # This program is free software: you can redistribute it and/or modify 29 | # it under the terms of the GNU Affero General Public License as published by 30 | # the Free Software Foundation, either version 3 of the License, or 31 | # (at your option) any later version. 32 | # 33 | # This program is distributed in the hope that it will be useful, 34 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 35 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 36 | # GNU Affero General Public License for more details. 37 | # 38 | # You should have received a copy of the GNU Affero General Public License 39 | # along with this program. If not, see . 40 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## jetson-linux-build 2 | Tools to build the Linux kernel and modules on board Jetson Developer Kits 3 | 4 | Note: Currently this is for JetPack versions 4 and earlier - Working on upgrading to JetPack 5 5 | 6 | This is a tool for meant for intermediate+ users. Please read this entire document before proceeding. 7 | 8 | This repository contains convenience scripts to: 9 | * Download Kernel and Module sources (**B**oard **S**upport **P**ackage - **BSP**) 10 | * Edit the kernel configuration 11 | * Build the kernel image 12 | * Build all of the kernel modules 13 | * Copy the Kernel Image to the /boot directory - This may not supported for newer versions of L4T - see below _**copyImage.sh deprecation (mostly)**_ 14 | * An example to build a single kernel module (most useful) 15 | 16 | ## Scripts 17 | 18 | ### getKernelSources.sh 19 | 20 | Downloads the kernel sources for L4T from the NVIDIA website and decompresses them into _/usr/src/_ . Note that this also sets the .config file to that of the current system, and sets the LOCALVERSION to the current local version, i.e., **-tegra** 21 | 22 | ### makeKernel.sh 23 | 24 | Please read the notes below about installing the kernel using copyImage.sh. Compiles the kernel using make. The script commands builds the kernel Image file. Installing the Image file on to the system is a separate step. 25 | 26 | This and other parts of the kernel build, such as building the device tree, may require that the result be 'signed' and flashed from the the NVIDIA tools on a host PC. 27 | 28 | ### makeModules.sh 29 | 30 | Compiles all of the the modules on the system using make and then installs them. You more than likely not want to do this. Instead, look at the script **build-module.sh** in the _example_ directory for an outline on how to build a single module. 31 | 32 | ### copyImage.sh 33 | 34 | Please read the notes below under _**Background Notes**_ about installing the kernel image. This script copies the Image file created by compiling the kernel to the _**/boot**_ directory. Note that while developing you will want to be more conservative than this: You will probably want to copy the new kernel Image to a different name in the boot directory, and modify _**/boot/extlinux/extlinux.conf**_ to have entry points at the old image, or the new image. This way, if things go sideways you can still boot the machine using the serial console. 35 | 36 | You will want to make a copy of the original Image before the copy, something like: 37 | ``` 38 | $ cp /boot/Image $INSTALL_DIR/Image.orig 39 | $ ./copyImage.sh 40 | $ echo "New Image created and placed in /boot" 41 | ``` 42 | ### editConfig.sh 43 | Edit the .config file located in _**/usr/src/kernel/kernel-4.9**_ This file must be present (from the getKernelSources.sh script) before launching the file. Note that if you change the local version, you will need to make both the kernel and modules and install them. 44 | 45 | ### removeAllKernelSources.sh 46 | 47 | Removes all of the kernel sources and compressed source files. You may want to make a backup of the files before deletion. 48 | 49 | ### Example - build-module.sh 50 | The most likely use for these scripts is to build kernel module(s). In the example folder, there is a script named _**build-module.sh**_ 51 | You should open the script, read through it, and modify to meet your needs. The script builds a module for the Logitech F710 game controller. The module name is **hid-logitech.ko** 52 | 53 | You will need to know the module flag to use this method, in this case it is: **LOGITECH_FF** 54 | 55 | 56 | ## Background Notes 57 | Over the years, we have been maintaining several different repositories here and on https://github.com/jetsonhacksnano to build the Linux kernel and modules for the various NVIDIA Jetson models: 58 | 59 | * Jetson Nano 60 | * Jetson Nano 2GB 61 | * Jetson TX1 62 | * Jetson TX2 63 | * Jetson AGX Xavier 64 | * Jetson Xavier NX 65 | 66 | The main difficulty of this approach is that there are several different repositories to maintain across NVIDIA L4T releases. 67 | 68 | There are two different versions of BSP source code for each NVIDIA L4T release. One version is for the Jetson Nano, Nano 2GB and TX1 named **T210**. The other version is for the Jetson TX2, AGX Xavier, and Xavier NX named **T186**. The only difference in building the kernel from machine to machine is where to download the BSP sources from for a given release. The idea of this repository is to place these URLs into an associative array to lookup given the L4T release version. 69 | 70 | The other procedures have remained the same over the years, except for placing items in the _**/boot**_ directory. The placement of the Linux kernel image, device tree and extlinux.conf may be different based on the Jetson model and L4T release. 71 | 72 | ### copyImage.sh deprecation (mostly) 73 | There has been an architectural shift on different Jetson models to provide better security. These changes are implemented differently on each model, depending on hardware capabilities and bootloaders of the Jetson module in question. Several system files, such as but not limited to the Linux kernel and device tree, may now be signed. 74 | 75 | For example, on the Jetson Xaviers the kernel is PKC Signed and has SBK encryption in the newer releases. Currently, the NVIDIA approved application to sign these files is an x86 app running on the host machine. 76 | 77 | Additionally, there are Jetsons which place the **/boot** folder into the onboard QSPI-NOR flash memory to be read at boot time, rather than reading it from the **APP** partition. Consequently the developer needs to know where/how to place a newly created kernel and support code. 78 | 79 | The copyImage.sh script may be helpful depending on the Jetson model and L4T release it is being used with. However, on some releases or Jetson models it may not work, or give a false sense of hope of actually doing something. 80 | 81 | ### So what good are these scripts? 82 | One thing that the scripts are useful for is building external kernel modules. People can build the modules on the device without having to go through the steps of setting up a development environment on the host, building the module, and transferring it to the Jetson. Instead, build the module on the Jetson and then install it. 83 | 84 | ## Release Notes 85 | 86 | Special thanks to Raffaello Bonghi (https://github.com/rbonghi) for jetson_variable script. 87 | 88 | ### November, 2022 89 | * Add L4T 35.0.1 90 | * Initial Orin support 91 | * Fix issue with Jetson Nano (t186) not working correctly 92 | 93 | ### June, 2022 94 | * Add L4T 32.7.1, L4T 32.7.2 95 | 96 | ### September, 2021 97 | * Initial Release 98 | * Unification of build methods across Jetson platform 99 | * Jetson Nano, Nano 2GB, TX1, TX2, AGX Xavier, Xavier NX 100 | * Associative lookup of BSP source code via L4T Release name 101 | * L4T Releases 32.4.2 through 32.6.1 102 | * Tested on Jetson Nano, Jetson Xavier NX 103 | -------------------------------------------------------------------------------- /copyImage.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # Copy the kernel image on NVIDIA Jetson Developer Kit 3 | # Copyright (c) 2016-21 Jetsonhacks 4 | # MIT License 5 | 6 | SOURCE_TARGET="/usr/src/" 7 | KERNEL_RELEASE=$( uname -r | cut -d. -f1-2) # e.g. 4.9 8 | export SOURCE_TARGET 9 | export KERNEL_RELEASE 10 | sudo -E ./scripts/copyImage.sh 11 | -------------------------------------------------------------------------------- /editConfig.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # Edit the kernel configuration for NVIDIA Jetson Developer Kit 3 | # Copyright (c) 2016-21 Jetsonhacks 4 | # MIT License 5 | 6 | SOURCE_TARGET="/usr/src" 7 | KERNEL_RELEASE=$( uname -r | cut -d. -f1-2) # e.g. 4.9 8 | 9 | function usage 10 | { 11 | echo "usage: ./editConfig.sh [[-d directory ] | [-h]]" 12 | echo "-d | --directory Directory path to parent of kernel" 13 | echo "-h | --help This message" 14 | } 15 | 16 | # Iterate through command line inputs 17 | while [ "$1" != "" ]; do 18 | case $1 in 19 | -d | --directory ) shift 20 | SOURCE_TARGET=$1 21 | ;; 22 | -h | --help ) usage 23 | exit 24 | ;; 25 | * ) usage 26 | exit 1 27 | esac 28 | shift 29 | done 30 | 31 | LAST="${SOURCE_TARGET: -1}" 32 | if [ $LAST != '/' ] ; then 33 | SOURCE_TARGET="$SOURCE_TARGET""/" 34 | fi 35 | 36 | # Check to see if source tree is already installed 37 | PROPOSED_SRC_PATH="$SOURCE_TARGET""kernel/kernel-"$KERNEL_RELEASE 38 | echo "Proposed source path: ""$PROPOSED_SRC_PATH" 39 | if [ ! -d "$PROPOSED_SRC_PATH" ]; then 40 | tput setaf 1 41 | echo "==== Cannot find kernel source! =============== " 42 | tput sgr0 43 | echo "The kernel source does not appear to be installed at: " 44 | echo " ""$PROPOSED_SRC_PATH" 45 | echo "Unable to edit kernel configuration." 46 | exit 1 47 | fi 48 | 49 | cd "$PROPOSED_SRC_PATH" 50 | sudo make menuconfig 51 | -------------------------------------------------------------------------------- /example/build-module.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # Example to build Logitech F710 module on NVIDIA Jetson Developer Kit 3 | # Copyright (c) 2016-21 Jetsonhacks 4 | # MIT License 5 | # build the hid-logitech.ko module with Logitech F710 support 6 | # We need the kernel sources installed 7 | 8 | SOURCE_TARGET="/usr/src/" 9 | KERNEL_RELEASE=$( uname -r | cut -d. -f1-2) 10 | KERNEL_URI=$SOURCE_TARGET"kernel/kernel-"$KERNEL_RELEASE 11 | if [ ! -d "$KERNEL_URI" ] ; then 12 | echo "Cannot find kernel source in $SOURCE_TARGET." 13 | echo "You will need to install the kernel source before proceeding." 14 | exit 1 15 | fi 16 | 17 | cd "$KERNEL_URI" 18 | 19 | sudo bash scripts/config --file .config \ 20 | --set-val LOGITECH_FF y 21 | sudo make modules_prepare 22 | sudo make drivers/hid/hid-logitech.ko 23 | 24 | echo "Build complete." 25 | echo "The module is here: ${KERNEL_URI}/drivers/hid/hid-logitech.ko" 26 | echo "To install the module:" 27 | echo " " 28 | 29 | INSTALL_DIRECTORY=/lib/modules/$(uname -r)/kernel/drivers/hid 30 | echo "$ sudo cp -v ${KERNEL_URI}/drivers/hid/hid-logitech.ko $INSTALL_DIRECTORY" 31 | echo "$ sudo depmod -a" 32 | 33 | echo "" 34 | echo "You may need to reboot for the changes to take effect." 35 | 36 | 37 | 38 | 39 | -------------------------------------------------------------------------------- /getKernelSources.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # Get the kernel source for NVIDIA Jetson Developer Kit 3 | # Copyright (c) 2016-21 Jetsonhacks 4 | # MIT License 5 | 6 | # Install the kernel source for L4T 7 | source scripts/jetson_variables 8 | 9 | #Print Jetson version 10 | echo "$JETSON_MACHINE" 11 | #Print Jetpack version 12 | echo "Jetpack $JETSON_JETPACK [L4T $JETSON_L4T]" 13 | SOURCE_TARGET="/usr/src/" 14 | KERNEL_RELEASE=$( uname -r | cut -d. -f1-2) # e.g. 4.9 15 | 16 | LAST="${SOURCE_TARGET: -1}" 17 | if [ $LAST != '/' ] ; then 18 | SOURCE_TARGET="$SOURCE_TARGET""/" 19 | fi 20 | 21 | echo "Kernel Release: $KERNEL_RELEASE" 22 | echo "Placing kernel source into $SOURCE_TARGET" 23 | 24 | # Check to see if source tree is already installed 25 | PROPOSED_SRC_PATH="$SOURCE_TARGET""kernel/kernel-"$KERNEL_RELEASE 26 | if [ -d "$PROPOSED_SRC_PATH" ]; then 27 | tput setaf 1 28 | echo "==== Kernel source appears to already be installed! =============== " 29 | tput sgr0 30 | echo "The kernel source appears to already be installed at: " 31 | echo " ""$PROPOSED_SRC_PATH" 32 | echo "If you want to reinstall the source files, first remove the directories: " 33 | echo " ""$SOURCE_TARGET""kernel" 34 | echo " ""$SOURCE_TARGET""hardware" 35 | echo "then rerun this script" 36 | exit 1 37 | fi 38 | 39 | export SOURCE_TARGET 40 | export KERNEL_RELEASE 41 | 42 | # -E preserves environment variables 43 | sudo -E ./scripts/getKernelSources.sh 44 | 45 | 46 | -------------------------------------------------------------------------------- /makeKernel.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # Make the kernel for NVIDIA Developer Kit 3 | # Copyright (c) 2016-21 Jetsonhacks 4 | # MIT License 5 | 6 | SOURCE_TARGET="/usr/src" 7 | KERNEL_RELEASE=$( uname -r | cut -d. -f1-2) # e.g. 4.9 8 | 9 | function usage 10 | { 11 | echo "usage: ./makeKernel.sh [[-d directory ] | [-h]]" 12 | echo "-d | --directory Directory path to parent of kernel" 13 | echo "-h | --help This message" 14 | } 15 | 16 | # Iterate through command line inputs 17 | while [ "$1" != "" ]; do 18 | case $1 in 19 | -d | --directory ) shift 20 | SOURCE_TARGET=$1 21 | ;; 22 | -h | --help ) usage 23 | exit 24 | ;; 25 | * ) usage 26 | exit 1 27 | esac 28 | shift 29 | done 30 | 31 | LAST="${SOURCE_TARGET: -1}" 32 | if [ $LAST != '/' ] ; then 33 | SOURCE_TARGET="$SOURCE_TARGET""/" 34 | fi 35 | 36 | # Check to see if source tree is already installed 37 | PROPOSED_SRC_PATH="$SOURCE_TARGET""kernel/kernel-"$KERNEL_RELEASE 38 | echo "Proposed source path: ""$PROPOSED_SRC_PATH" 39 | if [ ! -d "$PROPOSED_SRC_PATH" ]; then 40 | tput setaf 1 41 | echo "==== Cannot find kernel source! =============== " 42 | tput sgr0 43 | echo "The kernel source does not appear to be installed at: " 44 | echo " ""$PROPOSED_SRC_PATH" 45 | echo "Unable to start making kernel." 46 | exit 1 47 | fi 48 | 49 | export SOURCE_TARGET 50 | export KERNEL_RELEASE 51 | 52 | # E Option carries over environment variables 53 | sudo -E ./scripts/makeKernel.sh 54 | -------------------------------------------------------------------------------- /makeModules.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # Make kernel modules for NVIDIA Jetson Developer Kit 3 | # Copyright (c) 2016-21 Jetsonhacks 4 | # MIT License 5 | 6 | SOURCE_TARGET="/usr/src" 7 | KERNEL_RELEASE=$( uname -r | cut -d. -f1-2) # e.g. 4.9 8 | 9 | function usage 10 | { 11 | echo "usage: ./makeModules.sh [[-d directory ] | [-h]]" 12 | echo "-d | --directory Directory path to parent of kernel" 13 | echo "-h | --help This message" 14 | } 15 | 16 | # Iterate through command line inputs 17 | while [ "$1" != "" ]; do 18 | case $1 in 19 | -d | --directory ) shift 20 | SOURCE_TARGET=$1 21 | ;; 22 | -h | --help ) usage 23 | exit 24 | ;; 25 | * ) usage 26 | exit 1 27 | esac 28 | shift 29 | done 30 | 31 | LAST="${SOURCE_TARGET: -1}" 32 | if [ $LAST != '/' ] ; then 33 | SOURCE_TARGET="$SOURCE_TARGET""/" 34 | fi 35 | 36 | # Check to see if source tree is already installed 37 | PROPOSED_SRC_PATH="$SOURCE_TARGET""kernel/kernel-"$KERNEL_RELEASE 38 | echo "Proposed source path: ""$PROPOSED_SRC_PATH" 39 | if [ ! -d "$PROPOSED_SRC_PATH" ]; then 40 | tput setaf 1 41 | echo "==== Cannot find kernel source! =============== " 42 | tput sgr0 43 | echo "The kernel source does not appear to be installed at: " 44 | echo " ""$PROPOSED_SRC_PATH" 45 | echo "Unable to start making kernel." 46 | exit 1 47 | fi 48 | 49 | export SOURCE_TARGET 50 | export KERNEL_RELEASE 51 | 52 | # E Option carries over environment variables 53 | sudo -E ./scripts/makeModules.sh 54 | -------------------------------------------------------------------------------- /removeAllKernelSources.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # Remove the kernel sources and build remnants from the NVIDIA Developer Kit 3 | # This should reverse getKernelSources.sh 4 | # Copyright (c) 2016-21 Jetsonhacks 5 | # MIT License 6 | 7 | # Remove all of the kernel sources that were downloaded and built during the kernel build process 8 | # Note that this will also remove the possibly changed .config file in: 9 | # /usr/src/kernel/kernel-4.9 10 | 11 | SOURCE_TARGET="/usr/src/" 12 | KERNEL_RELEASE=$( uname -r | cut -d. -f1-2) # e.g. 4.9 13 | 14 | echo "Removing All Kernel Sources" 15 | export SOURCE_TARGET 16 | export KERNEL_RELEASE 17 | sudo -E ./scripts/removeAllKernelSources.sh 18 | echo "Kernel sources removed" 19 | -------------------------------------------------------------------------------- /scripts/copyImage.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # Copy the kernel image on NVIDIA Jetson Developer Kit 3 | # Copyright (c) 2016-21 Jetsonhacks 4 | # MIT License 5 | 6 | cd ${SOURCE_TARGET}kernel/kernel-${KERNEL_RELEASE} 7 | # On the stock Jetsoninstall, there is no zImage in the boot directory 8 | # So we just copy the Image file over 9 | # If the zImage is needed, you must either 10 | # $ make zImage 11 | # or 12 | # $ make 13 | # Both of these commands must be executed in /usr/src/kernel/kernel-4.9 14 | # sudo cp arch/arm64/boot/zImage /boot/zImage 15 | # Note that if you are compiling on an external device, like a SSD, you should probably 16 | # copy this over to the internal eMMC if that is where the Jetson boots 17 | sudo cp arch/arm64/boot/Image /boot/Image 18 | 19 | 20 | -------------------------------------------------------------------------------- /scripts/getKernelSources.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # Get the kernel source for NVIDIA Jetson Developer Kit 3 | # Copyright (c) 2016-21 Jetsonhacks 4 | # MIT License 5 | 6 | # Table of the URLs to Kernel Sources for Jetson Nano, Nano 2GB and TX1 7 | # L4T Driver Package [BSP] Sources - Code 210 8 | declare -A source_url_list_210=( 9 | 10 | ["32.7.4"]="https://developer.nvidia.com/embedded/l4t/r32_release_v7.4/sources/t210/public_sources.tbz2" 11 | ["32.7.3"]="https://developer.nvidia.com/downloads/remack-sdksjetpack-463r32releasev73sourcest210publicsourcestbz2" 12 | ["32.7.2"]="https://developer.nvidia.com/embedded/l4t/r32_release_v7.2/sources/t210/public_sources.tbz2" 13 | ["32.7.1"]="https://developer.nvidia.com/embedded/l4t/r32_release_v7.1/sources/t210/public_sources.tbz2" 14 | ["32.6.1"]="https://developer.nvidia.com/embedded/l4t/r32_release_v6.1/sources/t210/public_sources.tbz2" 15 | ["32.5.2"]="https://developer.nvidia.com/embedded/l4t/r32_release_v5.2/sources/t210/public_sources.tbz2" 16 | ["32.5.1"]="https://developer.nvidia.com/embedded/l4t/r32_release_v5.1/r32_release_v5.1/sources/t210/public_sources.tbz2" 17 | ["32.5.0"]="https://developer.nvidia.com/embedded/L4T/r32_Release_v5.0/sources/T210/public_sources.tbz2" 18 | ["32.4.4"]="https://developer.nvidia.com/embedded/L4T/r32_Release_v4.4/r32_Release_v4.4-GMC3/Sources/T210/public_sources.tbz2" 19 | ["32.4.3"]="https://developer.nvidia.com/embedded/L4T/r32_Release_v4.3/Sources/T210/public_sources.tbz2" 20 | ["32.4.2"]="https://developer.nvidia.com/embedded/L4T/r32_Release_v4.2/Sources/T210/public_sources.tbz2" ) 21 | 22 | # Table of the URLs to Kernel Sources for Jetson TX2, AGX Xavier, Xavier NX, AGX Orin 23 | # L4T Driver Package [BSP] Sources - Code 186 24 | declare -A source_url_list_186=( 25 | ["36.3.0"]="https://developer.nvidia.com/downloads/embedded/l4t/r36_release_v3.0/sources/public_sources.tbz2" 26 | ["35.5.0"]="https://developer.nvidia.com/downloads/embedded/l4t/r35_release_v5.0/sources/public_sources.tbz2" 27 | ["35.4.1"]="https://developer.nvidia.com/downloads/embedded/l4t/r35_release_v4.1/sources/public_sources.tbz2" 28 | ["35.3.1"]="https://developer.nvidia.com/downloads/embedded/l4t/r35_release_v3.1/sources/public_sources.tbz2" 29 | ["35.2.1"]="https://developer.download.nvidia.com/embedded/L4T/r35_Release_v2.1/sources/public_sources.tbz2" 30 | ["35.1.0"]="https://developer.nvidia.com/embedded/l4t/r35_release_v1.0/sources/public_sources.tbz2" 31 | ["32.7.5"]="https://developer.nvidia.com/downloads/embedded/l4t/r32_release_v7.5/sources/t186/public_sources.tbz2" 32 | ["32.7.4"]="https://developer.nvidia.com/downloads/embedded/l4t/r32_release_v7.4/sources/t186/public_sources.tbz2" 33 | ["32.7.3"]="https://developer.nvidia.com/downloads/remack-sdksjetpack-463r32releasev73sourcest186publicsourcestbz2" 34 | ["32.7.2"]="https://developer.nvidia.com/embedded/l4t/r32_release_v7.2/sources/t186/public_sources.tbz2" 35 | ["32.7.1"]="https://developer.nvidia.com/embedded/l4t/r32_release_v7.1/sources/t186/public_sources.tbz2" 36 | ["32.6.1"]="https://developer.nvidia.com/embedded/l4t/r32_release_v6.1/sources/t186/public_sources.tbz2" 37 | ["32.5.2"]="https://developer.nvidia.com/embedded/l4t/r32_release_v5.2/sources/t186/public_sources.tbz2" 38 | ["32.5.1"]="https://developer.nvidia.com/embedded/l4t/r32_release_v5.1/r32_release_v5.1/sources/t186/public_sources.tbz2" 39 | ["32.5.0"]="https://developer.nvidia.com/embedded/L4T/r32_Release_v5.0/sources/T186/public_sources.tbz2" 40 | ["32.4.4"]="https://developer.nvidia.com/embedded/L4T/r32_Release_v4.4/r32_Release_v4.4-GMC3/Sources/T186/public_sources.tbz2" 41 | ["32.4.3"]="https://developer.nvidia.com/embedded/L4T/r32_Release_v4.3/Sources/T186/public_sources.tbz2" 42 | ["32.4.2"]="https://developer.nvidia.com/embedded/L4T/r32_Release_v4.2/Sources/T186/public_sources.tbz2" ) 43 | 44 | # Get the Board ID ; must be t210ref or t186 ref 45 | BOARD_ID="" 46 | if [ -f /etc/nv_tegra_release ]; then 47 | # L4T string 48 | # First line of /etc/nv_tegra_release e.g: 49 | # - "# R28 (release), REVISION: 2.1, GCID: 11272647, BOARD: t186ref, EABI: aarch64, DATE: Thu May 17 07:29:06 UTC 2018" 50 | TEGRA_RELEASE=$(head -n 1 /etc/nv_tegra_release) 51 | BOARD="BOARD: " 52 | BOARD_ID=${TEGRA_RELEASE##*$BOARD} 53 | BOARD_ID=${BOARD_ID%%$","*} 54 | else 55 | # There were a couple of releases where /etc/nv_tegra_release was not present 56 | # Need to figure it out from the CHIP ID 57 | case $JETSON_CHIP_ID in 58 | 33 ) # Jetson Nano, Nano 2GB, TX1 ; 0x21 59 | BOARD_ID="t210ref" 60 | ;; 61 | 24 ) # Jetson TX2 ; 0x18 62 | BOARD_ID="t186ref" 63 | ;; 64 | 25 ) # Jetson Xavier NX, AGX Xavier ; 0x19 65 | BOARD_ID="t186ref" 66 | ;; 67 | *) # Unknown board 68 | echo "Unrecognized board" 69 | esac 70 | fi 71 | 72 | if [ "$BOARD_ID" = "" ] ; then 73 | echo "Unrecongized board" 74 | exit 1 75 | fi 76 | 77 | SOURCE_URL="" 78 | case ${BOARD_ID} in 79 | "t186ref" ) 80 | SOURCE_URL=${source_url_list_186[$JETSON_L4T]} 81 | ;; 82 | "t210ref" ) 83 | SOURCE_URL=${source_url_list_210[$JETSON_L4T]} 84 | ;; 85 | *) 86 | echo "Unrecognized board id: '$BOARD_ID'" 87 | exit 1 88 | esac 89 | 90 | if [ "$SOURCE_URL" = "" ] ; then 91 | echo "Unable to find source files on developer.nvidia.com" 92 | echo "L4T $JETSON_L4T" 93 | exit 1 94 | fi 95 | 96 | apt-add-repository universe 97 | apt-get update 98 | apt-get install pkg-config -y 99 | # We use 'make menuconfig' to edit the .config file; install dependencies 100 | apt-get install libncurses5-dev -y 101 | 102 | # A release version is typically something like: 4.9.253-tegra 103 | # We gather the local version (anything after the release numbers, starting with the '-') to 104 | # set the local version for the kernel build process. 105 | KERNEL_VERSION=$(uname -r) 106 | LOCAL_VERSION="-$(echo ${KERNEL_VERSION} | cut -d "-" -f2-)" 107 | 108 | # Build the symvers module address 109 | # Example: /usr/src/linux-headers-4.9.253-tegra-ubuntu18.04_aarch64/kernel-4.9/Module.symvers 110 | 111 | # Distribution 112 | DISTRIBUTION=$(lsb_release -is) 113 | # Needs to be lower case 114 | DISTRIBUTION="$(echo $DISTRIBUTION | tr '[A-Z]' '[a-z]')" 115 | OS_RELEASE=$(lsb_release -rs) 116 | MODULE_SYMVERS_URL=${SOURCE_TARGET}"linux-headers-"${KERNEL_VERSION}-${DISTRIBUTION}${OS_RELEASE}_$(uname -m)/kernel-${KERNEL_RELEASE}/Module.symvers 117 | 118 | echo $MODULE_SYMVERS_URL 119 | 120 | 121 | cd "$SOURCE_TARGET" 122 | echo "$PWD" 123 | # L4T Driver Package (BSP) Sources 124 | wget -N "$SOURCE_URL" -O public_sources.tbz2 125 | 126 | # l4t-sources is a tbz2 file 127 | tar -xvf public_sources.tbz2 Linux_for_Tegra/source/public/kernel_src.tbz2 --strip-components=3 128 | tar -xvf kernel_src.tbz2 129 | # Space is tight; get rid of the compressed kernel source 130 | rm -r kernel_src.tbz2 131 | cd kernel/kernel-"$KERNEL_RELEASE" 132 | echo "$PWD" 133 | 134 | # Copy over the module symbols 135 | # These should be part of the default rootfs 136 | # When the kernel itself is compiled, it should generate its own Module.symvers and place it here 137 | cp "$MODULE_SYMVERS_URL" . 138 | # Go get the current kernel config file; this becomes the base system configuration 139 | zcat /proc/config.gz > .config 140 | # Make a backup of the original configuration 141 | cp .config config.orig 142 | # Default to the current local version 143 | # Should be "-tegra" 144 | bash scripts/config --file .config \ 145 | --set-str LOCALVERSION $LOCAL_VERSION 146 | 147 | 148 | 149 | 150 | 151 | -------------------------------------------------------------------------------- /scripts/jetson_variables: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # This file is part of the jetson_stats package (https://github.com/rbonghi/jetson_stats or http://rnext.it). 3 | # Copyright (c) 2020 Raffaello Bonghi. 4 | # 5 | # This program is free software: you can redistribute it and/or modify 6 | # it under the terms of the GNU Affero General Public License as published by 7 | # the Free Software Foundation, either version 3 of the License, or 8 | # (at your option) any later version. 9 | # 10 | # This program is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | # GNU Affero General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU Affero General Public License 16 | # along with this program. If not, see . 17 | 18 | 19 | # TODO Add enviroments variables: 20 | # - UID -> https://devtalk.nvidia.com/default/topic/996988/jetson-tk1/chip-uid/post/5100481/#5100481 21 | # - GCID, BOARD, EABI 22 | 23 | ########################### 24 | #### JETPACK DETECTION #### 25 | ########################### 26 | # Write version of jetpack installed 27 | # https://developer.nvidia.com/embedded/jetpack-archive 28 | jetson_jetpack() 29 | { 30 | local JETSON_L4T=$1 31 | local JETSON_JETPACK="" 32 | case $JETSON_L4T in 33 | "36.3.0") JETSON_JETPACK="6.0" ;; 34 | "35.5.0") JETSON_JETPACK="5.1.3" ;; 35 | "35.4.1") JETSON_JETPACK="5.1.2" ;; 36 | "35.3.1") JETSON_JETPACK="5.1.1" ;; 37 | "35.2.1") JETSON_JETPACK="5.1" ;; 38 | "35.1.0") JETSON_JETPACK="5.0.2" ;; 39 | "34.1.1") JETSON_JETPACK="5.0.1 DP" ;; 40 | "34.1.0") JETSON_JETPACK="5.0 DP" ;; 41 | "32.7.4") JETSON_JETPACK="4.6.4" ;; 42 | "32.7.3") JETSON_JETPACK="4.6.3" ;; 43 | "32.7.2") JETSON_JETPACK="4.6.2" ;; 44 | "32.7.1") JETSON_JETPACK="4.6.1" ;; 45 | "32.6.1") JETSON_JETPACK="4.6" ;; 46 | "32.5.1" | "32.5.2") JETSON_JETPACK="4.5.1" ;; 47 | "32.5.0" | "32.5") JETSON_JETPACK="4.5" ;; 48 | "32.4.4") JETSON_JETPACK="4.4.1" ;; 49 | "32.4.3") JETSON_JETPACK="4.4" ;; 50 | "32.4.2") JETSON_JETPACK="4.4 DP" ;; 51 | "32.3.1") JETSON_JETPACK="4.3" ;; 52 | "32.2.3") JETSON_JETPACK="4.2.3" ;; 53 | "32.2.1") JETSON_JETPACK="4.2.2" ;; 54 | "32.2.0" | "32.2") JETSON_JETPACK="4.2.1" ;; 55 | "32.1.0" | "32.1") JETSON_JETPACK="4.2" ;; 56 | "31.1.0" | "31.1") JETSON_JETPACK="4.1.1" ;; 57 | "31.0.2") JETSON_JETPACK="4.1" ;; 58 | "31.0.1") JETSON_JETPACK="4.0" ;; 59 | "28.4.0") JETSON_JETPACK="3.3.3" ;; 60 | "28.2.1") JETSON_JETPACK="3.3 | 3.2.1" ;; 61 | "28.2.0" | "28.2") JETSON_JETPACK="3.2" ;; 62 | "28.1.0" | "28.1") JETSON_JETPACK="3.1" ;; 63 | "27.1.0" | "27.1") JETSON_JETPACK="3.0" ;; 64 | "24.2.1") JETSON_JETPACK="3.0 | 2.3.1" ;; 65 | "24.2.0" | "24.2") JETSON_JETPACK="2.3" ;; 66 | "24.1.0" | "24.1") JETSON_JETPACK="2.2.1 | 2.2" ;; 67 | "23.2.0" | "23.2") JETSON_JETPACK="2.1" ;; 68 | "23.1.0" | "23.1") JETSON_JETPACK="2.0" ;; 69 | "21.5.0" | "21.5") JETSON_JETPACK="2.3.1 | 2.3" ;; 70 | "21.4.0" | "21.4") JETSON_JETPACK="2.2 | 2.1 | 2.0 | 1.2 DP" ;; 71 | "21.3.0" | "21.3") JETSON_JETPACK="1.1 DP" ;; 72 | "21.2.0" | "21.2") JETSON_JETPACK="1.0 DP" ;; 73 | *) JETSON_JETPACK="UNKNOWN" ;; 74 | esac 75 | # return type jetpack 76 | echo $JETSON_JETPACK 77 | } 78 | ########################### 79 | 80 | JETSON_MODEL="UNKNOWN" 81 | # Extract jetson model name 82 | if [ -f /sys/firmware/devicetree/base/model ]; then 83 | JETSON_MODEL=$(tr -d '\0' < /sys/firmware/devicetree/base/model) 84 | fi 85 | 86 | # Extract jetson chip id 87 | JETSON_CHIP_ID="" 88 | if [ -f /sys/module/tegra_fuse/parameters/tegra_chip_id ]; then 89 | JETSON_CHIP_ID=$(cat /sys/module/tegra_fuse/parameters/tegra_chip_id) 90 | fi 91 | # Ectract type board 92 | JETSON_SOC="" 93 | if [ -f /proc/device-tree/compatible ]; then 94 | # Extract the last part of name 95 | JETSON_SOC=$(tr -d '\0' < /proc/device-tree/compatible | sed -e 's/.*,//') 96 | fi 97 | # Extract boardids if exists 98 | JETSON_BOARDIDS="" 99 | if [ -f /proc/device-tree/nvidia,boardids ]; then 100 | JETSON_BOARDIDS=$(tr -d '\0' < /proc/device-tree/nvidia,boardids) 101 | fi 102 | 103 | # Code name 104 | JETSON_CODENAME="" 105 | JETSON_MODULE="UNKNOWN" 106 | JETSON_CARRIER="UNKNOWN" 107 | list_hw_boards() 108 | { 109 | # Extract from DTS the name of the boards available 110 | # Reference: 111 | # 1. https://unix.stackexchange.com/questions/251013/bash-regex-capture-group 112 | # 2. https://unix.stackexchange.com/questions/144298/delete-the-last-character-of-a-string-using-string-manipulation-in-shell-script 113 | local s=$1 114 | local regex='p([0-9-]+)' # Equivalent to p([\d-]*-) 115 | while [[ $s =~ $regex ]]; do 116 | local board_name=$(echo "P${BASH_REMATCH[1]}" | sed 's/-*$//' ) 117 | # Load jetson type 118 | # If jetson type is not empty the module name is the same 119 | if [ $JETSON_MODULE = "UNKNOWN" ] ; then 120 | JETSON_MODULE=$board_name 121 | echo "JETSON_MODULE=\"$JETSON_MODULE\"" 122 | else 123 | JETSON_CARRIER=$board_name 124 | echo "JETSON_CARRIER=\"$JETSON_CARRIER\"" 125 | fi 126 | # Find next match 127 | s=${s#*"${BASH_REMATCH[1]}"} 128 | done 129 | } 130 | # Read DTS file 131 | # 1. https://devtalk.nvidia.com/default/topic/1071080/jetson-nano/best-way-to-check-which-tegra-board/ 132 | # 2. https://devtalk.nvidia.com/default/topic/1014424/jetson-tx2/identifying-tx1-and-tx2-at-runtime/ 133 | # 3. https://devtalk.nvidia.com/default/topic/996988/jetson-tk1/chip-uid/post/5100481/#5100481 134 | if [ -f /proc/device-tree/nvidia,dtsfilename ]; then 135 | # ../hardware/nvidia/platform/t210/porg/kernel-dts/tegra210-p3448-0000-p3449-0000-b00.dts 136 | # The last third is the codename of the board 137 | JETSON_CODENAME=$(tr -d '\0' < /proc/device-tree/nvidia,dtsfilename) 138 | JETSON_CODENAME=$(echo ${JETSON_CODENAME#*"/hardware/nvidia/platform/"} | tr '/' '\n' | head -2 | tail -1 ) 139 | # The basename extract the board type 140 | JETSON_DTS="$(tr -d '\0' < /proc/device-tree/nvidia,dtsfilename | sed 's/.*\///')" 141 | # List of all boards 142 | eval $(list_hw_boards "$JETSON_DTS") 143 | fi 144 | 145 | # Export variables 146 | export JETSON_MODEL 147 | export JETSON_CHIP_ID 148 | export JETSON_SOC 149 | export JETSON_BOARDIDS 150 | export JETSON_CODENAME 151 | export JETSON_MODULE 152 | export JETSON_CARRIER 153 | 154 | # Write CUDA architecture 155 | # https://developer.nvidia.com/cuda-gpus 156 | # https://devtalk.nvidia.com/default/topic/988317/jetson-tx1/what-should-be-the-value-of-cuda_arch_bin/ 157 | case $JETSON_MODEL in 158 | *Orin*) JETSON_CUDA_ARCH_BIN="8.7" ;; 159 | *Xavier*) JETSON_CUDA_ARCH_BIN="7.2" ;; 160 | *TX2*) JETSON_CUDA_ARCH_BIN="6.2" ;; 161 | *TX1* | *Nano*) JETSON_CUDA_ARCH_BIN="5.3" ;; 162 | *TK1*) JETSON_CUDA_ARCH_BIN="3.2" ;; 163 | * ) JETSON_CUDA_ARCH_BIN="NONE" ;; 164 | esac 165 | # Export Jetson CUDA ARCHITECTURE 166 | export JETSON_CUDA_ARCH_BIN 167 | 168 | # Serial number 169 | # https://devtalk.nvidia.com/default/topic/1055507/jetson-nano/nano-serial-number-/ 170 | JETSON_SERIAL_NUMBER="" 171 | if [ -f /sys/firmware/devicetree/base/serial-number ]; then 172 | JETSON_SERIAL_NUMBER=$(tr -d '\0' &2 27 | echo "Retrying ... " 28 | # Single thread this time 29 | make Image 30 | if [ $? -eq 0 ] ; then 31 | echo "Image make successful" 32 | echo "Image file is here: " 33 | echo "$SOURCE_TARGET""kernel/kernel-"$KERNEL_RELEASE"/arch/arm64/boot/Image" 34 | else 35 | # Try to make again 36 | echo "Make did not successfully build" >&2 37 | echo "Please fix issues and retry build" 38 | exit 1 39 | fi 40 | fi 41 | 42 | 43 | -------------------------------------------------------------------------------- /scripts/makeModules.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # Builds modules and installs them 3 | # Assumes that the .config file is available in /proc/config.gz 4 | # Added check to see if make builds correctly; retry once if not 5 | 6 | echo "Source Target: "$SOURCE_TARGET 7 | 8 | cd $SOURCE_TARGET"kernel/kernel-"$KERNEL_RELEASE 9 | 10 | # Get the number of CPUs 11 | NUM_CPU=$(nproc) 12 | 13 | # Make the kernel Image 14 | time make -j$(($NUM_CPU - 1)) modules 15 | if [ $? -eq 0 ] ; then 16 | echo "Modules make successful" 17 | else 18 | # Try to make again; Sometimes there are issues with the build 19 | # because of lack of resources or concurrency issues 20 | echo "Make did not build " >&2 21 | echo "Retrying ... " 22 | # Single thread this time 23 | make modules 24 | if [ $? -eq 0 ] ; then 25 | echo "Module make successful" 26 | else 27 | # Try to make again 28 | echo "Make did not successfully build modules" >&2 29 | echo "Please fix issues and retry build" 30 | exit 1 31 | fi 32 | fi 33 | 34 | make modules_install 35 | 36 | 37 | -------------------------------------------------------------------------------- /scripts/removeAllKernelSources.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # Remove the kernel sources and build remnants from the NVIDIA Developer Kit 3 | # This should reverse getKernelSources.sh 4 | # Copyright (c) 2016-21 Jetsonhacks 5 | # MIT License 6 | 7 | cd ${SOURCE_TARGET} 8 | rm -r kernel 9 | rm -r hardware 10 | rm nvbuild.sh 11 | rm nvcommon_build.sh 12 | rm public_sources.tbz2 13 | 14 | --------------------------------------------------------------------------------