mirror of
https://github.com/ipmitool/ipmitool.git
synced 2026-07-03 18:51:42 +00:00
ID: 50 - ipmi_hpmfwupg needs a clean up
Rather major re-work of internal logic in HpmfwupgPreparationStage().
This commit is contained in:
@@ -602,157 +602,154 @@ 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) {
|
||||||
/* Validate device ID */
|
return HPMFWUPG_ERROR;
|
||||||
if (pImageHeader->deviceId == pFwupgCtx->devId.device_id) {
|
}
|
||||||
/* Validate product ID */
|
/* Validate device ID */
|
||||||
if (memcmp(pImageHeader->prodId,
|
if (pImageHeader->deviceId == pFwupgCtx->devId.device_id) {
|
||||||
pFwupgCtx->devId.product_id,
|
/* Validate product ID */
|
||||||
HPMFWUPG_PRODUCT_ID_LENGTH ) == 0) {
|
if (memcmp(pImageHeader->prodId,
|
||||||
/* Validate man ID */
|
pFwupgCtx->devId.product_id,
|
||||||
if (memcmp(pImageHeader->manId,
|
HPMFWUPG_PRODUCT_ID_LENGTH ) == 0) {
|
||||||
pFwupgCtx->devId.manufacturer_id,
|
/* Validate man ID */
|
||||||
HPMFWUPG_MANUFATURER_ID_LENGTH) != 0) {
|
if (memcmp(pImageHeader->manId,
|
||||||
lprintf(LOG_NOTICE,
|
pFwupgCtx->devId.manufacturer_id,
|
||||||
"\n Invalid image file for manufacturer %u",
|
HPMFWUPG_MANUFATURER_ID_LENGTH) != 0) {
|
||||||
buf2short(pFwupgCtx->devId.manufacturer_id));
|
|
||||||
rc = HPMFWUPG_ERROR;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
lprintf(LOG_NOTICE,
|
lprintf(LOG_NOTICE,
|
||||||
"\n Invalid image file for product %u",
|
"\n Invalid image file for manufacturer %u",
|
||||||
buf2short(pFwupgCtx->devId.product_id));
|
buf2short(pFwupgCtx->devId.manufacturer_id));
|
||||||
rc = HPMFWUPG_ERROR;
|
rc = HPMFWUPG_ERROR;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
lprintf(LOG_NOTICE,
|
lprintf(LOG_NOTICE,
|
||||||
"\n Invalid device ID %x",
|
"\n Invalid image file for product %u",
|
||||||
pFwupgCtx->devId.device_id);
|
buf2short(pFwupgCtx->devId.product_id));
|
||||||
rc = HPMFWUPG_ERROR;
|
rc = HPMFWUPG_ERROR;
|
||||||
}
|
}
|
||||||
if (rc != HPMFWUPG_SUCCESS) {
|
} else {
|
||||||
/* Giving one more chance to user to check whether its OK to continue even if the
|
lprintf(LOG_NOTICE, "\n Invalid device ID %x",
|
||||||
* product ID does not match. This is helpful as sometimes we just want to update
|
pFwupgCtx->devId.device_id);
|
||||||
* and dont care whether we have a different product Id. If the user says NO then
|
rc = HPMFWUPG_ERROR;
|
||||||
* we need to just bail out from here
|
}
|
||||||
*/
|
if (rc != HPMFWUPG_SUCCESS) {
|
||||||
if ((option & FORCE_MODE) || (option & VIEW_MODE)) {
|
/* Giving one more chance to user to check whether its OK to continue even if the
|
||||||
printf("\n Image Information");
|
* product ID does not match. This is helpful as sometimes we just want to update
|
||||||
printf("\n Device Id : 0x%x", pImageHeader->deviceId);
|
* and dont care whether we have a different product Id. If the user says NO then
|
||||||
printf("\n Prod Id : 0x%02x%02x",
|
* we need to just bail out from here
|
||||||
pImageHeader->prodId[1], pImageHeader->prodId[0]);
|
*/
|
||||||
printf("\n Manuf Id : 0x%02x%02x%02x",
|
if (!((option & FORCE_MODE) || (option & VIEW_MODE))) {
|
||||||
pImageHeader->manId[2],
|
printf("\n\n Use \"force\" option for copying all the components\n");
|
||||||
pImageHeader->manId[1],
|
return HPMFWUPG_ERROR;
|
||||||
pImageHeader->manId[0]);
|
}
|
||||||
printf("\n Board Information");
|
printf("\n Image Information");
|
||||||
printf("\n Device Id : 0x%x", pFwupgCtx->devId.device_id);
|
printf("\n Device Id : 0x%x", pImageHeader->deviceId);
|
||||||
printf("\n Prod Id : 0x%02x%02x",
|
printf("\n Prod Id : 0x%02x%02x",
|
||||||
pFwupgCtx->devId.product_id[1], pFwupgCtx->devId.product_id[0]);
|
pImageHeader->prodId[1], pImageHeader->prodId[0]);
|
||||||
printf("\n Manuf Id : 0x%02x%02x%02x",
|
printf("\n Manuf Id : 0x%02x%02x%02x",
|
||||||
pFwupgCtx->devId.manufacturer_id[2],
|
pImageHeader->manId[2],
|
||||||
pFwupgCtx->devId.manufacturer_id[1],
|
pImageHeader->manId[1],
|
||||||
pFwupgCtx->devId.manufacturer_id[0]);
|
pImageHeader->manId[0]);
|
||||||
if (HpmGetUserInput("\n Continue ignoring DeviceID/ProductID/ManufacturingID (Y/N) :")) {
|
printf("\n Board Information");
|
||||||
rc = HPMFWUPG_SUCCESS;
|
printf("\n Device Id : 0x%x", pFwupgCtx->devId.device_id);
|
||||||
}
|
printf("\n Prod Id : 0x%02x%02x",
|
||||||
} else {
|
pFwupgCtx->devId.product_id[1], pFwupgCtx->devId.product_id[0]);
|
||||||
printf("\n\n Use \"force\" option for copying all the components\n");
|
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;
|
||||||
|
} else {
|
||||||
|
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
|
&& pImageHeader->compRevision[1] > pFwupgCtx->devId.fw_rev2)) {
|
||||||
&& pImageHeader->compRevision[1] > pFwupgCtx->devId.fw_rev2)) {
|
/* Version not compatible for upgrade */
|
||||||
/* Version not compatible for upgrade */
|
lprintf(LOG_NOTICE, "\n Version: Major: %d", pImageHeader->compRevision[0]);
|
||||||
lprintf(LOG_NOTICE, "\n Version: Major: %d", pImageHeader->compRevision[0]);
|
lprintf(LOG_NOTICE, " Minor: %x", pImageHeader->compRevision[1]);
|
||||||
lprintf(LOG_NOTICE, " Minor: %x", pImageHeader->compRevision[1]);
|
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);
|
/* Confirming it once again */
|
||||||
rc = HPMFWUPG_ERROR;
|
if (!((option & FORCE_MODE) || (option & VIEW_MODE))) {
|
||||||
|
return HPMFWUPG_ERROR;
|
||||||
}
|
}
|
||||||
if (rc != HPMFWUPG_SUCCESS) {
|
if (HpmGetUserInput("\n Continue IGNORING Earliest compatibility (Y/N): ")) {
|
||||||
/* Confirming it once again */
|
rc = HPMFWUPG_SUCCESS;
|
||||||
if ((option & FORCE_MODE) || (option & VIEW_MODE)) {
|
} else {
|
||||||
if(HpmGetUserInput("\n Continue IGNORING Earliest compatibility (Y/N) :")) {
|
return HPMFWUPG_ERROR;
|
||||||
rc = HPMFWUPG_SUCCESS;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/* Get target upgrade capabilities */
|
/* Get target upgrade capabilities */
|
||||||
if (rc == HPMFWUPG_SUCCESS) {
|
rc = HpmfwupgGetTargetUpgCapabilities(intf, &targetCapCmd);
|
||||||
struct HpmfwupgGetTargetUpgCapabilitiesCtx targetCapCmd;
|
if (rc != HPMFWUPG_SUCCESS) {
|
||||||
rc = HpmfwupgGetTargetUpgCapabilities(intf, &targetCapCmd);
|
return HPMFWUPG_ERROR;
|
||||||
if (rc == HPMFWUPG_SUCCESS) {
|
}
|
||||||
/* Copy response to context */
|
/* Copy response to context */
|
||||||
memcpy(&pFwupgCtx->targetCap,
|
memcpy(&pFwupgCtx->targetCap,
|
||||||
&targetCapCmd.resp,
|
&targetCapCmd.resp,
|
||||||
sizeof(struct HpmfwupgGetTargetUpgCapabilitiesResp));
|
sizeof(struct HpmfwupgGetTargetUpgCapabilitiesResp));
|
||||||
if (option & VIEW_MODE) {
|
if (option & VIEW_MODE) {
|
||||||
/* do nothing */
|
/* do nothing */
|
||||||
|
} else {
|
||||||
|
/* 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) !=
|
||||||
|
pImageHeader->components.ComponentBits.byte) {
|
||||||
|
lprintf(LOG_NOTICE,
|
||||||
|
"\n Some components present in the image file are not supported by the IPMC");
|
||||||
|
return 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");
|
||||||
|
return HPMFWUPG_ERROR;
|
||||||
|
}
|
||||||
|
/* Get confimation from the user if he wants to continue when
|
||||||
|
* service affected during upgrade
|
||||||
|
*/
|
||||||
|
if (!(option & COMPARE_MODE)
|
||||||
|
&& (pFwupgCtx->targetCap.GlobalCapabilities.bitField.servAffectDuringUpg == 1
|
||||||
|
|| pImageHeader->imageCapabilities.bitField.servAffected == 1)) {
|
||||||
|
if (HpmGetUserInput("\nServices may be affected during upgrade. Do you wish to continue? (y/n): ")) {
|
||||||
|
rc = HPMFWUPG_SUCCESS;
|
||||||
} else {
|
} else {
|
||||||
/* Make sure all component IDs defined in the
|
return HPMFWUPG_ERROR;
|
||||||
* upgrade image are supported by the IPMC
|
|
||||||
*/
|
|
||||||
if ((pImageHeader->components.ComponentBits.byte &
|
|
||||||
pFwupgCtx->targetCap.componentsPresent.ComponentBits.byte) !=
|
|
||||||
pImageHeader->components.ComponentBits.byte) {
|
|
||||||
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 affected during upgrade
|
|
||||||
*/
|
|
||||||
if (!(option & COMPARE_MODE)
|
|
||||||
&& (pFwupgCtx->targetCap.GlobalCapabilities.bitField.servAffectDuringUpg == 1
|
|
||||||
|| pImageHeader->imageCapabilities.bitField.servAffected == 1)) {
|
|
||||||
if (HpmGetUserInput("\nServices may be affected during upgrade. Do you wish to continue? y/n ")) {
|
|
||||||
rc = HPMFWUPG_SUCCESS;
|
|
||||||
} else {
|
|
||||||
rc = 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) {
|
for (componentId = HPMFWUPG_COMPONENT_ID_0;
|
||||||
int componentId;
|
componentId < HPMFWUPG_COMPONENT_ID_MAX;
|
||||||
for (componentId = HPMFWUPG_COMPONENT_ID_0;
|
componentId++) {
|
||||||
componentId < HPMFWUPG_COMPONENT_ID_MAX;
|
/* Reset component properties */
|
||||||
componentId++) {
|
memset(&pFwupgCtx->genCompProp[componentId], 0,
|
||||||
/* Reset component properties */
|
sizeof (struct HpmfwupgGetGeneralPropResp));
|
||||||
memset(&pFwupgCtx->genCompProp[componentId], 0,
|
if ((1 << componentId & pImageHeader->components.ComponentBits.byte)) {
|
||||||
sizeof (struct HpmfwupgGetGeneralPropResp));
|
struct HpmfwupgGetComponentPropertiesCtx getCompPropCmd;
|
||||||
if ((1 << componentId & pImageHeader->components.ComponentBits.byte)) {
|
/* Get general component properties */
|
||||||
struct HpmfwupgGetComponentPropertiesCtx getCompPropCmd;
|
getCompPropCmd.req.componentId = componentId;
|
||||||
/* Get general component properties */
|
getCompPropCmd.req.selector = HPMFWUPG_COMP_GEN_PROPERTIES;
|
||||||
getCompPropCmd.req.componentId = componentId;
|
rc = HpmfwupgGetComponentProperties(intf, &getCompPropCmd);
|
||||||
getCompPropCmd.req.selector = HPMFWUPG_COMP_GEN_PROPERTIES;
|
if (rc == HPMFWUPG_SUCCESS) {
|
||||||
rc = HpmfwupgGetComponentProperties(intf, &getCompPropCmd);
|
/* Copy response to context */
|
||||||
if (rc == HPMFWUPG_SUCCESS) {
|
memcpy(&pFwupgCtx->genCompProp[componentId],
|
||||||
/* Copy response to context */
|
&getCompPropCmd.resp,
|
||||||
memcpy(&pFwupgCtx->genCompProp[componentId],
|
sizeof(struct HpmfwupgGetGeneralPropResp));
|
||||||
&getCompPropCmd.resp,
|
|
||||||
sizeof(struct HpmfwupgGetGeneralPropResp));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user