diff options
author | Furquan Shaikh <furquan@google.com> | 2018-05-30 23:46:16 -0700 |
---|---|---|
committer | Furquan Shaikh <furquan@google.com> | 2018-06-05 20:57:26 +0000 |
commit | a0cc5a697ce13dece6833dca41913fe5c467d3d3 (patch) | |
tree | 32baa1e1ce9b76470ecf3ae94c91111c5750274f /util/sconfig/main.c | |
parent | 79e8412665567cfd2a18e144794f5b3d924b0cbc (diff) | |
download | coreboot-a0cc5a697ce13dece6833dca41913fe5c467d3d3.tar.xz |
util/sconfig: Re-factor emitting of headers to static.c
This change removes call to add_header from parsing functions and
moves it to a local function within main.c. It also adds a new
function emit_headers that is responsible for creating the linked list
for chip headers and emitting those to static.c
BUG=b:80081934
TEST=Verified that static.c for all files compiled using abuild is the
same with and without this change.
Change-Id: I24d526e81323115d3cc927242a4b9e49414afbe0
Signed-off-by: Furquan Shaikh <furquan@google.com>
Reviewed-on: https://review.coreboot.org/26726
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Aaron Durbin <adurbin@chromium.org>
Diffstat (limited to 'util/sconfig/main.c')
-rw-r--r-- | util/sconfig/main.c | 110 |
1 files changed, 59 insertions, 51 deletions
diff --git a/util/sconfig/main.c b/util/sconfig/main.c index 382d5e5c7b..7cdde1c28e 100644 --- a/util/sconfig/main.c +++ b/util/sconfig/main.c @@ -22,8 +22,6 @@ extern int linenum; struct device *head, *lastdev; -struct header headers; - static struct chip *chip_head; /* @@ -244,30 +242,6 @@ struct chip *new_chip(char *path) return new_chip; } -void add_header(struct chip *chip) -{ - int include_exists = 0; - struct header *h = &headers; - while (h->next) { - int result = strcmp(chip->name, h->next->name); - if (result == 0) { - include_exists = 1; - break; - } - if (result < 0) - break; - h = h->next; - } - if (!include_exists) { - struct header *tmp = h->next; - h->next = malloc(sizeof(struct header)); - memset(h->next, 0, sizeof(struct header)); - h->next->chiph_exists = chip->chiph_exists; - h->next->name = chip->name; - h->next->next = tmp; - } -} - struct device *new_device(struct device *parent, struct device *busdev, struct chip *chip, const int bus, const char *devnum, int enabled) @@ -622,10 +596,69 @@ static void walk_device_tree(FILE *fil, struct device *ptr, } while (ptr); } +static void add_header(struct chip *chip, struct header *h) +{ + int include_exists = 0; + + while (h->next) { + int result = strcmp(chip->name, h->next->name); + if (result == 0) { + include_exists = 1; + break; + } + if (result < 0) + break; + h = h->next; + } + + if (!include_exists) { + struct header *tmp = h->next; + h->next = malloc(sizeof(struct header)); + memset(h->next, 0, sizeof(struct header)); + h->next->chiph_exists = chip->chiph_exists; + h->next->name = chip->name; + h->next->next = tmp; + } +} + +static void emit_headers(FILE *fil) +{ + struct header *h; + struct chip *chip; + struct header headers = {}; + + for (chip = chip_head; chip; chip = chip->next) + add_header(chip, &headers); + + fprintf(fil, "#include <device/device.h>\n"); + fprintf(fil, "#include <device/pci.h>\n"); + h = &headers; + while (h->next) { + h = h->next; + if (h->chiph_exists) + fprintf(fil, "#include \"%s/chip.h\"\n", h->name); + } + fprintf(fil, "\n#if !DEVTREE_EARLY\n"); + fprintf(fil, + "__attribute__((weak)) struct chip_operations mainboard_ops = {};\n"); + h = &headers; + while (h->next) { + h = h->next; + char *name_underscore = translate_name(h->name, UNSLASH); + fprintf(fil, + "__attribute__((weak)) struct chip_operations %s_ops = {};\n", + name_underscore); + free(name_underscore); + } + fprintf(fil, "#endif\n"); +} + static void emit_chips(FILE *fil) { struct chip *chip; + emit_headers(fil); + for (chip = chip_head; chip; chip = chip->next) { if (!chip->chiph_exists) continue; @@ -693,8 +726,6 @@ int main(int argc, char **argv) char *devtree = argv[DEVICEFILE_ARG]; char *outputc = argv[OUTPUTFILE_ARG]; - headers.next = 0; - FILE *filec = fopen(devtree, "r"); if (!filec) { perror(NULL); @@ -717,29 +748,6 @@ int main(int argc, char **argv) exit(1); } - struct header *h; - fprintf(autogen, "#include <device/device.h>\n"); - fprintf(autogen, "#include <device/pci.h>\n"); - h = &headers; - while (h->next) { - h = h->next; - if (h->chiph_exists) - fprintf(autogen, "#include \"%s/chip.h\"\n", h->name); - } - fprintf(autogen, "\n#if !DEVTREE_EARLY\n"); - fprintf(autogen, - "__attribute__((weak)) struct chip_operations mainboard_ops = {};\n"); - h = &headers; - while (h->next) { - h = h->next; - char *name_underscore = translate_name(h->name, UNSLASH); - fprintf(autogen, - "__attribute__((weak)) struct chip_operations %s_ops = {};\n", - name_underscore); - free(name_underscore); - } - fprintf(autogen, "#endif\n"); - emit_chips(autogen); walk_device_tree(autogen, &root, inherit_subsystem_ids, NULL); |