Re: [PATCH] Revert "spi: spi-uclass: Add support to manually relocate spi memory ops"

2021-07-23 Thread Dennis Gilmore
On Fri, Jul 23, 2021 at 10:25 PM Tom Rini  wrote:
>
> On Fri, Jul 23, 2021 at 09:46:44PM -0500, Dennis Gilmore wrote:
>
> > removing the header is not sufficient to have the boards booting from SPI.
> >
> > U-Boot TPL 2021.07-00768-g49373a3334-dirty (Jul 23 2021 - 20:42:57)
> > Channel 0: LPDDR4, 50MHz
> > BW=32 Col=10 Bk=8 CS0 Row=16/15 CS=1 Die BW=16 Size=2048MB
> > Channel 1: LPDDR4, 50MHz
> > BW=32 Col=10 Bk=8 CS0 Row=16/15 CS=1 Die BW=16 Size=2048MB
> > 256B stride
> > lpddr4_set_rate: change freq to 4 mhz 0, 1
> > lpddr4_set_rate: change freq to 8 mhz 1, 0
> > Trying to boot from BOOTROM
> > Returning to boot ROM...
> >
> > U-Boot SPL 2021.07-00768-g49373a3334-dirty (Jul 23 2021 - 20:42:57 -0500)
> > Trying to boot from SPI
> >
> > At this point u-boot hangs, with the patch reverted I get the following
> > U-Boot TPL 2021.07-00769-g4af8bd872c-dirty (Jul 23 2021 - 21:20:51)
> > Channel 0: LPDDR4, 50MHz
> > BW=32 Col=10 Bk=8 CS0 Row=16/15 CS=1 Die BW=16 Size=2048MB
> > Channel 1: LPDDR4, 50MHz
> > BW=32 Col=10 Bk=8 CS0 Row=16/15 CS=1 Die BW=16 Size=2048MB
> > 256B stride
> > lpddr4_set_rate: change freq to 4 mhz 0, 1
> > lpddr4_set_rate: change freq to 8 mhz 1, 0
> > Trying to boot from BOOTROM
> > Returning to boot ROM...
> >
> > U-Boot SPL 2021.07-00769-g4af8bd872c-dirty (Jul 23 2021 - 21:20:51 -0500)
> > Trying to boot from SPI
> >
> >
> > U-Boot 2021.07-00769-g4af8bd872c-dirty (Jul 23 2021 - 21:20:51 -0500)
> >
> > SoC: Rockchip rk3399
> > Reset cause: RST
> > Model: Kobol Helios64
> > Revision: 0.0 - Unknown
> > DRAM:  3.9 GiB
> > PMIC:  RK808
> > MMC:   mmc@fe32: 1, mmc@fe33: 0
> > Loading Environment from SPIFlash... SF: Detected w25q128 with page
> > size 256 Bytes, erase size 4 KiB, total 16 MiB
> > *** Warning - bad CRC, using default environment
> >
> > In:serial@ff1a
> > Out:   serial@ff1a
> > Err:   serial@ff1a
> > Model: Kobol Helios64
> > Revision: UNKNOWN
> > Net:   dw_dm_mdio_init: mdio node is missing, registering legacy mdio
> > busNo ethernet found.
> >
> > starting USB...
> > Bus usb@fe90: usb maximum-speed not found
> > Register 2000140 NbrPorts 2
> > Starting the controller
> > USB XHCI 1.10
> > scanning bus usb@fe90 for devices... 2 USB Device(s) found
> >scanning usb for storage devices... 0 Storage Device(s) found
> > Hit any key to stop autoboot:  0
> > switch to partitions #0, OK
> > mmc0(part 0) is current device
> > ** No partition table - mmc 0 **
> > Couldn't find partition mmc 0:1
> > switch to partitions #0, OK
> > mmc1 is current device
> > Scanning mmc 1:1...
> > Scanning disk m...@fe32.blk...
> > Scanning disk m...@fe33.blk...
> > ** Unrecognized filesystem type **
> > Found 5 disks
> > dw_dm_mdio_init: mdio node is missing, registering legacy mdio
> > busdw_dm_mdio_init: mdio node is missing, registering legacy mdio
> > busLoading Boot 'Fedora' failed
> > EFI boot manager: Cannot load any image
> > Found EFI removable media binary efi/boot/bootaa64.efi
>
> Is LTO on, on these platforms?  That code in question really should not
> be enabled, at all.  Like, if you toss an #error in that section of
> code, it should still build.  It does, right?

It does still build if I put a #error in the middle of it

$ grep LTO .config
CONFIG_ARCH_SUPPORTS_LTO=y
# CONFIG_LTO is not set


LTO is not on


> --
> Tom


Re: [PATCH] Revert "spi: spi-uclass: Add support to manually relocate spi memory ops"

2021-07-23 Thread Tom Rini
On Fri, Jul 23, 2021 at 09:46:44PM -0500, Dennis Gilmore wrote:

> removing the header is not sufficient to have the boards booting from SPI.
> 
> U-Boot TPL 2021.07-00768-g49373a3334-dirty (Jul 23 2021 - 20:42:57)
> Channel 0: LPDDR4, 50MHz
> BW=32 Col=10 Bk=8 CS0 Row=16/15 CS=1 Die BW=16 Size=2048MB
> Channel 1: LPDDR4, 50MHz
> BW=32 Col=10 Bk=8 CS0 Row=16/15 CS=1 Die BW=16 Size=2048MB
> 256B stride
> lpddr4_set_rate: change freq to 4 mhz 0, 1
> lpddr4_set_rate: change freq to 8 mhz 1, 0
> Trying to boot from BOOTROM
> Returning to boot ROM...
> 
> U-Boot SPL 2021.07-00768-g49373a3334-dirty (Jul 23 2021 - 20:42:57 -0500)
> Trying to boot from SPI
> 
> At this point u-boot hangs, with the patch reverted I get the following
> U-Boot TPL 2021.07-00769-g4af8bd872c-dirty (Jul 23 2021 - 21:20:51)
> Channel 0: LPDDR4, 50MHz
> BW=32 Col=10 Bk=8 CS0 Row=16/15 CS=1 Die BW=16 Size=2048MB
> Channel 1: LPDDR4, 50MHz
> BW=32 Col=10 Bk=8 CS0 Row=16/15 CS=1 Die BW=16 Size=2048MB
> 256B stride
> lpddr4_set_rate: change freq to 4 mhz 0, 1
> lpddr4_set_rate: change freq to 8 mhz 1, 0
> Trying to boot from BOOTROM
> Returning to boot ROM...
> 
> U-Boot SPL 2021.07-00769-g4af8bd872c-dirty (Jul 23 2021 - 21:20:51 -0500)
> Trying to boot from SPI
> 
> 
> U-Boot 2021.07-00769-g4af8bd872c-dirty (Jul 23 2021 - 21:20:51 -0500)
> 
> SoC: Rockchip rk3399
> Reset cause: RST
> Model: Kobol Helios64
> Revision: 0.0 - Unknown
> DRAM:  3.9 GiB
> PMIC:  RK808
> MMC:   mmc@fe32: 1, mmc@fe33: 0
> Loading Environment from SPIFlash... SF: Detected w25q128 with page
> size 256 Bytes, erase size 4 KiB, total 16 MiB
> *** Warning - bad CRC, using default environment
> 
> In:serial@ff1a
> Out:   serial@ff1a
> Err:   serial@ff1a
> Model: Kobol Helios64
> Revision: UNKNOWN
> Net:   dw_dm_mdio_init: mdio node is missing, registering legacy mdio
> busNo ethernet found.
> 
> starting USB...
> Bus usb@fe90: usb maximum-speed not found
> Register 2000140 NbrPorts 2
> Starting the controller
> USB XHCI 1.10
> scanning bus usb@fe90 for devices... 2 USB Device(s) found
>scanning usb for storage devices... 0 Storage Device(s) found
> Hit any key to stop autoboot:  0
> switch to partitions #0, OK
> mmc0(part 0) is current device
> ** No partition table - mmc 0 **
> Couldn't find partition mmc 0:1
> switch to partitions #0, OK
> mmc1 is current device
> Scanning mmc 1:1...
> Scanning disk m...@fe32.blk...
> Scanning disk m...@fe33.blk...
> ** Unrecognized filesystem type **
> Found 5 disks
> dw_dm_mdio_init: mdio node is missing, registering legacy mdio
> busdw_dm_mdio_init: mdio node is missing, registering legacy mdio
> busLoading Boot 'Fedora' failed
> EFI boot manager: Cannot load any image
> Found EFI removable media binary efi/boot/bootaa64.efi

Is LTO on, on these platforms?  That code in question really should not
be enabled, at all.  Like, if you toss an #error in that section of
code, it should still build.  It does, right?

-- 
Tom


signature.asc
Description: PGP signature


Re: [PATCH] Revert "spi: spi-uclass: Add support to manually relocate spi memory ops"

2021-07-23 Thread Dennis Gilmore
removing the header is not sufficient to have the boards booting from SPI.

U-Boot TPL 2021.07-00768-g49373a3334-dirty (Jul 23 2021 - 20:42:57)
Channel 0: LPDDR4, 50MHz
BW=32 Col=10 Bk=8 CS0 Row=16/15 CS=1 Die BW=16 Size=2048MB
Channel 1: LPDDR4, 50MHz
BW=32 Col=10 Bk=8 CS0 Row=16/15 CS=1 Die BW=16 Size=2048MB
256B stride
lpddr4_set_rate: change freq to 4 mhz 0, 1
lpddr4_set_rate: change freq to 8 mhz 1, 0
Trying to boot from BOOTROM
Returning to boot ROM...

U-Boot SPL 2021.07-00768-g49373a3334-dirty (Jul 23 2021 - 20:42:57 -0500)
Trying to boot from SPI

At this point u-boot hangs, with the patch reverted I get the following
U-Boot TPL 2021.07-00769-g4af8bd872c-dirty (Jul 23 2021 - 21:20:51)
Channel 0: LPDDR4, 50MHz
BW=32 Col=10 Bk=8 CS0 Row=16/15 CS=1 Die BW=16 Size=2048MB
Channel 1: LPDDR4, 50MHz
BW=32 Col=10 Bk=8 CS0 Row=16/15 CS=1 Die BW=16 Size=2048MB
256B stride
lpddr4_set_rate: change freq to 4 mhz 0, 1
lpddr4_set_rate: change freq to 8 mhz 1, 0
Trying to boot from BOOTROM
Returning to boot ROM...

U-Boot SPL 2021.07-00769-g4af8bd872c-dirty (Jul 23 2021 - 21:20:51 -0500)
Trying to boot from SPI


U-Boot 2021.07-00769-g4af8bd872c-dirty (Jul 23 2021 - 21:20:51 -0500)

SoC: Rockchip rk3399
Reset cause: RST
Model: Kobol Helios64
Revision: 0.0 - Unknown
DRAM:  3.9 GiB
PMIC:  RK808
MMC:   mmc@fe32: 1, mmc@fe33: 0
Loading Environment from SPIFlash... SF: Detected w25q128 with page
size 256 Bytes, erase size 4 KiB, total 16 MiB
*** Warning - bad CRC, using default environment

In:serial@ff1a
Out:   serial@ff1a
Err:   serial@ff1a
Model: Kobol Helios64
Revision: UNKNOWN
Net:   dw_dm_mdio_init: mdio node is missing, registering legacy mdio
busNo ethernet found.

starting USB...
Bus usb@fe90: usb maximum-speed not found
Register 2000140 NbrPorts 2
Starting the controller
USB XHCI 1.10
scanning bus usb@fe90 for devices... 2 USB Device(s) found
   scanning usb for storage devices... 0 Storage Device(s) found
Hit any key to stop autoboot:  0
switch to partitions #0, OK
mmc0(part 0) is current device
** No partition table - mmc 0 **
Couldn't find partition mmc 0:1
switch to partitions #0, OK
mmc1 is current device
Scanning mmc 1:1...
Scanning disk m...@fe32.blk...
Scanning disk m...@fe33.blk...
** Unrecognized filesystem type **
Found 5 disks
dw_dm_mdio_init: mdio node is missing, registering legacy mdio
busdw_dm_mdio_init: mdio node is missing, registering legacy mdio
busLoading Boot 'Fedora' failed
EFI boot manager: Cannot load any image
Found EFI removable media binary efi/boot/bootaa64.efi

On Thu, Jul 22, 2021 at 12:30 PM Tom Rini  wrote:
>
> On Thu, Jul 22, 2021 at 06:04:40PM +0200, Michal Simek wrote:
> >
> >
> > On 7/22/21 5:25 PM, Peter Robinson wrote:
> > > This reverts commit 346df7d4fa62afc578d820b3a18815eec765074f.
> > >
> > > This patch broke booting Rockchip systems from U-Boot residing on SPI
> > > flash, for at least the Pinebook Pro and Rockpro64, and also confirmed
> > > with the not yet upstream Helios64.
> > >
> > > Signed-off-by: Peter Robinson 
> > > Cc: T Karthik Reddy 
> > > Cc: Ashok Reddy Soma 
> > > Cc: Michal Simek 
> > > Cc: Pratyush Yadav 
> > > ---
> > >  drivers/spi/spi-uclass.c | 11 ---
> > >  1 file changed, 11 deletions(-)
> > >
> > > diff --git a/drivers/spi/spi-uclass.c b/drivers/spi/spi-uclass.c
> > > index d867b27806..ec7f4652b3 100644
> > > --- a/drivers/spi/spi-uclass.c
> > > +++ b/drivers/spi/spi-uclass.c
> > > @@ -11,7 +11,6 @@
> > >  #include 
> > >  #include 
> > >  #include 
> > > -#include 
> > >  #include 
> > >  #include 
> > >  #include 
> > > @@ -200,16 +199,6 @@ static int spi_post_probe(struct udevice *bus)
> > > ops->set_mode += gd->reloc_off;
> > > if (ops->cs_info)
> > > ops->cs_info += gd->reloc_off;
> > > -   if (ops->mem_ops) {
> > > -   struct spi_controller_mem_ops *mem_ops =
> > > -   (struct spi_controller_mem_ops *)ops->mem_ops;
> > > -   if (mem_ops->adjust_op_size)
> > > -   mem_ops->adjust_op_size += gd->reloc_off;
> > > -   if (mem_ops->supports_op)
> > > -   mem_ops->supports_op += gd->reloc_off;
> > > -   if (mem_ops->exec_op)
> > > -   mem_ops->exec_op += gd->reloc_off;
> > > -   }
> > > reloc_done++;
> > > }
> > >  #endif
> > >
> >
> > This is protected by CONFIG_NEEDS_MANUAL_RELOC which is only enable for
> > m68k and microblaze. I expect rockchip is arm and you should never have
> > this code in your binary. That's why please double check it.
>
> Yes, this really doesn't make sense.  Try also just removing spi-mem.h
> from the file and see if that causes things to work again.  If so, time
> to dig in to that header file to figure out what could be going wrong.
>
> --
> Tom


Re: Help with TI-U-BOOT

2021-07-23 Thread Nishanth Menon
On 14:17-20210723, Antoine Naud wrote:
> Here is the full list of my commands:
> 
> $ sudo apt-get update
> $ sudo apt-get install git-core
> $ sudo apt-get install build-essential autoconf automake bison flex 
> libssl-dev bc u-boot-tools python diffstat texinfo gawk chrpath dos2unix wget 
> unzip socat doxygen libc6:i386 libncurses5:i386 libstdc++6:i386 libz1:i386 
> g++-multilib
> $ sudo apt-get update
> $ sudo apt-get install python3.8
> $ sudo apt-get install python3-distutils
> $ sudo apt-get update
> $ sudo dpkg-reconfigure dash
> 
> $ wget 
> https://developer.arm.com/-/media/Files/downloads/gnu-a/9.2-2019.12/binrel/gcc-arm-9.2-2019.12-x86_64-arm-none-linux-gnueabihf.tar.xz
> $ tar -Jxvf gcc-arm-9.2-2019.12-x86_64-arm-none-linux-gnueabihf.tar.xz -C 
> $HOME
> $ wget 
> https://developer.arm.com/-/media/Files/downloads/gnu-a/9.2-2019.12/binrel/gcc-arm-9.2-2019.12-x86_64-aarch64-none-linux-gnu.tar.xz
> $ tar -Jxvf gcc-arm-9.2-2019.12-x86_64-aarch64-none-linux-gnu.tar.xz -C $HOME
> 
> $ git clone git://arago-project.org/git/projects/oe-layersetup.git tisdk
> $ cd tisdk
> $ ./oe-layertool-setup.sh -f configs/coresdk/coresdk-07.03.00.005-config.txt
> $ cd build
> $ . conf/setenv
> $ export 
> TOOLCHAIN_PATH_ARMV7=$HOME/gcc-arm-9.2-2019.12-x86_64-arm-none-linux-gnueabihf
> $ export 
> TOOLCHAIN_PATH_ARMV8=$HOME/gcc-arm-9.2-2019.12-x86_64-aarch64-none-linux-gnu
> $ MACHINE=adm437x-evm ARAGO_RT_ENABLE=1 bitbake tisdk-base-image
> 
> $ git clone git://git.ti.com/ti-u-boot/ti-u-boot.git

I think you  might have missed a step here -> by default when you clone,
  you get to the master branch which is not aligned with the OE
  configuration you picked. OE recipes is a bit smarter, and picks a specific
  commit in a release and builds with it.

Since I am familiar with the convention, the branch you are looking for
is ti-u-boot-2020.01   So: git checkout ti-u-boot-2020.01   to flip over
to the branch that coresdk-07.03.00.05 -> you can even pick the exact
tag corresponding to the release if you like.


> $ make CROSS_COMPILE=arm-linux-gnueabihf- O=CSCM_build CSCM_defconfig all
Hmm.. personally I did'nt know you could mix defconfig and all step  in
one shot.. but hey, seems to work for me:
$ git branch -v
  mastera15fa1ba67d7 Merge tag 'dm-pull-21jul21' of 
https://gitlab.denx.de/u-boot/custodians/u-boot-dm
* ti-u-boot-2020.01 e995ed0ec11b configs: am64x_sk: Drop unused defconfigs

$ make -j`nproc` CROSS_COMPILE=arm-linux-gnueabihf- O=CSCM_build 
am335x_evm_mini_defconfig all

[...]
  COPYspl/u-boot-spl.bin
  MKIMAGE MLO
  MKIMAGE MLO.byteswap
  CFGCHK  u-boot.cfg

> 

Now, that said, since there is a bit of a mix of TI conventions involved, i 
would
suggest asking for help in https://e2e.ti.com/


-- 
Regards,
Nishanth Menon
Key (0xDDB5849D1736249D) / Fingerprint: F8A2 8693 54EB 8232 17A3  1A34 DDB5 
849D 1736 249D


[PATCH] mkimage: use environment variable MKIMAGE_SIGN_PIN to set pin for OpenSSL Engine

2021-07-23 Thread Marc Kleine-Budde
This patch adds the possibility to pass the PIN the OpenSSL Engine
used during signing via the environment variable MKIMAGE_SIGN_PIN.
This follows the approach used during kernel module
signing ("KBUILD_SIGN_PIN") or UBIFS image
signing ("MKIMAGE_SIGN_PIN").

Signed-off-by: Marc Kleine-Budde 
---
 doc/uImage.FIT/signature.txt |  4 ++--
 lib/rsa/rsa-sign.c   | 11 +++
 2 files changed, 13 insertions(+), 2 deletions(-)

diff --git a/doc/uImage.FIT/signature.txt b/doc/uImage.FIT/signature.txt
index 7cb1c15e5e15..61a72db3c74f 100644
--- a/doc/uImage.FIT/signature.txt
+++ b/doc/uImage.FIT/signature.txt
@@ -533,8 +533,8 @@ Generic engine key ids:
 or
   ""
 
-As mkimage does not at this time support prompting for passwords HSM may need
-key preloading wrapper to be used when invoking mkimage.
+In order to set the pin in the HSM, an environment variable "MKIMAGE_SIGN_PIN"
+can be specified.
 
 The following examples use the Nitrokey Pro using pkcs11 engine. Instructions
 for other devices may vary.
diff --git a/lib/rsa/rsa-sign.c b/lib/rsa/rsa-sign.c
index f4ed11e74a4a..49abec6c83fb 100644
--- a/lib/rsa/rsa-sign.c
+++ b/lib/rsa/rsa-sign.c
@@ -338,6 +338,7 @@ static int rsa_init(void)
 
 static int rsa_engine_init(const char *engine_id, ENGINE **pe)
 {
+   const char *key_pass;
ENGINE *e;
int ret;
 
@@ -362,10 +363,20 @@ static int rsa_engine_init(const char *engine_id, ENGINE 
**pe)
goto err_set_rsa;
}
 
+   key_pass = getenv("MKIMAGE_SIGN_PIN");
+   if (key_pass) {
+   if (!ENGINE_ctrl_cmd_string(e, "PIN", key_pass, 0)) {
+   fprintf(stderr, "Couldn't set PIN\n");
+   ret = -1;
+   goto err_set_pin;
+   }
+   }
+
*pe = e;
 
return 0;
 
+err_set_pin:
 err_set_rsa:
ENGINE_finish(e);
 err_engine_init:
-- 
2.30.2




RE: Help with TI-U-BOOT

2021-07-23 Thread Antoine Naud
Here is the full list of my commands:

$ sudo apt-get update
$ sudo apt-get install git-core
$ sudo apt-get install build-essential autoconf automake bison flex libssl-dev 
bc u-boot-tools python diffstat texinfo gawk chrpath dos2unix wget unzip socat 
doxygen libc6:i386 libncurses5:i386 libstdc++6:i386 libz1:i386 g++-multilib
$ sudo apt-get update
$ sudo apt-get install python3.8
$ sudo apt-get install python3-distutils
$ sudo apt-get update
$ sudo dpkg-reconfigure dash

$ wget 
https://developer.arm.com/-/media/Files/downloads/gnu-a/9.2-2019.12/binrel/gcc-arm-9.2-2019.12-x86_64-arm-none-linux-gnueabihf.tar.xz
$ tar -Jxvf gcc-arm-9.2-2019.12-x86_64-arm-none-linux-gnueabihf.tar.xz -C $HOME
$ wget 
https://developer.arm.com/-/media/Files/downloads/gnu-a/9.2-2019.12/binrel/gcc-arm-9.2-2019.12-x86_64-aarch64-none-linux-gnu.tar.xz
$ tar -Jxvf gcc-arm-9.2-2019.12-x86_64-aarch64-none-linux-gnu.tar.xz -C $HOME

$ git clone git://arago-project.org/git/projects/oe-layersetup.git tisdk
$ cd tisdk
$ ./oe-layertool-setup.sh -f configs/coresdk/coresdk-07.03.00.005-config.txt
$ cd build
$ . conf/setenv
$ export 
TOOLCHAIN_PATH_ARMV7=$HOME/gcc-arm-9.2-2019.12-x86_64-arm-none-linux-gnueabihf
$ export 
TOOLCHAIN_PATH_ARMV8=$HOME/gcc-arm-9.2-2019.12-x86_64-aarch64-none-linux-gnu
$ MACHINE=adm437x-evm ARAGO_RT_ENABLE=1 bitbake tisdk-base-image

$ git clone git://git.ti.com/ti-u-boot/ti-u-boot.git
$ make CROSS_COMPILE=arm-linux-gnueabihf- O=CSCM_build CSCM_defconfig all

-Message d'origine-
De : Ramon Fried  
Envoyé : 23 juillet 2021 10:06
À : Antoine Naud 
Cc : u-boot@lists.denx.de
Objet : Re: Help with TI-U-BOOT

On Fri, Jul 23, 2021 at 3:31 PM Antoine Naud  wrote:
>
> Okay ! Thanks for answering,
>
> Here is the error I got when trying to compile using the command (make 
> CROSS_COMPILE=arm-none-linux-gnueabihf- O=CSCM_build CSCM_defconfig all):
>
> In file included from ../include/dm/of.h:11,
>  from ../include/dm/ofnode.h:12,
>  from ../include/asm-generic/gpio.h:10,
>  from ../arch/arm/include/asm/gpio.h:4,
>  from ../arch/arm/cpu/armv8/hisilicon/pinmux.c:10:
> ../include/dm/of.h: At top level:
> ../arch/arm/include/asm/global_data.h:117:58: error: invalid register name 
> for ‘gd’
>   117 | #define DECLARE_GLOBAL_DATA_PTR  register volatile gd_t *gd asm 
> ("x18")
>   |  ^~
> ../include/dm/of.h:86:1: note: in expansion of macro ‘DECLARE_GLOBAL_DATA_PTR’
>86 | DECLARE_GLOBAL_DATA_PTR;
>   | ^~~
> ../scripts/Makefile.build:253: recipe for target 
> 'arch/arm/cpu/armv8/hisilicon/pinmux.o' failed
> make[4]: *** [arch/arm/cpu/armv8/hisilicon/pinmux.o] Error 1
> ../scripts/Makefile.build:394: recipe for target 
> 'arch/arm/cpu/armv8/hisilicon' failed
> make[3]: *** [arch/arm/cpu/armv8/hisilicon] Error 2
> ../Makefile:1815: recipe for target 'arch/arm/cpu/armv8' failed
> make[2]: *** [arch/arm/cpu/armv8] Error 2
> /home/antoine/tisdk/build/ti-u-boot/Makefile:551: recipe for target 
> '__build_one_by_one' failed
> make[1]: *** [__build_one_by_one] Error 2
> make[1]: Leaving directory '/home/antoine/tisdk/build/ti-u-boot/CSCM_build'
> Makefile:177: recipe for target 'sub-make' failed
> make: *** [sub-make] Error 2
> antoine@ubuntu:~/tisdk/build/ti-u-boot$
>
> thanks,
>
> Antoine
>
> -Message d'origine-
> De : Ramon Fried  Envoyé : 22 juillet 2021 16:13 
> À : Antoine Naud  Cc : u-boot@lists.denx.de 
> Objet : Re: Help with TI-U-BOOT
>
> On Thu, Jul 22, 2021 at 10:57 PM Antoine Naud  wrote:
> >
> > Hi,
> >
> > I don't know if I will join someone, but I try anyway !
> > Can I ask a question about an error I have while compiling the bootloader ?
> >
> > Thanks,
> > Antoine
> Yes, just ask.
Looks like you're using the wrong cross-compiler What instructions are you 
following for building the project ?


[PATCH] board: fsl_validate: Fix resource leak issue

2021-07-23 Thread Kshitiz Varshney
Free dynamically allocated memory before every return statement
in calc_esbchdr_esbc_hash() function.
Verified the secure boot changes using ls1046afrwy board.

Signed-off-by: Kshitiz Varshney 
---
 board/freescale/common/fsl_validate.c | 25 ++---
 1 file changed, 18 insertions(+), 7 deletions(-)

diff --git a/board/freescale/common/fsl_validate.c 
b/board/freescale/common/fsl_validate.c
index 564a8b3b54..05d9a004e7 100644
--- a/board/freescale/common/fsl_validate.c
+++ b/board/freescale/common/fsl_validate.c
@@ -547,14 +547,18 @@ static int calc_esbchdr_esbc_hash(struct 
fsl_secboot_img_priv *img)
 
ret = algo->hash_init(algo, );
/* Copy hash at destination buffer */
-   if (ret)
+   if (ret) {
+   free(ctx);
return ret;
+   }
 
/* Update hash for CSF Header */
ret = algo->hash_update(algo, ctx,
(u8 *)>hdr, sizeof(struct fsl_secboot_img_hdr), 0);
-   if (ret)
+   if (ret) {
+   free(ctx);
return ret;
+   }
 
/* Update the hash with that of srk table if srk flag is 1
 * If IE Table is selected, key is not added in the hash
@@ -581,22 +585,29 @@ static int calc_esbchdr_esbc_hash(struct 
fsl_secboot_img_priv *img)
key_hash = 1;
}
 #endif
-   if (ret)
+   if (ret) {
+   free(ctx);
return ret;
-   if (!key_hash)
+   }
+   if (!key_hash) {
+   free(ctx);
return ERROR_KEY_TABLE_NOT_FOUND;
+   }
 
/* Update hash for actual Image */
ret = algo->hash_update(algo, ctx,
(u8 *)(*(img->img_addr_ptr)), img->img_size, 1);
-   if (ret)
+   if (ret) {
+   free(ctx);
return ret;
+   }
 
/* Copy hash at destination buffer */
ret = algo->hash_finish(algo, ctx, hash_val, algo->digest_size);
-   if (ret)
+   if (ret) {
+   free(ctx);
return ret;
-
+   }
return 0;
 }
 
-- 
2.25.1



[PATCH] board: fsl_validate: Fix resource leak issue

2021-07-23 Thread Kshitiz Varshney
Free dynamically allocated memory before every return statement
in calc_img_key_hash() function.
Verified the secure boot changes using ls1046afrwy board.
Signed-off-by: Kshitiz Varshney 
---
 board/freescale/common/fsl_validate.c | 10 --
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/board/freescale/common/fsl_validate.c 
b/board/freescale/common/fsl_validate.c
index 564a8b3b54..d553bd88a0 100644
--- a/board/freescale/common/fsl_validate.c
+++ b/board/freescale/common/fsl_validate.c
@@ -498,8 +498,11 @@ static int calc_img_key_hash(struct fsl_secboot_img_priv 
*img)
return ret;
 
ret = algo->hash_init(algo, );
-   if (ret)
+   if (ret) {
+   if (ctx)
+   free(ctx);
return ret;
+   }
 
/* Update hash for ESBC key */
 #ifdef CONFIG_KEY_REVOCATION
@@ -518,8 +521,11 @@ static int calc_img_key_hash(struct fsl_secboot_img_priv 
*img)
 
/* Copy hash at destination buffer */
ret = algo->hash_finish(algo, ctx, hash_val, algo->digest_size);
-   if (ret)
+   if (ret) {
+   if (ctx)
+   free(ctx);
return ret;
+   }
 
for (i = 0; i < SHA256_BYTES; i++)
img->img_key_hash[i] = hash_val[i];
-- 
2.25.1



SAMA5D27 - UTMI issue?

2021-07-23 Thread Tim
Hi,

I have a custom board using the SAMA5D27 and basically have u-boot running
now. The only issue I have is that because it uses a 24MHz crystal (like the
SOM EV board) the UTMICKTRIM register needs to be set correctly (not just
for USB - the CAN system runs best from the 480MHz UPLL clock).

I can see code (a driver?) that does this but I don't believe it is being
called (an inspection of the relevant register from the final user app that
u-boot calls shows it has not been set, or not set correctly).

I can see a patch 4 years ago that discusses this but I cannot for the life
of me work out where or how from the myriad of Kconfig options, or anything
else, that this would get called/set/used. Undoubtedly due to my
inexperience with u-boot!

Can someone please point me in the right direction? I don't think it's a
bug/issue as such, I just need what is the magic CONFIG or board specific
function/call, or whatever I need get the code called!

Thanks,

Tim.






Re: using binman fails boot

