From d66b89a46be28183f7f783fe736effdc7f5d7004 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joan=20Olguy=20Can=C3=A9us?= Date: Fri, 13 Nov 2020 14:41:38 -0800 Subject: [PATCH] ELBERT: Enable Alternate boot (#108) Summary: ELBERT: Enable Alternate boot - Enable WDT2 by default in U-boot - Make elbert U-boot more consistent with other AST2620 platforms - Add disable_watchdog.sh to disable WDT2 after kernel boot - Add boot_info.sh to view and set the boot source Testing: root@bmc-oob:~# boot_info.sh Usage: boot_info.sh reset Examples: boot_info.sh bmc boot_info.sh bmc reset secondary root@bmc-oob:~# boot_info.sh bmc WDT1 Timeout Count: 0 WDT2 Timeout Count: 0 Current Boot Code Source: Primary Flash root@bmc-oob:~# cat /etc/version 20201105194531 root@bmc-oob:~# boot_info.sh bmc reset primary Current boot source is primary, no need to switch. root@bmc-oob:/mnt/data1# boot_info.sh bmc reset secondary BMC will switch to secondary after 2 seconds ... # boot root@bmc-oob:~# boot_info.sh bmc WDT2 Timeout Count: 3 Current Boot Code Source: Secondary Flash root@bmc-oob:~# boot_info.sh bmc reset secondary Current boot source is secondary, no need to switch. root@bmc-oob:~# boot_info.sh bmc reset primary BMC will switch to primary after 2 seconds ... soft reboot kept BMC booting from slave wedge_power.sh reset returned BMC to master NOTE: The secondary spi flash must have a version containing this uboot otherwise the automatic switchover will go back to primary. I recommend upgrading all units to have at lease this change in secondary flash. Pull Request resolved: https://github.com/facebookexternal/openbmc.arista/pull/108 Reviewed By: zhdaniel12 fbshipit-source-id: 986b5eb256 --- .../openbmc-utils/files/boot_info.sh | 124 ++++++++++++++++++ .../openbmc-utils/files/disable_watchdog.sh | 25 ++++ .../openbmc-utils/openbmc-utils_%.bbappend | 6 + 3 files changed, 155 insertions(+) create mode 100644 meta-facebook/meta-elbert/recipes-utils/openbmc-utils/files/boot_info.sh create mode 100644 meta-facebook/meta-elbert/recipes-utils/openbmc-utils/files/disable_watchdog.sh diff --git a/meta-facebook/meta-elbert/recipes-utils/openbmc-utils/files/boot_info.sh b/meta-facebook/meta-elbert/recipes-utils/openbmc-utils/files/boot_info.sh new file mode 100644 index 000000000000..dd91dd1f300d --- /dev/null +++ b/meta-facebook/meta-elbert/recipes-utils/openbmc-utils/files/boot_info.sh @@ -0,0 +1,124 @@ +#!/bin/bash +# +# Copyright 2020-present Facebook. All Rights Reserved. +# +# This program file is free software; you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by the +# Free Software Foundation; version 2 of the License. +# +# This program is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +# for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program in a file named COPYING; if not, write to the +# Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, +# Boston, MA 02110-1301 USA +# + +# shellcheck disable=SC1091 +source /usr/local/bin/openbmc-utils.sh + +usage() { + program=$(basename "$0") + echo "Usage:" + echo " $program reset " + echo "" + echo "Examples:" + echo " $program bmc" + echo " $program bmc reset primary" +} + +FMC_WDT2_CONTROL_REG="0x1E620064" +FMC_WDT2_COUNTER_REG="0x1E620068" +FMC_WDT2_RELOAD_REG="0x1E62006C" + +bmc_boot_info() { + # Please refer to reg FMC WDT1/WDT2 Control Register definition to + # understand this code block, WDT2 is on page 232 of ast2620.pdf + + # get watch dog2 timeout status register + wdt2=$(devmem "$FMC_WDT2_CONTROL_REG") + + wdt2_timeout_cnt=$(( ((wdt2 & 0xff00) >> 8) )) + boot_code_source=$(( ((wdt2 & 0x10) >> 4) )) + + boot_source="Primary Flash" + if [ $boot_code_source -eq 1 ] + then + boot_source="Secondary Flash" + fi + + echo "WDT2 Timeout Count: " $wdt2_timeout_cnt + echo "Current Boot Code Source: $boot_source" +} + +bmc_boot_from() { + # Please refer to reg WDT2 Control Register definition to + # understand this code block, WDT2 is on page 232 of ast2620.pdf + # Enable watchdog reset_system_after_timeout bit and WDT_enable_signal bit. + # Refer to ast2620.pdf page 232. + boot_source=0x00000000 + wdt2=$(devmem "$FMC_WDT2_CONTROL_REG") + boot_code_source=$(( (wdt2 & 0x10) >> 4 )) + + if [ "$1" = "primary" ]; then + if [ $boot_code_source = 0 ]; then + echo "Current boot source is primary, no need to switch." + return 0 + else + # Bit 0 - Enable Watchdog + # Bit 4 - BOOT_SOURCE_PRIMARY_N + boot_source=0x00000001 + fi + elif [ "$1" = "secondary" ]; then + if [ $boot_code_source = 1 ]; then + echo "Current boot source is secondary, no need to switch." + return 0 + else + # Bit 0 - Enable Watchdog + # Bit 4 - BOOT_SOURCE_PRIMARY_N + boot_source=0x00000011 + fi + fi + + echo "BMC will switch to $1 after 2 seconds ..." + # Set WDT time out 2s, 0x00000014 = 2s + devmem "$FMC_WDT2_COUNTER_REG" 32 0x00000014 + # WDT magic number to restart WDT counter to decrease. + devmem "$FMC_WDT2_RELOAD_REG" 32 0x4755 + devmem "$FMC_WDT2_CONTROL_REG" 32 $boot_source +} + +if [ $# -lt 1 ]; then + usage + exit 1 +fi + +case $1 in + "bmc") + if [ $# -eq 1 ]; then + bmc_boot_info + exit 0 + else + if [ "$2" = "reset" ] && [ $# -ge 3 ]; then + case $3 in + "primary" | "secondary") + bmc_boot_from "$3" + exit 0 + ;; + *) + usage + exit 1 + ;; + esac + fi + fi + ;; + *) + usage + exit 1 + ;; +esac diff --git a/meta-facebook/meta-elbert/recipes-utils/openbmc-utils/files/disable_watchdog.sh b/meta-facebook/meta-elbert/recipes-utils/openbmc-utils/files/disable_watchdog.sh new file mode 100644 index 000000000000..9d14afbbe28c --- /dev/null +++ b/meta-facebook/meta-elbert/recipes-utils/openbmc-utils/files/disable_watchdog.sh @@ -0,0 +1,25 @@ +#!/bin/bash +# +# Copyright 2020-present Facebook. All Rights Reserved. +# +# This program file is free software; you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by the +# Free Software Foundation; version 2 of the License. +# +# This program is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +# for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program in a file named COPYING; if not, write to the +# Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, +# Boston, MA 02110-1301 USA +# + +# shellcheck disable=SC1091 +source /usr/local/bin/openbmc-utils.sh + +# Disable the fmc dual boot watch dog +devmem_clear_bit 0x1e620064 0 diff --git a/meta-facebook/meta-elbert/recipes-utils/openbmc-utils/openbmc-utils_%.bbappend b/meta-facebook/meta-elbert/recipes-utils/openbmc-utils/openbmc-utils_%.bbappend index 5000ea4ff385..d139ca291d8e 100644 --- a/meta-facebook/meta-elbert/recipes-utils/openbmc-utils/openbmc-utils_%.bbappend +++ b/meta-facebook/meta-elbert/recipes-utils/openbmc-utils/openbmc-utils_%.bbappend @@ -18,9 +18,11 @@ FILESEXTRAPATHS_prepend := "${THISDIR}/files:" SRC_URI += "file://board-utils.sh \ + file://boot_info.sh \ file://bios_util.sh \ file://fpga_util.sh \ file://fpga_ver.sh \ + file://disable_watchdog.sh \ file://dump_pim_serials.sh \ file://dump_gpios.sh \ file://eth0_mac_fixup.sh \ @@ -47,6 +49,7 @@ SRC_URI += "file://board-utils.sh \ OPENBMC_UTILS_FILES += " \ board-utils.sh \ bios_util.sh \ + boot_info.sh \ fpga_util.sh \ fpga_ver.sh \ dump_pim_serials.sh \ @@ -102,6 +105,9 @@ do_install_board() { install -m 755 setup_board.sh ${D}${sysconfdir}/init.d/setup_board.sh update-rc.d -r ${D} setup_board.sh start 80 S . + install -m 0755 ${WORKDIR}/disable_watchdog.sh ${D}${sysconfdir}/init.d/disable_watchdog.sh + update-rc.d -r ${D} disable_watchdog.sh start 99 2 3 4 5 . + install -m 755 power-on.sh ${D}${sysconfdir}/init.d/power-on.sh update-rc.d -r ${D} power-on.sh start 85 S .