Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pull request to add bfb installation script to the switch image #5

Closed
wants to merge 11 commits into from
2 changes: 2 additions & 0 deletions files/build_templates/sonic_debian_extension.j2
Original file line number Diff line number Diff line change
Expand Up @@ -1016,6 +1016,8 @@ sudo cp $files_path/$COMPONENT_VERSIONS_FILE $FILESYSTEM_ROOT/etc/mlnx/component
sudo cp $files_path/$MLNX_FFB_SCRIPT $FILESYSTEM_ROOT/usr/bin/mlnx-ffb.sh
sudo cp $files_path/$MLNX_ONIE_FW_UPDATE $FILESYSTEM_ROOT/usr/bin/$MLNX_ONIE_FW_UPDATE
sudo cp $files_path/$MLNX_SSD_FW_UPDATE $FILESYSTEM_ROOT/usr/bin/$MLNX_SSD_FW_UPDATE
sudo cp $files_path/$MLNX_SONIC_BFB_INSTALL $FILESYSTEM_ROOT/usr/bin/$MLNX_SONIC_BFB_INSTALL
sudo cp $files_path/$MLNX_BFB_INSTALL $FILESYSTEM_ROOT/usr/bin/$MLNX_BFB_INSTALL
sudo cp $files_path/$MLNX_INSTALL_PENDING_FW $FILESYSTEM_ROOT/usr/bin/$MLNX_INSTALL_PENDING_FW
sudo mkdir -p $FILESYSTEM_ROOT/etc/mlnx/cpld/
for MLNX_CPLD_ARCHIVE in $MLNX_CPLD_ARCHIVES; do
Expand Down
153 changes: 153 additions & 0 deletions platform/mellanox/bfb-install
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
#!/bin/sh

# Copyright (c) 2020, NVIDIA Corporation
gpunathilell marked this conversation as resolved.
Show resolved Hide resolved
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# 1. Redistributions of source code must retain the above copyright notice, this
# list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
# ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
# The views and conclusions contained in the software and documentation are those
# of the authors and should not be interpreted as representing official policies,
# either expressed or implied, of the FreeBSD Project.

usage ()
{
echo "syntax: bfb-install --bfb|-b <BFBFILE> [--config|-c <bf.cfg>] \\"
echo " [--rootfs|-f <rootfs.tar.xz>] --rshim|-r <rshimN> [--help|-h]"
}

bfb=
cfg=
rootfs=
rshim=

options=`getopt -n bfb-install -o b:c:f:r:h \
-l help,bfb:,config:,rootfs:,rshim: -- "$@"`
eval set -- $options
while [ "$1" != -- ]; do
case $1 in
--help|-h) usage; exit 0 ;;
--bfb|-b) shift; bfb=$1 ;;
--config|-c) shift; cfg=$1 ;;
--rootfs|-f) shift; rootfs=$1 ;;
--rshim|-r) shift; rshim=$1 ;;
esac
shift
done
shift

