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

@ -33,7 +33,6 @@
* EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
*/
#include <string.h>
#include <math.h>
#include <time.h>
@ -46,20 +45,9 @@
#include <ipmitool/ipmi_intf.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_MIN 3
typedef enum eKFWUM_Task
{
KFWUM_TASK_INFO,
@ -112,9 +100,10 @@ typedef struct sKFWUM_InFirmwareInfo
unsigned short checksum;
unsigned short sumToRemoveFromChecksum;
/* Since the checksum is added in the bin
after the checksum is calculated, we
need to remove the each byte value. This
byte will contain the addition of both bytes*/
* after the checksum is calculated, we
* need to remove the each byte value. This
* byte will contain the addition of both bytes
*/
tKFWUM_BoardList boardId;
unsigned char deviceId;
unsigned char tableVers;
@ -133,11 +122,15 @@ typedef struct sKFWUM_SaveFirmwareInfo
unsigned char overheadSize;
} tKFWUM_SaveFirmwareInfo;
#define KFWUM_SMALL_BUFFER 32 /* Minimum size (IPMB/IOL/old protocol) */
#define KFWUM_BIG_BUFFER 32 /* Maximum size on KCS interface */
/* Minimum size (IPMB/IOL/old protocol) */
#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*/
#define KFWUM_NEW_CMD_OVERHEAD 4 /*1 sequence+ 1 size + 1 checksum + 1 command*/
/* 3 address + 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
extern int verbose;
@ -155,8 +148,6 @@ void KfwumShowProgress(const char *task, unsigned long current,
unsigned long total);
static unsigned short KfwumCalculateChecksumPadding(unsigned char *pBuffer,
unsigned long totalSize);
static tKFWUM_Status KfwumGetInfo(struct ipmi_intf *intf, unsigned char output,
unsigned char *pNumBank);
static tKFWUM_Status KfwumGetDeviceInfo(struct ipmi_intf *intf,
@ -173,19 +164,15 @@ static tKFWUM_Status KfwumFinishFirmwareImage(struct ipmi_intf * intf,
static tKFWUM_Status KfwumUploadFirmware(struct ipmi_intf *intf,
unsigned char *pBuffer, unsigned long totalSize);
static tKFWUM_Status KfwumStartFirmwareUpgrade(struct ipmi_intf *intf);
static tKFWUM_Status KfwumGetInfoFromFirmware(unsigned char *pBuf,
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_InFirmwareInfo firmInfo);
void printf_kfwum_info(tKFWUM_BoardInfo boardInfo,
tKFWUM_InFirmwareInfo firmInfo);
/* ipmi_fwum_main - entry point for this ipmitool mode
*
* @intf: ipmi interface
@ -195,7 +182,8 @@ void printf_kfwum_info(tKFWUM_BoardInfo boardInfo,
* returns 0 on success
* 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;
printf("FWUM extension Version %d.%d\n", VERSION_MAJ, VERSION_MIN);
@ -252,17 +240,14 @@ int ipmi_fwum_main(struct ipmi_intf * intf, int argc, char ** argv)
return rc;
}
void printf_kfwum_help(void)
void
printf_kfwum_help(void)
{
lprintf(LOG_NOTICE,
"KFWUM Commands: info status download upgrade rollback tracelog");
}
/****************************************/
/** private definitions and macros **/
/****************************************/
/* private definitions and macros */
typedef enum eFWUM_CmdId
{
KFWUM_CMD_ID_GET_FIRMWARE_INFO = 0,
@ -282,36 +267,15 @@ typedef enum eFWUM_CmdId
KFWUM_CMD_ID_EXTENDED_CMD = 0xC0
} tKFWUM_CmdId;
/****************************************/
/** global/static variables definition **/
/****************************************/
/****************************************/
/** functions definition **/
/****************************************/
/*******************************************************************************
/* KfwumMain - function implements upload of the firmware data received as
* parameters
*
* Function Name: KfwumMain
* @task: task to do
*
* 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)
* returns void
*/
static void
KfwumMain(struct ipmi_intf *intf, tKFWUM_Task task)
{
tKFWUM_Status status = KFWUM_STATUS_OK;
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
*/
static tKFWUM_Status KfwumGetFileSize(unsigned char *pFileName,
unsigned long *pFileSize)
static tKFWUM_Status
KfwumGetFileSize(unsigned char *pFileName, unsigned long *pFileSize)
{
FILE *pFileHandle = NULL;
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
*/
#define MAX_BUFFER_SIZE 1024*16
static tKFWUM_Status KfwumSetupBuffersFromFile(unsigned char * pFileName,
unsigned long fileSize)
static tKFWUM_Status
KfwumSetupBuffersFromFile(unsigned char * pFileName, unsigned long fileSize)
{
tKFWUM_Status status = KFWUM_STATUS_ERROR;
FILE *pFileHandle = NULL;
@ -505,38 +469,29 @@ KfwumShowProgress(const char *task, unsigned long current, unsigned long total)
fflush(stdout);
}
/* KfwumCalculateChecksumPadding
*
* TBD
*
/* KfwumCalculateChecksumPadding - TBD
*/
static unsigned short KfwumCalculateChecksumPadding(unsigned char * pBuffer,
unsigned long totalSize)
static unsigned short
KfwumCalculateChecksumPadding(unsigned char *pBuffer, unsigned long totalSize)
{
unsigned short sumOfBytes = 0;
unsigned short padding;
unsigned long counter;
for(counter = 0; counter < totalSize; counter ++ )
{
for (counter = 0; counter < totalSize; counter ++) {
sumOfBytes += pBuffer[counter];
}
padding = 0 - sumOfBytes;
return padding;
}
/******************************************************************************
******************************* COMMANDS **************************************
******************************************************************************/
/* COMMANDS */
#ifdef HAVE_PRAGMA_PACK
#pragma pack(1)
#endif
struct KfwumGetInfoResp {
unsigned char protocolRevision;
unsigned char controllerDeviceId;
struct
{
struct {
unsigned char mode:1;
unsigned char seqAdd:1;
unsigned char res : 6;
@ -549,15 +504,14 @@ struct KfwumGetInfoResp {
#pragma pack(0)
#endif
/* KfwumGetInfo - Get Firmware Update Manager (FWUM) information
*
* *intf : IPMI interface
* output : when set to non zero, queried information is displayed
* 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)
{
tKFWUM_Status status = KFWUM_STATUS_OK;
@ -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.");
return KFWUM_STATUS_ERROR;
} 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);
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
*/
static tKFWUM_Status KfwumGetDeviceInfo(struct ipmi_intf *intf,
unsigned char output, tKFWUM_BoardInfo *pBoardInfo)
static tKFWUM_Status
KfwumGetDeviceInfo(struct ipmi_intf *intf, unsigned char output,
tKFWUM_BoardInfo *pBoardInfo)
{
struct ipm_devid_rsp *pGetDevId;
struct ipmi_rs *rsp;
@ -698,7 +653,6 @@ static tKFWUM_Status KfwumGetDeviceInfo(struct ipmi_intf *intf,
return KFWUM_STATUS_OK;
}
#ifdef HAVE_PRAGMA_PACK
#pragma pack(1)
#endif
@ -715,7 +669,6 @@ struct KfwumGetStatusResp {
#pragma pack(0)
#endif
const struct valstr bankStateValS[] = {
{ 0x00, "Not programmed" },
{ 0x01, "New firmware" },
@ -801,14 +754,14 @@ struct KfwumManualRollbackReq{
#pragma pack(0)
#endif
/* KfwumManualRollback - Ask IPMC to rollback to previous version
*
* *intf : IPMI interface
*
* 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_rq req;
@ -860,8 +813,9 @@ struct KfwumStartFirmwareDownloadResp {
#pragma pack(0)
#endif
static tKFWUM_Status KfwumStartFirmwareImage(struct ipmi_intf * intf,
unsigned long length, unsigned short padding)
static tKFWUM_Status
KfwumStartFirmwareImage(struct ipmi_intf *intf, unsigned long length,
unsigned short padding)
{
struct ipmi_rs *rsp;
struct ipmi_rq req;
@ -928,12 +882,12 @@ struct KfwumSaveFirmwareSequenceReq
#pragma pack(0)
#endif
# define FWUM_SAVE_FIRMWARE_NO_RESPONSE_LIMIT 6
static tKFWUM_Status KfwumSaveFirmwareImage(struct ipmi_intf * intf,
unsigned char sequenceNumber, unsigned long address,
unsigned char *pFirmBuf, unsigned char *pInBufLength)
static tKFWUM_Status
KfwumSaveFirmwareImage(struct ipmi_intf *intf, unsigned char sequenceNumber,
unsigned long address, unsigned char *pFirmBuf,
unsigned char *pInBufLength)
{
tKFWUM_Status status = KFWUM_STATUS_OK;
struct ipmi_rs *rsp;
@ -1035,8 +989,8 @@ struct KfwumFinishFirmwareDownloadReq{
#pragma pack(0)
#endif
static tKFWUM_Status KfwumFinishFirmwareImage(struct ipmi_intf * intf,
tKFWUM_InFirmwareInfo firmInfo)
static tKFWUM_Status
KfwumFinishFirmwareImage(struct ipmi_intf *intf, tKFWUM_InFirmwareInfo firmInfo)
{
struct ipmi_rs *rsp;
struct ipmi_rq req;
@ -1070,10 +1024,10 @@ static tKFWUM_Status KfwumFinishFirmwareImage(struct ipmi_intf * intf,
return KFWUM_STATUS_OK;
}
#define FWUM_MAX_UPLOAD_RETRY 6
static tKFWUM_Status KfwumUploadFirmware(struct ipmi_intf * intf,
unsigned char *pBuffer, unsigned long totalSize)
static tKFWUM_Status
KfwumUploadFirmware(struct ipmi_intf *intf, unsigned char *pBuffer,
unsigned long totalSize)
{
tKFWUM_Status status = KFWUM_STATUS_ERROR;
unsigned long address = 0x0;
@ -1181,7 +1135,8 @@ static const char* CMD_ID_STRING[] = {
"FinishFwImage",
"ReadFwImage",
"ManualRollback",
"GetTraceLog" };
"GetTraceLog"
};
static const char* EXT_CMD_ID_STRING[] = {
"FwUpgradeLock",
@ -1189,15 +1144,15 @@ static const char* EXT_CMD_ID_STRING[] = {
"ProcessFwRb",
"WaitHSAfterUpg",
"WaitFirstHSUpg",
"FwInfoStateChange" };
"FwInfoStateChange"
};
static const char* CMD_STATE_STRING[] = {
"Invalid",
"Begin",
"Progress",
"Completed" };
"Completed"
};
static tKFWUM_Status
KfwumGetTraceLog(struct ipmi_intf *intf)
@ -1255,30 +1210,6 @@ KfwumGetTraceLog(struct ipmi_intf *intf)
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_SIZE 20
#define IN_FIRMWARE_INFO_OFFSET_FILE_SIZE 0
@ -1373,16 +1304,17 @@ KfwumGetInfoFromFirmware(unsigned char *pBuf, unsigned long bufSize,
return KFWUM_STATUS_OK;
}
void KfwumFixTableVersionForOldFirmware(tKFWUM_InFirmwareInfo * pInfo)
{
switch(pInfo->boardId)
void
KfwumFixTableVersionForOldFirmware(tKFWUM_InFirmwareInfo * pInfo)
{
switch(pInfo->boardId) {
case KFWUM_BOARD_KONTRON_UNKNOWN:
pInfo->tableVers = 0xff;
break;
default:
/* pInfo->tableVers is already set for the right version */
/* pInfo->tableVers is already set for
* the right version
*/
break;
}
}
@ -1395,7 +1327,8 @@ void KfwumFixTableVersionForOldFirmware(tKFWUM_InFirmwareInfo * pInfo)
*
* 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_Status status = KFWUM_STATUS_OK;
@ -1416,7 +1349,6 @@ tKFWUM_Status ipmi_kfwum_checkfwcompat(tKFWUM_BoardInfo boardInfo,
return status;
}
void
printf_kfwum_info(tKFWUM_BoardInfo boardInfo, tKFWUM_InFirmwareInfo firmInfo)
{