[POWERPC] Fix bug adding properties with flatdevtree.c's ft_set_prop()

ft_set_prop() from flatdevtree.c in the zImage wrapper will either
replace an existing property in the flat device tree, or add a new
property definiion if the given property isn't present.

However, when adding properties, it adds the property definition
immediately before the node's END_NODE tag, potentially after any
subnode definitions for the node. This confuses the kernel flat tree
parser in prom.c which assumes that all property definitions for a
node come before all subnode definitions.

This patch corrects ft_set_prop() so that it adds new properties
before the first subnode, instead of before the END_NODE tag.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
Acked-by: Scott Wood <scottwood@freescale.com>
Acked-by: Mark A. Greer <mgreer@mvista.com>
Signed-off-by: Paul Mackerras <paulus@samba.org>

authored by David Gibson and committed by Paul Mackerras 7c40542f e3d67b66

+8 -9
+8 -9
arch/powerpc/boot/flatdevtree.c
··· 891 struct ft_atom atom; 892 void *node; 893 char *p, *next; 894 - int nextra, depth; 895 896 node = ft_node_ph2node(cxt, phandle); 897 if (node == NULL) 898 return -1; 899 900 - depth = 0; 901 - p = node; 902 903 while ((next = ft_next(cxt, p, &atom)) != NULL) { 904 switch (atom.tag) { 905 - case OF_DT_BEGIN_NODE: 906 - ++depth; 907 - break; 908 case OF_DT_END_NODE: 909 - if (--depth > 0) 910 - break; 911 /* haven't found the property, insert here */ 912 cxt->p = p; 913 return ft_prop(cxt, propname, buf, buflen); 914 case OF_DT_PROP: 915 - if ((depth != 1) || strcmp(atom.name, propname)) 916 break; 917 /* found an existing property, overwrite it */ 918 nextra = _ALIGN(buflen, 4) - _ALIGN(atom.size, 4);
··· 891 struct ft_atom atom; 892 void *node; 893 char *p, *next; 894 + int nextra; 895 896 node = ft_node_ph2node(cxt, phandle); 897 if (node == NULL) 898 return -1; 899 900 + next = ft_next(cxt, node, &atom); 901 + if (atom.tag != OF_DT_BEGIN_NODE) 902 + /* phandle didn't point to a node */ 903 + return -1; 904 + p = next; 905 906 while ((next = ft_next(cxt, p, &atom)) != NULL) { 907 switch (atom.tag) { 908 + case OF_DT_BEGIN_NODE: /* properties must go before subnodes */ 909 case OF_DT_END_NODE: 910 /* haven't found the property, insert here */ 911 cxt->p = p; 912 return ft_prop(cxt, propname, buf, buflen); 913 case OF_DT_PROP: 914 + if (strcmp(atom.name, propname)) 915 break; 916 /* found an existing property, overwrite it */ 917 nextra = _ALIGN(buflen, 4) - _ALIGN(atom.size, 4);