Re: verified boot (vboot) with secure U-Boot env for SWUpdate

2021-03-20 Thread Stefano Babic

Hi Tim,

On 19.03.21 19:40, Tim Harvey wrote:

On Fri, Mar 19, 2021 at 10:17 AM Stefano Babic  wrote:


Hi Tim,

On 19.03.21 16:50, Tim Harvey wrote:

Greetings,

I'm looking at using SWUpdate to facilitate an A/B ping-pong method of
firmware updates where a state is stored in U-Boot env by the SWUpdate
postinst script.


You do not need a postinstall script, yoiu just add the environment to
the "bootenv" section in sw-description.


I'm using the postinst script to determine the root partition and
write it, so there is some intelligence there. The generic
instructions I put together to demonstrate this setup are at
http://trac.gateworks.com/wiki/buildroot#SWUpdate which likely
explains best what I'm doing.


If this can help...

Your setup forbids streaming (installed-directly = true for each 
artifact), and the images are first extracted into /tmp before installing.


If this can help, I have recently exported a global "getroot" lua 
function that can be called from sw-description.








I'm needing to use secure boot with U-Boot's verified boot support and
am not clear how, if at all, the U-Boot env can be authenticated.

Is there any authentication support within a flash stored U-boot
environment that is supported by fw_setenv and if not what is the
recommendation for removing environment and are there any other
suggestions for an SWUpdate postinstall script to select the OS image
to boot after an update?


There is no authentication in U-Boot - I supposed to add a signed
environment to U-Boot, but then U-Boot won't be able save the env
because a "saveenv" requires a private key.

The current solution is to use CONFIG_ENV_WRITEABLE_LIST. You have a
short list (I use just one) of variables that are allowed to be changed,
while the complete environment is added via CONFIG_EXTRA_ENV and,
because it is linked to u-boot, is signed as well. If you set your
script to depend on just one variable to select if A or B can run, you
can be sure that the rest of environment cannot be compromised. You
should also set flags for the variable to be sure that it is not changed
to be a script (just integer are accepted).


Thanks - I was not aware of this feature. This looks like it would work well.

So for my case I'm toggling 'mmcbootpart' from a '2' to a '3' in
postinst so I suppose in U-Boot I would:
CONFIG_ENV_WRITEABLE_LIST=y
CONFIG_ENV_FLAGS_LIST_DEFAULT=mmcbootpart:d

and make sure my compiled in env a minimal bootcmd that uses
mmcbootpart as the only variable.

when CONFIG_ENV_WRITEABLE_LIST=y do all other env vars defined in
built-in-env get automatically flagged as non-writable?


Yes, only variables in the list can be modified.



and regardless of what modifications are done to the flash backed env
(via something like fw_setenv for example) are the only vars that get
merged into the runtime env hashtable those defined in
CONFIG_ENV_FLAGS_LIST_DEFAULT?


Right - you can write whatever you want via SWUpdate or fw_setenv, but 
U-Boot takes just the variables in the list and discards the other ones.






Another solution is to use CONFIG_ENV_EMBEDDED and to switch via the
ssbl_hanlder in SWUpdate. Anyway, support for this easy "switcher" is
not present in U-Boot and should be added. This left the whole
environment untouched, and the selection between A/B is done via an
external structure.


Sounds like your previous solution works well enough.



Best regards,
Stefano


Pull request efi-2021-04-rc5-2

2021-03-20 Thread Heinrich Schuchardt

Dear Tom,

The following changes since commit e3310c21a43c1e3c004c6b53ee9179420a1be375:

  Merge tag 'video-for-v2021.04' of
https://source.denx.de/u-boot/custodians/u-boot-video (2021-03-19
08:20:19 -0400)

are available in the Git repository at:

  https://source.denx.de/u-boot/custodians/u-boot-efi.git
tags/efi-2021-04-rc5-2

for you to fetch changes up to 76b0a19022e22a5bbb84cd76d516bdb625a70417:

  cmd/load: support uploading EFI binary via UART (2021-03-19 20:54:55
+0100)

Gitlab CI showed no problems:
https://source.denx.de/u-boot/custodians/u-boot-efi/-/pipelines/6836


Pull request efi-2021-04-rc5-2

Bug fixes:

* re-enable loading UEFI binaries via UART
* fix a NULL dereference in EFI console


Heinrich Schuchardt (3):
  efi_loader: NULL dereference in EFI console
  efi_loader: Uart device path
  cmd/load: support uploading EFI binary via UART

 cmd/load.c   | 10 +--
 include/efi_api.h| 10 +++
 lib/efi_loader/efi_console.c | 51

 lib/efi_loader/efi_device_path.c | 41 +++--
 lib/efi_loader/efi_device_path_to_text.c | 13 
 5 files changed, 101 insertions(+), 24 deletions(-)


Re: [PATCH] Fix data abort in startup for at91 machines based on ARM926EJS

2021-03-20 Thread Martin Townsend
Hi Eugen,

It didn't work I'm afraid.  I took a look at the code and I don't think the 
stack is available, in start.S we have the following for the reset vector:

reset:
/*
* set the cpu to SVC32 mode
*/
mrs r0,cpsr
bic r0,r0,#0x1f
orr r0,r0,#0xd3
msr cpsr,r0

/*
* we do sys-critical inits only at reboot,
* not when booting from ram!
*/
#ifndef CONFIG_SKIP_LOWLEVEL_INIT
bl cpu_init_crit
#endif

bl _main

cpu_init_crit calls lowlevel_init but the stack is not setup until _main is 
executed

ENTRY(_main)

/*
 * Set up initial C runtime environment and call board_init_f(0).
 */

#if defined(CONFIG_TPL_BUILD) && defined(CONFIG_TPL_NEEDS_SEPARATE_STACK)
ldr r0, =(CONFIG_TPL_STACK)
#elif defined(CONFIG_SPL_BUILD) && defined(CONFIG_SPL_STACK)
ldr r0, =(CONFIG_SPL_STACK)
#else
ldr r0, =(CONFIG_SYS_INIT_SP_ADDR)
#endif
bic r0, r0, #7 /* 8-byte alignment for ABI compliance */
mov sp, r0

which kind of makes sense as the lowlevel_init will initialise the SDRAM that 
the stack requires.








From: eugen.hris...@microchip.com 
Sent: 19 March 2021 06:49
To: Martin Townsend ; u-boot@lists.denx.de 

Cc: albert.u.b...@aribaud.net ; 
nicolas.fe...@microchip.com 
Subject: Re: [PATCH] Fix data abort in startup for at91 machines based on 
ARM926EJS

Yes, please, try like this, continue to use r4 as it was done initially,
but save r4 to stack and restore before returning. Let's see if this
solution works for you.
I will wait for your v2 of the patch.

Thanks !
Eugen

On 3/18/21 10:31 PM, Martin Townsend wrote:
> Hi Eugen,
>
> Pop and push gets my vote as it future proofs the code from usage of r6
> in lowlevel_init.  Let me know if you want me to respin the patch with
> this and test it out on my board here.
>
> Kind regards
>
> Martin
>
> *Martin Townsend**| *Embedded Software Engineer**
>
> _mar...@rufilla.com _
>
>
> **
>
> **
>
> *W***_http://www.rufilla.com _
>
> *T*+44 (0)1865 601201
>
> *A*Building D5 | Culham Science Centre | Abingdon, UK | OX14 3DB
>
> rufilla_logo_transparent 
>
> Rufilla Ltd is a company registered in England and Wales, No. 7093478.
>   Registered address : 6a St Andrew’s Court, Wellington Street, Thame,
> Oxfordshire, OX9 3WT, United Kingdom.  Rufilla Ltd cannot guarantee
> e-mail transmission to be secure or error-free as information could be
> intercepted, corrupted, lost, destroyed, arrive late or incomplete, or
> contain viruses. The sender therefore does not accept any liability
> whatsoever for any errors or omissions in the contents of this message
> or that arises from any data corruption, interception or unauthorised
> amendment, whether or not these arise as a result of the e-mail
> transmission. The information on which this communication is based has
> been obtained from sources we believe to be reliable, but we do not
> guarantee its accuracy or completeness. All expressions of opinion are
> subject to change without notice.  This email may contain confidential
> information and as such, should be treated as confidential. It may also
> contain legally privileged information. It is intended solely for use by
> the normal or ordinary user of the e-mail address to which it has been
> addressed. If you are not the named addressee of this e-mail you are
> prohibited from disseminating, distributing, amending, copying or
> otherwise acting on the contents, including any attachments, of this
> e-mail. Please notify the sender immediately by e-mail if you have
> received this e-mail in error and immediately delete this e-mail from
> your system. You may be asked to confirm that the e-mail received in
> error has been deleted from your system and/or that you have not made
> any unauthorised use, disclosure, distribution or copy of the e-mail.
> Rufilla Ltd is a VAT registered company No.131363252.
>
> Any and all communications sent to us may be monitored and/or stored by
> us to ensure compliance with relevant legislation, rules, and policies.
> All communications are handled in full compliance with current data
> protection legislation including, but not limited to, EU Regulation
> 2016/679 General Data Protection Regulation (“GDPR”).  For further
> information, please refer to our _Privacy Policy
> _
>
> 
>
>
> 
> *From:* eugen.hris...@microchip.com 
> *Sent:* 18 March 2021 16:53
> *To:* Martin Townsend ; u-boot@lists.denx.de
> 
> *Cc:* albert.u.b...@aribaud.net ;
> nicolas.fe...@microchip.com 
> *Subject:* Re: [PATCH] Fix data abort in startup for at91 machines based
> on ARM926EJS
> Hello Martin,
>
> I reviewed things a bit,

[PATCH] riscv: assembler versions of memcpy, memmove, memset

2021-03-20 Thread Heinrich Schuchardt
Provide optimized versions of memcpy(), memmove(), memset() copied from
the Linux kernel.

Signed-off-by: Heinrich Schuchardt 
---
 arch/riscv/Kconfig  |  78 ++
 arch/riscv/include/asm/string.h |  36 +-
 arch/riscv/lib/Makefile |   5 ++
 arch/riscv/lib/memcpy.S | 108 ++
 arch/riscv/lib/memmove.S|  64 ++
 arch/riscv/lib/memset.S | 113 
 6 files changed, 383 insertions(+), 21 deletions(-)
 create mode 100644 arch/riscv/lib/memcpy.S
 create mode 100644 arch/riscv/lib/memmove.S
 create mode 100644 arch/riscv/lib/memset.S

diff --git a/arch/riscv/Kconfig b/arch/riscv/Kconfig
index 55eaee2da6..7d0bd73ce2 100644
--- a/arch/riscv/Kconfig
+++ b/arch/riscv/Kconfig
@@ -271,4 +271,82 @@ config STACK_SIZE_SHIFT
 config OF_BOARD_FIXUP
default y if OF_SEPARATE && RISCV_SMODE

+config USE_ARCH_MEMCPY
+   bool "Use an assembly optimized implementation of memcpy"
+   default y
+   help
+ Enable the generation of an optimized version of memcpy.
+ Such an implementation may be faster under some conditions
+ but may increase the binary size.
+
+config SPL_USE_ARCH_MEMCPY
+   bool "Use an assembly optimized implementation of memcpy for SPL"
+   default y if USE_ARCH_MEMCPY
+   depends on SPL
+   help
+ Enable the generation of an optimized version of memcpy.
+ Such an implementation may be faster under some conditions
+ but may increase the binary size.
+
+config TPL_USE_ARCH_MEMCPY
+   bool "Use an assembly optimized implementation of memcpy for TPL"
+   default y if USE_ARCH_MEMCPY
+   depends on TPL
+   help
+ Enable the generation of an optimized version of memcpy.
+ Such an implementation may be faster under some conditions
+ but may increase the binary size.
+
+config USE_ARCH_MEMMOVE
+   bool "Use an assembly optimized implementation of memmove"
+   default y
+   help
+ Enable the generation of an optimized version of memmove.
+ Such an implementation may be faster under some conditions
+ but may increase the binary size.
+
+config SPL_USE_ARCH_MEMMOVE
+   bool "Use an assembly optimized implementation of memmove for SPL"
+   default y if USE_ARCH_MEMCPY
+   depends on SPL
+   help
+ Enable the generation of an optimized version of memmove.
+ Such an implementation may be faster under some conditions
+ but may increase the binary size.
+
+config TPL_USE_ARCH_MEMMOVE
+   bool "Use an assembly optimized implementation of memmove for TPL"
+   default y if USE_ARCH_MEMCPY
+   depends on TPL
+   help
+ Enable the generation of an optimized version of memmove.
+ Such an implementation may be faster under some conditions
+ but may increase the binary size.
+
+config USE_ARCH_MEMSET
+   bool "Use an assembly optimized implementation of memset"
+   default y
+   help
+ Enable the generation of an optimized version of memset.
+ Such an implementation may be faster under some conditions
+ but may increase the binary size.
+
+config SPL_USE_ARCH_MEMSET
+   bool "Use an assembly optimized implementation of memset for SPL"
+   default y if USE_ARCH_MEMSET
+   depends on SPL
+   help
+ Enable the generation of an optimized version of memset.
+ Such an implementation may be faster under some conditions
+ but may increase the binary size.
+
+config TPL_USE_ARCH_MEMSET
+   bool "Use an assembly optimized implementation of memset for TPL"
+   default y if USE_ARCH_MEMSET
+   depends on TPL
+   help
+ Enable the generation of an optimized version of memset.
+ Such an implementation may be faster under some conditions
+ but may increase the binary size.
+
 endmenu
diff --git a/arch/riscv/include/asm/string.h b/arch/riscv/include/asm/string.h
index 0fc3424a2f..7dee3e4c9f 100644
--- a/arch/riscv/include/asm/string.h
+++ b/arch/riscv/include/asm/string.h
@@ -19,31 +19,25 @@

 #undef __HAVE_ARCH_STRRCHR
 #undef __HAVE_ARCH_STRCHR
-#undef __HAVE_ARCH_MEMCPY
-#undef __HAVE_ARCH_MEMMOVE
 #undef __HAVE_ARCH_MEMCHR
 #undef __HAVE_ARCH_MEMZERO
-#undef __HAVE_ARCH_MEMSET

