diff mbox series

[v7] fdt: Allow the devicetree to come from a bloblist

Message ID 20240104014919.413568-1-sjg@chromium.org
State Accepted
Commit 70fe23859437ffe4efe0793423937d8b78ebf9d6
Delegated to: Simon Glass
Headers show
Series [v7] fdt: Allow the devicetree to come from a bloblist | expand

Commit Message

Simon Glass Jan. 4, 2024, 1:49 a.m. UTC
Standard passage provides for a bloblist to be passed from one firmware
phase to the next. That can be used to pass the devicetree along as well.
Add an option to support this.

Tests for this will be added as part of the Universal Payload work.

Signed-off-by: Simon Glass <sjg@chromium.org>
---
The discussion on this was not resolved and is now important due to the
bloblist series from Raymond. So I am sending it again since I believe
this is a better starting point than building on OF_BOARD

Changes in v7:
- Drop use of OF_BLOBLIST

Changes in v6:
- Don't allow bloblist with OF_EMBED

Changes in v5:
- Make OF_BLOBLIST default y
- Make OF_BLOBLIST optional at runtime

Changes in v4:
- Rebase to -next

 doc/develop/devicetree/control.rst |  3 ++
 include/fdtdec.h                   |  6 ++--
 lib/fdtdec.c                       | 44 +++++++++++++++++++++++-------
 3 files changed, 41 insertions(+), 12 deletions(-)

Comments

Tom Rini Jan. 4, 2024, 1:51 p.m. UTC | #1
On Wed, Jan 03, 2024 at 06:49:19PM -0700, Simon Glass wrote:

> Standard passage provides for a bloblist to be passed from one firmware
> phase to the next. That can be used to pass the devicetree along as well.
> Add an option to support this.
> 
> Tests for this will be added as part of the Universal Payload work.
> 
> Signed-off-by: Simon Glass <sjg@chromium.org>

Thanks for reworking this.

