All of lore.kernel.org
 help / color / mirror / Atom feed
From: Maxime Ripard <maxime.ripard-wi1+55ScJUtKEb57/3fJTNBPR1lH4CV8@public.gmane.org>
To: Pantelis Antoniou
	<pantelis.antoniou-OWPKS81ov/FWk0Htik3J/w@public.gmane.org>
Cc: "Simon Glass" <sjg-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org>,
	"Boris Brezillon"
	<boris.brezillon-wi1+55ScJUtKEb57/3fJTNBPR1lH4CV8@public.gmane.org>,
	"Alexander Kaplan" <alex-MflLfwwFzuz+yO7R74ARew@public.gmane.org>,
	"Thomas Petazzoni"
	<thomas.petazzoni-wi1+55ScJUtKEb57/3fJTNBPR1lH4CV8@public.gmane.org>,
	devicetree-compiler-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
	"Antoine Ténart"
	<antoine.tenart-wi1+55ScJUtKEb57/3fJTNBPR1lH4CV8@public.gmane.org>,
	"Hans de Goede"
	<hdegoede-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>,
	"Tom Rini" <trini-OWPKS81ov/FWk0Htik3J/w@public.gmane.org>,
	u-boot-0aAXYlwwYIKGBzrmiIFOJg@public.gmane.org,
	"Stefan Agner" <stefan-XLVq0VzYD2Y@public.gmane.org>
Subject: Re: [PATCH v2 7/9] libfdt: Add overlay application function
Date: Mon, 13 Jun 2016 11:51:50 +0200	[thread overview]
Message-ID: <20160613095150.GG4481@lukather> (raw)
In-Reply-To: <34997AD3-B621-4823-920E-22E4A6F0E0D1-OWPKS81ov/FWk0Htik3J/w@public.gmane.org>

[-- Attachment #1: Type: text/plain, Size: 4029 bytes --]

Hi Pantelis,

On Fri, Jun 10, 2016 at 05:28:11PM +0300, Pantelis Antoniou wrote:
> Hi Maxime,
> 
> > On May 27, 2016, at 12:13 , Maxime Ripard <maxime.ripard@free-electrons.com> wrote:
> > 
> > The device tree overlays are a good way to deal with user-modifyable
> > boards or boards with some kind of an expansion mechanism where we can
> > easily plug new board in (like the BBB, the Raspberry Pi or the CHIP).
> > 
> > Add a new function to merge overlays with a base device tree.
> > 
> > Signed-off-by: Maxime Ripard <maxime.ripard-wi1+55ScJUtKEb57/3fJTNBPR1lH4CV8@public.gmane.org>
> > ---
> > include/libfdt.h         |  30 ++++
> > lib/libfdt/Makefile      |   2 +-
> > lib/libfdt/fdt_overlay.c | 414 +++++++++++++++++++++++++++++++++++++++++++++++
> > 3 files changed, 445 insertions(+), 1 deletion(-)
> > create mode 100644 lib/libfdt/fdt_overlay.c
> > 
> > diff --git a/include/libfdt.h b/include/libfdt.h
> > index 1e01b2c7ebdf..783067e841a1 100644
> > --- a/include/libfdt.h
> > +++ b/include/libfdt.h
> > @@ -1698,6 +1698,36 @@ int fdt_add_subnode(void *fdt, int parentoffset, const char *name);
> >  */
> > int fdt_del_node(void *fdt, int nodeoffset);
> > 
> > +/**
> > + * fdt_overlay_apply - Applies a DT overlay on a base DT
> > + * @fdt: pointer to the base device tree blob
> > + * @fdto: pointer to the device tree overlay blob
> > + *
> > + * fdt_overlay_apply() will apply the given device tree overlay on the
> > + * given base device tree.
> > + *
> > + * Expect the base device tree to be modified, even if the function
> > + * returns an error.
> > + *
> 
> If the base tree has been modified on an error it is unsafe to use it
> for booting. A valid strategy would be to scribble over the DT magic
> number so that that blob is invalidated.
> 
> What are the other people’s opinion on this?

That would probably be safer yes, I'll change that.

> > +static int fdt_overlay_get_target(const void *fdt, const void *fdto,
> > +				  int fragment)
> > +{
> > +	uint32_t phandle;
> > +	const char *path;
> > +
> > +	/* Try first to do a phandle based lookup */
> > +	phandle = fdt_overlay_get_target_phandle(fdto, fragment);
> > +	if (phandle)
> > +		return fdt_node_offset_by_phandle(fdt, phandle);
> > +
> > +	/* And then a path based lookup */
> > +	path = fdt_getprop(fdto, fragment, "target-path", NULL);
> > +	if (!path)
> > +		return -FDT_ERR_NOTFOUND;
> > +
> > +	return fdt_path_offset(fdt, path);
> > +}
> > +
> 
> Those targets are fine; beware there are patches with more target options.

