Skip to content

Commit

Permalink
Merge branch 'devel' into auto-bin2hpm
Browse files Browse the repository at this point in the history
  • Loading branch information
augustofg authored Jul 3, 2023
2 parents 67be386 + 5631857 commit f51f435
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 36 deletions.
63 changes: 34 additions & 29 deletions modules/hpm.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ static uint8_t cmd_in_progress;
static uint8_t last_cmd_cc;

/*Current component under upgrade */
static uint8_t active_id;
static t_component* active_component = NULL;

/* Variable used to monitor HPM upload fw block command's block number */
static uint8_t expected_block_n;
Expand Down Expand Up @@ -215,14 +215,24 @@ IPMI_HANDLER(ipmi_picmg_initiate_upgrade_action, NETFN_GRPEXT, IPMI_PICMG_CMD_HP
{
uint8_t len = rsp->data_len = 0;

uint8_t comp_id = req->data[1];
uint8_t upgrade_action = req->data[2];

expected_block_n = 0x00;

rsp->completion_code = IPMI_CC_UNSPECIFIED_ERROR;

if (comp_id > 7) {
uint8_t comp_id;

/* Set the component that'll be upgraded */
/*
* As specified in the Hardware Platform Management IPM Controller Firmware Upgrade Specification, Table 3-4,
* treat the component selection (req->data[1]) as a bit field.
*/
switch (req->data[1]) {
case 0x01:
comp_id = 0;
break;
case 0x02:
comp_id = 1;
break;
case 0x04:
comp_id = 2;
break;
default:
/* Component ID out of range */
rsp->data[len++] = IPMI_PICMG_GRP_EXT;
/* Return command-specific completion code: 0x82 (Invalid Component ID) */
Expand All @@ -231,26 +241,21 @@ IPMI_HANDLER(ipmi_picmg_initiate_upgrade_action, NETFN_GRPEXT, IPMI_PICMG_CMD_HP
return;
}

active_id = comp_id;

uint8_t upgrade_action = req->data[2];
expected_block_n = 0x00;
rsp->completion_code = IPMI_CC_UNSPECIFIED_ERROR;
active_component = &hpm_components[comp_id];
rsp->data[len++] = IPMI_PICMG_GRP_EXT;

switch (upgrade_action) {
case 0x00:
/* Backup component */
break;
case 0x01:
/* Prepare Component */
if (hpm_components[active_id].hpm_prepare_comp_f) {
rsp->completion_code = hpm_components[active_id].hpm_prepare_comp_f();
}
break;
case 0x02:
/* Upload for upgrade */
/* Set the component that'll be upgraded */
active_id = comp_id;
if (hpm_components[active_id].hpm_prepare_comp_f) {
rsp->completion_code = hpm_components[active_id].hpm_prepare_comp_f();
if (active_component->hpm_prepare_comp_f) {
rsp->completion_code = active_component->hpm_prepare_comp_f();
}
break;
case 0x03:
Expand All @@ -271,9 +276,9 @@ IPMI_HANDLER(ipmi_picmg_get_upgrade_status, NETFN_GRPEXT, IPMI_PICMG_CMD_HPM_GET
{
uint8_t len = rsp->data_len = 0;

if (hpm_components[active_id].hpm_get_upgrade_status_f) {
if (active_component->hpm_get_upgrade_status_f) {
/* WARNING: This function can't block! */
last_cmd_cc = hpm_components[active_id].hpm_get_upgrade_status_f();
last_cmd_cc = active_component->hpm_get_upgrade_status_f();
} else {
/* Returning IPMI_CC_OK for debug purposes only, should be IPMI_CC_UNSPECIFIED_ERROR */
last_cmd_cc = IPMI_CC_OK;
Expand Down Expand Up @@ -305,7 +310,7 @@ IPMI_HANDLER(ipmi_picmg_upload_firmware_block, NETFN_GRPEXT, IPMI_PICMG_CMD_HPM_
uint8_t block_data[HPM_BLOCK_SIZE];
uint8_t block_sz = req->data_len-2;

if (active_id > 7) {
if (active_component == NULL) {
/* Component ID out of range */
rsp->data[len++] = IPMI_PICMG_GRP_EXT;
/* Return command-specific completion code: 0x81 (Invalid Component ID) */
Expand All @@ -318,11 +323,11 @@ IPMI_HANDLER(ipmi_picmg_upload_firmware_block, NETFN_GRPEXT, IPMI_PICMG_CMD_HPM_

/* TODO: perform checksum of the block */

if (hpm_components[active_id].hpm_upload_block_f) {
if (active_component->hpm_upload_block_f) {
/* WARNING: This function can't block! */
/* req->data[1] holds the block number */
if(req->data[1] == expected_block_n) {
rsp->completion_code = hpm_components[active_id].hpm_upload_block_f(&block_data[0], block_sz);
rsp->completion_code = active_component->hpm_upload_block_f(&block_data[0], block_sz);
expected_block_n++;
} else { /* Repeated block, ignore it */
rsp->completion_code = IPMI_CC_OK;
Expand All @@ -347,8 +352,8 @@ IPMI_HANDLER(ipmi_picmg_finish_firmware_upload, NETFN_GRPEXT, IPMI_PICMG_CMD_HPM

/* TODO: implement HPM.1 REQ3.59 */

if ( hpm_components[active_id].hpm_finish_upload_f) {
rsp->completion_code = hpm_components[active_id].hpm_finish_upload_f( image_len );
if ( active_component->hpm_finish_upload_f) {
rsp->completion_code = active_component->hpm_finish_upload_f( image_len );
} else {
rsp->completion_code = IPMI_CC_UNSPECIFIED_ERROR;
}
Expand All @@ -368,8 +373,8 @@ IPMI_HANDLER(ipmi_picmg_activate_firmware, NETFN_GRPEXT, IPMI_PICMG_CMD_HPM_ACTI

/* TODO: Compare firmware revisions before activating */

if (hpm_components[active_id].hpm_activate_firmware_f) {
rsp->completion_code = hpm_components[active_id].hpm_activate_firmware_f();
if (active_component->hpm_activate_firmware_f) {
rsp->completion_code = active_component->hpm_activate_firmware_f();
} else {
rsp->completion_code = IPMI_CC_UNSPECIFIED_ERROR;
}
Expand Down
19 changes: 12 additions & 7 deletions modules/hpm.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,16 +52,21 @@ typedef uint8_t (* t_hpm_prepare_comp)(void);
typedef uint8_t (* t_hpm_get_upgrade_status)(void);
typedef uint8_t (* t_hpm_activate_firmware)(void);


/*
* Define the "Get target upgrade capabilities" message struct as define in the
* Hardware Platform Management IPM Controller Firmware Upgrade Specification, Table 3-3
*/
typedef union {
struct {
uint8_t upgrade_undesirable:1;
uint8_t automatic_rollback_overridden:1;
uint8_t ipmc_degraded_in_update:1;
uint8_t deferred_activation:1;
uint8_t services_affected:1;
uint8_t manual_rollback:1;
uint8_t automatic_rollback:1;
uint8_t self_test:1;
uint8_t automatic_rollback:1;
uint8_t manual_rollback:1;
uint8_t services_affected:1;
uint8_t deferred_activation:1;
uint8_t ipmc_degraded_in_update:1;
uint8_t automatic_rollback_overridden:1;
uint8_t upgrade_undesirable:1;
} flags;
uint8_t byte;
} t_ipmc_capabilities;
Expand Down

0 comments on commit f51f435

Please sign in to comment.