Initial commit

This commit is contained in:
Your Name
2026-04-23 17:07:55 +08:00
commit b7e39e063b
16725 changed files with 1625565 additions and 0 deletions
@@ -0,0 +1,29 @@
#!/bin/bash
DELAY_BEFORE_BIND=5000000
# Each driver include driver name and driver path
declare -a DRIVER_NAMEs=("2-004f"
"2-004e"
)
# Driver path should include / at the end
declare -a DRIVER_PATHs=("/sys/bus/i2c/drivers/smpro-core/"
"/sys/bus/i2c/drivers/smpro-core/"
)
# get length of an array
arraylength=${#DRIVER_NAMEs[@]}
usleep $DELAY_BEFORE_BIND
# 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]}"
if [ -d "$driverDir" ]; then
echo "Driver ${DRIVER_NAMEs[$i]} is already bound."
continue;
fi
echo "${DRIVER_NAMEs[$i]}" > "$bindFile"
done
exit 0
@@ -0,0 +1,151 @@
#!/bin/bash
do_fru_upgrade() {
FRU_DEVICE="/sys/bus/i2c/devices/3-0050/eeprom"
if ! command -v ampere_fru_upgrade;
then
echo "Bypass fru update as no ampere_fru_upgrade available"
exit
fi
ampere_fru_upgrade -d $FRU_DEVICE -f "$IMAGE"
systemctl restart xyz.openbmc_project.FruDevice.service
systemctl restart phosphor-ipmi-host.service
}
do_smpmpro_upgrade() {
I2C_BUS_DEV="1"
EEPROM_ADDR="0x50"
if ! command -v ampere_eeprom_prog;
then
echo "Bypass SCP firmware update as no ampere_eeprom_prog available"
exit
fi
echo "SECPRO mode: $SECPRO"
# 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
# Wait 60s until Chassis is off
cnt=30
while [ "$cnt" -gt 0 ];
do
cnt=$((cnt - 1))
sleep 2
# Check if HOST was OFF
chassisstate_off=$(obmcutil chassisstate | awk -F. '{print $NF}')
if [ "$chassisstate_off" != 'On' ];
then
break
fi
if [ "$cnt" == "0" ];
then
echo "--- Error : Failed turning the Chassis off"
exit 1
fi
done
fi
if [[ $SECPRO == 1 ]]; then
# 3 is S0_SPECIAL_BOOT
gpioset 0 3=1
# 66 is S1_SPECIAL_BOOT
gpioset 0 66=1
fi
# Switch EEPROM control to BMC AST2500 I2C
# 226 is BMC_GPIOAC2_SPI0_PROGRAM_SEL
gpioset 0 226=0
# 08 is BMC_GPIOB0_I2C_BACKUP_SEL
if [[ $DEV_SEL == 1 ]]; then
echo "Run update primary Boot EEPROM"
gpioset 0 8=1 # Main EEPROM
elif [[ $DEV_SEL == 2 ]]; then
echo "Run update secondary Boot EEPROM"
gpioset 0 8=0 # Second EEPROM
else
echo "Please choose Main (1) or Second EEPROM (2)"
exit 0
fi
# Write Firmware to EEPROM and read back for validation
ampere_eeprom_prog -b $I2C_BUS_DEV -s $EEPROM_ADDR -p -f "$IMAGE"
# Switch EEPROM control to Host
# 08 is BMC_GPIOB0_I2C_BACKUP_SEL
gpioset 0 8=1
# 226 is BMC_GPIOAC2_SPI0_PROGRAM_SEL
gpioset 0 226=1
# Deassert SECPRO GPIO PINs
if [[ $SECPRO == 1 ]]; then
echo "De-asserting special GPIO PINs"
# 3 is S0_SPECIAL_BOOT
gpioset 0 3=0
# 66 is S1_SPECIAL_BOOT
gpioset 0 66=0
fi
if [ "$chassisstate" == 'On' ];
then
sleep 5
echo "Turn on the Host"
obmcutil poweron
fi
}
if [ $# -eq 0 ]; then
echo "Usage:"
echo " $(basename "$0") <Type> <Image file> <DEV_SEL> [SECPRO]"
echo "Where:"
echo " <Type>: smpmpro or fru"
echo " If Type is smpmpro, then DEV_SEL must is 1 (MAIN EEPROM), 2 (Failover)"
echo " SECPRO: Optional, input '1' to enter & flash secpro mode. Default: 0"
exit 0
fi
TYPE=$1
IMAGE=$2
if [ -z "$3" ]
then
DEV_SEL="1" # by default, select Main image
else
DEV_SEL=$3
fi
SECPRO=0
if [ -n "$4" ]; then
if [[ "$4" == "1" ]]; then
SECPRO=1
fi
fi
MANIFEST="$(echo "$IMAGE" | cut -d'/' -f-4)/MANIFEST"
if [ -f "$MANIFEST" ]; then
echo "MANIFEST: $MANIFEST"
if grep -qF "SECPRO" "$MANIFEST"; then
SECPRO=1
fi
fi
# Restrict to flash failover in case of SECPRO
if [ $SECPRO == 1 ] && [ "$DEV_SEL" == 2 ]; then
echo "Not allow to flash the failover with SECPRO image"
exit
fi
if [[ $TYPE == "smpmpro" ]]; then
do_smpmpro_upgrade
elif [[ $TYPE == "fru" ]]; then
do_fru_upgrade
fi
@@ -0,0 +1,129 @@
#!/bin/bash
#
# Copyright (c) 2021 Ampere Computing LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
do_flash () {
# Check the PNOR partition available
HOST_MTD=$(< /proc/mtd grep "pnor-uefi" | sed -n 's/^\(.*\):.*/\1/p')
if [ -z "$HOST_MTD" ];
then
# Check the ASpeed SMC driver bound 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 PNOR 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-uefi" | 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 to @/dev/$HOST_MTD"
flashcp -v "$IMAGE" /dev/"$HOST_MTD"
}
if [ $# -eq 0 ]; then
echo "Usage: $(basename "$0") <BIOS image file>"
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
# 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
# Wait 60s until Chassis is off
cnt=30
while [ "$cnt" -gt 0 ];
do
cnt=$((cnt - 1))
sleep 2
# Check if HOST was OFF
chassisstate_off=$(obmcutil chassisstate | awk -F. '{print $NF}')
if [ "$chassisstate_off" != 'On' ];
then
break
fi
if [ "$cnt" == "0" ];
then
echo "--- Error : Failed turning the Chassis off"
exit 1
fi
done
fi
# Switch the host SPI bus to BMC"
echo "--- Switch the host SPI bus to BMC."
if ! gpioset 0 226=0; 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)
# 227 is BMC_SPI0_BACKUP_SEL
if [[ $DEV_SEL == 1 ]]; then
echo "Run update primary Host SPI-NOR"
gpioset 0 227=0 # Primary SPI
elif [[ $DEV_SEL == 2 ]]; then
echo "Run update secondary Host SPI-NOR"
gpioset 0 227=1 # Second SPI
else
echo "Please choose primary SPI (1) or second SPI (2)"
exit 0
fi
# Flash the firmware
do_flash
# Switch the host SPI bus to HOST."
echo "--- Switch the host SPI bus to HOST."
if ! gpioset 0 226=1; then
echo "ERROR: Switch the host SPI bus to HOST. Please check gpio state"
exit 1
fi
if [ "$chassisstate" == 'On' ];
then
sleep 5
echo "Turn on the Host"
obmcutil poweron
fi
@@ -0,0 +1,120 @@
#!/bin/bash
# shellcheck source=meta-ampere/meta-jade/recipes-ampere/platform/ampere-utils/gpio-defs.sh
source /usr/sbin/gpio-defs.sh
# Usage of this utility
function usage() {
echo "Usage:"
echo " ampere_power_util.sh mb [status|shutdown_ack|force_reset|soft_off]";
}
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
gpioset -l 0 "$S0_SHD_REQ_L"=1
sleep 1s
gpioset -l 0 "$S0_SHD_REQ_L"=0
# 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
echo "Triggering sysreset pin"
gpioset -l 0 "$S0_SYSRESET_L"=1
sleep 1
gpioset -l 0 "$S0_SYSRESET_L"=0
}
if [ $# -lt 2 ]; then
echo "Total number of parameter=$#"
echo "Insufficient parameter"
usage;
exit 0;
fi
if [ "$1" != "mb" ]; then
echo "Invalid parameter1=$1"
usage;
exit 0;
fi
mkdir -p /run/openbmc/
if [ "$2" == "shutdown_ack" ]; then
shutdown_ack
elif [ "$2" == "status" ]; then
power_status
elif [ "$2" == "force_reset" ]; then
force_reset
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;
@@ -0,0 +1,59 @@
#!/bin/sh
# shellcheck disable=SC2034
# Index of GPIO device in gpioget/gpioset
GPIO_CHIP0_IDX=0
GPIO_CHIP1_IDX=1
# Base of GPIO chip in /sys/class/gpio
GPIO_CHIP0_BASE=792
GPIO_CHIP1_BASE=780
### Power control configuration
# Power control gpios
S0_SHD_REQ_L=49
S0_SHD_ACK_L=50
S0_REBOOT_ACK_L=75
S0_SYSRESET_L=91
S1_SYSRESET_L=92
### Table 1: GPIO Assignments
BMC_I2C_BACKUP_SEL=8
S0_CPU_FW_BOOT_OK=48
CPU_BMC_OVERTEMP_L=51
CPU_BMC_HIGHTEMP_L=72
CPU_FAULT_ALERT=73
S1_CPU_FW_BOOT_OK=202
S0_SPECIAL_BOOT=3
S1_SPECIAL_BOOT=66
RTC_LOCK=203
### Table 2: Alert and Additional Miscellaneous Signals
S0_SCP_AUTH_FAILURE=74
S1_SCP_AUTH_FAILURE=205
BMC_OK=228
SLAVE_PRESENT_L=230
### Common GPIOs
SYS_PSON_L=42
BMC_READY=229
### OCP power selection
OCP_AUX_PWREN=139
OCP_MAIN_PWREN=140
### SPI0 Mode selection
SPI0_PROGRAM_SEL=226
SPI0_BACKUP_SEL=227
### Mt.Jade specific GPIOs
S0_I2C9_ALERT_L=100
S1_I2C9_ALERT_L=101
GPIO_BMC_VGA_FRONT_PRES_L=135
GPIO_S0_VRHOT_L=144
GPIO_S1_VRHOT_L=145
BMC_VGA_SEL=195
BMC_GPIOR2_EXT_HIGHTEMP_L=138
GPIO_BMC_VR_PMBUS_SEL_L=149
GPIO_BMC_I2C6_RESET_L=63
@@ -0,0 +1,33 @@
#!/bin/bash
# shellcheck source=meta-ampere/meta-jade/recipes-ampere/platform/ampere-utils/gpio-defs.sh
source /usr/sbin/gpio-defs.sh
function gpio_number() {
GPIO_BASE=$(cat /sys/class/gpio/gpiochip"$GPIO_CHIP0_BASE"/base)
echo $((GPIO_BASE + $1))
}
# Configure GPIO as output and set its value
function gpio_configure_output() {
gpioId=$(gpio_number "$1")
echo "$gpioId" > /sys/class/gpio/export
echo out > /sys/class/gpio/gpio"${gpioId}"/direction
echo "$2" > /sys/class/gpio/gpio"${gpioId}"/value
echo "$gpioId" > /sys/class/gpio/unexport
}
function gpio_get_val() {
gpioId=$(gpio_number "$1")
echo "$gpioId" > /sys/class/gpio/export
cat /sys/class/gpio/gpio"$gpioId"/value
echo "$gpioId" > /sys/class/gpio/unexport
}
# Configure GPIO as input
function gpio_configure_input() {
gpioId=$(gpio_number "$1")
echo "$gpioId" > /sys/class/gpio/export
echo "in" > /sys/class/gpio/gpio"${gpioId}"/direction
echo "$gpioId" > /sys/class/gpio/unexport
}