ID: 50 - ipmi_hpmfwupg needs a clean up

Rather major re-work of internal logic in HpmfwupgPreparationStage().
This commit is contained in:
Zdenek Styblik 2013-10-26 14:18:48 +00:00
parent f4730e1f67
commit 968f5d6552

View File

@ -602,13 +602,17 @@ int
HpmfwupgPreparationStage(struct ipmi_intf *intf, HpmfwupgPreparationStage(struct ipmi_intf *intf,
struct HpmfwupgUpgradeCtx *pFwupgCtx, int option) struct HpmfwupgUpgradeCtx *pFwupgCtx, int option)
{ {
int componentId;
int rc = HPMFWUPG_SUCCESS; int rc = HPMFWUPG_SUCCESS;
struct HpmfwupgGetTargetUpgCapabilitiesCtx targetCapCmd;
struct HpmfwupgImageHeader *pImageHeader = (struct HpmfwupgImageHeader*) struct HpmfwupgImageHeader *pImageHeader = (struct HpmfwupgImageHeader*)
pFwupgCtx->pImageData; pFwupgCtx->pImageData;
/* Get device ID */ /* Get device ID */
rc = HpmfwupgGetDeviceId(intf, &pFwupgCtx->devId); rc = HpmfwupgGetDeviceId(intf, &pFwupgCtx->devId);
/* Match current IPMC IDs with upgrade image */ /* Match current IPMC IDs with upgrade image */
if (rc == HPMFWUPG_SUCCESS) { if (rc != HPMFWUPG_SUCCESS) {
return HPMFWUPG_ERROR;
}
/* Validate device ID */ /* Validate device ID */
if (pImageHeader->deviceId == pFwupgCtx->devId.device_id) { if (pImageHeader->deviceId == pFwupgCtx->devId.device_id) {
/* Validate product ID */ /* Validate product ID */
@ -631,8 +635,7 @@ HpmfwupgPreparationStage(struct ipmi_intf *intf,
rc = HPMFWUPG_ERROR; rc = HPMFWUPG_ERROR;
} }
} else { } else {
lprintf(LOG_NOTICE, lprintf(LOG_NOTICE, "\n Invalid device ID %x",
"\n Invalid device ID %x",
pFwupgCtx->devId.device_id); pFwupgCtx->devId.device_id);
rc = HPMFWUPG_ERROR; rc = HPMFWUPG_ERROR;
} }
@ -642,7 +645,10 @@ HpmfwupgPreparationStage(struct ipmi_intf *intf,
* and dont care whether we have a different product Id. If the user says NO then * and dont care whether we have a different product Id. If the user says NO then
* we need to just bail out from here * we need to just bail out from here
*/ */
if ((option & FORCE_MODE) || (option & VIEW_MODE)) { if (!((option & FORCE_MODE) || (option & VIEW_MODE))) {
printf("\n\n Use \"force\" option for copying all the components\n");
return HPMFWUPG_ERROR;
}
printf("\n Image Information"); printf("\n Image Information");
printf("\n Device Id : 0x%x", pImageHeader->deviceId); printf("\n Device Id : 0x%x", pImageHeader->deviceId);
printf("\n Prod Id : 0x%02x%02x", printf("\n Prod Id : 0x%02x%02x",
@ -659,16 +665,13 @@ HpmfwupgPreparationStage(struct ipmi_intf *intf,
pFwupgCtx->devId.manufacturer_id[2], pFwupgCtx->devId.manufacturer_id[2],
pFwupgCtx->devId.manufacturer_id[1], pFwupgCtx->devId.manufacturer_id[1],
pFwupgCtx->devId.manufacturer_id[0]); pFwupgCtx->devId.manufacturer_id[0]);
if (HpmGetUserInput("\n Continue ignoring DeviceID/ProductID/ManufacturingID (Y/N) :")) { if (HpmGetUserInput("\n Continue ignoring DeviceID/ProductID/ManufacturingID (Y/N): ")) {
rc = HPMFWUPG_SUCCESS; rc = HPMFWUPG_SUCCESS;
}
} else { } else {
printf("\n\n Use \"force\" option for copying all the components\n"); return HPMFWUPG_ERROR;
}
} }
} }
/* Validate earliest compatible revision */ /* Validate earliest compatible revision */
if (rc == HPMFWUPG_SUCCESS) {
/* Validate major & minor revision */ /* Validate major & minor revision */
if (pImageHeader->compRevision[0] > pFwupgCtx->devId.fw_rev1 if (pImageHeader->compRevision[0] > pFwupgCtx->devId.fw_rev1
|| (pImageHeader->compRevision[0] == pFwupgCtx->devId.fw_rev1 || (pImageHeader->compRevision[0] == pFwupgCtx->devId.fw_rev1
@ -679,22 +682,21 @@ HpmfwupgPreparationStage(struct ipmi_intf *intf,
lprintf(LOG_NOTICE, " Not compatible with "); lprintf(LOG_NOTICE, " Not compatible with ");
lprintf(LOG_NOTICE, " Version: Major: %d", pFwupgCtx->devId.fw_rev1); lprintf(LOG_NOTICE, " Version: Major: %d", pFwupgCtx->devId.fw_rev1);
lprintf(LOG_NOTICE, " Minor: %x", pFwupgCtx->devId.fw_rev2); lprintf(LOG_NOTICE, " Minor: %x", pFwupgCtx->devId.fw_rev2);
rc = HPMFWUPG_ERROR;
}
if (rc != HPMFWUPG_SUCCESS) {
/* Confirming it once again */ /* Confirming it once again */
if ((option & FORCE_MODE) || (option & VIEW_MODE)) { if (!((option & FORCE_MODE) || (option & VIEW_MODE))) {
if(HpmGetUserInput("\n Continue IGNORING Earliest compatibility (Y/N) :")) { return HPMFWUPG_ERROR;
}
if (HpmGetUserInput("\n Continue IGNORING Earliest compatibility (Y/N): ")) {
rc = HPMFWUPG_SUCCESS; rc = HPMFWUPG_SUCCESS;
} } else {
} return HPMFWUPG_ERROR;
} }
} }
/* Get target upgrade capabilities */ /* Get target upgrade capabilities */
if (rc == HPMFWUPG_SUCCESS) {
struct HpmfwupgGetTargetUpgCapabilitiesCtx targetCapCmd;
rc = HpmfwupgGetTargetUpgCapabilities(intf, &targetCapCmd); rc = HpmfwupgGetTargetUpgCapabilities(intf, &targetCapCmd);
if (rc == HPMFWUPG_SUCCESS) { if (rc != HPMFWUPG_SUCCESS) {
return HPMFWUPG_ERROR;
}
/* Copy response to context */ /* Copy response to context */
memcpy(&pFwupgCtx->targetCap, memcpy(&pFwupgCtx->targetCap,
&targetCapCmd.resp, &targetCapCmd.resp,
@ -710,12 +712,12 @@ HpmfwupgPreparationStage(struct ipmi_intf *intf,
pImageHeader->components.ComponentBits.byte) { pImageHeader->components.ComponentBits.byte) {
lprintf(LOG_NOTICE, lprintf(LOG_NOTICE,
"\n Some components present in the image file are not supported by the IPMC"); "\n Some components present in the image file are not supported by the IPMC");
rc = HPMFWUPG_ERROR; return HPMFWUPG_ERROR;
} }
/* Make sure the upgrade is desirable rigth now */ /* Make sure the upgrade is desirable rigth now */
if (pFwupgCtx->targetCap.GlobalCapabilities.bitField.fwUpgUndesirable == 1) { if (pFwupgCtx->targetCap.GlobalCapabilities.bitField.fwUpgUndesirable == 1) {
lprintf(LOG_NOTICE, "\n Upgrade undesirable at this moment"); lprintf(LOG_NOTICE, "\n Upgrade undesirable at this moment");
rc = HPMFWUPG_ERROR; return HPMFWUPG_ERROR;
} }
/* Get confimation from the user if he wants to continue when /* Get confimation from the user if he wants to continue when
* service affected during upgrade * service affected during upgrade
@ -723,18 +725,14 @@ HpmfwupgPreparationStage(struct ipmi_intf *intf,
if (!(option & COMPARE_MODE) if (!(option & COMPARE_MODE)
&& (pFwupgCtx->targetCap.GlobalCapabilities.bitField.servAffectDuringUpg == 1 && (pFwupgCtx->targetCap.GlobalCapabilities.bitField.servAffectDuringUpg == 1
|| pImageHeader->imageCapabilities.bitField.servAffected == 1)) { || pImageHeader->imageCapabilities.bitField.servAffected == 1)) {
if (HpmGetUserInput("\nServices may be affected during upgrade. Do you wish to continue? y/n ")) { if (HpmGetUserInput("\nServices may be affected during upgrade. Do you wish to continue? (y/n): ")) {
rc = HPMFWUPG_SUCCESS; rc = HPMFWUPG_SUCCESS;
} else { } else {
rc = HPMFWUPG_ERROR; return HPMFWUPG_ERROR;
}
}
} }
} }
} }
/* Get the general properties of each component present in image */ /* 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 < HPMFWUPG_COMPONENT_ID_MAX;
componentId++) { componentId++) {
@ -755,7 +753,6 @@ HpmfwupgPreparationStage(struct ipmi_intf *intf,
} }
} }
} }
}
return rc; return rc;
} }