[coreboot] [PATCH] [v3] add array parsing to dts

Ward Vandewege ward at gnu.org
Wed Apr 16 14:52:46 CEST 2008


On Wed, Apr 16, 2008 at 05:02:47AM +0200, Peter Stuge wrote:
> On Sat, Apr 12, 2008 at 10:11:18PM -0400, Ward Vandewege wrote:
> > ..byte properties..
> 
> I guess they should be unsigned chars?

Maybe - the DTS syntax suggests this is an array; so an array of unsigned
chars? The example in the test.dts file in util/dtc goes like this:

  randomnode {
    string = "\xff\0stuffstuff\t\t\t\n\n\n";
    blob = [0a 0b 0c 0d de ea ad be ef];
    ref = < &/memory at 0 >;
  };

That 'blob' property is what's called a 'byte' property.

> > Index: flattree.c
> > ===================================================================
> > --- util/dtc/flattree.c	(revision 656)
> > +++ util/dtc/flattree.c	(working copy)
> > @@ -452,9 +452,24 @@
> >  		return;
> >  
> >  	cleanname = clean(p->name, 1);
> > -	fprintf(f, "\t.%s = ", cleanname);
> > +	if (d.type == 'S') {
> > +		// Standard property (scalar)
> > +		fprintf(f, "\t.%s = ", cleanname);
> > +		fprintf(f, "0x%lx,\n", strtoul((char *)d.val, 0, 0));
> > +	} else if (d.type == 'C') {
> > +		// 'Cell' property (array of 4-byte elements)
> > +		fprintf(f, "\t.%s = {\n", cleanname, d.len/4);
> 
> Why the last parameter d.len/4? It's not used, right?

Right, that was leftover from an earlier version of the patch. Dropped.

> > +		int i;
> > +	  for (i = 0; (i < d.len) && (0 != *(u32 *)(d.val+i)); i = i+4) {
> > +			fprintf(f, "\t\t[%d] = 0x%08X,\n",i/4,*(u32 *)(d.val+i));
> > +		} 
> 
> Looks like there's some strange whitespace here.

Good catch, fixed.

> 
> 
> > +		fprintf(f, "\t\t[%d] = 0x00000000,\n",i/4);	// Make sure to end our array with a zero element
> 
> Perhaps use 0x0 or 0 to show that this last entry is not generated
> the same way as the previous ones.

Good idea, done.

> > @@ -785,7 +800,16 @@
> >  			if (streq(prop->name, "device_operations")) /* this is special */
> >  				continue;
> >  			cleanname = clean(prop->name, 0);
> > -			fprintf(f, "\tu32 %s;\n", cleanname);
> > +			if (prop->val.type == 'S') {
> > +				// Standard property, scalar
> > +				fprintf(f, "\tu32 %s;\n", cleanname);
> > +			} else if (prop->val.type == 'C') {
> > +				// 'Cell' property (array of 4-byte elements)
> > +				fprintf(f, "\tu32 %s[];\n", cleanname);
> 
> Will this always work? An empty array like this must be last in the
> containing struct, and there can only ever be one in each struct.

Ah, that's a good point. Since we know at this point how long the array is
going to be, I've just added that to the struct definition.

Is the attached better?

Thanks,
Ward.


-- 
Ward Vandewege <ward at fsf.org>
Free Software Foundation - Senior System Administrator
-------------- next part --------------
A non-text attachment was scrubbed...
Name: v3-dts-array3.patch
Type: text/x-diff
Size: 3754 bytes
Desc: not available
URL: <http://www.coreboot.org/pipermail/coreboot/attachments/20080416/40fca3fc/attachment.bin>


More information about the coreboot mailing list