From e2b72d82ded319096630a5209030938419596931 Mon Sep 17 00:00:00 2001 From: Francois Isabelle Date: Wed, 18 Mar 2009 20:19:23 +0000 Subject: [PATCH] updated HPM firmware agent to version 1.04 2009-02-11 - With multi-component HPM file, if one component need to be skipped because the component is already up-to-date, ipmitool sends "Initiate upgrade action / Upload for upgrade" anyway. If the component needs to be skipped, ipmitool will not send "Initiate upgrade action / Upload for upgrade" - Incremented version to 1.03 2009-02-11 - Fixed side effect introduced by last version, "forced" update didn't work anymore - Incremented version to 1.04 --- ipmitool/lib/ipmi_hpmfwupg.c | 1368 ++++++++++++++++++---------------- 1 file changed, 714 insertions(+), 654 deletions(-) diff --git a/ipmitool/lib/ipmi_hpmfwupg.c b/ipmitool/lib/ipmi_hpmfwupg.c index 848aafd..4474d87 100644 --- a/ipmitool/lib/ipmi_hpmfwupg.c +++ b/ipmitool/lib/ipmi_hpmfwupg.c @@ -6,7 +6,7 @@ * modification, are permitted provided that the following conditions * are met: * - * Redistribution of source code must retain the above copyright + * Redistribution of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * Redistribution in binary form must reproduce the above copyright @@ -35,7 +35,7 @@ #include #include #include -#include +#include #include #include "../src/plugins/lan/md5.h" #include @@ -49,14 +49,14 @@ * * Copyright (c) 2006 Kontron Canada, Inc. All Rights Reserved. * -* HPM.1 +* HPM.1 * Hardware Platform Management * IPM Controller Firmware Upgrade Procedure * * This module implements an Upgrade Agent for the IPM Controller * Firmware Upgrade Procedure (HPM.1) specification version 1.0. * -* author: +* author: * Frederic.Lelievre@ca.kontron.com * Francois.Isabelle@ca.kontron.com * Jean-Michel.Audet@ca.kontron.com @@ -65,25 +65,25 @@ * * HISTORY * =========================================================================== -* 2007-01-11 +* 2007-01-11 * * - Incremented to version 0.2 * - Added lan packet size reduction mechanism to workaround fact * that lan iface will not return C7 on excessive length * - Fixed some typos * - now uses lprintf() -* -* - Incremented to version 0.3 +* +* - Incremented to version 0.3 * - added patch for openipmi si driver V39 (send message in driver does not * retry on 82/83 completion code and return 82/83 as response from target * [conditionnaly built with ENABLE_OPENIPMI_V39_PATCH] * * see: ipmi-fix-send-msg-retry.pacth in openipmi-developer mailing list * -* 2007-01-16 +* 2007-01-16 * * - Incremented to version 0.4 -* - Fixed lan iface inaccesiblity timeout handling. Waiting for firmware +* - Fixed lan iface inaccesiblity timeout handling. Waiting for firmware * activation completion (fixed sleep) before re-opening a session and * get the final firmware upgrade status. * - Fixed some user interface stuff. @@ -98,20 +98,35 @@ * - Modified the display of upgrade of Firmware version. * - Added new options like "check" and "component" and "all" to hpm commands. * - By default we skip the upgrade if we have the same firmware version -* as compared to the Image file (*.hpm).This will ensure that user does +* as compared to the Image file (*.hpm).This will ensure that user does * not update the target incase its already been updated * * 2008-01-25 * - Reduce buffer length more aggressively when no response from iol. * - Incremented version to 1.02 * +* 2009-02-11 +* - With multi-component HPM file, if one component need to be skipped because +* the component is already up-to-date, ipmitool sends "Initiate upgrade +* action / Upload for upgrade" anyway. +* +* If the component needs to be skipped, ipmitool will not send "Initiate +* upgrade action / Upload for upgrade" +* +* - Incremented version to 1.03 +* +* 2009-02-11 +* - Fixed side effect introduced by last version, "forced" update didn't +* work anymore +* - Incremented version to 1.04 +* * =========================================================================== * TODO * =========================================================================== * 2007-01-11 * - Add interpretation of GetSelftestResults * - Add interpretation of component ID string -* +* *****************************************************************************/ extern int verbose; @@ -119,18 +134,18 @@ extern int verbose; /* * Agent version */ -#define HPMFWUPG_VERSION_MAJOR 1 +#define HPMFWUPG_VERSION_MAJOR 1 #define HPMFWUPG_VERSION_MINOR 0 -#define HPMFWUPG_VERSION_SUBMINOR 2 +#define HPMFWUPG_VERSION_SUBMINOR 4 -/* +/* * HPM.1 FIRMWARE UPGRADE COMMANDS (part of PICMG) */ #define HPMFWUPG_GET_TARGET_UPG_CAPABILITIES 0x2E -#define HPMFWUPG_GET_COMPONENT_PROPERTIES 0x2F -#define HPMFWUPG_ABORT_UPGRADE 0x30 -#define HPMFWUPG_INITIATE_UPGRADE_ACTION 0x31 +#define HPMFWUPG_GET_COMPONENT_PROPERTIES 0x2F +#define HPMFWUPG_ABORT_UPGRADE 0x30 +#define HPMFWUPG_INITIATE_UPGRADE_ACTION 0x31 #define HPMFWUPG_UPLOAD_FIRMWARE_BLOCK 0x32 #define HPMFWUPG_FINISH_FIRMWARE_UPLOAD 0x33 #define HPMFWUPG_GET_UPGRADE_STATUS 0x34 @@ -157,12 +172,12 @@ extern int verbose; #define HPMFWUPG_FW_MISMATCH 0x83 #define HPMFWUPG_ROLLBACK_DENIED 0x83 -/* +/* * This error code is used as a temporary PATCH to * the latest Open ipmi driver. This PATCH * will be removed once a new Open IPMI driver is released. * (Buggy version = 39) - */ + */ #define ENABLE_OPENIPMI_V39_PATCH #ifdef ENABLE_OPENIPMI_V39_PATCH @@ -177,7 +192,7 @@ static int errorCount; #define HPMFWUPG_IS_RETRYABLE(error) FALSE #endif -/* +/* * HPM FIRMWARE UPGRADE GENERAL DEFINITIONS */ @@ -200,7 +215,7 @@ typedef enum eHpmfwupgComponentId HPMFWUPG_COMPONENT_ID_6, HPMFWUPG_COMPONENT_ID_7, HPMFWUPG_COMPONENT_ID_MAX -} tHpmfwupgComponentId; +} tHpmfwupgComponentId; #ifdef PRAGMA_PACK #pramga pack(1) @@ -225,7 +240,7 @@ struct HpmfwupgComponentBitMask unsigned char component0 : 1; unsigned char component1 : 1; unsigned char component2 : 1; - unsigned char component3 : 1; + unsigned char component3 : 1; unsigned char component4 : 1; unsigned char component5 : 1; unsigned char component6 : 1; @@ -246,7 +261,7 @@ static const int HPMFWUPG_UPLOAD_BLOCK_LENGTH = 1; static const int HPMFWUPG_UPLOAD_RETRY = 2; -/* +/* * TARGET UPGRADE CAPABILITIES DEFINITIONS */ @@ -278,7 +293,7 @@ struct HpmfwupgGetTargetUpgCapabilitiesResp unsigned char autRollbackOverride : 1; unsigned char ipmcDegradedDurinUpg: 1; unsigned char deferActivation : 1; - unsigned char servAffectDuringUpg : 1; + unsigned char servAffectDuringUpg : 1; unsigned char manualRollback : 1; unsigned char autRollback : 1; unsigned char ipmcSelftestCap : 1; @@ -288,8 +303,8 @@ struct HpmfwupgGetTargetUpgCapabilitiesResp unsigned char manualRollback : 1; unsigned char servAffectDuringUpg : 1; unsigned char deferActivation : 1; - unsigned char ipmcDegradedDurinUpg: 1; - unsigned char autRollbackOverride : 1; + unsigned char ipmcDegradedDurinUpg: 1; + unsigned char autRollbackOverride : 1; unsigned char fwUpgUndesirable : 1; #endif }bitField; @@ -316,20 +331,20 @@ struct HpmfwupgGetTargetUpgCapabilitiesCtx #pramga pack(0) #endif -/* +/* * COMPONENT PROPERTIES DEFINITIONS */ - + typedef enum eHpmfwupgCompPropertiesSelect { HPMFWUPG_COMP_GEN_PROPERTIES = 0, - HPMFWUPG_COMP_CURRENT_VERSION, + HPMFWUPG_COMP_CURRENT_VERSION, HPMFWUPG_COMP_DESCRIPTION_STRING, HPMFWUPG_COMP_ROLLBACK_FIRMWARE_VERSION, HPMFWUPG_COMP_DEFERRED_FIRMWARE_VERSION, HPMFWUPG_COMP_RESERVED, - HPMFWUPG_COMP_OEM_PROPERTIES = 192 -} tHpmfwupgCompPropertiesSelect; + HPMFWUPG_COMP_OEM_PROPERTIES = 192 +} tHpmfwupgCompPropertiesSelect; #ifdef PRAGMA_PACK #pramga pack(1) @@ -347,7 +362,7 @@ struct HpmfwupgGetComponentPropertiesReq #ifdef PRAGMA_PACK #pramga pack(1) #endif -struct HpmfwupgGetGeneralPropResp +struct HpmfwupgGetGeneralPropResp { unsigned char picmgId; union @@ -356,7 +371,7 @@ struct HpmfwupgGetGeneralPropResp struct { #if WORDS_BIGENDIAN - unsigned char reserved : 2; + unsigned char reserved : 2; unsigned char payloadColdReset : 1; unsigned char deferredActivation : 1; unsigned char comparisonSupport : 1; @@ -380,7 +395,7 @@ struct HpmfwupgGetGeneralPropResp #ifdef PRAGMA_PACK #pramga pack(1) #endif -struct HpmfwupgGetCurrentVersionResp +struct HpmfwupgGetCurrentVersionResp { unsigned char picmgId; unsigned char currentVersion[HPMFWUPG_VERSION_SIZE]; @@ -392,7 +407,7 @@ struct HpmfwupgGetCurrentVersionResp #ifdef PRAGMA_PACK #pramga pack(1) #endif -struct HpmfwupgGetDescStringResp +struct HpmfwupgGetDescStringResp { unsigned char picmgId; char descString[HPMFWUPG_DESC_STRING_LENGTH]; @@ -404,7 +419,7 @@ struct HpmfwupgGetDescStringResp #ifdef PRAGMA_PACK #pramga pack(1) #endif -struct HpmfwupgGetRollbackFwVersionResp +struct HpmfwupgGetRollbackFwVersionResp { unsigned char picmgId; unsigned char rollbackFwVersion[HPMFWUPG_VERSION_SIZE]; @@ -416,7 +431,7 @@ struct HpmfwupgGetRollbackFwVersionResp #ifdef PRAGMA_PACK #pramga pack(1) #endif -struct HpmfwupgGetDeferredFwVersionResp +struct HpmfwupgGetDeferredFwVersionResp { unsigned char picmgId; unsigned char deferredFwVersion[HPMFWUPG_VERSION_SIZE]; @@ -425,14 +440,14 @@ struct HpmfwupgGetDeferredFwVersionResp #pramga pack(0) #endif -/* +/* * GetComponentProperties - OEM properties (192) */ #define HPMFWUPG_OEM_LENGTH 4 #ifdef PRAGMA_PACK #pramga pack(1) #endif -struct HpmfwupgGetOemProperties +struct HpmfwupgGetOemProperties { unsigned char picmgId; unsigned char oemRspData[HPMFWUPG_OEM_LENGTH]; @@ -473,7 +488,7 @@ struct HpmfwupgGetComponentPropertiesCtx #endif -/* +/* * ABORT UPGRADE DEFINITIONS */ #ifdef PRAGMA_PACK @@ -510,7 +525,7 @@ struct HpmfwupgAbortUpgradeCtx #pramga pack(0) #endif -/* +/* * UPGRADE ACTIONS DEFINITIONS */ typedef enum eHpmfwupgUpgradeAction @@ -558,7 +573,7 @@ struct HpmfwupgInitiateUpgradeActionCtx #pramga pack(0) #endif -/* +/* * UPLOAD FIRMWARE BLOCK DEFINITIONS */ @@ -686,7 +701,7 @@ struct HpmfwupgActivateFirmwareCtx #pramga pack(0) #endif - + /* * GET UPGRADE STATUS DEFINITIONS */ @@ -725,7 +740,7 @@ struct HpmfwupgGetUpgradeStatusCtx #ifdef PRAGMA_PACK #pramga pack(0) #endif - + /* * MANUAL FW ROLLBACK DEFINITIONS */ @@ -842,7 +857,7 @@ struct HpmfwupgQuerySelftestResultCtx #endif /* * HPM.1 IMAGE DEFINITIONS - */ + */ #define HPMFWUPG_HEADER_SIGNATURE_LENGTH 8 #define HPMFWUPG_MANUFATURER_ID_LENGTH 3 @@ -851,9 +866,9 @@ struct HpmfwupgQuerySelftestResultCtx #define HPMFWUPG_TIMEOUT_LENGTH 1 #define HPMFWUPG_COMP_REVISION_LENGTH 2 #define HPMFWUPG_FIRM_REVISION_LENGTH 6 -#define HPMFWUPG_IMAGE_HEADER_VERSION 0 +#define HPMFWUPG_IMAGE_HEADER_VERSION 0 #define HPMFWUPG_IMAGE_SIGNATURE "PICMGFWU" - + #ifdef PRAGMA_PACK #pramga pack(1) #endif @@ -865,13 +880,13 @@ struct HpmfwupgImageHeader unsigned char manId[HPMFWUPG_MANUFATURER_ID_LENGTH]; unsigned char prodId[HPMFWUPG_PRODUCT_ID_LENGTH]; unsigned char time[HPMFWUPG_TIME_LENGTH]; - union + union { - struct + struct { #if WORDS_BIGENDIAN unsigned char imageSelfTest : 1; - unsigned char autRollback : 1; + unsigned char autRollback : 1; unsigned char manRollback : 1; unsigned char servAffected : 1; unsigned char reserved : 4; @@ -994,43 +1009,43 @@ VERSIONINFO gVersionInfo[HPMFWUPG_COMPONENT_ID_MAX]; -static int HpmfwupgUpgrade(struct ipmi_intf *intf, char* imageFilename, int activate, int,int); +static int HpmfwupgUpgrade(struct ipmi_intf *intf, char* imageFilename, int activate, int,int); static int HpmfwupgValidateImageIntegrity(struct HpmfwupgUpgradeCtx* pFwupgCtx); -static int HpmfwupgPreparationStage( struct ipmi_intf *intf, +static int HpmfwupgPreparationStage( struct ipmi_intf *intf, struct HpmfwupgUpgradeCtx* pFwupgCtx, int option); -static int HpmfwupgUpgradeStage ( struct ipmi_intf *intf, +static int HpmfwupgUpgradeStage ( struct ipmi_intf *intf, struct HpmfwupgUpgradeCtx* pFwupgCtx, int compToUpload ,int option); -static int HpmfwupgActivationStage(struct ipmi_intf *intf, +static int HpmfwupgActivationStage(struct ipmi_intf *intf, struct HpmfwupgUpgradeCtx* pFwupgCtx); -static int HpmfwupgGetTargetUpgCapabilities(struct ipmi_intf *intf, +static int HpmfwupgGetTargetUpgCapabilities(struct ipmi_intf *intf, struct HpmfwupgGetTargetUpgCapabilitiesCtx* pCtx); -static int HpmfwupgGetComponentProperties(struct ipmi_intf *intf, +static int HpmfwupgGetComponentProperties(struct ipmi_intf *intf, struct HpmfwupgGetComponentPropertiesCtx* pCtx); -static int HpmfwupgQuerySelftestResult(struct ipmi_intf *intf, +static int HpmfwupgQuerySelftestResult(struct ipmi_intf *intf, struct HpmfwupgQuerySelftestResultCtx* pCtx, struct HpmfwupgUpgradeCtx* pFwupgCtx); -static int HpmfwupgQueryRollbackStatus(struct ipmi_intf *intf, +static int HpmfwupgQueryRollbackStatus(struct ipmi_intf *intf, struct HpmfwupgQueryRollbackStatusCtx* pCtx, struct HpmfwupgUpgradeCtx* pFwupgCtx); -static int HpmfwupgAbortUpgrade(struct ipmi_intf *intf, - struct HpmfwupgAbortUpgradeCtx* pCtx); -static int HpmfwupgInitiateUpgradeAction(struct ipmi_intf *intf, +static int HpmfwupgAbortUpgrade(struct ipmi_intf *intf, + struct HpmfwupgAbortUpgradeCtx* pCtx); +static int HpmfwupgInitiateUpgradeAction(struct ipmi_intf *intf, struct HpmfwupgInitiateUpgradeActionCtx* pCtx, - struct HpmfwupgUpgradeCtx* pFwupgCtx); -static int HpmfwupgUploadFirmwareBlock(struct ipmi_intf *intf, - struct HpmfwupgUploadFirmwareBlockCtx* pCtx, + struct HpmfwupgUpgradeCtx* pFwupgCtx); +static int HpmfwupgUploadFirmwareBlock(struct ipmi_intf *intf, + struct HpmfwupgUploadFirmwareBlockCtx* pCtx, struct HpmfwupgUpgradeCtx* pFwupgCtx, int count , unsigned int *pOffset, unsigned int *blockLen); -static int HpmfwupgFinishFirmwareUpload(struct ipmi_intf *intf, +static int HpmfwupgFinishFirmwareUpload(struct ipmi_intf *intf, struct HpmfwupgFinishFirmwareUploadCtx* pCtx, struct HpmfwupgUpgradeCtx* pFwupgCtx); -static int HpmfwupgActivateFirmware(struct ipmi_intf *intf, +static int HpmfwupgActivateFirmware(struct ipmi_intf *intf, struct HpmfwupgActivateFirmwareCtx* pCtx, struct HpmfwupgUpgradeCtx* pFwupgCtx); -static int HpmfwupgGetUpgradeStatus(struct ipmi_intf *intf, - struct HpmfwupgGetUpgradeStatusCtx* pCtxstruct, +static int HpmfwupgGetUpgradeStatus(struct ipmi_intf *intf, + struct HpmfwupgGetUpgradeStatusCtx* pCtxstruct, struct HpmfwupgUpgradeCtx* pFwupgCtx); -static int HpmfwupgManualFirmwareRollback(struct ipmi_intf *intf, +static int HpmfwupgManualFirmwareRollback(struct ipmi_intf *intf, struct HpmfwupgManualFirmwareRollbackCtx* pCtx, struct HpmfwupgUpgradeCtx* pFwupgCtx); static void HpmfwupgPrintUsage(void); @@ -1041,7 +1056,19 @@ static int HpmfwupgWaitLongDurationCmd(struct ipmi_intf *intf, struct HpmfwupgUp static struct ipmi_rs * HpmfwupgSendCmd(struct ipmi_intf *intf, struct ipmi_rq req, struct HpmfwupgUpgradeCtx* pFwupgCtx); - + + +static int HpmFwupgActionUploadFirmware +( + struct HpmfwupgComponentBitMask components, + struct HpmfwupgUpgradeCtx* pFwupgCtx, + unsigned char** pImagePtr, + int componentToUpload, + struct ipmi_intf *intf, + int option, + int* pFlagColdReset +); + /**************************************************************************** * * Function Name: HpmGetuserInput @@ -1060,7 +1087,7 @@ int HpmGetUserInput(char *str) return 1; } return 0; -} +} /**************************************************************************** * * Function Name: HpmDisplayLine @@ -1098,24 +1125,24 @@ void HpmDisplayUpgradeHeader(int option) * every 5% of its completion. * *****************************************************************************/ -void HpmDisplayUpgrade( int skip, unsigned int totalSent, +void HpmDisplayUpgrade( int skip, unsigned int totalSent, unsigned int displayFWLength,time_t timeElapsed) { int percent; static int old_percent=1; - if (skip) - { + if (skip) + { printf("| Skip || --.-- | ----- |\n"); return; } fflush(stdout); - + percent = ((float)totalSent/displayFWLength)*100; if (((percent % 5) == 0)) { - if (percent != old_percent) + if (percent != old_percent) { - if ( percent == 0 ) printf("|"); + if ( percent == 0 ) printf("|"); else if (percent == 100) printf("|"); else printf("."); old_percent = percent; @@ -1127,13 +1154,13 @@ void HpmDisplayUpgrade( int skip, unsigned int totalSent, /* Display the time taken to complete the upgrade */ printf("| %02d.%02d | %05x |\n",timeElapsed/60,timeElapsed%60,totalSent); } -} +} /**************************************************************************** * * Function Name: HpmDisplayVersionHeader * -* Description: This function displays the information about version header +* Description: This function displays the information about version header * *****************************************************************************/ int HpmDisplayVersionHeader(int mode) @@ -1144,14 +1171,14 @@ int HpmDisplayVersionHeader(int mode) HpmDisplayLine("-",41 ); printf("|ID | Name | Versions |\n"); printf("| | | Active| Backup| File |\n"); - HpmDisplayLine("-",41 ); + HpmDisplayLine("-",41 ); } else { - HpmDisplayLine("-",33 ); + HpmDisplayLine("-",33 ); printf("|ID | Name | Versions |\n"); printf("| | | Active| Backup|\n"); - HpmDisplayLine("-",33 ); + HpmDisplayLine("-",33 ); } } @@ -1171,20 +1198,20 @@ int HpmDisplayVersion(int mode,VERSIONINFO *pVersion) * is more than required it does not give problem in displaying it */ strncpy(descString,pVersion->descString,11); - /* - * If the cold reset is required then we can display * on it + /* + * If the cold reset is required then we can display * on it * so that user is aware that he needs to do payload power * cycle after upgrade */ printf("|%c%-2d|%-11s|",pVersion->coldResetRequired?'*':' ',pVersion->componentId,descString); - if (mode & TARGET_VER) + if (mode & TARGET_VER) { if (pVersion->targetMajor == 0xFF && pVersion->targetMinor == 0xFF) printf(" --.-- |"); else printf("%3d.%02x |",pVersion->targetMajor,pVersion->targetMinor); - + if (mode & ROLLBACK_VER) { if (pVersion->rollbackMajor == 0xFF && pVersion->rollbackMinor == 0xFF) @@ -1198,7 +1225,7 @@ int HpmDisplayVersion(int mode,VERSIONINFO *pVersion) } } - if (mode & IMAGE_VER) + if (mode & IMAGE_VER) { if (pVersion->imageMajor == 0xFF && pVersion->imageMinor == 0xFF) printf(" --.-- |"); @@ -1220,7 +1247,7 @@ int HpmfwupgTargetCheck(struct ipmi_intf * intf, int option) { struct HpmfwupgUpgradeCtx fwupgCtx; struct HpmfwupgGetTargetUpgCapabilitiesCtx targetCapCmd; - int rc = HPMFWUPG_SUCCESS; + int rc = HPMFWUPG_SUCCESS; int componentId = 0; int flagColdReset = FALSE; struct ipm_devid_rsp devIdrsp; @@ -1256,7 +1283,7 @@ int HpmfwupgTargetCheck(struct ipmi_intf * intf, int option) val2str(buf2short(devIdrsp.manufacturer_id),ipmi_oem_info)); HpmDisplayVersionHeader(TARGET_VER|ROLLBACK_VER); } - + for ( componentId = HPMFWUPG_COMPONENT_ID_0; componentId < HPMFWUPG_COMPONENT_ID_MAX; componentId++ ) { @@ -1322,8 +1349,8 @@ int HpmfwupgTargetCheck(struct ipmi_intf * intf, int option) if (gVersionInfo[componentId].coldResetRequired) { - /* - * If any of the component indicates that the Payload Cold reset is required + /* + * If any of the component indicates that the Payload Cold reset is required * then set the flag */ flagColdReset = TRUE; @@ -1335,7 +1362,7 @@ int HpmfwupgTargetCheck(struct ipmi_intf * intf, int option) } } } - + if (option & VIEW_MODE) { HpmDisplayLine("-",33 ); @@ -1357,23 +1384,23 @@ int HpmfwupgTargetCheck(struct ipmi_intf * intf, int option) * version 1.0 * *****************************************************************************/ -int HpmfwupgUpgrade(struct ipmi_intf *intf, char* imageFilename, +int HpmfwupgUpgrade(struct ipmi_intf *intf, char* imageFilename, int activate,int componentToUpload, int option) { int rc = HPMFWUPG_SUCCESS; struct HpmfwupgImageHeader imageHeader; struct HpmfwupgUpgradeCtx fwupgCtx; - + /* * GET IMAGE BUFFER FROM FILE */ - + rc = HpmfwupgGetBufferFromFile(imageFilename, &fwupgCtx); - + /* * VALIDATE IMAGE INTEGRITY - */ - + */ + if ( rc == HPMFWUPG_SUCCESS ) { printf("Validating firmware image integrity..."); @@ -1389,11 +1416,11 @@ int HpmfwupgUpgrade(struct ipmi_intf *intf, char* imageFilename, free(fwupgCtx.pImageData); } } - + /* * PREPARATION STAGE */ - + if ( rc == HPMFWUPG_SUCCESS ) { printf("Performing preparation stage..."); @@ -1409,11 +1436,11 @@ int HpmfwupgUpgrade(struct ipmi_intf *intf, char* imageFilename, free(fwupgCtx.pImageData); } } - + /* * UPGRADE STAGE */ - + if ( rc == HPMFWUPG_SUCCESS ) { if (option & VIEW_MODE) @@ -1442,7 +1469,7 @@ int HpmfwupgUpgrade(struct ipmi_intf *intf, char* imageFilename, free(fwupgCtx.pImageData); } } - + /* * ACTIVATION STAGE */ @@ -1455,7 +1482,7 @@ int HpmfwupgUpgrade(struct ipmi_intf *intf, char* imageFilename, free(fwupgCtx.pImageData); } } - + if ( rc == HPMFWUPG_SUCCESS ) { if (option & VIEW_MODE) @@ -1473,16 +1500,16 @@ int HpmfwupgUpgrade(struct ipmi_intf *intf, char* imageFilename, { lprintf(LOG_NOTICE,"Firmware upgrade procedure failed\n"); } - + return rc; -} - +} + /**************************************************************************** * * Function Name: HpmfwupgValidateImageIntegrity * * Description: This function validates a HPM.1 firmware image file as defined -* in section 4 of the IPM Controller Firmware Upgrade +* in section 4 of the IPM Controller Firmware Upgrade * Specification version 1.0 * *****************************************************************************/ @@ -1493,15 +1520,15 @@ int HpmfwupgValidateImageIntegrity(struct HpmfwupgUpgradeCtx* pFwupgCtx) pFwupgCtx->pImageData; md5_state_t ctx; static unsigned char md[HPMFWUPG_MD5_SIGNATURE_LENGTH]; - unsigned char* pMd5Sig = pFwupgCtx->pImageData + - (pFwupgCtx->imageSize - + unsigned char* pMd5Sig = pFwupgCtx->pImageData + + (pFwupgCtx->imageSize - HPMFWUPG_MD5_SIGNATURE_LENGTH); - + /* Validate MD5 checksum */ memset(md, 0, HPMFWUPG_MD5_SIGNATURE_LENGTH); memset(&ctx, 0, sizeof(md5_state_t)); md5_init(&ctx); - md5_append(&ctx, pFwupgCtx->pImageData, pFwupgCtx->imageSize - + md5_append(&ctx, pFwupgCtx->pImageData, pFwupgCtx->imageSize - HPMFWUPG_MD5_SIGNATURE_LENGTH); md5_finish(&ctx, md); if ( memcmp(md, pMd5Sig,HPMFWUPG_MD5_SIGNATURE_LENGTH) != 0 ) @@ -1509,7 +1536,7 @@ int HpmfwupgValidateImageIntegrity(struct HpmfwupgUpgradeCtx* pFwupgCtx) lprintf(LOG_NOTICE,"\n Invalid MD5 signature"); rc = HPMFWUPG_ERROR; } - + if ( rc == HPMFWUPG_SUCCESS ) { /* Validate Header signature */ @@ -1519,9 +1546,9 @@ int HpmfwupgValidateImageIntegrity(struct HpmfwupgUpgradeCtx* pFwupgCtx) if ( pImageHeader->formatVersion == HPMFWUPG_IMAGE_HEADER_VERSION ) { /* Validate header checksum */ - if ( HpmfwupgCalculateChecksum((unsigned char*)pImageHeader, - sizeof(struct HpmfwupgImageHeader) + - pImageHeader->oemDataLength + + if ( HpmfwupgCalculateChecksum((unsigned char*)pImageHeader, + sizeof(struct HpmfwupgImageHeader) + + pImageHeader->oemDataLength + sizeof(unsigned char)/*checksum*/) != 0 ) { lprintf(LOG_NOTICE,"\n Invalid header checksum"); @@ -1541,14 +1568,14 @@ int HpmfwupgValidateImageIntegrity(struct HpmfwupgUpgradeCtx* pFwupgCtx) } } return rc; -} +} /**************************************************************************** * * Function Name: HpmfwupgPreparationStage * -* Description: This function the preperation stage of a firmware upgrade -* procedure as defined in section 3.2 of the IPM Controller +* Description: This function the preperation stage of a firmware upgrade +* procedure as defined in section 3.2 of the IPM Controller * Firmware Upgrade Specification version 1.0 * *****************************************************************************/ @@ -1557,10 +1584,10 @@ int HpmfwupgPreparationStage(struct ipmi_intf *intf, struct HpmfwupgUpgradeCtx* int rc = HPMFWUPG_SUCCESS; struct HpmfwupgImageHeader* pImageHeader = (struct HpmfwupgImageHeader*) pFwupgCtx->pImageData; - + /* Get device ID */ rc = HpmfwupgGetDeviceId(intf, &pFwupgCtx->devId); - + /* Match current IPMC IDs with upgrade image */ if ( rc == HPMFWUPG_SUCCESS ) { @@ -1571,21 +1598,21 @@ int HpmfwupgPreparationStage(struct ipmi_intf *intf, struct HpmfwupgUpgradeCtx* if ( memcmp(pImageHeader->prodId, pFwupgCtx->devId.product_id, HPMFWUPG_PRODUCT_ID_LENGTH ) == 0 ) { /* Validate man ID */ - if ( memcmp(pImageHeader->manId, pFwupgCtx->devId.manufacturer_id, + if ( memcmp(pImageHeader->manId, pFwupgCtx->devId.manufacturer_id, HPMFWUPG_MANUFATURER_ID_LENGTH ) != 0 ) { - lprintf(LOG_NOTICE,"\n Invalid image file for manufacturer %u", - buf2short(pFwupgCtx->devId.manufacturer_id)); + lprintf(LOG_NOTICE,"\n Invalid image file for manufacturer %u", + buf2short(pFwupgCtx->devId.manufacturer_id)); rc = HPMFWUPG_ERROR; } } else { - lprintf(LOG_NOTICE,"\n Invalid image file for product %u", + lprintf(LOG_NOTICE,"\n Invalid image file for product %u", buf2short(pFwupgCtx->devId.product_id)); rc = HPMFWUPG_ERROR; } - + } else { @@ -1595,7 +1622,7 @@ int HpmfwupgPreparationStage(struct ipmi_intf *intf, struct HpmfwupgUpgradeCtx* if (rc != HPMFWUPG_SUCCESS) { - /* + /* * Giving one more chance to user to check whether its OK to continue even if the * product ID does not match. This is helpful as sometimes we just want to update * and dont care whether we have a different product Id. If the user says NO then @@ -1606,12 +1633,12 @@ int HpmfwupgPreparationStage(struct ipmi_intf *intf, struct HpmfwupgUpgradeCtx* printf("\n Image Information"); printf("\n Device Id : 0x%x",pImageHeader->deviceId); printf("\n Prod Id : 0x%02x%02x",pImageHeader->prodId[1], pImageHeader->prodId[0]); - printf("\n Manuf Id : 0x%02x%02x%02x",pImageHeader->manId[2], + printf("\n Manuf Id : 0x%02x%02x%02x",pImageHeader->manId[2], pImageHeader->manId[1],pImageHeader->manId[0]); printf("\n Board Information"); printf("\n Device Id : 0x%x", pFwupgCtx->devId.device_id); printf("\n Prod Id : 0x%02x%02x",pFwupgCtx->devId.product_id[1], pFwupgCtx->devId.product_id[0]); - printf("\n Manuf Id : 0x%02x%02x%02x",pFwupgCtx->devId.manufacturer_id[2], + printf("\n Manuf Id : 0x%02x%02x%02x",pFwupgCtx->devId.manufacturer_id[2], pFwupgCtx->devId.manufacturer_id[1],pFwupgCtx->devId.manufacturer_id[0]); if (HpmGetUserInput("\n Continue ignoring DeviceID/ProductID/ManufacturingID (Y/N) :")) rc = HPMFWUPG_SUCCESS; @@ -1619,20 +1646,20 @@ int HpmfwupgPreparationStage(struct ipmi_intf *intf, struct HpmfwupgUpgradeCtx* else { /* - * If you use all option its kind of FORCE command where we need to upgrade all the components + * If you use all option its kind of FORCE command where we need to upgrade all the components */ printf("\n\n Use \"all\" option for uploading all the components\n"); } } } - + /* Validate earliest compatible revision */ if ( rc == HPMFWUPG_SUCCESS ) { /* Validate major & minor revision */ if ( pImageHeader->compRevision[0] < pFwupgCtx->devId.fw_rev1 ) { - /* Do nothing, upgrade accepted */ + /* Do nothing, upgrade accepted */ } else if ( pImageHeader->compRevision[0] == pFwupgCtx->devId.fw_rev1 ) { @@ -1656,7 +1683,7 @@ int HpmfwupgPreparationStage(struct ipmi_intf *intf, struct HpmfwupgUpgradeCtx* lprintf(LOG_NOTICE," Not compatible with "); lprintf(LOG_NOTICE," Version: Major: %d", pFwupgCtx->devId.fw_rev1); lprintf(LOG_NOTICE," Minor: %x", pFwupgCtx->devId.fw_rev2); - rc = HPMFWUPG_ERROR; + rc = HPMFWUPG_ERROR; } if (rc != HPMFWUPG_SUCCESS) @@ -1669,19 +1696,19 @@ int HpmfwupgPreparationStage(struct ipmi_intf *intf, struct HpmfwupgUpgradeCtx* } } } - + /* Get target upgrade capabilities */ if ( rc == HPMFWUPG_SUCCESS ) { struct HpmfwupgGetTargetUpgCapabilitiesCtx targetCapCmd; - + rc = HpmfwupgGetTargetUpgCapabilities(intf, &targetCapCmd); - + if ( rc == HPMFWUPG_SUCCESS ) { /* Copy response to context */ - memcpy(&pFwupgCtx->targetCap, - &targetCapCmd.resp, + memcpy(&pFwupgCtx->targetCap, + &targetCapCmd.resp, sizeof(struct HpmfwupgGetTargetUpgCapabilitiesResp)); if (option & VIEW_MODE) @@ -1690,7 +1717,7 @@ int HpmfwupgPreparationStage(struct ipmi_intf *intf, struct HpmfwupgUpgradeCtx* } else { - /* Make sure all component IDs defined in the upgrade + /* Make sure all component IDs defined in the upgrade image are supported by the IPMC */ if ( (pImageHeader->components.ComponentBits.byte & pFwupgCtx->targetCap.componentsPresent.ComponentBits.byte ) != @@ -1699,15 +1726,15 @@ int HpmfwupgPreparationStage(struct ipmi_intf *intf, struct HpmfwupgUpgradeCtx* lprintf(LOG_NOTICE,"\n Some components present in the image file are not supported by the IPMC"); rc = HPMFWUPG_ERROR; } - + /* Make sure the upgrade is desirable rigth now */ if ( pFwupgCtx->targetCap.GlobalCapabilities.bitField.fwUpgUndesirable == 1 ) { lprintf(LOG_NOTICE,"\n Upgrade undesirable at this moment"); rc = HPMFWUPG_ERROR; } - - /* Get confimation from the user if he wants to continue when service + + /* Get confimation from the user if he wants to continue when service affected during upgrade */ if ( pFwupgCtx->targetCap.GlobalCapabilities.bitField.servAffectDuringUpg == 1 || pImageHeader->imageCapabilities.bitField.servAffected == 1 ) @@ -1724,34 +1751,34 @@ int HpmfwupgPreparationStage(struct ipmi_intf *intf, struct HpmfwupgUpgradeCtx* } } } - + /* Get the general properties of each component present in image */ if ( rc == HPMFWUPG_SUCCESS ) { int componentId; - for ( componentId = HPMFWUPG_COMPONENT_ID_0; + for ( componentId = HPMFWUPG_COMPONENT_ID_0; componentId < HPMFWUPG_COMPONENT_ID_MAX; componentId++ ) { /* Reset component properties */ memset(&pFwupgCtx->genCompProp[componentId], 0, sizeof (struct HpmfwupgGetGeneralPropResp)); - + if ( (1 << componentId & pImageHeader->components.ComponentBits.byte) ) { struct HpmfwupgGetComponentPropertiesCtx getCompPropCmd; - + /* Get general component properties */ getCompPropCmd.req.componentId = componentId; getCompPropCmd.req.selector = HPMFWUPG_COMP_GEN_PROPERTIES; - + rc = HpmfwupgGetComponentProperties(intf, &getCompPropCmd); - + if ( rc == HPMFWUPG_SUCCESS ) { /* Copy response to context */ - memcpy(&pFwupgCtx->genCompProp[componentId], - &getCompPropCmd.resp, + memcpy(&pFwupgCtx->genCompProp[componentId], + &getCompPropCmd.resp, sizeof(struct HpmfwupgGetGeneralPropResp)); } } @@ -1780,36 +1807,36 @@ int HpmfwupgPreUpgradeCheck(struct ipmi_intf *intf, struct HpmfwupgUpgradeCtx* p int flagColdReset = FALSE; struct HpmfwupgImageHeader* pImageHeader = (struct HpmfwupgImageHeader*) pFwupgCtx->pImageData; - + /* Put pointer after image header */ - pImagePtr = (unsigned char*) + pImagePtr = (unsigned char*) (pFwupgCtx->pImageData + sizeof(struct HpmfwupgImageHeader) + pImageHeader->oemDataLength + sizeof(unsigned char)/*checksum*/); - - /* Deternime actions size */ - actionsSize = pFwupgCtx->imageSize - sizeof(struct HpmfwupgImageHeader); - + + /* Deternime actions size */ + actionsSize = pFwupgCtx->imageSize - sizeof(struct HpmfwupgImageHeader); + if (option & VIEW_MODE) { HpmDisplayVersionHeader(TARGET_VER|ROLLBACK_VER|IMAGE_VER); } /* Perform actions defined in the image */ - while( ( pImagePtr < (pFwupgCtx->pImageData + pFwupgCtx->imageSize - + while( ( pImagePtr < (pFwupgCtx->pImageData + pFwupgCtx->imageSize - HPMFWUPG_MD5_SIGNATURE_LENGTH)) && ( rc == HPMFWUPG_SUCCESS) ) { /* Get action record */ pActionRecord = (struct HpmfwupgActionRecord*)pImagePtr; - + /* Validate action record checksum */ - if ( HpmfwupgCalculateChecksum((unsigned char*)pActionRecord, + if ( HpmfwupgCalculateChecksum((unsigned char*)pActionRecord, sizeof(struct HpmfwupgActionRecord)) != 0 ) { lprintf(LOG_NOTICE," Invalid Action record."); rc = HPMFWUPG_ERROR; } - + if ( rc == HPMFWUPG_SUCCESS ) { switch( pActionRecord->actionType ) @@ -1844,7 +1871,7 @@ int HpmfwupgPreUpgradeCheck(struct ipmi_intf *intf, struct HpmfwupgUpgradeCtx* p unsigned char componentId = 0x00; unsigned char componentIdByte = 0x00; VERSIONINFO *pVersionInfo; - + struct HpmfwupgGetComponentPropertiesCtx getCompProp; /* Save component ID on which the upload is done */ @@ -1854,7 +1881,7 @@ int HpmfwupgPreUpgradeCheck(struct ipmi_intf *intf, struct HpmfwupgUpgradeCtx* p componentId++; } pFwupgCtx->componentId = componentId; - pFwImage = (struct HpmfwupgFirmwareImage*)(pImagePtr + + pFwImage = (struct HpmfwupgFirmwareImage*)(pImagePtr + sizeof(struct HpmfwupgActionRecord)); pData = ((unsigned char*)pFwImage + sizeof(struct HpmfwupgFirmwareImage)); @@ -1866,10 +1893,10 @@ int HpmfwupgPreUpgradeCheck(struct ipmi_intf *intf, struct HpmfwupgUpgradeCtx* p firmwareLength |= (pFwImage->length[3] << 24) & 0xff000000; pVersionInfo = &gVersionInfo[componentId]; - + pVersionInfo->imageMajor = pFwImage->version[0]; pVersionInfo->imageMinor = pFwImage->version[1]; - + mode = TARGET_VER | IMAGE_VER; if (pVersionInfo->coldResetRequired) @@ -1883,12 +1910,12 @@ int HpmfwupgPreUpgradeCheck(struct ipmi_intf *intf, struct HpmfwupgUpgradeCtx* p { if (pVersionInfo->rollbackSupported) { - /*If the Image Versions are same as Target Versions then check for the + /*If the Image Versions are same as Target Versions then check for the * rollback version*/ if ( (pVersionInfo->imageMajor == pVersionInfo->rollbackMajor) && (pVersionInfo->imageMinor == pVersionInfo->rollbackMinor)) { - /* This indicates that the Rollback version is also same as + /* This indicates that the Rollback version is also same as * Image version -- So now we must skip it */ pVersionInfo->skipUpgrade = TRUE; } @@ -1931,8 +1958,8 @@ int HpmfwupgPreUpgradeCheck(struct ipmi_intf *intf, struct HpmfwupgUpgradeCtx* p * * Function Name: HpmfwupgUpgradeStage * -* Description: This function the upgrade stage of a firmware upgrade -* procedure as defined in section 3.3 of the IPM Controller +* Description: This function the upgrade stage of a firmware upgrade +* procedure as defined in section 3.3 of the IPM Controller * Firmware Upgrade Specification version 1.0 * *****************************************************************************/ @@ -1941,7 +1968,7 @@ int HpmfwupgUpgradeStage(struct ipmi_intf *intf, struct HpmfwupgUpgradeCtx* pFwu { struct HpmfwupgImageHeader* pImageHeader = (struct HpmfwupgImageHeader*) pFwupgCtx->pImageData; - struct HpmfwupgComponentBitMask componentToUploadMsk; + struct HpmfwupgComponentBitMask componentToUploadMsk; struct HpmfwupgActionRecord* pActionRecord; int rc = HPMFWUPG_SUCCESS; @@ -1951,13 +1978,12 @@ int HpmfwupgUpgradeStage(struct ipmi_intf *intf, struct HpmfwupgUpgradeCtx* pFwu time_t start,end; /* Put pointer after image header */ - pImagePtr = (unsigned char*) + pImagePtr = (unsigned char*) (pFwupgCtx->pImageData + sizeof(struct HpmfwupgImageHeader) + pImageHeader->oemDataLength + sizeof(unsigned char)/*checksum*/); - - /* Deternime actions size */ - actionsSize = pFwupgCtx->imageSize - sizeof(struct HpmfwupgImageHeader); - + + /* Deternime actions size */ + actionsSize = pFwupgCtx->imageSize - sizeof(struct HpmfwupgImageHeader); if (option & VERSIONCHECK_MODE || option & FORCE_MODE) { @@ -1965,21 +1991,21 @@ int HpmfwupgUpgradeStage(struct ipmi_intf *intf, struct HpmfwupgUpgradeCtx* pFwu } /* Perform actions defined in the image */ - while( ( pImagePtr < (pFwupgCtx->pImageData + pFwupgCtx->imageSize - + while( ( pImagePtr < (pFwupgCtx->pImageData + pFwupgCtx->imageSize - HPMFWUPG_MD5_SIGNATURE_LENGTH)) && ( rc == HPMFWUPG_SUCCESS) ) { /* Get action record */ pActionRecord = (struct HpmfwupgActionRecord*)pImagePtr; - + /* Validate action record checksum */ - if ( HpmfwupgCalculateChecksum((unsigned char*)pActionRecord, + if ( HpmfwupgCalculateChecksum((unsigned char*)pActionRecord, sizeof(struct HpmfwupgActionRecord)) != 0 ) { lprintf(LOG_NOTICE," Invalid Action record."); rc = HPMFWUPG_ERROR; } - + if ( rc == HPMFWUPG_SUCCESS ) { switch( pActionRecord->actionType ) @@ -1988,22 +2014,22 @@ int HpmfwupgUpgradeStage(struct ipmi_intf *intf, struct HpmfwupgUpgradeCtx* pFwu { /* Send prepare components command */ struct HpmfwupgInitiateUpgradeActionCtx initUpgActionCmd; - + initUpgActionCmd.req.componentsMask = pActionRecord->components; /* Action is prepare components */ initUpgActionCmd.req.upgradeAction = HPMFWUPG_UPGRADE_ACTION_BACKUP; rc = HpmfwupgInitiateUpgradeAction(intf, &initUpgActionCmd, pFwupgCtx); pImagePtr += sizeof(struct HpmfwupgActionRecord); - + } break; case HPMFWUPG_ACTION_PREPARE_COMPONENTS: { int componentId; - /* Make sure every components specified by this action + /* Make sure every components specified by this action supports the prepare components */ componentToUploadMsk.ComponentBits.byte = 0x00; - for ( componentId = HPMFWUPG_COMPONENT_ID_0; + for ( componentId = HPMFWUPG_COMPONENT_ID_0; componentId < HPMFWUPG_COMPONENT_ID_MAX; componentId++ ) { @@ -2017,7 +2043,7 @@ int HpmfwupgUpgradeStage(struct ipmi_intf *intf, struct HpmfwupgUpgradeCtx* pFwu } if (!gVersionInfo[componentId].skipUpgrade) { - /* If the component needs not to be skipped then you need to + /* If the component needs not to be skipped then you need to * add it in componentToUploadMsk */ componentToUploadMsk.ComponentBits.byte |= 1<components.ComponentBits.byte; } @@ -2046,7 +2072,7 @@ int HpmfwupgUpgradeStage(struct ipmi_intf *intf, struct HpmfwupgUpgradeCtx* pFwu /* Action is prepare components */ initUpgActionCmd.req.upgradeAction = HPMFWUPG_UPGRADE_ACTION_PREPARE; rc = HpmfwupgInitiateUpgradeAction(intf, &initUpgActionCmd, pFwupgCtx); - } + } pImagePtr += sizeof(struct HpmfwupgActionRecord); } } @@ -2054,275 +2080,17 @@ int HpmfwupgUpgradeStage(struct ipmi_intf *intf, struct HpmfwupgUpgradeCtx* pFwu case HPMFWUPG_ACTION_UPLOAD_FIRMWARE: /* Upload all firmware blocks */ - { - struct HpmfwupgFirmwareImage* pFwImage; - struct HpmfwupgInitiateUpgradeActionCtx initUpgActionCmd; - struct HpmfwupgUploadFirmwareBlockCtx uploadCmd; - struct HpmfwupgFinishFirmwareUploadCtx finishCmd; - struct HpmfwupgGetComponentPropertiesCtx getCompProp; - VERSIONINFO *pVersionInfo; - - unsigned char* pData, *pDataInitial; - unsigned char count; - unsigned int totalSent = 0; - unsigned char bufLength = 0; - unsigned int firmwareLength = 0; - - unsigned int displayFWLength = 0; - unsigned char *pDataTemp; - unsigned int imageOffset = 0x00; - unsigned int blockLength = 0x00; - unsigned int lengthOfBlock = 0x00; - unsigned int numTxPkts = 0; - unsigned int numRxPkts = 0; - unsigned char mode = 0; - unsigned char componentId = 0x00; - unsigned char componentIdByte = 0x00; - + rc = HpmFwupgActionUploadFirmware + ( + pActionRecord->components, + pFwupgCtx, + &pImagePtr, + componentToUpload, + intf, + option, + &flagColdReset + ); - /* Save component ID on which the upload is done */ - componentIdByte = pActionRecord->components.ComponentBits.byte; - while ((componentIdByte>>=1)!=0) - { - componentId++; - } - pFwupgCtx->componentId = componentId; - - /* Initialize parameters */ - uploadCmd.req.blockNumber = 0; - pFwImage = (struct HpmfwupgFirmwareImage*)(pImagePtr + - sizeof(struct HpmfwupgActionRecord)); - -/* - * lprintf(LOG_NOTICE," Upgrading %s", pFwImage->desc); - * lprintf(LOG_NOTICE," with Version: Major: %d", pFwImage->version[0]); - * lprintf(LOG_NOTICE," Minor: %x", pFwImage->version[1]); - * lprintf(LOG_NOTICE," Aux : %03d %03d %03d %03d", pFwImage->version[2], - * pFwImage->version[3], - * pFwImage->version[4], - * pFwImage->version[5]); - */ - pDataInitial = ((unsigned char*)pFwImage + sizeof(struct HpmfwupgFirmwareImage)); - pData = pDataInitial; - - /* Find max buffer length according the connection parameters */ - if ( strstr(intf->name,"lan") != NULL ) - { - bufLength = HPMFWUPG_SEND_DATA_COUNT_LAN - 2; - if ( intf->transit_addr != intf->my_addr && intf->transit_addr != 0 ) - bufLength -= 8; - } - else - { - if - ( - strstr(intf->name,"open") != NULL - && - ( - intf->target_addr == intf->my_addr - ) - ) - { - bufLength = HPMFWUPG_SEND_DATA_COUNT_KCS - 2; - } - else - { - if ( intf->target_channel == 7 ) - { - bufLength = HPMFWUPG_SEND_DATA_COUNT_IPMBL; - } - else - { - bufLength = HPMFWUPG_SEND_DATA_COUNT_IPMB; - } - } - } - - /* Get firmware length */ - firmwareLength = pFwImage->length[0]; - firmwareLength |= (pFwImage->length[1] << 8) & 0xff00; - firmwareLength |= (pFwImage->length[2] << 16) & 0xff0000; - firmwareLength |= (pFwImage->length[3] << 24) & 0xff000000; - - if ( (!(1<components.ComponentBits.byte)) - && (componentToUpload != DEFAULT_COMPONENT_UPLOAD)) - { - /* We will skip if the user has given some components in command line "component 2" */ - pImagePtr = pDataInitial + firmwareLength; - break; - } - - /* Send initiate command */ - initUpgActionCmd.req.componentsMask = pActionRecord->components; - /* Action is upgrade */ - initUpgActionCmd.req.upgradeAction = HPMFWUPG_UPGRADE_ACTION_UPGRADE; - rc = HpmfwupgInitiateUpgradeAction(intf, &initUpgActionCmd, pFwupgCtx); - - if (rc != HPMFWUPG_SUCCESS) - { - break; - } - - pVersionInfo = (VERSIONINFO*) &gVersionInfo[componentId]; - - mode = TARGET_VER | IMAGE_VER; - if (pVersionInfo->rollbackSupported) - { - mode |= ROLLBACK_VER; - } - if ( pVersionInfo->coldResetRequired) - { - flagColdReset = TRUE; - } - if( (option & VERSIONCHECK_MODE) && pVersionInfo->skipUpgrade) - { - - HpmDisplayVersion(mode,pVersionInfo); - HpmDisplayUpgrade(1,0,0,0); - pImagePtr = pDataInitial + firmwareLength; - break; - } - - if ((option & DEBUG_MODE)) - { - printf("\n\n Comp ID : %d [%-20s]\n",pVersionInfo->componentId,pFwImage->desc); - } - else - { - HpmDisplayVersion(mode,pVersionInfo); - } - - /* pDataInitial is the starting pointer of the image data */ - /* pDataTemp is one which we will move across */ - pData = pDataInitial; - pDataTemp = pDataInitial; - lengthOfBlock = firmwareLength; - totalSent = 0x00; - displayFWLength= firmwareLength; - time(&start); - while ( (pData < (pDataTemp+lengthOfBlock)) && (rc == HPMFWUPG_SUCCESS) ) - { - if ( (pData+bufLength) <= (pDataTemp+lengthOfBlock) ) - { - count = bufLength; - } - else - { - count = (unsigned char)((pDataTemp+lengthOfBlock) - pData); - } - memcpy(&uploadCmd.req.data, pData, bufLength); - - imageOffset = 0x00; - blockLength = 0x00; - numTxPkts++; - rc = HpmfwupgUploadFirmwareBlock(intf, &uploadCmd, pFwupgCtx, count, - &imageOffset,&blockLength); - numRxPkts++; - - if ( rc != HPMFWUPG_SUCCESS) - { - if ( rc == HPMFWUPG_UPLOAD_BLOCK_LENGTH ) - { - /* Retry with a smaller buffer length */ - if ( strstr(intf->name,"lan") != NULL ) - { - bufLength -= (unsigned char)8; - } - else - { - bufLength -= (unsigned char)1; - } - rc = HPMFWUPG_SUCCESS; - } - else if ( rc == HPMFWUPG_UPLOAD_RETRY ) - { - rc = HPMFWUPG_SUCCESS; - } - else - { - fflush(stdout); - lprintf(LOG_NOTICE,"\n Error in Upload FIRMWARE command [rc=%d]\n",rc); - lprintf(LOG_NOTICE,"\n TotalSent:0x%x ",totalSent); - /* Exiting from the function */ - rc = HPMFWUPG_ERROR; - break; - } - } - else - { - if (blockLength > firmwareLength) - { - /* - * blockLength is the remaining length of the firnware to upload so - * if its greater than the firmware length then its kind of error - */ - lprintf(LOG_NOTICE,"\n Error in Upload FIRMWARE command [rc=%d]\n",rc); - lprintf(LOG_NOTICE,"\n TotalSent:0x%x Img offset:0x%x Blk length:0x%x Fwlen:0x%x\n", - totalSent,imageOffset,blockLength,firmwareLength); - rc = HPMFWUPG_ERROR; - break; - } - totalSent += count; - if (imageOffset != 0x00) - { - /* block Length is valid */ - lengthOfBlock = blockLength; - pDataTemp = pDataInitial + imageOffset; - pData = pDataTemp; - if ( displayFWLength == firmwareLength) - { - /* This is basically used only to make sure that we display uptil 100% */ - displayFWLength = blockLength + totalSent; - } - } - else - { - pData += count; - } - time(&end); - /* - * Just added debug mode in case we need to see exactly how many bytes have - * gone through - Its a hidden option used mainly should be used for debugging - */ - if ( option & DEBUG_MODE) - { - fflush(stdout); - printf(" Blk Num : %02x Bytes : %05x \r", - uploadCmd.req.blockNumber,totalSent); - if (imageOffset || blockLength) - { - printf("\n\r--> ImgOff : %x BlkLen : %x\n",imageOffset,blockLength); - } - if (displayFWLength == totalSent) - { - printf("\n Time Taken %02d:%02d",(end-start)/60, (end-start)%60); - printf("\n\n"); - } - } - else - { - HpmDisplayUpgrade(0,totalSent,displayFWLength,(end-start)); - } - uploadCmd.req.blockNumber++; - } - } - - if (rc == HPMFWUPG_SUCCESS) - { - /* Send finish component */ - /* Set image length */ - finishCmd.req.componentId = componentId; - /* We need to send the actual data that is sent - * not the comlete firmware image length - */ - finishCmd.req.imageLength[0] = totalSent & 0xFF; - finishCmd.req.imageLength[1] = (totalSent >> 8) & 0xFF; - finishCmd.req.imageLength[2] = (totalSent >> 16) & 0xFF; - finishCmd.req.imageLength[3] = (totalSent >> 24) & 0xFF; - rc = HpmfwupgFinishFirmwareUpload(intf, &finishCmd, pFwupgCtx); - pImagePtr = pDataInitial + firmwareLength; - } - } break; default: lprintf(LOG_NOTICE," Invalid Action type. Cannot continue"); @@ -2339,15 +2107,307 @@ int HpmfwupgUpgradeStage(struct ipmi_intf *intf, struct HpmfwupgUpgradeCtx* pFwu fflush(stdout); lprintf(LOG_NOTICE,"(*) Component requires Payload Cold Reset"); } - return rc; + return rc; } - + +static int HpmFwupgActionUploadFirmware +( + struct HpmfwupgComponentBitMask components, + struct HpmfwupgUpgradeCtx* pFwupgCtx, + unsigned char** pImagePtr, + int componentToUpload, + struct ipmi_intf *intf, + int option, + int *pFlagColdReset +) +{ + struct HpmfwupgFirmwareImage* pFwImage; + struct HpmfwupgInitiateUpgradeActionCtx initUpgActionCmd; + struct HpmfwupgUploadFirmwareBlockCtx uploadCmd; + struct HpmfwupgFinishFirmwareUploadCtx finishCmd; + struct HpmfwupgGetComponentPropertiesCtx getCompProp; + VERSIONINFO *pVersionInfo; + time_t start,end; + + int rc = HPMFWUPG_SUCCESS; + int skip = FALSE; + unsigned char* pData, *pDataInitial; + unsigned char count; + unsigned int totalSent = 0; + unsigned char bufLength = 0; + unsigned int firmwareLength = 0; + + unsigned int displayFWLength = 0; + unsigned char *pDataTemp; + unsigned int imageOffset = 0x00; + unsigned int blockLength = 0x00; + unsigned int lengthOfBlock = 0x00; + unsigned int numTxPkts = 0; + unsigned int numRxPkts = 0; + unsigned char mode = 0; + unsigned char componentId = 0x00; + unsigned char componentIdByte = 0x00; + + /* Save component ID on which the upload is done */ + componentIdByte = components.ComponentBits.byte; + while ((componentIdByte>>=1)!=0) + { + componentId++; + } + pFwupgCtx->componentId = componentId; + + pVersionInfo = (VERSIONINFO*) &gVersionInfo[componentId]; + + pFwImage = (struct HpmfwupgFirmwareImage*)((*pImagePtr) + + sizeof(struct HpmfwupgActionRecord)); + + pDataInitial = ((unsigned char*)pFwImage + sizeof(struct HpmfwupgFirmwareImage)); + pData = pDataInitial; + + /* Get firmware length */ + firmwareLength = pFwImage->length[0]; + firmwareLength |= (pFwImage->length[1] << 8) & 0xff00; + firmwareLength |= (pFwImage->length[2] << 16) & 0xff0000; + firmwareLength |= (pFwImage->length[3] << 24) & 0xff000000; + + mode = TARGET_VER | IMAGE_VER; + if (pVersionInfo->rollbackSupported) + { + mode |= ROLLBACK_VER; + } + + if ((option & DEBUG_MODE)) + { + printf("\n\n Comp ID : %d [%-20s]\n",pVersionInfo->componentId,pFwImage->desc); + } + else + { + HpmDisplayVersion(mode,pVersionInfo); + } + + if + ( + ( + (pVersionInfo->skipUpgrade) + || + ( + /* We will skip if the user has given some components in command line "component 2" */ + (!(1<name,"lan") != NULL ) + { + bufLength = HPMFWUPG_SEND_DATA_COUNT_LAN - 2; + if ( intf->transit_addr != intf->my_addr && intf->transit_addr != 0 ) + bufLength -= 8; + } + else + { + if + ( + strstr(intf->name,"open") != NULL + && + ( + intf->target_addr == intf->my_addr + ) + ) + { + bufLength = HPMFWUPG_SEND_DATA_COUNT_KCS - 2; + } + else + { + if ( intf->target_channel == 7 ) + { + bufLength = HPMFWUPG_SEND_DATA_COUNT_IPMBL; + } + else + { + bufLength = HPMFWUPG_SEND_DATA_COUNT_IPMB; + } + } + } + + /* Send Initiate Upgrade Action */ + initUpgActionCmd.req.componentsMask = components; + /* Action is upgrade */ + initUpgActionCmd.req.upgradeAction = HPMFWUPG_UPGRADE_ACTION_UPGRADE; + rc = HpmfwupgInitiateUpgradeAction(intf, &initUpgActionCmd, pFwupgCtx); + + if (rc != HPMFWUPG_SUCCESS) + { + skip = TRUE; + } + + if ( (pVersionInfo->coldResetRequired) && (!skip)) + { + *pFlagColdReset = TRUE; + } + /* pDataInitial is the starting pointer of the image data */ + /* pDataTemp is one which we will move across */ + pData = pDataInitial; + pDataTemp = pDataInitial; + lengthOfBlock = firmwareLength; + totalSent = 0x00; + displayFWLength= firmwareLength; + time(&start); + while ( (pData < (pDataTemp+lengthOfBlock)) && (rc == HPMFWUPG_SUCCESS) ) + { + if ( (pData+bufLength) <= (pDataTemp+lengthOfBlock) ) + { + count = bufLength; + } + else + { + count = (unsigned char)((pDataTemp+lengthOfBlock) - pData); + } + memcpy(&uploadCmd.req.data, pData, bufLength); + + imageOffset = 0x00; + blockLength = 0x00; + numTxPkts++; + rc = HpmfwupgUploadFirmwareBlock(intf, &uploadCmd, pFwupgCtx, count, + &imageOffset,&blockLength); + numRxPkts++; + + if ( rc != HPMFWUPG_SUCCESS) + { + if ( rc == HPMFWUPG_UPLOAD_BLOCK_LENGTH ) + { + /* Retry with a smaller buffer length */ + if ( strstr(intf->name,"lan") != NULL ) + { + bufLength -= (unsigned char)8; + } + else + { + bufLength -= (unsigned char)1; + } + rc = HPMFWUPG_SUCCESS; + } + else if ( rc == HPMFWUPG_UPLOAD_RETRY ) + { + rc = HPMFWUPG_SUCCESS; + } + else + { + fflush(stdout); + lprintf(LOG_NOTICE,"\n Error in Upload FIRMWARE command [rc=%d]\n",rc); + lprintf(LOG_NOTICE,"\n TotalSent:0x%x ",totalSent); + /* Exiting from the function */ + rc = HPMFWUPG_ERROR; + } + } + else + { + if (blockLength > firmwareLength) + { + /* + * blockLength is the remaining length of the firmware to upload so + * if its greater than the firmware length then its kind of error + */ + lprintf(LOG_NOTICE,"\n Error in Upload FIRMWARE command [rc=%d]\n",rc); + lprintf(LOG_NOTICE,"\n TotalSent:0x%x Img offset:0x%x Blk length:0x%x Fwlen:0x%x\n", + totalSent,imageOffset,blockLength,firmwareLength); + rc = HPMFWUPG_ERROR; + } + totalSent += count; + if (imageOffset != 0x00) + { + /* block Length is valid */ + lengthOfBlock = blockLength; + pDataTemp = pDataInitial + imageOffset; + pData = pDataTemp; + if ( displayFWLength == firmwareLength) + { + /* This is basically used only to make sure that we display uptil 100% */ + displayFWLength = blockLength + totalSent; + } + } + else + { + pData += count; + } + time(&end); + /* + * Just added debug mode in case we need to see exactly how many bytes have + * gone through - Its a hidden option used mainly should be used for debugging + */ + if ( option & DEBUG_MODE) + { + fflush(stdout); + printf(" Blk Num : %02x Bytes : %05x \r", + uploadCmd.req.blockNumber,totalSent); + if (imageOffset || blockLength) + { + printf("\n\r--> ImgOff : %x BlkLen : %x\n",imageOffset,blockLength); + } + if (displayFWLength == totalSent) + { + printf("\n Time Taken %02d:%02d",(end-start)/60, (end-start)%60); + printf("\n\n"); + } + } + else + { + HpmDisplayUpgrade(0,totalSent,displayFWLength,(end-start)); + } + uploadCmd.req.blockNumber++; + } + } + } + + if (skip) + { + + HpmDisplayUpgrade(1,0,0,0); + *pImagePtr = pDataInitial + firmwareLength; + } + + if + ( + (rc == HPMFWUPG_SUCCESS) + && + (!skip) + ) + { + /* Send finish component */ + /* Set image length */ + finishCmd.req.componentId = componentId; + /* We need to send the actual data that is sent + * not the comlete firmware image length + */ + finishCmd.req.imageLength[0] = totalSent & 0xFF; + finishCmd.req.imageLength[1] = (totalSent >> 8) & 0xFF; + finishCmd.req.imageLength[2] = (totalSent >> 16) & 0xFF; + finishCmd.req.imageLength[3] = (totalSent >> 24) & 0xFF; + rc = HpmfwupgFinishFirmwareUpload(intf, &finishCmd, pFwupgCtx); + *pImagePtr = pDataInitial + firmwareLength; + } + + return rc; +} + /**************************************************************************** * * Function Name: HpmfwupgActivationStage * -* Description: This function the validation stage of a firmware upgrade -* procedure as defined in section 3.4 of the IPM Controller +* Description: This function the validation stage of a firmware upgrade +* procedure as defined in section 3.4 of the IPM Controller * Firmware Upgrade Specification version 1.0 * *****************************************************************************/ @@ -2363,16 +2423,16 @@ static int HpmfwupgActivationStage(struct ipmi_intf *intf, struct HpmfwupgUpgrad fflush(stdout); /* Activate new firmware */ rc = HpmfwupgActivateFirmware(intf, &activateCmd, pFwupgCtx); - + if ( rc == HPMFWUPG_SUCCESS ) { /* Query self test result if supported by target and new image */ - if ( (pFwupgCtx->targetCap.GlobalCapabilities.bitField.ipmcSelftestCap == 1) || + if ( (pFwupgCtx->targetCap.GlobalCapabilities.bitField.ipmcSelftestCap == 1) || (pImageHeader->imageCapabilities.bitField.imageSelfTest == 1) ) { struct HpmfwupgQuerySelftestResultCtx selfTestCmd; rc = HpmfwupgQuerySelftestResult(intf, &selfTestCmd, pFwupgCtx); - + if ( rc == HPMFWUPG_SUCCESS ) { /* Get the self test result */ @@ -2394,7 +2454,7 @@ static int HpmfwupgActivationStage(struct ipmi_intf *intf, struct HpmfwupgUpgrad } } } - + /* If activation / self test failed, query rollback status if automatic rollback supported */ if ( rc == HPMFWUPG_ERROR ) { @@ -2407,26 +2467,26 @@ static int HpmfwupgActivationStage(struct ipmi_intf *intf, struct HpmfwupgUpgrad rc = HpmfwupgQueryRollbackStatus(intf, &rollCmd, pFwupgCtx); } } - + return rc; -} +} int HpmfwupgGetBufferFromFile(char* imageFilename, struct HpmfwupgUpgradeCtx* pFwupgCtx) { int rc = HPMFWUPG_SUCCESS; FILE* pImageFile = fopen(imageFilename, "rb"); - + if ( pImageFile == NULL ) { lprintf(LOG_NOTICE,"Cannot open image file %s", imageFilename); rc = HPMFWUPG_ERROR; } - + if ( rc == HPMFWUPG_SUCCESS ) { /* Get the raw data in file */ fseek(pImageFile, 0, SEEK_END); - pFwupgCtx->imageSize = ftell(pImageFile); + pFwupgCtx->imageSize = ftell(pImageFile); pFwupgCtx->pImageData = malloc(sizeof(unsigned char)*pFwupgCtx->imageSize); rewind(pImageFile); if ( pFwupgCtx->pImageData != NULL ) @@ -2437,26 +2497,26 @@ int HpmfwupgGetBufferFromFile(char* imageFilename, struct HpmfwupgUpgradeCtx* pF { rc = HPMFWUPG_ERROR; } - + fclose(pImageFile); } - + return rc; -} +} int HpmfwupgGetDeviceId(struct ipmi_intf *intf, struct ipm_devid_rsp* pGetDevId) { int rc = HPMFWUPG_SUCCESS; struct ipmi_rs * rsp; struct ipmi_rq req; - + memset(&req, 0, sizeof(req)); req.msg.netfn = IPMI_NETFN_APP; req.msg.cmd = BMC_GET_DEVICE_ID; req.msg.data_len = 0; rsp = HpmfwupgSendCmd(intf, req, NULL); - + if ( rsp ) { if ( rsp->ccode == 0x00 ) @@ -2475,25 +2535,25 @@ int HpmfwupgGetDeviceId(struct ipmi_intf *intf, struct ipm_devid_rsp* pGetDevId) rc = HPMFWUPG_ERROR; } return rc; -} +} -int HpmfwupgGetTargetUpgCapabilities(struct ipmi_intf *intf, +int HpmfwupgGetTargetUpgCapabilities(struct ipmi_intf *intf, struct HpmfwupgGetTargetUpgCapabilitiesCtx* pCtx) { int rc = HPMFWUPG_SUCCESS; struct ipmi_rs * rsp; struct ipmi_rq req; - + pCtx->req.picmgId = HPMFWUPG_PICMG_IDENTIFIER; - + memset(&req, 0, sizeof(req)); req.msg.netfn = IPMI_NETFN_PICMG; req.msg.cmd = HPMFWUPG_GET_TARGET_UPG_CAPABILITIES; req.msg.data = (unsigned char*)&pCtx->req; req.msg.data_len = sizeof(struct HpmfwupgGetTargetUpgCapabilitiesReq); - + rsp = HpmfwupgSendCmd(intf, req, NULL); - + if ( rsp ) { if ( rsp->ccode == 0x00 ) @@ -2507,36 +2567,36 @@ int HpmfwupgGetTargetUpgCapabilities(struct ipmi_intf *intf, lprintf(LOG_NOTICE,"Component 0 presence....[%c] ", pCtx->resp.componentsPresent.ComponentBits. bitField.component0 ? 'y' : 'n'); lprintf(LOG_NOTICE,"Component 1 presence....[%c] ", pCtx->resp.componentsPresent.ComponentBits. - bitField.component1 ? 'y' : 'n'); + bitField.component1 ? 'y' : 'n'); lprintf(LOG_NOTICE,"Component 2 presence....[%c] ", pCtx->resp.componentsPresent.ComponentBits. - bitField.component2 ? 'y' : 'n'); + bitField.component2 ? 'y' : 'n'); lprintf(LOG_NOTICE,"Component 3 presence....[%c] ", pCtx->resp.componentsPresent.ComponentBits. bitField.component3 ? 'y' : 'n'); lprintf(LOG_NOTICE,"Component 4 presence....[%c] ", pCtx->resp.componentsPresent.ComponentBits. bitField.component4 ? 'y' : 'n'); lprintf(LOG_NOTICE,"Component 5 presence....[%c] ", pCtx->resp.componentsPresent.ComponentBits. - bitField.component5 ? 'y' : 'n'); + bitField.component5 ? 'y' : 'n'); lprintf(LOG_NOTICE,"Component 6 presence....[%c] ", pCtx->resp.componentsPresent.ComponentBits. - bitField.component6 ? 'y' : 'n'); + bitField.component6 ? 'y' : 'n'); lprintf(LOG_NOTICE,"Component 7 presence....[%c] ", pCtx->resp.componentsPresent.ComponentBits. bitField.component7 ? 'y' : 'n'); lprintf(LOG_NOTICE,"Upgrade undesirable.....[%c] ", pCtx->resp.GlobalCapabilities. - bitField.fwUpgUndesirable ? 'y' : 'n'); + bitField.fwUpgUndesirable ? 'y' : 'n'); lprintf(LOG_NOTICE,"Aut rollback override...[%c] ", pCtx->resp.GlobalCapabilities. - bitField.autRollbackOverride ? 'y' : 'n'); + bitField.autRollbackOverride ? 'y' : 'n'); lprintf(LOG_NOTICE,"IPMC degraded...........[%c] ", pCtx->resp.GlobalCapabilities. bitField.ipmcDegradedDurinUpg ? 'y' : 'n'); lprintf(LOG_NOTICE,"Defered activation......[%c] ", pCtx->resp.GlobalCapabilities. bitField.deferActivation ? 'y' : 'n'); lprintf(LOG_NOTICE,"Service affected........[%c] ", pCtx->resp.GlobalCapabilities. - bitField.servAffectDuringUpg ? 'y' : 'n'); + bitField.servAffectDuringUpg ? 'y' : 'n'); lprintf(LOG_NOTICE,"Manual rollback.........[%c] ", pCtx->resp.GlobalCapabilities. - bitField.manualRollback ? 'y' : 'n'); + bitField.manualRollback ? 'y' : 'n'); lprintf(LOG_NOTICE,"Automatic rollback......[%c] ", pCtx->resp.GlobalCapabilities. - bitField.autRollback ? 'y' : 'n'); + bitField.autRollback ? 'y' : 'n'); lprintf(LOG_NOTICE,"Self test...............[%c] ", pCtx->resp.GlobalCapabilities. bitField.ipmcSelftestCap ? 'y' : 'n'); - lprintf(LOG_NOTICE,"Upgrade timeout.........[%d sec] ", pCtx->resp.upgradeTimeout*5); + lprintf(LOG_NOTICE,"Upgrade timeout.........[%d sec] ", pCtx->resp.upgradeTimeout*5); lprintf(LOG_NOTICE,"Self test timeout.......[%d sec] ", pCtx->resp.selftestTimeout*5); lprintf(LOG_NOTICE,"Rollback timeout........[%d sec] ", pCtx->resp.rollbackTimeout*5); lprintf(LOG_NOTICE,"Inaccessibility timeout.[%d sec] \n", pCtx->resp.rollbackTimeout*5); @@ -2553,11 +2613,11 @@ int HpmfwupgGetTargetUpgCapabilities(struct ipmi_intf *intf, lprintf(LOG_NOTICE,"Error getting target upgrade capabilities\n"); rc = HPMFWUPG_ERROR; } - - - + + + return rc; -} +} int HpmfwupgGetComponentProperties(struct ipmi_intf *intf, struct HpmfwupgGetComponentPropertiesCtx* pCtx) @@ -2565,9 +2625,9 @@ int HpmfwupgGetComponentProperties(struct ipmi_intf *intf, struct HpmfwupgGetCom int rc = HPMFWUPG_SUCCESS; struct ipmi_rs * rsp; struct ipmi_rq req; - + pCtx->req.picmgId = HPMFWUPG_PICMG_IDENTIFIER; - + memset(&req, 0, sizeof(req)); req.msg.netfn = IPMI_NETFN_PICMG; req.msg.cmd = HPMFWUPG_GET_COMPONENT_PROPERTIES; @@ -2575,11 +2635,11 @@ int HpmfwupgGetComponentProperties(struct ipmi_intf *intf, struct HpmfwupgGetCom req.msg.data_len = sizeof(struct HpmfwupgGetComponentPropertiesReq); rsp = HpmfwupgSendCmd(intf, req, NULL); - + if ( rsp ) { if ( rsp->ccode == 0x00 ) - { + { switch ( pCtx->req.selector ) { case HPMFWUPG_COMP_GEN_PROPERTIES: @@ -2591,11 +2651,11 @@ int HpmfwupgGetComponentProperties(struct ipmi_intf *intf, struct HpmfwupgGetCom lprintf(LOG_NOTICE,"Payload cold reset req....[%c] ", pCtx->resp.Response.generalPropResp. GeneralCompProperties.bitfield.payloadColdReset ? 'y' : 'n'); lprintf(LOG_NOTICE,"Def. activation supported.[%c] ", pCtx->resp.Response.generalPropResp. - GeneralCompProperties.bitfield.deferredActivation ? 'y' : 'n'); + GeneralCompProperties.bitfield.deferredActivation ? 'y' : 'n'); lprintf(LOG_NOTICE,"Comparison supported......[%c] ", pCtx->resp.Response.generalPropResp. GeneralCompProperties.bitfield.comparisonSupport ? 'y' : 'n'); lprintf(LOG_NOTICE,"Preparation supported.....[%c] ", pCtx->resp.Response.generalPropResp. - GeneralCompProperties.bitfield.preparationSupport ? 'y' : 'n'); + GeneralCompProperties.bitfield.preparationSupport ? 'y' : 'n'); lprintf(LOG_NOTICE,"Rollback supported........[%c] \n", pCtx->resp.Response.generalPropResp. GeneralCompProperties.bitfield.rollbackBackup ? 'y' : 'n'); } @@ -2611,8 +2671,8 @@ int HpmfwupgGetComponentProperties(struct ipmi_intf *intf, struct HpmfwupgGetCom pCtx->resp.Response.currentVersionResp.currentVersion[3], pCtx->resp.Response.currentVersionResp.currentVersion[4], pCtx->resp.Response.currentVersionResp.currentVersion[5]); - } - break; + } + break; case HPMFWUPG_COMP_DESCRIPTION_STRING: memcpy(&pCtx->resp, rsp->data, sizeof(struct HpmfwupgGetDescStringResp)); if ( verbose ) @@ -2631,7 +2691,7 @@ int HpmfwupgGetComponentProperties(struct ipmi_intf *intf, struct HpmfwupgGetCom pCtx->resp.Response.rollbackFwVersionResp.rollbackFwVersion[3], pCtx->resp.Response.rollbackFwVersionResp.rollbackFwVersion[4], pCtx->resp.Response.rollbackFwVersionResp.rollbackFwVersion[5]); - } + } break; case HPMFWUPG_COMP_DEFERRED_FIRMWARE_VERSION: memcpy(&pCtx->resp, rsp->data, sizeof(struct HpmfwupgGetDeferredFwVersionResp)); @@ -2644,9 +2704,9 @@ int HpmfwupgGetComponentProperties(struct ipmi_intf *intf, struct HpmfwupgGetCom pCtx->resp.Response.deferredFwVersionResp.deferredFwVersion[3], pCtx->resp.Response.deferredFwVersionResp.deferredFwVersion[4], pCtx->resp.Response.deferredFwVersionResp.deferredFwVersion[5]); - } + } break; - // OEM Properties command + // OEM Properties command case HPMFWUPG_COMP_OEM_PROPERTIES: memcpy(&pCtx->resp, rsp->data, sizeof(struct HpmfwupgGetOemProperties)); if ( verbose ) @@ -2657,14 +2717,14 @@ int HpmfwupgGetComponentProperties(struct ipmi_intf *intf, struct HpmfwupgGetCom { lprintf(LOG_NOTICE," 0x%x ", pCtx->resp.Response.oemProperties.oemRspData[i]); } - } + } break; default: lprintf(LOG_NOTICE,"Unsupported component selector"); rc = HPMFWUPG_ERROR; break; } - } + } else { lprintf(LOG_NOTICE,"Error getting component properties, compcode = %x\n", rsp->ccode); @@ -2676,27 +2736,27 @@ int HpmfwupgGetComponentProperties(struct ipmi_intf *intf, struct HpmfwupgGetCom lprintf(LOG_NOTICE,"Error getting component properties\n"); rc = HPMFWUPG_ERROR; } - - - return rc; -} -int HpmfwupgAbortUpgrade(struct ipmi_intf *intf, struct HpmfwupgAbortUpgradeCtx* pCtx) + + return rc; +} + +int HpmfwupgAbortUpgrade(struct ipmi_intf *intf, struct HpmfwupgAbortUpgradeCtx* pCtx) { int rc = HPMFWUPG_SUCCESS; struct ipmi_rs * rsp; struct ipmi_rq req; - + pCtx->req.picmgId = HPMFWUPG_PICMG_IDENTIFIER; - + memset(&req, 0, sizeof(req)); req.msg.netfn = IPMI_NETFN_PICMG; req.msg.cmd = HPMFWUPG_ABORT_UPGRADE; req.msg.data = (unsigned char*)&pCtx->req; req.msg.data_len = sizeof(struct HpmfwupgAbortUpgradeReq); - - rsp = HpmfwupgSendCmd(intf, req, NULL); - + + rsp = HpmfwupgSendCmd(intf, req, NULL); + if ( rsp ) { if ( rsp->ccode != 0x00 ) @@ -2711,7 +2771,7 @@ int HpmfwupgAbortUpgrade(struct ipmi_intf *intf, struct HpmfwupgAbortUpgradeCtx* rc = HPMFWUPG_ERROR; } return rc; -} +} int HpmfwupgInitiateUpgradeAction(struct ipmi_intf *intf, struct HpmfwupgInitiateUpgradeActionCtx* pCtx, struct HpmfwupgUpgradeCtx* pFwupgCtx) @@ -2719,17 +2779,17 @@ int HpmfwupgInitiateUpgradeAction(struct ipmi_intf *intf, struct HpmfwupgInitiat int rc = HPMFWUPG_SUCCESS; struct ipmi_rs * rsp; struct ipmi_rq req; - + pCtx->req.picmgId = HPMFWUPG_PICMG_IDENTIFIER; - + memset(&req, 0, sizeof(req)); req.msg.netfn = IPMI_NETFN_PICMG; req.msg.cmd = HPMFWUPG_INITIATE_UPGRADE_ACTION; req.msg.data = (unsigned char*)&pCtx->req; req.msg.data_len = sizeof(struct HpmfwupgInitiateUpgradeActionReq); - - rsp = HpmfwupgSendCmd(intf, req, pFwupgCtx); - + + rsp = HpmfwupgSendCmd(intf, req, pFwupgCtx); + if ( rsp ) { /* Long duration command handling */ @@ -2750,9 +2810,9 @@ int HpmfwupgInitiateUpgradeAction(struct ipmi_intf *intf, struct HpmfwupgInitiat } return rc; -} +} -int HpmfwupgUploadFirmwareBlock(struct ipmi_intf *intf, struct HpmfwupgUploadFirmwareBlockCtx* pCtx, +int HpmfwupgUploadFirmwareBlock(struct ipmi_intf *intf, struct HpmfwupgUploadFirmwareBlockCtx* pCtx, struct HpmfwupgUpgradeCtx* pFwupgCtx, int count ,unsigned int *imageOffset, unsigned int *blockLength ) { @@ -2768,26 +2828,26 @@ int HpmfwupgUploadFirmwareBlock(struct ipmi_intf *intf, struct HpmfwupgUploadFir req.msg.data = (unsigned char*)&pCtx->req; /* 2 is the size of the upload struct - data */ req.msg.data_len = 2 + count; - - rsp = HpmfwupgSendCmd(intf, req, pFwupgCtx); - + + rsp = HpmfwupgSendCmd(intf, req, pFwupgCtx); + if ( rsp ) { - if ( rsp->ccode == HPMFWUPG_COMMAND_IN_PROGRESS || + if ( rsp->ccode == HPMFWUPG_COMMAND_IN_PROGRESS || rsp->ccode == 0x00 ) { - /* - * We need to check if the response also contains the next upload firmware offset + /* + * We need to check if the response also contains the next upload firmware offset * and the firmware length in its response - These are optional but very vital */ if ( rsp->data_len > 1 ) { - /* - * If the response data length is greater than 1 it should contain both the - * the Section offset and section length. Because we cannot just have + /* + * If the response data length is greater than 1 it should contain both the + * the Section offset and section length. Because we cannot just have * Section offset without section length so the length should be 9 */ - if ( rsp->data_len == 9 ) + if ( rsp->data_len == 9 ) { /* rsp->data[1] - LSB rsp->data[2] - rsp->data[3] = MSB */ *imageOffset = (rsp->data[4] << 24) + (rsp->data[3] << 16) + (rsp->data[2] << 8) + rsp->data[1]; @@ -2796,8 +2856,8 @@ int HpmfwupgUploadFirmwareBlock(struct ipmi_intf *intf, struct HpmfwupgUploadFir else { /* - * The Spec does not say much for this kind of errors where the - * firmware returned only offset and length so currently returning it + * The Spec does not say much for this kind of errors where the + * firmware returned only offset and length so currently returning it * as 0x82 - Internal CheckSum Error */ lprintf(LOG_NOTICE,"Error wrong rsp->datalen %d for Upload Firmware block command\n",rsp->data_len); @@ -2810,7 +2870,7 @@ int HpmfwupgUploadFirmwareBlock(struct ipmi_intf *intf, struct HpmfwupgUploadFir { rc = HpmfwupgWaitLongDurationCmd(intf, pFwupgCtx); } - /* + /* * If we get 0xcc here this is probably because we send an invalid sequence * number (Packet sent twice). Continue as if we had no error. */ @@ -2818,7 +2878,7 @@ int HpmfwupgUploadFirmwareBlock(struct ipmi_intf *intf, struct HpmfwupgUploadFir { /* * PATCH --> This validation is to handle retryables errors codes on IPMB bus. - * This will be fixed in the next release of open ipmi and this + * This will be fixed in the next release of open ipmi and this * check will have to be removed. (Buggy version = 39) */ if ( HPMFWUPG_IS_RETRYABLE(rsp->ccode) ) @@ -2826,8 +2886,8 @@ int HpmfwupgUploadFirmwareBlock(struct ipmi_intf *intf, struct HpmfwupgUploadFir lprintf(LOG_DEBUG,"HPM: [PATCH]Retryable error detected"); rc = HPMFWUPG_UPLOAD_RETRY; } - /* - * If completion code = 0xc7, we will retry with a reduced buffer length. + /* + * If completion code = 0xc7, we will retry with a reduced buffer length. * Do not print error. */ else if ( rsp->ccode == IPMI_CC_REQ_DATA_INV_LENGTH ) @@ -2846,27 +2906,27 @@ int HpmfwupgUploadFirmwareBlock(struct ipmi_intf *intf, struct HpmfwupgUploadFir lprintf(LOG_NOTICE,"Error uploading firmware block\n"); rc = HPMFWUPG_ERROR; } - + return rc; -} +} int HpmfwupgFinishFirmwareUpload(struct ipmi_intf *intf, struct HpmfwupgFinishFirmwareUploadCtx* pCtx, - struct HpmfwupgUpgradeCtx* pFwupgCtx) + struct HpmfwupgUpgradeCtx* pFwupgCtx) { int rc = HPMFWUPG_SUCCESS; struct ipmi_rs * rsp; struct ipmi_rq req; - + pCtx->req.picmgId = HPMFWUPG_PICMG_IDENTIFIER; - + memset(&req, 0, sizeof(req)); req.msg.netfn = IPMI_NETFN_PICMG; req.msg.cmd = HPMFWUPG_FINISH_FIRMWARE_UPLOAD; req.msg.data = (unsigned char*)&pCtx->req; req.msg.data_len = sizeof(struct HpmfwupgFinishFirmwareUploadReq); - - rsp = HpmfwupgSendCmd(intf, req, pFwupgCtx); - + + rsp = HpmfwupgSendCmd(intf, req, pFwupgCtx); + if ( rsp ) { /* Long duration command handling */ @@ -2885,28 +2945,28 @@ int HpmfwupgFinishFirmwareUpload(struct ipmi_intf *intf, struct HpmfwupgFinishFi lprintf(LOG_NOTICE,"Error fininshing firmware upload\n"); rc = HPMFWUPG_ERROR; } - + return rc; -} +} int HpmfwupgActivateFirmware(struct ipmi_intf *intf, struct HpmfwupgActivateFirmwareCtx* pCtx, - struct HpmfwupgUpgradeCtx* pFwupgCtx) + struct HpmfwupgUpgradeCtx* pFwupgCtx) { int rc = HPMFWUPG_SUCCESS; struct ipmi_rs * rsp; struct ipmi_rq req; - + pCtx->req.picmgId = HPMFWUPG_PICMG_IDENTIFIER; - + memset(&req, 0, sizeof(req)); req.msg.netfn = IPMI_NETFN_PICMG; req.msg.cmd = HPMFWUPG_ACTIVATE_FIRMWARE; req.msg.data = (unsigned char*)&pCtx->req; req.msg.data_len = sizeof(struct HpmfwupgActivateFirmwareReq) - (!pCtx->req.rollback_override ? 1 : 0); - - rsp = HpmfwupgSendCmd(intf, req, pFwupgCtx); - + + rsp = HpmfwupgSendCmd(intf, req, pFwupgCtx); + if ( rsp ) { /* Long duration command handling */ @@ -2914,7 +2974,7 @@ int HpmfwupgActivateFirmware(struct ipmi_intf *intf, struct HpmfwupgActivateFirm { printf("Waiting firmware activation..."); fflush(stdout); - + rc = HpmfwupgWaitLongDurationCmd(intf, pFwupgCtx); if ( rc == HPMFWUPG_SUCCESS ) @@ -2928,7 +2988,7 @@ int HpmfwupgActivateFirmware(struct ipmi_intf *intf, struct HpmfwupgActivateFirm } else if ( rsp->ccode != IPMI_CC_OK ) { - lprintf(LOG_NOTICE,"Error activating firmware, compcode = %x\n", + lprintf(LOG_NOTICE,"Error activating firmware, compcode = %x\n", rsp->ccode); rc = HPMFWUPG_ERROR; } @@ -2940,7 +3000,7 @@ int HpmfwupgActivateFirmware(struct ipmi_intf *intf, struct HpmfwupgActivateFirm } return rc; -} +} int HpmfwupgGetUpgradeStatus(struct ipmi_intf *intf, struct HpmfwupgGetUpgradeStatusCtx* pCtx, struct HpmfwupgUpgradeCtx* pFwupgCtx) @@ -2948,19 +3008,19 @@ int HpmfwupgGetUpgradeStatus(struct ipmi_intf *intf, struct HpmfwupgGetUpgradeSt int rc = HPMFWUPG_SUCCESS; struct ipmi_rs * rsp; struct ipmi_rq req; - + pCtx->req.picmgId = HPMFWUPG_PICMG_IDENTIFIER; - + memset(&req, 0, sizeof(req)); req.msg.netfn = IPMI_NETFN_PICMG; req.msg.cmd = HPMFWUPG_GET_UPGRADE_STATUS; req.msg.data = (unsigned char*)&pCtx->req; req.msg.data_len = sizeof(struct HpmfwupgGetUpgradeStatusReq); - + rsp = HpmfwupgSendCmd(intf, req, pFwupgCtx); - + if ( rsp ) - { + { if ( rsp->ccode == 0x00 ) { memcpy(&pCtx->resp, rsp->data, sizeof(struct HpmfwupgGetUpgradeStatusResp)); @@ -2973,7 +3033,7 @@ int HpmfwupgGetUpgradeStatus(struct ipmi_intf *intf, struct HpmfwupgGetUpgradeSt } /* * PATCH --> This validation is to handle retryables errors codes on IPMB bus. - * This will be fixed in the next release of open ipmi and this + * This will be fixed in the next release of open ipmi and this * check will have to be removed. (Buggy version = 39) */ else if ( HPMFWUPG_IS_RETRYABLE(rsp->ccode) ) @@ -2999,9 +3059,9 @@ int HpmfwupgGetUpgradeStatus(struct ipmi_intf *intf, struct HpmfwupgGetUpgradeSt rc = HPMFWUPG_ERROR; } } - + return rc; -} +} int HpmfwupgManualFirmwareRollback(struct ipmi_intf *intf, struct HpmfwupgManualFirmwareRollbackCtx* pCtx, struct HpmfwupgUpgradeCtx* pFwupgCtx) @@ -3009,17 +3069,17 @@ int HpmfwupgManualFirmwareRollback(struct ipmi_intf *intf, struct HpmfwupgManual int rc = HPMFWUPG_SUCCESS; struct ipmi_rs * rsp; struct ipmi_rq req; - + pCtx->req.picmgId = HPMFWUPG_PICMG_IDENTIFIER; - + memset(&req, 0, sizeof(req)); req.msg.netfn = IPMI_NETFN_PICMG; req.msg.cmd = HPMFWUPG_MANUAL_FIRMWARE_ROLLBACK; req.msg.data = (unsigned char*)&pCtx->req; req.msg.data_len = sizeof(struct HpmfwupgManualFirmwareRollbackReq); - - rsp = HpmfwupgSendCmd(intf, req, pFwupgCtx); - + + rsp = HpmfwupgSendCmd(intf, req, pFwupgCtx); + if ( rsp ) { /* Long duration command handling */ @@ -3042,7 +3102,7 @@ int HpmfwupgManualFirmwareRollback(struct ipmi_intf *intf, struct HpmfwupgManual rc = HPMFWUPG_ERROR; } return rc; -} +} int HpmfwupgQueryRollbackStatus(struct ipmi_intf *intf, struct HpmfwupgQueryRollbackStatusCtx* pCtx, struct HpmfwupgUpgradeCtx* pFwupgCtx) @@ -3052,16 +3112,16 @@ int HpmfwupgQueryRollbackStatus(struct ipmi_intf *intf, struct HpmfwupgQueryRoll struct ipmi_rq req; unsigned char rollbackTimeout = 0; unsigned int timeoutSec1, timeoutSec2; - + pCtx->req.picmgId = HPMFWUPG_PICMG_IDENTIFIER; - + memset(&req, 0, sizeof(req)); req.msg.netfn = IPMI_NETFN_PICMG; req.msg.cmd = HPMFWUPG_QUERY_ROLLBACK_STATUS; req.msg.data = (unsigned char*)&pCtx->req; req.msg.data_len = sizeof(struct HpmfwupgQueryRollbackStatusReq); - - /* + + /* * If we are not in upgrade context, we use default timeout values */ if ( pFwupgCtx != NULL ) @@ -3072,7 +3132,7 @@ int HpmfwupgQueryRollbackStatus(struct ipmi_intf *intf, struct HpmfwupgQueryRoll { rollbackTimeout = HPMFWUPG_DEFAULT_UPGRADE_TIMEOUT; } - + /* Poll rollback status until completion or timeout */ timeoutSec1 = time(NULL); timeoutSec2 = time(NULL); @@ -3083,7 +3143,7 @@ int HpmfwupgQueryRollbackStatus(struct ipmi_intf *intf, struct HpmfwupgQueryRoll rsp = HpmfwupgSendCmd(intf, req, pFwupgCtx); /* * PATCH --> This validation is to handle retryables errors codes on IPMB bus. - * This will be fixed in the next release of open ipmi and this + * This will be fixed in the next release of open ipmi and this * check will have to be removed. (Buggy version = 39) */ if ( rsp ) @@ -3095,11 +3155,11 @@ int HpmfwupgQueryRollbackStatus(struct ipmi_intf *intf, struct HpmfwupgQueryRoll } } timeoutSec2 = time(NULL); - + }while( rsp && (rsp->ccode == HPMFWUPG_COMMAND_IN_PROGRESS) && (timeoutSec2 - timeoutSec1 < rollbackTimeout ) ); - + if ( rsp ) { if ( rsp->ccode == 0x00 ) @@ -3118,7 +3178,7 @@ int HpmfwupgQueryRollbackStatus(struct ipmi_intf *intf, struct HpmfwupgQueryRoll } else if ( rsp->ccode == 0x81 ) { - lprintf(LOG_NOTICE,"Rollback failed on component mask: 0x%02x", + lprintf(LOG_NOTICE,"Rollback failed on component mask: 0x%02x", pCtx->resp.rollbackComp.ComponentBits.byte); rc = HPMFWUPG_ERROR; } @@ -3133,22 +3193,22 @@ int HpmfwupgQueryRollbackStatus(struct ipmi_intf *intf, struct HpmfwupgQueryRoll lprintf(LOG_NOTICE,"Error getting upgrade status\n"); rc = HPMFWUPG_ERROR; } - + return rc; -} +} int HpmfwupgQuerySelftestResult(struct ipmi_intf *intf, struct HpmfwupgQuerySelftestResultCtx* pCtx, - struct HpmfwupgUpgradeCtx* pFwupgCtx) + struct HpmfwupgUpgradeCtx* pFwupgCtx) { int rc = HPMFWUPG_SUCCESS; struct ipmi_rs * rsp; struct ipmi_rq req; unsigned char selfTestTimeout = 0; unsigned int timeoutSec1, timeoutSec2; - + pCtx->req.picmgId = HPMFWUPG_PICMG_IDENTIFIER; - - /* + + /* * If we are not in upgrade context, we use default timeout values */ if ( pFwupgCtx != NULL ) @@ -3162,14 +3222,14 @@ int HpmfwupgQuerySelftestResult(struct ipmi_intf *intf, struct HpmfwupgQuerySelf { selfTestTimeout = HPMFWUPG_DEFAULT_UPGRADE_TIMEOUT; } - + memset(&req, 0, sizeof(req)); req.msg.netfn = IPMI_NETFN_PICMG; req.msg.cmd = HPMFWUPG_QUERY_SELFTEST_RESULT; req.msg.data = (unsigned char*)&pCtx->req; req.msg.data_len = sizeof(struct HpmfwupgQuerySelftestResultReq); - - + + /* Poll rollback status until completion or timeout */ timeoutSec1 = time(NULL); timeoutSec2 = time(NULL); @@ -3180,7 +3240,7 @@ int HpmfwupgQuerySelftestResult(struct ipmi_intf *intf, struct HpmfwupgQuerySelf rsp = HpmfwupgSendCmd(intf, req, pFwupgCtx); /* * PATCH --> This validation is to handle retryables errors codes on IPMB bus. - * This will be fixed in the next release of open ipmi and this + * This will be fixed in the next release of open ipmi and this * check will have to be removed. (Buggy version = 39) */ if ( rsp ) @@ -3192,11 +3252,11 @@ int HpmfwupgQuerySelftestResult(struct ipmi_intf *intf, struct HpmfwupgQuerySelf } } timeoutSec2 = time(NULL); - + }while( rsp && (rsp->ccode == HPMFWUPG_COMMAND_IN_PROGRESS) && (timeoutSec2 - timeoutSec1 < selfTestTimeout ) ); - + if ( rsp ) { if ( rsp->ccode == 0x00 ) @@ -3220,20 +3280,20 @@ int HpmfwupgQuerySelftestResult(struct ipmi_intf *intf, struct HpmfwupgQuerySelf lprintf(LOG_NOTICE,"Error getting upgrade status\n"); rc = HPMFWUPG_ERROR; } - + return rc; } -struct ipmi_rs * HpmfwupgSendCmd(struct ipmi_intf *intf, struct ipmi_rq req, +struct ipmi_rs * HpmfwupgSendCmd(struct ipmi_intf *intf, struct ipmi_rq req, struct HpmfwupgUpgradeCtx* pFwupgCtx ) { struct ipmi_rs * rsp; unsigned char inaccessTimeout = 0, inaccessTimeoutCounter = 0; unsigned char upgradeTimeout = 0, upgradeTimeoutCounter = 0; unsigned int timeoutSec1, timeoutSec2; - unsigned char retry = 0; - - /* + unsigned char retry = 0; + + /* * If we are not in upgrade context, we use default timeout values */ if ( pFwupgCtx != NULL ) @@ -3243,7 +3303,7 @@ struct ipmi_rs * HpmfwupgSendCmd(struct ipmi_intf *intf, struct ipmi_rq req, } else { - /* keeping the inaccessTimeout to 60 seconds results in almost 2900 retries + /* keeping the inaccessTimeout to 60 seconds results in almost 2900 retries * So if the target is not available it will be retrying the command for 2900 * times which is not effecient -So reducing the Timout to 5 seconds which is * almost 200 retries if it continuously recieves 0xC3 as completion code. @@ -3251,14 +3311,14 @@ struct ipmi_rs * HpmfwupgSendCmd(struct ipmi_intf *intf, struct ipmi_rq req, inaccessTimeout = HPMFWUPG_DEFAULT_UPGRADE_TIMEOUT; upgradeTimeout = HPMFWUPG_DEFAULT_UPGRADE_TIMEOUT; } - + timeoutSec1 = time(NULL); - + do { rsp = intf->sendrecv(intf, &req); - - if( rsp == NULL ) + + if( rsp == NULL ) { #define HPM_LAN_PACKET_RESIZE_LIMIT 6 if(strstr(intf->name,"lan")!= NULL) /* also covers lanplus */ @@ -3269,14 +3329,14 @@ struct ipmi_rs * HpmfwupgSendCmd(struct ipmi_intf *intf, struct ipmi_rq req, lprintf(LOG_DEBUG,"HPM: no response available"); lprintf(LOG_DEBUG,"HPM: the command may be rejected for " \ "security reasons"); - + if - ( + ( req.msg.netfn == IPMI_NETFN_PICMG && req.msg.cmd == HPMFWUPG_UPLOAD_FIRMWARE_BLOCK && - errorCount < HPM_LAN_PACKET_RESIZE_LIMIT + errorCount < HPM_LAN_PACKET_RESIZE_LIMIT ) { lprintf(LOG_DEBUG,"HPM: upload firmware block API called"); @@ -3286,43 +3346,43 @@ struct ipmi_rs * HpmfwupgSendCmd(struct ipmi_intf *intf, struct ipmi_rq req, rsp = &fakeRsp; errorCount++; } - else if - ( + else if + ( req.msg.netfn == IPMI_NETFN_PICMG && ( req.msg.cmd == HPMFWUPG_ACTIVATE_FIRMWARE || req.msg.cmd == HPMFWUPG_MANUAL_FIRMWARE_ROLLBACK ) ) { - /* - * rsp == NULL and command activate firmware or manual firmware - * rollback most likely occurs when we have sent a firmware activation + /* + * rsp == NULL and command activate firmware or manual firmware + * rollback most likely occurs when we have sent a firmware activation * request. Fake a command in progress response. */ lprintf(LOG_DEBUG,"HPM: activate/rollback firmware API called"); lprintf(LOG_DEBUG,"HPM: returning in progress to handle IOL session lost"); - + fakeRsp.ccode = HPMFWUPG_COMMAND_IN_PROGRESS; rsp = &fakeRsp; } - else if - ( + else if + ( req.msg.netfn == IPMI_NETFN_PICMG && ( req.msg.cmd == HPMFWUPG_QUERY_ROLLBACK_STATUS || req.msg.cmd == HPMFWUPG_GET_UPGRADE_STATUS ) ) { - /* + /* * rsp == NULL and command get upgrade status or query rollback - * status most likely occurs when we are waiting for firmware + * status most likely occurs when we are waiting for firmware * activation. Try to re-open the IOL session (re-open will work * once the IPMC recovers from firmware activation. */ - + lprintf(LOG_DEBUG,"HPM: upg/rollback status firmware API called"); lprintf(LOG_DEBUG,"HPM: try to re-open IOL session"); - + if ( intf->target_addr == intf->my_addr ) { /* force session re-open */ @@ -3333,13 +3393,13 @@ struct ipmi_rs * HpmfwupgSendCmd(struct ipmi_intf *intf, struct ipmi_rq req, intf->session->out_seq = 0; intf->session->active = 0; intf->session->retry = 10; - - while - ( - intf->open(intf) == HPMFWUPG_ERROR + + while + ( + intf->open(intf) == HPMFWUPG_ERROR && inaccessTimeoutCounter < inaccessTimeout - ) + ) { inaccessTimeoutCounter += (time(NULL) - timeoutSec1); timeoutSec1 = time(NULL); @@ -3351,11 +3411,11 @@ struct ipmi_rs * HpmfwupgSendCmd(struct ipmi_intf *intf, struct ipmi_rq req, } } } - + /* Handle inaccessibility timeout (rsp = NULL if IOL) */ if ( rsp == NULL || rsp->ccode == 0xff || rsp->ccode == 0xc3 || rsp->ccode == 0xd3 ) { - if ( inaccessTimeoutCounter < inaccessTimeout ) + if ( inaccessTimeoutCounter < inaccessTimeout ) { timeoutSec2 = time(NULL); if ( timeoutSec2 > timeoutSec1 ) @@ -3374,7 +3434,7 @@ struct ipmi_rs * HpmfwupgSendCmd(struct ipmi_intf *intf, struct ipmi_rq req, /* Handle node busy timeout */ else if ( rsp->ccode == 0xc0 ) { - if ( upgradeTimeoutCounter < upgradeTimeout ) + if ( upgradeTimeoutCounter < upgradeTimeout ) { timeoutSec2 = time(NULL); if ( timeoutSec2 > timeoutSec1 ) @@ -3402,7 +3462,7 @@ struct ipmi_rs * HpmfwupgSendCmd(struct ipmi_intf *intf, struct ipmi_rq req, } }while( retry ); return rsp; -} +} int HpmfwupgWaitLongDurationCmd(struct ipmi_intf *intf, struct HpmfwupgUpgradeCtx* pFwupgCtx) { @@ -3411,7 +3471,7 @@ int HpmfwupgWaitLongDurationCmd(struct ipmi_intf *intf, struct HpmfwupgUpgradeCt unsigned int timeoutSec1, timeoutSec2; struct HpmfwupgGetUpgradeStatusCtx upgStatusCmd; - /* + /* * If we are not in upgrade context, we use default timeout values */ if ( pFwupgCtx != NULL ) @@ -3427,9 +3487,9 @@ int HpmfwupgWaitLongDurationCmd(struct ipmi_intf *intf, struct HpmfwupgUpgradeCt timeoutSec1 = time(NULL); timeoutSec2 = time(NULL); rc = HpmfwupgGetUpgradeStatus(intf, &upgStatusCmd, pFwupgCtx); - + while((upgStatusCmd.resp.lastCmdCompCode == HPMFWUPG_COMMAND_IN_PROGRESS ) && - (timeoutSec2 - timeoutSec1 < upgradeTimeout ) && + (timeoutSec2 - timeoutSec1 < upgradeTimeout ) && (rc == HPMFWUPG_SUCCESS) ) { /* Must wait at least 100 ms between status requests */ @@ -3437,20 +3497,20 @@ int HpmfwupgWaitLongDurationCmd(struct ipmi_intf *intf, struct HpmfwupgUpgradeCt timeoutSec2 = time(NULL); rc = HpmfwupgGetUpgradeStatus(intf, &upgStatusCmd, pFwupgCtx); } - + if ( upgStatusCmd.resp.lastCmdCompCode != 0x00 ) { if ( verbose ) { - lprintf(LOG_NOTICE,"Error waiting for command %x, compcode = %x", - upgStatusCmd.resp.cmdInProcess, + lprintf(LOG_NOTICE,"Error waiting for command %x, compcode = %x", + upgStatusCmd.resp.cmdInProcess, upgStatusCmd.resp.lastCmdCompCode); } rc = HPMFWUPG_ERROR; } - + return rc; -} +} unsigned char HpmfwupgCalculateChecksum(unsigned char* pData, unsigned int length) { @@ -3462,12 +3522,12 @@ unsigned char HpmfwupgCalculateChecksum(unsigned char* pData, unsigned int lengt checksum += pData[dataIdx]; } return checksum; -} +} static void HpmfwupgPrintUsage(void) { - lprintf(LOG_NOTICE,"help - This help menu"); - lprintf(LOG_NOTICE,"check - Check the target information"); + lprintf(LOG_NOTICE,"help - This help menu"); + lprintf(LOG_NOTICE,"check - Check the target information"); lprintf(LOG_NOTICE,"check - If the user is unsure of what update is going to be "); lprintf(LOG_NOTICE," This will display the existing target version and image "); lprintf(LOG_NOTICE," version on the screen"); @@ -3506,14 +3566,14 @@ int ipmi_hpmfwupg_main(struct ipmi_intf * intf, int argc, char ** argv) int activateFlag = 0x00; int componentId = DEFAULT_COMPONENT_UPLOAD; int option = VERSIONCHECK_MODE; - - lprintf(LOG_DEBUG,"ipmi_hpmfwupg_main()"); - - lprintf(LOG_NOTICE,"\nPICMG HPM.1 Upgrade Agent %d.%d.%d: \n", + lprintf(LOG_DEBUG,"ipmi_hpmfwupg_main()"); + + + lprintf(LOG_NOTICE,"\nPICMG HPM.1 Upgrade Agent %d.%d.%d: \n", HPMFWUPG_VERSION_MAJOR, HPMFWUPG_VERSION_MINOR, HPMFWUPG_VERSION_SUBMINOR); - - if ( (argc == 0) || (strcmp(argv[0], "help") == 0) ) + + if ( (argc == 0) || (strcmp(argv[0], "help") == 0) ) { HpmfwupgPrintUsage(); return; @@ -3535,8 +3595,8 @@ int ipmi_hpmfwupg_main(struct ipmi_intf * intf, int argc, char ** argv) } } } - - else if ( strcmp(argv[0], "upgrade") == 0) + + else if ( strcmp(argv[0], "upgrade") == 0) { int i =0; for (i=1; i< argc ; i++) @@ -3555,14 +3615,14 @@ int ipmi_hpmfwupg_main(struct ipmi_intf * intf, int argc, char ** argv) /* hpm upgrade component */ if (strcmp(argv[i],"component") == 0) { - if (i+1 < argc) - { + if (i+1 < argc) + { componentId = atoi(argv[i+1]); option &= ~(VERSIONCHECK_MODE); option &= ~(VIEW_MODE); option |= FORCE_MODE_COMPONENT; /* Error Checking */ - if (componentId >= HPMFWUPG_COMPONENT_ID_MAX) + if (componentId >= HPMFWUPG_COMPONENT_ID_MAX) { lprintf(LOG_NOTICE,"Given component ID %d exceeds Max Comp ID %d\n", componentId, HPMFWUPG_COMPONENT_ID_MAX-1); @@ -3589,7 +3649,7 @@ int ipmi_hpmfwupg_main(struct ipmi_intf * intf, int argc, char ** argv) rc = HpmfwupgUpgrade(intf, argv[1],activateFlag,componentId,option); } } - + else if ( (argc >= 1) && (strcmp(argv[0], "activate") == 0) ) { struct HpmfwupgActivateFirmwareCtx cmdCtx; @@ -3624,11 +3684,11 @@ int ipmi_hpmfwupg_main(struct ipmi_intf * intf, int argc, char ** argv) struct HpmfwupgGetUpgradeStatusCtx cmdCtx; verbose++; rc = HpmfwupgGetUpgradeStatus(intf, &cmdCtx, NULL); - } + } else if ( (argc == 1) && (strcmp(argv[0], "rollback") == 0) ) { struct HpmfwupgManualFirmwareRollbackCtx cmdCtx; - verbose++; + verbose++; rc = HpmfwupgManualFirmwareRollback(intf, &cmdCtx, NULL); } else if ( (argc == 1) && (strcmp(argv[0], "rollbackstatus") == 0) ) @@ -3645,9 +3705,9 @@ int ipmi_hpmfwupg_main(struct ipmi_intf * intf, int argc, char ** argv) } else { - HpmfwupgPrintUsage(); + HpmfwupgPrintUsage(); } - + return rc; }