1 /**
2  * Describes functions for converting firmware CPER sections from binary and JSON format
3  * into an intermediate format.
4  *
5  * Author: Lawrence.Tang@arm.com
6  **/
7 #include <stdio.h>
8 #include "json.h"
9 #include "../edk/Cper.h"
10 #include "../cper-utils.h"
11 #include "cper-section-firmware.h"
12 
13 //Converts a single firmware CPER section into JSON IR.
14 json_object* cper_section_firmware_to_ir(void* section, EFI_ERROR_SECTION_DESCRIPTOR* descriptor)
15 {
16     EFI_FIRMWARE_ERROR_DATA* firmware_error = (EFI_FIRMWARE_ERROR_DATA*)section;
17     json_object* section_ir = json_object_new_object();
18 
19     //Record type.
20     json_object* record_type = integer_to_readable_pair(firmware_error->ErrorType, 3,
21         FIRMWARE_ERROR_RECORD_TYPES_KEYS,
22         FIRMWARE_ERROR_RECORD_TYPES_VALUES,
23         "Unknown (Reserved)");
24     json_object_object_add(section_ir, "errorRecordType", record_type);
25 
26     //Revision, record identifier.
27     json_object_object_add(section_ir, "revision", json_object_new_int(firmware_error->Revision));
28     json_object_object_add(section_ir, "recordID", json_object_new_uint64(firmware_error->RecordId));
29 
30     //Record GUID.
31     char record_id_guid[GUID_STRING_LENGTH];
32     guid_to_string(record_id_guid, &firmware_error->RecordIdGuid);
33     json_object_object_add(section_ir, "recordIDGUID", json_object_new_string(record_id_guid));
34 
35     return section_ir;
36 }