[TOOLS] remove Mellanox burning tools. They are to be provided for each kind of HW...
authorleonidk <leonidk@ad392aa1-c5ef-ae45-8dd8-e69d62a5ef86>
Wed, 11 Jun 2008 10:25:31 +0000 (10:25 +0000)
committerleonidk <leonidk@ad392aa1-c5ef-ae45-8dd8-e69d62a5ef86>
Wed, 11 Jun 2008 10:25:31 +0000 (10:25 +0000)
git-svn-id: svn://openib.tc.cornell.edu/gen1/trunk@1261 ad392aa1-c5ef-ae45-8dd8-e69d62a5ef86

39 files changed:
tools/flint/dirs [deleted file]
tools/flint/user/SOURCES [deleted file]
tools/flint/user/flint.cpp [deleted file]
tools/flint/user/flint.rc [deleted file]
tools/flint/user/makefile [deleted file]
tools/flint/user/mflash.c [deleted file]
tools/flint/user/mflash.h [deleted file]
tools/mread/user/SOURCES [deleted file]
tools/mread/user/makefile [deleted file]
tools/mread/user/mread.c [deleted file]
tools/mst/dirs [deleted file]
tools/mst/user/SOURCES [deleted file]
tools/mst/user/makefile [deleted file]
tools/mst/user/mst.c [deleted file]
tools/mst/user/mst.rc [deleted file]
tools/mtcr/dirs [deleted file]
tools/mtcr/user/SOURCES [deleted file]
tools/mtcr/user/com_def.h [deleted file]
tools/mtcr/user/makefile [deleted file]
tools/mtcr/user/mtcr.c [deleted file]
tools/mtcr/user/mtcr.def [deleted file]
tools/mtcr/user/mtcr.h [deleted file]
tools/mtcr/user/mtcr.rc [deleted file]
tools/mtcr/user/mtcr_i2c.c [deleted file]
tools/mtcr/user/mtcr_i2c.h [deleted file]
tools/mtcr/user/usb.cpp [deleted file]
tools/mtcr/user/usb.h [deleted file]
tools/mtcr/user/usb/I2cBrdg.lib [deleted file]
tools/mtcr/user/usb/UsbI2cIo.lib [deleted file]
tools/mtcr/user/usb/i2cbridge.h [deleted file]
tools/mtcr/user/usb/usbi2cio.h [deleted file]
tools/mwrite/user/SOURCES [deleted file]
tools/mwrite/user/makefile [deleted file]
tools/mwrite/user/mwrite.c [deleted file]
tools/spark/dirs [deleted file]
tools/spark/user/SOURCES [deleted file]
tools/spark/user/makefile [deleted file]
tools/spark/user/spark.cpp [deleted file]
tools/spark/user/spark.rc [deleted file]

diff --git a/tools/flint/dirs b/tools/flint/dirs
deleted file mode 100644 (file)
index 5a7e8b3..0000000
+++ /dev/null
@@ -1,2 +0,0 @@
-DIRS=\
-       user
diff --git a/tools/flint/user/SOURCES b/tools/flint/user/SOURCES
deleted file mode 100644 (file)
index b7df37a..0000000
+++ /dev/null
@@ -1,57 +0,0 @@
-TARGETNAME=flint\r
-TARGETTYPE=PROGRAM\r
-UMTYPE=console\r
-USE_MSVCRT=1\r
-USE_STL=1\r
-USE_NATIVE_EH=1\r
-\r
-TRUNK=..\..\..\r
-!if !defined(EXTERNAL_TOOLS)\r
-EXTERNAL_TOOLS=$(TRUNK)\ext_libs\r
-!endif\r
-\r
-ZLIB=$(EXTERNAL_TOOLS)\zlib-1.1.4\r
-\r
-TARGETPATH=$(TRUNK)\bin\user\obj$(BUILD_ALT_DIR)\r
-\r
-386_STDCALL=0\r
-amd64_STDCALL=0\r
-\r
-# TODO: Define free and checked.\r
-TARGETLIBS=\\r
-    $(TARGETPATH)\*\mtcr.lib \\r
-    $(SDK_LIB_PATH)\Ws2_32.lib\r
-\r
-\r
-#!if defined(NO_ZLIB)\r
-#C_DEFINES=$(C_DEFINES) -DNO_ZLIB\r
-#!else\r
-#TARGETLIBS=$(TARGETLIBS) $(ZLIB)\lib\zlib.lib\r
-#C_DEFINES=$(C_DEFINES) -DZEXPORT=__cdecl\r
-#!endif\r
-\r
-               \r
-SOURCES=mflash.c flint.cpp\r
-\r
-INCLUDES=  \\r
-        ..; \\r
-       $(TRUNK)\tools\WinMst\user\mtcr;  \\r
-       $(TRUNK)\tools\common; \\r
-       $(ZLIB)\include;\\r
-       ..\..\mtcr\user\r
-       \r
-# Could be any special flag needed for this project\r
-USER_C_FLAGS=$(USER_C_FLAGS) /MD \r
-\r
-C_DEFINES=$(C_DEFINES) -DWIN32 -D__WIN__ -D__i386__ -DNO_ZLIB\r
-!if !$(FREEBUILD)\r
-C_DEFINES=$(C_DEFINES) -D_DEBUG -DDEBUG -DDBG\r
-!endif\r
-\r
-# LINKER_FLAGS= $(LINKER_FLAGS)\r
-\r
-# Version:\r
-!if defined(VERSION_ID)\r
-C_DEFINES=$(C_DEFINES) "-DVERSION_ID=$(VERSION_ID)"\r
-!endif\r
-\r
diff --git a/tools/flint/user/flint.cpp b/tools/flint/user/flint.cpp
deleted file mode 100644 (file)
index da7f469..0000000
+++ /dev/null
@@ -1,5640 +0,0 @@
-/*
- *
- * flint.cpp - FLash INTerface
- *
- * Copyright (c) 2005-2008 Mellanox Technologies Ltd.  All rights reserved.
- *
- * This software is available to you under the OpenIB.org BSD license
- * below:
- *
- *     Redistribution and use in source and binary forms, with or
- *     without modification, are permitted provided that the following
- *     conditions are met:
- *
- *      - Redistributions of source code must retain the above
- *        copyright notice, this list of conditions and the following
- *        disclaimer.
- *
- *      - Redistributions in binary form must reproduce the above
- *        copyright notice, this list of conditions and the following
- *        disclaimer in the documentation and/or other materials
- *        provided with the distribution.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
- * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
- * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
- * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
- * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
- * 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$
- *
- */
-
-
-#include <ctype.h>
-#include <stdarg.h>
-#include <stdio.h>
-#include <string.h>
-#include <stdlib.h>
-#include <errno.h>
-#include <malloc.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <fcntl.h>
-#include <assert.h>
-
-#ifndef NO_ZLIB
-#include <zlib.h>
-#endif
-
-#include <signal.h>
-
-#ifndef __WIN__ 
-
-//
-// GCC Compiler
-//
-
-
-#if defined __DJGPP__
-//
-// DJGPP - GCC PORT TO MS DOS 
-//
-
-#include <mtcr.h> // This contains the u_* types definitions
-
-#include <netinet/in.h>
-#include <unistd.h>
-
-#define bswap_32(x) ntohl(x)
-
-// djgpp stdio does not define vsnprintf. I simply call vsprintf (and pray ...)
-#define vsnprintf(buf, len, format, args) (vsprintf(buf, format, args))
-
-#else // Linux GCC 
-
-#include <byteswap.h>
-#include <endian.h>
-#include <alloca.h>
-#include <netinet/in.h>
-#include <unistd.h>
-
-#endif // __DJGPP__
-
-#else // __WIN__
-
-//
-// Windows (Under DDK)
-//
-
-#include <io.h>
-#include <Winsock2.h>
-#include <mtcr.h>
-// Sleep adaptor
-#define        usleep(x) Sleep((x)/1000)
-#define sleep(x)  Sleep((x)*1000)
-
-#define vsnprintf      _vsnprintf
-#define strtoull       _strtoui64
-#define isatty         _isatty
-
-#define COMP_CDECL     __cdecl
-
-#define __LITTLE_ENDIAN 1234
-#define __BIG_ENDIAN 4321
-#define __BYTE_ORDER __LITTLE_ENDIAN
-
-
-#if __BYTE_ORDER == __LITTLE_ENDIAN
-#define bswap_32(x) ntohl(x)
-#else
-#error windows is assumed to run a on little endian architecture
-#endif
-
-#endif // __WIN__
-
-#include <memory>
-#include <vector>
-
-#include <mflash.h>
-
-
-#ifndef DEV_MST_EXAMPLE1
-    #define DEV_MST_EXAMPLE1 "/dev/mst/mt23108_pci_cr0"
-#endif
-
-#ifndef DEV_MST_EXAMPLE2
-    #define DEV_MST_EXAMPLE2 "/dev/mst/mt23108_pciconf0"
-#endif
-
-#ifndef FLINT_NAME
-    #ifdef __GNUC__
-        #define FLINT_NAME "%1$s"
-    #else
-        #define FLINT_NAME "./flint"
-    #endif
-#endif
-
-namespace std {}; using namespace std;
-
-#ifdef VERSION_ID
-//char* _versionID = VERSION_ID ;
-#define __VFSTR(x)                     #x
-#define _VFSTR(x)                      __VFSTR(x)
-char* _versionID = _VFSTR( VERSION_ID ) ;
-#else
-char* _versionID = "VERSION_ID_HERE";
-#endif
-
-char* _svnID     = "$Revision: 4337 $";
-
-#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
-
-
-////////////////////////////////////////////////////////////////////////
-//                                                                    //
-// ****************************************************************** //
-//                     Miscellaneous global stuff                     //
-// ****************************************************************** //
-//                                                                    //
-////////////////////////////////////////////////////////////////////////
-typedef struct guid {
-    u_int32_t h;
-    u_int32_t l;
-} guid_t;
-
-static inline void be_guid_to_cpu(guid_t* to, guid_t* from) {
-    to->h=__be32_to_cpu(from->h);
-    to->l=__be32_to_cpu(from->l);
-}
-
-static inline void cpu_to_be_guid(guid_t* to, guid_t* from) {
-    to->h=__cpu_to_be32(from->h);
-    to->l=__cpu_to_be32(from->l);
-}
-
-#define GUID_FORMAT "%8.8x%8.8x"
-#define MAC_FORMAT  "%4.4x%8.8x"
-#define TOCPU1(s) s = __be32_to_cpu(s)
-#define TOCPU(s) do {                                              \
-    u_int32_t *p = (u_int32_t *)(s);                               \
-    for (u_int32_t ii=0; ii<sizeof(s)/sizeof(u_int32_t); ii++,p++) \
-        *p = __be32_to_cpu(*p);                                    \
-    } while(0)
-#define TOCPUn(s, n) do {                                          \
-    u_int32_t *p = (u_int32_t *)(s);                               \
-    for (u_int32_t ii=0; ii<(n); ii++,p++)                         \
-        *p = __be32_to_cpu(*p);                                    \
-    } while(0)
-#define TOCPUBY(s) do {                                            \
-    u_int32_t *p = (u_int32_t *)(&s);                              \
-    for (u_int32_t ii=0; ii<sizeof(s)/sizeof(u_int32_t); ii++,p++) \
-        *p = __be32_to_cpu(*p);                                    \
-    } while(0)
-#define TOCPUBY64(s) do {                                          \
-    guid_t *p = s;                              \
-    for (unsigned ii=0; ii<sizeof(s)/sizeof(guid_t); ii++,p++) \
-        be_guid_to_cpu(p,p);                                   \
-    } while(0)
-#define CRC(c, s) do {                                             \
-    u_int32_t *p = (u_int32_t *)(s);                               \
-    for (u_int32_t ii=0; ii<sizeof(s)/sizeof(u_int32_t); ii++)     \
-        c << *p++;                                                 \
-    } while(0)
-#define CRCn(c, s, n) do {                                         \
-    u_int32_t *p = (u_int32_t *)(s);                               \
-    for (u_int32_t ii=0; ii<(n); ii++)                             \
-        c << *p++;                                                 \
-    } while(0)
-#define CRCBY(c, s) do {                                           \
-    u_int32_t *p = (u_int32_t *)(&s);                              \
-    for (u_int32_t ii=0; ii<sizeof(s)/sizeof(u_int32_t); ii++)     \
-        c << *p++;                                                 \
-    } while(0)
-#define CRC1(c, s) do {                                            \
-    u_int32_t *p = (u_int32_t *)(s);                               \
-    for (u_int32_t ii=0; ii<sizeof(s)/sizeof(u_int32_t) - 1; ii++) \
-        c << *p++;                                                 \
-    } while(0)
-#define CRC1n(c, s, n) do {                                        \
-    u_int32_t *p = (u_int32_t *)(s);                               \
-    for (u_int32_t ii=0; ii<(n) - 1; ii++)                         \
-        c << *p++;                                                 \
-    } while(0)
-#define CRC1BY(c, s) do {                                          \
-    u_int32_t *p = (u_int32_t *)(&s);                              \
-    for (u_int32_t ii=0; ii<sizeof(s)/sizeof(u_int32_t) - 1; ii++) \
-        c << *p++;                                                 \
-    } while(0)
-#define CHECKB2(f,b,o,n,p) do { if (!checkBoot2(f,b,o,n,p)) return false; } while (0)
-#define CHECKGN(f,b,o,n,p) do { if (!checkGen(f,b,o,n,p)) return false; } while (0)
-#define CHECKLS(f,o,s,p) do { if (!checkList(f,o,s,p)) return false; } while(0)
-#define READ4(f,o,d,p) do { if (!f.read(o,d)) {  \
-    return errmsg("%s - read error (%s)\n", p, f.err()); }} while (0)
-#define READBUF(f,o,d,l,p) do { if (!f.read(o,d,l)) { \
-    return errmsg("%s - read error (%s)\n", p, f.err()); }} while (0)
-
-
-class ErrMsg
-{
-public:
-    ErrMsg() : _err(0)       {                           }
-    ~ErrMsg()                { err_clear();              }
-    const char *err() const  { return _err;              }
-    void       err_clear()   { delete [] _err; _err = 0; }
-
-protected:
-    
-    char *vprint(const char *format, va_list args)
-    {
-       const int INIT_VAL = 1024;
-       int       max_str, max_buf = INIT_VAL;
-       char      *out_buf;
-       
-       while (1)
-       {
-           out_buf = new char[max_buf];
-           max_str = max_buf - 1;
-           
-           if (vsnprintf(out_buf, max_str, format, args) < max_str)
-               return out_buf;
-           delete [] out_buf;
-           max_buf *= 2;
-       }
-    } 
-
-
-    bool errmsg(const char *format, ...)
-#ifdef __GNUC__
-        __attribute__ ((format (printf, 2, 3)))
-#endif
-    ;    
-
-private:
-
-    char       *_err;
-};
-
-
-bool ErrMsg::errmsg(const char *format, ...) {
-    va_list   args;
-
-    char* prev_err = _err;
-
-    va_start(args, format);
-    _err = vprint(format, args);
-    va_end(args);
-
-    delete[] prev_err;
-
-    return false;
-}   
-
-
-enum {
-    SIGNATURE          = 0x5a445a44,
-    MELLANOX_VENDOR_ID = 0x15b3
-};
-struct PS {
-    u_int32_t fi_addr;
-    u_int32_t fi_size;
-    u_int32_t signature;
-    u_int32_t fw_reserved[5];
-    u_int32_t vsd[52];
-    u_int32_t psid[4];
-    u_int32_t branch_to;
-    u_int32_t crc016;
-};
-
-enum {
-    H_FIRST     =  1, 
-    H_DDR       =  1, 
-    H_CNF       =  2,
-    H_JMP       =  3,
-    H_EMT       =  4,
-    H_ROM       =  5,
-    H_GUID      =  6,
-    H_BOARD_ID  =  7, 
-    H_USER_DATA =  8,
-    H_FW_CONF   =  9,
-    H_IMG_INFO  = 10,
-    H_DDRZ      = 11,
-    H_LAST
-};
-
-const char* g_sectNames[] = {
-    "UNKNOWN (0 - Reserved)",
-    "DDR"             , 
-    "Configuration"   ,
-    "Jump addresses"  ,
-    "EMT Service"     ,
-    "ROM"             ,
-    "GUID"            ,
-    "BOARD ID"        , 
-    "User Data"       ,
-    "FW Configuration",
-    "Image Info"      ,
-    "DDRZ"
-};
-
-
-struct GPH {
-    u_int32_t type;
-    u_int32_t size;
-    u_int32_t param;
-    u_int32_t next;
-};
-
-#define MAX_SECTION_SIZE 0x400000
-
-const u_int32_t BOARD_ID_BSN_LEN=64;
-const u_int32_t BOARD_ID_BID_LEN=32;
-const u_int32_t BOARD_ID_PID=7;
-
-struct BOARD_ID {
-    char      bsn[BOARD_ID_BSN_LEN];
-    char      bid[BOARD_ID_BID_LEN];
-};
-
-int  const VSD_LEN  = 208;
-int  const PSID_LEN = 16;
-int  const PRODUCT_VER_LEN = 16;
-
-//
-// TODO: Remove the below globals to class members.
-//
-bool _print_crc = false;
-bool _silent = false;
-bool _assume_yes = false;
-bool _assume_no = false;
-bool _no_erase = false;
-bool _no_burn = false;
-
-bool _unlock_bypass = false;
-
-bool _byte_write = false;
-
-
-void report(const char *format, ...)
-#ifdef __GNUC__
-__attribute__ ((format (printf, 1, 2)))
-#endif
-;
-void report(const char *format, ...)
-{
-    va_list  args;
-
-    if (!_silent) {
-        va_start(args, format);
-        vprintf(format, args);
-        va_end(args);
-    }
-} // report
-
-void report_erase(const char *format, ...)
-{
-    va_list  args;
-    char buf[256];
-    int i;
-    int len;
-
-    if (_silent)
-       return;
-
-    va_start(args, format);
-    vsnprintf(buf, sizeof buf, format, args);
-    va_end(args);
-    
-    len = strlen(buf);
-    for(i=0; i < len; ++i)
-       printf("\b");
-} // report_erase
-
-
-////////////////////////////////////////////////////////////////////////
-//                                                                    //
-// ****************************************************************** //
-//                        CRC16 CALCULATION                           //
-// ****************************************************************** //
-//                                                                    //
-////////////////////////////////////////////////////////////////////////
-class Crc16 {
-public:
-    Crc16(bool d = false) : _debug(d) { clear();}
-    u_int16_t      get()              { return _crc;}
-    void           clear()            { _crc = 0xffff;}
-    void           operator<<(u_int32_t val) { add(val);}
-    void           add(u_int32_t val);
-    void           finish();
-private:
-    u_int16_t      _crc;
-    bool           _debug;
-};
-
-////////////////////////////////////////////////////////////////////////
-void Crc16::add(u_int32_t o)
-{
-    if (_debug)
-        printf("Crc16::add(%08x)\n", o);
-    for (int i=0; i<32; i++) {
-        if (_crc & 0x8000)
-            _crc = (u_int16_t) ((((_crc<<1) | (o>>31)) ^  0x100b) & 0xffff);
-        else
-            _crc= (u_int16_t) (((_crc<<1) | (o>>31)) & 0xffff);
-        o = (o<<1) & 0xffffffff;
-    }
-} // Crc16::add
-
-
-////////////////////////////////////////////////////////////////////////
-void Crc16::finish()
-{
-    for (int i=0; i<16; i++) {
-        if (_crc & 0x8000)
-            _crc=((_crc<<1)  ^  0x100b) & 0xffff;
-        else
-            _crc=(_crc<<1) & 0xffff;
-    }
-
-    // Revert 16 low bits
-    _crc = _crc ^ 0xffff;
-
-} // Crc16::finish
-
-
-//////////////////////////////////////////////////////////////////////
-//
-//  class u_int32_ba (bit access):
-//  A uint wrapper which allows easy access to bit/range of bits.
-//
-//  Usage example:
-//     u_int32_ba a;
-//     Read_Word( Table.reg ,&a);
-//     int upper_byte = a.range(31,24);
-//     if (a[15])
-//        cout << " Bit 15 is 1 \n";
-//     else
-//        cout << " Bit 15 is 0 \n";
-//
-//     u_int32_ba b;
-//     b.range(15,12) = 0xa;
-//     b[31]          = 1;     // b == 0x8000a000
-//     Write_Word( Table.reg ,b);
-//
-//////////////////////////////////////////////////////////////////////
-
-
-class u_int32_ba {
-public:
-    u_int32_ba(u_int32_t i = 0) :
-    _bits(i),
-    _rbits(_bits),
-    _sptr1(0),
-    _eptr(31)    {}
-
-    u_int32_ba  operator[](u_int32_t idx) {return range((u_int8_t)idx,(u_int8_t)idx);}
-    u_int32_ba& operator= (u_int32_t i)   {_rbits = ((i << _sptr1) & mask()) | (_rbits & ~mask()); return *this;}
-    u_int32_t*  operator& ()              {return &_bits;}
-    operator    u_int32_t ()              {return((mask() & _rbits) >> _sptr1);}
-
-    u_int32_ba  range     (u_int8_t eptr, 
-                           u_int8_t sptr) {return u_int32_ba(*this,eptr,sptr);}
-
-private:
-    u_int32_ba(u_int32_ba& other, u_int8_t eptr, u_int8_t sptr) :
-    _bits(other._bits),
-    _rbits(other._bits),
-    _sptr1(sptr),
-    _eptr(eptr) {}
-
-    u_int32_t  mask       () {
-        u_int32_t s_msk = (u_int32_t)-1; // start mask
-        u_int32_t e_msk = (u_int32_t)-1; // end mask
-
-        s_msk = (s_msk << _sptr1);
-        e_msk = (_eptr >= (sizeof(_bits)*8-1)) ? e_msk : ~(e_msk << (_eptr+1));
-
-        return(s_msk & e_msk);
-    };
-
-    u_int32_t  _bits;
-    u_int32_t& _rbits;
-
-    u_int8_t   _sptr1;
-    u_int8_t   _eptr;
-};
-
-//////////////////////////////////////////////////////////////////////
-//
-//  class Aligner:
-//  A utillity class for accessing an addr/size region 
-//  in a specific alignment.
-//  If a 0 alignment is given, infinity (no alignment requirements) 
-//  is assumed - This is to support single flow for the caller.
-//
-//////////////////////////////////////////////////////////////////////
-
-class Aligner {
-public:
-    Aligner(u_int32_t log2_alignment_size) :
-        _log2_alignment_size(log2_alignment_size),
-        _alignment_size(1 << log2_alignment_size),
-        _alignment_mask(_alignment_size - 1)
-    {
-        if (_log2_alignment_size == 0) {
-            _log2_alignment_size = 31;
-            _alignment_size      = 1 << _log2_alignment_size;
-            _alignment_mask      = _alignment_size - 1;
-        }
-    }
-    
-    void Init        (u_int32_t  addr, u_int32_t  size) {
-        _curr_addr = addr;
-        _curr_size = size;
-    }
-
-    bool GetNextChunk(u_int32_t& chunk_addr, u_int32_t& chunk_size) {
-        if (_curr_size == 0) {
-            return false;
-        }
-
-        chunk_addr = _curr_addr;
-
-        if ( (_curr_addr               >> _log2_alignment_size) != 
-            ((_curr_addr + _curr_size) >> _log2_alignment_size)) {
-            // Next chunk crosses alignment boundary
-            chunk_size = _alignment_size - (_curr_addr & _alignment_mask);
-        } else {
-            chunk_size = _curr_size;
-        }
-
-        _curr_addr += chunk_size;
-        _curr_size -= chunk_size;
-        
-        return true;
-    }
-
-private:
-    u_int32_t _curr_addr;
-    u_int32_t _curr_size;
-    u_int32_t _log2_alignment_size;
-    u_int32_t _alignment_size;
-    u_int32_t _alignment_mask;
-};
-
-
-
-
-////////////////////////////////////////////////////////////////////////
-//                                                                    //
-// ****************************************************************** //
-//                        FLASH ACCESS                                //
-// ****************************************************************** //
-//                                                                    //
-////////////////////////////////////////////////////////////////////////
-
-// Common base class for Flash and for FImage
-
-
-class FBase : public ErrMsg{
-public:
-    FBase(bool is_flash) :
-        _log2_chunk_size(0), 
-        _is_flash(is_flash) {}
-    virtual ~FBase()  {}
-
-    virtual bool open(const char *, bool)                  {return false;}
-    virtual void close()                                   = 0;
-    virtual bool read(u_int32_t addr, u_int32_t *data)     = 0;
-    virtual bool read(u_int32_t addr, void *data, int len,
-                      bool verbose=false)                  = 0;
-
-    virtual u_int32_t get_sector_size()                    = 0;
-    virtual u_int32_t get_size()                           = 0;
-
-    virtual u_int32_t get_dev_id()                         = 0;
-
-    bool              is_flash() {return _is_flash;};
-
-    virtual void set_address_convertor(u_int32_t log2_chunk_size, bool is_image_in_odd_chunks) {
-        _log2_chunk_size = log2_chunk_size;
-        _is_image_in_odd_chunks = is_image_in_odd_chunks;
-    }
-
-    enum {
-        MAX_FLASH = 4*1048576
-    };
-
-protected:
-
-    // Address translation functions for ConnectX.
-    // Translate between contiguous "logical" addresses 
-
-    // If Failsafe zebra mapping is enabled:
-
-    // Result is concatenation of:
-    // The lower log2_chunk_size bits of the cons_addr
-    // The is_image_in_odd_chunk bit
-    // The remaining upper bits of the cons_addr
-
-    u_int32_t cont2phys(u_int32_t cont_addr) {
-        u_int32_t result;
-        if (_log2_chunk_size) {
-            result  = (cont_addr       & (0xffffffff >> (32 - _log2_chunk_size))) |
-                      (_is_image_in_odd_chunks       << _log2_chunk_size)         |
-                     ((cont_addr << 1) & (0xffffffff << (_log2_chunk_size + 1)));
-        } else {
-            result = cont_addr;
-        }
-        return result;
-    }
-    
-    u_int32_t phys2cont(u_int32_t phys_addr) {
-        u_int32_t result;
-        if (_log2_chunk_size) {
-            result =  (phys_addr       & (0xffffffff >> (32 - _log2_chunk_size)))  |
-                     ((phys_addr >> 1) & (0xffffffff << (     _log2_chunk_size)));
-        } else {
-            result = phys_addr;
-        }
-        return result;
-    }
-
-    bool       _is_image_in_odd_chunks;
-    u_int32_t  _log2_chunk_size;
-
-    const bool _is_flash;
-
-};
-
-// Flash image (RO)
-class FImage : public FBase {
-public:
-    FImage() :  FBase(false), _buf(0) {}
-    virtual ~FImage() { close();}
-
-    u_int32_t    *getBuf()      { return _buf;}
-    u_int32_t    getBufLength() { return _len;}
-    virtual bool open(const char *fname, bool read_only = false);
-    virtual void close();
-    virtual bool read(u_int32_t addr, u_int32_t *data);
-    virtual bool read(u_int32_t addr, void *data, int len, bool verbose=false);
-
-    virtual u_int32_t get_sector_size();
-    virtual u_int32_t get_size()     { return  getBufLength();}
-    virtual u_int32_t get_dev_id()   { return  0;}
-
-private:
-    u_int32_t *_buf;
-    u_int32_t _len;
-};
-
-// 
-// Flash access (R/W)
-//
-class Flash : public FBase {
-public:
-    Flash() :
-        FBase(true),
-        _mfl(0),
-        _curr_sector(0xffffffff),
-        _port_num(0)
-     {}
-
-    virtual ~Flash()  { close();};
-
-    // FBase Interface
-
-    virtual bool open          (const char *device,
-                               bool force_lock = false,
-                                bool read_only  = false);
-
-    virtual void close         ();
-
-    virtual bool read          (u_int32_t addr, 
-                                u_int32_t *data);
-
-    virtual bool read          (u_int32_t addr, 
-                                void*     data, 
-                                int       len, 
-                                bool      verbose = false);
-
-    bool         cr_write      (u_int32_t addr,
-                                u_int32_t data) {return mf_cr_write(_mfl, addr, data) == MFE_OK;}
-
-    //
-    // Flash Interface
-    //
-
-    u_int32_t get_sector_size        ()  {return _attr.sector_size; } 
-    u_int32_t get_size               ()  {return _attr.size;}
-    
-    u_int32_t get_dev_id             ()  {return _attr.hw_dev_id;}
-
-    u_int32_t get_port_num           ()  {return _port_num;}
-
-    // Write and Erase functions are performed by the Command Set
-
-    virtual bool erase_sector  (u_int32_t addr);
-
-    virtual bool write         (u_int32_t addr, 
-                                void*     data, 
-                                int       cnt,
-                                bool      noerase = false);
-
-    virtual bool write         (u_int32_t addr, 
-                                u_int32_t data);
-
-    bool         print_attr();
-    bool         print_attr_old_format();
-
-    enum {
-        TRANS = 4096
-    };
-
-    static bool _byte_mode;
-
-#ifndef _MSC_VER
-protected:
-#endif
-
-    mflash*    _mfl;
-    flash_attr _attr;
-
-    u_int32_t  _curr_sector;
-    u_int32_t  _port_num;
-};
-
-
-////////////////////////////////////////////////////////////////////////
-//
-// FImage Class Implementation
-//
-////////////////////////////////////////////////////////////////////////
-
-bool FImage::open(const char *fname, bool read_only)
-{
-    int                fsize;
-    int                r_cnt;
-    FILE              *fh;
-
-    read_only = true;  // FImage can be opened only for read
-
-    fh = fopen(fname, "rb");
-
-    if (!fh) {
-        return errmsg("Can not open file \"%s\" - %s\n", fname, strerror(errno));
-    }
-
-    // Get the file size:
-    if (fseek(fh, 0, SEEK_END) < 0) {
-        return errmsg("Can not get file size for \"%s\" - %s\n", fname, strerror(errno));
-    }
-
-    fsize = ftell(fh);
-    if (fsize < 0) {
-        return errmsg("Can not get file size for \"%s\" - %s\n", fname, strerror(errno));
-    }
-    rewind(fh);
-
-    //printf("-D- %s size is %d\n", fname, fsize);
-    if (fsize & 0x3) {
-        return errmsg("Image size should be 4-bytes aligned. Make sure file %s is in the right format (binary image)",
-                     fname);
-    }
-
-    _buf = new u_int32_t[fsize/4];
-    if ((r_cnt = fread(_buf, 1, fsize, fh)) != fsize) {
-        if (r_cnt < 0)
-            return errmsg("Read error on file \"%s\" - %s\n",fname, strerror(errno));
-        else
-            return errmsg("Read error on file \"%s\" - read only %d bytes (from %ld)\n",
-                         fname, r_cnt, (unsigned long)fsize);
-    }
-
-    _len = fsize;
-    fclose(fh);
-
-    return true;
-} // FImage::open
-
-////////////////////////////////////////////////////////////////////////
-void FImage::close()
-{
-    delete [] _buf;
-    _buf = 0;
-} // FImage::close
-
-////////////////////////////////////////////////////////////////////////
-bool FImage::read(u_int32_t addr, u_int32_t *data)
-{
-    return read(addr, data, 4);
-} // FImage::read
-
-////////////////////////////////////////////////////////////////////////
-bool FImage::read(u_int32_t addr, void *data, int len, bool)
-{
-
-    if (addr & 0x3) {
-        return errmsg("Address should be 4-bytes aligned.");
-    }
-    if (len & 0x3) {
-        return errmsg("Length should be 4-bytes aligned.");
-    }
-    if (!_buf) {
-       return errmsg("read() when not opened");
-    }
-
-    if (cont2phys(addr + len) > _len) {
-        return errmsg("Reading 0x%x bytes from %saddress 0x%x is out of image limits (0x%x bytes)", 
-                     len,
-                      _log2_chunk_size ? "physical " : "",
-                      addr, 
-                      _len);
-    }
-
-    u_int32_t chunk_addr;
-    u_int32_t chunk_size;    
-    Aligner align(_log2_chunk_size);
-    align.Init (addr, len);
-    while (align.GetNextChunk(chunk_addr, chunk_size)) {
-        u_int32_t phys_addr = cont2phys(chunk_addr);
-
-        memcpy((u_int8_t*)data + (chunk_addr - addr), 
-               (u_int8_t*)_buf +  phys_addr, 
-                chunk_size);
-    }
-
-    return true;
-} // FImage::read
-
-////////////////////////////////////////////////////////////////////////
-u_int32_t FImage::get_sector_size() 
-{   
-    u_int32_t log2_sector_sz_ptr;
-    u_int32_t log2_sector_sz;
-    u_int32_t signature;
-
-    read(0x24, &signature);
-    TOCPU1(signature);
-    if (signature == SIGNATURE) {
-        // full image:
-        read(0x14, &log2_sector_sz_ptr);
-        TOCPU1(log2_sector_sz_ptr);
-        log2_sector_sz_ptr &= 0xffff;
-
-        read(0x30 + log2_sector_sz_ptr, &log2_sector_sz);
-        TOCPU1(log2_sector_sz);
-        log2_sector_sz &= 0xffff;
-
-        return(1 << log2_sector_sz);
-
-    } else {
-        return 0;
-    }
-}
-
-
-
-////////////////////////////////////////////////////////////////////////
-//
-// Flash Class Implementation
-//
-////////////////////////////////////////////////////////////////////////
-
-
-bool Flash::_byte_mode = false;
-
-////////////////////////////////////////////////////////////////////////
-bool Flash::open(const char *device, bool force_lock, bool read_only)
-{
-    // Open device
-    int rc;
-    read_only = false;
-
-    rc = mf_open(&_mfl, device);
-
-    if ((rc == MFE_SEM_LOCKED) && force_lock) {
-        report("Warning: Taking flash lock even though semaphore is set.\n");
-        rc = mf_open_ignore_lock(_mfl);
-    }
-
-    if (rc == MFE_SEM_LOCKED) {
-        return errmsg("Can not obtain Flash semaphore (63). You can run \"flint -clear_semaphore -d <device>\" to force semaphore unlock. See help for details.");
-    } else 
-        if (rc != MFE_OK) {
-        return errmsg("%s %s", errno == 0 ? "" : strerror(errno), mf_err2str(rc));
-    }
-
-    rc = mf_get_attr(_mfl, &_attr);
-    if (rc != MFE_OK) {
-        return errmsg("Failed getting flash attributes for device %s: %s", device,  mf_err2str(rc));
-    }  
-
-    if (_attr.hw_dev_id == 25204 || _attr.hw_dev_id == 24204) {
-        _port_num = 1;
-    } else {
-        _port_num = 2;
-    }
-
-    if (_byte_mode) {
-        rc = mf_set_opt(_mfl, MFO_AMD_BYTE_MODE, 1); 
-        if (rc != MFE_OK) {
-            return errmsg("Failed setting byte mode fore device %s: %s", device,  mf_err2str(rc));
-        }
-    }
-
-    return true;
-} // Flash::open
-
-////////////////////////////////////////////////////////////////////////
-void Flash::close()
-{
-    if (!_mfl)
-        return;
-
-    mf_close(_mfl); 
-    _mfl = 0;
-} // Flash::close
-
-
-bool Flash::read(u_int32_t addr, 
-                 u_int32_t *data) {
-    int rc;
-
-    u_int32_t phys_addr = cont2phys(addr);
-    rc = mf_read(_mfl, phys_addr, 4, (u_int8_t*)data);
-    if (rc != MFE_OK) {
-        return errmsg("Flash read failed at address %s%x : %s",
-                      _log2_chunk_size ? "physical " : "",
-                      addr,
-                      mf_err2str(rc));
-    }
-
-    return true;
-}
-
-////////////////////////////////////////////////////////////////////////
-bool Flash::read(u_int32_t addr, void *data, int len, bool verbose)
-{
-    int rc;
-    u_int32_t  perc = 0xffffffff;
-
-    if (addr & 0x3) {
-        return errmsg("Address should be 4-bytes aligned.");
-    }
-    if (len & 0x3) {
-        return errmsg("Length should be 4-bytes aligned.");
-    }
-
-    // Report
-    if (verbose) {
-        printf("000%%");
-        fflush(stdout);
-    }
-
-    // Much better perf for read in a single chunk. need to work on progress report though.
-    bool read_in_single_chunk = true;
-
-    if (read_in_single_chunk) {
-        u_int32_t chunk_addr;
-        u_int32_t chunk_size;
-
-        Aligner align(_log2_chunk_size);
-        align.Init (addr, len);
-        while (align.GetNextChunk(chunk_addr, chunk_size)) {
-            u_int32_t phys_addr = cont2phys(chunk_addr);
-
-            rc = mf_read(_mfl, phys_addr, chunk_size, ((u_int8_t*)data) + chunk_addr - addr);
-            if (rc != MFE_OK) {
-                return errmsg("Flash read failed at address %s%x : %s",
-                              _log2_chunk_size ? "physical " : "",
-                              chunk_addr,
-                              mf_err2str(rc));
-            }
-        }
-    
-    } else {
-        u_int32_t *p = (u_int32_t *)data;
-        for (int i=0; i<len/4; i++) {
-            if (!read(addr, p++))
-                return false;
-            
-            addr += 4;
-
-            // Report
-            if (verbose) {
-                u_int32_t new_perc = (i * 100) / len;
-                if (new_perc != perc) {
-                    printf("\b\b\b\b%03d%%", new_perc);
-                    fflush(stdout);
-                    perc = new_perc;
-                }
-            }
-        }
-    }
-    // Report
-    if (verbose) {
-        printf("\b\b\b\b100%%");
-        fflush(stdout);
-    }
-
-    return true;
-} // Flash::read
-
-
-////////////////////////////////////////////////////////////////////////
-bool Flash::write  (u_int32_t addr, 
-                   void*     data, 
-                   int       cnt,
-                   bool      noerase)
-{
-    
-    // FIX:
-    noerase = _no_erase || noerase;    
-
-    if (!_mfl) {
-        return errmsg("Not opened");
-    }
-    if (addr & 0x3) {
-        return errmsg("Address should be 4-bytes aligned.");
-    }
-
-
-    if (cont2phys(addr + cnt) > get_size()) {
-       return errmsg( 
-           "Trying to write %d bytes to address 0x%x, which exceeds max image size (0x%x - half of total flash size).",
-           cnt, 
-           addr,
-           get_size() / 2);
-    }
-    
-    u_int8_t         *p = (u_int8_t *)data;
-    u_int32_t sect_size = get_sector_size();
-
-    u_int32_t chunk_addr;
-    u_int32_t chunk_size;
-
-    u_int32_t first_set;
-    for (first_set = 0; ((sect_size >> first_set) & 1) == 0; first_set++ )
-        ;
-
-    Aligner align(first_set);
-    align.Init (addr, cnt);
-    while (align.GetNextChunk(chunk_addr, chunk_size)) {
-        // Write / Erase in sector_size alligned chunks
-        int rc;
-        
-        if (!noerase) {
-            u_int32_t sector = (chunk_addr / sect_size) * sect_size;
-            if (sector != _curr_sector) {
-                _curr_sector = sector;
-                if (!erase_sector(_curr_sector))
-                    return false;
-            }
-        }
-
-        if (_no_burn)
-            continue;
-
-        // Actual write:
-        u_int32_t phys_addr = cont2phys(chunk_addr);
-        rc = mf_write(_mfl, phys_addr, chunk_size, p);
-        if (rc != MFE_OK) {
-            return errmsg("Flash write of %d bytes to address %s0x%x failed: %s",
-                          chunk_size,
-                          _log2_chunk_size ? "physical " : "",
-                          chunk_addr,
-                          mf_err2str(rc));
-        }
-
-        // Loop advance
-        p    += chunk_size;
-    }
-
-    return true;
-}
-
-
-////////////////////////////////////////////////////////////////////////
-bool Flash::write(u_int32_t addr, u_int32_t data)
-{
-    if (!_mfl) {
-       return errmsg("Not opened");
-    }
-    if (addr & 0x3) {
-        return errmsg("Address should be 4-bytes aligned.");
-    }
-
-    u_int32_t word;
-
-    u_int32_t sector_size = _attr.sector_size;
-    u_int32_t sector_mask = ~(sector_size - 1);
-
-    u_int32_t sector = addr & sector_mask;
-    u_int32_t word_in_sector = (addr & ~sector_mask)/sizeof(u_int32_t);
-
-    if (!read(addr, &word))
-        return false;
-    if (word == data)
-        return true;   // already there
-
-    vector<u_int32_t> buff(sector_size/sizeof(u_int32_t));
-    if (!read(sector, &buff[0] , sector_size))
-        return false;
-    buff[word_in_sector] = data;
-    return write(sector, &buff[0], sector_size);
-} // Flash::write
-
-
-bool Flash::erase_sector  (u_int32_t addr) {
-    int rc;
-
-    u_int32_t phys_addr = cont2phys(addr);
-    rc = mf_erase_sector(_mfl, phys_addr);
-    if (rc != MFE_OK) {
-        return errmsg("Flash erase of address 0x%x failed: %s", 
-                      phys_addr,
-                      mf_err2str(rc));
-    }
-
-    return true;
-}
-
-bool Flash::print_attr() {
-    printf("Flash attributes:\n");
-    printf("  HwDevId          %d\n",     _attr.hw_dev_id);
-    printf("  TotalSize        0x%x\n",   _attr.size);
-    printf("  Banks            0x%x\n",   _attr.size/_attr.bank_size );
-    printf("  SectorSize       0x%x\n",   _attr.sector_size );
-    printf("  WriteBlockSize   0x%x\n",   _attr.block_write);
-    printf("  CmdSet           0x%x\n",   _attr.command_set);
-
-    return true;
-}
-
-bool Flash::print_attr_old_format() {
-    // Needed for some old tools which parce the size section of the CFI query in oder flint versions:
-
-    int i;
-    printf("\n----Sector Organization Parameters-------------------\n\n");
-
-    printf("%-50s ", "Device size:");
-    printf("[%8li] bytes, or [%2i] Mbit\n",
-           (long int)_attr.size, 
-           (int) (_attr.size/((long)0x20000)));
-
-    printf("%-50s ", "Number of erase block regions:");
-    printf("%d\n", _attr.num_erase_blocks);
-
-    for (i = 0; i < _attr.num_erase_blocks; i++) {
-        printf("  Size:[%8lx] bytes, Mask [%08x], [Number:[%4i]\n",
-               _attr.erase_block[i].sector_size,
-               _attr.erase_block[i].sector_mask,
-               _attr.erase_block[i].num_sectors);
-    }
-    return true;
-}
-
-////////////////////////////////////////////////////////////////////////
-
-
-
-////////////////////////////////////////////////////////////////////////
-//
-// Burn Operations functions
-//
-////////////////////////////////////////////////////////////////////////
-
-class Operations : public ErrMsg {
-public:
-    Operations() : 
-        _last_image_addr(0), 
-        _num_ports(2), 
-        _allow_skip_is(false), 
-        _is_cntx(false), 
-        _cntx_striped_image(false),
-        _burn_blank_guids(false) {}
-
-    enum {
-       GUIDS = 4,
-        MACS  = 2,
-        MAX_GUIDS = 6
-    };
-
-    enum ImageInfoTags {
-        II_IiFormatRevision   = 0,
-        II_FwVersion          = 1,
-        II_FwBuildTime        = 2, 
-        II_DeviceType         = 3,
-        II_PSID               = 4,
-        II_VSD                = 5,
-        II_SuppurtedPsids     = 6,
-        II_ProductVer         = 7,
-        II_VsdVendorId        = 8,
-        II_IsGa               = 9,
-        II_Last               = 10,  // Mark the end of used tag ids
-        II_End                = 0xff
-    };
-    
-    struct ImageInfo;
-
-    // Burn operations:
-    bool write_image     (Flash& f, u_int32_t addr, void *data, int cnt, bool need_report);
-    bool WriteSignature  (Flash& f, u_int32_t image_idx, u_int32_t sig);
-    bool repair          (Flash& f, const int from, const int to, bool need_report);
-    bool FailSafeBurn    (Flash& f, FImage& fim, bool need_report, bool single_image_burn);
-    bool CntxFailSafeBurn(Flash&     f, 
-                          FImage&    fim, 
-                          bool       need_report, 
-                          ImageInfo* flash_info, 
-                          ImageInfo* image_info,
-                          bool       allow_nofs = false);
-    // Image operations:
-    bool Verify          (FBase& f, ImageInfo* info = NULL, bool both_images = false);
-    bool VerifyCntx      (FBase& f, ImageInfo* info = NULL, bool both_images = false, bool only_get_start = false);
-
-    bool LoadAsExpRom    (FBase& f);
-
-    bool DumpConf        (const char* conf_file = NULL);
-    bool GetExpRomVersion(ImageInfo* info);
-
-    bool DisplayExpRomInfo(ImageInfo* info);
-    bool DisplayImageInfo (ImageInfo* info);
-
-    bool QueryAll        (FBase& f, ImageInfo* info) {return (IsCntx() ||
-                                                              (QueryIs(f, info) && 
-                                                              (!info->isFailsafe || QueryPs(f, info)))) && 
-                                                             QueryImage(f, info);}
-
-    bool getBSN          (char *s, guid_t *guid);
-    bool getGUID         (const char *s, guid_t *guid);
-
-    bool patchVSD        (FImage& f, 
-                          Operations::ImageInfo* info,
-                          const char *user_vsd, 
-                          const char *user_psid,
-                          const char *curr_vsd,
-                          const char *curr_psid,
-                          const char *image_psid);
-
-    // Misc operations
-    void SetDevFlags(u_int16_t devType, bool& ib_dev, bool& eth_dev);
-    bool CheckGuidsFlags(u_int16_t devType,
-                         bool ib_dev,
-                         bool guids_specified,
-                         bool eth_dev,
-                         bool macs_specified);
-
-    bool patchGUIDs      (FImage&    f,
-                          ImageInfo* info,
-                          bool       patch_guids, 
-                          bool       patch_macs, 
-                          bool       user_guids,
-                          bool       user_macs,
-                          guid_t     new_guids[MAX_GUIDS], 
-                          guid_t     old_guids[MAX_GUIDS],
-                          u_int32_t num_of_old_guids,
-                          bool       interactive);
-
-    bool printGUIDs(const char* msg, guid_t guids[MAX_GUIDS], bool print_guids, bool print_macs, bool old_guid_fmt);
-
-    void SetNumPorts     (u_int32_t num_ports) {_num_ports = num_ports;}
-    void SetAllowSkipIs  (bool asis)           {_allow_skip_is = asis;}
-
-    void SetBurnBlankGuids(bool b) {_burn_blank_guids = b;}
-    bool GetBurnBlankGuids() {return _burn_blank_guids;}
-
-    // ConnectX methods
-    void SetCntxMode     (bool cntx_mode)      {_is_cntx = cntx_mode;}
-    void SetCntxStripedImage(bool si)          {_cntx_striped_image = si;}
-    bool IsCntx          ()                    {return _is_cntx;}
-    bool CheckMac        (u_int64_t mac);
-
-    bool CheckIsCntx     (FBase& f);
-
-    bool CntxIsIb        (u_int32_t devid)     {return (devid == 25408) || // IB SDR
-                                                       (devid == 25418) || // IB DDR
-                                                       (devid == 25428) || // IB QDR
-                                                       (devid == 26418) || // IB DDR
-                                                       (devid == 26428);   // IB QDR
-    }
-
-    bool CntxIsEth       (u_int32_t devid)     {return (devid == 25448) || // ETH
-                                                       (devid == 26448) || // ETH
-                                                        CntxIsIb(devid);   // From FW 2.5.0, CntX ib devices also support ETH
-    }
-
-    bool CntxIsMp        (u_int32_t devid)     {return CntxIsIb(devid) && CntxIsEth(devid);}
-
-    bool ask_user        ();
-
-    // _last_image_addr is set by the Verify() op
-    u_int32_t            _last_image_addr;
-
-    // 
-    // ImageInfo struct: Everything you wanted to know about the FW image (and was afraid to ask).
-    // This struct includes both user's info (psid, dev rev , fwver ...) and tools internal
-    // info (images locations, guid ptr ...).
-    //
-    struct ImageInfo {
-        ImageInfo() :
-            invSectOk(false),
-            psOk(false),
-            imageOk(false)
-        {
-            memset(allImgStart,    0, sizeof(allImgStart));
-            memset(guids      , 0xff, sizeof(guids));
-
-            psid[0] = '\0';
-            vsd[0]  = '\0';
-            for (int i=0; i < II_Last; i++ ) 
-                infoOffs[i] = 0;
-
-            expRomFound = false;
-        }
-        
-        // *Ok : The exit status of the specific query.
-        // Note - invSectOk = true doesnt mean that invariant sector exists, it
-        //        only means that the query was OK (and isFailsafe may be false).
-
-        bool         invSectOk;
-        bool         psOk;
-        bool         imageOk;
-
-        u_int32_t    allImgStart[2];
-
-        bool         isFailsafe;
-
-        // ConnectX:
-        // For an image file where the image is marked as FW but actually contiguous, this bit would be cleared. 
-        bool         actuallyFailsafe;
-        u_int32_t    cntxLog2ChunkSize;
-
-        bool         validImage[2];
-        u_int32_t    psStart;
-        u_int32_t    imgStart;
-
-        // For ConnectX, guids 4:5 are the cards MAC addresses (if applicable)
-        guid_t       guids[MAX_GUIDS];
-        u_int32_t    guidPtr;
-        u_int32_t    guidNum;
-        bool         blankGuids;
-
-        u_int32_t    infoSectPtr;
-
-        u_int16_t    vsdVendorId;
-        char         vsd[VSD_LEN+1];
-        char         psid[PSID_LEN+1];
-        char         productVer[17];
-
-        bool         isGa;
-
-        u_int8_t     isVer;
-        u_int16_t    fwVer[3];        // = {major_ver, minor_ver , sum_minor_ver}
-        u_int16_t    fwTime[6];  // = {year, month, day, hour, minute, second}
-
-        u_int16_t    devType;
-        u_int8_t     devRev;
-
-        u_int32_t    infoOffs[II_Last];  // Offset of the tag data inside the info section data. 
-                                         // Can not be 0 (because of tag header) - 0 means not found.
-        bool         expRomFound;
-        bool         expRomValidVersion;
-        u_int16_t    expRomProductId;    // 0 - invalid.
-        u_int16_t    expRomVer[3];
-        u_int16_t    expRomDevId;
-        u_int8_t     expRomPort;
-
-        bool         magicPatternFound;
-    };
-
-    bool FwVerLessThan(u_int16_t r1[3], u_int16_t r2[3]) {
-        int i;
-        for (i = 0; i < 3 ; i++)
-            if      (r1[i] < r2[i]) 
-                return true;
-            else if (r1[i] > r2[i])
-                return false;
-            
-        return false; // equal versions
-    }
-
-    enum {CNTX_START_POS_SIZE = 6};
-
-    static const u_int32_t _cntx_image_start_pos[CNTX_START_POS_SIZE];
-
-    static const u_int32_t _cntx_magic_pattern[4];
-
-    void patchGUIDsSection      (u_int32_t *buf, u_int32_t ind,
-                                guid_t guids[GUIDS], int nguids);
-private:
-
-    bool FailSafe_burn_image   (Flash&       f, 
-                               void         *data, 
-                               int          ps_addr, 
-                               const char*  image_name, 
-                               int          image_addr,
-                               int          image_size,
-                               bool         need_report);
-
-    bool CheckInvariantSector   (Flash& f, u_int32_t *data32, int sect_size);
-
-    bool FailSafe_burn_internal (Flash& f, void *data, int cnt, bool need_report);
-
-    bool checkBoot2             (FBase& f, u_int32_t beg, u_int32_t offs,
-                                u_int32_t& next, const char *pref);
-
-    bool checkGen               (FBase& f, u_int32_t beg,
-                                 u_int32_t offs, u_int32_t& next, const char *pref);
-
-    bool checkPS                (FBase& f, u_int32_t offs, u_int32_t& next, const char *pref);
-
-    bool checkList              (FBase& f, u_int32_t offs, u_int32_t fw_start, const char *pref);
-
-    bool extractGUIDptr         (u_int32_t sign, u_int32_t *buf, int buf_len,
-                                char *pref, u_int32_t *ind, int *nguids);
-
-
-    void recalcSectionCrc       (u_int8_t *buf, u_int32_t data_size);
-
-    u_int32_t BSN_subfield      (const char *s, int beg, int len);
-
-    void PatchPs                (u_int8_t*      rawPs, 
-                                 const char     vsd[VSD_LEN],
-                                 const char     psid[PSID_LEN]   = NULL,
-                                 u_int32_t      imageAddr        = 0);
-
-    void PatchInfoSect          (u_int8_t*      rawSect,
-                                 u_int32_t      vsdOffs,
-                                 const char*    vsd);
-
-    bool QueryIs                (FBase& f,  ImageInfo* info);
-    bool QueryPs                (FBase& f,  ImageInfo* info);
-    bool QueryImage             (FBase& f,  ImageInfo* info);
-
-    bool CntxFindMagicPattern   (FBase& f,  u_int32_t addr);
-    bool CntxFindAllImageStart  (FBase& f,  u_int32_t start_locations[CNTX_START_POS_SIZE], u_int32_t* found_images);
-    bool CntxGetFsData          (FBase& f,  u_int32_t img_addr, bool& fs_en, u_int32_t& log2chunk_size);
-
-    bool ParseInfoSect          (u_int8_t* buff, u_int32_t byteSize, ImageInfo *info);
-
-    u_int32_t _num_ports;
-    bool      _allow_skip_is;
-    bool      _is_cntx;
-    bool      _cntx_striped_image;
-
-    bool      _burn_blank_guids;
-
-    std::vector<u_int8_t>  _fw_conf_sect;
-    std::vector<u_int8_t>  _rom_sect;
-};
-
-
-const u_int32_t Operations::_cntx_magic_pattern[4] = {
-    0x4D544657,   // Ascii of "MTFW" 
-    0x8CDFD000,   // Random data     
-    0xDEAD9270,                      
-    0x4154BEEF
-};
-
-const u_int32_t Operations::_cntx_image_start_pos[Operations::CNTX_START_POS_SIZE] = {
-           0,
-     0x10000,
-     0x20000,
-     0x40000,
-     0x80000,
-    0x100000
-};
-
-
-//
-// Asks user a yes/no question. 
-// Returns true if user chose Y, false if user chose N.
-//
-
-bool Operations::ask_user() {
-    printf("\n Do you want to continue ? (y/n) [n] : ");
-    if (_assume_yes)
-        printf("y\n");
-    else {
-        char ansbuff[32];
-        ansbuff[0] = '\0';
-        if (_assume_no) {
-            printf("n\n");
-            return errmsg("-no flag is set");
-        }
-
-        if (!isatty(0)) {
-            return errmsg("Not on tty - Can not interact. assuming \"no\"");
-        }
-        fflush(stdout);
-        fgets(ansbuff, 30, stdin);
-
-        if (  strcmp(ansbuff, "y\n") &&
-              strcmp(ansbuff, "Y\n") &&
-              strcmp(ansbuff, "yes\n") &&
-              strcmp(ansbuff, "Yes\n") &&
-              strcmp(ansbuff, "YES\n"))
-            return errmsg("Aborted by user");
-    }
-    return true;
-}
-
-bool Operations::write_image(Flash& f, u_int32_t addr, void *data, int cnt, bool need_report)
-{
-    u_int8_t   *p = (u_int8_t *)data;
-    u_int32_t  curr_addr = addr;
-    u_int32_t  towrite = cnt;
-    u_int32_t  perc = 0xffffffff;
-
-    //f.curr_sector = 0xffffffff;  // Erase sector first time
-    if (need_report) {
-        printf("000%%");
-        fflush(stdout);
-    }
-
-
-    while (towrite) {
-        // Write
-        int trans = (towrite > (int)Flash::TRANS) ? (int)Flash::TRANS : towrite;
-        if (!f.write(curr_addr, p, trans))
-            return errmsg("Flash write failed: %s", f.err());
-        p += trans;
-        curr_addr += trans;
-        towrite -= trans;
-
-        // Report
-        if (need_report) {
-            u_int32_t new_perc = ((cnt - towrite) * 100) / cnt;
-            if (new_perc != perc) {
-                printf("\b\b\b\b%03d%%", new_perc);
-                fflush(stdout);
-                perc = new_perc;
-            }
-        }
-    }
-
-    if (need_report) {
-        printf("\b\b\b\b100%%");
-        fflush(stdout);
-    }
-
-    return true;
-} //  Flash::write_image
-
-
-////////////////////////////////////////////////////////////////////////
-bool Operations::WriteSignature(Flash& f, u_int32_t image_idx, u_int32_t sig) {
-    u_int32_t sect_size = f.get_sector_size();
-
-    if (!f.write( sect_size * (image_idx + 1)  + 8, &sig, 4, true))
-        return false;
-
-    return true;
-}
-
-
-////////////////////////////////////////////////////////////////////////
-bool Operations::repair(Flash& f, const int from, const int to, bool need_report)
-{
-
-    u_int32_t sect_size = f.get_sector_size();
-
-    report("Repairing: Copy %s image to %s     -", from ? "secondary" : "primary" ,
-           to ? "secondary" : "primary");
-
-
-    // Read valid pointer sector
-    u_int32_t sect[sizeof(PS)/4];
-    report("\b READ %s ", from ? "SPS" : "PPS");
-    if (!f.read(from ? sect_size*2 : sect_size, sect, sizeof(sect) , need_report)) {
-        report("FAILED\n\n");
-        return false;
-    }
-    report_erase(" READ %s 100%", from ? "SPS" : "PPS");
-
-    u_int32_t im_ptr = sect[0];
-    u_int32_t sig    = sect[2];
-
-    TOCPU1(im_ptr);
-    TOCPU1(sig);
-
-    // Make sure ps ik ok:
-    if (sig != SIGNATURE) {
-        return errmsg("Can not copy image. Pointer sector %d signature is bad (%08x).", from, sig);
-    }
-
-    // Valid image size in bytes
-    u_int32_t im_size_b;
-    if (!f.read(sect_size * (from+1) + 4, &im_size_b)) {
-        report("FAILED\n\n");
-        return false;
-    }
-    TOCPU1(im_size_b);
-
-    // Valid image size in sectors
-    u_int32_t im_size_s = (im_size_b + sect_size - 1) / sect_size;
-
-    // Address to copy valid image
-    u_int32_t write_to = (!to) ? sect_size * 3 : sect_size * (3 + im_size_s);
-
-    // f.read valid image
-    report(" READ FW ");
-    fflush(stdout);
-    char *buf = new char[im_size_b];
-    if (!f.read(im_ptr, buf, im_size_b, need_report)) {
-        report("FAILED\n\n");
-        delete [] buf;
-        return false;
-    }
-    report_erase(" READ FW 100%");
-
-    // Copy it to right place
-    report("\b WRITE FW ");
-    fflush(stdout);
-    if (!write_image(f, write_to, buf, im_size_b, need_report)) {
-        report("FAILED\n\n");
-        delete [] buf;
-        return false;
-    }
-    delete [] buf;
-    report_erase(" WRITE FW 100%");
-
-    // Set new image address
-    // ++++++
-    sect[0] = __be32_to_cpu(write_to);
-
-    // Calculate new CRC
-    // ++++++
-    Crc16 crc;
-
-    for (u_int32_t i = 0; i < (sizeof(sect)/4 - 1) ; i++) {
-        crc << __be32_to_cpu(sect[i]);
-    }
-    crc.finish();
-
-    sect[sizeof(sect)/4 - 1] = __be32_to_cpu(crc.get());
-
-    // Corrupt signature
-    u_int32_t valid_signature = sect[2];
-    sect[2] = 0xffffffff;
-
-    // Write it to invalid sector
-    report("\b WRITE %s ", to ? "SPS" : "PPS");
-    if (!write_image(f, to ? sect_size*2 : sect_size, sect, sizeof(sect), need_report)) {
-        report("FAILED\n\n");
-        return false;
-    }
-    report_erase(" WRITE %s 100%", to ? "SPS" : "PPS");
-
-    // Validate signature
-    report("\b SIGNATURE     ");
-    if (!WriteSignature(f, to, valid_signature)) {
-        report("FAILED\n\n");
-        return false;
-    }
-
-    report_erase(" SIGNATURE     ");
-    report(" OK       \n");
-    return true;
-} // Flash::repair
-
-
-
-
-
-////////////////////////////////////////////////////////////////////////
-bool Operations::FailSafe_burn_image(Flash&       f, 
-                         void         *data, 
-                         int          ps_addr, 
-                         const char*  image_name, 
-                         int          image_addr,
-                         int          image_size,
-                         bool         need_report) {
-
-    u_int8_t* data8 = (u_int8_t*) data;
-    u_int32_t sect_size = f.get_sector_size();
-
-    report("Burning %-6s FW image without signatures  - ", image_name);
-    fflush(stdout);
-
-    // Invalidate signature
-    u_int32_t zeros = 0;
-    if (!f.write(ps_addr + 8, &zeros, 4, true)) {
-        report("FAILED (Invalidating signature)\n\n");
-        return false;
-    }
-
-    // Burn image (from new offset)
-
-    // Both burnt images are taken from the first image in the file - both images in file are identical.
-    // (future binary releases may contain a single image).
-    if (!write_image(f, image_addr, data8 + sect_size * 3, image_size, need_report)) {
-        report("FAILED\n\n");
-        return false;
-    }
-    report("\b\b\b\bOK  \n");
-    report("Restoring %-6s signature                  - ", image_name); 
-    fflush(stdout);
-
-    // Burn PS
-    if (!write_image(f, ps_addr, data8 + ps_addr, sect_size, false)) {
-        report("FAILED\n\n");
-        return false;
-    }
-
-    // Validate signature
-    u_int32_t sig = SIGNATURE;
-    TOCPU1(sig);
-    if (!f.write(ps_addr + 8, &sig, 4, true)) {
-        report("FAILED\n\n");
-        return false;
-    }
-
-    report("OK  \n");
-
-    return true;
-}   
-
-
-////////////////////////////////////////////////////////////////////////
-bool Operations::FailSafe_burn_internal(Flash& f, void *data, int cnt, bool need_report)
-{
-    u_int32_t *data32 = (u_int32_t *)data;
-
-    u_int32_t sect_size = f.get_sector_size();
-
-    // Extract Primary/Secondary image pointers and lengths
-    u_int32_t prim_ptr = data32[sect_size / 4];
-    u_int32_t prim_len = data32[sect_size / 4 + 1];
-    u_int32_t scnd_ptr = data32[(sect_size * 2) / 4];
-    u_int32_t scnd_len = data32[(sect_size * 2) / 4 + 1];
-    TOCPU1(prim_ptr);
-    TOCPU1(prim_len);
-    TOCPU1(scnd_ptr);
-    TOCPU1(scnd_len);
-    if ((cnt < (int)(prim_ptr + prim_len)) || (cnt < (int)(scnd_ptr + scnd_len))) {
-        return errmsg("Invalid image: too small.");
-    }
-    if (prim_len != scnd_len) {
-        return errmsg("Invalid image: two FW images should have the same size.");
-    }
-
-    // Image size from flash
-    u_int32_t old_im_size;
-    if (!f.read(sect_size + 4, &old_im_size)) {
-        report("FAILED\n\n");
-        return false;
-    }
-    TOCPU1(old_im_size);
-
-    u_int32_t prim_order;
-    u_int32_t scnd_order;
-
-    u_int32_t ps_addr[2];
-    u_int32_t image_addr[2];
-    char*     image_name[2];
-
-
-    if (prim_len > old_im_size) {
-        scnd_order = 0;
-        prim_order = 1;
-    } else {
-        prim_order = 0;    
-        scnd_order = 1;
-    }
-
-    image_name[scnd_order] = "Secondary";
-    image_addr[scnd_order] = scnd_ptr;
-    ps_addr   [scnd_order] = sect_size * 2;
-
-    image_name[prim_order] = "Primary";
-    image_addr[prim_order] = prim_ptr;
-    ps_addr   [prim_order] = sect_size; 
-
-
-    for (int i = 0 ; i < 2 ; i++) {
-        if (!FailSafe_burn_image(f, data, ps_addr[i], image_name[i], image_addr[i], prim_len, need_report)) {
-            return false;
-        }
-    }
-
-    return true;
-}
-
-bool Operations::CheckInvariantSector(Flash& f, u_int32_t *data32, int sect_size) {
-    int i;
-
-    report("\nRead and verify Invariant Sector            - ");
-    fflush(stdout);
-
-    // Once more check signature - the Inv.Sector signature should be OK
-    u_int32_t signature;
-    if (!f.read(0x24, &signature)) {
-        report("FAILED\n\n");
-        return false;
-    }
-    TOCPU1(signature);
-    if (signature != SIGNATURE) {
-        report("FAILED\n\n");
-       return errmsg("Flash has wrong signature in Invariant Sector (Expected %08x, got %08x).", SIGNATURE, signature);
-    }
-
-    // Now check Invariant sector contents
-    vector<u_int32_t> buf1(sect_size/4);
-
-    if (!f.read(0, &buf1[0] , sect_size)) {
-        report("FAILED\n\n");
-        return false;
-    }
-
-    int first_diff = -1;
-
-    for (i=0; i < sect_size/4; i++) {
-        if (buf1[i] != data32[i]  &&  (data32[i] != 0 || buf1[i] != 0xffffffff)) {
-            if (first_diff == -1) 
-                first_diff = i;
-        }
-    }
-
-    // Check if a diff was found:
-    if (first_diff != -1) {
-            report("DIFF DETECTED\n\n");
-            printf(" Invariant sector mismatch. Address 0x%x "
-                   " in image: 0x%08x, while on flash: 0x%08x\n\n",
-                   first_diff*4 , data32[first_diff], buf1[first_diff]);
-
-            printf(" The invariant sector can not be burnt in a failsafe manner.\n");
-
-        if (_allow_skip_is) {
-            printf(" You can continue the FW update without burning the invariant sector.\n"
-                   " See FW release notes for details on invariant sector updates.\n\n");
-
-            return ask_user();
-
-        } else {
-            // Continue with burn
-            printf(" You can perform the FW update without burning the invariant sector by\n"
-                   " by specifying the -skip_is flag.\n" 
-                   " See FW release notes for details on invariant sector updates.\n\n");
-
-            return errmsg("Invariant sector mismatch");
-        }
-    }
-
-    report("OK\n");
-    return true;
-
-}
-
-////////////////////////////////////////////////////////////////////////
-bool Operations::FailSafeBurn(Flash& f, FImage& fim, bool need_report, bool single_image_burn)
-{
-    u_int32_t *data32 = fim.getBuf();
-    u_int8_t  *data8  = (u_int8_t *) data32;
-    void*      data   = data8;
-    int        size   = fim.getBufLength();
-
-    u_int32_t i;
-        
-    u_int32_t sect_size     = f.get_sector_size();
-    u_int32_t img_sect_size = fim.get_sector_size();
-
-    // Check that the flash sector size is well defined in the image
-    if (img_sect_size && (img_sect_size != sect_size)) {
-        return errmsg("Flash sector size(0x%x) differs from sector size defined in the image (0x%x).\n"
-                      "This means that the given FW file is not configured to work with the burnt HCA board type.\n",
-                      sect_size,
-                      img_sect_size);
-    }
-
-    if (size < (int)sect_size * 3) {
-        report("FAILED\n\n");
-        return errmsg("Image is too small.");
-    }
-
-    if (!CheckInvariantSector(f, data32, sect_size)) {
-        return false;
-    }
-
-    // Check signatures in image
-    u_int32_t actual_signature = data32[sect_size/4 + 2];
-
-    u_int32_t signature_for_compare = actual_signature;
-
-    TOCPU1(signature_for_compare);
-    if (signature_for_compare != SIGNATURE) {
-        return errmsg("Bad image file given: signature in PPS is 0x%08x (should be 0x%08x)",
-                     signature_for_compare, SIGNATURE);
-    }
-    signature_for_compare = data32[(sect_size * 2)/4 + 2];
-    TOCPU1(signature_for_compare);
-    if (signature_for_compare != SIGNATURE) {
-        return errmsg("Bad image file given: signature in SPS is 0x%08x (should be 0x%08x)",
-                     signature_for_compare, SIGNATURE);
-    }
-
-    // Corrupt signatures in image
-    data32[sect_size/4 + 2] = 0xffffffff;
-    data32[(sect_size * 2)/4 + 2] = 0xffffffff;
-
-    bool       cur_image_ok[2] = {false, false};
-    u_int32_t  cur_image_addr[2];
-    u_int32_t  cur_image_size[2];
-
-    // Check signatures on flash
-    report("Read and verify PPS/SPS on flash            - ");
-    for (i = 0 ; i < 2 ; i++) {
-        if (!f.read(sect_size * (i+1) + 8, &signature_for_compare)) {
-
-        }
-        TOCPU1(signature_for_compare);
-        if (signature_for_compare == SIGNATURE) {
-            cur_image_ok[i] = true;
-            
-            if (!f.read(sect_size * (i+1)    , &cur_image_addr[i]) ||
-                !f.read(sect_size * (i+1) + 4, &cur_image_size[i])) {
-                 report("FAILED\n\n");
-                 return false;           
-            }
-  
-            TOCPU1(cur_image_addr[i]);
-            TOCPU1(cur_image_size[i]);
-        }
-    }
-
-    if (!cur_image_ok[0] && !cur_image_ok[1]) {
-        //
-        // Both images are invalid on flash
-        // --------------------------------
-        //
-        printf("\nBoth images (primary and secondary) are invalid on flash.\n");
-        printf("The burning can not be failsafe, but it is harmless for host.\n");
-        if(!ask_user()) {
-            return false;
-        }
-
-        // Burn all image
-        report("Burn FW image without signatures - ");
-        fflush(stdout);
-        if (!write_image(f, sect_size, data8 + sect_size, size - sect_size, need_report)) {
-            report("FAILED\n\n");
-            return false;
-        }
-        report("\b\b\b\bOK  \n");
-
-        // Restore signatures
-        report("Restore right signatures         - ");
-        fflush(stdout);
-        if (!WriteSignature(f, 0, actual_signature)) {
-            report("FAILED (PPS Signature)\n\n");
-            return false;
-        }
-        if (!WriteSignature(f, 1, actual_signature)) {
-            report("FAILED (SPS Signature)\n\n");
-            return false;
-        }
-        report("OK\n");
-        return true;
-    } else {
-        report("OK\n"); 
-    }
-
-    if (single_image_burn == false) {
-
-        if (cur_image_ok[0] == false || cur_image_ok[1] == false) {
-            int image_from;
-            int image_to;
-
-           assert (cur_image_ok[1] || cur_image_ok[0]);
-
-            if (cur_image_ok[1]) {
-                image_from = 1;
-                image_to   = 0;
-            } else {
-                image_from = 0;
-                image_to   = 1;
-            }
-
-           report("Reparable Error Detected.\n");
-           if (!repair(f, image_from, image_to, need_report))
-                   return false;
-        }
-
-        //
-        // Both images are valid on flash
-        //
-        return FailSafe_burn_internal(f, data, size, need_report);
-
-    } else {
-
-        //
-        // Single image burn:
-        //
-
-        // Extract Primary/Secondary image pointers and lengths
-        u_int32_t frst_new_image_addr = data32[sect_size / 4];
-        u_int32_t frst_new_image_size = data32[sect_size / 4 + 1];
-        TOCPU1(frst_new_image_addr);
-        TOCPU1(frst_new_image_size);
-
-        if (!cur_image_ok[0] && cur_image_ok[1]) {
-            // Second image is valid on flash.
-            // If the new image can fit in the first image gap, it would be
-            //   burnt as first image.
-            // Otherwise (new image too big), image on flash is copied from second to 
-            //   first image, and new image would be written as second.
-
-            if (frst_new_image_addr + frst_new_image_size > cur_image_addr[1]) {
-                // New image is too large - can not get in between first image start 
-                // and current (second) image - move current image to be first.
-                if (!repair(f, 1, 0, need_report))
-                    return false;
-
-                // Now 2 images are valid
-                cur_image_ok[0] = true;
-            } else {
-                if (!FailSafe_burn_image(f, data, sect_size, "first", sect_size * 3, frst_new_image_size, need_report))
-                    return false;
-
-                if (!WriteSignature(f, 1, 0))
-                    return false;
-
-                return true;
-            }
-        }
-
-        if (cur_image_ok[0] && cur_image_ok[1]) {
-            // Invalidate second image
-            if (!WriteSignature(f, 1, 0)) {
-                report("FAILED\n");
-                return false;
-            }
-
-            cur_image_ok[1] = false;
-        }
-
-        if (cur_image_ok[0] && !cur_image_ok[1]) {
-            u_int32_t new_image_size_sect = ((frst_new_image_size - 1) / sect_size) + 1 ;
-  
-            // First image is valid on flash.
-            // If the new image is smaller than current image, it would
-            // overwrite the end of current image. In this case, move the current image
-            // to the second position and burn in first.
-            //
-            // TODO: STOP THIS MOVEMENT BULLSHI%@#&! !!! : Reproduce PS in flint with the correct addr. Locate second image in middle of flash. 
-
-            if ( (3 + new_image_size_sect) * sect_size < cur_image_addr[0] + cur_image_size[0]) {
-                // New image overwrites end of cur image
-                // move current image to be second.
-                if (!repair(f, 0, 1, need_report))
-                    return false;
-
-                // Now 2 images are valid
-                cur_image_ok[1] = true;
-
-                // Burn new image as firse
-                if (!FailSafe_burn_image(f, data, sect_size, "first", 
-                                         sect_size * 3, frst_new_image_size, need_report))
-                    return false;
-
-                if (!WriteSignature(f, 1, 0))
-                    return false;
-
-                return true;
-
-            } else {
-                if (!FailSafe_burn_image(f, data, sect_size * 2, "second", 
-                                     sect_size * (3 + new_image_size_sect) , frst_new_image_size, need_report))
-                    return false;
-
-                // Invalidate first image 
-                if (!WriteSignature(f, 0, 0))
-                    return false;
-
-                return true;
-
-            }
-        } else {
-            report("Bad flash state: Valid images = (%d,%d).\n", cur_image_ok[0], cur_image_ok[1] );
-            return false;
-        }
-
-    }
-
-    return true;
-}
-
-bool Operations::CntxFailSafeBurn(Flash&    f, 
-                                  FImage&   fim, 
-                                  bool      need_report, 
-                                  Operations::ImageInfo* flash_info, 
-                                  Operations::ImageInfo* image_info,
-                                  bool      allow_nofs) {
-
-    // TODO: See getBuf effect on zebra image.
-    u_int8_t  *data8      = (u_int8_t *) fim.getBuf();
-    int        image_size = fim.getBufLength();
-    u_int32_t  zeroes     = 0;
-
-    bool is_curr_image_in_odd_chunks;
-
-    if (!allow_nofs) {
-        if (!image_info->isFailsafe) {
-            return errmsg("The given image is not a failsae image");
-        }
-
-        if (flash_info->cntxLog2ChunkSize != image_info->cntxLog2ChunkSize) {
-            return errmsg("Failsafe chunk sizes in flash (0x%x) and in image (0x%x) are not the same.",
-                          1 << flash_info->cntxLog2ChunkSize,
-                          1 << image_info->cntxLog2ChunkSize);
-        }
-    }
-
-    u_int32_t new_image_start;
-
-    if (flash_info->imgStart != 0) {
-        is_curr_image_in_odd_chunks = 1;
-        new_image_start = 0;
-    } else {
-        is_curr_image_in_odd_chunks = 0;
-        new_image_start = (1 << image_info->cntxLog2ChunkSize);
-    }
-
-    //printf("-I- Chunk=%x . Cur image start=%x burning from %x, flash_log2_chunk_size=%d\n", 
-    //       1 << flash_info->cntxLog2ChunkSize, 
-    //       flash_info->imgStart, 
-    //       new_image_start,
-    //       flash_info->cntxLog2ChunkSize);
-
-    if (image_info->isFailsafe) {
-        f.set_address_convertor(image_info->cntxLog2ChunkSize, !is_curr_image_in_odd_chunks);
-    } else {
-        f.set_address_convertor(0,0);
-        new_image_start = 0;
-    }
-
-    // Go ahead and burn!
-    const char* image_name = new_image_start == 0 ? "first" : "second";
-    report("\nBurning %-6s FW image without signatures  - ", image_name);
-
-    fflush(stdout);
-
-    if (!write_image(f, 16 , data8 + 16, image_size - 16, need_report)) {
-        report("FAILED\n\n");
-        return false;
-    }
-    report("\b\b\b\bOK  \n");
-
-    report("Restoring %-6s signature                  -     ", image_name); 
-
-    fflush(stdout);
-
-    // Write new signature
-    if (!f.write(0, data8, 16, true)) {
-        report("FAILED\n\n");
-        return false;
-    }
-
-    // Write new image start address to crspace (for SW reset)
-    f.cr_write(0xf0000, (new_image_start << 8) | 0x06);
-
-    if (image_info->isFailsafe) {
-        if (allow_nofs) {
-            // When burning in nofs, remnant of older image with different chunk size
-            // may reside on the flash - 
-            // Invalidate all images marking on flash except the one we've just burnt
-
-            u_int32_t cntx_image_start[CNTX_START_POS_SIZE];
-            u_int32_t cntx_image_num;
-            u_int32_t i;
-
-            CntxFindAllImageStart(f, cntx_image_start, &cntx_image_num);
-            // Address convertor is disabled now - use phys addresses
-            for (i = 0; i < cntx_image_num; i++) {
-                if (cntx_image_start[i] != new_image_start) {
-                    if (!f.write(cntx_image_start[i], &zeroes, sizeof(zeroes), true)) {
-                        report("FAILED\n\n");
-                        return false;
-                    } 
-                }
-            }
-        } else {
-            // invalidate previous signature
-            f.set_address_convertor(image_info->cntxLog2ChunkSize, is_curr_image_in_odd_chunks);
-            if (!f.write(0, &zeroes, sizeof(zeroes), true)) {
-                report("FAILED\n\n");
-                return false;
-            }
-        }
-    }
-    report("\b\b\b\bOK  \n");
-
-    if (allow_nofs && image_info->isFailsafe) {
-
-    }
-
-    return true;
-}
-
-
-
-
-////////////////////////////////////////////////////////////////////////
-//                                                                    //
-// ****************************************************************** //
-//                        VERIFY FLASH                                //
-// ****************************************************************** //
-//                                                                    //
-////////////////////////////////////////////////////////////////////////
-
-
-//
-// Cntx image verification flow:
-// 
-// The "zebra"failsafe scheme presents few problems:
-// - Need to search for a valid image in the flash.
-// - handle no image / more than a single valid image cases
-// - check image actual start location(s) vs. fs_zebra_size field in the image.
-// - Image file is not striped though its fs_zebra_size sais it is - need to allow that
-//   when checking a file.
-//
-// Verification flow:
-// 
-// 1. Find image start addresses.
-//    if num of start_addr not in [1,2] - Error - corrupted flash
-// 2. for each start_addr:
-//      Check that its fs_zebra_size is identical to other images (if exists)
-//      For Flash: 
-//          Set address translation according to the fs_zebra_size.
-//      For File:
-//          *GUESS* if image is contiguous or striped. This can be according
-//          to the file size vs. image size field in the image.
-//          Set address translation according to the fs_zebra_size or to 0.
-//      verify - same as previous projects nofs image, with the aditional start
-//
-
-
-bool Operations::CntxFindMagicPattern       (FBase& f,  u_int32_t addr) {
-    int i;
-    if (addr + 16 > f.get_size()) {
-        return false;
-    }
-    for (i = 0; i < 4 ; i++) {
-        u_int32_t w;
-        READ4(f, addr + i * 4, &w, "Magic Pattern" );
-        TOCPU1(w);
-        if (w != _cntx_magic_pattern[i]) {
-            //printf("-D- Looking for magic pattern %d addr %06x: Exp=%08x Act=%08x\n", i, addr + i * 4, _cntx_magic_pattern[i], w);
-            return false;
-        }
-    }
-
-    return true;
-}
-
-// FindAllImageStart
-// OUT: start_locations: set to the start addresses of the found image markers (in accending order)
-// OUT: found_images:    Number of found images (and number of valid entries in the start_locations array).
-bool Operations::CntxFindAllImageStart       (FBase& f,  u_int32_t start_locations[CNTX_START_POS_SIZE], u_int32_t* found_images) {
-    int i;
-    f.set_address_convertor(0,0);
-
-    *found_images = 0;
-    for (i = 0; i < CNTX_START_POS_SIZE; i++) {
-        if (CntxFindMagicPattern(f, _cntx_image_start_pos[i])) {
-            start_locations[*found_images] = _cntx_image_start_pos[i];
-            (*found_images)++;
-        }
-    }
-
-    return true;
-}
-
-bool Operations::checkBoot2(FBase& f, u_int32_t beg, u_int32_t offs,
-                u_int32_t& next, const char *pref)
-{
-    u_int32_t    size;
-
-    char         *pr = (char *)alloca(strlen(pref) + 512);
-
-    sprintf(pr, "%s /0x%08x/ (BOOT2)", pref, offs+beg);
-
-    // Size
-    READ4(f, offs+beg+4, &size, pr);
-    TOCPU1(size);
-    if (size > 1048576 || size < 4) {
-        report("%s /0x%08x/ - unexpected size (0x%x)\n", pr, offs+beg+4, size);
-        return false;
-    }
-
-    sprintf(pr, "%s /0x%08x-0x%08x (0x%06x)/ (BOOT2)", pref, offs+beg,
-            offs+beg+(size+4)*4-1, (size+4)*4);
-
-    Crc16        crc;
-    u_int32_t    *buff = (u_int32_t*)alloca((size + 4)*sizeof(u_int32_t));
-
-    READBUF(f, offs+beg, buff, size*4 + 16, pr);
-    TOCPUn(buff, size+4);
-    CRC1n(crc, buff, size+4);
-    crc.finish();
-    u_int32_t crc_act = buff[size+3];
-    if (crc.get() != crc_act) {
-        report("%s /0x%08x/ - wrong CRC (exp:0x%x, act:0x%x)\n",
-               pr, offs+beg, crc.get(), crc_act);
-        return errmsg("Bad CRC");
-    }
-
-    if (_print_crc)
-        report("%s - OK (CRC:0x%04x)\n", pr, crc_act&0xffff);
-    else
-        report("%s - OK\n", pr);
-    next = offs + size*4 + 16;
-    return true;
-} // checkBoot2
-
-static int part_cnt;
-
-////////////////////////////////////////////////////////////////////////
-bool Operations::checkGen(FBase& f, u_int32_t beg,
-              u_int32_t offs, u_int32_t& next, const char *pref)
-{
-    char         *pr = (char *)alloca(strlen(pref) + 100);
-
-    char         unknown_sect_name[128];
-    const char*  sect_name;
-
-    u_int32_t    size=0;
-    GPH          gph;
-
-    // GPH
-    sprintf(pr, "%s /0x%08x/ (GeneralHeader)", pref, offs+beg);
-    READBUF(f, offs+beg, &gph, sizeof(GPH), pr);
-    TOCPUBY(gph);
-
-    // Body
-    part_cnt++;
-
-    // May be BOOT3?
-    if (gph.type < H_FIRST  ||  gph.type >= H_LAST) {
-        if (part_cnt > 2) {
-            //report("%s /0x%x/ - Invalid partition type (%d)\n",
-            //       pref, offs+beg, gph.type);
-            //return false;
-        } else
-            return checkBoot2(f, beg, offs, next, pref);
-    }
-
-    // All partitions here
-    offs += beg;
-
-    if (gph.type < H_FIRST  ||  gph.type >= H_LAST) {
-        // For forward compatibility, try analyzing even if section type is uncknown
-        // Assuming the size is in DW, like all other sections (except emt service).
-        // If this assumption is wrong, CRC calc would fail - no harm done.
-        sprintf(unknown_sect_name, "UNKNOWN (%d)" , gph.type);
-        sect_name = unknown_sect_name;
-        size = gph.size * 4;
-    } else {
-        if (gph.type == H_EMT) {
-            size = (gph.size + 3) / 4 * 4;
-        } else {
-            size = gph.size * 4;
-        }
-        sect_name = g_sectNames[gph.type];
-    }
-
-    sprintf(pr, "%s /0x%08x-0x%08x (0x%06x)/ (%s)",
-                pref, offs, offs+size+(u_int32_t)sizeof(gph)+3,
-                size+(u_int32_t)sizeof(gph)+4, sect_name);
-    
-    if (size > MAX_SECTION_SIZE) {
-        report("%s - size too big (0x%x)\n",
-               pr, size);
-        return false;
-    }
-
-    // CRC
-    Crc16        crc;
-    std::vector<u_int8_t> buffv(size);
-    u_int32_t *buff = (u_int32_t*)(&(buffv[0]));
-
-    READBUF(f, offs+sizeof(gph), buff, size, pr);
-
-    TOCPUn(buff,size/4);
-    CRCBY(crc, gph);
-    CRCn(crc, buff, size/4);
-    crc.finish();
-    u_int32_t crc_act;
-    READ4(f, offs+sizeof(gph)+size, &crc_act, pr);
-    TOCPU1(crc_act);
-    bool blank_crc = false;
-    if (gph.type == H_GUID && crc_act == 0xffff) {
-        blank_crc = true;
-    } else if (crc.get() != crc_act) {
-        report("%s /0x%08x/ - wrong CRC (exp:0x%x, act:0x%x)\n",
-               pr, offs, crc.get(), crc_act);
-        return errmsg("Bad CRC");
-    }
-
-    if (_print_crc)
-        report("%s - OK (CRC:0x%04x)\n", pr, crc_act&0xffff);
-    else
-        if (blank_crc) {
-            report("%s - BLANK CRC (0xffff)\n", pr);
-        } else {
-            report("%s - OK\n", pr);
-        }
-    next = gph.next;
-
-    if (gph.type == H_FW_CONF) {
-        _fw_conf_sect.clear();
-        _fw_conf_sect.insert(_fw_conf_sect.end(), 
-                         vector<u_int8_t>::iterator((u_int8_t*)buff), 
-                         vector<u_int8_t>::iterator((u_int8_t*)buff + size));
-
-    }
-
-    if (gph.type == H_ROM && _rom_sect.empty()) {
-        _rom_sect.clear();
-        _rom_sect.insert(_rom_sect.end(), 
-                         vector<u_int8_t>::iterator((u_int8_t*)buff), 
-                         vector<u_int8_t>::iterator((u_int8_t*)buff + size));
-    }
-
-    // mark last read addr
-    _last_image_addr = offs + size +sizeof(gph) + 4;  // the 4 is for the trailing crc
-    
-    return true;
-} // checkGen
-
-////////////////////////////////////////////////////////////////////////
-bool Operations::checkPS(FBase& f, u_int32_t offs, u_int32_t& next, const char *pref)
-{
-    Crc16 crc;
-    PS    ps;
-    f.read(offs, &ps, sizeof(ps));
-    TOCPUBY(ps);
-
-    // Signature
-    if (ps.signature != SIGNATURE) {
-        report("%s Pointer Sector /0x%08x/ - invalid signature (%08x)\n",
-               pref, offs, ps.signature);
-        return false;
-    }
-
-    // CRC
-    CRC1BY(crc, ps);
-    crc.finish();
-    if (crc.get() != ps.crc016) {
-        report("%s Pointer Sector /0x%08x/ - wrong CRC (exp:0x%x, act:0x%x)\n",
-               pref, offs, ps.crc016, crc.get());
-        return errmsg("Bad CRC");
-    }
-
-    next = ps.fi_addr;
-    if (_print_crc)
-        report("%s Image /0x%08x-0x%08x (0x%06x)/ (Pointer Sector)- OK (CRC:0x%04x)\n", pref, offs,
-               offs+(u_int32_t)sizeof(ps)-1, (u_int32_t)sizeof(ps), ps.crc016&0xffff);
-    else
-        report("%s Image /0x%08x-0x%08x (0x%06x)/ (Pointer Sector)- OK\n", pref, offs,
-               offs+(u_int32_t)sizeof(ps)-1, (u_int32_t)sizeof(ps));
-    return true;
-} // checkPS
-
-////////////////////////////////////////////////////////////////////////
-bool Operations::checkList(FBase& f, u_int32_t offs, u_int32_t fw_start, const char *pref)
-{
-    u_int32_t next_ptr;
-
-    CHECKB2(f, offs, fw_start, next_ptr, pref);
-    part_cnt = 1;
-    while (next_ptr && next_ptr != 0xff000000)
-        CHECKGN(f, offs, next_ptr, next_ptr, pref);
-
-    return true;
-} // checkList
-
-////////////////////////////////////////////////////////////////////////
-
-bool Operations::CheckIsCntx(FBase& f) {
-    if (f.is_flash()) {
-        return (((Flash*)&f)->get_dev_id() == 400);
-    } else {
-        u_int32_t found_images;
-        u_int32_t image_start[CNTX_START_POS_SIZE];
-
-        // Image - check if magic pattern is somewhere in the file:
-        CntxFindAllImageStart(f, image_start, &found_images);
-        return found_images > 0;
-    }
-}
-
-bool Operations::CheckMac(u_int64_t mac) {
-    if ((mac >> 40) & 0x1) {
-        return errmsg("Multicast bit (bit 40) is set");
-    }
-
-    if (mac >> 48) {
-        return errmsg("More than 48 bits are used");
-    }
-
-    return true;
-}
-
-
-bool Operations::CntxGetFsData(FBase& f, u_int32_t img_addr, bool& fs_en, u_int32_t& log2chunk_size) {
-    u_int32_t fs_info_word;
-    u_int8_t  checksum;
-
-    f.read(img_addr + 0x28, &fs_info_word);
-    TOCPU1(fs_info_word);
-
-    // printf("-D- fs_info_word=%08x\n", fs_info_word);
-
-    checksum = ((fs_info_word      ) & 0xff) +
-               ((fs_info_word >>  8) & 0xff) +
-               ((fs_info_word >> 16) & 0xff) +
-               ((fs_info_word >> 24) & 0xff);
-
-    if (checksum != 0) {
-        return errmsg("Corrupted chunk size checksum");
-    }
-
-    fs_en = (fs_info_word & 0x8) != 0;
-
-    if (fs_en) {
-        log2chunk_size = (fs_info_word & 0x7) + 16;
-    } else {
-        log2chunk_size = 0;
-    }
-
-    return true;
-}
-
-bool Operations::VerifyCntx(FBase& f, Operations::ImageInfo* info, bool both_images, bool only_get_start) {
-    u_int32_t cntx_image_start[CNTX_START_POS_SIZE];
-    u_int32_t cntx_image_num;
-    u_int32_t i;
-    bool      ret = true;
-
-    // Look for image in "physical addresses
-
-    CntxFindAllImageStart(f, cntx_image_start, &cntx_image_num);
-
-    if (cntx_image_num == 0) {
-        return errmsg("No valid image found");
-    } else if (cntx_image_num > 2) {
-                // This check may be redundant - Maybe ignore if more than 2 images found
-                return errmsg("More than 2 image start locations found at addresses %x, %x and %x. Image may be corrupted.",
-                              cntx_image_start[0],
-                              cntx_image_start[1],
-                              cntx_image_start[2]);
-    }
-
-    if (!both_images) {
-        // Check only the first image. This is enough to ensure that the device is bootable.
-        cntx_image_num = 1;
-    }
-
-    bool info_set = false;
-
-    // Verify the images:
-    for (i = 0; i < cntx_image_num; i++ ) {
-        bool      fs_en;
-        u_int32_t log2chunk_size;
-
-        f.set_address_convertor(0,0);
-        if (!CntxGetFsData(f, cntx_image_start[i], fs_en, log2chunk_size)) {
-            report("\n    Can't read failsafe info word: %s\n", err());
-
-            return (i > 0);
-        }
-
-        // If fw not enabled, image must start at addr 0
-        if (!fs_en && cntx_image_start[i] != 0) {
-            return errmsg("ConnectX Non Failsafe image must start at address 0. Found non-fs image at address %x",
-                          cntx_image_start[i]);
-        }
-
-        if (fs_en) {
-            report("\n     ConnectX failsafe image. Start address: %x. Chunk size %x:\n\n", cntx_image_start[i], 1 << log2chunk_size);
-            report("     NOTE: The addresses below are contiguous logical addresses. Physical addresses on\n"
-                   "           flash may be different, based on the image start address and chunk size\n\n");
-        } else {
-            report("\n     ConnectX non failsafe image:\n\n");
-        }
-
-        if (fs_en && cntx_image_start[i] != 0 && cntx_image_start[i] != (u_int32_t)(1 << log2chunk_size)) {
-            return errmsg("ConnectX Failsafe image must start at address 0 or at chunk size. Found a failsafe image at address %x",
-                          cntx_image_start[i]);
-        }
-
-        if (info && !info_set) {
-            info->imgStart          = cntx_image_start[i];
-            info->isFailsafe        = fs_en;
-            info->actuallyFailsafe  = true;
-            info->cntxLog2ChunkSize = log2chunk_size;
-        }
-
-        if (f.is_flash()) {
-            // In flash, image layout must match the FS Data
-            if (info && !info_set) {
-                info->actuallyFailsafe    = true;
-                info_set = true;
-            }
-
-            if (fs_en) {
-                f.set_address_convertor(log2chunk_size, cntx_image_start[i] != 0);
-            }
-        } else {
-            // In an image file there are 2 cases:
-            // 1. Image generated by mlxburn 
-            //    The image in the file is contiguous (though it is marked as FS) - no need to set address convertion.
-            // 2. The image was raw read from flash. In this case it would be in "zebra" format.
-            //
-            // So - I try both cases, and see which verify() succeeds.
-            //
-            // Heuristics that may come in handy:
-            // If the image does not start at addr 0, it's not an mlxburn image.
-            // If there is more than a single valid image, it's not an mlxburn image.
-            // If the file size matches the image size, it is an mlxburn image.
-            //
-            // For now, get the "striped" indication from user.
-
-            if (_cntx_striped_image) {
-                f.set_address_convertor(log2chunk_size, cntx_image_start[i] != 0);
-            } else {
-                f.set_address_convertor(0,0); //disable conversion
-            }
-            if (info && !info_set) {
-                info->actuallyFailsafe    = _cntx_striped_image;
-                info_set = true;
-            }   
-        }
-
-        bool imgStat = true;
-
-        if (!only_get_start) {
-            imgStat = checkList(f, 0, 0x38, "    ");
-        }
-        if (i == 0) {
-            ret = ret && imgStat;
-        }
-    }
-    return ret;
-}
-
-bool Operations::Verify(FBase& f, Operations::ImageInfo* info, bool both_images)
-{
-    u_int32_t prim_ptr, scnd_ptr;
-    u_int32_t signature;
-
-    bool      ret = true;
-
-    if (IsCntx()) {
-        return VerifyCntx(f, info, both_images);
-    }
-
-    READ4(f, 0x24, &signature, "Signature");
-    TOCPU1(signature);
-    if (signature == SIGNATURE) {
-        // Full image
-
-        bool psStat[2];
-
-        report("\nFailsafe image:\n\n");
-        CHECKB2(f, 0, 0x28, prim_ptr, "Invariant      ");
-        report("\n");
-        psStat[0] = checkPS(f, f.get_sector_size(), prim_ptr, "Primary  ");
-        if (psStat[0]) {
-            ret &= checkList(f, prim_ptr, 0x28, "               ");
-        }
-        report("\n");
-
-        if (psStat[0] && !both_images) {
-            return ret;
-        }
-
-        psStat[1] = checkPS(f, f.get_sector_size() * 2, scnd_ptr, "Secondary");
-        bool scndStat;
-        if (psStat[1]) {
-            scndStat = checkList(f, scnd_ptr, 0x28, "               ");
-            if (!psStat[0]) {
-                // If the first image is valid, the HCA would boot OK even if the secondary image is messed up - 
-                // consider this status only if the first image is not valid.
-                ret &= scndStat;
-            }
-        }
-
-        if (psStat[0] == false && psStat[1] == false) {
-            ret = false;
-        }
-    } else {
-
-        report("\nShort image:\n");
-        CHECKLS(f, 0, 0x28, "    ");
-    }
-
-    return ret;
-} // Verify
-
-bool Operations::GetExpRomVersion(ImageInfo* info) {
-    const char* magic_string = "mlxsign:";
-    u_int32_t   magic_len    = strlen(magic_string);
-    u_int32_t   i;
-    bool        magic_found  = false;
-    u_int32_t   ver_offset;
-    u_int8_t    rom_checksum = 0;
-    u_int32_t   rom_checksum_range;
-
-    info->expRomValidVersion = false;
-    if (_rom_sect.empty()) {
-        return errmsg("Expansion Rom section not found.");
-    }
-
-    // When checking the version of the expansion rom, only the first image has
-    // to be checked. This is because the second image  the uefi image does not 
-    // have to comply with checksumming to 0. To do this you have to read  byte 
-    // 2 (third) of the image  and multiply by 512 to get the size of the x86 
-    // image.
-
-    // Checksum:
-    if (_rom_sect.size() < 4) {
-        return errmsg("ROM size (0x%x) is too small", (u_int32_t)_rom_sect.size());
-    }
-
-    // restore endianess.
-    TOCPUn(&(_rom_sect[0]), _rom_sect.size()/4);
-
-    rom_checksum_range = _rom_sect[2] * 512 ;
-    if (rom_checksum_range > _rom_sect.size()) {
-       return errmsg("ROM size field (0x%2x) is larger than actual ROM size (0x%x)", 
-                     rom_checksum_range , 
-                     (u_int32_t)_rom_sect.size());
-    } else if (rom_checksum_range == 0) {
-       return errmsg("ROM size field is 0. Unknown ROM format or corrupted ROM.");
-    }
-
-    for (i = 0; i < rom_checksum_range; i++) {
-        rom_checksum += _rom_sect[i];
-    }
-
-    if (rom_checksum != 0) {
-        return errmsg("Bad ROM Checksum (0x%02x)", rom_checksum);
-    }
-
-    for (i = 0 ; i < rom_checksum_range; i++) {
-        for (u_int32_t j = 0; j < magic_len; j++) {
-            if (_rom_sect[i+j] != magic_string[j]) {
-                break;
-            } else if (j == magic_len - 1) {
-                magic_found = true;
-            }
-        }
-
-        if (magic_found) {
-            break;
-        }
-    }
-
-    if (magic_found) {
-        ver_offset = i + magic_len;
-    } else {
-        return errmsg("Mellanox version string (%s) not found in ROM section.", magic_string);
-    }
-
-    // Following mlxsign:
-    // 31:24   0        Compatible with UEFI
-    // 23:16   ProductID       Product ID:
-    //                          1 - CLP implementation for Sinai (MT25408)
-    //                          2 - CLP implementation for Hermon DDR (MT25418)
-    //                          0X10 - PXE
-    // 15:0    Major version   If ProductID < 0x10 this field is subversion 
-    //                          number, otherwise It's product major version. 
-    // 
-    // 31:16   Minor version   Product minor version*. Not valid if 
-    //                          roductID < 0x10.
-    // 15:0    SubMinor version        Product sub minor version*. Not valid if 
-    //                                  ProductID < 0x10.
-    // 
-    // 31:16   Device ID       The PCI Device ID (ex. 0x634A for Hermon 
-    //                          DDR). Not valid if ProductID < 0x10.
-    // 15:12   Port Number     Port number: 0 - Port independent, 1 - Port 1, 2 - Port 2
-    // 11:0    Reserved        
-
-    u_int32_t tmp;
-
-    tmp = __le32_to_cpu(*((u_int32_t*) &_rom_sect[ver_offset]));
-    info->expRomProductId = tmp >> 16;
-    info->expRomVer[0]    = tmp & 0xffff;
-
-    if (info->expRomProductId >= 0x10) {
-        tmp = __le32_to_cpu(*((u_int32_t*) &_rom_sect[ver_offset + 4]));
-        info->expRomVer[1] = tmp >> 16;
-        info->expRomVer[2] = tmp  & 0xffff;
-
-        tmp = __le32_to_cpu(*((u_int32_t*) &_rom_sect[ver_offset + 8]));
-        info->expRomDevId  = tmp >> 16;
-        info->expRomPort   = (tmp >> 12) & 0xf;
-    }
-    info->expRomValidVersion = true;
-    return true;
-}
-
-bool Operations::LoadAsExpRom (FBase& f) {
-    _rom_sect.clear();
-    _rom_sect.resize(f.get_size());
-    if (!f.read(0, &_rom_sect[0], f.get_size()))
-        return errmsg(f.err());
-
-    TOCPUn(&_rom_sect[0], _rom_sect.size()/4);
-
-    return true;
-}
-
-bool Operations::DumpConf        (const char* conf_file) {
-#ifndef NO_ZLIB
-
-    FILE* out;
-    if (conf_file == NULL) {
-        out = stdout;
-    } else {
-        out = fopen(conf_file, "w");
-
-        if (out == NULL) {
-            return errmsg("Can not open file %s for write: %s.", conf_file, strerror(errno));
-        }
-    }
-
-    if (_fw_conf_sect.empty()) {
-        return errmsg("FW configuration section not found in the given image.");
-    }
-
-    // restore endianess.
-    TOCPUn(&(_fw_conf_sect[0]), _fw_conf_sect.size()/4);
-
-    // uncompress:
-    uLongf destLen = _fw_conf_sect.size();
-    destLen *= 10;
-    vector<u_int8_t> dest(destLen);
-
-    int rc = uncompress((Bytef *)&(dest[0]), &destLen,
-                        (const Bytef *)&(_fw_conf_sect[0]), _fw_conf_sect.size());
-
-    if (rc != Z_OK)
-    {
-        return errmsg("Failed uncompressing FW configuration section. uncompress returnes %d", rc);
-    }
-
-    dest.resize(destLen);
-    dest[destLen] = 0;  // Terminating NULL
-    fprintf(out, "%s", (char*)&(dest[0]));
-
-    if (conf_file != NULL) {
-        fclose(out);
-    }
-
-    return true;
-#else 
-    return errmsg("Executable was compiled with \"dump configuration\" option disabled.");
-#endif
-
-} // DumpConf
-
-
-
-////////////////////////////////////////////////////////////////////////
-//                                                                    //
-// ****************************************************************** //
-//                       GUIDs TREATMENT                              //
-// ****************************************************************** //
-//                                                                    //
-////////////////////////////////////////////////////////////////////////
-#define GETGUID(s, g) do { if (!ops.getGUID(s,g)) return 1; } while (0)
-#define GETBSN(s, g)  do { if (!ops.getBSN(s,g)) return 1; } while (0)
-
-#define BSN_RET do {                                            \
-    printf("Invalid BSN. Should be MTxxxxx[-]R[xx]ddmmyy-nnn[-cc]\n"); \
-    return false;                                               \
-} while(0)
-#define BSN_RET1(s) do {                                             \
-    printf("Valid BSN format is: MTxxxxx[-]R[xx]ddmmyy-nnn[-cc]\n%s.\n",s); \
-    return false;                                                    \
-} while(0)
-u_int32_t Operations::BSN_subfield(const char *s, int beg, int len)
-{
-    char buf[64];
-    strncpy(buf, &s[beg], len);
-    buf[len] = '\0';
-    return strtoul(&buf[0], 0, 10);
-}
-bool Operations::getBSN(char *s, guid_t *guid)
-{
-    const u_int64_t COMPANY_ID = 0x0002c9;
-    const u_int64_t  TYPE      = 1;
-    bool cc_present = false;
-    char *p;
-    int  date_offs = 0;
-    int  i;
-
-    // Convert to lowercase
-    for (p = s; *p; p++)
-        *p = (char)tolower(*p);
-
-    // Check validity
-    p = s;
-    if (strncmp(p, "mt", 2))     // MT
-        BSN_RET;
-    p += 2;
-    for (i=0; i<5; i++)
-        if (!isdigit(*p++))      // xxxxx
-            BSN_RET;
-    if (*p == '-') {               // - /optional/
-        p++;
-        date_offs++;
-    }
-    if (*p < 'a' || *p > 'z')    // R
-        BSN_RET;
-    p++;
-
-    // Count how many digits after R
-    char *q = p;
-    int  ndigits=0;
-    while (isdigit(*q++))
-        ndigits++;
-
-    switch (ndigits) {
-    case 6:
-        p += 6;                  // skip ddmmyy
-        break;
-    case 8:
-        p += 8;                  // skip xxddmmyy
-        date_offs += 2;
-        break;
-    default:
-        BSN_RET;
-    }
-
-    if (*p++ != '-')             // -
-        BSN_RET;
-    for (i=0; i<3; i++)          // nnn
-        if (!isdigit(*p++))
-            BSN_RET;
-    if (*p) {
-        cc_present = true;
-        if (*p++ != '-')         // -
-            BSN_RET;
-        for (i=0; i<2; i++)      // cc
-            if (!isdigit(*p++))
-                BSN_RET;
-    }
-
-    u_int32_t dd = BSN_subfield(s, 8+date_offs, 2);
-    if (dd > 31)
-        BSN_RET1("Day (dd) should not exceed 31");
-    if (!dd)
-        BSN_RET1("Day (dd) can not be zero");
-    u_int32_t mm = BSN_subfield(s, 10+date_offs, 2);
-    if (mm > 12)
-        BSN_RET1("Months (mm) should not exceed 12");
-    if (!mm)
-        BSN_RET1("Months (mm) can not be zero");
-    u_int32_t yy = BSN_subfield(s, 12+date_offs, 2);
-    if (yy > 99)
-        BSN_RET1("Year (yy) should not exceed 99");
-    if (!yy)
-        BSN_RET1("Year (yy) can not be zero");
-    u_int32_t num = BSN_subfield(s, 15+date_offs, 3);
-    if (num > 999)
-        BSN_RET1("Number (num) should not exceed 999");
-    if (!num)
-        BSN_RET1("Number (num) can not be zero");
-    int cc = 1;
-    if (cc_present) {
-        cc = BSN_subfield(s, 19+date_offs, 2);
-        if (cc > 14)
-            BSN_RET1("Chip number (cc) should not exceed 14");
-        if (!cc)
-            BSN_RET1("Chip number (cc) can not be zero");
-    }
-    u_int64_t id = ((((yy*12+mm-1)*31+ dd-1) * 1000) + num-1) * 112;
-    id += (cc-1)*8;
-
-    u_int64_t g = (COMPANY_ID << 40) | (TYPE << 32) | id;
-    guid->h = (u_int32_t)(g>>32);
-    guid->l = (u_int32_t)g;
-    return true;
-}
-
-bool Operations::getGUID(const char *s, guid_t *guid)
-{
-    char* endp;
-    u_int64_t g;
-
-    g = strtoull(s, &endp, 16);
-    if (*endp || (g == 0xffffffffffffffffULL && errno == ERANGE)) {
-        printf("Invalid GUID syntax (%s) %s \n",
-               s,
-               errno ? strerror(errno) : "" );
-        return false;
-    }
-    guid->h = (u_int32_t)(g >> 32);
-    guid->l = (u_int32_t)(g & 0xffffffff);
-    return true;
-} // getGUID
-
-////////////////////////////////////////////////////////////////////////
-bool Operations::extractGUIDptr(u_int32_t sign, u_int32_t *buf, int buf_len,
-                    char *pref, u_int32_t *ind, int *nguids)
-{
-    u_int32_t offs = 0;
-
-    if (IsCntx()) {
-        offs = 16;
-    }
-
-    // Check signature
-    if (sign) {
-        u_int32_t signature = buf[(sign + 8)/4];
-        TOCPU1(signature);
-        if (signature != SIGNATURE) {
-            printf("%s pointer section not valid\n", pref);
-            return false;
-        }
-        offs = buf[sign/4];
-        TOCPU1(offs);
-    }
-
-    // Get GUID ptr
-    *ind = buf[(offs+0x24)/4];
-    TOCPU1(*ind);
-    if (!IsCntx()) {
-        *ind += offs;
-    }
-    if (*ind >= (u_int32_t)buf_len) {
-        printf("%s image - illegal GUID pointer (%08x)\n", pref, *ind);
-        return false;
-    }
-    *nguids = buf[*ind/4 - 3];
-    TOCPU1(*nguids);
-    *nguids /= 2;
-
-    // More sanity check
-    if (IsCntx() ? (*nguids > MAX_GUIDS) : (*nguids > GUIDS)) {
-        printf("%s image - illegal number of GUIDs (0x%x)\n", pref, *nguids);
-        return false;
-    }
-
-    return true;
-} // extractGUIDptr
-
-
-
-////////////////////////////////////////////////////////////////////////
-
-//
-// This function calculates CRC over the geven buf/size, and stores 
-// the crc in the dwors after the data.
-// Caller should make sure CRC word memory is really there.
-void Operations::recalcSectionCrc(u_int8_t *buf, u_int32_t data_size) {
-    Crc16              crc;
-    u_int32_t          i;
-
-    for (i = 0; i < data_size; i += 4) {
-        crc << __be32_to_cpu(*(u_int32_t*)(buf + i));
-    }
-    crc.finish();
-    *(u_int32_t*)(buf + data_size) = __cpu_to_be32(crc.get());
-}
-
-////////////////////////////////////////////////////////////////////////
-void Operations::patchGUIDsSection(u_int32_t *buf, u_int32_t ind,
-                       guid_t guids[MAX_GUIDS], int nguids)
-{
-    u_int32_t       i;
-    u_int32_t       new_buf[MAX_GUIDS*2];
-
-    // Form new GUID section
-    for (i=0; i<(u_int32_t)nguids; i++) {
-        new_buf[i*2] = guids[i].h;
-        new_buf[i*2+1] = guids[i].l;
-    }
-
-    // Patch GUIDs
-    for (i=0; i<sizeof(new_buf)/sizeof(u_int32_t); ++i) {
-        new_buf[i] = _burn_blank_guids ? 0xffffffff : __cpu_to_be32(new_buf[i]);
-    }
-    memcpy(&buf[ind/4], &new_buf[0], nguids * 2 * sizeof(u_int32_t));
-
-    // Insert new CRC
-    if (_burn_blank_guids) {
-        buf[ind/4 + nguids*2] =  __cpu_to_be32(0xffff);
-    } else {
-        recalcSectionCrc((u_int8_t*)buf + ind - sizeof(GPH), sizeof(GPH) + nguids * 8);
-    }
-} // patchGUIDsSection
-
-
-
-
-// 
-// PatchInfoSect() :
-// This func assumes it gets a pointer (rawSect) to a valid info sect.
-// It patches the it with the given data, recalculated CRC ,
-// and copies it back to the geven data
-//
-
-void Operations::PatchInfoSect(u_int8_t*      rawSect,
-                               u_int32_t      vsdOffs,
-                               const char*    vsd) {
-
-    u_int32_t  vsdSize  = __be32_to_cpu(*((u_int32_t*)(rawSect + sizeof(GPH) + vsdOffs - 4))) & 0xffffff;
-    u_int32_t  infoSize = __be32_to_cpu(*((u_int32_t*)(rawSect + 4)));
-
-    // byte size;
-    infoSize *= 4;
-
-    //printf("-D- vsdOffs=%x, vsdSize=%x, infoSize=%x\n", vsdOffs,vsdSize, infoSize );
-    if (vsd) {
-        u_int32_t len = strlen(vsd);
-
-        if (len > vsdSize) {
-            report("Warning: The given VSD length is too large (%d chars). Truncating to %d chars.\n", len, vsdSize);
-            len = vsdSize;
-        }
-       
-        memset(rawSect + sizeof(GPH) + vsdOffs,  0,   vsdSize );
-        memcpy(rawSect + sizeof(GPH) + vsdOffs,  vsd, len);
-    }
-
-    recalcSectionCrc(rawSect, sizeof(GPH) + infoSize);
-}
-
-
-// 
-// PatchPs() :
-// This func assumes it gets a pointer (rawPs) to a valid PS.
-// It patches the PS with the given data, recalculated CRC ,
-// and copies it back to the rawPs.
-//
-
-void Operations::PatchPs(u_int8_t*      rawPs, 
-                         const char*    vsd,
-                         const char*    psid,
-                         u_int32_t      imageAddr) {
-
-    PS         *ps = (PS*)rawPs;
-
-    u_int32_t fix_start = 0;
-    u_int32_t fix_end   = 0;
-
-    if (vsd) {
-        u_int32_t len = strlen(vsd);
-       
-        memset(&ps->vsd[0],  0,   VSD_LEN );
-        memcpy(&ps->vsd[0],  vsd, len);
-
-        fix_end += VSD_LEN;
-    } else {
-        fix_start +=VSD_LEN;
-    }
-    if (psid) {
-        u_int32_t len = strlen(psid);
-
-        memset(&ps->psid[0],  0,    PSID_LEN );
-        memcpy(&ps->psid[0],  psid, len );
-        fix_end += PSID_LEN;
-    }
-
-    //VSD is kept on flash byte-swapped.
-    //recode it back before patching
-    u_int32_t *qp;
-
-    qp = (u_int32_t *)&ps->vsd[0];
-    for (u_int32_t i=fix_start; i<fix_end/4; i++) {
-        *qp = bswap_32(*qp);
-        qp++;
-    }
-
-    if (imageAddr) {
-        ps->fi_addr = __cpu_to_be32(imageAddr);
-    }
-
-    recalcSectionCrc((u_int8_t *)ps, sizeof(PS) - 4);
-}
-        
-
-////////////////////////////////////////////////////////////////////////
-//Note that vsd1 is a string of bytes.
-bool Operations::patchVSD(FImage& f,
-                          Operations::ImageInfo* info,
-                          const char *user_vsd, 
-                          const char *user_psid,
-                          const char *curr_vsd,
-                          const char *curr_psid,
-                          const char *image_psid)
-{
-    const char* vsd_to_use  = curr_vsd ? curr_vsd : "";
-    const char* psid_to_use = image_psid;
-
-    // TODO: Should not give the user_psid param. Do not allow for on-the-fly PSID changes.
-
-    curr_psid = NULL;
-    // Form new VSD
-
-    if (user_psid) {
-        // New psid is explicitly given - take it from user
-        printf("\n    You are about to replace current PSID in the image file - \"%s\" with a different PSID - \"%s\".\n"
-               "    Note: It is highly recommended not to change the image PSID.\n", user_psid, image_psid);
-
-        if (! ask_user())
-            return false;
-
-        psid_to_use = user_psid;
-    }
-
-    if (user_vsd) {
-        vsd_to_use = user_vsd;
-    }
-
-    if (IsCntx() && info->infoOffs[II_VSD]) {
-        PatchInfoSect((u_int8_t*)f.getBuf() + info->infoSectPtr - sizeof(GPH), 
-                      info->infoOffs[II_VSD],
-                      vsd_to_use);
-    } else {
-        PatchPs((u_int8_t*)f.getBuf() + f.get_sector_size(),     vsd_to_use, psid_to_use);
-        PatchPs((u_int8_t*)f.getBuf() + f.get_sector_size() * 2, vsd_to_use, psid_to_use);
-    }
-
-    return true;
-} // pathVSD
-
-
-bool Operations::printGUIDs(const char* msg, guid_t guids[MAX_GUIDS], bool print_guids, bool print_macs, bool old_guid_fmt) {
-    const char* g_m;
-
-    if        ( print_guids &&  print_macs) {
-        g_m = "GUIDs/MACs";
-    } else if (!print_guids &&  print_macs) {
-        g_m = "MACs";
-    } else if ( print_guids && !print_macs) {
-        g_m = "GUIDs";
-    } else {
-        return errmsg("Internal error: Operations::PrintGuids() with both guid and mac turned off");
-    }
-
-    printf("%s %s:\n", msg, g_m);
-    if (print_guids) {
-        printf("        Node  GUID:     " GUID_FORMAT "\n", guids[0].h, guids[0].l);
-        printf("        Port1 GUID:     " GUID_FORMAT "\n", guids[1].h, guids[1].l);
-        if (_num_ports > 1) 
-            printf("        Port2 GUID:     " GUID_FORMAT "\n", guids[2].h, guids[2].l);
-        if (!old_guid_fmt)
-            printf("        Sys.Image GUID: " GUID_FORMAT "\n", guids[3].h, guids[3].l);
-    }
-
-    if (print_macs) {
-        printf("        Port1 MAC:      " MAC_FORMAT "\n", guids[4].h, guids[4].l);
-        printf("        Port2 MAC:      " MAC_FORMAT "\n", guids[5].h, guids[5].l);
-    }
-    return true;
-}   
-
-void Operations::SetDevFlags(u_int16_t devType, bool& ib_dev, bool& eth_dev) {
-    ib_dev  = !IsCntx() || CntxIsIb(devType);
-    eth_dev = IsCntx()  && CntxIsEth(devType);
-
-    if (!ib_dev && !eth_dev) {
-        // Unknown device id - for forward compat - assume that ConnectX is MP and
-        // prev HCAs are IB only (these flags are for printing only - no real harm can be done).
-        ib_dev = true;
-        if (IsCntx()) {
-            eth_dev = true;
-        }
-    }
-}
-
-bool Operations::CheckGuidsFlags (u_int16_t devType,
-                                  bool ib_dev,
-                                  bool guids_specified,
-                                  bool eth_dev,
-                                  bool macs_specified) {
-    // Patch GUIDS
-    if  (guids_specified || macs_specified) {
-        if (!IsCntx() && macs_specified) {
-            return errmsg("-mac flag is not applicable for IB MT%d device.\n",
-                          devType);
-        } else if ((ib_dev && eth_dev) && !(guids_specified && macs_specified)) {
-            return errmsg("Use both -mac and -guid flags for device id %d.\n",
-                          devType);
-        } else if (ib_dev  && !guids_specified) {
-            return errmsg("Use -guid(s) flag for IB MT%d device.\n",
-                          devType);
-        } else if (eth_dev && !macs_specified) {
-            return errmsg("*** ERROR *** Use -mac(s) flag for ETH MT%d device.\n",
-                   devType);
-        }  
-    } 
-    return true;
-}
-
-////////////////////////////////////////////////////////////////////////
-bool Operations::patchGUIDs (FImage&   f, 
-                             ImageInfo* info,
-                             bool      patch_guids, 
-                             bool      patch_macs,
-                             bool      user_guids,
-                             bool      user_macs,
-                             guid_t    new_guids[MAX_GUIDS], 
-                             guid_t    old_guids[MAX_GUIDS],
-                             u_int32_t num_of_old_guids,
-                             bool      interactive)
-{
-    guid_t*         used_guids = old_guids ? old_guids : new_guids;
-    u_int32_t       *buf = f.getBuf();
-    int i;
-
-    bool old_guids_fmt = info->guidNum < GUIDS;
-
-    // Print old GUIDs and get confirmation
-    if (new_guids) {
-        if (old_guids_fmt) 
-            printf("    Old image!!!! Only %d GUIDs may be set.\n", info->guidNum);
-            // if only guids or only macs are specified by user, keep the other
-            // as currently set of flash. This is in order to simplify transitions between
-            // burning IB and ETH FW.
-
-        if (old_guids && !user_guids) {
-            for (i = 0; i < GUIDS; i++) {
-                new_guids[i] = old_guids[i];
-            }
-        }
-        
-        if (old_guids && !user_macs) {
-            for (i = GUIDS; i < MAX_GUIDS; i++) {
-                new_guids[i] = old_guids[i];
-            }
-        }
-    
-        used_guids = new_guids;
-    }   
-
-    if (patch_macs) {
-
-        // To ease upgrade from 4 GUIDS format to 4+2 format, or to move from IB to ETH,
-        // if macs are not
-        // explicitly set in flash, they are derived from the GUIDs according to 
-        // Mellanox methodology - 48 bit MAC == 64 bit GUID without the middle 16 bits.
-        
-        if (old_guids && ((num_of_old_guids == 4) || 
-                          (num_of_old_guids == 6 && 
-                            (old_guids[GUIDS  ].h & 0xffff)     == 0xffff     &&
-                            (old_guids[GUIDS  ].l & 0xffffffff) == 0xffffffff &&
-                            (old_guids[GUIDS+1].h & 0xffff)     == 0xffff     &&
-                            (old_guids[GUIDS+1].l & 0xffffffff) == 0xffffffff))) {
-            for (i = 0 ; i < MACS; i++) {
-                u_int64_t mac  =  old_guids[i+1].h >> 8;
-                mac <<= 24;
-                mac |= (old_guids[i+1].l & 0xffffff);
-
-                old_guids[GUIDS+i].h = u_int32_t(mac >> 32);
-                old_guids[GUIDS+i].l = u_int32_t(mac  & 0xffffffff);
-
-                // printf("-D- Guid " GUID_FORMAT " to MAC "MAC_FORMAT"\n", old_guids[i+1].h, old_guids[i+1].l, old_guids[i+GUIDS].h,old_guids[i+GUIDS].l  );
-            }
-        }
-
-        guid_t* macs = &used_guids[4];
-        int i;
-                
-        for (i = 0 ; i < Operations::MACS ; i++) {
-            u_int64_t mac = (((u_int64_t)macs[i].h) << 32) | macs[i].l;
-            if (!_burn_blank_guids && !CheckMac(mac)) {
-                printf("*** ERROR *** Bad mac (" MAC_FORMAT ") %s: %s. Please re-burn with a valid -mac flag value.\n", 
-                       macs[i].h,
-                       macs[i].l,
-                       user_macs ? "given" : "found on flash",
-                       err());
-                return false;
-            }
-        }
-    }
-
-    if (new_guids && old_guids) {
-        printGUIDs("    Current settings of",
-                   old_guids,
-                   patch_guids,
-                   patch_macs,
-                   old_guids_fmt);
-        printf("\n");
-    }
-
-    if (interactive) {
-        printGUIDs("    You are about to burn the image with the following",
-                   used_guids,
-                   patch_guids,
-                   patch_macs,
-                   old_guids_fmt);
-
-        if (!ask_user())
-            return false;
-    }
-
-    // Path GUIDs section
-    if (info->guidPtr) {
-        patchGUIDsSection(buf, info->imgStart + info->guidPtr, used_guids, info->guidNum);
-
-        if (info->allImgStart[1]) {
-            // For no ConnectX HCAs, patch also the secondary image (if found). This is applicable 
-            // only for nofs burn, where both images are burnt as is.
-            patchGUIDsSection(buf, info->allImgStart[1] + info->guidPtr, used_guids, info->guidNum);
-        }
-    }
-
-    return true;
-} // patchGUIDs
-
-
-////////////////////////////////////////////////////////////////////////
-//                                                                    //
-// ****************************************************************** //
-//                  Revision info and board ID                        //
-// ****************************************************************** //
-//                                                                    //
-////////////////////////////////////////////////////////////////////////
-
-bool Operations::QueryIs (FBase& f, 
-                          Operations::ImageInfo* info) {
-    u_int32_t signature;
-
-    READ4(f, 0x24, &signature, "Signature");
-    TOCPU1(signature);
-    if (signature == SIGNATURE) {
-        // Full image
-        info->isFailsafe = true;
-        
-        // FW ID
-        u_int32_t fw_id;
-        
-        READ4(f, 0x10, &fw_id, "FW ID");
-        TOCPU1(fw_id);
-        
-        info->isVer   = ( fw_id >> 8) && 0xff;
-        info->devRev  = fw_id >> 24;
-        
-    } else {
-        info->isFailsafe = false;
-        info->imgStart   = 0;
-    }
-
-    info->invSectOk = true;
-    return true;
-}
-
-bool Operations::QueryPs (FBase& f, 
-                          Operations::ImageInfo* info) {
-
-    if (!info->isFailsafe) {
-        return errmsg("Internal Error: Tried to query PS when image is not failsafe");
-    }
-
-    u_int32_t prim_ptr, scnd_ptr;
-    u_int32_t sectSize = f.get_sector_size();
-
-    bool currSielent = _silent;
-    _silent = true;
-
-    if (checkPS(f, sectSize, prim_ptr, "Primary  ")) {
-        info->allImgStart[0] = prim_ptr;
-        info->imgStart = prim_ptr;
-        info->psStart  = sectSize;
-    } 
-    if (checkPS(f, sectSize * 2, scnd_ptr, "Secondary")) {
-        info->allImgStart[1] = scnd_ptr;
-        if (info->allImgStart[0] == 0) {
-            info->imgStart = scnd_ptr;
-            info->psStart  = sectSize * 2;
-        }
-    } 
-
-    if (info->allImgStart[0] == 0 && info->allImgStart[1] == 0)  {
-        return errmsg("No valid image found.");
-    }
-
-    char       vsd[VSD_LEN+PSID_LEN+1];   // +1  => Leave a space for \0 when psid size == 16 .
-
-    memset(vsd, 0, sizeof(vsd));
-    READBUF(f, info->psStart + 0x20, vsd, VSD_LEN+PSID_LEN , "Vendor Specific Data (Board ID)");
-    u_int32_t* vsd_dwp = (u_int32_t*)vsd;
-
-    for (u_int32_t i=0; i < sizeof(vsd)/sizeof(u_int32_t); i++)
-         vsd_dwp[i] = bswap_32(vsd_dwp[i]);
-
-    memcpy(info->vsd,  vsd,           VSD_LEN);
-    memcpy(info->psid, vsd + VSD_LEN, PSID_LEN);
-
-    info->vsd [sizeof(info->vsd)  - 1] = '\0';
-    info->psid[sizeof(info->psid) - 1] = '\0';
-
-    _silent = currSielent;
-
-    info->psOk = true;
-
-    return true;
-}
-
-
-bool Operations::QueryImage (FBase& f, 
-                             Operations::ImageInfo* info) {
-
-    u_int32_t guid_ptr, nguids;
-    guid_t guids[MAX_GUIDS];
-
-    // FW ID
-    u_int32_t fw_id;
-    u_int32_t fw_id_offs;
-    u_int32_t im_start = info->imgStart;
-
-    if (IsCntx()) {
-        if (info->isFailsafe && info->actuallyFailsafe) {
-            f.set_address_convertor(info->cntxLog2ChunkSize, im_start != 0);
-        } else {
-            f.set_address_convertor(0,0);
-        }
-
-        im_start = 0; // offset is done by address convertor
-        info->magicPatternFound = true;
-        fw_id_offs = 0x20;
-    } else {
-        info->magicPatternFound = false;
-        fw_id_offs = 0x10;
-    }
-
-    READ4(f, im_start + fw_id_offs, &fw_id, "FW ID");
-    TOCPU1(fw_id);
-
-    info->devRev  = fw_id >> 24;    
-    // Read GUIDs
-    READ4(f, im_start + fw_id_offs + 0x14 , &guid_ptr, "GUID PTR");
-    TOCPU1(guid_ptr);
-    info->guidPtr = guid_ptr;
-
-    guid_ptr += im_start;
-    if (guid_ptr >= f.get_size()) {
-        return errmsg("Failed to read GUIDs - Illegal GUID pointer (%08x). Probably image is corrupted", guid_ptr);
-    }
-    READ4(f, guid_ptr - 3*sizeof(u_int32_t), &nguids, "Number of GUIDs");
-    TOCPU1(nguids);
-    nguids /= 2;
-    if (nguids > MAX_GUIDS) {
-        report("Failed to read GUIDs - Illegal Number of GUIDs (%d)\n", nguids);
-        return false;
-    }
-    READBUF(f, guid_ptr, guids, nguids * sizeof(u_int64_t), "GUIDS");
-    TOCPUBY64(guids);
-
-    u_int32_t guids_crc;
-    READ4(f, guid_ptr + nguids * sizeof(u_int64_t), &guids_crc, "GUIDS CRC");
-    guids_crc = __be32_to_cpu(guids_crc); 
-
-    info->blankGuids = true;
-
-    if ((guids_crc & 0xffff) != 0xffff ) {
-       info->blankGuids = false; 
-    }
-
-    info->guidNum = nguids;
-    for (u_int32_t i = 0 ; i < nguids ; i++) {
-        info->guids[i] = guids[i];
-        if (guids[i].h != 0xffffffff || guids[i].l != 0xffffffff) {
-            info->blankGuids = false;
-        }
-    }
-
-    // Expansion Rom version:
-    if (_rom_sect.empty()) {
-        info->expRomFound = false;
-    } else {
-        info->expRomFound = true;
-        if (!GetExpRomVersion(info)) {
-            report("\nWarning: Failed to get ROM Version: %s\n\n", err()); 
-            info->expRomValidVersion = false;
-        }
-    }
-
-    // Read Info:
-    u_int32_ba info_ptr_ba;
-    u_int32_t  info_ptr;
-    u_int32_t  info_size;
-    u_int8_t   info_ptr_cs = 0;
-    READ4(f, im_start + fw_id_offs + 0xC, &info_ptr, "INFO PTR");
-    TOCPU1(info_ptr);
-
-    // Verify info_ptr checksum (should be 0)
-    info_ptr_ba = info_ptr;
-    for (u_int32_t i = 0; i < 4 ; i++) {
-        info_ptr_cs += (u_int8_t)info_ptr_ba.range(i*8+7, i*8);
-    }
-
-    if (info_ptr_cs) {
-        return errmsg("Failed to read Info Section - Bad checksum for Info section pointer (%08x). Probably the image is corrupted.", info_ptr);        
-    }
-
-    info_ptr = info_ptr_ba.range(23,0);
-    if (info_ptr_cs == 0 && info_ptr != 0) {
-        info->infoSectPtr = info_ptr;
-
-        info_ptr += im_start;
-        if (info_ptr >= f.get_size()) {
-            return errmsg("Failed to read Info Section - Info section pointer (%08x) too large. Probably the image is corrupted.", info_ptr);
-        }
-        READ4(f, info_ptr - 3*sizeof(u_int32_t), &info_size, "Info section size");
-        TOCPU1(info_size);
-
-        // byte size;
-        info_size *= 4;
-
-        u_int8_t* info_buff = (u_int8_t*)alloca(info_size);
-        READBUF(f, info_ptr, info_buff, info_size, "Info Section");
-
-        if (!ParseInfoSect(info_buff, info_size,  info)) {
-            return false;
-        }
-    }
-
-    info->imageOk = true;
-    return true;
-}
-
-
-bool Operations::ParseInfoSect(u_int8_t* buff, u_int32_t byteSize, Operations::ImageInfo *info) {
-
-    u_int32_t *p = (u_int32_t*)buff;
-    u_int32_t offs = 0;
-    u_int32_t tagNum = 0;
-    bool endFound = false;
-
-    while (!endFound && offs < byteSize) {
-        u_int32_t tagSize = __be32_to_cpu(*p) & 0xffffff;
-        u_int32_t tagId   = __be32_to_cpu(*p) >> 24;
-
-        if (offs + tagSize > byteSize) {
-            return errmsg("Info section corrupted: Tag %d (TagId %d, size %d) exceeds Info section size (%d bytes) ",
-                          tagNum, tagId, tagSize, byteSize);
-        }
-
-        u_int32_t   tmp;
-        const char* str;
-
-        switch (tagId) {
-        case II_FwVersion:
-            info->fwVer[0] = (u_int16_t)(__be32_to_cpu(*(p+1)) >> 16);
-            tmp = __be32_to_cpu(*(p+2));
-            info->fwVer[1] = tmp >> 16;
-            info->fwVer[2] = tmp & 0xffff;
-            break;
-
-        case II_DeviceType:
-            tmp = __be32_to_cpu(*(p+1));
-            info->devType = tmp & 0xffff;
-            //info->devRev  = (tmp >> 16) & 0xff;
-            break;
-
-        case II_VsdVendorId:
-            tmp = __be32_to_cpu(*(p+1));
-            info->vsdVendorId = tmp & 0xffff;
-            break;
-
-        case II_IsGa:
-            tmp = __be32_to_cpu(*(p+1));
-            info->isGa = tmp ? true : false;;
-            break;
-
-        case II_PSID: 
-            // set psid only if not previosly found in PS
-            if (!info->psOk) {
-                str = (const char*)p;
-                str += 4;
-
-                for (int i = 0 ; i < PSID_LEN ; i++) {
-                    info->psid[i] = str[i];
-                }
-                info->psid[PSID_LEN] = '\0';
-            }
-            break;
-
-        case II_VSD: 
-            // set psid only if not previosly found in PS
-            if (!info->psOk) {
-                str = (const char*)p;
-                str += 4;
-
-                for (int i = 0 ; i < VSD_LEN ; i++) {
-                    info->vsd[i] = str[i];
-                }
-                info->vsd[VSD_LEN] = '\0';
-            }
-            break;
-
-        case II_ProductVer: 
-        
-            str = (const char*)p;
-            str += 4;
-
-            for (int i = 0 ; i < PRODUCT_VER_LEN ; i++) {
-                info->productVer[i] = str[i];
-            }
-            info->productVer[PRODUCT_VER_LEN] = '\0';
-            break;
-
-        case II_End:
-            endFound = true;
-            break;
-
-        //default:
-            //printf("-D- Found tag ID %d of size %d - ignoring.\n", tagId, tagSize);
-        }
-
-        if (tagId < II_Last) {
-            info->infoOffs[tagId] = offs + 4;
-        }
-
-        p    += tagSize/4 + 1;
-        offs += tagSize + 4;
-        tagNum++;
-    }
-
-    if (offs != byteSize) {
-        if (endFound) {
-            return errmsg("Info section corrupted: Section data size is %x bytes, "
-                          "but end tag found after %x bytes.", byteSize, offs);
-        } else {
-            return errmsg("Info section corrupted: Section data size is %x bytes, "
-                          "but end tag not found before section end.", byteSize);
-        }
-    }
-
-    return true;
-}
-
-bool Operations::DisplayExpRomInfo(Operations::ImageInfo* info) {
-    report("Rom Info:        ");
-    if (info->expRomValidVersion) {
-        report("type=");
-        switch (info->expRomProductId) {
-        case 1   : report("CLP1 "); break;
-        case 2   : report("CLP2 "); break;
-        case 0x10: report("GPXE "); break;
-        default:   report("0x%x ", info->expRomProductId);
-        }
-
-        report("version=%d", info->expRomVer[0]);
-
-        if (info->expRomProductId >= 0x10) {
-            report(".%d.%d devid=%d", 
-                   info->expRomVer[1],
-                   info->expRomVer[2],
-                   info->expRomDevId);
-
-            if (info->expRomPort) {
-                // Do not display if 0 - port independant
-                report(" port=%d", info->expRomPort);
-            }
-        }
-        report("\n");
-    } else {
-        report("N/A\n");
-    }
-    return true;
-}
-
-bool Operations::DisplayImageInfo(Operations::ImageInfo* info) {
-    report("Image type:      %s\n", info->magicPatternFound ? "ConnectX"   : 
-                                    info->isFailsafe        ? "Failsafe" : 
-                                                              "Short");
-
-    if (info->infoOffs[II_FwVersion]) {
-        report("FW Version:      %d.%d.%d\n", info->fwVer[0], info->fwVer[1], info->fwVer[2]);
-    }
-
-    if (info->infoOffs[II_ProductVer] && strlen(info->productVer)) {
-        report("Product Version: %s\n", info->productVer);
-    }
-
-    if (info->expRomFound) {
-        DisplayExpRomInfo(info);
-    }
-
-    if (info->isFailsafe && !IsCntx()) {
-        report("I.S. Version:    %d\n", info->isVer );
-    }
-
-    if (info->infoOffs[II_DeviceType]) {
-        report("Device ID:       %d\n", info->devType);
-        if (info->devType == 25204 || info->devType == 24204) {
-            _num_ports = 1;
-        }
-    }
-
-    report("Chip Revision:   %X\n", info->devRev);
-
-    // GUIDS:
-    // TODO: Handle case where devtype not found.
-    bool ib_dev; 
-    bool eth_dev;
-    SetDevFlags(info->devType, ib_dev, eth_dev);
-
-    char* mac_indent = "";
-    if (ib_dev) {
-        //report("GUID Des:        Node             Port1            ");        
-        report("Description:     Node             Port1            ");
-
-        if (_num_ports > 1)
-            report("Port2            ");
-        report( "Sys image\n");
-        
-        report("GUIDs:           ");
-        for (u_int32_t i=0; i < GUIDS; i++) {
-            if (i != 2 || _num_ports > 1 ) 
-                report(GUID_FORMAT " ", info->guids[i].h, info->guids[i].l);
-        }
-        mac_indent = "                 ";
-    }
-
-    // MACS:
-    if (eth_dev) {
-        if (info->guidNum == MAX_GUIDS) {
-            if (!ib_dev) 
-                report("Description:%s     Port1            Port2\n", mac_indent);
-            else 
-                printf("\n");
-            
-            report("MACs:    %s        ", mac_indent);
-            for (u_int32_t i=GUIDS; i < MAX_GUIDS; i++) {
-                report(MAC_FORMAT "     ", info->guids[i].h, info->guids[i].l);
-            }
-
-            for (u_int32_t i=GUIDS; i < MAX_GUIDS; i++) {
-                u_int64_t mac = (((u_int64_t)info->guids[i].h) << 32) | info->guids[GUIDS + i].l;
-                if (!info->blankGuids && !CheckMac(mac)) {
-                    if (i==GUIDS) printf("\n\n");
-                    printf("Warning: Bad mac address (" MAC_FORMAT "): %s\n", info->guids[i].h, info->guids[i].l, err());
-                }
-            }
-        } else {
-            printf("\nWarning: Can not get MAC addrerss: Expecting %d entries in guid section, got %d. Probably an old FW image. Please update.\n",
-                   MAX_GUIDS,
-                   info->guidNum);
-        }
-    }
-
-    // VSD, PSID
-    if (!info->infoOffs[II_VsdVendorId] || info->vsdVendorId == MELLANOX_VENDOR_ID) {
-        report("\nBoard ID:        %s", info->vsd);
-        if (info->psid[0])
-            report(" (%s)\n", info->psid);
-        else
-            report("\n");
-
-        report("VSD:             %s\n", info->vsd);
-        report("PSID:            %s\n", info->psid);
-    } else {
-        report("\n\nWarning: Not a Mellanox FW image (vendor_id = 0x%04x). VSD and PSID are not displayed.\n\n", info->vsdVendorId);
-    }
-
-    if (info->infoOffs[II_IsGa]) {
-        if (!info->isGa) {
-            report("BOARD GA:        no\n");
-        }
-    }
-
-    if (info->blankGuids) {
-        report("\nWarning: GUIDs%s values and their CRC are not set.\n",
-               IsCntx() ? "/MACs" : "");
-    }
-    return true;
-}
-
-////////////////////////////////////////////////////////////////////////
-//                                                                    //
-// ****************************************************************** //
-//                           MAIN                                     //
-// ****************************************************************** //
-//                                                                    //
-////////////////////////////////////////////////////////////////////////
-// sed -e 's/"/\\"/g' < flint.txt | perl -pe 's/^(.*)$/"$1\\n"/'
-void usage(const char *sname, bool full = false)
-{
-    const char *descr =
-    "\n"
-    "               FLINT - FLash INTerface\n"
-    "\n"
-    "FW (firmware) burning and flash memory operations tool for\n"
-    "Mellanox Infiniband HCAs and Ethernet NIC cards.\n"
-    "\n"
-    "Usage:\n"
-    "------\n"
-    "\n"
-    "    " FLINT_NAME " [switches...] <command> [parameters...]\n"
-    "\n"
-    "\n"
-    "Switches summary:\n"
-    "-----------------\n"
-//    "    -bsn <BSN>         - Mellanox Board Serial Number (BSN).\n"
-//    "                         Valid BSN format is:\n"
-//    "                                 MTxxxxx[-]R[xx]ddmmyy-nnn[-cc]\n"
-//    "                         Commands affected: burn\n"
-//    "\n"
-//    "    -crc               - Print out each section CRC.\n"
-//    "                         Commands affected: verify\n"
-    "\n"
-    "    -d[evice] <device> - Device flash is connected to.\n"
-    "                         Commands affected: all\n"
-    "\n"
-    "    -guid <GUID>       - GUID base value. 4 GUIDs\n"
-    "                         are automatically assigned to the\n"
-    "                         following values:\n"
-    "\n"
-    "                         guid   -> node GUID\n"
-    "                         guid+1 -> port1\n"
-    "                         guid+2 -> port2\n"
-    "                         guid+3 -> system image GUID.\n"
-    "\n"
-    "                         Note: port2 guid will be assigned even for a"
-    "                         single port HCA - The HCA ignores this value.\n"
-    "\n"
-    "                         Commands affected: burn, sg\n"
-    "\n"
-    "    -guids <GUIDs...>  - 4 GUIDs must be specified here.\n"
-    "                         The specified GUIDs are assigned\n"
-    "                         the following values, repectively:\n"
-    "                         node, port1, port2 and system image GUID.\n"
-    "\n"
-    "                         Note: port2 guid must be specified even for a\n"
-    "                         single port HCA - The HCA ignores this value.\n"
-    "                         It can be set to 0x0.\n"
-    "\n"
-    "                         Commands affected: burn, sg\n"
-    "\n"
-    "    -mac <MAC>         - MAC address base value. 2 MACs\n"
-    "                         are automatically assigned to the\n"
-    "                         following values:\n"
-    "\n"
-    "                         mac    -> port1\n"
-    "                         mac+1  -> port2\n"
-    "\n"
-    "                         Commands affected: burn, sg\n"
-    "\n"
-    "    -macs <MACs...>    - 2 MACs must be specified here.\n"
-    "                         The specified MACs are assigned\n"
-    "                         to port1, port2, repectively.\n"
-    "\n"
-    "                         Commands affected: burn, sg\n"
-    "                         Note: -mac/-macs flags are applicable only for Mellanox\n"
-    "                               Technologies ethernet products.\n"
-    "\n"
-    "    -blank_guids       - Burn the image with blank GUIDs and MACs (where\n"
-    "                         applicable). These values can be set later using\n"
-    "                         the \"sg\" command (see details below).\n"
-    "\n"
-    "                         Commands affected: burn\n"
-    "\n"
-    "    -clear_semaphore   - Force clear the flash semaphore on the device.\n"
-    "                         No command is allowed when this flag is used.\n"
-    "                         NOTE: May result in system instability or flash\n"
-    "                               corruption if the device or another\n"
-    "                               application is currently using the flash.\n"
-    "                               Exercise caution.\n"
-    "\n"
-    "    -h[elp]            - Prints this message and exits\n"
-    "    -hh                - Prints extended command help\n"
-    "\n"
-    "    -i[mage] <image>   - Binary image file.\n"
-    "                         Commands affected: burn, verify\n"
-    "\n"
-    "    -nofs              - Burn image in a non failsafe manner.\n"
-    "\n"
-    "    -skip_is           - Allow burning the FW image without updating the invariant sector,\n"
-    "                         to ensure failsafe burning even when an invariant sector difference is detected.\n"
-    "                         See the specific FW release notes for more details.\n"
-    "\n"
-    "    -byte_mode         - Shift address when accessing flash internal registers. May\n"
-    "                         be required for burn/write commands when accessing certain\n"
-    "                         flash types.\n" 
-    "\n"
-#if 0
-    "    -unlock            - Use unlock bypass feature of the flash for quicker burn.\n"
-    "                         Commands affected: burn\n"
-    "\n"
-#endif
-    "    -s[ilent]          - Do not print burn progress flyer.\n"
-    "                         Commands affected: burn\n"
-    "\n"
-    "    -y[es]             - Non interactive mode - assume answer\n"
-    "                         \"yes\" to all questions.\n"
-    "                         Commands affected: all\n"
-    "\n"
-    "    -no                - Non interactive mode - assume answer\n"
-    "                         \"no\" to all questions.\n"
-    "                         Commands affected: all\n"
-    "\n"
-    "    -vsd  <string>     - Write this string, of up to 208 characters, to VSD when burn.\n"
-    "\n"
-    "    -use_image_ps      - Burn vsd as appears in the given image - do not keep existing VSD on flash.\n"
-    "                         Commands affected: burn\n"
-    "\n"
-    "    -dual_image        - Make the burn process burn two images on flash (previously default algorithm). Current\n" 
-    "                         default failsafe burn process burns a single image (in alternating locations).\n"
-    "                         Commands affected: burn\n"
-    "\n"
-    "    -v                 - Version info.\n"
-    "\n"
-    "Commands summary (use -hh flag for full commands description):\n"
-    "-----------------\n"
-    "  b[urn]              - Burn flash\n"
-    "  q[uery]             - Query misc. flash/firmware characteristics\n"
-    "  v[erify]            - Verify entire flash\n"
-    "  bb                  - Burn Block - Burns the given image as is. \n"
-    "                        No checks are done.\n"
-    "  sg                  - Set Guids\n"
-    "  ri       <out-file> - Read the fw image on the flash.\n"
-    "  dc       [out-file] - Dump Configuration: print fw configuration file\n"
-    "                        for the given image.\n"
-    "  e[rase]  <addr>     - Erase sector\n"
-    "  rw       <addr>     - Read one dword from flash\n"
-    "  ww       <addr> < data> \n"
-    "                      - Write one dword to flash\n"
-    "  wwne     <addr>     - Write one dword to flash without sector erase\n"
-    "  wbne     <addr> <size> <data ...> \n"
-    "                      - Write a data block to flash without sector erase\n"
-    "  rb       <addr> <size> [out-file]\n"
-    "                      - Read  a data block from flash\n"
-    "\n"
-    "  Return values:\n"
-    "  0 - Successful completion\n"
-    "  1 - An error has occurred\n"
-    "  7 - For burn command - FW already updated - burn was aborted.\n"
-    "\n";
-
-    const char* full_descr =
-    "\n"
-    "Command descriptions:\n"
-    "----------------------------\n"
-    "\n"
-    "* Burn flash\n"
-    "  Burns entire flash from raw binary image.\n"
-    "\n"
-    "    Command:\n"
-    "        b[urn]\n"
-    "    Parameters:\n"
-    "        None\n"
-    "    Examples:\n"
-    "        " FLINT_NAME " -d " DEV_MST_EXAMPLE1 " -i image1.bin burn\n"
-    "        " FLINT_NAME " -d " DEV_MST_EXAMPLE2 " -guid 0x2c9000100d050 -i image1.bin b\n"
-    "\n"
-    "\n"
-    "* Burn Block\n"
-    "  Burns entire flash from raw binary image as is. No checks are done on the flash or\n"
-    "  on the given image file. No fields (such as VSD or Guids) are read from flash. \n"
-    "\n"
-    "    Command:\n"
-    "        bb\n"
-    "    Parameters:\n"
-    "        None\n"
-    "    Examples:\n"
-    "        " FLINT_NAME " -d " DEV_MST_EXAMPLE1 " -i image1.bin bb\n"
-    "\n"
-    "\n"
-    "* sg\n"
-    "  Set GUIDs/MACs in the given device.\n"
-    "  Use -guid(s) and -mac(s) flags to set the desired values.\n"
-    "  This command is applicable only for images with blank (0xff)\n"
-    "  GUIDs/MACs values and crc, I.E., that were burnt or generated\n"
-    "  using -blank_guids flag.\n"
-    "  The sg command  is used in production to apply GUIDs/MACs values\n"
-    "  to cards that were pre-burnt with blank guids. It is not meant for\n"
-    "  use in field\n"
-    "\n"
-    "    Command:\n"
-    "        sg\n"
-    "    Parameters:\n"
-    "        None\n"
-    "    Examples:\n"
-    "        " FLINT_NAME " -d " DEV_MST_EXAMPLE1 " -guid 0x0002c9000100d050 sg\n"
-    "\n"
-    "\n"
-    "* Erase sector.\n"
-    "  Erases a sector that contains specified address.\n"
-    "\n"
-    "    Command:\n"
-    "        e[rase]\n"
-    "    Parameters:\n"
-    "        addr - address of word in sector that you want\n"
-    "                   to erase.\n"
-    "    Example:\n"
-    "        " FLINT_NAME " -d " DEV_MST_EXAMPLE1 " erase 0x10000\n"
-    "\n"
-    "\n"
-    "* Query miscellaneous FW and flash parameters\n"
-    "\n"
-    "    Command:\n"
-    "        q[uery]\n"
-    "    Parameters:\n"
-    "        None\n"
-    "    Example:\n"
-    "        " FLINT_NAME " -d " DEV_MST_EXAMPLE1 " query\n"
-    "\n"
-    "\n"
-    "* Query flash device parameters (Common Flash Interface)\n"
-    "\n"
-    "    Command:\n"
-    "        cfi\n"
-    "    Parameters:\n"
-    "        None\n"
-    "    Example:\n"
-    "        " FLINT_NAME " -d " DEV_MST_EXAMPLE1 " cfi\n"
-    "\n"
-    "\n"
-    "* Read one dword from flash.\n"
-    "\n"
-    "    Command:\n"
-    "        rw\n"
-    "    Parameters:\n"
-    "        addr - address of word to read\n"
-    "    Example:\n"
-    "        " FLINT_NAME " -d " DEV_MST_EXAMPLE1 " rw 0x20\n"
-    "\n"
-    "\n"
-    "* Verify entire flash.\n"
-    "\n"
-    "    Command:\n"
-    "        v[erify]\n"
-    "    Parameters:\n"
-    "        None\n"
-    "    Example:\n"
-    "        " FLINT_NAME " -d " DEV_MST_EXAMPLE1 " v\n"
-    "\n"
-    "\n"
-    "* Write one dword to flash.\n"
-    "  Note that the utility will read an entire flash sector,\n"
-    "  modify one word and write the sector back. This may take\n"
-    "  a few seconds.\n"
-    "\n"
-    "    Command:\n"
-    "        ww\n"
-    "    Parameters:\n"
-    "        addr - address of word\n"
-    "        data - value of word\n"
-    "    Example:\n"
-    "        " FLINT_NAME " -d " DEV_MST_EXAMPLE1 " ww 0x10008 0x5a445a44\n"
-    "\n"
-    "\n"
-    "* Write one dword to flash without sector erase.\n"
-    "  Note that the result of operation is undefined and depends\n"
-    "  on flash type. Usually \"bitwise AND\" (&) between specified\n"
-    "  word and previous flash contents will be written to\n"
-    "  specified address.\n"
-    "\n"
-    "    Command:\n"
-    "        wwne\n"
-    "    Parameters:\n"
-    "        addr - address of word\n"
-    "        data - value of word\n"
-    "    Example:\n"
-    "        " FLINT_NAME " -d " DEV_MST_EXAMPLE1 " wwne 0x10008 0x5a445a44\n"
-    "\n"
-    "* Read a data block from the flash and write it to a file or to screen.\n"
-    "\n"
-    "    Command:\n"
-    "        rb\n"
-    "    Parameters:\n"
-    "        addr - address of block\n"
-    "        size - size of data to read in bytes\n"
-    "        file - filename to write the block (raw binary). If not given, the data\n"
-    "               is printed to screen\n"
-    "    Example:\n"
-    "        " FLINT_NAME " -d " DEV_MST_EXAMPLE1 " rb 0x10000 100 file.bin\n"
-    "\n"
-    "* Read the FW image from flash and write it to a file.\n"
-    "\n"
-    "    Command:\n"
-    "        ri\n"
-    "    Parameters:\n"
-    "        file - filename to write the image to (raw binary).\n"
-    "    Example:\n"
-    "        " FLINT_NAME " -d " DEV_MST_EXAMPLE1 " ri file.bin\n"
-    "\n"
-    "* Write a block of data to the flash without erasing.\n"
-    "\n"
-    "    Command:\n"
-    "        wbne\n"
-    "    Parameters:\n"
-    "        addr - address of block\n"
-    "        size - size of data to write in bytes\n"
-    "        data - data to write - space seperated dwords\n"
-    "    Example:\n"
-    "        " FLINT_NAME " -d " DEV_MST_EXAMPLE1 " wbne 0x10000 12 0x30000 0x76800 0x5a445a44\n"
-    "\n"
-    "* Print (to screen or to a file) the FW configuration text file used by the image generation process.\n"
-    "  This command would fail if the image does not contain a FW configuration section. Existence of this\n"
-    "  section depends on the version of the image generation tool.\n"
-    "\n"
-    "    Command:\n"
-    "        dc\n"
-    "    Parameters:\n"
-    "        file - (optional) filename to write the dumped configuration to. If not given, the data\n"
-    "               is printed to screen\n"
-    "    Example:\n"
-    "        " FLINT_NAME " -d " DEV_MST_EXAMPLE1 " dc\n"
-    "\n";
-
-    printf(descr, sname);
-
-    if (full) {
-        printf(full_descr, sname);
-    }
-}
-
-
-//
-// Signal handlers 
-//
-
-Flash* g_flash = NULL;
-
-#ifdef _WIN32
-HANDLE g_hMainTread = GetCurrentThread();
-#endif
-
-
-
-int g_signals_for_termination[] = {
-    SIGINT,
-#ifndef _WIN32
-    SIGHUP,
-#endif
-    SIGTERM
-};
-
-
-
-void TerminationHandler (int signum)
-{
-    static volatile sig_atomic_t fatal_error_in_progress = 0;
-
-#ifdef _WIN32
-    if (signum == 0) {
-
-        report ("\nWarning: Got SIGINT. Raising SIGTERM\n");
-        raise(SIGTERM);
-        return;
-    }
-
-    report ("\nWarning: This program can not be interrupted.Please wait for its termination.\n");
-    signal(signum, TerminationHandler);
-    return;
-#endif
-
-
-    if (fatal_error_in_progress)
-        raise (signum);
-    fatal_error_in_progress = 1;
-
-    signal (signum, SIG_DFL);
-
-    if (g_flash != NULL) {
-        report("\n Received signal %d. Cleaning up ...", signum);
-        fflush(stdout);
-        sleep(1); // let erase sector end
-        //g_flash->wait_ready("Process termination");
-
-        g_flash->close();
-        report(" Done.\n");
-    }
-    raise(signum);
-}
-
-//
-// Commands database and parsing methods
-//
-enum CommandInput {
-    CI_NONE         = 0x01,
-    CI_IMG_ONLY     = 0x02,
-    CI_DEV_ONLY     = 0x04,
-    CI_IMG_OR_DEV   = 0x06,
-    CI_IMG_AND_DEV  = 0x08
-};
-
-enum CommandType {
-    CMD_UNKNOWN,
-    CMD_BURN,
-    CMD_SET_GUIDS,
-    CMD_BURN_BLOCK,
-    CMD_QUERY,
-    CMD_QUERY_ROM,
-    CMD_QUERY_FORCE,
-    CMD_VERIFY,
-    CMD_READ_WORD,
-    CMD_READ_BLOCK,
-    CMD_WRITE_WORD,
-    CMD_WRITE_WORD_NE,
-    CMD_WRITE_BLOCK,
-    CMD_WRITE_BLOCK_NE,
-    CMD_ERASE_SECT,
-    CMD_DUMP_CONF,
-    CMD_READ_IMAGE,
-    CMD_CFI,
-    CMD_CLEAR_SEM
-};
-
-struct CommandInfo {
-    CommandType  cmd;
-    const char*  cmdName;
-    bool         requireExactMatch;
-    int          maxArgs;
-    CommandInput requiredInput;
-    const char*  cmdDescription;
-};
-
-CommandInfo const g_commands[] = {
-    { CMD_BURN           , "burn"  ,false , 0 , CI_IMG_AND_DEV , ""},
-    { CMD_BURN_BLOCK     , "bb"    ,true  , 0 , CI_IMG_AND_DEV , ""},
-    { CMD_SET_GUIDS      , "sg"    ,true  , 0 , CI_DEV_ONLY    , ""},
-    { CMD_QUERY_FORCE    , "qf"    ,true  , 0 , CI_IMG_OR_DEV  , ""},
-    { CMD_QUERY          , "query" ,false , 0 , CI_IMG_OR_DEV  , ""},
-    { CMD_QUERY_ROM      , "qrom"  ,true  , 0 , CI_IMG_ONLY    , ""},
-    { CMD_VERIFY         , "verify",false , 0 , CI_IMG_OR_DEV  , ""},            
-    { CMD_READ_WORD      , "rw"    ,true  , 1 , CI_DEV_ONLY    , ""},      
-    { CMD_READ_BLOCK     , "rb"    ,true  , 3 , CI_IMG_OR_DEV  , ""},
-    { CMD_WRITE_WORD     , "ww"    ,true  , 2 , CI_DEV_ONLY    , ""},    
-    { CMD_WRITE_WORD_NE  , "wwne"  ,true  , 2 , CI_DEV_ONLY    , ""},    
-    { CMD_WRITE_BLOCK    , "wb"    ,true  , 2 , CI_DEV_ONLY    , ""},   
-    { CMD_WRITE_BLOCK_NE , "wbne"  ,true  ,-1 , CI_DEV_ONLY    , ""}, 
-    { CMD_ERASE_SECT     , "erase" ,false , 1 , CI_DEV_ONLY    , ""},     
-    { CMD_DUMP_CONF      , "dc"    ,true  , 1 , CI_IMG_OR_DEV  , ""},
-    { CMD_READ_IMAGE     , "ri"    ,true  , 1 , CI_DEV_ONLY    , ""},
-    { CMD_CLEAR_SEM      , "clear_semaphore"    ,true  , 0 , CI_DEV_ONLY    , ""},
-    { CMD_CFI            , "cfi"   ,true  , 0 , CI_DEV_ONLY    , ""}
-};
-
-#define numbel(x) (sizeof(x)/sizeof((x)[0]))
-
-
-const CommandInfo* GetCommandInfo(CommandType cmd) {
-    for (u_int32_t i = 0 ; i < numbel(g_commands); i++ ) {
-        if (cmd == g_commands[i].cmd) {
-            return &g_commands[i];
-        }
-    }
-
-    return NULL;
-}
-
-CommandType ParseCommand(const char* cmd) {
-    u_int32_t cmdLenGiven = strlen(cmd);
-
-    for (u_int32_t i = 0 ; i < numbel(g_commands); i++ ) {
-        if (g_commands[i].requireExactMatch ) {
-            if (!strcmp(cmd, g_commands[i].cmdName)) {
-                return g_commands[i].cmd;
-            }
-        } else {
-            // Match if given cmd maches the beginning of the checked cmd 
-            if (!strncmp(cmd, g_commands[i].cmdName, cmdLenGiven )) {
-                return g_commands[i].cmd;
-            }
-        }
-    }
-    return CMD_UNKNOWN;
-}
-
-
-bool CheckCommandInputs(const char* dev, 
-                        const char* img, 
-                        CommandType cmd) {
-
-    const CommandInfo* cmdInfo = GetCommandInfo(cmd);
-
-    if (!cmdInfo) {
-        printf("*** INTERNAL ERROR *** Unknown command given to CheckCommandInputs() (%d)\n", cmd);
-        return false;
-    }
-
-    char* inputDesStr [] = {
-        NULL,
-        "neither a device nor an image file",       // CI_NONE
-        "an image file",                            // CI_IMG_ONLY,
-        NULL,
-        "a device",                                 // CI_DEV_ONLY,
-        NULL,
-        "either an image file or a device",         // CI_IMG_OR_DEV,
-        NULL,
-        "both an image file and a device"           // CI_IMG_AND_DEV
-    };
-
-    CommandInput given;
-
-    if        ( dev && img) {
-        given = CI_IMG_AND_DEV;
-    } else if (!dev && img) {
-        given = CI_IMG_ONLY;
-    } else if (dev && !img) {
-        given = CI_DEV_ONLY;
-    } else {
-        given = CI_NONE;
-    }
-
-    if ((given & cmdInfo->requiredInput) == 0) {
-        printf("*** ERROR *** Command \"%s\" requires %s to be specified",
-               cmdInfo->cmdName,
-               inputDesStr[cmdInfo->requiredInput]);
-    
-        if (given != CI_NONE) {
-            printf(", but %s %s given.\n",
-                   inputDesStr[given],
-                   given == CI_IMG_AND_DEV ? "are" : "is");
-        } else {
-            printf(".\n");
-        }
-
-        return false;
-    }
-
-    return true;
-}
-
-bool CheckMaxCmdArguments(CommandType cmd, int numArgs) {
-    const CommandInfo* cmdInfo = GetCommandInfo(cmd);
-    if (!cmdInfo) {
-        printf("*** INTERNAL ERROR *** Unknown command given to CheckMaxCmdArguments (%d)\n", cmd);
-        return false;
-    }
-
-    if (cmdInfo->maxArgs >= 0 && numArgs > cmdInfo->maxArgs) {
-        printf("*** ERROR *** Command \"%s\" requires %d arguments, but %d arguments were given\n",
-               cmdInfo->cmdName,
-               cmdInfo->maxArgs,
-               numArgs);
-        return false;
-    }
-    return true;
-}
-
-////////////////////////////////////////////////////////////////////////
-// 
-
-// Return values:
-#define RC_FW_ALREADY_UPDATED 7
-
-#define NEXTS(s) do {                                        \
-    if (++i >= ac)                                           \
-    {                                                        \
-        printf("Missed parameter after \"%s\" switch\n", s); \
-        return 1;                                            \
-    }} while(0)
-#define NEXTC(p, s) do {                                           \
-    if (++i >= ac)                                                 \
-    {                                                              \
-        printf("Missed %s parameter after \"%s\" command\n", p,s); \
-        return 1;                                                  \
-    }} while(0)
-
-#define SETERR(args) do { printf("*** ERROR *** "); printf args; printf("\n"); return 1; } while(0)
-
-
-int main(int ac, char *av[])
-{
-
-    char         *image_fname=0, *device=0;
-    bool         clear_semaphore  = false;
-    bool         silent           = false; 
-    bool         guids_specified  = false;
-    bool         macs_specified   = false;
-    bool         burn_failsafe    = true;
-    bool         use_image_ps     = false;
-    bool         single_image_burn = true;
-
-    char*        cmdStr           = NULL;
-
-    char         *user_vsd=0;
-    char         *user_psid=0;
-    guid_t       user_guids[Operations::MAX_GUIDS];
-    int                 rc = 0;
-
-    CommandType cmd = CMD_UNKNOWN;
-
-    auto_ptr<Flash>       f;
-    FImage                fim;
-
-    Operations            ops;
-
-    FBase*      fbase     = NULL;
-    char*       cmdTarget = NULL;
-    char*       cmdAccess = NULL;
-
-    bool        cntx_image  = false;
-    bool        cntx_device = false;
-    //
-    // Map termination signal handlers
-    //
-    int i;
-    for (i = 0 ; i < (int)(sizeof(g_signals_for_termination)/sizeof(g_signals_for_termination[0])) ; i++ ) {
-        signal (g_signals_for_termination[i], TerminationHandler);    
-    }
-
-    if (ac < 2) {
-        usage(av[0]);
-        rc =  1; goto done; 
-    }
-
-    // Init with FFs - for ConnectX if only MAC or GUID is specified
-    memset(user_guids, 0xff, sizeof(user_guids));
-
-    // Go thru command line options
-    for (i=1; i < ac; i++) {
-        //
-        // Switches
-        // --------
-        //
-        if (*av[i] == '-') {
-            int switchLen = strlen(av[i]);
-
-            if (!strcmp(av[i], "-dual_image"))
-                single_image_burn = false;
-
-           else if (!strcmp(av[i], "-clear_semaphore")) {
-                clear_semaphore = true;
-           }
-
-            else if (!strncmp(av[i], "-device", switchLen)) {
-                NEXTS("-device");
-                device = av[i];
-
-            } else if (!strcmp(av[i], "-v") || !strcmp(av[i], "-vv")) {
-                printf("%s: %s .",
-                       av[0],
-                       _versionID);
-
-                if (!strcmp(av[i], "-vv")) {
-                    printf(" SVN %s", _svnID + 1); 
-                }
-
-                printf("\n");
-                rc =  0; goto done; 
-
-            } else if (!strcmp(av[i], "-unlock")) {
-                _unlock_bypass = true;  
-            } else if (!strcmp(av[i], "-noerase"))
-                _no_erase = true;
-            else if (!strcmp(av[i], "-noburn"))
-                _no_burn = true;
-            else if (!strcmp(av[i], "-crc"))
-                _print_crc = true;
-            else if (!strcmp(av[i], "-bytewrite")) {
-                if (device) {
-                    printf("\"-bytewrite\" should be specifies before \"-device\" switch in the command line.\n");
-                    rc =  1; goto done; 
-                }
-                _byte_write = true;
-            } else if (!strcmp(av[i], "-vsd")) {
-                NEXTS("-vsd");
-                user_vsd = av[i];
-            }
-            // -vsd1 is an alias to -vsd, for backward compatibility. Can be removed in the future.
-            else if (!strcmp(av[i], "-vsd1")) {
-                NEXTS("-vsd1");
-                user_vsd = av[i];
-            } else if (!strcmp(av[i], "-psid")) {
-                NEXTS("-psid");
-                user_psid = av[i];
-            }
-            // -vsd2 is an alias to psid, for backward compatibility. Can be removed in the future.
-            else if (!strcmp(av[i], "-vsd2")) {
-                NEXTS("-vsd2");
-                user_psid = av[i];
-            } else if (!strcmp(av[i], "-bsn")) {
-                NEXTS("-bsn");
-                GETBSN(av[i], &user_guids[0]);
-                for (int i=1; i<Operations::GUIDS; i++) {
-                    u_int64_t g=user_guids[0].h;
-                    g=(g<<32) | user_guids[0].l;
-                    g += i;
-                    user_guids[i].h = (u_int32_t)(g>>32);
-                    user_guids[i].l = (u_int32_t)g;
-                }
-                guids_specified = true;
-            } else if (!strncmp(av[i], "-image", switchLen)) {
-                NEXTS("-image");
-                image_fname = av[i];
-            } else if (!strcmp(av[i], "-guid")) {
-                NEXTS("-guid");
-                GETGUID(av[i], &user_guids[0]);
-                for (int i=1; i<Operations::GUIDS; i++) {
-                    u_int64_t g=user_guids[0].h;
-                    g=(g<<32) | user_guids[0].l;
-                    g += i;
-                    user_guids[i].h = (u_int32_t)(g>>32);
-                    user_guids[i].l = (u_int32_t)g;
-                }
-                guids_specified = true;
-            } else if (!strcmp(av[i], "-guids")) {
-                if (i + 4 >= ac) {
-                    printf("Exactly four GUIDs must be specified.\n");
-                    rc =  1; goto done;                    
-                }
-                i++;
-                for (int j=0; j<Operations::GUIDS; j++) {
-                    GETGUID(av[i+j], &user_guids[j]);
-                }
-                i += 3;
-                guids_specified = true;
-
-            } else if (!strcmp(av[i], "-mac")) {
-                NEXTS("-mac");
-                GETGUID(av[i], &user_guids[Operations::GUIDS]);
-                for (int i=1; i < Operations::MACS ; i++) {
-                    u_int64_t g=user_guids[Operations::GUIDS].h;
-                    g=(g<<32) | user_guids[Operations::GUIDS].l;
-                    g += i;
-                    user_guids[Operations::GUIDS + i].h = (u_int32_t)(g>>32);
-                    user_guids[Operations::GUIDS + i].l = (u_int32_t)g;
-                }
-                macs_specified = true;
-            } else if (!strcmp(av[i], "-macs")) {
-                if (i + 2 >= ac) {
-                    printf("Exactly two MACs must be specified.\n");
-                    rc =  1; goto done;                    
-                }
-                i++;
-                for (int j=0; j<Operations::MACS; j++) {
-                    GETGUID(av[i+j], &user_guids[Operations::GUIDS+j]);
-                }
-                i += 1;
-                macs_specified = true;
-            } else if (!strncmp(av[i], "-silent", switchLen))
-                silent = true;
-            else if (!strncmp(av[i], "-use_image_ps", 2))
-                use_image_ps = true;
-            else if (!strncmp(av[i], "-nofs", 5))
-                burn_failsafe = false;
-            else if (!strcmp(av[i], "-skip_is"))
-                ops.SetAllowSkipIs(true);
-            else if (!strcmp(av[i], "-striped_image"))
-                ops.SetCntxStripedImage(true);
-            else if (!strcmp(av[i], "-blank_guids"))
-                ops.SetBurnBlankGuids(true);
-            else if (!strncmp(av[i], "-yes", switchLen))
-                _assume_yes = true;
-            else if (!strcmp(av[i], "-no"))
-                _assume_no = true;
-            else if (!strcmp(av[i], "-byte_mode"))
-                Flash::_byte_mode = true;
-
-            else if (!strncmp(av[i], "-hh", 3) ||  !strncmp(av[i], "--hh", 4)) {
-                usage(av[0], true);
-                rc =  0; goto done; 
-            } else if (!strncmp(av[i], "-help", switchLen) ||  !strncmp(av[i], "--h", 3)) {
-                usage(av[0]);
-                rc =  0; goto done; 
-            } else {
-                printf("*** ERROR *** Invalid switch \"%s\" is specified.\n", av[i]);
-                rc =  1; goto done; 
-            }
-        }  else {
-            // command
-            cmdStr = av[i];
-            break;
-        }
-    }
-
-    if (_assume_yes && _assume_no) {
-        printf("*** ERROR *** -yes and -no options can not be specified together.\n");
-        rc =  1; goto done; 
-    }
-
-    if (ops.GetBurnBlankGuids() && (guids_specified || macs_specified)) {
-        const char* flag = "-guid(s)";
-
-        if (macs_specified && !guids_specified) {
-            flag = "-mac(s)";
-        }
-
-        printf("*** ERROR *** -blank_guids and %s options can not be specified together.\n", flag);
-        rc =  1; goto done; 
-    }
-
-    //
-    // Commands
-    // --------
-    //
-
-    if (clear_semaphore) {
-        if (cmdStr) {
-            printf("*** ERROR *** No command is allowed when -clear_semaphore flag is given.\n");
-            rc =  1; goto done; 
-        } else {
-            cmdStr = "clear_semaphore";
-        }
-    }
-
-    if (!cmdStr) {
-        printf("*** ERROR *** No command given. See help for details.\n");  
-        rc =  1; goto done; 
-    }
-
-    //
-    // Check and parse command
-    //
-    cmd = ParseCommand(cmdStr);
-
-    if (cmd == CMD_UNKNOWN) {
-        printf("*** ERROR *** Invalid command \"%s\".\n", av[i]);
-        rc =  1; goto done; 
-    }
-
-    if (cmd == CMD_CLEAR_SEM) {
-        clear_semaphore = true;
-    }
-
-    if (!CheckCommandInputs(device, image_fname, cmd)) {
-        rc = 1; goto done;
-    }
-
-    if (!CheckMaxCmdArguments(cmd, ac - i - 1 )) {
-        rc = 1; goto done;
-    }
-
-    if (device) {
-        // Open the device
-        auto_ptr<Flash>       tmp(new Flash);
-        f = tmp;
-        
-        if (f.get() == NULL) {
-            printf("*** ERROR *** Memory allocation failed\n");
-            rc =  1; goto done; 
-        }
-               
-        g_flash = f.get();
-        if (!f->open(device, clear_semaphore)) {
-            printf("*** ERROR *** Can not open %s: %s\n", device, f->err());
-            rc =  1; goto done; 
-        }
-
-        ops.SetNumPorts(f->get_port_num());
-
-        cmdTarget = "Flash";
-        cmdAccess = device;
-        fbase     = f.get();
-
-        // Connectx Mode:
-        cntx_device = ops.CheckIsCntx(*fbase);
-    }
-
-    if (image_fname) {
-        if (!fim.open(image_fname)) {
-            printf("*** ERROR *** Image file open failed: %s\n", fim.err());
-            rc =  1; goto done; 
-        }
-
-        cmdTarget = "Image file";
-        cmdAccess = image_fname;
-        fbase     = &fim;
-
-        // Connectx Mode:
-        cntx_image = ops.CheckIsCntx(fim);
-    }
-
-    ops.SetCntxMode(cntx_image || cntx_device);
-
-    switch (cmd) {
-    case CMD_BURN:
-    case CMD_BURN_BLOCK:
-    {
-        
-        //
-        // BURN
-        //
-        Operations::ImageInfo fileInfo;
-        Operations::ImageInfo flashInfo;
-        bool burn_block = (cmd == CMD_BURN_BLOCK);
-                
-        if (!burn_block) {
-
-            if (cntx_image != cntx_device) {
-                printf("*** ERROR *** The given device is %sa ConnectX HCA, but the given image file %s a ConnectX FW image\n", 
-                       cntx_device ? ""         : "not ",
-                       cntx_image  ? "contains" : "does not contain");
-                rc =  1; goto done; 
-            }
-
-            // Make checks and replace vsd/guids.    
-            bool old_silent = _silent;
-            _silent = true;
-            if (!ops.Verify(fim, &fileInfo) || !ops.QueryAll(fim, &fileInfo)) {
-                printf("*** ERROR *** %s: Not a valid image file (%s)\n", image_fname, ops.err());
-                rc =  1; goto done; 
-            }
-                        
-            // Get GUID and VSD info from flash
-            
-            bool read_guids = true;
-            bool read_ps    = true;
-            
-            // Flash query (unlike image file query) does not have to
-            // pass. E.G. blank flash and the user supplies the needed data (guids, vsd).
-            
-            bool flash_query_res = ops.Verify(*f, &flashInfo) && ops.QueryAll(*f, &flashInfo);
-
-            bool ib_dev;
-            bool eth_dev;
-
-            ops.SetDevFlags(fileInfo.devType, ib_dev,eth_dev);
-
-            if ((user_vsd && user_psid) || use_image_ps)
-                read_ps = false;
-
-            if (ops.GetBurnBlankGuids() ||
-                (guids_specified && ib_dev) || 
-                (macs_specified && eth_dev))
-                read_guids = false;
-
-            if (read_guids && !flash_query_res) {
-                char* missing_info;
-                char* missing_flags;
-
-                if (ib_dev && eth_dev) {
-                    missing_info  = "GUIDs / MACs";
-                    missing_flags = "-guid(s) / -mac(s)";
-                } else if (ib_dev) {
-                    missing_info  = "GUIDs";
-                    missing_flags = "-guid(s)";
-                } else {
-                    missing_info  = "MACs";
-                    missing_flags = "-mac(s)";
-                }
-
-                if (read_guids && !flashInfo.imageOk) {
-                    printf("\n");
-                    printf("*** ERROR *** Can not extract %s info from flash. "
-                           "Please specify %s (using command line flags %s ). \n", missing_info, missing_info, missing_flags);
-                }
-
-                if (burn_failsafe) {
-                    printf("              Can not burn in a failsafe mode.\n");
-                   printf("              If you want to burn in non failsafe mode, use the \"-nofs\" switch.\n");
-                }
-                rc =  1; goto done;
-            }
-
-            // Patch GUIDS
-            if  (guids_specified || macs_specified) {
-                if (!ops.CheckGuidsFlags(fileInfo.devType, ib_dev, guids_specified, eth_dev, macs_specified)) {
-                    printf("*** ERROR *** %s\n", ops.err());
-                    rc =  1; goto done;
-                }
-
-                if (!ops.patchGUIDs(fim,
-                                    &fileInfo,
-                                    ib_dev,
-                                    eth_dev,
-                                    guids_specified,
-                                    macs_specified,
-                                    user_guids,
-                                    flashInfo.imageOk ? flashInfo.guids : NULL,
-                                    flashInfo.guidNum,
-                                    true)) {
-                    rc =  1; goto done;
-                }
-            } else {
-                if (!ops.patchGUIDs(fim,
-                                    &fileInfo,
-                                    ib_dev,
-                                    eth_dev,
-                                    false,
-                                    false,
-                                    NULL,  
-                                    flashInfo.guids,
-                                    flashInfo.guidNum,
-                                    false)) {
-                    rc =  1; goto done;
-                }
-            }
-
-            if (burn_failsafe && (!fileInfo.isFailsafe || !flashInfo.isFailsafe)) {
-                printf("*** ERROR *** Failsafe burn failed: FW image in the %s is non failsafe.\n",         fileInfo.isFailsafe ? "flash" : "given file");
-                printf("              It is impossible to burn %sa non failsafe image in a failsafe mode.\n", fileInfo.isFailsafe ? "over " : "");
-                printf("              If you want to burn in non failsafe mode, use the \"-nofs\" switch.\n");
-                rc =  1; goto done; 
-            }
-
-            if (!user_vsd && !(flashInfo.psOk || (flashInfo.infoOffs[Operations::II_PSID] && 
-                                                flashInfo.infoOffs[Operations::II_VSD]  ))) {
-                printf("\n");
-                if (burn_failsafe) {
-
-                    printf("*** ERROR *** Can not extract VSD/PSID info from flash.\n"
-                           "              Can not burn in a failsafe mode. Please use \"-nofs\" flag to burn in a non failsafe mode.\n");
-                    rc =  1; goto done;
-                }  else {
-                    printf("*** WARNING *** Can not extract VSD/PSID info from flash.\n\n"
-                           "    To use a specific VSD, abort and re-burn specifying the\n"
-                           "    needed info (using command line flags -vsd / -use_image_ps).\n"
-                           "    You can also continue burn using blank VSD.\n");
-                
-                    if (!ops.ask_user()) {
-                        rc =  1; goto done;
-                    }
-                }
-            }
-
-            // Print FW versions:
-            printf("\n");
-            printf("    Current FW version on flash:  ");
-            if (flashInfo.infoOffs[Operations::II_FwVersion]) {
-                printf("%d.%d.%d\n", flashInfo.fwVer[0], flashInfo.fwVer[1], flashInfo.fwVer[2]);  
-            } else {
-                printf("N/A\n");
-            }
-            
-            printf("    New FW version:               ");
-            if (fileInfo.infoOffs[Operations::II_FwVersion]) {
-                printf("%d.%d.%d\n", fileInfo.fwVer[0], fileInfo.fwVer[1], fileInfo.fwVer[2]);  
-            } else {
-                printf("N/A\n");
-            }
-
-            bool updateRequired = true;
-
-            if (fileInfo.infoOffs[Operations::II_FwVersion]  && 
-                flashInfo.infoOffs[Operations::II_FwVersion]) {
-
-                updateRequired = ops.FwVerLessThan(flashInfo.fwVer,fileInfo.fwVer);
-            }
-
-            if (!updateRequired) {
-                printf("\n    Note: The new FW version is not newer than the current FW version on flash.\n");
-                if (! ops.ask_user()) {
-                    rc =  RC_FW_ALREADY_UPDATED; goto done;
-                }
-            }
-
-            if (fileInfo.infoOffs[Operations::II_IsGa] && !fileInfo.isGa) {
-                printf("\n    Note: You are attempting to burn a pre-production FW image.\n");
-                if (! ops.ask_user()){
-                    rc =  1; goto done;
-                }
-            }
-
-            if (!use_image_ps) {
-                if (fileInfo.psOk || (ops.IsCntx() && fileInfo.infoOffs[Operations::II_VSD])) {
-                    if (!ops.patchVSD(fim, 
-                                      &fileInfo,
-                                      user_vsd, 
-                                      user_psid,
-                                      flashInfo.vsd,
-                                      NULL,
-                                      fileInfo.psid )) {
-                        rc =  1; goto done;
-                    }
-                }
-            }
-
-            // Check PSID and ib -> eth change.
-
-            if (fileInfo.infoOffs[Operations::II_PSID]  && 
-                flashInfo.infoOffs[Operations::II_PSID] && 
-                strncmp( fileInfo.psid, flashInfo.psid, PSID_LEN)) {
-                if (ops.IsCntx() && 
-                    (!ib_dev && eth_dev) && 
-                    flashInfo.infoOffs[Operations::II_DeviceType] &&
-                     ops.CntxIsIb(flashInfo.devType) &&
-                    !ops.CntxIsEth(flashInfo.devType)) {
-
-                    printf("\n    You are about to replace FW image type from IB to ETH image.\n");
-                } else {
-                    printf("\n    You are about to replace current PSID on flash - \"%s\" with a different PSID - \"%s\".\n"
-                           "    Note: It is highly recommended not to change the PSID.\n",
-                           flashInfo.psid, 
-                           fileInfo.psid);
-                }
-
-                if (! ops.ask_user()){
-                    rc =  1; goto done;
-                }
-            }           
-
-            // Check exp rom:
-            if (!fileInfo.expRomFound && flashInfo.expRomFound) {
-                printf("\n    Expansion-ROM mismatch: \n"
-                       "    Current FW on flash contains an expansion-ROM.\n"
-                       "    The new FW image does not contain an expansion-ROM\n");
-
-                if (! ops.ask_user()){
-                    rc =  1; goto done;
-                }
-            }
-
-            _silent = old_silent;
-
-        } else {
-            // BURN BLOCK:
-            burn_failsafe = false;
-        }
-
-        // Burn it
-        if (burn_failsafe) {
-            // FS burn
-            bool ret;
-            if (ops.IsCntx()) {
-                ret = ops.CntxFailSafeBurn(*f,
-                                           fim,
-                                           !silent,
-                                           &flashInfo,
-                                           &fileInfo,
-                                           false);
-                                           
-            } else {
-                ret = ops.FailSafeBurn(*f, 
-                                       fim,
-                                       !silent,
-                                       single_image_burn);
-            }
-
-            if (!ret) {
-               if (f->err()) {
-                   // The error is in flash access:
-                   printf("*** ERROR *** Flash access failed during burn: %s\n", f->err());
-               } else {
-                   // operation/ algorithm error:
-                   printf("*** ERROR *** Failsafe burn error: %s\n", ops.err());  
-               }
-                rc =  1; goto done; 
-            }
-        } else {
-            //
-            // Not failsafe (sequential) burn
-            //
-
-            // Ask is it OK
-            printf("\n");
-            if (burn_block) {
-                printf("Block burn: The given image will be burnt as is. No fields (such\n");
-                printf("as GUIDS,VSD) are taken from current image on flash.\n");
-            }
-            printf("Burn process will not be failsafe. No checks will be performed.\n");
-
-            printf("ALL flash, including the Invariant Sector will be overwritten.\n");
-            printf("If this process fails, computer may remain in an inoperable state.\n");
-
-            if (!ops.ask_user()) {
-                rc =  1; goto done;
-           }
-
-            // Non FS burn
-            bool ret;
-            if (ops.IsCntx() && !burn_block) {
-                ret = ops.CntxFailSafeBurn(*f,
-                                           fim,
-                                           !silent,
-                                           &flashInfo,
-                                           &fileInfo,
-                                           true); // Allow nofs
-            } else {
-                ret = ops.write_image(*f, 0, fim.getBuf(), fim.getBufLength(),!silent);
-            }
-
-        
-            if (!ret) {
-                report("\n");
-                printf("*** ERROR *** Non failsafe burn failed: %s\n", ops.err());
-                rc =  1; goto done; 
-            }
-            report("\n");
-        }
-    }
-    break;
-    case CMD_SET_GUIDS:
-    {
-        Operations::ImageInfo info;
-        u_int32_t guid_sect_addr[2] = {0};
-        u_int32_t i;
-
-        if (ops.IsCntx()) {
-            _silent       = true;
-            if (!ops.VerifyCntx(*fbase, &info, false, true)) {
-                printf("\n*** ERROR *** Can not set GUIDs: %s. \n", ops.err());
-                rc =  1; goto done;
-            }
-            _silent = false;
-        }
-
-        if (!ops.QueryAll(*fbase, &info)) {
-            printf("*** ERROR *** Can not set GUIDs: %s query (%s) failed: %s\n", cmdTarget , cmdAccess, ops.err());
-            rc =  1; goto done;
-        }
-
-        if (!info.blankGuids) {
-            printf("\n*** ERROR *** Can not set GUIDs: Guids are already set.\n");
-            rc =  1; goto done;
-        }
-
-        bool ib_dev;
-        bool eth_dev;
-
-        ops.SetDevFlags(info.devType, ib_dev, eth_dev);
-
-        if (macs_specified || guids_specified) {
-            if (!ops.CheckGuidsFlags(info.devType, ib_dev, guids_specified, eth_dev, macs_specified)) {
-                printf("*** ERROR *** %s\n", ops.err());
-                rc =  1; goto done;
-            }
-        } else {
-            char* missing_info;
-            char* missing_flags;
-
-            if (ib_dev && eth_dev) {
-                missing_info  = "GUIDs / MACs";
-                missing_flags = "-guid(s) / -mac(s)";
-            } else if (ib_dev) {
-                missing_info  = "GUIDs";
-                missing_flags = "-guid(s)";
-            } else {
-                missing_info  = "MACs";
-                missing_flags = "-mac(s)";
-            }
-
-            printf("\n");
-            printf("*** ERROR *** For set_guids command, "
-                   "Please specify %s (using command line flags %s ). \n", missing_info, missing_flags);
-
-            rc = 1; goto done;
-        }
-
-        if (ops.IsCntx() || !info.isFailsafe) {
-            guid_sect_addr[0] = info.guidPtr;
-        } else {
-            int addr_idx = 0;
-            for (i = 0; i < 2; i++) {
-                if (info.allImgStart[i]) {
-                    guid_sect_addr[addr_idx] = info.allImgStart[i] + info.guidPtr;
-                    addr_idx++;
-                }
-            }
-        }
-
-        for (i = 0; i < 2 && guid_sect_addr[i]; i++ ) {
-            u_int32_t guid_sect[Operations::MAX_GUIDS*2 + 5]; // Save room for header + crc
-            
-            if (!f->read(guid_sect_addr[i] - 16 , guid_sect, 16)) {
-                printf("*** ERROR *** Failed to read guids section - flash read error (%s)\n", fbase->err());
-            }
-            
-            ops.patchGUIDsSection (guid_sect, 16, user_guids, info.guidNum);
-    
-            if (!f->write(guid_sect_addr[i], guid_sect + 4 , info.guidNum * 8 + 4, true)) {
-                printf("*** ERROR *** Guids set failed - flash write error (%s)\n", fbase->err());
-            }
-        }
-    }
-    break;
-
-    case CMD_ERASE_SECT:
-    {    
-        //
-        // ERASE SECTOR <ADDR>
-        //     Parameters: <ADDR>
-        //
-        u_int32_t    addr;
-        char         *endp;
-
-        // Address of sector to erase
-        NEXTC("<ADDR>", "erase");
-        addr = strtoul(av[i], &endp, 0);
-        if (*endp) {
-            printf("Invalid address \"%s\"\n", av[i]);
-            rc =  1; goto done; 
-        }
-
-        // Erase
-        if (!f->erase_sector(addr)) {
-            printf("*** ERROR *** Erase sector failed: %s\n", f->err());
-            rc =  1; goto done; 
-        }
-    }
-    break;
-
-    case CMD_QUERY_FORCE:
-    case CMD_QUERY:
-    {
-        // QUERY
-        Operations::ImageInfo info;
-        bool imageOk;
-        bool checkValidImage = false;
-
-        _silent       = true;
-        if (cmd == CMD_QUERY_FORCE) {
-            printf("\n*** WARNING *** Running query without verifying the image first. Results may be undefined.\n"); 
-            if (ops.IsCntx()) {
-                imageOk = ops.VerifyCntx(*fbase, &info, false, true);
-                checkValidImage = true;
-            }
-        } else {
-            imageOk = ops.Verify(*fbase, &info);
-            checkValidImage = true;
-        }
-        _silent = false;
-
-        if (checkValidImage && !imageOk) {
-            printf("\n*** ERROR *** %s query (%s) failed. Not a valid image.\n", cmdTarget , cmdAccess);
-            rc =  1; goto done; 
-        }
-
-        if (!ops.QueryAll(*fbase, &info)) {
-                printf("*** ERROR *** %s query (%s) failed: %s\n", cmdTarget , cmdAccess, ops.err());
-                rc =  1; goto done;
-        }
-
-        ops.DisplayImageInfo(&info);
-    }
-    break;
-
-    case CMD_QUERY_ROM:
-    {
-        Operations::ImageInfo info;
-        if (!ops.LoadAsExpRom(*fbase)    || 
-            !ops.GetExpRomVersion(&info) || 
-            !ops.DisplayExpRomInfo(&info)) {
-            printf("*** ERROR *** %s rom query (%s) failed: %s\n", cmdTarget , cmdAccess, ops.err());
-            rc =  1; goto done;
-        }
-    }
-    break;
-    case CMD_READ_BLOCK:
-    {
-        // READ BLOCK
-        //     Parameters:  <ADDR> <LENGTH> [OUT_FILENAME]
-        //     if OUT_FILENAME is given, binari read block is stored
-        //     in the given file. Otherwise, data is printed to screen.
-        u_int32_t    addr, length;
-        u_int8_t     *data;
-        char         *endp;
-
-        bool         to_file = false;
-
-        // Address and length
-        NEXTC("<ADDR>", "rb");
-        addr = strtoul(av[i], &endp, 0);
-        if (*endp) {
-            printf("Invalid address \"%s\"\n", av[i]);
-            rc =  1; goto done; 
-        }
-        NEXTC("<LENGTH>", "rb");
-        length = strtoul(av[i], &endp, 0);
-        if (*endp) {
-            printf("Invalid length \"%s\"\n", av[i]);
-            rc =  1; goto done; 
-        }
-        data = new u_int8_t[length];
-
-        // Output file
-        FILE*  fh = NULL;
-
-        if (i + 2 == ac)
-            to_file = true;
-
-        if (to_file) {
-            NEXTC("<OUT_FILENAME>", "rb");
-            if ((fh = fopen(av[i], "wb")) == NULL) {
-                fprintf(stderr, "Can not open ");
-                perror(av[i]);
-                rc =  1; goto done; 
-            }
-        }
-
-        // Read flash
-        if (!fbase->read(addr, data, length)) {
-            printf("*** ERROR *** Flash read failed: %s\n", fbase->err());
-            rc =  1; goto done; 
-        }
-
-        if (to_file) {
-            // Write output
-            if (fwrite(data, 1, length, fh) != length) {
-                perror("Write error");
-                rc =  1; goto done; 
-            }
-            fclose(fh);
-        } else {
-            for (u_int32_t i = 0; i < length ; i+=4) {
-                u_int32_t word = *((u_int32_t*)(data + i));
-
-                word  = __be32_to_cpu(word);
-                printf("0x%08x ", word);  
-            }
-            printf("\n");
-        }
-        delete [] data;
-    }
-    break;
-
-    case CMD_READ_WORD:
-    {
-        // READ DWORD <ADDR>
-        //     Parameters: <ADDR>
-        u_int32_t    data, addr;
-        char         *endp;
-
-        // Address
-        NEXTC("<ADDR>", "rw");
-        addr = strtoul(av[i], &endp, 0);
-        if (*endp) {
-            printf("Invalid address \"%s\"\n", av[i]);
-            rc =  1; goto done; 
-        }
-
-        // Read
-        if (!f->read(addr, &data)) {
-            printf("*** ERROR *** Flash read failed: %s\n", f->err());
-            rc =  1; goto done; 
-        }
-        printf("0x%08x\n", (unsigned int)__cpu_to_be32(data));
-
-    } 
-    break;
-
-    case CMD_VERIFY:
-    {
-        // VERIFY
-        if (!ops.Verify(*fbase, NULL, true)) {
-            printf("\n*** ERROR *** FW image verification failed");
-            if (ops.err()) {
-                printf(": %s", ops.err());
-            }
-            printf(". AN HCA DEVICE CAN NOT BOOT FROM THIS IMAGE.\n");
-            rc =  1; goto done; 
-        } else {
-            printf("\nFW image verification succeeded. Image is bootable.\n\n");
-        }
-    }
-    break;
-
-    case CMD_DUMP_CONF:
-    {
-        // Dump conf
-        _silent = true;
-
-        char* conf_file = NULL;
-        if (i + 2 <= ac) {
-            NEXTC("<OUT_FILENAME>", "dc");
-            conf_file = av[i];
-        }
-
-        ops.Verify(*fbase);
-
-        if(!ops.DumpConf(conf_file)) {
-            printf("*** ERROR *** Failed dumping FW configuration: %s\n", ops.err());
-            rc =  1; goto done; 
-        }
-    }
-    break;
-
-    case CMD_READ_IMAGE:
-    {
-        // Dump conf
-        _silent = true;
-
-        char* img_file = NULL;
-        NEXTC("<OUT_FILENAME>", "ri");
-        img_file = av[i];
-
-        // For ConnectX, read only a single image. For other HCAs, try to read both images, since
-        // the distributed image binary file also contains both images.
-        ops.Verify(*f, NULL, !ops.IsCntx());
-        
-        //printf("Last addr: 0x%08x\n", ops._last_image_addr);
-
-        u_int32_t length = ops._last_image_addr;
-        u_int8_t* data = new u_int8_t[length];
-
-        FILE* fh;
-
-        if ((fh = fopen(av[i], "wb")) == NULL) {
-            fprintf(stderr, "Can not open ");
-            perror(av[i]);
-            rc =  1; goto done; 
-        }
-
-        // Read flash
-        if (!f->read(0, data, length)) {
-            printf("*** ERROR *** Flash read failed: %s\n", f->err());
-            rc =  1; goto done; 
-        }
-
-        // Write output
-        if (fwrite(data, 1, length, fh) != length) {
-            perror("Write error");
-            rc =  1; goto done; 
-        }
-        fclose(fh);
-
-        delete [] data;
-    }
-    break;
-
-    case CMD_WRITE_BLOCK:
-    {
-        // WRITE BLOCK
-        //     Parameters:  <IN_FILENAME> <ADDR>
-        u_int32_t    addr;
-        char         *endp;
-
-        // Input file
-        FImage fim;
-
-        NEXTC("<IN_FILENAME>", "wb");
-
-        image_fname = av[i];
-
-        // Address
-        NEXTC("<ADDR>", "wb");
-        addr = strtoul(av[i], &endp, 0);
-        if (*endp) {
-            printf("Invalid address \"%s\"\n", av[i]);
-            rc =  1; goto done; 
-        }
-
-        if (!fim.open(image_fname)) {
-            printf("*** ERROR *** Image file open failed: %s\n", fim.err());
-            rc =  1; goto done; 
-        }
-
-        // Write flash
-        if (!ops.write_image(*f, addr, fim.getBuf(), fim.getBufLength(), !silent)) {
-            printf("*** ERROR *** Flash write failed: %s\n", ops.err());
-            rc =  1; goto done; 
-        }
-    }
-    break;
-
-    case CMD_WRITE_WORD:
-    {
-        // WRITE DWORD
-        //     Parameters: <ADDR> <DATA>
-        u_int32_t    data, addr;
-        char         *endp;
-
-        // Address and data
-        NEXTC("<ADDR>", "ww");
-        addr = strtoul(av[i], &endp, 0);
-        if (*endp) {
-            printf("Invalid address \"%s\"\n", av[i]);
-            rc =  1; goto done; 
-        }
-        NEXTC("<DATA>", "ww");
-        data = __cpu_to_be32(strtoul(av[i], &endp, 0));
-        if (*endp) {
-            printf("Invalid data \"%s\"\n", av[i]);
-            rc =  1; goto done; 
-        }
-
-        //f->curr_sector = 0xffffffff;  // First time erase sector
-        if (!f->write(addr, data)) {
-            printf("*** ERROR *** Flash write failed: %s\n", f->err());
-            rc =  1; goto done; 
-        }
-    }
-    break;
-
-    case CMD_WRITE_BLOCK_NE:
-    {
-        // WRITE DWORD WITHOUT ERASE
-        //     Parameters: <ADDR> <SIZE> <DATA>
-        u_int32_t    size, addr;
-        char         *endp;
-
-        // Address and data
-        NEXTC("<ADDR>", "wbne");
-        addr = strtoul(av[i], &endp, 0);
-        if (*endp) {
-            printf("Invalid address \"%s\"\n", av[i]);
-            rc =  1; goto done; 
-        }
-        NEXTC("<SIZE>", "wbne");
-        size = strtoul(av[i], &endp, 0);
-        if (*endp || size % 4) {
-            printf("Invalid size \"%s\"\n", av[i]);
-            rc =  1; goto done; 
-        }
-        vector<u_int32_t> data_vec(size/4);
-        for (u_int32_t w = 0; w < size/4 ; w++) {
-            NEXTC("<DATA>", "wbne");
-            data_vec[w] = __cpu_to_be32(strtoul(av[i], &endp, 0));
-            if (*endp) {
-                printf("Invalid data \"%s\"\n", av[i]);
-                rc =  1; goto done; 
-            }
-
-            //printf("-D- writing: %08x : %08x\n", addr + w*4 , data_vec[w]);
-        }
-
-        if (!f->write(addr, &data_vec[0], size, true)) {
-            printf("*** ERROR *** Flash write failed: %s\n", f->err());
-            rc =  1; goto done; 
-        }
-    }
-    break;
-
-    case CMD_WRITE_WORD_NE:
-    {
-        // WRITE DWORD WITHOUT ERASE
-        //     Parameters: <ADDR> <DATA>
-        u_int32_t    data, addr;
-        char         *endp;
-
-        // Address and data
-        NEXTC("<ADDR>", "wwne");
-        addr = strtoul(av[i], &endp, 0);
-        if (*endp) {
-            printf("Invalid address \"%s\"\n", av[i]);
-            rc =  1; goto done; 
-        }
-        NEXTC("<DATA>", "wwne");
-        data = __cpu_to_be32(strtoul(av[i], &endp, 0));
-        if (*endp) {
-            printf("Invalid data \"%s\"\n", av[i]);
-            rc =  1; goto done; 
-        }
-
-        if (!f->write(addr, &data, 4, true)) {
-            printf("*** ERROR *** Flash write failed: %s\n", f->err());
-            rc =  1; goto done; 
-        }
-    }
-    break;
-
-    case CMD_CFI:
-    {
-        if (!f->print_attr() || !f->print_attr_old_format()) {
-            printf("*** ERROR *** Cfi query failed: %s\n", f->err());
-            rc =  1; goto done; 
-        }
-    }
-    break;
-
-    case CMD_CLEAR_SEM:
-        // Do nothing - opening the device already cleared the semaphore.
-        break;
-
-    default:
-        printf("*** INTERNAL ERROR *** Invalid command %d.\n", cmd);
-        rc =  1; goto done; 
-    }
-
-done:
-    //mask signals   
-    for (i = 0 ; i < (int)(sizeof(g_signals_for_termination)/sizeof(g_signals_for_termination[0])) ; i++ ) {
-        signal (g_signals_for_termination[i], SIG_IGN);    
-    }
-
-    return rc;
-}
-
diff --git a/tools/flint/user/flint.rc b/tools/flint/user/flint.rc
deleted file mode 100644 (file)
index 62ad3fd..0000000
+++ /dev/null
@@ -1,47 +0,0 @@
-/*\r
- * Copyright (c) 2005 Mellanox Technologies.  All rights reserved.\r
- *\r
- * This software is available to you under the OpenIB.org BSD license\r
- * below:\r
- *\r
- *     Redistribution and use in source and binary forms, with or\r
- *     without modification, are permitted provided that the following\r
- *     conditions are met:\r
- *\r
- *      - Redistributions of source code must retain the above\r
- *        copyright notice, this list of conditions and the following\r
- *        disclaimer.\r
- *\r
- *      - Redistributions in binary form must reproduce the above\r
- *        copyright notice, this list of conditions and the following\r
- *        disclaimer in the documentation and/or other materials\r
- *        provided with the distribution.\r
- *\r
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,\r
- * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\r
- * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND\r
- * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS\r
- * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN\r
- * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN\r
- * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\r
- * SOFTWARE.\r
- *\r
- * $Id$\r
- */\r
-\r
-\r
-#include <oib_ver.h>\r
-\r
-#define VER_FILETYPE                           VFT_APP\r
-#define VER_FILESUBTYPE                                VFT2_UNKNOWN\r
-\r
-#if DBG\r
-#define VER_FILEDESCRIPTION_STR                "Mellanox HCAs FW burning tool. (Debug)"\r
-#else\r
-#define VER_FILEDESCRIPTION_STR                "Mellanox HCAs FW burning tool."\r
-#endif\r
-\r
-#define VER_INTERNALNAME_STR           "flint.exe"\r
-#define VER_ORIGINALFILENAME_STR       "flint.exe"\r
-\r
-#include <common.ver>\r
diff --git a/tools/flint/user/makefile b/tools/flint/user/makefile
deleted file mode 100644 (file)
index 128ed37..0000000
+++ /dev/null
@@ -1,7 +0,0 @@
-#\r
-# DO NOT EDIT THIS FILE!!!  Edit .\sources. if you want to add a new source\r
-# file to this component.  This file merely indirects to the real make file\r
-# that is shared by all the driver components of the Windows NT DDK\r
-#\r
-\r
-!INCLUDE ..\..\..\inc\openib.def\r
diff --git a/tools/flint/user/mflash.c b/tools/flint/user/mflash.c
deleted file mode 100644 (file)
index bf74a50..0000000
+++ /dev/null
@@ -1,2308 +0,0 @@
-/*
- * Copyright (c) 2006 Mellanox Technologies.  All rights reserved.
- *
- * This software is available to you under the OpenIB.org BSD license
- * below:
- *
- *     Redistribution and use in source and binary forms, with or
- *     without modification, are permitted provided that the following
- *     conditions are met:
- *
- *      - Redistributions of source code must retain the above
- *        copyright notice, this list of conditions and the following
- *        disclaimer.
- *
- *      - Redistributions in binary form must reproduce the above
- *        copyright notice, this list of conditions and the following
- *        disclaimer in the documentation and/or other materials
- *        provided with the distribution.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
- * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
- * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
- * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
- * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
- * 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.
- */
-
-#ifdef IRISC
-#include <tavor_mac.h>
-#define __cpu_to_be32(val) (val)
-#define NULL 0
-#else
-
-#include <mtcr.h>
-#include <stdlib.h>
-#include <stdio.h>
-#include <errno.h>
-#include <string.h>
-
-
-// Bit Slicing macros
-#define ONES32(size)                    ((size)?(0xffffffff>>(32-(size))):0)
-#define MASK32(offset,size)             (ONES32(size)<<(offset))
-
-#define EXTRACT_C(source,offset,size)   ((((unsigned)(source))>>(offset)) & ONES32(size))
-#define EXTRACT(src,start,len)          (((len)==32)?(src):EXTRACT_C(src,start,len))
-
-#define MERGE_C(rsrc1,rsrc2,start,len)  ((((rsrc2)<<(start)) & (MASK32((start),(len)))) | ((rsrc1) & (~MASK32((start),(len)))))
-#define MERGE(rsrc1,rsrc2,start,len)    (((len)==32)?(rsrc2):MERGE_C(rsrc1,rsrc2,start,len))
-
-
-#ifndef __WIN__
-
-#if defined __DJGPP__
-//
-// DJGPP - GCC PORT TO MS DOS
-//
-
-#include <netinet/in.h>
-#include <unistd.h>
-
-#define bswap_32(x) ntohl(x)
-
-
-#else // Linux GCC
-
-#include <byteswap.h>
-#include <endian.h>
-
-#endif // __DJGPP__
-
-#define SWAPL(l) bswap_32(l)
-
-#ifndef __cpu_to_be32
-#if __BYTE_ORDER == __LITTLE_ENDIAN
-#define __cpu_to_be32(val) SWAPL(val)
-#else
-#define __cpu_to_be32(val) (val)
-#endif
-#endif
-
-#else // __WIN__
-
-//
-// Windows (Under DDK)
-//
-
-#include <io.h>
-#include <Winsock2.h>
-#define SWAPL(l) ntohl(l)
-#define inline __inline
-#define __cpu_to_be32(val) SWAPL(val) // Win is only run on LE CPUS
-
-#endif // __WIN__
-#endif
-
-#include "mflash.h"
-
-#ifndef __be32_to_cpu
-#define __be32_to_cpu(val)  __cpu_to_be32(val)
-#endif
-
-#ifndef zero
-#define zero 0
-#endif
-
-//
-// Mellanox Technologies LTD Devices naming/abbreviation convention in this file:
-//
-// InfiniHost       ihst
-// InfiniHostIII    ihst3
-// InfiniHostIIILx  ih3lx
-// ConnectX         cntx
-//
-
-
-/*
-*  Low level operations
-*/
-
-/* Flash Functions: */
-//typedef struct mflash *mflash;
-
-typedef int (*f_mf_lock)      (mflash* mfl);
-typedef int (*f_mf_unlock)    (mflash* mfl);
-
-typedef int (*f_mf_set_bank)  (mflash* mfl, u_int32_t bank);
-typedef int (*f_mf_read)      (mflash* mfl, u_int32_t addr, u_int32_t len, u_int8_t* data);
-typedef int (*f_mf_write)     (mflash* mfl, u_int32_t addr, u_int32_t len, u_int8_t* data);
-typedef int (*f_mf_erase_sect)(mflash* mfl, u_int32_t addr);
-typedef int (*f_mf_reset)     (mflash* mfl);
-
-typedef int (*f_st_spi_status)(mflash* mfl, u_int8_t op_type, u_int8_t* status);
-
-// This is an interface function when running in IRISC
-int mf_open_fw(mflash* mfl);
-
-//
-// mflash struct
-//
-#ifndef IRISC
-#define MFLASH_ERR_STR_SIZE 1024
-#else
-#define MFLASH_ERR_STR_SIZE    4
-#endif
-
-struct mflash {
-#ifndef IRISC
-    mfile*      mf;
-#endif
-
-    // Functions:
-    f_mf_lock       f_lock;
-    f_mf_unlock     f_unlock;
-    f_mf_set_bank   f_set_bank;
-
-    f_mf_read       f_read;
-    f_mf_write      f_write;
-    f_mf_write      f_write_blk;   // write and write_block have the same signateure, but theyr'e not the same func !
-    f_mf_read       f_read_blk;    // read  and read_block have the same signateure, but theyr'e not the same func !
-    f_mf_erase_sect f_erase_sect;
-    f_mf_reset      f_reset;
-
-    // Relevant for SPI flash (InfiniHostIIILx, ConnectX) only.
-    f_st_spi_status f_spi_status;
-
-    int             curr_bank;
-    int             is_locked;
-
-    flash_attr      attr;
-
-    int             opts[MFO_LAST];
-    char            last_err_str[MFLASH_ERR_STR_SIZE];
-};
-
-
-// NOTE: This macro returns ... not nice.
-#define CHECK_RC(rc) do {if (rc) return rc;} while(0)
-
-#define ARRSIZE(arr) (sizeof(arr)/sizeof(arr[0]))
-
-#ifdef ESS
-#define MREAD4(offs, val)  do {*val=READ_WORD(offs);} while (0)
-#define MWRITE4(offs, val) do {WRITE_WORD(offs, val);} while (0)
-#else
-#define MREAD4(offs, val)  do { if (mread4 (mfl->mf, offs, val) != 4) { \
-                                  fprintf(stderr, "-E- Cr read (0x%08x) failed: %s(%d)\n", (u_int32_t)(offs), strerror(errno), (u_int32_t)errno); \
-                                 exit(2); } \
-                                  } while (0)
-                                  
-#define MWRITE4(offs, val) do { if (mwrite4(mfl->mf, offs, val) != 4) { \
-                                  fprintf(stderr, "-E- Cr write (0x%08x, 0x%08x) failed: %s(%d)\n", (u_int32_t)(offs), (u_int32_t)(val), strerror(errno), (u_int32_t)errno); \
-                                 mclose(mfl->mf); exit(2); } \
-                                  } while (0)
-#endif
-
-// Constants:
-
-// General:
-#define GPIO_DIR_L       0xf008c
-#define GPIO_POL_L       0xf0094
-#define GPIO_MOD_L       0xf009c
-#define GPIO_DAT_L       0xf0084
-#define GPIO_DATACLEAR_L 0xf00d4
-#define GPIO_DATASET_L   0xf00dc
-
-#define SEMAP63          0xf03fc
-
-// InfiniHost specific
-#define IDLE           0
-#define READ4          (1<<29)
-#define WRITE1         (2<<29)
-
-#define CR_FLASH       0xf01a4
-#define ADDR_MSK       0x7ffffUL
-#define CMD_MASK       0xe0000000UL
-
-#define CPUMODE_MSK    0xc0000000UL
-#define CPUMODE_SHIFT  30
-#define CPUMODE        0xf0150
-
-enum FlashConstant {
-    FLASH_CMD_CNT  = 5000,    // Number of reads till flash cmd is zeroed
-    ERASE_DELAY    = 200000,  // Delay between reads when wating for sector erase
-    ERASE_CNT      = 1000000,      // Maximal number of reads when wating for sector erase
-    READ_CNT_FAST  = 50000,        // Number of fast reads after write byte
-    READ_CNT_SLOW  = 50,      // Number of slow reads after write byte
-    READ_DELAY     = 100000,  // Delay between slow reads after write byte
-    WR_REPORT_FAST = 256,     // Report frequency when write (fast interfaces)
-    WR_REPORT_SLOW = 4,       // Report frequency when write (slow interfaces)
-    RD_REPORT_FAST = 4096,    // Report frequency when read (fast interfaces)
-    RD_REPORT_SLOW = 64,      // Report frequency when read (slow interfaces)
-    GPIO_SEM_TRIES = 1024 ,   // Number of tries to obtain a GPIO sem.
-    MAX_WRITE_BUFFER_SIZE = 32// Max buffer size for buffer write devices
-};
-
-
-enum IntelFlashCommand {
-    FC_ReadID      = 0x90,
-    FC_Read        = 0xFF,
-    FC_Erase       = 0x20,
-    FC_Confirm     = 0xD0,
-    FC_Clear       = 0x50,
-    FC_Write       = 0x40,
-    FC_LoadPB      = 0xE0,
-    FC_PBWrite     = 0x0C,
-    FC_Status      = 0x70,
-    FC_Suspend     = 0xB0,
-    FC_Resume      = 0xD0,
-    FC_ReadESR     = 0x71,
-    FC_QueryCFI    = 0x98,
-    FC_SCSErase    = 0x28,
-    FC_SCSWrite    = 0xE8
-};
-
-enum IntelFlashStatus {
-    FS_Ready       = 0x80,
-    FS_Suspended   = 0x40,
-    FS_Error       = 0x3E,
-    FS_BlockError  = 0x3F
-};
-
-// InfiniHost funcs:
-int ihst_flash_init      (mflash* mfl);
-
-int fill_attr_cfi         (mflash* mfl);
-
-int ihst_write_internal  (mflash* mfl, u_int32_t addr, u_int8_t data);
-int ihst_fill_attr       (mflash* mfl);
-
-int ihst_flash_read      (mflash* mfl, u_int32_t addr, u_int32_t len, u_int8_t* data);
-int ihst_flash_lock      (mflash* mfl);
-
-//static inline
-//int ihst_set_bank        (mflash* mfl, u_int32_t addr);
-static u_int32_t log2up (u_int32_t in) {
-    u_int32_t i;
-    for (i = 0; i < 32; i++) {
-        if (in <= (u_int32_t)(1 << i))
-            break;
-    }
-
-    return i;
-}
-
-static inline
-int set_bank(mflash* mfl, u_int32_t addr) {
-    int bank = addr >> mfl->attr.log2_bank_size;
-
-    if (mfl->curr_bank != bank) {
-        mfl->curr_bank = bank;
-        return mfl->f_set_bank(mfl, bank);
-    }
-
-    return MFE_OK;
-}
-
-// amd parallel flash funcs:
-int amd_flash_reset       (mflash* mfl);
-int amd_flash_write       (mflash* mfl, u_int32_t addr, u_int32_t len, u_int8_t* data);
-int amd_flash_erase_sect  (mflash* mfl, u_int32_t addr);
-
-// intel parallel flash funcs:
-int intel_flash_reset      (mflash* mfl);
-//int intel_flash_byte_write (mflash* mfl, u_int32_t addr, u_int32_t len, u_int8_t* data);
-int intel_flash_block_write(mflash* mfl, u_int32_t addr, u_int32_t len, u_int8_t* data);
-int intel_flash_erase_sect (mflash* mfl, u_int32_t addr);
-
-
-// InfiniHostIIILx SPI interface:
-int ih3lx_flash_init      (mflash* mfl);
-
-int ih3lx_fill_attr       (mflash* mfl);
-
-int ih3lx_flash_read      (mflash* mfl, u_int32_t addr, u_int32_t len, u_int8_t* data);
-
-int ih3lx_st_spi_reset          (mflash* mfl);
-int ih3lx_st_spi_erase_sect     (mflash* mfl, u_int32_t addr);
-
-
-// ConnectX SPI interface:
-int cntx_flash_init      (mflash* mfl);
-
-int cntx_fill_attr       (mflash* mfl);
-
-int cntx_flash_read      (mflash* mfl, u_int32_t addr, u_int32_t len, u_int8_t* data);
-int cntx_flash_lock      (mflash* mfl);
-
-int cntx_st_spi_reset          (mflash* mfl);
-int cntx_st_spi_erase_sect     (mflash* mfl, u_int32_t addr);
-
-int cntx_st_spi_block_write_ex (mflash*   mfl, 
-                                u_int32_t blk_addr, 
-                                u_int32_t blk_size, 
-                                u_int8_t* data, 
-                                u_int8_t  is_first, 
-                                u_int8_t  is_last);
-
-int cntx_st_spi_block_read_ex  (mflash*   mfl, 
-                                u_int32_t blk_addr, 
-                                u_int32_t blk_size, 
-                                u_int8_t* data, 
-                                u_int8_t  is_first, 
-                                u_int8_t  is_last);
-
-int my_memset(void* dst, u_int8_t data, u_int32_t len) {
-    u_int32_t i;
-    u_int8_t* bytes = (u_int8_t*)dst;
-
-    for (i = 0; i < len;  i++) {
-        bytes[i] = data;
-    }
-
-    return 0;
-}
-
-int my_memcpy(void* dst, void* src, u_int32_t len) {
-    u_int32_t i;
-    u_int8_t* dbytes = (u_int8_t*)dst;
-    u_int8_t* sbytes = (u_int8_t*)src;
-
-    for (i = 0; i < len;  i++) {
-        dbytes[i] = sbytes[i];
-    }
-
-    return 0;
-}
-
-#if 0 // TODO: Currently the polling is in max throttle - no sleep is done
-int usleep(u_int32_t usecs) {
-    u_int32_t i;
-    u_int32_t stub = 0;
-    // TODO: Some more intelegent /accurate way to do it, or remove T.Os completely.
-    u_int32_t loops = (usecs << 9);
-    for (i = 0; i < loops; i++) {
-        stub++;
-    }
-
-    return stub;
-}
-#endif
-
-int write_chunks   (mflash* mfl, u_int32_t addr, u_int32_t len, u_int8_t* data) {
-    int       rc;
-    u_int8_t  *p         = (u_int8_t *)data;
-
-    int       all_ffs;
-
-    // TODO - Check MAX_WRITE_BUFFER_SIZE against block_size in open (or here)
-    u_int8_t  tmp_buff[MAX_WRITE_BUFFER_SIZE];
-
-    if (!mfl) {
-        return MFE_BAD_PARAMS;
-    }
-
-    //printf("-D- write_chunks(addr=%x, size=%x)\n", addr, len); 
-
-    while (len) {
-        u_int32_t i;
-        u_int32_t prefix_pad_size = 0;
-        u_int32_t suffix_pad_size = 0;
-
-        u_int32_t block_size = mfl->attr.block_write;
-        u_int32_t block_mask = ~(block_size - 1 );
-
-        u_int32_t block_addr = addr & block_mask;
-        u_int32_t data_size  = block_size;
-
-        u_int8_t* block_data = p;
-
-        //
-        // To keep things simple, we always write full blocks.
-        // (there's an option to write partial buffer, but Intel reference code always
-        // writes full buffer, with pads if needed. I do the same ...)
-        //
-        // The First and last cycles (can be the same one) may not be block aligned.
-        // If this is the case, copy the block data to a 0xFF padded temp buffer (writing 0xFF 
-        // does not effect the flash)
-        //
-
-        prefix_pad_size = addr - block_addr;
-
-        if ((addr & block_mask) == ((addr + len) & block_mask)) {
-            suffix_pad_size = block_size - ((addr + len) % block_size);
-        }
-
-        if (suffix_pad_size || prefix_pad_size) {
-            my_memset(tmp_buff, 0xff, block_size);
-
-            data_size -= prefix_pad_size;
-            data_size -= suffix_pad_size;
-
-            my_memcpy(tmp_buff + prefix_pad_size, p , data_size);
-
-            block_data = tmp_buff;
-        } else if (mfl->attr.page_write) {
-            // current write is aligned to block size, 
-            // write data to next page, or to last full block (if we're in the last block in a page)
-            u_int32_t page_mask             = ~(mfl->attr.page_write - 1);
-            u_int32_t next_page_addr        = (addr + mfl->attr.page_write + 1) & page_mask;
-            u_int32_t size_to_page_boundary = next_page_addr - addr;
-            if (len > size_to_page_boundary) {
-                block_size = size_to_page_boundary;
-            } else {
-                block_size = len & block_mask;
-            }
-            data_size = block_size;
-        }
-
-        //
-        // Check to see if there's something to do
-        //
-        all_ffs = 1;
-        for (i = 0; i < block_size ; i++) {
-            if (block_data[i] != 0xff) {
-                all_ffs = 0;
-                break;
-            }
-        }
-
-        if (!all_ffs) {
-            rc = mfl->f_write_blk(mfl, block_addr, block_size, block_data); CHECK_RC(rc);
-
-            if (mfl->opts[MFO_NO_VERIFY]) {
-                u_int8_t verify_buffer[MAX_WRITE_BUFFER_SIZE];
-                rc = mfl->f_reset(mfl);                                CHECK_RC(rc);
-                rc = mfl->f_read(mfl, addr, data_size, verify_buffer); CHECK_RC(rc);
-
-                // Verify data
-                for (i = 0 ; i < data_size ; i++) {
-                    if (verify_buffer[i] != block_data[i + prefix_pad_size]) {
-                        //return _f.errmsg("Write verification failed. Addr %08x - exp:%02x act:%02x\n",
-                        //       addr + i,
-                        //       block_data[i + prefix_pad_size] ,
-                        //       verify_buffer[i]);
-                        return MFE_VERIFY_ERROR;
-                    }
-                }
-            }
-        }
-
-        //
-        // loop advance
-        //
-
-        addr += data_size;
-        p    += data_size;
-        len  -= data_size;
-    }
-
-    rc = mfl->f_reset(mfl); CHECK_RC(rc);
-
-    return MFE_OK;
-}
-
-static int apply_mx_flash_workaround(flash_attr* attr) {
-    if (attr->num_erase_blocks == 1) {
-        attr->sector_size = attr->erase_block[0].sector_size;
-    } else if (attr->num_erase_blocks == 2 &&
-               attr->erase_block[0].sector_size == 0x2000 &&
-               attr->erase_block[0].sector_mask == 0xffffe000 &&
-               attr->erase_block[0].num_sectors == 8 &&
-               attr->erase_block[1].sector_size == 0x10000 &&
-               attr->erase_block[1].sector_mask == 0xffff0000 &&
-               attr->erase_block[1].num_sectors == 63) {
-
-        attr->sector_size = attr->erase_block[1].sector_size;
-    } else {
-        return MFE_UNSUPPORTED_FLASH_TOPOLOGY;
-    }
-
-    return MFE_OK;
-}
-
-
-int ihst_init_gpios(mflash* mfl) {
-    u_int32_t dir;
-    u_int32_t pol;
-    u_int32_t mod;
-    u_int32_t word;
-    u_int32_t data;
-
-    // Save old values
-    MREAD4(GPIO_DIR_L, &dir);
-    MREAD4(GPIO_POL_L, &pol);
-    MREAD4(GPIO_MOD_L, &mod);
-    MREAD4(GPIO_DAT_L, &data);
-
-    // Set Direction=1, Polarity=0, Mode=0 for 3 GPIO lower bits
-    dir = dir | 0x70;
-    pol = pol & ~0x70;
-    mod = mod & ~0x70;
-
-    MWRITE4(GPIO_DIR_L, dir);
-    MWRITE4(GPIO_POL_L, pol);
-    MWRITE4(GPIO_MOD_L, mod);
-
-    // Set CPUMODE
-    MREAD4(CPUMODE, &word);
-    word &= ~CPUMODE_MSK;
-    word |= 1 << CPUMODE_SHIFT;
-    MWRITE4(CPUMODE, word);
-
-    return MFE_OK;
-}
-
-int ihst_set_bank(mflash* mfl, u_int32_t bank) {
-    MWRITE4(GPIO_DATACLEAR_L, 0x70);
-    MWRITE4(GPIO_DATASET_L, (bank << 4) & 0x70);
-    return MFE_OK;
-}
-
-int ihst_flash_init(mflash* mfl) {
-    int rc;
-
-    mfl->f_read           = ihst_flash_read;
-    mfl->f_lock           = ihst_flash_lock;
-    mfl->f_set_bank       = ihst_set_bank;
-
-    rc = mfl->f_lock(mfl);
-    if (!mfl->opts[MFO_IGNORE_SEM_LOCK]) {
-        CHECK_RC(rc);
-    } else {
-        mfl->is_locked = 1;
-    }
-
-    rc = ihst_init_gpios(mfl);  CHECK_RC(rc);
-
-    mfl->attr.log2_bank_size = 19;
-    mfl->attr.bank_size = (1 << mfl->attr.log2_bank_size);
-
-    rc = fill_attr_cfi(mfl); CHECK_RC(rc);
-    rc = apply_mx_flash_workaround(&mfl->attr);  CHECK_RC(rc);
-
-    if        (mfl->attr.command_set == CS_AMD) {
-        mfl->f_reset      = amd_flash_reset;
-        mfl->f_write      = amd_flash_write;
-        mfl->f_erase_sect = amd_flash_erase_sect;
-    } else if (mfl->attr.command_set == CS_INTEL) {
-        mfl->f_reset      = intel_flash_reset;
-        //mfl->f_write      = intel_flash_blk_write;
-        mfl->f_write_blk  = intel_flash_block_write;
-        mfl->f_write      = write_chunks;
-        mfl->f_erase_sect = intel_flash_erase_sect;
-    } else {
-        return MFE_UNSUPPORTED_FLASH_TYPE;
-    }
-
-    rc = mfl->f_reset(mfl); CHECK_RC(rc);
-
-    return MFE_OK;
-}
-
-
-static u_int16_t extract_word   ( const u_int8_t* pb)  {
-    u_int16_t ret = *pb | ((*(pb + 1)) << 8);
-    return ret;
-}
-
-int fill_attr_cfi(mflash* mfl) {
-    int rc;
-
-    #define TOTAL_QUERY_SIZE 0x100
-
-    u_int8_t fwp[TOTAL_QUERY_SIZE]; // flash window
-
-    int temp=0, i=0;
-
-    // Initial house-cleaning
-    my_memset(fwp, 0xff, TOTAL_QUERY_SIZE);
-
-    for (i=0; i < (int)ARRSIZE(mfl->attr.erase_block); i++) {
-        mfl->attr.erase_block[i].sector_size = 0;
-        mfl->attr.erase_block[i].num_sectors = 0;
-        mfl->attr.erase_block[i].sector_mask = 0;
-    }
-
-    // reset
-    rc = ihst_write_internal(mfl, 0x55, 0xff);          CHECK_RC(rc);
-
-    // CFI QUERY
-    rc = ihst_write_internal(mfl, 0x55, 0x98);          CHECK_RC(rc);
-
-    
-    rc = mfl->f_read(mfl, 0, TOTAL_QUERY_SIZE, fwp);     CHECK_RC(rc);
-
-    if (        fwp[0x10]      == 'Q' &&
-                fwp[0x11]      == 'R' &&
-                fwp[0x12]      == 'Y') {
-
-        // x8 CFI flash (AMD)
-    } else if ( fwp[0x20] == 'Q' &&
-                fwp[0x22] == 'R' &&
-                fwp[0x24] == 'Y') {
-        // x16 CFI flash worqing in x8 mode
-        
-        for (i = 0; i < TOTAL_QUERY_SIZE ; i+=2) {
-            fwp[i/2] = fwp[i];
-        }
-
-    } else {
-
-        printf(" Received CFI query from addr 0x10: [%c%c%c]\n", fwp[0x10], fwp[0x11], fwp[0x12] );
-        printf(" Received CFI query from addr 0x20: [%c%c%c]\n", fwp[0x20], fwp[0x22], fwp[0x24]);
-
-        return MFE_CFI_FAILED;
-    }
-
-    // mfl->attr.manuf_id              = fwp[query_base * 0];
-    // mfl->attr.device_id             = fwp[query_base * 1];
-
-
-    mfl->attr.command_set =          extract_word(fwp + 0x13);
-
-    temp = fwp[0x27];
-
-    mfl->attr.size = (1 << temp);
-
-    temp = fwp[0x2A];
-    if (temp != 0x00)
-        mfl->attr.block_write = (1 << temp);
-    else
-        mfl->attr.block_write = 0;
-
-    mfl->attr.num_erase_blocks = fwp[0x2C];
-
-    if (mfl->attr.num_erase_blocks > 8) {
-        printf("-E- More than 8 erase blocks (%d found)- not supported\n",
-               mfl->attr.num_erase_blocks);
-        return MFE_CFI_FAILED;
-    }
-
-//    rc = mfl->f_read(mfl,
-//                     0x2C,
-//                     4 * (mfl->attr.num_erase_blocks + 1),
-//                     fwp + 0x2C );
-//    CHECK_RC(rc);
-
-    for (i=0; i < mfl->attr.num_erase_blocks; i++) {
-        mfl->attr.erase_block[i].num_sectors = extract_word(fwp + 0x2D+(4*i)) + 1;
-
-        mfl->attr.erase_block[i].sector_size = extract_word(fwp + 0x2F+(4*i)) * 256;
-
-        mfl->attr.erase_block[i].sector_mask =
-            ~( mfl->attr.erase_block[i].sector_size - 1);
-    }
-
-    return MFE_OK;
-}
-
-
-int ihst_wait_ready(mflash* mfl, char* msg) {
-    //int rc;
-    u_int32_t cnt = 0;
-    u_int32_t cmd;
-    do {
-        // Timeout checks
-        if (++cnt > FLASH_CMD_CNT) {
-            printf("-E- Flash gateway timeout: %s", msg);
-            return MFE_TIMEOUT;
-        }
-
-        MREAD4(CR_FLASH, &cmd);
-    } while (cmd & CMD_MASK);
-
-    return MFE_OK;
-}
-
-int ihst_write_internal  (mflash* mfl, u_int32_t addr, u_int8_t data) {
-    int rc;
-
-    MWRITE4(CR_FLASH+4, data << 24);
-    MWRITE4(CR_FLASH, WRITE1 | (addr & ADDR_MSK));
-
-    rc = ihst_wait_ready(mfl, "Write"); CHECK_RC(rc);
-
-    return MFE_OK;
-}
-
-
-int ihst_flash_read4(mflash* mfl, u_int32_t addr, u_int32_t* data) {
-
-    int rc;
-    u_int32_t cmd;
-    if (addr & 0x3) {
-        return MFE_BAD_ALIGN;
-    }
-
-    rc = set_bank(mfl, addr); CHECK_RC(rc);
-
-    MWRITE4(CR_FLASH, READ4 | (addr & ADDR_MSK));
-
-    rc = ihst_wait_ready(mfl, "Read"); CHECK_RC(rc);
-
-    MREAD4(CR_FLASH+4, &cmd);
-
-    *data =  __cpu_to_be32(cmd);
-
-    return MFE_OK;
-
-}
-
-int ihst_flash_read(mflash* mfl, u_int32_t addr, u_int32_t len, u_int8_t* data) {
-    u_int32_t i;
-    int rc;
-
-    if ((len & 3) || (addr & 3)) {
-        return MFE_BAD_ALIGN;
-    }
-
-    for (i = 0; i < len; i += 4) {
-        rc = ihst_flash_read4(mfl, addr + i, (u_int32_t*) (data + i)); CHECK_RC(rc);
-    }
-
-    return MFE_OK;
-}
-
-int ihst_flash_lock(mflash* mfl) {
-
-    // Obtain GPIO Semaphore
-    u_int32_t cnt=0;
-    u_int32_t word;
-    do {
-        if (++cnt > GPIO_SEM_TRIES) {
-            //printf("-E- Can not obtain Flash semaphore");
-            return MFE_SEM_LOCKED;
-        }
-        MREAD4(SEMAP63, &word);
-    } while (word);
-
-    mfl->is_locked = 1;
-    return MFE_OK;
-}
-
-
-int ihst_flash_unlock(mflash* mfl) {
-    if (mfl->is_locked) {
-        MWRITE4(SEMAP63, 0);
-        mfl->is_locked = 0;
-    }
-
-    return MFE_OK;
-}
-
-
-
-// amd parallel flash funcs:
-int amd_flash_reset       (mflash* mfl) {
-    int rc;
-    rc = ihst_write_internal(mfl, 0x555, 0xf0); CHECK_RC(rc);
-    return MFE_OK;
-}
-
-int amd_flash_write       (mflash* mfl, u_int32_t addr, u_int32_t len, u_int8_t* data) {
-    int rc;
-    u_int32_t i;
-
-    char         *p = (char *)data;
-
-    for (i = 0; i < len; i++ , addr++) {
-        u_int32_t  word;
-        u_int8_t   act, exp;
-        int        cnt1 = 0;
-
-        rc = set_bank(mfl, addr); CHECK_RC(rc);
-
-        if ((u_int8_t)(*p) != 0xff) {
-
-            if (mfl->opts[MFO_AMD_BYTE_MODE]) {
-
-                rc = ihst_write_internal(mfl, 0xaaa, 0xaa); CHECK_RC(rc);
-                rc = ihst_write_internal(mfl, 0x555, 0x55); CHECK_RC(rc);
-                rc = ihst_write_internal(mfl, 0xaaa, 0xa0); CHECK_RC(rc);
-            } else {
-                if (!mfl->opts[MFO_AMD_UNLOCK_BYPASS]) {
-                    rc = ihst_write_internal(mfl, 0x555, 0xaa); CHECK_RC(rc);
-                    rc = ihst_write_internal(mfl, 0x2aa, 0x55); CHECK_RC(rc);
-                }
-
-                rc = ihst_write_internal(mfl, 0x555, 0xa0); CHECK_RC(rc);
-            }
-
-            rc = ihst_write_internal(mfl, addr, *p++); CHECK_RC(rc);
-
-            do {
-                // Timeout checks
-                //if (++cnt1 > READ_CNT_FAST)
-                //    usleep(READ_DELAY);
-                if (cnt1 > READ_CNT_FAST + READ_CNT_SLOW) {
-                    return MFE_WRITE_TIMEOUT;
-                }
-
-                rc = ihst_flash_read4(mfl, addr & ~3, &word); CHECK_RC(rc);
-
-                word = __be32_to_cpu(word);
-                act = (u_int8_t) ((word >> ((3 - (addr & 3)) * 8)) & 0xff);
-                exp = *(p-1) & 0xff;
-                //if (act != exp)
-                //    printf("write: %08x - exp:%02x act:%02x /%08x/\n",
-                //           addr, exp & 0xff, act & 0xff, word);
-            } while (act != exp);
-
-        } else {
-            p++;
-        }
-    }
-
-    return MFE_OK;
-}
-
-int amd_flash_erase_sect  (mflash* mfl, u_int32_t addr) {
-    u_int32_t word = 0;
-    int       cnt  = 0;
-    int       rc;
-
-    rc = set_bank(mfl, addr); CHECK_RC(rc);
-
-    // Just to insure zeroes because erase completion waits for ones
-    rc = amd_flash_write(mfl, addr,  sizeof(word), (u_int8_t*) &word); CHECK_RC(rc);
-
-    // erase sector sequence
-    if (mfl->opts[MFO_AMD_BYTE_MODE]) {
-        rc = ihst_write_internal(mfl, 0xaaa, 0xaa); CHECK_RC(rc);
-        rc = ihst_write_internal(mfl, 0x555, 0x55); CHECK_RC(rc);
-        rc = ihst_write_internal(mfl, 0xaaa, 0x80); CHECK_RC(rc);
-        rc = ihst_write_internal(mfl, 0xaaa, 0xaa); CHECK_RC(rc);
-        rc = ihst_write_internal(mfl, 0x555, 0x55); CHECK_RC(rc);
-        rc = ihst_write_internal(mfl, addr , 0x30); CHECK_RC(rc);
-    } else {
-        rc = ihst_write_internal(mfl, 0x555, 0xaa); CHECK_RC(rc);
-        rc = ihst_write_internal(mfl, 0x2aa, 0x55); CHECK_RC(rc);
-        rc = ihst_write_internal(mfl, 0x555, 0x80); CHECK_RC(rc);
-        rc = ihst_write_internal(mfl, 0x555, 0xaa); CHECK_RC(rc);
-        rc = ihst_write_internal(mfl, 0x2aa, 0x55); CHECK_RC(rc);
-        rc = ihst_write_internal(mfl, addr , 0x30); CHECK_RC(rc);
-    }
-
-    // Wait while erase completes
-    do {
-        // Timeout checks
-        if (++cnt > ERASE_CNT) {
-            return MFE_ERASE_TIMEOUT;
-        }
-        rc = ihst_flash_read4(mfl, addr, &word); CHECK_RC(rc);
-
-        //printf("erase_sector: addr:%08lx, %08x\n", addr, word);
-        //usleep(ERASE_DELAY);
-    } while (word != 0xffffffff);
-
-    return MFE_OK;
-}
-
-// intel parallel flash funcs:
-int intel_flash_reset     (mflash* mfl) {
-    int rc;
-    rc = ihst_write_internal(mfl, 0x555, FC_Read); CHECK_RC(rc);
-    return MFE_OK;
-}
-
-
-int intel_flash_byte_write  (mflash* mfl, u_int32_t addr, u_int32_t len, u_int8_t* data) {
-    int rc;
-    u_int32_t i;
-    char         *p = (char *)data;
-
-    for (i=0; i<len; i++,addr++) {
-        u_int32_t  status;
-        int        cnt1 = 0;
-
-        rc = set_bank(mfl, addr); CHECK_RC(rc);
-
-        if ((u_int8_t)(*p) != 0xff) {
-            // Write byte
-            rc = ihst_write_internal(mfl, addr, FC_Write); CHECK_RC(rc);
-            rc = ihst_write_internal(mfl, addr, *p++);     CHECK_RC(rc);
-
-            do {
-                // Timeout checks
-                //if (++cnt1 > READ_CNT_FAST)
-                //    usleep(READ_DELAY);
-                if (cnt1 > READ_CNT_FAST + READ_CNT_SLOW) {
-                    return MFE_WRITE_TIMEOUT;
-                }
-
-                rc = ihst_flash_read(mfl, addr & ~3, 4, (u_int8_t*)&status); CHECK_RC(rc);
-
-            } while ((status & FS_Ready) == 0);
-
-            if (status & FS_Error) {
-                return MFE_WRITE_ERROR;
-            }
-
-            // TODO: Check verify
-
-            /* For ESS: verify is done by the test.
-            if (!noverify) {
-                u_int32_t word;
-                if (!reset())
-                    return false;
-                if (!_f.read(addr & ~3, &word))
-                    return false;
-
-                word = __be32_to_cpu(word);
-                act = (u_int8_t) ((word >> ((3 - (addr & 3)) * 8)) & 0xff);
-                exp = *(p-1) & 0xff;
-
-                if (act != exp) {
-                    printf("write: %08x - exp:%02x act:%02x /%08x/\n",
-                           addr, exp & 0xff, act & 0xff, word);
-
-                    return _f.errmsg("Write verification failed");
-                }
-            }
-            */
-        } else {
-            p++;
-        }
-    }
-
-    rc = intel_flash_reset(mfl); CHECK_RC(rc);
-
-    return MFE_OK;
-}
-
-
-int intel_flash_block_write(mflash* mfl, u_int32_t blk_addr, u_int32_t blk_size, u_int8_t* data) {
-    int rc;
-    u_int32_t status;
-    int cnt1 = 0;
-    u_int32_t i;
-
-    rc = set_bank(mfl, blk_addr); CHECK_RC(rc);
-
-    do {
-        // Get Write buffer
-        rc = ihst_write_internal(mfl, blk_addr, FC_SCSWrite); CHECK_RC(rc);
-
-        if (cnt1 > ((READ_CNT_FAST + READ_CNT_SLOW) * 4)) {
-            //printf("-D- status = %08x\n", status);
-            intel_flash_reset(mfl);
-            // TODO: specific err code.
-            return MFE_WRITE_ERROR;
-        }
-
-        cnt1++;
-
-        rc = mfl->f_read(mfl, blk_addr, 4, (u_int8_t*) &status); CHECK_RC(rc);
-
-    } while (!(status & FS_Ready));
-
-    if (status & FS_Error) {
-        return MFE_WRITE_ERROR;
-    }
-
-    // word count (allways full buffer, coded as cull buffer size -1)
-    rc = ihst_write_internal(mfl, blk_addr, blk_size - 1); CHECK_RC(rc);
-
-    // Write data to buffer
-    for (i = 0; i < blk_size ; i++ ) {
-        rc = ihst_write_internal(mfl, blk_addr + i, data[i]); CHECK_RC(rc);
-    }
-
-    // write confirm
-    rc = ihst_write_internal(mfl, blk_addr, FC_Confirm); CHECK_RC(rc);
-    cnt1 = 0;
-    do {
-        // Timeout checks
-        //if (++cnt1 > READ_CNT_FAST)
-        //    usleep(READ_DELAY);
-        if (cnt1 > READ_CNT_FAST + READ_CNT_SLOW) {
-            intel_flash_reset(mfl);
-            // TODO: specific err code.
-            return MFE_WRITE_TIMEOUT;
-        }
-
-        rc = mfl->f_read(mfl, blk_addr, 4, (u_int8_t*) &status); CHECK_RC(rc);
-    } while ((status & 0x80) == 0);
-
-    return MFE_OK;
-}
-
-int intel_flash_erase_sect(mflash* mfl, u_int32_t addr) {
-    int rc;
-
-    u_int32_t    status = 0;
-    int          cnt    = 0;
-
-    rc = set_bank(mfl, addr); CHECK_RC(rc);
-
-    // Just to insure zeroes because erase completion waits for ones
-    //if (!write(addr, &word, sizeof(word), true))
-    //    return false;
-
-    // Erase command
-    rc = ihst_write_internal(mfl, addr, FC_Erase);   CHECK_RC(rc);
-
-    // Erase confirm
-    rc = ihst_write_internal(mfl, addr, FC_Confirm); CHECK_RC(rc);
-
-    //usleep(ERASE_DELAY);
-
-    // Wait while erase completes
-    do {
-        // Timeout checks
-        if (++cnt > ERASE_CNT) {
-            return MFE_ERASE_TIMEOUT;
-        }
-        rc = ihst_flash_read(mfl, addr, 4, (u_int8_t*) &status); CHECK_RC(rc);
-
-        //printf("CmdSetIntel::erase_sector: addr:%08lx, %08x\n", addr, word);
-        //usleep(ERASE_DELAY);
-    } while ((status & FS_Ready) == 0);
-
-    if (status & FS_Error) {
-        // printf("-D- read %d times. status=%x\n",cnt,  status);
-        return MFE_ERASE_ERROR;
-    }
-
-    rc = intel_flash_reset(mfl); CHECK_RC(rc);
-
-    return MFE_OK;
-}
-
-
-////////////////////////////////////////
-//
-// ST SPI functions - common for InfiniHostIIILx and ConnectX
-//
-////////////////////////////////////////
-
-enum StFlashCommand {
-    SFC_SE    = 0xD8,
-    SFC_PP    = 0x02,
-    SFC_RDSR  = 0x05,
-    SFC_WREN  = 0x06,
-    SFC_READ  = 0x03,
-    SFC_RDID  = 0xF9,
-    SFC_RES   = 0xAB
-};
-
-int st_spi_fill_attr(mflash* mfl) {
-    int rc;
-
-    u_int32_t spi_size = 0;
-    u_int32_t log2spi_size = 0;
-    u_int32_t num_spis = 0;
-    u_int32_t spi_sel;
-
-    mfl->attr.block_write                = 16; // In SPI context, this is the transaction size. Max is 16.
-
-    mfl->attr.num_erase_blocks           = 1;
-
-    mfl->attr.erase_block[0].sector_size = 64 * 1024;
-    mfl->attr.erase_block[0].sector_mask = ~(mfl->attr.erase_block[0].sector_size - 1);
-
-    mfl->attr.sector_size = mfl->attr.erase_block[0].sector_size;
-
-    for (spi_sel = 0 ; spi_sel < 4 ; spi_sel++) {
-        unsigned char es; // electronic signature
-        u_int32_t cur_spi_size = 0;
-
-        rc = set_bank(mfl, spi_sel);                    CHECK_RC(rc);
-
-        rc = mfl->f_spi_status(mfl, SFC_RES, &es);      CHECK_RC(rc);
-
-        if (es >= 0x10 && es < 0x17) {
-            // Range OK:
-
-            // NOTE: This mapping between electronic signature and device size is device specific!
-            //       This mapping works for ST M25Pxx and Saifun SA25Fxxx families.
-            log2spi_size = (es + 1);
-            cur_spi_size = 1 << log2spi_size;
-
-            num_spis++;
-
-            if (spi_sel == 0) {
-                spi_size = cur_spi_size;
-            } else if (cur_spi_size != spi_size){
-                printf ("-E- SPI flash #%d of size 0x%x bytes differs in size from SPI flash #%d of size 0x%x bytes. "
-                              "All flash devices must be of the same size.",
-                              spi_sel,
-                              cur_spi_size,
-                              spi_sel - 1,
-                              spi_size);
-                return MFE_UNSUPPORTED_FLASH_TOPOLOGY;
-            }
-        } else if (es == 0xff 
-                   || es == 0
-                   ) {
-            // No spi device on this chip_select
-            break;
-        } else {
-            printf("-E- Unexpected SPI electronic signature value (0x%2x) when detecting flash size. "
-                          "Flash #%d my be defected.",
-                          es,
-                          spi_sel);
-            return MFE_UNSUPPORTED_FLASH_TOPOLOGY;
-        }
-
-        // printf("-D- %3d %08x\n", spi_sel, cur_spi_size);
-    }
-
-    if (num_spis == 0) {
-        return MFE_UNSUPPORTED_FLASH_TYPE;
-    }
-
-    mfl->attr.bank_size      = spi_size;
-    mfl->attr.size           = spi_size * num_spis;
-    mfl->attr.log2_bank_size = log2spi_size;
-
-    mfl->attr.command_set    = MCS_STSPI;
-
-    return MFE_OK;
-}
-
-int st_spi_wait_wip(mflash* mfl, u_int32_t delay, u_int32_t retrys, u_int32_t fast_retrys) {
-
-    int       rc;
-    u_int8_t  status;
-    u_int32_t cnt = 0;
-
-    delay = 0; // UNUSED FOR NOW
-
-    do {
-        if (++cnt > fast_retrys) {
-            //usleep(delay);
-        }
-        if (cnt > retrys) {
-            return MFE_WRITE_TIMEOUT;
-        }
-
-        rc = mfl->f_spi_status(mfl, SFC_RDSR, &status);
-    } while (status & 0x01);
-
-    return MFE_OK;
-}
-
-int read_chunks   (mflash* mfl, u_int32_t addr, u_int32_t len, u_int8_t* data) {
-
-    int       rc;
-    u_int8_t  *p         = (u_int8_t *)data;
-
-    // Note:
-    // Assuming read block is the same as write block size.
-    // This is true for current Mellanox devices SPI flash access implementation.
-    // Check for future devices.
-    u_int32_t block_size = mfl->attr.block_write;
-    u_int32_t block_mask;
-
-
-    // TODO - Check MAX_WRITE_BUFFER_SIZE against block_size in open (or here)
-    u_int8_t  tmp_buff[MAX_WRITE_BUFFER_SIZE];
-
-    if (!mfl) {
-        return MFE_BAD_PARAMS;
-    }
-
-    if (len < block_size) {
-        // If we're reading a small chunk, use the smallest block_size to avoid the extra reads and padding overhead
-        block_size = 4;
-    }
-
-    block_mask = ~(block_size - 1);
-
-    while (len) {
-
-        u_int32_t i;
-        u_int32_t prefix_pad_size = 0;
-        u_int32_t suffix_pad_size = 0;
-
-        u_int32_t block_addr = addr & block_mask;
-        u_int32_t data_size  = block_size;
-
-        u_int8_t* block_data = p;
-
-        //
-        // First and last cycles (can be the same one) may not be block aligned.
-        // Check the status, and copy data to a padded temp bufer if not alligned.
-        // (there's an option to write partial buffer, but Intel reference code always
-        // writes full buffer, with pads if needed. I do the dame ...)
-        //
-
-        prefix_pad_size = addr - block_addr;
-
-        if ((addr & block_mask) == ((addr + len) & block_mask)) {
-            suffix_pad_size = block_size - ((addr + len) % block_size);
-        }
-
-        if (suffix_pad_size || prefix_pad_size) {
-            // block exceeds given buffer - read to a temp bufer and 
-            // copy the required data to user's bufer.
-            data_size -= suffix_pad_size;
-            data_size -= prefix_pad_size;
-            block_data = tmp_buff;
-        }
-        
-        rc = mfl->f_read_blk(mfl, block_addr, block_size, block_data); CHECK_RC(rc);
-
-        if (suffix_pad_size || prefix_pad_size) {
-            for (i = 0; i < data_size; i++) {
-                p[i] = tmp_buff[prefix_pad_size + i];
-            }
-        }
-
-        //
-        // loop advance
-        //
-
-        addr += data_size;
-        p    += data_size;
-        len  -= data_size;
-    }
-
-    return MFE_OK;
-}
-
-
-
-
-////////////////////////////////////////
-//
-// InfiniHostIIILx spi  access functions
-//
-////////////////////////////////////////
-
-
-//
-// Relevant CR addresses, Bit offset and bit size
-//
-
-enum Ih3lxCrConstans {
-    CR_FLASH_GW     = 0xf0400,
-    CR_FLASH_ADDR   = 0xf0404,
-    CR_FLASH_DATA   = 0xf0408,
-    CR_FLASH_CS     = 0xf0418,
-
-    CR_GPIO_LOCK    = 0xf00ec,
-
-    BO_READ_OP      = 0,
-    BO_ADDR_INCR    = 1,
-
-    BO_LPC_STOP     = 3,
-    BO_SPI_NO_DATA  = 4,
-    BO_SPI_NO_ADDR  = 5,
-    BO_SPI_SPECIAL  = 6,
-
-    BO_MSIZE        = 8,
-    BS_MSIZE        = 3,
-
-    BO_STATUS       = 26,
-    BS_STATUS       = 4,
-
-    BO_BUSY         = 30,
-
-    BO_SPI_ADDR     = 0,
-    BS_SPI_ADDR     = 24,
-
-    BO_SPI_CMD      = 24,
-    BS_SPI_CMD      = 8,
-
-    BO_SPI_GPIO     = 25,
-    BS_SPI_GPIO     = 4
-};
-
-int ih3lx_wait_ready(mflash* mfl, char* msg) {
-    u_int32_t gw_cmd;
-    u_int32_t cnt = 0;
-    msg = 0; // NOT USED FOR NOW
-    do {
-        // Timeout checks
-        if (++cnt > FLASH_CMD_CNT) {
-            //return errmsg("Flash gateway timeout: %s.", msg);
-            return MFE_TIMEOUT;
-        }
-
-        MREAD4(CR_FLASH_GW, &gw_cmd);
-
-    } while (EXTRACT(gw_cmd, BO_BUSY, 1));
-
-    return MFE_OK;
-}
-
-//__inline
-int ih3lx_exec_cmd(mflash* mfl, u_int32_t gw_cmd, u_int32_t gw_addr, char* msg) {
-    gw_cmd = MERGE(gw_cmd, 1 , BO_BUSY, 1); 
-
-    MWRITE4(CR_FLASH_ADDR, gw_addr);
-    MWRITE4(CR_FLASH_GW,   gw_cmd);
-
-    return ih3lx_wait_ready(mfl, msg);
-}
-
-int ih3lx_set_bank(mflash* mfl, u_int32_t bank) {
-    u_int32_t flash_cs = 0;
-    // TODO: Check number of banks in open
-    if (bank > 3) {
-        //return errmsg("Tried to set bank to %d but %d is the is the largest bank number", bank, 3);
-        return MFE_BAD_PARAMS;
-    }
-
-    //printf("\n*** Flash::set_bank(0x%lx) : 0x%lx\n", bank, (bank >> 19) & 0x07);
-
-    flash_cs = MERGE(flash_cs, bank,30, 2);
-    MWRITE4(CR_FLASH_CS, flash_cs);
-
-    return MFE_OK;
-}
-
-int ih3lx_st_spi_get_status(mflash* mfl, u_int8_t op_type, u_int8_t* status) {
-    int rc;
-
-    u_int32_t gw_cmd  = 0;
-    u_int32_t gw_addr = 0;
-    u_int32_t flash_data;
-
-    gw_cmd = MERGE(gw_cmd, 1, BO_READ_OP,     1);
-    gw_cmd = MERGE(gw_cmd, 1, BO_SPI_SPECIAL, 1);
-    gw_cmd = MERGE(gw_cmd, 1, BO_SPI_NO_ADDR, 1);
-
-    gw_cmd = MERGE(gw_cmd, 2, BO_MSIZE  , BS_MSIZE);
-
-    gw_addr = MERGE(gw_addr, op_type, BO_SPI_CMD, BS_SPI_CMD);
-
-    rc = ih3lx_exec_cmd(mfl, gw_cmd, gw_addr, "Read id"); CHECK_RC(rc);
-
-    MREAD4(CR_FLASH_DATA, &flash_data);
-
-    // Return status reg byte is at offset 3 in word
-    *status = (u_int8_t)(flash_data & 0xff);
-
-    return MFE_OK;
-}
-
-int ih3lx_init_gpios(mflash* mfl) {
-    //
-    // Set Multi SPI CS to output and 0.
-    // Assuming 4 flashes. If there are less than 4 flashes and there's
-    // a write attempt, it will fail.
-    //
-
-    u_int32_t       num_of_spis = 4;
-    u_int32_t       spi_en      = (1 << (num_of_spis - 1 ) ) - 1;
-
-    u_int32_t       dir;
-    u_int32_t       mod;
-    u_int32_t       pol;
-
-    // No need to set the data - SPI GW CS does that in HW
-    //MREAD4(GPIO_DAT_L, &data);
-
-    MREAD4(GPIO_DIR_L, &dir);
-    MREAD4(GPIO_POL_L, &pol);
-    MREAD4(GPIO_MOD_L, &mod);
-
-    dir = MERGE(dir,  spi_en, BO_SPI_GPIO, BS_SPI_GPIO);
-    pol = MERGE(pol, ~spi_en, BO_SPI_GPIO, BS_SPI_GPIO);
-    mod = MERGE(mod, ~spi_en, BO_SPI_GPIO, BS_SPI_GPIO);
-
-    // unlock gpio
-    MWRITE4(CR_GPIO_LOCK , 0xaaaa);
-
-    MWRITE4(GPIO_DIR_L, dir);
-    MWRITE4(GPIO_POL_L, pol);
-    MWRITE4(GPIO_MOD_L, mod);
-
-    return MFE_OK;
-}
-
-
-int ih3lx_st_spi_write_enable(mflash* mfl) {
-    u_int32_t gw_cmd  = 0;
-    u_int32_t gw_addr = 0;
-
-    // Write enable:
-    gw_cmd = MERGE(gw_cmd, 1, BO_SPI_NO_ADDR ,  1);
-    gw_cmd = MERGE(gw_cmd, 1, BO_SPI_NO_DATA ,  1);
-    gw_cmd = MERGE(gw_cmd, 1, BO_SPI_SPECIAL ,  1);
-
-    gw_addr = MERGE(gw_addr, SFC_WREN, BO_SPI_CMD, BS_SPI_CMD);
-
-    return ih3lx_exec_cmd(mfl, gw_cmd, gw_addr, "WREN command");
-}
-
-int ih3lx_st_spi_block_read    (mflash* mfl, u_int32_t blk_addr, u_int32_t blk_size, u_int8_t* data) {
-    int rc;
-    u_int32_t offs;
-    u_int32_t gw_cmd   = 0;
-    u_int32_t gw_addr  = 0;
-
-    if (blk_addr & (blk_size - 1 )) {
-        //return _f.errmsg("Address should be 4-bytes aligned.");
-        return MFE_BAD_ALIGN;
-    }
-
-    if (blk_size > (u_int32_t)mfl->attr.block_write  || blk_size < 4) {
-        //return _f.errmsg("Block write of wrong block size. %d instead of %d",
-       //               block_size, (u_int32_t)_f._cfi_data.max_multi_byte_write);
-        return MFE_BAD_PARAMS;
-    }
-
-    rc = set_bank(mfl, blk_addr);        CHECK_RC(rc);
-
-    // Write the data block
-    gw_cmd = MERGE(gw_cmd, 1               , BO_READ_OP,     1);
-    gw_cmd = MERGE(gw_cmd, log2up(blk_size), BO_MSIZE,       BS_MSIZE);
-
-    gw_addr = blk_addr & ONES32(mfl->attr.log2_bank_size);
-
-    rc = ih3lx_exec_cmd(mfl, gw_cmd, gw_addr, "Read"); CHECK_RC(rc);
-
-    // Data:
-    for (offs = 0 ; offs < blk_size ; offs += 4) {
-        u_int32_t word;
-        MREAD4(CR_FLASH_DATA + offs, &word);
-        *((u_int32_t*)(data + offs))= __cpu_to_be32(word);
-    }
-
-    return MFE_OK;
-}
-
-
-int ih3lx_st_spi_reset          (mflash* mfl) {
-    mfl = NULL;
-    return MFE_OK;
-}
-
-int ih3lx_st_spi_block_write    (mflash* mfl, u_int32_t blk_addr, u_int32_t blk_size, u_int8_t* data) {
-    int rc;
-    u_int32_t offs;
-    u_int32_t gw_cmd   = 0;
-    u_int32_t gw_addr  = 0;
-
-    if (blk_addr & (blk_size - 1 )) {
-        //return _f.errmsg("Address should be 4-bytes aligned.");
-        return MFE_BAD_ALIGN;
-    }
-
-    // sanity check ??? remove ???
-    if (blk_size != (u_int32_t)mfl->attr.block_write ) {
-        //return _f.errmsg("Block write of wrong block size. %d instead of %d",
-       //               block_size, (u_int32_t)_f._cfi_data.max_multi_byte_write);
-        return MFE_BAD_PARAMS;
-    }
-
-    rc = set_bank(mfl, blk_addr);        CHECK_RC(rc);
-
-    rc = ih3lx_st_spi_write_enable(mfl); CHECK_RC(rc);
-
-    // Write the data block
-    gw_cmd = MERGE(gw_cmd, 1               , BO_SPI_SPECIAL,        1);
-    gw_cmd = MERGE(gw_cmd, log2up(blk_size), BO_MSIZE,       BS_MSIZE);
-
-    gw_addr = blk_addr & ONES32(mfl->attr.log2_bank_size);
-
-    gw_addr = MERGE(gw_addr, SFC_PP, BO_SPI_CMD, BS_SPI_CMD);
-
-    // Data:
-    for (offs = 0 ; offs < blk_size ; offs += 4) {
-        u_int32_t word = zero;
-        word = MERGE(word, data[offs + 0] , 24 , 8);
-        word = MERGE(word, data[offs + 1] , 16 , 8);
-        word = MERGE(word, data[offs + 2] ,  8 , 8);
-        word = MERGE(word, data[offs + 3] ,  0 , 8);
-        MWRITE4(CR_FLASH_DATA + offs, word );
-    }
-
-    rc = ih3lx_exec_cmd(mfl, gw_cmd, gw_addr, "PP command"); CHECK_RC(rc);
-
-    //
-    // Wait for end of write in flash (WriteInProgress = 0):
-    //
-
-    rc = st_spi_wait_wip(mfl, READ_DELAY, READ_CNT_SLOW + READ_CNT_FAST, READ_CNT_FAST); CHECK_RC(rc);
-
-    return MFE_OK;
-}
-
-int ih3lx_st_spi_erase_sect     (mflash* mfl, u_int32_t addr) {
-    int rc;
-
-    u_int32_t gw_cmd  = 0;
-    u_int32_t gw_addr = 0;
-
-    rc = set_bank(mfl, addr); CHECK_RC(rc);
-
-    rc = ih3lx_st_spi_write_enable(mfl); CHECK_RC(rc);
-
-    // Erase sector command:
-    gw_cmd = MERGE(gw_cmd, 1, BO_SPI_NO_DATA ,  1);
-    gw_cmd = MERGE(gw_cmd, 1, BO_SPI_SPECIAL ,  1);
-
-    gw_addr = addr & ONES32(mfl->attr.log2_bank_size);
-    gw_addr = MERGE(gw_addr, SFC_SE, BO_SPI_CMD, BS_SPI_CMD);
-
-    rc = ih3lx_exec_cmd(mfl, gw_cmd, gw_addr, "ES"); CHECK_RC(rc);
-
-    // Wait for erase completion
-    rc = st_spi_wait_wip(mfl, ERASE_DELAY, ERASE_CNT, 0); CHECK_RC(rc);
-
-    return MFE_OK;
-}
-
-int ih3lx_flash_init(mflash* mfl) {
-    int rc;
-
-    enum {
-        CR_FLASH_TYPE   = 0xf0810,
-        BO_FLASH_TYPE_S = 10,
-        BO_FLASH_TYPE_E = 11,
-    };
-
-    enum FlashType {
-        FT_LPC    = 0,
-        FT_SPI    = 1,
-        FT_XBUS   = 2,
-        FT_EEPROM = 3
-    };
-
-    char* flash_type_str[] = {"LPC", "SPI", "XBUS", "EEPROM"};
-
-    u_int32_t  strap_option;
-    u_int32_t  flash_type;
-
-    MREAD4(CR_FLASH_TYPE, &strap_option);
-
-    flash_type = EXTRACT_C(strap_option, BO_FLASH_TYPE_S, 2);
-
-    if (flash_type == FT_LPC   ||
-        flash_type == FT_XBUS  ||
-        flash_type == FT_EEPROM) {
-        printf("-E- flash of type %s not supported.\n", flash_type_str[flash_type]);
-        return MFE_UNSUPPORTED_FLASH_TYPE;
-    }
-
-    //mfl->f_read           = ih3lx_flash_read;
-    mfl->f_read           = read_chunks;
-    mfl->f_read_blk       = ih3lx_st_spi_block_read;
-    mfl->f_lock           = ihst_flash_lock; // Flash lock has same address and functionality as in InfiniHost.
-    mfl->f_set_bank       = ih3lx_set_bank;
-
-    rc = mfl->f_lock(mfl);
-    if (!mfl->opts[MFO_IGNORE_SEM_LOCK]) {
-        CHECK_RC(rc);
-    } else {
-        mfl->is_locked = 1;
-    }
-
-    rc = ih3lx_init_gpios(mfl);  CHECK_RC(rc);
-
-    mfl->f_spi_status = ih3lx_st_spi_get_status;
-
-    rc = st_spi_fill_attr(mfl);   CHECK_RC(rc);
-
-    if        (mfl->attr.command_set == MCS_STSPI) {
-        mfl->f_reset      = ih3lx_st_spi_reset;
-        mfl->f_write_blk  = ih3lx_st_spi_block_write;
-        mfl->f_write      = write_chunks;
-        mfl->f_erase_sect = ih3lx_st_spi_erase_sect;
-    } else {
-        return MFE_UNSUPPORTED_FLASH_TYPE;
-    }
-
-    rc = mfl->f_reset(mfl);
-
-    return MFE_OK;
-}
-
-//////////////////////////////////////////
-//
-// ConnectX functions implementation
-//
-//////////////////////////////////////////
-enum CntxCrConstants{
-    HCR_FLASH_CMD     = 0xf0400,
-    HCR_FLASH_ADDR    = 0xf0404,
-
-    HCR_FLASH_DATA    = 0xf0410,
-
-    HBO_READ_OP       = 0, 
-    HBO_ADDR_AUTO_INC = 1,  
-    HBO_CMD_PHASE     = 2,  
-    HBO_ADDR_PHASE    = 3,  
-    HBO_DATA_PHASE    = 4,  
-    HBO_CS_HOLD       = 5, 
-
-    HBO_MSIZE         = 8,
-    HBS_MSIZE         = 3,
-
-    HBO_CHIP_SELECT   = 11,
-    HBS_CHIP_SELECT   =  2,
-
-    HBO_FLASH_ENABLE  = 13,
-
-    HBO_CMD           = 16,
-    HBS_CMD           =  8,
-
-    HBO_BUSY          = 30,
-
-    HBO_ADDR          =  0,
-    HBS_ADDR          = 24,
-
-
-    // GPIOs
-    HCR_GPIO_LOCK     = 0xf0048,
-    HCR_GPIO_LOCK_VAL = 0xd42f,
-
-    HCR_GPIO_DATA_OUT = 0xf0040,
-    HCR_GPIO_MODE0    = 0xf0050,
-    HCR_GPIO_MODE1    = 0xf004c,
-
-    HBO_GPIO_CS       = 25,
-    HBS_GPIO_CS       =  4
-};
-
-int cntx_set_bank(mflash* mfl, u_int32_t bank) {
-    // NULL function - No actual work here - in ConnectX the curr_bank is written in the command word.
-    mfl = NULL; // Compiler warning
-    bank = 0;   // Compiler warning
-    return MFE_OK;
-}
-
-int cntx_exec_cmd(mflash* mfl, u_int32_t gw_cmd, char* msg) {
-    gw_cmd = MERGE(gw_cmd,              1, HBO_BUSY,                       1); 
-    gw_cmd = MERGE(gw_cmd,              1, HBO_FLASH_ENABLE,               1);
-    gw_cmd = MERGE(gw_cmd, (u_int32_t)mfl->curr_bank, 
-                                           HBO_CHIP_SELECT,  HBS_CHIP_SELECT);
-
-    MWRITE4(CR_FLASH_GW,   gw_cmd);
-
-    return ih3lx_wait_ready(mfl, msg);
-}
-
-int cntx_st_spi_get_status(mflash* mfl, u_int8_t op_type, u_int8_t* status) {
-    int rc;
-
-    u_int32_t gw_cmd  = 0;
-    u_int32_t flash_data;
-
-    gw_cmd = MERGE(gw_cmd,       1, HBO_READ_OP,    1);
-    gw_cmd = MERGE(gw_cmd,       1, HBO_CMD_PHASE,  1);
-    gw_cmd = MERGE(gw_cmd,       1, HBO_DATA_PHASE, 1);
-    gw_cmd = MERGE(gw_cmd,       2, HBO_MSIZE,      HBS_MSIZE);
-
-    gw_cmd = MERGE(gw_cmd, op_type, HBO_CMD,        HBS_CMD);
-
-    rc = cntx_exec_cmd(mfl, gw_cmd, "Read id");  CHECK_RC(rc);
-
-    MREAD4(HCR_FLASH_DATA, &flash_data);
-
-    // Return status reg byte is at offset 3 in word
-    *status = (u_int8_t)(flash_data & 0xff);
-
-    return MFE_OK;
-}
-
-int cntx_init_gpios(mflash* mfl) {
-    //
-    // Set Multi SPI CS to output and with value of 1 (inactive)
-    // Assuming 4 flashes. If there are less than 4 flashes and there's
-    // an access to a void flash, the access will fail.
-    //
-
-    u_int32_t       spi_en      = 0xf;
-
-    u_int32_t       mode0;
-    u_int32_t       mode1;
-    u_int32_t       data;
-
-    // Set 4 Chip selects to 1
-    MREAD4(HCR_GPIO_DATA_OUT, &data);
-    data = MERGE(data, spi_en, BO_SPI_GPIO, BS_SPI_GPIO);
-    MWRITE4(HCR_GPIO_DATA_OUT, data);
-
-    MREAD4(HCR_GPIO_MODE0, &mode0);
-    MREAD4(HCR_GPIO_MODE1, &mode1);
-
-    // Set 4 Chip selects to outputs
-    if (EXTRACT(mode0, HBO_GPIO_CS, HBS_GPIO_CS) != spi_en ||
-        EXTRACT(mode1, HBO_GPIO_CS, HBS_GPIO_CS) != 0          ) {
-        mode0 = MERGE(mode0,  spi_en, BO_SPI_GPIO, BS_SPI_GPIO);
-        mode1 = MERGE(mode1, ~spi_en, BO_SPI_GPIO, BS_SPI_GPIO);
-
-        // unlock gpio
-        MWRITE4(HCR_GPIO_LOCK , HCR_GPIO_LOCK_VAL);
-
-        MWRITE4(HCR_GPIO_MODE0, mode0);
-        MWRITE4(HCR_GPIO_MODE1, mode1);
-
-        // re-lock
-        MWRITE4(HCR_GPIO_LOCK , 0);
-    }
-
-    return MFE_OK;
-}
-
-int cntx_st_spi_write_enable(mflash* mfl) {
-    u_int32_t gw_cmd  = 0;
-
-    // Write enable:
-    gw_cmd = MERGE(gw_cmd,        1, HBO_CMD_PHASE,       1);
-    gw_cmd = MERGE(gw_cmd, SFC_WREN, HBO_CMD,       HBS_CMD);
-
-    return cntx_exec_cmd(mfl, gw_cmd, "WREN command");
-}
-
-int cntx_st_spi_reset          (mflash* mfl) {
-    mfl = NULL;
-    return MFE_OK;
-}
-
-int cntx_st_spi_page_read    (mflash* mfl, u_int32_t addr, u_int32_t size, u_int8_t* data) {
-    int rc;
-
-    u_int32_t last_blk_addr;
-    u_int32_t last_addr;
-    u_int8_t  is_first = 1;
-    u_int8_t  is_last  = 0;
-    u_int8_t* p        = data;
-
-    if (addr & ((u_int32_t)mfl->attr.block_write - 1)) {
-        return MFE_BAD_ALIGN;
-    }
-
-    if (size & ((u_int32_t)mfl->attr.block_write - 1)) {
-         return MFE_BAD_ALIGN;
-    }
-
-    printf("-D- cntx_st_spi_page_read(addr=%05x, u_int32_t size=%03x)\n", addr, size);
-
-    last_addr     = addr + size;
-    last_blk_addr = last_addr - mfl->attr.block_write;
-
-    while (addr < last_addr) {
-        if (addr == last_blk_addr) {
-            is_last = 1;
-        }
-        
-        rc = cntx_st_spi_block_read_ex(mfl, addr, mfl->attr.block_write, p, is_first, is_last); CHECK_RC(rc);
-
-        is_first = 0;
-        addr += mfl->attr.block_write;
-        p    += mfl->attr.block_write;
-    }
-
-    return MFE_OK;    
-}
-
-int cntx_st_spi_block_read_ex  (mflash* mfl, u_int32_t blk_addr, u_int32_t blk_size, u_int8_t* data, u_int8_t is_first, u_int8_t is_last) {
-    int rc;
-    u_int32_t offs;
-    u_int32_t gw_cmd   = 0;
-    u_int32_t gw_addr  = 0;
-
-    //printf("-D- cntx_st_spi_block_read_ex(addr=%05x, u_int32_t size=%03x, first=%d, last=%d)\n", blk_addr, blk_size, (u_int32_t) is_first, (u_int32_t) is_last);
-
-    if (blk_addr & (blk_size - 1 )) {
-        return MFE_BAD_ALIGN;
-    }
-
-    if (blk_size > (u_int32_t)mfl->attr.block_write  || blk_size < 4) {
-        return MFE_BAD_PARAMS;
-    }
-
-    rc = set_bank(mfl, blk_addr);        CHECK_RC(rc);
-
-    if (is_first) {
-        gw_cmd = MERGE(gw_cmd, 1               , HBO_CMD_PHASE,  1);
-        gw_cmd = MERGE(gw_cmd, 1               , HBO_ADDR_PHASE, 1);
-        gw_cmd = MERGE(gw_cmd, SFC_READ        , HBO_CMD,        HBS_CMD);
-
-        gw_addr = blk_addr & ONES32(mfl->attr.log2_bank_size);
-        MWRITE4(HCR_FLASH_ADDR, gw_addr);
-    }
-
-    if (!is_last) {
-        gw_cmd = MERGE(gw_cmd, 1               , HBO_CS_HOLD,    1);
-    }
-
-    // Read the data block
-    gw_cmd = MERGE(gw_cmd, 1, HBO_READ_OP,           1);
-    gw_cmd = MERGE(gw_cmd, 1, HBO_DATA_PHASE,        1);
-    gw_cmd = MERGE(gw_cmd, log2up(blk_size), BO_MSIZE,       BS_MSIZE);
-
-    rc = cntx_exec_cmd(mfl, gw_cmd, "Read"); CHECK_RC(rc);
-
-    // Data: 
-    for (offs = 0 ; offs < blk_size ; offs += 4) {
-        u_int32_t word;
-        MREAD4(HCR_FLASH_DATA + offs, &word);
-        *((u_int32_t*)(data + offs))=  __cpu_to_be32(word);
-    }
-
-    return MFE_OK;
-}
-
-int cntx_st_spi_block_read  (mflash* mfl, u_int32_t blk_addr, u_int32_t blk_size, u_int8_t* data) {
-    return cntx_st_spi_block_read_ex(mfl, blk_addr, blk_size, data, 1, 1);
-}
-
-int cntx_st_spi_block_read_old  (mflash* mfl, u_int32_t blk_addr, u_int32_t blk_size, u_int8_t* data) {
-    int rc;
-    u_int32_t offs;
-    u_int32_t gw_cmd   = 0;
-    u_int32_t gw_addr  = 0;
-
-    if (blk_addr & (blk_size - 1 )) {
-        return MFE_BAD_ALIGN;
-    }
-
-    if (blk_size > (u_int32_t)mfl->attr.block_write  || blk_size < 4) {
-        return MFE_BAD_PARAMS;
-    }
-
-    rc = set_bank(mfl, blk_addr);        CHECK_RC(rc);
-
-    // Read the data block
-    gw_cmd = MERGE(gw_cmd, 1, HBO_READ_OP,           1);
-    gw_cmd = MERGE(gw_cmd, 1, HBO_CMD_PHASE,         1);
-    gw_cmd = MERGE(gw_cmd, 1, HBO_ADDR_PHASE,        1);
-    gw_cmd = MERGE(gw_cmd, 1, HBO_DATA_PHASE,        1);
-    gw_cmd = MERGE(gw_cmd, log2up(blk_size), BO_MSIZE,       BS_MSIZE);
-    gw_cmd = MERGE(gw_cmd, SFC_READ, HBO_CMD,       HBS_CMD);
-
-    gw_addr = blk_addr & ONES32(mfl->attr.log2_bank_size);
-    MWRITE4(HCR_FLASH_ADDR, gw_addr);
-
-    rc = cntx_exec_cmd(mfl, gw_cmd, "Read"); CHECK_RC(rc);
-
-    // Data:
-    for (offs = 0 ; offs < blk_size ; offs += 4) {
-        u_int32_t word;
-        MREAD4(HCR_FLASH_DATA + offs, &word);
-        *((u_int32_t*)(data + offs))= __cpu_to_be32(word);
-    }
-
-    return MFE_OK;
-}
-
-int cntx_st_spi_page_write    (mflash* mfl, u_int32_t addr, u_int32_t size, u_int8_t* data) {
-    int rc;
-
-    u_int32_t last_blk_addr;
-    u_int32_t last_addr;
-    u_int8_t  is_first = 1;
-    u_int8_t  is_last  = 0;
-    u_int8_t* p        = data;
-
-    if (addr & ((u_int32_t)mfl->attr.block_write - 1)) {
-        return MFE_BAD_ALIGN;
-    }
-
-    if (size & ((u_int32_t)mfl->attr.block_write - 1)) {
-         return MFE_BAD_ALIGN;
-    }
-
-    //printf("-D- cntx_st_spi_page_write(addr=%05x, u_int32_t size=%03x)\n", addr, size);
-
-    last_addr     = addr + size;
-    last_blk_addr = last_addr - mfl->attr.block_write;
-
-    while (addr < last_addr) {
-        if (addr == last_blk_addr) {
-            is_last = 1;
-        }
-        
-        rc = cntx_st_spi_block_write_ex(mfl, addr, mfl->attr.block_write, p, is_first, is_last); CHECK_RC(rc);
-
-        is_first = 0;
-        addr += mfl->attr.block_write;
-        p    += mfl->attr.block_write;
-    }
-
-    return MFE_OK;
-}
-
-int cntx_st_spi_block_write_ex (mflash* mfl, u_int32_t blk_addr, u_int32_t blk_size, u_int8_t* data, u_int8_t is_first, u_int8_t is_last) {
-    int rc;
-    u_int32_t offs;
-    u_int32_t gw_cmd   = 0;
-    u_int32_t gw_addr  = 0;
-
-    if (blk_addr & ((u_int32_t)mfl->attr.block_write - 1 )) {
-        return MFE_BAD_ALIGN;
-    }
-
-    // sanity check ??? remove ???
-    if (blk_size != (u_int32_t)mfl->attr.block_write ) {
-        return MFE_BAD_PARAMS;
-    }
-
-    //printf("-D- cntx_st_spi_block_write_ex(addr=%05x, u_int32_t size=%03x, first=%d, last=%d)\n", blk_addr, blk_size, (u_int32_t) is_first, (u_int32_t) is_last);
-
-    rc = set_bank(mfl, blk_addr);        CHECK_RC(rc);
-
-    gw_cmd = MERGE(gw_cmd, 1               , HBO_DATA_PHASE, 1);
-    gw_cmd = MERGE(gw_cmd, log2up(blk_size), HBO_MSIZE,      HBS_MSIZE);
-
-    if (is_first) {
-        rc = cntx_st_spi_write_enable(mfl); CHECK_RC(rc);
-
-        // Write the data block
-        gw_cmd = MERGE(gw_cmd, 1               , HBO_CMD_PHASE,  1);
-        gw_cmd = MERGE(gw_cmd, 1               , HBO_ADDR_PHASE, 1);
-        gw_cmd = MERGE(gw_cmd, SFC_PP          , HBO_CMD,        HBS_CMD);
-
-        gw_addr = blk_addr & ONES32(mfl->attr.log2_bank_size);
-
-        MWRITE4(HCR_FLASH_ADDR, gw_addr);
-    }
-
-    if (!is_last) {
-        gw_cmd = MERGE(gw_cmd, 1               , HBO_CS_HOLD,    1);
-    }
-    
-    // Data:
-    for (offs = 0 ; offs < blk_size ; offs += 4) {
-        u_int32_t word = zero;
-        word = MERGE(word, data[offs + 0] , 24 , 8);
-        word = MERGE(word, data[offs + 1] , 16 , 8);
-        word = MERGE(word, data[offs + 2] ,  8 , 8);
-        word = MERGE(word, data[offs + 3] ,  0 , 8);
-        MWRITE4(HCR_FLASH_DATA + offs, word );
-    }
-
-    rc = cntx_exec_cmd(mfl, gw_cmd, "PP command"); CHECK_RC(rc);
-
-    //
-    // Wait for end of write in flash (WriteInProgress = 0):
-    //
-
-    if (is_last) {
-        rc = st_spi_wait_wip(mfl, READ_DELAY, READ_CNT_SLOW + READ_CNT_FAST, READ_CNT_FAST); CHECK_RC(rc);
-    }
-
-    return MFE_OK;
-}
-
-int cntx_st_spi_block_write     (mflash* mfl, u_int32_t blk_addr, u_int32_t blk_size, u_int8_t* data) {
-   return cntx_st_spi_block_write_ex(mfl, blk_addr, blk_size, data, 1, 1); 
-}
-
-int cntx_st_spi_block_write_old (mflash* mfl, u_int32_t blk_addr, u_int32_t blk_size, u_int8_t* data) {
-    int rc;
-    u_int32_t offs;
-    u_int32_t gw_cmd   = 0;
-    u_int32_t gw_addr  = 0;
-
-
-    if (blk_addr & (blk_size - 1 )) {
-        return MFE_BAD_ALIGN;
-    }
-
-    // sanity check ??? remove ???
-    if (blk_size != (u_int32_t)mfl->attr.block_write ) {
-        return MFE_BAD_PARAMS;
-    }
-
-    rc = set_bank(mfl, blk_addr);        CHECK_RC(rc);
-
-    rc = cntx_st_spi_write_enable(mfl); CHECK_RC(rc);
-
-    // Write the data block
-    gw_cmd = MERGE(gw_cmd, 1               , HBO_CMD_PHASE,  1);
-    gw_cmd = MERGE(gw_cmd, 1               , HBO_ADDR_PHASE, 1);
-    gw_cmd = MERGE(gw_cmd, 1               , HBO_DATA_PHASE, 1);
-
-    gw_cmd = MERGE(gw_cmd, log2up(blk_size), HBO_MSIZE,      HBS_MSIZE);
-    gw_cmd = MERGE(gw_cmd, SFC_PP          , HBO_CMD,        HBS_CMD);
-
-    gw_addr = blk_addr & ONES32(mfl->attr.log2_bank_size);
-
-    MWRITE4(HCR_FLASH_ADDR, gw_addr);
-
-    // Data:
-    for (offs = 0 ; offs < blk_size ; offs += 4) {
-        u_int32_t word = zero;
-        word = MERGE(word, data[offs + 0] , 24 , 8);
-        word = MERGE(word, data[offs + 1] , 16 , 8);
-        word = MERGE(word, data[offs + 2] ,  8 , 8);
-        word = MERGE(word, data[offs + 3] ,  0 , 8);
-        MWRITE4(HCR_FLASH_DATA + offs, word );
-    }
-
-    rc = cntx_exec_cmd(mfl, gw_cmd, "PP command"); CHECK_RC(rc);
-
-    //
-    // Wait for end of write in flash (WriteInProgress = 0):
-    //
-
-    rc = st_spi_wait_wip(mfl, READ_DELAY, READ_CNT_SLOW + READ_CNT_FAST, READ_CNT_FAST); CHECK_RC(rc);
-
-    return MFE_OK;
-    }
-
-int cntx_st_spi_erase_sect(mflash* mfl, u_int32_t addr) {
-    int rc;
-
-    u_int32_t gw_cmd  = 0;
-    u_int32_t gw_addr = 0;
-
-    rc = set_bank(mfl, addr); CHECK_RC(rc);
-
-    rc = cntx_st_spi_write_enable(mfl); CHECK_RC(rc);
-
-    // Erase sector command:
-    gw_cmd = MERGE(gw_cmd,      1, HBO_CMD_PHASE,  1);
-    gw_cmd = MERGE(gw_cmd,      1, HBO_ADDR_PHASE, 1);
-    gw_cmd = MERGE(gw_cmd, SFC_SE, HBO_CMD,        HBS_CMD); 
-
-    gw_addr = addr & ONES32(mfl->attr.log2_bank_size);
-    
-    MWRITE4(HCR_FLASH_ADDR, gw_addr);
-
-    rc = cntx_exec_cmd(mfl, gw_cmd, "ES"); CHECK_RC(rc);
-
-    // Wait for erase completion
-    rc = st_spi_wait_wip(mfl, ERASE_DELAY, ERASE_CNT, 0); CHECK_RC(rc);
-
-    return MFE_OK;
-}
-
-int cntx_flash_init(mflash* mfl) {
-    int rc;
-    u_int32_t tmp;
-
-    // Without too much details:
-    // When the ConnectX boots up without a valid FW , the PCIE link may be unstable.
-    // In that case, turn off the auto reset on link down, so we'll be able to burn the device.
-    MREAD4(0x41270, &tmp);
-    if (tmp > 0xfff00000) {
-        u_int32_t tmp1;
-        MREAD4(0xf3834, &tmp1);
-        tmp1 = MERGE(tmp1, 2, 27, 2);
-        MWRITE4(0xf3834, tmp1);
-    }
-
-
-    //TODO: Enable page_read (slightly better perf)
-    //mfl->f_read           = cntx_st_spi_page_read;
-    mfl->f_read           = read_chunks;
-    mfl->f_read_blk       = cntx_st_spi_block_read;
-    mfl->f_lock           = ihst_flash_lock; // Flash lock has same address and functionality as in InfiniHost.
-    mfl->f_set_bank       = cntx_set_bank;
-
-    rc = mfl->f_lock(mfl);
-    if (!mfl->opts[MFO_IGNORE_SEM_LOCK]) {
-        CHECK_RC(rc);
-    } else {
-        mfl->is_locked = 1;
-    }
-
-    rc = cntx_init_gpios(mfl);  CHECK_RC(rc);
-
-    mfl->f_spi_status = cntx_st_spi_get_status;
-
-    rc = st_spi_fill_attr(mfl);   CHECK_RC(rc);
-
-    if        (mfl->attr.command_set == MCS_STSPI) {
-        mfl->f_reset      = ih3lx_st_spi_reset; // Null func - same as in ih3lx
-        //mfl->f_write_blk  = cntx_st_spi_block_write;  
-        mfl->f_write_blk  = cntx_st_spi_page_write; mfl->attr.page_write = 256;
-        mfl->f_write      = write_chunks;
-        mfl->f_erase_sect = cntx_st_spi_erase_sect;
-    } else {
-        return MFE_UNSUPPORTED_FLASH_TYPE;
-    }
-
-    rc = mfl->f_reset(mfl);
-
-    return MFE_OK;
-}
-
-//
-// Interface functions:
-//
-
-int     mf_read        (mflash* mfl, u_int32_t addr, u_int32_t len, u_int8_t* data) {
-    if (addr + len > mfl->attr.size) {
-        return MFE_OUT_OF_RANGE;
-    }
-    return mfl->f_read(mfl, addr, len, data);
-}
-
-int     mf_write       (mflash* mfl, u_int32_t addr, u_int32_t len, u_int8_t* data) {
-    if (addr + len > mfl->attr.size) {
-        return MFE_OUT_OF_RANGE;
-    }
-    return mfl->f_write(mfl, addr, len, data);
-}
-
-int     mf_erase_sector(mflash* mfl, u_int32_t addr) {
-    if (addr >= mfl->attr.size) {
-        return MFE_OUT_OF_RANGE;
-    }
-    return mfl->f_erase_sect(mfl, addr);
-}
-
-int mf_open_ignore_lock(mflash* mfl) {
-    mfl->opts[MFO_IGNORE_SEM_LOCK] = 1;
-    return mf_open_fw(mfl);
-}
-
-//Caller must zero the mflash struct before calling this func.
-int mf_open_fw(mflash* mfl)
-{
-    int rc;
-    u_int32_t dev_id;
-
-    if (!mfl) {
-        return MFE_BAD_PARAMS;
-    }
-
-    MREAD4(0xf0014, &dev_id);
-
-    dev_id &= 0xffff;
-
-    mfl->attr.hw_dev_id = dev_id;
-    //printf("-D- read dev id: %d\n", dev_id);
-
-    if (dev_id == 23108 || dev_id == 25208) {
-        rc = ihst_flash_init(mfl);
-    } else if (dev_id == 24204 || dev_id == 25204) {
-        rc = ih3lx_flash_init(mfl);
-    } else if (dev_id == 400) {
-        rc = cntx_flash_init(mfl);
-    } else if (dev_id == 0xffff) {
-        printf("-E- Read a corrupted device id (0x%x). Probably HW/PCI access problem\n", dev_id);
-        rc = MFE_CR_ERROR;
-    } else {
-        printf("-E- Device type %d not supported.\n", dev_id);
-        rc = MFE_INVAL;
-    }
-
-    CHECK_RC(rc);
-
-    mfl->curr_bank = -1;
-    mfl->f_set_bank(mfl,0);
-
-    return MFE_OK;
-}
-
-int    mf_opend       (mflash** pmfl, struct mfile_t* mf) {
-    int rc;
-    *pmfl = (mflash*)malloc(sizeof(mflash));
-    if (!*pmfl) {
-        return MFE_NOMEM;
-    }
-
-    memset(*pmfl, 0, sizeof(mflash));
-    (*pmfl)->mf = (mfile*)mf;
-
-    rc = mf_open_fw(*pmfl);
-
-    return rc;
-}
-
-int     mf_open        (mflash** pmfl, const char* dev) {
-    mfile*  mf;
-
-    int rc;
-
-    if (!dev) {
-        return MFE_BAD_PARAMS;
-    }
-
-    mf = mopen(dev);
-
-    if (!mf) {
-        return MFE_CR_ERROR;
-    }
-
-    rc = mf_opend(pmfl, (struct mfile_t*) mf);
-
-    if ((*pmfl)) {
-        (*pmfl)->opts[MFO_CLOSE_MF_ON_EXIT] = 1;
-    }
-
-    CHECK_RC(rc);
-
-    return MFE_OK;
-}
-
-int     mf_close       (mflash* mfl) {
-    if (!mfl) {
-        return MFE_BAD_PARAMS;
-    }
-
-    if (mfl->f_reset) {
-        mfl->f_reset(mfl);
-    }
-
-    set_bank(mfl, 0);
-
-    if (mfl->is_locked) {
-        MWRITE4(SEMAP63, 0);
-    }
-
-    if (mfl->mf && (mfl)->opts[MFO_CLOSE_MF_ON_EXIT]) {
-        mclose(mfl->mf);
-    }
-
-    free(mfl);
-    return MFE_OK;
-}
-
-
-int     mf_get_attr    (mflash* mfl, flash_attr* attr) {
-    *attr = mfl->attr;
-    return MFE_OK;
-}
-
-const char*   mf_err2str (int err_code) {
-    static char* mf_err_str[] = {
-    "MFE_OK",
-    "MFE_ERROR",
-    "MFE_BAD_PARAMS",
-    "MFE_CR_ERROR",
-    "MFE_INVAL",
-    "MFE_NOT_IMPLEMENTED",
-    "MFE_UNSUPPORTED_FLASH_TOPOLOGY",
-    "MFE_UNSUPPORTED_FLASH_TYPE",
-    "MFE_CFI_FAILED",
-    "MFE_TIMEOUT",
-    "MFE_ERASE_TIMEOUT",
-    "MFE_WRITE_TIMEOUT",
-    "MFE_ERASE_ERROR",
-    "MFE_WRITE_ERROR",
-    "MFE_BAD_ALIGN",
-    "MFE_SEM_LOCKED",
-    "MFE_VERIFY_ERROR",
-    "MFE_NOMEM",
-    "MFE_OUT_OF_RANGE"
-    };
-
-    return err_code < (int)ARRSIZE(mf_err_str) ? mf_err_str[err_code] : NULL;
-}
-
-int     mf_set_opt     (mflash* mfl, MfOpt opt, int  val) {
-    if ((int)opt < 0 || opt > MFO_LAST) {
-        return MFE_BAD_PARAMS;
-    }
-    mfl->opts[opt] = val;
-    return MFE_OK;
-}
-
-int     mf_get_opt     (mflash* mfl, MfOpt opt, int *val) {
-    if ((int)opt < 0 || opt > MFO_LAST) {
-        return MFE_BAD_PARAMS;
-    }
-    *val = mfl->opts[opt];
-    return MFE_OK;
-}
-
-
-int     mf_cr_read     (mflash* mfl, u_int32_t cr_addr, u_int32_t* data) {
-    if (mread4(mfl->mf, cr_addr, data) != 4) {
-        return MFE_CR_ERROR;
-    }
-    return MFE_OK;
-}
-int     mf_cr_write    (mflash* mfl, u_int32_t cr_addr, u_int32_t  data) {
-    if (mwrite4(mfl->mf, cr_addr, data) != 4) {
-        return MFE_CR_ERROR;
-    }
-    return MFE_OK;
-}
diff --git a/tools/flint/user/mflash.h b/tools/flint/user/mflash.h
deleted file mode 100644 (file)
index 1796152..0000000
+++ /dev/null
@@ -1,222 +0,0 @@
-/*
- *
- * mflash.h - Mellanox Technilogies LTD. Flash access lib heared file
- * ==================================================================
- *
- * Copyright (c) 2005-2008 Mellanox Technologies.  All rights reserved.
- *
- * This software is available to you under the OpenIB.org BSD license
- * below:
- *
- *     Redistribution and use in source and binary forms, with or
- *     without modification, are permitted provided that the following
- *     conditions are met:
- *
- *      - Redistributions of source code must retain the above
- *        copyright notice, this list of conditions and the following
- *        disclaimer.
- *
- *      - Redistributions in binary form must reproduce the above
- *        copyright notice, this list of conditions and the following
- *        disclaimer in the documentation and/or other materials
- *        provided with the distribution.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
- * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
- * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
- * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
- * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
- * 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: $
- *
- */
-#ifndef MFLASH_H
-#define MFLASH_H
-
-#ifndef __WIN__
-#include <sys/types.h>
-#endif
-
-#ifdef __cplusplus
-#define EXTERN_C_START extern "C" {
-#define EXTERN_C_END   }
-#else
-#define EXTERN_C_START
-#define EXTERN_C_END
-#endif
-
-EXTERN_C_START
-
-typedef enum MfCommandSet {
-    CS_INTEL  = 1,
-    CS_AMD    = 2,
-
-    MCS_STSPI = 0x80  // This is not a "real" CFI command set - it's used as a "Meta" command set number.
-} MfCommandSet;
-
-typedef enum MfError {
-    MFE_OK = 0,
-    MFE_ERROR,
-    MFE_BAD_PARAMS,
-    MFE_CR_ERROR,
-    MFE_INVAL,
-    MFE_NOT_IMPLEMENTED,
-    MFE_UNSUPPORTED_FLASH_TOPOLOGY,
-    MFE_UNSUPPORTED_FLASH_TYPE,
-    MFE_CFI_FAILED,
-    MFE_TIMEOUT,
-    MFE_ERASE_TIMEOUT,
-    MFE_WRITE_TIMEOUT,
-    MFE_ERASE_ERROR,
-    MFE_WRITE_ERROR,
-    MFE_BAD_ALIGN,
-    MFE_SEM_LOCKED,
-    MFE_VERIFY_ERROR,
-    MFE_NOMEM,
-    MFE_OUT_OF_RANGE,
-    MFE_LAST
-} MfError;
-
-typedef enum MfOpt {
-    MFO_NO_VERIFY = 0,
-    MFO_AMD_UNLOCK_BYPASS,
-    MFO_AMD_BYTE_MODE,
-    MFO_IGNORE_SEM_LOCK,
-    MFO_CLOSE_MF_ON_EXIT,
-    MFO_LAST
-} MfOpt;
-
-/////////////////////////////////////////////
-//
-// Flash attributes struct
-//
-/////////////////////////////////////////////
-typedef struct flash_attr {
-    //
-    // hw_dev_id    hw dev id of the HCA.
-    //
-    u_int32_t hw_dev_id;
-
-    //
-    // size:        Total size (in bytes) of all flash devices connected to
-    //              the device (forming a contigous address space)
-    //
-    u_int32_t size;
-
-    //
-    // sector_size: Flash sector size (in bytes).
-    //              Assuming a single sector size for the flash.
-    //
-    u_int32_t sector_size;
-
-    int       num_erase_blocks;         // Number of sector defs.
-    struct {
-        unsigned long sector_size;      // Byte size of sector
-        int           num_sectors;      // Num sectors of this size
-        u_int32_t     sector_mask;      // Sector mask
-    } erase_block[8];
-
-    //
-    // bank_size:   Different bank means a different chip sellect or gpio settings is needed when crossing 
-    //              this alignment.
-    //              This may indicate a different flash device (for SPI flash in InfiniHostIIILx / ConnectX).
-    //              Or GPIO change for parallel flash (in InfiniHostIII / InfiniHost)
-    //
-    int bank_size;
-    int log2_bank_size;
-
-    //
-    // Command set (taken from CFI terminology)
-    //
-    int command_set;
-
-    //
-    // block_write - if block write is supported, holds the block size in bytes. 0 otherwise.
-    //               The meaning of "block write" is not the same in parallel and serial flash.
-    //
-    int block_write;
-
-    //
-    // page_write -  if page write is supported, holds the page size in bytes. 0 otherwise.
-    //
-    int page_write;
-
-} flash_attr;
-
-
-/////////////////////////////////////////////
-//
-// MFLASH INTERFACE FUNCTIONS
-// 
-// Return value: 
-// All functions returns MfError enum values.
-//
-/////////////////////////////////////////////
-
-struct mfile_t;
-typedef struct mflash mflash;
-
-//
-// open/close functions:
-// This lib is used pretty much like a C file: open it, use and close when done.
-//
-// mf_open(): Allocates and init the mflash object to be used with the other lib funcs.
-//   OUT: pmfl - The opened mflash struct is returned here.
-//   IN : dev  - The string name of the crspace device to use.
-// 
-// mf_opend(): Same as mf_open, but uses an already opened crspace device.
-//
-// mf_open_ignore_lock() : 
-//   THIS FUNCTION IS NOT SAFE -
-//   It ignores the flash semaphore during flash init sequence.
-//   Use only after one of the above open() failed because of MFE_SEM_LOCKED
-//   and you are absolutely sure that the lock can be overridden (E.G. semaphore 
-//   remained in locked state due to previous kill of the burning app).
-//
-// mf_close() : Deallocates mflash resources.
-//   Note: User should call mf_close() even if mf_open failed (and the returning mfl is not NULL)
-//
-int     mf_open        (mflash** pmfl, const char* dev);
-int     mf_opend       (mflash** pmfl, struct mfile_t* mf);
-int     mf_open_ignore_lock(mflash* mfl);
-int     mf_close       (mflash* mfl);
-
-//
-// Flash access functions:
-// The data buffer should be pre-allocated by caller. The rest is quite self explanatory. .
-//
-int     mf_read        (mflash* mfl, u_int32_t addr, u_int32_t len, u_int8_t* data);
-int     mf_write       (mflash* mfl, u_int32_t addr, u_int32_t len, u_int8_t* data);
-int     mf_erase_sector(mflash* mfl, u_int32_t addr);
-
-//
-// Crspace access through mflash: 
-//
-int     mf_cr_read     (mflash* mfl, u_int32_t cr_addr, u_int32_t* data);
-int     mf_cr_write    (mflash* mfl, u_int32_t cr_addr, u_int32_t  data);
-
-//
-// mf_get_attr(): Returns the flash_attr struct
-//
-int     mf_get_attr    (mflash* mfl, flash_attr* attr);
-
-//
-// Set/Get for some options.
-//
-int     mf_set_opt     (mflash* mfl, MfOpt opt, int  val);
-int     mf_get_opt     (mflash* mfl, MfOpt opt, int *val);
-
-//
-// err code to string translation for printing.
-//
-const char* mf_err2str (int err_code);
-
-EXTERN_C_END
-
-#endif // MFLASH_H
-
-
-
diff --git a/tools/mread/user/SOURCES b/tools/mread/user/SOURCES
deleted file mode 100644 (file)
index 359ceff..0000000
+++ /dev/null
@@ -1,40 +0,0 @@
-TARGETNAME=mread\r
-TARGETTYPE=PROGRAM\r
-UMTYPE=console\r
-USE_CRTDLL=1\r
-\r
-\r
-!if !defined(WINIBHOME)\r
-WINIBHOME=..\..\..\r
-!endif\r
-\r
-TARGETPATH=$(WINIBHOME)\bin\user\obj$(BUILD_ALT_DIR)\r
-\r
-\r
-\r
-SOURCES=mread.c \\r
-        mread.rc\r
-\r
-INCLUDES= $(WINIBHOME)\inc;                    \\r
-          $(WINIBHOME)\inc\user;               \\r
-         $(WINIBHOME)\inc\iba;                \\r
-          $(WINIBHOME)\tools\mtcr\user;\r
-\r
-TARGETLIBS= \\r
-!if $(FREEBUILD)\r
-                       $(TARGETPATH)\*\mtcr.lib\r
-!else\r
-                       $(TARGETPATH)\*\mtcr.lib\r
-!endif\r
-\r
-!if $(FREEBUILD)\r
-\r
-!else\r
-C_DEFINES=$(C_DEFINES) -DDEBUG\r
-!endif\r
-\r
-C_DEFINES=$(C_DEFINES) -D__WIN__\r
-\r
-386_STDCALL=0\r
-\r
-\r
diff --git a/tools/mread/user/makefile b/tools/mread/user/makefile
deleted file mode 100644 (file)
index 80d407b..0000000
+++ /dev/null
@@ -1,8 +0,0 @@
-#\r
-# DO NOT EDIT THIS FILE!!!  Edit .\sources. if you want to add a new source\r
-# file to this component.  This file merely indirects to the real make file\r
-# that is shared by all the driver components of the Windows NT DDK\r
-#\r
-\r
-!INCLUDE ..\..\..\inc\openib.def\r
-\r
diff --git a/tools/mread/user/mread.c b/tools/mread/user/mread.c
deleted file mode 100644 (file)
index dd3db44..0000000
+++ /dev/null
@@ -1,73 +0,0 @@
-/*
- *
- *  mread.c - CR Space read access
- *
- */
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
-#include "mtcr.h"
-
-void usage(const char *n)
-{
-    printf("%s <device> <addr> [<i2c_slave>]\n", n);
-    exit(1);
-}
-
-int main(int ac, char *av[])
-{
-    char          *endp;
-    int           rc=0;
-    unsigned int  addr, val;
-    mfile         *mf;
-    DType         dtype = MST_TAVOR;
-
-#if 0
-    int  i, rc1;
-    char buf[1024], *p=buf;
-    rc1 = mdevices(buf, 1024);
-    for (i=0; i<rc1; i++)
-    {
-        printf("Found: \"%s\"\n", p);
-        p += strlen(p)+1;
-    }
-    exit(0);
-#endif
-
-    if (ac < 3)
-        usage(av[0]);
-    addr = strtoul(av[2], &endp, 0);
-    if (*endp)
-        usage(av[0]);
-
-    if (strstr(av[1], "mt21108_pci") && !strstr(av[1], "i2cm"))
-        dtype = MST_GAMLA;
-    mf = mopend(av[1], dtype);
-    if (!mf)
-    {
-        perror("mopen");
-        return 1;
-    }
-
-    if (ac >= 4)
-        mset_i2c_slave(mf, (unsigned char)strtoul(av[3],0,0));
-
-    if ((rc = mread4(mf, addr, &val)) < 0)
-    {
-        mclose(mf);
-        perror("mread");
-        return 1;
-    }
-    if (rc < 4)
-    {
-        mclose(mf);
-        printf("Read only %d bytes\n", rc);
-        return 1;
-    }
-
-    mclose(mf);
-    printf("Read 0x%08x:0x%08x\n", addr, val);
-    return rc;
-}
diff --git a/tools/mst/dirs b/tools/mst/dirs
deleted file mode 100644 (file)
index 5a7e8b3..0000000
+++ /dev/null
@@ -1,2 +0,0 @@
-DIRS=\
-       user
diff --git a/tools/mst/user/SOURCES b/tools/mst/user/SOURCES
deleted file mode 100644 (file)
index 90387f9..0000000
+++ /dev/null
@@ -1,40 +0,0 @@
-TARGETNAME=mst\r
-TARGETTYPE=PROGRAM\r
-UMTYPE=console\r
-USE_MSVCRT=1\r
-\r
-!if !defined(WINIBHOME)\r
-WINIBHOME=..\..\..\r
-!endif\r
-\r
-TARGETPATH=$(WINIBHOME)\bin\user\obj$(BUILD_ALT_DIR)\r
-\r
-\r
-\r
-SOURCES=mst.c \\r
-        mst.rc\r
-\r
-\r
-INCLUDES= $(WINIBHOME)\inc;                    \\r
-          $(WINIBHOME)\inc\user;               \\r
-         $(WINIBHOME)\inc\iba;                \\r
-          $(WINIBHOME)\tools\mtcr\user;\r
-\r
-TARGETLIBS= \\r
-!if $(FREEBUILD)\r
-                       $(TARGETPATH)\*\mtcr.lib\r
-!else\r
-                       $(TARGETPATH)\*\mtcr.lib\r
-!endif\r
-\r
-!if $(FREEBUILD)\r
-\r
-!else\r
-C_DEFINES=$(C_DEFINES) -DDEBUG\r
-!endif\r
-\r
-C_DEFINES=$(C_DEFINES) -D__WIN__\r
-\r
-386_STDCALL=0\r
-\r
-\r
diff --git a/tools/mst/user/makefile b/tools/mst/user/makefile
deleted file mode 100644 (file)
index 80d407b..0000000
+++ /dev/null
@@ -1,8 +0,0 @@
-#\r
-# DO NOT EDIT THIS FILE!!!  Edit .\sources. if you want to add a new source\r
-# file to this component.  This file merely indirects to the real make file\r
-# that is shared by all the driver components of the Windows NT DDK\r
-#\r
-\r
-!INCLUDE ..\..\..\inc\openib.def\r
-\r
diff --git a/tools/mst/user/mst.c b/tools/mst/user/mst.c
deleted file mode 100644 (file)
index 41a4260..0000000
+++ /dev/null
@@ -1,46 +0,0 @@
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
-#include "mtcr.h"
-
-void usage(const char *n)
-{
-    printf("%s: List available mst devices.\nUsage: %s status\n", n, n);
-    exit(1);
-}
-
-int list_devices() {
-    char buff[1024];
-    int devs;
-    int i;
-    char* p = buff;
-    devs = mdevices(buff, sizeof(buff), 0xffffffff);
-    
-    if (devs < 0) {
-        printf("-E- Error getting devices\n");
-        return 0;
-    }
-
-    printf("Found %d devices:\n", devs);
-
-    for (i = 0; i < devs ; i++) {
-        printf("  %s\n", p);
-        p += strlen(p) + 1;
-    }
-    return 1;
-}
-
-int __cdecl main(int ac, char *av[])
-{
-
-    if (ac != 2 || strcmp(av[1],"status")) {
-        usage(av[0]);
-    }
-
-    if (!list_devices())
-           return 1;
-
-    return 0;
-}
-
diff --git a/tools/mst/user/mst.rc b/tools/mst/user/mst.rc
deleted file mode 100644 (file)
index 93b7884..0000000
+++ /dev/null
@@ -1,47 +0,0 @@
-/*\r
- * Copyright (c) 2005 Mellanox Technologies.  All rights reserved.\r
- *\r
- * This software is available to you under the OpenIB.org BSD license\r
- * below:\r
- *\r
- *     Redistribution and use in source and binary forms, with or\r
- *     without modification, are permitted provided that the following\r
- *     conditions are met:\r
- *\r
- *      - Redistributions of source code must retain the above\r
- *        copyright notice, this list of conditions and the following\r
- *        disclaimer.\r
- *\r
- *      - Redistributions in binary form must reproduce the above\r
- *        copyright notice, this list of conditions and the following\r
- *        disclaimer in the documentation and/or other materials\r
- *        provided with the distribution.\r
- *\r
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,\r
- * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\r
- * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND\r
- * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS\r
- * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN\r
- * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN\r
- * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\r
- * SOFTWARE.\r
- *\r
- * $Id$\r
- */\r
-\r
-\r
-#include <oib_ver.h>\r
-\r
-#define VER_FILETYPE                           VFT_APP\r
-#define VER_FILESUBTYPE                                VFT2_UNKNOWN\r
-\r
-#if DBG\r
-#define VER_FILEDESCRIPTION_STR                "Mellanox HW access device listing. (Debug)"\r
-#else\r
-#define VER_FILEDESCRIPTION_STR                "Mellanox HW access device listing."\r
-#endif\r
-\r
-#define VER_INTERNALNAME_STR           "mst.exe"\r
-#define VER_ORIGINALFILENAME_STR       "mst.exe"\r
-\r
-#include <common.ver>\r
diff --git a/tools/mtcr/dirs b/tools/mtcr/dirs
deleted file mode 100644 (file)
index 5a7e8b3..0000000
+++ /dev/null
@@ -1,2 +0,0 @@
-DIRS=\
-       user
diff --git a/tools/mtcr/user/SOURCES b/tools/mtcr/user/SOURCES
deleted file mode 100644 (file)
index d02d3cc..0000000
+++ /dev/null
@@ -1,86 +0,0 @@
-#\r
-# Name: sources\r
-#\r
-# Purpose:\r
-#      Building MTCR for this platform (user space)\r
-#\r
-\r
-TARGETTYPE=DYNLINK\r
-TARGETNAME=mtcr\r
-DLLENTRY=_DllMainCRTStartup\r
-DLLDEF=mtcr.def\r
-USE_MSVCRT=1\r
-\r
-!if !defined(WINIBHOME)\r
-WINIBHOME=..\..\..\r
-!endif\r
-\r
-LIBPATH=$(WINIBHOME)\bin\user\obj$(BUILD_ALT_DIR)\r
-\r
-TARGETPATH=$(WINIBHOME)\bin\user\obj$(BUILD_ALT_DIR)\r
-\r
-\r
-INCLUDES= $(WINIBHOME)\inc;                    \\r
-          $(WINIBHOME)\inc\user;               \\r
-         $(WINIBHOME)\inc\iba;                \\r
-         $(WINIBHOME)\inc\mthca;                \\r
-         .\usb;\r
-         \r
-\r
-SOURCES= \\r
-       mtcr.rc \\r
-       mtcr_i2c.c \\r
-       mtcr.c \\r
-       usb.cpp\r
\r
-\r
-TARGETLIBS= \\r
-!if $(FREEBUILD)\r
-                       $(TARGETPATH)\*\complib.lib \\r
-                       $(TARGETPATH)\*\ibal.lib\\r
-                       $(SDK_LIB_PATH)\Kernel32.lib\\r
-!else\r
-                       $(TARGETPATH)\*\complibd.lib\\r
-                       $(TARGETPATH)\*\ibald.lib\\r
-                       $(SDK_LIB_PATH)\Ws2_32.lib\\r
-                       $(SDK_LIB_PATH)\Kernel32.lib\\r
-\r
-!endif\r
-\r
-\r
-# dimax driver not provided for 64 bits arch.\r
-MTCR_NO_USB=1\r
-\r
-\r
-!if "$(_BUILDARCH)" == "x86" && !defined (MTCR_NO_USB)\r
-TARGETLIBS=$(TARGETLIBS)\\r
-       .\usb\usbi2cio.lib \\r
-       .\usb\I2cBrdg.lib\r
-       \r
-C_DEFINES=$(C_DEFINES) -DMTCR_USB_SUPPORT\r
-!endif\r
-\r
-\r
-\r
-\r
-# TODO:Should I define the __WIN__ manually\r
-C_DEFINES=$(C_DEFINES) /DMTCR_EXPORTS /DMTL_MODULE=MTCR -D__WIN__ \r
-\r
-\r
-!if $(FREEBUILD)\r
-\r
-!else\r
-C_DEFINES=$(C_DEFINES) -DDEBUG -DDBG\r
-!endif\r
-\r
-\r
-# This is for the perl and zlib lib funcs, which requires __cdecl.\r
-# TODO: define for all arch. check if MSC_STDCALL works.\r
-386_STDCALL=0\r
-amd64_STDCALL=0\r
-\r
-MSC_WARNING_LEVEL= /W3\r
-\r
-#BUILD_CONSUMES=mlxsys\r
-BUILD_PRODUCES=mtcr\r
-\r
diff --git a/tools/mtcr/user/com_def.h b/tools/mtcr/user/com_def.h
deleted file mode 100644 (file)
index ff50335..0000000
+++ /dev/null
@@ -1,206 +0,0 @@
-/*
- * Copyright (c) 2005 SilverStorm Technologies.  All rights reserved.
- * Copyright (c) 2004-2005 Mellanox Technologies, Inc. All rights reserved. 
- *
- * This software is available to you under the OpenIB.org BSD license
- * below:
- *
- *     Redistribution and use in source and binary forms, with or
- *     without modification, are permitted provided that the following
- *     conditions are met:
- *
- *      - Redistributions of source code must retain the above
- *        copyright notice, this list of conditions and the following
- *        disclaimer.
- *
- *      - Redistributions in binary form must reproduce the above
- *        copyright notice, this list of conditions and the following
- *        disclaimer in the documentation and/or other materials
- *        provided with the distribution.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
- * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
- * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
- * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
- * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
- * 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$
- */
-
-#ifndef COM_DEF_H
-#define COM_DEF_H
-
-#include <io.h>
-#include <windows.h>
-
-
-#include <windows.h>
-
-// TODO: reference additional headers your program requires here
-#include <stdio.h>
-#include <stdlib.h>
-
-
-//-----------------------------------------------------
-// DEBUG PRINTS
-//-----------------------------------------------------
-
-#define DEBUG_LEVEL_HIGH       5
-#define DEBUG_LEVEL_MID                3
-#define DEBUG_LEVEL_LOW                1
-#define DEBUG_LEVEL_ALWAYS     0
-
-
-#ifdef __cplusplus
-#define EXTERN_VAR extern "C"
-#else
-#define EXTERN_VAR extern
-#endif 
-
-EXTERN_VAR ULONG g_DebugLevel;
-
-//
-// HACK: For this revision, allow debug prng (up to level 3) also for non debug build
-//
-
-//#ifdef DBG
-#define DEBUG_PRINT_ON 1
-//#else
-// to see the prints - uncomment the next line and set level to DEBUG_LEVEL_MID
-//#define DEBUG_PRINT_ON       1
-//#endif
-
-#ifdef DEBUG_PRINT_ON
-
-    #include <stdio.h>
-    #define M_DEBUG(args)        do { printf("-D- "); printf args ;} while(0)
-    #define M_DEBUGS(args, stat) do { printf("-D- "); printf ("stat:%#x:%s: ", stat, ib_get_err_str(stat)); printf args ;} while(0)
-
-    #define DBG_PRINT(lvl, params ) \
-               if (g_DebugLevel >= lvl) { M_DEBUG (params); }
-
-    #define DBG_PRINTS(lvl, params, stat ) \
-               if (g_DebugLevel >= lvl) { M_DEBUGS (params, stat); }
-
-#else
-    #define DBG_PRINT(lvl, params ) 
-    #define M_DEBUG(args)
-    #define M_DEBUGS(args, stat)
-    #define DBG_PRINTS(lvl, params, stat )
-#endif
-
-
-#define DPRINT0(params)        DBG_PRINT(DEBUG_LEVEL_ALWAYS, params)
-#define DPRINT1(params)        DBG_PRINT(DEBUG_LEVEL_LOW, params)
-#define DPRINT3(params)        DBG_PRINT(DEBUG_LEVEL_MID, params)
-
-#ifdef DBG
-#define DPRINT5(params)        DBG_PRINT(DEBUG_LEVEL_HIGH, params)
-#else 
-#define DPRINT5(params)
-#endif
-
-#define DPRINTS1(params, stat)         DBG_PRINTS(DEBUG_LEVEL_LOW, params, stat)
-
-
-/*
- * Errors
- */
-#include <errno.h>
-
-  /****************** General Purpose Error Codes (0 to -999) *****************/
-
-#define ERROR_LIST_GENERAL \
-  INFO( MT_OK,          0,      "success" ) \
-  INFO( MT_ERROR,       -1,     "generic error" ) \
-  INFO( MT_ENOINIT,     -2,     "module not initialized" ) \
-  INFO( MT_EINVAL,      -3,     "invalid argument" ) \
-  INFO( MT_ENORSC,      -4,     "No such resource (probably out of range)" ) \
-  INFO( MT_EPERM,       -5,     "Not enough permissions to perform operation" ) \
-  INFO( MT_ENOSYS,      -6,     "The system doesn't support requested operation" ) \
-  INFO( MT_EAGAIN,      -7,     "Resource temporarily unavailable" ) \
-  INFO( MT_EALIGN,      -8,     "Alignment error (offset/size not aligned)" ) \
-  INFO( MT_EDEADLK,     -9,     "Resource deadlock avoided" ) \
-  INFO( MT_ENOENT,     -10,     "No such file or directory" ) \
-  INFO( MT_EACCES,     -11,     "Permission denied" ) \
-  INFO( MT_EINTR,      -12,     "process received interrupt") \
-  INFO( MT_ESTATE,     -13,     "Invalid state") \
-  INFO( MT_ENOMOD,     -ENOSYS, "module not loaded") /* When module not loaded, syscall return ENOSYS */
-
-  /**************** Memory Handling Error Codes (-1000 to -1199) **************/
-
-
-#define ERROR_LIST_MEMORY \
-  INFO( MT_EKMALLOC,    -1000,  "Can't allocate kernel memory" ) \
-  INFO( MT_ENOMEM,      -1001,  "Given address doesn't match process address space" ) \
-  INFO( MT_EMALLOC,     -1002,  "malloc fail") \
-  INFO( MT_EFAULT,      -1003,  "Bad address" )
-
-  /****************** General Device Error Codes (-1200 to -1399) *************/
-
-#define ERROR_LIST_DEVICE \
-  INFO( MT_ENODEV,      -1200,  "No such device" ) \
-  INFO( MT_EBUSY,       -1201,  "Device or resource busy (or used by another)" ) \
-  INFO( MT_EBUSBUSY,    -1202,  "Bus busy" )
-
-  /*********************** I2C Error Codes (-1400 to -1499) *******************/
-
-#define ERROR_LIST_I2C \
-  INFO( MT_EI2CNACK,    -1400,   "I2C: received NACK from slave" ) \
-  INFO( MT_EI2PINHI,    -1401,   "I2C: Pending Interrupt Not does no become low" ) \
-  INFO( MT_EI2TOUT,     -1402,   "I2C: Operation has been timed out" )  
-#define ERROR_LIST      ERROR_LIST_GENERAL ERROR_LIST_MEMORY ERROR_LIST_DEVICE ERROR_LIST_I2C
-
-  /** 
-   **   See at end of file the full list of POSIX errors
-   **/
-
-
-typedef enum {
-#define INFO(A,B,C)     A = B,
-        ERROR_LIST
-#undef INFO
-           MT_DUMMY_ERROR   /* this one is needed to quite warning by -pedantic */
-} call_result_t;
-/*
- * Different names
- */
-#define sys_errlist _sys_errlist
-
-/*
- * Types
- */
-
-/*
- * Endianess
- */
-#define __be32_to_cpu __cpu_to_be32
-
-#ifdef _WIN64
-#define __cpu_to_be32(x) ((((x) >> 24)&0x000000ff) | (((x) >> 8)&0x0000ff00) | (((x) << 8)&0x00ff0000) | (((x) << 24)&0xff000000))
-#elif defined(_WIN32)
-__inline __int32 __cpu_to_be32( __int32 dwX ) 
-{ 
-    _asm    mov     eax, dwX     
-    _asm    bswap   eax     
-    _asm    mov     dwX, eax   
-        
-    return dwX; 
-}
-#else
-#error unsupported platform
-#endif
-
-#define __be16_to_cpu __cpu_to_be16
-#define __cpu_to_be16(x) ((((x) >> 8)&0xff) | (((x) << 8)&0xff00))
-
-/*
- * usleep
- */
-_inline void usleep( unsigned long x) { Sleep((x + 999) / 1000); }
-
-#endif
diff --git a/tools/mtcr/user/makefile b/tools/mtcr/user/makefile
deleted file mode 100644 (file)
index 80d407b..0000000
+++ /dev/null
@@ -1,8 +0,0 @@
-#\r
-# DO NOT EDIT THIS FILE!!!  Edit .\sources. if you want to add a new source\r
-# file to this component.  This file merely indirects to the real make file\r
-# that is shared by all the driver components of the Windows NT DDK\r
-#\r
-\r
-!INCLUDE ..\..\..\inc\openib.def\r
-\r
diff --git a/tools/mtcr/user/mtcr.c b/tools/mtcr/user/mtcr.c
deleted file mode 100644 (file)
index dd808f4..0000000
+++ /dev/null
@@ -1,1222 +0,0 @@
-// mtcr.c : Defines the entry point for the DLL application.\r
-//\r
-#include <stdlib.h>\r
-#include <errno.h>\r
-#include <ib_types.h>\r
-#include <ib_al.h>\r
-\r
-\r
-#include "com_def.h"\r
-#include "usb.h"\r
-#include "mtcr.h"\r
-#include "mtcr_i2c.h"\r
-#include "mthca_vc.h"\r
-\r
-//-----------------------------------------------------\r
-// NEW FEATURES\r
-//-----------------------------------------------------\r
-#define FIX_NAME                        1\r
-#define SUPPORT_I2CM            1\r
-\r
-#define USB_DEV_NAME    "mtusb-1"\r
-#define CLEAR(st)               memset(&(st), 0, sizeof(st))\r
-\r
-// HERMON ORDERING WA:\r
-#define HERMON_WA_BASE 0xf0384 // SEM BASE ADDR. SEM 0xf0380 is reserved for external tools usage.\r
-#define HERMON_WA_SIZE 3       // Size in entries\r
-\r
-#define MTCR_DEBUG_ENV "MTCR_DEBUG_LEVEL"\r
-\r
-/* \r
- * DLL global variables \r
- */\r
-#pragma data_seg(".sdata")\r
-\r
-/* Process / thread count */\r
-DWORD g_Slots[HERMON_WA_SIZE]; /* 3 slots */\r
-\r
-#ifdef DBG\r
-ULONG g_DebugLevel = DEBUG_LEVEL_MID;\r
-#else\r
-ULONG g_DebugLevel = DEBUG_LEVEL_LOW;\r
-#endif\r
-\r
-#pragma data_seg()\r
-\r
-\r
-//-----------------------------------------------------\r
-\r
-#define MAX_HCA_NUM 16\r
-\r
-// flags in below structure\r
-#define FIX_ORDERING_BUG       1\r
-\r
-typedef struct mfile_ibal_t {\r
-    mfile            s;\r
-    ib_al_handle_t   h_al;      \r
-    ib_ca_handle_t   h_ca;\r
-    map_crspace      cr_map;\r
-\r
-    int                  bugs;\r
-    int                  slot_num;\r
-    u_int32_t    hermon_wa_slot; /* apply hermon cr write workaround */\r
-    int                  hermon_wa_last_op_write;\r
-    u_int64_t    hermon_wa_max_retries;\r
-    u_int64_t    hermon_wa_num_of_writes;\r
-    u_int64_t    hermon_wa_num_of_retry_writes;\r
-} mfile_ibal;\r
-\r
-\r
-// Return slot_num or -1 when no free slots \r
-static int __get_slot()\r
-{\r
-       int i, prev_val;\r
-\r
-       for (i = 0; i < HERMON_WA_SIZE; ++i) {\r
-               prev_val = InterlockedCompareExchange(\r
-                       (LONG volatile* )&g_Slots[i], 0, 1 );\r
-               if ( prev_val ) \r
-                       return i;\r
-       }\r
-       return -1;\r
-}\r
-\r
-static void __put_slot(int slot_num)\r
-{\r
-       int prev_val;\r
-       prev_val = InterlockedExchange(\r
-               (LONG volatile* )&g_Slots[slot_num], 1 );\r
-       if ( !prev_val ) \r
-               DPRINT1(("Wrong semaphore %d value \n", slot_num));\r
-       \r
-}\r
-\r
-BOOL APIENTRY DllMain( HANDLE hModule,\r
-                       DWORD  ul_reason_for_call,\r
-                       LPVOID lpReserved\r
-                                         )\r
-{\r
-    int i;\r
-    char* pszDbgLevel;\r
-    switch (ul_reason_for_call)\r
-    {\r
-    case DLL_PROCESS_ATTACH:\r
-        // s_hCtl = (HANDLE)-1;\r
-        // ConnectToDriver();\r
-        g_DebugLevel = 0;\r
-        pszDbgLevel = getenv(MTCR_DEBUG_ENV);\r
-        if (pszDbgLevel) {\r
-            g_DebugLevel = atol(pszDbgLevel);\r
-        }\r
-               // set slot data\r
-               for (i = 0; i < HERMON_WA_SIZE; ++i)\r
-                       g_Slots[i] = 1;\r
-\r
-        break;\r
-        \r
-    case DLL_PROCESS_DETACH:\r
-        // DisconnectFromDriver();\r
-        break;\r
-        \r
-    case DLL_THREAD_ATTACH:\r
-    case DLL_THREAD_DETACH:\r
-        break;\r
-    }\r
-    return TRUE;\r
-}\r
-\r
-// device ids\r
-#define DEVASYS_DEV_ID                                  12345   /* dummy */\r
-#define TAVOR_DEV_ID                                    23108\r
-#define TAVOR_CONF_DEV_ID                               23109\r
-#define ARBEL_TM_DEV_ID                                 25208\r
-#define ARBEL_TM_CONF_DEV_ID                            25209\r
-#define ARBEL_DEV_ID                                    25218\r
-#define ARBEL_CONF_DEV_ID                               25219\r
-#define SINAI_4X_DEV_ID                                 24204\r
-#define SINAI_4X_CONF_DEV_ID                            24205\r
-#define SINAI_8X_DEV_ID                                 25204\r
-#define SINAI_8X_CONF_DEV_ID                            25205\r
-#define HERMON_SDR_DEV_ID                               25408\r
-#define HERMON_DDR_DEV_ID                               25418\r
-#define HERMON_QDR_DEV_ID                               25428\r
-#define HERMON_DDR_PCI5_DEV_ID                          26418\r
-#define HERMON_QDR_PCI5_DEV_ID                          26428\r
-#define HERMON_CONF_DEV_ID                              401\r
-\r
-#define IS_CONF_DEV(dev_id)     \\r
-               ((dev_id == TAVOR_CONF_DEV_ID)    || \\r
-               (dev_id == ARBEL_TM_CONF_DEV_ID) || \\r
-               (dev_id == ARBEL_CONF_DEV_ID)    || \\r
-               (dev_id == SINAI_4X_CONF_DEV_ID) || \\r
-               (dev_id == SINAI_8X_CONF_DEV_ID) || \\r
-               (dev_id == HERMON_CONF_DEV_ID))\r
-        \r
-#define MAX_DEV_NAME            32\r
-typedef struct {\r
-    USHORT  DevId;                             // Device Id, e.g.      23108                   \r
-    UCHAR   DevName[MAX_DEV_NAME];     // exported name, e.g.  "InfiniHost"\r
-    Mdevs   mask;\r
-} DEVICE_DB_T, *PDEVICE_DB_T;\r
-\r
-\r
-#define TAVOR_TYPE_DEVICE_NAME_FMT      "mt%hu_pci%s%hu"\r
-#define MDT_DEVICE_NAME_FMT             "%s%hu"\r
-\r
-static DEVICE_DB_T db[] = {\r
-        {       DEVASYS_DEV_ID,         "devasys_usb",          MDEVS_TAVOR     },\r
-        {       TAVOR_DEV_ID,           "InfiniHost",           MDEVS_TAVOR     },\r
-        {       TAVOR_CONF_DEV_ID,      "InfiniHostBd",         MDEVS_TAVOR_CR  },\r
-        {       ARBEL_TM_DEV_ID,        "InfiniHost",           MDEVS_TAVOR     },\r
-        {       ARBEL_TM_CONF_DEV_ID,   "InfiniHostBd",         MDEVS_TAVOR_CR  },\r
-        {       ARBEL_DEV_ID,           "InfiniHost_III_Ex",    MDEVS_TAVOR     },\r
-        {       ARBEL_CONF_DEV_ID,      "InfiniHostBd",         MDEVS_TAVOR_CR  },\r
-        {       SINAI_4X_DEV_ID,        "InfiniHost_III_Lx",    MDEVS_TAVOR     },\r
-        {       SINAI_4X_CONF_DEV_ID,   "InfiniHostBd",         MDEVS_TAVOR_CR  },\r
-        {       SINAI_8X_DEV_ID,        "InfiniHost_III_Lx",    MDEVS_TAVOR     },\r
-        {       SINAI_8X_CONF_DEV_ID,  "InfiniHostBd",                 MDEVS_TAVOR_CR  },\r
-\r
-                       {       HERMON_SDR_DEV_ID,      "ConnectX",             MDEVS_TAVOR_CR  },\r
-                       {       HERMON_DDR_DEV_ID,      "ConnectX",             MDEVS_TAVOR_CR  },\r
-                       {       HERMON_QDR_DEV_ID,      "ConnectX",             MDEVS_TAVOR_CR  },\r
-                       {       HERMON_DDR_PCI5_DEV_ID, "ConnectX",             MDEVS_TAVOR_CR  },\r
-                       {       HERMON_QDR_PCI5_DEV_ID, "ConnectX",             MDEVS_TAVOR_CR  },\r
-                       \r
-                       {       HERMON_CONF_DEV_ID, "ConnectXBd",               MDEVS_TAVOR_CR  },\r
-};\r
-#define DEVICE_DB_SIZE  (sizeof(db) / sizeof(DEVICE_DB_T))\r
-\r
-Mdevs dmasks[] = { MDEVS_TAVOR_CR, MDEVS_TAVOR_CR, MDEVS_TAVOR_UAR, MDEVS_TAVOR_DDR };\r
-char *dsuffix[] = { "conf", "_cr", "_uar", "_ddr"};\r
-#define MASKS_SIZE      (sizeof(dmasks) / sizeof(Mdevs))\r
-\r
-static int is_hermon(USHORT dev_id)\r
-{\r
-       return (dev_id == HERMON_SDR_DEV_ID) ||\r
-               (dev_id == HERMON_DDR_DEV_ID) ||\r
-               (dev_id == HERMON_QDR_DEV_ID) ||\r
-               (dev_id == HERMON_DDR_PCI5_DEV_ID) ||\r
-               (dev_id == HERMON_QDR_PCI5_DEV_ID);\r
-}\r
-\r
-// Return: < 0 - Error.   > 0 - Numbern of characters written (including last '\0')\r
-int create_mst_names_by_dev_id(USHORT dev_id, int dev_ix, int mask, char *name, int name_len, int *cnt)\r
-{\r
-    int i,j; char *suffix; BOOL found = FALSE; char *nm_ptr = name;\r
-    int tot_len = 0;\r
-\r
-    DPRINT3(( "create_mst_names_by_dev_id: dev_id %d, dev_ix %d, mask %#x, name_len %d\n", \r
-        &nb