1 /**
2  * Functions for generating psuedo-random CPER firmware error sections.
3  *
4  * Author: Lawrence.Tang@arm.com
5  **/
6 
7 #include <stdlib.h>
8 #include "../../edk/BaseTypes.h"
9 #include "../gen-utils.h"
10 #include "gen-sections.h"
11 
12 //Generates a single psuedo-random firmware error section, saving the resulting address to the given
13 //location. Returns the size of the newly created section.
14 size_t generate_section_firmware(void** location)
15 {
16     //Create random bytes.
17     int size = 32;
18     UINT8* bytes = generate_random_bytes(size);
19 
20     //Set reserved areas to zero.
21     for (int i=0; i<6; i++)
22         *(bytes + 2 + i) = 0; //Reserved bytes 2-7.
23 
24     //Set expected values.
25     *(bytes + 1) = 2; //Revision, referenced version of spec is 2.
26     UINT64* record_id = (UINT64*)(bytes + 8);
27     *record_id = 0; //Record ID, should be forced to NULL.
28     *bytes = rand() % 3; //Record type.
29 
30     //Set return values, exit.
31     *location = bytes;
32     return size;
33 }