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. |
Ed Tanous | fedd457 | 2024-07-12 13:56:00 -0700 | [diff] [blame] | 3 | * |
Lawrence Tang | de9707f | 2022-07-19 10:54:31 +0100 | [diff] [blame] | 4 | * Author: Lawrence.Tang@arm.com |
| 5 | **/ |
| 6 | |
| 7 | #include <stdlib.h> |
Ed Tanous | a3b7f8a | 2024-11-04 16:38:59 -0800 | [diff] [blame^] | 8 | #include "../../BaseTypes.h" |
Lawrence Tang | de9707f | 2022-07-19 10:54:31 +0100 | [diff] [blame] | 9 | #include "../gen-utils.h" |
Lawrence Tang | 8f97745 | 2022-08-24 14:55:07 +0100 | [diff] [blame] | 10 | #include "gen-section.h" |
Lawrence Tang | de9707f | 2022-07-19 10:54:31 +0100 | [diff] [blame] | 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. |
John Chung | f8fc705 | 2024-05-03 20:05:29 +0800 | [diff] [blame] | 14 | size_t generate_section_firmware(void **location) |
Lawrence Tang | de9707f | 2022-07-19 10:54:31 +0100 | [diff] [blame] | 15 | { |
John Chung | f8fc705 | 2024-05-03 20:05:29 +0800 | [diff] [blame] | 16 | //Create random bytes. |
| 17 | int size = 32; |
| 18 | UINT8 *bytes = generate_random_bytes(size); |
Lawrence Tang | de9707f | 2022-07-19 10:54:31 +0100 | [diff] [blame] | 19 | |
John Chung | f8fc705 | 2024-05-03 20:05:29 +0800 | [diff] [blame] | 20 | //Set reserved areas to zero. |
| 21 | for (int i = 0; i < 6; i++) { |
| 22 | *(bytes + 2 + i) = 0; //Reserved bytes 2-7. |
| 23 | } |
Lawrence Tang | de9707f | 2022-07-19 10:54:31 +0100 | [diff] [blame] | 24 | |
John Chung | f8fc705 | 2024-05-03 20:05:29 +0800 | [diff] [blame] | 25 | //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 | } |