blob: 7604dc0e7adc9dc4598dff22b480adb1e9f5e9b8 [file] [log] [blame]
#include <stdio.h>
#include <json.h>
#include <libcper/Cper.h>
#include <libcper/cper-utils.h>
#include <libcper/sections/cper-section-ampere.h>
//Converts the given processor-generic CPER section into JSON IR.
json_object *cper_section_ampere_to_ir(void *section)
{
EFI_AMPERE_ERROR_DATA *record = (EFI_AMPERE_ERROR_DATA *)section;
json_object *section_ir = json_object_new_object();
json_object_object_add(section_ir, "typeId",
json_object_new_int(record->TypeId));
json_object_object_add(section_ir, "subTypeId",
json_object_new_int(record->SubtypeId));
json_object_object_add(section_ir, "instanceId",
json_object_new_int(record->InstanceId));
return section_ir;
}
//Converts a single CPER-JSON ARM error section into CPER binary, outputting to the given stream.
void ir_section_ampere_to_cper(json_object *section, FILE *out)
{
EFI_AMPERE_ERROR_DATA *section_cper = (EFI_AMPERE_ERROR_DATA *)calloc(
1, sizeof(EFI_AMPERE_ERROR_DATA));
//Count of error/context info structures.
section_cper->TypeId =
json_object_get_int(json_object_object_get(section, "typeId"));
section_cper->SubtypeId = json_object_get_int(
json_object_object_get(section, "subTypeId"));
section_cper->InstanceId = json_object_get_int(
json_object_object_get(section, "instanceId"));
//Flush header to stream.
fwrite(section_cper, sizeof(EFI_AMPERE_ERROR_DATA), 1, out);
fflush(out);
free(section_cper);
}