Commit | Line | Data |
---|---|---|
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 | ||
52 | say () { | |
53 | echo "$*" 2>&1 > /dev/tty | |
54 | } | |
55 | ||
56 | usage() { | |
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 | ||
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 | INPGPIODRV=$1 | |
96 | INPGPIOCONF=$1.conf | |
97 | PROGRAM=$2 | |
98 | OUTPUT=$3 | |
99 | INPDRVR64=$4 | |
100 | if test $# -eq 5 | |
101 | then | |
102 | ARG5=$5 | |
103 | else | |
104 | ARG5=NULL | |
105 | fi | |
106 | ||
107 | if test $# -eq 6 | |
108 | then | |
109 | ARG6=$6 | |
110 | else | |
111 | ARG6=NULL | |
112 | fi | |
113 | ||
114 | DRVRNAME=flashprom | |
115 | DRV=/kernel/drv/$DRVRNAME | |
116 | ||
117 | if [ $ARG5 = SUN4U -0 $ARG6 = SUN4U ] | |
118 | then | |
119 | EDRVRNAM=eeprom | |
120 | EDRV=/kernel/drv/$EDRVRNAM | |
121 | fi | |
122 | ||
123 | GPIODRVRNAME=sb_gpio | |
124 | ||
125 | check $INPGPIODRV | |
126 | check $INPGPIOCONF | |
127 | check $INPDRVR64 | |
128 | check $PROGRAM | |
129 | ||
130 | cat << SEND > $OUTPUT | |
131 | #!/bin/sh | |
132 | ||
133 | # | |
134 | # Copyright 1995-2000,2002 Sun Microsystems, Inc. | |
135 | # All Rights Reserved | |
136 | # | |
137 | ||
138 | textdom="SUNW_UXFL_DTOP" | |
139 | ||
140 | echo "" | |
141 | echo \`gettext \$textdom \\ | |
142 | "Flash Update 2.4: Program and system initialization in progress..."\` | |
143 | SEND | |
144 | ||
145 | if [ $ARG5 = OPS -0 $ARG6 = OPS ] | |
146 | then | |
147 | ||
148 | cat << SEND >> $OUTPUT | |
149 | echo "" | |
150 | echo "This version of the flash update utility is intended for" | |
151 | echo "use within Sun Microsystems' Operations groups only. It" | |
152 | echo "is not intended for use by other groups within Sun or by" | |
153 | echo "customers external to Sun." | |
154 | echo "" | |
155 | SEND | |
156 | ||
157 | fi | |
158 | ||
159 | cat << SEND >> $OUTPUT | |
160 | ||
161 | PATH=/usr/bin:/usr/sbin:/sbin | |
162 | export PATH | |
163 | XDRV=/kernel/drv | |
164 | TMP=/tmp/flash-update.\$\$ | |
165 | ||
166 | if [ -w \$XDRV ] | |
167 | then | |
168 | DRV=\$XDRV/$DRVRNAME | |
169 | if [ $ARG5 = SUN4U -0 $ARG6 = SUN4U ] | |
170 | then | |
171 | EDRV=\$XDRV/$EDRVRNAM | |
172 | fi | |
173 | else | |
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 | |
194 | fi | |
195 | ||
196 | cleanup() { | |
197 | rem_drv $DRVRNAME > /dev/null 2>&1 | |
198 | if [ $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 | ||
211 | trap cleanup 1 2 3 15 | |
212 | ||
213 | mkdir -m 700 \$TMP | |
214 | ||
215 | GPIODRV_UU=\$TMP/sb_gpio.uu | |
216 | GPIOCONF_UU=\$TMP/sb_gpio_conf.uu | |
217 | DRV64_UU=\$TMP/flashprom64.uu | |
218 | ||
219 | $RMF \$GPIODRV_UU \$TMP/sb_gpio.Z \$GPIOCONF_UU | |
220 | $RMF \$DRV64_UU \$TMP/flashprom64.Z | |
221 | ||
222 | cat << END > \$DRV64_UU | |
223 | SEND | |
224 | ||
225 | $RMF \$DRV64_UU | |
226 | ||
227 | compress -cf $INPDRVR64 | uuencode flashprom64.Z \ | |
228 | |sed 's/\\/\\\\/g' \ | |
229 | |sed 's/\$/\\$/g' \ | |
230 | >> $OUTPUT | |
231 | ||
232 | cat << SEND >> $OUTPUT | |
233 | END | |
234 | ||
235 | ||
236 | # gpio driver (64-bit only) | |
237 | cat << END >\$GPIODRV_UU | |
238 | SEND | |
239 | ||
240 | $RMF \$GPIODRV_UU | |
241 | ||
242 | compress -cf $INPGPIODRV | uuencode sb_gpio64.Z \ | |
243 | |sed 's/\\/\\\\/g' \ | |
244 | |sed 's/\$/\\$/g' \ | |
245 | >> $OUTPUT | |
246 | ||
247 | cat << SEND >> $OUTPUT | |
248 | END | |
249 | ||
250 | # gpio driver conf file | |
251 | cat << END >\$GPIOCONF_UU | |
252 | SEND | |
253 | ||
254 | $RMF \$GPIOCONF_UU | |
255 | ||
256 | compress -cf $INPGPIOCONF | uuencode sb_gpio_conf.Z \ | |
257 | |sed 's/\\/\\\\/g' \ | |
258 | |sed 's/\$/\\$/g' \ | |
259 | >> $OUTPUT | |
260 | ||
261 | cat << SEND >> $OUTPUT | |
262 | END | |
263 | ||
264 | OUR_CWD=\`pwd\` | |
265 | ||
266 | rem_drv $DRVRNAME > /dev/null 2>&1 | |
267 | rem_drv $GPIODRVRNAME > /dev/null 2>&1 | |
268 | ||
269 | if [ $ARG5 = SUN4U -0 $ARG6 = SUN4U ] | |
270 | then | |
271 | rem_drv $EDRVRNAM > /dev/null 2>&1 | |
272 | fi | |
273 | ||
274 | $RMF \$DRV | |
275 | if [ $ARG5 = SUN4U -0 $ARG6 = SUN4U ] | |
276 | then | |
277 | $RMF \$EDRV | |
278 | fi | |
279 | if [ -d /kernel/drv/sparcv9 ] | |
280 | then | |
281 | $RMF /kernel/drv/sparcv9/$DRVRNAME | |
282 | $RMF /kernel/drv/sparcv9/$GPIODRVRNAME | |
283 | $RMF /kernel/drv/$GPIODRVRNAME.conf | |
284 | $RMF /kernel/drv/$DRVRNAME.conf | |
285 | if [ $ARG5 = SUN4U -0 $ARG6 = SUN4U ] | |
286 | then | |
287 | $RMF /kernel/drv/sparcv9/$EDRVRNAM | |
288 | fi | |
289 | fi | |
290 | ||
291 | cd \$TMP; uudecode \$GPIODRV_UU ; uncompress sb_gpio64.Z | |
292 | cd \$TMP; uudecode \$GPIOCONF_UU ; uncompress sb_gpio_conf.Z | |
293 | cd \$TMP; uudecode \$DRV64_UU ; uncompress flashprom64.Z | |
294 | cd \$OUR_CWD | |
295 | ||
296 | if [ -d /kernel/drv/sparcv9 ] | |
297 | then | |
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 | ||
308 | else | |
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 | |
313 | fi | |
314 | ||
315 | $RMF \$GPIODRV_UU \$TMP/sb_gpio64.Z \$DRV64_UU \$TMP/flashprom64.Z | |
316 | $RMF \$GPIOCONF_UU \$TMP/sb_gpio_conf.Z | |
317 | ||
318 | add_drv $DRVRNAME | |
319 | add_drv $GPIODRVRNAME | |
320 | ||
321 | if [ $ARG5 = SUN4U -0 $ARG6 = SUN4U ] | |
322 | then | |
323 | add_drv $EDRVRNAM | |
324 | fi | |
325 | ||
326 | AWKSCR=\$TMP/awk.\$$ | |
327 | cat <<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 | ||
333 | EOF | |
334 | ||
335 | AWKSCRE=\$TMP/awke.\$$ | |
336 | cat <<EOF > \$AWKSCRE | |
337 | { | |
338 | printf "rm -f /dev/eeprom\n"; | |
339 | printf "ln -s %s:%s /dev/eeprom\n", \\\$1, \\\$2; | |
340 | } | |
341 | ||
342 | EOF | |
343 | ||
344 | AWKSCRG=\$TMP/awkg.\$$ | |
345 | cat <<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 | ||
351 | EOF | |
352 | ||
353 | make_link() { | |
354 | ( | |
355 | cd /devices | |
356 | find ../devices -name "flashprom@*:\$1" -exec echo {} \; \ | |
357 | |awk -F: -f \$AWKSCR | /bin/sh | |
358 | find ../devices -name "sb_gpio@*" -exec echo {} \; \ | |
359 | |awk -F: -f \$AWKSCRG | /bin/sh | |
360 | if [ $ARG5 = SUN4U -0 $ARG6 = SUN4U ] | |
361 | then | |
362 | find ../devices -name "eeprom@*:\$1" -exec echo {} \; \ | |
363 | |awk -F: -f \$AWKSCRE | /bin/sh | |
364 | fi | |
365 | ) | |
366 | } | |
367 | ||
368 | make_link 0 | |
369 | ||
370 | $RMF \$AWKSCR | |
371 | if [ $ARG5 = SUN4U -0 $ARG6 = SUN4U ] | |
372 | then | |
373 | $RMF \$AWKSCRE | |
374 | fi | |
375 | ||
376 | PRG_UU=\$TMP/flash-update.uu | |
377 | ||
378 | $RMF \$PRG_UU \$TMP/flash-update.Z | |
379 | cat << END > \$PRG_UU | |
380 | SEND | |
381 | ||
382 | $RMF \$PRG_UU \$TMP/flash-update.Z | |
383 | ||
384 | compress -cf $PROGRAM | uuencode flash-update.Z \ | |
385 | |sed 's/\\/\\\\/g' \ | |
386 | |sed 's/\$/\\$/g' \ | |
387 | >> $OUTPUT | |
388 | ||
389 | ||
390 | cat << SEND >> $OUTPUT | |
391 | END | |
392 | ||
393 | cd \$TMP; uudecode \$PRG_UU ; uncompress flash-update.Z ; \ | |
394 | chmod u+x flash-update | |
395 | cd \$OUR_CWD | |
396 | $RMF \$PRG_UU \$TMP/flash-update.Z | |
397 | ||
398 | \$TMP/flash-update | |
399 | exitval=\$? | |
400 | ||
401 | cleanup | |
402 | ||
403 | if [ \$exitval -eq 25 ] | |
404 | then | |
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 | |
408 | fi | |
409 | ||
410 | ||
411 | SEND | |
412 | ||
413 | if [ $ARG5 = OPS -0 $ARG6 = OPS ] | |
414 | then | |
415 | #******ifthen-else-fi intentionally not indented****** | |
416 | # For Ops, always exit such that a reboot is never issued. | |
417 | ||
418 | cat << SEND >> $OUTPUT | |
419 | exit \$exitval | |
420 | SEND | |
421 | ||
422 | else | |
423 | ||
424 | cat << SEND >> $OUTPUT | |
425 | if [ \$exitval -ne 0 ] | |
426 | then | |
427 | exit \$exitval | |
428 | fi | |
429 | ||
430 | echo "" | |
431 | echo \`gettext \$textdom \\ | |
432 | "Please wait while the system is rebooted..."\` | |
433 | echo "" | |
434 | /etc/shutdown -i6 -g0 -y | |
435 | ||
436 | SEND | |
437 | ||
438 | fi |