Re: [PATCH 3/4] doc: codingstyle: Remove comment about '//' style comments

2022-06-30 Thread Simon Glass
On Mon, 27 Jun 2022 at 11:17, Tom Rini  wrote:
>
> For some time now we've allowed for '//' style comments, which mirrors
> the Linux kernel.  So drop this point here.
>
> Signed-off-by: Tom Rini 
> ---
>  doc/develop/codingstyle.rst | 5 -
>  1 file changed, 5 deletions(-)

Oh I didn't know that.

Reviewed-by: Simon Glass 


Re: [PATCH] board_init: Do not reserve MALLOC_F area on stack if non-zero MALLOC_F_ADDR

2022-06-30 Thread Simon Glass
Hi Marek,

On Sat, 25 Jun 2022 at 11:58, Marek Vasut  wrote:
>
> In case the MALLOC_F_ADDR is set to non-zero value, the early malloc area is
> not going to be placed just below stack top, but elsewhere. Do not reserve
> MALLOC_F bytes in this case, as that wastes stack space and may even cause
> insufficient stack space in SPL.
>
> This functionality is particularly useful on i.MX8M, where the insufficient
> stack space can be triggered.
>
> Signed-off-by: Marek Vasut 
> Cc: Albert ARIBAUD 
> Cc: Fabio Estevam 
> Cc: Peng Fan 
> Cc: Simon Glass 
> Cc: Stefano Babic 
> Cc: Thomas Chou 
> Cc: Tom Rini 
> ---
>  common/init/board_init.c | 2 ++
>  1 file changed, 2 insertions(+)

Please can you migrate the option to Kconfig first? I suspect that
will simplify the logic and avoid the #ifndef

