Add CPER conversion for single section records.
diff --git a/generator/cper-generate-cli.c b/generator/cper-generate-cli.c
index 0f0399b..ed974f5 100644
--- a/generator/cper-generate-cli.c
+++ b/generator/cper-generate-cli.c
@@ -22,18 +22,23 @@
//Parse the command line arguments.
char *out_file = NULL;
+ char *single_section = NULL;
char **sections = NULL;
UINT16 num_sections = 0;
for (int i = 1; i < argc; i++) {
if (strcmp(argv[i], "--out") == 0 && i < argc - 1) {
out_file = argv[i + 1];
i++;
+ } else if (strcmp(argv[i], "--single-section") == 0 &&
+ i < argc - 1) {
+ single_section = argv[i + 1];
+ i++;
} else if (strcmp(argv[i], "--sections") == 0 && i < argc - 1) {
//All arguments after this must be section names.
num_sections = argc - i - 1;
sections = malloc(sizeof(char *) * num_sections);
i++;
-
+
for (int j = i; j < argc; j++)
sections[j - i] = argv[j];
break;
@@ -58,8 +63,16 @@
return -1;
}
- //Generate the record. Type names start from argv[4].
- generate_cper_record(sections, num_sections, cper_file);
+ //Which type are we generating?
+ if (single_section != NULL && sections == NULL) {
+ generate_single_section_record(single_section, cper_file);
+ } else if (sections != NULL && single_section == NULL) {
+ generate_cper_record(sections, num_sections, cper_file);
+ } else {
+ //Invalid arguments.
+ printf("Invalid argument. Either both '--sections' and '--single-section' were set, or neither. For command information, refer to 'cper-generate --help'.\n");
+ return -1;
+ }
//Close & free remaining resources.
fclose(cper_file);
@@ -70,8 +83,12 @@
//Prints command help for this CPER generator.
void print_help()
{
- printf(":: --out cper.file --sections section1 [section2 section3 ...]\n");
- printf("\tGenerates a pseudo-random CPER file with the provided section types and outputs to the given file name.\n");
+ printf(":: --out cper.file [--sections section1 ...] [--single-section sectiontype]\n");
+ printf("\tGenerates a pseudo-random CPER file with the provided section types and outputs to the given file name.\n\n");
+ printf("\tWhen the '--sections' flag is set, all following arguments are section names, and a full CPER log is generated\n");
+ printf("\tcontaining the given sections.\n");
+ printf("\tWhen the '--single-section' flag is set, the next argument is the single section that should be generated, and\n");
+ printf("\ta single section (no header, only a section descriptor & section) CPER file is generated.\n\n");
printf("\tValid section type names are the following:\n");
printf("\t\t- generic\n");
printf("\t\t- ia32x64\n");
diff --git a/generator/cper-generate.c b/generator/cper-generate.c
index 594bd90..3322372 100644
--- a/generator/cper-generate.c
+++ b/generator/cper-generate.c
@@ -89,6 +89,29 @@
}
}
+//Generates a single section record for the given section, and outputs to file.
+void generate_single_section_record(char *type, FILE *out)
+{
+ //Generate a section.
+ void *section;
+ size_t section_len = generate_section(§ion, type);
+
+ //Generate a descriptor, correct the offset.
+ EFI_ERROR_SECTION_DESCRIPTOR *section_descriptor =
+ generate_section_descriptor(type, §ion_len, 0, 1);
+ section_descriptor->SectionOffset =
+ sizeof(EFI_ERROR_SECTION_DESCRIPTOR);
+
+ //Write all to file.
+ fwrite(section_descriptor, sizeof(EFI_ERROR_SECTION_DESCRIPTOR), 1,
+ out);
+ fwrite(section, section_len, 1, out);
+ fflush(out);
+
+ //Free remaining resources.
+ free(section_descriptor);
+}
+
//Generates a single section descriptor for a section with the given properties.
EFI_ERROR_SECTION_DESCRIPTOR *generate_section_descriptor(char *type,
size_t *lengths,
diff --git a/generator/cper-generate.h b/generator/cper-generate.h
index 213cf8c..2874fa5 100644
--- a/generator/cper-generate.h
+++ b/generator/cper-generate.h
@@ -4,6 +4,7 @@
#include <stdio.h>
#include "../edk/BaseTypes.h"
-void generate_cper_record(char** types, UINT16 num_sections, FILE* cper_file);
+void generate_cper_record(char **types, UINT16 num_sections, FILE *cper_file);
+void generate_single_section_record(char *type, FILE *out);
#endif
\ No newline at end of file