summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFurquan Shaikh <furquan@google.com>2018-06-11 04:26:45 -0700
committerPatrick Georgi <pgeorgi@google.com>2018-06-13 14:48:12 +0000
commitde39fc71604eb49ee652d68085595d2f151d8a28 (patch)
treeff2e9f69693be4de97addad4f7c9af253a3bb5cf
parent93459d6278f1557f3e38c33b79a8fd739aa7ff68 (diff)
util/sconfig: Prepare sconfig to allow parsing multiple trees
In preparation to allow devicetree overrides, it will be necessary to use the same parsing functions to prepare two separate parse trees. This change does the following things: 1. Updates root device and bus names to add base_ prefix. 2. Adds a function parse_devicetree that sets the root_parent and linenum before calling yyparse(). 3. Updates all uses of root_dev to refer to the next base_root_dev. BUG=b:80081934 TEST=Verified that static.c generated for all boards built using abuild is the same with and without this change. Change-Id: I403a90c1ebf07ac66115ddfe137daf0980dc1a18 Signed-off-by: Furquan Shaikh <furquan@google.com> Reviewed-on: https://review.coreboot.org/27017 Tested-by: build bot (Jenkins) <no-reply@coreboot.org> Reviewed-by: Stefan Reinauer <stefan.reinauer@coreboot.org>
-rw-r--r--util/sconfig/main.c55
1 files changed, 32 insertions, 23 deletions
diff --git a/util/sconfig/main.c b/util/sconfig/main.c
index 2a7fa15faf..b293c5d08a 100644
--- a/util/sconfig/main.c
+++ b/util/sconfig/main.c
@@ -20,6 +20,7 @@
extern int linenum;
+/* Maintains list of all the unique chip structures for the board. */
static struct chip chip_header;
/*
@@ -43,8 +44,8 @@ typedef enum {
*
*
* +------------------------+ +----------------------+
- * | | | Mainboard |
- * +---------+ Root device (root_dev) +--------------->+ instance +
+ * | Root device | | Mainboard |
+ * +---------+ (base_root_dev) +--------------->+ instance +
* | | | chip_instance | (mainboard_instance)|
* | +------------------------+ | |
* | | +----------------------+
@@ -52,7 +53,7 @@ typedef enum {
* | parent v |
* | +-------------------+ |
* | | Root bus | |
- * +----------->+ (root_bus) | |
+ * +----------->+ (base_root_bus) | |
* | | |
* +-------------------+ |
* | |
@@ -74,23 +75,23 @@ typedef enum {
*
*
*/
-static struct device root_dev;
+static struct device base_root_dev;
static struct chip_instance mainboard_instance;
-static struct bus root_bus = {
+static struct bus base_root_bus = {
.id = 0,
- .dev = &root_dev,
+ .dev = &base_root_dev,
};
-static struct device root_dev = {
+static struct device base_root_dev = {
.name = "dev_root",
.id = 0,
.chip_instance = &mainboard_instance,
.path = " .type = DEVICE_PATH_ROOT ",
.ops = "&default_dev_ops_root",
- .parent = &root_bus,
+ .parent = &base_root_bus,
.enabled = 1,
- .bus = &root_bus,
+ .bus = &base_root_bus,
};
static struct chip mainboard_chip = {
@@ -105,7 +106,7 @@ static struct chip_instance mainboard_instance = {
};
/* This is the parent of all devices added by parsing the devicetree file. */
-struct bus *root_parent = &root_bus;
+struct bus *root_parent;
struct queue_entry {
void *data;
@@ -581,7 +582,7 @@ static int dev_has_children(struct device *dev)
static void pass0(FILE *fil, struct device *ptr, struct device *next)
{
- if (ptr == &root_dev) {
+ if (ptr == &base_root_dev) {
fprintf(fil, "DEVTREE_CONST struct bus %s_links[];\n",
ptr->name);
return;
@@ -670,7 +671,7 @@ static void pass1(FILE *fil, struct device *ptr, struct device *next)
struct chip_instance *chip_ins = ptr->chip_instance;
int has_children = dev_has_children(ptr);
- if (ptr != &root_dev)
+ if (ptr != &base_root_dev)
fprintf(fil, "static ");
fprintf(fil, "DEVTREE_CONST struct device %s = {\n", ptr->name);
fprintf(fil, "#if !DEVTREE_EARLY\n");
@@ -867,15 +868,9 @@ enum {
#define ARG_COUNT 3
-int main(int argc, char **argv)
+static void parse_devicetree(const char *file, struct bus *parent)
{
- if (argc != ARG_COUNT)
- usage();
-
- char *devtree = argv[DEVICEFILE_ARG];
- char *outputc = argv[OUTPUTFILE_ARG];
-
- FILE *filec = fopen(devtree, "r");
+ FILE *filec = fopen(file, "r");
if (!filec) {
perror(NULL);
exit(1);
@@ -883,9 +878,23 @@ int main(int argc, char **argv)
yyrestart(filec);
+ root_parent = parent;
+ linenum = 0;
+
yyparse();
fclose(filec);
+}
+
+int main(int argc, char **argv)
+{
+ if (argc != ARG_COUNT)
+ usage();
+
+ char *base_devtree = argv[DEVICEFILE_ARG];
+ char *outputc = argv[OUTPUTFILE_ARG];
+
+ parse_devicetree(base_devtree, &base_root_bus);
FILE *autogen = fopen(outputc, "w");
if (!autogen) {
@@ -897,11 +906,11 @@ int main(int argc, char **argv)
emit_chips(autogen);
- walk_device_tree(autogen, &root_dev, inherit_subsystem_ids);
+ walk_device_tree(autogen, &base_root_dev, inherit_subsystem_ids);
fprintf(autogen, "\n/* pass 0 */\n");
- walk_device_tree(autogen, &root_dev, pass0);
+ walk_device_tree(autogen, &base_root_dev, pass0);
fprintf(autogen, "\n/* pass 1 */\n");
- walk_device_tree(autogen, &root_dev, pass1);
+ walk_device_tree(autogen, &base_root_dev, pass1);
fclose(autogen);