1de9707f9SLawrence Tang /** 2efe17e2cSLawrence 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" 108f977457SLawrence Tang #include "gen-section.h" 11de9707f9SLawrence Tang 12efe17e2cSLawrence 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. 21*f8fc7052SJohn Chung for (int i = 0; i < 6; i++) { 220a4b3f2dSLawrence Tang *(bytes + 2 + i) = 0; //Reserved bytes 2-7. 23*f8fc7052SJohn Chung } 24de9707f9SLawrence Tang 25de9707f9SLawrence Tang //Set expected values. 26de9707f9SLawrence Tang *(bytes + 1) = 2; //Revision, referenced version of spec is 2. 27de9707f9SLawrence Tang UINT64 *record_id = (UINT64 *)(bytes + 8); 28de9707f9SLawrence Tang *record_id = 0; //Record ID, should be forced to NULL. 29de9707f9SLawrence Tang *bytes = rand() % 3; //Record type. 30de9707f9SLawrence Tang 31de9707f9SLawrence Tang //Set return values, exit. 32de9707f9SLawrence Tang *location = bytes; 33de9707f9SLawrence Tang return size; 34de9707f9SLawrence Tang } 35