> -----Original Message-----
> From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
> On Behalf Of ron minnich
> Sent: Monday, November 24, 2008 11:06 AM
> To: Coreboot
> Subject: [coreboot] dt compiler patch
> 
> This has been tested and builds a working boot-to-linux coreboot on
> the dbe62 (old style dts) and builds a serengeti target (new dts, but
> that new dts not submitted yet).
> 
> ron

Here's my first pass.

Thanks,
Myles

> I took the opportunity to do some cleanup. 
> 
> Signed-off-by: Ronald G. Minnich <[EMAIL PROTECTED]>
> Index: util/dtc/flattree.c
> ===================================================================
> --- util/dtc/flattree.c       (revision 1046)
> +++ util/dtc/flattree.c       (working copy)
> @@ -443,10 +449,7 @@
>  {
>       struct data d = p->val;
>       FILE *f = e;
> -     int i;
>       char *cleanname;
> -     int vallen = d.len > 4 ? 4 : d.len;
> -

Lets take out the commented code that uses these variables at the same time.

>       /* nothing to do? */
>       if (d.len == 0)
>               return;
> @@ -865,7 +875,7 @@
>  
>       if (tree->config){
>               int i;
> -//           treename = clean(tree->label, 0);
> +//           treename = clean(tree->dtslabel, 0);

Maybe just remove this line.

>               treename = toname(tree->config->label, "_config");
>               for(i = 0; i < emitted_names_count; i++)
>                       if (!strcmp(treename, emitted_names[i]))
> Index: util/dtc/livetree.c
> ===================================================================
> --- util/dtc/livetree.c       (revision 1046)
> +++ util/dtc/livetree.c       (working copy)
> @@ -43,6 +44,74 @@
>       return new;
>  }
>  
> +/* XXX HACK */
> +void move_proplist_to_config(struct node *f)
> +{
> +     struct node *n = f;
> +     while (n) {
> +             n->config = n->proplist; 
> +             n->proplist = NULL;
> +             move_proplist_to_config(n->children);
> +             n = n->next_sibling;
> +     } 
> +}
> +
> +/** 
> + * Given a set of nodes from a chip dts, and a set of nodes from the
mainboard dts, 
> + * update the chip dts nodes with values from the mainboard dts. 
> + * All this work is so that a chip dts can set default values and a
mainboard 
> + * can override them. 
> + * Node definitions come from the chip dts.
> + * These definitions have properties that are used in turn to create the 
> + * C structures. 
> + * Changing the vlaues of properties in the node definitions is done by
> + * creating nodes in the mainboard dts. 
> + * For each of the node defintions from 'config', we 
> + * have to match the node definitions in 'subnodes', 
> + * that have matching labels. For each matching label, we modify the 
> + * property settings for the node in config. 
> + * Finally, for all subnodes that are leftover, i.e. did not match
anything in the 
> + * config, we simply append them to the list of subnodes from config. 
> + * Later, it might be an error to have a missing match. 
> + * 
> + */
> +void
> +fixup_properties(struct node *chipnodes, struct node *mainboardnodes)
> +{
> +     struct node *c;
> +     struct node *m = mainboardnodes;
> +     struct node *del = NULL;
> +     struct node *head = mainboardnodes;
> +
> +     while (m) {
> +             for (c = chipnodes; c; c = c->next) {
> +                     if (strcmp(c->dtslabel, m->dtslabel)) {
> +                             continue;
> +                     }
> +                     /* match */
> +                     /* the chip properties are in c->config list
> +                      * the dts properties are in the m->proplist. 
> +                      * So copy the mainboard properties to the chip
proplist. 
> +                      */
> +                     c->proplist = m->proplist;

This is a replacement, shouldn't it be an append?

> +                     c->children = m->children;

Again, this is a replacement, shouldn't it be an append?

> +                     /* since we matched this node we have to delete it.
*/

The delete function says you can't have children, so the children link needs
to be NULL here.

> +                     del = m;
> +                     break;
> +             }
> +             /* must track head node for append_node below. */
> +             if (m == head)
> +                     head = m->next;
> +             m = m->next;
> +             if (del)
> +                     del_node(del);
> +             del = NULL;
> +     }
> +     /* backwards compatibility: anything left gets appended to the chip
list */
> +     if (head)
> +             append_node(chipnodes, head);
> +}
> +
>  struct property *chain_property(struct property *first, struct property
*list)
>  {
>       assert(first->next == NULL);
> @@ -51,12 +120,9 @@
>       return first;      
>  }
>  
> -struct node *build_node(struct property *config, struct property
*proplist, struct node *children)
> +struct node *new_node(struct property *config, struct property *proplist,
struct node *children)
>  {
> -     static struct node *last_node = NULL;
> -
>       struct node *new = xmalloc(sizeof(*new));
> -     struct node *child;
>  
>       memset(new, 0, sizeof(*new));
>  
> @@ -64,6 +130,39 @@
>       new->proplist = proplist;
>       new->children = children;
>  
> +     return new;
> +}
> +
> +/* we should only ever delete simple nodes: nodes with no kids. */
> +void del_node(struct node *node)
> +{
> +     struct node *n;
> +     assert(! node->children);
> +     if (first_node == node) {
> +             first_node = node->next;
> +             free(node);
> +             return;
> +     }
> +     for_all_nodes(n) {
> +             if (n->next != node)
> +                     continue;
> +             n->next = node->next;
> +             n->next_sibling = node->next_sibling;

Will this always be true?  It seems like you need to go through again to do
the sibling links right.

> +             if (node == last_node)
> +                     last_node = n;
> +             break;
> +     }
> +     free(node);
> +}
> +
> +struct node *build_node(struct property *config, struct property
*proplist, struct node *children)
> +{
> +
> +     struct node *new;
> +     struct node *child;
> +
> +     new = new_node(config, proplist, children);
> +
>       for_each_child(new, child) {
>               child->parent = new;
>       }
> @@ -85,7 +184,7 @@
>  
>       node->name = name;
>  
> -     node->label = label;
> +     node->dtslabel = label;
>  
>       return node;
>  }
> @@ -98,6 +197,16 @@
>       return first;
>  }
>  

Do we guarantee that you will never be appending to a NULL list (first ==
NULL), I didn't see that check.

> +struct node *append_node(struct node *first, struct node *list)
> +{
> +     struct node *n = first;
> +     while(n->next_sibling) {
> +             n = n->next_sibling;
> +     } 
> +     n->next_sibling = list;
> +     return first;
> +}
> +
>  void add_property(struct node *node, struct property *prop)
>  {
>       struct property **p;


--
coreboot mailing list: [email protected]
http://www.coreboot.org/mailman/listinfo/coreboot

Reply via email to