Angel Pons has uploaded this change for review.

View Change

util/sconfig: Refactor handling of SMBIOS data

Extract the code that handles devices' SMBIOS data into a helper
function, and add another helper function to check if any SMBIOS
information is present.

Change-Id: I4f36d6c6f26e79558d360d319d09b0b8426def0e
Signed-off-by: Angel Pons <th3fanbus@gmail.com>
---
M util/sconfig/main.c
1 file changed, 37 insertions(+), 23 deletions(-)

git pull ssh://review.coreboot.org:29418/coreboot refs/changes/69/57369/1
diff --git a/util/sconfig/main.c b/util/sconfig/main.c
index f7d1d10..a9634dd 100644
--- a/util/sconfig/main.c
+++ b/util/sconfig/main.c
@@ -1108,6 +1108,40 @@
ptr->name);
}

+static int have_smbios_data(struct device *ptr)
+{
+ return (ptr->smbios_slot_type ||
+ ptr->smbios_slot_data_width ||
+ ptr->smbios_slot_designation ||
+ ptr->smbios_slot_length);
+}
+
+static void emit_smbios_data(FILE *fil, struct device *ptr)
+{
+ if (!have_smbios_data(ptr))
+ return;
+
+ fprintf(fil, "#if !DEVTREE_EARLY\n");
+ fprintf(fil, "#if CONFIG(GENERATE_SMBIOS_TABLES)\n");
+
+ /* SMBIOS types start at 1, if zero it hasn't been set */
+ if (ptr->smbios_slot_type)
+ fprintf(fil, "\t.smbios_slot_type = %s,\n",
+ ptr->smbios_slot_type);
+ if (ptr->smbios_slot_data_width)
+ fprintf(fil, "\t.smbios_slot_data_width = %s,\n",
+ ptr->smbios_slot_data_width);
+ if (ptr->smbios_slot_designation)
+ fprintf(fil, "\t.smbios_slot_designation = \"%s\",\n",
+ ptr->smbios_slot_designation);
+ if (ptr->smbios_slot_length)
+ fprintf(fil, "\t.smbios_slot_length = %s,\n",
+ ptr->smbios_slot_length);
+
+ fprintf(fil, "#endif\n");
+ fprintf(fil, "#endif\n");
+}
+
static void emit_resources(FILE *fil, struct device *ptr)
{
if (ptr->res == NULL)
@@ -1266,29 +1300,9 @@
chip_ins->chip->name_underscore, chip_ins->id);
if (next)
fprintf(fil, "\t.next=&%s,\n", next->name);
- if (ptr->smbios_slot_type || ptr->smbios_slot_data_width ||
- ptr->smbios_slot_designation || ptr->smbios_slot_length) {
- fprintf(fil, "#if !DEVTREE_EARLY\n");
- fprintf(fil, "#if CONFIG(GENERATE_SMBIOS_TABLES)\n");
- }
- /* SMBIOS types start at 1, if zero it hasn't been set */
- if (ptr->smbios_slot_type)
- fprintf(fil, "\t.smbios_slot_type = %s,\n",
- ptr->smbios_slot_type);
- if (ptr->smbios_slot_data_width)
- fprintf(fil, "\t.smbios_slot_data_width = %s,\n",
- ptr->smbios_slot_data_width);
- if (ptr->smbios_slot_designation)
- fprintf(fil, "\t.smbios_slot_designation = \"%s\",\n",
- ptr->smbios_slot_designation);
- if (ptr->smbios_slot_length)
- fprintf(fil, "\t.smbios_slot_length = %s,\n",
- ptr->smbios_slot_length);
- if (ptr->smbios_slot_type || ptr->smbios_slot_data_width ||
- ptr->smbios_slot_designation || ptr->smbios_slot_length) {
- fprintf(fil, "#endif\n");
- fprintf(fil, "#endif\n");
- }
+
+ emit_smbios_data(fil, ptr);
+
fprintf(fil, "};\n");

emit_resources(fil, ptr);

To view, visit change 57369. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-Project: coreboot
Gerrit-Branch: master
Gerrit-Change-Id: I4f36d6c6f26e79558d360d319d09b0b8426def0e
Gerrit-Change-Number: 57369
Gerrit-PatchSet: 1
Gerrit-Owner: Angel Pons <th3fanbus@gmail.com>
Gerrit-MessageType: newchange