public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: Pantelis Antoniou <pantelis.antoniou@konsulko.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH 3/5] fdt: Allow stacked overlays phandle references
Date: Tue, 04 Jul 2017 20:03:42 +0300	[thread overview]
Message-ID: <1499187822.4225.47.camel@hp800z> (raw)
In-Reply-To: <822fa395-bca7-82ec-a795-4e4be5ef8fbc@denx.de>

Hi Marek,

On Sat, 2017-07-01 at 16:07 +0200, Marek Vasut wrote:
> On 06/30/2017 06:23 PM, Pantelis Antoniou wrote:
> 
> [...]
> 
> > +static int overlay_symbol_update(void *fdt, void *fdto)
> > +{
> > +	int root_sym, ov_sym, prop, path_len, fragment, target;
> > +	int len, frag_name_len, ret, rel_path_len;
> > +	const char *s;
> > +	const char *path;
> > +	const char *name;
> > +	const char *frag_name;
> > +	const char *rel_path;
> > +	char *buf = NULL;
> > +
> > +	root_sym = fdt_subnode_offset(fdt, 0, "__symbols__");
> > +	ov_sym = fdt_subnode_offset(fdto, 0, "__symbols__");
> > +
> > +	/* if neither exist we can't update symbols, but that's OK */
> > +	if (root_sym < 0 || ov_sym < 0)
> > +		return 0;
> 
> If you have symbol table in either the DTO or the base DT, but not in
> the other one, wouldn't it make sense to use that one symbol table
> instead of bailing out ?
> 

It's bailing out without an error.

The logic is simple; if there's no symbol table in the base tree, that
means that there's no symbols in the base device tree, i.e. not compiled
with the option to generate it. No point in inserting overlay symbols.

If there's no symbol table in the overlay that perfectly fine, no symbol
work then.

> > +	buf = malloc(FDT_PATH_MAX);
> > +	if (!buf)
> > +		return -FDT_ERR_NOSPACE;
> 
> Would it make sense to allocate this on stack ?
> 

FDT_PATH_MAX = 4K, dubious if the u-boot stack will have enough space.
Especially in SPL cases. 

> > +	/* iterate over each overlay symbol */
> > +	fdt_for_each_property_offset(prop, fdto, ov_sym) {
> > +
> > +		path = fdt_getprop_by_offset(fdto, prop, &name, &path_len);
> > +		if (!path) {
> > +			ret = path_len;
> > +			goto out;
> > +		}
> > +
> > +		/* skip autogenerated properties */
> > +		if (!strcmp(name, "name"))
> > +			continue;
> > +
> > +		/* format: /<fragment-name>/__overlay__/<relative-subnode-path> */
> > +
> > +		if (*path != '/') {
> > +			ret = -FDT_ERR_BADVALUE;
> > +			goto out;
> > +		}
> > +
> > +		/* get frag name first */
> 
> "frag name" ? What is this now, Unreal Tournament ? :)
> 

Fragment. There were computers before first person shooters.

> > +		s = strchr(path + 1, '/');
> > +		if (!s) {
> > +			ret = -FDT_ERR_BADVALUE;
> > +			goto out;
> > +		}
> > +		frag_name = path + 1;
> > +		frag_name_len = s - path - 1;
> > +
> > +		/* verify format */
> > +		len = strlen("/__overlay__/");
> > +		if (strncmp(s, "/__overlay__/", len)) {
> > +			ret = -FDT_ERR_NOTFOUND;
> > +			goto out;
> > +		}
> > +
> > +		rel_path = s + len;
> > +		rel_path_len = strlen(rel_path);
> > +
> > +		/* find the fragment index in which the symbol lies */
> > +		fdt_for_each_subnode(fragment, fdto, 0) {
> > +
> > +			s = fdt_get_name(fdto, fragment, &len);
> > +			if (!s)
> > +				continue;
> > +
> > +			/* name must match */
> > +			if (len == frag_name_len && !memcmp(s, frag_name, len))
> > +				break;
> > +		}
> > +
> > +		/* not found? */
> > +		if (fragment < 0) {
> > +			ret = -FDT_ERR_NOTFOUND;
> > +			goto out;
> > +		}
> > +
> > +		/* an __overlay__ subnode must exist */
> > +		ret = fdt_subnode_offset(fdto, fragment, "__overlay__");
> > +		if (ret < 0)
> > +			goto out;
> > +
> > +		/* get the target of the fragment */
> > +		ret = overlay_get_target(fdt, fdto, fragment);
> > +		if (ret < 0)
> > +			goto out;
> > +		target = ret;
> > +
> > +		/* get the path of the target */
> > +		ret = fdt_get_path(fdt, target, buf, FDT_PATH_MAX);
> > +		if (ret < 0)
> > +			goto out;
> > +
> > +		len = strlen(buf);
> > +
> > +		/* if the target is root strip leading / */
> > +		if (len == 1 && buf[0] == '/')
> > +			len = 0;
> > +
> > +		/* make sure we have enough space */
> > +		if (len + 1 + rel_path_len + 1 > FDT_PATH_MAX) {
> > +			ret = -FDT_ERR_NOSPACE;
> > +			goto out;
> > +		}
> > +
> > +		/* create new symbol path in place */
> > +		buf[len] = '/';
> > +		memcpy(buf + len + 1, rel_path, rel_path_len);
> > +		buf[len + 1 + rel_path_len] = '\0';
> 
> Can snprintf() help somewhere here instead of the memcpy() ?
> 

It is going to be considerably slower (although that doesn't matter
much). We still need to do the space check before so it's not going to
be worth the change IMO.
 
> > +		ret = fdt_setprop_string(fdt, root_sym, name, buf);
> > +		if (ret < 0)
> > +			goto out;
> > +	}
> > +
> > +	ret = 0;
> > +
> > +out:
> > +	if (buf)
> > +		free(buf);
> > +
> > +	return ret;
> > +}
> > +
> >  int fdt_overlay_apply(void *fdt, void *fdto)
> >  {
> >  	uint32_t delta = fdt_get_max_phandle(fdt);
> > @@ -654,6 +796,10 @@ int fdt_overlay_apply(void *fdt, void *fdto)
> >  	if (ret)
> >  		goto err;
> >  
> > +	ret = overlay_symbol_update(fdt, fdto);
> > +	if (ret)
> > +		goto err;
> > +
> >  	/*
> >  	 * The overlay has been damaged, erase its magic.
> >  	 */
> > 
> 
> 

Regards

-- Pantelis

  reply	other threads:[~2017-07-04 17:03 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-06-30 16:22 [U-Boot] [PATCH 0/5] uboot overlays and FIT image Pantelis Antoniou
2017-06-30 16:22 ` [U-Boot] [PATCH 1/5] libfdt.h: Introduce FDT_PATH_MAX Pantelis Antoniou
2017-07-01 14:01   ` Marek Vasut
2017-07-07  3:58     ` Simon Glass
2017-07-07  7:03       ` Pantelis Antoniou
2017-06-30 16:22 ` [U-Boot] [PATCH 2/5] libfdt_env.h: Add <malloc.h> in libfdt environment Pantelis Antoniou
2017-07-01 14:02   ` Marek Vasut
2017-07-04 16:53     ` Pantelis Antoniou
2017-07-07  3:58   ` Simon Glass
2017-06-30 16:23 ` [U-Boot] [PATCH 3/5] fdt: Allow stacked overlays phandle references Pantelis Antoniou
2017-07-01 14:07   ` Marek Vasut
2017-07-04 17:03     ` Pantelis Antoniou [this message]
2017-07-05  6:25     ` Lothar Waßmann
2017-07-07  3:58   ` Simon Glass
2017-07-07  7:02     ` Pantelis Antoniou
2017-07-14 13:51       ` Simon Glass
2017-06-30 16:23 ` [U-Boot] [PATCH 4/5] test: overlay: Add unit test for stacked overlay Pantelis Antoniou
2017-07-07  3:58   ` Simon Glass
2017-07-07  7:48   ` Moritz Fischer
2017-07-07  8:32     ` Marek Vasut
2017-07-07 10:33     ` Pantelis Antoniou
2017-06-30 16:23 ` [U-Boot] [PATCH 5/5] fit: Introduce methods for applying overlays on fit-load Pantelis Antoniou
2017-07-01 14:11   ` Marek Vasut
2017-07-04 17:05     ` Pantelis Antoniou
2017-07-04 22:19       ` stefan.bruens at rwth-aachen.de
2017-07-05  6:32         ` Lothar Waßmann
2017-07-28 18:48 ` [U-Boot] [PATCH 0/5] uboot overlays and FIT image Simon Glass
2017-07-28 19:20   ` Tom Rini

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1499187822.4225.47.camel@hp800z \
    --to=pantelis.antoniou@konsulko.com \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox