1 #include <stdio.h> 2 #include <json.h> 3 #include <libcper/Cper.h> 4 #include <libcper/cper-utils.h> 5 #include <libcper/sections/cper-section-ampere.h> 6 #include <libcper/log.h> 7 8 //Converts the given processor-generic CPER section into JSON IR. 9 json_object *cper_section_ampere_to_ir(const UINT8 *section, UINT32 size) 10 { 11 if (size < sizeof(EFI_AMPERE_ERROR_DATA)) { 12 return NULL; 13 } 14 15 EFI_AMPERE_ERROR_DATA *record = (EFI_AMPERE_ERROR_DATA *)section; 16 json_object *section_ir = json_object_new_object(); 17 18 json_object_object_add(section_ir, "typeId", 19 json_object_new_int(record->TypeId)); 20 json_object_object_add(section_ir, "subTypeId", 21 json_object_new_int(record->SubtypeId)); 22 json_object_object_add(section_ir, "instanceId", 23 json_object_new_int(record->InstanceId)); 24 25 return section_ir; 26 } 27 28 //Converts a single CPER-JSON ARM error section into CPER binary, outputting to the given stream. 29 void ir_section_ampere_to_cper(json_object *section, FILE *out) 30 { 31 EFI_AMPERE_ERROR_DATA *section_cper = (EFI_AMPERE_ERROR_DATA *)calloc( 32 1, sizeof(EFI_AMPERE_ERROR_DATA)); 33 34 //Count of error/context info structures. 35 section_cper->TypeId = 36 json_object_get_int(json_object_object_get(section, "typeId")); 37 section_cper->SubtypeId = json_object_get_int( 38 json_object_object_get(section, "subTypeId")); 39 section_cper->InstanceId = json_object_get_int( 40 json_object_object_get(section, "instanceId")); 41 42 //Flush header to stream. 43 fwrite(section_cper, sizeof(EFI_AMPERE_ERROR_DATA), 1, out); 44 fflush(out); 45 free(section_cper); 46 } 47