From 116c651f7ca2e5eebe998bd234b8510af614ea49 Mon Sep 17 00:00:00 2001 From: ertaozh Date: Thu, 26 Oct 2017 05:58:21 -0400 Subject: [PATCH 1/2] add the script to update nvme firmware --- xCAT/postscripts/update_nvme_firmware | 81 +++++++++++++++++++++++++++ 1 file changed, 81 insertions(+) create mode 100755 xCAT/postscripts/update_nvme_firmware diff --git a/xCAT/postscripts/update_nvme_firmware b/xCAT/postscripts/update_nvme_firmware new file mode 100755 index 000000000..a57370db6 --- /dev/null +++ b/xCAT/postscripts/update_nvme_firmware @@ -0,0 +1,81 @@ +#!/bin/sh +# +# If NVMe firmware file is located here: +# /install/MN12MN12.img +# +# Call the script as follows to update firmware for device /dev/nvme0: +# updatenode -P "update_nvme_firmware /install/MN12MN12.img [/dev/nvme0]" +# + +if [[ -z ${1} ]]; then + echo "Error: you must provide the path of the NVMe Firmware file" + exit 1 +fi +NVME_FILE_PATH=${1} +if ! which nvme > /dev/null; then + echo "Error: No nvme tool find, pls install nvme-cli first" + exit 1 +fi +if [[ -z ${2} ]]; then + if ! ls /dev/nvme* 2>1 >/dev/nul; then + echo "No NVMe device find"; + exit 1 + else + TARGET_DEV=`ls /dev/nvme*| egrep "nvme[0-9]$"` + fi +else + TARGET_DEV=${2} + if ! ls $TARGET_DEV 2>1 >/dev/null; then + echo "Not find nvme device $TARGET_DEV"; + exit 1 + fi +fi + +WORKING_DIR="/" +NVME_FIRM_FILE=`basename ${NVME_FILE_PATH}` +TARGET_FIRM_FILE="${WORKING_DIR}/${NVME_FIRM_FILE}" + +echo "==> NVMe Firmware File PATH: ${NVME_FILE_PATH}" +echo "==> NVMe Firmware File: ${NVME_FIRM_FILE}" + +if [[ -e ${TARGET_FIRM_FILE} ]]; then + rm -f ${TARGET_FIRM_FILE} +fi + +echo "==> Retrieving file from http://${MASTER}/${NVME_FILE_PATH}" +wget -q http://${MASTER}/${NVME_FILE_PATH} -O ${TARGET_FIRM_FILE} +if [[ $? ]]; then + echo "Error: Download ${NVME_FILE_PATH} failed from ${MASTER}" + exit 1 +fi + +ls -ltr ${TARGET_FIRM_FILE} + +if ! nvme fw-download $TARGET_DEV --fw=${TARGET_FIRM_FILE}; then + echo "Firmware download to NVMe device $TARGET_DEV failed" + exit 1 +fi + +nvme fw-activate $TARGET_DEV -a 1 -s 1 +nvme fw-activate $TARGET_DEV -a 1 -s 2 +nvme fw-activate $TARGET_DEV -a 1 -s 3 +nvme fw-activate $TARGET_DEV -a 1 -s 4 + +nvme reset $TARGET_DEV + +TARGET_VERSION=`nvme id-ctrl $TARGET_DEV | grep "fr " | awk '{ print $3}'` + +RC=0 +if [[ x"$NVME_FIRM_FILE" == x"${TARGET_VERSION}.img" ]]; then + echo "Update Succeed to $TARGET_VERSION" +else + echo "Update failed, the current version is $TARGET_VERSION" + RC=1 +fi +# +# Clean up +# +sleep 1 +rm -f ${TARGET_FIRM_FILE} + +exit $RC From cc79123674e7ce469a351f035805e443562e7412 Mon Sep 17 00:00:00 2001 From: ertaozh Date: Mon, 30 Oct 2017 09:04:25 -0400 Subject: [PATCH 2/2] update script update_nvme_firmware based on Victor's comments --- xCAT/postscripts/update_nvme_firmware | 68 +++++++++++++++------------ 1 file changed, 37 insertions(+), 31 deletions(-) diff --git a/xCAT/postscripts/update_nvme_firmware b/xCAT/postscripts/update_nvme_firmware index a57370db6..019551953 100755 --- a/xCAT/postscripts/update_nvme_firmware +++ b/xCAT/postscripts/update_nvme_firmware @@ -6,32 +6,36 @@ # Call the script as follows to update firmware for device /dev/nvme0: # updatenode -P "update_nvme_firmware /install/MN12MN12.img [/dev/nvme0]" # - +function usage() { + echo "Usage: $0 [nvme device]" +} if [[ -z ${1} ]]; then echo "Error: you must provide the path of the NVMe Firmware file" + usage exit 1 fi NVME_FILE_PATH=${1} if ! which nvme > /dev/null; then - echo "Error: No nvme tool find, pls install nvme-cli first" + echo "Error: nvme utility not found, install 'nvme-cli' package and retry" exit 1 fi if [[ -z ${2} ]]; then - if ! ls /dev/nvme* 2>1 >/dev/nul; then - echo "No NVMe device find"; - exit 1 + if ! ls /dev/nvme* 2>1 >/dev/null; then + echo "INFO: No NVMe device find, nothing to do" + exit 0 else - TARGET_DEV=`ls /dev/nvme*| egrep "nvme[0-9]$"` + TARGET_DEV=`ls /dev/nvme* | egrep "nvme[0-9]*$"` fi else TARGET_DEV=${2} if ! ls $TARGET_DEV 2>1 >/dev/null; then - echo "Not find nvme device $TARGET_DEV"; + echo "Error: Could not find NVMe device: $TARGET_DEV" exit 1 fi fi -WORKING_DIR="/" +WORKING_DIR="/tmp/xcat.nvme" +/usr/bin/mkdir -p ${WORKING_DIR} NVME_FIRM_FILE=`basename ${NVME_FILE_PATH}` TARGET_FIRM_FILE="${WORKING_DIR}/${NVME_FIRM_FILE}" @@ -44,38 +48,40 @@ fi echo "==> Retrieving file from http://${MASTER}/${NVME_FILE_PATH}" wget -q http://${MASTER}/${NVME_FILE_PATH} -O ${TARGET_FIRM_FILE} -if [[ $? ]]; then +if [[ $? -ne 0 ]]; then echo "Error: Download ${NVME_FILE_PATH} failed from ${MASTER}" exit 1 fi ls -ltr ${TARGET_FIRM_FILE} - -if ! nvme fw-download $TARGET_DEV --fw=${TARGET_FIRM_FILE}; then - echo "Firmware download to NVMe device $TARGET_DEV failed" - exit 1 -fi - -nvme fw-activate $TARGET_DEV -a 1 -s 1 -nvme fw-activate $TARGET_DEV -a 1 -s 2 -nvme fw-activate $TARGET_DEV -a 1 -s 3 -nvme fw-activate $TARGET_DEV -a 1 -s 4 - -nvme reset $TARGET_DEV - -TARGET_VERSION=`nvme id-ctrl $TARGET_DEV | grep "fr " | awk '{ print $3}'` - RC=0 -if [[ x"$NVME_FIRM_FILE" == x"${TARGET_VERSION}.img" ]]; then - echo "Update Succeed to $TARGET_VERSION" -else - echo "Update failed, the current version is $TARGET_VERSION" - RC=1 -fi +for DEV in $TARGET_DEV; do + if ! nvme fw-download $DEV --fw=${TARGET_FIRM_FILE} 2>1 >/dev/null ; then + echo "${DEV}: Firmware download to device failed" + RC=1 + continue + fi + + nvme fw-activate $DEV -a 1 -s 1 + nvme fw-activate $DEV -a 1 -s 2 + nvme fw-activate $DEV -a 1 -s 3 + nvme fw-activate $DEV -a 1 -s 4 + + nvme reset $DEV + + TARGET_VERSION=`nvme id-ctrl $DEV | grep "fr " | awk '{ print $3}'` + + if [[ x"$NVME_FIRM_FILE" == x"${TARGET_VERSION}.img" ]]; then + echo "${DEV}: Firmware successfully updated to $TARGET_VERSION" + else + echo "${DEV}: Firmware update failed, current version is ${TARGET_VERSION}" + RC=1 + fi +done # # Clean up # -sleep 1 rm -f ${TARGET_FIRM_FILE} +/usr/bin/rmdir ${WORKING_DIR} exit $RC