>
> diff --git a/common/init/board_init.c b/common/init/board_init.c
> index eab5ee13953..6a550261778 100644
> --- a/common/init/board_init.c
> +++ b/common/init/board_init.c
> @@ -78,8 +78,10 @@ __weak void board_init_f_init_stack_protection(void)
>  ulong board_init_f_alloc_reserve(ulong top)
>  {
> /* Reserve early malloc arena */
> +#ifndef CONFIG_MALLOC_F_ADDR
>  #if CONFIG_VAL(SYS_MALLOC_F_LEN)
> top -= CONFIG_VAL(SYS_MALLOC_F_LEN);
> +#endif
>  #endif
> /* LAST : reserve GD (rounded up to a multiple of 16 bytes) */
> top = rounddown(top-sizeof(struct global_data), 16);
> --
> 2.35.1
>

Regards,
Simon


Re: [PATCH v3 06/14] doc: mkimage: Rearrange/remove some options

2022-06-30 Thread Simon Glass
On Sat, 25 Jun 2022 at 11:12, Sean Anderson  wrote:
>
> This moves some options which work in any mode to the general options
> section. -p is moved to after -E/-B since those options are related. This
> also adds documentation for -h and -V.
>
> The -F, -l, and -G options are documented twice. Remove the second
> documentation in each case. The synopsis for -l also suggests an implied
> second uimage-file-name parameter. E.g.
>
> mkimage [-l uimage-file-name] uimage-file-name
>
> This is misleading, so remove it. Wrap a few lines to 80 characters as
> well.
>
> Signed-off-by: Sean Anderson 
> ---
>
> (no changes since v2)
>
> Changes in v2:
> - Document -h and -V
> - Rearrange more options
>
>  doc/mkimage.1 | 62 ---
>  1 file changed, 29 insertions(+), 33 deletions(-)
>

Reviewed-by: Simon Glass 


Re: [PATCH v3 09/14] doc: mkimage: Add BUGS section

2022-06-30 Thread Simon Glass
On Sat, 25 Jun 2022 at 11:12, Sean Anderson  wrote:
>
> In leiu of a non-standard HOMEPAGE section, add a BUGS section with a link
> to the issue tracker.
>
> Signed-off-by: Sean Anderson 
> ---
>
> (no changes since v1)
>
>  doc/mkimage.1 | 7 +--
>  1 file changed, 5 insertions(+), 2 deletions(-)
>

Reviewed-by: Simon Glass 


Re: [PATCH v3 11/14] doc: mkimage: Remove AUTHORS section

2022-06-30 Thread Simon Glass
On Sat, 25 Jun 2022 at 11:12, Sean Anderson  wrote:
>
> Per man-pages(7), "use of an AUTHORS section is strongly discouraged."
> Remove it, and instead add some copyright notices and an SPDX. The default
> license for U-Boot is GPL2, so that's what I put. The copyright dates are
> based on the commit dates.
>
> Signed-off-by: Sean Anderson 
> ---
>
> (no changes since v2)
>
> Changes in v2:
> - Ensure comments are requests
>
>  doc/mkimage.1 | 12 ++--
>  1 file changed, 6 insertions(+), 6 deletions(-)

Reviewed-by: Simon Glass 


Re: [PATCH v3 08/14] doc: mkimage: Edit options for style and consistency

2022-06-30 Thread Simon Glass
On Sat, 25 Jun 2022 at 11:12, Sean Anderson  wrote:
>
> This makes a variety of changes for the options to make them
> typographically consistent, clarify their meaning, and fix grammatical (or
> other) errors. Many of the changes here are stylistic, though there are a
> few fixes. The main changes I made across the board were:
>
> - All options are bolded and parameters italicised
> - All single quotes are properly matched (instead of using apostrophes)
> - Minor background info has been added to clarify many underdocumented
>   options
> - Default values for options are documented
>
> Signed-off-by: Sean Anderson 
> ---
>
> Changes in v3:
> - Document option defaults
> - Note that "legacy" images are only legacy for U-Boot. In particular, mkimage
>   supports many other image formats using the same syntax which are decidedly
>   not "legacy."
> - Use multiple .BRs for the -f auto option list
>
> Changes in v2:
> - Better document multi images
> - Fix -B not being bolded in the description for -R
> - Italicize parameter for -d
> - Make lists of valid algos bold
> - Remove spaces around pipes
> - Use escape-sequences for options width all three of B/I/R. This renders
>   better with mandoc.
>
>  doc/mkimage.1 | 273 +++++++++-
>  1 file changed, 205 insertions(+), 68 deletions(-)

Reviewed-by: Simon Glass 


Re: [PATCH v3 05/14] doc: mkimage: Use subsection macro

2022-06-30 Thread Simon Glass
On Sat, 25 Jun 2022 at 11:12, Sean Anderson  wrote:
>
> The options are divided up into several subsections. Use the appropriate
> macro. While we're at it, rename the headings to better reflect the
> contents of their sections.
>
> Signed-off-by: Sean Anderson 
> ---
>
> Changes in v3:
> - Remove usage of "legacy" in section headings
>
> Changes in v2:
> - Rename first subsection to "General options"
> - Use paired quotation marks
>
>  doc/mkimage.1 | 8 +++-----
>  1 file changed, 3 insertions(+), 5 deletions(-)

Reviewed-by: Simon Glass 


Re: [PATCH v3 04/14] doc: mkimage: Regularize option documentation

2022-06-30 Thread Simon Glass
On Sat, 25 Jun 2022 at 11:12, Sean Anderson  wrote:
>
> Square brackets are commonly used to denote optional parts of a command.
> However, all option arguments are mandatory. Remove these brackets. This
> also removes some unnecessary quotation marks, and uses hyphens to connect
> words in option arguments. This is intended to just clean up the
> formatting, leaving content corrections to later patches.
>
> Signed-off-by: Sean Anderson 
> ---
>
> Changes in v3:
> - Clarify intent in commit message
>
> Changes in v2:
> - Fix extra quote in -E synopsis
>
>  doc/mkimage.1 | 72 +--
>  1 file changed, 36 insertions(+), 36 deletions(-)

Reviewed-by: Simon Glass 


Re: [PATCH RFC 1/8] fs: fat: unexport file_fat_read_at()

2022-06-30 Thread Simon Glass
On Tue, 28 Jun 2022 at 01:28, Qu Wenruo  wrote:
>
> That function is only utilized inside fat driver, unexport it.
>
> Signed-off-by: Qu Wenruo 
> ---
>  fs/fat/fat.c  | 4 ++--
>  include/fat.h | 2 --
>  2 files changed, 2 insertions(+), 4 deletions(-)

Reviewed-by: Simon Glass 


>
> diff --git a/fs/fat/fat.c b/fs/fat/fat.c
> index df9ea2c028fc..dcceccbcee0a 100644
> --- a/fs/fat/fat.c
> +++ b/fs/fat/fat.c
> @@ -1243,8 +1243,8 @@ out_free_itr:
> return ret;
>  }
>
> -int file_fat_read_at(const char *filename, loff_t pos, void *buffer,
> -loff_t maxsize, loff_t *actread)
> +static int file_fat_read_at(const char *filename, loff_t pos, void *buffer,
> +   loff_t maxsize, loff_t *actread)
>  {
> fsdata fsdata;
> fat_itr *itr;
> diff --git a/include/fat.h b/include/fat.h
> index bd8e450b33a3..a9756fb4cd1b 100644
> --- a/include/fat.h
> +++ b/include/fat.h
> @@ -200,8 +200,6 @@ static inline u32 sect_to_clust(fsdata *fsdata, int sect)
>  int file_fat_detectfs(void);
>  int fat_exists(const char *filename);
>  int fat_size(const char *filename, loff_t *size);
> -int file_fat_read_at(const char *filename, loff_t pos, void *buffer,
> -loff_t maxsize, loff_t *actread);
>  int file_fat_read(const char *filename, void *buffer, int maxsize);
>  int fat_set_blk_dev(struct blk_desc *rbdd, struct disk_partition *info);
>  int fat_register_device(struct blk_desc *dev_desc, int part_no);
> --
> 2.36.1
>


Re: [PATCH 4/4] doc: Migrate Process wiki page to sphinx

2022-06-30 Thread Simon Glass
On Mon, 27 Jun 2022 at 11:18, Tom Rini  wrote:
>
> Move the current Process wiki page to doc/develop/process.rst.  The
> changes here are for formatting or slight rewording so that it reads
> well when linking to other sphinx documents.
>
> Signed-off-by: Tom Rini 
> ---
>  doc/develop/index.rst   |   1 +
>  doc/develop/process.rst | 182 
>  2 files changed, 183 insertions(+)
>  create mode 100644 doc/develop/process.rst

Reviewed-by: Simon Glass 


Re: [PATCH RFC 6/8] fs: sandboxfs: add sandbox_fs_get_blocksize()

2022-06-30 Thread Simon Glass
On Tue, 28 Jun 2022 at 01:28, Qu Wenruo  wrote:
>
> This is to make sandboxfs to report blocksize it supports for
> _fs_read() to handle unaligned read.
>
> Unlike all other fses, sandboxfs can handle unaligned read/write without
> any problem since it's calling read()/write(), which doesn't bother the
> blocksize at all.
>
> This change is mostly to make testing of _fs_read() much easier.
>
> Cc: Simon Glass 
> Signed-off-by: Qu Wenruo 
> ---
>  arch/sandbox/cpu/os.c  | 11 +++
>  fs/fs.c|  2 +-
>  fs/sandbox/sandboxfs.c | 14 ++
>  include/os.h   |  8 
>  include/sandboxfs.h|  1 +
>  5 files changed, 35 insertions(+), 1 deletion(-)

Reviewed-by: Simon Glass 

with a comment as requested below

>
> diff --git a/arch/sandbox/cpu/os.c b/arch/sandbox/cpu/os.c
> index 5ea54179176c..6c29f29bdd9b 100644
> --- a/arch/sandbox/cpu/os.c
> +++ b/arch/sandbox/cpu/os.c
> @@ -46,6 +46,17 @@ ssize_t os_read(int fd, void *buf, size_t count)
> return read(fd, buf, count);
>  }
>
> +ssize_t os_get_blocksize(int fd)
> +{
> +   struct stat stat = {0};
> +   int ret;
> +
> +   ret = fstat(fd, );
> +   if (ret < 0)
> +   return -errno;
> +   return stat.st_blksize;
> +}
> +
>  ssize_t os_write(int fd, const void *buf, size_t count)
>  {
> return write(fd, buf, count);
> diff --git a/fs/fs.c b/fs/fs.c
> index 7e4ead9b790b..337d5711c28c 100644
> --- a/fs/fs.c
> +++ b/fs/fs.c
> @@ -261,7 +261,7 @@ static struct fstype_info fstypes[] = {
> .exists = sandbox_fs_exists,
> .size = sandbox_fs_size,
> .read = fs_read_sandbox,
> -   .get_blocksize = fs_get_blocksize_unsupported,
> +   .get_blocksize = sandbox_fs_get_blocksize,
> .write = fs_write_sandbox,
> .uuid = fs_uuid_unsupported,
> .opendir = fs_opendir_unsupported,
> diff --git a/fs/sandbox/sandboxfs.c b/fs/sandbox/sandboxfs.c
> index 4ae41d5b4db1..130fee088621 100644
> --- a/fs/sandbox/sandboxfs.c
> +++ b/fs/sandbox/sandboxfs.c
> @@ -55,6 +55,20 @@ int sandbox_fs_read_at(const char *filename, loff_t pos, 
> void *buffer,
> return ret;
>  }
>
> +int sandbox_fs_get_blocksize(const char *filename)
> +{
> +   int fd;
> +   int ret;
> +
> +   fd = os_open(filename, OS_O_RDONLY);
> +   if (fd < 0)
> +   return fd;
> +
> +   ret = os_get_blocksize(fd);
> +   os_close(fd);
> +   return ret;
> +}
> +
>  int sandbox_fs_write_at(const char *filename, loff_t pos, void *buffer,
> loff_t towrite, loff_t *actwrite)
>  {
> diff --git a/include/os.h b/include/os.h
> index 10e198cf503e..a864d9ca39b2 100644
> --- a/include/os.h
> +++ b/include/os.h
> @@ -26,6 +26,14 @@ struct sandbox_state;
>   */
>  ssize_t os_read(int fd, void *buf, size_t count);
>
> +/**
> + * Get the optimial blocksize through stat() call.
> + *
> + * @fd:File descriptor as returned by os_open()
> + * Return: >=0 for the blocksize. <0 for error.
> + */
> +ssize_t os_get_blocksize(int fd);
> +
>  /**
>   * Access to the OS write() system call
>   *
> diff --git a/include/sandboxfs.h b/include/sandboxfs.h
> index 783dd5c88a73..6937068f7b82 100644
> --- a/include/sandboxfs.h
> +++ b/include/sandboxfs.h
> @@ -32,6 +32,7 @@ void sandbox_fs_close(void);
>  int sandbox_fs_ls(const char *dirname);
>  int sandbox_fs_exists(const char *filename);
>  int sandbox_fs_size(const char *filename, loff_t *size);
> +int sandbox_fs_get_blocksize(const char *filename);

Please add a full comment.

>  int fs_read_sandbox(const char *filename, void *buf, loff_t offset, loff_t 
> len,
> loff_t *actread);
>  int fs_write_sandbox(const char *filename, void *buf, loff_t offset,
> --
> 2.36.1
>

Regards,
Simon


Re: [PATCH 2/4] doc: Migrate DesignPrinciples wiki page to sphinx

2022-06-30 Thread Simon Glass
On Mon, 27 Jun 2022 at 11:18, Tom Rini  wrote:
>
> Move the current DesignPrinciples wiki page to
> doc/develop/designprinciples.rst.  The changes here are for formatting
> or slight rewording so that it reads well when linking to other sphinx
> documents.
>
> Signed-off-by: Tom Rini 
> ---
>  doc/develop/designprinciples.rst | 197 +++
>  doc/develop/index.rst|   1 +
>  2 files changed, 198 insertions(+)
>  create mode 100644 doc/develop/designprinciples.rst

Reviewed-by: Simon Glass 


Re: [PATCH 1/4] doc: Migrate CodingStyle wiki page to sphinx

2022-06-30 Thread Simon Glass
On Mon, 27 Jun 2022 at 11:17, Tom Rini  wrote:
>
> Move the current CodingStyle wiki page to doc/develop/codingstyle.rst.
> The changes here are for formatting or slight rewording so that it reads
> well when linking to other sphinx documents.
>
> Signed-off-by: Tom Rini 
> ---
>  doc/develop/codingstyle.rst | 211 
>  doc/develop/index.rst   |   8 ++
>  2 files changed, 219 insertions(+)
>  create mode 100644 doc/develop/codingstyle.rst
>

Reviewed-by: Simon Glass 


Re: [PATCH v3 13/14] doc: mkimage: Further document -o and -R

2022-06-30 Thread Simon Glass
On Sat, 25 Jun 2022 at 11:12, Sean Anderson  wrote:
>
> Despite the original description of these options, they are not always
> image names, or even files. Some image types use these options to convey
> configuration directly. Re-document these options as configuration options.
>
> Additionally, add a new section documenting the format of the configuration
> for each image type which uses it. In general, if configuration is used
> directly (without a separate file) I have added documentation for it. If
> the configuration points to a separate file, I have referenced that file's
> documentation. Where there is no such documentation, I have added it.
>
> Signed-off-by: Sean Anderson 
> ---
>
> (no changes since v2)
>
> Changes in v2:
> - New
>
>  doc/mkimage.1 | 270 +++---
>  1 file changed, 236 insertions(+), 34 deletions(-)
>

Reviewed-by: Simon Glass 


Re: [PATCH v3 14/14] doc: Add man page for dumpimage

2022-06-30 Thread Simon Glass
On Sat, 25 Jun 2022 at 11:12, Sean Anderson  wrote:
>
> This tool seems a bit underloved. Unfortunately, it seems to be missing
> support for FIT images. Alas...

Flat Image Tree Images - I think just FIT is enough

>
> Add a man page documenting it. The example is taken from commit a804b5ce2d
> ("Add dumpimage, a tool to extract data from U-Boot images").
>
> Signed-off-by: Sean Anderson 
> ---
>
> (no changes since v2)
>
> Changes in v2:
> - Ensure comments are requests
>
>  doc/dumpimage.1 | 103 
>  1 file changed, 103 insertions(+)
>  create mode 100644 doc/dumpimage.1
>

Reviewed-by: Simon Glass 


Re: [PATCH v3 12/14] mkimage: Add long options

2022-06-30 Thread Simon Glass
On Sat, 25 Jun 2022 at 11:12, Sean Anderson  wrote:
>
> The mkimage command has had many options added over the years.
> Unfortunately, we are starting to run out of short options. Recent options
> don't have any obvious relation to their meaning (e.g. -o/-g). Fortunately,
> long options exist. Add long options for each current short option.
>
> For the curious, the remaining short options are HIkLmMPQSuUwWXyYzZ.
>
> Signed-off-by: Sean Anderson 
> ---
>
> (no changes since v2)
>
> Changes in v2:
> - New
>
>  doc/mkimage.1   | 66 +
>  tools/mkimage.c | 45 +++--
>  2 files changed, 109 insertions(+), 2 deletions(-)

Reviewed-by: Simon Glass 


Re: [PATCH v3 10/14] doc: mkimage: Add SEE ALSO section

2022-06-30 Thread Simon Glass
On Sat, 25 Jun 2022 at 11:12, Sean Anderson  wrote:
>
> This adds a SEE ALSO section to link to similar man pages, as well as to
> the U-Boot documentation.
>
> Signed-off-by: Sean Anderson 
> ---
>
> (no changes since v1)
>
>  doc/mkimage.1 | 8 
>  1 file changed, 8 insertions(+)
>

Reviewed-by: Simon Glass 


Re: [PATCH v3 07/14] doc: mkimage: Use correct capitalization for NAME

2022-06-30 Thread Simon Glass
On Sat, 25 Jun 2022 at 11:12, Sean Anderson  wrote:
>
> The description in NAME should not be capitalized. Fix a grammatical error
> as well.
>
> Signed-off-by: Sean Anderson 
> ---
>
> (no changes since v1)
>
>  doc/mkimage.1 | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)

Reviewed-by: Simon Glass 


>
> diff --git a/doc/mkimage.1 b/doc/mkimage.1
> index 34c0c2050f..ee5d0dd0ef 100644
> --- a/doc/mkimage.1
> +++ b/doc/mkimage.1
> @@ -1,7 +1,7 @@
>  .TH MKIMAGE 1 "2022-02-07"
>  .
>  .SH NAME
> -mkimage \- Generate image for U-Boot
> +mkimage \- generate images for U-Boot
>  .SH SYNOPSIS
>  .SY mkimage
>  .OP \-T type
> --
> 2.35.1
>


Re: [PATCH v3 01/14] doc: mkimage: Use standard style for synopsis

2022-06-30 Thread Simon Glass
On Sat, 25 Jun 2022 at 11:12, Sean Anderson  wrote:
>
> The synopsis section is a bit messy. As an example, "uimage file name" is
> printed in italics, bold, and roman (depending on the line). This cleans
> things up and converts the synopsis section to use standard style. The
> .SY/.YS macros set up appropriate formatting for command synopsis sections
> (such as disabling hyphenation and setting a hanging indent). All parts of
> the synopsis now use the following style:
>
> - Bold for parts of the command which should be typed in by the user (such
>   as the program name and flags)
> - Italic for parts which should be replaced (such as uimage-file-name)
> - Roman for parts which should not be typed at all (such as brackets)
>
> Multi-word variables now use hyphens to connect their words instead of
> spaces. This makes it clearer that all the words are part of the same
> variable. Additionally, "option ..." is used to denote where other options
> may be specified, as this appears to be standard style.
>
> In addition to the above style changes, this also makes some changes to
> content. The use of the term "legacy" has been removed, since this simply
> refers to any non-FIT image type. Additionally, wording like "uimage file
> name" has been replaced with "image-file-name" to better reflect that
> images may or may not be uImages. Lastly, the "auto" value for -f is
> documented in the synopsis.
>
> Signed-off-by: Sean Anderson 
> ---
>
> Changes in v3:
> - Document the various content changes in the commit message
> - Fix typo in commit message
> - Remove "legacy" wording from synopsis
> - Reorder "legacy" synopsis first
>
> Changes in v2:
> - Fix spacing for -F
>
>  doc/mkimage.1 | 27 +++
>  1 file changed, 19 insertions(+), 8 deletions(-)

Reviewed-by: Simon Glass 


Re: [PATCH v3 02/14] doc: mkimage: Use empty request instead of blank lines

2022-06-30 Thread Simon Glass
On Sat, 25 Jun 2022 at 11:12, Sean Anderson  wrote:
>
> Blank lines do not have well-defined semantics in fill mode (the default).
> Instead, use empty requests (.) where vertical space is necessary for
> readability. There are a few places where we use a paragraph instead.
>
> Signed-off-by: Sean Anderson 
> ---
>
> (no changes since v1)
>
>  doc/mkimage.1 | 108 +-
>  1 file changed, 54 insertions(+), 54 deletions(-)

Reviewed-by: Simon Glass 


Re: [PATCH v3 03/14] doc: mkimage: Reformat examples

2022-06-30 Thread Simon Glass
On Sat, 25 Jun 2022 at 11:12, Sean Anderson  wrote:
>
> This puts each example in a new paragraph and uses a hanging indent for
> continued lines to increase clarity. We use tabs instead of .in or .RS for
> the indent because it renders properly in both man and mandoc (which is
> what many common HTML man pages use). The only nit is that the tab stops in
> man default to something like 2", so reduce that to 1". We also escape
> every "minus" as recommended by man-pages(7).
>
> Signed-off-by: Sean Anderson 
> ---
>
> (no changes since v2)
>
> Changes in v2:
> - Escape minus signs in examples
> - Indent things more robustly
>
>  doc/mkimage.1 | 116 +-----
>  1 file changed, 67 insertions(+), 49 deletions(-)

Reviewed-by: Simon Glass 

Gosh this format is a pain


Re: [PATCH 12/20] arm: Remove PXA architecture support

2022-06-30 Thread Simon Glass
On Sat, 25 Jun 2022 at 09:06, Tom Rini  wrote:
>
> With the last platform for this architecture removed, remove the rest of
> the architecture support as well.
>
> Cc: Marek Vasut 
> Signed-off-by: Tom Rini 
> ---
>  MAINTAINERS   |7 -
>  README|7 -
>  arch/arm/Kconfig  |   14 +-
>  arch/arm/Makefile |2 -
>  arch/arm/cpu/pxa/Makefile |   14 -
>  arch/arm/cpu/pxa/cache.c  |   58 -
>  arch/arm/cpu/pxa/config.mk|   18 -
>  arch/arm/cpu/pxa/cpuinfo.c|  139 --
>  arch/arm/cpu/pxa/pxa2xx.c |  295 ---
>  arch/arm/cpu/pxa/relocate.S   |   22 -
>  arch/arm/cpu/pxa/start.S  |   98 -
>  arch/arm/cpu/pxa/timer.c  |   16 -
>  arch/arm/cpu/pxa/usb.c|   89 -
>  arch/arm/include/asm/arch-pxa/bitfield.h  |  112 -
>  arch/arm/include/asm/arch-pxa/config.h|   22 -
>  arch/arm/include/asm/arch-pxa/hardware.h  |   82 -
>  arch/arm/include/asm/arch-pxa/pxa-regs.h  | 2635 -
>  arch/arm/include/asm/arch-pxa/pxa.h   |   28 -
>  arch/arm/include/asm/arch-pxa/regs-mmc.h  |  140 --
>  arch/arm/include/asm/arch-pxa/regs-uart.h |   95 -
>  arch/arm/include/asm/arch-pxa/regs-usb.h  |  146 --
>  arch/arm/include/asm/config.h |2 -
>  doc/develop/driver-model/serial-howto.rst |9 -
>  drivers/mmc/Kconfig   |8 -
>  drivers/mmc/Makefile  |1 -
>  drivers/mmc/pxa_mmc_gen.c |  531 -
>  drivers/serial/Kconfig|6 -
>  drivers/serial/Makefile   |1 -
>  drivers/serial/serial_pxa.c   |  342 ---
>  drivers/serial/usbtty.h   |2 -
>  drivers/usb/gadget/Makefile   |1 -
>  drivers/usb/gadget/epautoconf.c   |6 -
>  drivers/usb/gadget/ether.c|   25 +-
>  drivers/usb/gadget/gadget_chips.h |   17 -
>  drivers/usb/gadget/pxa27x_udc.c   |  703 --
>  drivers/video/Makefile|1 -
>  drivers/video/pxa_lcd.c   |  549 -
>  include/dm/platform_data/pxa_mmc_gen.h|   22 -
>  include/dm/platform_data/serial_pxa.h |   40 -
>  include/lcd.h |4 +-
>  include/pxa_lcd.h |   80 -
>  include/usb/pxa27x_udc.h  |   31 -
>  42 files changed, 3 insertions(+), 6417 deletions(-)
>  delete mode 100644 arch/arm/cpu/pxa/Makefile
>  delete mode 100644 arch/arm/cpu/pxa/cache.c
>  delete mode 100644 arch/arm/cpu/pxa/config.mk
>  delete mode 100644 arch/arm/cpu/pxa/cpuinfo.c
>  delete mode 100644 arch/arm/cpu/pxa/pxa2xx.c
>  delete mode 100644 arch/arm/cpu/pxa/relocate.S
>  delete mode 100644 arch/arm/cpu/pxa/start.S
>  delete mode 100644 arch/arm/cpu/pxa/timer.c
>  delete mode 100644 arch/arm/cpu/pxa/usb.c
>  delete mode 100644 arch/arm/include/asm/arch-pxa/bitfield.h
>  delete mode 100644 arch/arm/include/asm/arch-pxa/config.h
>  delete mode 100644 arch/arm/include/asm/arch-pxa/hardware.h
>  delete mode 100644 arch/arm/include/asm/arch-pxa/pxa-regs.h
>  delete mode 100644 arch/arm/include/asm/arch-pxa/pxa.h
>  delete mode 100644 arch/arm/include/asm/arch-pxa/regs-mmc.h
>  delete mode 100644 arch/arm/include/asm/arch-pxa/regs-uart.h
>  delete mode 100644 arch/arm/include/asm/arch-pxa/regs-usb.h
>  delete mode 100644 drivers/mmc/pxa_mmc_gen.c
>  delete mode 100644 drivers/serial/serial_pxa.c
>  delete mode 100644 drivers/usb/gadget/pxa27x_udc.c
>  delete mode 100644 drivers/video/pxa_lcd.c
>  delete mode 100644 include/dm/platform_data/pxa_mmc_gen.h
>  delete mode 100644 include/dm/platform_data/serial_pxa.h
>  delete mode 100644 include/pxa_lcd.h
>  delete mode 100644 include/usb/pxa27x_udc.h

Reviewed-by: Simon Glass 


Re: [PATCH] regmap: fix some comments

2022-06-30 Thread Simon Glass
On Fri, 24 Jun 2022 at 09:20, Ralph Siemsen  wrote:
>
> Correct spelling and copy/paste errors in comments.
>
> Fixes 1c4db59d9b ("regmap: Add support for regmap fields")
>
> Signed-off-by: Ralph Siemsen 
> ---
>  include/regmap.h | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)

Reviewed-by: Simon Glass 


Re: [PATCH 3/3] doc: environment: Further expand on Image locations and provide example

2022-06-30 Thread Simon Glass
On Mon, 20 Jun 2022 at 08:32, Tom Rini  wrote:
>
> Start by elaborating on what some of our constraints tend to be with
> image location values, and document where these external constraints
> come from.  Provide a new subsection, an example based on the TI ARMv7
> OMAP2PLUS families of chips, that gives sample values and explains why
> we use these particular values.  This is based on what is in
> include/configs/ti_armv7_common.h as of fb3ad9bd923d ("TI: Add, use a
> DEFAULT_LINUX_BOOT_ENV environment string") as this contains just the
> values referenced in this document now and not some of the further
> additions that are less generic.
>
> Signed-off-by: Tom Rini 
> ---
>  doc/usage/environment.rst | 39 +++
>  1 file changed, 39 insertions(+)

Reviewed-by: Simon Glass 

>
> diff --git a/doc/usage/environment.rst b/doc/usage/environment.rst
> index a9a4702632d2..f70ccd6a58ee 100644
> --- a/doc/usage/environment.rst
> +++ b/doc/usage/environment.rst
> @@ -404,6 +404,42 @@ device tree blob  fdtfilefdt_addr_r   
> fdt_addr
>  ramdisk   ramdiskfileramdisk_addr_r   ramdisk_addr
>  = ==  ==
>
> +When setting the RAM addresses for `kernel_addr_r`, `fdt_addr_r` and
> +`ramdisk_addr_r` there are several constraints to keep in mind. When booting
> +Linux, the `Booting ARM Linux`_ and `Booting AArch64 Linux`_ documents lay 
> out
> +the requirements for booting all ARM platforms, including both alignment and
> +where within memory various things must be.  These guidelines tend to also be
> +correct for other OSes and unless specifically contradicted by documentation
> +specific to another architecture, are good rules to follow for other
> +architectures as well.
> +
> +Example Image locations
> +^^^
> +
> +If we take the Texas Instruments OMAP2PLUS family of ARMv7 processors as an
> +example for the above listed variables, we would do::
> +
> +loadaddr=0x8200
> +kernel_addr_r=${loadaddr}
> +fdt_addr_r=0x8800
> +ramdisk_addr_r=0x8808
> +bootm_size=0x1000
> +
> +To explain this, we start by noting that DRAM starts at 0x8000.  A 32MiB

Should it say 'We use a 32MiB' ?


> +buffer from the start of memory as our default load address, and so where the
> +kernel would also be loaded to.  This will hopefully allow for us to have the
> +whole of the compressed kernel image exist in memory above where the whole of
> +the decompressed kernel image will be, and allow for a quicker boot.  Next, 
> we
> +say that the device tree will be placed at 128MiB offset from the start of
> +memory.  This is suggested by the kernel documment as it is exceedingly
> +unlikely to be overwritten by the kernel itself given other architectural
> +constraints.  We then allow for the device tree to be up to 512KiB in size
> +before placing the ramdisk in memory.  We then say that everything should be
> +within the first 256MiB of memory so that U-Boot can relocate things as 
> needed
> +to ensure proper alignment.  We pick 256MiB as our value here because we know
> +there are very few platforms on in this family with less memory.  It could be
> +as high as 768MiB and still ensure that everything would be visible to the
> +kernel, but again we go with what we assume is the safest assumption.
>
>  Automatically updated variables
>  ---
> @@ -472,3 +508,6 @@ Implementation
>  --
>
>  See :doc:`../develop/environment` for internal development details.
> +
> +.. _`Booting ARM Linux`: 
> https://www.kernel.org/doc/html/latest/arm/booting.html
> +.. _`Booting AArch64 Linux`: 
> https://www.kernel.org/doc/html/latest/arm64/booting.html
> --
> 2.25.1
>


Re: [PATCH 2/3] doc: environment: Expand on fdt_addr, initrd_addr and loadaddr

2022-06-30 Thread Simon Glass
On Mon, 20 Jun 2022 at 08:32, Tom Rini  wrote:
>
> - Explain why fdt_addr and initrd_addr should not be set to disable
>   relocation normally.
> - Provide some advice on the typical loadaddr default value.
>
> Signed-off-by: Tom Rini 
> ---
>  doc/usage/environment.rst | 15 ---
>  1 file changed, 12 insertions(+), 3 deletions(-)

Reviewed-by: Simon Glass 


Re: [PATCH 1/3] doc: environment: Drop u-boot_addr_r

2022-06-30 Thread Simon Glass
On Mon, 20 Jun 2022 at 08:31, Tom Rini  wrote:
>
> This variable is never set nor explained why it would be set, drop it.
>
> Signed-off-by: Tom Rini 
> ---
>  doc/usage/environment.rst | 1 -
>  1 file changed, 1 deletion(-)

Reviewed-by: Simon Glass 


Re: [RFC] Proposed location to host the firmware handoff specification.

2022-06-30 Thread Simon Glass
Hi Jose,

I don't think this is correct. TF-A is a project that aims to replace
U-Boot SPL (and perhaps other components) with more closed firmware,
e.g. the permissive license.

This spec needs to be in a neutral place, not captive of one project.

Given its close relationship to device tree, I suggest github.com/devicetree-org

If that is not acceptable then we should look for something else.

Regards,
Simon

On Thu, 23 Jun 2022 at 08:20, Jose Marinho  wrote:
>
> Hi,
>
> Arm worked to draft a firmware handoff [1] specification, evolving it based 
> on community feedback.
>
> This activity followed the request of some members of the Arm ecosystem [2].
> The spec (still at ALP – feedback/comments welcome!) standardizes how 
> information is propagated between different firmware components during boot.
>
> The spec hopes to remove the reliance on bespoke/platform-specific 
> information handoff mechanisms, thus reducing the code maintenance burden.
>
>
>
> The concept of entry types is present in the spec – these are data structure 
> layouts that carry a specific type of data.
> New types are meant to be added, following the needs and use-cases of the 
> different communities.
> Thus, these communities should be empowered to request new types!
>
> To enable community contributions, the specification must be hosted in a 
> location that is friendly to change requests.
>
> We propose to host the spec in trustedfirmware.org (tf.org).
>
>
> Tf.org hosts several open-source projects and already has an open governance 
> model.
> TF-A, and the associated community, rely on tf.org, and thus are already well 
> equipped to maintain this specification and keep it up to date.
> Tf.org is agnostic of any downstream projects that would adopt this 
> specification (e.g. U-boot, EDK2, etc.).
>
> We welcome the views of the communities and want to understand if there are 
> any strong objections to what’s being proposed!
> If anyone has objections, we are happy to consider alternatives and 
> associated trade-offs.
>
>
> Regards
>
> [1] https://developer.arm.com/documentation/den0135/latest
>
> [2] Re: [TF-A] Proposal: TF-A to adopt hand-off blocks (HOBs) for information 
> passing between boot stages - TF-A - lists.trustedfirmware.org
>
>


Re: [PATCH 1/9] dm: core: Rename dm_dump_all()

2022-06-28 Thread Simon Glass
This is not a good name anymore as it does not dump everything. Rename it
to dm_dump_tree() to avoid confusion.

Signed-off-by: Simon Glass 
---

 cmd/dm.c| 8 
 drivers/core/dump.c | 2 +-
 include/dm/util.h   | 2 +-
 3 files changed, 6 insertions(+), 6 deletions(-)

Applied to u-boot-dm, thanks!


Re: [PATCH v2] patman: Fix defaults not propagating to subparsers

2022-06-28 Thread Simon Glass
On python 3.8.10 (and 3.10), subparsers are not updated with defaults. I
suspect this is related to [1]. Fix this by explicitly updating
subparsers with settings.

[1] https://github.com/python/cpython/issues/89398

Fixes: 3145b63513 ("patman: Update defaults in subparsers")
Signed-off-by: Sean Anderson 
Reviewed-by: Alper Nebi Yasak 
Tested-by: Alper Nebi Yasak 
---

Changes in v2:
- Fix spelling of "propagating" in commit message
- Update comment to more clearly indicate intent

 tools/patman/settings.py | 7 ++-
 1 file changed, 6 insertions(+), 1 deletion(-)

Applied to u-boot-dm, thanks!


Re: [PATCH 3/9] dm: core: Fix addresses in the dm static command

2022-06-28 Thread Simon Glass
This command converts pointers to addresses, but the pointers being
converted are in the image's rodata region. For sandbox this means it
is not in DRAM so it does not make sense to do this conversion.

Fix this by showing a simple pointer instead. Drop the unnecessary
@ and hex prefixes.

Signed-off-by: Simon Glass 
---

 drivers/core/dump.c | 6 ++
 1 file changed, 2 insertions(+), 4 deletions(-)

Applied to u-boot-dm, thanks!


Re: [PATCH 4/5] patman: test_util: Customize unittest test results for more info

2022-06-28 Thread Simon Glass
By default, unittest test summaries only print extended info about tests
that failed or couldn't run due to an error. Use a custom text result
class to print info about more cases: skipped tests, expected failures
and unexpected successes.

Signed-off-by: Alper Nebi Yasak 
---
This could be squashed into the previous patch, but makes the diff ugly.

 tools/patman/test_util.py | 46 +++
 1 file changed, 46 insertions(+)

Applied to u-boot-dm, thanks!


Re: [PATCH 2/9] dm: core: Sort dm subcommands

2022-06-28 Thread Simon Glass
Put these in alphabetic order, both in the help and in the implementation,
as there are quite a few subcommands now. Tweak the help for 'dm tree' to
better explain what it does.

Signed-off-by: Simon Glass 
---

 cmd/dm.c | 48 
 1 file changed, 24 insertions(+), 24 deletions(-)

Applied to u-boot-dm, thanks!


Please pull u-boot-dm/next

2022-06-28 Thread Simon Glass
Hi Tom,

This is for the -next branch.

https://source.denx.de/u-boot/custodians/u-boot-dm/-/commit/e87da5704ffa6fc782d93d137fa30a37a5df3566


The following changes since commit ea82ed8c2eaee0a0f7dee31016aaee4ce88e9ea7:

  Merge branch '2022-06-27-add-armv8-sha1-sha256-support' into next
(2022-06-27 13:39:19 -0400)

are available in the Git repository at:

  git://git.denx.de/u-boot-dm.git tags/dm-pull-28jun22

for you to fetch changes up to e87da5704ffa6fc782d93d137fa30a37a5df3566:

  armv8: u-boot-spl.lds: mark __image_copy_start as symbol (2022-06-28
03:09:52 +0100)


nman external-symbol improvements
Driver model memory-usage reporting
patman test-reporting improvements
Add bloblist design goals


Alper Nebi Yasak (12):
  patman: test_util: Fix printing results for failed tests
  patman: test_util: Handle nonexistent tests while loading tests
  patman: test_util: Use unittest text runner to print test results
  patman: test_util: Customize unittest test results for more info
  patman: test_util: Print test stdout/stderr within test summaries
  spl: binman: Fix use of undeclared u_boot_any symbols
  spl: binman: Make TPL_BINMAN_SYMBOLS depend on TPL_FRAMEWORK
  spl: binman: Declare extern symbols for VPL as well
  spl: binman: Split binman symbols support from enabling binman
  spl: binman: Add config options for binman symbols in VPL
  spl: binman: Check at runtime if binman symbols were filled in
  spl: binman: Disable u_boot_any symbols for i.MX8M boards

Heinrich Schuchardt (6):
  sandbox: add function os_printf()
  sandbox: show error if the device-tree cannot be loaded
  dm: fix formatting of uclass dump
  sandbox: raise SANDBOX_RAM_SIZE_MB default to 256
  test: fix some pylint errors in test_bind.py
  sandbox: cast to pointer from integer of different size

Peng Fan (1):
  armv8: u-boot-spl.lds: mark __image_copy_start as symbol

Sean Anderson (4):
  sandbox: usb: Fix out-of-bounds read when fd=-1
  dm: core: Provide fallbacks for ofnode_conf_read_...
  dm: core: Use device_foreach_child where possible
  patman: Fix defaults not propagating to subparsers

Simon Glass (11):
  bloblist: Describe the design goals
  dtoc: Update fdt tests to use test_util
  dm: core: Rename dm_dump_all()
  dm: core: Sort dm subcommands
  dm: core: Fix addresses in the dm static command
  dm: core: Add documentation for the dm command
  dm: core: Switch the testbus driver to use a new struct
  dm: core: Support accessing core tags
  dm: core: Add a way to collect memory usage
  dm: core: Add a command to show driver model statistics
  dm: spl: Allow SPL to show memory usage

 arch/arm/cpu/armv8/u-boot-spl.lds   |   2 +-
 arch/sandbox/Kconfig|   4 +-
 arch/sandbox/cpu/cpu.c  |   8 +-
 arch/sandbox/cpu/os.c   |  13 +
 cmd/dm.c|  72 ++--
 common/spl/Kconfig  |  23 +-
 common/spl/Kconfig.tpl  |  27 +-
 common/spl/Kconfig.vpl  |  25 ++
 common/spl/spl.c|  25 +-
 common/spl/spl_ram.c|   2 +-
 doc/develop/bloblist.rst|   2 +
 doc/usage/cmd/dm.rst| 487 
 doc/usage/index.rst |   1 +
 drivers/core/Kconfig|  21 ++
 drivers/core/device-remove.c|   4 +-
 drivers/core/device.c   |  86 -
 drivers/core/devres.c   |   2 +-
 drivers/core/dump.c |  83 -
 drivers/core/root.c |  53 +++
 drivers/core/tag.c  |  29 ++
 drivers/misc/qfw_sandbox.c  |   2 +-
 drivers/misc/test_drv.c |   6 +-
 drivers/usb/emul/sandbox_flash.c|   5 +-
 include/binman_sym.h|  51 ++-
 include/bloblist.h  |  62 +++-
 include/dm/device.h |  25 ++
 include/dm/ofnode.h |  66 ++--
 include/dm/root.h   |  45 +++
 include/dm/tag.h|  32 +-
 include/dm/test.h   |   7 +
 include/dm/util.h   |  11 +-
 include/os.h|   7 +
 include/spl.h   |   2 +
 test/dm/core.c  |  91 ++
 test/py/tests/test_bind.py  | 345 ++--
 tools/binman/elf.py |  12 +-
 tools/binman/elf_test.py|  12 +-
 tools/binman/ftest.py   |  33 +-
 tools/binman

Re: [PATCH] dm: core: Use device_foreach_child where possible

2022-06-28 Thread Simon Glass
We have some nice macros for iterating over devices in device.h, but they
are not used by the driver core. Convert all the users I could find.

Signed-off-by: Sean Anderson 
---

 drivers/core/device-remove.c |  4 ++--
 drivers/core/device.c| 21 ++---
 drivers/core/devres.c|  2 +-
 drivers/core/dump.c  |  2 +-
 4 files changed, 14 insertions(+), 15 deletions(-)

Applied to u-boot-dm, thanks!


Re: [PATCH] dtoc: Update fdt tests to use test_util

2022-06-28 Thread Simon Glass
On 19/03/2022 03:01, Simon Glass wrote:
> Use the common functions to run tests and report results. Ensure that the
> result code indicates success or failure.
>
> Signed-off-by: Simon Glass 
> ---
>
>  tools/dtoc/test_fdt.py | 27 ++-
>  1 file changed, 10 insertions(+), 17 deletions(-)

Reviewed-by: Alper Nebi Yasak 

Applied to u-boot-dm, thanks!


Re: [PATCH] bloblist: Describe the design goals

2022-06-28 Thread Simon Glass
Add a comment explaining the design goals of bloblist, to make it easier
for people to understand and comment on the structure.

Signed-off-by: Simon Glass 
---

 doc/develop/bloblist.rst |  2 ++
 include/bloblist.h   | 62 ++--
 2 files changed, 62 insertions(+), 2 deletions(-)

Applied to u-boot-dm, thanks!


Re: [PATCH] dm: core: Provide fallbacks for ofnode_conf_read_...

2022-06-28 Thread Simon Glass
On 3/28/22 6:14 PM, Sean Anderson wrote:
> Because fdt_get_config_str et al. were moved/renamed to
> ofnode_conf_read_str, they now depend on CONFIG_DM as well as
> CONFIG_OF_CONTROL. Add some fallback implementations, preventing a
> linker error when CONFIG_SPL_OF_CONTROL and CONFIG_SPL_ENV_IS_IN_MMC are
> enabled and CONFIG_SPL_DM is disabled.
>
> Fixes: 7de8bd03c3 ("treewide: fdt: Move fdt_get_config_... to 
> ofnode_conf_read...")
> Signed-off-by: Sean Anderson 
> ---
>
>  include/dm/ofnode.h | 17 +
>  1 file changed, 17 insertions(+)
>
Applied to u-boot-dm, thanks!


Re: [PATCH 8/9] dm: core: Add a command to show driver model statistics

2022-06-28 Thread Simon Glass
This command shows the memory used by driver model along with various
hints as to what it might be if some 'core' tags were moved to use the
tag list instead of a core (i.e. always-there) pointer.

This may help with future work to reduce memory usage.

Signed-off-by: Simon Glass 
---

 cmd/dm.c | 23 ++
 drivers/core/Kconfig | 11 +++
 drivers/core/dump.c  | 73 
 drivers/core/tag.c   | 18 +++
 include/dm/root.h|  2 +-
 include/dm/tag.h |  8 +
 include/dm/util.h|  9 ++
 7 files changed, 143 insertions(+), 1 deletion(-)

Applied to u-boot-dm, thanks!


Re: [PATCH 6/9] dm: core: Support accessing core tags

2022-06-28 Thread Simon Glass
Hi Simon,

On Sun, May 08, 2022 at 04:39:24AM -0600, Simon Glass wrote:
> At present tag numbers are only allocated for non-core data, meaning that
> the 'core' data, like priv and plat, are accessed through dedicated
> functions.
>
> For debugging and consistency it is convenient to use tags for this 'core'
> data too. Add support for this, with new tag numbers and functions to
> access the pointer and size for each.
>
> Update one of the test drivers so that the uclass-private data can be
> tested here.
>
> There is some code duplication with functions like device_alloc_priv() but
> this is not addressed for now. At some point, some rationalisation may
> help to reduce code size, but more thought it needed on that.
>
> Signed-off-by: Simon Glass 
> ---
>
>  drivers/core/device.c   | 65 +
>  drivers/misc/test_drv.c |  4 ++-
>  include/dm/device.h | 25 +
>  include/dm/tag.h| 13 ++-
>  test/dm/core.c  | 80 +
>  tools/dtoc/test_dtoc.py |  4 +++
>  6 files changed, 189 insertions(+), 2 deletions(-)
>
Applied to u-boot-dm, thanks!


Re: [PATCH] sandbox: usb: Fix out-of-bounds read when fd=-1

2022-06-28 Thread Simon Glass
Hi Sean,

On Wed, 23 Mar 2022 at 16:24, Sean Anderson  wrote:
>
> sandbox_flash_bulk uses priv->read_len to determine if priv->buff contains
> the response data (such as from SCSI_INQUIRY). However, if priv->fd=-1 in
> handle_read, then priv->read_len is not set even though we are going to
> PHASE_DATA. This causes sandbox_flash_bulk to try and read len bytes from
> priv->buff, which likely goes past the end of the buffer. Fix this by always
> setting priv->read_len even if we aren't going to read anything.
>
> Fixes: f4f715360c ("dm: usb: sandbox: Add an emulator for USB flash devices")
> Signed-off-by: Sean Anderson 
> ---
> Is returning -EIO correct here? Should we return 0 (nothing read)? Or pretend 
> to
> read the whole thing and then let the caller figure it out based on the 
> status?

It looks like returning an error makes sense, but Marek may know more.

>
>  drivers/usb/emul/sandbox_flash.c | 5 ++++-
>  1 file changed, 4 insertions(+), 1 deletion(-)

Reviewed-by: Simon Glass 

>
Applied to u-boot-dm, thanks!


Re: [PATCH 1/5] patman: test_util: Fix printing results for failed tests

2022-06-28 Thread Simon Glass
On Sat, 2 Apr 2022 at 11:06, Alper Nebi Yasak  wrote:
>
> When printing a python tool's test results, the entire list of failed
> tests and their tracebacks are reprinted for every failed test. This
> makes the test output quite unreadable. Fix the loop to print failures
> and tracebacks one at a time.
>
> Signed-off-by: Alper Nebi Yasak 
> ---
>
>  tools/patman/test_util.py | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)

Reviewed-by: Simon Glass 

Applied to u-boot-dm, thanks!


Re: [PATCH 2/5] patman: test_util: Handle nonexistent tests while loading tests

2022-06-28 Thread Simon Glass
On Sat, 2 Apr 2022 at 11:06, Alper Nebi Yasak  wrote:
>
> It's possible to request a specific test to run when trying to run a
> python tool's tests. If we request a nonexistent test, the unittest
> loaders generate a fake test that reports this as an error. However, we
> get these fake tests even when the test exists, because test_util can
> load tests from multiple places one by one and the test we want only
> exists in one.
>
> The test_util helpers currently remove these fake tests when printing
> test results, but that's more of a workaround than a proper solution.
> Instead, don't even try to load the missing tests.
>
> Signed-off-by: Alper Nebi Yasak 
> ---
>
>  tools/patman/test_util.py | 21 +
>  1 file changed, 5 insertions(+), 16 deletions(-)

Reviewed-by: Simon Glass 

Applied to u-boot-dm, thanks!


Re: [PATCH 5/5] patman: test_util: Print test stdout/stderr within test summaries

2022-06-28 Thread Simon Glass
On Sat, 2 Apr 2022 at 11:06, Alper Nebi Yasak  wrote:
>
> While running tests for a python tool, the tests' outputs get printed in
> whatever order they happen to run, without any indication as to which
> output belongs to which test. Unittest supports capturing these outputs
> and printing them as part of the test summaries, but when a failure or
> error occurs it switches back to printing as the tests run. Testtools
> and subunit tests can do the same as their parts inherit from unittest,
> but they don't outright expose this functionality.
>
> On the unittest side, enable output buffering for the custom test result
> class. Try to avoid ugly outputs by not printing stdout/stderr before
> the test summary for low verbosity levels and for successful tests.
>
> On the subunit side, implement a custom TestProtocolClient that enables
> the same underlying functionality and injects the captured streams as
> additional test details. This causes them to be merged into their test's
> error traceback message, which is later rebuilt into an exception and
> passed to our unittest report class.
>
> Signed-off-by: Alper Nebi Yasak 
> ---
> The way I had to do this for concurrencytest feels hacky, so I am
> ambivalent towards this patch. I'm actually fine with re-running a
> failing binman test alone with --debug -v6 to get better, isolated
> output from it.

Yes that's what I tend to do, but I think we should try this patch. We
can always drop it in a future release if it causes problems.

>
>  tools/concurrencytest/concurrencytest.py | 83 +++-
>  tools/patman/test_util.py| 33 +++++-
>  2 files changed, 112 insertions(+), 4 deletions(-)

Reviewed-by: Simon Glass 

Applied to u-boot-dm, thanks!


Re: [PATCH 2/2] sandbox: show error if the device-tree cannot be loaded

2022-06-28 Thread Simon Glass
U-Boot's printf() used before setting up U-Boot's serial driver does not
create any output. Use os_printf() for error messages related to loading
the device-tree.

Signed-off-by: Heinrich Schuchardt 
---
 arch/sandbox/cpu/cpu.c | 8 
 1 file changed, 4 insertions(+), 4 deletions(-)

Applied to u-boot-dm, thanks!


Re: [PATCH 1/1] sandbox: raise SANDBOX_RAM_SIZE_MB default to 256

2022-06-28 Thread Simon Glass
The UEFI Self Certification Test (SCT) cannot run on 128 MiB.

Signed-off-by: Heinrich Schuchardt 
---
 arch/sandbox/Kconfig | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Applied to u-boot-dm, thanks!


Re: [PATCH 1/1] dm: fix formatting of uclass dump

2022-06-28 Thread Simon Glass
Insert an empty line after each uclass independent of whether it has
devices or not.

Signed-off-by: Heinrich Schuchardt 
---
 drivers/core/dump.c | 2 --
 1 file changed, 2 deletions(-)

Applied to u-boot-dm, thanks!


Re: [PATCH 1/2] sandbox: add function os_printf()

2022-06-28 Thread Simon Glass
Before setting up the devices U-Boot's printf() function cannot be used
for console output. Provide function os_printf() to print to stderr.

Signed-off-by: Heinrich Schuchardt 
---
 arch/sandbox/cpu/os.c | 13 +
 include/os.h  |  7 +++
 2 files changed, 20 insertions(+)

Applied to u-boot-dm, thanks!


Re: [PATCH] test: fix some pylint errors in test_bind.py

2022-06-28 Thread Simon Glass
* Use spaces not tabs
* Limit lines to 100 spaces
* Remove an unused import
* Sort imports correctly
* Add a module description

Signed-off-by: Heinrich Schuchardt 
---
 test/py/tests/test_bind.py | 345 +++--
 1 file changed, 175 insertions(+), 170 deletions(-)

Applied to u-boot-dm, thanks!


Re: [PATCH 4/9] dm: core: Add documentation for the dm command

2022-06-28 Thread Simon Glass
Add a description and examples for the dm subcommands.

Signed-off-by: Simon Glass 
---

 doc/usage/cmd/dm.rst | 487 +++
 doc/usage/index.rst  |   1 +
 2 files changed, 488 insertions(+)
 create mode 100644 doc/usage/cmd/dm.rst

Applied to u-boot-dm, thanks!


Re: [PATCH v2 3/8] spl: binman: Declare extern symbols for VPL as well

2022-06-28 Thread Simon Glass
The binman extern symbol declarations in spl.h are missing the VPL
symbols recently added to spl.c, add them like the others.

Signed-off-by: Alper Nebi Yasak 
---

(no changes since v1)

 include/spl.h | 2 ++
 1 file changed, 2 insertions(+)

Applied to u-boot-dm, thanks!


Re: [PATCH 5/9] dm: core: Switch the testbus driver to use a new struct

2022-06-28 Thread Simon Glass
At present this driver uses 'priv' struct to hold 'plat' data, which is
confusing. The contents of the strct don't matter, since only dtoc is
using it. Create a new struct with the correct name.

Signed-off-by: Simon Glass 
---

 drivers/misc/test_drv.c | 2 +-
 include/dm/test.h   | 7 +++
 tools/dtoc/test_dtoc.py | 2 +-
 3 files changed, 9 insertions(+), 2 deletions(-)

Applied to u-boot-dm, thanks!


Re: [PATCH v2 1/8] spl: binman: Fix use of undeclared u_boot_any symbols

2022-06-28 Thread Simon Glass
Some SPL functions directly use the binman 'u_boot_any' symbols to get
U-Boot's binman image position. These symbols are declared by the
SPL/TPL_BINMAN_SYMBOLS configs, but they are accessed by macros defined
by just CONFIG_BINMAN. So when BINMAN is enabled and BINMAN_SYMBOLS is
disabled, the code tries to use undeclared symbols and we get an error.

Therefore, any use of 'u_boot_any' symbols in the code is an implicit
dependency on SPL/TPL_BINMAN_SYMBOLS. However, in the current uses
they are meant to be the next phase's values, where that happens to be
U-Boot. In the meantime, helper funcions spl_get_image_pos/size() were
introduced to get these values.

Convert all uses of u_boot_any symbols to these functions, so we only
access these symbols at one place. Make sure they will not use these
symbols when the BINMAN_SYMBOLS configs are disabled, by returning early
in those cases.

Signed-off-by: Alper Nebi Yasak 
---

(no changes since v1)

 common/spl/spl.c | 10 +++---
 common/spl/spl_ram.c |  2 +-
 2 files changed, 8 insertions(+), 4 deletions(-)

Applied to u-boot-dm, thanks!


Re: [PATCH 7/9] dm: core: Add a way to collect memory usage

2022-06-28 Thread Simon Glass
Add a function for collecting the amount of memory used by driver model,
including devices, uclasses and attached data and tags.

This information can provide insights into how to reduce the memory
required by driver model. Future work may look at execution speed also.

Signed-off-by: Simon Glass 
---

 drivers/core/root.c | 53 +
 drivers/core/tag.c  | 11 ++
 include/dm/root.h   | 45 ++
 include/dm/tag.h| 11 ++
 test/dm/core.c  | 11 ++
 5 files changed, 131 insertions(+)

Applied to u-boot-dm, thanks!


Re: [PATCH 9/9] dm: spl: Allow SPL to show memory usage

2022-06-28 Thread Simon Glass
Add an option to tell SPL to show memory usage for driver model just
before it boots into the next phase.

Signed-off-by: Simon Glass 
---

 common/spl/spl.c |  9 +
 drivers/core/Kconfig | 10 ++
 2 files changed, 19 insertions(+)

Applied to u-boot-dm, thanks!


Re: [PATCH v2 2/8] spl: binman: Make TPL_BINMAN_SYMBOLS depend on TPL_FRAMEWORK

2022-06-28 Thread Simon Glass
TPL_BINMAN_SYMBOLS depends on SPL_FRAMEWORK. The code this enables is
compiled by checking CONFIG_$(SPL_TPL_)FRAMEWORK, so it should depend on
TPL_FRAMEWORK instead (which in turn depends on SPL_FRAMEWORK). This was
most likely a typo due to copy-pasting the config's SPL version, fix it.

Signed-off-by: Alper Nebi Yasak 
---

(no changes since v1)

 common/spl/Kconfig.tpl | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Applied to u-boot-dm, thanks!


Re: [PATCH v2 4/8] spl: binman: Split binman symbols support from enabling binman

2022-06-28 Thread Simon Glass
Enabling CONFIG_BINMAN makes binman run after a build to package any
images specified in the device-tree. It also enables a mechanism for
SPL/TPL to declare and use special linker symbols that refer to other
entries in the same binman image. A similar feature that gets this info
from the device-tree exists for U-Boot proper, but it is gated behind a
CONFIG_BINMAN_FDT unlike the symbols.

Confusingly, CONFIG_SPL/TPL_BINMAN_SYMBOLS also exist. These configs
don't actually enable/disable the symbols mechanism as one would expect,
but declare some symbols for U-Boot using this mechanism.

Reuse the BINMAN_SYMBOLS configs to make them toggle the symbols
mechanism, and declare symbols for the U-Boot phases in a dependent
BINMAN_UBOOT_SYMBOLS config. Extend it to cover symbols of all phases.
Update the config prompt and help message to make it clearer about this.
Fix binman test binaries to work with CONFIG_IS_ENABLED(BINMAN_SYMBOLS).

Co-developed-by: Peng Fan 
[Alper: New config for phase symbols, update Kconfigs, commit message]
Signed-off-by: Alper Nebi Yasak 
---
See Peng's patch [1] included in these changes.

[1] binman_sym: guard with CONFIG_IS_ENABLED(BINMAN_SYMBOLS)
https://lore.kernel.org/u-boot/20220603071715.15212-8-peng@oss.nxp.com/

Changes in v2:
- Split binman symbols support from enabling binman
- Move U-Boot phase symbol declarations to BINMAN_UBOOT_SYMBOLS configs
- Merge in Peng's patch for binman_sym.h changes

 common/spl/Kconfig  | 22 ++-
 common/spl/Kconfig.tpl  | 24 +++--
 common/spl/spl.c|  9 
 include/binman_sym.h|  6 +++---
 tools/binman/test/Makefile  |  2 +-
 tools/binman/test/generated/autoconf.h  |  3 +++
 tools/binman/test/u_boot_binman_syms.c  |  2 +-
 tools/binman/test/u_boot_binman_syms_size.c |  2 +-
 8 files changed, 49 insertions(+), 21 deletions(-)
 create mode 100644 tools/binman/test/generated/autoconf.h

Applied to u-boot-dm, thanks!


Re: [PATCH 3/5] patman: test_util: Use unittest text runner to print test results

2022-06-28 Thread Simon Glass
On Sat, 2 Apr 2022 at 11:06, Alper Nebi Yasak  wrote:
>
> The python tools' test utilities handle printing test results, but the
> output is quite bare compared to an ordinary unittest run. Delegate
> printing the results to a unittest text runner, which gives us niceties
> like clear separation between each test's result and how long it took to
> run the test suite.
>
> Unfortunately it does not print info for skipped tests by default, but
> this can be handled later by a custom test result subclass. It also does
> not print the tool name; manually print a heading that includes the
> toolname so that the outputs of each tool's tests are distinguishable in
> the CI output.
>
> Signed-off-by: Alper Nebi Yasak 
> ---
>
>  tools/binman/main.py  |  8 ++
>  tools/buildman/main.py|  8 ++
>  tools/dtoc/main.py|  9 +++---
>  tools/dtoc/test_fdt.py|  8 +++---
>  tools/patman/main.py  |  8 ++
>  tools/patman/test_util.py | 58 ++-
>  6 files changed, 38 insertions(+), 61 deletions(-)
>

Reviewed-by: Simon Glass 

Applied to u-boot-dm, thanks!


Re: [PATCH 1/1] sandbox: cast to pointer from integer of different size

2022-06-28 Thread Simon Glass
On Sun, Jun 12, 2022 at 7:25 PM Heinrich Schuchardt  wrote:
>
> Building sandbox_defconfig on ARMv7 with HOST_32BIT=y results in:
>
> drivers/misc/qfw_sandbox.c:51:25: warning:
> cast to pointer from integer of different size [-Wint-to-pointer-cast]
>51 | void *address = (void *)be64_to_cpu(dma->address);
>
> Add the missing type conversion.
>
> Fixes: 69512551aa84 ("test: qemu: add qfw sandbox driver, dm tests, qemu 
> tests")
> Signed-off-by: Heinrich Schuchardt 
> ---
>  drivers/misc/qfw_sandbox.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>

Reviewed-by: Bin Meng 

Applied to u-boot-dm, thanks!


Re: [PATCH v2 5/8] spl: binman: Add config options for binman symbols in VPL

2022-06-28 Thread Simon Glass
The SPL code declares binman symbols for U-Boot phases depending on
CONFIG_IS_ENABLED(BINMAN_UBOOT_SYMBOLS). This config exists for SPL and
TPL, also add a version for VPL.

Signed-off-by: Alper Nebi Yasak 
---

Changes in v2:
- Update VPL configs for the new BINMAN_UBOOT_SYMBOLS

 common/spl/Kconfig.vpl | 24 
 1 file changed, 24 insertions(+)

Applied to u-boot-dm, thanks!


Re: [PATCH v2 7/8] spl: binman: Disable u_boot_any symbols for i.MX8M boards

2022-06-28 Thread Simon Glass
The i.MX8M boards use partially specified binman images which have an
SPL entry without a U-Boot entry. This would normally cause an error due
to the 'u_boot_any' binman symbols declared by BINMAN_UBOOT_SYMBOLS
requiring a U-Boot-like entry in the same image as the SPL.

However, a problem in the ARMv8 __image_copy_start symbol definition
effectively disables binman from attempting to write any symbols at all,
so everything appears to work fine until runtime. A future patch fixes
the issue in the linker scripts, which lets binman fill in the symbols,
which would result in the build error described above.

Explicitly disable the 'u_boot_any' symbols for i.MX8M boards. They are
already effectively unusable, and they are incompatible with the boards'
current binman image descriptions.

Signed-off-by: Alper Nebi Yasak 
---

Changes in v2:
- Add new patch to disable u_boot_any symbols for i.MX8M boards

 common/spl/Kconfig | 1 +
 common/spl/Kconfig.tpl | 1 +
 common/spl/Kconfig.vpl | 1 +
 3 files changed, 3 insertions(+)

Applied to u-boot-dm, thanks!


Re: [PATCH v2 6/8] spl: binman: Check at runtime if binman symbols were filled in

2022-06-28 Thread Simon Glass
Binman lets us declare symbols in SPL/TPL that refer to other entries in
the same binman image as them. These symbols are filled in with the
correct values while binman assembles the images, but this is done
in-memory only. Symbols marked as optional can be filled with
BINMAN_SYM_MISSING as an error value if their referred entry is missing.

However, the unmodified SPL/TPL binaries are still available on disk,
and can be used by people. For these files, nothing ensures that the
symbols are set to this error value, and they will be considered valid
when they are not.

Empirically, all symbols show up as zero in a sandbox_vpl build when we
run e.g. tpl/u-boot-tpl directly. On the other hand, zero is a perfectly
fine value for a binman-written symbol, so we cannot say the symbols
have wrong values based on that.

Declare a magic symbol that binman always fills in with a fixed value.
Check this value as an indicator that symbols were filled in correctly.
Return the error value for all symbols when this magic symbol has the
wrong value.

For binman tests, we need to make room for the new symbol in the mocked
SPL/TPL data by extending them by four bytes. This messes up some test
image layouts. Fix the affected values, and check the magic symbol
wherever it makes sense.

Signed-off-by: Alper Nebi Yasak 
---

(no changes since v1)

 common/spl/spl.c|  1 +
 include/binman_sym.h| 45 -
 tools/binman/elf.py | 12 --
 tools/binman/elf_test.py| 12 +++---
 tools/binman/ftest.py   | 33 +++
 tools/binman/test/021_image_pad.dts |  2 +-
 tools/binman/test/024_sorted.dts|  2 +-
 tools/binman/test/028_pack_4gb_outside.dts  |  2 +-
 tools/binman/test/029_x86_rom.dts   |  6 +--
 tools/binman/test/053_symbols.dts   |  2 +-
 tools/binman/test/149_symbols_tpl.dts   |  4 +-
 tools/binman/test/155_symbols_tpl_x86.dts   |  4 +-
 tools/binman/test/187_symbols_sub.dts   |  2 +-
 tools/binman/test/u_boot_binman_syms.c  |  4 ++
 tools/binman/test/u_boot_binman_syms_size.c |  4 ++
 15 files changed, 97 insertions(+), 38 deletions(-)

Applied to u-boot-dm, thanks!


Re: [PATCH v2 8/8] armv8: u-boot-spl.lds: mark __image_copy_start as symbol

2022-06-28 Thread Simon Glass
From: Peng Fan 

In arch/arm/lib/sections.c there is below code:
char __image_copy_start[0] __section(".__image_copy_start");
But actually 'objdump -t spl/u-boot-spl' not able to find out
symbol '__image_copy_start' for binman update image-pos/size.

So update link file

Signed-off-by: Peng Fan 
Reviewed-by: Tom Rini 
Reviewed-by: Alper Nebi Yasak 
---
This is from Peng's i.MX8M binman symbols series [1], picked it onto
this series because it made more sense as a binman symbols fix.

[1] armv8: u-boot-spl.lds: mark __image_copy_start as symbol
https://lore.kernel.org/u-boot/20220603071715.15212-5-peng@oss.nxp.com/

Changes in v2:
- Pick Peng's __image_copy_start fix

 arch/arm/cpu/armv8/u-boot-spl.lds | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Applied to u-boot-dm, thanks!


Re: [RFC] Data structure for information handoff between firmware boot stages

2022-06-20 Thread Simon Glass
ry can be soon integrated as a 
> community contribution!
>
> Please let us know if you (and the u-boot community) have additional comments 
> on the ALP1 spec.
>
> Kind Regards,
> Jose
>
>
> > -Original Message-
> > From: Simon Glass 
> > Sent: 03 May 2022 10:32
> > To: Jose Marinho 
> > Cc: u-boot@lists.denx.de; Heinrich Schuchardt ; Ilias
> > Apalodimas ; Tom Rini ;
> > Samer El-Haj-Mahmoud ; Manish
> > Pandey2 ; nd 
> > Subject: Re: [RFC] Data structure for information handoff between firmware
> > boot stages
> >
> > Hi Jose,
> >
> > On Tue, 3 May 2022 at 02:26, Jose Marinho  wrote:
> > >
> > > Hi Simon,
> > >
> > > Thank you for reviewing the draft proposal!
> > >
> > > Would you be able to share your review comments on the PDF?
> > > Currently the document is not in a markup form and is yet to be hosted in 
> > > a
> > repository. That's the intent for the long term.
> >
> > Yes it looks like I can do that, so will share with you when done.
> >
> > Regards,
> > Simon
> >
> > >
> > > Cheers,
> > > Jose
> > >
> > > > -Original Message-
> > > > From: Simon Glass 
> > > > Sent: 03 May 2022 08:59
> > > > To: Jose Marinho 
> > > > Cc: u-boot@lists.denx.de; Heinrich Schuchardt ;
> > > > Ilias Apalodimas ; Tom Rini
> > > > ; Samer El-Haj-Mahmoud
> > > > ; Manish Pandey2
> > > > ; nd 
> > > > Subject: Re: [RFC] Data structure for information handoff between
> > > > firmware boot stages
> > > >
> > > > Hi Jose,
> > > >
> > > > On Thu, 7 Apr 2022 at 13:23, Jose Marinho 
> > wrote:
> > > > >
> > > > > Hi All,
> > > > >
> > > > > The topic of information handoff between TF-A’s BL31 and BL33
> > > > > (e.g. U-boot
> > > > proper, EDK2) was discussed last year in the TF-A and U-boot mailing
> > > > lists [1], [2].
> > > > >
> > > > > Examples of information to be handed off between firmware stages
> > > > > are the
> > > > TPM log, HOB nodes, etc.
> > > > > Having a standard data structure which is usable/supported by
> > > > > every
> > > > community contributes to code reuse and leads to simpler codebase
> > > > maintenance.
> > > > >
> > > > > Some already existing data structures, such as the UEFI HOB list
> > > > > [3], and the
> > > > Bloblist from U-boot, were proposed to be employed for the handoffs.
> > > > > There are pros and cons with both HOBs and Bloblist.
> > > > > The discussion settled with a consensus that a data structure
> > > > > ought to be
> > > > defined which encapsulates the best traits of HOBs and Bloblist.
> > > > >
> > > > > Properties that the data structure should have:
> > > > > - node types identified by an integer,
> > > > > - easily relocatable,
> > > > >
> > > > > - straightforward to append new nodes,
> > > > > - easy to read and append to from resource constrained environments.
> > > > >
> > > > > The data structure should be suitable to pass information between
> > > > > different
> > > > firmware stages, such as:
> > > > > U-boot SPL -> BL31 -> U-boot
> > > > > BL1 -> BL2 -> BL31 -> U-boot
> > > > >
> > > > > As requested in the ML, an initial proposal was drafted [4].
> > > > > The document [4] is an initial proposal (at an alpha stage).
> > > > > The document [4] is being circulated for the purpose of gathering
> > > > > initial
> > > > feedback.
> > > > > This proposal is closely aligned with an ongoing effort in the
> > > > > u-boot mailing
> > > > list [5].
> > > > > The proposal defines 1) a set of standard nodes and 2) the
> > > > > registers used at
> > > > the handoff boundary.
> > > > >
> > > > > Standard nodes:
> > > > > - fdt node: HW description fdt,
> > > > > - HOB node,
> > > > > - ACPI table node: the main use-case for this node is to carry the TPM
> > log.
> > > > >
> > > > > The document [4] accommodate

Re: [PATCH v2 11/11] socfpga: arria10: Allow dcache_enable before relocation

2022-05-27 Thread Simon Glass
On Thu, 26 May 2022 at 07:38, Paweł Anikiel  wrote:
>
> Before relocating to SDRAM, the ECC is initialized by clearing the
> whole SDRAM. In order to speed this up, dcache_enable is used (see
> sdram_init_ecc_bits).
>
> Since commit 503eea451903 ("arm: cp15: update DACR value to activate
> access control"), this no longer works, because running code in OCRAM
> with the XN bit set causes a page fault. Override dram_bank_mmu_setup
> to disable XN in the OCRAM and setup DRAM dcache before relocation.
>
> Signed-off-by: Paweł Anikiel 
> ---
>  arch/arm/mach-socfpga/misc_arria10.c | 26 ++
>  1 file changed, 26 insertions(+)
>

Reviewed-by: Simon Glass 


Re: [PATCH v2 08/11] socfpga: arria10: Replace delays with busy waiting in cm_full_cfg

2022-05-27 Thread Simon Glass
On Thu, 26 May 2022 at 07:38, Paweł Anikiel  wrote:
>
> Using udelay while the clocks aren't fully configured causes the timer
> system to save the wrong clock rate. Use sdelay and wait_on_value
> instead (the values used in these functions were found experimentally).
>
> Signed-off-by: Paweł Anikiel 
> ---
>  arch/arm/mach-socfpga/clock_manager.c  |  7 ---
>  arch/arm/mach-socfpga/clock_manager_arria10.c  | 12 ++--
>  arch/arm/mach-socfpga/include/mach/clock_manager.h |  4 
>  3 files changed, 14 insertions(+), 9 deletions(-)

Reviewed-by: Simon Glass 


Re: [PATCH v2 10/11] socfpga: arria10: Wait for fifo empty after writing bitstream

2022-05-27 Thread Simon Glass
On Thu, 26 May 2022 at 07:38, Paweł Anikiel  wrote:
>
> For some reason, on the Mercury+ AA1 module, calling
> fpgamgr_wait_early_user_mode immediately after writing the peripheral
> bitstream leaves the fpga in a broken state (ddr calibration hangs).
> Adding a delay before the first sync word is written seems to fix this.
> Inspecting the fpgamgr registers before and after the delay,
> imgcfg_FifoEmpty is the only bit that changes. Waiting for this bit
> (instead of a hardcoded delay) also fixes the issue.
>
> Signed-off-by: Paweł Anikiel 
> ---
>  drivers/fpga/socfpga_arria10.c | 8 
>  1 file changed, 8 insertions(+)

Reviewed-by: Simon Glass 


Re: [PATCH v2 09/11] socfpga: arria10: Improve bitstream loading speed

2022-05-27 Thread Simon Glass
On Thu, 26 May 2022 at 07:38, Paweł Anikiel  wrote:
>
> Apply some optimizations to speed up bitstream loading
> (both for full and split periph/core bitstreams):
>
>  * Change the size of the first fs read, so that all the subsequent
>reads are aligned to a specific value (called MAX_FIRST_LOAD_SIZE).
>This value was chosen so that in subsequent reads the fat fs driver
>doesn't have to allocate a temporary buffer in get_contents
>(assuming 8KiB clusters).
>
>  * Change the buffer size to a larger value when reading to ddr
>(but not too large, because large transfers cause a stack overflow
>in the dwmmc driver).

When the size is too large, where exactly does that stack overflow happen?

>
> Signed-off-by: Paweł Anikiel 
> ---
>  drivers/fpga/socfpga_arria10.c | 20 ++--
>  1 file changed, 18 insertions(+), 2 deletions(-)
>

Reviewed-by: Simon Glass 


Re: [PATCH v2 07/11] sysreset: socfpga: Use parent device for reading base address

2022-05-27 Thread Simon Glass
On Thu, 26 May 2022 at 07:38, Paweł Anikiel  wrote:
>
> This driver is a child of the rstmgr driver, both of which share the
> same devicetree node. As a result, passing the child's udevice pointer
> to dev_read_addr_ptr results in a failure of reading the #address-cells
> property. Use the parent udevice pointer instead.
>
> Signed-off-by: Paweł Anikiel 
> ---
>  drivers/sysreset/sysreset_socfpga.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>

Reviewed-by: Simon Glass 


Re: [PATCH v2 05/11] config: Add Chameleonv3 config

2022-05-27 Thread Simon Glass
On Thu, 26 May 2022 at 07:38, Paweł Anikiel  wrote:
>
> Add defconfig and Kconfig files for Google Chameleon V3 board
>
> Signed-off-by: Paweł Anikiel 
> ---
>  arch/arm/mach-socfpga/Kconfig |  7 +
>  configs/socfpga_chameleonv3_defconfig | 29 ++
>  include/configs/socfpga_chameleonv3.h | 44 +++
>  3 files changed, 80 insertions(+)
>  create mode 100644 configs/socfpga_chameleonv3_defconfig
>  create mode 100644 include/configs/socfpga_chameleonv3.h
>

Reviewed-by: Simon Glass 


Re: [PATCH v2 06/11] misc: atsha204a: Increase wake delay by tWHI

2022-05-27 Thread Simon Glass
On Thu, 26 May 2022 at 07:38, Paweł Anikiel  wrote:
>
> From the ATSHA204A datasheet (document DS40002025A):
>
> Wake: If SDA is held low for a period greater than tWLO, the device
> exits low-power mode and, after a delay of tWHI, is ready to receive
> I2C commands.
>
> tWHI value can be found in table 7-2.
>
> Signed-off-by: Paweł Anikiel 
> ---
>  drivers/misc/atsha204a-i2c.c | 5 +++--
>  1 file changed, 3 insertions(+), 2 deletions(-)
>

Reviewed-by: Simon Glass 


Re: [PATCH v2 03/11] arm: dts: Add Chameleonv3 devicetrees

2022-05-27 Thread Simon Glass
On Thu, 26 May 2022 at 07:37, Paweł Anikiel  wrote:
>
> Add devicetrees for Google Chameleon V3 board
>
> Signed-off-by: Paweł Anikiel 
> Signed-off-by: Alexandru M Stan 
> ---
>  arch/arm/dts/Makefile |  2 +
>  arch/arm/dts/socfpga_arria10_chameleonv3.dts  | 90 +++
>  ...fpga_arria10_chameleonv3_270_3-u-boot.dtsi |  8 ++
>  .../dts/socfpga_arria10_chameleonv3_270_3.dts |  5 ++
>  ...fpga_arria10_chameleonv3_480_2-u-boot.dtsi |  8 ++
>  .../dts/socfpga_arria10_chameleonv3_480_2.dts |  5 ++
>  6 files changed, 118 insertions(+)
>  create mode 100644 arch/arm/dts/socfpga_arria10_chameleonv3.dts
>  create mode 100644 arch/arm/dts/socfpga_arria10_chameleonv3_270_3-u-boot.dtsi
>  create mode 100644 arch/arm/dts/socfpga_arria10_chameleonv3_270_3.dts
>  create mode 100644 arch/arm/dts/socfpga_arria10_chameleonv3_480_2-u-boot.dtsi
>  create mode 100644 arch/arm/dts/socfpga_arria10_chameleonv3_480_2.dts
>

Reviewed-by: Simon Glass 


Re: [PATCH v2 04/11] board: Add Chameleonv3 board dir

2022-05-27 Thread Simon Glass
On Thu, 26 May 2022 at 07:37, Paweł Anikiel  wrote:
>
> Add board directory for Google Chameleon V3 board
>
> Signed-off-by: Paweł Anikiel 
> ---
>  board/google/chameleonv3/Makefile  |  5 +++
>  board/google/chameleonv3/board.c   | 27 ++
>  board/google/chameleonv3/fpga.its  | 28 ++
>  board/google/chameleonv3/fpga_early_io.its | 35 ++
>  board/google/chameleonv3/mercury_aa1.c | 43 ++
>  board/google/chameleonv3/mercury_aa1.h | 12 ++
>  6 files changed, 150 insertions(+)
>  create mode 100644 board/google/chameleonv3/Makefile
>  create mode 100644 board/google/chameleonv3/board.c
>  create mode 100644 board/google/chameleonv3/fpga.its
>  create mode 100644 board/google/chameleonv3/fpga_early_io.its
>  create mode 100644 board/google/chameleonv3/mercury_aa1.c
>  create mode 100644 board/google/chameleonv3/mercury_aa1.h

Reviewed-by: Simon Glass 


Re: [PATCH v2 02/11] arm: dts: Add Chameleonv3 handoff headers

2022-05-27 Thread Simon Glass
On Thu, 26 May 2022 at 07:37, Paweł Anikiel  wrote:
>
> Add handoff headers for the Google Chameleonv3 variants: 480-2 and
> 270-3. Both files were generated using qts-filter-a10.sh.
>
> Signed-off-by: Paweł Anikiel 
> ---
>  ...ocfpga_arria10_chameleonv3_270_3_handoff.h | 305 ++
>  ...ocfpga_arria10_chameleonv3_480_2_handoff.h | 305 ++
>  2 files changed, 610 insertions(+)
>  create mode 100644 arch/arm/dts/socfpga_arria10_chameleonv3_270_3_handoff.h
>  create mode 100644 arch/arm/dts/socfpga_arria10_chameleonv3_480_2_handoff.h
>

Reviewed-by: Simon Glass 


Re: [PATCH v2 01/11] arm: dts: Add Mercury+ AA1 devicetrees

2022-05-27 Thread Simon Glass
On Thu, 26 May 2022 at 07:37, Paweł Anikiel  wrote:
>
> Devicetree headers for Mercury+ AA1 module
>
> Signed-off-by: Paweł Anikiel 
> ---
>  .../socfpga_arria10_mercury_aa1-u-boot.dtsi   | 54 ++
>  arch/arm/dts/socfpga_arria10_mercury_aa1.dtsi | 72 +++
>  2 files changed, 126 insertions(+)
>  create mode 100644 arch/arm/dts/socfpga_arria10_mercury_aa1-u-boot.dtsi
>  create mode 100644 arch/arm/dts/socfpga_arria10_mercury_aa1.dtsi

Reviewed-by: Simon Glass 


[PATCH 9/9] dm: spl: Allow SPL to show memory usage

2022-05-08 Thread Simon Glass
Add an option to tell SPL to show memory usage for driver model just
before it boots into the next phase.

Signed-off-by: Simon Glass 
---

 common/spl/spl.c |  9 +
 drivers/core/Kconfig | 10 ++
 2 files changed, 19 insertions(+)

diff --git a/common/spl/spl.c b/common/spl/spl.c
index c8c463f80bd..540e1925577 100644
--- a/common/spl/spl.c
+++ b/common/spl/spl.c
@@ -33,6 +33,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -780,6 +781,14 @@ void board_init_r(gd_t *dummy1, ulong dummy2)
 
bootcount_inc();
 
+   /* Dump driver model states to aid analysis */
+   if (CONFIG_IS_ENABLED(DM_STATS)) {
+   struct dm_stats mem;
+
+   dm_get_mem();
+   dm_dump_mem();
+   }
+
memset(_image, '\0', sizeof(spl_image));
 #ifdef CONFIG_SYS_SPL_ARGS_ADDR
spl_image.arg = (void *)CONFIG_SYS_SPL_ARGS_ADDR;
diff --git a/drivers/core/Kconfig b/drivers/core/Kconfig
index fa2811af83c..5c35914d30b 100644
--- a/drivers/core/Kconfig
+++ b/drivers/core/Kconfig
@@ -86,6 +86,16 @@ config DM_STATS
 
  To display the memory stats, use the 'dm mem' command.
 
+config SPL_DM_STATS
+   bool "Collect and show driver model stats in SPL"
+   depends on DM_SPL
+   help
+ Enable this to collect and display memory statistics about driver
+ model. This can help to figure out where all the memory is going and
+ to find optimisations.
+
+ The stats are displayed just before SPL boots to the next phase.
+
 config DM_DEVICE_REMOVE
bool "Support device removal"
depends on DM
-- 
2.36.0.512.ge40c2bad7a-goog



[PATCH 8/9] dm: core: Add a command to show driver model statistics

2022-05-08 Thread Simon Glass
This command shows the memory used by driver model along with various
hints as to what it might be if some 'core' tags were moved to use the
tag list instead of a core (i.e. always-there) pointer.

This may help with future work to reduce memory usage.

Signed-off-by: Simon Glass 
---

 cmd/dm.c | 23 ++
 drivers/core/Kconfig | 11 +++
 drivers/core/dump.c  | 73 
 drivers/core/tag.c   | 18 +++
 include/dm/root.h|  2 +-
 include/dm/tag.h |  8 +
 include/dm/util.h|  9 ++
 7 files changed, 143 insertions(+), 1 deletion(-)

diff --git a/cmd/dm.c b/cmd/dm.c
index 4c0a8a53ced..3814dcd20f1 100644
--- a/cmd/dm.c
+++ b/cmd/dm.c
@@ -40,6 +40,19 @@ static int do_dm_dump_drivers(struct cmd_tbl *cmdtp, int 
flag, int argc,
return 0;
 }
 
+#if CONFIG_IS_ENABLED(DM_STATS)
+static int do_dm_dump_mem(struct cmd_tbl *cmdtp, int flag, int argc,
+ char *const argv[])
+{
+   struct dm_stats mem;
+
+   dm_get_mem();
+   dm_dump_mem();
+
+   return 0;
+}
+#endif /* DM_STATS */
+
 static int do_dm_dump_static_driver_info(struct cmd_tbl *cmdtp, int flag,
 int argc, char * const argv[])
 {
@@ -68,6 +81,9 @@ static struct cmd_tbl test_commands[] = {
U_BOOT_CMD_MKENT(compat, 1, 1, do_dm_dump_driver_compat, "", ""),
U_BOOT_CMD_MKENT(devres, 1, 1, do_dm_dump_devres, "", ""),
U_BOOT_CMD_MKENT(drivers, 1, 1, do_dm_dump_drivers, "", ""),
+#if CONFIG_IS_ENABLED(DM_STATS)
+   U_BOOT_CMD_MKENT(mem, 1, 1, do_dm_dump_mem, "", ""),
+#endif
U_BOOT_CMD_MKENT(static, 1, 1, do_dm_dump_static_driver_info, "", ""),
U_BOOT_CMD_MKENT(tree, 0, 1, do_dm_dump_tree, "", ""),
U_BOOT_CMD_MKENT(uclass, 1, 1, do_dm_dump_uclass, "", ""),
@@ -106,12 +122,19 @@ static int do_dm(struct cmd_tbl *cmdtp, int flag, int 
argc, char *const argv[])
return cmd_process_error(test_cmd, ret);
 }
 
+#if CONFIG_IS_ENABLED(DM_STATS)
+#define DM_MEM_HELP"dm mem   Provide a summary of memory usage\n"
+#else
+#define DM_MEM_HELP
+#endif
+
 U_BOOT_CMD(
dm, 3,  1,  do_dm,
"Driver model low level access",
"compatDump list of drivers with compatibility strings\n"
"dm devresDump list of device resources for each device\n"
"dm drivers   Dump list of drivers with uclass and instances\n"
+   DM_MEM_HELP
"dm staticDump list of drivers with static platform data\n"
"dm tree  Dump tree of driver model devices ('*' = activated)\n"
"dm uclassDump list of instances for each uclass"
diff --git a/drivers/core/Kconfig b/drivers/core/Kconfig
index 408a8d8e28b..fa2811af83c 100644
--- a/drivers/core/Kconfig
+++ b/drivers/core/Kconfig
@@ -75,6 +75,17 @@ config DM_DEBUG
help
  Say Y here if you want to compile in debug messages in DM core.
 
+config DM_STATS
+   bool "Collect and show driver model stats"
+   depends on DM
+   default y if SANDBOX
+   help
+ Enable this to collect and display memory statistics about driver
+ model. This can help to figure out where all the memory is going and
+ to find optimisations.
+
+ To display the memory stats, use the 'dm mem' command.
+
 config DM_DEVICE_REMOVE
bool "Support device removal"
depends on DM
diff --git a/drivers/core/dump.c b/drivers/core/dump.c
index ce679e26290..43d1349635b 100644
--- a/drivers/core/dump.c
+++ b/drivers/core/dump.c
@@ -174,3 +174,76 @@ void dm_dump_static_driver_info(void)
for (entry = drv; entry != drv + n_ents; entry++)
printf("%-25.25s %p\n", entry->name, entry->plat);
 }
+
+void dm_dump_mem(struct dm_stats *stats)
+{
+   int total, total_delta;
+   int i;
+
+   /* Support SPL printf() */
+   printf("Struct sizes: udevice %x, driver %x, uclass %x, uc_driver %x\n",
+  (int)sizeof(struct udevice), (int)sizeof(struct driver),
+  (int)sizeof(struct uclass), (int)sizeof(struct uclass_driver));
+   printf("Memory: device %x:%x, device names %x, uclass %x:%x\n",
+  stats->dev_count, stats->dev_size, stats->dev_name_size,
+  stats->uc_count, stats->uc_size);
+   printf("\n");
+   printf("%-15s  %5s  %5s  %5s  %5s  %5s\n", "Attached type", "Count",
+  "Size", "Cur", "Tags", "Save");
+   printf("%-15s  %5s  %5s  %5s  %5s  %5s\n", "---", "-",
+  "

[PATCH 7/9] dm: core: Add a way to collect memory usage

2022-05-08 Thread Simon Glass
Add a function for collecting the amount of memory used by driver model,
including devices, uclasses and attached data and tags.

This information can provide insights into how to reduce the memory
required by driver model. Future work may look at execution speed also.

Signed-off-by: Simon Glass 
---

 drivers/core/root.c | 53 +
 drivers/core/tag.c  | 11 ++
 include/dm/root.h   | 45 ++
 include/dm/tag.h| 11 ++
 test/dm/core.c  | 11 ++
 5 files changed, 131 insertions(+)

diff --git a/drivers/core/root.c b/drivers/core/root.c
index 17dd1205a32..f24ddfa5218 100644
--- a/drivers/core/root.c
+++ b/drivers/core/root.c
@@ -449,6 +449,59 @@ void dm_get_stats(int *device_countp, int *uclass_countp)
*uclass_countp = uclass_get_count();
 }
 
+void dev_collect_stats(struct dm_stats *stats, const struct udevice *parent)
+{
+   const struct udevice *dev;
+   int i;
+
+   stats->dev_count++;
+   stats->dev_size += sizeof(struct udevice);
+   stats->dev_name_size += strlen(parent->name) + 1;
+   for (i = 0; i < DM_TAG_ATTACH_COUNT; i++) {
+   int size = dev_get_attach_size(parent, i);
+
+   if (size ||
+   (i == DM_TAG_DRIVER_DATA && parent->driver_data)) {
+   stats->attach_count[i]++;
+   stats->attach_size[i] += size;
+   stats->attach_count_total++;
+   stats->attach_size_total += size;
+   }
+   }
+
+   list_for_each_entry(dev, >child_head, sibling_node)
+   dev_collect_stats(stats, dev);
+}
+
+void uclass_collect_stats(struct dm_stats *stats)
+{
+   struct uclass *uc;
+
+   list_for_each_entry(uc, gd->uclass_root, sibling_node) {
+   int size;
+
+   stats->uc_count++;
+   stats->uc_size += sizeof(struct uclass);
+   size = uc->uc_drv->priv_auto;
+   if (size) {
+   stats->uc_attach_count++;
+   stats->uc_attach_size += size;
+   }
+   }
+}
+
+void dm_get_mem(struct dm_stats *stats)
+{
+   memset(stats, '\0', sizeof(*stats));
+   dev_collect_stats(stats, gd->dm_root);
+   uclass_collect_stats(stats);
+   dev_tag_collect_stats(stats);
+
+   stats->total_size = stats->dev_size + stats->uc_size +
+   stats->attach_size_total + stats->uc_attach_size +
+   stats->tag_size;
+}
+
 #ifdef CONFIG_ACPIGEN
 static int root_acpi_get_name(const struct udevice *dev, char *out_name)
 {
diff --git a/drivers/core/tag.c b/drivers/core/tag.c
index 22999193a5a..2961725b658 100644
--- a/drivers/core/tag.c
+++ b/drivers/core/tag.c
@@ -6,6 +6,7 @@
 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -137,3 +138,13 @@ int dev_tag_del_all(struct udevice *dev)
 
return -ENOENT;
 }
+
+void dev_tag_collect_stats(struct dm_stats *stats)
+{
+   struct dmtag_node *node;
+
+   list_for_each_entry(node, >dmtag_list, sibling) {
+   stats->tag_count++;
+   stats->tag_size += sizeof(struct dmtag_node);
+   }
+}
diff --git a/include/dm/root.h b/include/dm/root.h
index e888fb993c0..382f83c7f5b 100644
--- a/include/dm/root.h
+++ b/include/dm/root.h
@@ -9,11 +9,49 @@
 #ifndef _DM_ROOT_H_
 #define _DM_ROOT_H_
 
+#include 
+
 struct udevice;
 
 /* Head of the uclass list if CONFIG_OF_PLATDATA_INST is enabled */
 extern struct list_head uclass_head;
 
+/**
+ * struct dm_stats - Information about driver model memory usage
+ *
+ * @total_size: All data
+ * @dev_count: Number of devices
+ * @dev_size: Size of all devices (just the struct udevice)
+ * @dev_name_size: Bytes used by device names
+ * @uc_count: Number of uclasses
+ * @uc_size: Size of all uclasses (just the struct uclass)
+ * @tag_count: Number of tags
+ * @tag_size: Bytes used by all tags
+ * @uc_attach_count: Number of uclasses with attached data (priv)
+ * @uc_attach_size: Total size of that attached data
+ * @attach_count_total: Total number of attached data items for all udevices 
and
+ * uclasses
+ * @attach_size_total: Total number of bytes of attached data
+ * @attach_count: Number of devices with attached, for each type
+ * @attach_size: Total number of bytes of attached data, for each type
+ */
+struct dm_stats {
+   int total_size;
+   int dev_count;
+   int dev_size;
+   int dev_name_size;
+   int uc_count;
+   int uc_size;
+   int tag_count;
+   int tag_size;
+   int uc_attach_count;
+   int uc_attach_size;
+   int attach_count_total;
+   int attach_size_total;
+   int attach_count[DM_TAG_ATTACH_COUNT];
+   int attach_size[DM_TAG_ATTACH_COUNT];
+};
+
 /**
  * dm_root() - Return pointer to the top of the driver tre

[PATCH 5/9] dm: core: Switch the testbus driver to use a new struct

2022-05-08 Thread Simon Glass
At present this driver uses 'priv' struct to hold 'plat' data, which is
confusing. The contents of the strct don't matter, since only dtoc is
using it. Create a new struct with the correct name.

Signed-off-by: Simon Glass 
---

 drivers/misc/test_drv.c | 2 +-
 include/dm/test.h   | 7 +++
 tools/dtoc/test_dtoc.py | 2 +-
 3 files changed, 9 insertions(+), 2 deletions(-)

diff --git a/drivers/misc/test_drv.c b/drivers/misc/test_drv.c
index 5d72982f258..b6df1189032 100644
--- a/drivers/misc/test_drv.c
+++ b/drivers/misc/test_drv.c
@@ -109,7 +109,7 @@ UCLASS_DRIVER(testbus) = {
.child_post_probe = testbus_child_post_probe_uclass,
 
/* This is for dtoc testing only */
-   .per_device_plat_auto   = sizeof(struct dm_test_uclass_priv),
+   .per_device_plat_auto   = sizeof(struct dm_test_uclass_plat),
 };
 
 static int testfdt_drv_ping(struct udevice *dev, int pingval, int *pingret)
diff --git a/include/dm/test.h b/include/dm/test.h
index 4919064cc02..b5937509212 100644
--- a/include/dm/test.h
+++ b/include/dm/test.h
@@ -92,6 +92,13 @@ struct dm_test_uclass_priv {
int total_add;
 };
 
+/**
+ * struct dm_test_uclass_plat - private plat data for test uclass
+ */
+struct dm_test_uclass_plat {
+   char dummy[32];
+};
+
 /**
  * struct dm_test_parent_data - parent's information on each child
  *
diff --git a/tools/dtoc/test_dtoc.py b/tools/dtoc/test_dtoc.py
index c81bcc9c32f..8bac2076214 100755
--- a/tools/dtoc/test_dtoc.py
+++ b/tools/dtoc/test_dtoc.py
@@ -616,7 +616,7 @@ struct dm_test_pdata __attribute__ ((section 
(".priv_data")))
 u8 _denx_u_boot_test_bus_priv_some_bus[sizeof(struct dm_test_priv)]
 \t__attribute__ ((section (".priv_data")));
 #include 
-u8 _denx_u_boot_test_bus_ucplat_some_bus[sizeof(struct dm_test_uclass_priv)]
+u8 _denx_u_boot_test_bus_ucplat_some_bus[sizeof(struct dm_test_uclass_plat)]
 \t__attribute__ ((section (".priv_data")));
 #include 
 
-- 
2.36.0.512.ge40c2bad7a-goog



[PATCH 4/9] dm: core: Add documentation for the dm command

2022-05-08 Thread Simon Glass
Add a description and examples for the dm subcommands.

Signed-off-by: Simon Glass 
---

 doc/usage/cmd/dm.rst | 487 +++
 doc/usage/index.rst  |   1 +
 2 files changed, 488 insertions(+)
 create mode 100644 doc/usage/cmd/dm.rst

diff --git a/doc/usage/cmd/dm.rst b/doc/usage/cmd/dm.rst
new file mode 100644
index 000..7bc1962a754
--- /dev/null
+++ b/doc/usage/cmd/dm.rst
@@ -0,0 +1,487 @@
+.. SPDX-License-Identifier: GPL-2.0+:
+
+dm command
+==
+
+Synopis
+---
+
+::
+
+dm compat
+dm devres
+dm drivers
+dm static
+dm tree
+dm uclass
+
+Description
+---
+
+The *dm* command allows viewing information about driver model, including the
+tree of devices and list of available uclasses.
+
+
+dm compat
+~
+
+This shows the compatible strings associated with each driver. Often there
+is only one, but multiple strings are shown on their own line. These strings
+can be looked up in the device tree files for each board, to see which driver 
is
+used for each node.
+
+dm devres
+~
+
+This shows a list of a `devres` (device resource) records for a device. Some
+drivers use the devres API to allocate memory, so that it can be freed
+automatically (without any code needed in the driver's remove() method) when 
the
+device is removed.
+
+This feature is controlled by CONFIG_DEVRES so no useful output is obtained if
+this option is disabled.
+
+dm drivers
+~~
+
+This shows all the available drivers, their uclass and a list of devices that
+use that driver, each on its own line. Drivers with no devices are shown with
+`` as the driver name.
+
+
+dm mem
+~~
+
+This subcommand is really just for debugging and exploration. It can be enabled
+with the `CONFIG_DM_STATS` option.
+
+All output is in hex except that in brackets which is decimal.
+
+The output consists of a header shows the size of the main device model
+structures (struct udevice, struct driver, struct uclass and struct uc_driver)
+and the count and memory used by each (number of devices, memory used by
+devices, memory used by device names, number of uclasses, memory used by
+uclasses).
+
+After that is a table of information about each type of data that can be
+attached to a device, showing the number that have non-null data for that type,
+the total size of all that data, the amount of memory used in total, the
+amount that would be used if this type uses tags instead and the amount that
+would be thus saved.
+
+The `driver_data` line shows the number of devices which have non-NULL driver
+data.
+
+The `tags` line shows the number of tags and the memory used by those.
+
+At the bottom is an indication of the total memory usage obtained by 
undertaking
+various changes, none of which is currently implemented in U-Boot:
+
+With tags
+Using tags instead of all attached types
+
+Singly linked
+Using a singly linked list
+
+driver index
+Using a driver index instead of a pointer
+
+uclass index
+Using a uclass index instead of a pointer
+
+Drop device name
+Using empty device names
+
+
+dm static
+~
+
+This shows devices bound by platform data, i.e. not from the device tree. There
+are normally none of these, but some boards may use static devices for space
+reasons.
+
+
+dm tree
+~~~
+
+This shows the full tree of devices including the following fields:
+
+uclass
+Shows the name of the uclass for the device
+
+Index
+Shows the index number of the device, within the uclass. This shows the
+ordering within the uclass, but not the sequence number.
+
+Probed
+Shows `+` if the device is active
+
+Driver
+Shows the name of the driver that this device uses
+
+Name
+Shows the device name as well as the tree structure, since child devices 
are
+shown attached to their parent.
+
+
+dm uclass
+~
+
+This shows each uclass along with a list of devices in that uclass. The uclass
+ID is shown (e.g. uclass 7) and its name.
+
+For each device, the format is::
+
+nname @ a, seq s
+
+where `n` is the index within the uclass, `a` is the address of the device in
+memory and `s` is the sequence number of the device.
+
+
+Examples
+
+
+dm compat
+~
+
+This example shows an abridged version of the sandbox output::
+
+=> dm compat
+DriverCompatible
+
+act8846_reg
+sandbox_adder sandbox,adder
+axi_sandbox_bus   sandbox,axi
+blk_partition
+bootcount-rtc u-boot,bootcount-rtc
+...
+rockchip_rk805rockchip,rk805
+  rockchip,rk808
+  rockchip,rk809
+  rockchip,rk816
+  rockchip,rk817
+  rockchip,rk818
+root_driver
+rtc-rv8803microcrystal,rv8803
+  epson,rx8803
+  epson,rx8

[PATCH 6/9] dm: core: Support accessing core tags

2022-05-08 Thread Simon Glass
At present tag numbers are only allocated for non-core data, meaning that
the 'core' data, like priv and plat, are accessed through dedicated
functions.

For debugging and consistency it is convenient to use tags for this 'core'
data too. Add support for this, with new tag numbers and functions to
access the pointer and size for each.

Update one of the test drivers so that the uclass-private data can be
tested here.

There is some code duplication with functions like device_alloc_priv() but
this is not addressed for now. At some point, some rationalisation may
help to reduce code size, but more thought it needed on that.

Signed-off-by: Simon Glass 
---

 drivers/core/device.c   | 65 +
 drivers/misc/test_drv.c |  4 ++-
 include/dm/device.h | 25 +
 include/dm/tag.h| 13 ++-
 test/dm/core.c  | 80 +
 tools/dtoc/test_dtoc.py |  4 +++
 6 files changed, 189 insertions(+), 2 deletions(-)

diff --git a/drivers/core/device.c b/drivers/core/device.c
index 3ab2583df38..d7936a46732 100644
--- a/drivers/core/device.c
+++ b/drivers/core/device.c
@@ -680,6 +680,71 @@ void *dev_get_parent_priv(const struct udevice *dev)
return dm_priv_to_rw(dev->parent_priv_);
 }
 
+void *dev_get_attach_ptr(const struct udevice *dev, enum dm_tag_t tag)
+{
+   switch (tag) {
+   case DM_TAG_PLAT:
+   return dev_get_plat(dev);
+   case DM_TAG_PARENT_PLAT:
+   return dev_get_parent_plat(dev);
+   case DM_TAG_UC_PLAT:
+   return dev_get_uclass_plat(dev);
+   case DM_TAG_PRIV:
+   return dev_get_priv(dev);
+   case DM_TAG_PARENT_PRIV:
+   return dev_get_parent_priv(dev);
+   case DM_TAG_UC_PRIV:
+   return dev_get_uclass_priv(dev);
+   default:
+   return NULL;
+   }
+}
+
+int dev_get_attach_size(const struct udevice *dev, enum dm_tag_t tag)
+{
+   const struct udevice *parent = dev_get_parent(dev);
+   const struct uclass *uc = dev->uclass;
+   const struct uclass_driver *uc_drv = uc->uc_drv;
+   const struct driver *parent_drv = NULL;
+   int size = 0;
+
+   if (parent)
+   parent_drv = parent->driver;
+
+   switch (tag) {
+   case DM_TAG_PLAT:
+   size = dev->driver->plat_auto;
+   break;
+   case DM_TAG_PARENT_PLAT:
+   if (parent) {
+   size = parent_drv->per_child_plat_auto;
+   if (!size)
+   size = 
parent->uclass->uc_drv->per_child_plat_auto;
+   }
+   break;
+   case DM_TAG_UC_PLAT:
+   size = uc_drv->per_device_plat_auto;
+   break;
+   case DM_TAG_PRIV:
+   size = dev->driver->priv_auto;
+   break;
+   case DM_TAG_PARENT_PRIV:
+   if (parent) {
+   size = parent_drv->per_child_auto;
+   if (!size)
+   size = parent->uclass->uc_drv->per_child_auto;
+   }
+   break;
+   case DM_TAG_UC_PRIV:
+   size = uc_drv->per_device_auto;
+   break;
+   default:
+   break;
+   }
+
+   return size;
+}
+
 static int device_get_device_tail(struct udevice *dev, int ret,
  struct udevice **devp)
 {
diff --git a/drivers/misc/test_drv.c b/drivers/misc/test_drv.c
index b6df1189032..927618256f0 100644
--- a/drivers/misc/test_drv.c
+++ b/drivers/misc/test_drv.c
@@ -108,7 +108,9 @@ UCLASS_DRIVER(testbus) = {
.child_pre_probe = testbus_child_pre_probe_uclass,
.child_post_probe = testbus_child_post_probe_uclass,
 
-   /* This is for dtoc testing only */
+   .per_device_auto   = sizeof(struct dm_test_uclass_priv),
+
+   /* Note: this is for dtoc testing as well as tags*/
.per_device_plat_auto   = sizeof(struct dm_test_uclass_plat),
 };
 
diff --git a/include/dm/device.h b/include/dm/device.h
index 5bdb10653f8..12c6ba37ff3 100644
--- a/include/dm/device.h
+++ b/include/dm/device.h
@@ -11,6 +11,7 @@
 #define _DM_DEVICE_H
 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -546,6 +547,30 @@ void *dev_get_parent_priv(const struct udevice *dev);
  */
 void *dev_get_uclass_priv(const struct udevice *dev);
 
+/**
+ * dev_get_attach_ptr() - Get the value of an attached pointed tag
+ *
+ * The tag is assumed to hold a pointer, if it exists
+ *
+ * @dev: Device to look at
+ * @tag: Tag to access
+ * @return value of tag, or NULL if there is no tag of this type
+ */
+void *dev_get_attach_ptr(const struct udevice *dev, enum dm_tag_t tag);
+
+/**
+ * dev_get_attach_size() - Get the size of an attached tag
+ *
+ * Core tags have an automatic-allocation mechanism where the allocated size is
+ * defined by the devi

[PATCH 3/9] dm: core: Fix addresses in the dm static command

2022-05-08 Thread Simon Glass
This command converts pointers to addresses, but the pointers being
converted are in the image's rodata region. For sandbox this means it
is not in DRAM so it does not make sense to do this conversion.

Fix this by showing a simple pointer instead. Drop the unnecessary
@ and hex prefixes.

Signed-off-by: Simon Glass 
---

 drivers/core/dump.c | 6 ++
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/drivers/core/dump.c b/drivers/core/dump.c
index 606883ac941..ce679e26290 100644
--- a/drivers/core/dump.c
+++ b/drivers/core/dump.c
@@ -171,8 +171,6 @@ void dm_dump_static_driver_info(void)
 
puts("DriverAddress\n");
puts("-\n");
-   for (entry = drv; entry != drv + n_ents; entry++) {
-   printf("%-25.25s @%08lx\n", entry->name,
-  (ulong)map_to_sysmem(entry->plat));
-   }
+   for (entry = drv; entry != drv + n_ents; entry++)
+   printf("%-25.25s %p\n", entry->name, entry->plat);
 }
-- 
2.36.0.512.ge40c2bad7a-goog



[PATCH 2/9] dm: core: Sort dm subcommands

2022-05-08 Thread Simon Glass
Put these in alphabetic order, both in the help and in the implementation,
as there are quite a few subcommands now. Tweak the help for 'dm tree' to
better explain what it does.

Signed-off-by: Simon Glass 
---

 cmd/dm.c | 48 
 1 file changed, 24 insertions(+), 24 deletions(-)

diff --git a/cmd/dm.c b/cmd/dm.c
index cb4c358e942..4c0a8a53ced 100644
--- a/cmd/dm.c
+++ b/cmd/dm.c
@@ -16,18 +16,10 @@
 #include 
 #include 
 
-static int do_dm_dump_tree(struct cmd_tbl *cmdtp, int flag, int argc,
-  char *const argv[])
-{
-   dm_dump_tree();
-
-   return 0;
-}
-
-static int do_dm_dump_uclass(struct cmd_tbl *cmdtp, int flag, int argc,
-char *const argv[])
+static int do_dm_dump_driver_compat(struct cmd_tbl *cmdtp, int flag, int argc,
+   char * const argv[])
 {
-   dm_dump_uclass();
+   dm_dump_driver_compat();
 
return 0;
 }
@@ -48,29 +40,37 @@ static int do_dm_dump_drivers(struct cmd_tbl *cmdtp, int 
flag, int argc,
return 0;
 }
 
-static int do_dm_dump_driver_compat(struct cmd_tbl *cmdtp, int flag, int argc,
-   char * const argv[])
+static int do_dm_dump_static_driver_info(struct cmd_tbl *cmdtp, int flag,
+int argc, char * const argv[])
 {
-   dm_dump_driver_compat();
+   dm_dump_static_driver_info();
 
return 0;
 }
 
-static int do_dm_dump_static_driver_info(struct cmd_tbl *cmdtp, int flag, int 
argc,
-char * const argv[])
+static int do_dm_dump_tree(struct cmd_tbl *cmdtp, int flag, int argc,
+  char *const argv[])
 {
-   dm_dump_static_driver_info();
+   dm_dump_tree();
+
+   return 0;
+}
+
+static int do_dm_dump_uclass(struct cmd_tbl *cmdtp, int flag, int argc,
+char *const argv[])
+{
+   dm_dump_uclass();
 
return 0;
 }
 
 static struct cmd_tbl test_commands[] = {
-   U_BOOT_CMD_MKENT(tree, 0, 1, do_dm_dump_tree, "", ""),
-   U_BOOT_CMD_MKENT(uclass, 1, 1, do_dm_dump_uclass, "", ""),
+   U_BOOT_CMD_MKENT(compat, 1, 1, do_dm_dump_driver_compat, "", ""),
U_BOOT_CMD_MKENT(devres, 1, 1, do_dm_dump_devres, "", ""),
U_BOOT_CMD_MKENT(drivers, 1, 1, do_dm_dump_drivers, "", ""),
-   U_BOOT_CMD_MKENT(compat, 1, 1, do_dm_dump_driver_compat, "", ""),
U_BOOT_CMD_MKENT(static, 1, 1, do_dm_dump_static_driver_info, "", ""),
+   U_BOOT_CMD_MKENT(tree, 0, 1, do_dm_dump_tree, "", ""),
+   U_BOOT_CMD_MKENT(uclass, 1, 1, do_dm_dump_uclass, "", ""),
 };
 
 static __maybe_unused void dm_reloc(void)
@@ -109,10 +109,10 @@ static int do_dm(struct cmd_tbl *cmdtp, int flag, int 
argc, char *const argv[])
 U_BOOT_CMD(
dm, 3,  1,  do_dm,
"Driver model low level access",
-   "tree  Dump driver model tree ('*' = activated)\n"
-   "dm uclassDump list of instances for each uclass\n"
+   "compatDump list of drivers with compatibility strings\n"
"dm devresDump list of device resources for each device\n"
"dm drivers   Dump list of drivers with uclass and instances\n"
-   "dm compatDump list of drivers with compatibility strings\n"
-   "dm staticDump list of drivers with static platform data"
+   "dm staticDump list of drivers with static platform data\n"
+   "dm tree  Dump tree of driver model devices ('*' = activated)\n"
+   "dm uclassDump list of instances for each uclass"
 );
-- 
2.36.0.512.ge40c2bad7a-goog



[PATCH 1/9] dm: core: Rename dm_dump_all()

2022-05-08 Thread Simon Glass
This is not a good name anymore as it does not dump everything. Rename it
to dm_dump_tree() to avoid confusion.

Signed-off-by: Simon Glass 
---

 cmd/dm.c| 8 
 drivers/core/dump.c | 2 +-
 include/dm/util.h   | 2 +-
 3 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/cmd/dm.c b/cmd/dm.c
index 1dd19fe45b5..cb4c358e942 100644
--- a/cmd/dm.c
+++ b/cmd/dm.c
@@ -16,10 +16,10 @@
 #include 
 #include 
 
-static int do_dm_dump_all(struct cmd_tbl *cmdtp, int flag, int argc,
- char *const argv[])
+static int do_dm_dump_tree(struct cmd_tbl *cmdtp, int flag, int argc,
+  char *const argv[])
 {
-   dm_dump_all();
+   dm_dump_tree();
 
return 0;
 }
@@ -65,7 +65,7 @@ static int do_dm_dump_static_driver_info(struct cmd_tbl 
*cmdtp, int flag, int ar
 }
 
 static struct cmd_tbl test_commands[] = {
-   U_BOOT_CMD_MKENT(tree, 0, 1, do_dm_dump_all, "", ""),
+   U_BOOT_CMD_MKENT(tree, 0, 1, do_dm_dump_tree, "", ""),
U_BOOT_CMD_MKENT(uclass, 1, 1, do_dm_dump_uclass, "", ""),
U_BOOT_CMD_MKENT(devres, 1, 1, do_dm_dump_devres, "", ""),
U_BOOT_CMD_MKENT(drivers, 1, 1, do_dm_dump_drivers, "", ""),
diff --git a/drivers/core/dump.c b/drivers/core/dump.c
index f2f9cacc56c..606883ac941 100644
--- a/drivers/core/dump.c
+++ b/drivers/core/dump.c
@@ -45,7 +45,7 @@ static void show_devices(struct udevice *dev, int depth, int 
last_flag)
}
 }
 
-void dm_dump_all(void)
+void dm_dump_tree(void)
 {
struct udevice *root;
 
diff --git a/include/dm/util.h b/include/dm/util.h
index 4428f045b72..c52daa87ef3 100644
--- a/include/dm/util.h
+++ b/include/dm/util.h
@@ -25,7 +25,7 @@ struct list_head;
 int list_count_items(struct list_head *head);
 
 /* Dump out a tree of all devices */
-void dm_dump_all(void);
+void dm_dump_tree(void);
 
 /* Dump out a list of uclasses and their devices */
 void dm_dump_uclass(void);
-- 
2.36.0.512.ge40c2bad7a-goog



[PATCH 0/9] dm: core: Support collecting and reporting stats

2022-05-08 Thread Simon Glass
Driver model can use a lot of memory, as it is the core of all drivers
and devices in U-Boot. Add a command to show how much is in use, along
with the sizes of various data structures.

This patch can be used to analyse the impact of various potential changes
to driver model for SPL, none of which has been implemented. Most involve
shrinking the size of struct udevice, which is a particular problem on
64-bit machines since their pointers are so unnecessarily large in SPL.

To try this out, enable SPL_DM_STATS and then build and run on your
board. You should see output for SPL and U-Boot proper, like this:

   Struct sizes: udevice 90, driver 78, uclass 30, uc_driver 78
   Memory: device 11:990, device names 111, uclass a:1e0

   Attached typeCount   SizeCur   Tags   Save
   ---  -  -  -  -  -
   plat 3 e0990914 7c (124)
   parent_plat  2 40990910 80 (128)
   uclass_plat  1 1099090c 84 (132)
   priv 613d990920 70 (112)
   parent_priv  0  0990908 88 (136)
   uclass_priv  3 38990914 7c (124)
   driver_data  0  0990908 88 (136)
   uclass   0  0
   Attached total   f2a5   37c (892)
   tags 0  0

   Total size: e15 (3605)

   With tags:   a99 (2713)
   - singly-linked: 901 (2305)
   - driver index:  88a (2186)
   - uclass index:  813 (2067)
   Drop device name (not SRAM): 111 (273)


Simon Glass (9):
  dm: core: Rename dm_dump_all()
  dm: core: Sort dm subcommands
  dm: core: Fix addresses in the dm static command
  dm: core: Add documentation for the dm command
  dm: core: Switch the testbus driver to use a new struct
  dm: core: Support accessing core tags
  dm: core: Add a way to collect memory usage
  dm: core: Add a command to show driver model statistics
  dm: spl: Allow SPL to show memory usage

 cmd/dm.c|  69 --
 common/spl/spl.c|   9 +
 doc/usage/cmd/dm.rst| 487 
 doc/usage/index.rst |   1 +
 drivers/core/Kconfig|  21 ++
 drivers/core/device.c   |  65 ++
 drivers/core/dump.c |  79 ++-
 drivers/core/root.c |  53 +
 drivers/core/tag.c  |  29 +++
 drivers/misc/test_drv.c |   6 +-
 include/dm/device.h |  25 +++
 include/dm/root.h   |  45 
 include/dm/tag.h|  32 ++-
 include/dm/test.h   |   7 +
 include/dm/util.h   |  11 +-
 test/dm/core.c  |  91 
 tools/dtoc/test_dtoc.py |   6 +-
 17 files changed, 1004 insertions(+), 32 deletions(-)
 create mode 100644 doc/usage/cmd/dm.rst

-- 
2.36.0.512.ge40c2bad7a-goog



Re: [RFC] Data structure for information handoff between firmware boot stages

2022-05-03 Thread Simon Glass
Hi Jose,

On Tue, 3 May 2022 at 02:26, Jose Marinho  wrote:
>
> Hi Simon,
>
> Thank you for reviewing the draft proposal!
>
> Would you be able to share your review comments on the PDF?
> Currently the document is not in a markup form and is yet to be hosted in a 
> repository. That's the intent for the long term.

Yes it looks like I can do that, so will share with you when done.

Regards,
Simon

>
> Cheers,
> Jose
>
> > -Original Message-
> > From: Simon Glass 
> > Sent: 03 May 2022 08:59
> > To: Jose Marinho 
> > Cc: u-boot@lists.denx.de; Heinrich Schuchardt ; Ilias
> > Apalodimas ; Tom Rini ;
> > Samer El-Haj-Mahmoud ; Manish Pandey2
> > ; nd 
> > Subject: Re: [RFC] Data structure for information handoff between firmware
> > boot stages
> >
> > Hi Jose,
> >
> > On Thu, 7 Apr 2022 at 13:23, Jose Marinho  wrote:
> > >
> > > Hi All,
> > >
> > > The topic of information handoff between TF-A’s BL31 and BL33 (e.g. U-boot
> > proper, EDK2) was discussed last year in the TF-A and U-boot mailing lists 
> > [1],
> > [2].
> > >
> > > Examples of information to be handed off between firmware stages are the
> > TPM log, HOB nodes, etc.
> > > Having a standard data structure which is usable/supported by every
> > community contributes to code reuse and leads to simpler codebase
> > maintenance.
> > >
> > > Some already existing data structures, such as the UEFI HOB list [3], and 
> > > the
> > Bloblist from U-boot, were proposed to be employed for the handoffs.
> > > There are pros and cons with both HOBs and Bloblist.
> > > The discussion settled with a consensus that a data structure ought to be
> > defined which encapsulates the best traits of HOBs and Bloblist.
> > >
> > > Properties that the data structure should have:
> > > - node types identified by an integer,
> > > - easily relocatable,
> > >
> > > - straightforward to append new nodes,
> > > - easy to read and append to from resource constrained environments.
> > >
> > > The data structure should be suitable to pass information between 
> > > different
> > firmware stages, such as:
> > > U-boot SPL -> BL31 -> U-boot
> > > BL1 -> BL2 -> BL31 -> U-boot
> > >
> > > As requested in the ML, an initial proposal was drafted [4].
> > > The document [4] is an initial proposal (at an alpha stage).
> > > The document [4] is being circulated for the purpose of gathering initial
> > feedback.
> > > This proposal is closely aligned with an ongoing effort in the u-boot 
> > > mailing
> > list [5].
> > > The proposal defines 1) a set of standard nodes and 2) the registers used 
> > > at
> > the handoff boundary.
> > >
> > > Standard nodes:
> > > - fdt node: HW description fdt,
> > > - HOB node,
> > > - ACPI table node: the main use-case for this node is to carry the TPM 
> > > log.
> > >
> > > The document [4] accommodates an OEM range, which enables IMPDEF
> > nodes to be caried in the handoff list.
> > > By definition, the nodes in the OEM range are not standard and can be
> > defined per-platform.
> > >
> > > Note: the document [4] encapsulates the standard node definition as that 
> > > is
> > the simplest approach for feedback gathering.
> > > Once there is sufficient consensus around the proposal, the standard node
> > definitions should be moved to a project independent repository. The
> > repository location is TBD.
> > > The list of standard nodes is expected to grow with community 
> > > contribution.
> >
> > Thank you for the document. Is there a way to comment on it or should I just
> > send you my hand-written markup?
> >
> > Regards,
> > Simon
> >
> > >
> > > Kind Regards,
> > > Jose
> > >
> > >
> > >
> > > [1]
> > > https://lists.trustedfirmware.org/archives/list/tf-a@lists.trustedfirm
> > > ware.org/message/LUIUOVGUMVWID5RUMTYA463KGIU2EHIU/
> > >
> > > [2]
> > > https://lore.kernel.org/u-boot/CAODwPW_FwFN1E84cV1+nC1aiahiwOL-
> > TV=mP_6
> > > o8h0y9+pc...@mail.gmail.com/
> > >
> > > [3] https://uefi.org/sites/default/files/resources/PI_Spec_1_6.pdf
> > >
> > > [4] https://developer.arm.com/documentation/den0135/a
> > > [5]
> > > https://lore.kernel.org/u-boot/20220113022625.413990-1-...@chromium.or
> > > g/
> > >
> > >


Re: [PATCH v3 08/13] misc: Add support for nvmem cells

2022-05-03 Thread Simon Glass
Hi Sean,

On Fri, 29 Apr 2022 at 13:40, Sean Anderson  wrote:
>
> Hi Simon,
>
> On 4/25/22 11:24 AM, Sean Anderson wrote:
> >
> >
> > On 4/25/22 1:48 AM, Simon Glass wrote:
> >> Hi Sean,
> >>
> >> On Mon, 18 Apr 2022 at 13:37, Sean Anderson  wrote:
> >>>
> >>> This adds support for "nvmem cells" as seen in Linux. The nvmem device
> >>> class in Linux is used for various assorted ROMs and EEPROMs. In this
> >>> sense, it is similar to UCLASS_MISC, but also includes
> >>> UCLASS_I2C_EEPROM, UCLASS_RTC, and UCLASS_MTD. New drivers corresponding
> >>> to a Linux-style nvmem device should be implemented as one of the
> >>> previously-mentioned uclasses. The nvmem API acts as a compatibility
> >>> layer to adapt the (slightly different) APIs of these uclasses. It also
> >>> handles the lookup of nvmem cells.
> >>>
> >>> While nvmem devices can be accessed directly, they are most often used
> >>> by reading/writing contiguous values called "cells". Cells typically
> >>> hold information like calibration, versions, or configuration (such as
> >>> mac addresses).
> >>>
> >>> nvmem devices can specify "cells" in their device tree:
> >>>
> >>> qfprom: eeprom@70 {
> >>> #address-cells = <1>;
> >>> #size-cells = <1>;
> >>> reg = <0x0070 0x10>;
> >>>
> >>> /* ... */
> >>>
> >>> tsens_calibration: calib@404 {
> >>> reg = <0x404 0x10>;
> >>> };
> >>> };
> >>>
> >>> which can then be referenced like:
> >>>
> >>> tsens {
> >>> /* ... */
> >>> nvmem-cells = <_calibration>;
> >>> nvmem-cell-names = "calibration";
> >>> };
> >>>
> >>> The tsens driver could then read the calibration value like:
> >>>
> >>> struct nvmem_cell cal_cell;
> >>> u8 cal[16];
> >>> nvmem_cell_get_by_name(dev, "calibration", _cell);
> >>> nvmem_cell_read(_cell, cal, sizeof(cal));
> >>>
> >>> Because nvmem devices are not all of the same uclass, supported uclasses
> >>> must register a nvmem_interface struct. This allows CONFIG_NVMEM to be
> >>> enabled without depending on specific uclasses. At the moment,
> >>> nvmem_interface is very bare-bones, and assumes that no initialization
> >>> is necessary. However, this could be amended in the future.
> >>>
> >>> Although I2C_EEPROM and MISC are quite similar (and could likely be
> >>> unified), they present different read/write function signatures. To
> >>> abstract over this, NVMEM uses the same read/write signature as Linux.
> >>> In particular, short read/writes are not allowed, which is allowed by
> >>> MISC.
> >>>
> >>> The functionality implemented by nvmem cells is very similar to that
> >>> provided by i2c_eeprom_partition. "fixed-partition"s for eeproms does
> >>> not seem to have made its way into Linux or into any device tree other
> >>> than sandbox. It is possible that with the introduction of this API it
> >>> would be possible to remove it.
> >>
> >> I still think this would be better as a separate uclass, with child
> >> devices created at bind time in each of the respective uclasses, like
> >> mmc_bind() does. Then you will see the nvmem devices in the DM tree.
> >> Wouldn't we want to add a command to access the nvmem devices?
> >
> > We already do. E.g. the misc/rtc/eeprom commands. The problem is that
> > for software to access them, they would have to use misc_read/dm_rtc_read/
> > i2c_eeprom_read.
> >
> >> This patch feels like a shortcut to me and I'm not sure of the
> >> benefit of that shortcut.
> > Well, I suppose it's because "nvmem" devices are strict subsets of
> > existing devices. There is no new functionality here (except adapting
> > between semantics like for misc). We should always be able to use the
> > existing API to implement support for a new underlying uclass. There
> > should never be device-specific read/write methods, because we

Re: [RFC] Data structure for information handoff between firmware boot stages

2022-05-03 Thread Simon Glass
Hi Jose,

On Thu, 7 Apr 2022 at 13:23, Jose Marinho  wrote:
>
> Hi All,
>
> The topic of information handoff between TF-A’s BL31 and BL33 (e.g. U-boot 
> proper, EDK2) was discussed last year in the TF-A and U-boot mailing lists 
> [1], [2].
>
> Examples of information to be handed off between firmware stages are the TPM 
> log, HOB nodes, etc.
> Having a standard data structure which is usable/supported by every community 
> contributes to code reuse and leads to simpler codebase maintenance.
>
> Some already existing data structures, such as the UEFI HOB list [3], and the 
> Bloblist from U-boot, were proposed to be employed for the handoffs.
> There are pros and cons with both HOBs and Bloblist.
> The discussion settled with a consensus that a data structure ought to be 
> defined which encapsulates the best traits of HOBs and Bloblist.
>
> Properties that the data structure should have:
> - node types identified by an integer,
> - easily relocatable,
>
> - straightforward to append new nodes,
> - easy to read and append to from resource constrained environments.
>
> The data structure should be suitable to pass information between different 
> firmware stages, such as:
> U-boot SPL -> BL31 -> U-boot
> BL1 -> BL2 -> BL31 -> U-boot
>
> As requested in the ML, an initial proposal was drafted [4].
> The document [4] is an initial proposal (at an alpha stage).
> The document [4] is being circulated for the purpose of gathering initial 
> feedback.
> This proposal is closely aligned with an ongoing effort in the u-boot mailing 
> list [5].
> The proposal defines 1) a set of standard nodes and 2) the registers used at 
> the handoff boundary.
>
> Standard nodes:
> - fdt node: HW description fdt,
> - HOB node,
> - ACPI table node: the main use-case for this node is to carry the TPM log.
>
> The document [4] accommodates an OEM range, which enables IMPDEF nodes to be 
> caried in the handoff list.
> By definition, the nodes in the OEM range are not standard and can be defined 
> per-platform.
>
> Note: the document [4] encapsulates the standard node definition as that is 
> the simplest approach for feedback gathering.
> Once there is sufficient consensus around the proposal, the standard node 
> definitions should be moved to a project independent repository. The 
> repository location is TBD.
> The list of standard nodes is expected to grow with community contribution.

