Lawrence Tang | d34f2b1 | 2022-07-19 15:36:31 +0100 | [diff] [blame] | 1 | /** |
| 2 | * A user-space application for generating psuedo-random specification compliant CPER records. |
| 3 | * |
| 4 | * Author: Lawrence.Tang@arm.com |
| 5 | **/ |
| 6 | |
| 7 | #include <stdio.h> |
| 8 | #include <string.h> |
| 9 | #include "../edk/Cper.h" |
| 10 | #include "cper-generate.h" |
| 11 | |
| 12 | void print_help(); |
| 13 | |
Lawrence Tang | e407b4c | 2022-07-21 13:54:01 +0100 | [diff] [blame^] | 14 | int main(int argc, char *argv[]) |
Lawrence Tang | d34f2b1 | 2022-07-19 15:36:31 +0100 | [diff] [blame] | 15 | { |
Lawrence Tang | e407b4c | 2022-07-21 13:54:01 +0100 | [diff] [blame^] | 16 | //If help requested, print help. |
| 17 | if (argc == 2 && strcmp(argv[1], "--help") == 0) { |
| 18 | print_help(); |
| 19 | return 0; |
| 20 | } |
Lawrence Tang | d34f2b1 | 2022-07-19 15:36:31 +0100 | [diff] [blame] | 21 | |
Lawrence Tang | e407b4c | 2022-07-21 13:54:01 +0100 | [diff] [blame^] | 22 | //Ensure the minimum number of arguments. |
| 23 | if (argc < 5) { |
| 24 | printf("Insufficient number of arguments. See 'cper-generate --help' for command information.\n"); |
| 25 | return -1; |
| 26 | } |
Lawrence Tang | d34f2b1 | 2022-07-19 15:36:31 +0100 | [diff] [blame] | 27 | |
Lawrence Tang | e407b4c | 2022-07-21 13:54:01 +0100 | [diff] [blame^] | 28 | //Open a file handle to write output. |
| 29 | FILE *cper_file = fopen(argv[2], "w"); |
| 30 | if (cper_file == NULL) { |
| 31 | printf("Could not get a handle for output file '%s', file handle returned null.\n", |
| 32 | argv[2]); |
| 33 | return -1; |
| 34 | } |
Lawrence Tang | d34f2b1 | 2022-07-19 15:36:31 +0100 | [diff] [blame] | 35 | |
Lawrence Tang | e407b4c | 2022-07-21 13:54:01 +0100 | [diff] [blame^] | 36 | //Generate the record. Type names start from argv[4]. |
| 37 | UINT16 num_sections = argc - 4; |
| 38 | generate_cper_record(argv + 4, num_sections, cper_file); |
| 39 | fclose(cper_file); |
Lawrence Tang | d34f2b1 | 2022-07-19 15:36:31 +0100 | [diff] [blame] | 40 | } |
| 41 | |
Lawrence Tang | d34f2b1 | 2022-07-19 15:36:31 +0100 | [diff] [blame] | 42 | //Prints command help for this CPER generator. |
| 43 | void print_help() |
| 44 | { |
Lawrence Tang | e407b4c | 2022-07-21 13:54:01 +0100 | [diff] [blame^] | 45 | printf(":: --out cper.file --sections section1 [section2 section3 ...]\n"); |
| 46 | printf("\tGenerates a psuedo-random CPER file with the provided section types and outputs to the given file name.\n"); |
| 47 | printf("\tValid section type names are the following:\n"); |
| 48 | printf("\t\t- generic\n"); |
| 49 | printf("\t\t- ia32x64\n"); |
| 50 | printf("\t\t- ipf\n"); |
| 51 | printf("\t\t- arm\n"); |
| 52 | printf("\t\t- memory\n"); |
| 53 | printf("\t\t- memory2\n"); |
| 54 | printf("\t\t- pcie\n"); |
| 55 | printf("\t\t- firmware\n"); |
| 56 | printf("\t\t- pcibus\n"); |
| 57 | printf("\t\t- pcidev\n"); |
| 58 | printf("\t\t- dmargeneric\n"); |
| 59 | printf("\t\t- dmarvtd\n"); |
| 60 | printf("\t\t- dmariommu\n"); |
| 61 | printf("\t\t- ccixper\n"); |
| 62 | printf("\t\t- cxlprotocol\n"); |
| 63 | printf("\t\t- cxlcomponent\n"); |
| 64 | printf("\t\t- unknown\n"); |
| 65 | printf("\n:: --help\n"); |
| 66 | printf("\tDisplays help information to the console.\n"); |
Lawrence Tang | d34f2b1 | 2022-07-19 15:36:31 +0100 | [diff] [blame] | 67 | } |