2021-07-23 Thread Tim Harvey
On Fri, Jul 23, 2021 at 2:41 PM Simon Glass  wrote:
>
> Hi Tim,
>
> On Fri, 23 Jul 2021 at 15:06, Tim Harvey  wrote:
> >
> > On Thu, Jul 22, 2021 at 8:07 PM Simon Glass  wrote:
> > >
> > > Hi Tim,
> > >
> > > On Mon, 19 Jul 2021 at 17:23, Tim Harvey  wrote:
> > > >
> > > > On Sat, Jul 17, 2021 at 7:22 PM Simon Glass  wrote:
> > > > >
> > >
> > > [..]
> > >
> > > > > > But isn't blob-ext@4 a correct name? I can't use 'blob-ext-4' as
> > > > > > that's an unknown entry type.
> > > > >
> > > > > Well you can use any name and specify the type:
> > > > >
> > > > > my-name {
> > > > >type = "blob-ext";
> > > > > };
> > > > >
> > > >
> > > > Ok - I understand.
> > > >
> > > > > >
> > > > > > >
> > > > > > > If you can push your tree somewhere (with this problem) I'll see 
> > > > > > > if I
> > > > > > > can figure out why.
> > > > > > >
> > > > > >
> > > > > > Sure, I pushed it to
> > > > > > https://github.com/Gateworks/uboot-venice/tree/WIP-venice-binman
> > > > > > make imx8mm_venice_defconfig
> > > > > > make
> > > > >
> > > > > OK
> > > > >
> > > > > >
> > > > > > > >
> > > > > > > > BINMAN_VERBOSE=4 indeed prints out a tone of stuff but I'm not 
> > > > > > > > seeing
> > > > > > > > anything for 'blob' below that would seem to indicate one node 
> > > > > > > > name vs
> > > > > > > > another:
> > > > > > >
> > > > > > > Oops you need BINMAN_VERBOSE=5 - see elf.py 
> > > > > > > LookupAndWriteSymbols()
> > > > > > > which has tout.Debug() which is level 5.
> > > > > > >
> > > > > >
> > > > > > LookupAndWriteSymbols ends up doing nothing because
> > > > > > syms.get('__image_copy_start') returns None.
> > > > >
> > > > > Well that is likely the problem.
> > >
> > > I sent a patch to make binman report this as an error.
> > >
> > > I pushed the resulting tree to:
> > >
> > > https://github.com/sjg20/u-boot/tree/try-tim
> > >
> > > Now the error is:
> > >
> > > binman: Section '/binman/u-boot-spl-ddr': Symbol
> > > '_binman_u_boot_any_prop_image_pos'
> > >
> > >in entry '/binman/u-boot-spl-ddr/u-boot-spl/u-boot-spl-nodtb':
> > > Entry 'u-boot-any' not found in list
> > > (u-boot-spl-nodtb,u-boot-spl-dtb,u-boot-spl,blob-ext@1,blob-ext@2,blob-ext@3,blob-ext@4,main-section)
> > >
> > > The problem seems to be that you are asking binman to generate three
> > > independent images. U-Boot is in a FIT which is not in the same image
> > > as SPL. So it is not possible to locate the flash offset of U-Boot
> > > (with in the FIT).
> > >
> > > Can you give me a bit more info about your intent here? Is it to load
> > > U-Boot from the FIT? I so, I suppose it is possible to make binman
> > > access an independent image, if it is told where it starts.
> > >
> > > But why is everything not in one image?
> > >
> >
> > Simon,
> >
> > I would rather have 1 image. I was going off of the imx8mm_evk switch
> > to binman which creates the separate images.
>
> Well at present you are loading a FIT into RAM, I think? Is it coming
> from flash?
>
> If you load a FIT containing U-Boot then you don't need the binman
> symbol stuff, since SPL looks in the FIT for the location of U-Boot.
> There isn't much benefit in having binman point to U-Boot within the
> FIT, since we already have code to find it. It might save a few bytes
> of code, but it would be confusing...I'm not sure if that is worth the
> hassle.
>
> If you want a single image, then you might not want FIT at all...just
> use binman.
>
> It really depends what you want.

Maybe my terminology is all wrong or I'm not making myself clear. I'm
trying to access data inside the SPL binary in board_init_f() 'before'
the SPL has done anything at all with FIT.

I'm using FIT because I have multiple board models (ie multiple DTB's)
supported by a single U-Boot 'board'.

So my boot goes like this:
IMX8M BOOT ROM fetches flash.bin (SPL) from eMMC into OCRAM
SPL configures PMIC and DRAM based on runtime detection of board model
  - at this point in time SPL is using a generic imx8mm-venice.dts
that just supports i2c/uart2/emmc which are common to all venice
boards
  - pmic config is done without dm because we don't have the
board-specific dtb yet which defines the pmic
  - DRAM config is done based on eeprom bytes that specify the DRAM
size/density/etc
  - DRAM config includes loading the 'blobs' to the M4 CPU - these are
the blobs I want to locate in the SPL
SPL locates FIT and starts chugging through it (I don't claim to fully
understand this part)
  - board_fit_config_name_match() is called for each DTB found and I
return a success if the DTB matches the board model found via I2C
EEPROM
SPL loads ATF and executes it
ATF executes? U-Boot (not super clear on all of this either)
U-Boot Proper runs with the board-specific dtb (not imx8mm-venice.dtb
but imx8mm-venice-gw.dtb)

>
> >
> > The whole point of what I'm investigating here has to do with the SPL.
> > OCRAM is at a premium and the current way the IMX8M is handling DDR
> > firmware is to tack it on after the code in the 

Re: using binman fails boot

2021-07-23 Thread Simon Glass
Hi Tim,

On Fri, 23 Jul 2021 at 15:06, Tim Harvey  wrote:
>
> On Thu, Jul 22, 2021 at 8:07 PM Simon Glass  wrote:
> >
> > Hi Tim,
> >
> > On Mon, 19 Jul 2021 at 17:23, Tim Harvey  wrote:
> > >
> > > On Sat, Jul 17, 2021 at 7:22 PM Simon Glass  wrote:
> > > >
> >
> > [..]
> >
> > > > > But isn't blob-ext@4 a correct name? I can't use 'blob-ext-4' as
> > > > > that's an unknown entry type.
> > > >
> > > > Well you can use any name and specify the type:
> > > >
> > > > my-name {
> > > >type = "blob-ext";
> > > > };
> > > >
> > >
> > > Ok - I understand.
> > >
> > > > >
> > > > > >
> > > > > > If you can push your tree somewhere (with this problem) I'll see if 
> > > > > > I
> > > > > > can figure out why.
> > > > > >
> > > > >
> > > > > Sure, I pushed it to
> > > > > https://github.com/Gateworks/uboot-venice/tree/WIP-venice-binman
> > > > > make imx8mm_venice_defconfig
> > > > > make
> > > >
> > > > OK
> > > >
> > > > >
> > > > > > >
> > > > > > > BINMAN_VERBOSE=4 indeed prints out a tone of stuff but I'm not 
> > > > > > > seeing
> > > > > > > anything for 'blob' below that would seem to indicate one node 
> > > > > > > name vs
> > > > > > > another:
> > > > > >
> > > > > > Oops you need BINMAN_VERBOSE=5 - see elf.py LookupAndWriteSymbols()
> > > > > > which has tout.Debug() which is level 5.
> > > > > >
> > > > >
> > > > > LookupAndWriteSymbols ends up doing nothing because
> > > > > syms.get('__image_copy_start') returns None.
> > > >
> > > > Well that is likely the problem.
> >
> > I sent a patch to make binman report this as an error.
> >
> > I pushed the resulting tree to:
> >
> > https://github.com/sjg20/u-boot/tree/try-tim
> >
> > Now the error is:
> >
> > binman: Section '/binman/u-boot-spl-ddr': Symbol
> > '_binman_u_boot_any_prop_image_pos'
> >
> >in entry '/binman/u-boot-spl-ddr/u-boot-spl/u-boot-spl-nodtb':
> > Entry 'u-boot-any' not found in list
> > (u-boot-spl-nodtb,u-boot-spl-dtb,u-boot-spl,blob-ext@1,blob-ext@2,blob-ext@3,blob-ext@4,main-section)
> >
> > The problem seems to be that you are asking binman to generate three
> > independent images. U-Boot is in a FIT which is not in the same image
> > as SPL. So it is not possible to locate the flash offset of U-Boot
> > (with in the FIT).
> >
> > Can you give me a bit more info about your intent here? Is it to load
> > U-Boot from the FIT? I so, I suppose it is possible to make binman
> > access an independent image, if it is told where it starts.
> >
> > But why is everything not in one image?
> >
>
> Simon,
>
> I would rather have 1 image. I was going off of the imx8mm_evk switch
> to binman which creates the separate images.

Well at present you are loading a FIT into RAM, I think? Is it coming
from flash?

If you load a FIT containing U-Boot then you don't need the binman
symbol stuff, since SPL looks in the FIT for the location of U-Boot.
There isn't much benefit in having binman point to U-Boot within the
FIT, since we already have code to find it. It might save a few bytes
of code, but it would be confusing...I'm not sure if that is worth the
hassle.

If you want a single image, then you might not want FIT at all...just
use binman.

It really depends what you want.

>
> The whole point of what I'm investigating here has to do with the SPL.
> OCRAM is at a premium and the current way the IMX8M is handling DDR
> firmware is to tack it on after the code in the SPL image and it gets
> padded to make it easy to locate which is a huge waste of space. I
> figured we can use binman to locate the blobs without the padding.
>
> So, if you take 'just' the spl image here:
> spl: u-boot-spl-ddr {
> filename = "u-boot-spl-ddr.bin";
> pad-byte = <0xff>;
> align-size = <4>;
> align = <4>;
>
> u-boot-spl {
> align-end = <4>;
> };
>
> blob_1: blob-ext@1 {
> filename = "lpddr4_pmu_train_1d_imem.bin";
> size = <0x8000>;
> };
>
> blob_2: blob-ext@2 {
> filename = "lpddr4_pmu_train_1d_dmem.bin";
> size = <0x4000>;
> };
>
> blob_3: blob-ext@3 {
> filename = "lpddr4_pmu_train_2d_imem.bin";
> size = <0x8000>;
> };
>
> blob_4: blob-ext@4 {
> filename = "lpddr4_pmu_train_2d_dmem.bin";
> size = <0x4000>;
> };
> };
>
> My intention is to remove the size arguments above which are currently
> forcing wasted padding and locate the blobs at runtime with binman.

Well you can just remove them.

>
> Based on your other patch it it would seem I'm missing something from
> my lds to add __image_copy_start yet in
> arch/arm/cpu/armv8/u-boot-spl.lds I see:
> .text : {
> . = ALIGN(8);
>

Re: [PATCH v3 2/6] cmd: printf: import busybox-1.33.1 printf.c

2021-07-23 Thread Simon Glass
Hi Roland,

On Fri, 23 Jul 2021 at 06:30, Roland Gaudig
 wrote:
>
> From: Roland Gaudig 
>
> Import printf.c from the Busybox project, which provides Bash like
> format string handling.
>
>   src-url: https://git.busybox.net/busybox/
>   commit bcc5b0e6caca6c7602a6a41f "Bump version to 1.33.1"
>   version: 1.33.1
>
> Signed-off-by: Roland Gaudig 
> ---
>
> (no changes since v1)
>
>  cmd/printf.c | 455 +++
>  1 file changed, 455 insertions(+)
>  create mode 100644 cmd/printf.c

I think I missed the discussion on this. Why can we not use U-Boot's
existing printf()?

If we can't, dot we need to remove the existing U-Boot printf()?
Again, sorry if I missed some discussion.

Regards,
Simon


Re: [PATCH 00/15] lib: Add support for a decimal 0m prefix for numbers

2021-07-23 Thread Simon Glass
Hi,

On Wed, 21 Jul 2021 at 08:46, Simon Glass  wrote:
>
> Hi Wolfgang,
>
> On Wed, 21 Jul 2021 at 01:53, Wolfgang Denk  wrote:
> >
> > Hi,
> >
> > In message <20210720160547.GM9379@bill-the-cat> you wrote:
> > >
> > > > So for example (10)123 would mean decimal 123? I don't know how we
> > > > would parse brackets separately from expressions though.
> > >
> > > (123)10 would be "123" in decimal.  Which is indeed a mouthful.  But it
> > > would also be generic and (123)16 would be 0x123.  So the parsing
> > > shouldn't be too hard, for most commands.  But then yes, expressions
> > > become quite hard.
> >
> > Come on, guys, be serious!  This is a boot loader.  Size matters.
> >
> > Do we _really_ need all this, and is it worth the code size?
> >
> > Simon's patches include some cleanup, which probably even reduces
> > the size, so good.
>
> It reduces U-Boot proper by about 400-700 bytes but not much effect on SPL:
>
> 16: RFC: Change simple_strtoul() et al to default to hex
>arm: evb-ast2500 brppt1_spi brsmarc1
>aarch64: (for 300/301 boards) all -754.8 bss +0.0
> spl/u-boot-spl:all -9.9 spl/u-boot-spl:text -9.9 text -754.8
>arc: (for 10/11 boards) all -242.0 text -242.0
>arm: (for 625/627 boards) all -468.7 bss +0.8 data +0.0 rodata
> +0.0 spl/u-boot-spl:all -1.5 spl/u-boot-spl:bss -0.1
> spl/u-boot-spl:text -1.4 text -469.5
>   m68k: (for 18/18 boards) all -499.1 data +11.8 text -510.9
> microblaze: (for 1/1 boards) all -392.0 bss +44.0 data +4.0 rodata
> -4.0 text -436.0
>   mips: (for 43/43 boards) all -457.5 bss +1.1 text -458.6
>  nds32: (for 2/2 boards) all -206.0 text -206.0
>  nios2: (for 2/2 boards) all -480.0 text -480.0
>powerpc: (for 40/98 boards) all -708.4 text -708.4
>
> >
> > But whether it's 0m123 or 0t123 or 0!123 or ... is pretty much
> > irrelevant - chose one symbol, use it, and be done with that.

Given Roland's setexpr thing and the discussion here I think I will
resend the series with 0n for decimal and drop the binary/octal for
now. It is a tiny size increment and easy to add later if useful.

Regards,
Simon


Re: [PATCH v3 6/6] test: cmd: setexpr: add format string tests

2021-07-23 Thread Simon Glass
Hi Roland,

On Fri, 23 Jul 2021 at 06:30, Roland Gaudig
 wrote:
>
> From: Roland Gaudig 
>
> Add test cases for the setexpr format string operator.
>
> Signed-off-by: Roland Gaudig 
> ---
>
> (no changes since v1)
>
>  test/cmd/setexpr.c | 84 ++
>  1 file changed, 84 insertions(+)
>
> diff --git a/test/cmd/setexpr.c b/test/cmd/setexpr.c
> index 08b6e6e724..0dc94f7e61 100644
> --- a/test/cmd/setexpr.c
> +++ b/test/cmd/setexpr.c
> @@ -386,6 +386,90 @@ static int setexpr_test_str_long(struct unit_test_state 
> *uts)
>  }
>  SETEXPR_TEST(setexpr_test_str_long, UT_TESTF_CONSOLE_REC);
>
> +#ifdef CONFIG_CMD_SETEXPR_FMT
> +/* Test 'setexpr' command with simply setting integers */

comment needs an update

