ID: 70 - Fixes and updates for ipmitool hpm

Update HpmfwupgPreUpgradeCheck to check if the Aux version is also
different when it compares the Image version to the active and
rollback versions.

Fixed the indenting and style of HpmfwupgPreUpgradeCheck to make it
more readable.

Commit for Dan Gora
This commit is contained in:
Zdenek Styblik 2013-07-17 10:19:43 +00:00
parent 2db7f5f6b9
commit bf8acad458

View File

@ -1019,7 +1019,6 @@ typedef struct _VERSIONINFO
unsigned char imageAux[4]; unsigned char imageAux[4];
unsigned char coldResetRequired; unsigned char coldResetRequired;
unsigned char rollbackSupported; unsigned char rollbackSupported;
unsigned char skipUpgrade;
char descString[15]; char descString[15];
}VERSIONINFO, *PVERSIONINFO; }VERSIONINFO, *PVERSIONINFO;
@ -1851,6 +1850,37 @@ int HpmfwupgPreparationStage(struct ipmi_intf *intf, struct HpmfwupgUpgradeCtx*
return rc; return rc;
} }
static int image_version_upgradable(VERSIONINFO *pVersionInfo)
{
/* If the image and active target versions are different, then
* upgrade */
if ((pVersionInfo->imageMajor != pVersionInfo->targetMajor) ||
(pVersionInfo->imageMinor != pVersionInfo->targetMinor) ||
(pVersionInfo->imageAux[0] != pVersionInfo->targetAux[0]) ||
(pVersionInfo->imageAux[1] != pVersionInfo->targetAux[1]) ||
(pVersionInfo->imageAux[2] != pVersionInfo->targetAux[2]) ||
(pVersionInfo->imageAux[3] != pVersionInfo->targetAux[3]))
return (1);
/* If the image and active target versions are the same and rollback
* is not supported, then there's nothing to do, skip the upgrade */
if (!pVersionInfo->rollbackSupported)
return (0);
/* If the image and rollback target versions are different, then
* go ahead and upgrade */
if ((pVersionInfo->imageMajor != pVersionInfo->rollbackMajor) ||
(pVersionInfo->imageMinor != pVersionInfo->rollbackMinor) ||
(pVersionInfo->imageAux[0] != pVersionInfo->rollbackAux[0]) ||
(pVersionInfo->imageAux[1] != pVersionInfo->rollbackAux[1]) ||
(pVersionInfo->imageAux[2] != pVersionInfo->rollbackAux[2]) ||
(pVersionInfo->imageAux[3] != pVersionInfo->rollbackAux[3]))
return (1);
/* Image and rollback target versions are the same too, skip it */
return (0);
}
/**************************************************************************** /****************************************************************************
* *
* Function Name: HpmfwupgPreUpgradeCheck * Function Name: HpmfwupgPreUpgradeCheck
@ -1860,48 +1890,39 @@ int HpmfwupgPreparationStage(struct ipmi_intf *intf, struct HpmfwupgUpgradeCtx*
* is same as target version. * is same as target version.
* *
*****************************************************************************/ *****************************************************************************/
int HpmfwupgPreUpgradeCheck(struct ipmi_intf *intf, struct HpmfwupgUpgradeCtx* pFwupgCtx, int HpmfwupgPreUpgradeCheck(struct ipmi_intf *intf,
struct HpmfwupgUpgradeCtx* pFwupgCtx,
int componentToUpload, int option) int componentToUpload, int option)
{ {
int rc = HPMFWUPG_SUCCESS;
unsigned char* pImagePtr; unsigned char* pImagePtr;
struct HpmfwupgActionRecord *pActionRecord; struct HpmfwupgActionRecord *pActionRecord;
unsigned int actionsSize;
int flagColdReset = FALSE; int flagColdReset = FALSE;
struct HpmfwupgImageHeader* pImageHeader = (struct HpmfwupgImageHeader*) struct HpmfwupgImageHeader *pImageHeader;
pFwupgCtx->pImageData;
pImageHeader = (struct HpmfwupgImageHeader*) pFwupgCtx->pImageData;
/* Put pointer after image header */ /* Put pointer after image header */
pImagePtr = (unsigned char*) pImagePtr = (unsigned char*)
(pFwupgCtx->pImageData + sizeof(struct HpmfwupgImageHeader) + (pFwupgCtx->pImageData + sizeof(struct HpmfwupgImageHeader) +
pImageHeader->oemDataLength + sizeof(unsigned char)/*checksum*/); pImageHeader->oemDataLength + sizeof(unsigned char)/*chksum*/);
/* Deternime actions size */ if (option & VIEW_MODE) {
actionsSize = pFwupgCtx->imageSize - sizeof(struct HpmfwupgImageHeader);
if (option & VIEW_MODE)
{
HpmDisplayVersionHeader(TARGET_VER|ROLLBACK_VER|IMAGE_VER); HpmDisplayVersionHeader(TARGET_VER|ROLLBACK_VER|IMAGE_VER);
} }
/* Perform actions defined in the image */ /* Perform actions defined in the image */
while( ( pImagePtr < (pFwupgCtx->pImageData + pFwupgCtx->imageSize - while (pImagePtr < (pFwupgCtx->pImageData + pFwupgCtx->imageSize -
HPMFWUPG_MD5_SIGNATURE_LENGTH)) && HPMFWUPG_MD5_SIGNATURE_LENGTH)) {
( rc == HPMFWUPG_SUCCESS) )
{
/* Get action record */ /* Get action record */
pActionRecord = (struct HpmfwupgActionRecord*)pImagePtr; pActionRecord = (struct HpmfwupgActionRecord*)pImagePtr;
/* Validate action record checksum */ /* Validate action record checksum */
if (HpmfwupgCalculateChecksum((unsigned char*)pActionRecord, if (HpmfwupgCalculateChecksum((unsigned char*)pActionRecord,
sizeof(struct HpmfwupgActionRecord)) != 0 ) sizeof(struct HpmfwupgActionRecord)) != 0) {
{
lprintf(LOG_NOTICE," Invalid Action record."); lprintf(LOG_NOTICE," Invalid Action record.");
rc = HPMFWUPG_ERROR; return HPMFWUPG_ERROR;
} }
if ( rc == HPMFWUPG_SUCCESS )
{
switch( pActionRecord->actionType ) switch( pActionRecord->actionType )
{ {
case HPMFWUPG_ACTION_BACKUP_COMPONENTS: case HPMFWUPG_ACTION_BACKUP_COMPONENTS:
@ -1912,11 +1933,11 @@ int HpmfwupgPreUpgradeCheck(struct ipmi_intf *intf, struct HpmfwupgUpgradeCtx* p
case HPMFWUPG_ACTION_PREPARE_COMPONENTS: case HPMFWUPG_ACTION_PREPARE_COMPONENTS:
{ {
if (componentToUpload != DEFAULT_COMPONENT_UPLOAD) if (componentToUpload != DEFAULT_COMPONENT_UPLOAD) {
{ if (!((1 << componentToUpload) &
if (!(1<<componentToUpload & pActionRecord->components.ComponentBits.byte)) pActionRecord->components.ComponentBits.byte)) {
{ lprintf(LOG_NOTICE,
lprintf(LOG_NOTICE,"\nComponent Id given is not supported\n"); "\nComponent Id given is not supported\n");
return HPMFWUPG_ERROR; return HPMFWUPG_ERROR;
} }
} }
@ -1929,19 +1950,19 @@ int HpmfwupgPreUpgradeCheck(struct ipmi_intf *intf, struct HpmfwupgUpgradeCtx* p
{ {
struct HpmfwupgFirmwareImage *pFwImage; struct HpmfwupgFirmwareImage *pFwImage;
unsigned char *pData; unsigned char *pData;
unsigned int firmwareLength = 0; unsigned int firmwareLength;
unsigned char mode = 0; unsigned char mode;
unsigned char componentId = 0x00; unsigned char componentId;
unsigned char componentIdByte = 0x00; unsigned char componentIdByte;
unsigned int upgrade_comp;
VERSIONINFO *pVersionInfo; VERSIONINFO *pVersionInfo;
struct HpmfwupgGetComponentPropertiesCtx getCompProp; struct HpmfwupgGetComponentPropertiesCtx getCompProp;
/* Save component ID on which the upload is done */ /* Save component ID on which the upload is done */
componentIdByte = pActionRecord->components.ComponentBits.byte; componentIdByte = pActionRecord->components.ComponentBits.byte;
while ((componentIdByte>>=1)!=0) componentId = 0;
{ while ((componentIdByte >>= 1) !=0) {
componentId++; componentId++;
} }
pFwupgCtx->componentId = componentId; pFwupgCtx->componentId = componentId;
@ -1949,7 +1970,8 @@ int HpmfwupgPreUpgradeCheck(struct ipmi_intf *intf, struct HpmfwupgUpgradeCtx* p
pFwImage = (struct HpmfwupgFirmwareImage*)(pImagePtr + pFwImage = (struct HpmfwupgFirmwareImage*)(pImagePtr +
sizeof(struct HpmfwupgActionRecord)); sizeof(struct HpmfwupgActionRecord));
pData = ((unsigned char*)pFwImage + sizeof(struct HpmfwupgFirmwareImage)); pData = ((unsigned char*)pFwImage +
sizeof(struct HpmfwupgFirmwareImage));
/* Get firmware length */ /* Get firmware length */
firmwareLength = pFwImage->length[0]; firmwareLength = pFwImage->length[0];
@ -1969,74 +1991,32 @@ int HpmfwupgPreUpgradeCheck(struct ipmi_intf *intf, struct HpmfwupgUpgradeCtx* p
mode = TARGET_VER | IMAGE_VER; mode = TARGET_VER | IMAGE_VER;
if (pVersionInfo->coldResetRequired) if (pVersionInfo->coldResetRequired)
{
flagColdReset = TRUE; flagColdReset = TRUE;
}
pVersionInfo->skipUpgrade = FALSE;
if (option & FORCE_MODE_ALL) upgrade_comp = 0;
{ if (option & FORCE_MODE_ALL) {
/* user has given all to upload all the components on the command line */ upgrade_comp = 1;
if(verbose) {
lprintf(LOG_NOTICE,"Forcing ALL components");
} }
else if ((option & FORCE_MODE_COMPONENT) &&
(componentToUpload == componentId)) {
upgrade_comp = 1;
} }
else if( option & FORCE_MODE_COMPONENT ) else if (image_version_upgradable(pVersionInfo)) {
{ upgrade_comp = 1;
if( componentToUpload != componentId )
{
if(verbose) {
lprintf(LOG_NOTICE,"Forcing component %d skip", componentId);
} }
/* user has given the component Id to upload on the command line */
pVersionInfo->skipUpgrade = TRUE; if (verbose)
} lprintf(LOG_NOTICE,"%s component %d",
else if(verbose) (upgrade_comp ? "Updating" : "Skipping"),
{ componentId);
lprintf(LOG_NOTICE,"Forcing component %d update", componentId);
/* user has given the component Id to upload on the command line */ if (upgrade_comp)
} pFwupgCtx->compUpdateMask.ComponentBits.byte |=
} 1 << componentId;
else
{ if (option & VIEW_MODE) {
if
(
(pVersionInfo->imageMajor == pVersionInfo->targetMajor)
&&
(pVersionInfo->imageMinor == pVersionInfo->targetMinor))
{
if (pVersionInfo->rollbackSupported) if (pVersionInfo->rollbackSupported)
{
/*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
* Image version -- So now we must skip it */
pVersionInfo->skipUpgrade = TRUE;
}
mode |= ROLLBACK_VER; mode |= ROLLBACK_VER;
}
else
{
pVersionInfo->skipUpgrade = TRUE;
}
}
if ( verbose ) {
lprintf(LOG_NOTICE,"Component %d: %s", componentId , (pVersionInfo->skipUpgrade?"skipped":"to update"));
}
}
if( pVersionInfo->skipUpgrade == FALSE )
{
pFwupgCtx->compUpdateMask.ComponentBits.byte |= 1<<componentId;
}
if (option & VIEW_MODE)
{
HpmDisplayVersion(mode,pVersionInfo); HpmDisplayVersion(mode,pVersionInfo);
printf("\n"); printf("\n");
} }
@ -2044,22 +2024,21 @@ int HpmfwupgPreUpgradeCheck(struct ipmi_intf *intf, struct HpmfwupgUpgradeCtx* p
} }
break; break;
default: default:
lprintf(LOG_NOTICE," Invalid Action type. Cannot continue"); lprintf(LOG_NOTICE,
rc = HPMFWUPG_ERROR; " Invalid Action type. Cannot continue");
return HPMFWUPG_ERROR;
break; break;
} }
} }
}
if (option & VIEW_MODE) if (option & VIEW_MODE) {
{
HpmDisplayLine("-",71); HpmDisplayLine("-",71);
if (flagColdReset) if (flagColdReset) {
{
fflush(stdout); fflush(stdout);
lprintf(LOG_NOTICE,"(*) Component requires Payload Cold Reset"); lprintf(LOG_NOTICE,"(*) Component requires Payload Cold Reset");
} }
} }
return rc; return HPMFWUPG_SUCCESS;
} }