Re: [PATCH 2/2] event: Correct dependencies on the EVENT framework

2023-01-15 Thread AKASHI Takahiro
On Mon, Jan 16, 2023 at 01:17:53PM +0900, AKASHI Takahiro wrote:
> On Sun, Jan 15, 2023 at 10:15:11PM -0500, Tom Rini wrote:
> > On Mon, Jan 16, 2023 at 12:10:50PM +0900, AKASHI Takahiro wrote:
> > > Hi Tom,
> > > 
> > > On Sat, Jan 14, 2023 at 03:49:36PM -0500, Tom Rini wrote:
> > > > The event framework is just that, a framework. Enabling it by itself
> > > > does nothing, so we shouldn't ask the user about it. Reword (and correct
> > > > typos) around this the option and help text. This also applies to
> > > > DM_EVENT, so reword as well.
> > > > 
> > > > With this, it's time to address the larger problems. When functionality
> > > > uses events, typically via EVENT_SPY, the appropriate framework then
> > > > must be select'd and NOT imply'd. As the functionality will cease to
> > > > work (and so, platforms will fail to boot) this is non-optional and
> > > > where select is appropriate. Audit the current users of EVENT_SPY to
> > > > have a more fine-grained approach to select'ing the framework where
> > > > used.
> > > > 
> > > > Cc: Simon Glass 
> > > > Reported-by: Oliver Graute 
> > > > Reported-by: Francesco Dolcini 
> > > > Fixes: 7fe32b3442f0 ("event: Convert arch_cpu_init_dm() to use events")
> > > > Fixes: 42fdcebf859f ("event: Convert misc_init_f() to use events")
> > > > Signed-off-by: Tom Rini 
> > > > ---
> > > >  arch/Kconfig |  6 +++---
> > > >  arch/arm/Kconfig |  9 -
> > > >  arch/arm/mach-omap2/Kconfig  |  3 +++
> > > >  arch/mips/Kconfig|  2 +-
> > > >  arch/powerpc/cpu/mpc85xx/Kconfig |  1 +
> > > >  arch/x86/Kconfig |  1 +
> > > >  arch/x86/cpu/baytrail/Kconfig|  1 +
> > > >  arch/x86/cpu/broadwell/Kconfig   |  1 +
> > > >  arch/x86/cpu/ivybridge/Kconfig   |  1 +
> > > >  arch/x86/cpu/quark/Kconfig   |  1 +
> > > >  board/google/Kconfig |  1 +
> > > >  board/keymile/Kconfig|  1 +
> > > >  boot/Kconfig |  1 +
> > > >  cmd/Kconfig  |  1 +
> > > >  common/Kconfig   | 17 -
> > > >  drivers/core/Kconfig |  9 +
> > > >  drivers/cpu/Kconfig  |  1 -
> > > >  lib/efi_loader/Kconfig   |  5 ++---
> > > >  18 files changed, 36 insertions(+), 26 deletions(-)
> > > > 
> > > > diff --git a/arch/Kconfig b/arch/Kconfig
> > > > index 8fb87b7d857c..d30676ae817b 100644
> > > > --- a/arch/Kconfig
> > > > +++ b/arch/Kconfig
> > > > @@ -93,7 +93,7 @@ config NIOS2
> > > > bool "Nios II architecture"
> > > > select CPU
> > > > select DM
> > > > -   imply DM_EVENT
> > > > +   select DM_EVENT
> > > > select OF_CONTROL
> > > > select SUPPORT_OF_CONTROL
> > > > imply CMD_DM
> > > > @@ -111,9 +111,9 @@ config RISCV
> > > > select SUPPORT_OF_CONTROL
> > > > select OF_CONTROL
> > > > select DM
> > > > +   select DM_EVENT
> > > > imply SPL_SEPARATE_BSS if SPL
> > > > imply DM_SERIAL
> > > > -   imply DM_EVENT
> > > > imply DM_MMC
> > > > imply DM_SPI
> > > > imply DM_SPI_FLASH
> > > > @@ -136,6 +136,7 @@ config SANDBOX
> > > > select BZIP2
> > > > select CMD_POWEROFF
> > > > select DM
> > > > +   select DM_EVENT
> > > > select DM_FUZZING_ENGINE
> > > > select DM_GPIO
> > > > select DM_I2C
> > > > @@ -240,7 +241,6 @@ config X86
> > > > imply CMD_SF
> > > > imply CMD_SF_TEST
> > > > imply CMD_ZBOOT
> > > > -   imply DM_EVENT
> > > > imply DM_GPIO
> > > > imply DM_KEYBOARD
> > > > imply DM_MMC
> > > > diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig
> > > > index bbf1d5227b3f..c9a44ebc2213 100644
> > > > --- a/arch/arm/Kconfig
> > > > +++ b/arch/arm/Kconfig
> > > > @@ -778,7 +778,6 @@ config ARCH_OMAP2PLUS
> > > > select SUPPORT_SPL
> > > > imply TI_SYSC if DM && OF_CONTROL
> > > > imply FIT
> > > > -   imply DM_EVENT
> > > > imply SPL_SEPARATE_BSS
> > > >  
> > > >  config ARCH_MESON
> > > > @@ -823,11 +822,11 @@ config ARCH_IMX8
> > > > select SYS_FSL_SEC_COMPAT_4
> > > > select SYS_FSL_SEC_LE
> > > > select DM
> > > > +   select DM_EVENT
> > > > select GPIO_EXTRA_HEADER
> > > > select MACH_IMX
> > > > select OF_CONTROL
> > > > select ENABLE_ARM_SOC_BOOT0_HOOK
> > > > -   imply DM_EVENT
> > > >  
> > > >  config ARCH_IMX8M
> > > > bool "NXP i.MX8M platform"
> > > > @@ -839,14 +838,15 @@ config ARCH_IMX8M
> > > > select SYS_FSL_SEC_LE
> > > > select SYS_I2C_MXC
> > > > select DM
> > > > +   select DM_EVENT if CLK
> > > > select SUPPORT_SPL
> > > > imply CMD_DM
> > > > -   imply DM_EVENT
> > > >  
> > > >  config ARCH_IMX8ULP
> > > > bool "NXP i.MX8ULP platform"
> > > > select ARM64
> > > > se

Re: [PATCH v2 u-boot 2/3] powerpc/mpc85xx: socrates: Rename u-boot-socrates.bin to u-boot.bin

2023-01-15 Thread Heiko Schocher
Hello Tom, Pali,

On 14.01.23 22:24, Tom Rini wrote:
> On Sat, Jan 14, 2023 at 10:12:06PM +0100, Pali Rohár wrote:
>> On Friday 13 January 2023 18:16:03 Tom Rini wrote:
>>> On Sat, Jan 14, 2023 at 12:11:22AM +0100, Pali Rohár wrote:
 U-Boot build process for socrates board produces final U-Boot binary in
 file u-boot-socrates.bin (by binman) And as a bonus it produces two
 unusable broken binaries u-boot-dtb.bin and u-boot.bin (by Makefile).

 So do not build broken u-boot-dtb.bin and u-boot.bin binaries and rename
 board specific u-boot-socrates.bin binary to u-boot.bin.

 Renaming requires to define a new socrates specific Makefile target for
 u-boot.bin (via binman) and also changing output name in socrates binman
 config file.

 With this change U-Boot build process for socrates board also produces
 final U-Boot binary in file u-boot.bin.

 Signed-off-by: Pali Rohár 
 ---
 Added make dependency on u-boot.dtb
 ---
  Makefile  | 11 +++
  arch/powerpc/dts/socrates-u-boot.dtsi |  2 +-
  2 files changed, 12 insertions(+), 1 deletion(-)

 diff --git a/Makefile b/Makefile
 index a4a14d5d35a8..5473bea25332 100644
 --- a/Makefile
 +++ b/Makefile
 @@ -1195,22 +1195,30 @@ endif
  u-boot.bin: u-boot-fit-dtb.bin FORCE
$(call if_changed,copy)
  
 +ifneq ($(CONFIG_TARGET_SOCRATES),y)
  u-boot-dtb.bin: u-boot-nodtb.bin dts/dt.dtb FORCE
$(call if_changed,cat)
 +endif
  
  else ifeq ($(CONFIG_OF_SEPARATE).$(CONFIG_OF_OMIT_DTB),y.)
 +ifneq ($(CONFIG_TARGET_SOCRATES),y)
  u-boot-dtb.bin: u-boot-nodtb.bin dts/dt.dtb FORCE
$(call if_changed,cat)
 +endif
  
  ifneq ($(CONFIG_MPC85XX_HAVE_RESET_VECTOR)$(CONFIG_OF_SEPARATE),yy)
 +ifneq ($(CONFIG_TARGET_SOCRATES),y)
  u-boot.bin: u-boot-dtb.bin FORCE
$(call if_changed,copy)
  endif
 +endif
  
  else ifneq ($(CONFIG_MPC85XX_HAVE_RESET_VECTOR)$(CONFIG_OF_SEPARATE),yy)
 +ifneq ($(CONFIG_TARGET_SOCRATES),y)
  u-boot.bin: u-boot-nodtb.bin FORCE
$(call if_changed,copy)
  endif
 +endif
>>>
>>> Simon's point from before still stands. This is the opposite of what we
>>> want. There must not be CONFIG_TARGET_ logic introduced to the
>>> top-level Makefile. socrate is "just" another mpc85xx platform, it
>>> doesn't have a special ROM, we need to adjust it back to acting like
>>> other platforms.
>>
>> socrates has its own flash layout, own build procedure and purpose of
>> this patch is just to prevent another breakage (like it was done in the
>> past) by throwing make errors.
>>
>> Trying to adjust board code and changing its layout is really not up to
>> me. I do not have this board.
>>
>> One there is generic binman build rules from make then it can be
>> switches to that generic binman rule. Until it happen there is not
>> better option...
> 
> Yes, it should be Heiko, as the board maintainer, dealing with fixing
> this part. I don't understand the flash layout, and the partition table
> laid out in arch/powerpc/dts/socrates.dts confuses things even more to
> me. But, the board maintainer should be able to sort this all out.
> Because we do not want to add CONFIG_TARGET_ logic to the top-level
> Makefile.

Seems I missed this point from Simon... I take a look into it!

bye,
Heiko
-- 
DENX Software Engineering GmbH,  Managing Director: Erika Unter
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: +49-8142-66989-52   Fax: +49-8142-66989-80   Email: h...@denx.de


Re: [PATCH v3 3/3] eficonfig: add vertical scroll support

2023-01-15 Thread Masahisa Kojima
On Sat, 14 Jan 2023 at 19:26, Heinrich Schuchardt  wrote:
>
> On 1/14/23 11:06, Heinrich Schuchardt wrote:
> > On 1/5/23 03:58, Masahisa Kojima wrote:
> >> The current eficonfig menu does not support vertical scroll,
> >> so it can not display the menu entries greater than
> >> the console row size.
> >>
> >> This commit add the vertial scroll support.
> >> The console size is retrieved by
> >> SIMPLE_TEXT_OUTPUT_PROTOCOL.QueryMode() service, then
> >> calculates the row size for menu entry by subtracting
> >> menu header and description row size from the console row size.
> >> "start" and "end" are added in the efimenu structure.
> >> "start" keeps the menu entry index at the top, "end" keeps
> >> the bottom menu entry index. item_data_print() menu function
> >> only draws the menu entry between "start" and "end".
> >>
> >> Signed-off-by: Masahisa Kojima 
> >
> > Hello Masahisa,
> >
> > unfortunately this does not work.
> >
> > I create a boot.scr script to create 100 boot options:
> >
> > #!/bin/bash
> > a=0
> > while [ $a -lt 100 ]; do
> > b="$a"
> > c=${b: -4}
> > echo "efidebug boot add -b $c label$c host 0:1 dtbdump.efi" >> boot.txt
> > a=$(( $a + 1 ))
> > done
> > mkimage -T script -n foo -d boot.txt boot.scr
> > rm boot.txt
> >
> > In sandbox_defconfig:
> >
> > host bind 0 ../sandbox.img
> > host load 0:1 $kernel_addr_r boot.scr
> > source $kernel_addr_r
> > efidebug boot dump
> >
> > Now I have 100 boot options.
> >
> > I start 'eficonfig'. Whenever I push the up or down key this immediately
> > leads to exiting the command and I am back at the console prompt.
> >
> > Best regards
> >
> > Heinrich
> >
>
> The problem seems to be that the space for variables is exhausted.
> The user should see an error message in this case.

I will check the error cases and add error messages.
I will send a fix as a separate series.

>
> With CONFIG_EFI_VAR_BUF_SIZE=65536 the navigation works but I only see
> entries label - label0095. Where are the other entries?

Current eficonfig menu can have at most 99 entries.
I guess the following menu entries appears in your environment.
 - 96 entries (label - label0095)
 - 2 entries ("host 0:1" and "host 0:2"
 - 1 entry ("Quit")

The current maximum number of menu entries(99) is debatable,
I think the menu should have a predefined maximum number.

Thank you for your review and testing.

Best Regards,
Masahisa Kojima

>
> I have been adding CONFIG_LEGACY_IMAGE_FORMAT=y to read the boot.scr file.
>
> Best regards
>
> Heinrich


Re: [bug] timer: orion-timer: static variable patch breaks armada-388-clearfog boot

2023-01-15 Thread Martin Rowe
Tony,

> Did you build this clearfog board as is? i.e. did you make any change
> in the clearfog_defconfig?

clearfog_defconfig with:
CONFIG_MVEBU_SPL_BOOT_DEVICE_SATA=y
CONFIG_SPL_SATA=y

Plus a dts patch to sdhci@d8000 to make it work for eMMC (swap
cd-gpios for non-removable)
Plus a workaround that's not yet merged for a build failure with SATA from [1]

Shouldn't be anything that affects the timer, but I can try a fully
clean build with the defconfig if you need it.

Regards

Martin

[1] https://lore.kernel.org/u-boot/20230110161946.3816866-8-tr...@konsulko.com/


Re: [bug] timer: orion-timer: static variable patch breaks armada-388-clearfog boot

2023-01-15 Thread Tony Dinh
Hi Martin,

On Sat, Jan 14, 2023 at 9:31 PM Martin Rowe  wrote:
>
> Hi,
>
> Commit 5387b093 was a fix for early_init_done causing issues on Pogo
> v4 [1]. The fix breaks armada-388-clearfog because the boot hangs
> indefinitely.
>
> It appears that the cause is an infinite loop in __udelay due to
> get_ticks() always returning 0. After adding some printf statements it
> became apparent that the timer was never getting initialised.
>
> git-blame identified the "timer: orion-timer: Fix problem with early
> static variable" patch as a likely issue. Reverting the commit
> restores boot for armada-388-clearfog.

Did you build this clearfog board as is? i.e. did you make any change
in the clearfog_defconfig?

Thanks,
Tony


Tony

>
> Patching the issue is a bit beyond me without understanding the Pogo
> v4 issue, but I'm happy to test any patches that are developed.
>
> Regards
>
> Martin
>
> [1] https://lore.kernel.org/u-boot/20221221091849.1018783-1...@denx.de/


Re: [PATCH 2/2] event: Correct dependencies on the EVENT framework

2023-01-15 Thread AKASHI Takahiro
On Sun, Jan 15, 2023 at 10:15:11PM -0500, Tom Rini wrote:
> On Mon, Jan 16, 2023 at 12:10:50PM +0900, AKASHI Takahiro wrote:
> > Hi Tom,
> > 
> > On Sat, Jan 14, 2023 at 03:49:36PM -0500, Tom Rini wrote:
> > > The event framework is just that, a framework. Enabling it by itself
> > > does nothing, so we shouldn't ask the user about it. Reword (and correct
> > > typos) around this the option and help text. This also applies to
> > > DM_EVENT, so reword as well.
> > > 
> > > With this, it's time to address the larger problems. When functionality
> > > uses events, typically via EVENT_SPY, the appropriate framework then
> > > must be select'd and NOT imply'd. As the functionality will cease to
> > > work (and so, platforms will fail to boot) this is non-optional and
> > > where select is appropriate. Audit the current users of EVENT_SPY to
> > > have a more fine-grained approach to select'ing the framework where
> > > used.
> > > 
> > > Cc: Simon Glass 
> > > Reported-by: Oliver Graute 
> > > Reported-by: Francesco Dolcini 
> > > Fixes: 7fe32b3442f0 ("event: Convert arch_cpu_init_dm() to use events")
> > > Fixes: 42fdcebf859f ("event: Convert misc_init_f() to use events")
> > > Signed-off-by: Tom Rini 
> > > ---
> > >  arch/Kconfig |  6 +++---
> > >  arch/arm/Kconfig |  9 -
> > >  arch/arm/mach-omap2/Kconfig  |  3 +++
> > >  arch/mips/Kconfig|  2 +-
> > >  arch/powerpc/cpu/mpc85xx/Kconfig |  1 +
> > >  arch/x86/Kconfig |  1 +
> > >  arch/x86/cpu/baytrail/Kconfig|  1 +
> > >  arch/x86/cpu/broadwell/Kconfig   |  1 +
> > >  arch/x86/cpu/ivybridge/Kconfig   |  1 +
> > >  arch/x86/cpu/quark/Kconfig   |  1 +
> > >  board/google/Kconfig |  1 +
> > >  board/keymile/Kconfig|  1 +
> > >  boot/Kconfig |  1 +
> > >  cmd/Kconfig  |  1 +
> > >  common/Kconfig   | 17 -
> > >  drivers/core/Kconfig |  9 +
> > >  drivers/cpu/Kconfig  |  1 -
> > >  lib/efi_loader/Kconfig   |  5 ++---
> > >  18 files changed, 36 insertions(+), 26 deletions(-)
> > > 
> > > diff --git a/arch/Kconfig b/arch/Kconfig
> > > index 8fb87b7d857c..d30676ae817b 100644
> > > --- a/arch/Kconfig
> > > +++ b/arch/Kconfig
> > > @@ -93,7 +93,7 @@ config NIOS2
> > >   bool "Nios II architecture"
> > >   select CPU
> > >   select DM
> > > - imply DM_EVENT
> > > + select DM_EVENT
> > >   select OF_CONTROL
> > >   select SUPPORT_OF_CONTROL
> > >   imply CMD_DM
> > > @@ -111,9 +111,9 @@ config RISCV
> > >   select SUPPORT_OF_CONTROL
> > >   select OF_CONTROL
> > >   select DM
> > > + select DM_EVENT
> > >   imply SPL_SEPARATE_BSS if SPL
> > >   imply DM_SERIAL
> > > - imply DM_EVENT
> > >   imply DM_MMC
> > >   imply DM_SPI
> > >   imply DM_SPI_FLASH
> > > @@ -136,6 +136,7 @@ config SANDBOX
> > >   select BZIP2
> > >   select CMD_POWEROFF
> > >   select DM
> > > + select DM_EVENT
> > >   select DM_FUZZING_ENGINE
> > >   select DM_GPIO
> > >   select DM_I2C
> > > @@ -240,7 +241,6 @@ config X86
> > >   imply CMD_SF
> > >   imply CMD_SF_TEST
> > >   imply CMD_ZBOOT
> > > - imply DM_EVENT
> > >   imply DM_GPIO
> > >   imply DM_KEYBOARD
> > >   imply DM_MMC
> > > diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig
> > > index bbf1d5227b3f..c9a44ebc2213 100644
> > > --- a/arch/arm/Kconfig
> > > +++ b/arch/arm/Kconfig
> > > @@ -778,7 +778,6 @@ config ARCH_OMAP2PLUS
> > >   select SUPPORT_SPL
> > >   imply TI_SYSC if DM && OF_CONTROL
> > >   imply FIT
> > > - imply DM_EVENT
> > >   imply SPL_SEPARATE_BSS
> > >  
> > >  config ARCH_MESON
> > > @@ -823,11 +822,11 @@ config ARCH_IMX8
> > >   select SYS_FSL_SEC_COMPAT_4
> > >   select SYS_FSL_SEC_LE
> > >   select DM
> > > + select DM_EVENT
> > >   select GPIO_EXTRA_HEADER
> > >   select MACH_IMX
> > >   select OF_CONTROL
> > >   select ENABLE_ARM_SOC_BOOT0_HOOK
> > > - imply DM_EVENT
> > >  
> > >  config ARCH_IMX8M
> > >   bool "NXP i.MX8M platform"
> > > @@ -839,14 +838,15 @@ config ARCH_IMX8M
> > >   select SYS_FSL_SEC_LE
> > >   select SYS_I2C_MXC
> > >   select DM
> > > + select DM_EVENT if CLK
> > >   select SUPPORT_SPL
> > >   imply CMD_DM
> > > - imply DM_EVENT
> > >  
> > >  config ARCH_IMX8ULP
> > >   bool "NXP i.MX8ULP platform"
> > >   select ARM64
> > >   select DM
> > > + select DM_EVENT
> > >   select MACH_IMX
> > >   select OF_CONTROL
> > >   select SUPPORT_SPL
> > > @@ -854,19 +854,18 @@ config ARCH_IMX8ULP
> > >   select MISC
> > >   select IMX_SENTINEL
> > >   imply CMD_DM
> > > - imply DM_EVENT
> > >  
> > >  config ARCH_IMX9
> > >   bool "NXP i.MX9 platform"
> > >   select ARM64
> > >   select DM
> > > + select DM_EVENT
> > >   select MACH_IMX
> > >   select SUPPORT_SPL
> > >   select GPIO_EXTRA_HEADER
> > >   select MISC
> > >   select IMX_SENTINEL
> > >   imply CMD_DM
> > > - imply DM_EVENT
> > >  
> > >  config ARCH_IMXRT
> > >   bool "NXP i.MXRT platform"
> > > diff --git a/arch/arm/mac

[PATCH v5 03/13] gnu: u-boot: Reduce the number of native inputs.

2023-01-15 Thread Maxim Cournoyer
The extra python inputs are only needed for running the u-boot-test-tools test
suite.  This lowers the requirements for cross-building the various u-boot
packages.

* gnu/packages/bootloaders.scm (u-boot) [native-inputs]: Delete bc.
Move python-coverage, python-pycryptodomex and python-pytest to...
* gnu/packages/bootloaders.scm (u-boot-tools) [native-inputs]: ... here.

---

Changes in v5:
- New commit.

 gnu/packages/bootloaders.scm | 8 ++--
 1 file changed, 2 insertions(+), 6 deletions(-)

