1 /**
2  * Functions for generating pseudo-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-section.h"
11 
12 //Generates a single pseudo-random firmware error section, saving the resulting address to the given
13 //location. Returns the size of the newly created section.
generate_section_firmware(void ** location)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 
25 	//Set expected values.
26 	*(bytes + 1) = 2;    //Revision, referenced version of spec is 2.
27 	UINT64 *record_id = (UINT64 *)(bytes + 8);
28 	*record_id = 0;	     //Record ID, should be forced to NULL.
29 	*bytes = rand() % 3; //Record type.
30 
31 	//Set return values, exit.
32 	*location = bytes;
33 	return size;
34 }
35