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,12 @@
[Unit]
Description=Ampere BMC heartbeat service
[Service]
Type=simple
Restart=always
ExecStart=/usr/sbin/ampere_bmc_heartbeat.sh
SyslogIdentifier = "ampere-bmc-heartbeat"
[Install]
WantedBy=multi-user.target
@@ -0,0 +1,11 @@
[Unit]
Description = Ampere Platform Initialization
[Service]
Restart=no
RemainAfterExit=true
Type=oneshot
ExecStart=/usr/sbin/ampere_platform_init.sh
[Install]
WantedBy=sysinit.target
@@ -0,0 +1,19 @@
#!/bin/bash
# shellcheck source=meta-ampere/meta-mitchell/recipes-ampere/platform/ampere-platform-init/gpio-lib.sh
source /usr/sbin/gpio-lib.sh
value=0
while true;
do
if [[ $value -eq 0 ]]; then
value=1
gpio_name_set led-sw-hb 1
gpio_name_set led-bmc-hb 0
else
value=0
gpio_name_set led-sw-hb 0
gpio_name_set led-bmc-hb 1
fi
sleep 1s
done
@@ -0,0 +1,52 @@
#!/bin/bash
# shellcheck source=meta-ampere/meta-mitchell/recipes-ampere/platform/ampere-platform-init/gpio-lib.sh
source /usr/sbin/gpio-lib.sh
# shellcheck source=meta-ampere/meta-mitchell/recipes-ampere/platform/ampere-platform-init/mtmitchell_platform_gpios_init.sh
source /usr/sbin/platform_gpios_init.sh
source /usr/sbin/ampere_uart_console_setup.sh
#pre platform init function. implemented in platform_gpios_init.sh
pre-platform-init
# =======================================================
# Setting default value for device sel and mux
bootstatus=$(cat /sys/class/watchdog/watchdog0/bootstatus)
if [ "$bootstatus" == '32' ]; then
echo "CONFIGURE: gpio pins to output high after AC power"
for gpioName in "${output_high_gpios_in_ac[@]}"; do
gpio_name_set "$gpioName" 1
done
echo "CONFIGURE: gpio pins to output low after AC power"
for gpioName in "${output_low_gpios_in_ac[@]}"; do
gpio_name_set "$gpioName" 0
done
echo "CONFIGURE: gpio pins to input after AC power"
for gpioName in "${input_gpios_in_ac[@]}"; do
gpio_name_input "$gpioName"
done
fi
# =======================================================
# Setting default value for others gpio pins
echo "CONFIGURE: gpio pins to output high"
for gpioName in "${output_high_gpios_in_bmc_reboot[@]}"; do
gpio_name_set "$gpioName" 1
done
echo "CONFIGURE: gpio pins to output low"
for gpioName in "${output_low_gpios_in_bmc_reboot[@]}"; do
gpio_name_set "$gpioName" 0
done
echo "CONFIGURE: gpio pins to input"
for gpioName in "${input_gpios_in_bmc_reboot[@]}"; do
gpio_name_input "$gpioName"
done
# =======================================================
# Setting uart muxes to BMC as default
uart_console_setup
#post platform init function. implemented in platform_gpios_init.sh
post-platform-init
exit 0
@@ -0,0 +1,47 @@
#!/bin/sh -e
# shellcheck disable=SC2039
# shellcheck disable=SC2112
# shellcheck disable=SC3010
# shellcheck disable=SC3030
# shellcheck disable=SC3054
export obmc_console_tty=("ttyS0" "ttyS1" "ttyS2" "ttyS3" "ttyS7" "ttyS8")
function get_uart_port()
{
tty=$1
case "${tty}" in
"ttyS0") uart=1
;;
"ttyS1") uart=2
;;
"ttyS2") uart=3
;;
"ttyS3") uart=4
;;
"ttyS7") uart=0
;;
"ttyS8") uart=0
;;
*) echo "Invalid tty passed to $0. Exiting!"
exit 1;
;;
esac
echo $uart
}
function uart_console_setup()
{
# Default the host routing through the mux to use the BMC (2)
# This allows the SoL console in webui, and the ssh port 2200, to work
# upon startup. If UART transcievers are installed on the header and required,
# this value should be set to 1
for tty in "${obmc_console_tty[@]}"; do
uart=$(get_uart_port "$tty")
if [ "${uart}" -ne 0 ]
then
/usr/sbin/ampere_uartmux_ctrl.sh "${uart}" 2
fi
done
}
@@ -0,0 +1,44 @@
#!/bin/bash
#
# shellcheck disable=SC2046
# This can be called to set uart mux manually
if [ $# -lt 2 ]; then
exit 1
fi
case "$1" in
1) GPIO_UARTx_MODE0="uart1-mode0"
GPIO_UARTx_MODE1="uart1-mode1"
;;
2) GPIO_UARTx_MODE0="uart2-mode0"
GPIO_UARTx_MODE1="uart2-mode1"
;;
3) GPIO_UARTx_MODE0="uart3-mode0"
GPIO_UARTx_MODE1="uart3-mode1"
;;
4) GPIO_UARTx_MODE0="uart4-mode0"
GPIO_UARTx_MODE1="uart4-mode1"
;;
*) echo "Invalid UART port selection"
exit 1
;;
esac
echo "Ampere UART MUX CTRL UART port $1 to mode $2"
case "$2" in
# To HDR
1) gpioset $(gpiofind "$GPIO_UARTx_MODE0")=1
gpioset $(gpiofind "$GPIO_UARTx_MODE1")=0
exit 0
;;
# To BMC
2) gpioset $(gpiofind "$GPIO_UARTx_MODE0")=0
gpioset $(gpiofind "$GPIO_UARTx_MODE1")=1
exit 0
;;
*) echo "Invalid UART mode selection"
exit 1
;;
esac
@@ -0,0 +1,69 @@
#!/bin/bash
# Configure GPIO as output and set its value
AST2600_GPIO_BASE=(
816
780
)
function gpio_configure_output() {
echo "$1" > /sys/class/gpio/export
echo out > /sys/class/gpio/gpio"$1"/direction
echo "$2" > /sys/class/gpio/gpio"$1"/value
echo "$1" > /sys/class/gpio/unexport
}
function gpio_get_val() {
echo "$1" > /sys/class/gpio/export
cat /sys/class/gpio/gpio"$1"/value
echo "$1" > /sys/class/gpio/unexport
}
# Configure GPIO as input
function gpio_configure_input() {
echo "$1" > /sys/class/gpio/export
echo "in" > /sys/class/gpio/gpio"$1"/direction
echo "$1" > /sys/class/gpio/unexport
}
function gpio_name_set()
{
str=$(gpiofind "$1")
#Verify error code when run gpiofind
if [ "$?" == '1' ]; then
echo "Invalid gpio name $1"
else
gpioid=$(echo "$str"|cut -c 9)
offset=$(echo "$str"|cut -d " " -f 2)
gpioPin=$(("$offset" + ${AST2600_GPIO_BASE[$gpioid]}))
gpio_configure_output "$gpioPin" "$2"
fi
}
function gpio_name_get()
{
str=$(gpiofind "$1")
#Verify error code when run gpiofind
if [ "$?" == '1' ]; then
echo "Invalid gpio name $1"
else
offset=$(echo "$str"|cut -d " " -f 2)
gpioid=$(echo "$str"|cut -c 9)
gpioPin=$(("$offset" + ${AST2600_GPIO_BASE[$gpioid]}))
gpio_get_val "$gpioPin"
fi
}
function gpio_name_input()
{
str=$(gpiofind "$1")
#Verify error code when run gpiofind
if [ "$?" == '1' ]; then
echo "Invalid gpio name $1"
else
gpioid=$(echo "$str"|cut -c 9)
offset=$(echo "$str"|cut -d " " -f 2)
gpioPin=$(("$offset" + ${AST2600_GPIO_BASE[$gpioid]}))
gpio_configure_input "$gpioPin"
fi
}
@@ -0,0 +1,144 @@
#!/bin/bash
# shellcheck source=meta-ampere/meta-mitchell/recipes-ampere/platform/ampere-platform-init/gpio-lib.sh
source /usr/sbin/gpio-lib.sh
function bind_rtc_driver() {
# If rtc device can not present, bind the device
if [[ ! -e /dev/rtc0 ]]; then
echo "Bind rtc driver"
echo 6-0051 > /sys/bus/i2c/drivers/rtc-pcf85063/bind
fi
}
function pre-platform-init() {
echo "Do pre platform init"
}
function post-platform-init() {
# When BMC is rebooted, because PSON_L has pull up to P3V3_STB, it changes its
# value to HIGH. Add code to check P3V3_STB and recover PSON_L to correct state
# before setting BMC_RDY.
cnt=10
pgood=""
while [ $cnt -gt 0 ];
do
pgood=$(busctl get-property org.openbmc.control.Power /org/openbmc/control/power0 org.openbmc.control.Power pgood | cut -d' ' -f2)
if [[ "$pgood" != '' ]]; then
break;
fi
cnt=$(( cnt - 1 ))
sleep 1
done
if [ "$pgood" == '1' ]; then
echo "PSU is on. Setting PSON to 0"
gpio_name_set power-chassis-control 0
else
echo "pgood D-Bus property response as 0. PSU is off."
# for unknown reason when stress reboot bmc power-control.exe detect power-chassis-good is 1 (power on)
# But "busctl get-property org.openbmc.control.Power /org/openbmc/control/power0 org.openbmc.control.Power pgood" responses 0 (power off)
# Add sleep 3 seconds after the pgood dbus reponse (power off) and recheck the power-chassis-good to confirm about the PSU power state
sleep 3
pgood=$(gpio_name_get power-chassis-good)
if [ "$pgood" == '0' ]; then
echo "power-chassis-good reponse as 0. Confirm PSU is off. Setting PSON to 1."
gpio_name_set power-chassis-control 1
fi
fi
gpio_name_set host0-sysreset-n 1
# gpio-leds is controlling bmc-ready, not by gpio
echo 1 > /sys/class/leds/bmc-ready/brightness
echo "Set default FAN speed to 60%"
for filename in /sys/class/hwmon/*/pwm*
do
echo 153 > "$filename"
done
# Bind rtc driver
bind_rtc_driver
}
export output_high_gpios_in_ac=(
# add device enable, mux setting, device select gpios
"spi0-backup-sel"
"i2c-backup-sel"
)
export output_low_gpios_in_ac=(
# add device enable, mux setting, device select gpios
"spi0-program-sel"
"ocp-main-pwren"
)
export input_gpios_in_ac=(
# add device enable, mux setting, device select gpios
)
export output_high_gpios_in_bmc_reboot=(
"host0-sysreset-n"
"host0-pmin-n"
"bmc-debug-mode"
"vrd-sel"
"spd-sel"
"ext-high-temp-n"
"fpga-program-b"
"wd-disable-n"
"hpm-stby-rst-n"
"jtag-sel-s0"
"cpld-user-mode"
"jtag-srst-n"
"host0-shd-req-n"
)
export output_low_gpios_in_bmc_reboot=(
"rtc-battery-voltage-read-enable"
"s0-rtc-lock"
"hpm-fw-recovery"
"led-fault"
"spi-nor-access"
"host0-special-boot"
)
export input_gpios_in_bmc_reboot=(
"s0-vrd-fault-n"
"s1-vrd-fault-n"
"irq-n"
"presence-ps0"
"presence-ps1"
"hsc-12vmain-alt2-n"
"eth-phy-int-n"
"s0-pcp-oc-warn-n"
"s1-pcp-oc-warn-n"
"cpu-bios-recover"
"s0-heartbeat"
"hs-scout-proc-hot"
"s0-vr-hot-n"
"s1-vr-hot-n"
"hsc-12vmain-alt1-n"
"power-chassis-good"
"s0-ddr-save"
"soc-spi-nor-access"
"presence-cpu0"
"jtag-dbgr-prsnt-n"
"ps0-ac-loss-n"
"ps1-ac-loss-n"
"s1-ddr-save"
"sys-pgood"
"presence-cpu1"
"s0-fault-alert"
"s0-sys-auth-failure-n"
"host0-ready"
"ocp-pgood"
"s1-fault-alert"
"s1-fw-boot-ok"
"s0-spi-auth-fail-n"
"s1-sys-auth-failure-n"
"cpld-s1-spi-auth-fail-n"
"ps0-pgood"
"ps1-pgood"
"s0-soc-pgood"
)