blob: dd2d69dc26720a0a8c404306ce1637b1f699d386 [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>
Ed Tanousa3b7f8a2024-11-04 16:38:59 -08008#include "../../BaseTypes.h"
Lawrence Tangde9707f2022-07-19 10:54:31 +01009#include "../gen-utils.h"
Lawrence Tang8f977452022-08-24 14:55:07 +010010#include "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}