Re: [PATCH v2 09/19] video: sunxi: de2: switch to public uclass functions

2021-03-06 Thread Jernej Škrabec
Dne nedelja, 07. marec 2021 ob 02:32:52 CET je Andre Przywara napisal(a):
> On Sat,  6 Mar 2021 20:54:27 +0100
> 
> Jernej Skrabec  wrote:
> > Currently DE2 driver uses functions which are defined in internal
> > headers. They are not meant to be used outside of uclass framework.
> > Switch DE2 driver to public ones. This has additional benefit that
> > device_probe doesn't need to be called manually.
> 
> Indeed, good solution: for the calls in _probe(), we call de2_init()
> right afterwards, which would explicitly call probe for the display, so
> this both saves this call and the usage of the internal function.
> For the calls in simplefb_setup: the DM framework checks if a device
> has already been activated, so there is no problem with double probes.
> 
> However, actually testing this on a Pine64-LTS revealed that this breaks
> on the A64: I only get a black screen (bisecting down to this commit).
> 
> I didn't investigate any further yet, just wanted to give a heads up.

Thanks! I'll check what's going on.

Best regards,
Jernej

> 
> Cheers,
> Andre
> 
> > Signed-off-by: Jernej Skrabec 
> > ---
> > 
> >  drivers/video/sunxi/sunxi_de2.c | 29 ++---
> >  1 file changed, 10 insertions(+), 19 deletions(-)
> > 
> > diff --git a/drivers/video/sunxi/sunxi_de2.c
> > b/drivers/video/sunxi/sunxi_de2.c index 6b836a011944..e02d359cd259 100644
> > --- a/drivers/video/sunxi/sunxi_de2.c
> > +++ b/drivers/video/sunxi/sunxi_de2.c
> > @@ -19,8 +19,6 @@
> > 
> >  #include 
> >  #include 
> >  #include 
> > 
> > -#include 
> > -#include 
> > 
> >  #include 
> >  #include "simplefb_common.h"
> > 
> > @@ -198,13 +196,6 @@ static int sunxi_de2_init(struct udevice *dev, ulong
> > fbbase,> 
> > disp_uc_plat->source_id = mux;
> > 
> > -   ret = device_probe(disp);
> > -   if (ret) {
> > -   debug("%s: device '%s' display won't probe (ret=%d)\n",
> > - __func__, dev->name, ret);
> > -   return ret;
> > -   }
> > -
> > 
> > ret = display_read_timing(disp, );
> > if (ret) {
> > 
> > debug("%s: Failed to read timings\n", __func__);
> > 
> > @@ -245,8 +236,8 @@ static int sunxi_de2_probe(struct udevice *dev)
> > 
> > if (!(gd->flags & GD_FLG_RELOC))
> > 
> > return 0;
> > 
> > -   ret = uclass_find_device_by_name(UCLASS_DISPLAY,
> > -"sunxi_lcd", );
> > +   ret = uclass_get_device_by_driver(UCLASS_DISPLAY,
> > + 
DM_DRIVER_GET(sunxi_lcd), );
> > 
> > if (!ret) {
> > 
> > int mux;
> > 
> > @@ -262,8 +253,8 @@ static int sunxi_de2_probe(struct udevice *dev)
> > 
> > debug("%s: lcd display not found (ret=%d)\n", __func__, ret);
> > 
> > -   ret = uclass_find_device_by_name(UCLASS_DISPLAY,
> > -"sunxi_dw_hdmi", 
);
> > +   ret = uclass_get_device_by_driver(UCLASS_DISPLAY,
> > + 
DM_DRIVER_GET(sunxi_dw_hdmi), );
> > 
> > if (!ret) {
> > 
> > int mux;
> > if (IS_ENABLED(CONFIG_MACH_SUNXI_H3_H5))
> > 
> > @@ -332,8 +323,8 @@ int sunxi_simplefb_setup(void *blob)
> > 
> > mux = 1;
> > 
> > /* Skip simplefb setting if DE2 / HDMI is not present */
> > 
> > -   ret = uclass_find_device_by_name(UCLASS_VIDEO,
> > -"sunxi_de2", );
> > +   ret = uclass_get_device_by_driver(UCLASS_VIDEO,
> > + 
DM_DRIVER_GET(sunxi_de2), );
> > 
> > if (ret) {
> > 
> > debug("DE2 not present\n");
> > return 0;
> > 
> > @@ -342,8 +333,8 @@ int sunxi_simplefb_setup(void *blob)
> > 
> > return 0;
> > 
> > }
> > 
> > -   ret = uclass_find_device_by_name(UCLASS_DISPLAY,
> > -"sunxi_dw_hdmi", 
);
> > +   ret = uclass_get_device_by_driver(UCLASS_DISPLAY,
> > + 
DM_DRIVER_GET(sunxi_dw_hdmi), );
> > 
> > if (ret) {
> > 
> > debug("HDMI not present\n");
> > 
> > } else if (device_active(hdmi)) {
> > 
> > @@ -355,8 +346,8 @@ int sunxi_simplefb_setup(void *blob)
> > 
> > debug("HDMI present but not probed\n");
> > 
> > }
> > 
> > -   ret = uclass_find_device_by_name(UCLASS_DISPLAY,
> > -"sunxi_lcd", );
> > +   ret = uclass_get_device_by_driver(UCLASS_DISPLAY,
> > + 
DM_DRIVER_GET(sunxi_lcd), );
> > 
> > if (ret)
> > 
> > debug("LCD not present\n");
> > 
> > else if (device_active(lcd))






Re: [PATCH u-boot 30/39] ARM: imx6m: fix imx_eqos_txclk_set_rate() type mismatch for LTO

2021-03-06 Thread Sean Anderson

Re: [PATCH u-boot 30/39] ARM: imx6m: fix imx_eqos_txclk_set_rate() type 
mismatch for LTO


imx8m?

On 3/6/21 11:25 PM, Marek Behún wrote:

When building imx8mp_evk_defconfig with LTO, the compiler complains
about type mismatch of function imx_eqos_txclk_set_rate() in file
   drivers/net/dwc_eth_qos.c:845:12
which contains a weak definition of this function, vs file
   arch/arm/mach-imx/imx8m/clock_imx8mm.c
which contains an implementation.

Change the type of this function in the implementation to fix this.

Signed-off-by: Marek Behún 
---
  arch/arm/mach-imx/imx8m/clock_imx8mm.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/arm/mach-imx/imx8m/clock_imx8mm.c 
b/arch/arm/mach-imx/imx8m/clock_imx8mm.c
index 4024dafca1..554ff0eaca 100644
--- a/arch/arm/mach-imx/imx8m/clock_imx8mm.c
+++ b/arch/arm/mach-imx/imx8m/clock_imx8mm.c
@@ -838,7 +838,7 @@ int set_clk_eqos(enum enet_freq type)
return 0;
  }
  
-int imx_eqos_txclk_set_rate(u32 rate)

+int imx_eqos_txclk_set_rate(ulong rate)
  {
u32 val;
u32 eqos_post_div;






Re: [PATCH u-boot 14/39] lib: crc32: make the crc_table variable non-const

2021-03-06 Thread Marek Vasut

On 3/7/21 5:58 AM, Marek Behun wrote:

On Sun, 7 Mar 2021 05:46:24 +0100
Marek Vasut  wrote:


On 3/7/21 5:25 AM, Marek Behún wrote:

When compiling with LTO, the compiler fails with an error saying that
`crc_table` causes a section type conflict with `efi_var_buf`.

This is because both are declared to be in the same section (via macro
`__efi_runtime_data`), but one is const while the other is not.

Make this variable non-const in order to fix this.


This does not look right, the crc32 array is constant.
Maybe what you want to do instead if create some __efi_constant_data
section ?


Yes, this was the easier solution, and maybe is not ideal.

I thought it would not be much of a problem since this array can be
nonconstant (generated after boot) if CONFIG_DYNAMIC_CRC_TABLE is
enabled.

Anyway I don't much understand the EFI code so I wanted to poke into it
as little as possible.


Isn't the compiler capable of better optimization on constant stuff ?
That's pretty much what prompted my suggestion to add separate section.


Re: [PATCH u-boot 11/39] binman: declare symbols externally visible

2021-03-06 Thread Marek Behun
I forgot to drop this patch. It is not needed, please ignore it.

Marek


Re: [PATCH u-boot 14/39] lib: crc32: make the crc_table variable non-const

2021-03-06 Thread Marek Behun
On Sun, 7 Mar 2021 05:46:24 +0100
Marek Vasut  wrote:

> On 3/7/21 5:25 AM, Marek Behún wrote:
> > When compiling with LTO, the compiler fails with an error saying that
> > `crc_table` causes a section type conflict with `efi_var_buf`.
> > 
> > This is because both are declared to be in the same section (via macro
> > `__efi_runtime_data`), but one is const while the other is not.
> > 
> > Make this variable non-const in order to fix this.  
> 
> This does not look right, the crc32 array is constant.
> Maybe what you want to do instead if create some __efi_constant_data 
> section ?

Yes, this was the easier solution, and maybe is not ideal.

I thought it would not be much of a problem since this array can be
nonconstant (generated after boot) if CONFIG_DYNAMIC_CRC_TABLE is
enabled.

Anyway I don't much understand the EFI code so I wanted to poke into it
as little as possible.

Marek


Re: [PATCH u-boot 05/39] checkpatch: require quotes around section name in the __section() macro

2021-03-06 Thread Marek Behun
On Sun, 7 Mar 2021 05:47:56 +0100
Marek Vasut  wrote:

> On 3/7/21 5:25 AM, Marek Behún wrote:
> > This is how Linux does this now, see Linux commit 339f29d91acf.
> > 
> > Signed-off-by: Marek Behún 
> > ---
> >   scripts/checkpatch.pl | 2 +-
> >   1 file changed, 1 insertion(+), 1 deletion(-)
> > 
> > diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
> > index 755f4802a4..fd1e9c4d24 100755
> > --- a/scripts/checkpatch.pl
> > +++ b/scripts/checkpatch.pl
> > @@ -6065,7 +6065,7 @@ sub process {
> > my $old = substr($rawline, $-[1], $+[1] - $-[1]);
> > my $new = substr($old, 1, -1);
> > if (WARN("PREFER_SECTION",
> > -"__section($new) is preferred over 
> > __attribute__((section($old)))\n" . $herecurr) &&
> > +"__section(\"$new\") is preferred over 
> > __attribute__((section($old)))\n" . $herecurr) &&
> > $fix) {
> > $fixed[$fixlinenr] =~ 
> > s/\b__attribute__\s*\(\s*\(\s*_*section_*\s*\(\s*\Q$old\E\s*\)\s*\)\s*\)/__section($new)/;
> >   
> 
> Shouldn't some of the patches which are clearly fixes be sent as 
> separate fixes, so they can be picked while the LTO support is being 
> worked on ?

Yes, ideally it would be better, but:

this patch is connected to patch 6 of this series, and patch 6 needs to
be in this series because otherwise people trying to apply this series
would get an error.

The first 4 patches are also fixes for something else, but they
were discovered thanks to LTO and without them users will get
warnings/errors when trying to build for some boards.

Tom, should I send these patches separately? Also the first 3 patches
should maybe be applied via Stefan and Simon, via their trees...

Marek


Re: [PATCH u-boot 05/39] checkpatch: require quotes around section name in the __section() macro

2021-03-06 Thread Marek Vasut

On 3/7/21 5:25 AM, Marek Behún wrote:

This is how Linux does this now, see Linux commit 339f29d91acf.

Signed-off-by: Marek Behún 
---
  scripts/checkpatch.pl | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index 755f4802a4..fd1e9c4d24 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -6065,7 +6065,7 @@ sub process {
my $old = substr($rawline, $-[1], $+[1] - $-[1]);
my $new = substr($old, 1, -1);
if (WARN("PREFER_SECTION",
-"__section($new) is preferred over 
__attribute__((section($old)))\n" . $herecurr) &&
+"__section(\"$new\") is preferred over 
__attribute__((section($old)))\n" . $herecurr) &&
$fix) {
$fixed[$fixlinenr] =~ 
s/\b__attribute__\s*\(\s*\(\s*_*section_*\s*\(\s*\Q$old\E\s*\)\s*\)\s*\)/__section($new)/;


Shouldn't some of the patches which are clearly fixes be sent as 
separate fixes, so they can be picked while the LTO support is being 
worked on ?


Re: [PATCH u-boot 14/39] lib: crc32: make the crc_table variable non-const

2021-03-06 Thread Marek Vasut

On 3/7/21 5:25 AM, Marek Behún wrote:

When compiling with LTO, the compiler fails with an error saying that
`crc_table` causes a section type conflict with `efi_var_buf`.

This is because both are declared to be in the same section (via macro
`__efi_runtime_data`), but one is const while the other is not.

Make this variable non-const in order to fix this.


This does not look right, the crc32 array is constant.
Maybe what you want to do instead if create some __efi_constant_data 
section ?


[...]


diff --git a/lib/crc32.c b/lib/crc32.c
index e9be3bf386..c033449cff 100644
--- a/lib/crc32.c
+++ b/lib/crc32.c
@@ -88,7 +88,7 @@ static void __efi_runtime make_crc_table(void)
   * Table of CRC-32's of all single-byte values (made by make_crc_table)
   */
  
-static const uint32_t __efi_runtime_data crc_table[256] = {

+static uint32_t __efi_runtime_data crc_table[256] = {
  tole(0xL), tole(0x77073096L), tole(0xee0e612cL), tole(0x990951baL),
  tole(0x076dc419L), tole(0x706af48fL), tole(0xe963a535L), tole(0x9e6495a3L),
  tole(0x0edb8832L), tole(0x79dcb8a4L), tole(0xe0d5e91eL), tole(0x97d2d988L),



[PATCH u-boot 38/39] ARM: enable LTO for some boards

2021-03-06 Thread Marek Behún
Enable LTO for some boards that were tested by people on U-Boot Mailing
List.

Signed-off-by: Marek Behún 
Tested-by: Adam Ford 
Tested-by: Pali Rohár 
---
 configs/da850evm_defconfig| 1 +
 configs/da850evm_direct_nor_defconfig | 1 +
 configs/da850evm_nand_defconfig   | 1 +
 configs/imx6q_logic_defconfig | 1 +
 configs/imx8mn_beacon_2g_defconfig| 1 +
 configs/imx8mn_beacon_defconfig   | 1 +
 configs/nokia_rx51_defconfig  | 1 +
 configs/turris_mox_defconfig  | 1 +
 configs/turris_omnia_defconfig| 1 +
 9 files changed, 9 insertions(+)

diff --git a/configs/da850evm_defconfig b/configs/da850evm_defconfig
index 26e76a2929..6ff5e21bc6 100644
--- a/configs/da850evm_defconfig
+++ b/configs/da850evm_defconfig
@@ -1,3 +1,4 @@
+CONFIG_LTO=y
 CONFIG_ARM=y
 CONFIG_SYS_THUMB_BUILD=y
 CONFIG_ARCH_DAVINCI=y
diff --git a/configs/da850evm_direct_nor_defconfig 
b/configs/da850evm_direct_nor_defconfig
index d3860a963d..06c7ce7c47 100644
--- a/configs/da850evm_direct_nor_defconfig
+++ b/configs/da850evm_direct_nor_defconfig
@@ -1,3 +1,4 @@
+CONFIG_LTO=y
 CONFIG_ARM=y
 CONFIG_ARCH_CPU_INIT=y
 CONFIG_ARCH_DAVINCI=y
diff --git a/configs/da850evm_nand_defconfig b/configs/da850evm_nand_defconfig
index 0d0e9a148d..be737564e1 100644
--- a/configs/da850evm_nand_defconfig
+++ b/configs/da850evm_nand_defconfig
@@ -1,3 +1,4 @@
+CONFIG_LTO=y
 CONFIG_ARM=y
 CONFIG_SYS_THUMB_BUILD=y
 CONFIG_ARCH_DAVINCI=y
diff --git a/configs/imx6q_logic_defconfig b/configs/imx6q_logic_defconfig
index 36dc24d080..0f8aea6983 100644
--- a/configs/imx6q_logic_defconfig
+++ b/configs/imx6q_logic_defconfig
@@ -1,3 +1,4 @@
+CONFIG_LTO=y
 CONFIG_ARM=y
 CONFIG_ARCH_MX6=y
 CONFIG_SYS_TEXT_BASE=0x1780
diff --git a/configs/imx8mn_beacon_2g_defconfig 
b/configs/imx8mn_beacon_2g_defconfig
index 58b8e49486..1c8cbc2c89 100644
--- a/configs/imx8mn_beacon_2g_defconfig
+++ b/configs/imx8mn_beacon_2g_defconfig
@@ -1,3 +1,4 @@
+CONFIG_LTO=y
 CONFIG_ARM=y
 CONFIG_ARCH_IMX8M=y
 CONFIG_SYS_TEXT_BASE=0x4020
diff --git a/configs/imx8mn_beacon_defconfig b/configs/imx8mn_beacon_defconfig
index d6a3385d8d..6457b9409a 100644
--- a/configs/imx8mn_beacon_defconfig
+++ b/configs/imx8mn_beacon_defconfig
@@ -1,3 +1,4 @@
+CONFIG_LTO=y
 CONFIG_ARM=y
 CONFIG_ARCH_IMX8M=y
 CONFIG_SYS_TEXT_BASE=0x4020
diff --git a/configs/nokia_rx51_defconfig b/configs/nokia_rx51_defconfig
index 312ca3a1a9..85ca627790 100644
--- a/configs/nokia_rx51_defconfig
+++ b/configs/nokia_rx51_defconfig
@@ -1,3 +1,4 @@
+CONFIG_LTO=y
 CONFIG_ARM=y
 # CONFIG_SYS_THUMB_BUILD is not set
 CONFIG_ARCH_OMAP2PLUS=y
diff --git a/configs/turris_mox_defconfig b/configs/turris_mox_defconfig
index f938fbb475..2a351d9180 100644
--- a/configs/turris_mox_defconfig
+++ b/configs/turris_mox_defconfig
@@ -1,3 +1,4 @@
+CONFIG_LTO=y
 CONFIG_ARM=y
 CONFIG_ARCH_CPU_INIT=y
 CONFIG_ARCH_MVEBU=y
diff --git a/configs/turris_omnia_defconfig b/configs/turris_omnia_defconfig
index 4b8843d7be..d7a2ec3592 100644
--- a/configs/turris_omnia_defconfig
+++ b/configs/turris_omnia_defconfig
@@ -1,3 +1,4 @@
+CONFIG_LTO=y
 CONFIG_ARM=y
 CONFIG_ARCH_CPU_INIT=y
 CONFIG_SPL_SYS_THUMB_BUILD=y
-- 
2.26.2



[PATCH u-boot 37/39] ARM: don't use -ffunction-sections/-fdata-sections with LTO build

2021-03-06 Thread Marek Behún
When building with LTO, using -ffunction-sections/-fdata-sections is not
useful anymore.

Signed-off-by: Marek Behún 
---
 arch/arm/config.mk | 8 ++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/arch/arm/config.mk b/arch/arm/config.mk
index 4153f7e371..2b2c6ad2e5 100644
--- a/arch/arm/config.mk
+++ b/arch/arm/config.mk
@@ -15,8 +15,12 @@ CFLAGS_NON_EFI := -fno-pic -ffixed-r9 -ffunction-sections 
-fdata-sections
 CFLAGS_EFI := -fpic -fshort-wchar
 
 LDFLAGS_FINAL += --gc-sections
-PLATFORM_RELFLAGS += -ffunction-sections -fdata-sections \
--fno-common -ffixed-r9
+
+ifndef CONFIG_LTO
+PLATFORM_RELFLAGS += -ffunction-sections -fdata-sections
+endif
+
+PLATFORM_RELFLAGS += -fno-common -ffixed-r9
 PLATFORM_RELFLAGS += $(call cc-option, -msoft-float) \
   $(call cc-option,-mshort-load-bytes,$(call cc-option,-malignment-traps,))
 
-- 
2.26.2



[PATCH u-boot 39/39] DO NOT MERGE! ARM: enable LTO by default

2021-03-06 Thread Marek Behún
Build ARM targets with LTO by default.

Signed-off-by: Marek Behún 
---
 arch/Kconfig | 1 +
 1 file changed, 1 insertion(+)

diff --git a/arch/Kconfig b/arch/Kconfig
index bf4b8afcb4..d0f5a16b95 100644
--- a/arch/Kconfig
+++ b/arch/Kconfig
@@ -37,6 +37,7 @@ config ARM
select CREATE_ARCH_SYMLINK
select HAVE_PRIVATE_LIBGCC if !ARM64
select SUPPORT_OF_CONTROL
+   imply LTO
 
 config M68K
bool "M68000 architecture"
-- 
2.26.2



[PATCH u-boot 36/39] ARM: make LTO available

2021-03-06 Thread Marek Behún
Make LTO available for ARM architecture.

Signed-off-by: Marek Behún 
---
 arch/Kconfig  | 1 +
 arch/arm/lib/Makefile | 2 ++
 2 files changed, 3 insertions(+)

diff --git a/arch/Kconfig b/arch/Kconfig
index b884b7b248..bf4b8afcb4 100644
--- a/arch/Kconfig
+++ b/arch/Kconfig
@@ -33,6 +33,7 @@ config ARC
 
 config ARM
bool "ARM architecture"
+   select ARCH_SUPPORTS_LTO
select CREATE_ARCH_SYMLINK
select HAVE_PRIVATE_LIBGCC if !ARM64
select SUPPORT_OF_CONTROL
diff --git a/arch/arm/lib/Makefile b/arch/arm/lib/Makefile
index 61bef1d5af..7f66332715 100644
--- a/arch/arm/lib/Makefile
+++ b/arch/arm/lib/Makefile
@@ -45,6 +45,8 @@ obj-$(CONFIG_SEMIHOSTING) += semihosting.o
 
 obj-y  += bdinfo.o
 obj-y  += sections.o
+CFLAGS_REMOVE_sections.o := $(LTO_CFLAGS)
+
 obj-y  += stack.o
 ifdef CONFIG_CPU_V7M
 obj-y  += interrupts_m.o
-- 
2.26.2



[PATCH u-boot 35/39] ata: ahci: fix ahci_link_up() type mismatch for LTO

2021-03-06 Thread Marek Behún
When building highbank_defconfig with LTO, the compiler complains about
type mismatch of function ahci_link_up().

The third parameter of this function is of type u8 in
drivers/ata/ahci.c, but of type int in board/highbank/ahci.c.

There is no reason in using u8, and the code using this function
actually passes an int variable into the function (so it is implicitly
converted to u8).

Change the type of this parameter to int in drivers/ata/ahci.c.

Signed-off-by: Marek Behún 
---
 drivers/ata/ahci.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/ata/ahci.c b/drivers/ata/ahci.c
index 2ef21ec508..3d16bc21a8 100644
--- a/drivers/ata/ahci.c
+++ b/drivers/ata/ahci.c
@@ -110,7 +110,7 @@ static int waiting_for_cmd_completed(void __iomem *offset,
return (i < timeout_msec) ? 0 : -1;
 }
 
-int __weak ahci_link_up(struct ahci_uc_priv *uc_priv, u8 port)
+int __weak ahci_link_up(struct ahci_uc_priv *uc_priv, int port)
 {
u32 tmp;
int j = 0;
-- 
2.26.2



[PATCH u-boot 33/39] ARM: omap3: fix LTO for DM3730 (and possibly other omap3 boards)

2021-03-06 Thread Marek Behún
Adam Ford says that DM3730 needs board.c compiled without LTO flags.

Also add clock.c, since it says in Makefile that it need different
flags.

Signed-off-by: Marek Behún 
Suggested-by: Adam Ford 
---
 arch/arm/mach-omap2/omap3/Makefile | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/arch/arm/mach-omap2/omap3/Makefile 
b/arch/arm/mach-omap2/omap3/Makefile
index 91ed8ebc9f..7d22f04bbf 100644
--- a/arch/arm/mach-omap2/omap3/Makefile
+++ b/arch/arm/mach-omap2/omap3/Makefile
@@ -5,10 +5,12 @@
 
 # If clock.c is compiled for Thumb2, then it fails on OMAP3530
 CFLAGS_clock.o += -marm
+CFLAGS_REMOVE_clock.o := $(LTO_CFLAGS)
 
 obj-y  := lowlevel_init.o
 
 obj-y  += board.o
+CFLAGS_REMOVE_board.o := $(LTO_CFLAGS)
 obj-y  += boot.o
 obj-y  += clock.o
 obj-y  += sys_info.o
-- 
2.26.2



[PATCH u-boot 32/39] ARM: fix LTO for rockchip and samsung

2021-03-06 Thread Marek Behún
When building with LTO, the compiler complains about type mismatch of
function usb_gadget_handle_interrupts(). This function is defined
without parameters in files
  arch/arm/mach-rockchip/board.c
  board/samsung/common/exynos5-dt.c
but it should have one parameter, int index.

Fix this.

Signed-off-by: Marek Behún 
---
 arch/arm/mach-rockchip/board.c| 2 +-
 board/samsung/common/exynos5-dt.c | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/arch/arm/mach-rockchip/board.c b/arch/arm/mach-rockchip/board.c
index c386b52987..5304eb055c 100644
--- a/arch/arm/mach-rockchip/board.c
+++ b/arch/arm/mach-rockchip/board.c
@@ -139,7 +139,7 @@ static struct dwc3_device dwc3_device_data = {
.hsphy_mode = USBPHY_INTERFACE_MODE_UTMIW,
 };
 
-int usb_gadget_handle_interrupts(void)
+int usb_gadget_handle_interrupts(int index)
 {
dwc3_uboot_handle_interrupt(0);
return 0;
diff --git a/board/samsung/common/exynos5-dt.c 
b/board/samsung/common/exynos5-dt.c
index 4463cdcb87..1318ea716a 100644
--- a/board/samsung/common/exynos5-dt.c
+++ b/board/samsung/common/exynos5-dt.c
@@ -126,7 +126,7 @@ static struct dwc3_device dwc3_device_data = {
.index = 0,
 };
 
-int usb_gadget_handle_interrupts(void)
+int usb_gadget_handle_interrupts(int index)
 {
dwc3_uboot_handle_interrupt(0);
return 0;
-- 
2.26.2



[PATCH u-boot 34/39] armv8: SPL: discard relocation information

2021-03-06 Thread Marek Behún
For some reason when building SPL for ARMv8 with LTO, the relocation
information is not discarded.

Discard it explicitly in the linker script.

This fixes LTO build for imx8mm_venice_defconfig.

Signed-off-by: Marek Behún 
---
 arch/arm/cpu/armv8/u-boot-spl.lds | 1 +
 1 file changed, 1 insertion(+)

diff --git a/arch/arm/cpu/armv8/u-boot-spl.lds 
b/arch/arm/cpu/armv8/u-boot-spl.lds
index 0e67ab09d7..9edb662b09 100644
--- a/arch/arm/cpu/armv8/u-boot-spl.lds
+++ b/arch/arm/cpu/armv8/u-boot-spl.lds
@@ -77,6 +77,7 @@ SECTIONS
KEEP(*(.__bss_end));
} >.sdram
 
+   /DISCARD/ : { *(.rela*) }
/DISCARD/ : { *(.dynsym) }
/DISCARD/ : { *(.dynstr*) }
/DISCARD/ : { *(.dynamic*) }
-- 
2.26.2



[PATCH u-boot 30/39] ARM: imx6m: fix imx_eqos_txclk_set_rate() type mismatch for LTO

2021-03-06 Thread Marek Behún
When building imx8mp_evk_defconfig with LTO, the compiler complains
about type mismatch of function imx_eqos_txclk_set_rate() in file
  drivers/net/dwc_eth_qos.c:845:12
which contains a weak definition of this function, vs file
  arch/arm/mach-imx/imx8m/clock_imx8mm.c
which contains an implementation.

Change the type of this function in the implementation to fix this.

Signed-off-by: Marek Behún 
---
 arch/arm/mach-imx/imx8m/clock_imx8mm.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/arm/mach-imx/imx8m/clock_imx8mm.c 
b/arch/arm/mach-imx/imx8m/clock_imx8mm.c
index 4024dafca1..554ff0eaca 100644
--- a/arch/arm/mach-imx/imx8m/clock_imx8mm.c
+++ b/arch/arm/mach-imx/imx8m/clock_imx8mm.c
@@ -838,7 +838,7 @@ int set_clk_eqos(enum enet_freq type)
return 0;
 }
 
-int imx_eqos_txclk_set_rate(u32 rate)
+int imx_eqos_txclk_set_rate(ulong rate)
 {
u32 val;
u32 eqos_post_div;
-- 
2.26.2



[PATCH u-boot 31/39] ARM: fix LTO for seaboard

2021-03-06 Thread Marek Behún
When seaboard_defconfig is compiled with LTO, the compiler complains
about some instructions not being supported in ARM mode.

This is caused by arch/arm/mach-tegra/tegra20/warmboot_avp.c having
different CFLAGS declared in Makefile. This file needs to be compiled
without LTO.

Fix this by removing -flto for this file.

Signed-off-by: Marek Behún 
---
 arch/arm/mach-tegra/tegra20/Makefile | 1 +
 1 file changed, 1 insertion(+)

diff --git a/arch/arm/mach-tegra/tegra20/Makefile 
b/arch/arm/mach-tegra/tegra20/Makefile
index faaf30d068..bb17c90cca 100644
--- a/arch/arm/mach-tegra/tegra20/Makefile
+++ b/arch/arm/mach-tegra/tegra20/Makefile
@@ -10,6 +10,7 @@ endif
 # flags for any startup files it might use.
 CFLAGS_warmboot_avp.o = -march=armv4t -U__LINUX_ARM_ARCH__ \
-D__LINUX_ARM_ARCH__=4
+CFLAGS_REMOVE_warmboot_avp.o := $(LTO_CFLAGS)
 
 obj-y  += clock.o funcmux.o pinmux.o
 obj-$(CONFIG_TEGRA_LP0) += warmboot.o crypto.o warmboot_avp.o
-- 
2.26.2



[PATCH u-boot 29/39] ARM: kona: fix clk_bsc_enable() type mismatch for LTO

2021-03-06 Thread Marek Behún
When building with LTO, the compiler complains about type mismatch of
function clk_bsc_enable() in file:
  arch/arm/cpu/armv7/kona-common/clk-stubs.c
vs other files that define or use this function:
  warning: type of ‘clk_bsc_enable’ does not match original declaration.

Change the type of this function to that of the other usages.

Signed-off-by: Marek Behún 
---
 arch/arm/cpu/armv7/kona-common/clk-stubs.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/arm/cpu/armv7/kona-common/clk-stubs.c 
b/arch/arm/cpu/armv7/kona-common/clk-stubs.c
index 2dfa3f7e73..4eddaca887 100644
--- a/arch/arm/cpu/armv7/kona-common/clk-stubs.c
+++ b/arch/arm/cpu/armv7/kona-common/clk-stubs.c
@@ -14,7 +14,7 @@ int __weak clk_sdio_enable(void *base, u32 rate, u32 
*actual_ratep)
return 0;
 }
 
-int __weak clk_bsc_enable(void *base, u32 rate, u32 *actual_ratep)
+int __weak clk_bsc_enable(void *base)
 {
return 0;
 }
-- 
2.26.2



[PATCH u-boot 28/39] ARM: fix LTO for keystone

2021-03-06 Thread Marek Behún
When building keystone with LTO the compiler complains:
  Error: selected processor does not support `smc #0' in Thumb mode

Fix this by removing -flto for the file implementing these SMC calls.

Signed-off-by: Marek Behún 
---
 arch/arm/mach-keystone/Makefile | 1 +
 1 file changed, 1 insertion(+)

diff --git a/arch/arm/mach-keystone/Makefile b/arch/arm/mach-keystone/Makefile
index 3e076e12ec..6c7c25090a 100644
--- a/arch/arm/mach-keystone/Makefile
+++ b/arch/arm/mach-keystone/Makefile
@@ -9,6 +9,7 @@ obj-y   += init.o
 obj-y  += psc.o
 obj-y  += clock.o
 obj-y  += mon.o
+CFLAGS_REMOVE_mon.o := $(LTO_CFLAGS)
 ifndef CONFIG_SPL_BUILD
 obj-y  += cmd_clock.o
 obj-y  += cmd_mon.o
-- 
2.26.2



[PATCH u-boot 27/39] ARM: fix LTO for apf27

2021-03-06 Thread Marek Behún
When apf27_defconfig is built with LTO, linking complains about
undefined reference to `nand_boot`. This is because it is referenced
from inline assembly. Make it visible.

Signed-off-by: Marek Behún 
---
 drivers/mtd/nand/raw/mxc_nand_spl.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/mtd/nand/raw/mxc_nand_spl.c 
b/drivers/mtd/nand/raw/mxc_nand_spl.c
index e1e542519d..2f054b60ed 100644
--- a/drivers/mtd/nand/raw/mxc_nand_spl.c
+++ b/drivers/mtd/nand/raw/mxc_nand_spl.c
@@ -326,7 +326,7 @@ int nand_spl_load_image(uint32_t from, unsigned int size, 
void *buf)
  * configured and available since this code loads the main U-Boot image
  * from NAND into SDRAM and starts it from there.
  */
-void nand_boot(void)
+__used void nand_boot(void)
 {
__attribute__((noreturn)) void (*uboot)(void);
 
-- 
2.26.2



[PATCH u-boot 24/39] ARM: make gd a function call for LTO and set via set_gd()

2021-03-06 Thread Marek Behún
On ARM, the gd pointer is stored in registers r9 / x18. For this the
-ffixed-r9 / -ffixed-x18 flag is used when compiling, but using global
register variables causes errors when building with LTO, and these
errors are very difficult to overcome.

Richard Biener says [1]:
  Note that global register vars shouldn't be used with LTO and if they
  are restricted to just a few compilation units the recommended fix is
  to build those CUs without -flto.

We cannot do this for U-Boot since all CUs use -ffixed-reg flag.

It seems that with LTO we could in fact store the gd pointer differently
and gain performance or size benefit by allowing the compiler to use
r9 / x18. But this would need more work.

So for now, when building with LTO, go the clang way, and instead of
declaring gd a global register variable, we make it a function call via
macro.

[1] https://gcc.gnu.org/bugzilla/show_bug.cgi?id=68384

Signed-off-by: Marek Behún 
---
 arch/arm/cpu/arm926ejs/mxs/spl_boot.c |  2 +-
 arch/arm/include/asm/global_data.h|  2 +-
 arch/arm/mach-exynos/spl_boot.c   |  2 +-
 arch/arm/mach-imx/imx8m/soc.c |  2 +-
 arch/arm/mach-imx/spl_imx_romapi.c| 16 
 5 files changed, 12 insertions(+), 12 deletions(-)

diff --git a/arch/arm/cpu/arm926ejs/mxs/spl_boot.c 
b/arch/arm/cpu/arm926ejs/mxs/spl_boot.c
index a16a15e79d..66406cc857 100644
--- a/arch/arm/cpu/arm926ejs/mxs/spl_boot.c
+++ b/arch/arm/cpu/arm926ejs/mxs/spl_boot.c
@@ -122,7 +122,7 @@ void mxs_common_spl_init(const uint32_t arg, const uint32_t 
*resptr,
 {
struct mxs_spl_data *data = MXS_SPL_DATA;
uint8_t bootmode = mxs_get_bootmode_index();
-   gd = 
+   set_gd();
 
mxs_spl_fixup_vectors();
 
diff --git a/arch/arm/include/asm/global_data.h 
b/arch/arm/include/asm/global_data.h
index bb82efafa6..2aff1c467c 100644
--- a/arch/arm/include/asm/global_data.h
+++ b/arch/arm/include/asm/global_data.h
@@ -91,7 +91,7 @@ struct arch_global_data {
 
 #include 
 
-#ifdef __clang__
+#if defined(__clang__) || defined(CONFIG_LTO)
 
 #define DECLARE_GLOBAL_DATA_PTR
 #define gd get_gd()
diff --git a/arch/arm/mach-exynos/spl_boot.c b/arch/arm/mach-exynos/spl_boot.c
index 27f0dac182..722449881a 100644
--- a/arch/arm/mach-exynos/spl_boot.c
+++ b/arch/arm/mach-exynos/spl_boot.c
@@ -279,7 +279,7 @@ void memzero(void *s, size_t n)
  */
 static void setup_global_data(gd_t *gdp)
 {
-   gd = gdp;
+   set_gd(gdp);
memzero((void *)gd, sizeof(gd_t));
gd->flags |= GD_FLG_RELOC;
gd->baudrate = CONFIG_BAUDRATE;
diff --git a/arch/arm/mach-imx/imx8m/soc.c b/arch/arm/mach-imx/imx8m/soc.c
index 5f37282ff1..15d0da7060 100644
--- a/arch/arm/mach-imx/imx8m/soc.c
+++ b/arch/arm/mach-imx/imx8m/soc.c
@@ -509,7 +509,7 @@ enum boot_device get_boot_device(void)
 
ret = g_rom_api->query_boot_infor(QUERY_BT_DEV, ,
  ((uintptr_t)) ^ QUERY_BT_DEV);
-   gd = pgd;
+   set_gd(pgd);
 
if (ret != ROM_API_OKAY) {
puts("ROMAPI: failure at query_boot_info\n");
diff --git a/arch/arm/mach-imx/spl_imx_romapi.c 
b/arch/arm/mach-imx/spl_imx_romapi.c
index 9f4d95982e..d2085dabd3 100644
--- a/arch/arm/mach-imx/spl_imx_romapi.c
+++ b/arch/arm/mach-imx/spl_imx_romapi.c
@@ -45,7 +45,7 @@ static ulong spl_romapi_read_seekable(struct spl_load_info 
*load,
 
ret = g_rom_api->download_image(buf, offset, byte,
((uintptr_t)buf) ^ offset ^ byte);
-   gd = pgd;
+   set_gd(pgd);
 
if (ret == ROM_API_OKAY)
return count;
@@ -73,7 +73,7 @@ static int spl_romapi_load_image_seekable(struct 
spl_image_info *spl_image,
ret |= g_rom_api->query_boot_infor(QUERY_IMG_OFF, _offset,
   ((uintptr_t)_offset) ^ 
QUERY_IMG_OFF);
 
-   gd = pgd;
+   set_gd(pgd);
 
if (ret != ROM_API_OKAY) {
puts("ROMAPI: Failure query boot infor pagesize/offset\n");
@@ -94,7 +94,7 @@ static int spl_romapi_load_image_seekable(struct 
spl_image_info *spl_image,
size = ALIGN(sizeof(struct image_header), pagesize);
ret = g_rom_api->download_image((u8 *)header, offset, size,
((uintptr_t)header) ^ offset ^ size);
-   gd = pgd;
+   set_gd(pgd);
 
if (ret != ROM_API_OKAY) {
printf("ROMAPI: download failure offset 0x%x size 0x%x\n",
@@ -180,7 +180,7 @@ static int spl_romapi_load_image_stream(struct 
spl_image_info *spl_image,
 
ret = g_rom_api->query_boot_infor(QUERY_PAGE_SZ, ,
  ((uintptr_t)) ^ 
QUERY_PAGE_SZ);
-   gd = pgd;
+   set_gd(pgd);
 
if (ret != ROM_API_OKAY)
puts("failure at query_boot_info\n");
@@ -192,7 +192,7 @@ static int spl_romapi_load_image_stream(struct 
spl_image_info *spl_image,
for (i = 0; i < 640; i++) {
ret = g_rom_api->download_image(p, 0, 

[PATCH u-boot 26/39] ARM: fix LTO for imx28_xea

2021-03-06 Thread Marek Behún
When imx28_xea_defconfig is built with LTO, the compiler complains about
the two different declarations of _start:
   include/asm-generic/sections.has  extern void _start(void);
   arch/arm/cpu/arm926ejs/mxs/mxs.c  as  extern uint32_t _start;

Fix this.

Signed-off-by: Marek Behún 
---
 arch/arm/cpu/arm926ejs/mxs/mxs.c  | 2 +-
 arch/arm/cpu/arm926ejs/mxs/spl_boot.c | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/arch/arm/cpu/arm926ejs/mxs/mxs.c b/arch/arm/cpu/arm926ejs/mxs/mxs.c
index c9362136fb..81805e1955 100644
--- a/arch/arm/cpu/arm926ejs/mxs/mxs.c
+++ b/arch/arm/cpu/arm926ejs/mxs/mxs.c
@@ -25,6 +25,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 
 DECLARE_GLOBAL_DATA_PTR;
@@ -98,7 +99,6 @@ int arch_cpu_init(void)
 {
struct mxs_clkctrl_regs *clkctrl_regs =
(struct mxs_clkctrl_regs *)MXS_CLKCTRL_BASE;
-   extern uint32_t _start;
 
mx28_fixup_vt((uint32_t)&_start);
 
diff --git a/arch/arm/cpu/arm926ejs/mxs/spl_boot.c 
b/arch/arm/cpu/arm926ejs/mxs/spl_boot.c
index 66406cc857..0a8985b90a 100644
--- a/arch/arm/cpu/arm926ejs/mxs/spl_boot.c
+++ b/arch/arm/cpu/arm926ejs/mxs/spl_boot.c
@@ -16,6 +16,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 
 #include "mxs_init.h"
@@ -100,7 +101,6 @@ static void mxs_spl_fixup_vectors(void)
 * thus this fixup. Our vectoring table is PIC, so copying is
 * fine.
 */
-   extern uint32_t _start;
 
/* cppcheck-suppress nullPointer */
memcpy(0x0, &_start, 0x60);
-- 
2.26.2



[PATCH u-boot 25/39] ARM: fix LTO build for some thumb-interwork cases

2021-03-06 Thread Marek Behún
Fix LTO build for some thumb-interwork usecases (such as for
da850evm_defconfig), where inline assmebly such as
  mrc p15,0,r2,c1,c0,0
causes the compiler to fail during LTO linking with
  Error: selected processor does not support `mrc p15,0,r2,c1,c0,0'
 in Thumb mode

Signed-off-by: Marek Behún 
---
 arch/arm/cpu/arm926ejs/Makefile | 2 ++
 arch/arm/lib/Makefile   | 1 +
 2 files changed, 3 insertions(+)

diff --git a/arch/arm/cpu/arm926ejs/Makefile b/arch/arm/cpu/arm926ejs/Makefile
index af63d5cc5e..98aafe805a 100644
--- a/arch/arm/cpu/arm926ejs/Makefile
+++ b/arch/arm/cpu/arm926ejs/Makefile
@@ -25,6 +25,8 @@ ifndef CONFIG_HAS_THUMB2
 
 CFLAGS_cpu.o := -marm
 CFLAGS_cache.o := -marm
+CFLAGS_REMOVE_cpu.o := $(LTO_CFLAGS)
+CFLAGS_REMOVE_cache.o := $(LTO_CFLAGS)
 
 endif
 endif
diff --git a/arch/arm/lib/Makefile b/arch/arm/lib/Makefile
index 27b12e7f2b..61bef1d5af 100644
--- a/arch/arm/lib/Makefile
+++ b/arch/arm/lib/Makefile
@@ -64,6 +64,7 @@ endif
 
 obj-y  += cache.o
 obj-$(CONFIG_SYS_ARM_CACHE_CP15)   += cache-cp15.o
+CFLAGS_REMOVE_cache-cp15.o := $(LTO_CFLAGS)
 
 obj-y  += psci-dt.o
 
-- 
2.26.2



[PATCH u-boot 23/39] ARM: global_data: make set_gd() work for armv5 and armv6

2021-03-06 Thread Marek Behún
The Thumb instruction `ldr` is able to move high registers only from
armv7. For armv5 and armv6 we have to use `mov`.

Signed-off-by: Marek Behún 
---
 arch/arm/include/asm/global_data.h | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/arch/arm/include/asm/global_data.h 
b/arch/arm/include/asm/global_data.h
index fba655f3b9..bb82efafa6 100644
--- a/arch/arm/include/asm/global_data.h
+++ b/arch/arm/include/asm/global_data.h
@@ -122,8 +122,10 @@ static inline void set_gd(volatile gd_t *gd_ptr)
 {
 #ifdef CONFIG_ARM64
__asm__ volatile("ldr x18, %0\n" : : "m"(gd_ptr));
-#else
+#elif __ARM_ARCH >= 7
__asm__ volatile("ldr r9, %0\n" : : "m"(gd_ptr));
+#else
+   __asm__ volatile("mov r9, %0\n" : : "r"(gd_ptr));
 #endif
 }
 
-- 
2.26.2



[PATCH u-boot 20/39] sandbox: use sections instead of symbols for getopt array boundaries

2021-03-06 Thread Marek Behún
In style of linked lists, instead of declaring symbols for boundaries
of getopt options array in the linker script, declare corresponding
sections and retrieve the boundaries via static inline functions.

Without this clang's LTO produces binary without any getopt options,
because for some reason it thinks that array is empty (start and end
symbols are at the same address).

Signed-off-by: Marek Behún 
---
 arch/sandbox/cpu/os.c   |  3 ++-
 arch/sandbox/cpu/start.c|  3 ++-
 arch/sandbox/cpu/u-boot-spl.lds |  8 +---
 arch/sandbox/cpu/u-boot.lds |  8 +---
 arch/sandbox/include/asm/sections.h | 21 ++---
 5 files changed, 32 insertions(+), 11 deletions(-)

diff --git a/arch/sandbox/cpu/os.c b/arch/sandbox/cpu/os.c
index 3d8af0a52b..6d4fecee1d 100644
--- a/arch/sandbox/cpu/os.c
+++ b/arch/sandbox/cpu/os.c
@@ -327,7 +327,8 @@ static struct option *long_opts;
 
 int os_parse_args(struct sandbox_state *state, int argc, char *argv[])
 {
-   struct sandbox_cmdline_option **sb_opt = __u_boot_sandbox_option_start;
+   struct sandbox_cmdline_option **sb_opt =
+   __u_boot_sandbox_option_start();
size_t num_options = __u_boot_sandbox_option_count();
size_t i;
 
diff --git a/arch/sandbox/cpu/start.c b/arch/sandbox/cpu/start.c
index 483a264040..05dc04d43a 100644
--- a/arch/sandbox/cpu/start.c
+++ b/arch/sandbox/cpu/start.c
@@ -58,7 +58,8 @@ static int h_compare_opt(const void *p1, const void *p2)
 int sandbox_early_getopt_check(void)
 {
struct sandbox_state *state = state_get_current();
-   struct sandbox_cmdline_option **sb_opt = __u_boot_sandbox_option_start;
+   struct sandbox_cmdline_option **sb_opt =
+   __u_boot_sandbox_option_start();
size_t num_options = __u_boot_sandbox_option_count();
size_t i;
int max_arg_len, max_noarg_len;
diff --git a/arch/sandbox/cpu/u-boot-spl.lds b/arch/sandbox/cpu/u-boot-spl.lds
index 649abeb5ee..3a86595e85 100644
--- a/arch/sandbox/cpu/u-boot-spl.lds
+++ b/arch/sandbox/cpu/u-boot-spl.lds
@@ -13,9 +13,11 @@ SECTIONS
KEEP(*(SORT(.u_boot_list*)));
}
 
-   __u_boot_sandbox_option_start = .;
-   _u_boot_sandbox_getopt : { KEEP(*(.u_boot_sandbox_getopt)) }
-   __u_boot_sandbox_option_end = .;
+   _u_boot_sandbox_getopt : {
+   *(.u_boot_sandbox_getopt_start)
+   KEEP(*(.u_boot_sandbox_getopt))
+   *(.u_boot_sandbox_getopt_end)
+   }
 }
 
 INSERT AFTER .data;
diff --git a/arch/sandbox/cpu/u-boot.lds b/arch/sandbox/cpu/u-boot.lds
index 936da5e140..1d917a3244 100644
--- a/arch/sandbox/cpu/u-boot.lds
+++ b/arch/sandbox/cpu/u-boot.lds
@@ -13,9 +13,11 @@ SECTIONS
KEEP(*(SORT(.u_boot_list*)));
}
 
-   __u_boot_sandbox_option_start = .;
-   _u_boot_sandbox_getopt : { *(.u_boot_sandbox_getopt) }
-   __u_boot_sandbox_option_end = .;
+   _u_boot_sandbox_getopt : {
+   *(.u_boot_sandbox_getopt_start)
+   *(.u_boot_sandbox_getopt)
+   *(.u_boot_sandbox_getopt_end)
+   }
 
.__efi_runtime_start : {
*(.__efi_runtime_start)
diff --git a/arch/sandbox/include/asm/sections.h 
b/arch/sandbox/include/asm/sections.h
index fbc1bd11a3..f4351ae7db 100644
--- a/arch/sandbox/include/asm/sections.h
+++ b/arch/sandbox/include/asm/sections.h
@@ -13,12 +13,27 @@
 
 struct sandbox_cmdline_option;
 
-extern struct sandbox_cmdline_option *__u_boot_sandbox_option_start[],
-   *__u_boot_sandbox_option_end[];
+static inline struct sandbox_cmdline_option **
+__u_boot_sandbox_option_start(void)
+{
+   static char start[0] __aligned(4) __attribute__((unused))
+   __section(".u_boot_sandbox_getopt_start");
+
+   return (struct sandbox_cmdline_option **)
+}
+
+static inline struct sandbox_cmdline_option **
+__u_boot_sandbox_option_end(void)
+{
+   static char end[0] __aligned(4) __attribute__((unused))
+   __section(".u_boot_sandbox_getopt_end");
+
+   return (struct sandbox_cmdline_option **)
+}
 
 static inline size_t __u_boot_sandbox_option_count(void)
 {
-   return __u_boot_sandbox_option_end - __u_boot_sandbox_option_start;
+   return __u_boot_sandbox_option_end() - __u_boot_sandbox_option_start();
 }
 
 #endif
-- 
2.26.2



[PATCH u-boot 22/39] sandbox: enable LTO by default

2021-03-06 Thread Marek Behún
Build sandbox targets with LTO by default.

Signed-off-by: Marek Behún 
---
 arch/Kconfig | 1 +
 1 file changed, 1 insertion(+)

diff --git a/arch/Kconfig b/arch/Kconfig
index a6dab3e56d..b884b7b248 100644
--- a/arch/Kconfig
+++ b/arch/Kconfig
@@ -123,6 +123,7 @@ config SANDBOX
select SYSRESET_CMD_POWEROFF
imply BITREVERSE
select BLOBLIST
+   imply LTO
imply CMD_DM
imply CMD_EXCEPTION
imply CMD_GETTIME
-- 
2.26.2



[PATCH u-boot 21/39] sandbox: make LTO available

2021-03-06 Thread Marek Behún
Make LTO available for sandbox architecture.

Signed-off-by: Marek Behún 
---
 arch/Kconfig   | 1 +
 arch/sandbox/config.mk | 2 ++
 2 files changed, 3 insertions(+)

diff --git a/arch/Kconfig b/arch/Kconfig
index 27843cd79c..a6dab3e56d 100644
--- a/arch/Kconfig
+++ b/arch/Kconfig
@@ -101,6 +101,7 @@ config RISCV
 
 config SANDBOX
bool "Sandbox"
+   select ARCH_SUPPORTS_LTO
select BOARD_LATE_INIT
select BZIP2
select CMD_POWEROFF
diff --git a/arch/sandbox/config.mk b/arch/sandbox/config.mk
index d11b9c63c9..acf0a19dc4 100644
--- a/arch/sandbox/config.mk
+++ b/arch/sandbox/config.mk
@@ -17,12 +17,14 @@ PLATFORM_CPPFLAGS += $(shell $(SDL_CONFIG) --cflags)
 endif
 
 cmd_u-boot__ = $(CC) -o $@ -Wl,-T u-boot.lds $(u-boot-init) \
+   $(LTO_FINAL_LDFLAGS) \
-Wl,--start-group -Wl,--whole-archive \
$(u-boot-main) \
-Wl,--no-whole-archive -Wl,--end-group \
$(PLATFORM_LIBS) -Wl,-Map -Wl,u-boot.map
 
 cmd_u-boot-spl = (cd $(obj) && $(CC) -o $(SPL_BIN) -Wl,-T u-boot-spl.lds \
+   $(LTO_FINAL_LDFLAGS) \
$(patsubst $(obj)/%,%,$(u-boot-spl-init)) \
-Wl,--start-group -Wl,--whole-archive \
$(patsubst $(obj)/%,%,$(u-boot-spl-main)) \
-- 
2.26.2



[PATCH u-boot 19/39] sandbox: errno: avoid conflict with libc's errno

2021-03-06 Thread Marek Behún
When building with LTO, the system libc's `errno` variable used in
arch/sandbox/cpu/os.c conflicts with U-Boot's `errno` (defined in
lib/errno.c) with the following error:
 .../ld: errno@@GLIBC_PRIVATE: TLS definition in /lib64/libc.so.6
 section .tbss mismatches non-TLS reference in
 /tmp/u-boot.EQlEXz.ltrans0.ltrans.o

To avoid this conflict use different asm label for this variable when
CONFIG_SANDBOX is enabled.

Signed-off-by: Marek Behún 
---
 include/errno.h | 8 +++-
 lib/errno.c | 4 +++-
 2 files changed, 10 insertions(+), 2 deletions(-)

diff --git a/include/errno.h b/include/errno.h
index 3af539b9e9..652ad67306 100644
--- a/include/errno.h
+++ b/include/errno.h
@@ -8,7 +8,13 @@
 
 #include 
 
-extern int errno;
+#ifdef __SANDBOX__
+#define __errno_asm_label asm("__u_boot_errno")
+#else
+#define __errno_asm_label
+#endif
+
+extern int errno __errno_asm_label;
 
 #define __set_errno(val) do { errno = val; } while (0)
 
diff --git a/lib/errno.c b/lib/errno.c
index 8330a8fd14..ca0c756bd9 100644
--- a/lib/errno.c
+++ b/lib/errno.c
@@ -1 +1,3 @@
-int errno = 0;
+#include 
+
+int errno __errno_asm_label = 0;
-- 
2.26.2



[PATCH u-boot 17/39] build: support building with Link Time Optimizations

2021-03-06 Thread Marek Behún
Add plumbing for building U-Boot with Link Time Optimizations.

Signed-off-by: Marek Behún 
---
 Kbuild   |  2 ++
 Kconfig  | 19 +++
 Makefile | 36 
 scripts/Makefile.lib |  3 +++
 scripts/Makefile.spl | 14 ++
 5 files changed, 74 insertions(+)

diff --git a/Kbuild b/Kbuild
index 1eac091594..bf52e54051 100644
--- a/Kbuild
+++ b/Kbuild
@@ -10,6 +10,8 @@ generic-offsets-file := 
include/generated/generic-asm-offsets.h
 always  := $(generic-offsets-file)
 targets := lib/asm-offsets.s
 
+CFLAGS_REMOVE_asm-offsets.o := $(LTO_CFLAGS)
+
 $(obj)/$(generic-offsets-file): $(obj)/lib/asm-offsets.s FORCE
$(call filechk,offsets,__GENERIC_ASM_OFFSETS_H__)
 
diff --git a/Kconfig b/Kconfig
index 86f0a39bb0..ceba53926f 100644
--- a/Kconfig
+++ b/Kconfig
@@ -85,6 +85,25 @@ config SPL_OPTIMIZE_INLINING
  do what it thinks is best, which is desirable in some cases for size
  reasons.
 
+config ARCH_SUPPORTS_LTO
+   bool
+
+config LTO
+   bool "Enable Link Time Optimizations"
+   depends on ARCH_SUPPORTS_LTO
+   default n
+   help
+ This option enables Link Time Optimization (LTO), a mechanism which
+ allows the compiler to optimize between different compilation units.
+
+ This can optimize away dead code paths, resulting in smaller binary
+ size (if CC_OPTIMIZE_FOR_SIZE is enabled).
+
+ This option is not available for every architecture and may
+ introduce bugs.
+
+ If unsure, say n.
+
 config TPL_OPTIMIZE_INLINING
bool "Allow compiler to uninline functions marked 'inline' in TPL"
depends on TPL
diff --git a/Makefile b/Makefile
index 6dc47810ea..4eee0c4196 100644
--- a/Makefile
+++ b/Makefile
@@ -677,6 +677,28 @@ else
 KBUILD_CFLAGS  += -O2
 endif
 
+LTO_CFLAGS :=
+LTO_FINAL_LDFLAGS :=
+export LTO_CFLAGS LTO_FINAL_LDFLAGS
+ifdef CONFIG_LTO
+   LTO_CFLAGS  := -flto
+   LTO_FINAL_LDFLAGS   := -fwhole-program
+
+   CFLAGS_NON_EFI  += $(LTO_CFLAGS)
+
+   ifeq ($(cc-name),clang)
+   LTO_FINAL_LDFLAGS   += -flto
+   else
+   LTO_FINAL_LDFLAGS   += -fuse-linker-plugin -flto=jobserver
+
+   # use plugin aware tools
+   AR  = $(CROSS_COMPILE)gcc-ar
+   NM  = $(CROSS_COMPILE)gcc-nm
+   endif
+
+   KBUILD_CFLAGS   += $(LTO_CFLAGS)
+endif
+
 KBUILD_CFLAGS += $(call cc-option,-fno-stack-protector)
 KBUILD_CFLAGS += $(call cc-option,-fno-delete-null-pointer-checks)
 
@@ -1751,6 +1773,19 @@ ARCH_POSTLINK := $(wildcard 
$(srctree)/arch/$(ARCH)/Makefile.postlink)
 
 # Rule to link u-boot
 # May be overridden by arch/$(ARCH)/config.mk
+ifdef CONFIG_LTO
+quiet_cmd_u-boot__ ?= LTO $@
+  cmd_u-boot__ ?=  
\
+   $(CC) -nostdlib -nostartfiles   
\
+   $(LTO_FINAL_CFLAGS) $(c_flags)  
\
+   $(KBUILD_LDFLAGS:%=-Wl,%) $(LDFLAGS_u-boot:%=-Wl,%) -o $@   
\
+   -T u-boot.lds $(u-boot-init)
\
+   -Wl,--start-group -Wl,--whole-archive   
\
+   $(u-boot-main)  
\
+   -Wl,--no-whole-archive -Wl,--end-group  
\
+   $(PLATFORM_LIBS) -Wl,-Map,u-boot.map;   
\
+   $(if $(ARCH_POSTLINK), $(MAKE) -f $(ARCH_POSTLINK) $@, true)
+else
 quiet_cmd_u-boot__ ?= LD  $@
   cmd_u-boot__ ?= $(LD) $(KBUILD_LDFLAGS) $(LDFLAGS_u-boot) -o $@  
\
-T u-boot.lds $(u-boot-init)
\
@@ -1759,6 +1794,7 @@ quiet_cmd_u-boot__ ?= LD  $@
--no-whole-archive --end-group  
\
$(PLATFORM_LIBS) -Map u-boot.map;   
\
$(if $(ARCH_POSTLINK), $(MAKE) -f $(ARCH_POSTLINK) $@, true)
+endif
 
 quiet_cmd_smap = GEN common/system_map.o
 cmd_smap = \
diff --git a/scripts/Makefile.lib b/scripts/Makefile.lib
index 78543c6dd1..78bbebe7e9 100644
--- a/scripts/Makefile.lib
+++ b/scripts/Makefile.lib
@@ -419,6 +419,9 @@ $(obj)/%_efi.so: $(obj)/%.o $(obj)/efi_crt0.o 
$(obj)/efi_reloc.o $(obj)/efi_free
 
 targets += $(obj)/efi_crt0.o $(obj)/efi_reloc.o $(obj)/efi_freestanding.o
 
+CFLAGS_REMOVE_efi_reloc.o := $(LTO_CFLAGS)
+CFLAGS_REMOVE_efi_freestanding.o := $(LTO_CFLAGS)
+
 # ACPI
 # ---
 #
diff --git a/scripts/Makefile.spl b/scripts/Makefile.spl
index 889debb93c..6da5883442 100644
--- a/scripts/Makefile.spl
+++ b/scripts/Makefile.spl
@@ -419,6 +419,19 @@ 

[PATCH u-boot 16/39] build: use thin archives instead of incremental linking

2021-03-06 Thread Marek Behún
Currently we use incremental linking (ld -r) to link several object
files from one directory into one built-in.o object file containing the
linked code from that directory (and its subdirectories).

Linux has, some time ago, moved to thin archives instead.

Thin archives are archives (.a) that do not really contain the object
files, only references to them.

Using thin archives instead of incremental linking
- saves disk space
- apparently works better with dead code elimination
- makes things easier for LTO

The third point is the important one for us. With incremental linking
there are several options how to do LTO, and that would unnecessarily
complicate things.

On the other hand, by using thin archives we can make (via the
--whole-archive use flag) the final linking behave as if we passed all
the object files from the archives to the linking program as arguments.

We also need to use the P flag for ar, otherwise final linking may fail.

Signed-off-by: Marek Behún 
---
 Makefile   |  4 ++--
 arch/sandbox/config.mk | 10 +++---
 scripts/Makefile.build | 16 
 scripts/Makefile.spl   |  4 ++--
 4 files changed, 19 insertions(+), 15 deletions(-)

diff --git a/Makefile b/Makefile
index 7b0ba9df9a..6dc47810ea 100644
--- a/Makefile
+++ b/Makefile
@@ -1754,9 +1754,9 @@ ARCH_POSTLINK := $(wildcard 
$(srctree)/arch/$(ARCH)/Makefile.postlink)
 quiet_cmd_u-boot__ ?= LD  $@
   cmd_u-boot__ ?= $(LD) $(KBUILD_LDFLAGS) $(LDFLAGS_u-boot) -o $@  
\
-T u-boot.lds $(u-boot-init)
\
-   --start-group   
\
+   --start-group --whole-archive   
\
$(u-boot-main)  
\
-   --end-group 
\
+   --no-whole-archive --end-group  
\
$(PLATFORM_LIBS) -Map u-boot.map;   
\
$(if $(ARCH_POSTLINK), $(MAKE) -f $(ARCH_POSTLINK) $@, true)
 
diff --git a/arch/sandbox/config.mk b/arch/sandbox/config.mk
index 189e9c2b0c..d11b9c63c9 100644
--- a/arch/sandbox/config.mk
+++ b/arch/sandbox/config.mk
@@ -17,13 +17,17 @@ PLATFORM_CPPFLAGS += $(shell $(SDL_CONFIG) --cflags)
 endif
 
 cmd_u-boot__ = $(CC) -o $@ -Wl,-T u-boot.lds $(u-boot-init) \
-   -Wl,--start-group $(u-boot-main) -Wl,--end-group \
+   -Wl,--start-group -Wl,--whole-archive \
+   $(u-boot-main) \
+   -Wl,--no-whole-archive -Wl,--end-group \
$(PLATFORM_LIBS) -Wl,-Map -Wl,u-boot.map
 
 cmd_u-boot-spl = (cd $(obj) && $(CC) -o $(SPL_BIN) -Wl,-T u-boot-spl.lds \
$(patsubst $(obj)/%,%,$(u-boot-spl-init)) \
-   -Wl,--start-group $(patsubst $(obj)/%,%,$(u-boot-spl-main)) \
-   $(patsubst $(obj)/%,%,$(u-boot-spl-platdata)) -Wl,--end-group \
+   -Wl,--start-group -Wl,--whole-archive \
+   $(patsubst $(obj)/%,%,$(u-boot-spl-main)) \
+   $(patsubst $(obj)/%,%,$(u-boot-spl-platdata)) \
+   -Wl,--no-whole-archive -Wl,--end-group \
$(PLATFORM_LIBS) -Wl,-Map -Wl,u-boot-spl.map -Wl,--gc-sections)
 
 CONFIG_ARCH_DEVICE_TREE := sandbox
diff --git a/scripts/Makefile.build b/scripts/Makefile.build
index 705a886cb9..a9a02d7d33 100644
--- a/scripts/Makefile.build
+++ b/scripts/Makefile.build
@@ -331,12 +331,11 @@ $(sort $(subdir-obj-y)): $(subdir-ym) ;
 # Rule to compile a set of .o files into one .o file
 #
 ifdef builtin-target
-quiet_cmd_link_o_target = LD  $@
+quiet_cmd_link_o_target = AR  $@
 # If the list of objects to link is empty, just create an empty built-in.o
 cmd_link_o_target = $(if $(strip $(obj-y)),\
- $(LD) $(ld_flags) -r -o $@ $(filter $(obj-y), $^) \
- $(cmd_secanalysis),\
- rm -f $@; $(AR) rcs$(KBUILD_ARFLAGS) $@)
+ rm -f $@; $(AR) cDPrsT $@ $(filter $(obj-y), $^), \
+ rm -f $@; $(AR) cPrsT$(KBUILD_ARFLAGS) $@)
 
 $(builtin-target): $(obj-y) FORCE
$(call if_changed,link_o_target)
@@ -362,7 +361,7 @@ $(modorder-target): $(subdir-ym) FORCE
 #
 ifdef lib-target
 quiet_cmd_link_l_target = AR  $@
-cmd_link_l_target = rm -f $@; $(AR) rcs$(KBUILD_ARFLAGS) $@ $(lib-y)
+cmd_link_l_target = rm -f $@; $(AR) cPrs$(KBUILD_ARFLAGS) $@ $(lib-y)
 
 $(lib-target): $(lib-y) FORCE
$(call if_changed,link_l_target)
@@ -382,10 +381,11 @@ $(filter $(addprefix $(obj)/, \
 $($(subst $(obj)/,,$(@:.o=-objs)))\
 $($(subst $(obj)/,,$(@:.o=-y, $^)
 
-quiet_cmd_link_multi-y = LD  $@
-cmd_link_multi-y = $(LD) $(ld_flags) -r -o $@ $(link_multi_deps) 
$(cmd_secanalysis)
 
-quiet_cmd_link_multi-m = LD [M]  $@
+quiet_cmd_link_multi-y = AR  $@
+cmd_link_multi-y = rm -f $@; $(AR) cDPrsT $@ $(link_multi_deps)
+
+quiet_cmd_link_multi-m = AR [M]  $@
 cmd_link_multi-m = 

[PATCH u-boot 18/39] build: LTO: move platform libs into --start-group list

2021-03-06 Thread Marek Behún
When building with LTO, move $(PLATFORM_LIBS) into the --start-group /
--end-group list.
Otherwise some functions declared in assembly may not be resolved and
linking may fail.

Signed-off-by: Marek Behún 
---
 Makefile | 3 ++-
 scripts/Makefile.spl | 3 ++-
 2 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/Makefile b/Makefile
index 4eee0c4196..0f538270d7 100644
--- a/Makefile
+++ b/Makefile
@@ -1782,8 +1782,9 @@ quiet_cmd_u-boot__ ?= LTO $@
-T u-boot.lds $(u-boot-init)
\
-Wl,--start-group -Wl,--whole-archive   
\
$(u-boot-main)  
\
+   $(PLATFORM_LIBS)
\
-Wl,--no-whole-archive -Wl,--end-group  
\
-   $(PLATFORM_LIBS) -Wl,-Map,u-boot.map;   
\
+   -Wl,-Map,u-boot.map;
\
$(if $(ARCH_POSTLINK), $(MAKE) -f $(ARCH_POSTLINK) $@, true)
 else
 quiet_cmd_u-boot__ ?= LD  $@
diff --git a/scripts/Makefile.spl b/scripts/Makefile.spl
index 6da5883442..d89917ca8e 100644
--- a/scripts/Makefile.spl
+++ b/scripts/Makefile.spl
@@ -428,8 +428,9 @@ quiet_cmd_u-boot-spl ?= LTO $@
-Wl,--start-group -Wl,--whole-archive   
\
$(patsubst $(obj)/%,%,$(u-boot-spl-main))   
\
$(patsubst $(obj)/%,%,$(u-boot-spl-platdata))   
\
+   $(PLATFORM_LIBS)
\
-Wl,--no-whole-archive -Wl,--end-group  
\
-   $(PLATFORM_LIBS) -Wl,-Map,$(SPL_BIN).map -o $(SPL_BIN)  
\
+   -Wl,-Map,$(SPL_BIN).map -o $(SPL_BIN)   
\
)
 else
 quiet_cmd_u-boot-spl ?= LD  $@
-- 
2.26.2



[PATCH u-boot 14/39] lib: crc32: make the crc_table variable non-const

2021-03-06 Thread Marek Behún
When compiling with LTO, the compiler fails with an error saying that
`crc_table` causes a section type conflict with `efi_var_buf`.

This is because both are declared to be in the same section (via macro
`__efi_runtime_data`), but one is const while the other is not.

Make this variable non-const in order to fix this.

Signed-off-by: Marek Behún 
---
 lib/crc32.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lib/crc32.c b/lib/crc32.c
index e9be3bf386..c033449cff 100644
--- a/lib/crc32.c
+++ b/lib/crc32.c
@@ -88,7 +88,7 @@ static void __efi_runtime make_crc_table(void)
  * Table of CRC-32's of all single-byte values (made by make_crc_table)
  */
 
-static const uint32_t __efi_runtime_data crc_table[256] = {
+static uint32_t __efi_runtime_data crc_table[256] = {
 tole(0xL), tole(0x77073096L), tole(0xee0e612cL), tole(0x990951baL),
 tole(0x076dc419L), tole(0x706af48fL), tole(0xe963a535L), tole(0x9e6495a3L),
 tole(0x0edb8832L), tole(0x79dcb8a4L), tole(0xe0d5e91eL), tole(0x97d2d988L),
-- 
2.26.2



[PATCH u-boot 15/39] Makefile, Makefile.spl: cosmetic change

2021-03-06 Thread Marek Behún
Indent the linking commands so that they look cosmetically better.

Signed-off-by: Marek Behún 
---
 Makefile | 12 +++-
 scripts/Makefile.spl | 15 +--
 2 files changed, 16 insertions(+), 11 deletions(-)

diff --git a/Makefile b/Makefile
index 68ce5195b2..7b0ba9df9a 100644
--- a/Makefile
+++ b/Makefile
@@ -1752,11 +1752,13 @@ ARCH_POSTLINK := $(wildcard 
$(srctree)/arch/$(ARCH)/Makefile.postlink)
 # Rule to link u-boot
 # May be overridden by arch/$(ARCH)/config.mk
 quiet_cmd_u-boot__ ?= LD  $@
-  cmd_u-boot__ ?= $(LD) $(KBUILD_LDFLAGS) $(LDFLAGS_u-boot) -o $@ \
-  -T u-boot.lds $(u-boot-init) \
-  --start-group $(u-boot-main) --end-group \
-  $(PLATFORM_LIBS) -Map u-boot.map;\
-  $(if $(ARCH_POSTLINK), $(MAKE) -f $(ARCH_POSTLINK) $@, true)
+  cmd_u-boot__ ?= $(LD) $(KBUILD_LDFLAGS) $(LDFLAGS_u-boot) -o $@  
\
+   -T u-boot.lds $(u-boot-init)
\
+   --start-group   
\
+   $(u-boot-main)  
\
+   --end-group 
\
+   $(PLATFORM_LIBS) -Map u-boot.map;   
\
+   $(if $(ARCH_POSTLINK), $(MAKE) -f $(ARCH_POSTLINK) $@, true)
 
 quiet_cmd_smap = GEN common/system_map.o
 cmd_smap = \
diff --git a/scripts/Makefile.spl b/scripts/Makefile.spl
index ea4e045769..3b5f5046c9 100644
--- a/scripts/Makefile.spl
+++ b/scripts/Makefile.spl
@@ -420,12 +420,15 @@ $(obj)/$(SPL_BIN).sym: $(obj)/$(SPL_BIN) FORCE
 # Rule to link u-boot-spl
 # May be overridden by arch/$(ARCH)/config.mk
 quiet_cmd_u-boot-spl ?= LD  $@
-  cmd_u-boot-spl ?= (cd $(obj) && $(LD) $(KBUILD_LDFLAGS) $(LDFLAGS_$(@F)) 
\
-  $(patsubst $(obj)/%,%,$(u-boot-spl-init)) --start-group \
-  $(patsubst $(obj)/%,%,$(u-boot-spl-main))  \
-  $(patsubst $(obj)/%,%,$(u-boot-spl-platdata)) \
-  --end-group \
-  $(PLATFORM_LIBS) -Map $(SPL_BIN).map -o $(SPL_BIN))
+  cmd_u-boot-spl ?= (cd $(obj) && \
+   $(LD) $(KBUILD_LDFLAGS) $(LDFLAGS_$(@F))\
+   $(patsubst $(obj)/%,%,$(u-boot-spl-init))   \
+   --start-group   \
+   $(patsubst $(obj)/%,%,$(u-boot-spl-main))   \
+   $(patsubst $(obj)/%,%,$(u-boot-spl-platdata))   \
+   --end-group \
+   $(PLATFORM_LIBS) -Map $(SPL_BIN).map -o $(SPL_BIN)  \
+   )
 
 $(obj)/$(SPL_BIN): $(u-boot-spl-platdata) $(u-boot-spl-init) \
$(u-boot-spl-main) $(obj)/u-boot-spl.lds FORCE
-- 
2.26.2



[PATCH u-boot 13/39] efi_loader: fix warning when linking with LTO

2021-03-06 Thread Marek Behún
When linking with LTO, the compiler complains about type mismatch of
variables `__efi_runtime_start`, `__efi_runtime_stop`,
`__efi_runtime_rel_start` and `__efi_runtime_rel_stop`:

 include/efi_loader.h:218:21: warning: type of ‘__efi_runtime_start’
   does not match original
   declaration [-Wlto-type-mismatch]
218 | extern unsigned int __efi_runtime_start, __efi_runtime_stop;
| ^
  arch/sandbox/lib/sections.c:7:6: note: ‘__efi_runtime_start’ was
 previously declared here
  7 | char __efi_runtime_start[0] __attribute__((section(".__efi_run
|  ^

Change the type to char[] in include/efi_loader.h.

Signed-off-by: Marek Behún 
---
 include/efi_loader.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/include/efi_loader.h b/include/efi_loader.h
index e38b41952d..a8281b3c95 100644
--- a/include/efi_loader.h
+++ b/include/efi_loader.h
@@ -215,8 +215,8 @@ extern const efi_guid_t efi_guid_capsule_report;
 /* GUID of firmware management protocol */
 extern const efi_guid_t efi_guid_firmware_management_protocol;
 
-extern unsigned int __efi_runtime_start, __efi_runtime_stop;
-extern unsigned int __efi_runtime_rel_start, __efi_runtime_rel_stop;
+extern char __efi_runtime_start[], __efi_runtime_stop[];
+extern char __efi_runtime_rel_start[], __efi_runtime_rel_stop[];
 
 /**
  * struct efi_open_protocol_info_item - open protocol info item
-- 
2.26.2



[PATCH u-boot 12/39] string: make memcpy() and memset() visible to fix LTO linking errors

2021-03-06 Thread Marek Behún
It seems that sometimes (happening on ARM64, for example with
turris_mox_defconfig) GCC, when linking with LTO, changes the symbol
names of some functions, for example lib/string.c's memcpy() function to
memcpy.isra.0.

This is a problem however when GCC for a code such as this:
struct some_struct *info = get_some_struct();
struct some struct tmpinfo;
tmpinfo = *info;
emits a call to memcpy() by builtin behaviour, to copy *info to tmpinfo.
memset() can be generated sometimes as well.

This then results in the following linking error:
  .../lz4.c:93: undefined reference to `memcpy'
  .../uuid.c:206: more undefined references to `memcpy' follow

Make memcpy() and memset() visible by using the __used macro to avoid
this error.

Signed-off-by: Marek Behún 
---
 lib/string.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/lib/string.c b/lib/string.c
index 73b984123d..bfda3952ee 100644
--- a/lib/string.c
+++ b/lib/string.c
@@ -16,6 +16,7 @@
  */
 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -490,7 +491,7 @@ char *strswab(const char *s)
  *
  * Do not use memset() to access IO space, use memset_io() instead.
  */
-void * memset(void * s,int c,size_t count)
+__used void * memset(void * s,int c,size_t count)
 {
unsigned long *sl = (unsigned long *) s;
char *s8;
@@ -529,7 +530,7 @@ void * memset(void * s,int c,size_t count)
  * You should not use this function to access IO space, use memcpy_toio()
  * or memcpy_fromio() instead.
  */
-void * memcpy(void *dest, const void *src, size_t count)
+__used void * memcpy(void *dest, const void *src, size_t count)
 {
unsigned long *dl = (unsigned long *)dest, *sl = (unsigned long *)src;
char *d8, *s8;
-- 
2.26.2



[PATCH u-boot 11/39] binman: declare symbols externally visible

2021-03-06 Thread Marek Behún
Use the `externally_visible` attribute to declare binman symbols
externally visible, so that when building with LTO the compiler does not
optimize this data away.

Signed-off-by: Marek Behún 
---
 include/binman_sym.h | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/include/binman_sym.h b/include/binman_sym.h
index 72e6765fe5..f9c0e681c9 100644
--- a/include/binman_sym.h
+++ b/include/binman_sym.h
@@ -34,7 +34,8 @@
  */
 #define binman_sym_declare(_type, _entry_name, _prop_name) \
_type binman_symname(_entry_name, _prop_name) \
-   __attribute__((aligned(4), unused, section(".binman_sym")))
+   __attribute__((aligned(4), unused, externally_visible, \
+   section(".binman_sym")))
 
 /**
  * binman_sym_extern() - Declare a extern symbol that will be used at run-time
@@ -59,7 +60,7 @@
  */
 #define binman_sym_declare_optional(_type, _entry_name, _prop_name) \
_type binman_symname(_entry_name, _prop_name) \
-   __attribute__((aligned(4), weak, unused, \
+   __attribute__((aligned(4), weak, unused, externally_visible \
section(".binman_sym")))
 
 /**
-- 
2.26.2



[PATCH u-boot 10/39] linker_lists: declare lists and entries as __ADDRESSABLE for LTO

2021-03-06 Thread Marek Behún
Use the __ADDRESSABLE() macro to make entries and lists declared by
ll_entry_declare() and ll_entry_declare_list() addressable so that when
building with LTO the compiler does not optimize this data away.

Signed-off-by: Marek Behún 
---
 include/linker_lists.h | 8 ++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/include/linker_lists.h b/include/linker_lists.h
index 815a90691a..c9c3b3c2ad 100644
--- a/include/linker_lists.h
+++ b/include/linker_lists.h
@@ -88,7 +88,9 @@
  *   .y = 4,
  *   };
  */
-#define ll_entry_declare(_type, _name, _list) \
+#define ll_entry_declare(_type, _name, _list)  \
+   __lldecl(_type, _name, _list);  \
+   __ADDRESSABLE(__llname(_name, _list));  \
__lldecl(_type, _name, _list)
 
 /**
@@ -109,7 +111,9 @@
  *{ .x = 1, .y = 7 }
  *   };
  */
-#define ll_entry_declare_list(_type, _name, _list) \
+#define ll_entry_declare_list(_type, _name, _list) \
+   __lldecl(_type, _name, _list)[];\
+   __ADDRESSABLE(__llname(_name, _list));  \
__lldecl(_type, _name, _list)[]
 
 /*
-- 
2.26.2



[PATCH u-boot 06/39] treewide: Convert macro and uses of __section(foo) to __section("foo")

2021-03-06 Thread Marek Behún
This commit does the same thing as Linux commit 33def8498fdd.

Use a more generic form for __section that requires quotes to avoid
complications with clang and gcc differences.

Remove the quote operator # from compiler_attributes.h __section macro.

Convert all unquoted __section(foo) uses to quoted __section("foo").
Also convert __attribute__((section("foo"))) uses to __section("foo")
even if the __attribute__ has multiple list entry forms.

Signed-off-by: Marek Behún 
---
 arch/arm/cpu/arm926ejs/spear/spl.c|  2 +-
 arch/arm/cpu/armv7/ls102xa/ls102xa_psci.c |  2 +-
 arch/arm/cpu/armv8/fsl-layerscape/spl.c   |  2 +-
 arch/arm/cpu/armv8/spl_data.c |  4 +--
 arch/arm/include/asm/secure.h |  6 ++---
 arch/arm/include/asm/setup.h  |  2 +-
 arch/arm/lib/sections.c   | 31 ---
 arch/arm/lib/spl.c|  2 +-
 arch/arm/mach-at91/spl.c  |  2 +-
 arch/arm/mach-k3/am6_init.c   |  2 +-
 arch/arm/mach-k3/j721e_init.c |  4 +--
 arch/arm/mach-mvebu/mbus.c|  4 +--
 arch/arm/mach-mvebu/timer.c   |  2 +-
 arch/arm/mach-nexell/clock.c  |  6 ++---
 arch/arm/mach-nexell/timer.c  |  6 ++---
 arch/arm/mach-socfpga/spl_a10.c   |  2 +-
 arch/arm/mach-sunxi/board.c   |  2 +-
 arch/arm/mach-tegra/board.c   |  2 +-
 arch/arm/mach-tegra/cboot.c   |  8 +++---
 arch/mips/mach-jz47xx/jz4780/jz4780.c |  2 +-
 arch/nds32/include/asm/setup.h|  6 ++---
 arch/powerpc/include/asm/cache.h  |  4 +--
 arch/riscv/cpu/cpu.c  |  4 +--
 arch/sandbox/include/asm/getopt.h |  2 +-
 arch/sandbox/lib/sections.c   |  9 ---
 arch/x86/cpu/coreboot/tables.c|  2 +-
 arch/x86/cpu/coreboot/timestamp.c |  2 +-
 arch/x86/lib/sections.c   |  9 ---
 arch/xtensa/cpu/cpu.c |  2 +-
 board/bosch/shc/board.c   |  2 +-
 board/broadcom/bcmstb/bcmstb.c|  2 +-
 board/samsung/arndale/arndale_spl.c   |  2 +-
 board/samsung/smdk5250/smdk5250_spl.c |  2 +-
 board/samsung/smdk5420/smdk5420_spl.c |  2 +-
 board/siemens/draco/board.c   |  2 +-
 board/xilinx/common/fru_ops.c |  2 +-
 drivers/bios_emulator/biosemu.c   |  4 +--
 drivers/firmware/psci.c   |  2 +-
 drivers/pinctrl/nxp/pinctrl-imx5.c|  2 +-
 drivers/pinctrl/nxp/pinctrl-imx7.c|  2 +-
 drivers/pinctrl/nxp/pinctrl-imx8m.c   |  2 +-
 drivers/power/pmic/pmic_tps62362.c|  2 +-
 drivers/power/pmic/pmic_tps65217.c|  2 +-
 drivers/power/pmic/pmic_tps65218.c|  2 +-
 drivers/power/pmic/pmic_tps65910.c|  2 +-
 drivers/serial/serial_pl01x.c |  4 +--
 include/efi_loader.h  |  4 +--
 include/linker_lists.h| 24 +-
 include/linux/compiler.h  |  8 +++---
 include/linux/compiler_attributes.h   |  2 +-
 lib/trace.c   |  4 +--
 51 files changed, 108 insertions(+), 105 deletions(-)

diff --git a/arch/arm/cpu/arm926ejs/spear/spl.c 
b/arch/arm/cpu/arm926ejs/spear/spl.c
index 08b98a2d06..b5b9945a87 100644
--- a/arch/arm/cpu/arm926ejs/spear/spl.c
+++ b/arch/arm/cpu/arm926ejs/spear/spl.c
@@ -22,7 +22,7 @@
  * The BSS cannot be used for this purpose because it will be zeroed after
  * having stored the pointer, so force the location to the data section.
  */
-u32 bootrom_stash_sp __attribute__((section(".data")));
+u32 bootrom_stash_sp __section(".data");
 
 static void ddr_clock_init(void)
 {
diff --git a/arch/arm/cpu/armv7/ls102xa/ls102xa_psci.c 
b/arch/arm/cpu/armv7/ls102xa/ls102xa_psci.c
index 4a4b3c6f23..28a7945207 100644
--- a/arch/arm/cpu/armv7/ls102xa/ls102xa_psci.c
+++ b/arch/arm/cpu/armv7/ls102xa/ls102xa_psci.c
@@ -13,7 +13,7 @@
 #include 
 #include "fsl_epu.h"
 
-#define __secure __attribute__((section("._secure.text")))
+#define __secure __section("._secure.text")
 
 #define CCSR_GICD_CTLR 0x1000
 #define CCSR_GICC_CTLR 0x2000
diff --git a/arch/arm/cpu/armv8/fsl-layerscape/spl.c 
b/arch/arm/cpu/armv8/fsl-layerscape/spl.c
index d5131bcf4b..f3e7e07412 100644
--- a/arch/arm/cpu/armv8/fsl-layerscape/spl.c
+++ b/arch/arm/cpu/armv8/fsl-layerscape/spl.c
@@ -40,7 +40,7 @@ u32 spl_boot_device(void)
 #ifdef CONFIG_SPL_BUILD
 
 /* Define board data structure */
-static struct bd_info bdata __attribute__ ((section(".data")));
+static struct bd_info bdata __section(".data");
 
 void spl_board_init(void)
 {
diff --git a/arch/arm/cpu/armv8/spl_data.c b/arch/arm/cpu/armv8/spl_data.c
index 8fd986a67a..8f1231c86e 100644
--- a/arch/arm/cpu/armv8/spl_data.c
+++ b/arch/arm/cpu/armv8/spl_data.c
@@ -6,8 +6,8 @@
 #include 
 #include 
 
-char __data_save_start[0] __section(.__data_save_start);
-char __data_save_end[0] 

[PATCH u-boot 09/39] test/py: improve regular expression for ut subtest symbol matcher

2021-03-06 Thread Marek Behún
Improve the regular expression that matches unittest symbols in
u-boot.sym.

Currently we do not enforce no prefix in symbol string, but with the
soon to come change in linker lists declaring lists and entries with the
__ADDRESSABLE macro (because of LTO), the symbol file will contain for
every symbol of the form
  _u_boot_list_2_X_2_Y
also symbol
  __UNIQUE_ID___addressable__u_boot_list_2_X_2_YN,
(where N at the end is some number).

In order to avoid matching these additional symbols, ensure that the
character before "_u_boot_list_2" is not a symbol name character.

Signed-off-by: Marek Behún 
---
 test/py/conftest.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/test/py/conftest.py b/test/py/conftest.py
index 9bfd926345..3ea3fa5220 100644
--- a/test/py/conftest.py
+++ b/test/py/conftest.py
@@ -226,7 +226,7 @@ def pytest_configure(config):
 import u_boot_console_exec_attach
 console = u_boot_console_exec_attach.ConsoleExecAttach(log, ubconfig)
 
-re_ut_test_list = re.compile(r'_u_boot_list_2_(.*)_test_2_\1_test_(.*)\s*$')
+re_ut_test_list = 
re.compile(r'[^a-zA-Z0-9_]_u_boot_list_2_(.*)_test_2_\1_test_(.*)\s*$')
 def generate_ut_subtest(metafunc, fixture_name, sym_path):
 """Provide parametrization for a ut_subtest fixture.
 
-- 
2.26.2



[PATCH u-boot 08/39] linker_lists: prepare macros to avoid code repetition

2021-03-06 Thread Marek Behún
Prepare private macros expanding to linker list entry symbol name and
declaration to avoid nasty code repetition in the next patch.

We also avoid some code repetition in current code with these macros.

Signed-off-by: Marek Behún 
---
 include/linker_lists.h | 46 --
 1 file changed, 31 insertions(+), 15 deletions(-)

diff --git a/include/linker_lists.h b/include/linker_lists.h
index 0259d34919..815a90691a 100644
--- a/include/linker_lists.h
+++ b/include/linker_lists.h
@@ -19,6 +19,27 @@
 
 #if !defined(__ASSEMBLY__)
 
+/**
+ * __llname() - Private macro expanding to symbol name for linker list entry
+ * @_name: Name of the entry
+ * @_list: name of the list. Should contain only characters allowed
+ * in a C variable name!
+ */
+#define __llname(_name, _list) \
+   _u_boot_list_2_##_list##_2_##_name
+
+/**
+ * __lldecl() - Private macro expanding to declaration of linker list entry
+ * @_type: Data type of the entry
+ * @_name: Name of the entry
+ * @_list: name of the list. Should contain only characters allowed
+ * in a C variable name!
+ */
+#define __lldecl(_type, _name, _list)  \
+   _type __aligned(4) __attribute__((unused))  \
+   __section(".u_boot_list_2_"#_list"_2_"#_name)   \
+   __llname(_name, _list)
+
 /**
  * llsym() - Access a linker-generated array entry
  * @_type: Data type of the entry
@@ -27,7 +48,7 @@
  * in a C variable name!
  */
 #define llsym(_type, _name, _list) \
-   ((_type *)&_u_boot_list_2_##_list##_2_##_name)
+   ((_type *)&__llname(_name, _list))
 
 /**
  * ll_entry_declare() - Declare linker-generated array entry
@@ -67,10 +88,8 @@
  *   .y = 4,
  *   };
  */
-#define ll_entry_declare(_type, _name, _list)  \
-   _type _u_boot_list_2_##_list##_2_##_name __aligned(4)   \
-   __attribute__((unused)) \
-   __section(".u_boot_list_2_"#_list"_2_"#_name)
+#define ll_entry_declare(_type, _name, _list) \
+   __lldecl(_type, _name, _list)
 
 /**
  * ll_entry_declare_list() - Declare a list of link-generated array entries
@@ -90,10 +109,8 @@
  *{ .x = 1, .y = 7 }
  *   };
  */
-#define ll_entry_declare_list(_type, _name, _list) \
-   _type _u_boot_list_2_##_list##_2_##_name[] __aligned(4) \
-   __attribute__((unused)) \
-   __section(".u_boot_list_2_"#_list"_2_"#_name)
+#define ll_entry_declare_list(_type, _name, _list) \
+   __lldecl(_type, _name, _list)[]
 
 /*
  * We need a 0-byte-size type for iterator symbols, and the compiler
@@ -203,12 +220,11 @@
  *   ...
  *   struct my_sub_cmd *c = ll_entry_get(struct my_sub_cmd, my_sub_cmd, 
cmd_sub);
  */
-#define ll_entry_get(_type, _name, _list)  \
-   ({  \
-   extern _type _u_boot_list_2_##_list##_2_##_name;\
-   _type *_ll_result = \
-   &_u_boot_list_2_##_list##_2_##_name;\
-   _ll_result; \
+#define ll_entry_get(_type, _name, _list)  \
+   ({  \
+   extern _type __llname(_name, _list);\
+   _type *_ll_result = &__llname(_name, _list);\
+   _ll_result; \
})
 
 /**
-- 
2.26.2



[PATCH u-boot 07/39] compiler.h: align the __ADDRESSABLE macro with Linux' version

2021-03-06 Thread Marek Behún
Use UNIQUE_ID in the __ADDRESSABLE macro.

Signed-off-by: Marek Behún 
---
 include/linux/compiler.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/include/linux/compiler.h b/include/linux/compiler.h
index 82a8a4ede9..98dd3fc4cc 100644
--- a/include/linux/compiler.h
+++ b/include/linux/compiler.h
@@ -295,7 +295,7 @@ unsigned long read_word_at_a_time(const void *addr)
  */
 #define __ADDRESSABLE(sym) \
static void * __section(".discard.addressable") __used \
-   __PASTE(__addressable_##sym, __LINE__) = (void *)
+   __UNIQUE_ID(__PASTE(__addressable_,sym)) = (void *)
 
 /**
  * offset_to_ptr - convert a relative memory offset to an absolute pointer
-- 
2.26.2



[PATCH u-boot-marvell 02/39] ddr: marvell: axp: fix array types have different bounds warning

2021-03-06 Thread Marek Behún
The arrays `pbs_dq_mapping`, `div_ratio1to1` and `div_ratio2to1` have
different bounds declared in header files where these variables are also
defined from the ones declared in source files.

This causes the compiler to complain (when building with LTO):
  ddr3_sdram.c:24:12: warning: type of ‘pbs_dq_mapping’ does not match
   original declaration
   [-Wlto-type-mismatch]
  ddr3_patterns_64bit.h:911:5: note: array types have different bounds
  ddr3_patterns_64bit.h:911:5: note: ‘pbs_dq_mapping’ was previously
 declared here

ddr3_dfs.c:45:11: warning: type of ‘div_ratio1to1’ does not match
   original declaration [-Wlto-type-mismatch]
ddr3_axp_vars.h:167:4: note: array types have different bounds
ddr3_axp_vars.h:167:4: note: ‘div_ratio1to1’ was previously declared
 here

ddr3_dfs.c:46:11: warning: type of ‘div_ratio2to1’ does not match
   original declaration [-Wlto-type-mismatch]
ddr3_axp_vars.h:196:4: note: array types have different bounds
ddr3_axp_vars.h:196:4: note: ‘div_ratio2to1’ was previously declared
 here

CI managed to trigger this as an error when compiling with LTO for AXP.

Fix this by using values from the header files, which seem to be the
correct ones.

Signed-off-by: Marek Behún 
---
 drivers/ddr/marvell/axp/ddr3_dfs.c   | 4 ++--
 drivers/ddr/marvell/axp/ddr3_sdram.c | 2 +-
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/ddr/marvell/axp/ddr3_dfs.c 
b/drivers/ddr/marvell/axp/ddr3_dfs.c
index b58c0fe01e..2a4596680b 100644
--- a/drivers/ddr/marvell/axp/ddr3_dfs.c
+++ b/drivers/ddr/marvell/axp/ddr3_dfs.c
@@ -42,8 +42,8 @@ extern u8 div_ratio[CLK_VCO][CLK_DDR];
 extern void get_target_freq(u32 freq_mode, u32 *ddr_freq, u32 *hclk_ps);
 #else
 extern u16 odt_dynamic[ODT_OPT][MAX_CS];
-extern u8 div_ratio1to1[CLK_CPU][CLK_DDR];
-extern u8 div_ratio2to1[CLK_CPU][CLK_DDR];
+extern u8 div_ratio1to1[CLK_VCO][CLK_DDR];
+extern u8 div_ratio2to1[CLK_VCO][CLK_DDR];
 #endif
 extern u16 odt_static[ODT_OPT][MAX_CS];
 
diff --git a/drivers/ddr/marvell/axp/ddr3_sdram.c 
b/drivers/ddr/marvell/axp/ddr3_sdram.c
index 3a266c6de4..0b150b20f3 100644
--- a/drivers/ddr/marvell/axp/ddr3_sdram.c
+++ b/drivers/ddr/marvell/axp/ddr3_sdram.c
@@ -21,7 +21,7 @@ extern u32 pbs_pattern_32b[2][LEN_PBS_PATTERN];
 #if defined(MV88F78X60)
 extern u32 pbs_pattern_64b[2][LEN_PBS_PATTERN];
 #endif
-extern u32 pbs_dq_mapping[PUP_NUM_64BIT][DQ_NUM];
+extern u32 pbs_dq_mapping[PUP_NUM_64BIT + 1][DQ_NUM];
 
 #if defined(MV88F78X60) || defined(MV88F672X)
 /* PBS locked dq (per pup) */
-- 
2.26.2



[PATCH u-boot-dm 03/39] regmap: fix a serious pointer casting bug

2021-03-06 Thread Marek Behún
There is a serious bug in regmap_read() and regmap_write() functions
where an uint pointer is cast to (void *) which is then cast to (u8 *),
(u16 *), (u32 *) or (u64 *), depending on register width of the map.

For example given a regmap with 16-bit register width the code
int val = 0x1234;
regmap_read(map, 0, );
only changes the lower 16 bits of val on little-endian machines.
The upper 16 bits will remain 0x1234.

Nobody noticed this probably because this bug can be triggered with
regmap_write() only on big-endian architectures (which are not used by
many people anymore), and on little endian this bug has consequences
only if register width is 8 or 16 bits and also the memory place to
which regmap_read() should store it's result has non-zero upper bits,
which it seems doesn't happen anywhere in U-Boot normally. CI managed to
trigger this bug in unit test of dm_test_devm_regmap_field when compiled
for sandbox_defconfig using LTO.

Fix this simply by taking into account that regmap_raw_read() and
regmap_raw_write() behave as if the data given to these functions were
in little-endian format, i.e. use cpu_to_le32() / le32_to_cpu(). In
regmap_read() also zero out the space so that we don't get invalid
result if regmap_raw_read() does not fill the whole object.

Signed-off-by: Marek Behún 
Reviewed-by: Simon Glass 
Reviewed-by: Heiko Schocher 
---
 drivers/core/regmap.c | 13 -
 1 file changed, 12 insertions(+), 1 deletion(-)

diff --git a/drivers/core/regmap.c b/drivers/core/regmap.c
index b51ce108c1..5d37006fff 100644
--- a/drivers/core/regmap.c
+++ b/drivers/core/regmap.c
@@ -435,7 +435,16 @@ int regmap_raw_read(struct regmap *map, uint offset, void 
*valp, size_t val_len)
 
 int regmap_read(struct regmap *map, uint offset, uint *valp)
 {
-   return regmap_raw_read(map, offset, valp, map->width);
+   int res;
+
+   *valp = 0;
+   res = regmap_raw_read(map, offset, valp, map->width);
+   if (res)
+   return res;
+
+   *valp = le32_to_cpu(*valp);
+
+   return 0;
 }
 
 static inline void __write_8(u8 *addr, const u8 *val,
@@ -546,6 +555,8 @@ int regmap_raw_write(struct regmap *map, uint offset, const 
void *val,
 
 int regmap_write(struct regmap *map, uint offset, uint val)
 {
+   val = cpu_to_le32(val);
+
return regmap_raw_write(map, offset, , map->width);
 }
 
-- 
2.26.2



[PATCH u-boot 04/39] api: fix a potential serious bug caused by undef CONFIG_SYS_64BIT_LBA

2021-03-06 Thread Marek Behún
The api_public.h header file undefined macro CONFIG_SYS_64BIT_LBA.

But api/api_storage.c includes this header before including part.h,
causing the type of lbaint_t and subsequently the type signature of
blk_dread() and blk_dwrite() functions to change from the rest of U-Boot
(if CONFIG_SYS_64BIT_LBA is defined for the board).

This is of course wrong, because the call to blk_dread() / blk_dwrite()
will recieve mangled arguments.

Fix this by removing the undef of macro CONFIG_SYS_64BIT_LBA and instead
make the immediate code do what it would do as if the macro was not
defined.

Add a FIXME to whoever is maintaining this code.

CI managed to trigger this bug when compiling for lsxhl_defconfig, which
has CONFIG_API selected. The compiler complained about blk_dwrite() and
blk_dread() not matching original declarations:

  include/blk.h:280:15: warning: type of ‘blk_dwrite’ does not match
 original declaration
 [-Wlto-type-mismatch]
  280 | unsigned long blk_dwrite(struct blk_desc *block_dev, lbaint_t st
  |   ^
  drivers/block/blk-uclass.c:456:15: note: type mismatch in parameter 2
  456 | unsigned long blk_dwrite(struct blk_desc *block_dev, lbaint_t st
  |   ^

Signed-off-by: Marek Behún 
---
 include/api_public.h | 23 ++-
 1 file changed, 18 insertions(+), 5 deletions(-)

diff --git a/include/api_public.h b/include/api_public.h
index def103ce22..5a4465ea89 100644
--- a/include/api_public.h
+++ b/include/api_public.h
@@ -70,12 +70,25 @@ struct sys_info {
int mr_no;  /* number of memory regions */
 };
 
-#undef CONFIG_SYS_64BIT_LBA
-#ifdef CONFIG_SYS_64BIT_LBA
-typedefu_int64_t lbasize_t;
-#else
+/*
+ * FIXME: Previously this code was:
+ *
+ *   #undef CONFIG_SYS_64BIT_LBA
+ *   #ifdef CONFIG_SYS_64BIT_LBA
+ *   typedef u_int64_t lbasize_t;
+ *   #else
+ *   typedef unsigned long lbasize_t;
+ *   #endif
+ *
+ * But we cannot just undefine CONFIG_SYS_64BIT_LBA, because then in
+ * api/api_storage.c the type signature of lbaint_t will be different if
+ * CONFIG_SYS_64BIT_LBA is enabled for the board, which can result in various
+ * bugs.
+ * So simply define lbasize_t as an unsigned long, since this was what was done
+ * anyway for at least 13 years, but don't undefine CONFIG_SYS_64BIT_LBA.
+ */
 typedef unsigned long lbasize_t;
-#endif
+
 typedef unsigned long lbastart_t;
 
 #define DEV_TYP_NONE   0x
-- 
2.26.2



[PATCH u-boot 05/39] checkpatch: require quotes around section name in the __section() macro

2021-03-06 Thread Marek Behún
This is how Linux does this now, see Linux commit 339f29d91acf.

Signed-off-by: Marek Behún 
---
 scripts/checkpatch.pl | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index 755f4802a4..fd1e9c4d24 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -6065,7 +6065,7 @@ sub process {
my $old = substr($rawline, $-[1], $+[1] - $-[1]);
my $new = substr($old, 1, -1);
if (WARN("PREFER_SECTION",
-"__section($new) is preferred over 
__attribute__((section($old)))\n" . $herecurr) &&
+"__section(\"$new\") is preferred over 
__attribute__((section($old)))\n" . $herecurr) &&
$fix) {
$fixed[$fixlinenr] =~ 
s/\b__attribute__\s*\(\s*\(\s*_*section_*\s*\(\s*\Q$old\E\s*\)\s*\)\s*\)/__section($new)/;
}
-- 
2.26.2



[PATCH u-boot 00/39] U-Boot LTO (Sandbox + Some ARM boards)

2021-03-06 Thread Marek Behún
Hello,

so after the RFC I am now sending first version of patches adding
support for LTO to U-Boot.

This series was tested by Github/Azure CI at
  https://github.com/u-boot/u-boot/pull/57
and also by Pali Rohar and Adam Ford for some boards.

There is one test that fails and one that did not complete after 60
minutes, but these seem to be related to an issue regarding a race
condition with GNU Make's jobserver - I am using -flto=jobserver.
We could remove the jobserver option, but the linking is then painfully
slow, so I don't know.

Anyway the code size decrease is nice, approximately 15% for SPL.
It's lower on the main binary, only about 5%, but this is still nice
and needed for some boards, such as Nokia RX-51 (N900), because the
binary is otherwise on the boundary already.

I am satisfied with how even clang now links with LTO, at least for
sandbox, and passing all CI tests.

For sandbox I have added a patch that enables LTO by default.

For ARM, there is one patch that enables LTO for several boards -
these are tested to work (thanks Pali and Adam).

The last patch, which enables LTO for all ARM boards by default,
is prefixed "DO NOT MERGE!"

This patch series therefore should not (hopefully) cause regression
when applied.

Marek

Marek Behún (39):
  ddr: marvell: axp: align signature of mv_xor_mem_init() with a38x
  ddr: marvell: axp: fix array types have different bounds warning
  regmap: fix a serious pointer casting bug
  api: fix a potential serious bug caused by undef CONFIG_SYS_64BIT_LBA
  checkpatch: require quotes around section name in the __section()
macro
  treewide: Convert macro and uses of __section(foo) to __section("foo")
  compiler.h: align the __ADDRESSABLE macro with Linux' version
  linker_lists: prepare macros to avoid code repetition
  test/py: improve regular expression for ut subtest symbol matcher
  linker_lists: declare lists and entries as __ADDRESSABLE for LTO
  binman: declare symbols externally visible
  string: make memcpy() and memset() visible to fix LTO linking errors
  efi_loader: fix warning when linking with LTO
  lib: crc32: make the crc_table variable non-const
  Makefile, Makefile.spl: cosmetic change
  build: use thin archives instead of incremental linking
  build: support building with Link Time Optimizations
  build: LTO: move platform libs into --start-group list
  sandbox: errno: avoid conflict with libc's errno
  sandbox: use sections instead of symbols for getopt array boundaries
  sandbox: make LTO available
  sandbox: enable LTO by default
  ARM: global_data: make set_gd() work for armv5 and armv6
  ARM: make gd a function call for LTO and set via set_gd()
  ARM: fix LTO build for some thumb-interwork cases
  ARM: fix LTO for imx28_xea
  ARM: fix LTO for apf27
  ARM: fix LTO for keystone
  ARM: kona: fix clk_bsc_enable() type mismatch for LTO
  ARM: imx6m: fix imx_eqos_txclk_set_rate() type mismatch for LTO
  ARM: fix LTO for seaboard
  ARM: fix LTO for rockchip and samsung
  ARM: omap3: fix LTO for DM3730 (and possibly other omap3 boards)
  armv8: SPL: discard relocation information
  ata: ahci: fix ahci_link_up() type mismatch for LTO
  ARM: make LTO available
  ARM: don't use -ffunction-sections/-fdata-sections with LTO build
  ARM: enable LTO for some boards
  ARM: enable LTO by default

 Kbuild |  2 +
 Kconfig| 19 +++
 Makefile   | 49 ++--
 arch/Kconfig   |  4 ++
 arch/arm/config.mk |  8 ++-
 arch/arm/cpu/arm926ejs/Makefile|  2 +
 arch/arm/cpu/arm926ejs/mxs/mxs.c   |  2 +-
 arch/arm/cpu/arm926ejs/mxs/spl_boot.c  |  4 +-
 arch/arm/cpu/arm926ejs/spear/spl.c |  2 +-
 arch/arm/cpu/armv7/kona-common/clk-stubs.c |  2 +-
 arch/arm/cpu/armv7/ls102xa/ls102xa_psci.c  |  2 +-
 arch/arm/cpu/armv8/fsl-layerscape/spl.c|  2 +-
 arch/arm/cpu/armv8/spl_data.c  |  4 +-
 arch/arm/cpu/armv8/u-boot-spl.lds  |  1 +
 arch/arm/include/asm/global_data.h |  6 +-
 arch/arm/include/asm/secure.h  |  6 +-
 arch/arm/include/asm/setup.h   |  2 +-
 arch/arm/lib/Makefile  |  3 +
 arch/arm/lib/sections.c| 31 +-
 arch/arm/lib/spl.c |  2 +-
 arch/arm/mach-at91/spl.c   |  2 +-
 arch/arm/mach-exynos/spl_boot.c|  2 +-
 arch/arm/mach-imx/imx8m/clock_imx8mm.c |  2 +-
 arch/arm/mach-imx/imx8m/soc.c  |  2 +-
 arch/arm/mach-imx/spl_imx_romapi.c | 16 +++---
 arch/arm/mach-k3/am6_init.c|  2 +-
 arch/arm/mach-k3/j721e_init.c  |  4 +-
 arch/arm/mach-keystone/Makefile|  1 +
 arch/arm/mach-mvebu/mbus.c |  4 +-
 arch/arm/mach-mvebu/timer.c|  2 +-
 arch/arm/mach-nexell/clock.c   |  6 +-
 arch/arm/mach-nexell/timer.c   |  

[PATCH u-boot-marvell 01/39] ddr: marvell: axp: align signature of mv_xor_mem_init() with a38x

2021-03-06 Thread Marek Behún
In arch/arm/mach-mvebu/dram.c we always include axp's xor.h for common
XOR definitions, regardless whether we compile for axp or a38x.

But the declaration of this function has a different signature in axp's
xor.h from the one used in a38x' implementation - one parameter is u64
instead of u32. This can result in wrong argument's being passed to that
function on a38x with no one the wiser.

I discovered this when building U-Boot for Turris Omnia with LTO. The
compiler complains about the different signatures being thrown into the
same linking process:

  axp/xor.h:67:5: warning: type of ‘mv_xor_mem_init’ does not match
   original declaration [-Wlto-type-mismatch]
   67 | int mv_xor_mem_init(u32 chan, u32 start_ptr, u32 block_size,
  | ^
  a38x/xor.c:165:5: note: type mismatch in parameter 3
  165 | int mv_xor_mem_init(u32 chan, u32 start_ptr, unsigned long long
  | ^
  a38x/xor.c:165:5: note: type ‘long long unsigned int’ should match
  type ‘u32’

Fix this by changing the type of the block_size argument in the axp's
implementation and header file to the one used in a38x (and upstream
mv-ddr-marvell).

Signed-off-by: Marek Behún 
Reviewed-by: Stefan Roese 
---
 drivers/ddr/marvell/axp/xor.c | 4 ++--
 drivers/ddr/marvell/axp/xor.h | 4 ++--
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/ddr/marvell/axp/xor.c b/drivers/ddr/marvell/axp/xor.c
index 17bfe6a7bf..76aea96682 100644
--- a/drivers/ddr/marvell/axp/xor.c
+++ b/drivers/ddr/marvell/axp/xor.c
@@ -152,8 +152,8 @@ static int mv_xor_ctrl_set(u32 chan, u32 xor_ctrl)
return MV_OK;
 }
 
-int mv_xor_mem_init(u32 chan, u32 start_ptr, u32 block_size, u32 init_val_high,
-   u32 init_val_low)
+int mv_xor_mem_init(u32 chan, u32 start_ptr, unsigned long long block_size,
+   u32 init_val_high, u32 init_val_low)
 {
u32 tmp;
 
diff --git a/drivers/ddr/marvell/axp/xor.h b/drivers/ddr/marvell/axp/xor.h
index 97d1056432..a7c6ae840c 100644
--- a/drivers/ddr/marvell/axp/xor.h
+++ b/drivers/ddr/marvell/axp/xor.h
@@ -64,7 +64,7 @@ int mv_xor_state_get(u32 chan);
 void mv_sys_xor_init(MV_DRAM_INFO *dram_info);
 void mv_sys_xor_finish(void);
 int mv_xor_transfer(u32 chan, int xor_type, u32 xor_chain_ptr);
-int mv_xor_mem_init(u32 chan, u32 start_ptr, u32 block_size, u32 init_val_high,
-   u32 init_val_low);
+int mv_xor_mem_init(u32 chan, u32 start_ptr, unsigned long long block_size,
+   u32 init_val_high, u32 init_val_low);
 
 #endif /* __XOR_H */
-- 
2.26.2



Re: [RFC PATCH u-boot 00/12] U-Boot LTO (Sandbox + ARM Nokia RX-51)

2021-03-06 Thread Marek Behun
On Sat, 6 Mar 2021 21:45:02 -0600
Adam Ford  wrote:

> On Sat, Mar 6, 2021 at 3:49 PM Marek Behun  wrote:
> >
> > On Sat, 6 Mar 2021 22:38:52 +0100
> > Pali Rohár  wrote:
> >  
> > > On Saturday 06 March 2021 22:19:22 Marek Behun wrote:  
> > > > On Sat, 6 Mar 2021 22:00:45 +0100
> > > > Pali Rohár  wrote:
> > > >  
> > > > > On Saturday 06 March 2021 21:54:00 Marek Behun wrote:  
> > > > > > On Sat, 6 Mar 2021 21:41:14 +0100
> > > > > > Pali Rohár  wrote:
> > > > > >  
> > > > > > > On Saturday 06 March 2021 15:08:13 Tom Rini wrote:  
> > > > > > > > Perhaps we'll default to yes on some SoCs.  The omap3 thing is 
> > > > > > > > a bit
> > > > > > > > odd, but we'll see what happens on real N900 hardware.  
> > > > > > >
> > > > > > > Hello!
> > > > > > >
> > > > > > > Could you send me a link to git repo / branch and tell me from 
> > > > > > > which
> > > > > > > commit should I do tests on real N900 hardware? I will test it 
> > > > > > > and let
> > > > > > > you know results.
> > > > > > >
> > > > > > > Adding maemo ML to the loop as on the maemo list are more people 
> > > > > > > with
> > > > > > > N900 HW and U-Boot.  
> > > > > >
> > > > > > https://github.com/elkablo/u-boot branch lto  
> > > > >
> > > > > Sorry, compilation is failing :-(
> > > > >
> > > > > $ git clone https://github.com/elkablo/u-boot -b lto --depth=100
> > > > > Cloning into 'u-boot'...
> > > > > remote: Enumerating objects: 33644, done.
> > > > > remote: Counting objects: 100% (33644/33644), done.
> > > > > remote: Compressing objects: 100% (20116/20116), done.
> > > > > remote: Total 33644 (delta 15838), reused 19947 (delta 13018), 
> > > > > pack-reused 0
> > > > > Receiving objects: 100% (33644/33644), 26.28 MiB | 10.21 MiB/s, done.
> > > > > Resolving deltas: 100% (15838/15838), done.
> > > > >
> > > > > $ cd u-boot
> > > > >
> > > > > $ make CROSS_COMPILE=arm-linux-gnueabi- nokia_rx51_config
> > > > >   HOSTCC  scripts/basic/fixdep
> > > > >   HOSTCC  scripts/kconfig/conf.o
> > > > >   YACCscripts/kconfig/zconf.tab.c
> > > > >   LEX scripts/kconfig/zconf.lex.c
> > > > >   HOSTCC  scripts/kconfig/zconf.tab.o
> > > > >   HOSTLD  scripts/kconfig/conf
> > > > > #
> > > > > # configuration written to .config
> > > > > #
> > > > >
> > > > > $ make CROSS_COMPILE=arm-linux-gnueabi- u-boot.bin
> > > > > ...
> > > > >   LTO u-boot
> > > > > /usr/lib/gcc-cross/arm-linux-gnueabi/8/../../../../arm-linux-gnueabi/bin/ld:
> > > > >  
> > > > > /usr/lib/gcc-cross/arm-linux-gnueabi/8/../../../../arm-linux-gnueabi/bin/ld:
> > > > >  DWARF error: offset (1258291444) greater than or equal to .debug_str 
> > > > > size (676)
> > > > > /usr/lib/gcc-cross/arm-linux-gnueabi/8/../../../../arm-linux-gnueabi/bin/ld:
> > > > >  DWARF error: offset (1459618036) greater than or equal to .debug_str 
> > > > > size (676)
> > > > > /usr/lib/gcc-cross/arm-linux-gnueabi/8/../../../../arm-linux-gnueabi/bin/ld:
> > > > >  DWARF error: could not find abbrev number 48028
> > > > > /tmp/cc8l0QSQ.ltrans3.ltrans.o: in function `omap3_set_aux_cr_secure':
> > > > > :(.text+0x6eb8): undefined reference to 
> > > > > `do_omap3_emu_romcode_call'
> > > > > collect2: error: ld returned 1 exit status
> > > > > make: *** [Makefile:1808: u-boot] Error 1
> > > > >
> > > > >
> > > > > I'm using arm-linux-gnueabi-gcc version 8.3.0 which is available in
> > > > > current Debian stable (Debian 10 Buster).  
> > > >
> > > > Fixed and force-pushed, it seems ar needs the P flag that Bin Meng
> > > > questioned.  
> > >
> > > Problem is fixed, now compilation succeeded. u-boot.bin has size 243788
> > > bytes.
> > >
> > > And seems that compiled U-Boot is working fine!
> > >
> > > Nokia RX-51 # version
> > > U-Boot 2021.04-rc3-00338-g88d0a5042c97 (Mar 06 2021 - 22:19:08 +0100)
> > >
> > > arm-linux-gnueabi-gcc (Debian 8.3.0-2) 8.3.0
> > > GNU ld (GNU Binutils for Debian) 2.31.1
> > >
> > > I can send binary files via usbtty and 'loadb' command. I can boot linux
> > > kernel via 'bootm'. I can chainload to another U-Boot binary (loaded by
> > > 'loadb') via 'go' command. Also 'ext4ls' and 'fatls' commands are
> > > working. Also 'onenand dump bootloader' is working.
> > >
> > > Do you need something more to test?
> > >
> > > If not you can add my 'Tested-by: Pali Rohár ' line for
> > > all patches which are up to the commit 88d0a5042c97.
> > >
> > > Good job!  
> >
> > Thanks.
> >
> > I am still working on these patches, since I have discovered some more
> > defconfigs which fail to build for one reason or another.
> >
> > I will send a patch enabling LTO for Nokia N900 though.
> >  
> 
> I have my DM3730 booting now
> 
> diff --git a/arch/arm/mach-omap2/omap3/Makefile
> b/arch/arm/mach-omap2/omap3/Makefile
> index 91ed8ebc9f..4c96c81bf7 100644
> --- a/arch/arm/mach-omap2/omap3/Makefile
> +++ b/arch/arm/mach-omap2/omap3/Makefile
> @@ -6,6 +6,8 @@
>  # If clock.c is compiled for Thumb2, then it fails on OMAP3530
>  CFLAGS_clock.o += -marm
> 
> +CFLAGS_REMOVE_board.o := 

[PATCH 2/2] arm: omap3: Make secure_unlock_mem() static

2021-03-06 Thread Adam Ford
secure_unlock_mem() is only used in one file, so make it static
in that file. This
may help with some further optimization in the future.

Signed-off-by: Adam Ford 

diff --git a/arch/arm/mach-omap2/omap3/board.c 
b/arch/arm/mach-omap2/omap3/board.c
index 879b0f..74b5a4b111 100644
--- a/arch/arm/mach-omap2/omap3/board.c
+++ b/arch/arm/mach-omap2/omap3/board.c
@@ -76,7 +76,7 @@ const struct gpio_bank *const omap_gpio_bank = gpio_bank_34xx;
  * Description: Setup security registers for access
  *  (GP Device only)
  */
-void secure_unlock_mem(void)
+static void secure_unlock_mem(void)
 {
struct pm *pm_rt_ape_base = (struct pm *)PM_RT_APE_BASE_ADDR_ARM;
struct pm *pm_gpmc_base = (struct pm *)PM_GPMC_BASE_ADDR_ARM;
-- 
2.25.1



[PATCH 1/2] arm: omap3: Make secureworld_exit() static

2021-03-06 Thread Adam Ford
secureworld_exit() is only used in one file, so make it static
to that file and remove it from sys_proto.h. This
may help with some further optimization in the future.

Signed-off-by: Adam Ford 

diff --git a/arch/arm/include/asm/arch-omap3/sys_proto.h 
b/arch/arm/include/asm/arch-omap3/sys_proto.h
index 656f848a73..a6e9ff84aa 100644
--- a/arch/arm/include/asm/arch-omap3/sys_proto.h
+++ b/arch/arm/include/asm/arch-omap3/sys_proto.h
@@ -59,7 +59,6 @@ u32 is_running_in_sdram(void);
 u32 is_running_in_sram(void);
 u32 is_running_in_flash(void);
 u32 get_device_type(void);
-void secureworld_exit(void);
 u32 get_boot_type(void);
 void invalidate_dcache(u32);
 u32 wait_on_value(u32, u32, void *, u32);
diff --git a/arch/arm/mach-omap2/omap3/board.c 
b/arch/arm/mach-omap2/omap3/board.c
index c621177580..879b0f 100644
--- a/arch/arm/mach-omap2/omap3/board.c
+++ b/arch/arm/mach-omap2/omap3/board.c
@@ -114,7 +114,7 @@ void secure_unlock_mem(void)
  * configure secure registers and exit secure world
  *  general use.
  */
-void secureworld_exit(void)
+static void secureworld_exit(void)
 {
unsigned long i;
 
-- 
2.25.1



[PATCH v6 4/4] qemu: arm: select QFW, MMIO on qemu-arm

2021-03-06 Thread Asherah Connor
Select CMD_QFW and QFW_MMIO in the qemu-arm board (covers arm and
arm64).

Signed-off-by: Asherah Connor 

---

(no changes since v5)

Changes in v5:
* Split adding MMIO driver to QEMU arm/64 into own commit.
* Use the generic qemu-arm board config rather than adding to multiple
  defconfigs.

 board/emulation/qemu-arm/Kconfig | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/board/emulation/qemu-arm/Kconfig b/board/emulation/qemu-arm/Kconfig
index fb8d38f5b8..95dbefa78b 100644
--- a/board/emulation/qemu-arm/Kconfig
+++ b/board/emulation/qemu-arm/Kconfig
@@ -5,6 +5,8 @@ config SYS_TEXT_BASE
 
 config BOARD_SPECIFIC_OPTIONS # dummy
def_bool y
+   select CMD_QFW
+   select QFW_MMIO
imply VIRTIO_MMIO
imply VIRTIO_PCI
imply VIRTIO_NET
-- 
2.20.1



[PATCH v6 3/4] qemu: add MMIO driver for QFW

2021-03-06 Thread Asherah Connor
Add MMIO driver for QFW.

Note that there is no consumer as of this patch.

Signed-off-by: Asherah Connor 
---

(no changes since v5)

Changes in v5:
* Split MMIO driver into its own commit.
* Add CONFIG_QFW_MMIO for selection by arch/board.

 drivers/misc/Kconfig|   7 +++
 drivers/misc/Makefile   |   1 +
 drivers/misc/qfw_mmio.c | 119 
 3 files changed, 127 insertions(+)
 create mode 100644 drivers/misc/qfw_mmio.c

diff --git a/drivers/misc/Kconfig b/drivers/misc/Kconfig
index 3a254eba4b..c650471ff7 100644
--- a/drivers/misc/Kconfig
+++ b/drivers/misc/Kconfig
@@ -378,6 +378,13 @@ config QFW_PIO
  Hidden option to enable PIO QEMU fw_cfg interface. This will be
  selected by the appropriate QEMU board.
 
+config QFW_MMIO
+   bool
+   depends on QFW
+   help
+ Hidden option to enable MMIO QEMU fw_cfg interface. This will be
+ selected by the appropriate QEMU board.
+
 config I2C_EEPROM
bool "Enable driver for generic I2C-attached EEPROMs"
depends on MISC
diff --git a/drivers/misc/Makefile b/drivers/misc/Makefile
index 2864b84af9..0c67d43a5d 100644
--- a/drivers/misc/Makefile
+++ b/drivers/misc/Makefile
@@ -58,6 +58,7 @@ obj-$(CONFIG_$(SPL_)PWRSEQ) += pwrseq-uclass.o
 ifdef CONFIG_QFW
 obj-y += qfw.o
 obj-$(CONFIG_QFW_PIO) += qfw_pio.o
+obj-$(CONFIG_QFW_MMIO) += qfw_mmio.o
 obj-$(CONFIG_SANDBOX) += qfw_sandbox.o
 endif
 obj-$(CONFIG_ROCKCHIP_EFUSE) += rockchip-efuse.o
diff --git a/drivers/misc/qfw_mmio.c b/drivers/misc/qfw_mmio.c
new file mode 100644
index 00..f397384054
--- /dev/null
+++ b/drivers/misc/qfw_mmio.c
@@ -0,0 +1,119 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * MMIO interface for QFW
+ *
+ * (C) Copyright 2015 Miao Yan 
+ * (C) Copyright 2021 Asherah Connor 
+ */
+
+#define LOG_CATEGORY UCLASS_QFW
+
+#include 
+#include 
+#include 
+#include 
+#include 
+
+struct qfw_mmio {
+   /*
+* Each access to the 64-bit data register can be 8/16/32/64 bits wide.
+*/
+   union {
+   u8 data8;
+   u16 data16;
+   u32 data32;
+   u64 data64;
+   };
+   u16 selector;
+   u8 padding[6];
+   u64 dma;
+};
+
+struct qfw_mmio_plat {
+   volatile struct qfw_mmio *mmio;
+};
+
+static void qfw_mmio_read_entry_io(struct udevice *dev, u16 entry, u32 size,
+  void *address)
+{
+   struct qfw_mmio_plat *plat = dev_get_plat(dev);
+
+   /*
+* writing FW_CFG_INVALID will cause read operation to resume at last
+* offset, otherwise read will start at offset 0
+*
+* Note: on platform where the control register is MMIO, the register
+* is big endian.
+*/
+   if (entry != FW_CFG_INVALID)
+   plat->mmio->selector = cpu_to_be16(entry);
+
+   /* the endianness of data register is string-preserving */
+   while (size >= 8) {
+   *(u64 *)address = plat->mmio->data64;
+   address += 8;
+   size -= 8;
+   }
+   while (size >= 4) {
+   *(u32 *)address = plat->mmio->data32;
+   address += 4;
+   size -= 4;
+   }
+   while (size >= 2) {
+   *(u16 *)address = plat->mmio->data16;
+   address += 2;
+   size -= 2;
+   }
+   while (size >= 1) {
+   *(u8 *)address = plat->mmio->data8;
+   address += 1;
+   size -= 1;
+   }
+}
+
+/* Read configuration item using fw_cfg DMA interface */
+static void qfw_mmio_read_entry_dma(struct udevice *dev, struct qfw_dma *dma)
+{
+   struct qfw_mmio_plat *plat = dev_get_plat(dev);
+
+   /* the DMA address register is big-endian */
+   plat->mmio->dma = cpu_to_be64((uintptr_t)dma);
+
+   while (be32_to_cpu(dma->control) & ~FW_CFG_DMA_ERROR);
+}
+
+static int qfw_mmio_of_to_plat(struct udevice *dev)
+{
+   struct qfw_mmio_plat *plat = dev_get_plat(dev);
+
+   plat->mmio = map_physmem(dev_read_addr(dev),
+sizeof(struct qfw_mmio),
+MAP_NOCACHE);
+
+   return 0;
+}
+
+static int qfw_mmio_probe(struct udevice *dev)
+{
+   return qfw_register(dev);
+}
+
+static struct dm_qfw_ops qfw_mmio_ops = {
+   .read_entry_io = qfw_mmio_read_entry_io,
+   .read_entry_dma = qfw_mmio_read_entry_dma,
+};
+
+static const struct udevice_id qfw_mmio_ids[] = {
+   { .compatible = "qemu,fw-cfg-mmio" },
+   {}
+};
+
+U_BOOT_DRIVER(qfw_mmio) = {
+   .name   = "qfw_mmio",
+   .id = UCLASS_QFW,
+   .of_match   = qfw_mmio_ids,
+   .plat_auto  = sizeof(struct qfw_mmio_plat),
+   .of_to_plat = qfw_mmio_of_to_plat,
+   .probe  = qfw_mmio_probe,
+   .ops= _mmio_ops,
+};
-- 
2.20.1



[PATCH v6 2/4] test: qemu: add qfw sandbox driver, dm tests, qemu tests

2021-03-06 Thread Asherah Connor
A sandbox driver and test are added for the qfw uclass, and a test in
QEMU added for qfw functionality to confirm it doesn't break in real
world use.

Signed-off-by: Asherah Connor 
Reviewed-by: Simon Glass 
---

(no changes since v1)

 drivers/misc/Makefile  |   1 +
 drivers/misc/qfw_sandbox.c | 128 +
 test/dm/Makefile   |   1 +
 test/dm/qfw.c  |  42 
 test/py/tests/test_qfw.py  |  21 ++
 5 files changed, 193 insertions(+)
 create mode 100644 drivers/misc/qfw_sandbox.c
 create mode 100644 test/dm/qfw.c
 create mode 100644 test/py/tests/test_qfw.py

diff --git a/drivers/misc/Makefile b/drivers/misc/Makefile
index 53bff72428..2864b84af9 100644
--- a/drivers/misc/Makefile
+++ b/drivers/misc/Makefile
@@ -58,6 +58,7 @@ obj-$(CONFIG_$(SPL_)PWRSEQ) += pwrseq-uclass.o
 ifdef CONFIG_QFW
 obj-y += qfw.o
 obj-$(CONFIG_QFW_PIO) += qfw_pio.o
+obj-$(CONFIG_SANDBOX) += qfw_sandbox.o
 endif
 obj-$(CONFIG_ROCKCHIP_EFUSE) += rockchip-efuse.o
 obj-$(CONFIG_ROCKCHIP_OTP) += rockchip-otp.o
diff --git a/drivers/misc/qfw_sandbox.c b/drivers/misc/qfw_sandbox.c
new file mode 100644
index 00..7ce532310f
--- /dev/null
+++ b/drivers/misc/qfw_sandbox.c
@@ -0,0 +1,128 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Sandbox interface for QFW
+ *
+ * (C) Copyright 2015 Miao Yan 
+ * (C) Copyright 2021 Asherah Connor 
+ */
+
+#define LOG_CATEGORY UCLASS_QFW
+
+#include 
+#include 
+#include 
+#include 
+#include 
+
+struct qfw_sandbox_plat {
+   u8 file_dir_offset;
+};
+
+static void qfw_sandbox_read_entry_io(struct udevice *dev, u16 entry, u32 size,
+ void *address)
+{
+   debug("%s: entry 0x%x size %u address %p\n", __func__, entry, size,
+ address);
+
+   switch (entry) {
+   case FW_CFG_SIGNATURE:
+   if (size == 4)
+   *((u32 *)address) = cpu_to_be32(QEMU_FW_CFG_SIGNATURE);
+   break;
+   case FW_CFG_ID:
+   /* Advertise DMA support */
+   if (size == 1)
+   *((u8 *)address) = FW_CFG_DMA_ENABLED;
+   break;
+   default:
+   debug("%s got unsupported entry 0x%x\n", __func__, entry);
+   /*
+* Sandbox driver doesn't support other entries here, assume we use DMA
+* to read them -- the uclass driver will exclusively use it when
+* advertised.
+*/
+   }
+}
+
+static void qfw_sandbox_read_entry_dma(struct udevice *dev, struct qfw_dma 
*dma)
+{
+   u16 entry;
+   u32 control = be32_to_cpu(dma->control);
+   void *address = (void *)be64_to_cpu(dma->address);
+   u32 length = be32_to_cpu(dma->length);
+   struct qfw_sandbox_plat *plat = dev_get_plat(dev);
+   struct fw_cfg_file *file;
+
+   debug("%s\n", __func__);
+
+   if (!(control & FW_CFG_DMA_READ))
+   return;
+
+   if (control & FW_CFG_DMA_SELECT) {
+   /* Start new read. */
+   entry = control >> 16;
+
+   /* Arbitrary values to be used by tests. */
+   switch (entry) {
+   case FW_CFG_NB_CPUS:
+   if (length == 2)
+   *((u16 *)address) = cpu_to_le16(5);
+   break;
+   case FW_CFG_FILE_DIR:
+   if (length == 4) {
+   *((u32 *)address) = cpu_to_be32(2);
+   plat->file_dir_offset = 1;
+   }
+   break;
+   default:
+   debug("%s got unsupported entry 0x%x\n", __func__,
+ entry);
+   }
+   } else if (plat->file_dir_offset && length == 64) {
+   file = address;
+   switch (plat->file_dir_offset) {
+   case 1:
+   file->size = cpu_to_be32(8);
+   file->select = cpu_to_be16(FW_CFG_FILE_FIRST);
+   strcpy(file->name, "test-one");
+   plat->file_dir_offset++;
+   break;
+   case 2:
+   file->size = cpu_to_be32(8);
+   file->select = cpu_to_be16(FW_CFG_FILE_FIRST + 1);
+   strcpy(file->name, "test-two");
+   plat->file_dir_offset++;
+   break;
+   }
+   }
+
+   /*
+* Signal that we are finished. No-one checks this in sandbox --
+* normally the platform-specific driver looks for it -- but let's
+* replicate the behaviour in case someone relies on it later.
+*/
+   dma->control = 0;
+}
+
+static int qfw_sandbox_probe(struct udevice *dev)
+{
+   return qfw_register(dev);
+}
+
+static struct dm_qfw_ops qfw_sandbox_ops = {
+   .read_entry_io = qfw_sandbox_read_entry_io,
+   .read_entry_dma = 

[PATCH v6 1/4] x86: qemu: move QFW to its own uclass

2021-03-06 Thread Asherah Connor
We move qfw into its own uclass and split the PIO functions into a
specific driver for that uclass.  The PIO driver is selected in the
qemu-x86 board config (this covers x86 and x86_64).

include/qfw.h is cleaned up and documentation added.

Signed-off-by: Asherah Connor 

---

Changes in v6:
* Sandbox driver and tests are split into own commit.

Changes in v5:
* Split conversion of existing x86-only QFW to DM into its own patch.
* Fix qfw_get_dev() so it actually returns -ENODEV when device is
missing.
* Add CONFIG_QFW_PIO.
* Choose CONFIG_QFW_PIO in board/emulation/qemu-x86/Kconfig.
* QFW sandbox driver no longer inserts itself from device tree; wasn't
relevant to implementation and the ``compatible'' string was too
made-up.  Use U_BOOT_DRVINFO like the other QFW driver in this patch.
* Relevant documentation and sandbox/qemu tests are now here.

 arch/x86/cpu/qemu/cpu.c  |   9 +-
 arch/x86/cpu/qemu/qemu.c |  49 +--
 arch/x86/cpu/qfw_cpu.c   |  11 +-
 board/emulation/qemu-x86/Kconfig |   1 +
 cmd/qfw.c|  56 ---
 common/Makefile  |   2 +
 common/qfw.c | 105 +
 drivers/misc/Kconfig |  11 +-
 drivers/misc/Makefile|   5 +-
 drivers/misc/qfw.c   | 243 +++
 drivers/misc/qfw_pio.c   |  69 +
 include/dm/uclass-id.h   |   1 +
 include/qfw.h| 200 +
 13 files changed, 490 insertions(+), 272 deletions(-)
 create mode 100644 common/qfw.c
 create mode 100644 drivers/misc/qfw_pio.c

diff --git a/arch/x86/cpu/qemu/cpu.c b/arch/x86/cpu/qemu/cpu.c
index 9ce86b379c..735b656084 100644
--- a/arch/x86/cpu/qemu/cpu.c
+++ b/arch/x86/cpu/qemu/cpu.c
@@ -22,7 +22,14 @@ int cpu_qemu_get_desc(const struct udevice *dev, char *buf, 
int size)
 
 static int cpu_qemu_get_count(const struct udevice *dev)
 {
-   return qemu_fwcfg_online_cpus();
+   int ret;
+   struct udevice *qfw_dev;
+
+   ret = qfw_get_dev(_dev);
+   if (ret)
+   return ret;
+
+   return qfw_online_cpus(qfw_dev);
 }
 
 static const struct cpu_ops cpu_qemu_ops = {
diff --git a/arch/x86/cpu/qemu/qemu.c b/arch/x86/cpu/qemu/qemu.c
index 044a429c13..e54082df7f 100644
--- a/arch/x86/cpu/qemu/qemu.c
+++ b/arch/x86/cpu/qemu/qemu.c
@@ -8,6 +8,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -16,47 +17,9 @@
 
 static bool i440fx;
 
-#ifdef CONFIG_QFW
-
-/* on x86, the qfw registers are all IO ports */
-#define FW_CONTROL_PORT0x510
-#define FW_DATA_PORT   0x511
-#define FW_DMA_PORT_LOW0x514
-#define FW_DMA_PORT_HIGH   0x518
-
-static void qemu_x86_fwcfg_read_entry_pio(uint16_t entry,
-   uint32_t size, void *address)
-{
-   uint32_t i = 0;
-   uint8_t *data = address;
-
-   /*
-* writting FW_CFG_INVALID will cause read operation to resume at
-* last offset, otherwise read will start at offset 0
-*
-* Note: on platform where the control register is IO port, the
-* endianness is little endian.
-*/
-   if (entry != FW_CFG_INVALID)
-   outw(cpu_to_le16(entry), FW_CONTROL_PORT);
-
-   /* the endianness of data register is string-preserving */
-   while (size--)
-   data[i++] = inb(FW_DATA_PORT);
-}
-
-static void qemu_x86_fwcfg_read_entry_dma(struct fw_cfg_dma_access *dma)
-{
-   /* the DMA address register is big endian */
-   outl(cpu_to_be32((uintptr_t)dma), FW_DMA_PORT_HIGH);
-
-   while (be32_to_cpu(dma->control) & ~FW_CFG_DMA_ERROR)
-   __asm__ __volatile__ ("pause");
-}
-
-static struct fw_cfg_arch_ops fwcfg_x86_ops = {
-   .arch_read_pio = qemu_x86_fwcfg_read_entry_pio,
-   .arch_read_dma = qemu_x86_fwcfg_read_entry_dma
+#if CONFIG_IS_ENABLED(QFW_PIO)
+U_BOOT_DRVINFO(x86_qfw_pio) = {
+   .name = "qfw_pio",
 };
 #endif
 
@@ -132,10 +95,6 @@ static void qemu_chipset_init(void)
 
enable_pm_ich9();
}
-
-#ifdef CONFIG_QFW
-   qemu_fwcfg_init(_x86_ops);
-#endif
 }
 
 #if !CONFIG_IS_ENABLED(SPL_X86_32BIT_INIT)
diff --git a/arch/x86/cpu/qfw_cpu.c b/arch/x86/cpu/qfw_cpu.c
index b959eaddde..ee00b8fe73 100644
--- a/arch/x86/cpu/qfw_cpu.c
+++ b/arch/x86/cpu/qfw_cpu.c
@@ -18,7 +18,7 @@ int qemu_cpu_fixup(void)
int cpu_num;
int cpu_online;
struct uclass *uc;
-   struct udevice *dev, *pdev;
+   struct udevice *dev, *pdev, *qfwdev;
struct cpu_plat *plat;
char *cpu;
 
@@ -39,6 +39,13 @@ int qemu_cpu_fixup(void)
return -ENODEV;
}
 
+   /* get qfw dev */
+   ret = qfw_get_dev();
+   if (ret) {
+   printf("unable to find qfw device\n");
+   return ret;
+   }
+
/* calculate cpus that are already bound */
cpu_num = 0;
for (uclass_find_first_device(UCLASS_CPU, );
@@ 

[PATCH v6 0/4] Move qfw to DM, add Arm support

2021-03-06 Thread Asherah Connor
This series moves the QFW driver into a uclass, UCLASS_QFW, and splits
the driver into qfw_pio and qfw_mmio.  Each driver is selected on the
appropriate QEMU board.  A sandbox driver is also added, and a DM unit
test against that driver.  The qfw command is tested in QEMU, and
documentation added.

Version 6 splits the sandbox driver and qemu tests out of the initial
conversion commit.

To view the changes online, see:
https://git.src.kameliya.ee/~kameliya/u-boot/log/qfw-priv

Changes in v6:
* Sandbox driver and tests are split into own commit.

Changes in v5:
* Split conversion of existing x86-only QFW to DM into its own patch.
* Split MMIO driver into its own commit.
* Split adding MMIO driver to QEMU arm/64 into own commit.

Asherah Connor (4):
  x86: qemu: move QFW to its own uclass
  test: qemu: add qfw sandbox driver, dm tests, qemu tests
  qemu: add MMIO driver for QFW
  qemu: arm: select QFW, MMIO on qemu-arm

 arch/x86/cpu/qemu/cpu.c  |   9 +-
 arch/x86/cpu/qemu/qemu.c |  49 +--
 arch/x86/cpu/qfw_cpu.c   |  11 +-
 board/emulation/qemu-arm/Kconfig |   2 +
 board/emulation/qemu-x86/Kconfig |   1 +
 cmd/qfw.c|  56 ---
 common/Makefile  |   2 +
 common/qfw.c | 105 +
 drivers/misc/Kconfig |  18 ++-
 drivers/misc/Makefile|   7 +-
 drivers/misc/qfw.c   | 243 +++
 drivers/misc/qfw_mmio.c  | 119 +++
 drivers/misc/qfw_pio.c   |  69 +
 drivers/misc/qfw_sandbox.c   | 128 
 include/dm/uclass-id.h   |   1 +
 include/qfw.h| 200 +
 test/dm/Makefile |   1 +
 test/dm/qfw.c|  42 ++
 test/py/tests/test_qfw.py|  21 +++
 19 files changed, 812 insertions(+), 272 deletions(-)
 create mode 100644 common/qfw.c
 create mode 100644 drivers/misc/qfw_mmio.c
 create mode 100644 drivers/misc/qfw_pio.c
 create mode 100644 drivers/misc/qfw_sandbox.c
 create mode 100644 test/dm/qfw.c
 create mode 100644 test/py/tests/test_qfw.py

-- 
2.20.1



Re: [PATCH v5 1/3] x86: qemu: move QFW to its own uclass

2021-03-06 Thread Asherah Connor
Hi Bin, Simon,

On 21/03/05 10:03:p, Bin Meng wrote:
> On Fri, Mar 5, 2021 at 10:31 PM Simon Glass  wrote:
> > If I previously reviewed it you can add my tag.

I wasn't sure of the correct etiquette when a large rearrangement of the
patches had been done; I'll keep this in mind.

> > I think sandbox driver/tests being separate is a good idea.
> 
> Yes, as Simon said, sandbox driver/test should be a separate patch.

This will be sent along shortly.  The initial rework commit email is
still fairly sizeable (+490 -272), but I've compared this series with v4
(which had sjg's Reviewed-by: on all initially) and confirmed nothing
new has crept in other than:

* part 1:
  * adding config QFW_PIO to select the PIO driver
  * completing documentation to Sphinx standard
* part 2:
  * nothing new
* part 3:
  * adding config QFW_MMIO to select the driver
* part 4:
  * just adds two `select's to Kconfig

So there should be only these parts of the patch needing careful review.
Given parts 1, 3 and 4 are still at least partly unreviewed, I will not
carry the Reviewed-by: over.  2 is good to go.

Best,

Asherah


[PATCH] arm: omap3: Make try_unlock_memory() static

2021-03-06 Thread Adam Ford
try_unlock_memory() is only used in one file, so make it static
in that file and remove it from the sys_proto header file. This
may help with some further optimization in the future.

Signed-off-by: Adam Ford 

diff --git a/arch/arm/include/asm/arch-omap3/sys_proto.h 
b/arch/arm/include/asm/arch-omap3/sys_proto.h
index 32ac033515..656f848a73 100644
--- a/arch/arm/include/asm/arch-omap3/sys_proto.h
+++ b/arch/arm/include/asm/arch-omap3/sys_proto.h
@@ -60,7 +60,6 @@ u32 is_running_in_sram(void);
 u32 is_running_in_flash(void);
 u32 get_device_type(void);
 void secureworld_exit(void);
-void try_unlock_memory(void);
 u32 get_boot_type(void);
 void invalidate_dcache(u32);
 u32 wait_on_value(u32, u32, void *, u32);
diff --git a/arch/arm/mach-omap2/omap3/board.c 
b/arch/arm/mach-omap2/omap3/board.c
index 029bd54595..c621177580 100644
--- a/arch/arm/mach-omap2/omap3/board.c
+++ b/arch/arm/mach-omap2/omap3/board.c
@@ -145,7 +145,7 @@ void secureworld_exit(void)
  * Description: If chip is GP/EMU(special) type, unlock the SRAM for
  *  general use.
  */
-void try_unlock_memory(void)
+static void try_unlock_memory(void)
 {
int mode;
int in_sdram = is_running_in_sdram();
-- 
2.25.1



Re: [RFC PATCH u-boot 00/12] U-Boot LTO (Sandbox + ARM Nokia RX-51)

2021-03-06 Thread Adam Ford
On Sat, Mar 6, 2021 at 3:49 PM Marek Behun  wrote:
>
> On Sat, 6 Mar 2021 22:38:52 +0100
> Pali Rohár  wrote:
>
> > On Saturday 06 March 2021 22:19:22 Marek Behun wrote:
> > > On Sat, 6 Mar 2021 22:00:45 +0100
> > > Pali Rohár  wrote:
> > >
> > > > On Saturday 06 March 2021 21:54:00 Marek Behun wrote:
> > > > > On Sat, 6 Mar 2021 21:41:14 +0100
> > > > > Pali Rohár  wrote:
> > > > >
> > > > > > On Saturday 06 March 2021 15:08:13 Tom Rini wrote:
> > > > > > > Perhaps we'll default to yes on some SoCs.  The omap3 thing is a 
> > > > > > > bit
> > > > > > > odd, but we'll see what happens on real N900 hardware.
> > > > > >
> > > > > > Hello!
> > > > > >
> > > > > > Could you send me a link to git repo / branch and tell me from which
> > > > > > commit should I do tests on real N900 hardware? I will test it and 
> > > > > > let
> > > > > > you know results.
> > > > > >
> > > > > > Adding maemo ML to the loop as on the maemo list are more people 
> > > > > > with
> > > > > > N900 HW and U-Boot.
> > > > >
> > > > > https://github.com/elkablo/u-boot branch lto
> > > >
> > > > Sorry, compilation is failing :-(
> > > >
> > > > $ git clone https://github.com/elkablo/u-boot -b lto --depth=100
> > > > Cloning into 'u-boot'...
> > > > remote: Enumerating objects: 33644, done.
> > > > remote: Counting objects: 100% (33644/33644), done.
> > > > remote: Compressing objects: 100% (20116/20116), done.
> > > > remote: Total 33644 (delta 15838), reused 19947 (delta 13018), 
> > > > pack-reused 0
> > > > Receiving objects: 100% (33644/33644), 26.28 MiB | 10.21 MiB/s, done.
> > > > Resolving deltas: 100% (15838/15838), done.
> > > >
> > > > $ cd u-boot
> > > >
> > > > $ make CROSS_COMPILE=arm-linux-gnueabi- nokia_rx51_config
> > > >   HOSTCC  scripts/basic/fixdep
> > > >   HOSTCC  scripts/kconfig/conf.o
> > > >   YACCscripts/kconfig/zconf.tab.c
> > > >   LEX scripts/kconfig/zconf.lex.c
> > > >   HOSTCC  scripts/kconfig/zconf.tab.o
> > > >   HOSTLD  scripts/kconfig/conf
> > > > #
> > > > # configuration written to .config
> > > > #
> > > >
> > > > $ make CROSS_COMPILE=arm-linux-gnueabi- u-boot.bin
> > > > ...
> > > >   LTO u-boot
> > > > /usr/lib/gcc-cross/arm-linux-gnueabi/8/../../../../arm-linux-gnueabi/bin/ld:
> > > >  
> > > > /usr/lib/gcc-cross/arm-linux-gnueabi/8/../../../../arm-linux-gnueabi/bin/ld:
> > > >  DWARF error: offset (1258291444) greater than or equal to .debug_str 
> > > > size (676)
> > > > /usr/lib/gcc-cross/arm-linux-gnueabi/8/../../../../arm-linux-gnueabi/bin/ld:
> > > >  DWARF error: offset (1459618036) greater than or equal to .debug_str 
> > > > size (676)
> > > > /usr/lib/gcc-cross/arm-linux-gnueabi/8/../../../../arm-linux-gnueabi/bin/ld:
> > > >  DWARF error: could not find abbrev number 48028
> > > > /tmp/cc8l0QSQ.ltrans3.ltrans.o: in function `omap3_set_aux_cr_secure':
> > > > :(.text+0x6eb8): undefined reference to 
> > > > `do_omap3_emu_romcode_call'
> > > > collect2: error: ld returned 1 exit status
> > > > make: *** [Makefile:1808: u-boot] Error 1
> > > >
> > > >
> > > > I'm using arm-linux-gnueabi-gcc version 8.3.0 which is available in
> > > > current Debian stable (Debian 10 Buster).
> > >
> > > Fixed and force-pushed, it seems ar needs the P flag that Bin Meng
> > > questioned.
> >
> > Problem is fixed, now compilation succeeded. u-boot.bin has size 243788
> > bytes.
> >
> > And seems that compiled U-Boot is working fine!
> >
> > Nokia RX-51 # version
> > U-Boot 2021.04-rc3-00338-g88d0a5042c97 (Mar 06 2021 - 22:19:08 +0100)
> >
> > arm-linux-gnueabi-gcc (Debian 8.3.0-2) 8.3.0
> > GNU ld (GNU Binutils for Debian) 2.31.1
> >
> > I can send binary files via usbtty and 'loadb' command. I can boot linux
> > kernel via 'bootm'. I can chainload to another U-Boot binary (loaded by
> > 'loadb') via 'go' command. Also 'ext4ls' and 'fatls' commands are
> > working. Also 'onenand dump bootloader' is working.
> >
> > Do you need something more to test?
> >
> > If not you can add my 'Tested-by: Pali Rohár ' line for
> > all patches which are up to the commit 88d0a5042c97.
> >
> > Good job!
>
> Thanks.
>
> I am still working on these patches, since I have discovered some more
> defconfigs which fail to build for one reason or another.
>
> I will send a patch enabling LTO for Nokia N900 though.
>

I have my DM3730 booting now

diff --git a/arch/arm/mach-omap2/omap3/Makefile
b/arch/arm/mach-omap2/omap3/Makefile
index 91ed8ebc9f..4c96c81bf7 100644
--- a/arch/arm/mach-omap2/omap3/Makefile
+++ b/arch/arm/mach-omap2/omap3/Makefile
@@ -6,6 +6,8 @@
 # If clock.c is compiled for Thumb2, then it fails on OMAP3530
 CFLAGS_clock.o += -marm

+CFLAGS_REMOVE_board.o := $(LTO_CFLAGS)
+
 obj-y  := lowlevel_init.o

 obj-y  += board.o

The board.c file has a few functions with assembly code and some
functions called by assembly.  I wonder if there needs to be some
compiler flags added to it to ensure it boots.  I am not as
experienced with compiler directives and Makefile tweaks, but I am
willing to try stuff if 

Re: [RFC PATCH u-boot 02/12] sandbox: errno: avoid conflict with libc's errno

2021-03-06 Thread Marek Behun
On Fri, 5 Mar 2021 18:21:51 +0100
Heinrich Schuchardt  wrote:

> On 05.03.21 16:37, Marek Behun wrote:
> > On Fri, 5 Mar 2021 11:00:45 +0800
> > Bin Meng  wrote:
> >  
> >> On Wed, Mar 3, 2021 at 12:13 PM Marek Behún  wrote:  
> >>>
> >>> When building with LTO, the system libc's `errno` variable used in
> >>> arch/sandbox/cpu/os.c conflicts with U-Boot's `errno` (defined in
> >>> lib/errno.c) with the following error:
> >>>  .../ld: errno@@GLIBC_PRIVATE: TLS definition in /lib64/libc.so.6
> >>>  section .tbss mismatches non-TLS reference in
> >>>  /tmp/u-boot.EQlEXz.ltrans0.ltrans.o  
> >>
> >> Do you know if this is the expected behavior when enabling LTO on the 
> >> compiler?  
> >
> > I don't, but this is a bug anyway. The symbol clashes with the symbol
> > from glibc. Does somebody know whether the usage of this symbol in os.c
> > does really use glibc's version or U-Boot's one?
> >  
> 
> Hello Marek,
> 
> Why do you resort to assembler in your patch instead of simply using:
> 
> #define errno __uboot_errno
> 
> to substitute the symbol?

Meh. :D That would just make error messages from gcc more
complicated, if suddenly the compiler spat out 2 more lines, saying "in
expansion of macro...".

I think that using attributes, static inline functions and everything
else the compiler provides instead of macros is better.

> Why explicitly set errno = 0? Globals are automatically initialized to zero.

I just added the symbol renaming part, the = 0 assignment was already
there. I don't think this commit should remove it. If we want that, we
can make it in another commit.

Marek


Re: U-Boot CI error, unable to reproduce locally

2021-03-06 Thread Marek Behun
On Sat, 6 Mar 2021 21:11:34 -0500
Tom Rini  wrote:

> On Sun, Mar 07, 2021 at 02:27:33AM +0100, Marek Behun wrote:
> 
> > Hello Tom,
> > 
> > I seem to run into an error on Azure's CI for U-Boot that I cannot
> > reproduce locally.
> > 
> > It concerns my LTO work https://github.com/u-boot/u-boot/pull/57
> > 
> > The test
> >   u-boot.u-boot (test.py xilinx_zynq_virt)
> > is failing with this log
> > https://dev.azure.com/u-boot/a1096300-2999-4ec4-a21a-4c22075e3771/_apis/build/builds/1936/logs/283
> > 
> > The error seems to be
> >   make[3]: *** read jobs pipe: No such file or directory.  Stop.
> >   lto-wrapper: fatal error: make returned 2 exit status
> > as if make's jobserver died, or something.
> > 
> > But when I build with buildman on my local machine, everything is OK.  
> 
> Seems like there's still some build races on fast machines?
> 

Can this happen even if only 2 jobs are used? According to that log -j2
was used.


Re: U-Boot CI error, unable to reproduce locally

2021-03-06 Thread Tom Rini
On Sun, Mar 07, 2021 at 02:27:33AM +0100, Marek Behun wrote:

> Hello Tom,
> 
> I seem to run into an error on Azure's CI for U-Boot that I cannot
> reproduce locally.
> 
> It concerns my LTO work https://github.com/u-boot/u-boot/pull/57
> 
> The test
>   u-boot.u-boot (test.py xilinx_zynq_virt)
> is failing with this log
> https://dev.azure.com/u-boot/a1096300-2999-4ec4-a21a-4c22075e3771/_apis/build/builds/1936/logs/283
> 
> The error seems to be
>   make[3]: *** read jobs pipe: No such file or directory.  Stop.
>   lto-wrapper: fatal error: make returned 2 exit status
> as if make's jobserver died, or something.
> 
> But when I build with buildman on my local machine, everything is OK.

Seems like there's still some build races on fast machines?

-- 
Tom


signature.asc
Description: PGP signature


request for i.MX8MM Venice test

2021-03-06 Thread Marek Behun
[sorry for the spam, I accidentally sent this e-mail from my personal
address]

Hello Tim,

you are listed as maintainer of i.MX8MM Venice board in U-Boot.

I am currently working on LTO support for U-Boot, and I have
encountered a problem with i.MX8MM Venice board:
when LTO is enabled, the linking process for SPL does not throw away
relocation information, making the resulting SPL image too big for that
board.

I have added a patch that discards symbols from .rela* section to my
patch series, but I would like you to test whether the patch series
works for your board and does not break anything.

Could you please clone https://github.com/elkablo/u-boot branch lto,
build for imx8mm_venice_defconfig and test whether it boots on your
board and maybe test some U-Boot commands (disk reads, kernel
booting, ...)? If it does not work, could you also please check with
current U-Boot master, to see if it got broken with my patches or with
something different?

Thank you.

Marek


Re: Fastboot

2021-03-06 Thread Sean Anderson

On 3/6/21 8:38 PM, Jonas Vautherin wrote:

Thanks a lot Sean!

I tried to enable logging by using the following CONFIG_:

```
CONFIG_LOG=y
CONFIG_SPL_LOG=y
CONFIG_TPL_LOG=y
CONFIG_LOG_MAX_LEVEL=5


You need to increase this. Log levels are only compiled-in if they are
less than the max log level.


CONFIG_SPL_LOG_MAX_LEVEL=3
CONFIG_TPL_LOG_MAX_LEVEL=3
CONFIG_LOG_DEFAULT_LEVEL=7
CONFIG_LOG_CONSOLE=y
CONFIG_SPL_LOG_CONSOLE=y
CONFIG_TPL_LOG_CONSOLE=y

CONFIG_CMD_LOG=y
```

And I got the "log" function indeed. But it did not have the effect I was 
hoping for:

```
=> log level set 7


Use the help function ;)

The correct syntax is "log level 7"

If you use a newer U-Boot (newer than 2021.01) then the output will be
more verbose. E.g.

=> log level
EMERG
ALERT
CRIT
ERR
WARNING
NOTICE
INFO (default)
DEBUG

--Sean


=> log level
Default log level: 0
=> usb start
starting USB...
Bus usb@47401800: Port not available.
```

First, I don't get why it says "Default log level: 0" after I set it (to 
whatever number, apparently). And second, it does not seem to bring me more output about 
the usb issue :-/.

Am I missing something?

Best,
Jonas

On Sat, Mar 6, 2021 at 3:20 AM Sean Anderson mailto:sean...@gmail.com>> wrote:

On 3/5/21 7:10 PM, Jonas Vautherin wrote:
 > Hello!
 >
 > I am learning about Fastboot, and I would like to run it from u-boot and
 > detect it from my host computer (I have the tools on my host, that's
 > working with other devices).
 >
 > I am using a pocketbeagle and I built an image using Yocto. I can get 
into
 > the u-boot prompt at boot time, and I get the following output:
 >
 > ```
 > Rebooting... reboot: Restarting system
 >
 > U-Boot SPL 2020.07 (Jul 06 2020 - 19:22:53 +)
 > Trying to boot from MMC1
 >
 >
 > U-Boot 2020.07 (Jul 06 2020 - 19:22:53 +)
 >
 > CPU  : AM335X-GP rev 2.1
 > Model: TI AM335x PocketBeagle
 > DRAM:  512 MiB
 > WDT:   Started with servicing (60s timeout)
 > NAND:  0 MiB
 > MMC:   OMAP SD/MMC: 0
 > Loading Environment from FAT... *** Warning - bad CRC, using default
 > environment
 >
 >  not set. Validating first E-fuse MAC
 > Net:   No ethernet found.
 > Hit any key to stop autoboot:  2
 > ```
 >
 > If I hit a key here, I get the u-boot prompt (`=>`) where I find
 > "fastboot". The thing is that none of the fastboot commands I run have 
any
 > output:

This is normal. There will be output only when you issue commands.

 >
 > * fastboot usb 0
 > * fastboot usb
 > * fastboot udp
 >
 > Now, fastboot udp is not enabled in my defconfig, but the udp gadget
 > support is, and the usb fastboot gadget is enabled, too. From my host, I
 > just don't see anything in the `dmesg` output.
 >
 > Here are a few questions:
 >
 > * Does fastboot usb go over ethernet? If yes, I guess that the "Net: No
 > ethernet found." message is an issue that I need to fix such that a new 
usb
 > network interface is created by my host, but from my tests with this
 > proprietary device I own, it does not seem to be enumerated as a network
 > interface.

Only udp goes over ethernet (though I suppose you could use a
usb-ethernet gadget/dongle).

 > * In readthedocs [1], it mentions that "The CONFIG_USB_GADGET_VENDOR_NUM
 > must be one of the numbers supported by the fastboot client." In my 
setup,
 > it is set to 0x0451, and I did not find what is supposed to be supported 
in
 > fastboot.cpp [2]. So from the host, I also tried `fastboot -i 0x0451
 > devices`. Is that an issue?

The fastboot client detects devices with two bulk endpoints and the
correct interface (see match_fastboot and filter_usb_device). Generally,
you will only have to specify the vid/pid/serial if you have multiple
devices plugged in at once.

 > * I thought that maybe I should start USB, because the output of `usb 
tree`
 > says "USB is stopped. Please issue 'usb start' first.". But running `usb
 > start` errors with "Bus usb@47401800: Port not available.". Is that 
related
 > to fastboot at all, i.e. should I be concerned about that? And how can I
 > debug it?

That's probably why your fastboot isn't working :)

You can try debugging it by enabling debug messages. If you want less than
a firehose, you can try setting the default log level to info, and then
setting it to debug before running usb start. See [1] for details.

[1] https://u-boot.readthedocs.io/en/latest/develop/logging.html

--Sean

 > Thanks in advance for the help!
 > Jonas
 >
 > [1]: https://u-boot.readthedocs.io/en/latest/android/fastboot.html
 > [2]:
 > 
https://android.googlesource.com/platform/system/core/+/master/fastboot/fastboot.cpp
 >





Re: Fastboot

2021-03-06 Thread Jonas Vautherin
Thanks a lot Sean!

I tried to enable logging by using the following CONFIG_:

```
CONFIG_LOG=y
CONFIG_SPL_LOG=y
CONFIG_TPL_LOG=y
CONFIG_LOG_MAX_LEVEL=5
CONFIG_SPL_LOG_MAX_LEVEL=3
CONFIG_TPL_LOG_MAX_LEVEL=3
CONFIG_LOG_DEFAULT_LEVEL=7
CONFIG_LOG_CONSOLE=y
CONFIG_SPL_LOG_CONSOLE=y
CONFIG_TPL_LOG_CONSOLE=y

CONFIG_CMD_LOG=y
```

And I got the "log" function indeed. But it did not have the effect I was
hoping for:

```
=> log level set 7
=> log level
Default log level: 0
=> usb start
starting USB...
Bus usb@47401800: Port not available.
```

First, I don't get why it says "Default log level: 0" after I set it (to
whatever number, apparently). And second, it does not seem to bring me more
output about the usb issue :-/.

Am I missing something?

Best,
Jonas

On Sat, Mar 6, 2021 at 3:20 AM Sean Anderson  wrote:

> On 3/5/21 7:10 PM, Jonas Vautherin wrote:
> > Hello!
> >
> > I am learning about Fastboot, and I would like to run it from u-boot and
> > detect it from my host computer (I have the tools on my host, that's
> > working with other devices).
> >
> > I am using a pocketbeagle and I built an image using Yocto. I can get
> into
> > the u-boot prompt at boot time, and I get the following output:
> >
> > ```
> > Rebooting... reboot: Restarting system
> >
> > U-Boot SPL 2020.07 (Jul 06 2020 - 19:22:53 +)
> > Trying to boot from MMC1
> >
> >
> > U-Boot 2020.07 (Jul 06 2020 - 19:22:53 +)
> >
> > CPU  : AM335X-GP rev 2.1
> > Model: TI AM335x PocketBeagle
> > DRAM:  512 MiB
> > WDT:   Started with servicing (60s timeout)
> > NAND:  0 MiB
> > MMC:   OMAP SD/MMC: 0
> > Loading Environment from FAT... *** Warning - bad CRC, using default
> > environment
> >
> >  not set. Validating first E-fuse MAC
> > Net:   No ethernet found.
> > Hit any key to stop autoboot:  2
> > ```
> >
> > If I hit a key here, I get the u-boot prompt (`=>`) where I find
> > "fastboot". The thing is that none of the fastboot commands I run have
> any
> > output:
>
> This is normal. There will be output only when you issue commands.
>
> >
> > * fastboot usb 0
> > * fastboot usb
> > * fastboot udp
> >
> > Now, fastboot udp is not enabled in my defconfig, but the udp gadget
> > support is, and the usb fastboot gadget is enabled, too. From my host, I
> > just don't see anything in the `dmesg` output.
> >
> > Here are a few questions:
> >
> > * Does fastboot usb go over ethernet? If yes, I guess that the "Net: No
> > ethernet found." message is an issue that I need to fix such that a new
> usb
> > network interface is created by my host, but from my tests with this
> > proprietary device I own, it does not seem to be enumerated as a network
> > interface.
>
> Only udp goes over ethernet (though I suppose you could use a
> usb-ethernet gadget/dongle).
>
> > * In readthedocs [1], it mentions that "The CONFIG_USB_GADGET_VENDOR_NUM
> > must be one of the numbers supported by the fastboot client." In my
> setup,
> > it is set to 0x0451, and I did not find what is supposed to be supported
> in
> > fastboot.cpp [2]. So from the host, I also tried `fastboot -i 0x0451
> > devices`. Is that an issue?
>
> The fastboot client detects devices with two bulk endpoints and the
> correct interface (see match_fastboot and filter_usb_device). Generally,
> you will only have to specify the vid/pid/serial if you have multiple
> devices plugged in at once.
>
> > * I thought that maybe I should start USB, because the output of `usb
> tree`
> > says "USB is stopped. Please issue 'usb start' first.". But running `usb
> > start` errors with "Bus usb@47401800: Port not available.". Is that
> related
> > to fastboot at all, i.e. should I be concerned about that? And how can I
> > debug it?
>
> That's probably why your fastboot isn't working :)
>
> You can try debugging it by enabling debug messages. If you want less than
> a firehose, you can try setting the default log level to info, and then
> setting it to debug before running usb start. See [1] for details.
>
> [1] https://u-boot.readthedocs.io/en/latest/develop/logging.html
>
> --Sean
>
> > Thanks in advance for the help!
> > Jonas
> >
> > [1]: https://u-boot.readthedocs.io/en/latest/android/fastboot.html
> > [2]:
> >
> https://android.googlesource.com/platform/system/core/+/master/fastboot/fastboot.cpp
> >
>
>


Re: [PATCH v2 10/19] video: sunxi: dw-hdmi: probe driver by compatible

2021-03-06 Thread Andre Przywara
On Sat,  6 Mar 2021 20:54:28 +0100
Jernej Skrabec  wrote:

> Currently sunxi dw-hdmi driver is probed unconditionally, even if there
> is no such device.
> 
> Switch driver to probing via compatible string. This brings many
> benefits - driver can read DT node and allows driver to be always
> enabled.

Confirmed that this the one compatible string that all supported SoCs
use.

> Signed-off-by: Jernej Skrabec 

Reviewed-by: Andre Przywara 

Thanks!
Andre

> ---
>  drivers/video/sunxi/sunxi_dw_hdmi.c | 10 ++
>  1 file changed, 6 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/video/sunxi/sunxi_dw_hdmi.c 
> b/drivers/video/sunxi/sunxi_dw_hdmi.c
> index 6d2bc206fc2c..6f77b2a43b40 100644
> --- a/drivers/video/sunxi/sunxi_dw_hdmi.c
> +++ b/drivers/video/sunxi/sunxi_dw_hdmi.c
> @@ -372,14 +372,16 @@ static const struct dm_display_ops sunxi_dw_hdmi_ops = {
>   .mode_valid = sunxi_dw_hdmi_mode_valid,
>  };
>  
> +static const struct udevice_id sunxi_dw_hdmi_ids[] = {
> + { .compatible = "allwinner,sun8i-a83t-dw-hdmi" },
> + { }
> +};
> +
>  U_BOOT_DRIVER(sunxi_dw_hdmi) = {
>   .name   = "sunxi_dw_hdmi",
>   .id = UCLASS_DISPLAY,
> + .of_match = sunxi_dw_hdmi_ids,
>   .ops= _dw_hdmi_ops,
>   .probe  = sunxi_dw_hdmi_probe,
>   .priv_auto  = sizeof(struct sunxi_dw_hdmi_priv),
>  };
> -
> -U_BOOT_DRVINFO(sunxi_dw_hdmi) = {
> - .name = "sunxi_dw_hdmi"
> -};



Re: [PATCH v2 09/19] video: sunxi: de2: switch to public uclass functions

2021-03-06 Thread Andre Przywara
On Sat,  6 Mar 2021 20:54:27 +0100
Jernej Skrabec  wrote:

> Currently DE2 driver uses functions which are defined in internal
> headers. They are not meant to be used outside of uclass framework.
> Switch DE2 driver to public ones. This has additional benefit that
> device_probe doesn't need to be called manually.

Indeed, good solution: for the calls in _probe(), we call de2_init()
right afterwards, which would explicitly call probe for the display, so
this both saves this call and the usage of the internal function.
For the calls in simplefb_setup: the DM framework checks if a device
has already been activated, so there is no problem with double probes.

However, actually testing this on a Pine64-LTS revealed that this breaks
on the A64: I only get a black screen (bisecting down to this commit).

I didn't investigate any further yet, just wanted to give a heads up.

Cheers,
Andre

> Signed-off-by: Jernej Skrabec 
> ---
>  drivers/video/sunxi/sunxi_de2.c | 29 ++---
>  1 file changed, 10 insertions(+), 19 deletions(-)
> 
> diff --git a/drivers/video/sunxi/sunxi_de2.c b/drivers/video/sunxi/sunxi_de2.c
> index 6b836a011944..e02d359cd259 100644
> --- a/drivers/video/sunxi/sunxi_de2.c
> +++ b/drivers/video/sunxi/sunxi_de2.c
> @@ -19,8 +19,6 @@
>  #include 
>  #include 
>  #include 
> -#include 
> -#include 
>  #include 
>  #include "simplefb_common.h"
>  
> @@ -198,13 +196,6 @@ static int sunxi_de2_init(struct udevice *dev, ulong 
> fbbase,
>  
>   disp_uc_plat->source_id = mux;
>  
> - ret = device_probe(disp);
> - if (ret) {
> - debug("%s: device '%s' display won't probe (ret=%d)\n",
> -   __func__, dev->name, ret);
> - return ret;
> - }
> -
>   ret = display_read_timing(disp, );
>   if (ret) {
>   debug("%s: Failed to read timings\n", __func__);
> @@ -245,8 +236,8 @@ static int sunxi_de2_probe(struct udevice *dev)
>   if (!(gd->flags & GD_FLG_RELOC))
>   return 0;
>  
> - ret = uclass_find_device_by_name(UCLASS_DISPLAY,
> -  "sunxi_lcd", );
> + ret = uclass_get_device_by_driver(UCLASS_DISPLAY,
> +   DM_DRIVER_GET(sunxi_lcd), );
>   if (!ret) {
>   int mux;
>  
> @@ -262,8 +253,8 @@ static int sunxi_de2_probe(struct udevice *dev)
>  
>   debug("%s: lcd display not found (ret=%d)\n", __func__, ret);
>  
> - ret = uclass_find_device_by_name(UCLASS_DISPLAY,
> -  "sunxi_dw_hdmi", );
> + ret = uclass_get_device_by_driver(UCLASS_DISPLAY,
> +   DM_DRIVER_GET(sunxi_dw_hdmi), );
>   if (!ret) {
>   int mux;
>   if (IS_ENABLED(CONFIG_MACH_SUNXI_H3_H5))
> @@ -332,8 +323,8 @@ int sunxi_simplefb_setup(void *blob)
>   mux = 1;
>  
>   /* Skip simplefb setting if DE2 / HDMI is not present */
> - ret = uclass_find_device_by_name(UCLASS_VIDEO,
> -  "sunxi_de2", );
> + ret = uclass_get_device_by_driver(UCLASS_VIDEO,
> +   DM_DRIVER_GET(sunxi_de2), );
>   if (ret) {
>   debug("DE2 not present\n");
>   return 0;
> @@ -342,8 +333,8 @@ int sunxi_simplefb_setup(void *blob)
>   return 0;
>   }
>  
> - ret = uclass_find_device_by_name(UCLASS_DISPLAY,
> -  "sunxi_dw_hdmi", );
> + ret = uclass_get_device_by_driver(UCLASS_DISPLAY,
> +   DM_DRIVER_GET(sunxi_dw_hdmi), );
>   if (ret) {
>   debug("HDMI not present\n");
>   } else if (device_active(hdmi)) {
> @@ -355,8 +346,8 @@ int sunxi_simplefb_setup(void *blob)
>   debug("HDMI present but not probed\n");
>   }
>  
> - ret = uclass_find_device_by_name(UCLASS_DISPLAY,
> -  "sunxi_lcd", );
> + ret = uclass_get_device_by_driver(UCLASS_DISPLAY,
> +   DM_DRIVER_GET(sunxi_lcd), );
>   if (ret)
>   debug("LCD not present\n");
>   else if (device_active(lcd))



Re: [PATCH v2 08/19] video: sunxi: Remove TV probe from DE2

2021-03-06 Thread Andre Przywara
On Sat,  6 Mar 2021 20:54:26 +0100
Jernej Skrabec  wrote:

> TV driver was never fully implemented. Remove search for it from DE2
> driver.

Correct, there is no driver in the tree which would match this string.

> Signed-off-by: Jernej Skrabec 

Reviewed-by: Andre Przywara 

Cheers,
Andre

> ---
>  drivers/video/sunxi/sunxi_de2.c | 15 +--
>  1 file changed, 1 insertion(+), 14 deletions(-)
> 
> diff --git a/drivers/video/sunxi/sunxi_de2.c b/drivers/video/sunxi/sunxi_de2.c
> index a3e21aa5f13e..6b836a011944 100644
> --- a/drivers/video/sunxi/sunxi_de2.c
> +++ b/drivers/video/sunxi/sunxi_de2.c
> @@ -281,20 +281,7 @@ static int sunxi_de2_probe(struct udevice *dev)
>  
>   debug("%s: hdmi display not found (ret=%d)\n", __func__, ret);
>  
> - ret = uclass_find_device_by_name(UCLASS_DISPLAY,
> - "sunxi_tve", );
> - if (ret) {
> - debug("%s: tv not found (ret=%d)\n", __func__, ret);
> - return ret;
> - }
> -
> - ret = sunxi_de2_init(dev, plat->base, VIDEO_BPP32, disp, 1, true);
> - if (ret)
> - return ret;
> -
> - video_set_flush_dcache(dev, 1);
> -
> - return 0;
> + return -ENODEV;
>  }
>  
>  static int sunxi_de2_bind(struct udevice *dev)



Re: [PATCH v2 06/19] video: sunxi: Use DW-HDMI hpd function

2021-03-06 Thread Andre Przywara
On Sat,  6 Mar 2021 20:54:24 +0100
Jernej Skrabec  wrote:

> It turns out that there are two ways how hot plug detection can be done.
> One is standard way for DW HDMI controller - checking bit 2 in 0x3004
> register. Another way is applicable only to Allwinner custom PHY - by
> checking bit 19 in register 0x10038. Both method are equally good as far
> as we know.
> 
> Use standard method in order to reduce amount of custom code.

Thanks for the clarification!
 
> Signed-off-by: Jernej Skrabec 

Reviewed-by: Andre Przywara 

> ---
>  drivers/video/sunxi/sunxi_dw_hdmi.c | 34 +
>  1 file changed, 6 insertions(+), 28 deletions(-)
> 
> diff --git a/drivers/video/sunxi/sunxi_dw_hdmi.c 
> b/drivers/video/sunxi/sunxi_dw_hdmi.c
> index e3811a2ec15f..37e78ff24111 100644
> --- a/drivers/video/sunxi/sunxi_dw_hdmi.c
> +++ b/drivers/video/sunxi/sunxi_dw_hdmi.c
> @@ -114,28 +114,6 @@ static void sunxi_dw_hdmi_phy_init(void)
>   writel(0x42494E47, >unscramble);
>  }
>  
> -static int sunxi_dw_hdmi_get_plug_in_status(void)
> -{
> - struct sunxi_hdmi_phy * const phy =
> - (struct sunxi_hdmi_phy *)(SUNXI_HDMI_BASE + HDMI_PHY_OFFS);
> -
> - return !!(readl(>status) & (1 << 19));
> -}
> -
> -static int sunxi_dw_hdmi_wait_for_hpd(void)
> -{
> - ulong start;
> -
> - start = get_timer(0);
> - do {
> - if (sunxi_dw_hdmi_get_plug_in_status())
> - return 0;
> - udelay(100);
> - } while (get_timer(start) < 300);
> -
> - return -1;
> -}
> -
>  static void sunxi_dw_hdmi_phy_set(uint clock, int phy_div)
>  {
>   struct sunxi_hdmi_phy * const phy =
> @@ -370,12 +348,6 @@ static int sunxi_dw_hdmi_probe(struct udevice *dev)
>  
>   sunxi_dw_hdmi_phy_init();
>  
> - ret = sunxi_dw_hdmi_wait_for_hpd();
> - if (ret < 0) {
> - debug("hdmi can not get hpd signal\n");
> - return -1;
> - }
> -
>   priv->hdmi.ioaddr = SUNXI_HDMI_BASE;
>   priv->hdmi.i2c_clk_high = 0xd8;
>   priv->hdmi.i2c_clk_low = 0xfe;
> @@ -383,6 +355,12 @@ static int sunxi_dw_hdmi_probe(struct udevice *dev)
>   priv->hdmi.phy_set = sunxi_dw_hdmi_phy_cfg;
>   priv->mux = uc_plat->source_id;
>  
> + ret = dw_hdmi_phy_wait_for_hpd(>hdmi);
> + if (ret < 0) {
> + debug("hdmi can not get hpd signal\n");
> + return -1;
> + }
> +
>   uclass_get_device_by_phandle(UCLASS_I2C, dev, "ddc-i2c-bus",
>>hdmi.ddc_bus);
>  



Re: [PATCH v2 04/19] common: edid: extract code for detailed timing search

2021-03-06 Thread Andre Przywara
On Sat,  6 Mar 2021 20:54:22 +0100
Jernej Skrabec  wrote:

> Code which searches for valid detailed timing entry will be used in more
> places. Extract it.
> 
> No functional change is made. However, descriptors are casted to
> edid_detailed_timing instead of edid_monitor_descriptor. Descriptor can
> be of either type, but since we're interested only in DTD, it is more
> fitting to cast to edid_detailed_timing.

Thanks for adding the explanation!
> 
> Signed-off-by: Jernej Skrabec 

Reviewed-by: Andre Przywara 

> ---
>  common/edid.c | 49 -
>  1 file changed, 28 insertions(+), 21 deletions(-)
> 
> diff --git a/common/edid.c b/common/edid.c
> index 1cb7177742e8..a6c875d9c8e8 100644
> --- a/common/edid.c
> +++ b/common/edid.c
> @@ -169,6 +169,29 @@ static bool cea_is_hdmi_vsdb_present(struct 
> edid_cea861_info *info)
>   return false;
>  }
>  
> +static bool edid_find_valid_timing(void *buf, int count,
> +struct display_timing *timing,
> +bool (*mode_valid)(void *priv,
> + const struct display_timing *timing),
> +void *mode_valid_priv)
> +{
> + struct edid_detailed_timing *t = buf;
> + bool found = false;
> + int i;
> +
> + for (i = 0; i < count && !found; i++, t++)
> + if (EDID_DETAILED_TIMING_PIXEL_CLOCK(*t) != 0) {
> + decode_timing((u8 *)t, timing);
> + if (mode_valid)
> + found = mode_valid(mode_valid_priv,
> +timing);
> + else
> + found = true;
> + }
> +
> + return found;
> +}
> +
>  int edid_get_timing_validate(u8 *buf, int buf_size,
>struct display_timing *timing,
>int *panel_bits_per_colourp,
> @@ -177,8 +200,7 @@ int edid_get_timing_validate(u8 *buf, int buf_size,
>void *mode_valid_priv)
>  {
>   struct edid1_info *edid = (struct edid1_info *)buf;
> - bool timing_done;
> - int i;
> + bool found;
>  
>   if (buf_size < sizeof(*edid) || edid_check_info(edid)) {
>   debug("%s: Invalid buffer\n", __func__);
> @@ -195,25 +217,10 @@ int edid_get_timing_validate(u8 *buf, int buf_size,
>   return -ENOENT;
>   }
>  
> - /* Look for detailed timing */
> - timing_done = false;
> - for (i = 0; i < 4; i++) {
> - struct edid_monitor_descriptor *desc;
> -
> - desc = >monitor_details.descriptor[i];
> - if (desc->zero_flag_1 != 0) {
> - decode_timing((u8 *)desc, timing);
> - if (mode_valid)
> - timing_done = mode_valid(mode_valid_priv,
> -  timing);
> - else
> - timing_done = true;
> -
> - if (timing_done)
> - break;
> - }
> - }
> - if (!timing_done)
> + /* Look for detailed timing in base EDID */
> + found = edid_find_valid_timing(edid->monitor_details.descriptor, 4,
> +timing, mode_valid, mode_valid_priv);
> + if (!found)
>   return -EINVAL;
>  
>   if (edid->version != 1 || edid->revision < 4) {



U-Boot CI error, unable to reproduce locally

2021-03-06 Thread Marek Behun
Hello Tom,

I seem to run into an error on Azure's CI for U-Boot that I cannot
reproduce locally.

It concerns my LTO work https://github.com/u-boot/u-boot/pull/57

The test
  u-boot.u-boot (test.py xilinx_zynq_virt)
is failing with this log
https://dev.azure.com/u-boot/a1096300-2999-4ec4-a21a-4c22075e3771/_apis/build/builds/1936/logs/283

The error seems to be
  make[3]: *** read jobs pipe: No such file or directory.  Stop.
  lto-wrapper: fatal error: make returned 2 exit status
as if make's jobserver died, or something.

But when I build with buildman on my local machine, everything is OK.

How should I proceed?

Marek


request for i.MX8MM Venice test

2021-03-06 Thread Marek Behun
Hello Tim,

you are listed as maintainer of i.MX8MM Venice board in U-Boot.

I am currently working on LTO support for U-Boot, and I have
encountered a problem with i.MX8MM Venice board:
when LTO is enabled, the linking process for SPL does not throw away
relocation information, making the resulting SPL image too big for that
board.

I have added a patch that discards symbols from .rela* section to my
patch series, but I would like you to test whether the patch series
works for your board and does not break anything.

Could you please clone https://github.com/elkablo/u-boot branch lto,
build for imx8mm_venice_defconfig and test whether it boots on your
board and maybe test some U-Boot commands (disk reads, kernel
booting, ...)? If it does not work, could you also please check with
current U-Boot master, to see if it got broken with my patches or with
something different?

Thank you.

Marek


[PATCH] armv8: SPL: discard relocation information

2021-03-06 Thread Marek Behún
For some reason when building SPL for ARMv8 with LTO, the relocation
information is not discarded.

Discard it explicitly in the linker script.

This fixes LTO build for imx8mm_venice_defconfig.

Signed-off-by: Marek Behún 
---
 arch/arm/cpu/armv8/u-boot-spl.lds | 1 +
 1 file changed, 1 insertion(+)

diff --git a/arch/arm/cpu/armv8/u-boot-spl.lds 
b/arch/arm/cpu/armv8/u-boot-spl.lds
index 0e67ab09d7..9edb662b09 100644
--- a/arch/arm/cpu/armv8/u-boot-spl.lds
+++ b/arch/arm/cpu/armv8/u-boot-spl.lds
@@ -77,6 +77,7 @@ SECTIONS
KEEP(*(.__bss_end));
} >.sdram
 
+   /DISCARD/ : { *(.rela*) }
/DISCARD/ : { *(.dynsym) }
/DISCARD/ : { *(.dynstr*) }
/DISCARD/ : { *(.dynamic*) }
-- 
2.26.2



[PATCH u-boot-marvell] ddr: marvell: axp: fix array types have different bounds warning

2021-03-06 Thread Marek Behún
The arrays `pbs_dq_mapping`, `div_ratio1to1` and `div_ratio2to1` have
different bounds declared in header files where these variables are also
defined from the ones declared in source files.

This causes the compiler to complain (when building with LTO):
  ddr3_sdram.c:24:12: warning: type of ‘pbs_dq_mapping’ does not match
   original declaration
   [-Wlto-type-mismatch]
  ddr3_patterns_64bit.h:911:5: note: array types have different bounds
  ddr3_patterns_64bit.h:911:5: note: ‘pbs_dq_mapping’ was previously
 declared here

ddr3_dfs.c:45:11: warning: type of ‘div_ratio1to1’ does not match
   original declaration [-Wlto-type-mismatch]
ddr3_axp_vars.h:167:4: note: array types have different bounds
ddr3_axp_vars.h:167:4: note: ‘div_ratio1to1’ was previously declared
 here

ddr3_dfs.c:46:11: warning: type of ‘div_ratio2to1’ does not match
   original declaration [-Wlto-type-mismatch]
ddr3_axp_vars.h:196:4: note: array types have different bounds
ddr3_axp_vars.h:196:4: note: ‘div_ratio2to1’ was previously declared
 here

CI managed to trigger this as an error when compiling with LTO for AXP.

Fix this by using values from the header files, which seem to be the
correct ones.

Signed-off-by: Marek Behún 
---
 drivers/ddr/marvell/axp/ddr3_dfs.c   | 4 ++--
 drivers/ddr/marvell/axp/ddr3_sdram.c | 2 +-
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/ddr/marvell/axp/ddr3_dfs.c 
b/drivers/ddr/marvell/axp/ddr3_dfs.c
index b58c0fe01e..2a4596680b 100644
--- a/drivers/ddr/marvell/axp/ddr3_dfs.c
+++ b/drivers/ddr/marvell/axp/ddr3_dfs.c
@@ -42,8 +42,8 @@ extern u8 div_ratio[CLK_VCO][CLK_DDR];
 extern void get_target_freq(u32 freq_mode, u32 *ddr_freq, u32 *hclk_ps);
 #else
 extern u16 odt_dynamic[ODT_OPT][MAX_CS];
-extern u8 div_ratio1to1[CLK_CPU][CLK_DDR];
-extern u8 div_ratio2to1[CLK_CPU][CLK_DDR];
+extern u8 div_ratio1to1[CLK_VCO][CLK_DDR];
+extern u8 div_ratio2to1[CLK_VCO][CLK_DDR];
 #endif
 extern u16 odt_static[ODT_OPT][MAX_CS];
 
diff --git a/drivers/ddr/marvell/axp/ddr3_sdram.c 
b/drivers/ddr/marvell/axp/ddr3_sdram.c
index 3a266c6de4..0b150b20f3 100644
--- a/drivers/ddr/marvell/axp/ddr3_sdram.c
+++ b/drivers/ddr/marvell/axp/ddr3_sdram.c
@@ -21,7 +21,7 @@ extern u32 pbs_pattern_32b[2][LEN_PBS_PATTERN];
 #if defined(MV88F78X60)
 extern u32 pbs_pattern_64b[2][LEN_PBS_PATTERN];
 #endif
-extern u32 pbs_dq_mapping[PUP_NUM_64BIT][DQ_NUM];
+extern u32 pbs_dq_mapping[PUP_NUM_64BIT + 1][DQ_NUM];
 
 #if defined(MV88F78X60) || defined(MV88F672X)
 /* PBS locked dq (per pup) */
-- 
2.26.2



test/image/test-imagetools.sh: Broken by 3f04db89

2021-03-06 Thread Vagrant Cascadian
It seems like commit:

3f04db891a353f4b127ed57279279f851c6b4917 image: Check for unit addresses in FIT

Broke test/image/test-imagetools.sh.

I get the impression test-imagetools.sh is more-or-less unmaintained and
deprecated. Does test-imagetools.sh perform tests that are not covered
elsewhere? If it is not maintained (and especially otherwise covered),
it might be worth removing entirely.


Thanks for all your work on u-boot!


live well,
  vagrant


signature.asc
Description: PGP signature


[PATCH u-boot] api: fix a potential serious bug caused by undef CONFIG_SYS_64BIT_LBA

2021-03-06 Thread Marek Behún
The api_public.h header file undefined macro CONFIG_SYS_64BIT_LBA.

But api/api_storage.c includes this header before including part.h,
causing the type of lbaint_t and subsequently the type signature of
blk_dread() and blk_dwrite() functions to change from the rest of U-Boot
(if CONFIG_SYS_64BIT_LBA is defined for the board).

This is of course wrong, because the call to blk_dread() / blk_dwrite()
will recieve mangled arguments.

Fix this by removing the undef of macro CONFIG_SYS_64BIT_LBA and instead
make the immediate code do what it would do as if the macro was not
defined.

Add a FIXME to whoever is maintaining this code.

CI managed to trigger this bug when compiling for lsxhl_defconfig, which
has CONFIG_API selected. The compiler complained about blk_dwrite() and
blk_dread() not matching original declarations:

  include/blk.h:280:15: warning: type of ‘blk_dwrite’ does not match
 original declaration
 [-Wlto-type-mismatch]
  280 | unsigned long blk_dwrite(struct blk_desc *block_dev, lbaint_t st
  |   ^
  drivers/block/blk-uclass.c:456:15: note: type mismatch in parameter 2
  456 | unsigned long blk_dwrite(struct blk_desc *block_dev, lbaint_t st
  |   ^

Signed-off-by: Marek Behún 
---
 include/api_public.h | 23 ++-
 1 file changed, 18 insertions(+), 5 deletions(-)

diff --git a/include/api_public.h b/include/api_public.h
index def103ce22..5a4465ea89 100644
--- a/include/api_public.h
+++ b/include/api_public.h
@@ -70,12 +70,25 @@ struct sys_info {
int mr_no;  /* number of memory regions */
 };
 
-#undef CONFIG_SYS_64BIT_LBA
-#ifdef CONFIG_SYS_64BIT_LBA
-typedefu_int64_t lbasize_t;
-#else
+/*
+ * FIXME: Previously this code was:
+ *
+ *   #undef CONFIG_SYS_64BIT_LBA
+ *   #ifdef CONFIG_SYS_64BIT_LBA
+ *   typedef u_int64_t lbasize_t;
+ *   #else
+ *   typedef unsigned long lbasize_t;
+ *   #endif
+ *
+ * But we cannot just undefine CONFIG_SYS_64BIT_LBA, because then in
+ * api/api_storage.c the type signature of lbaint_t will be different if
+ * CONFIG_SYS_64BIT_LBA is enabled for the board, which can result in various
+ * bugs.
+ * So simply define lbasize_t as an unsigned long, since this was what was done
+ * anyway for at least 13 years, but don't undefine CONFIG_SYS_64BIT_LBA.
+ */
 typedef unsigned long lbasize_t;
-#endif
+
 typedef unsigned long lbastart_t;
 
 #define DEV_TYP_NONE   0x
-- 
2.26.2



[PATCH] Nokia RX-51: Enable CONFIG_WDT to remove deprecation warning

2021-03-06 Thread Pali Rohár
Signed-off-by: Pali Rohár 
---
This patch increase u-boot.bin binary size above maximal limit. So this
patch cannot be applied yet. But it can be applied on top of the LTO
patches. So please put this patch into the queue and include it into
U-Boot after LTO patches are merged.
---
 configs/nokia_rx51_defconfig | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/configs/nokia_rx51_defconfig b/configs/nokia_rx51_defconfig
index 312ca3a1a991..2949c37f721b 100644
--- a/configs/nokia_rx51_defconfig
+++ b/configs/nokia_rx51_defconfig
@@ -67,4 +67,6 @@ CONFIG_CFB_CONSOLE=y
 CONFIG_CFB_CONSOLE_ANSI=y
 # CONFIG_VGA_AS_SINGLE_DEVICE is not set
 CONFIG_SPLASH_SCREEN=y
+# CONFIG_WATCHDOG is not set
+CONFIG_WDT=y
 # CONFIG_GZIP is not set
-- 
2.20.1



Re: [PATCH 1/1] configs: EXT4, FAT, hush shell, env on S-mode MAIX

2021-03-06 Thread Sean Anderson

On 3/6/21 3:20 AM, Heinrich Schuchardt wrote:

* enable storing the environment in the SPI flash
* enable EXT4 and FAT file system
* enable hush shell
* run k210_bootcmd as default boot command

Signed-off-by: Heinrich Schuchardt 
---
  configs/sipeed_maix_smode_defconfig | 11 +++
  1 file changed, 11 insertions(+)

diff --git a/configs/sipeed_maix_smode_defconfig 
b/configs/sipeed_maix_smode_defconfig
index 2516bb7258..c20c389cac 100644
--- a/configs/sipeed_maix_smode_defconfig
+++ b/configs/sipeed_maix_smode_defconfig
@@ -1,10 +1,21 @@
  CONFIG_RISCV=y
  CONFIG_SYS_TEXT_BASE=0x8002
+CONFIG_ENV_SIZE=0x1000
+CONFIG_ENV_OFFSET=0xfff000
+CONFIG_ENV_SECT_SIZE=0x1000
  CONFIG_TARGET_SIPEED_MAIX=y
  CONFIG_ARCH_RV64I=y
  CONFIG_RISCV_SMODE=y
  CONFIG_STACK_SIZE=0x10
+CONFIG_USE_BOOTCOMMAND=y
+CONFIG_BOOTCOMMAND="run k210_bootcmd"
+CONFIG_HUSH_PARSER=y
+CONFIG_MTDIDS_DEFAULT="nor0=spi3:0"
+CONFIG_MTDPARTS_DEFAULT="nor0:1M(u-boot),0x1000@0xfff000(env)"
  # CONFIG_NET is not set
  # CONFIG_INPUT is not set
+CONFIG_SF_DEFAULT_BUS=3
  # CONFIG_DM_ETH is not set
+CONFIG_FS_EXT4=y
+CONFIG_FS_FAT=y
  # CONFIG_EFI_UNICODE_CAPITALIZATION is not set
--
2.30.1



Reviewed-by: Sean Anderson 


Re: [RFC PATCH u-boot 00/12] U-Boot LTO (Sandbox + ARM Nokia RX-51)

2021-03-06 Thread Marek Behun
On Sat, 6 Mar 2021 22:38:52 +0100
Pali Rohár  wrote:

> On Saturday 06 March 2021 22:19:22 Marek Behun wrote:
> > On Sat, 6 Mar 2021 22:00:45 +0100
> > Pali Rohár  wrote:
> >   
> > > On Saturday 06 March 2021 21:54:00 Marek Behun wrote:  
> > > > On Sat, 6 Mar 2021 21:41:14 +0100
> > > > Pali Rohár  wrote:
> > > > 
> > > > > On Saturday 06 March 2021 15:08:13 Tom Rini wrote:
> > > > > > Perhaps we'll default to yes on some SoCs.  The omap3 thing is a bit
> > > > > > odd, but we'll see what happens on real N900 hardware.  
> > > > > 
> > > > > Hello!
> > > > > 
> > > > > Could you send me a link to git repo / branch and tell me from which
> > > > > commit should I do tests on real N900 hardware? I will test it and let
> > > > > you know results.
> > > > > 
> > > > > Adding maemo ML to the loop as on the maemo list are more people with
> > > > > N900 HW and U-Boot.
> > > > 
> > > > https://github.com/elkablo/u-boot branch lto
> > > 
> > > Sorry, compilation is failing :-(
> > > 
> > > $ git clone https://github.com/elkablo/u-boot -b lto --depth=100
> > > Cloning into 'u-boot'...
> > > remote: Enumerating objects: 33644, done.
> > > remote: Counting objects: 100% (33644/33644), done.
> > > remote: Compressing objects: 100% (20116/20116), done.
> > > remote: Total 33644 (delta 15838), reused 19947 (delta 13018), 
> > > pack-reused 0
> > > Receiving objects: 100% (33644/33644), 26.28 MiB | 10.21 MiB/s, done.
> > > Resolving deltas: 100% (15838/15838), done.
> > > 
> > > $ cd u-boot
> > > 
> > > $ make CROSS_COMPILE=arm-linux-gnueabi- nokia_rx51_config
> > >   HOSTCC  scripts/basic/fixdep
> > >   HOSTCC  scripts/kconfig/conf.o
> > >   YACCscripts/kconfig/zconf.tab.c
> > >   LEX scripts/kconfig/zconf.lex.c
> > >   HOSTCC  scripts/kconfig/zconf.tab.o
> > >   HOSTLD  scripts/kconfig/conf
> > > #
> > > # configuration written to .config
> > > #
> > > 
> > > $ make CROSS_COMPILE=arm-linux-gnueabi- u-boot.bin
> > > ...
> > >   LTO u-boot
> > > /usr/lib/gcc-cross/arm-linux-gnueabi/8/../../../../arm-linux-gnueabi/bin/ld:
> > >  
> > > /usr/lib/gcc-cross/arm-linux-gnueabi/8/../../../../arm-linux-gnueabi/bin/ld:
> > >  DWARF error: offset (1258291444) greater than or equal to .debug_str 
> > > size (676)
> > > /usr/lib/gcc-cross/arm-linux-gnueabi/8/../../../../arm-linux-gnueabi/bin/ld:
> > >  DWARF error: offset (1459618036) greater than or equal to .debug_str 
> > > size (676)
> > > /usr/lib/gcc-cross/arm-linux-gnueabi/8/../../../../arm-linux-gnueabi/bin/ld:
> > >  DWARF error: could not find abbrev number 48028
> > > /tmp/cc8l0QSQ.ltrans3.ltrans.o: in function `omap3_set_aux_cr_secure':
> > > :(.text+0x6eb8): undefined reference to 
> > > `do_omap3_emu_romcode_call'
> > > collect2: error: ld returned 1 exit status
> > > make: *** [Makefile:1808: u-boot] Error 1
> > > 
> > > 
> > > I'm using arm-linux-gnueabi-gcc version 8.3.0 which is available in
> > > current Debian stable (Debian 10 Buster).  
> > 
> > Fixed and force-pushed, it seems ar needs the P flag that Bin Meng
> > questioned.  
> 
> Problem is fixed, now compilation succeeded. u-boot.bin has size 243788
> bytes.
> 
> And seems that compiled U-Boot is working fine!
> 
> Nokia RX-51 # version
> U-Boot 2021.04-rc3-00338-g88d0a5042c97 (Mar 06 2021 - 22:19:08 +0100)
> 
> arm-linux-gnueabi-gcc (Debian 8.3.0-2) 8.3.0
> GNU ld (GNU Binutils for Debian) 2.31.1
> 
> I can send binary files via usbtty and 'loadb' command. I can boot linux
> kernel via 'bootm'. I can chainload to another U-Boot binary (loaded by
> 'loadb') via 'go' command. Also 'ext4ls' and 'fatls' commands are
> working. Also 'onenand dump bootloader' is working.
> 
> Do you need something more to test?
> 
> If not you can add my 'Tested-by: Pali Rohár ' line for
> all patches which are up to the commit 88d0a5042c97.
> 
> Good job!

Thanks.

I am still working on these patches, since I have discovered some more
defconfigs which fail to build for one reason or another.

I will send a patch enabling LTO for Nokia N900 though.

marek


Re: [PATCH 1/5] risv: add missing SBI extension definitions

2021-03-06 Thread Sean Anderson

On 3/6/21 12:59 AM, Bin Meng wrote:

On Fri, Mar 5, 2021 at 1:02 AM Heinrich Schuchardt  wrote:


Add the System Reset Extension and the Hart State Management Extension
definitions.

Add missing RFENCE Extension enum values.

The SBI 0.1 extension constants are needed for for the sbi command. Remove
an #ifdef.

Cf. https://github.com/riscv/riscv-sbi-doc/blob/master/riscv-sbi.adoc

Signed-off-by: Heinrich Schuchardt 
---
  arch/riscv/include/asm/sbi.h | 36 ++--
  1 file changed, 34 insertions(+), 2 deletions(-)



U-Boot does not need HSM.


(yet)

As far as I can tell, it's completely conforming for all harts but one
to be put into the STOPPED state by the SBI (with the expectation that
U-Boot or something else start them). Also, while we currently figure
out which harts to start via device tree passed from SBI, that behavior
is not standardized. Going forward, I we may see some SBI
implementations which communicate this sort of info through HSM. Though
this has not happened yet...

--Sean


Re: [RFC PATCH u-boot 00/12] U-Boot LTO (Sandbox + ARM Nokia RX-51)

2021-03-06 Thread Pali Rohár
On Saturday 06 March 2021 22:19:22 Marek Behun wrote:
> On Sat, 6 Mar 2021 22:00:45 +0100
> Pali Rohár  wrote:
> 
> > On Saturday 06 March 2021 21:54:00 Marek Behun wrote:
> > > On Sat, 6 Mar 2021 21:41:14 +0100
> > > Pali Rohár  wrote:
> > >   
> > > > On Saturday 06 March 2021 15:08:13 Tom Rini wrote:  
> > > > > Perhaps we'll default to yes on some SoCs.  The omap3 thing is a bit
> > > > > odd, but we'll see what happens on real N900 hardware.
> > > > 
> > > > Hello!
> > > > 
> > > > Could you send me a link to git repo / branch and tell me from which
> > > > commit should I do tests on real N900 hardware? I will test it and let
> > > > you know results.
> > > > 
> > > > Adding maemo ML to the loop as on the maemo list are more people with
> > > > N900 HW and U-Boot.  
> > > 
> > > https://github.com/elkablo/u-boot branch lto  
> > 
> > Sorry, compilation is failing :-(
> > 
> > $ git clone https://github.com/elkablo/u-boot -b lto --depth=100
> > Cloning into 'u-boot'...
> > remote: Enumerating objects: 33644, done.
> > remote: Counting objects: 100% (33644/33644), done.
> > remote: Compressing objects: 100% (20116/20116), done.
> > remote: Total 33644 (delta 15838), reused 19947 (delta 13018), pack-reused 0
> > Receiving objects: 100% (33644/33644), 26.28 MiB | 10.21 MiB/s, done.
> > Resolving deltas: 100% (15838/15838), done.
> > 
> > $ cd u-boot
> > 
> > $ make CROSS_COMPILE=arm-linux-gnueabi- nokia_rx51_config
> >   HOSTCC  scripts/basic/fixdep
> >   HOSTCC  scripts/kconfig/conf.o
> >   YACCscripts/kconfig/zconf.tab.c
> >   LEX scripts/kconfig/zconf.lex.c
> >   HOSTCC  scripts/kconfig/zconf.tab.o
> >   HOSTLD  scripts/kconfig/conf
> > #
> > # configuration written to .config
> > #
> > 
> > $ make CROSS_COMPILE=arm-linux-gnueabi- u-boot.bin
> > ...
> >   LTO u-boot
> > /usr/lib/gcc-cross/arm-linux-gnueabi/8/../../../../arm-linux-gnueabi/bin/ld:
> >  
> > /usr/lib/gcc-cross/arm-linux-gnueabi/8/../../../../arm-linux-gnueabi/bin/ld:
> >  DWARF error: offset (1258291444) greater than or equal to .debug_str size 
> > (676)
> > /usr/lib/gcc-cross/arm-linux-gnueabi/8/../../../../arm-linux-gnueabi/bin/ld:
> >  DWARF error: offset (1459618036) greater than or equal to .debug_str size 
> > (676)
> > /usr/lib/gcc-cross/arm-linux-gnueabi/8/../../../../arm-linux-gnueabi/bin/ld:
> >  DWARF error: could not find abbrev number 48028
> > /tmp/cc8l0QSQ.ltrans3.ltrans.o: in function `omap3_set_aux_cr_secure':
> > :(.text+0x6eb8): undefined reference to 
> > `do_omap3_emu_romcode_call'
> > collect2: error: ld returned 1 exit status
> > make: *** [Makefile:1808: u-boot] Error 1
> > 
> > 
> > I'm using arm-linux-gnueabi-gcc version 8.3.0 which is available in
> > current Debian stable (Debian 10 Buster).
> 
> Fixed and force-pushed, it seems ar needs the P flag that Bin Meng
> questioned.

Problem is fixed, now compilation succeeded. u-boot.bin has size 243788
bytes.

And seems that compiled U-Boot is working fine!

Nokia RX-51 # version
U-Boot 2021.04-rc3-00338-g88d0a5042c97 (Mar 06 2021 - 22:19:08 +0100)

arm-linux-gnueabi-gcc (Debian 8.3.0-2) 8.3.0
GNU ld (GNU Binutils for Debian) 2.31.1

I can send binary files via usbtty and 'loadb' command. I can boot linux
kernel via 'bootm'. I can chainload to another U-Boot binary (loaded by
'loadb') via 'go' command. Also 'ext4ls' and 'fatls' commands are
working. Also 'onenand dump bootloader' is working.

Do you need something more to test?

If not you can add my 'Tested-by: Pali Rohár ' line for
all patches which are up to the commit 88d0a5042c97.

Good job!


Re: [RFC PATCH u-boot 01/12] build: use thin archives instead of incremental linking

2021-03-06 Thread Marek Behun
On Fri, 5 Mar 2021 08:37:28 -0500
Tom Rini  wrote:

> On Fri, Mar 05, 2021 at 09:34:42PM +0800, Bin Meng wrote:
> > Hi Marek,
> > 
> > On Fri, Mar 5, 2021 at 2:17 AM Marek Behun  wrote:  
> > >
> > > On Thu, 4 Mar 2021 18:57:11 +0800
> > > Bin Meng  wrote:
> > >  
> > > > Hi Marek,
> > > >
> > > > On Wed, Mar 3, 2021 at 12:13 PM Marek Behún  wrote: 
> > > >  
> > > > >
> > > > > Using thin archives instead of incremental linking
> > > > > - saves disk space
> > > > > - works better with dead code elimination
> > > > > - prepares for potential LTO  
> > > >
> > > > The commit message is a little bit confusing. This commit actually
> > > > does 2 things: don't do incremental linking (using --whole-archive),
> > > > and use thin archive (passing T to ar). I believe they are for
> > > > different purposes, so we cannot say "using thin archives instead of
> > > > incremental linking".  
> > > > > -   -Wl,--start-group $(patsubst $(obj)/%,%,$(u-boot-spl-main)) \
> > > > > -   $(patsubst $(obj)/%,%,$(u-boot-spl-platdata)) -Wl,--end-group 
> > > > > \
> > > > > +   -Wl,--whole-archive $(patsubst $(obj)/%,%,$(u-boot-spl-main)) 
> > > > > -Wl,--no-whole-archive \
> > > > > +   -Wl,--start-group $(patsubst 
> > > > > $(obj)/%,%,$(u-boot-spl-platdata)) -Wl,--end-group \  
> > > >
> > > > u-boot-spl-platdata is still within --start-group, --end-group, is
> > > > this intentional?  
> > >
> > > I confess that I did not really study these options, I have made these
> > > changes according to old LTO patches for Linux. But you are right that
> > > it does not make sense. I have fixed this for the next version of this
> > > patch.
> > >  
> > > > Is P required to make everything work?  
> > >
> > > It is not. Removed in next version.  
> > 
> > I did more investigation on this.
> > 
> > The Linux kernel specially added P to ar, in below commit:
> > https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=9a6cfca4f4130444
> > 
> > So it looks like we should keep P here?
> > 
> > But I don't get the point of switching to thin archives. Based on my
> > experiment, LTO does not rely on thin archives. The Linux kernel did
> > not introduce thin archives for LTO.
> > https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=a5967db9af51a84f
> >   
> 
> So technically it would just be part of dealing with the backlog of
> kbuild-resync to take it in this series I guess.
> 

It seems the P flag is needed for ar, otherwise final linking may fail,
for example for nokia rx51. Since Linux uses this as well I am just
gonna put it there.


Re: [RFC PATCH u-boot 00/12] U-Boot LTO (Sandbox + ARM Nokia RX-51)

2021-03-06 Thread Marek Behun
On Sat, 6 Mar 2021 22:00:45 +0100
Pali Rohár  wrote:

> On Saturday 06 March 2021 21:54:00 Marek Behun wrote:
> > On Sat, 6 Mar 2021 21:41:14 +0100
> > Pali Rohár  wrote:
> >   
> > > On Saturday 06 March 2021 15:08:13 Tom Rini wrote:  
> > > > Perhaps we'll default to yes on some SoCs.  The omap3 thing is a bit
> > > > odd, but we'll see what happens on real N900 hardware.
> > > 
> > > Hello!
> > > 
> > > Could you send me a link to git repo / branch and tell me from which
> > > commit should I do tests on real N900 hardware? I will test it and let
> > > you know results.
> > > 
> > > Adding maemo ML to the loop as on the maemo list are more people with
> > > N900 HW and U-Boot.  
> > 
> > https://github.com/elkablo/u-boot branch lto  
> 
> Sorry, compilation is failing :-(
> 
> $ git clone https://github.com/elkablo/u-boot -b lto --depth=100
> Cloning into 'u-boot'...
> remote: Enumerating objects: 33644, done.
> remote: Counting objects: 100% (33644/33644), done.
> remote: Compressing objects: 100% (20116/20116), done.
> remote: Total 33644 (delta 15838), reused 19947 (delta 13018), pack-reused 0
> Receiving objects: 100% (33644/33644), 26.28 MiB | 10.21 MiB/s, done.
> Resolving deltas: 100% (15838/15838), done.
> 
> $ cd u-boot
> 
> $ make CROSS_COMPILE=arm-linux-gnueabi- nokia_rx51_config
>   HOSTCC  scripts/basic/fixdep
>   HOSTCC  scripts/kconfig/conf.o
>   YACCscripts/kconfig/zconf.tab.c
>   LEX scripts/kconfig/zconf.lex.c
>   HOSTCC  scripts/kconfig/zconf.tab.o
>   HOSTLD  scripts/kconfig/conf
> #
> # configuration written to .config
> #
> 
> $ make CROSS_COMPILE=arm-linux-gnueabi- u-boot.bin
> ...
>   LTO u-boot
> /usr/lib/gcc-cross/arm-linux-gnueabi/8/../../../../arm-linux-gnueabi/bin/ld: 
> /usr/lib/gcc-cross/arm-linux-gnueabi/8/../../../../arm-linux-gnueabi/bin/ld: 
> DWARF error: offset (1258291444) greater than or equal to .debug_str size 
> (676)
> /usr/lib/gcc-cross/arm-linux-gnueabi/8/../../../../arm-linux-gnueabi/bin/ld: 
> DWARF error: offset (1459618036) greater than or equal to .debug_str size 
> (676)
> /usr/lib/gcc-cross/arm-linux-gnueabi/8/../../../../arm-linux-gnueabi/bin/ld: 
> DWARF error: could not find abbrev number 48028
> /tmp/cc8l0QSQ.ltrans3.ltrans.o: in function `omap3_set_aux_cr_secure':
> :(.text+0x6eb8): undefined reference to 
> `do_omap3_emu_romcode_call'
> collect2: error: ld returned 1 exit status
> make: *** [Makefile:1808: u-boot] Error 1
> 
> 
> I'm using arm-linux-gnueabi-gcc version 8.3.0 which is available in
> current Debian stable (Debian 10 Buster).

Fixed and force-pushed, it seems ar needs the P flag that Bin Meng
questioned.


Re: [RFC PATCH u-boot 00/12] U-Boot LTO (Sandbox + ARM Nokia RX-51)

2021-03-06 Thread Pali Rohár
On Saturday 06 March 2021 21:54:00 Marek Behun wrote:
> On Sat, 6 Mar 2021 21:41:14 +0100
> Pali Rohár  wrote:
> 
> > On Saturday 06 March 2021 15:08:13 Tom Rini wrote:
> > > Perhaps we'll default to yes on some SoCs.  The omap3 thing is a bit
> > > odd, but we'll see what happens on real N900 hardware.  
> > 
> > Hello!
> > 
> > Could you send me a link to git repo / branch and tell me from which
> > commit should I do tests on real N900 hardware? I will test it and let
> > you know results.
> > 
> > Adding maemo ML to the loop as on the maemo list are more people with
> > N900 HW and U-Boot.
> 
> https://github.com/elkablo/u-boot branch lto

Sorry, compilation is failing :-(

$ git clone https://github.com/elkablo/u-boot -b lto --depth=100
Cloning into 'u-boot'...
remote: Enumerating objects: 33644, done.
remote: Counting objects: 100% (33644/33644), done.
remote: Compressing objects: 100% (20116/20116), done.
remote: Total 33644 (delta 15838), reused 19947 (delta 13018), pack-reused 0
Receiving objects: 100% (33644/33644), 26.28 MiB | 10.21 MiB/s, done.
Resolving deltas: 100% (15838/15838), done.

$ cd u-boot

$ make CROSS_COMPILE=arm-linux-gnueabi- nokia_rx51_config
  HOSTCC  scripts/basic/fixdep
  HOSTCC  scripts/kconfig/conf.o
  YACCscripts/kconfig/zconf.tab.c
  LEX scripts/kconfig/zconf.lex.c
  HOSTCC  scripts/kconfig/zconf.tab.o
  HOSTLD  scripts/kconfig/conf
#
# configuration written to .config
#

$ make CROSS_COMPILE=arm-linux-gnueabi- u-boot.bin
...
  LTO u-boot
/usr/lib/gcc-cross/arm-linux-gnueabi/8/../../../../arm-linux-gnueabi/bin/ld: 
/usr/lib/gcc-cross/arm-linux-gnueabi/8/../../../../arm-linux-gnueabi/bin/ld: 
DWARF error: offset (1258291444) greater than or equal to .debug_str size (676)
/usr/lib/gcc-cross/arm-linux-gnueabi/8/../../../../arm-linux-gnueabi/bin/ld: 
DWARF error: offset (1459618036) greater than or equal to .debug_str size (676)
/usr/lib/gcc-cross/arm-linux-gnueabi/8/../../../../arm-linux-gnueabi/bin/ld: 
DWARF error: could not find abbrev number 48028
/tmp/cc8l0QSQ.ltrans3.ltrans.o: in function `omap3_set_aux_cr_secure':
:(.text+0x6eb8): undefined reference to `do_omap3_emu_romcode_call'
collect2: error: ld returned 1 exit status
make: *** [Makefile:1808: u-boot] Error 1


I'm using arm-linux-gnueabi-gcc version 8.3.0 which is available in
current Debian stable (Debian 10 Buster).


Re: [RFC PATCH u-boot 00/12] U-Boot LTO (Sandbox + ARM Nokia RX-51)

2021-03-06 Thread Marek Behun
On Sat, 6 Mar 2021 21:41:14 +0100
Pali Rohár  wrote:

> On Saturday 06 March 2021 15:08:13 Tom Rini wrote:
> > Perhaps we'll default to yes on some SoCs.  The omap3 thing is a bit
> > odd, but we'll see what happens on real N900 hardware.  
> 
> Hello!
> 
> Could you send me a link to git repo / branch and tell me from which
> commit should I do tests on real N900 hardware? I will test it and let
> you know results.
> 
> Adding maemo ML to the loop as on the maemo list are more people with
> N900 HW and U-Boot.

https://github.com/elkablo/u-boot branch lto


[PATCH] doc: stm32mp1: Use u-boot.itb if CONFIG_SPL_LOAD_FIT=y

2021-03-06 Thread Marek Vasut
For systems where SPL loads fitImage, i.e. CONFIG_SPL_LOAD_FIT=y, use
u-boot.itb in the relevant documentation parts. Otherwise use u-boot.img.

Signed-off-by: Marek Vasut 
Cc: Patrice Chotard 
Cc: Patrick Delaunay 
---
 doc/board/st/stm32mp1.rst | 16 +++-
 1 file changed, 11 insertions(+), 5 deletions(-)

diff --git a/doc/board/st/stm32mp1.rst b/doc/board/st/stm32mp1.rst
index 20f5c9e301e..f0c2b09b988 100644
--- a/doc/board/st/stm32mp1.rst
+++ b/doc/board/st/stm32mp1.rst
@@ -237,7 +237,8 @@ Build Procedure
   - For Basic boot
 
  - FSBL = spl/u-boot-spl.stm32
- - SSBL = u-boot.img
+ - SSBL = u-boot.img (without CONFIG_SPL_LOAD_FIT) or
+  u-boot.itb (with CONFIG_SPL_LOAD_FIT=y)
 
 Switch Setting for Boot Mode
 
@@ -347,7 +348,9 @@ c) copy the FSBL (2 times) and SSBL file on the correct 
partition.
 
 # dd if=u-boot-spl.stm32 of=/dev/mmcblk0p1
 # dd if=u-boot-spl.stm32 of=/dev/mmcblk0p2
-# dd if=u-boot.img of=/dev/mmcblk0p3
+# dd if=u-boot.img of=/dev/mmcblk0p3 # Without CONFIG_SPL_LOAD_FIT
+  OR
+  dd if=u-boot.itb of=/dev/mmcblk0p3 # With CONFIG_SPL_LOAD_FIT=y
 
for trusted boot mode: ::
 
@@ -363,8 +366,9 @@ Prepare eMMC
 You can use U-Boot to copy binary in eMMC.
 
 In the next example, you need to boot from SD card and the images
-(u-boot-spl.stm32, u-boot.img) are presents on SD card (mmc 0)
-in ext4 partition 4 (bootfs).
+(u-boot-spl.stm32, u-boot.img for systems without CONFIG_SPL_LOAD_FIT
+or u-boot.itb for systems with CONFIG_SPL_LOAD_FIT=y) are presents on
+SD card (mmc 0) in ext4 partition 4 (bootfs).
 
 To boot from SD card, select BootPinMode = 1 0 1 and reset.
 
@@ -387,7 +391,9 @@ b) copy SPL on eMMC on firts boot partition
 
 c) copy U-Boot in first GPT partition of eMMC::
 
-# ext4load mmc 0:4 0xC000 u-boot.img
+# ext4load mmc 0:4 0xC000 u-boot.img # Without CONFIG_SPL_LOAD_FIT
+  OR
+  ext4load mmc 0:4 0xC000 u-boot.itb # With CONFIG_SPL_LOAD_FIT=y
 # mmc dev 1
 # part start mmc 1 1 partstart
 # mmc write ${fileaddr} ${partstart} ${filesize}
-- 
2.30.1



Re: [RFC PATCH u-boot 00/12] U-Boot LTO (Sandbox + ARM Nokia RX-51)

2021-03-06 Thread Pali Rohár
On Saturday 06 March 2021 15:08:13 Tom Rini wrote:
> Perhaps we'll default to yes on some SoCs.  The omap3 thing is a bit
> odd, but we'll see what happens on real N900 hardware.

Hello!

Could you send me a link to git repo / branch and tell me from which
commit should I do tests on real N900 hardware? I will test it and let
you know results.

Adding maemo ML to the loop as on the maemo list are more people with
N900 HW and U-Boot.


Re: [PATCH] cmd: part: number: remove inconsistent 0x from returned value

2021-03-06 Thread Tom Rini
On Fri, Mar 05, 2021 at 07:35:24AM -0700, Simon Glass wrote:
> Hi,
> 
> On Fri, 5 Mar 2021 at 07:33, Stefan Herbrechtsmeier
>  wrote:
> >
> > Hi Eugeniu,
> >
> > Am 05.03.2021 um 12:52 schrieb Eugeniu Rosca:
> > > Hello Stefan,
> > >
> > > On Fri, Mar 05, 2021 at 07:39:04AM +, Stefan Herbrechtsmeier wrote:
> > >> From: Stefan Herbrechtsmeier 
> > >>
> > >> The part number sub-command returns the hexadecimal value with a leading
> > >> 0x.
> > >
> > > That's to make sure that:
> > > - users have clear and unequivocal feedback that '10'
> > >   returned by the command is really HEX 10, not DEC 10.
> > > - other U-Boot commands which need to take '0x10' as input
> > >   will interpret it correctly, regardless of the way these
> > >   other commands implement ascii-to-integer conversion.
> >
> > 'Almost all U-Boot commands expect numbers to be entered in hexadecimal
> > input format.' [1]
> >
> > The filesystem commands use `simple_strtoul(.., 16)` and interpret the
> > value as hexadecimal value.
> >
> > The 0x suggests that a 10 will be interpreted as decimal value and this
> > isn't true.
> >
> > >> This is inconsistent with other values in the command
> > >
> > > It could be, but it is then better to fix the inconsistency in those
> > > commands/sub-commands which add the ambiguity.
> >
> > Normally you are right but U-Boot by design use hexadecimal values
> > without 0x. The env_set_hex functions doesn't use 0x.
> >
> > >> and U-Boot uses hexadecimal values generally.
> > >
> > > The key word is "generally", but not always. Some U-Boot commands will
> > > process '10' as HEX 10 and some will process 10 as DEC 10. So, in order
> > > to avoid these games, I vote for leaving the 0x in place.
> 
> I would be very surprised if 10 means 0d10 in a partition number. I
> agree that putting a 0x in these values is a dangerous precedent and
> will just cause confusion. U-Boot uses hex for addresses and most
> arguments
> 
> >
> > You can avoid it only if you could mark decimal numbers and that is
> > impossible.
> 
> 0d10 is available. People are not used to it though.
> 
> Reviewed-by: Simon Glass 
> 
> >
> > @Tom: Does U-Boot still expect numbers to be hexadecimal values?
> >
> > [1] https://www.denx.de/wiki/DULG/UBootCommandLineInterface
> >
> > >>
> > >> Signed-off-by: Stefan Herbrechtsmeier 
> > >> 
> > >>
> > >> ---
> > >>
> > >>   cmd/part.c | 2 +-
> > >>   1 file changed, 1 insertion(+), 1 deletion(-)
> > >>
> > >> diff --git a/cmd/part.c b/cmd/part.c
> > >> index 3395c17b89..56e1852c66 100644
> > >> --- a/cmd/part.c
> > >> +++ b/cmd/part.c
> > >> @@ -152,7 +152,7 @@ static int do_part_info(int argc, char *const 
> > >> argv[], enum cmd_part_info param)
> > >>  snprintf(buf, sizeof(buf), LBAF, info.size);
> > >>  break;
> > >>  case CMD_PART_INFO_NUMBER:
> > >> -snprintf(buf, sizeof(buf), "0x%x", part);
> > >> +snprintf(buf, sizeof(buf), "%x", part);
> > >

I am not a fan of this change as well, especially having spent time on
some platforms that have literally 20+ partition entries.  Being clear
here that this is a hex value is important.


-- 
Tom


signature.asc
Description: PGP signature


Re: [RFC PATCH u-boot 00/12] U-Boot LTO (Sandbox + ARM Nokia RX-51)

2021-03-06 Thread Tom Rini
On Sat, Mar 06, 2021 at 06:37:49PM +0100, Marek Behun wrote:
> On Sat, 6 Mar 2021 05:12:12 -0600
> Adam Ford  wrote:
> 
> > On Fri, Mar 5, 2021 at 9:03 PM Adam Ford  wrote:
> > >
> > > On Fri, Mar 5, 2021 at 11:10 AM Adam Ford  wrote:  
> > > >
> > > > On Fri, Mar 5, 2021 at 6:31 AM Stefan Roese  wrote:  
> > > > >
> > > > > On 05.03.21 12:25, Adam Ford wrote:  
> > > > > > On Thu, Mar 4, 2021 at 4:33 PM Marek Behun  
> > > > > > wrote:  
> > > > > >>
> > > > > >> On Thu, 4 Mar 2021 16:18:03 -0600
> > > > > >> Adam Ford  wrote:
> > > > > >>  
> > > > > >>> diff --git a/arch/arm/mach-omap2/omap3/Makefile
> > > > > >>> b/arch/arm/mach-omap2/omap3/Makefile
> > > > > >>> index 91ed8ebc9f..a2cc21c6d2 100644
> > > > > >>> --- a/arch/arm/mach-omap2/omap3/Makefile
> > > > > >>> +++ b/arch/arm/mach-omap2/omap3/Makefile
> > > > > >>> @@ -6,6 +6,8 @@
> > > > > >>>   # If clock.c is compiled for Thumb2, then it fails on OMAP3530
> > > > > >>>   CFLAGS_clock.o += -marm
> > > > > >>>
> > > > > >>> +CFLAGS_REMOVE_file.o := $(LTO_CFLAGS)  
> > > > > >>
> > > > > >> Eh? There is no file.c in arch/arm/mach-omap2/omap3/ directory.  
> > > > > >
> > > > > > It must be from something else that had changed when I did a git 
> > > > > > pull
> > > > > > pull on your repo. I guess that's better news.  
> > > > >
> > > > > It might be a misunderstanding. Marek means that you need to replace
> > > > > "file" with your real filename, like:
> > > > >
> > > > > driver_spi.c ->
> > > > >
> > > > > +CFLAGS_REMOVE_driver_spi.o := $(LTO_CFLAGS)  
> > > >
> > > > I first did a git pull from his git repo, and then blindly copy-pasted
> > > > the suggested link to that above directly.  I don't play with
> > > > Makefiles often, so I didn't really notice that I needed to match the
> > > > line to an actual file.  When I rebuilt, my initial issue with showing
> > > > too much DDR and hanging went away, so I wrongly assumed that this
> > > > fixed it.  In reality, I think it was a patch that had been applied to
> > > > his git repo that got pulled in at the same time.
> > > >
> > > > On the testing front,
> > > > I started testing the da850evm (ARM9) this morning.  I ran into an
> > > > issue that I apparently caused some time ago, and I'm trying to
> > > > resolve that now.  I have it working, but I need to clean it up.  I'll
> > > > push the clean-up to the ML then try the LTO on that board to see if
> > > > U-Boot and/or SPL work with LTO enabled.
> > > >
> > > > As of now, I have one board that seems to fully boot (imx6q_logic) and
> > > > a family of boards that work in U-Boot but not SPL (omap3_logic).
> > > >
> > > > After the da850em, I'll test a 64-bit Renesas board without SPL and a
> > > > 64-bit NXP board with SPL to test.
> > > >
> > > > On the build-testing I have done, I am seeing an average of a 10-20%
> > > > reduction in size for SPL, and a ~ 3% reduction in size in U-Boot.
> > > >  
> > >
> > > With a patch that I've already sent to the mailing list for the
> > > da850evm, it's booting both SPL and U-Boot
> > >
> > > With the compiler I have, the code went from:
> > > SPL24305
> > > U-Boot  381930
> > >
> > > To:
> > > SPL20937
> > > U-Boot  358780
> > >
> > > For a Reduction of:
> > > SPL-3368 (-13.86%)
> > > U-Boot -23150 (-6.06%)
> > >
> > > I didn't test the NOR or NAND booting versions of the da850evm, but I
> > > will try to do that when the time comes.
> > >  
> > 
> > I ran the same tests on the imx8mn_beacon board, and this board boots.
> > 
> > Without LTO
> > SPL 82487
> > U-Boot  704477
> > 
> > With LTO:
> > SPL 74526
> > U-Boot   670859
> > 
> > For a reduction of:
> > SPL -7961 (-9.65%)
> > U-Boot  -33618 (-4.77%)
> 
> Thank you Adam for these tests.
> I think you are right in that we should not enable LTO for all ARM
> boards, but only those that are tested, at least until for example
> about 80% of them are tested.

Perhaps we'll default to yes on some SoCs.  The omap3 thing is a bit
odd, but we'll see what happens on real N900 hardware.  I'm gonna be
pretty confident that the LTO-related issues are in the SoC-specific
areas and probably related to some assumptions or another about where
code gets located within the resulting binary.

-- 
Tom


signature.asc
Description: PGP signature


[PATCH v2 19/19] video: sunxi: dw-hdmi: Use new PHY driver

2021-03-06 Thread Jernej Skrabec
Remove direct PHY managing from dw-hdmi platform driver and use
dedicated driver instead. While at it, enable clocks and deassert reset
lines through clk and reset framework instead of manually configuring
bits.

Signed-off-by: Jernej Skrabec 
---
 drivers/video/sunxi/sunxi_dw_hdmi.c | 225 +---
 1 file changed, 36 insertions(+), 189 deletions(-)

diff --git a/drivers/video/sunxi/sunxi_dw_hdmi.c 
b/drivers/video/sunxi/sunxi_dw_hdmi.c
index 483d57293155..16051baca8c5 100644
--- a/drivers/video/sunxi/sunxi_dw_hdmi.c
+++ b/drivers/video/sunxi/sunxi_dw_hdmi.c
@@ -5,190 +5,26 @@
  * (C) Copyright 2017 Jernej Skrabec 
  */
 
+#include 
 #include 
 #include 
 #include 
 #include 
 #include 
-#include 
-#include 
+#include 
+#include 
 #include 
 #include 
 #include 
 #include 
-#include 
+#include "sunxi_dw_hdmi_phy.h"
 
 struct sunxi_dw_hdmi_priv {
struct dw_hdmi hdmi;
int mux;
+   struct phy phy;
 };
 
-struct sunxi_hdmi_phy {
-   u32 pol;
-   u32 res1[3];
-   u32 read_en;
-   u32 unscramble;
-   u32 res2[2];
-   u32 ctrl;
-   u32 unk1;
-   u32 unk2;
-   u32 pll;
-   u32 clk;
-   u32 unk3;
-   u32 status;
-};
-
-#define HDMI_PHY_OFFS 0x1
-
-static int sunxi_dw_hdmi_get_divider(uint clock)
-{
-   /*
-* Due to missing documentaion of HDMI PHY, we know correct
-* settings only for following four PHY dividers. Select one
-* based on clock speed.
-*/
-   if (clock <= 2700)
-   return 11;
-   else if (clock <= 7425)
-   return 4;
-   else if (clock <= 14850)
-   return 2;
-   else
-   return 1;
-}
-
-static void sunxi_dw_hdmi_phy_init(struct dw_hdmi *hdmi)
-{
-   struct sunxi_hdmi_phy * const phy =
-   (struct sunxi_hdmi_phy *)(hdmi->ioaddr + HDMI_PHY_OFFS);
-   unsigned long tmo;
-   u32 tmp;
-
-   /*
-* HDMI PHY settings are taken as-is from Allwinner BSP code.
-* There is no documentation.
-*/
-   writel(0, >ctrl);
-   setbits_le32(>ctrl, BIT(0));
-   udelay(5);
-   setbits_le32(>ctrl, BIT(16));
-   setbits_le32(>ctrl, BIT(1));
-   udelay(10);
-   setbits_le32(>ctrl, BIT(2));
-   udelay(5);
-   setbits_le32(>ctrl, BIT(3));
-   udelay(40);
-   setbits_le32(>ctrl, BIT(19));
-   udelay(100);
-   setbits_le32(>ctrl, BIT(18));
-   setbits_le32(>ctrl, 7 << 4);
-
-   /* Note that Allwinner code doesn't fail in case of timeout */
-   tmo = timer_get_us() + 2000;
-   while ((readl(>status) & 0x80) == 0) {
-   if (timer_get_us() > tmo) {
-   printf("Warning: HDMI PHY init timeout!\n");
-   break;
-   }
-   }
-
-   setbits_le32(>ctrl, 0xf << 8);
-   setbits_le32(>ctrl, BIT(7));
-
-   writel(0x39dc5040, >pll);
-   writel(0x80084343, >clk);
-   udelay(1);
-   writel(1, >unk3);
-   setbits_le32(>pll, BIT(25));
-   udelay(10);
-   tmp = (readl(>status) & 0x1f800) >> 11;
-   setbits_le32(>pll, BIT(31) | BIT(30));
-   setbits_le32(>pll, tmp);
-   writel(0x01FF0F7F, >ctrl);
-   writel(0x80639000, >unk1);
-   writel(0x0F81C405, >unk2);
-
-   /* enable read access to HDMI controller */
-   writel(0x54524545, >read_en);
-   /* descramble register offsets */
-   writel(0x42494E47, >unscramble);
-}
-
-static void sunxi_dw_hdmi_phy_set(struct dw_hdmi *hdmi, uint clock, int 
phy_div)
-{
-   struct sunxi_hdmi_phy * const phy =
-   (struct sunxi_hdmi_phy *)(hdmi->ioaddr + HDMI_PHY_OFFS);
-   int div = sunxi_dw_hdmi_get_divider(clock);
-   u32 tmp;
-
-   /*
-* Unfortunately, we don't know much about those magic
-* numbers. They are taken from Allwinner BSP driver.
-*/
-   switch (div) {
-   case 1:
-   writel(0x30dc5fc0, >pll);
-   writel(0x800863C0 | (phy_div - 1), >clk);
-   mdelay(10);
-   writel(0x0001, >unk3);
-   setbits_le32(>pll, BIT(25));
-   mdelay(200);
-   tmp = (readl(>status) & 0x1f800) >> 11;
-   setbits_le32(>pll, BIT(31) | BIT(30));
-   if (tmp < 0x3d)
-   setbits_le32(>pll, tmp + 2);
-   else
-   setbits_le32(>pll, 0x3f);
-   mdelay(100);
-   writel(0x017F, >ctrl);
-   writel(0x8063b000, >unk1);
-   writel(0x0F8246B5, >unk2);
-   break;
-   case 2:
-   writel(0x39dc5040, >pll);
-   writel(0x80084380 | (phy_div - 1), >clk);
-   mdelay(10);
-   writel(0x0001, >unk3);
-   setbits_le32(>pll, BIT(25));
-   mdelay(100);
-   tmp = (readl(>status) & 0x1f800) >> 11;
-   

[PATCH v2 18/19] video: sunxi: Add DW HDMI PHY driver

2021-03-06 Thread Jernej Skrabec
This commit adds standalone driver for DW HDMI PHY. It deprecates code
which is included in sunxi dw-hdmi platform driver.

Signed-off-by: Jernej Skrabec 
---
 arch/arm/mach-sunxi/Kconfig |   1 +
 drivers/video/sunxi/Makefile|   2 +-
 drivers/video/sunxi/sunxi_dw_hdmi_phy.c | 423 
 drivers/video/sunxi/sunxi_dw_hdmi_phy.h |  24 ++
 4 files changed, 449 insertions(+), 1 deletion(-)
 create mode 100644 drivers/video/sunxi/sunxi_dw_hdmi_phy.c
 create mode 100644 drivers/video/sunxi/sunxi_dw_hdmi_phy.h

diff --git a/arch/arm/mach-sunxi/Kconfig b/arch/arm/mach-sunxi/Kconfig
index 34ef1f4b030f..5f2df7727357 100644
--- a/arch/arm/mach-sunxi/Kconfig
+++ b/arch/arm/mach-sunxi/Kconfig
@@ -973,6 +973,7 @@ config VIDEO_DE2
select CLK_SUN8I_DE2
select DM_VIDEO
select DISPLAY
+   select PHY
select VIDEO_DW_HDMI
imply VIDEO_DT_SIMPLEFB
default y
diff --git a/drivers/video/sunxi/Makefile b/drivers/video/sunxi/Makefile
index 4321673312bf..22ec17fb4fd2 100644
--- a/drivers/video/sunxi/Makefile
+++ b/drivers/video/sunxi/Makefile
@@ -4,4 +4,4 @@
 # Wolfgang Denk, DENX Software Engineering, w...@denx.de.
 
 obj-$(CONFIG_VIDEO_SUNXI) += sunxi_display.o simplefb_common.o lcdc.o 
tve_common.o ../videomodes.o
-obj-$(CONFIG_VIDEO_DE2) += sunxi_de2.o sunxi_dw_hdmi.o simplefb_common.o 
lcdc.o sunxi_lcd.o
+obj-$(CONFIG_VIDEO_DE2) += sunxi_de2.o sunxi_dw_hdmi.o sunxi_dw_hdmi_phy.o 
simplefb_common.o lcdc.o sunxi_lcd.o
diff --git a/drivers/video/sunxi/sunxi_dw_hdmi_phy.c 
b/drivers/video/sunxi/sunxi_dw_hdmi_phy.c
new file mode 100644
index ..bed5c2fdfe81
--- /dev/null
+++ b/drivers/video/sunxi/sunxi_dw_hdmi_phy.c
@@ -0,0 +1,423 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Allwinner DW HDMI PHY driver
+ *
+ * (C) Copyright 2021 Jernej Skrabec 
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include "sunxi_dw_hdmi_phy.h"
+
+#define SUN8I_HDMI_PHY_DBG_CTRL_PX_LOCKBIT(0)
+#define SUN8I_HDMI_PHY_DBG_CTRL_POL_MASK   GENMASK(15, 8)
+#define SUN8I_HDMI_PHY_DBG_CTRL_POL_NHSYNC BIT(8)
+#define SUN8I_HDMI_PHY_DBG_CTRL_POL_NVSYNC BIT(9)
+#define SUN8I_HDMI_PHY_DBG_CTRL_ADDR_MASK  GENMASK(23, 16)
+#define SUN8I_HDMI_PHY_DBG_CTRL_ADDR(addr) (addr << 16)
+
+#define SUN8I_HDMI_PHY_REXT_CTRL_REXT_EN   BIT(31)
+
+#define SUN8I_HDMI_PHY_READ_EN_MAGIC   0x54524545
+
+#define SUN8I_HDMI_PHY_UNSCRAMBLE_MAGIC0x42494E47
+
+#define SUN8I_HDMI_PHY_ANA_CFG1_REG_SWIBIT(31)
+#define SUN8I_HDMI_PHY_ANA_CFG1_REG_PWEND  BIT(30)
+#define SUN8I_HDMI_PHY_ANA_CFG1_REG_PWENC  BIT(29)
+#define SUN8I_HDMI_PHY_ANA_CFG1_REG_CALSW  BIT(28)
+#define SUN8I_HDMI_PHY_ANA_CFG1_REG_SVRCAL(x)  ((x) << 26)
+#define SUN8I_HDMI_PHY_ANA_CFG1_REG_SVBH(x)((x) << 24)
+#define SUN8I_HDMI_PHY_ANA_CFG1_AMP_OPTBIT(23)
+#define SUN8I_HDMI_PHY_ANA_CFG1_EMP_OPTBIT(22)
+#define SUN8I_HDMI_PHY_ANA_CFG1_AMPCK_OPT  BIT(21)
+#define SUN8I_HDMI_PHY_ANA_CFG1_EMPCK_OPT  BIT(20)
+#define SUN8I_HDMI_PHY_ANA_CFG1_ENRCAL BIT(19)
+#define SUN8I_HDMI_PHY_ANA_CFG1_ENCALOGBIT(18)
+#define SUN8I_HDMI_PHY_ANA_CFG1_REG_SCKTMDSBIT(17)
+#define SUN8I_HDMI_PHY_ANA_CFG1_TMDSCLK_EN BIT(16)
+#define SUN8I_HDMI_PHY_ANA_CFG1_TXEN_MASK  GENMASK(15, 12)
+#define SUN8I_HDMI_PHY_ANA_CFG1_TXEN_ALL   (0xf << 12)
+#define SUN8I_HDMI_PHY_ANA_CFG1_BIASEN_TMDSCLK BIT(11)
+#define SUN8I_HDMI_PHY_ANA_CFG1_BIASEN_TMDS2   BIT(10)
+#define SUN8I_HDMI_PHY_ANA_CFG1_BIASEN_TMDS1   BIT(9)
+#define SUN8I_HDMI_PHY_ANA_CFG1_BIASEN_TMDS0   BIT(8)
+#define SUN8I_HDMI_PHY_ANA_CFG1_ENP2S_TMDSCLK  BIT(7)
+#define SUN8I_HDMI_PHY_ANA_CFG1_ENP2S_TMDS2BIT(6)
+#define SUN8I_HDMI_PHY_ANA_CFG1_ENP2S_TMDS1BIT(5)
+#define SUN8I_HDMI_PHY_ANA_CFG1_ENP2S_TMDS0BIT(4)
+#define SUN8I_HDMI_PHY_ANA_CFG1_CKEN   BIT(3)
+#define SUN8I_HDMI_PHY_ANA_CFG1_LDOEN  BIT(2)
+#define SUN8I_HDMI_PHY_ANA_CFG1_ENVBS  BIT(1)
+#define SUN8I_HDMI_PHY_ANA_CFG1_ENBI   BIT(0)
+
+#define SUN8I_HDMI_PHY_ANA_CFG2_M_EN   BIT(31)
+#define SUN8I_HDMI_PHY_ANA_CFG2_PLLDBENBIT(30)
+#define SUN8I_HDMI_PHY_ANA_CFG2_SENBIT(29)
+#define SUN8I_HDMI_PHY_ANA_CFG2_REG_HPDPD  BIT(28)
+#define SUN8I_HDMI_PHY_ANA_CFG2_REG_HPDEN  BIT(27)
+#define SUN8I_HDMI_PHY_ANA_CFG2_REG_PLRCK  BIT(26)
+#define SUN8I_HDMI_PHY_ANA_CFG2_REG_PLR(x) ((x) << 23)
+#define SUN8I_HDMI_PHY_ANA_CFG2_REG_DENCK  BIT(22)
+#define SUN8I_HDMI_PHY_ANA_CFG2_REG_DENBIT(21)
+#define SUN8I_HDMI_PHY_ANA_CFG2_REG_CD(x)  ((x) << 19)
+#define SUN8I_HDMI_PHY_ANA_CFG2_REG_CKSS(x)((x) << 17)
+#define SUN8I_HDMI_PHY_ANA_CFG2_REG_BIGSWCKBIT(16)
+#define SUN8I_HDMI_PHY_ANA_CFG2_REG_BIGSW  BIT(15)
+#define SUN8I_HDMI_PHY_ANA_CFG2_REG_CSMPS(x)   ((x) << 13)
+#define 

[PATCH v2 17/19] video: dw-hdmi: modify phy init callback to include full timings

2021-03-06 Thread Jernej Skrabec
Currently PHY init callback has only pixel clock as a parameter, but
other timing parameters may be needed for custom PHYs. Modify callback
signature to include full timings.

Cc: Neil Armstrong 
Signed-off-by: Jernej Skrabec 
---
 drivers/video/dw_hdmi.c | 6 +++---
 drivers/video/meson/meson_dw_hdmi.c | 5 +++--
 drivers/video/sunxi/sunxi_dw_hdmi.c | 7 ---
 include/dw_hdmi.h   | 4 ++--
 4 files changed, 12 insertions(+), 10 deletions(-)

diff --git a/drivers/video/dw_hdmi.c b/drivers/video/dw_hdmi.c
index c4fbb1829446..8d71f713f99f 100644
--- a/drivers/video/dw_hdmi.c
+++ b/drivers/video/dw_hdmi.c
@@ -901,7 +901,7 @@ static const u8 pre_buf[] = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe9,
 };
 
-int dw_hdmi_phy_cfg(struct dw_hdmi *hdmi, uint mpixelclock)
+int dw_hdmi_phy_cfg(struct dw_hdmi *hdmi, const struct display_timing *edid)
 {
int i, ret;
 
@@ -912,7 +912,7 @@ int dw_hdmi_phy_cfg(struct dw_hdmi *hdmi, uint mpixelclock)
hdmi_phy_enable_tmds(hdmi, 0);
hdmi_phy_enable_power(hdmi, 0);
 
-   ret = hdmi_phy_configure(hdmi, mpixelclock);
+   ret = hdmi_phy_configure(hdmi, edid->pixelclock.typ);
if (ret) {
debug("hdmi phy config failure %d\n", ret);
return ret;
@@ -988,7 +988,7 @@ int dw_hdmi_enable(struct dw_hdmi *hdmi, const struct 
display_timing *edid)
 
hdmi_av_composer(hdmi, edid);
 
-   ret = hdmi->phy_set(hdmi, edid->pixelclock.typ);
+   ret = hdmi->phy_set(hdmi, edid);
if (ret)
return ret;
 
diff --git a/drivers/video/meson/meson_dw_hdmi.c 
b/drivers/video/meson/meson_dw_hdmi.c
index e5f281320534..7558814b3491 100644
--- a/drivers/video/meson/meson_dw_hdmi.c
+++ b/drivers/video/meson/meson_dw_hdmi.c
@@ -292,7 +292,8 @@ static void meson_dw_hdmi_phy_setup_mode(struct 
meson_dw_hdmi *priv,
}
 }
 
-static int meson_dw_hdmi_phy_init(struct dw_hdmi *hdmi, uint pixel_clock)
+static int meson_dw_hdmi_phy_init(struct dw_hdmi *hdmi,
+ const struct display_timing *edid)
 {
struct meson_dw_hdmi *priv = container_of(hdmi, struct meson_dw_hdmi,
  hdmi);
@@ -322,7 +323,7 @@ static int meson_dw_hdmi_phy_init(struct dw_hdmi *hdmi, 
uint pixel_clock)
dw_hdmi_top_write(hdmi, HDMITX_TOP_TMDS_CLK_PTTN_CNTL, 0x2);
 
/* Setup PHY parameters */
-   meson_dw_hdmi_phy_setup_mode(priv, pixel_clock);
+   meson_dw_hdmi_phy_setup_mode(priv, edid->pixelclock.typ);
 
/* Setup PHY */
dw_hdmi_hhi_update_bits(priv, HHI_HDMI_PHY_CNTL1,
diff --git a/drivers/video/sunxi/sunxi_dw_hdmi.c 
b/drivers/video/sunxi/sunxi_dw_hdmi.c
index 0744954fa15f..483d57293155 100644
--- a/drivers/video/sunxi/sunxi_dw_hdmi.c
+++ b/drivers/video/sunxi/sunxi_dw_hdmi.c
@@ -266,12 +266,13 @@ static void sunxi_dw_hdmi_lcdc_init(int mux, const struct 
display_timing *edid,
lcdc_enable(lcdc, bpp);
 }
 
-static int sunxi_dw_hdmi_phy_cfg(struct dw_hdmi *hdmi, uint mpixelclock)
+static int sunxi_dw_hdmi_phy_cfg(struct dw_hdmi *hdmi,
+const struct display_timing *edid)
 {
int phy_div;
 
-   sunxi_dw_hdmi_pll_set(mpixelclock / 1000, _div);
-   sunxi_dw_hdmi_phy_set(hdmi, mpixelclock, phy_div);
+   sunxi_dw_hdmi_pll_set(edid->pixelclock.typ / 1000, _div);
+   sunxi_dw_hdmi_phy_set(hdmi, edid->pixelclock.typ, phy_div);
 
return 0;
 }
diff --git a/include/dw_hdmi.h b/include/dw_hdmi.h
index 8acae3839fb3..46b87916b8bb 100644
--- a/include/dw_hdmi.h
+++ b/include/dw_hdmi.h
@@ -544,12 +544,12 @@ struct dw_hdmi {
struct hdmi_data_info hdmi_data;
struct udevice *ddc_bus;
 
-   int (*phy_set)(struct dw_hdmi *hdmi, uint mpixelclock);
+   int (*phy_set)(struct dw_hdmi *hdmi, const struct display_timing *edid);
void (*write_reg)(struct dw_hdmi *hdmi, u8 val, int offset);
u8 (*read_reg)(struct dw_hdmi *hdmi, int offset);
 };
 
-int dw_hdmi_phy_cfg(struct dw_hdmi *hdmi, uint mpixelclock);
+int dw_hdmi_phy_cfg(struct dw_hdmi *hdmi, const struct display_timing *edid);
 int dw_hdmi_phy_wait_for_hpd(struct dw_hdmi *hdmi);
 void dw_hdmi_phy_init(struct dw_hdmi *hdmi);
 
-- 
2.30.1



[PATCH v2 16/19] video: sunxi: de2: switch clock setup to DM model

2021-03-06 Thread Jernej Skrabec
Now that proper DM clock and reset driver exists for Display Engine 2
and 3, remove all clock and reset related code and use appropriate
framework instead.

Signed-off-by: Jernej Skrabec 
---
 arch/arm/mach-sunxi/Kconfig |  1 +
 drivers/video/sunxi/sunxi_de2.c | 67 +++--
 2 files changed, 23 insertions(+), 45 deletions(-)

diff --git a/arch/arm/mach-sunxi/Kconfig b/arch/arm/mach-sunxi/Kconfig
index 9149196b223e..34ef1f4b030f 100644
--- a/arch/arm/mach-sunxi/Kconfig
+++ b/arch/arm/mach-sunxi/Kconfig
@@ -970,6 +970,7 @@ config SUNXI_DE2
 config VIDEO_DE2
bool "Display Engine 2 video driver"
depends on SUNXI_DE2
+   select CLK_SUN8I_DE2
select DM_VIDEO
select DISPLAY
select VIDEO_DW_HDMI
diff --git a/drivers/video/sunxi/sunxi_de2.c b/drivers/video/sunxi/sunxi_de2.c
index f6c8ca075aba..cee9b46b1259 100644
--- a/drivers/video/sunxi/sunxi_de2.c
+++ b/drivers/video/sunxi/sunxi_de2.c
@@ -6,6 +6,7 @@
  */
 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -14,10 +15,10 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
-#include 
 #include 
 #include 
 #include "simplefb_common.h"
@@ -36,40 +37,10 @@ struct sunxi_de2_data {
const char *disp_drv_name;
 };
 
-static void sunxi_de2_composer_init(void)
-{
-   struct sunxi_ccm_reg * const ccm =
-   (struct sunxi_ccm_reg *)SUNXI_CCM_BASE;
-
-#ifdef CONFIG_MACH_SUN50I
-   u32 reg_value;
-
-   /* set SRAM for video use (A64 only) */
-   reg_value = readl(SUNXI_SRAMC_BASE + 0x04);
-   reg_value &= ~(0x01 << 24);
-   writel(reg_value, SUNXI_SRAMC_BASE + 0x04);
-#endif
-
-   clock_set_pll10(43200);
-
-   /* Set DE parent to pll10 */
-   clrsetbits_le32(>de_clk_cfg, CCM_DE2_CTRL_PLL_MASK,
-   CCM_DE2_CTRL_PLL10);
-
-   /* Set ahb gating to pass */
-   setbits_le32(>ahb_reset1_cfg, 1 << AHB_RESET_OFFSET_DE);
-   setbits_le32(>ahb_gate1, 1 << AHB_GATE_OFFSET_DE);
-
-   /* Clock on */
-   setbits_le32(>de_clk_cfg, CCM_DE2_CTRL_GATE);
-}
-
-static void sunxi_de2_mode_set(ulong de_mux_base, int mux,
+static void sunxi_de2_mode_set(ulong de_mux_base,
   const struct display_timing *mode,
   int bpp, ulong address, bool is_composite)
 {
-   struct de_clk * const de_clk_regs =
-   (struct de_clk *)(SUNXI_DE2_BASE);
struct de_glb * const de_glb_regs =
(struct de_glb *)(de_mux_base +
  SUNXI_DE2_MUX_GLB_REGS);
@@ -87,17 +58,6 @@ static void sunxi_de2_mode_set(ulong de_mux_base, int mux,
int channel;
u32 format;
 
-   /* enable clock */
-#ifdef CONFIG_MACH_SUN8I_H3
-   setbits_le32(_clk_regs->rst_cfg, (mux == 0) ? 1 : 4);
-#else
-   setbits_le32(_clk_regs->rst_cfg, BIT(mux));
-#endif
-   setbits_le32(_clk_regs->gate_cfg, BIT(mux));
-   setbits_le32(_clk_regs->bus_cfg, BIT(mux));
-
-   clrbits_le32(_clk_regs->sel_cfg, 1);
-
writel(SUNXI_DE2_MUX_GLB_CTL_EN, _glb_regs->ctl);
writel(0, _glb_regs->status);
writel(1, _glb_regs->dbuff);
@@ -189,6 +149,8 @@ static int sunxi_de2_init(struct udevice *dev, ulong fbbase,
struct video_priv *uc_priv = dev_get_uclass_priv(dev);
struct display_timing timing;
struct display_plat *disp_uc_plat;
+   struct reset_ctl_bulk resets;
+   struct clk_bulk clocks;
int ret;
 
disp_uc_plat = dev_get_uclass_plat(disp);
@@ -206,8 +168,23 @@ static int sunxi_de2_init(struct udevice *dev, ulong 
fbbase,
return ret;
}
 
-   sunxi_de2_composer_init();
-   sunxi_de2_mode_set((ulong)dev_read_addr(dev), mux, ,
+   ret = reset_get_bulk(dev, );
+   if (ret)
+   return ret;
+
+   ret = clk_get_bulk(dev, );
+   if (ret)
+   return ret;
+
+   ret = clk_enable_bulk();
+   if (ret)
+   return ret;
+
+   ret = reset_deassert_bulk();
+   if (ret)
+   return ret;
+
+   sunxi_de2_mode_set((ulong)dev_read_addr(dev), ,
   1 << l2bpp, fbbase, is_composite);
 
ret = display_enable(disp, 1 << l2bpp, );
-- 
2.30.1



[PATCH v2 15/19] clk: sunxi: add DE2 clock driver

2021-03-06 Thread Jernej Skrabec
Video driver currently manages clocks and resets by directly writing to
registers. This is already a bit messy because each SoC has some
specifics. It's much better to implement proper clock and reset driver
which takes information from device tree file.

Note that this driver is not perfect yet. It still sets PLL and parent
by hand. Sunxi clock framework still doesn't know how to set parents or
rates. However, this is already big step in right direction.

Cc: Lukasz Majewski 
Signed-off-by: Jernej Skrabec 
---
 drivers/clk/sunxi/Kconfig   |  5 +++
 drivers/clk/sunxi/Makefile  |  1 +
 drivers/clk/sunxi/clk_de2.c | 85 +
 3 files changed, 91 insertions(+)
 create mode 100644 drivers/clk/sunxi/clk_de2.c

diff --git a/drivers/clk/sunxi/Kconfig b/drivers/clk/sunxi/Kconfig
index bf084fa7a84a..6c96affb1f87 100644
--- a/drivers/clk/sunxi/Kconfig
+++ b/drivers/clk/sunxi/Kconfig
@@ -44,6 +44,11 @@ config CLK_SUN8I_A83T
  This enables common clock driver support for platforms based
  on Allwinner A83T SoC.
 
+config CLK_SUN8I_DE2
+   bool "Clock driver for Allwinner Display Engine 2 and 3"
+   help
+ This enables common clock driver support for Display Engine 2 and 3.
+
 config CLK_SUN8I_R40
bool "Clock driver for Allwinner R40"
default MACH_SUN8I_R40
diff --git a/drivers/clk/sunxi/Makefile b/drivers/clk/sunxi/Makefile
index 0dfc0593fb1c..620ff96ac6f5 100644
--- a/drivers/clk/sunxi/Makefile
+++ b/drivers/clk/sunxi/Makefile
@@ -11,6 +11,7 @@ obj-$(CONFIG_CLK_SUN5I_A10S) += clk_a10s.o
 obj-$(CONFIG_CLK_SUN6I_A31) += clk_a31.o
 obj-$(CONFIG_CLK_SUN8I_A23) += clk_a23.o
 obj-$(CONFIG_CLK_SUN8I_A83T) += clk_a83t.o
+obj-$(CONFIG_CLK_SUN8I_DE2) += clk_de2.o
 obj-$(CONFIG_CLK_SUN8I_R40) += clk_r40.o
 obj-$(CONFIG_CLK_SUN8I_V3S) += clk_v3s.o
 obj-$(CONFIG_CLK_SUN9I_A80) += clk_a80.o
diff --git a/drivers/clk/sunxi/clk_de2.c b/drivers/clk/sunxi/clk_de2.c
new file mode 100644
index ..b8c45404c1b6
--- /dev/null
+++ b/drivers/clk/sunxi/clk_de2.c
@@ -0,0 +1,85 @@
+// SPDX-License-Identifier: (GPL-2.0+ OR MIT)
+/*
+ * Copyright (C) 2021 Jernej Skrabec 
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+static struct ccu_clk_gate de2_gates[] = {
+   [CLK_MIXER0]= GATE(0x00, BIT(0)),
+   [CLK_MIXER1]= GATE(0x00, BIT(1)),
+   [CLK_WB]= GATE(0x00, BIT(2)),
+
+   [CLK_BUS_MIXER0]= GATE(0x04, BIT(0)),
+   [CLK_BUS_MIXER1]= GATE(0x04, BIT(1)),
+   [CLK_BUS_WB]= GATE(0x04, BIT(2)),
+};
+
+static struct ccu_reset de2_resets[] = {
+   [RST_MIXER0]= RESET(0x08, BIT(0)),
+   [RST_MIXER1]= RESET(0x08, BIT(1)),
+   [RST_WB]= RESET(0x08, BIT(2)),
+};
+
+static const struct ccu_desc de2_ccu_desc = {
+   .gates = de2_gates,
+   .resets = de2_resets,
+};
+
+static int de2_clk_probe(struct udevice *dev)
+{
+   struct sunxi_ccm_reg * const ccm =
+   (struct sunxi_ccm_reg *)SUNXI_CCM_BASE;
+   u32 val;
+
+   if (device_is_compatible(dev_get_parent(dev),
+"allwinner,sun50i-a64-de2")) {
+   /* set SRAM for video use */
+   val = readl(SUNXI_SRAMC_BASE + 0x04);
+   val &= ~(0x01 << 24);
+   writel(val, SUNXI_SRAMC_BASE + 0x04);
+   }
+
+   /* clock driver doesn't know how to set rate or parent yet */
+   clock_set_pll10(43200);
+
+   /* Set DE parent to pll10 */
+   clrsetbits_le32(>de_clk_cfg, CCM_DE2_CTRL_PLL_MASK,
+   CCM_DE2_CTRL_PLL10);
+
+   return sunxi_clk_probe(dev);
+}
+
+static int de2_clk_bind(struct udevice *dev)
+{
+   return sunxi_reset_bind(dev, ARRAY_SIZE(de2_resets));
+}
+
+static const struct udevice_id de2_ccu_ids[] = {
+   { .compatible = "allwinner,sun8i-h3-de2-clk",
+ .data = (ulong)_ccu_desc },
+   { .compatible = "allwinner,sun50i-a64-de2-clk",
+ .data = (ulong)_ccu_desc },
+   { .compatible = "allwinner,sun50i-h5-de2-clk",
+ .data = (ulong)_ccu_desc },
+   { }
+};
+
+U_BOOT_DRIVER(clk_sun8i_de2) = {
+   .name   = "sun8i_de2_ccu",
+   .id = UCLASS_CLK,
+   .of_match   = de2_ccu_ids,
+   .priv_auto  = sizeof(struct ccu_priv),
+   .ops= _clk_ops,
+   .probe  = de2_clk_probe,
+   .bind   = de2_clk_bind,
+};
-- 
2.30.1



[PATCH v2 14/19] clk: sunxi: Add DE2 and HDMI clocks to H3 and A64

2021-03-06 Thread Jernej Skrabec
These clocks and resets are needed for video drivers.

Cc: Lukasz Majewski 
Signed-off-by: Jernej Skrabec 
---
 drivers/clk/sunxi/clk_a64.c | 12 
 drivers/clk/sunxi/clk_h3.c  | 12 
 2 files changed, 24 insertions(+)

diff --git a/drivers/clk/sunxi/clk_a64.c b/drivers/clk/sunxi/clk_a64.c
index 0553ffa4399a..28131240652f 100644
--- a/drivers/clk/sunxi/clk_a64.c
+++ b/drivers/clk/sunxi/clk_a64.c
@@ -26,6 +26,9 @@ static const struct ccu_clk_gate a64_gates[] = {
[CLK_BUS_OHCI0] = GATE(0x060, BIT(28)),
[CLK_BUS_OHCI1] = GATE(0x060, BIT(29)),
 
+   [CLK_BUS_HDMI]  = GATE(0x064, BIT(11)),
+   [CLK_BUS_DE]= GATE(0x064, BIT(12)),
+
[CLK_BUS_UART0] = GATE(0x06c, BIT(16)),
[CLK_BUS_UART1] = GATE(0x06c, BIT(17)),
[CLK_BUS_UART2] = GATE(0x06c, BIT(18)),
@@ -41,6 +44,11 @@ static const struct ccu_clk_gate a64_gates[] = {
[CLK_USB_HSIC_12M]  = GATE(0x0cc, BIT(11)),
[CLK_USB_OHCI0] = GATE(0x0cc, BIT(16)),
[CLK_USB_OHCI1] = GATE(0x0cc, BIT(17)),
+
+   [CLK_DE]= GATE(0x104, BIT(31)),
+
+   [CLK_HDMI]  = GATE(0x150, BIT(31)),
+   [CLK_HDMI_DDC]  = GATE(0x154, BIT(31)),
 };
 
 static const struct ccu_reset a64_resets[] = {
@@ -60,6 +68,10 @@ static const struct ccu_reset a64_resets[] = {
[RST_BUS_OHCI0] = RESET(0x2c0, BIT(28)),
[RST_BUS_OHCI1] = RESET(0x2c0, BIT(29)),
 
+   [RST_BUS_HDMI0] = RESET(0x2c4, BIT(10)),
+   [RST_BUS_HDMI1] = RESET(0x2c4, BIT(11)),
+   [RST_BUS_DE]= RESET(0x2c4, BIT(12)),
+
[RST_BUS_UART0] = RESET(0x2d8, BIT(16)),
[RST_BUS_UART1] = RESET(0x2d8, BIT(17)),
[RST_BUS_UART2] = RESET(0x2d8, BIT(18)),
diff --git a/drivers/clk/sunxi/clk_h3.c b/drivers/clk/sunxi/clk_h3.c
index f81633b92d5a..806a35b37435 100644
--- a/drivers/clk/sunxi/clk_h3.c
+++ b/drivers/clk/sunxi/clk_h3.c
@@ -30,6 +30,9 @@ static struct ccu_clk_gate h3_gates[] = {
[CLK_BUS_OHCI2] = GATE(0x060, BIT(30)),
[CLK_BUS_OHCI3] = GATE(0x060, BIT(31)),
 
+   [CLK_BUS_HDMI]  = GATE(0x064, BIT(11)),
+   [CLK_BUS_DE]= GATE(0x064, BIT(12)),
+
[CLK_BUS_UART0] = GATE(0x06c, BIT(16)),
[CLK_BUS_UART1] = GATE(0x06c, BIT(17)),
[CLK_BUS_UART2] = GATE(0x06c, BIT(18)),
@@ -48,6 +51,11 @@ static struct ccu_clk_gate h3_gates[] = {
[CLK_USB_OHCI1] = GATE(0x0cc, BIT(17)),
[CLK_USB_OHCI2] = GATE(0x0cc, BIT(18)),
[CLK_USB_OHCI3] = GATE(0x0cc, BIT(19)),
+
+   [CLK_DE]= GATE(0x104, BIT(31)),
+
+   [CLK_HDMI]  = GATE(0x150, BIT(31)),
+   [CLK_HDMI_DDC]  = GATE(0x154, BIT(31)),
 };
 
 static struct ccu_reset h3_resets[] = {
@@ -72,6 +80,10 @@ static struct ccu_reset h3_resets[] = {
[RST_BUS_OHCI2] = RESET(0x2c0, BIT(30)),
[RST_BUS_OHCI3] = RESET(0x2c0, BIT(31)),
 
+   [RST_BUS_HDMI0] = RESET(0x2c4, BIT(10)),
+   [RST_BUS_HDMI1] = RESET(0x2c4, BIT(11)),
+   [RST_BUS_DE]= RESET(0x2c4, BIT(12)),
+
[RST_BUS_EPHY]  = RESET(0x2c8, BIT(2)),
 
[RST_BUS_UART0] = RESET(0x2d8, BIT(16)),
-- 
2.30.1



[PATCH v2 13/19] video: sunxi: de2: read address from DT node

2021-03-06 Thread Jernej Skrabec
Currently DE2 uses hardcoded address based on SoC for which U-Boot is
built. Read it from DT instead so there is no need to specify it when
support for new SoC is added.

Signed-off-by: Jernej Skrabec 
---
 drivers/video/sunxi/sunxi_de2.c | 8 
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/video/sunxi/sunxi_de2.c b/drivers/video/sunxi/sunxi_de2.c
index 81576e45e9ef..f6c8ca075aba 100644
--- a/drivers/video/sunxi/sunxi_de2.c
+++ b/drivers/video/sunxi/sunxi_de2.c
@@ -64,11 +64,10 @@ static void sunxi_de2_composer_init(void)
setbits_le32(>de_clk_cfg, CCM_DE2_CTRL_GATE);
 }
 
-static void sunxi_de2_mode_set(int mux, const struct display_timing *mode,
+static void sunxi_de2_mode_set(ulong de_mux_base, int mux,
+  const struct display_timing *mode,
   int bpp, ulong address, bool is_composite)
 {
-   ulong de_mux_base = (mux == 0) ?
-   SUNXI_DE2_MUX0_BASE : SUNXI_DE2_MUX1_BASE;
struct de_clk * const de_clk_regs =
(struct de_clk *)(SUNXI_DE2_BASE);
struct de_glb * const de_glb_regs =
@@ -208,7 +207,8 @@ static int sunxi_de2_init(struct udevice *dev, ulong fbbase,
}
 
sunxi_de2_composer_init();
-   sunxi_de2_mode_set(mux, , 1 << l2bpp, fbbase, is_composite);
+   sunxi_de2_mode_set((ulong)dev_read_addr(dev), mux, ,
+  1 << l2bpp, fbbase, is_composite);
 
ret = display_enable(disp, 1 << l2bpp, );
if (ret) {
-- 
2.30.1



[PATCH v2 12/19] video: sunxi: de2: switch to DT probing

2021-03-06 Thread Jernej Skrabec
Currently DE2 driver is probed via driver info. Switch probing to device
tree compatible string method.

Display is now searched via driver name which has same limitation as
previous method. This can be improved only when all drivers in chain are
probed via device tree compatible strings.

Signed-off-by: Jernej Skrabec 
---
 drivers/video/sunxi/sunxi_de2.c | 88 +++--
 1 file changed, 52 insertions(+), 36 deletions(-)

diff --git a/drivers/video/sunxi/sunxi_de2.c b/drivers/video/sunxi/sunxi_de2.c
index e02d359cd259..81576e45e9ef 100644
--- a/drivers/video/sunxi/sunxi_de2.c
+++ b/drivers/video/sunxi/sunxi_de2.c
@@ -31,6 +31,11 @@ enum {
LCD_MAX_LOG2_BPP= VIDEO_BPP32,
 };
 
+struct sunxi_de2_data {
+   int id;
+   const char *disp_drv_name;
+};
+
 static void sunxi_de2_composer_init(void)
 {
struct sunxi_ccm_reg * const ccm =
@@ -228,51 +233,34 @@ static int sunxi_de2_init(struct udevice *dev, ulong 
fbbase,
 
 static int sunxi_de2_probe(struct udevice *dev)
 {
+   const struct sunxi_de2_data *data =
+   (const struct sunxi_de2_data *)dev_get_driver_data(dev);
struct video_uc_plat *plat = dev_get_uclass_plat(dev);
struct udevice *disp;
-   int ret;
+   int ret, index = 0;
 
/* Before relocation we don't need to do anything */
if (!(gd->flags & GD_FLG_RELOC))
return 0;
 
-   ret = uclass_get_device_by_driver(UCLASS_DISPLAY,
- DM_DRIVER_GET(sunxi_lcd), );
-   if (!ret) {
-   int mux;
+   while (!(ret = uclass_get_device(UCLASS_DISPLAY, index++, ))) {
+   if (strcmp(disp->driver->name, data->disp_drv_name))
+   continue;
 
-   mux = 0;
+   ret = sunxi_de2_init(dev, plat->base, VIDEO_BPP32, disp,
+data->id, false);
+   if (ret)
+   return ret;
 
-   ret = sunxi_de2_init(dev, plat->base, VIDEO_BPP32, disp, mux,
-false);
-   if (!ret) {
-   video_set_flush_dcache(dev, 1);
-   return 0;
-   }
-   }
-
-   debug("%s: lcd display not found (ret=%d)\n", __func__, ret);
-
-   ret = uclass_get_device_by_driver(UCLASS_DISPLAY,
- DM_DRIVER_GET(sunxi_dw_hdmi), );
-   if (!ret) {
-   int mux;
-   if (IS_ENABLED(CONFIG_MACH_SUNXI_H3_H5))
-   mux = 0;
-   else
-   mux = 1;
+   video_set_flush_dcache(dev, 1);
 
-   ret = sunxi_de2_init(dev, plat->base, VIDEO_BPP32, disp, mux,
-false);
-   if (!ret) {
-   video_set_flush_dcache(dev, 1);
-   return 0;
-   }
+   return 0;
}
 
-   debug("%s: hdmi display not found (ret=%d)\n", __func__, ret);
+   debug("%s: %s not found (ret=%d)\n", __func__,
+ data->disp_drv_name, ret);
 
-   return -ENODEV;
+   return ret;
 }
 
 static int sunxi_de2_bind(struct udevice *dev)
@@ -285,22 +273,50 @@ static int sunxi_de2_bind(struct udevice *dev)
return 0;
 }
 
+const struct sunxi_de2_data h3_mixer_0 = {
+   .id = 0,
+   .disp_drv_name = "sunxi_dw_hdmi",
+};
+
+const struct sunxi_de2_data a64_mixer_0 = {
+   .id = 0,
+   .disp_drv_name = "sunxi_lcd",
+};
+
+const struct sunxi_de2_data a64_mixer_1 = {
+   .id = 1,
+   .disp_drv_name = "sunxi_dw_hdmi",
+};
+
+static const struct udevice_id sunxi_de2_ids[] = {
+   {
+   .compatible = "allwinner,sun8i-h3-de2-mixer-0",
+   .data = (ulong)_mixer_0,
+   },
+   {
+   .compatible = "allwinner,sun50i-a64-de2-mixer-0",
+   .data = (ulong)_mixer_0,
+   },
+   {
+   .compatible = "allwinner,sun50i-a64-de2-mixer-1",
+   .data = (ulong)_mixer_1,
+   },
+   { }
+};
+
 static const struct video_ops sunxi_de2_ops = {
 };
 
 U_BOOT_DRIVER(sunxi_de2) = {
.name   = "sunxi_de2",
.id = UCLASS_VIDEO,
+   .of_match = sunxi_de2_ids,
.ops= _de2_ops,
.bind   = sunxi_de2_bind,
.probe  = sunxi_de2_probe,
.flags  = DM_FLAG_PRE_RELOC,
 };
 
-U_BOOT_DRVINFO(sunxi_de2) = {
-   .name = "sunxi_de2"
-};
-
 /*
  * Simplefb support.
  */
-- 
2.30.1



[PATCH v2 11/19] video: sunxi: dw-hdmi: read address from DT node

2021-03-06 Thread Jernej Skrabec
Currently HDMI controller MMIO address is hardcoded. Change that so
address is read from DT node. That will make adding support for new
variants a bit easier.

Signed-off-by: Jernej Skrabec 
---
 drivers/video/sunxi/sunxi_dw_hdmi.c | 38 ++---
 1 file changed, 24 insertions(+), 14 deletions(-)

diff --git a/drivers/video/sunxi/sunxi_dw_hdmi.c 
b/drivers/video/sunxi/sunxi_dw_hdmi.c
index 6f77b2a43b40..0744954fa15f 100644
--- a/drivers/video/sunxi/sunxi_dw_hdmi.c
+++ b/drivers/video/sunxi/sunxi_dw_hdmi.c
@@ -57,10 +57,10 @@ static int sunxi_dw_hdmi_get_divider(uint clock)
return 1;
 }
 
-static void sunxi_dw_hdmi_phy_init(void)
+static void sunxi_dw_hdmi_phy_init(struct dw_hdmi *hdmi)
 {
struct sunxi_hdmi_phy * const phy =
-   (struct sunxi_hdmi_phy *)(SUNXI_HDMI_BASE + HDMI_PHY_OFFS);
+   (struct sunxi_hdmi_phy *)(hdmi->ioaddr + HDMI_PHY_OFFS);
unsigned long tmo;
u32 tmp;
 
@@ -114,10 +114,10 @@ static void sunxi_dw_hdmi_phy_init(void)
writel(0x42494E47, >unscramble);
 }
 
-static void sunxi_dw_hdmi_phy_set(uint clock, int phy_div)
+static void sunxi_dw_hdmi_phy_set(struct dw_hdmi *hdmi, uint clock, int 
phy_div)
 {
struct sunxi_hdmi_phy * const phy =
-   (struct sunxi_hdmi_phy *)(SUNXI_HDMI_BASE + HDMI_PHY_OFFS);
+   (struct sunxi_hdmi_phy *)(hdmi->ioaddr + HDMI_PHY_OFFS);
int div = sunxi_dw_hdmi_get_divider(clock);
u32 tmp;
 
@@ -271,7 +271,7 @@ static int sunxi_dw_hdmi_phy_cfg(struct dw_hdmi *hdmi, uint 
mpixelclock)
int phy_div;
 
sunxi_dw_hdmi_pll_set(mpixelclock / 1000, _div);
-   sunxi_dw_hdmi_phy_set(mpixelclock, phy_div);
+   sunxi_dw_hdmi_phy_set(hdmi, mpixelclock, phy_div);
 
return 0;
 }
@@ -292,9 +292,9 @@ static bool sunxi_dw_hdmi_mode_valid(struct udevice *dev,
 static int sunxi_dw_hdmi_enable(struct udevice *dev, int panel_bpp,
const struct display_timing *edid)
 {
-   struct sunxi_hdmi_phy * const phy =
-   (struct sunxi_hdmi_phy *)(SUNXI_HDMI_BASE + HDMI_PHY_OFFS);
struct sunxi_dw_hdmi_priv *priv = dev_get_priv(dev);
+   struct sunxi_hdmi_phy * const phy =
+   (struct sunxi_hdmi_phy *)(priv->hdmi.ioaddr + HDMI_PHY_OFFS);
int ret;
 
ret = dw_hdmi_enable(>hdmi, edid);
@@ -316,12 +316,26 @@ static int sunxi_dw_hdmi_enable(struct udevice *dev, int 
panel_bpp,
 * again or othwerwise BSP driver won't work. Dummy read is
 * needed or otherwise last write doesn't get written correctly.
 */
-   (void)readb(SUNXI_HDMI_BASE);
+   (void)readb(priv->hdmi.ioaddr);
writel(0, >unscramble);
 
return 0;
 }
 
+static int sunxi_dw_hdmi_of_to_plat(struct udevice *dev)
+{
+   struct sunxi_dw_hdmi_priv *priv = dev_get_priv(dev);
+   struct dw_hdmi *hdmi = >hdmi;
+
+   hdmi->ioaddr = (ulong)dev_read_addr(dev);
+   hdmi->i2c_clk_high = 0xd8;
+   hdmi->i2c_clk_low = 0xfe;
+   hdmi->reg_io_width = 1;
+   hdmi->phy_set = sunxi_dw_hdmi_phy_cfg;
+
+   return 0;
+}
+
 static int sunxi_dw_hdmi_probe(struct udevice *dev)
 {
struct display_plat *uc_plat = dev_get_uclass_plat(dev);
@@ -346,13 +360,8 @@ static int sunxi_dw_hdmi_probe(struct udevice *dev)
/* Clock on */
setbits_le32(>hdmi_clk_cfg, CCM_HDMI_CTRL_GATE);
 
-   sunxi_dw_hdmi_phy_init();
+   sunxi_dw_hdmi_phy_init(>hdmi);
 
-   priv->hdmi.ioaddr = SUNXI_HDMI_BASE;
-   priv->hdmi.i2c_clk_high = 0xd8;
-   priv->hdmi.i2c_clk_low = 0xfe;
-   priv->hdmi.reg_io_width = 1;
-   priv->hdmi.phy_set = sunxi_dw_hdmi_phy_cfg;
priv->mux = uc_plat->source_id;
 
ret = dw_hdmi_phy_wait_for_hpd(>hdmi);
@@ -382,6 +391,7 @@ U_BOOT_DRIVER(sunxi_dw_hdmi) = {
.id = UCLASS_DISPLAY,
.of_match = sunxi_dw_hdmi_ids,
.ops= _dw_hdmi_ops,
+   .of_to_plat = sunxi_dw_hdmi_of_to_plat,
.probe  = sunxi_dw_hdmi_probe,
.priv_auto  = sizeof(struct sunxi_dw_hdmi_priv),
 };
-- 
2.30.1



[PATCH v2 10/19] video: sunxi: dw-hdmi: probe driver by compatible

2021-03-06 Thread Jernej Skrabec
Currently sunxi dw-hdmi driver is probed unconditionally, even if there
is no such device.

Switch driver to probing via compatible string. This brings many
benefits - driver can read DT node and allows driver to be always
enabled.

Signed-off-by: Jernej Skrabec 
---
 drivers/video/sunxi/sunxi_dw_hdmi.c | 10 ++
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/drivers/video/sunxi/sunxi_dw_hdmi.c 
b/drivers/video/sunxi/sunxi_dw_hdmi.c
index 6d2bc206fc2c..6f77b2a43b40 100644
--- a/drivers/video/sunxi/sunxi_dw_hdmi.c
+++ b/drivers/video/sunxi/sunxi_dw_hdmi.c
@@ -372,14 +372,16 @@ static const struct dm_display_ops sunxi_dw_hdmi_ops = {
.mode_valid = sunxi_dw_hdmi_mode_valid,
 };
 
+static const struct udevice_id sunxi_dw_hdmi_ids[] = {
+   { .compatible = "allwinner,sun8i-a83t-dw-hdmi" },
+   { }
+};
+
 U_BOOT_DRIVER(sunxi_dw_hdmi) = {
.name   = "sunxi_dw_hdmi",
.id = UCLASS_DISPLAY,
+   .of_match = sunxi_dw_hdmi_ids,
.ops= _dw_hdmi_ops,
.probe  = sunxi_dw_hdmi_probe,
.priv_auto  = sizeof(struct sunxi_dw_hdmi_priv),
 };
-
-U_BOOT_DRVINFO(sunxi_dw_hdmi) = {
-   .name = "sunxi_dw_hdmi"
-};
-- 
2.30.1



[PATCH v2 09/19] video: sunxi: de2: switch to public uclass functions

2021-03-06 Thread Jernej Skrabec
Currently DE2 driver uses functions which are defined in internal
headers. They are not meant to be used outside of uclass framework.
Switch DE2 driver to public ones. This has additional benefit that
device_probe doesn't need to be called manually.

Signed-off-by: Jernej Skrabec 
---
 drivers/video/sunxi/sunxi_de2.c | 29 ++---
 1 file changed, 10 insertions(+), 19 deletions(-)

diff --git a/drivers/video/sunxi/sunxi_de2.c b/drivers/video/sunxi/sunxi_de2.c
index 6b836a011944..e02d359cd259 100644
--- a/drivers/video/sunxi/sunxi_de2.c
+++ b/drivers/video/sunxi/sunxi_de2.c
@@ -19,8 +19,6 @@
 #include 
 #include 
 #include 
-#include 
-#include 
 #include 
 #include "simplefb_common.h"
 
@@ -198,13 +196,6 @@ static int sunxi_de2_init(struct udevice *dev, ulong 
fbbase,
 
disp_uc_plat->source_id = mux;
 
-   ret = device_probe(disp);
-   if (ret) {
-   debug("%s: device '%s' display won't probe (ret=%d)\n",
- __func__, dev->name, ret);
-   return ret;
-   }
-
ret = display_read_timing(disp, );
if (ret) {
debug("%s: Failed to read timings\n", __func__);
@@ -245,8 +236,8 @@ static int sunxi_de2_probe(struct udevice *dev)
if (!(gd->flags & GD_FLG_RELOC))
return 0;
 
-   ret = uclass_find_device_by_name(UCLASS_DISPLAY,
-"sunxi_lcd", );
+   ret = uclass_get_device_by_driver(UCLASS_DISPLAY,
+ DM_DRIVER_GET(sunxi_lcd), );
if (!ret) {
int mux;
 
@@ -262,8 +253,8 @@ static int sunxi_de2_probe(struct udevice *dev)
 
debug("%s: lcd display not found (ret=%d)\n", __func__, ret);
 
-   ret = uclass_find_device_by_name(UCLASS_DISPLAY,
-"sunxi_dw_hdmi", );
+   ret = uclass_get_device_by_driver(UCLASS_DISPLAY,
+ DM_DRIVER_GET(sunxi_dw_hdmi), );
if (!ret) {
int mux;
if (IS_ENABLED(CONFIG_MACH_SUNXI_H3_H5))
@@ -332,8 +323,8 @@ int sunxi_simplefb_setup(void *blob)
mux = 1;
 
/* Skip simplefb setting if DE2 / HDMI is not present */
-   ret = uclass_find_device_by_name(UCLASS_VIDEO,
-"sunxi_de2", );
+   ret = uclass_get_device_by_driver(UCLASS_VIDEO,
+ DM_DRIVER_GET(sunxi_de2), );
if (ret) {
debug("DE2 not present\n");
return 0;
@@ -342,8 +333,8 @@ int sunxi_simplefb_setup(void *blob)
return 0;
}
 
-   ret = uclass_find_device_by_name(UCLASS_DISPLAY,
-"sunxi_dw_hdmi", );
+   ret = uclass_get_device_by_driver(UCLASS_DISPLAY,
+ DM_DRIVER_GET(sunxi_dw_hdmi), );
if (ret) {
debug("HDMI not present\n");
} else if (device_active(hdmi)) {
@@ -355,8 +346,8 @@ int sunxi_simplefb_setup(void *blob)
debug("HDMI present but not probed\n");
}
 
-   ret = uclass_find_device_by_name(UCLASS_DISPLAY,
-"sunxi_lcd", );
+   ret = uclass_get_device_by_driver(UCLASS_DISPLAY,
+ DM_DRIVER_GET(sunxi_lcd), );
if (ret)
debug("LCD not present\n");
else if (device_active(lcd))
-- 
2.30.1



  1   2   >