blob: 7b47e54a060ea2968e6d2a46b76cb3b7c4f8b866 [file] [log] [blame]
Lawrence Tangde9707f2022-07-19 10:54:31 +01001/**
Lawrence Tangefe17e22022-08-08 09:16:23 +01002 * Functions for generating pseudo-random CPER firmware error sections.
Lawrence Tangde9707f2022-07-19 10:54:31 +01003 *
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
Lawrence Tangefe17e22022-08-08 09:16:23 +010012//Generates a single pseudo-random firmware error section, saving the resulting address to the given
Lawrence Tangde9707f2022-07-19 10:54:31 +010013//location. Returns the size of the newly created section.
14size_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.
Lawrence Tang0a4b3f22022-07-21 10:40:10 +010021 for (int i=0; i<6; i++)
22 *(bytes + 2 + i) = 0; //Reserved bytes 2-7.
Lawrence Tangde9707f2022-07-19 10:54:31 +010023
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}