Initial commit of OpenSPARC T2 architecture model.
[OpenSPARC-T2-SAM] / obp / tools / jbos_mkflash.sh
CommitLineData
920dae64
AT
1#!/bin/sh
2# ========== Copyright Header Begin ==========================================
3#
4# Hypervisor Software File: jbos_mkflash.sh
5#
6# Copyright (c) 2006 Sun Microsystems, Inc. All Rights Reserved.
7#
8# - Do no alter or remove copyright notices
9#
10# - Redistribution and use of this software in source and binary forms, with
11# or without modification, are permitted provided that the following
12# conditions are met:
13#
14# - Redistribution of source code must retain the above copyright notice,
15# this list of conditions and the following disclaimer.
16#
17# - Redistribution in binary form must reproduce the above copyright notice,
18# this list of conditions and the following disclaimer in the
19# documentation and/or other materials provided with the distribution.
20#
21# Neither the name of Sun Microsystems, Inc. or the names of contributors
22# may be used to endorse or promote products derived from this software
23# without specific prior written permission.
24#
25# This software is provided "AS IS," without a warranty of any kind.
26# ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES,
27# INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A
28# PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN
29# MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR
30# ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
31# DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN
32# OR ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR
33# FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE
34# DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY,
35# ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF
36# SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
37#
38# You acknowledge that this software is not designed, licensed or
39# intended for use in the design, construction, operation or maintenance of
40# any nuclear facility.
41#
42# ========== Copyright Header End ============================================
43
44#
45# id: @(#)jbos_mkflash.sh 1.1 02/11/08
46# purpose: Stiletto-specific version of the mkflash script.
47# purpose: Builds the final script for the OS-level Flash PROM Update Utility
48# copyright: Copyright 2002 Sun Microsystems, Inc. All Rights Reserved
49# copyright: Use is subject to license terms.
50#
51
52say () {
53 echo "$*" 2>&1 > /dev/tty
54}
55
56usage() {
57 say "mkflash <in: gpio drvr name> <in: update prog name> <out: filename>" say " <in: drvr name 64b> [ OPS ] [ SUN4U ]"
58 exit 1;
59}
60
61check() {
62 if [ ! -f $1 ];
63 then
64 say $1: No such file or directory
65 exit 1
66 fi
67}
68
69PATH=/usr/bin:/usr/sbin:/sbin
70export PATH
71RMF="rm -f"
72RMRF="rm -rf"
73
74cleanup() {
75 $RMF $OUTPUT
76}
77
78trap cleanup 1 2 3 15
79
80if test $# -lt 4
81then
82 usage
83fi
84if test $# -gt 6
85then
86 usage
87fi
88# Note that there will normally be 4 args, as shown in usage(). However,
89# for Ops, a 5th arg may be passed in which, if it is "OPS", will cause
90# the final script to be created such that a final reboot is not issued.
91# Also the SUN4U flag may be provided, which causes the kernel nvram driver
92# to be added as "eeprom" (sun4s doesn't have an eeprom node and so by
93# default the eeprom driver does not get added).
94
95INPGPIODRV=$1
96INPGPIOCONF=$1.conf
97PROGRAM=$2
98OUTPUT=$3
99INPDRVR64=$4
100if test $# -eq 5
101then
102 ARG5=$5
103else
104 ARG5=NULL
105fi
106
107if test $# -eq 6
108then
109 ARG6=$6
110else
111 ARG6=NULL
112fi
113
114DRVRNAME=flashprom
115DRV=/kernel/drv/$DRVRNAME
116
117if [ $ARG5 = SUN4U -0 $ARG6 = SUN4U ]
118then
119EDRVRNAM=eeprom
120EDRV=/kernel/drv/$EDRVRNAM
121fi
122
123GPIODRVRNAME=sb_gpio
124
125check $INPGPIODRV
126check $INPGPIOCONF
127check $INPDRVR64
128check $PROGRAM
129
130cat << SEND > $OUTPUT
131#!/bin/sh
132
133#
134# Copyright 1995-2000,2002 Sun Microsystems, Inc.
135# All Rights Reserved
136#
137
138textdom="SUNW_UXFL_DTOP"
139
140echo ""
141echo \`gettext \$textdom \\
142"Flash Update 2.4: Program and system initialization in progress..."\`
143SEND
144
145if [ $ARG5 = OPS -0 $ARG6 = OPS ]
146then
147
148cat << SEND >> $OUTPUT
149echo ""
150echo "This version of the flash update utility is intended for"
151echo "use within Sun Microsystems' Operations groups only. It"
152echo "is not intended for use by other groups within Sun or by"
153echo "customers external to Sun."
154echo ""
155SEND
156
157fi
158
159cat << SEND >> $OUTPUT
160
161PATH=/usr/bin:/usr/sbin:/sbin
162export PATH
163XDRV=/kernel/drv
164TMP=/tmp/flash-update.\$\$
165
166if [ -w \$XDRV ]
167then
168 DRV=\$XDRV/$DRVRNAME
169if [ $ARG5 = SUN4U -0 $ARG6 = SUN4U ]
170then
171 EDRV=\$XDRV/$EDRVRNAM
172fi
173else
174# backup driver location is for OPS, since their systems usually run
175# as clients, and thus don't have a /usr/kernel/drv.
176 ALTDRVPATH=/platform/sun4u/kernel/drv
177 if [ -w \$ALTDRVPATH ]
178 then
179 echo \`gettext \$textdom "\$XDRV does not exist or is not writable:"\`
180 echo \`gettext \$textdom "Driver is now located at \$ALTDRVPATH ."\`
181 DRV=\$ALTDRVPATH/$DRVRNAME
182 EDRV=\$ALTDRVPATH/$EDRVRNAM
183 else
184 echo
185 echo \`gettext \$textdom "Could not find a writable driver location;"\`
186 echo \`gettext \$textdom " \$XDRV"\`
187 echo \`gettext \$textdom " \$ALTDRVPATH"\`
188 echo \`gettext \$textdom "\(Be sure the program is run as root.\)"\`
189 echo
190 echo \`gettext \$textdom "The flash PROM update was not successful."\`
191 echo
192 exit 1
193 fi
194fi
195
196cleanup() {
197rem_drv $DRVRNAME > /dev/null 2>&1
198if [ $ARG5 = SUN4U -0 $ARG6 = SUN4U ]
199 then
200 rem_drv $EDRVRNAM > /dev/null 2>&1
201 $RMF /dev/eeprom
202 $RMF \$EDRV
203 fi
204 $RMF /dev/flashprom:?
205 $RMF \$DRV
206 $RMF \$DRV.conf
207 $RMF /kernel/drv/$GPIODRVRNAME.conf
208 $RMRF \$TMP
209}
210
211trap cleanup 1 2 3 15
212
213mkdir -m 700 \$TMP
214
215GPIODRV_UU=\$TMP/sb_gpio.uu
216GPIOCONF_UU=\$TMP/sb_gpio_conf.uu
217DRV64_UU=\$TMP/flashprom64.uu
218
219$RMF \$GPIODRV_UU \$TMP/sb_gpio.Z \$GPIOCONF_UU
220$RMF \$DRV64_UU \$TMP/flashprom64.Z
221
222cat << END > \$DRV64_UU
223SEND
224
225$RMF \$DRV64_UU
226
227compress -cf $INPDRVR64 | uuencode flashprom64.Z \
228 |sed 's/\\/\\\\/g' \
229 |sed 's/\$/\\$/g' \
230 >> $OUTPUT
231
232cat << SEND >> $OUTPUT
233END
234
235
236# gpio driver (64-bit only)
237cat << END >\$GPIODRV_UU
238SEND
239
240$RMF \$GPIODRV_UU
241
242compress -cf $INPGPIODRV | uuencode sb_gpio64.Z \
243 |sed 's/\\/\\\\/g' \
244 |sed 's/\$/\\$/g' \
245 >> $OUTPUT
246
247cat << SEND >> $OUTPUT
248END
249
250# gpio driver conf file
251cat << END >\$GPIOCONF_UU
252SEND
253
254$RMF \$GPIOCONF_UU
255
256compress -cf $INPGPIOCONF | uuencode sb_gpio_conf.Z \
257 |sed 's/\\/\\\\/g' \
258 |sed 's/\$/\\$/g' \
259 >> $OUTPUT
260
261cat << SEND >> $OUTPUT
262END
263
264OUR_CWD=\`pwd\`
265
266rem_drv $DRVRNAME > /dev/null 2>&1
267rem_drv $GPIODRVRNAME > /dev/null 2>&1
268
269if [ $ARG5 = SUN4U -0 $ARG6 = SUN4U ]
270then
271rem_drv $EDRVRNAM > /dev/null 2>&1
272fi
273
274$RMF \$DRV
275if [ $ARG5 = SUN4U -0 $ARG6 = SUN4U ]
276then
277$RMF \$EDRV
278fi
279if [ -d /kernel/drv/sparcv9 ]
280then
281 $RMF /kernel/drv/sparcv9/$DRVRNAME
282 $RMF /kernel/drv/sparcv9/$GPIODRVRNAME
283 $RMF /kernel/drv/$GPIODRVRNAME.conf
284 $RMF /kernel/drv/$DRVRNAME.conf
285if [ $ARG5 = SUN4U -0 $ARG6 = SUN4U ]
286then
287 $RMF /kernel/drv/sparcv9/$EDRVRNAM
288fi
289fi
290
291cd \$TMP; uudecode \$GPIODRV_UU ; uncompress sb_gpio64.Z
292cd \$TMP; uudecode \$GPIOCONF_UU ; uncompress sb_gpio_conf.Z
293cd \$TMP; uudecode \$DRV64_UU ; uncompress flashprom64.Z
294cd \$OUR_CWD
295
296if [ -d /kernel/drv/sparcv9 ]
297then
298
299 if [ $ARG5 = SUN4U -0 $ARG6 = SUN4U ]
300 then
301 cp -p \$TMP/flashprom64 /kernel/drv/sparcv9/$EDRVRNAM
302 fi
303 mv -f \$TMP/flashprom64 /kernel/drv/sparcv9/$DRVRNAME
304 mv -f \$TMP/sb_gpio64 /kernel/drv/sparcv9/$GPIODRVRNAME
305 mv -f \$TMP/sb_gpio_conf /kernel/drv/$GPIODRVRNAME.conf
306
307
308else
309 $RMF \$TMP/flashprom64
310 echo \`gettext \$textdom "Flash Update 2.4: 64-bit kernel is required."\`
311 echo \`gettext \$textdom "The flash PROM update was not successful."\`
312 exit 1
313fi
314
315$RMF \$GPIODRV_UU \$TMP/sb_gpio64.Z \$DRV64_UU \$TMP/flashprom64.Z
316$RMF \$GPIOCONF_UU \$TMP/sb_gpio_conf.Z
317
318add_drv $DRVRNAME
319add_drv $GPIODRVRNAME
320
321if [ $ARG5 = SUN4U -0 $ARG6 = SUN4U ]
322then
323add_drv $EDRVRNAM
324fi
325
326AWKSCR=\$TMP/awk.\$$
327cat <<EOF > \$AWKSCR
328{
329 printf "rm -f /dev/flashprom:%s\n", \\\$2;
330 printf "ln -s %s:%s /dev/flashprom:%s\n", \\\$1, \\\$2, \\\$2;
331}
332
333EOF
334
335AWKSCRE=\$TMP/awke.\$$
336cat <<EOF > \$AWKSCRE
337{
338 printf "rm -f /dev/eeprom\n";
339 printf "ln -s %s:%s /dev/eeprom\n", \\\$1, \\\$2;
340}
341
342EOF
343
344AWKSCRG=\$TMP/awkg.\$$
345cat <<EOF > \$AWKSCRG
346{
347 printf "rm -f /dev/sb_gpio\n";
348 printf "ln -s %s:%s /dev/sb_gpio\n", \\\$1, \\\$2;
349}
350
351EOF
352
353make_link() {
354(
355cd /devices
356find ../devices -name "flashprom@*:\$1" -exec echo {} \; \
357 |awk -F: -f \$AWKSCR | /bin/sh
358find ../devices -name "sb_gpio@*" -exec echo {} \; \
359 |awk -F: -f \$AWKSCRG | /bin/sh
360if [ $ARG5 = SUN4U -0 $ARG6 = SUN4U ]
361then
362find ../devices -name "eeprom@*:\$1" -exec echo {} \; \
363 |awk -F: -f \$AWKSCRE | /bin/sh
364fi
365)
366}
367
368make_link 0
369
370$RMF \$AWKSCR
371if [ $ARG5 = SUN4U -0 $ARG6 = SUN4U ]
372then
373$RMF \$AWKSCRE
374fi
375
376PRG_UU=\$TMP/flash-update.uu
377
378$RMF \$PRG_UU \$TMP/flash-update.Z
379cat << END > \$PRG_UU
380SEND
381
382$RMF \$PRG_UU \$TMP/flash-update.Z
383
384compress -cf $PROGRAM | uuencode flash-update.Z \
385 |sed 's/\\/\\\\/g' \
386 |sed 's/\$/\\$/g' \
387 >> $OUTPUT
388
389
390cat << SEND >> $OUTPUT
391END
392
393cd \$TMP; uudecode \$PRG_UU ; uncompress flash-update.Z ; \
394chmod u+x flash-update
395cd \$OUR_CWD
396$RMF \$PRG_UU \$TMP/flash-update.Z
397
398\$TMP/flash-update
399exitval=\$?
400
401cleanup
402
403if [ \$exitval -eq 25 ]
404then
405# Exit status to indicate that the user chose to exit without doing the
406# update - this is necessary so that a reboot is not issued.
407 exit 0
408fi
409
410
411SEND
412
413if [ $ARG5 = OPS -0 $ARG6 = OPS ]
414then
415#******ifthen-else-fi intentionally not indented******
416# For Ops, always exit such that a reboot is never issued.
417
418cat << SEND >> $OUTPUT
419exit \$exitval
420SEND
421
422else
423
424cat << SEND >> $OUTPUT
425if [ \$exitval -ne 0 ]
426then
427 exit \$exitval
428fi
429
430echo ""
431echo \`gettext \$textdom \\
432"Please wait while the system is rebooted..."\`
433echo ""
434/etc/shutdown -i6 -g0 -y
435
436SEND
437
438fi