]> rtime.felk.cvut.cz Git - hercules2020/jailhouse-build.git/blob - nv-tegra/source_sync.sh
5a848b873e72fc3e5a7d944eb0eb631a7602653b
[hercules2020/jailhouse-build.git] / nv-tegra / source_sync.sh
1 #!/bin/bash
2
3 # Copyright (c) 2012-2017 NVIDIA CORPORATION.  All rights reserved.
4 #
5 # Redistribution and use in source and binary forms, with or without
6 # modification, are permitted provided that the following conditions
7 # are met:
8 #  * Redistributions of source code must retain the above copyright
9 #    notice, this list of conditions and the following disclaimer.
10 #  * Redistributions in binary form must reproduce the above copyright
11 #    notice, this list of conditions and the following disclaimer in the
12 #    documentation and/or other materials provided with the distribution.
13 #  * Neither the name of NVIDIA CORPORATION nor the names of its
14 #    contributors may be used to endorse or promote products derived
15 #    from this software without specific prior written permission.
16 #
17 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY
18 # EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
20 # PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR
21 # CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
22 # EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
23 # PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
24 # PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
25 # OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28
29
30 #
31 # This script sync's NVIDIA's version of
32 # 1. the kernel source
33 # 2. the u-boot source
34 # from nv-tegra, NVIDIA's public git repository.
35 # The script also provides opportunities to the sync to a specific tag
36 # so that the binaries shipped with a release can be replicated.
37 #
38 # Usage:
39 # By default it will download all the listed sources
40 # ./source_sync.sh
41 # Use the -t <TAG> option to provide the TAG to be used to sync all the sources.
42 # Use the -k <TAG> option to download only the kernel and device tree repos and optionally sync to TAG
43 # Use the -u <TAG> option to download only the u-boot repo and optionally sync to TAG
44 # For detailed usage information run with -h option.
45 #
46
47
48 # verify that git is installed
49 if  ! which git > /dev/null  ; then
50   echo "ERROR: git is not installed. If your linux distro is 10.04 or later,"
51   echo "git can be installed by 'sudo apt-get install git-core'."
52   exit 1
53 fi
54
55 # source dir
56 LDK_DIR=$(cd `dirname $0` && pwd)
57 LDK_DIR="${LDK_DIR}/sources"
58 # script name
59 SCRIPT_NAME=`basename $0`
60 # info about sources.
61 # NOTE: *Add only kernel repos here. Add new repos separately below. Keep related repos together*
62 SOURCE_INFO="
63 k:kernel/kernel-4.4:nv-tegra.nvidia.com/linux-4.4.git:
64 k:kernel/t18x:nv-tegra.nvidia.com/linux-t18x.git:
65 k:kernel/nvgpu:nv-tegra.nvidia.com/linux-nvgpu.git:
66 k:kernel/nvhost:nv-tegra.nvidia.com/linux-nvhost.git:
67 k:kernel/nvmap:nv-tegra.nvidia.com/linux-nvmap.git:
68 k:kernel/nvmap-t18x:nv-tegra.nvidia.com/linux-nvmap-t18x.git:
69 k:kernel/display:nv-tegra.nvidia.com/linux-display.git:
70 k:hardware/nvidia/soc/t18x:nv-tegra.nvidia.com/device/hardware/nvidia/soc/t18x.git:
71 k:hardware/nvidia/platform/tegra/common:nv-tegra.nvidia.com/device/hardware/nvidia/platform/tegra/common.git:
72 k:hardware/nvidia/platform/t18x/common:nv-tegra.nvidia.com/device/hardware/nvidia/platform/t18x/common.git:
73 k:hardware/nvidia/platform/t18x/quill:nv-tegra.nvidia.com/device/hardware/nvidia/platform/t18x/quill.git:
74 k:hardware/nvidia/soc/t210:nv-tegra.nvidia.com/device/hardware/nvidia/soc/t210.git:
75 k:hardware/nvidia/platform/t210/common:nv-tegra.nvidia.com/device/hardware/nvidia/platform/t210/common.git:
76 k:hardware/nvidia/platform/t210/jetson:nv-tegra.nvidia.com/device/hardware/nvidia/platform/t210/jetson.git:
77 k:hardware/nvidia/soc/tegra:nv-tegra.nvidia.com/device/hardware/nvidia/soc/tegra.git:
78 "
79 SOURCE_INFO+="
80 u:u-boot:nv-tegra.nvidia.com/3rdparty/u-boot.git:
81 "
82
83 # exit on error on sync
84 EOE=0
85 # after processing SOURCE_INFO
86 NSOURCES=0
87 declare -a SOURCE_INFO_PROCESSED
88 # download all?
89 DALL=1
90
91 function Usages {
92         local ScriptName=$1
93         local LINE
94         local OP
95         local DESC
96         local PROCESSED=()
97         local i
98
99         echo "Use: $1 [options]"
100         echo "Available general options are,"
101         echo "     -h     :     help"
102         echo "     -e     : exit on sync error"
103         echo "     -d [DIR] : root of source is DIR"
104         echo "     -t [TAG] : Git tag that will be used to sync all the sources"
105         echo ""
106         echo "By default, all sources are downloaded."
107         echo "Only specified sources are downloaded, if one or more of the following options are mentioned."
108         echo ""
109         echo "$SOURCE_INFO" | while read LINE; do
110                 if [ ! -z "$LINE" ]; then
111                         OP=$(echo "$LINE" | cut -f 1 -d ':')
112                         DESC=$(echo "$LINE" | cut -f 2 -d ':')
113                         if [[ ! " ${PROCESSED[@]} " =~ " ${OP} " ]]; then
114                                 echo "     -${OP} [TAG]: Download $DESC source and optionally sync to TAG"
115                                 PROCESSED+=("${OP}")
116                         else
117                                 echo "           and download $DESC source and sync to the same TAG"
118                         fi
119                 fi
120         done
121         echo ""
122 }
123
124 function ProcessSwitch {
125         local SWITCH="$1"
126         local TAG="$2"
127         local i
128         local found=0
129
130         for ((i=0; i < NSOURCES; i++)); do
131                 local OP=$(echo "${SOURCE_INFO_PROCESSED[i]}" | cut -f 1 -d ':')
132                 if [ "-${OP}" == "$SWITCH" ]; then
133                         SOURCE_INFO_PROCESSED[i]="${SOURCE_INFO_PROCESSED[i]}${TAG}:y"
134                         DALL=0
135                         found=1
136                 fi
137         done
138
139         if [ "$found" == 1 ]; then
140                 return 0
141         fi
142
143         echo "Terminating... wrong switch: ${SWITCH}" >&2
144         Usages "$SCRIPT_NAME"
145         exit 1
146 }
147
148 function UpdateTags {
149         local SWITCH="$1"
150         local TAG="$2"
151         local i
152
153         for ((i=0; i < NSOURCES; i++)); do
154                 local OP=$(echo "${SOURCE_INFO_PROCESSED[i]}" | cut -f 1 -d ':')
155                 if [ "${OP}" == "$SWITCH" ]; then
156                         SOURCE_INFO_PROCESSED[i]=$(echo "${SOURCE_INFO_PROCESSED[i]}" \
157                                 | awk -F: -v OFS=: -v var="${TAG}" '{$4=var; print}')
158                 fi
159         done
160 }
161
162 function DownloadAndSync {
163         local WHAT_SOURCE="$1"
164         local LDK_SOURCE_DIR="$2"
165         local REPO_URL="$3"
166         local TAG="$4"
167         local OPT="$5"
168         local RET=0
169
170         if [ -d "${LDK_SOURCE_DIR}" ] ; then
171                 echo "Directory for $WHAT, ${LDK_SOURCE_DIR}, already exists!"
172                 pushd "${LDK_SOURCE_DIR}" > /dev/null
173                 git status 2>&1 >/dev/null
174                 if [ $? -ne 0 ]; then
175                         echo "But the directory is not a git repository -- clean it up first"
176                         echo ""
177                         echo ""
178                         popd > /dev/null
179                         return 1
180                 fi
181                 git fetch --all 2>&1 >/dev/null
182                 popd > /dev/null
183         else
184                 echo "Downloading default $WHAT source..."
185
186                 git clone "$REPO_URL" -n ${LDK_SOURCE_DIR} 2>&1 >/dev/null
187                 if [ $? -ne 0 ]; then
188                         echo "$2 source sync failed!"
189                         echo ""
190                         echo ""
191                         return 1
192                 fi
193
194                 echo "The default $WHAT source is downloaded in: ${LDK_SOURCE_DIR}"
195         fi
196
197         if [ -z "$TAG" ]; then
198                 echo "Please enter a tag to sync $2 source to"
199                 echo -n "(enter nothing to skip): "
200                 read TAG
201                 TAG=$(echo $TAG)
202                 UpdateTags $OPT $TAG
203         fi
204
205         if [ ! -z "$TAG" ]; then
206                 pushd ${LDK_SOURCE_DIR} > /dev/null
207                 git tag -l 2>/dev/null | grep -q -P "^$TAG\$"
208                 if [ $? -eq 0 ]; then
209                         echo "Syncing up with tag $TAG..."
210                         git checkout -b mybranch_$(date +%Y-%m-%d-%s) $TAG
211                         echo "$2 source sync'ed to tag $TAG successfully!"
212                 else
213                         echo "Couldn't find tag $TAG"
214                         echo "$2 source sync to tag $TAG failed!"
215                         RET=1
216                 fi
217                 popd > /dev/null
218         fi
219         echo ""
220         echo ""
221
222         return "$RET"
223 }
224
225 # prepare processing ....
226 GETOPT=":ehd:t:"
227
228 OIFS="$IFS"
229 IFS=$(echo -en "\n\b")
230 SOURCE_INFO_PROCESSED=($(echo "$SOURCE_INFO"))
231 IFS="$OIFS"
232 NSOURCES=${#SOURCE_INFO_PROCESSED[*]}
233
234 for ((i=0; i < NSOURCES; i++)); do
235         OP=$(echo "${SOURCE_INFO_PROCESSED[i]}" | cut -f 1 -d ':')
236         GETOPT="${GETOPT}${OP}:"
237 done
238
239 # parse the command line first
240 while getopts "$GETOPT" opt; do
241         case $opt in
242                 d)
243                         case $OPTARG in
244                                 -[A-Za-z]*)
245                                         Usages "$SCRIPT_NAME"
246                                         exit 1
247                                         ;;
248                                 *)
249                                         LDK_DIR="$OPTARG"
250                                         ;;
251                         esac
252                         ;;
253                 e)
254                         EOE=1
255                         ;;
256                 h)
257                         Usages "$SCRIPT_NAME"
258                         exit 1
259                         ;;
260                 t)
261                         TAG="$OPTARG"
262                         PROCESSED=()
263                         for ((i=0; i < NSOURCES; i++)); do
264                                 OP=$(echo "${SOURCE_INFO_PROCESSED[i]}" | cut -f 1 -d ':')
265                                 if [[ ! " ${PROCESSED[@]} " =~ " ${OP} " ]]; then
266                                         UpdateTags $OP $TAG
267                                         PROCESSED+=("${OP}")
268                                 fi
269                         done
270                         ;;
271                 [A-Za-z])
272                         case $OPTARG in
273                                 -[A-Za-z]*)
274                                         eval arg=\$$((OPTIND-1))
275                                         case $arg in
276                                                 -[A-Za-Z]-*)
277                                                         Usages "$SCRIPT_NAME"
278                                                         exit 1
279                                                         ;;
280                                                 *)
281                                                         ProcessSwitch "-$opt" ""
282                                                         OPTIND=$((OPTIND-1))
283                                                         ;;
284                                         esac
285                                         ;;
286                                 *)
287                                         ProcessSwitch "-$opt" "$OPTARG"
288                                         ;;
289                         esac
290                         ;;
291                 :)
292                         case $OPTARG in
293                                 #required arguments
294                                 d)
295                                         Usages "$SCRIPT_NAME"
296                                         exit 1
297                                         ;;
298                                 #optional arguments
299                                 [A-Za-z])
300                                         ProcessSwitch "-$OPTARG" ""
301                                         ;;
302                         esac
303                         ;;
304                 \?)
305                         echo "Terminating... wrong switch: $@" >&2
306                         Usages "$SCRIPT_NAME"
307                         exit 1
308                         ;;
309         esac
310 done
311 shift $((OPTIND-1))
312
313 GRET=0
314 for ((i=0; i < NSOURCES; i++)); do
315         OPT=$(echo "${SOURCE_INFO_PROCESSED[i]}" | cut -f 1 -d ':')
316         WHAT=$(echo "${SOURCE_INFO_PROCESSED[i]}" | cut -f 2 -d ':')
317         REPO=$(echo "${SOURCE_INFO_PROCESSED[i]}" | cut -f 3 -d ':')
318         TAG=$(echo "${SOURCE_INFO_PROCESSED[i]}" | cut -f 4 -d ':')
319         DNLOAD=$(echo "${SOURCE_INFO_PROCESSED[i]}" | cut -f 5 -d ':')
320
321         if [ $DALL -eq 1 -o "x${DNLOAD}" == "xy" ]; then
322                 DownloadAndSync "$WHAT" "${LDK_DIR}/${WHAT}" "git://${REPO}" "${TAG}" "${OPT}"
323                 tRET=$?
324                 let GRET=GRET+tRET
325                 if [ $tRET -ne 0 -a $EOE -eq 1 ]; then
326                         exit $tRET
327                 fi
328         fi
329 done
330
331 exit $GRET