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=Boot Status LED Manager
After=xyz.openbmc_project.LED.GroupManager.service
Wants=xyz.openbmc_project.LED.GroupManager.service
[Service]
ExecStart=/usr/bin/boot-status-led.sh
Type=simple
Restart=on-failure
[Install]
WantedBy=multi-user.target
@@ -0,0 +1,34 @@
#!/bin/bash
BOOT_SERVICE_NAME="xyz.openbmc_project.State.Host"
BOOT_STATUS_OBJPATH="/xyz/openbmc_project/state/host0"
BOOT_INTERFACE_NAME="xyz.openbmc_project.State.OperatingSystem.Status"
BOOT_Property="OperatingSystemState"
LED_SERVICE_NAME="xyz.openbmc_project.LED.GroupManager"
LED_INACTIVE_OBJPATH="/xyz/openbmc_project/led/groups/boot_status_inactive"
LED_STANDBY_OBJPATH="/xyz/openbmc_project/led/groups/boot_status_standby"
LED_INTERFACE_NAME="xyz.openbmc_project.Led.Group"
LED_Property="Asserted"
boot_status=""
led_status=""
while true; do
boot_status="$(busctl get-property $BOOT_SERVICE_NAME $BOOT_STATUS_OBJPATH $BOOT_INTERFACE_NAME $BOOT_Property | awk '{print $2}')"
if [[ $boot_status != "\"xyz.openbmc_project.State.OperatingSystem.Status.OSStatus.Standby\"" ]] && [[ $led_status != "BLINKING" ]];then
busctl set-property $LED_SERVICE_NAME $LED_INACTIVE_OBJPATH $LED_INTERFACE_NAME $LED_Property b true
busctl set-property $LED_SERVICE_NAME $LED_STANDBY_OBJPATH $LED_INTERFACE_NAME $LED_Property b false
led_status="BLINKING"
elif [[ $boot_status == "\"xyz.openbmc_project.State.OperatingSystem.Status.OSStatus.Standby\"" ]] && [[ $led_status != "ON" ]];then
busctl set-property $LED_SERVICE_NAME $LED_INACTIVE_OBJPATH $LED_INTERFACE_NAME $LED_Property b false
busctl set-property $LED_SERVICE_NAME $LED_STANDBY_OBJPATH $LED_INTERFACE_NAME $LED_Property b true
led_status="ON"
fi
sleep 10
done
exit 0
@@ -0,0 +1,25 @@
SUMMARY = "OpenBMC Mori Boot Status LED Service"
DESCRIPTION = "OpenBMC Mori Boot Status LED Daemon."
LICENSE = "Apache-2.0"
LIC_FILES_CHKSUM = "file://${COREBASE}/meta/files/common-licenses/Apache-2.0;md5=89aea4e17d99a7cacdbeed46a0096b10"
DEPENDS:append = " systemd"
PR = "r1"
SRC_URI = " \
file://boot-status-led.sh \
file://boot-status-led.service \
"
SYSTEMD_SERVICE:${PN} = "boot-status-led.service"
inherit systemd
do_install() {
install -d ${D}${bindir}
install -m 0755 ${WORKDIR}/boot-status-led.sh ${D}${bindir}/
install -d ${D}${systemd_system_unitdir}
install -m 0644 ${WORKDIR}/boot-status-led.service \
${D}${systemd_system_unitdir}
}
RDEPENDS:${PN}:append = " bash"
@@ -0,0 +1,31 @@
SUMMARY = "Phosphor OpenBMC Mori BIOS Firmware Upgrade Command"
DESCRIPTION = "Phosphor OpenBMC Mori BIOS Firmware Upgrade Comman Daemon"
LICENSE = "Apache-2.0"
LIC_FILES_CHKSUM = "file://${COREBASE}/meta/files/common-licenses/Apache-2.0;md5=89aea4e17d99a7cacdbeed46a0096b10"
DEPENDS:append = " systemd phosphor-ipmi-flash"
PROVIDES:append = " virtual/bios-update"
PR = "r1"
SRC_URI = " \
file://phosphor-ipmi-flash-bios-update.service \
file://config-bios.json \
"
SYSTEMD_SERVICE:${PN} = "phosphor-ipmi-flash-bios-update.service"
inherit systemd obmc-phosphor-systemd
do_install () {
install -d ${D}${datadir}/phosphor-ipmi-flash
install -m 0644 ${WORKDIR}/config-bios.json \
${D}${datadir}/phosphor-ipmi-flash
install -d ${D}${systemd_system_unitdir}
install -m 0644 ${WORKDIR}/phosphor-ipmi-flash-bios-update.service \
${D}${systemd_system_unitdir}
}
RDEPENDS:${PN}:append = " libsystemd mori-fw"
RPROVIDES:${PN}:append = " virtual/bios-update"
FILES:${PN}:append = " ${datadir}/phosphor-ipmi-flash/config-bios.json"
@@ -0,0 +1,19 @@
[{
"blob": "/flash/bios",
"handler": {
"type": "file",
"path": "/run/initramfs/bios-image"
},
"actions": {
"preparation": {
"type": "skip"
},
"verification": {
"type": "skip"
},
"update": {
"type": "systemd",
"unit": "phosphor-ipmi-flash-bios-update.service"
}
}
}]
@@ -0,0 +1,6 @@
[Unit]
Description=Phosphor-ipmi-flash update BIOS firmware service
[Service]
ExecStart=mori-fw.sh bios /run/initramfs/bios-image
Type=oneshot
@@ -0,0 +1,21 @@
SUMMARY = "Phosphor OpenBMC Mori BMC Firmware Upgrade Command"
DESCRIPTION = "Phosphor OpenBMC Mori BMC Firmware Upgrade Comman Daemon"
LICENSE = "Apache-2.0"
LIC_FILES_CHKSUM = "file://${COREBASE}/meta/files/common-licenses/Apache-2.0;md5=89aea4e17d99a7cacdbeed46a0096b10"
DEPENDS:append = " phosphor-ipmi-flash"
PROVIDES:append = " virtual/bmc-update"
PR = "r1"
SRC_URI = "file://config-bmc.json"
do_install () {
install -d ${D}${datadir}/phosphor-ipmi-flash
install -m 0644 ${WORKDIR}/config-bmc.json \
${D}${datadir}/phosphor-ipmi-flash
}
RDEPENDS:${PN}:append = " mori-fw"
RPROVIDES:${PN}:append = " virtual/bmc-update"
FILES:${PN}:append = " ${datadir}/phosphor-ipmi-flash/config-bmc.json"
@@ -0,0 +1,20 @@
[{
"blob": "/flash/image",
"handler": {
"type": "file",
"path": "/run/initramfs/image-bmc"
},
"actions": {
"preparation": {
"type": "skip"
},
"verification": {
"type": "skip"
},
"update": {
"type": "systemd",
"unit": "reboot.target",
"mode": "replace-irreversibly"
}
}
}]
@@ -0,0 +1,43 @@
SUMMARY = "Phosphor OpenBMC Mori CPLD Firmware Upgrade Command"
DESCRIPTION = "Phosphor OpenBMC Mori CPLD Firmware Upgrade Comman Daemon"
LICENSE = "Apache-2.0"
LIC_FILES_CHKSUM = "file://${COREBASE}/meta/files/common-licenses/Apache-2.0;md5=89aea4e17d99a7cacdbeed46a0096b10"
DEPENDS:append = " systemd phosphor-ipmi-flash"
PROVIDES:append = " virtual/cpld-update"
PR = "r1"
SRC_URI = " \
file://phosphor-ipmi-flash-bmccpld-update.service \
file://phosphor-ipmi-flash-mbcpld-update.service \
file://config-bmccpld.json \
file://config-mbcpld.json \
"
SYSTEMD_SERVICE:${PN} = " \
phosphor-ipmi-flash-bmccpld-update.service \
phosphor-ipmi-flash-mbcpld-update.service \
"
inherit systemd obmc-phosphor-systemd
do_install () {
install -d ${D}${datadir}/phosphor-ipmi-flash
install -m 0644 ${WORKDIR}/config-bmccpld.json \
${D}${datadir}/phosphor-ipmi-flash
install -m 0644 ${WORKDIR}/config-mbcpld.json \
${D}${datadir}/phosphor-ipmi-flash
install -d ${D}${systemd_system_unitdir}
install -m 0644 ${WORKDIR}/phosphor-ipmi-flash-bmccpld-update.service \
${D}${systemd_system_unitdir}
install -m 0644 ${WORKDIR}/phosphor-ipmi-flash-mbcpld-update.service \
${D}${systemd_system_unitdir}
}
RDEPENDS:${PN}:append = " libsystemd mori-fw"
RPROVIDES:${PN}:append = " virtual/cpld-update"
FILES:${PN}:append = " \
${datadir}/phosphor-ipmi-flash/config-bmccpld.json \
${datadir}/phosphor-ipmi-flash/config-mbcpld.json \
"
@@ -0,0 +1,19 @@
[{
"blob": "/flash/bmccpld",
"handler": {
"type": "file",
"path": "/run/initramfs/bmc-cpld.svf"
},
"actions": {
"preparation": {
"type": "skip"
},
"verification": {
"type": "skip"
},
"update": {
"type": "systemd",
"unit": "phosphor-ipmi-flash-bmccpld-update.service"
}
}
}]
@@ -0,0 +1,20 @@
[{
"blob": "/flash/mbcpld",
"handler": {
"type": "file",
"path": "/run/initramfs/mb-cpld.svf"
},
"actions": {
"preparation": {
"type": "skip"
},
"verification": {
"type": "skip"
},
"update": {
"type": "systemd",
"unit": "phosphor-ipmi-flash-mbcpld-update.service"
}
}
}]
@@ -0,0 +1,9 @@
[Unit]
Description=Phosphor-ipmi-flash update BMC CPLD firmware service
[Service]
ExecStart=mori-fw.sh bmccpld /run/initramfs/bmc-cpld.svf
Type=oneshot
[Install]
WantedBy=phosphor-ipmi-flash-bmccpld-update.target
@@ -0,0 +1,9 @@
[Unit]
Description=Phosphor-ipmi-flash update MB CPLD firmware service
[Service]
ExecStart=mori-fw.sh mbcpld /run/initramfs/mb-cpld.svf
Type=oneshot
[Install]
WantedBy=phosphor-ipmi-flash-mbcpld-update.target
@@ -0,0 +1,30 @@
SUMMARY = "Phosphor OpenBMC mori Firmware Upgrade Command"
DESCRIPTION = "Phosphor OpenBMC mori Firmware Upgrade Comman Daemon"
LICENSE = "Apache-2.0"
LIC_FILES_CHKSUM = "file://${COREBASE}/meta/files/common-licenses/Apache-2.0;md5=89aea4e17d99a7cacdbeed46a0096b10"
DEPENDS:append = " systemd phosphor-ipmi-flash"
PR = "r1"
SRC_URI = " \
file://mori-fw.sh \
file://mori-fw-ver.service \
file://mori-fw-ver.sh \
file://mori-lib.sh \
"
SYSTEMD_SERVICE:${PN} = "mori-fw-ver.service"
inherit systemd obmc-phosphor-systemd
do_install () {
install -d ${D}${sbindir}
install -d ${D}${libexecdir}/${PN}
install -m 0755 ${WORKDIR}/mori-fw.sh ${D}${sbindir}/mori-fw.sh
install -m 0755 ${WORKDIR}/mori-fw-ver.sh \
${D}${libexecdir}/${PN}/mori-fw-ver.sh
install -m 0755 ${WORKDIR}/mori-lib.sh ${D}${libexecdir}/${PN}/mori-lib.sh
install -d ${D}${systemd_system_unitdir}
install -m 0644 ${WORKDIR}/mori-fw-ver.service ${D}${systemd_system_unitdir}
}
RDEPENDS:${PN}:append = " libsystemd bash"
@@ -0,0 +1,12 @@
[Unit]
Description=Firmware Version Daemon
Wants=host-powerctrl.service
After=host-powerctrl.service
[Service]
RemainAfterExit=yes
Type=oneshot
ExecStart=/usr/libexec/mori-fw/mori-fw-ver.sh
[Install]
WantedBy=multi-user.target
@@ -0,0 +1,33 @@
#!/bin/bash
# Disable check for splitting
# shellcheck disable=SC2207
# Provide source directive to shellcheck.
# shellcheck source=meta-fii/meta-mori/recipes-mori/mori-fw-utility/mori-fw/mori-lib.sh
source /usr/libexec/mori-fw/mori-lib.sh
BMC_CPLD_VER_FILE="/run/cpld0.version"
MB_CPLD_VER_FILE="/run/cpld1.version"
ver=''
function fw_rev() {
case $1 in
cpldb)
rsp=($(i2cget -y -f -a "${I2C_BMC_CPLD[0]}" 0x"${I2C_BMC_CPLD[1]}" 0x00 i 5))
ver=$(printf '%d.%d.%d.%d' "${rsp[4]}" "${rsp[3]}" "${rsp[2]}" "${rsp[1]}")
;;
cpldm)
rsp=($(i2cget -y -f -a "${I2C_MB_CPLD[0]}" 0x"${I2C_MB_CPLD[1]}" 0x00 i 5))
ver=$(printf '%d.%d.%d.%d' "${rsp[4]}" "${rsp[3]}" "${rsp[2]}" "${rsp[1]}")
;;
*)
;;
esac
}
fw_rev cpldb
echo "BMC CPLD version : ${ver}"
echo "${ver}" > "${BMC_CPLD_VER_FILE}"
fw_rev cpldm
echo "MB CPLD version : ${ver}"
echo "${ver}" > "${MB_CPLD_VER_FILE}"
@@ -0,0 +1,184 @@
#!/bin/bash
# Provide source directive to shellcheck.
# shellcheck source=meta-fii/meta-mori/recipes-mori/mori-fw-utility/mori-fw/mori-lib.sh
# Disable check for globbing and word splitting within double quotes
# shellcheck disable=SC2086
source /usr/libexec/mori-fw/mori-lib.sh
function fwbios() {
ret=0
if [ ! -f "$1" ]; then
echo " Cannot find the" "$1" "image file"
return 1
fi
setup_bios_access
# write to the mtd device
BIOS_MTD=$(grep "hnor" /proc/mtd | sed -n 's/^\(.*\):.*/\1/p')
{
flock -x 200
echo "Flashing BIOS @/dev/${BIOS_MTD}"
if ! flashcp -v $1 /dev/${BIOS_MTD} ; then
echo "Flashing the bios failed " >&2
ret=1
fi
} 200>$RST_LOCK_FILE
cleanup_bios_access
return $ret
}
function fwbmccpld() {
ret=0
if [ ! -s "$1" ]; then
echo "Image file" "$1" "is empty or nonexistent, BMC CPLD update failed"
return 1
fi
# MB_JTAG_MUX 0:CPU 1:MB
# BMC_JTAG_MUX 0:GF/MB 1:BMC
set_gpio_ctrl MB_JTAG_MUX_SEL 0
set_gpio_ctrl BMC_JTAG_MUX_SEL 1
{
flock -x 200
# 1st condition checks if the svf file is valid
# 2nd condition checks flashing logs for flash errors
if ! mesg=$(loadsvf -d /dev/jtag0 -s $1 -m 0 2>&1) \
|| echo "$mesg" | grep -i -e error -e fail ; then
echo "$mesg" | grep -i -e error -e fail
echo "BMC CPLD update failed"
ret=1
else
echo "BMC CPLD update successful"
fi
} 200>$RST_LOCK_FILE
return $ret
}
function fwmbcpld() {
ret=0
if [ ! -s "$1" ]; then
echo "Image file" "$1" "is empty or nonexistent, MB CPLD update failed"
return 1
fi
# MB_JTAG_MUX 0:CPU 1:MB
# BMC_JTAG_MUX 0:GF/MB 1:BMC
set_gpio_ctrl MB_JTAG_MUX_SEL 1
set_gpio_ctrl BMC_JTAG_MUX_SEL 0
{
flock -x 200
# 1st condition checks if the svf file is valid
# 2nd condition checks flashing logs for flash errors
if ! mesg=$(loadsvf -d /dev/jtag0 -s $1 -m 0 2>&1) \
|| echo "$mesg" | grep -i -e error -e fail ; then
echo "MB CPLD update failed"
ret=1
else
echo "MB CPLD update successful"
fi
} 200>$RST_LOCK_FILE
set_gpio_ctrl MB_JTAG_MUX_SEL 0
echo "MB CPLD update successful"
return $ret
}
function fwbootstrap() {
# to flash the CPU EEPROM
#unbind bootstrap EEPROM
echo ${I2C_CPU_EEPROM[0]}-00${I2C_CPU_EEPROM[1]} > /sys/bus/i2c/drivers/at24/unbind
#switch access to BMC
set_gpio_ctrl CPU_EEPROM_SEL 0
if [ "$(bootstrap_flash -b ${I2C_CPU_EEPROM[0]} -s 0x${I2C_CPU_EEPROM[1]} -p -f $1)" -ne 0 ]; then
echo "CPU bootstrap EEPROM update failed" >&2
return 1
fi
wait
#bind bootstrap EEPROM
echo ${I2C_CPU_EEPROM[0]}-00${I2C_CPU_EEPROM[1]} > /sys/bus/i2c/drivers/at24/bind
#switch back access to CPU
set_gpio_ctrl CPU_EEPROM_SEL 1
return 0
}
function fwmb_pwr_seq(){
#$1 PS seq config file
ret=0
if [[ ! -e "$1" ]]; then
echo "The file $1 does not exist"
return 1
fi
echo "${I2C_MB_PWRSEQ[0]}"-00"${I2C_MB_PWRSEQ[1]}" > /sys/bus/i2c/drivers/adm1266/unbind
{
flock -x 200
#Parameters passed to adm1266_fw_fx to be used to flash PS
#1st I2C bus number of PS's
#2nd PS seq config file
if [ "$(mb_power_sequencer_flash ${I2C_MB_PWRSEQ[0]} $1)" -ne 0 ]; then
echo "The power seq flash failed" >&2
ret=1
else
echo "${I2C_MB_PWRSEQ[0]}"-00"${I2C_MB_PWRSEQ[1]}" > /sys/bus/i2c/drivers/adm1266/bind
fi
} 200>$RST_LOCK_FILE
return $ret
}
if [[ ! $(which flashcp) ]]; then
echo "flashcp utility not installed"
exit 1
fi
if [[ ! $(which loadsvf) ]]; then
echo "loadsvf utility not installed"
exit 1
fi
if [[ ! $(which mb_power_sequencer_flash) ]]; then
echo "mb_power_sequencer_flash utility not installed"
exit 1
fi
if [[ ! $(which bootstrap_flash) ]]; then
echo "bootstrap_flash utility not installed"
exit 1
fi
if [[ ! -e /dev/jtag0 ]]; then
echo "Jtag device driver not functional"
exit 1
fi
case $1 in
bios)
fwbios "$2"
;;
bmccpld)
fwbmccpld "$2"
;;
mbcpld)
fwmbcpld "$2"
;;
bootstrap)
fwbootstrap "$2"
;;
mbseq)
fwmb_pwr_seq "$2"
;;
*)
;;
esac
ret=$?
rm -f "$2"
exit $ret
@@ -0,0 +1,139 @@
#!/bin/bash
# Disable check for usage of the definitions within mori-lib.sh
#shellcheck disable=SC2034
# get_gpio_num
# Dynamically obtains GPIO number from chip base and I2C expanders
# line-name
function get_gpio_num() {
#shellcheck disable=SC2207
CHIP_PIN=($(gpiofind "$1" | awk '{print substr ($1, 9 ), $2 }'))
#shellcheck disable=SC2128
if [ -z "$CHIP_PIN" ]; then
echo "Could not find GPIO with name: $1"
return 1
fi
if [ "${CHIP_PIN[0]}" -gt 7 ]; then
BUS_ADDR=$(gpiodetect | grep gpiochip"${CHIP_PIN[0]}" | \
grep -o '\[.*]' | tr -d ' \[\]')
GPIO_BASE_DIR=$(cd /sys/bus/i2c/devices/"$BUS_ADDR"/gpio/ || \
exit; ls -1 -v)
# Check that there is a single gpiobank per i2c device
GPIO_BANKS=$(cd /sys/bus/i2c/devices/"$BUS_ADDR"/ || \
exit ; ls -1 -d -v gpiochip*)
# Determine which GPIO_BASE to use based on the place of the GPIO_BANK
# in comparision to GPIO_BANKS
# gpiochip# is set in reverse order of numbering for location of
# GPIO_BASE_DIR
count=$(echo "$GPIO_BANKS" | wc -w)
for X in ${GPIO_BANKS}
do
if [[ $(gpiofind "$1" | cut -d " " -f 1) == "$X" ]]; then
# Used to select the correct GPIO_BASE value
#shellcheck disable=SC2086
GPIO_BASE_DIR=("$(echo ${GPIO_BASE_DIR} | cut -d " " -f $count)")
break
fi
count=$((count-1))
done
tmp="/sys/bus/i2c/devices/$BUS_ADDR/gpio/${GPIO_BASE_DIR[0]}/base"
GPIO_BASE=$(cat "$tmp")
echo "$((GPIO_BASE+CHIP_PIN[1]))"
else
echo "$((CHIP_PIN[0]*32+CHIP_PIN[1]))"
fi
}
# set_gpio_ctrl
# line-name, high(1)/low(0)
function set_gpio_ctrl() {
#shellcheck disable=SC2046
gpioset $(gpiofind "$1")="$2"
}
# get_gpio_ctrl
# line-name
function get_gpio_ctrl() {
GPIO_NUM=$(get_gpio_num "$1")
echo "$GPIO_NUM" > /sys/class/gpio/export
# GPIOs added by drivers use different path for value most but not all
# drivers follow this trend
# Try reading like traditional GPIO, if fails, try reading in driver format
if ! cat /sys/class/gpio/gpio"$GPIO_NUM"/value 2> /dev/null ; then
cat /sys/class/gpio/"$1"/value
fi
echo "$GPIO_NUM" > /sys/class/gpio/unexport
}
function Does_File_Exist() {
local FILE=$1
if [[ ! -f "${FILE}" ]]; then
echo "${FILE} file does not exist" >&2
return 1
fi
}
function cleanup_bios_access() {
# Run only if setup_bios_access was previously ran
if Does_File_Exist /run/bios_access &> /dev/null ; then
# switch the SPI mux from BMC to Host
if [ -d "${KERNEL_SYSFS_FIU}/${KERNEL_FIU_ID}" ]; then
echo "${KERNEL_FIU_ID}" > "${KERNEL_SYSFS_FIU}"/unbind
fi
set_gpio_ctrl FM_BIOS_FLASH_SPI_MUX_R_SEL 0
# Indicate to host that BMC is finished accessing SPI
set_gpio_ctrl S0_BMC_SPI_NOR_ACCESS 0
rm /run/bios_access
fi
}
function setup_bios_access() {
# Run only if setup_bios_access was not previously ran without cleanup
if ! Does_File_Exist /run/bios_access &> /dev/null ; then
echo "BMC is accessing BIOS" > /run/bios_access
# rescan the spi bus
if [ -d "${KERNEL_SYSFS_FIU}/${KERNEL_FIU_ID}" ]; then
echo "${KERNEL_FIU_ID}" > "${KERNEL_SYSFS_FIU}"/unbind
usleep 100
fi
# Wait until the host is finished accessing the SPI
while [[ $(get_gpio_ctrl S0_SOC_SPI_NOR_ACCESS) == 1 ]]
do
sleep 1
done
# Indicate to host that BMC is accessing SPI
set_gpio_ctrl S0_BMC_SPI_NOR_ACCESS 1
# switch the SPI mux from Host to BMC
set_gpio_ctrl FM_BIOS_FLASH_SPI_MUX_R_SEL 1
echo "${KERNEL_FIU_ID}" > "${KERNEL_SYSFS_FIU}"/bind
fi
}
# Start definitions
# I2C Definitions
# The array is (<bus> <address>), where address is in hexadecimal.
I2C_BMC_CPLD=(13 76)
I2C_MB_CPLD=(0 76)
I2C_FANCTRL=(35 2c)
I2C_BMC_PWRSEQ=(48 59)
I2C_MB_PWRSEQ=(40 40)
I2C_CPU_EEPROM=(19 50)
# File Path Definition
# File path used to prevent hotswapping
RST_LOCK_FILE="/etc/FW_FLASH_ONGOING"
# Device name and driver path used for BIOS SPI
KERNEL_FIU_ID="c0000000.spi"
KERNEL_SYSFS_FIU="/sys/bus/platform/drivers/NPCM-FIU"
@@ -0,0 +1,25 @@
SUMMARY = "Phosphor OpenBMC Mori System Power Control Service"
DESCRIPTION = "Phosphor OpenBMC Mori System Power Control Daemon"
LICENSE = "Apache-2.0"
LIC_FILES_CHKSUM = "file://${COREBASE}/meta/files/common-licenses/Apache-2.0;md5=89aea4e17d99a7cacdbeed46a0096b10"
DEPENDS:append = " systemd"
PR = "r1"
SRC_URI = " \
file://init_once.sh \
file://host-powerctrl.service \
"
SYSTEMD_SERVICE:${PN} = "host-powerctrl.service"
inherit systemd obmc-phosphor-systemd
do_install () {
install -d ${D}${libexecdir}/${PN}
install -m 0755 ${WORKDIR}/init_once.sh ${D}${libexecdir}/${PN}
install -d ${D}${systemd_unitdir}/system/
install -m 0644 ${WORKDIR}/host-powerctrl.service \
${D}${systemd_unitdir}/system
}
RDEPENDS:${PN}:append = " libsystemd bash"
@@ -0,0 +1,14 @@
[Unit]
Description = Host Power Control Sequence
Wants=ssifbridge.service
After=ssifbridge.service
[Service]
Restart=no
RemainAfterExit=true
Type=oneshot
ExecStart=/usr/libexec/mori-boot/init_once.sh
StandardOutput=syslog
[Install]
WantedBy=sysinit.target
@@ -0,0 +1,27 @@
#!/bin/bash
# Provide source directive to shellcheck.
# shellcheck source=meta-fii/meta-mori/recipes-mori/mori-fw-utility/mori-fw/mori-lib.sh
source /usr/libexec/mori-fw/mori-lib.sh
function set_mux_default(){
# set all mux route to CPU before power on host
# BMC_CPU_DDR_I2C_SEL
set_gpio_ctrl CPU_DDR_SEL 1
# BMC_CPU_EEPROM_I2C_SEL
set_gpio_ctrl CPU_EEPROM_SEL 1
# BMC_CPU_PMBUS_SEL
set_gpio_ctrl CPU_VRD_SEL 1
}
set_mux_default
sleep 5
set_gpio_ctrl S0_BMC_OK 1
# Create /run/openbmc for system power files
if [[ ! -d "/run/openbmc" ]]; then
mkdir "/run/openbmc"
fi
echo "BMC initialization complete"
@@ -0,0 +1,14 @@
SUMMARY = "Phosphor OpenBMC Mori System Command"
DESCRIPTION = "Phosphor OpenBMC Mori System Command Daemon"
LICENSE = "Apache-2.0"
LIC_FILES_CHKSUM = "file://${COREBASE}/meta/files/common-licenses/Apache-2.0;md5=89aea4e17d99a7cacdbeed46a0096b10"
PR = "r1"
SRC_URI = "file://mori.sh"
do_install () {
install -d ${D}${sbindir}
install -m 0755 ${WORKDIR}/mori.sh ${D}${sbindir}/mori.sh
}
RDEPENDS:${PN}:append = " bash"
@@ -0,0 +1,333 @@
#!/bin/bash
# help information
# Provide source directive to shellcheck.
# shellcheck source=meta-fii/meta-mori/recipes-mori/mori-fw-utility/mori-fw/mori-lib.sh
source /usr/libexec/mori-fw/mori-lib.sh
function usage_rst() {
echo " mori rst [parameter]"
echo " system --> reset the host"
echo " btn --> trigger a power button event"
echo " shutdown --> send out shutdown signal to CPU"
echo " display --> "
}
function usage_led() {
echo " mori led 'attn'/'boot' [parameter]"
echo " on --> turn led on"
echo " off --> turn led off"
echo " toggle --> toggle led"
echo " status --> get status of led"
}
function usage_uart() {
echo " mori uart [parameter]"
echo " host --> show CPU console"
echo " mpro --> show Mpro console"
echo " swhost --> change to CPU console to ttyS1"
echo " swmpro --> change to CPU 0 Mpro console to ttyS3"
echo " swhosthr --> change CPU console to header"
echo " swmprohr --> change Mpro console to header"
echo " display --> "
}
function usage_rtc() {
echo " mori rtc [parameter]"
echo " lock --> disable host access to rtc"
echo " unlock --> enable host access to rtc"
echo " status --> get status of host accessibility to rtc"
}
function usage_gpio() {
echo " mori gpio [parameter]"
echo " get [GPIO_LINE_NAME] --> get the gpio value of GPIO_LINE_NAME"
echo " set [GPIO_LINE_NAME] [GPIO_VALUE] --> set the gpio of GPIO_LINE_NAME to the value of GPIO_VALUE"
}
function usage() {
echo " mori BMC console system utilities"
echo " mori [optional] [parameter]"
echo " rst --> reset target device"
echo " fw --> get version"
echo " uart --> control the uart mux"
echo " led --> control the leds"
echo " rtc --> control host access to rtc"
echo " gpio --> control the gpios"
}
function reset() {
case $1 in
system)
# S0 system reset
echo "System has been reset, host will start booting in a few minutes"
ipmitool chassis power reset
;;
btn)
# virtual power button on
set_gpio_ctrl POWER_OUT 0
sleep 1
set_gpio_ctrl POWER_OUT 1
;;
shutdown)
# request host shutdown
set_gpio_ctrl S0_SHD_REQ 0
sleep 3
set_gpio_ctrl S0_SHD_REQ 1
;;
forceOff)
# virtual power button off
set_gpio_ctrl POWER_OUT 0
sleep 6
set_gpio_ctrl POWER_OUT 1
;;
display)
echo "Virtual AC Reset: GPIO$(get_gpio_num HOTSWAP)" "State:$(get_gpio_ctrl HOTSWAP)"
echo "Virtual Power Button: GPIO$(get_gpio_num POWER_OUT)" "State:$(get_gpio_ctrl POWER_OUT)"
echo "S0 System Reset: GPIO$(get_gpio_num S0_SYSRESET)" "State:$(get_gpio_ctrl S0_SYSRESET)"
echo "S0 Shutdown Request: GPIO$(get_gpio_num S0_SHD_REQ)" "State:$(get_gpio_ctrl S0_SHD_REQ)"
;;
*)
usage_rst
;;
esac
}
function fw_rev() {
BMC_CPLD_VER_FILE="/run/cpld0.version"
MB_CPLD_VER_FILE="/run/cpld1.version"
cmd=$(cat ${BMC_CPLD_VER_FILE})
echo " BMC_CPLD: " "${cmd}"
cmd=$(cat ${MB_CPLD_VER_FILE})
echo " MB_CPLD: " "${cmd}"
# BMC Version
# Save VERSION_ID line in string "VERSION_ID=*-Major.Submajor.Minor.Subminor" and
# extract the substring after - sign "Major.Submajor.Minor.Subminor"
BMCVersion=$(awk '/VERSION_ID/' /etc/os-release | sed "s/.*-//g")
# BMCVersion="Major.Submajor.Minor"
echo " BMC: ${BMCVersion%.*}"
#BMC PWR Sequencer
i2cset -y -f -a "${I2C_BMC_PWRSEQ[0]}" 0x"${I2C_BMC_PWRSEQ[1]}" 0xfe 0x0000 w
cmd=$(i2cget -y -f -a "${I2C_BMC_PWRSEQ[0]}" 0x"${I2C_BMC_PWRSEQ[1]}" 0xfe i 2 | awk '{print substr($0,3)}')
echo " BMC PowerSequencer : ${cmd}"
#only display with smbios exists
if [[ -e /var/lib/smbios/smbios2 ]]; then
cmd=$(busctl get-property xyz.openbmc_project.Smbios.MDR_V2 \
/xyz/openbmc_project/inventory/system/chassis/motherboard/bios\
xyz.openbmc_project.Inventory.Decorator.Revision Version | awk '{print $2}')
echo " Bios: $cmd"
fi
if [[ ! $(which mb_power_sequencer_version) ]]; then
echo "mb_power_sequencer_version utility not installed"
return
fi
mb_power_sequencer_version "${I2C_MB_PWRSEQ[0]}" | grep REVISION
}
function uartmux() {
case $1 in
host)
if [ "$(tty)" == "/dev/ttyS0" ]; then
echo "Couldn't redirect to the host console within BMC local console"
else
echo "Entering Console use 'shift ~~..' to quit"
obmc-console-client -c /etc/obmc-console/server.ttyS1.conf
fi
;;
mpro)
if [ "$(tty)" == "/dev/ttyS0" ]; then
echo "Couldn't redirect to the Mpro console within BMC local console"
else
echo "Entering Console use 'shift ~~..' to quit"
obmc-console-client -c /etc/obmc-console/server.ttyS3.conf
fi
;;
swhost)
set_gpio_ctrl S0_UART0_BMC_SEL 1
;;
swmpro)
set_gpio_ctrl S0_UART1_BMC_SEL 1
;;
swhosthr)
set_gpio_ctrl S0_UART0_BMC_SEL 0
;;
swmprohr)
set_gpio_ctrl S0_UART1_BMC_SEL 0
;;
display)
if [ "$(get_gpio_ctrl S0_UART0_BMC_SEL)" -eq 1 ]; then
echo " CPU host to BMC console"
else
echo " CPU host to header"
fi
if [ "$(get_gpio_ctrl S0_UART1_BMC_SEL)" -eq 1 ]; then
echo " Mpro host to BMC console"
else
echo " Mpro host to header"
fi
;;
*)
usage_uart
;;
esac
}
function ledtoggle() {
case $1 in
boot)
cmd=$(get_gpio_ctrl SYS_BOOT_STATUS_LED)
case $2 in
on)
#turn on LED
set_gpio_ctrl SYS_BOOT_STATUS_LED 1
;;
off)
#turn off LED
set_gpio_ctrl SYS_BOOT_STATUS_LED 0
;;
toggle)
#toggle off LED
if [[ $cmd -eq 1 ]]; then
set_gpio_ctrl SYS_BOOT_STATUS_LED 0
fi
#toggle on LED
if [[ $cmd -eq 0 ]]; then
set_gpio_ctrl SYS_BOOT_STATUS_LED 1
fi
;;
status)
#displayLED status
if [[ $cmd -eq 1 ]]; then
echo "on"
else
echo "off"
fi
;;
*)
usage_led
;;
esac
;;
attn)
cmd=$(get_gpio_ctrl SYS_ERROR_LED)
case $2 in
on)
#turn on LED
set_gpio_ctrl SYS_ERROR_LED 1
;;
off)
#turn off LED
set_gpio_ctrl SYS_ERROR_LED 0
;;
toggle)
#toggle off LED
if [[ $cmd -eq 1 ]]; then
set_gpio_ctrl SYS_ERROR_LED 0
fi
#toggle on LED
if [[ $cmd -eq 0 ]]; then
set_gpio_ctrl SYS_ERROR_LED 1
fi
;;
status)
#displayLED status
if [[ $cmd -eq 1 ]]; then
echo "on"
else
echo "off"
fi
;;
*)
usage_led
;;
esac
;;
*)
usage_led
;;
esac
}
function usblist() {
for i in {5..9}
do
cmd=$(devmem 0xf083"${i}"154)
printf "udc%d : 0xF083%d154-" "${i}" "${i}"
echo "$cmd"
done
}
function rtcctrl() {
case $1 in
lock)
# Disable host access to rtc
set_gpio_ctrl S0_RTC_LOCK 1
;;
unlock)
# Enable host access to rtc
set_gpio_ctrl S0_RTC_LOCK 0
;;
status)
cmd=$(get_gpio_ctrl S0_RTC_LOCK)
if [[ $cmd -eq 1 ]]; then
echo "locked"
else
echo "unlocked"
fi
;;
*)
usage_rtc
;;
esac
}
function gpioctrl() {
case $1 in
get)
get_gpio_ctrl "$2"
;;
set)
set_gpio_ctrl "$2" "$3"
;;
*)
usage_gpio
;;
esac
}
case $1 in
rst)
reset "$2"
;;
fw)
fw_rev
;;
uart)
uartmux "$2"
;;
usb)
usblist
;;
led)
ledtoggle "$2" "$3"
;;
rtc)
rtcctrl "$2"
;;
gpio)
gpioctrl "$2" "$3" "$4"
;;
*)
usage
;;
esac