blob: 7afc2aaf045206e07e3b1ff9b3cca9ea4c7e65bb [file] [log] [blame]
Lawrence Tangd34f2b12022-07-19 15:36:31 +01001/**
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
12void print_help();
13
Lawrence Tange407b4c2022-07-21 13:54:01 +010014int main(int argc, char *argv[])
Lawrence Tangd34f2b12022-07-19 15:36:31 +010015{
Lawrence Tange407b4c2022-07-21 13:54:01 +010016 //If help requested, print help.
17 if (argc == 2 && strcmp(argv[1], "--help") == 0) {
18 print_help();
19 return 0;
20 }
Lawrence Tangd34f2b12022-07-19 15:36:31 +010021
Lawrence Tange407b4c2022-07-21 13:54:01 +010022 //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 Tangd34f2b12022-07-19 15:36:31 +010027
Lawrence Tange407b4c2022-07-21 13:54:01 +010028 //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 Tangd34f2b12022-07-19 15:36:31 +010035
Lawrence Tange407b4c2022-07-21 13:54:01 +010036 //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 Tangd34f2b12022-07-19 15:36:31 +010040}
41
Lawrence Tangd34f2b12022-07-19 15:36:31 +010042//Prints command help for this CPER generator.
43void print_help()
44{
Lawrence Tange407b4c2022-07-21 13:54:01 +010045 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 Tangd34f2b12022-07-19 15:36:31 +010067}