Skip to content

Commit

Permalink
Added bf-upgrade environment
Browse files Browse the repository at this point in the history
Supported ATF/UEFI capsule update, BMC/CEC firmware upgrade and NIC
firmware golden image upgrade.

Signed-off-by: Vladimir Sokolovsky <vlad@nvidia.com>
  • Loading branch information
vladsokolovsky committed Sep 11, 2024
1 parent 2b421fb commit d26fa80
Show file tree
Hide file tree
Showing 7 changed files with 984 additions and 50 deletions.
3 changes: 3 additions & 0 deletions bf-release.spec
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ install -m 0644 src/mlnx-ovs.conf %{buildroot}/etc/mellanox
install -d %{buildroot}/etc/acpi/actions/
install -m 0755 src/rebootcontrol %{buildroot}/etc/acpi/actions/
install -m 0755 src/bf-upgrade %{buildroot}/etc/acpi/actions/
cp -a src/bf-upgrade.env %{buildroot}/etc/acpi/actions/

install -d %{buildroot}/etc/acpi/events/
install -m 0644 src/mlnx-powerconf %{buildroot}/etc/acpi/events/
Expand Down Expand Up @@ -321,6 +322,8 @@ fi
%dir /etc/acpi/actions/
/etc/acpi/actions/rebootcontrol
/etc/acpi/actions/bf-upgrade
%dir /etc/acpi/actions/bf-upgrade.env
/etc/acpi/actions/bf-upgrade.env/*

%dir /etc/systemd/logind.conf.d/
/etc/systemd/logind.conf.d/lid.conf
Expand Down
1 change: 1 addition & 0 deletions debian/rules
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ endif
dh_installdirs -p$(pname) etc/acpi/actions
install -m 0755 src/rebootcontrol debian/$(pname)/etc/acpi/actions
install -m 0755 src/bf-upgrade debian/$(pname)/etc/acpi/actions
cp -a src/bf-upgrade.env debian/$(pname)/etc/acpi/actions
dh_installdirs -p$(pname) etc/acpi/events
install -m 0644 src/mlnx-powerconf debian/$(pname)/etc/acpi/events
install -m 0644 src/mlnx-lidconf debian/$(pname)/etc/acpi/events
Expand Down
160 changes: 110 additions & 50 deletions src/bf-upgrade
Original file line number Diff line number Diff line change
@@ -1,35 +1,64 @@
#!/bin/bash
###############################################################################
#
# Copyright 2024 NVIDIA Corporation
#
# Permission is hereby granted, free of charge, to any person obtaining a copy of
# this software and associated documentation files (the "Software"), to deal in
# the Software without restriction, including without limitation the rights to
# use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
# the Software, and to permit persons to whom the Software is furnished to do so,
# subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
# FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
# COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
# IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#
###############################################################################

# Maximum idle time in seconds to decide no more data from BOOTFIFO.
IDLE_MAX=5

# Source a configuration if exists.
[ -f /etc/bf-upgrade.conf ] && source /etc/bf-upgrade.conf

SCRIPTS_DIR=$(dirname $0)


[ ! -e /proc/acpi/button/lid/LID/state ] && exit 0

BOOTFIFO="/sys/bus/platform/devices/MLNXBF04:00/driver/bootfifo"
if [ ! -e "$BOOTFIFO" ]; then
BOOTFIFO="/sys/devices/platform/MLNXBF04:00/bootfifo"
[ ! -e "$BOOTFIFO" ] && exit -1
[ ! -e "$BOOTFIFO" ] && exit 1
fi

WDIR=${WDIR:-"/tmp/bfb"}
mkdir -p ${WDIR}

# Only handles upgrade in closed state.
state=`cat /proc/acpi/button/lid/LID/state | awk '{print $2}' 2>/dev/null`
[ $state != "closed" ] && exit 0
state=$(cat /proc/acpi/button/lid/LID/state | awk '{print $2}' 2>/dev/null)
[ "$state" != "closed" ] && exit 0

# Add a delay for the boot-fifo to be filled.
sleep $IDLE_MAX

# Example code to fetch the upgrade bfb.
# !!!Use eMMC or NVME to avoid running out of memory in NIC mode.!!!
UPGRADE_IMAGE=/tmp/upgrade.bfb
UPGRADE_IMAGE=${WDIR}/upgrade.bfb
rm -f ${UPGRADE_IMAGE}* 2>/dev/null

idle_cnt=0
while [ $idle_cnt -lt $IDLE_MAX ]; do
cat "$BOOTFIFO" > ${UPGRADE_IMAGE}.tmp
filesize=`du -b ${UPGRADE_IMAGE}.tmp | awk '{print $1}'`
if [ -z "$filesize" -o ."$filesize" == ."0" ]; then
filesize=$(du -b ${UPGRADE_IMAGE}.tmp | awk '{print $1}')
if [[ -z "$filesize" || ."$filesize" == ."0" ]]; then
# Done if no more data in 5 seconds.
idle_cnt=$((idle_cnt + 1))
sleep 1
Expand All @@ -39,58 +68,89 @@ while [ $idle_cnt -lt $IDLE_MAX ]; do
fi
done

# Get the upgrade image.
rm -f ${UPGRADE_IMAGE}.tmp 2>/dev/null
cd /tmp
rm -f dump-upgrade-image-v0 2>/dev/null
mlx-mkbfb -x -n upgrade-image-v0 ${UPGRADE_IMAGE}
/bin/rm -f ${UPGRADE_IMAGE}.tmp
cd ${WDIR}
/bin/rm -f dump-*

mlx-mkbfb -x ${UPGRADE_IMAGE}
rm -f ${UPGRADE_IMAGE}

if [ ! -e upgrade-image-v0 ]; then
bfrshlog "Error: No upgrade image found"
exit 1
# dump-boot-args-v0 - bf.cfg
# dump-capsule-v0 - BSP upgrade capsule
# dump-image-v0 - BMC firmware image
# dump-upgrade-image-v0 - CEC upgrade image
# dump-ramdisk-v0 - NIC firmware Golden Image

if ( bash -n dump-boot-args-v0 ); then
bfrshlog "Found bf.cfg"
. dump-boot-args-v0
fi

# Include scripts that provide upgrade infrastructure
if (bash -n ${SCRIPTS_DIR}/bf-upgrade.env/common 2>/dev/null); then
. ${SCRIPTS_DIR}/bf-upgrade.env/common
fi

if (bash -n ${SCRIPTS_DIR}/bf-upgrade.env/atf-uefi 2>/dev/null); then
. ${SCRIPTS_DIR}/bf-upgrade.env/atf-uefi
fi

case "$(file --brief --mime-type upgrade-image-v0)" in
application/gzip)
app=gzip
;;
application/zstd)
app=zstd
;;
*)
app=gzip
;;
esac

mkdir image
cd image
$app -d < ../upgrade-image-v0 | cpio -id

install_sh=$(/bin/ls -1 */install.sh 2> /dev/null)