if [ $# -ne 0 ]; then
usage >&2
exit 1
fi

if [ -z "${bfb}" -o -z "${rshim}" ]; then
echo "Error: Need to provide both bfb file and rshim device name."
usage >&2
exit 1
fi

if [ ! -e "${bfb}" ]; then
echo "Error: ${bfb} not found."
exit 1
fi

if [ ."$(echo "${rshim}" | cut -c1-1)" != ."/" ]; then
rshim="/dev/${rshim}"
fi

if [ ! -e "${rshim}/boot" ]; then
echo "Error: ${rshim}/boot not found."
exit 1
fi

if [ -n "${rootfs}" -a ! -e "${rootfs}" ]; then
echo "Error: ${rootfs} not found."
exit 1
fi

if [ -n "${cfg}" -a ! -e "${cfg}" ]; then
echo "Error: ${cfg} not found."
exit 1
fi

if [ $(id -u) -ne 0 ]; then
echo "Error: Need root permission to push BFB on local host."
exit 1
fi

pv=$(which pv 2>/dev/null)
if [ -z "${pv}" ]; then
echo "Warn: 'pv' command not found. Continue without showing BFB progress."
fi

# Push the boot stream.
echo "Pushing bfb${cfg:+ + cfg}${rootfs:+ + rootfs}"
sh -c "cat ${bfb} ${cfg:+$cfg} ${rootfs:+${rootfs}} ${pv:+| ${pv} | cat -} > ${rshim}/boot"
RETVAL=$?
if [ $RETVAL -ne 0 ]; then
echo "Failed to push BFB"
exit
fi

# Print the rshim log.
echo "Collecting BlueField booting status. Press Ctrl+C to stop…"

last=""
while true; do
last_len=${#last}
cur=$(echo 'DISPLAY_LEVEL 2' > ${rshim}/misc && cat ${rshim}/misc | sed -n '/^ INFO/,$p')
RETVAL=$?
if [ $RETVAL -ne 0 ]; then
echo "Failed to read ${rshim}/misc"
exit
fi
cur_len=${#cur}

sleep 1

# Overwrite if current length smaller than previous length.
if [ ${last_len} -eq 0 -o ${last_len} -gt ${cur_len} ]; then
echo "${cur}" | sed '/^[[:space:]]*$/d'
last="${cur}"
continue
fi

# Overwrite if first portion doesn't match.
sub_cur=$(echo "${cur}" | dd bs=1 count=${last_len} 2>/dev/null)
if [ "${sub_cur}" != "${last}" ]; then
echo "${cur}" | sed '/^[[:space:]]*$/d'
last="${cur}"
continue
fi

# Nothing if no update.
if [ ${last_len} -eq ${cur_len} ]; then
continue;
fi

# Print the diff.
echo "${cur}" | dd bs=1 skip=${last_len} 2>/dev/null | sed '/^[[:space:]]*$/d'
last="${cur}"

if echo ${cur} | grep -Ei "Reboot|finished|DPU is ready" >/dev/null; then
break;
fi
done
34 changes: 34 additions & 0 deletions platform/mellanox/mlnx-sonic-bfb-installer.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#
# Copyright (c) 2020-2021 NVIDIA CORPORATION & AFFILIATES.
# Apache-2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# ssd update tool
gpunathilell marked this conversation as resolved.
Show resolved Hide resolved

MLNX_SONIC_BFB_INSTALL = sonic-bfb-installer
$(MLNX_SONIC_BFB_INSTALL)_PATH = $(PLATFORM_PATH)/

gpunathilell marked this conversation as resolved.
Show resolved Hide resolved
MLNX_BFB_INSTALL = bfb-install
$(MLNX_BFB_INSTALL)_PATH = $(PLATFORM_PATH)/

MLNX_BFB_FILES = $(MLNX_BFB_INSTALL) $(MLNX_SONIC_BFB_INSTALL)


SONIC_COPY_FILES += $(MLNX_BFB_FILES)


MLNX_FILES += $(MLNX_BFB_FILES)

export MLNX_SONIC_BFB_INSTALL
export MLNX_BFB_INSTALL
1 change: 1 addition & 0 deletions platform/mellanox/rules.mk
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ include $(PLATFORM_PATH)/iproute2.mk
include $(PLATFORM_PATH)/install-pending-fw.mk
include $(PLATFORM_PATH)/integration-scripts.mk
include $(PLATFORM_PATH)/component-versions.mk
include $(PLATFORM_PATH)/mlnx-sonic-bfb-installer.mk

SONIC_ALL += $(SONIC_ONE_IMAGE) \
$(DOCKER_FPM)
Expand Down
114 changes: 114 additions & 0 deletions platform/mellanox/sonic-bfb-installer
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
#!/bin/bash
command_name="sonic-bfb-installer"
usage(){
echo "Syntax: $command_name -b|--bfb <BFB_Image_Path> --rshim|-r <rshim1,..rshimN> --verbose|-v --config|-c <Options> --help|h"
echo "Arguments:"
echo "-b Provide custom path for bfb image"
echo "-r Install only on DPUs connected to rshim interfaces provided, mention all if installation is requried on all connected DPUs"
echo "-v Verbose installation result output"
echo "-c Config file"
echo "-h Help"
}

bfb_install_call(){
#Example:sudo bfb-install -b <full path to image> -r rshim<id>
local result_file=$(mktemp "/tmp/result_file.XXXXX")
local cmd="sudo ./bfb-install -b $2 -r $1 $appendix"
gpunathilell marked this conversation as resolved.
Show resolved Hide resolved
echo "Installing bfb image on DPU connected to $1 using $cmd"
local indicator="$1:"
eval "$cmd" > "$result_file" 2>&1 > >(while IFS= read -r line; do echo "$indicator $line"; done > "$result_file")
gpunathilell marked this conversation as resolved.
Show resolved Hide resolved
local exit_status=$?
if [ $exit_status -ne 0 ]; then
echo "$1: Error: Installation failed on connected DPU!"
else
echo "$1: Installation Successful"
fi
if [ $exit_status -ne 0 ] ||[ $verbose = true ]; then
cat "$result_file"
fi
rm -f "$result_file"
gpunathilell marked this conversation as resolved.
Show resolved Hide resolved
}

validate_rshim(){
local provided_list=("$@")
for item1 in "${provided_list[@]}"; do
local found=0
for item2 in "${dev_names_det[@]}"; do
if [[ "$item1" = "$item2" ]]; then
found=1
break
fi
done
if [[ $found -eq 0 ]]; then
echo "$item1 is not detected! Please provide proper rshim interface list!"
exit 1
fi
done
}

main(){
local config=
while [ "$1" != "--" ] && [ -n "$1" ]; do
case $1 in
--help|-h)
usage;
exit 0
;;
--bfb|-b)
shift;
bfb=$1
;;
--rshim|-r)
shift;
rshim_dev=$1
;;
--config|-c)
shift;
config=$1
;;
--verbose|-v)
verbose=true
;;
esac
shift
done
if [ -z "$bfb" ]; then
echo "Error : bfb image is not provided."
usage
exit 1
fi
if [[ -f ${config} ]]; then
echo "Using ${config} file"
appendix="-c ${config}"
fi
IFS=$'\n'
dev_names_det+=($(ls /dev/rshim* | awk -F'/' '/^\/dev\/rshim/ {gsub(/:/,"",$NF); print $NF}'))
if [ "${#dev_names_det[@]}" -eq 0 ]; then
echo "No rshim interfaces detected! Make sure to run the $command_name script from the host device/ switch!"
exit 1
fi
if [ -z "$rshim_dev" ]; then
echo "No rshim interfaces provided!"
usage
exit 1
else
if [ "$rshim_dev" = "all" ]; then
dev_names=("${dev_names_det[@]}")
echo "${#dev_names_det[@]} rshim interfaces detected:"
echo "${dev_names_det[@]}"
else
IFS=',' read -ra dev_names <<< "$rshim_dev"
validate_rshim $dev_names
fi
fi
for i in "${dev_names[@]}"
do
:
bfb_install_call $i $bfb &
gpunathilell marked this conversation as resolved.
Show resolved Hide resolved
done
wait
}

appendix=
verbose=false
main "$@"