Kyösti Mälkki submitted this change.

View Change

Approvals: build bot (Jenkins): Verified Kyösti Mälkki: Looks good to me, approved Aaron Durbin: Looks good to me, approved
util/sconfig: Issue header for exposed PCI and PNP names

Let `sconfig` output a C header file with the symbol names that we
generate since 5e2a2cd5e7 (util/sconfig: Expose usable PCI and PNP
device names).

We add another command line argument for the path to the header
file. As the file is similar in nature to our `config.h` we simply
put it in $(obj)/ too.

Change-Id: I8f87288c82f2844b61eba6534797a42b978b47bb
Signed-off-by: Nico Huber <nico.huber@secunet.com>
Reviewed-on: https://review.coreboot.org/c/coreboot/+/35488
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Kyösti Mälkki <kyosti.malkki@gmail.com>
Reviewed-by: Aaron Durbin <adurbin@chromium.org>
---
M Makefile.inc
M util/sconfig/main.c
2 files changed, 38 insertions(+), 16 deletions(-)

diff --git a/Makefile.inc b/Makefile.inc
index 8676404..d13a795 100644
--- a/Makefile.inc
+++ b/Makefile.inc
@@ -591,11 +591,12 @@
endif

DEVICETREE_STATIC_C := $(obj)/mainboard/$(MAINBOARDDIR)/static.c
+DEVICETREE_STATIC_H := $(obj)/static.h

$(DEVICETREE_STATIC_C): $(DEVICETREE_FILE) $(OVERRIDE_DEVICETREE_FILE) $(objutil)/sconfig/sconfig
@printf " SCONFIG $(subst $(src)/,,$(<))\n"
mkdir -p $(dir $(DEVICETREE_STATIC_C))
- $(objutil)/sconfig/sconfig $(DEVICETREE_FILE) $(DEVICETREE_STATIC_C) $(OVERRIDE_DEVICETREE_FILE)
+ $(objutil)/sconfig/sconfig $(DEVICETREE_FILE) $(DEVICETREE_STATIC_C) $(DEVICETREE_STATIC_H) $(OVERRIDE_DEVICETREE_FILE)

ramstage-y+=$(DEVICETREE_STATIC_C)
romstage-y+=$(DEVICETREE_STATIC_C)
diff --git a/util/sconfig/main.c b/util/sconfig/main.c
index 6b421ec..5c23333 100644
--- a/util/sconfig/main.c
+++ b/util/sconfig/main.c
@@ -696,7 +696,7 @@
return 0;
}

