Initial commit of OpenSPARC T2 architecture model.
[OpenSPARC-T2-SAM] / obp / tools / mkflash.sh
CommitLineData
920dae64
AT
1#!/bin/sh
2# ========== Copyright Header Begin ==========================================
3#
4# Hypervisor Software File: 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: @(#)mkflash.sh 1.18 01/12/21
46# purpose: Builds the final script for the OS-level Flash PROM Update Utility
47# copyright: Copyright 1995-2001 Sun Microsystems, Inc.
48# All Rights Reserved
49#
50
51say () {
52 echo "$*" 2>&1 > /dev/tty
53}
54
55usage() {
56 say "mkflash <in: drvr name 32b> <in: update prog name> <out: filename>"
57 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
95INPDRVR32=$1
96PROGRAM=$2
97OUTPUT=$3
98INPDRVR64=$4
99if test $# -eq 5
100then
101 ARG5=$5
102else
103 ARG5=NULL
104fi
105
106if test $# -eq 6
107then
108 ARG6=$6
109else
110 ARG6=NULL
111fi
112
113DRVRNAME=flashprom
114DRV=/kernel/drv/$DRVRNAME
115
116if [ $ARG5 = SUN4U -0 $ARG6 = SUN4U ]
117then
118EDRVRNAM=eeprom
119EDRV=/kernel/drv/$EDRVRNAM
120fi
121
122check $INPDRVR32
123check $INPDRVR64
124check $PROGRAM
125
126cat << SEND > $OUTPUT
127#!/bin/sh
128
129#
130# Copyright 1995-2000 Sun Microsystems, Inc.
131# All Rights Reserved
132#
133
134textdom="SUNW_UXFL_DTOP"
135
136echo ""
137echo \`gettext \$textdom \\
138"Flash Update 2.4: Program and system initialization in progress..."\`
139SEND
140
141if [ $ARG5 = OPS -0 $ARG6 = OPS ]
142then
143
144cat << SEND >> $OUTPUT
145echo ""
146echo "This version of the flash update utility is intended for"
147echo "use within Sun Microsystems' Operations groups only. It"
148echo "is not intended for use by other groups within Sun or by"
149echo "customers external to Sun."
150echo ""
151SEND
152
153fi
154
155cat << SEND >> $OUTPUT
156
157PATH=/usr/bin:/usr/sbin:/sbin
158export PATH
159XDRV=/kernel/drv
160TMP=/tmp/flash-update.\$\$
161
162if [ -w \$XDRV ]
163then
164 DRV=\$XDRV/$DRVRNAME
165if [ $ARG5 = SUN4U -0 $ARG6 = SUN4U ]
166then
167 EDRV=\$XDRV/$EDRVRNAM
168fi
169else
170# backup driver location is for OPS, since their systems usually run
171# as clients, and thus don't have a /usr/kernel/drv.
172 ALTDRVPATH=/platform/sun4u/kernel/drv
173 if [ -w \$ALTDRVPATH ]
174 then
175 echo \`gettext \$textdom "\$XDRV does not exist or is not writable:"\`
176 echo \`gettext \$textdom "Driver is now located at \$ALTDRVPATH ."\`
177 DRV=\$ALTDRVPATH/$DRVRNAME
178 EDRV=\$ALTDRVPATH/$EDRVRNAM
179 else
180 echo
181 echo \`gettext \$textdom "Could not find a writable driver location;"\`
182 echo \`gettext \$textdom " \$XDRV"\`
183 echo \`gettext \$textdom " \$ALTDRVPATH"\`
184 echo \`gettext \$textdom "\(Be sure the program is run as root.\)"\`
185 echo
186 echo \`gettext \$textdom "The flash PROM update was not successful."\`
187 echo
188 exit 1
189 fi
190fi
191
192cleanup() {
193 rem_drv $DRVRNAME > /dev/null 2>&1
194if [ $ARG5 = SUN4U -0 $ARG6 = SUN4U ]
195then
196 rem_drv $EDRVRNAM > /dev/null 2>&1
197 $RMF /dev/eeprom
198 $RMF \$EDRV
199fi
200 $RMF /dev/flashprom:?
201 $RMF \$DRV
202 $RMRF \$TMP
203}
204
205trap cleanup 1 2 3 15
206
207mkdir -m 700 \$TMP
208
209DRV32_UU=\$TMP/flashprom32.uu
210DRV64_UU=\$TMP/flashprom64.uu
211
212$RMF \$DRV32_UU \$TMP/flashprom64.Z
213$RMF \$DRV64_UU \$TMP/flashprom32.Z
214
215cat << END > \$DRV32_UU
216SEND
217
218$RMF \$DRV32_UU
219
220compress -cf $INPDRVR32 | uuencode flashprom32.Z \
221 |sed 's/\\/\\\\/g' \
222 |sed 's/\$/\\$/g' \
223 >> $OUTPUT
224
225cat << SEND >> $OUTPUT
226END
227
228cat << END > \$DRV64_UU
229SEND
230
231$RMF \$DRV64_UU
232
233compress -cf $INPDRVR64 | uuencode flashprom64.Z \
234 |sed 's/\\/\\\\/g' \
235 |sed 's/\$/\\$/g' \
236 >> $OUTPUT
237
238cat << SEND >> $OUTPUT
239END
240
241OUR_CWD=\`pwd\`
242
243rem_drv $DRVRNAME > /dev/null 2>&1
244
245if [ $ARG5 = SUN4U -0 $ARG6 = SUN4U ]
246then
247rem_drv $EDRVRNAM > /dev/null 2>&1
248fi
249
250$RMF \$DRV
251if [ $ARG5 = SUN4U -0 $ARG6 = SUN4U ]
252then
253$RMF \$EDRV
254fi
255if [ -d /kernel/drv/sparcv9 ]
256then
257 $RMF /kernel/drv/sparcv9/$DRVRNAME
258if [ $ARG5 = SUN4U -0 $ARG6 = SUN4U ]
259then
260 $RMF /kernel/drv/sparcv9/$EDRVRNAM
261fi
262fi
263
264cd \$TMP; uudecode \$DRV32_UU ; uncompress flashprom32.Z
265cd \$TMP; uudecode \$DRV64_UU ; uncompress flashprom64.Z
266cd \$OUR_CWD
267
268if [ $ARG5 = SUN4U -0 $ARG6 = SUN4U ]
269then
270cp -p \$TMP/flashprom32 \$EDRV
271fi
272mv -f \$TMP/flashprom32 \$DRV
273if [ -d /kernel/drv/sparcv9 ]
274then
275
276if [ $ARG5 = SUN4U -0 $ARG6 = SUN4U ]
277then
278 cp -p \$TMP/flashprom64 /kernel/drv/sparcv9/$EDRVRNAM
279fi
280 mv -f \$TMP/flashprom64 /kernel/drv/sparcv9/$DRVRNAME
281else
282 $RMF \$TMP/flashprom64
283fi
284
285$RMF \$DRV32_UU \$TMP/flashprom32.Z \$DRV64_UU \$TMP/flashprom64.Z
286
287add_drv $DRVRNAME
288
289if [ $ARG5 = SUN4U -0 $ARG6 = SUN4U ]
290then
291add_drv $EDRVRNAM
292fi
293
294AWKSCR=\$TMP/awk.\$$
295cat <<EOF > \$AWKSCR
296{
297 printf "rm -f /dev/flashprom:%s\n", \\\$2;
298 printf "ln -s %s:%s /dev/flashprom:%s\n", \\\$1, \\\$2, \\\$2;
299}
300
301EOF
302
303AWKSCRE=\$TMP/awke.\$$
304cat <<EOF > \$AWKSCRE
305{
306 printf "rm -f /dev/eeprom\n";
307 printf "ln -s %s:%s /dev/eeprom\n", \\\$1, \\\$2;
308}
309
310EOF
311
312make_link() {
313(
314cd /devices
315find ../devices -name "flashprom@*:\$1" -exec echo {} \; \
316 |awk -F: -f \$AWKSCR | /bin/sh
317if [ $ARG5 = SUN4U -0 $ARG6 = SUN4U ]
318then
319find ../devices -name "eeprom@*:\$1" -exec echo {} \; \
320 |awk -F: -f \$AWKSCRE | /bin/sh
321fi
322)
323}
324
325make_link 0
326
327$RMF \$AWKSCR
328if [ $ARG5 = SUN4U -0 $ARG6 = SUN4U ]
329then
330$RMF \$AWKSCRE
331fi
332
333PRG_UU=\$TMP/flash-update.uu
334
335$RMF \$PRG_UU \$TMP/flash-update.Z
336cat << END > \$PRG_UU
337SEND
338
339$RMF \$PRG_UU \$TMP/flash-update.Z
340
341compress -cf $PROGRAM | uuencode flash-update.Z \
342 |sed 's/\\/\\\\/g' \
343 |sed 's/\$/\\$/g' \
344 >> $OUTPUT
345
346
347cat << SEND >> $OUTPUT
348END
349
350cd \$TMP; uudecode \$PRG_UU ; uncompress flash-update.Z ; \
351chmod u+x flash-update
352cd \$OUR_CWD
353$RMF \$PRG_UU \$TMP/flash-update.Z
354
355\$TMP/flash-update
356exitval=\$?
357
358cleanup
359
360if [ \$exitval -eq 25 ]
361then
362# Exit status to indicate that the user chose to exit without doing the
363# update - this is necessary so that a reboot is not issued.
364 exit 0
365fi
366
367
368SEND
369
370if [ $ARG5 = OPS -0 $ARG6 = OPS ]
371then
372#******ifthen-else-fi intentionally not indented******
373# For Ops, always exit such that a reboot is never issued.
374
375cat << SEND >> $OUTPUT
376exit \$exitval
377SEND
378
379else
380
381cat << SEND >> $OUTPUT
382if [ \$exitval -ne 0 ]
383then
384 exit \$exitval
385fi
386
387echo ""
388echo \`gettext \$textdom \\
389"Please wait while the system is rebooted..."\`
390echo ""
391/etc/shutdown -i6 -g0 -y
392
393SEND
394
395fi