> +static int setexpr_test_fmt(struct unit_test_state *uts)
> +{
> +   u8 *buf;
> +
> +   buf = map_sysmem(0, BUF_SIZE);
> +   memset(buf, '\xff', BUF_SIZE);
> +
> +   /* Test decimal conversion */
> +   ut_assertok(run_command("setexpr fred fmt %d 0xff", 0));
> +   ut_asserteq_str("255", env_get("fred"));

I suggest a blank line before each comment to make this easier to read.

Also how about adding a helper that does the run_command() and returns
the value of env_get("fred") ? Then your tests might fit in one
statement, and perhaps even one line in some cases.

> +   /* Test hexadecimal conversion with 0x prefix and 4 digits */
> +   ut_assertok(run_command("setexpr fred fmt 0x%04x 257", 0));

nit: that should really be %#04x so we teach people to use that
feature. Another one below.

> +   ut_asserteq_str("0x0257", env_get("fred"));
> +   /* Test octal conversion with % prefix */
> +   ut_assertok(run_command("setexpr fred fmt %%%o 8", 0));
> +   ut_asserteq_str("%10", env_get("fred"));
> +   /* Test argument surrounded by %% */
> +   ut_assertok(run_command("setexpr fred fmt %%%x%% 0xff", 0));
> +   ut_asserteq_str("%ff%", env_get("fred"));
> +   /* Test escape sequence */
> +   ut_assertok(run_command("setexpr fred fmt \"hello\\040world\"", 0));
> +   ut_asserteq_str("hello world", env_get("fred"));
> +   /* Test %b with string containing octal escape sequence */
> +   ut_assertok(run_command("setexpr fred fmt oh%bno \137", 0));
> +   ut_asserteq_str("oh_no", env_get("fred"));
> +   /* Test %b with string containing \c escape sequence */
> +   ut_assertok(run_command("setexpr fred fmt hello%bworld \"\\c\"", 0));
> +   ut_asserteq_str("hello", env_get("fred"));
> +   /* Test multiple arguments referencing environment varialbes */
> +   ut_assertok(run_command("setenv a eff", 0));
> +   ut_assertok(run_command("setenv b hello", 0));
> +   ut_assertok(run_command("setenv c 0x63", 0));
> +   ut_assertok(run_command("setenv d world", 0));
> +   ut_assertok(run_command("setexpr fred fmt \"0x%08x-%s-%d-%s\" $a $b 
> $c $d", 0));
> +   ut_asserteq_str("0x0eff-hello-99-world", env_get("fred"));
> +   /* Test with two format specifiers, but only one argument */
> +   ut_assertok(run_command("setexpr fred fmt %d_%x 100", 0));
> +   ut_asserteq_str("256_0", env_get("fred"));
> +   /* Test maximum string length */
> +   ut_assertok(run_command("setexpr fred fmt \"%0127d\" 7b", 0));
> +   
> ut_asserteq_str("123",
>  env_get("fred"));
> +   /* Test maximum unsigned integer size */
> +   ut_assertok(run_command("setexpr fred fmt %u ", 0));

I think this needs to check sizeof(ulong) because this will only work
on 64-bit machines.

How about splitting these ones out into two separate test functions,
one for 32-bit and one for 64-bit?

> +   ut_asserteq_str("18446744073709551615", env_get("fred"));
> +   /* Test maximum positive integer size */
> +   ut_assertok(run_command("setexpr fred fmt %d 7fff", 0));
> +   ut_asserteq_str("9223372036854775807", env_get("fred"));
> +   /* Test maximum negative integer size */
> +   ut_assertok(run_command("setexpr fred fmt %d 8000", 0));
> +   ut_asserteq_str("-9223372036854775808", env_get("fred"));
> +   /* Test minimum negative integer size */
> +   ut_assertok(run_command("setexpr fred fmt %d ", 0));
> +   ut_asserteq_str("-1", env_get("fred"));
> +   /* Test signed value with + sign */
> +   ut_assertok(run_command("setexpr fred fmt %d +5", 0));
> +   ut_asserteq_str("5", env_get("fred"));
> +   /* Test signed value with - sign */
> +   ut_assertok(run_command("setexpr fred fmt %d -4", 0));
> +   ut_asserteq_str("-4", env_get("fred"));
> +   /* Test unsigned value with + sign */
> +   ut_assertok(run_command("setexpr fred fmt %u +3", 0));
> +   ut_asserteq_str("3", env_get("fred"));
> +   /* Test unsigned value with - sign */

Re: [PATCH v3 5/6] doc: usage: add description for setexpr command

2021-07-23 Thread Simon Glass
Hi Roland,

On Fri, 23 Jul 2021 at 06:30, Roland Gaudig
 wrote:
>
> From: Roland Gaudig 
>
> Add usage for the setexpr command. It has been added to describe
> mainly the new setexpr format string operation.
>
> Signed-off-by: Roland Gaudig 
> ---
>
> (no changes since v1)
>
>  MAINTAINERS   |   1 +
>  doc/usage/index.rst   |   1 +
>  doc/usage/setexpr.rst | 148 ++
>  3 files changed, 150 insertions(+)
>  create mode 100644 doc/usage/setexpr.rst

Reviewed-by: Simon Glass 

optional nits below

>
> diff --git a/MAINTAINERS b/MAINTAINERS
> index fe53698878..57c3349ef5 100644
> --- a/MAINTAINERS
> +++ b/MAINTAINERS
> @@ -1053,6 +1053,7 @@ SETEXPR
>  M: Roland Gaudig 
>  S: Maintained
>  F: cmd/printf.c
> +F: doc/usage/setexpr.rst
>
>  SH
>  M: Marek Vasut 
> diff --git a/doc/usage/index.rst b/doc/usage/index.rst
> index 40b796a3a9..719b2c90b9 100644
> --- a/doc/usage/index.rst
> +++ b/doc/usage/index.rst
> @@ -43,6 +43,7 @@ Shell commands
> reset
> sbi
> scp03
> +   setexpr
> size
> true
> ums
> diff --git a/doc/usage/setexpr.rst b/doc/usage/setexpr.rst
> new file mode 100644
> index 00..2e511b1290
> --- /dev/null
> +++ b/doc/usage/setexpr.rst
> @@ -0,0 +1,148 @@
> +.. SPDX-License-Identifier: GPL-2.0+
> +
> +setexpr command
> +===
> +
> +Synopsis
> +
> +
> +::
> +
> +setexpr[.b, .w, .l .s]  [*]  [*]
> +setexpr[.b, .w, .l]  [*]
> +setexpr  fmt  [value]...
> +setexpr  gsub r s [t]
> +setexpr  sub r s [t]
> +
> +Description
> +---
> +
> +The setexpr command is used to set an environment variable to the result
> +of an evaluation.
> +
> +setexpr[.b, .w, .l .s]  [*]  [*]
> + Set environment variable  to the result of the evaluated
> + expression specified by .
> +
> +setexpr[.b, .w, .l] name [*]value
> + Load  into environment variable 
> +
> +setexpr name fmt  value
> + Set environment variable  to the result of the C like
> + format string  evaluation of .
> +
> +setexpr name gsub   []
> + For each substring matching the regular expression  in the
> + string , substitute the string .
> + The result is assigned to .
> + If  is not supplied, use the old value of .
> +
> +setexpr name sub   []
> + Just like gsub(), but replace only the first matching substring
> +
> +The setexpr command takes the following arguments:
> +
> +format
> +This parameter contains a C or Bash like format string.

C- or Bash-like ?

or: C or Bash-like ?

Definitely needs at least one hyphen.

> +The number of arguments is limited to 4.
> +The following format types are supported:
> +
> +c
> +single character
> +d, i
> +decimal value
> +o
> +octal value
> +s
> +string
> +u
> +unsigned decimal value
> +x, X
> +hexadecimal value
> +'%'
> +no conversion, instead a % character will be written
> +
> +Backslash escapes:
> +
> +\" = double quote
> +\\ = backslash
> +\a = alert (bell)
> +\b = backspace
> +\c = produce no further output
> +\f = form feed
> +\n = new line
> +\r = carriage return
> +\t = horizontal tab
> +\v = vertical tab
> +\NNN = octal number (NNN is 0 to 3 digits)

For me this list comes out wrong...may need an extra \ ?

> +
> +name
> +The name of the environment variable to be set
> +
> +op
> +'|'
> +name = value | value2
> +'&'
> +name = value & value2
> +'+'
> +name = value + value2
> +(This is the only operator supported for strings.
> +   It acts as concatenation operator on strings)
> +'^'
> +name = value ^ value2
> +'-'
> +name = value - value2
> +'*'
> +name = value * value2
> +'/'
> +name = value / value2
> +'%'
> +name = value % value2

Those ops might look better as a table.

> +
> +r
> +Regular expression
> +
> +s
> +Substitution string
> +
> +t
> +string
> +
> +value
> +Can either be an integer value, a string.
> +If the pointer prefix '*' is given value is treated as memory address.
> +
> +value2
> +See value
> +
> +Example
> +---
> +
> +::
> +
> +=> setexpr foo fmt %d 0x100
> +=> echo $foo
> +256
> +=>
> +
> +=> setexpr foo fmt 0x%08x 63
> +=> echo $foo
> +0x0063
> +=>
> +
> +=> setexpr foo fmt %%%o 8
> +=> echo $foo
> +%10
> +=>
> +
> +Configuration
> +-
> +
> +The setexpr gsub and sub operations are only available if CONFIG_REGEX=y.

Should we use `CONFIG_REGEX=y` ?


> +
> +Return value
> +
> +
> +The return value $? is set to 0 (true) if the operation was successful.
> +
> +If an error occurs, the return value $? is set to 1 (false).
> --
> 2.25.1
>


Re: [PATCH v3 4/6] cmd: setexpr: add format string handling

2021-07-23 Thread Simon Glass
Hi Roland,

On Fri, 23 Jul 2021 at 06:30, Roland Gaudig
 wrote:
>
> From: Roland Gaudig 
>
> Add format string handling operator to the setexpr command.
> It allows to use C or Bash like format string expressions to be
> evaluated with the result being stored inside the environment variable
> name.
>
>   setexpr  fmt  [value]...
>
> The following example
>
>   setexpr foo fmt "%d, 0x%x" 0x100 ff
>
> will result in $foo being set to "256, 0xff".
>
> Signed-off-by: Roland Gaudig 
> ---
>
> (no changes since v1)
>
>  MAINTAINERS   |   5 +
>  cmd/Kconfig   |   8 +
>  cmd/Makefile  |   1 +
>  cmd/printf.c  | 419 +-
>  cmd/printf.h  |   8 +
>  cmd/setexpr.c |  37 -
>  6 files changed, 300 insertions(+), 178 deletions(-)
>  create mode 100644 cmd/printf.h

Reviewed-by: Simon Glass 

nit below

>
> diff --git a/MAINTAINERS b/MAINTAINERS
> index a6b49b54b9..fe53698878 100644
> --- a/MAINTAINERS
> +++ b/MAINTAINERS
> @@ -1049,6 +1049,11 @@ F:   arch/sandbox/
>  F: doc/arch/sandbox.rst
>  F: include/dt-bindings/*/sandbox*.h
>
> +SETEXPR
> +M: Roland Gaudig 
> +S: Maintained
> +F: cmd/printf.c
> +
>  SH
>  M: Marek Vasut 
>  M: Nobuhiro Iwamatsu 
> diff --git a/cmd/Kconfig b/cmd/Kconfig
> index e40d390f88..f1bcf9ebde 100644
> --- a/cmd/Kconfig
> +++ b/cmd/Kconfig
> @@ -1414,6 +1414,14 @@ config CMD_SETEXPR
>   Also supports loading the value at a memory location into a 
> variable.
>   If CONFIG_REGEX is enabled, setexpr also supports a gsub function.
>
> +config CMD_SETEXPR_FMT
> +   bool "setexpr_fmt"
> +   default n
> +   depends on CMD_SETEXPR
> +   help
> + Evaluate format string expression and store result in an environment
> +   variable.
> +
>  endmenu
>
>  menu "Android support commands"
> diff --git a/cmd/Makefile b/cmd/Makefile
> index 9d10e07f0e..ed3669411e 100644
> --- a/cmd/Makefile
> +++ b/cmd/Makefile
> @@ -141,6 +141,7 @@ obj-$(CONFIG_CMD_SF) += sf.o
>  obj-$(CONFIG_CMD_SCSI) += scsi.o disk.o
>  obj-$(CONFIG_CMD_SHA1SUM) += sha1sum.o
>  obj-$(CONFIG_CMD_SETEXPR) += setexpr.o
> +obj-$(CONFIG_CMD_SETEXPR_FMT) += printf.o
>  obj-$(CONFIG_CMD_SPI) += spi.o
>  obj-$(CONFIG_CMD_STRINGS) += strings.o
>  obj-$(CONFIG_CMD_SMC) += smccc.o
> diff --git a/cmd/printf.c b/cmd/printf.c
> index 337ab8ce5d..e024676743 100644
> --- a/cmd/printf.c
> +++ b/cmd/printf.c
> @@ -1,12 +1,21 @@
> -/* vi: set sw=4 ts=4: */
> +// SPDX-License-Identifier: GPL-2.0+
>  /*
> - * printf - format and print data
> + * Copyright (C) 2021 Weidmüller Interface GmbH & Co. KG
> + * Roland Gaudig 
>   *
>   * Copyright 1999 Dave Cinege
>   * Portions copyright (C) 1990-1996 Free Software Foundation, Inc.
>   *
>   * Licensed under GPLv2 or later, see file LICENSE in this source tree.
>   */
> +/*
> + * This file provides a shell printf like format string expansion as required

This is a bit confusing with all the words run together.

Does it mean a printf-like, format-string expansion feature ?


Re: [PATCH v3 1/6] lib: strto: add simple_strtoll function

2021-07-23 Thread Simon Glass
On Fri, 23 Jul 2021 at 06:29, Roland Gaudig
 wrote:
>
> From: Roland Gaudig 
>
> Add simple_strtoll function for converting a string containing digits
> into a long long int value.
>
> Signed-off-by: Roland Gaudig 
> ---
>
> (no changes since v1)
>
>  include/vsprintf.h | 1 +
>  lib/strto.c| 8 
>  2 files changed, 9 insertions(+)

Reviewed-by: Simon Glass 


Re: [PATCH 13/15] RFC: lib: Support a binary prefix 0y

2021-07-23 Thread Simon Glass
Hi Wolfgang,

On Fri, 23 Jul 2021 at 00:55, Wolfgang Denk  wrote:
>
> Dear Simon,
>
> In message 
>  you 
> wrote:
> >
> > > Drop?  AFAICT we never supported octal. Something like "md 040" will
> > > start dumping at 0x0040, right?
> >
> > There are quite a few places where simple_strtoul() is called with a
> > base of 0. In that case, if the string starts with 0 it is interpreted
> > as octal.
>
> That's a bug, then.

If so it is a 19-year-old bug: (was lib_generic/vsprintc.c)

153d511e369 Initial revision

Regards,
Simon


Re: using binman fails boot

2021-07-23 Thread Tim Harvey
On Thu, Jul 22, 2021 at 8:07 PM Simon Glass  wrote:
>
> Hi Tim,
>
> On Mon, 19 Jul 2021 at 17:23, Tim Harvey  wrote:
> >
> > On Sat, Jul 17, 2021 at 7:22 PM Simon Glass  wrote:
> > >
>
> [..]
>
> > > > But isn't blob-ext@4 a correct name? I can't use 'blob-ext-4' as
> > > > that's an unknown entry type.
> > >
> > > Well you can use any name and specify the type:
> > >
> > > my-name {
> > >type = "blob-ext";
> > > };
> > >
> >
> > Ok - I understand.
> >
> > > >
> > > > >
> > > > > If you can push your tree somewhere (with this problem) I'll see if I
> > > > > can figure out why.
> > > > >
> > > >
> > > > Sure, I pushed it to
> > > > https://github.com/Gateworks/uboot-venice/tree/WIP-venice-binman
> > > > make imx8mm_venice_defconfig
> > > > make
> > >
> > > OK
> > >
> > > >
> > > > > >
> > > > > > BINMAN_VERBOSE=4 indeed prints out a tone of stuff but I'm not 
> > > > > > seeing
> > > > > > anything for 'blob' below that would seem to indicate one node name 
> > > > > > vs
> > > > > > another:
> > > > >
> > > > > Oops you need BINMAN_VERBOSE=5 - see elf.py LookupAndWriteSymbols()
> > > > > which has tout.Debug() which is level 5.
> > > > >
> > > >
> > > > LookupAndWriteSymbols ends up doing nothing because
> > > > syms.get('__image_copy_start') returns None.
> > >
> > > Well that is likely the problem.
>
> I sent a patch to make binman report this as an error.
>
> I pushed the resulting tree to:
>
> https://github.com/sjg20/u-boot/tree/try-tim
>
> Now the error is:
>
> binman: Section '/binman/u-boot-spl-ddr': Symbol
> '_binman_u_boot_any_prop_image_pos'
>
>in entry '/binman/u-boot-spl-ddr/u-boot-spl/u-boot-spl-nodtb':
> Entry 'u-boot-any' not found in list
> (u-boot-spl-nodtb,u-boot-spl-dtb,u-boot-spl,blob-ext@1,blob-ext@2,blob-ext@3,blob-ext@4,main-section)
>
> The problem seems to be that you are asking binman to generate three
> independent images. U-Boot is in a FIT which is not in the same image
> as SPL. So it is not possible to locate the flash offset of U-Boot
> (with in the FIT).
>
> Can you give me a bit more info about your intent here? Is it to load
> U-Boot from the FIT? I so, I suppose it is possible to make binman
> access an independent image, if it is told where it starts.
>
> But why is everything not in one image?
>

Simon,

I would rather have 1 image. I was going off of the imx8mm_evk switch
to binman which creates the separate images.

The whole point of what I'm investigating here has to do with the SPL.
OCRAM is at a premium and the current way the IMX8M is handling DDR
firmware is to tack it on after the code in the SPL image and it gets
padded to make it easy to locate which is a huge waste of space. I
figured we can use binman to locate the blobs without the padding.

So, if you take 'just' the spl image here:
spl: u-boot-spl-ddr {
filename = "u-boot-spl-ddr.bin";
pad-byte = <0xff>;
align-size = <4>;
align = <4>;

u-boot-spl {
align-end = <4>;
};

blob_1: blob-ext@1 {
filename = "lpddr4_pmu_train_1d_imem.bin";
size = <0x8000>;
};

blob_2: blob-ext@2 {
filename = "lpddr4_pmu_train_1d_dmem.bin";
size = <0x4000>;
};

blob_3: blob-ext@3 {
filename = "lpddr4_pmu_train_2d_imem.bin";
size = <0x8000>;
};

blob_4: blob-ext@4 {
filename = "lpddr4_pmu_train_2d_dmem.bin";
size = <0x4000>;
};
};

My intention is to remove the size arguments above which are currently
forcing wasted padding and locate the blobs at runtime with binman.

Based on your other patch it it would seem I'm missing something from
my lds to add __image_copy_start yet in
arch/arm/cpu/armv8/u-boot-spl.lds I see:
.text : {
. = ALIGN(8);
*(.__image_copy_start)
CPUDIR/start.o (.text*)
*(.text*)
} >.sram

My understanding of linker files is pretty slim so perhaps there's
something missing above.

Regards,

Tim


Re: Help with TI-U-BOOT

2021-07-23 Thread Ramon Fried
On Fri, Jul 23, 2021 at 5:17 PM Antoine Naud  wrote:
>
> Here is the full list of my commands:
>
> $ sudo apt-get update
> $ sudo apt-get install git-core
> $ sudo apt-get install build-essential autoconf automake bison flex 
> libssl-dev bc u-boot-tools python diffstat texinfo gawk chrpath dos2unix wget 
> unzip socat doxygen libc6:i386 libncurses5:i386 libstdc++6:i386 libz1:i386 
> g++-multilib
> $ sudo apt-get update
> $ sudo apt-get install python3.8
> $ sudo apt-get install python3-distutils
> $ sudo apt-get update
> $ sudo dpkg-reconfigure dash
>
> $ wget 
> https://developer.arm.com/-/media/Files/downloads/gnu-a/9.2-2019.12/binrel/gcc-arm-9.2-2019.12-x86_64-arm-none-linux-gnueabihf.tar.xz
> $ tar -Jxvf gcc-arm-9.2-2019.12-x86_64-arm-none-linux-gnueabihf.tar.xz -C 
> $HOME
> $ wget 
> https://developer.arm.com/-/media/Files/downloads/gnu-a/9.2-2019.12/binrel/gcc-arm-9.2-2019.12-x86_64-aarch64-none-linux-gnu.tar.xz
> $ tar -Jxvf gcc-arm-9.2-2019.12-x86_64-aarch64-none-linux-gnu.tar.xz -C $HOME
>
> $ git clone git://arago-project.org/git/projects/oe-layersetup.git tisdk
> $ cd tisdk
> $ ./oe-layertool-setup.sh -f configs/coresdk/coresdk-07.03.00.005-config.txt
> $ cd build
> $ . conf/setenv
> $ export 
> TOOLCHAIN_PATH_ARMV7=$HOME/gcc-arm-9.2-2019.12-x86_64-arm-none-linux-gnueabihf
> $ export 
> TOOLCHAIN_PATH_ARMV8=$HOME/gcc-arm-9.2-2019.12-x86_64-aarch64-none-linux-gnu
> $ MACHINE=adm437x-evm ARAGO_RT_ENABLE=1 bitbake tisdk-base-image
>
> $ git clone git://git.ti.com/ti-u-boot/ti-u-boot.git
> $ make CROSS_COMPILE=arm-linux-gnueabihf- O=CSCM_build CSCM_defconfig all
>
> -Message d'origine-
> De : Ramon Fried 
> Envoyé : 23 juillet 2021 10:06
> À : Antoine Naud 
> Cc : u-boot@lists.denx.de
> Objet : Re: Help with TI-U-BOOT
>
> On Fri, Jul 23, 2021 at 3:31 PM Antoine Naud  wrote:
> >
> > Okay ! Thanks for answering,
> >
> > Here is the error I got when trying to compile using the command (make 
> > CROSS_COMPILE=arm-none-linux-gnueabihf- O=CSCM_build CSCM_defconfig all):
> >
> > In file included from ../include/dm/of.h:11,
> >  from ../include/dm/ofnode.h:12,
> >  from ../include/asm-generic/gpio.h:10,
> >  from ../arch/arm/include/asm/gpio.h:4,
> >  from ../arch/arm/cpu/armv8/hisilicon/pinmux.c:10:
> > ../include/dm/of.h: At top level:
> > ../arch/arm/include/asm/global_data.h:117:58: error: invalid register name 
> > for ‘gd’
> >   117 | #define DECLARE_GLOBAL_DATA_PTR  register volatile gd_t *gd asm 
> > ("x18")
> >   |  ^~
> > ../include/dm/of.h:86:1: note: in expansion of macro 
> > ‘DECLARE_GLOBAL_DATA_PTR’
> >86 | DECLARE_GLOBAL_DATA_PTR;
> >   | ^~~
> > ../scripts/Makefile.build:253: recipe for target
> > 'arch/arm/cpu/armv8/hisilicon/pinmux.o' failed
> > make[4]: *** [arch/arm/cpu/armv8/hisilicon/pinmux.o] Error 1
> > ../scripts/Makefile.build:394: recipe for target
> > 'arch/arm/cpu/armv8/hisilicon' failed
> > make[3]: *** [arch/arm/cpu/armv8/hisilicon] Error 2
> > ../Makefile:1815: recipe for target 'arch/arm/cpu/armv8' failed
> > make[2]: *** [arch/arm/cpu/armv8] Error 2
> > /home/antoine/tisdk/build/ti-u-boot/Makefile:551: recipe for target
> > '__build_one_by_one' failed
> > make[1]: *** [__build_one_by_one] Error 2
> > make[1]: Leaving directory '/home/antoine/tisdk/build/ti-u-boot/CSCM_build'
> > Makefile:177: recipe for target 'sub-make' failed
> > make: *** [sub-make] Error 2
> > antoine@ubuntu:~/tisdk/build/ti-u-boot$
> >
> > thanks,
> >
> > Antoine
> >
> > -Message d'origine-
> > De : Ramon Fried  Envoyé : 22 juillet 2021 16:13
> > À : Antoine Naud  Cc : u-boot@lists.denx.de
> > Objet : Re: Help with TI-U-BOOT
> >
> > On Thu, Jul 22, 2021 at 10:57 PM Antoine Naud  
> > wrote:
> > >
> > > Hi,
> > >
> > > I don't know if I will join someone, but I try anyway !
> > > Can I ask a question about an error I have while compiling the bootloader 
> > > ?
> > >
> > > Thanks,
> > > Antoine
> > Yes, just ask.
> Looks like you're using the wrong cross-compiler What instructions are you 
> following for building the project ?
You're using a vendor specific build flow, please take it with them.


Re: [PATCH v5 8/8] test: add first autoboot unit tests

2021-07-23 Thread Tom Rini
On Thu, Jul 08, 2021 at 03:57:40PM +0200, Steffen Jaeckel wrote:

> This adds tests for the crypt-based and plain SHA256-based password hashing
> algorithms in the autoboot flow.
> 
> Signed-off-by: Steffen Jaeckel 
> Reviewed-by: Simon Glass 

Applied to u-boot/master, thanks!

-- 
Tom


signature.asc
Description: PGP signature


Re: [PATCH v5 7/8] common: add support to fallback to plain SHA256

2021-07-23 Thread Tom Rini
On Thu, Jul 08, 2021 at 03:57:39PM +0200, Steffen Jaeckel wrote:

> In case crypt-based hashing is enabled this will be the default mechanism
> that is used. If a user wants to have support for both, the environment
> variable `bootstopusesha256` can be set to `true` to allow plain SHA256
> based hashing of the password.
> 
> Signed-off-by: Steffen Jaeckel 
> Reviewed-by: Simon Glass 

Applied to u-boot/master, thanks!

-- 
Tom


signature.asc
Description: PGP signature


Re: [PATCH v5 6/8] common: add AUTOBOOT_FLUSH_STDIN option

2021-07-23 Thread Tom Rini
On Thu, Jul 08, 2021 at 03:57:38PM +0200, Steffen Jaeckel wrote:

> The key-sequence based unlock mechanisms are sensitive to junk symbols
> that could have been sent to stdin and are still waiting to be retrieved.
> Enabling this option will read all symbols off stdin before displaying the
> autoboot prompt (and starting to read the password from stdin).
> 
> Signed-off-by: Steffen Jaeckel 
> Reviewed-by: Simon Glass 

Applied to u-boot/master, thanks!

-- 
Tom


signature.asc
Description: PGP signature


Re: [PATCH v5 5/8] common: allow disabling of timeout for password entry

2021-07-23 Thread Tom Rini
On Thu, Jul 08, 2021 at 03:57:37PM +0200, Steffen Jaeckel wrote:

> In case a user has to enter a complicated password it is sometimes
> desireable to give the user more time than the default timeout.
> Enabling this feature will disable the timeout entirely in case the user
> presses the  key before entering any other character.
> 
> Signed-off-by: Steffen Jaeckel 
> Reviewed-by: Simon Glass 

Applied to u-boot/master, thanks!

-- 
Tom


signature.asc
Description: PGP signature


Re: [PATCH v5 4/8] common: Rename macro appropriately

2021-07-23 Thread Tom Rini
On Thu, Jul 08, 2021 at 03:57:36PM +0200, Steffen Jaeckel wrote:

> While doing code-review internally this got nitpicked by 2 reviewers, so
> I decided to include this here.
> 
> Signed-off-by: Steffen Jaeckel 
> Reviewed-by: Simon Glass 
> Reviewed-by: Heiko Schocher 

Applied to u-boot/master, thanks!

-- 
Tom


signature.asc
Description: PGP signature


Re: [PATCH v5 2/8] lib: wrap crypt API to hide errno usage

2021-07-23 Thread Tom Rini
On Thu, Jul 08, 2021 at 03:57:34PM +0200, Steffen Jaeckel wrote:

> In order to prevent using the global errno, replace it with a static
> version and create a wrapper function which returns the error value.
> 
> Signed-off-by: Steffen Jaeckel 
> Reviewed-by: Simon Glass 
> Reviewed-by: Heiko Schocher 

Applied to u-boot/master, thanks!

-- 
Tom


signature.asc
Description: PGP signature


Re: [PATCH v5 3/8] common: integrate crypt-based passwords

2021-07-23 Thread Tom Rini
On Thu, Jul 08, 2021 at 03:57:35PM +0200, Steffen Jaeckel wrote:

> Hook into the autoboot flow as an alternative to the existing
> mechanisms.
> 
> Signed-off-by: Steffen Jaeckel 
> Reviewed-by: Simon Glass 
> Reviewed-by: Heiko Schocher 

Applied to u-boot/master, thanks!

-- 
Tom


signature.asc
Description: PGP signature


Re: [PATCH v5 1/8] lib: add crypt subsystem

2021-07-23 Thread Tom Rini
On Thu, Jul 08, 2021 at 03:57:33PM +0200, Steffen Jaeckel wrote:

> Add the basic functionality required to support the standard crypt
> format.
> The files crypt-sha256.c and crypt-sha512.c originate from libxcrypt and
> their formatting is therefor retained.
> The integration is done via a crypt_compare() function in crypt.c.
> 
> ```
> libxcrypt $ git describe --long --always --all
> tags/v4.4.17-0-g6b110bc
> ```
> 
> Signed-off-by: Steffen Jaeckel 
> Reviewed-by: Simon Glass 
> Reviewed-by: Heiko Schocher 

Applied to u-boot/master, thanks!

-- 
Tom


signature.asc
Description: PGP signature


Re: [PATCH v4 3/3] reboot-mode: read the boot mode from RTC memory

2021-07-23 Thread Tom Rini
On Thu, Jun 10, 2021 at 04:56:45PM +0300, Nandor Han wrote:

> RTC devices could provide battery-backed memory that can be used for
> storing the reboot mode magic value.
> 
> Add a new reboot-mode back-end that uses RTC to store the reboot-mode
> magic value. The driver also supports both endianness modes.
> 
> Signed-off-by: Nandor Han 
> Reviewed-by: Simon Glass 

Applied to u-boot/master, thanks!

-- 
Tom


signature.asc
Description: PGP signature


Re: [PATCH v4 2/3] reboot-mode: read the boot mode from GPIOs status

2021-07-23 Thread Tom Rini
On Thu, Jun 10, 2021 at 04:56:44PM +0300, Nandor Han wrote:

> A use case for controlling the boot mode is when the user wants
> to control the device boot by pushing a button without needing to
> go in user-space.
> 
> Add a new backed for reboot mode where GPIOs are used to control the
> reboot-mode. The driver is able to scan a predefined list of GPIOs
> and return the magic value. Having the modes associated with
> the magic value generated based on the GPIO values, allows the
> reboot mode uclass to select the proper mode.
> 
> Signed-off-by: Nandor Han 
> Reviewed-by: Simon Glass 

Applied to u-boot/master, thanks!

-- 
Tom


signature.asc
Description: PGP signature


Re: [PATCH v4 1/3] reboot-mode: add support for reboot mode control

2021-07-23 Thread Tom Rini
On Thu, Jun 10, 2021 at 04:56:43PM +0300, Nandor Han wrote:

> A new driver uclass is created to handle the reboot mode control.
> 
> The new uclass driver is updating an environment variable with the
> configured reboot mode. The mode is extracted from a map provided
> at initialization time. The map contains a list of modes
> and associated ids.
> 
> Signed-off-by: Nandor Han 
> Reviewed-by: Simon Glass 

Applied to u-boot/master, thanks!

-- 
Tom


signature.asc
Description: PGP signature


[PATCH u-boot-mvebu] arm64: a37xx: pinctrl: Correct PWM pins definitions

2021-07-23 Thread Marek Behún
The PWM pins on North Bridge on Armada 37xx can be configured into PWM
or GPIO functions. When in PWM function, each pin can also be configured
to drive low on 0 and tri-state on 1 (LED mode).

The current definitions handle this by declaring two pin groups for each
pin:
- group "pwmN" with functions "pwm" and "gpio"
- group "ledN_od" ("od" for open drain) with functions "led" and "gpio"

This is semantically incorrect. The correct definition for each pin
should be one group with three functions: "pwm", "led" and "gpio".

Change the "pwmN" groups to support "led" function.

Remove "ledN_od" groups. This cannot break backwards compatibility with
older device trees: no device tree uses it since there is no PWM driver
for this SOC yet. Also "ledN_od" groups are not even documented.

Signed-off-by: Marek Behún 
---
This was recently applied also in Linux, see
https://lore.kernel.org/linux-gpio/CACRpkdbkWxw8wEOt2nsiYKLw+=TjFrJX=wyalupctwwc9xg...@mail.gmail.com/T/#t
---
 .../pinctrl/marvell,armada-37xx-pinctrl.txt |  8 
 drivers/pinctrl/mvebu/pinctrl-armada-37xx.c | 17 -
 2 files changed, 12 insertions(+), 13 deletions(-)

diff --git a/doc/device-tree-bindings/pinctrl/marvell,armada-37xx-pinctrl.txt 
b/doc/device-tree-bindings/pinctrl/marvell,armada-37xx-pinctrl.txt
index 86ec11361c..3139a99fa9 100644
--- a/doc/device-tree-bindings/pinctrl/marvell,armada-37xx-pinctrl.txt
+++ b/doc/device-tree-bindings/pinctrl/marvell,armada-37xx-pinctrl.txt
@@ -38,19 +38,19 @@ group emmc_nb
 
 group pwm0
  - pin 11 (GPIO1-11)
- - functions pwm, gpio
+ - functions pwm, led, gpio
 
 group pwm1
  - pin 12
- - functions pwm, gpio
+ - functions pwm, led, gpio
 
 group pwm2
  - pin 13
- - functions pwm, gpio
+ - functions pwm, led, gpio
 
 group pwm3
  - pin 14
- - functions pwm, gpio
+ - functions pwm, led, gpio
 
 group pmic1
  - pin 7
diff --git a/drivers/pinctrl/mvebu/pinctrl-armada-37xx.c 
b/drivers/pinctrl/mvebu/pinctrl-armada-37xx.c
index b9d389e70f..1cf1f06f10 100644
--- a/drivers/pinctrl/mvebu/pinctrl-armada-37xx.c
+++ b/drivers/pinctrl/mvebu/pinctrl-armada-37xx.c
@@ -160,10 +160,14 @@ static struct armada_37xx_pin_group 
armada_37xx_nb_groups[] = {
PIN_GRP_GPIO("jtag", 20, 5, BIT(0), "jtag"),
PIN_GRP_GPIO("sdio0", 8, 3, BIT(1), "sdio"),
PIN_GRP_GPIO("emmc_nb", 27, 9, BIT(2), "emmc"),
-   PIN_GRP_GPIO("pwm0", 11, 1, BIT(3), "pwm"),
-   PIN_GRP_GPIO("pwm1", 12, 1, BIT(4), "pwm"),
-   PIN_GRP_GPIO("pwm2", 13, 1, BIT(5), "pwm"),
-   PIN_GRP_GPIO("pwm3", 14, 1, BIT(6), "pwm"),
+   PIN_GRP_GPIO_3("pwm0", 11, 1, BIT(3) | BIT(20), 0, BIT(20), BIT(3),
+  "pwm", "led"),
+   PIN_GRP_GPIO_3("pwm1", 11, 1, BIT(4) | BIT(21), 0, BIT(21), BIT(4),
+  "pwm", "led"),
+   PIN_GRP_GPIO_3("pwm2", 11, 1, BIT(5) | BIT(22), 0, BIT(22), BIT(5),
+  "pwm", "led"),
+   PIN_GRP_GPIO_3("pwm3", 11, 1, BIT(6) | BIT(23), 0, BIT(23), BIT(6),
+  "pwm", "led"),
PIN_GRP_GPIO("pmic1", 7, 1, BIT(7), "pmic"),
PIN_GRP_GPIO("pmic0", 6, 1, BIT(8), "pmic"),
PIN_GRP_GPIO("i2c2", 2, 2, BIT(9), "i2c"),
@@ -177,11 +181,6 @@ static struct armada_37xx_pin_group 
armada_37xx_nb_groups[] = {
PIN_GRP_EXTRA("uart2", 9, 2, BIT(1) | BIT(13) | BIT(14) | BIT(19),
  BIT(1) | BIT(13) | BIT(14), BIT(1) | BIT(19),
  18, 2, "gpio", "uart"),
-   PIN_GRP_GPIO("led0_od", 11, 1, BIT(20), "led"),
-   PIN_GRP_GPIO("led1_od", 12, 1, BIT(21), "led"),
-   PIN_GRP_GPIO("led2_od", 13, 1, BIT(22), "led"),
-   PIN_GRP_GPIO("led3_od", 14, 1, BIT(23), "led"),
-
 };
 
 static struct armada_37xx_pin_group armada_37xx_sb_groups[] = {
-- 
2.31.1



[PATCH] qemu-riscv64_smode: fix extlinux (define preboot)

2021-07-23 Thread Dimitri John Ledkov
Commit 37304aaf60bf ("Convert CONFIG_USE_PREBOOT and CONFIG_PREBOOT to
Kconfig") removed preboot commands in RISC-V targets and broke
extlinux support as reported by Fu Wei .

The patch finishes migration of CONFIG_USE_PREBOOT and CONFIG_REBOOT
to Kconfig.

Signed-off-by: David Abdurachmanov 
Signed-off-by: Dimitri John Ledkov 
---

 Original patch author is David Abdurachmanov

 Previously this was submitted in 2019
 
https://patchwork.ozlabs.org/project/uboot/patch/20190821190720.4286-1-david.abdurachma...@sifive.com/

 Since then the sifive fu540 portion of this change was merged, but
 not the qemu one.

 Submitting the qemu portion again. Without this change, qemu smode
 cannot boot Ubuntu's riscv64 cloud images with extlinux.conf.


 configs/qemu-riscv64_smode_defconfig | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/configs/qemu-riscv64_smode_defconfig 
b/configs/qemu-riscv64_smode_defconfig
index 564e41..cb674c6a75 100644
--- a/configs/qemu-riscv64_smode_defconfig
+++ b/configs/qemu-riscv64_smode_defconfig
@@ -14,3 +14,5 @@ CONFIG_CMD_NVEDIT_EFI=y
 CONFIG_OF_PRIOR_STAGE=y
 CONFIG_SYS_RELOC_GD_ENV_ADDR=y
 CONFIG_DM_MTD=y
+CONFIG_USE_PREBOOT=y
+CONFIG_PREBOOT="setenv fdt_addr ${fdtcontroladdr}; fdt addr ${fdtcontroladdr};"
-- 
2.30.2



Re: Help with TI-U-BOOT

2021-07-23 Thread Ramon Fried
On Fri, Jul 23, 2021 at 3:31 PM Antoine Naud  wrote:
>
> Okay ! Thanks for answering,
>
> Here is the error I got when trying to compile using the command (make 
> CROSS_COMPILE=arm-none-linux-gnueabihf- O=CSCM_build CSCM_defconfig all):
>
> In file included from ../include/dm/of.h:11,
>  from ../include/dm/ofnode.h:12,
>  from ../include/asm-generic/gpio.h:10,
>  from ../arch/arm/include/asm/gpio.h:4,
>  from ../arch/arm/cpu/armv8/hisilicon/pinmux.c:10:
> ../include/dm/of.h: At top level:
> ../arch/arm/include/asm/global_data.h:117:58: error: invalid register name 
> for ‘gd’
>   117 | #define DECLARE_GLOBAL_DATA_PTR  register volatile gd_t *gd asm 
> ("x18")
>   |  ^~
> ../include/dm/of.h:86:1: note: in expansion of macro ‘DECLARE_GLOBAL_DATA_PTR’
>86 | DECLARE_GLOBAL_DATA_PTR;
>   | ^~~
> ../scripts/Makefile.build:253: recipe for target 
> 'arch/arm/cpu/armv8/hisilicon/pinmux.o' failed
> make[4]: *** [arch/arm/cpu/armv8/hisilicon/pinmux.o] Error 1
> ../scripts/Makefile.build:394: recipe for target 
> 'arch/arm/cpu/armv8/hisilicon' failed
> make[3]: *** [arch/arm/cpu/armv8/hisilicon] Error 2
> ../Makefile:1815: recipe for target 'arch/arm/cpu/armv8' failed
> make[2]: *** [arch/arm/cpu/armv8] Error 2
> /home/antoine/tisdk/build/ti-u-boot/Makefile:551: recipe for target 
> '__build_one_by_one' failed
> make[1]: *** [__build_one_by_one] Error 2
> make[1]: Leaving directory '/home/antoine/tisdk/build/ti-u-boot/CSCM_build'
> Makefile:177: recipe for target 'sub-make' failed
> make: *** [sub-make] Error 2
> antoine@ubuntu:~/tisdk/build/ti-u-boot$
>
> thanks,
>
> Antoine
>
> -Message d'origine-
> De : Ramon Fried 
> Envoyé : 22 juillet 2021 16:13
> À : Antoine Naud 
> Cc : u-boot@lists.denx.de
> Objet : Re: Help with TI-U-BOOT
>
> On Thu, Jul 22, 2021 at 10:57 PM Antoine Naud  wrote:
> >
> > Hi,
> >
> > I don't know if I will join someone, but I try anyway !
> > Can I ask a question about an error I have while compiling the bootloader ?
> >
> > Thanks,
> > Antoine
> Yes, just ask.
Looks like you're using the wrong cross-compiler
What instructions are you following for building the project ?


Re: [PATCH] test/py: Improve check for mksquashfs version

2021-07-23 Thread João Marcos Costa
Em qui., 22 de jul. de 2021 às 17:52, Marek Behún  escreveu:
>
> Some builds of squashfs-tools append version string with "-git" or
> similar. The float() conversion will fail in this case.
>
> Improve the code to only convert to float() the string before the '-'
> character.
>
> Signed-off-by: Marek Behún 
> ---
>  test/py/tests/test_fs/test_squashfs/sqfs_common.py | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/test/py/tests/test_fs/test_squashfs/sqfs_common.py 
> b/test/py/tests/test_fs/test_squashfs/sqfs_common.py
> index 267c4b57d1..8b84c2cdca 100644
> --- a/test/py/tests/test_fs/test_squashfs/sqfs_common.py
> +++ b/test/py/tests/test_fs/test_squashfs/sqfs_common.py
> @@ -146,7 +146,7 @@ def get_mksquashfs_version():
>  out = subprocess.run(['mksquashfs -version'], shell=True, check=True,
>   capture_output=True, text=True)
>  # 'out' is: mksquashfs version X (/mm/dd) ...
> -return float(out.stdout.split()[2])
> +return float(out.stdout.split()[2].split('-')[0])
>
>  def check_mksquashfs_version():
>  """ Checks if mksquashfs meets the required version. """
> --
> 2.31.1
>

Reviewed-by: Joao Marcos Costa 

Thanks!

-- 
Atenciosamente,
João Marcos Costa

www.linkedin.com/in/jmarcoscosta/
https://github.com/jmarcoscosta


RE: Help with TI-U-BOOT

2021-07-23 Thread Antoine Naud
Okay ! Thanks for answering,

Here is the error I got when trying to compile using the command (make 
CROSS_COMPILE=arm-none-linux-gnueabihf- O=CSCM_build CSCM_defconfig all): 

In file included from ../include/dm/of.h:11,
 from ../include/dm/ofnode.h:12,
 from ../include/asm-generic/gpio.h:10,
 from ../arch/arm/include/asm/gpio.h:4,
 from ../arch/arm/cpu/armv8/hisilicon/pinmux.c:10:
../include/dm/of.h: At top level:
../arch/arm/include/asm/global_data.h:117:58: error: invalid register name for 
‘gd’
  117 | #define DECLARE_GLOBAL_DATA_PTR  register volatile gd_t *gd asm ("x18")
  |  ^~
../include/dm/of.h:86:1: note: in expansion of macro ‘DECLARE_GLOBAL_DATA_PTR’
   86 | DECLARE_GLOBAL_DATA_PTR;
  | ^~~
../scripts/Makefile.build:253: recipe for target 
'arch/arm/cpu/armv8/hisilicon/pinmux.o' failed
make[4]: *** [arch/arm/cpu/armv8/hisilicon/pinmux.o] Error 1
../scripts/Makefile.build:394: recipe for target 'arch/arm/cpu/armv8/hisilicon' 
failed
make[3]: *** [arch/arm/cpu/armv8/hisilicon] Error 2
../Makefile:1815: recipe for target 'arch/arm/cpu/armv8' failed
make[2]: *** [arch/arm/cpu/armv8] Error 2
/home/antoine/tisdk/build/ti-u-boot/Makefile:551: recipe for target 
'__build_one_by_one' failed
make[1]: *** [__build_one_by_one] Error 2
make[1]: Leaving directory '/home/antoine/tisdk/build/ti-u-boot/CSCM_build'
Makefile:177: recipe for target 'sub-make' failed
make: *** [sub-make] Error 2
antoine@ubuntu:~/tisdk/build/ti-u-boot$

thanks,

Antoine

-Message d'origine-
De : Ramon Fried  
Envoyé : 22 juillet 2021 16:13
À : Antoine Naud 
Cc : u-boot@lists.denx.de
Objet : Re: Help with TI-U-BOOT

On Thu, Jul 22, 2021 at 10:57 PM Antoine Naud  wrote:
>
> Hi,
>
> I don't know if I will join someone, but I try anyway !
> Can I ask a question about an error I have while compiling the bootloader ?
>
> Thanks,
> Antoine
Yes, just ask.


Re: [PATCH] net: remove CONFIG_NET_MULTI (again)

2021-07-23 Thread Tom Rini
On Wed, Jul 14, 2021 at 09:12:41AM +0200, Michal Simek wrote:

> CONFIG_NET_MULTI has been removed long time ago by commit 795428fc679f
> ("net: remove CONFIG_NET_MULTI") but 4 boards were added later which wasn't
> found.  The patch is removing this reference from 4 boards.
> 
> Signed-off-by: Michal Simek 
> Reviewed-by: Chris Packham 

Applied to u-boot/master, thanks!

-- 
Tom


signature.asc
Description: PGP signature


Re: [PATCH] mux: correct prototype for mux_control_try_select()

2021-07-23 Thread Tom Rini
On Tue, Jul 13, 2021 at 11:02:18PM +0200, Patrick Wildt wrote:

> The macro should be passed a state, which should be passed
> to the actual function.  Otherwise using that macro would
> yield a build error.
> 
> Signed-off-by: Patrick Wildt 
> Reviewed-by: Pratyush Yadav 

Applied to u-boot/master, thanks!

-- 
Tom


signature.asc
Description: PGP signature


Re: [PATCH] arm: vexpress64: juno: Enable distro_bootcmd functionality

2021-07-23 Thread Tom Rini
On Mon, Jul 12, 2021 at 12:25:15AM +0100, Andre Przywara wrote:

> The ARM Juno boards can be used as somewhat decent machines to run
> off-the-shelf distributions, with USB, SATA, GBit Ethernet and 8GB of
> DRAM.
> 
> With stable DTs in the board's NOR flash this would work really nicely,
> however the default boot command is to fetch a kernel and an initrd from
> the on-board NOR flash, which sounds somewhat embedded.
> 
> Include the config_distro_bootcmd.h header and define the available
> devices (starting with USB, to catch USB installer sticks) to make
> distributions and UEFI work out of the box.
> The NOR flash kernel functionality is still preserved as the last
> resort, should all other methods fail.
> 
> Signed-off-by: Andre Przywara 
> Reviewed-by: Simon Glass 
> Reviewed-by: Linus Walleij 

Applied to u-boot/master, thanks!

-- 
Tom


signature.asc
Description: PGP signature


Re: [PATCH] distro_boot: Fix block device after DHCP boot sequence

2021-07-23 Thread Tom Rini
On Mon, Jul 12, 2021 at 12:07:09AM +0100, Andre Przywara wrote:

> The generic distro boot sequence iterates over several types of devices,
> trying one after another. In doing do, it starts with setting the
> "devtype" variable, then uses this later in more generic commands.
> 
> Now most (block) device types use a local variable for that, but DHCP
> puts the type into the environment, where it shadows any local variables.
> As a consequence any boot attempt after bootcmd_dhcp has been run fails:
> ===
> VExpress64# run bootcmd_dhcp
> ...
> VExpress64# run bootcmd_sata0
> SATA#0:
> (3.0 Gbps)
> SATA#1:
> (No RDY)
> Device 0: Model: 16GB SATA Flash Drive  
> ... is now current device
> Couldn't find partition dhcp 0:1
> ===
> This problem typically doesn't show, because DHCP is mostly the last
> command to try, but is a problem when this order is different, or when
> distro_bootcmd or bootcmd_xxx are run separately or multiple times.
> 
> Let bootcmd_dhcp use a local variable, as the other kids do, to make the
> order of boot commands irrelevant, and allow repeated calls.
> 
> Signed-off-by: Andre Przywara 
> Reviewed-by: Simon Glass 

Applied to u-boot/master, thanks!

-- 
Tom


signature.asc
Description: PGP signature


Re: [PATCH] Kconfig.boot: Make 0x0 the default SYS_TEXT_BASE for POSITION_INDEPENDENT

2021-07-23 Thread Tom Rini
On Fri, Jul 09, 2021 at 10:39:21AM -0400, Tom Rini wrote:

> When we build U-Boot with POSITION_INDEPENDENT we must have
> SYS_TEXT_BASE be set to zero.  Make this the default in that case.
> 
> Signed-off-by: Tom Rini 
> Reviewed-by: Mark Kettenis 

Applied to u-boot/master, thanks!

-- 
Tom


signature.asc
Description: PGP signature


Re: [PATCH] fit: Allow external data for FDTs

2021-07-23 Thread Tom Rini
On Fri, Jun 25, 2021 at 05:58:04PM +0100, John Keeping wrote:

> Switch to fit_image_get_data_and_size() for consistency with all other
> data loaded from FIT.
> 
> Signed-off-by: John Keeping 
> Reviewed-by: Simon Glass 

Applied to u-boot/master, thanks!

-- 
Tom


signature.asc
Description: PGP signature


Re: [PATCH] cmd: part: Correct error handling

2021-07-23 Thread Tom Rini
On Tue, Jun 22, 2021 at 10:40:01AM +0100, Anders Dellien wrote:

> As 'part_get_info_by_name' now returns more status codes than just
> -1 to indicate failure, we need to update the return value check.
> 
> Signed-off-by: Anders Dellien 
> Reviewed-by: Sean Anderson 

Applied to u-boot/master, thanks!

-- 
Tom


signature.asc
Description: PGP signature


Re: [PATCH 2/2] i2c: pcf8575: Add support for 8 bit I2C IO expanders (like pca8574)

2021-07-23 Thread Tom Rini
On Mon, Jun 07, 2021 at 02:26:34PM +0200, Lukasz Majewski wrote:

> This patch add support for using NXP's pca8574 I2C IO expander, which
> has only 8 IO lines.
> 
> After this change the .data member's information from struct udevice_id
> are used to either sent one or two bytes.
> 
> Moreover, the '_le16' suffix from pcf8575_i2c_{write|read}_le16()
> functions have been removed as now we also sent 8 bit data.
> 
> Signed-off-by: Lukasz Majewski 
> Reviewed-by: Heiko Schocher 

Applied to u-boot/master, thanks!

-- 
Tom


signature.asc
Description: PGP signature


Re: [PATCH 1/2] i2c: pcf8575: Remove not used members of pcf8575_chip structure

2021-07-23 Thread Tom Rini
On Mon, Jun 07, 2021 at 02:26:33PM +0200, Lukasz Majewski wrote:

> Those members are not used anymore as ones from gpio_dev_priv
> structure (when DM_GPIO support is enabled) are used instead.
> 
> Signed-off-by: Lukasz Majewski 
> Reviewed-by: Heiko Schocher 

Applied to u-boot/master, thanks!

-- 
Tom


signature.asc
Description: PGP signature


Re: [PATCH] spl: fit: Also record architecture in /fit-images

2021-07-23 Thread Tom Rini
On Mon, May 31, 2021 at 10:57:07AM +0200, Michal Simek wrote:

> On ARM64 secure OS can run as 64bit or 32bit that's why it is necessary to
> record information about architecture that other code can read it and
> properly pass it to TF-A and start in 64bit or 32bit mode.
> 
> Signed-off-by: Michal Simek 
> Reviewed-by: Simon Glass 

Applied to u-boot/master, thanks!

-- 
Tom


signature.asc
Description: PGP signature


Re: [PATCH v3 2/2] cmd: pinmux: support pin name in status command

2021-07-23 Thread Tom Rini
On Fri, May 21, 2021 at 09:47:32AM +0200, Patrick Delaunay wrote:

> Allow pin name parameter for pimux staus command,
> as gpio command to get status of one pin.
> 
> The possible usage of the command is:
> 
> > pinmux dev pinctrl
> > pinmux status
> 
> > pinmux status -a
> 
> > pinmux status 
> 
> Signed-off-by: Patrick Delaunay 
> Reviewed-by: Simon Glass 

Applied to u-boot/master, thanks!

-- 
Tom


signature.asc
Description: PGP signature


Re: [PATCH v3 1/2] cmd: pinmux: update result of do_status

2021-07-23 Thread Tom Rini
On Fri, May 21, 2021 at 09:47:31AM +0200, Patrick Delaunay wrote:

> Update the result of do_status and always returns a CMD_RET_ value
> (-ENOSYS was a possible result of show_pinmux).
> 
> This patch also adds pincontrol name in error messages (dev->name)
> and treats correctly the status sub command when pin-controller device is
> not selected.
> 
> Signed-off-by: Patrick Delaunay 
> Reviewed-by: Simon Glass 

Applied to u-boot/master, thanks!

-- 
Tom


signature.asc
Description: PGP signature


Re: [PATCH v2] tee: optee: sync cache on pre-reloc OP-TEE invocation

2021-07-23 Thread Tom Rini
On Wed, May 19, 2021 at 04:27:41PM +0200, Etienne Carriere wrote:

> This change ensures both U-Boot and OP-TEE see the same content
> from shared memory when OP-TEE is invoked prior U-Boot relocation.
> 
> This change is required since U-Boot may execute with data cache off
> while OP-TEE always enables cache on memory shared with U-Boot.
> 
> Signed-off-by: Etienne Carriere 
> Reviewed-by: Jens Wiklander 
> Acked-by: Ilias Apalodimas 

Applied to u-boot/master, thanks!

-- 
Tom


signature.asc
Description: PGP signature


Re: [PATCH] spl: use CONFIG_IS_ENABLED(LOAD_FIT_FULL)

2021-07-23 Thread Tom Rini
On Wed, May 19, 2021 at 03:05:53PM +0100, John Keeping wrote:

> It's possible that LOAD_FIT_FULL will have different values for TPL and
> SPL, in which case just checking CONFIG_SPL_LOAD_FIT_FULL causes this to
> be compiled in to the TPL even though functions and struct members it
> depends on are not.
> 
> Use CONFIG_IS_ENABLED() to ensure the correct TPL/SPL variant is
> checked.
> 
> Signed-off-by: John Keeping 
> Reviewed-by: Bin Meng 
> Reviewed-by: Simon Glass 

Applied to u-boot/master, thanks!

-- 
Tom


signature.asc
Description: PGP signature


[PATCH v3 6/6] test: cmd: setexpr: add format string tests

2021-07-23 Thread Roland Gaudig
From: Roland Gaudig 

Add test cases for the setexpr format string operator.

Signed-off-by: Roland Gaudig 
---

(no changes since v1)

 test/cmd/setexpr.c | 84 ++
 1 file changed, 84 insertions(+)

diff --git a/test/cmd/setexpr.c b/test/cmd/setexpr.c
index 08b6e6e724..0dc94f7e61 100644
--- a/test/cmd/setexpr.c
+++ b/test/cmd/setexpr.c
@@ -386,6 +386,90 @@ static int setexpr_test_str_long(struct unit_test_state 
*uts)
 }
 SETEXPR_TEST(setexpr_test_str_long, UT_TESTF_CONSOLE_REC);
 
+#ifdef CONFIG_CMD_SETEXPR_FMT
+/* Test 'setexpr' command with simply setting integers */
+static int setexpr_test_fmt(struct unit_test_state *uts)
+{
+   u8 *buf;
+
+   buf = map_sysmem(0, BUF_SIZE);
+   memset(buf, '\xff', BUF_SIZE);
+
+   /* Test decimal conversion */
+   ut_assertok(run_command("setexpr fred fmt %d 0xff", 0));
+   ut_asserteq_str("255", env_get("fred"));
+   /* Test hexadecimal conversion with 0x prefix and 4 digits */
+   ut_assertok(run_command("setexpr fred fmt 0x%04x 257", 0));
+   ut_asserteq_str("0x0257", env_get("fred"));
+   /* Test octal conversion with % prefix */
+   ut_assertok(run_command("setexpr fred fmt %%%o 8", 0));
+   ut_asserteq_str("%10", env_get("fred"));
+   /* Test argument surrounded by %% */
+   ut_assertok(run_command("setexpr fred fmt %%%x%% 0xff", 0));
+   ut_asserteq_str("%ff%", env_get("fred"));
+   /* Test escape sequence */
+   ut_assertok(run_command("setexpr fred fmt \"hello\\040world\"", 0));
+   ut_asserteq_str("hello world", env_get("fred"));
+   /* Test %b with string containing octal escape sequence */
+   ut_assertok(run_command("setexpr fred fmt oh%bno \137", 0));
+   ut_asserteq_str("oh_no", env_get("fred"));
+   /* Test %b with string containing \c escape sequence */
+   ut_assertok(run_command("setexpr fred fmt hello%bworld \"\\c\"", 0));
+   ut_asserteq_str("hello", env_get("fred"));
+   /* Test multiple arguments referencing environment varialbes */
+   ut_assertok(run_command("setenv a eff", 0));
+   ut_assertok(run_command("setenv b hello", 0));
+   ut_assertok(run_command("setenv c 0x63", 0));
+   ut_assertok(run_command("setenv d world", 0));
+   ut_assertok(run_command("setexpr fred fmt \"0x%08x-%s-%d-%s\" $a $b $c 
$d", 0));
+   ut_asserteq_str("0x0eff-hello-99-world", env_get("fred"));
+   /* Test with two format specifiers, but only one argument */
+   ut_assertok(run_command("setexpr fred fmt %d_%x 100", 0));
+   ut_asserteq_str("256_0", env_get("fred"));
+   /* Test maximum string length */
+   ut_assertok(run_command("setexpr fred fmt \"%0127d\" 7b", 0));
+   
ut_asserteq_str("123",
 env_get("fred"));
+   /* Test maximum unsigned integer size */
+   ut_assertok(run_command("setexpr fred fmt %u ", 0));
+   ut_asserteq_str("18446744073709551615", env_get("fred"));
+   /* Test maximum positive integer size */
+   ut_assertok(run_command("setexpr fred fmt %d 7fff", 0));
+   ut_asserteq_str("9223372036854775807", env_get("fred"));
+   /* Test maximum negative integer size */
+   ut_assertok(run_command("setexpr fred fmt %d 8000", 0));
+   ut_asserteq_str("-9223372036854775808", env_get("fred"));
+   /* Test minimum negative integer size */
+   ut_assertok(run_command("setexpr fred fmt %d ", 0));
+   ut_asserteq_str("-1", env_get("fred"));
+   /* Test signed value with + sign */
+   ut_assertok(run_command("setexpr fred fmt %d +5", 0));
+   ut_asserteq_str("5", env_get("fred"));
+   /* Test signed value with - sign */
+   ut_assertok(run_command("setexpr fred fmt %d -4", 0));
+   ut_asserteq_str("-4", env_get("fred"));
+   /* Test unsigned value with + sign */
+   ut_assertok(run_command("setexpr fred fmt %u +3", 0));
+   ut_asserteq_str("3", env_get("fred"));
+   /* Test unsigned value with - sign */
+   ut_assertok(run_command("setexpr fred fmt %x -2", 0));
+   ut_asserteq_str("fffe", env_get("fred"));
+   /* Error test with missing format specifier */
+   ut_asserteq(1, run_command("setexpr fred fmd hello 0xff", 0));
+   /* Error test with invalid format type */
+   ut_asserteq(1, run_command("setexpr fred fmt %a 0xff", 0));
+   /* Error test with incomplete format specifier */
+   ut_asserteq(1, run_command("setexpr fred fmt hello% bf", 0));
+   /* Error exceeding maximum string length */
+   ut_asserteq(1, run_command("setexpr fred fmt \"%0128d\" 456", 0));
+
+   unmap_sysmem(buf);
+
+   return 0;
+}
+
+SETEXPR_TEST(setexpr_test_fmt, UT_TESTF_CONSOLE_REC);
+#endif
+
 int do_ut_setexpr(struct cmd_tbl *cmdtp, int flag, int argc, char 

[PATCH v3 5/6] doc: usage: add description for setexpr command

2021-07-23 Thread Roland Gaudig
From: Roland Gaudig 

Add usage for the setexpr command. It has been added to describe
mainly the new setexpr format string operation.

Signed-off-by: Roland Gaudig 
---

(no changes since v1)

 MAINTAINERS   |   1 +
 doc/usage/index.rst   |   1 +
 doc/usage/setexpr.rst | 148 ++
 3 files changed, 150 insertions(+)
 create mode 100644 doc/usage/setexpr.rst

diff --git a/MAINTAINERS b/MAINTAINERS
index fe53698878..57c3349ef5 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -1053,6 +1053,7 @@ SETEXPR
 M: Roland Gaudig 
 S: Maintained
 F: cmd/printf.c
+F: doc/usage/setexpr.rst
 
 SH
 M: Marek Vasut 
diff --git a/doc/usage/index.rst b/doc/usage/index.rst
index 40b796a3a9..719b2c90b9 100644
--- a/doc/usage/index.rst
+++ b/doc/usage/index.rst
@@ -43,6 +43,7 @@ Shell commands
reset
sbi
scp03
+   setexpr
size
true
ums
diff --git a/doc/usage/setexpr.rst b/doc/usage/setexpr.rst
new file mode 100644
index 00..2e511b1290
--- /dev/null
+++ b/doc/usage/setexpr.rst
@@ -0,0 +1,148 @@
+.. SPDX-License-Identifier: GPL-2.0+
+
+setexpr command
+===
+
+Synopsis
+
+
+::
+
+setexpr[.b, .w, .l .s]  [*]  [*]
+setexpr[.b, .w, .l]  [*]
+setexpr  fmt  [value]...
+setexpr  gsub r s [t]
+setexpr  sub r s [t]
+
+Description
+---
+
+The setexpr command is used to set an environment variable to the result
+of an evaluation.
+
+setexpr[.b, .w, .l .s]  [*]  [*]
+ Set environment variable  to the result of the evaluated
+ expression specified by .
+
+setexpr[.b, .w, .l] name [*]value
+ Load  into environment variable 
+
+setexpr name fmt  value
+ Set environment variable  to the result of the C like
+ format string  evaluation of .
+
+setexpr name gsub   []
+ For each substring matching the regular expression  in the
+ string , substitute the string .
+ The result is assigned to .
+ If  is not supplied, use the old value of .
+
+setexpr name sub   []
+ Just like gsub(), but replace only the first matching substring
+
+The setexpr command takes the following arguments:
+
+format
+This parameter contains a C or Bash like format string.
+The number of arguments is limited to 4.
+The following format types are supported:
+
+c
+single character
+d, i
+decimal value
+o
+octal value
+s
+string
+u
+unsigned decimal value
+x, X
+hexadecimal value
+'%'
+no conversion, instead a % character will be written
+
+Backslash escapes:
+
+\" = double quote
+\\ = backslash
+\a = alert (bell)
+\b = backspace
+\c = produce no further output
+\f = form feed
+\n = new line
+\r = carriage return
+\t = horizontal tab
+\v = vertical tab
+\NNN = octal number (NNN is 0 to 3 digits)
+
+name
+The name of the environment variable to be set
+
+op
+'|'
+name = value | value2
+'&'
+name = value & value2
+'+'
+name = value + value2
+(This is the only operator supported for strings.
+   It acts as concatenation operator on strings)
+'^'
+name = value ^ value2
+'-'
+name = value - value2
+'*'
+name = value * value2
+'/'
+name = value / value2
+'%'
+name = value % value2
+
+r
+Regular expression
+
+s
+Substitution string
+
+t
+string
+
+value
+Can either be an integer value, a string.
+If the pointer prefix '*' is given value is treated as memory address.
+
+value2
+See value
+
+Example
+---
+
+::
+
+=> setexpr foo fmt %d 0x100
+=> echo $foo
+256
+=>
+
+=> setexpr foo fmt 0x%08x 63
+=> echo $foo
+0x0063
+=>
+
+=> setexpr foo fmt %%%o 8
+=> echo $foo
+%10
+=>
+
+Configuration
+-
+
+The setexpr gsub and sub operations are only available if CONFIG_REGEX=y.
+
+Return value
+
+
+The return value $? is set to 0 (true) if the operation was successful.
+
+If an error occurs, the return value $? is set to 1 (false).
-- 
2.25.1



[PATCH v3 4/6] cmd: setexpr: add format string handling

2021-07-23 Thread Roland Gaudig
From: Roland Gaudig 

Add format string handling operator to the setexpr command.
It allows to use C or Bash like format string expressions to be
evaluated with the result being stored inside the environment variable
name.

  setexpr  fmt  [value]...

The following example

  setexpr foo fmt "%d, 0x%x" 0x100 ff

will result in $foo being set to "256, 0xff".

Signed-off-by: Roland Gaudig 
---

(no changes since v1)

 MAINTAINERS   |   5 +
 cmd/Kconfig   |   8 +
 cmd/Makefile  |   1 +
 cmd/printf.c  | 419 +-
 cmd/printf.h  |   8 +
 cmd/setexpr.c |  37 -
 6 files changed, 300 insertions(+), 178 deletions(-)
 create mode 100644 cmd/printf.h

diff --git a/MAINTAINERS b/MAINTAINERS
index a6b49b54b9..fe53698878 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -1049,6 +1049,11 @@ F:   arch/sandbox/
 F: doc/arch/sandbox.rst
 F: include/dt-bindings/*/sandbox*.h
 
+SETEXPR
+M: Roland Gaudig 
+S: Maintained
+F: cmd/printf.c
+
 SH
 M: Marek Vasut 
 M: Nobuhiro Iwamatsu 
diff --git a/cmd/Kconfig b/cmd/Kconfig
index e40d390f88..f1bcf9ebde 100644
--- a/cmd/Kconfig
+++ b/cmd/Kconfig
@@ -1414,6 +1414,14 @@ config CMD_SETEXPR
  Also supports loading the value at a memory location into a variable.
  If CONFIG_REGEX is enabled, setexpr also supports a gsub function.
 
+config CMD_SETEXPR_FMT
+   bool "setexpr_fmt"
+   default n
+   depends on CMD_SETEXPR
+   help
+ Evaluate format string expression and store result in an environment
+   variable.
+
 endmenu
 
 menu "Android support commands"
diff --git a/cmd/Makefile b/cmd/Makefile
index 9d10e07f0e..ed3669411e 100644
--- a/cmd/Makefile
+++ b/cmd/Makefile
@@ -141,6 +141,7 @@ obj-$(CONFIG_CMD_SF) += sf.o
 obj-$(CONFIG_CMD_SCSI) += scsi.o disk.o
 obj-$(CONFIG_CMD_SHA1SUM) += sha1sum.o
 obj-$(CONFIG_CMD_SETEXPR) += setexpr.o
+obj-$(CONFIG_CMD_SETEXPR_FMT) += printf.o
 obj-$(CONFIG_CMD_SPI) += spi.o
 obj-$(CONFIG_CMD_STRINGS) += strings.o
 obj-$(CONFIG_CMD_SMC) += smccc.o
diff --git a/cmd/printf.c b/cmd/printf.c
index 337ab8ce5d..e024676743 100644
--- a/cmd/printf.c
+++ b/cmd/printf.c
@@ -1,12 +1,21 @@
-/* vi: set sw=4 ts=4: */
+// SPDX-License-Identifier: GPL-2.0+
 /*
- * printf - format and print data
+ * Copyright (C) 2021 Weidmüller Interface GmbH & Co. KG
+ * Roland Gaudig 
  *
  * Copyright 1999 Dave Cinege
  * Portions copyright (C) 1990-1996 Free Software Foundation, Inc.
  *
  * Licensed under GPLv2 or later, see file LICENSE in this source tree.
  */
+/*
+ * This file provides a shell printf like format string expansion as required
+ * for the setexpr  fmt   command.
+ * This source file was mostly taken from the BusyBox project (www.busybox.net)
+ * In contrast to the original sources the output is not written to stdout
+ * anymore but into a char array, which can be used as input for the env_set()
+ * function.
+ */
 /* Usage: printf format [argument...]
  *
  * A front end to the printf function that lets it be used from the shell.
@@ -59,8 +68,6 @@
 //usage:   "$ printf \"Val=%d\\n\" 5\n"
 //usage:   "Val=5\n"
 
-#include "libbb.h"
-
 /* A note on bad input: neither bash 3.2 nor coreutils 6.10 stop on it.
  * They report it:
  *  bash: printf: XXX: invalid number
@@ -77,22 +84,97 @@
  * We try to be compatible.
  */
 
-typedef void FAST_FUNC (*converter)(const char *arg, void *result);
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
 
 #define WANT_HEX_ESCAPES 0
+#define PRINT_CONVERSION_ERROR 1
+#define PRINT_TRUNCATED_ERROR 2
+#define PRINT_SIZE_ERROR 4
+
+struct print_inf {
+   char *str;
+   size_t size;
+   size_t offset;
+   unsigned int error;
+};
+
+typedef void (*converter)(const char *arg, void *result);
+
+/**
+ * printf_str() - print formatted into char array with length checks
+ *
+ * This function povides a printf like function for printing into a char array
+ * with checking the boundaries.
+ * Unlike snprintf, all checks are performed inside this function and status
+ * reports are stored inside the print_inf struct. That way, this function can
+ * be used almost as drop-in replacement without needing much code changes.
+ * Unlike snprintf errors are not reported by return value, but inside the
+ * error member of struct print_inf. The output stored inside the struct
+ * print_inf str member shall only be used when the error member is 0.
+ *
+ * @inf: Info structure for print operation
+ * @char: format string with optional arguments
+ */
+static void printf_str(struct print_inf *inf, char *format, ...)
+{
+   va_list args;
+   int i;
 
-/* Usual "this only works for ascii compatible encodings" disclaimer. */
-#undef _tolower
-#define _tolower(X) ((X)|((char) 0x20))
+   if (!inf)
+   return;
+
+   /* Do not write anything if previous error is pending */
+   if (inf->error)
+   return;
+
+   /* Check if end of receiving buffer is already 

[PATCH v3 3/6] cmd: printf: add helper functions from busybox

2021-07-23 Thread Roland Gaudig
From: Roland Gaudig 

Import the following helper functions from Busybox-1.33.1 which are
required by printf.c:

  process_escape_sequence from libbb/process_escape_sequence.c,
  skip_whitespace from libbb/skip_whitespace.c,
  overlapping_strcpy  from libbb/safe_strncpy.c

  src-url: https://git.busybox.net/busybox/
  commit bcc5b0e6caca6c7602a6a41f "Bump version to 1.33.1"
  version: 1.33.1

Signed-off-by: Roland Gaudig 
---

(no changes since v1)

 cmd/printf.c | 121 +++
 1 file changed, 121 insertions(+)

diff --git a/cmd/printf.c b/cmd/printf.c
index a20fc33013..337ab8ce5d 100644
--- a/cmd/printf.c
+++ b/cmd/printf.c
@@ -79,6 +79,127 @@
 
 typedef void FAST_FUNC (*converter)(const char *arg, void *result);
 
+#define WANT_HEX_ESCAPES 0
+
+/* Usual "this only works for ascii compatible encodings" disclaimer. */
+#undef _tolower
+#define _tolower(X) ((X)|((char) 0x20))
+
+char FAST_FUNC bb_process_escape_sequence(const char **ptr)
+{
+   const char *q;
+   unsigned num_digits;
+   unsigned n;
+   unsigned base;
+
+   num_digits = n = 0;
+   base = 8;
+   q = *ptr;
+
+   if (WANT_HEX_ESCAPES && *q == 'x') {
+   ++q;
+   base = 16;
+   ++num_digits;
+   }
+
+   /* bash requires leading 0 in octal escapes:
+* \02 works, \2 does not (prints \ and 2).
+* We treat \2 as a valid octal escape sequence. */
+   do {
+   unsigned r;
+   unsigned d = (unsigned char)(*q) - '0';
+#if WANT_HEX_ESCAPES
+   if (d >= 10) {
+   d = (unsigned char)_tolower(*q) - 'a';
+   //d += 10;
+   /* The above would map 'A'-'F' and 'a'-'f' to 10-15,
+* however, some chars like '@' would map to 9 < base.
+* Do not allow that, map invalid chars to N > base:
+*/
+   if ((int)d >= 0)
+   d += 10;
+   }
+#endif
+   if (d >= base) {
+   if (WANT_HEX_ESCAPES && base == 16) {
+   --num_digits;
+   if (num_digits == 0) {
+   /* \x: return '\',
+* leave ptr pointing to x */
+   return '\\';
+   }
+   }
+   break;
+   }
+
+   r = n * base + d;
+   if (r > UCHAR_MAX) {
+   break;
+   }
+
+   n = r;
+   ++q;
+   } while (++num_digits < 3);
+
+   if (num_digits == 0) {
+   /* Not octal or hex escape sequence.
+* Is it one-letter one? */
+
+   /* bash builtin "echo -e '\ec'" interprets \e as ESC,
+* but coreutils "/bin/echo -e '\ec'" does not.
+* Manpages tend to support coreutils way.
+* Update: coreutils added support for \e on 28 Oct 2009. */
+   static const char charmap[] ALIGN1 = {
+   'a',  'b', 'e', 'f',  'n',  'r',  't',  'v',  '\\', 
'\0',
+   '\a', '\b', 27, '\f', '\n', '\r', '\t', '\v', '\\', 
'\\',
+   };
+   const char *p = charmap;
+   do {
+   if (*p == *q) {
+   q++;
+   break;
+   }
+   } while (*++p != '\0');
+   /* p points to found escape char or NUL,
+* advance it and find what it translates to.
+* Note that \NUL and unrecognized sequence \z return '\'
+* and leave ptr pointing to NUL or z. */
+   n = p[sizeof(charmap) / 2];
+   }
+
+   *ptr = q;
+
+   return (char) n;
+}
+
+char* FAST_FUNC skip_whitespace(const char *s)
+{
+   /* In POSIX/C locale (the only locale we care about: do we REALLY want
+* to allow Unicode whitespace in, say, .conf files? nuts!)
+* isspace is only these chars: "\t\n\v\f\r" and space.
+* "\t\n\v\f\r" happen to have ASCII codes 9,10,11,12,13.
+* Use that.
+*/
+   while (*s == ' ' || (unsigned char)(*s - 9) <= (13 - 9))
+   s++;
+
+   return (char *) s;
+}
+
+/* Like strcpy but can copy overlapping strings. */
+void FAST_FUNC overlapping_strcpy(char *dst, const char *src)
+{
+   /* Cheap optimization for dst == src case -
+* better to have it here than in many callers.
+*/
+   if (dst != src) {
+   while ((*dst = *src) != '\0') {
+   dst++;
+   src++;
+   }
+   }
+}
+
 static int multiconvert(const char *arg, void *result, converter convert)
 {
if (*arg == 

[PATCH v3 2/6] cmd: printf: import busybox-1.33.1 printf.c

2021-07-23 Thread Roland Gaudig
From: Roland Gaudig 

Import printf.c from the Busybox project, which provides Bash like
format string handling.

  src-url: https://git.busybox.net/busybox/
  commit bcc5b0e6caca6c7602a6a41f "Bump version to 1.33.1"
  version: 1.33.1

Signed-off-by: Roland Gaudig 
---

(no changes since v1)

 cmd/printf.c | 455 +++
 1 file changed, 455 insertions(+)
 create mode 100644 cmd/printf.c

diff --git a/cmd/printf.c b/cmd/printf.c
new file mode 100644
index 00..a20fc33013
--- /dev/null
+++ b/cmd/printf.c
@@ -0,0 +1,455 @@
+/* vi: set sw=4 ts=4: */
+/*
+ * printf - format and print data
+ *
+ * Copyright 1999 Dave Cinege
+ * Portions copyright (C) 1990-1996 Free Software Foundation, Inc.
+ *
+ * Licensed under GPLv2 or later, see file LICENSE in this source tree.
+ */
+/* Usage: printf format [argument...]
+ *
+ * A front end to the printf function that lets it be used from the shell.
+ *
+ * Backslash escapes:
+ *
+ * \" = double quote
+ * \\ = backslash
+ * \a = alert (bell)
+ * \b = backspace
+ * \c = produce no further output
+ * \f = form feed
+ * \n = new line
+ * \r = carriage return
+ * \t = horizontal tab
+ * \v = vertical tab
+ * \0ooo = octal number (ooo is 0 to 3 digits)
+ * \xhhh = hexadecimal number (hhh is 1 to 3 digits)
+ *
+ * Additional directive:
+ *
+ * %b = print an argument string, interpreting backslash escapes
+ *
+ * The 'format' argument is re-used as many times as necessary
+ * to convert all of the given arguments.
+ *
+ * David MacKenzie 
+ */
+/* 19990508 Busy Boxed! Dave Cinege */
+
+//config:config PRINTF
+//config:  bool "printf (3.8 kb)"
+//config:  default y
+//config:  help
+//config:  printf is used to format and print specified strings.
+//config:  It's similar to 'echo' except it has more options.
+
+//applet:IF_PRINTF(APPLET_NOFORK(printf, printf, BB_DIR_USR_BIN, BB_SUID_DROP, 
printf))
+
+//kbuild:lib-$(CONFIG_PRINTF) += printf.o
+//kbuild:lib-$(CONFIG_ASH_PRINTF)  += printf.o
+//kbuild:lib-$(CONFIG_HUSH_PRINTF) += printf.o
+
+//usage:#define printf_trivial_usage
+//usage:   "FORMAT [ARG]..."
+//usage:#define printf_full_usage "\n\n"
+//usage:   "Format and print ARG(s) according to FORMAT (a-la C printf)"
+//usage:
+//usage:#define printf_example_usage
+//usage:   "$ printf \"Val=%d\\n\" 5\n"
+//usage:   "Val=5\n"
+
+#include "libbb.h"
+
+/* A note on bad input: neither bash 3.2 nor coreutils 6.10 stop on it.
+ * They report it:
+ *  bash: printf: XXX: invalid number
+ *  printf: XXX: expected a numeric value
+ *  bash: printf: 123XXX: invalid number
+ *  printf: 123XXX: value not completely converted
+ * but then they use 0 (or partially converted numeric prefix) as a value
+ * and continue. They exit with 1 in this case.
+ * Both accept insane field width/precision (e.g. %99.99d).
+ * Both print error message and assume 0 if %*.*f width/precision is "bad"
+ *  (but negative numbers are not "bad").
+ * Both accept negative numbers for %u specifier.
+ *
+ * We try to be compatible.
+ */
+
+typedef void FAST_FUNC (*converter)(const char *arg, void *result);
+
+static int multiconvert(const char *arg, void *result, converter convert)
+{
+   if (*arg == '"' || *arg == '\'') {
+   arg = utoa((unsigned char)arg[1]);
+   }
+   errno = 0;
+   convert(arg, result);
+   if (errno) {
+   bb_error_msg("invalid number '%s'", arg);
+   return 1;
+   }
+   return 0;
+}
+
+static void FAST_FUNC conv_strtoull(const char *arg, void *result)
+{
+   /* Allow leading '+' - bb_strtoull() by itself does not allow it,
+* and probably shouldn't (other callers might require purely numeric
+* inputs to be allowed.
+*/
+   if (arg[0] == '+')
+   arg++;
+   *(unsigned long long*)result = bb_strtoull(arg, NULL, 0);
+   /* both coreutils 6.10 and bash 3.2:
+* $ printf '%x\n' -2
+* fffe
+* Mimic that:
+*/
+   if (errno) {
+   *(unsigned long long*)result = bb_strtoll(arg, NULL, 0);
+   }
+}
+static void FAST_FUNC conv_strtoll(const char *arg, void *result)
+{
+   if (arg[0] == '+')
+   arg++;
+   *(long long*)result = bb_strtoll(arg, NULL, 0);
+}
+static void FAST_FUNC conv_strtod(const char *arg, void *result)
+{
+   char *end;
+   /* Well, this one allows leading whitespace... so what? */
+   /* What I like much less is that "-" accepted too! :( */
+   *(double*)result = strtod(arg, );
+   if (end[0]) {
+   errno = ERANGE;
+   *(double*)result = 0;
+   }
+}
+
+/* Callers should check errno to detect errors */
+static unsigned long long my_xstrtoull(const char *arg)
+{
+   unsigned long long result;
+   if (multiconvert(arg, , conv_strtoull))
+   result = 0;
+   return result;
+}
+static long long my_xstrtoll(const char *arg)
+{

[PATCH v3 1/6] lib: strto: add simple_strtoll function

2021-07-23 Thread Roland Gaudig
From: Roland Gaudig 

Add simple_strtoll function for converting a string containing digits
into a long long int value.

Signed-off-by: Roland Gaudig 
---

(no changes since v1)

 include/vsprintf.h | 1 +
 lib/strto.c| 8 
 2 files changed, 9 insertions(+)

diff --git a/include/vsprintf.h b/include/vsprintf.h
index 2290083eba..4016de6677 100644
--- a/include/vsprintf.h
+++ b/include/vsprintf.h
@@ -41,6 +41,7 @@ int strict_strtoul(const char *cp, unsigned int base, 
unsigned long *res);
 unsigned long long simple_strtoull(const char *cp, char **endp,
unsigned int base);
 long simple_strtol(const char *cp, char **endp, unsigned int base);
+long long simple_strtoll(const char *cp, char **endp, unsigned int base);
 
 /**
  * trailing_strtol() - extract a trailing integer from a string
diff --git a/lib/strto.c b/lib/strto.c
index c00bb5895d..f8b53d846b 100644
--- a/lib/strto.c
+++ b/lib/strto.c
@@ -143,6 +143,14 @@ unsigned long long simple_strtoull(const char *cp, char 
**endp,
return result;
 }
 
+long long simple_strtoll(const char *cp, char **endp, unsigned int base)
+{
+   if (*cp == '-')
+   return -simple_strtoull(cp + 1, endp, base);
+
+   return simple_strtoull(cp, endp, base);
+}
+
 long trailing_strtoln(const char *str, const char *end)
 {
const char *p;
-- 
2.25.1



[PATCH v3 0/6] cmd: setexpr: add fmt format string operation

2021-07-23 Thread Roland Gaudig
From: Roland Gaudig 


In contrast to version 2, the "fmt" operator has been made more flexible
like its Bash counterpart, as some comments to version 2 requested.
For license compatibility reasons the code for parsing the format string
has been taken from the BusyBox project and not from Bash.

The _maxags limit for setexpr has been increased to 8, which allows up
to 4 remaining arguments for the format string.

This patch adds C like format string capabilities to the setexpr
command. Here are some examples:

  => setexpr foo fmt %d 0x100
  => echo $foo
  256
  =>

  => setexpr foo fmt 0x%08x 0x63
  => echo $foo
  0x0063
  =>

  => setexpr foo fmt %%%o 8
  => echo $foo
  %10
  =>

  => setexpr foo fmt \"0x%08x-%s-%d-%s\" $a $b $c $d
  => echo $foo
  0x0eff-hello-99-world
  =>

Format string handling can be turned on by enabling the
CONFIG_CMD_SETEXPR_FMT option. Enabling that option will increase code
size by 2480 bytes on ARM target and 1648 bytes on ARM Thumb2 target.
Handling of float already has been removed. A further reduction is
possible by disabling the escape character handling.

Changes in v3:
 - enable Bash like format string support for the setexpr fmt operator
 - import format string parsing routines from Busybox project

Changes in v2:
 - replace the setexpr dec operator by fmt for simple format strings


(no changes since v1)

Roland Gaudig (6):
  lib: strto: add simple_strtoll function
  cmd: printf: import busybox-1.33.1 printf.c
  cmd: printf: add helper functions from busybox
  cmd: setexpr: add format string handling
  doc: usage: add description for setexpr command
  test: cmd: setexpr: add format string tests

 MAINTAINERS   |   6 +
 cmd/Kconfig   |   8 +
 cmd/Makefile  |   1 +
 cmd/printf.c  | 647 ++
 cmd/printf.h  |   8 +
 cmd/setexpr.c |  37 ++-
 doc/usage/index.rst   |   1 +
 doc/usage/setexpr.rst | 148 ++
 include/vsprintf.h|   1 +
 lib/strto.c   |   8 +
 test/cmd/setexpr.c|  84 ++
 11 files changed, 945 insertions(+), 4 deletions(-)
 create mode 100644 cmd/printf.c
 create mode 100644 cmd/printf.h
 create mode 100644 doc/usage/setexpr.rst

-- 
2.25.1



[PATCH] test/py: tpm2: Skip tpm pytest based on env variable

2021-07-23 Thread Ashok Reddy Soma
From: T Karthik Reddy 

Tpm test cases relies on tpm device setup. Provide an environment
variable "env__tpm_device_test_skip = True" to skip the test case
if tpm device is not present.
Only needed will have to add variable to the py-test framework.
Test runs successfully even this variable is absent.

Signed-off-by: T Karthik Reddy 
Signed-off-by: Ashok Reddy Soma 
---

 test/py/tests/test_tpm2.py | 28 
 1 file changed, 28 insertions(+)

diff --git a/test/py/tests/test_tpm2.py b/test/py/tests/test_tpm2.py
index 70f906da51..bb147d4e88 100644
--- a/test/py/tests/test_tpm2.py
+++ b/test/py/tests/test_tpm2.py
@@ -18,6 +18,15 @@ any password.
 * Commands like pcr_setauthpolicy and pcr_resetauthpolicy are not implemented
 here because they would fail the tests in most cases (TPMs do not implement 
them
 and return an error).
+
+
+Note:
+This test doesn't rely on boardenv_* configuration value but can change test
+behavior.
+
+* Setup env__tpm_device_test_skip to True if tests with TPM devices should be
+skipped.
+
 """
 
 updates = 0
@@ -29,6 +38,9 @@ def force_init(u_boot_console, force=False):
 twice will spawn an error used to detect that the TPM was not reset and no
 initialization code should be run.
 """
+skip_test = u_boot_console.config.env.get('env__tpm_device_test_skip', 
False)
+if skip_test:
+pytest.skip('skip TPM device test')
 output = u_boot_console.run_command('tpm2 init')
 if force or not 'Error' in output:
 u_boot_console.run_command('echo --- start of init ---')
@@ -44,6 +56,10 @@ def force_init(u_boot_console, force=False):
 def test_tpm2_init(u_boot_console):
 """Init the software stack to use TPMv2 commands."""
 
+skip_test = u_boot_console.config.env.get('env__tpm_device_test_skip', 
False)
+if skip_test:
+pytest.skip('skip TPM device test')
+
 u_boot_console.run_command('tpm2 init')
 output = u_boot_console.run_command('echo $?')
 assert output.endswith('0')
@@ -55,6 +71,9 @@ def test_tpm2_startup(u_boot_console):
 Initiate the TPM internal state machine.
 """
 
+skip_test = u_boot_console.config.env.get('env__tpm_device_test_skip', 
False)
+if skip_test:
+pytest.skip('skip TPM device test')
 u_boot_console.run_command('tpm2 startup TPM2_SU_CLEAR')
 output = u_boot_console.run_command('echo $?')
 assert output.endswith('0')
@@ -66,6 +85,9 @@ def test_tpm2_self_test_full(u_boot_console):
 Ask the TPM to perform all self tests to also enable full capabilities.
 """
 
+skip_test = u_boot_console.config.env.get('env__tpm_device_test_skip', 
False)
+if skip_test:
+pytest.skip('skip TPM device test')
 u_boot_console.run_command('tpm2 self_test full')
 output = u_boot_console.run_command('echo $?')
 assert output.endswith('0')
@@ -78,6 +100,9 @@ def test_tpm2_continue_self_test(u_boot_console):
 to enter a fully operational state.
 """
 
+skip_test = u_boot_console.config.env.get('env__tpm_device_test_skip', 
False)
+if skip_test:
+pytest.skip('skip TPM device test')
 u_boot_console.run_command('tpm2 self_test continue')
 output = u_boot_console.run_command('echo $?')
 assert output.endswith('0')
@@ -95,6 +120,9 @@ def test_tpm2_clear(u_boot_console):
 PLATFORM hierarchies are also available.
 """
 
+skip_test = u_boot_console.config.env.get('env__tpm_device_test_skip', 
False)
+if skip_test:
+pytest.skip('skip TPM device test')
 u_boot_console.run_command('tpm2 clear TPM2_RH_LOCKOUT')
 output = u_boot_console.run_command('echo $?')
 assert output.endswith('0')
-- 
2.17.1



Re: Please pull u-boot-net

2021-07-23 Thread Tom Rini
On Thu, Jul 22, 2021 at 11:12:52PM +0300, Ramon Fried wrote:

> Hi Tom,
> 
> Please pull the latest patches in u-boot-net tree.
> 
> The following changes since commit 806734f41b25931798fdf667b5a2ae830229c13f:
> 
>   Merge https://gitlab.denx.de/u-boot/custodians/u-boot-fsl-qoriq
> (2021-07-22 08:45:32 -0400)
> 
> are available in the Git repository at:
> 
>   https://source.denx.de/u-boot/custodians/u-boot-net.git network_master
> 
> for you to fetch changes up to 669884ea6f290e5ec912a2fe4d10c687a04cd239:
> 
>   net: fsl-mc: fix logically dead code (2021-07-22 22:16:26 +0300)
> 

Applied to u-boot/master, thanks!

-- 
Tom


signature.asc
Description: PGP signature


Re: [PATCH V1] arm: add initial support for the Phytium Pomelo Board

2021-07-23 Thread Andre Przywara
On Mon, 19 Jul 2021 17:46:41 +0800
nicholas_zh...@outlook.com wrote:

Hi,

as Peter already mentioned, this should be [PATCH v2], the next
version [PATCH v3], and so on. And please don't resend the same email
(and they are identical, I diffed them) without any comments as to why.
If you want to ping people, reply to your own email.

Now for the technical part:

> From: weichangzheng 
> 
> This adds platform code and the device tree for the Phytium Pomelo Board.
> The initial support comprises the UART and the PCIE.
> 
> Signed-off-by: weichangzheng 
> Changes since v1:
> - updated to DT
> ---
>  arch/arm/Kconfig |   8 ++
>  arch/arm/dts/Makefile|   1 +
>  arch/arm/dts/phytium-pomelo.dts  | 113 +
>  board/phytium/pomelo/Kconfig |  12 +++
>  board/phytium/pomelo/MAINTAINERS |   8 ++
>  board/phytium/pomelo/Makefile|  14 +++
>  board/phytium/pomelo/cpu.h   |  73 ++
>  board/phytium/pomelo/ddr.c   | 164 +++
>  board/phytium/pomelo/pcie.c  |  61 
>  board/phytium/pomelo/pll.c   |  75 ++
>  board/phytium/pomelo/pomelo.c| 120 ++
>  board/phytium/pomelo/sec.c   |  40 
>  configs/pomelo_defconfig |  36 +++
>  include/configs/pomelo.h |  45 +
>  14 files changed, 770 insertions(+)
>  create mode 100644 arch/arm/dts/phytium-pomelo.dts
>  create mode 100644 board/phytium/pomelo/Kconfig
>  create mode 100644 board/phytium/pomelo/MAINTAINERS
>  create mode 100644 board/phytium/pomelo/Makefile
>  create mode 100644 board/phytium/pomelo/cpu.h
>  create mode 100644 board/phytium/pomelo/ddr.c
>  create mode 100644 board/phytium/pomelo/pcie.c
>  create mode 100644 board/phytium/pomelo/pll.c
>  create mode 100644 board/phytium/pomelo/pomelo.c
>  create mode 100644 board/phytium/pomelo/sec.c
>  create mode 100644 configs/pomelo_defconfig
>  create mode 100644 include/configs/pomelo.h
> 
> diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig
> index 0448787b8b..0afbb86640 100644
> --- a/arch/arm/Kconfig
> +++ b/arch/arm/Kconfig
> @@ -1818,6 +1818,13 @@ config TARGET_DURIAN
> Support for durian platform.
> It has 2GB Sdram, uart and pcie.
>  
> +config TARGET_POMELO
> + bool "Support Phytium Pomelo Platform"
> + select ARM64

You should use this stanza here to select more of U-Boot features (see
below).

> + help
> + Support for pomelo platform.
> + It has 2GB Sdram, uart and pcie.
> +
>  config TARGET_PRESIDIO_ASIC
>   bool "Support Cortina Presidio ASIC Platform"
>   select ARM64
> @@ -2038,6 +2045,7 @@ source "board/toradex/colibri_pxa270/Kconfig"
>  source "board/variscite/dart_6ul/Kconfig"
>  source "board/vscom/baltos/Kconfig"
>  source "board/phytium/durian/Kconfig"
> +source "board/phytium/pomelo/Kconfig"
>  source "board/xen/xenguest_arm64/Kconfig"
>  source "board/keymile/Kconfig"
>  
> diff --git a/arch/arm/dts/Makefile b/arch/arm/dts/Makefile
> index 9fb38682e6..45d0340bd3 100644
> --- a/arch/arm/dts/Makefile
> +++ b/arch/arm/dts/Makefile
> @@ -1107,6 +1107,7 @@ dtb-$(CONFIG_TARGET_MX53PPD) += imx53-ppd.dtb
>  dtb-$(CONFIG_TARGET_TOTAL_COMPUTE) += total_compute.dtb
>  
>  dtb-$(CONFIG_TARGET_DURIAN) += phytium-durian.dtb
> +dtb-$(CONFIG_TARGET_POMELO) += phytium-pomelo.dtb
>  
>  dtb-$(CONFIG_TARGET_PRESIDIO_ASIC) += ca-presidio-engboard.dtb
>  
> diff --git a/arch/arm/dts/phytium-pomelo.dts b/arch/arm/dts/phytium-pomelo.dts
> new file mode 100644
> index 00..3869475902
> --- /dev/null
> +++ b/arch/arm/dts/phytium-pomelo.dts
> @@ -0,0 +1,113 @@
> +// SPDX-License-Identifier: GPL-2.0+
> +/*
> + * dts file for Phytium Pomelo board
> + * Copyright (C) 2021, Phytium Ltd.
> + * lixinde 
> + * weichangzheng   
> + */
> +/dts-v1/;
> +
> +/ {
> + model = "Phytium Pomelo";
> + compatible = "phytium,pomelo";
> + #address-cells = <2>;
> + #size-cells = <2>;
> +
> + aliases {
> + serial0 = 
> + };
> +
> + cpus {
> + #address-cells = <0x2>;
> + #size-cells = <0x0>;
> +
> + cpu0: cpu@0 {
> + device_type = "cpu";
> + compatible = "arm,armv8";
> + reg = <0x0 0x0>;
> + enable-method = "psci";
> + numa-node-id = <0>;
> + };
> +
> + cpu1: cpu@1 {
> + device_type = "cpu";
> + compatible = "arm,armv8";
> + reg = <0x0 0x1>;
> + enable-method = "psci";
> + numa-node-id = <0>;
> + };
> +
> + cpu2: cpu@4 {
> + device_type = "cpu";
> + compatible = "arm,armv8";
> + reg = <0x0 0x100>;
> + enable-method = "psci";
> + numa-node-id = <0>;
> + };
> +
> 

RPI 4 U-Boot 2021.01 Yocto fails with Card did not respond to voltage select! : -110

2021-07-23 Thread Kaiwan N Billimoria
Hi all,

Env am using:
Yocto 3.3.1 hardknott
 meta-raspberrypi bsp layer
 U-Boot 2021.01 (it pulls this in)

The boot on an RPi 4B consistently fails with:


U-Boot 2021.01 (Jan 11 2021 - 18:11:43 +)
DRAM: 1.9 GiB
RPI 4 Model B (0xb03114)

MMC: mmcnr@7e30: 1, emmc2@7e34: 0

Loading Environment from FAT... unable to select a mode
In: serial
Out: serial
Err: serial
Net: eth0: ethernet@7d58
PCIe BRCM: link up, 5.0 Gbps x1 (SSC)
starting USB...
Bus xhci_pci: Register 5000420 NbrPorts 5
Starting the controller
USB XHCI 1.00
scanning bus xhci_pci for devices... 2 USB Device(s) found
scanning usb for storage devices... 0 Storage Device(s) found

Hit any key to stop autoboot: 0

switch to partitions #0, OK
mmc0 is current device

** No partition table - mmc 0 **
Card did not respond to voltage select! : -110

Device 0: unknown device
...



Also, FYI:

U-Boot> mmcinfo
Device: emmc2@7e34
Manufacturer ID: 3
OEM: 5344
Name: SL64G
Bus Speed: 2500
Mode: MMC legacy
Rd Block Len: 512
SD version 3.0
High Capacity: Yes
Capacity: 59.5 GiB
Bus Width: 4-bit
Erase Group Size: 512 Bytes
U-Boot>

Should 'Mode' be different?? High Speed?
Unsure as to what will fix this... any help appreciated ! TIA,

Funny thing is, it was working a week back (with Yocto 3.2 - though
even that doesn't work now; same issue)..

Regards,
Kaiwan.


Re: [PATCH v4 2/2] imx: imx8mm: Add support for Kontron Electronics SL/BL i.MX8M-Mini boards (N801x)

2021-07-23 Thread Michael Walle

Hi Frieder,

Am 2021-07-21 10:03, schrieb Frieder Schrempf:

From: Frieder Schrempf 

The Kontron SoM-Line i.MX8MM (N801x) by Kontron Electronics GmbH is a 
SoM
module with an i.MX8M-Mini SoC, 1/2/4 GB LPDDR4 RAM, SPI NOR, eMMC and 
PMIC.


The matching evaluation boards (Board-Line) have 2 Ethernets, USB 2.0,
HDMI/LVDS,
SD card, CAN, RS485 and much more.

Signed-off-by: Frieder Schrempf 
Reviewed-by: Stefano Babic 
---
Fixes in v4:
  * Fix checkpatch errors/warnings

Fixes in v3:
  * None

Fixes in v2:
  * Fix header includes in spl.c
  * Add MAINTAINERS file
  * Rename board directory
  * Add Stefano's R-b tag
---
 arch/arm/dts/Makefile |2 +
 arch/arm/dts/imx8mm-kontron-n801x-s-lvds.dts  |  116 ++
 .../dts/imx8mm-kontron-n801x-s-u-boot.dtsi|  236 +++
 arch/arm/dts/imx8mm-kontron-n801x-s.dts   |  388 
 arch/arm/dts/imx8mm-kontron-n801x-som.dtsi|  298 +++
 arch/arm/mach-imx/imx8m/Kconfig   |8 +
 board/kontron/sl-mx8mm/Kconfig|   15 +
 board/kontron/sl-mx8mm/MAINTAINERS|7 +
 board/kontron/sl-mx8mm/Makefile   |9 +
 board/kontron/sl-mx8mm/imximage.cfg   |9 +
 board/kontron/sl-mx8mm/kontron_mx8mm.c|   99 +


mx8mm.c please


 board/kontron/sl-mx8mm/lpddr4_timing.c| 1844 +
 board/kontron/sl-mx8mm/spl.c  |  321 +++
 configs/kontron_mx8mm_defconfig   |  124 ++
 include/configs/kontron_mx8mm.h   |   67 +


no doc/board/kontron/mx8mm.rst?

-michael


Re: [PATCH v4 1/2] imx: imx6ul: Add support for Kontron Electronics SL/BL i.MX6UL/ULL boards (N63xx/N64xx)

2021-07-23 Thread Michael Walle

Am 2021-07-21 10:03, schrieb Frieder Schrempf:

From: Frieder Schrempf 

This adds support for i.MX6UL/ULL-based evaluation kits with SoMs by
Kontron Electronics GmbH.

Currently there are the following SoM flavors (SoM-Line):
  * N6310: SOM with i.MX6UL-2, 256MB RAM, 256MB SPI NAND
  * N6311: SOM with i.MX6UL-2, 512MB RAM, 512MB SPI NAND
  * N6411: SOM with i.MX6ULL, 512MB RAM, 512MB SPI NAND

And the according evaluation boards (Board-Line):
  * N6310-S: Baseboard with SOM N6310, eMMC, display (optional), ...
  * N6311-S: Baseboard with SOM N6311, eMMC, display (optional), ...
  * N6411-S: Baseboard with SOM N6411, eMMC, display (optional), ...

Currently U-Boot describes i.MX6UL and i.MX6ULL through separate config
options at compile-time. Though the differences are so minor, that for
the scope of these SoMs we just use a single defconfig that is 
compatible

with both SoCs.

Signed-off-by: Frieder Schrempf 
Reviewed-by: Stefano Babic 
---
Fixes in v4:
  * Fix checkpatch errors/warnings
  * Stop disabling initrd/fdt relocation

Fixes in v3:
  * Guard binman nodes to fix build of other UL boards

Fixes in v2:
  * Add MAINTAINERS file
  * Rename board directory
  * Use binman to generate FIT
  * Support legacy images
  * Add Stefano's R-b tag
---
 arch/arm/dts/Makefile |   4 +-
 .../dts/imx6ul-kontron-n631x-s-u-boot.dtsi|   7 +
 arch/arm/dts/imx6ul-kontron-n631x-s.dts   |  17 +
 arch/arm/dts/imx6ul-kontron-n631x-som.dtsi|  14 +
 .../dts/imx6ul-kontron-n6x1x-s-u-boot.dtsi|  98 
 arch/arm/dts/imx6ul-kontron-n6x1x-s.dts   | 423 ++
 arch/arm/dts/imx6ul-kontron-n6x1x-s.dtsi  | 420 +
 .../dts/imx6ul-kontron-n6x1x-som-common.dtsi  | 124 +
 .../dts/imx6ull-kontron-n641x-s-u-boot.dtsi   |   7 +
 arch/arm/dts/imx6ull-kontron-n641x-s.dts  |  16 +
 arch/arm/dts/imx6ull-kontron-n641x-som.dtsi   |  13 +
 arch/arm/mach-imx/mx6/Kconfig |   9 +
 board/kontron/sl-mx6ul/Kconfig|  15 +
 board/kontron/sl-mx6ul/MAINTAINERS|   9 +
 board/kontron/sl-mx6ul/Makefile   |   8 +
 board/kontron/sl-mx6ul/kontron_mx6ul.c|  85 


Can we name that just mx6ul.c and drop the kontron prefix? Just for
consitency reasons.


 board/kontron/sl-mx6ul/spl.c  | 377 
 configs/kontron_mx6ul_defconfig   | 109 +
 include/configs/kontron_common.h  |  84 
 include/configs/kontron_mx6ul.h   |  52 +++


no README in doc/board/kontron/...?


 20 files changed, 1890 insertions(+), 1 deletion(-)
 create mode 100644 arch/arm/dts/imx6ul-kontron-n631x-s-u-boot.dtsi
 create mode 100644 arch/arm/dts/imx6ul-kontron-n631x-s.dts
 create mode 100644 arch/arm/dts/imx6ul-kontron-n631x-som.dtsi
 create mode 100644 arch/arm/dts/imx6ul-kontron-n6x1x-s-u-boot.dtsi
 create mode 100644 arch/arm/dts/imx6ul-kontron-n6x1x-s.dts
 create mode 100644 arch/arm/dts/imx6ul-kontron-n6x1x-s.dtsi
 create mode 100644 arch/arm/dts/imx6ul-kontron-n6x1x-som-common.dtsi
 create mode 100644 arch/arm/dts/imx6ull-kontron-n641x-s-u-boot.dtsi
 create mode 100644 arch/arm/dts/imx6ull-kontron-n641x-s.dts
 create mode 100644 arch/arm/dts/imx6ull-kontron-n641x-som.dtsi
 create mode 100644 board/kontron/sl-mx6ul/Kconfig
 create mode 100644 board/kontron/sl-mx6ul/MAINTAINERS
 create mode 100644 board/kontron/sl-mx6ul/Makefile
 create mode 100644 board/kontron/sl-mx6ul/kontron_mx6ul.c
 create mode 100644 board/kontron/sl-mx6ul/spl.c
 create mode 100644 configs/kontron_mx6ul_defconfig
 create mode 100644 include/configs/kontron_common.h
 create mode 100644 include/configs/kontron_mx6ul.h

diff --git a/arch/arm/dts/Makefile b/arch/arm/dts/Makefile
index 91228b7032..b2b0e50dc5 100644
--- a/arch/arm/dts/Makefile
+++ b/arch/arm/dts/Makefile
@@ -811,7 +811,9 @@ dtb-$(CONFIG_MX6UL) += \
imx6ul-liteboard.dtb \
imx6ul-phytec-segin-ff-rdk-nand.dtb \
imx6ul-pico-hobbit.dtb \
-   imx6ul-pico-pi.dtb
+   imx6ul-pico-pi.dtb \
+   imx6ul-kontron-n631x-s.dtb \
+   imx6ull-kontron-n641x-s.dtb

 dtb-$(CONFIG_MX6ULL) += \
imx6ull-14x14-evk.dtb \
diff --git a/arch/arm/dts/imx6ul-kontron-n631x-s-u-boot.dtsi
b/arch/arm/dts/imx6ul-kontron-n631x-s-u-boot.dtsi
new file mode 100644
index 00..d3f013c58c
--- /dev/null
+++ b/arch/arm/dts/imx6ul-kontron-n631x-s-u-boot.dtsi
@@ -0,0 +1,7 @@
+// SPDX-License-Identifier: GPL-2.0 OR MIT
+/*
+ * Copyright (C) 2017 exceet electronics GmbH
+ * Copyright (C) 2018 Kontron Electronics GmbH


2021? I don't know how that is handled in u-boot though.

[..]

diff --git a/board/kontron/sl-mx6ul/spl.c 
b/board/kontron/sl-mx6ul/spl.c

new file mode 100644
index 00..57760981c5
--- /dev/null
+++ b/board/kontron/sl-mx6ul/spl.c
@@ -0,0 +1,377 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright (C) 2018 Kontron Electronics GmbH
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 

[PATCH u-boot-mvebu v3 23/41] tools: kwboot: Fix wrong parameter passed to read()

2021-07-23 Thread Marek Behún
From: Pali Rohár 

The 'buf' variable is a pointer and '_buf' is the array itself.
Therefore we should pass sizeof(_buf) instead of sizeof(buf) to read().

Signed-off-by: Pali Rohár 
Reviewed-by: Marek Behún 
Reviewed-by: Stefan Roese 
Reviewed-by: Chris Packham 
Tested-by: Chris Packham 
---
 tools/kwboot.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tools/kwboot.c b/tools/kwboot.c
index 2683e5360c..1ba5ded5d3 100644
--- a/tools/kwboot.c
+++ b/tools/kwboot.c
@@ -465,7 +465,7 @@ kwboot_term_pipe(int in, int out, char *quit, int *s)
ssize_t nin, nout;
char _buf[128], *buf = _buf;
 
-   nin = read(in, buf, sizeof(buf));
+   nin = read(in, buf, sizeof(_buf));
if (nin <= 0)
return -1;
 
-- 
2.31.1



[PATCH u-boot-mvebu v3 34/41] SPL: Add support for parsing board / BootROM specific image types

2021-07-23 Thread Marek Behún
From: Pali Rohár 

Platform specific BootROM may use its own image type for loading SPL or
U-Boot proper. In some cases it makes sense to not use BootROM supplied
code for booting U-Boot proper but rather to use U-Boot SPL for this,
e.g. when U-Boot SPL can load U-Boot proper faster than BootROM. In this
case it is required for platform board code to parse and load U-Boot in
BootROM specific image type.

This change adds support for parsing platform / board / BootROM specific
image types via weak function spl_parse_board_header() which is called
before marking boot image as a raw.

Signed-off-by: Pali Rohár 
Reviewed-by: Marek Behún 
Reviewed-by: Stefan Roese 
---
 common/spl/spl.c | 9 +
 1 file changed, 9 insertions(+)

diff --git a/common/spl/spl.c b/common/spl/spl.c
index 3b96f2fc31..1df31de5b3 100644
--- a/common/spl/spl.c
+++ b/common/spl/spl.c
@@ -296,6 +296,12 @@ static int spl_load_fit_image(struct spl_image_info 
*spl_image,
 }
 #endif
 
+__weak int spl_parse_board_header(struct spl_image_info *spl_image,
+ const void *image_header, size_t size)
+{
+   return -EINVAL;
+}
+
 __weak int spl_parse_legacy_header(struct spl_image_info *spl_image,
   const struct image_header *header)
 {
@@ -348,6 +354,9 @@ int spl_parse_image_header(struct spl_image_info *spl_image,
}
 #endif
 
+   if (!spl_parse_board_header(spl_image, (const void *)header, 
sizeof(*header)))
+   return 0;
+
 #ifdef CONFIG_SPL_RAW_IMAGE_SUPPORT
/* Signature not found - assume u-boot.bin */
debug("mkimage signature not found - ih_magic = %x\n",
-- 
2.31.1



[PATCH u-boot-mvebu v3 25/41] tools: kwboot: Print trailing newline after terminal is terminated

2021-07-23 Thread Marek Behún
From: Pali Rohár 

Print trailing newline as the last printed byte can be something
different.

Signed-off-by: Pali Rohár 
Reviewed-by: Marek Behún 
Reviewed-by: Stefan Roese 
Reviewed-by: Chris Packham 
Tested-by: Chris Packham 
---
 tools/kwboot.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/tools/kwboot.c b/tools/kwboot.c
index 7fa742d84c..941f4228f9 100644
--- a/tools/kwboot.c
+++ b/tools/kwboot.c
@@ -560,6 +560,7 @@ kwboot_terminal(int tty)
 
if (in >= 0)
tcsetattr(in, TCSANOW, );
+   printf("\n");
 out:
return rc;
 }
-- 
2.31.1



[PATCH u-boot-mvebu v3 15/41] tools: kwbimage: Add support for more BINARY headers

2021-07-23 Thread Marek Behún
From: Pali Rohár 

The kwbimage v1 format supports multiple BINARY executable headers.
Add support for it into mkimage/kwbimage tool.

Signed-off-by: Pali Rohár 
Reviewed-by: Marek Behún 
Reviewed-by: Chris Packham 
Reviewed-by: Stefan Roese 
Tested-by: Chris Packham 
---
 tools/kwbimage.c | 59 +++-
 1 file changed, 28 insertions(+), 31 deletions(-)

diff --git a/tools/kwbimage.c b/tools/kwbimage.c
index 6c9f93ae8b..1bfc524424 100644
--- a/tools/kwbimage.c
+++ b/tools/kwbimage.c
@@ -942,6 +942,7 @@ static size_t image_headersz_v1(int *hasext)
 {
struct image_cfg_element *binarye;
size_t headersz;
+   int cfgi;
 
/*
 * Calculate the size of the header and the size of the
@@ -949,21 +950,19 @@ static size_t image_headersz_v1(int *hasext)
 */
headersz = sizeof(struct main_hdr_v1);
 
-   if (image_count_options(IMAGE_CFG_BINARY) > 1) {
-   fprintf(stderr, "More than one binary blob, not supported\n");
-   return 0;
-   }
-
if (image_count_options(IMAGE_CFG_PAYLOAD) > 1) {
fprintf(stderr, "More than one payload, not possible\n");
return 0;
}
 
-   binarye = image_find_option(IMAGE_CFG_BINARY);
-   if (binarye) {
+   for (cfgi = 0; cfgi < cfgn; cfgi++) {
int ret;
struct stat s;
 
+   binarye = _cfg[cfgi];
+   if (binarye->type != IMAGE_CFG_BINARY)
+   continue;
+
ret = stat(binarye->binary.file, );
if (ret < 0) {
char cwd[PATH_MAX];
@@ -1018,10 +1017,10 @@ static size_t image_headersz_v1(int *hasext)
return ALIGN(headersz, 4096);
 }
 
-int add_binary_header_v1(uint8_t *cur)
+int add_binary_header_v1(uint8_t **cur, uint8_t **next_ext,
+struct image_cfg_element *binarye)
 {
-   struct image_cfg_element *binarye;
-   struct opt_hdr_v1 *hdr = (struct opt_hdr_v1 *)cur;
+   struct opt_hdr_v1 *hdr = (struct opt_hdr_v1 *)*cur;
uint32_t *args;
size_t binhdrsz;
struct stat s;
@@ -1029,11 +1028,6 @@ int add_binary_header_v1(uint8_t *cur)
FILE *bin;
int ret;
 
-   binarye = image_find_option(IMAGE_CFG_BINARY);
-
-   if (!binarye)
-   return 0;
-
hdr->headertype = OPT_HDR_V1_BINARY_TYPE;
 
bin = fopen(binarye->binary.file, "r");
@@ -1055,17 +1049,17 @@ int add_binary_header_v1(uint8_t *cur)
hdr->headersz_lsb = cpu_to_le16(binhdrsz & 0x);
hdr->headersz_msb = (binhdrsz & 0x) >> 16;
 
-   cur += sizeof(struct opt_hdr_v1);
+   *cur += sizeof(struct opt_hdr_v1);
 
-   args = (uint32_t *)cur;
+   args = (uint32_t *)*cur;
*args = cpu_to_le32(binarye->binary.nargs);
args++;
for (argi = 0; argi < binarye->binary.nargs; argi++)
args[argi] = cpu_to_le32(binarye->binary.args[argi]);
 
-   cur += (binarye->binary.nargs + 1) * sizeof(uint32_t);
+   *cur += (binarye->binary.nargs + 1) * sizeof(uint32_t);
 
-   ret = fread(cur, s.st_size, 1, bin);
+   ret = fread(*cur, s.st_size, 1, bin);
if (ret != 1) {
fprintf(stderr,
"Could not read binary image %s\n",
@@ -1075,17 +1069,13 @@ int add_binary_header_v1(uint8_t *cur)
 
fclose(bin);
 
-   cur += ALIGN(s.st_size, 4);
+   *cur += ALIGN(s.st_size, 4);
 
-   /*
-* For now, we don't support more than one binary
-* header, and no other header types are
-* supported. So, the binary header is necessarily the
-* last one
-*/
-   *((uint32_t *)cur) = 0x;
+   *((uint32_t *)*cur) = 0x;
+   **next_ext = 1;
+   *next_ext = *cur;
 
-   cur += sizeof(uint32_t);
+   *cur += sizeof(uint32_t);
 
return 0;
 
@@ -1218,6 +1208,7 @@ static void *image_create_v1(size_t *imagesz, struct 
image_tool_params *params,
uint8_t *image, *cur;
int hasext = 0;
uint8_t *next_ext = NULL;
+   int cfgi;
 
/*
 * Calculate the size of the header and the size of the
@@ -1296,13 +1287,19 @@ static void *image_create_v1(size_t *imagesz, struct 
image_tool_params *params,
 */
secure_hdr = (struct secure_hdr_v1 *)cur;
cur += sizeof(struct secure_hdr_v1);
+   *next_ext = 1;
next_ext = _hdr->next;
}
 #endif
-   *next_ext = 1;
 
-   if (add_binary_header_v1(cur))
-   return NULL;
+   for (cfgi = 0; cfgi < cfgn; cfgi++) {
+   e = _cfg[cfgi];
+   if (e->type != IMAGE_CFG_BINARY)
+   continue;
+
+   if (add_binary_header_v1(, _ext, e))
+   return NULL;
+   }
 
 #if defined(CONFIG_KWB_SECURE)
if (secure_hdr && 

[PATCH u-boot-mvebu v3 31/41] arm: mvebu: Implement return_to_bootrom() via U-Boot's SPL framework

2021-07-23 Thread Marek Behún
From: Pali Rohár 

U-Boot's SPL framework already has an API for loading U-Boot via
BootROM.

Implement the function board_return_to_bootrom() for mvebu SPL code.

Signed-off-by: Pali Rohár 
Reviewed-by: Marek Behún 
Reviewed-by: Stefan Roese 
Reviewed-by: Chris Packham 
Tested-by: Chris Packham 
---
 arch/arm/mach-mvebu/Kconfig |  4 
 arch/arm/mach-mvebu/spl.c   | 12 
 2 files changed, 16 insertions(+)

diff --git a/arch/arm/mach-mvebu/Kconfig b/arch/arm/mach-mvebu/Kconfig
index cda65f7478..2133d9a172 100644
--- a/arch/arm/mach-mvebu/Kconfig
+++ b/arch/arm/mach-mvebu/Kconfig
@@ -257,6 +257,7 @@ config MVEBU_SPL_BOOT_DEVICE_SPI
select SPL_SPI_FLASH_SUPPORT
select SPL_SPI_LOAD
select SPL_SPI_SUPPORT
+   select SPL_BOOTROM_SUPPORT
 
 config MVEBU_SPL_BOOT_DEVICE_MMC
bool "SDIO/MMC card"
@@ -267,14 +268,17 @@ config MVEBU_SPL_BOOT_DEVICE_MMC
select SPL_GPIO_SUPPORT
select SPL_LIBDISK_SUPPORT
select SPL_MMC_SUPPORT
+   select SPL_BOOTROM_SUPPORT
 
 config MVEBU_SPL_BOOT_DEVICE_SATA
bool "SATA"
select SPL_SATA_SUPPORT
select SPL_LIBDISK_SUPPORT
+   select SPL_BOOTROM_SUPPORT
 
 config MVEBU_SPL_BOOT_DEVICE_UART
bool "UART"
+   select SPL_BOOTROM_SUPPORT
 
 endchoice
 
diff --git a/arch/arm/mach-mvebu/spl.c b/arch/arm/mach-mvebu/spl.c
index 16ebb7a59e..836eb18889 100644
--- a/arch/arm/mach-mvebu/spl.c
+++ b/arch/arm/mach-mvebu/spl.c
@@ -79,6 +79,18 @@ u32 spl_boot_device(void)
return get_boot_device();
 }
 
+int board_return_to_bootrom(struct spl_image_info *spl_image,
+   struct spl_boot_device *bootdev)
+{
+   u32 *regs = *(u32 **)CONFIG_SPL_BOOTROM_SAVE;
+
+   printf("Returning to BootROM (return address 0x%08x)...\n", regs[13]);
+   return_to_bootrom();
+
+   /* NOTREACHED - return_to_bootrom() does not return */
+   hang();
+}
+
 void board_init_f(ulong dummy)
 {
int ret;
-- 
2.31.1



[PATCH u-boot-mvebu v3 28/41] tools: kwboot: Fix checking image header version

2021-07-23 Thread Marek Behún
From: Pali Rohár 

Function image_version() returns unsigned value, so it can never be
negative. Explicitly check for two supported image versions: v0 and v1.

Signed-off-by: Pali Rohár 
Reviewed-by: Marek Behún 
Reviewed-by: Stefan Roese 
---
 tools/kwboot.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tools/kwboot.c b/tools/kwboot.c
index 1d32c1b7ad..7feeaa45a2 100644
--- a/tools/kwboot.c
+++ b/tools/kwboot.c
@@ -634,7 +634,7 @@ kwboot_img_patch_hdr(void *img, size_t size)
}
 
image_ver = image_version(img);
-   if (image_ver < 0) {
+   if (image_ver != 0 && image_ver != 1) {
fprintf(stderr, "Invalid image header version\n");
errno = EINVAL;
goto out;
-- 
2.31.1



[PATCH u-boot-mvebu v3 32/41] arm: mvebu: Use U-Boot's SPL BootROM framework for booting from NAND/UART

2021-07-23 Thread Marek Behún
From: Pali Rohár 

Current code uses hack in board_init_f() which calls return_to_bootrom()
to skip U-Boot SPL code and return back to BootROM to load U-Boot via
UART or from NAND.

This change migrates that hack from the board_init_f() function and
changes it to return BOOT_DEVICE_BOOTROM instead of returning to BootROM
directly, so that U-Boot's SPL framework is used for returning to
BootROM.

Signed-off-by: Pali Rohár 
Reviewed-by: Marek Behún 
Reviewed-by: Stefan Roese 
Reviewed-by: Chris Packham 
Tested-by: Chris Packham 
---
 arch/arm/mach-mvebu/spl.c | 47 ---
 1 file changed, 24 insertions(+), 23 deletions(-)

diff --git a/arch/arm/mach-mvebu/spl.c b/arch/arm/mach-mvebu/spl.c
index 836eb18889..5c3d959bff 100644
--- a/arch/arm/mach-mvebu/spl.c
+++ b/arch/arm/mach-mvebu/spl.c
@@ -76,7 +76,30 @@ static u32 get_boot_device(void)
 
 u32 spl_boot_device(void)
 {
-   return get_boot_device();
+   u32 boot_device = get_boot_device();
+
+   /*
+* Return to the BootROM to continue the Marvell xmodem
+* UART boot protocol. As initiated by the kwboot tool.
+*
+* This can only be done by the BootROM since the beginning
+* of the image is already read and interpreted by the BootROM.
+* SPL has no chance to receive this information. So we
+* need to return to the BootROM to enable this xmodem
+* UART download. Use SPL infrastructure to return to BootROM.
+*
+* If booting from NAND lets let the BootROM load the
+* rest of the bootloader.
+*/
+   switch (boot_device) {
+   case BOOT_DEVICE_UART:
+#if defined(CONFIG_ARMADA_38X)
+   case BOOT_DEVICE_NAND:
+#endif
+   return BOOT_DEVICE_BOOTROM;
+   default:
+   return boot_device;
+   }
 }
 
 int board_return_to_bootrom(struct spl_image_info *spl_image,
@@ -147,26 +170,4 @@ void board_init_f(ulong dummy)
 
/* Update read timing control for PCIe */
mv_rtc_config();
-
-   /*
-* Return to the BootROM to continue the Marvell xmodem
-* UART boot protocol. As initiated by the kwboot tool.
-*
-* This can only be done by the BootROM and not by the
-* U-Boot SPL infrastructure, since the beginning of the
-* image is already read and interpreted by the BootROM.
-* SPL has no chance to receive this information. So we
-* need to return to the BootROM to enable this xmodem
-* UART download.
-*
-* If booting from NAND lets let the BootROM load the
-* rest of the bootloader.
-*/
-   switch (get_boot_device()) {
-   case BOOT_DEVICE_UART:
-#if defined(CONFIG_ARMADA_38X)
-   case BOOT_DEVICE_NAND:
-#endif
-   return_to_bootrom();
-   }
 }
-- 
2.31.1



[PATCH u-boot-mvebu v3 17/41] tools: kwbimage: Add support for DATA command also for v1 images

2021-07-23 Thread Marek Behún
From: Pali Rohár 

The DATA command is already supported by mkimage for v0 images, but not
for v1 images.

BootROM code which executes v1 images also supports DATA command via an
optional extended v1 header OPT_HDR_V1_REGISTER_TYPE.

Implement support for DATA command for v1 images.

Signed-off-by: Pali Rohár 
Reviewed-by: Marek Behún 
Reviewed-by: Chris Packham 
Reviewed-by: Stefan Roese 
Tested-by: Chris Packham 
---
 tools/kwbimage.c | 32 +++-
 tools/kwbimage.h | 27 +++
 2 files changed, 58 insertions(+), 1 deletion(-)

diff --git a/tools/kwbimage.c b/tools/kwbimage.c
index 74a77412d7..b585f49180 100644
--- a/tools/kwbimage.c
+++ b/tools/kwbimage.c
@@ -933,6 +933,7 @@ static void *image_create_v0(size_t *imagesz, struct 
image_tool_params *params,
 static size_t image_headersz_v1(int *hasext)
 {
struct image_cfg_element *binarye;
+   unsigned int count;
size_t headersz;
int cfgi;
 
@@ -942,6 +943,10 @@ static size_t image_headersz_v1(int *hasext)
 */
headersz = sizeof(struct main_hdr_v1);
 
+   count = image_count_options(IMAGE_CFG_DATA);
+   if (count > 0)
+   headersz += sizeof(struct register_set_hdr_v1) + 8 * count + 4;
+
for (cfgi = 0; cfgi < cfgn; cfgi++) {
int ret;
struct stat s;
@@ -1188,6 +1193,7 @@ static void *image_create_v1(size_t *imagesz, struct 
image_tool_params *params,
 {
struct image_cfg_element *e;
struct main_hdr_v1 *main_hdr;
+   struct register_set_hdr_v1 *register_set_hdr;
 #if defined(CONFIG_KWB_SECURE)
struct secure_hdr_v1 *secure_hdr = NULL;
 #endif
@@ -1195,7 +1201,7 @@ static void *image_create_v1(size_t *imagesz, struct 
image_tool_params *params,
uint8_t *image, *cur;
int hasext = 0;
uint8_t *next_ext = NULL;
-   int cfgi;
+   int cfgi, datai, size;
 
/*
 * Calculate the size of the header and the size of the
@@ -1279,6 +1285,30 @@ static void *image_create_v1(size_t *imagesz, struct 
image_tool_params *params,
}
 #endif
 
+   datai = 0;
+   register_set_hdr = (struct register_set_hdr_v1 *)cur;
+   for (cfgi = 0; cfgi < cfgn; cfgi++) {
+   e = _cfg[cfgi];
+   if (e->type != IMAGE_CFG_DATA)
+   continue;
+   register_set_hdr->data[datai].entry.address =
+   cpu_to_le32(e->regdata.raddr);
+   register_set_hdr->data[datai].entry.value =
+   cpu_to_le32(e->regdata.rdata);
+   datai++;
+   }
+   if (datai != 0) {
+   size = sizeof(struct register_set_hdr_v1) + 8 * datai + 4;
+   register_set_hdr->headertype = OPT_HDR_V1_REGISTER_TYPE;
+   register_set_hdr->headersz_lsb = cpu_to_le16(size & 0x);
+   register_set_hdr->headersz_msb = size >> 16;
+   /* Set delay to the smallest possible value 1ms. */
+   register_set_hdr->data[datai].last_entry.delay = 1;
+   cur += size;
+   *next_ext = 1;
+   next_ext = _set_hdr->data[datai].last_entry.next;
+   }
+
for (cfgi = 0; cfgi < cfgn; cfgi++) {
e = _cfg[cfgi];
if (e->type != IMAGE_CFG_BINARY)
diff --git a/tools/kwbimage.h b/tools/kwbimage.h
index cab3d95d13..9f86da46e8 100644
--- a/tools/kwbimage.h
+++ b/tools/kwbimage.h
@@ -148,6 +148,33 @@ struct secure_hdr_v1 {
uint16_t reserved5; /* 0x25E2 - 0x25E3 */
 };
 
+/*
+ * Structure of register set
+ */
+struct register_set_hdr_v1 {
+   uint8_t  headertype;/* 0x0 */
+   uint8_t  headersz_msb;  /* 0x1 */
+   uint16_t headersz_lsb;  /* 0x2 - 0x3 */
+   union {
+   struct {
+   uint32_t address;   /* 0x4+8*N - 0x7+8*N */
+   uint32_t value; /* 0x8+8*N - 0xB+8*N */
+   } entry;
+   struct {
+   uint8_t  next;  /* 0xC+8*N */
+   uint8_t  delay; /* 0xD+8*N */
+   uint16_t reserved;  /* 0xE+8*N - 0xF+8*N */
+   } last_entry;
+   } data[];
+};
+
+/*
+ * Value 0 in register_set_hdr_v1 delay field is special.
+ * Instead of delay it setup SDRAM Controller.
+ */
+#define REGISTER_SET_HDR_OPT_DELAY_SDRAM_SETUP 0
+#define REGISTER_SET_HDR_OPT_DELAY_MS(val) ((val) ?: 1)
+
 /*
  * Various values for the opt_hdr_v1->headertype field, describing the
  * different types of optional headers. The "secure" header contains
-- 
2.31.1



[PATCH u-boot-mvebu v3 22/41] tools: dumpimage: Show error message when trying to extract data from kwbimage

2021-07-23 Thread Marek Behún
From: Pali Rohár 

There is no code for extracting data from kwbimage, so show an error
message when user tries this via e.g. dumpimage call:
  ./tools/dumpimage -T kwbimage -o /tmp/out u-boot-spl.kwb

Signed-off-by: Pali Rohár 
Reviewed-by: Marek Behún 
Reviewed-by: Stefan Roese 
---
 tools/kwbimage.c | 5 +
 1 file changed, 5 insertions(+)

diff --git a/tools/kwbimage.c b/tools/kwbimage.c
index 5410df63f5..9ecda861e4 100644
--- a/tools/kwbimage.c
+++ b/tools/kwbimage.c
@@ -1867,6 +1867,11 @@ static int kwbimage_generate(struct image_tool_params 
*params,
  */
 static int kwbimage_check_params(struct image_tool_params *params)
 {
+   if (params->iflag) {
+   fprintf(stderr, "%s: kwbimage does not support extract 
operation\n", params->cmdname);
+   return CFG_INVALID;
+   }
+
if (!params->imagename || !strlen(params->imagename)) {
char *msg = "Configuration file for kwbimage creation omitted";
 
-- 
2.31.1



[PATCH u-boot-mvebu v3 19/41] tools: kwbimage: Do not hide usage of secure header under CONFIG_ARMADA_38X

2021-07-23 Thread Marek Behún
From: Pali Rohár 

The mkimage host tool can be used to generate kwbimage v1 image with
secure header on host system for A38x plaform also when U-Boot is being
compiled for different platform. So there is no reason to not allow
compiling of mkimage/kwbimage with secure header support for e.g. x86-64
host.

Signed-off-by: Pali Rohár 
Reviewed-by: Marek Behún 
Reviewed-by: Chris Packham 
Reviewed-by: Stefan Roese 
Tested-by: Chris Packham 
---
 tools/Makefile   |  4 
 tools/kwbimage.c | 22 --
 2 files changed, 26 deletions(-)

diff --git a/tools/Makefile b/tools/Makefile
index 9517f203fd..35aefc207c 100644
--- a/tools/Makefile
+++ b/tools/Makefile
@@ -173,10 +173,6 @@ ifneq ($(CONFIG_SYS_U_BOOT_OFFS),)
 HOSTCFLAGS_kwbimage.o += -DCONFIG_SYS_U_BOOT_OFFS=$(CONFIG_SYS_U_BOOT_OFFS)
 endif
 
-ifneq ($(CONFIG_ARMADA_38X),)
-HOSTCFLAGS_kwbimage.o += -DCONFIG_KWB_SECURE
-endif
-
 # MXSImage needs LibSSL
 ifneq 
($(CONFIG_MX23)$(CONFIG_MX28)$(CONFIG_ARMADA_38X)$(CONFIG_TOOLS_LIBCRYPTO),)
 HOSTCFLAGS_kwbimage.o += \
diff --git a/tools/kwbimage.c b/tools/kwbimage.c
index 469e5b55f2..f3b16d94ad 100644
--- a/tools/kwbimage.c
+++ b/tools/kwbimage.c
@@ -16,7 +16,6 @@
 #include 
 #include "kwbimage.h"
 
-#ifdef CONFIG_KWB_SECURE
 #include 
 #include 
 #include 
@@ -42,13 +41,10 @@ void EVP_MD_CTX_cleanup(EVP_MD_CTX *ctx)
EVP_MD_CTX_reset(ctx);
 }
 #endif
-#endif
 
 static struct image_cfg_element *image_cfg;
 static int cfgn;
-#ifdef CONFIG_KWB_SECURE
 static int verbose_mode;
-#endif
 
 struct boot_mode {
unsigned int id;
@@ -243,8 +239,6 @@ image_count_options(unsigned int optiontype)
return count;
 }
 
-#if defined(CONFIG_KWB_SECURE)
-
 static int image_get_csk_index(void)
 {
struct image_cfg_element *e;
@@ -267,8 +261,6 @@ static bool image_get_spezialized_img(void)
return e->sec_specialized_img;
 }
 
-#endif
-
 /*
  * Compute a 8-bit checksum of a memory area. This algorithm follows
  * the requirements of the Marvell SoC BootROM specifications.
@@ -363,7 +355,6 @@ static uint8_t baudrate_to_option(unsigned int baudrate)
}
 }
 
-#if defined(CONFIG_KWB_SECURE)
 static void kwb_msg(const char *fmt, ...)
 {
if (verbose_mode) {
@@ -852,8 +843,6 @@ done:
return ret;
 }
 
-#endif
-
 static void *image_create_v0(size_t *imagesz, struct image_tool_params *params,
 int payloadsz)
 {
@@ -984,13 +973,11 @@ static size_t image_headersz_v1(int *hasext)
*hasext = 1;
}
 
-#if defined(CONFIG_KWB_SECURE)
if (image_get_csk_index() >= 0) {
headersz += sizeof(struct secure_hdr_v1);
if (hasext)
*hasext = 1;
}
-#endif
 
 #if defined(CONFIG_SYS_U_BOOT_OFFS)
if (headersz > CONFIG_SYS_U_BOOT_OFFS) {
@@ -1080,8 +1067,6 @@ err_close:
return -1;
 }
 
-#if defined(CONFIG_KWB_SECURE)
-
 int export_pub_kak_hash(RSA *kak, struct secure_hdr_v1 *secure_hdr)
 {
FILE *hashf;
@@ -1189,7 +1174,6 @@ int add_secure_header_v1(struct image_tool_params 
*params, uint8_t *ptr,
 
return 0;
 }
-#endif
 
 static void *image_create_v1(size_t *imagesz, struct image_tool_params *params,
 uint8_t *ptr, int payloadsz)
@@ -1197,9 +1181,7 @@ static void *image_create_v1(size_t *imagesz, struct 
image_tool_params *params,
struct image_cfg_element *e;
struct main_hdr_v1 *main_hdr;
struct register_set_hdr_v1 *register_set_hdr;
-#if defined(CONFIG_KWB_SECURE)
struct secure_hdr_v1 *secure_hdr = NULL;
-#endif
size_t headersz;
uint8_t *image, *cur;
int hasext = 0;
@@ -1275,7 +1257,6 @@ static void *image_create_v1(size_t *imagesz, struct 
image_tool_params *params,
if (main_hdr->blockid == IBR_HDR_PEX_ID)
main_hdr->srcaddr = cpu_to_le32(0x);
 
-#if defined(CONFIG_KWB_SECURE)
if (image_get_csk_index() >= 0) {
/*
 * only reserve the space here; we fill the header later since
@@ -1286,7 +1267,6 @@ static void *image_create_v1(size_t *imagesz, struct 
image_tool_params *params,
*next_ext = 1;
next_ext = _hdr->next;
}
-#endif
 
datai = 0;
register_set_hdr = (struct register_set_hdr_v1 *)cur;
@@ -1334,11 +1314,9 @@ static void *image_create_v1(size_t *imagesz, struct 
image_tool_params *params,
return NULL;
}
 
-#if defined(CONFIG_KWB_SECURE)
if (secure_hdr && add_secure_header_v1(params, ptr, payloadsz,
   headersz, image, secure_hdr))
return NULL;
-#endif
 
/* Calculate and set the header checksum */
main_hdr->checksum = image_checksum8(main_hdr, headersz);
-- 
2.31.1



[PATCH u-boot-mvebu v3 21/41] tools: dumpimage: Fix crashing when trying to extract data from kwbimage

2021-07-23 Thread Marek Behún
From: Pali Rohár 

Trying to call the following command causes NULL pointer dereference in
strlen():
  ./tools/dumpimage -T kwbimage -o /tmp/out u-boot-spl.kwb

Fix it by checking whether params->imagename is non-NULL before calling
strlen().

Signed-off-by: Pali Rohár 
Reviewed-by: Marek Behún 
Reviewed-by: Stefan Roese 
---
 tools/kwbimage.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tools/kwbimage.c b/tools/kwbimage.c
index f3b16d94ad..5410df63f5 100644
--- a/tools/kwbimage.c
+++ b/tools/kwbimage.c
@@ -1867,7 +1867,7 @@ static int kwbimage_generate(struct image_tool_params 
*params,
  */
 static int kwbimage_check_params(struct image_tool_params *params)
 {
-   if (!strlen(params->imagename)) {
+   if (!params->imagename || !strlen(params->imagename)) {
char *msg = "Configuration file for kwbimage creation omitted";
 
fprintf(stderr, "Error:%s - %s\n", params->cmdname, msg);
-- 
2.31.1



[PATCH u-boot-mvebu v3 16/41] tools: kwbimage: Don't parse PAYLOAD keyword

2021-07-23 Thread Marek Behún
From: Pali Rohár 

The PAYLOAD keyword does nothing. No code is using it and both mkimage
and kwbimage completely ignore it. It looks like a relict from the past.
The payload image itself can be specified only via -d parameter to
mkimage.

Signed-off-by: Pali Rohár 
Reviewed-by: Marek Behún 
Reviewed-by: Chris Packham 
Reviewed-by: Stefan Roese 
Tested-by: Chris Packham 
---
 tools/kwbimage.c | 13 -
 1 file changed, 13 deletions(-)

diff --git a/tools/kwbimage.c b/tools/kwbimage.c
index 1bfc524424..74a77412d7 100644
--- a/tools/kwbimage.c
+++ b/tools/kwbimage.c
@@ -103,7 +103,6 @@ enum image_cfg_type {
IMAGE_CFG_NAND_ECC_MODE,
IMAGE_CFG_NAND_PAGESZ,
IMAGE_CFG_BINARY,
-   IMAGE_CFG_PAYLOAD,
IMAGE_CFG_DATA,
IMAGE_CFG_BAUDRATE,
IMAGE_CFG_DEBUG,
@@ -131,7 +130,6 @@ static const char * const id_strs[] = {
[IMAGE_CFG_NAND_ECC_MODE] = "NAND_ECC_MODE",
[IMAGE_CFG_NAND_PAGESZ] = "NAND_PAGE_SIZE",
[IMAGE_CFG_BINARY] = "BINARY",
-   [IMAGE_CFG_PAYLOAD] = "PAYLOAD",
[IMAGE_CFG_DATA] = "DATA",
[IMAGE_CFG_BAUDRATE] = "BAUDRATE",
[IMAGE_CFG_DEBUG] = "DEBUG",
@@ -157,7 +155,6 @@ struct image_cfg_element {
unsigned int args[BINARY_MAX_ARGS];
unsigned int nargs;
} binary;
-   const char *payload;
unsigned int dstaddr;
unsigned int execaddr;
unsigned int nandblksz;
@@ -874,11 +871,6 @@ static void *image_create_v0(size_t *imagesz, struct 
image_tool_params *params,
headersz += sizeof(struct ext_hdr_v0);
}
 
-   if (image_count_options(IMAGE_CFG_PAYLOAD) > 1) {
-   fprintf(stderr, "More than one payload, not possible\n");
-   return NULL;
-   }
-
image = malloc(headersz);
if (!image) {
fprintf(stderr, "Cannot allocate memory for image\n");
@@ -950,11 +942,6 @@ static size_t image_headersz_v1(int *hasext)
 */
headersz = sizeof(struct main_hdr_v1);
 
-   if (image_count_options(IMAGE_CFG_PAYLOAD) > 1) {
-   fprintf(stderr, "More than one payload, not possible\n");
-   return 0;
-   }
-
for (cfgi = 0; cfgi < cfgn; cfgi++) {
int ret;
struct stat s;
-- 
2.31.1



[PATCH u-boot-mvebu v3 29/41] arm: mvebu: Fix return_to_bootrom()

2021-07-23 Thread Marek Behún
From: Pali Rohár 

Register r0 should be set to return value 0x0 - NO_ERR.

Set r0 with return value after all registers are restored from the
stack, so that the return value is always correct.

Signed-off-by: Pali Rohár 
Fixes: 944c7a317675 ("arm: mvebu: Add option to use UART xmodem protocol via 
kwboot")
Reviewed-by: Marek Behún 
Reviewed-by: Stefan Roese 
Reviewed-by: Chris Packham 
Tested-by: Chris Packham 
---
 arch/arm/mach-mvebu/lowlevel_spl.S | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/arch/arm/mach-mvebu/lowlevel_spl.S 
b/arch/arm/mach-mvebu/lowlevel_spl.S
index 8718d7a43e..dde77b7652 100644
--- a/arch/arm/mach-mvebu/lowlevel_spl.S
+++ b/arch/arm/mach-mvebu/lowlevel_spl.S
@@ -13,8 +13,9 @@ ENDPROC(save_boot_params)
 ENTRY(return_to_bootrom)
ldr r12, =CONFIG_SPL_BOOTROM_SAVE
ldr sp, [r12]
+   ldmfd   sp!, {r0 - r12, lr} /* @ restore registers from stack */
mov r0, #0x0/* @ return value: 0x0 NO_ERR */
-   ldmfd   sp!, {r0 - r12, pc} /* @ restore regs and return */
+   bx  lr  /* @ return to bootrom */
 ENDPROC(return_to_bootrom)
 
 /*
-- 
2.31.1



[PATCH u-boot-mvebu v3 18/41] tools: kwbimage: Add support for a new DATA_DELAY command

2021-07-23 Thread Marek Behún
From: Pali Rohár 

This command is supported only by v1 images and specifies a milliseconds
delay after executing some set of DATA commands. The special string value
SDRAM_SETUP instructs BootROM to setup SDRAM controller instead of
executing delay. SDRAM_SETUP may be specified only once and after the
last DATA command.

Signed-off-by: Pali Rohár 
Reviewed-by: Marek Behún 
Reviewed-by: Chris Packham 
Reviewed-by: Stefan Roese 
Tested-by: Chris Packham 
---
 tools/kwbimage.c | 24 +++-
 1 file changed, 23 insertions(+), 1 deletion(-)

diff --git a/tools/kwbimage.c b/tools/kwbimage.c
index b585f49180..469e5b55f2 100644
--- a/tools/kwbimage.c
+++ b/tools/kwbimage.c
@@ -104,6 +104,7 @@ enum image_cfg_type {
IMAGE_CFG_NAND_PAGESZ,
IMAGE_CFG_BINARY,
IMAGE_CFG_DATA,
+   IMAGE_CFG_DATA_DELAY,
IMAGE_CFG_BAUDRATE,
IMAGE_CFG_DEBUG,
IMAGE_CFG_KAK,
@@ -131,6 +132,7 @@ static const char * const id_strs[] = {
[IMAGE_CFG_NAND_PAGESZ] = "NAND_PAGE_SIZE",
[IMAGE_CFG_BINARY] = "BINARY",
[IMAGE_CFG_DATA] = "DATA",
+   [IMAGE_CFG_DATA_DELAY] = "DATA_DELAY",
[IMAGE_CFG_BAUDRATE] = "BAUDRATE",
[IMAGE_CFG_DEBUG] = "DEBUG",
[IMAGE_CFG_KAK] = "KAK",
@@ -162,6 +164,7 @@ struct image_cfg_element {
unsigned int nandeccmode;
unsigned int nandpagesz;
struct ext_hdr_v0_reg regdata;
+   unsigned int regdata_delay;
unsigned int baudrate;
unsigned int debug;
const char *key_name;
@@ -1289,8 +1292,21 @@ static void *image_create_v1(size_t *imagesz, struct 
image_tool_params *params,
register_set_hdr = (struct register_set_hdr_v1 *)cur;
for (cfgi = 0; cfgi < cfgn; cfgi++) {
e = _cfg[cfgi];
-   if (e->type != IMAGE_CFG_DATA)
+   if (e->type != IMAGE_CFG_DATA &&
+   e->type != IMAGE_CFG_DATA_DELAY)
continue;
+   if (e->type == IMAGE_CFG_DATA_DELAY) {
+   size = sizeof(struct register_set_hdr_v1) + 8 * datai + 
4;
+   register_set_hdr->headertype = OPT_HDR_V1_REGISTER_TYPE;
+   register_set_hdr->headersz_lsb = cpu_to_le16(size & 
0x);
+   register_set_hdr->headersz_msb = size >> 16;
+   register_set_hdr->data[datai].last_entry.delay = 
e->regdata_delay;
+   cur += size;
+   *next_ext = 1;
+   next_ext = 
_set_hdr->data[datai].last_entry.next;
+   datai = 0;
+   continue;
+   }
register_set_hdr->data[datai].entry.address =
cpu_to_le32(e->regdata.raddr);
register_set_hdr->data[datai].entry.value =
@@ -1429,6 +1445,12 @@ static int image_create_config_parse_oneline(char *line,
el->regdata.raddr = strtoul(value1, NULL, 16);
el->regdata.rdata = strtoul(value2, NULL, 16);
break;
+   case IMAGE_CFG_DATA_DELAY:
+   if (!strcmp(value1, "SDRAM_SETUP"))
+   el->regdata_delay = 
REGISTER_SET_HDR_OPT_DELAY_SDRAM_SETUP;
+   else
+   el->regdata_delay = 
REGISTER_SET_HDR_OPT_DELAY_MS(strtoul(value1, NULL, 10));
+   break;
case IMAGE_CFG_BAUDRATE:
el->baudrate = strtoul(value1, NULL, 10);
break;
-- 
2.31.1



[PATCH u-boot-mvebu v3 24/41] tools: kwboot: Fix restoring terminal

2021-07-23 Thread Marek Behún
From: Pali Rohár 

Call tcsetattr() only if the file descriptor is valid. It may be
invalidated by previous lines (if it is not a tty descriptor).

Signed-off-by: Pali Rohár 
Reviewed-by: Marek Behún 
Reviewed-by: Stefan Roese 
Reviewed-by: Chris Packham 
Tested-by: Chris Packham 
---
 tools/kwboot.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/tools/kwboot.c b/tools/kwboot.c
index 1ba5ded5d3..7fa742d84c 100644
--- a/tools/kwboot.c
+++ b/tools/kwboot.c
@@ -558,7 +558,8 @@ kwboot_terminal(int tty)
}
} while (quit[s] != 0);
 
-   tcsetattr(in, TCSANOW, );
+   if (in >= 0)
+   tcsetattr(in, TCSANOW, );
 out:
return rc;
 }
-- 
2.31.1



[PATCH u-boot-mvebu v3 27/41] tools: kwboot: Check for v1 header size

2021-07-23 Thread Marek Behún
From: Pali Rohár 

Too small invalid headers may cause kwboot to crash.
Check for header size of v1 images.

Signed-off-by: Pali Rohár 
Reviewed-by: Marek Behún 
Reviewed-by: Stefan Roese 
Reviewed-by: Chris Packham 
Tested-by: Chris Packham 
---
 tools/kwboot.c | 5 +
 1 file changed, 5 insertions(+)

diff --git a/tools/kwboot.c b/tools/kwboot.c
index c0ac4ce19e..1d32c1b7ad 100644
--- a/tools/kwboot.c
+++ b/tools/kwboot.c
@@ -645,6 +645,11 @@ kwboot_img_patch_hdr(void *img, size_t size)
else
hdrsz = KWBHEADER_V1_SIZE(hdr);
 
+   if (size < hdrsz) {
+   errno = EINVAL;
+   goto out;
+   }
+
csum = kwboot_img_csum8(hdr, hdrsz) - hdr->checksum;
if (csum != hdr->checksum) {
errno = EINVAL;
-- 
2.31.1



[PATCH u-boot-mvebu v3 30/41] arm: mvebu: Mark return_to_bootrom() as a noreturn function

2021-07-23 Thread Marek Behún
From: Pali Rohár 

This function does not return, so add the appropriate compiler flag.

Signed-off-by: Pali Rohár 
Reviewed-by: Marek Behún 
Reviewed-by: Stefan Roese 
Reviewed-by: Chris Packham 
Tested-by: Chris Packham 
---
 arch/arm/mach-mvebu/include/mach/cpu.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/arm/mach-mvebu/include/mach/cpu.h 
b/arch/arm/mach-mvebu/include/mach/cpu.h
index 52473ade7a..79858858c2 100644
--- a/arch/arm/mach-mvebu/include/mach/cpu.h
+++ b/arch/arm/mach-mvebu/include/mach/cpu.h
@@ -142,7 +142,7 @@ int mvebu_mbus_probe(struct mbus_win windows[], int count);
 int mvebu_soc_family(void);
 u32 mvebu_get_nand_clock(void);
 
-void return_to_bootrom(void);
+void __noreturn return_to_bootrom(void);
 
 #ifndef CONFIG_DM_MMC
 int mv_sdh_init(unsigned long regbase, u32 max_clk, u32 min_clk, u32 quirks);
-- 
2.31.1



[PATCH u-boot-mvebu v3 26/41] tools: kwboot: Cosmetic fix - add missing curly brackets

2021-07-23 Thread Marek Behún
From: Pali Rohár 

Add missing curly brackets for this else statement.

Signed-off-by: Pali Rohár 
Reviewed-by: Marek Behún 
Reviewed-by: Stefan Roese 
Reviewed-by: Chris Packham 
Tested-by: Chris Packham 
---
 tools/kwboot.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/tools/kwboot.c b/tools/kwboot.c
index 941f4228f9..c0ac4ce19e 100644
--- a/tools/kwboot.c
+++ b/tools/kwboot.c
@@ -479,13 +479,14 @@ kwboot_term_pipe(int in, int out, char *quit, int *s)
return 0;
buf++;
nin--;
-   } else
+   } else {
while (*s > 0) {
nout = write(out, quit, *s);
if (nout <= 0)
return -1;
(*s) -= nout;
}
+   }
}
}
 
-- 
2.31.1



[PATCH u-boot-mvebu v3 41/41] kwbimage: Update help message about how to extract from an existing image

2021-07-23 Thread Marek Behún
From: Pali Rohár 

Extracting is now supported by dumpimage, so mention it in help instead
of `kwbimage -x`.

Signed-off-by: Pali Rohár 
Reviewed-by: Marek Behún 
Reviewed-by: Stefan Roese 
---
 tools/kwbimage.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tools/kwbimage.c b/tools/kwbimage.c
index 5665198db0..00cb338d64 100644
--- a/tools/kwbimage.c
+++ b/tools/kwbimage.c
@@ -961,7 +961,7 @@ static size_t image_headersz_v1(int *hasext)
fprintf(stderr,
"Didn't find the file '%s' in '%s' which is 
mandatory to generate the image\n"
"This file generally contains the DDR3 training 
code, and should be extracted from an existing bootable\n"
-   "image for your board. See 'kwbimage -x' to 
extract it from an existing image.\n",
+   "image for your board. Use 'dumpimage -T 
kwbimage -p 0' to extract it from an existing image.\n",
binarye->binary.file, dir);
return 0;
}
-- 
2.31.1



[PATCH u-boot-mvebu v3 40/41] kwbimage: Add support for extracting images via dumpimage tool

2021-07-23 Thread Marek Behún
From: Pali Rohár 

The kwbimage library does not support extracting subimages. Implement it.

Signed-off-by: Pali Rohár 
Reviewed-by: Marek Behún 
Reviewed-by: Stefan Roese 
---
 tools/kwbimage.c | 72 ++--
 1 file changed, 64 insertions(+), 8 deletions(-)

diff --git a/tools/kwbimage.c b/tools/kwbimage.c
index ccb0b92266..5665198db0 100644
--- a/tools/kwbimage.c
+++ b/tools/kwbimage.c
@@ -1849,17 +1849,73 @@ static int kwbimage_generate(struct image_tool_params 
*params,
return 4 + (4 - s.st_size % 4) % 4;
 }
 
+static int kwbimage_extract_subimage(void *ptr, struct image_tool_params 
*params)
+{
+   struct main_hdr_v1 *mhdr = (struct main_hdr_v1 *)ptr;
+   size_t header_size = kwbimage_header_size(ptr);
+   int idx = params->pflag;
+   int cur_idx = 0;
+   uint32_t offset;
+   ulong image;
+   ulong size;
+
+   if (image_version((void *)ptr) == 1 && (mhdr->ext & 0x1)) {
+   struct opt_hdr_v1 *ohdr = (struct opt_hdr_v1 *)
+ ((uint8_t *)ptr +
+  sizeof(*mhdr));
+
+   while (1) {
+   uint32_t ohdr_size = (ohdr->headersz_msb << 16) |
+le16_to_cpu(ohdr->headersz_lsb);
+
+   if (ohdr->headertype == OPT_HDR_V1_BINARY_TYPE) {
+   if (idx == cur_idx) {
+   image = (ulong)>data[4 +
+4 * ohdr->data[0]];
+   size = ohdr_size - 12 -
+  4 * ohdr->data[0];
+   goto extract;
+   }
+   ++cur_idx;
+   }
+   if (!(*((uint8_t *)ohdr + ohdr_size - 4) & 0x1))
+   break;
+   ohdr = (struct opt_hdr_v1 *)((uint8_t *)ohdr +
+ohdr_size);
+   }
+   }
+
+   if (idx != cur_idx) {
+   printf("Image %d is not present\n", idx);
+   return -1;
+   }
+
+   offset = le32_to_cpu(mhdr->srcaddr);
+
+   if (mhdr->blockid == IBR_HDR_SATA_ID) {
+   offset -= 1;
+   offset *= 512;
+   }
+
+   if (mhdr->blockid == IBR_HDR_SDIO_ID)
+   offset *= 512;
+
+   if (mhdr->blockid == IBR_HDR_PEX_ID && offset == 0x)
+   offset = header_size;
+
+   image = (ulong)((uint8_t *)ptr + offset);
+   size = le32_to_cpu(mhdr->blocksize) - 4;
+
+extract:
+   return imagetool_save_subimage(params->outfile, image, size);
+}
+
 /*
  * Report Error if xflag is set in addition to default
  */
 static int kwbimage_check_params(struct image_tool_params *params)
 {
-   if (params->iflag) {
-   fprintf(stderr, "%s: kwbimage does not support extract 
operation\n", params->cmdname);
-   return CFG_INVALID;
-   }
-
-   if (!params->imagename || !strlen(params->imagename)) {
+   if (!params->iflag && (!params->imagename || 
!strlen(params->imagename))) {
char *msg = "Configuration file for kwbimage creation omitted";
 
fprintf(stderr, "Error:%s - %s\n", params->cmdname, msg);
@@ -1869,7 +1925,7 @@ static int kwbimage_check_params(struct image_tool_params 
*params)
return (params->dflag && (params->fflag || params->lflag)) ||
(params->fflag && (params->dflag || params->lflag)) ||
(params->lflag && (params->dflag || params->fflag)) ||
-   (params->xflag) || !(strlen(params->imagename));
+   (params->xflag);
 }
 
 /*
@@ -1884,7 +1940,7 @@ U_BOOT_IMAGE_TYPE(
kwbimage_verify_header,
kwbimage_print_header,
kwbimage_set_header,
-   NULL,
+   kwbimage_extract_subimage,
kwbimage_check_image_types,
NULL,
kwbimage_generate
-- 
2.31.1



[PATCH u-boot-mvebu v3 38/41] arm: mvebu: Remove unused macro CONFIG_SYS_U_BOOT_OFFS

2021-07-23 Thread Marek Behún
From: Pali Rohár 

Macro CONFIG_SYS_U_BOOT_OFFS is set but not used anymore. Remove it.

Signed-off-by: Pali Rohár 
Reviewed-by: Marek Behún 
Reviewed-by: Chris Packham 
Reviewed-by: Stefan Roese 
---
 include/configs/clearfog.h| 6 +-
 include/configs/controlcenterdc.h | 6 --
 include/configs/db-88f6720.h  | 3 ---
 include/configs/db-88f6820-amc.h  | 5 -
 include/configs/db-88f6820-gp.h   | 6 --
 include/configs/db-mv784mp-gp.h   | 3 ---
 include/configs/ds414.h   | 5 -
 include/configs/helios4.h | 6 +-
 include/configs/theadorable.h | 3 ---
 include/configs/turris_omnia.h| 6 --
 include/configs/x530.h| 3 ---
 scripts/config_whitelist.txt  | 1 -
 12 files changed, 2 insertions(+), 51 deletions(-)

diff --git a/include/configs/clearfog.h b/include/configs/clearfog.h
index 255b147945..fbdd2f0a24 100644
--- a/include/configs/clearfog.h
+++ b/include/configs/clearfog.h
@@ -69,12 +69,8 @@
 #define CONFIG_SPL_STACK   (0x4000 + ((192 - 16) << 10))
 #define CONFIG_SPL_BOOTROM_SAVE(CONFIG_SPL_STACK + 4)
 
-#if defined(CONFIG_MVEBU_SPL_BOOT_DEVICE_SPI)
-/* SPL related SPI defines */
-#define CONFIG_SYS_U_BOOT_OFFS 0x2
-#elif defined(CONFIG_MVEBU_SPL_BOOT_DEVICE_MMC) || 
defined(CONFIG_MVEBU_SPL_BOOT_DEVICE_SATA)
+#if defined(CONFIG_MVEBU_SPL_BOOT_DEVICE_MMC) || 
defined(CONFIG_MVEBU_SPL_BOOT_DEVICE_SATA)
 /* SPL related MMC defines */
-#define CONFIG_SYS_U_BOOT_OFFS (160 << 10)
 #ifdef CONFIG_SPL_BUILD
 #define CONFIG_FIXED_SDHCI_ALIGNED_BUFFER  0x0018  /* in SDRAM */
 #endif
diff --git a/include/configs/controlcenterdc.h 
b/include/configs/controlcenterdc.h
index fffc372872..e81d05aa2e 100644
--- a/include/configs/controlcenterdc.h
+++ b/include/configs/controlcenterdc.h
@@ -85,15 +85,9 @@
 #define CONFIG_SPL_LIBGENERIC_SUPPORT
 #define CONFIG_SPL_I2C_SUPPORT
 
-#if CONFIG_SPL_BOOT_DEVICE == SPL_BOOT_SPI_NOR_FLASH
-/* SPL related SPI defines */
-#define CONFIG_SYS_U_BOOT_OFFS 0x3
-#endif
-
 #if CONFIG_SPL_BOOT_DEVICE == SPL_BOOT_SDIO_MMC_CARD
 /* SPL related MMC defines */
 #define CONFIG_SPL_MMC_SUPPORT
-#define CONFIG_SYS_U_BOOT_OFFS (168 << 10)
 #ifdef CONFIG_SPL_BUILD
 #define CONFIG_FIXED_SDHCI_ALIGNED_BUFFER  0x0018  /* in SDRAM */
 #endif
diff --git a/include/configs/db-88f6720.h b/include/configs/db-88f6720.h
index 14c0190375..cbb9270f93 100644
--- a/include/configs/db-88f6720.h
+++ b/include/configs/db-88f6720.h
@@ -65,7 +65,4 @@
 #define CONFIG_SPL_STACK   (0x4000 + ((192 - 16) << 10))
 #define CONFIG_SPL_BOOTROM_SAVE(CONFIG_SPL_STACK + 4)
 
-/* SPL related SPI defines */
-#define CONFIG_SYS_U_BOOT_OFFS 0x2
-
 #endif /* _CONFIG_DB_88F6720_H */
diff --git a/include/configs/db-88f6820-amc.h b/include/configs/db-88f6820-amc.h
index 3cd1ff899a..757fbc0b9b 100644
--- a/include/configs/db-88f6820-amc.h
+++ b/include/configs/db-88f6820-amc.h
@@ -59,11 +59,6 @@
 #define CONFIG_SPL_STACK   (0x4000 + ((192 - 16) << 10))
 #define CONFIG_SPL_BOOTROM_SAVE(CONFIG_SPL_STACK + 4)
 
-#if CONFIG_SPL_BOOT_DEVICE == SPL_BOOT_SPI_NOR_FLASH
-/* SPL related SPI defines */
-#define CONFIG_SYS_U_BOOT_OFFS 0x24000
-#endif
-
 /*
  * mv-common.h should be defined after CMD configs since it used them
  * to enable certain macros
diff --git a/include/configs/db-88f6820-gp.h b/include/configs/db-88f6820-gp.h
index 5e43191e8e..d50eb2c120 100644
--- a/include/configs/db-88f6820-gp.h
+++ b/include/configs/db-88f6820-gp.h
@@ -71,14 +71,8 @@
 #define CONFIG_SPL_STACK   (0x4000 + ((192 - 16) << 10))
 #define CONFIG_SPL_BOOTROM_SAVE(CONFIG_SPL_STACK + 4)
 
-#if CONFIG_SPL_BOOT_DEVICE == SPL_BOOT_SPI_NOR_FLASH
-/* SPL related SPI defines */
-#define CONFIG_SYS_U_BOOT_OFFS 0x24000
-#endif
-
 #if CONFIG_SPL_BOOT_DEVICE == SPL_BOOT_SDIO_MMC_CARD
 /* SPL related MMC defines */
-#define CONFIG_SYS_U_BOOT_OFFS (160 << 10)
 #ifdef CONFIG_SPL_BUILD
 #define CONFIG_FIXED_SDHCI_ALIGNED_BUFFER  0x0018  /* in SDRAM */
 #endif
diff --git a/include/configs/db-mv784mp-gp.h b/include/configs/db-mv784mp-gp.h
index 990fcec129..ef7eebd081 100644
--- a/include/configs/db-mv784mp-gp.h
+++ b/include/configs/db-mv784mp-gp.h
@@ -78,9 +78,6 @@
 #define CONFIG_SPL_STACK   (0x4000 + ((192 - 16) << 10))
 #define CONFIG_SPL_BOOTROM_SAVE(CONFIG_SPL_STACK + 4)
 
-/* SPL related SPI defines */
-#define CONFIG_SYS_U_BOOT_OFFS 0x2
-
 /* Enable DDR support in SPL (DDR3 training from Marvell bin_hdr) */
 #define CONFIG_SPD_EEPROM  0x4e
 #define CONFIG_BOARD_ECC_SUPPORT   /* this board supports ECC */
diff --git a/include/configs/ds414.h b/include/configs/ds414.h
index b34da334e2..4bbb244fa2 100644
--- a/include/configs/ds414.h
+++ b/include/configs/ds414.h
@@ -68,11 +68,6 @@
 

[PATCH u-boot-mvebu v3 39/41] arm: mvebu: gdsys: Remove custom spl_board_init()

2021-07-23 Thread Marek Behún
From: Pali Rohár 

The gdsys a38x config file (controlcenterdc_defconfig) uses BootROM to
load U-Boot proper.

Since it is now possible to do this via U-Boot SPL framework, we do not
need to provide custom spl_board_init() which calls return_to_bootrom().

Signed-off-by: Pali Rohár 
Reviewed-by: Marek Behún 
Reviewed-by: Chris Packham 
Reviewed-by: Stefan Roese 
---
 board/gdsys/a38x/Makefile |  2 +-
 board/gdsys/a38x/spl.c| 20 
 configs/controlcenterdc_defconfig |  1 -
 3 files changed, 1 insertion(+), 22 deletions(-)
 delete mode 100644 board/gdsys/a38x/spl.c

diff --git a/board/gdsys/a38x/Makefile b/board/gdsys/a38x/Makefile
index 32fffab467..4b13859fed 100644
--- a/board/gdsys/a38x/Makefile
+++ b/board/gdsys/a38x/Makefile
@@ -4,7 +4,7 @@
 # Copyright (C) 2015 Reinhard Pfau 
 # Copyright (C) 2016 Mario Six 
 
-obj-$(CONFIG_TARGET_CONTROLCENTERDC) += controlcenterdc.o hre.o spl.o 
keyprogram.o dt_helpers.o
+obj-$(CONFIG_TARGET_CONTROLCENTERDC) += controlcenterdc.o hre.o keyprogram.o 
dt_helpers.o
 
 ifeq ($(CONFIG_SPL_BUILD),)
 obj-$(CONFIG_TARGET_CONTROLCENTERDC) += hydra.o ihs_phys.o
diff --git a/board/gdsys/a38x/spl.c b/board/gdsys/a38x/spl.c
deleted file mode 100644
index 84864d1974..00
--- a/board/gdsys/a38x/spl.c
+++ /dev/null
@@ -1,20 +0,0 @@
-// SPDX-License-Identifier: GPL-2.0+
-/*
- * (C) Copyright 2016
- * Mario Six, Guntermann & Drunck GmbH, mario@gdsys.cc
- */
-
-#include 
-#include 
-#include 
-
-void spl_board_init(void)
-{
-#if CONFIG_SPL_BOOT_DEVICE == SPL_BOOT_SPI_NOR_FLASH
-   u32 *bootrom_save = (u32 *)CONFIG_SPL_BOOTROM_SAVE;
-   u32 *regs = (u32 *)(*bootrom_save);
-
-   printf("Returning to BootROM (return address %08x)...\n", regs[13]);
-   return_to_bootrom();
-#endif
-}
diff --git a/configs/controlcenterdc_defconfig 
b/configs/controlcenterdc_defconfig
index eccc1d7dfc..89cc579261 100644
--- a/configs/controlcenterdc_defconfig
+++ b/configs/controlcenterdc_defconfig
@@ -27,7 +27,6 @@ CONFIG_SYS_CONSOLE_INFO_QUIET=y
 CONFIG_DISPLAY_BOARDINFO_LATE=y
 CONFIG_BOARD_LATE_INIT=y
 CONFIG_LAST_STAGE_INIT=y
-CONFIG_SPL_BOARD_INIT=y
 CONFIG_SPL_SYS_MALLOC_SIMPLE=y
 CONFIG_HUSH_PARSER=y
 # CONFIG_CMD_ELF is not set
-- 
2.31.1



[PATCH u-boot-mvebu v3 37/41] tools: kwbimage: Remove v1 kwbimage SPL padding to CONFIG_SYS_U_BOOT_OFFS bytes

2021-07-23 Thread Marek Behún
From: Pali Rohár 

This padding depends on board config file and therefore it makes the
mkimage binary tool board specific, which is not correct. One cannot use
mkimage tool built as a result for board A to generate images for board
B, even if both A and B are on the same platform.

This CONFIG_SYS_U_BOOT_OFFS padding was needed when kwbimage v1 contained
SPL code which loaded U-Boot proper based on CONFIG_SYS_U_BOOT_OFFS,
instead of reading correct offset from kwbimage header.

Now that SPL code parses kwbimage header and deterinate correct offset,
there is no need for this CONFIG_SYS_U_BOOT_OFFS padding anymore.

By removing it we also reduce the size of SPL code and therefore also
decrease the final size of v1 kwbimage. This means there is more space
for U-Boot proper binary.

Signed-off-by: Pali Rohár 
Reviewed-by: Marek Behún 
Reviewed-by: Chris Packham 
Reviewed-by: Stefan Roese 
---
 tools/Makefile   |  4 
 tools/kwbimage.c | 13 -
 2 files changed, 17 deletions(-)

diff --git a/tools/Makefile b/tools/Makefile
index 35aefc207c..4a86321f64 100644
--- a/tools/Makefile
+++ b/tools/Makefile
@@ -169,10 +169,6 @@ HOST_EXTRACFLAGS   += 
-DCONFIG_FIT_SIGNATURE_MAX_SIZE=0x
 HOST_EXTRACFLAGS   += -DCONFIG_FIT_CIPHER
 endif
 
-ifneq ($(CONFIG_SYS_U_BOOT_OFFS),)
-HOSTCFLAGS_kwbimage.o += -DCONFIG_SYS_U_BOOT_OFFS=$(CONFIG_SYS_U_BOOT_OFFS)
-endif
-
 # MXSImage needs LibSSL
 ifneq 
($(CONFIG_MX23)$(CONFIG_MX28)$(CONFIG_ARMADA_38X)$(CONFIG_TOOLS_LIBCRYPTO),)
 HOSTCFLAGS_kwbimage.o += \
diff --git a/tools/kwbimage.c b/tools/kwbimage.c
index 9ecda861e4..ccb0b92266 100644
--- a/tools/kwbimage.c
+++ b/tools/kwbimage.c
@@ -979,19 +979,6 @@ static size_t image_headersz_v1(int *hasext)
*hasext = 1;
}
 
-#if defined(CONFIG_SYS_U_BOOT_OFFS)
-   if (headersz > CONFIG_SYS_U_BOOT_OFFS) {
-   fprintf(stderr,
-   "Error: Image header (incl. SPL image) too big!\n");
-   fprintf(stderr, "header=0x%x CONFIG_SYS_U_BOOT_OFFS=0x%x!\n",
-   (int)headersz, CONFIG_SYS_U_BOOT_OFFS);
-   fprintf(stderr, "Increase CONFIG_SYS_U_BOOT_OFFS!\n");
-   return 0;
-   }
-
-   headersz = CONFIG_SYS_U_BOOT_OFFS;
-#endif
-
/*
 * The payload should be aligned on some reasonable
 * boundary
-- 
2.31.1



[PATCH u-boot-mvebu v3 33/41] SPL: Add support for specifying offset between header and image

2021-07-23 Thread Marek Behún
From: Pali Rohár 

Some image types (e.g. kwbimage v1) store the offset to SPL binary and
offset to U-Boot proper binary in their headers. To avoid reading SPL
binary when loading U-Boot proper, add support for specifying offset in
struct spl_image_info, which defines the offset from the beginning of
the header and the beginning of the executable data.

Initial support is added only for SPI, MMC and SATA code. We can extend
it later if needed.

Signed-off-by: Pali Rohár 
Reviewed-by: Marek Behún 
Reviewed-by: Stefan Roese 
---
 common/spl/spl_mmc.c  | 16 +++-
 common/spl/spl_sata.c | 12 +++-
 common/spl/spl_spi.c  |  2 +-
 include/spl.h |  1 +
 4 files changed, 28 insertions(+), 3 deletions(-)

diff --git a/common/spl/spl_mmc.c b/common/spl/spl_mmc.c
index 2377d0937d..9f9a87afcf 100644
--- a/common/spl/spl_mmc.c
+++ b/common/spl/spl_mmc.c
@@ -20,26 +20,40 @@
 static int mmc_load_legacy(struct spl_image_info *spl_image, struct mmc *mmc,
   ulong sector, struct image_header *header)
 {
+   u32 image_offset_sectors;
u32 image_size_sectors;
unsigned long count;
+   u32 image_offset;
int ret;
 
ret = spl_parse_image_header(spl_image, header);
if (ret)
return ret;
 
+   /* convert offset to sectors - round down */
+   image_offset_sectors = spl_image->offset / mmc->read_bl_len;
+   /* calculate remaining offset */
+   image_offset = spl_image->offset % mmc->read_bl_len;
+
/* convert size to sectors - round up */
image_size_sectors = (spl_image->size + mmc->read_bl_len - 1) /
 mmc->read_bl_len;
 
/* Read the header too to avoid extra memcpy */
-   count = blk_dread(mmc_get_blk_desc(mmc), sector, image_size_sectors,
+   count = blk_dread(mmc_get_blk_desc(mmc),
+ sector + image_offset_sectors,
+ image_size_sectors,
  (void *)(ulong)spl_image->load_addr);
debug("read %x sectors to %lx\n", image_size_sectors,
  spl_image->load_addr);
if (count != image_size_sectors)
return -EIO;
 
+   if (image_offset)
+   memmove((void *)(ulong)spl_image->load_addr,
+   (void *)(ulong)spl_image->load_addr + image_offset,
+   spl_image->size);
+
return 0;
 }
 
diff --git a/common/spl/spl_sata.c b/common/spl/spl_sata.c
index e108af0576..535a9219ef 100644
--- a/common/spl/spl_sata.c
+++ b/common/spl/spl_sata.c
@@ -36,6 +36,8 @@ static int spl_sata_load_image_raw(struct spl_image_info 
*spl_image,
struct image_header *header;
unsigned long count;
u32 image_size_sectors;
+   u32 image_offset_sectors;
+   u32 image_offset;
int ret;
 
header = spl_get_load_buffer(-sizeof(*header), stor_dev->blksz);
@@ -48,11 +50,19 @@ static int spl_sata_load_image_raw(struct spl_image_info 
*spl_image,
return ret;
 
image_size_sectors = DIV_ROUND_UP(spl_image->size, stor_dev->blksz);
-   count = blk_dread(stor_dev, sector, image_size_sectors,
+   image_offset_sectors = spl_image->offset / stor_dev->blksz;
+   image_offset = spl_image->offset % stor_dev->blksz;
+   count = blk_dread(stor_dev, sector + image_offset_sectors,
+   image_size_sectors,
(void *)spl_image->load_addr);
if (count != image_size_sectors)
return -EIO;
 
+   if (image_offset)
+   memmove((void *)spl_image->load_addr,
+   (void *)spl_image->load_addr + image_offset,
+   spl_image->size);
+
return 0;
 }
 
diff --git a/common/spl/spl_spi.c b/common/spl/spl_spi.c
index 6a4e033287..9884e7c185 100644
--- a/common/spl/spl_spi.c
+++ b/common/spl/spl_spi.c
@@ -159,7 +159,7 @@ static int spl_spi_load_image(struct spl_image_info 
*spl_image,
err = spl_parse_image_header(spl_image, header);
if (err)
return err;
-   err = spi_flash_read(flash, payload_offs,
+   err = spi_flash_read(flash, payload_offs + 
spl_image->offset,
 spl_image->size,
 (void *)spl_image->load_addr);
}
diff --git a/include/spl.h b/include/spl.h
index 74a1939452..d1a903fef7 100644
--- a/include/spl.h
+++ b/include/spl.h
@@ -219,6 +219,7 @@ struct spl_image_info {
void *fdt_addr;
 #endif
u32 boot_device;
+   u32 offset;
u32 size;
u32 flags;
void *arg;
-- 
2.31.1



[PATCH u-boot-mvebu v3 35/41] arm: mvebu: Load U-Boot proper binary in SPL code based on kwbimage header

2021-07-23 Thread Marek Behún
From: Pali Rohár 

Now that proper load and execution addresses are set in v1 kwbimage we
can use it for loading and booting U-Boot proper.

Use the new spl_parse_board_header() function to implement parsing the
kwbimage v1 header. Use information from this header to locate offset and
size of the U-Boot proper binary, instead of using the legacy U-Boot
header which is prepended to the U-Boot proper binary stored at fixed
offset. This has the advantage that we do not need to relay on legacy
U-Boot header anymore and therefore U-Boot proper binary can be stored at
any offset, as is the case when loading & booting U-Boot proper by
BootROM. The CONFIG_SYS_U_BOOT_OFFS option is therefore not used by SPL
code anymore.

Also allow to compile U-Boot SPL without CONFIG_SPL_SPI_FLASH_SUPPORT,
CONFIG_SPL_MMC_SUPPORT or CONFIG_SPL_SATA_SUPPORT set. In this case
BootROM is used for loading and executing U-Boot proper. This reduces the
size of U-Boot's SPL image. By default these config options are enabled
and so BootROM loading is not used. In some cases BootROM reads from SPI
NOR at lower speed than U-Boot SPL. So people can decide whether they
want to have smaller SPL binary at the cost of slower boot.

Therefore dependency on CONFIG_SPL_DM_SPI, CONFIG_SPL_SPI_FLASH_SUPPORT,
CONFIG_SPL_SPI_LOAD, CONFIG_SPL_SPI_SUPPORT, CONFIG_SPL_DM_GPIO,
CONFIG_SPL_DM_MMC, CONFIG_SPL_GPIO_SUPPORT, CONFIG_SPL_LIBDISK_SUPPORT,
CONFIG_SPL_MMC_SUPPORT, CONFIG_SPL_SATA_SUPPORT and
CONFIG_SPL_LIBDISK_SUPPORT is changed from strict to related "imply"
(which can be selectivelly turned off and causes booting via BootROM).

Options CONFIG_SYS_SPI_U_BOOT_OFFS,
CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_SECTOR and
CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_DATA_PART_OFFSET have to to be set to
zero as they define the location where kwbimage header starts. It is the
location where BootROM expects start of the kwbimage from which it reads,
parses and executes SPL part. The same applies to option
CONFIG_SPL_SATA_RAW_U_BOOT_SECTOR, which has to be set to one.

Update all config files to set correct values of these options and set
CONFIG_SYS_U_BOOT_OFFS to the correct value - the offset where U-Boot
proper starts.

Signed-off-by: Pali Rohár 
Reviewed-by: Marek Behún 
Reviewed-by: Stefan Roese 
---
 arch/arm/mach-mvebu/Kconfig |  22 +--
 arch/arm/mach-mvebu/spl.c   | 205 ++--
 board/kobol/helios4/Kconfig |   5 -
 board/solidrun/clearfog/Kconfig |   5 -
 common/spl/Kconfig  |   4 +-
 configs/clearfog_defconfig  |   1 -
 configs/controlcenterdc_defconfig   |   1 -
 configs/db-88f6720_defconfig|   1 -
 configs/db-88f6820-amc_defconfig|   1 -
 configs/db-88f6820-gp_defconfig |   2 -
 configs/db-mv784mp-gp_defconfig |   1 -
 configs/ds414_defconfig |   1 -
 configs/helios4_defconfig   |   1 -
 configs/maxbcm_defconfig|   1 -
 configs/theadorable_debug_defconfig |   1 -
 configs/turris_omnia_defconfig  |   1 -
 configs/x530_defconfig  |   1 -
 include/configs/clearfog.h  |   5 +-
 include/configs/controlcenterdc.h   |   7 +-
 include/configs/db-88f6720.h|   2 +-
 include/configs/db-88f6820-amc.h|   2 +-
 include/configs/db-88f6820-gp.h |   5 +-
 include/configs/db-mv784mp-gp.h |   2 +-
 include/configs/ds414.h |   2 +-
 include/configs/helios4.h   |   5 +-
 include/configs/theadorable.h   |   2 +-
 include/configs/turris_omnia.h  |   5 +-
 include/configs/x530.h  |   2 +-
 28 files changed, 224 insertions(+), 69 deletions(-)

diff --git a/arch/arm/mach-mvebu/Kconfig b/arch/arm/mach-mvebu/Kconfig
index 2133d9a172..140c4199a2 100644
--- a/arch/arm/mach-mvebu/Kconfig
+++ b/arch/arm/mach-mvebu/Kconfig
@@ -253,27 +253,27 @@ choice
 config MVEBU_SPL_BOOT_DEVICE_SPI
bool "SPI NOR flash"
imply ENV_IS_IN_SPI_FLASH
-   select SPL_DM_SPI
-   select SPL_SPI_FLASH_SUPPORT
-   select SPL_SPI_LOAD
-   select SPL_SPI_SUPPORT
+   imply SPL_DM_SPI
+   imply SPL_SPI_FLASH_SUPPORT
+   imply SPL_SPI_LOAD
+   imply SPL_SPI_SUPPORT
select SPL_BOOTROM_SUPPORT
 
 config MVEBU_SPL_BOOT_DEVICE_MMC
bool "SDIO/MMC card"
imply ENV_IS_IN_MMC
# GPIO needed for eMMC/SD card presence detection
-   select SPL_DM_GPIO
-   select SPL_DM_MMC
-   select SPL_GPIO_SUPPORT
-   select SPL_LIBDISK_SUPPORT
-   select SPL_MMC_SUPPORT
+   imply SPL_DM_GPIO
+   imply SPL_DM_MMC
+   imply SPL_GPIO_SUPPORT
+   imply SPL_LIBDISK_SUPPORT
+   imply SPL_MMC_SUPPORT
select SPL_BOOTROM_SUPPORT
 
 config MVEBU_SPL_BOOT_DEVICE_SATA
bool "SATA"
-   select SPL_SATA_SUPPORT
-   select SPL_LIBDISK_SUPPORT
+   imply SPL_SATA_SUPPORT
+   imply SPL_LIBDISK_SUPPORT
select SPL_BOOTROM_SUPPORT
 
 config MVEBU_SPL_BOOT_DEVICE_UART
diff --git a/arch/arm/mach-mvebu/spl.c 

[PATCH u-boot-mvebu v3 20/41] tools: kwbimage: Mark all BootROM structures __packed

2021-07-23 Thread Marek Behún
From: Pali Rohár 

These structures must have specific size without padding, so mark them as
packed via the de-facto standard macro __packed. Also replace PACKED
macro.

Signed-off-by: Pali Rohár 
Reviewed-by: Marek Behún 
Reviewed-by: Stefan Roese 
---
 tools/kwbimage.h | 30 ++
 tools/kwboot.c   |  8 +---
 2 files changed, 19 insertions(+), 19 deletions(-)

diff --git a/tools/kwbimage.h b/tools/kwbimage.h
index 9f86da46e8..e063e3e41e 100644
--- a/tools/kwbimage.h
+++ b/tools/kwbimage.h
@@ -11,6 +11,12 @@
 #include 
 #include 
 
+#ifdef __GNUC__
+#define __packed __attribute((packed))
+#else
+#define __packed
+#endif
+
 #define KWBIMAGE_MAX_CONFIG((0x1dc - 0x20)/sizeof(struct reg_config))
 #define MAX_TEMPBUF_LEN32
 
@@ -46,12 +52,12 @@ struct main_hdr_v0 {
uint16_t rsvd2; /* 0x1C-0x1D */
uint8_t  ext;   /* 0x1E  */
uint8_t  checksum;  /* 0x1F  */
-};
+} __packed;
 
 struct ext_hdr_v0_reg {
uint32_t raddr;
uint32_t rdata;
-};
+} __packed;
 
 #define EXT_HDR_V0_REG_COUNT ((0x1dc - 0x20) / sizeof(struct ext_hdr_v0_reg))
 
@@ -61,12 +67,12 @@ struct ext_hdr_v0 {
struct ext_hdr_v0_reg rcfg[EXT_HDR_V0_REG_COUNT];
uint8_t   reserved2[7];
uint8_t   checksum;
-};
+} __packed;
 
 struct kwb_header {
struct main_hdr_v0  kwb_hdr;
struct ext_hdr_v0   kwb_exthdr;
-};
+} __packed;
 
 /* Structure of the main header, version 1 (Armada 370/38x/XP) */
 struct main_hdr_v1 {
@@ -87,7 +93,7 @@ struct main_hdr_v1 {
uint16_t reserved5; /* 0x1C-0x1D */
uint8_t  ext;   /* 0x1E  */
uint8_t  checksum;  /* 0x1F  */
-};
+} __packed;
 
 /*
  * Main header options
@@ -109,21 +115,21 @@ struct opt_hdr_v1 {
uint8_t  headersz_msb;
uint16_t headersz_lsb;
char data[0];
-};
+} __packed;
 
 /*
  * Public Key data in DER format
  */
 struct pubkey_der_v1 {
uint8_t key[524];
-};
+} __packed;
 
 /*
  * Signature (RSA 2048)
  */
 struct sig_v1 {
uint8_t sig[256];
-};
+} __packed;
 
 /*
  * Structure of secure header (Armada 38x)
@@ -146,7 +152,7 @@ struct secure_hdr_v1 {
uint8_t  next;  /* 0x25E0 */
uint8_t  reserved4; /* 0x25E1 */
uint16_t reserved5; /* 0x25E2 - 0x25E3 */
-};
+} __packed;
 
 /*
  * Structure of register set
@@ -159,14 +165,14 @@ struct register_set_hdr_v1 {
struct {
uint32_t address;   /* 0x4+8*N - 0x7+8*N */
uint32_t value; /* 0x8+8*N - 0xB+8*N */
-   } entry;
+   } __packed entry;
struct {
uint8_t  next;  /* 0xC+8*N */
uint8_t  delay; /* 0xD+8*N */
uint16_t reserved;  /* 0xE+8*N - 0xF+8*N */
-   } last_entry;
+   } __packed last_entry;
} data[];
-};
+} __packed;
 
 /*
  * Value 0 in register_set_hdr_v1 delay field is special.
diff --git a/tools/kwboot.c b/tools/kwboot.c
index 4be094c9c8..2683e5360c 100644
--- a/tools/kwboot.c
+++ b/tools/kwboot.c
@@ -26,12 +26,6 @@
 #include 
 #include 
 
-#ifdef __GNUC__
-#define PACKED __attribute((packed))
-#else
-#define PACKED
-#endif
-
 /*
  * Marvell BootROM UART Sensing
  */
@@ -68,7 +62,7 @@ struct kwboot_block {
uint8_t _pnum;
uint8_t data[128];
uint8_t csum;
-} PACKED;
+} __packed;
 
 #define KWBOOT_BLK_RSP_TIMEO 1000 /* ms */
 
-- 
2.31.1



[PATCH u-boot-mvebu v3 36/41] arm: mvebu: Remove legacy U-Boot header from kwbimage v1 files

2021-07-23 Thread Marek Behún
From: Pali Rohár 

The SPL code now already parses kwbimage v1 headers where all necessary
information about how to load and execute U-Boot proper is present. The
legacy 64-byte U-Boot header is not used anymore.

Remove this 64-byte header by putting u-boot.bin binary (instead of
u-boot.img) into kwbimage v1 and let SPL code or BootROM to load U-Boot
directly at its execution address.

Signed-off-by: Pali Rohár 
Reviewed-by: Marek Behún 
Reviewed-by: Chris Packham 
Reviewed-by: Stefan Roese 
---
 Makefile | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/Makefile b/Makefile
index c6de6393cb..26999fb2ab 100644
--- a/Makefile
+++ b/Makefile
@@ -1398,7 +1398,7 @@ MKIMAGEFLAGS_u-boot.kwb = -n $(KWD_CONFIG_FILE) \
-T kwbimage -a $(CONFIG_SYS_TEXT_BASE) -e $(CONFIG_SYS_TEXT_BASE)
 
 MKIMAGEFLAGS_u-boot-spl.kwb = -n $(KWD_CONFIG_FILE) \
-   -T kwbimage -a $(shell printf "0x%x" $$(($(CONFIG_SYS_TEXT_BASE)-64))) 
-e $(CONFIG_SYS_TEXT_BASE) \
+   -T kwbimage -a $(CONFIG_SYS_TEXT_BASE) -e $(CONFIG_SYS_TEXT_BASE) \
$(if $(KEYDIR),-k $(KEYDIR))
 
 MKIMAGEFLAGS_u-boot.pbl = -n $(srctree)/$(CONFIG_SYS_FSL_PBL_RCW:"%"=%) \
@@ -1441,7 +1441,7 @@ u-boot.itb: u-boot-nodtb.bin \
$(BOARD_SIZE_CHECK)
 endif
 
-u-boot-spl.kwb: u-boot.img spl/u-boot-spl.bin FORCE
+u-boot-spl.kwb: u-boot.bin spl/u-boot-spl.bin FORCE
$(call if_changed,mkimage)
 
 u-boot.sha1:   u-boot.bin
-- 
2.31.1



[PATCH u-boot-mvebu v3 14/41] tools: kwbimage: Fix calculating size of binary header

2021-07-23 Thread Marek Behún
From: Pali Rohár 

Binary header consist of:
* 1 byte for header type
* 3 bytes for header size
* 1 byte for number of arguments
* 3 reserved bytes
* N*4 bytes for arguments
* M bytes (aligned to 4 bytes) for executable data
* 1 byte for information about next header
* 3 reserved bytes

The first four bytes are specified as
  sizeof(struct opt_hdr_v1)
and the remaining bytes as
  ALIGN(s.st_size, 4) + (binarye->binary.nargs + 2) * sizeof(uint32_t)

Signed-off-by: Pali Rohár 
Reviewed-by: Marek Behún 
Reviewed-by: Stefan Roese 
---
 tools/kwbimage.c | 11 ++-
 1 file changed, 2 insertions(+), 9 deletions(-)

diff --git a/tools/kwbimage.c b/tools/kwbimage.c
index 2d4574af7d..6c9f93ae8b 100644
--- a/tools/kwbimage.c
+++ b/tools/kwbimage.c
@@ -984,7 +984,7 @@ static size_t image_headersz_v1(int *hasext)
}
 
headersz += sizeof(struct opt_hdr_v1) +
-   s.st_size +
+   ALIGN(s.st_size, 4) +
(binarye->binary.nargs + 2) * sizeof(uint32_t);
if (hasext)
*hasext = 1;
@@ -1051,14 +1051,7 @@ int add_binary_header_v1(uint8_t *cur)
 
binhdrsz = sizeof(struct opt_hdr_v1) +
(binarye->binary.nargs + 2) * sizeof(uint32_t) +
-   s.st_size;
-
-   /*
-* The size includes the binary image size, rounded
-* up to a 4-byte boundary. Plus 4 bytes for the
-* next-header byte and 3-byte alignment at the end.
-*/
-   binhdrsz = ALIGN(binhdrsz, 4) + 4;
+   ALIGN(s.st_size, 4);
hdr->headersz_lsb = cpu_to_le16(binhdrsz & 0x);
hdr->headersz_msb = (binhdrsz & 0x) >> 16;
 
-- 
2.31.1



[PATCH u-boot-mvebu v3 13/41] tools: kwbimage: Change maximum number of arguments in binary header to 256

2021-07-23 Thread Marek Behún
From: Pali Rohár 

The number is stored in one byte, so the maximum should be 255.

Signed-off-by: Pali Rohár 
Reviewed-by: Marek Behún 
Reviewed-by: Stefan Roese 
---
 tools/kwbimage.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tools/kwbimage.c b/tools/kwbimage.c
index 76c25628d4..2d4574af7d 100644
--- a/tools/kwbimage.c
+++ b/tools/kwbimage.c
@@ -89,7 +89,7 @@ struct nand_ecc_mode nand_ecc_modes[] = {
 /* Used to identify an undefined execution or destination address */
 #define ADDR_INVALID ((uint32_t)-1)
 
-#define BINARY_MAX_ARGS 8
+#define BINARY_MAX_ARGS 255
 
 /* In-memory representation of a line of the configuration file */
 
-- 
2.31.1



[PATCH u-boot-mvebu v3 12/41] tools: kwbimage: Use -a parameter (load address) for v1 images

2021-07-23 Thread Marek Behún
From: Pali Rohár 

The data part of v1 kwbimage currently contains U-Boot binary prepended
by 64 bytes long Legacy U-Boot image header. This means that the load
address is currently substracted by 64 bytes to ensure that U-Boot's
entry point is at specified execution address.

As mkimage has already separate arguments for load (-a) and execution
(-e) address, there is no need to derive fixed load address from
execution address.

Therefore remove this load address hack from the kwbimage tool and
support generating v1 kwbimage with arbitrary addresses for load and
execution.

Finally, calculate correct load address by caller for mkimage tool in
Makefile. File u-boot-spl.kwb is always a v1 kwbimage and it is the only
v1 kwbimage which U-Boot's build system generates.

Remove also useless overwriting of destaddr for /binary.0 to the value
which is already set on previous lines.

Signed-off-by: Pali Rohár 
Reviewed-by: Marek Behún 
Reviewed-by: Stefan Roese 
Reviewed-by: Chris Packham 
Tested-by: Chris Packham 
---
 Makefile |  2 +-
 tools/kwbimage.c | 10 +-
 2 files changed, 2 insertions(+), 10 deletions(-)

diff --git a/Makefile b/Makefile
index ca2432c8ce..c6de6393cb 100644
--- a/Makefile
+++ b/Makefile
@@ -1398,7 +1398,7 @@ MKIMAGEFLAGS_u-boot.kwb = -n $(KWD_CONFIG_FILE) \
-T kwbimage -a $(CONFIG_SYS_TEXT_BASE) -e $(CONFIG_SYS_TEXT_BASE)
 
 MKIMAGEFLAGS_u-boot-spl.kwb = -n $(KWD_CONFIG_FILE) \
-   -T kwbimage -a $(CONFIG_SYS_TEXT_BASE) -e $(CONFIG_SYS_TEXT_BASE) \
+   -T kwbimage -a $(shell printf "0x%x" $$(($(CONFIG_SYS_TEXT_BASE)-64))) 
-e $(CONFIG_SYS_TEXT_BASE) \
$(if $(KEYDIR),-k $(KEYDIR))
 
 MKIMAGEFLAGS_u-boot.pbl = -n $(srctree)/$(CONFIG_SYS_FSL_PBL_RCW:"%"=%) \
diff --git a/tools/kwbimage.c b/tools/kwbimage.c
index bc30233871..76c25628d4 100644
--- a/tools/kwbimage.c
+++ b/tools/kwbimage.c
@@ -1252,8 +1252,7 @@ static void *image_create_v1(size_t *imagesz, struct 
image_tool_params *params,
cpu_to_le32(payloadsz - headersz);
main_hdr->headersz_lsb = cpu_to_le16(headersz & 0x);
main_hdr->headersz_msb = (headersz & 0x) >> 16;
-   main_hdr->destaddr = cpu_to_le32(params->addr)
-- sizeof(image_header_t);
+   main_hdr->destaddr = cpu_to_le32(params->addr);
main_hdr->execaddr = cpu_to_le32(params->ep);
main_hdr->srcaddr  = cpu_to_le32(headersz);
main_hdr->ext  = hasext;
@@ -1273,13 +1272,6 @@ static void *image_create_v1(size_t *imagesz, struct 
image_tool_params *params,
e = image_find_option(IMAGE_CFG_DEBUG);
if (e)
main_hdr->flags = e->debug ? 0x1 : 0;
-   e = image_find_option(IMAGE_CFG_BINARY);
-   if (e) {
-   char *s = strrchr(e->binary.file, '/');
-
-   if (s && strcmp(s, "/binary.0") == 0)
-   main_hdr->destaddr = cpu_to_le32(params->addr);
-   }
 
/*
 * For SATA srcaddr is specified in number of sectors starting from
-- 
2.31.1



[PATCH u-boot-mvebu v3 02/41] tools: kwbimage: Simplify aligning and calculating checksum

2021-07-23 Thread Marek Behún
From: Pali Rohár 

The return value of kwbimage_generate() is used for aligning the data
part of kwbimage. Use it for calculating proper 4 byte alignment as is
required by BootROM and also use it for allocating additional 4 bytes
for the 32-bit data checksum.

This simplifies the alignment code to be only at one place (in function
kwbimage_generate) and also simplifies setting checksum as it can be
directly updated in memory.

Signed-off-by: Pali Rohár 
Reviewed-by: Marek Behún 
Reviewed-by: Stefan Roese 
Reviewed-by: Chris Packham 
Tested-by: Chris Packham 
---
 tools/kwbimage.c | 36 +++-
 1 file changed, 15 insertions(+), 21 deletions(-)

diff --git a/tools/kwbimage.c b/tools/kwbimage.c
index 02fd0c949f..c775abf0e3 100644
--- a/tools/kwbimage.c
+++ b/tools/kwbimage.c
@@ -891,7 +891,7 @@ static void *image_create_v0(size_t *imagesz, struct 
image_tool_params *params,
 
/* Fill in the main header */
main_hdr->blocksize =
-   cpu_to_le32(payloadsz + sizeof(uint32_t) - headersz);
+   cpu_to_le32(payloadsz - headersz);
main_hdr->srcaddr   = cpu_to_le32(headersz);
main_hdr->ext   = has_ext;
main_hdr->destaddr  = cpu_to_le32(params->addr);
@@ -1249,7 +1249,7 @@ static void *image_create_v1(size_t *imagesz, struct 
image_tool_params *params,
 
/* Fill the main header */
main_hdr->blocksize=
-   cpu_to_le32(payloadsz - headersz + sizeof(uint32_t));
+   cpu_to_le32(payloadsz - headersz);
main_hdr->headersz_lsb = cpu_to_le16(headersz & 0x);
main_hdr->headersz_msb = (headersz & 0x) >> 16;
main_hdr->destaddr = cpu_to_le32(params->addr)
@@ -1519,7 +1519,6 @@ static void kwbimage_set_header(void *ptr, struct stat 
*sbuf, int ifd,
size_t headersz = 0;
uint32_t checksum;
int ret;
-   int size;
 
fcfg = fopen(params->imagename, "r");
if (!fcfg) {
@@ -1547,9 +1546,6 @@ static void kwbimage_set_header(void *ptr, struct stat 
*sbuf, int ifd,
exit(EXIT_FAILURE);
}
 
-   /* The MVEBU BootROM does not allow non word aligned payloads */
-   sbuf->st_size = ALIGN(sbuf->st_size, 4);
-
version = image_get_version();
switch (version) {
/*
@@ -1580,16 +1576,10 @@ static void kwbimage_set_header(void *ptr, struct stat 
*sbuf, int ifd,
free(image_cfg);
 
/* Build and add image checksum header */
-   checksum =
-   cpu_to_le32(image_checksum32((uint32_t *)ptr, sbuf->st_size));
-   size = write(ifd, , sizeof(uint32_t));
-   if (size != sizeof(uint32_t)) {
-   fprintf(stderr, "Error:%s - Checksum write %d bytes %s\n",
-   params->cmdname, size, params->imagefile);
-   exit(EXIT_FAILURE);
-   }
-
-   sbuf->st_size += sizeof(uint32_t);
+   checksum = cpu_to_le32(image_checksum32((uint8_t *)ptr + headersz,
+   sbuf->st_size - headersz - sizeof(uint32_t)));
+   memcpy((uint8_t *)ptr + sbuf->st_size - sizeof(uint32_t), ,
+   sizeof(uint32_t));
 
/* Finally copy the header into the image area */
memcpy(ptr, image, headersz);
@@ -1650,6 +1640,7 @@ static int kwbimage_generate(struct image_tool_params 
*params,
 struct image_type_params *tparams)
 {
FILE *fcfg;
+   struct stat s;
int alloc_len;
int version;
void *hdr;
@@ -1662,6 +1653,12 @@ static int kwbimage_generate(struct image_tool_params 
*params,
exit(EXIT_FAILURE);
}
 
+   if (stat(params->datafile, )) {
+   fprintf(stderr, "Could not stat data file %s: %s\n",
+   params->datafile, strerror(errno));
+   exit(EXIT_FAILURE);
+   }
+
image_cfg = malloc(IMAGE_CFG_ELEMENT_MAX *
   sizeof(struct image_cfg_element));
if (!image_cfg) {
@@ -1719,12 +1716,9 @@ static int kwbimage_generate(struct image_tool_params 
*params,
/*
 * The resulting image needs to be 4-byte aligned. At least
 * the Marvell hdrparser tool complains if its unaligned.
-* By returning 1 here in this function, called via
-* tparams->vrec_header() in mkimage.c, mkimage will
-* automatically pad the the resulting image to a 4-byte
-* size if necessary.
+* After the image data is stored 4-byte checksum.
 */
-   return 1;
+   return 4 + (4 - s.st_size % 4) % 4;
 }
 
 /*
-- 
2.31.1



[PATCH u-boot-mvebu v3 11/41] tools: kwbimage: Cosmetic fix - remove redundant space character

2021-07-23 Thread Marek Behún
Remove this space, since the constants are indented by tabs.

Signed-off-by: Marek Behún 
Reviewed-by: Stefan Roese 
Reviewed-by: Chris Packham 
Tested-by: Chris Packham 
---
 tools/kwbimage.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tools/kwbimage.h b/tools/kwbimage.h
index 9856b44536..cab3d95d13 100644
--- a/tools/kwbimage.h
+++ b/tools/kwbimage.h
@@ -28,7 +28,7 @@
 #define IBR_HDR_PEX_ID 0x9C
 #define IBR_HDR_UART_ID0x69
 #define IBR_HDR_SDIO_ID0xAE
-#define IBR_DEF_ATTRIB 0x00
+#define IBR_DEF_ATTRIB 0x00
 
 /* Structure of the main header, version 0 (Kirkwood, Dove) */
 struct main_hdr_v0 {
-- 
2.31.1



[PATCH u-boot-mvebu v3 10/41] tools: kwbimage: Print size of binary header in kwbimage_print_header()

2021-07-23 Thread Marek Behún
From: Pali Rohár 

The binary header in kwbimage contains executable SPL code.

Print information about this binary header and not only information
about it's data part.

Signed-off-by: Pali Rohár 
Reviewed-by: Marek Behún 
Reviewed-by: Stefan Roese 
Reviewed-by: Chris Packham 
Tested-by: Chris Packham 
---
 tools/kwbimage.c | 24 
 1 file changed, 24 insertions(+)

diff --git a/tools/kwbimage.c b/tools/kwbimage.c
index edda0ce7aa..bc30233871 100644
--- a/tools/kwbimage.c
+++ b/tools/kwbimage.c
@@ -1627,6 +1627,30 @@ static void kwbimage_print_header(const void *ptr)
printf("Image Type:   MVEBU Boot from %s Image\n",
   image_boot_mode_name(mhdr->blockid));
printf("Image version:%d\n", image_version((void *)ptr));
+   if (image_version((void *)ptr) == 1) {
+   struct main_hdr_v1 *mhdr = (struct main_hdr_v1 *)ptr;
+
+   if (mhdr->ext & 0x1) {
+   struct opt_hdr_v1 *ohdr = (struct opt_hdr_v1 *)
+ ((uint8_t *)ptr +
+  sizeof(*mhdr));
+
+   while (1) {
+   uint32_t ohdr_size;
+
+   ohdr_size = (ohdr->headersz_msb << 16) |
+   le16_to_cpu(ohdr->headersz_lsb);
+   if (ohdr->headertype == OPT_HDR_V1_BINARY_TYPE) 
{
+   printf("BIN Hdr Size: ");
+   genimg_print_size(ohdr_size - 12 - 4 * 
ohdr->data[0]);
+   }
+   if (!(*((uint8_t *)ohdr + ohdr_size - 4) & 0x1))
+   break;
+   ohdr = (struct opt_hdr_v1 *)((uint8_t *)ohdr +
+ohdr_size);
+   }
+   }
+   }
printf("Data Size:");
genimg_print_size(mhdr->blocksize - sizeof(uint32_t));
printf("Load Address: %08x\n", mhdr->destaddr);
-- 
2.31.1



[PATCH u-boot-mvebu v3 09/41] tools: kwbimage: Validate data checksum of v1 images

2021-07-23 Thread Marek Behún
From: Pali Rohár 

The data part of v1 images contains 32-bit checksum after the data.
Validate whether this checksum is correct.

Signed-off-by: Pali Rohár 
Reviewed-by: Marek Behún 
Reviewed-by: Stefan Roese 
Reviewed-by: Chris Packham 
Tested-by: Chris Packham 
---
 tools/kwbimage.c | 43 +++
 1 file changed, 43 insertions(+)

diff --git a/tools/kwbimage.c b/tools/kwbimage.c
index 5d017dd5ac..edda0ce7aa 100644
--- a/tools/kwbimage.c
+++ b/tools/kwbimage.c
@@ -1672,6 +1672,8 @@ static int kwbimage_verify_header(unsigned char *ptr, int 
image_size,
 
if (image_version((void *)ptr) == 1) {
struct main_hdr_v1 *mhdr = (struct main_hdr_v1 *)ptr;
+   uint32_t offset;
+   uint32_t size;
 
if (mhdr->ext & 0x1) {
uint32_t ohdr_size;
@@ -1697,6 +1699,47 @@ static int kwbimage_verify_header(unsigned char *ptr, 
int image_size,
 ohdr_size);
}
}
+
+   offset = le32_to_cpu(mhdr->srcaddr);
+
+   /*
+* For SATA srcaddr is specified in number of sectors.
+* The main header is must be stored at sector number 1.
+* This expects that sector size is 512 bytes and recalculates
+* data offset to bytes relative to the main header.
+*/
+   if (mhdr->blockid == IBR_HDR_SATA_ID) {
+   if (offset < 1)
+   return -FDT_ERR_BADSTRUCTURE;
+   offset -= 1;
+   offset *= 512;
+   }
+
+   /*
+* For SDIO srcaddr is specified in number of sectors.
+* This expects that sector size is 512 bytes and recalculates
+* data offset to bytes.
+*/
+   if (mhdr->blockid == IBR_HDR_SDIO_ID)
+   offset *= 512;
+
+   /*
+* For PCIe srcaddr is always set to 0x.
+* This expects that data starts after all headers.
+*/
+   if (mhdr->blockid == IBR_HDR_PEX_ID && offset == 0x)
+   offset = header_size;
+
+   if (offset > image_size || offset % 4 != 0)
+   return -FDT_ERR_BADSTRUCTURE;
+
+   size = le32_to_cpu(mhdr->blocksize);
+   if (offset + size > image_size || size % 4 != 0)
+   return -FDT_ERR_BADSTRUCTURE;
+
+   if (image_checksum32(ptr + offset, size - 4) !=
+   *(uint32_t *)(ptr + offset + size - 4))
+   return -FDT_ERR_BADSTRUCTURE;
}
 
return 0;
-- 
2.31.1



[PATCH u-boot-mvebu v3 08/41] tools: kwbimage: Validate extended headers of v1 images

2021-07-23 Thread Marek Behún
From: Pali Rohár 

Add basic checks for extended headers of v1 images.

Signed-off-by: Pali Rohár 
Reviewed-by: Marek Behún 
Reviewed-by: Stefan Roese 
Reviewed-by: Chris Packham 
Tested-by: Chris Packham 
---
 tools/kwbimage.c | 29 +
 1 file changed, 29 insertions(+)

diff --git a/tools/kwbimage.c b/tools/kwbimage.c
index 4d9d818538..5d017dd5ac 100644
--- a/tools/kwbimage.c
+++ b/tools/kwbimage.c
@@ -1670,6 +1670,35 @@ static int kwbimage_verify_header(unsigned char *ptr, 
int image_size,
}
}
 
+   if (image_version((void *)ptr) == 1) {
+   struct main_hdr_v1 *mhdr = (struct main_hdr_v1 *)ptr;
+
+   if (mhdr->ext & 0x1) {
+   uint32_t ohdr_size;
+   struct opt_hdr_v1 *ohdr = (struct opt_hdr_v1 *)
+ (ptr + sizeof(*mhdr));
+
+   while (1) {
+   if ((uint8_t *)ohdr + sizeof(*ohdr) >
+   (uint8_t *)mhdr + header_size)
+   return -FDT_ERR_BADSTRUCTURE;
+
+   ohdr_size = (ohdr->headersz_msb << 16) |
+   le16_to_cpu(ohdr->headersz_lsb);
+
+   if (ohdr_size < 8 ||
+   (uint8_t *)ohdr + ohdr_size >
+   (uint8_t *)mhdr + header_size)
+   return -FDT_ERR_BADSTRUCTURE;
+
+   if (!(*((uint8_t *)ohdr + ohdr_size - 4) & 0x1))
+   break;
+   ohdr = (struct opt_hdr_v1 *)((uint8_t *)ohdr +
+ohdr_size);
+   }
+   }
+   }
+
return 0;
 }
 
-- 
2.31.1



[PATCH u-boot-mvebu v3 07/41] tools: kwbimage: Fix check for v0 extended header checksum

2021-07-23 Thread Marek Behún
From: Pali Rohár 

Extended header checksum for v0 image is present only in the case when
extended header is present. Skip checksum validation if extended header
is not present.

Signed-off-by: Pali Rohár 
Reviewed-by: Marek Behún 
Reviewed-by: Stefan Roese 
Reviewed-by: Chris Packham 
Tested-by: Chris Packham 
---
 tools/kwbimage.c | 18 +++---
 1 file changed, 11 insertions(+), 7 deletions(-)

diff --git a/tools/kwbimage.c b/tools/kwbimage.c
index 724459fb8e..4d9d818538 100644
--- a/tools/kwbimage.c
+++ b/tools/kwbimage.c
@@ -1655,15 +1655,19 @@ static int kwbimage_verify_header(unsigned char *ptr, 
int image_size,
 
/* Only version 0 extended header has checksum */
if (image_version((void *)ptr) == 0) {
-   struct ext_hdr_v0 *ext_hdr;
+   struct main_hdr_v0 *mhdr = (struct main_hdr_v0 *)ptr;
 
-   ext_hdr = (struct ext_hdr_v0 *)
+   if (mhdr->ext & 0x1) {
+   struct ext_hdr_v0 *ext_hdr;
+
+   ext_hdr = (struct ext_hdr_v0 *)
(ptr + sizeof(struct main_hdr_v0));
-   checksum = image_checksum8(ext_hdr,
-  sizeof(struct ext_hdr_v0)
-  - sizeof(uint8_t));
-   if (checksum != ext_hdr->checksum)
-   return -FDT_ERR_BADSTRUCTURE;
+   checksum = image_checksum8(ext_hdr,
+  sizeof(struct ext_hdr_v0)
+  - sizeof(uint8_t));
+   if (checksum != ext_hdr->checksum)
+   return -FDT_ERR_BADSTRUCTURE;
+   }
}
 
return 0;
-- 
2.31.1



[PATCH u-boot-mvebu v3 06/41] tools: kwbimage: Don't crash when binary file name does not contain '/'

2021-07-23 Thread Marek Behún
From: Pali Rohár 

In the case when the file name is specified relative to the current
working directory, it does not contain '/' character and strrchr()
returns NULL.

The following strcmp() function then crashes on NULL pointer
dereference.

Signed-off-by: Pali Rohár 
Reviewed-by: Marek Behún 
Reviewed-by: Stefan Roese 
Reviewed-by: Chris Packham 
Tested-by: Chris Packham 
---
 tools/kwbimage.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tools/kwbimage.c b/tools/kwbimage.c
index c65a40ecb7..724459fb8e 100644
--- a/tools/kwbimage.c
+++ b/tools/kwbimage.c
@@ -1277,7 +1277,7 @@ static void *image_create_v1(size_t *imagesz, struct 
image_tool_params *params,
if (e) {
char *s = strrchr(e->binary.file, '/');
 
-   if (strcmp(s, "/binary.0") == 0)
+   if (s && strcmp(s, "/binary.0") == 0)
main_hdr->destaddr = cpu_to_le32(params->addr);
}
 
-- 
2.31.1



  1   2   >