-static void pass0(FILE *fil, struct device *ptr, struct device *next)
+static void pass0(FILE *fil, FILE *head, struct device *ptr, struct device *next)
{
if (ptr == &base_root_dev) {
fprintf(fil, "STORAGE struct bus %s_links[];\n",
@@ -781,7 +781,7 @@
fprintf(fil, "\t};\n");
}

-static void pass1(FILE *fil, struct device *ptr, struct device *next)
+static void pass1(FILE *fil, FILE *head, struct device *ptr, struct device *next)
{
int pin;
struct chip_instance *chip_ins = ptr->chip_instance;
@@ -883,16 +883,22 @@
emit_dev_links(fil, ptr);
}

-static void expose_device_names(FILE *fil, struct device *ptr, struct device *next)
+static void expose_device_names(FILE *fil, FILE *head, struct device *ptr, struct device *next)
{
/* Only devices on root bus here. */
- if (ptr->bustype == PCI && ptr->parent->dev->bustype == DOMAIN)
+ if (ptr->bustype == PCI && ptr->parent->dev->bustype == DOMAIN) {
+ fprintf(head, "extern DEVTREE_CONST struct device *DEVTREE_CONST __pci_0_%02x_%d;\n",
+ ptr->path_a, ptr->path_b);
fprintf(fil, "DEVTREE_CONST struct device *DEVTREE_CONST __pci_0_%02x_%d = &%s;\n",
ptr->path_a, ptr->path_b, ptr->name);
+ }

- if (ptr->bustype == PNP)
+ if (ptr->bustype == PNP) {
+ fprintf(head, "extern DEVTREE_CONST struct device *DEVTREE_CONST __pnp_%04x_%02x;\n",
+ ptr->path_a, ptr->path_b);
fprintf(fil, "DEVTREE_CONST struct device *DEVTREE_CONST __pnp_%04x_%02x = &%s;\n",
ptr->path_a, ptr->path_b, ptr->name);
+ }
}

static void add_siblings_to_queue(struct queue_entry **bfs_q_head,
@@ -916,8 +922,8 @@
}
}

-static void walk_device_tree(FILE *fil, struct device *ptr,
- void (*func)(FILE *, struct device *,
+static void walk_device_tree(FILE *fil, FILE *head, struct device *ptr,
+ void (*func)(FILE *, FILE *, struct device *,
struct device *))
{
struct queue_entry *bfs_q_head = NULL;
@@ -926,7 +932,7 @@

while ((ptr = dequeue_head(&bfs_q_head))) {
add_children_to_queue(&bfs_q_head, ptr);
- func(fil, ptr, peek_queue_head(bfs_q_head));
+ func(fil, head, ptr, peek_queue_head(bfs_q_head));
}
}

@@ -995,7 +1001,7 @@
}
}

-static void inherit_subsystem_ids(FILE *file, struct device *dev,
+static void inherit_subsystem_ids(FILE *file, FILE *head, struct device *dev,
struct device *next)
{
struct device *p;
@@ -1020,17 +1026,18 @@

static void usage(void)
{
- printf("usage: sconfig devicetree_file output_file [override_devicetree_file]\n");
+ printf("usage: sconfig devicetree_file output_file header_file [override_devicetree_file]\n");
exit(1);
}

enum {
DEVICEFILE_ARG = 1,
OUTPUTFILE_ARG,
+ HEADERFILE_ARG,
OVERRIDE_DEVICEFILE_ARG,
};

-#define MANDATORY_ARG_COUNT 3
+#define MANDATORY_ARG_COUNT 4
#define OPTIONAL_ARG_COUNT 1
#define TOTAL_ARG_COUNT (MANDATORY_ARG_COUNT + OPTIONAL_ARG_COUNT)

@@ -1365,6 +1372,7 @@

const char *base_devtree = argv[DEVICEFILE_ARG];
const char *outputc = argv[OUTPUTFILE_ARG];
+ const char *outputh = argv[HEADERFILE_ARG];
const char *override_devtree;

parse_devicetree(base_devtree, &base_root_bus);
@@ -1389,18 +1397,31 @@
exit(1);
}

+ FILE *autohead = fopen(outputh, "w");
+ if (!autohead) {
+ fprintf(stderr, "Could not open file '%s' for writing: ", outputh);
+ perror(NULL);
+ fclose(autogen);
+ exit(1);
+ }
+ fprintf(autohead, "#ifndef __STATIC_DEVICE_TREE_H\n");
+ fprintf(autohead, "#define __STATIC_DEVICE_TREE_H\n\n");
+ fprintf(autohead, "#include <device/device.h>\n\n");
+
emit_chips(autogen);

- walk_device_tree(autogen, &base_root_dev, inherit_subsystem_ids);
+ walk_device_tree(autogen, autohead, &base_root_dev, inherit_subsystem_ids);
fprintf(autogen, "\n/* pass 0 */\n");
- walk_device_tree(autogen, &base_root_dev, pass0);
+ walk_device_tree(autogen, autohead, &base_root_dev, pass0);
fprintf(autogen, "\n/* pass 1 */\n");
- walk_device_tree(autogen, &base_root_dev, pass1);
+ walk_device_tree(autogen, autohead, &base_root_dev, pass1);

/* Expose static devicenames to global namespace. */
fprintf(autogen, "\n/* expose_device_names */\n");
- walk_device_tree(autogen, &base_root_dev, expose_device_names);
+ walk_device_tree(autogen, autohead, &base_root_dev, expose_device_names);

+ fprintf(autohead, "\n#endif /* __STATIC_DEVICE_TREE_H */\n");
+ fclose(autohead);
fclose(autogen);

return 0;

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

Gerrit-Project: coreboot
Gerrit-Branch: master
Gerrit-Change-Id: I8f87288c82f2844b61eba6534797a42b978b47bb
Gerrit-Change-Number: 35488
Gerrit-PatchSet: 2
Gerrit-Owner: Nico Huber <nico.h@gmx.de>
Gerrit-Reviewer: Aaron Durbin <adurbin@chromium.org>
Gerrit-Reviewer: Kyösti Mälkki <kyosti.malkki@gmail.com>
Gerrit-Reviewer: Martin Roth <martinroth@google.com>
Gerrit-Reviewer: Nico Huber <nico.h@gmx.de>
Gerrit-Reviewer: Patrick Georgi <pgeorgi@google.com>
Gerrit-Reviewer: build bot (Jenkins) <no-reply@coreboot.org>
Gerrit-CC: Paul Menzel <paulepanter@users.sourceforge.net>
Gerrit-MessageType: merged