Thank you for the document. Is there a way to comment on it or should
I just send you my hand-written markup?

Regards,
Simon

>
> Kind Regards,
> Jose
>
>
>
> [1] 
> https://lists.trustedfirmware.org/archives/list/t...@lists.trustedfirmware.org/message/LUIUOVGUMVWID5RUMTYA463KGIU2EHIU/
>
> [2] 
> https://lore.kernel.org/u-boot/CAODwPW_FwFN1E84cV1+nC1aiahiwOL-TV=mp_6o8h0y9+pc...@mail.gmail.com/
>
> [3] https://uefi.org/sites/default/files/resources/PI_Spec_1_6.pdf
>
> [4] https://developer.arm.com/documentation/den0135/a
> [5] https://lore.kernel.org/u-boot/20220113022625.413990-1-...@chromium.org/
>
>


[PATCH v8 09/13] vpl: Add Kconfig options for VPL

2022-04-30 Thread Simon Glass
Add VPL versions of commonly used Kconfig options.

Signed-off-by: Simon Glass 
---

Changes in v8:
- Support SYSCON and REGMAP too

Changes in v7:
- Add a few more options

Changes in v5:
- Rebase this patch on mainline (for GPIO and MISC Kconfig renames)

Changes in v4:
- Add options for blk, core, misc and tpl also
- Add VPL_SIZE_LIMIT

 Kconfig  |  10 ++
 common/Kconfig   |  67 
 common/spl/Kconfig   | 219 +++
 drivers/block/Kconfig|  12 +++
 drivers/clk/Kconfig  |  26 +
 drivers/core/Kconfig |  54 +-
 drivers/core/Makefile|   2 +-
 drivers/gpio/Kconfig |  11 ++
 drivers/i2c/Kconfig  |  11 ++
 drivers/misc/Kconfig |  28 +
 drivers/pinctrl/Kconfig  |  18 +++-
 drivers/rtc/Kconfig  |   9 ++
 drivers/serial/Kconfig   |  20 
 drivers/sysreset/Kconfig |  10 ++
 drivers/timer/Kconfig|  10 ++
 drivers/tpm/Kconfig  |  30 ++
 dts/Kconfig  |  17 +++
 lib/Kconfig  |  62 +++
 18 files changed, 612 insertions(+), 4 deletions(-)

