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