diff --git a/platform/mellanox/mlnx-fw-upgrade.j2 b/platform/mellanox/mlnx-fw-upgrade.j2 index 3caaa8bbc685..86fd32e6a89a 100755 --- a/platform/mellanox/mlnx-fw-upgrade.j2 +++ b/platform/mellanox/mlnx-fw-upgrade.j2 @@ -40,6 +40,7 @@ declare -rA FW_FILE_MAP=( \ ) IMAGE_UPGRADE="${NO_PARAM}" +SYSLOG_LOGGER="${NO_PARAM}" VERBOSE_LEVEL="${VERBOSE_MIN}" function PrintHelp() { @@ -48,7 +49,8 @@ function PrintHelp() { echo echo "OPTIONS:" echo " -u, --upgrade Upgrade ASIC firmware using next boot image (useful after SONiC-To-SONiC update)" - echo " -v, --verbose Verbose mode" + echo " -s, --syslog Use syslog logger (enabled when -u|--upgrade)" + echo " -v, --verbose Verbose mode (enabled when -u|--upgrade)" echo " -h, --help Print help" echo echo "Examples:" @@ -63,10 +65,14 @@ function ParseArguments() { case "$1" in -u|--upgrade) IMAGE_UPGRADE="${YES_PARAM}" + SYSLOG_LOGGER="${YES_PARAM}" ;; -v|--verbose) VERBOSE_LEVEL="${VERBOSE_MAX}" ;; + -s|--syslog) + SYSLOG_LOGGER="${YES_PARAM}" + ;; -h|--help) PrintHelp exit "${EXIT_SUCCESS}" @@ -79,6 +85,11 @@ function ParseArguments() { function LogError() { if [[ "${VERBOSE_LEVEL}" -ge "${VERBOSE_ERROR}" ]]; then echo "ERROR: $*" + logger -p "ERROR" -t "${SCRIPT_NAME}" "$*" + fi + + if [[ "${SYSLOG_LOGGER}" = "${YES_PARAM}" ]]; then + logger -p "ERROR" -t "${SCRIPT_NAME}" "$*" fi } @@ -86,18 +97,30 @@ function LogWarning() { if [[ "${VERBOSE_LEVEL}" -ge "${VERBOSE_WARNING}" ]]; then echo "WARNING: $*" fi + + if [[ "${SYSLOG_LOGGER}" = "${YES_PARAM}" ]]; then + logger -p "WARNING" -t "${SCRIPT_NAME}" "$*" + fi } function LogNotice() { if [[ "${VERBOSE_LEVEL}" -ge "${VERBOSE_NOTICE}" ]]; then echo "NOTICE: $*" fi + + if [[ "${SYSLOG_LOGGER}" = "${YES_PARAM}" ]]; then + logger -p "NOTICE" -t "${SCRIPT_NAME}" "$*" + fi } function LogInfo() { if [[ "${VERBOSE_LEVEL}" -ge "${VERBOSE_INFO}" ]]; then echo "INFO: $*" fi + + if [[ "${SYSLOG_LOGGER}" = "${YES_PARAM}" ]]; then + logger -p "INFO" -t "${SCRIPT_NAME}" "$*" + fi } function ExitFailure() { @@ -186,6 +209,23 @@ function RunCmd() { fi } +function RunFwUpdateCmd() { + local ERROR_CODE="${EXIT_SUCCESS}" + local COMMAND="${BURN_CMD} $@" + + if [[ "${VERBOSE_LEVEL}" -eq "${VERBOSE_MAX}" ]]; then + output=$(eval "${COMMAND}") + else + output=$(eval "${COMMAND}") >/dev/null 2>&1 + fi + + ERROR_CODE="$?" + if [[ "${ERROR_CODE}" != "${EXIT_SUCCESS}" ]]; then + failure_msg="${output#*Fail : }" + ExitFailure "FW Update command: ${COMMAND} failed with error: ${failure_msg}" + fi +} + function UpgradeFW() { local -r _FS_MOUNTPOINT="$1" @@ -229,9 +269,9 @@ function UpgradeFW() { local -r _MST_DEVICE="$(GetMstDevice)" if [[ "${_MST_DEVICE}" = "${UNKN_MST}" ]]; then LogWarning "could not find fastest mst device, using default device" - RunCmd "${BURN_CMD} -i ${_FW_FILE}" + RunFwUpdateCmd "-i ${_FW_FILE}" else - RunCmd "${BURN_CMD} -d ${_MST_DEVICE} -i ${_FW_FILE}" + RunFwUpdateCmd "-d ${_MST_DEVICE} -i ${_FW_FILE}" fi fi }