[coreboot] [PATCH] v3: more uniqueness in the dtc generated struct names

Carl-Daniel Hailfinger c-d.hailfinger.devel.2006 at gmx.net
Sat Aug 30 00:57:27 CEST 2008


I managed to break dtc while working on PCI bridges:
dtc only uses dev_fn as identifier for a PCI device. That gets us a name
collision if we have the same dev_fn combination on multiple buses.
Either we add a random unique ID to the struct name or we integrate the
number of the parent device as well.
A third option would be to store the complete hierarchy in the name.
I decided to go for integration of parent device name.

With the following device tree

/{
	cpus {};
	domain at 0 {
		bus at 0 {
			pci at 0,0 {
			};
			pci at 1,1 {
			};
			pci at f,0 {
				bus at 1 {
					pci at 0,0 {
					};
				};
			};
		};
	};
};


we get the old names:
dev_root
dev_cpus
dev_domain_0
dev_bus_0
dev_pci_0_0
dev_pci_1_1
dev_pci_f_0
dev_bus_1
dev_pci_0_0 COLLISION!!!


and the new names:
dev_root
dev_cpus
dev_domain_0
dev_domain_0_bus_0
dev_bus_0_pci_0_0
dev_bus_0_pci_1_1
dev_bus_0_pci_f_0
dev_pci_f_0_bus_1
dev_bus_1_pci_0_0

and the third option (not used) would have looked like this:
dev_root
dev_cpus
dev_domain_0
dev_domain_0_bus_0
dev_domain_0_bus_0_pci_0_0
dev_domain_0_bus_0_pci_1_1
dev_domain_0_bus_0_pci_f_0
dev_domain_0_bus_0_pci_f_0_bus_1
dev_domain_0_bus_0_pci_f_0_bus_1_pci_0_0


Signed-off-by: Carl-Daniel Hailfinger <c-d.hailfinger.devel.2006 at gmx.net>


Index: corebootv3-pci_scan_bus/util/dtc/flattree.c
===================================================================
--- corebootv3-pci_scan_bus/util/dtc/flattree.c	(Revision 846)
+++ corebootv3-pci_scan_bus/util/dtc/flattree.c	(Arbeitskopie)
@@ -931,6 +931,7 @@
 		emit->endnode(etarget, treelabel);
 	}
 
+	//fprintf(f, "//tree->label is %s, tree->parent->label is %s\n", tree->label, tree->parent ? tree->parent->label : NULL);
 	/* now emit the device for this node, with sibling and child pointers etc. */
 	emit->special(f, tree);
 
@@ -1313,8 +1314,23 @@
 labeltree(struct node *tree)
 {
 	struct node *child;
+	char *tmp1;
+	char *tmp2;
 
+	//printf("//tree->label is %s, tree->parent->label is %s\n", tree->label, tree->parent ? tree->parent->label : NULL);
 	tree->label = clean(tree->name, 1);
+	if (tree->parent && tree->label) {
+		tmp1 = clean(tree->parent->name, 1);
+		if (strlen(tmp1)) {
+			tmp2 = tree->label;
+			tree->label = malloc(strlen(tmp1) + strlen(tmp2) + 2);
+			strcpy(tree->label, tmp1);
+			strcat(tree->label, "_");
+			strcat(tree->label, tmp2);
+			free(tmp2);
+		}
+		free(tmp1);
+	}
 	
 	if (tree->next_sibling)
 		labeltree(tree->next_sibling);


-- 
http://www.hailfinger.org/





More information about the coreboot mailing list