1*ea4b82b3SLawrence Tang# Extending `cper-parse` With OEM Sections 2*ea4b82b3SLawrence TangSection 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*ea4b82b3SLawrence Tang 4*ea4b82b3SLawrence Tang## Creating a Section Parser 5*ea4b82b3SLawrence TangFirst, we need to create a parser to actually handle the conversion of the section from CPER -> CPER-JSON and CPER-JSON -> CPER. 6*ea4b82b3SLawrence TangFor the purposes of example here, we will create a fake CPER section, "myVendorSection", in `cper-section-myvendor.h` and `cper-section-myvendor.c`. 7*ea4b82b3SLawrence Tang 8*ea4b82b3SLawrence Tang*sections/cper-section-myvendor.h* 9*ea4b82b3SLawrence Tang```c 10*ea4b82b3SLawrence Tang#ifndef CPER_SECTION_MYVENDOR 11*ea4b82b3SLawrence Tang#define CPER_SECTION_MYVENDOR 12*ea4b82b3SLawrence Tang 13*ea4b82b3SLawrence Tang#include <json.h> 14*ea4b82b3SLawrence Tang#include "../edk/Cper.h" 15*ea4b82b3SLawrence Tang 16*ea4b82b3SLawrence Tangjson_object* cper_section_myvendor_to_ir(void* section, EFI_ERROR_SECTION_DESCRIPTOR* descriptor); 17*ea4b82b3SLawrence Tangvoid ir_section_myvendor_to_cper(json_object* section, FILE* out); 18*ea4b82b3SLawrence Tang 19*ea4b82b3SLawrence Tang#endif 20*ea4b82b3SLawrence Tang``` 21*ea4b82b3SLawrence Tang 22*ea4b82b3SLawrence Tang*sections/cper-section-myvendor.c* 23*ea4b82b3SLawrence Tang```c 24*ea4b82b3SLawrence Tang/** 25*ea4b82b3SLawrence Tang * Describes functions for converting MyVendor sections from binary and JSON format 26*ea4b82b3SLawrence Tang * into an intermediate format. 27*ea4b82b3SLawrence Tang * 28*ea4b82b3SLawrence Tang * Author: author@example.com 29*ea4b82b3SLawrence Tang **/ 30*ea4b82b3SLawrence Tang#include <stdio.h> 31*ea4b82b3SLawrence Tang#include <json.h> 32*ea4b82b3SLawrence Tang#include "../edk/Cper.h" 33*ea4b82b3SLawrence Tang#include "cper-section-ccix-per.h" 34*ea4b82b3SLawrence Tang 35*ea4b82b3SLawrence Tangjson_object* cper_section_myvendor_to_ir(void* section, EFI_ERROR_SECTION_DESCRIPTOR* descriptor) 36*ea4b82b3SLawrence Tang{ 37*ea4b82b3SLawrence Tang //Define a method here that converts the bytes starting from "section" into JSON IR. 38*ea4b82b3SLawrence Tang //The length of the bytes is described in descriptor->Length. 39*ea4b82b3SLawrence Tang //... 40*ea4b82b3SLawrence Tang} 41*ea4b82b3SLawrence Tang 42*ea4b82b3SLawrence Tangvoid ir_section_myvendor_to_cper(json_object* section, FILE* out) 43*ea4b82b3SLawrence Tang{ 44*ea4b82b3SLawrence Tang //Define a method here that converts the given JSON IR object into CPER binary, 45*ea4b82b3SLawrence Tang //writing the output to the provided stream. 46*ea4b82b3SLawrence Tang //... 47*ea4b82b3SLawrence Tang} 48*ea4b82b3SLawrence Tang``` 49*ea4b82b3SLawrence TangOnce this is done, we can add our section to the parser. 50*ea4b82b3SLawrence Tang 51*ea4b82b3SLawrence Tang## Adding a Section GUID 52*ea4b82b3SLawrence TangTo identify our section for parsing, we must define a section GUID within `edk/Cper.h` and `edk/Cper.c` respectively. 53*ea4b82b3SLawrence TangThey 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*ea4b82b3SLawrence Tang 55*ea4b82b3SLawrence Tang*edk/Cper.h*: 56*ea4b82b3SLawrence Tang```c 57*ea4b82b3SLawrence Tang... 58*ea4b82b3SLawrence Tangextern EFI_GUID gEfiCxlVirtualSwitchErrorSectionGuid; 59*ea4b82b3SLawrence Tangextern EFI_GUID gEfiCxlMldPortErrorSectionGuid; 60*ea4b82b3SLawrence Tangextern EFI_GUID gMyVendorSectionGuid; 61*ea4b82b3SLawrence Tang``` 62*ea4b82b3SLawrence Tang 63*ea4b82b3SLawrence Tang*edk/Cper.c*: 64*ea4b82b3SLawrence Tang```c 65*ea4b82b3SLawrence Tang... 66*ea4b82b3SLawrence TangEFI_GUID gEfiCxlVirtualSwitchErrorSectionGuid = { 0x40d26425, 0x3396, 0x4c4d, { 0xa5, 0xda, 0x3d, 0x47, 0x26, 0x3a, 0xf4, 0x25 }}; 67*ea4b82b3SLawrence TangEFI_GUID gEfiCxlMldPortErrorSectionGuid = { 0x8dc44363, 0x0c96, 0x4710, { 0xb7, 0xbf, 0x04, 0xbb, 0x99, 0x53, 0x4c, 0x3f }}; 68*ea4b82b3SLawrence TangEFI_GUID gMyVendorSectionGuid = { 0x40d26425, 0x3396, 0x4c4d, { 0xa5, 0xda, 0x3d, 0x47, 0x26, 0x3a, 0xf4, 0x25 }}; 69*ea4b82b3SLawrence Tang``` 70*ea4b82b3SLawrence Tang 71*ea4b82b3SLawrence Tang## Adding a Section Definition 72*ea4b82b3SLawrence TangFinally, we need to add a section definition for our section, matching the GUID to the name and conversion methods. 73*ea4b82b3SLawrence TangOpen `sections/cper-section.c` and add your definition to the `section_definitions` array, like so: 74*ea4b82b3SLawrence Tang 75*ea4b82b3SLawrence Tang*sections/cper-section.c* 76*ea4b82b3SLawrence Tang```c 77*ea4b82b3SLawrence Tang/** 78*ea4b82b3SLawrence Tang * Describes available sections to the CPER parser. 79*ea4b82b3SLawrence Tang * 80*ea4b82b3SLawrence Tang * Author: Lawrence.Tang@arm.com 81*ea4b82b3SLawrence Tang **/ 82*ea4b82b3SLawrence Tang#include "../edk/Cper.h" 83*ea4b82b3SLawrence Tang#include "cper-section.h" 84*ea4b82b3SLawrence Tang... 85*ea4b82b3SLawrence Tang#include "cper-section-myvendor.h" 86*ea4b82b3SLawrence Tang 87*ea4b82b3SLawrence Tang//Definitions of all sections available to the CPER parser. 88*ea4b82b3SLawrence TangCPER_SECTION_DEFINITION section_definitions[] = { 89*ea4b82b3SLawrence Tang ... 90*ea4b82b3SLawrence Tang {&gMyVendorSectionGuid, "MyVendor Error", cper_section_myvendor_to_ir, ir_section_myvendor_to_cper}, 91*ea4b82b3SLawrence Tang}; 92*ea4b82b3SLawrence Tang``` 93*ea4b82b3SLawrence TangNow 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.