|
1 | 1 | #!/bin/bash
|
2 |
| -# Install the kernel source for L4T |
3 |
| -source scripts/jetson_variables.sh |
4 |
| -#Print Jetson version |
5 |
| -echo "$JETSON_DESCRIPTION" |
6 |
| -#Print Jetpack version |
7 |
| -echo "Jetpack $JETSON_JETPACK [L4T $JETSON_L4T]" |
| 2 | +# Get the kernel source for NVIDIA Jetson Nano Developer Kit, L4T |
| 3 | +# Copyright (c) 2016-2020 Jetsonhacks |
| 4 | +# MIT License |
| 5 | + |
| 6 | +JETSON_MODEL="TX2" |
| 7 | +L4T_TARGET="32.3.1" |
| 8 | +SOURCE_TARGET="/usr/src" |
| 9 | +KERNEL_RELEASE="4.9" |
| 10 | + |
| 11 | +#Get the Board Model |
| 12 | +JETSON_BOARD="UNKNOWN" |
| 13 | + |
| 14 | +if [ -f /sys/module/tegra_fuse/parameters/tegra_chip_id ]; then |
| 15 | + JETSON_BOARD=$(case $(cat /sys/module/tegra_fuse/parameters/tegra_chip_id) in |
| 16 | + 64) |
| 17 | + echo TK1 ;; |
| 18 | + 33) |
| 19 | + echo Nano/TX1 ;; |
| 20 | + 24) |
| 21 | + echo TX2 ;; |
| 22 | + 25) |
| 23 | + echo AGX Xavier ;; |
| 24 | + esac) |
| 25 | + JETSON_DESCRIPTION="NVIDIA Jetson $JETSON_BOARD" |
| 26 | +fi |
| 27 | +echo "Jetson Model: "$JETSON_BOARD |
| 28 | + |
| 29 | +JETSON_L4T="" |
| 30 | + |
| 31 | +# Starting with L4T 32.2, the recommended way to find the L4T Release Number |
| 32 | +# is to use dpkg |
| 33 | +# L4T 32.3.1, NVIDIA added back /etc/nv_tegra_release |
| 34 | +function check_L4T_version() |
| 35 | +{ |
| 36 | + if [ -f /etc/nv_tegra_release ]; then |
| 37 | + JETSON_L4T_STRING=$(head -n 1 /etc/nv_tegra_release) |
| 38 | + JETSON_L4T_RELEASE=$(echo $JETSON_L4T_STRING | cut -f 2 -d ' ' | grep -Po '(?<=R)[^;]+') |
| 39 | + JETSON_L4T_REVISION=$(echo $JETSON_L4T_STRING | cut -f 2 -d ',' | grep -Po '(?<=REVISION: )[^;]+') |
| 40 | + JETSON_L4T_VERSION=$JETSON_L4T_RELEASE.$JETSON_L4T_REVISION |
| 41 | + |
| 42 | + else |
| 43 | + echo "$LOG Reading L4T version from \"dpkg-query --show nvidia-l4t-core\"" |
| 44 | + |
| 45 | + JETSON_L4T_STRING=$(dpkg-query --showformat='${Version}' --show nvidia-l4t-core) |
| 46 | + # For example: 32.2.1-20190812212815 |
| 47 | + JETSON_L4T_VERSION=$(echo $JETSON_L4T_STRING | cut -d '-' -f 1) |
| 48 | + JETSON_L4T_RELEASE=$(echo $JETSON_L4T_VERSION | cut -d '.' -f 1) |
| 49 | + # # operator remove prefix in string operations in bash script. Don't forget . eg "32." |
| 50 | + JETSON_L4T_REVISION=${JETSON_L4T_VERSION#$JETSON_L4T_RELEASE.} |
| 51 | + fi |
| 52 | + echo "$LOG Jetson BSP Version: L4T R$JETSON_L4T_VERSION" |
| 53 | + |
| 54 | +} |
| 55 | + |
| 56 | +echo "Getting L4T Version" |
| 57 | +check_L4T_version |
| 58 | +JETSON_L4T="$JETSON_L4T_VERSION" |
| 59 | + |
| 60 | +function usage |
| 61 | +{ |
| 62 | + echo "usage: ./getKernelSources.sh [[-d directory ] | [-h]]" |
| 63 | + echo "-h | --help This message" |
| 64 | +} |
| 65 | + |
| 66 | +# Iterate through command line inputs |
| 67 | +while [ "$1" != "" ]; do |
| 68 | + case $1 in |
| 69 | + -d | --directory ) shift |
| 70 | + SOURCE_TARGET=$1 |
| 71 | + ;; |
| 72 | + -h | --help ) usage |
| 73 | + exit |
| 74 | + ;; |
| 75 | + * ) usage |
| 76 | + exit 1 |
| 77 | + esac |
| 78 | + shift |
| 79 | +done |
| 80 | + |
| 81 | +red=`tput setaf 1` |
| 82 | +green=`tput setaf 2` |
| 83 | +reset=`tput sgr0` |
| 84 | +# e.g. echo "${red}The red tail hawk ${green}loves the green grass${reset}" |
| 85 | + |
| 86 | +LAST="${SOURCE_TARGET: -1}" |
| 87 | +if [ $LAST != '/' ] ; then |
| 88 | + SOURCE_TARGET="$SOURCE_TARGET""/" |
| 89 | +fi |
| 90 | + |
| 91 | +INSTALL_DIR=$PWD |
| 92 | + |
| 93 | +# Error out if something goes wrong |
| 94 | +set -e |
8 | 95 |
|
9 | 96 | # Check to make sure we're installing the correct kernel sources
|
10 |
| -L4TTarget="32.1.0" |
11 |
| -if [ $JETSON_L4T == $L4TTarget ] ; then |
12 |
| - echo "Getting kernel sources" |
13 |
| - sudo ./scripts/getKernelSources.sh |
14 |
| -else |
| 97 | +# Determine the correct kernel version |
| 98 | +# The KERNEL_BUILD_VERSION is the release tag for the JetsonHacks buildKernel repository |
| 99 | +KERNEL_BUILD_VERSION=master |
| 100 | +if [ "$JETSON_BOARD" == "$JETSON_MODEL" ] ; then |
| 101 | + if [ $JETSON_L4T == "$L4T_TARGET" ] ; then |
| 102 | + KERNEL_BUILD_VERSION=$L4T_TARGET |
| 103 | + else |
15 | 104 | echo ""
|
16 | 105 | tput setaf 1
|
17 | 106 | echo "==== L4T Kernel Version Mismatch! ============="
|
18 | 107 | tput sgr0
|
19 | 108 | echo ""
|
20 |
| - echo "This repository branch is for installing the kernel sources for L4T "$L4TTarget |
21 |
| - echo "You are attempting to use these kernel sources on a L4T "$JETSON_L4T "system." |
22 |
| - echo "The kernel sources do not match their L4T release!" |
| 109 | + echo "This repository is for modifying the kernel for a L4T "$L4T_TARGET "system." |
| 110 | + echo "You are attempting to modify a L4T "$JETSON_MODEL "system with L4T "$JETSON_L4T |
| 111 | + echo "The L4T releases must match!" |
23 | 112 | echo ""
|
24 |
| - echo "Please git checkout the appropriate kernel sources for your release" |
25 |
| - echo " " |
26 |
| - echo "You can list the tagged versions." |
27 |
| - echo "$ git tag -l" |
28 |
| - echo "And then checkout the latest version: " |
29 |
| - echo "For example" |
30 |
| - echo "$ git checkout v1.0-L4T"$JETSON_L4T |
| 113 | + echo "There may be versions in the tag/release sections that meet your needs" |
31 | 114 | echo ""
|
| 115 | + exit 1 |
| 116 | + fi |
| 117 | +else |
| 118 | + tput setaf 1 |
| 119 | + echo "==== Jetson Board Mismatch! =============" |
| 120 | + tput sgr0 |
| 121 | + echo "Currently this script works for the $JETSON_MODEL." |
| 122 | + echo "This processor appears to be a $JETSON_BOARD, which does not have a corresponding script" |
| 123 | + echo "" |
| 124 | + echo "Exiting" |
| 125 | + exit 1 |
32 | 126 | fi
|
33 | 127 |
|
| 128 | +# Check to see if source tree is already installed |
| 129 | +PROPOSED_SRC_PATH="$SOURCE_TARGET""kernel/kernel-"$KERNEL_RELEASE |
| 130 | +echo "Proposed source path: ""$PROPOSED_SRC_PATH" |
| 131 | +if [ -d "$PROPOSED_SRC_PATH" ]; then |
| 132 | + tput setaf 1 |
| 133 | + echo "==== Kernel source appears to already be installed! =============== " |
| 134 | + tput sgr0 |
| 135 | + echo "The kernel source appears to already be installed at: " |
| 136 | + echo " ""$PROPOSED_SRC_PATH" |
| 137 | + echo "If you want to reinstall the source files, first remove the directories: " |
| 138 | + echo " ""$SOURCE_TARGET""kernel" |
| 139 | + echo " ""$SOURCE_TARGET""hardware" |
| 140 | + echo "then rerun this script" |
| 141 | + exit 1 |
| 142 | +fi |
| 143 | + |
| 144 | +export SOURCE_TARGET |
| 145 | +# -E preserves environment variables |
| 146 | +sudo -E ./scripts/getKernelSources.sh |
| 147 | + |
34 | 148 |
|
0 commit comments