From 1b3d4dae5f41e70af385dfb0e284b4cece44d887 Mon Sep 17 00:00:00 2001 From: Hieu Huynh Date: Wed, 28 Jul 2021 08:06:42 +0000 Subject: meta-ampere: network: enable nic-ethtool The SpeedMbds of ethernet interface is implemented in getInterfaceInfo() from the phosphor-networkd repo. It is disabled by NIC_SUPPORTS_ETHTOOL conditional compilation. The default compile mode is to omit the getInterfaceInfo() which causes the SpeedMbps not set. This commit supports enable the NIC_SUPPORTS_ETHTOOL to report correct speed. Tested: 1.Get SpeedMbps via rest: $ curl -XGET --user root:0penBmc -H "Content-Type: application/json" \ -H "If-match: *" --insecure \ https://10.38.14.2/redfish/v1/Managers/bmc/EthernetInterfaces/eth1 \ grep | "SpeedMbps" 2.Get speed of eth1 interface on BMC console $ cat /sys/class/net/eth1/speed The value getting from openbmc#1 and openbmc#2 match together. Signed-off-by: Hieu Huynh Change-Id: I57047151fc4eea08c857b95c0770d89ba95f9bc7 --- .../meta-common/recipes-phosphor/network/phosphor-network_%.bbappend | 1 + 1 file changed, 1 insertion(+) create mode 100644 meta-ampere/meta-common/recipes-phosphor/network/phosphor-network_%.bbappend (limited to 'meta-ampere/meta-common') diff --git a/meta-ampere/meta-common/recipes-phosphor/network/phosphor-network_%.bbappend b/meta-ampere/meta-common/recipes-phosphor/network/phosphor-network_%.bbappend new file mode 100644 index 000000000..b2883fcaf --- /dev/null +++ b/meta-ampere/meta-common/recipes-phosphor/network/phosphor-network_%.bbappend @@ -0,0 +1 @@ +PACKAGECONFIG_append = " nic-ethtool" -- cgit v1.2.3 From 220ffaf1f2498b128808e05aea53190b20582593 Mon Sep 17 00:00:00 2001 From: "William A. Kennington III" Date: Thu, 29 Jul 2021 18:28:08 -0700 Subject: meta-ampere: phosphor-sel-logger: Use packageconfig This makes it possible for us to change out build specific settings. Change-Id: I862366d8efa97c4c3181b842662bf28dd5bec270 Signed-off-by: William A. Kennington III --- .../recipes-phosphor/sel-logger/phosphor-sel-logger_%.bbappend | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'meta-ampere/meta-common') diff --git a/meta-ampere/meta-common/recipes-phosphor/sel-logger/phosphor-sel-logger_%.bbappend b/meta-ampere/meta-common/recipes-phosphor/sel-logger/phosphor-sel-logger_%.bbappend index 4be8ddbd5..2f74fd2c3 100644 --- a/meta-ampere/meta-common/recipes-phosphor/sel-logger/phosphor-sel-logger_%.bbappend +++ b/meta-ampere/meta-common/recipes-phosphor/sel-logger/phosphor-sel-logger_%.bbappend @@ -1,2 +1 @@ -# Enable threshold monitoring -EXTRA_OECMAKE += "-DSEL_LOGGER_MONITOR_THRESHOLD_EVENTS=ON" +PACKAGECONFIG_append = " log-threshold" -- cgit v1.2.3 From 98f43bec14af073da25f53db2122fe3546f54095 Mon Sep 17 00:00:00 2001 From: ThuBaNguyen Date: Thu, 1 Jul 2021 22:29:49 +0700 Subject: meta-ampere: power control: refactor power soft/off functions The current ampere-hostctl package removes the power off/on services of phosphor-state-manager and uses Ampere services. This solution is not correct. Ampere platform should use power control functions of phosphor-state-manager. And only appends or overides the default services by Ampere's services if need. By default, to handle power soft action, phosphor-state-manager will trigger obmc-host-shutdown@0.target. This target then call xyz.openbmc_project.Ipmi.Internal.SoftPowerOff.service to request OS shutdown. When the host OS shutdown is already done, the target will trigger obmc-chassis-poweroff@0.target to turn off the chassis. The default xyz.openbmc_project.Ipmi.Internal.SoftPowerOff.service uses Ipmi inband to communicate with the host. It is different with Ampere Mt.Jade platform. We use the GPIO pin SHD_REQ to request shutdown the host OS. The host will trigger SHD_ACK when shutdown is done. So *.Ipmi.Internal.SoftPowerOff.service will be overide by Ampere service named ampere.*.Ipmi.Internal.SoftPowerOff.service. This service will trigger SHD_REQ pin and wait for SHD_ACK before start obmc-chassis-poweroff@0.target. This commit removes ampere-chassis-poweroff, ampere-host-shutdown serives which handle power off/soft actions and restore phosphor-state-manager's services. It also supports ampere.xyz.openbmc_project.Ipmi.Internal.SoftPowerOff.service which will overide xyz.openbmc_project.Ipmi.Internal.SoftPowerOff.service. Tested: 1. Create "power soft" actions use ipmitool, redfish and BMC web. 2. Make sure the power order will be shutdown the host then power of the chassis. 3. Create "power off" actions use ipmitool, redfish and BMC web. 4. Make sure the power action will be power off the chassis. Signed-off-by: ThuBaNguyen Change-Id: Ibc0dc8c62408e8282520c9b70e41ab75c10137f6 --- .../recipes-ac01/host/ampere-hostctrl.bb | 16 +----- .../ampere-chassis-poweroff.service | 11 ---- .../ampere-hostctrl/ampere-host-shutdown.service | 10 ---- .../recipes-ac01/host/files/ampere_power_util.sh | 65 +++++++++++++++++----- .../state/phosphor-state-manager_%.bbappend | 8 --- .../ampere-phosphor-softpoweroff | 5 ++ ...nbmc_project.Ipmi.Internal.SoftPowerOff.service | 13 +++++ .../ipmi/phosphor-ipmi-host_%.bbappend | 10 ++++ 8 files changed, 79 insertions(+), 59 deletions(-) delete mode 100644 meta-ampere/meta-common/recipes-ac01/host/ampere-hostctrl/ampere-chassis-poweroff.service delete mode 100644 meta-ampere/meta-common/recipes-ac01/host/ampere-hostctrl/ampere-host-shutdown.service create mode 100644 meta-ampere/meta-jade/recipes-phosphor/ipmi/phosphor-ipmi-host/ampere-phosphor-softpoweroff create mode 100644 meta-ampere/meta-jade/recipes-phosphor/ipmi/phosphor-ipmi-host/ampere.xyz.openbmc_project.Ipmi.Internal.SoftPowerOff.service (limited to 'meta-ampere/meta-common') diff --git a/meta-ampere/meta-common/recipes-ac01/host/ampere-hostctrl.bb b/meta-ampere/meta-common/recipes-ac01/host/ampere-hostctrl.bb index e7c3cc160..f8e295401 100644 --- a/meta-ampere/meta-common/recipes-ac01/host/ampere-hostctrl.bb +++ b/meta-ampere/meta-common/recipes-ac01/host/ampere-hostctrl.bb @@ -13,10 +13,9 @@ SYSTEMD_ENVIRONMENT_FILE_${PN} +="obmc/gpio/shutdown_ack obmc/gpio/reboot_ack" S = "${WORKDIR}" -SRC_URI = "file://ampere-host-shutdown.service \ +SRC_URI = " \ file://ampere-host-reset.service \ file://ampere_power_util.sh \ - file://ampere-chassis-poweroff.service \ file://ampere-chassis-poweron.service \ file://ampere-host-reset-ack.service \ file://ampere-host-force-reset.service \ @@ -28,21 +27,13 @@ RDEPENDS_${PN} = "bash virtual/obmc-gpio-monitor" SYSTEMD_PACKAGES = "${PN}" SYSTEMD_SERVICE_${PN} = " \ - ampere-host-shutdown.service \ ampere-host-reset.service \ - ampere-chassis-poweroff.service \ ampere-chassis-poweron.service \ ampere-host-reset-ack.service \ ampere-host-force-reset.service \ ampere-host-power-cycle.service \ " # host power control -# overwrite the host shutdown to graceful shutdown -HOST_SHUTDOWN_TMPL = "ampere-host-shutdown.service" -HOST_SHUTDOWN_TGTFMT = "obmc-host-shutdown@{0}.target" -HOST_SHUTDOWN_FMT = "../${HOST_SHUTDOWN_TMPL}:${HOST_SHUTDOWN_TGTFMT}.requires/${HOST_SHUTDOWN_TMPL}" -SYSTEMD_LINK_${PN} += "${@compose_list_zip(d, 'HOST_SHUTDOWN_FMT', 'OBMC_HOST_INSTANCES')}" - # Force the power cycle target to run the ampere power cycle HOST_REBOOT_SVC = "ampere-host-power-cycle.service" HOST_REBOOT_SVC_TGTFMT = "obmc-host-reboot@{0}.target" @@ -67,11 +58,6 @@ CHASSIS_POWERON_TGTFMT = "obmc-chassis-poweron@{0}.target" CHASSIS_POWERON_FMT = "../${CHASSIS_POWERON_SVC}:${CHASSIS_POWERON_TGTFMT}.requires/${CHASSIS_POWERON_SVC}" SYSTEMD_LINK_${PN} += "${@compose_list_zip(d, 'CHASSIS_POWERON_FMT', 'OBMC_CHASSIS_INSTANCES')}" -CHASSIS_POWEROFF_SVC = "ampere-chassis-poweroff.service" -CHASSIS_POWEROFF_TGTFMT = "obmc-chassis-poweroff@{0}.target" -CHASSIS_POWEROFF_FMT = "../${CHASSIS_POWEROFF_SVC}:${CHASSIS_POWEROFF_TGTFMT}.requires/${CHASSIS_POWEROFF_SVC}" -SYSTEMD_LINK_${PN} += "${@compose_list_zip(d, 'CHASSIS_POWEROFF_FMT', 'OBMC_CHASSIS_INSTANCES')}" - TMPL = "phosphor-gpio-monitor@.service" INSTFMT = "phosphor-gpio-monitor@{0}.service" TGT = "multi-user.target" diff --git a/meta-ampere/meta-common/recipes-ac01/host/ampere-hostctrl/ampere-chassis-poweroff.service b/meta-ampere/meta-common/recipes-ac01/host/ampere-hostctrl/ampere-chassis-poweroff.service deleted file mode 100644 index b0a1af785..000000000 --- a/meta-ampere/meta-common/recipes-ac01/host/ampere-hostctrl/ampere-chassis-poweroff.service +++ /dev/null @@ -1,11 +0,0 @@ -[Unit] -Description=Ampere Computing LLC Power OFF Chassis -Requires=op-wait-power-off@%i.service -Before=op-wait-power-off@%i.service -Conflicts=obmc-chassis-poweron@0.target - -[Service] -RemainAfterExit=no -Type=oneshot -ExecStart=/usr/bin/env ampere_power_util.sh mb off -SyslogIdentifier=ampere_power_util.sh diff --git a/meta-ampere/meta-common/recipes-ac01/host/ampere-hostctrl/ampere-host-shutdown.service b/meta-ampere/meta-common/recipes-ac01/host/ampere-hostctrl/ampere-host-shutdown.service deleted file mode 100644 index be4d45260..000000000 --- a/meta-ampere/meta-common/recipes-ac01/host/ampere-hostctrl/ampere-host-shutdown.service +++ /dev/null @@ -1,10 +0,0 @@ -[Unit] -Description=Ampere Computing LLC graceful shutdown host -Conflicts=obmc-host-start@0.target -OnFailure=obmc-chassis-poweroff@0.target - -[Service] -RemainAfterExit=no -Type=oneshot -ExecStart=/usr/bin/env ampere_power_util.sh mb graceful_shutdown -SyslogIdentifier=ampere_power_util.sh diff --git a/meta-ampere/meta-common/recipes-ac01/host/files/ampere_power_util.sh b/meta-ampere/meta-common/recipes-ac01/host/files/ampere_power_util.sh index 8bab9a370..9a8b06c6b 100644 --- a/meta-ampere/meta-common/recipes-ac01/host/files/ampere_power_util.sh +++ b/meta-ampere/meta-common/recipes-ac01/host/files/ampere_power_util.sh @@ -1,12 +1,11 @@ #!/bin/bash # Usage of this utility function usage() { - echo "usage: power-util mb [on|off|status|cycle|reset|graceful_shutdown|graceful_reset|force_reset]"; + echo "usage: power-util mb [on|status|cycle|reset|graceful_reset|force_reset|soft_off]"; } power_off() { - echo "Shutting down Server $2" - 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 + echo "power_off" } power_on() { @@ -28,6 +27,19 @@ power_reset() { 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.Reboot } +timestamp() { + date +"%s" # current time +} + +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" + fi +} + graceful_shutdown() { if [ -f "/run/openbmc/host@0-request" ]; then echo "shutdown host immediately" @@ -41,6 +53,33 @@ graceful_shutdown() { fi } +soft_off() { + # Trigger shutdown_req + touch /run/openbmc/host@0-softpoweroff + gpioset -l 0 49=1 + sleep 1s + gpioset -l 0 49=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() { echo "Triggering sysreset pin" gpioset -l 0 91=1 @@ -65,16 +104,6 @@ if [ $2 = "on" ]; then if [ $(power_status) == "off" ]; then power_on fi -elif [ $2 = "off" ]; then - if [ $(power_status) == "on" ]; then - power_off - fi - # If any request of graceful reset, need to power on - if [ -f "/run/openbmc/host@0-graceful-reset" ]; then - sleep 20s - power_on - rm -f "/run/openbmc/host@0-graceful-reset" - fi elif [ $2 == "cycle" ]; then if [ $(power_status) == "on" ]; then echo "Powering off server" @@ -90,8 +119,6 @@ elif [ $2 == "reset" ]; then else echo "ERROR: Server not powered on" fi -elif [[ $2 == "graceful_shutdown" ]]; then - graceful_shutdown elif [ $2 == "graceful_reset" ]; then mkdir -p "/run/openbmc/" touch "/run/openbmc/host@0-graceful-reset" @@ -101,6 +128,14 @@ 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; diff --git a/meta-ampere/meta-common/recipes-phosphor/state/phosphor-state-manager_%.bbappend b/meta-ampere/meta-common/recipes-phosphor/state/phosphor-state-manager_%.bbappend index d54407ba3..78683f841 100644 --- a/meta-ampere/meta-common/recipes-phosphor/state/phosphor-state-manager_%.bbappend +++ b/meta-ampere/meta-common/recipes-phosphor/state/phosphor-state-manager_%.bbappend @@ -4,15 +4,7 @@ DEPS_CFG = "resetreason.conf" DEPS_TGT = "phosphor-discover-system-state@.service" SYSTEMD_OVERRIDE_${PN}-discover_append = "${DEPS_CFG}:${DEPS_TGT}.d/${DEPS_CFG}" -# We don't want the obmc-host-shutdown (softoff) to require -# obmc-chassis-poweroff. obmc-chassis-poweroff will be activated once -# the Shutdown ACK pin is toggled (monitored by phosphor-gpio-monitor) -HOST_STOP_FMT = "" -HOST_REBOOT_FMT = "" - pkg_postinst_${PN}-obmc-targets_append() { - rm "$D$systemd_system_unitdir/obmc-host-shutdown@0.target.requires/obmc-chassis-poweroff@0.target" - rm "$D$systemd_system_unitdir/obmc-host-warm-reboot@0.target.requires/xyz.openbmc_project.Ipmi.Internal.SoftPowerOff.service" rm "$D$systemd_system_unitdir/obmc-host-warm-reboot@0.target.requires/obmc-host-force-warm-reboot@0.target" diff --git a/meta-ampere/meta-jade/recipes-phosphor/ipmi/phosphor-ipmi-host/ampere-phosphor-softpoweroff b/meta-ampere/meta-jade/recipes-phosphor/ipmi/phosphor-ipmi-host/ampere-phosphor-softpoweroff new file mode 100644 index 000000000..214aeed7a --- /dev/null +++ b/meta-ampere/meta-jade/recipes-phosphor/ipmi/phosphor-ipmi-host/ampere-phosphor-softpoweroff @@ -0,0 +1,5 @@ +#!/bin/bash +# Usage of this utility +echo "Trigger soft off the host." +/usr/sbin/ampere_power_util.sh mb soft_off +exit $?; diff --git a/meta-ampere/meta-jade/recipes-phosphor/ipmi/phosphor-ipmi-host/ampere.xyz.openbmc_project.Ipmi.Internal.SoftPowerOff.service b/meta-ampere/meta-jade/recipes-phosphor/ipmi/phosphor-ipmi-host/ampere.xyz.openbmc_project.Ipmi.Internal.SoftPowerOff.service new file mode 100644 index 000000000..01b31b1b3 --- /dev/null +++ b/meta-ampere/meta-jade/recipes-phosphor/ipmi/phosphor-ipmi-host/ampere.xyz.openbmc_project.Ipmi.Internal.SoftPowerOff.service @@ -0,0 +1,13 @@ +[Unit] +Description=Ampere Soft power off of the host +Wants=obmc-host-stop-pre@0.target +Before=obmc-host-stop-pre@0.target +Conflicts=obmc-host-start@0.target +ConditionPathExists=!/run/openbmc/host@0-request +ConditionPathExists=!/lib/systemd/system/pldmSoftPowerOff.service + +[Service] +Restart=no +ExecStart=/usr/bin/env phosphor-softpoweroff +SyslogIdentifier=phosphor-softpoweroff +Type=oneshot diff --git a/meta-ampere/meta-jade/recipes-phosphor/ipmi/phosphor-ipmi-host_%.bbappend b/meta-ampere/meta-jade/recipes-phosphor/ipmi/phosphor-ipmi-host_%.bbappend index c0bcbdd3a..b8ea8d8d5 100644 --- a/meta-ampere/meta-jade/recipes-phosphor/ipmi/phosphor-ipmi-host_%.bbappend +++ b/meta-ampere/meta-jade/recipes-phosphor/ipmi/phosphor-ipmi-host_%.bbappend @@ -3,13 +3,23 @@ FILESEXTRAPATHS_append_mtjade := "${THISDIR}/${PN}:" DEPENDS_append_mtjade = " mtjade-yaml-config" RRECOMMENDS_${PN} += "ipmitool" +RDEPENDS_${PN} += "bash" + +SRC_URI += " \ + file://ampere-phosphor-softpoweroff \ + file://ampere.xyz.openbmc_project.Ipmi.Internal.SoftPowerOff.service \ + " EXTRA_OECONF_mtjade = " \ SENSOR_YAML_GEN=${STAGING_DIR_HOST}${datadir}/mtjade-yaml-config/ipmi-sensors-${MACHINE}.yaml \ FRU_YAML_GEN=${STAGING_DIR_HOST}${datadir}/mtjade-yaml-config/ipmi-fru-read.yaml \ " +AMPERE_SOFTPOWEROFF_TMPL = "ampere.xyz.openbmc_project.Ipmi.Internal.SoftPowerOff.service" + do_install_append_mtjade(){ install -d ${D}${includedir}/phosphor-ipmi-host install -m 0644 -D ${S}/selutility.hpp ${D}${includedir}/phosphor-ipmi-host + install -m 0755 ${WORKDIR}/ampere-phosphor-softpoweroff ${D}/${bindir}/phosphor-softpoweroff + install -m 0644 ${WORKDIR}/${AMPERE_SOFTPOWEROFF_TMPL} ${D}${systemd_unitdir}/system/xyz.openbmc_project.Ipmi.Internal.SoftPowerOff.service } -- cgit v1.2.3 From 509991d6a5f34772788ca6d8401c19109e6280a6 Mon Sep 17 00:00:00 2001 From: "Thang Q. Nguyen" Date: Tue, 20 Jul 2021 15:48:50 +0700 Subject: meta-ampere: mtjade: flash UEFI firmware at 4MB offset UEFI firmware for Ampere Altra-based platform starts at offset 0x400000 but currently the firmware image is flashed start at offset 0. This makes the Host fail to boot. This commit supports offset option for the mtd-util's flashcp utility and update the script to flash UEFI firmware starting at offset 0x400000. Tested: 1. Turn on the Host. 2. Flash UEFI firmware. Wait for the flash complete and check if Host can boot successfully. 4. Turn off the Host. 5. Flash UEFI firmware. Wait for the flash complete. 6. Turn on the Host and check if Host can boot successfully. Signed-off-by: Tung Nguyen Signed-off-by: Thang Q. Nguyen Change-Id: I0d48bfd0a7b7350b46a98bf10fe4de3887f09f02 --- .../0001-flashcp-support-offset-option.patch | 143 +++++++++++++++++++++ .../recipes-devtools/mtd/mtd-utils_%.bbappend | 3 + meta-ampere/meta-jade/conf/machine/mtjade.conf | 4 + .../flash/ampere-flash-utils/ampere_flash_bios.sh | 20 +-- 4 files changed, 157 insertions(+), 13 deletions(-) create mode 100644 meta-ampere/meta-common/recipes-devtools/mtd/mtd-utils/0001-flashcp-support-offset-option.patch create mode 100644 meta-ampere/meta-common/recipes-devtools/mtd/mtd-utils_%.bbappend (limited to 'meta-ampere/meta-common') diff --git a/meta-ampere/meta-common/recipes-devtools/mtd/mtd-utils/0001-flashcp-support-offset-option.patch b/meta-ampere/meta-common/recipes-devtools/mtd/mtd-utils/0001-flashcp-support-offset-option.patch new file mode 100644 index 000000000..174a1cd6d --- /dev/null +++ b/meta-ampere/meta-common/recipes-devtools/mtd/mtd-utils/0001-flashcp-support-offset-option.patch @@ -0,0 +1,143 @@ +From e29268bb252b4eec5830816912817a2650b04ee9 Mon Sep 17 00:00:00 2001 +From: Tung Nguyen +Date: Tue, 20 Jul 2021 15:32:32 +0700 +Subject: [PATCH] flashcp support offset option + +The flashcp command from mtd-utils just support to flash from offset 0. +Add offset option to specify the start offset so that firmware can be +flashed correctly + +Signed-off-by: Tung Nguyen + +%% original patch: 0001-support-flash-offset.patch +--- + misc-utils/flashcp.c | 50 +++++++++++++++++++++++++++++++++++++++++--- + 1 file changed, 47 insertions(+), 3 deletions(-) + +diff --git a/misc-utils/flashcp.c b/misc-utils/flashcp.c +index d7b0a59..d1ef79c 100644 +--- a/misc-utils/flashcp.c ++++ b/misc-utils/flashcp.c +@@ -90,7 +90,7 @@ static NORETURN void showusage(bool error) + "\n" + "Flash Copy - Written by Abraham van der Merwe \n" + "\n" +- "usage: %1$s [ -v | --verbose | -A | --erase-all ] \n" ++ "usage: %1$s [ -v | --verbose | -A | --erase-all ] \n" + " %1$s -h | --help\n" + " %1$s -V | --version\n" + "\n" +@@ -100,6 +100,7 @@ static NORETURN void showusage(bool error) + " -V | --version Show version information and exit\n" + " File which you want to copy to flash\n" + " Flash device to write to (e.g. /dev/mtd0, /dev/mtd1, etc.)\n" ++ " The start offset. Optional, default: 0\n" + "\n", + PROGRAM_NAME); + +@@ -154,6 +155,16 @@ static void safe_rewind (int fd,const char *filename) + } + } + ++static int safe_rewind_offset(int fd, const char *filename, off_t offset) ++{ ++ if (lseek(fd, offset, SEEK_SET) < 0) { ++ log_printf(LOG_ERROR, "While seeking to start of %s: %m\n", filename); ++ return EXIT_FAILURE; ++ } ++ ++ return EXIT_SUCCESS; ++} ++ + /******************************************************************************/ + + static int dev_fd = -1,fil_fd = -1; +@@ -167,6 +178,8 @@ static void cleanup (void) + int main (int argc,char *argv[]) + { + const char *filename = NULL,*device = NULL; ++ off_t offset; ++ + int i,flags = FLAG_NONE; + ssize_t result; + size_t size,written; +@@ -218,6 +231,20 @@ int main (int argc,char *argv[]) + showusage(true); + } + } ++ ++ if (optind + 3 == argc) { ++ flags |= FLAG_FILENAME; ++ filename = argv[optind]; ++ DEBUG("Got filename: %s\n", filename); ++ ++ flags |= FLAG_DEVICE; ++ device = argv[optind + 1]; ++ DEBUG("Got device: %s\n", device); ++ ++ offset = strtoul(argv[optind + 2], NULL, 16); ++ DEBUG("Got offset: 0x%x\n", offset); ++ } ++ + if (optind+2 == argc) { + flags |= FLAG_FILENAME; + filename = argv[optind]; +@@ -226,6 +253,8 @@ int main (int argc,char *argv[]) + flags |= FLAG_DEVICE; + device = argv[optind+1]; + DEBUG("Got device: %s\n",device); ++ ++ offset = 0; + } + + if (flags & FLAG_HELP || device == NULL) +@@ -257,6 +286,12 @@ int main (int argc,char *argv[]) + exit (EXIT_FAILURE); + } + ++ /* does offset is out of the mtd */ ++ if (offset > mtd.size) { ++ log_printf(LOG_ERROR, "%s offset won't fit into %s!\n", offset, device); ++ exit(EXIT_FAILURE); ++ } ++ + /***************************************************** + * erase enough blocks so that we can write the file * + *****************************************************/ +@@ -271,6 +306,8 @@ int main (int argc,char *argv[]) + } + else + { ++ /* Erase from the offset */ ++ erase.start = offset; + erase.length = (filestat.st_size + mtd.erasesize - 1) / mtd.erasesize; + erase.length *= mtd.erasesize; + } +@@ -317,6 +354,12 @@ int main (int argc,char *argv[]) + size = filestat.st_size; + i = BUFSIZE; + written = 0; ++ ++ /* if offset is greater than 0 */ ++ if (offset) ++ if (safe_rewind_offset(dev_fd, device, offset) != EXIT_SUCCESS) ++ return EXIT_FAILURE; ++ + while (size) + { + if (size < BUFSIZE) i = size; +@@ -361,8 +404,9 @@ int main (int argc,char *argv[]) + * verify that flash == file data * + **********************************/ + +- safe_rewind (fil_fd,filename); +- safe_rewind (dev_fd,device); ++ safe_rewind(fil_fd, filename); ++ safe_rewind_offset(dev_fd, device, offset); ++ + size = filestat.st_size; + i = BUFSIZE; + written = 0; +-- +2.17.1 + diff --git a/meta-ampere/meta-common/recipes-devtools/mtd/mtd-utils_%.bbappend b/meta-ampere/meta-common/recipes-devtools/mtd/mtd-utils_%.bbappend new file mode 100644 index 000000000..08aa3ce69 --- /dev/null +++ b/meta-ampere/meta-common/recipes-devtools/mtd/mtd-utils_%.bbappend @@ -0,0 +1,3 @@ +FILESEXTRAPATHS_prepend := "${THISDIR}/${PN}:" + +SRC_URI += "file://0001-flashcp-support-offset-option.patch " diff --git a/meta-ampere/meta-jade/conf/machine/mtjade.conf b/meta-ampere/meta-jade/conf/machine/mtjade.conf index 171a023f4..e749af6de 100644 --- a/meta-ampere/meta-jade/conf/machine/mtjade.conf +++ b/meta-ampere/meta-jade/conf/machine/mtjade.conf @@ -15,6 +15,10 @@ FLASH_RWFS_OFFSET = "43008" OBMC_POWER_SUPPLY_INSTANCES = "0 1" +IMAGE_INSTALL += " \ + mtd-utils \ + " + OBMC_MACHINE_FEATURES += "\ obmc-phosphor-chassis-mgmt \ obmc-phosphor-flash-mgmt \ diff --git a/meta-ampere/meta-jade/recipes-ampere/flash/ampere-flash-utils/ampere_flash_bios.sh b/meta-ampere/meta-jade/recipes-ampere/flash/ampere-flash-utils/ampere_flash_bios.sh index 876671c1b..7a9ace30e 100755 --- a/meta-ampere/meta-jade/recipes-ampere/flash/ampere-flash-utils/ampere_flash_bios.sh +++ b/meta-ampere/meta-jade/recipes-ampere/flash/ampere-flash-utils/ampere_flash_bios.sh @@ -15,6 +15,8 @@ # limitations under the License. do_flash () { + OFFSET=$1 + # Check the PNOR partition available HOST_MTD=$(cat /proc/mtd | grep "pnor" | sed -n 's/^\(.*\):.*/\1/p') if [ -z "$HOST_MTD" ]; @@ -30,18 +32,10 @@ do_flash () { echo "Fail to probe Host SPI-NOR device" exit 1 fi - - echo "--- Flashing firmware to @/dev/$HOST_MTD" - flash_eraseall /dev/$HOST_MTD - flashcp -v $IMAGE /dev/$HOST_MTD - - echo "--- Unbind the ASpeed SMC driver" - echo 1e630000.spi > /sys/bus/platform/drivers/aspeed-smc/unbind - else - echo "--- Flashing firmware to @/dev/$HOST_MTD" - flash_eraseall /dev/$HOST_MTD - flashcp -v $IMAGE /dev/$HOST_MTD fi + + echo "--- Flashing firmware to @/dev/$HOST_MTD offset=$OFFSET" + flashcp -v $IMAGE /dev/$HOST_MTD $OFFSET } @@ -84,7 +78,7 @@ if [[ $? -ne 0 ]]; then fi # Flash the firmware -do_flash +do_flash 0x400000 # Switch the host SPI bus to HOST." echo "--- Switch the host SPI bus to HOST." @@ -99,5 +93,5 @@ if [ "$chassisstate" == 'On' ]; then sleep 5 echo "Turn on the Host" - obmcutil chassison + obmcutil poweron fi -- cgit v1.2.3 From 2f952142e9ed8b436a0e702a0f46ac88842dd51e Mon Sep 17 00:00:00 2001 From: ThuBaNguyen Date: Mon, 5 Jul 2021 13:32:26 +0700 Subject: meta-ampere: power control: refactor host power control Refactor the Mt.Jade Host power control operations to support Altra CPU following the Altra SoC BMC Interface specification which still satisfying the OpenBMC power control framework. Tested: check the below cases and ensure Host state report correctly: 1. Run "reboot" from Host Linux. Check the Host is graceful shutdown, then SYS_RESET is asserted and the Host is booted. 2. Run "shutdown" from Host Linux. Check the Host is graceful shutdown then the chassis power is turned OFF. 3. Run "ipmitool chassis power soft". Check the Host is graceful shutdown 4. Execute Redfish GracefulShutdown. Check the Host is graceful shutdown then the chassis power is turned OFF. 5. Execute Redfish GracefulRestart. Check the Host is graceful shutdown then turned ON. 6. Check other IPMI chassis power and Redfish Reset actions work. Signed-off-by: ThuBaNguyen Change-Id: I3a9716f37d7e80bdc1a1d0422e561c8fc51ad040 --- .../recipes-ac01/host/ampere-hostctrl.bb | 34 ++------- .../ampere-hostctrl/ampere-chassis-poweron.service | 9 --- .../ampere-host-force-reset.service | 11 --- .../ampere-host-force-reset@.service | 14 ++++ .../ampere-host-power-cycle.service | 10 --- .../ampere-hostctrl/ampere-host-reset-ack.service | 10 --- .../host/ampere-hostctrl/ampere-host-reset.service | 9 --- .../ampere-host-shutdown-ack@.service | 8 +++ .../recipes-ac01/host/files/ampere_power_util.sh | 80 +++++++++++----------- .../recipes-ac01/host/files/obmc/gpio/reboot_ack | 2 +- .../recipes-ac01/host/files/obmc/gpio/shutdown_ack | 2 +- .../state/phosphor-state-manager_%.bbappend | 11 --- 12 files changed, 69 insertions(+), 131 deletions(-) delete mode 100644 meta-ampere/meta-common/recipes-ac01/host/ampere-hostctrl/ampere-chassis-poweron.service delete mode 100644 meta-ampere/meta-common/recipes-ac01/host/ampere-hostctrl/ampere-host-force-reset.service create mode 100644 meta-ampere/meta-common/recipes-ac01/host/ampere-hostctrl/ampere-host-force-reset@.service delete mode 100644 meta-ampere/meta-common/recipes-ac01/host/ampere-hostctrl/ampere-host-power-cycle.service delete mode 100644 meta-ampere/meta-common/recipes-ac01/host/ampere-hostctrl/ampere-host-reset-ack.service delete mode 100644 meta-ampere/meta-common/recipes-ac01/host/ampere-hostctrl/ampere-host-reset.service create mode 100644 meta-ampere/meta-common/recipes-ac01/host/ampere-hostctrl/ampere-host-shutdown-ack@.service (limited to 'meta-ampere/meta-common') diff --git a/meta-ampere/meta-common/recipes-ac01/host/ampere-hostctrl.bb b/meta-ampere/meta-common/recipes-ac01/host/ampere-hostctrl.bb index f8e295401..4a44d1b2f 100644 --- a/meta-ampere/meta-common/recipes-ac01/host/ampere-hostctrl.bb +++ b/meta-ampere/meta-common/recipes-ac01/host/ampere-hostctrl.bb @@ -14,12 +14,9 @@ SYSTEMD_ENVIRONMENT_FILE_${PN} +="obmc/gpio/shutdown_ack obmc/gpio/reboot_ack" S = "${WORKDIR}" SRC_URI = " \ - file://ampere-host-reset.service \ file://ampere_power_util.sh \ - file://ampere-chassis-poweron.service \ - file://ampere-host-reset-ack.service \ - file://ampere-host-force-reset.service \ - file://ampere-host-power-cycle.service \ + file://ampere-host-force-reset@.service \ + file://ampere-host-shutdown-ack@.service \ " DEPENDS = "systemd virtual/obmc-gpio-monitor" @@ -27,37 +24,16 @@ RDEPENDS_${PN} = "bash virtual/obmc-gpio-monitor" SYSTEMD_PACKAGES = "${PN}" SYSTEMD_SERVICE_${PN} = " \ - ampere-host-reset.service \ - ampere-chassis-poweron.service \ - ampere-host-reset-ack.service \ - ampere-host-force-reset.service \ - ampere-host-power-cycle.service \ + ampere-host-force-reset@.service \ + ampere-host-shutdown-ack@.service \ " -# host power control -# Force the power cycle target to run the ampere power cycle -HOST_REBOOT_SVC = "ampere-host-power-cycle.service" -HOST_REBOOT_SVC_TGTFMT = "obmc-host-reboot@{0}.target" -HOST_REBOOT_SVC_FMT = "../${HOST_REBOOT_SVC}:${HOST_REBOOT_SVC_TGTFMT}.requires/${HOST_REBOOT_SVC}" -SYSTEMD_LINK_${PN} += "${@compose_list_zip(d, 'HOST_REBOOT_SVC_FMT', 'OBMC_HOST_INSTANCES')}" - -# overwrite the host reset to graceful reset -HOST_WARM_REBOOT_SOFT_SVC = "ampere-host-reset.service" -HOST_WARM_REBOOT_TGTFMT = "obmc-host-warm-reboot@{0}.target" -HOST_WARM_REBOOT_SOFT_SVC_FMT = "../${HOST_WARM_REBOOT_SOFT_SVC}:${HOST_WARM_REBOOT_TGTFMT}.requires/${HOST_WARM_REBOOT_SOFT_SVC}" -SYSTEMD_LINK_${PN} += "${@compose_list_zip(d, 'HOST_WARM_REBOOT_SOFT_SVC_FMT', 'OBMC_HOST_INSTANCES')}" # overwrite force reboot -HOST_WARM_REBOOT_FORCE_TGT = "ampere-host-force-reset.service" +HOST_WARM_REBOOT_FORCE_TGT = "ampere-host-force-reset@.service" HOST_WARM_REBOOT_FORCE_TGTFMT = "obmc-host-force-warm-reboot@{0}.target" HOST_WARM_REBOOT_FORCE_TARGET_FMT = "../${HOST_WARM_REBOOT_FORCE_TGT}:${HOST_WARM_REBOOT_FORCE_TGTFMT}.requires/${HOST_WARM_REBOOT_FORCE_TGT}" SYSTEMD_LINK_${PN} += "${@compose_list_zip(d, 'HOST_WARM_REBOOT_FORCE_TARGET_FMT', 'OBMC_HOST_INSTANCES')}" -# chassis power control -CHASSIS_POWERON_SVC = "ampere-chassis-poweron.service" -CHASSIS_POWERON_TGTFMT = "obmc-chassis-poweron@{0}.target" -CHASSIS_POWERON_FMT = "../${CHASSIS_POWERON_SVC}:${CHASSIS_POWERON_TGTFMT}.requires/${CHASSIS_POWERON_SVC}" -SYSTEMD_LINK_${PN} += "${@compose_list_zip(d, 'CHASSIS_POWERON_FMT', 'OBMC_CHASSIS_INSTANCES')}" - TMPL = "phosphor-gpio-monitor@.service" INSTFMT = "phosphor-gpio-monitor@{0}.service" TGT = "multi-user.target" diff --git a/meta-ampere/meta-common/recipes-ac01/host/ampere-hostctrl/ampere-chassis-poweron.service b/meta-ampere/meta-common/recipes-ac01/host/ampere-hostctrl/ampere-chassis-poweron.service deleted file mode 100644 index 76ceb8856..000000000 --- a/meta-ampere/meta-common/recipes-ac01/host/ampere-hostctrl/ampere-chassis-poweron.service +++ /dev/null @@ -1,9 +0,0 @@ -[Unit] -Description=Ampere Computing LLC Power ON Chassis -Conflicts=obmc-chassis-poweroff@0.target - -[Service] -RemainAfterExit=yes -Type=oneshot -ExecStart=/usr/bin/env ampere_power_util.sh mb on -SyslogIdentifier=ampere_power_util.sh diff --git a/meta-ampere/meta-common/recipes-ac01/host/ampere-hostctrl/ampere-host-force-reset.service b/meta-ampere/meta-common/recipes-ac01/host/ampere-hostctrl/ampere-host-force-reset.service deleted file mode 100644 index 8a40baf7b..000000000 --- a/meta-ampere/meta-common/recipes-ac01/host/ampere-hostctrl/ampere-host-force-reset.service +++ /dev/null @@ -1,11 +0,0 @@ -[Unit] -Description=Ampere Computing LLC force reset host -Conflicts=obmc-chassis-poweroff@0.target -OnFailure=obmc-chassis-powerreset@0.target - -[Service] -RemainAfterExit=no -Type=oneshot -ExecStart=/usr/bin/env ampere_power_util.sh mb force_reset -SyslogIdentifier=ampere_power_util.sh - diff --git a/meta-ampere/meta-common/recipes-ac01/host/ampere-hostctrl/ampere-host-force-reset@.service b/meta-ampere/meta-common/recipes-ac01/host/ampere-hostctrl/ampere-host-force-reset@.service new file mode 100644 index 000000000..6e03c8b81 --- /dev/null +++ b/meta-ampere/meta-common/recipes-ac01/host/ampere-hostctrl/ampere-host-force-reset@.service @@ -0,0 +1,14 @@ +[Unit] +Description=Ampere Computing LLC force reset host%i +Wants=phosphor-reboot-host@%i.service +Conflicts=obmc-chassis-poweroff@%i.target +OnFailure=obmc-chassis-powerreset@%i.target + +[Service] +RemainAfterExit=no +Type=oneshot +ExecStart=/bin/sh -c "sleep 3 && /usr/bin/env ampere_power_util.sh mb force_reset" +SyslogIdentifier=ampere_power_util.sh + +[Install] +WantedBy=obmc-host-force-warm-reboot@%i.target \ No newline at end of file diff --git a/meta-ampere/meta-common/recipes-ac01/host/ampere-hostctrl/ampere-host-power-cycle.service b/meta-ampere/meta-common/recipes-ac01/host/ampere-hostctrl/ampere-host-power-cycle.service deleted file mode 100644 index 2fb03effb..000000000 --- a/meta-ampere/meta-common/recipes-ac01/host/ampere-hostctrl/ampere-host-power-cycle.service +++ /dev/null @@ -1,10 +0,0 @@ -[Unit] -Description=Ampere Computing LLC power cycle service -Conflicts=obmc-host-start@0.target -OnFailure=obmc-chassis-powerreset@0.target - -[Service] -RemainAfterExit=no -Type=oneshot -ExecStart=/usr/bin/env ampere_power_util.sh mb cycle -SyslogIdentifier=ampere_power_util.sh diff --git a/meta-ampere/meta-common/recipes-ac01/host/ampere-hostctrl/ampere-host-reset-ack.service b/meta-ampere/meta-common/recipes-ac01/host/ampere-hostctrl/ampere-host-reset-ack.service deleted file mode 100644 index 504186ec6..000000000 --- a/meta-ampere/meta-common/recipes-ac01/host/ampere-hostctrl/ampere-host-reset-ack.service +++ /dev/null @@ -1,10 +0,0 @@ -[Unit] -Description=Ampere Computing LLC triggering reset ACK -Conflicts=obmc-host-start@0.target -OnFailure=obmc-chassis-powerreset@0.target - -[Service] -RemainAfterExit=no -Type=oneshot -ExecStart=/usr/bin/env ampere_power_util.sh mb force_reset -SyslogIdentifier=ampere_power_util.sh diff --git a/meta-ampere/meta-common/recipes-ac01/host/ampere-hostctrl/ampere-host-reset.service b/meta-ampere/meta-common/recipes-ac01/host/ampere-hostctrl/ampere-host-reset.service deleted file mode 100644 index ac7618ad0..000000000 --- a/meta-ampere/meta-common/recipes-ac01/host/ampere-hostctrl/ampere-host-reset.service +++ /dev/null @@ -1,9 +0,0 @@ -[Unit] -Description=Ampere Computing LLC warm reset host -Conflicts=obmc-chassis-poweroff@0.target - -[Service] -RemainAfterExit=no -Type=oneshot -ExecStart=/usr/bin/env ampere_power_util.sh mb graceful_reset -SyslogIdentifier=ampere_power_util.sh diff --git a/meta-ampere/meta-common/recipes-ac01/host/ampere-hostctrl/ampere-host-shutdown-ack@.service b/meta-ampere/meta-common/recipes-ac01/host/ampere-hostctrl/ampere-host-shutdown-ack@.service new file mode 100644 index 000000000..6588191aa --- /dev/null +++ b/meta-ampere/meta-common/recipes-ac01/host/ampere-hostctrl/ampere-host-shutdown-ack@.service @@ -0,0 +1,8 @@ +[Unit] +Description=Ampere Computing LLC host shutdown ACK +Conflicts=obmc-chassis-poweron@0.target + +[Service] +Type=oneshot +ExecStart=/usr/bin/env ampere_power_util.sh mb shutdown_ack +SyslogIdentifier=ampere_host_shutdown_ack diff --git a/meta-ampere/meta-common/recipes-ac01/host/files/ampere_power_util.sh b/meta-ampere/meta-common/recipes-ac01/host/files/ampere_power_util.sh index 9a8b06c6b..aa742104f 100644 --- a/meta-ampere/meta-common/recipes-ac01/host/files/ampere_power_util.sh +++ b/meta-ampere/meta-common/recipes-ac01/host/files/ampere_power_util.sh @@ -4,15 +4,6 @@ function usage() { echo "usage: power-util mb [on|status|cycle|reset|graceful_reset|force_reset|soft_off]"; } -power_off() { - echo "power_off" -} - -power_on() { - echo "Powering on Server $2" - 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.On -} - 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 @@ -22,21 +13,13 @@ power_status() { fi } -power_reset() { - echo "Reset on server $2" - 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.Reboot -} - -timestamp() { - date +"%s" # current time -} - 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" +<<<<<<< HEAD fi } @@ -50,6 +33,10 @@ graceful_shutdown() { sleep 1 gpioset -l 0 49=0 sleep 30s +======= + sleep 3 + systemctl start obmc-chassis-poweroff@0.target +>>>>>>> 397e033ef... meta-ampere: power control: refactor host power control fi } @@ -81,6 +68,26 @@ soft_off() { } 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 91=1 sleep 1 @@ -100,30 +107,23 @@ if [ $1 != "mb" ]; then exit 0; fi -if [ $2 = "on" ]; then - if [ $(power_status) == "off" ]; then - power_on +# check if power guard enabled +dir="/run/systemd/system/" +file="reboot-guard.conf" +units=("reboot" "poweroff" "halt") +for unit in "${units[@]}"; do + if [ -f ${dir}${unit}.target.d/${file} ]; then + echo "PowerGuard enabled, cannot do power control, exit!!!" + exit -1 fi -elif [ $2 == "cycle" ]; then - if [ $(power_status) == "on" ]; then - echo "Powering off server" - power_off - sleep 20s - power_on - else - echo "Host is already off, do nothing" - fi -elif [ $2 == "reset" ]; then - if [ $(power_status) == "on" ]; then - power_reset - else - echo "ERROR: Server not powered on" - fi -elif [ $2 == "graceful_reset" ]; then +done + +if [ ! -d "/run/openbmc/" ]; then mkdir -p "/run/openbmc/" - touch "/run/openbmc/host@0-graceful-reset" - graceful_shutdown - sleep 20s +fi + +if [ $2 == "shutdown_ack" ]; then + shutdown_ack elif [ $2 == "status" ]; then power_status elif [ $2 == "force_reset" ]; then diff --git a/meta-ampere/meta-common/recipes-ac01/host/files/obmc/gpio/reboot_ack b/meta-ampere/meta-common/recipes-ac01/host/files/obmc/gpio/reboot_ack index 0436d32da..a8ad98ee7 100644 --- a/meta-ampere/meta-common/recipes-ac01/host/files/obmc/gpio/reboot_ack +++ b/meta-ampere/meta-common/recipes-ac01/host/files/obmc/gpio/reboot_ack @@ -1,4 +1,4 @@ DEVPATH=/dev/input/event0 KEY=75 POLARITY=1 -TARGET=ampere-host-reset-ack.service +TARGET=obmc-host-force-warm-reboot@0.target diff --git a/meta-ampere/meta-common/recipes-ac01/host/files/obmc/gpio/shutdown_ack b/meta-ampere/meta-common/recipes-ac01/host/files/obmc/gpio/shutdown_ack index a0e857fac..18cc87246 100644 --- a/meta-ampere/meta-common/recipes-ac01/host/files/obmc/gpio/shutdown_ack +++ b/meta-ampere/meta-common/recipes-ac01/host/files/obmc/gpio/shutdown_ack @@ -1,4 +1,4 @@ DEVPATH=/dev/input/event0 KEY=50 POLARITY=1 -TARGET=ampere-chassis-poweroff.service +TARGET=ampere-host-shutdown-ack@0.service diff --git a/meta-ampere/meta-common/recipes-phosphor/state/phosphor-state-manager_%.bbappend b/meta-ampere/meta-common/recipes-phosphor/state/phosphor-state-manager_%.bbappend index 78683f841..dcf8cac00 100644 --- a/meta-ampere/meta-common/recipes-phosphor/state/phosphor-state-manager_%.bbappend +++ b/meta-ampere/meta-common/recipes-phosphor/state/phosphor-state-manager_%.bbappend @@ -3,14 +3,3 @@ FILESEXTRAPATHS_prepend := "${THISDIR}/${PN}:" DEPS_CFG = "resetreason.conf" DEPS_TGT = "phosphor-discover-system-state@.service" SYSTEMD_OVERRIDE_${PN}-discover_append = "${DEPS_CFG}:${DEPS_TGT}.d/${DEPS_CFG}" - -pkg_postinst_${PN}-obmc-targets_append() { - rm "$D$systemd_system_unitdir/obmc-host-warm-reboot@0.target.requires/xyz.openbmc_project.Ipmi.Internal.SoftPowerOff.service" - rm "$D$systemd_system_unitdir/obmc-host-warm-reboot@0.target.requires/obmc-host-force-warm-reboot@0.target" - - rm "$D$systemd_system_unitdir/obmc-host-reboot@0.target.requires/phosphor-reboot-host@0.service" - rm "$D$systemd_system_unitdir/obmc-host-reboot@0.target.requires/obmc-host-shutdown@0.target" - - rm "$D$systemd_system_unitdir/obmc-host-force-warm-reboot@0.target.requires/obmc-host-stop@0.target" - rm "$D$systemd_system_unitdir/obmc-host-force-warm-reboot@0.target.requires/phosphor-reboot-host@0.service" -} -- cgit v1.2.3 From fb214784edbc1da7ba155a1cddf7b3f6d0bbfb66 Mon Sep 17 00:00:00 2001 From: ThuBaNguyen Date: Thu, 8 Jul 2021 14:20:43 +0700 Subject: meta-ampere: power control: restructure source code ampere-hostctrl package includes the generic codes and the platform specific codes. The generic sources are applied for all of the Ampere platforms, they are the service files and the scripts to setting the GPIO pins. The platform specific sources are the GPIO pin config file and the gpio monitor config files. This commit moves the platform specific files to the platform code. Tested: 1. Do the power control actions use ipmitool, BMC web and Redfish. 2. Make sure the server states are changed as expected. Signed-off-by: ThuBaNguyen Change-Id: Ic0e261109f7a5dfaf38c883bff0afedab763a0b6 --- .../recipes-ac01/host/ampere-hostctrl.bb | 26 +--- .../ampere-host-shutdown-ack@.service | 8 -- .../recipes-ac01/host/files/ampere_power_util.sh | 144 -------------------- .../recipes-ac01/host/files/obmc/gpio/reboot_ack | 4 - .../recipes-ac01/host/files/obmc/gpio/shutdown_ack | 4 - meta-ampere/meta-jade/conf/machine/mtjade.conf | 1 + .../recipes-ampere/platform/mtjade-utils.bb | 18 +++ .../platform/mtjade-utils/ampere_power_util.sh | 147 +++++++++++++++++++++ .../platform/mtjade-utils/gpio-defs.sh | 32 +++++ .../recipes-phosphor/gpio/host-gpio-handling.bb | 23 ++++ .../ampere-host-shutdown-ack@.service | 8 ++ .../gpio/host-gpio-handling/obmc/gpio/reboot_ack | 4 + .../gpio/host-gpio-handling/obmc/gpio/shutdown_ack | 4 + .../packagegroups/packagegroup-obmc-apps.bbappend | 4 + 14 files changed, 244 insertions(+), 183 deletions(-) delete mode 100644 meta-ampere/meta-common/recipes-ac01/host/ampere-hostctrl/ampere-host-shutdown-ack@.service delete mode 100644 meta-ampere/meta-common/recipes-ac01/host/files/ampere_power_util.sh delete mode 100644 meta-ampere/meta-common/recipes-ac01/host/files/obmc/gpio/reboot_ack delete mode 100644 meta-ampere/meta-common/recipes-ac01/host/files/obmc/gpio/shutdown_ack create mode 100644 meta-ampere/meta-jade/recipes-ampere/platform/mtjade-utils.bb create mode 100644 meta-ampere/meta-jade/recipes-ampere/platform/mtjade-utils/ampere_power_util.sh create mode 100644 meta-ampere/meta-jade/recipes-ampere/platform/mtjade-utils/gpio-defs.sh create mode 100644 meta-ampere/meta-jade/recipes-phosphor/gpio/host-gpio-handling.bb create mode 100644 meta-ampere/meta-jade/recipes-phosphor/gpio/host-gpio-handling/ampere-host-shutdown-ack@.service create mode 100644 meta-ampere/meta-jade/recipes-phosphor/gpio/host-gpio-handling/obmc/gpio/reboot_ack create mode 100644 meta-ampere/meta-jade/recipes-phosphor/gpio/host-gpio-handling/obmc/gpio/shutdown_ack (limited to 'meta-ampere/meta-common') diff --git a/meta-ampere/meta-common/recipes-ac01/host/ampere-hostctrl.bb b/meta-ampere/meta-common/recipes-ac01/host/ampere-hostctrl.bb index 4a44d1b2f..cfefa8d94 100644 --- a/meta-ampere/meta-common/recipes-ac01/host/ampere-hostctrl.bb +++ b/meta-ampere/meta-common/recipes-ac01/host/ampere-hostctrl.bb @@ -7,41 +7,21 @@ LIC_FILES_CHKSUM = "file://${COMMON_LICENSE_DIR}/Apache-2.0;md5=89aea4e17d99a7ca inherit systemd inherit obmc-phosphor-systemd -# For now, monitoring shutdown_ack and reboot_ack are the only usecases -OBMC_HOST_MONITOR_INSTANCES = "shutdown_ack reboot_ack" -SYSTEMD_ENVIRONMENT_FILE_${PN} +="obmc/gpio/shutdown_ack obmc/gpio/reboot_ack" - S = "${WORKDIR}" SRC_URI = " \ - file://ampere_power_util.sh \ file://ampere-host-force-reset@.service \ - file://ampere-host-shutdown-ack@.service \ " -DEPENDS = "systemd virtual/obmc-gpio-monitor" -RDEPENDS_${PN} = "bash virtual/obmc-gpio-monitor" - SYSTEMD_PACKAGES = "${PN}" SYSTEMD_SERVICE_${PN} = " \ ampere-host-force-reset@.service \ - ampere-host-shutdown-ack@.service \ " -# overwrite force reboot +# append force reboot HOST_WARM_REBOOT_FORCE_TGT = "ampere-host-force-reset@.service" +HOST_WARM_REBOOT_FORCE_INSTMPL = "ampere-host-force-reset@{0}.service" HOST_WARM_REBOOT_FORCE_TGTFMT = "obmc-host-force-warm-reboot@{0}.target" -HOST_WARM_REBOOT_FORCE_TARGET_FMT = "../${HOST_WARM_REBOOT_FORCE_TGT}:${HOST_WARM_REBOOT_FORCE_TGTFMT}.requires/${HOST_WARM_REBOOT_FORCE_TGT}" +HOST_WARM_REBOOT_FORCE_TARGET_FMT = "../${HOST_WARM_REBOOT_FORCE_TGT}:${HOST_WARM_REBOOT_FORCE_TGTFMT}.requires/${HOST_WARM_REBOOT_FORCE_INSTMPL}" SYSTEMD_LINK_${PN} += "${@compose_list_zip(d, 'HOST_WARM_REBOOT_FORCE_TARGET_FMT', 'OBMC_HOST_INSTANCES')}" -TMPL = "phosphor-gpio-monitor@.service" -INSTFMT = "phosphor-gpio-monitor@{0}.service" -TGT = "multi-user.target" -FMT = "../${TMPL}:${TGT}.requires/${INSTFMT}" -SYSTEMD_LINK_${PN} += "${@compose_list(d, 'FMT', 'OBMC_HOST_MONITOR_INSTANCES')}" - -do_install() { - install -d ${D}/usr/sbin - install -m 0755 ${WORKDIR}/ampere_power_util.sh ${D}/${sbindir}/ampere_power_util.sh -} - diff --git a/meta-ampere/meta-common/recipes-ac01/host/ampere-hostctrl/ampere-host-shutdown-ack@.service b/meta-ampere/meta-common/recipes-ac01/host/ampere-hostctrl/ampere-host-shutdown-ack@.service deleted file mode 100644 index 6588191aa..000000000 --- a/meta-ampere/meta-common/recipes-ac01/host/ampere-hostctrl/ampere-host-shutdown-ack@.service +++ /dev/null @@ -1,8 +0,0 @@ -[Unit] -Description=Ampere Computing LLC host shutdown ACK -Conflicts=obmc-chassis-poweron@0.target - -[Service] -Type=oneshot -ExecStart=/usr/bin/env ampere_power_util.sh mb shutdown_ack -SyslogIdentifier=ampere_host_shutdown_ack diff --git a/meta-ampere/meta-common/recipes-ac01/host/files/ampere_power_util.sh b/meta-ampere/meta-common/recipes-ac01/host/files/ampere_power_util.sh deleted file mode 100644 index aa742104f..000000000 --- a/meta-ampere/meta-common/recipes-ac01/host/files/ampere_power_util.sh +++ /dev/null @@ -1,144 +0,0 @@ -#!/bin/bash -# Usage of this utility -function usage() { - echo "usage: power-util mb [on|status|cycle|reset|graceful_reset|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" -<<<<<<< HEAD - fi -} - -graceful_shutdown() { - if [ -f "/run/openbmc/host@0-request" ]; then - echo "shutdown host immediately" - power_off - else - echo "Triggering graceful shutdown" - gpioset -l 0 49=1 - sleep 1 - gpioset -l 0 49=0 - sleep 30s -======= - sleep 3 - systemctl start obmc-chassis-poweroff@0.target ->>>>>>> 397e033ef... meta-ampere: power control: refactor host power control - fi -} - -soft_off() { - # Trigger shutdown_req - touch /run/openbmc/host@0-softpoweroff - gpioset -l 0 49=1 - sleep 1s - gpioset -l 0 49=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 91=1 - sleep 1 - gpioset -l 0 91=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 - -# check if power guard enabled -dir="/run/systemd/system/" -file="reboot-guard.conf" -units=("reboot" "poweroff" "halt") -for unit in "${units[@]}"; do - if [ -f ${dir}${unit}.target.d/${file} ]; then - echo "PowerGuard enabled, cannot do power control, exit!!!" - exit -1 - fi -done - -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 == "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; diff --git a/meta-ampere/meta-common/recipes-ac01/host/files/obmc/gpio/reboot_ack b/meta-ampere/meta-common/recipes-ac01/host/files/obmc/gpio/reboot_ack deleted file mode 100644 index a8ad98ee7..000000000 --- a/meta-ampere/meta-common/recipes-ac01/host/files/obmc/gpio/reboot_ack +++ /dev/null @@ -1,4 +0,0 @@ -DEVPATH=/dev/input/event0 -KEY=75 -POLARITY=1 -TARGET=obmc-host-force-warm-reboot@0.target diff --git a/meta-ampere/meta-common/recipes-ac01/host/files/obmc/gpio/shutdown_ack b/meta-ampere/meta-common/recipes-ac01/host/files/obmc/gpio/shutdown_ack deleted file mode 100644 index 18cc87246..000000000 --- a/meta-ampere/meta-common/recipes-ac01/host/files/obmc/gpio/shutdown_ack +++ /dev/null @@ -1,4 +0,0 @@ -DEVPATH=/dev/input/event0 -KEY=50 -POLARITY=1 -TARGET=ampere-host-shutdown-ack@0.service diff --git a/meta-ampere/meta-jade/conf/machine/mtjade.conf b/meta-ampere/meta-jade/conf/machine/mtjade.conf index e749af6de..558a6f404 100644 --- a/meta-ampere/meta-jade/conf/machine/mtjade.conf +++ b/meta-ampere/meta-jade/conf/machine/mtjade.conf @@ -29,6 +29,7 @@ OBMC_MACHINE_FEATURES += "\ VOLATILE_LOG_DIR = "no" OBMC_IMAGE_EXTRA_INSTALL_append = "\ + mtjade-utils \ ampere-usbnet \ ampere-flash-utils \ ampere-mac-update \ diff --git a/meta-ampere/meta-jade/recipes-ampere/platform/mtjade-utils.bb b/meta-ampere/meta-jade/recipes-ampere/platform/mtjade-utils.bb new file mode 100644 index 000000000..184d643f6 --- /dev/null +++ b/meta-ampere/meta-jade/recipes-ampere/platform/mtjade-utils.bb @@ -0,0 +1,18 @@ +SUMMARY = "Ampere Platform Environment Definitions" +DESCRIPTION = "Ampere Platform Environment Definitions" +PR = "r1" +LICENSE = "Apache-2.0" +LIC_FILES_CHKSUM = "file://${COMMON_LICENSE_DIR}/Apache-2.0;md5=89aea4e17d99a7cacdbeed46a0096b10" + +SRC_URI = " \ + file://gpio-defs.sh \ + file://ampere_power_util.sh \ + " + +RDEPENDS_${PN} = "bash" + +do_install() { + install -d ${D}/usr/sbin + install -m 0755 ${WORKDIR}/gpio-defs.sh ${D}/${sbindir}/ + install -m 0755 ${WORKDIR}/ampere_power_util.sh ${D}/${sbindir}/ +} \ No newline at end of file diff --git a/meta-ampere/meta-jade/recipes-ampere/platform/mtjade-utils/ampere_power_util.sh b/meta-ampere/meta-jade/recipes-ampere/platform/mtjade-utils/ampere_power_util.sh new file mode 100644 index 000000000..4ad07a68f --- /dev/null +++ b/meta-ampere/meta-jade/recipes-ampere/platform/mtjade-utils/ampere_power_util.sh @@ -0,0 +1,147 @@ +#!/bin/bash +#ampere_platform_config.sh is platform configuration file +source /usr/sbin/gpio-defs.sh + +# Usage of this utility +function usage() { + echo "usage: power-util mb [on|status|cycle|reset|graceful_reset|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" +<<<<<<< HEAD + fi +} + +graceful_shutdown() { + if [ -f "/run/openbmc/host@0-request" ]; then + echo "shutdown host immediately" + power_off + else + echo "Triggering graceful shutdown" + gpioset -l 0 49=1 + sleep 1 + gpioset -l 0 49=0 + sleep 30s +======= + sleep 3 + systemctl start obmc-chassis-poweroff@0.target +>>>>>>> 397e033ef... meta-ampere: power control: refactor host power control + fi +} + +soft_off() { + # Trigger shutdown_req + touch /run/openbmc/host@0-softpoweroff + gpioset -l $GPIO_CHIP0_IDX $S0_SHD_REQ_L=1 + sleep 1s + gpioset -l $GPIO_CHIP0_IDX $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 $GPIO_CHIP0_IDX $S0_SYSRESET_L=1 + sleep 1 + gpioset -l $GPIO_CHIP0_IDX $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 + +# check if power guard enabled +dir="/run/systemd/system/" +file="reboot-guard.conf" +units=("reboot" "poweroff" "halt") +for unit in "${units[@]}"; do + if [ -f ${dir}${unit}.target.d/${file} ]; then + echo "PowerGuard enabled, cannot do power control, exit!!!" + exit -1 + fi +done + +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 == "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; diff --git a/meta-ampere/meta-jade/recipes-ampere/platform/mtjade-utils/gpio-defs.sh b/meta-ampere/meta-jade/recipes-ampere/platform/mtjade-utils/gpio-defs.sh new file mode 100644 index 000000000..fce59d581 --- /dev/null +++ b/meta-ampere/meta-jade/recipes-ampere/platform/mtjade-utils/gpio-defs.sh @@ -0,0 +1,32 @@ +# 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 + + +### Table 1: GPIO Assignments +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 + +### 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 diff --git a/meta-ampere/meta-jade/recipes-phosphor/gpio/host-gpio-handling.bb b/meta-ampere/meta-jade/recipes-phosphor/gpio/host-gpio-handling.bb new file mode 100644 index 000000000..4358b1242 --- /dev/null +++ b/meta-ampere/meta-jade/recipes-phosphor/gpio/host-gpio-handling.bb @@ -0,0 +1,23 @@ +SUMMARY = "Ampere Computing LLC Host Gpio Handling" +PR = "r1" +LICENSE = "Apache-2.0" +LIC_FILES_CHKSUM = "file://${COMMON_LICENSE_DIR}/Apache-2.0;md5=89aea4e17d99a7cacdbeed46a0096b10" + +inherit obmc-phosphor-systemd + +DEPENDS += "virtual/obmc-gpio-monitor" +RDEPENDS_${PN} += "virtual/obmc-gpio-monitor" + +OBMC_HOST_ACK_MONITOR_INSTANCES = "reboot_ack shutdown_ack" + +SYSTEMD_ENVIRONMENT_FILE_${PN} +="obmc/gpio/reboot_ack \ + obmc/gpio/shutdown_ack \ + " + +TMPL = "phosphor-gpio-monitor@.service" +INSTFMT = "phosphor-gpio-monitor@{0}.service" +TGT = "multi-user.target" +FMT = "../${TMPL}:${TGT}.requires/${INSTFMT}" + +SYSTEMD_SERVICE_${PN} += "ampere-host-shutdown-ack@.service" +SYSTEMD_LINK_${PN} += "${@compose_list(d, 'FMT', 'OBMC_HOST_ACK_MONITOR_INSTANCES')}" diff --git a/meta-ampere/meta-jade/recipes-phosphor/gpio/host-gpio-handling/ampere-host-shutdown-ack@.service b/meta-ampere/meta-jade/recipes-phosphor/gpio/host-gpio-handling/ampere-host-shutdown-ack@.service new file mode 100644 index 000000000..6588191aa --- /dev/null +++ b/meta-ampere/meta-jade/recipes-phosphor/gpio/host-gpio-handling/ampere-host-shutdown-ack@.service @@ -0,0 +1,8 @@ +[Unit] +Description=Ampere Computing LLC host shutdown ACK +Conflicts=obmc-chassis-poweron@0.target + +[Service] +Type=oneshot +ExecStart=/usr/bin/env ampere_power_util.sh mb shutdown_ack +SyslogIdentifier=ampere_host_shutdown_ack diff --git a/meta-ampere/meta-jade/recipes-phosphor/gpio/host-gpio-handling/obmc/gpio/reboot_ack b/meta-ampere/meta-jade/recipes-phosphor/gpio/host-gpio-handling/obmc/gpio/reboot_ack new file mode 100644 index 000000000..a8ad98ee7 --- /dev/null +++ b/meta-ampere/meta-jade/recipes-phosphor/gpio/host-gpio-handling/obmc/gpio/reboot_ack @@ -0,0 +1,4 @@ +DEVPATH=/dev/input/event0 +KEY=75 +POLARITY=1 +TARGET=obmc-host-force-warm-reboot@0.target diff --git a/meta-ampere/meta-jade/recipes-phosphor/gpio/host-gpio-handling/obmc/gpio/shutdown_ack b/meta-ampere/meta-jade/recipes-phosphor/gpio/host-gpio-handling/obmc/gpio/shutdown_ack new file mode 100644 index 000000000..18cc87246 --- /dev/null +++ b/meta-ampere/meta-jade/recipes-phosphor/gpio/host-gpio-handling/obmc/gpio/shutdown_ack @@ -0,0 +1,4 @@ +DEVPATH=/dev/input/event0 +KEY=50 +POLARITY=1 +TARGET=ampere-host-shutdown-ack@0.service diff --git a/meta-ampere/meta-jade/recipes-phosphor/packagegroups/packagegroup-obmc-apps.bbappend b/meta-ampere/meta-jade/recipes-phosphor/packagegroups/packagegroup-obmc-apps.bbappend index 3af702292..ca86a4a21 100644 --- a/meta-ampere/meta-jade/recipes-phosphor/packagegroups/packagegroup-obmc-apps.bbappend +++ b/meta-ampere/meta-jade/recipes-phosphor/packagegroups/packagegroup-obmc-apps.bbappend @@ -1,2 +1,6 @@ RDEPENDS_${PN}-extras_append_mtjade = " webui-vue phosphor-image-signing phosphor-virtual-sensor" RDEPENDS_${PN}-inventory_append_mtjade = " fault-monitor id-button psu-hotswap-reset" + +RDEPENDS_${PN}-inventory_append_mtjade = " \ + host-gpio-handling \ + " -- cgit v1.2.3 From 7b4528285147286f72769333cfde8c0d07ed11d1 Mon Sep 17 00:00:00 2001 From: ThuBaNguyen Date: Sun, 6 Jun 2021 14:36:07 +0700 Subject: meta-ampere: host-check: verify the host state When phosphor-state-manager handles the power action to turn on the host, phosphor-state-manager does not use the software interfaces to verify the host state. It set the host state to running after all of required services of the power action target are done. The power on watchdog is used to verify the host state and handle the failure in the host state changing. But Mt.Jade platforms do not handle power on watchdog. This causes the CurrentHostState dbus property is Running before the host is ready. In Mt.Jade platform, the SCP drives S0_FW_BOOT_OK to high when the host is already on. This GPIO can be used to identify the host state. One service should be added to the required list. This service checks the host state in power on and triggers obmc-host-quiesce@%i.target when the host is failed to boot. ampere-host-check package adds ampere-host-on-host-check@.service for that purpose. Tested: 1. Boot up BMC with the host is off/on. Check CurrentHostState. 2. Call Ipmitool power off/on. Check the CurrentHostState. 3. Call Ipmitool chassis power off/on. Check the CurrentHostState. 4. Call Ipmitool power cycle. Check the CurrentHostState. 5. Call Ipmitool chassis power cycle. Check the CurrentHostState. 6. Power off the host. Set power policty to Always-on. AC power. The host should be on. And CurrentHostState should be Running. 7. Power on the host. Set power policty to Always-off. AC power. The host should be off. And CurrentHostState should be Off. Change-Id: I9b0b346883a5f0203bf078453065c18ae4603311 Signed-off-by: ThuBaNguyen --- .../recipes-ac01/host/ampere-hostctrl.bb | 8 ++++ .../ampere-host-on-host-check@.service | 13 +++++++ .../recipes-ampere/platform/mtjade-utils.bb | 4 ++ .../platform/mtjade-utils/ampere_host_check.sh | 45 ++++++++++++++++++++++ .../platform/mtjade-utils/gpio-lib.sh | 30 +++++++++++++++ 5 files changed, 100 insertions(+) create mode 100644 meta-ampere/meta-common/recipes-ac01/host/ampere-hostctrl/ampere-host-on-host-check@.service create mode 100644 meta-ampere/meta-jade/recipes-ampere/platform/mtjade-utils/ampere_host_check.sh create mode 100644 meta-ampere/meta-jade/recipes-ampere/platform/mtjade-utils/gpio-lib.sh (limited to 'meta-ampere/meta-common') diff --git a/meta-ampere/meta-common/recipes-ac01/host/ampere-hostctrl.bb b/meta-ampere/meta-common/recipes-ac01/host/ampere-hostctrl.bb index cfefa8d94..5c4b6a012 100644 --- a/meta-ampere/meta-common/recipes-ac01/host/ampere-hostctrl.bb +++ b/meta-ampere/meta-common/recipes-ac01/host/ampere-hostctrl.bb @@ -11,6 +11,7 @@ S = "${WORKDIR}" SRC_URI = " \ file://ampere-host-force-reset@.service \ + file://ampere-host-on-host-check@.service \ " SYSTEMD_PACKAGES = "${PN}" @@ -24,4 +25,11 @@ HOST_WARM_REBOOT_FORCE_INSTMPL = "ampere-host-force-reset@{0}.service" HOST_WARM_REBOOT_FORCE_TGTFMT = "obmc-host-force-warm-reboot@{0}.target" HOST_WARM_REBOOT_FORCE_TARGET_FMT = "../${HOST_WARM_REBOOT_FORCE_TGT}:${HOST_WARM_REBOOT_FORCE_TGTFMT}.requires/${HOST_WARM_REBOOT_FORCE_INSTMPL}" SYSTEMD_LINK_${PN} += "${@compose_list_zip(d, 'HOST_WARM_REBOOT_FORCE_TARGET_FMT', 'OBMC_HOST_INSTANCES')}" +SYSTEMD_SERVICE_${PN} += "${HOST_WARM_REBOOT_FORCE_TGT}" +HOST_ON_RESET_HOSTTMPL = "ampere-host-on-host-check@.service" +HOST_ON_RESET_HOSTINSTMPL = "ampere-host-on-host-check@{0}.service" +HOST_ON_RESET_HOSTTGTFMT = "obmc-host-startmin@{0}.target" +HOST_ON_RESET_HOSTFMT = "../${HOST_ON_RESET_HOSTTMPL}:${HOST_ON_RESET_HOSTTGTFMT}.requires/${HOST_ON_RESET_HOSTINSTMPL}" +SYSTEMD_LINK_${PN} += "${@compose_list_zip(d, 'HOST_ON_RESET_HOSTFMT', 'OBMC_HOST_INSTANCES')}" +SYSTEMD_SERVICE_${PN} += "${HOST_ON_RESET_HOSTTMPL}" diff --git a/meta-ampere/meta-common/recipes-ac01/host/ampere-hostctrl/ampere-host-on-host-check@.service b/meta-ampere/meta-common/recipes-ac01/host/ampere-hostctrl/ampere-host-on-host-check@.service new file mode 100644 index 000000000..36e5a642c --- /dev/null +++ b/meta-ampere/meta-common/recipes-ac01/host/ampere-hostctrl/ampere-host-on-host-check@.service @@ -0,0 +1,13 @@ +[Unit] +Description=Check Host%i status before obmc-host-startmin +Wants=obmc-host-started@%i.target +After=obmc-host-started@%i.target +Conflicts=obmc-host-stop@%i.target +Conflicts=phosphor-reset-host-check@%i.service +OnFailure=obmc-host-quiesce@%i.target +OnFailureJobMode=flush +ConditionPathExists=!/run/openbmc/host@%i-on + +[Service] +Type=oneshot +ExecStart=/usr/sbin/ampere_host_check.sh 1 0 diff --git a/meta-ampere/meta-jade/recipes-ampere/platform/mtjade-utils.bb b/meta-ampere/meta-jade/recipes-ampere/platform/mtjade-utils.bb index 184d643f6..159ccdd64 100644 --- a/meta-ampere/meta-jade/recipes-ampere/platform/mtjade-utils.bb +++ b/meta-ampere/meta-jade/recipes-ampere/platform/mtjade-utils.bb @@ -6,13 +6,17 @@ LIC_FILES_CHKSUM = "file://${COMMON_LICENSE_DIR}/Apache-2.0;md5=89aea4e17d99a7ca SRC_URI = " \ file://gpio-defs.sh \ + file://gpio-lib.sh \ file://ampere_power_util.sh \ + file://ampere_host_check.sh \ " RDEPENDS_${PN} = "bash" do_install() { install -d ${D}/usr/sbin + install -m 0755 ${WORKDIR}/gpio-lib.sh ${D}/${sbindir}/ install -m 0755 ${WORKDIR}/gpio-defs.sh ${D}/${sbindir}/ install -m 0755 ${WORKDIR}/ampere_power_util.sh ${D}/${sbindir}/ + install -m 0755 ${WORKDIR}/ampere_host_check.sh ${D}/${sbindir}/ } \ No newline at end of file diff --git a/meta-ampere/meta-jade/recipes-ampere/platform/mtjade-utils/ampere_host_check.sh b/meta-ampere/meta-jade/recipes-ampere/platform/mtjade-utils/ampere_host_check.sh new file mode 100644 index 000000000..9eeeeca5a --- /dev/null +++ b/meta-ampere/meta-jade/recipes-ampere/platform/mtjade-utils/ampere_host_check.sh @@ -0,0 +1,45 @@ +#!/bin/bash + +source /usr/sbin/gpio-defs.sh +source /usr/sbin/gpio-lib.sh + +host_status() { + st=$(busctl get-property xyz.openbmc_project.State.Host /xyz/openbmc_project/state/host0 xyz.openbmc_project.State.Host CurrentHostState | cut -d"." -f6) + if [ "$st" == "Running\"" ]; then + echo "on" + else + echo "off" + fi +} + +createFile=$1 +setState=$2 + +if [ $(host_status) == "on" ]; then + exit 0 +fi + +# Time out to check S0_FW_BOOT_OK is 60 seconds +cnt=60 +val=0 +while [ $cnt -gt 0 ]; +do + val=$(gpio_get_val $S0_CPU_FW_BOOT_OK) + cnt=$((cnt - 1)) + echo "$cnt S0_CPU_FW_BOOT_OK = $val" + if [ $val == 1 ]; then + # Sleep 5 second before the host is ready + sleep 5 + if [ $createFile == 1 ]; then + if [ ! -d "/run/openbmc" ]; then + mkdir -p /run/openbmc + fi + echo "Creating /run/openbmc/host@0-on" + touch /run/openbmc/host@0-on + fi + exit 0 + fi + sleep 1 +done + +exit 1 diff --git a/meta-ampere/meta-jade/recipes-ampere/platform/mtjade-utils/gpio-lib.sh b/meta-ampere/meta-jade/recipes-ampere/platform/mtjade-utils/gpio-lib.sh new file mode 100644 index 000000000..fcc2d5411 --- /dev/null +++ b/meta-ampere/meta-jade/recipes-ampere/platform/mtjade-utils/gpio-lib.sh @@ -0,0 +1,30 @@ +#!/bin/bash + +function gpio_number() { + GPIO_BASE=$(cat /sys/class/gpio/gpio*/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 + echo $(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 +} -- cgit v1.2.3 From 99becbb128fb93a84197dafb8b7519dab5a65000 Mon Sep 17 00:00:00 2001 From: ThuBaNguyen Date: Sat, 19 Jun 2021 16:15:13 +0700 Subject: meta-ampere: host-check: overide phosphor-reset-host-check When BMC boots, phosphor-host-check uses the software interfaces(IPMI inband Hearbeat command or PLDM interface) to verify the host state and creates the host on indicator file. Ampere Altra SoCs do not support those software interfaces. They use the GPIO interface. GPIO pin S0_FW_BOOT_OK go high when the host is on. This commit appends ampere-reset-host-check@.service to phosphor-state-manager This service will replaces the role of phosphor-reset-host-check@.service. Tested: 1. Boot up BMC with the host is off/on. 2. Verify the CurrentHostState. Signed-off-by: ThuBaNguyen Change-Id: Ie4f73538266fff7d8c5fd40b437ffebc82cb12c5 --- .../ampere-reset-host-check@.service | 18 ++++++++++++++++++ .../state/phosphor-state-manager_%.bbappend | 8 ++++++++ 2 files changed, 26 insertions(+) create mode 100644 meta-ampere/meta-common/recipes-phosphor/state/phosphor-state-manager/ampere-reset-host-check@.service (limited to 'meta-ampere/meta-common') diff --git a/meta-ampere/meta-common/recipes-phosphor/state/phosphor-state-manager/ampere-reset-host-check@.service b/meta-ampere/meta-common/recipes-phosphor/state/phosphor-state-manager/ampere-reset-host-check@.service new file mode 100644 index 000000000..83f6581be --- /dev/null +++ b/meta-ampere/meta-common/recipes-phosphor/state/phosphor-state-manager/ampere-reset-host-check@.service @@ -0,0 +1,18 @@ +[Unit] +Description=Check Host%i status on BMC reset +Wants=phosphor-ipmi-host.service +After=phosphor-ipmi-host.service +Wants=obmc-host-reset-running@%i.target +Before=obmc-host-reset-running@%i.target +Wants=op-reset-chassis-on@%i.service +After=op-reset-chassis-on@%i.service +Conflicts=obmc-host-stop@%i.target +ConditionPathExists=/run/openbmc/chassis@%i-on + +[Service] +RemainAfterExit=yes +Type=oneshot +ExecStart=/usr/sbin/ampere_host_check.sh 1 0 + +[Install] +WantedBy=obmc-host-reset@%i.target \ No newline at end of file diff --git a/meta-ampere/meta-common/recipes-phosphor/state/phosphor-state-manager_%.bbappend b/meta-ampere/meta-common/recipes-phosphor/state/phosphor-state-manager_%.bbappend index dcf8cac00..bdb89ce63 100644 --- a/meta-ampere/meta-common/recipes-phosphor/state/phosphor-state-manager_%.bbappend +++ b/meta-ampere/meta-common/recipes-phosphor/state/phosphor-state-manager_%.bbappend @@ -3,3 +3,11 @@ FILESEXTRAPATHS_prepend := "${THISDIR}/${PN}:" DEPS_CFG = "resetreason.conf" DEPS_TGT = "phosphor-discover-system-state@.service" SYSTEMD_OVERRIDE_${PN}-discover_append = "${DEPS_CFG}:${DEPS_TGT}.d/${DEPS_CFG}" + +SRC_URI += " \ + file://ampere-reset-host-check@.service \ + " + +do_install_append() { + install -m 0644 ${WORKDIR}/ampere-reset-host-check@.service ${D}${systemd_unitdir}/system/phosphor-reset-host-check@.service +} \ No newline at end of file -- cgit v1.2.3