Commit | Line | Data |
---|---|---|
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 | ||
51 | say () { | |
52 | echo "$*" 2>&1 > /dev/tty | |
53 | } | |
54 | ||
55 | usage() { | |
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 | ||
61 | check() { | |
62 | if [ ! -f $1 ]; | |
63 | then | |
64 | say $1: No such file or directory | |
65 | exit 1 | |
66 | fi | |
67 | } | |
68 | ||
69 | PATH=/usr/bin:/usr/sbin:/sbin | |
70 | export PATH | |
71 | RMF="rm -f" | |
72 | RMRF="rm -rf" | |
73 | ||
74 | cleanup() { | |
75 | $RMF $OUTPUT | |
76 | } | |
77 | ||
78 | trap cleanup 1 2 3 15 | |
79 | ||
80 | if test $# -lt 4 | |
81 | then | |
82 | usage | |
83 | fi | |
84 | if test $# -gt 6 | |
85 | then | |
86 | usage | |
87 | fi | |
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 | ||
95 | INPDRVR32=$1 | |
96 | PROGRAM=$2 | |
97 | OUTPUT=$3 | |
98 | INPDRVR64=$4 | |
99 | if test $# -eq 5 | |
100 | then | |
101 | ARG5=$5 | |
102 | else | |
103 | ARG5=NULL | |
104 | fi | |
105 | ||
106 | if test $# -eq 6 | |
107 | then | |
108 | ARG6=$6 | |
109 | else | |
110 | ARG6=NULL | |
111 | fi | |
112 | ||
113 | DRVRNAME=flashprom | |
114 | DRV=/kernel/drv/$DRVRNAME | |
115 | ||
116 | if [ $ARG5 = SUN4U -0 $ARG6 = SUN4U ] | |
117 | then | |
118 | EDRVRNAM=eeprom | |
119 | EDRV=/kernel/drv/$EDRVRNAM | |
120 | fi | |
121 | ||
122 | check $INPDRVR32 | |
123 | check $INPDRVR64 | |
124 | check $PROGRAM | |
125 | ||
126 | cat << SEND > $OUTPUT | |
127 | #!/bin/sh | |
128 | ||
129 | # | |
130 | # Copyright 1995-2000 Sun Microsystems, Inc. | |
131 | # All Rights Reserved | |
132 | # | |
133 | ||
134 | textdom="SUNW_UXFL_DTOP" | |
135 | ||
136 | echo "" | |
137 | echo \`gettext \$textdom \\ | |
138 | "Flash Update 2.4: Program and system initialization in progress..."\` | |
139 | SEND | |
140 | ||
141 | if [ $ARG5 = OPS -0 $ARG6 = OPS ] | |
142 | then | |
143 | ||
144 | cat << SEND >> $OUTPUT | |
145 | echo "" | |
146 | echo "This version of the flash update utility is intended for" | |
147 | echo "use within Sun Microsystems' Operations groups only. It" | |
148 | echo "is not intended for use by other groups within Sun or by" | |
149 | echo "customers external to Sun." | |
150 | echo "" | |
151 | SEND | |
152 | ||
153 | fi | |
154 | ||
155 | cat << SEND >> $OUTPUT | |
156 | ||
157 | PATH=/usr/bin:/usr/sbin:/sbin | |
158 | export PATH | |
159 | XDRV=/kernel/drv | |
160 | TMP=/tmp/flash-update.\$\$ | |
161 | ||
162 | if [ -w \$XDRV ] | |
163 | then | |
164 | DRV=\$XDRV/$DRVRNAME | |
165 | if [ $ARG5 = SUN4U -0 $ARG6 = SUN4U ] | |
166 | then | |
167 | EDRV=\$XDRV/$EDRVRNAM | |
168 | fi | |
169 | else | |
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 | |
190 | fi | |
191 | ||
192 | cleanup() { | |
193 | rem_drv $DRVRNAME > /dev/null 2>&1 | |
194 | if [ $ARG5 = SUN4U -0 $ARG6 = SUN4U ] | |
195 | then | |
196 | rem_drv $EDRVRNAM > /dev/null 2>&1 | |
197 | $RMF /dev/eeprom | |
198 | $RMF \$EDRV | |
199 | fi | |
200 | $RMF /dev/flashprom:? | |
201 | $RMF \$DRV | |
202 | $RMRF \$TMP | |
203 | } | |
204 | ||
205 | trap cleanup 1 2 3 15 | |
206 | ||
207 | mkdir -m 700 \$TMP | |
208 | ||
209 | DRV32_UU=\$TMP/flashprom32.uu | |
210 | DRV64_UU=\$TMP/flashprom64.uu | |
211 | ||
212 | $RMF \$DRV32_UU \$TMP/flashprom64.Z | |
213 | $RMF \$DRV64_UU \$TMP/flashprom32.Z | |
214 | ||
215 | cat << END > \$DRV32_UU | |
216 | SEND | |
217 | ||
218 | $RMF \$DRV32_UU | |
219 | ||
220 | compress -cf $INPDRVR32 | uuencode flashprom32.Z \ | |
221 | |sed 's/\\/\\\\/g' \ | |
222 | |sed 's/\$/\\$/g' \ | |
223 | >> $OUTPUT | |
224 | ||
225 | cat << SEND >> $OUTPUT | |
226 | END | |
227 | ||
228 | cat << END > \$DRV64_UU | |
229 | SEND | |
230 | ||
231 | $RMF \$DRV64_UU | |
232 | ||
233 | compress -cf $INPDRVR64 | uuencode flashprom64.Z \ | |
234 | |sed 's/\\/\\\\/g' \ | |
235 | |sed 's/\$/\\$/g' \ | |
236 | >> $OUTPUT | |
237 | ||
238 | cat << SEND >> $OUTPUT | |
239 | END | |
240 | ||
241 | OUR_CWD=\`pwd\` | |
242 | ||
243 | rem_drv $DRVRNAME > /dev/null 2>&1 | |
244 | ||
245 | if [ $ARG5 = SUN4U -0 $ARG6 = SUN4U ] | |
246 | then | |
247 | rem_drv $EDRVRNAM > /dev/null 2>&1 | |
248 | fi | |
249 | ||
250 | $RMF \$DRV | |
251 | if [ $ARG5 = SUN4U -0 $ARG6 = SUN4U ] | |
252 | then | |
253 | $RMF \$EDRV | |
254 | fi | |
255 | if [ -d /kernel/drv/sparcv9 ] | |
256 | then | |
257 | $RMF /kernel/drv/sparcv9/$DRVRNAME | |
258 | if [ $ARG5 = SUN4U -0 $ARG6 = SUN4U ] | |
259 | then | |
260 | $RMF /kernel/drv/sparcv9/$EDRVRNAM | |
261 | fi | |
262 | fi | |
263 | ||
264 | cd \$TMP; uudecode \$DRV32_UU ; uncompress flashprom32.Z | |
265 | cd \$TMP; uudecode \$DRV64_UU ; uncompress flashprom64.Z | |
266 | cd \$OUR_CWD | |
267 | ||
268 | if [ $ARG5 = SUN4U -0 $ARG6 = SUN4U ] | |
269 | then | |
270 | cp -p \$TMP/flashprom32 \$EDRV | |
271 | fi | |
272 | mv -f \$TMP/flashprom32 \$DRV | |
273 | if [ -d /kernel/drv/sparcv9 ] | |
274 | then | |
275 | ||
276 | if [ $ARG5 = SUN4U -0 $ARG6 = SUN4U ] | |
277 | then | |
278 | cp -p \$TMP/flashprom64 /kernel/drv/sparcv9/$EDRVRNAM | |
279 | fi | |
280 | mv -f \$TMP/flashprom64 /kernel/drv/sparcv9/$DRVRNAME | |
281 | else | |
282 | $RMF \$TMP/flashprom64 | |
283 | fi | |
284 | ||
285 | $RMF \$DRV32_UU \$TMP/flashprom32.Z \$DRV64_UU \$TMP/flashprom64.Z | |
286 | ||
287 | add_drv $DRVRNAME | |
288 | ||
289 | if [ $ARG5 = SUN4U -0 $ARG6 = SUN4U ] | |
290 | then | |
291 | add_drv $EDRVRNAM | |
292 | fi | |
293 | ||
294 | AWKSCR=\$TMP/awk.\$$ | |
295 | cat <<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 | ||
301 | EOF | |
302 | ||
303 | AWKSCRE=\$TMP/awke.\$$ | |
304 | cat <<EOF > \$AWKSCRE | |
305 | { | |
306 | printf "rm -f /dev/eeprom\n"; | |
307 | printf "ln -s %s:%s /dev/eeprom\n", \\\$1, \\\$2; | |
308 | } | |
309 | ||
310 | EOF | |
311 | ||
312 | make_link() { | |
313 | ( | |
314 | cd /devices | |
315 | find ../devices -name "flashprom@*:\$1" -exec echo {} \; \ | |
316 | |awk -F: -f \$AWKSCR | /bin/sh | |
317 | if [ $ARG5 = SUN4U -0 $ARG6 = SUN4U ] | |
318 | then | |
319 | find ../devices -name "eeprom@*:\$1" -exec echo {} \; \ | |
320 | |awk -F: -f \$AWKSCRE | /bin/sh | |
321 | fi | |
322 | ) | |
323 | } | |
324 | ||
325 | make_link 0 | |
326 | ||
327 | $RMF \$AWKSCR | |
328 | if [ $ARG5 = SUN4U -0 $ARG6 = SUN4U ] | |
329 | then | |
330 | $RMF \$AWKSCRE | |
331 | fi | |
332 | ||
333 | PRG_UU=\$TMP/flash-update.uu | |
334 | ||
335 | $RMF \$PRG_UU \$TMP/flash-update.Z | |
336 | cat << END > \$PRG_UU | |
337 | SEND | |
338 | ||
339 | $RMF \$PRG_UU \$TMP/flash-update.Z | |
340 | ||
341 | compress -cf $PROGRAM | uuencode flash-update.Z \ | |
342 | |sed 's/\\/\\\\/g' \ | |
343 | |sed 's/\$/\\$/g' \ | |
344 | >> $OUTPUT | |
345 | ||
346 | ||
347 | cat << SEND >> $OUTPUT | |
348 | END | |
349 | ||
350 | cd \$TMP; uudecode \$PRG_UU ; uncompress flash-update.Z ; \ | |
351 | chmod u+x flash-update | |
352 | cd \$OUR_CWD | |
353 | $RMF \$PRG_UU \$TMP/flash-update.Z | |
354 | ||
355 | \$TMP/flash-update | |
356 | exitval=\$? | |
357 | ||
358 | cleanup | |
359 | ||
360 | if [ \$exitval -eq 25 ] | |
361 | then | |
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 | |
365 | fi | |
366 | ||
367 | ||
368 | SEND | |
369 | ||
370 | if [ $ARG5 = OPS -0 $ARG6 = OPS ] | |
371 | then | |
372 | #******ifthen-else-fi intentionally not indented****** | |
373 | # For Ops, always exit such that a reboot is never issued. | |
374 | ||
375 | cat << SEND >> $OUTPUT | |
376 | exit \$exitval | |
377 | SEND | |
378 | ||
379 | else | |
380 | ||
381 | cat << SEND >> $OUTPUT | |
382 | if [ \$exitval -ne 0 ] | |
383 | then | |
384 | exit \$exitval | |
385 | fi | |
386 | ||
387 | echo "" | |
388 | echo \`gettext \$textdom \\ | |
389 | "Please wait while the system is rebooted..."\` | |
390 | echo "" | |
391 | /etc/shutdown -i6 -g0 -y | |
392 | ||
393 | SEND | |
394 | ||
395 | fi |