]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - android/vendor-ti-am57x.git/blob - sgx_km/eurasia_km/eurasiacon/build/linux2/common/android/install.sh.tpl
sgx_km: Build SGX KM from source
[android/vendor-ti-am57x.git] / sgx_km / eurasia_km / eurasiacon / build / linux2 / common / android / install.sh.tpl
1 #!/bin/bash
2 ############################################################################ ###
3 #@Copyright     Copyright (c) Imagination Technologies Ltd. All Rights Reserved
4 #@License       Dual MIT/GPLv2
5
6 # The contents of this file are subject to the MIT license as set out below.
7
8 # Permission is hereby granted, free of charge, to any person obtaining a copy
9 # of this software and associated documentation files (the "Software"), to deal
10 # in the Software without restriction, including without limitation the rights
11 # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12 # copies of the Software, and to permit persons to whom the Software is
13 # furnished to do so, subject to the following conditions:
14
15 # The above copyright notice and this permission notice shall be included in
16 # all copies or substantial portions of the Software.
17
18 # Alternatively, the contents of this file may be used under the terms of
19 # the GNU General Public License Version 2 ("GPL") in which case the provisions
20 # of GPL are applicable instead of those above.
21
22 # If you wish to allow use of your version of this file only under the terms of
23 # GPL, and not to allow others to use your version of this file under the terms
24 # of the MIT license, indicate your decision by deleting the provisions above
25 # and replace them with the notice and other provisions required by GPL as set
26 # out in the file called "GPL-COPYING" included in this distribution. If you do
27 # not delete the provisions above, a recipient may use your version of this file
28 # under the terms of either the MIT license or GPL.
29
30 # This License is also included in this distribution in the file called
31 # "MIT-COPYING".
32
33 # EXCEPT AS OTHERWISE STATED IN A NEGOTIATED AGREEMENT: (A) THE SOFTWARE IS
34 # PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
35 # BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
36 # PURPOSE AND NONINFRINGEMENT; AND (B) IN NO EVENT SHALL THE AUTHORS OR
37 # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
38 # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
39 # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
40 #### ###########################################################################
41 # Help on how to invoke
42 #
43 function usage {
44     echo "usage: $0 [options...]"
45     echo ""
46     echo "Options: -v            Verbose mode."
47     echo "         -n            Dry-run mode."
48     echo "         -u            Uninstall-only mode."
49     echo "         --root <path> Use <path> as the root of the install file system."
50     echo "                       (Overrides the DISCIMAGE environment variable.)"
51     exit 1
52 }
54 WD=`pwd`
55 SCRIPT_ROOT=`dirname $0`
56 cd $SCRIPT_ROOT
58 PVRVERSION=[PVRVERSION]
59 PVRBUILD=[PVRBUILD]
60 PRIMARY_ARCH="[PRIMARY_ARCH]"
61 ARCHITECTURES="[ARCHITECTURES]"
63 APP_DESTDIR=[APP_DESTDIR]
64 BIN_DESTDIR=[BIN_DESTDIR]
65 DATA_DESTDIR=[BIN_DESTDIR]
67 # Exit with an error messages.
68 # $1=blurb
69 #
70 function bail {
71     if [ ! -z "$1" ]; then
72         echo "$1" >&2
73     fi
75     echo "" >&2
76     echo "Installation failed" >&2
77     exit 1
78 }
80 # Copy all the required files into their appropriate places on the local machine.
81 function install_locally {
82     # Define functions required for local installs
84     # basic installation function
85     # $1=fromfile, $2=destfilename, $3=blurb, $4=chmod-flags, $5=chown-flags
86     #
87     function install_file {
88         if [ -z "$DDK_INSTALL_LOG" ]; then
89             bail "INTERNAL ERROR: Invoking install without setting logfile name"
90         fi
91         DESTFILE=${DISCIMAGE}$2
92         DESTDIR=`dirname $DESTFILE`
94         if [ ! -e $1 ]; then
95             [ -n "$VERBOSE" ] && echo "skipping file $1 -> $2"
96             return
97         fi
99         # Destination directory - make sure it's there and writable
100         #
101         if [ -d "${DESTDIR}" ]; then
102             if [ ! -w "${DESTDIR}" ]; then
103                 bail "${DESTDIR} is not writable."
104             fi
105         else
106             $DOIT mkdir -p ${DESTDIR} || bail "Couldn't mkdir -p ${DESTDIR}"
107             [ -n "$VERBOSE" ] && echo "Created directory `dirname $2`"
108         fi
110         # Delete the original so that permissions don't persist.
111         #
112         $DOIT rm -f $DESTFILE
114         $DOIT cp -f $1 $DESTFILE || bail "Couldn't copy $1 to $DESTFILE"
115         $DOIT chmod $4 ${DESTFILE}
117         echo "$3 `basename $1` -> $2"
118         $DOIT echo "file $2" >> $DDK_INSTALL_LOG
119     }
121     # If we install to an empty $DISCIMAGE, then we need to create some
122     # dummy directories, even if they contain no files, otherwise 'adb
123     # sync' may fail. (It allows '/vendor' to not exist currently.)
124     [ ! -d ${DISCIMAGE}/data ]   && mkdir ${DISCIMAGE}/data
125     [ ! -d ${DISCIMAGE}/system ] && mkdir ${DISCIMAGE}/system
127     for arch in $ARCHITECTURES; do
128         if [ ! -d $arch ]; then
129             echo "Missing architecture $arch"
130                 if [ "$arch" = "$PRIMARY_ARCH" ]; then
131                     echo "Primary architecture is missing, aborting!"
132                     exit 1
133                 else
134                     continue
135                 fi
136         fi
138         BASE_DESTDIR=`dirname ${BIN_DESTDIR}`
139         case $arch in
140             target*64*  )
141                 SHLIB_DESTDIR=${BASE_DESTDIR}/lib64
142                 ;;
143             *)
144                 SHLIB_DESTDIR=${BASE_DESTDIR}/lib
145         esac
146         EGL_DESTDIR=${SHLIB_DESTDIR}/egl
148         pushd $arch > /dev/null
149         # Install UM components
150         if [ -f install_um.sh ]; then
151             DDK_INSTALL_LOG=$UMLOG
152             echo "Installing User components for architecture $arch"
153             $DOIT echo "version $PVRVERSION" > $DDK_INSTALL_LOG
154             source install_um.sh
155             echo
156         fi
157         popd > /dev/null
158     done
160     pushd $PRIMARY_ARCH > /dev/null
161     # Install KM components
162     if [ -f install_km.sh ]; then
163         DDK_INSTALL_LOG=$KMLOG
164         echo "Installing Kernel components for architecture $PRIMARY_ARCH"
165         $DOIT echo "version $PVRVERSION" > $DDK_INSTALL_LOG
166         source install_km.sh
167         echo
168     fi
169     popd > /dev/null
171     # Create an OLDLOG so old versions of the driver can uninstall.
172     $DOIT echo "version $PVRVERSION" > $OLDLOG
173     if [ -f $KMLOG ]; then
174         tail -n +2 $KMLOG >> $OLDLOG
175     fi
176     if [ -f $UMLOG ]; then
177         tail -n +2 $UMLOG >> $OLDLOG
178     fi
180     # Make sure new logs are newer than $OLDLOG
181     touch -m -d "last sunday" $OLDLOG
184 # Read the appropriate install log and delete anything therein.
185 function uninstall_locally {
186     # Function to uninstall something.
187     function do_uninstall {
188         LOG=$1
190         if [ ! -f $LOG ]; then
191             echo "Nothing to un-install."
192             return;
193         fi
195         BAD=0
196         VERSION=""
197         while read type data; do
198             case $type in
199             version)
200                 echo "Uninstalling existing version $data"
201                 VERSION="$data"
202                 ;;
203             link|file)
204                 if [ -z "$VERSION" ]; then
205                     BAD=1;
206                     echo "No version record at head of $LOG"
207                 elif ! $DOIT rm -f ${DISCIMAGE}${data}; then
208                     BAD=1;
209                 else
210                     [ -n "$VERBOSE" ] && echo "Deleted $type $data"
211                 fi
212                 ;;
213             tree)
214                 ;;
215             esac
216         done < $1;
218         if [ $BAD = 0 ]; then
219             echo "Uninstallation completed."
220             $DOIT rm -f $LOG
221         else
222             echo "Uninstallation failed!!!"
223         fi
224     }
226     if [ -z "$OLDLOG" -o -z "$KMLOG" -o -z "$UMLOG" ]; then
227         bail "INTERNAL ERROR: Invoking uninstall without setting logfile name"
228     fi
230     # Uninstall anything installed using the old-style install scripts.
231     LEGACY_LOG=0
232     if [ -f $OLDLOG ]; then
233         if [ -f $KMLOG -a $KMLOG -nt $OLDLOG ]; then
234             # Last install was new scheme.
235             rm $OLDLOG
236         elif [ -f $UMLOG -a $UMLOG -nt $OLDLOG ]; then
237             # Last install was new scheme.
238             rm $OLDLOG
239         else
240             echo "Uninstalling all components from legacy log."
241             do_uninstall $OLDLOG
242             LEGACY_LOG=1
243             echo
244         fi
245     fi
247     if [ $LEGACY_LOG = 0 ]; then
248         # Uninstall KM components if we are doing a KM install.
249         if [ -f install_km.sh -a -f $KMLOG ]; then
250             echo "Uninstalling Kernel components"
251             do_uninstall $KMLOG
252             echo
253         fi
254         # Uninstall UM components if we are doing a UM install.
255         if [ -f install_um.sh -a -f $UMLOG ]; then
256             echo "Uninstalling User components"
257             do_uninstall $UMLOG
258             echo
259         fi
260     fi
263 # Work out if there are any special instructions.
265 while [ "$1" ]; do
266     case "$1" in
267     -v|--verbose)
268         VERBOSE=v
269         ;;
270     -r|--root)
271         DISCIMAGE=$2
272         shift;
273         ;;
274     -u|--uninstall)
275         UNINSTALL_ONLY=y
276         ;;
277     -n)
278         DOIT=echo
279         ;;
280     -h | --help | *)
281         usage
282         ;;
283     esac
284     shift
285 done
287 if [ ! -z "$DISCIMAGE" ]; then
289     if [ ! -d "$DISCIMAGE" ]; then
290        bail "$0: $DISCIMAGE does not exist."
291     fi
293     echo
294     if [ $DISCIMAGE == "/" ]; then
295         echo "Installing PowerVR '$PVRVERSION ($PVRBUILD)' locally"
296     else
297         echo "Installing PowerVR '$PVRVERSION ($PVRBUILD)' on $DISCIMAGE"
298     fi
299     echo
300     echo "File system installation root is $DISCIMAGE"
301     echo
303     OLDLOG=$DISCIMAGE/powervr_ddk_install.log
304     KMLOG=$DISCIMAGE/powervr_ddk_install_km.log
305     UMLOG=$DISCIMAGE/powervr_ddk_install_um.log
307     uninstall_locally
309     if [ "$UNINSTALL_ONLY" != "y" ]; then
310         install_locally
311     fi
313 else
314     bail "DISCIMAGE must be set for installation to be possible."
315 fi