blob: 6ec4b888dddcc2abec0217ac1c8850f81a62ecb5 [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.
Ed Tanousfedd4572024-07-12 13:56:00 -07003 *
Lawrence Tangde9707f2022-07-19 10:54:31 +01004 * Author: Lawrence.Tang@arm.com
5 **/
6
7#include <stdlib.h>
Thu Nguyene42fb482024-10-15 14:43:11 +00008#include <libcper/BaseTypes.h>
9#include <libcper/generator/gen-utils.h>
10#include <libcper/generator/sections/gen-section.h>
Lawrence Tangde9707f2022-07-19 10:54:31 +010011
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.
Aushim Nagarkattiae8f6d92025-01-29 17:34:44 -080014size_t generate_section_firmware(void **location,
15 GEN_VALID_BITS_TEST_TYPE validBitsType)
Lawrence Tangde9707f2022-07-19 10:54:31 +010016{
Aushim Nagarkattiae8f6d92025-01-29 17:34:44 -080017 (void)validBitsType;
John Chungf8fc7052024-05-03 20:05:29 +080018 //Create random bytes.
19 int size = 32;
20 UINT8 *bytes = generate_random_bytes(size);
Lawrence Tangde9707f2022-07-19 10:54:31 +010021
John Chungf8fc7052024-05-03 20:05:29 +080022 //Set reserved areas to zero.
23 for (int i = 0; i < 6; i++) {
24 *(bytes + 2 + i) = 0; //Reserved bytes 2-7.
25 }
Lawrence Tangde9707f2022-07-19 10:54:31 +010026
John Chungf8fc7052024-05-03 20:05:29 +080027 //Set expected values.
28 *(bytes + 1) = 2; //Revision, referenced version of spec is 2.
29 UINT64 *record_id = (UINT64 *)(bytes + 8);
30 *record_id = 0; //Record ID, should be forced to NULL.
31 *bytes = rand() % 3; //Record type.
32
33 //Set return values, exit.
34 *location = bytes;
35 return size;
36}