Initial commit
This commit is contained in:
@@ -0,0 +1,168 @@
|
||||
#!/bin/bash
|
||||
|
||||
fanSensorService="xyz.openbmc_project.FanSensor"
|
||||
|
||||
sensorPath="/xyz/openbmc_project/sensors/fan_tach/"
|
||||
pwmTargetPath="/xyz/openbmc_project/control/fanpwm/"
|
||||
|
||||
sensorValueInterfaceName="xyz.openbmc_project.Sensor.Value"
|
||||
sensorValuePropertyName="Value"
|
||||
|
||||
pwmTargetInterfaceName="xyz.openbmc_project.Control.FanPwm"
|
||||
pwmTargetPropertyName="Target"
|
||||
|
||||
function stop_phosphor_fan_services() {
|
||||
systemctl stop phosphor-fan-control@0.service
|
||||
systemctl stop phosphor-fan-monitor@0.service
|
||||
systemctl stop phosphor-fan-presence-tach@0.service
|
||||
}
|
||||
|
||||
function start_phosphor_fan_services() {
|
||||
systemctl start phosphor-fan-control@0.service
|
||||
systemctl start phosphor-fan-monitor@0.service
|
||||
systemctl start phosphor-fan-presence-tach@0.service
|
||||
}
|
||||
|
||||
function read_speed() {
|
||||
fan_val=$(busctl get-property "$fanSensorService" "${sensorPath}$1" "$sensorValueInterfaceName" "$sensorValuePropertyName")
|
||||
busctl_error=$?
|
||||
if (( busctl_error != 0 )); then
|
||||
echo "Error: get-property $sensorValuePropertyName failed! "
|
||||
exit 1
|
||||
fi
|
||||
|
||||
pwm_target=$(busctl get-property "$fanSensorService" "${pwmTargetPath}$2" "$pwmTargetInterfaceName" "$pwmTargetPropertyName")
|
||||
busctl_error=$?
|
||||
if (( busctl_error != 0 )); then
|
||||
echo "Error: get-property $pwmTargetPropertyName failed! "
|
||||
exit 1
|
||||
fi
|
||||
|
||||
fan_val=$(echo "$fan_val" | cut -d " " -f 2)
|
||||
pwm_target=$(echo "$pwm_target" | cut -d " " -f 2)
|
||||
|
||||
# Convert fan PWM to Duty cycle, adding 127 for rounding.
|
||||
pwm_duty_cyle=$(((("$pwm_target" * 100) + 127) / 255))
|
||||
|
||||
echo "$1, PWM: $pwm_target, Duty cycle: $pwm_duty_cyle%, Speed(RPM): $fan_val"
|
||||
}
|
||||
|
||||
function set_pwm() {
|
||||
|
||||
# Convert Fan Duty cycle to PWM, adding 50 for rounding.
|
||||
fan_pwm=$(((($2 * 255) + 50) / 100))
|
||||
|
||||
busctl set-property "$fanSensorService" "${pwmTargetPath}$1" "$pwmTargetInterfaceName" "$pwmTargetPropertyName" t "$fan_pwm"
|
||||
busctl_error=$?
|
||||
if (( busctl_error != 0 )); then
|
||||
echo "Error: set-property $pwmTargetPropertyName failed! "
|
||||
exit 255
|
||||
fi
|
||||
}
|
||||
|
||||
function getstatus() {
|
||||
fan_ctl_stt=$(systemctl is-active phosphor-fan-control@0.service | grep inactive)
|
||||
fan_monitor_stt=$(systemctl is-active phosphor-fan-monitor@0.service | grep inactive)
|
||||
if [[ -z "$fan_ctl_stt" && -z "$fan_monitor_stt" ]]; then
|
||||
echo "Thermal Control operational status: Enabled"
|
||||
exit 0
|
||||
else
|
||||
echo "Thermal Control operational status: Disabled"
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
function setstatus() {
|
||||
if [ "$1" == 0 ]; then
|
||||
# Enable fan services
|
||||
start_phosphor_fan_services
|
||||
else
|
||||
# Disable fan services
|
||||
stop_phosphor_fan_services
|
||||
fi
|
||||
}
|
||||
|
||||
function setspeed() {
|
||||
# Get fan_pwm value of the fan
|
||||
case "$1" in
|
||||
0) fan_pwm=PWM7
|
||||
;;
|
||||
1) fan_pwm=PWM5
|
||||
;;
|
||||
2) fan_pwm=PWM4
|
||||
;;
|
||||
3) fan_pwm=PWM3
|
||||
;;
|
||||
4) fan_pwm=PWM1
|
||||
;;
|
||||
5) fan_pwm=PWM0
|
||||
;;
|
||||
*) echo "fan $1 doesn't exit"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
|
||||
set_pwm "$fan_pwm" "$2"
|
||||
exit 0
|
||||
}
|
||||
|
||||
function getspeed() {
|
||||
|
||||
# Mapping fan number to fan_input and fan_pwm index
|
||||
case "$1" in
|
||||
0) fan_input_f=FAN0_F
|
||||
fan_input_r=FAN0_R
|
||||
fan_pwm=PWM7
|
||||
;;
|
||||
1) fan_input_f=FAN1_F
|
||||
fan_input_r=FAN1_R
|
||||
fan_pwm=PWM5
|
||||
;;
|
||||
2) fan_input_f=FAN2_F
|
||||
fan_input_r=FAN2_R
|
||||
fan_pwm=PWM4
|
||||
;;
|
||||
3) fan_input_f=FAN3_F
|
||||
fan_input_r=FAN3_R
|
||||
fan_pwm=PWM3
|
||||
;;
|
||||
4) fan_input_f=FAN4_F
|
||||
fan_input_r=FAN4_R
|
||||
fan_pwm=PWM1
|
||||
;;
|
||||
5) fan_input_f=FAN5_F
|
||||
fan_input_r=FAN5_F
|
||||
fan_pwm=PWM0
|
||||
;;
|
||||
*) echo "fan $1 doesn't exit"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
|
||||
# Get fan speed, each fan number has two values is front and rear
|
||||
read_speed "$fan_input_f" "$fan_pwm"
|
||||
read_speed "$fan_input_r" "$fan_pwm"
|
||||
|
||||
exit 0
|
||||
}
|
||||
|
||||
# Usage of this utility
|
||||
function usage() {
|
||||
echo "Usage:"
|
||||
echo " ampere_fanctrl.sh [getstatus] [setstatus <0|1>] [setspeed <fan> <duty>] [getspeed <fan>]"
|
||||
echo " fan: 0-5"
|
||||
echo " duty: 1-100"
|
||||
}
|
||||
|
||||
if [ "$1" == "getstatus" ]; then
|
||||
getstatus
|
||||
elif [ "$1" == "setstatus" ]; then
|
||||
setstatus "$2"
|
||||
elif [ "$1" == "setspeed" ]; then
|
||||
stop_phosphor_fan_services
|
||||
setspeed "$2" "$3"
|
||||
elif [ "$1" == "getspeed" ]; then
|
||||
getspeed "$2"
|
||||
else
|
||||
usage
|
||||
fi
|
||||
Executable
+201
@@ -0,0 +1,201 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Helper script to flash FRU and Boot EEPROM devices.
|
||||
#
|
||||
# Syntax for FRU:
|
||||
# ampere_firmware_upgrade.sh fru <image> [<dev>]
|
||||
# dev: 1 for MB FRU (default), 2 for BMC FRU.
|
||||
#
|
||||
# Syntax for EEPROM:
|
||||
# ampere_firmware_upgrade.sh eeprom <image> [<dev>]
|
||||
# dev: 1 for main Boot EEPROM (default), 2 for secondary Boot EEPROM (if supported)
|
||||
#
|
||||
# Syntax for Mainboard CPLD:
|
||||
# ampere_firmware_upgrade.sh main_cpld <image>
|
||||
#
|
||||
# Syntax for BMC CPLD:
|
||||
# ampere_firmware_upgrade.sh bmc_cpld <image>
|
||||
#
|
||||
# Syntax for Backplane CPLD:
|
||||
# ampere_firmware_upgrade.sh bp_cpld <image> [<target>]
|
||||
# target: 1 for Front Backplane 1
|
||||
# 2 for Front Backplane 2
|
||||
# 3 for Front Backplane 3
|
||||
# 4 for Rear Backplane 1
|
||||
# 5 for Rear Backplane 2
|
||||
#
|
||||
|
||||
# shellcheck disable=SC2046
|
||||
|
||||
do_eeprom_flash() {
|
||||
FIRMWARE_IMAGE=$IMAGE
|
||||
BACKUP_SEL=$2
|
||||
|
||||
# Turn off the Host if it is currently ON
|
||||
chassisstate=$(obmcutil chassisstate | awk -F. '{print $NF}')
|
||||
echo "Current Chassis State: $chassisstate"
|
||||
if [ "$chassisstate" == 'On' ];
|
||||
then
|
||||
echo "Turning the Chassis off"
|
||||
obmcutil chassisoff
|
||||
sleep 15
|
||||
# Check if HOST was OFF
|
||||
chassisstate_off=$(obmcutil chassisstate | awk -F. '{print $NF}')
|
||||
if [ "$chassisstate_off" == 'On' ];
|
||||
then
|
||||
echo "Error : Failed turning the Chassis off"
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
|
||||
# Switch EEPROM control to BMC AST2600 I2C
|
||||
# BMC_GPIOW6_SPI0_PROGRAM_SEL
|
||||
gpioset $(gpiofind spi0-program-sel)=1
|
||||
|
||||
# BMC_GPIOX0_I2C_BACKUP_SEL (GPIO 184)
|
||||
if [[ $BACKUP_SEL == 1 ]]; then
|
||||
echo "Run update Primary EEPROM"
|
||||
gpioset $(gpiofind i2c-backup-sel)=0
|
||||
elif [[ $BACKUP_SEL == 2 ]]; then
|
||||
echo "Run update Failover EEPROM"
|
||||
gpioset $(gpiofind i2c-backup-sel)=1
|
||||
else
|
||||
echo "Please choose Primary EEPROM (1) or Failover EEPROM (2)"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# The EEPROM (AT24C64WI) with address 0x50 at BMC_I2C11 bus
|
||||
# Write Firmware to EEPROM and read back for validation
|
||||
ampere_eeprom_prog -b 10 -s 0x50 -p -f "$FIRMWARE_IMAGE"
|
||||
|
||||
# Switch to primary EEPROM
|
||||
gpioset $(gpiofind i2c-backup-sel)=0
|
||||
|
||||
# Switch EEPROM control to CPU HOST
|
||||
gpioset $(gpiofind spi0-program-sel)=0
|
||||
|
||||
if [ "$chassisstate" == 'On' ];
|
||||
then
|
||||
sleep 5
|
||||
echo "Turn on the Host"
|
||||
obmcutil poweron
|
||||
fi
|
||||
}
|
||||
|
||||
do_fru_flash() {
|
||||
FRU_IMAGE=$1
|
||||
FRU_DEV=$2
|
||||
|
||||
if [[ $FRU_DEV == 1 ]]; then
|
||||
if [ -f /sys/bus/i2c/devices/4-0050/eeprom ]; then
|
||||
FRU_DEVICE="/sys/bus/i2c/devices/4-0050/eeprom"
|
||||
else
|
||||
FRU_DEVICE="/sys/bus/i2c/devices/3-0050/eeprom"
|
||||
fi
|
||||
echo "Flash MB FRU with image $IMAGE at $FRU_DEVICE"
|
||||
elif [[ $FRU_DEV == 2 ]]; then
|
||||
FRU_DEVICE="/sys/bus/i2c/devices/14-0050/eeprom"
|
||||
echo "Flash BMC FRU with image $IMAGE at $FRU_DEVICE"
|
||||
else
|
||||
echo "Please select MB FRU (1) or BMC FRU (2)"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
ampere_fru_upgrade -d "$FRU_DEVICE" -f "$FRU_IMAGE"
|
||||
|
||||
systemctl restart xyz.openbmc_project.FruDevice.service
|
||||
systemctl restart phosphor-ipmi-host.service
|
||||
|
||||
echo "Done"
|
||||
}
|
||||
|
||||
do_mb_cpld_flash() {
|
||||
MB_CPLD_IMAGE=$1
|
||||
echo "Flashing MB CPLD"
|
||||
gpioset $(gpiofind hpm-fw-recovery)=1
|
||||
gpioset $(gpiofind jtag-program-sel)=1
|
||||
sleep 2
|
||||
ampere_cpldupdate_jtag -t 1 -p "$MB_CPLD_IMAGE"
|
||||
gpioset $(gpiofind hpm-fw-recovery)=0
|
||||
echo "Done"
|
||||
}
|
||||
|
||||
do_bmc_cpld_flash() {
|
||||
BMC_CPLD_IMAGE=$1
|
||||
echo "Flashing BMC CPLD"
|
||||
gpioset $(gpiofind jtag-program-sel)=0
|
||||
sleep 2
|
||||
ampere_cpldupdate_jtag -t 1 -p "$BMC_CPLD_IMAGE"
|
||||
echo "Done"
|
||||
}
|
||||
|
||||
do_bp_cpld_flash() {
|
||||
BP_CPLD_IMAGE=$1
|
||||
BP_TARGET=$2
|
||||
if [[ $BP_TARGET == 1 ]]; then
|
||||
echo "Flashing Front Backplane 1 CPLD"
|
||||
ampere_cpldupdate_i2c -b 101 -s 0x40 -t 3 -p "$BP_CPLD_IMAGE"
|
||||
elif [[ $BP_TARGET == 2 ]]; then
|
||||
echo "Flashing Front Backplane 2 CPLD"
|
||||
ampere_cpldupdate_i2c -b 102 -s 0x40 -t 3 -p "$BP_CPLD_IMAGE"
|
||||
elif [[ $BP_TARGET == 3 ]]; then
|
||||
echo "Flashing Front Backplane 3 CPLD"
|
||||
ampere_cpldupdate_i2c -b 100 -s 0x40 -t 3 -p "$BP_CPLD_IMAGE"
|
||||
elif [[ $BP_TARGET == 4 ]]; then
|
||||
echo "Flashing Rear Backplane 1 CPLD"
|
||||
ampere_cpldupdate_i2c -b 103 -s 0x40 -t 3 -p "$BP_CPLD_IMAGE"
|
||||
elif [[ $BP_TARGET == 5 ]]; then
|
||||
echo "Flashing Rear Backplane 2 CPLD"
|
||||
ampere_cpldupdate_i2c -b 104 -s 0x40 -t 3 -p "$BP_CPLD_IMAGE"
|
||||
fi
|
||||
|
||||
echo "Done"
|
||||
}
|
||||
|
||||
if [ $# -eq 0 ]; then
|
||||
echo "Usage:"
|
||||
echo " - Flash Boot EEPROM"
|
||||
echo " $(basename "$0") eeprom <Image file>"
|
||||
echo " - Flash FRU"
|
||||
echo " $(basename "$0") fru <Image file> [dev]"
|
||||
echo " Where:"
|
||||
echo " dev: 1 - MB FRU, 2 - BMC FRU"
|
||||
echo " - Flash Mainboard CPLD"
|
||||
echo " $(basename "$0") mb_cpld <Image file>"
|
||||
echo " - Flash BMC CPLD (only for DC-SCM BMC board)"
|
||||
echo " $(basename "$0") bmc_cpld <Image file>"
|
||||
echo " - Flash Backplane CPLD"
|
||||
echo " $(basename "$0") bp_cpld <Image file> <Target> "
|
||||
echo " Where:"
|
||||
echo " Target: 1 - FrontBP1, 2 - FrontBP2, 3 - FrontBP3"
|
||||
echo " 4 - RearBP1, 5 - RearBP2"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
TYPE=$1
|
||||
IMAGE=$2
|
||||
TARGET=$3
|
||||
if [ -z "$3" ]; then
|
||||
BACKUP_SEL=1
|
||||
else
|
||||
BACKUP_SEL=$3
|
||||
fi
|
||||
|
||||
if [[ $TYPE == "eeprom" ]]; then
|
||||
# Run EEPROM update: write/read/validation with CRC32 checksum
|
||||
do_eeprom_flash "$IMAGE" "$BACKUP_SEL"
|
||||
elif [[ $TYPE == "fru" ]]; then
|
||||
# Run FRU update
|
||||
do_fru_flash "$IMAGE" "$BACKUP_SEL"
|
||||
elif [[ $TYPE == "mb_cpld" ]]; then
|
||||
# Run Mainboard CPLD update
|
||||
do_mb_cpld_flash "$IMAGE"
|
||||
elif [[ $TYPE == "bmc_cpld" ]]; then
|
||||
# Run CPLD BMC update
|
||||
do_bmc_cpld_flash "$IMAGE"
|
||||
elif [[ $TYPE == "bp_cpld" ]]; then
|
||||
# Run Backplane CPLD update
|
||||
do_bp_cpld_flash "$IMAGE" "$TARGET"
|
||||
fi
|
||||
|
||||
exit 0
|
||||
Executable
+99
@@ -0,0 +1,99 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Helper script to report firmware version for components on the system (MB CPLD, Backplane CPLD, …)
|
||||
# Author : Hieu Huynh (hieu.huynh@amperecomputing.com)
|
||||
#
|
||||
# Get MB CPLD firmware revision:
|
||||
# ampere_firmware_version.sh mb_cpld
|
||||
#
|
||||
# Get BMC CPLD firmware revision:
|
||||
# ampere_firmware_version.sh bmc_cpld
|
||||
#
|
||||
# Get Backplane CPLD firmware revision:
|
||||
# ampere_firmware_version.sh bp_cpld <id>
|
||||
# <id>: 1 for Front Backplane 1
|
||||
# 2 for Front Backplane 2
|
||||
# 3 for Front Backplane 3
|
||||
# 4 for Rear Backplane 1
|
||||
# 5 for Rear Backplane 2
|
||||
|
||||
# shellcheck disable=SC2046
|
||||
|
||||
do_mb_cpld_firmware_report() {
|
||||
echo "MB CPLD"
|
||||
gpioset $(gpiofind hpm-fw-recovery)=1
|
||||
gpioset $(gpiofind jtag-program-sel)=1
|
||||
sleep 1
|
||||
ampere_cpldupdate_jtag -v
|
||||
ampere_cpldupdate_jtag -i
|
||||
}
|
||||
|
||||
do_bmc_cpld_firmware_report() {
|
||||
echo "BMC CPLD (Only for DC-SCM board)"
|
||||
gpioset $(gpiofind jtag-program-sel)=0
|
||||
sleep 1
|
||||
ampere_cpldupdate_jtag -v
|
||||
ampere_cpldupdate_jtag -i
|
||||
}
|
||||
|
||||
do_bp_cpld_firmware_report() {
|
||||
BP_ID=$1
|
||||
if [[ $BP_ID == 1 ]]; then
|
||||
echo "Front Backplane 1 CPLD"
|
||||
ampere_cpldupdate_i2c -b 101 -s 0x40 -t 3 -v
|
||||
ampere_cpldupdate_i2c -b 101 -s 0x40 -t 3 -i
|
||||
elif [[ $BP_ID == 2 ]]; then
|
||||
echo "Front Backplane 2 CPLD"
|
||||
ampere_cpldupdate_i2c -b 102 -s 0x40 -t 3 -v
|
||||
ampere_cpldupdate_i2c -b 102 -s 0x40 -t 3 -i
|
||||
elif [[ $BP_ID == 3 ]]; then
|
||||
echo "Front Backplane 3 CPLD"
|
||||
ampere_cpldupdate_i2c -b 100 -s 0x40 -t 3 -v
|
||||
ampere_cpldupdate_i2c -b 100 -s 0x40 -t 3 -i
|
||||
elif [[ $BP_ID == 4 ]]; then
|
||||
echo "Rear Backplane 1 CPLD"
|
||||
ampere_cpldupdate_i2c -b 103 -s 0x40 -t 3 -v
|
||||
ampere_cpldupdate_i2c -b 103 -s 0x40 -t 3 -i
|
||||
elif [[ $BP_ID == 5 ]]; then
|
||||
echo "Rear Backplane 2 CPLD"
|
||||
ampere_cpldupdate_i2c -b 104 -s 0x40 -t 3 -v
|
||||
ampere_cpldupdate_i2c -b 104 -s 0x40 -t 3 -i
|
||||
fi
|
||||
}
|
||||
|
||||
if [ $# -eq 0 ]; then
|
||||
echo "Usage:"
|
||||
echo " - Get MB CPLD firmware revision"
|
||||
echo " $(basename "$0") mb_cpld"
|
||||
echo " - Get BMC CPLD firmware revision"
|
||||
echo " $(basename "$0") bmc_cpld"
|
||||
echo " - Get Backplane CPLD firmware revision"
|
||||
echo " $(basename "$0") bp_cpld <id>"
|
||||
echo " <id>:"
|
||||
echo " 1 - FrontBP1"
|
||||
echo " 2 - FrontBP2"
|
||||
echo " 3 - FrontBP3"
|
||||
echo " 4 - RearBP1"
|
||||
echo " 5 - RearBP2"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
TYPE=$1
|
||||
ID=$2
|
||||
|
||||
if [[ $TYPE == "mb_cpld" ]]; then
|
||||
do_mb_cpld_firmware_report
|
||||
elif [[ $TYPE == "bmc_cpld" ]]; then
|
||||
do_bmc_cpld_firmware_report
|
||||
elif [[ $TYPE == "bp_cpld" ]]; then
|
||||
if [ -z "$ID" ]; then
|
||||
echo "Please choose backplanes id: 1 - FrontBP1, 2 - FrontBP2, 3 - FrontBP3, 4 - FrontBP4, 5 - FrontBP5"
|
||||
exit 0
|
||||
elif [[ "$ID" -ge "1" ]] && [[ "$ID" -le "5" ]]; then
|
||||
do_bp_cpld_firmware_report "$ID"
|
||||
else
|
||||
echo "Backplanes id invalid"
|
||||
fi
|
||||
fi
|
||||
|
||||
exit 0
|
||||
+162
@@ -0,0 +1,162 @@
|
||||
#!/bin/bash
|
||||
|
||||
# This script is used to flash the UEFI/EDKII
|
||||
|
||||
# Syntax: ampere_flash_bios.sh $image_file $device_sellect
|
||||
# Where:
|
||||
# $image_file : the image binary file
|
||||
# $device_sellect : 1 - Host Main SPI Nor
|
||||
# 2 - Host Second SPI Nor
|
||||
|
||||
# Author : Chanh Nguyen (chnguyen@amperecomputing.com)
|
||||
|
||||
# Note:
|
||||
# BMC_GPIOW6_SPI0_PROGRAM_SEL (GPIO 182): 1 => BMC owns SPI bus for upgrading
|
||||
# 0 => HOST owns SPI bus for upgrading
|
||||
|
||||
# BMC_GPIOW7_SPI0_BACKUP_SEL (GPIO 183) : 1 => to switch SPI_CS0_L to primary SPI Nor device
|
||||
# 0 => to switch SPI_CS0_L to second SPI Nor device
|
||||
|
||||
# shellcheck disable=SC2046
|
||||
|
||||
do_flash () {
|
||||
# Check the HNOR partition available
|
||||
HOST_MTD=$(< /proc/mtd grep "pnor" | sed -n 's/^\(.*\):.*/\1/p')
|
||||
if [ -z "$HOST_MTD" ];
|
||||
then
|
||||
# Check the ASpeed SMC driver binded before
|
||||
HOST_SPI=/sys/bus/platform/drivers/spi-aspeed-smc/1e630000.spi
|
||||
if [ -d "$HOST_SPI" ]; then
|
||||
echo "Unbind the ASpeed SMC driver"
|
||||
echo 1e630000.spi > /sys/bus/platform/drivers/spi-aspeed-smc/unbind
|
||||
sleep 2
|
||||
fi
|
||||
|
||||
# If the HNOR partition is not available, then bind again driver
|
||||
echo "--- Bind the ASpeed SMC driver"
|
||||
echo 1e630000.spi > /sys/bus/platform/drivers/spi-aspeed-smc/bind
|
||||
sleep 2
|
||||
|
||||
HOST_MTD=$(< /proc/mtd grep "pnor" | sed -n 's/^\(.*\):.*/\1/p')
|
||||
if [ -z "$HOST_MTD" ];
|
||||
then
|
||||
echo "Fail to probe Host SPI-NOR device"
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
|
||||
echo "--- Flashing firmware image $IMAGE to @/dev/$HOST_MTD"
|
||||
flashcp -v "$IMAGE" /dev/"$HOST_MTD"
|
||||
}
|
||||
|
||||
|
||||
if [ $# -eq 0 ]; then
|
||||
echo "Usage: $(basename "$0") <UEFI/EDKII image file> <DEV_SEL> [SPECIAL_BOOT]"
|
||||
echo "Where:"
|
||||
echo " DEV_SEL 1 is Primary SPI (by default), 2 is Second SPI"
|
||||
echo " SPECIAL_BOOT: Optional, input '1' to enter & flash SPECIAL_BOOT mode. Default: 0"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
IMAGE="$1"
|
||||
if [ ! -f "$IMAGE" ]; then
|
||||
echo "The image file $IMAGE does not exist"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [ -z "$2" ]; then
|
||||
DEV_SEL="1" # by default, select primary device
|
||||
else
|
||||
DEV_SEL="$2"
|
||||
fi
|
||||
|
||||
SPECIAL_BOOT=0
|
||||
if [[ "$3" == "1" ]]; then
|
||||
SPECIAL_BOOT=1
|
||||
fi
|
||||
|
||||
echo "SPECIAL_BOOT mode: $SPECIAL_BOOT"
|
||||
# Turn off the Host if it is currently ON
|
||||
chassisstate=$(obmcutil chassisstate | awk -F. '{print $NF}')
|
||||
echo "--- Current Chassis State: $chassisstate"
|
||||
if [ "$chassisstate" == 'On' ];
|
||||
then
|
||||
echo "--- Turning the Chassis off"
|
||||
obmcutil chassisoff
|
||||
sleep 10
|
||||
# Check if HOST was OFF
|
||||
chassisstate_off=$(obmcutil chassisstate | awk -F. '{print $NF}')
|
||||
if [ "$chassisstate_off" == 'On' ];
|
||||
then
|
||||
echo "--- Error : Failed turning the Chassis off"
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
|
||||
# Switch the host SPI bus to BMC"
|
||||
echo "--- Switch the host SPI bus to BMC."
|
||||
if ! gpioset $(gpiofind spi0-program-sel)=1; then
|
||||
echo "ERROR: Switch the host SPI bus to BMC. Please check gpio state"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Switch the host SPI bus (between primary and secondary)
|
||||
# 183 is BMC_GPIOW7_SPI0_BACKUP_SEL
|
||||
if [[ $DEV_SEL == 1 ]]; then
|
||||
echo "Run update Primary Host SPI-NOR"
|
||||
gpioset $(gpiofind spi0-backup-sel)=1 # Primary SPI
|
||||
elif [[ $DEV_SEL == 2 ]]; then
|
||||
echo "Run update Second Host SPI-NOR"
|
||||
gpioset $(gpiofind spi0-backup-sel)=0 # Second SPI
|
||||
else
|
||||
echo "Please choose primary SPI (1) or second SPI (2)"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# Restrict to flash Second Host SPI-NOR in case of SPECIAL_BOOT
|
||||
if [ $SPECIAL_BOOT == 1 ] && [ "$DEV_SEL" == 2 ]; then
|
||||
echo "Not allow to flash the Second Host SPI-NOR with SPECIAL_BOOT image"
|
||||
exit
|
||||
fi
|
||||
|
||||
# Flash the firmware
|
||||
do_flash
|
||||
|
||||
# Assert SPECIAL_BOOT GPIO PIN
|
||||
if [[ $SPECIAL_BOOT == 1 ]]; then
|
||||
gpioset $(gpiofind host0-special-boot)=1
|
||||
fi
|
||||
|
||||
# Switch the SPI bus to the primary spi device
|
||||
echo "Switch to the Primary Host SPI-NOR"
|
||||
gpioset $(gpiofind spi0-backup-sel)=1 # Primary SPI
|
||||
|
||||
# Switch the host SPI bus to HOST."
|
||||
echo "--- Switch the host SPI bus to HOST."
|
||||
if ! gpioset $(gpiofind spi0-program-sel)=0; then
|
||||
echo "ERROR: Switch the host SPI bus to HOST. Please check gpio state"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [ "$chassisstate" == 'On' ] || [ $SPECIAL_BOOT == 1 ];
|
||||
then
|
||||
sleep 5
|
||||
echo "Turn on the Host"
|
||||
obmcutil poweron
|
||||
fi
|
||||
|
||||
# Deassert SPECIAL_BOOT GPIO PIN if it is being asserted
|
||||
if [[ $SPECIAL_BOOT == 1 ]]; then
|
||||
# Time out checking for Host ON is 60s
|
||||
cnt=12
|
||||
while [ "$cnt" -gt 0 ];
|
||||
do
|
||||
cnt=$((cnt - 1))
|
||||
if systemctl status obmc-host-already-on@0.target | grep "Active: active"; then
|
||||
echo "Deassert SPECIAL_BOOT GPIO PIN if it is being asserted."
|
||||
gpioset $(gpiofind host0-special-boot)=0
|
||||
exit 0
|
||||
fi
|
||||
sleep 5
|
||||
done
|
||||
fi
|
||||
+50
@@ -0,0 +1,50 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Each driver include driver name and driver path
|
||||
declare -a DRIVER_NAMEs=(
|
||||
"107-0070"
|
||||
"100-0071"
|
||||
"101-0071"
|
||||
"102-0071"
|
||||
"103-0071"
|
||||
"104-0071"
|
||||
"100-0050"
|
||||
"101-0050"
|
||||
"102-0050"
|
||||
"100-004c"
|
||||
"101-004c"
|
||||
"102-004c"
|
||||
)
|
||||
# Driver path should include / at the end
|
||||
declare -a DRIVER_PATHs=(
|
||||
"/sys/bus/i2c/drivers/pca954x/"
|
||||
"/sys/bus/i2c/drivers/pca954x/"
|
||||
"/sys/bus/i2c/drivers/pca954x/"
|
||||
"/sys/bus/i2c/drivers/pca954x/"
|
||||
"/sys/bus/i2c/drivers/pca954x/"
|
||||
"/sys/bus/i2c/drivers/pca954x/"
|
||||
"/sys/bus/i2c/drivers/at24/"
|
||||
"/sys/bus/i2c/drivers/at24/"
|
||||
"/sys/bus/i2c/drivers/at24/"
|
||||
"/sys/bus/i2c/drivers/lm75/"
|
||||
"/sys/bus/i2c/drivers/lm75/"
|
||||
"/sys/bus/i2c/drivers/lm75/"
|
||||
)
|
||||
|
||||
# get length of an array
|
||||
arraylength=${#DRIVER_NAMEs[@]}
|
||||
|
||||
# use for loop to read all values and indexes
|
||||
for (( i=0; i<"${arraylength}"; i++ ));
|
||||
do
|
||||
bindFile="${DRIVER_PATHs[$i]}bind"
|
||||
driverDir="${DRIVER_PATHs[$i]}${DRIVER_NAMEs[$i]}"
|
||||
echo "binding ${DRIVER_NAMEs[$i]} path ${DRIVER_PATHs[$i]} on Chassi Power On"
|
||||
if [ -d "$driverDir" ]; then
|
||||
echo "Driver ${DRIVER_NAMEs[$i]} is already bound."
|
||||
else
|
||||
echo "${DRIVER_NAMEs[$i]}" > "$bindFile"
|
||||
fi
|
||||
done
|
||||
|
||||
exit 0
|
||||
@@ -0,0 +1,131 @@
|
||||
#!/bin/bash
|
||||
|
||||
# shellcheck source=meta-ampere/meta-mitchell/recipes-ampere/platform/ampere-platform-init/gpio-lib.sh
|
||||
source /usr/sbin/gpio-lib.sh
|
||||
|
||||
# Usage of this utility
|
||||
function usage() {
|
||||
echo "usage: power-util mb [status|shutdown_ack|force_reset|soft_off|host_reboot_wa]";
|
||||
}
|
||||
|
||||
power_status() {
|
||||
st=$(busctl get-property xyz.openbmc_project.State.Chassis /xyz/openbmc_project/state/chassis0 xyz.openbmc_project.State.Chassis CurrentPowerState | cut -d"." -f6)
|
||||
if [ "$st" == "On\"" ]; then
|
||||
echo "on"
|
||||
else
|
||||
echo "off"
|
||||
fi
|
||||
}
|
||||
|
||||
shutdown_ack() {
|
||||
if [ -f "/run/openbmc/host@0-softpoweroff" ]; then
|
||||
echo "Receive shutdown ACK triggered after softportoff the host."
|
||||
touch /run/openbmc/host@0-softpoweroff-shutdown-ack
|
||||
else
|
||||
echo "Receive shutdown ACK triggered"
|
||||
sleep 3
|
||||
systemctl start obmc-chassis-poweroff@0.target
|
||||
fi
|
||||
}
|
||||
|
||||
soft_off() {
|
||||
# Trigger shutdown_req
|
||||
touch /run/openbmc/host@0-softpoweroff
|
||||
gpio_name_set host0-shd-req-n 0
|
||||
sleep 0.05
|
||||
gpio_name_set host0-shd-req-n 1
|
||||
|
||||
# Wait for shutdown_ack from the host in 30 seconds
|
||||
cnt=30
|
||||
while [ $cnt -gt 0 ];
|
||||
do
|
||||
# Wait for SHUTDOWN_ACK and create the host@0-softpoweroff-shutdown-ack
|
||||
if [ -f "/run/openbmc/host@0-softpoweroff-shutdown-ack" ]; then
|
||||
break
|
||||
fi
|
||||
sleep 1
|
||||
cnt=$((cnt - 1))
|
||||
done
|
||||
|
||||
# Softpoweroff is successed
|
||||
sleep 2
|
||||
rm -rf /run/openbmc/host@0-softpoweroff
|
||||
if [ -f "/run/openbmc/host@0-softpoweroff-shutdown-ack" ]; then
|
||||
rm -rf /run/openbmc/host@0-softpoweroff-shutdown-ack
|
||||
fi
|
||||
echo 0
|
||||
}
|
||||
|
||||
force_reset() {
|
||||
if [ -f "/run/openbmc/host@0-softpoweroff" ]; then
|
||||
# In graceful host reset, after trigger os shutdown,
|
||||
# the phosphor-state-manager will call force-warm-reset
|
||||
# in this case the force_reset should wait for shutdown_ack from host
|
||||
cnt=30
|
||||
while [ $cnt -gt 0 ];
|
||||
do
|
||||
if [ -f "/run/openbmc/host@0-softpoweroff-shutdown-ack" ]; then
|
||||
break
|
||||
fi
|
||||
echo "Waiting for shutdown-ack count down $cnt"
|
||||
sleep 1
|
||||
cnt=$((cnt - 1))
|
||||
done
|
||||
# The host OS is failed to shutdown
|
||||
if [ $cnt == 0 ]; then
|
||||
echo "Shutdown-ack time out after 30s."
|
||||
exit 0
|
||||
fi
|
||||
fi
|
||||
rm -f /run/openbmc/host@0-on
|
||||
echo "Triggering sysreset pin"
|
||||
gpio_name_set host0-sysreset-n 0
|
||||
sleep 1
|
||||
gpio_name_set host0-sysreset-n 1
|
||||
}
|
||||
|
||||
host_reboot_wa() {
|
||||
busctl set-property xyz.openbmc_project.State.Chassis \
|
||||
/xyz/openbmc_project/state/chassis0 xyz.openbmc_project.State.Chassis \
|
||||
RequestedPowerTransition s "xyz.openbmc_project.State.Chassis.Transition.Off"
|
||||
|
||||
while ( true )
|
||||
do
|
||||
if systemctl status obmc-power-off@0.target | grep "Active: active"; then
|
||||
break;
|
||||
fi
|
||||
sleep 2
|
||||
done
|
||||
echo "The power is already Off."
|
||||
|
||||
busctl set-property xyz.openbmc_project.State.Host \
|
||||
/xyz/openbmc_project/state/host0 xyz.openbmc_project.State.Host \
|
||||
RequestedHostTransition s "xyz.openbmc_project.State.Host.Transition.On"
|
||||
}
|
||||
|
||||
if [ ! -d "/run/openbmc/" ]; then
|
||||
mkdir -p "/run/openbmc/"
|
||||
fi
|
||||
|
||||
if [ "$2" == "shutdown_ack" ]; then
|
||||
shutdown_ack
|
||||
elif [ "$2" == "status" ]; then
|
||||
power_status
|
||||
elif [ "$2" == "force_reset" ]; then
|
||||
force_reset
|
||||
elif [ "$2" == "host_reboot_wa" ]; then
|
||||
host_reboot_wa
|
||||
elif [ "$2" == "soft_off" ]; then
|
||||
ret=$(soft_off)
|
||||
if [ "$ret" == 0 ]; then
|
||||
echo "The host is already softoff"
|
||||
else
|
||||
echo "Failed to softoff the host"
|
||||
fi
|
||||
exit "$ret";
|
||||
else
|
||||
echo "Invalid parameter2=$2"
|
||||
usage;
|
||||
fi
|
||||
|
||||
exit 0;
|
||||
+94
@@ -0,0 +1,94 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Helper script to support enable/disable Scandump Mode
|
||||
# Author : Hieu Huynh (hieu.huynh@amperecomputing.com)
|
||||
#
|
||||
# To enable Scandump mode:
|
||||
# ampere_scandump_mode.sh enable
|
||||
#
|
||||
# To disable Scandump mode:
|
||||
# ampere_scandump_mode.sh disable
|
||||
#
|
||||
# To get Scandump mode status:
|
||||
# ampere_scandump_mode.sh getstatus
|
||||
|
||||
enable_scandump_mode() {
|
||||
echo "Enable Scandump mode"
|
||||
# Disable Mpro hang detection
|
||||
systemctl stop ampere-sysfw-hang-handler.service
|
||||
|
||||
# Disable PLDM service
|
||||
systemctl stop pldmd.service
|
||||
|
||||
# Enable scandump mode in CPLD
|
||||
# Get Port0 value
|
||||
p0_val=$(i2cget -f -y 15 0x22 0x02)
|
||||
p0_val=$(("$p0_val" | (1 << 4)))
|
||||
# Set Port0[4] value to "1" to mask all CPU’s GPIOs, set Port0[4].
|
||||
i2cset -f -y 15 0x22 0x02 $p0_val
|
||||
|
||||
p0_IOexp_val=$(i2cget -f -y 15 0x22 0x06)
|
||||
p0_IOexp_val=$(("$p0_IOexp_val" & ~(1 << 4)))
|
||||
# Config CPLD's IOepx Port0[4] from input to output, clear IOepx Port0[4].
|
||||
i2cset -f -y 15 0x22 0x06 $p0_IOexp_val
|
||||
}
|
||||
|
||||
diable_scandump_mode() {
|
||||
echo "Disable Scandump mode"
|
||||
|
||||
# Disable scandump mode in CPLD
|
||||
# Get Port0 value
|
||||
p0_val=$(i2cget -f -y 15 0x22 0x02)
|
||||
p0_val=$(("$p0_val" & ~(1 << 4)))
|
||||
# Set Port0[4] value to "0" to unmask all CPU’s GPIOs, clear Port0[4].
|
||||
i2cset -f -y 15 0x22 0x02 $p0_val
|
||||
|
||||
p0_IOexp_val=$(i2cget -f -y 15 0x22 0x06)
|
||||
p0_IOexp_val=$(("$p0_IOexp_val" | (1 << 4)))
|
||||
# Config CPLD's IOepx Port0[4] from output to input, set IOepx Port0[4].
|
||||
i2cset -f -y 15 0x22 0x06 $p0_IOexp_val
|
||||
|
||||
# Enable Mpro hang detection
|
||||
systemctl start ampere-sysfw-hang-handler.service
|
||||
|
||||
# Enable PLDM service
|
||||
systemctl start pldmd.service
|
||||
}
|
||||
|
||||
getstatus() {
|
||||
# Get CPLD's IOepx Port0[4], if this bit is "0" scandump mode is enabled.
|
||||
p0_IOexp_val=$(i2cget -f -y 15 0x22 0x06)
|
||||
p0_IOexp_val=$(("$p0_IOexp_val" & (1 << 4)))
|
||||
if [[ "$p0_IOexp_val" == "0" ]]; then
|
||||
echo "Scandump mode is enabled"
|
||||
exit 1
|
||||
else
|
||||
echo "Scandump mode is disabled"
|
||||
exit 0
|
||||
fi
|
||||
}
|
||||
|
||||
# Usage of this utility
|
||||
usage() {
|
||||
echo "Usage:"
|
||||
echo " - To enable Scandump mode"
|
||||
echo " $(basename "$0") enable"
|
||||
echo " - To disable Scandump mode"
|
||||
echo " $(basename "$0") disable"
|
||||
echo " - To get Scandump mode status"
|
||||
echo " $(basename "$0") getstatus"
|
||||
exit 0
|
||||
}
|
||||
|
||||
if [[ $1 == "enable" ]]; then
|
||||
enable_scandump_mode
|
||||
elif [[ $1 == "disable" ]]; then
|
||||
diable_scandump_mode
|
||||
elif [[ $1 == "getstatus" ]]; then
|
||||
getstatus
|
||||
else
|
||||
echo "Invalid mode"
|
||||
usage
|
||||
fi
|
||||
|
||||
exit 0
|
||||
Reference in New Issue
Block a user