-#ifdef CONFIG_MARCO_MEMSET
-#define memset(_p, _v, _n) \
-   (typeof(_p) (p) = (_p); \
-typeof(_v) (v) = (_v); \
-typeof(_n) (n) = (_n); \
-{  \
-   if ((n) != 0) { \
-   if (__builtin_constant_p((v)) && (v) == 0)  \
-   __memzero((p), (n));\
-   else\
-   memset((p), (v), (n)); 

Re: [PATCH] imx8mn_ddr4_evk: Allow booting the kernel by default

2021-03-20 Thread Fabio Estevam
Hi Stefano and Tom,

On Thu, Mar 4, 2021 at 9:59 AM Andrey Zhizhikin  wrote:
>
> Hello Fabio,
>
> On Thu, Mar 4, 2021 at 12:07 PM Fabio Estevam  wrote:
> >
> > Currently it is not possible to boot Linux from the SD card
> > by default.
> >
> > Make the necessary adjustments to allow it.
> >
> > Reported-by: Peter Bergin 
> > Signed-off-by: Fabio Estevam 
>
> Tested-by: Andrey Zhizhikin  # imx8mn_ddr4_evk

Please consider applying this one for 2021.04 as it allows imx8mn-evk
booting Linux by default.

Thanks


Re: [PATCH v2] bus: ti-sysc: change in a normal driver

2021-03-20 Thread Tom Rini
On Sat, Mar 20, 2021 at 02:59:05PM +1300, Simon Glass wrote:
> Hi Tom,
> 
> On Sat, 20 Mar 2021 at 14:06, Tom Rini  wrote:
> >
> > On Sat, Mar 20, 2021 at 12:54:00PM +1300, Simon Glass wrote:
> > > On Sat, 20 Mar 2021 at 09:42, Tom Rini  wrote:
> > > >
> > > > On Tue, Mar 16, 2021 at 09:51:44PM +0100, Dario Binacchi wrote:
> > > >
> > > > > The module defines a duplicate uclass driver for UCLASS_SIMPLE_BUS, 
> > > > > but
> > > > > it is not allowed. This breaks of-platdata and makes the result
> > > > > non-deterministic.
> > > > >
> > > > > The driver does not need to be an uclass driver, so lets remove it. I
> > > > > had turned it into an uclass driver because I thought wrongly it had 
> > > > > to
> > > > > call the dm_scan_fdt_dev routine to work properly, but some tests on 
> > > > > the
> > > > > board have shown otherwise.
> > > > >
> > > > > Signed-off-by: Dario Binacchi 
> > > > > Reviewed-by: Simon Glass 
> > > >
> > > > Applied to u-boot/master, thanks!
> > >
> > > Also applied to u-boot-dm/next, thanks!
> >
> > Well, wait, no, why?  -rc5 will get merged to -next in time I hope.  Is
> > this going to block other work in dm/next?
> 
> Ah I'm about to send a pull request which fails without this. I can
> hold off if you like?

Ah, OK.  git should do the right thing in the end, I hope.  I'll do a
quick local test to confirm once you send me the PR.

-- 
Tom


signature.asc
Description: PGP signature


Re: Pull request efi-2021-04-rc5-2

2021-03-20 Thread Tom Rini
On Sat, Mar 20, 2021 at 11:06:18AM +0100, Heinrich Schuchardt wrote:

> Dear Tom,
> 
> The following changes since commit e3310c21a43c1e3c004c6b53ee9179420a1be375:
> 
>   Merge tag 'video-for-v2021.04' of
> https://source.denx.de/u-boot/custodians/u-boot-video (2021-03-19
> 08:20:19 -0400)
> 
> are available in the Git repository at:
> 
>   https://source.denx.de/u-boot/custodians/u-boot-efi.git
> tags/efi-2021-04-rc5-2
> 
> for you to fetch changes up to 76b0a19022e22a5bbb84cd76d516bdb625a70417:
> 
>   cmd/load: support uploading EFI binary via UART (2021-03-19 20:54:55
> +0100)
> 
> Gitlab CI showed no problems:
> https://source.denx.de/u-boot/custodians/u-boot-efi/-/pipelines/6836
> 

Applied to u-boot/master, thanks!

-- 
Tom


signature.asc
Description: PGP signature


Re: [PATCH] imx8mn_ddr4_evk: Allow booting the kernel by default

2021-03-20 Thread Stefano Babic

Hi Fabio,

On 20.03.21 15:05, Fabio Estevam wrote:

Hi Stefano and Tom,

On Thu, Mar 4, 2021 at 9:59 AM Andrey Zhizhikin  wrote:


Hello Fabio,

On Thu, Mar 4, 2021 at 12:07 PM Fabio Estevam  wrote:


Currently it is not possible to boot Linux from the SD card
by default.

Make the necessary adjustments to allow it.

Reported-by: Peter Bergin 
Signed-off-by: Fabio Estevam 


Tested-by: Andrey Zhizhikin  # imx8mn_ddr4_evk


Please consider applying this one for 2021.04 as it allows imx8mn-evk
booting Linux by default.



Thanks for fixing it. I pick it up for release.

Stefano


Thanks



Please pull u-boot-dm/next into -next

2021-03-20 Thread Simon Glass
Hi Tom,

This is for the -next branch, mostly the of-platdata-inst implementation.

https://source.denx.de/u-boot/custodians/u-boot-dm/-/pipelines/6844


The following changes since commit f879f2621b42529cf5f88912a07d2866cfc8fd45:

  Merge branch 'next' of git://source.denx.de/u-boot-sh into next
(2021-03-19 08:20:34 -0400)

are available in the Git repository at:

  git://git.denx.de/u-boot-dm.git tags/dm-pull-21mar21

for you to fetch changes up to 4fd57aeeb4359268f0d70a04ad7769985789ab8c:

  binman: Update various pieces of the documentation (2021-03-20 12:55:54
+1300)


dtoc support for of-platdata-inst
driver model support for of-platdata-inst
support of-platdata-inst on x86 / coral
binman support for exapanded entries
binman convert docs to reST
ti-sysc fix for duplicate uclass driver
patman minor improvements


Bin Meng (3):
  mmc: pci: Fix Kconfig dependency
  test: cmd: setexpr: Fix a typo
  test: print_ut: Fix potential build error

Dario Binacchi (1):
  bus: ti-sysc: change in a normal driver

Heinrich Schuchardt (4):
  sandbox: allow cross-compiling sandbox
  sandbox: enable cros-ec-keyb in test.dtb
  dm: error handling dev_get_dma_range()
  sandbox: add FAT to the list of usable env drivers

Marek Behún (1):
  regmap: fix a serious pointer casting bug

Nicolas Boichat (1):
  patman: Use less for help file, if available

Samuel Dionne-Riel (1):
  tools: fdtgrep: Use unsigned chars for arrays

Simon Glass (103):
  patman: Update documentation to match new usage
  patman: Quieten down the alias checking
  dtoc: Scan drivers for available information
  dtoc: Save scan information across test runs
  dtoc: Ignore unwanted files when scanning for drivers
  dtoc: Collect priv/plat struct info from drivers
  dtoc: Support scanning of uclasses
  dtoc: Support scanning of structs in header files
  dtoc: Move test files into a test/ directory
  dtoc: Rename sandbox_i2c_test and sandbox_pmic_test
  dtoc: Add some extra properties to nodes
  dtoc: Make use of node properties
  dtoc: Process nodes to set up required properties
  dtoc: Track nodes which are actually used
  dtoc: Support tracking the phase of U-Boot
  Makefile: Pass the U-Boot phase to dtoc
  dtoc: Support headers needed for drivers
  dtoc: Process driver aliases along with drivers
  dtoc: Warn of duplicate drivers
  dtoc: Read aliases for uclasses
  dtoc: Detect drivers only at the start of start of line
  dtoc: Assign a sequence number to each node
  dtoc: Set up the uclasses that are used
  dtoc: Support processing the root node
  dtoc: Add an option for device instantiation
  dm: of-platadata: Add option for device instantiation
  dtoc: Add support for decl file
  dtoc: Don't generate platform data with instantiation
  sandbox: Make sandbox,emul more conventional
  sandbox: i2c: Rename driver names to work with of-platdata
  dtoc: Tidy up the list of supported phandle properties
  dtoc: Generate a summary in the dt-plat.c file
  dtoc: Generate uclass devices
  dtoc: Generate device instances
  dtoc: Drop use of DECL() macros
  sandbox: Drop debug message in os_spl_to_uboot()
  linker_lists: Allow use in data structures
  dm: core: Add macros to access the new linker lists
  dm: core: Allow dropping run-time binding of devices
  dm: core: Adjust uclass setup with of-platdata
  dm: core: Set up driver model for OF_PLATDATA_INST
  dm: core: Skip adding uclasses with OF_PLATDATA_INST
  dm: Add the new dtoc-generated files to the build
  dm: core: Include dt-decl.h automatically
  dm: test: Avoid destroying uclasses with of-platdata-inst
  clk: sandbox: Move priv/plat data to a header file
  clk: fixed-rate: Export driver parts for OF_PLATDATA_INST
  clk: sandbox: Create a special fixed-rate driver
  dm: core: Drop device_get_by_driver_info()
  dm: core: Drop uclass_find_device_by_phandle() with of-platdata
  sandbox: i2c: Move platdata structs to header files
  dm: Rename device_get_by_driver_info_idx()
  sandbox_spl: Increase SPL malloc() size
  sandbox: i2c: Support i2c emulation with of-platdata
  Revert "sandbox: Disable I2C emulators in SPL"
  sandbox: Create a new sandbox_noinst build
  test: Run sandbox_spl tests on sandbox_noinst
  azure/gitlab: Add tests for sandbox_noinst
  dm: core: Add an option to support SPL in read-only memory
  dm: core: Create a struct for device runtime info
  dm: core: Move flags to device-runtime info
  dm: core: Allow storing priv/plat data separately
  sandbox: Define a region for device priv/plat data
  dm: core: Use separate priv/plat data region
  dm: core: Add warnings to priva

[PATCH] Rockchip board with DWC3 controller may lead to usb init function declared twice

2021-03-20 Thread Janpieter Sollie
diff --git a/arch/arm/mach-rockchip/board.c b/arch/arm/mach-rockchip/board.c
index c386b529..11866e6e 100644
--- a/arch/arm/mach-rockchip/board.c
+++ b/arch/arm/mach-rockchip/board.c
@@ -67,7 +67,7 @@ static struct dwc2_plat_otg_data otg_data = {
.tx_fifo_sz = 128,
 };

-int board_usb_init(int index, enum usb_init_type init)
+static int __board_usb_init(int index, enum usb_init_type init)
 {
ofnode node;
const char *mode;
@@ -151,6 +151,13 @@ int board_usb_init(int index, enum usb_init_type init)
 }
 #endif /* CONFIG_USB_DWC3_GADGET */

+#else
+int board_usb_init(int index, enum usb_init_type init)
+{
+   return __board_usb_init(&dwc3_device_data);
+}
+
+
 #endif /* CONFIG_USB_GADGET */

 #if CONFIG_IS_ENABLED(FASTBOOT)


[PATCH] Support building on macOS/arm64

2021-03-20 Thread Jessica Clarke
On Arm-based Macs, -no_pie is ignored and gives a linker warning.
Moreover, the build falls over with:

  ld: Absolute addressing not allowed in arm64 code but used in 
'_image_type_ptr_aisimage' referencing '_image_type_aisimage'

for dumpimage and mkimage, since we put data structs in text sections
not data sections and so cannot have dynamic relocations. Instead, move
the sections to __DATA and drop disabling PIE.

Signed-off-by: Jessica Clarke 
---
 Makefile  | 5 -
 tools/imagetool.h | 4 ++--
 2 files changed, 2 insertions(+), 7 deletions(-)

diff --git a/Makefile b/Makefile
index 3ebb38b113..df3354d9f8 100644
--- a/Makefile
+++ b/Makefile
@@ -324,11 +324,6 @@ HOSTCC   = $(call os_x_before, 10, 5, "cc", "gcc")
 KBUILD_HOSTCFLAGS  += $(call os_x_before, 10, 4, "-traditional-cpp")
 KBUILD_HOSTLDFLAGS += $(call os_x_before, 10, 5, "-multiply_defined suppress")
 
-# since Lion (10.7) ASLR is on by default, but we use linker generated lists
-# in some host tools which is a problem then ... so disable ASLR for these
-# tools
-KBUILD_HOSTLDFLAGS += $(call os_x_before, 10, 7, "", "-Xlinker -no_pie")
-
 # macOS Mojave (10.14.X) 
 # Undefined symbols for architecture x86_64: "_PyArg_ParseTuple"
 KBUILD_HOSTLDFLAGS += $(call os_x_after, 10, 14, "-lpython -dynamclib", "")
diff --git a/tools/imagetool.h b/tools/imagetool.h
index 8726792c8c..2801ea9e9f 100644
--- a/tools/imagetool.h
+++ b/tools/imagetool.h
@@ -273,14 +273,14 @@ int rockchip_copy_image(int fd, struct image_tool_params 
*mparams);
 
 #define INIT_SECTION(name)  do {   \
unsigned long name ## _len; \
-   char *__cat(pstart_, name) = getsectdata("__TEXT",  \
+   char *__cat(pstart_, name) = getsectdata("__DATA",  \
#name, &__cat(name, _len)); \
char *__cat(pstop_, name) = __cat(pstart_, name) +  \
__cat(name, _len);  \
__cat(__start_, name) = (void *)__cat(pstart_, name);   \
__cat(__stop_, name) = (void *)__cat(pstop_, name); \
} while (0)
-#define SECTION(name)   __attribute__((section("__TEXT, " #name)))
+#define SECTION(name)   __attribute__((section("__DATA, " #name)))
 
 struct image_type_params **__start_image_type, **__stop_image_type;
 #else
-- 
2.31.0



Re: Please pull u-boot-dm/next into -next

2021-03-20 Thread Marek Behún
Simon,

you forgot to drop my regmap patch.

Marek


Re: [PATCH 1/3] board: mediatek: rename pumpkin board into mt8516

2021-03-20 Thread Tom Rini
On Mon, Feb 15, 2021 at 07:07:44PM +0100, Fabien Parent wrote:

> More than one pumpkin board has been made with different MediaTek SoCs.
> Rename the pumpkin board to follow the naming convention of all
> other MediaTek boards and also to not be confusing when other pumpkin
> boards will be added in follow-up commits.
> 
> Signed-off-by: Fabien Parent 

Applied to u-boot/next, thanks!

-- 
Tom


signature.asc
Description: PGP signature


Re: [PATCH 2/3] board: mediatek: mt8516: init USB Ether for pumpkin board

2021-03-20 Thread Tom Rini
On Mon, Feb 15, 2021 at 07:07:45PM +0100, Fabien Parent wrote:

> Init USB Ether if CONFIG_USB_ETHER is enabled.
> 
> Signed-off-by: Fabien Parent 

Applied to u-boot/next, thanks!

-- 
Tom


signature.asc
Description: PGP signature


Re: [PATCH 3/3] configs: mt8516: use bootcmd from config_distro_bootcmd.h

2021-03-20 Thread Tom Rini
On Mon, Feb 15, 2021 at 07:07:46PM +0100, Fabien Parent wrote:

> Instead of redefining our own way to boot, let's just use
> config_distro_bootcmd.h.
> 
> Signed-off-by: Fabien Parent 

Applied to u-boot/next, thanks!

-- 
Tom


signature.asc
Description: PGP signature


Re: [PATCH 1/2] ARM: mediatek: Add MT8183 support

2021-03-20 Thread Tom Rini
On Mon, Feb 15, 2021 at 07:21:11PM +0100, Fabien Parent wrote:

> Add the MT8183 SoC support.
> 
> Signed-off-by: Fabien Parent 

Applied to u-boot/next, thanks!

-- 
Tom


signature.asc
Description: PGP signature


Re: [PATCH 2/2] board: Add MT8183 pumpkin board support

2021-03-20 Thread Tom Rini
On Mon, Feb 15, 2021 at 07:21:12PM +0100, Fabien Parent wrote:

> Add the MT8183 pumpkin board support.
> 
> Signed-off-by: Fabien Parent 

Applied to u-boot/next, thanks!

-- 
Tom


signature.asc
Description: PGP signature


Re: [PATCH 1/4] pinctrl: mediatek: fix wrong assignment in mtk_get_pin_name

2021-03-20 Thread Tom Rini
On Fri, Mar 05, 2021 at 10:22:11AM +0800, Weijie Gao wrote:

> From: Sam Shih 
> 
> This is a bug fix for mtk pinctrl common part. Appearently pins should be
> used instead of grps in mtk_get_pin_name().
> 
> Signed-off-by: Sam Shih 

Applied to u-boot/next, thanks!

-- 
Tom


signature.asc
Description: PGP signature


Re: [PATCH 2/4] pinctrl: mediatek: add get_pin_muxing ops for mediatek pinctrl

2021-03-20 Thread Tom Rini
On Fri, Mar 05, 2021 at 10:22:19AM +0800, Weijie Gao wrote:

> From: Sam Shih 
> 
> This patch add get_pin_muxing support for mediatek pinctrl drivers
> 
> Signed-off-by: Sam Shih 

Applied to u-boot/next, thanks!

-- 
Tom


signature.asc
Description: PGP signature


Re: [PATCH 3/4] pinctrl: mediatek: do not probe gpio driver if not enabled

2021-03-20 Thread Tom Rini
On Fri, Mar 05, 2021 at 10:22:26AM +0800, Weijie Gao wrote:

> The mtk pinctrl driver is a combination driver with support for both
> pinctrl and gpio. When this driver is used in SPL, gpio support may not be
> enabled, and this will result in a compilation error.
> 
> To fix this, macros are added to make sure gpio related code will only be
> compiled when gpio support is enabled.
> 
> Signed-off-by: Weijie Gao 

Applied to u-boot/next, thanks!

-- 
Tom


signature.asc
Description: PGP signature


Re: [PATCH 4/4] pinctrl: mt7629: add jtag function and pin group

2021-03-20 Thread Tom Rini
On Fri, Mar 05, 2021 at 10:22:31AM +0800, Weijie Gao wrote:

> The EPHY LEDs of mt7629 can be used as JTAG. This patch adds the jtag pin
> group to the pinctrl driver.
> 
> Signed-off-by: Weijie Gao 

Applied to u-boot/next, thanks!

-- 
Tom


signature.asc
Description: PGP signature


Re: [PATCH] configs: mt7622: use ARMv8 Generic Timer instead of mtk_timer

2021-03-20 Thread Tom Rini
On Fri, Mar 05, 2021 at 10:24:58AM +0800, Weijie Gao wrote:

> It's better to use the generic timer which is correctly initialized by
> the ATF. The generic timer has higher resolution than the mtk_timer.
> 
> Signed-off-by: Weijie Gao 

Applied to u-boot/next, thanks!

-- 
Tom


signature.asc
Description: PGP signature


Re: [PATCH] dts: mt7629: enable JTAG pins by default

2021-03-20 Thread Tom Rini
On Fri, Mar 05, 2021 at 10:27:46AM +0800, Weijie Gao wrote:

> The EPHY LEDs belongs to the built-in FE switch of MT7629, which is barely
> used. These LED pins on reference boards are used as JTAG socket. So it's
> a good idea to change the default state to JTAG, and this will make it
> convenience for debugging.
> 
> Signed-off-by: Weijie Gao 

Applied to u-boot/next, thanks!

-- 
Tom


signature.asc
Description: PGP signature


Re: [PATCH] serial: mtk: rewrite the setbrg function

2021-03-20 Thread Tom Rini
On Fri, Mar 05, 2021 at 10:35:39AM +0800, Weijie Gao wrote:

> Currently the setbrg logic of serial-mtk is messy, and should be rewritten.
> Also an option is added to make it possible to use highspeed-3 mode for all
> bauds.
> 
> The new logic is:
> 1. If baud clock > 12MHz
>a) If baud <= 115200, highspeed-0 mode will be used (ns16550 compatible)
>b) If baud <= 576000, highspeed-2 mode will be used
>c) any bauds > 576000, highspeed-3 mode will be used
> 2. If baud clock <= 12MHz
>Forced highspeed-3 mode
>a) If baud <= 115200, calculates the divisor using DIV_ROUND_CLOSEST
>b) any bauds > 115200, the same as 1. c)
> 
> Signed-off-by: Weijie Gao 

