Skip to content

Commit

Permalink
ELBERT: Enable Alternate boot (#108)
Browse files Browse the repository at this point in the history
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 <bmc> reset <primary|secondary>

     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: facebookexternal/openbmc.arista#108

Reviewed By: zhdaniel12

fbshipit-source-id: 986b5eb256
  • Loading branch information
joancaneus authored and facebook-github-bot committed Nov 17, 2020
1 parent 4661c39 commit d66b89a
Show file tree
Hide file tree
Showing 3 changed files with 155 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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 <bmc> reset <primary|secondary>"
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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand All @@ -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 \
Expand Down Expand Up @@ -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 .

Expand Down

0 comments on commit d66b89a

Please sign in to comment.