From 2979f81a81ae21c5bba4ba5af27dde3bb6ac59d3 Mon Sep 17 00:00:00 2001 From: Stepan Blyschak Date: Wed, 8 Feb 2023 18:58:45 +0200 Subject: [PATCH 1/3] [nvidia] Place FW binaries under platform directory instead of squashfs Upgrade from old image always requires squashfs mount to get the next image FW binary. This can be avoided if we put FW binary under platform directory which is easily accessible after installation: ``` admin@r-spider-05:~$ ls /host/image-fw-new-loc.0-dirty-20230208.193534/platform/fw-SPC.mfa /host/image-fw-new-loc.0-dirty-20230208.193534/platform/fw-SPC.mfa admin@r-spider-05:~$ ls -al /tmp/image-fw-new-loc.0-dirty-20230208.193534-fs/etc/mlnx/fw-SPC.mfa lrwxrwxrwx 1 root root 66 Feb 8 17:57 /tmp/image-fw-new-loc.0-dirty-20230208.193534-fs/etc/mlnx/fw-SPC.mfa -> /host/image-fw-new-loc.0-dirty-20230208.193534/platform/fw-SPC.mfa ``` Signed-off-by: Stepan Blyschak --- .../build_templates/sonic_debian_extension.j2 | 18 ++++++--- platform/mellanox/mlnx-fw-upgrade.j2 | 37 +++++++++++++------ 2 files changed, 38 insertions(+), 17 deletions(-) diff --git a/files/build_templates/sonic_debian_extension.j2 b/files/build_templates/sonic_debian_extension.j2 index 8edf79553d7e..cbd8faf8620e 100644 --- a/files/build_templates/sonic_debian_extension.j2 +++ b/files/build_templates/sonic_debian_extension.j2 @@ -928,11 +928,19 @@ sudo cp {{src}} $FILESYSTEM_ROOT/{{dst}} {% endfor -%} {% if sonic_asic_platform == "mellanox" %} -sudo mkdir -p $FILESYSTEM_ROOT/etc/mlnx/ -sudo cp $files_path/$MLNX_SPC_FW_FILE $FILESYSTEM_ROOT/etc/mlnx/fw-SPC.mfa -sudo cp $files_path/$MLNX_SPC2_FW_FILE $FILESYSTEM_ROOT/etc/mlnx/fw-SPC2.mfa -sudo cp $files_path/$MLNX_SPC3_FW_FILE $FILESYSTEM_ROOT/etc/mlnx/fw-SPC3.mfa -sudo cp $files_path/$MLNX_SPC4_FW_FILE $FILESYSTEM_ROOT/etc/mlnx/fw-SPC4.mfa +declare -rA FW_FILE_MAP=( \ + [$MLNX_SPC_FW_FILE]="fw-SPC.mfa" \ + [$MLNX_SPC2_FW_FILE]="fw-SPC2.mfa" \ + [$MLNX_SPC3_FW_FILE]="fw-SPC3.mfa" \ + [$MLNX_SPC4_FW_FILE]="fw-SPC4.mfa" \ +) +sudo mkdir -p $FILESYSTEM_ROOT/$PLATFORM_DIR/fw/asic/ +sudo mkdir -p $FILESYSTEM_ROOT_ETC/mlnx/ +for fw_file_name in ${!FW_FILE_MAP[@]}; do + sudo cp $files_path/$fw_file_name $FILESYSTEM_ROOT/$PLATFORM_DIR/${FW_FILE_MAP[$fw_file_name]} + # Link old FW location to not break existing automation/scripts + sudo ln -s /host/image-$SONIC_IMAGE_VERSION/$PLATFORM_DIR/${FW_FILE_MAP[$fw_file_name]} $FILESYSTEM_ROOT/etc/mlnx/${FW_FILE_MAP[$fw_file_name]} +done sudo cp $files_path/$ISSU_VERSION_FILE $FILESYSTEM_ROOT/etc/mlnx/issu-version 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 diff --git a/platform/mellanox/mlnx-fw-upgrade.j2 b/platform/mellanox/mlnx-fw-upgrade.j2 index 86fd32e6a89a..89447b02f193 100755 --- a/platform/mellanox/mlnx-fw-upgrade.j2 +++ b/platform/mellanox/mlnx-fw-upgrade.j2 @@ -33,10 +33,10 @@ declare -r UNKN_ASIC="unknown" declare -r UNKN_MST="unknown" declare -rA FW_FILE_MAP=( \ - [$SPC1_ASIC]="/etc/mlnx/fw-SPC.mfa" \ - [$SPC2_ASIC]="/etc/mlnx/fw-SPC2.mfa" \ - [$SPC3_ASIC]="/etc/mlnx/fw-SPC3.mfa" \ - [$SPC4_ASIC]="/etc/mlnx/fw-SPC4.mfa" \ + [$SPC1_ASIC]="fw-SPC.mfa" \ + [$SPC2_ASIC]="fw-SPC2.mfa" \ + [$SPC3_ASIC]="fw-SPC3.mfa" \ + [$SPC4_ASIC]="fw-SPC4.mfa" \ ) IMAGE_UPGRADE="${NO_PARAM}" @@ -227,17 +227,17 @@ function RunFwUpdateCmd() { } function UpgradeFW() { - local -r _FS_MOUNTPOINT="$1" + local -r _FW_BIN_PATH="$1" local -r _ASIC_TYPE="$(GetAsicType)" if [[ "${_ASIC_TYPE}" = "${UNKN_ASIC}" ]]; then ExitFailure "failed to detect ASIC type" fi - if [ ! -z "${_FS_MOUNTPOINT}" ]; then - local -r _FW_FILE="${_FS_MOUNTPOINT}/${FW_FILE_MAP[$_ASIC_TYPE]}" + if [ ! -z "${_FW_BIN_PATH}" ]; then + local -r _FW_FILE="${_FW_BIN_PATH}/${FW_FILE_MAP[$_ASIC_TYPE]}" else - local -r _FW_FILE="${FW_FILE_MAP[$_ASIC_TYPE]}" + local -r _FW_FILE="/etc/mlnx/${FW_FILE_MAP[$_ASIC_TYPE]}" fi if [ ! -f "${_FW_FILE}" ]; then @@ -280,16 +280,29 @@ function UpgradeFWFromImage() { local -r _NEXT_SONIC_IMAGE="$(sonic-installer list | grep "Next: " | cut -f2 -d' ')" local -r _CURRENT_SONIC_IMAGE="$(sonic-installer list | grep "Current: " | cut -f2 -d' ')" - local -r _FS_PATH="/host/image-${_NEXT_SONIC_IMAGE#SONiC-OS-}/fs.squashfs" - local -r _FS_MOUNTPOINT="/tmp/image-${_NEXT_SONIC_IMAGE#SONiC-OS-}-fs" - if [[ "${_CURRENT_SONIC_IMAGE}" == "${_NEXT_SONIC_IMAGE}" ]]; then ExitSuccess "firmware is up to date" + fi + + # /host/image-/platform/fw/asic is now the new location for FW binaries. + # Prefere this path and if it does not exist use squashfs as a fallback. + local -r _NEXT_IMAGE_FW_BIN_PATH="/host/image-${_NEXT_SONIC_IMAGE#SONiC-OS-}/platform/fw/asic/" + + if [[ -d "${_NEXT_IMAGE_FW_BIN_PATH}" ]]; then + LogInfo "Using FW binaries from ${_NEXT_IMAGE_FW_BIN_PATH}" + + UpgradeFW "${_NEXT_IMAGE_FW_BIN_PATH}" else + local -r _FS_PATH="/host/image-${_NEXT_SONIC_IMAGE#SONiC-OS-}/fs.squashfs" + local -r _FS_MOUNTPOINT="/tmp/image-${_NEXT_SONIC_IMAGE#SONiC-OS-}-fs" + local -r _FW_BIN_PATH="${_FS_MOUNTPOINT}/etc/mlnx/" + + LogInfo "Using FW binaries from ${_FW_BIN_PATH}" + mkdir -p "${_FS_MOUNTPOINT}" mount -t squashfs "${_FS_PATH}" "${_FS_MOUNTPOINT}" - UpgradeFW "${_FS_MOUNTPOINT}" + UpgradeFW "${_FW_BIN_PATH}" umount -rf "${_FS_MOUNTPOINT}" rm -rf "${_FS_MOUNTPOINT}" From 18657ae5f6c74d9f14e30baec35662d5d951e855 Mon Sep 17 00:00:00 2001 From: Stepan Blyshchak <38952541+stepanblyschak@users.noreply.github.com> Date: Thu, 16 Feb 2023 16:05:05 +0200 Subject: [PATCH 2/3] Apply suggestions from code review Co-authored-by: Nazarii Hnydyn --- files/build_templates/sonic_debian_extension.j2 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/files/build_templates/sonic_debian_extension.j2 b/files/build_templates/sonic_debian_extension.j2 index cbd8faf8620e..bbdfbc96c900 100644 --- a/files/build_templates/sonic_debian_extension.j2 +++ b/files/build_templates/sonic_debian_extension.j2 @@ -937,9 +937,9 @@ declare -rA FW_FILE_MAP=( \ sudo mkdir -p $FILESYSTEM_ROOT/$PLATFORM_DIR/fw/asic/ sudo mkdir -p $FILESYSTEM_ROOT_ETC/mlnx/ for fw_file_name in ${!FW_FILE_MAP[@]}; do - sudo cp $files_path/$fw_file_name $FILESYSTEM_ROOT/$PLATFORM_DIR/${FW_FILE_MAP[$fw_file_name]} + sudo cp $files_path/$fw_file_name $FILESYSTEM_ROOT/$PLATFORM_DIR/fw/asic/${FW_FILE_MAP[$fw_file_name]} # Link old FW location to not break existing automation/scripts - sudo ln -s /host/image-$SONIC_IMAGE_VERSION/$PLATFORM_DIR/${FW_FILE_MAP[$fw_file_name]} $FILESYSTEM_ROOT/etc/mlnx/${FW_FILE_MAP[$fw_file_name]} + sudo ln -s /host/image-$SONIC_IMAGE_VERSION/$PLATFORM_DIR/fw/asic/${FW_FILE_MAP[$fw_file_name]} $FILESYSTEM_ROOT/etc/mlnx/${FW_FILE_MAP[$fw_file_name]} done sudo cp $files_path/$ISSU_VERSION_FILE $FILESYSTEM_ROOT/etc/mlnx/issu-version sudo cp $files_path/$MLNX_FFB_SCRIPT $FILESYSTEM_ROOT/usr/bin/mlnx-ffb.sh From b3bde088b9e637cf60f0b3a729d2f82d8d2ddb62 Mon Sep 17 00:00:00 2001 From: Stepan Blyschak Date: Thu, 16 Feb 2023 16:46:18 +0200 Subject: [PATCH 3/3] rename _NEXT_IMAGE_FW_BIN_PATH Signed-off-by: Stepan Blyschak --- platform/mellanox/mlnx-fw-upgrade.j2 | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/platform/mellanox/mlnx-fw-upgrade.j2 b/platform/mellanox/mlnx-fw-upgrade.j2 index 89447b02f193..81f58cee8a25 100755 --- a/platform/mellanox/mlnx-fw-upgrade.j2 +++ b/platform/mellanox/mlnx-fw-upgrade.j2 @@ -286,12 +286,12 @@ function UpgradeFWFromImage() { # /host/image-/platform/fw/asic is now the new location for FW binaries. # Prefere this path and if it does not exist use squashfs as a fallback. - local -r _NEXT_IMAGE_FW_BIN_PATH="/host/image-${_NEXT_SONIC_IMAGE#SONiC-OS-}/platform/fw/asic/" + local -r _PLATFORM_FW_BIN_PATH="/host/image-${_NEXT_SONIC_IMAGE#SONiC-OS-}/platform/fw/asic/" - if [[ -d "${_NEXT_IMAGE_FW_BIN_PATH}" ]]; then - LogInfo "Using FW binaries from ${_NEXT_IMAGE_FW_BIN_PATH}" + if [[ -d "${_PLATFORM_FW_BIN_PATH}" ]]; then + LogInfo "Using FW binaries from ${_PLATFORM_FW_BIN_PATH}" - UpgradeFW "${_NEXT_IMAGE_FW_BIN_PATH}" + UpgradeFW "${_PLATFORM_FW_BIN_PATH}" else local -r _FS_PATH="/host/image-${_NEXT_SONIC_IMAGE#SONiC-OS-}/fs.squashfs" local -r _FS_MOUNTPOINT="/tmp/image-${_NEXT_SONIC_IMAGE#SONiC-OS-}-fs"