Tim Wawrzynczak has uploaded this change for review. ( https://review.coreboot.org/c/coreboot/+/45667 )
Change subject: sconfig: Move exported device names to separate output file ......................................................................
sconfig: Move exported device names to separate output file
Both the FW_CONFIG_FIELD_* macros and exported devicetree device names were placed in static.h. Some payloads may decide they would like to consume FW_CONFIG as well, however the current status of static.h makes this impossible. To alleviate this, the exported device names are moved to a separate output file named static_devices.h. This leaves static.h with only the FW_CONFIG_FIELD* macros, making it easily consumable by payloads.
Change-Id: Ie0f4520ee055528c7be84d1d1e2dcea113ea8b5f Signed-off-by: Tim Wawrzynczak twawrzynczak@chromium.org --- M Makefile.inc M util/sconfig/main.c 2 files changed, 30 insertions(+), 9 deletions(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/67/45667/1
diff --git a/Makefile.inc b/Makefile.inc index ccc614c..b9758f0 100644 --- a/Makefile.inc +++ b/Makefile.inc @@ -619,6 +619,9 @@ mkdir -p $(dir $(DEVICETREE_STATIC_C)) $(objutil)/sconfig/sconfig $(SCONFIG_OPTIONS)
+DEVICETREE_DEVICENAMES_H := $(obj)/static_devices.h +SCONFIG_OPTIONS += --output_d=$(DEVICETREE_DEVICENAMES_H) + ramstage-y+=$(DEVICETREE_STATIC_C) romstage-y+=$(DEVICETREE_STATIC_C) verstage-y+=$(DEVICETREE_STATIC_C) diff --git a/util/sconfig/main.c b/util/sconfig/main.c index 842c8af..a35013c 100644 --- a/util/sconfig/main.c +++ b/util/sconfig/main.c @@ -528,9 +528,6 @@ if (!field) return;
- fprintf(fil, "\n/* firmware configuration */\n"); - fprintf(fil, "#include <fw_config.h>\n"); - while (field) { struct fw_config_option *option = field->options; uint32_t mask; @@ -1719,6 +1716,7 @@ { "chipset_devtree", 1, NULL, 'p' }, { "output_c", 1, NULL, 'c' }, { "output_h", 1, NULL, 'r' }, + { "output_d", 1, NULL, 'd' }, { "help", 1, NULL, 'h' }, { } }; @@ -1727,9 +1725,10 @@ const char *chipset_devtree = NULL; const char *outputc = NULL; const char *outputh = NULL; + const char *outputd = NULL; int opt, option_index;
- while ((opt = getopt_long(argc, argv, "m:o:p:c:r:h", long_options, + while ((opt = getopt_long(argc, argv, "m:o:p:c:r:d:h", long_options, &option_index)) != EOF) { switch (opt) { case 'm': @@ -1747,13 +1746,16 @@ case 'r': outputh = strdup(optarg); break; + case 'd': + outputd = strdup(optarg); + break; case 'h': default: usage(); } }
- if (!base_devtree || !outputc || !outputh) + if (!base_devtree || !outputc || !outputh || !outputd) usage();
if (chipset_devtree) { @@ -1783,14 +1785,25 @@ fclose(autogen); exit(1); } + + FILE *autodev = fopen(outputd, "w"); + if (!autodev) { + fprintf(stderr, "Could not open file '%s' for writing: ", outputd); + perror(NULL); + fclose(autogen); + fclose(autohead); + 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_fw_config(autohead);
fprintf(autogen, "#include <device/device.h>\n"); - fprintf(autogen, "#include <device/pci.h>\n\n"); + fprintf(autogen, "#include <device/pci.h>\n"); + fprintf(autogen, "#include <fw_config.h>\n"); fprintf(autogen, "#include <static.h>\n"); + fprintf(autogen, "#include <static_devices.h>\n\n"); emit_chip_headers(autogen, chip_header.next); fprintf(autogen, "\n#define STORAGE static __unused DEVTREE_CONST\n\n");
@@ -1804,12 +1817,17 @@ 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, autohead, &base_root_dev, expose_device_names); + fprintf(autodev, "#ifndef __STATIC_DEVICES_H\n"); + fprintf(autodev, "#define __STATIC_DEVICES_H\n\n"); + fprintf(autodev, "#include <device/device.h>\n\n"); + fprintf(autodev, "/* expose_device_names */\n"); + walk_device_tree(autogen, autodev, &base_root_dev, expose_device_names);
fprintf(autohead, "\n#endif /* __STATIC_DEVICE_TREE_H */\n"); + fprintf(autodev, "\n#endif /* __STATIC_DEVICE_NAMES_H */\n"); fclose(autohead); fclose(autogen); + fclose(autodev);
return 0; }
build bot (Jenkins) has posted comments on this change. ( https://review.coreboot.org/c/coreboot/+/45667 )
Change subject: sconfig: Move exported device names to separate output file ......................................................................
Patch Set 1:
(1 comment)
https://review.coreboot.org/c/coreboot/+/45667/1/util/sconfig/main.c File util/sconfig/main.c:
https://review.coreboot.org/c/coreboot/+/45667/1/util/sconfig/main.c@1789 PS1, Line 1789: FILE *autodev = fopen(outputd, "w"); need consistent spacing around '*' (ctx:WxV)
Furquan Shaikh has posted comments on this change. ( https://review.coreboot.org/c/coreboot/+/45667 )
Change subject: sconfig: Move exported device names to separate output file ......................................................................
Patch Set 1:
(4 comments)
https://review.coreboot.org/c/coreboot/+/45667/1//COMMIT_MSG Commit Message:
https://review.coreboot.org/c/coreboot/+/45667/1//COMMIT_MSG@14 PS1, Line 14: with only the FW_CONFIG_FIELD* macros, making it easily consumable by : payloads. Shouldn't we also add FW_CONFIG_FIELD* macros to something like static_fw_config.h instead of including them directly in static.h: 1. Having the file name include context would be helpful even for payloads when including this file in their codebase. 2. If more things get added to static.h in the future, this helps with clean organization. Basically, static.h will only include other header files -- each created for a specific purpose.
https://review.coreboot.org/c/coreboot/+/45667/1/Makefile.inc File Makefile.inc:
https://review.coreboot.org/c/coreboot/+/45667/1/Makefile.inc@622 PS1, Line 622: DEVICETREE_DEVICENAMES_H := $(obj)/static_devices.h : SCONFIG_OPTIONS += --output_d=$(DEVICETREE_DEVICENAMES_H) Place this with DEVICETREE_STATIC_H above?
https://review.coreboot.org/c/coreboot/+/45667/1/util/sconfig/main.c File util/sconfig/main.c:
https://review.coreboot.org/c/coreboot/+/45667/1/util/sconfig/main.c@1806 PS1, Line 1806: static_devices.h Not a big problem, but we take in the file name as input which gets used to get a pointer to the file descriptor and write to file, but when generating #include, we just hardcode the file name here. I know this is similar to what we did for static.h as well. But if we were to ever change the filename for any reason, we would have to update sconfig as well.
https://review.coreboot.org/c/coreboot/+/45667/1/util/sconfig/main.c@1826 PS1, Line 1826: fprintf(autohead, "\n#endif /* __STATIC_DEVICE_TREE_H */\n"); : fprintf(autodev, "\n#endif /* __STATIC_DEVICE_NAMES_H */\n"); Time to create helper functions to create each header file?
Tim Wawrzynczak has posted comments on this change. ( https://review.coreboot.org/c/coreboot/+/45667 )
Change subject: sconfig: Move exported device names to separate output file ......................................................................
Patch Set 1:
(4 comments)
https://review.coreboot.org/c/coreboot/+/45667/1//COMMIT_MSG Commit Message:
https://review.coreboot.org/c/coreboot/+/45667/1//COMMIT_MSG@14 PS1, Line 14: with only the FW_CONFIG_FIELD* macros, making it easily consumable by : payloads.
Shouldn't we also add FW_CONFIG_FIELD* macros to something like static_fw_config. […]
I like that, will try it.
https://review.coreboot.org/c/coreboot/+/45667/1/Makefile.inc File Makefile.inc:
https://review.coreboot.org/c/coreboot/+/45667/1/Makefile.inc@622 PS1, Line 622: DEVICETREE_DEVICENAMES_H := $(obj)/static_devices.h : SCONFIG_OPTIONS += --output_d=$(DEVICETREE_DEVICENAMES_H)
Place this with DEVICETREE_STATIC_H above?
Ack
https://review.coreboot.org/c/coreboot/+/45667/1/util/sconfig/main.c File util/sconfig/main.c:
https://review.coreboot.org/c/coreboot/+/45667/1/util/sconfig/main.c@1806 PS1, Line 1806: static_devices.h
Not a big problem, but we take in the file name as input which gets used to get a pointer to the fil […]
Good eye, I will change them to use the passed-in values
https://review.coreboot.org/c/coreboot/+/45667/1/util/sconfig/main.c@1826 PS1, Line 1826: fprintf(autohead, "\n#endif /* __STATIC_DEVICE_TREE_H */\n"); : fprintf(autodev, "\n#endif /* __STATIC_DEVICE_NAMES_H */\n");
Time to create helper functions to create each header file?
Good call, I was getting myself tripped up editing these...
Hello build bot (Jenkins), Nico Huber, Patrick Georgi, Martin Roth, Duncan Laurie, Julius Werner, Angel Pons, Aaron Durbin,
I'd like you to reexamine a change. Please visit
https://review.coreboot.org/c/coreboot/+/45667
to look at the new patch set (#2).
Change subject: sconfig: Split up sconfig-generated static.h ......................................................................
sconfig: Split up sconfig-generated static.h
Currently sconfig generates a `static.h` to accompany `static.c`. However, some payloads may decide they would like to consume the FW_CONFIG macros as well. The current state of `static.h` makes this impossible (relying on `device/device.h`).
This patch splits up `static.h` into 3 files: `static.h, `static_devices.h`, and `static_fw_config.h`. `static.h` simply includes the other two `.h` files to ensure no changes are needed to other code. `static_devices.h` contains the extern'd definitions of the device names recently introduced to sconfig. `static_fw_config.h` contains the FW_CONFIG_FIELD_* macros only, which makes it easily consumable by a payload which wishes to use FW_CONFIG.
Also refactor the generation of all these output files, as the code was getting messy.
Change-Id: Ie0f4520ee055528c7be84d1d1e2dcea113ea8b5f Signed-off-by: Tim Wawrzynczak twawrzynczak@chromium.org --- M Makefile.inc M util/sconfig/main.c 2 files changed, 109 insertions(+), 27 deletions(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/67/45667/2
Angel Pons has posted comments on this change. ( https://review.coreboot.org/c/coreboot/+/45667 )
Change subject: sconfig: Split up sconfig-generated static.h ......................................................................
Patch Set 2: Code-Review+1
Duncan Laurie has posted comments on this change. ( https://review.coreboot.org/c/coreboot/+/45667 )
Change subject: sconfig: Split up sconfig-generated static.h ......................................................................
Patch Set 2: Code-Review+2
(1 comment)
https://review.coreboot.org/c/coreboot/+/45667/2/util/sconfig/main.c File util/sconfig/main.c:
https://review.coreboot.org/c/coreboot/+/45667/2/util/sconfig/main.c@1349 PS2, Line 1349: required In theory this could be optional if no fw_config section is defined in the devicetree by checking if fw_config_fields is null, but I don't know that it is worthwhile given sconfig is just called by the make system and can easily supply a file even if it isn't used.
Furquan Shaikh has posted comments on this change. ( https://review.coreboot.org/c/coreboot/+/45667 )
Change subject: sconfig: Split up sconfig-generated static.h ......................................................................
Patch Set 2: Code-Review+2
(1 comment)
https://review.coreboot.org/c/coreboot/+/45667/2/util/sconfig/main.c File util/sconfig/main.c:
https://review.coreboot.org/c/coreboot/+/45667/2/util/sconfig/main.c@1089 PS2, Line 1089: exit(1); Not for this change, but I think this is generally bad. We have more files that are opened and might not be closed if sconfig exits here.
Tim Wawrzynczak has posted comments on this change. ( https://review.coreboot.org/c/coreboot/+/45667 )
Change subject: sconfig: Split up sconfig-generated static.h ......................................................................
Patch Set 2:
(1 comment)
https://review.coreboot.org/c/coreboot/+/45667/2/util/sconfig/main.c File util/sconfig/main.c:
https://review.coreboot.org/c/coreboot/+/45667/2/util/sconfig/main.c@1089 PS2, Line 1089: exit(1);
Not for this change, but I think this is generally bad. […]
I know, that's something I want to go back and clean up later.
Hello build bot (Jenkins), Nico Huber, Furquan Shaikh, Patrick Georgi, Martin Roth, Duncan Laurie, Angel Pons, Julius Werner, Rob Barnes, Aaron Durbin, Karthikeyan Ramasubramanian,
I'd like you to reexamine a change. Please visit
https://review.coreboot.org/c/coreboot/+/45667
to look at the new patch set (#3).
Change subject: sconfig: Split up sconfig-generated static.h ......................................................................
sconfig: Split up sconfig-generated static.h
Currently sconfig generates a `static.h` to accompany `static.c`. However, some payloads may decide they would like to consume the FW_CONFIG macros as well. The current state of `static.h` makes this impossible (relying on `device/device.h`).
This patch splits up `static.h` into 3 files: `static.h, `static_devices.h`, and `static_fw_config.h`. `static.h` simply includes the other two `.h` files to ensure no changes are needed to other code. `static_devices.h` contains the extern'd definitions of the device names recently introduced to sconfig. `static_fw_config.h` contains the FW_CONFIG_FIELD_* macros only, which makes it easily consumable by a payload which wishes to use FW_CONFIG.
Also refactor the generation of all these output files, as the code was getting messy.
Change-Id: Ie0f4520ee055528c7be84d1d1e2dcea113ea8b5f Signed-off-by: Tim Wawrzynczak twawrzynczak@chromium.org --- M Makefile.inc M util/sconfig/main.c 2 files changed, 110 insertions(+), 27 deletions(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/67/45667/3
build bot (Jenkins) has posted comments on this change. ( https://review.coreboot.org/c/coreboot/+/45667 )
Change subject: sconfig: Split up sconfig-generated static.h ......................................................................
Patch Set 3:
(2 comments)
https://review.coreboot.org/c/coreboot/+/45667/3/util/sconfig/main.c File util/sconfig/main.c:
https://review.coreboot.org/c/coreboot/+/45667/3/util/sconfig/main.c@1348 PS3, Line 1348: printf(" -d | --output_d : Path to header static_devices.h file (required)\n"); line over 96 characters
https://review.coreboot.org/c/coreboot/+/45667/3/util/sconfig/main.c@1349 PS3, Line 1349: printf(" -f | --output_f : Path to header static_fw_config.h file (required)\n"); line over 96 characters
build bot (Jenkins) has posted comments on this change. ( https://review.coreboot.org/c/coreboot/+/45667 )
Change subject: sconfig: Split up sconfig-generated static.h ......................................................................
Patch Set 4:
(2 comments)
https://review.coreboot.org/c/coreboot/+/45667/4/util/sconfig/main.c File util/sconfig/main.c:
https://review.coreboot.org/c/coreboot/+/45667/4/util/sconfig/main.c@1358 PS4, Line 1358: printf(" -d | --output_d : Path to header static_devices.h file (required)\n"); line over 96 characters
https://review.coreboot.org/c/coreboot/+/45667/4/util/sconfig/main.c@1359 PS4, Line 1359: printf(" -f | --output_f : Path to header static_fw_config.h file (required)\n"); line over 96 characters
build bot (Jenkins) has posted comments on this change. ( https://review.coreboot.org/c/coreboot/+/45667 )
Change subject: sconfig: Split up sconfig-generated static.h ......................................................................
Patch Set 5:
(2 comments)
https://review.coreboot.org/c/coreboot/+/45667/5/util/sconfig/main.c File util/sconfig/main.c:
https://review.coreboot.org/c/coreboot/+/45667/5/util/sconfig/main.c@1358 PS5, Line 1358: printf(" -d | --output_d : Path to header static_devices.h file (required)\n"); line over 96 characters
https://review.coreboot.org/c/coreboot/+/45667/5/util/sconfig/main.c@1359 PS5, Line 1359: printf(" -f | --output_f : Path to header static_fw_config.h file (required)\n"); line over 96 characters
Furquan Shaikh has posted comments on this change. ( https://review.coreboot.org/c/coreboot/+/45667 )
Change subject: sconfig: Split up sconfig-generated static.h ......................................................................
Patch Set 5: Code-Review+2
Nick Vaccaro has posted comments on this change. ( https://review.coreboot.org/c/coreboot/+/45667 )
Change subject: sconfig: Split up sconfig-generated static.h ......................................................................
Patch Set 5: Code-Review+2
Patrick Georgi has submitted this change. ( https://review.coreboot.org/c/coreboot/+/45667 )
Change subject: sconfig: Split up sconfig-generated static.h ......................................................................
sconfig: Split up sconfig-generated static.h
Currently sconfig generates a `static.h` to accompany `static.c`. However, some payloads may decide they would like to consume the FW_CONFIG macros as well. The current state of `static.h` makes this impossible (relying on `device/device.h`).
This patch splits up `static.h` into 3 files: `static.h, `static_devices.h`, and `static_fw_config.h`. `static.h` simply includes the other two `.h` files to ensure no changes are needed to other code. `static_devices.h` contains the extern'd definitions of the device names recently introduced to sconfig. `static_fw_config.h` contains the FW_CONFIG_FIELD_* macros only, which makes it easily consumable by a payload which wishes to use FW_CONFIG.
Also refactor the generation of all these output files, as the code was getting messy.
Change-Id: Ie0f4520ee055528c7be84d1d1e2dcea113ea8b5f Signed-off-by: Tim Wawrzynczak twawrzynczak@chromium.org Reviewed-on: https://review.coreboot.org/c/coreboot/+/45667 Tested-by: build bot (Jenkins) no-reply@coreboot.org Reviewed-by: Furquan Shaikh furquan@google.com Reviewed-by: Nick Vaccaro nvaccaro@google.com --- M Makefile.inc M util/sconfig/main.c 2 files changed, 110 insertions(+), 27 deletions(-)
Approvals: build bot (Jenkins): Verified Furquan Shaikh: Looks good to me, approved Nick Vaccaro: Looks good to me, approved
diff --git a/Makefile.inc b/Makefile.inc index 297f7b1..a6418b1 100644 --- a/Makefile.inc +++ b/Makefile.inc @@ -611,6 +611,12 @@ DEVICETREE_STATIC_H := $(obj)/static.h SCONFIG_OPTIONS += --output_h=$(DEVICETREE_STATIC_H)
+DEVICETREE_DEVICENAMES_H := $(obj)/static_devices.h +SCONFIG_OPTIONS += --output_d=$(DEVICETREE_DEVICENAMES_H) + +DEVICETREE_FWCONFIG_H := $(obj)/static_fw_config.h +SCONFIG_OPTIONS += --output_f=$(DEVICETREE_FWCONFIG_H) + $(DEVICETREE_STATIC_C): $(DEVICETREE_FILE) $(OVERRIDE_DEVICETREE_FILE) $(CHIPSET_DEVICETREE_FILE) $(objutil)/sconfig/sconfig @printf " SCONFIG $(subst $(src)/,,$(<))\n" mkdir -p $(dir $(DEVICETREE_STATIC_C)) diff --git a/util/sconfig/main.c b/util/sconfig/main.c index bff7215..4f13293 100644 --- a/util/sconfig/main.c +++ b/util/sconfig/main.c @@ -1,9 +1,11 @@ /* sconfig, coreboot device tree compiler */ /* SPDX-License-Identifier: GPL-2.0-only */
+#include <assert.h> #include <ctype.h> #include <getopt.h> /* stat.h needs to be included before commonlib/helpers.h to avoid errors.*/ +#include <libgen.h> #include <sys/stat.h> #include <commonlib/helpers.h> #include <stdint.h> @@ -528,9 +530,6 @@ if (!field) return;
- fprintf(fil, "\n/* firmware configuration */\n"); - fprintf(fil, "#include <fw_config.h>\n"); - while (field) { struct fw_config_option *option = field->options; uint32_t mask; @@ -1094,7 +1093,8 @@
/* Emit probe structures. */ if (ptr->probe && (emit_fw_config_probe(fil, ptr) < 0)) { - fclose(head); + if (head) + fclose(head); fclose(fil); exit(1); } @@ -1355,9 +1355,12 @@ printf("usage: sconfig <options>\n"); printf(" -c | --output_c : Path to output static.c file (required)\n"); printf(" -r | --output_h : Path to header static.h file (required)\n"); + printf(" -d | --output_d : Path to header static_devices.h file (required)\n"); + printf(" -f | --output_f : Path to header static_fw_config.h file (required)\n"); printf(" -m | --mainboard_devtree : Path to mainboard devicetree file (required)\n"); printf(" -o | --override_devtree : Path to override devicetree file (optional)\n"); printf(" -p | --chipset_devtree : Path to chipset/SOC devicetree file (optional)\n"); + exit(1); }
@@ -1721,6 +1724,54 @@ override_devicetree(&base_root_bus, dev->bus); }
+static void generate_outputh(FILE *f, const char *fw_conf_header, const char *device_header) +{ + fprintf(f, "#ifndef __STATIC_DEVICE_TREE_H\n"); + fprintf(f, "#define __STATIC_DEVICE_TREE_H\n\n"); + + fprintf(f, "#include <%s>\n", fw_conf_header); + fprintf(f, "#include <%s>\n\n", device_header); + + fprintf(f, "\n#endif /* __STATIC_DEVICE_TREE_H */\n"); +} + +static void generate_outputc(FILE *f, const char *static_header) +{ + fprintf(f, "#include <device/device.h>\n"); + fprintf(f, "#include <device/pci.h>\n"); + fprintf(f, "#include <fw_config.h>\n"); + fprintf(f, "#include <%s>\n", static_header); + emit_chip_headers(f, chip_header.next); + fprintf(f, "\n#define STORAGE static __unused DEVTREE_CONST\n\n"); + + walk_device_tree(NULL, NULL, &base_root_dev, inherit_subsystem_ids); + fprintf(f, "\n/* pass 0 */\n"); + walk_device_tree(f, NULL, &base_root_dev, pass0); + walk_device_tree(NULL, NULL, &base_root_dev, update_references); + fprintf(f, "\n/* chip configs */\n"); + emit_chip_configs(f); + fprintf(f, "\n/* pass 1 */\n"); + walk_device_tree(f, NULL, &base_root_dev, pass1); +} + +static void generate_outputd(FILE *gen, FILE *dev) +{ + fprintf(dev, "#ifndef __STATIC_DEVICES_H\n"); + fprintf(dev, "#define __STATIC_DEVICES_H\n\n"); + fprintf(dev, "#include <device/device.h>\n\n"); + fprintf(dev, "/* expose_device_names */\n"); + walk_device_tree(gen, dev, &base_root_dev, expose_device_names); + fprintf(dev, "\n#endif /* __STATIC_DEVICE_NAMES_H */\n"); +} + +static void generate_outputf(FILE *f) +{ + fprintf(f, "#ifndef __STATIC_FW_CONFIG_H\n"); + fprintf(f, "#define __STATIC_FW_CONFIG_H\n\n"); + emit_fw_config(f); + fprintf(f, "\n#endif /* __STATIC_FW_CONFIG_H */\n"); +} + int main(int argc, char **argv) { static const struct option long_options[] = { @@ -1729,6 +1780,8 @@ { "chipset_devtree", 1, NULL, 'p' }, { "output_c", 1, NULL, 'c' }, { "output_h", 1, NULL, 'r' }, + { "output_d", 1, NULL, 'd' }, + { "output_f", 1, NULL, 'f' }, { "help", 1, NULL, 'h' }, { } }; @@ -1737,9 +1790,11 @@ const char *chipset_devtree = NULL; const char *outputc = NULL; const char *outputh = NULL; + const char *outputd = NULL; + const char *outputf = NULL; int opt, option_index;
- while ((opt = getopt_long(argc, argv, "m:o:p:c:r:h", long_options, + while ((opt = getopt_long(argc, argv, "m:o:p:c:r:d:f:h", long_options, &option_index)) != EOF) { switch (opt) { case 'm': @@ -1757,13 +1812,19 @@ case 'r': outputh = strdup(optarg); break; + case 'd': + outputd = strdup(optarg); + break; + case 'f': + outputf = strdup(optarg); + break; case 'h': default: usage(); } }
- if (!base_devtree || !outputc || !outputh) + if (!base_devtree || !outputc || !outputh || !outputd || !outputf) usage();
if (chipset_devtree) { @@ -1793,33 +1854,49 @@ 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_fw_config(autohead);
- fprintf(autogen, "#include <device/device.h>\n"); - fprintf(autogen, "#include <device/pci.h>\n\n"); - fprintf(autogen, "#include <static.h>\n"); - emit_chip_headers(autogen, chip_header.next); - fprintf(autogen, "\n#define STORAGE static __unused DEVTREE_CONST\n\n"); + FILE *autodev = fopen(outputd, "w"); + if (!autodev) { + fprintf(stderr, "Could not open file '%s' for writing: ", outputd); + perror(NULL); + fclose(autogen); + fclose(autohead); + exit(1); + }
- walk_device_tree(autogen, autohead, &base_root_dev, inherit_subsystem_ids); - fprintf(autogen, "\n/* pass 0 */\n"); - walk_device_tree(autogen, autohead, &base_root_dev, pass0); - walk_device_tree(autogen, autohead, &base_root_dev, update_references); - fprintf(autogen, "\n/* chip configs */\n"); - emit_chip_configs(autogen); - fprintf(autogen, "\n/* pass 1 */\n"); - walk_device_tree(autogen, autohead, &base_root_dev, pass1); + FILE *autofwconf = fopen(outputf, "w"); + if (!autofwconf) { + fprintf(stderr, "Could not open file '%s' for writing: ", outputf); + perror(NULL); + fclose(autogen); + fclose(autohead); + fclose(autodev); + exit(1); + }
- /* Expose static devicenames to global namespace. */ - fprintf(autogen, "\n/* expose_device_names */\n"); - walk_device_tree(autogen, autohead, &base_root_dev, expose_device_names); + char *f = strdup(outputf); + assert(f); + char *d = strdup(outputd); + assert(d); + char *h = strdup(outputh); + assert(h);
- fprintf(autohead, "\n#endif /* __STATIC_DEVICE_TREE_H */\n"); + const char *fw_conf_header = basename(f); + const char *device_header = basename(d); + const char *static_header = basename(h); + + generate_outputh(autohead, fw_conf_header, device_header); + generate_outputc(autogen, static_header); + generate_outputd(autogen, autodev); + generate_outputf(autofwconf); + fclose(autohead); fclose(autogen); + fclose(autodev); + fclose(autofwconf); + free(f); + free(d); + free(h);
return 0; }