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