From ad556fa6e56e33f6bed812f01c84363f4f5b34cf Mon Sep 17 00:00:00 2001 From: Adrian Chiris Date: Wed, 14 May 2014 10:49:15 +0300 Subject: [PATCH] applied some patches main changes: - compiling mstflint with no termios.h will work - removed un-needed includes - mtcr_ul when calling mtcr_mmap() it advances the enable counter when accessing deivce through /sys/bus/pci - removed some includes from headers and moved them to source files --- configure.ac | 3 ++ flint/cmd_line_parser.cpp | 6 ++- flint/subcommands.cpp | 9 +++- include/mtcr_ul/mtcr.h | 3 ++ mlxfwops/lib/flint_base.cpp | 4 +- mlxfwops/lib/flint_base.h | 64 ++------------------------ mlxfwops/lib/flint_io.cpp | 8 ++-- mlxfwops/lib/fw_ops.cpp | 7 ++- mtcr_ul/mtcr_ul.c | 91 +++++++++++++++++++++++++------------ 9 files changed, 92 insertions(+), 103 deletions(-) diff --git a/configure.ac b/configure.ac index b1ca89c..617eabe 100644 --- a/configure.ac +++ b/configure.ac @@ -18,6 +18,9 @@ AC_PROG_CXX AC_PROG_LIBTOOL AC_CONFIG_HEADERS( config.h ) +dnl Checks for headers +AC_CHECK_HEADER(termios.h,[CXXFLAGS="${CXXFLAGS} -DHAVE_TERMIOS_H"]) + AC_MSG_CHECKING(--enable-dc argument) AC_ARG_ENABLE(dc, [ --disable-dc Disable mstflint "dc" command. Eliminates zlib dependency], diff --git a/flint/cmd_line_parser.cpp b/flint/cmd_line_parser.cpp index fd19166..ee7b2f8 100644 --- a/flint/cmd_line_parser.cpp +++ b/flint/cmd_line_parser.cpp @@ -1,7 +1,8 @@ /* + * * cmd_line_parser.cpp - FLash INTerface * - * Copyright (C) Jan 2013 Mellanox Technologies Ltd. All rights reserved. + * Copyright (c) 2013 Mellanox Technologies Ltd. All rights reserved. * * This software is available to you under a choice of one of two * licenses. You may choose to be licensed under the terms of the GNU @@ -37,6 +38,7 @@ #include #include +#include // Flint includes #include "flint.h" #include @@ -79,7 +81,7 @@ SubCmdMetaData::SubCmdMetaData() { _sCmds.push_back(new SubCmd("q", "query", SC_Query)); _sCmds.push_back(new SubCmd("v", "verify", SC_Verify)); _sCmds.push_back(new SubCmd("", "swreset", SC_Swreset)); - _sCmds.push_back(new SubCmd("r", "reset_cfg", SC_ResetCfg)); + _sCmds.push_back(new SubCmd("", "reset_cfg", SC_ResetCfg)); _sCmds.push_back(new SubCmd("", "brom", SC_Brom)); _sCmds.push_back(new SubCmd("", "drom", SC_Drom)); _sCmds.push_back(new SubCmd("", "rrom", SC_Rrom)); diff --git a/flint/subcommands.cpp b/flint/subcommands.cpp index c753a60..140be65 100644 --- a/flint/subcommands.cpp +++ b/flint/subcommands.cpp @@ -38,6 +38,8 @@ #include +#include +#include #include #include @@ -46,6 +48,11 @@ #include #endif +#if !defined(__WIN__) && !defined(__DJGPP__) && !defined(UEFI_BUILD) && defined(HAVE_TERMIOS_H) + // used in mygetchar + #include +#endif + #include "subcommands.h" using namespace std; @@ -541,7 +548,7 @@ bool SubCommand::getGUIDFromStr(string str, guid_t& guid, string prefixErr) } -#if !defined(__WIN__) && !defined(__DJGPP__) +#if !defined(__WIN__) && !defined(__DJGPP__) && !defined(UEFI_BUILD) && defined(HAVE_TERMIOS_H) static int mygetch(void) { struct termios oldt, diff --git a/include/mtcr_ul/mtcr.h b/include/mtcr_ul/mtcr.h index c8ea8e1..89166f9 100644 --- a/include/mtcr_ul/mtcr.h +++ b/include/mtcr_ul/mtcr.h @@ -91,6 +91,9 @@ typedef enum MError { ME_ICMD_STATUS_IFC_BUSY, ME_ICMD_STATUS_ICMD_NOT_READY, ME_ICMD_UNSUPPORTED_ICMD_VERSION, + ME_ICMD_UNKNOWN_STATUS, + ME_ICMD_ICM_NOT_AVAIL, + ME_ICMD_WRITE_PROTECT, //errors regarding Tools CMDIF ME_CMDIF_BUSY = 0x300, diff --git a/mlxfwops/lib/flint_base.cpp b/mlxfwops/lib/flint_base.cpp index df011d9..f041f17 100755 --- a/mlxfwops/lib/flint_base.cpp +++ b/mlxfwops/lib/flint_base.cpp @@ -2,7 +2,7 @@ * * flint_base.cpp - FLash INTerface * - * Copyright (C) Jan 2013 Mellanox Technologies Ltd. All rights reserved. + * Copyright (c) 2013 Mellanox Technologies Ltd. All rights reserved. * * This software is available to you under a choice of one of two * licenses. You may choose to be licensed under the terms of the GNU @@ -33,7 +33,7 @@ * SOFTWARE. */ - +#include #include "flint_base.h" diff --git a/mlxfwops/lib/flint_base.h b/mlxfwops/lib/flint_base.h index f7fd706..c11374a 100755 --- a/mlxfwops/lib/flint_base.h +++ b/mlxfwops/lib/flint_base.h @@ -2,7 +2,7 @@ * * flint_base.h - FLash INTerface * - * Copyright (C) Jan 2013 Mellanox Technologies Ltd. All rights reserved. + * Copyright (c) 2013 Mellanox Technologies Ltd. All rights reserved. * * This software is available to you under a choice of one of two * licenses. You may choose to be licensed under the terms of the GNU @@ -32,8 +32,6 @@ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ - - #ifndef FLINT_BASE_H #define FLINT_BASE_H @@ -43,28 +41,10 @@ #endif #else #include "uefi_c.h" - // #include "uefi_c.cpp" #endif - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - - - -#include "tools_version.h" - #include +#include "tools_version.h" #ifndef __WIN__ @@ -89,9 +69,6 @@ #define vsnprintf(buf, len, format, args) (vsprintf(buf, format, args)) #define snprintf(buf, len, format, args...) (sprintf(buf, format, args)) #else // Linux GCC -#ifndef UEFI_BUILD - #include -#endif #ifdef __FreeBSD__ #define SWAPL(l) ntohl(l) #include @@ -145,7 +122,7 @@ #endif #endif // __WIN__ -#include + #include #include "compatibility.h" #include "mlxfwops_com.h" @@ -155,41 +132,6 @@ static inline void be_guid_to_cpu(guid_t* to, guid_t* from) { to->l=__be32_to_cpu(from->l); } namespace std {}; using namespace std; -/* -#ifndef __be32_to_cpu - #define __be32_to_cpu(x) ntohl(x) - #ifndef bswap_32 - #define bswap_32(x) (htonl(x)) - #endif -#endif -#ifndef __cpu_to_be32 - #define __cpu_to_be32(x) htonl(x) -#endif - -#if __BYTE_ORDER == __LITTLE_ENDIAN - #ifndef __cpu_to_le32 - #define __cpu_to_le32(x) (x) - #endif - #ifndef __le32_to_cpu - #define __le32_to_cpu(x) (x) - #endif -#elif __BYTE_ORDER == __BIG_ENDIAN - #ifndef __cpu_to_le32 - #define __cpu_to_le32(x) bswap_32(x) - #endif - #ifndef __le32_to_cpu - #define __le32_to_cpu(x) bswap_32(x) - #endif -#else - #ifndef __cpu_to_le32 - #define __cpu_to_le32(x) bswap_32(__cpu_to_be32(x)) - #endif - #ifndef __le32_to_cpu - #define __le32_to_cpu(x) __be32_to_cpu(bswap_32(x)) - #endif -#endif -*/ - #define TOCPU1(s) s = __be32_to_cpu((u_int32_t)(s)); #define CPUTO1(s) s = __cpu_to_be32((u_int32_t)(s)); diff --git a/mlxfwops/lib/flint_io.cpp b/mlxfwops/lib/flint_io.cpp index 5cde277..3e86e0e 100755 --- a/mlxfwops/lib/flint_io.cpp +++ b/mlxfwops/lib/flint_io.cpp @@ -2,7 +2,7 @@ * * flint_io.cpp - FLash INTerface * - * Copyright (C) Jan 2013 Mellanox Technologies Ltd. All rights reserved. + * Copyright (c) 2013 Mellanox Technologies Ltd. All rights reserved. * * This software is available to you under a choice of one of two * licenses. You may choose to be licensed under the terms of the GNU @@ -31,11 +31,9 @@ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. - * - * Version: $Id: flint_io.cpp 7522 2011-11-16 15:37:21Z mohammad $ - * */ +#include #include "flint_io.h" @@ -486,7 +484,7 @@ bool Flash::write (u_int32_t addr, deal_with_signal(); if (rc != MFE_OK) { - if (rc == MFE_ICMD_BAD_PARAM) { + if (rc == MFE_ICMD_BAD_PARAM || rc == MFE_REG_ACCESS_BAD_PARAM) { return errmsg("Flash write of %d bytes to address %s0x%x failed: %s\n" " This may indicate that a FW image was already updated on flash, but not loaded by the device.\n" " Please load FW on the device (reset device or reboot machine) before burning a new FW.", diff --git a/mlxfwops/lib/fw_ops.cpp b/mlxfwops/lib/fw_ops.cpp index 3a2059d..251afcd 100644 --- a/mlxfwops/lib/fw_ops.cpp +++ b/mlxfwops/lib/fw_ops.cpp @@ -31,8 +31,10 @@ */ -#include "stdlib.h" -#include "string.h" +#include +#include +#include + #include "flint_base.h" #include "flint_io.h" #include "fw_ops.h" @@ -475,6 +477,7 @@ FwOperations* FwOperations::FwOperationsCreate(void* fwHndl, void *info, char* p fwParams.hndlType = hndlType; fwParams.errBuff = errBuff; fwParams.errBuffSize = buffSize; + fwParams.shortErrors = true; if (hndlType == FHT_FW_FILE) { fwParams.fileHndl = (char*)fwHndl; diff --git a/mtcr_ul/mtcr_ul.c b/mtcr_ul/mtcr_ul.c index 3670362..9d703be 100644 --- a/mtcr_ul/mtcr_ul.c +++ b/mtcr_ul/mtcr_ul.c @@ -398,8 +398,37 @@ int mtcr_pcicr_mclose(mfile *mf) static int mtcr_mmap(struct pcicr_context *mf, const char *name, off_t off, int ioctl_needed) { + static const char sysbuspcidevices[] = "/sys/bus/pci/devices/"; int err; + // Enable PCI device before mmapping it + // this allows to flash a device even if mlx4_core fails to load with some kernels. + if (!strncmp(name, sysbuspcidevices, sizeof(sysbuspcidevices)-1)) { + /* Accessing through sysfs: need to enable PCI device. + We need to write 1 to 'enable' file located in + parent dir for 'name' */ + int fd; + char fname[4096]; + int i = strrchr(name, '/') - name; /*always ok*/ + if (i + sizeof("enable") >= sizeof(fname)) { + return -1; + } + strncpy(fname, name, i+1); + strcpy(fname + i + 1, "enable"); + + fd = open(fname, O_WRONLY | O_SYNC); + if (fd < 0) { + return -1; + } + i = write(fd, "1", 1); + err = errno; + close(fd); + errno = err; + if (1 != i) { + return -1; + } + } + mf->fd = open(name, O_RDWR | O_SYNC); if (mf->fd < 0) return -1; @@ -1185,7 +1214,7 @@ int get_inband_dev_from_pci(char* inband_dev, char* pci_dev) } closedir(d); - (void)access;//avoid compiler warrnings + (void)access; // avoid compiler warrnings if (found) { return 0; } else { @@ -1439,16 +1468,15 @@ static int mreg_send_wrapper(mfile* mf, u_int8_t *data, int r_icmd_size, int w_i return ME_MAD_SEND_FAILED; } } else if (supports_icmd(mf)) { - #ifdef MST_UL - //ugly hack to avoid warnings - if (0) { - rc = icmd_send_command_int(mf, FLASH_REG_ACCESS, data, w_icmd_size, r_icmd_size, 0); - } - // in mstflint we access through inband - rc = maccess_reg_mad(mf, data); - #else + #ifdef MST_UL //ugly hack to avoid compiler warrnings + if (0) { rc = icmd_send_command_int(mf, FLASH_REG_ACCESS, data, w_icmd_size, r_icmd_size, 0); - #endif + } + // in mstflint we send reg_access via MADS + rc = maccess_reg_mad(mf, data); + #else + rc = icmd_send_command_int(mf, FLASH_REG_ACCESS, data, w_icmd_size, r_icmd_size, 0); + #endif if (rc) { return rc; } @@ -1532,11 +1560,9 @@ static int mreg_send_raw(mfile *mf, u_int16_t reg_id, maccess_reg_method_t metho #define HW_ID_ADDR 0xf0014 static int supports_icmd(mfile* mf) { -#ifndef MST_UL_ICMD -#ifndef MST_UL - (void)mf; // avoid warnings - return 0; -#endif +#if !defined(MST_UL_ICMD) && !defined(MST_UL) + (void)mf; // avoid warnings + return 0; #endif u_int32_t dev_id; mread4(mf,HW_ID_ADDR, &dev_id); // cr might be locked and retured 0xbad0cafe but we dont care we search for device that supports icmd @@ -1569,21 +1595,20 @@ static int supports_tools_cmdif_reg(mfile* mf) { int mget_max_reg_size(mfile *mf) { - if (mf->access_type == MTCR_ACCESS_INBAND) { - return INBAND_MAX_REG_SIZE; - } - if (supports_icmd(mf)){ - // we support icmd and we dont use IB interface -> we use icmd for reg access - #ifdef MST_UL - return INBAND_MAX_REG_SIZE; - #else - return ICMD_MAX_REG_SIZE; - #endif - } - if (supports_tools_cmdif_reg(mf)) { - return TOOLS_HCR_MAX_MBOX; - } - return 0; + if (mf->access_type == MTCR_ACCESS_INBAND) { + return INBAND_MAX_REG_SIZE; + } + if (supports_icmd(mf)){ // we support icmd and we dont use IB interface -> we use icmd for reg access + #ifdef MST_UL + return INBAND_MAX_REG_SIZE; + #else + return ICMD_MAX_REG_SIZE; + #endif + } + if (supports_tools_cmdif_reg(mf)) { + return TOOLS_HCR_MAX_MBOX; + } + return 0; } /************************************ @@ -1677,6 +1702,12 @@ const char* m_err2str(MError status) return "ME_ICMD_BAD_PARAM"; case ME_ICMD_BUSY: return "ME_ICMD_BUSY"; + case ME_ICMD_ICM_NOT_AVAIL: + return "ME_ICMD_ICM_NOT_AVAIL"; + case ME_ICMD_WRITE_PROTECT: + return "ME_ICMD_WRITE_PROTECT"; + case ME_ICMD_UNKNOWN_STATUS: + return "ME_ICMD_UNKNOWN_STATUS"; // TOOLS HCR access errors case ME_CMDIF_BUSY: -- 2.41.0