diff --git a/Kconfig b/Kconfig
index bdae59e06f4..8bbb988790b 100644
--- a/Kconfig
+++ b/Kconfig
@@ -319,6 +319,16 @@ config VALGRIND
  it can be handled accurately by Valgrind. If you aren't planning on
  using valgrind to debug U-Boot, say 'n'.
 
+config VPL_SYS_MALLOC_F_LEN
+   hex "Size of malloc() pool in VPL before relocation"
+   depends on SYS_MALLOC_F && VPL
+   default SYS_MALLOC_F_LEN
+   help
+ Before relocation, memory is very limited on many platforms. Still,
+ we can provide a small malloc() pool if needed. Driver model in
+ particular needs this to operate, so that it can allocate the
+ initial serial device and any others that are needed.
+
 menuconfig EXPERT
bool "Configure standard U-Boot features (expert users)"
default y
diff --git a/common/Kconfig b/common/Kconfig
index f55b4211bb2..a96842a5c11 100644
--- a/common/Kconfig
+++ b/common/Kconfig
@@ -89,6 +89,15 @@ config TPL_LOGLEVEL
int
default LOGLEVEL
 
+config VPL_LOGLEVEL
+   int "loglevel for VPL"
+   default LOGLEVEL
+   help
+ All Messages with a loglevel smaller than the console loglevel will
+ be compiled in to VPL. See LOGLEVEL for a list of available log
+ levels. Setting this to a value above 4 may increase the code size
+ significantly.
+
 config SILENT_CONSOLE
