int main(int argc, char** argv) { if (argc < 3) usage(); char *mainboard=argv[1]; char *outputdir=argv[2]; char *devtree=malloc(strlen(mainboard)+30); sprintf(devtree, "src/mainboard/%s/devicetree.cb", mainboard); char *outputc; if (argc == 3) { scan_mode = STATIC_MODE; outputc=malloc(strlen(outputdir)+20); sprintf(outputc, "%s/static.c", outputdir); } else if ((argc == 5) && (argv[3][0] == '-') && (argv[3][2] == 0)) { switch (argv[3][1]) { case 's': scan_mode = STATIC_MODE; break; case 'b': scan_mode = BOOTBLOCK_MODE; break; case 'k': scan_mode = KCONFIG_MODE; break; default: usage(); break; } char *outputfile=argv[4]; outputc=malloc(strlen(outputdir)+strlen(outputfile)+2); sprintf(outputc, "%s/%s", outputdir, outputfile); } headers.next = 0; #ifdef MAINBOARDS_HAVE_CHIP_H if (scan_mode == STATIC_MODE) { headers.next = malloc(sizeof(struct header)); headers.next->name = malloc(strlen(mainboard)+12); headers.next->next = 0; sprintf(headers.next->name, "mainboard/%s", mainboard); } #endif FILE *filec = fopen(devtree, "r"); if (!filec) { fprintf(stderr, "Could not open file '%s' for reading: ", devtree); perror(NULL); exit(1); } yyrestart(filec); lastdev = head = &root; yyparse(); fclose(filec); if ((head->type == chip) && (!head->chiph_exists)) { struct device *tmp = head; head = &root; while (head->next != tmp) head = head->next; } FILE *autogen = fopen(outputc, "w"); if (!autogen) { fprintf(stderr, "Could not open file '%s' for writing: ", outputc); perror(NULL); exit(1); } struct header *h; if (scan_mode == STATIC_MODE) { 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#ifndef __PRE_RAM__\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"); walk_device_tree(autogen, &root, inherit_subsystem_ids, NULL); fprintf(autogen, "\n/* pass 0 */\n"); walk_device_tree(autogen, &root, pass0, NULL); fprintf(autogen, "\n/* pass 1 */\n" "ROMSTAGE_CONST struct device * ROMSTAGE_CONST last_dev = &%s;\n", lastdev->name); #ifdef MAINBOARDS_HAVE_CHIP_H fprintf(autogen, "static ROMSTAGE_CONST struct mainboard_config ROMSTAGE_CONST mainboard_info_0;\n"); #endif walk_device_tree(autogen, &root, pass1, NULL); } else if (scan_mode == BOOTBLOCK_MODE) { h = &headers; while (h->next) { h = h->next; fprintf(autogen, "#include \"%s/bootblock.c\"\n", h->name); } fprintf(autogen, "\n#if CONFIG_HAS_MAINBOARD_BOOTBLOCK\n"); fprintf(autogen, "#include \"mainboard/%s/bootblock.c\"\n", mainboard); fprintf(autogen, "#else\n"); fprintf(autogen, "static unsigned long init_mainboard(int bsp_cpu)\n{\n"); fprintf(autogen, "\tif (! bsp_cpu) return 0;\n"); h = &headers; while (h->next) { h = h->next; char * buf = translate_name(h->name, UNSLASH); if (buf) { fprintf(autogen, "\tinit_%s();\n", buf); free(buf); } } fprintf(autogen, "\treturn 0;\n}\n"); fprintf(autogen, "#endif\n"); } else if (scan_mode == KCONFIG_MODE) { fprintf(autogen, "\nconfig MAINBOARD_DIR\n\tstring\n"); fprintf(autogen, "\tdefault %s\n", mainboard); fprintf(autogen, "\nconfig MAINBOARD_DEVTREE\n\tdef_bool y\n"); h = &headers; while (h->next) { h = h->next; char * buf = translate_name(h->name, TO_UPPER); if (buf) { fprintf(autogen, "\tselect %s\n", buf); free(buf); } } } fclose(autogen); return 0; }
int main(int argc, char **argv) { if (argc != ARG_COUNT) usage(); char *devtree = argv[DEVICEFILE_ARG]; char *outputc = argv[OUTPUTFILE_ARG]; headers.next = 0; FILE *filec = fopen(devtree, "r"); if (!filec) { perror(NULL); exit(1); } yyrestart(filec); lastdev = head = &root; yyparse(); fclose(filec); if ((head->type == chip) && (!head->chiph_exists)) { struct device *tmp = head; head = &root; while (head->next != tmp) head = head->next; } FILE *autogen = fopen(outputc, "w"); if (!autogen) { fprintf(stderr, "Could not open file '%s' for writing: ", outputc); perror(NULL); 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#ifndef __PRE_RAM__\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"); walk_device_tree(autogen, &root, inherit_subsystem_ids, NULL); fprintf(autogen, "\n/* pass 0 */\n"); walk_device_tree(autogen, &root, pass0, NULL); fprintf(autogen, "\n/* pass 1 */\n" "ROMSTAGE_CONST struct device * ROMSTAGE_CONST last_dev = &%s;\n", lastdev->name); walk_device_tree(autogen, &root, pass1, NULL); fclose(autogen); return 0; }