diff --git a/gnu/packages/bootloaders.scm b/gnu/packages/bootloaders.scm
index b17f8b1a9f..7ec26dda05 100644
--- a/gnu/packages/bootloaders.scm
+++ b/gnu/packages/bootloaders.scm
@@ -662,8 +662,7 @@ (define u-boot
 "1y5x8vxdgsqdqlsvq01mn8lmw53fqairkhvhhjx83hjva0m4id2h"
 (build-system  gnu-build-system)
 (native-inputs
- (list bc
-   bison
+ (list bison
dtc
gnutls
flex
@@ -672,9 +671,6 @@ (define u-boot
perl
pkg-config   ;for 'make menuconfig'
python
-   python-coverage
-   python-pycryptodomex
-   python-pytest
swig
(list util-linux "lib")))
 (home-page "https://www.denx.de/wiki/U-Boot/";)
@@ -725,7 +721,7 @@ (define-public u-boot-tools
 (name "u-boot-tools")
 (native-inputs
  (modify-inputs (package-native-inputs u-boot)
-   (prepend sdl2)))
+   (prepend python-coverage python-pycryptodomex python-pytest sdl2)))
 (arguments
  `(#:make-flags '("HOSTCC=gcc")
#:test-target "tcheck"
-- 
2.38.1



Re: [PATCH 2/2] event: Correct dependencies on the EVENT framework

2023-01-15 Thread Tom Rini
On Mon, Jan 16, 2023 at 12:10:50PM +0900, AKASHI Takahiro wrote:
> Hi Tom,
> 
> On Sat, Jan 14, 2023 at 03:49:36PM -0500, Tom Rini wrote:
> > The event framework is just that, a framework. Enabling it by itself
> > does nothing, so we shouldn't ask the user about it. Reword (and correct
> > typos) around this the option and help text. This also applies to
> > DM_EVENT, so reword as well.
> > 
> > With this, it's time to address the larger problems. When functionality
> > uses events, typically via EVENT_SPY, the appropriate framework then
> > must be select'd and NOT imply'd. As the functionality will cease to
> > work (and so, platforms will fail to boot) this is non-optional and
> > where select is appropriate. Audit the current users of EVENT_SPY to
> > have a more fine-grained approach to select'ing the framework where
> > used.
> > 
> > Cc: Simon Glass 
> > Reported-by: Oliver Graute 
> > Reported-by: Francesco Dolcini 
> > Fixes: 7fe32b3442f0 ("event: Convert arch_cpu_init_dm() to use events")
> > Fixes: 42fdcebf859f ("event: Convert misc_init_f() to use events")
> > Signed-off-by: Tom Rini 
> > ---
> >  arch/Kconfig |  6 +++---
> >  arch/arm/Kconfig |  9 -
> >  arch/arm/mach-omap2/Kconfig  |  3 +++
> >  arch/mips/Kconfig|  2 +-
> >  arch/powerpc/cpu/mpc85xx/Kconfig |  1 +
> >  arch/x86/Kconfig |  1 +
> >  arch/x86/cpu/baytrail/Kconfig|  1 +
> >  arch/x86/cpu/broadwell/Kconfig   |  1 +
> >  arch/x86/cpu/ivybridge/Kconfig   |  1 +
> >  arch/x86/cpu/quark/Kconfig   |  1 +
> >  board/google/Kconfig |  1 +
> >  board/keymile/Kconfig|  1 +
> >  boot/Kconfig |  1 +
> >  cmd/Kconfig  |  1 +
> >  common/Kconfig   | 17 -
> >  drivers/core/Kconfig |  9 +
> >  drivers/cpu/Kconfig  |  1 -
> >  lib/efi_loader/Kconfig   |  5 ++---
> >  18 files changed, 36 insertions(+), 26 deletions(-)
> > 
> > diff --git a/arch/Kconfig b/arch/Kconfig
> > index 8fb87b7d857c..d30676ae817b 100644
> > --- a/arch/Kconfig
> > +++ b/arch/Kconfig
> > @@ -93,7 +93,7 @@ config NIOS2
> > bool "Nios II architecture"
> > select CPU
> > select DM
> > -   imply DM_EVENT
> > +   select DM_EVENT
> > select OF_CONTROL
> > select SUPPORT_OF_CONTROL
> > imply CMD_DM
> > @@ -111,9 +111,9 @@ config RISCV
> > select SUPPORT_OF_CONTROL
> > select OF_CONTROL
> > select DM
> > +   select DM_EVENT
> > imply SPL_SEPARATE_BSS if SPL
> > imply DM_SERIAL
> > -   imply DM_EVENT
> > imply DM_MMC
> > imply DM_SPI
> > imply DM_SPI_FLASH
> > @@ -136,6 +136,7 @@ config SANDBOX
> > select BZIP2
> > select CMD_POWEROFF
> > select DM
> > +   select DM_EVENT
> > select DM_FUZZING_ENGINE
> > select DM_GPIO
> > select DM_I2C
> > @@ -240,7 +241,6 @@ config X86
> > imply CMD_SF
> > imply CMD_SF_TEST
> > imply CMD_ZBOOT
> > -   imply DM_EVENT
> > imply DM_GPIO
> > imply DM_KEYBOARD
> > imply DM_MMC
> > diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig
> > index bbf1d5227b3f..c9a44ebc2213 100644
> > --- a/arch/arm/Kconfig
> > +++ b/arch/arm/Kconfig
> > @@ -778,7 +778,6 @@ config ARCH_OMAP2PLUS
> > select SUPPORT_SPL
> > imply TI_SYSC if DM && OF_CONTROL
> > imply FIT
> > -   imply DM_EVENT
> > imply SPL_SEPARATE_BSS
> >  
> >  config ARCH_MESON
> > @@ -823,11 +822,11 @@ config ARCH_IMX8
> > select SYS_FSL_SEC_COMPAT_4
> > select SYS_FSL_SEC_LE
> > select DM
> > +   select DM_EVENT
> > select GPIO_EXTRA_HEADER
> > select MACH_IMX
> > select OF_CONTROL
> > select ENABLE_ARM_SOC_BOOT0_HOOK
> > -   imply DM_EVENT
> >  
> >  config ARCH_IMX8M
> > bool "NXP i.MX8M platform"
> > @@ -839,14 +838,15 @@ config ARCH_IMX8M
> > select SYS_FSL_SEC_LE
> > select SYS_I2C_MXC
> > select DM
> > +   select DM_EVENT if CLK
> > select SUPPORT_SPL
> > imply CMD_DM
> > -   imply DM_EVENT
> >  
> >  config ARCH_IMX8ULP
> > bool "NXP i.MX8ULP platform"
> > select ARM64
> > select DM
> > +   select DM_EVENT
> > select MACH_IMX
> > select OF_CONTROL
> > select SUPPORT_SPL
> > @@ -854,19 +854,18 @@ config ARCH_IMX8ULP
> > select MISC
> > select IMX_SENTINEL
> > imply CMD_DM
> > -   imply DM_EVENT
> >  
> >  config ARCH_IMX9
> > bool "NXP i.MX9 platform"
> > select ARM64
> > select DM
> > +   select DM_EVENT
> > select MACH_IMX
> > select SUPPORT_SPL
> > select GPIO_EXTRA_HEADER
> > select MISC
> > select IMX_SENTINEL
> > imply CMD_DM
> > -   imply DM_EVENT
> >  
> >  config ARCH_IMXRT
> > bool "NXP i.MXRT platform"
> > diff --git a/arch/arm/mach-omap2/Kconfig b/arch/arm/mach-omap2/Kconfig
> > index 1db71df27212..309b967b0dd5 100644
> > --- a/arch/arm/mach-omap2/Kconfig
> > +++ b/arch/arm/mach-omap2/Kconfig
> > @@ -31,6 +31,7 @@ config OMAP3

Re: [PATCH 2/2] event: Correct dependencies on the EVENT framework

2023-01-15 Thread AKASHI Takahiro
Hi Tom,

On Sat, Jan 14, 2023 at 03:49:36PM -0500, Tom Rini wrote:
> The event framework is just that, a framework. Enabling it by itself
> does nothing, so we shouldn't ask the user about it. Reword (and correct
> typos) around this the option and help text. This also applies to
> DM_EVENT, so reword as well.
> 
> With this, it's time to address the larger problems. When functionality
> uses events, typically via EVENT_SPY, the appropriate framework then
> must be select'd and NOT imply'd. As the functionality will cease to
> work (and so, platforms will fail to boot) this is non-optional and
> where select is appropriate. Audit the current users of EVENT_SPY to
> have a more fine-grained approach to select'ing the framework where
> used.
> 
> Cc: Simon Glass 
> Reported-by: Oliver Graute 
> Reported-by: Francesco Dolcini 
> Fixes: 7fe32b3442f0 ("event: Convert arch_cpu_init_dm() to use events")
> Fixes: 42fdcebf859f ("event: Convert misc_init_f() to use events")
> Signed-off-by: Tom Rini 
> ---
>  arch/Kconfig |  6 +++---
>  arch/arm/Kconfig |  9 -
>  arch/arm/mach-omap2/Kconfig  |  3 +++
>  arch/mips/Kconfig|  2 +-
>  arch/powerpc/cpu/mpc85xx/Kconfig |  1 +
>  arch/x86/Kconfig |  1 +
>  arch/x86/cpu/baytrail/Kconfig|  1 +
>  arch/x86/cpu/broadwell/Kconfig   |  1 +
>  arch/x86/cpu/ivybridge/Kconfig   |  1 +
>  arch/x86/cpu/quark/Kconfig   |  1 +
>  board/google/Kconfig |  1 +
>  board/keymile/Kconfig|  1 +
>  boot/Kconfig |  1 +
>  cmd/Kconfig  |  1 +
>  common/Kconfig   | 17 -
>  drivers/core/Kconfig |  9 +
>  drivers/cpu/Kconfig  |  1 -
>  lib/efi_loader/Kconfig   |  5 ++---
>  18 files changed, 36 insertions(+), 26 deletions(-)
> 
> diff --git a/arch/Kconfig b/arch/Kconfig
> index 8fb87b7d857c..d30676ae817b 100644
> --- a/arch/Kconfig
> +++ b/arch/Kconfig
> @@ -93,7 +93,7 @@ config NIOS2
>   bool "Nios II architecture"
>   select CPU
>   select DM
> - imply DM_EVENT
> + select DM_EVENT
>   select OF_CONTROL
>   select SUPPORT_OF_CONTROL
>   imply CMD_DM
> @@ -111,9 +111,9 @@ config RISCV
>   select SUPPORT_OF_CONTROL
>   select OF_CONTROL
>   select DM
> + select DM_EVENT
>   imply SPL_SEPARATE_BSS if SPL
>   imply DM_SERIAL
> - imply DM_EVENT
>   imply DM_MMC
>   imply DM_SPI
>   imply DM_SPI_FLASH
> @@ -136,6 +136,7 @@ config SANDBOX
>   select BZIP2
>   select CMD_POWEROFF
>   select DM
> + select DM_EVENT
>   select DM_FUZZING_ENGINE
>   select DM_GPIO
>   select DM_I2C
> @@ -240,7 +241,6 @@ config X86
>   imply CMD_SF
>   imply CMD_SF_TEST
>   imply CMD_ZBOOT
> - imply DM_EVENT
>   imply DM_GPIO
>   imply DM_KEYBOARD
>   imply DM_MMC
> diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig
> index bbf1d5227b3f..c9a44ebc2213 100644
> --- a/arch/arm/Kconfig
> +++ b/arch/arm/Kconfig
> @@ -778,7 +778,6 @@ config ARCH_OMAP2PLUS
>   select SUPPORT_SPL
>   imply TI_SYSC if DM && OF_CONTROL
>   imply FIT
> - imply DM_EVENT
>   imply SPL_SEPARATE_BSS
>  
>  config ARCH_MESON
> @@ -823,11 +822,11 @@ config ARCH_IMX8
>   select SYS_FSL_SEC_COMPAT_4
>   select SYS_FSL_SEC_LE
>   select DM
> + select DM_EVENT
>   select GPIO_EXTRA_HEADER
>   select MACH_IMX
>   select OF_CONTROL
>   select ENABLE_ARM_SOC_BOOT0_HOOK
> - imply DM_EVENT
>  
>  config ARCH_IMX8M
>   bool "NXP i.MX8M platform"
> @@ -839,14 +838,15 @@ config ARCH_IMX8M
>   select SYS_FSL_SEC_LE
>   select SYS_I2C_MXC
>   select DM
> + select DM_EVENT if CLK
>   select SUPPORT_SPL
>   imply CMD_DM
> - imply DM_EVENT
>  
>  config ARCH_IMX8ULP
>   bool "NXP i.MX8ULP platform"
>   select ARM64
>   select DM
> + select DM_EVENT
>   select MACH_IMX
>   select OF_CONTROL
>   select SUPPORT_SPL
> @@ -854,19 +854,18 @@ config ARCH_IMX8ULP
>   select MISC
>   select IMX_SENTINEL
>   imply CMD_DM
> - imply DM_EVENT
>  
>  config ARCH_IMX9
>   bool "NXP i.MX9 platform"
>   select ARM64
>   select DM
> + select DM_EVENT
>   select MACH_IMX
>   select SUPPORT_SPL
>   select GPIO_EXTRA_HEADER
>   select MISC
>   select IMX_SENTINEL
>   imply CMD_DM
> - imply DM_EVENT
>  
>  config ARCH_IMXRT
>   bool "NXP i.MXRT platform"
> diff --git a/arch/arm/mach-omap2/Kconfig b/arch/arm/mach-omap2/Kconfig
> index 1db71df27212..309b967b0dd5 100644
> --- a/arch/arm/mach-omap2/Kconfig
> +++ b/arch/arm/mach-omap2/Kconfig
> @@ -31,6 +31,7 @@ config OMAP34XX
>  
>  config OMAP44XX
>   bool "OMAP44XX SoC"
> + select DM_EVENT
>   select SPL_USE_TINY_PRINTF
>   select SPL_SYS_NO_VECTOR_TABLE if SPL
>   imply NAND_OMAP_ELM
> @@ -55,6 +56,7 @@ confi

Re: [PATCH v1 15/17] riscv: dts: jh7110: Add initial u-boot device tree

2023-01-15 Thread yanhong wang



On 2023/1/5 3:19, Sean Anderson wrote:
> On 12/11/22 21:50, Yanhong Wang wrote:
>> Add initial u-boot device tree for the JH7110 RISC-V SoC.
>>
>> Signed-off-by: Yanhong Wang 
>> ---
>>   arch/riscv/dts/jh7110-u-boot.dtsi | 86 +++
>>   1 file changed, 86 insertions(+)
>>   create mode 100644 arch/riscv/dts/jh7110-u-boot.dtsi
>>
>> diff --git a/arch/riscv/dts/jh7110-u-boot.dtsi 
>> b/arch/riscv/dts/jh7110-u-boot.dtsi
>> new file mode 100644
>> index 00..243237e83a
>> --- /dev/null
>> +++ b/arch/riscv/dts/jh7110-u-boot.dtsi
>> @@ -0,0 +1,86 @@
>> +// SPDX-License-Identifier: GPL-2.0 OR MIT
>> +/*
>> + * Copyright (C) 2022 StarFive Technology Co., Ltd.
>> + */
>> +
>> +#include 
>> +
>> +/ {
>> +    cpus: cpus {
>> +    u-boot,dm-spl;
>> +
>> +    cpu0: cpu@0 {
>> +    u-boot,dm-spl;
>> +    status = "okay";
>> +    cpu0_intc: interrupt-controller {
>> +    u-boot,dm-spl;
>> +    };
>> +    };
>> +
>> +    cpu1: cpu@1 {
>> +    u-boot,dm-spl;
>> +    cpu1_intc: interrupt-controller {
>> +    u-boot,dm-spl;
>> +    };
>> +    };
>> +
>> +    cpu2: cpu@2 {
>> +    u-boot,dm-spl;
>> +    cpu2_intc: interrupt-controller {
>> +    u-boot,dm-spl;
>> +    };
>> +    };
>> +
>> +    cpu3: cpu@3 {
>> +    u-boot,dm-spl;
>> +    cpu3_intc: interrupt-controller {
>> +    u-boot,dm-spl;
>> +    };
>> +    };
>> +
>> +    cpu4: cpu@4 {
>> +    u-boot,dm-spl;
>> +    cpu4_intc: interrupt-controller {
>> +    u-boot,dm-spl;
>> +    };
>> +    };
> 
> Use the S76_0/U74_1/etc references you defined earlier.
> 

Thanks, i will fix.

>> +    };
>> +
>> +    soc {
>> +    u-boot,dm-spl;
>> +
>> +    clint: clint@200 {
>> +    u-boot,dm-spl;
>> +    };
>> +
>> +    dmc: dmc@1570 {
>> +    u-boot,dm-spl;
>> +    compatible = "starfive,jh7110-dmc";
>> +    reg = <0x0 0x1570 0x0 0x1>,
>> +    <0x0 0x1300 0x0 0x1>;
>> +    resets = <&syscrg JH7110_SYSRST_DDR_AXI>,
>> +    <&syscrg JH7110_SYSRST_DDR_OSC>,
>> +    <&syscrg JH7110_SYSRST_DDR_APB>;
>> +    reset-names = "axi", "osc", "apb";
>> +    clocks = <&syscrg JH7110_SYSCLK_PLL1_OUT>;
>> +    clock-names = "pll1";
>> +    clock-frequency = <2133>;
>> +    };
> 
> This should go in the SoC dtsi.
> 

I will move it to the SoC dtsi.

>> +    };
>> +};
>> +
>> +&gmac0_rmii_refin {
>> +    u-boot,dm-spl;
>> +};
>> +
>> +&aoncrg {
>> +    u-boot,dm-spl;
>> +};
>> +
>> +&syscrg {
>> +    u-boot,dm-spl;
>> +};
>> +
>> +&stgcrg {
>> +    u-boot,dm-spl;
>> +};
> 


Re: [PATCH v1 10/17] board: starfive: add StarFive VisionFive v2 board support

2023-01-15 Thread yanhong wang



On 2023/1/5 3:18, Sean Anderson wrote:
> On 12/11/22 21:50, Yanhong Wang wrote:
>> Add board support for StarFive VisionFive v2.
>>
>> Signed-off-by: Yanhong Wang 
>> ---
>>   board/starfive/visionfive2/MAINTAINERS    |   7 ++
>>   board/starfive/visionfive2/Makefile   |   7 ++
>>   board/starfive/visionfive2/spl.c  | 119 ++
>>   .../visionfive2/starfive_visionfive2.c    |  39 ++
>>   include/configs/starfive-visionfive2.h    |  18 +++
>>   5 files changed, 190 insertions(+)
>>   create mode 100644 board/starfive/visionfive2/MAINTAINERS
>>   create mode 100644 board/starfive/visionfive2/Makefile
>>   create mode 100644 board/starfive/visionfive2/spl.c
>>   create mode 100644 board/starfive/visionfive2/starfive_visionfive2.c
>>   create mode 100644 include/configs/starfive-visionfive2.h
>>
>> diff --git a/board/starfive/visionfive2/MAINTAINERS 
>> b/board/starfive/visionfive2/MAINTAINERS
>> new file mode 100644
>> index 00..c5369086d8
>> --- /dev/null
>> +++ b/board/starfive/visionfive2/MAINTAINERS
>> @@ -0,0 +1,7 @@
>> +STARFIVE JH7110 VISIONFIVE2 BOARD
>> +M: startfive
>> +S:    Maintained
>> +F:    arch/riscv/include/asm/arch-jh7110/
>> +F:    board/starfive/visionfive2/
>> +F:    include/configs/starfive-visionfive2.h
>> +F:    configs/starfive_visionfive2_defconfig
>> diff --git a/board/starfive/visionfive2/Makefile 
>> b/board/starfive/visionfive2/Makefile
>> new file mode 100644
>> index 00..66c854df39
>> --- /dev/null
>> +++ b/board/starfive/visionfive2/Makefile
>> @@ -0,0 +1,7 @@
>> +# SPDX-License-Identifier: GPL-2.0+
>> +#
>> +# Copyright (C) 2022 StarFive Technology Co., Ltd.
>> +#
>> +
>> +obj-y    := starfive_visionfive2.o
>> +obj-$(CONFIG_SPL_BUILD) += spl.o
>> diff --git a/board/starfive/visionfive2/spl.c 
>> b/board/starfive/visionfive2/spl.c
>> new file mode 100644
>> index 00..473689eb71
>> --- /dev/null
>> +++ b/board/starfive/visionfive2/spl.c
>> @@ -0,0 +1,119 @@
>> +// SPDX-License-Identifier: GPL-2.0+
>> +/*
>> + * Copyright (C) 2022 StarFive Technology Co., Ltd.
>> + * Author:    Yanhong Wang
>> + *
>> + */
>> +
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +
>> +#define JH7110_CLK_CPU_ROOT_OFFSET    0x0U
>> +#define JH7110_CLK_CPU_ROOT_SHIFT    24
>> +#define JH7110_CLK_CPU_ROOT_MASK    GENMASK(29, 24)
>> +#define JH7110_CLK_BUS_ROOT_OFFSET    0x14U
>> +#define JH7110_CLK_BUS_ROOT_SHIFT    24
>> +#define JH7110_CLK_BUS_ROOT_MASK    GENMASK(29, 24)
>> +#define JH7110_CLK_PERH_ROOT_OFFSET    0x10U
>> +#define JH7110_CLK_PERH_ROOT_SHIFT    24
>> +#define JH7110_CLK_PERH_ROOT_MASK    GENMASK(29, 24)
>> +#define JH7110_CLK_NOC_BUS_STG_AXI_OFFSET    0x180U
>> +#define JH7110_CLK_NOC_BUS_STG_AXI_SHIFT    31
>> +#define JH7110_CLK_NOC_BUS_STG_AXI_MASK    BIT(31)
>> +#define JH7110_CLK_AON_APB_FUNC_OFFSET    0x4U
>> +#define JH7110_CLK_AON_APB_FUNC_SHIFT    24
>> +#define JH7110_CLK_AON_APB_FUNC_MASK    GENMASK(29, 24)
>> +#define JH7110_CLK_QSPI_REF_OFFSET    0x168U
>> +#define JH7110_CLK_QSPI_REF_SHIFT    24
>> +#define JH7110_CLK_QSPI_REF_MASK    GENMASK(29, 24)
>> +
>> +#define SET_DIV(type, val) \
>> +    clrsetbits_le32(JH7110_SYS_CRG + JH7110_CLK_##type##_OFFSET, \
>> +    JH7110_CLK_##type##_MASK, \
>> +    ((val) << JH7110_CLK_##type##_SHIFT) & JH7110_CLK_##type##_MASK)
>> +
>> +int spl_board_init_f(void)
>> +{
>> +    int ret;
>> +
>> +    ret = spl_soc_init();
>> +    if (ret) {
>> +    debug("JH7110 SPL init failed: %d\n", ret);
>> +    return ret;
>> +    }
>> +
>> +    return 0;
>> +}
>> +
>> +u32 spl_boot_device(void)
>> +{
>> +    u32 mode;
>> +
>> +    mode = in_le32(JH7110_BOOT_MODE_SELECT_REG)
>> +    & JH7110_BOOT_MODE_SELECT_MASK;
>> +    switch (mode) {
>> +    case 0:
>> +    return BOOT_DEVICE_SPI;
>> +
>> +    case 1:
>> +    return BOOT_DEVICE_MMC2;
>> +
>> +    case 2:
>> +    return BOOT_DEVICE_MMC1;
>> +
>> +    case 3:
>> +    return BOOT_DEVICE_UART;
>> +
>> +    default:
>> +    debug("Unsupported boot device 0x%x.\n", mode);
>> +    return BOOT_DEVICE_NONE;
>> +    }
>> +}
>> +
>> +void board_init_f(ulong dummy)
>> +{
>> +    int ret;
>> +
>> +    ret = spl_early_init();
>> +    if (ret)
>> +    panic("spl_early_init() failed: %d\n", ret);
>> +
>> +    riscv_cpu_setup(NULL, NULL);
>> +    preloader_console_init();
>> +
>> +    /* select clk_pll0 by default */
>> +    SET_DIV(CPU_ROOT, 1);
>> +
>> +    /* select clk_pll2 by default */
>> +    SET_DIV(BUS_ROOT, 1);
>> +
>> +    /* select clk_pll2 by default */
>> +    SET_DIV(PERH_ROOT, 1);
>> +
>> +    SET_DIV(NOC_BUS_STG_AXI, 1);
> 
> Use assigned-clock-parents/assigned-clock-rates.
> 
> --Sean
> 

thanks,i will fix.

>> +    clrsetbits_le32(JH7110_AON_CRG + JH7110_CLK_AON_APB_FUNC_OFFSET,
>> +    JH7110_CLK_AON_APB_FUNC_MASK,
>> +    BIT(JH7110_CLK_AON_APB_FUN

Re: [PATCH 1/3] binman: add sign option for binman

2023-01-15 Thread Ivan Mikhaylov
On Fri, 2023-01-13 at 11:00 -0700, Simon Glass wrote:
> Hi Ivan,
> 
> On Sat, 24 Dec 2022 at 15:35, Ivan Mikhaylov 
> wrote:
> > 
> > On Sat, 2022-12-17 at 15:02 -0700, Simon Glass wrote:
> > > Hi Ivan,
> > > 
> > > On Tue, 13 Dec 2022 at 11:51, Ivan Mikhaylov
> > > 
> > > wrote:
> > > > 
> > > > On Fri, 2022-11-18 at 13:50 -0700, Simon Glass wrote:
> > > > > Hi Ivan,
> > > > > 
> > > > > On Thu, 15 Sept 2022 at 13:44, Ivan Mikhaylov
> > > > > 
> > > > > wrote:
> > > > > > 
> > > > > > On Wed, 2022-09-07 at 15:10 -0600, Simon Glass wrote:
> > > > > > > Hi Ivan,
> > > > > > > 
> > > > > > > Section data comes from the BuildSectionData() method, so
> > > > > > > you
> > > > > > > could
> > > > > > > try calling that.
> > > > > > > 
> > > > > > > See also collect_contents_to_file()
> > > > > > > 
> > > > > > > Regards,
> > > > > > > Simon
> > > > > > 
> > > > > > Simon, I've tried both these ways and they both don't work
> > > > > > to
> > > > > > me.
> > > > > > What
> > > > > > I've got:
> > > > > > 
> > > > > > def SignEntries(image_fname, input_fname, privatekey_fname,
> > > > > > algo,
> > > > > > entry_paths):
> > > > > >     image_fname = os.path.abspath(image_fname)
> > > > > >     image = Image.FromFile(image_fname)
> > > > > >     state.PrepareFromLoadedData(image)
> > > > > >     image.LoadData()
> > > > > > 
> > > > > > 1. BuildSectionData
> > > > > > 
> > > > > >     for entry_path in entry_paths:
> > > > > >     entry = image.FindEntryPath(entry_path)
> > > > > > 
> > > > > >     try:
> > > > > >     entry.BuildSectionData(True)
> > > > > >     except Exception as e:
> > > > > >     logging.error(traceback.format_exc())
> > > > > > 
> > > > > > 
> > > > > > ERROR:root:AttributeError: 'NoneType' object has no
> > > > > > attribute
> > > > > > 'run'
> > > > 
> > > > Hi Simon, sorry for long delay.
> > > > 
> > > > binman: 'NoneType' object has no attribute 'run'
> > > > 
> > > > Traceback (most recent call last):
> > > >   File "/home/fr/upstream_uboot/tools/binman/binman", line 133,
> > > > in
> > > > RunBinman
> > > >     ret_code = control.Binman(args)
> > > >   File "/home/fr/upstream_uboot/tools/binman/control.py", line
> > > > 684,
> > > > in
> > > > Binman
> > > >     SignEntries(args.image, args.file, args.key, args.algo,
> > > > args.paths)
> > > >   File "/home/fr/upstream_uboot/tools/binman/control.py", line
> > > > 469,
> > > > in
> > > > SignEntries
> > > >     entry.BuildSectionData(True)
> > > >   File "/home/fr/upstream_uboot/tools/binman/etype/fit.py",
> > > > line
> > > > 426,
> > > > in BuildSectionData
> > > >     if self.mkimage.run(reset_timestamp=True,
> > > > output_fname=output_fname,
> > > > AttributeError: 'NoneType' object has no attribute 'run'
> > > > 
> > > 
> > > You need to call image.CollectBintolls() like ReadEntry() and
> > > other
> > > functions similar to yours that read images from a file. This is
> > > the
> > > only way that the 'mkimage' tool becomes available to fit.py
> > > 
> > > See fit.AddBintools() which is called by that function and sets
> > > 'self.mkimage'
> > > > 
> > Simon, thanks, now this part works fine but there is still issue
> > with
> > updating of fit section, saw that there exists some functions like
> > WriteData but for section(etype/fit.py) it is not implemented yet.
> > 
> > ValueError: Node '/fit': Replacing sections is not implemented yet
> > 
> > Also tried SetContents but it doesn't update fit section in place.
> > Any
> > suggestions here?
> 
> Updating a FIT in the image is not supported, or at least not tested,
> so presumably doesn't work.
> 
> I obtained fdt_add_pubkey
> from
> https://patchwork.ozlabs.org/project/uboot/list/?series=271511&state=
> *
> 
> I tried this:
> 
> binman test testSignSimple
>  Running binman tests
> 
> E
> =
> =
> ERROR: binman.ftest.TestFunctional.testSignSimple
> (subunit.RemotedTestCase)
> binman.ftest.TestFunctional.testSignSimple
> -
> -
> testtools.testresult.real._StringException: ValueError: Error 1
> running 'fdt_add_pubkey -a sha256,rsa4096 -k /tmp/binman.1antmyoq -n
> test_key /tmp/binman.1antmyoq/source.dtb': .dtb too small, increasing
> size by 1024 bytes
> .dtb too small, increasing size by 1024 bytes
> fdt_add_pubkey: Cannot add public key to FIT blob: Unknown error -56
> 
> 
> During handling of the above exception, another exception occurred:
> 
> UnboundLocalError: local variable 'key_dir' referenced before
> assignment
> 
> 
> -
> -
> Ran 1 test in 1.658s
> 
> FAILED (errors=1)
> 
> [sjg@kea u ((5cf6f1f8e7c...) $)]$ binman test testSignSimpleExact
>  Running binman tests
> 
> 
> -
> -
> R

[PATCH 5/5] spmi: msm: Fix up msm_spmi_write() for ARB V5

2023-01-15 Thread Alexey Minnekhanov
In commit f5a2d6b4b03a ("spmi: msm: add arbiter version 5 support")
support for arbiter V5 was introduced, and msm_spmi_read() was
correctly converted to use varying channel offset depending on
ARB version. But msm_spmi_write() was not fully converted.

Even though ch_offset variable was introduced, it was not used
in read/write operations in that function. Fix this inconsistency,
use calculated ch_offset instead of SPMI_CH_OFFSET(..).

Fixes: f5a2d6b4b03a ("spmi: msm: add arbiter version 5 support")

Signed-off-by: Alexey Minnekhanov 
---
 drivers/spmi/spmi-msm.c | 19 ---
 1 file changed, 8 insertions(+), 11 deletions(-)

diff --git a/drivers/spmi/spmi-msm.c b/drivers/spmi/spmi-msm.c
index 3df0f12c8b86..2174c10c920a 100644
--- a/drivers/spmi/spmi-msm.c
+++ b/drivers/spmi/spmi-msm.c
@@ -92,13 +92,16 @@ static int msm_spmi_write(struct udevice *dev, int usid, 
int pid, int off,
return -EIO;
 
channel = priv->channel_map[usid][pid];
+   if (priv->arb_ver == V5)
+   ch_offset = SPMI_V5_RW_CH_OFFSET(channel);
+   else
+   ch_offset = SPMI_CH_OFFSET(channel);
 
/* Disable IRQ mode for the current channel*/
-   writel(0x0,
-  priv->spmi_core + SPMI_CH_OFFSET(channel) + SPMI_REG_CONFIG);
+   writel(0x0, priv->spmi_core + ch_offset + SPMI_REG_CONFIG);
 
/* Write single byte */
-   writel(val, priv->spmi_core + SPMI_CH_OFFSET(channel) + SPMI_REG_WDATA);
+   writel(val, priv->spmi_core + ch_offset + SPMI_REG_WDATA);
 
/* Prepare write command */
reg |= SPMI_CMD_EXT_REG_WRITE_LONG << SPMI_CMD_OPCODE_SHIFT;
@@ -107,19 +110,13 @@ static int msm_spmi_write(struct udevice *dev, int usid, 
int pid, int off,
reg |= (off << SPMI_CMD_ADDR_OFFSET_SHIFT);
reg |= 1; /* byte count */
 
-   if (priv->arb_ver == V5)
-   ch_offset = SPMI_V5_RW_CH_OFFSET(channel);
-   else
-   ch_offset = SPMI_CH_OFFSET(channel);
-
/* Send write command */
-   writel(reg, priv->spmi_core + SPMI_CH_OFFSET(channel) + SPMI_REG_CMD0);
+   writel(reg, priv->spmi_core + ch_offset + SPMI_REG_CMD0);
 
/* Wait till CMD DONE status */
reg = 0;
while (!reg) {
-   reg = readl(priv->spmi_core + SPMI_CH_OFFSET(channel) +
-   SPMI_REG_STATUS);
+   reg = readl(priv->spmi_core + ch_offset + SPMI_REG_STATUS);
}
 
if (reg ^ SPMI_STATUS_DONE) {
-- 
2.38.2



[PATCH 4/5] arm64: dts: qcom: Fix SPMI arbiter regs and reg-names

2023-01-15 Thread Alexey Minnekhanov
Now that reg-names is required, specify them, and use correct
addresses for SPMI arbiter regs, taken from Linux dts [1] [2].

[1] 
https://elixir.bootlin.com/linux/v6.1.5/source/arch/arm64/boot/dts/qcom/qcs404.dtsi#L739
[2] 
https://elixir.bootlin.com/linux/v6.1.5/source/arch/arm64/boot/dts/qcom/sdm845.dtsi#L4896

Signed-off-by: Alexey Minnekhanov 
---
 arch/arm/dts/qcs404-evb.dts | 7 ---
 arch/arm/dts/sdm845.dtsi| 8 
 2 files changed, 8 insertions(+), 7 deletions(-)

diff --git a/arch/arm/dts/qcs404-evb.dts b/arch/arm/dts/qcs404-evb.dts
index 0639af8fe336..6bf6736139ed 100644
--- a/arch/arm/dts/qcs404-evb.dts
+++ b/arch/arm/dts/qcs404-evb.dts
@@ -171,9 +171,10 @@
 
spmi@200f000 {
compatible = "qcom,spmi-pmic-arb";
-   reg = <0x200f000 0x1000
-  0x240 0x40
-  0x2c0 0x40>;
+   reg = <0x0200f000 0x1000>,
+ <0x0200a000 0x2100>,
+ <0x02c0 0x80>;
+   reg-names = "core", "cnfg", "obsrvr";
#address-cells = <0x1>;
#size-cells = <0x1>;
 
diff --git a/arch/arm/dts/sdm845.dtsi b/arch/arm/dts/sdm845.dtsi
index 607af277f8be..2bb0954133c5 100644
--- a/arch/arm/dts/sdm845.dtsi
+++ b/arch/arm/dts/sdm845.dtsi
@@ -65,10 +65,10 @@
 
spmi@c44 {
compatible = "qcom,spmi-pmic-arb";
-   reg = <0xc44 0x1100>,
- <0xc60 0x200>,
- <0xe60 0x10>;
-   reg-names = "cnfg", "core", "obsrvr";
+   reg = <0x0c44 0x1100>,
+ <0x0c40a000 0x26000>,
+ <0x0e60 0x10>;
+   reg-names = "core", "cnfg", "obsrvr";
#address-cells = <0x1>;
#size-cells = <0x1>;
 
-- 
2.38.2



[PATCH 3/5] doc: spmi-msm: Update docs to reflect current state

2023-01-15 Thread Alexey Minnekhanov
Update spmi-msm documentation and example to reflect the current
state of the driver.

Signed-off-by: Alexey Minnekhanov 
---
 doc/device-tree-bindings/spmi/spmi-msm.txt | 21 ++---
 1 file changed, 14 insertions(+), 7 deletions(-)

diff --git a/doc/device-tree-bindings/spmi/spmi-msm.txt 
b/doc/device-tree-bindings/spmi/spmi-msm.txt
index ae47673b768b..cd0380b723b9 100644
--- a/doc/device-tree-bindings/spmi/spmi-msm.txt
+++ b/doc/device-tree-bindings/spmi/spmi-msm.txt
@@ -1,13 +1,17 @@
 Qualcomm SPMI arbiter/bus driver
 
 This is bus driver for Qualcomm chips that use SPMI to communicate with PMICs.
+The SPMI PMIC Arbiter is found on Snapdragon chipsets. It is an SPMI
+controller with wrapping arbitration logic to allow for multiple on-chip
+devices to control a single SPMI master.
 
 Required properties:
 - compatible: "qcom,spmi-pmic-arb"
 - reg: Register block adresses and sizes for various parts of device:
-   1) PMIC arbiter channel mapping base (PMIC_ARB_REG_CHNLn)
-   2) SPMI write command (master) registers (PMIC_ARB_CORE_SW_DEC_CHANNELS)
-   3) SPMI read command (observer) registers (PMIC_ARB_CORE_REGISTERS_OBS)
+   1) PMIC arbiter core registers
+   2) SPMI configuration registers
+   3) SPMI read command (observer) registers
+- reg-names: "core", "cnfg", "obsrvr" for corresponding reg values
 
 Optional properties (if not set by parent):
 - #address-cells: 0x1 - childs slave ID address
@@ -18,9 +22,12 @@ Automatic detection of childs is currently not supported.
 
 Example:
 
-spmi@200f000 {
+spmi@fc4cf000 {
compatible = "qcom,spmi-pmic-arb";
-   reg = <0x200f800 0x200 0x240 0x40 0x2c0 0x40>;
-   #address-cells = <0x1>;
-   #size-cells = <0x1>;
+   reg = <0xfc4cf000 0x1000>,
+ <0xfc4cb000 0x1000>,
+ <0xfc4ca000 0x1000>;
+   reg-names = "core", "cnfg", "obsrvr";
+   #address-cells = <1>;
+   #size-cells = <1>;
 };
-- 
2.38.2



[PATCH 2/5] spmi: msm: Fix parsing FDT and reading ARB version

2023-01-15 Thread Alexey Minnekhanov
First of all, use dev_read_addr_name() instead of
dev_read_addr_index() to avoid confusion: most dts files
have their regs specified in the wrong order, so driver
is reading config reg and using it instead of core reg.
Using names instead of indexes helps to avoid such errors.

Second, same as Linux driver, use core reg to read version
from [1]. This fixes reading incorrect arbiter version.

Third, print addresses in hex, so it can be visually
compared to values in DTS more easily.

[1]: 
https://elixir.bootlin.com/linux/v6.1.6/source/drivers/spmi/spmi-pmic-arb.c#L1339

Signed-off-by: Alexey Minnekhanov 
---
 drivers/spmi/spmi-msm.c | 16 +---
 1 file changed, 9 insertions(+), 7 deletions(-)

diff --git a/drivers/spmi/spmi-msm.c b/drivers/spmi/spmi-msm.c
index a9dcf5ab7f91..3df0f12c8b86 100644
--- a/drivers/spmi/spmi-msm.c
+++ b/drivers/spmi/spmi-msm.c
@@ -191,11 +191,12 @@ static int msm_spmi_probe(struct udevice *dev)
u32 version;
int i;
 
-   config_addr = dev_read_addr_index(dev, 0);
-   priv->spmi_core = dev_read_addr_index(dev, 1);
-   priv->spmi_obs = dev_read_addr_index(dev, 2);
+   /* DTS bindings: reg-names = "cnfg", "core", "obsrvr"; */
+   config_addr = dev_read_addr_name(dev, "cnfg");
+   priv->spmi_core = dev_read_addr_name(dev, "core");
+   priv->spmi_obs = dev_read_addr_name(dev, "obsrvr");
 
-   hw_ver = readl(config_addr + PMIC_ARB_VERSION);
+   hw_ver = readl(priv->spmi_core + PMIC_ARB_VERSION);
 
if (hw_ver < PMIC_ARB_VERSION_V3_MIN) {
priv->arb_ver = V2;
@@ -218,9 +219,10 @@ static int msm_spmi_probe(struct udevice *dev)
priv->spmi_obs == FDT_ADDR_T_NONE)
return -EINVAL;
 
-   dev_dbg(dev, "priv->arb_chnl address (%llu)\n", priv->arb_chnl);
-   dev_dbg(dev, "priv->spmi_core address (%llu)\n", priv->spmi_core);
-   dev_dbg(dev, "priv->spmi_obs address (%llu)\n", priv->spmi_obs);
+   dev_dbg(dev, "priv->arb_chnl address (%llx)\n", priv->arb_chnl);
+   dev_dbg(dev, "priv->spmi_core address (%llx)\n", priv->spmi_core);
+   dev_dbg(dev, "priv->spmi_obs address (%llx)\n", priv->spmi_obs);
+
/* Scan peripherals connected to each SPMI channel */
for (i = 0; i < SPMI_MAX_PERIPH; i++) {
uint32_t periph = readl(priv->arb_chnl + ARB_CHANNEL_OFFSET(i));
-- 
2.38.2



[PATCH 1/5] spmi: msm: Remove wrong and unused code

2023-01-15 Thread Alexey Minnekhanov
Variable err is never initialized and therefore not needed,
as well as the whole error handler block; the mentioned
"APID->PPID mapping table" is never read in the code anyways.

Signed-off-by: Alexey Minnekhanov 
---
 drivers/spmi/spmi-msm.c | 6 --
 1 file changed, 6 deletions(-)

diff --git a/drivers/spmi/spmi-msm.c b/drivers/spmi/spmi-msm.c
index 27a035c0a595..a9dcf5ab7f91 100644
--- a/drivers/spmi/spmi-msm.c
+++ b/drivers/spmi/spmi-msm.c
@@ -190,7 +190,6 @@ static int msm_spmi_probe(struct udevice *dev)
u32 hw_ver;
u32 version;
int i;
-   int err;
 
config_addr = dev_read_addr_index(dev, 0);
priv->spmi_core = dev_read_addr_index(dev, 1);
@@ -210,11 +209,6 @@ static int msm_spmi_probe(struct udevice *dev)
priv->arb_ver = V5;
version = 5;
priv->arb_chnl = config_addr + APID_MAP_OFFSET_V5;
-
-   if (err) {
-   dev_err(dev, "could not read APID->PPID mapping table, 
rc= %d\n", err);
-   return -1;
-   }
}
 
dev_dbg(dev, "PMIC Arb Version-%d (0x%x)\n", version, hw_ver);
-- 
2.38.2



[PATCH 0/5] spmi:msm: Several fixes

2023-01-15 Thread Alexey Minnekhanov
In the process of porting my board to u-boot I've noticed incorrect
behaviour, some things that clearly look wrong, and other strange
things. Here go several fixes to MSM SPMI driver, mostly related
to newer platforms support.

Alexey Minnekhanov (5):
  spmi: msm: Remove wrong and unused code
  spmi: msm: Fix parsing FDT and reading ARB version
  doc: spmi-msm: Update docs to reflect current state
  arm64: dts: qcom: Fix SPMI arbiter regs and reg-names
  spmi: msm: Fix up msm_spmi_write() for ARB V5

 arch/arm/dts/qcs404-evb.dts|  7 ++--
 arch/arm/dts/sdm845.dtsi   |  8 ++---
 doc/device-tree-bindings/spmi/spmi-msm.txt | 21 +++
 drivers/spmi/spmi-msm.c| 41 +-
 4 files changed, 39 insertions(+), 38 deletions(-)

-- 
2.38.2



Re: [PATCH 2/2] event: Correct dependencies on the EVENT framework

2023-01-15 Thread Tom Rini
On Sun, Jan 15, 2023 at 02:52:35PM -0700, Simon Glass wrote:
> Hi Tom,
> 
> On Sun, 15 Jan 2023 at 06:45, Tom Rini  wrote:
> >
> > On Sat, Jan 14, 2023 at 06:31:05PM -0700, Simon Glass wrote:
> > > Hi Tom,
> > >
> > > On Sat, 14 Jan 2023 at 13:49, Tom Rini  wrote:
> > > >
> > > > The event framework is just that, a framework. Enabling it by itself
> > > > does nothing, so we shouldn't ask the user about it. Reword (and correct
> > > > typos) around this the option and help text. This also applies to
> > > > DM_EVENT, so reword as well.
> > > >
> > > > With this, it's time to address the larger problems. When functionality
> > > > uses events, typically via EVENT_SPY, the appropriate framework then
> > > > must be select'd and NOT imply'd. As the functionality will cease to
> > > > work (and so, platforms will fail to boot) this is non-optional and
> > > > where select is appropriate. Audit the current users of EVENT_SPY to
> > > > have a more fine-grained approach to select'ing the framework where
> > > > used.
> > > >
> > > > Cc: Simon Glass 
> > > > Reported-by: Oliver Graute 
> > > > Reported-by: Francesco Dolcini 
> > > > Fixes: 7fe32b3442f0 ("event: Convert arch_cpu_init_dm() to use events")
> > > > Fixes: 42fdcebf859f ("event: Convert misc_init_f() to use events")
> > > > Signed-off-by: Tom Rini 
> > > > ---
> > > >  arch/Kconfig |  6 +++---
> > > >  arch/arm/Kconfig |  9 -
> > > >  arch/arm/mach-omap2/Kconfig  |  3 +++
> > > >  arch/mips/Kconfig|  2 +-
> > > >  arch/powerpc/cpu/mpc85xx/Kconfig |  1 +
> > > >  arch/x86/Kconfig |  1 +
> > > >  arch/x86/cpu/baytrail/Kconfig|  1 +
> > > >  arch/x86/cpu/broadwell/Kconfig   |  1 +
> > > >  arch/x86/cpu/ivybridge/Kconfig   |  1 +
> > > >  arch/x86/cpu/quark/Kconfig   |  1 +
> > > >  board/google/Kconfig |  1 +
> > > >  board/keymile/Kconfig|  1 +
> > > >  boot/Kconfig |  1 +
> > > >  cmd/Kconfig  |  1 +
> > > >  common/Kconfig   | 17 -
> > > >  drivers/core/Kconfig |  9 +
> > > >  drivers/cpu/Kconfig  |  1 -
> > >
> > > Reviewed-by: Simon Glass 
> > >
> > > Tested on chromebook-coral:
> > > Tested-by: Simon Glass 
> > >
> > > I am not quite sure what the effective difference is between select
> > > and imply. Doesn't this suggest that there are some conflicting config
> > > options? The only way imply would be disabled ( I thought) is if a
> > > board does it explicitly?
> >
> > So there's two parts to it. As a framework, the option needs to be
> > select'd, not implied. It doesn't make sense to disable the event
> > framework and then wonder why VBE doesn't work. The next part however is
> >
> > Fixes: c5ef2025579e ("dm: fix DM_EVENT dependencies")
> 
> OK
> 
> >
> > should have been part of it too. That commit turned all of the platforms
> > which had imply DM_EVENT (and so from DM_EVENT, imply EVENT) in to
> > depends on EVENT being set, and if it wasn't set (or select'd, only
> > EFI_LOADER was select'ing it at the time) in to not enabling DM_EVENT,
> > and since imply options can be off, no warnings were thrown by the build
> > system. And since all of the non-dynamic EVENT stuff is linker-based,
> > no binary size changes happened either.
> 
> So does this mean that select is 'forcing' the option to be enabled,
> even if it conflicts with something else, or depends on something
> which is not set?
> 
> I'd quite like to understand this better for the future. Could you
> point to a board that was broken and now fixed, so I can have a fiddle
> with it?

While kernel centric at times (of course)
https://www.kernel.org/doc/html/latest/kbuild/kconfig-language.html#menu-attributes
covers things well, especially for the language itself. So yes, select
forces the option to be enabled. If there's an unmet (depends on ...)
dependency, then it will emit a warning to tell you as such. An example
of a previously broken board would be apalis-imx8 as it does not enable
EFI_LOADER so no DM_EVENT / EVENT and so:
arch/arm/mach-imx/imx8/cpu.c:EVENT_SPY(EVT_DM_POST_INIT, imx8_init_mu);
wasn't called and the platform would silently fail to boot.

-- 
Tom


signature.asc
Description: PGP signature


Re: [PATCH 2/2] event: Correct dependencies on the EVENT framework

2023-01-15 Thread Simon Glass
Hi Tom,

On Sun, 15 Jan 2023 at 06:45, Tom Rini  wrote:
>
> On Sat, Jan 14, 2023 at 06:31:05PM -0700, Simon Glass wrote:
> > Hi Tom,
> >
> > On Sat, 14 Jan 2023 at 13:49, Tom Rini  wrote:
> > >
> > > The event framework is just that, a framework. Enabling it by itself
> > > does nothing, so we shouldn't ask the user about it. Reword (and correct
> > > typos) around this the option and help text. This also applies to
> > > DM_EVENT, so reword as well.
> > >
> > > With this, it's time to address the larger problems. When functionality
> > > uses events, typically via EVENT_SPY, the appropriate framework then
> > > must be select'd and NOT imply'd. As the functionality will cease to
> > > work (and so, platforms will fail to boot) this is non-optional and
> > > where select is appropriate. Audit the current users of EVENT_SPY to
> > > have a more fine-grained approach to select'ing the framework where
> > > used.
> > >
> > > Cc: Simon Glass 
> > > Reported-by: Oliver Graute 
> > > Reported-by: Francesco Dolcini 
> > > Fixes: 7fe32b3442f0 ("event: Convert arch_cpu_init_dm() to use events")
> > > Fixes: 42fdcebf859f ("event: Convert misc_init_f() to use events")
> > > Signed-off-by: Tom Rini 
> > > ---
> > >  arch/Kconfig |  6 +++---
> > >  arch/arm/Kconfig |  9 -
> > >  arch/arm/mach-omap2/Kconfig  |  3 +++
> > >  arch/mips/Kconfig|  2 +-
> > >  arch/powerpc/cpu/mpc85xx/Kconfig |  1 +
> > >  arch/x86/Kconfig |  1 +
> > >  arch/x86/cpu/baytrail/Kconfig|  1 +
> > >  arch/x86/cpu/broadwell/Kconfig   |  1 +
> > >  arch/x86/cpu/ivybridge/Kconfig   |  1 +
> > >  arch/x86/cpu/quark/Kconfig   |  1 +
> > >  board/google/Kconfig |  1 +
> > >  board/keymile/Kconfig|  1 +
> > >  boot/Kconfig |  1 +
> > >  cmd/Kconfig  |  1 +
> > >  common/Kconfig   | 17 -
> > >  drivers/core/Kconfig |  9 +
> > >  drivers/cpu/Kconfig  |  1 -
> >
> > Reviewed-by: Simon Glass 
> >
> > Tested on chromebook-coral:
> > Tested-by: Simon Glass 
> >
> > I am not quite sure what the effective difference is between select
> > and imply. Doesn't this suggest that there are some conflicting config
> > options? The only way imply would be disabled ( I thought) is if a
> > board does it explicitly?
>
> So there's two parts to it. As a framework, the option needs to be
> select'd, not implied. It doesn't make sense to disable the event
> framework and then wonder why VBE doesn't work. The next part however is
>
> Fixes: c5ef2025579e ("dm: fix DM_EVENT dependencies")

OK

>
> should have been part of it too. That commit turned all of the platforms
> which had imply DM_EVENT (and so from DM_EVENT, imply EVENT) in to
> depends on EVENT being set, and if it wasn't set (or select'd, only
> EFI_LOADER was select'ing it at the time) in to not enabling DM_EVENT,
> and since imply options can be off, no warnings were thrown by the build
> system. And since all of the non-dynamic EVENT stuff is linker-based,
> no binary size changes happened either.

So does this mean that select is 'forcing' the option to be enabled,
even if it conflicts with something else, or depends on something
which is not set?

I'd quite like to understand this better for the future. Could you
point to a board that was broken and now fixed, so I can have a fiddle
with it?

Thanks,
Simon


Re: [PATCH 07/24] trace: Reduce the default for TRACE_EARLY_CALL_DEPTH_LIMIT

2023-01-15 Thread Heinrich Schuchardt



Am 15. Januar 2023 22:15:44 MEZ schrieb Simon Glass :
>This is a silly value at present, since U-Boot's call depth never reaches
>200. Fix it.
>
>Signed-off-by: Simon Glass 
>---
>
> lib/Kconfig | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
>diff --git a/lib/Kconfig b/lib/Kconfig
>index a83f32d82a5..11968a0c531 100644
>--- a/lib/Kconfig
>+++ b/lib/Kconfig
>@@ -368,7 +368,7 @@ config TRACE_EARLY_SIZE
> config TRACE_EARLY_CALL_DEPTH_LIMIT
>   int "Early trace call depth limit"
>   depends on TRACE_EARLY
>-  default 200

The call depth when running the EFI SCT by far exceeds 15.

Is the suggested change relevant after reaching the cli?

Did you measure the actual call depth?

Best regards

Heinrich 

>+  default 15
>   help
> Sets the maximum call depth up to which function calls are recorded
> during early tracing.


[PATCH 21/24] trace: Provide a flamegraph that uses timing

2023-01-15 Thread Simon Glass
Add a second variant of the flame graph that shows records in terms of the
number of microseconds used by each call stack. This is a useful way of
seeing where time is going within the execution of U-Boot.

This requires a call stack that records the start time of each function,
as well as a way of subtracting all time consumed by child functions, so
that this time is not counted twice by the flamegraph. The time values in
the output are just for the function itself, not for its children.

Signed-off-by: Simon Glass 
---

 tools/proftool.c | 108 ++-
 1 file changed, 97 insertions(+), 11 deletions(-)

diff --git a/tools/proftool.c b/tools/proftool.c
index 844ff3d0d06..089360428c2 100644
--- a/tools/proftool.c
+++ b/tools/proftool.c
@@ -67,11 +67,16 @@ enum {
  * @OUT_FMT_DEFAULT: Use the default for the output file
  * @OUT_FMT_FUNCTION: Write ftrace 'function' records
  * @OUT_FMT_FUNCGRAPH: Write ftrace funcgraph_entry and funcgraph_exit records
+ * @OUT_FMT_FLAMEGRAPH_CALLS: Write a file suitable for flamegraph.pl
+ * @OUT_FMT_FLAMEGRAPH_TIMING: Write a file suitable for flamegraph.pl with the
+ * counts set to the number of microseconds used by each function
  */
 enum out_format_t {
OUT_FMT_DEFAULT,
OUT_FMT_FUNCTION,
OUT_FMT_FUNCGRAPH,
+   OUT_FMT_FLAMEGRAPH_CALLS,
+   OUT_FMT_FLAMEGRAPH_TIMING,
 };
 
 /* Section types for v7 format (trace-cmd format) */
@@ -127,6 +132,8 @@ enum trace_type {
  * @sibling: Next node in the list of children
  * @func: Function this node refers to (NULL for root node)
  * @count: Number of times this call-stack occurred
+ * @duration: Number of microseconds taken to run this function, excluding all
+ * of the functions it calls
  */
 struct flame_node {
struct flame_node *parent;
@@ -134,16 +141,27 @@ struct flame_node {
struct list_head sibling_node;
struct func_info *func;
int count;
+   ulong duration;
 };
 
 /**
  * struct flame_state - state information for building the flame graph
  *
  * @node: Current node being processed (corresponds to a function call)
+ * @stack: Stack of call-start time for this function as well as the
+ * accumulated total time of all child calls (so we can subtract them from the
+ * function's call time. This is an 'empty' stack, meaning that @stack_ptr
+ * points to the next available stack position
+ * @stack_ptr: points to first empty position in the stack
  * @nodes: Number of nodes created (running count)
  */
 struct flame_state {
struct flame_node *node;
+   struct stack_info {
+   ulong timestamp;
+   ulong child_total;
+   } stack[MAX_STACK_DEPTH];
+   int stack_ptr;
int nodes;
 };
 
@@ -279,7 +297,11 @@ static void usage(void)
"\n"
"Subtypes for dump-ftrace:\n"
"   function - write function-call records (caller/callee)\n"
-   "   funcgraph - write function entry/exit records (graph)\n");
+   "   funcgraph - write function entry/exit records (graph)\n"
+   "\n"
+   "Subtypes for dump-flamegraph\n"
+   "   calls - create a flamegraph of stack frames\n"
+   "   timing - create a flamegraph of microseconds for each stack 
frame\n");
exit(EXIT_FAILURE);
 }
 
@@ -1604,6 +1626,7 @@ static int process_call(struct flame_state *state, bool 
entry, ulong timestamp,
struct func_info *func)
 {
struct flame_node *node = state->node;
+   int stack_ptr = state->stack_ptr;
 
if (entry) {
struct flame_node *child, *chd;
@@ -1630,14 +1653,44 @@ static int process_call(struct flame_state *state, bool 
entry, ulong timestamp,
  node->func ? node->func->name : "(root)",
  child->func->name);
child->count++;
+   if (stack_ptr < MAX_STACK_DEPTH) {
+   state->stack[stack_ptr].timestamp = timestamp;
+   state->stack[stack_ptr].child_total = 0;
+   }
+   debug("%d: %20s: entry at %ld\n", stack_ptr, func->name,
+ timestamp);
+   stack_ptr++;
node = child;
} else if (node->parent) {
+   ulong total_duration = 0, child_duration = 0;
+   struct stack_info *stk;
+
debug("exit  %s: move from %s to %s\n", func->name,
  node->func->name, node->parent->func ?
  node->parent->func->name : "(root)");
+   if (stack_ptr && stack_ptr <= MAX_STACK_DEPTH) {
+   stk = &state->stack[--stack_ptr];
+
+   /*
+* get total duration of the function which just
+* exited
+*/
+   total_duration = timestamp - stk->timestamp;
+  

[PATCH 23/24] trace: Add a test

2023-01-15 Thread Simon Glass
Add a test which runs sandbox, collects a trace and makes sure it can
be processed by trace-cmd. This should ensure that this feature continues
to work as U-Boot and trace-cmd evolve.

Signed-off-by: Simon Glass 
---

 .azure-pipelines.yml|   8 +
 .gitlab-ci.yml  |  12 ++
 test/py/tests/test_trace.py | 304 
 3 files changed, 324 insertions(+)
 create mode 100644 test/py/tests/test_trace.py

diff --git a/.azure-pipelines.yml b/.azure-pipelines.yml
index 49fc34fbf23..8f5c8e05dc5 100644
--- a/.azure-pipelines.yml
+++ b/.azure-pipelines.yml
@@ -239,6 +239,11 @@ stages:
   TEST_PY_TEST_SPEC: "test_ofplatdata or test_handoff or test_spl"
 sandbox_flattree:
   TEST_PY_BD: "sandbox_flattree"
+sandbox_trace:
+  TEST_PY_BD: "sandbox"
+  BUILD_ENV: "FTRACE=1 NO_LTO=1"
+  TEST_PY_TEST_SPEC: "trace"
+  OVERRIDE: "-a CONFIG_TRACE=y -a CONFIG_TRACE_EARLY=y -a 
CONFIG_TRACE_EARLY_SIZE=0x0100"
 coreboot:
   TEST_PY_BD: "coreboot"
   TEST_PY_ID: "--id qemu"
@@ -361,6 +366,9 @@ stages:
   # the below corresponds to .gitlab-ci.yml "script"
   cd ${WORK_DIR}
   export UBOOT_TRAVIS_BUILD_DIR=/tmp/${TEST_PY_BD};
+  if [ -n "${BUILD_ENV}" ]; then
+  export ${BUILD_ENV};
+  fi
   tools/buildman/buildman -o ${UBOOT_TRAVIS_BUILD_DIR} -w -E -W -e 
--board ${TEST_PY_BD} ${OVERRIDE}
   cp ~/grub_x86.efi ${UBOOT_TRAVIS_BUILD_DIR}/
   cp ~/grub_x64.efi ${UBOOT_TRAVIS_BUILD_DIR}/
diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index 398fa2b45e2..87288a666df 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -35,6 +35,9 @@ stages:
 # If we've been asked to use clang only do one configuration.
 - export UBOOT_TRAVIS_BUILD_DIR=/tmp/${TEST_PY_BD}
 - echo BUILD_ENV ${BUILD_ENV}
+- if [ -n "${BUILD_ENV}" ]; then
+export ${BUILD_ENV};
+  fi
 - tools/buildman/buildman -o ${UBOOT_TRAVIS_BUILD_DIR} -w -E -W -e
 --board ${TEST_PY_BD} ${OVERRIDE}
 - cp ~/grub_x86.efi $UBOOT_TRAVIS_BUILD_DIR/
@@ -267,6 +270,15 @@ sandbox_vpl test.py:
 TEST_PY_TEST_SPEC: "test_vpl_help or test_spl"
   <<: *buildman_and_testpy_dfn
 
+# Enable tracing and disable LTO, to ensure functions are not elided
+sandbox trace_test.py:
+  variables:
+TEST_PY_BD: "sandbox"
+BUILD_ENV: "FTRACE=1 NO_LTO=1"
+TEST_PY_TEST_SPEC: "trace"
+OVERRIDE: "-a CONFIG_TRACE=y -a CONFIG_TRACE_EARLY=y -a 
CONFIG_TRACE_EARLY_SIZE=0x0100"
+  <<: *buildman_and_testpy_dfn
+
 evb-ast2500 test.py:
   variables:
 TEST_PY_BD: "evb-ast2500"
diff --git a/test/py/tests/test_trace.py b/test/py/tests/test_trace.py
new file mode 100644
index 000..14584d11a23
--- /dev/null
+++ b/test/py/tests/test_trace.py
@@ -0,0 +1,304 @@
+# SPDX-License-Identifier: GPL-2.0
+# Copyright 2022 Google LLC
+# Written by Simon Glass 
+
+import os
+import pytest
+import re
+
+import u_boot_utils as util
+
+# This is needed for Azure, since the default '..' directory is not writeable
+TMPDIR = '/tmp/test_trace'
+
+# Decode a function-graph line
+RE_LINE = re.compile(r'.*\[000\]\s*([0-9.]*): func.*[|](\s*)(\S.*)?([{};])$')
+
+
+def collect_trace(cons):
+"""Build U-Boot and run it to collect a trace
+
+Args:
+cons (ConsoleBase): U-Boot console
+
+Returns:
+tuple:
+str: Filename of the output trace file
+int: Microseconds taken for initf_dm according to bootstage
+"""
+cons.run_command('trace pause')
+out = cons.run_command('trace stats')
+
+# The output is something like this:
+#251,003 function sites
+#  1,160,283 function calls
+#  0 untracked function calls
+#  1,230,758 traced function calls (341538 dropped due to overflow)
+# 33 maximum observed call depth
+# 15 call depth limit
+#748,268 calls not traced due to depth
+#  1,230,758 max function calls
+
+# Get a dict of values from the output
+lines = [line.split(maxsplit=1) for line in out.splitlines() if line]
+vals = {key: val.replace(',', '') for val, key in lines}
+
+assert int(vals['function sites']) > 10
+assert int(vals['function calls']) > 20
+assert int(vals['untracked function calls']) == 0
+assert int(vals['maximum observed call depth']) > 30
+assert (vals['call depth limit'] ==
+cons.config.buildconfig.get('config_trace_call_depth_limit'))
+assert int(vals['calls not traced due to depth']) > 10
+
+out = cons.run_command('bootstage report')
+# Accumulated time:
+#   19,104  dm_r
+#   23,078  of_live
+#   46,280  dm_f
+dm_f_time = [line.split()[0] for line in out.replace(',', '').splitlines()
+ if 'dm_f' in line]
+
+# Read out the trace data
+addr = 0x0200
+size = 0x0100
+out = cons.run_command(f'trac

[PATCH 22/24] Docker: Support trace-cmd

2023-01-15 Thread Simon Glass
Build trace-cmd as part of the docker image, so that trace tests can be
used. Unfortunately the version provided by distributions is a little old
and has bugs. It also does not support specifying the time base for the
trace, which is required to convert microseconds to nanaseconds.

Signed-off-by: Simon Glass 
---

 tools/docker/Dockerfile | 16 
 1 file changed, 16 insertions(+)

diff --git a/tools/docker/Dockerfile b/tools/docker/Dockerfile
index 202a8145af7..6e0cdd48dd5 100644
--- a/tools/docker/Dockerfile
+++ b/tools/docker/Dockerfile
@@ -213,6 +213,22 @@ RUN git clone https://github.com/stefanberger/swtpm 
/tmp/swtpm && \
make install && \
rm -rf /tmp/swtpm
 
+# Build trace-cmd
+RUN mkdir /tmp/trace && \
+git clone https://git.kernel.org/pub/scm/libs/libtrace/libtraceevent.git 
/tmp/trace/libtraceevent && \
+cd /tmp/trace/libtraceevent && \
+make -j$(nproc) && \
+sudo make install && \
+git clone https://git.kernel.org/pub/scm/libs/libtrace/libtracefs.git 
/tmp/trace/libtracefs && \
+cd /tmp/trace/libtracefs && \
+make -j$(nproc) && \
+sudo make install && \
+git clone https://github.com/rostedt/trace-cmd.git /tmp/trace/trace-cmd && 
\
+cd /tmp/trace/trace-cmd && \
+make -j$(nproc) && \
+sudo make install && \
+rm -rf /tmp/trace
+
 # Create our user/group
 RUN echo uboot ALL=NOPASSWD: ALL > /etc/sudoers.d/uboot
 RUN useradd -m -U uboot
-- 
2.39.0.314.g84b9a713c41-goog



[PATCH 20/24] trace: Support output of a flamegraph

2023-01-15 Thread Simon Glass
It is useful to see how many times each function is called, particularly
in the context of its callers. A flamegraph is a way of showing this.

Support output in this format which can be used by the flamegraph.pl
script, to generate an SVG image for browsing.

Signed-off-by: Simon Glass 
---

 tools/proftool.c | 272 ++-
 1 file changed, 271 insertions(+), 1 deletion(-)

diff --git a/tools/proftool.c b/tools/proftool.c
index 588ae48a0c8..844ff3d0d06 100644
--- a/tools/proftool.c
+++ b/tools/proftool.c
@@ -6,7 +6,7 @@
 
 /*
  * Decode and dump U-Boot trace information into formats that can be used
- * by trace-cmd or kernelshark
+ * by trace-cmd, kernelshark or flamegraph.pl
  *
  * See doc/develop/trace.rst for more information
  */
@@ -27,6 +27,8 @@
 #include 
 #include 
 
+#include 
+
 /* Set to 1 to emit version 7 file (currently this doesn't work) */
 #define VERSION7   0
 
@@ -37,6 +39,18 @@
 #define __ALIGN_MASK(x, mask)  (((x) + (mask)) & ~(mask))
 #define ALIGN(x, a)__ALIGN_MASK((x), (typeof(x))(a) - 1)
 
+/**
+ * container_of - cast a member of a structure out to the containing structure
+ * @ptr:   the pointer to the member.
+ * @type:  the type of the container struct this is embedded in.
+ * @member:the name of the member within the struct.
+ *
+ * (this is needed by list.h)
+ */
+#define container_of(ptr, type, member) ({ \
+   const typeof( ((type *)0)->member ) *__mptr = (ptr);\
+   (type *)( (char *)__mptr - offsetof(type,member) );})
+
 enum {
FUNCF_TRACE = 1 << 0,   /* Include this function in trace */
TRACE_PAGE_SIZE = 4096, /* Assumed page size for trace */
@@ -101,6 +115,38 @@ enum trace_type {
TRACE_GRAPH_ENT,
 };
 
+/**
+ * struct flame_node - a node in the call-stack tree
+ *
+ * Each stack frame detected in the trace is given a node corresponding to a
+ * function call in the call stack. Functions can appear multiple times when
+ * they are called by a different set of parent functions.
+ *
+ * @parent: Parent node (the call stack for the function that called this one)
+ * @child_head: List of children of this node (functions called from here)
+ * @sibling: Next node in the list of children
+ * @func: Function this node refers to (NULL for root node)
+ * @count: Number of times this call-stack occurred
+ */
+struct flame_node {
+   struct flame_node *parent;
+   struct list_head child_head;
+   struct list_head sibling_node;
+   struct func_info *func;
+   int count;
+};
+
+/**
+ * struct flame_state - state information for building the flame graph
+ *
+ * @node: Current node being processed (corresponds to a function call)
+ * @nodes: Number of nodes created (running count)
+ */
+struct flame_state {
+   struct flame_node *node;
+   int nodes;
+};
+
 /**
  * struct func_info - information recorded for each function
  *
@@ -221,6 +267,7 @@ static void usage(void)
"\n"
"Commands\n"
"   dump-ftrace\t\tDump out records in ftrace format for use by 
trace-cmd\n"
+   "   dump-flamegraph\tWrite a file for use with flamegraph.pl\n"
"\n"
"Options:\n"
"   -c \tSpecify config file\n"
@@ -1517,6 +1564,218 @@ static int make_ftrace(FILE *fout, enum out_format_t 
out_format)
return 0;
 }
 
+/**
+ * create_node() - Create a new node in the flamegraph tree
+ *
+ * @msg: Message to use for debugging if something goes wrong
+ * Returns: Pointer to newly created node, or NULL on error
+ */
+static struct flame_node *create_node(const char *msg)
+{
+   struct flame_node *node;
+
+   node = calloc(1, sizeof(*node));
+   if (!node) {
+   fprintf(stderr, "Out of memory for %s\n", msg);
+   return NULL;
+   }
+   INIT_LIST_HEAD(&node->child_head);
+
+   return node;
+}
+
+/**
+ * process_call(): Add a call to the flamegraph info
+ *
+ * For function calls, if this call stack has been seen before, this increments
+ * the call count, creating a new node if needed.
+ *
+ * For function returns, it adds up the time spent in this call stack,
+ * subtracting the time spent by child functions.
+ *
+ * @state: Current flamegraph state
+ * @entry: true if this is a function entry, false if a function exit
+ * @timestamp: Timestamp from the trace file (in microseconds)
+ * @func: Function that was called/returned from
+ *
+ * Returns: 0 on success, -ve on error
+ */
+static int process_call(struct flame_state *state, bool entry, ulong timestamp,
+   struct func_info *func)
+{
+   struct flame_node *node = state->node;
+
+   if (entry) {
+   struct flame_node *child, *chd;
+
+   /* see if we have this as a child node already */
+   child = NULL;
+   list_for_each_entry(chd, &node->child_head, sibling_node) {
+   

[PATCH 17/24] trace: Drop use of objsection

2023-01-15 Thread Simon Glass
This feature was only partly implemented and serves no current purpose.
Drop it.

Signed-off-by: Simon Glass 
---

 tools/proftool.c | 29 +
 1 file changed, 1 insertion(+), 28 deletions(-)

diff --git a/tools/proftool.c b/tools/proftool.c
index feeef55c1b9..0d74e1169a9 100644
--- a/tools/proftool.c
+++ b/tools/proftool.c
@@ -95,14 +95,12 @@ enum trace_type {
  * @name: Function name
  * @code_size: Total code size of the function
  * @flags: Either 0 or FUNCF_TRACE
- * @objsection: the section this function is in
  */
 struct func_info {
unsigned long offset;
const char *name;
unsigned long code_size;
unsigned flags;
-   struct objsection_info *objsection;
 };
 
 /**
@@ -540,31 +538,6 @@ static void check_trace_config(void)
check_trace_config_line(line);
 }
 
-/**
- * Check the functions to see if they each have an objsection. If not, then
- * the linker must have eliminated them.
- */
-static void check_functions(void)
-{
-   struct func_info *func, *end;
-   unsigned long removed_code_size = 0;
-   int not_found = 0;
-
-   /* Look for missing functions */
-   for (func = func_list, end = func + func_count; func < end; func++) {
-   if (!func->objsection) {
-   removed_code_size += func->code_size;
-   not_found++;
-   }
-   }
-
-   /* Figure out what functions we want to trace */
-   check_trace_config();
-
-   warn("%d functions removed by linker, %ld code size\n",
-not_found, removed_code_size);
-}
-
 /**
  * read_trace_config() - read the trace-config file
  *
@@ -1460,7 +1433,7 @@ static int prof_tool(int argc, char *const argv[],
if (trace_config_fname && read_trace_config_file(trace_config_fname))
return -1;
 
-   check_functions();
+   check_trace_config();
 
for (; argc; argc--, argv++) {
const char *cmd = *argv;
-- 
2.39.0.314.g84b9a713c41-goog



[PATCH 18/24] trace: Use text_base from the trace header

2023-01-15 Thread Simon Glass
Use the information in the trace header instead of reading it from the
trace records. Add debugging to check that System.map and the trace header
agree on this value.

Signed-off-by: Simon Glass 
---

 tools/proftool.c | 7 ++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/tools/proftool.c b/tools/proftool.c
index 0d74e1169a9..b5b8a9f7938 100644
--- a/tools/proftool.c
+++ b/tools/proftool.c
@@ -179,6 +179,7 @@ struct trace_call *call_list;   /* list of all calls in 
the input trace file */
 int call_count;/* number of calls */
 int verbose;   /* Verbosity level 0=none, 1=warn, 2=notice, 3=info, 4=debug */
 ulong text_offset; /* text address of first function */
+ulong text_base;   /* CONFIG_TEXT_BASE from trace file */
 
 /* debugging helpers */
 static void outf(int level, const char *fmt, ...)
@@ -289,7 +290,8 @@ static int read_system_map(FILE *fin)
if (func_count > 1)
func[-1].code_size = func->offset - func[-1].offset;
}
-   notice("%d functions found in map file\n", func_count);
+   notice("%d functions found in map file, start addr %lx\n", func_count,
+  start);
text_offset = start;
 
return 0;
@@ -415,6 +417,7 @@ static int read_trace(FILE *fin)
break; /* EOF */
else if (err)
return 1;
+   text_base = hdr.text_base;
 
switch (hdr.type) {
case TRACE_CHUNK_FUNCS:
@@ -1342,6 +1345,8 @@ static int write_flyrecord(struct twriter *tw, int 
*missing_countp,
tw->ptr += tputq(fout, len);
tw->ptr += tputs(fout, str);
 
+   debug("trace text base %lx, map file %lx\n", text_base, text_offset);
+
ret = write_pages(tw, missing_countp, skip_countp);
if (ret < 0) {
fprintf(stderr, "Cannot output pages\n");
-- 
2.39.0.314.g84b9a713c41-goog



[PATCH 16/24] trace: Update proftool to use new binary format

2023-01-15 Thread Simon Glass
The old text format is not much used anymore. Instead a new trace-cmd tool
has introduced a binary format for trace records.

Add support for generating this format. This involves removing the old
text format, adding various helpers for the new format and adjusting the
code to use an output file instead of stdout.

Signed-off-by: Simon Glass 
---

 tools/Makefile   |   3 +
 tools/proftool.c | 896 ---
 2 files changed, 854 insertions(+), 45 deletions(-)

diff --git a/tools/Makefile b/tools/Makefile
index edfa40903d9..269bedd206e 100644
--- a/tools/Makefile
+++ b/tools/Makefile
@@ -225,7 +225,10 @@ HOSTCFLAGS_ubsha1.o := -pedantic
 
 hostprogs-$(CONFIG_ARCH_KIRKWOOD) += kwboot
 hostprogs-$(CONFIG_ARCH_MVEBU) += kwboot
+
 hostprogs-y += proftool
+proftool-objs = proftool.o lib/abuf.o
+
 hostprogs-$(CONFIG_STATIC_RELA) += relocate-rela
 hostprogs-$(CONFIG_RISCV) += prelink-riscv
 
diff --git a/tools/proftool.c b/tools/proftool.c
index 6aa157c8b59..feeef55c1b9 100644
--- a/tools/proftool.c
+++ b/tools/proftool.c
@@ -1,9 +1,15 @@
 // SPDX-License-Identifier: GPL-2.0+
 /*
- * Copyright (c) 2013 Google, Inc
+ * Copyright 2023 Google LLC
+ * Written by Simon Glass 
  */
 
-/* Decode and dump U-Boot profiling information */
+/*
+ * Decode and dump U-Boot trace information into formats that can be used
+ * by trace-cmd or kernelshark
+ *
+ * See doc/develop/trace.rst for more information
+ */
 
 #include 
 #include 
@@ -19,11 +25,67 @@
 
 #include 
 #include 
+#include 
+
+/* Set to 1 to emit version 7 file (currently this doesn't work) */
+#define VERSION7   0
 
-#define MAX_LINE_LEN 500
+/* enable some debug features */
+#define _DEBUG 0
+
+/* from linux/kernel.h */
+#define __ALIGN_MASK(x, mask)  (((x) + (mask)) & ~(mask))
+#define ALIGN(x, a)__ALIGN_MASK((x), (typeof(x))(a) - 1)
 
 enum {
FUNCF_TRACE = 1 << 0,   /* Include this function in trace */
+   TRACE_PAGE_SIZE = 4096, /* Assumed page size for trace */
+   TRACE_PID   = 1,/* PID to use for U-Boot */
+   LEN_STACK_SIZE  = 4,/* number of nested length fix-ups */
+   TRACE_PAGE_MASK = TRACE_PAGE_SIZE - 1,
+   MAX_STACK_DEPTH = 50,   /* Max nested function calls */
+   MAX_LINE_LEN= 500,  /* Max characters per line */
+};
+
+/* Section types for v7 format (trace-cmd format) */
+enum {
+   SECTION_OPTIONS,
+};
+
+/* Option types (trace-cmd format) */
+enum {
+   OPTION_DONE,
+   OPTION_DATE,
+   OPTION_CPUSTAT,
+   OPTION_BUFFER,
+   OPTION_TRACECLOCK,
+   OPTION_UNAME,
+   OPTION_HOOK,
+   OPTION_OFFSET,
+   OPTION_CPUCOUNT,
+   OPTION_VERSION,
+   OPTION_PROCMAPS,
+   OPTION_TRACEID,
+   OPTION_TIME_SHIFT,
+   OPTION_GUEST,
+   OPTION_TSC2NSEC,
+};
+
+/* types of trace records (trace-cmd format) */
+enum trace_type {
+   __TRACE_FIRST_TYPE = 0,
+
+   TRACE_FN,
+   TRACE_CTX,
+   TRACE_WAKE,
+   TRACE_STACK,
+   TRACE_PRINT,
+   TRACE_BPRINT,
+   TRACE_MMIO_RW,
+   TRACE_MMIO_MAP,
+   TRACE_BRANCH,
+   TRACE_GRAPH_RET,
+   TRACE_GRAPH_ENT,
 };
 
 /**
@@ -69,6 +131,45 @@ struct trace_configline_info {
regex_t regex;
 };
 
+/**
+ * struct tw_len - holds information about a length value that need fix-ups
+ *
+ * This is used to record a placeholder for a u32 or u64 length which is 
written
+ * to the output file but needs to be updated once the length is actually known
+ *
+ * This allows us to write tw->ptr - @len_base to position @ptr in the file
+ *
+ * @ptr: Position of the length value in the file
+ * @base: Base position for the calculation
+ * @size: Size of the length value, in bytes (4 or 8)
+ */
+struct tw_len {
+   int ptr;
+   int base;
+   int size;
+};
+
+/**
+ * struct twriter - Writer for trace records
+ *
+ * Maintains state used when writing the output file in trace-cmd format
+ *
+ * @ptr: Current file position
+ * @len_stack: Stack of length values that need fixing up
+ * @len: Number of items on @len_stack
+ * @str_buf: Buffer of strings (for v7 format)
+ * @str_ptr: Current write-position in the buffer for strings
+ * @fout: Output file
+ */
+struct twriter {
+   int ptr;
+   struct tw_len len_stack[LEN_STACK_SIZE];
+   int len_count;
+   struct abuf str_buf;
+   int str_ptr;
+   FILE *fout;
+};
+
 /* The contents of the trace config file */
 struct trace_configline_info *trace_config_head;
 
@@ -569,56 +670,577 @@ static int read_trace_config_file(const char *fname)
return err;
 }
 
-static void out_func(ulong func_offset, int is_caller, const char *suffix)
+/**
+ * tputh() - Write a 16-bit little-endian value to a file
+ *
+ * @fout: File to write to
+ * @val: Value to write
+ * Returns: number of bytes written (2)
+ */
+static int tputh(FILE *fout, unsigned int val)
 {
-   struct func_info *func;
+   fputc(val, fout)

[PATCH 19/24] trace: Support output of funcgraph records

2023-01-15 Thread Simon Glass
Add support for writing ftrace records in the 'funcgraph' format, which
shows function entry and exit points as well as the time taken by each
function.

Signed-off-by: Simon Glass 
---

 tools/proftool.c | 182 ++-
 1 file changed, 150 insertions(+), 32 deletions(-)

diff --git a/tools/proftool.c b/tools/proftool.c
index b5b8a9f7938..588ae48a0c8 100644
--- a/tools/proftool.c
+++ b/tools/proftool.c
@@ -47,6 +47,19 @@ enum {
MAX_LINE_LEN= 500,  /* Max characters per line */
 };
 
+/**
+ * enum out_format_t - supported output formats
+ *
+ * @OUT_FMT_DEFAULT: Use the default for the output file
+ * @OUT_FMT_FUNCTION: Write ftrace 'function' records
+ * @OUT_FMT_FUNCGRAPH: Write ftrace funcgraph_entry and funcgraph_exit records
+ */
+enum out_format_t {
+   OUT_FMT_DEFAULT,
+   OUT_FMT_FUNCTION,
+   OUT_FMT_FUNCGRAPH,
+};
+
 /* Section types for v7 format (trace-cmd format) */
 enum {
SECTION_OPTIONS,
@@ -211,10 +224,15 @@ static void usage(void)
"\n"
"Options:\n"
"   -c \tSpecify config file\n"
+   "   -f \tSpecify output subtype\n"
"   -m \tSpecify Systen.map file\n"
"   -o \tSpecify output file\n"
"   -t \tSpecify trace data file (from U-Boot 'trace 
calls')\n"
-   "   -v <0-4>\tSpecify verbosity\n");
+   "   -v <0-4>\tSpecify verbosity\n"
+   "\n"
+   "Subtypes for dump-ftrace:\n"
+   "   function - write function-call records (caller/callee)\n"
+   "   funcgraph - write function entry/exit records (graph)\n");
exit(EXIT_FAILURE);
 }
 
@@ -1165,6 +1183,43 @@ static int write_options(struct twriter *tw)
return 0;
 }
 
+/**
+ * calc_min_depth() - Calculate the minimum call depth from the call list
+ *
+ * Starting with a depth of 0, this works through the call list, adding 1 for
+ * each function call and subtracting 1 for each function return. Most likely
+ * the value ends up being negative, since the trace does not start at the
+ * very top of the call stack, e.g. main(), but some function called by that.
+ *
+ * This value can be used to calculate the depth value for the first call,
+ * such that it never goes negative for subsequent returns.
+ *
+ * Returns: minimum call depth (e.g. -2)
+ */
+static int calc_min_depth(void)
+{
+   struct trace_call *call;
+   int depth, min_depth, i;
+
+   /* Calculate minimum depth */
+   depth = 0;
+   min_depth = 0;
+   for (i = 0, call = call_list; i < call_count; i++, call++) {
+   switch (TRACE_CALL_TYPE(call)) {
+   case FUNCF_ENTRY:
+   depth++;
+   break;
+   case FUNCF_EXIT:
+   depth--;
+   if (depth < min_depth)
+   min_depth = depth;
+   break;
+   }
+   }
+
+   return min_depth;
+}
+
 /**
  * write_pages() - Write the pages of trace data
  *
@@ -1172,17 +1227,19 @@ static int write_options(struct twriter *tw)
  * needed.
  *
  * @tw: Writer context
+ * @out_format: Output format to use
  * @missing_countp: Returns number of missing functions (not found in function
  * list)
  * @skip_countp: Returns number of skipped functions (excluded from trace)
  *
  * Returns: 0 on success, -ve on error
  */
-static int write_pages(struct twriter *tw, int *missing_countp,
-  int *skip_countp)
+static int write_pages(struct twriter *tw, enum out_format_t out_format,
+  int *missing_countp, int *skip_countp)
 {
+   ulong func_stack[MAX_STACK_DEPTH];
int stack_ptr;  /* next free position in stack */
-   int upto, page_upto, i;
+   int upto, depth, page_upto, i;
int missing_count = 0, skip_count = 0;
struct trace_call *call;
ulong last_timestamp;
@@ -1200,8 +1257,13 @@ static int write_pages(struct twriter *tw, int 
*missing_countp,
/* maintain a stack of start times for calling functions */
stack_ptr = 0;
 
+   /*
+* The first thing in the trace may not be the top-level function, so
+* set the initial depth so that no function goes below depth 0
+*/
+   depth = -calc_min_depth();
for (i = 0, call = call_list; i < call_count; i++, call++) {
-   struct func_info *caller_func;
+   bool entry = TRACE_CALL_TYPE(call) == FUNCF_ENTRY;
struct func_info *func;
ulong timestamp;
uint rec_words;
@@ -1227,7 +1289,10 @@ static int write_pages(struct twriter *tw, int 
*missing_countp,
continue;
}
 
-   rec_words = 6;
+   if (out_format == OUT_FMT_FUNCTION)
+   rec_words = 6;
+   else /* 2 header words and

[PATCH 15/24] trace: Rename prof to trace and improve comments

2023-01-15 Thread Simon Glass
The current use of 'profile' in some places is confusing. Update the code
to use the word 'trace' consistently. Change the flags to better match
their meaning and add some more comments.

Signed-off-by: Simon Glass 
---

 tools/proftool.c | 196 +--
 1 file changed, 157 insertions(+), 39 deletions(-)

diff --git a/tools/proftool.c b/tools/proftool.c
index b66ea556486..6aa157c8b59 100644
--- a/tools/proftool.c
+++ b/tools/proftool.c
@@ -26,38 +26,62 @@ enum {
FUNCF_TRACE = 1 << 0,   /* Include this function in trace */
 };
 
+/**
+ * struct func_info - information recorded for each function
+ *
+ * @offset: Function offset in the image, measured from the text_base
+ * @name: Function name
+ * @code_size: Total code size of the function
+ * @flags: Either 0 or FUNCF_TRACE
+ * @objsection: the section this function is in
+ */
 struct func_info {
unsigned long offset;
const char *name;
unsigned long code_size;
-   unsigned long call_count;
unsigned flags;
-   /* the section this function is in */
struct objsection_info *objsection;
 };
 
+/**
+ * enum trace_line_type - whether to include or exclude a function
+ *
+ * @TRACE_LINE_INCLUDE: Include the function
+ * @TRACE_LINE_EXCLUDE: Exclude the function
+ */
 enum trace_line_type {
TRACE_LINE_INCLUDE,
TRACE_LINE_EXCLUDE,
 };
 
+/**
+ * struct trace_configline_info - information about a config-file line
+ *
+ * @next: Next line
+ * @type: Line type
+ * @name: identifier name / wildcard
+ * @regex: Regex to use if name starts with '/'
+ */
 struct trace_configline_info {
struct trace_configline_info *next;
enum trace_line_type type;
-   const char *name;   /* identifier name / wildcard */
-   regex_t regex;  /* Regex to use if name starts with / */
+   const char *name;
+   regex_t regex;
 };
 
 /* The contents of the trace config file */
 struct trace_configline_info *trace_config_head;
 
+/* list of all functions in System.map file, sorted by offset in the image */
 struct func_info *func_list;
-int func_count;
-struct trace_call *call_list;
-int call_count;
+
+int func_count;/* number of functions */
+struct trace_call *call_list;  /* list of all calls in the input trace file */
+int call_count;/* number of calls */
 int verbose;   /* Verbosity level 0=none, 1=warn, 2=notice, 3=info, 4=debug */
-unsigned long text_offset; /* text address of first function */
+ulong text_offset; /* text address of first function */
 
+/* debugging helpers */
 static void outf(int level, const char *fmt, ...)
__attribute__ ((format (__printf__, 2, 3)));
 #define error(fmt, b...) outf(0, fmt, ##b)
@@ -66,7 +90,6 @@ static void outf(int level, const char *fmt, ...)
 #define info(fmt, b...) outf(3, fmt, ##b)
 #define debug(fmt, b...) outf(4, fmt, ##b)
 
-
 static void outf(int level, const char *fmt, ...)
 {
if (verbose >= level) {
@@ -84,16 +107,24 @@ static void usage(void)
"Usage: proftool [-cmtv]  \n"
"\n"
"Commands\n"
-   "   dump-ftrace\t\tDump out textual data in ftrace format\n"
+   "   dump-ftrace\t\tDump out records in ftrace format for use by 
trace-cmd\n"
"\n"
"Options:\n"
-   "   -c \tSpecific config file\n"
+   "   -c \tSpecify config file\n"
"   -m \tSpecify Systen.map file\n"
+   "   -o \tSpecify output file\n"
"   -t \tSpecify trace data file (from U-Boot 'trace 
calls')\n"
"   -v <0-4>\tSpecify verbosity\n");
exit(EXIT_FAILURE);
 }
 
+/**
+ * h_cmp_offset - bsearch() function to compare two functions bny their offset
+ *
+ * @v1: Pointer to first function (struct func_info)
+ * @v2: Pointer to second function (struct func_info)
+ * Returns: < 0 if v1 offset < v2 offset, 0 if equal, > 0 otherwise
+ */
 static int h_cmp_offset(const void *v1, const void *v2)
 {
const struct func_info *f1 = v1, *f2 = v2;
@@ -101,6 +132,15 @@ static int h_cmp_offset(const void *v1, const void *v2)
return (f1->offset / FUNC_SITE_SIZE) - (f2->offset / FUNC_SITE_SIZE);
 }
 
+/**
+ * read_system_map() - read the System.map file to create a list of functions
+ *
+ * This also reads the text_offset value, since we assume that the first text
+ * symbol is at that address
+ *
+ * @fin: File to read
+ * Returns: 0 if OK, non-zero on error
+ */
 static int read_system_map(FILE *fin)
 {
unsigned long offset, start = 0;
@@ -152,6 +192,7 @@ static int read_system_map(FILE *fin)
}
notice("%d functions found in map file\n", func_count);
text_offset = start;
+
return 0;
 }
 
@@ -163,13 +204,22 @@ static int read_data(FILE *fin, void *buff, int size)
if (!err)
return 1;
 

[PATCH 14/24] trace: Detect an infinite loop

2023-01-15 Thread Simon Glass
If something is wrong with a board's timer function such that it calls
functions not marked with notrace, U-Boot will hang.

Detect this, print a message and disable the trace.

Signed-off-by: Simon Glass 
---

 lib/trace.c | 10 ++
 1 file changed, 10 insertions(+)

diff --git a/lib/trace.c b/lib/trace.c
index bbc316af295..1091a5793a1 100644
--- a/lib/trace.c
+++ b/lib/trace.c
@@ -39,6 +39,7 @@ struct trace_hdr {
int depth_limit;/* Depth limit to trace to */
int max_depth;  /* Maximum depth seen so far */
int min_depth;  /* Minimum depth seen so far */
+   bool trace_locked;  /* Used to detect recursive tracing */
 };
 
 /* Pointer to start of trace buffer */
@@ -133,6 +134,14 @@ void notrace __cyg_profile_func_enter(void *func_ptr, void 
*caller)
if (trace_enabled) {
int func;
 
+   if (hdr->trace_locked) {
+   trace_enabled = 0;
+   puts("trace: recursion detected, disabling\n");
+   hdr->trace_locked = false;
+   return;
+   }
+
+   hdr->trace_locked = true;
trace_swap_gd();
add_ftrace(func_ptr, caller, FUNCF_ENTRY);
func = func_ptr_to_num(func_ptr);
@@ -146,6 +155,7 @@ void notrace __cyg_profile_func_enter(void *func_ptr, void 
*caller)
if (hdr->depth > hdr->max_depth)
hdr->max_depth = hdr->depth;
trace_swap_gd();
+   hdr->trace_locked = false;
}
 }
 
-- 
2.39.0.314.g84b9a713c41-goog



[PATCH 13/24] trace: Correct the relocation handover with buffer overflow

2023-01-15 Thread Simon Glass
When the early trace buffer overflows it leaves a gap in the trace buffer
between where the actual data finished and where it would have finished if
there were enough buffer space. This results in corrupted output.

Adjust the logic to resolve this and add a message when the buffer
overflows.

Signed-off-by: Simon Glass 
---

 lib/trace.c | 13 ++---
 1 file changed, 10 insertions(+), 3 deletions(-)

diff --git a/lib/trace.c b/lib/trace.c
index c3354a256fb..bbc316af295 100644
--- a/lib/trace.c
+++ b/lib/trace.c
@@ -360,8 +360,8 @@ int notrace trace_init(void *buff, size_t buff_size)
 
if (!was_disabled) {
 #ifdef CONFIG_TRACE_EARLY
+   ulong used, count;
char *end;
-   ulong used;
 
/*
 * Copy over the early trace data if we have it. Disable
@@ -370,12 +370,19 @@ int notrace trace_init(void *buff, size_t buff_size)
trace_enabled = 0;
hdr = map_sysmem(CONFIG_TRACE_EARLY_ADDR,
 CONFIG_TRACE_EARLY_SIZE);
-   end = (char *)&hdr->ftrace[min(hdr->ftrace_count,
-  hdr->ftrace_size)];
+   count = min(hdr->ftrace_count, hdr->ftrace_size);
+   end = (char *)&hdr->ftrace[count];
used = end - (char *)hdr;
printf("trace: copying %08lx bytes of early data from %x to 
%08lx\n",
   used, CONFIG_TRACE_EARLY_ADDR,
   (ulong)map_to_sysmem(buff));
+   printf("%lu traced function calls", count);
+   if (hdr->ftrace_count > hdr->ftrace_size) {
+   printf(" (%lu dropped due to overflow)",
+  hdr->ftrace_count - hdr->ftrace_size);
+   hdr->ftrace_count = hdr->ftrace_size;
+   }
+   puts("\n");
memcpy(buff, hdr, used);
 #else
puts("trace: already enabled\n");
-- 
2.39.0.314.g84b9a713c41-goog



[PATCH 12/24] trace: Show a few more stats about tracing

2023-01-15 Thread Simon Glass
Add a few more useful items into the output. Update the buffers to use hex
consistently.

Signed-off-by: Simon Glass 
---

 lib/trace.c | 8 ++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/lib/trace.c b/lib/trace.c
index 3551ef3a23c..c3354a256fb 100644
--- a/lib/trace.c
+++ b/lib/trace.c
@@ -319,6 +319,10 @@ void trace_print_stats(void)
printf("%15d call depth limit\n", hdr->depth_limit);
print_grouped_ull(hdr->ftrace_too_deep_count, 10);
puts(" calls not traced due to depth\n");
+   print_grouped_ull(hdr->ftrace_size, 10);
+   puts(" max function calls\n");
+   printf("\ntrace buffer %lx call records %lx\n",
+  (ulong)map_to_sysmem(hdr), (ulong)map_to_sysmem(hdr->ftrace));
 }
 
 void notrace trace_set_enabled(int enabled)
@@ -381,7 +385,7 @@ int notrace trace_init(void *buff, size_t buff_size)
hdr = (struct trace_hdr *)buff;
needed = sizeof(*hdr) + func_count * sizeof(uintptr_t);
if (needed > buff_size) {
-   printf("trace: buffer size %zd bytes: at least %zd needed\n",
+   printf("trace: buffer size %zx bytes: at least %zx needed\n",
   buff_size, needed);
return -ENOSPC;
}
@@ -426,7 +430,7 @@ int notrace trace_early_init(void)
hdr = map_sysmem(CONFIG_TRACE_EARLY_ADDR, CONFIG_TRACE_EARLY_SIZE);
needed = sizeof(*hdr) + func_count * sizeof(uintptr_t);
if (needed > buff_size) {
-   printf("trace: buffer size is %zd bytes, at least %zd needed\n",
+   printf("trace: buffer size is %zx bytes, at least %zx needed\n",
   buff_size, needed);
return -ENOSPC;
}
-- 
2.39.0.314.g84b9a713c41-goog



[PATCH 10/24] trace: Reduce the number of function sites

2023-01-15 Thread Simon Glass
Given that the compiler adds two function calls into each function, the
current spacing is overkill. Drop it down to 16 bytes per function, which
is still plenty. This saves some space in the trace buffer.

Also move the calculation into a function, so it is common code. Add a
check for gd->mon_len being unset, which breaks tracing.

Signed-off-by: Simon Glass 
---

 include/trace.h |  6 --
 lib/trace.c | 19 +--
 2 files changed, 21 insertions(+), 4 deletions(-)

diff --git a/include/trace.h b/include/trace.h
index 2be8d81b515..763d6d1255a 100644
--- a/include/trace.h
+++ b/include/trace.h
@@ -17,14 +17,16 @@ enum {
 *
 * The value here assumes a minimum instruction size of 4 bytes,
 * or that instructions are 2 bytes but there are at least 2 of
-* them in every function.
+* them in every function. Given that each function needs a call to
+* __cyg_profile_func_enter() and __cyg_profile_func_exit() as well,
+* we cannot have functions smaller that 16 bytes.
 *
 * Increasing this value reduces the number of functions we can
 * resolve, but reduces the size of the uintptr_t array used for
 * our function list, which is the length of the code divided by
 * this value.
 */
-   FUNC_SITE_SIZE  = 4,/* distance between function sites */
+   FUNC_SITE_SIZE  = 16,   /* distance between function sites */
 
TRACE_VERSION   = 1,
 };
diff --git a/lib/trace.c b/lib/trace.c
index 2e2c1bed54f..12dae2089a4 100644
--- a/lib/trace.c
+++ b/lib/trace.c
@@ -321,6 +321,17 @@ void notrace trace_set_enabled(int enabled)
trace_enabled = enabled != 0;
 }
 
+static int get_func_count(void)
+{
+   /* Detect no support for mon_len since this means tracing cannot work */
+   if (IS_ENABLED(CONFIG_SANDBOX) && !gd->mon_len) {
+   puts("Tracing is not supported on this board\n");
+   return -ENOTSUPP;
+   }
+
+   return gd->mon_len / FUNC_SITE_SIZE;
+}
+
 /**
  * trace_init() - initialize the tracing system and enable it
  *
@@ -330,10 +341,12 @@ void notrace trace_set_enabled(int enabled)
  */
 int notrace trace_init(void *buff, size_t buff_size)
 {
-   ulong func_count = gd->mon_len / FUNC_SITE_SIZE;
+   int func_count = get_func_count();
size_t needed;
int was_disabled = !trace_enabled;
 
+   if (func_count < 0)
+   return func_count;
trace_save_gd();
 
if (!was_disabled) {
@@ -393,10 +406,12 @@ int notrace trace_init(void *buff, size_t buff_size)
  */
 int notrace trace_early_init(void)
 {
-   ulong func_count = gd->mon_len / FUNC_SITE_SIZE;
+   int func_count = get_func_count();
size_t buff_size = CONFIG_TRACE_EARLY_SIZE;
size_t needed;
 
+   if (func_count < 0)
+   return func_count;
/* We can ignore additional calls to this function */
if (trace_enabled)
return 0;
-- 
2.39.0.314.g84b9a713c41-goog



[PATCH 11/24] trace: Track the minimum stack depth

2023-01-15 Thread Simon Glass
The trace does not necessarily start at the top level, so we can see it
go negative. Track this so that we can show an accurate value for the
stack depth.

Signed-off-by: Simon Glass 
---

 lib/trace.c | 24 
 1 file changed, 16 insertions(+), 8 deletions(-)

diff --git a/lib/trace.c b/lib/trace.c
index 12dae2089a4..3551ef3a23c 100644
--- a/lib/trace.c
+++ b/lib/trace.c
@@ -35,9 +35,10 @@ struct trace_hdr {
ulong ftrace_count; /* Num. of ftrace records written */
ulong ftrace_too_deep_count;/* Functions that were too deep */
 
-   int depth;
-   int depth_limit;
-   int max_depth;
+   int depth;  /* Depth of function calls */
+   int depth_limit;/* Depth limit to trace to */
+   int max_depth;  /* Maximum depth seen so far */
+   int min_depth;  /* Minimum depth seen so far */
 };
 
 /* Pointer to start of trace buffer */
@@ -142,7 +143,7 @@ void notrace __cyg_profile_func_enter(void *func_ptr, void 
*caller)
hdr->untracked_count++;
}
hdr->depth++;
-   if (hdr->depth > hdr->depth_limit)
+   if (hdr->depth > hdr->max_depth)
hdr->max_depth = hdr->depth;
trace_swap_gd();
}
@@ -158,8 +159,10 @@ void notrace __cyg_profile_func_exit(void *func_ptr, void 
*caller)
 {
if (trace_enabled) {
trace_swap_gd();
-   add_ftrace(func_ptr, caller, FUNCF_EXIT);
hdr->depth--;
+   add_ftrace(func_ptr, caller, FUNCF_EXIT);
+   if (hdr->depth < hdr->min_depth)
+   hdr->min_depth = hdr->depth;
trace_swap_gd();
}
 }
@@ -309,8 +312,10 @@ void trace_print_stats(void)
printf(" (%lu dropped due to overflow)",
   hdr->ftrace_count - hdr->ftrace_size);
}
-   puts("\n");
-   printf("%15d maximum observed call depth\n", hdr->max_depth);
+
+   /* Add in minimum depth since the trace did not start at top level */
+   printf("\n%15d maximum observed call depth\n",
+  hdr->max_depth - hdr->min_depth);
printf("%15d call depth limit\n", hdr->depth_limit);
print_grouped_ull(hdr->ftrace_too_deep_count, 10);
puts(" calls not traced due to depth\n");
@@ -381,8 +386,10 @@ int notrace trace_init(void *buff, size_t buff_size)
return -ENOSPC;
}
 
-   if (was_disabled)
+   if (was_disabled) {
memset(hdr, '\0', needed);
+   hdr->min_depth = INT_MAX;
+   }
hdr->func_count = func_count;
hdr->call_accum = (uintptr_t *)(hdr + 1);
 
@@ -427,6 +434,7 @@ int notrace trace_early_init(void)
memset(hdr, '\0', needed);
hdr->call_accum = (uintptr_t *)(hdr + 1);
hdr->func_count = func_count;
+   hdr->min_depth = INT_MAX;
 
/* Use any remaining space for the timed function trace */
hdr->ftrace = (struct trace_call *)((char *)hdr + needed);
-- 
2.39.0.314.g84b9a713c41-goog



[PATCH 09/24] trace: Update the file header

2023-01-15 Thread Simon Glass
It seems better to put the TEXT_BASE value in the file header rather than
in an entry record. While it is true that there is a separate base for
pre-relocation, this can be handled by using offsets in the file.

It is useful to have a version number in case we need to change the trace
format again.

Update the header to make these changes.

Signed-off-by: Simon Glass 
---

 include/trace.h | 12 ++--
 lib/trace.c | 19 ---
 2 files changed, 14 insertions(+), 17 deletions(-)

diff --git a/include/trace.h b/include/trace.h
index e7aee024f03..2be8d81b515 100644
--- a/include/trace.h
+++ b/include/trace.h
@@ -6,6 +6,8 @@
 #ifndef __TRACE_H
 #define __TRACE_H
 
+/* this file is included from a tool so uses uint32_t instead of u32, etc. */
+
 enum {
/*
 * This affects the granularity of our trace. We can bin function
@@ -23,6 +25,8 @@ enum {
 * this value.
 */
FUNC_SITE_SIZE  = 4,/* distance between function sites */
+
+   TRACE_VERSION   = 1,
 };
 
 enum trace_chunk_type {
@@ -39,7 +43,11 @@ struct trace_output_func {
 /* A header at the start of the trace output buffer */
 struct trace_output_hdr {
enum trace_chunk_type type; /* Record type */
-   size_t rec_count;   /* Number of records */
+   uint32_t version;   /* Version (TRACE_VERSION) */
+   uint32_t rec_count; /* Number of records */
+   uint32_t spare; /* 0 */
+   uint64_t text_base; /* Value of CONFIG_TEXT_BASE */
+   uint64_t spare2;/* 0 */
 };
 
 /* Print statistics about traced function calls */
@@ -63,7 +71,7 @@ int trace_list_functions(void *buff, size_t buff_size, size_t 
*needed);
 enum ftrace_flags {
FUNCF_EXIT  = 0UL << 30,
FUNCF_ENTRY = 1UL << 30,
-   FUNCF_TEXTBASE  = 2UL << 30,
+   /* two more values are available */
 
FUNCF_TIMESTAMP_MASK= 0x3fff,
 };
diff --git a/lib/trace.c b/lib/trace.c
index b9dc6d2e4b5..2e2c1bed54f 100644
--- a/lib/trace.c
+++ b/lib/trace.c
@@ -118,18 +118,6 @@ static void notrace add_ftrace(void *func_ptr, void 
*caller, ulong flags)
hdr->ftrace_count++;
 }
 
-static void notrace add_textbase(void)
-{
-   if (hdr->ftrace_count < hdr->ftrace_size) {
-   struct trace_call *rec = &hdr->ftrace[hdr->ftrace_count];
-
-   rec->func = CONFIG_TEXT_BASE;
-   rec->caller = 0;
-   rec->flags = FUNCF_TEXTBASE;
-   }
-   hdr->ftrace_count++;
-}
-
 /**
  * __cyg_profile_func_enter() - record function entry
  *
@@ -278,8 +266,11 @@ int trace_list_calls(void *buff, size_t buff_size, size_t 
*needed)
 
/* Update the header */
if (output_hdr) {
+   memset(output_hdr, '\0', sizeof(*output_hdr));
output_hdr->rec_count = upto;
output_hdr->type = TRACE_CHUNK_CALLS;
+   output_hdr->version = TRACE_VERSION;
+   output_hdr->text_base = CONFIG_TEXT_BASE;
}
 
/* Work out how must of the buffer we used */
@@ -385,10 +376,9 @@ int notrace trace_init(void *buff, size_t buff_size)
/* Use any remaining space for the timed function trace */
hdr->ftrace = (struct trace_call *)(buff + needed);
hdr->ftrace_size = (buff_size - needed) / sizeof(*hdr->ftrace);
-   add_textbase();
+   hdr->depth_limit = CONFIG_TRACE_CALL_DEPTH_LIMIT;
 
puts("trace: enabled\n");
-   hdr->depth_limit = CONFIG_TRACE_CALL_DEPTH_LIMIT;
trace_enabled = 1;
trace_inited = 1;
 
@@ -426,7 +416,6 @@ int notrace trace_early_init(void)
/* Use any remaining space for the timed function trace */
hdr->ftrace = (struct trace_call *)((char *)hdr + needed);
hdr->ftrace_size = (buff_size - needed) / sizeof(*hdr->ftrace);
-   add_textbase();
hdr->depth_limit = CONFIG_TRACE_EARLY_CALL_DEPTH_LIMIT;
printf("trace: early enable at %08x\n", CONFIG_TRACE_EARLY_ADDR);
 
-- 
2.39.0.314.g84b9a713c41-goog



[PATCH 06/24] time: Tidy up some unnecessary #ifdefs

2023-01-15 Thread Simon Glass
Avoid using the preprocessor with TIMER_EARLY.

Signed-off-by: Simon Glass 
---

 lib/time.c | 14 ++
 1 file changed, 6 insertions(+), 8 deletions(-)

diff --git a/lib/time.c b/lib/time.c
index 0c95d12f614..1ef58f92cd1 100644
--- a/lib/time.c
+++ b/lib/time.c
@@ -70,15 +70,14 @@ extern unsigned long timer_read_counter(void);
 ulong notrace get_tbclk(void)
 {
if (!gd->timer) {
-#ifdef CONFIG_TIMER_EARLY
-   return timer_early_get_rate();
-#else
int ret;
 
+   if (IS_ENABLED(CONFIG_TIMER_EARLY))
+   return timer_early_get_rate();
+
ret = dm_timer_init();
if (ret)
return ret;
-#endif
}
 
return timer_get_rate(gd->timer);
@@ -90,15 +89,14 @@ uint64_t notrace get_ticks(void)
int ret;
 
if (!gd->timer) {
-#ifdef CONFIG_TIMER_EARLY
-   return timer_early_get_count();
-#else
int ret;
 
+   if (IS_ENABLED(CONFIG_TIMER_EARLY))
+   return timer_early_get_count();
+
ret = dm_timer_init();
if (ret)
panic("Could not initialize timer (err %d)\n", ret);
-#endif
}
 
ret = timer_get_count(gd->timer, &count);
-- 
2.39.0.314.g84b9a713c41-goog



[PATCH 08/24] abuf: Support use from tools

2023-01-15 Thread Simon Glass
Update the code slightly so that abuf can be used in U-Boot tools. It will
soon be needed for proftool.

Signed-off-by: Simon Glass 
---

 lib/abuf.c | 21 -
 1 file changed, 20 insertions(+), 1 deletion(-)

diff --git a/lib/abuf.c b/lib/abuf.c
index 1635d58682c..bd270467dd4 100644
--- a/lib/abuf.c
+++ b/lib/abuf.c
@@ -6,11 +6,14 @@
  * Written by Simon Glass 
  */
 
+#ifndef USE_HOSTCC
 #include 
-#include 
 #include 
 #include 
 #include 
+#endif
+
+#include 
 
 void abuf_set(struct abuf *abuf, void *data, size_t size)
 {
@@ -19,10 +22,26 @@ void abuf_set(struct abuf *abuf, void *data, size_t size)
abuf->size = size;
 }
 
+#ifndef USE_HOSTCC
 void abuf_map_sysmem(struct abuf *abuf, ulong addr, size_t size)
 {
abuf_set(abuf, map_sysmem(addr, size), size);
 }
+#else
+/* copied from lib/string.c for convenience */
+static char *memdup(const void *src, size_t len)
+{
+   char *p;
+
+   p = malloc(len);
+   if (!p)
+   return NULL;
+
+   memcpy(p, src, len);
+
+   return p;
+}
+#endif
 
 bool abuf_realloc(struct abuf *abuf, size_t new_size)
 {
-- 
2.39.0.314.g84b9a713c41-goog



[PATCH 07/24] trace: Reduce the default for TRACE_EARLY_CALL_DEPTH_LIMIT

2023-01-15 Thread Simon Glass
This is a silly value at present, since U-Boot's call depth never reaches
200. Fix it.

Signed-off-by: Simon Glass 
---

 lib/Kconfig | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lib/Kconfig b/lib/Kconfig
index a83f32d82a5..11968a0c531 100644
--- a/lib/Kconfig
+++ b/lib/Kconfig
@@ -368,7 +368,7 @@ config TRACE_EARLY_SIZE
 config TRACE_EARLY_CALL_DEPTH_LIMIT
int "Early trace call depth limit"
depends on TRACE_EARLY
-   default 200
+   default 15
help
  Sets the maximum call depth up to which function calls are recorded
  during early tracing.
-- 
2.39.0.314.g84b9a713c41-goog



[PATCH 04/24] dm: Allow serial output during the relocation process

2023-01-15 Thread Simon Glass
Reset the serial flags so that the debug UART can be used (if enabled)
in the small window where there is no serial device. This can avoid a hang
in some cases.

Signed-off-by: Simon Glass 
---

 common/board_r.c | 9 +
 1 file changed, 9 insertions(+)

diff --git a/common/board_r.c b/common/board_r.c
index 3618acad437..5f3c3db476d 100644
--- a/common/board_r.c
+++ b/common/board_r.c
@@ -796,6 +796,15 @@ static init_fnc_t init_sequence_r[] = {
 
 void board_init_r(gd_t *new_gd, ulong dest_addr)
 {
+   /*
+* The pre-relocation drivers may be using memory that has now gone
+* away. Mark serial as unavailable - this will fall back to the debug
+* UART if available.
+*
+* Do the same with log drivers since the memory may not be available.
+*/
+   gd->flags &= ~(GD_FLG_SERIAL_READY | GD_FLG_LOG_READY);
+
/*
 * Set up the new global data pointer. So far only x86 does this
 * here.
-- 
2.39.0.314.g84b9a713c41-goog



[PATCH 03/24] sandbox: Bring back setting mon_len in global_data

2023-01-15 Thread Simon Glass
This change was made for the benefit of RISC-V but broke other
architectures also. In particular, tracing cannot work without this value.
Add it back for architectures which support it.

Fixes: 3c9fc23c443 ("sandbox: don't refer to symbol _init")
Signed-off-by: Simon Glass 
---

 common/board_f.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/common/board_f.c b/common/board_f.c
index 2b4edf30c93..f3c1ab53b1c 100644
--- a/common/board_f.c
+++ b/common/board_f.c
@@ -290,7 +290,10 @@ static int setup_mon_len(void)
 {
 #if defined(__ARM__) || defined(__MICROBLAZE__)
gd->mon_len = (ulong)&__bss_end - (ulong)_start;
+#elif defined(CONFIG_SANDBOX) && !defined(__riscv)
+   gd->mon_len = (ulong)&_end - (ulong)_init;
 #elif defined(CONFIG_SANDBOX)
+   /* gcc does not provide _init in crti.o on RISC-V */
gd->mon_len = 0;
 #elif defined(CONFIG_EFI_APP)
gd->mon_len = (ulong)&_end - (ulong)_init;
-- 
2.39.0.314.g84b9a713c41-goog



[PATCH 05/24] timer: Tidy up use of notrace

2023-01-15 Thread Simon Glass
Tracing is typically enabled by the time driver model starts up, so there
is no point in adding a 'notrace' to the timer-init function. However,
once the driver model timer is enabled, we do need to be able to access
the timer's private data when reading the timer, so add it to the core
function needed for that.

Update the function's documentation while we are here.

Signed-off-by: Simon Glass 
---

 drivers/core/device.c|  3 ++-
 drivers/timer/timer-uclass.c |  2 +-
 include/timer.h  | 13 +
 3 files changed, 12 insertions(+), 6 deletions(-)

diff --git a/drivers/core/device.c b/drivers/core/device.c
index d9ce546c0c4..6e26b64fb81 100644
--- a/drivers/core/device.c
+++ b/drivers/core/device.c
@@ -654,7 +654,8 @@ void *dev_get_priv(const struct udevice *dev)
return dm_priv_to_rw(dev->priv_);
 }
 
-void *dev_get_uclass_priv(const struct udevice *dev)
+/* notrace is needed as this is called by timer_get_rate() */
+notrace void *dev_get_uclass_priv(const struct udevice *dev)
 {
if (!dev) {
dm_warn("%s: null device\n", __func__);
diff --git a/drivers/timer/timer-uclass.c b/drivers/timer/timer-uclass.c
index bb719792135..f4b871ac23a 100644
--- a/drivers/timer/timer-uclass.c
+++ b/drivers/timer/timer-uclass.c
@@ -136,7 +136,7 @@ u64 timer_conv_64(u32 count)
return ((u64)gd->timebase_h << 32) | gd->timebase_l;
 }
 
-int notrace dm_timer_init(void)
+int dm_timer_init(void)
 {
struct udevice *dev = NULL;
__maybe_unused ofnode node;
diff --git a/include/timer.h b/include/timer.h
index d33a26e28fe..311ce6b2c3a 100644
--- a/include/timer.h
+++ b/include/timer.h
@@ -9,11 +9,16 @@
 #define timer_get_ops(dev) ((struct timer_ops *)(dev)->driver->ops)
 
 /**
- * dm_timer_init() - initialize a timer for time keeping. On success
- * initializes gd->timer so that lib/timer can use it for future
- * referrence.
+ * dm_timer_init() - set up a timer for time keeping
  *
- * Return: 0 on success or error number
+ * Sets up gd->timer if the device is not already bound, making sure it is
+ * probed and ready for use
+ *
+ * On success, inits gd->timer so that lib/timer can use it for future 
reference
+ *
+ * Returns: 0 on success, -EAGAIN if driver model is not ready yet, -ENODEV if
+ * no timer could be found, other error if the timer could not be bound or
+ * probed
  */
 int dm_timer_init(void);
 
-- 
2.39.0.314.g84b9a713c41-goog



[PATCH 02/24] sandbox: Expand the space for sandbox_vpl

2023-01-15 Thread Simon Glass
This is quite near the limit so add a little more space.

Signed-off-by: Simon Glass 
---

 arch/sandbox/dts/sandbox_vpl.dtsi | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/arch/sandbox/dts/sandbox_vpl.dtsi 
b/arch/sandbox/dts/sandbox_vpl.dtsi
index 1fba537f135..6966eeff7b3 100644
--- a/arch/sandbox/dts/sandbox_vpl.dtsi
+++ b/arch/sandbox/dts/sandbox_vpl.dtsi
@@ -17,8 +17,8 @@
 * provide plenty of space for ELF files with debug info so that
 * gdb can be used
 */
-   offset = <0x40>;
-   size = <0xdffc00>;
+   offset = <0x50>;
+   size = <0xcffc00>;
 
fit {
fit,external-offset = <0>;
-- 
2.39.0.314.g84b9a713c41-goog



[PATCH 01/24] .gitignore: Ignore the moveconfig database

2023-01-15 Thread Simon Glass
This file is produced by the moveconfig.py tool. It should never be added
to the repo, so add it to the .gitignore file.

Signed-off-by: Simon Glass 
---

 .gitignore | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/.gitignore b/.gitignore
index eb769f144c3..357bcfe9917 100644
--- a/.gitignore
+++ b/.gitignore
@@ -104,3 +104,6 @@ __pycache__
 # pylint files
 /pylint.cur
 /pylint.out/
+
+# moveconfig database
+/moveconfig.db
-- 
2.39.0.314.g84b9a713c41-goog



[PATCH 00/24] trace: Update the trace feature to work with trace-cmd

2023-01-15 Thread Simon Glass
Since U-Boot's tracing feature was originally written, quite a few changes
have taken place in this domain. The original text format used by tracing
is still emitted by Linux, but a new trace-cmd tool has invented a binary
format which is now used by new tools, such as kernelshark.

With recent distributions and the move to Python 3, the old pybootchart
tool does not build or run. Unfortunately there is no 1:1 replacement for
the features that were provided by pybootchart, or at least it is not
obvious. Still, it makes sense to keep with the times.

This series updates proftool to use the new binary format, adding support
for function and funcgraph tracing, so that U-Boot's trace records can be
examined by trace-cmd and kernelshark.

This series also adds support for a flamegraph, which provides a visual
way to see which functions are called a lot, as well as which ones consume
the most time.

Some minor updates to the trace implementation within U-Boot are included,
to provide a little more information and to fix a few problems.

No unit tests are provided by proftool, but a functional test ensures that
sandbox can emit traces which can be processed by proftool, then parsed by
trace-cmd and that the timing of the various formats looks consistent.


Simon Glass (24):
  .gitignore: Ignore the moveconfig database
  sandbox: Expand the space for sandbox_vpl
  sandbox: Bring back setting mon_len in global_data
  dm: Allow serial output during the relocation process
  timer: Tidy up use of notrace
  time: Tidy up some unnecessary #ifdefs
  trace: Reduce the default for TRACE_EARLY_CALL_DEPTH_LIMIT
  abuf: Support use from tools
  trace: Update the file header
  trace: Reduce the number of function sites
  trace: Track the minimum stack depth
  trace: Show a few more stats about tracing
  trace: Correct the relocation handover with buffer overflow
  trace: Detect an infinite loop
  trace: Rename prof to trace and improve comments
  trace: Update proftool to use new binary format
  trace: Drop use of objsection
  trace: Use text_base from the trace header
  trace: Support output of funcgraph records
  trace: Support output of a flamegraph
  trace: Provide a flamegraph that uses timing
  Docker: Support trace-cmd
  trace: Add a test
  trace: Update documentation

 .azure-pipelines.yml   |8 +
 .gitattributes |1 +
 .gitignore |3 +
 .gitlab-ci.yml |   12 +
 arch/sandbox/dts/sandbox_vpl.dtsi  |4 +-
 common/board_f.c   |3 +
 common/board_r.c   |9 +
 doc/develop/pics/flamegraph.png|  Bin 0 -> 48224 bytes
 doc/develop/pics/flamegraph_timing.png |  Bin 0 -> 31305 bytes
 doc/develop/pics/flamegraph_zoom.png   |  Bin 0 -> 25465 bytes
 doc/develop/pics/kernelshark.png   |  Bin 0 -> 29617 bytes
 doc/develop/pics/kernelshark_fg.png|  Bin 0 -> 28899 bytes
 doc/develop/trace.rst  |  281 -
 doc/usage/cmd/trace.rst|  163 +++
 doc/usage/index.rst|1 +
 drivers/core/device.c  |3 +-
 drivers/timer/timer-uclass.c   |2 +-
 include/timer.h|   13 +-
 include/trace.h|   18 +-
 lib/Kconfig|2 +-
 lib/abuf.c |   21 +-
 lib/time.c |   14 +-
 lib/trace.c|   93 +-
 test/py/tests/test_trace.py|  304 +
 tools/Makefile |3 +
 tools/docker/Dockerfile|   16 +
 tools/proftool.c   | 1598 ++--
 27 files changed, 2345 insertions(+), 227 deletions(-)
 create mode 100644 doc/develop/pics/flamegraph.png
 create mode 100644 doc/develop/pics/flamegraph_timing.png
 create mode 100644 doc/develop/pics/flamegraph_zoom.png
 create mode 100644 doc/develop/pics/kernelshark.png
 create mode 100644 doc/develop/pics/kernelshark_fg.png
 create mode 100644 doc/usage/cmd/trace.rst
 create mode 100644 test/py/tests/test_trace.py

-- 
2.39.0.314.g84b9a713c41-goog



Re: [PATCH v2] vbe: Allow probing the VBE bootmeth to fail in OS fixup

2023-01-15 Thread Karsten Merker
On Thu, Jan 12, 2023 at 04:48:54PM -0700 Simon Glass wrote:

> This device is created when there are no bootmeths defined in the device
> tree. But it cannot be probed without a device tree node.
> 
> For now, ignore a probe failure.
> 
> Signed-off-by: Simon Glass 
> Reported-by: Karsten Merker 
> Suggested-by: Heinrich Schuchardt 
> Fixes: a56f663f0707 ("vbe: Add info about the VBE device to the fwupd node")

Tested-by: Karsten Merker 

Hello,

applying this patch fixes the boot failure on the riscv64
qemu virt platform:

U-Boot 2023.01-1-g5c392f7ced (Jan 15 2023 - 21:34:26 +0100)

CPU:   rv64imafdch_zicsr_zifencei_zihintpause_zba_zbb_zbc_zbs_sstc
Model: riscv-virtio,qemu
DRAM:  8 GiB
Core:  31 devices, 15 uclasses, devicetree: board
Flash: 32 MiB
Loading Environment from nowhere... OK
In:serial@1000
Out:   serial@1000
Err:   serial@1000
Net:   eth0: virtio-net#2
Working FDT set to ff7344b0
Hit any key to stop autoboot:  0 

Device 0: QEMU VirtIO Block Device
Type: Hard Disk
Capacity: 102400.0 MB = 100.0 GB (209715200 x 512)
... is now current device
Scanning virtio 0:1...
Found /boot/extlinux/extlinux.conf
Retrieving file: /boot/extlinux/extlinux.conf
U-Boot menu
1:  Debian GNU/Linux bookworm/sid 6.1.0-1-riscv64
2:  Debian GNU/Linux bookworm/sid 6.1.0-1-riscv64 (rescue target)
3:  Debian GNU/Linux bookworm/sid 6.0.0-6-riscv64
4:  Debian GNU/Linux bookworm/sid 6.0.0-6-riscv64 (rescue target)
5:  Debian GNU/Linux bookworm/sid 6.0.0-5-riscv64
6:  Debian GNU/Linux bookworm/sid 6.0.0-5-riscv64 (rescue target)
Enter choice: 1:Debian GNU/Linux bookworm/sid 6.1.0-1-riscv64
Retrieving file: /boot/initrd.img-6.1.0-1-riscv64
Retrieving file: /boot/vmlinux-6.1.0-1-riscv64
append: root=/dev/vda1 rw noquiet
Moving Image from 0x8400 to 0x8020, end=815e5000
## Flattened Device Tree blob at ff7344b0
   Booting using the fdt blob at 0xff7344b0
Working FDT set to ff7344b0
   Using Device Tree in place at ff7344b0, end ff738dea
Working FDT set to ff7344b0

Starting kernel ...

[0.00] Linux version 6.1.0-1-riscv64 (debian-ker...@lists.debian.org) 
(gcc-12 (Debian 12.2.0-11) 12.2.0, GNU ld (GNU Binutils for Debian) 
2.39.90.20221231) #1 SMP Debian 6.1.4-1 (2023-01-07)
[0.00] random: crng init done
[0.00] OF: fdt: Ignoring memory range 0x8000 - 0x8020
[0.00] Machine model: riscv-virtio,qemu
[...]

Regards and many thanks,
Karsten
-- 
Hiermit widerspreche ich ausdrücklich der Nutzung sowie der Weitergabe
meiner personenbezogenen Daten für Zwecke der Werbung sowie der Markt-
oder Meinungsforschung.


Re: [PULL] u-boot-sh/master

2023-01-15 Thread Tom Rini
On Sun, Jan 15, 2023 at 03:27:04PM +0100, Marek Vasut wrote:

> The following changes since commit fe4c21de4fbf5756d354d2473ffc675e7596ccfb:
> 
>   Merge tag 'u-boot-stm32-20230113' of
> https://source.denx.de/u-boot/custodians/u-boot-stm (2023-01-13 09:56:19
> -0500)
> 
> are available in the Git repository at:
> 
>   git://source.denx.de/u-boot-sh.git master
> 
> for you to fetch changes up to 4327df1d345e502f48a1a23b091ae39110481026:
> 
>   configs: r8a77980: Condor: Enable MMC support by default (2023-01-14
> 14:10:12 +0100)
> 

Applied to u-boot/master, thanks!

-- 
Tom


signature.asc
Description: PGP signature


Re: [PULL] u-boot-usb/master

2023-01-15 Thread Tom Rini
On Sun, Jan 15, 2023 at 03:27:02PM +0100, Marek Vasut wrote:

> The following changes since commit fe4c21de4fbf5756d354d2473ffc675e7596ccfb:
> 
>   Merge tag 'u-boot-stm32-20230113' of
> https://source.denx.de/u-boot/custodians/u-boot-stm (2023-01-13 09:56:19
> -0500)
> 
> are available in the Git repository at:
> 
>   git://source.denx.de/u-boot-usb.git master
> 
> for you to fetch changes up to 2383e8f4aec7a5087526d501478c4ba8235da2b4:
> 
>   usb: gadget: dwc2_udc_otg: implement pullup() (2023-01-14 14:10:30 +0100)
> 

Applied to u-boot/master, thanks!

-- 
Tom


signature.asc
Description: PGP signature


[PATCH 14/14] mtd: rawnand: brcmnand: fix OOB R/W with Hamming ECC

2023-01-15 Thread Linus Walleij
From: Álvaro Fernández Rojas 

Hamming ECC doesn't cover the OOB data, so reading or writing OOB shall
always be done without ECC enabled.
This is a problem when adding JFFS2 cleanmarkers to erased blocks. If JFFS2
clenmarkers are added to the OOB with ECC enabled, OOB bytes will be changed
from ff ff ff to 00 00 00, reporting incorrect ECC errors.

Fixes: 27c5b17cd1b1 ("mtd: nand: add NAND driver "library" for Broadcom STB 
NAND controller")
Signed-off-by: Álvaro Fernández Rojas 
Acked-by: Brian Norris 
Signed-off-by: Miquel Raynal 
Link: https://lore.kernel.org/linux-mtd/20210224080210.23686-1-nolt...@gmail.com
[Ported to U-Boot from the Linux kernel]
Signed-off-by: Linus Walleij 
---
 drivers/mtd/nand/raw/brcmnand/brcmnand.c | 6 ++
 1 file changed, 6 insertions(+)

diff --git a/drivers/mtd/nand/raw/brcmnand/brcmnand.c 
b/drivers/mtd/nand/raw/brcmnand/brcmnand.c
index 2cca897ab3c9..ee3ff372b863 100644
--- a/drivers/mtd/nand/raw/brcmnand/brcmnand.c
+++ b/drivers/mtd/nand/raw/brcmnand/brcmnand.c
@@ -2567,6 +2567,12 @@ static int brcmnand_init_cs(struct brcmnand_host *host, 
ofnode dn)
ret = nand_register(0, mtd);
 #endif /* __UBOOT__ */
 
+   /* If OOB is written with ECC enabled it will cause ECC errors */
+   if (is_hamming_ecc(host->ctrl, &host->hwcfg)) {
+   chip->ecc.write_oob = brcmnand_write_oob_raw;
+   chip->ecc.read_oob = brcmnand_read_oob_raw;
+   }
+
return ret;
 }
 
-- 
2.39.0



[PATCH 13/14] mtd: rawnand: brcmnand: support v2.1-v2.2 controllers

2023-01-15 Thread Linus Walleij
From: Álvaro Fernández Rojas 

v2.1: tested on Netgear DGND3700v1 (BCM6368)
v2.2: tested on Netgear DGND3700v2 (BCM6362)

Signed-off-by: Álvaro Fernández Rojas 
Acked-by: Florian Fainelli 
Signed-off-by: Miquel Raynal 
Link: 
https://lore.kernel.org/linux-mtd/20200522121524.4161539-6-nolt...@gmail.com
[Ported to U-Boot from the Linux kernel]
Signed-off-by: Linus Walleij 
---
 drivers/mtd/nand/raw/brcmnand/brcmnand.c | 85 +---
 1 file changed, 76 insertions(+), 9 deletions(-)

diff --git a/drivers/mtd/nand/raw/brcmnand/brcmnand.c 
b/drivers/mtd/nand/raw/brcmnand/brcmnand.c
index 934981e2f3fe..2cca897ab3c9 100644
--- a/drivers/mtd/nand/raw/brcmnand/brcmnand.c
+++ b/drivers/mtd/nand/raw/brcmnand/brcmnand.c
@@ -217,6 +217,7 @@ struct brcmnand_controller {
const unsigned int  *block_sizes;
unsigned intmax_page_size;
const unsigned int  *page_sizes;
+   unsigned intpage_size_shift;
unsigned intmax_oob;
u32 features;
 
@@ -293,6 +294,36 @@ enum brcmnand_reg {
BRCMNAND_FC_BASE,
 };
 
+/* BRCMNAND v2.1-v2.2 */
+static const u16 brcmnand_regs_v21[] = {
+   [BRCMNAND_CMD_START]=  0x04,
+   [BRCMNAND_CMD_EXT_ADDRESS]  =  0x08,
+   [BRCMNAND_CMD_ADDRESS]  =  0x0c,
+   [BRCMNAND_INTFC_STATUS] =  0x5c,
+   [BRCMNAND_CS_SELECT]=  0x14,
+   [BRCMNAND_CS_XOR]   =  0x18,
+   [BRCMNAND_LL_OP]= 0,
+   [BRCMNAND_CS0_BASE] =  0x40,
+   [BRCMNAND_CS1_BASE] = 0,
+   [BRCMNAND_CORR_THRESHOLD]   = 0,
+   [BRCMNAND_CORR_THRESHOLD_EXT]   = 0,
+   [BRCMNAND_UNCORR_COUNT] = 0,
+   [BRCMNAND_CORR_COUNT]   = 0,
+   [BRCMNAND_CORR_EXT_ADDR]=  0x60,
+   [BRCMNAND_CORR_ADDR]=  0x64,
+   [BRCMNAND_UNCORR_EXT_ADDR]  =  0x68,
+   [BRCMNAND_UNCORR_ADDR]  =  0x6c,
+   [BRCMNAND_SEMAPHORE]=  0x50,
+   [BRCMNAND_ID]   =  0x54,
+   [BRCMNAND_ID_EXT]   = 0,
+   [BRCMNAND_LL_RDATA] = 0,
+   [BRCMNAND_OOB_READ_BASE]=  0x20,
+   [BRCMNAND_OOB_READ_10_BASE] = 0,
+   [BRCMNAND_OOB_WRITE_BASE]   =  0x30,
+   [BRCMNAND_OOB_WRITE_10_BASE]= 0,
+   [BRCMNAND_FC_BASE]  = 0x200,
+};
+
 /* BRCMNAND v3.3-v4.0 */
 static const u16 brcmnand_regs_v33[] = {
[BRCMNAND_CMD_START]=  0x04,
@@ -491,6 +522,9 @@ enum {
CFG_BUS_WIDTH   = BIT(CFG_BUS_WIDTH_SHIFT),
CFG_DEVICE_SIZE_SHIFT   = 24,
 
+   /* Only for v2.1 */
+   CFG_PAGE_SIZE_SHIFT_v2_1= 30,
+
/* Only for pre-v7.1 (with no CFG_EXT register) */
CFG_PAGE_SIZE_SHIFT = 20,
CFG_BLK_SIZE_SHIFT  = 28,
@@ -526,12 +560,16 @@ static int brcmnand_revision_init(struct 
brcmnand_controller *ctrl)
 {
static const unsigned int block_sizes_v6[] = { 8, 16, 128, 256, 512, 
1024, 2048, 0 };
static const unsigned int block_sizes_v4[] = { 16, 128, 8, 512, 256, 
1024, 2048, 0 };
+   static const unsigned int block_sizes_v2_2[] = { 16, 128, 8, 512, 256, 
0 };
+   static const unsigned int block_sizes_v2_1[] = { 16, 128, 8, 512, 0 };
static const unsigned int page_sizes_v3_4[] = { 512, 2048, 4096, 8192, 
0 };
+   static const unsigned int page_sizes_v2_2[] = { 512, 2048, 4096, 0 };
+   static const unsigned int page_sizes_v2_1[] = { 512, 2048, 0 };
 
ctrl->nand_version = nand_readreg(ctrl, 0) & 0x;
 
-   /* Only support v4.0+? */
-   if (ctrl->nand_version < 0x0400) {
+   /* Only support v2.1+ */
+   if (ctrl->nand_version < 0x0201) {
dev_err(ctrl->dev, "version %#x not supported\n",
ctrl->nand_version);
return -ENODEV;
@@ -548,6 +586,8 @@ static int brcmnand_revision_init(struct 
brcmnand_controller *ctrl)
ctrl->reg_offsets = brcmnand_regs_v50;
else if (ctrl->nand_version >= 0x0303)
ctrl->reg_offsets = brcmnand_regs_v33;
+   else if (ctrl->nand_version >= 0x0201)
+   ctrl->reg_offsets = brcmnand_regs_v21;
 
/* Chip-select stride */
if (ctrl->nand_version >= 0x0701)
@@ -573,14 +613,32 @@ static int brcmnand_revision_init(struct 
brcmnand_controller *ctrl)
ctrl->max_page_size = 16 * 1024;
ctrl->max_block_size = 2 * 1024 * 1024;
} else {
-   ctrl->page_sizes = page_sizes_v3_4;
+   if (ctrl->nand_version >= 0x0304)
+   ctrl->page_sizes = page_sizes_v3_4;
+   else if (ctrl->nand_version >= 0x0202)
+   ctrl->page_sizes = page_sizes_v2_2;
+   else
+   ctrl->page_sizes = page_sizes_v2_

[PATCH 12/14] mtd: rawnand: brcmnand: rename page sizes

2023-01-15 Thread Linus Walleij
From: Álvaro Fernández Rojas 

Current pages sizes apply to controllers after v3.4

Signed-off-by: Álvaro Fernández Rojas 
Acked-by: Florian Fainelli 
Signed-off-by: Miquel Raynal 
Link: 
https://lore.kernel.org/linux-mtd/20200522121524.4161539-4-nolt...@gmail.com
[Ported to U-Boot from the Linux kernel]
Signed-off-by: Linus Walleij 
---
 drivers/mtd/nand/raw/brcmnand/brcmnand.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/mtd/nand/raw/brcmnand/brcmnand.c 
b/drivers/mtd/nand/raw/brcmnand/brcmnand.c
index c02d34ffbc95..934981e2f3fe 100644
--- a/drivers/mtd/nand/raw/brcmnand/brcmnand.c
+++ b/drivers/mtd/nand/raw/brcmnand/brcmnand.c
@@ -526,7 +526,7 @@ static int brcmnand_revision_init(struct 
brcmnand_controller *ctrl)
 {
static const unsigned int block_sizes_v6[] = { 8, 16, 128, 256, 512, 
1024, 2048, 0 };
static const unsigned int block_sizes_v4[] = { 16, 128, 8, 512, 256, 
1024, 2048, 0 };
-   static const unsigned int page_sizes[] = { 512, 2048, 4096, 8192, 0 };
+   static const unsigned int page_sizes_v3_4[] = { 512, 2048, 4096, 8192, 
0 };
 
ctrl->nand_version = nand_readreg(ctrl, 0) & 0x;
 
@@ -573,7 +573,7 @@ static int brcmnand_revision_init(struct 
brcmnand_controller *ctrl)
ctrl->max_page_size = 16 * 1024;
ctrl->max_block_size = 2 * 1024 * 1024;
} else {
-   ctrl->page_sizes = page_sizes;
+   ctrl->page_sizes = page_sizes_v3_4;
if (ctrl->nand_version >= 0x0600)
ctrl->block_sizes = block_sizes_v6;
else
-- 
2.39.0



[PATCH 11/14] mtd: rawnand: brcmnand: fix CS0 layout

2023-01-15 Thread Linus Walleij
From: Álvaro Fernández Rojas 

Only v3.3-v5.0 have a different CS0 layout.
Controllers before v3.3 use the same layout for every CS.

Fixes: 27c5b17cd1b1 ("mtd: nand: add NAND driver "library" for Broadcom STB 
NAND controller")
Signed-off-by: Álvaro Fernández Rojas 
Acked-by: Florian Fainelli 
Signed-off-by: Miquel Raynal 
Link: 
https://lore.kernel.org/linux-mtd/20200522121524.4161539-3-nolt...@gmail.com
[Ported to U-Boot from the Linux kernel]
Signed-off-by: Linus Walleij 
---
 drivers/mtd/nand/raw/brcmnand/brcmnand.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/drivers/mtd/nand/raw/brcmnand/brcmnand.c 
b/drivers/mtd/nand/raw/brcmnand/brcmnand.c
index effc7f1ea802..c02d34ffbc95 100644
--- a/drivers/mtd/nand/raw/brcmnand/brcmnand.c
+++ b/drivers/mtd/nand/raw/brcmnand/brcmnand.c
@@ -561,8 +561,9 @@ static int brcmnand_revision_init(struct 
brcmnand_controller *ctrl)
} else {
ctrl->cs_offsets = brcmnand_cs_offsets;
 
-   /* v5.0 and earlier has a different CS0 offset layout */
-   if (ctrl->nand_version <= 0x0500)
+   /* v3.3-5.0 have a different CS0 offset layout */
+   if (ctrl->nand_version >= 0x0303 &&
+   ctrl->nand_version <= 0x0500)
ctrl->cs0_offsets = brcmnand_cs_offsets_cs0;
}
 
-- 
2.39.0



[PATCH 09/14] mtd: rawnand: brcmnand: correctly verify erased pages

2023-01-15 Thread Linus Walleij
From: Álvaro Fernández Rojas 

The current code checks that the whole OOB area is erased.
This is a problem when JFFS2 cleanmarkers are added to the OOB, since it will
fail due to the usable OOB bytes not being 0xff.
Correct this by only checking that data and ECC bytes aren't 0xff.

Fixes: 02b88eea9f9c ("mtd: brcmnand: Add check for erased page bitflips")
Signed-off-by: Álvaro Fernández Rojas 
Signed-off-by: Miquel Raynal 
Link: 
https://lore.kernel.org/linux-mtd/20200512082451.771212-1-nolt...@gmail.com
[Ported to U-Boot from the Linux kernel]
Signed-off-by: Linus Walleij 
---
 drivers/mtd/nand/raw/brcmnand/brcmnand.c | 19 +++
 1 file changed, 11 insertions(+), 8 deletions(-)

diff --git a/drivers/mtd/nand/raw/brcmnand/brcmnand.c 
b/drivers/mtd/nand/raw/brcmnand/brcmnand.c
index d082801b8306..b87e3e0656df 100644
--- a/drivers/mtd/nand/raw/brcmnand/brcmnand.c
+++ b/drivers/mtd/nand/raw/brcmnand/brcmnand.c
@@ -1829,11 +1829,12 @@ static int brcmnand_read_by_pio(struct mtd_info *mtd, 
struct nand_chip *chip,
 static int brcmstb_nand_verify_erased_page(struct mtd_info *mtd,
  struct nand_chip *chip, void *buf, u64 addr)
 {
-   int i, sas;
-   void *oob = chip->oob_poi;
+   struct mtd_oob_region ecc;
+   int i;
int bitflips = 0;
int page = addr >> chip->page_shift;
int ret;
+   void *ecc_bytes;
void *ecc_chunk;
 
if (!buf) {
@@ -1846,18 +1847,20 @@ static int brcmstb_nand_verify_erased_page(struct 
mtd_info *mtd,
chip->pagebuf = -1;
}
 
-   sas = mtd->oobsize / chip->ecc.steps;
-
/* read without ecc for verification */
ret = chip->ecc.read_page_raw(mtd, chip, buf, true, page);
if (ret)
return ret;
 
-   for (i = 0; i < chip->ecc.steps; i++, oob += sas) {
+   for (i = 0; i < chip->ecc.steps; i++) {
ecc_chunk = buf + chip->ecc.size * i;
-   ret = nand_check_erased_ecc_chunk(ecc_chunk,
- chip->ecc.size,
- oob, sas, NULL, 0,
+
+   mtd_ooblayout_ecc(mtd, i, &ecc);
+   ecc_bytes = chip->oob_poi + ecc.offset;
+
+   ret = nand_check_erased_ecc_chunk(ecc_chunk, chip->ecc.size,
+ ecc_bytes, ecc.length,
+ NULL, 0,
  chip->ecc.strength);
if (ret < 0)
return ret;
-- 
2.39.0



[PATCH 10/14] mtd: rawnand: brcmnand: rename v4 registers

2023-01-15 Thread Linus Walleij
From: Álvaro Fernández Rojas 

These registers are also used on v3.3.

Signed-off-by: Álvaro Fernández Rojas 
Reviewed-by: Miquel Raynal 
Acked-by: Florian Fainelli 
Signed-off-by: Miquel Raynal 
Link: 
https://lore.kernel.org/linux-mtd/20200522121524.4161539-2-nolt...@gmail.com
[Ported to U-Boot from the Linux kernel]
Signed-off-by: Linus Walleij 
---
 drivers/mtd/nand/raw/brcmnand/brcmnand.c | 8 
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/mtd/nand/raw/brcmnand/brcmnand.c 
b/drivers/mtd/nand/raw/brcmnand/brcmnand.c
index b87e3e0656df..effc7f1ea802 100644
--- a/drivers/mtd/nand/raw/brcmnand/brcmnand.c
+++ b/drivers/mtd/nand/raw/brcmnand/brcmnand.c
@@ -293,8 +293,8 @@ enum brcmnand_reg {
BRCMNAND_FC_BASE,
 };
 
-/* BRCMNAND v4.0 */
-static const u16 brcmnand_regs_v40[] = {
+/* BRCMNAND v3.3-v4.0 */
+static const u16 brcmnand_regs_v33[] = {
[BRCMNAND_CMD_START]=  0x04,
[BRCMNAND_CMD_EXT_ADDRESS]  =  0x08,
[BRCMNAND_CMD_ADDRESS]  =  0x0c,
@@ -546,8 +546,8 @@ static int brcmnand_revision_init(struct 
brcmnand_controller *ctrl)
ctrl->reg_offsets = brcmnand_regs_v60;
else if (ctrl->nand_version >= 0x0500)
ctrl->reg_offsets = brcmnand_regs_v50;
-   else if (ctrl->nand_version >= 0x0400)
-   ctrl->reg_offsets = brcmnand_regs_v40;
+   else if (ctrl->nand_version >= 0x0303)
+   ctrl->reg_offsets = brcmnand_regs_v33;
 
/* Chip-select stride */
if (ctrl->nand_version >= 0x0701)
-- 
2.39.0



[PATCH 08/14] mtd: rawnand: brcmnand: improve hamming oob layout

2023-01-15 Thread Linus Walleij
From: Álvaro Fernández Rojas 

The current code generates 8 oob sections:
S1  1-5
ECC 6-8
S2  9-15
S3  16-21
ECC 22-24
S4  25-31
S5  32-37
ECC 38-40
S6  41-47
S7  48-53
ECC 54-56
S8  57-63

Change it by merging continuous sections:
S1  1-5
ECC 6-8
S2  9-21
ECC 22-24
S3  25-37
ECC 38-40
S4  41-53
ECC 54-56
S5  57-63

Signed-off-by: Álvaro Fernández Rojas 
Signed-off-by: Miquel Raynal 
Link: 
https://lore.kernel.org/linux-mtd/20200512075733.745374-3-nolt...@gmail.com
[Ported to U-Boot from the Linux kernel]
Signed-off-by: Linus Walleij 
---
 drivers/mtd/nand/raw/brcmnand/brcmnand.c | 35 +++-
 1 file changed, 16 insertions(+), 19 deletions(-)

diff --git a/drivers/mtd/nand/raw/brcmnand/brcmnand.c 
b/drivers/mtd/nand/raw/brcmnand/brcmnand.c
index 7cb6f2651250..d082801b8306 100644
--- a/drivers/mtd/nand/raw/brcmnand/brcmnand.c
+++ b/drivers/mtd/nand/raw/brcmnand/brcmnand.c
@@ -1043,33 +1043,30 @@ static int brcmnand_hamming_ooblayout_free(struct 
mtd_info *mtd, int section,
struct brcmnand_cfg *cfg = &host->hwcfg;
int sas = cfg->spare_area_size << cfg->sector_size_1k;
int sectors = cfg->page_size / (512 << cfg->sector_size_1k);
+   u32 next;
 
-   if (section >= sectors * 2)
+   if (section > sectors)
return -ERANGE;
 
-   oobregion->offset = (section / 2) * sas;
+   next = (section * sas);
+   if (section < sectors)
+   next += 6;
 
-   if (section & 1) {
-   oobregion->offset += 9;
-   oobregion->length = 7;
+   if (section) {
+   oobregion->offset = ((section - 1) * sas) + 9;
} else {
-   oobregion->length = 6;
-
-   /* First sector of each page may have BBI */
-   if (!section) {
-   /*
-* Small-page NAND use byte 6 for BBI while large-page
-* NAND use bytes 0 and 1.
-*/
-   if (cfg->page_size > 512) {
-   oobregion->offset += 2;
-   oobregion->length -= 2;
-   } else {
-   oobregion->length--;
-   }
+   if (cfg->page_size > 512) {
+   /* Large page NAND uses first 2 bytes for BBI */
+   oobregion->offset = 2;
+   } else {
+   /* Small page NAND uses last byte before ECC for BBI */
+   oobregion->offset = 0;
+   next--;
}
}
 
+   oobregion->length = next - oobregion->offset;
+
return 0;
 }
 
-- 
2.39.0



[PATCH 07/14] mtd: rawnand: brcmnand: fix hamming oob layout

2023-01-15 Thread Linus Walleij
From: Álvaro Fernández Rojas 

First 2 bytes are used in large-page nand.

Fixes: ef5eeea6e911 ("mtd: nand: brcm: switch to mtd_ooblayout_ops")
Cc: sta...@vger.kernel.org
Signed-off-by: Álvaro Fernández Rojas 
Signed-off-by: Miquel Raynal 
Link: 
https://lore.kernel.org/linux-mtd/20200512075733.745374-2-nolt...@gmail.com
[Ported to U-Boot from the Linux kernel]
Signed-off-by: Linus Walleij 
---
 drivers/mtd/nand/raw/brcmnand/brcmnand.c | 11 +++
 1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/drivers/mtd/nand/raw/brcmnand/brcmnand.c 
b/drivers/mtd/nand/raw/brcmnand/brcmnand.c
index fdc1fc6c1043..7cb6f2651250 100644
--- a/drivers/mtd/nand/raw/brcmnand/brcmnand.c
+++ b/drivers/mtd/nand/raw/brcmnand/brcmnand.c
@@ -1059,11 +1059,14 @@ static int brcmnand_hamming_ooblayout_free(struct 
mtd_info *mtd, int section,
if (!section) {
/*
 * Small-page NAND use byte 6 for BBI while large-page
-* NAND use byte 0.
+* NAND use bytes 0 and 1.
 */
-   if (cfg->page_size > 512)
-   oobregion->offset++;
-   oobregion->length--;
+   if (cfg->page_size > 512) {
+   oobregion->offset += 2;
+   oobregion->length -= 2;
+   } else {
+   oobregion->length--;
+   }
}
}
 
-- 
2.39.0



[PATCH 06/14] mtd: nand: brcmnand: Add support for flash-dma v0

2023-01-15 Thread Linus Walleij
From: Kamal Dasu 

This change adds support for flash dma v0.0.

Signed-off-by: Kamal Dasu 
Signed-off-by: Miquel Raynal 
[Ported to U-Boot from the Linux kernel]
Signed-off-by: Linus Walleij 
---
 drivers/mtd/nand/raw/brcmnand/brcmnand.c | 21 +++--
 1 file changed, 19 insertions(+), 2 deletions(-)

diff --git a/drivers/mtd/nand/raw/brcmnand/brcmnand.c 
b/drivers/mtd/nand/raw/brcmnand/brcmnand.c
index bbaf403d2a03..fdc1fc6c1043 100644
--- a/drivers/mtd/nand/raw/brcmnand/brcmnand.c
+++ b/drivers/mtd/nand/raw/brcmnand/brcmnand.c
@@ -120,6 +120,18 @@ enum flash_dma_reg {
 };
 
 #ifndef __UBOOT__
+/* flash_dma registers v0*/
+static const u16 flash_dma_regs_v0[] = {
+   [FLASH_DMA_REVISION]= 0x00,
+   [FLASH_DMA_FIRST_DESC]  = 0x04,
+   [FLASH_DMA_CTRL]= 0x08,
+   [FLASH_DMA_MODE]= 0x0c,
+   [FLASH_DMA_STATUS]  = 0x10,
+   [FLASH_DMA_INTERRUPT_DESC]  = 0x14,
+   [FLASH_DMA_ERROR_STATUS]= 0x18,
+   [FLASH_DMA_CURRENT_DESC]= 0x1c,
+};
+
 /* flash_dma registers v1*/
 static const u16 flash_dma_regs_v1[] = {
[FLASH_DMA_REVISION]= 0x00,
@@ -614,6 +626,8 @@ static void brcmnand_flash_dma_revision_init(struct 
brcmnand_controller *ctrl)
/* flash_dma register offsets */
if (ctrl->nand_version >= 0x0703)
ctrl->flash_dma_offsets = flash_dma_regs_v4;
+   else if (ctrl->nand_version == 0x0602)
+   ctrl->flash_dma_offsets = flash_dma_regs_v0;
else
ctrl->flash_dma_offsets = flash_dma_regs_v1;
 }
@@ -1697,8 +1711,11 @@ static void brcmnand_dma_run(struct brcmnand_host *host, 
dma_addr_t desc)
 
flash_dma_writel(ctrl, FLASH_DMA_FIRST_DESC, lower_32_bits(desc));
(void)flash_dma_readl(ctrl, FLASH_DMA_FIRST_DESC);
-   flash_dma_writel(ctrl, FLASH_DMA_FIRST_DESC_EXT, upper_32_bits(desc));
-   (void)flash_dma_readl(ctrl, FLASH_DMA_FIRST_DESC_EXT);
+   if (ctrl->nand_version > 0x0602) {
+   flash_dma_writel(ctrl, FLASH_DMA_FIRST_DESC_EXT,
+upper_32_bits(desc));
+   (void)flash_dma_readl(ctrl, FLASH_DMA_FIRST_DESC_EXT);
+   }
 
/* Start FLASH_DMA engine */
ctrl->dma_pending = true;
-- 
2.39.0



[PATCH 05/14] mtd: rawnand: brcmnand: Fix ecc chunk calculation for erased page bitfips

2023-01-15 Thread Linus Walleij
From: Claire Lin 

In brcmstb_nand_verify_erased_page(), the ECC chunk pointer calculation
while correcting erased page bitflips is wrong, fix it.

Fixes: 02b88eea9f9c ("mtd: brcmnand: Add check for erased page bitflips")
Signed-off-by: Claire Lin 
Reviewed-by: Ray Jui 
Signed-off-by: Kamal Dasu 
Signed-off-by: Miquel Raynal 
[Ported to U-Boot from the Linux kernel]
Signed-off-by: Linus Walleij 
---
 drivers/mtd/nand/raw/brcmnand/brcmnand.c | 5 -
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/drivers/mtd/nand/raw/brcmnand/brcmnand.c 
b/drivers/mtd/nand/raw/brcmnand/brcmnand.c
index ef73205d8c18..bbaf403d2a03 100644
--- a/drivers/mtd/nand/raw/brcmnand/brcmnand.c
+++ b/drivers/mtd/nand/raw/brcmnand/brcmnand.c
@@ -1817,6 +1817,7 @@ static int brcmstb_nand_verify_erased_page(struct 
mtd_info *mtd,
int bitflips = 0;
int page = addr >> chip->page_shift;
int ret;
+   void *ecc_chunk;
 
if (!buf) {
 #ifndef __UBOOT__
@@ -1836,7 +1837,9 @@ static int brcmstb_nand_verify_erased_page(struct 
mtd_info *mtd,
return ret;
 
for (i = 0; i < chip->ecc.steps; i++, oob += sas) {
-   ret = nand_check_erased_ecc_chunk(buf, chip->ecc.size,
+   ecc_chunk = buf + chip->ecc.size * i;
+   ret = nand_check_erased_ecc_chunk(ecc_chunk,
+ chip->ecc.size,
  oob, sas, NULL, 0,
  chip->ecc.strength);
if (ret < 0)
-- 
2.39.0



[PATCH 04/14] mtd: rawnand: brcmnand: Add support for v7.3 controller

2023-01-15 Thread Linus Walleij
From: Kamal Dasu 

This change adds support for brcm NAND v7.3 controller. This controller
uses a newer version of flash_dma engine and change mostly implements
these differences.

Signed-off-by: Kamal Dasu 
Signed-off-by: Miquel Raynal 
[Ported to U-Boot from the Linux kernel]
Signed-off-by: Linus Walleij 
---
 drivers/mtd/nand/raw/brcmnand/brcmnand.c | 106 ++-
 1 file changed, 84 insertions(+), 22 deletions(-)

diff --git a/drivers/mtd/nand/raw/brcmnand/brcmnand.c 
b/drivers/mtd/nand/raw/brcmnand/brcmnand.c
index ede51def5063..ef73205d8c18 100644
--- a/drivers/mtd/nand/raw/brcmnand/brcmnand.c
+++ b/drivers/mtd/nand/raw/brcmnand/brcmnand.c
@@ -86,6 +86,12 @@ struct brcm_nand_dma_desc {
 #define FLASH_DMA_ECC_ERROR(1 << 8)
 #define FLASH_DMA_CORR_ERROR   (1 << 9)
 
+/* Bitfields for DMA_MODE */
+#define FLASH_DMA_MODE_STOP_ON_ERROR   BIT(1) /* stop in Uncorr ECC error */
+#define FLASH_DMA_MODE_MODEBIT(0) /* link list */
+#define FLASH_DMA_MODE_MASK(FLASH_DMA_MODE_STOP_ON_ERROR | \
+   FLASH_DMA_MODE_MODE)
+
 /* 512B flash cache in the NAND controller HW */
 #define FC_SHIFT   9U
 #define FC_BYTES   512U
@@ -98,6 +104,53 @@ struct brcm_nand_dma_desc {
 #define NAND_CTRL_RDY  (INTFC_CTLR_READY | INTFC_FLASH_READY)
 #define NAND_POLL_STATUS_TIMEOUT_MS100
 
+/* flash_dma registers */
+enum flash_dma_reg {
+   FLASH_DMA_REVISION = 0,
+   FLASH_DMA_FIRST_DESC,
+   FLASH_DMA_FIRST_DESC_EXT,
+   FLASH_DMA_CTRL,
+   FLASH_DMA_MODE,
+   FLASH_DMA_STATUS,
+   FLASH_DMA_INTERRUPT_DESC,
+   FLASH_DMA_INTERRUPT_DESC_EXT,
+   FLASH_DMA_ERROR_STATUS,
+   FLASH_DMA_CURRENT_DESC,
+   FLASH_DMA_CURRENT_DESC_EXT,
+};
+
+#ifndef __UBOOT__
+/* flash_dma registers v1*/
+static const u16 flash_dma_regs_v1[] = {
+   [FLASH_DMA_REVISION]= 0x00,
+   [FLASH_DMA_FIRST_DESC]  = 0x04,
+   [FLASH_DMA_FIRST_DESC_EXT]  = 0x08,
+   [FLASH_DMA_CTRL]= 0x0c,
+   [FLASH_DMA_MODE]= 0x10,
+   [FLASH_DMA_STATUS]  = 0x14,
+   [FLASH_DMA_INTERRUPT_DESC]  = 0x18,
+   [FLASH_DMA_INTERRUPT_DESC_EXT]  = 0x1c,
+   [FLASH_DMA_ERROR_STATUS]= 0x20,
+   [FLASH_DMA_CURRENT_DESC]= 0x24,
+   [FLASH_DMA_CURRENT_DESC_EXT]= 0x28,
+};
+
+/* flash_dma registers v4 */
+static const u16 flash_dma_regs_v4[] = {
+   [FLASH_DMA_REVISION]= 0x00,
+   [FLASH_DMA_FIRST_DESC]  = 0x08,
+   [FLASH_DMA_FIRST_DESC_EXT]  = 0x0c,
+   [FLASH_DMA_CTRL]= 0x10,
+   [FLASH_DMA_MODE]= 0x14,
+   [FLASH_DMA_STATUS]  = 0x18,
+   [FLASH_DMA_INTERRUPT_DESC]  = 0x20,
+   [FLASH_DMA_INTERRUPT_DESC_EXT]  = 0x24,
+   [FLASH_DMA_ERROR_STATUS]= 0x28,
+   [FLASH_DMA_CURRENT_DESC]= 0x30,
+   [FLASH_DMA_CURRENT_DESC_EXT]= 0x34,
+};
+#endif /* __UBOOT__ */
+
 /* Controller feature flags */
 enum {
BRCMNAND_HAS_1K_SECTORS = BIT(0),
@@ -135,6 +188,8 @@ struct brcmnand_controller {
/* List of NAND hosts (one for each chip-select) */
struct list_head host_list;
 
+   /* flash_dma reg */
+   const u16   *flash_dma_offsets;
struct brcm_nand_dma_desc *dma_desc;
dma_addr_t  dma_pa;
 
@@ -473,7 +528,7 @@ static int brcmnand_revision_init(struct 
brcmnand_controller *ctrl)
/* Register offsets */
if (ctrl->nand_version >= 0x0702)
ctrl->reg_offsets = brcmnand_regs_v72;
-   else if (ctrl->nand_version >= 0x0701)
+   else if (ctrl->nand_version == 0x0701)
ctrl->reg_offsets = brcmnand_regs_v71;
else if (ctrl->nand_version >= 0x0600)
ctrl->reg_offsets = brcmnand_regs_v60;
@@ -518,7 +573,7 @@ static int brcmnand_revision_init(struct 
brcmnand_controller *ctrl)
}
 
/* Maximum spare area sector size (per 512B) */
-   if (ctrl->nand_version >= 0x0702)
+   if (ctrl->nand_version == 0x0702)
ctrl->max_oob = 128;
else if (ctrl->nand_version >= 0x0600)
ctrl->max_oob = 64;
@@ -553,6 +608,17 @@ static int brcmnand_revision_init(struct 
brcmnand_controller *ctrl)
return 0;
 }
 
+#ifndef __UBOOT__
+static void brcmnand_flash_dma_revision_init(struct brcmnand_controller *ctrl)
+{
+   /* flash_dma register offsets */
+   if (ctrl->nand_version >= 0x0703)
+   ctrl->flash_dma_offsets = flash_dma_regs_v4;
+   else
+   ctrl->flash_dma_offsets = flash_dma_regs_v1;
+}
+#endif /* __UBOOT__ */
+
 static inline u32 brcmnand_read_reg(struct brcmnand_controller *ctrl,
enum brcmnand_reg reg)
 {
@@ -675,7 +741,7 @@ static void brcmnand_wr_corr_thresh(struct brcmnand_host 
*host, u8 val)
enum brcmnand_reg re

[PATCH 03/14] mtd: rawnand: brcmnand: Refactored code to introduce helper functions

2023-01-15 Thread Linus Walleij
From: Kamal Dasu 

Refactored NAND ECC and CMD address configuration code to use helper
functions.

Signed-off-by: Kamal Dasu 
Signed-off-by: Miquel Raynal 
[Ported to U-Boot from the Linux kernel]
Signed-off-by: Linus Walleij 
---
 drivers/mtd/nand/raw/brcmnand/brcmnand.c | 100 ++-
 1 file changed, 62 insertions(+), 38 deletions(-)

diff --git a/drivers/mtd/nand/raw/brcmnand/brcmnand.c 
b/drivers/mtd/nand/raw/brcmnand/brcmnand.c
index 65aab4be87b9..ede51def5063 100644
--- a/drivers/mtd/nand/raw/brcmnand/brcmnand.c
+++ b/drivers/mtd/nand/raw/brcmnand/brcmnand.c
@@ -595,6 +595,54 @@ static inline void brcmnand_write_fc(struct 
brcmnand_controller *ctrl,
__raw_writel(val, ctrl->nand_fc + word * 4);
 }
 
+static void brcmnand_clear_ecc_addr(struct brcmnand_controller *ctrl)
+{
+
+   /* Clear error addresses */
+   brcmnand_write_reg(ctrl, BRCMNAND_UNCORR_ADDR, 0);
+   brcmnand_write_reg(ctrl, BRCMNAND_CORR_ADDR, 0);
+   brcmnand_write_reg(ctrl, BRCMNAND_UNCORR_EXT_ADDR, 0);
+   brcmnand_write_reg(ctrl, BRCMNAND_CORR_EXT_ADDR, 0);
+}
+
+static u64 brcmnand_get_uncorrecc_addr(struct brcmnand_controller *ctrl)
+{
+   u64 err_addr;
+
+   err_addr = brcmnand_read_reg(ctrl, BRCMNAND_UNCORR_ADDR);
+   err_addr |= ((u64)(brcmnand_read_reg(ctrl,
+BRCMNAND_UNCORR_EXT_ADDR)
+& 0x) << 32);
+
+   return err_addr;
+}
+
+static u64 brcmnand_get_correcc_addr(struct brcmnand_controller *ctrl)
+{
+   u64 err_addr;
+
+   err_addr = brcmnand_read_reg(ctrl, BRCMNAND_CORR_ADDR);
+   err_addr |= ((u64)(brcmnand_read_reg(ctrl,
+BRCMNAND_CORR_EXT_ADDR)
+& 0x) << 32);
+
+   return err_addr;
+}
+
+static void brcmnand_set_cmd_addr(struct mtd_info *mtd, u64 addr)
+{
+   struct nand_chip *chip =  mtd_to_nand(mtd);
+   struct brcmnand_host *host = nand_get_controller_data(chip);
+   struct brcmnand_controller *ctrl = host->ctrl;
+
+   brcmnand_write_reg(ctrl, BRCMNAND_CMD_EXT_ADDRESS,
+  (host->cs << 16) | ((addr >> 32) & 0x));
+   (void)brcmnand_read_reg(ctrl, BRCMNAND_CMD_EXT_ADDRESS);
+   brcmnand_write_reg(ctrl, BRCMNAND_CMD_ADDRESS,
+  lower_32_bits(addr));
+   (void)brcmnand_read_reg(ctrl, BRCMNAND_CMD_ADDRESS);
+}
+
 static inline u16 brcmnand_cs_offset(struct brcmnand_controller *ctrl, int cs,
 enum brcmnand_cs_reg reg)
 {
@@ -1242,9 +1290,12 @@ static void brcmnand_send_cmd(struct brcmnand_host 
*host, int cmd)
 {
struct brcmnand_controller *ctrl = host->ctrl;
int ret;
+   u64 cmd_addr;
+
+   cmd_addr = brcmnand_read_reg(ctrl, BRCMNAND_CMD_ADDRESS);
+
+   dev_dbg(ctrl->dev, "send native cmd %d addr 0x%llx\n", cmd, cmd_addr);
 
-   dev_dbg(ctrl->dev, "send native cmd %d addr_lo 0x%x\n", cmd,
-   brcmnand_read_reg(ctrl, BRCMNAND_CMD_ADDRESS));
BUG_ON(ctrl->cmd_pending != 0);
ctrl->cmd_pending = cmd;
 
@@ -1417,12 +1468,7 @@ static void brcmnand_cmdfunc(struct mtd_info *mtd, 
unsigned command,
if (!native_cmd)
return;
 
-   brcmnand_write_reg(ctrl, BRCMNAND_CMD_EXT_ADDRESS,
-   (host->cs << 16) | ((addr >> 32) & 0x));
-   (void)brcmnand_read_reg(ctrl, BRCMNAND_CMD_EXT_ADDRESS);
-   brcmnand_write_reg(ctrl, BRCMNAND_CMD_ADDRESS, lower_32_bits(addr));
-   (void)brcmnand_read_reg(ctrl, BRCMNAND_CMD_ADDRESS);
-
+   brcmnand_set_cmd_addr(mtd, addr);
brcmnand_send_cmd(host, native_cmd);
brcmnand_waitfunc(mtd, chip);
 
@@ -1652,20 +1698,10 @@ static int brcmnand_read_by_pio(struct mtd_info *mtd, 
struct nand_chip *chip,
struct brcmnand_controller *ctrl = host->ctrl;
int i, j, ret = 0;
 
-   /* Clear error addresses */
-   brcmnand_write_reg(ctrl, BRCMNAND_UNCORR_ADDR, 0);
-   brcmnand_write_reg(ctrl, BRCMNAND_CORR_ADDR, 0);
-   brcmnand_write_reg(ctrl, BRCMNAND_UNCORR_EXT_ADDR, 0);
-   brcmnand_write_reg(ctrl, BRCMNAND_CORR_EXT_ADDR, 0);
-
-   brcmnand_write_reg(ctrl, BRCMNAND_CMD_EXT_ADDRESS,
-   (host->cs << 16) | ((addr >> 32) & 0x));
-   (void)brcmnand_read_reg(ctrl, BRCMNAND_CMD_EXT_ADDRESS);
+   brcmnand_clear_ecc_addr(ctrl);
 
for (i = 0; i < trans; i++, addr += FC_BYTES) {
-   brcmnand_write_reg(ctrl, BRCMNAND_CMD_ADDRESS,
-  lower_32_bits(addr));
-   (void)brcmnand_read_reg(ctrl, BRCMNAND_CMD_ADDRESS);
+   brcmnand_set_cmd_addr(mtd, addr);
/* SPARE_AREA_READ does not use ECC, so just use PAGE_READ */
brcmnand_send_cmd(host, CMD_PAGE_READ);
brcmnand_waitfunc(mtd, chip);
@@ -1685,21 +1721,15 @@ static int brcmnand_read_by_pio(struct m

[PATCH 02/14] mtd: rawnand: brcmnand: Fix BCH ECC layout for large page NAND parts

2023-01-15 Thread Linus Walleij
From: Kamal Dasu 

The way oobregion->offset is derived for large page NAND parts is
wrong, fixes it.

Fixes: ef5eeea6e911 ("mtd: nand: brcm: switch to mtd_ooblayout_ops")
Signed-off-by: Kamal Dasu 
Reviewed-by: Florian Fainelli 
Signed-off-by: Miquel Raynal 
[Ported to U-Boot from the Linux kernel]
Signed-off-by: Linus Walleij 
---
 drivers/mtd/nand/raw/brcmnand/brcmnand.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/mtd/nand/raw/brcmnand/brcmnand.c 
b/drivers/mtd/nand/raw/brcmnand/brcmnand.c
index 8ea33e861354..65aab4be87b9 100644
--- a/drivers/mtd/nand/raw/brcmnand/brcmnand.c
+++ b/drivers/mtd/nand/raw/brcmnand/brcmnand.c
@@ -968,7 +968,7 @@ static int brcmnand_bch_ooblayout_ecc(struct mtd_info *mtd, 
int section,
if (section >= sectors)
return -ERANGE;
 
-   oobregion->offset = (section * (sas + 1)) - chip->ecc.bytes;
+   oobregion->offset = ((section + 1) * sas) - chip->ecc.bytes;
oobregion->length = chip->ecc.bytes;
 
return 0;
-- 
2.39.0



[PATCH 01/14] mtd: nand: brcm: switch to mtd_ooblayout_ops

2023-01-15 Thread Linus Walleij
From: Boris Brezillon 

Implementing the mtd_ooblayout_ops interface is the new way of exposing
ECC/OOB layout to MTD users.

Signed-off-by: Boris Brezillon 
[Ported to U-Boot from the Linux kernel]
Signed-off-by: Linus Walleij 
---
 drivers/mtd/nand/raw/brcmnand/brcmnand.c | 260 ++-
 1 file changed, 156 insertions(+), 104 deletions(-)

diff --git a/drivers/mtd/nand/raw/brcmnand/brcmnand.c 
b/drivers/mtd/nand/raw/brcmnand/brcmnand.c
index 74c9348f7fc4..8ea33e861354 100644
--- a/drivers/mtd/nand/raw/brcmnand/brcmnand.c
+++ b/drivers/mtd/nand/raw/brcmnand/brcmnand.c
@@ -894,131 +894,183 @@ static inline bool is_hamming_ecc(struct 
brcmnand_controller *ctrl,
 }
 
 /*
- * Returns a nand_ecclayout strucutre for the given layout/configuration.
- * Returns NULL on failure.
+ * Set mtd->ooblayout to the appropriate mtd_ooblayout_ops given
+ * the layout/configuration.
+ * Returns -ERRCODE on failure.
  */
-static struct nand_ecclayout *brcmnand_create_layout(int ecc_level,
-struct brcmnand_host *host)
+static int brcmnand_hamming_ooblayout_ecc(struct mtd_info *mtd, int section,
+ struct mtd_oob_region *oobregion)
 {
+   struct nand_chip *chip = mtd_to_nand(mtd);
+   struct brcmnand_host *host = nand_get_controller_data(chip);
struct brcmnand_cfg *cfg = &host->hwcfg;
-   int i, j;
-   struct nand_ecclayout *layout;
-   int req;
-   int sectors;
-   int sas;
-   int idx1, idx2;
 
-#ifndef __UBOOT__
-   layout = devm_kzalloc(&host->pdev->dev, sizeof(*layout), GFP_KERNEL);
-#else
-   layout = devm_kzalloc(host->pdev, sizeof(*layout), GFP_KERNEL);
-#endif
-   if (!layout)
-   return NULL;
-
-   sectors = cfg->page_size / (512 << cfg->sector_size_1k);
-   sas = cfg->spare_area_size << cfg->sector_size_1k;
-
-   /* Hamming */
-   if (is_hamming_ecc(host->ctrl, cfg)) {
-   for (i = 0, idx1 = 0, idx2 = 0; i < sectors; i++) {
-   /* First sector of each page may have BBI */
-   if (i == 0) {
-   layout->oobfree[idx2].offset = i * sas + 1;
-   /* Small-page NAND use byte 6 for BBI */
-   if (cfg->page_size == 512)
-   layout->oobfree[idx2].offset--;
-   layout->oobfree[idx2].length = 5;
-   } else {
-   layout->oobfree[idx2].offset = i * sas;
-   layout->oobfree[idx2].length = 6;
-   }
-   idx2++;
-   layout->eccpos[idx1++] = i * sas + 6;
-   layout->eccpos[idx1++] = i * sas + 7;
-   layout->eccpos[idx1++] = i * sas + 8;
-   layout->oobfree[idx2].offset = i * sas + 9;
-   layout->oobfree[idx2].length = 7;
-   idx2++;
-   /* Leave zero-terminated entry for OOBFREE */
-   if (idx1 >= MTD_MAX_ECCPOS_ENTRIES_LARGE ||
-   idx2 >= MTD_MAX_OOBFREE_ENTRIES_LARGE - 1)
-   break;
-   }
+   int sas = cfg->spare_area_size << cfg->sector_size_1k;
+   int sectors = cfg->page_size / (512 << cfg->sector_size_1k);
 
-   return layout;
-   }
+   if (section >= sectors)
+   return -ERANGE;
+   oobregion->offset = (section * sas) + 6;
+   oobregion->length = 3;
 
-   /*
-* CONTROLLER_VERSION:
-*   < v5.0: ECC_REQ = ceil(BCH_T * 13/8)
-*  >= v5.0: ECC_REQ = ceil(BCH_T * 14/8)
-* But we will just be conservative.
-*/
-   req = DIV_ROUND_UP(ecc_level * 14, 8);
-   if (req >= sas) {
-   dev_err(host->pdev,
-   "error: ECC too large for OOB (ECC bytes %d, spare 
sector %d)\n",
-   req, sas);
-   return NULL;
-   }
+   return 0;
+}
+
+static int brcmnand_hamming_ooblayout_free(struct mtd_info *mtd, int section,
+  struct mtd_oob_region *oobregion)
+{
+   struct nand_chip *chip = mtd_to_nand(mtd);
+   struct brcmnand_host *host = nand_get_controller_data(chip);
+   struct brcmnand_cfg *cfg = &host->hwcfg;
+   int sas = cfg->spare_area_size << cfg->sector_size_1k;
+   int sectors = cfg->page_size / (512 << cfg->sector_size_1k);
+
+   if (section >= sectors * 2)
+   return -ERANGE;
+
+   oobregion->offset = (section / 2) * sas;
 
-   layout->eccbytes = req * sectors;
-   for (i = 0, idx1 = 0, idx2 = 0; i < sectors; i++) {
-   for (j = sas - req; j < sas && idx1 <
-   MTD_MAX_ECCPOS_ENTRIES_LARGE; j++, idx1++)
-   layout->

[PATCH 00/14] Backport BRCMNAND changes from Linux

2023-01-15 Thread Linus Walleij
Hunting down a bug on my system I took to back-porting
all reasonable changes from the Linux brcmnand driver that
were not yet in the U-Boot derivative.

I noticed that a simple diff -ur between brcmnand.c
between the file in Linux and U-Boot was possible to see
what differs. Combining this with some git log --oneline
manual comparison, fuzzing and manual intervention I
backported a set of relevant patches from Linux that
compiles and WorksForMe(TM).

The diff between Linux and U-Boot is much smaller after
this, the main missing part are subsystem cosmetics
changes and the EDU DMA mode support.

This was as much as I could bite off in one go.

All patches countersigned-off and marked as [backported].

It's nice if someone else tests this I think.

Boris Brezillon (1):
  mtd: nand: brcm: switch to mtd_ooblayout_ops

Claire Lin (1):
  mtd: rawnand: brcmnand: Fix ecc chunk calculation for erased page
bitfips

Kamal Dasu (4):
  mtd: rawnand: brcmnand: Fix BCH ECC layout for large page NAND parts
  mtd: rawnand: brcmnand: Refactored code to introduce helper functions
  mtd: rawnand: brcmnand: Add support for v7.3 controller
  mtd: nand: brcmnand: Add support for flash-dma v0

Álvaro Fernández Rojas (8):
  mtd: rawnand: brcmnand: fix hamming oob layout
  mtd: rawnand: brcmnand: improve hamming oob layout
  mtd: rawnand: brcmnand: correctly verify erased pages
  mtd: rawnand: brcmnand: rename v4 registers
  mtd: rawnand: brcmnand: fix CS0 layout
  mtd: rawnand: brcmnand: rename page sizes
  mtd: rawnand: brcmnand: support v2.1-v2.2 controllers
  mtd: rawnand: brcmnand: fix OOB R/W with Hamming ECC

 drivers/mtd/nand/raw/brcmnand/brcmnand.c | 615 ---
 1 file changed, 425 insertions(+), 190 deletions(-)

-- 
2.39.0



Re: v2023.01: u-boot-tools build failure

2023-01-15 Thread Fabio Estevam
Hi Vagrant,

On Fri, Jan 13, 2023 at 8:37 PM Vagrant Cascadian  wrote:

> FWIW, we have not shipped bmp_logo in Debian's u-boot-tools package, so
> we have managed without it, though curious what the use-case might be.
>
> It is disabled in Debian for now:
>
>   
> https://salsa.debian.org/debian/u-boot/-/blob/debian/2023.01+dfsg-1/debian/patches/tools-disable-video-logo
>
> ... at least until a better fix comes along. :)

Thanks for sharing your input.

Peter,

Commit 1cfba53ca46c ("config: tools only: add VIDEO to build
bmp_logo") is causing issues
on Debian and OpenEmbedded.

How do you suggest we proceed?

Thanks


SPL_FIT_GENERATOR series

2023-01-15 Thread Simon Glass
Hi Kever,

Do you think we could apply this series[1] ?

I am happy to do this myself if you would like it to go through the
driver model tree.

Regards,
Simon

[1] https://patchwork.ozlabs.org/project/uboot/list/?series=335487


Re: [PATCH 7/8] [DO NOT MERGE, DIRTY HACK] sunxi: use UBI for environement storage

2023-01-15 Thread Icenowy Zheng
在 2022-10-14星期五的 11:05 +0800,Icenowy Zheng写道:
> Signed-off-by: Icenowy Zheng 

By the way should we have some better way to handle the placement of
environments?

> ---
>  board/sunxi/board.c | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/board/sunxi/board.c b/board/sunxi/board.c
> index 21a2407e06..f4138573d4 100644
> --- a/board/sunxi/board.c
> +++ b/board/sunxi/board.c
> @@ -133,6 +133,7 @@ void i2c_init_board(void)
>   */
>  enum env_location env_get_location(enum env_operation op, int prio)
>  {
> +   return prio ? ENVL_UNKNOWN : ENVL_UBI;
> if (prio > 1)
> return ENVL_UNKNOWN;
>  



Re: [PATCH v9 14/14] treewide: Disable USE_SPL_FIT_GENERATOR by default

2023-01-15 Thread Simon Glass
Hi Michal,

On Tue, 10 Jan 2023 at 08:16, Michal Simek  wrote:
>
> Hi Simon,
>
> On 1/9/23 16:34, Simon Glass wrote:
> > Hi Michal,
> >
> > On Mon, 9 Jan 2023 at 04:07, Michal Simek  > > wrote:
> >  >
> >  > Hi,
> >  >
> >  > On 1/8/23 20:36, Simon Glass wrote:
> >  > > Hi Tom,
> >  > >
> >  > > On Sun, 8 Jan 2023 at 09:24, Tom Rini  > > wrote:
> >  > >>
> >  > >> On Sun, Jan 08, 2023 at 09:20:09AM -0700, Simon Glass wrote:
> >  > >>> Hi Tom,
> >  > >>>
> >  > >>> On Sun, 8 Jan 2023 at 09:06, Tom Rini  > > wrote:
> >  > 
> >  >  On Sun, Jan 08, 2023 at 08:48:37AM -0700, Simon Glass wrote:
> >  > > Hi Tom,
> >  > >
> >  > > On Sun, 8 Jan 2023 at 06:41, Tom Rini  > > wrote:
> >  > >>
> >  > >> On Sat, Jan 07, 2023 at 02:07:21PM -0700, Simon Glass wrote:
> >  > >>
> >  > >>> This option is deprecated and only used by two boards. Enable it 
> > for just
> >  > >>> those two boards, so others don't accidentally enable it.
> >  > >>>
> >  > >>> Signed-off-by: Simon Glass  > >
> >  > >> [snip]
> >  > >>> diff --git a/boot/Kconfig b/boot/Kconfig
> >  > >>> index 55f06761ef8..7ab0dd14211 100644
> >  > >>> --- a/boot/Kconfig
> >  > >>> +++ b/boot/Kconfig
> >  > >>> @@ -282,12 +282,13 @@ config SPL_FIT_SOURCE
> >  > >>>   config USE_SPL_FIT_GENERATOR
> >  > >>>bool "Use a script to generate the .its script"
> >  > >>>depends on SPL_FIT
> >  > >>> - default y if SPL_FIT && ARCH_ZYNQMP
> >  > >>> + help
> >  > >>> +   This is deprecated. Please do not use it. Use binman 
> > instead.
> >  > >>
> >  > >> Lets remove the text around bool so it can't be enabled, and move 
> > to
> >  > >> select'ing it from the two boards that need it. Michal, Luca, 
> > what's
> >  > >> needed to move your two platforms
> >  > >> (avnet_ultrazedev_cc_v1_0_ultrazedev_som_v1_0 and 
> > xilinx_zynqmp_virt off
> >  > >> of this very legacy option, given that other xilinx platforms have
> >  > >> already migrated to binman ?
> >  > >
> >  > > That's a good idea, but these two boards do not have TARGET Kconfig
> >  > > options so it is not possible without adding some Kconfig specific 
> > to
> >  > > those boards, then defining it in the defconfig files.
> >  > >
> >  > > We already have the legacy warning.
> >  > 
> >  >  Yes, but I swear these are new legacy users as when we started 
> > trying to
> >  >  kill off this option it was just a few i.MX platforms lagging 
> > behind.
> >  > 
> >  >  Maybe make ARCH_ZYNQMP select DEPRECATED, USE_SPL_FIT_GENERATOR 
> > depend
> >  >  on DEPRECATED and add "DERECATED" to the end of the text line?  Or 
> > maybe
> >  >  Michal or Luca will speak up soon and migrate these over quickly so 
> > we
> >  >  can just nuke this.
> >  > >>>
> >  > >>> Isn't that just more tortuous? I can disable SPL_LOAD_FIT on these 
> > two
> >  > >>> boards since they don't appear in CI. Then they can convert them when
> >  > >>> ready.
> >  > >>>
> >  > >>> That way we can drop the option now, if that is your goal.
> >  > >>
> >  > >> I thought xilinx_zynqmp_virt was in CI, but I see I'm mistaken. I 
> > still
> >  > >> don't want to break platforms outright, and since it's Sunday right 
> > now
> >  > >> afterall, we should let Michal and Luca a chance to catch up and chime
> >  > >> in. I hope it's either going to be a quick conversion or expose
> >  > >> something missing and needed in binman, as to why these still haven't
> >  > >> been converted.
> >  > >>
> >  > >
> >  > > OK let's hold off on this patch for now. It is just a clean-up anyway.
> >  >
> >  > First of all. ZynqMP is not wired in CI simply because we are missing 
> > some bits
> >  > and pieces in upstream qemu to run it. If we can wire it with Xilinx 
> > version we
> >  > can do it. I have asked to fix it our qemu team but they have never done 
> > it.
> >  >
> >  > In U-Boot SPL flow this script is used all the time. I use it all the 
> > time when
> >  > I build work on ZynqMP. Also buildroot is using it.
> >  >
> >  > In connection to binman. I have looked at it 2/3 times in past. The 
> > biggest
> >  > issue which I have with it is that DT node presence in DT which goes to 
> > the
> > system.
> >  >
> >  > Here is example
> >  >
> >  > [u-boot](binman)$ make kontron_sl28_defconfig >/dev/null
> >  > [u-boot](binman)$ make -j8 >/dev/null
> >  > [u-boot](binman)$ dtc -I dtb -O dts dts/dt.dtb 2>/dev/null | grep binman
> >  > binman {
> >  > binman = "/binman";
> >  > u_boot_rom = "/binman/u-boot-rom";
> >  >
> >  > where binmap is the part of target DT.
> >
> > Thanks for the info.
> >
> >  >
> >  > It has side effects.
> >  > 1. DT is bigger
> >
> >  From my experience 

Re: [PATCH v1 1/3] fdt: validate/fix cells count on mtdpart fixup

2023-01-15 Thread Marek Vasut

On 1/13/23 19:45, Francesco Dolcini wrote:

From: Francesco Dolcini 

Fixup #size-cells value when updating the MTD partitions, this is
required to prevent issues in case the MTD parent set #size-cells to
zero.
This could happen for example in the legacy case in which the partitions
are created as direct child of the mtd node and that specific node has
no children. Recent clean-up on Linux device tree files created a boot
regression on colibri-imx7.

This fixup has the limitation to assume 32-bit (#size-cells=1)
addressing, therefore it will not work with device bigger than 4GiB.

This change also enforce #address-cells to be the same as #size-cells,
this was already silently enforced by fdt_node_set_part_info(), now this
is checked explicitly and partition fixup will just fail in such case.

In general board should not generally need nor use this functionality
and should be just deprecated, passing mtdparts= in the kernel command
line is the preferred way according to Linux MTD subsystem maintainer.

Link: https://lore.kernel.org/all/20221202071900.1143950-1-france...@dolcini.it/
Link: https://lore.kernel.org/all/y4dgbtgnwpm6s...@francesco-nb.int.toradex.com/
Cc: Marek Vasut 
Cc: Miquel Raynal 
Signed-off-by: Francesco Dolcini 
---
  common/fdt_support.c | 45 ++--
  1 file changed, 35 insertions(+), 10 deletions(-)

diff --git a/common/fdt_support.c b/common/fdt_support.c
index dbceec6f2dcc..3aee826e60cf 100644
--- a/common/fdt_support.c
+++ b/common/fdt_support.c
@@ -877,27 +877,20 @@ static int fdt_del_partitions(void *blob, int 
parent_offset)
return 0;
  }
  
-static int fdt_node_set_part_info(void *blob, int parent_offset,

+/* This expects #address-cells and #size-cells to have same value */
+static int fdt_node_set_part_info(void *blob, int parent_offset, int sizecell,
  struct mtd_device *dev)
  {
struct list_head *pentry;
struct part_info *part;
int off, ndepth = 0;
int part_num, ret;
-   int sizecell;
char buf[64];
  
  	ret = fdt_del_partitions(blob, parent_offset);

if (ret < 0)
return ret;
  
-	/*

-* Check if size/address is 1 or 2 cells.
-* We assume #address-cells and #size-cells have same value.
-*/
-   sizecell = fdt_getprop_u32_default_node(blob, parent_offset,
-   0, "#size-cells", 1);
-
/*
 * Check if it is nand {}; subnode, adjust
 * the offset in this case
@@ -992,6 +985,31 @@ err_prop:
return ret;
  }
  
+static int fdt_mtdparts_cell_cnt(void *fdt, int off)

+{
+   int sizecell, addrcell;
+
+   sizecell = fdt_getprop_u32_default_node(fdt, off, 0, "#size-cells", 0);
+   if (sizecell != 1 && sizecell != 2) {
+   printf("%s: Invalid or missing #size-cells %d value, assuming 
1\n",
+  __func__, sizecell);
+
+   sizecell = 1;
+   if (fdt_setprop_u32(fdt, off, "#size-cells", sizecell))
+   return -1;
+   }
+
+   addrcell = fdt_getprop_u32_default_node(fdt, off, 0,
+   "#address-cells", 0);
+   if (addrcell != sizecell) {
+   printf("%s: Invalid #address-cells %d != #size-cells %d, 
aborting\n",
+  __func__, addrcell, sizecell);
+   return -1;
+   }
+
+   return sizecell;
+}
+
  /*
   * Update partitions in nor/nand nodes using info from
   * mtdparts environment variable. The nodes to update are
@@ -1037,12 +1055,19 @@ void fdt_fixup_mtdparts(void *blob, const struct 
node_info *node_info,
  
  			dev = device_find(node_info[i].type, idx++);

if (dev) {
+   int cell;
+
parts = fdt_subnode_offset(blob, noff,
   "partitions");
if (parts < 0)
parts = noff;
  
-if (fdt_node_set_part_info(blob, parts, dev))

+   cell = fdt_mtdparts_cell_cnt(blob, parts);
+   if (cell < 0)
+   return;
+
+   if (fdt_node_set_part_info(blob, parts,
+  cell, dev))
return; /* return on error */
}
}


Can you please include the resulting gpmi node content with this fixup 
applied in the commit message , so it can be validated ?


Re: [PATCH v1 2/3] colibri-imx7: specify MTD partitions on command line

2023-01-15 Thread Marek Vasut

On 1/13/23 19:45, Francesco Dolcini wrote:

From: Francesco Dolcini 

Disable fdt_fixup_mtdparts(), instead pass MTD partition on the command
line. This is the preferred method to be used when partitions are not
statically defined into the DTS according the Linux MTD subsystem
maintainer.


Do we really want to do this ?
I thought passing the mtdparts via DT is the preferred way ?


[PULL] u-boot-sh/master

2023-01-15 Thread Marek Vasut

The following changes since commit fe4c21de4fbf5756d354d2473ffc675e7596ccfb:

  Merge tag 'u-boot-stm32-20230113' of 
https://source.denx.de/u-boot/custodians/u-boot-stm (2023-01-13 09:56:19 
-0500)


are available in the Git repository at:

  git://source.denx.de/u-boot-sh.git master

for you to fetch changes up to 4327df1d345e502f48a1a23b091ae39110481026:

  configs: r8a77980: Condor: Enable MMC support by default (2023-01-14 
14:10:12 +0100)



Andrey Dolnikov (1):
  configs: r8a77980: Condor: Enable MMC support by default

Hai Pham (1):
  ARM: renesas: condor: switch eMMC bus to 1V8

Marek Vasut (9):
  ARM: renesas: Enable LTO on R-Car3 ULCB
  ARM: renesas: Enable LTO on R-Car3 Eagle
  ARM: renesas: Enable LTO on R-Car3 Condor
  ARM: renesas: Enable LTO on R-Car3 Ebisu
  ARM: renesas: Enable LTO on R-Car3 Draak
  ARM: renesas: Enable LTO on R-Car3 Falcon
  ARM: renesas: condor: Set CONFIG_TEXT_BASE=0x0 on R-Car Gen3 Condor
  ARM: renesas: ulcb: Set CONFIG_TEXT_BASE=0x0 on R-Car Gen3 ULCB
  ARM: dts: renesas: condor: Enable SPI NOR fast-read

 arch/arm/dts/r8a77980-condor-u-boot.dts |  1 +
 arch/arm/dts/r8a77980-condor.dts|  8 +---
 configs/r8a77970_eagle_defconfig|  1 +
 configs/r8a77980_condor_defconfig   | 10 --
 configs/r8a77990_ebisu_defconfig|  1 +
 configs/r8a77995_draak_defconfig|  1 +
 configs/r8a779a0_falcon_defconfig   |  1 +
 configs/rcar3_ulcb_defconfig|  3 ++-
 8 files changed, 16 insertions(+), 10 deletions(-)


[PULL] u-boot-usb/master

2023-01-15 Thread Marek Vasut

The following changes since commit fe4c21de4fbf5756d354d2473ffc675e7596ccfb:

  Merge tag 'u-boot-stm32-20230113' of 
https://source.denx.de/u-boot/custodians/u-boot-stm (2023-01-13 09:56:19 
-0500)


are available in the Git repository at:

  git://source.denx.de/u-boot-usb.git master

for you to fetch changes up to 2383e8f4aec7a5087526d501478c4ba8235da2b4:

  usb: gadget: dwc2_udc_otg: implement pullup() (2023-01-14 14:10:30 +0100)


Dario Binacchi (1):
  usb: gadget: fastboot: detach usb just before rebooting

Mattijs Korpershoek (1):
  usb: gadget: dwc2_udc_otg: implement pullup()

Patrick Delaunay (1):
  usb: hub: allow to increase HUB_DEBOUNCE_TIMEOUT

 common/Kconfig| 12 
 common/usb_hub.c  |  2 +-
 drivers/usb/gadget/dwc2_udc_otg.c |  9 +
 drivers/usb/gadget/f_fastboot.c   |  2 +-
 4 files changed, 23 insertions(+), 2 deletions(-)


Re: [PATCH 2/2] event: Correct dependencies on the EVENT framework

2023-01-15 Thread Tom Rini
On Sat, Jan 14, 2023 at 06:31:05PM -0700, Simon Glass wrote:
> Hi Tom,
> 
> On Sat, 14 Jan 2023 at 13:49, Tom Rini  wrote:
> >
> > The event framework is just that, a framework. Enabling it by itself
> > does nothing, so we shouldn't ask the user about it. Reword (and correct
> > typos) around this the option and help text. This also applies to
> > DM_EVENT, so reword as well.
> >
> > With this, it's time to address the larger problems. When functionality
> > uses events, typically via EVENT_SPY, the appropriate framework then
> > must be select'd and NOT imply'd. As the functionality will cease to
> > work (and so, platforms will fail to boot) this is non-optional and
> > where select is appropriate. Audit the current users of EVENT_SPY to
> > have a more fine-grained approach to select'ing the framework where
> > used.
> >
> > Cc: Simon Glass 
> > Reported-by: Oliver Graute 
> > Reported-by: Francesco Dolcini 
> > Fixes: 7fe32b3442f0 ("event: Convert arch_cpu_init_dm() to use events")
> > Fixes: 42fdcebf859f ("event: Convert misc_init_f() to use events")
> > Signed-off-by: Tom Rini 
> > ---
> >  arch/Kconfig |  6 +++---
> >  arch/arm/Kconfig |  9 -
> >  arch/arm/mach-omap2/Kconfig  |  3 +++
> >  arch/mips/Kconfig|  2 +-
> >  arch/powerpc/cpu/mpc85xx/Kconfig |  1 +
> >  arch/x86/Kconfig |  1 +
> >  arch/x86/cpu/baytrail/Kconfig|  1 +
> >  arch/x86/cpu/broadwell/Kconfig   |  1 +
> >  arch/x86/cpu/ivybridge/Kconfig   |  1 +
> >  arch/x86/cpu/quark/Kconfig   |  1 +
> >  board/google/Kconfig |  1 +
> >  board/keymile/Kconfig|  1 +
> >  boot/Kconfig |  1 +
> >  cmd/Kconfig  |  1 +
> >  common/Kconfig   | 17 -
> >  drivers/core/Kconfig |  9 +
> >  drivers/cpu/Kconfig  |  1 -
> 
> Reviewed-by: Simon Glass 
> 
> Tested on chromebook-coral:
> Tested-by: Simon Glass 
> 
> I am not quite sure what the effective difference is between select
> and imply. Doesn't this suggest that there are some conflicting config
> options? The only way imply would be disabled ( I thought) is if a
> board does it explicitly?

So there's two parts to it. As a framework, the option needs to be
select'd, not implied. It doesn't make sense to disable the event
framework and then wonder why VBE doesn't work. The next part however is

Fixes: c5ef2025579e ("dm: fix DM_EVENT dependencies")

should have been part of it too. That commit turned all of the platforms
which had imply DM_EVENT (and so from DM_EVENT, imply EVENT) in to
depends on EVENT being set, and if it wasn't set (or select'd, only
EFI_LOADER was select'ing it at the time) in to not enabling DM_EVENT,
and since imply options can be off, no warnings were thrown by the build
system. And since all of the non-dynamic EVENT stuff is linker-based,
no binary size changes happened either.

-- 
Tom


signature.asc
Description: PGP signature


Re: [PATCH 2/2] event: Correct dependencies on the EVENT framework

2023-01-15 Thread Fabio Estevam
Hi Tom,

On Sat, Jan 14, 2023 at 5:50 PM Tom Rini  wrote:
>
> The event framework is just that, a framework. Enabling it by itself
> does nothing, so we shouldn't ask the user about it. Reword (and correct
> typos) around this the option and help text. This also applies to
> DM_EVENT, so reword as well.
>
> With this, it's time to address the larger problems. When functionality
> uses events, typically via EVENT_SPY, the appropriate framework then
> must be select'd and NOT imply'd. As the functionality will cease to
> work (and so, platforms will fail to boot) this is non-optional and
> where select is appropriate. Audit the current users of EVENT_SPY to
> have a more fine-grained approach to select'ing the framework where
> used.
>
> Cc: Simon Glass 
> Reported-by: Oliver Graute 
> Reported-by: Francesco Dolcini 
> Fixes: 7fe32b3442f0 ("event: Convert arch_cpu_init_dm() to use events")
> Fixes: 42fdcebf859f ("event: Convert misc_init_f() to use events")
> Signed-off-by: Tom Rini 

Thanks for investigating and providing a proper fix:

Reviewed-by: Fabio Estevam 


[PATCH 1/1] doc: man-page for bdinfo

2023-01-15 Thread Heinrich Schuchardt
Provide a man-page for the bdinfo command

Signed-off-by: Heinrich Schuchardt 
---
 doc/usage/cmd/bdinfo.rst | 119 +++
 doc/usage/index.rst  |   1 +
 2 files changed, 120 insertions(+)
 create mode 100644 doc/usage/cmd/bdinfo.rst

diff --git a/doc/usage/cmd/bdinfo.rst b/doc/usage/cmd/bdinfo.rst
new file mode 100644
index 00..6b3cde2ccb
--- /dev/null
+++ b/doc/usage/cmd/bdinfo.rst
@@ -0,0 +1,119 @@
+.. SPDX-License-Identifier: GPL-2.0+
+.. Copyright 2023, Heinrich Schuchardt 
+
+bdinfo command
+==
+
+Synopsis
+
+
+::
+
+bdinfo
+
+Description
+---
+
+The *bdinfo* command prints information about the board.
+
+Example
+===
+
+::
+
+=> bdinfo
+boot_params = 0x
+DRAM bank   = 0x
+-> start= 0x4000
+-> size = 0x0001
+flashstart  = 0x
+flashsize   = 0x0400
+flashoffset = 0x000e87f8
+baudrate= 115200 bps
+relocaddr   = 0x00013fefb000
+reloc off   = 0x00013fefb000
+Build   = 64-bit
+current eth = virtio-net#32
+ethaddr = 52:52:52:52:52:52
+IP addr = 10.0.2.15
+fdt_blob= 0x00013edbadb0
+new_fdt = 0x00013edbadb0
+fdt_size= 0x0010
+lmb_dump_all:
+ memory.cnt  = 0x1
+ memory[0]  [0x4000-0x13fff], 0x1 bytes flags: 0
+ reserved.cnt  = 0x2
+ reserved[0][0x13ddb3000-0x13fff], 0x0224d000 bytes flags: 0
+ reserved[1][0x13edb6930-0x13fff], 0x012496d0 bytes flags: 0
+devicetree  = board
+arch_number = 0x
+TLB addr= 0x00013fff
+irq_sp  = 0x00013edbada0
+sp start= 0x00013edbada0
+Early malloc usage: 3a8 / 2000
+=>
+
+boot_params
+address of the memory area for boot parameters
+
+DRAM bank
+index, start address and end address of a memory bank
+
+baudrate
+baud rate of the serial console
+
+relocaddr
+address to which U-Boot has relocated itself
+
+reloc off
+relocation offset, difference between *relocaddr* and the text base
+
+Build
+bitness of the system
+
+current eth
+name of the active network device
+
+IP addr
+network address, value of the environment variable *ipaddr*
+
+fdt_blob
+address of U-Boot's own device tree, NULL if none
+
+new_fdt
+location of the relocated device tree
+
+fdt_size
+space reserved for relocated device space
+
+lmb_dump_all
+available memory and memory reservations
+
+devicetree
+source of the device-tree
+
+arch_number
+unique id for the board
+
+TLB addr
+address of the translation lookaside buffer
+
+irq_sp
+address of the IRQ stack pointer
+
+sp start
+initial stack pointer address
+
+Early malloc usage
+amount of memory used in the early malloc memory and its maximum size
+as defined by CONFIGSYS_MALLOC_F_LEN
+
+Configuration
+-
+
+The bdinfo command is available if CONFIG_CMD_BDI=y.
+
+Return code
+---
+
+The return code $? is 0 (true).
diff --git a/doc/usage/index.rst b/doc/usage/index.rst
index 707e3116be..8dfc79a0ca 100644
--- a/doc/usage/index.rst
+++ b/doc/usage/index.rst
@@ -23,6 +23,7 @@ Shell commands
cmd/addrmap
cmd/askenv
cmd/base
+   cmd/bdinfo
cmd/blkcache
cmd/bootd
cmd/bootdev
-- 
2.38.1



[PATCH 1/1] doc: man-page for blkcache

2023-01-15 Thread Heinrich Schuchardt
Provide a man-page for the blkcache command.

Signed-off-by: Heinrich Schuchardt 
---
 doc/usage/cmd/blkcache.rst | 74 ++
 doc/usage/index.rst|  1 +
 2 files changed, 75 insertions(+)
 create mode 100644 doc/usage/cmd/blkcache.rst

diff --git a/doc/usage/cmd/blkcache.rst b/doc/usage/cmd/blkcache.rst
new file mode 100644
index 00..6409f20f31
--- /dev/null
+++ b/doc/usage/cmd/blkcache.rst
@@ -0,0 +1,74 @@
+.. SPDX-License-Identifier: GPL-2.0+
+.. Copyright 2023, Heinrich Schuchardt 
+
+blkcache command
+
+
+Synopsis
+
+
+::
+
+blkcache show
+blkcache configure  
+
+Description
+===
+
+The *blkcache* command is used to control the size of the block cache and to
+display statistics.
+
+The block cache buffers data read from block devices. This speeds up the access
+to file-systems.
+
+show
+show and reset statistics
+
+configure
+set the maximum number of cache entries and the maximum number of blocks 
per
+entry
+
+blocks
+maximum number of blocks per cache entry. The block size is device 
specific.
+The initial value is 8.
+
+entries
+maximum number of entries in the cche. The initial value is 32.
+
+Example
+===
+
+.. code-block::
+
+=> blkcache show
+hits: 296
+misses: 149
+entries: 7
+max blocks/entry: 8
+max cache entries: 32
+=> blkcache show
+hits: 0
+misses: 0
+entries: 7
+max blocks/entry: 8
+max cache entries: 32
+=> blkcache configure 16 64
+changed to max of 64 entries of 16 blocks each
+=> blkcache show
+hits: 0
+misses: 0
+entries: 0
+max blocks/entry: 16
+max cache entries: 64
+=>
+
+Configuration
+=
+
+The blkcache command is only available if CONFIG_CMD_BLOCK_CACHE=y.
+
+Return code
+===
+
+If the command succeeds, the return code $? is set 0 (true). In case of an
+error the return code is set to 1 (false).
diff --git a/doc/usage/index.rst b/doc/usage/index.rst
index 14457aba69..707e3116be 100644
--- a/doc/usage/index.rst
+++ b/doc/usage/index.rst
@@ -23,6 +23,7 @@ Shell commands
cmd/addrmap
cmd/askenv
cmd/base
+   cmd/blkcache
cmd/bootd
cmd/bootdev
cmd/bootefi
-- 
2.38.1



Re: [PATCH v6 1/6] rockchip: px30: fix possibly unused grf and cru variables

2023-01-15 Thread Kever Yang



On 2023/1/9 18:36, Quentin Schulz wrote:

From: Quentin Schulz 

The grf and cru are only used when no UART base is provided by the user
(defaults to UART2) or for UART1, UART3 and UART5 to be used for the
debug UART. Therefore, let's surround those variable definitions with
the proper checks.

This wasn't an issue before support for UART0 was added, because all
cases were using cru and grf. UART0 only uses pmucru so there's a need
to not define those variables anymore.

Fixes: d0af506625ff ("rockchip: px30: support debug uart on UART0")
Cc: Quentin Schulz 
Signed-off-by: Quentin Schulz 

Reviewed-by: Kever Yang 

Thanks,
- Kever

---
  arch/arm/mach-rockchip/px30/px30.c | 10 ++
  1 file changed, 10 insertions(+)

diff --git a/arch/arm/mach-rockchip/px30/px30.c 
b/arch/arm/mach-rockchip/px30/px30.c
index 0641e6af0f..35a36700df 100644
--- a/arch/arm/mach-rockchip/px30/px30.c
+++ b/arch/arm/mach-rockchip/px30/px30.c
@@ -297,8 +297,18 @@ void board_debug_uart_init(void)
CONFIG_DEBUG_UART_BASE == 0xff03)
static struct px30_pmugrf * const pmugrf = (void *)PMUGRF_BASE;
  #endif
+#if !defined(CONFIG_DEBUG_UART_BASE) || \
+   (CONFIG_DEBUG_UART_BASE != 0xff158000 && \
+CONFIG_DEBUG_UART_BASE != 0xff168000 && \
+CONFIG_DEBUG_UART_BASE != 0xff178000 && \
+CONFIG_DEBUG_UART_BASE != 0xff03) || \
+   (defined(CONFIG_DEBUG_UART_BASE) && \
+(CONFIG_DEBUG_UART_BASE == 0xff158000 || \
+ CONFIG_DEBUG_UART_BASE == 0xff168000 || \
+ CONFIG_DEBUG_UART_BASE == 0xff178000))
static struct px30_grf * const grf = (void *)GRF_BASE;
static struct px30_cru * const cru = (void *)CRU_BASE;
+#endif
  #if defined(CONFIG_DEBUG_UART_BASE) && CONFIG_DEBUG_UART_BASE == 0xff03
static struct px30_pmucru * const pmucru = (void *)PMUCRU_BASE;
  #endif