bool "Support a silent console"
help
@@ -262,6 +271,15 @@ config LOG
 
 if LOG
 
+config VPL_LOG
+   bool "Enable logging support in VPL"
+   depends on LOG
+   help
+ This enables support for logging of status and debug messages. These
+ can be displayed on the console, recorded in a memory buffer, or
+ discarded if not needed. Logging supports various categories and
+ levels of severity.
+
 config LOG_MAX_LEVEL
int "Maximum log level to record"
default 6
@@ -431,6 +449,47 @@ config TPL_LOG_CONSOLE
 
 endif
 
+config VPL_LOG
+   bool "Enable logging support in VPL"
+   depends on LOG
+   help
+ This enables support for logging of status and debug messages. These
+ can be displayed on the console, recorded in a memory buffer, or
+ discarded if not needed. Logging supports various categories and
+ levels of severity.
+
+if VPL_LOG
+
+config VPL_LOG_MAX_LEVEL
+   int "Maximum log level to record in VPL"
+   default 3
+   help
+ This selects the maximum log level that will be recorded. Any value
+ higher than this will be ignored. If possible log statements below
+ this level will be discarded at build time. Levels:
+
+   0 - emergency
+   1 - alert
+   2 - critical
+   3 - error
+   4 - warning
+   5 - note
+   6 - info
+   7 - debug
+   8 - debug content
+   9 - debug hardware I/O
+
+config VPL_LOG_CONSOLE
+   bool "Allow log output to the console in VPL"
+   default y
+   help
+ Enables a log driver which writes log records to the console.
+ Generally the console is the serial port or LCD display. Only the
+ log message is shown - other details like level, category, file and
+ line number are omitted.
+
+endif
+
 config LOG_ERROR_RETURN
