1de9707f9SLawrence Tang /** 2*efe17e2cSLawrence Tang * Functions for generating pseudo-random CPER firmware error sections. 3de9707f9SLawrence Tang * 4de9707f9SLawrence Tang * Author: Lawrence.Tang@arm.com 5de9707f9SLawrence Tang **/ 6de9707f9SLawrence Tang 7de9707f9SLawrence Tang #include <stdlib.h> 8de9707f9SLawrence Tang #include "../../edk/BaseTypes.h" 9de9707f9SLawrence Tang #include "../gen-utils.h" 10de9707f9SLawrence Tang #include "gen-sections.h" 11de9707f9SLawrence Tang 12*efe17e2cSLawrence Tang //Generates a single pseudo-random firmware error section, saving the resulting address to the given 13de9707f9SLawrence Tang //location. Returns the size of the newly created section. 14de9707f9SLawrence Tang size_t generate_section_firmware(void** location) 15de9707f9SLawrence Tang { 16de9707f9SLawrence Tang //Create random bytes. 17de9707f9SLawrence Tang int size = 32; 18de9707f9SLawrence Tang UINT8* bytes = generate_random_bytes(size); 19de9707f9SLawrence Tang 20de9707f9SLawrence Tang //Set reserved areas to zero. 210a4b3f2dSLawrence Tang for (int i=0; i<6; i++) 220a4b3f2dSLawrence Tang *(bytes + 2 + i) = 0; //Reserved bytes 2-7. 23de9707f9SLawrence Tang 24de9707f9SLawrence Tang //Set expected values. 25de9707f9SLawrence Tang *(bytes + 1) = 2; //Revision, referenced version of spec is 2. 26de9707f9SLawrence Tang UINT64* record_id = (UINT64*)(bytes + 8); 27de9707f9SLawrence Tang *record_id = 0; //Record ID, should be forced to NULL. 28de9707f9SLawrence Tang *bytes = rand() % 3; //Record type. 29de9707f9SLawrence Tang 30de9707f9SLawrence Tang //Set return values, exit. 31de9707f9SLawrence Tang *location = bytes; 32de9707f9SLawrence Tang return size; 33de9707f9SLawrence Tang }