Reviewed-by: Tom Rini <trini@konsulko.com>
Ilias Apalodimas Jan. 4, 2024, 2:24 p.m. UTC | #2
On Thu, 4 Jan 2024 at 03:49, Simon Glass <sjg@chromium.org> wrote:
>
> Standard passage provides for a bloblist to be passed from one firmware
> phase to the next. That can be used to pass the devicetree along as well.
> Add an option to support this.
>
> Tests for this will be added as part of the Universal Payload work.
>
> Signed-off-by: Simon Glass <sjg@chromium.org>
> ---
> The discussion on this was not resolved and is now important due to the
> bloblist series from Raymond. So I am sending it again since I believe
> this is a better starting point than building on OF_BOARD
>
> Changes in v7:
> - Drop use of OF_BLOBLIST
>
> Changes in v6:
> - Don't allow bloblist with OF_EMBED
>
> Changes in v5:
> - Make OF_BLOBLIST default y
> - Make OF_BLOBLIST optional at runtime
>
> Changes in v4:
> - Rebase to -next
>
>  doc/develop/devicetree/control.rst |  3 ++
>  include/fdtdec.h                   |  6 ++--
>  lib/fdtdec.c                       | 44 +++++++++++++++++++++++-------
>  3 files changed, 41 insertions(+), 12 deletions(-)
>
> diff --git a/doc/develop/devicetree/control.rst b/doc/develop/devicetree/control.rst
> index cbb65c9b177..11c92d440f4 100644
> --- a/doc/develop/devicetree/control.rst
> +++ b/doc/develop/devicetree/control.rst
> @@ -108,6 +108,9 @@ If CONFIG_OF_BOARD is defined, a board-specific routine will provide the
>  devicetree at runtime, for example if an earlier bootloader stage creates
>  it and passes it to U-Boot.
>
> +If CONFIG_BLOBLIST is defined, the devicetree may come from a bloblist passed
> +from a previous stage, if present.
> +
>  If CONFIG_SANDBOX is defined, then it will be read from a file on
>  startup. Use the -d flag to U-Boot to specify the file to read, -D for the
>  default and -T for the test devicetree, used to run sandbox unit tests.
> diff --git a/include/fdtdec.h b/include/fdtdec.h
> index bd1149f46d0..e80de24076c 100644
> --- a/include/fdtdec.h
> +++ b/include/fdtdec.h
> @@ -72,7 +72,7 @@ struct bd_info;
>   *     U-Boot is packaged as an ELF file, e.g. for debugging purposes
>   * @FDTSRC_ENV: Provided by the fdtcontroladdr environment variable. This should
>   *     be used for debugging/development only
> - * @FDTSRC_NONE: No devicetree at all
> + * @FDTSRC_BLOBLIST: Provided by a bloblist from an earlier phase
>   */
>  enum fdt_source_t {
>         FDTSRC_SEPARATE,
> @@ -80,6 +80,7 @@ enum fdt_source_t {
>         FDTSRC_BOARD,
>         FDTSRC_EMBED,
>         FDTSRC_ENV,
> +       FDTSRC_BLOBLIST,
>  };
>
>  /*
> @@ -1190,7 +1191,8 @@ int fdtdec_resetup(int *rescan);
>   *
>   * The existing devicetree is available at gd->fdt_blob
>   *
> - * @err internal error code if we fail to setup a DTB
> + * @err: 0 on success, -EEXIST if the devicetree is already correct, or other
> + * internal error code if we fail to setup a DTB
>   * @returns new devicetree blob pointer
>   */
>  void *board_fdt_blob_setup(int *err);
> diff --git a/lib/fdtdec.c b/lib/fdtdec.c
> index 4016bf3c113..b2c59ab3818 100644
> --- a/lib/fdtdec.c
> +++ b/lib/fdtdec.c
> @@ -7,6 +7,10 @@
>   */
>
>  #ifndef USE_HOSTCC
> +
> +#define LOG_CATEGORY   LOGC_DT
> +
> +#include <bloblist.h>
>  #include <boot_fit.h>
>  #include <display_options.h>
>  #include <dm.h>
> @@ -86,6 +90,7 @@ static const char *const fdt_src_name[] = {
>         [FDTSRC_BOARD] = "board",
>         [FDTSRC_EMBED] = "embed",
>         [FDTSRC_ENV] = "env",
> +       [FDTSRC_BLOBLIST] = "bloblist",
>  };
>
>  const char *fdtdec_get_srcname(void)
> @@ -1662,23 +1667,42 @@ static void setup_multi_dtb_fit(void)
>
>  int fdtdec_setup(void)
>  {
> -       int ret;
> +       int ret = -ENOENT;
> +
> +       /* If allowing a bloblist, check that first */
> +       if (CONFIG_IS_ENABLED(BLOBLIST)) {
> +               ret = bloblist_maybe_init();
> +               if (!ret) {
> +                       gd->fdt_blob = bloblist_find(BLOBLISTT_CONTROL_FDT, 0);
> +                       if (gd->fdt_blob) {
> +                               gd->fdt_src = FDTSRC_BLOBLIST;
> +                               log_debug("Devicetree is in bloblist at %p\n",
> +                                         gd->fdt_blob);
> +                       } else {
> +                               log_debug("No FDT found in bloblist\n");
> +                               ret = -ENOENT;
> +                       }
> +               }
> +       }
>
> -       /* The devicetree is typically appended to U-Boot */
> -       if (IS_ENABLED(CONFIG_OF_SEPARATE)) {
> -               gd->fdt_blob = fdt_find_separate();
> -               gd->fdt_src = FDTSRC_SEPARATE;
> -       } else { /* embed dtb in ELF file for testing / development */
> -               gd->fdt_blob = dtb_dt_embedded();
> -               gd->fdt_src = FDTSRC_EMBED;
> +       /* Otherwise, the devicetree is typically appended to U-Boot */
> +       if (ret) {
> +               if (IS_ENABLED(CONFIG_OF_SEPARATE)) {
> +                       gd->fdt_blob = fdt_find_separate();
> +                       gd->fdt_src = FDTSRC_SEPARATE;
> +               } else { /* embed dtb in ELF file for testing / development */
> +                       gd->fdt_blob = dtb_dt_embedded();
> +                       gd->fdt_src = FDTSRC_EMBED;
> +               }
>         }
>
>         /* Allow the board to override the fdt address. */
>         if (IS_ENABLED(CONFIG_OF_BOARD)) {
>                 gd->fdt_blob = board_fdt_blob_setup(&ret);
> -               if (ret)
> +               if (!ret)
> +                       gd->fdt_src = FDTSRC_BOARD;
> +               else if (ret != -EEXIST)
>                         return ret;
> -               gd->fdt_src = FDTSRC_BOARD;
>         }
>
>         /* Allow the early environment to override the fdt address */
> --
> 2.34.1
>

Thanks Simon
Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Simon Glass Jan. 8, 2024, 12:16 a.m. UTC | #3
On Thu, 4 Jan 2024 at 03:49, Simon Glass <sjg@chromium.org> wrote:
>
> Standard passage provides for a bloblist to be passed from one firmware
> phase to the next. That can be used to pass the devicetree along as well.
> Add an option to support this.
>
> Tests for this will be added as part of the Universal Payload work.
>
> Signed-off-by: Simon Glass <sjg@chromium.org>
> ---
> The discussion on this was not resolved and is now important due to the
> bloblist series from Raymond. So I am sending it again since I believe
> this is a better starting point than building on OF_BOARD
>
> Changes in v7:
> - Drop use of OF_BLOBLIST
>
> Changes in v6:
> - Don't allow bloblist with OF_EMBED
>
> Changes in v5:
> - Make OF_BLOBLIST default y
> - Make OF_BLOBLIST optional at runtime
>
> Changes in v4:
> - Rebase to -next
>
>  doc/develop/devicetree/control.rst |  3 ++
>  include/fdtdec.h                   |  6 ++--
>  lib/fdtdec.c                       | 44 +++++++++++++++++++++++-------
>  3 files changed, 41 insertions(+), 12 deletions(-)
>
Applied to u-boot-dm/next, thanks!
Conor Dooley Jan. 16, 2024, 1:48 p.m. UTC | #4
Yo,

On Wed, Jan 03, 2024 at 06:49:19PM -0700, Simon Glass wrote:
> Standard passage provides for a bloblist to be passed from one firmware
> phase to the next. That can be used to pass the devicetree along as well.
> Add an option to support this.
> 
> Tests for this will be added as part of the Universal Payload work.
> 
> Signed-off-by: Simon Glass <sjg@chromium.org>

Since this was merged into master, U-Boot is no longer booting on my
icicle kit (At least that's what my bisection tells me). This is a
RISC-V board and U-Boot for it is built from
microchip_mpfs_icicle_defconfig.

There's zero output on the console from U-Boot at all, the last thing
that I see is OpenSBI before things grind to a halt.

Thanks,
Conor.


> ---
> The discussion on this was not resolved and is now important due to the
> bloblist series from Raymond. So I am sending it again since I believe
> this is a better starting point than building on OF_BOARD
> 
> Changes in v7:
> - Drop use of OF_BLOBLIST
> 
> Changes in v6:
> - Don't allow bloblist with OF_EMBED
> 
> Changes in v5:
> - Make OF_BLOBLIST default y
> - Make OF_BLOBLIST optional at runtime
> 
> Changes in v4:
> - Rebase to -next
> 
>  doc/develop/devicetree/control.rst |  3 ++
>  include/fdtdec.h                   |  6 ++--
>  lib/fdtdec.c                       | 44 +++++++++++++++++++++++-------
>  3 files changed, 41 insertions(+), 12 deletions(-)
> 
> diff --git a/doc/develop/devicetree/control.rst b/doc/develop/devicetree/control.rst
> index cbb65c9b177..11c92d440f4 100644
> --- a/doc/develop/devicetree/control.rst
> +++ b/doc/develop/devicetree/control.rst
> @@ -108,6 +108,9 @@ If CONFIG_OF_BOARD is defined, a board-specific routine will provide the
>  devicetree at runtime, for example if an earlier bootloader stage creates
>  it and passes it to U-Boot.
>  
> +If CONFIG_BLOBLIST is defined, the devicetree may come from a bloblist passed
> +from a previous stage, if present.
> +
>  If CONFIG_SANDBOX is defined, then it will be read from a file on
>  startup. Use the -d flag to U-Boot to specify the file to read, -D for the
>  default and -T for the test devicetree, used to run sandbox unit tests.
> diff --git a/include/fdtdec.h b/include/fdtdec.h
> index bd1149f46d0..e80de24076c 100644
> --- a/include/fdtdec.h
> +++ b/include/fdtdec.h
> @@ -72,7 +72,7 @@ struct bd_info;
>   *	U-Boot is packaged as an ELF file, e.g. for debugging purposes
>   * @FDTSRC_ENV: Provided by the fdtcontroladdr environment variable. This should
>   *	be used for debugging/development only
> - * @FDTSRC_NONE: No devicetree at all
> + * @FDTSRC_BLOBLIST: Provided by a bloblist from an earlier phase
>   */
>  enum fdt_source_t {
>  	FDTSRC_SEPARATE,
> @@ -80,6 +80,7 @@ enum fdt_source_t {
>  	FDTSRC_BOARD,
>  	FDTSRC_EMBED,
>  	FDTSRC_ENV,
> +	FDTSRC_BLOBLIST,
>  };
>  
>  /*
> @@ -1190,7 +1191,8 @@ int fdtdec_resetup(int *rescan);
>   *
>   * The existing devicetree is available at gd->fdt_blob
>   *
> - * @err internal error code if we fail to setup a DTB
> + * @err: 0 on success, -EEXIST if the devicetree is already correct, or other
> + * internal error code if we fail to setup a DTB
>   * @returns new devicetree blob pointer
>   */
>  void *board_fdt_blob_setup(int *err);
> diff --git a/lib/fdtdec.c b/lib/fdtdec.c
> index 4016bf3c113..b2c59ab3818 100644
> --- a/lib/fdtdec.c
> +++ b/lib/fdtdec.c
> @@ -7,6 +7,10 @@
>   */
>  
>  #ifndef USE_HOSTCC
> +
> +#define LOG_CATEGORY	LOGC_DT
> +
> +#include <bloblist.h>
>  #include <boot_fit.h>
>  #include <display_options.h>
>  #include <dm.h>
> @@ -86,6 +90,7 @@ static const char *const fdt_src_name[] = {
>  	[FDTSRC_BOARD] = "board",
>  	[FDTSRC_EMBED] = "embed",
>  	[FDTSRC_ENV] = "env",
> +	[FDTSRC_BLOBLIST] = "bloblist",
>  };
>  
>  const char *fdtdec_get_srcname(void)
> @@ -1662,23 +1667,42 @@ static void setup_multi_dtb_fit(void)
>  
>  int fdtdec_setup(void)
>  {
> -	int ret;
> +	int ret = -ENOENT;
> +
> +	/* If allowing a bloblist, check that first */
> +	if (CONFIG_IS_ENABLED(BLOBLIST)) {
> +		ret = bloblist_maybe_init();
> +		if (!ret) {
> +			gd->fdt_blob = bloblist_find(BLOBLISTT_CONTROL_FDT, 0);
> +			if (gd->fdt_blob) {
> +				gd->fdt_src = FDTSRC_BLOBLIST;
> +				log_debug("Devicetree is in bloblist at %p\n",
> +					  gd->fdt_blob);
> +			} else {
> +				log_debug("No FDT found in bloblist\n");
> +				ret = -ENOENT;
> +			}
> +		}
> +	}
>  
> -	/* The devicetree is typically appended to U-Boot */
> -	if (IS_ENABLED(CONFIG_OF_SEPARATE)) {
> -		gd->fdt_blob = fdt_find_separate();
> -		gd->fdt_src = FDTSRC_SEPARATE;
> -	} else { /* embed dtb in ELF file for testing / development */
> -		gd->fdt_blob = dtb_dt_embedded();
> -		gd->fdt_src = FDTSRC_EMBED;
> +	/* Otherwise, the devicetree is typically appended to U-Boot */
> +	if (ret) {
> +		if (IS_ENABLED(CONFIG_OF_SEPARATE)) {
> +			gd->fdt_blob = fdt_find_separate();
> +			gd->fdt_src = FDTSRC_SEPARATE;
> +		} else { /* embed dtb in ELF file for testing / development */
> +			gd->fdt_blob = dtb_dt_embedded();
> +			gd->fdt_src = FDTSRC_EMBED;
> +		}
>  	}
>  
>  	/* Allow the board to override the fdt address. */
>  	if (IS_ENABLED(CONFIG_OF_BOARD)) {
>  		gd->fdt_blob = board_fdt_blob_setup(&ret);
> -		if (ret)
> +		if (!ret)
> +			gd->fdt_src = FDTSRC_BOARD;
> +		else if (ret != -EEXIST)
>  			return ret;
> -		gd->fdt_src = FDTSRC_BOARD;
>  	}
>  
>  	/* Allow the early environment to override the fdt address */
> -- 
> 2.34.1
>
Conor Dooley Jan. 22, 2024, 6:36 p.m. UTC | #5
Hey,

On Tue, Jan 16, 2024 at 01:48:06PM +0000, Conor Dooley wrote:
> Yo,
> 
> On Wed, Jan 03, 2024 at 06:49:19PM -0700, Simon Glass wrote:
> > Standard passage provides for a bloblist to be passed from one firmware
> > phase to the next. That can be used to pass the devicetree along as well.
> > Add an option to support this.
> > 
> > Tests for this will be added as part of the Universal Payload work.
> > 
> > Signed-off-by: Simon Glass <sjg@chromium.org>
> 
> Since this was merged into master, U-Boot is no longer booting on my
> icicle kit (At least that's what my bisection tells me). This is a
> RISC-V board and U-Boot for it is built from
> microchip_mpfs_icicle_defconfig.
> 
> There's zero output on the console from U-Boot at all, the last thing
> that I see is OpenSBI before things grind to a halt.

Just wondering if there's anything I can do to help this one along?
Got a red CI complaining at me every morning about it :|

> 
> Thanks,
> Conor.
> 
> 
> > ---
> > The discussion on this was not resolved and is now important due to the
> > bloblist series from Raymond. So I am sending it again since I believe
> > this is a better starting point than building on OF_BOARD
> > 
> > Changes in v7:
> > - Drop use of OF_BLOBLIST
> > 
> > Changes in v6:
> > - Don't allow bloblist with OF_EMBED
> > 
> > Changes in v5:
> > - Make OF_BLOBLIST default y
> > - Make OF_BLOBLIST optional at runtime
> > 
> > Changes in v4:
> > - Rebase to -next
> > 
> >  doc/develop/devicetree/control.rst |  3 ++
> >  include/fdtdec.h                   |  6 ++--
> >  lib/fdtdec.c                       | 44 +++++++++++++++++++++++-------
> >  3 files changed, 41 insertions(+), 12 deletions(-)
> > 
> > diff --git a/doc/develop/devicetree/control.rst b/doc/develop/devicetree/control.rst
> > index cbb65c9b177..11c92d440f4 100644
> > --- a/doc/develop/devicetree/control.rst
> > +++ b/doc/develop/devicetree/control.rst
> > @@ -108,6 +108,9 @@ If CONFIG_OF_BOARD is defined, a board-specific routine will provide the
> >  devicetree at runtime, for example if an earlier bootloader stage creates
> >  it and passes it to U-Boot.
> >  
> > +If CONFIG_BLOBLIST is defined, the devicetree may come from a bloblist passed
> > +from a previous stage, if present.
> > +
> >  If CONFIG_SANDBOX is defined, then it will be read from a file on
> >  startup. Use the -d flag to U-Boot to specify the file to read, -D for the
> >  default and -T for the test devicetree, used to run sandbox unit tests.
> > diff --git a/include/fdtdec.h b/include/fdtdec.h
> > index bd1149f46d0..e80de24076c 100644
> > --- a/include/fdtdec.h
> > +++ b/include/fdtdec.h
> > @@ -72,7 +72,7 @@ struct bd_info;
> >   *	U-Boot is packaged as an ELF file, e.g. for debugging purposes
> >   * @FDTSRC_ENV: Provided by the fdtcontroladdr environment variable. This should
> >   *	be used for debugging/development only
> > - * @FDTSRC_NONE: No devicetree at all
> > + * @FDTSRC_BLOBLIST: Provided by a bloblist from an earlier phase
> >   */
> >  enum fdt_source_t {
> >  	FDTSRC_SEPARATE,
> > @@ -80,6 +80,7 @@ enum fdt_source_t {
> >  	FDTSRC_BOARD,
> >  	FDTSRC_EMBED,
> >  	FDTSRC_ENV,
> > +	FDTSRC_BLOBLIST,
> >  };
> >  
> >  /*
> > @@ -1190,7 +1191,8 @@ int fdtdec_resetup(int *rescan);
> >   *
> >   * The existing devicetree is available at gd->fdt_blob
> >   *
> > - * @err internal error code if we fail to setup a DTB
> > + * @err: 0 on success, -EEXIST if the devicetree is already correct, or other
> > + * internal error code if we fail to setup a DTB
> >   * @returns new devicetree blob pointer
> >   */
> >  void *board_fdt_blob_setup(int *err);
> > diff --git a/lib/fdtdec.c b/lib/fdtdec.c
> > index 4016bf3c113..b2c59ab3818 100644
> > --- a/lib/fdtdec.c
> > +++ b/lib/fdtdec.c
> > @@ -7,6 +7,10 @@
> >   */
> >  
> >  #ifndef USE_HOSTCC
> > +
> > +#define LOG_CATEGORY	LOGC_DT
> > +
> > +#include <bloblist.h>
> >  #include <boot_fit.h>
> >  #include <display_options.h>
> >  #include <dm.h>
> > @@ -86,6 +90,7 @@ static const char *const fdt_src_name[] = {
> >  	[FDTSRC_BOARD] = "board",
> >  	[FDTSRC_EMBED] = "embed",
> >  	[FDTSRC_ENV] = "env",
> > +	[FDTSRC_BLOBLIST] = "bloblist",
> >  };
> >  
> >  const char *fdtdec_get_srcname(void)
> > @@ -1662,23 +1667,42 @@ static void setup_multi_dtb_fit(void)
> >  
> >  int fdtdec_setup(void)
> >  {
> > -	int ret;
> > +	int ret = -ENOENT;
> > +
> > +	/* If allowing a bloblist, check that first */
> > +	if (CONFIG_IS_ENABLED(BLOBLIST)) {
> > +		ret = bloblist_maybe_init();
> > +		if (!ret) {
> > +			gd->fdt_blob = bloblist_find(BLOBLISTT_CONTROL_FDT, 0);
> > +			if (gd->fdt_blob) {
> > +				gd->fdt_src = FDTSRC_BLOBLIST;
> > +				log_debug("Devicetree is in bloblist at %p\n",
> > +					  gd->fdt_blob);
> > +			} else {
> > +				log_debug("No FDT found in bloblist\n");
> > +				ret = -ENOENT;
> > +			}
> > +		}
> > +	}
> >  
> > -	/* The devicetree is typically appended to U-Boot */
> > -	if (IS_ENABLED(CONFIG_OF_SEPARATE)) {
> > -		gd->fdt_blob = fdt_find_separate();
> > -		gd->fdt_src = FDTSRC_SEPARATE;
> > -	} else { /* embed dtb in ELF file for testing / development */
> > -		gd->fdt_blob = dtb_dt_embedded();
> > -		gd->fdt_src = FDTSRC_EMBED;
> > +	/* Otherwise, the devicetree is typically appended to U-Boot */
> > +	if (ret) {
> > +		if (IS_ENABLED(CONFIG_OF_SEPARATE)) {
> > +			gd->fdt_blob = fdt_find_separate();
> > +			gd->fdt_src = FDTSRC_SEPARATE;
> > +		} else { /* embed dtb in ELF file for testing / development */
> > +			gd->fdt_blob = dtb_dt_embedded();
> > +			gd->fdt_src = FDTSRC_EMBED;
> > +		}
> >  	}
> >  
> >  	/* Allow the board to override the fdt address. */
> >  	if (IS_ENABLED(CONFIG_OF_BOARD)) {
> >  		gd->fdt_blob = board_fdt_blob_setup(&ret);
> > -		if (ret)
> > +		if (!ret)
> > +			gd->fdt_src = FDTSRC_BOARD;
> > +		else if (ret != -EEXIST)
> >  			return ret;
> > -		gd->fdt_src = FDTSRC_BOARD;
> >  	}
> >  
> >  	/* Allow the early environment to override the fdt address */
> > -- 
> > 2.34.1
> >
Tom Rini Jan. 22, 2024, 6:47 p.m. UTC | #6
On Mon, Jan 22, 2024 at 06:36:31PM +0000, Conor Dooley wrote:
> Hey,
> 
> On Tue, Jan 16, 2024 at 01:48:06PM +0000, Conor Dooley wrote:
> > Yo,
> > 
> > On Wed, Jan 03, 2024 at 06:49:19PM -0700, Simon Glass wrote:
> > > Standard passage provides for a bloblist to be passed from one firmware
> > > phase to the next. That can be used to pass the devicetree along as well.
> > > Add an option to support this.
> > > 
> > > Tests for this will be added as part of the Universal Payload work.
> > > 
> > > Signed-off-by: Simon Glass <sjg@chromium.org>
> > 
> > Since this was merged into master, U-Boot is no longer booting on my
> > icicle kit (At least that's what my bisection tells me). This is a
> > RISC-V board and U-Boot for it is built from
> > microchip_mpfs_icicle_defconfig.
> > 
> > There's zero output on the console from U-Boot at all, the last thing
> > that I see is OpenSBI before things grind to a halt.
> 
> Just wondering if there's anything I can do to help this one along?
> Got a red CI complaining at me every morning about it :|

Well, can you please look in to what part of this is causing the
failure? I don't really see what would have changed on
microchip_mpfs_icicle_defconfig from this as BLOBLIST isn't set before
nor after this change.
Conor Dooley Jan. 22, 2024, 6:55 p.m. UTC | #7
On Mon, Jan 22, 2024 at 01:47:17PM -0500, Tom Rini wrote:
> On Mon, Jan 22, 2024 at 06:36:31PM +0000, Conor Dooley wrote:
> > Hey,
> > 
> > On Tue, Jan 16, 2024 at 01:48:06PM +0000, Conor Dooley wrote:
> > > Yo,
> > > 
> > > On Wed, Jan 03, 2024 at 06:49:19PM -0700, Simon Glass wrote:
> > > > Standard passage provides for a bloblist to be passed from one firmware
> > > > phase to the next. That can be used to pass the devicetree along as well.
> > > > Add an option to support this.
> > > > 
> > > > Tests for this will be added as part of the Universal Payload work.
> > > > 
> > > > Signed-off-by: Simon Glass <sjg@chromium.org>
> > > 
> > > Since this was merged into master, U-Boot is no longer booting on my
> > > icicle kit (At least that's what my bisection tells me). This is a
> > > RISC-V board and U-Boot for it is built from
> > > microchip_mpfs_icicle_defconfig.
> > > 
> > > There's zero output on the console from U-Boot at all, the last thing
> > > that I see is OpenSBI before things grind to a halt.
> > 
> > Just wondering if there's anything I can do to help this one along?
> > Got a red CI complaining at me every morning about it :|
> 
> Well, can you please look in to what part of this is causing the
> failure? I don't really see what would have changed on
> microchip_mpfs_icicle_defconfig from this as BLOBLIST isn't set before
> nor after this change.

Sure. I'll try to look into it more tomorrow.
Conor Dooley Jan. 23, 2024, 11:27 a.m. UTC | #8
On Mon, Jan 22, 2024 at 06:55:01PM +0000, Conor Dooley wrote:
> On Mon, Jan 22, 2024 at 01:47:17PM -0500, Tom Rini wrote:
> > On Mon, Jan 22, 2024 at 06:36:31PM +0000, Conor Dooley wrote:
> > > Hey,
> > > 
> > > On Tue, Jan 16, 2024 at 01:48:06PM +0000, Conor Dooley wrote:
> > > > Yo,
> > > > 
> > > > On Wed, Jan 03, 2024 at 06:49:19PM -0700, Simon Glass wrote:
> > > > > Standard passage provides for a bloblist to be passed from one firmware
> > > > > phase to the next. That can be used to pass the devicetree along as well.
> > > > > Add an option to support this.
> > > > > 
> > > > > Tests for this will be added as part of the Universal Payload work.
> > > > > 
> > > > > Signed-off-by: Simon Glass <sjg@chromium.org>
> > > > 
> > > > Since this was merged into master, U-Boot is no longer booting on my
> > > > icicle kit (At least that's what my bisection tells me). This is a
> > > > RISC-V board and U-Boot for it is built from
> > > > microchip_mpfs_icicle_defconfig.
> > > > 
> > > > There's zero output on the console from U-Boot at all, the last thing
> > > > that I see is OpenSBI before things grind to a halt.
> > > 
> > > Just wondering if there's anything I can do to help this one along?
> > > Got a red CI complaining at me every morning about it :|
> > 
> > Well, can you please look in to what part of this is causing the
> > failure? I don't really see what would have changed on
> > microchip_mpfs_icicle_defconfig from this as BLOBLIST isn't set before
> > nor after this change.
> 
> Sure. I'll try to look into it more tomorrow.

I gave it a try, it seems to be the FDTSRC_BLOBLIST additions that kill
it, not the actual code in fdtdec_setup().
Tom Rini Jan. 23, 2024, 6:03 p.m. UTC | #9
On Tue, Jan 23, 2024 at 11:27:57AM +0000, Conor Dooley wrote:
> On Mon, Jan 22, 2024 at 06:55:01PM +0000, Conor Dooley wrote:
> > On Mon, Jan 22, 2024 at 01:47:17PM -0500, Tom Rini wrote:
> > > On Mon, Jan 22, 2024 at 06:36:31PM +0000, Conor Dooley wrote:
> > > > Hey,
> > > > 
> > > > On Tue, Jan 16, 2024 at 01:48:06PM +0000, Conor Dooley wrote:
> > > > > Yo,
> > > > > 
> > > > > On Wed, Jan 03, 2024 at 06:49:19PM -0700, Simon Glass wrote:
> > > > > > Standard passage provides for a bloblist to be passed from one firmware
> > > > > > phase to the next. That can be used to pass the devicetree along as well.
> > > > > > Add an option to support this.
> > > > > > 
> > > > > > Tests for this will be added as part of the Universal Payload work.
> > > > > > 
> > > > > > Signed-off-by: Simon Glass <sjg@chromium.org>
> > > > > 
> > > > > Since this was merged into master, U-Boot is no longer booting on my
> > > > > icicle kit (At least that's what my bisection tells me). This is a
> > > > > RISC-V board and U-Boot for it is built from
> > > > > microchip_mpfs_icicle_defconfig.
> > > > > 
> > > > > There's zero output on the console from U-Boot at all, the last thing
> > > > > that I see is OpenSBI before things grind to a halt.
> > > > 
> > > > Just wondering if there's anything I can do to help this one along?
> > > > Got a red CI complaining at me every morning about it :|
> > > 
> > > Well, can you please look in to what part of this is causing the
> > > failure? I don't really see what would have changed on
> > > microchip_mpfs_icicle_defconfig from this as BLOBLIST isn't set before
> > > nor after this change.
> > 
> > Sure. I'll try to look into it more tomorrow.
> 
> I gave it a try, it seems to be the FDTSRC_BLOBLIST additions that kill
> it, not the actual code in fdtdec_setup().

Well that's very unexpected. Can you see what boundary we're crossing or
whatever has overflowed now or something on your platform?
Conor Dooley Feb. 6, 2024, 5:20 p.m. UTC | #10
On Tue, Jan 23, 2024 at 01:03:00PM -0500, Tom Rini wrote:
> On Tue, Jan 23, 2024 at 11:27:57AM +0000, Conor Dooley wrote:
> > On Mon, Jan 22, 2024 at 06:55:01PM +0000, Conor Dooley wrote:
> > > On Mon, Jan 22, 2024 at 01:47:17PM -0500, Tom Rini wrote:
> > > > On Mon, Jan 22, 2024 at 06:36:31PM +0000, Conor Dooley wrote:
> > > > > Hey,
> > > > > 
> > > > > On Tue, Jan 16, 2024 at 01:48:06PM +0000, Conor Dooley wrote:
> > > > > > Yo,
> > > > > > 
> > > > > > On Wed, Jan 03, 2024 at 06:49:19PM -0700, Simon Glass wrote:
> > > > > > > Standard passage provides for a bloblist to be passed from one firmware
> > > > > > > phase to the next. That can be used to pass the devicetree along as well.
> > > > > > > Add an option to support this.
> > > > > > > 
> > > > > > > Tests for this will be added as part of the Universal Payload work.
> > > > > > > 
> > > > > > > Signed-off-by: Simon Glass <sjg@chromium.org>
> > > > > > 
> > > > > > Since this was merged into master, U-Boot is no longer booting on my
> > > > > > icicle kit (At least that's what my bisection tells me). This is a
> > > > > > RISC-V board and U-Boot for it is built from
> > > > > > microchip_mpfs_icicle_defconfig.
> > > > > > 
> > > > > > There's zero output on the console from U-Boot at all, the last thing
> > > > > > that I see is OpenSBI before things grind to a halt.
> > > > > 
> > > > > Just wondering if there's anything I can do to help this one along?
> > > > > Got a red CI complaining at me every morning about it :|
> > > > 
> > > > Well, can you please look in to what part of this is causing the
> > > > failure? I don't really see what would have changed on
> > > > microchip_mpfs_icicle_defconfig from this as BLOBLIST isn't set before
> > > > nor after this change.
> > > 
> > > Sure. I'll try to look into it more tomorrow.
> > 
> > I gave it a try, it seems to be the FDTSRC_BLOBLIST additions that kill
> > it, not the actual code in fdtdec_setup().
> 
> Well that's very unexpected. Can you see what boundary we're crossing or
> whatever has overflowed now or something on your platform?

And you know what else was not expected? The issue randomly disappearing
a few days after I sent this email. Or maybe that should be expected
given how the issue actually cropped up in the first place.
I didn't have a chance yet to see how this particular patch may have
interacted with the sections etc, but looking into it is still on my
todo list, just much lower down now that things actually boot again for
me...

Thanks,
Conor.
diff mbox series

Patch

diff --git a/doc/develop/devicetree/control.rst b/doc/develop/devicetree/control.rst
index cbb65c9b177..11c92d440f4 100644
--- a/doc/develop/devicetree/control.rst
+++ b/doc/develop/devicetree/control.rst
@@ -108,6 +108,9 @@  If CONFIG_OF_BOARD is defined, a board-specific routine will provide the
 devicetree at runtime, for example if an earlier bootloader stage creates
 it and passes it to U-Boot.
 
+If CONFIG_BLOBLIST is defined, the devicetree may come from a bloblist passed
+from a previous stage, if present.
+
 If CONFIG_SANDBOX is defined, then it will be read from a file on
 startup. Use the -d flag to U-Boot to specify the file to read, -D for the
 default and -T for the test devicetree, used to run sandbox unit tests.
diff --git a/include/fdtdec.h b/include/fdtdec.h
index bd1149f46d0..e80de24076c 100644
--- a/include/fdtdec.h
+++ b/include/fdtdec.h
@@ -72,7 +72,7 @@  struct bd_info;
  *	U-Boot is packaged as an ELF file, e.g. for debugging purposes
  * @FDTSRC_ENV: Provided by the fdtcontroladdr environment variable. This should
  *	be used for debugging/development only
- * @FDTSRC_NONE: No devicetree at all
+ * @FDTSRC_BLOBLIST: Provided by a bloblist from an earlier phase
  */
 enum fdt_source_t {
 	FDTSRC_SEPARATE,
@@ -80,6 +80,7 @@  enum fdt_source_t {
 	FDTSRC_BOARD,
 	FDTSRC_EMBED,
 	FDTSRC_ENV,
+	FDTSRC_BLOBLIST,
 };
 
 /*
@@ -1190,7 +1191,8 @@  int fdtdec_resetup(int *rescan);
  *
  * The existing devicetree is available at gd->fdt_blob
  *
- * @err internal error code if we fail to setup a DTB
+ * @err: 0 on success, -EEXIST if the devicetree is already correct, or other
+ * internal error code if we fail to setup a DTB
  * @returns new devicetree blob pointer
  */
 void *board_fdt_blob_setup(int *err);
diff --git a/lib/fdtdec.c b/lib/fdtdec.c
index 4016bf3c113..b2c59ab3818 100644
--- a/lib/fdtdec.c
+++ b/lib/fdtdec.c
@@ -7,6 +7,10 @@ 
  */
 
 #ifndef USE_HOSTCC
+
+#define LOG_CATEGORY	LOGC_DT
+
+#include <bloblist.h>
 #include <boot_fit.h>
 #include <display_options.h>
 #include <dm.h>
@@ -86,6 +90,7 @@  static const char *const fdt_src_name[] = {
 	[FDTSRC_BOARD] = "board",
 	[FDTSRC_EMBED] = "embed",
 	[FDTSRC_ENV] = "env",
+	[FDTSRC_BLOBLIST] = "bloblist",
 };
 
 const char *fdtdec_get_srcname(void)
@@ -1662,23 +1667,42 @@  static void setup_multi_dtb_fit(void)
 
 int fdtdec_setup(void)
 {
-	int ret;
+	int ret = -ENOENT;
+
+	/* If allowing a bloblist, check that first */
+	if (CONFIG_IS_ENABLED(BLOBLIST)) {
+		ret = bloblist_maybe_init();
+		if (!ret) {
+			gd->fdt_blob = bloblist_find(BLOBLISTT_CONTROL_FDT, 0);
+			if (gd->fdt_blob) {
+				gd->fdt_src = FDTSRC_BLOBLIST;
+				log_debug("Devicetree is in bloblist at %p\n",
+					  gd->fdt_blob);
+			} else {
+				log_debug("No FDT found in bloblist\n");
+				ret = -ENOENT;
+			}
+		}
+	}
 
-	/* The devicetree is typically appended to U-Boot */
-	if (IS_ENABLED(CONFIG_OF_SEPARATE)) {
-		gd->fdt_blob = fdt_find_separate();
-		gd->fdt_src = FDTSRC_SEPARATE;
-	} else { /* embed dtb in ELF file for testing / development */
-		gd->fdt_blob = dtb_dt_embedded();
-		gd->fdt_src = FDTSRC_EMBED;
+	/* Otherwise, the devicetree is typically appended to U-Boot */
+	if (ret) {
+		if (IS_ENABLED(CONFIG_OF_SEPARATE)) {
+			gd->fdt_blob = fdt_find_separate();
+			gd->fdt_src = FDTSRC_SEPARATE;
+		} else { /* embed dtb in ELF file for testing / development */
+			gd->fdt_blob = dtb_dt_embedded();
+			gd->fdt_src = FDTSRC_EMBED;
+		}
 	}
 
 	/* Allow the board to override the fdt address. */
 	if (IS_ENABLED(CONFIG_OF_BOARD)) {
 		gd->fdt_blob = board_fdt_blob_setup(&ret);
-		if (ret)
+		if (!ret)
+			gd->fdt_src = FDTSRC_BOARD;
+		else if (ret != -EEXIST)
 			return ret;
-		gd->fdt_src = FDTSRC_BOARD;
 	}
 
 	/* Allow the early environment to override the fdt address */