bool "Log all functions which return an error"
help
@@ -777,6 +836,14 @@ config TPL_BLOBLIST
  This enables a bloblist in TPL. The bloblist is set up in TPL and
  passed to SPL and U-Boot proper.
 
+config VPL_BLOBLIST
+   bool "Support for a bloblist in VPL"
+   depends on BLOBLIST && VPL_LIBGENERIC_SUPPORT && VPL_LIBCOMMON_SUPPORT
+   default y if 

[PATCH v8 11/13] vpl: Support running vpl tests

2022-04-30 Thread Simon Glass
Add support for these to the pytest system.

Signed-off-by: Simon Glass 
---

Changes in v8:
- Add new patch to support running vpl tests

 test/py/conftest.py   |  7 +--
 test/py/tests/test_vpl.py | 34 +++
 test/py/u_boot_console_sandbox.py |  7 ++-
 3 files changed, 45 insertions(+), 3 deletions(-)
 create mode 100644 test/py/tests/test_vpl.py

diff --git a/test/py/conftest.py b/test/py/conftest.py
index 16e445cd8ee..2ba34479e03 100644
--- a/test/py/conftest.py
+++ b/test/py/conftest.py
@@ -322,8 +322,11 @@ def pytest_generate_tests(metafunc):
 if fn == 'ut_subtest':
 generate_ut_subtest(metafunc, fn, '/u-boot.sym')
 continue
