summaryrefslogtreecommitdiff
path: root/mlxfwupdate
diff options
Diffstat (limited to 'mlxfwupdate')
-rwxr-xr-xmlxfwupdate/Makefile.am14
-rw-r--r--mlxfwupdate/Makefile.in42
-rw-r--r--mlxfwupdate/cmd_line_params.cpp3
-rw-r--r--mlxfwupdate/cmd_line_params.h2
-rw-r--r--mlxfwupdate/cmd_line_parser.cpp20
-rw-r--r--mlxfwupdate/err_msgs.h4
-rw-r--r--mlxfwupdate/image_access.cpp201
-rw-r--r--mlxfwupdate/image_access.h29
-rw-r--r--mlxfwupdate/mlnx_dev.cpp121
-rw-r--r--mlxfwupdate/mlnx_dev.h5
-rw-r--r--mlxfwupdate/mlxfwmanager.cpp348
-rw-r--r--mlxfwupdate/mlxfwmanager.h17
-rw-r--r--mlxfwupdate/mlxfwmanager_common.cpp3
-rw-r--r--mlxfwupdate/psid_query_item.h13
-rw-r--r--mlxfwupdate/server_request.cpp71
-rw-r--r--mlxfwupdate/server_request.h1
16 files changed, 698 insertions, 196 deletions
diff --git a/mlxfwupdate/Makefile.am b/mlxfwupdate/Makefile.am
index e593707..4c7b952 100755
--- a/mlxfwupdate/Makefile.am
+++ b/mlxfwupdate/Makefile.am
@@ -46,7 +46,9 @@ AM_CPPFLAGS = \
-I$(top_srcdir)/mft_utils \
-I$(top_srcdir)/mlxfwops/lib \
-I$(top_srcdir)/pldmlib \
- -I$(CURL_INC_DIR)
+ $(libxml2_CFLAGS) \
+ $(libcurl_CFLAGS) \
+ $(openssl_CFLAGS)
bin_PROGRAMS = mstfwmanager
@@ -108,20 +110,16 @@ mstfwmanager_DEPENDENCIES = \
$(MUPARSER_LIBS) \
$(SQLITE_LIBS)
-LDADD_mstfwmanager = -lm -lz ${LDL}
-# XML libs
-LDADD_mstfwmanager += -lxml2
-# curl libs
-LDADD_mstfwmanager += -lcurl -lssl -lcrypto -lrt
+LDADD_mstfwmanager = $(libcurl_LIBS) $(libz_LIBS) $(liblzma_LIBS) $(libxml2_LIBS)
if ENABLE_OPENSSL
mstfwmanager_DEPENDENCIES += $(top_builddir)/mlxsign_lib/libmlxsign.la
-LDADD_mstfwmanager += -lcrypto -lssl
+LDADD_mstfwmanager += $(openssl_LIBS)
endif
if ENABLE_CS
mstfwmanager_DEPENDENCIES += $(top_builddir)/tools_crypto/libtools_crypto.a
-LDADD_mstfwmanager += -lcrypto
+LDADD_mstfwmanager += $(openssl_LIBS)
endif
if ENABLE_INBAND
diff --git a/mlxfwupdate/Makefile.in b/mlxfwupdate/Makefile.in
index 865ae9e..5690c64 100644
--- a/mlxfwupdate/Makefile.in
+++ b/mlxfwupdate/Makefile.in
@@ -113,9 +113,9 @@ build_triplet = @build@
host_triplet = @host@
bin_PROGRAMS = mstfwmanager$(EXEEXT)
@ENABLE_OPENSSL_TRUE@am__append_1 = $(top_builddir)/mlxsign_lib/libmlxsign.la
-@ENABLE_OPENSSL_TRUE@am__append_2 = -lcrypto -lssl
+@ENABLE_OPENSSL_TRUE@am__append_2 = $(openssl_LIBS)
@ENABLE_CS_TRUE@am__append_3 = $(top_builddir)/tools_crypto/libtools_crypto.a
-@ENABLE_CS_TRUE@am__append_4 = -lcrypto
+@ENABLE_CS_TRUE@am__append_4 = $(openssl_LIBS)
@ENABLE_INBAND_TRUE@am__append_5 = $(top_builddir)/mad_ifc/libmad_ifc.la
@ENABLE_DPA_TRUE@am__append_6 = -DENABLE_DPA
@ENABLE_DPA_TRUE@am__append_7 = $(top_builddir)/mlxdpa/libmstdpa.a
@@ -124,7 +124,7 @@ DIST_COMMON = $(srcdir)/Makefile.in $(srcdir)/Makefile.am \
$(top_srcdir)/config/depcomp $(dist_doc_DATA)
ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
am__aclocal_m4_deps = $(top_srcdir)/m4/ax_check_compile_flag.m4 \
- $(top_srcdir)/configure.ac
+ $(top_srcdir)/m4/pkg.m4 $(top_srcdir)/configure.ac
am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \
$(ACLOCAL_M4)
mkinstalldirs = $(install_sh) -d
@@ -168,8 +168,11 @@ am__DEPENDENCIES_2 = $(top_builddir)/dev_mgt/libdev_mgt.la \
$(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1) \
$(am__DEPENDENCIES_1) $(am__append_1) $(am__append_3) \
$(am__append_5) $(am__append_7)
-am__DEPENDENCIES_3 = $(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1) \
- $(am__DEPENDENCIES_1)
+@ENABLE_OPENSSL_TRUE@am__DEPENDENCIES_3 = $(am__DEPENDENCIES_1)
+@ENABLE_CS_TRUE@am__DEPENDENCIES_4 = $(am__DEPENDENCIES_1)
+am__DEPENDENCIES_5 = $(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1) \
+ $(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1) \
+ $(am__DEPENDENCIES_3) $(am__DEPENDENCIES_4)
AM_V_lt = $(am__v_lt_@AM_V@)
am__v_lt_ = $(am__v_lt_@AM_DEFAULT_V@)
am__v_lt_0 = --silent
@@ -295,13 +298,13 @@ AUTOCONF = @AUTOCONF@
AUTOHEADER = @AUTOHEADER@
AUTOMAKE = @AUTOMAKE@
AWK = @AWK@
+CABLE_ACCESS_DIR = @CABLE_ACCESS_DIR@
CC = @CC@
CCDEPMODE = @CCDEPMODE@
CFLAGS = @CFLAGS@
COMPILER_FPIC = @COMPILER_FPIC@
CPP = @CPP@
CPPFLAGS = @CPPFLAGS@
-CURL_INC_DIR = @CURL_INC_DIR@
CXX = @CXX@
CXXCPP = @CXXCPP@
CXXDEPMODE = @CXXDEPMODE@
@@ -355,6 +358,7 @@ MUPARSER_CFLAGS = @MUPARSER_CFLAGS@
MUPARSER_LIBS = @MUPARSER_LIBS@
NM = @NM@
NMEDIT = @NMEDIT@
+NVML_DIR = @NVML_DIR@
OBJDUMP = @OBJDUMP@
OBJEXT = @OBJEXT@
OFED_BUILD = @OFED_BUILD@
@@ -368,6 +372,9 @@ PACKAGE_TARNAME = @PACKAGE_TARNAME@
PACKAGE_URL = @PACKAGE_URL@
PACKAGE_VERSION = @PACKAGE_VERSION@
PATH_SEPARATOR = @PATH_SEPARATOR@
+PKG_CONFIG = @PKG_CONFIG@
+PKG_CONFIG_LIBDIR = @PKG_CONFIG_LIBDIR@
+PKG_CONFIG_PATH = @PKG_CONFIG_PATH@
PROJECT = @PROJECT@
RANLIB = @RANLIB@
SED = @SED@
@@ -380,6 +387,7 @@ TOOLS_BUILD_TIME = @TOOLS_BUILD_TIME@
TOOLS_CRYPTO = @TOOLS_CRYPTO@
TOOLS_GIT_SHA = @TOOLS_GIT_SHA@
VERSION = @VERSION@
+VFIO_DRIVER_DIR = @VFIO_DRIVER_DIR@
XZ_UTILS_DIR = @XZ_UTILS_DIR@
abs_builddir = @abs_builddir@
abs_srcdir = @abs_srcdir@
@@ -407,6 +415,8 @@ default_en_inband = @default_en_inband@
docdir = $(INSTALL_BASEDIR)/etc/mstflint
dvidir = @dvidir@
exec_prefix = @exec_prefix@
+expat_CFLAGS = @expat_CFLAGS@
+expat_LIBS = @expat_LIBS@
host = @host@
host_alias = @host_alias@
host_cpu = @host_cpu@
@@ -416,13 +426,23 @@ htmldir = @htmldir@
includedir = @includedir@
infodir = @infodir@
install_sh = @install_sh@
+libcurl_CFLAGS = @libcurl_CFLAGS@
+libcurl_LIBS = @libcurl_LIBS@
libdir = @libdir@
libexecdir = @libexecdir@
+liblzma_CFLAGS = @liblzma_CFLAGS@
+liblzma_LIBS = @liblzma_LIBS@
+libxml2_CFLAGS = @libxml2_CFLAGS@
+libxml2_LIBS = @libxml2_LIBS@
+libz_CFLAGS = @libz_CFLAGS@
+libz_LIBS = @libz_LIBS@
localedir = @localedir@
localstatedir = @localstatedir@
mandir = @mandir@
mkdir_p = @mkdir_p@
oldincludedir = @oldincludedir@
+openssl_CFLAGS = @openssl_CFLAGS@
+openssl_LIBS = @openssl_LIBS@
pdfdir = @pdfdir@
prefix = @prefix@
program_transform_name = @program_transform_name@
@@ -449,7 +469,9 @@ AM_CPPFLAGS = \
-I$(top_srcdir)/mft_utils \
-I$(top_srcdir)/mlxfwops/lib \
-I$(top_srcdir)/pldmlib \
- -I$(CURL_INC_DIR)
+ $(libxml2_CFLAGS) \
+ $(libcurl_CFLAGS) \
+ $(openssl_CFLAGS)
mstfwmanager_CXXFLAGS = -g -MP -MD -Wall -W -DMSTFLINT \
$(INIPARSER_CFLAGS) $(JSON_CFLAGS) -DUSE_XML -DLIBXML_STATIC \
@@ -505,10 +527,8 @@ mstfwmanager_DEPENDENCIES = $(top_builddir)/dev_mgt/libdev_mgt.la \
$(INIPARSER_LIBS) $(MUPARSER_LIBS) $(SQLITE_LIBS) \
$(am__append_1) $(am__append_3) $(am__append_5) \
$(am__append_7)
-# XML libs
-# curl libs
-LDADD_mstfwmanager = -lm -lz ${LDL} -lxml2 -lcurl -lssl -lcrypto -lrt \
- $(am__append_2) $(am__append_4)
+LDADD_mstfwmanager = $(libcurl_LIBS) $(libz_LIBS) $(liblzma_LIBS) \
+ $(libxml2_LIBS) $(am__append_2) $(am__append_4)
mstfwmanager_LDADD = $(mstfwmanager_DEPENDENCIES) $(LDADD_mstfwmanager)
mstfwmanager_LDFLAGS = -static
all: all-am
diff --git a/mlxfwupdate/cmd_line_params.cpp b/mlxfwupdate/cmd_line_params.cpp
index 737620d..cb3b270 100644
--- a/mlxfwupdate/cmd_line_params.cpp
+++ b/mlxfwupdate/cmd_line_params.cpp
@@ -80,7 +80,8 @@ CmdLineParams::CmdLineParams()
dl = false;
no_extract_list = false;
numberOfRetrials = 5;
-
+ component_type = "";
+ skip_if_same = false;
#ifdef __WIN__
char execName[1024];
char certificatPath[1024];
diff --git a/mlxfwupdate/cmd_line_params.h b/mlxfwupdate/cmd_line_params.h
index dfdd041..f1cc4b2 100644
--- a/mlxfwupdate/cmd_line_params.h
+++ b/mlxfwupdate/cmd_line_params.h
@@ -51,6 +51,7 @@ public:
int update_fw;
int use_mfa_file;
int use_mfa_dir;
+ bool skip_if_same;
string mfa_dir;
string mfa_file;
@@ -100,6 +101,7 @@ public:
bool no_extract_list;
int numberOfRetrials;
bool no_fw_ctrl;
+ string component_type;
};
#endif
diff --git a/mlxfwupdate/cmd_line_parser.cpp b/mlxfwupdate/cmd_line_parser.cpp
index a518c07..d0ed2ee 100644
--- a/mlxfwupdate/cmd_line_parser.cpp
+++ b/mlxfwupdate/cmd_line_parser.cpp
@@ -210,6 +210,12 @@ using namespace mft_utils;
#define NO_FW_CTRL_L "no_fw_ctrl"
#define NO_FW_CTRL_S ' '
+#define COMP_TYPE_L "component_type"
+#define COMP_TYPE_S ' '
+
+#define SKIP_IF_SAME_L "skip_if_same"
+#define SKIP_IF_SAME_S ' '
+
string toolName = "";
/************************************
* Function: CmdLineParser
@@ -455,6 +461,10 @@ void CmdLineParser::initOptions()
this->AddOptions(NO_EXTRACT_LIST_L, NO_EXTRACT_LIST_S, "", "Do not extract or list binaries",
true); // Hidden
+
+ this->AddOptions(COMP_TYPE_L, COMP_TYPE_S, "componentName", "Specify the PLDM component type to extract");
+
+ this->AddOptions(SKIP_IF_SAME_L, SKIP_IF_SAME_S, "", "Skip firmware update if current and new versions match");
}
bool csvSplit(string str, vector<string>& strv)
@@ -655,6 +665,11 @@ ParseStatus CmdLineParser::HandleOption(string name, string value)
_cmdLineParams->target_file = value;
return PARSE_OK;
}
+ else if (name == COMP_TYPE_L)
+ {
+ _cmdLineParams->component_type = value;
+ return PARSE_OK;
+ }
else if (name == QUERY_L)
{
_cmdLineParams->query_device = true;
@@ -813,6 +828,11 @@ ParseStatus CmdLineParser::HandleOption(string name, string value)
}
return PARSE_OK;
}
+ else if (name == SKIP_IF_SAME_L)
+ {
+ _cmdLineParams->skip_if_same = true;
+ return PARSE_OK;
+ }
else
{
cout << "Unknown Flag: " << name << "\n";
diff --git a/mlxfwupdate/err_msgs.h b/mlxfwupdate/err_msgs.h
index 5138f9e..6249492 100644
--- a/mlxfwupdate/err_msgs.h
+++ b/mlxfwupdate/err_msgs.h
@@ -68,6 +68,8 @@ enum
ERR_CODE_INVALID_CHOICE = 26,
ERR_CODE_NONE_FAIL_SAFE = 27,
ERR_CODE_SERVER_QUERY_FAILED = 28,
+ ERR_CODE_INVALID_PLDM_COMPONENT = 29,
+ ERR_CODE_INVALID_PLDM_FORMAT = 30,
ERR_CODES_NUM
};
@@ -99,5 +101,7 @@ enum
#define ERR_MSG_IVALID_CHOICE "Select choice is invalid"
#define ERR_MSG_NONE_FAIL_SAFE "Burn is fail safe, None fail safe required"
#define ERR_MSG_SERVER_QUERY "Failed to query PSIDs from server"
+#define ERR_MSG_PLDM_COMPONENT "Not valid PLDM component type"
+#define ERR_MSG_INVALID_PLDM_FORMAT "Can't parse PLDM format"
#endif
diff --git a/mlxfwupdate/image_access.cpp b/mlxfwupdate/image_access.cpp
index 6a885e7..fd2f656 100644
--- a/mlxfwupdate/image_access.cpp
+++ b/mlxfwupdate/image_access.cpp
@@ -50,6 +50,7 @@
#else
#include <tools_layouts/connectx4_layouts.h>
#endif
+#include "pldmlib/pldm_utils.h"
using namespace std;
@@ -153,7 +154,12 @@ clean_up:
return res;
}
-bool ImageAccess::openImg(fw_hndl_type_t hndlType, char* psid, char* fileHndl)
+bool ImageAccess::openImg(fw_hndl_type_t hndlType,
+ char* psid,
+ char* fileHndl,
+ u_int16_t swDevId,
+ u_int32_t* data,
+ u_int32_t dataSize)
{
memset(_errBuff, 0, sizeof(_errBuff));
_imgFwParams.errBuff = _errBuff;
@@ -162,6 +168,12 @@ bool ImageAccess::openImg(fw_hndl_type_t hndlType, char* psid, char* fileHndl)
_imgFwParams.psid = psid;
_imgFwParams.fileHndl = fileHndl;
_imgFwParams.shortErrors = true;
+ if (dataSize)
+ {
+ _imgFwParams.buffHndl = data;
+ _imgFwParams.buffSize = dataSize;
+ _imgFwParams.swDevId = swDevId;
+ }
_imgFwOps = FwOperations::FwOperationsCreate(_imgFwParams);
if (_imgFwOps == NULL) {
_errMsg = "-E- " + (string)_errBuff + "\n";
@@ -189,8 +201,18 @@ int ImageAccess::queryPsid(const string& fname,
vector < u_int8_t > sect; /* to get fw configuration. */
vector < u_int8_t > dest;
+ bool isStripedImage = false;
- if (!openImg(FHT_FW_FILE, (char*)psid.c_str(), (char*)fname.c_str())) {
+ if (getFileSignature(fname) == IMG_SIG_TYPE_PLDM)
+ {
+ res = getPldmImage(fname, psid);
+ if (res != 1)
+ {
+ goto clean_up;
+ }
+ isStripedImage = true;
+ }
+ else if (!openImg(FHT_FW_FILE, (char*)psid.c_str(), (char*)fname.c_str())) {
return 0;
}
@@ -198,7 +220,7 @@ int ImageAccess::queryPsid(const string& fname,
ri.found = 0;
memset(&img_query, 0, sizeof(img_query));
- if (!_imgFwOps->FwQuery(&img_query, true)) {
+ if (!_imgFwOps->FwQuery(&img_query, true, isStripedImage)) {
_errMsg = "Failed to query " + (string)_imgFwOps->err();
_log += _errMsg;
goto clean_up;
@@ -275,14 +297,58 @@ int ImageAccess::queryPsid(const string& fname,
clean_up:
(void)selector_tag;
(void)image_type;
- _imgFwOps->FwCleanUp();
- delete _imgFwOps;
-
- _imgFwOps = NULL;
+ if(_imgFwOps != nullptr)
+ {
+ _imgFwOps->FwCleanUp();
+ delete _imgFwOps;
+ _imgFwOps = NULL;
+ }
return res;
}
+int ImageAccess::getPldmImage(const string& fname, const string& psid)
+{
+ if (!loadPldmPkg(fname))
+ {
+ _errMsg = "-E- Failed to load PLDM package from file: " + fname;
+ return -1;
+ }
+ u_int16_t swDevId = 0;
+ if (!_pldmPkg.isPsidInPldm(psid))
+ {
+ return 0;
+ }
+ else if (!getPldmDescriptorByPsid(psid, DEV_ID_TYPE, swDevId))
+ {
+ _errMsg = "-E- No swId found for psid: " + psid + " in file: " + fname;
+ return -1;
+ }
+ u_int8_t* buff;
+ u_int32_t buffSize = 0;
+ if (!getPldmComponentByPsid(psid, ComponentIdentifier::Identifier_NIC_FW_Comp, &buff, buffSize))
+ {
+ _errMsg = "-E- Nic FW component not found for psid: " + psid + " in file: " + fname;
+ return -1;
+ }
+ if (!openImg(FHT_FW_BUFF, (char*)psid.c_str(), nullptr, swDevId, (u_int32_t*)buff, buffSize))
+ {
+ _errMsg = "Unable to open the PLDM buffer component.";
+ return -1;
+ }
+ if (_imgFwOps->FwType() != FIT_FS4 && _imgFwOps->FwType() != FIT_FS5)
+ {
+ _errMsg = "Update FW using PLDM is applicable only for FS4 and FS5 images.";
+ if (buff)
+ {
+ delete[] buff;
+ }
+ return -1;
+ }
+ delete[] buff;
+ return 1;
+}
+
int ImageAccess::getImage(const string& fname,
const string& psid,
string& selector_tag,
@@ -420,7 +486,7 @@ int ImageAccess::get_bin_content(const string& fname, vector < PsidQueryItem >&
if (!openImg(FHT_FW_FILE, NULL, (char*)fname.c_str())) {
return -1;
}
-
+
memset(&img_query, 0, sizeof(img_query));
if (!_imgFwOps->FwQuery(&img_query, true)) {
_errMsg = "Failed to query " + (string)_imgFwOps->err();
@@ -632,31 +698,6 @@ bool ImageAccess::extract_pldm_image_info(const u_int8_t* buff, u_int32_t size,
return 0;
}
-int ImageAccess::get_pldm_content(const string& fname, vector < PsidQueryItem >& riv)
-{
- PldmBuffer pldm_buff;
-
- pldm_buff.loadFile(fname);
- PldmPkg pldm;
-
- pldm.unpack(pldm_buff);
-
- u_int8_t dev_count = pldm.getDeviceIDRecordCount();
-
- for (u_int8_t i = 0; i < dev_count; i++) {
- PldmDevIdRecord* rec = pldm.getDeviceIDRecord(i);
- PsidQueryItem item;
- item.psid = rec->getDevicePsid();
- item.description = rec->getDescription();
- int image_index = rec->getComponentImageIndex();
- PldmComponenetImage* image_obj = pldm.getComponentImage(image_index);
- extract_pldm_image_info(image_obj->getComponentData(), image_obj->getComponentSize(), item);
- riv.push_back(item);
- }
-
- return 0;
-}
-
int ImageAccess::get_file_content(const string& fname, vector < PsidQueryItem >& riv)
{
int type = getFileSignature(fname);
@@ -672,7 +713,11 @@ int ImageAccess::get_file_content(const string& fname, vector < PsidQueryItem >&
break;
case IMG_SIG_TYPE_PLDM:
- res = get_pldm_content(fname, riv);
+ if (!loadPldmPkg(fname))
+ {
+ return res;
+ }
+ res = getPldmContent(riv);
break;
}
return res;
@@ -692,3 +737,91 @@ string ImageAccess::getLog()
{
return _log;
}
+
+/**********************
+ PLDM suport functions
+***********************/
+bool ImageAccess::loadPldmPkg(const string& fname)
+{
+ _pldm_buff.reset();
+ if (_pldm_buff.loadFile(fname))
+ {
+ return false;
+ }
+ _pldmPkg.reset();
+ if (!_pldmPkg.unpack(_pldm_buff))
+ {
+ return false;
+ }
+ return true;
+}
+
+FwComponent::comps_ids_t ImageAccess::ToCompId(ComponentIdentifier compIdentifier)
+{
+ if (compIdentifier == ComponentIdentifier::Identifier_BFB_Comp)
+ {
+ return FwComponent::comps_ids_t::COMPID_BFB;
+ }
+ return FwComponent::comps_ids_t::COMPID_UNKNOWN;
+}
+
+bool ImageAccess::getPldmDescriptorByPsid(string psid, u_int16_t type, u_int16_t& descriptor)
+{
+ return _pldmPkg.getPldmDescriptorByPsid(psid, type, descriptor);
+}
+
+bool ImageAccess::isPsidInPldm(string psid)
+{
+ return _pldmPkg.isPsidInPldm(psid);
+}
+
+int ImageAccess::getPldmComponentByPsid(string psid,
+ ComponentIdentifier compIdentifier,
+ u_int8_t** buff,
+ u_int32_t& buffSize)
+{
+ return _pldmPkg.getComponentDataByPsid(compIdentifier, psid, buff, buffSize);
+}
+
+// get all components Or get all component with specific identifier
+int ImageAccess::getPldmContent(vector<PsidQueryItem>& riv, ComponentIdentifier compIdentifier)
+{
+ if (!isValidComponent(compIdentifier))
+ {
+ _errMsg = "Invalid component identifier.";
+ return -1;
+ }
+ u_int8_t dev_count = _pldmPkg.getDeviceIDRecordCount();
+ for (u_int8_t i = 0; i < dev_count; i++)
+ {
+ PldmDevIdRecord* rec = _pldmPkg.getDeviceIDRecord(i);
+ vector<u_int8_t> componentsIndexes = rec->getComponentsIndexes();
+ for (size_t index = 0; index < componentsIndexes.size(); index++)
+ {
+ if (componentsIndexes[index])
+ {
+ PldmComponenetImage* getComponentImage = _pldmPkg.getComponentByIndex(index);
+ ComponentIdentifier identifier = static_cast<ComponentIdentifier>(getComponentImage->getComponentIdentifier());
+
+ PsidQueryItem item;
+ ComponentIdentifierToStringValue(identifier, COMPONENT_NAME, item.name);
+ item.type = getComponentImage->getcomponentVersionString();
+ item.psid = rec->getDevicePsid();
+ item.isNicComp = false;
+ if ((isNicFwComponent(identifier) &&
+ ((compIdentifier == ComponentIdentifier::Identifier_General) || isNicFwComponent(compIdentifier))))
+ {
+ item.isNicComp = true;
+ extract_pldm_image_info(
+ getComponentImage->getComponentData(), getComponentImage->getComponentSize(), item);
+ }
+ else if (identifier != compIdentifier && compIdentifier != ComponentIdentifier::Identifier_General)
+ {
+ continue;
+ }
+ riv.push_back(item);
+ }
+ }
+ }
+ return 0;
+} \ No newline at end of file
diff --git a/mlxfwupdate/image_access.h b/mlxfwupdate/image_access.h
index 93cfc46..49d5918 100644
--- a/mlxfwupdate/image_access.h
+++ b/mlxfwupdate/image_access.h
@@ -42,6 +42,8 @@
#include "psid_query_item.h"
#include "mlxfwmanager_common.h"
#include "mlnx_dev.h"
+#include "pldmlib/pldm_utils.h"
+#include "pldmlib/pldm_pkg.h"
using namespace std;
#define MLNX_ERR_BUFF_SIZE 1024
@@ -59,10 +61,25 @@ public:
ImageAccess(int compareFFV);
~ImageAccess();
int queryDirPsid(string& path, string& psid, string& selector_tag, int image_type, vector<PsidQueryItem>& riv);
- int queryPsid(const string& fname, const string& psid, string& selector_tag, int image_type, PsidQueryItem& ri);
+ int queryPsid(const string& fname,
+ const string& psid,
+ string& selector_tag,
+ int image_type,
+ PsidQueryItem& ri);
int getImage(const string& fname, u_int8_t** filebuf);
int getImage(const string& fname, const string& psid, string& selector_tag, int image_type, u_int8_t** filebuf);
int get_file_content(const string& fname, vector<PsidQueryItem>& riv);
+
+ // PLDM functions
+ bool loadPldmPkg(const string& fname);
+ int getPldmImage(const string& fname, const string& psid);
+ bool getPldmDescriptorByPsid(string psid, u_int16_t type, u_int16_t& descriptor);
+ int getPldmComponentByPsid(string psid, ComponentIdentifier compIdentifier, u_int8_t** buff, u_int32_t& buffSize);
+ int getPldmContent(vector<PsidQueryItem>& riv,
+ ComponentIdentifier compIdentifier = ComponentIdentifier::Identifier_General);
+ bool isPsidInPldm(string psid);
+ FwComponent::comps_ids_t ToCompId(ComponentIdentifier compIdentifier);
+
static int getFileSignature(const string& fname);
static bool hasMFAs(string dir);
string getLastErrMsg();
@@ -77,12 +94,16 @@ private:
int checkImgSignature(const char* fname);
int get_mfa_content(const string& fname, vector<PsidQueryItem>& riv);
- int get_pldm_content(const string& fname, vector<PsidQueryItem>& riv);
int get_bin_content(const string& fname, vector<PsidQueryItem>& riv);
bool extract_pldm_image_info(const u_int8_t* buff, u_int32_t size, PsidQueryItem& ri);
void parse_image_info_data(u_int8_t* image_info_data, PsidQueryItem& query_item);
static int getBufferSignature(u_int8_t* buf, u_int32_t size);
- bool openImg(fw_hndl_type_t hndlType, char* psid, char* fileHndl);
+ bool openImg(fw_hndl_type_t hndlType,
+ char* psid,
+ char* fileHndl,
+ u_int16_t swDevId = 0,
+ u_int32_t* data = nullptr,
+ u_int32_t dataSize = 0);
char _errBuff[MLNX_ERR_BUFF_SIZE];
int _compareFFV;
string _log;
@@ -90,6 +111,8 @@ private:
string _warning;
FwOperations::fw_ops_params_t _imgFwParams;
FwOperations* _imgFwOps;
+ PldmBuffer _pldm_buff;
+ PldmPkg _pldmPkg;
};
#endif
diff --git a/mlxfwupdate/mlnx_dev.cpp b/mlxfwupdate/mlnx_dev.cpp
index 757d6dc..e0aff2b 100644
--- a/mlxfwupdate/mlnx_dev.cpp
+++ b/mlxfwupdate/mlnx_dev.cpp
@@ -45,6 +45,7 @@
#include <string.h>
#include "image_access.h"
#include "mvpd/mvpd.h"
+#include "pldmlib/pldm_utils.h"
#if !defined(__WIN__) && !defined(__FreeBSD__)
#include <sys/socket.h>
@@ -137,6 +138,7 @@ void MlnxDev::_MlnxDevInit(int compare_ffv)
_preBurnInit = false;
_uniqueId = "NA";
_unknowProgress = 0;
+ _bfbSupported = false;
initUniqueId();
setDeviceType();
}
@@ -519,7 +521,7 @@ int MlnxDev::isQuerySuccess()
return _querySuccess;
}
-bool MlnxDev::openImg(u_int32_t* fileBuffer, u_int32_t bufferSize)
+bool MlnxDev::openImg(u_int32_t* fileBuffer, u_int32_t bufferSize, u_int16_t swDevId)
{
memset(_errBuff, 0, sizeof(_errBuff));
_imgFwParams.errBuff = _errBuff;
@@ -529,6 +531,7 @@ bool MlnxDev::openImg(u_int32_t* fileBuffer, u_int32_t bufferSize)
_imgFwParams.buffHndl = fileBuffer;
_imgFwParams.buffSize = bufferSize;
_imgFwParams.shortErrors = true;
+ _imgFwParams.swDevId = swDevId;
_imgFwOps = FwOperations::FwOperationsCreate(_imgFwParams);
if (_imgFwOps == NULL)
{
@@ -549,13 +552,50 @@ int MlnxDev::preBurn(string mfa_file,
string cmd;
int rc;
u_int8_t* filebuf = NULL;
+ u_int16_t swDevId = 0;
+ int sza;
ImageAccess imgacc(_compareFFV);
fw_info_t dev_fw_query;
fw_info_t img_fw_query;
memset(&dev_fw_query, 0, sizeof(dev_fw_query));
memset(&img_fw_query, 0, sizeof(img_fw_query));
_burnSuccess = 0;
- int sza = imgacc.getImage(mfa_file, &filebuf);
+ bool isStripedImage = false;
+ bool pldmFlow = false;
+
+ if (ImageAccess::getFileSignature(mfa_file) == IMG_SIG_TYPE_PLDM)
+ {
+ pldmFlow = true;
+ isStripedImage = true;
+ }
+
+ if (pldmFlow)
+ {
+ if (_psid.empty())
+ {
+ _errMsg = "-E- Can't extract Image from PLDM package, PSID missing in the device.\n";
+ return -1;
+ }
+ if (!imgacc.loadPldmPkg(mfa_file))
+ {
+ return -1;
+ }
+ if (!imgacc.getPldmDescriptorByPsid(_psid, DEV_ID_TYPE, swDevId))
+ {
+ _errMsg = "-E- Can't extract DEVICE ID from PLDM package.\n";
+ }
+ u_int32_t buffSize;
+ if (!imgacc.getPldmComponentByPsid(_psid, ComponentIdentifier::Identifier_NIC_FW_Comp, &filebuf, buffSize))
+ {
+ _errMsg = "-E- The component was not found in the PLDM.\n";
+ }
+ sza = static_cast<int>(buffSize);
+ }
+ else
+ {
+ sza = imgacc.getImage(mfa_file, &filebuf);
+ }
+
if (sza < 0)
{
_errMsg = imgacc.getLastErrMsg();
@@ -563,11 +603,16 @@ int MlnxDev::preBurn(string mfa_file,
return -1;
}
- if (!openImg((u_int32_t*)filebuf, (u_int32_t)sza))
+ if (!openImg((u_int32_t*)filebuf, (u_int32_t)sza, swDevId))
{
goto clean_up_on_error;
}
+ if (isStripedImage)
+ {
+ _imgFwOps->SetIsStripedImage(true);
+ }
+
if (!_imgFwOps->isEncrypted(_imageEncrypted))
{
_errMsg = "Failed to identify if image is encrypted.";
@@ -575,7 +620,7 @@ int MlnxDev::preBurn(string mfa_file,
goto clean_up_on_error;
}
- rc = _imgFwOps->FwQuery(&img_fw_query);
+ rc = _imgFwOps->FwQuery(&img_fw_query, true, isStripedImage);
if (!rc)
{
_errMsg = "Failed to query the image, " + (string)_imgFwOps->err();
@@ -592,6 +637,31 @@ int MlnxDev::preBurn(string mfa_file,
goto clean_up_on_error;
}
+ if (pldmFlow)
+ {
+ if (!_devFwOps->IsFsCtrlOperations())
+ {
+ _errMsg = "FW doesn't support update using PLDM.\n";
+ rc = -1;
+ goto clean_up_on_error;
+ }
+ else
+ {
+ if (_devFwOps->IsComponentSupported(FwComponent::comps_ids_t::COMPID_BFB))
+ {
+ _bfbSupported = true;
+ }
+ }
+
+ dm_dev_id_t imageType = dm_dev_sw_id2type(swDevId);
+ if (_deviceType != imageType)
+ {
+ _errMsg = "PCI Device ID in PLDM is not compatible with the Device ID on the device.\n";
+ rc = -1;
+ goto clean_up_on_error;
+ }
+ }
+
if (!_devFwOps->isEncrypted(_deviceEncrypted))
{
_errMsg = "Failed to identify if device is encrypted.";
@@ -762,6 +832,33 @@ clean_up:
return res;
}
+bool MlnxDev::burnPLDMComponent(FwComponent::comps_ids_t compId, u_int8_t* buff, u_int32_t buffSize)
+{
+ bool rc, res = true;
+ if (!_devFwOps->IsFsCtrlOperations())
+ {
+ _errMsg = "FW doesn't support Burning PLDM components using MCC.";
+ return false;
+ }
+ vector<u_int8_t> compData(*buff, *buff + buffSize);
+ rc = _devFwOps->FwBurnAdvanced(compData, _burnParams, compId);
+ if (!rc)
+ {
+ if (_devFwOps->err() != NULL)
+ {
+ _errMsg = _devFwOps->err();
+ }
+ else
+ {
+ _errMsg = "Failed to burn, unknown reason";
+ }
+ _log += _errMsg;
+ res = false;
+ UnlockDevice(_devFwOps);
+ }
+ return res;
+}
+
bool MlnxDev::InitDevFWParams(FwOperations::fw_ops_params_t& devFwParams)
{
string devName = getDevName();
@@ -771,6 +868,11 @@ bool MlnxDev::InitDevFWParams(FwOperations::fw_ops_params_t& devFwParams)
devFwParams.hndlType = FHT_MST_DEV;
char* deviceName = (char*)devName.c_str();
int length = ((strlen(deviceName) + 1) * sizeof(char));
+ if (devFwParams.mstHndl)
+ {
+ delete[] devFwParams.mstHndl;
+ devFwParams.mstHndl = NULL;
+ }
devFwParams.mstHndl = new char[length];
if (devFwParams.mstHndl == NULL)
{
@@ -799,8 +901,15 @@ bool MlnxDev::OpenDev()
{
return false;
}
+
+ if (_devFwOps)
+ {
+ _devFwOps->FwCleanUp();
+ delete _devFwOps;
+ _devFwOps = NULL;
+ }
_devFwOps = FwOperations::FwOperationsCreate(_devFwParams);
- delete[] _devFwParams.mstHndl;
+
if (_devFwOps == NULL)
{
_errMsg = _errBuff;
@@ -869,8 +978,6 @@ int MlnxDev::queryFwops()
if (!_description.size() || !_partNumber.size())
{ // take missing from ini
setMccSupport(false);
- _devFwOps->FwCleanUp();
- delete _devFwOps;
if (!OpenDev())
{
return -1;
diff --git a/mlxfwupdate/mlnx_dev.h b/mlxfwupdate/mlnx_dev.h
index 7661c2c..9ac1d93 100644
--- a/mlxfwupdate/mlnx_dev.h
+++ b/mlxfwupdate/mlnx_dev.h
@@ -67,6 +67,7 @@ public:
vector<string>& questions,
f_prog_func_adv stage_prog = (f_prog_func_adv)NULL);
int burn(bool&);
+ bool burnPLDMComponent(FwComponent::comps_ids_t compId, u_int8_t* buff, u_int32_t buffSize);
bool clearSemaphore();
int isBurnSuccess();
int isQuerySuccess();
@@ -94,6 +95,7 @@ public:
bool checkExistence(vector<MlnxDev*>& devs);
string getUniqueId() { return _uniqueId; };
+ bool isBFBSupported() { return _bfbSupported; };
public:
string guidPortOne;
@@ -119,6 +121,7 @@ private:
int getImageIndex(string type);
int queryFwops();
bool OpenDev();
+ bool openImg(u_int32_t* fileBuffer, u_int32_t bufferSize, u_int16_t swDevId = 0);
bool openImg(u_int32_t* fileBuffer, u_int32_t bufferSize);
port_type_t findPortType(int port);
void initUniqueId();
@@ -167,6 +170,8 @@ private:
bool _preBurnInit;
int _unknowProgress;
+ bool _bfbSupported;
+
#ifdef __WIN__
ToolsSync m_ToolsSync;
#endif
diff --git a/mlxfwupdate/mlxfwmanager.cpp b/mlxfwupdate/mlxfwmanager.cpp
index 018732a..7b36fe2 100644
--- a/mlxfwupdate/mlxfwmanager.cpp
+++ b/mlxfwupdate/mlxfwmanager.cpp
@@ -43,6 +43,12 @@
#include <algorithm>
#include <set>
+#include "pldmlib/pldm_utils.h"
+
+#define TUPLE_POS_COMPID 0
+#define TUPLE_POS_BUFF_PTR 1
+#define TUPLE_POS_BUFF_SIZE 2
+
int main(int argc, char* argv[])
{
try
@@ -54,6 +60,11 @@ int main(int argc, char* argv[])
fprintf(stderr, "-E- %s\n", e.what());
return ERR_CODE_SERVER_RETRIEVE_FAIL;
}
+ catch (const PLDMException& e)
+ {
+ fprintf(stderr, "-E- %s\n", e._err.c_str());
+ return ERR_CODE_INVALID_PLDM_COMPONENT;
+ }
}
int mainEntry(int argc, char* argv[])
{
@@ -62,6 +73,8 @@ int mainEntry(int argc, char* argv[])
bool early_cleanup = true;
bool os_valid;
int rc, rc0;
+ bool pldmFlow = false;
+ bool shouldSkip = false;
vector<string> dev_names;
vector<MlnxDev*> devs;
CmdLineParams cmd_params;
@@ -71,6 +84,7 @@ int mainEntry(int argc, char* argv[])
int require_update_cnt = 0;
vector<string> status_strings;
map<string, PsidQueryItem> psidUpdateInfo;
+ map<string, vector<tuple<FwComponent::comps_ids_t, u_int8_t*, u_int32_t>>> psidPldmComponents;
vector<string> psid_list;
vector<string> fw_version_list;
vector<dm_dev_id_t> dev_types_list;
@@ -345,6 +359,10 @@ int mainEntry(int argc, char* argv[])
{
psidLookupDB.readFile(adjustRelPath(cmd_params.lookup_file, config.adjuster_path));
}
+ if (ImageAccess::getFileSignature(config.mfa_path) == IMG_SIG_TYPE_PLDM)
+ {
+ pldmFlow = true;
+ }
// Query all Devs
print_out("Querying Mellanox devices firmware ...\n");
@@ -438,8 +456,14 @@ int mainEntry(int argc, char* argv[])
{
mpath = adjustRelPath(cmd_params.mfa_file, config.adjuster_path);
}
- rc = queryMFAs(srq, mpath, psid_list, dev_types_list, psidUpdateInfo, cmd_params.update_online, errorMsg,
- fw_version_list);
+
+ if (pldmFlow)
+ {
+ rc = queryPLDM(cmd_params.mfa_file, psid_list, psidPldmComponents);
+ }
+
+ rc = queryMFAs(srq, mpath, psid_list, dev_types_list, psidUpdateInfo, cmd_params.update_online, errorMsg, fw_version_list);
+
if (rc < 0)
{
// print_err("-E- No relevant image files or info could be found\n");
@@ -447,7 +471,8 @@ int mainEntry(int argc, char* argv[])
}
// Get required list of MFAs to download/burn
- getUniqueMFAList(devs, psidUpdateInfo, cmd_params.force_update, mfa_list, downloaded_files_names);
+ getUniqueMFAList(devs, psidUpdateInfo, cmd_params.force_update, mfa_list, downloaded_files_names,
+ cmd_params.skip_if_same);
}
rc = checkAndDisplayDeviceQuery1D(devs,
@@ -520,6 +545,14 @@ int mainEntry(int argc, char* argv[])
err_continue++;
continue;
}
+
+ shouldSkip = cmd_params.skip_if_same && isSameVersion(devs[i], psidUpdateInfo[devs[i]->getPsid()]);
+ if (shouldSkip)
+ {
+ status_strings[i] = "Skipped (same version)";
+ continue;
+ }
+
if (!cmd_params.force_update)
{
if (!devs[i]->doesDevNeedUpdate())
@@ -577,7 +610,7 @@ int mainEntry(int argc, char* argv[])
burn_cnt++;
string mfa_file = config.mfa_path;
string tmp = psidUpdateInfo[devs[i]->getPsid()].url;
- if (!cmd_params.use_mfa_file)
+ if (!cmd_params.use_mfa_file && !pldmFlow)
{
size_t pos = tmp.rfind("/");
if (pos != string::npos)
@@ -626,6 +659,21 @@ int mainEntry(int argc, char* argv[])
{
print_out("Preparing...\n");
}
+ if (pldmFlow)
+ {
+ for (auto comps : (psidPldmComponents[devs[i]->getPsid()]))
+ {
+ if (std::get<TUPLE_POS_COMPID>(comps) == FwComponent::comps_ids_t::COMPID_BFB)
+ {
+ if (devs[i]->isBFBSupported())
+ {
+ devs[i]->burnPLDMComponent(std::get<TUPLE_POS_COMPID>(comps),
+ std::get<TUPLE_POS_BUFF_PTR>(comps),
+ std::get<TUPLE_POS_BUFF_SIZE>(comps));
+ }
+ }
+ }
+ }
rc0 = devs[i]->burn(imageWasCached);
if (!rc0)
{
@@ -786,87 +834,135 @@ int extract_image(CmdLineParams& cmd_params, config_t& config, ServerRequest* sr
u_int8_t* filebuf = NULL;
ImageAccess imgacc(CompareFFV);
- if (cmd_params.psid == "")
+ if (ImageAccess::getFileSignature(config.mfa_path) == IMG_SIG_TYPE_PLDM)
{
- print_err("-E- Need to provide PSID for extraction.\n");
- res = ERR_CODE_BAD_CMD_ARGS;
- return res;
- }
-
- psid_list.push_back(cmd_params.psid);
- mpath = config.mfa_path;
+ if (cmd_params.psid == "")
+ {
+ print_err("-E- Need to provide PSID for extraction.\n");
+ res = ERR_CODE_BAD_CMD_ARGS;
+ return res;
+ }
+ ComponentIdentifier compIdentifier = ComponentIdentifier::Identifier_Not_Valid;
+ StringToComponentIdentifier(cmd_params.component_type, compIdentifier);
- if (cmd_params.use_mfa_file)
- {
- mpath = adjustRelPath(cmd_params.mfa_file, config.adjuster_path);
- }
+ u_int32_t buffSize;
+ if (!imgacc.loadPldmPkg(config.mfa_path))
+ {
+ print_err("-E- Can't parse PLDM package.\n");
+ res = ERR_CODE_INVALID_PLDM_FORMAT;
+ return res;
+ }
+ if (!imgacc.getPldmComponentByPsid(cmd_params.psid, compIdentifier, &filebuf, buffSize))
+ {
+ print_err("-E- The component wasn't found in the PLDM package.\n");
+ res = ERR_CODE_INVALID_PLDM_COMPONENT;
+ return res;
+ }
+ string targetFile = cmd_params.target_file;
- rc = queryMFAs(srq, mpath, psid_list, dev_types_list, psidUpdateInfo, cmd_params.update_online, errorMsg,
- fw_version_list);
- if (rc < 0)
- {
- print_err("-E- Failed while reading file(s)\n");
- res = ERR_CODE_IMG_NOT_FOUND;
- return res;
- }
- config.mfa_path = mpath;
- int cnt = psidUpdateInfo.size();
- ssize_t sza = 0;
- if (cnt == 1)
- {
- string srcFile = psidUpdateInfo[cmd_params.psid].url;
- string tag = psidUpdateInfo[cmd_params.psid].selector_tag;
- sza = imgacc.getImage(srcFile.c_str(), cmd_params.psid, tag, 1, &filebuf);
- if (sza > 0)
+ FILE* f = fopen(targetFile.c_str(), "wb");
+ u_int32_t sz = 0;
+ if (f != NULL)
{
- string targetFile = cmd_params.target_file;
- if (generateProductionName(targetFile, psidUpdateInfo[cmd_params.psid]))
+ sz = fwrite(filebuf, 1, buffSize, f);
+ fclose(f);
+ if (sz < buffSize)
{
+ print_err("-E- Failed while writing to file.\n");
res = ERR_CODE_WRITE_FILE_FAIL;
- goto clean_up;
}
+ }
+ else
+ {
+ print_err("-E- Failed to open %s for writing.\n", targetFile.c_str());
+ res = ERR_CODE_WRITE_FILE_FAIL;
+ }
+ print_out("Done!\n");
+ }
+ else
+ {
+ if (cmd_params.psid == "")
+ {
+ print_err("-E- Need to provide PSID for extraction.\n");
+ res = ERR_CODE_BAD_CMD_ARGS;
+ return res;
+ }
- if (useExtractDir)
- {
- targetFile = cmd_params.extract_dir + (string)PATH_SEPARATOR + targetFile;
- }
- targetFile = adjustRelPath(targetFile, config.adjuster_path);
- print_out("Extracting image for psid: %s to %s ...\n", cmd_params.psid.c_str(), targetFile.c_str());
- FILE* f = fopen(targetFile.c_str(), "wb");
- int sz = 0;
- if (f != NULL)
+ psid_list.push_back(cmd_params.psid);
+ mpath = config.mfa_path;
+
+ if (cmd_params.use_mfa_file)
+ {
+ mpath = adjustRelPath(cmd_params.mfa_file, config.adjuster_path);
+ }
+
+ rc = queryMFAs(srq, mpath, psid_list, dev_types_list, psidUpdateInfo, cmd_params.update_online, errorMsg,
+ fw_version_list);
+ if (rc < 0)
+ {
+ print_err("-E- Failed while reading file(s)\n");
+ res = ERR_CODE_IMG_NOT_FOUND;
+ return res;
+ }
+ config.mfa_path = mpath;
+ int cnt = psidUpdateInfo.size();
+ ssize_t sza = 0;
+ if (cnt == 1)
+ {
+ string srcFile = psidUpdateInfo[cmd_params.psid].url;
+ string tag = psidUpdateInfo[cmd_params.psid].selector_tag;
+ sza = imgacc.getImage(srcFile.c_str(), cmd_params.psid, tag, 1, &filebuf);
+ if (sza > 0)
{
- sz = fwrite(filebuf, 1, sza, f);
- fclose(f);
- if (sz < sza)
+ string targetFile = cmd_params.target_file;
+ if (generateProductionName(targetFile, psidUpdateInfo[cmd_params.psid]))
+ {
+ res = ERR_CODE_WRITE_FILE_FAIL;
+ goto clean_up;
+ }
+
+ if (useExtractDir)
+ {
+ targetFile = cmd_params.extract_dir + (string)PATH_SEPARATOR + targetFile;
+ }
+ targetFile = adjustRelPath(targetFile, config.adjuster_path);
+ print_out("Extracting image for psid: %s to %s ...\n", cmd_params.psid.c_str(), targetFile.c_str());
+ FILE* f = fopen(targetFile.c_str(), "wb");
+ int sz = 0;
+ if (f != NULL)
+ {
+ sz = fwrite(filebuf, 1, sza, f);
+ fclose(f);
+ if (sz < sza)
+ {
+ print_err("-E- Failed while writing to file.\n");
+ res = ERR_CODE_WRITE_FILE_FAIL;
+ }
+ }
+ else
{
- print_err("-E- Failed while writing to file.\n");
+ print_err("-E- Failed to open %s for writing.\n", targetFile.c_str());
res = ERR_CODE_WRITE_FILE_FAIL;
}
+ print_out("Done!\n");
}
else
{
- print_err("-E- Failed to open %s for writing.\n", targetFile.c_str());
- res = ERR_CODE_WRITE_FILE_FAIL;
+ print_err("-E- Failed to extract image, MFA file might not have requested PSID\n");
+ res = ERR_CODE_INTERNAL_ERR;
}
- print_out("Done!\n");
+ }
+ else if (cnt > 1)
+ {
+ print_err("-E- More than one relevant image found. Not performing extraction!\n");
+ res = ERR_CODE_IMG_NOT_FOUND;
}
else
{
- print_err("-E- Failed to extract image, MFA file might not have requested PSID\n");
- res = ERR_CODE_INTERNAL_ERR;
+ print_err("-E- NO mfa file found!\n");
+ res = ERR_CODE_IMG_NOT_FOUND;
}
}
- else if (cnt > 1)
- {
- print_err("-E- More than one relevant image found. Not performing extraction!\n");
- res = ERR_CODE_IMG_NOT_FOUND;
- }
- else
- {
- print_err("-E- NO mfa file found!\n");
- res = ERR_CODE_IMG_NOT_FOUND;
- }
clean_up:
if (filebuf)
@@ -1158,6 +1254,7 @@ int checkAndDisplayDeviceQuery1D(vector<MlnxDev*>& devs,
string print_err_str = "";
string xml_output = "";
string tmpstr;
+ bool shouldSkip = false;
print_out("\n");
if (devs.size() > 0)
{
@@ -1328,7 +1425,12 @@ int checkAndDisplayDeviceQuery1D(vector<MlnxDev*>& devs,
}
else if (imgFound)
{
- if ((nUpdateReasons > 0) && (nKeepReasons == 0))
+ shouldSkip = cmd_params.skip_if_same && isSameVersion(devs[i], psidUpdateInfo[devs[i]->getPsid()]);
+ if (shouldSkip)
+ {
+ statusStr = "Skipped (same version)";
+ }
+ else if ((nUpdateReasons > 0) && (nKeepReasons == 0))
{
statusStr = "Update required";
devs[i]->setDevToNeedUpdate();
@@ -1522,13 +1624,27 @@ void getUniquePsidList(vector<MlnxDev*>& devs,
}
}
+// helper function to check if the current firmware version matches the target version
+bool isSameVersion(MlnxDev* dev, PsidQueryItem& psidUpdateInfo)
+{
+ ImgVersion* fwImgVer = (ImgVersion*)psidUpdateInfo.findImageVersion("FW");
+ if (fwImgVer != NULL && dev->compareFWVer(*fwImgVer) == 0)
+ {
+ return true;
+ }
+ return false;
+}
+
void getUniqueMFAList(vector<MlnxDev*>& devs,
map<string, PsidQueryItem>& psidUpdateInfo,
int force_update,
vector<string>& mfa_list,
- vector<string>& mfa_base_name_list)
+ vector<string>& mfa_base_name_list,
+ bool skip_if_same)
{
map<string, int> mfa2download;
+ bool shouldSkip = false;
+
for (int i = 0; i < (int)devs.size(); i++)
{
if (!devs[i]->isQuerySuccess())
@@ -1543,6 +1659,15 @@ void getUniqueMFAList(vector<MlnxDev*>& devs,
{
continue;
}
+
+ shouldSkip = skip_if_same && isSameVersion(devs[i], psidUpdateInfo[devs[i]->getPsid()]);
+ if (shouldSkip)
+ {
+ printf("Device %s: Current firmware version matches target version. Skipping update.\n",
+ devs[i]->getDevName().c_str());
+ continue;
+ }
+
if (force_update || (devs[i]->compareFWVer(psidUpdateInfo[devs[i]->getPsid()].imgVers[0]) < 0))
{
if (mfa2download.count(psidUpdateInfo[devs[i]->getPsid()].url) == 0)
@@ -1569,6 +1694,37 @@ int isDirectory(string path)
return (S_ISDIR(st.st_mode));
}
+int getPLDMCompsListFromPSIDs(string file,
+ vector<string>& psid_list,
+ vector<tuple<PsidQueryItem, u_int8_t*, u_int32_t>>& results,
+ ComponentIdentifier compIdentifier)
+{
+ int rc = 0;
+ ImageAccess imgacc(CompareFFV);
+ vector<PsidQueryItem> comps;
+ imgacc.loadPldmPkg(file);
+ imgacc.getPldmContent(comps, compIdentifier);
+ for (auto& comp : comps)
+ {
+ for (string psid : psid_list)
+ {
+ if (comp.psid == psid)
+ {
+ u_int8_t* buff;
+ u_int32_t buffSize = 0;
+ if (!imgacc.getPldmComponentByPsid(psid, compIdentifier, &buff, buffSize))
+ {
+ print_out("-E- can't extract component data from PLDM package.\n");
+ rc = -1;
+ }
+ comp.compId = imgacc.ToCompId(compIdentifier);
+ results.push_back(std::make_tuple(comp, buff, buffSize));
+ }
+ }
+ }
+ return rc;
+}
+
int isFile(string path)
{
int status;
@@ -1656,6 +1812,22 @@ int getMFAListFromPSIDs(string mfa_path, vector<string>& psid_list, vector<PsidQ
return 0;
}
+int queryPLDM(string file,
+ vector<string>& psid_list,
+ map<string, vector<tuple<FwComponent::comps_ids_t, u_int8_t*, u_int32_t>>>& psidPldmComponents)
+{
+ vector<tuple<PsidQueryItem, u_int8_t*, u_int32_t>> pldmCompsResults;
+ getPLDMCompsListFromPSIDs(file, psid_list, pldmCompsResults, ComponentIdentifier::Identifier_BFB_Comp);
+ for (unsigned i = 0; i < pldmCompsResults.size(); i++)
+ {
+ tuple<FwComponent::comps_ids_t, u_int8_t*, u_int32_t> compTuple =
+ std::make_tuple(get<TUPLE_POS_COMPID>(pldmCompsResults[i]).compId,
+ get<TUPLE_POS_BUFF_PTR>(pldmCompsResults[i]), get<TUPLE_POS_BUFF_SIZE>(pldmCompsResults[i]));
+ psidPldmComponents[get<0>(pldmCompsResults[i]).psid].push_back(compTuple);
+ }
+ return 0;
+}
+
int queryMFAs(ServerRequest* srq,
string& mfa_path,
vector<string>& psid_list,
@@ -1943,7 +2115,7 @@ int list_files_content(config_t& config)
}
else
{
- display_file_listing(items, config.psid, show_titles);
+ display_file_listing(items, config.psid, show_titles, ImageAccess::getFileSignature(fpath));
}
}
else
@@ -1995,7 +2167,7 @@ int list_files_content(config_t& config)
printf("Supported Boards in File: %s\n", fpath.c_str());
show_titles = true;
}
- display_file_listing(items, config.psid, show_titles);
+ display_file_listing(items, config.psid, show_titles, ImageAccess::getFileSignature(fpath));
items.clear();
show_titles = false;
displayed_files_cnt++;
@@ -2031,7 +2203,7 @@ void display_field_str(string field, int size, string display_if_empty = "")
print_out(fmt, f.c_str());
}
-void display_file_listing(vector<PsidQueryItem>& items, string psid, bool show_titles)
+void display_file_listing(vector<PsidQueryItem>& items, string psid, bool show_titles, int signature)
{
int max_pn_length = 25;
int tmpLen = 0;
@@ -2063,8 +2235,16 @@ void display_file_listing(vector<PsidQueryItem>& items, string psid, bool show_t
}
print_out("\n");
}
+
+ vector<PsidQueryItem> notNicComps;
+ bool pldmFile = signature == IMG_SIG_TYPE_PLDM;
for (unsigned i = 0; i < items.size(); i++)
{
+ if (pldmFile && !items[i].isNicComp)
+ {
+ notNicComps.push_back(items[i]);
+ continue;
+ }
if (psid.length())
{
if (psid.compare(items[i].psid))
@@ -2084,6 +2264,10 @@ void display_file_listing(vector<PsidQueryItem>& items, string psid, bool show_t
{
display_field_str(imv->getPrintableVersion(0), 28);
}
+ else if (pldmFile)
+ {
+ display_field_str(items[i].type, 28);
+ }
else
{
display_field_str("", 16);
@@ -2116,6 +2300,32 @@ void display_file_listing(vector<PsidQueryItem>& items, string psid, bool show_t
break;
}
}
+
+ print_out("\n");
+ if (signature == IMG_SIG_TYPE_PLDM && notNicComps.size() > 0)
+ {
+ if (show_titles)
+ {
+ display_field_str("Type", max_pn_length);
+ print_out(" ");
+ display_field_str("Version", 28);
+ print_out(" ");
+ print_out("\n");
+ for (int i = 0; i < 110; i++)
+ {
+ print_out("-");
+ }
+ print_out("\n");
+ }
+ for (unsigned i = 0; i < notNicComps.size(); i++)
+ {
+ display_field_str(notNicComps[i].name, max_pn_length, "N/A");
+ print_out(" ");
+ display_field_str(notNicComps[i].type, 18);
+ print_out(" ");
+ print_out("\n");
+ }
+ }
}
int CalcFileCrc(char* fileName)
diff --git a/mlxfwupdate/mlxfwmanager.h b/mlxfwupdate/mlxfwmanager.h
index 9c4ca4d..12568fe 100644
--- a/mlxfwupdate/mlxfwmanager.h
+++ b/mlxfwupdate/mlxfwmanager.h
@@ -127,7 +127,10 @@ string getline();
// void displayFilesToBeDownloaded(filesOPtions filterOPtions, CmdLineParams cmd_params);
int displayReleaseNoteFiles(const filesOPtions& filterOPtions, const CmdLineParams& cmd_params);
void displayReleaseNoteMFAs(map<string, PsidQueryItem> psidUpdateInfo, vector<MlnxDev*> devs, int deviceIndex);
-void display_file_listing(vector<PsidQueryItem>& items, string psid, bool show_titles);
+void display_file_listing(vector<PsidQueryItem>& items,
+ string psid,
+ bool show_titles,
+ int signature = IMG_SIG_TYPE_UNKNOWN);
int getLocalDevices(dev_info** devs);
void getUniquePsidList(vector<MlnxDev*>& devs,
vector<string>& psid_list,
@@ -137,7 +140,8 @@ void getUniqueMFAList(vector<MlnxDev*>& devs,
map<string, PsidQueryItem>& psidUpdateInfo,
int force_update,
vector<string>& mfa_list,
- vector<string>& mfa_base_name_list);
+ vector<string>& mfa_base_name_list,
+ bool skip_if_same);
int queryMFAs(ServerRequest* srq,
string& mfa_path,
vector<string>& psid_list,
@@ -146,6 +150,14 @@ int queryMFAs(ServerRequest* srq,
int online_update,
string& errorMsg,
vector<string>& fw_version_list);
+int getPLDMImgListFromPSIDs(string file, vector<string>& psid_list, vector<PsidQueryItem>& results);
+int getPLDMCompsListFromPSIDs(string file,
+ vector<string>& psid_list,
+ vector<tuple<PsidQueryItem, u_int8_t*, u_int32_t>>& results,
+ ComponentIdentifier compId);
+int queryPLDM(string file,
+ vector<string>& psid_list,
+ map<string, vector<tuple<FwComponent::comps_ids_t, u_int8_t*, u_int32_t>>>& psidPldmComponents);
int download(ServerRequest* srq,
vector<string>& url,
vector<string>& fileNames,
@@ -231,6 +243,7 @@ void filterFiles(vector<DownloadedFileProperties> files,
int family);
int generateProductionName(string& targetFile, PsidQueryItem ri);
+bool isSameVersion(MlnxDev* dev, PsidQueryItem& psidUpdateInfo);
int abort_request = 0;
int CompareFFV = 0;
diff --git a/mlxfwupdate/mlxfwmanager_common.cpp b/mlxfwupdate/mlxfwmanager_common.cpp
index c6e82df..03f4484 100644
--- a/mlxfwupdate/mlxfwmanager_common.cpp
+++ b/mlxfwupdate/mlxfwmanager_common.cpp
@@ -354,6 +354,9 @@ string getErrStr(int rc)
err_msg[ERR_CODE_INVALID_CHOICE] = ERR_MSG_IVALID_CHOICE;
err_msg[ERR_CODE_NONE_FAIL_SAFE] = ERR_MSG_NONE_FAIL_SAFE;
err_msg[ERR_CODE_SERVER_QUERY_FAILED] = ERR_MSG_SERVER_QUERY;
+ err_msg[ERR_CODE_INVALID_PLDM_COMPONENT] = ERR_MSG_PLDM_COMPONENT;
+ err_msg[ERR_CODE_INVALID_PLDM_FORMAT] = ERR_MSG_INVALID_PLDM_FORMAT;
+
if (err_msg.find(rc) != err_msg.end())
{
return err_msg[rc];
diff --git a/mlxfwupdate/psid_query_item.h b/mlxfwupdate/psid_query_item.h
index 6726009..9230130 100644
--- a/mlxfwupdate/psid_query_item.h
+++ b/mlxfwupdate/psid_query_item.h
@@ -37,6 +37,7 @@
#define __PSID_QUERY_ITEM_H__
#include <img_version.h>
+#include "fw_comps_mgr/fw_comps_mgr.h"
#include <string>
#include <vector>
@@ -45,7 +46,14 @@ using namespace std;
class PsidQueryItem
{
public:
- PsidQueryItem() : devId(0), revId(0), found(0), isFailSafe(true){};
+ PsidQueryItem() :
+ devId(0),
+ revId(0),
+ found(0),
+ isFailSafe(true),
+ isNicComp(true),
+ swDevId(0),
+ compId(FwComponent::comps_ids_t::COMPID_UNKNOWN){};
virtual ~PsidQueryItem() {}
const ImgVersion* findImageVersion(string type);
string psid;
@@ -64,6 +72,9 @@ public:
vector<ImgVersion> imgVers;
bool isFailSafe;
string branch;
+ bool isNicComp;
+ u_int16_t swDevId;
+ FwComponent::comps_ids_t compId;
};
#endif
diff --git a/mlxfwupdate/server_request.cpp b/mlxfwupdate/server_request.cpp
index 0196e16..09da91b 100644
--- a/mlxfwupdate/server_request.cpp
+++ b/mlxfwupdate/server_request.cpp
@@ -84,12 +84,14 @@ int ServerRequest::parseQueryResponse(string jsonTxt, vector<PsidQueryItem>& res
#ifdef USE_CURL
string fileTag;
Json::Value root;
- mstflint::common::ReaderWrapper readerWrapper;
- Json::Reader* reader = readerWrapper.getReader();
- bool rc = reader->parse(jsonTxt, root);
+ Json::CharReaderBuilder builder;
+ const std::unique_ptr<Json::CharReader> reader(builder.newCharReader());
+ JSONCPP_STRING errs;
+
+ bool rc = reader->parse(jsonTxt.c_str(), jsonTxt.c_str() + jsonTxt.length(), &root, &errs);
if (!rc)
{
- setError(rc, "-E- Failed To parse server response\n");
+ setError(rc, std::string("-E- Failed To parse server response: ").append(errs).append("\n"));
return -1;
}
result.clear();
@@ -258,14 +260,15 @@ int ServerRequest::parseDownloadFilesResponse(string jsonTxt, vector<DownloadedF
{
#ifdef USE_CURL
Json::Value root;
- mstflint::common::ReaderWrapper readerWrapper;
- Json::Reader* reader = readerWrapper.getReader();
string url;
- // printf("response = %s\n", jsonTxt.c_str());
- bool rc = reader->parse(jsonTxt, root);
+ Json::CharReaderBuilder builder;
+ const std::unique_ptr<Json::CharReader> reader(builder.newCharReader());
+ JSONCPP_STRING errs;
+
+ bool rc = reader->parse(jsonTxt.c_str(), jsonTxt.c_str() + jsonTxt.length(), &root, &errs);
if (!rc)
{
- setError(rc, "-E- Failed To parse server response\n");
+ setError(rc, std::string("-E- Failed To parse server response: ").append(errs).append("\n"));
return -1;
}
for (unsigned j = 0; j < root.size(); j++)
@@ -429,56 +432,6 @@ string ServerRequest::genertDownloadUrl(string file_url)
return _Url + "/" + file_url;
}
-#if 0
-int ServerRequest::queryAllMFAs(vector<string> &mfa_list)
-{
- int res = 0;
- vector<string> psid_list;
- vector<dm_dev_id_t> dev_types_list;
- vector<string> fw_version_list;
- string response;
- mfa_list.clear();
- Json::Value root;
- Json::StyledWriter writer;
- root["psids"] = "";
- root["devs"] = "";
- root["mode"] = 1; // get all mfas;
- root["versions"] = "";
- root["key"] = _key;
-
- string data = writer.write( root );
- res = curl_request_str(_WebService.c_str(), data.c_str(), response);
- if (res) {
- return res;
- }
- res = parseQueryAllMFAsRespone(response, mfa_list);
- return res;
-}
-
-
-int ServerRequest::parseQueryAllMFAsRespone(string jsonTxt, vector <string> &result)
-{
-
- Json::Value root;
- mstflint::common::ReaderWrapper readerWrapper;
- Json::Reader* reader = readerWrapper.getReader();
- string url;
- bool rc = reader->parse(jsonTxt, root);
- if (!rc) {
- setError(rc, "-E- Failed To parse server response\n");
- //To be removed
- return rc;
- }
- for (unsigned j = 0; j < root.size(); j++) {
- if (root[j].isString()) {
- url = root[j].asString();
- result.push_back(_Url + url);
- }
- }
- return 0;
-}
-#endif
-
int ServerRequest::download(string url, string dest_path)
{
int res = 0;
diff --git a/mlxfwupdate/server_request.h b/mlxfwupdate/server_request.h
index 1c81cae..3b443e3 100644
--- a/mlxfwupdate/server_request.h
+++ b/mlxfwupdate/server_request.h
@@ -41,7 +41,6 @@
#include <tools_dev_types.h>
#include "psid_query_item.h"
#include "mlxfwmanager_common.h"
-#include "common/tools_json.h"
#ifdef USE_CURL
#include <json/reader.h>
#include <json/writer.h>