1# Extending `cper-generator` With OEM Sections
2Much like `cper-parse`, `cper-generator` supports the addition of arbitrary OEM sections as extensions. This document details how an OEM section generator could be added to the `cper-generate` project from a stock version.
3
4## Creating a Section Generator
5The first step is to create the generator itself. To do this, you should create a function predefinition inside `sections/gen-section.h` as shown below, and then create a C file within `sections/` to house your generation code. For the sake of example, we will create a generator for a fake OEM section "myVendorSection".
6
7*sections/gen-section.h*
8```c
9//Section generator function predefinitions.
10...
11size_t generate_section_cxl_protocol(void** location);
12size_t generate_section_cxl_component(void** location);
13size_t generate_section_myvendor(void** location);
14```
15
16*sections/gen-myvendor.c*
17```c
18/**
19 * Functions for generating pseudo-random MyVendor error sections.
20 *
21 * Author: author@example.com
22 **/
23
24#include <stdlib.h>
25
26size_t generate_section_myvendor(void** location)
27{
28    //...
29}
30```
31
32## Adding a Section GUID
33To identify our section for parsing, we must define a section GUID within `edk/Cper.h` and `edk/Cper.c` respectively.
34This is the same step taken when adding an OEM extension to `cper-parse`, so if you've already done this, you do not need to repeat it again.
35
36*edk/Cper.h*:
37```c
38...
39extern EFI_GUID   gEfiCxlVirtualSwitchErrorSectionGuid;
40extern EFI_GUID   gEfiCxlMldPortErrorSectionGuid;
41extern EFI_GUID   gMyVendorSectionGuid;
42```
43
44*edk/Cper.c*:
45```c
46...
47EFI_GUID gEfiCxlVirtualSwitchErrorSectionGuid = { 0x40d26425, 0x3396, 0x4c4d, { 0xa5, 0xda, 0x3d, 0x47, 0x26, 0x3a, 0xf4, 0x25 }};
48EFI_GUID gEfiCxlMldPortErrorSectionGuid = { 0x8dc44363, 0x0c96, 0x4710, { 0xb7, 0xbf, 0x04, 0xbb, 0x99, 0x53, 0x4c, 0x3f }};
49EFI_GUID gMyVendorSectionGuid = { 0x40d26425, 0x3396, 0x4c4d, { 0xa5, 0xda, 0x3d, 0x47, 0x26, 0x3a, 0xf4, 0x25 }};
50```
51
52## Adding a Generator Definition
53Now that a GUID and generation function are created for our section, we can finally add it to the generator definitions for `cper-generate`. To do this, edit `sections/gen-section.c` and add your generator definition to the `generator_definitions` array. The second string parameter here is the shortcode used for generating your section, and must contain **no spaces** (this is also asserted via. GTest).
54```c
55/**
56 * Describes available section generators to the CPER generator.
57 *
58 * Author: Lawrence.Tang@arm.com
59 **/
60#include "gen-section.h"
61
62CPER_GENERATOR_DEFINITION generator_definitions[] = {
63    ...
64    {&gEfiCxlVirtualSwitchErrorSectionGuid, "cxlcomponent-vswitch", generate_section_cxl_component},
65    {&gEfiCxlMldPortErrorSectionGuid, "cxlcomponent-mld", generate_section_cxl_component},
66    {&gMyVendorSectionGuid, "myvendor", generate_section_myvendor},
67};
68```
69Once this is complete, after a `cmake .` and `make`, your section should be available to generate through `cper-generate` and `libcper-generate`.