blob: e482a6b11e6aa245e33190242eb6096a9e928eb7 [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.
John Chungf8fc7052024-05-03 20:05:29 +080014size_t generate_section_firmware(void **location)
Lawrence Tangde9707f2022-07-19 10:54:31 +010015{
John Chungf8fc7052024-05-03 20:05:29 +080016 //Create random bytes.
17 int size = 32;
18 UINT8 *bytes = generate_random_bytes(size);
Lawrence Tangde9707f2022-07-19 10:54:31 +010019
John Chungf8fc7052024-05-03 20:05:29 +080020 //Set reserved areas to zero.
21 for (int i = 0; i < 6; i++) {
22 *(bytes + 2 + i) = 0; //Reserved bytes 2-7.
23 }
Lawrence Tangde9707f2022-07-19 10:54:31 +010024
John Chungf8fc7052024-05-03 20:05:29 +080025 //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}