From 36ac5024f90f2370a419e2270a1cd4a52513d351 Mon Sep 17 00:00:00 2001 From: Stepan Blyschak Date: Tue, 28 Aug 2018 14:38:27 +0300 Subject: [PATCH] [mellanox] Enhance mlnx-fw-upgrade.sh Install a new FW by specifying FW path (mlnx-fw-upgrade.sh /path/to/FW) or use default at '/etc/mlnx/fw-SPC.mfa' Signed-off-by: Stepan Blyschak --- platform/mellanox/mlnx-fw-upgrade.j2 | 65 ++++++++++++++++++---------- 1 file changed, 43 insertions(+), 22 deletions(-) diff --git a/platform/mellanox/mlnx-fw-upgrade.j2 b/platform/mellanox/mlnx-fw-upgrade.j2 index ec002497ebd8..4e7a4a77b6aa 100755 --- a/platform/mellanox/mlnx-fw-upgrade.j2 +++ b/platform/mellanox/mlnx-fw-upgrade.j2 @@ -23,25 +23,46 @@ while [[ (${query_retry_count} -lt ${query_retry_count_max}) && ($? -ne "0") ]]; ${query_cmd} > /dev/null done -run_or_fail "${query_cmd}" > /tmp/mlnxfwmanager-query.txt - -# get current firmware version and required version -fw_info=$(grep FW /tmp/mlnxfwmanager-query.txt) -fw_current=$(echo $fw_info | cut -f2 -d' ') - -if [[ -z ${fw_current} ]]; then - echo "Could not retreive current FW version." - exit 1 -fi - -if [[ -z ${fw_required} ]]; then - echo "Could not retreive required FW version." - exit 1 -fi - -if [[ ${fw_current} == ${fw_required} ]]; then - echo "Mellanox firmware is up to date." -else - echo "Mellanox firmware required version is ${fw_required}. Installing compatible version..." - run_or_fail "mlxfwmanager -i ${fw_file} -u -f -y" -fi +function upgrade() { + if [ ! -z "$1" ]; then + fw_file="$1" + if [ ! -f "$fw_file" ]; then + >&2 echo "No such file: $fw_file" + exit 1 + fi + + run_or_fail "${query_cmd} -i ${fw_file}" > /tmp/mlnxfwmanager-query.txt + + # get current firmware version and available version from $fw_file + fw_info=$(grep FW /tmp/mlnxfwmanager-query.txt) + fw_current=$(echo $fw_info | cut -f2 -d' ') + fw_available=$(echo $fw_info | cut -f3 -d' ') + + fw_required=$fw_available + else + run_or_fail "${query_cmd}" > /tmp/mlnxfwmanager-query.txt + + # get current firmware version and required version + fw_info=$(grep FW /tmp/mlnxfwmanager-query.txt) + fw_current=$(echo $fw_info | cut -f2 -d' ') + fi + + if [[ -z ${fw_current} ]]; then + echo "Could not retreive current FW version." + exit 1 + fi + + if [[ -z ${fw_required} ]]; then + echo "Could not retreive required FW version." + exit 1 + fi + + if [[ ${fw_current} == ${fw_required} ]]; then + echo "Mellanox firmware is up to date." + else + echo "Mellanox firmware required version is ${fw_required}. Installing compatible version..." + run_or_fail "mlxfwmanager -i ${fw_file} -u -f -y" + fi +} + +upgrade "$1"