[U-Boot-Users] [PATCH][RFC] Add common memory fixup function

Kumar Gala galak at kernel.crashing.org
Mon Nov 26 23:23:10 CET 2007


>
> +/ 
> ********************************************************************/
> +
> +static int ft_get_property_int(void *blob, char *path, const char  
> *prop)
> +{
> +	int offset, len;
> +	void *ptr;
> +	u32 dst;
> +
> +	offset = fdt_find_node_by_path(blob, path);
> +	ptr = fdt_getprop(blob, offset, prop, &len);
> +	debug("%s(): got %d size %d\n", __FUNCTION__, ptr, len);
> +	if ((ptr) && (len == sizeof(int))) {
> +		memcpy(&dst, ptr, len);
> +		debug("dest %d\n", dst);
> +		return dst;
> +	}
> +	return -1;
> +}
> +
> +int fdt_memory(void *fdt)

I want it to be passed start and size rather than grabbing them  
directly.  I have future applications in which using the same function  
will be useful.

> +{
> +	int   nodeoffset;
> +	int   err;
> +	u32   tmp[4];
> +	bd_t *bd = gd->bd;
> +
> +	err = fdt_check_header(fdt);
> +	if (err < 0) {
> +		printf("fdt_memory: %s\n", fdt_strerror(err));
> +		return err;
> +	}
> +
> +	memset(tmp, 0, sizeof(tmp));
> +	/* Now, figure out toplevel #ac and #sc - we'll need them later */
> +	offset = fdt_find_node_by_path(fdt, "/");
> +	ac = ft_get_property_int(fdt, "/", "#address-cells");
> +	sc = ft_get_property_int(fdt, "/", "#size-cells");
> +	debug("#address-cells=%d size-cells=%d\n", ac, sc);
> +
> +	/* update, or add and update /memory node */
> +	nodeoffset = fdt_find_node_by_path(fdt, "/memory");
> +	if (nodeoffset < 0) {
> +		nodeoffset = fdt_add_subnode(fdt, 0, "memory");
> +		if (nodeoffset < 0)
> +			printf("WARNING could not create /memory: %s.\n",
> +				fdt_strerror(nodeoffset));
> +		return nodeoffset;
> +	}
> +	err = fdt_setprop(fdt, nodeoffset, "device_type", "memory",
> +			  sizeof("memory"));
> +	if (err < 0) {
> +		printf("WARNING: could not set %s %s.\n",
> +		       "device_type", fdt_strerror(err));
> +		return err;
> +	}
> +
> +	/* this is a little rashly, but as long as u-boot is keeping
> +	 * memstart and memsize as ulong, should be safe.
> +	 */

Hmm, I think this is a bad assumption.  (We are looking at 36-bit phys  
support on e500 & e600).

> +	if ((ac >= 1) || (sc >= 1))
> +		debug("ulong memory params while #ac=%d and #sc=%d\n",
> +				ac, sc);
> +	tmp[ac-1] = cpu_to_fdt32(bd->bi_memstart);
> +	tmp[ac+sc-1] = cpu_to_fdt32(bd->bi_memsize);
> +
> +	err = fdt_setprop(blob, offset, "reg",
> +			tmp, (ac+sc)*sizeof(tmp[0])))
> +	if (err < 0) {
> +		printf("WARNING: could not set %s %s.\n",
> +		       "reg", fdt_strerror(err));
> +		return err;
> +	}
> +	return 0;
> +}
> +
> #endif /* CONFIG_OF_LIBFDT */




More information about the U-Boot mailing list