Ack.

> > +static int fdt_overlay_merge(void *dt, void *dto)
> > +{
> > +	int root, fragment;
> > +
> > +	root = fdt_path_offset(dto, "/");
> > +	if (root < 0)
> > +		return root;
> > +
> > +	fdt_for_each_subnode(dto, fragment, root) {
> > +		const char *name = fdt_get_name(dto, fragment, NULL);
> > +		uint32_t target;
> > +		int overlay;
> > +		int ret;
> > +
> > +		if (strncmp(name, "fragment", 8))
> > +			continue;
> > +
> 
> This is incorrect. The use of “fragment” is a convention only.
> The real test whether the node is an overlay fragment is that
> it contains a target property.
> 
> > +		target = fdt_overlay_get_target(dt, dto, fragment);
> > +		if (target < 0)
> > +			return target;
> > +
> 
> So you could do ‘if (target < 0) continue;’ or handle a more complex error code.

Ok, will change.

> I would caution against the liberal use of malloc in libfdt. We’re
> possibly running in a constrained environment; a custom extents
> based (non freeing) allocator should be better.

David had the same comments, and I will drop the mallocs entirely.

> We need some figures about memory consumption when this is enabled,
> and a CONFIG option to disable it.

The current code (before and after that patch) adds 18kB to a
sandbox_defconfig.

Maxime

-- 
Maxime Ripard, Free Electrons
Embedded Linux, Kernel and Android engineering
http://free-electrons.com

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 819 bytes --]

WARNING: multiple messages have this Message-ID (diff)
From: Maxime Ripard <maxime.ripard@free-electrons.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH v2 7/9] libfdt: Add overlay application function
Date: Mon, 13 Jun 2016 11:51:50 +0200	[thread overview]
Message-ID: <20160613095150.GG4481@lukather> (raw)
In-Reply-To: <34997AD3-B621-4823-920E-22E4A6F0E0D1@konsulko.com>

Hi Pantelis,

On Fri, Jun 10, 2016 at 05:28:11PM +0300, Pantelis Antoniou wrote:
> Hi Maxime,
> 
> > On May 27, 2016, at 12:13 , Maxime Ripard <maxime.ripard@free-electrons.com> wrote:
> > 
> > The device tree overlays are a good way to deal with user-modifyable
> > boards or boards with some kind of an expansion mechanism where we can
> > easily plug new board in (like the BBB, the Raspberry Pi or the CHIP).
> > 
> > Add a new function to merge overlays with a base device tree.
> > 
> > Signed-off-by: Maxime Ripard <maxime.ripard@free-electrons.com>
> > ---
> > include/libfdt.h         |  30 ++++
> > lib/libfdt/Makefile      |   2 +-
> > lib/libfdt/fdt_overlay.c | 414 +++++++++++++++++++++++++++++++++++++++++++++++
> > 3 files changed, 445 insertions(+), 1 deletion(-)
> > create mode 100644 lib/libfdt/fdt_overlay.c
> > 
> > diff --git a/include/libfdt.h b/include/libfdt.h
> > index 1e01b2c7ebdf..783067e841a1 100644
> > --- a/include/libfdt.h
> > +++ b/include/libfdt.h
> > @@ -1698,6 +1698,36 @@ int fdt_add_subnode(void *fdt, int parentoffset, const char *name);
> >  */
> > int fdt_del_node(void *fdt, int nodeoffset);
> > 
> > +/**
> > + * fdt_overlay_apply - Applies a DT overlay on a base DT
> > + * @fdt: pointer to the base device tree blob
> > + * @fdto: pointer to the device tree overlay blob
> > + *
> > + * fdt_overlay_apply() will apply the given device tree overlay on the
> > + * given base device tree.
> > + *
> > + * Expect the base device tree to be modified, even if the function
> > + * returns an error.
> > + *
> 
> If the base tree has been modified on an error it is unsafe to use it
> for booting. A valid strategy would be to scribble over the DT magic
> number so that that blob is invalidated.
> 
> What are the other people?s opinion on this?

That would probably be safer yes, I'll change that.

> > +static int fdt_overlay_get_target(const void *fdt, const void *fdto,
> > +				  int fragment)
> > +{
> > +	uint32_t phandle;
> > +	const char *path;
> > +
> > +	/* Try first to do a phandle based lookup */
> > +	phandle = fdt_overlay_get_target_phandle(fdto, fragment);
> > +	if (phandle)
> > +		return fdt_node_offset_by_phandle(fdt, phandle);
> > +
> > +	/* And then a path based lookup */
> > +	path = fdt_getprop(fdto, fragment, "target-path", NULL);
> > +	if (!path)
> > +		return -FDT_ERR_NOTFOUND;
> > +
> > +	return fdt_path_offset(fdt, path);
> > +}
> > +
> 
> Those targets are fine; beware there are patches with more target options.

