Partial reformat to kernel code style.
diff --git a/ir-parse.c b/ir-parse.c
index 82904b5..437dd82 100644
--- a/ir-parse.c
+++ b/ir-parse.c
@@ -28,188 +28,252 @@
#include "sections/cper-section-cxl-component.h"
//Private pre-declarations.
-void ir_header_to_cper(json_object* header_ir, EFI_COMMON_ERROR_RECORD_HEADER* header);
-void ir_section_descriptor_to_cper(json_object* section_descriptor_ir, EFI_ERROR_SECTION_DESCRIPTOR* descriptor);
+void ir_header_to_cper(json_object *header_ir,
+ EFI_COMMON_ERROR_RECORD_HEADER *header);
+void ir_section_descriptor_to_cper(json_object *section_descriptor_ir,
+ EFI_ERROR_SECTION_DESCRIPTOR *descriptor);
//Converts the given JSON IR CPER representation into CPER binary format, piped to the provided file stream.
//This function performs no validation of the IR against the CPER-JSON specification. To ensure a safe call,
-//use validate_schema() from json-schema.h before attempting to call this function.
-void ir_to_cper(json_object* ir, FILE* out)
+//use validate_schema() from json-schema.h before attempting to call this function.
+void ir_to_cper(json_object *ir, FILE *out)
{
- //Create the CPER header.
- EFI_COMMON_ERROR_RECORD_HEADER* header = (EFI_COMMON_ERROR_RECORD_HEADER*)calloc(1, sizeof(EFI_COMMON_ERROR_RECORD_HEADER));
- ir_header_to_cper(json_object_object_get(ir, "header"), header);
- fwrite(header, sizeof(EFI_COMMON_ERROR_RECORD_HEADER), 1, out);
- fflush(out);
+ //Create the CPER header.
+ EFI_COMMON_ERROR_RECORD_HEADER *header =
+ (EFI_COMMON_ERROR_RECORD_HEADER *)calloc(
+ 1, sizeof(EFI_COMMON_ERROR_RECORD_HEADER));
+ ir_header_to_cper(json_object_object_get(ir, "header"), header);
+ fwrite(header, sizeof(EFI_COMMON_ERROR_RECORD_HEADER), 1, out);
+ fflush(out);
- //Create the CPER section descriptors.
- json_object* section_descriptors = json_object_object_get(ir, "sectionDescriptors");
- int amt_descriptors = json_object_array_length(section_descriptors);
- EFI_ERROR_SECTION_DESCRIPTOR* descriptors[amt_descriptors];
- for (int i=0; i<amt_descriptors; i++)
- {
- descriptors[i] = (EFI_ERROR_SECTION_DESCRIPTOR*)calloc(1, sizeof(EFI_ERROR_SECTION_DESCRIPTOR));
- ir_section_descriptor_to_cper(json_object_array_get_idx(section_descriptors, i), descriptors[i]);
- fwrite(descriptors[i], sizeof(EFI_ERROR_SECTION_DESCRIPTOR), 1, out);
- fflush(out);
- }
-
- //Run through each section in turn.
- json_object* sections = json_object_object_get(ir, "sections");
- int amt_sections = json_object_array_length(sections);
- for (int i=0; i<amt_sections; i++)
- {
- //Get the section itself from the IR.
- json_object* section = json_object_array_get_idx(sections, i);
+ //Create the CPER section descriptors.
+ json_object *section_descriptors =
+ json_object_object_get(ir, "sectionDescriptors");
+ int amt_descriptors = json_object_array_length(section_descriptors);
+ EFI_ERROR_SECTION_DESCRIPTOR *descriptors[amt_descriptors];
+ for (int i = 0; i < amt_descriptors; i++) {
+ descriptors[i] = (EFI_ERROR_SECTION_DESCRIPTOR *)calloc(
+ 1, sizeof(EFI_ERROR_SECTION_DESCRIPTOR));
+ ir_section_descriptor_to_cper(
+ json_object_array_get_idx(section_descriptors, i),
+ descriptors[i]);
+ fwrite(descriptors[i], sizeof(EFI_ERROR_SECTION_DESCRIPTOR), 1,
+ out);
+ fflush(out);
+ }
- //Find the correct section type, and parse.
- if (guid_equal(&descriptors[i]->SectionType, &gEfiProcessorGenericErrorSectionGuid))
- ir_section_generic_to_cper(section, out);
- else if (guid_equal(&descriptors[i]->SectionType, &gEfiIa32X64ProcessorErrorSectionGuid))
- ir_section_ia32x64_to_cper(section, out);
- // else if (guid_equal(&descriptors[i]->SectionType, &gEfiIpfProcessorErrorSectionGuid))
- // ir_section_ipf_to_cper(section, out);
- else if (guid_equal(&descriptors[i]->SectionType, &gEfiArmProcessorErrorSectionGuid))
- ir_section_arm_to_cper(section, out);
- else if (guid_equal(&descriptors[i]->SectionType, &gEfiPlatformMemoryErrorSectionGuid))
- ir_section_memory_to_cper(section, out);
- else if (guid_equal(&descriptors[i]->SectionType, &gEfiPlatformMemoryError2SectionGuid))
- ir_section_memory2_to_cper(section, out);
- else if (guid_equal(&descriptors[i]->SectionType, &gEfiPcieErrorSectionGuid))
- ir_section_pcie_to_cper(section, out);
- else if (guid_equal(&descriptors[i]->SectionType, &gEfiFirmwareErrorSectionGuid))
- ir_section_firmware_to_cper(section, out);
- else if (guid_equal(&descriptors[i]->SectionType, &gEfiPciBusErrorSectionGuid))
- ir_section_pci_bus_to_cper(section, out);
- else if (guid_equal(&descriptors[i]->SectionType, &gEfiPciDevErrorSectionGuid))
- ir_section_pci_dev_to_cper(section, out);
- else if (guid_equal(&descriptors[i]->SectionType, &gEfiDMArGenericErrorSectionGuid))
- ir_section_dmar_generic_to_cper(section, out);
- else if (guid_equal(&descriptors[i]->SectionType, &gEfiDirectedIoDMArErrorSectionGuid))
- ir_section_dmar_vtd_to_cper(section, out);
- else if (guid_equal(&descriptors[i]->SectionType, &gEfiIommuDMArErrorSectionGuid))
- ir_section_dmar_iommu_to_cper(section, out);
- else if (guid_equal(&descriptors[i]->SectionType, &gEfiCcixPerLogErrorSectionGuid))
- ir_section_ccix_per_to_cper(section, out);
- else if (guid_equal(&descriptors[i]->SectionType, &gEfiCxlProtocolErrorSectionGuid))
- ir_section_cxl_protocol_to_cper(section, out);
- else if (guid_equal(&descriptors[i]->SectionType, &gEfiCxlGeneralMediaErrorSectionGuid)
- || guid_equal(&descriptors[i]->SectionType, &gEfiCxlDramEventErrorSectionGuid)
- || guid_equal(&descriptors[i]->SectionType, &gEfiCxlPhysicalSwitchErrorSectionGuid)
- || guid_equal(&descriptors[i]->SectionType, &gEfiCxlVirtualSwitchErrorSectionGuid)
- || guid_equal(&descriptors[i]->SectionType, &gEfiCxlMldPortErrorSectionGuid))
- {
- ir_section_cxl_component_to_cper(section, out);
- }
- else
- {
- //Unknown GUID, so read as a base64 unknown section.
- json_object* encoded = json_object_object_get(section, "data");
- UINT8* decoded = b64_decode(json_object_get_string(encoded), json_object_get_string_len(encoded));
- fwrite(decoded, descriptors[i]->SectionLength, 1, out);
- fflush(out);
- free(decoded);
- }
- }
+ //Run through each section in turn.
+ json_object *sections = json_object_object_get(ir, "sections");
+ int amt_sections = json_object_array_length(sections);
+ for (int i = 0; i < amt_sections; i++) {
+ //Get the section itself from the IR.
+ json_object *section = json_object_array_get_idx(sections, i);
- //Free all remaining resources.
- free(header);
- for (int i=0; i<amt_descriptors; i++)
- free(descriptors[i]);
+ //Find the correct section type, and parse.
+ if (guid_equal(&descriptors[i]->SectionType,
+ &gEfiProcessorGenericErrorSectionGuid))
+ ir_section_generic_to_cper(section, out);
+ else if (guid_equal(&descriptors[i]->SectionType,
+ &gEfiIa32X64ProcessorErrorSectionGuid))
+ ir_section_ia32x64_to_cper(section, out);
+ // else if (guid_equal(&descriptors[i]->SectionType, &gEfiIpfProcessorErrorSectionGuid))
+ // ir_section_ipf_to_cper(section, out);
+ else if (guid_equal(&descriptors[i]->SectionType,
+ &gEfiArmProcessorErrorSectionGuid))
+ ir_section_arm_to_cper(section, out);
+ else if (guid_equal(&descriptors[i]->SectionType,
+ &gEfiPlatformMemoryErrorSectionGuid))
+ ir_section_memory_to_cper(section, out);
+ else if (guid_equal(&descriptors[i]->SectionType,
+ &gEfiPlatformMemoryError2SectionGuid))
+ ir_section_memory2_to_cper(section, out);
+ else if (guid_equal(&descriptors[i]->SectionType,
+ &gEfiPcieErrorSectionGuid))
+ ir_section_pcie_to_cper(section, out);
+ else if (guid_equal(&descriptors[i]->SectionType,
+ &gEfiFirmwareErrorSectionGuid))
+ ir_section_firmware_to_cper(section, out);
+ else if (guid_equal(&descriptors[i]->SectionType,
+ &gEfiPciBusErrorSectionGuid))
+ ir_section_pci_bus_to_cper(section, out);
+ else if (guid_equal(&descriptors[i]->SectionType,
+ &gEfiPciDevErrorSectionGuid))
+ ir_section_pci_dev_to_cper(section, out);
+ else if (guid_equal(&descriptors[i]->SectionType,
+ &gEfiDMArGenericErrorSectionGuid))
+ ir_section_dmar_generic_to_cper(section, out);
+ else if (guid_equal(&descriptors[i]->SectionType,
+ &gEfiDirectedIoDMArErrorSectionGuid))
+ ir_section_dmar_vtd_to_cper(section, out);
+ else if (guid_equal(&descriptors[i]->SectionType,
+ &gEfiIommuDMArErrorSectionGuid))
+ ir_section_dmar_iommu_to_cper(section, out);
+ else if (guid_equal(&descriptors[i]->SectionType,
+ &gEfiCcixPerLogErrorSectionGuid))
+ ir_section_ccix_per_to_cper(section, out);
+ else if (guid_equal(&descriptors[i]->SectionType,
+ &gEfiCxlProtocolErrorSectionGuid))
+ ir_section_cxl_protocol_to_cper(section, out);
+ else if (guid_equal(&descriptors[i]->SectionType,
+ &gEfiCxlGeneralMediaErrorSectionGuid) ||
+ guid_equal(&descriptors[i]->SectionType,
+ &gEfiCxlDramEventErrorSectionGuid) ||
+ guid_equal(&descriptors[i]->SectionType,
+ &gEfiCxlPhysicalSwitchErrorSectionGuid) ||
+ guid_equal(&descriptors[i]->SectionType,
+ &gEfiCxlVirtualSwitchErrorSectionGuid) ||
+ guid_equal(&descriptors[i]->SectionType,
+ &gEfiCxlMldPortErrorSectionGuid)) {
+ ir_section_cxl_component_to_cper(section, out);
+ } else {
+ //Unknown GUID, so read as a base64 unknown section.
+ json_object *encoded =
+ json_object_object_get(section, "data");
+ UINT8 *decoded =
+ b64_decode(json_object_get_string(encoded),
+ json_object_get_string_len(encoded));
+ fwrite(decoded, descriptors[i]->SectionLength, 1, out);
+ fflush(out);
+ free(decoded);
+ }
+ }
+
+ //Free all remaining resources.
+ free(header);
+ for (int i = 0; i < amt_descriptors; i++)
+ free(descriptors[i]);
}
//Converts a CPER-JSON IR header to a CPER header structure.
-void ir_header_to_cper(json_object* header_ir, EFI_COMMON_ERROR_RECORD_HEADER* header)
+void ir_header_to_cper(json_object *header_ir,
+ EFI_COMMON_ERROR_RECORD_HEADER *header)
{
- header->SignatureStart = 0x52455043; //CPER
+ header->SignatureStart = 0x52455043; //CPER
- //Revision.
- json_object* revision = json_object_object_get(header_ir, "revision");
- int minor = json_object_get_int(json_object_object_get(revision, "minor"));
- int major = json_object_get_int(json_object_object_get(revision, "major"));
- header->Revision = minor + (major << 8);
+ //Revision.
+ json_object *revision = json_object_object_get(header_ir, "revision");
+ int minor =
+ json_object_get_int(json_object_object_get(revision, "minor"));
+ int major =
+ json_object_get_int(json_object_object_get(revision, "major"));
+ header->Revision = minor + (major << 8);
- header->SignatureEnd = 0xFFFFFFFF;
+ header->SignatureEnd = 0xFFFFFFFF;
- //Section count.
- int section_count = json_object_get_int(json_object_object_get(header_ir, "sectionCount"));
- header->SectionCount = (UINT16)section_count;
+ //Section count.
+ int section_count = json_object_get_int(
+ json_object_object_get(header_ir, "sectionCount"));
+ header->SectionCount = (UINT16)section_count;
- //Error severity.
- json_object* severity = json_object_object_get(header_ir, "severity");
- header->ErrorSeverity = (UINT32)json_object_get_uint64(json_object_object_get(severity, "code"));
+ //Error severity.
+ json_object *severity = json_object_object_get(header_ir, "severity");
+ header->ErrorSeverity = (UINT32)json_object_get_uint64(
+ json_object_object_get(severity, "code"));
- //Validation bits.
- header->ValidationBits = ir_to_bitfield(json_object_object_get(header_ir, "validationBits"),
- 3, CPER_HEADER_VALID_BITFIELD_NAMES);
+ //Validation bits.
+ header->ValidationBits = ir_to_bitfield(
+ json_object_object_get(header_ir, "validationBits"), 3,
+ CPER_HEADER_VALID_BITFIELD_NAMES);
- //Record length.
- header->RecordLength = (UINT32)json_object_get_uint64(json_object_object_get(header_ir, "recordLength"));
+ //Record length.
+ header->RecordLength = (UINT32)json_object_get_uint64(
+ json_object_object_get(header_ir, "recordLength"));
- //Timestamp, if present.
- json_object* timestamp = json_object_object_get(header_ir, "timestamp");
- if (timestamp != NULL)
- {
- string_to_timestamp(&header->TimeStamp, json_object_get_string(timestamp));
- header->TimeStamp.Flag = json_object_get_boolean(json_object_object_get(header_ir, "timestampIsPrecise"));
- }
+ //Timestamp, if present.
+ json_object *timestamp = json_object_object_get(header_ir, "timestamp");
+ if (timestamp != NULL) {
+ string_to_timestamp(&header->TimeStamp,
+ json_object_get_string(timestamp));
+ header->TimeStamp.Flag = json_object_get_boolean(
+ json_object_object_get(header_ir,
+ "timestampIsPrecise"));
+ }
- //Various GUIDs.
- json_object* platform_id = json_object_object_get(header_ir, "platformID");
- json_object* partition_id = json_object_object_get(header_ir, "partitionID");
- if (platform_id != NULL)
- string_to_guid(&header->PlatformID, json_object_get_string(platform_id));
- if (partition_id != NULL)
- string_to_guid(&header->PartitionID, json_object_get_string(partition_id));
- string_to_guid(&header->CreatorID, json_object_get_string(json_object_object_get(header_ir, "creatorID")));
+ //Various GUIDs.
+ json_object *platform_id =
+ json_object_object_get(header_ir, "platformID");
+ json_object *partition_id =
+ json_object_object_get(header_ir, "partitionID");
+ if (platform_id != NULL)
+ string_to_guid(&header->PlatformID,
+ json_object_get_string(platform_id));
+ if (partition_id != NULL)
+ string_to_guid(&header->PartitionID,
+ json_object_get_string(partition_id));
+ string_to_guid(&header->CreatorID,
+ json_object_get_string(
+ json_object_object_get(header_ir, "creatorID")));
- //Notification type.
- json_object* notification_type = json_object_object_get(header_ir, "notificationType");
- string_to_guid(&header->NotificationType, json_object_get_string(json_object_object_get(notification_type, "guid")));
+ //Notification type.
+ json_object *notification_type =
+ json_object_object_get(header_ir, "notificationType");
+ string_to_guid(&header->NotificationType,
+ json_object_get_string(json_object_object_get(
+ notification_type, "guid")));
- //Record ID, persistence info.
- header->RecordID = json_object_get_uint64(json_object_object_get(header_ir, "recordID"));
- header->PersistenceInfo = json_object_get_uint64(json_object_object_get(header_ir, "persistenceInfo"));
+ //Record ID, persistence info.
+ header->RecordID = json_object_get_uint64(
+ json_object_object_get(header_ir, "recordID"));
+ header->PersistenceInfo = json_object_get_uint64(
+ json_object_object_get(header_ir, "persistenceInfo"));
- //Flags.
- json_object* flags = json_object_object_get(header_ir, "flags");
- header->Flags = (UINT32)json_object_get_uint64(json_object_object_get(flags, "value"));
+ //Flags.
+ json_object *flags = json_object_object_get(header_ir, "flags");
+ header->Flags = (UINT32)json_object_get_uint64(
+ json_object_object_get(flags, "value"));
}
//Converts a single CPER-JSON IR section descriptor into a CPER structure.
-void ir_section_descriptor_to_cper(json_object* section_descriptor_ir, EFI_ERROR_SECTION_DESCRIPTOR* descriptor)
+void ir_section_descriptor_to_cper(json_object *section_descriptor_ir,
+ EFI_ERROR_SECTION_DESCRIPTOR *descriptor)
{
- //Section offset, length.
- descriptor->SectionOffset = (UINT32)json_object_get_uint64(json_object_object_get(section_descriptor_ir, "sectionOffset"));
- descriptor->SectionLength = (UINT32)json_object_get_uint64(json_object_object_get(section_descriptor_ir, "sectionLength"));
+ //Section offset, length.
+ descriptor->SectionOffset = (UINT32)json_object_get_uint64(
+ json_object_object_get(section_descriptor_ir, "sectionOffset"));
+ descriptor->SectionLength = (UINT32)json_object_get_uint64(
+ json_object_object_get(section_descriptor_ir, "sectionLength"));
- //Revision.
- json_object* revision = json_object_object_get(section_descriptor_ir, "revision");
- int minor = json_object_get_int(json_object_object_get(revision, "minor"));
- int major = json_object_get_int(json_object_object_get(revision, "major"));
- descriptor->Revision = minor + (major << 8);
+ //Revision.
+ json_object *revision =
+ json_object_object_get(section_descriptor_ir, "revision");
+ int minor =
+ json_object_get_int(json_object_object_get(revision, "minor"));
+ int major =
+ json_object_get_int(json_object_object_get(revision, "major"));
+ descriptor->Revision = minor + (major << 8);
- //Validation bits, flags.
- descriptor->SecValidMask = ir_to_bitfield(json_object_object_get(section_descriptor_ir, "validationBits"),
- 2, CPER_SECTION_DESCRIPTOR_VALID_BITFIELD_NAMES);
- descriptor->SectionFlags = ir_to_bitfield(json_object_object_get(section_descriptor_ir, "flags"),
- 8, CPER_SECTION_DESCRIPTOR_FLAGS_BITFIELD_NAMES);
+ //Validation bits, flags.
+ descriptor->SecValidMask = ir_to_bitfield(
+ json_object_object_get(section_descriptor_ir, "validationBits"),
+ 2, CPER_SECTION_DESCRIPTOR_VALID_BITFIELD_NAMES);
+ descriptor->SectionFlags = ir_to_bitfield(
+ json_object_object_get(section_descriptor_ir, "flags"), 8,
+ CPER_SECTION_DESCRIPTOR_FLAGS_BITFIELD_NAMES);
- //Section type.
- json_object* section_type = json_object_object_get(section_descriptor_ir, "sectionType");
- string_to_guid(&descriptor->SectionType, json_object_get_string(json_object_object_get(section_type, "data")));
+ //Section type.
+ json_object *section_type =
+ json_object_object_get(section_descriptor_ir, "sectionType");
+ string_to_guid(&descriptor->SectionType,
+ json_object_get_string(
+ json_object_object_get(section_type, "data")));
- //FRU ID, if present.
- json_object* fru_id = json_object_object_get(section_descriptor_ir, "fruID");
- if (fru_id != NULL)
- string_to_guid(&descriptor->FruId, json_object_get_string(fru_id));
+ //FRU ID, if present.
+ json_object *fru_id =
+ json_object_object_get(section_descriptor_ir, "fruID");
+ if (fru_id != NULL)
+ string_to_guid(&descriptor->FruId,
+ json_object_get_string(fru_id));
- //Severity code.
- json_object* severity = json_object_object_get(section_descriptor_ir, "severity");
- descriptor->Severity = (UINT32)json_object_get_uint64(json_object_object_get(severity, "code"));
+ //Severity code.
+ json_object *severity =
+ json_object_object_get(section_descriptor_ir, "severity");
+ descriptor->Severity = (UINT32)json_object_get_uint64(
+ json_object_object_get(severity, "code"));
- //FRU text, if present.
- json_object* fru_text = json_object_object_get(section_descriptor_ir, "fruText");
- if (fru_text != NULL)
- strncpy(descriptor->FruString, json_object_get_string(fru_text), 20);
+ //FRU text, if present.
+ json_object *fru_text =
+ json_object_object_get(section_descriptor_ir, "fruText");
+ if (fru_text != NULL)
+ strncpy(descriptor->FruString, json_object_get_string(fru_text),
+ 20);
}
\ No newline at end of file