xref: /openbmc/libcper/docs/OEMExtensions.md (revision ec9fc0db)
1ea4b82b3SLawrence Tang# Extending `cper-parse` With OEM Sections
2044afd01SJohn Chung
3044afd01SJohn ChungSection definitions within `cper-parse` are entirely modular, and can be easily
4044afd01SJohn Chungmodified at compile time to include custom OEM section extensions. This document
5044afd01SJohn Chungwill detail how these extensions can be added in from a stock version of the
6044afd01SJohn Chungproject.
7ea4b82b3SLawrence Tang
8ea4b82b3SLawrence Tang## Creating a Section Parser
9ea4b82b3SLawrence Tang
10044afd01SJohn ChungFirst, we need to create a parser to actually handle the conversion of the
11044afd01SJohn Chungsection from CPER -> CPER-JSON and CPER-JSON -> CPER. For the purposes of
12044afd01SJohn Chungexample here, we will create a fake CPER section, "myVendorSection", in
13044afd01SJohn Chung`cper-section-myvendor.h` and `cper-section-myvendor.c`.
14044afd01SJohn Chung
15*ec9fc0dbSGeorge Liu_sections/cper-section-myvendor.h_:
16044afd01SJohn Chung
17ea4b82b3SLawrence Tang```c
18ea4b82b3SLawrence Tang#ifndef CPER_SECTION_MYVENDOR
19ea4b82b3SLawrence Tang#define CPER_SECTION_MYVENDOR
20ea4b82b3SLawrence Tang
21ea4b82b3SLawrence Tang#include <json.h>
22ea4b82b3SLawrence Tang#include "../edk/Cper.h"
23ea4b82b3SLawrence Tang
24ea4b82b3SLawrence Tangjson_object* cper_section_myvendor_to_ir(void* section, EFI_ERROR_SECTION_DESCRIPTOR* descriptor);
25ea4b82b3SLawrence Tangvoid ir_section_myvendor_to_cper(json_object* section, FILE* out);
26ea4b82b3SLawrence Tang
27ea4b82b3SLawrence Tang#endif
28ea4b82b3SLawrence Tang```
29ea4b82b3SLawrence Tang
30*ec9fc0dbSGeorge Liu_sections/cper-section-myvendor.c_:
31044afd01SJohn Chung
32ea4b82b3SLawrence Tang```c
33ea4b82b3SLawrence Tang/**
34ea4b82b3SLawrence Tang * Describes functions for converting MyVendor sections from binary and JSON format
35ea4b82b3SLawrence Tang * into an intermediate format.
36ea4b82b3SLawrence Tang *
37ea4b82b3SLawrence Tang * Author: author@example.com
38ea4b82b3SLawrence Tang **/
39ea4b82b3SLawrence Tang#include <stdio.h>
40ea4b82b3SLawrence Tang#include <json.h>
41ea4b82b3SLawrence Tang#include "../edk/Cper.h"
42ea4b82b3SLawrence Tang#include "cper-section-ccix-per.h"
43ea4b82b3SLawrence Tang
44ea4b82b3SLawrence Tangjson_object* cper_section_myvendor_to_ir(void* section, EFI_ERROR_SECTION_DESCRIPTOR* descriptor)
45ea4b82b3SLawrence Tang{
46ea4b82b3SLawrence Tang    //Define a method here that converts the bytes starting from "section" into JSON IR.
47ea4b82b3SLawrence Tang    //The length of the bytes is described in descriptor->Length.
48ea4b82b3SLawrence Tang    //...
49ea4b82b3SLawrence Tang}
50ea4b82b3SLawrence Tang
51ea4b82b3SLawrence Tangvoid ir_section_myvendor_to_cper(json_object* section, FILE* out)
52ea4b82b3SLawrence Tang{
53ea4b82b3SLawrence Tang    //Define a method here that converts the given JSON IR object into CPER binary,
54ea4b82b3SLawrence Tang    //writing the output to the provided stream.
55ea4b82b3SLawrence Tang    //...
56ea4b82b3SLawrence Tang}
57ea4b82b3SLawrence Tang```
58044afd01SJohn Chung
59ea4b82b3SLawrence TangOnce this is done, we can add our section to the parser.
60ea4b82b3SLawrence Tang
61ea4b82b3SLawrence Tang## Adding a Section GUID
62ea4b82b3SLawrence Tang
63044afd01SJohn ChungTo identify our section for parsing, we must define a section GUID within
64044afd01SJohn Chung`edk/Cper.h` and `edk/Cper.c` respectively. They are defined here for shared use
65044afd01SJohn Chungin both `cper-parse` and also `cper-generator` if you wish to write a generation
66044afd01SJohn Chungmethod for your section.
67044afd01SJohn Chung
68044afd01SJohn Chung_edk/Cper.h_:
69044afd01SJohn Chung
70ea4b82b3SLawrence Tang```c
71ea4b82b3SLawrence Tang...
72ea4b82b3SLawrence Tangextern EFI_GUID   gEfiCxlVirtualSwitchErrorSectionGuid;
73ea4b82b3SLawrence Tangextern EFI_GUID   gEfiCxlMldPortErrorSectionGuid;
74ea4b82b3SLawrence Tangextern EFI_GUID   gMyVendorSectionGuid;
75ea4b82b3SLawrence Tang```
76ea4b82b3SLawrence Tang
77044afd01SJohn Chung_edk/Cper.c_:
78044afd01SJohn Chung
79ea4b82b3SLawrence Tang```c
80ea4b82b3SLawrence Tang...
81ea4b82b3SLawrence TangEFI_GUID gEfiCxlVirtualSwitchErrorSectionGuid = { 0x40d26425, 0x3396, 0x4c4d, { 0xa5, 0xda, 0x3d, 0x47, 0x26, 0x3a, 0xf4, 0x25 }};
82ea4b82b3SLawrence TangEFI_GUID gEfiCxlMldPortErrorSectionGuid = { 0x8dc44363, 0x0c96, 0x4710, { 0xb7, 0xbf, 0x04, 0xbb, 0x99, 0x53, 0x4c, 0x3f }};
83ea4b82b3SLawrence TangEFI_GUID gMyVendorSectionGuid = { 0x40d26425, 0x3396, 0x4c4d, { 0xa5, 0xda, 0x3d, 0x47, 0x26, 0x3a, 0xf4, 0x25 }};
84ea4b82b3SLawrence Tang```
85ea4b82b3SLawrence Tang
86ea4b82b3SLawrence Tang## Adding a Section Definition
87ea4b82b3SLawrence Tang
88044afd01SJohn ChungFinally, we need to add a section definition for our section, matching the GUID
89044afd01SJohn Chungto the name and conversion methods. Open `sections/cper-section.c` and add your
90044afd01SJohn Chungdefinition to the `section_definitions` array, like so:
91044afd01SJohn Chung
92*ec9fc0dbSGeorge Liu_sections/cper-section.c_:
93044afd01SJohn Chung
94ea4b82b3SLawrence Tang```c
95ea4b82b3SLawrence Tang/**
96ea4b82b3SLawrence Tang * Describes available sections to the CPER parser.
97ea4b82b3SLawrence Tang *
98ea4b82b3SLawrence Tang * Author: Lawrence.Tang@arm.com
99ea4b82b3SLawrence Tang **/
100ea4b82b3SLawrence Tang#include "../edk/Cper.h"
101ea4b82b3SLawrence Tang#include "cper-section.h"
102ea4b82b3SLawrence Tang...
103ea4b82b3SLawrence Tang#include "cper-section-myvendor.h"
104ea4b82b3SLawrence Tang
105ea4b82b3SLawrence Tang//Definitions of all sections available to the CPER parser.
106ea4b82b3SLawrence TangCPER_SECTION_DEFINITION section_definitions[] = {
107ea4b82b3SLawrence Tang    ...
108ea4b82b3SLawrence Tang    {&gMyVendorSectionGuid, "MyVendor Error", cper_section_myvendor_to_ir, ir_section_myvendor_to_cper},
109ea4b82b3SLawrence Tang};
110ea4b82b3SLawrence Tang```
111044afd01SJohn Chung
112044afd01SJohn ChungNow you're done! After a further `cmake .` and `make`, `cper-convert` and all
113044afd01SJohn Chungother conversion libraries included should successfully convert your OEM CPER
114044afd01SJohn Chungsection between CPER-JSON and CPER binary.
115