if [ -z $install_sh ]; then
echo "Error: No installation script found"
cd ..
/bin/rm -rf image
echo "upgrade-image-v0 not supported"
exit 1
if (bash -n ${SCRIPTS_DIR}/bf-upgrade.env/nic-fw 2>/dev/null); then
. ${SCRIPTS_DIR}/bf-upgrade.env/nic-fw
fi

mount --bind /dev dev
mount --bind /sys sys
mount --bind /proc proc
if (bash -n ${SCRIPTS_DIR}/bf-upgrade.env/bmc 2>/dev/null); then
. ${SCRIPTS_DIR}/bf-upgrade.env/bmc
fi

if [ -e /etc/bf.cfg ]; then
cp /etc/bf.cfg etc/
if [ "$UPDATE_ATF_UEFI" == "yes" ]; then
if [ -e dump-capsule-v0 ]; then
if function_exists update_atf_uefi; then
update_atf_uefi $(readlink -f dump-capsule-v0)
else
log "ERROR: BSP upgrade function does not exist"
fi
else
log "ERROR: BSP upgrade capsule dump-capsule-v0 was not found"
UPDATE_ATF_UEFI="no"
fi
fi

chroot . /$install_sh
if [ "$UPDATE_BMC_FW" == "yes" ]; then
if [ -e dump-image-v0 ]; then
BMC_IMAGE=$(readlink -f dump-image-v0)
else
log "ERROR: BMC firmware dump-image-v0 was not found"
UPDATE_BMC_FW="no"
fi
fi

if [ "$UPDATE_CEC_FW" == "yes" ]; then
if [ -e dump-upgrade-image-v0 ]; then
CEC_IMAGE=$(readlink -f dump-upgrade-image-v0)
else
log "ERROR: CEC firmware dump-upgrade-image-v0 was not found"
UPDATE_CEC_FW="no"
fi
fi

if [ "$UPDATE_NIC_FW_GOLDEN_IMAGE" == "yes" ]; then
if [ -e dump-ramdisk-v0 ]; then
NIC_FW_GOLDEN_IMAGE=$(readlink -f dump-ramdisk-v0)
else
# log "ERROR: NIC firmware golden image dump-upgrade-image-v0 was not found"
UPDATE_NIC_FW_GOLDEN_IMAGE="no"
fi
fi

if function_exists update_atf_uefi; then
bmc_components_update
else
log "ERROR: BMC upgrade function does not exist"
fi

umount /proc
umount /sys
umount /dev
cd ${WDIR}
/bin/rm -f dump-*

bfrshlog "Runtime upgrade finished"
sleep 3
reboot -f
log "Runtime upgrade finished"
sleep 3
19 changes: 19 additions & 0 deletions src/bf-upgrade.env/atf-uefi
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
update_atf_uefi()
{
if function_exists pre_update_atf_uefi; then
log "INFO: Running pre_update_atf_uefi from bf.cfg"
pre_update_atf_uefi
fi

if [ ! -d /sys/firmware/efi/efivars ]; then
mount -t efivarfs none /sys/firmware/efi/efivars
fi

ilog "Updating ATF/UEFI:"
ilog "$(bfrec --capsule $1 2>&1)"

if function_exists post_update_atf_uefi; then
log "INFO: Running post_update_atf_uefi from bf.cfg"
post_update_atf_uefi
fi
}
Loading

0 comments on commit d26fa80

Please sign in to comment.