Partial reformat to kernel code style.
diff --git a/generator/cper-generate-cli.c b/generator/cper-generate-cli.c
index 0b17efe..7afc2aa 100644
--- a/generator/cper-generate-cli.c
+++ b/generator/cper-generate-cli.c
@@ -11,60 +11,57 @@
void print_help();
-int main(int argc, char* argv[])
+int main(int argc, char *argv[])
{
- //If help requested, print help.
- if (argc == 2 && strcmp(argv[1], "--help") == 0)
- {
- print_help();
- return 0;
- }
+ //If help requested, print help.
+ if (argc == 2 && strcmp(argv[1], "--help") == 0) {
+ print_help();
+ return 0;
+ }
- //Ensure the minimum number of arguments.
- if (argc < 5)
- {
- printf("Insufficient number of arguments. See 'cper-generate --help' for command information.\n");
- return -1;
- }
+ //Ensure the minimum number of arguments.
+ if (argc < 5) {
+ printf("Insufficient number of arguments. See 'cper-generate --help' for command information.\n");
+ return -1;
+ }
- //Open a file handle to write output.
- FILE* cper_file = fopen(argv[2], "w");
- if (cper_file == NULL)
- {
- printf("Could not get a handle for output file '%s', file handle returned null.\n", argv[2]);
- return -1;
- }
+ //Open a file handle to write output.
+ FILE *cper_file = fopen(argv[2], "w");
+ if (cper_file == NULL) {
+ printf("Could not get a handle for output file '%s', file handle returned null.\n",
+ argv[2]);
+ return -1;
+ }
- //Generate the record. Type names start from argv[4].
- UINT16 num_sections = argc - 4;
- generate_cper_record(argv + 4, num_sections, cper_file);
- fclose(cper_file);
+ //Generate the record. Type names start from argv[4].
+ UINT16 num_sections = argc - 4;
+ generate_cper_record(argv + 4, num_sections, cper_file);
+ fclose(cper_file);
}
-
//Prints command help for this CPER generator.
void print_help()
{
- printf(":: --out cper.file --sections section1 [section2 section3 ...]\n");
- printf("\tGenerates a psuedo-random CPER file with the provided section types and outputs to the given file name.\n");
- printf("\tValid section type names are the following:\n");
- printf("\t\t- generic\n");
- printf("\t\t- ia32x64\n");
- printf("\t\t- ipf\n");
- printf("\t\t- arm\n");
- printf("\t\t- memory\n");
- printf("\t\t- memory2\n");
- printf("\t\t- pcie\n");
- printf("\t\t- firmware\n");
- printf("\t\t- pcibus\n");
- printf("\t\t- pcidev\n");
- printf("\t\t- dmargeneric\n");
- printf("\t\t- dmarvtd\n");
- printf("\t\t- dmariommu\n");
- printf("\t\t- ccixper\n");
- printf("\t\t- cxlprotocol\n");
- printf("\t\t- cxlcomponent\n");
- printf("\t\t- unknown\n");
- printf("\n:: --help\n");
- printf("\tDisplays help information to the console.\n");
+ printf(":: --out cper.file --sections section1 [section2 section3 ...]\n");
+ printf("\tGenerates a psuedo-random CPER file with the provided section types and outputs to the given file name.\n");
+ printf("\tValid section type names are the following:\n");
+ printf("\t\t- generic\n");
+ printf("\t\t- ia32x64\n");
+ printf("\t\t- ipf\n");
+ printf("\t\t- arm\n");
+ printf("\t\t- memory\n");
+ printf("\t\t- memory2\n");
+ printf("\t\t- pcie\n");
+ printf("\t\t- firmware\n");
+ printf("\t\t- pcibus\n");
+ printf("\t\t- pcidev\n");
+ printf("\t\t- dmargeneric\n");
+ printf("\t\t- dmarvtd\n");
+ printf("\t\t- dmariommu\n");
+ printf("\t\t- ccixper\n");
+ printf("\t\t- cxlprotocol\n");
+ printf("\t\t- cxlcomponent\n");
+ printf("\t\t- unknown\n");
+ printf("\n:: --help\n");
+ printf("\tDisplays help information to the console.\n");
}
\ No newline at end of file
diff --git a/generator/cper-generate.c b/generator/cper-generate.c
index 7e7cc40..b1389b5 100644
--- a/generator/cper-generate.c
+++ b/generator/cper-generate.c
@@ -12,225 +12,254 @@
#include "sections/gen-sections.h"
#include "cper-generate.h"
-EFI_ERROR_SECTION_DESCRIPTOR* generate_section_descriptor(char* type, size_t* lengths, int index, int num_sections);
-size_t generate_section(void** location, char* type);
+EFI_ERROR_SECTION_DESCRIPTOR *generate_section_descriptor(char *type,
+ size_t *lengths,
+ int index,
+ int num_sections);
+size_t generate_section(void **location, char *type);
//Generates a CPER record with the given section types, outputting to the given stream.
-void generate_cper_record(char** types, UINT16 num_sections, FILE* out)
+void generate_cper_record(char **types, UINT16 num_sections, FILE *out)
{
- //Initialise randomiser.
- init_random();
+ //Initialise randomiser.
+ init_random();
- //Generate the sections.
- void* sections[num_sections];
- size_t section_lengths[num_sections];
- for (int i=0; i<num_sections; i++)
- {
- section_lengths[i] = generate_section(sections + i, types[i]);
- if (section_lengths[i] == 0)
- {
- //Error encountered, exit.
- printf("Error encountered generating section %d of type '%s', length returned zero.\n", i+1, types[i]);
- return;
- }
- }
+ //Generate the sections.
+ void *sections[num_sections];
+ size_t section_lengths[num_sections];
+ for (int i = 0; i < num_sections; i++) {
+ section_lengths[i] = generate_section(sections + i, types[i]);
+ if (section_lengths[i] == 0) {
+ //Error encountered, exit.
+ printf("Error encountered generating section %d of type '%s', length returned zero.\n",
+ i + 1, types[i]);
+ return;
+ }
+ }
- //Generate the header given the number of sections.
- EFI_COMMON_ERROR_RECORD_HEADER* header =
- (EFI_COMMON_ERROR_RECORD_HEADER*)calloc(1, sizeof(EFI_COMMON_ERROR_RECORD_HEADER));
- header->SignatureStart = 0x52455043; //CPER
- header->SectionCount = num_sections;
- header->SignatureEnd = 0xFFFFFFFF;
- header->Flags = 4; //HW_ERROR_FLAGS_SIMULATED
- header->RecordID = (UINT64)rand();
- header->ErrorSeverity = rand() % 4;
+ //Generate the header given the number of sections.
+ EFI_COMMON_ERROR_RECORD_HEADER *header =
+ (EFI_COMMON_ERROR_RECORD_HEADER *)calloc(
+ 1, sizeof(EFI_COMMON_ERROR_RECORD_HEADER));
+ header->SignatureStart = 0x52455043; //CPER
+ header->SectionCount = num_sections;
+ header->SignatureEnd = 0xFFFFFFFF;
+ header->Flags = 4; //HW_ERROR_FLAGS_SIMULATED
+ header->RecordID = (UINT64)rand();
+ header->ErrorSeverity = rand() % 4;
- //Generate a valid timestamp.
- header->TimeStamp.Century = int_to_bcd(rand() % 100);
- header->TimeStamp.Year = int_to_bcd(rand() % 100);
- header->TimeStamp.Month = int_to_bcd(rand() % 12 + 1);
- header->TimeStamp.Day = int_to_bcd(rand() % 31 + 1);
- header->TimeStamp.Hours = int_to_bcd(rand() % 24 + 1);
- header->TimeStamp.Seconds = int_to_bcd(rand() % 60);
+ //Generate a valid timestamp.
+ header->TimeStamp.Century = int_to_bcd(rand() % 100);
+ header->TimeStamp.Year = int_to_bcd(rand() % 100);
+ header->TimeStamp.Month = int_to_bcd(rand() % 12 + 1);
+ header->TimeStamp.Day = int_to_bcd(rand() % 31 + 1);
+ header->TimeStamp.Hours = int_to_bcd(rand() % 24 + 1);
+ header->TimeStamp.Seconds = int_to_bcd(rand() % 60);
- //Turn all validation bits on.
- header->ValidationBits = 0b11;
+ //Turn all validation bits on.
+ header->ValidationBits = 0b11;
- //Generate the section descriptors given the number of sections.
- EFI_ERROR_SECTION_DESCRIPTOR* section_descriptors[num_sections];
- for (int i=0; i<num_sections; i++)
- section_descriptors[i] = generate_section_descriptor(types[i], section_lengths, i, num_sections);
+ //Generate the section descriptors given the number of sections.
+ EFI_ERROR_SECTION_DESCRIPTOR *section_descriptors[num_sections];
+ for (int i = 0; i < num_sections; i++)
+ section_descriptors[i] = generate_section_descriptor(
+ types[i], section_lengths, i, num_sections);
- //Calculate total length of structure, set in header.
- size_t total_len = sizeof(EFI_COMMON_ERROR_RECORD_HEADER);
- for (int i=0; i<num_sections; i++)
- total_len += section_lengths[i];
- total_len += num_sections * sizeof(EFI_ERROR_SECTION_DESCRIPTOR);
- header->RecordLength = (UINT32)total_len;
+ //Calculate total length of structure, set in header.
+ size_t total_len = sizeof(EFI_COMMON_ERROR_RECORD_HEADER);
+ for (int i = 0; i < num_sections; i++)
+ total_len += section_lengths[i];
+ total_len += num_sections * sizeof(EFI_ERROR_SECTION_DESCRIPTOR);
+ header->RecordLength = (UINT32)total_len;
- //Write to stream in order, free all resources.
- fwrite(header, sizeof(EFI_COMMON_ERROR_RECORD_HEADER), 1, out);
- fflush(out);
- free(header);
- for (int i=0; i<num_sections; i++)
- {
- fwrite(section_descriptors[i], sizeof(EFI_ERROR_SECTION_DESCRIPTOR), 1, out);
- fflush(out);
- free(section_descriptors[i]);
- }
- for (int i=0; i<num_sections; i++)
- {
- fwrite(sections[i], section_lengths[i], 1, out);
- fflush(out);
- free(sections[i]);
- }
+ //Write to stream in order, free all resources.
+ fwrite(header, sizeof(EFI_COMMON_ERROR_RECORD_HEADER), 1, out);
+ fflush(out);
+ free(header);
+ for (int i = 0; i < num_sections; i++) {
+ fwrite(section_descriptors[i],
+ sizeof(EFI_ERROR_SECTION_DESCRIPTOR), 1, out);
+ fflush(out);
+ free(section_descriptors[i]);
+ }
+ for (int i = 0; i < num_sections; i++) {
+ fwrite(sections[i], section_lengths[i], 1, out);
+ fflush(out);
+ free(sections[i]);
+ }
}
//Generates a single section descriptor for a section with the given properties.
-EFI_ERROR_SECTION_DESCRIPTOR* generate_section_descriptor(char* type, size_t* lengths, int index, int num_sections)
+EFI_ERROR_SECTION_DESCRIPTOR *generate_section_descriptor(char *type,
+ size_t *lengths,
+ int index,
+ int num_sections)
{
- EFI_ERROR_SECTION_DESCRIPTOR* descriptor =
- (EFI_ERROR_SECTION_DESCRIPTOR*)generate_random_bytes(sizeof(EFI_ERROR_SECTION_DESCRIPTOR));
+ EFI_ERROR_SECTION_DESCRIPTOR *descriptor =
+ (EFI_ERROR_SECTION_DESCRIPTOR *)generate_random_bytes(
+ sizeof(EFI_ERROR_SECTION_DESCRIPTOR));
- //Set reserved bits to zero.
- descriptor->Resv1 = 0;
- descriptor->SectionFlags &= 0xFF;
+ //Set reserved bits to zero.
+ descriptor->Resv1 = 0;
+ descriptor->SectionFlags &= 0xFF;
- //Validation bits all set to 'on'.
- descriptor->SecValidMask = 0b11;
+ //Validation bits all set to 'on'.
+ descriptor->SecValidMask = 0b11;
- //Set severity.
- descriptor->Severity = rand() % 4;
+ //Set severity.
+ descriptor->Severity = rand() % 4;
- //Set length, offset from base record.
- descriptor->SectionLength = (UINT32)lengths[index];
- descriptor->SectionOffset = sizeof(EFI_COMMON_ERROR_RECORD_HEADER)
- + (num_sections * sizeof(EFI_ERROR_SECTION_DESCRIPTOR));
- for (int i=0; i<index; i++)
- descriptor->SectionOffset += lengths[i];
-
- //Ensure the FRU text is not null terminated early.
- for (int i=0; i<20; i++)
- {
- if (descriptor->FruString[i] == 0x0)
- descriptor->FruString[i] = rand() % 127 + 1;
+ //Set length, offset from base record.
+ descriptor->SectionLength = (UINT32)lengths[index];
+ descriptor->SectionOffset =
+ sizeof(EFI_COMMON_ERROR_RECORD_HEADER) +
+ (num_sections * sizeof(EFI_ERROR_SECTION_DESCRIPTOR));
+ for (int i = 0; i < index; i++)
+ descriptor->SectionOffset += lengths[i];
- //Null terminate last byte.
- if (i == 19)
- descriptor->FruString[i] = 0x0;
- }
+ //Ensure the FRU text is not null terminated early.
+ for (int i = 0; i < 20; i++) {
+ if (descriptor->FruString[i] == 0x0)
+ descriptor->FruString[i] = rand() % 127 + 1;
- //Set section type GUID based on type name.
- if (strcmp(type, "generic") == 0)
- memcpy(&descriptor->SectionType, &gEfiProcessorGenericErrorSectionGuid, sizeof(EFI_GUID));
- else if (strcmp(type, "ia32x64") == 0)
- memcpy(&descriptor->SectionType, &gEfiIa32X64ProcessorErrorSectionGuid, sizeof(EFI_GUID));
- else if (strcmp(type, "ipf") == 0)
- memcpy(&descriptor->SectionType, &gEfiIpfProcessorErrorSectionGuid, sizeof(EFI_GUID));
- else if (strcmp(type, "arm") == 0)
- memcpy(&descriptor->SectionType, &gEfiArmProcessorErrorSectionGuid, sizeof(EFI_GUID));
- else if (strcmp(type, "memory") == 0)
- memcpy(&descriptor->SectionType, &gEfiPlatformMemoryErrorSectionGuid, sizeof(EFI_GUID));
- else if (strcmp(type, "memory2") == 0)
- memcpy(&descriptor->SectionType, &gEfiPlatformMemoryError2SectionGuid, sizeof(EFI_GUID));
- else if (strcmp(type, "pcie") == 0)
- memcpy(&descriptor->SectionType, &gEfiPcieErrorSectionGuid, sizeof(EFI_GUID));
- else if (strcmp(type, "firmware") == 0)
- memcpy(&descriptor->SectionType, &gEfiFirmwareErrorSectionGuid, sizeof(EFI_GUID));
- else if (strcmp(type, "pcibus") == 0)
- memcpy(&descriptor->SectionType, &gEfiPciBusErrorSectionGuid, sizeof(EFI_GUID));
- else if (strcmp(type, "pcidev") == 0)
- memcpy(&descriptor->SectionType, &gEfiPciDevErrorSectionGuid, sizeof(EFI_GUID));
- else if (strcmp(type, "dmargeneric") == 0)
- memcpy(&descriptor->SectionType, &gEfiDMArGenericErrorSectionGuid, sizeof(EFI_GUID));
- else if (strcmp(type, "dmarvtd") == 0)
- memcpy(&descriptor->SectionType, &gEfiDirectedIoDMArErrorSectionGuid, sizeof(EFI_GUID));
- else if (strcmp(type, "dmariommu") == 0)
- memcpy(&descriptor->SectionType, &gEfiIommuDMArErrorSectionGuid, sizeof(EFI_GUID));
- else if (strcmp(type, "ccixper") == 0)
- memcpy(&descriptor->SectionType, &gEfiCcixPerLogErrorSectionGuid, sizeof(EFI_GUID));
- else if (strcmp(type, "cxlprotocol") == 0)
- memcpy(&descriptor->SectionType, &gEfiCxlProtocolErrorSectionGuid, sizeof(EFI_GUID));
- else if (strcmp(type, "cxlcomponent") == 0)
- {
- //Choose between the different CXL component type GUIDs.
- int componentType = rand() % 5;
- switch (componentType)
- {
- case 0:
- memcpy(&descriptor->SectionType, &gEfiCxlGeneralMediaErrorSectionGuid, sizeof(EFI_GUID));
- break;
- case 1:
- memcpy(&descriptor->SectionType, &gEfiCxlDramEventErrorSectionGuid, sizeof(EFI_GUID));
- break;
- case 2:
- memcpy(&descriptor->SectionType, &gEfiCxlPhysicalSwitchErrorSectionGuid, sizeof(EFI_GUID));
- break;
- case 3:
- memcpy(&descriptor->SectionType, &gEfiCxlVirtualSwitchErrorSectionGuid, sizeof(EFI_GUID));
- break;
- default:
- memcpy(&descriptor->SectionType, &gEfiCxlMldPortErrorSectionGuid, sizeof(EFI_GUID));
- break;
- }
- }
- else if (strcmp(type, "unknown") != 0)
- {
- //Undefined section, show error.
- printf("Undefined section type '%s' provided. See 'cper-generate --help' for command information.\n", type);
- return 0;
- }
+ //Null terminate last byte.
+ if (i == 19)
+ descriptor->FruString[i] = 0x0;
+ }
- return descriptor;
+ //Set section type GUID based on type name.
+ if (strcmp(type, "generic") == 0)
+ memcpy(&descriptor->SectionType,
+ &gEfiProcessorGenericErrorSectionGuid, sizeof(EFI_GUID));
+ else if (strcmp(type, "ia32x64") == 0)
+ memcpy(&descriptor->SectionType,
+ &gEfiIa32X64ProcessorErrorSectionGuid, sizeof(EFI_GUID));
+ else if (strcmp(type, "ipf") == 0)
+ memcpy(&descriptor->SectionType,
+ &gEfiIpfProcessorErrorSectionGuid, sizeof(EFI_GUID));
+ else if (strcmp(type, "arm") == 0)
+ memcpy(&descriptor->SectionType,
+ &gEfiArmProcessorErrorSectionGuid, sizeof(EFI_GUID));
+ else if (strcmp(type, "memory") == 0)
+ memcpy(&descriptor->SectionType,
+ &gEfiPlatformMemoryErrorSectionGuid, sizeof(EFI_GUID));
+ else if (strcmp(type, "memory2") == 0)
+ memcpy(&descriptor->SectionType,
+ &gEfiPlatformMemoryError2SectionGuid, sizeof(EFI_GUID));
+ else if (strcmp(type, "pcie") == 0)
+ memcpy(&descriptor->SectionType, &gEfiPcieErrorSectionGuid,
+ sizeof(EFI_GUID));
+ else if (strcmp(type, "firmware") == 0)
+ memcpy(&descriptor->SectionType, &gEfiFirmwareErrorSectionGuid,
+ sizeof(EFI_GUID));
+ else if (strcmp(type, "pcibus") == 0)
+ memcpy(&descriptor->SectionType, &gEfiPciBusErrorSectionGuid,
+ sizeof(EFI_GUID));
+ else if (strcmp(type, "pcidev") == 0)
+ memcpy(&descriptor->SectionType, &gEfiPciDevErrorSectionGuid,
+ sizeof(EFI_GUID));
+ else if (strcmp(type, "dmargeneric") == 0)
+ memcpy(&descriptor->SectionType,
+ &gEfiDMArGenericErrorSectionGuid, sizeof(EFI_GUID));
+ else if (strcmp(type, "dmarvtd") == 0)
+ memcpy(&descriptor->SectionType,
+ &gEfiDirectedIoDMArErrorSectionGuid, sizeof(EFI_GUID));
+ else if (strcmp(type, "dmariommu") == 0)
+ memcpy(&descriptor->SectionType, &gEfiIommuDMArErrorSectionGuid,
+ sizeof(EFI_GUID));
+ else if (strcmp(type, "ccixper") == 0)
+ memcpy(&descriptor->SectionType,
+ &gEfiCcixPerLogErrorSectionGuid, sizeof(EFI_GUID));
+ else if (strcmp(type, "cxlprotocol") == 0)
+ memcpy(&descriptor->SectionType,
+ &gEfiCxlProtocolErrorSectionGuid, sizeof(EFI_GUID));
+ else if (strcmp(type, "cxlcomponent") == 0) {
+ //Choose between the different CXL component type GUIDs.
+ int componentType = rand() % 5;
+ switch (componentType) {
+ case 0:
+ memcpy(&descriptor->SectionType,
+ &gEfiCxlGeneralMediaErrorSectionGuid,
+ sizeof(EFI_GUID));
+ break;
+ case 1:
+ memcpy(&descriptor->SectionType,
+ &gEfiCxlDramEventErrorSectionGuid,
+ sizeof(EFI_GUID));
+ break;
+ case 2:
+ memcpy(&descriptor->SectionType,
+ &gEfiCxlPhysicalSwitchErrorSectionGuid,
+ sizeof(EFI_GUID));
+ break;
+ case 3:
+ memcpy(&descriptor->SectionType,
+ &gEfiCxlVirtualSwitchErrorSectionGuid,
+ sizeof(EFI_GUID));
+ break;
+ default:
+ memcpy(&descriptor->SectionType,
+ &gEfiCxlMldPortErrorSectionGuid,
+ sizeof(EFI_GUID));
+ break;
+ }
+ } else if (strcmp(type, "unknown") != 0) {
+ //Undefined section, show error.
+ printf("Undefined section type '%s' provided. See 'cper-generate --help' for command information.\n",
+ type);
+ return 0;
+ }
+
+ return descriptor;
}
//Generates a single CPER section given the string type.
-size_t generate_section(void** location, char* type)
+size_t generate_section(void **location, char *type)
{
- //The length of the section.
- size_t length = 0;
+ //The length of the section.
+ size_t length = 0;
- //Switch on the type, generate accordingly.
- if (strcmp(type, "generic") == 0)
- length = generate_section_generic(location);
- else if (strcmp(type, "ia32x64") == 0)
- length = generate_section_ia32x64(location);
- // else if (strcmp(type, "ipf") == 0)
- // length = generate_section_ipf(location);
- else if (strcmp(type, "arm") == 0)
- length = generate_section_arm(location);
- else if (strcmp(type, "memory") == 0)
- length = generate_section_memory(location);
- else if (strcmp(type, "memory2") == 0)
- length = generate_section_memory2(location);
- else if (strcmp(type, "pcie") == 0)
- length = generate_section_pcie(location);
- else if (strcmp(type, "firmware") == 0)
- length = generate_section_firmware(location);
- else if (strcmp(type, "pcibus") == 0)
- length = generate_section_pci_bus(location);
- else if (strcmp(type, "pcidev") == 0)
- length = generate_section_pci_dev(location);
- else if (strcmp(type, "dmargeneric") == 0)
- length = generate_section_dmar_generic(location);
- else if (strcmp(type, "dmarvtd") == 0)
- length = generate_section_dmar_vtd(location);
- else if (strcmp(type, "dmariommu") == 0)
- length = generate_section_dmar_iommu(location);
- else if (strcmp(type, "ccixper") == 0)
- length = generate_section_ccix_per(location);
- else if (strcmp(type, "cxlprotocol") == 0)
- length = generate_section_cxl_protocol(location);
- else if (strcmp(type, "cxlcomponent") == 0)
- length = generate_section_cxl_component(location);
- else if (strcmp(type, "unknown") == 0)
- length = generate_random_section(location, rand() % 256);
- else
- {
- //Undefined section, show error.
- printf("Undefined section type '%s' given to generate. See 'cper-generate --help' for command information.\n", type);
- return 0;
- }
+ //Switch on the type, generate accordingly.
+ if (strcmp(type, "generic") == 0)
+ length = generate_section_generic(location);
+ else if (strcmp(type, "ia32x64") == 0)
+ length = generate_section_ia32x64(location);
+ // else if (strcmp(type, "ipf") == 0)
+ // length = generate_section_ipf(location);
+ else if (strcmp(type, "arm") == 0)
+ length = generate_section_arm(location);
+ else if (strcmp(type, "memory") == 0)
+ length = generate_section_memory(location);
+ else if (strcmp(type, "memory2") == 0)
+ length = generate_section_memory2(location);
+ else if (strcmp(type, "pcie") == 0)
+ length = generate_section_pcie(location);
+ else if (strcmp(type, "firmware") == 0)
+ length = generate_section_firmware(location);
+ else if (strcmp(type, "pcibus") == 0)
+ length = generate_section_pci_bus(location);
+ else if (strcmp(type, "pcidev") == 0)
+ length = generate_section_pci_dev(location);
+ else if (strcmp(type, "dmargeneric") == 0)
+ length = generate_section_dmar_generic(location);
+ else if (strcmp(type, "dmarvtd") == 0)
+ length = generate_section_dmar_vtd(location);
+ else if (strcmp(type, "dmariommu") == 0)
+ length = generate_section_dmar_iommu(location);
+ else if (strcmp(type, "ccixper") == 0)
+ length = generate_section_ccix_per(location);
+ else if (strcmp(type, "cxlprotocol") == 0)
+ length = generate_section_cxl_protocol(location);
+ else if (strcmp(type, "cxlcomponent") == 0)
+ length = generate_section_cxl_component(location);
+ else if (strcmp(type, "unknown") == 0)
+ length = generate_random_section(location, rand() % 256);
+ else {
+ //Undefined section, show error.
+ printf("Undefined section type '%s' given to generate. See 'cper-generate --help' for command information.\n",
+ type);
+ return 0;
+ }
- return length;
+ return length;
}
\ No newline at end of file
diff --git a/generator/gen-utils.c b/generator/gen-utils.c
index 1ab318f..bce904a 100644
--- a/generator/gen-utils.c
+++ b/generator/gen-utils.c
@@ -10,36 +10,38 @@
//Generates a random section of the given byte size, saving the result to the given location.
//Returns the length of the section as passed in.
-size_t generate_random_section(void** location, size_t size)
+size_t generate_random_section(void **location, size_t size)
{
- *location = generate_random_bytes(size);
- return size;
+ *location = generate_random_bytes(size);
+ return size;
}
//Generates a random byte allocation of the given size.
-UINT8* generate_random_bytes(size_t size)
+UINT8 *generate_random_bytes(size_t size)
{
- UINT8* bytes = malloc(size);
- for (size_t i = 0; i < size; i++)
- bytes[i] = rand();
- return bytes;
+ UINT8 *bytes = malloc(size);
+ for (size_t i = 0; i < size; i++)
+ bytes[i] = rand();
+ return bytes;
}
//Creates a valid common CPER error section, given the start of the error section.
//Clears reserved bits.
-void create_valid_error_section(UINT8* start)
+void create_valid_error_section(UINT8 *start)
{
- //Fix reserved bits.
- UINT64* error_section = (UINT64*)start;
- *error_section &= ~0xFF; //Reserved bits 0-7.
- *error_section &= 0x7FFFFF; //Reserved bits 23-63
+ //Fix reserved bits.
+ UINT64 *error_section = (UINT64 *)start;
+ *error_section &= ~0xFF; //Reserved bits 0-7.
+ *error_section &= 0x7FFFFF; //Reserved bits 23-63
- //Ensure error type has a valid value.
- *(start + 1) = CPER_ERROR_TYPES_KEYS[rand() % (sizeof(CPER_ERROR_TYPES_KEYS) / sizeof(int))];
+ //Ensure error type has a valid value.
+ *(start + 1) =
+ CPER_ERROR_TYPES_KEYS[rand() % (sizeof(CPER_ERROR_TYPES_KEYS) /
+ sizeof(int))];
}
//Initializes the random seed for rand() using the current time.
void init_random()
{
- srand((unsigned int)time(NULL));
+ srand((unsigned int)time(NULL));
}
\ No newline at end of file