Re: [PATCH v5 18/27] misc: am33xx: add control module driver

2020-11-08 Thread Dario Binacchi
Hi Simon,
I still have some doubts and therefore I would like to also add
Lokesh on this matter to finally decide what to do.

> Il 03/11/2020 16:12 Simon Glass  ha scritto:
> 
>  
> Hi Dario,
> 
> On Sun, 1 Nov 2020 at 02:13, Dario Binacchi  wrote:
> >
> > Hi Simon,
> >
> > > Il 28/10/2020 03:10 Simon Glass  ha scritto:
> > >
> > >
> > > On Sun, 25 Oct 2020 at 06:40, Dario Binacchi  wrote:
> > > >
> > > > The implementation of this driver was needed to bind the device tree
> > > > sub-nodes of the 'clocks' node. In fact, the lack of the compatible
> > > > property in the 'clocks' node does not allow the generic 'syscon' or
> > > > 'simple-bus' drivers linked to the 'scm_conf@0' node to bind the
> > > > 'clocks' node and in turn its sub-nodes.
> > > > The 'scm@21' node is therefore the node closest to the 'clocks' node
> > > > whose driver can bind all the 'clocks' sub-nodes. In this way, the
> > > > address translation functions are able to walk along the device tree
> > > > towards the upper nodes until the address composition is completed.
> > > >
> > > > scm: scm@21 {
> > > > compatible = "ti,am3-scm", "simple-bus";
> > > > ...
> > > >
> > > > scm_conf: scm_conf@0 {
> > > > compatible = "syscon", "simple-bus";
> > > > #address-cells = <1>;
> > > > #size-cells = <1>;
> > > > ranges = <0 0 0x800>;
> > > >
> > > > scm_clocks: clocks {
> > > > #address-cells = <1>;
> > > > #size-cells = <0>;
> > > > };
> > > > };
> > > > };
> > > >
> > > > For DT binding details see Linux doc:
> > > > - Documentation/devicetree/bindings/arm/omap/ctrl.txt
> > > >
> > > > Signed-off-by: Dario Binacchi 
> > > >
> > > > ---
> > > >
> > > > (no changes since v4)
> > > >
> > > > Changes in v4:
> > > > - Include device_compat.h header for dev_xxx macros.
> > > >
> > > > Changes in v3:
> > > > - Remove doc/device-tree-bindings/arm/omap,ctrl.txt.
> > > > - Remove doc/device-tree-bindings/pinctrl/pinctrl-single.txt.
> > > > - Add to commit message the references to linux kernel dt binding
> > > >   documentation.
> > > >
> > > > Changes in v2:
> > > > - Remove the 'ti_am3_scm_clocks' driver. Handle 'scm_clocks' node in
> > > >   the 'ti_am3_scm' driver.
> > > > - Update the commit message.
> > > >
> > > >  drivers/misc/Kconfig  |  7 
> > > >  drivers/misc/Makefile |  1 +
> > > >  drivers/misc/ti-am3-scm.c | 82 +++
> > > >  3 files changed, 90 insertions(+)
> > > >  create mode 100644 drivers/misc/ti-am3-scm.c
> > > >
> > > > diff --git a/drivers/misc/Kconfig b/drivers/misc/Kconfig
> > > > index b67e906a76..9e8b676637 100644
> > > > --- a/drivers/misc/Kconfig
> > > > +++ b/drivers/misc/Kconfig
> > > > @@ -500,4 +500,11 @@ config ESM_PMIC
> > > >   Support ESM (Error Signal Monitor) on PMIC devices. ESM is 
> > > > used
> > > >   typically to reboot the board in error condition.
> > > >
> > > > +config TI_AM3_SCM
> > > > +   bool "AM33XX specific control module support (SCM)"
> > > > +   depends on ARCH_OMAP2PLUS
> > > > +   help
> > > > +The control module includes status and control logic not 
> > > > addressed
> > > > +within the peripherals or the rest of the device 
> > > > infrastructure.
> > > > +
> > > >  endmenu
> > > > diff --git a/drivers/misc/Makefile b/drivers/misc/Makefile
> > > > index 947bd3a647..056fb3b522 100644
> > > > --- a/drivers/misc/Makefile
> > > > +++ b/drivers/misc/Makefile
> > > > @@ -75,3 +75,4 @@ obj-$(CONFIG_MICROCHIP_FLEXCOM) += microchip_flexcom.o
> > > >  obj-$(CONFIG_K3_AVS0) += k3_avs.o
> > > >  obj-$(CONFIG_ESM_K3) += k3_esm.o
> > > >  obj-$(CONFIG_ESM_PMIC) += esm_pmic.o
> > > > +obj-$(CONFIG_TI_AM3_SCM) += ti-am3-scm.o
> > > > diff --git a/drivers/misc/ti-am3-scm.c b/drivers/misc/ti-am3-scm.c
> > > > new file mode 100644
> > > > index 00..ed886e6916
> > > > --- /dev/null
> > > > +++ b/drivers/misc/ti-am3-scm.c
> > > > @@ -0,0 +1,82 @@
> > > > +// SPDX-License-Identifier: GPL-2.0+
> > > > +/*
> > > > + * AM335x specific control module (scm)
> > > > + *
> > > > + * Copyright (C) 2020 Dario Binacchi 
> > > > + */
> > > > +
> > > > +#include 
> > > > +#include 
> > > > +#include 
> > > > +#include 
> > > > +#include 
> > > > +
> > > > +static int ti_am3_scm_bind(struct udevice *dev)
> > > > +{
> > > > +   ofnode clocks_node, conf_node, node;
> > > > +   struct udevice *conf_dev;
> > > > +   int err;
> > > > +
> > > > +   if (!strcmp("clocks", ofnode_get_name(dev_ofnode(dev {
> > > > +   ofnode_for_each_subnode(node, dev_ofnode(dev)) {
> > >
> > > Is there not a compatible string for these subnodes?
> > >
> > > > +   dev_dbg(dev, "%s: node=%s\n", __func__,
> > > > +   ofnode_get_name(node));
> > > > +   err = lists_bind_fdt(

Re: [PATCH v4 07/27] rockchip: Enable building a SPI ROM image on bob

2020-11-08 Thread Emmanuel Vadot


 Hi Simon,

On Tue, 3 Nov 2020 08:11:59 -0700
Simon Glass  wrote:

> Hi Hugh,
> 
> On Wed, 14 Oct 2020 at 12:37, Hugh Cole-Baker  wrote:
> >
> > Hello,
> > > On 11 Oct 2020, at 16:39, Emmanuel Vadot  wrote:
> > >
> > >
> > > Hi Simon,
> > >
> > > On Sun, 19 Jul 2020 13:55:58 -0600
> > > Simon Glass  wrote:
> > >
> > >> Add a simple binman config and enable CONFIG_HAS_ROM so that U-Boot
> > >> produces a ROM for bob.
> > >>
> > >> Signed-off-by: Simon Glass 
> > >> ---
> > >>
> > >> Changes in v4:
> > >> - Use CONFIG_ROCKCHIP_SPI_IMAGE to select the image
> > >>
> > >> arch/arm/dts/rk3399-gru-u-boot.dtsi   |  4 
> > >> arch/arm/dts/rk3399-gru.dtsi  |  2 +-
> > >> arch/arm/dts/rk3399-u-boot.dtsi   | 27 +++
> > >> arch/arm/mach-rockchip/rk3399/Kconfig |  2 ++
> > >> 4 files changed, 34 insertions(+), 1 deletion(-)
> > >>
> > >> diff --git a/arch/arm/dts/rk3399-gru-u-boot.dtsi 
> > >> b/arch/arm/dts/rk3399-gru-u-boot.dtsi
> > >> index 7bddc3acdb..390ac2bb5a 100644
> > >> --- a/arch/arm/dts/rk3399-gru-u-boot.dtsi
> > >> +++ b/arch/arm/dts/rk3399-gru-u-boot.dtsi
> > >> @@ -4,3 +4,7 @@
> > >>  */
> > >>
> > >> #include "rk3399-u-boot.dtsi"
> > >> +
> > >> +&spi_flash {
> > >> +u-boot,dm-pre-reloc;
> > >> +};
> > >> diff --git a/arch/arm/dts/rk3399-gru.dtsi b/arch/arm/dts/rk3399-gru.dtsi
> > >> index 7ac88392f2..f9c5bb607b 100644
> > >> --- a/arch/arm/dts/rk3399-gru.dtsi
> > >> +++ b/arch/arm/dts/rk3399-gru.dtsi
> > >> @@ -537,7 +537,7 @@ ap_i2c_audio: &i2c8 {
> > >>  pinctrl-names = "default", "sleep";
> > >>  pinctrl-1 = <&spi1_sleep>;
> > >>
> > >> -spiflash@0 {
> > >> +spi_flash: spiflash@0 {
> > >>  compatible = "jedec,spi-nor";
> > >>  reg = <0>;
> > >>
> > >> diff --git a/arch/arm/dts/rk3399-u-boot.dtsi 
> > >> b/arch/arm/dts/rk3399-u-boot.dtsi
> > >> index 8237782408..ecd230c720 100644
> > >> --- a/arch/arm/dts/rk3399-u-boot.dtsi
> > >> +++ b/arch/arm/dts/rk3399-u-boot.dtsi
> > >> @@ -4,11 +4,14 @@
> > >>  */
> > >> #define USB_CLASS_HUB9
> > >>
> > >> +#include "rockchip-u-boot.dtsi"
> > >> +
> > >> / {
> > >>  aliases {
> > >>  mmc0 = &sdhci;
> > >>  mmc1 = &sdmmc;
> > >>  pci0 = &pcie0;
> > >> +spi1 = &spi1;
> > >
> > > I don't really understand why but this added alias break spi flash
> > > detection on rockpro64.
> > > Removing it make it work again.
> >
> > I've noticed the same problem - rockpro64 already had an alias
> >
> > spi0 = &spi1;
> >
> > so after this change there are spi0 and spi1 aliases pointing to &spi1.
> > In U-Boot proper, that seems to cause the SPI flash to appear on bus 1
> > rather than the former bus 0, e.g. sf probe 1:0 works but sf probe 0:0
> > doesn't.
> >
> > So I tried removing the spi0 alias and setting CONFIG_SF_DEFAULT_BUS=1
> > which fixed the flash detection in U-Boot proper, but now the SPL can't
> > load U-Boot from SPI flash - it fails with an "Invalid bus 1 (err=-19)"
> > It seems like SPL doesn't pay attention to the spi1 alias in the same
> > way that U-boot proper does, I haven't yet figured out why.
> >
> 
> Could this be CONFIG_SPL_DM_SEQ_ALIAS ?
> 
> Regards,
> Simon

 I don't know if you suggested to set CONFIG_SPL_DM_SEQ_ALIAS=y in
configs/rockpro64-rk3399_defconfig but this doesn't help.

 Cheers,

-- 
Emmanuel Vadot  


[PATCH 0/5] sunxi: enable automatic eMMC boot partition support

2020-11-08 Thread Andre Przywara
The eMMC standard describes the concept of boot partitions, consisting
of two storage areas separate from the main user data partition.
The Allwinner BootROM supports loading SPL/Boot0 from such a boot
partition, if that is configured in the eMMC device [1].

To load U-Boot proper along with the SPL from there, currently this
requires to enable CONFIG_SUPPORT_EMMC_BOOT, and this means that this
build won't boot from the normal eMMC user partition anymore.
Also the raw MMC sector offset needs to be adjusted manually, preventing
a boot from an SD card.

This series introduces automatic detection of eMMC boot partition boot.
Patch 3/5 automates the raw MMC sector offset decision, allowing such
a build to also boot from an SD card.
Unfortunately the BootROM does not mark an eMMC boot partition boot
differently from the normal eMMC user data partition boot, so patch 4/5
introduces a function that repeats the BootROM algorithm, so that the SPL
comes to the same conclusion as the BootROM. This allows to build one
single image that boots from everywhere: eMMC user data, eMMC boot,
SD card, SPI flash.
Patch 1/5 contains a bugfix that's needed in a later patch, patch 2/5
extends the generic spl_mmc_boot_mode() interface to make 4/5 feasible.

Without enabling CONFIG_SUPPORT_EMMC_BOOT, the AArch64 SPL grows by
92 bytes, ARMv7 grows by 36 bytes. With enabling the feature, the size
goes up by 444 bytes (AArch64) and 260 bytes (ARMv7).
Even for AArch64 this is still 4.5 KB below the SPL limit, so patch 5/5
enables this new mechanism for some boards I could test this on.

Please have a look and test this if you have a board with eMMC.
I put installation instructions into the linux-sunxi Wiki:
http://linux-sunxi.org/Bootable_eMMC

Cheers,
Andre

[1] http://linux-sunxi.org/Bootable_eMMC#The_BROM_implementation_details

Andre Przywara (5):
  sunxi: Fix is_boot0_magic macro
  spl: mmc: extend spl_mmc_boot_mode() to take mmc argument
  sunxi: Simplify eMMC boot partition booting
  sunxi: eMMC: Add automatic boot detection
  sunxi: defconfig: enable eMMC boot partition support

 arch/arm/include/asm/arch-sunxi/spl.h  |  2 +-
 arch/arm/mach-imx/spl.c|  2 +-
 arch/arm/mach-k3/am6_init.c|  2 +-
 arch/arm/mach-k3/j721e_init.c  |  2 +-
 arch/arm/mach-omap2/boot-common.c  |  2 +-
 arch/arm/mach-rockchip/spl.c   |  2 +-
 arch/arm/mach-socfpga/spl_a10.c|  2 +-
 arch/arm/mach-socfpga/spl_agilex.c |  2 +-
 arch/arm/mach-socfpga/spl_gen5.c   |  2 +-
 arch/arm/mach-socfpga/spl_s10.c|  2 +-
 arch/arm/mach-stm32mp/spl.c|  2 +-
 arch/arm/mach-sunxi/board.c| 94 +-
 arch/arm/mach-uniphier/mmc-boot-mode.c |  5 +-
 common/spl/spl_mmc.c   |  4 +-
 configs/bananapi_m64_defconfig |  1 +
 configs/emlid_neutis_n5_devboard_defconfig |  1 +
 configs/pine64-lts_defconfig   |  1 +
 configs/pine_h64_defconfig |  1 +
 include/spl.h  |  3 +-
 19 files changed, 113 insertions(+), 19 deletions(-)

-- 
2.17.5



[PATCH 3/5] sunxi: Simplify eMMC boot partition booting

2020-11-08 Thread Andre Przywara
The Allwinner BROM also supports loading the SPL from the eMMC boot
partition, for this we have to set the CONFIG_SUPPORT_EMMC_BOOT Kconfig
symbol. But on top of that a user has to manually adjust the raw sector
to load U-Boot proper from: CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_SECTOR.

To simplify this, we adjust the sector offset dynamically, whenever we
find CONFIG_SUPPORT_EMMC_BOOT enabled and are booting from the eMMC.

Unfortunately the BROM sets the same boot source code as for the boot
from the normal eMMC user data partition, so we can't tell those two
cases apart easily (yet).

Signed-off-by: Andre Przywara 
---
 arch/arm/mach-sunxi/board.c | 10 +-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/arch/arm/mach-sunxi/board.c b/arch/arm/mach-sunxi/board.c
index f40fccd8f8b..586af24535d 100644
--- a/arch/arm/mach-sunxi/board.c
+++ b/arch/arm/mach-sunxi/board.c
@@ -279,21 +279,29 @@ uint32_t sunxi_get_boot_device(void)
 #ifdef CONFIG_SPL_BUILD
 /*
  * The eGON SPL image can be located at 8KB or at 128KB into an SD card or
- * an eMMC device. The boot source has bit 4 set in the latter case.
+ * an eMMC user partition. The boot source has bit 4 set in the latter case.
  * By adding 120KB to the normal offset when booting from a "high" location
  * we can support both cases.
+ * In an eMMC boot partition the SPL is located at offset 0, so we subtract
+ * the usual 8K offset.
  */
 unsigned long spl_mmc_get_uboot_raw_sector(struct mmc *mmc)
 {
unsigned long sector = CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_SECTOR;
 
switch (sunxi_get_boot_source()) {
+   case SUNXI_BOOTED_FROM_MMC2:
+   if (IS_ENABLED(CONFIG_SUPPORT_EMMC_BOOT))
+   sector -= 8 * 2;
+   break;
case SUNXI_BOOTED_FROM_MMC0_HIGH:
case SUNXI_BOOTED_FROM_MMC2_HIGH:
sector += (128 - 8) * 2;
break;
}
 
+   debug("loading U-Boot proper from sector 0x%lx\n", sector);
+
return sector;
 }
 
-- 
2.17.5



[PATCH 2/5] spl: mmc: extend spl_mmc_boot_mode() to take mmc argument

2020-11-08 Thread Andre Przywara
Platforms can overwrite the weak definition of spl_mmc_boot_mode() to
determine where to load U-Boot proper from.
For most of them this is a trivial decision based on Kconfig variables,
but it might be desirable the probe the actual device to answer this
question.

Pass the pointer to the mmc struct to that function, so implementations
can make use of them.

Compile-tested for all users changed.

Cc: Stefano Babic 
Cc: Fabio Estevam 
Cc: NXP i.MX U-Boot Team 
Cc: Lokesh Vutla 
Cc: Philipp Tomsich 
Cc: Kever Yang 
Cc: Marek Vasut 
Cc: Simon Goldschmidt 
Cc: Ley Foon Tan 
Cc: Patrick Delaunay 
Cc: Patrice Chotard 
Signed-off-by: Andre Przywara 
---
 arch/arm/mach-imx/spl.c| 2 +-
 arch/arm/mach-k3/am6_init.c| 2 +-
 arch/arm/mach-k3/j721e_init.c  | 2 +-
 arch/arm/mach-omap2/boot-common.c  | 2 +-
 arch/arm/mach-rockchip/spl.c   | 2 +-
 arch/arm/mach-socfpga/spl_a10.c| 2 +-
 arch/arm/mach-socfpga/spl_agilex.c | 2 +-
 arch/arm/mach-socfpga/spl_gen5.c   | 2 +-
 arch/arm/mach-socfpga/spl_s10.c| 2 +-
 arch/arm/mach-stm32mp/spl.c| 2 +-
 arch/arm/mach-uniphier/mmc-boot-mode.c | 5 +
 common/spl/spl_mmc.c   | 4 ++--
 include/spl.h  | 3 ++-
 13 files changed, 15 insertions(+), 17 deletions(-)

diff --git a/arch/arm/mach-imx/spl.c b/arch/arm/mach-imx/spl.c
index aa2686bb921..2cfedccfaf2 100644
--- a/arch/arm/mach-imx/spl.c
+++ b/arch/arm/mach-imx/spl.c
@@ -197,7 +197,7 @@ int g_dnl_get_board_bcd_device_number(int gcnum)
 
 #if defined(CONFIG_SPL_MMC_SUPPORT)
 /* called from spl_mmc to see type of boot mode for storage (RAW or FAT) */
-u32 spl_mmc_boot_mode(const u32 boot_device)
+u32 spl_mmc_boot_mode(struct mmc *mmc, const u32 boot_device)
 {
 #if defined(CONFIG_MX7) || defined(CONFIG_IMX8M) || defined(CONFIG_IMX8)
switch (get_boot_device()) {
diff --git a/arch/arm/mach-k3/am6_init.c b/arch/arm/mach-k3/am6_init.c
index 603834e5078..55328757a64 100644
--- a/arch/arm/mach-k3/am6_init.c
+++ b/arch/arm/mach-k3/am6_init.c
@@ -252,7 +252,7 @@ void board_init_f(ulong dummy)
spl_enable_dcache();
 }
 
-u32 spl_mmc_boot_mode(const u32 boot_device)
+u32 spl_mmc_boot_mode(struct mmc *mmc, const u32 boot_device)
 {
 #if defined(CONFIG_SUPPORT_EMMC_BOOT)
u32 devstat = readl(CTRLMMR_MAIN_DEVSTAT);
diff --git a/arch/arm/mach-k3/j721e_init.c b/arch/arm/mach-k3/j721e_init.c
index a36e4ed603b..97818a0be6d 100644
--- a/arch/arm/mach-k3/j721e_init.c
+++ b/arch/arm/mach-k3/j721e_init.c
@@ -220,7 +220,7 @@ void board_init_f(ulong dummy)
spl_enable_dcache();
 }
 
-u32 spl_mmc_boot_mode(const u32 boot_device)
+u32 spl_mmc_boot_mode(struct mmc *mmc, const u32 boot_device)
 {
switch (boot_device) {
case BOOT_DEVICE_MMC1:
diff --git a/arch/arm/mach-omap2/boot-common.c 
b/arch/arm/mach-omap2/boot-common.c
index cb9d7fdb156..b65827668de 100644
--- a/arch/arm/mach-omap2/boot-common.c
+++ b/arch/arm/mach-omap2/boot-common.c
@@ -188,7 +188,7 @@ u32 spl_boot_device(void)
return gd->arch.omap_boot_device;
 }
 
-u32 spl_mmc_boot_mode(const u32 boot_device)
+u32 spl_mmc_boot_mode(struct mmc *mmc, const u32 boot_device)
 {
return gd->arch.omap_boot_mode;
 }
diff --git a/arch/arm/mach-rockchip/spl.c b/arch/arm/mach-rockchip/spl.c
index f148d48b6a3..24c5f385e19 100644
--- a/arch/arm/mach-rockchip/spl.c
+++ b/arch/arm/mach-rockchip/spl.c
@@ -64,7 +64,7 @@ u32 spl_boot_device(void)
return boot_device;
 }
 
-u32 spl_mmc_boot_mode(const u32 boot_device)
+u32 spl_mmc_boot_mode(struct mmc *mmc, const u32 boot_device)
 {
return MMCSD_MODE_RAW;
 }
diff --git a/arch/arm/mach-socfpga/spl_a10.c b/arch/arm/mach-socfpga/spl_a10.c
index 45aea4ab6cc..618ca898dd7 100644
--- a/arch/arm/mach-socfpga/spl_a10.c
+++ b/arch/arm/mach-socfpga/spl_a10.c
@@ -93,7 +93,7 @@ u32 spl_boot_device(void)
 }
 
 #ifdef CONFIG_SPL_MMC_SUPPORT
-u32 spl_mmc_boot_mode(const u32 boot_device)
+u32 spl_mmc_boot_mode(struct mmc *mmc, const u32 boot_device)
 {
 #if defined(CONFIG_SPL_FS_FAT) || defined(CONFIG_SPL_FS_EXT4)
return MMCSD_MODE_FS;
diff --git a/arch/arm/mach-socfpga/spl_agilex.c 
b/arch/arm/mach-socfpga/spl_agilex.c
index 78b5d7c8d98..fe4253b8e65 100644
--- a/arch/arm/mach-socfpga/spl_agilex.c
+++ b/arch/arm/mach-socfpga/spl_agilex.c
@@ -30,7 +30,7 @@ u32 spl_boot_device(void)
 }
 
 #ifdef CONFIG_SPL_MMC_SUPPORT
-u32 spl_mmc_boot_mode(const u32 boot_device)
+u32 spl_mmc_boot_mode(struct mmc *mmc, const u32 boot_device)
 {
 #if defined(CONFIG_SPL_FS_FAT) || defined(CONFIG_SPL_FS_EXT4)
return MMCSD_MODE_FS;
diff --git a/arch/arm/mach-socfpga/spl_gen5.c b/arch/arm/mach-socfpga/spl_gen5.c
index 5a7c5ef76d5..e526470aa15 100644
--- a/arch/arm/mach-socfpga/spl_gen5.c
+++ b/arch/arm/mach-socfpga/spl_gen5.c
@@ -52,7 +52,7 @@ u32 spl_boot_device(void)
 }
 
 #ifdef CONFIG_SPL_MMC_SUPPORT
-u32 spl_mmc_boot_mode(const u32 boot_device)
+u32 spl_mmc_boot_mode(struct mmc *mmc, const u32 

[PATCH 1/5] sunxi: Fix is_boot0_magic macro

2020-11-08 Thread Andre Przywara
The is_boot0_magic macro is missing parentheses around the macro
argument, breaking any usage with a more complex argument.

Signed-off-by: Andre Przywara 
---
 arch/arm/include/asm/arch-sunxi/spl.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/arm/include/asm/arch-sunxi/spl.h 
b/arch/arm/include/asm/arch-sunxi/spl.h
index 8c916e8c752..6b3566f55e5 100644
--- a/arch/arm/include/asm/arch-sunxi/spl.h
+++ b/arch/arm/include/asm/arch-sunxi/spl.h
@@ -83,7 +83,7 @@ struct boot_file_head {
 /* Compile time check to assure proper alignment of structure */
 typedef char boot_file_head_not_multiple_of_32[1 - 2*(sizeof(struct 
boot_file_head) % 32)];
 
-#define is_boot0_magic(addr)   (memcmp((void *)addr, BOOT0_MAGIC, 8) == 0)
+#define is_boot0_magic(addr)   (memcmp((void *)(addr), BOOT0_MAGIC, 8) == 0)
 
 uint32_t sunxi_get_boot_device(void);
 
-- 
2.17.5



[PATCH 5/5] sunxi: defconfig: enable eMMC boot partition support

2020-11-08 Thread Andre Przywara
Now that the SPL can detect whether it was loaded from an eMMC boot
partition or the normal user data partition, let's enable this feature
on some boards that feature eMMC storage.

That covers the boards where I could test this on.

Signed-off-by: Andre Przywara 
---
 configs/bananapi_m64_defconfig | 1 +
 configs/emlid_neutis_n5_devboard_defconfig | 1 +
 configs/pine64-lts_defconfig   | 1 +
 configs/pine_h64_defconfig | 1 +
 4 files changed, 4 insertions(+)

diff --git a/configs/bananapi_m64_defconfig b/configs/bananapi_m64_defconfig
index 802f9820d07..f28dd7771b7 100644
--- a/configs/bananapi_m64_defconfig
+++ b/configs/bananapi_m64_defconfig
@@ -5,6 +5,7 @@ CONFIG_MACH_SUN50I=y
 CONFIG_RESERVE_ALLWINNER_BOOT0_HEADER=y
 CONFIG_MMC0_CD_PIN="PH13"
 CONFIG_MMC_SUNXI_SLOT_EXTRA=2
+CONFIG_SUPPORT_EMMC_BOOT=y
 CONFIG_DEFAULT_DEVICE_TREE="sun50i-a64-bananapi-m64"
 # CONFIG_SYS_MALLOC_CLEAR_ON_INIT is not set
 CONFIG_SUN8I_EMAC=y
diff --git a/configs/emlid_neutis_n5_devboard_defconfig 
b/configs/emlid_neutis_n5_devboard_defconfig
index 0e908c327b1..59062bf8bcc 100644
--- a/configs/emlid_neutis_n5_devboard_defconfig
+++ b/configs/emlid_neutis_n5_devboard_defconfig
@@ -6,5 +6,6 @@ CONFIG_DRAM_CLK=408
 CONFIG_DRAM_ZQ=3881977
 # CONFIG_DRAM_ODT_EN is not set
 CONFIG_MMC_SUNXI_SLOT_EXTRA=2
+CONFIG_SUPPORT_EMMC_BOOT=y
 CONFIG_DEFAULT_DEVICE_TREE="sun50i-h5-emlid-neutis-n5-devboard"
 # CONFIG_SYS_MALLOC_CLEAR_ON_INIT is not set
diff --git a/configs/pine64-lts_defconfig b/configs/pine64-lts_defconfig
index 048b31d73ce..24d479ce5d3 100644
--- a/configs/pine64-lts_defconfig
+++ b/configs/pine64-lts_defconfig
@@ -7,6 +7,7 @@ CONFIG_DRAM_CLK=552
 CONFIG_DRAM_ZQ=3881949
 CONFIG_MMC0_CD_PIN=""
 CONFIG_MMC_SUNXI_SLOT_EXTRA=2
+CONFIG_SUPPORT_EMMC_BOOT=y
 CONFIG_SPL_SPI_SUNXI=y
 CONFIG_DEFAULT_DEVICE_TREE="sun50i-a64-pine64-lts"
 # CONFIG_SYS_MALLOC_CLEAR_ON_INIT is not set
diff --git a/configs/pine_h64_defconfig b/configs/pine_h64_defconfig
index 2fa66f38343..2cfa3df2ff4 100644
--- a/configs/pine_h64_defconfig
+++ b/configs/pine_h64_defconfig
@@ -6,6 +6,7 @@ CONFIG_SUNXI_DRAM_H6_LPDDR3=y
 CONFIG_MACPWR="PC16"
 CONFIG_MMC0_CD_PIN="PF6"
 CONFIG_MMC_SUNXI_SLOT_EXTRA=2
+CONFIG_SUPPORT_EMMC_BOOT=y
 CONFIG_USB3_VBUS_PIN="PL5"
 CONFIG_SPL_SPI_SUNXI=y
 # CONFIG_PSCI_RESET is not set
-- 
2.17.5



[PATCH 4/5] sunxi: eMMC: Add automatic boot detection

2020-11-08 Thread Andre Przywara
When the Allwinner BROM loads the SPL from an eMMC boot partition, it
sets the boot source byte to the same value as when booting from the
user data partition. This prevents us from easily determining the boot
source to load U-Boot proper from the proper partition.

To learn about the boot source anyway, we repeat the algorithm the BROM
used to select the boot partition in the first place:
- Test EXT_CSD[179] to check if an eMMC boot partition is enabled.
- Test EXT_CSD[177] to check for valid MMC interface settings.
- Check if BOOT_ACK is enabled.
- Check the beginning of the first sector for a valid eGON signature.
- Load the whole SPL (limited to be at most 32KB).
- Recalculate the checksum to verify the SPL is valid.

If one of those steps fails, we bail out and continue loading from the
user data partition. Otherwise we load from the selected boot partition,
automatically adjusting the sector offset accordingly.

Since the boot source is needed twice in the boot process, we cache the
result of this test to avoid doing this costly test multiple times.

This allows the very same image file to be put onto an SD card, into the
eMMC user data partition or into the eMMC boot partition.
CONFIG_SUPPORT_EMMC_BOOT needs still to be enabled to activate this
feature, but it does not force booting from the eMMC boot partition
anymore.

Signed-off-by: Andre Przywara 
---
 arch/arm/mach-sunxi/board.c | 86 -
 1 file changed, 85 insertions(+), 1 deletion(-)

diff --git a/arch/arm/mach-sunxi/board.c b/arch/arm/mach-sunxi/board.c
index 586af24535d..a141f24acdd 100644
--- a/arch/arm/mach-sunxi/board.c
+++ b/arch/arm/mach-sunxi/board.c
@@ -291,7 +291,7 @@ unsigned long spl_mmc_get_uboot_raw_sector(struct mmc *mmc)
 
switch (sunxi_get_boot_source()) {
case SUNXI_BOOTED_FROM_MMC2:
-   if (IS_ENABLED(CONFIG_SUPPORT_EMMC_BOOT))
+   if (spl_mmc_boot_mode(mmc, 1) == MMCSD_MODE_EMMCBOOT)
sector -= 8 * 2;
break;
case SUNXI_BOOTED_FROM_MMC0_HIGH:
@@ -310,6 +310,90 @@ u32 spl_boot_device(void)
return sunxi_get_boot_device();
 }
 
+/*
+ * When booting from an eMMC boot partition, the SPL puts the same boot
+ * source code into SRAM A1 as when loading the SPL from the normal
+ * eMMC user data partition: 0x2. So to know where we have been loaded
+ * from, we repeat the BROM algorithm here: checking for a valid eGON boot
+ * image at offset 0 of a (potentially) selected boot partition.
+ * If any of the conditions is not met, it must have been the eMMC user
+ * data partition.
+ */
+static bool sunxi_valid_emmc_boot(struct mmc *mmc)
+{
+   struct blk_desc *bd = mmc_get_blk_desc(mmc);
+   uint32_t *buffer = (void *)(uintptr_t)CONFIG_SYS_TEXT_BASE;
+   int bootpart = EXT_CSD_EXTRACT_BOOT_PART(mmc->part_config);
+   uint32_t spl_size, emmc_checksum, chksum = 0;
+   ulong count;
+
+   /* The BROM requires BOOT_ACK to be enabled. */
+   if (!EXT_CSD_EXTRACT_BOOT_ACK(mmc->part_config))
+   return false;
+
+   /*
+* The BOOT_BUS_CONDITION register must be 4-bit SDR, with (0x09)
+* or without (0x01) high speed timings.
+*/
+   if ((mmc->ext_csd[EXT_CSD_BOOT_BUS_WIDTH] & 0x1b) != 0x01 &&
+   (mmc->ext_csd[EXT_CSD_BOOT_BUS_WIDTH] & 0x1b) != 0x09)
+   return false;
+
+   /* Partition 0 is the user data partition, bootpart must be 1 or 2. */
+   if (bootpart != 1 && bootpart != 2)
+   return false;
+
+   mmc_switch_part(mmc, bootpart);
+
+   /* Read the first block to do some sanity checks on the eGON header. */
+   count = blk_dread(bd, 0, 1, buffer);
+   if (count != 1 || !is_boot0_magic(buffer + 1))
+   return false;
+
+   /* The BROM will only read up to 32KB into SRAM A1. */
+   spl_size = buffer[4];
+   if ((spl_size & 3) || spl_size > 32768)
+   return false;
+
+   /* Read the rest of the SPL now we know it's halfway sane. */
+   count = blk_dread(bd, 1, DIV_ROUND_UP(spl_size, bd->blksz) - 1,
+ buffer + bd->blksz / 4);
+
+   /* Save the checksum and replace it with the "stamp value". */
+   emmc_checksum = buffer[3];
+   buffer[3] = 0x5f0a6c39;
+
+   /* The checksum is a simple ignore-carry addition of all words. */
+   for (count = 0; count < spl_size / 4; count++)
+   chksum += buffer[count];
+
+   debug("eMMC boot part SPL checksum: stored: 0x%08x, computed: 0x%08x\n",
+  emmc_checksum, chksum);
+
+   return emmc_checksum == chksum;
+}
+
+u32 spl_mmc_boot_mode(struct mmc *mmc, const u32 boot_device)
+{
+   static u32 result = ~0;
+
+   if (result != ~0)
+   return result;
+
+   result = MMCSD_MODE_RAW;
+   if (!IS_SD(mmc) && IS_ENABLED(CONFIG_SUPPORT_EMMC_BOOT)) {
+   if (sunxi_valid_emmc_boot(mmc))
+   r

Re: [PATCH] env: env_sf: don't set .init op if not needed

2020-11-08 Thread Wolfgang Denk
Dear Rasmus,

In message  you wrote:
>
> > The CONFIG_ENV_IS_FOO means: if you use "env save", then U-Boot will
> > write the config to external storage using the FOO storage device.
>
> Wolfgang, you're wrong. What you're saying was once true, when the
> location was a "choice" in Kconfig, but it hasn't been that since
> fb69464eae. Nowadays one can select multiple possible backends, and only
> one of them will be used when doing "env save".

I know that.  But that slection is made from the selected drivers
enabled by the CONFIG_ENV_IS_* settings.

> Later (208bd2b8), _NOWHERE was made non-mutually-exclusive with the real
> storage targets.

And this is a buf that should be fixed, as it makes no sense at all.

> > If you define CONFIG_ENV_IS_NOWHERE, I would for example expect that
> > all "env save" related code is omitted as we will never need it.
>
> I haven't checked, but that functionality does seem to exist - not
> depending on whether CONFIG_ENV_IS_NOWHERE is not selected, but whether
> any of the CONFIG_ENV_IS_ is. See the ENV_IS_IN_DEVICE logic
> in cmd/nvedit.c. So if you select CONFIG_ENV_IS_NOWHERE and not any of
> the others, I think the build works as you'd expect.

This is intransparent and error prone.  This check must not be
implemented somewhere in the code, but at Kconfig level.

Best regards,

Wolfgang Denk

-- 
DENX Software Engineering GmbH,  Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: w...@denx.de
  Bugs are by far the largest and  most successful class of
  entity, with nearly a million known species. In this res-
  pect they outnumber all the other  known  creatures about
  four to one.  -- Professor Snope's Encyclopedia of Animal


Re: [PATCH] env: env_sf: don't set .init op if not needed

2020-11-08 Thread Wolfgang Denk
Dear Tom,

In message <20201106204557.GG5340@bill-the-cat> you wrote:
> 
> > Later (208bd2b8), _NOWHERE was made non-mutually-exclusive with the real
> > storage targets.
>
> Yes.  It's intentional that "NOWHERE" means that if this is our run-time
> location for the environment, then you cannot save the environment.  But
> since we finally implemented the ability to have more than one option
> enabled and pick the correct one at run time, we build both "mmc" and
> "nowhere".

But this breaks logic.  If you wanna have a nulldev, than implement
a /dev/null.

CONFIG_ENV_IS_NOWHERE should be the means to be used when no
environment storage drivers are needed / selected, not even
/dev/null.

Best regards,

Wolfgang Denk

-- 
DENX Software Engineering GmbH,  Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: w...@denx.de
My challenge to the goto-less programmer  is  to  recode  tcp_input()
without any gotos ... without any loss of efficiency (there has to be
a catch). - W. R. Stevens


Re: [PATCH v2 0/3] allow positional arguments with "run"

2020-11-08 Thread Wolfgang Denk
Dear Tom,

In message <20201106205245.GH5340@bill-the-cat> you wrote:
> 
> Sorry for the lack of feedback.  I guess, I just don't know.  There's at
> least two series now (this and Simon's setexp) where part of the
> feedback has been "our hush is ancient, and we should replace and keep
> it in sync, and add features _upstream_".  That position isn't wrong.
> But it's not easy to do, either.  I know you already said you didn't
> have time and wouldn't step up to do that.

This argument is not new, and I can fully understand this position,
too.  I'mm all to often myself in the position where the right Thing
(TM) requires more efforts and/or time than what is available in the
given project.

And from the maintainer's point of view, this has always been the
argument to sneak in code which is a workaround at best, and which
itself cements the original problem even more and makes it more
difficult to solve it at the roots.

Best regards,

Wolfgang Denk

-- 
DENX Software Engineering GmbH,  Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: w...@denx.de
Q:  Why do mountain climbers rope themselves together?
A:  To prevent the sensible ones from going home.


Re: [PATCH 3/3 v2] efi: Add basic EFI_TCG2_PROTOCOL support

2020-11-08 Thread Ilias Apalodimas
Hi Heinrich, 

[...]
> > diff --git a/include/efi_tcg2.h b/include/efi_tcg2.h
> > new file mode 100644
> > index ..9e7b85db058d
> > --- /dev/null
> > +++ b/include/efi_tcg2.h
> > @@ -0,0 +1,91 @@
> > +/* SPDX-License-Identifier: GPL-2.0+ */
> > +/*
> > + * Copyright (c) 2020, Linaro Limited
> 
> Please, add at least one line describing what this include is about.
> 

Ok 

> > + */
> > +
> > +#if !defined _EFI_TCG2_PROTOCOL_H_
> > +#define _EFI_TCG2_PROTOCOL_H_
> > +
> > +#include 
> > +
> > +#define EFI_TCG2_PROTOCOL_GUID \
> > +   EFI_GUID(0x607f766c, 0x7455, 0x42be, 0x93, \
> > +0x0b, 0xe4, 0xd7, 0x6d, 0xb2, 0x72, 0x0f)
> > +
> > +/* TPMV2 only */
> > +#define TCG2_EVENT_LOG_FORMAT_TCG_2 0x0002
> > +
> > +/* SHA1, SHA256, SHA384, SHA512, TPM_ALG_SM3_256 */
> > +#define MAX_HASH_COUNT 5
> > +/* Algorithm Registry */
> > +#define EFI_TCG2_BOOT_HASH_ALG_SHA10x0001
> > +#define EFI_TCG2_BOOT_HASH_ALG_SHA256  0x0002
> > +#define EFI_TCG2_BOOT_HASH_ALG_SHA384  0x0004
> > +#define EFI_TCG2_BOOT_HASH_ALG_SHA512  0x0008
> > +#define EFI_TCG2_BOOT_HASH_ALG_SM3_256 0x0010
> > +
> > +typedef u32 efi_tcg_event_log_bitmap;
> > +typedef u32 efi_tcg_event_log_format;
> > +typedef u32 efi_tcg_event_algorithm_bitmap;
> > +
> > +struct efi_tcg2_version {
> > +   u8 major;
> > +   u8 minor;
> > +};
> > +
> > +struct efi_tcg2_event_header {
> > +   u32 header_size;
> > +   u16 header_version;
> > +   u32 pcr_index;
> > +   u32 event_type;
> > +} __packed;
> > +
> > +struct efi_tcg2_event {
> > +   u32 size;
> > +   struct efi_tcg2_event_header header;
> > +   u8 event[];
> > +} __packed;
> > +
> > +struct efi_tcg2_boot_service_capability {
> > +   u8 size;
> > +   struct efi_tcg2_version structure_version;
> > +   struct efi_tcg2_version protocol_version;
> > +   efi_tcg_event_algorithm_bitmap hash_algorithm_bitmap;
> > +   efi_tcg_event_log_bitmap supported_event_logs;
> > +   bool tpm_present_flag;
> 
> The UEFI spec defines BOOLEAN as "1-byte value".
> The C99 standard does not require that _Bool has size 1 byte.
> Wouldn't it be wiser to use u8?

Yes, good catch

> 
> Other structures in this patch are packed. Has this structure to be
> packed too? The EFI ProtocolSpecification has this sentence:
> "All structures defined in this specification are packed, except where
> explicitly otherwise defined."
> 

Nop this is expliticly required to be not packed 
https://trustedcomputinggroup.org/wp-content/uploads/EFI-Protocol-Specification-rev13-160330final.pdf
Section 6.4 

[...]
> >
> > +config EFI_TCG2_PROTOCOL
> > +   bool "EFI_TCG2_PROTOCOL support"
> > +   depends on TPM_V2
> > +   default n
> 
> default n is superfluous.
> 

Ok

> > +   help
> > + Provide a EFI_TCG2_PROTOCOL implementation using the TPM hardware
> > + of the platform.
> > +
> >  config EFI_LOAD_FILE2_INITRD
> > bool "EFI_FILE_LOAD2_PROTOCOL for Linux initial ramdisk"
> > default n
> > diff --git a/lib/efi_loader/Makefile b/lib/efi_loader/Makefile
> > index 8892fb01e125..cd4b252a417c 100644
> > --- a/lib/efi_loader/Makefile
> > +++ b/lib/efi_loader/Makefile
> > @@ -53,6 +53,7 @@ obj-$(CONFIG_NET) += efi_net.o
> >  obj-$(CONFIG_GENERATE_ACPI_TABLE) += efi_acpi.o
> >  obj-$(CONFIG_GENERATE_SMBIOS_TABLE) += efi_smbios.o
> >  obj-$(CONFIG_EFI_RNG_PROTOCOL) += efi_rng.o
> > +obj-$(CONFIG_EFI_TCG2_PROTOCOL) += efi_tcg2.o
> >  obj-$(CONFIG_EFI_LOAD_FILE2_INITRD) += efi_load_initrd.o
> >  obj-y += efi_signature.o
> >
> > diff --git a/lib/efi_loader/efi_setup.c b/lib/efi_loader/efi_setup.c
> > index 45226c5c1a53..e206b60bb82c 100644
> > --- a/lib/efi_loader/efi_setup.c
> > +++ b/lib/efi_loader/efi_setup.c
> > @@ -156,6 +156,13 @@ efi_status_t efi_init_obj_list(void)
> > if (ret != EFI_SUCCESS)
> > goto out;
> > }
> > +
> > +   if (IS_ENABLED(CONFIG_EFI_TCG2_PROTOCOL)) {
> > +   ret = efi_tcg2_register();
> > +   if (ret != EFI_SUCCESS)
> > +   goto out;
> > +   }
> > +
> > /* Initialize variable services */
> > ret = efi_init_variables();
> > if (ret != EFI_SUCCESS)
> > diff --git a/lib/efi_loader/efi_tcg2.c b/lib/efi_loader/efi_tcg2.c
> > new file mode 100644
> > index ..b735f3f2a83d
> > --- /dev/null
> > +++ b/lib/efi_loader/efi_tcg2.c
> > @@ -0,0 +1,493 @@
> > +// SPDX-License-Identifier: GPL-2.0+
> > +/*
> > + * Copyright (c) 2020, Linaro Limited
> 
> Please, add at least one line describing what this module is about.
> 

Ok

> > + */
> > +
> > +#define LOG_CATEGORY LOGC_EFI
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +
> > +DECLARE_GLOBAL_DATA_PTR;
> > +
> > +/*
> > + * When requesting TPM2_CAP_TPM_PROPERTIES the value is on a standard 
> > offset.
> > + * Since the current tpm2_get_capability() response buffers starts at
> > + * 'union tpmu_capabilities data' of 'struct tpms_capability_data', 
> > calculate the
> > + * resp

Re: [PATCH 2/5] spl: mmc: extend spl_mmc_boot_mode() to take mmc argument

2020-11-08 Thread Stefano Babic
On 08.11.20 14:14, Andre Przywara wrote:
> Platforms can overwrite the weak definition of spl_mmc_boot_mode() to
> determine where to load U-Boot proper from.
> For most of them this is a trivial decision based on Kconfig variables,
> but it might be desirable the probe the actual device to answer this
> question.
> 
> Pass the pointer to the mmc struct to that function, so implementations
> can make use of them.
> 
> Compile-tested for all users changed.
> 
> Cc: Stefano Babic 
> Cc: Fabio Estevam 
> Cc: NXP i.MX U-Boot Team 
> Cc: Lokesh Vutla 
> Cc: Philipp Tomsich 
> Cc: Kever Yang 
> Cc: Marek Vasut 
> Cc: Simon Goldschmidt 
> Cc: Ley Foon Tan 
> Cc: Patrick Delaunay 
> Cc: Patrice Chotard 
> Signed-off-by: Andre Przywara 
> ---
>  arch/arm/mach-imx/spl.c| 2 +-
>  arch/arm/mach-k3/am6_init.c| 2 +-
>  arch/arm/mach-k3/j721e_init.c  | 2 +-
>  arch/arm/mach-omap2/boot-common.c  | 2 +-
>  arch/arm/mach-rockchip/spl.c   | 2 +-
>  arch/arm/mach-socfpga/spl_a10.c| 2 +-
>  arch/arm/mach-socfpga/spl_agilex.c | 2 +-
>  arch/arm/mach-socfpga/spl_gen5.c   | 2 +-
>  arch/arm/mach-socfpga/spl_s10.c| 2 +-
>  arch/arm/mach-stm32mp/spl.c| 2 +-
>  arch/arm/mach-uniphier/mmc-boot-mode.c | 5 +
>  common/spl/spl_mmc.c   | 4 ++--
>  include/spl.h  | 3 ++-
>  13 files changed, 15 insertions(+), 17 deletions(-)
> 
> diff --git a/arch/arm/mach-imx/spl.c b/arch/arm/mach-imx/spl.c
> index aa2686bb921..2cfedccfaf2 100644
> --- a/arch/arm/mach-imx/spl.c
> +++ b/arch/arm/mach-imx/spl.c
> @@ -197,7 +197,7 @@ int g_dnl_get_board_bcd_device_number(int gcnum)
>  
>  #if defined(CONFIG_SPL_MMC_SUPPORT)
>  /* called from spl_mmc to see type of boot mode for storage (RAW or FAT) */
> -u32 spl_mmc_boot_mode(const u32 boot_device)
> +u32 spl_mmc_boot_mode(struct mmc *mmc, const u32 boot_device)
>  {
>  #if defined(CONFIG_MX7) || defined(CONFIG_IMX8M) || defined(CONFIG_IMX8)
>   switch (get_boot_device()) {
> diff --git a/arch/arm/mach-k3/am6_init.c b/arch/arm/mach-k3/am6_init.c
> index 603834e5078..55328757a64 100644
> --- a/arch/arm/mach-k3/am6_init.c
> +++ b/arch/arm/mach-k3/am6_init.c
> @@ -252,7 +252,7 @@ void board_init_f(ulong dummy)
>   spl_enable_dcache();
>  }
>  
> -u32 spl_mmc_boot_mode(const u32 boot_device)
> +u32 spl_mmc_boot_mode(struct mmc *mmc, const u32 boot_device)
>  {
>  #if defined(CONFIG_SUPPORT_EMMC_BOOT)
>   u32 devstat = readl(CTRLMMR_MAIN_DEVSTAT);
> diff --git a/arch/arm/mach-k3/j721e_init.c b/arch/arm/mach-k3/j721e_init.c
> index a36e4ed603b..97818a0be6d 100644
> --- a/arch/arm/mach-k3/j721e_init.c
> +++ b/arch/arm/mach-k3/j721e_init.c
> @@ -220,7 +220,7 @@ void board_init_f(ulong dummy)
>   spl_enable_dcache();
>  }
>  
> -u32 spl_mmc_boot_mode(const u32 boot_device)
> +u32 spl_mmc_boot_mode(struct mmc *mmc, const u32 boot_device)
>  {
>   switch (boot_device) {
>   case BOOT_DEVICE_MMC1:
> diff --git a/arch/arm/mach-omap2/boot-common.c 
> b/arch/arm/mach-omap2/boot-common.c
> index cb9d7fdb156..b65827668de 100644
> --- a/arch/arm/mach-omap2/boot-common.c
> +++ b/arch/arm/mach-omap2/boot-common.c
> @@ -188,7 +188,7 @@ u32 spl_boot_device(void)
>   return gd->arch.omap_boot_device;
>  }
>  
> -u32 spl_mmc_boot_mode(const u32 boot_device)
> +u32 spl_mmc_boot_mode(struct mmc *mmc, const u32 boot_device)
>  {
>   return gd->arch.omap_boot_mode;
>  }
> diff --git a/arch/arm/mach-rockchip/spl.c b/arch/arm/mach-rockchip/spl.c
> index f148d48b6a3..24c5f385e19 100644
> --- a/arch/arm/mach-rockchip/spl.c
> +++ b/arch/arm/mach-rockchip/spl.c
> @@ -64,7 +64,7 @@ u32 spl_boot_device(void)
>   return boot_device;
>  }
>  
> -u32 spl_mmc_boot_mode(const u32 boot_device)
> +u32 spl_mmc_boot_mode(struct mmc *mmc, const u32 boot_device)
>  {
>   return MMCSD_MODE_RAW;
>  }
> diff --git a/arch/arm/mach-socfpga/spl_a10.c b/arch/arm/mach-socfpga/spl_a10.c
> index 45aea4ab6cc..618ca898dd7 100644
> --- a/arch/arm/mach-socfpga/spl_a10.c
> +++ b/arch/arm/mach-socfpga/spl_a10.c
> @@ -93,7 +93,7 @@ u32 spl_boot_device(void)
>  }
>  
>  #ifdef CONFIG_SPL_MMC_SUPPORT
> -u32 spl_mmc_boot_mode(const u32 boot_device)
> +u32 spl_mmc_boot_mode(struct mmc *mmc, const u32 boot_device)
>  {
>  #if defined(CONFIG_SPL_FS_FAT) || defined(CONFIG_SPL_FS_EXT4)
>   return MMCSD_MODE_FS;
> diff --git a/arch/arm/mach-socfpga/spl_agilex.c 
> b/arch/arm/mach-socfpga/spl_agilex.c
> index 78b5d7c8d98..fe4253b8e65 100644
> --- a/arch/arm/mach-socfpga/spl_agilex.c
> +++ b/arch/arm/mach-socfpga/spl_agilex.c
> @@ -30,7 +30,7 @@ u32 spl_boot_device(void)
>  }
>  
>  #ifdef CONFIG_SPL_MMC_SUPPORT
> -u32 spl_mmc_boot_mode(const u32 boot_device)
> +u32 spl_mmc_boot_mode(struct mmc *mmc, const u32 boot_device)
>  {
>  #if defined(CONFIG_SPL_FS_FAT) || defined(CONFIG_SPL_FS_EXT4)
>   return MMCSD_MODE_FS;
> diff --git a/arch/arm/mach-socfpga/spl_gen5.c 
> b/arch/arm/mach-socfpga/spl_gen5.c
> inde

Re: [PATCH 2/3 v2] tpm: Add some headers from the spec

2020-11-08 Thread Ilias Apalodimas
On Sat, Nov 07, 2020 at 09:33:35PM +0100, Heinrich Schuchardt wrote:
> On 11/5/20 10:58 PM, Ilias Apalodimas wrote:
> > A following patch introduces EFI_TCG2_PROTOCOL.
> > Add the required TPMv2 headers to support that and remove the (now)
> > redundant definitions from tpm2_tis_sandbox
> >
> > Signed-off-by: Ilias Apalodimas 
> > ---
> >  include/tpm-v2.h | 69 
> >  1 file changed, 69 insertions(+)
> >
> > diff --git a/include/tpm-v2.h b/include/tpm-v2.h
> > index f6c045d35480..b62f2c5b0fb8 100644
> > --- a/include/tpm-v2.h
> > +++ b/include/tpm-v2.h
> > @@ -11,6 +11,73 @@
> >
> >  #define TPM2_DIGEST_LEN32
> 
> Miquel, the constant name and its usage seems not to reflect the TCG spec:
> 
> The spec has the following alternative digest length constants:
> 
> #define TPM2_SHA_DIGEST_SIZE   20
> #define TPM2_SHA1_DIGEST_SIZE  20
> #define TPM2_SHA256_DIGEST_SIZE32
> #define TPM2_SHA384_DIGEST_SIZE48
> #define TPM2_SHA512_DIGEST_SIZE64
> #define TPM2_SM3_256_DIGEST_SIZE   32
> 
> Can't we use the same names as in the spec? Why did you assume in your
> code that SHA256 is the only digest being used?
> 
> >
> > +#define TPM2_MAX_PCRS 32
> > +#define TPM2_PCR_SELECT_MAX ((TPM2_MAX_PCRS + 7) / 8)
> > +#define TPM2_MAX_CAP_BUFFER 1024
> > +#define TPM2_MAX_TPM_PROPERTIES   ((TPM2_MAX_CAP_BUFFER - sizeof(u32) /* 
> > TPM2_CAP */ - \
> > +  sizeof(u32)) / sizeof(struct 
> > tpms_tagged_property))
> > +
> > +/*
> > + *  We deviate from this draft of the specification by increasing the 
> > value of TPM2_NUM_PCR_BANKS
> > + *  from 3 to 16 to ensure compatibility with TPM2 implementations that 
> > have enabled a larger than
> > + *  typical number of PCR banks. This larger value for TPM2_NUM_PCR_BANKS 
> > is expected to be included
> > + *  in a future revision of the specification.
> 
> Ilias, please, restrict your lines to 80 characters where possible.
> 

Sure

> Do you have a reference for the usage of that larger number on current
> hardware? We should make the deviation from the standard easily verifiable.
> 

Yes this was copied from this:
https://tpm2-tss.readthedocs.io/en/latest/

> > + */
> > +#define TPM2_NUM_PCR_BANKS 16
> > +
> > +/* Definition of (UINT32) TPM2_CAP Constants */
> > +#define TPM2_CAP_PCRS 0x0005U
> > +#define TPM2_CAP_TPM_PROPERTIES 0x0006U
> > +
> > +/* Definition of (UINT32) TPM2_PT Constants */
> > +#define PT_GROUP   (u32)(0x0100)
> > +#define PT_FIXED   (u32)(PT_GROUP * 1)
> > +#define TPM2_PT_MANUFACTURER(u32)(PT_FIXED + 5)
> > +#define TPM2_PT_PCR_COUNT   (u32)(PT_FIXED + 18)
> > +#define TPM2_PT_MAX_COMMAND_SIZE(u32)(PT_FIXED + 30)
> > +#define TPM2_PT_MAX_RESPONSE_SIZE   (u32)(PT_FIXED + 31)
> 
> All these definitions are all copied from the "TCG TSS2.0 Overview and
> Common Structures Specification". I am missing a reference to the
> copyright notice of the spec. I think the best thing to do would be
> placing the TCG copyrighted code into a separate include that is
> included in tpm_v2.h. Please, check with Tom if the license contradicts
> GPL. Especially the following sentence seems problematic:
> 
> "THE COPYRIGHT LICENSES SET FORTH ABOVE DO NOT REPRESENT ANY FORM OF
> LICENSE OR WAIVER, EXPRESS OR IMPLIED, BY ESTOPPEL OR OTHERWISE, WITH
> RESPECT TO PATENT RIGHTS HELD BY TCG MEMBERS (OR OTHER THIRD PARTIES)
> THAT MAY BE NECESSARY TO IMPLEMENT THIS SPECIFICATION OR OTHERWISE."
> 
> Cf. https://fedoraproject.org/wiki/Licensing/TCGL
> 

Ok will do

> > +
> > +/* TPMS_TAGGED_PROPERTY Structure */
> > +struct tpms_tagged_property {
> > +   u32 property;
> > +   u32 value;
> > +} __packed;
> > +
> > +/* TPMS_PCR_SELECTION Structure */
> > +struct tpms_pcr_selection {
> > +   u16 hash;
> (This is a TPM2_ALG_ID.)
> > +   u8 size_of_select;
> > +   u8 pcr_select[TPM2_PCR_SELECT_MAX];
> > +} __packed;
> > +
> > +/* TPML_PCR_SELECTION Structure */
> > +struct tpml_pcr_selection {
> > +   u32 count;
> > +   struct tpms_pcr_selection selection[TPM2_NUM_PCR_BANKS];
> > +} __packed;
> > +
> > +/* TPML_TAGGED_TPM_PROPERTY Structure */
> > +struct tpml_tagged_tpm_property {
> > +   u32 count;
> > +   struct tpms_tagged_property tpm_property[TPM2_MAX_TPM_PROPERTIES];
> > +} __packed;
> > +
> > +/* TPMU_CAPABILITIES Union */
> > +union tpmu_capabilities {
> > +   /*
> > +* Non exhaustive. Only added the structs needed for our
> > +* current code
> > +*/
> > +   struct tpml_pcr_selection assigned_pcr;
> > +   struct tpml_tagged_tpm_property tpm_properties;
> > +} __packed;
> > +
> > +/* TPMS_CAPABILITY_DATA Structure */
> > +struct tpms_capability_data {
> > +   u32 capability;
> > +   union tpmu_capabilities data;
> > +} __packed;
> > +
> >  /**
> >   * TPM2 Structure Tags for command/response buffers.
> >   *
> > @@ -123,11 +190,13 @@ enum tpm2_return_codes {
> >   * TPM2 algorithms.
> >   */
> >  enum tpm2_a

[PATCH] rockchip: rockpro64: fix boot from SPI flash on spi1

2020-11-08 Thread Hugh Cole-Baker
Commit c4cea2bbf995 ("rockchip: Enable building a SPI ROM image on bob")
added an alias spi1 referring to spi@ff1d, however there was already
an alias spi0 referring to the same node in rockpro64's u-boot.dtsi, and
having both aliases present broke booting from SPI flash for this board.

Remove the spi0 alias, set the default bus for SPI flash to 1, and
enable support for numbered aliases in SPL so that it uses the same bus
numbering as U-Boot proper. This fixes booting from U-Boot in SPI flash
on the rockpro64 board.

Signed-off-by: Hugh Cole-Baker 
Suggested-by: Simon Glass 
Fixes: c4cea2bbf995 ("rockchip: Enable building a SPI ROM image on bob")
---
 arch/arm/dts/rk3399-rockpro64-u-boot.dtsi | 4 
 configs/rockpro64-rk3399_defconfig| 2 ++
 2 files changed, 2 insertions(+), 4 deletions(-)

diff --git a/arch/arm/dts/rk3399-rockpro64-u-boot.dtsi 
b/arch/arm/dts/rk3399-rockpro64-u-boot.dtsi
index cb8991aa253..6317b47e41a 100644
--- a/arch/arm/dts/rk3399-rockpro64-u-boot.dtsi
+++ b/arch/arm/dts/rk3399-rockpro64-u-boot.dtsi
@@ -6,10 +6,6 @@
 #include "rk3399-u-boot.dtsi"
 #include "rk3399-sdram-lpddr4-100.dtsi"
 / {
-   aliases {
-   spi0 = &spi1;
-   };
-
chosen {
u-boot,spl-boot-order = "same-as-spl", &spi_flash, &sdmmc, 
&sdhci;
};
diff --git a/configs/rockpro64-rk3399_defconfig 
b/configs/rockpro64-rk3399_defconfig
index bfba8704072..575b7a20d50 100644
--- a/configs/rockpro64-rk3399_defconfig
+++ b/configs/rockpro64-rk3399_defconfig
@@ -32,6 +32,7 @@ CONFIG_SPL_OF_CONTROL=y
 CONFIG_OF_SPL_REMOVE_PROPS="pinctrl-0 pinctrl-names clock-names 
interrupt-parent assigned-clocks assigned-clock-rates assigned-clock-parents"
 CONFIG_ENV_IS_IN_SPI_FLASH=y
 CONFIG_SYS_RELOC_GD_ENV_ADDR=y
+CONFIG_SPL_DM_SEQ_ALIAS=y
 CONFIG_ROCKCHIP_GPIO=y
 CONFIG_SYS_I2C_ROCKCHIP=y
 CONFIG_DM_KEYBOARD=y
@@ -41,6 +42,7 @@ CONFIG_MMC_DW=y
 CONFIG_MMC_DW_ROCKCHIP=y
 CONFIG_MMC_SDHCI=y
 CONFIG_MMC_SDHCI_ROCKCHIP=y
+CONFIG_SF_DEFAULT_BUS=1
 CONFIG_SPI_FLASH_GIGADEVICE=y
 CONFIG_DM_ETH=y
 CONFIG_ETH_DESIGNWARE=y
-- 
2.24.3 (Apple Git-128)



Re: [PATCH v4 07/27] rockchip: Enable building a SPI ROM image on bob

2020-11-08 Thread Hugh Cole-Baker
Hi Simon,

> On 3 Nov 2020, at 15:11, Simon Glass  wrote:
> 
> Hi Hugh,
> 
> On Wed, 14 Oct 2020 at 12:37, Hugh Cole-Baker  wrote:
>> 
>> Hello,
>>> On 11 Oct 2020, at 16:39, Emmanuel Vadot  wrote:
>>> 
>>> 
>>> Hi Simon,
>>> 
>>> On Sun, 19 Jul 2020 13:55:58 -0600
>>> Simon Glass  wrote:
>>> 
 Add a simple binman config and enable CONFIG_HAS_ROM so that U-Boot
 produces a ROM for bob.
 
 Signed-off-by: Simon Glass 
 ---
 
 Changes in v4:
 - Use CONFIG_ROCKCHIP_SPI_IMAGE to select the image
 
 arch/arm/dts/rk3399-gru-u-boot.dtsi   |  4 
 arch/arm/dts/rk3399-gru.dtsi  |  2 +-
 arch/arm/dts/rk3399-u-boot.dtsi   | 27 +++
 arch/arm/mach-rockchip/rk3399/Kconfig |  2 ++
 4 files changed, 34 insertions(+), 1 deletion(-)
 
 diff --git a/arch/arm/dts/rk3399-gru-u-boot.dtsi 
 b/arch/arm/dts/rk3399-gru-u-boot.dtsi
 index 7bddc3acdb..390ac2bb5a 100644
 --- a/arch/arm/dts/rk3399-gru-u-boot.dtsi
 +++ b/arch/arm/dts/rk3399-gru-u-boot.dtsi
 @@ -4,3 +4,7 @@
 */
 
 #include "rk3399-u-boot.dtsi"
 +
 +&spi_flash {
 +u-boot,dm-pre-reloc;
 +};
 diff --git a/arch/arm/dts/rk3399-gru.dtsi b/arch/arm/dts/rk3399-gru.dtsi
 index 7ac88392f2..f9c5bb607b 100644
 --- a/arch/arm/dts/rk3399-gru.dtsi
 +++ b/arch/arm/dts/rk3399-gru.dtsi
 @@ -537,7 +537,7 @@ ap_i2c_audio: &i2c8 {
 pinctrl-names = "default", "sleep";
 pinctrl-1 = <&spi1_sleep>;
 
 -spiflash@0 {
 +spi_flash: spiflash@0 {
 compatible = "jedec,spi-nor";
 reg = <0>;
 
 diff --git a/arch/arm/dts/rk3399-u-boot.dtsi 
 b/arch/arm/dts/rk3399-u-boot.dtsi
 index 8237782408..ecd230c720 100644
 --- a/arch/arm/dts/rk3399-u-boot.dtsi
 +++ b/arch/arm/dts/rk3399-u-boot.dtsi
 @@ -4,11 +4,14 @@
 */
 #define USB_CLASS_HUB9
 
 +#include "rockchip-u-boot.dtsi"
 +
 / {
 aliases {
 mmc0 = &sdhci;
 mmc1 = &sdmmc;
 pci0 = &pcie0;
 +spi1 = &spi1;
>>> 
>>> I don't really understand why but this added alias break spi flash
>>> detection on rockpro64.
>>> Removing it make it work again.
>> 
>> I've noticed the same problem - rockpro64 already had an alias
>> 
>> spi0 = &spi1;
>> 
>> so after this change there are spi0 and spi1 aliases pointing to &spi1.
>> In U-Boot proper, that seems to cause the SPI flash to appear on bus 1
>> rather than the former bus 0, e.g. sf probe 1:0 works but sf probe 0:0
>> doesn't.
>> 
>> So I tried removing the spi0 alias and setting CONFIG_SF_DEFAULT_BUS=1
>> which fixed the flash detection in U-Boot proper, but now the SPL can't
>> load U-Boot from SPI flash - it fails with an "Invalid bus 1 (err=-19)"
>> It seems like SPL doesn't pay attention to the spi1 alias in the same
>> way that U-boot proper does, I haven't yet figured out why.
>> 
> 
> Could this be CONFIG_SPL_DM_SEQ_ALIAS ?
> 
> Regards,
> Simon

Thanks for the pointer, that was the last missing piece to get SPI boot
working again on my board. I've just submitted a patch with the fix.

Regards,
Hugh



[PATCH V3] dm: core: Add late driver remove option

2020-11-08 Thread Marek Vasut
Add another flag to the DM core which could be assigned to drivers and
which makes those drivers call their remove callbacks last, just before
booting OS and after all the other drivers finished with their remove
callbacks. This is necessary for things like clock drivers, where the
other drivers might depend on the clock driver in their remove callbacks.
Prime example is the mmc subsystem, which can reconfigure a card from HS
mode to slower modes in the remove callback and for that it needs to
reconfigure the controller clock.

Signed-off-by: Marek Vasut 
Cc: Simon Glass 
Cc: Stefan Roese 
Cc: Tom Rini 
---
V2: Fix DM tests
V3: - Address feedback from V2, drop extra {}
- Add test
---
 arch/arm/lib/bootm.c|  1 +
 board/Marvell/octeontx2/board.c |  4 +-
 drivers/core/device-remove.c| 13 +++--
 drivers/core/root.c |  2 +
 drivers/core/uclass.c   | 26 +++--
 include/dm/device.h | 10 
 include/dm/uclass-internal.h|  3 +-
 test/dm/core.c  | 99 ++---
 test/dm/test-driver.c   | 11 
 test/dm/test-main.c | 30 +-
 10 files changed, 165 insertions(+), 34 deletions(-)

diff --git a/arch/arm/lib/bootm.c b/arch/arm/lib/bootm.c
index 1206e306db..f9091a3d41 100644
--- a/arch/arm/lib/bootm.c
+++ b/arch/arm/lib/bootm.c
@@ -120,6 +120,7 @@ static void announce_and_cleanup(int fake)
 * of DMA operation or releasing device internal buffers.
 */
dm_remove_devices_flags(DM_REMOVE_ACTIVE_ALL);
+   dm_remove_devices_flags(DM_REMOVE_ACTIVE_ALL | DM_REMOVE_LATE);
 
cleanup_before_linux();
 }
diff --git a/board/Marvell/octeontx2/board.c b/board/Marvell/octeontx2/board.c
index 50e903d9aa..d1e2372a37 100644
--- a/board/Marvell/octeontx2/board.c
+++ b/board/Marvell/octeontx2/board.c
@@ -65,7 +65,7 @@ void board_quiesce_devices(void)
/* Removes all RVU PF devices */
ret = uclass_get(UCLASS_ETH, &uc_dev);
if (uc_dev)
-   ret = uclass_destroy(uc_dev);
+   ret = uclass_destroy(uc_dev, DM_REMOVE_NORMAL);
if (ret)
printf("couldn't remove rvu pf devices\n");
 
@@ -77,7 +77,7 @@ void board_quiesce_devices(void)
/* Removes all CGX and RVU AF devices */
ret = uclass_get(UCLASS_MISC, &uc_dev);
if (uc_dev)
-   ret = uclass_destroy(uc_dev);
+   ret = uclass_destroy(uc_dev, DM_REMOVE_NORMAL);
if (ret)
printf("couldn't remove misc (cgx/rvu_af) devices\n");
 
diff --git a/drivers/core/device-remove.c b/drivers/core/device-remove.c
index efdb0f2905..a387d5666c 100644
--- a/drivers/core/device-remove.c
+++ b/drivers/core/device-remove.c
@@ -152,7 +152,7 @@ void device_free(struct udevice *dev)
 static bool flags_remove(uint flags, uint drv_flags)
 {
if ((flags & DM_REMOVE_NORMAL) ||
-   (flags & (drv_flags & (DM_FLAG_ACTIVE_DMA | DM_FLAG_OS_PREPARE
+   (flags && (drv_flags & (DM_FLAG_ACTIVE_DMA | DM_FLAG_OS_PREPARE
return true;
 
return false;
@@ -172,14 +172,19 @@ int device_remove(struct udevice *dev, uint flags)
drv = dev->driver;
assert(drv);
 
-   ret = uclass_pre_remove_device(dev);
-   if (ret)
-   return ret;
+   if (!(flags & DM_REMOVE_LATE)) {
+   ret = uclass_pre_remove_device(dev);
+   if (ret)
+   return ret;
+   }
 
ret = device_chld_remove(dev, NULL, flags);
if (ret)
goto err;
 
+   if (!(flags & DM_REMOVE_LATE) && (drv->flags & DM_FLAG_REMOVE_LATE))
+   return 0;
+
/*
 * Remove the device if called with the "normal" remove flag set,
 * or if the remove flag matches any of the drivers remove flags
diff --git a/drivers/core/root.c b/drivers/core/root.c
index 5f10d7a39c..5eb33f809e 100644
--- a/drivers/core/root.c
+++ b/drivers/core/root.c
@@ -163,6 +163,7 @@ int dm_init(bool of_live)
 int dm_uninit(void)
 {
device_remove(dm_root(), DM_REMOVE_NORMAL);
+   device_remove(dm_root(), DM_REMOVE_LATE);
device_unbind(dm_root());
gd->dm_root = NULL;
 
@@ -391,6 +392,7 @@ struct acpi_ops root_acpi_ops = {
 U_BOOT_DRIVER(root_driver) = {
.name   = "root_driver",
.id = UCLASS_ROOT,
+   .flags  = DM_FLAG_REMOVE_LATE,
ACPI_OPS_PTR(&root_acpi_ops)
 };
 
diff --git a/drivers/core/uclass.c b/drivers/core/uclass.c
index c3f1b73cd6..a20f7b41ce 100644
--- a/drivers/core/uclass.c
+++ b/drivers/core/uclass.c
@@ -104,10 +104,28 @@ fail_mem:
return ret;
 }
 
-int uclass_destroy(struct uclass *uc)
+int uclass_find_device_by_drv_flag(struct uclass *uc, const unsigned int flag,
+  const bool neg, struct udevice **devp)
+{
+   struct udevice *dev;
+
+   *devp = NULL;
+   uclass_foreach_dev(dev, uc) {
+   if ((neg && (dev-

Re: [PATCH 0/5] sunxi: enable automatic eMMC boot partition support

2020-11-08 Thread Peter Robinson
On Sun, Nov 8, 2020 at 1:14 PM Andre Przywara  wrote:
>
> The eMMC standard describes the concept of boot partitions, consisting
> of two storage areas separate from the main user data partition.
> The Allwinner BootROM supports loading SPL/Boot0 from such a boot
> partition, if that is configured in the eMMC device [1].
>
> To load U-Boot proper along with the SPL from there, currently this
> requires to enable CONFIG_SUPPORT_EMMC_BOOT, and this means that this
> build won't boot from the normal eMMC user partition anymore.
> Also the raw MMC sector offset needs to be adjusted manually, preventing
> a boot from an SD card.
>
> This series introduces automatic detection of eMMC boot partition boot.
> Patch 3/5 automates the raw MMC sector offset decision, allowing such
> a build to also boot from an SD card.
> Unfortunately the BootROM does not mark an eMMC boot partition boot
> differently from the normal eMMC user data partition boot, so patch 4/5
> introduces a function that repeats the BootROM algorithm, so that the SPL
> comes to the same conclusion as the BootROM. This allows to build one
> single image that boots from everywhere: eMMC user data, eMMC boot,
> SD card, SPI flash.
> Patch 1/5 contains a bugfix that's needed in a later patch, patch 2/5
> extends the generic spl_mmc_boot_mode() interface to make 4/5 feasible.
>
> Without enabling CONFIG_SUPPORT_EMMC_BOOT, the AArch64 SPL grows by
> 92 bytes, ARMv7 grows by 36 bytes. With enabling the feature, the size
> goes up by 444 bytes (AArch64) and 260 bytes (ARMv7).
> Even for AArch64 this is still 4.5 KB below the SPL limit, so patch 5/5
> enables this new mechanism for some boards I could test this on.
>
> Please have a look and test this if you have a board with eMMC.
> I put installation instructions into the linux-sunxi Wiki:
> http://linux-sunxi.org/Bootable_eMMC

It would probably be good to put that link in the local Allwinner docs
so it's easier for people to find.

Peter

> Cheers,
> Andre
>
> [1] http://linux-sunxi.org/Bootable_eMMC#The_BROM_implementation_details
>
> Andre Przywara (5):
>   sunxi: Fix is_boot0_magic macro
>   spl: mmc: extend spl_mmc_boot_mode() to take mmc argument
>   sunxi: Simplify eMMC boot partition booting
>   sunxi: eMMC: Add automatic boot detection
>   sunxi: defconfig: enable eMMC boot partition support
>
>  arch/arm/include/asm/arch-sunxi/spl.h  |  2 +-
>  arch/arm/mach-imx/spl.c|  2 +-
>  arch/arm/mach-k3/am6_init.c|  2 +-
>  arch/arm/mach-k3/j721e_init.c  |  2 +-
>  arch/arm/mach-omap2/boot-common.c  |  2 +-
>  arch/arm/mach-rockchip/spl.c   |  2 +-
>  arch/arm/mach-socfpga/spl_a10.c|  2 +-
>  arch/arm/mach-socfpga/spl_agilex.c |  2 +-
>  arch/arm/mach-socfpga/spl_gen5.c   |  2 +-
>  arch/arm/mach-socfpga/spl_s10.c|  2 +-
>  arch/arm/mach-stm32mp/spl.c|  2 +-
>  arch/arm/mach-sunxi/board.c| 94 +-
>  arch/arm/mach-uniphier/mmc-boot-mode.c |  5 +-
>  common/spl/spl_mmc.c   |  4 +-
>  configs/bananapi_m64_defconfig |  1 +
>  configs/emlid_neutis_n5_devboard_defconfig |  1 +
>  configs/pine64-lts_defconfig   |  1 +
>  configs/pine_h64_defconfig |  1 +
>  include/spl.h  |  3 +-
>  19 files changed, 113 insertions(+), 19 deletions(-)
>
> --
> 2.17.5
>


Re: [PATCH 0/5] sunxi: enable automatic eMMC boot partition support

2020-11-08 Thread André Przywara
On 08/11/2020 14:59, Peter Robinson wrote:

Hi,

> On Sun, Nov 8, 2020 at 1:14 PM Andre Przywara  wrote:
>>
>> The eMMC standard describes the concept of boot partitions, consisting
>> of two storage areas separate from the main user data partition.
>> The Allwinner BootROM supports loading SPL/Boot0 from such a boot
>> partition, if that is configured in the eMMC device [1].
>>
>> To load U-Boot proper along with the SPL from there, currently this
>> requires to enable CONFIG_SUPPORT_EMMC_BOOT, and this means that this
>> build won't boot from the normal eMMC user partition anymore.
>> Also the raw MMC sector offset needs to be adjusted manually, preventing
>> a boot from an SD card.
>>
>> This series introduces automatic detection of eMMC boot partition boot.
>> Patch 3/5 automates the raw MMC sector offset decision, allowing such
>> a build to also boot from an SD card.
>> Unfortunately the BootROM does not mark an eMMC boot partition boot
>> differently from the normal eMMC user data partition boot, so patch 4/5
>> introduces a function that repeats the BootROM algorithm, so that the SPL
>> comes to the same conclusion as the BootROM. This allows to build one
>> single image that boots from everywhere: eMMC user data, eMMC boot,
>> SD card, SPI flash.
>> Patch 1/5 contains a bugfix that's needed in a later patch, patch 2/5
>> extends the generic spl_mmc_boot_mode() interface to make 4/5 feasible.
>>
>> Without enabling CONFIG_SUPPORT_EMMC_BOOT, the AArch64 SPL grows by
>> 92 bytes, ARMv7 grows by 36 bytes. With enabling the feature, the size
>> goes up by 444 bytes (AArch64) and 260 bytes (ARMv7).
>> Even for AArch64 this is still 4.5 KB below the SPL limit, so patch 5/5
>> enables this new mechanism for some boards I could test this on.
>>
>> Please have a look and test this if you have a board with eMMC.
>> I put installation instructions into the linux-sunxi Wiki:
>> http://linux-sunxi.org/Bootable_eMMC
> 
> It would probably be good to put that link in the local Allwinner docs
> so it's easier for people to find.

Yeah, actually as you mention it:
There does not seem to be some generic README.sunxi file where this
would belong to.

Jagan: would it make sense to create one, and describe how to get U-Boot
into the devices (SD card, eMMC, SPI flash, FEL)? That could move some
parts of README.sunxi64 out of there, since they apply to all Allwinner
devices.

If people agree that this is the right thing to do, I would be happy to
send a patch.

Cheers,
Andre

>>
>> [1] http://linux-sunxi.org/Bootable_eMMC#The_BROM_implementation_details
>>
>> Andre Przywara (5):
>>   sunxi: Fix is_boot0_magic macro
>>   spl: mmc: extend spl_mmc_boot_mode() to take mmc argument
>>   sunxi: Simplify eMMC boot partition booting
>>   sunxi: eMMC: Add automatic boot detection
>>   sunxi: defconfig: enable eMMC boot partition support
>>
>>  arch/arm/include/asm/arch-sunxi/spl.h  |  2 +-
>>  arch/arm/mach-imx/spl.c|  2 +-
>>  arch/arm/mach-k3/am6_init.c|  2 +-
>>  arch/arm/mach-k3/j721e_init.c  |  2 +-
>>  arch/arm/mach-omap2/boot-common.c  |  2 +-
>>  arch/arm/mach-rockchip/spl.c   |  2 +-
>>  arch/arm/mach-socfpga/spl_a10.c|  2 +-
>>  arch/arm/mach-socfpga/spl_agilex.c |  2 +-
>>  arch/arm/mach-socfpga/spl_gen5.c   |  2 +-
>>  arch/arm/mach-socfpga/spl_s10.c|  2 +-
>>  arch/arm/mach-stm32mp/spl.c|  2 +-
>>  arch/arm/mach-sunxi/board.c| 94 +-
>>  arch/arm/mach-uniphier/mmc-boot-mode.c |  5 +-
>>  common/spl/spl_mmc.c   |  4 +-
>>  configs/bananapi_m64_defconfig |  1 +
>>  configs/emlid_neutis_n5_devboard_defconfig |  1 +
>>  configs/pine64-lts_defconfig   |  1 +
>>  configs/pine_h64_defconfig |  1 +
>>  include/spl.h  |  3 +-
>>  19 files changed, 113 insertions(+), 19 deletions(-)
>>
>> --
>> 2.17.5
>>



[PATCH v2] arm: mvebu: a38x: Configurable USB2 high-speed impedance threshold

2020-11-08 Thread Joshua Scott
Hardware testing of a board using the Armada 385 has shown that an
impedance threshold setting of 0x7 performs better in an eye-diagram
test than with Marvell's recommended value 0x6.

As other boards may still perform better with Marvell's reccomended value,
a configuration option is added with a default value of 0x6.

Signed-off-by: Joshua Scott 
Reviewed-by: Stefan Roese 
---
Changes for v2:
- Added "range" to Kconfig to prevent invalid values from being
  selected.

 arch/arm/mach-mvebu/Kconfig   | 6 ++
 arch/arm/mach-mvebu/serdes/a38x/high_speed_env_spec.c | 6 +++---
 2 files changed, 9 insertions(+), 3 deletions(-)

diff --git a/arch/arm/mach-mvebu/Kconfig b/arch/arm/mach-mvebu/Kconfig
index 0d8e0922a2..72aee8b3e5 100644
--- a/arch/arm/mach-mvebu/Kconfig
+++ b/arch/arm/mach-mvebu/Kconfig
@@ -30,6 +30,12 @@ config ARMADA_38X
select ARMADA_32BIT
select HAVE_MVEBU_EFUSE
 
+config ARMADA_38X_HS_IMPEDANCE_THRESH
+   hex  "Armada 38x USB 2.0 High-Speed Impedance Threshold (0x0 - 0x7)"
+   depends on ARMADA_38X
+   default 0x6
+   range 0x0 0x7
+
 config ARMADA_XP
bool
select ARMADA_32BIT
diff --git a/arch/arm/mach-mvebu/serdes/a38x/high_speed_env_spec.c 
b/arch/arm/mach-mvebu/serdes/a38x/high_speed_env_spec.c
index 2454730e6d..ae2a361104 100644
--- a/arch/arm/mach-mvebu/serdes/a38x/high_speed_env_spec.c
+++ b/arch/arm/mach-mvebu/serdes/a38x/high_speed_env_spec.c
@@ -677,9 +677,9 @@ struct op_params usb2_power_up_params[] = {
{0xc200c, 0x0 /*NA*/, 0xf000, {0x1000}, 0, 0},
{0xc400c, 0x0 /*NA*/, 0xf000, {0x1000}, 0, 0},
/* Change the High speed impedance threshold */
-   {0xc0008, 0x0 /*NA*/, 0x700, {0x600}, 0, 0},
-   {0xc2008, 0x0 /*NA*/, 0x700, {0x600}, 0, 0},
-   {0xc4008, 0x0 /*NA*/, 0x700, {0x600}, 0, 0},
+   {0xc0008, 0x0 /*NA*/, 0x700, {CONFIG_ARMADA_38X_HS_IMPEDANCE_THRESH << 
8}, 0, 0},
+   {0xc2008, 0x0 /*NA*/, 0x700, {CONFIG_ARMADA_38X_HS_IMPEDANCE_THRESH << 
8}, 0, 0},
+   {0xc4008, 0x0 /*NA*/, 0x700, {CONFIG_ARMADA_38X_HS_IMPEDANCE_THRESH << 
8}, 0, 0},
/* Change the squelch level of the receiver to meet the receiver 
electrical measurements (squelch and receiver sensitivity tests) */
{0xc0014, 0x0 /*NA*/, 0xf, {0x8}, 0, 0},
{0xc2014, 0x0 /*NA*/, 0xf, {0x8}, 0, 0},
-- 
2.29.2



[PATCH] rockchip: Move Bob specific bits to it's specific u-boot.dtsi

2020-11-08 Thread Peter Robinson
Move the bits that are device specific to the -u-boot.dtsi as the
bits may be different on other devices and hence breaks SPI on
those devices such as the Pinebook Pro.

Signed-off-by: Peter Robinson 
Fixes: c4cea2bbf995 ("rockchip: Enable building a SPI ROM image on bob")
Cc: Simon Glass 
---
 arch/arm/dts/rk3399-gru-u-boot.dtsi | 30 +
 arch/arm/dts/rk3399-u-boot.dtsi | 25 
 2 files changed, 30 insertions(+), 25 deletions(-)

diff --git a/arch/arm/dts/rk3399-gru-u-boot.dtsi 
b/arch/arm/dts/rk3399-gru-u-boot.dtsi
index 390ac2bb5a..5e95cacfea 100644
--- a/arch/arm/dts/rk3399-gru-u-boot.dtsi
+++ b/arch/arm/dts/rk3399-gru-u-boot.dtsi
@@ -5,6 +5,36 @@
 
 #include "rk3399-u-boot.dtsi"
 
+/ {
+   aliases {
+   spi1 = &spi1;
+   };
+};
+
+#ifdef CONFIG_ROCKCHIP_SPI_IMAGE
+&binman {
+   rom {
+   filename = "u-boot.rom";
+   size = <0x40>;
+   pad-byte = <0xff>;
+
+   mkimage {
+   args = "-n rk3399 -T rkspi";
+   u-boot-spl {
+   };
+   };
+   u-boot-img {
+   offset = <0x4>;
+   };
+   u-boot {
+   offset = <0x30>;
+   };
+   fdtmap {
+   };
+   };
+};
+#endif
+
 &spi_flash {
u-boot,dm-pre-reloc;
 };
diff --git a/arch/arm/dts/rk3399-u-boot.dtsi b/arch/arm/dts/rk3399-u-boot.dtsi
index ecd230c720..26b0a34e64 100644
--- a/arch/arm/dts/rk3399-u-boot.dtsi
+++ b/arch/arm/dts/rk3399-u-boot.dtsi
@@ -11,7 +11,6 @@
mmc0 = &sdhci;
mmc1 = &sdmmc;
pci0 = &pcie0;
-   spi1 = &spi1;
};
 
cic: syscon@ff62 {
@@ -60,30 +59,6 @@
 
 };
 
-#ifdef CONFIG_ROCKCHIP_SPI_IMAGE
-&binman {
-   rom {
-   filename = "u-boot.rom";
-   size = <0x40>;
-   pad-byte = <0xff>;
-
-   mkimage {
-   args = "-n rk3399 -T rkspi";
-   u-boot-spl {
-   };
-   };
-   u-boot-img {
-   offset = <0x4>;
-   };
-   u-boot {
-   offset = <0x30>;
-   };
-   fdtmap {
-   };
-   };
-};
-#endif
-
 &cru {
u-boot,dm-pre-reloc;
 };
-- 
2.28.0



Re: [PATCH 2/3] mmc: meson-gx: limit max frequency on SM1 SoCs

2020-11-08 Thread Jaehoon Chung
Hi Mark,

On 11/6/20 8:53 PM, Mark Kettenis wrote:
>> From: Neil Armstrong 
>> Date: Fri, 6 Nov 2020 11:35:30 +0100
>>
>> On 06/11/2020 11:32, Jaehoon Chung wrote:
>>> On 11/6/20 6:27 PM, Neil Armstrong wrote:
 Amlogic SM1 SoCs doesn't handle very well high clocks from the DIV2 input
 Thus we limit the max freq to 26MHz on SM1 SoCs until we handle higher
 frequencies via the first input from a composite clock.

 Here 26MHz corresponds to MMC_HS clock speed.

 We also add a u-boot only sm1 compatible to distinguish the controller.
>>>
>>> Well, it's workaround for using eMMC.
>>
>> It's for the next release, to have a temporary fix.
>> The goal is to not have such workaround
>>
>>> I didn't check all SM1 SoCs..but odroid-c4 is supported hs200 mode (200MHz) 
>>> on Kernel side.
>>> It means that bootloader can also support its mode.
>>>
>>> I'm checking this problem with odroid-c4 target. If i find how to fix, i 
>>> will share.
>>
>> H200 will need a big work including tuning and proper clock management.
> 
> I worry a bit that this would make things more fragile.  I have some
> trouble getting HS200 to work properly on the Odroid-N2 in OpenBSD
> (might be a clock management issue).  And the fact that on both the
> Odroid-N2 and Odroid-C4 the eMMC isn't soldered on means that it has
> to work reliably on a wider variety of eMMC modules.
> 
> I believe Linux automatically switches back to a lowe-speed mode if
> HS200 doesn't work isn't it?  Should U-Boot do something similar?

As i know, It's provided on U-boot side, likes Linux.
If HS200 or other modes are failed, then it's trying to set lower mode.
But I don't know why SM1 SoC doesn't set to it. 
It seems that doesn't recovery to previous clock or some configs.

Best Regards,
Jaehoon Chung

> 
>> If you manage to got that far, I'll be great !
>>
>> Neil
>>
>>>
>>> Best Regards,
>>> Jaehoon Chung
>>>
>>>

 Finally a TOFIX is added to precise the clock management should use
 the clock controller instead of local management with fixed clock rates.

 Signed-off-by: Neil Armstrong 
 ---
  drivers/mmc/meson_gx_mmc.c | 26 +++---
  drivers/mmc/meson_gx_mmc.h |  5 +
  2 files changed, 28 insertions(+), 3 deletions(-)

 diff --git a/drivers/mmc/meson_gx_mmc.c b/drivers/mmc/meson_gx_mmc.c
 index 9350edf3fa..2c6b6cd15b 100644
 --- a/drivers/mmc/meson_gx_mmc.c
 +++ b/drivers/mmc/meson_gx_mmc.c
 @@ -17,6 +17,14 @@
  #include 
  #include "meson_gx_mmc.h"
  
 +bool meson_gx_mmc_is_compatible(struct udevice *dev,
 +  enum meson_gx_mmc_compatible family)
 +{
 +  enum meson_gx_mmc_compatible compat = dev_get_driver_data(dev);
 +
 +  return compat == family;
 +}
 +
  static inline void *get_regbase(const struct mmc *mmc)
  {
struct meson_mmc_platdata *pdata = mmc->priv;
 @@ -42,6 +50,8 @@ static void meson_mmc_config_clock(struct mmc *mmc)
if (!mmc->clock)
return;
  
 +  /* TOFIX This should use the proper clock taken from DT */
 +
/* 1GHz / CLK_MAX_DIV = 15,9 MHz */
if (mmc->clock > 1600) {
clk = SD_EMMC_CLKSRC_DIV2;
 @@ -265,7 +275,16 @@ static int meson_mmc_probe(struct udevice *dev)
cfg->host_caps = MMC_MODE_8BIT | MMC_MODE_4BIT |
MMC_MODE_HS_52MHz | MMC_MODE_HS;
cfg->f_min = DIV_ROUND_UP(SD_EMMC_CLKSRC_24M, CLK_MAX_DIV);
 -  cfg->f_max = 1; /* 100 MHz */;
 +  /*
 +   * TOFIX SM1 SoCs doesn't handle very well high clocks from the DIV2 
 input
 +   * Thus we limit the max freq to 26MHz on SM1 SoCs until we handle 
 higher
 +   * frequencies via the first input from a composite clock
 +   * 26MHz corresponds to MMC_HS clock speed
 +   */
 +  if (meson_gx_mmc_is_compatible(dev, MMC_COMPATIBLE_SM1))
 +  cfg->f_max = 2600; /* 26 MHz */
 +  else
 +  cfg->f_max = 1; /* 100 MHz */
cfg->b_max = 511; /* max 512 - 1 blocks */
cfg->name = dev->name;
  
 @@ -308,8 +327,9 @@ int meson_mmc_bind(struct udevice *dev)
  }
  
  static const struct udevice_id meson_mmc_match[] = {
 -  { .compatible = "amlogic,meson-gx-mmc" },
 -  { .compatible = "amlogic,meson-axg-mmc" },
 +  { .compatible = "amlogic,meson-gx-mmc", .data = MMC_COMPATIBLE_GX },
 +  { .compatible = "amlogic,meson-axg-mmc", .data = MMC_COMPATIBLE_GX },
 +  { .compatible = "amlogic,meson-sm1-mmc", .data = MMC_COMPATIBLE_SM1 },
{ /* sentinel */ }
  };
  
 diff --git a/drivers/mmc/meson_gx_mmc.h b/drivers/mmc/meson_gx_mmc.h
 index b4544b5562..92aec5329f 100644
 --- a/drivers/mmc/meson_gx_mmc.h
 +++ b/drivers/mmc/meson_gx_mmc.h
 @@ -9,6 +9,11 @@
  #include 
  #include 
  
 +enum meson_gx_mmc_compatible {
 +  MMC_COMPATIBL

[PATCH] efi_loader: improve detection of ESP for storing UEFI variables

2020-11-08 Thread Paulo Alcantara
The UEFI specification does not restrict on the number and location of
ESPs in a system.  They are discovered as required by looking at the
partition type, but firmware implementations are allowed to support
ESPs which do not contain a valid partition type.

Besides checking for the partition type, for non-removable media check
if /EFI directory exists, otherwise check if /EFI/BOOT/BOOT{ARCH}.EFI
file exists as specified in UEFI 2.8 "13.3.1.3 Directory Structure".

Signed-off-by: Paulo Alcantara (SUSE) 
---
 lib/efi_loader/efi_disk.c | 60 +--
 1 file changed, 38 insertions(+), 22 deletions(-)

diff --git a/lib/efi_loader/efi_disk.c b/lib/efi_loader/efi_disk.c
index 7bd1ccec4501..2940a2edf2e8 100644
--- a/lib/efi_loader/efi_disk.c
+++ b/lib/efi_loader/efi_disk.c
@@ -335,6 +335,35 @@ static int efi_fs_exists(struct blk_desc *desc, int part)
return 1;
 }
 
+/**
+ * efi_part_is_esp() - check if a partition is an EFI system partition
+ *
+ * @desc:  block device descriptor
+ * @part:  partition number
+ * Return: true if a partition is an EFI system partition
+ * false otherwise
+ */
+static bool efi_part_is_esp(struct blk_desc *desc, int part)
+{
+   int ret;
+   struct disk_partition info;
+
+   ret = part_get_info(desc, part, &info);
+   if (ret)
+   return false;
+
+   if (info.bootable & PART_EFI_SYSTEM_PARTITION)
+   return true;
+
+   if (fs_set_blk_dev_with_part(desc, part))
+   return false;
+
+   if (!desc->removable)
+   return !!fs_exists("/EFI");
+
+   return !!fs_exists("/EFI/BOOT/" BOOTEFI_NAME);
+}
+
 /**
  * efi_disk_add_dev() - create a handle for a partition or disk
  *
@@ -436,21 +465,14 @@ static efi_status_t efi_disk_add_dev(
*disk = diskobj;
 
/* Store first EFI system partition */
-   if (part && !efi_system_partition.if_type) {
-   int r;
-   struct disk_partition info;
-
-   r = part_get_info(desc, part, &info);
-   if (r)
-   return EFI_DEVICE_ERROR;
-   if (info.bootable & PART_EFI_SYSTEM_PARTITION) {
-   efi_system_partition.if_type = desc->if_type;
-   efi_system_partition.devnum = desc->devnum;
-   efi_system_partition.part = part;
-   EFI_PRINT("EFI system partition: %s %d:%d\n",
- blk_get_if_type_name(desc->if_type),
- desc->devnum, part);
-   }
+   if (part && !efi_system_partition.if_type &&
+   efi_part_is_esp(desc, part)) {
+   efi_system_partition.if_type = desc->if_type;
+   efi_system_partition.devnum = desc->devnum;
+   efi_system_partition.part = part;
+   EFI_PRINT("EFI system partition: %s %d:%d\n",
+ blk_get_if_type_name(desc->if_type),
+ desc->devnum, part);
}
return EFI_SUCCESS;
 }
@@ -614,9 +636,7 @@ bool efi_disk_is_system_part(efi_handle_t handle)
 {
struct efi_handler *handler;
struct efi_disk_obj *diskobj;
-   struct disk_partition info;
efi_status_t ret;
-   int r;
 
/* check if this is a block device */
ret = efi_search_protocol(handle, &efi_block_io_guid, &handler);
@@ -625,9 +645,5 @@ bool efi_disk_is_system_part(efi_handle_t handle)
 
diskobj = container_of(handle, struct efi_disk_obj, header);
 
-   r = part_get_info(diskobj->desc, diskobj->part, &info);
-   if (r)
-   return false;
-
-   return !!(info.bootable & PART_EFI_SYSTEM_PARTITION);
+   return efi_part_is_esp(diskobj->desc, diskobj->part);
 }
-- 
2.29.2



Re: [PATCH V3] dm: core: Add late driver remove option

2020-11-08 Thread Simon Glass
Hi Marek,

On Sun, 8 Nov 2020 at 07:09, Marek Vasut  wrote:
>
> Add another flag to the DM core which could be assigned to drivers and
> which makes those drivers call their remove callbacks last, just before
> booting OS and after all the other drivers finished with their remove
> callbacks. This is necessary for things like clock drivers, where the
> other drivers might depend on the clock driver in their remove callbacks.
> Prime example is the mmc subsystem, which can reconfigure a card from HS
> mode to slower modes in the remove callback and for that it needs to
> reconfigure the controller clock.
>
> Signed-off-by: Marek Vasut 
> Cc: Simon Glass 
> Cc: Stefan Roese 
> Cc: Tom Rini 
> ---
> V2: Fix DM tests
> V3: - Address feedback from V2, drop extra {}
> - Add test
> ---
>  arch/arm/lib/bootm.c|  1 +
>  board/Marvell/octeontx2/board.c |  4 +-
>  drivers/core/device-remove.c| 13 +++--
>  drivers/core/root.c |  2 +
>  drivers/core/uclass.c   | 26 +++--
>  include/dm/device.h | 10 
>  include/dm/uclass-internal.h|  3 +-
>  test/dm/core.c  | 99 ++---
>  test/dm/test-driver.c   | 11 
>  test/dm/test-main.c | 30 +-
>  10 files changed, 165 insertions(+), 34 deletions(-)
>
> diff --git a/arch/arm/lib/bootm.c b/arch/arm/lib/bootm.c
> index 1206e306db..f9091a3d41 100644
> --- a/arch/arm/lib/bootm.c
> +++ b/arch/arm/lib/bootm.c
> @@ -120,6 +120,7 @@ static void announce_and_cleanup(int fake)
>  * of DMA operation or releasing device internal buffers.
>  */
> dm_remove_devices_flags(DM_REMOVE_ACTIVE_ALL);
> +   dm_remove_devices_flags(DM_REMOVE_ACTIVE_ALL | DM_REMOVE_LATE);

Please see my previous comments about the naming and semantics. I'm
repeating them here:

Firstly I think we should use a different name. 'Late' doesn't really
tell me anything.

If I understand it correctly, this is supposed to be after OS_PREPARE
but before booting the OS?

I think we need to separate the flag names as they are too similar.

I think DM_FLAG_BASIC and DM_REMOVE_NON_BASIC would be better (or some
term that explains that this is a device used by many others)

If BASIC is too terrible, perhaps CORE, or VITAL, or PRIME or CRITICAL
or something like that?

That way we are describing the property of the device rather than what
we want to do with it.

Note also the semantics of what is going on here. The idea of the
existing OS_PREPARE and ACTIVE_DMA flags is that the default for
device_remove() is to remove everything, but if you provide a flag
then it just removes those things. Your flag is the opposite to that,
which is why you are changing so much code.

So I think we could change this to DM_REMOVE_NON_BASIC and make that a
separate step before we do a final remove with flags of 0.

>
> cleanup_before_linux();
>  }
> diff --git a/board/Marvell/octeontx2/board.c b/board/Marvell/octeontx2/board.c
> index 50e903d9aa..d1e2372a37 100644
> --- a/board/Marvell/octeontx2/board.c
> +++ b/board/Marvell/octeontx2/board.c

Should be in a separate patch

> @@ -65,7 +65,7 @@ void board_quiesce_devices(void)
> /* Removes all RVU PF devices */
> ret = uclass_get(UCLASS_ETH, &uc_dev);
> if (uc_dev)
> -   ret = uclass_destroy(uc_dev);
> +   ret = uclass_destroy(uc_dev, DM_REMOVE_NORMAL);
> if (ret)
> printf("couldn't remove rvu pf devices\n");
>
> @@ -77,7 +77,7 @@ void board_quiesce_devices(void)
> /* Removes all CGX and RVU AF devices */
> ret = uclass_get(UCLASS_MISC, &uc_dev);
> if (uc_dev)
> -   ret = uclass_destroy(uc_dev);
> +   ret = uclass_destroy(uc_dev, DM_REMOVE_NORMAL);
> if (ret)
> printf("couldn't remove misc (cgx/rvu_af) devices\n");
>
> diff --git a/drivers/core/device-remove.c b/drivers/core/device-remove.c
> index efdb0f2905..a387d5666c 100644
> --- a/drivers/core/device-remove.c
> +++ b/drivers/core/device-remove.c
> @@ -152,7 +152,7 @@ void device_free(struct udevice *dev)
>  static bool flags_remove(uint flags, uint drv_flags)
>  {
> if ((flags & DM_REMOVE_NORMAL) ||
> -   (flags & (drv_flags & (DM_FLAG_ACTIVE_DMA | DM_FLAG_OS_PREPARE
> +   (flags && (drv_flags & (DM_FLAG_ACTIVE_DMA | 
> DM_FLAG_OS_PREPARE

This looks like a bug fix. In any case it should be in its own patch.

> return true;
>
> return false;
> @@ -172,14 +172,19 @@ int device_remove(struct udevice *dev, uint flags)
> drv = dev->driver;
> assert(drv);
>
> -   ret = uclass_pre_remove_device(dev);
> -   if (ret)
> -   return ret;
> +   if (!(flags & DM_REMOVE_LATE)) {
> +   ret = uclass_pre_remove_device(dev);
> +   if (ret)
> +   return ret;
> +   }
>
> ret = device_chld_remove(dev, NULL, fl

RE: [PATCH] usb: xhci: fix event trb handling missed

2020-11-08 Thread Ran Wang
Hi Bin,

On Friday, November 6, 2020 3:54 PM, Bin Meng wrote:
> To: Marek Vasut 
> Cc: Ran Wang ; U-Boot Mailing List
> 
> Subject: Re: [PATCH] usb: xhci: fix event trb handling missed
> 
> On Tue, Sep 22, 2020 at 7:41 PM Marek Vasut  wrote:
> >
> > On 9/22/20 6:54 AM, Ran Wang wrote:
> > > In functiion xhci_bulk_tx(), when buffer cross 64KB boundary, it
> > > will send request in more than 1 Transfer TRB by chaining them, but
> > > then handle only 1 event TRB to mark request completed.
> > >
> > > However, on Layerscape platforms (LS1028A, LS1088A, etc), we observe
> > > xhci controller will generated more than 1 event TRB sometimes, this
> > > cause that function mishandle event TRB in next round call, then
> > > system hang due to
> > > BUG() checking.
> > >
> > > This patch adds a loop to make sure the event TRB for last Transfer
> > > TRB has to be handled in time.
> >
> > Bin, can you please take a look at this one ? Thanks
> 
> Sorry I missed this one. Will take a look at this soon.

Kindly remind that this patch is to resolve issue I ever sent to community for 
help: 
https://lists.denx.de/pipermail/u-boot/2020-September/426981.html

Thanks & Regards,
Ran



Re: [PATCH 0/3] mmc: meson-gx: fix mmc & scard failure on SM1 SoCs

2020-11-08 Thread Jaehoon Chung
Dear Neil,

On 11/6/20 6:27 PM, Neil Armstrong wrote:
> Amlogic SM1 SoCs doesn't handle very well high clocks from the DIV2 input
> Thus we limit the max freq to 26MHz on SM1 SoCs until we handle higher
> frequencies via the first input from a composite clock.
> 
> Here 26MHz corresponds to MMC_HS clock speed.

When i have checked, it's working with 52MHz.

mmc1(part 0) is current device
Odroid N2> mmcinfo
Device: mmc@ffe07000
Manufacturer ID: 15
OEM: 100
Name: BJTD4
Bus Speed: 5200
Mode: MMC High Speed (52MHz)
Rd Block Len: 512
MMC version 5.1
High Capacity: Yes
Capacity: 29.1 GiB
Bus Width: 8-bit
Erase Group Size: 512 KiB
HC WP Group Size: 8 MiB
User Capacity: 29.1 GiB WRREL
Boot Capacity: 4 MiB ENH
RPMB Capacity: 4 MiB ENH


Device: sd@ffe05000
Manufacturer ID: 3
OEM: 5344
Name: SB16G
Bus Speed: 5000
Mode: SD High Speed (50MHz)
Rd Block Len: 512
SD version 3.0
High Capacity: Yes
Capacity: 14.8 GiB
Bus Width: 4-bit
Erase Group Size: 512 Bytes
Odroid N2> ums 0 mmc 0

If you can wait for more time, i can fix it.
I think that it's better than applying this patch.
But i don't know which boards are SM1 SoC..(Odroid-c4 and VIM3L?)

Best Regards,
Jaehoon Chung

> 
> We also add a u-boot only sm1 compatible to distinguish the controller in a 
> new
> meson-sm1-u-boot.dtsi and reworks the other -u-boot.dtsi to use this for SM1 
> based boards.
> 
> Finally a TOFIX is added to precise the clock management should use
> the clock controller instead of local management with fixed clock rates.
> 
> Neil Armstrong (3):
>   mmc: meson-gx: move arch header to local header
>   mmc: meson-gx: limit max frequency on SM1 SoCs
>   ARM: dts: meson-sm1: add u-boot specific MMC controller compatible
> 
>  .../meson-g12b-a311d-khadas-vim3-u-boot.dtsi  |  1 +
>  arch/arm/dts/meson-khadas-vim3-u-boot.dtsi|  2 --
>  .../dts/meson-sm1-khadas-vim3l-u-boot.dtsi|  1 +
>  arch/arm/dts/meson-sm1-odroid-c4-u-boot.dtsi  |  2 +-
>  arch/arm/dts/meson-sm1-sei610-u-boot.dtsi |  2 +-
>  arch/arm/dts/meson-sm1-u-boot.dtsi| 20 +
>  drivers/mmc/meson_gx_mmc.c| 28 ---
>  .../sd_emmc.h => drivers/mmc/meson_gx_mmc.h   | 10 ---
>  8 files changed, 54 insertions(+), 12 deletions(-)
>  create mode 100644 arch/arm/dts/meson-sm1-u-boot.dtsi
>  rename arch/arm/include/asm/arch-meson/sd_emmc.h => 
> drivers/mmc/meson_gx_mmc.h (95%)
> 



RE: [PATCH 2/5] spl: mmc: extend spl_mmc_boot_mode() to take mmc argument

2020-11-08 Thread Tan, Ley Foon



> -Original Message-
> From: Andre Przywara 
> Sent: Sunday, November 8, 2020 9:14 PM
> To: Jagan Teki 
> Cc: Petr Štetiar ; Sunil Mohan Adapa ;
> Samuel Holland ; Aleksandr Aleksandrov
> ; Icenowy Zheng ;
> Simon Glass ; Tom Rini ; linux-
> su...@googlegroups.com; u-boot@lists.denx.de; Stefano Babic
> ; Fabio Estevam ; NXP i . MX U-
> Boot Team ; Lokesh Vutla ;
> Philipp Tomsich ; Kever Yang
> ; Marek Vasut ; Simon
> Goldschmidt ; Tan, Ley Foon
> ; Patrick Delaunay ;
> Patrice Chotard ; Andre Przywara
> 
> Subject: [PATCH 2/5] spl: mmc: extend spl_mmc_boot_mode() to take mmc
> argument
> 
> Platforms can overwrite the weak definition of spl_mmc_boot_mode() to
> determine where to load U-Boot proper from.
> For most of them this is a trivial decision based on Kconfig variables, but it
> might be desirable the probe the actual device to answer this question.
> 
> Pass the pointer to the mmc struct to that function, so implementations can
> make use of them.
> 
> Compile-tested for all users changed.
> 
> Cc: Stefano Babic 
> Cc: Fabio Estevam 
> Cc: NXP i.MX U-Boot Team 
> Cc: Lokesh Vutla 
> Cc: Philipp Tomsich 
> Cc: Kever Yang 
> Cc: Marek Vasut 
> Cc: Simon Goldschmidt 
> Cc: Ley Foon Tan 
> Cc: Patrick Delaunay 
> Cc: Patrice Chotard 
> Signed-off-by: Andre Przywara 
> ---
>  arch/arm/mach-imx/spl.c| 2 +-
>  arch/arm/mach-k3/am6_init.c| 2 +-
>  arch/arm/mach-k3/j721e_init.c  | 2 +-
>  arch/arm/mach-omap2/boot-common.c  | 2 +-
>  arch/arm/mach-rockchip/spl.c   | 2 +-
>  arch/arm/mach-socfpga/spl_a10.c| 2 +-
>  arch/arm/mach-socfpga/spl_agilex.c | 2 +-
>  arch/arm/mach-socfpga/spl_gen5.c   | 2 +-
>  arch/arm/mach-socfpga/spl_s10.c| 2 +-
>  arch/arm/mach-stm32mp/spl.c| 2 +-
>  arch/arm/mach-uniphier/mmc-boot-mode.c | 5 +
>  common/spl/spl_mmc.c   | 4 ++--
>  include/spl.h  | 3 ++-
>  13 files changed, 15 insertions(+), 17 deletions(-)
> 

For SoCFPGA,
Reviewed-by: Ley Foon Tan 

Regards
Ley Foon


Re: [PATCH v2 16/21] spi: add spi controller support for MediaTek MT7620 SoC

2020-11-08 Thread Weijie Gao
On Mon, 2020-11-02 at 11:30 +0530, Jagan Teki wrote:
> On Fri, Oct 30, 2020 at 3:05 PM Weijie Gao  wrote:
> >
> > This patch adds spi controller support for MediaTek MT7620 SoC.
> >
> > The SPI controller supports two chip selects. These two chip selects are
> > implemented as two separate register groups, but they share the same bus
> > (DI/DO/CLK), only CS pins are dedicated for each register group.
> > Appearently these two register groups cannot operates simulataneously so
> > they are implemented as one controller.
> >
> > Signed-off-by: Weijie Gao 
> > ---
> > v2 changes: none
> > ---
> >  drivers/spi/Kconfig  |   7 +
> >  drivers/spi/Makefile |   1 +
> >  drivers/spi/mt7620_spi.c | 277 +++
> >  3 files changed, 285 insertions(+)
> >  create mode 100644 drivers/spi/mt7620_spi.c
> >
> > diff --git a/drivers/spi/Kconfig b/drivers/spi/Kconfig
> > index f7a9852565..ec50d843ef 100644
> > --- a/drivers/spi/Kconfig
> > +++ b/drivers/spi/Kconfig
> > @@ -202,6 +202,13 @@ config MSCC_BB_SPI
> >   Enable MSCC bitbang SPI driver. This driver can be used on
> >   MSCC SOCs.
> >
> > +config MT7620_SPI
> > +   bool "MediaTek MT7620 SPI driver"
> > +   depends on SOC_MT7620
> > +   help
> > + Enable the MT7620 SPI driver. This driver can be used to access
> > + generic SPI devices on MediaTek MT7620 SoC.
> > +
> >  config MT7621_SPI
> > bool "MediaTek MT7621 SPI driver"
> > depends on SOC_MT7628
> > diff --git a/drivers/spi/Makefile b/drivers/spi/Makefile
> > index d9b5bd9b79..bfd142d153 100644
> > --- a/drivers/spi/Makefile
> > +++ b/drivers/spi/Makefile
> > @@ -36,6 +36,7 @@ obj-$(CONFIG_MESON_SPIFC) += meson_spifc.o
> >  obj-$(CONFIG_MPC8XX_SPI) += mpc8xx_spi.o
> >  obj-$(CONFIG_MPC8XXX_SPI) += mpc8xxx_spi.o
> >  obj-$(CONFIG_MTK_SNFI_SPI) += mtk_snfi_spi.o
> > +obj-$(CONFIG_MT7620_SPI) += mt7620_spi.o
> >  obj-$(CONFIG_MT7621_SPI) += mt7621_spi.o
> >  obj-$(CONFIG_MSCC_BB_SPI) += mscc_bb_spi.o
> >  obj-$(CONFIG_MVEBU_A3700_SPI) += mvebu_a3700_spi.o
> > diff --git a/drivers/spi/mt7620_spi.c b/drivers/spi/mt7620_spi.c
> > new file mode 100644
> > index 00..c0b3d1d8eb
> > --- /dev/null
> > +++ b/drivers/spi/mt7620_spi.c
> > @@ -0,0 +1,277 @@
> > +// SPDX-License-Identifier: GPL-2.0
> > +/*
> > + * Copyright (C) 2020 MediaTek Inc.
> > + *
> > + * Author: Weijie Gao 
> > + *
> > + * Generic SPI driver for MediaTek MT7620 SoC
> > + */
> > +
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +
> > +#define MT7620_SPI_NUM_CS  2
> > +#define MT7620_SPI_MASTER1_OFF 0x00
> > +#define MT7620_SPI_MASTER2_OFF 0x40
> > +
> > +/* SPI_STAT */
> > +#define   SPI_BUSY BIT(0)
> > +
> > +/* SPI_CFG */
> > +#define   MSB_FIRSTBIT(8)
> > +#define   SPI_CLK_POL  BIT(6)
> > +#define   RX_CLK_EDGE  BIT(5)
> > +#define   TX_CLK_EDGE  BIT(4)
> > +#define   SPI_CLK_S0
> > +#define   SPI_CLK_MGENMASK(2, 0)
> > +
> > +/* SPI_CTL */
> > +#define   START_WR BIT(2)
> > +#define   START_RD BIT(1)
> > +#define   SPI_HIGH BIT(0)
> > +
> > +#define SPI_ARB0xf0
> > +#define   ARB_EN   BIT(31)
> > +
> > +struct mt7620_spi_master_regs {
> > +   u32 stat;
> > +   u32 reserved0[3];
> > +   u32 cfg;
> > +   u32 ctl;
> > +   u32 reserved1[2];
> > +   u32 data;
> > +};
> > +
> > +struct mt7620_spi {
> > +   void __iomem *regs;
> > +   struct mt7620_spi_master_regs *m[MT7620_SPI_NUM_CS];
> > +   unsigned int sys_freq;
> > +   u32 wait_us;
> > +   uint mode;
> > +   uint speed;
> > +};
> > +
> > +static void mt7620_spi_master_setup(struct mt7620_spi *ms, int cs)
> > +{
> > +   u32 rate, prescale, freq, tmo, cfg;
> > +
> > +   /* Calculate the clock divsior */
> > +   rate = DIV_ROUND_UP(ms->sys_freq, ms->speed);
> > +   rate = roundup_pow_of_two(rate);
> > +
> > +   prescale = ilog2(rate / 2);
> > +   if (prescale > 6)
> > +   prescale = 6;
> > +
> > +   /* Calculate the real clock, and usecs for one byte transaction */
> > +   freq = ms->sys_freq >> (prescale + 1);
> > +   tmo = DIV_ROUND_UP(8 * 100, freq);
> > +
> > +   /* 10 times tolerance plus 100us */
> > +   ms->wait_us = 10 * tmo + 100;
> 
> Replace the above magic numbers with meaningful macros.

ok.

> 
> > +
> > +   /* set SPI_CFG */
> > +   cfg = prescale << SPI_CLK_S;
> > +
> > +   switch (ms->mode & (SPI_CPOL | SPI_CPHA)) {
> > +   case SPI_MODE_0:
> > +   cfg |= TX_CLK_EDGE;
> > +   break;
> > +   case SPI_MODE_1:
> > +   cfg |= RX_CLK_EDGE;
> > +   break;
> > +   case SPI_MODE_2:
> > +   cfg |= SPI_CLK_POL | RX_CLK_EDGE;
> > +   break;
> > +   case SPI_MODE_3:
> > +

RE: [PATCH] mmc: display an error number to debug

2020-11-08 Thread Peng Fan
> Subject: [PATCH] mmc: display an error number to debug
> 
> It's useful to know an error number when it's debugging.
> 
> Signed-off-by: Jaehoon Chung 
> ---
>  drivers/mmc/mmc.c | 10 +-
>  1 file changed, 5 insertions(+), 5 deletions(-)
> 
> diff --git a/drivers/mmc/mmc.c b/drivers/mmc/mmc.c index
> 7783535d0953..2457c6fef97a 100644
> --- a/drivers/mmc/mmc.c
> +++ b/drivers/mmc/mmc.c
> @@ -2179,7 +2179,7 @@ static int mmc_select_mode_and_width(struct
> mmc *mmc, uint card_caps)
>   err = mmc_execute_tuning(mmc,
>mwt->tuning);
>   if (err) {
> - pr_debug("tuning failed\n");
> + pr_debug("tuning failed : 
> %d\n", err);
>   goto error;
>   }
>   }
> @@ -2200,7 +2200,7 @@ error:
>   }
>   }
> 
> - pr_err("unable to select a mode\n");
> + pr_err("unable to select a mode : %d\n", err);
> 
>   return -ENOTSUPP;
>  }
> @@ -2746,7 +2746,7 @@ static int mmc_power_on(struct mmc *mmc)
>   int ret = regulator_set_enable(mmc->vmmc_supply, true);
> 
>   if (ret) {
> - puts("Error enabling VMMC supply\n");
> + puts("Error enabling VMMC supply : %d\n", ret);
>   return ret;
>   }
>   }
> @@ -2762,7 +2762,7 @@ static int mmc_power_off(struct mmc *mmc)
>   int ret = regulator_set_enable(mmc->vmmc_supply, false);
> 
>   if (ret) {
> - pr_debug("Error disabling VMMC supply\n");
> + pr_debug("Error disabling VMMC supply : %d\n", ret);
>   return ret;
>   }
>   }
> @@ -2866,7 +2866,7 @@ retry:
> 
>   if (err) {
>  #if !defined(CONFIG_SPL_BUILD) ||
> defined(CONFIG_SPL_LIBCOMMON_SUPPORT)
> - pr_err("Card did not respond to voltage select!\n");
> + pr_err("Card did not respond to voltage select! : 
> %d\n", err);
>  #endif
>   return -EOPNOTSUPP;
>   }
> --

Reviewed-by: Peng Fan 


RE: [PATCH] mmc: check a return value about regulator's always-on

2020-11-08 Thread Peng Fan
> Subject: [PATCH] mmc: check a return value about regulator's always-on
> 
> Regulator can be set to "always-on".
> It's not error about enable/disable. It needs to check about its condition.
> 
> Signed-off-by: Jaehoon Chung 
> ---
>  drivers/mmc/mmc.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/mmc/mmc.c b/drivers/mmc/mmc.c index
> 2457c6fef97a..9526d27976c7 100644
> --- a/drivers/mmc/mmc.c
> +++ b/drivers/mmc/mmc.c
> @@ -2745,7 +2745,7 @@ static int mmc_power_on(struct mmc *mmc)
>   if (mmc->vmmc_supply) {
>   int ret = regulator_set_enable(mmc->vmmc_supply, true);
> 
> - if (ret) {
> + if (ret && ret != -EACCES) {
>   puts("Error enabling VMMC supply : %d\n", ret);
>   return ret;
>   }
> @@ -2761,7 +2761,7 @@ static int mmc_power_off(struct mmc *mmc)
>   if (mmc->vmmc_supply) {
>   int ret = regulator_set_enable(mmc->vmmc_supply, false);
> 
> - if (ret) {
> + if (ret && ret != -EACCES) {
>   pr_debug("Error disabling VMMC supply : %d\n", ret);
>   return ret;
>   }
> --

Reviewed-by: Peng Fan 


Re: [PATCH v2 14/21] watchdog: add watchdog driver for MediaTek MT7620 SoC

2020-11-08 Thread Weijie Gao
On Mon, 2020-11-02 at 11:32 +0530, Jagan Teki wrote:
> On Fri, Oct 30, 2020 at 3:04 PM Weijie Gao  wrote:
> >
> > This patch adds watchdog support for the Mediatek MT7620 SoC
> >
> > Signed-off-by: Weijie Gao 
> > ---
> > v2 changes: add expire_now
> > ---
> >  drivers/watchdog/Kconfig  |   7 ++
> >  drivers/watchdog/Makefile |   1 +
> >  drivers/watchdog/mt7620_wdt.c | 132 ++
> >  3 files changed, 140 insertions(+)
> >  create mode 100644 drivers/watchdog/mt7620_wdt.c
> >
> > diff --git a/drivers/watchdog/Kconfig b/drivers/watchdog/Kconfig
> > index 210d9f8093..35d078caa0 100644
> > --- a/drivers/watchdog/Kconfig
> > +++ b/drivers/watchdog/Kconfig
> > @@ -124,6 +124,13 @@ config WDT_MPC8xx
> > help
> >   Select this to enable mpc8xx watchdog timer
> >
> > +config WDT_MT7620
> > +   bool "MediaTek MT7620 watchdog timer support"
> > +   depends on WDT && SOC_MT7620
> > +   help
> > + Select this to enable watchdog timer on MediaTek MT7620 and 
> > earlier
> > + SoC chips.
> > +
> >  config WDT_MT7621
> > bool "MediaTek MT7621 watchdog timer support"
> > depends on WDT && SOC_MT7628
> > diff --git a/drivers/watchdog/Makefile b/drivers/watchdog/Makefile
> > index 01b8231f2b..825b50e626 100644
> > --- a/drivers/watchdog/Makefile
> > +++ b/drivers/watchdog/Makefile
> > @@ -24,6 +24,7 @@ obj-$(CONFIG_WDT_CORTINA) += cortina_wdt.o
> >  obj-$(CONFIG_WDT_ORION) += orion_wdt.o
> >  obj-$(CONFIG_WDT_CDNS) += cdns_wdt.o
> >  obj-$(CONFIG_WDT_MPC8xx) += mpc8xx_wdt.o
> > +obj-$(CONFIG_WDT_MT7620) += mt7620_wdt.o
> >  obj-$(CONFIG_WDT_MT7621) += mt7621_wdt.o
> >  obj-$(CONFIG_WDT_MTK) += mtk_wdt.o
> >  obj-$(CONFIG_WDT_OCTEONTX) += octeontx_wdt.o
> > diff --git a/drivers/watchdog/mt7620_wdt.c b/drivers/watchdog/mt7620_wdt.c
> > new file mode 100644
> > index 00..2643167f8f
> > --- /dev/null
> > +++ b/drivers/watchdog/mt7620_wdt.c
> > @@ -0,0 +1,132 @@
> > +// SPDX-License-Identifier: GPL-2.0
> > +/*
> > + * Copyright (C) 2020 MediaTek Inc.
> > + *
> > + * Author:  Weijie Gao 
> > + *
> > + * Watchdog timer for MT7620 and earlier SoCs
> > + */
> > +
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +
> > +struct mt7620_wdt {
> > +   void __iomem *regs;
> > +   u64 timeout;
> > +};
> > +
> > +#define TIMER_FREQ 4000
> > +#define TIMER_MASK 0x
> > +#define TIMER_PRESCALE 65536
> > +
> > +#define TIMER_LOAD 0x00
> > +#define TIMER_CTL  0x08
> > +
> > +#define TIMER_ENABLE   BIT(7)
> > +#define TIMER_MODE_SHIFT   4
> > +#define   TIMER_MODE_WDT   3
> > +#define TIMER_PRESCALE_SHIFT   0
> > +#define   TIMER_PRESCALE_65536 15
> > +
> > +static void mt7620_wdt_ping(struct mt7620_wdt *priv)
> > +{
> > +   u64 val;
> > +
> > +   val = (TIMER_FREQ / TIMER_PRESCALE) * priv->timeout;
> > +   do_div(val, 1000);
> > +
> > +   if (val > TIMER_MASK)
> > +   val = TIMER_MASK;
> > +
> > +   writel(val, priv->regs + TIMER_LOAD);
> > +}
> > +
> > +static int mt7620_wdt_start(struct udevice *dev, u64 ms, ulong flags)
> > +{
> > +   struct mt7620_wdt *priv = dev_get_priv(dev);
> > +
> > +   priv->timeout = ms;
> > +   mt7620_wdt_ping(priv);
> > +
> > +   writel(TIMER_ENABLE | (TIMER_MODE_WDT << TIMER_MODE_SHIFT) |
> > +  (TIMER_PRESCALE_65536 << TIMER_PRESCALE_SHIFT),
> > +  priv->regs + TIMER_CTL);
> > +
> > +   return 0;
> > +}
> > +
> > +static int mt7620_wdt_stop(struct udevice *dev)
> > +{
> > +   struct mt7620_wdt *priv = dev_get_priv(dev);
> > +
> > +   mt7620_wdt_ping(priv);
> > +
> > +   clrbits_32(priv->regs + TIMER_CTL, TIMER_ENABLE);
> > +
> > +   return 0;
> > +}
> > +
> > +static int mt7620_wdt_reset(struct udevice *dev)
> > +{
> > +   struct mt7620_wdt *priv = dev_get_priv(dev);
> > +
> > +   mt7620_wdt_ping(priv);
> > +
> > +   return 0;
> > +}
> > +
> > +static int mt7620_wdt_expire_now(struct udevice *dev, ulong flags)
> > +{
> > +   struct mt7620_wdt *priv = dev_get_priv(dev);
> > +
> > +   mt7620_wdt_start(dev, 1, flags);
> > +
> > +   /* 0 will disable the timer, so use 1 instead */
> > +   writel(1, priv->regs + TIMER_LOAD);
> 
> Better replace the magic number with macro.
> Otherwise,

this line means load timer with value 1. Since the timer is a countdown,
1 is the smallest value to cause a wdt timeout.

> 
> Reviewed-by: Jagan Teki 



Re: [PATCH v2 17/21] phy: add USB PHY driver for MediaTek MT7620 SoC

2020-11-08 Thread Weijie Gao
On Mon, 2020-11-02 at 11:41 +0530, Jagan Teki wrote:
> On Fri, Oct 30, 2020 at 3:05 PM Weijie Gao  wrote:
> >
> > This patch adds USB PHY driver for MediaTek MT7620 SoC
> >
> > Signed-off-by: Weijie Gao 
> > ---
> > v2 changes: none
> > ---
> >  drivers/phy/Kconfig  |   7 +++
> >  drivers/phy/Makefile |   1 +
> >  drivers/phy/mt7620-usb-phy.c | 113 +++
> >  3 files changed, 121 insertions(+)
> >  create mode 100644 drivers/phy/mt7620-usb-phy.c
> >
> > diff --git a/drivers/phy/Kconfig b/drivers/phy/Kconfig
> > index d12a6b02ad..ab638f0e7d 100644
> > --- a/drivers/phy/Kconfig
> > +++ b/drivers/phy/Kconfig
> > @@ -218,6 +218,13 @@ config KEYSTONE_USB_PHY
> >
> >   This PHY is found on some Keystone (K2) devices supporting USB.
> >
> > +config MT7620_USB_PHY
> > +   bool "MediaTek MT7620 USB PHY support"
> > +   depends on PHY
> > +   depends on SOC_MT7620
> > +   help
> > +  Support the intergated USB PHY in MediaTek MT7620 SoC
> > +
> >  config MT76X8_USB_PHY
> > bool "MediaTek MT76x8 (7628/88) USB PHY support"
> > depends on PHY
> > diff --git a/drivers/phy/Makefile b/drivers/phy/Makefile
> > index 45a7fe5b56..6b3761b8c8 100644
> > --- a/drivers/phy/Makefile
> > +++ b/drivers/phy/Makefile
> > @@ -24,6 +24,7 @@ obj-$(CONFIG_MESON_G12A_USB_PHY) += meson-g12a-usb2.o 
> > meson-g12a-usb3-pcie.o
> >  obj-$(CONFIG_MSM8916_USB_PHY) += msm8916-usbh-phy.o
> >  obj-$(CONFIG_OMAP_USB2_PHY) += omap-usb2-phy.o
> >  obj-$(CONFIG_KEYSTONE_USB_PHY) += keystone-usb-phy.o
> > +obj-$(CONFIG_MT7620_USB_PHY) += mt7620-usb-phy.o
> >  obj-$(CONFIG_MT76X8_USB_PHY) += mt76x8-usb-phy.o
> >  obj-$(CONFIG_PHY_DA8XX_USB) += phy-da8xx-usb.o
> >  obj-$(CONFIG_PHY_MTK_TPHY) += phy-mtk-tphy.o
> > diff --git a/drivers/phy/mt7620-usb-phy.c b/drivers/phy/mt7620-usb-phy.c
> > new file mode 100644
> > index 00..59ac32f327
> > --- /dev/null
> > +++ b/drivers/phy/mt7620-usb-phy.c
> > @@ -0,0 +1,113 @@
> > +// SPDX-License-Identifier: GPL-2.0
> > +/*
> > + * Copyright (C) 2020 MediaTek Inc. All Rights Reserved.
> > + *
> > + * Author: Weijie Gao 
> > + */
> > +
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +
> > +struct mt7620_usb_phy {
> > +   struct udevice *dev;
> 
> Why this explicit dev required here? generic_phy_get_ calls will assign 
> phy->dev

I didn't notice that. This will be modified in next series.



[PATCH] mmc: meson_gx_mmc: change a clock phase to stable value

2020-11-08 Thread Jaehoon Chung
Core clock phase value is changed from 180' to 270'.
It's more stable than before.
- Odroidn-N2/C4 : Working fine with 52MHz
- VIM3 : Working fine with 52MHz

Before this patch, Odroid-C4 doesn't work fine with 52MHz.

Signed-off-by: Jaehoon Chung 
---
 drivers/mmc/meson_gx_mmc.c | 14 ++
 1 file changed, 10 insertions(+), 4 deletions(-)

diff --git a/drivers/mmc/meson_gx_mmc.c b/drivers/mmc/meson_gx_mmc.c
index 719dd1e5e570..7c60e0566560 100644
--- a/drivers/mmc/meson_gx_mmc.c
+++ b/drivers/mmc/meson_gx_mmc.c
@@ -52,10 +52,16 @@ static void meson_mmc_config_clock(struct mmc *mmc)
}
clk_div = DIV_ROUND_UP(clk, mmc->clock);
 
-   /* 180 phase core clock */
-   meson_mmc_clk |= CLK_CO_PHASE_180;
-
-   /* 180 phase tx clock */
+   /*
+* Clock Phase needs to set a proper value.
+* It can be changed to other value.
+* Because CORE : 270' Phase and TX : 0' Phase are stable,
+* set to them by default.
+*/
+   /* Core Clock Phase */
+   meson_mmc_clk |= CLK_CO_PHASE_270;
+
+   /* TX Clock Phase */
meson_mmc_clk |= CLK_TX_PHASE_000;
 
/* clock settings */
-- 
2.29.0



Unit test is not available out of sandbox config

2020-11-08 Thread Kever Yang

Hi Simon,

    Seems like the Unit test is only available with sandbox now, 
because of the bloblist test depends on the header in sandbox arch,


see the build error:

  CC  test/bloblist.o
  CC  test/env/attr.o
  CC  test/overlay/cmd_ut_overlay.o
  LD  drivers/fastboot/built-in.o
  LD  drivers/built-in.o
test/bloblist.c:10:23: fatal error: asm/state.h: No such file or directory
 #include 
   ^
compilation terminated.
  LD  test/log/built-in.o
make[1]: *** [scripts/Makefile.build:265: test/bloblist.o] Error 1
make[1]: *** Waiting for unfinished jobs


Thanks,

- Kever





[PATCH 4/5] patman: Drop tools.ToChar() and ToChars()

2020-11-08 Thread Simon Glass
This is useful anymore, since we always want to call chr() in Python 3.
Drop it and adjust callers to use chr().

Also drop ToChars() which is no-longer used.

Signed-off-by: Simon Glass 
---

 tools/dtoc/fdt.py  |  8 
 tools/dtoc/test_fdt.py |  2 +-
 tools/patman/tools.py  | 23 ---
 3 files changed, 5 insertions(+), 28 deletions(-)

diff --git a/tools/dtoc/fdt.py b/tools/dtoc/fdt.py
index cb365ca094a..4a78c737252 100644
--- a/tools/dtoc/fdt.py
+++ b/tools/dtoc/fdt.py
@@ -87,9 +87,9 @@ def BytesToValue(data):
 return Type.STRING, [s.decode() for s in strings[:-1]]
 if size % 4:
 if size == 1:
-return Type.BYTE, tools.ToChar(data[0])
+return Type.BYTE, chr(data[0])
 else:
-return Type.BYTE, [tools.ToChar(ch) for ch in list(data)]
+return Type.BYTE, [chr(ch) for ch in list(data)]
 val = []
 for i in range(0, size, 4):
 val.append(data[i:i + 4])
@@ -152,9 +152,9 @@ class Prop:
 if type(self.value) == list:
 new_value = []
 for val in self.value:
-new_value += [tools.ToChar(by) for by in val]
+new_value += [chr(by) for by in val]
 else:
-new_value = [tools.ToChar(by) for by in self.value]
+new_value = [chr(by) for by in self.value]
 self.value = new_value
 self.type = newprop.type
 
diff --git a/tools/dtoc/test_fdt.py b/tools/dtoc/test_fdt.py
index 10e7f33a595..dc6943f7337 100755
--- a/tools/dtoc/test_fdt.py
+++ b/tools/dtoc/test_fdt.py
@@ -46,7 +46,7 @@ def _GetPropertyValue(dtb, node, prop_name):
 # Add 12, which is sizeof(struct fdt_property), to get to start of data
 offset = prop.GetOffset() + 12
 data = dtb.GetContents()[offset:offset + len(prop.value)]
-return prop, [tools.ToChar(x) for x in data]
+return prop, [chr(x) for x in data]
 
 
 class TestFdt(unittest.TestCase):
diff --git a/tools/patman/tools.py b/tools/patman/tools.py
index 7cd58031e78..00c7013924d 100644
--- a/tools/patman/tools.py
+++ b/tools/patman/tools.py
@@ -423,29 +423,6 @@ def GetBytes(byte, size):
 """
 return bytes([byte]) * size
 
-def ToChar(byte):
-"""Convert a byte to a character
-
-This is useful because in Python 2 bytes is an alias for str, but in
-Python 3 they are separate types. This function converts an ASCII value to
-a value with the appropriate type in either case.
-
-Args:
-byte: A byte or str value
-"""
-return chr(byte) if type(byte) != str else byte
-
-def ToChars(byte_list):
-"""Convert a list of bytes to a str/bytes type
-
-Args:
-byte_list: List of ASCII values representing the string
-
-Returns:
-string made by concatenating all the ASCII values
-"""
-return ''.join([chr(byte) for byte in byte_list])
-
 def ToBytes(string):
 """Convert a str type into a bytes type
 
-- 
2.29.2.222.g5d2a92d10f8-goog



[PATCH 3/5] patman: Drop tools.ToByte()

2020-11-08 Thread Simon Glass
This is not needed in Python 3. Drop it.

Signed-off-by: Simon Glass 
---

 tools/binman/elf.py|  6 +++---
 tools/dtoc/dtb_platdata.py |  2 +-
 tools/patman/tools.py  | 15 ---
 3 files changed, 4 insertions(+), 19 deletions(-)

diff --git a/tools/binman/elf.py b/tools/binman/elf.py
index 5e566e56cbf..249074a334a 100644
--- a/tools/binman/elf.py
+++ b/tools/binman/elf.py
@@ -158,9 +158,9 @@ def MakeElf(elf_fname, text, data):
 
 # Spilt the text into two parts so that we can make the entry point two
 # bytes after the start of the text section
-text_bytes1 = ['\t.byte\t%#x' % tools.ToByte(byte) for byte in text[:2]]
-text_bytes2 = ['\t.byte\t%#x' % tools.ToByte(byte) for byte in text[2:]]
-data_bytes = ['\t.byte\t%#x' % tools.ToByte(byte) for byte in data]
+text_bytes1 = ['\t.byte\t%#x' % byte for byte in text[:2]]
+text_bytes2 = ['\t.byte\t%#x' % byte for byte in text[2:]]
+data_bytes = ['\t.byte\t%#x' % byte for byte in data]
 with open(s_file, 'w') as fd:
 print('''/* Auto-generated C program to produce an ELF file for 
testing */
 
diff --git a/tools/dtoc/dtb_platdata.py b/tools/dtoc/dtb_platdata.py
index ee98010423c..0ef245397a9 100644
--- a/tools/dtoc/dtb_platdata.py
+++ b/tools/dtoc/dtb_platdata.py
@@ -110,7 +110,7 @@ def get_value(ftype, value):
 return '%#x' % fdt_util.fdt32_to_cpu(value)
 elif ftype == fdt.Type.BYTE:
 ch = value[0]
-return '%#x' % ord(ch) if type(ch) == str else ch
+return '%#x' % (ord(ch) if type(ch) == str else ch)
 elif ftype == fdt.Type.STRING:
 # Handle evil ACPI backslashes by adding another backslash before them.
 # So "\\_SB.GPO0" in the device tree effectively stays like that in C
diff --git a/tools/patman/tools.py b/tools/patman/tools.py
index 55ba1e9c985..7cd58031e78 100644
--- a/tools/patman/tools.py
+++ b/tools/patman/tools.py
@@ -423,21 +423,6 @@ def GetBytes(byte, size):
 """
 return bytes([byte]) * size
 
-def ToByte(ch):
-"""Convert a character to an ASCII value
-
-This is useful because in Python 2 bytes is an alias for str, but in
-Python 3 they are separate types. This function converts the argument to
-an ASCII value in either case.
-
-Args:
-ch: A string (Python 2) or byte (Python 3) value
-
-Returns:
-integer ASCII value for ch
-"""
-return ord(ch) if type(ch) == str else ch
-
 def ToChar(byte):
 """Convert a byte to a character
 
-- 
2.29.2.222.g5d2a92d10f8-goog



[PATCH 0/5] patman: Tidy up some hangovers from Python 2

2020-11-08 Thread Simon Glass
Various functions were used to deal with the differences between Python
2 and 3. These can be removed now that Python 2 is not supported.

Also tidy up the code style in dtb_platdata.py


Simon Glass (5):
  fdt: Use an Enum for the data type
  patman: Drop unicode helper functions
  patman: Drop tools.ToByte()
  patman: Drop tools.ToChar() and ToChars()
  dtoc: Tidy up Python style in dtb_platdata

 tools/binman/elf.py|  6 +--
 tools/binman/etype/fmap.py |  2 +-
 tools/binman/fdt_test.py   | 14 +++---
 tools/binman/fmap_util.py  |  3 +-
 tools/dtoc/dtb_platdata.py | 96 ++
 tools/dtoc/fdt.py  | 58 +++
 tools/dtoc/test_dtoc.py| 10 ++--
 tools/dtoc/test_fdt.py | 34 +++---
 tools/patman/func_test.py  | 16 +++
 tools/patman/gitutil.py|  3 +-
 tools/patman/series.py |  4 +-
 tools/patman/settings.py   |  5 +-
 tools/patman/tools.py  | 85 ++---
 13 files changed, 140 insertions(+), 196 deletions(-)

-- 
2.29.2.222.g5d2a92d10f8-goog



[PATCH 1/5] fdt: Use an Enum for the data type

2020-11-08 Thread Simon Glass
Use an Enum instead of the current ad-hoc constants, so that there is a
data type associated with each 'type' value.

Signed-off-by: Simon Glass 
---

 tools/binman/fdt_test.py   | 14 +-
 tools/dtoc/dtb_platdata.py | 26 +-
 tools/dtoc/fdt.py  | 54 +-
 tools/dtoc/test_dtoc.py| 10 +++
 tools/dtoc/test_fdt.py | 32 +++---
 5 files changed, 77 insertions(+), 59 deletions(-)

diff --git a/tools/binman/fdt_test.py b/tools/binman/fdt_test.py
index c491d40e9ee..3e12540f62e 100644
--- a/tools/binman/fdt_test.py
+++ b/tools/binman/fdt_test.py
@@ -50,37 +50,37 @@ class TestFdt(unittest.TestCase):
 self.assertEquals('me.bin', val)
 
 prop = node.props['intval']
-self.assertEquals(fdt.TYPE_INT, prop.type)
+self.assertEquals(fdt.Type.INT, prop.type)
 self.assertEquals(3, fdt_util.GetInt(node, 'intval'))
 
 prop = node.props['intarray']
-self.assertEquals(fdt.TYPE_INT, prop.type)
+self.assertEquals(fdt.Type.INT, prop.type)
 self.assertEquals(list, type(prop.value))
 self.assertEquals(2, len(prop.value))
 self.assertEquals([5, 6],
   [fdt_util.fdt32_to_cpu(val) for val in prop.value])
 
 prop = node.props['byteval']
-self.assertEquals(fdt.TYPE_BYTE, prop.type)
+self.assertEquals(fdt.Type.BYTE, prop.type)
 self.assertEquals(chr(8), prop.value)
 
 prop = node.props['bytearray']
-self.assertEquals(fdt.TYPE_BYTE, prop.type)
+self.assertEquals(fdt.Type.BYTE, prop.type)
 self.assertEquals(list, type(prop.value))
 self.assertEquals(str, type(prop.value[0]))
 self.assertEquals(3, len(prop.value))
 self.assertEquals([chr(1), '#', '4'], prop.value)
 
 prop = node.props['longbytearray']
-self.assertEquals(fdt.TYPE_INT, prop.type)
+self.assertEquals(fdt.Type.INT, prop.type)
 self.assertEquals(0x090a0b0c, fdt_util.GetInt(node, 'longbytearray'))
 
 prop = node.props['stringval']
-self.assertEquals(fdt.TYPE_STRING, prop.type)
+self.assertEquals(fdt.Type.STRING, prop.type)
 self.assertEquals('message2', fdt_util.GetString(node, 'stringval'))
 
 prop = node.props['stringarray']
-self.assertEquals(fdt.TYPE_STRING, prop.type)
+self.assertEquals(fdt.Type.STRING, prop.type)
 self.assertEquals(list, type(prop.value))
 self.assertEquals(3, len(prop.value))
 self.assertEquals(['another', 'multi-word', 'message'], prop.value)
diff --git a/tools/dtoc/dtb_platdata.py b/tools/dtoc/dtb_platdata.py
index 9b27aecc140..7926fe3a792 100644
--- a/tools/dtoc/dtb_platdata.py
+++ b/tools/dtoc/dtb_platdata.py
@@ -35,13 +35,13 @@ PROP_IGNORE_LIST = [
 'u-boot,dm-spl',
 ]
 
-# C type declarations for the tyues we support
+# C type declarations for the types we support
 TYPE_NAMES = {
-fdt.TYPE_INT: 'fdt32_t',
-fdt.TYPE_BYTE: 'unsigned char',
-fdt.TYPE_STRING: 'const char *',
-fdt.TYPE_BOOL: 'bool',
-fdt.TYPE_INT64: 'fdt64_t',
+fdt.Type.INT: 'fdt32_t',
+fdt.Type.BYTE: 'unsigned char',
+fdt.Type.STRING: 'const char *',
+fdt.Type.BOOL: 'bool',
+fdt.Type.INT64: 'fdt64_t',
 }
 
 STRUCT_PREFIX = 'dtd_'
@@ -106,17 +106,17 @@ def get_value(ftype, value):
 type: Data type (fdt_util)
 value: Data value, as a string of bytes
 """
-if ftype == fdt.TYPE_INT:
+if ftype == fdt.Type.INT:
 return '%#x' % fdt_util.fdt32_to_cpu(value)
-elif ftype == fdt.TYPE_BYTE:
+elif ftype == fdt.Type.BYTE:
 return '%#x' % tools.ToByte(value[0])
-elif ftype == fdt.TYPE_STRING:
+elif ftype == fdt.Type.STRING:
 # Handle evil ACPI backslashes by adding another backslash before them.
 # So "\\_SB.GPO0" in the device tree effectively stays like that in C
 return '"%s"' % value.replace('\\', '')
-elif ftype == fdt.TYPE_BOOL:
+elif ftype == fdt.Type.BOOL:
 return 'true'
-elif ftype == fdt.TYPE_INT64:
+elif ftype == fdt.Type.INT64:
 return '%#x' % value
 
 def get_compat_name(node):
@@ -435,7 +435,7 @@ class DtbPlatdata(object):
 na, ns = self.get_num_cells(node)
 total = na + ns
 
-if reg.type != fdt.TYPE_INT:
+if reg.type != fdt.Type.INT:
 raise ValueError("Node '%s' reg property is not an int" %
  node.name)
 if len(reg.value) % total:
@@ -445,7 +445,7 @@ class DtbPlatdata(object):
 reg.na = na
 reg.ns = ns
 if na != 1 or ns != 1:
-reg.type = fdt.TYPE_INT64
+reg.type = fdt.Type.INT64
 i = 0
 new_value = []
 val = reg.value
diff --git a/tools/dtoc/fdt.py b/tools/dtoc/fdt.py
index 03b86773d5f..cb365ca094a 100644
--- a/too

[PATCH 2/5] patman: Drop unicode helper functions

2020-11-08 Thread Simon Glass
We don't need these now that everything uses Python 3. Remove them and
the extra code in GetBytes() and ToBytes() too.

Signed-off-by: Simon Glass 
---

 tools/binman/etype/fmap.py |  2 +-
 tools/binman/fmap_util.py  |  3 +--
 tools/dtoc/dtb_platdata.py |  3 ++-
 tools/patman/func_test.py  | 16 +
 tools/patman/gitutil.py|  3 +--
 tools/patman/series.py |  4 +---
 tools/patman/settings.py   |  5 ++--
 tools/patman/tools.py  | 47 +++---
 8 files changed, 17 insertions(+), 66 deletions(-)

diff --git a/tools/binman/etype/fmap.py b/tools/binman/etype/fmap.py
index 3e9b815d119..fe81c6f64a5 100644
--- a/tools/binman/etype/fmap.py
+++ b/tools/binman/etype/fmap.py
@@ -52,7 +52,7 @@ class Entry_fmap(Entry):
 if pos is not None:
 pos -= entry.section.GetRootSkipAtStart()
 areas.append(fmap_util.FmapArea(pos or 0, entry.size or 0,
-tools.FromUnicode(entry.name), 0))
+entry.name, 0))
 
 entries = self.GetImage().GetEntries()
 areas = []
diff --git a/tools/binman/fmap_util.py b/tools/binman/fmap_util.py
index 25fe60a9cc3..b03fc28fbb4 100644
--- a/tools/binman/fmap_util.py
+++ b/tools/binman/fmap_util.py
@@ -111,8 +111,7 @@ def EncodeFmap(image_size, name, areas):
 ConvertName(names, params)
 return struct.pack(fmt, *params)
 
-values = FmapHeader(FMAP_SIGNATURE, 1, 0, 0, image_size,
-tools.FromUnicode(name), len(areas))
+values = FmapHeader(FMAP_SIGNATURE, 1, 0, 0, image_size, name, len(areas))
 blob = _FormatBlob(FMAP_HEADER_FORMAT, FMAP_HEADER_NAMES, values)
 for area in areas:
 blob += _FormatBlob(FMAP_AREA_FORMAT, FMAP_AREA_NAMES, area)
diff --git a/tools/dtoc/dtb_platdata.py b/tools/dtoc/dtb_platdata.py
index 7926fe3a792..ee98010423c 100644
--- a/tools/dtoc/dtb_platdata.py
+++ b/tools/dtoc/dtb_platdata.py
@@ -109,7 +109,8 @@ def get_value(ftype, value):
 if ftype == fdt.Type.INT:
 return '%#x' % fdt_util.fdt32_to_cpu(value)
 elif ftype == fdt.Type.BYTE:
-return '%#x' % tools.ToByte(value[0])
+ch = value[0]
+return '%#x' % ord(ch) if type(ch) == str else ch
 elif ftype == fdt.Type.STRING:
 # Handle evil ACPI backslashes by adding another backslash before them.
 # So "\\_SB.GPO0" in the device tree effectively stays like that in C
diff --git a/tools/patman/func_test.py b/tools/patman/func_test.py
index 810af9c6042..3a229be1ba8 100644
--- a/tools/patman/func_test.py
+++ b/tools/patman/func_test.py
@@ -199,17 +199,14 @@ class TestFunctional(unittest.TestCase):
 while 'Cc:' in lines[line]:
 line += 1
 self.assertEqual('To:u-boot@lists.denx.de', lines[line])
-self.assertEqual('Cc:%s' % tools.FromUnicode(stefan),
- lines[line + 1])
+self.assertEqual('Cc:%s' % stefan, lines[line + 1])
 self.assertEqual('Version:  3', lines[line + 2])
 self.assertEqual('Prefix:\t  RFC', lines[line + 3])
 self.assertEqual('Cover: 4 lines', lines[line + 4])
 line += 5
 self.assertEqual('  Cc:  %s' % fred, lines[line + 0])
-self.assertEqual('  Cc:  %s' % tools.FromUnicode(ed),
- lines[line + 1])
-self.assertEqual('  Cc:  %s' % tools.FromUnicode(mel),
- lines[line + 2])
+self.assertEqual('  Cc:  %s' % ed, lines[line + 1])
+self.assertEqual('  Cc:  %s' % mel, lines[line + 2])
 self.assertEqual('  Cc:  %s' % rick, lines[line + 3])
 expected = ('Git command: git send-email --annotate '
 '--in-reply-to="%s" --to "u-boot@lists.denx.de" '
@@ -217,12 +214,11 @@ class TestFunctional(unittest.TestCase):
 % (in_reply_to, stefan, sys.argv[0], cc_file, cover_fname,
' '.join(args)))
 line += 4
-self.assertEqual(expected, tools.ToUnicode(lines[line]))
+self.assertEqual(expected, lines[line])
 
-self.assertEqual(('%s %s\0%s' % (args[0], rick, stefan)),
- tools.ToUnicode(cc_lines[0]))
+self.assertEqual(('%s %s\0%s' % (args[0], rick, stefan)), cc_lines[0])
 self.assertEqual(('%s %s\0%s\0%s\0%s' % (args[1], fred, ed, rick,
- stefan)), tools.ToUnicode(cc_lines[1]))
+ stefan)), cc_lines[1])
 
 expected = '''
 This is a test of how the cover
diff --git a/tools/patman/gitutil.py b/tools/patman/gitutil.py
index 27a0a9fbc1f..1ac5a6aacda 100644
--- a/tools/patman/gitutil.py
+++ b/tools/patman/gitutil.py
@@ -379,7 +379,6 @@ def BuildEmailList(in_list, tag=None, alias=None, 
raise_on_error=True):
 raw += LookupEmail(item, alias, raise_on_error=raise_on_error)
  

[PATCH 5/5] dtoc: Tidy up Python style in dtb_platdata

2020-11-08 Thread Simon Glass
Update this, mostly to add comments for argument and return types. It is
probably still too early to use type hinting since it was introduced in
3.5.

Signed-off-by: Simon Glass 
---

 tools/dtoc/dtb_platdata.py | 71 ++
 1 file changed, 42 insertions(+), 29 deletions(-)

diff --git a/tools/dtoc/dtb_platdata.py b/tools/dtoc/dtb_platdata.py
index 0ef245397a9..6b10eabafb9 100644
--- a/tools/dtoc/dtb_platdata.py
+++ b/tools/dtoc/dtb_platdata.py
@@ -9,6 +9,8 @@
 
 This supports converting device tree data to C structures definitions and
 static data.
+
+See doc/driver-model/of-plat.rst for more informaiton
 """
 
 import collections
@@ -19,9 +21,9 @@ import sys
 
 from dtoc import fdt
 from dtoc import fdt_util
-from patman import tools
 
-# When we see these properties we ignore them - i.e. do not create a structure 
member
+# When we see these properties we ignore them - i.e. do not create a structure
+# member
 PROP_IGNORE_LIST = [
 '#address-cells',
 '#gpio-cells',
@@ -69,9 +71,9 @@ def conv_name_to_c(name):
 (400ms for 1m calls versus 1000ms for the 're' version).
 
 Args:
-name:   Name to convert
+name (str): Name to convert
 Return:
-String containing the C version of this name
+str: String containing the C version of this name
 """
 new = name.replace('@', '_at_')
 new = new.replace('-', '_')
@@ -83,11 +85,11 @@ def tab_to(num_tabs, line):
 """Append tabs to a line of text to reach a tab stop.
 
 Args:
-num_tabs: Tab stop to obtain (0 = column 0, 1 = column 8, etc.)
-line: Line of text to append to
+num_tabs (int): Tab stop to obtain (0 = column 0, 1 = column 8, etc.)
+line (str): Line of text to append to
 
 Returns:
-line with the correct number of tabs appeneded. If the line already
+str: line with the correct number of tabs appeneded. If the line 
already
 extends past that tab stop then a single space is appended.
 """
 if len(line) >= num_tabs * 8:
@@ -103,28 +105,31 @@ def get_value(ftype, value):
 For booleans this return 'true'
 
 Args:
-type: Data type (fdt_util)
-value: Data value, as a string of bytes
+ftype (fdt.Type): Data type (fdt_util)
+value (bytes): Data value, as a string of bytes
+
+Returns:
+str: String representation of the value
 """
 if ftype == fdt.Type.INT:
 return '%#x' % fdt_util.fdt32_to_cpu(value)
 elif ftype == fdt.Type.BYTE:
 ch = value[0]
-return '%#x' % (ord(ch) if type(ch) == str else ch)
+return '%#x' % (ord(ch) if isinstance(ch, str) else ch)
 elif ftype == fdt.Type.STRING:
 # Handle evil ACPI backslashes by adding another backslash before them.
 # So "\\_SB.GPO0" in the device tree effectively stays like that in C
 return '"%s"' % value.replace('\\', '')
 elif ftype == fdt.Type.BOOL:
 return 'true'
-elif ftype == fdt.Type.INT64:
+else:  # ftype == fdt.Type.INT64:
 return '%#x' % value
 
 def get_compat_name(node):
 """Get the node's list of compatible string as a C identifiers
 
 Args:
-node: Node object to check
+node (fdt.Node): Node object to check
 Return:
 List of C identifiers for all the compatible strings
 """
@@ -213,7 +218,7 @@ class DtbPlatdata(object):
 file.
 
 Args:
-fname: Filename to send output to, or '-' for stdout
+fname (str): Filename to send output to, or '-' for stdout
 """
 if fname == '-':
 self._outfile = sys.stdout
@@ -224,7 +229,7 @@ class DtbPlatdata(object):
 """Output a string to the output file
 
 Args:
-line: String to output
+line (str): String to output
 """
 self._outfile.write(line)
 
@@ -232,7 +237,7 @@ class DtbPlatdata(object):
 """Buffer up a string to send later
 
 Args:
-line: String to add to our 'buffer' list
+line (str): String to add to our 'buffer' list
 """
 self._lines.append(line)
 
@@ -240,7 +245,7 @@ class DtbPlatdata(object):
 """Get the contents of the output buffer, and clear it
 
 Returns:
-The output buffer, which is then cleared for future use
+list(str): The output buffer, which is then cleared for future use
 """
 lines = self._lines
 self._lines = []
@@ -263,9 +268,14 @@ class DtbPlatdata(object):
 or not. As an interim measure, use a list of known property names.
 
 Args:
-prop: Prop object to check
-Return:
-Number of argument cells is this is a phandle, else None
+prop (fdt.Prop): Prop object to check
+node_name (str): Node name, only used for raising an error
+Returns:
+int or None: Number of argument cell

[PATCH 0/3] sandbox: Minor improvements to serial driver

2020-11-08 Thread Simon Glass
This series updates the sandbox serial driver to clean up the code a
little.


Simon Glass (3):
  serial: sandbox: Drop unnecessary #ifdefs
  sandbox: serial: Convert to livetree
  sandbox: serial: Update to use membuff

 drivers/serial/sandbox.c | 63 ++--
 1 file changed, 22 insertions(+), 41 deletions(-)

-- 
2.29.2.222.g5d2a92d10f8-goog



[PATCH 1/3] serial: sandbox: Drop unnecessary #ifdefs

2020-11-08 Thread Simon Glass
CONFIG_OF_CONTROL is always enabled for sandbox (as it should be for all
boards), so we can drop it. Also use IS_ENABLED() for the SPL check.

Signed-off-by: Simon Glass 
---

 drivers/serial/sandbox.c | 11 ++-
 1 file changed, 2 insertions(+), 9 deletions(-)

diff --git a/drivers/serial/sandbox.c b/drivers/serial/sandbox.c
index db2fbac6295..e3967deaaf2 100644
--- a/drivers/serial/sandbox.c
+++ b/drivers/serial/sandbox.c
@@ -22,8 +22,6 @@
 
 DECLARE_GLOBAL_DATA_PTR;
 
-#if CONFIG_IS_ENABLED(OF_CONTROL)
-
 /*
  *
  *   serial_buf: A buffer that holds keyboard characters for the
@@ -122,9 +120,8 @@ static int sandbox_serial_pending(struct udevice *dev, bool 
input)
return 0;
 
os_usleep(100);
-#ifndef CONFIG_SPL_BUILD
-   video_sync_all();
-#endif
+   if (!IS_ENABLED(CONFIG_SPL_BUILD))
+   video_sync_all();
if (next_index == serial_buf_read)
return 1;   /* buffer full */
 
@@ -146,7 +143,6 @@ static int sandbox_serial_getc(struct udevice *dev)
serial_buf_read = increment_buffer_index(serial_buf_read);
return result;
 }
-#endif /* CONFIG_IS_ENABLED(OF_CONTROL) */
 
 #ifdef CONFIG_DEBUG_UART_SANDBOX
 
@@ -211,7 +207,6 @@ static int sandbox_serial_getinfo(struct udevice *dev,
return 0;
 }
 
-#if CONFIG_IS_ENABLED(OF_CONTROL)
 static const char * const ansi_colour[] = {
"black", "red", "green", "yellow", "blue", "megenta", "cyan",
"white",
@@ -277,5 +272,3 @@ U_BOOT_DEVICE(serial_sandbox_non_fdt) = {
.platdata = &platdata_non_fdt,
 };
 #endif
-
-#endif /* CONFIG_IS_ENABLED(OF_CONTROL) */
-- 
2.29.2.222.g5d2a92d10f8-goog



[PATCH 2/3] sandbox: serial: Convert to livetree

2020-11-08 Thread Simon Glass
Use a livetree function to read the colour.

Signed-off-by: Simon Glass 
---

 drivers/serial/sandbox.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/drivers/serial/sandbox.c b/drivers/serial/sandbox.c
index e3967deaaf2..8c74c3a1b8c 100644
--- a/drivers/serial/sandbox.c
+++ b/drivers/serial/sandbox.c
@@ -12,7 +12,6 @@
 #include 
 #include 
 #include 
-#include 
 #include 
 #include 
 #include 
@@ -221,8 +220,7 @@ static int sandbox_serial_ofdata_to_platdata(struct udevice 
*dev)
if (CONFIG_IS_ENABLED(OF_PLATDATA))
return 0;
plat->colour = -1;
-   colour = fdt_getprop(gd->fdt_blob, dev_of_offset(dev),
-"sandbox,text-colour", NULL);
+   colour = dev_read_string(dev, "sandbox,text-colour");
if (colour) {
for (i = 0; i < ARRAY_SIZE(ansi_colour); i++) {
if (!strcmp(colour, ansi_colour[i])) {
-- 
2.29.2.222.g5d2a92d10f8-goog



[PATCH 3/3] sandbox: serial: Update to use membuff

2020-11-08 Thread Simon Glass
Rather than implementing our own circular queue, use membuff. This allows
us to read multiple bytes at once into the serial input.

Signed-off-by: Simon Glass 
---

 drivers/serial/sandbox.c | 48 
 1 file changed, 19 insertions(+), 29 deletions(-)

diff --git a/drivers/serial/sandbox.c b/drivers/serial/sandbox.c
index 8c74c3a1b8c..8e269a205d7 100644
--- a/drivers/serial/sandbox.c
+++ b/drivers/serial/sandbox.c
@@ -21,24 +21,18 @@
 
 DECLARE_GLOBAL_DATA_PTR;
 
-/*
- *
- *   serial_buf: A buffer that holds keyboard characters for the
- *  Sandbox U-Boot.
- *
- * invariants:
- *   serial_buf_write   == serial_buf_read -> empty buffer
- *   (serial_buf_write + 1) % 16 == serial_buf_read -> full buffer
- */
-static unsigned char serial_buf[16];
-static unsigned int serial_buf_write;
-static unsigned int serial_buf_read;
-
 struct sandbox_serial_platdata {
int colour; /* Text colour to use for output, -1 for none */
 };
 
+/**
+ * struct sandbox_serial_priv - Private data for this driver
+ *
+ * @buf: holds input characters available to be read by this driver
+ */
 struct sandbox_serial_priv {
+   struct membuff buf;
+   char serial_buf[16];
bool start_of_line;
 };
 
@@ -71,6 +65,7 @@ static int sandbox_serial_probe(struct udevice *dev)
 
if (state->term_raw != STATE_TERM_RAW)
disable_ctrlc(1);
+   membuff_init(&priv->buf, priv->serial_buf, sizeof(priv->serial_buf));
 
return 0;
 }
@@ -104,16 +99,12 @@ static int sandbox_serial_putc(struct udevice *dev, const 
char ch)
return 0;
 }
 
-static unsigned int increment_buffer_index(unsigned int index)
-{
-   return (index + 1) % ARRAY_SIZE(serial_buf);
-}
-
 static int sandbox_serial_pending(struct udevice *dev, bool input)
 {
-   const unsigned int next_index =
-   increment_buffer_index(serial_buf_write);
+   struct sandbox_serial_priv *priv = dev_get_priv(dev);
ssize_t count;
+   char *data;
+   int avail;
 
if (!input)
return 0;
@@ -121,26 +112,25 @@ static int sandbox_serial_pending(struct udevice *dev, 
bool input)
os_usleep(100);
if (!IS_ENABLED(CONFIG_SPL_BUILD))
video_sync_all();
-   if (next_index == serial_buf_read)
+   avail = membuff_putraw(&priv->buf, 100, false, &data);
+   if (!avail)
return 1;   /* buffer full */
 
-   count = os_read(0, &serial_buf[serial_buf_write], 1);
-   if (count == 1)
-   serial_buf_write = next_index;
+   count = os_read(0, data, avail);
+   if (count > 0)
+   membuff_putraw(&priv->buf, count, true, &data);
 
-   return serial_buf_write != serial_buf_read;
+   return membuff_avail(&priv->buf);
 }
 
 static int sandbox_serial_getc(struct udevice *dev)
 {
-   int result;
+   struct sandbox_serial_priv *priv = dev_get_priv(dev);
 
if (!sandbox_serial_pending(dev, true))
return -EAGAIN; /* buffer empty */
 
-   result = serial_buf[serial_buf_read];
-   serial_buf_read = increment_buffer_index(serial_buf_read);
-   return result;
+   return membuff_getbyte(&priv->buf);
 }
 
 #ifdef CONFIG_DEBUG_UART_SANDBOX
-- 
2.29.2.222.g5d2a92d10f8-goog



Re: Unit test is not available out of sandbox config

2020-11-08 Thread Simon Glass
Hi Kever,

On Sun, 8 Nov 2020 at 20:26, Kever Yang  wrote:
>
> Hi Simon,
>
>  Seems like the Unit test is only available with sandbox now,
> because of the bloblist test depends on the header in sandbox arch,
>
> see the build error:
>
>CC  test/bloblist.o
>CC  test/env/attr.o
>CC  test/overlay/cmd_ut_overlay.o
>LD  drivers/fastboot/built-in.o
>LD  drivers/built-in.o
> test/bloblist.c:10:23: fatal error: asm/state.h: No such file or directory
>   #include 
> ^
> compilation terminated.
>LD  test/log/built-in.o
> make[1]: *** [scripts/Makefile.build:265: test/bloblist.o] Error 1
> make[1]: *** Waiting for unfinished jobs

Oh dear. Thanks for the report. I will send a patch.

Regards,
Simon


[PATCH 1/2] test: Avoid assuming sandbox board for bloblist test

2020-11-08 Thread Simon Glass
This tests assumes it is running on sandbox. Add a few functions to handle
silencing the console on any board and use those instead.

Reported-by: Kever Yang 

Signed-off-by: Simon Glass 
---

 include/test/ut.h | 18 ++
 test/bloblist.c   | 13 -
 test/ut.c | 18 ++
 3 files changed, 40 insertions(+), 9 deletions(-)

diff --git a/include/test/ut.h b/include/test/ut.h
index 3f2ee7514b8..17400c73ea9 100644
--- a/include/test/ut.h
+++ b/include/test/ut.h
@@ -338,4 +338,22 @@ ulong ut_check_free(void);
  */
 long ut_check_delta(ulong last);
 
+/**
+ * ut_silence_console() - Silence the console if requested by the user
+ *
+ * This stops test output from appear on the console. It is the default on
+ * sandbox, unless the -v flag is given. For other boards, this does nothing.
+ *
+ * @uts: Test state (in case in future we want to keep state here)
+ */
+void ut_silence_console(struct unit_test_state *uts);
+
+/**
+ * ut_unsilence_console() - Unsilence the console after a test
+ *
+ * This restarts console output again and turns off console recording. This
+ * happens on all boards, including sandbox.
+ */
+void ut_unsilence_console(struct unit_test_state *uts);
+
 #endif
diff --git a/test/bloblist.c b/test/bloblist.c
index 0bb9e2d81e7..900299dd68e 100644
--- a/test/bloblist.c
+++ b/test/bloblist.c
@@ -7,7 +7,6 @@
 #include 
 #include 
 #include 
-#include 
 #include 
 #include 
 #include 
@@ -240,7 +239,6 @@ BLOBLIST_TEST(bloblist_test_checksum, 0);
 /* Test the 'bloblist info' command */
 static int bloblist_test_cmd_info(struct unit_test_state *uts)
 {
-   struct sandbox_state *state = state_get_current();
struct bloblist_hdr *hdr;
char *data, *data2;
 
@@ -250,8 +248,7 @@ static int bloblist_test_cmd_info(struct unit_test_state 
*uts)
data2 = bloblist_ensure(TEST_TAG2, TEST_SIZE2);
 
console_record_reset_enable();
-   if (!state->show_test_output)
-   gd->flags |= GD_FLG_SILENT;
+   ut_silence_console(uts);
console_record_reset();
run_command("bloblist info", 0);
ut_assert_nextline("base: %lx", (ulong)map_to_sysmem(hdr));
@@ -259,7 +256,7 @@ static int bloblist_test_cmd_info(struct unit_test_state 
*uts)
ut_assert_nextline("alloced:  70 112 Bytes");
ut_assert_nextline("free: 390912 Bytes");
ut_assert_console_end();
-   gd->flags &= ~(GD_FLG_SILENT | GD_FLG_RECORD);
+   ut_unsilence_console(uts);
 
return 0;
 }
@@ -268,7 +265,6 @@ BLOBLIST_TEST(bloblist_test_cmd_info, 0);
 /* Test the 'bloblist list' command */
 static int bloblist_test_cmd_list(struct unit_test_state *uts)
 {
-   struct sandbox_state *state = state_get_current();
struct bloblist_hdr *hdr;
char *data, *data2;
 
@@ -278,8 +274,7 @@ static int bloblist_test_cmd_list(struct unit_test_state 
*uts)
data2 = bloblist_ensure(TEST_TAG2, TEST_SIZE2);
 
console_record_reset_enable();
-   if (!state->show_test_output)
-   gd->flags |= GD_FLG_SILENT;
+   ut_silence_console(uts);
console_record_reset();
run_command("bloblist list", 0);
ut_assert_nextline("Address   Size  Tag Name");
@@ -288,7 +283,7 @@ static int bloblist_test_cmd_list(struct unit_test_state 
*uts)
ut_assert_nextline("%08lx  %8x2 SPL hand-off",
   (ulong)map_to_sysmem(data2), TEST_SIZE2);
ut_assert_console_end();
-   gd->flags &= ~(GD_FLG_SILENT | GD_FLG_RECORD);
+   ut_unsilence_console(uts);
 
return 0;
 }
diff --git a/test/ut.c b/test/ut.c
index 95bdd66de6a..44ed1ba2d31 100644
--- a/test/ut.c
+++ b/test/ut.c
@@ -8,6 +8,9 @@
 #include 
 #include 
 #include 
+#ifdef CONFIG_SANDBOX
+#include 
+#endif
 #include 
 #include 
 
@@ -114,3 +117,18 @@ int ut_check_console_dump(struct unit_test_state *uts, int 
total_bytes)
 
return upto == total_bytes ? 0 : 1;
 }
+
+void ut_silence_console(struct unit_test_state *uts)
+{
+#ifdef CONFIG_SANDBOX
+   struct sandbox_state *state = state_get_current();
+
+   if (!state->show_test_output)
+   gd->flags |= GD_FLG_SILENT;
+#endif
+}
+
+void ut_unsilence_console(struct unit_test_state *uts)
+{
+   gd->flags &= ~(GD_FLG_SILENT | GD_FLG_RECORD);
+}
-- 
2.29.2.222.g5d2a92d10f8-goog



[PATCH 2/2] test: Only enable bloblist test when supported

2020-11-08 Thread Simon Glass
This test cannot work unless CONFIG_BLOBLIST is enabled. Update it to add
that condition.

Reported-by: Kever Yang 
Signed-off-by: Simon Glass 
---

 test/Makefile | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/test/Makefile b/test/Makefile
index 1c930b31485..cdbfa61cda3 100644
--- a/test/Makefile
+++ b/test/Makefile
@@ -2,7 +2,9 @@
 #
 # (C) Copyright 2012 The Chromium Authors
 
+ifneq ($(CONFIG_$(SPL_)BLOBLIST),)
 obj-$(CONFIG_$(SPL_)CMDLINE) += bloblist.o
+endif
 obj-$(CONFIG_$(SPL_)CMDLINE) += cmd/
 obj-$(CONFIG_$(SPL_)CMDLINE) += cmd_ut.o
 obj-$(CONFIG_$(SPL_)CMDLINE) += command_ut.o
-- 
2.29.2.222.g5d2a92d10f8-goog



Re: [PATCH 2/5] spl: mmc: extend spl_mmc_boot_mode() to take mmc argument

2020-11-08 Thread Lokesh Vutla



On 08/11/20 6:44 pm, Andre Przywara wrote:
> Platforms can overwrite the weak definition of spl_mmc_boot_mode() to
> determine where to load U-Boot proper from.
> For most of them this is a trivial decision based on Kconfig variables,
> but it might be desirable the probe the actual device to answer this
> question.
> 
> Pass the pointer to the mmc struct to that function, so implementations
> can make use of them.
> 
> Compile-tested for all users changed.
> 
> Cc: Stefano Babic 
> Cc: Fabio Estevam 
> Cc: NXP i.MX U-Boot Team 
> Cc: Lokesh Vutla 
> Cc: Philipp Tomsich 
> Cc: Kever Yang 
> Cc: Marek Vasut 
> Cc: Simon Goldschmidt 
> Cc: Ley Foon Tan 
> Cc: Patrick Delaunay 
> Cc: Patrice Chotard 
> Signed-off-by: Andre Przywara 


For OMAP and K3

Acked-by: Lokesh Vutla 

Thanks and regards,
Lokesh



[PATCH v5 1/1] cmd: gpt: add eMMC and GPT support

2020-11-08 Thread Rayagonda Kokatanur
From: Corneliu Doban 

Add eMMC and GPT support.
- GPT partition list and command to create the GPT added to u-boot
  environment
- eMMC boot commands added to u-boot environment
- new gpt commands (enumarate and setenv) that are used by broadcom
  update scripts and boot commands
- eMMC specific u-boot configurations with environment saved in eMMC
  and GPT support

Signed-off-by: Corneliu Doban 
Signed-off-by: Rayagonda Kokatanur 
---
Changes from v4:
 -Address review comments from Thiru,
  Use env_set_hex() instead of env_set_ulong() in two place.

Changes from v3:
 -Address review comments from Simon Glass,
  Return -ve number instead of 1 upon failure,
  Use shorter variable name,
  Modified code to avoid buffer overflow,
  Use if (!strcmp(...)) instead of if (strcmp(...) == 0)

Changes from v2:
 -Address review comments from Simon Glass,
  Check for return value of part_driver_get_count(),
  Don't check return value of part_driver_get(),
  Rewrite part_driver_get() and rename to part_driver_get_first(),
  Use env_set_ulong() whereever applicable, 

 -Address review comments from Michael Nazzareno Trimarchi,
  Add new function to set all env vriables,

Changes from v1:
 -Address review comments from Simon Glass,
  Correct function comments,
  Check for return value,
  Add helper function in part.h

 cmd/gpt.c  | 161 +
 include/part.h |  29 +
 2 files changed, 190 insertions(+)

diff --git a/cmd/gpt.c b/cmd/gpt.c
index df759416c8..56986ad554 100644
--- a/cmd/gpt.c
+++ b/cmd/gpt.c
@@ -18,6 +18,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -621,6 +622,152 @@ static int gpt_verify(struct blk_desc *blk_dev_desc, 
const char *str_part)
return ret;
 }
 
+/**
+ * gpt_enumerate() - Enumerate partition names into environment variable.
+ *
+ * Enumerate partition names. Partition names are stored in gpt_partition_list
+ * environment variable. Each partition name is delimited by space.
+ *
+ * @desc: block device descriptor
+ *
+ * @Return: '0' on success and -ve error on failure
+ */
+static int gpt_enumerate(struct blk_desc *desc)
+{
+   struct part_driver *first_drv, *part_drv;
+   int str_len = 0, tmp_len;
+   char part_list[2048];
+   int n_drvs;
+   char *ptr;
+
+   part_list[0] = 0;
+   n_drvs = part_driver_get_count();
+   if (!n_drvs) {
+   printf("Failed to get partition driver count\n");
+   return -ENOENT;
+   }
+
+   first_drv = part_driver_get_first();
+   for (part_drv = first_drv; part_drv != first_drv + n_drvs; part_drv++) {
+   struct disk_partition pinfo;
+   int ret;
+   int i;
+
+   for (i = 1; i < part_drv->max_entries; i++) {
+   ret = part_drv->get_info(desc, i, &pinfo);
+   if (ret) {
+   /* no more entries in table */
+   break;
+   }
+
+   ptr = &part_list[str_len];
+   tmp_len = strlen((const char *)pinfo.name);
+   str_len += tmp_len;
+   /* +1 for space */
+   str_len++;
+   if (str_len > sizeof(part_list)) {
+   printf("Error insufficient memory\n");
+   return -ENOMEM;
+   }
+   strcpy(ptr, (const char *)pinfo.name);
+   /* One byte for space(" ") delimiter */
+   ptr[tmp_len] = ' ';
+   }
+   }
+   if (*part_list)
+   part_list[strlen(part_list) - 1] = 0;
+   debug("setenv gpt_partition_list %s\n", part_list);
+
+   return env_set("gpt_partition_list", part_list);
+}
+
+/**
+ * gpt_setenv_part_variables() - setup partition environmental variables
+ *
+ * Setup the gpt_partition_name, gpt_partition_entry, gpt_partition_addr
+ * and gpt_partition_size environment variables.
+ *
+ * @pinfo: pointer to disk partition
+ * @i: partition entry
+ *
+ * @Return: '0' on success and -ENOENT on failure
+ */
+static int gpt_setenv_part_variables(struct disk_partition *pinfo, int i)
+{
+   int ret;
+
+   ret = env_set_hex("gpt_partition_addr", pinfo->start);
+   if (ret)
+   goto fail;
+
+   ret = env_set_hex("gpt_partition_size", pinfo->size);
+   if (ret)
+   goto fail;
+
+   ret = env_set_ulong("gpt_partition_entry", i);
+   if (ret)
+   goto fail;
+
+   ret = env_set("gpt_partition_name", (const char *)pinfo->name);
+   if (ret)
+   goto fail;
+
+   return 0;
+
+fail:
+   return -ENOENT;
+}
+
+/**
+ * gpt_setenv() - Dynamically setup environment variables.
+ *
+ * Dynamically setup environment variables for name, index, offset and size
+ * for partition in GPT table after runn

Re: [PATCH 2/2] test: Only enable bloblist test when supported

2020-11-08 Thread Heinrich Schuchardt
On 09.11.20 05:08, Simon Glass wrote:
> This test cannot work unless CONFIG_BLOBLIST is enabled. Update it to add
> that condition.
>
> Reported-by: Kever Yang 
> Signed-off-by: Simon Glass 
> ---
>
>  test/Makefile | 2 ++
>  1 file changed, 2 insertions(+)
>
> diff --git a/test/Makefile b/test/Makefile
> index 1c930b31485..cdbfa61cda3 100644
> --- a/test/Makefile
> +++ b/test/Makefile
> @@ -2,7 +2,9 @@
>  #
>  # (C) Copyright 2012 The Chromium Authors
>
> +ifneq ($(CONFIG_$(SPL_)BLOBLIST),)
>  obj-$(CONFIG_$(SPL_)CMDLINE) += bloblist.o
> +endif
>  obj-$(CONFIG_$(SPL_)CMDLINE) += cmd/
>  obj-$(CONFIG_$(SPL_)CMDLINE) += cmd_ut.o
>  obj-$(CONFIG_$(SPL_)CMDLINE) += command_ut.o
>

This patch conflicts with my patch

[1/1] test: test/bloblist.c depends on asm/state.h
https://patchwork.ozlabs.org/project/uboot/patch/20201031073806.30736-1-xypron.g...@gmx.de/

It seems that my patch is obsoleted by the first patch of Kever's series:

test: Avoid assuming sandbox board for bloblist test
https://patchwork.ozlabs.org/project/uboot/patch/20201108210834.1.I08cec35c8482583834811d48894f358277c662aa@changeid/

Best regards

Heinrich