1# Extending `cper-parse` With OEM Sections 2Section definitions within `cper-parse` are entirely modular, and can be easily modified at compile time to include custom OEM section extensions. This document will detail how these extensions can be added in from a stock version of the project. 3 4## Creating a Section Parser 5First, we need to create a parser to actually handle the conversion of the section from CPER -> CPER-JSON and CPER-JSON -> CPER. 6For the purposes of example here, we will create a fake CPER section, "myVendorSection", in `cper-section-myvendor.h` and `cper-section-myvendor.c`. 7 8*sections/cper-section-myvendor.h* 9```c 10#ifndef CPER_SECTION_MYVENDOR 11#define CPER_SECTION_MYVENDOR 12 13#include <json.h> 14#include "../edk/Cper.h" 15 16json_object* cper_section_myvendor_to_ir(void* section, EFI_ERROR_SECTION_DESCRIPTOR* descriptor); 17void ir_section_myvendor_to_cper(json_object* section, FILE* out); 18 19#endif 20``` 21 22*sections/cper-section-myvendor.c* 23```c 24/** 25 * Describes functions for converting MyVendor sections from binary and JSON format 26 * into an intermediate format. 27 * 28 * Author: author@example.com 29 **/ 30#include <stdio.h> 31#include <json.h> 32#include "../edk/Cper.h" 33#include "cper-section-ccix-per.h" 34 35json_object* cper_section_myvendor_to_ir(void* section, EFI_ERROR_SECTION_DESCRIPTOR* descriptor) 36{ 37 //Define a method here that converts the bytes starting from "section" into JSON IR. 38 //The length of the bytes is described in descriptor->Length. 39 //... 40} 41 42void ir_section_myvendor_to_cper(json_object* section, FILE* out) 43{ 44 //Define a method here that converts the given JSON IR object into CPER binary, 45 //writing the output to the provided stream. 46 //... 47} 48``` 49Once this is done, we can add our section to the parser. 50 51## Adding a Section GUID 52To identify our section for parsing, we must define a section GUID within `edk/Cper.h` and `edk/Cper.c` respectively. 53They are defined here for shared use in both `cper-parse` and also `cper-generator` if you wish to write a generation method for your section. 54 55*edk/Cper.h*: 56```c 57... 58extern EFI_GUID gEfiCxlVirtualSwitchErrorSectionGuid; 59extern EFI_GUID gEfiCxlMldPortErrorSectionGuid; 60extern EFI_GUID gMyVendorSectionGuid; 61``` 62 63*edk/Cper.c*: 64```c 65... 66EFI_GUID gEfiCxlVirtualSwitchErrorSectionGuid = { 0x40d26425, 0x3396, 0x4c4d, { 0xa5, 0xda, 0x3d, 0x47, 0x26, 0x3a, 0xf4, 0x25 }}; 67EFI_GUID gEfiCxlMldPortErrorSectionGuid = { 0x8dc44363, 0x0c96, 0x4710, { 0xb7, 0xbf, 0x04, 0xbb, 0x99, 0x53, 0x4c, 0x3f }}; 68EFI_GUID gMyVendorSectionGuid = { 0x40d26425, 0x3396, 0x4c4d, { 0xa5, 0xda, 0x3d, 0x47, 0x26, 0x3a, 0xf4, 0x25 }}; 69``` 70 71## Adding a Section Definition 72Finally, we need to add a section definition for our section, matching the GUID to the name and conversion methods. 73Open `sections/cper-section.c` and add your definition to the `section_definitions` array, like so: 74 75*sections/cper-section.c* 76```c 77/** 78 * Describes available sections to the CPER parser. 79 * 80 * Author: Lawrence.Tang@arm.com 81 **/ 82#include "../edk/Cper.h" 83#include "cper-section.h" 84... 85#include "cper-section-myvendor.h" 86 87//Definitions of all sections available to the CPER parser. 88CPER_SECTION_DEFINITION section_definitions[] = { 89 ... 90 {&gMyVendorSectionGuid, "MyVendor Error", cper_section_myvendor_to_ir, ir_section_myvendor_to_cper}, 91}; 92``` 93Now you're done! After a further `cmake .` and `make`, `cper-convert` and all other conversion libraries included should successfully convert your OEM CPER section between CPER-JSON and CPER binary.