Applied to u-boot/next, thanks!

-- 
Tom


signature.asc
Description: PGP signature


Re: [PATCH] board: mt7629: enable compression of u-boot to reduce the size of final image

2021-03-20 Thread Tom Rini
On Fri, Mar 05, 2021 at 10:39:55AM +0800, Weijie Gao wrote:

> This patch makes use of the decompression mechanism implemented for mt7628
> previously to reduce the total image size. Binman will be also removed.
> 
> Signed-off-by: Weijie Gao 

Applied to u-boot/next, thanks!

-- 
Tom


signature.asc
Description: PGP signature


Re: [PATCH] configs: mt7622: enable debug uart for mt7622_rfb_defconfig

2021-03-20 Thread Tom Rini
On Fri, Mar 05, 2021 at 10:41:33AM +0800, Weijie Gao wrote:
> Enable debug uart for mt7622_rfb_defconfig

> 
> Signed-off-by: Weijie Gao 

Applied to u-boot/next, thanks!

-- 
Tom


signature.asc
Description: PGP signature


Re: [PATCH] tools: mtk_image: add an option to set device header offset

2021-03-20 Thread Tom Rini
On Tue, Mar 09, 2021 at 03:52:31PM +0800, Weijie Gao wrote:

> This patch adds an option which allows setting the device header offset.
> This is useful if this tool is used to generate ATF BL2 image of mt7622 for
> SD cards.
> 
> Signed-off-by: Weijie Gao 

Applied to u-boot/next, thanks!

-- 
Tom


signature.asc
Description: PGP signature


Re: Please pull u-boot-dm/next into -next

2021-03-20 Thread Simon Glass
Hi Marek,

On Sun, 21 Mar 2021 at 12:21, Marek Behún  wrote:
>
> Simon,
>
> you forgot to drop my regmap patch.

Ah yes, I dropped it from dm/master, but left it in -next. I am hoping
that git will figure it out as that is what it is supposed to be good
at :-)

Regards,
Simon
>
>


Re: Please pull u-boot-dm/next into -next

2021-03-20 Thread Bin Meng
Hi Simon,

On Sun, Mar 21, 2021 at 8:21 AM Simon Glass  wrote:
>
> Hi Marek,
>
> On Sun, 21 Mar 2021 at 12:21, Marek Behún  wrote:
> >
> > Simon,
> >
> > you forgot to drop my regmap patch.
>
> Ah yes, I dropped it from dm/master, but left it in -next. I am hoping
> that git will figure it out as that is what it is supposed to be good
> at :-)

The thing is that that patch you applied has some issues, and Marek
has sent an updated correct patch.

Regards,
Bin


Re: Please pull u-boot-dm/next into -next

2021-03-20 Thread Simon Glass
Hi Bin,

On Sun, 21 Mar 2021 at 14:16, Bin Meng  wrote:
>
> Hi Simon,
>
> On Sun, Mar 21, 2021 at 8:21 AM Simon Glass  wrote:
> >
> > Hi Marek,
> >
> > On Sun, 21 Mar 2021 at 12:21, Marek Behún  wrote:
> > >
> > > Simon,
> > >
> > > you forgot to drop my regmap patch.
> >
> > Ah yes, I dropped it from dm/master, but left it in -next. I am hoping
> > that git will figure it out as that is what it is supposed to be good
> > at :-)
>
> The thing is that that patch you applied has some issues, and Marek
> has sent an updated correct patch.

Oh dear...

Tom shall I redo the pull request?

Regards,
Simon


Re: Please pull u-boot-dm/next into -next

2021-03-20 Thread Tom Rini
On Sun, Mar 21, 2021 at 02:18:40PM +1300, Simon Glass wrote:
> Hi Bin,
> 
> On Sun, 21 Mar 2021 at 14:16, Bin Meng  wrote:
> >
> > Hi Simon,
> >
> > On Sun, Mar 21, 2021 at 8:21 AM Simon Glass  wrote:
> > >
> > > Hi Marek,
> > >
> > > On Sun, 21 Mar 2021 at 12:21, Marek Behún  wrote:
> > > >
> > > > Simon,
> > > >
> > > > you forgot to drop my regmap patch.
> > >
> > > Ah yes, I dropped it from dm/master, but left it in -next. I am hoping
> > > that git will figure it out as that is what it is supposed to be good
> > > at :-)
> >
> > The thing is that that patch you applied has some issues, and Marek
> > has sent an updated correct patch.
> 
> Oh dear...
> 
> Tom shall I redo the pull request?

Yes, thanks.

-- 
Tom


signature.asc
Description: PGP signature


Please pull u-boot-dm/next take 2

2021-03-20 Thread Simon Glass
Hi Tom,

This is for the -next branch

https://source.denx.de/u-boot/custodians/u-boot-dm/-/pipelines/6849


The following changes since commit f879f2621b42529cf5f88912a07d2866cfc8fd45:

  Merge branch 'next' of git://source.denx.de/u-boot-sh into next
(2021-03-19 08:20:34 -0400)

are available in the Git repository at:

  git://git.denx.de/u-boot-dm.git tags/dm-pull-21mar21-take2

for you to fetch changes up to 72f2592b113815039000e9b295a2ea6f2e9d4f2f:

  binman: Update various pieces of the documentation (2021-03-21 14:30:48 +1300)


dtoc support for of-platdata-inst
driver model support for of-platdata-inst
support of-platdata-inst on x86 / coral
binman support for exapanded entries
binman convert docs to reST
ti-sysc fix for duplicate uclass driver
patman minor improvements


Bin Meng (3):
  mmc: pci: Fix Kconfig dependency
  test: cmd: setexpr: Fix a typo
  test: print_ut: Fix potential build error

Dario Binacchi (1):
  bus: ti-sysc: change in a normal driver

Heinrich Schuchardt (4):
  sandbox: allow cross-compiling sandbox
  sandbox: enable cros-ec-keyb in test.dtb
  dm: error handling dev_get_dma_range()
  sandbox: add FAT to the list of usable env drivers

Nicolas Boichat (1):
  patman: Use less for help file, if available

Samuel Dionne-Riel (1):
  tools: fdtgrep: Use unsigned chars for arrays

Simon Glass (103):
  patman: Update documentation to match new usage
  patman: Quieten down the alias checking
  dtoc: Scan drivers for available information
  dtoc: Save scan information across test runs
  dtoc: Ignore unwanted files when scanning for drivers
  dtoc: Collect priv/plat struct info from drivers
  dtoc: Support scanning of uclasses
  dtoc: Support scanning of structs in header files
  dtoc: Move test files into a test/ directory
  dtoc: Rename sandbox_i2c_test and sandbox_pmic_test
  dtoc: Add some extra properties to nodes
  dtoc: Make use of node properties
  dtoc: Process nodes to set up required properties
  dtoc: Track nodes which are actually used
  dtoc: Support tracking the phase of U-Boot
  Makefile: Pass the U-Boot phase to dtoc
  dtoc: Support headers needed for drivers
  dtoc: Process driver aliases along with drivers
  dtoc: Warn of duplicate drivers
  dtoc: Read aliases for uclasses
  dtoc: Detect drivers only at the start of start of line
  dtoc: Assign a sequence number to each node
  dtoc: Set up the uclasses that are used
  dtoc: Support processing the root node
  dtoc: Add an option for device instantiation
  dm: of-platadata: Add option for device instantiation
  dtoc: Add support for decl file
  dtoc: Don't generate platform data with instantiation
  sandbox: Make sandbox,emul more conventional
  sandbox: i2c: Rename driver names to work with of-platdata
  dtoc: Tidy up the list of supported phandle properties
  dtoc: Generate a summary in the dt-plat.c file
  dtoc: Generate uclass devices
  dtoc: Generate device instances
  dtoc: Drop use of DECL() macros
  sandbox: Drop debug message in os_spl_to_uboot()
  linker_lists: Allow use in data structures
  dm: core: Add macros to access the new linker lists
  dm: core: Allow dropping run-time binding of devices
  dm: core: Adjust uclass setup with of-platdata
  dm: core: Set up driver model for OF_PLATDATA_INST
  dm: core: Skip adding uclasses with OF_PLATDATA_INST
  dm: Add the new dtoc-generated files to the build
  dm: core: Include dt-decl.h automatically
  dm: test: Avoid destroying uclasses with of-platdata-inst
  clk: sandbox: Move priv/plat data to a header file
  clk: fixed-rate: Export driver parts for OF_PLATDATA_INST
  clk: sandbox: Create a special fixed-rate driver
  dm: core: Drop device_get_by_driver_info()
  dm: core: Drop uclass_find_device_by_phandle() with of-platdata
  sandbox: i2c: Move platdata structs to header files
  dm: Rename device_get_by_driver_info_idx()
  sandbox_spl: Increase SPL malloc() size
  sandbox: i2c: Support i2c emulation with of-platdata
  Revert "sandbox: Disable I2C emulators in SPL"
  sandbox: Create a new sandbox_noinst build
  test: Run sandbox_spl tests on sandbox_noinst
  azure/gitlab: Add tests for sandbox_noinst
  dm: core: Add an option to support SPL in read-only memory
  dm: core: Create a struct for device runtime info
  dm: core: Move flags to device-runtime info
  dm: core: Allow storing priv/plat data separately
  sandbox: Define a region for device priv/plat data
  dm: core: Use separate priv/plat data region
  dm: core: Add warnings to private / platform setters
  dm: doc: Tidy up of-platdata docs
  dm: doc: Add documentation for of-pla

[PATCH 0/6] Use -ENOSYS consistently

2021-03-20 Thread Simon Glass
A few places use -ENOTSUPP when they should use -ENOSYS. In two cases both
are used. This little series tidies this up.


Simon Glass (6):
  usb: Return -ENOSYS when system call is not available
  spi: Return -ENOSYS when system call is not available
  tlv_eeprom: Return -ENOSYS when system call is not available
  clk: Return -ENOSYS when system call is not available
  simple-pm-bus: Use -ENOSYS for checking missing system call
  pinctrl: Return -ENOSYS when system call is not available

 drivers/clk/clk-composite.c |  8 
 drivers/core/simple-pm-bus.c|  4 ++--
 drivers/pinctrl/pinctrl-uclass.c| 10 ++
 drivers/usb/gadget/udc/udc-uclass.c |  2 +-
 include/spi-mem.h   |  2 +-
 include/tlv_eeprom.h|  6 +++---
 6 files changed, 17 insertions(+), 15 deletions(-)

