RK3368 GPU version Rogue M 1.28
[firefly-linux-kernel-4.4.55.git] / drivers / gpu / rogue_m / build / linux / 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 }
53
54 WD=`pwd`
55 SCRIPT_ROOT=`dirname $0`
56 cd $SCRIPT_ROOT
57
58 PVRVERSION=[PVRVERSION]
59 PVRBUILD=[PVRBUILD]
60 PRIMARY_ARCH="[PRIMARY_ARCH]"
61 ARCHITECTURES="[ARCHITECTURES]"
62
63 # These destination directories are the same for 32- or 64-bit binaries.
64 # zxl: change module's path from /system/modules/ to /system/lib/modules/
65 MOD_DESTDIR=/system/lib/modules
66 BIN_DESTDIR=/system/vendor/bin
67 DATA_DESTDIR=${BIN_DESTDIR}
68
69 # Exit with an error messages.
70 # $1=blurb
71 #
72 function bail {
73     if [ ! -z "$1" ]; then
74         echo "$1" >&2
75     fi
76
77     echo "" >&2
78     echo "Installation failed" >&2
79     exit 1
80 }
81
82 # Copy all the required files into their appropriate places on the local machine.
83 function install_locally {
84     # Define functions required for local installs
85
86     # basic installation function
87     # $1=fromfile, $2=destfilename, $3=blurb, $4=chmod-flags, $5=chown-flags
88     #
89     function install_file {
90         if [ -z "$DDK_INSTALL_LOG" ]; then
91             bail "INTERNAL ERROR: Invoking install without setting logfile name"
92         fi
93         DESTFILE=${DISCIMAGE}$2
94         DESTDIR=`dirname $DESTFILE`
95     
96         if [ ! -e $1 ]; then
97             [ -n "$VERBOSE" ] && echo "skipping file $1 -> $2"
98             return
99         fi
100         
101         # Destination directory - make sure it's there and writable
102         #
103         if [ -d "${DESTDIR}" ]; then
104             if [ ! -w "${DESTDIR}" ]; then
105                 bail "${DESTDIR} is not writable."
106             fi
107         else
108             $DOIT mkdir -p ${DESTDIR} || bail "Couldn't mkdir -p ${DESTDIR}"
109             [ -n "$VERBOSE" ] && echo "Created directory `dirname $2`"
110         fi
111     
112         # Delete the original so that permissions don't persist.
113         #
114         $DOIT rm -f $DESTFILE
115     
116         $DOIT cp -f $1 $DESTFILE || bail "Couldn't copy $1 to $DESTFILE"
117         $DOIT chmod $4 ${DESTFILE}
118     
119         echo "$3 `basename $1` -> $2"
120         $DOIT echo "file $2" >> $DDK_INSTALL_LOG
121     }
122
123         # Android-specific targetfs mkdir workarounds
124         if [ ! -d ${DISCIMAGE}/data ]; then
125                 mkdir ${DISCIMAGE}/data
126                 chown 1000:1000 ${DISCIMAGE}/data
127                 chmod 0771 ${DISCIMAGE}/data
128         fi
129         if [ ! -d ${DISCIMAGE}/data/app ]; then
130                 mkdir ${DISCIMAGE}/data/app
131                 chown 1000:1000 ${DISCIMAGE}/data/app
132                 chmod 0771 ${DISCIMAGE}/data/app
133         fi
134
135     for arch in $ARCHITECTURES; do
136         if [ ! -d $arch ]; then
137             echo "Unknown architecture $arch.  Aborting"
138             #exit 1
139         fi
140
141         case $arch in
142             target*64)
143                 SHLIB_DESTDIR=/system/vendor/lib64
144                 ;;
145             *)
146                 SHLIB_DESTDIR=/system/vendor/lib
147         esac
148         EGL_DESTDIR=${SHLIB_DESTDIR}/egl
149
150         pushd $arch > /dev/null
151         # Install UM components
152         if [ -f install_um.sh ]; then
153             DDK_INSTALL_LOG=$UMLOG
154             echo "Installing User components for architecture $arch"
155             $DOIT echo "version $PVRVERSION" > $DDK_INSTALL_LOG
156             source install_um.sh
157             echo 
158         fi
159         popd > /dev/null
160     done
161
162     pushd $PRIMARY_ARCH > /dev/null
163     # Install KM components
164     if [ -f install_km.sh ]; then
165         DDK_INSTALL_LOG=$KMLOG
166         echo "Installing Kernel components for architecture $PRIMARY_ARCH"
167         $DOIT echo "version $PVRVERSION" > $DDK_INSTALL_LOG
168         source install_km.sh
169         echo
170     fi
171     popd > /dev/null
172
173         $DOIT mkdir -p ${DISCIMAGE}/system/lib/egl
174         $DOIT cat >${DISCIMAGE}/system/lib/egl/egl.cfg <<EOF
175 0 0 POWERVR_ROGUE
176 EOF
177         $DOIT echo "file /system/lib/egl/egl.cfg" >> $DDK_INSTALL_LOG
178
179     # Create an OLDLOG so old versions of the driver can uninstall.
180     $DOIT echo "version $PVRVERSION" > $OLDLOG
181     if [ -f $KMLOG ]; then
182         tail -n +2 $KMLOG >> $OLDLOG
183     fi
184     if [ -f $UMLOG ]; then
185         tail -n +2 $UMLOG >> $OLDLOG
186     fi
187     
188     # Make sure new logs are newer than $OLDLOG
189     touch -m -d "last sunday" $OLDLOG
190 }
191
192 # Read the appropriate install log and delete anything therein.
193 function uninstall_locally {
194     # Function to uninstall something.
195     function do_uninstall {
196         LOG=$1
197
198         if [ ! -f $LOG ]; then
199             echo "Nothing to un-install."
200             return;
201         fi
202     
203         BAD=0
204         VERSION=""
205         while read type data; do
206             case $type in
207             version)
208                 echo "Uninstalling existing version $data"
209                 VERSION="$data"
210                 ;;
211             link|file) 
212                 if [ -z "$VERSION" ]; then
213                     BAD=1;
214                     echo "No version record at head of $LOG"
215                 elif ! $DOIT rm -f ${DISCIMAGE}${data}; then
216                     BAD=1;
217                 else
218                     [ -n "$VERBOSE" ] && echo "Deleted $type $data"
219                 fi
220                 ;;
221             tree)
222                 ;;
223             esac
224         done < $1;
225
226         if [ $BAD = 0 ]; then
227             echo "Uninstallation completed."
228             $DOIT rm -f $LOG
229         else
230             echo "Uninstallation failed!!!"
231         fi
232     }
233
234     if [ -z "$OLDLOG" -o -z "$KMLOG" -o -z "$UMLOG" ]; then
235         bail "INTERNAL ERROR: Invoking uninstall without setting logfile name"
236     fi
237
238     # Uninstall anything installed using the old-style install scripts.
239     LEGACY_LOG=0
240     if [ -f $OLDLOG ]; then
241         if [ -f $KMLOG -a $KMLOG -nt $OLDLOG ]; then
242             # Last install was new scheme.
243             rm $OLDLOG
244         elif [ -f $UMLOG -a $UMLOG -nt $OLDLOG ]; then
245             # Last install was new scheme.
246             rm $OLDLOG
247         else
248             echo "Uninstalling all components from legacy log."
249             do_uninstall $OLDLOG
250             LEGACY_LOG=1
251             echo 
252         fi
253     fi
254
255     if [ $LEGACY_LOG = 0 ]; then
256         # Uninstall KM components if we are doing a KM install.
257         if [ -f install_km.sh -a -f $KMLOG ]; then
258             echo "Uninstalling Kernel components"
259             do_uninstall $KMLOG
260             echo 
261         fi
262         # Uninstall UM components if we are doing a UM install.
263         if [ -f install_um.sh -a -f $UMLOG ]; then
264             echo "Uninstalling User components"
265             do_uninstall $UMLOG
266             echo 
267         fi
268     fi
269 }
270
271 # Work out if there are any special instructions.
272 #
273 while [ "$1" ]; do
274     case "$1" in
275     -v|--verbose)
276         VERBOSE=v
277         ;;
278     -r|--root)
279         DISCIMAGE=$2
280         shift;
281         ;;
282     -u|--uninstall)
283         UNINSTALL_ONLY=y
284         ;;
285     -n)
286         DOIT=echo
287         ;;
288     -h | --help | *)
289         usage
290         ;;
291     esac
292     shift
293 done
294
295 if [ ! -z "$DISCIMAGE" ]; then
296
297     if [ ! -d "$DISCIMAGE" ]; then
298        bail "$0: $DISCIMAGE does not exist."
299     fi
300
301     echo
302     if [ $DISCIMAGE == "/" ]; then
303         echo "Installing PowerVR '$PVRVERSION ($PVRBUILD)' locally"
304     else
305         echo "Installing PowerVR '$PVRVERSION ($PVRBUILD)' on $DISCIMAGE"
306     fi
307     echo
308     echo "File system installation root is $DISCIMAGE"
309     echo
310
311     OLDLOG=$DISCIMAGE/powervr_ddk_install.log
312     KMLOG=$DISCIMAGE/powervr_ddk_install_km.log
313     UMLOG=$DISCIMAGE/powervr_ddk_install_um.log
314
315     uninstall_locally
316
317     if [ "$UNINSTALL_ONLY" != "y" ]; then
318         install_locally
319     fi
320
321 else
322     bail "DISCIMAGE must be set for installation to be possible."
323 fi