Ack.

> > +static int fdt_overlay_merge(void *dt, void *dto)
> > +{
> > +	int root, fragment;
> > +
> > +	root = fdt_path_offset(dto, "/");
> > +	if (root < 0)
> > +		return root;
> > +
> > +	fdt_for_each_subnode(dto, fragment, root) {
> > +		const char *name = fdt_get_name(dto, fragment, NULL);
> > +		uint32_t target;
> > +		int overlay;
> > +		int ret;
> > +
> > +		if (strncmp(name, "fragment", 8))
> > +			continue;
> > +
> 
> This is incorrect. The use of ?fragment? is a convention only.
> The real test whether the node is an overlay fragment is that
> it contains a target property.
> 
> > +		target = fdt_overlay_get_target(dt, dto, fragment);
> > +		if (target < 0)
> > +			return target;
> > +
> 
> So you could do ?if (target < 0) continue;? or handle a more complex error code.

Ok, will change.

> I would caution against the liberal use of malloc in libfdt. We?re
> possibly running in a constrained environment; a custom extents
> based (non freeing) allocator should be better.

David had the same comments, and I will drop the mallocs entirely.

> We need some figures about memory consumption when this is enabled,
> and a CONFIG option to disable it.

The current code (before and after that patch) adds 18kB to a
sandbox_defconfig.

Maxime

-- 
Maxime Ripard, Free Electrons
Embedded Linux, Kernel and Android engineering
http://free-electrons.com
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20160613/2e1c13a3/attachment.sig>

  parent reply	other threads:[~2016-06-13  9:51 UTC|newest]

Thread overview: 82+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-05-27  9:13 [PATCH v2 0/9] cmd: fdt: Add device tree overlays support Maxime Ripard
2016-05-27  9:13 ` [U-Boot] " Maxime Ripard
     [not found] ` <1464340402-2249-1-git-send-email-maxime.ripard-wi1+55ScJUtKEb57/3fJTNBPR1lH4CV8@public.gmane.org>
2016-05-27  9:13   ` [PATCH v2 1/9] cmd: fdt: Narrow the check for fdt addr Maxime Ripard
2016-05-27  9:13     ` [U-Boot] " Maxime Ripard
     [not found]     ` <1464340402-2249-2-git-send-email-maxime.ripard-wi1+55ScJUtKEb57/3fJTNBPR1lH4CV8@public.gmane.org>
2016-06-10  0:34       ` Simon Glass
2016-06-10  0:34         ` [U-Boot] " Simon Glass
2016-06-10 13:55         ` Pantelis Antoniou
2016-06-10 13:55           ` [U-Boot] " Pantelis Antoniou
2016-05-27  9:13   ` [PATCH v2 2/9] scripts: Makefile.lib: Sanitize DTB names Maxime Ripard
2016-05-27  9:13     ` [U-Boot] " Maxime Ripard
     [not found]     ` <1464340402-2249-3-git-send-email-maxime.ripard-wi1+55ScJUtKEb57/3fJTNBPR1lH4CV8@public.gmane.org>
2016-06-10  0:34       ` Simon Glass
2016-06-10  0:34         ` [U-Boot] " Simon Glass
2016-06-10 13:59       ` Pantelis Antoniou
2016-06-10 13:59         ` [U-Boot] " Pantelis Antoniou
2016-05-27  9:13   ` [PATCH v2 3/9] vsprintf: Include stdarg for va_list Maxime Ripard
2016-05-27  9:13     ` [U-Boot] " Maxime Ripard
     [not found]     ` <1464340402-2249-4-git-send-email-maxime.ripard-wi1+55ScJUtKEb57/3fJTNBPR1lH4CV8@public.gmane.org>
2016-06-10  0:34       ` Simon Glass
2016-06-10  0:34         ` [U-Boot] " Simon Glass
2016-06-10 14:00     ` Pantelis Antoniou
2016-06-10 14:00       ` [U-Boot] " Pantelis Antoniou
2016-05-27  9:13   ` [PATCH v2 4/9] libfdt: Add new headers and defines Maxime Ripard
2016-05-27  9:13     ` [U-Boot] " Maxime Ripard
     [not found]     ` <1464340402-2249-5-git-send-email-maxime.ripard-wi1+55ScJUtKEb57/3fJTNBPR1lH4CV8@public.gmane.org>
2016-06-10  0:34       ` Simon Glass
2016-06-10  0:34         ` [U-Boot] " Simon Glass
2016-06-10 14:03       ` Pantelis Antoniou
2016-06-10 14:03         ` [U-Boot] " Pantelis Antoniou
     [not found]         ` <D44ABB0F-69B9-4DA6-8F8B-6F74A5B4BFE1-OWPKS81ov/FWk0Htik3J/w@public.gmane.org>
2016-06-11 10:30           ` David Gibson
2016-06-11 10:30             ` [U-Boot] " David Gibson
     [not found]             ` <20160611103035.GW9226-RXTfZT5YzpxwFLYp8hBm2A@public.gmane.org>
2016-06-13  9:28               ` Maxime Ripard
2016-06-13  9:28                 ` [U-Boot] " Maxime Ripard
2016-06-16  0:39                 ` Simon Glass
2016-06-16  0:39                   ` [U-Boot] " Simon Glass
2016-05-27  9:13   ` [PATCH v2 5/9] libfdt: Add iterator over properties Maxime Ripard
2016-05-27  9:13     ` [U-Boot] " Maxime Ripard
2016-06-10  2:51     ` Stefan Agner
2016-06-10  2:51       ` [U-Boot] " Stefan Agner
2016-06-10 14:04     ` Pantelis Antoniou
2016-06-10 14:04       ` [U-Boot] " Pantelis Antoniou
     [not found]       ` <73A48AF0-F702-4C43-80A4-A18AC4AD59C6-OWPKS81ov/FWk0Htik3J/w@public.gmane.org>
2016-06-13  9:35         ` Maxime Ripard
2016-06-13  9:35           ` [U-Boot] " Maxime Ripard
2016-05-27  9:13   ` [PATCH v2 6/9] libfdt: Add max phandle retrieval function Maxime Ripard
2016-05-27  9:13     ` [U-Boot] " Maxime Ripard
2016-06-10  2:55     ` Stefan Agner
2016-06-10  2:55       ` [U-Boot] " Stefan Agner
     [not found]     ` <1464340402-2249-7-git-send-email-maxime.ripard-wi1+55ScJUtKEb57/3fJTNBPR1lH4CV8@public.gmane.org>
2016-06-10 15:13       ` Pantelis Antoniou
2016-06-10 15:13         ` [U-Boot] " Pantelis Antoniou
2016-05-27  9:13   ` [PATCH v2 7/9] libfdt: Add overlay application function Maxime Ripard
2016-05-27  9:13     ` [U-Boot] " Maxime Ripard
2016-06-10  3:38     ` Stefan Agner
2016-06-10  3:38       ` [U-Boot] " Stefan Agner
     [not found]     ` <1464340402-2249-8-git-send-email-maxime.ripard-wi1+55ScJUtKEb57/3fJTNBPR1lH4CV8@public.gmane.org>
2016-06-10 14:28       ` Pantelis Antoniou
2016-06-10 14:28         ` [U-Boot] " Pantelis Antoniou
     [not found]         ` <34997AD3-B621-4823-920E-22E4A6F0E0D1-OWPKS81ov/FWk0Htik3J/w@public.gmane.org>
2016-06-13  9:51           ` Maxime Ripard [this message]
2016-06-13  9:51             ` Maxime Ripard
2016-06-14  0:25           ` David Gibson
2016-06-14  0:25             ` [U-Boot] " David Gibson
     [not found]             ` <20160614002550.GA4882-RXTfZT5YzpxwFLYp8hBm2A@public.gmane.org>
2016-06-14  9:22               ` Pantelis Antoniou
2016-06-14  9:22                 ` [U-Boot] " Pantelis Antoniou
     [not found]                 ` <F0B62E6A-D5CE-4505-BC19-5EAB72A33ADE-OWPKS81ov/FWk0Htik3J/w@public.gmane.org>
2016-06-15  3:14                   ` David Gibson
2016-06-15  3:14                     ` [U-Boot] " David Gibson
2016-06-15  9:34                     ` Pantelis Antoniou
2016-06-15  9:34                       ` [U-Boot] " Pantelis Antoniou
     [not found]                       ` <7E8A7CBD-D682-45E5-AD2C-19F137E5ED38-OWPKS81ov/FWk0Htik3J/w@public.gmane.org>
2016-06-15 10:19                         ` David Gibson
2016-06-15 10:19                           ` [U-Boot] " David Gibson
2016-06-15 10:23                           ` Pantelis Antoniou
2016-06-15 10:23                             ` [U-Boot] " Pantelis Antoniou
     [not found]                             ` <F67FB562-88F6-4B3A-8952-ACA38AAC9256-OWPKS81ov/FWk0Htik3J/w@public.gmane.org>
2016-06-15 14:49                               ` Warner Losh
2016-06-15 14:49                                 ` [U-Boot] " Warner Losh
2016-05-27  9:13   ` [PATCH v2 8/9] cmd: fdt: add fdt overlay application subcommand Maxime Ripard
2016-05-27  9:13     ` [U-Boot] " Maxime Ripard
     [not found]     ` <1464340402-2249-9-git-send-email-maxime.ripard-wi1+55ScJUtKEb57/3fJTNBPR1lH4CV8@public.gmane.org>
2016-06-10  0:34       ` Simon Glass
2016-06-10  0:34         ` [U-Boot] " Simon Glass
2016-06-10  3:45       ` Stefan Agner
2016-06-10  3:45         ` [U-Boot] " Stefan Agner
2016-06-10 13:56       ` Pantelis Antoniou
2016-06-10 13:56         ` [U-Boot] " Pantelis Antoniou
2016-05-27  9:13   ` [PATCH v2 9/9] tests: Introduce DT overlay tests Maxime Ripard
2016-05-27  9:13     ` [U-Boot] " Maxime Ripard
     [not found]     ` <1464340402-2249-10-git-send-email-maxime.ripard-wi1+55ScJUtKEb57/3fJTNBPR1lH4CV8@public.gmane.org>
2016-06-10  0:34       ` Simon Glass
2016-06-10  0:34         ` [U-Boot] " Simon Glass
2016-06-10 15:20       ` Pantelis Antoniou
2016-06-10 15:20         ` [U-Boot] " Pantelis Antoniou

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=20160613095150.GG4481@lukather \
    --to=maxime.ripard-wi1+55scjutkeb57/3fjtnbpr1lh4cv8@public.gmane.org \
    --cc=alex-MflLfwwFzuz+yO7R74ARew@public.gmane.org \
    --cc=antoine.tenart-wi1+55ScJUtKEb57/3fJTNBPR1lH4CV8@public.gmane.org \
    --cc=boris.brezillon-wi1+55ScJUtKEb57/3fJTNBPR1lH4CV8@public.gmane.org \
    --cc=devicetree-compiler-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=hdegoede-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org \
    --cc=pantelis.antoniou-OWPKS81ov/FWk0Htik3J/w@public.gmane.org \
    --cc=sjg-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org \
    --cc=stefan-XLVq0VzYD2Y@public.gmane.org \
    --cc=thomas.petazzoni-wi1+55ScJUtKEb57/3fJTNBPR1lH4CV8@public.gmane.org \
    --cc=trini-OWPKS81ov/FWk0Htik3J/w@public.gmane.org \
    --cc=u-boot-0aAXYlwwYIKGBzrmiIFOJg@public.gmane.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.