-- 
2.31.0.rc2.261.g7f71774620-goog



[PATCH 1/6] usb: Return -ENOSYS when system call is not available

2021-03-20 Thread Simon Glass
Update usb_gadget_release() to use -ENOSYS, which is the correct error
code for U-Boot.

Signed-off-by: Simon Glass 
---

 drivers/usb/gadget/udc/udc-uclass.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/usb/gadget/udc/udc-uclass.c 
b/drivers/usb/gadget/udc/udc-uclass.c
index 3053ccf7d97..dbc354e84f9 100644
--- a/drivers/usb/gadget/udc/udc-uclass.c
+++ b/drivers/usb/gadget/udc/udc-uclass.c
@@ -45,7 +45,7 @@ int usb_gadget_release(int index)
dev_array[index] = NULL;
return ret;
 #else
-   return -ENOTSUPP;
+   return -ENOSYS;
 #endif
 }
 
-- 
2.31.0.rc2.261.g7f71774620-goog



[PATCH 3/6] tlv_eeprom: Return -ENOSYS when system call is not available

2021-03-20 Thread Simon Glass
When CMD_TLV_EEPROM is not enabled, use -ENOSYS, which is the correct
error code for U-Boot.

Signed-off-by: Simon Glass 
---

 include/tlv_eeprom.h | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/include/tlv_eeprom.h b/include/tlv_eeprom.h
index 1de2fe2337c..a2c333e7446 100644
--- a/include/tlv_eeprom.h
+++ b/include/tlv_eeprom.h
@@ -114,19 +114,19 @@ int read_tlvinfo_tlv_eeprom(void *eeprom, struct 
tlvinfo_header **hdr,
 
 static inline int read_tlv_eeprom(void *eeprom, int offset, int len, int dev)
 {
-   return -ENOTSUPP;
+   return -ENOSYS;
 }
 
 static inline int write_tlv_eeprom(void *eeprom, int len)
 {
-   return -ENOTSUPP;
+   return -ENOSYS;
 }
 
 static inline int
 read_tlvinfo_tlv_eeprom(void *eeprom, struct tlvinfo_header **hdr,
struct tlvinfo_tlv **first_entry, int dev)
 {
-   return -ENOTSUPP;
+   return -ENOSYS;
 }
 
 #endif /* CONFIG_IS_ENABLED(CMD_TLV_EEPROM) */
-- 
2.31.0.rc2.261.g7f71774620-goog



[PATCH 5/6] simple-pm-bus: Use -ENOSYS for checking missing system call

2021-03-20 Thread Simon Glass
We don't need to check -ENOTSUPP since this is not used for this purpose
in U-Boot. Update the code accordingly.

Signed-off-by: Simon Glass 
---

 drivers/core/simple-pm-bus.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/core/simple-pm-bus.c b/drivers/core/simple-pm-bus.c
index 7a18953cba1..1bb0d86e289 100644
--- a/drivers/core/simple-pm-bus.c
+++ b/drivers/core/simple-pm-bus.c
@@ -21,7 +21,7 @@ static int simple_pm_bus_probe(struct udevice *dev)
return ret;
 
ret = clk_enable_bulk(bulk);
-   if (ret && ret != -ENOSYS && ret != -ENOTSUPP) {
+   if (ret && ret != -ENOSYS) {
clk_release_bulk(bulk);
return ret;
}
@@ -34,7 +34,7 @@ static int simple_pm_bus_remove(struct udevice *dev)
struct clk_bulk *bulk = dev_get_priv(dev);
 
ret = clk_release_bulk(bulk);
-   if (ret && ret != -ENOSYS && ret != -ENOTSUPP)
+   if (ret && ret != -ENOSYS)
return ret;
else
return 0;
-- 
2.31.0.rc2.261.g7f71774620-goog



[PATCH 2/6] spi: Return -ENOSYS when system call is not available

2021-03-20 Thread Simon Glass
Update spi_controller_dma_map_mem_op_data() to use -ENOSYS, which is the
correct error code for U-Boot.

Signed-off-by: Simon Glass 
---

 include/spi-mem.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/include/spi-mem.h b/include/spi-mem.h
index 8be3e2bf6b5..e354c388979 100644
--- a/include/spi-mem.h
+++ b/include/spi-mem.h
@@ -222,7 +222,7 @@ spi_controller_dma_map_mem_op_data(struct spi_controller 
*ctlr,
   const struct spi_mem_op *op,
   struct sg_table *sg)
 {
-   return -ENOTSUPP;
+   return -ENOSYS;
 }
 
 static inline void
-- 
2.31.0.rc2.261.g7f71774620-goog



[PATCH 4/6] clk: Return -ENOSYS when system call is not available

2021-03-20 Thread Simon Glass
Update clk_composite_set_parent() to use -ENOSYS, which is the correct
error code for U-Boot. Also rearrange the code so that the error condition
is clearly indicated and the function runs to the end in the normal case,
since this is the common style in U-Boot.

Signed-off-by: Simon Glass 
---

 drivers/clk/clk-composite.c | 8 
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/clk/clk-composite.c b/drivers/clk/clk-composite.c
index 7e99c5b910d..bb5351ebc0b 100644
--- a/drivers/clk/clk-composite.c
+++ b/drivers/clk/clk-composite.c
@@ -37,10 +37,10 @@ static int clk_composite_set_parent(struct clk *clk, struct 
clk *parent)
const struct clk_ops *mux_ops = composite->mux_ops;
struct clk *mux = composite->mux;
 
-   if (mux && mux_ops)
-   return mux_ops->set_parent(mux, parent);
-   else
-   return -ENOTSUPP;
+   if (!mux || !mux_ops)
+   return -ENOSYS;
+
+   return mux_ops->set_parent(mux, parent);
 }
 
 static unsigned long clk_composite_recalc_rate(struct clk *clk)
-- 
2.31.0.rc2.261.g7f71774620-goog



[PATCH 6/6] pinctrl: Return -ENOSYS when system call is not available

2021-03-20 Thread Simon Glass
Update the code to use -ENOSYS, which is the correct error code for an
unimplemented system call in U-Boot.

Also we should not check for a missing operations array as this is not
permitted. For now this can be covered by an assert().

Signed-off-by: Simon Glass 
---

 drivers/pinctrl/pinctrl-uclass.c | 10 ++
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/drivers/pinctrl/pinctrl-uclass.c b/drivers/pinctrl/pinctrl-uclass.c
index b0f30aa1f75..6e68e52c32c 100644
--- a/drivers/pinctrl/pinctrl-uclass.c
+++ b/drivers/pinctrl/pinctrl-uclass.c
@@ -235,8 +235,9 @@ int pinctrl_gpio_request(struct udevice *dev, unsigned 
offset)
return ret;
 
ops = pinctrl_get_ops(pctldev);
-   if (!ops || !ops->gpio_request_enable)
-   return -ENOTSUPP;
+   assert(ops);
+   if (!ops->gpio_request_enable)
+   return -ENOSYS;
 
return ops->gpio_request_enable(pctldev, pin_selector);
 }
@@ -261,8 +262,9 @@ int pinctrl_gpio_free(struct udevice *dev, unsigned offset)
return ret;
 
ops = pinctrl_get_ops(pctldev);
-   if (!ops || !ops->gpio_disable_free)
-   return -ENOTSUPP;
+   assert(ops);
+   if (!ops->gpio_disable_free)
+   return -ENOSYS;
 
return ops->gpio_disable_free(pctldev, pin_selector);
 }
-- 
2.31.0.rc2.261.g7f71774620-goog



[PATCH v5 0/2] x86: Minor improvements mostly for image loading

2021-03-20 Thread Simon Glass
This series provides a few improvements for loading of images. It also
provides a way to show more detailed model information as well as an
of-platdata fix noticed recently.

Note that this series depends on the GPIO series here:

   http://patchwork.ozlabs.org/project/uboot/list/?series=226118

Changes in v5:
- Rebase to upstream/next

Changes in v4:
- Rebase to x86/master (but will not build until GPIO series lands)
- Update cover letter

Changes in v3:
- Rebase to master
- Rebase to master
- Drop patches previously applied

Changes in v2:
- Fix two missing asterisks in comments

Simon Glass (2):
  sysinfo: Allow showing model info from sysinfo
  x86: coral: Show memory config and SKU ID on startup

 arch/x86/dts/chromebook_coral.dts |  11 ++
 board/google/chromebook_coral/coral.c | 139 +-
 board/google/chromebook_coral/variant_gpio.h  |   6 -
 common/board_info.c   |  37 -
 .../sysinfo/google,coral.txt  |  37 +
 include/sysinfo.h |   4 +
 6 files changed, 212 insertions(+), 22 deletions(-)
 create mode 100644 doc/device-tree-bindings/sysinfo/google,coral.txt

-- 
2.31.0.rc2.261.g7f71774620-goog



[PATCH v5 1/2] sysinfo: Allow showing model info from sysinfo

2021-03-20 Thread Simon Glass
Some boards may want to show the SKU ID or other information obtained at
runtime. Allow this to come from sysinfo. The board can then provide a
sysinfo driver to provide it.

Signed-off-by: Simon Glass 
Reviewed-by: Bin Meng 
---

(no changes since v3)

Changes in v3:
- Rebase to master

 common/board_info.c | 37 +
 include/sysinfo.h   |  4 
 2 files changed, 33 insertions(+), 8 deletions(-)

diff --git a/common/board_info.c b/common/board_info.c
index b54aa30a944..1cfe34f7067 100644
--- a/common/board_info.c
+++ b/common/board_info.c
@@ -1,31 +1,52 @@
 // SPDX-License-Identifier: GPL-2.0+
 
 #include 
+#include 
 #include 
+#include 
 #include 
 #include 
 #include 
 
+DECLARE_GLOBAL_DATA_PTR;
+
 int __weak checkboard(void)
 {
return 0;
 }
 
 /*
- * If the root node of the DTB has a "model" property, show it.
+ * Check sysinfo for board information. Failing that if the root node of the 
DTB
+ * has a "model" property, show it.
+ *
  * Then call checkboard().
  */
 int __weak show_board_info(void)
 {
-#ifdef CONFIG_OF_CONTROL
-   DECLARE_GLOBAL_DATA_PTR;
-   const char *model;
+   if (IS_ENABLED(CONFIG_OF_CONTROL)) {
+   struct udevice *dev;
+   const char *model;
+   char str[80];
+   int ret = -ENOSYS;
+
+   if (IS_ENABLED(CONFIG_SYSINFO)) {
+   /* This might provide more detail */
+   ret = uclass_first_device_err(UCLASS_SYSINFO, &dev);
+   if (!ret)
+   ret = sysinfo_get_str(dev,
+ SYSINFO_ID_BOARD_MODEL,
+ sizeof(str), str);
+   }
 
-   model = fdt_getprop(gd->fdt_blob, 0, "model", NULL);
+   /* Fail back to the main 'model' if available */
+   if (ret)
+   model = fdt_getprop(gd->fdt_blob, 0, "model", NULL);
+   else
+   model = str;
 
-   if (model)
-   printf("Model: %s\n", model);
-#endif
+   if (model)
+   printf("Model: %s\n", model);
+   }
 
return checkboard();
 }
diff --git a/include/sysinfo.h b/include/sysinfo.h
index 270ac1b377f..68fad25a065 100644
--- a/include/sysinfo.h
+++ b/include/sysinfo.h
@@ -37,9 +37,13 @@ struct udevice;
 enum sysinfo_id {
SYSINFO_ID_NONE,
 
+   /* For SMBIOS tables */
SYSINFO_ID_SMBIOS_SYSTEM_VERSION,
SYSINFO_ID_SMBIOS_BASEBOARD_VERSION,
 
+   /* For show_board_info() */
+   SYSINFO_ID_BOARD_MODEL,
+
/* First value available for downstream/board used */
SYSINFO_ID_USER = 0x1000,
 };
-- 
2.31.0.rc2.261.g7f71774620-goog



[PATCH v5 2/2] x86: coral: Show memory config and SKU ID on startup

2021-03-20 Thread Simon Glass
Provide the model information through sysinfo so that it shows up on
boot. For memconfig 4 pins are provided, for 16 combinations. For SKU
ID there are two options:

   - two pins provided in a ternary arrangement, for 9 combinations.
   - reading from the EC

Add a binding doc and drop the unused #defines as well.

Example:

   U-Boot 2021.01-rc5

   CPU:   Intel(R) Celeron(R) CPU N3450 @ 1.10GHz
   DRAM:  3.9 GiB
   MMC:   sdmmc@1b,0: 1, emmc@1c,0: 2
   Video: 1024x768x32 @ b000
   Model: Google Coral (memconfig 5, SKU 3)

This depends on the GPIO series:

   http://patchwork.ozlabs.org/project/uboot/list/?series=228126

Signed-off-by: Simon Glass 

Acked-by: Bin Meng 
---

Changes in v5:
- Rebase to upstream/next

Changes in v4:
- Rebase to x86/master (but will not build until GPIO series lands)
- Update cover letter

Changes in v3:
- Rebase to master
- Drop patches previously applied

Changes in v2:
- Fix two missing asterisks in comments

 arch/x86/dts/chromebook_coral.dts |  11 ++
 board/google/chromebook_coral/coral.c | 139 +-
 board/google/chromebook_coral/variant_gpio.h  |   6 -
 .../sysinfo/google,coral.txt  |  37 +
 4 files changed, 179 insertions(+), 14 deletions(-)
 create mode 100644 doc/device-tree-bindings/sysinfo/google,coral.txt

