diff options
author | Angelos Mouzakitis <a.mouzakitis@virtualopensystems.com> | 2023-10-10 14:33:42 +0000 |
---|---|---|
committer | Angelos Mouzakitis <a.mouzakitis@virtualopensystems.com> | 2023-10-10 14:33:42 +0000 |
commit | af1a266670d040d2f4083ff309d732d648afba2a (patch) | |
tree | 2fc46203448ddcc6f81546d379abfaeb323575e9 /roms/skiboot/external/boot-tests | |
parent | e02cda008591317b1625707ff8e115a4841aa889 (diff) |
Change-Id: Iaf8d18082d3991dec7c0ebbea540f092188eb4ec
Diffstat (limited to 'roms/skiboot/external/boot-tests')
-rw-r--r-- | roms/skiboot/external/boot-tests/bmc_support.sh | 147 | ||||
-rwxr-xr-x | roms/skiboot/external/boot-tests/boot_test.sh | 303 | ||||
-rwxr-xr-x | roms/skiboot/external/boot-tests/extract_gcov.sh | 30 | ||||
-rw-r--r-- | roms/skiboot/external/boot-tests/fsp_support.sh | 178 | ||||
-rw-r--r-- | roms/skiboot/external/boot-tests/openbmc_support.sh | 129 | ||||
-rw-r--r-- | roms/skiboot/external/boot-tests/smc_support.sh | 128 |
6 files changed, 915 insertions, 0 deletions
diff --git a/roms/skiboot/external/boot-tests/bmc_support.sh b/roms/skiboot/external/boot-tests/bmc_support.sh new file mode 100644 index 000000000..82b9e8ece --- /dev/null +++ b/roms/skiboot/external/boot-tests/bmc_support.sh @@ -0,0 +1,147 @@ +#Number of times to sleep +BOOT_TIMEOUT="5"; + +#Path to memboot binary +#MEMBOOT=${MEMBOOT:-memboot}; + +#Username/password for ssh to BMC machines +SSHUSER=${SSHUSER:-sysadmin}; +export SSHPASS=${SSHPASS:-superuser}; + +#Username/password for IPMI +IPMI_AUTH="-U ${IPMI_USER:-admin} -P ${IPMI_PASS:-admin}" +PFLASH_TO_COPY=${PFLASH_TO_COPY:-} +PFLASH_BINARY=/usr/local/bin/pflash + +# Strip control characters from IPMI before grepping? +STRIP_CONTROL=0 + +# How do we SSH/SCP in? +SSHCMD="sshpass -e ssh -l $SSHUSER -o LogLevel=quiet -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no $target"; + +function sshcmd { + $SSHCMD $*; +} + +# remotecp file target target_location +function remotecp { + sshpass -e ssh -o User=$SSHUSER -o LogLevel=quiet -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no $2 dd of=$3 < $1; +} + +function is_off { + return $([ "$($IPMI_COMMAND chassis power status)" = "Chassis Power is off" ]); +} + +function poweroff { + $IPMI_COMMAND chassis power off + # give it some time + sleep 10 +} + +function force_primary_side { + # Now we force booting from primary (not golden) side + $IPMI_COMMAND raw 0x04 0x30 0x5c 0x01 0x00 0x00 0 0 0 0 0 0 + # and from somewhere else we get this raw command. Obvious really. + $IPMI_COMMAND raw 0x04 0x30 0xd2 0x01 0x00 0x00 0 0 0 0 0 0 + sleep 8 +} + +function flash { + if [ ! -z "$PFLASH_TO_COPY" ]; then + remotecp $PFLASH_TO_COPY $target /tmp/pflash + $SSHCMD chmod +x /tmp/pflash + PFLASH_BINARY=/tmp/pflash + fi + if [ ! -z "$PNOR" ]; then + remotecp $PNOR $target /tmp/image.pnor; + fi + if [ "${LID[0]}" != "" ]; then + remotecp ${LID[0]} $target /tmp/skiboot.lid; + fi + if [ "${LID[1]}" != "" ]; then + remotecp ${LID[1]} $target /tmp/bootkernel + fi + if [ "${arbitrary_lid[1]}" != "" ]; then + remotecp ${arbitrary_lid[1]} $target /tmp/$(basename ${arbitrary_lid[1]}) + fi + + if [ "$?" -ne "0" ] ; then + error "Couldn't copy firmware image"; + fi + + # Habenaro doesn't have md5sum + #flash_md5=$(md5sum "$1" | cut -f 1 -d ' '); + #$SSHCMD "flash_md5r=\$(md5sum /tmp/image.pnor | cut -f 1 -d ' '); + # if [ \"$flash_md5\" != \"\$flash_md5r\" ] ; then + # exit 1; + # fi"; + #if [ "$?" -ne "0" ] ; then + # error "Firmware MD5s don't match"; + #fi + + # flash it + if [ ! -z "$PNOR" ]; then + msg "Flashing full PNOR" + $SSHCMD "$PFLASH_BINARY -E -f -p /tmp/image.pnor" + if [ "$?" -ne "0" ] ; then + error "An unexpected pflash error has occurred"; + fi + msg "Removing /tmp/image.pnor" + $SSHCMD "rm /tmp/image.pnor" + fi + + if [ ! -z "${LID[0]}" ] ; then + msg "Flashing PAYLOAD PNOR partition" + $SSHCMD "$PFLASH_BINARY -e -f -P PAYLOAD -p /tmp/skiboot.lid" + if [ "$?" -ne "0" ] ; then + error "An unexpected pflash error has occurred"; + fi + msg "Removing /tmp/pskiboot.lid" + $SSHCMD "rm /tmp/skiboot.lid" + fi + + if [ ! -z "${LID[1]}" ] ; then + msg "Flashing BOOTKERNEL PNOR partition" + $SSHCMD "$PFLASH_BINARY -e -f -P BOOTKERNEL -p /tmp/bootkernel" + if [ "$?" -ne "0" ] ; then + error "An unexpected pflash error has occurred"; + fi + msg "Removing /tmp/bootkernel" + $SSHCMD "rm /tmp/bootkernel" + fi + + if [ ! -z "${arbitrary_lid[0]}" -a ! -z "${arbitrary_lid[1]}" ] ; then + msg "Flashing ${arbitrary_lid[0]} PNOR partition" + $SSHCMD "$PFLASH_BINARY -e -f -P ${arbitrary_lid[0]} -p /tmp/$(basename ${arbitrary_lid[1]})" + if [ "$?" -ne "0" ] ; then + error "An unexpected pflash error has occurred"; + fi + msg "Removing /tmp/$(basename ${arbitrary_lid[1]})" + $SSHCMD "rm /tmp/$(basename ${arbitrary_lid[1]})" + fi + +} + +function boot_firmware { + $IPMI_COMMAND chassis power on > /dev/null; + i=0; + while [ "$($IPMI_COMMAND chassis power status)" = "Chassis Power is off" -a \( "$i" -lt "$BOOT_TIMEOUT" \) ] ; do + msg -n "."; + sleep $BOOT_SLEEP_PERIOD; + i=$(expr $i + 1); + done + if [ "$i" -eq "$BOOT_TIMEOUT" ] ; then + error "Couldn't power on $target"; + fi +} + +function machine_sanity_test { + sshcmd true; + if [ $? -ne 0 ]; then + echo "$target: Failed to SSH to $target..." + echo "$target: Command was: $SSHCMD true" + error "Try connecting manually to diagnose the issue." + fi + # No further sanity tests for BMC machines. + true +} diff --git a/roms/skiboot/external/boot-tests/boot_test.sh b/roms/skiboot/external/boot-tests/boot_test.sh new file mode 100755 index 000000000..233467c23 --- /dev/null +++ b/roms/skiboot/external/boot-tests/boot_test.sh @@ -0,0 +1,303 @@ +#!/bin/bash +# Lets try for /bin/sh but bashisms will sneak in. + +# partial bash strict mode +set -uo pipefail + +V=0; +target="" + +if [ -f ~/.skiboot_boot_tests ]; then + source ~/.skiboot_boot_tests +fi + +# Utility functions +function error { + unset SSHPASS + if [ ! -z "$target" ]; then + echo "$target: $*" >&2 + else + echo "$0: $*" >&2 + fi + + exit 1 +} + +function msg { + if [ $V -ne 0 ]; then + if [ ! -z "$target" ]; then + echo "$target: $*" + else + echo "$0: $*" + fi + fi +} + +# Generic conf +BOOT_SLEEP_PERIOD=10 +FUNCTIONS_NEEDED="sshpass ssh ipmitool md5sum rsync expect"; + +function linux_boot { + if [ $STRIP_CONTROL -eq 1 ]; then + STRIPCOMMAND="col -b -l 1" + else + STRIPCOMMAND="cat" + fi + + #Everyone is going to forget to disconnect - force them off + ipmiresult=$($IPMI_COMMAND sol deactivate 2>&1); + retval=$? + if [ $retval -ne 0 -a "$ipmiresult" != "Info: SOL payload already de-activated" ]; then + msg "IPMI sol deactivate failed; IPMI may have stalled, may just be IPMI. Good luck." + fi + + LINUXBOOT_LOG=$(mktemp --tmpdir boot-test-$target.XXXXXX); + cat <<EOF | expect > $LINUXBOOT_LOG +set timeout 300 +spawn $IPMI_COMMAND sol activate +expect { +timeout { send_user "\nTimeout waiting for petitboot\n"; exit 1 } +eof { send_user "\nUnexpected EOF\n;" exit 1 } +"Welcome to Petitboot" +} + +close +exit 0 +EOF + retval=$? + $IPMI_COMMAND sol deactivate > /dev/null; + if [ $retval -ne 0 ]; then + msg "Waiting for linux has timed out" + msg "Boot log follows:" + cat $LINUXBOOT_LOG + if [ $keep_log_failure -eq 0 ]; then + rm -f $LINUXBOOT_LOG + fi + return 1 + else + if [ $keep_log_success -eq 0 ]; then + rm -f $LINUXBOOT_LOG + fi + return 0 + fi +} + +function boot_test { + # The functions called (e.g. flash, boot) are from the *_support files + if [ $bootonly -ne 1 ]; then + msg "Flashing ${target}..." + flash $@; + fi + + if [ $nobooting -ne 1 ] ; then + msg "Booting $target..." + boot_firmware; + msg "firmware looks good, waiting for linux"; + + linux_boot; + if [ $? -ne 0 ] ; then + error "Couldn't reach petitboot on $target"; + fi + msg "$target has booted"; + fi + unset SSHPASS; +} + +function sanity_test { + $IPMI_COMMAND chassis power status > /dev/null; + if [ $? -ne 0 ]; then + echo "$target: Failed to connect to $target with IPMI..." + echo "$target: Command was: $IPMI_COMMAND chassis power status" + error "Try connecting manually to diagnose the issue." + fi + + # do further machine-type specific tests + machine_sanity_test +} + +function usage { + cat <<EOF +boot_test.sh tests the bootability of a given target, optionally after + flashing new firmware onto the target. + +There are three usage modes. + +1) boot_test.sh -h + Print this help + +2) boot_test.sh [-vdp] -t target -B -b (fsp|bmc|smc|openbmc) + Boot test the target without flashing. Specify the type of machine + (FSP, BMC, SMC, OpenBMC) with the -b option. + +3) boot_test.sh [-vdp] -b bmc -t target -P pnor [-N] + boot_test.sh [-vdp] -b bmc -t target [-1 PAYLOAD] [-2 BOOTKERNEL] [-N] + boot_test.sh [-vdp] -b bmc -t target [-F eyecatcher:lid] [-N] + boot_test.sh [-vdp] -b fsp -t target [-1 lid1] [-2 lid2] [-3 lid3] + + Flash the given firmware before boot testing. + + For a BMC target, -P specifies a full PNOR. + + For a BMC target, -1/-2 specify the PAYLOAD and BOOTKERNEL PNOR partitions + respectively; -e specifies the partition name for -3. + Only the given partitions will be flashed. + + For an FSP target, -1/-2/-3 specify lids. Any combination of lids is + acceptable. + +Common Options: + + -p powers off the machine if it is running. Without -p, a running machine + will cause the script to error out. + + -v makes the script print some progress messages. Recommended. + + -d makes the script print lots of things (set -vx). + Only use this for debugging the script: it's highly likely that + successful booting into Petitboot will not be detected with this option. + + -b BMC type (bmc or fsp). + + -k keep logs on failure. + + -K keep logs on success or failure. + + -N No booting. +EOF + exit 1; +} + +## 'Main' script begins + +# Check prereqs +for func in $FUNCTIONS_NEEDED ; do + if ! command -v "$func" &> /dev/null ; then + error "I require command $func but it is not in \$PATH ($PATH)"; + fi +done + +# Parse options +V=0; +bootonly=0; +nobooting=0; +powerdown=0; +firmware_supplied=0; +target="" +method="" +PNOR="" +arbitrary_lid[0]="" +arbitrary_lid[1]="" +LID[0]="" +LID[1]="" +LID[2]="" +keep_log_success=0 +keep_log_failure=0 +while getopts "kKhvdpB1:2:3:P:t:b:F:N" OPT; do + case "$OPT" in + v) + V=1; + ;; + h) + usage; + ;; + d) + set -vx; + ;; + k) + keep_log_failure=1; + ;; + K) + keep_log_failure=1; + keep_log_success=1; + ;; + B) + bootonly=1; + if [ $firmware_supplied -eq 1 ]; then + usage + fi + ;; + N) + nobooting=1; + if [ $firmware_supplied -eq 0 ] ; then + error "Firmware not supplied." + fi + ;; + p) + powerdown=1; + ;; + b) + method=$OPTARG; + ;; + 1|2|3) + firmware_supplied=1; + if [ ! -e "$OPTARG" ] ; then + error "Couldn't stat $OPTARG"; + fi + LID[$(expr ${OPT} - 1)]="$OPTARG" + ;; + P) + firmware_supplied=1; + if [ ! -e "$OPTARG" ] ; then + error "Couldn't stat $OPTARG"; + fi + PNOR="$OPTARG" + ;; + F) + firmware_supplied=1; + arbitrary_lid[0]=`echo "$OPTARG" | cut -s -f1 -d:`; + arbitrary_lid[1]=`echo "$OPTARG" | cut -s -f2 -d:`; + if [ -z "${arbitrary_lid[0]}" -o -z "${arbitrary_lid[1]}" ] ; then + error "-F must be in the format eyecatcher:lid, e.g. GARD:gard.bin"; + fi + ;; + t) + target=$OPTARG; + ;; + \?) + usage; + ;; + esac +done + +shift $(expr $OPTIND - 1); + +# Pull out the target and test +if [ "$target" = "" ]; then + usage; +fi + +if ! ping -c 1 "$target" &> /dev/null ; then + error "Couldn't ping $target"; +fi + +if [ "$#" -ne 0 ]; then + usage +fi + + +# pull in the relevant config file and set things up +source $(dirname $(readlink -f $0))/${method}_support.sh +IPMI_COMMAND="ipmitool -I lanplus -H $target $IPMI_AUTH" + +msg "Running sanity test" +sanity_test +msg "Passed." + +# check the target is down +# (pulls in is_off from ${method}_support.sh) +if ! is_off; then + if [ $powerdown -eq 1 ]; then + poweroff + else + error "$target is not turned off"; + fi +fi + +force_primary_side # ensure we're booting from side we flash. + +# run the boot test +echo "$target: Boot testing $target"; +begin_t=$(date +%s); +boot_test + +echo "$target: Done in $(expr $(date +%s) - $begin_t ) seconds"; diff --git a/roms/skiboot/external/boot-tests/extract_gcov.sh b/roms/skiboot/external/boot-tests/extract_gcov.sh new file mode 100755 index 000000000..c40e01e56 --- /dev/null +++ b/roms/skiboot/external/boot-tests/extract_gcov.sh @@ -0,0 +1,30 @@ +#!/bin/bash + +if [ "$SKIBOOT_GCOV" != 1 ]; then + echo "Skipping GCOV test on physical hardware. Enable with SKIBOOT_GCOV=1" + exit 0; +fi + +if [ ! -f ~/.skiboot_boot_tests ]; then + if [ -z $FSPSSHUSER ] || [ -z $FSPSSHPASS ] ; then + echo "Skipping extract gcov due to missing ~/.skiboot_boot_tests" + echo "Set FSPSSHUSER and FSPSSHPASS in ~/.skiboot_boot_tests" + exit 0; + fi +fi + +source ~/.skiboot_boot_tests + +target=$1 +SSHUSER=$FSPSSHUSER +SSHPASS=$FSPSSHPASS + +export SSHUSER SSHPASS + +SSHCMD="sshpass -e ssh -l $SSHUSER -o LogLevel=quiet -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no $target"; +REMOTECPCMD="sshpass -e scp -o User=$SSHUSER -o LogLevel=quiet -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no "; + +$SSHCMD rm -f skiboot-$target.dump +echo "Dumping skiboot memory from host: $target... (takes time)" +$SSHCMD sh --login -c \"getmemproc 30000000 3145728 -fb skiboot-$target.dump\" +$REMOTECPCMD $target:skiboot-$target.dump skiboot-$target.dump diff --git a/roms/skiboot/external/boot-tests/fsp_support.sh b/roms/skiboot/external/boot-tests/fsp_support.sh new file mode 100644 index 000000000..fc0d66d16 --- /dev/null +++ b/roms/skiboot/external/boot-tests/fsp_support.sh @@ -0,0 +1,178 @@ +#Number of times to sleep +BOOT_TIMEOUT="20"; + +#Username/password for for ssh to FSP machines +SSHUSER=${FSPSSHUSER:-} +SSHPASS=${FSPSSHPASS:-} + +if [ -z $SSHUSER ] || [ -z $SSHPASS ] ; then + msg "Set FSPSSHUSER and FSPSSHPASS in ENV or ~/.skiboot_boot_tests" + exit 1; +fi + +export SSHUSER SSHPASS + +#IPMI +IPMI_AUTH="-P ${IPMI_PASS:-foo}"; + +# Strip control characters from IPMI before grepping? +STRIP_CONTROL=1 + +# How do we SSH in, cp files across? +SSHCMD="sshpass -e ssh -l $SSHUSER -o LogLevel=quiet -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no $target"; +REMOTECPCMD="sshpass -e scp -o User=$SSHUSER -o LogLevel=quiet -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no "; + +GET_PROFILE='. /etc/profile; test -e /home/dev/.profile && . /home/dev/.profile'; + +function sshcmd { + $SSHCMD $*; +} + +function is_off { + state=$($SSHCMD "$GET_PROFILE; smgr mfgState"); + return $([ "$state" = "standby" ]); +} + +function poweroff { + i=0; + state=$($SSHCMD "$GET_PROFILE; smgr mfgState"); + if [ "$state" = "standby" ]; then + # already off + return 0 + fi + $SSHCMD "$GET_PROFILE; panlexec -f 8"; + msg "Waiting 30 seconds..." + sleep 30 + state=$($SSHCMD "$GET_PROFILE; smgr mfgState"); + while [ "$state" != "standby" -a "$i" -lt "$BOOT_TIMEOUT" ] ; do + msg "Waiting $BOOT_SLEEP_PERIOD more seconds..." + sleep $BOOT_SLEEP_PERIOD; + i=$(expr $i + 1); + state=$($SSHCMD "$GET_PROFILE; smgr mfgState"); + done; + # sleep a little bit longer --- p81 was getting a bit confused. + sleep 10 + msg "Finishing with state '$state'." +} + +function force_primary_side { + return 0 +} + +function flash { + #Make a backup of the current lids + $REMOTECPCMD $target:/opt/extucode/80f00100.lid 80f00100.lid.bak && + $REMOTECPCMD $target:/opt/extucode/80f00101.lid 80f00101.lid.bak && + $REMOTECPCMD $target:/opt/extucode/80f00102.lid 80f00102.lid.bak; + if [ $? -ne 0 ] ; then + error "Couldn't make backup of currently installed lids"; + fi + + if [ "${LID[0]}" != "" ]; then + $REMOTECPCMD ${LID[0]} $target:/opt/extucode/80f00100.lid || + error "Error copying lid ${LID[0]}"; + sum=$(md5sum ${LID[0]} | cut -f 1 -d ' '); + $SSHCMD "$GET_PROFILE; + sumr=\$(md5sum /opt/extucode/80f00100.lid | cut -f 1 -d ' '); + if [ \"$sum\" != \"\$sumr\" ] ; then + exit 1; + fi;" || error "MD5sum doesn't match for ${LID[0]}" + + fi + + if [ "${LID[1]}" != "" ]; then + $REMOTECPCMD ${LID[1]} $target:/opt/extucode/80f00101.lid || + error "Error copying lid"; + sum=$(md5sum ${LID[1]} | cut -f 1 -d ' '); + $SSHCMD "$GET_PROFILE; + sumr=\$(md5sum /opt/extucode/80f00101.lid | cut -f 1 -d ' '); + if [ \"$sum\" != \"\$sumr\" ] ; then + exit 1; + fi;" || error "MD5sum doesn't match for ${LID[1]}" + fi + + if [ "${LID[2]}" != "" ]; then + $REMOTECPCMD ${LID[2]} $target:/opt/extucode/80f00102.lid || + error "Error copying lid"; + sum=$(md5sum ${LID[2]} | cut -f 1 -d ' '); + $SSHCMD "$GET_PROFILE; + sumr=\$(md5sum /opt/extucode/80f00102.lid | cut -f 1 -d ' '); + if [ \"$sum\" != \"\$sumr\" ] ; then + exit 1; + fi;" || error "MD5sum doesn't match for ${LID[2]}" + fi + + + $SSHCMD "$GET_PROFILE; + if [ \$(smgr mfgState) != 'standby' ] ; then + exit 1; + fi + cupdmfg -opt | grep '80f0010'"; + if [ $? -ne 0 ] ; then + error "Could not install lids on the FSP"; + fi + + sleep 2; #Don't rush the fsp +} + +function boot_firmware { + ISTEP_LOG=$(mktemp --tmpdir builder-1.XXXXXX); + $SSHCMD "$GET_PROFILE; istep" &> $ISTEP_LOG & + msg "Waiting 90 seconds for $target to boot"; + sleep 90; + i=0; + state=$($SSHCMD "$GET_PROFILE; smgr mfgState"); + while [ \( "$state" != "runtime" \) -a \( "$i" -lt "$BOOT_TIMEOUT" \) ] ; do + msg "Waiting $BOOT_SLEEP_PERIOD more seconds (istep: `grep iStep $ISTEP_LOG|tail -n 1`)"; + sleep "$BOOT_SLEEP_PERIOD"; + i=$(expr $i + 1); + state=$($SSHCMD "$GET_PROFILE; smgr mfgState"); + done; + + if [ "$i" -eq "$BOOT_TIMEOUT" ] ; then + state=$($SSHCMD "$GET_PROFILE; smgr mfgState"); + case "$state" in + "ipling") + echo "$target: still hasn't come up but firmware hasn't specifically crashed"; + ;; + "dumping") + echo "$target: has crashed"; + ;; + "runtime") + echo "$target: Oops, looks like system has managed to come up..."; + ;; + "standby") + echo "$target: System is powered off? How can this be?"; + ;; + *) + echo "$target: is an unknown state '$state'"; + ;; + esac + echo "$target: istep log"; + cat $ISTEP_LOG; + rm -rf $ISTEP_LOG + error "Boot test on $target failed"; + fi + rm -rf $ISTEP_LOG; +} + +function machine_sanity_test { + sshcmd true; + if [ $? -ne 0 ]; then + echo "$target: Failed to SSH to $target..." + echo "$target: Command was: $SSHCMD true" + error "Try connecting manually to diagnose the issue." + fi + + $SSHCMD "$GET_PROFILE; test -d /nfs/bin" + if [ $? -ne 0 ]; then + echo "$target: Failed to read /nfs/bin" + error "Is /nfs mounted on the FSP?" + fi + + $SSHCMD "$GET_PROFILE; which md5sum > /dev/null && which cupdmfg > /dev/null" + if [ $? -ne 0 ]; then + echo "$target: Missing md5sum or cupdmfg on the FSP?" + error "Is /nfs mounted on the FSP?" + fi +} diff --git a/roms/skiboot/external/boot-tests/openbmc_support.sh b/roms/skiboot/external/boot-tests/openbmc_support.sh new file mode 100644 index 000000000..8c0b29677 --- /dev/null +++ b/roms/skiboot/external/boot-tests/openbmc_support.sh @@ -0,0 +1,129 @@ +#Number of times to sleep +BOOT_TIMEOUT="5"; + +#Username/password for ssh to BMC machines +SSHUSER=${SSHUSER:-root}; +export SSHPASS=${SSHPASS:-0penBmc}; + +PFLASH_TO_COPY=${PFLASH_TO_COPY:-} +PFLASH_BINARY=/usr/sbin/pflash + +# How do we SSH/SCP in? +SSHCMD="sshpass -e ssh -l $SSHUSER -o LogLevel=quiet -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no $target"; + +IPMI_AUTH="-P ${IPMI_PASS:-0penBmc}" + +# Strip control characters from IPMI before grepping? +STRIP_CONTROL=0 + +function sshcmd { + $SSHCMD $*; +} + +# remotecp file target target_location +function remotecp { + sshpass -e scp -o User=$SSHUSER -o LogLevel=quiet -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no $1 $2:$3 +} + +function is_off { + return $([ "$($SSHCMD /usr/sbin/obmcutil power|grep 'state')" = "state = 0" ]); +} + +function poweroff { + $SSHCMD /usr/sbin/obmcutil poweroff + # give it some time + sleep 5 +} + +function force_primary_side { + true +} + +function flash { + if [ ! -z "$PFLASH_TO_COPY" ]; then + remotecp $PFLASH_TO_COPY $target /tmp/pflash + $SSHCMD chmod +x /tmp/pflash + PFLASH_BINARY=/tmp/pflash + fi + if [ ! -z "$PNOR" ]; then + remotecp $PNOR $target /tmp/image.pnor; + fi + if [ "${LID[0]}" != "" ]; then + remotecp ${LID[0]} $target /tmp/skiboot.lid; + fi + if [ "${LID[1]}" != "" ]; then + remotecp ${LID[1]} $target /tmp/bootkernel + fi + if [ "${arbitrary_lid[1]}" != "" ]; then + remotecp ${arbitrary_lid[1]} $target /tmp/$(basename ${arbitrary_lid[1]}) + fi + + if [ "$?" -ne "0" ] ; then + error "Couldn't copy firmware image"; + fi + + if [ ! -z "$PNOR" ]; then + msg "Flashing full PNOR" + $SSHCMD "$PFLASH_BINARY -E -f -p /tmp/image.pnor" + if [ "$?" -ne "0" ] ; then + error "An unexpected pflash error has occurred"; + fi + msg "Removing /tmp/image.pnor" + $SSHCMD "rm /tmp/image.pnor" + fi + + if [ ! -z "${LID[0]}" ] ; then + msg "Flashing PAYLOAD PNOR partition" + $SSHCMD "$PFLASH_BINARY -e -f -P PAYLOAD -p /tmp/skiboot.lid" + if [ "$?" -ne "0" ] ; then + error "An unexpected pflash error has occurred"; + fi + msg "Removing /tmp/pskiboot.lid" + $SSHCMD "rm /tmp/skiboot.lid" + fi + + if [ ! -z "${LID[1]}" ] ; then + msg "Flashing BOOTKERNEL PNOR partition" + $SSHCMD "$PFLASH_BINARY -e -f -P BOOTKERNEL -p /tmp/bootkernel" + if [ "$?" -ne "0" ] ; then + error "An unexpected pflash error has occurred"; + fi + msg "Removing /tmp/bootkernel" + $SSHCMD "rm /tmp/bootkernel" + fi + + if [ ! -z "${arbitrary_lid[0]}" -a ! -z "${arbitrary_lid[1]}" ] ; then + msg "Flashing ${arbitrary_lid[0]} PNOR partition" + $SSHCMD "$PFLASH_BINARY -e -f -P ${arbitrary_lid[0]} -p /tmp/$(basename ${arbitrary_lid[1]})" + if [ "$?" -ne "0" ] ; then + error "An unexpected pflash error has occurred"; + fi + msg "Removing /tmp/$(basename ${arbitrary_lid[1]})" + $SSHCMD "rm /tmp/$(basename ${arbitrary_lid[1]})" + fi + +} + +function boot_firmware { + $SSHCMD /usr/sbin/obmcutil poweron + i=0; + while [ "$($SSHCMD /usr/sbin/obmcutil power|grep state)" = "state = 0" -a \( "$i" -lt "$BOOT_TIMEOUT" \) ] ; do + msg -n "."; + sleep $BOOT_SLEEP_PERIOD; + i=$(expr $i + 1); + done + if [ "$i" -eq "$BOOT_TIMEOUT" ] ; then + error "Couldn't power on $target"; + fi +} + +function machine_sanity_test { + sshcmd true; + if [ $? -ne 0 ]; then + echo "$target: Failed to SSH to $target..." + echo "$target: Command was: $SSHCMD true" + error "Try connecting manually to diagnose the issue." + fi + # No further sanity tests for BMC machines. + true +} diff --git a/roms/skiboot/external/boot-tests/smc_support.sh b/roms/skiboot/external/boot-tests/smc_support.sh new file mode 100644 index 000000000..5e2a834d8 --- /dev/null +++ b/roms/skiboot/external/boot-tests/smc_support.sh @@ -0,0 +1,128 @@ +#Number of times to sleep +BOOT_TIMEOUT="5"; + +#Username/password for ssh to BMC machines +SSHUSER=${SSHUSER:-ADMIN}; +export SSHPASS=${SSHPASS:-ADMIN}; + +#Username/password for IPMI +IPMI_AUTH="-U ${IPMI_USER:-ADMIN} -P ${IPMI_PASS:-ADMIN}" +PFLASH_TO_COPY=${PFLASH_TO_COPY:-} +PFLASH_BINARY=/tmp/pflash + +# Strip control characters from IPMI before grepping? +STRIP_CONTROL=0 + +# How do we SSH/SCP in? +SSHCMD="sshpass -e ssh -l $SSHUSER -o LogLevel=quiet -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no $target"; + +function sshcmd { + # because BMC: + $IPMI_COMMAND $SMC_PRESSHIPMICMD; + expect -c "spawn $SSHCMD" -c "set timeout 600" -c "expect \"#\" { send \"$*\\r\" }" -c 'expect "#" { send "exit\r" }' -c 'wait'; +} + +# remotecp file target target_location +function remotecp { + rsync -av $1 rsync://$2/files/$3 +} + +function is_off { + return $([ "$($IPMI_COMMAND chassis power status)" = "Chassis Power is off" ]); +} + +function poweroff { + $IPMI_COMMAND chassis power off + # give it some time + sleep 10 +} + +function force_primary_side { + true +} + +function flash { + if [ ! -z "$PFLASH_TO_COPY" ]; then + remotecp $PFLASH_TO_COPY $target pflash + sshcmd chmod +x /tmp/rsync_file/pflash + PFLASH_BINARY=/tmp/rsync_file/pflash + fi + if [ ! -z "$PNOR" ]; then + remotecp $PNOR $target image.pnor; + fi + if [ "${LID[0]}" != "" ]; then + remotecp ${LID[0]} $target skiboot.lid; + fi + if [ "${LID[1]}" != "" ]; then + remotecp ${LID[1]} $target bootkernel + fi + if [ "${arbitrary_lid[1]}" != "" ]; then + remotecp ${arbitrary_lid[1]} $target $(basename ${arbitrary_lid[1]}) + fi + + if [ "$?" -ne "0" ] ; then + error "Couldn't copy firmware image"; + fi + + # flash it + if [ ! -z "$PNOR" ]; then + msg "Flashing full PNOR" + sshcmd "$PFLASH_BINARY -E -f -p /tmp/rsync_file/image.pnor" + if [ "$?" -ne "0" ] ; then + error "An unexpected pflash error has occurred"; + fi + msg "Removing /tmp/rsync_file/image.pnor" + sshcmd "rm /tmp/rsync_file/image.pnor" + fi + + if [ ! -z "${LID[0]}" ] ; then + msg "Flashing PAYLOAD PNOR partition" + sshcmd "$PFLASH_BINARY -e -f -P PAYLOAD -p /tmp/rsync_file/skiboot.lid" + if [ "$?" -ne "0" ] ; then + error "An unexpected pflash error has occurred"; + fi + msg "Removing /tmp/rsync_file/skiboot.lid" + sshcmd "rm /tmp/skiboot.lid" + fi + + if [ ! -z "${LID[1]}" ] ; then + msg "Flashing BOOTKERNEL PNOR partition" + sshcmd "$PFLASH_BINARY -e -f -P BOOTKERNEL -p /tmp/rsync_file/bootkernel" + if [ "$?" -ne "0" ] ; then + error "An unexpected pflash error has occurred"; + fi + msg "Removing /tmp/rsync_file/bootkernel" + sshcmd "rm /tmp/rsync_file/bootkernel" + fi + + if [ ! -z "${arbitrary_lid[0]}" -a ! -z "${arbitrary_lid[1]}" ] ; then + msg "Flashing ${arbitrary_lid[0]} PNOR partition" + sshcmd "$PFLASH_BINARY -e -f -P ${arbitrary_lid[0]} -p /tmp/rsync_file/$(basename ${arbitrary_lid[1]})" + if [ "$?" -ne "0" ] ; then + error "An unexpected pflash error has occurred"; + fi + msg "Removing /tmp/rsync_file/$(basename ${arbitrary_lid[1]})" + sshcmd "rm /tmp/rsync_file/$(basename ${arbitrary_lid[1]})" + fi + + msg "Clearing mboxd caches..." + sshcmd "/bin/mboxctl --clear-cache" +} + +function boot_firmware { + $IPMI_COMMAND chassis power on > /dev/null; + i=0; + while [ "$($IPMI_COMMAND chassis power status)" = "Chassis Power is off" -a \( "$i" -lt "$BOOT_TIMEOUT" \) ] ; do + msg -n "."; + sleep $BOOT_SLEEP_PERIOD; + i=$(expr $i + 1); + done + if [ "$i" -eq "$BOOT_TIMEOUT" ] ; then + error "Couldn't power on $target"; + fi +} + +function machine_sanity_test { + # No further sanity tests for BMC machines. + true +} |