|
| 1 | +#Number of times to sleep |
| 2 | +BOOT_TIMEOUT="5"; |
| 3 | + |
| 4 | +#Username/password for ssh to BMC machines |
| 5 | +SSHUSER=${SSHUSER:-root}; |
| 6 | +export SSHPASS=${SSHPASS:-0penBmc}; |
| 7 | + |
| 8 | +PFLASH_BINARY=/usr/sbin/pflash |
| 9 | + |
| 10 | +# How do we SSH/SCP in? |
| 11 | +SSHCMD="sshpass -e ssh -l $SSHUSER -o LogLevel=quiet -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no $target"; |
| 12 | + |
| 13 | +IPMI_AUTH="-P ${IPMI_PASS:-0penBmc}" |
| 14 | + |
| 15 | +# Strip control characters from IPMI before grepping? |
| 16 | +STRIP_CONTROL=0 |
| 17 | + |
| 18 | +function sshcmd { |
| 19 | + $SSHCMD $*; |
| 20 | +} |
| 21 | + |
| 22 | +# remotecp file target target_location |
| 23 | +function remotecp { |
| 24 | + sshpass -e scp -o User=$SSHUSER -o LogLevel=quiet -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no $1 $2:$3 |
| 25 | +} |
| 26 | + |
| 27 | +function is_off { |
| 28 | + return $([ "$($SSHCMD /usr/sbin/obmcutil power|grep 'state')" = "state = 0" ]); |
| 29 | +} |
| 30 | + |
| 31 | +function poweroff { |
| 32 | + $SSHCMD /usr/sbin/obmcutil poweroff |
| 33 | + # give it some time |
| 34 | + sleep 5 |
| 35 | +} |
| 36 | + |
| 37 | +function force_primary_side { |
| 38 | + true |
| 39 | +} |
| 40 | + |
| 41 | +function flash { |
| 42 | + if [ ! -z "$PNOR" ]; then |
| 43 | + remotecp $PNOR $target /tmp/image.pnor; |
| 44 | + fi |
| 45 | + if [ "${LID[0]}" != "" ]; then |
| 46 | + remotecp ${LID[0]} $target /tmp/skiboot.lid; |
| 47 | + fi |
| 48 | + if [ "${LID[1]}" != "" ]; then |
| 49 | + remotecp ${LID[1]} $target /tmp/bootkernel |
| 50 | + fi |
| 51 | + if [ "${arbitrary_lid[1]}" != "" ]; then |
| 52 | + remotecp ${arbitrary_lid[1]} $target /tmp/$(basename ${arbitrary_lid[1]}) |
| 53 | + fi |
| 54 | + |
| 55 | + if [ "$?" -ne "0" ] ; then |
| 56 | + error "Couldn't copy firmware image"; |
| 57 | + fi |
| 58 | + |
| 59 | + if [ ! -z "$PNOR" ]; then |
| 60 | + msg "Flashing full PNOR" |
| 61 | + $SSHCMD "$PFLASH_BINARY -E -f -p /tmp/image.pnor" |
| 62 | + if [ "$?" -ne "0" ] ; then |
| 63 | + error "An unexpected pflash error has occurred"; |
| 64 | + fi |
| 65 | + msg "Removing /tmp/image.pnor" |
| 66 | + $SSHCMD "rm /tmp/image.pnor" |
| 67 | + fi |
| 68 | + |
| 69 | + if [ ! -z "${LID[0]}" ] ; then |
| 70 | + msg "Flashing PAYLOAD PNOR partition" |
| 71 | + $SSHCMD "$PFLASH_BINARY -e -f -P PAYLOAD -p /tmp/skiboot.lid" |
| 72 | + if [ "$?" -ne "0" ] ; then |
| 73 | + error "An unexpected pflash error has occurred"; |
| 74 | + fi |
| 75 | + msg "Removing /tmp/pskiboot.lid" |
| 76 | + $SSHCMD "rm /tmp/skiboot.lid" |
| 77 | + fi |
| 78 | + |
| 79 | + if [ ! -z "${LID[1]}" ] ; then |
| 80 | + msg "Flashing BOOTKERNEL PNOR partition" |
| 81 | + $SSHCMD "$PFLASH_BINARY -e -f -P BOOTKERNEL -p /tmp/bootkernel" |
| 82 | + if [ "$?" -ne "0" ] ; then |
| 83 | + error "An unexpected pflash error has occurred"; |
| 84 | + fi |
| 85 | + msg "Removing /tmp/bootkernel" |
| 86 | + $SSHCMD "rm /tmp/bootkernel" |
| 87 | + fi |
| 88 | + |
| 89 | + if [ ! -z "${arbitrary_lid[0]}" -a ! -z "${arbitrary_lid[1]}" ] ; then |
| 90 | + msg "Flashing ${arbitrary_lid[0]} PNOR partition" |
| 91 | + $SSHCMD "$PFLASH_BINARY -e -f -P ${arbitrary_lid[0]} -p /tmp/$(basename ${arbitrary_lid[1]})" |
| 92 | + if [ "$?" -ne "0" ] ; then |
| 93 | + error "An unexpected pflash error has occurred"; |
| 94 | + fi |
| 95 | + msg "Removing /tmp/$(basename ${arbitrary_lid[1]})" |
| 96 | + $SSHCMD "rm /tmp/$(basename ${arbitrary_lid[1]})" |
| 97 | + fi |
| 98 | + |
| 99 | +} |
| 100 | + |
| 101 | +function boot_firmware { |
| 102 | + $SSHCMD /usr/sbin/obmcutil poweron |
| 103 | + i=0; |
| 104 | + while [ "$($SSHCMD /usr/sbin/obmcutil power|grep state)" = "state = 0" -a \( "$i" -lt "$BOOT_TIMEOUT" \) ] ; do |
| 105 | + msg -n "."; |
| 106 | + sleep $BOOT_SLEEP_PERIOD; |
| 107 | + i=$(expr $i + 1); |
| 108 | + done |
| 109 | + if [ "$i" -eq "$BOOT_TIMEOUT" ] ; then |
| 110 | + error "Couldn't power on $target"; |
| 111 | + fi |
| 112 | +} |
| 113 | + |
| 114 | +function machine_sanity_test { |
| 115 | + sshcmd true; |
| 116 | + if [ $? -ne 0 ]; then |
| 117 | + echo "$target: Failed to SSH to $target..." |
| 118 | + echo "$target: Command was: $SSHCMD true" |
| 119 | + error "Try connecting manually to diagnose the issue." |
| 120 | + fi |
| 121 | + # No further sanity tests for BMC machines. |
| 122 | + true |
| 123 | +} |
0 commit comments