Skip to content

Commit

Permalink
Factor FW finding logic into separate script (#43)
Browse files Browse the repository at this point in the history
The logic for finding firmware archives turns out to be useful outside
of bfvcheck, so factor it into its own script. For now, it will be used
in two places: bfvcheck, and firmware installation testing.
  • Loading branch information
sl-mlx authored Jul 31, 2020
1 parent 47a23f8 commit ce84a23
Show file tree
Hide file tree
Showing 6 changed files with 151 additions and 75 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Overview of each file:
- **bfcpu-freq** Display Arm core frequency.
- **bfdracut** Create an initramfs.
- **bffamily** Display the BlueField family for the particular board.
- **bfhcafw** Utilities for managing ConnectX firmware.
- **bfinst** Simple installation script for both the bootloader and a root file
system.
- **bfpxe** PXE boot helper script.
Expand Down
125 changes: 125 additions & 0 deletions bfhcafw
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
#!/bin/sh -e

# Copyright (c) 2020, Mellanox Technologies
# 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 () {
cat >&2 <<EOF
usage: bfhcafw [-h|--help] find
Various utilities for ConnectX firmware on BlueField systems. Currently there
is only one command: find, which searches the filesystem for the correct
ConnectX firmware image for the current system and prints the full path to it.
EOF
}

err () {
echo "bfhcafw: $@" >&2
}

BASE_FW_NAME=mlxfwmanager_sriov_dis_aarch64

# Set mlxfw filename based on current system
set_mlxfw_name () {
if ! command -v mst >/dev/null; then
err "warn: cannot find mst"
return 1
fi

mst start 1>&2
pciconf=$(find /dev/mst -name *_pciconf0 -exec basename {} \;)

if [ -z "$pciconf" ]; then
err "warn: cannot find mst device"
return 1
fi

# Should replace with general solution later, but there are only
# two HW versions right now.
case $pciconf in
mt41682_pciconf0)
# BF1
chipnum=41682
;;
mt41686_pciconf0)
# BF2
chipnum=41686
;;
*)
err "warn: cannot determine HW version"
return 1
esac

mlxfw_name="${BASE_FW_NAME}_${chipnum}"
}

# Finds the FW file on the system and sets $mlxfw accordingly.
# Returns 1 if not found, 0 otherwise.
find_fw_with_name () {
# find the firmware package on the system
mlxfw="/opt/mellanox/mlnx-fw-updater/firmware/${mlxfw_name}"
[ -f $mlxfw ] && return 0

# FW package not in /opt/mellanox, we're probably running on yocto
mlxfw="/lib/firmware/mellanox/${mlxfw_name}"
[ -f $mlxfw ] && return 0

return 1
}

find_fw () {
if set_mlxfw_name; then
# If name set succeeds, we try once with the new name, and then if that
# doesn't work, continue to legacy check.
find_fw_with_name && return 0
fi

err "warn: falling back to legacy FW filename"
mlxfw_name="$BASE_FW_NAME"
find_fw_with_name && return 0

return 1
}

if [ "$1" = "-h" ] || [ "$1" = "--help" ]; then
usage
exit 0
fi

if [ "$1" = "find" ]; then
if find_fw; then
echo "$mlxfw"
exit 0
else
err "err: the firmware package could not be located"
exit 1
fi
else
err "err: unknown cmd"
usage
exit 1
fi
76 changes: 2 additions & 74 deletions bfvcheck
Original file line number Diff line number Diff line change
Expand Up @@ -32,81 +32,9 @@ echo "Beginning version check..."
# bfb file used to extract ATF/UEFI's expected version information
BOOTIMG_LOCATION=/lib/firmware/mellanox/boot/default.bfb

BASE_FW_NAME=mlxfwmanager_sriov_dis_aarch64
mlxfw=$(bfhcafw find)

# Set mlxfw filename based on current system, or
set_mlxfw_name () {
if ! command -v mst >/dev/null; then
echo "bfvcheck: cannot find mst"
return 1
fi

mst start
pciconf=$(find /dev/mst -name *_pciconf0 -exec basename {} \;)

if [ -z "$pciconf" ]; then
echo "bfvcheck: cannot find mst device"
return 1
fi

# Should replace with general solution later, but there are only
# two HW versions right now.
case $pciconf in
mt41682_pciconf0)
# BF1
chipnum=41682
;;
mt41686_pciconf0)
# BF2
chipnum=41686
;;
*)
echo "bfvcheck: cannot determine HW version"
return 1
esac

mlxfw_name="${BASE_FW_NAME}_${chipnum}"
}

# Finds the FW file on the system and sets $mlxfw accordingly.
# Returns 1 if not found, 0 otherwise.
find_fw_with_name () {
# find the firmware package on the system
mlxfw="/opt/mellanox/mlnx-fw-updater/firmware/${mlxfw_name}"

if [ -f $mlxfw ]; then
return 0
else
# FW package not in /opt/mellanox, we're probably running on yocto
mlxfw="/lib/firmware/mellanox/${mlxfw_name}"
fi

if [ -f $mlxfw ]; then
return 0
else
return 1
fi
}

find_fw () {
if set_mlxfw_name; then
# If name set succeeds, we try once with the new name, and then if that
# doesn't work, continue to legacy check.
if find_fw_with_name; then
return 0
fi
fi

echo "bfvcheck: warning: falling back to legacy FW filename"
mlxfw_name="$BASE_FW_NAME"
if find_fw_with_name; then
return 0
fi

return 1
}

if ! find_fw; then
if [ "$?" -ne 0 ]; then
# FW package not found anywhere, so error out fw check
# We keep going to check bootloader versions anyway.
echo "The firmware package could not be located."
Expand Down
2 changes: 1 addition & 1 deletion debian/mlxbf-scripts.install
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
bfauxpwr bfbootmgr bfcfg bfcpu-freq bfdracut bffamily bfinst usr/bin/
bfpart bfpxe bfrec bfsbkeys bfvcheck bfver mlx-mkbfb usr/bin/
bfpart bfpxe bfrec bfsbkeys bfvcheck bfver mlx-mkbfb bfhcafw usr/bin/
bfvcheck.service lib/systemd/system/
20 changes: 20 additions & 0 deletions man/bfhcafw.8
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
.TH BFFINDFW 8 "July 2020"
.SH NAME
bfhcafw \- Utilities for BlueField ConnectX firmware
.SH SYNOPSIS
.B bfhcafw
.RB [ \-\-help | \-h ]
.PP
.B bfhcafw
find
.SH DESCRIPTION
A collection of utilities for managing ConnectX firmware on BlueField systems.
The functionality of this utility is divided into commands, of which there is
currently only one:
.IP find
Searches the filesystem for the ConnectX firmware distribution appropriate
for the current BlueField hardware revision and linux distribution, and prints
the absolute file path to stdout.
.SH OPTIONS
.IP "-h | --help"
Print a short help message.
2 changes: 2 additions & 0 deletions mlxbf-bfscripts.spec.rpkg
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ install -p bfver %{installdir}
install -p man/bfver.8 %{man8dir}
install -p bfauxpwr %{installdir}
install -p man/bfauxpwr.8 %{man8dir}
install -p bfhcafw %{installdir}
install -p man/bfhcafw.8 %{man8dir}

install -p mlx-mkbfb %{installdir}
install -p man/mlx-mkbfb.1 %{man1dir}
Expand Down

0 comments on commit ce84a23

Please sign in to comment.