ID: 46 - ipmi_fwum needs some re-work

Finish off formatting, remove useless comments

Commit finishes off formatting changes and removes useless, out-of-date,
comments.
This commit is contained in:
Zdenek Styblik 2013-10-26 19:18:01 +00:00
parent 5bf68a4769
commit 24923222f6

View File

@ -19,7 +19,7 @@
* contributors may be used to endorse or promote products derived * contributors may be used to endorse or promote products derived
* from this software without specific prior written permission. * from this software without specific prior written permission.
* *
* This software is provided "AS IS," without a warranty of any kind. * This software is provided "AS IS," without a warranty of any kind.
* ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES,
* INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A
* PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED.
@ -33,7 +33,6 @@
* EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. * EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
*/ */
#include <string.h> #include <string.h>
#include <math.h> #include <math.h>
#include <time.h> #include <time.h>
@ -46,98 +45,92 @@
#include <ipmitool/ipmi_intf.h> #include <ipmitool/ipmi_intf.h>
#include <ipmitool/ipmi_mc.h> #include <ipmitool/ipmi_mc.h>
/******************************************************************************
* HISTORY
* ===========================================================================
* 2007-01-11 [FI]
* - Incremented to version 1.3
* - Added lan packet size reduction mechanism to workaround fact
* that lan iface will not return C7 on excessive length
*
*****************************************************************************/
#define VERSION_MAJ 1 #define VERSION_MAJ 1
#define VERSION_MIN 3 #define VERSION_MIN 3
typedef enum eKFWUM_Task typedef enum eKFWUM_Task
{ {
KFWUM_TASK_INFO, KFWUM_TASK_INFO,
KFWUM_TASK_STATUS, KFWUM_TASK_STATUS,
KFWUM_TASK_DOWNLOAD, KFWUM_TASK_DOWNLOAD,
KFWUM_TASK_UPGRADE, KFWUM_TASK_UPGRADE,
KFWUM_TASK_START_UPGRADE, KFWUM_TASK_START_UPGRADE,
KFWUM_TASK_ROLLBACK, KFWUM_TASK_ROLLBACK,
KFWUM_TASK_TRACELOG KFWUM_TASK_TRACELOG
}tKFWUM_Task; } tKFWUM_Task;
typedef enum eKFWUM_BoardList typedef enum eKFWUM_BoardList
{ {
KFWUM_BOARD_KONTRON_UNKNOWN = 0, KFWUM_BOARD_KONTRON_UNKNOWN = 0,
KFWUM_BOARD_KONTRON_5002 = 5002, KFWUM_BOARD_KONTRON_5002 = 5002,
}tKFWUM_BoardList; } tKFWUM_BoardList;
typedef enum eKFWUM_IanaList typedef enum eKFWUM_IanaList
{ {
KFWUM_IANA_KONTRON = 15000, KFWUM_IANA_KONTRON = 15000,
}tKFWUM_IanaList; } tKFWUM_IanaList;
typedef struct sKFWUM_BoardInfo typedef struct sKFWUM_BoardInfo
{ {
tKFWUM_BoardList boardId; tKFWUM_BoardList boardId;
tKFWUM_IanaList iana; tKFWUM_IanaList iana;
}tKFWUM_BoardInfo; } tKFWUM_BoardInfo;
typedef enum eKFWUM_Status typedef enum eKFWUM_Status
{ {
KFWUM_STATUS_OK, KFWUM_STATUS_OK,
KFWUM_STATUS_ERROR KFWUM_STATUS_ERROR
}tKFWUM_Status; } tKFWUM_Status;
typedef enum eKFWUM_DownloadType typedef enum eKFWUM_DownloadType
{ {
KFWUM_DOWNLOAD_TYPE_ADDRESS = 0, KFWUM_DOWNLOAD_TYPE_ADDRESS = 0,
KFWUM_DOWNLOAD_TYPE_SEQUENCE, KFWUM_DOWNLOAD_TYPE_SEQUENCE,
}tKFWUM_DownloadType; } tKFWUM_DownloadType;
typedef enum eKFWUM_DownloadBuffferType typedef enum eKFWUM_DownloadBuffferType
{ {
KFWUM_SMALL_BUFFER_TYPE = 0, KFWUM_SMALL_BUFFER_TYPE = 0,
KFUMW_BIG_BUFFER_TYPE KFUMW_BIG_BUFFER_TYPE
}tKFWUM_DownloadBuffferType; } tKFWUM_DownloadBuffferType;
typedef struct sKFWUM_InFirmwareInfo typedef struct sKFWUM_InFirmwareInfo
{ {
unsigned long fileSize; unsigned long fileSize;
unsigned short checksum; unsigned short checksum;
unsigned short sumToRemoveFromChecksum; unsigned short sumToRemoveFromChecksum;
/* Since the checksum is added in the bin /* Since the checksum is added in the bin
after the checksum is calculated, we * after the checksum is calculated, we
need to remove the each byte value. This * need to remove the each byte value. This
byte will contain the addition of both bytes*/ * byte will contain the addition of both bytes
tKFWUM_BoardList boardId; */
unsigned char deviceId; tKFWUM_BoardList boardId;
unsigned char tableVers; unsigned char deviceId;
unsigned char implRev; unsigned char tableVers;
unsigned char versMajor; unsigned char implRev;
unsigned char versMinor; unsigned char versMajor;
unsigned char versSubMinor; unsigned char versMinor;
unsigned char sdrRev; unsigned char versSubMinor;
tKFWUM_IanaList iana; unsigned char sdrRev;
}tKFWUM_InFirmwareInfo; tKFWUM_IanaList iana;
} tKFWUM_InFirmwareInfo;
typedef struct sKFWUM_SaveFirmwareInfo typedef struct sKFWUM_SaveFirmwareInfo
{ {
tKFWUM_DownloadType downloadType; tKFWUM_DownloadType downloadType;
unsigned char bufferSize; unsigned char bufferSize;
unsigned char overheadSize; unsigned char overheadSize;
}tKFWUM_SaveFirmwareInfo; } tKFWUM_SaveFirmwareInfo;
#define KFWUM_SMALL_BUFFER 32 /* Minimum size (IPMB/IOL/old protocol) */ /* Minimum size (IPMB/IOL/old protocol) */
#define KFWUM_BIG_BUFFER 32 /* Maximum size on KCS interface */ #define KFWUM_SMALL_BUFFER 32
/* Maximum size on KCS interface */
#define KFWUM_BIG_BUFFER 32
#define KFWUM_OLD_CMD_OVERHEAD 6 /*3 address + 1 size + 1 checksum + 1 command*/ /* 3 address + 1 size + 1 checksum + 1 command */
#define KFWUM_NEW_CMD_OVERHEAD 4 /*1 sequence+ 1 size + 1 checksum + 1 command*/ #define KFWUM_OLD_CMD_OVERHEAD 6
/* 1 sequence + 1 size + 1 checksum + 1 command */
#define KFWUM_NEW_CMD_OVERHEAD 4
#define KFWUM_PAGE_SIZE 256 #define KFWUM_PAGE_SIZE 256
extern int verbose; extern int verbose;
@ -146,56 +139,51 @@ static unsigned char firmBuf[1024*512];
static tKFWUM_SaveFirmwareInfo saveFirmwareInfo; static tKFWUM_SaveFirmwareInfo saveFirmwareInfo;
void printf_kfwum_help(void); void printf_kfwum_help(void);
static void KfwumMain(struct ipmi_intf * intf, tKFWUM_Task task); static void KfwumMain(struct ipmi_intf *intf, tKFWUM_Task task);
static tKFWUM_Status KfwumGetFileSize(unsigned char * pFileName, static tKFWUM_Status KfwumGetFileSize(unsigned char *pFileName,
unsigned long * pFileSize); unsigned long *pFileSize);
static tKFWUM_Status KfwumSetupBuffersFromFile(unsigned char * pFileName, static tKFWUM_Status KfwumSetupBuffersFromFile(unsigned char *pFileName,
unsigned long fileSize); unsigned long fileSize);
void KfwumShowProgress(const char *task, unsigned long current, void KfwumShowProgress(const char *task, unsigned long current,
unsigned long total); unsigned long total);
static unsigned short KfwumCalculateChecksumPadding(unsigned char * pBuffer, static unsigned short KfwumCalculateChecksumPadding(unsigned char *pBuffer,
unsigned long totalSize); unsigned long totalSize);
static tKFWUM_Status KfwumGetInfo(struct ipmi_intf *intf, unsigned char output,
unsigned char *pNumBank);
static tKFWUM_Status KfwumGetInfo(struct ipmi_intf * intf, unsigned char output, static tKFWUM_Status KfwumGetDeviceInfo(struct ipmi_intf *intf,
unsigned char *pNumBank); unsigned char output, tKFWUM_BoardInfo *pBoardInfo);
static tKFWUM_Status KfwumGetDeviceInfo(struct ipmi_intf * intf, static tKFWUM_Status KfwumGetStatus(struct ipmi_intf *intf);
unsigned char output, tKFWUM_BoardInfo * pBoardInfo); static tKFWUM_Status KfwumManualRollback(struct ipmi_intf *intf);
static tKFWUM_Status KfwumGetStatus(struct ipmi_intf * intf); static tKFWUM_Status KfwumStartFirmwareImage(struct ipmi_intf *intf,
static tKFWUM_Status KfwumManualRollback(struct ipmi_intf * intf); unsigned long length, unsigned short padding);
static tKFWUM_Status KfwumStartFirmwareImage(struct ipmi_intf * intf, static tKFWUM_Status KfwumSaveFirmwareImage(struct ipmi_intf *intf,
unsigned long length,unsigned short padding); unsigned char sequenceNumber, unsigned long address,
static tKFWUM_Status KfwumSaveFirmwareImage(struct ipmi_intf * intf, unsigned char *pFirmBuf, unsigned char *pInBufLength);
unsigned char sequenceNumber, unsigned long address, static tKFWUM_Status KfwumFinishFirmwareImage(struct ipmi_intf *intf,
unsigned char *pFirmBuf, unsigned char * pInBufLength); tKFWUM_InFirmwareInfo firmInfo);
static tKFWUM_Status KfwumFinishFirmwareImage(struct ipmi_intf * intf, static tKFWUM_Status KfwumUploadFirmware(struct ipmi_intf *intf,
tKFWUM_InFirmwareInfo firmInfo); unsigned char *pBuffer, unsigned long totalSize);
static tKFWUM_Status KfwumUploadFirmware(struct ipmi_intf * intf, static tKFWUM_Status KfwumStartFirmwareUpgrade(struct ipmi_intf *intf);
unsigned char * pBuffer, unsigned long totalSize); static tKFWUM_Status KfwumGetInfoFromFirmware(unsigned char *pBuf,
static tKFWUM_Status KfwumStartFirmwareUpgrade(struct ipmi_intf * intf); unsigned long bufSize, tKFWUM_InFirmwareInfo *pInfo);
static void KfwumFixTableVersionForOldFirmware(tKFWUM_InFirmwareInfo *pInfo);
static tKFWUM_Status KfwumGetInfoFromFirmware(unsigned char * pBuf, static tKFWUM_Status KfwumGetTraceLog(struct ipmi_intf *intf);
unsigned long bufSize, tKFWUM_InFirmwareInfo * pInfo);
static void KfwumFixTableVersionForOldFirmware(tKFWUM_InFirmwareInfo * pInfo);
static tKFWUM_Status KfwumGetTraceLog(struct ipmi_intf * intf);
tKFWUM_Status ipmi_kfwum_checkfwcompat(tKFWUM_BoardInfo boardInfo, tKFWUM_Status ipmi_kfwum_checkfwcompat(tKFWUM_BoardInfo boardInfo,
tKFWUM_InFirmwareInfo firmInfo); tKFWUM_InFirmwareInfo firmInfo);
void printf_kfwum_info(tKFWUM_BoardInfo boardInfo, void printf_kfwum_info(tKFWUM_BoardInfo boardInfo,
tKFWUM_InFirmwareInfo firmInfo); tKFWUM_InFirmwareInfo firmInfo);
/* ipmi_fwum_main - entry point for this ipmitool mode /* ipmi_fwum_main - entry point for this ipmitool mode
* *
* @intf: ipmi interface * @intf: ipmi interface
* @arc : number of arguments * @arc: number of arguments
* @argv : point to argument array * @argv: point to argument array
* *
* returns 0 on success * returns 0 on success
* returns -1 on error * returns -1 on error
*/ */
int ipmi_fwum_main(struct ipmi_intf * intf, int argc, char ** argv) int
ipmi_fwum_main(struct ipmi_intf *intf, int argc, char **argv)
{ {
int rc = 0; int rc = 0;
printf("FWUM extension Version %d.%d\n", VERSION_MAJ, VERSION_MIN); printf("FWUM extension Version %d.%d\n", VERSION_MAJ, VERSION_MIN);
@ -252,66 +240,42 @@ int ipmi_fwum_main(struct ipmi_intf * intf, int argc, char ** argv)
return rc; return rc;
} }
void
void printf_kfwum_help(void) printf_kfwum_help(void)
{ {
lprintf(LOG_NOTICE, lprintf(LOG_NOTICE,
"KFWUM Commands: info status download upgrade rollback tracelog"); "KFWUM Commands: info status download upgrade rollback tracelog");
} }
/* private definitions and macros */
/****************************************/
/** private definitions and macros **/
/****************************************/
typedef enum eFWUM_CmdId typedef enum eFWUM_CmdId
{ {
KFWUM_CMD_ID_GET_FIRMWARE_INFO = 0, KFWUM_CMD_ID_GET_FIRMWARE_INFO = 0,
KFWUM_CMD_ID_KICK_IPMC_WATCHDOG = 1, KFWUM_CMD_ID_KICK_IPMC_WATCHDOG = 1,
KFWUM_CMD_ID_GET_LAST_ANSWER = 2, KFWUM_CMD_ID_GET_LAST_ANSWER = 2,
KFWUM_CMD_ID_BOOT_HANDSHAKE = 3, KFWUM_CMD_ID_BOOT_HANDSHAKE = 3,
KFWUM_CMD_ID_REPORT_STATUS = 4, KFWUM_CMD_ID_REPORT_STATUS = 4,
KFWUM_CMD_ID_GET_FIRMWARE_STATUS = 7, KFWUM_CMD_ID_GET_FIRMWARE_STATUS = 7,
KFWUM_CMD_ID_START_FIRMWARE_UPDATE = 9, KFWUM_CMD_ID_START_FIRMWARE_UPDATE = 9,
KFWUM_CMD_ID_START_FIRMWARE_IMAGE = 0x0a, KFWUM_CMD_ID_START_FIRMWARE_IMAGE = 0x0a,
KFWUM_CMD_ID_SAVE_FIRMWARE_IMAGE = 0x0b, KFWUM_CMD_ID_SAVE_FIRMWARE_IMAGE = 0x0b,
KFWUM_CMD_ID_FINISH_FIRMWARE_IMAGE = 0x0c, KFWUM_CMD_ID_FINISH_FIRMWARE_IMAGE = 0x0c,
KFWUM_CMD_ID_READ_FIRMWARE_IMAGE = 0x0d, KFWUM_CMD_ID_READ_FIRMWARE_IMAGE = 0x0d,
KFWUM_CMD_ID_MANUAL_ROLLBACK = 0x0e, KFWUM_CMD_ID_MANUAL_ROLLBACK = 0x0e,
KFWUM_CMD_ID_GET_TRACE_LOG = 0x0f, KFWUM_CMD_ID_GET_TRACE_LOG = 0x0f,
KFWUM_CMD_ID_STD_MAX_CMD, KFWUM_CMD_ID_STD_MAX_CMD,
KFWUM_CMD_ID_EXTENDED_CMD = 0xC0 KFWUM_CMD_ID_EXTENDED_CMD = 0xC0
} tKFWUM_CmdId; } tKFWUM_CmdId;
/* KfwumMain - function implements upload of the firmware data received as
* parameters
/****************************************/ *
/** global/static variables definition **/ * @task: task to do
/****************************************/ *
* returns void
/****************************************/ */
/** functions definition **/ static void
/****************************************/ KfwumMain(struct ipmi_intf *intf, tKFWUM_Task task)
/*******************************************************************************
*
* Function Name: KfwumMain
*
* Description: This function implements the upload of the firware data
* received as parameters.
*
* Restriction: Called only from main
*
* Input: unsigned char * pBuffer[] : The buffers
* unsigned long bufSize : The size of the buffers
*
* Output: None
*
* Global: none
*
* Return: tIFWU_Status (success or failure)
*
*******************************************************************************/
static void KfwumMain(struct ipmi_intf * intf, tKFWUM_Task task)
{ {
tKFWUM_Status status = KFWUM_STATUS_OK; tKFWUM_Status status = KFWUM_STATUS_OK;
tKFWUM_BoardInfo boardInfo; tKFWUM_BoardInfo boardInfo;
@ -398,8 +362,8 @@ static void KfwumMain(struct ipmi_intf * intf, tKFWUM_Task task)
* *
* returns KFWUM_STATUS_OK or KFWUM_STATUS_ERROR * returns KFWUM_STATUS_OK or KFWUM_STATUS_ERROR
*/ */
static tKFWUM_Status KfwumGetFileSize(unsigned char *pFileName, static tKFWUM_Status
unsigned long *pFileSize) KfwumGetFileSize(unsigned char *pFileName, unsigned long *pFileSize)
{ {
FILE *pFileHandle = NULL; FILE *pFileHandle = NULL;
pFileHandle = fopen((const char *)pFileName, "rb"); pFileHandle = fopen((const char *)pFileName, "rb");
@ -424,8 +388,8 @@ static tKFWUM_Status KfwumGetFileSize(unsigned char *pFileName,
* returns KFWUM_STATUS_OK or KFWUM_STATUS_ERROR * returns KFWUM_STATUS_OK or KFWUM_STATUS_ERROR
*/ */
#define MAX_BUFFER_SIZE 1024*16 #define MAX_BUFFER_SIZE 1024*16
static tKFWUM_Status KfwumSetupBuffersFromFile(unsigned char * pFileName, static tKFWUM_Status
unsigned long fileSize) KfwumSetupBuffersFromFile(unsigned char * pFileName, unsigned long fileSize)
{ {
tKFWUM_Status status = KFWUM_STATUS_ERROR; tKFWUM_Status status = KFWUM_STATUS_ERROR;
FILE *pFileHandle = NULL; FILE *pFileHandle = NULL;
@ -443,7 +407,7 @@ static tKFWUM_Status KfwumSetupBuffersFromFile(unsigned char * pFileName,
modulus = fileSize % MAX_BUFFER_SIZE; modulus = fileSize % MAX_BUFFER_SIZE;
rewind(pFileHandle); rewind(pFileHandle);
for (qty=0; qty < count; qty++) { for (qty = 0; qty < count; qty++) {
KfwumShowProgress("Reading Firmware from File", KfwumShowProgress("Reading Firmware from File",
qty, count); qty, count);
if (fread(&firmBuf[qty * MAX_BUFFER_SIZE], 1, if (fread(&firmBuf[qty * MAX_BUFFER_SIZE], 1,
@ -480,8 +444,8 @@ KfwumShowProgress(const char *task, unsigned long current, unsigned long total)
static unsigned long staticProgress=0xffffffff; static unsigned long staticProgress=0xffffffff;
unsigned char spaces[PROG_LENGTH + 1]; unsigned char spaces[PROG_LENGTH + 1];
unsigned short hash; unsigned short hash;
float percent = ((float)current/total); float percent = ((float)current / total);
unsigned long progress = 100*(percent); unsigned long progress = 100 * (percent);
if (staticProgress == progress) { if (staticProgress == progress) {
/* We displayed the same last time.. so don't do it */ /* We displayed the same last time.. so don't do it */
@ -490,7 +454,7 @@ KfwumShowProgress(const char *task, unsigned long current, unsigned long total)
staticProgress = progress; staticProgress = progress;
printf("%-25s : ", task); /* total 20 bytes */ printf("%-25s : ", task); /* total 20 bytes */
hash = (percent * PROG_LENGTH); hash = (percent * PROG_LENGTH);
memset(spaces,'#', hash); memset(spaces, '#', hash);
spaces[hash] = '\0'; spaces[hash] = '\0';
printf("%s", spaces); printf("%s", spaces);
@ -505,64 +469,54 @@ KfwumShowProgress(const char *task, unsigned long current, unsigned long total)
fflush(stdout); fflush(stdout);
} }
/* KfwumCalculateChecksumPadding /* KfwumCalculateChecksumPadding - TBD
*
* TBD
*
*/ */
static unsigned short KfwumCalculateChecksumPadding(unsigned char * pBuffer, static unsigned short
unsigned long totalSize) KfwumCalculateChecksumPadding(unsigned char *pBuffer, unsigned long totalSize)
{ {
unsigned short sumOfBytes = 0; unsigned short sumOfBytes = 0;
unsigned short padding; unsigned short padding;
unsigned long counter; unsigned long counter;
for (counter = 0; counter < totalSize; counter ++) {
for(counter = 0; counter < totalSize; counter ++ ) sumOfBytes += pBuffer[counter];
{ }
sumOfBytes += pBuffer[counter]; padding = 0 - sumOfBytes;
} return padding;
padding = 0 - sumOfBytes;
return padding;
} }
/****************************************************************************** /* COMMANDS */
******************************* COMMANDS **************************************
******************************************************************************/
#ifdef HAVE_PRAGMA_PACK #ifdef HAVE_PRAGMA_PACK
#pragma pack(1) #pragma pack(1)
#endif #endif
struct KfwumGetInfoResp { struct KfwumGetInfoResp {
unsigned char protocolRevision; unsigned char protocolRevision;
unsigned char controllerDeviceId; unsigned char controllerDeviceId;
struct struct {
{ unsigned char mode:1;
unsigned char mode:1; unsigned char seqAdd:1;
unsigned char seqAdd:1; unsigned char res : 6;
unsigned char res : 6; } byte;
} byte; unsigned char firmRev1;
unsigned char firmRev1; unsigned char firmRev2;
unsigned char firmRev2; unsigned char numBank;
unsigned char numBank;
} ATTRIBUTE_PACKING; } ATTRIBUTE_PACKING;
#ifdef HAVE_PRAGMA_PACK #ifdef HAVE_PRAGMA_PACK
#pragma pack(0) #pragma pack(0)
#endif #endif
/* KfwumGetInfo - Get Firmware Update Manager (FWUM) information /* KfwumGetInfo - Get Firmware Update Manager (FWUM) information
* *
* * intf : IPMI interface * *intf : IPMI interface
* output : when set to non zero, queried information is displayed * output : when set to non zero, queried information is displayed
* pNumBank: output ptr for number of banks * pNumBank: output ptr for number of banks
*/ */
static tKFWUM_Status KfwumGetInfo(struct ipmi_intf * intf, unsigned char output, static tKFWUM_Status
KfwumGetInfo(struct ipmi_intf *intf, unsigned char output,
unsigned char *pNumBank) unsigned char *pNumBank)
{ {
tKFWUM_Status status = KFWUM_STATUS_OK; tKFWUM_Status status = KFWUM_STATUS_OK;
static struct KfwumGetInfoResp *pGetInfo; static struct KfwumGetInfoResp *pGetInfo;
struct ipmi_rs * rsp; struct ipmi_rs *rsp;
struct ipmi_rq req; struct ipmi_rq req;
memset(&req, 0, sizeof(req)); memset(&req, 0, sizeof(req));
@ -575,7 +529,7 @@ static tKFWUM_Status KfwumGetInfo(struct ipmi_intf * intf, unsigned char output,
lprintf(LOG_ERR, "Error in FWUM Firmware Get Info Command."); lprintf(LOG_ERR, "Error in FWUM Firmware Get Info Command.");
return KFWUM_STATUS_ERROR; return KFWUM_STATUS_ERROR;
} else if (rsp->ccode != 0) { } else if (rsp->ccode != 0) {
lprintf(LOG_ERR, "FWUM Firmware Get Info returned %x\n", lprintf(LOG_ERR, "FWUM Firmware Get Info returned %x",
rsp->ccode); rsp->ccode);
return KFWUM_STATUS_ERROR; return KFWUM_STATUS_ERROR;
} }
@ -655,8 +609,9 @@ static tKFWUM_Status KfwumGetInfo(struct ipmi_intf * intf, unsigned char output,
* *
* returns KFWUM_STATUS_OK on success, otherwise KFWUM_STATUS_ERROR * returns KFWUM_STATUS_OK on success, otherwise KFWUM_STATUS_ERROR
*/ */
static tKFWUM_Status KfwumGetDeviceInfo(struct ipmi_intf *intf, static tKFWUM_Status
unsigned char output, tKFWUM_BoardInfo *pBoardInfo) KfwumGetDeviceInfo(struct ipmi_intf *intf, unsigned char output,
tKFWUM_BoardInfo *pBoardInfo)
{ {
struct ipm_devid_rsp *pGetDevId; struct ipm_devid_rsp *pGetDevId;
struct ipmi_rs *rsp; struct ipmi_rs *rsp;
@ -698,30 +653,28 @@ static tKFWUM_Status KfwumGetDeviceInfo(struct ipmi_intf *intf,
return KFWUM_STATUS_OK; return KFWUM_STATUS_OK;
} }
#ifdef HAVE_PRAGMA_PACK #ifdef HAVE_PRAGMA_PACK
#pragma pack(1) #pragma pack(1)
#endif #endif
struct KfwumGetStatusResp { struct KfwumGetStatusResp {
unsigned char bankState; unsigned char bankState;
unsigned char firmLengthLSB; unsigned char firmLengthLSB;
unsigned char firmLengthMid; unsigned char firmLengthMid;
unsigned char firmLengthMSB; unsigned char firmLengthMSB;
unsigned char firmRev1; unsigned char firmRev1;
unsigned char firmRev2; unsigned char firmRev2;
unsigned char firmRev3; unsigned char firmRev3;
} ATTRIBUTE_PACKING; } ATTRIBUTE_PACKING;
#ifdef HAVE_PRAGMA_PACK #ifdef HAVE_PRAGMA_PACK
#pragma pack(0) #pragma pack(0)
#endif #endif
const struct valstr bankStateValS[] = { const struct valstr bankStateValS[] = {
{ 0x00, "Not programmed" }, { 0x00, "Not programmed" },
{ 0x01, "New firmware" }, { 0x01, "New firmware" },
{ 0x02, "Wait for validation" }, { 0x02, "Wait for validation" },
{ 0x03, "Last Known Good" }, { 0x03, "Last Known Good" },
{ 0x04, "Previous Good" } { 0x04, "Previous Good" }
}; };
/* KfwumGetStatus - Get (and prints) FWUM banks information /* KfwumGetStatus - Get (and prints) FWUM banks information
@ -794,23 +747,23 @@ KfwumGetStatus(struct ipmi_intf * intf)
#ifdef HAVE_PRAGMA_PACK #ifdef HAVE_PRAGMA_PACK
#pragma pack(1) #pragma pack(1)
#endif #endif
struct KfwumManualRollbackReq{ struct KfwumManualRollbackReq {
unsigned char type; unsigned char type;
} ATTRIBUTE_PACKING; } ATTRIBUTE_PACKING;
#ifdef HAVE_PRAGMA_PACK #ifdef HAVE_PRAGMA_PACK
#pragma pack(0) #pragma pack(0)
#endif #endif
/* KfwumManualRollback - Ask IPMC to rollback to previous version /* KfwumManualRollback - Ask IPMC to rollback to previous version
* *
* *intf : IPMI interface * *intf : IPMI interface
* *
* returns KFWUM_STATUS_OK on success, otherwise KFWUM_STATUS_ERROR * returns KFWUM_STATUS_OK on success, otherwise KFWUM_STATUS_ERROR
*/ */
static tKFWUM_Status KfwumManualRollback(struct ipmi_intf * intf) static tKFWUM_Status
KfwumManualRollback(struct ipmi_intf *intf)
{ {
struct ipmi_rs * rsp; struct ipmi_rs *rsp;
struct ipmi_rq req; struct ipmi_rq req;
struct KfwumManualRollbackReq thisReq; struct KfwumManualRollbackReq thisReq;
@ -838,12 +791,12 @@ static tKFWUM_Status KfwumManualRollback(struct ipmi_intf * intf)
#ifdef HAVE_PRAGMA_PACK #ifdef HAVE_PRAGMA_PACK
#pragma pack(1) #pragma pack(1)
#endif #endif
struct KfwumStartFirmwareDownloadReq{ struct KfwumStartFirmwareDownloadReq {
unsigned char lengthLSB; unsigned char lengthLSB;
unsigned char lengthMid; unsigned char lengthMid;
unsigned char lengthMSB; unsigned char lengthMSB;
unsigned char paddingLSB; unsigned char paddingLSB;
unsigned char paddingMSB; unsigned char paddingMSB;
unsigned char useSequence; unsigned char useSequence;
} ATTRIBUTE_PACKING; } ATTRIBUTE_PACKING;
#ifdef HAVE_PRAGMA_PACK #ifdef HAVE_PRAGMA_PACK
@ -854,14 +807,15 @@ struct KfwumStartFirmwareDownloadReq{
#pragma pack(1) #pragma pack(1)
#endif #endif
struct KfwumStartFirmwareDownloadResp { struct KfwumStartFirmwareDownloadResp {
unsigned char bank; unsigned char bank;
} ATTRIBUTE_PACKING; } ATTRIBUTE_PACKING;
#ifdef HAVE_PRAGMA_PACK #ifdef HAVE_PRAGMA_PACK
#pragma pack(0) #pragma pack(0)
#endif #endif
static tKFWUM_Status KfwumStartFirmwareImage(struct ipmi_intf * intf, static tKFWUM_Status
unsigned long length, unsigned short padding) KfwumStartFirmwareImage(struct ipmi_intf *intf, unsigned long length,
unsigned short padding)
{ {
struct ipmi_rs *rsp; struct ipmi_rs *rsp;
struct ipmi_rq req; struct ipmi_rq req;
@ -906,11 +860,11 @@ static tKFWUM_Status KfwumStartFirmwareImage(struct ipmi_intf * intf,
#endif #endif
struct KfwumSaveFirmwareAddressReq struct KfwumSaveFirmwareAddressReq
{ {
unsigned char addressLSB; unsigned char addressLSB;
unsigned char addressMid; unsigned char addressMid;
unsigned char addressMSB; unsigned char addressMSB;
unsigned char numBytes; unsigned char numBytes;
unsigned char txBuf[KFWUM_SMALL_BUFFER-KFWUM_OLD_CMD_OVERHEAD]; unsigned char txBuf[KFWUM_SMALL_BUFFER-KFWUM_OLD_CMD_OVERHEAD];
} ATTRIBUTE_PACKING; } ATTRIBUTE_PACKING;
#ifdef HAVE_PRAGMA_PACK #ifdef HAVE_PRAGMA_PACK
#pragma pack(0) #pragma pack(0)
@ -921,19 +875,19 @@ struct KfwumSaveFirmwareAddressReq
#endif #endif
struct KfwumSaveFirmwareSequenceReq struct KfwumSaveFirmwareSequenceReq
{ {
unsigned char sequenceNumber; unsigned char sequenceNumber;
unsigned char txBuf[KFWUM_BIG_BUFFER]; unsigned char txBuf[KFWUM_BIG_BUFFER];
} ATTRIBUTE_PACKING; } ATTRIBUTE_PACKING;
#ifdef HAVE_PRAGMA_PACK #ifdef HAVE_PRAGMA_PACK
#pragma pack(0) #pragma pack(0)
#endif #endif
# define FWUM_SAVE_FIRMWARE_NO_RESPONSE_LIMIT 6 # define FWUM_SAVE_FIRMWARE_NO_RESPONSE_LIMIT 6
static tKFWUM_Status KfwumSaveFirmwareImage(struct ipmi_intf * intf, static tKFWUM_Status
unsigned char sequenceNumber, unsigned long address, KfwumSaveFirmwareImage(struct ipmi_intf *intf, unsigned char sequenceNumber,
unsigned char *pFirmBuf, unsigned char *pInBufLength) unsigned long address, unsigned char *pFirmBuf,
unsigned char *pInBufLength)
{ {
tKFWUM_Status status = KFWUM_STATUS_OK; tKFWUM_Status status = KFWUM_STATUS_OK;
struct ipmi_rs *rsp; struct ipmi_rs *rsp;
@ -1025,18 +979,18 @@ static tKFWUM_Status KfwumSaveFirmwareImage(struct ipmi_intf * intf,
#ifdef HAVE_PRAGMA_PACK #ifdef HAVE_PRAGMA_PACK
#pragma pack(1) #pragma pack(1)
#endif #endif
struct KfwumFinishFirmwareDownloadReq{ struct KfwumFinishFirmwareDownloadReq {
unsigned char versionMaj; unsigned char versionMaj;
unsigned char versionMinSub; unsigned char versionMinSub;
unsigned char versionSdr; unsigned char versionSdr;
unsigned char reserved; unsigned char reserved;
} ATTRIBUTE_PACKING; } ATTRIBUTE_PACKING;
#ifdef HAVE_PRAGMA_PACK #ifdef HAVE_PRAGMA_PACK
#pragma pack(0) #pragma pack(0)
#endif #endif
static tKFWUM_Status KfwumFinishFirmwareImage(struct ipmi_intf * intf, static tKFWUM_Status
tKFWUM_InFirmwareInfo firmInfo) KfwumFinishFirmwareImage(struct ipmi_intf *intf, tKFWUM_InFirmwareInfo firmInfo)
{ {
struct ipmi_rs *rsp; struct ipmi_rs *rsp;
struct ipmi_rq req; struct ipmi_rq req;
@ -1070,10 +1024,10 @@ static tKFWUM_Status KfwumFinishFirmwareImage(struct ipmi_intf * intf,
return KFWUM_STATUS_OK; return KFWUM_STATUS_OK;
} }
#define FWUM_MAX_UPLOAD_RETRY 6 #define FWUM_MAX_UPLOAD_RETRY 6
static tKFWUM_Status KfwumUploadFirmware(struct ipmi_intf * intf, static tKFWUM_Status
unsigned char *pBuffer, unsigned long totalSize) KfwumUploadFirmware(struct ipmi_intf *intf, unsigned char *pBuffer,
unsigned long totalSize)
{ {
tKFWUM_Status status = KFWUM_STATUS_ERROR; tKFWUM_Status status = KFWUM_STATUS_ERROR;
unsigned long address = 0x0; unsigned long address = 0x0;
@ -1166,38 +1120,39 @@ KfwumStartFirmwareUpgrade(struct ipmi_intf *intf)
/* String table */ /* String table */
/* Must match eFWUM_CmdId */ /* Must match eFWUM_CmdId */
static const char* CMD_ID_STRING[] = { static const char* CMD_ID_STRING[] = {
"GetFwInfo", "GetFwInfo",
"KickWatchdog", "KickWatchdog",
"GetLastAnswer", "GetLastAnswer",
"BootHandshake", "BootHandshake",
"ReportStatus", "ReportStatus",
"CtrlIPMBLine", "CtrlIPMBLine",
"SetFwState", "SetFwState",
"GetFwStatus", "GetFwStatus",
"GetSpiMemStatus", "GetSpiMemStatus",
"StartFwUpdate", "StartFwUpdate",
"StartFwImage", "StartFwImage",
"SaveFwImage", "SaveFwImage",
"FinishFwImage", "FinishFwImage",
"ReadFwImage", "ReadFwImage",
"ManualRollback", "ManualRollback",
"GetTraceLog" }; "GetTraceLog"
};
static const char* EXT_CMD_ID_STRING[] = { static const char* EXT_CMD_ID_STRING[] = {
"FwUpgradeLock", "FwUpgradeLock",
"ProcessFwUpg", "ProcessFwUpg",
"ProcessFwRb", "ProcessFwRb",
"WaitHSAfterUpg", "WaitHSAfterUpg",
"WaitFirstHSUpg", "WaitFirstHSUpg",
"FwInfoStateChange" }; "FwInfoStateChange"
};
static const char* CMD_STATE_STRING[] = { static const char* CMD_STATE_STRING[] = {
"Invalid", "Invalid",
"Begin", "Begin",
"Progress", "Progress",
"Completed" }; "Completed"
};
static tKFWUM_Status static tKFWUM_Status
KfwumGetTraceLog(struct ipmi_intf *intf) KfwumGetTraceLog(struct ipmi_intf *intf)
@ -1205,8 +1160,8 @@ KfwumGetTraceLog(struct ipmi_intf *intf)
tKFWUM_Status status = KFWUM_STATUS_OK; tKFWUM_Status status = KFWUM_STATUS_OK;
struct ipmi_rs *rsp; struct ipmi_rs *rsp;
struct ipmi_rq req; struct ipmi_rq req;
unsigned char chunkIdx; unsigned char chunkIdx;
unsigned char cmdIdx; unsigned char cmdIdx;
if (verbose) { if (verbose) {
printf(" Getting Trace Log!\n"); printf(" Getting Trace Log!\n");
} }
@ -1255,30 +1210,6 @@ KfwumGetTraceLog(struct ipmi_intf *intf)
return status; return status;
} }
/*******************************************************************************
* Function Name: KfwumGetInfoFromFirmware
*
* Description: This function retreive from the firmare the following info :
*
* o Checksum
* o File size (expected)
* o Board Id
* o Device Id
*
* Restriction: None
*
* Input: char * fileName - File to get info from
*
* Output: pInfo - container that will hold all the informations gattered.
* see structure for all details
*
* Global: None
*
* Return: IFWU_SUCCESS - file ok
* IFWU_ERROR - file error
*
*******************************************************************************/
#define IN_FIRMWARE_INFO_OFFSET_LOCATION 0x5a0 #define IN_FIRMWARE_INFO_OFFSET_LOCATION 0x5a0
#define IN_FIRMWARE_INFO_SIZE 20 #define IN_FIRMWARE_INFO_SIZE 20
#define IN_FIRMWARE_INFO_OFFSET_FILE_SIZE 0 #define IN_FIRMWARE_INFO_OFFSET_FILE_SIZE 0
@ -1373,18 +1304,19 @@ KfwumGetInfoFromFirmware(unsigned char *pBuf, unsigned long bufSize,
return KFWUM_STATUS_OK; return KFWUM_STATUS_OK;
} }
void
void KfwumFixTableVersionForOldFirmware(tKFWUM_InFirmwareInfo * pInfo) KfwumFixTableVersionForOldFirmware(tKFWUM_InFirmwareInfo * pInfo)
{ {
switch(pInfo->boardId) switch(pInfo->boardId) {
{ case KFWUM_BOARD_KONTRON_UNKNOWN:
case KFWUM_BOARD_KONTRON_UNKNOWN: pInfo->tableVers = 0xff;
pInfo->tableVers = 0xff; break;
break; default:
default: /* pInfo->tableVers is already set for
/* pInfo->tableVers is already set for the right version */ * the right version
break; */
} break;
}
} }
/* ipmi_kfwum_checkfwcompat - check whether firmware we're about to upload is /* ipmi_kfwum_checkfwcompat - check whether firmware we're about to upload is
@ -1395,7 +1327,8 @@ void KfwumFixTableVersionForOldFirmware(tKFWUM_InFirmwareInfo * pInfo)
* *
* returns KFWUM_STATUS_OK if compatible, otherwise KFWUM_STATUS_ERROR * returns KFWUM_STATUS_OK if compatible, otherwise KFWUM_STATUS_ERROR
*/ */
tKFWUM_Status ipmi_kfwum_checkfwcompat(tKFWUM_BoardInfo boardInfo, tKFWUM_Status
ipmi_kfwum_checkfwcompat(tKFWUM_BoardInfo boardInfo,
tKFWUM_InFirmwareInfo firmInfo) tKFWUM_InFirmwareInfo firmInfo)
{ {
tKFWUM_Status status = KFWUM_STATUS_OK; tKFWUM_Status status = KFWUM_STATUS_OK;
@ -1416,7 +1349,6 @@ tKFWUM_Status ipmi_kfwum_checkfwcompat(tKFWUM_BoardInfo boardInfo,
return status; return status;
} }
void void
printf_kfwum_info(tKFWUM_BoardInfo boardInfo, tKFWUM_InFirmwareInfo firmInfo) printf_kfwum_info(tKFWUM_BoardInfo boardInfo, tKFWUM_InFirmwareInfo firmInfo)
{ {