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