forked from JetsonHacksNano/installLibrealsense
-
Notifications
You must be signed in to change notification settings - Fork 0
/
patchUbuntu.sh
executable file
·174 lines (150 loc) · 5.22 KB
/
patchUbuntu.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
#!/bin/bash
# Copyright (c) 2016-19 Jetsonhacks
# MIT License
# Build kernel to include tegra usb firmware
JETSON_MODEL="NVIDIA Jetson Nano Developer Kit"
L4T_TARGET="32.2"
SOURCE_TARGET="/usr/src"
KERNEL_RELEASE="4.9"
BUILD_REPOSITORY="$HOME/buildKernelAndModules"
INSTALL_DIR=$PWD
LIBREALSENSE_DIRECTORY=${HOME}/librealsense
LIBREALSENSE_VERSION=v2.24.0
# Build the kernel and install it
BUILD_KERNEL=true
# < is more efficient than cat command
# NULL byte at end of board description gets bash upset; strip it out
JETSON_BOARD=$(tr -d '\0' </proc/device-tree/model)
JETSON_L4T=""
# Starting with L4T 32.2, the recommended way to find the L4T Release Number
# is to use dpkg
function check_L4T_version()
{
if [ -f /etc/nv_tegra_release ]; then
JETSON_L4T_STRING=$(head -n 1 /etc/nv_tegra_release)
JETSON_L4T_RELEASE=$(echo $JETSON_L4T_STRING | cut -f 2 -d ' ' | grep -Po '(?<=R)[^;]+')
JETSON_L4T_REVISION=$(echo $JETSON_L4T_STRING | cut -f 2 -d ',' | grep -Po '(?<=REVISION: )[^;]+')
else
echo "$LOG Reading L4T version from \"dpkg-query --show nvidia-l4t-core\""
JETSON_L4T_STRING=$(dpkg-query --showformat='${Version}' --show nvidia-l4t-core)
local JETSON_L4T_ARRAY=(${JETSON_L4T_STRING//./ })
#echo ${JETSON_L4T_ARRAY[@]}
#echo ${#JETSON_L4T_ARRAY[@]}
JETSON_L4T_RELEASE=${JETSON_L4T_ARRAY[0]}
JETSON_L4T_REVISION=${JETSON_L4T_ARRAY[1]}
fi
JETSON_L4T_VERSION="$JETSON_L4T_RELEASE.$JETSON_L4T_REVISION"
echo "$LOG Jetson BSP Version: L4T R$JETSON_L4T_VERSION"
}
echo "Getting L4T Version"
check_L4T_version
JETSON_L4T="$JETSON_L4T_VERSION"
echo "Jetson_L4T="$JETSON_L4T
LAST="${SOURCE_TARGET: -1}"
if [ $LAST != '/' ] ; then
SOURCE_TARGET="$SOURCE_TARGET""/"
fi
# Error out if something goes wrong
set -e
# Check to make sure we're installing the correct kernel sources
# Determine the correct kernel version
# The KERNEL_BUILD_VERSION is the release tag for the JetsonHacks buildKernel repository
KERNEL_BUILD_VERSION=master
if [ "$JETSON_BOARD" == "$JETSON_MODEL" ] ; then
if [ $JETSON_L4T == "$L4T_TARGET" ] ; then
KERNEL_BUILD_VERSION=$L4T_TARGET
else
echo ""
tput setaf 1
echo "==== L4T Kernel Version Mismatch! ============="
tput sgr0
echo ""
echo "This repository is for modifying the kernel for a L4T "$L4T_TARGET "system."
echo "You are attempting to modify a L4T "$JETSON_MODEL "system with L4T "$JETSON_L4T
echo "The L4T releases must match!"
echo ""
echo "There may be versions in the tag/release sections that meet your needs"
echo ""
exit 1
fi
else
tput setaf 1
echo "==== Jetson Board Mismatch! ============="
tput sgr0
echo "Currently this script works for the $JETSON_MODEL."
echo "This processor appears to be a $JETSON_BOARD, which does not have a corresponding script"
echo ""
echo "Exiting"
exit 1
fi
# Check to see if buildKernelAndModules is installed
# Expect it in the home directory
if [ -d "$BUILD_REPOSITORY" ] ; then
echo "buildModules and Kernel previously installed"
else
echo "Installing buildModulesAndKernel"
git clone https://github.com/jetsonhacksnano/buildKernelAndModules "$BUILD_REPOSITORY"
fi
# Check to see if source tree is already installed
PROPOSED_SRC_PATH="$SOURCE_TARGET""kernel/kernel-"$KERNEL_RELEASE
echo "Proposed source path: ""$PROPOSED_SRC_PATH"
if [ -d "$PROPOSED_SRC_PATH" ]; then
echo "==== Kernel source appears to already be installed =============== "
else
# Get the kernel sources
cd $BUILD_REPOSITORY
./getKernelSources.sh
cd $INSTALL_DIR
fi
# Is librealsense on the device?
if [ ! -d "$LIBREALSENSE_DIRECTORY" ] ; then
echo "The librealsense repository directory is not available"
read -p "Would you like to git clone librealsense? (y/n) " answer
case ${answer:0:1} in
y|Y )
# clone librealsense
cd ${HOME}
echo "${green}Cloning librealsense${reset}"
git clone https://github.com/IntelRealSense/librealsense.git
cd librealsense
# Checkout version the last tested version of librealsense
git checkout $LIBREALSENSE_VERSION
;;
* )
echo "Kernel patch and build not started"
exit 1
;;
esac
fi
# Is the version of librealsense current enough?
cd $LIBREALSENSE_DIRECTORY
VERSION_TAG=$(git tag -l $LIBREALSENSE_VERSION)
if [ ! $VERSION_TAG ] ; then
echo ""
tput setaf 1
echo "==== librealsense Version Mismatch! ============="
tput sgr0
echo ""
echo "The installed version of librealsense is not current enough for these scripts."
echo "This script needs librealsense tag version: "$LIBREALSENSE_VERSION "but it is not available."
echo "This script uses patches from librealsense on the kernel source."
echo "Please upgrade librealsense before attempting to patch and build the kernel again."
echo ""
exit 1
fi
# Switch back to the script directory
cd $INSTALL_DIR
# Get the kernel sources
echo "${green}Patching and configuring kernel${reset}"
sudo ./scripts/configureKernel.sh
sudo ./scripts/patchKernel.sh
echo "Making kernel"
cd $BUILD_REPOSITORY
if [ $BUILD_KERNEL ] ; then
./makeKernel.sh
./copyImage.sh
echo "Kernel image built, and has been copied to /boot/Image."
fi
./makeModules.sh
echo "Modules now patched and installed"
echo "Reboot for changes to take effect"