[coreboot-gerrit] Change in coreboot[master]: util/sconfig: Prepare sconfig to allow parsing multiple trees

Furquan Shaikh (Code Review) gerrit at coreboot.org
Mon Jun 11 13:39:14 CEST 2018


Furquan Shaikh has uploaded this change for review. ( https://review.coreboot.org/27017


Change subject: util/sconfig: Prepare sconfig to allow parsing multiple trees
......................................................................

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 at google.com>
---
M util/sconfig/main.c
1 file changed, 32 insertions(+), 23 deletions(-)



  git pull ssh://review.coreboot.org:29418/coreboot refs/changes/17/27017/1

diff --git a/util/sconfig/main.c b/util/sconfig/main.c
index 2a7fa15..b293c5d 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 @@
  *
  *
  *                 +------------------------+                +----------------------+
- *                 |                        |                |  Mainboard           |
- *       +---------+ Root device (root_dev) +--------------->+  instance            +
+ *                 |       Root device      |                |  Mainboard           |
+ *       +---------+     (base_root_dev)    +--------------->+  instance            +
  *       |         |                        | chip_instance  |  (mainboard_instance)|
  *       |         +------------------------+                |                      |
  *       |                      |                            +----------------------+
@@ -52,7 +53,7 @@
  *       | parent               v                                      |
  *       |            +-------------------+                            |
  *       |            |     Root bus      |                            |
- *       +----------->+    (root_bus)     |                            |
+ *       +----------->+  (base_root_bus)  |                            |
  *                    |                   |                            |
  *                    +-------------------+                            |
  *                              |                                      |
@@ -74,23 +75,23 @@
  *
  *
  */
-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 @@
 };
 
 /* 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 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 @@
 	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 @@
 
 #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 @@
 
 	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 @@
 
 	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);
 

-- 
To view, visit https://review.coreboot.org/27017
To unsubscribe, or for help writing mail filters, visit https://review.coreboot.org/settings

Gerrit-Project: coreboot
Gerrit-Branch: master
Gerrit-MessageType: newchange
Gerrit-Change-Id: I403a90c1ebf07ac66115ddfe137daf0980dc1a18
Gerrit-Change-Number: 27017
Gerrit-PatchSet: 1
Gerrit-Owner: Furquan Shaikh <furquan at google.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.coreboot.org/pipermail/coreboot-gerrit/attachments/20180611/4b10c12e/attachment-0001.html>


More information about the coreboot-gerrit mailing list