diff --git a/arch/x86/dts/chromebook_coral.dts 
b/arch/x86/dts/chromebook_coral.dts
index 2ffe3b423c3..18bbafe5981 100644
--- a/arch/x86/dts/chromebook_coral.dts
+++ b/arch/x86/dts/chromebook_coral.dts
@@ -55,6 +55,17 @@
recovery-gpios = <&gpio_nw (-1) GPIO_ACTIVE_LOW>;
write-protect-gpios = <&gpio_nw GPIO_75 GPIO_ACTIVE_HIGH>;
phase-enforce-gpios = <&gpio_n GPIO_10 GPIO_ACTIVE_HIGH>;
+   memconfig-gpios = <&gpio_nw GPIO_101 GPIO_ACTIVE_HIGH
+   &gpio_nw GPIO_102 GPIO_ACTIVE_HIGH
+   &gpio_n GPIO_38 GPIO_ACTIVE_HIGH
+   &gpio_n GPIO_45 GPIO_ACTIVE_HIGH>;
+
+   /*
+* This is used for reef only:
+*
+* skuconfig-gpios = <&gpio_nw GPIO_16 GPIO_ACTIVE_HIGH
+*  &gpio_nw GPIO_17 GPIO_ACTIVE_HIGH>;
+*/
smbios {
/* Type 1 table */
system {
diff --git a/board/google/chromebook_coral/coral.c 
b/board/google/chromebook_coral/coral.c
index f9fb3f163f0..77a6cca4497 100644
--- a/board/google/chromebook_coral/coral.c
+++ b/board/google/chromebook_coral/coral.c
@@ -3,9 +3,12 @@
  * Copyright 2019 Google LLC
  */
 
+#define LOG_CATEGORY   UCLASS_SYSINFO
+
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -15,6 +18,7 @@
 #include 
 #include 
 #include 
+#include 
 #include "variant_gpio.h"
 
 struct cros_gpio_info {
@@ -29,10 +33,125 @@ int arch_misc_init(void)
return 0;
 }
 
-/* This function is needed if CONFIG_CMDLINE is not enabled */
-int board_run_command(const char *cmdline)
+static int get_memconfig(struct udevice *dev)
 {
-   printf("No command line\n");
+   struct gpio_desc gpios[4];
+   int cfg;
+   int ret;
+
+   ret = gpio_request_list_by_name(dev, "memconfig-gpios", gpios,
+   ARRAY_SIZE(gpios),
+   GPIOD_IS_IN | GPIOD_PULL_UP);
+   if (ret < 0) {
+   log_debug("Cannot get GPIO list '%s' (%d)\n", dev->name, ret);
+   return ret;
+   }
+
+   /* Give the lines time to settle */
+   udelay(10);
+
+   ret = dm_gpio_get_values_as_int(gpios, ARRAY_SIZE(gpios));
+   if (ret < 0)
+   return log_msg_ret("get", ret);
+   cfg = ret;
+
+   ret = gpio_free_list(dev, gpios, ARRAY_SIZE(gpios));
+   if (ret)
+   return log_msg_ret("free", ret);
+
+   return cfg;
+}
+
+/**
+ * get_skuconfig() - Get the SKU number either from pins or the EC
+ *
+ * Two options are supported:
+ * skuconfig-gpios - two pins in the device tree (tried first)
+ * EC  - reading from the EC (backup)
+ *
+ * @dev: sysinfo device to use
+ * @return SKU ID, or -ve error if not found
+ */
+static int get_skuconfig(struct udevice *dev)
+{
+   struct gpio_desc gpios[2];
+   int cfg;
+   int ret;
+
+   ret = gpio_request_list_by_name(dev, "skuconfig-gpios", gpios,
+   ARRAY_SIZE(gpios),
+   GPIOD_IS_IN);
+   if (ret != ARRAY_SIZE(gpios)) {
+   struct udevice *cros_ec;
+
+   log_debug("Cannot get GPIO list '%s' (%d)\n", dev->name, ret);
+
+   /* Try the EC */
+   ret = uclass_first_device_err(UCLASS_CROS_EC, &cros_ec);
+   if (ret < 0) {
+   log_err("Cannot find EC for SKU details\n");
+   return log_msg_ret("sku", ret);
+   }
+   ret = c

Re: [PATCH v4 2/2] x86: coral: Show memory config and SKU ID on startup

2021-03-20 Thread Simon Glass
Hi Bin,

On Mon, 15 Mar 2021 at 18:30, Simon Glass  wrote:
>
> Hi Bin,
>
> On Tue, 9 Mar 2021 at 15:34, Bin Meng  wrote:
> >
> > Hi Simon,
> >
> > On Sun, Feb 7, 2021 at 12:13 AM Simon Glass  wrote:
> > >
> > > Provide the model information through sysinfo so that it shows up on
> > > boot. For memconfig 4 pins are provided, for 16 combinations. For SKU
> > > ID there are two options:
> > >
> > >- two pins provided in a ternary arrangement, for 9 combinations.
> > >- reading from the EC
> > >
> > > Add a binding doc and drop the unused #defines as well.
> > >
> > > Example:
> > >
> > >U-Boot 2021.01-rc5
> > >
> > >CPU:   Intel(R) Celeron(R) CPU N3450 @ 1.10GHz
> > >DRAM:  3.9 GiB
> > >MMC:   sdmmc@1b,0: 1, emmc@1c,0: 2
> > >Video: 1024x768x32 @ b000
> > >Model: Google Coral (memconfig 5, SKU 3)
> > >
> > > This depends on the GPIO series:
> > >
> > >http://patchwork.ozlabs.org/project/uboot/list/?series=228126
> >
> > It looks this series is applied as patchwork returns nothing?
> >
> > But the CI still fails
> > https://source.denx.de/u-boot/custodians/u-boot-x86/-/jobs/235619
>
> Can you apply it to u-boot-x86/next perhaps? The GPIO series was
> applied to -next, not -master.

I've sent a new version, v5, which should apply on the U-Boot -next
branch. Are you keeping a -next for x86? If not I am happy to apply it
via dm.

Regards,
Simon


Re: [PATCH 1/6] usb: Return -ENOSYS when system call is not available

2021-03-20 Thread Marek Vasut

On 3/21/21 4:18 AM, Simon Glass wrote:

Update usb_gadget_release() to use -ENOSYS, which is the correct error
code for U-Boot.


It would be good if you could explain _why_ this change is required. Why 
is ENOSYS the correct return value ? It is not clear from the patch 
description, sorry.


Re: [PATCH 1/6] usb: Return -ENOSYS when system call is not available

2021-03-20 Thread Simon Glass
Hi Marek,

On Sun, 21 Mar 2021 at 17:09, Marek Vasut  wrote:
>
> On 3/21/21 4:18 AM, Simon Glass wrote:
> > Update usb_gadget_release() to use -ENOSYS, which is the correct error
> > code for U-Boot.
>
> It would be good if you could explain _why_ this change is required. Why
> is ENOSYS the correct return value ? It is not clear from the patch
> description, sorry.

That is the value used throughout driver model, so it is a convention.
As per the cover letter and one on the patches, people are not sure
which one to use, because -ENOTSUPP has crept in in a few places.

Regards,
Simon


[PATCH v6 0/2] gpio: Update and simplify the uclass API

2021-03-20 Thread Simon Glass
At present the GPIO uclass mirrors what was in U-Boot before driver model.
It works well in most cases but is becoming cumbersome with things like
pull-up/down and drive strength. In those cases it is easier for the
driver to deal with all the flags at one, rather than piece by piece.

In fact the current API does not officially have a method for adjusting
anything other than the direction flags. While set_dir_flags() and
get_dir_flags() do in fact support changing other flags, this is not
documented.

Secondly, set_dir_flags actually ORs the current flags with the new ones
so it is not possible to clear flags. It seems better to use a clr/set
interface (bit clear followed by OR) to provide more flexibility.

Finally, direction_input() and direction_output() are really just the same
thing as set_dir_flags(), with a different name. We currently use the
latter if available, failing back to the former. But it makes sense to
deprecate the old methods.

This series makes the above changes. Existing drivers are mostly left
alone, since they should continue to operate as is. The sandbox driver is
updated to add the required new tests and the x86 driver is switched over
to the new API.

The STM32 driver should be checked to make sure the open source/open drain
features still work as intended.

Changes in v6:
- Use dm_gpio_clrset_flags() so that direction can be changed
- Simplify the code since masking is not needed

Changes in v5:
- Drop patches previously applied

Simon Glass (2):
  gpio: i2c-gpio: Drop use of dm_gpio_set_dir()
  gpio: Drop dm_gpio_set_dir()

 drivers/gpio/gpio-uclass.c | 11 ---
 drivers/i2c/i2c-gpio.c | 19 +--
 include/asm-generic/gpio.h | 11 ---
 3 files changed, 9 insertions(+), 32 deletions(-)

-- 
2.31.0.rc2.261.g7f71774620-goog



[PATCH v6 1/2] gpio: i2c-gpio: Drop use of dm_gpio_set_dir()

2021-03-20 Thread Simon Glass
This is the only driver that uses this function. Update it to use the
alternative which is dm_gpio_set_dir_flags().

Signed-off-by: Simon Glass 
---

Changes in v6:
- Use dm_gpio_clrset_flags() so that direction can be changed
- Simplify the code since masking is not needed

 drivers/i2c/i2c-gpio.c | 19 +--
 1 file changed, 9 insertions(+), 10 deletions(-)

diff --git a/drivers/i2c/i2c-gpio.c b/drivers/i2c/i2c-gpio.c
index a301a4460b3..cf8f8f40359 100644
--- a/drivers/i2c/i2c-gpio.c
+++ b/drivers/i2c/i2c-gpio.c
@@ -48,12 +48,13 @@ static int i2c_gpio_sda_get(struct i2c_gpio_bus *bus)
 static void i2c_gpio_sda_set(struct i2c_gpio_bus *bus, int bit)
 {
struct gpio_desc *sda = &bus->gpios[PIN_SDA];
+   ulong flags;
 
if (bit)
-   sda->flags = (sda->flags & ~GPIOD_IS_OUT) | GPIOD_IS_IN;
+   flags = GPIOD_IS_IN;
else
-   sda->flags = (sda->flags & (~GPIOD_IS_IN & 
~GPIOD_IS_OUT_ACTIVE)) | GPIOD_IS_OUT;
-   dm_gpio_set_dir(sda);
+   flags = GPIOD_IS_OUT;
+   dm_gpio_clrset_flags(sda, GPIOD_MASK_DIR, flags);
 }
 
 static void i2c_gpio_scl_set(struct i2c_gpio_bus *bus, int bit)
@@ -62,16 +63,14 @@ static void i2c_gpio_scl_set(struct i2c_gpio_bus *bus, int 
bit)
int count = 0;
 
if (bit) {
-   scl->flags = (scl->flags & ~GPIOD_IS_OUT) | GPIOD_IS_IN;
-   dm_gpio_set_dir(scl);
+   dm_gpio_clrset_flags(scl, GPIOD_MASK_DIR, GPIOD_IS_IN);
while (!dm_gpio_get_value(scl) && count++ < 10)
udelay(1);
 
if (!dm_gpio_get_value(scl))
pr_err("timeout waiting on slave to release scl\n");
} else {
-   scl->flags = (scl->flags & (~GPIOD_IS_IN & 
~GPIOD_IS_OUT_ACTIVE)) | GPIOD_IS_OUT;
-   dm_gpio_set_dir(scl);
+   dm_gpio_clrset_flags(scl, GPIOD_MASK_DIR, GPIOD_IS_OUT);
}
 }
 
@@ -79,11 +78,11 @@ static void i2c_gpio_scl_set(struct i2c_gpio_bus *bus, int 
bit)
 static void i2c_gpio_scl_set_output_only(struct i2c_gpio_bus *bus, int bit)
 {
struct gpio_desc *scl = &bus->gpios[PIN_SCL];
-   scl->flags = (scl->flags & (~GPIOD_IS_IN & ~GPIOD_IS_OUT_ACTIVE)) | 
GPIOD_IS_OUT;
+   ulong flags = GPIOD_IS_OUT;
 
if (bit)
-   scl->flags |= GPIOD_IS_OUT_ACTIVE;
-   dm_gpio_set_dir(scl);
+   flags |= GPIOD_IS_OUT_ACTIVE;
+   dm_gpio_clrset_flags(scl, GPIOD_MASK_DIR, flags);
 }
 
 static void i2c_gpio_write_bit(struct i2c_gpio_bus *bus, int delay, uchar bit)
-- 
2.31.0.rc2.261.g7f71774620-goog



[PATCH v6 2/2] gpio: Drop dm_gpio_set_dir()

2021-03-20 Thread Simon Glass
This function is not used. Drop it.

Signed-off-by: Simon Glass 
Reviewed-by: Patrick Delaunay 
---

(no changes since v5)

Changes in v5:
- Drop patches previously applied

 drivers/gpio/gpio-uclass.c | 11 ---
 include/asm-generic/gpio.h | 11 ---
 2 files changed, 22 deletions(-)

diff --git a/drivers/gpio/gpio-uclass.c b/drivers/gpio/gpio-uclass.c
index f24db87ef06..e4e7f58c39a 100644
--- a/drivers/gpio/gpio-uclass.c
+++ b/drivers/gpio/gpio-uclass.c
@@ -713,17 +713,6 @@ int dm_gpio_set_dir_flags(struct gpio_desc *desc, ulong 
flags)
return dm_gpio_clrset_flags(desc, GPIOD_MASK_DIR, flags);
 }
 
-int dm_gpio_set_dir(struct gpio_desc *desc)
-{
-   int ret;
-
-   ret = check_reserved(desc, "set_dir");
-   if (ret)
-   return ret;
-
-   return _dm_gpio_set_flags(desc, desc->flags);
-}
-
 int dm_gpios_clrset_flags(struct gpio_desc *desc, int count, ulong clr,
  ulong set)
 {
diff --git a/include/asm-generic/gpio.h b/include/asm-generic/gpio.h
index 2cb0500aec5..e33cde7abdd 100644
--- a/include/asm-generic/gpio.h
+++ b/include/asm-generic/gpio.h
@@ -706,17 +706,6 @@ int dm_gpio_get_value(const struct gpio_desc *desc);
 
 int dm_gpio_set_value(const struct gpio_desc *desc, int value);
 
-/**
- * dm_gpio_set_dir() - Set the direction for a GPIO
- *
- * This sets up the direction according to the GPIO flags: desc->flags.
- *
- * @desc:  GPIO description containing device, offset and flags,
- * previously returned by gpio_request_by_name()
- * @return 0 if OK, -ve on error
- */
-int dm_gpio_set_dir(struct gpio_desc *desc);
-
 /**
  * dm_gpio_clrset_flags() - Update flags
  *
-- 
2.31.0.rc2.261.g7f71774620-goog



Re: [PATCH 4/6] clk: Return -ENOSYS when system call is not available

2021-03-20 Thread Sean Anderson



On 3/20/21 11:18 PM, Simon Glass wrote:

Update clk_composite_set_parent() to use -ENOSYS, which is the correct
error code for U-Boot. Also rearrange the code so that the error condition
is clearly indicated and the function runs to the end in the normal case,
since this is the common style in U-Boot.

Signed-off-by: Simon Glass 
---

  drivers/clk/clk-composite.c | 8 
  1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/clk/clk-composite.c b/drivers/clk/clk-composite.c
index 7e99c5b910d..bb5351ebc0b 100644
--- a/drivers/clk/clk-composite.c
+++ b/drivers/clk/clk-composite.c
@@ -37,10 +37,10 @@ static int clk_composite_set_parent(struct clk *clk, struct 
clk *parent)
const struct clk_ops *mux_ops = composite->mux_ops;
struct clk *mux = composite->mux;
  
-	if (mux && mux_ops)

-   return mux_ops->set_parent(mux, parent);
-   else
-   return -ENOTSUPP;
+   if (!mux || !mux_ops)
+   return -ENOSYS;
+
+   return mux_ops->set_parent(mux, parent);
  }
  
  static unsigned long clk_composite_recalc_rate(struct clk *clk)




Reviewed-by: Sean Anderson 

Will this be applied to the whole clock subsystem? From what I can tell,
the clock subsystem returns ENOSYS in these situations, and drivers
return ENOTSUPP. It would be great if we could unified all these so
callers could check for one return value.

--Sean


Re: [PATCH 5/6] simple-pm-bus: Use -ENOSYS for checking missing system call

2021-03-20 Thread Sean Anderson



On 3/20/21 11:18 PM, Simon Glass wrote:

We don't need to check -ENOTSUPP since this is not used for this purpose
in U-Boot. Update the code accordingly.

Signed-off-by: Simon Glass 
---

  drivers/core/simple-pm-bus.c | 4 ++--
  1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/core/simple-pm-bus.c b/drivers/core/simple-pm-bus.c
index 7a18953cba1..1bb0d86e289 100644
--- a/drivers/core/simple-pm-bus.c
+++ b/drivers/core/simple-pm-bus.c
@@ -21,7 +21,7 @@ static int simple_pm_bus_probe(struct udevice *dev)
return ret;
  
  	ret = clk_enable_bulk(bulk);

-   if (ret && ret != -ENOSYS && ret != -ENOTSUPP) {
+   if (ret && ret != -ENOSYS) {
clk_release_bulk(bulk);
return ret;
}
@@ -34,7 +34,7 @@ static int simple_pm_bus_remove(struct udevice *dev)
struct clk_bulk *bulk = dev_get_priv(dev);
  
  	ret = clk_release_bulk(bulk);

-   if (ret && ret != -ENOSYS && ret != -ENOTSUPP)
+   if (ret && ret != -ENOSYS)
return ret;
else
return 0;



Nak. This cannot be removed until all drivers have been converted to use
-ENOSYS.

--Sean


[PATCH 00/11] binman: Enhancements to expanded entries

2021-03-20 Thread Simon Glass
At present it is not always possible to have an expanded entry as a
sibling of another node. This limitation applies in most situations where
the other node has properties which binman must update, or when other
nodes appear after the expanded entry. An example is a 'hash' node in
the same section as an expanding node, since binman must update the hash
node with the hash of the expanding node, but it cannot do this while
also inserting the expanding node.

These limitations are mostly to do with how the fdt library worked (the one
provided by dtoc). This library still uses pylibfdt directly. At some
point it would be nice to have a hierarchical (live-tree) implementation
in pylibfdt (and therefore libfdt), but this does not exist at present. It
would simplify the code in the fdt library.

This series takes the support for expanded entries a little further, allow
them to be used in nearly any situation.

Where expanded entries are not wanted in a paricular case, a new
'no-expanded' property can be used.

Another problem found in the real world is that some systems require a
particular alignment for entries. For example, Intel chips struggle to
read data from SPI flash unless it is word-aligned. This series provides
a way to specify the default alignment for all the entries in a section,
to avoid the tedium of putting this in every single entry.

Finally, the vblock implementation includes code to collect the contents of
other entries, as specified by a phandle. It happens that this doesn't work
if one of the entries is a section, e.g. an expanding entry, since (for
efficiency reasons) binman currently only calculates section contents when
performing final image assembly. This series removes this limitation. It
also creates a new 'collection' entry type, to serve as a base class for
vblock, since it is likely that this functionality will be useful for other
entry types.


Simon Glass (11):
  binman: Use a unique number for the symbols test file
  binman: Allow disabling expanding an entry
  binman: Add support for a collection of entries
  binman: Support obtaining section contents immediately
  binman: Support default alignment for sections
  dtoc: Improve internal error for Refresh()
  dtoc: Tidy up property-offset handling
  dtoc: Tweak ordering of fdt-offsets refreshing
  dtoc: Add a subnode test for multiple nodes
  dtoc: Support adding subnodes alongside existing ones
  dtoc: Add new check that offsets are correct

 tools/binman/binman.rst   | 14 +++
 tools/binman/entries.rst  | 21 -
 tools/binman/entry.py | 16 +++-
 tools/binman/etype/cbfs.py|  1 +
 tools/binman/etype/collection.py  | 67 ++
 tools/binman/etype/mkimage.py |  1 +
 tools/binman/etype/section.py | 36 ++--
 tools/binman/etype/u_boot.py  |  2 +-
 tools/binman/etype/u_boot_spl.py  |  2 +-
 tools/binman/etype/u_boot_tpl.py  |  2 +-
 tools/binman/etype/vblock.py  | 36 
 tools/binman/ftest.py | 57 +++-
 ...ymbols_nodtb.dts => 196_symbols_nodtb.dts} |  0
 tools/binman/test/197_symbols_expand.dts  | 23 +
 tools/binman/test/198_collection.dts  | 27 ++
 tools/binman/test/199_collection_section.dts  | 32 +++
 tools/binman/test/200_align_default.dts   | 30 ++
 tools/dtoc/fdt.py | 92 +++
 tools/dtoc/test/dtoc_test_simple.dts  |  4 +
 tools/dtoc/test_fdt.py| 76 ---
 20 files changed, 470 insertions(+), 69 deletions(-)
 create mode 100644 tools/binman/etype/collection.py
 rename tools/binman/test/{192_symbols_nodtb.dts => 196_symbols_nodtb.dts} 
(100%)
 create mode 100644 tools/binman/test/197_symbols_expand.dts
 create mode 100644 tools/binman/test/198_collection.dts
 create mode 100644 tools/binman/test/199_collection_section.dts
 create mode 100644 tools/binman/test/200_align_default.dts

-- 
2.31.0.rc2.261.g7f71774620-goog



[PATCH 01/11] binman: Use a unique number for the symbols test file

2021-03-20 Thread Simon Glass
Two test devicetree files currently have 192 as their unique number. Fix
this by separating them out.

Signed-off-by: Simon Glass 
---

 tools/binman/ftest.py   | 2 +-
 .../test/{192_symbols_nodtb.dts => 196_symbols_nodtb.dts}   | 0
 2 files changed, 1 insertion(+), 1 deletion(-)
 rename tools/binman/test/{192_symbols_nodtb.dts => 196_symbols_nodtb.dts} 
(100%)

diff --git a/tools/binman/ftest.py b/tools/binman/ftest.py
index 81c213a908a..34449553ca0 100644
--- a/tools/binman/ftest.py
+++ b/tools/binman/ftest.py
@@ -1377,7 +1377,7 @@ class TestFunctional(unittest.TestCase):
 
 def testSymbolsNoDtb(self):
 """Test binman can assign symbols embedded in U-Boot SPL"""
-self.checkSymbols('192_symbols_nodtb.dts',
+self.checkSymbols('196_symbols_nodtb.dts',
   U_BOOT_SPL_NODTB_DATA + U_BOOT_SPL_DTB_DATA,
   0x38)
 
diff --git a/tools/binman/test/192_symbols_nodtb.dts 
b/tools/binman/test/196_symbols_nodtb.dts
similarity index 100%
rename from tools/binman/test/192_symbols_nodtb.dts
rename to tools/binman/test/196_symbols_nodtb.dts
-- 
2.31.0.rc2.261.g7f71774620-goog



[PATCH 02/11] binman: Allow disabling expanding an entry

2021-03-20 Thread Simon Glass
At present there is a command-line flag to disable substitution of expanded
entries. Add an option to the entry node as well, so it can be controlled
at the node level.

Add a test to cover this. Fix up the comment to the checkSymbols() function
it uses, while we are here.

Signed-off-by: Simon Glass 
---

 tools/binman/binman.rst  |  7 +++
 tools/binman/entries.rst |  6 +++---
 tools/binman/entry.py|  3 ++-
 tools/binman/etype/u_boot.py |  2 +-
 tools/binman/etype/u_boot_spl.py |  2 +-
 tools/binman/etype/u_boot_tpl.py |  2 +-
 tools/binman/ftest.py| 20 ++--
 tools/binman/test/197_symbols_expand.dts | 23 +++
 8 files changed, 56 insertions(+), 9 deletions(-)
 create mode 100644 tools/binman/test/197_symbols_expand.dts

diff --git a/tools/binman/binman.rst b/tools/binman/binman.rst
index 15314d19586..28cb2e7a9c9 100644
--- a/tools/binman/binman.rst
+++ b/tools/binman/binman.rst
@@ -472,6 +472,13 @@ missing-msg:
 information about what needs to be fixed. See missing-blob-help for the
 message for each tag.
 
+no-expanded:
+By default binman substitutes entries with expanded versions if available,
+so that a `u-boot` entry type turns into `u-boot-expanded`, for example. 
The
+`--no-expanded` command-line option disables this globally. The
+`no-expanded` property disables this just for a single entry. Put the
+`no-expanded` boolean property in the node to select this behaviour.
+
 The attributes supported for images and sections are described below. Several
 are similar to those for entries.
 
diff --git a/tools/binman/entries.rst b/tools/binman/entries.rst
index f6faa15562f..1a71413f940 100644
--- a/tools/binman/entries.rst
+++ b/tools/binman/entries.rst
@@ -863,7 +863,7 @@ U-Boot can access binman symbols at runtime. See:
 in the binman README for more information.
 
 Note that this entry is automatically replaced with u-boot-expanded unless
---no-expanded is used.
+--no-expanded is used or the node has a 'no-expanded' property.
 
 
 
@@ -984,7 +984,7 @@ The ELF file 'spl/u-boot-spl' must also be available for 
this to work, since
 binman uses that to look up symbols to write into the SPL binary.
 
 Note that this entry is automatically replaced with u-boot-spl-expanded
-unless --no-expanded is used.
+unless --no-expanded is used or the node has a 'no-expanded' property.
 
 
 
@@ -1113,7 +1113,7 @@ The ELF file 'tpl/u-boot-tpl' must also be available for 
this to work, since
 binman uses that to look up symbols to write into the TPL binary.
 
 Note that this entry is automatically replaced with u-boot-tpl-expanded
-unless --no-expanded is used.
+unless --no-expanded is used or the node has a 'no-expanded' property.
 
 
 
diff --git a/tools/binman/entry.py b/tools/binman/entry.py
index 1cfa024a9f9..ac25986ee6e 100644
--- a/tools/binman/entry.py
+++ b/tools/binman/entry.py
@@ -164,7 +164,8 @@ class Entry(object):
 if obj and expanded:
 # Check whether to use the expanded entry
 new_etype = etype + '-expanded'
-if obj.UseExpanded(node, etype, new_etype):
+can_expand = not fdt_util.GetBool(node, 'no-expanded')
+if can_expand and obj.UseExpanded(node, etype, new_etype):
 etype = new_etype
 else:
 obj = None
diff --git a/tools/binman/etype/u_boot.py b/tools/binman/etype/u_boot.py
index d2eaba6d4aa..e8d180a46dd 100644
--- a/tools/binman/etype/u_boot.py
+++ b/tools/binman/etype/u_boot.py
@@ -25,7 +25,7 @@ class Entry_u_boot(Entry_blob):
 in the binman README for more information.
 
 Note that this entry is automatically replaced with u-boot-expanded unless
---no-expanded is used.
+--no-expanded is used or the node has a 'no-expanded' property.
 """
 def __init__(self, section, etype, node):
 super().__init__(section, etype, node)
diff --git a/tools/binman/etype/u_boot_spl.py b/tools/binman/etype/u_boot_spl.py
index 1c39f982519..6f79bf59f9f 100644
--- a/tools/binman/etype/u_boot_spl.py
+++ b/tools/binman/etype/u_boot_spl.py
@@ -32,7 +32,7 @@ class Entry_u_boot_spl(Entry_blob):
 binman uses that to look up symbols to write into the SPL binary.
 
 Note that this entry is automatically replaced with u-boot-spl-expanded
-unless --no-expanded is used.
+unless --no-expanded is used or the node has a 'no-expanded' property.
 """
 def __init__(self, section, etype, node):
 super().__init__(section, etype, node)
diff --git a/tools/binman/etype/u_boot_tpl.py b/tools/binman/etype/u_boot_tpl.py
index 95d9bd6b20e..0c575df8cdc 100644
--- a/tools/binman/etype/u_boot_tpl.py
+++ b/tools/binman/etype/u_boot_tpl.py
@@ -32,7 +32,7 @@ class Entry_u_boot_tpl(Entry_blob):
 binman uses that to look up symbols to write into the TPL binary.
 
 Note that this entry is automatically replaced with u

[PATCH 03/11] binman: Add support for a collection of entries

2021-03-20 Thread Simon Glass
The vblock entry type includes code to collect the data from a number of
other entries (not necessarily subentries) and concatenating it. This is
a useful feature for other entry types.

Make it a base class, so that vblock can use it, along with other entry
types.

Signed-off-by: Simon Glass 
---

 tools/binman/entries.rst | 13 ++
 tools/binman/entry.py|  5 +++
 tools/binman/etype/collection.py | 61 
 tools/binman/etype/vblock.py | 26 ++--
 tools/binman/ftest.py| 10 -
 tools/binman/test/198_collection.dts | 27 
 6 files changed, 128 insertions(+), 14 deletions(-)
 create mode 100644 tools/binman/etype/collection.py
 create mode 100644 tools/binman/test/198_collection.dts

diff --git a/tools/binman/entries.rst b/tools/binman/entries.rst
index 1a71413f940..d5f8d95dc19 100644
--- a/tools/binman/entries.rst
+++ b/tools/binman/entries.rst
@@ -248,6 +248,19 @@ both of size 1MB.
 
 
 
+Entry: collection: An entry which contains a collection of other entries
+
+
+Properties / Entry arguments:
+- content: List of phandles to entries to include
+
+This allows reusing the contents of other entries. The contents of the
+listed entries are combined to form this entry. This serves as a useful
+base class for entry types which need to process data from elsewhere in
+the image, not necessarily child entries.
+
+
+
 Entry: cros-ec-rw: A blob entry which contains a Chromium OS read-write EC 
image
 

 
diff --git a/tools/binman/entry.py b/tools/binman/entry.py
index ac25986ee6e..a157038d4e3 100644
--- a/tools/binman/entry.py
+++ b/tools/binman/entry.py
@@ -438,6 +438,11 @@ class Entry(object):
 """Convenience function to raise an error referencing a node"""
 raise ValueError("Node '%s': %s" % (self._node.path, msg))
 
+def Info(self, msg):
+"""Convenience function to log info referencing a node"""
+tag = "Info '%s'" % self._node.path
+tout.Detail('%30s: %s' % (tag, msg))
+
 def Detail(self, msg):
 """Convenience function to log detail referencing a node"""
 tag = "Node '%s'" % self._node.path
diff --git a/tools/binman/etype/collection.py b/tools/binman/etype/collection.py
new file mode 100644
index 000..c0c552ac4f3
--- /dev/null
+++ b/tools/binman/etype/collection.py
@@ -0,0 +1,61 @@
+# SPDX-License-Identifier: GPL-2.0+
+# Copyright 2021 Google LLC
+# Written by Simon Glass 
+#
+
+# Support for a collection of entries from other parts of an image
+
+from collections import OrderedDict
+import os
+
+from binman.entry import Entry
+from dtoc import fdt_util
+
+class Entry_collection(Entry):
+"""An entry which contains a collection of other entries
+
+Properties / Entry arguments:
+- content: List of phandles to entries to include
+
+This allows reusing the contents of other entries. The contents of the
+listed entries are combined to form this entry. This serves as a useful
+base class for entry types which need to process data from elsewhere in
+the image, not necessarily child entries.
+"""
+def __init__(self, section, etype, node):
+super().__init__(section, etype, node)
+self.content = fdt_util.GetPhandleList(self._node, 'content')
+if not self.content:
+self.Raise("Collection must have a 'content' property")
+
+def GetContents(self):
+"""Get the contents of this entry
+
+Returns:
+bytes content of the entry
+"""
+# Join up all the data
+self.Info('Getting content')
+data = b''
+for entry_phandle in self.content:
+entry_data = self.section.GetContentsByPhandle(entry_phandle, self)
+if entry_data is None:
+# Data not available yet
+return None
+data += entry_data
+
+self.Info('Returning contents size %x' % len(data))
+
+return data
+
+def ObtainContents(self):
+data = self.GetContents()
+if data is None:
+return False
+self.SetContents(data)
+return True
+
+def ProcessContents(self):
+# The blob may have changed due to WriteSymbols()
+data = self.GetContents()
+return self.ProcessContentsUpdate(data)
diff --git a/tools/binman/etype/vblock.py b/tools/binman/etype/vblock.py
index eba5351dd52..d473083cab8 100644
--- a/tools/binman/etype/vblock.py
+++ b/tools/binman/etype/vblock.py
@@ -9,12 +9,13 @@
 from collections import OrderedDict
 import os
 
-from binman.entry import Entry, EntryArg
+from binman.entry import EntryArg
+from binman.etype.collection import Entry_collection
 
 from dtoc import fdt_util
 from patman import tools
 
-class Entry_vblock(Entry):
+class Entry_vblock(Entry_coll

[PATCH 04/11] binman: Support obtaining section contents immediately

2021-03-20 Thread Simon Glass
Generally the content of sections is not built until the final assembly
of the image. This is partly to avoid wasting time, since the entries
within sections may change multiple times as binman works through its
various stages. This works quite well since sections exist in a strict
hierarchy, so they can be processed in a depth-first manner.

However the 'collection' entry type does not have this luxury. If it
contains a section within its 'content' list, then it must produce the
section contents, if available. That section is typically a sibling
node, i.e. not part oc the collection's hierarchy.

Add a new 'required' argument to section.GetData() to support this. When
required is True, any referenced sections are immediately built. If this
is not possible (because one of the subentries does not have its data yet)
then an error is produced.

The test for this uses a 'collection' entry type, referencing a section as
its first member. This forces a call to _BuildSectionData() with required
set to False, at first, then True later, when the image is assembled.

Signed-off-by: Simon Glass 
---

 tools/binman/entry.py|  6 +++-
 tools/binman/etype/collection.py | 18 +++
 tools/binman/etype/section.py| 33 +++-
 tools/binman/etype/vblock.py | 12 ---
 tools/binman/ftest.py| 13 
 tools/binman/test/199_collection_section.dts | 32 +++
 6 files changed, 95 insertions(+), 19 deletions(-)
 create mode 100644 tools/binman/test/199_collection_section.dts

diff --git a/tools/binman/entry.py b/tools/binman/entry.py
index a157038d4e3..b7b9791b10d 100644
--- a/tools/binman/entry.py
+++ b/tools/binman/entry.py
@@ -482,9 +482,13 @@ class Entry(object):
 """
 return self._node.path
 
-def GetData(self):
+def GetData(self, required=True):
 """Get the contents of an entry
 
+Args:
+required: True if the data must be present, False if it is OK to
+return None
+
 Returns:
 bytes content of the entry, excluding any padding. If the entry is
 compressed, the compressed data is returned
diff --git a/tools/binman/etype/collection.py b/tools/binman/etype/collection.py
index c0c552ac4f3..1625575fe98 100644
--- a/tools/binman/etype/collection.py
+++ b/tools/binman/etype/collection.py
@@ -28,18 +28,24 @@ class Entry_collection(Entry):
 if not self.content:
 self.Raise("Collection must have a 'content' property")
 
-def GetContents(self):
+def GetContents(self, required):
 """Get the contents of this entry
 
+Args:
+required: True if the data must be present, False if it is OK to
+return None
+
 Returns:
 bytes content of the entry
 """
 # Join up all the data
-self.Info('Getting content')
+self.Info('Getting contents, required=%s' % required)
 data = b''
 for entry_phandle in self.content:
-entry_data = self.section.GetContentsByPhandle(entry_phandle, self)
-if entry_data is None:
+entry_data = self.section.GetContentsByPhandle(entry_phandle, self,
+   required)
+if not required and entry_data is None:
+self.Info('Contents not available yet')
 # Data not available yet
 return None
 data += entry_data
@@ -49,7 +55,7 @@ class Entry_collection(Entry):
 return data
 
 def ObtainContents(self):
-data = self.GetContents()
+data = self.GetContents(False)
 if data is None:
 return False
 self.SetContents(data)
@@ -57,5 +63,5 @@ class Entry_collection(Entry):
 
 def ProcessContents(self):
 # The blob may have changed due to WriteSymbols()
-data = self.GetContents()
+data = self.GetContents(True)
 return self.ProcessContentsUpdate(data)
diff --git a/tools/binman/etype/section.py b/tools/binman/etype/section.py
index cce1500b4e5..d4a097b94bf 100644
--- a/tools/binman/etype/section.py
+++ b/tools/binman/etype/section.py
@@ -180,7 +180,7 @@ class Entry_section(Entry):
 
 return data
 
-def _BuildSectionData(self):
+def _BuildSectionData(self, required):
 """Build the contents of a section
 
 This places all entries at the right place, dealing with padding before
@@ -188,13 +188,20 @@ class Entry_section(Entry):
 pad-before and pad-after properties in the section items) since that is
 handled by the parent section.
 
+Args:
+required: True if the data must be present, False if it is OK to
+return None
+
 Returns:
 Contents of the section (bytes)
 """
 section_data = b''
 
 for entry in self._entries.

[PATCH 05/11] binman: Support default alignment for sections

2021-03-20 Thread Simon Glass
Sometimes it is useful to specify the default alignment for all entries
in a section, such as when word-alignment is necessary, for example. It
is tedious and error-prone to specify this individually for each section.

Add a property to control this for a section.

Signed-off-by: Simon Glass 
---

 tools/binman/binman.rst |  7 ++
 tools/binman/entries.rst|  2 ++
 tools/binman/entry.py   |  2 ++
 tools/binman/etype/cbfs.py  |  1 +
 tools/binman/etype/mkimage.py   |  1 +
 tools/binman/etype/section.py   |  3 +++
 tools/binman/ftest.py   | 12 ++
 tools/binman/test/200_align_default.dts | 30 +
 8 files changed, 58 insertions(+)
 create mode 100644 tools/binman/test/200_align_default.dts

diff --git a/tools/binman/binman.rst b/tools/binman/binman.rst
index 28cb2e7a9c9..1aa2459d50c 100644
--- a/tools/binman/binman.rst
+++ b/tools/binman/binman.rst
@@ -562,6 +562,13 @@ skip-at-start:
 'end-at-4gb' property is not applicable where CONFIG_SYS_TEXT_BASE +
 Image size != 4gb.
 
+align-default:
+Specifies the default alignment for entries in this section, if they do
+not specify an alignment. Note that this only applies to top-level entries
+in the section (direct subentries), not any subentries of those entries.
+This means that each section must specify its own default alignment, if
+required.
+
 Examples of the above options can be found in the tests. See the
 tools/binman/test directory.
 
diff --git a/tools/binman/entries.rst b/tools/binman/entries.rst
index d5f8d95dc19..a91211e93ed 100644
--- a/tools/binman/entries.rst
+++ b/tools/binman/entries.rst
@@ -796,6 +796,8 @@ Properties / Entry arguments: (see binman README for more 
information):
 file, since the first 16 bytes are skipped when writing.
 name-prefix: Adds a prefix to the name of every entry in the section
 when writing out the map
+align_default: Default alignment for this section, if no alignment is
+given in the entry
 
 Properties:
 allow_missing: True if this section permits external blobs to be
diff --git a/tools/binman/entry.py b/tools/binman/entry.py
index b7b9791b10d..70222718ea9 100644
--- a/tools/binman/entry.py
+++ b/tools/binman/entry.py
@@ -201,6 +201,8 @@ class Entry(object):
 if tools.NotPowerOfTwo(self.align):
 raise ValueError("Node '%s': Alignment %s must be a power of two" %
  (self._node.path, self.align))
+if self.section and self.align is None:
+self.align = self.section.align_default
 self.pad_before = fdt_util.GetInt(self._node, 'pad-before', 0)
 self.pad_after = fdt_util.GetInt(self._node, 'pad-after', 0)
 self.align_size = fdt_util.GetInt(self._node, 'align-size')
diff --git a/tools/binman/etype/cbfs.py b/tools/binman/etype/cbfs.py
index 1daddeb8229..44db7b9bb20 100644
--- a/tools/binman/etype/cbfs.py
+++ b/tools/binman/etype/cbfs.py
@@ -169,6 +169,7 @@ class Entry_cbfs(Entry):
 
 super().__init__(section, etype, node)
 self._cbfs_arg = fdt_util.GetString(node, 'cbfs-arch', 'x86')
+self.align_default = None
 self._cbfs_entries = OrderedDict()
 self._ReadSubnodes()
 self.reader = None
diff --git a/tools/binman/etype/mkimage.py b/tools/binman/etype/mkimage.py
index e9f82729ab4..e49977522e3 100644
--- a/tools/binman/etype/mkimage.py
+++ b/tools/binman/etype/mkimage.py
@@ -36,6 +36,7 @@ class Entry_mkimage(Entry):
 super().__init__(section, etype, node)
 self._args = fdt_util.GetString(self._node, 'args').split(' ')
 self._mkimage_entries = OrderedDict()
+self.align_default = None
 self._ReadSubnodes()
 
 def ObtainContents(self):
diff --git a/tools/binman/etype/section.py b/tools/binman/etype/section.py
index d4a097b94bf..c3bac026c14 100644
--- a/tools/binman/etype/section.py
+++ b/tools/binman/etype/section.py
@@ -36,6 +36,8 @@ class Entry_section(Entry):
 file, since the first 16 bytes are skipped when writing.
 name-prefix: Adds a prefix to the name of every entry in the section
 when writing out the map
+align_default: Default alignment for this section, if no alignment is
+given in the entry
 
 Properties:
 allow_missing: True if this section permits external blobs to be
@@ -76,6 +78,7 @@ class Entry_section(Entry):
 if self._skip_at_start is None:
 self._skip_at_start = 0
 self._name_prefix = fdt_util.GetString(self._node, 'name-prefix')
+self.align_default = fdt_util.GetInt(self._node, 'align-default', 0)
 filename = fdt_util.GetString(self._node, 'filename')
 if filename:
 self._filename = filename
diff --git a/tools/binman/ftest.py b/tools/binman/ftest.py
index 043b1b037c4..89fe6612e1b 100644
--- a/tools/binman/ftest.

[PATCH 06/11] dtoc: Improve internal error for Refresh()

2021-03-20 Thread Simon Glass
Add the node name too so it is easy to see which node failed.

Signed-off-by: Simon Glass 
---

 tools/dtoc/fdt.py  | 4 ++--
 tools/dtoc/test_fdt.py | 2 +-
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/tools/dtoc/fdt.py b/tools/dtoc/fdt.py
index 25ce5136ebf..f0d1384ccc3 100644
--- a/tools/dtoc/fdt.py
+++ b/tools/dtoc/fdt.py
@@ -339,8 +339,8 @@ class Node:
 p = fdt_obj.get_property_by_offset(poffset)
 prop = self.props.get(p.name)
 if not prop:
-raise ValueError("Internal error, property '%s' missing, "
- 'offset %d' % (p.name, poffset))
+raise ValueError("Internal error, node '%s' property '%s' 
missing, "
+ 'offset %d' % (self.path, p.name, poffset))
 prop.RefreshOffset(poffset)
 poffset = fdt_obj.next_property_offset(poffset, QUIET_NOTFOUND)
 
diff --git a/tools/dtoc/test_fdt.py b/tools/dtoc/test_fdt.py
index 1c3a8a2ab1e..72095b05434 100755
--- a/tools/dtoc/test_fdt.py
+++ b/tools/dtoc/test_fdt.py
@@ -209,7 +209,7 @@ class TestNode(unittest.TestCase):
 del self.node.props['notstring']
 with self.assertRaises(ValueError) as e:
 self.dtb.Refresh()
-self.assertIn("Internal error, property 'notstring' missing, offset ",
+self.assertIn("Internal error, node '/spl-test' property 'notstring' 
missing, offset ",
   str(e.exception))
 
 def testLookupPhandle(self):
-- 
2.31.0.rc2.261.g7f71774620-goog



[PATCH 07/11] dtoc: Tidy up property-offset handling

2021-03-20 Thread Simon Glass
If a property does not yet have an offset, then that means it exists in
the cache'd fdt but has not yet been synced back to the flat tree. Use
the dirty flag for this so we don't need to check the offset too. Improve
the comments for Prop and Node to make it clear what an offset of None
means.

Also clear the dirty flag after the property is synced.

Signed-off-by: Simon Glass 
---

 tools/dtoc/fdt.py | 10 +++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/tools/dtoc/fdt.py b/tools/dtoc/fdt.py
index f0d1384ccc3..36993c29ca4 100644
--- a/tools/dtoc/fdt.py
+++ b/tools/dtoc/fdt.py
@@ -103,6 +103,8 @@ class Prop:
 """A device tree property
 
 Properties:
+node: Node containing this property
+offset: Offset of the property (None if still to be synced)
 name: Property name (as per the device tree)
 value: Property value as a string of bytes, or a list of strings of
 bytes
@@ -114,7 +116,7 @@ class Prop:
 self.name = name
 self.value = None
 self.bytes = bytes(data)
-self.dirty = False
+self.dirty = offset is None
 if not data:
 self.type = Type.BOOL
 self.value = True
@@ -228,7 +230,7 @@ class Prop:
 Raises:
 FdtException if auto_resize is False and there is not enough space
 """
-if self._offset is None or self.dirty:
+if self.dirty:
 node = self._node
 fdt_obj = node._fdt._fdt_obj
 if auto_resize:
@@ -239,13 +241,15 @@ class Prop:
 fdt_obj.setprop(node.Offset(), self.name, self.bytes)
 else:
 fdt_obj.setprop(node.Offset(), self.name, self.bytes)
+self.dirty = False
 
 
 class Node:
 """A device tree node
 
 Properties:
-offset: Integer offset in the device tree
+parent: Parent Node
+offset: Integer offset in the device tree (None if to be synced)
 name: Device tree node tname
 path: Full path to node, along with the node name itself
 _fdt: Device tree object
-- 
2.31.0.rc2.261.g7f71774620-goog



[PATCH 08/11] dtoc: Tweak ordering of fdt-offsets refreshing

2021-03-20 Thread Simon Glass
Once the tree has been synced, thus potentially moving things around in the
fdt, we set _cached_offsets to False so that a refresh will happen next
time a property is accessed.

This 'lazy' refresh doesn't really save much time, since refresh is a very
fast operation, just a single walk of the tree. Also, having the refresh
happen in the bowels of property access it makes it harder to figure out
what is going on.

Simplify the code by always doing a refresh before and after a sync. Set
_cached_offsets to True immediately after this, in the Refresh() function,
since this makes more sense than doing it in the caller.

Signed-off-by: Simon Glass 
---

 tools/dtoc/fdt.py | 7 ---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/tools/dtoc/fdt.py b/tools/dtoc/fdt.py
index 36993c29ca4..a5e1d0b52f6 100644
--- a/tools/dtoc/fdt.py
+++ b/tools/dtoc/fdt.py
@@ -646,8 +646,9 @@ class Fdt:
 Raises:
 FdtException if auto_resize is False and there is not enough space
 """
+self.CheckCache()
 self._root.Sync(auto_resize)
-self.Invalidate()
+self.Refresh()
 
 def Pack(self):
 """Pack the device tree down to its minimum size
@@ -656,7 +657,7 @@ class Fdt:
 build up in the device tree binary.
 """
 CheckErr(self._fdt_obj.pack(), 'pack')
-self.Invalidate()
+self.Refresh()
 
 def GetContents(self):
 """Get the contents of the FDT
@@ -708,11 +709,11 @@ class Fdt:
 if self._cached_offsets:
 return
 self.Refresh()
-self._cached_offsets = True
 
 def Refresh(self):
 """Refresh the offset cache"""
 self._root.Refresh(0)
+self._cached_offsets = True
 
 def GetStructOffset(self, offset):
 """Get the file offset of a given struct offset
-- 
2.31.0.rc2.261.g7f71774620-goog



[PATCH 09/11] dtoc: Add a subnode test for multiple nodes

2021-03-20 Thread Simon Glass
Add a new test that adds a subnode alongside an existing one, as well as
adding properties to a subnode. This will expand to adding multiple
subnodes in future patches. Put a node after the one we are adding to so
we can check that things sync correctly.

The testAddNode() test should be in the TestNode class since it is a node
test, so move it.

Signed-off-by: Simon Glass 
---

 tools/dtoc/test/dtoc_test_simple.dts |  4 +++
 tools/dtoc/test_fdt.py   | 42 
 2 files changed, 34 insertions(+), 12 deletions(-)

diff --git a/tools/dtoc/test/dtoc_test_simple.dts 
b/tools/dtoc/test/dtoc_test_simple.dts
index d8ab8613ee3..b5c1274bb7c 100644
--- a/tools/dtoc/test/dtoc_test_simple.dts
+++ b/tools/dtoc/test/dtoc_test_simple.dts
@@ -56,4 +56,8 @@
low-power;
};
};
+
+   orig-node {
+   orig = <1 23 4>;
+   };
 };
diff --git a/tools/dtoc/test_fdt.py b/tools/dtoc/test_fdt.py
index 72095b05434..1e66e1bc353 100755
--- a/tools/dtoc/test_fdt.py
+++ b/tools/dtoc/test_fdt.py
@@ -154,6 +154,7 @@ class TestNode(unittest.TestCase):
 def setUp(self):
 self.dtb = fdt.FdtScan(find_dtb_file('dtoc_test_simple.dts'))
 self.node = self.dtb.GetNode('/spl-test')
+self.fdt = self.dtb.GetFdtObj()
 
 def testOffset(self):
 """Tests that we can obtain the offset of a node"""
@@ -197,7 +198,7 @@ class TestNode(unittest.TestCase):
 def testRefreshExtraNode(self):
 """Test refreshing offsets when an expected node is missing"""
 # Delete it from the device tre, not our tables
-self.dtb.GetFdtObj().del_node(self.node.Offset())
+self.fdt.del_node(self.node.Offset())
 with self.assertRaises(ValueError) as e:
 self.dtb.Refresh()
 self.assertIn('Internal error, node name mismatch '
@@ -220,6 +221,34 @@ class TestNode(unittest.TestCase):
 target = dtb.GetNode('/phandle-target')
 self.assertEqual(target, dtb.LookupPhandle(fdt32_to_cpu(prop.value)))
 
+def testAddNodeSpace(self):
+"""Test adding a single node when out of space"""
+self.fdt.pack()
+self.node.AddSubnode('subnode')
+with self.assertRaises(libfdt.FdtException) as e:
+self.dtb.Sync(auto_resize=False)
+self.assertIn('FDT_ERR_NOSPACE', str(e.exception))
+
+self.dtb.Sync(auto_resize=True)
+offset = self.fdt.path_offset('/spl-test/subnode')
+self.assertTrue(offset > 0)
+
+def testAddNodes(self):
+"""Test adding various subnode and properies"""
+node = self.dtb.GetNode('/i2c@0')
+
+# Add a property to the node after i2c@0 to check that this is not
+# disturbed by adding a subnode to i2c@0
+orig_node = self.dtb.GetNode('/orig-node')
+orig_node.AddInt('integer-4', 456)
+
+# Add a property to the pmic node to check that pmic properties are not
+# disturbed
+pmic = self.dtb.GetNode('/i2c@0/pmic@9')
+pmic.AddInt('integer-5', 567)
+
+self.dtb.Sync(auto_resize=True)
+
 
 class TestProp(unittest.TestCase):
 """Test operation of the Prop class"""
@@ -385,17 +414,6 @@ class TestProp(unittest.TestCase):
 self.assertIn('FDT_ERR_NOSPACE', str(e.exception))
 self.dtb.Sync(auto_resize=True)
 
-def testAddNode(self):
-self.fdt.pack()
-self.node.AddSubnode('subnode')
-with self.assertRaises(libfdt.FdtException) as e:
-self.dtb.Sync(auto_resize=False)
-self.assertIn('FDT_ERR_NOSPACE', str(e.exception))
-
-self.dtb.Sync(auto_resize=True)
-offset = self.fdt.path_offset('/spl-test/subnode')
-self.assertTrue(offset > 0)
-
 def testAddMore(self):
 """Test various other methods for adding and setting properties"""
 self.node.AddZeroProp('one')
-- 
2.31.0.rc2.261.g7f71774620-goog



[PATCH 11/11] dtoc: Add new check that offsets are correct

2021-03-20 Thread Simon Glass
Add a few more internal checks to make sure offsets are correct, before
updating the dtb.

To make this easier, update the functions which add a property to return
that property,.

Signed-off-by: Simon Glass 
---

 tools/dtoc/fdt.py  | 27 ---
 tools/dtoc/test_fdt.py | 16 
 2 files changed, 40 insertions(+), 3 deletions(-)

diff --git a/tools/dtoc/fdt.py b/tools/dtoc/fdt.py
index 63d1f68d816..3996971e39c 100644
--- a/tools/dtoc/fdt.py
+++ b/tools/dtoc/fdt.py
@@ -233,6 +233,11 @@ class Prop:
 if self.dirty:
 node = self._node
 fdt_obj = node._fdt._fdt_obj
+node_name = fdt_obj.get_name(node._offset)
+if node_name and node_name != node.name:
+raise ValueError("Internal error, node '%s' name mismatch 
'%s'" %
+ (node.path, node_name))
+
 if auto_resize:
 while fdt_obj.setprop(node.Offset(), self.name, self.bytes,
 (libfdt.NOSPACE,)) == -libfdt.NOSPACE:
@@ -328,6 +333,11 @@ class Node:
 fdt_obj = self._fdt._fdt_obj
 if self._offset != my_offset:
 self._offset = my_offset
+name = fdt_obj.get_name(self._offset)
+if name and self.name != name:
+raise ValueError("Internal error, node '%s' name mismatch '%s'" %
+ (self.path, name))
+
 offset = fdt_obj.first_subnode(self._offset, QUIET_NOTFOUND)
 for subnode in self.subnodes:
 if subnode.name != fdt_obj.get_name(offset):
@@ -451,8 +461,13 @@ class Node:
 Args:
 prop_name: Name of property to add
 val: Bytes value of property
+
+Returns:
+Prop added
 """
-self.props[prop_name] = Prop(self, None, prop_name, val)
+prop = Prop(self, None, prop_name, val)
+self.props[prop_name] = prop
+return prop
 
 def AddString(self, prop_name, val):
 """Add a new string property to a node
@@ -463,9 +478,12 @@ class Node:
 Args:
 prop_name: Name of property to add
 val: String value of property
+
+Returns:
+Prop added
 """
 val = bytes(val, 'utf-8')
-self.AddData(prop_name, val + b'\0')
+return self.AddData(prop_name, val + b'\0')
 
 def AddInt(self, prop_name, val):
 """Add a new integer property to a node
@@ -476,8 +494,11 @@ class Node:
 Args:
 prop_name: Name of property to add
 val: Integer value of property
+
+Returns:
+Prop added
 """
-self.AddData(prop_name, struct.pack('>I', val))
+return self.AddData(prop_name, struct.pack('>I', val))
 
 def AddSubnode(self, name):
 """Add a new subnode to the node
diff --git a/tools/dtoc/test_fdt.py b/tools/dtoc/test_fdt.py
index 49a2853f07f..856392b1bd9 100755
--- a/tools/dtoc/test_fdt.py
+++ b/tools/dtoc/test_fdt.py
@@ -265,6 +265,22 @@ class TestNode(unittest.TestCase):
 
 self.dtb.Sync(auto_resize=True)
 
+def testRefreshNameMismatch(self):
+"""Test name mismatch when syncing nodes and properties"""
+prop = self.node.AddInt('integer-a', 12)
+
+wrong_offset = self.dtb.GetNode('/i2c@0')._offset
+self.node._offset = wrong_offset
+with self.assertRaises(ValueError) as e:
+self.dtb.Sync()
+self.assertIn("Internal error, node '/spl-test' name mismatch 'i2c@0'",
+  str(e.exception))
+
+with self.assertRaises(ValueError) as e:
+self.node.Refresh(wrong_offset)
+self.assertIn("Internal error, node '/spl-test' name mismatch 'i2c@0'",
+  str(e.exception))
+
 
 class TestProp(unittest.TestCase):
 """Test operation of the Prop class"""
-- 
2.31.0.rc2.261.g7f71774620-goog



[PATCH 10/11] dtoc: Support adding subnodes alongside existing ones

2021-03-20 Thread Simon Glass
So far we have only needed to add subnodes to empty notds, so have not
had to deal with ordering. However this feature is needed for binman's
expanded nodes, since there may be another node in the same section.

While libfdt adds new properties after existing properties, it adds new
subnodes before existing subnodes. This means that we must reorder the
nodes in the cached version, so that the ordering remains consistent.

Update the sync implementation to sync existing subnodes first, then
add new ones, then tidy up the ordering in the cached version. Update the
test to cover this behaviour.

Also improve the comment about property syncing while we are here.

Signed-off-by: Simon Glass 
---

 tools/dtoc/fdt.py  | 44 +-
 tools/dtoc/test_fdt.py | 16 +++
 2 files changed, 51 insertions(+), 9 deletions(-)

diff --git a/tools/dtoc/fdt.py b/tools/dtoc/fdt.py
index a5e1d0b52f6..63d1f68d816 100644
--- a/tools/dtoc/fdt.py
+++ b/tools/dtoc/fdt.py
@@ -503,9 +503,13 @@ class Node:
 auto_resize: Resize the device tree automatically if it does not
 have enough space for the update
 
+Returns:
+True if the node had to be added, False if it already existed
+
 Raises:
 FdtException if auto_resize is False and there is not enough space
 """
+added = False
 if self._offset is None:
 # The subnode doesn't exist yet, so add it
 fdt_obj = self._fdt._fdt_obj
@@ -519,23 +523,45 @@ class Node:
 else:
 offset = fdt_obj.add_subnode(self.parent._offset, self.name)
 self._offset = offset
+added = True
 
-# Sync subnodes in reverse so that we don't disturb node offsets for
-# nodes that are earlier in the DT. This avoids an O(n^2) rescan of
-# node offsets.
+# Sync the existing subnodes first, so that we can rely on the offsets
+# being correct. As soon as we add new subnodes, it pushes all the
+# existing subnodes up.
 for node in reversed(self.subnodes):
-node.Sync(auto_resize)
+if node._offset is not None:
+node.Sync(auto_resize)
 
-# Sync properties now, whose offsets should not have been disturbed.
-# We do this after subnodes, since this disturbs the offsets of these
-# properties. Note that new properties will have an offset of None 
here,
-# which Python 3 cannot sort against int. So use a large value instead
-# to ensure that the new properties are added first.
+# Sync subnodes in reverse so that we get the expected order. Each
+# new node goes at the start of the subnode list. This avoids an O(n^2)
+# rescan of node offsets.
+num_added = 0
+for node in reversed(self.subnodes):
+if node.Sync(auto_resize):
+num_added += 1
+if num_added:
+# Reorder our list of nodes to put the new ones first, since that's
+# what libfdt does
+old_count = len(self.subnodes) - num_added
+subnodes = self.subnodes[old_count:] + self.subnodes[:old_count]
+self.subnodes = subnodes
+
+# Sync properties now, whose offsets should not have been disturbed,
+# since properties come before subnodes. This is done after all the
+# subnode processing above, since updating properties can disturb the
+# offsets of those subnodes.
+# Properties are synced in reverse order, with new properties added
+# before existing properties are synced. This ensures that the offsets
+# of earlier properties are not disturbed.
+# Note that new properties will have an offset of None here, which
+# Python cannot sort against int. So use a large value instead so that
+# new properties are added first.
 prop_list = sorted(self.props.values(),
key=lambda prop: prop._offset or 1 << 31,
reverse=True)
 for prop in prop_list:
 prop.Sync(auto_resize)
+return added
 
 
 class Fdt:
diff --git a/tools/dtoc/test_fdt.py b/tools/dtoc/test_fdt.py
index 1e66e1bc353..49a2853f07f 100755
--- a/tools/dtoc/test_fdt.py
+++ b/tools/dtoc/test_fdt.py
@@ -237,6 +237,22 @@ class TestNode(unittest.TestCase):
 """Test adding various subnode and properies"""
 node = self.dtb.GetNode('/i2c@0')
 
+# Add one more node next to the pmic one
+sn1 = node.AddSubnode('node-one')
+sn1.AddInt('integer-a', 12)
+sn1.AddInt('integer-b', 23)
+
+# Sync so that everything is clean
+self.dtb.Sync(auto_resize=True)
+
+# Add two subnodes next to pmic and node-one
+sn2 = node.AddSubnode('node-two')
+sn2.AddInt('integer-2a', 34)
+sn2.AddInt('integer-2b', 45)
+
+sn3 = node.Ad