1 /**
2  * A user-space application for generating pseudo-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 		print_help();
19 		return 0;
20 	}
21 
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 	}
27 
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 	}
35 
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);
40 }
41 
42 //Prints command help for this CPER generator.
43 void print_help()
44 {
45 	printf(":: --out cper.file --sections section1 [section2 section3 ...]\n");
46 	printf("\tGenerates a pseudo-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");
67 }