Skip to content

Commit

Permalink
RedfishPkg/RedfishPlatformConfigDxe: add debug message.
Browse files Browse the repository at this point in the history
Add debug prints to show HII option name when assert happens.
This helps developer to debug assert issue easily while Redfish
failed to convert HII value to Redfish value.

Signed-off-by: Nickle Wang <nicklew@nvidia.com>
Cc: Abner Chang <abner.chang@amd.com>
Cc: Igor Kulchytskyy <igork@ami.com>
Cc: Nick Ramirez <nramirez@nvidia.com>
Reviewed-by: Abner Chang <abner.chang@amd.com>
  • Loading branch information
nicklela authored and mergify[bot] committed Oct 24, 2023
1 parent 2ad52ad commit da73578
Showing 1 changed file with 122 additions and 1 deletion.
123 changes: 122 additions & 1 deletion RedfishPkg/RedfishPlatformConfigDxe/RedfishPlatformConfigDxe.c
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,106 @@ FindFormLinkToThis (
return NULL;
}

/**
Debug dump HII statement value.
@param[in] ErrorLevel DEBUG macro error level
@param[in] Value HII statement value to dump
@param[in] Message Debug message
@retval EFI_SUCCESS Dump HII statement value successfully
@retval Others Errors occur
**/
EFI_STATUS
DumpHiiStatementValue (
IN UINTN ErrorLevel,
IN HII_STATEMENT_VALUE *Value,
IN CHAR8 *Message OPTIONAL
)
{
UINT64 Data;

if (Value == NULL) {
return EFI_INVALID_PARAMETER;
}

switch (Value->Type) {
case EFI_IFR_TYPE_NUM_SIZE_8:
Data = Value->Value.u8;
break;
case EFI_IFR_TYPE_NUM_SIZE_16:
Data = Value->Value.u16;
break;
case EFI_IFR_TYPE_NUM_SIZE_32:
Data = Value->Value.u32;
break;
case EFI_IFR_TYPE_NUM_SIZE_64:
Data = Value->Value.u64;
break;
case EFI_IFR_TYPE_BOOLEAN:
Data = (Value->Value.b ? 1 : 0);
break;
default:
DEBUG ((ErrorLevel, "%a: unsupported type: 0x%x\n", __func__, Value->Type));
return EFI_UNSUPPORTED;
}

if (IS_EMPTY_STRING (Message)) {
DEBUG ((ErrorLevel, "0x%lx\n", Data));
} else {
DEBUG ((ErrorLevel, "%a: 0x%lx\n", Message, Data));
}

return EFI_SUCCESS;
}

/**
Debug dump HII statement prompt string.
@param[in] ErrorLevel DEBUG macro error level
@param[in] HiiHandle HII handle instance
@param[in] HiiStatement HII statement
@param[in] Message Debug message
@retval EFI_SUCCESS Dump HII statement string successfully
@retval Others Errors occur
**/
EFI_STATUS
DumpHiiStatementPrompt (
IN UINTN ErrorLevel,
IN EFI_HII_HANDLE HiiHandle,
IN HII_STATEMENT *HiiStatement,
IN CHAR8 *Message OPTIONAL
)
{
EFI_STRING String;

if ((HiiHandle == NULL) || (HiiStatement == NULL)) {
return EFI_INVALID_PARAMETER;
}

if (HiiStatement->Prompt == 0) {
return EFI_NOT_FOUND;
}

String = HiiGetString (HiiHandle, HiiStatement->Prompt, NULL);
if (String == NULL) {
return EFI_NOT_FOUND;
}

if (IS_EMPTY_STRING (Message)) {
DEBUG ((ErrorLevel, "%s\n", String));
} else {
DEBUG ((ErrorLevel, "%a: %s\n", Message, String));
}

FreePool (String);

return EFI_SUCCESS;
}

/**
Build the menu path to given statement instance. It is caller's
responsibility to free returned string buffer.
Expand Down Expand Up @@ -890,6 +990,7 @@ HiiValueToRedfishNumeric (
break;
default:
RedfishValue->Type = RedfishValueTypeUnknown;
DEBUG ((DEBUG_ERROR, "%a: Unsupported value type: 0x%x\n", __func__, Value->Type));
break;
}

Expand Down Expand Up @@ -1187,6 +1288,11 @@ HiiValueToRedfishValue (
case EFI_IFR_ONE_OF_OP:
StringId = HiiValueToOneOfOptionStringId (HiiStatement, Value);
if (StringId == 0) {
//
// Print prompt string of HII statement for ease of debugging
//
DumpHiiStatementPrompt (DEBUG_ERROR, HiiHandle, HiiStatement, "Can not find string ID");
DumpHiiStatementValue (DEBUG_ERROR, Value, "Current value");
ASSERT (FALSE);
Status = EFI_DEVICE_ERROR;
break;
Expand Down Expand Up @@ -1254,20 +1360,35 @@ HiiValueToRedfishValue (
case EFI_IFR_ORDERED_LIST_OP:
StringIdArray = HiiValueToOrderedListOptionStringId (HiiStatement, &Count);
if (StringIdArray == NULL) {
//
// Print prompt string of HII statement for ease of debugging
//
DumpHiiStatementPrompt (DEBUG_ERROR, HiiHandle, HiiStatement, "Can not get string ID array");
ASSERT (FALSE);
Status = EFI_DEVICE_ERROR;
break;
}

RedfishValue->Value.StringArray = AllocatePool (sizeof (CHAR8 *) * Count);
if (RedfishValue->Value.StringArray == NULL) {
//
// Print prompt string of HII statement for ease of debugging
//
DumpHiiStatementPrompt (DEBUG_ERROR, HiiHandle, HiiStatement, "Can not allocate memory");
ASSERT (FALSE);
Status = EFI_OUT_OF_RESOURCES;
break;
}

for (Index = 0; Index < Count; Index++) {
ASSERT (StringIdArray[Index] != 0);
if (StringIdArray[Index] == 0) {
//
// Print prompt string of HII statement for ease of debugging
//
DumpHiiStatementPrompt (DEBUG_ERROR, HiiHandle, HiiStatement, "String ID in array is 0");
ASSERT (FALSE);
}

RedfishValue->Value.StringArray[Index] = HiiGetRedfishAsciiString (HiiHandle, FullSchema, StringIdArray[Index]);
ASSERT (RedfishValue->Value.StringArray[Index] != NULL);
}
Expand Down

0 comments on commit da73578

Please sign in to comment.