-if fn == 'ut_spl_subtest':
-generate_ut_subtest(metafunc, fn, '/spl/u-boot-spl.sym')
+m_subtest = re.match('ut_(.)pl_subtest', fn)
+if m_subtest:
+spl_name = m_subtest.group(1)
+generate_ut_subtest(
+metafunc, fn, f'/{spl_name}pl/u-boot-{spl_name}pl.sym')
 continue
 generate_config(metafunc, fn)
 
diff --git a/test/py/tests/test_vpl.py b/test/py/tests/test_vpl.py
new file mode 100644
index 000..4af578b9173
--- /dev/null
+++ b/test/py/tests/test_vpl.py
@@ -0,0 +1,34 @@
+# SPDX-License-Identifier: GPL-2.0
+# Copyright 2022 Google LLC
+# Written by Simon Glass 
+
+import os.path
+import pytest
+
+def test_vpl(u_boot_console, ut_vpl_subtest):
+"""Execute a "ut" subtest.
+
+The subtests are collected in function generate_ut_subtest() from linker
+generated lists by applying a regular expression to the lines of file
+vpl/u-boot-vpl.sym. The list entries are created using the C macro
+UNIT_TEST().
+
+Strict naming conventions have to be followed to match the regular
+expression. Use UNIT_TEST(foo_test_bar, _flags, foo_test) for a test bar in
+test suite foo that can be executed via command 'ut foo bar' and is
+implemented in C function foo_test_bar().
+
+Args:
+u_boot_console (ConsoleBase): U-Boot console
+ut_subtest (str): VPL test to be executed (e.g. 'dm platdata_phandle')
+"""
+try:
+cons = u_boot_console
+cons.restart_uboot_with_flags(['-u', '-k', ut_vpl_subtest.split()[1]])
+output = cons.get_spawn_output().replace('\r', '')
+assert 'Failures: 0' in output
+finally:
+# Restart afterward in case a non-VPL test is run next. This should not
+# happen since VPL tests are run in their own invocation of test.py, 
but
+# the cost of doing this is not too great at present.
+u_boot_console.restart_uboot()
diff --git a/test/py/u_boot_console_sandbox.py 
b/test/py/u_boot_console_sandbox.py
index b79ec817957..27c6db8d719 100644
--- a/test/py/u_boot_console_sandbox.py
+++ b/test/py/u_boot_console_sandbox.py
@@ -44,7 +44,12 @@ class ConsoleSandbox(ConsoleBase):
 
 bcfg = self.config.buildconfig
 config_spl = bcfg.get('config_spl', 'n') == 'y'
-fname = '/spl/u-boot-spl' if config_spl else '/u-boot'
+config_vpl = bcfg.get('config_vpl', 'n') == 'y'
+if config_vpl:
+# Run TPL first, which runs VPL
+fname = '/tpl/u-boot-tpl'
+else:
+fname = '/spl/u-boot-spl' if config_spl else '/u-boot'
 print(fname)
 cmd = []
 if self.config.gdbserver:
-- 
2.36.0.464.gb9c8b46e94-goog



[PATCH v8 12/13] vpl: Test that VPL runs correctly through to U-Boot proper

2022-04-30 Thread Simon Glass
Check the TPL -> VPL -> SPL -> U-Boot path by running the 'help' command
in U-Boot.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 test/py/tests/test_help.py | 12 
 1 file changed, 12 insertions(+)

diff --git a/test/py/tests/test_help.py b/test/py/tests/test_help.py
index 03b9d91c117..153133cf28f 100644
--- a/test/py/tests/test_help.py
+++ b/test/py/tests/test_help.py
@@ -20,3 +20,15 @@ def test_help_no_devicetree(u_boot_console):
 finally:
 # Restart afterward to get the normal device tree back
 u_boot_console.restart_uboot()
+
+@pytest.mark.boardspec('sandbox_vpl')
+def test_vpl_help(u_boot_console):
+try:
+cons = u_boot_console
+cons.restart_uboot()
+cons.run_command('help')
+output = cons.get_spawn_output().replace('\r', '')
+assert 'print command description/usage' in output
+finally:
+# Restart afterward to get the normal device tree back
+u_boot_console.restart_uboot()
-- 
2.36.0.464.gb9c8b46e94-goog



[PATCH v8 13/13] CI: Run VPL tests

2022-04-30 Thread Simon Glass
Add tests for VPL into the mix. For now this just runs the help test and
a few SPL ones.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 .azure-pipelines.yml | 3 +++
 .gitlab-ci.yml   | 6 ++
 2 files changed, 9 insertions(+)

diff --git a/.azure-pipelines.yml b/.azure-pipelines.yml
index 48a587a59ea..4e5c4b785a7 100644
--- a/.azure-pipelines.yml
+++ b/.azure-pipelines.yml
@@ -245,6 +245,9 @@ stages:
 sandbox_spl:
   TEST_PY_BD: "sandbox_spl"
   TEST_PY_TEST_SPEC: "test_ofplatdata or test_handoff or test_spl"
+sandbox_vpl:
+  TEST_PY_BD: "sandbox_vpl"
+  TEST_PY_TEST_SPEC: "test_vpl_help or test_spl"
 sandbox_noinst:
   TEST_PY_BD: "sandbox_noinst"
   TEST_PY_TEST_SPEC: "test_ofplatdata or test_handoff or test_spl"
diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index f193ffd3cbc..c6a608f7e2a 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -260,6 +260,12 @@ sandbox_noinst_test.py:
 TEST_PY_TEST_SPEC: "test_ofplatdata or test_handoff or test_spl"
   <<: *buildman_and_testpy_dfn
 
+sandbox_vpl test.py:
+  variables:
+TEST_PY_BD: "sandbox_vpl"
+TEST_PY_TEST_SPEC: "test_vpl_help or test_spl"
+  <<: *buildman_and_testpy_dfn
+
 evb-ast2500 test.py:
   variables:
 TEST_PY_BD: "evb-ast2500"
-- 
2.36.0.464.gb9c8b46e94-goog



[PATCH v8 10/13] sandbox: Add a build for VPL

2022-04-30 Thread Simon Glass
Add an initial VPL build for sandbox. This includes the flow:

   TPL (with of-platdata) -> VPL -> SPL -> U-Boot

To run it:

   ./tpl/u-boot-tpl -D

The -D is needed to get the default device tree, which includes the serial
console info.

Add a Makefile check for OF_HOSTFILE which is the option that enables
devicetree control on sandbox.

Signed-off-by: Simon Glass 
---

Changes in v8:
- Update defconfig to account for option changes
- Drop reference to old OF_HOSTFILE option

Changes in v7:
- Rebase to master
- Update some options based on settings in master

Changes in v6:
- Add docs for sandbox_vpl build
- Drop TPL_HASH_SUPPORT patch since we only have SPL_HASH now

Changes in v4:
- Add a sandbox_vpl build
- Update cover letter

 arch/sandbox/Kconfig  |   8 ++
 arch/sandbox/cpu/spl.c|  12 +-
 arch/sandbox/dts/sandbox.dtsi |  10 +-
 board/sandbox/MAINTAINERS |   7 +
 configs/sandbox_vpl_defconfig | 251 ++
 doc/arch/sandbox.rst  |  13 ++
 6 files changed, 294 insertions(+), 7 deletions(-)
 create mode 100644 configs/sandbox_vpl_defconfig

diff --git a/arch/sandbox/Kconfig b/arch/sandbox/Kconfig
index 477c51960da..5f55c7f28e1 100644
--- a/arch/sandbox/Kconfig
+++ b/arch/sandbox/Kconfig
@@ -29,6 +29,14 @@ config SANDBOX_SPL
bool "Enable SPL for sandbox"
select SUPPORT_SPL
 
+config SANDBOX_TPL
+   bool "Enable TPL for sandbox"
+   select SUPPORT_TPL
+
+config SANDBOX_VPL
+   bool "Enable VPL for sandbox"
+   select SUPPORT_VPL
+
 config SYS_CONFIG_NAME
default "sandbox_spl" if SANDBOX_SPL
default "sandbox" if !SANDBOX_SPL
diff --git a/arch/sandbox/cpu/spl.c b/arch/sandbox/cpu/spl.c
index 3f107b8acbd..fe5d44d36ed 100644
--- a/arch/sandbox/cpu/spl.c
+++ b/arch/sandbox/cpu/spl.c
@@ -32,13 +32,21 @@ int sandbox_find_next_phase(char *fname, int maxlen, bool 
use_img)
return 0;
 }
 
-/* SPL / TPL init function */
+/* SPL / TPL / VPL init function */
 void board_init_f(ulong flag)
 {
struct sandbox_state *state = state_get_current();
+   int ret;
 
gd->arch.ram_buf = state->ram_buf;
gd->ram_size = state->ram_size;
+
+   ret = spl_early_init();
+   if (ret) {
+   debug("spl_early_init() failed: %d\n", ret);
+   hang();
+   }
+   preloader_console_init();
 }
 
 u32 spl_boot_device(void)
@@ -75,8 +83,6 @@ void spl_board_init(void)
 {
struct sandbox_state *state = state_get_current();
 
-   preloader_console_init();
-
if (state->run_unittests) {
struct unit_test *tests = UNIT_TEST_ALL_START();
const int count = UNIT_TEST_ALL_COUNT();
diff --git a/arch/sandbox/dts/sandbox.dtsi b/arch/sandbox/dts/sandbox.dtsi
index 29306ac04da..aa22b8765c8 100644
--- a/arch/sandbox/dts/sandbox.dtsi
+++ b/arch/sandbox/dts/sandbox.dtsi
@@ -254,7 +254,7 @@
};
 
spl-test {
-   u-boot,dm-pre-reloc;
+   u-boot,dm-spl;
compatible = "sandbox,spl-test";
boolval;
intval = <1>;
@@ -268,7 +268,7 @@
};
 
spl-test2 {
-   u-boot,dm-pre-reloc;
+   u-boot,dm-spl;
compatible = "sandbox,spl-test";
intval = <3>;
intarray = <5>;
@@ -280,14 +280,14 @@
};
 
spl-test3 {
-   u-boot,dm-pre-reloc;
+   u-boot,dm-spl;
compatible = "sandbox,spl-test";
stringarray = "one";
maybe-empty-int = <1>;
};
 
spl-test5 {
-   u-boot,dm-tpl;
+   u-boot,dm-vpl;
compatible = "sandbox,spl-test";
stringarray = "tpl";
};
@@ -334,6 +334,8 @@
/* Needs to be available prior to relocation */
uart0: serial {
u-boot,dm-spl;
+   u-boot,dm-tpl;
+   u-boot,dm-vpl;
compatible = "sandbox,serial";
sandbox,text-colour = "cyan";
pinctrl-names = "default";
diff --git a/board/sandbox/MAINTAINERS b/board/sandbox/MAINTAINERS
index d32561cd1d0..9f5073bf287 100644
--- a/board/sandbox/MAINTAINERS
+++ b/board/sandbox/MAINTAINERS
@@ -33,3 +33,10 @@ S:   Maintained
 F: board/sandbox/
 F: include/configs/sandbox.h
 F: configs/sandbox_flattree_defconfig
+
+SANDBOX VPL BOARD
+M: Simon Glass 
+S: Maintained
+F: board/sandbox/
+F: include/configs/sandbox_spl.h
+F: configs/sandbox_vpl_defconfig
diff --git a/configs/sandbox_vpl_defconfig b/configs/sandbox_vpl_defconfig
new file mode 100644
index 000..2cc16233cf7
--- /dev/null
+++ b/configs/sandbox_vpl_defconfig
@@ -0,0 +1,251 @@
+CON

[PATCH v8 08/13] Introduce Verifying Program Loader (VPL)

2022-04-30 Thread Simon Glass
Add support for VPL, a new phase of U-Boot. This runs after TPL. It is
responsible for selecting which SPL binary to run, based on a
verified-boot process.

Signed-off-by: Simon Glass 
---

Changes in v8:
- Rename the VPL symbols in spl.c

Changes in v4:
- Update spl_phase_prefix() for VPL
- Tidy up some of the Makefile rules

Changes in v3:
- Move VPL Kconfig options to a separate patch
- Add full build support for VPL
- Add a VPL size check (Kconfig option in next patch)

Changes in v2:
- Add some more VPL Kconfig options

 Makefile  | 14 ++
 common/spl/Kconfig| 15 ++-
 common/spl/spl.c  | 25 ++---
 doc/develop/spl.rst   |  7 ++-
 drivers/Makefile  |  2 ++
 include/bootstage.h   |  2 ++
 include/linux/kconfig.h   |  3 +++
 include/spl.h | 22 +++---
 scripts/Kbuild.include|  4 
 scripts/Makefile.autoconf | 12 
 scripts/Makefile.build|  4 
 scripts/Makefile.lib  |  5 +
 scripts/Makefile.spl  | 35 ---
 13 files changed, 131 insertions(+), 19 deletions(-)

diff --git a/Makefile b/Makefile
index 82c35a94ae6..ea80f00716d 100644
--- a/Makefile
+++ b/Makefile
@@ -911,6 +911,12 @@ else
 TPL_SIZE_CHECK =
 endif
 
+ifneq ($(CONFIG_VPL_SIZE_LIMIT),0x0)
+VPL_SIZE_CHECK = @$(call size_check,$@,$(CONFIG_VPL_SIZE_LIMIT))
+else
+VPL_SIZE_CHECK =
+endif
+
 # Statically apply RELA-style relocations (currently arm64 only)
 # This is useful for arm64 where static relocation needs to be performed on
 # the raw binary, but certain simulators only accept an ELF file (but don't
@@ -951,6 +957,7 @@ INPUTS-$(CONFIG_SPL_FRAMEWORK) += u-boot.img
 endif
 endif
 INPUTS-$(CONFIG_TPL) += tpl/u-boot-tpl.bin
+INPUTS-$(CONFIG_VPL) += vpl/u-boot-vpl.bin
 
 # Allow omitting the .dtb output if it is not normally used
 INPUTS-$(CONFIG_OF_SEPARATE) += $(if 
$(CONFIG_OF_OMIT_DTB),dts/dt.dtb,u-boot.dtb)
@@ -2117,6 +2124,13 @@ tpl/u-boot-tpl.bin: tpl/u-boot-tpl
 tpl/u-boot-tpl: tools prepare $(if $(CONFIG_TPL_OF_CONTROL),dts/dt.dtb)
$(Q)$(MAKE) obj=tpl -f $(srctree)/scripts/Makefile.spl all
 
+vpl/u-boot-vpl.bin: vpl/u-boot-vpl
+   @:
+   $(VPL_SIZE_CHECK)
+
+vpl/u-boot-vpl: tools prepare $(if $(CONFIG_TPL_OF_CONTROL),dts/dt.dtb)
+   $(Q)$(MAKE) obj=vpl -f $(srctree)/scripts/Makefile.spl all
+
 TAG_SUBDIRS := $(patsubst %,$(srctree)/%,$(u-boot-dirs) include)
 
 FIND := find
diff --git a/common/spl/Kconfig b/common/spl/Kconfig
index ac61b25a066..be098668f0e 100644
--- a/common/spl/Kconfig
+++ b/common/spl/Kconfig
@@ -1,4 +1,4 @@
-menu "SPL / TPL"
+menu "SPL / TPL / VPL"
 
 config SUPPORT_SPL
bool
@@ -6,6 +6,9 @@ config SUPPORT_SPL
 config SUPPORT_TPL
bool
 
+config SUPPORT_VPL
+   bool
+
 config SPL_DFU_NO_RESET
bool
 
@@ -302,6 +305,16 @@ config SPL_READ_ONLY
  writeable memory) of anything it wants to modify, such as
  device-private data.
 
+config TPL_SEPARATE_BSS
+   bool "BSS section is in a different memory region from text"
+   default y if SPL_SEPARATE_BSS
+   help
+ Some platforms need a large BSS region in TPL and can provide this
+ because RAM is already set up. In this case BSS can be moved to RAM.
+ This option should then be enabled so that the correct device tree
+ location is used. Normally we put the device tree at the end of BSS
+ but with this option enabled, it goes at _image_binary_end.
+
 config SPL_BANNER_PRINT
bool "Enable output of the SPL banner 'U-Boot SPL ...'"
default y
diff --git a/common/spl/spl.c b/common/spl/spl.c
index c9750ee1637..c8c463f80bd 100644
--- a/common/spl/spl.c
+++ b/common/spl/spl.c
@@ -61,6 +61,11 @@ binman_sym_declare(ulong, u_boot_spl, image_pos);
 binman_sym_declare(ulong, u_boot_spl, size);
 #endif
 
+#ifdef CONFIG_VPL
+binman_sym_declare(ulong, u_boot_vpl, image_pos);
+binman_sym_declare(ulong, u_boot_vpl, size);
+#endif
+
 /* Define board data structure */
 static struct bd_info bdata __attribute__ ((section(".data")));
 
@@ -146,14 +151,22 @@ void spl_fixup_fdt(void *fdt_blob)
 #if CONFIG_IS_ENABLED(BINMAN_SYMBOLS)
 ulong spl_get_image_pos(void)
 {
-   return spl_phase() == PHASE_TPL ?
+#ifdef CONFIG_VPL
+   if (spl_next_phase() == PHASE_VPL)
+   return binman_sym(ulong, u_boot_vpl, image_pos);
+#endif
+   return spl_next_phase() == PHASE_SPL ?
binman_sym(ulong, u_boot_spl, image_pos) :
binman_sym(ulong, u_boot_any, image_pos);
 }
 
 ulong spl_get_image_size(void)
 {
-   return spl_phase() == PHASE_TPL ?
+#ifdef CONFIG_VPL
+   if (spl_next_phase() == PHASE_VPL)
+   return binman_sym(ulong, u_boot_vpl, size);
+#endif
+   return spl_next_phase() == PHASE_SPL ?
binman_sym(ulong, u_boot_spl, size) :
binman_sym(ulong

[PATCH v8 06/13] Makefile: Simplify devicetree rules for SPL/TPL

2022-04-30 Thread Simon Glass
The current logic checks several options to decide whether SPL/TPL need
the U-Boot devicetree to be built. In fact we can check OF_CONTROL, which
is enabled in all cases that matter.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 Makefile | 7 ++-
 1 file changed, 2 insertions(+), 5 deletions(-)

diff --git a/Makefile b/Makefile
index 3f28333e644..9f220de3202 100644
--- a/Makefile
+++ b/Makefile
@@ -2095,9 +2095,7 @@ spl/u-boot-spl-dtb.bin: spl/u-boot-spl
 spl/u-boot-spl-dtb.hex: spl/u-boot-spl
@:
 
-spl/u-boot-spl: tools prepare \
-   $(if 
$(CONFIG_OF_SEPARATE)$(CONFIG_OF_EMBED)$(CONFIG_SPL_OF_PLATDATA),dts/dt.dtb) \
-   $(if 
$(CONFIG_OF_SEPARATE)$(CONFIG_OF_EMBED)$(CONFIG_TPL_OF_PLATDATA),dts/dt.dtb)
+spl/u-boot-spl: tools prepare $(if $(CONFIG_SPL_OF_CONTROL),dts/dt.dtb)
$(Q)$(MAKE) obj=spl -f $(srctree)/scripts/Makefile.spl all
 
 spl/sunxi-spl.bin: spl/u-boot-spl
@@ -2112,8 +2110,7 @@ spl/u-boot-spl.sfp: spl/u-boot-spl
 spl/boot.bin: spl/u-boot-spl
@:
 
-tpl/u-boot-tpl.bin: tools prepare \
-   $(if 
$(CONFIG_OF_SEPARATE)$(CONFIG_OF_EMBED)$(CONFIG_SPL_OF_PLATDATA),dts/dt.dtb)
+tpl/u-boot-tpl.bin: tools prepare $(if $(CONFIG_TPL_OF_CONTROL),dts/dt.dtb)
$(Q)$(MAKE) obj=tpl -f $(srctree)/scripts/Makefile.spl all
$(TPL_SIZE_CHECK)
 
-- 
2.36.0.464.gb9c8b46e94-goog



[PATCH v8 05/13] avb: Don't build in SPL

2022-04-30 Thread Simon Glass
This feature is not used in SPL at present. Update the Makefile to avoid
it being built.

Signed-off-by: Simon Glass 
---

(no changes since v4)

Changes in v4:
- Add new patch to avoid building avb in SPL

 common/Makefile | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/common/Makefile b/common/Makefile
index cc2ba30c631..75c24e32492 100644
--- a/common/Makefile
+++ b/common/Makefile
@@ -112,7 +112,7 @@ obj-y += s_record.o
 obj-$(CONFIG_CMD_LOADB) += xyzModem.o
 obj-$(CONFIG_$(SPL_TPL_)YMODEM_SUPPORT) += xyzModem.o
 
-obj-$(CONFIG_AVB_VERIFY) += avb_verify.o
+obj-$(CONFIG_$(SPL_TPL_)AVB_VERIFY) += avb_verify.o
 obj-$(CONFIG_$(SPL_TPL_)STACKPROTECTOR) += stackprot.o
 obj-$(CONFIG_SCP03) += scp03.o
 
-- 
2.36.0.464.gb9c8b46e94-goog



[PATCH v8 07/13] Makefile: Tidy up the TPL build rules

2022-04-30 Thread Simon Glass
These should follow the same pattern as SPL, for consistency. Fix them.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 Makefile | 7 +--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/Makefile b/Makefile
index 9f220de3202..82c35a94ae6 100644
--- a/Makefile
+++ b/Makefile
@@ -2110,10 +2110,13 @@ spl/u-boot-spl.sfp: spl/u-boot-spl
 spl/boot.bin: spl/u-boot-spl
@:
 
-tpl/u-boot-tpl.bin: tools prepare $(if $(CONFIG_TPL_OF_CONTROL),dts/dt.dtb)
-   $(Q)$(MAKE) obj=tpl -f $(srctree)/scripts/Makefile.spl all
+tpl/u-boot-tpl.bin: tpl/u-boot-tpl
+   @:
$(TPL_SIZE_CHECK)
 
+tpl/u-boot-tpl: tools prepare $(if $(CONFIG_TPL_OF_CONTROL),dts/dt.dtb)
+   $(Q)$(MAKE) obj=tpl -f $(srctree)/scripts/Makefile.spl all
+
 TAG_SUBDIRS := $(patsubst %,$(srctree)/%,$(u-boot-dirs) include)
 
 FIND := find
-- 
2.36.0.464.gb9c8b46e94-goog



[PATCH v8 04/13] bloblist: Correct Kconfig dependencies

2022-04-30 Thread Simon Glass
This feature is not available in SPL unless common/ and lib/ are built.
Update the Kconfig to avoid build errors.

Signed-off-by: Simon Glass 
---

(no changes since v4)

Changes in v4:
- Add new patch to correct bloblist Kconfig dependencies

 common/Kconfig | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/common/Kconfig b/common/Kconfig
index 8f8a9064d50..f55b4211bb2 100644
--- a/common/Kconfig
+++ b/common/Kconfig
@@ -762,7 +762,7 @@ config BLOBLIST
 
 config SPL_BLOBLIST
bool "Support for a bloblist in SPL"
-   depends on BLOBLIST
+   depends on BLOBLIST && SPL_LIBGENERIC_SUPPORT && SPL_LIBCOMMON_SUPPORT
default y if SPL
help
  This enables a bloblist in SPL. If this is the first part of U-Boot
@@ -771,7 +771,7 @@ config SPL_BLOBLIST
 
 config TPL_BLOBLIST
bool "Support for a bloblist in TPL"
-   depends on BLOBLIST
+   depends on BLOBLIST && TPL_LIBGENERIC_SUPPORT && TPL_LIBCOMMON_SUPPORT
default y if TPL
help
  This enables a bloblist in TPL. The bloblist is set up in TPL and
-- 
2.36.0.464.gb9c8b46e94-goog



[PATCH v8 03/13] test: Tidy up test building with SPL

2022-04-30 Thread Simon Glass
We can in principle add tests to any SPL build, e.g. TPL or VPL. Update
the build rules to handle this.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 Makefile | 2 +-
 scripts/Makefile.spl | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/Makefile b/Makefile
index ccc87c3a5cd..3f28333e644 100644
--- a/Makefile
+++ b/Makefile
@@ -846,7 +846,7 @@ libs-y += drivers/usb/ulpi/
 ifdef CONFIG_POST
 libs-y += post/
 endif
-libs-$(CONFIG_UNIT_TEST) += test/
+libs-$(CONFIG_$(SPL_TPL_)UNIT_TEST) += test/
 libs-$(CONFIG_UT_ENV) += test/env/
 libs-$(CONFIG_UT_OPTEE) += test/optee/
 libs-$(CONFIG_UT_OVERLAY) += test/overlay/
diff --git a/scripts/Makefile.spl b/scripts/Makefile.spl
index 6ad82cecfb7..30672a61179 100644
--- a/scripts/Makefile.spl
+++ b/scripts/Makefile.spl
@@ -109,7 +109,7 @@ libs-y += dts/
 libs-y += fs/
 libs-$(CONFIG_SPL_POST_MEM_SUPPORT) += post/drivers/
 libs-$(CONFIG_SPL_NET) += net/
-libs-$(CONFIG_SPL_UNIT_TEST) += test/
+libs-$(CONFIG_$(SPL_TPL_)UNIT_TEST) += test/
 
 head-y := $(addprefix $(obj)/,$(head-y))
 libs-y := $(addprefix $(obj)/,$(libs-y))
-- 
2.36.0.464.gb9c8b46e94-goog



[PATCH v8 02/13] doc: Expand SPL docs to explain the phase and config

2022-04-30 Thread Simon Glass
Add a bit more information about how to use SPL.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 doc/develop/spl.rst | 34 ++
 1 file changed, 34 insertions(+)

diff --git a/doc/develop/spl.rst b/doc/develop/spl.rst
index 4d6f394bed9..1059b2fb9c0 100644
--- a/doc/develop/spl.rst
+++ b/doc/develop/spl.rst
@@ -66,6 +66,40 @@ CONFIG_SPL_SPI_LOAD (drivers/mtd/spi/spi_spl_load.o)
 CONFIG_SPL_RAM_DEVICE (common/spl/spl.c)
 CONFIG_SPL_WATCHDOG (drivers/watchdog/libwatchdog.o)
 
+Adding SPL-specific code
+
+
+To check whether a feature is enabled, use CONFIG_IS_ENABLED()::
+
+  if (CONFIG_IS_ENABLED(CLK))
+  ...
+
+This checks CONFIG_CLK for the main build, CONFIG_SPL_CLK for the SPL build,
+CONFIG_TPL_CLK for the TPL build, etc.
+
+U-Boot Phases
+-
+
+U-Boot boots through the following phases:
+
+TPL
+   Very early init, as tiny as possible. This loads SPL.
+
+SPL
+   Secondary program loader. Sets up SDRAM and loads U-Boot proper. It may also
+   load other firmware components.
+
+U-Boot
+   U-Boot proper, containing the command line and boot logic.
+
+
+Checking the boot phase
+---
+
+Use `spl_phase()` to find the current U-Boot phase, e.g. `PHASE_SPL`. You can
+also find the previous and next phase and get the phase name.
+
+
 Device tree
 ---
 The U-Boot device tree is filtered by the fdtgrep tools during the build
-- 
2.36.0.464.gb9c8b46e94-goog



[PATCH v8 01/13] doc: Convert SPL documentation to ReST

2022-04-30 Thread Simon Glass
Move this documentation over to .rst format.

Signed-off-by: Simon Glass 
---

(no changes since v1)

 doc/develop/index.rst   |  1 +
 doc/{README.SPL => develop/spl.rst} | 36 +++--
 2 files changed, 20 insertions(+), 17 deletions(-)
 rename doc/{README.SPL => develop/spl.rst} (86%)

diff --git a/doc/develop/index.rst b/doc/develop/index.rst
index d32ec490221..fe3564a9fbf 100644
--- a/doc/develop/index.rst
+++ b/doc/develop/index.rst
@@ -25,6 +25,7 @@ Implementation
menus
printf
smbios
+   spl
uefi/index
version
 
diff --git a/doc/README.SPL b/doc/develop/spl.rst
similarity index 86%
rename from doc/README.SPL
rename to doc/develop/spl.rst
index 011fd42537a..4d6f394bed9 100644
--- a/doc/README.SPL
+++ b/doc/develop/spl.rst
@@ -20,19 +20,19 @@ u-boot-spl.map.
 A config option named CONFIG_SPL_BUILD is enabled by Kconfig for SPL.
 Source files can therefore be compiled for SPL with different settings.
 
-For example:
+For example::
 
-ifeq ($(CONFIG_SPL_BUILD),y)
-obj-y += board_spl.o
-else
-obj-y += board.o
-endif
+   ifeq ($(CONFIG_SPL_BUILD),y)
+   obj-y += board_spl.o
+   else
+   obj-y += board.o
+   endif
 
-obj-$(CONFIG_SPL_BUILD) += foo.o
+   obj-$(CONFIG_SPL_BUILD) += foo.o
 
-#ifdef CONFIG_SPL_BUILD
-   foo();
-#endif
+   #ifdef CONFIG_SPL_BUILD
+   foo();
+   #endif
 
 
 The building of SPL images can be enabled by CONFIG_SPL option in Kconfig.
@@ -71,11 +71,13 @@ Device tree
 The U-Boot device tree is filtered by the fdtgrep tools during the build
 process to generate a much smaller device tree used in SPL (spl/u-boot-spl.dtb)
 with:
+
 - the mandatory nodes (/alias, /chosen, /config)
 - the nodes with one pre-relocation property:
   'u-boot,dm-pre-reloc' or 'u-boot,dm-spl'
 
 fdtgrep is also used to remove:
+
 - the properties defined in CONFIG_OF_SPL_REMOVE_PROPS
 - all the pre-relocation properties
   ('u-boot,dm-pre-reloc', 'u-boot,dm-spl' and 'u-boot,dm-tpl')
@@ -98,14 +100,14 @@ stack usage at various points in run sequence of SPL.  The 
-fstack-usage option
 to gcc will produce '.su' files (such as arch/arm/cpu/armv7/syslib.su) that
 will give stack usage information and cflow can construct program flow.
 
-Must have gcc 4.6 or later, which supports -fstack-usage
+Must have gcc 4.6 or later, which supports -fstack-usage:
 
-1) Build normally
-2) Perform the following shell command to generate a list of C files used in
-SPL:
-$ find spl -name '*.su' | sed -e 's:^spl/::' -e 's:[.]su$:.c:' > used-spl.list
-3) Execute cflow:
-$ cflow --main=board_init_r `cat used-spl.list` 2>&1 | $PAGER
+#. Build normally
+#. Perform the following shell command to generate a list of C files used in
+   SPL:
+#. `find spl -name '*.su' | sed -e 's:^spl/::' -e 's:[.]su$:.c:' > 
used-spl.list`
+#. Execute cflow:
+   `$ cflow --main=board_init_r $(cat used-spl.list) 2>&1 | $PAGER`
 
 cflow will spit out a number of warnings as it does not parse
 the config files and picks functions based on #ifdef.  Parsing the '.i'
-- 
2.36.0.464.gb9c8b46e94-goog



  1   2   3   4   5   6   7   8   9   10   >