Re: [PATCH v5 02/20] net: introduce alternative implementation as net-lwip/

2024-07-25 Thread Maxim Uvarov
32f712a7c 100644
> --- a/drivers/net/Kconfig
> +++ b/drivers/net/Kconfig
> @@ -48,6 +48,7 @@ config DM_DSA
> bool "Enable Driver Model for DSA switches"
> depends on DM_MDIO
> depends on PHY_FIXED
> +   depends on !NET_LWIP
> help
>   Enable driver model for DSA switches
>
> diff --git a/drivers/net/phy/Kconfig b/drivers/net/phy/Kconfig
> index 73064b2af68..75986162914 100644
> --- a/drivers/net/phy/Kconfig
> +++ b/drivers/net/phy/Kconfig
> @@ -11,7 +11,7 @@ config MV88E6352_SWITCH
>
>  menuconfig PHYLIB
> bool "Ethernet PHY (physical media interface) support"
> -   depends on NET
> +   depends on NET || NET_LWIP
> help
>   Enable Ethernet PHY (physical media interface) support.
>
> diff --git a/drivers/usb/gadget/Kconfig b/drivers/usb/gadget/Kconfig
> index 4621a6fd5e6..03fe3bca197 100644
> --- a/drivers/usb/gadget/Kconfig
> +++ b/drivers/usb/gadget/Kconfig
> @@ -224,7 +224,7 @@ endif # USB_GADGET_DOWNLOAD
>
>  config USB_ETHER
> bool "USB Ethernet Gadget"
> -   depends on NET
> +   depends on NET || NET_LWIP
> default y if ARCH_SUNXI && USB_MUSB_GADGET
> help
>   Creates an Ethernet network device through a USB peripheral
> diff --git a/net/Kconfig b/net/Kconfig
> index 5dff6336293..952690d677d 100644
> --- a/net/Kconfig
> +++ b/net/Kconfig
> @@ -2,11 +2,6 @@
>  # Network configuration
>  #
>
> -menuconfig NET
> -   bool "Networking support"
> -   default y
> -   imply NETDEVICES
> -
>  if NET
>
>  config ARP_TIMEOUT
> @@ -26,15 +21,6 @@ config PROT_UDP
>   Enable a generic udp framework that allows defining a custom
>   handler for udp protocol.
>
> -config BOOTDEV_ETH
> -   bool "Enable bootdev for ethernet"
> -   depends on BOOTSTD
> -   default y
> -   help
> - Provide a bootdev for ethernet so that is it possible to boot
> - an operationg system over the network, using the PXE (Preboot
> - Execution Environment) protocol.
> -
>  config BOOTP_SEND_HOSTNAME
> bool "Send hostname to DNS server"
> help
> @@ -255,6 +241,19 @@ config IPV6
>
>  endif   # if NET
>
> +source "net/lwip/Kconfig"
> +
> +if NET || NET_LWIP
> +
> +config BOOTDEV_ETH
> +   bool "Enable bootdev for ethernet"
> +   depends on BOOTSTD
> +   default y
> +   help
> + Provide a bootdev for ethernet so that is it possible to boot
> + an operating system over the network, using the PXE (Preboot
> + Execution Environment) protocol.
> +
>  config SYS_RX_ETH_BUFFER
> int "Number of receive packet buffers"
> default 4
> @@ -263,3 +262,5 @@ config SYS_RX_ETH_BUFFER
>   controllers it is recommended to set this value to 8 or even higher,
>   since all buffers can be full shortly after enabling the interface 
> on
>   high Ethernet traffic.
> +
> +endif   # if NET || NET_LWIP
> diff --git a/net/Makefile b/net/Makefile
> index 64ab7ec740a..70eec8caf0d 100644
> --- a/net/Makefile
> +++ b/net/Makefile
> @@ -5,6 +5,8 @@
>
>  #ccflags-y += -DDEBUG
>
> +ifeq ($(CONFIG_NET),y)
> +
>  obj-$(CONFIG_NET)  += arp.o
>  obj-$(CONFIG_CMD_BOOTP) += bootp.o
>  obj-$(CONFIG_CMD_CDP)  += cdp.o
> @@ -38,3 +40,5 @@ obj-$(CONFIG_CMD_WGET) += wget.o
>  # sprintf(buf, index ? "foo%d" : "foo", index)
>  # and this is intentional usage.
>  CFLAGS_eth_common.o += -Wno-format-extra-args
> +
> +endif
> diff --git a/net/lwip/Kconfig b/net/lwip/Kconfig
> new file mode 100644
> index 000..0a6bcb41369
> --- /dev/null
> +++ b/net/lwip/Kconfig
> @@ -0,0 +1,36 @@
> +#
> +# Network configuration (with lwIP stack)
> +#
> +
> +config LWIP_DEBUG
> +   bool "Enable debug traces in the lwIP library"
> +
> +config LWIP_ASSERT
> +   bool "Enable assertions in the lwIP library"
> +
> +config PROT_DHCP_LWIP
> +   bool "DHCP support in lwIP"
> +   depends on PROT_UDP_LWIP
> +   help
> + Enable support for the DHCP protocol in lwIP.
> +
> +config PROT_DNS_LWIP
> +   bool
> +   depends on PROT_UDP_LWIP
> +
> +config PROT_RAW_LWIP
> +   bool
> +
> +config PROT_TCP_LWIP
> +   bool

Hello Jerome,

Not very critical, but it will be good to align options names.  I
think CONFIG_NET_LWIP_ is a good prefix.
It will be easier to grep configuration from .config.

BR,
Maxim.


> +
> +config PROT_TCP_SACK_LWIP
> +   bool "TCP SACK support"
> +   depends on PROT_TCP_LWIP
> +   default y
> +   help
> + TCP protocol with selective acknowledgements. Improves
> + file transfer speed in wget.
> +
> +config PROT_UDP_LWIP
> +   bool
> --
> 2.40.1
>


-- 
Best regards,
Maxim Uvarov


Re: [PATCH v4 00/14] Introduce the lwIP network stack

2024-06-22 Thread Maxim Uvarov
пт, 21 июн. 2024 г. в 21:42, Fabio Estevam :
>
> Hi Tim and Jerome,
>
> On Fri, Jun 21, 2024 at 1:08 PM Tim Harvey  wrote:
>
> > I tried your to-upstream/v5-wip branch
> > (042bea36eb9731079a3d7afffe3774d79e06ac5d) and it behaves the same. Do
> > you have something else to try/test?
>
> Yes, when I tested older versions from Maxim I could never get lwIP to
> work with i.MX.
>
> Jerome,
>
> Please try to run the lwIP series on any i.MX board, if possible.
>
> Thanks

Packet not for us means that incoming packet DST MAC does not match to
the MAC address inside lwip. I.e. to MAC address set into lwip when
lwip_init was done. Original U-Boot network stack does not compare
MACs but lwip does. There is something specific on this board, in
general lwip with debug should print out
MAC used during initialization. This MAC should match to the MAC from
the incoming packet.

-- 
Best regards,
Maxim Uvarov


Re: [PATCH v2 08/14] net-lwip: add wget command

2024-06-06 Thread Maxim Uvarov
чт, 6 июн. 2024 г. в 12:56, Jerome Forissier :
>
>
>
> On 5/28/24 15:39, Maxim Uvarov wrote:
> > пт, 24 мая 2024 г. в 19:22, Jerome Forissier :
> >>
> >> Add support for the wget command with NET_LWIP.
> >>
> >> About the small change in cmd/efidebug.c: when the wget command based
> >> on the lwIP stack is used the wget command has a built-in URL
> >> validation function since it needs to parse it anyways (in parse_url()).
> >> Therefore wget_validate_uri() doesn't exist. So, guard the call in
> >> efidebug.c with CONFIG_CMD_WGET.
> >>
> >> Based on code initially developed by Maxim U.
> >>
> >> Signed-off-by: Jerome Forissier 
> >> Co-developed-by: Maxim Uvarov 
> >> Cc: Maxim Uvarov 
> >> ---
> >>  cmd/Kconfig|   7 ++
> >>  cmd/Makefile   |   5 +-
> >>  cmd/efidebug.c |   8 +-
> >>  cmd/net-common.c   | 112 
> >>  cmd/net-lwip.c |  12 +++
> >>  cmd/net.c  | 115 -
> >>  include/net-lwip.h |  51 +
> >>  net-lwip/Makefile  |   1 +
> >>  net-lwip/wget.c| 180 +
> >>  9 files changed, 372 insertions(+), 119 deletions(-)
> >>  create mode 100644 cmd/net-common.c
> >>  create mode 100644 net-lwip/wget.c
> >>
> >> diff --git a/cmd/Kconfig b/cmd/Kconfig
> >> index 6ef0b52cd34..d9a86540be6 100644
> >> --- a/cmd/Kconfig
> >> +++ b/cmd/Kconfig
> >> @@ -2117,6 +2117,13 @@ config CMD_TFTPBOOT
> >> help
> >>   tftpboot - load file via network using TFTP protocol
> >>
> >> +config CMD_WGET
> >> +   bool "wget"
> >> +   select PROT_TCP_LWIP
> >> +   help
> >> + wget is a simple command to download kernel, or other files,
> >> + from a http server over TCP.
> >> +
> >>  endif
> >>
> >>  endif
> >> diff --git a/cmd/Makefile b/cmd/Makefile
> >> index 535b6838ca5..e90f2f68211 100644
> >> --- a/cmd/Makefile
> >> +++ b/cmd/Makefile
> >> @@ -129,8 +129,11 @@ obj-$(CONFIG_CMD_MUX) += mux.o
> >>  obj-$(CONFIG_CMD_NAND) += nand.o
> >>  obj-$(CONFIG_CMD_NET) += net.o
> >>  obj-$(CONFIG_CMD_NET_LWIP) += net-lwip.o
> >> +obj-$(filter y,$(CONFIG_CMD_NET) $(CONFIG_CMD_NET_LWIP)) += net-common.o
> >>  ifdef CONFIG_CMD_NET_LWIP
> >> -CFLAGS_net-lwip.o := -I$(srctree)/lib/lwip/lwip/src/include 
> >> -I$(srctree)/lib/lwip/u-boot
> >> +lwip-includes := -I$(srctree)/lib/lwip/lwip/src/include 
> >> -I$(srctree)/lib/lwip/u-boot
> >> +CFLAGS_net-lwip.o := $(lwip-includes)
> >> +CFLAGS_net-common.o := $(lwip-includes)
> >>  endif
> >>  obj-$(CONFIG_ENV_SUPPORT) += nvedit.o
> >>  obj-$(CONFIG_CMD_NVEDIT_EFI) += nvedit_efi.o
> >> diff --git a/cmd/efidebug.c b/cmd/efidebug.c
> >> index c2c525f2351..d80e91ecadd 100644
> >> --- a/cmd/efidebug.c
> >> +++ b/cmd/efidebug.c
> >> @@ -741,9 +741,11 @@ static int efi_boot_add_uri(int argc, char *const 
> >> argv[], u16 *var_name16,
> >> if (!label)
> >> return CMD_RET_FAILURE;
> >>
> >> -   if (!wget_validate_uri(argv[3])) {
> >> -   printf("ERROR: invalid URI\n");
> >> -   return CMD_RET_FAILURE;
> >> +   if (IS_ENABLED(CONFIG_CMD_WGET)) {
> >> +   if (!wget_validate_uri(argv[3])) {
> >> +   printf("ERROR: invalid URI\n");
> >> +   return CMD_RET_FAILURE;
> >> +   }
> >> }
> >>
> >> efi_create_indexed_name(var_name16, var_name16_size, "Boot", id);
> >> diff --git a/cmd/net-common.c b/cmd/net-common.c
> >> new file mode 100644
> >> index 000..b5dfd2c8866
> >> --- /dev/null
> >> +++ b/cmd/net-common.c
> >> @@ -0,0 +1,112 @@
> >> +// SPDX-License-Identifier: GPL-2.0+
> >> +/*
> >> + * (C) Copyright 2000
> >> + * Wolfgang Denk, DENX Software Engineering, w...@denx.de.
> >> + */
> >> +
> >> +#include 
> >> +#include 
> >> +#include 
> >> +#ifdef CONFIG_NET
> >> +#include 
> >> +#elif defined CONFIG_NET_LWIP
> >> +#include 
> >> +#else
> >> +#error Either NET or NET_LWIP must be enable

Re: [PATCH v2 07/14] net-lwip: add dns command

2024-06-06 Thread Maxim Uvarov
чт, 6 июн. 2024 г. в 09:29, Ilias Apalodimas :
>
> Hi Jerome,
>
> [...]
>
> > +
> > +static ulong start;
> > +static ip_addr_t host_ipaddr;
> > +static bool done;
> > +
> > +static void do_dns_tmr(void *arg)
> > +{
> > + dns_tmr();
> > +}
> > +
> > +static void dns_cb(const char *name, const ip_addr_t *ipaddr, void *arg)
> > +{
> > + char *var = (char *)arg;
>
> const char *
>
>
> > + char *ipstr = ip4addr_ntoa(ipaddr);
> > +
> > + done = true;
> > +
> > + if (!ipaddr) {
> > + printf("DNS: host not found\n");
> > + host_ipaddr.addr = 0;
> > + return;
> > + }
> > +
> > + if (var)
> > + env_set(var, ipstr);
> > +
> > + printf("%s\n", ipstr);
> > +}
> > +
> > +int do_dns(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
> > +{
> > + bool has_server = false;
> > + ip_addr_t ipaddr;
> > + ip_addr_t ns;
> > + char *nsenv;
> > + char *name;
> > + char *var;
> > + int ret;
> > +
> > + if (argc == 1 || argc > 3)
> > + return CMD_RET_USAGE;
> > +
> > + if (argc >= 2)
> > + name = argv[1];
> > +
> > + if (argc == 3)
> > + var = argv[2];
> > +
> > + dns_init();
> > +
> > + nsenv = env_get("dnsip");
> > + if (nsenv && ipaddr_aton(nsenv, &ns)) {
> > + dns_setserver(0, &ns);
> > + has_server = true;
> > + }
> > +
> > + nsenv = env_get("dnsip2");
> > + if (nsenv && ipaddr_aton(nsenv, &ns)) {
> > + dns_setserver(1, &ns);
> > + has_server = true;
> > + }
> > +
> > + if (!has_server) {
> > + log_err("No valid name server (dnsip/dnsip2)\n");
> > + return CMD_RET_FAILURE;
> > + }
> > +
> > + done = false;
> > +
> > + ret = dns_gethostbyname(name, &ipaddr, dns_cb, var);
> > +
> > + if (ret == ERR_OK) {
> > + dns_cb(name, &ipaddr, var);
> > + } else if (ret == ERR_INPROGRESS) {
> > + start = get_timer(0);
> > + sys_timeout(DNS_RESEND_MS, do_dns_tmr, NULL);
> > + do {
> > + eth_rx();
> > + if (done)
> > + break;
> > + sys_check_timeouts();
> > + if (ctrlc()) {
> > + printf("\nAbort\n");
> > +     break;
> > + }
> > + } while (get_timer(start) < DNS_TIMEOUT_MS);
> > + sys_untimeout(do_dns_tmr, NULL);
> > + }
>
> Looking at the lwip code there are other ret values than just ERR_OK,
> ERR_INPROGRESS. Should we have an 'else' handling the rest?
>
+1
And check the return code of eth_rx(), that is int function
and current code for some reason skips this check.

BR,
Maxim.

> > +
> > + if (done && host_ipaddr.addr != 0)
> > + return CMD_RET_SUCCESS;
> > +
> > + return CMD_RET_FAILURE;
> > +}
> > +
> > --
> > 2.40.1
> >
>
> Thanks
> /Ilias



-- 
Best regards,
Maxim Uvarov


Re: [PATCH v2 12/14] test/py: net: add _lwip variants of dhcp, ping and tftpboot tests

2024-05-30 Thread Maxim Uvarov
чт, 30 мая 2024 г. в 17:11, Jerome Forissier :
>
>
>
> On 5/28/24 11:53, Maxim Uvarov wrote:
> > пт, 24 мая 2024 г. в 19:22, Jerome Forissier :
> >>
> >> WHen NET_LWIP is enabled, the dhcp/ping/tftpboot commands are enabled
> >> via CMD_DHCP_LWIP, CMD_PING_LWIP and CMD_TFTPBOOT_LWIP, respectively;
> >> therefore the config annotations in the Python test scripts need to be
> >> cmd_dhcp_lwip, cmd_ping_lwip and cmd_tftpboot_lwip.
> >>
> >> The console output of the tftpboot command with lwIP is slightly
> >> different from the non-lwIP implementation. This is taken care of in
> >> test_net_tftpboot().
> >>
> >> Signed-off-by: Jerome Forissier 
> >> ---
> >>  test/py/tests/test_net.py | 21 +
> >>  1 file changed, 17 insertions(+), 4 deletions(-)
> >>
> >> diff --git a/test/py/tests/test_net.py b/test/py/tests/test_net.py
> >> index 038a473b239..ba30780903f 100644
> >> --- a/test/py/tests/test_net.py
> >> +++ b/test/py/tests/test_net.py
> >> @@ -127,6 +127,10 @@ def test_net_dhcp(u_boot_console):
> >>  global net_set_up
> >>  net_set_up = True
> >>
> >> +@pytest.mark.buildconfigspec('cmd_dhcp_lwip')
> >> +def test_net_dhcp_lwip(u_boot_console):
> >> +test_net_dhcp(u_boot_console)
> >> +
> >>  @pytest.mark.buildconfigspec('cmd_dhcp')
> >>  @pytest.mark.buildconfigspec('cmd_mii')
> >>  def test_net_dhcp_abort(u_boot_console):
> >> @@ -230,6 +234,10 @@ def test_net_ping(u_boot_console):
> >>  output = u_boot_console.run_command('ping $serverip')
> >>  assert 'is alive' in output
> >>
> >> +@pytest.mark.buildconfigspec('cmd_ping_lwip')
> >> +def test_net_ping_lwip(u_boot_console):
> >> +test_net_ping(u_boot_console)
> >> +
> >>  @pytest.mark.buildconfigspec('IPV6_ROUTER_DISCOVERY')
> >>  def test_net_network_discovery(u_boot_console):
> >>  """Test the network discovery feature of IPv6.
> >> @@ -255,7 +263,7 @@ def test_net_network_discovery(u_boot_console):
> >>  assert ':::::::' not in output
> >>
> >>  @pytest.mark.buildconfigspec('cmd_net')
> >> -def test_net_tftpboot(u_boot_console):
> >> +def test_net_tftpboot(u_boot_console, lwip = False):
> >>  """Test the tftpboot command.
> >>
> >>  A file is downloaded from the TFTP server, its size and optionally its
> >> @@ -279,10 +287,11 @@ def test_net_tftpboot(u_boot_console):
> >>  output = u_boot_console.run_command('tftpboot %s' % (fn))
> >>  else:
> >>  output = u_boot_console.run_command('tftpboot %x %s' % (addr, fn))
> >> -expected_text = 'Bytes transferred = '
> >>  sz = f.get('size', None)
> >> -if sz:
> >> -expected_text += '%d' % sz
> >> +if lwip:
> >> +expected_text = f'{sz} bytes transferred'
> >
> > Why not change patch 5 to print with capital character to match this 
> > pattern?
>
> I thought unifying the messages of wget and tftp would be a good idea. With
> this series, both commands print hash signs followed by:
> "xxx bytes transferred (yy MB/s)".
>
> Would a patch updating the tftp message when the legacy stack is used be
> acceptable?
>
> --
> Jerome
>

I think yes.

BR,
Maxim.

> > BR,
> > Maxim.
> >
> >> +else:
> >> +expected_text = f'Bytes transferred = {sz}'
> >>  assert expected_text in output
> >>
> >>  expected_crc = f.get('crc32', None)
> >> @@ -295,6 +304,10 @@ def test_net_tftpboot(u_boot_console):
> >>  output = u_boot_console.run_command('crc32 $fileaddr $filesize')
> >>  assert expected_crc in output
> >>
> >> +@pytest.mark.buildconfigspec("cmd_net_lwip")
> >> +def test_net_tftpboot_lwip(u_boot_console):
> >> +test_net_tftpboot(u_boot_console, True)
> >> +
> >>  @pytest.mark.buildconfigspec('cmd_nfs')
> >>  def test_net_nfs(u_boot_console):
> >>  """Test the nfs command.
> >> --
> >> 2.40.1
> >>
> >
> >



-- 
Best regards,
Maxim Uvarov


Re: [PATCH v2 08/14] net-lwip: add wget command

2024-05-28 Thread Maxim Uvarov
пт, 24 мая 2024 г. в 19:22, Jerome Forissier :
>
> Add support for the wget command with NET_LWIP.
>
> About the small change in cmd/efidebug.c: when the wget command based
> on the lwIP stack is used the wget command has a built-in URL
> validation function since it needs to parse it anyways (in parse_url()).
> Therefore wget_validate_uri() doesn't exist. So, guard the call in
> efidebug.c with CONFIG_CMD_WGET.
>
> Based on code initially developed by Maxim U.
>
> Signed-off-by: Jerome Forissier 
> Co-developed-by: Maxim Uvarov 
> Cc: Maxim Uvarov 
> ---
>  cmd/Kconfig|   7 ++
>  cmd/Makefile   |   5 +-
>  cmd/efidebug.c |   8 +-
>  cmd/net-common.c   | 112 
>  cmd/net-lwip.c |  12 +++
>  cmd/net.c  | 115 -
>  include/net-lwip.h |  51 +
>  net-lwip/Makefile  |   1 +
>  net-lwip/wget.c| 180 +
>  9 files changed, 372 insertions(+), 119 deletions(-)
>  create mode 100644 cmd/net-common.c
>  create mode 100644 net-lwip/wget.c
>
> diff --git a/cmd/Kconfig b/cmd/Kconfig
> index 6ef0b52cd34..d9a86540be6 100644
> --- a/cmd/Kconfig
> +++ b/cmd/Kconfig
> @@ -2117,6 +2117,13 @@ config CMD_TFTPBOOT
> help
>   tftpboot - load file via network using TFTP protocol
>
> +config CMD_WGET
> +   bool "wget"
> +   select PROT_TCP_LWIP
> +   help
> + wget is a simple command to download kernel, or other files,
> + from a http server over TCP.
> +
>  endif
>
>  endif
> diff --git a/cmd/Makefile b/cmd/Makefile
> index 535b6838ca5..e90f2f68211 100644
> --- a/cmd/Makefile
> +++ b/cmd/Makefile
> @@ -129,8 +129,11 @@ obj-$(CONFIG_CMD_MUX) += mux.o
>  obj-$(CONFIG_CMD_NAND) += nand.o
>  obj-$(CONFIG_CMD_NET) += net.o
>  obj-$(CONFIG_CMD_NET_LWIP) += net-lwip.o
> +obj-$(filter y,$(CONFIG_CMD_NET) $(CONFIG_CMD_NET_LWIP)) += net-common.o
>  ifdef CONFIG_CMD_NET_LWIP
> -CFLAGS_net-lwip.o := -I$(srctree)/lib/lwip/lwip/src/include 
> -I$(srctree)/lib/lwip/u-boot
> +lwip-includes := -I$(srctree)/lib/lwip/lwip/src/include 
> -I$(srctree)/lib/lwip/u-boot
> +CFLAGS_net-lwip.o := $(lwip-includes)
> +CFLAGS_net-common.o := $(lwip-includes)
>  endif
>  obj-$(CONFIG_ENV_SUPPORT) += nvedit.o
>  obj-$(CONFIG_CMD_NVEDIT_EFI) += nvedit_efi.o
> diff --git a/cmd/efidebug.c b/cmd/efidebug.c
> index c2c525f2351..d80e91ecadd 100644
> --- a/cmd/efidebug.c
> +++ b/cmd/efidebug.c
> @@ -741,9 +741,11 @@ static int efi_boot_add_uri(int argc, char *const 
> argv[], u16 *var_name16,
> if (!label)
> return CMD_RET_FAILURE;
>
> -   if (!wget_validate_uri(argv[3])) {
> -   printf("ERROR: invalid URI\n");
> -   return CMD_RET_FAILURE;
> +   if (IS_ENABLED(CONFIG_CMD_WGET)) {
> +   if (!wget_validate_uri(argv[3])) {
> +   printf("ERROR: invalid URI\n");
> +   return CMD_RET_FAILURE;
> +   }
> }
>
> efi_create_indexed_name(var_name16, var_name16_size, "Boot", id);
> diff --git a/cmd/net-common.c b/cmd/net-common.c
> new file mode 100644
> index 000..b5dfd2c8866
> --- /dev/null
> +++ b/cmd/net-common.c
> @@ -0,0 +1,112 @@
> +// SPDX-License-Identifier: GPL-2.0+
> +/*
> + * (C) Copyright 2000
> + * Wolfgang Denk, DENX Software Engineering, w...@denx.de.
> + */
> +
> +#include 
> +#include 
> +#include 
> +#ifdef CONFIG_NET
> +#include 
> +#elif defined CONFIG_NET_LWIP
> +#include 
> +#else
> +#error Either NET or NET_LWIP must be enabled
> +#endif
> +#include 
> +#include 
> +
> +static int do_net_list(struct cmd_tbl *cmdtp, int flag, int argc, char 
> *const argv[])
> +{
> +   const struct udevice *current = eth_get_dev();
> +   unsigned char env_enetaddr[ARP_HLEN];
> +   const struct udevice *dev;
> +   struct uclass *uc;
> +
> +   uclass_id_foreach_dev(UCLASS_ETH, dev, uc) {
> +   eth_env_get_enetaddr_by_index("eth", dev_seq(dev), 
> env_enetaddr);
> +   printf("eth%d : %s %pM %s\n", dev_seq(dev), dev->name, 
> env_enetaddr,
> +  current == dev ? "active" : "");
> +   }
> +   return CMD_RET_SUCCESS;
> +}
> +
> +static int do_net_stats(struct cmd_tbl *cmdtp, int flag, int argc, char 
> *const argv[])
> +{
> +   int nstats, err, i, off;
> +   struct udevice *dev;
> +   u64 *values;
> +   u8 *strings;
> +
> +   if (argc < 2)
> +

Re: [PATCH v2 12/14] test/py: net: add _lwip variants of dhcp, ping and tftpboot tests

2024-05-28 Thread Maxim Uvarov
пт, 24 мая 2024 г. в 19:22, Jerome Forissier :
>
> WHen NET_LWIP is enabled, the dhcp/ping/tftpboot commands are enabled
> via CMD_DHCP_LWIP, CMD_PING_LWIP and CMD_TFTPBOOT_LWIP, respectively;
> therefore the config annotations in the Python test scripts need to be
> cmd_dhcp_lwip, cmd_ping_lwip and cmd_tftpboot_lwip.
>
> The console output of the tftpboot command with lwIP is slightly
> different from the non-lwIP implementation. This is taken care of in
> test_net_tftpboot().
>
> Signed-off-by: Jerome Forissier 
> ---
>  test/py/tests/test_net.py | 21 +
>  1 file changed, 17 insertions(+), 4 deletions(-)
>
> diff --git a/test/py/tests/test_net.py b/test/py/tests/test_net.py
> index 038a473b239..ba30780903f 100644
> --- a/test/py/tests/test_net.py
> +++ b/test/py/tests/test_net.py
> @@ -127,6 +127,10 @@ def test_net_dhcp(u_boot_console):
>  global net_set_up
>  net_set_up = True
>
> +@pytest.mark.buildconfigspec('cmd_dhcp_lwip')
> +def test_net_dhcp_lwip(u_boot_console):
> +test_net_dhcp(u_boot_console)
> +
>  @pytest.mark.buildconfigspec('cmd_dhcp')
>  @pytest.mark.buildconfigspec('cmd_mii')
>  def test_net_dhcp_abort(u_boot_console):
> @@ -230,6 +234,10 @@ def test_net_ping(u_boot_console):
>  output = u_boot_console.run_command('ping $serverip')
>  assert 'is alive' in output
>
> +@pytest.mark.buildconfigspec('cmd_ping_lwip')
> +def test_net_ping_lwip(u_boot_console):
> +test_net_ping(u_boot_console)
> +
>  @pytest.mark.buildconfigspec('IPV6_ROUTER_DISCOVERY')
>  def test_net_network_discovery(u_boot_console):
>  """Test the network discovery feature of IPv6.
> @@ -255,7 +263,7 @@ def test_net_network_discovery(u_boot_console):
>  assert ':::::::' not in output
>
>  @pytest.mark.buildconfigspec('cmd_net')
> -def test_net_tftpboot(u_boot_console):
> +def test_net_tftpboot(u_boot_console, lwip = False):
>  """Test the tftpboot command.
>
>  A file is downloaded from the TFTP server, its size and optionally its
> @@ -279,10 +287,11 @@ def test_net_tftpboot(u_boot_console):
>  output = u_boot_console.run_command('tftpboot %s' % (fn))
>  else:
>  output = u_boot_console.run_command('tftpboot %x %s' % (addr, fn))
> -expected_text = 'Bytes transferred = '
>  sz = f.get('size', None)
> -if sz:
> -expected_text += '%d' % sz
> +if lwip:
> +expected_text = f'{sz} bytes transferred'

Why not change patch 5 to print with capital character to match this pattern?

BR,
Maxim.

> +else:
> +expected_text = f'Bytes transferred = {sz}'
>  assert expected_text in output
>
>  expected_crc = f.get('crc32', None)
> @@ -295,6 +304,10 @@ def test_net_tftpboot(u_boot_console):
>      output = u_boot_console.run_command('crc32 $fileaddr $filesize')
>  assert expected_crc in output
>
> +@pytest.mark.buildconfigspec("cmd_net_lwip")
> +def test_net_tftpboot_lwip(u_boot_console):
> +test_net_tftpboot(u_boot_console, True)
> +
>  @pytest.mark.buildconfigspec('cmd_nfs')
>  def test_net_nfs(u_boot_console):
>  """Test the nfs command.
> --
> 2.40.1
>


-- 
Best regards,
Maxim Uvarov


Re: [PATCH 10/15] test: dm: dsa, eth: disable tests when CONFIG_NET_LWIP=y

2024-05-24 Thread Maxim Uvarov
чт, 23 мая 2024 г. в 16:40, Peter Robinson :
>
> On Wed, 22 May 2024 at 19:08, Ilias Apalodimas
>  wrote:
> >
> > Hi Jerome,
> >
> > On Wed, 22 May 2024 at 19:04, Jerome Forissier
> >  wrote:
> > >
> > > Some sandbox tests make strong assumptions on how the network stack is
> > > implemented. For example, the ping tests assume that ARP resolution
> > > occurs upon sending out the ICMP packet. This is not always the case
> > > with the lwIP stack which can cache ARP information.
> > > Therefore, disable these tests when CONFIG_NET_LWIP is enabled.
> >
> > Is the ARP Caching the only issue?
> > U-Boot isn't supposed to use the network stack that much, so it might
> > be a better idea to disable arp-caching in LWIP (assuming it's
> > doable). We might even get a few size of bytes back
>
> You end up hitting an arp cache a lot because of references to say
> DNS, IP GW or server end point for downloading, so while at first it
> doesn't appear you'd need it you also don't want to do ARP for every
> packet sent.
>
> Peter
>
Caching has to be in the network stack. At least for 5-10 entries.
There are 2 ways:
or change the test or add flush/delete arp entries. Flushing and
printing ARPs are useful
for debugging and can go to the special Kconfig option.

BR,
Maxim.

> > Cheers
> > /Ilias
> > >
> > > Signed-off-by: Jerome Forissier 
> > > ---
> > >  test/dm/dsa.c | 2 ++
> > >  test/dm/eth.c | 4 
> > >  2 files changed, 6 insertions(+)
> > >
> > > diff --git a/test/dm/dsa.c b/test/dm/dsa.c
> > > index c857106eaf..147e2a4afe 100644
> > > --- a/test/dm/dsa.c
> > > +++ b/test/dm/dsa.c
> > > @@ -59,6 +59,7 @@ static int dm_test_dsa_probe(struct unit_test_state 
> > > *uts)
> > >
> > >  DM_TEST(dm_test_dsa_probe, UT_TESTF_SCAN_FDT);
> > >
> > > +#if !defined(CONFIG_NET_LWIP)
> > >  /* This test sends ping requests with the local address through each DSA 
> > > port
> > >   * via the sandbox DSA master Eth.
> > >   */
> > > @@ -80,3 +81,4 @@ static int dm_test_dsa(struct unit_test_state *uts)
> > >  }
> > >
> > >  DM_TEST(dm_test_dsa, UT_TESTF_SCAN_FDT);
> > > +#endif /* !defined(CONFIG_NET_LWIP) */
> > > diff --git a/test/dm/eth.c b/test/dm/eth.c
> > > index bb3dcc6b95..cf97b1c1ab 100644
> > > --- a/test/dm/eth.c
> > > +++ b/test/dm/eth.c
> > > @@ -170,6 +170,7 @@ static int dm_test_ip6_make_lladdr(struct 
> > > unit_test_state *uts)
> > >  DM_TEST(dm_test_ip6_make_lladdr, UT_TESTF_SCAN_FDT);
> > >  #endif
> > >
> > > +#if !defined(CONFIG_NET_LWIP)
> > >  static int dm_test_eth(struct unit_test_state *uts)
> > >  {
> > > net_ping_ip = string_to_ip("1.1.2.2");
> > > @@ -298,6 +299,7 @@ static int dm_test_eth_act(struct unit_test_state 
> > > *uts)
> > > return 0;
> > >  }
> > >  DM_TEST(dm_test_eth_act, UT_TESTF_SCAN_FDT);
> > > +#endif /* !CONFIG_NET_LWIP */
> > >
> > >  /* Ensure that all addresses are loaded properly */
> > >  static int dm_test_ethaddr(struct unit_test_state *uts)
> > > @@ -332,6 +334,7 @@ static int dm_test_ethaddr(struct unit_test_state 
> > > *uts)
> > >  }
> > >  DM_TEST(dm_test_ethaddr, UT_TESTF_SCAN_FDT);
> > >
> > > +#if !defined(CONFIG_NET_LWIP)
> > >  /* The asserts include a return on fail; cleanup in the caller */
> > >  static int _dm_test_eth_rotate1(struct unit_test_state *uts)
> > >  {
> > > @@ -616,6 +619,7 @@ static int dm_test_eth_async_ping_reply(struct 
> > > unit_test_state *uts)
> > >  }
> > >
> > >  DM_TEST(dm_test_eth_async_ping_reply, UT_TESTF_SCAN_FDT);
> > > +#endif /* !CONFIG_NET_LWIP */
> > >
> > >  #if IS_ENABLED(CONFIG_IPV6_ROUTER_DISCOVERY)
> > >
> > > --
> > > 2.40.1
> > >



-- 
Best regards,
Maxim Uvarov


Re: [PATHv11 00/43] net/lwip: add lwip library for the network stack

2024-01-08 Thread Maxim Uvarov
On Fri, 5 Jan 2024 at 02:46, Fabio Estevam  wrote:

> On Thu, Jan 4, 2024 at 12:02 PM Maxim Uvarov 
> wrote:
>
> > CI tests this in all qemu emulated boards. I tested it locally on
> Raspberry Pi - works well. This version did not
> > yet tested on imx8, but the previous version worked on eth0, did not
> work on eth1.  So I plan to continue testing
> > these patches on different boards. But in general it's the upper layer
> then drivers and theoretically has to work on any
> > board. But in fact different boards work in different ways and behaviour
> is different with their qemu model. So I'm a little bit confused
> > how to test and debug these patches on board which I don't have physical
> access...
>
> Can you try to get access to any i.MX board via Linaro?
>


I will try, but for some reason there is no i.MX board in the lab.


>
> > that is really strange, after reboot you should get the initial stage.
> > You can type 'lwip list' and 'net list' to check if there is an IP
> address for
> > active device set.
>
> Nothing strange there:
>
> u-boot=> lwip list
> 1:  eth0 UP IP: 192.168.0.122/255.255.255.0, GW: 192.168.0.1,
> 00:04:9f:06:33:d3
> done.
> u-boot=> net list
> eth0 : ethernet@30be 00:04:9f:06:12:98 active
>

MAC address is different in two commands, it has to be the same.

BR,
Maxim.


Re: [PATHv11 00/43] net/lwip: add lwip library for the network stack

2024-01-04 Thread Maxim Uvarov
On Wed, 3 Jan 2024 at 20:30, Fabio Estevam  wrote:

> Hi Maxim,
>
> On Tue, Jan 2, 2024 at 2:31 PM Maxim Uvarov 
> wrote:
> >
> > Small update here. I made changes without any board limit size changes.
> > Reordered patches to make them compile in sequence. I think I will do one
> > more clean up and more testing,
> > and after that will be able to send an updated version.
> > Working tree is here: https://github.com/u-boot/u-boot/pull/434
>
> In which boards have you tested the series?
>
>
CI tests this in all qemu emulated boards. I tested it locally on Raspberry
Pi - works well. This version did not
yet tested on imx8, but the previous version worked on eth0, did not work
on eth1.  So I plan to continue testing
these patches on different boards. But in general it's the upper layer then
drivers and theoretically has to work on any
board. But in fact different boards work in different ways and behaviour is
different with their qemu model. So I'm a little bit confused
how to test and debug these patches on board which I don't have physical
access...


> I built from https://github.com/muvarov/u-boot/tree/master_lwip_test_v10,
> but
> it does not work reliably on an imx8mn-evk board. (Actualy tftp worked
> only once):
>
> u-boot=> ping 192.168.0.16
> init already done for ethernet@30be
> Using ethernet@30be device
> pinging addr: 192.168.0.16
> host 192.168.0.16 is alive
>  3 ms
>

It looks like it worked here.


> u-boot=> dhcp Image
>

and this command did not get a dhcp response and unset IP address.
Because there is no IP address then all tftp commands fail. The reasons
might be different:
- no MAC address
- device is not active
- remote DHCP server does not answer for this request

init already done for ethernet@30be
> dhcp using: 0:ethernet@30be
> dhcp_tmo 20/20
> dhcp_tmo 19/20
> dhcp_tmo 18/20
> dhcp_tmo 17/20
> dhcp_tmo 16/20
> dhcp_tmo 15/20
> dhcp_tmo 14/20
> dhcp_tmo 13/20
> dhcp_tmo 12/20
> dhcp_tmo 11/20
> dhcp_tmo 10/20
> dhcp_tmo 9/20
> dhcp_tmo 8/20
> dhcp_tmo 7/20
> dhcp_tmo 6/20
> dhcp_tmo 5/20
> dhcp_tmo 4/20
> dhcp_tmo 3/20
> dhcp_tmo 2/20
> dhcp_tmo 1/20
> dhcp_tmo 0/20
> DHCP client timeout
> u-boot=> tftp Image
> init already done for ethernet@30be
> TFTP from server 192.168.0.16; our IP address is 
> Filename 'Image'.
> Load address: 0x4200
> Loading:
> done
> Bytes transferred = 19808768 (0x12e4200 hex)
> u-boot=> tftp Image
> init already done for ethernet@30be
> TFTP from server 192.168.0.16; our IP address is 
> Filename 'Image'.
> Load address: 0x4200
> Loading:eth_send error -22
>

ok. eth_send() is a function which actually sends a packet. It checks if
the device is active or not.
if (!eth_is_active(current))
return -EINVAL;
I think eth_init() or something else is missing this specific board. But I
don't have any idea how to fix it
without physical access to this board or a way to reproduce it on some
other board.
'ethact' - is a variable to choose an active net device.


> tftp_get err=-13
> u-boot=> tftp Image
> init already done for ethernet@30be
> TFTP from server 192.168.0.16; our IP address is 
> Filename 'Image'.
> Load address: 0x4200
> Loading:eth_send error -22
> tftp_get err=-13
> u-boot=> tftp Image
> init already done for ethernet@30be
> TFTP from server 192.168.0.16; our IP address is 
> Filename 'Image'.
> Load address: 0x4200
> Loading:eth_send error -22
> tftp_get err=-13
>
> Rebooted the board and tried again:
>
> u-boot=> ping 192.168.0.16
>

that is really strange, after reboot you should get the initial stage.
You can type 'lwip list' and 'net list' to check if there is an IP address
for
active device set.

eth0: ethernet@30be 00:04:9f:06:33:d3 active
> Using ethernet@30be device
> pinging addr: 192.168.0.16
> ping_tmo: ping failed; host 192.168.0.16 is not alive
> u-boot=>
>


Re: [PATHv11 00/43] net/lwip: add lwip library for the network stack

2024-01-02 Thread Maxim Uvarov
Small update here. I made changes without any board limit size changes.
Reordered patches to make them compile in sequence. I think I will do one
more clean up and more testing,
and after that will be able to send an updated version.
Working tree is here: https://github.com/u-boot/u-boot/pull/434

SPL might have a very limited network stack (current code for tftp and
bootp). While later stage bootloader can have complete protocol (lwip).
That model fits all current boards limits.

'ethrotate' variable is more likely to go away and be replaced with routing
tables and command line arguments ('dhcp all', "ping -i eth0 IP" ).

However, I have a strange issue with mips malta. Work around:
https://github.com/u-boot/u-boot/pull/434/commits/14717056115944f67eeb22571330d551a1b1ecb7
Issue is that if LWIP_TCP=0 generated code for network stack is less on few
kilobytes. In that case
qemu is unable to start and does not even print hello messages. I followed
this documentation ./doc/board/emulation/qemu-mips.rst
for qemu run. While if image size is bigger and TCP for example compiled
then qemu boots and operates fine. For now
this issue is a little bit strange for me. And more strange how that
related to lwip code, because the network works on much later
stage then initial messages print.

Thanks,
Maxim.


On Tue, 19 Dec 2023 at 16:12, Alexander Dahl  wrote:

> Hello Maxim,
>
> Am Mon, Nov 27, 2023 at 06:56:43PM +0600 schrieb Maxim Uvarov:
> > Hello,
> >
> > Please find updated version of lwip patches. Changes are in the
> > changelog bellow.
> >
> > Thank you,
> > Maxim.
> >
> > changelog:
> >   v11: - v11 is mosly respin of v10 patches with CI error fixes.
> > Gitlab CI:
> >
> https://source.denx.de/u-boot/custodians/u-boot-tpm/-/pipelines/18368
> > Azure CI:
> >
> https://dev.azure.com/u-boot/u-boot/_build/results?buildId=7366&view=results
> > (Azure CI, which is connected to github. Sometime I can
> see
> >  tftp timeout after some part of download there, but
> that can not be
> >  reproduced locally. While Gitblab CI is stable. Because
> of num tries in
> >  CI I suspect this CI was not always reliable.)
> > Azure and Gitlab also have different toolchains and I
> > would say Gitlab generates bigger code then Azure CI.
> >
> > Also many boards have a binary limit size of 800k (even
> > qemu has limits). And increased limits to fit all the
> code. Specially did it
> > patch by board config to show which boards are failing
> to build. There I have
> > a question if we really want to support new
> functionality for old boards (mips,
> > arm32 and etc...). I hope board owners can help me if
> > it's valid to increase these limits.
>
> In general one can not simply increase that limit without knowing
> details on where U-Boot binary is supposed to be stored on a
> particular board.  For example there are boards where U-Boot is stored
> on NAND flash with fixed sized (mtd) partitions.  Changing the
> partition layout on a running board is quite risky from my point of
> view, so you can assume that partition sizes fixed at all times.
> Those sizes determine the limit however.  That said: it has to be
> checked board by board if such a limit can be increased at all.
>
> Greets
> Alex
>
> >
> >   In this version I used git submodules and friend CI with
> >   submodules. But I don't mind if you decide to maintain it
> in a different
> >   way.
> >
> >
> >   v10: - fix ping with following tftp command issue with incorrect
> >   ping timeout clear.
> >- Makefile on make will init submodules and if needed will
> >  do git clone.
> >- wget - some minor code style changes.
> >   v9: - added first patch describing git submodule for lwip. So
> > the build procedure is:
> >   git submodule init
> >   git submodule update
> >   make
> >   - reworked a little bit dhcp cmd state polling
> >   - fixed review comments for v8
> >   v8: - comments for previous review
> >   - removed lwip timeout callback pointer
> >   - made lwip timeouts works, that also allowed to remove
> > static vars.
> >   - setenv for filesize tftp and wget has to be in hex.
> >   - Makefile changes always com

[PATHv3 8/8] Makefile: add dtbs to clean

2023-12-26 Thread Maxim Uvarov
CI test checks that generated dtb has to be cleaned up.
Use the same clean procedure as Linux top level Makefile has.

Signed-off-by: Maxim Uvarov 
---
 Makefile | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/Makefile b/Makefile
index 220411a293..b443831a93 100644
--- a/Makefile
+++ b/Makefile
@@ -2195,6 +2195,8 @@ clean: $(clean-dirs)
@find $(if $(KBUILD_EXTMOD), $(KBUILD_EXTMOD), .) $(RCS_FIND_IGNORE) \
\( -name '*.[oas]' -o -name '*.ko' -o -name '.*.cmd' \
-o -name '*.ko.*' -o -name '*.su' -o -name '*.pyc' \
+   -o -name '*.dtb' -o -name '*.dtbo' \
+   -o -name '*.dtb.S' -o -name '*.dtbo.S' \
-o -name '.*.d' -o -name '.*.tmp' -o -name '*.mod.c' \
-o -name '*.lex.c' -o -name '*.tab.[ch]' \
-o -name '*.asn1.[ch]' \
-- 
2.30.2



[PATHv3 7/8] omap3: use device specific naming for mem_init

2023-12-26 Thread Maxim Uvarov
Use device specific naming for functions so as to not overlap
with common function names.

Signed-off-by: Maxim Uvarov 
Reviewed-by: Tom Rini 
---
 arch/arm/include/asm/arch-omap3/mem.h | 2 +-
 arch/arm/mach-omap2/omap3/board.c | 2 +-
 arch/arm/mach-omap2/omap3/emif4.c | 4 ++--
 arch/arm/mach-omap2/omap3/sdrc.c  | 6 +++---
 4 files changed, 7 insertions(+), 7 deletions(-)

diff --git a/arch/arm/include/asm/arch-omap3/mem.h 
b/arch/arm/include/asm/arch-omap3/mem.h
index 569779c55e..fce3568eca 100644
--- a/arch/arm/include/asm/arch-omap3/mem.h
+++ b/arch/arm/include/asm/arch-omap3/mem.h
@@ -475,7 +475,7 @@ enum {
 #ifndef __ASSEMBLY__
 
 /* Function prototypes */
-void mem_init(void);
+void omap3_mem_init(void);
 
 u32 is_mem_sdr(void);
 u32 mem_ok(u32 cs);
diff --git a/arch/arm/mach-omap2/omap3/board.c 
b/arch/arm/mach-omap2/omap3/board.c
index 8b70251457..c76a95dd5d 100644
--- a/arch/arm/mach-omap2/omap3/board.c
+++ b/arch/arm/mach-omap2/omap3/board.c
@@ -216,7 +216,7 @@ void s_init(void)
 void board_init_f(ulong dummy)
 {
early_system_init();
-   mem_init();
+   omap3_mem_init();
/*
* Save the boot parameters passed from romcode.
* We cannot delay the saving further than this,
diff --git a/arch/arm/mach-omap2/omap3/emif4.c 
b/arch/arm/mach-omap2/omap3/emif4.c
index 7e5a281922..4fbfb387ab 100644
--- a/arch/arm/mach-omap2/omap3/emif4.c
+++ b/arch/arm/mach-omap2/omap3/emif4.c
@@ -159,10 +159,10 @@ int dram_init_banksize(void)
 }
 
 /*
- * mem_init() -
+ * omap3_mem_init() -
  *  - Initialize memory subsystem
  */
-void mem_init(void)
+void omap3_mem_init(void)
 {
do_emif4_init();
 }
diff --git a/arch/arm/mach-omap2/omap3/sdrc.c b/arch/arm/mach-omap2/omap3/sdrc.c
index 5d43e7c9cf..4d27d82c78 100644
--- a/arch/arm/mach-omap2/omap3/sdrc.c
+++ b/arch/arm/mach-omap2/omap3/sdrc.c
@@ -4,7 +4,7 @@
  *
  * This file has been created after exctracting and consolidating
  * the SDRC related content from mem.c and board.c, also created
- * generic init function (mem_init).
+ * generic init function (omap3_mem_init).
  *
  * Copyright (C) 2004-2010
  * Texas Instruments Incorporated - https://www.ti.com/
@@ -232,11 +232,11 @@ int dram_init_banksize(void)
 }
 
 /*
- * mem_init -
+ * omap3_mem_init -
  *  - Init the sdrc chip,
  *  - Selects CS0 and CS1,
  */
-void mem_init(void)
+void omap3_mem_init(void)
 {
/* only init up first bank here */
do_sdrc_init(CS0, EARLY_INIT);
-- 
2.30.2



[PATHv3 6/8] bcm_ns3: use device specific naming for variables

2023-12-26 Thread Maxim Uvarov
Use device specific naming for variables so as to not overlap
with common function names.

Signed-off-by: Maxim Uvarov 
Reviewed-by: Tom Rini 
Reviewed-by: Peter Robinson 
---
 include/configs/bcm_ns3.h | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/include/configs/bcm_ns3.h b/include/configs/bcm_ns3.h
index 47de4bc201..7c6e0725a6 100644
--- a/include/configs/bcm_ns3.h
+++ b/include/configs/bcm_ns3.h
@@ -45,11 +45,11 @@
 #define PCIE_ARGS "pcie_args=pci=pcie_bus_safe pcie_ports=native 
vfio_pci.disable_idle_d3=1\0"
 
 #ifdef CONFIG_BCM_SF2_ETH
-#define ETH_ADDR "ethaddr=00:0A:F7:95:65:A4\0"
+#define BCM_ETH_ADDR "ethaddr=00:0A:F7:95:65:A4\0"
 #define NET_ARGS "bgmac_platform.ethaddr=${ethaddr} " \
"ip=${ipaddr}::${gatewayip}:${netmask}::${ethif}:off"
 #else
-#define ETH_ADDR
+#define BMC_ETH_ADDR
 #define NET_ARGS
 #endif
 
@@ -749,7 +749,7 @@
OS_LOG_LEVEL \
EXTRA_ARGS \
PCIE_ARGS \
-   ETH_ADDR \
+   BMC_ETH_ADDR \
RESERVED_MEM \
SETBOOTARGS \
UPDATEME_FLASH_PARAMS \
-- 
2.30.2



[PATHv3 5/8] mach-socfpga: do not overlap defines with lwip

2023-12-26 Thread Maxim Uvarov
Fix compilation issue with overlapping lwip and march defines.

Signed-off-by: Maxim Uvarov 
Reviewed-by: Simon Glass 
---
 arch/arm/mach-socfpga/include/mach/handoff_soc64.h | 6 --
 arch/arm/mach-socfpga/wrap_handoff_soc64.c | 9 +
 2 files changed, 9 insertions(+), 6 deletions(-)

diff --git a/arch/arm/mach-socfpga/include/mach/handoff_soc64.h 
b/arch/arm/mach-socfpga/include/mach/handoff_soc64.h
index 902fc6bfb5..9b85e5865b 100644
--- a/arch/arm/mach-socfpga/include/mach/handoff_soc64.h
+++ b/arch/arm/mach-socfpga/include/mach/handoff_soc64.h
@@ -78,12 +78,6 @@
 
 #ifndef __ASSEMBLY__
 #include 
-enum endianness {
-   LITTLE_ENDIAN = 0,
-   BIG_ENDIAN,
-   UNKNOWN_ENDIANNESS
-};
-
 int socfpga_get_handoff_size(void *handoff_address);
 int socfpga_handoff_read(void *handoff_address, void *table, u32 table_len);
 #endif
diff --git a/arch/arm/mach-socfpga/wrap_handoff_soc64.c 
b/arch/arm/mach-socfpga/wrap_handoff_soc64.c
index e7cb5ea89c..df0701ec85 100644
--- a/arch/arm/mach-socfpga/wrap_handoff_soc64.c
+++ b/arch/arm/mach-socfpga/wrap_handoff_soc64.c
@@ -10,6 +10,15 @@
 #include 
 #include "log.h"
 
+#ifndef __ASSEMBLY__
+#include 
+enum endianness {
+   LITTLE_ENDIAN = 0,
+   BIG_ENDIAN,
+   UNKNOWN_ENDIANNESS
+};
+#endif
+
 static enum endianness check_endianness(u32 handoff)
 {
switch (handoff) {
-- 
2.30.2



[PATHv3 4/8] driver/net/rtl8139: remove debug print

2023-12-26 Thread Maxim Uvarov
debug print delays reset of the driver. Finally I see
bunch of "rx error " errors in the screen. CI can
not handle many prints. While network works fine there

Reproduced with:
make CROSS_COMPILE=sh2-linux- r2dplus_defconfig all
qemu-system-sh4 -M r2d -nographic -serial null \
-serial mon:stdio -net user,tftp=`pwd` \
-net nic,model=rtl8139 -kernel ./u-boot.bin

Signed-off-by: Maxim Uvarov 
Reviewed-by: Simon Glass 
---
 drivers/net/rtl8139.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/net/rtl8139.c b/drivers/net/rtl8139.c
index 106bc1c7ae..d8f24ec81a 100644
--- a/drivers/net/rtl8139.c
+++ b/drivers/net/rtl8139.c
@@ -453,7 +453,7 @@ static int rtl8139_recv_common(struct rtl8139_priv *priv, 
unsigned char *rxdata,
  RTL_STS_RXBADALIGN)) ||
(rx_size < ETH_ZLEN) ||
(rx_size > ETH_FRAME_LEN + 4)) {
-   printf("rx error %hX\n", rx_status);
+   debug("rx error %hX\n", rx_status);
/* this clears all interrupts still pending */
rtl8139_reset(priv);
return 0;
-- 
2.30.2



[PATHv3 3/8] sandbox: eth-raw-os: successful return code is 0

2023-12-26 Thread Maxim Uvarov
all network drivers return 0 on the successful
transmission.

Signed-off-by: Maxim Uvarov 
Reviewed-by: Simon Glass 
---
 arch/sandbox/cpu/eth-raw-os.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/sandbox/cpu/eth-raw-os.c b/arch/sandbox/cpu/eth-raw-os.c
index e59b96be5f..92c35aed95 100644
--- a/arch/sandbox/cpu/eth-raw-os.c
+++ b/arch/sandbox/cpu/eth-raw-os.c
@@ -256,7 +256,7 @@ int sandbox_eth_raw_os_send(void *packet, int length,
   strerror(errno));
return -errno;
}
-   return retval;
+   return 0;
 }
 
 int sandbox_eth_raw_os_recv(void *packet, int *length,
-- 
2.30.2



[PATHv3 2/8] net/smc911x: fix return from smc911x_send

2023-12-26 Thread Maxim Uvarov
return value of smc911x_send is ignored, but on sucesseful
send we need return 0 and or error -ETIMEOUT, not opposite.

Signed-off-by: Maxim Uvarov 
Reviewed-by: Tom Rini 
Reviewed-by: Simon Glass 
---
 drivers/net/smc911x.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/net/smc911x.c b/drivers/net/smc911x.c
index 5c5ad8b84a..616b7ce174 100644
--- a/drivers/net/smc911x.c
+++ b/drivers/net/smc911x.c
@@ -403,7 +403,7 @@ static int smc911x_send(struct udevice *dev, void *packet, 
int length)
 
ret = smc911x_send_common(priv, packet, length);
 
-   return ret ? 0 : -ETIMEDOUT;
+   return ret ? -ETIMEDOUT : 0;
 }
 
 static int smc911x_recv(struct udevice *dev, int flags, uchar **packetp)
-- 
2.30.2



[PATHv3 1/8] test_net: print out net list

2023-12-26 Thread Maxim Uvarov
Printing net list is useful in CI log files.

Signed-off-by: Maxim Uvarov 
Reviewed-by: Simon Glass 
---
 test/py/tests/test_net.py | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/test/py/tests/test_net.py b/test/py/tests/test_net.py
index b2241ae6a4..cd5b791a6a 100644
--- a/test/py/tests/test_net.py
+++ b/test/py/tests/test_net.py
@@ -96,6 +96,8 @@ def test_net_pre_commands(u_boot_console):
 if init_pci:
 u_boot_console.run_command('pci enum')
 
+u_boot_console.run_command('net list')
+
 @pytest.mark.buildconfigspec('cmd_dhcp')
 def test_net_dhcp(u_boot_console):
 """Test the dhcp command.
-- 
2.30.2



[PATHv3 0/8] net fixes prior lwip

2023-12-26 Thread Maxim Uvarov
Add small net fixes prior lwip patches.

v3: - some small review fixes.
v2: - rebase on the top of master tree with descriptions fixes
  suggested in review comments.
Maxim Uvarov (8):
  test_net: print out net list
  net/smc911x: fix return from smc911x_send
  sandbox: eth-raw-os: successful return code is 0
  driver/net/rtl8139: remove debug print
  mach-socfpga: do not overlap defines with lwip
  bcm_ns3: use device specific naming for variables
  omap3: use device specific naming for mem_init
  Makefile: add dtbs to clean

 Makefile   | 2 ++
 arch/arm/include/asm/arch-omap3/mem.h  | 2 +-
 arch/arm/mach-omap2/omap3/board.c  | 2 +-
 arch/arm/mach-omap2/omap3/emif4.c  | 4 ++--
 arch/arm/mach-omap2/omap3/sdrc.c   | 6 +++---
 arch/arm/mach-socfpga/include/mach/handoff_soc64.h | 6 --
 arch/arm/mach-socfpga/wrap_handoff_soc64.c | 9 +
 arch/sandbox/cpu/eth-raw-os.c  | 2 +-
 drivers/net/rtl8139.c  | 2 +-
 drivers/net/smc911x.c  | 2 +-
 include/configs/bcm_ns3.h  | 6 +++---
 test/py/tests/test_net.py  | 2 ++
 12 files changed, 26 insertions(+), 19 deletions(-)

-- 
2.30.2



Re: [PATHv2 9/9] Makefile: add dtbs to clean

2023-12-26 Thread Maxim Uvarov
On Tue, 26 Dec 2023 at 15:50, Simon Glass  wrote:

> Hi Maxim,
>
> On Mon, Dec 25, 2023 at 3:42 PM Maxim Uvarov 
> wrote:
> >
> > CI test checks that generated dtb has to be cleaned up.
> >
> > Signed-off-by: Maxim Uvarov 
> > ---
> >  Makefile | 3 ++-
> >  1 file changed, 2 insertions(+), 1 deletion(-)
> >
> > diff --git a/Makefile b/Makefile
> > index 220411a293..ab603191ad 100644
> > --- a/Makefile
> > +++ b/Makefile
> > @@ -2165,7 +2165,8 @@ CLEAN_FILES += include/autoconf.mk*
> include/bmp_logo.h include/bmp_logo_data.h \
> >mkimage-out.spl.mkimage mkimage.spl.mkimage imx-boot.map \
> >itb.fit.fit itb.fit.itb itb.map spl.map
> mkimage-out.rom.mkimage \
> >mkimage.rom.mkimage mkimage-in-simple-bin* rom.map
> simple-bin* \
> > -  idbloader-spi.img lib/efi_loader/helloworld_efi.S *.itb
> > +  idbloader-spi.img lib/efi_loader/helloworld_efi.S *.itb \
> > +  ./*/*.dtb *.dtb
> >
> >  # Directories & files removed with 'make mrproper'
> >  MRPROPER_DIRS  += include/config include/generated spl tpl vpl \
> > --
> > 2.30.2
> >
>
> Shouldn't this be handled with CLEAN_FILES in arch/xxx/dts ?
>
> Regards,
> Simon
>

I don't know. It looks like CLEAN_FILES is almost not used inside ./arch
directory. Only 1 place where it appears:

fgrep -r CLEAN_FILES ./arch/
./arch/arm/mach-rmobile/Makefile:CLEAN_FILES += u-boot-spl.scif

BR,
Maxim.


Re: [PATHv2 9/9] Makefile: add dtbs to clean

2023-12-26 Thread Maxim Uvarov
On Tue, 26 Dec 2023 at 20:26, Tom Rini  wrote:

> On Tue, Dec 26, 2023 at 06:27:58PM +0600, Maxim Uvarov wrote:
> > On Tue, 26 Dec 2023 at 15:50, Simon Glass  wrote:
> >
> > > Hi Maxim,
> > >
> > > On Mon, Dec 25, 2023 at 3:42 PM Maxim Uvarov 
> > > wrote:
> > > >
> > > > CI test checks that generated dtb has to be cleaned up.
> > > >
> > > > Signed-off-by: Maxim Uvarov 
> > > > ---
> > > >  Makefile | 3 ++-
> > > >  1 file changed, 2 insertions(+), 1 deletion(-)
> > > >
> > > > diff --git a/Makefile b/Makefile
> > > > index 220411a293..ab603191ad 100644
> > > > --- a/Makefile
> > > > +++ b/Makefile
> > > > @@ -2165,7 +2165,8 @@ CLEAN_FILES += include/autoconf.mk*
> > > include/bmp_logo.h include/bmp_logo_data.h \
> > > >mkimage-out.spl.mkimage mkimage.spl.mkimage
> imx-boot.map \
> > > >itb.fit.fit itb.fit.itb itb.map spl.map
> > > mkimage-out.rom.mkimage \
> > > >mkimage.rom.mkimage mkimage-in-simple-bin* rom.map
> > > simple-bin* \
> > > > -  idbloader-spi.img lib/efi_loader/helloworld_efi.S
> *.itb
> > > > +  idbloader-spi.img lib/efi_loader/helloworld_efi.S
> *.itb \
> > > > +  ./*/*.dtb *.dtb
> > > >
> > > >  # Directories & files removed with 'make mrproper'
> > > >  MRPROPER_DIRS  += include/config include/generated spl tpl vpl \
> > > > --
> > > > 2.30.2
> > > >
> > >
> > > Shouldn't this be handled with CLEAN_FILES in arch/xxx/dts ?
> > >
> > > Regards,
> > > Simon
> > >
> >
> > I don't know. It looks like CLEAN_FILES is almost not used inside ./arch
> > directory. Only 1 place where it appears:
> >
> > fgrep -r CLEAN_FILES ./arch/
> > ./arch/arm/mach-rmobile/Makefile:CLEAN_FILES += u-boot-spl.scif
>
> I see that our top-level clean target is missing dtb related targets
> like the linux kernel has, and that's how this should be fixed.
>
> --
> Tom
>

If I understand right you just refers to kernel's top level Makefile
clean:
find
-o -name '*.dtb' -o -name '*.dtbo' \

-o -name '*.dtb.S' -o -name '*.dtbo.S' \
| xargs rm -rf

 I will fix it in that way in v3.

BR,
Maxim.


Re: [PATHv2 2/9] net: sandbox: fix NULL pointer derefences

2023-12-26 Thread Maxim Uvarov
On Tue, 26 Dec 2023 at 12:25, Sean Anderson  wrote:

> On 12/26/23 01:18, Maxim Uvarov wrote:
> >
> >
> > On Tue, 26 Dec 2023 at 04:43, Sean Anderson  sean...@gmail.com>> wrote:
> >
> > On 12/25/23 10:39, Maxim Uvarov wrote:
> >  > Add additional checks for NULL pointers.
> >  >
> >  > Signed-off-by: Maxim Uvarov  maxim.uva...@linaro.org>>
> >  > ---
> >  >   drivers/net/sandbox.c | 3 +++
> >  >   1 file changed, 3 insertions(+)
> >  >
> >  > diff --git a/drivers/net/sandbox.c b/drivers/net/sandbox.c
> >  > index 13022addb6..d91935e032 100644
> >  > --- a/drivers/net/sandbox.c
> >  > +++ b/drivers/net/sandbox.c
> >  > @@ -65,6 +65,9 @@ int sandbox_eth_arp_req_to_reply(struct udevice
> *dev, void *packet,
> >  >   struct ethernet_hdr *eth_recv;
> >  >   struct arp_hdr *arp_recv;
> >  >
> >  > + if (!priv)
> >  > + return -EAGAIN;
> >  > +
> >
> > When can priv be NULL?
> >
> > --Sean
> >
> >
> > Function
> > struct eth_sandbox_priv *priv = dev_get_priv(dev)
> > can return NULL. If you ask why it doesn't return NULL without lwip
> patches and can return NULL with lwip patch while there is no clear code
> dependency..
> > Then I can not say right now and need additional investigation. But
> anyway the return code of dev_dev_priv() has to be checked I think.
>
> If you set priv_auto to a nonzero value, dev_get_priv will always return
> non-null
> and does not need to be checked. So this is a NACK from me until you can
> justify this.
>
> --Sean
>

Ok. I will remove this patch from v3 patchset and send it separately with a
more detailed description.

BR,
Maxim.


Re: [PATHv2 8/9] omap3: use device specific naming for mem_init

2023-12-25 Thread Maxim Uvarov
On Tue, 26 Dec 2023 at 04:49, Sean Anderson  wrote:

> On 12/25/23 10:39, Maxim Uvarov wrote:
> > Use device specific naming for functions so as to not overlap
> > with common function names.
> >
> > Signed-off-by: Maxim Uvarov 
> > Reviewed-by: Tom Rini 
> > ---
> >   arch/arm/include/asm/arch-omap3/mem.h | 2 +-
> >   arch/arm/mach-omap2/omap3/board.c | 2 +-
> >   arch/arm/mach-omap2/omap3/emif4.c | 4 ++--
> >   arch/arm/mach-omap2/omap3/sdrc.c  | 6 +++---
> >   4 files changed, 7 insertions(+), 7 deletions(-)
> >
> > diff --git a/arch/arm/include/asm/arch-omap3/mem.h
> b/arch/arm/include/asm/arch-omap3/mem.h
> > index 569779c55e..fce3568eca 100644
> > --- a/arch/arm/include/asm/arch-omap3/mem.h
> > +++ b/arch/arm/include/asm/arch-omap3/mem.h
> > @@ -475,7 +475,7 @@ enum {
> >   #ifndef __ASSEMBLY__
> >
> >   /* Function prototypes */
> > -void mem_init(void);
> > +void omap3_mem_init(void);
> >
> >   u32 is_mem_sdr(void);
> >   u32 mem_ok(u32 cs);
> > diff --git a/arch/arm/mach-omap2/omap3/board.c
> b/arch/arm/mach-omap2/omap3/board.c
> > index 8b70251457..c76a95dd5d 100644
> > --- a/arch/arm/mach-omap2/omap3/board.c
> > +++ b/arch/arm/mach-omap2/omap3/board.c
> > @@ -216,7 +216,7 @@ void s_init(void)
> >   void board_init_f(ulong dummy)
> >   {
> >   early_system_init();
> > - mem_init();
> > + omap3_mem_init();
> >   /*
> >   * Save the boot parameters passed from romcode.
> >   * We cannot delay the saving further than this,
> > diff --git a/arch/arm/mach-omap2/omap3/emif4.c
> b/arch/arm/mach-omap2/omap3/emif4.c
> > index 7e5a281922..4fbfb387ab 100644
> > --- a/arch/arm/mach-omap2/omap3/emif4.c
> > +++ b/arch/arm/mach-omap2/omap3/emif4.c
> > @@ -159,10 +159,10 @@ int dram_init_banksize(void)
> >   }
> >
> >   /*
> > - * mem_init() -
> > + * omap3_mem_init() -
> >*  - Initialize memory subsystem
> >*/
> > -void mem_init(void)
> > +void omap3_mem_init(void)
> >   {
> >   do_emif4_init();
> >   }
> > diff --git a/arch/arm/mach-omap2/omap3/sdrc.c
> b/arch/arm/mach-omap2/omap3/sdrc.c
> > index 5d43e7c9cf..f2a0769b9d 100644
> > --- a/arch/arm/mach-omap2/omap3/sdrc.c
> > +++ b/arch/arm/mach-omap2/omap3/sdrc.c
> > @@ -4,7 +4,7 @@
> >*
> >* This file has been created after exctracting and consolidating
> >* the SDRC related content from mem.c and board.c, also created
> > - * generic init function (mem_init).
> > + * generic init function (omap3_mem_init).
> >*
> >* Copyright (C) 2004-2010
> >* Texas Instruments Incorporated - https://www.ti.com/
> > @@ -232,11 +232,11 @@ int dram_init_banksize(void)
> >   }
> >
> >   /*
> > - * mem_init -
> > + * map3_mem_init -
>
> nit: omap3
>
>
thanks, will add to v3.



> >*  - Init the sdrc chip,
> >*  - Selects CS0 and CS1,
> >*/
> > -void mem_init(void)
> > +void omap3_mem_init(void)
> >   {
> >   /* only init up first bank here */
> >   do_sdrc_init(CS0, EARLY_INIT);
>
>


Re: [PATHv2 2/9] net: sandbox: fix NULL pointer derefences

2023-12-25 Thread Maxim Uvarov
On Tue, 26 Dec 2023 at 04:43, Sean Anderson  wrote:

> On 12/25/23 10:39, Maxim Uvarov wrote:
> > Add additional checks for NULL pointers.
> >
> > Signed-off-by: Maxim Uvarov 
> > ---
> >   drivers/net/sandbox.c | 3 +++
> >   1 file changed, 3 insertions(+)
> >
> > diff --git a/drivers/net/sandbox.c b/drivers/net/sandbox.c
> > index 13022addb6..d91935e032 100644
> > --- a/drivers/net/sandbox.c
> > +++ b/drivers/net/sandbox.c
> > @@ -65,6 +65,9 @@ int sandbox_eth_arp_req_to_reply(struct udevice *dev,
> void *packet,
> >   struct ethernet_hdr *eth_recv;
> >   struct arp_hdr *arp_recv;
> >
> > + if (!priv)
> > + return -EAGAIN;
> > +
>
> When can priv be NULL?
>
> --Sean
>
>
Function
struct eth_sandbox_priv *priv = dev_get_priv(dev)
can return NULL. If you ask why it doesn't return NULL without lwip patches
and can return NULL with lwip patch while there is no clear code
dependency..
Then I can not say right now and need additional investigation. But anyway
the return code of dev_dev_priv() has to be checked I think.

BR,
Maxim.



> >   if (ntohs(eth->et_protlen) != PROT_ARP)
> >   return -EAGAIN;
> >
>
>


[PATHv2 9/9] Makefile: add dtbs to clean

2023-12-25 Thread Maxim Uvarov
CI test checks that generated dtb has to be cleaned up.

Signed-off-by: Maxim Uvarov 
---
 Makefile | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/Makefile b/Makefile
index 220411a293..ab603191ad 100644
--- a/Makefile
+++ b/Makefile
@@ -2165,7 +2165,8 @@ CLEAN_FILES += include/autoconf.mk* include/bmp_logo.h 
include/bmp_logo_data.h \
   mkimage-out.spl.mkimage mkimage.spl.mkimage imx-boot.map \
   itb.fit.fit itb.fit.itb itb.map spl.map mkimage-out.rom.mkimage \
   mkimage.rom.mkimage mkimage-in-simple-bin* rom.map simple-bin* \
-  idbloader-spi.img lib/efi_loader/helloworld_efi.S *.itb
+  idbloader-spi.img lib/efi_loader/helloworld_efi.S *.itb \
+  ./*/*.dtb *.dtb
 
 # Directories & files removed with 'make mrproper'
 MRPROPER_DIRS  += include/config include/generated spl tpl vpl \
-- 
2.30.2



[PATHv2 8/9] omap3: use device specific naming for mem_init

2023-12-25 Thread Maxim Uvarov
Use device specific naming for functions so as to not overlap
with common function names.

Signed-off-by: Maxim Uvarov 
Reviewed-by: Tom Rini 
---
 arch/arm/include/asm/arch-omap3/mem.h | 2 +-
 arch/arm/mach-omap2/omap3/board.c | 2 +-
 arch/arm/mach-omap2/omap3/emif4.c | 4 ++--
 arch/arm/mach-omap2/omap3/sdrc.c  | 6 +++---
 4 files changed, 7 insertions(+), 7 deletions(-)

diff --git a/arch/arm/include/asm/arch-omap3/mem.h 
b/arch/arm/include/asm/arch-omap3/mem.h
index 569779c55e..fce3568eca 100644
--- a/arch/arm/include/asm/arch-omap3/mem.h
+++ b/arch/arm/include/asm/arch-omap3/mem.h
@@ -475,7 +475,7 @@ enum {
 #ifndef __ASSEMBLY__
 
 /* Function prototypes */
-void mem_init(void);
+void omap3_mem_init(void);
 
 u32 is_mem_sdr(void);
 u32 mem_ok(u32 cs);
diff --git a/arch/arm/mach-omap2/omap3/board.c 
b/arch/arm/mach-omap2/omap3/board.c
index 8b70251457..c76a95dd5d 100644
--- a/arch/arm/mach-omap2/omap3/board.c
+++ b/arch/arm/mach-omap2/omap3/board.c
@@ -216,7 +216,7 @@ void s_init(void)
 void board_init_f(ulong dummy)
 {
early_system_init();
-   mem_init();
+   omap3_mem_init();
/*
* Save the boot parameters passed from romcode.
* We cannot delay the saving further than this,
diff --git a/arch/arm/mach-omap2/omap3/emif4.c 
b/arch/arm/mach-omap2/omap3/emif4.c
index 7e5a281922..4fbfb387ab 100644
--- a/arch/arm/mach-omap2/omap3/emif4.c
+++ b/arch/arm/mach-omap2/omap3/emif4.c
@@ -159,10 +159,10 @@ int dram_init_banksize(void)
 }
 
 /*
- * mem_init() -
+ * omap3_mem_init() -
  *  - Initialize memory subsystem
  */
-void mem_init(void)
+void omap3_mem_init(void)
 {
do_emif4_init();
 }
diff --git a/arch/arm/mach-omap2/omap3/sdrc.c b/arch/arm/mach-omap2/omap3/sdrc.c
index 5d43e7c9cf..f2a0769b9d 100644
--- a/arch/arm/mach-omap2/omap3/sdrc.c
+++ b/arch/arm/mach-omap2/omap3/sdrc.c
@@ -4,7 +4,7 @@
  *
  * This file has been created after exctracting and consolidating
  * the SDRC related content from mem.c and board.c, also created
- * generic init function (mem_init).
+ * generic init function (omap3_mem_init).
  *
  * Copyright (C) 2004-2010
  * Texas Instruments Incorporated - https://www.ti.com/
@@ -232,11 +232,11 @@ int dram_init_banksize(void)
 }
 
 /*
- * mem_init -
+ * map3_mem_init -
  *  - Init the sdrc chip,
  *  - Selects CS0 and CS1,
  */
-void mem_init(void)
+void omap3_mem_init(void)
 {
/* only init up first bank here */
do_sdrc_init(CS0, EARLY_INIT);
-- 
2.30.2



[PATHv2 7/9] bcm_ns3: use device specific naming for variables

2023-12-25 Thread Maxim Uvarov
Use device specific naming for variables so as to not overlap
with common function names.

Signed-off-by: Maxim Uvarov 
Reviewed-by: Tom Rini 
Reviewed-by: Peter Robinson 
---
 include/configs/bcm_ns3.h | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/include/configs/bcm_ns3.h b/include/configs/bcm_ns3.h
index 47de4bc201..7c6e0725a6 100644
--- a/include/configs/bcm_ns3.h
+++ b/include/configs/bcm_ns3.h
@@ -45,11 +45,11 @@
 #define PCIE_ARGS "pcie_args=pci=pcie_bus_safe pcie_ports=native 
vfio_pci.disable_idle_d3=1\0"
 
 #ifdef CONFIG_BCM_SF2_ETH
-#define ETH_ADDR "ethaddr=00:0A:F7:95:65:A4\0"
+#define BCM_ETH_ADDR "ethaddr=00:0A:F7:95:65:A4\0"
 #define NET_ARGS "bgmac_platform.ethaddr=${ethaddr} " \
"ip=${ipaddr}::${gatewayip}:${netmask}::${ethif}:off"
 #else
-#define ETH_ADDR
+#define BMC_ETH_ADDR
 #define NET_ARGS
 #endif
 
@@ -749,7 +749,7 @@
OS_LOG_LEVEL \
EXTRA_ARGS \
PCIE_ARGS \
-   ETH_ADDR \
+   BMC_ETH_ADDR \
RESERVED_MEM \
SETBOOTARGS \
UPDATEME_FLASH_PARAMS \
-- 
2.30.2



[PATHv2 6/9] mach-socfpga: do not overlap defines with lwip

2023-12-25 Thread Maxim Uvarov
Fix compilation issue with overlapping lwip and march defines.

Signed-off-by: Maxim Uvarov 
---
 arch/arm/mach-socfpga/include/mach/handoff_soc64.h | 6 --
 arch/arm/mach-socfpga/wrap_handoff_soc64.c | 9 +
 2 files changed, 9 insertions(+), 6 deletions(-)

diff --git a/arch/arm/mach-socfpga/include/mach/handoff_soc64.h 
b/arch/arm/mach-socfpga/include/mach/handoff_soc64.h
index 902fc6bfb5..9b85e5865b 100644
--- a/arch/arm/mach-socfpga/include/mach/handoff_soc64.h
+++ b/arch/arm/mach-socfpga/include/mach/handoff_soc64.h
@@ -78,12 +78,6 @@
 
 #ifndef __ASSEMBLY__
 #include 
-enum endianness {
-   LITTLE_ENDIAN = 0,
-   BIG_ENDIAN,
-   UNKNOWN_ENDIANNESS
-};
-
 int socfpga_get_handoff_size(void *handoff_address);
 int socfpga_handoff_read(void *handoff_address, void *table, u32 table_len);
 #endif
diff --git a/arch/arm/mach-socfpga/wrap_handoff_soc64.c 
b/arch/arm/mach-socfpga/wrap_handoff_soc64.c
index e7cb5ea89c..df0701ec85 100644
--- a/arch/arm/mach-socfpga/wrap_handoff_soc64.c
+++ b/arch/arm/mach-socfpga/wrap_handoff_soc64.c
@@ -10,6 +10,15 @@
 #include 
 #include "log.h"
 
+#ifndef __ASSEMBLY__
+#include 
+enum endianness {
+   LITTLE_ENDIAN = 0,
+   BIG_ENDIAN,
+   UNKNOWN_ENDIANNESS
+};
+#endif
+
 static enum endianness check_endianness(u32 handoff)
 {
switch (handoff) {
-- 
2.30.2



[PATHv2 5/9] driver/net/rtl8139: remove debug print

2023-12-25 Thread Maxim Uvarov
debug print delays reset of the driver. Finally I see
bunch of "rx error " errors in the screen. CI can
not handle many prints. While network works fine there

Reproduced with:
make CROSS_COMPILE=sh2-linux- r2dplus_defconfig all
qemu-system-sh4 -M r2d -nographic -serial null \
-serial mon:stdio -net user,tftp=`pwd` \
-net nic,model=rtl8139 -kernel ./u-boot.bin

Signed-off-by: Maxim Uvarov 
---
 drivers/net/rtl8139.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/net/rtl8139.c b/drivers/net/rtl8139.c
index 106bc1c7ae..d8f24ec81a 100644
--- a/drivers/net/rtl8139.c
+++ b/drivers/net/rtl8139.c
@@ -453,7 +453,7 @@ static int rtl8139_recv_common(struct rtl8139_priv *priv, 
unsigned char *rxdata,
  RTL_STS_RXBADALIGN)) ||
(rx_size < ETH_ZLEN) ||
(rx_size > ETH_FRAME_LEN + 4)) {
-   printf("rx error %hX\n", rx_status);
+   debug("rx error %hX\n", rx_status);
/* this clears all interrupts still pending */
rtl8139_reset(priv);
return 0;
-- 
2.30.2



[PATHv2 4/9] sandbox: eth-raw-os: successful return code is 0

2023-12-25 Thread Maxim Uvarov
all network drivers return 0 on the successful
transmission.

Signed-off-by: Maxim Uvarov 
Reviewed-by: Simon Glass 
---
 arch/sandbox/cpu/eth-raw-os.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/sandbox/cpu/eth-raw-os.c b/arch/sandbox/cpu/eth-raw-os.c
index e59b96be5f..92c35aed95 100644
--- a/arch/sandbox/cpu/eth-raw-os.c
+++ b/arch/sandbox/cpu/eth-raw-os.c
@@ -256,7 +256,7 @@ int sandbox_eth_raw_os_send(void *packet, int length,
   strerror(errno));
return -errno;
}
-   return retval;
+   return 0;
 }
 
 int sandbox_eth_raw_os_recv(void *packet, int *length,
-- 
2.30.2



[PATHv2 3/9] net/smc911x: fix return from smc911x_send

2023-12-25 Thread Maxim Uvarov
return value of smc911x_send is ignored, but on sucesseful
send we need return 0 and or error -ETIMEOUT, not opposite.

Signed-off-by: Maxim Uvarov 
Reviewed-by: Tom Rini 
---
 drivers/net/smc911x.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/net/smc911x.c b/drivers/net/smc911x.c
index 5c5ad8b84a..616b7ce174 100644
--- a/drivers/net/smc911x.c
+++ b/drivers/net/smc911x.c
@@ -403,7 +403,7 @@ static int smc911x_send(struct udevice *dev, void *packet, 
int length)
 
ret = smc911x_send_common(priv, packet, length);
 
-   return ret ? 0 : -ETIMEDOUT;
+   return ret ? -ETIMEDOUT : 0;
 }
 
 static int smc911x_recv(struct udevice *dev, int flags, uchar **packetp)
-- 
2.30.2



[PATHv2 2/9] net: sandbox: fix NULL pointer derefences

2023-12-25 Thread Maxim Uvarov
Add additional checks for NULL pointers.

Signed-off-by: Maxim Uvarov 
---
 drivers/net/sandbox.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/net/sandbox.c b/drivers/net/sandbox.c
index 13022addb6..d91935e032 100644
--- a/drivers/net/sandbox.c
+++ b/drivers/net/sandbox.c
@@ -65,6 +65,9 @@ int sandbox_eth_arp_req_to_reply(struct udevice *dev, void 
*packet,
struct ethernet_hdr *eth_recv;
struct arp_hdr *arp_recv;
 
+   if (!priv)
+   return -EAGAIN;
+
if (ntohs(eth->et_protlen) != PROT_ARP)
return -EAGAIN;
 
-- 
2.30.2



[PATHv2 1/9] test_net: print out net list

2023-12-25 Thread Maxim Uvarov
Printing net list is useful in CI log files.

Signed-off-by: Maxim Uvarov 
---
 test/py/tests/test_net.py | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/test/py/tests/test_net.py b/test/py/tests/test_net.py
index b2241ae6a4..cd5b791a6a 100644
--- a/test/py/tests/test_net.py
+++ b/test/py/tests/test_net.py
@@ -96,6 +96,8 @@ def test_net_pre_commands(u_boot_console):
 if init_pci:
 u_boot_console.run_command('pci enum')
 
+u_boot_console.run_command('net list')
+
 @pytest.mark.buildconfigspec('cmd_dhcp')
 def test_net_dhcp(u_boot_console):
 """Test the dhcp command.
-- 
2.30.2



[PATHv2 0/9] net fixes prior lwip

2023-12-25 Thread Maxim Uvarov
Add small net fixes prior lwip patches.

v2: - rebase on the top of master tree with descriptions fixes
  suggested in review comments.

Maxim Uvarov (9):
  test_net: print out net list
  net: sandbox: fix NULL pointer derefences
  net/smc911x: fix return from smc911x_send
  sandbox: eth-raw-os: successful return code is 0
  driver/net/rtl8139: remove debug print
  mach-socfpga: do not overlap defines with lwip
  bcm_ns3: use device specific naming for variables
  omap3: use device specific naming for mem_init
  Makefile: add dtbs to clean

 Makefile   | 3 ++-
 arch/arm/include/asm/arch-omap3/mem.h  | 2 +-
 arch/arm/mach-omap2/omap3/board.c  | 2 +-
 arch/arm/mach-omap2/omap3/emif4.c  | 4 ++--
 arch/arm/mach-omap2/omap3/sdrc.c   | 6 +++---
 arch/arm/mach-socfpga/include/mach/handoff_soc64.h | 6 --
 arch/arm/mach-socfpga/wrap_handoff_soc64.c | 9 +
 arch/sandbox/cpu/eth-raw-os.c  | 2 +-
 drivers/net/rtl8139.c  | 2 +-
 drivers/net/sandbox.c  | 3 +++
 drivers/net/smc911x.c  | 2 +-
 include/configs/bcm_ns3.h  | 6 +++---
 test/py/tests/test_net.py  | 2 ++
 13 files changed, 29 insertions(+), 20 deletions(-)

-- 
2.30.2



Re: [PATHv1 0/9] net fixes prior lwip

2023-12-18 Thread Maxim Uvarov
Hi,

Do I need to resend this patchset with small comment message correction or
it can be done on the apply?

Thank you,
Maxim.

On Mon, 4 Dec 2023 at 18:06, Maxim Uvarov  wrote:

> Add small net fixes prior lwip patch.
>
> CI for this patch set:
>
> https://dev.azure.com/u-boot/u-boot/_build/results?buildId=7460&view=results
>
> Maxim Uvarov (9):
>   test_net: print out net list
>   net: sandbox: fix NULL pointer derefences
>   net/smc911x: fix return from smc911x_send
>   sandbox: eth-raw-os: successful return code is 0
>   driver/net/rtl8139: remove debug print
>   mach-socfpga: do not overlap defines with lwip
>   bcm_ns3: fix overlap define with lwip
>   omap3: rename mem_init
>   Makefile: add dtbs to clean
>
>  Makefile   | 3 ++-
>  arch/arm/include/asm/arch-omap3/mem.h  | 2 +-
>  arch/arm/mach-omap2/omap3/board.c  | 2 +-
>  arch/arm/mach-omap2/omap3/emif4.c  | 4 ++--
>  arch/arm/mach-omap2/omap3/sdrc.c   | 6 +++---
>  arch/arm/mach-socfpga/include/mach/handoff_soc64.h | 6 --
>  arch/arm/mach-socfpga/wrap_handoff_soc64.c | 9 +
>  arch/sandbox/cpu/eth-raw-os.c  | 2 +-
>  drivers/net/rtl8139.c  | 2 +-
>  drivers/net/sandbox.c  | 3 +++
>  drivers/net/smc911x.c  | 2 +-
>  include/configs/bcm_ns3.h  | 6 +++---
>  test/py/tests/test_net.py  | 2 ++
>  13 files changed, 29 insertions(+), 20 deletions(-)
>
> --
> 2.30.2
>
>


Re: [PATHv11 26/43] configs/tbs2910_defconfig inc limit

2023-12-06 Thread Maxim Uvarov
On Wed, 6 Dec 2023 at 13:06, Soeren Moch  wrote:

> On 05.12.23 21:00, Maxim Uvarov wrote:
>
> On Wed, 6 Dec 2023 at 00:25, Soeren Moch  wrote:
>
>> On 05.12.23 17:25, Maxim Uvarov wrote:
>>
>> On Tue, 5 Dec 2023 at 21:49, Soeren Moch  wrote:
>>
>>> On 05.12.23 14:15, Maxim Uvarov wrote:
>>>
>>> I think I solved the size issue on all the boards.
>>>
>>> Key changes:
>>> 1. remove compilation of original ping.c and tftp.c (tftp had also
>>> server code, so I will partially bring it back.)
>>>
>>> Interesting.
>>> @Tom: Is there other server code in u-boot, that is enabled by default
>>> (and can be used to reclaim code space)?
>>> Fur sure I do not need u-boot to act as server for tftp (maye nfs,
>>> others).
>>>
>>
>> Maybe I need to be more clear about this. reference to code from tftp.c
>> and ping.c exist in net.c, test/image/spl_load_net.c, test.dm/dsa.c,
>> test/dm/eth.c.
>> And even if that code is not used (replaced with lwip calls to the same
>> commands in my case) it adds additional size. Even enabled LTO does not see
>> direct difference.
>>
>> So 'server code' does not mean u-boot acting as network server, you mean
>> this code is referenced by something else? And things in test do increase
>> image size?
>>
> This was my question to understand possible options to save space.
>
>
>>
>>
>>> 2. LTO=y
>>> 3. CONFIG_LOGLEVEL=3 instead of 4.
>>> 4. CONFIG_CMD_DATE is not set
>>> 5. CONFIG_CMD_LICENSE is not set
>>> 6. CONFIG_CMD_PING (if 1-6 did not help).
>>>
>>> And these changes were enough for CI tagrets to build.
>>> I also tested that Raspberry PI 4B works fine (dhcp, ping). Looking for
>>> other boards to test.
>>>
>>> For example for this tbs2910 board changes are:
>>>
>>> Disabling CMD_DATE is unfortunate. This can help to debug RTC problems
>>> (already used it for this purpose).
>>> And, if we are that close to the size limit, than maybe we can get away
>>> for this series, but for sure will run into trouble for every other small
>>> change to u-boot core/driver code.
>>>
>>> Regards,
>>> Soeren
>>>
>>
>> The problem is that for many targets the limit is 1MB.
>>
>> For tbs2910 it is 383kBytes. And there was plenty of free space when I
>> introduced mainline u-boot support. But yes, space got tighter over time.
>>
>
> Hm,
> orig:
> -rw-r--r-- 1 uboot uboot 371K Dec  5 19:54 u-boot.bin
> lwip:
> -rw-r--r-- 1 uboot uboot 380K Dec  5 19:55 u-boot.bin
>
> Then if I just enable CMD_DATE:
> u-boot.imx exceeds file size limit:
>   limit:  0x5fc00 bytes
>   actual: 0x60c00 bytes
>   excess: 0x1000 bytes
> make: *** [Makefile:1240: u-boot.imx] Error 1
> make: *** Deleting file 'u-boot.imx'
> uboot@3eebd85985c8:~/uboot-size$ ls -lh u-boot.bin
> -rw-r--r-- 1 uboot uboot 382K Dec  5 19:58 u-boot.bin
>
> So limit for your board is:
> (gdb) p 0x5fc00/1024
> $1 = 383
>
> 383k. Where do you see the space?
>
> Here I do not understand what you want to ask.
>
> As I wrote earlier, yes, tbs2910 limit is 383k, for u-boot.imx, the number
> you tried to change in this patch to 408k, but this change is not possible.
>
> Without your changes there is some space left (not as much as 2014 when I
> introduced tbs2910 support in u-boot), but enough to make further u-boot
> development with unavoidable small image size increases possible. (size of
> v2024.01-rc4 u-boot.imx for tbs2910 is 375k).
>
> Regards,
> Soeren
>


Soeren, this patch which changes the limit will not be applied. I will send
another patch which modies defconfig and makes room for lwip stack.
If you want to keep CMD_DATE that is fine, probably we can disable EFI for
this board or something else.

BR,
Maxim.


>
> BR,
> Maxim.
>
>
>
>> U-Boot in some minimal configuration is about 500kb. But U-boot with EFI,
>> USB, Eth drivers,  MMC, RTC, and all the commands is 900+ kb and very close
>> to 1MB. Most of the new features are enabled by default.
>>
>> No. Tom does a very good job to ensure that there is no (not much)
>> additional space required for unrelated boards that do not need new
>> features.
>>
>> I.e. they do not exist in _defconfig and appear in the resulting .config
>> automatically.  I would say that for some small targets things like EFI,
>> Secure boot, TPM, Updates and many others are not needed. But if new
>> features will appear by de

Re: [PATHv11 26/43] configs/tbs2910_defconfig inc limit

2023-12-05 Thread Maxim Uvarov
On Wed, 6 Dec 2023 at 00:25, Soeren Moch  wrote:

>
>
> On 05.12.23 17:25, Maxim Uvarov wrote:
>
>
>
> On Tue, 5 Dec 2023 at 21:49, Soeren Moch  wrote:
>
>> On 05.12.23 14:15, Maxim Uvarov wrote:
>>
>> I think I solved the size issue on all the boards.
>>
>> Key changes:
>> 1. remove compilation of original ping.c and tftp.c (tftp had also server
>> code, so I will partially bring it back.)
>>
>> Interesting.
>> @Tom: Is there other server code in u-boot, that is enabled by default
>> (and can be used to reclaim code space)?
>> Fur sure I do not need u-boot to act as server for tftp (maye nfs,
>> others).
>>
>
> Maybe I need to be more clear about this. reference to code from tftp.c
> and ping.c exist in net.c, test/image/spl_load_net.c, test.dm/dsa.c,
> test/dm/eth.c.
> And even if that code is not used (replaced with lwip calls to the same
> commands in my case) it adds additional size. Even enabled LTO does not see
> direct difference.
>
> So 'server code' does not mean u-boot acting as network server, you mean
> this code is referenced by something else? And things in test do increase
> image size?
>
>
>
>
>> 2. LTO=y
>> 3. CONFIG_LOGLEVEL=3 instead of 4.
>> 4. CONFIG_CMD_DATE is not set
>> 5. CONFIG_CMD_LICENSE is not set
>> 6. CONFIG_CMD_PING (if 1-6 did not help).
>>
>> And these changes were enough for CI tagrets to build.
>> I also tested that Raspberry PI 4B works fine (dhcp, ping). Looking for
>> other boards to test.
>>
>> For example for this tbs2910 board changes are:
>>
>> Disabling CMD_DATE is unfortunate. This can help to debug RTC problems
>> (already used it for this purpose).
>> And, if we are that close to the size limit, than maybe we can get away
>> for this series, but for sure will run into trouble for every other small
>> change to u-boot core/driver code.
>>
>> Regards,
>> Soeren
>>
>
> The problem is that for many targets the limit is 1MB.
>
> For tbs2910 it is 383kBytes. And there was plenty of free space when I
> introduced mainline u-boot support. But yes, space got tighter over time.
>

Hm,
orig:
-rw-r--r-- 1 uboot uboot 371K Dec  5 19:54 u-boot.bin
lwip:
-rw-r--r-- 1 uboot uboot 380K Dec  5 19:55 u-boot.bin

Then if I just enable CMD_DATE:
u-boot.imx exceeds file size limit:
  limit:  0x5fc00 bytes
  actual: 0x60c00 bytes
  excess: 0x1000 bytes
make: *** [Makefile:1240: u-boot.imx] Error 1
make: *** Deleting file 'u-boot.imx'
uboot@3eebd85985c8:~/uboot-size$ ls -lh u-boot.bin
-rw-r--r-- 1 uboot uboot 382K Dec  5 19:58 u-boot.bin

So limit for your board is:
(gdb) p 0x5fc00/1024
$1 = 383

383k. Where do you see the space?

BR,
Maxim.



> U-Boot in some minimal configuration is about 500kb. But U-boot with EFI,
> USB, Eth drivers,  MMC, RTC, and all the commands is 900+ kb and very close
> to 1MB. Most of the new features are enabled by default.
>
> No. Tom does a very good job to ensure that there is no (not much)
> additional space required for unrelated boards that do not need new
> features.
>
> I.e. they do not exist in _defconfig and appear in the resulting .config
> automatically.  I would say that for some small targets things like EFI,
> Secure boot, TPM, Updates and many others are not needed. But if new
> features will appear by default very soon we will see limits.
>
> New features will not be enabled for old space constrained boards. In your
> series you did not offer to keep the old implementation instead, this is
> different and the reason why we discuss image size constraints.
>
> Regards,
> Soeren
>
>
> BR,
> Maxim.
>
>>
>> --- a/configs/tbs2910_defconfig
>> +++ b/configs/tbs2910_defconfig
>> @@ -18,6 +18,7 @@ CONFIG_SYS_MEMTEST_END=0x2f40
>>  CONFIG_LTO=y
>>  CONFIG_HAS_BOARD_SIZE_LIMIT=y
>>  CONFIG_BOARD_SIZE_LIMIT=392192
>> +CONFIG_TIMESTAMP=y (this was added by savedefconfig)
>>  # CONFIG_BOOTSTD is not set
>>  CONFIG_SUPPORT_RAW_INITRD=y
>>  CONFIG_BOOTDELAY=3
>> @@ -26,6 +27,7 @@ CONFIG_BOOTCOMMAND="mmc rescan; if run bootcmd_up1;
>> then run bootcmd_up2; else r
>>  CONFIG_USE_PREBOOT=y
>>  CONFIG_PREBOOT="echo PCI:; pci enum; pci 1; usb start"
>>  CONFIG_DEFAULT_FDT_FILE="imx6q-tbs2910.dtb"
>> +CONFIG_LOGLEVEL=3
>>  CONFIG_PRE_CONSOLE_BUFFER=y
>>  CONFIG_HUSH_PARSER=y
>>  CONFIG_SYS_PROMPT="Matrix U-Boot> "
>> @@ -52,7 +54,7 @@ CONFIG_CMD_DHCP=y
>>  CONFIG_CMD_MII=y
>>  CONFIG_CMD_PING=y
>>  CONFIG_CMD_CACHE=y
>> -CONFIG_CMD_TIME=y
>> +# CONFIG_CMD_DATE is not set
>>  

Re: [PATHv11 26/43] configs/tbs2910_defconfig inc limit

2023-12-05 Thread Maxim Uvarov
On Tue, 5 Dec 2023 at 21:49, Soeren Moch  wrote:

> On 05.12.23 14:15, Maxim Uvarov wrote:
>
> I think I solved the size issue on all the boards.
>
> Key changes:
> 1. remove compilation of original ping.c and tftp.c (tftp had also server
> code, so I will partially bring it back.)
>
> Interesting.
> @Tom: Is there other server code in u-boot, that is enabled by default
> (and can be used to reclaim code space)?
> Fur sure I do not need u-boot to act as server for tftp (maye nfs, others).
>

Maybe I need to be more clear about this. reference to code from tftp.c and
ping.c exist in net.c, test/image/spl_load_net.c, test.dm/dsa.c,
test/dm/eth.c.
And even if that code is not used (replaced with lwip calls to the same
commands in my case) it adds additional size. Even enabled LTO does not see
direct difference.



> 2. LTO=y
> 3. CONFIG_LOGLEVEL=3 instead of 4.
> 4. CONFIG_CMD_DATE is not set
> 5. CONFIG_CMD_LICENSE is not set
> 6. CONFIG_CMD_PING (if 1-6 did not help).
>
> And these changes were enough for CI tagrets to build.
> I also tested that Raspberry PI 4B works fine (dhcp, ping). Looking for
> other boards to test.
>
> For example for this tbs2910 board changes are:
>
> Disabling CMD_DATE is unfortunate. This can help to debug RTC problems
> (already used it for this purpose).
> And, if we are that close to the size limit, than maybe we can get away
> for this series, but for sure will run into trouble for every other small
> change to u-boot core/driver code.
>
> Regards,
> Soeren
>

The problem is that for many targets the limit is 1MB. U-Boot in some
minimal configuration is about 500kb. But U-boot with EFI, USB, Eth
drivers,  MMC, RTC, and all the commands is 900+ kb and very close to 1MB.
Most of the new features are enabled by default. I.e. they do not exist in
_defconfig and appear in the resulting .config automatically.  I would say
that for some small targets things like EFI, Secure boot, TPM, Updates and
many others are not needed. But if new features will appear by default very
soon we will see limits.

BR,
Maxim.

>
> --- a/configs/tbs2910_defconfig
> +++ b/configs/tbs2910_defconfig
> @@ -18,6 +18,7 @@ CONFIG_SYS_MEMTEST_END=0x2f40
>  CONFIG_LTO=y
>  CONFIG_HAS_BOARD_SIZE_LIMIT=y
>  CONFIG_BOARD_SIZE_LIMIT=392192
> +CONFIG_TIMESTAMP=y (this was added by savedefconfig)
>  # CONFIG_BOOTSTD is not set
>  CONFIG_SUPPORT_RAW_INITRD=y
>  CONFIG_BOOTDELAY=3
> @@ -26,6 +27,7 @@ CONFIG_BOOTCOMMAND="mmc rescan; if run bootcmd_up1; then
> run bootcmd_up2; else r
>  CONFIG_USE_PREBOOT=y
>  CONFIG_PREBOOT="echo PCI:; pci enum; pci 1; usb start"
>  CONFIG_DEFAULT_FDT_FILE="imx6q-tbs2910.dtb"
> +CONFIG_LOGLEVEL=3
>  CONFIG_PRE_CONSOLE_BUFFER=y
>  CONFIG_HUSH_PARSER=y
>  CONFIG_SYS_PROMPT="Matrix U-Boot> "
> @@ -52,7 +54,7 @@ CONFIG_CMD_DHCP=y
>  CONFIG_CMD_MII=y
>  CONFIG_CMD_PING=y
>  CONFIG_CMD_CACHE=y
> -CONFIG_CMD_TIME=y
> +# CONFIG_CMD_DATE is not set
>  CONFIG_CMD_SYSBOOT=y
>  # CONFIG_CMD_VIDCONSOLE is not set
>  CONFIG_CMD_EXT2=y
>
> BR,
> Maxim.
>
>
> On Tue, 28 Nov 2023 at 13:09, Maxim Uvarov 
> wrote:
>
>>
>>
>> On Tue, 28 Nov 2023 at 03:20, Soeren Moch  wrote:
>>
>>> On 27.11.23 14:11, Tom Rini wrote:
>>> > On Mon, Nov 27, 2023 at 06:57:09PM +0600, Maxim Uvarov wrote:
>>> >
>>> >> Increase allowed binary size to fit lwip code.
>>> >>
>>> >> Signed-off-by: Maxim Uvarov 
>>> >> ---
>>> >>   configs/tbs2910_defconfig | 2 +-
>>> >>   1 file changed, 1 insertion(+), 1 deletion(-)
>>> >>
>>> >> diff --git a/configs/tbs2910_defconfig b/configs/tbs2910_defconfig
>>> >> index 8fbe84f1d2..ce40efa9ab 100644
>>> >> --- a/configs/tbs2910_defconfig
>>> >> +++ b/configs/tbs2910_defconfig
>>> >> @@ -17,7 +17,7 @@ CONFIG_SYS_MEMTEST_START=0x1000
>>> >>   CONFIG_SYS_MEMTEST_END=0x2f40
>>> >>   CONFIG_LTO=y
>>> >>   CONFIG_HAS_BOARD_SIZE_LIMIT=y
>>> >> -CONFIG_BOARD_SIZE_LIMIT=392192
>>> >> +CONFIG_BOARD_SIZE_LIMIT=417792
>>> >>   # CONFIG_BOOTSTD is not set
>>> >>   CONFIG_SUPPORT_RAW_INITRD=y
>>> >>   CONFIG_BOOTDELAY=3
>>> > This is another case where the binary size is a fairly hard limit. You
>>> > forgot to cc the board maintainer here (and I assume the rest of the
>>> > series too) for these config changes.
>>> ThanksTom for sending a notification to me.
>>>
>>> Yes, the CONFIG_BOARD_SIZE_LIMIT is a hard limit and this patch in i

Re: [PATHv11 26/43] configs/tbs2910_defconfig inc limit

2023-12-05 Thread Maxim Uvarov
I think I solved the size issue on all the boards.

Key changes:
1. remove compilation of original ping.c and tftp.c (tftp had also server
code, so I will partially bring it back.)
2. LTO=y
3. CONFIG_LOGLEVEL=3 instead of 4.
4. CONFIG_CMD_DATE is not set
5. CONFIG_CMD_LICENSE is not set
6. CONFIG_CMD_PING (if 1-6 did not help).

And these changes were enough for CI tagrets to build.
I also tested that Raspberry PI 4B works fine (dhcp, ping). Looking for
other boards to test.

For example for this tbs2910 board changes are:

--- a/configs/tbs2910_defconfig
+++ b/configs/tbs2910_defconfig
@@ -18,6 +18,7 @@ CONFIG_SYS_MEMTEST_END=0x2f40
 CONFIG_LTO=y
 CONFIG_HAS_BOARD_SIZE_LIMIT=y
 CONFIG_BOARD_SIZE_LIMIT=392192
+CONFIG_TIMESTAMP=y (this was added by savedefconfig)
 # CONFIG_BOOTSTD is not set
 CONFIG_SUPPORT_RAW_INITRD=y
 CONFIG_BOOTDELAY=3
@@ -26,6 +27,7 @@ CONFIG_BOOTCOMMAND="mmc rescan; if run bootcmd_up1; then
run bootcmd_up2; else r
 CONFIG_USE_PREBOOT=y
 CONFIG_PREBOOT="echo PCI:; pci enum; pci 1; usb start"
 CONFIG_DEFAULT_FDT_FILE="imx6q-tbs2910.dtb"
+CONFIG_LOGLEVEL=3
 CONFIG_PRE_CONSOLE_BUFFER=y
 CONFIG_HUSH_PARSER=y
 CONFIG_SYS_PROMPT="Matrix U-Boot> "
@@ -52,7 +54,7 @@ CONFIG_CMD_DHCP=y
 CONFIG_CMD_MII=y
 CONFIG_CMD_PING=y
 CONFIG_CMD_CACHE=y
-CONFIG_CMD_TIME=y
+# CONFIG_CMD_DATE is not set
 CONFIG_CMD_SYSBOOT=y
 # CONFIG_CMD_VIDCONSOLE is not set
 CONFIG_CMD_EXT2=y

BR,
Maxim.


On Tue, 28 Nov 2023 at 13:09, Maxim Uvarov  wrote:

>
>
> On Tue, 28 Nov 2023 at 03:20, Soeren Moch  wrote:
>
>> On 27.11.23 14:11, Tom Rini wrote:
>> > On Mon, Nov 27, 2023 at 06:57:09PM +0600, Maxim Uvarov wrote:
>> >
>> >> Increase allowed binary size to fit lwip code.
>> >>
>> >> Signed-off-by: Maxim Uvarov 
>> >> ---
>> >>   configs/tbs2910_defconfig | 2 +-
>> >>   1 file changed, 1 insertion(+), 1 deletion(-)
>> >>
>> >> diff --git a/configs/tbs2910_defconfig b/configs/tbs2910_defconfig
>> >> index 8fbe84f1d2..ce40efa9ab 100644
>> >> --- a/configs/tbs2910_defconfig
>> >> +++ b/configs/tbs2910_defconfig
>> >> @@ -17,7 +17,7 @@ CONFIG_SYS_MEMTEST_START=0x1000
>> >>   CONFIG_SYS_MEMTEST_END=0x2f40
>> >>   CONFIG_LTO=y
>> >>   CONFIG_HAS_BOARD_SIZE_LIMIT=y
>> >> -CONFIG_BOARD_SIZE_LIMIT=392192
>> >> +CONFIG_BOARD_SIZE_LIMIT=417792
>> >>   # CONFIG_BOOTSTD is not set
>> >>   CONFIG_SUPPORT_RAW_INITRD=y
>> >>   CONFIG_BOOTDELAY=3
>> > This is another case where the binary size is a fairly hard limit. You
>> > forgot to cc the board maintainer here (and I assume the rest of the
>> > series too) for these config changes.
>> ThanksTom for sending a notification to me.
>>
>> Yes, the CONFIG_BOARD_SIZE_LIMIT is a hard limit and this patch in its
>> current form will break tbs2910 support and even brick the board for
>> some configurations. So NAK for this patch.
>> > I think on this platform it's not
>> > impossible (like it is on am335x where I just replied) but really
>> > difficult. I'll let Soeren comment on if switching the network stack to
>> > lwip is the kind of feature enhancement that warrants the pain of
>> > dealing with the size change here or not.
>> Network boot is no important feature for this board and not used in
>> the default boot configuration. But network support always was part
>> of the config, may be used by some users, and is at least required
>> to communicate the ethernet address to linux.
>>
>> So I'm not interested in a new network stack for this board, but
>> also cannot disable network support completely. This seems to be a
>> problem for this patch series, since networking support implies LWIP
>> now.
>>
>>
> Thanks Soeren for the explanation. Then yes, something more advanced is
> needed
> to be done here.
>
>
>
>> The question for me is, why is the new network stack consuming so
>> much space, with only a few enabled commands? Is the whole library
>> linked in with some unused features (the cover letter mentions much
>> more than what seems to be used in the converted commands). Or is
>> the old network stack linked in in parallel to the new one? Can
>> we save space here?
>>
>
> Yes, the old code is still there. I decided to not touch it for the first
> integration (arp.o, bootp.o, ping.o and
> mostly all from net/Makefile).  Those files also have reference code in
> net/net.c. Not compiling
> and not linking this code will save some space, but It's larger than the
> current version.
> Like for EVM SPL 

[PATHv1 9/9] Makefile: add dtbs to clean

2023-12-04 Thread Maxim Uvarov
CI test checks that generated dtb has to be cleaned up.

Signed-off-by: Maxim Uvarov 
---
 Makefile | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/Makefile b/Makefile
index 08604ed3c7..8dd6990584 100644
--- a/Makefile
+++ b/Makefile
@@ -2165,7 +2165,8 @@ CLEAN_FILES += include/autoconf.mk* include/bmp_logo.h 
include/bmp_logo_data.h \
   mkimage-out.spl.mkimage mkimage.spl.mkimage imx-boot.map \
   itb.fit.fit itb.fit.itb itb.map spl.map mkimage-out.rom.mkimage \
   mkimage.rom.mkimage mkimage-in-simple-bin* rom.map simple-bin* \
-  idbloader-spi.img lib/efi_loader/helloworld_efi.S *.itb
+  idbloader-spi.img lib/efi_loader/helloworld_efi.S *.itb \
+  ./*/*.dtb *.dtb
 
 # Directories & files removed with 'make mrproper'
 MRPROPER_DIRS  += include/config include/generated spl tpl vpl \
-- 
2.30.2



[PATHv1 8/9] omap3: rename mem_init

2023-12-04 Thread Maxim Uvarov
Rename mem_init to solve following compilation error with lwip
integrated code:
+arm-linux-gnueabi-ld.bfd: net/lwip/lwip-external/src/core/mem.o: in
  function `mem_init':
+net/lwip/lwip-external/src/core/mem.c:162: multiple definition
  of `mem_init';
  arch/arm/mach-omap2/omap3/sdrc.o:arch/arm/mach-omap2/omap3/
  sdrc.c:240: first defined here
+make[1]: *** [Makefile:1764: u-boot] Error 1
+/opt/gcc-13.1.0-nolibc/arm-linux-gnueabi/bin/../lib/gcc/arm-linux-
  gnueabi/13.1.0/../../
../../arm-linux-gnueabi/bin/ld: net/lwip/lwip-external/src/core/
  mem.o (symbol from
  plugin): in function `mem_init':
+(.text+0x0): multiple definition of `mem_init'; arch/arm/mach-omap2/
  omap3/emif4.o
  (symbol from plugin):(.text+0x0): first defined here
+collect2: error: ld returned 1 exit status
+(.text+0x0): multiple definition of `mem_init'; arch/arm/mach-omap2/
  omap3/sdrc.o
  (symbol from plugin):(.text+0x0): first defined here
+Image 'simple-bin' is missing external blobs and is non-functional:
   tee-os
+/binman/simple-bin/fit/images/op-tee/tee-os (tee-os):

Signed-off-by: Maxim Uvarov 
Reviewed-by: Tom Rini 
---
 arch/arm/include/asm/arch-omap3/mem.h | 2 +-
 arch/arm/mach-omap2/omap3/board.c | 2 +-
 arch/arm/mach-omap2/omap3/emif4.c | 4 ++--
 arch/arm/mach-omap2/omap3/sdrc.c  | 6 +++---
 4 files changed, 7 insertions(+), 7 deletions(-)

diff --git a/arch/arm/include/asm/arch-omap3/mem.h 
b/arch/arm/include/asm/arch-omap3/mem.h
index 569779c55e..fce3568eca 100644
--- a/arch/arm/include/asm/arch-omap3/mem.h
+++ b/arch/arm/include/asm/arch-omap3/mem.h
@@ -475,7 +475,7 @@ enum {
 #ifndef __ASSEMBLY__
 
 /* Function prototypes */
-void mem_init(void);
+void omap3_mem_init(void);
 
 u32 is_mem_sdr(void);
 u32 mem_ok(u32 cs);
diff --git a/arch/arm/mach-omap2/omap3/board.c 
b/arch/arm/mach-omap2/omap3/board.c
index 8b70251457..c76a95dd5d 100644
--- a/arch/arm/mach-omap2/omap3/board.c
+++ b/arch/arm/mach-omap2/omap3/board.c
@@ -216,7 +216,7 @@ void s_init(void)
 void board_init_f(ulong dummy)
 {
early_system_init();
-   mem_init();
+   omap3_mem_init();
/*
* Save the boot parameters passed from romcode.
* We cannot delay the saving further than this,
diff --git a/arch/arm/mach-omap2/omap3/emif4.c 
b/arch/arm/mach-omap2/omap3/emif4.c
index 7e5a281922..4fbfb387ab 100644
--- a/arch/arm/mach-omap2/omap3/emif4.c
+++ b/arch/arm/mach-omap2/omap3/emif4.c
@@ -159,10 +159,10 @@ int dram_init_banksize(void)
 }
 
 /*
- * mem_init() -
+ * omap3_mem_init() -
  *  - Initialize memory subsystem
  */
-void mem_init(void)
+void omap3_mem_init(void)
 {
do_emif4_init();
 }
diff --git a/arch/arm/mach-omap2/omap3/sdrc.c b/arch/arm/mach-omap2/omap3/sdrc.c
index 5d43e7c9cf..f2a0769b9d 100644
--- a/arch/arm/mach-omap2/omap3/sdrc.c
+++ b/arch/arm/mach-omap2/omap3/sdrc.c
@@ -4,7 +4,7 @@
  *
  * This file has been created after exctracting and consolidating
  * the SDRC related content from mem.c and board.c, also created
- * generic init function (mem_init).
+ * generic init function (omap3_mem_init).
  *
  * Copyright (C) 2004-2010
  * Texas Instruments Incorporated - https://www.ti.com/
@@ -232,11 +232,11 @@ int dram_init_banksize(void)
 }
 
 /*
- * mem_init -
+ * map3_mem_init -
  *  - Init the sdrc chip,
  *  - Selects CS0 and CS1,
  */
-void mem_init(void)
+void omap3_mem_init(void)
 {
/* only init up first bank here */
do_sdrc_init(CS0, EARLY_INIT);
-- 
2.30.2



[PATHv1 7/9] bcm_ns3: fix overlap define with lwip

2023-12-04 Thread Maxim Uvarov
Rename declaration to not overlap with lwip.

aarch64:  +   bcm_ns3
+In file included from net/lwip/lwip-external/src/include/lwip/etharp.h:53,
+ from net/lwip/lwip-external/src/core/init.c:55:
+net/lwip/lwip-external/src/include/lwip/prot/ethernet.h:69:
  error: "ETH_ADDR" redefined [-Werror]
+   69 | #define ETH_ADDR(b0, b1, b2, b3, b4, b5) {{b0, b1, b2, b3, b4, b5}}
+  |
+In file included from include/config.h:3,
+ from arch/arm/include/asm/string.h:4,
+ from include/linux/string.h:21,
+ from include/malloc.h:369,
+ from include/stdlib.h:9,
+ from net/lwip/lwip-external/src/include/lwip/arch.h:83,
+ from net/lwip/lwip-external/src/include/lwip/debug.h:40,
+ from net/lwip/lwipopts.h:93,
+ from net/lwip/lwip-external/src/include/lwip/opt.h:51,
+ from net/lwip/lwip-external/src/core/init.c:38:
+include/configs/bcm_ns3.h:52: note: this is the location of the previous 
definition
+   52 | #define ETH_ADDR

Signed-off-by: Maxim Uvarov 
Reviewed-by: Tom Rini 
---
 include/configs/bcm_ns3.h | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/include/configs/bcm_ns3.h b/include/configs/bcm_ns3.h
index 47de4bc201..7c6e0725a6 100644
--- a/include/configs/bcm_ns3.h
+++ b/include/configs/bcm_ns3.h
@@ -45,11 +45,11 @@
 #define PCIE_ARGS "pcie_args=pci=pcie_bus_safe pcie_ports=native 
vfio_pci.disable_idle_d3=1\0"
 
 #ifdef CONFIG_BCM_SF2_ETH
-#define ETH_ADDR "ethaddr=00:0A:F7:95:65:A4\0"
+#define BCM_ETH_ADDR "ethaddr=00:0A:F7:95:65:A4\0"
 #define NET_ARGS "bgmac_platform.ethaddr=${ethaddr} " \
"ip=${ipaddr}::${gatewayip}:${netmask}::${ethif}:off"
 #else
-#define ETH_ADDR
+#define BMC_ETH_ADDR
 #define NET_ARGS
 #endif
 
@@ -749,7 +749,7 @@
OS_LOG_LEVEL \
EXTRA_ARGS \
PCIE_ARGS \
-   ETH_ADDR \
+   BMC_ETH_ADDR \
RESERVED_MEM \
SETBOOTARGS \
UPDATEME_FLASH_PARAMS \
-- 
2.30.2



[PATHv1 6/9] mach-socfpga: do not overlap defines with lwip

2023-12-04 Thread Maxim Uvarov
Fix compilation issue with overlapping lwip and march defines.

Signed-off-by: Maxim Uvarov 
---
 arch/arm/mach-socfpga/include/mach/handoff_soc64.h | 6 --
 arch/arm/mach-socfpga/wrap_handoff_soc64.c | 9 +
 2 files changed, 9 insertions(+), 6 deletions(-)

diff --git a/arch/arm/mach-socfpga/include/mach/handoff_soc64.h 
b/arch/arm/mach-socfpga/include/mach/handoff_soc64.h
index 902fc6bfb5..9b85e5865b 100644
--- a/arch/arm/mach-socfpga/include/mach/handoff_soc64.h
+++ b/arch/arm/mach-socfpga/include/mach/handoff_soc64.h
@@ -78,12 +78,6 @@
 
 #ifndef __ASSEMBLY__
 #include 
-enum endianness {
-   LITTLE_ENDIAN = 0,
-   BIG_ENDIAN,
-   UNKNOWN_ENDIANNESS
-};
-
 int socfpga_get_handoff_size(void *handoff_address);
 int socfpga_handoff_read(void *handoff_address, void *table, u32 table_len);
 #endif
diff --git a/arch/arm/mach-socfpga/wrap_handoff_soc64.c 
b/arch/arm/mach-socfpga/wrap_handoff_soc64.c
index e7cb5ea89c..df0701ec85 100644
--- a/arch/arm/mach-socfpga/wrap_handoff_soc64.c
+++ b/arch/arm/mach-socfpga/wrap_handoff_soc64.c
@@ -10,6 +10,15 @@
 #include 
 #include "log.h"
 
+#ifndef __ASSEMBLY__
+#include 
+enum endianness {
+   LITTLE_ENDIAN = 0,
+   BIG_ENDIAN,
+   UNKNOWN_ENDIANNESS
+};
+#endif
+
 static enum endianness check_endianness(u32 handoff)
 {
switch (handoff) {
-- 
2.30.2



[PATHv1 5/9] driver/net/rtl8139: remove debug print

2023-12-04 Thread Maxim Uvarov
debug print delays reset of the driver. Finally I see
bunch of "rx error " errors in the screen. CI can
not handle many prints. While network works fine there

Reproduced with:
make CROSS_COMPILE=sh2-linux- r2dplus_defconfig all
qemu-system-sh4 -M r2d -nographic -serial null \
-serial mon:stdio -net user,tftp=`pwd` \
-net nic,model=rtl8139 -kernel ./u-boot.bin

Signed-off-by: Maxim Uvarov 
---
 drivers/net/rtl8139.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/net/rtl8139.c b/drivers/net/rtl8139.c
index 106bc1c7ae..d8f24ec81a 100644
--- a/drivers/net/rtl8139.c
+++ b/drivers/net/rtl8139.c
@@ -453,7 +453,7 @@ static int rtl8139_recv_common(struct rtl8139_priv *priv, 
unsigned char *rxdata,
  RTL_STS_RXBADALIGN)) ||
(rx_size < ETH_ZLEN) ||
(rx_size > ETH_FRAME_LEN + 4)) {
-   printf("rx error %hX\n", rx_status);
+   debug("rx error %hX\n", rx_status);
/* this clears all interrupts still pending */
rtl8139_reset(priv);
return 0;
-- 
2.30.2



[PATHv1 4/9] sandbox: eth-raw-os: successful return code is 0

2023-12-04 Thread Maxim Uvarov
all network drivers return 0 on the successful
transmission.

Signed-off-by: Maxim Uvarov 
Reviewed-by: Simon Glass 
---
 arch/sandbox/cpu/eth-raw-os.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/sandbox/cpu/eth-raw-os.c b/arch/sandbox/cpu/eth-raw-os.c
index e59b96be5f..92c35aed95 100644
--- a/arch/sandbox/cpu/eth-raw-os.c
+++ b/arch/sandbox/cpu/eth-raw-os.c
@@ -256,7 +256,7 @@ int sandbox_eth_raw_os_send(void *packet, int length,
   strerror(errno));
return -errno;
}
-   return retval;
+   return 0;
 }
 
 int sandbox_eth_raw_os_recv(void *packet, int *length,
-- 
2.30.2



[PATHv1 3/9] net/smc911x: fix return from smc911x_send

2023-12-04 Thread Maxim Uvarov
return value of smc911x_send is ignored, but on sucesseful
send we need return 0 and or error -ETIMEOUT, not opposite.

Signed-off-by: Maxim Uvarov 
Reviewed-by: Tom Rini 
---
 drivers/net/smc911x.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/net/smc911x.c b/drivers/net/smc911x.c
index 5c5ad8b84a..616b7ce174 100644
--- a/drivers/net/smc911x.c
+++ b/drivers/net/smc911x.c
@@ -403,7 +403,7 @@ static int smc911x_send(struct udevice *dev, void *packet, 
int length)
 
ret = smc911x_send_common(priv, packet, length);
 
-   return ret ? 0 : -ETIMEDOUT;
+   return ret ? -ETIMEDOUT : 0;
 }
 
 static int smc911x_recv(struct udevice *dev, int flags, uchar **packetp)
-- 
2.30.2



[PATHv1 2/9] net: sandbox: fix NULL pointer derefences

2023-12-04 Thread Maxim Uvarov
Add additional checks for NULL pointers.

Signed-off-by: Maxim Uvarov 
---
 drivers/net/sandbox.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/net/sandbox.c b/drivers/net/sandbox.c
index 13022addb6..d91935e032 100644
--- a/drivers/net/sandbox.c
+++ b/drivers/net/sandbox.c
@@ -65,6 +65,9 @@ int sandbox_eth_arp_req_to_reply(struct udevice *dev, void 
*packet,
struct ethernet_hdr *eth_recv;
struct arp_hdr *arp_recv;
 
+   if (!priv)
+   return -EAGAIN;
+
if (ntohs(eth->et_protlen) != PROT_ARP)
return -EAGAIN;
 
-- 
2.30.2



[PATHv1 1/9] test_net: print out net list

2023-12-04 Thread Maxim Uvarov
Printing net list is useful in CI log files.

Signed-off-by: Maxim Uvarov 
---
 test/py/tests/test_net.py | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/test/py/tests/test_net.py b/test/py/tests/test_net.py
index b2241ae6a4..cd5b791a6a 100644
--- a/test/py/tests/test_net.py
+++ b/test/py/tests/test_net.py
@@ -96,6 +96,8 @@ def test_net_pre_commands(u_boot_console):
 if init_pci:
 u_boot_console.run_command('pci enum')
 
+u_boot_console.run_command('net list')
+
 @pytest.mark.buildconfigspec('cmd_dhcp')
 def test_net_dhcp(u_boot_console):
 """Test the dhcp command.
-- 
2.30.2



[PATHv1 0/9] net fixes prior lwip

2023-12-04 Thread Maxim Uvarov
Add small net fixes prior lwip patch.

CI for this patch set:
https://dev.azure.com/u-boot/u-boot/_build/results?buildId=7460&view=results

Maxim Uvarov (9):
  test_net: print out net list
  net: sandbox: fix NULL pointer derefences
  net/smc911x: fix return from smc911x_send
  sandbox: eth-raw-os: successful return code is 0
  driver/net/rtl8139: remove debug print
  mach-socfpga: do not overlap defines with lwip
  bcm_ns3: fix overlap define with lwip
  omap3: rename mem_init
  Makefile: add dtbs to clean

 Makefile   | 3 ++-
 arch/arm/include/asm/arch-omap3/mem.h  | 2 +-
 arch/arm/mach-omap2/omap3/board.c  | 2 +-
 arch/arm/mach-omap2/omap3/emif4.c  | 4 ++--
 arch/arm/mach-omap2/omap3/sdrc.c   | 6 +++---
 arch/arm/mach-socfpga/include/mach/handoff_soc64.h | 6 --
 arch/arm/mach-socfpga/wrap_handoff_soc64.c | 9 +
 arch/sandbox/cpu/eth-raw-os.c  | 2 +-
 drivers/net/rtl8139.c  | 2 +-
 drivers/net/sandbox.c  | 3 +++
 drivers/net/smc911x.c  | 2 +-
 include/configs/bcm_ns3.h  | 6 +++---
 test/py/tests/test_net.py  | 2 ++
 13 files changed, 29 insertions(+), 20 deletions(-)

-- 
2.30.2



Re: [PATHv11 00/43] net/lwip: add lwip library for the network stack

2023-11-30 Thread Maxim Uvarov
On Thu, 30 Nov 2023 at 19:00, Fabio Estevam  wrote:

> Hi Maxim,
>
> On Thu, Nov 30, 2023 at 5:39 AM Maxim Uvarov 
> wrote:
>
> > If networking for some reason doesn't work on that board (I tested only
> virtual board). Please try to compile with:
>
> Could you also try on a real board?
>
> Tom tested on a Raspberry Pi3 and it failed too:
>
> https://lore.kernel.org/u-boot/20231127185953.GW2513409@bill-the-cat/
>
> > CONFIG_LWIP_LIB_DEBUG=y
> > #CONFIG_LWIP_LIB_NOASSERT is not set
> >
> > It should make network activity more verbose. In many cases I saw issues
> that physically MAC address do not match to lwip initialized value,
> > and lwip drops such packets.
>
> The ping response with:
>
> CONFIG_LWIP_LIB_DEBUG=y
>  #CONFIG_LWIP_LIB_NOASSERT is not set
>
> u-boot=> ping 192.168.0.16
> init already done for eth1
> Using eth1 device
> pinging addr: 192.168.0.16
> ping: send 192.168.0.16
> ip4_output_if: 0IP header:
> +---+
> | 4 | 5 |  0x00 |60 | (v, hl, tos, len)
> +---+
> |   40  |000|   0   | (id, flags, offset)
> +---+
> |  255  |1  |0x3994 | (ttl, proto, chksum)
> +---+
> |  192  |  168  |0  |  164  | (src)
> +---+
> |  192  |  168  |0  |   16  | (dest)
> +---+
> ip4_output_if: call netif->output()
> etharp_find_entry: found matching entry 0
> etharp_query: queued packet bdf03e70 on ARP entry 0
> ping_tmo: ping failed; host 192.168.0.16 is not alive
> u-boot=>
>

I will test that. smsc95xx_eth included in some CI tests and it worked. So
some differences on real hardware...
Log says that a ping packet was sent, but no packet on rx.
Might be the start function of  smsc95xx_eth called wrongly

BR,
Maxim.


Re: [PATHv11 00/43] net/lwip: add lwip library for the network stack

2023-11-30 Thread Maxim Uvarov
On Thu, 30 Nov 2023 at 17:09, Peter Robinson  wrote:

> Hi Maxim,
>
> > Please find updated version of lwip patches. Changes are in the
> > changelog bellow.
> >
> > Thank you,
> > Maxim.
> >
> > changelog:
> > v11: - v11 is mosly respin of v10 patches with CI error fixes.
> > Gitlab CI:
> >
> https://source.denx.de/u-boot/custodians/u-boot-tpm/-/pipelines/18368
> > Azure CI:
> >
> https://dev.azure.com/u-boot/u-boot/_build/results?buildId=7366&view=results
> > (Azure CI, which is connected to github. Sometime I can
> see
> >  tftp timeout after some part of download there, but
> that can not be
> >  reproduced locally. While Gitblab CI is stable. Because
> of num tries in
> >  CI I suspect this CI was not always reliable.)
> > Azure and Gitlab also have different toolchains and I
> > would say Gitlab generates bigger code then Azure CI.
> >
> > Also many boards have a binary limit size of 800k (even
> > qemu has limits). And increased limits to fit all the
> code. Specially did it
> > patch by board config to show which boards are failing
> to build. There I have
> > a question if we really want to support new
> functionality for old boards (mips,
> > arm32 and etc...). I hope board owners can help me if
> > it's valid to increase these limits.
> >
> > In this version I used git submodules and friend CI with
> > submodules. But I don't mind if you decide to maintain
> it in a different
> > way.
> >
> >
> > v10: - fix ping with following tftp command issue with incorrect
> > ping timeout clear.
> >  - Makefile on make will init submodules and if needed will
> >do git clone.
> >  - wget - some minor code style changes.
> > v9: - added first patch describing git submodule for lwip. So
> >   the build procedure is:
> > git submodule init
> > git submodule update
> > make
> > - reworked a little bit dhcp cmd state polling
> > - fixed review comments for v8
> > v8: - comments for previous review
> > - removed lwip timeout callback pointer
> > - made lwip timeouts works, that also allowed to remove
> >   static vars.
> > - setenv for filesize tftp and wget has to be in hex.
> > - Makefile changes always compile it tftp,dns,wget,ping due
> >   to it can be used not only by CONFIG_CMD_.
> > - Kconfig changes - simplify lwIP settings and support only
> >   one configuration.
> > - tested with mini debian.iso load over http or tftp, mount
> >   and boot it (qemu, arm64).
> > v7: - more review fixes.
> > - support of multiply eth devices, were "ethact" selects the
> >   active device.
> > v6: - fixed review comments for v5 (thanks Ilias and Simon).
> > v5: - fixed Iliases comments and split big patch on the small
> > ones.
> > v4: - tested with tests/py/ did some minor fixes (out of tree
> > build, variables set after downloads).
> >     - accounted review comments for documentation.
> > - implemented dns command
> > - corrected wget command to not use serverip variable and
> use just
> > url string.
> > v3: - use lwip commands for ping,tftp,wget,dhcp if this patch
> >   applied. Drop CONFIG_LIB_LWIP_REPLACE_ option.
> > - docs: use rst variant and drop references to RFC.
> >
> > Maxim Uvarov (43):
> >   submodule: add lwIP as git submodule
> >   net/lwip: add doc/develop/net_lwip.rst
> >   net/lwip: integrate lwIP library
> >   net/lwip: implement dns cmd
> >   net/lwip: implement dhcp cmd
> >   net/lwip: implement tftp cmd
> >   net/lwip: implement wget cmd
> >   net/lwip: implement ping cmd
> >   net/lwip: add lwIP configuration
> >   net/lwip: implement lwIP port to U-Boot
> >   net/lwip: update .gitignore with lwIP
> >   net/lwip: connection between cmd and lwip apps
> >   net/lwip: replace original net commands with lwip
> >   net

Re: [PATHv11 00/43] net/lwip: add lwip library for the network stack

2023-11-30 Thread Maxim Uvarov
On Wed, 29 Nov 2023 at 06:16, Fabio Estevam  wrote:

> Hi Tim,
>
> On Tue, Nov 28, 2023 at 9:10 PM Tim Harvey  wrote:
>
> > Fabio,
> >
> > You won't see this build issue with the entire series applied... only
> > with the patches up to and including 'net/lwip: integrate lwIP
> > library'. My point was there are points in the series where
> > compilation fails which is not ok.
>
> You are right and I agree with your point.
>
> I am able to reproduce the build failure at 'net/lwip: integrate lwIP
> library':
>
> In file included from net/lwip/lwip-external/src/core/init.c:38:
> ./net/lwip/lwip-external/src/include/lwip/opt.h:51:10: fatal error:
> lwipopts.h: No such file or directory
>51 | #include "lwipopts.h"
>   |  ^~~~
>
> Thanks
>

Ok, I will try to reorder patches.

If networking for some reason doesn't work on that board (I tested only
virtual board). Please try to compile with:
CONFIG_LWIP_LIB_DEBUG=y
#CONFIG_LWIP_LIB_NOASSERT is not set

It should make network activity more verbose. In many cases I saw issues
that physically MAC address do not match to lwip initialized value,
and lwip drops such packets.

BR,
Maxim.


Re: [PATHv11 07/43] net/lwip: implement wget cmd

2023-11-28 Thread Maxim Uvarov
Tim,

https://github.com/muvarov/u-boot/tree/master_lwip_test_v10
(branch master_lwip_test_v10)

Commit 8617b290e79e526119ccef0b0090cb220c78dd34
All later commits are experimental and I'm testing them in the CI.

And yes, this series has to apply to the current master without rejects.

BR,
Maxim.


On Wed, 29 Nov 2023 at 02:43, Tom Rini  wrote:

> On Tue, Nov 28, 2023 at 12:41:44PM -0800, Tim Harvey wrote:
> > On Tue, Nov 28, 2023 at 11:12 AM Fabio Estevam 
> wrote:
> > >
> > > Hi Maxim,
> > >
> > > On Tue, Nov 28, 2023 at 4:07 PM Maxim Uvarov 
> wrote:
> > >
> > > > From this log it's a little bit different wget output. My version
> prints "#"  for status. So I guess it's original wget. You can spend time
> on debugging it but this code will be replaced.
> > > > With my code I tried big iso download and check crc. I did not see
> any issues.
> > >
> > > Thanks for your feedback.
> > >
> > > I will test wget again after your series gets merged.
> > >
> >
> > Hi Maxim,
> >
> > Do you have a git repo that we can pull from to test for the wget
> failure?
>
> Note that "b4 am" for this series works currently on top of master, and
> getting more general testing on real hardware would be very nice.
>
> --
> Tom
>


Re: [PATHv11 00/43] net/lwip: add lwip library for the network stack

2023-11-28 Thread Maxim Uvarov
On Tue, 28 Nov 2023 at 16:37,  wrote:

> Hi,
>
> On 27/11/2023 13:56, Maxim Uvarov wrote:
> > Hello,
> >
> > Please find updated version of lwip patches. Changes are in the
> > changelog bellow.
>
> I've ran it on the libretech-cc board, and tried to load grub over tftp,
> and I got this strange EFI boot error:
>
> 
> U-Boot 2024.01-rc3-00056-g10d85cb3e3 (Nov 28 2023 - 11:17:24 +0100)
> libretech-cc
>
> Model: Libre Computer AML-S905X-CC
> SoC:   Amlogic Meson GXL (S905X) Revision 21:d (84:2)
> DRAM:  2 GiB
>
> 
>
> Net:   eth0: ethernet@c941
> Hit any key to stop autoboot:  0
> => setenv autoload no
> => dhcp
> ethernet@c941 LPA corruption - aneg restart
> ethernet@c941 Waiting for PHY auto negotiation to complete done
> Speed: 100, full duplex
> eth0: ethernet@c941 3e:a6:23:c0:39:4b active
> dhcp_tmo 20/20
> dhcp_tmo 19/20
> DHCP client bound to address 10.34.56.105
> => tftpboot 808 grubaa64.efi
> init already done for ethernet@c941
> Speed: 100, full duplex
> TFTP from server 10.34.56.1; our IP address is 10.34.56.105
> Filename 'grubaa64.efi'.
> Load address: 0x808
> Loading:
> done
> Bytes transferred = 4288512 (0x417000 hex)
> => crc32 808 0x417000
> crc32 for 0808 ... 08496fff ==> c79bc066
>
> 
>
> - DHCP OK,
> - transfer OK
> - CRC32 value OK
>
> but then trying to run the EFI binary:
>
> 
> => bootefi 808
> No EFI system partition
> No EFI system partition
> Failed to persist EFI variables
> No UEFI binary known at 808
>
> 
>
> This is what I get on the current master without this patchset:
>
> 
> U-Boot 2024.01-rc3-00013-gacae7eb5fe (Nov 28 2023 - 11:29:38 +0100)
> libretech-cc
>
> Model: Libre Computer AML-S905X-CC
> SoC:   Amlogic Meson GXL (S905X) Revision 21:d (84:2)
> DRAM:  2 GiB
>
> 
>
> Net:   eth0: ethernet@c941
> Hit any key to stop autoboot:  0
> => setenv autoload no
> => dhcp
> ethernet@c941 LPA corruption - aneg restart
> ethernet@c941 Waiting for PHY auto negotiation to complete done
> Speed: 100, full duplex
> BOOTP broadcast 1
> BOOTP broadcast 2
> BOOTP broadcast 3
> DHCP client bound to address 10.34.56.105 (1008 ms)
> => tftpboot 808 grubaa64.efi
> Speed: 100, full duplex
> Using ethernet@c941 device
> TFTP from server 10.34.56.1; our IP address is 10.34.56.105
> Filename 'grubaa64.efi'.
> Load address: 0x808
> Loading: ##T #T T
> ##
>  #
>  #
>  #
>  #
>  #
>  #
>  #
>  #
>  #
>  #
>  #
>  ##
>  199.2 KiB/s
> done
> Bytes transferred = 4288512 (417000 hex)
> => crc32 808 0x417000
> crc32 for 0808 ... 08496fff ==> c79bc066
> => bootefi 808
> No EFI system partition
> No EFI system partition
> Failed to persist EFI variables
> Booting /grubaa64.efi
> Welcome to GRUB!
>
> 
>
> grub> net_ls_addr
> efinet0 3e:a6:23:c0:39:4b 10.34.56.105
>
> 
>
> I don't see what's wrong, crc32 is good and env variables are the same:
> fileaddr=808
> filesize=417000
>
> Neil
>
>
Ok. You provided a small fix for this use case. Will take it into a new
version.



>
> >
> > Thank you,
> 

Re: [PATHv11 06/43] net/lwip: implement tftp cmd

2023-11-28 Thread Maxim Uvarov
On Tue, 28 Nov 2023 at 22:34,  wrote:

> Hi Maxim,
>
> On 27/11/2023 13:56, Maxim Uvarov wrote:
> > U-Boot recently got support for an alternative network stack using LWIP.
> > Replace tftp command with the LWIP variant while keeping the output and
> > error messages identical.
> >
> > Signed-off-by: Maxim Uvarov 
> > ---
> >   include/net/lwip.h |  13 
> >   net/lwip/Makefile  |   1 +
> >   net/lwip/apps/tftp/Makefile|   7 ++
> >   net/lwip/apps/tftp/lwip-tftp.c | 132 +
> >   4 files changed, 153 insertions(+)
> >   create mode 100644 net/lwip/apps/tftp/Makefile
> >   create mode 100644 net/lwip/apps/tftp/lwip-tftp.c
> >
>
> 
>
>
> With:
> ===><==
> diff --git a/net/lwip/apps/tftp/lwip-tftp.c
> b/net/lwip/apps/tftp/lwip-tftp.c
> index 7b384cecf8..1d1b7e8fa5 100644
> --- a/net/lwip/apps/tftp/lwip-tftp.c
> +++ b/net/lwip/apps/tftp/lwip-tftp.c
> @@ -8,6 +8,8 @@
>   #include 
>   #include 
>   #include 
> +#include 
> +#include 
>
>   #include "tftp_client.h"
>   #include "tftp_server.h"
> @@ -17,6 +19,7 @@
>
>   #include 
>
> +static char *filename;
>   static ulong daddr;
>   static ulong size;
>   static unsigned int progress_print;
> @@ -38,6 +41,12 @@ static void tftp_close(void *handle)
>  ulwip_exit(-1);
>  return;
>  }
> +
> +   if (IS_ENABLED(CONFIG_CMD_BOOTEFI))
> +   efi_set_bootdev("Net", "", filename,
> +   map_sysmem(daddr - size, 1),
> +   size);
> +
>  ulwip_exit(0);
>   }
>
> @@ -92,6 +101,7 @@ int ulwip_tftp(ulong addr, char *fname)
>
>  size = 0;
>  daddr = addr;
> +   filename = fname;
>  server_ip = env_get("serverip");
>  if (!server_ip) {
>  log_err("error: serverip variable has to be set\n");
> =><==
>
> Loading EFI works again, and you can drop patch 15.
>
> Neil
>

Thanks.


Re: [PATHv11 07/43] net/lwip: implement wget cmd

2023-11-28 Thread Maxim Uvarov
On Tue, 28 Nov 2023 at 17:32, Fabio Estevam  wrote:

> Hi Maxim,
>
> On Mon, Nov 27, 2023 at 5:46 PM Maxim Uvarov 
> wrote:
> >
> > U-Boot recently got support for an alternative network stack using LWIP.
> > Replace wget command with the LWIP variant while keeping the output and
> > error messages identical.
> >
> > Signed-off-by: Maxim Uvarov 
>
> Do you know whether this wget issue also happens when LWIP is used?
>
>
> https://lore.kernel.org/u-boot/caj+vnu2u9w2nrt6hf1caeq_56sdqviuezudd1iyopdf1cna...@mail.gmail.com/



>From this log it's a little bit different wget output. My version prints
"#"  for status. So I guess it's original wget. You can spend time on
debugging it but this code will be replaced.
With my code I tried big iso download and check crc. I did not see any
issues.

BR,
Maxim.


Re: [PATHv11 33/43] configs/am335x_evm_defconfig: inc SPL size

2023-11-28 Thread Maxim Uvarov
On Mon, 27 Nov 2023 at 22:31, Tom Rini  wrote:

> On Mon, Nov 27, 2023 at 03:52:50PM +, Peter Robinson wrote:
> > On Mon, Nov 27, 2023 at 3:32 PM Maxim Uvarov 
> wrote:
> > >
> > >
> > >
> > > On Mon, 27 Nov 2023 at 20:08, Tom Rini  wrote:
> > >>
> > >> On Mon, Nov 27, 2023 at 08:06:23PM +0600, Maxim Uvarov wrote:
> > >> > On Mon, 27 Nov 2023 at 19:08, Tom Rini  wrote:
> > >> >
> > >> > > On Mon, Nov 27, 2023 at 06:57:16PM +0600, Maxim Uvarov wrote:
> > >> > >
> > >> > > > Increase allowed binary size to fit lwip code.
> > >> > > >
> > >> > > > Signed-off-by: Maxim Uvarov 
> > >> > > > ---
> > >> > > >  configs/am335x_evm_defconfig | 1 +
> > >> > > >  1 file changed, 1 insertion(+)
> > >> > > >
> > >> > > > diff --git a/configs/am335x_evm_defconfig
> b/configs/am335x_evm_defconfig
> > >> > > > index f048e60f7f..9fd608bd76 100644
> > >> > > > --- a/configs/am335x_evm_defconfig
> > >> > > > +++ b/configs/am335x_evm_defconfig
> > >> > > > @@ -124,3 +124,4 @@ CONFIG_WDT=y
> > >> > > >  CONFIG_DYNAMIC_CRC_TABLE=y
> > >> > > >  CONFIG_RSA=y
> > >> > > >  CONFIG_LZO=y
> > >> > > > +CONFIG_SPL_MAX_SIZE=0x29000
> > >> > >
> > >> > > As probably a problem for other platforms you made this change on
> too,
> > >> > > you can't do this. The link limit is here because that's the
> limit the
> > >> > > hardware (and ROM) imposes.
> > >> > >
> > >> > > You might need to either:
> > >> > > - Figure out how to make lwip even tinier for the SPL case
> > >> > > - Limit the old network stack to just for SPL, and a later task
> is to
> > >> > >   reduce what's in the old stack to just what's also needed
> within SPL.
> > >> > >
> > >> > >
> > >> > Thanks Tom. All these size changes need to be reviewed.  Some of
> them are
> > >> > ok, I think like for x86 or qemu virt, but some of them might not
> work.
> > >> >
> > >> > Question - Do we need networking inside SPL rather than in the main
> binary?
> > >> > Is it a real use case?
> > >>
> > >> Yes, the device supports loading SPL, and then SPL loading U-Boot both
> > >> over USB RNDIS as well as regular physical ethernet.
> > >>
> > >> --
> > >> Tom
> > >
> > >
> > > That looks like not a production use case. USB + NET + drivers + EXT4
> + NAND + MTD and everything else and trying to fit into SPL.
> > > With enabling LTO I still need 4k (without dropping current code).
> From one point it's too synthetic use case here and might be a historical
> > > limitation which we will not see on future boards. From the other
> point it will be good to not break it somehow
> >
> > Does this still include the old network code?
> >
> > Also I wonder if we can have a paired down SPL_LWIP option that
> > removes things like PXE and HTTP/wget because none of those would be
> > used in the SPL use case as they're all brand new.
>
> To be clear, I am fine with either "old network stack only for SPL" or
> "figure out how to pair down lwip to just SPL features". In fact having
> said that, the first thing I would suggest is to turn off LTO as it
> makes reading the linker map file harder, increase the size limit for
> this platform, and take a look at what's being linked in and not
> discarded in SPL, for networking, in spl/u-boot-spl.map. Maybe the
> answer is that we just need to be more careful about using
> IS_ENABLED/CONFIG_IS_ENABLED (and obj-$(CONFIG_$(SPL_)FOO)) in the lwip
> series.
>
> --
> Tom
>

Yea. If I disable TCP then we get the right size for this board. So for SPL
I think to build without TCP so that ping, dhcp and tftp will still work.
For normal binary TCP will be enabled. For other boards with limits I think
also to disable TCP for now.

BR,
Maxim.


Re: [PATHv11 26/43] configs/tbs2910_defconfig inc limit

2023-11-27 Thread Maxim Uvarov
On Tue, 28 Nov 2023 at 03:20, Soeren Moch  wrote:

> On 27.11.23 14:11, Tom Rini wrote:
> > On Mon, Nov 27, 2023 at 06:57:09PM +0600, Maxim Uvarov wrote:
> >
> >> Increase allowed binary size to fit lwip code.
> >>
> >> Signed-off-by: Maxim Uvarov 
> >> ---
> >>   configs/tbs2910_defconfig | 2 +-
> >>   1 file changed, 1 insertion(+), 1 deletion(-)
> >>
> >> diff --git a/configs/tbs2910_defconfig b/configs/tbs2910_defconfig
> >> index 8fbe84f1d2..ce40efa9ab 100644
> >> --- a/configs/tbs2910_defconfig
> >> +++ b/configs/tbs2910_defconfig
> >> @@ -17,7 +17,7 @@ CONFIG_SYS_MEMTEST_START=0x1000
> >>   CONFIG_SYS_MEMTEST_END=0x2f40
> >>   CONFIG_LTO=y
> >>   CONFIG_HAS_BOARD_SIZE_LIMIT=y
> >> -CONFIG_BOARD_SIZE_LIMIT=392192
> >> +CONFIG_BOARD_SIZE_LIMIT=417792
> >>   # CONFIG_BOOTSTD is not set
> >>   CONFIG_SUPPORT_RAW_INITRD=y
> >>   CONFIG_BOOTDELAY=3
> > This is another case where the binary size is a fairly hard limit. You
> > forgot to cc the board maintainer here (and I assume the rest of the
> > series too) for these config changes.
> ThanksTom for sending a notification to me.
>
> Yes, the CONFIG_BOARD_SIZE_LIMIT is a hard limit and this patch in its
> current form will break tbs2910 support and even brick the board for
> some configurations. So NAK for this patch.
> > I think on this platform it's not
> > impossible (like it is on am335x where I just replied) but really
> > difficult. I'll let Soeren comment on if switching the network stack to
> > lwip is the kind of feature enhancement that warrants the pain of
> > dealing with the size change here or not.
> Network boot is no important feature for this board and not used in
> the default boot configuration. But network support always was part
> of the config, may be used by some users, and is at least required
> to communicate the ethernet address to linux.
>
> So I'm not interested in a new network stack for this board, but
> also cannot disable network support completely. This seems to be a
> problem for this patch series, since networking support implies LWIP
> now.
>
>
Thanks Soeren for the explanation. Then yes, something more advanced is
needed
to be done here.



> The question for me is, why is the new network stack consuming so
> much space, with only a few enabled commands? Is the whole library
> linked in with some unused features (the cover letter mentions much
> more than what seems to be used in the converted commands). Or is
> the old network stack linked in in parallel to the new one? Can
> we save space here?
>

Yes, the old code is still there. I decided to not touch it for the first
integration (arp.o, bootp.o, ping.o and
mostly all from net/Makefile).  Those files also have reference code in
net/net.c. Not compiling
and not linking this code will save some space, but It's larger than the
current version.
Like for EVM SPL code with usb+net+ext4 and etc have very minimal space for
network stack.
I will take a look at this more closely...


>
> NFS support in the old networking code is quite big, enabled by default,
> and probably still there in parallel to this new lwip library. If there
> is really no other option to save space, and lwip in general is agreed
> to be the way forward for U-Boot, and only tbs2910 is blocking that,
> then from my point of view disabling NFS for tbs2910 could be a way
> to stay within the size limit.
>
> ok. I think that by default we need something very minimal (dhcp, tftp),
probably ping is even not needed.



> Regards,
> Soeren
>
>


Re: [PATHv11 33/43] configs/am335x_evm_defconfig: inc SPL size

2023-11-27 Thread Maxim Uvarov
On Mon, 27 Nov 2023 at 20:08, Tom Rini  wrote:

> On Mon, Nov 27, 2023 at 08:06:23PM +0600, Maxim Uvarov wrote:
> > On Mon, 27 Nov 2023 at 19:08, Tom Rini  wrote:
> >
> > > On Mon, Nov 27, 2023 at 06:57:16PM +0600, Maxim Uvarov wrote:
> > >
> > > > Increase allowed binary size to fit lwip code.
> > > >
> > > > Signed-off-by: Maxim Uvarov 
> > > > ---
> > > >  configs/am335x_evm_defconfig | 1 +
> > > >  1 file changed, 1 insertion(+)
> > > >
> > > > diff --git a/configs/am335x_evm_defconfig
> b/configs/am335x_evm_defconfig
> > > > index f048e60f7f..9fd608bd76 100644
> > > > --- a/configs/am335x_evm_defconfig
> > > > +++ b/configs/am335x_evm_defconfig
> > > > @@ -124,3 +124,4 @@ CONFIG_WDT=y
> > > >  CONFIG_DYNAMIC_CRC_TABLE=y
> > > >  CONFIG_RSA=y
> > > >  CONFIG_LZO=y
> > > > +CONFIG_SPL_MAX_SIZE=0x29000
> > >
> > > As probably a problem for other platforms you made this change on too,
> > > you can't do this. The link limit is here because that's the limit the
> > > hardware (and ROM) imposes.
> > >
> > > You might need to either:
> > > - Figure out how to make lwip even tinier for the SPL case
> > > - Limit the old network stack to just for SPL, and a later task is to
> > >   reduce what's in the old stack to just what's also needed within SPL.
> > >
> > >
> > Thanks Tom. All these size changes need to be reviewed.  Some of them are
> > ok, I think like for x86 or qemu virt, but some of them might not work.
> >
> > Question - Do we need networking inside SPL rather than in the main
> binary?
> > Is it a real use case?
>
> Yes, the device supports loading SPL, and then SPL loading U-Boot both
> over USB RNDIS as well as regular physical ethernet.
>
> --
> Tom
>

That looks like not a production use case. USB + NET + drivers + EXT4 +
NAND + MTD and everything else and trying to fit into SPL.
With enabling LTO I still need 4k (without dropping current code). From one
point it's too synthetic use case here and might be a historical
limitation which we will not see on future boards. From the other point it
will be good to not break it somehow

BR,
Maxim.


Re: [PATHv11 33/43] configs/am335x_evm_defconfig: inc SPL size

2023-11-27 Thread Maxim Uvarov
On Mon, 27 Nov 2023 at 19:08, Tom Rini  wrote:

> On Mon, Nov 27, 2023 at 06:57:16PM +0600, Maxim Uvarov wrote:
>
> > Increase allowed binary size to fit lwip code.
> >
> > Signed-off-by: Maxim Uvarov 
> > ---
> >  configs/am335x_evm_defconfig | 1 +
> >  1 file changed, 1 insertion(+)
> >
> > diff --git a/configs/am335x_evm_defconfig b/configs/am335x_evm_defconfig
> > index f048e60f7f..9fd608bd76 100644
> > --- a/configs/am335x_evm_defconfig
> > +++ b/configs/am335x_evm_defconfig
> > @@ -124,3 +124,4 @@ CONFIG_WDT=y
> >  CONFIG_DYNAMIC_CRC_TABLE=y
> >  CONFIG_RSA=y
> >  CONFIG_LZO=y
> > +CONFIG_SPL_MAX_SIZE=0x29000
>
> As probably a problem for other platforms you made this change on too,
> you can't do this. The link limit is here because that's the limit the
> hardware (and ROM) imposes.
>
> You might need to either:
> - Figure out how to make lwip even tinier for the SPL case
> - Limit the old network stack to just for SPL, and a later task is to
>   reduce what's in the old stack to just what's also needed within SPL.
>
>
Thanks Tom. All these size changes need to be reviewed.  Some of them are
ok, I think like for x86 or qemu virt, but some of them might not work.

Question - Do we need networking inside SPL rather than in the main binary?
Is it a real use case?

BR,
Maxim.


> --
> Tom
>


[PATHv11 43/43] .gitlab-ci.yml: change ownership of the git files

2023-11-27 Thread Maxim Uvarov
Inside docker image owner of U-Boot files
is different, so user doesn't have permissions to update
submodules. Make the ower of git the same as current user.

Signed-off-by: Maxim Uvarov 
---
 .gitlab-ci.yml | 15 ++-
 1 file changed, 10 insertions(+), 5 deletions(-)

diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index fee165198a..cb4f00e978 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -104,7 +104,8 @@ build all 32bit ARM platforms:
   extends: .world_build
   script:
 - ret=0;
-  git config --global --add safe.directory "${CI_PROJECT_DIR}";
+  git clone `pwd` /tmp/u-boot.git;
+  cd /tmp/u-boot.git;
   pip install -r tools/buildman/requirements.txt;
   ./tools/buildman/buildman -o /tmp -PEWM arm -x aarch64 || ret=$?;
   if [[ $ret -ne 0 ]]; then
@@ -118,7 +119,8 @@ build all 64bit ARM platforms:
 - virtualenv -p /usr/bin/python3 /tmp/venv
 - . /tmp/venv/bin/activate
 - ret=0;
-  git config --global --add safe.directory "${CI_PROJECT_DIR}";
+  git clone `pwd` /tmp/u-boot.git;
+  cd /tmp/u-boot.git;
   pip install -r tools/buildman/requirements.txt;
   ./tools/buildman/buildman -o /tmp -PEWM aarch64 || ret=$?;
   if [[ $ret -ne 0 ]]; then
@@ -130,7 +132,8 @@ build all PowerPC platforms:
   extends: .world_build
   script:
 - ret=0;
-  git config --global --add safe.directory "${CI_PROJECT_DIR}";
+  git clone `pwd` /tmp/u-boot.git;
+  cd /tmp/u-boot.git;
   ./tools/buildman/buildman -o /tmp -P -E -W powerpc || ret=$?;
   if [[ $ret -ne 0 ]]; then
 ./tools/buildman/buildman -o /tmp -seP;
@@ -141,7 +144,8 @@ build all other platforms:
   extends: .world_build
   script:
 - ret=0;
-  git config --global --add safe.directory "${CI_PROJECT_DIR}";
+  git clone `pwd` /tmp/u-boot.git;
+  cd /tmp/u-boot.git;
   ./tools/buildman/buildman -o /tmp -PEWM -x arm,powerpc || ret=$?;
   if [[ $ret -ne 0 ]]; then
 ./tools/buildman/buildman -o /tmp -seP;
@@ -192,7 +196,8 @@ Run binman, buildman, dtoc, Kconfig and patman testsuites:
   script:
 - git config --global user.name "GitLab CI Runner";
   git config --global user.email tr...@konsulko.com;
-  git config --global --add safe.directory "${CI_PROJECT_DIR}";
+  git clone `pwd` /tmp/u-boot.git;
+  cd /tmp/u-boot.git;
   export USER=gitlab;
   virtualenv -p /usr/bin/python3 /tmp/venv;
   . /tmp/venv/bin/activate;
-- 
2.30.2



[PATHv11 42/43] configs/linkit-smart-7688_defconfig: increase board limit

2023-11-27 Thread Maxim Uvarov
Increase current board limit to fit new IP stack.
mips:  +   linkit-smart-7688
+u-boot.img exceeds file size limit:
+  limit:  0x87000 bytes
+  actual: 0x87184 bytes
+  excess: 0x184 bytes

Signed-off-by: Maxim Uvarov 
---
 configs/linkit-smart-7688_defconfig | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/configs/linkit-smart-7688_defconfig 
b/configs/linkit-smart-7688_defconfig
index d31f1ab3e0..1b24a70b67 100644
--- a/configs/linkit-smart-7688_defconfig
+++ b/configs/linkit-smart-7688_defconfig
@@ -22,7 +22,7 @@ CONFIG_RESTORE_EXCEPTION_VECTOR_BASE=y
 # CONFIG_MIPS_BOOT_ENV_LEGACY is not set
 CONFIG_MIPS_BOOT_FDT=y
 CONFIG_HAS_BOARD_SIZE_LIMIT=y
-CONFIG_BOARD_SIZE_LIMIT=552960
+CONFIG_BOARD_SIZE_LIMIT=553472
 CONFIG_FIT=y
 CONFIG_FIT_SIGNATURE=y
 CONFIG_LEGACY_IMAGE_FORMAT=y
-- 
2.30.2



[PATHv11 41/43] mach-mtmips: inc SPL size limit

2023-11-27 Thread Maxim Uvarov
Increase board limit on 0x200 to fit new IP stack.

Signed-off-by: Maxim Uvarov 
---
 arch/mips/mach-mtmips/Kconfig | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/mips/mach-mtmips/Kconfig b/arch/mips/mach-mtmips/Kconfig
index 15b2792e61..2f07e3a491 100644
--- a/arch/mips/mach-mtmips/Kconfig
+++ b/arch/mips/mach-mtmips/Kconfig
@@ -37,7 +37,7 @@ config SPL_TEXT_BASE
default 0x8010 if SOC_MT7621
 
 config SPL_SIZE_LIMIT
-   default 0x3 if SOC_MT7621
+   default 0x30200 if SOC_MT7621
 
 config TPL_TEXT_BASE
default 0xbfc0 if SOC_MT7621
-- 
2.30.2



[PATHv11 40/43] .azure-pipelines: init submodules

2023-11-27 Thread Maxim Uvarov
Azure CI does make testconfig then passes U-Boot sources
to docker image. Inside docker image owner of U-Boot files
is different, so user doesn't have permissions to update
submodules. In this case we can do init before we run
test docker image.

Signed-off-by: Maxim Uvarov 
---
 .azure-pipelines.yml | 10 --
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/.azure-pipelines.yml b/.azure-pipelines.yml
index d6f3fa423c..b6fa843e8c 100644
--- a/.azure-pipelines.yml
+++ b/.azure-pipelines.yml
@@ -113,6 +113,7 @@ stages:
 steps:
   - script: |
   cat << "EOF" > build.sh
+  set -x
   cd $(work_dir)
   git config --global user.name "Azure Pipelines"
   git config --global user.email bmeng...@gmail.com
@@ -134,6 +135,7 @@ stages:
   make O=${UBOOT_TRAVIS_BUILD_DIR} testconfig
   EOF
   cat build.sh
+  make initsubmodules
   # We cannot use "container" like other jobs above, as buildman
   # seems to hang forever with pre-configured "container" environment
   docker run -v $PWD:$(work_dir) $(ci_runner_image) /bin/bash 
$(work_dir)/build.sh
@@ -196,7 +198,9 @@ stages:
   set -ex
   # the below corresponds to .gitlab-ci.yml "before_script"
   cd \${WORK_DIR}
-  git config --global --add safe.directory \${WORK_DIR}
+  git clone \${WORK_DIR} /tmp/u-boot.git
+  WORK_DIR="/tmp/u-boot.git"
+  cd \${WORK_DIR}
   git clone --depth=1 https://source.denx.de/u-boot/u-boot-test-hooks 
/tmp/uboot-test-hooks
   ln -s travis-ci /tmp/uboot-test-hooks/bin/\`hostname\`
   ln -s travis-ci /tmp/uboot-test-hooks/py/\`hostname\`
@@ -506,7 +510,9 @@ stages:
   cd ${WORK_DIR}
   # make environment variables available as tests are running inside a 
container
   export BUILDMAN="${BUILDMAN}"
-  git config --global --add safe.directory ${WORK_DIR}
+  git clone ${WORK_DIR} /tmp/u-boot.git
+  WORK_DIR="/tmp/u-boot.git"
+  cd \${WORK_DIR}
   pip install -r tools/buildman/requirements.txt
   EOF
   cat << "EOF" >> build.sh
-- 
2.30.2



[PATHv11 39/43] Makefile: add dtbs to clean

2023-11-27 Thread Maxim Uvarov
CI test checks that generated dtb has to be cleaned up.

Signed-off-by: Maxim Uvarov 
---
 Makefile | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/Makefile b/Makefile
index 769111bf09..2fc04450c6 100644
--- a/Makefile
+++ b/Makefile
@@ -2172,7 +2172,8 @@ CLEAN_FILES += include/autoconf.mk* include/bmp_logo.h 
include/bmp_logo_data.h \
   itb.fit.fit itb.fit.itb itb.map spl.map mkimage-out.rom.mkimage \
   mkimage.rom.mkimage mkimage-in-simple-bin* rom.map simple-bin* \
   idbloader-spi.img lib/efi_loader/helloworld_efi.S *.itb \
-  net/lwip/apps/ping/ping.c
+  net/lwip/apps/ping/ping.c \
+  ./*/*.dtb *.dtb
 
 # Directories & files removed with 'make mrproper'
 MRPROPER_DIRS  += include/config include/generated spl tpl vpl \
-- 
2.30.2



[PATHv11 38/43] configs/qemu-x86_64_defconfig: increase ROM size

2023-11-27 Thread Maxim Uvarov
When lwIP compiled with debug info enabled U-Boot size
overlaps with SPL. Make more room for it.
binman: Node '/binman/rom/u-boot-spl-with-ucode-ptr':
Offset 0xfffd8000 (4294803456) overlaps with previous
entry '/binman/rom/u-boot-dtb' ending at 0xfffd8a40 (4294806080)

ImagePosOffset  Size  Name
  0010  rom
 fff0  000e0a58  u-boot →  0xfffe0a58
    000dff10  u-boot-nodtb
  000dff10  0b48  u-boot-dtb
 fffdb000  00016020  u-boot-spl-with-ucode-ptr CONFIG_X86_OFFSET_SPL

In general compilation issue can be solved with changing CONFIG_X86_OFFSET_SPL
to 0xfffe1000 from default 0xfffd8000 and all the code fits to 1MB rom
image. But with modified CONFIG_X86_OFFSET_SPL qemu process does not
boot. That is under investigation now.

Signed-off-by: Maxim Uvarov 
---
 configs/qemu-x86_64_defconfig | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/configs/qemu-x86_64_defconfig b/configs/qemu-x86_64_defconfig
index 2ff49fbd6a..88eeb6622a 100644
--- a/configs/qemu-x86_64_defconfig
+++ b/configs/qemu-x86_64_defconfig
@@ -6,18 +6,19 @@ CONFIG_ENV_SIZE=0x4
 CONFIG_MAX_CPUS=2
 CONFIG_SPL_DM_SPI=y
 CONFIG_DEFAULT_DEVICE_TREE="qemu-x86_i440fx"
-CONFIG_SPL_TEXT_BASE=0xfffd8000
+CONFIG_SPL_TEXT_BASE=0xfffdb000
 CONFIG_SPL_SYS_MALLOC_F_LEN=0x2000
 CONFIG_DEBUG_UART_BASE=0x3f8
 CONFIG_DEBUG_UART_CLOCK=1843200
 CONFIG_X86_RUN_64BIT=y
 CONFIG_TARGET_QEMU_X86_64=y
 CONFIG_DEBUG_UART=y
+CONFIG_UBOOT_ROMSIZE_KB_4096=y
 # CONFIG_HAVE_MICROCODE is not set
 CONFIG_SMP=y
 CONFIG_GENERATE_PIRQ_TABLE=y
 CONFIG_GENERATE_MP_TABLE=y
-CONFIG_X86_OFFSET_U_BOOT=0xfff0
+CONFIG_X86_OFFSET_U_BOOT=0xffc0
 CONFIG_SYS_MONITOR_BASE=0x0111
 CONFIG_FIT=y
 CONFIG_SPL_LOAD_FIT=y
-- 
2.30.2



[PATHv11 37/43] configs/rcar3_ulcb_defconfig: increase size

2023-11-27 Thread Maxim Uvarov
Increase allowed binary size to fit lwip code.
u-boot.img exceeds file size limit:
  limit:  0x10 bytes
  actual: 0x106c41 bytes
  excess: 0x6c41 bytes

Signed-off-by: Maxim Uvarov 
---
 configs/rcar3_ulcb_defconfig | 1 +
 1 file changed, 1 insertion(+)

diff --git a/configs/rcar3_ulcb_defconfig b/configs/rcar3_ulcb_defconfig
index acbc3147ce..9c3ecf40c6 100644
--- a/configs/rcar3_ulcb_defconfig
+++ b/configs/rcar3_ulcb_defconfig
@@ -112,3 +112,4 @@ CONFIG_USB_XHCI_HCD=y
 CONFIG_USB_EHCI_HCD=y
 CONFIG_USB_EHCI_GENERIC=y
 CONFIG_USB_STORAGE=y
+CONFIG_BOARD_SIZE_LIMIT=1081344
-- 
2.30.2



[PATHv11 36/43] configs/gardena-smart-gateway-mt7688_defconfig: increase size

2023-11-27 Thread Maxim Uvarov
Increase allowed binary size to fit lwip code.
  limit:  0xa bytes
  actual: 0xa0f54 bytes
  excess: 0xf54 bytes

Signed-off-by: Maxim Uvarov 
---
 configs/gardena-smart-gateway-mt7688_defconfig | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/configs/gardena-smart-gateway-mt7688_defconfig 
b/configs/gardena-smart-gateway-mt7688_defconfig
index bedc596910..4a26e6bbe0 100644
--- a/configs/gardena-smart-gateway-mt7688_defconfig
+++ b/configs/gardena-smart-gateway-mt7688_defconfig
@@ -25,7 +25,7 @@ CONFIG_RESTORE_EXCEPTION_VECTOR_BASE=y
 CONFIG_MIPS_BOOT_FDT=y
 CONFIG_ENV_VARS_UBOOT_CONFIG=y
 CONFIG_HAS_BOARD_SIZE_LIMIT=y
-CONFIG_BOARD_SIZE_LIMIT=655360
+CONFIG_BOARD_SIZE_LIMIT=720896
 CONFIG_FIT=y
 CONFIG_FIT_SIGNATURE=y
 CONFIG_LEGACY_IMAGE_FORMAT=y
-- 
2.30.2



[PATHv11 35/43] configs/linkit-smart-7688_defconfig: increse size

2023-11-27 Thread Maxim Uvarov
Increase allowed binary size to fit lwip code.
  limit:  0x8 bytes
  actual: 0x84c58 bytes
  excess: 0x4c58 bytes

Signed-off-by: Maxim Uvarov 
---
 configs/linkit-smart-7688_defconfig | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/configs/linkit-smart-7688_defconfig 
b/configs/linkit-smart-7688_defconfig
index 0bdb4e612c..d31f1ab3e0 100644
--- a/configs/linkit-smart-7688_defconfig
+++ b/configs/linkit-smart-7688_defconfig
@@ -22,7 +22,7 @@ CONFIG_RESTORE_EXCEPTION_VECTOR_BASE=y
 # CONFIG_MIPS_BOOT_ENV_LEGACY is not set
 CONFIG_MIPS_BOOT_FDT=y
 CONFIG_HAS_BOARD_SIZE_LIMIT=y
-CONFIG_BOARD_SIZE_LIMIT=524288
+CONFIG_BOARD_SIZE_LIMIT=552960
 CONFIG_FIT=y
 CONFIG_FIT_SIGNATURE=y
 CONFIG_LEGACY_IMAGE_FORMAT=y
-- 
2.30.2



[PATHv11 34/43] configs/bk4r1_defconfig: inc size

2023-11-27 Thread Maxim Uvarov
Increase allowed binary size to fit lwip code.

Signed-off-by: Maxim Uvarov 
---
 configs/bk4r1_defconfig | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/configs/bk4r1_defconfig b/configs/bk4r1_defconfig
index 95f0c30cde..30ab54a849 100644
--- a/configs/bk4r1_defconfig
+++ b/configs/bk4r1_defconfig
@@ -20,7 +20,7 @@ CONFIG_SYS_MEMTEST_START=0x8001
 CONFIG_SYS_MEMTEST_END=0x87c0
 CONFIG_LTO=y
 CONFIG_HAS_BOARD_SIZE_LIMIT=y
-CONFIG_BOARD_SIZE_LIMIT=520192
+CONFIG_BOARD_SIZE_LIMIT=526336
 CONFIG_FIT=y
 CONFIG_BOOTDELAY=3
 CONFIG_AUTOBOOT_KEYED=y
-- 
2.30.2



[PATHv11 33/43] configs/am335x_evm_defconfig: inc SPL size

2023-11-27 Thread Maxim Uvarov
Increase allowed binary size to fit lwip code.

Signed-off-by: Maxim Uvarov 
---
 configs/am335x_evm_defconfig | 1 +
 1 file changed, 1 insertion(+)

diff --git a/configs/am335x_evm_defconfig b/configs/am335x_evm_defconfig
index f048e60f7f..9fd608bd76 100644
--- a/configs/am335x_evm_defconfig
+++ b/configs/am335x_evm_defconfig
@@ -124,3 +124,4 @@ CONFIG_WDT=y
 CONFIG_DYNAMIC_CRC_TABLE=y
 CONFIG_RSA=y
 CONFIG_LZO=y
+CONFIG_SPL_MAX_SIZE=0x29000
-- 
2.30.2



[PATHv11 32/43] configs/lsxhl_defconfig: LTO + size

2023-11-27 Thread Maxim Uvarov
Increase allowed binary size to fit lwip code.

Signed-off-by: Maxim Uvarov 
---
 configs/lsxhl_defconfig | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/configs/lsxhl_defconfig b/configs/lsxhl_defconfig
index d729bcb530..066f8b16b3 100644
--- a/configs/lsxhl_defconfig
+++ b/configs/lsxhl_defconfig
@@ -20,7 +20,7 @@ CONFIG_DEFAULT_DEVICE_TREE="kirkwood-lsxhl"
 CONFIG_IDENT_STRING=" LS-XHL"
 CONFIG_SYS_LOAD_ADDR=0x80
 CONFIG_HAS_BOARD_SIZE_LIMIT=y
-CONFIG_BOARD_SIZE_LIMIT=393216
+CONFIG_BOARD_SIZE_LIMIT=409600
 # CONFIG_BOOTSTD is not set
 CONFIG_DISTRO_DEFAULTS=y
 CONFIG_SHOW_BOOT_PROGRESS=y
@@ -68,3 +68,4 @@ CONFIG_DM_SPI=y
 CONFIG_KIRKWOOD_SPI=y
 CONFIG_USB=y
 CONFIG_USB_EHCI_HCD=y
+CONFIG_LTO=y
-- 
2.30.2



[PATHv11 31/43] configs/lschlv2_defconfig: enable LTO and inc size

2023-11-27 Thread Maxim Uvarov
Increase allowed binary size to fit lwip code.

Signed-off-by: Maxim Uvarov 
---
 configs/lschlv2_defconfig | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/configs/lschlv2_defconfig b/configs/lschlv2_defconfig
index d7c77f8a88..7e0c70c6ea 100644
--- a/configs/lschlv2_defconfig
+++ b/configs/lschlv2_defconfig
@@ -19,7 +19,7 @@ CONFIG_DEFAULT_DEVICE_TREE="kirkwood-lschlv2"
 CONFIG_IDENT_STRING=" LS-CHLv2"
 CONFIG_SYS_LOAD_ADDR=0x80
 CONFIG_HAS_BOARD_SIZE_LIMIT=y
-CONFIG_BOARD_SIZE_LIMIT=393216
+CONFIG_BOARD_SIZE_LIMIT=409600
 # CONFIG_BOOTSTD is not set
 CONFIG_DISTRO_DEFAULTS=y
 CONFIG_SHOW_BOOT_PROGRESS=y
@@ -67,3 +67,4 @@ CONFIG_DM_SPI=y
 CONFIG_KIRKWOOD_SPI=y
 CONFIG_USB=y
 CONFIG_USB_EHCI_HCD=y
+CONFIG_LTO=y
-- 
2.30.2



[PATHv11 29/43] configs/am335x_boneblack_vboot_defconfig: enable LTO and increase SPL size

2023-11-27 Thread Maxim Uvarov
Increase allowed binary size to fit lwip code.

Signed-off-by: Maxim Uvarov 
---
 configs/am335x_boneblack_vboot_defconfig | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/configs/am335x_boneblack_vboot_defconfig 
b/configs/am335x_boneblack_vboot_defconfig
index 531703010a..4f06ed1b76 100644
--- a/configs/am335x_boneblack_vboot_defconfig
+++ b/configs/am335x_boneblack_vboot_defconfig
@@ -94,3 +94,6 @@ CONFIG_USB_GADGET_PRODUCT_NUM=0xd022
 CONFIG_USB_ETHER=y
 CONFIG_SPL_USB_ETHER=y
 CONFIG_LZO=y
+CONFIG_LTO=y
+CONFIG_SPL_MAX_SIZE=0x1c000
+CONFIG_SPL_PAD_TO=0x1c000
-- 
2.30.2



[PATHv11 30/43] configs/sheevaplug_defconfig: enable LTO and inc size

2023-11-27 Thread Maxim Uvarov
Increase allowed binary size to fit lwip code.

Signed-off-by: Maxim Uvarov 
---
 configs/sheevaplug_defconfig | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/configs/sheevaplug_defconfig b/configs/sheevaplug_defconfig
index 2e4901b840..c0b256f3b0 100644
--- a/configs/sheevaplug_defconfig
+++ b/configs/sheevaplug_defconfig
@@ -17,7 +17,7 @@ CONFIG_DEFAULT_DEVICE_TREE="kirkwood-sheevaplug"
 CONFIG_IDENT_STRING="\nMarvell-Sheevaplug"
 CONFIG_SYS_LOAD_ADDR=0x80
 CONFIG_HAS_BOARD_SIZE_LIMIT=y
-CONFIG_BOARD_SIZE_LIMIT=524288
+CONFIG_BOARD_SIZE_LIMIT=543744
 CONFIG_BOOTDELAY=3
 CONFIG_USE_BOOTCOMMAND=y
 CONFIG_BOOTCOMMAND="${x_bootcmd_kernel}; setenv bootargs ${x_bootargs} 
${x_bootargs_root}; bootm 0x640;"
@@ -72,3 +72,4 @@ CONFIG_USB_EHCI_HCD=y
 CONFIG_USB_STORAGE=y
 CONFIG_LZMA=y
 CONFIG_BZIP2=y
+CONFIG_LTO=y
-- 
2.30.2



[PATHv11 28/43] configs/turris_omnia_defconfig: enable LTO

2023-11-27 Thread Maxim Uvarov
Decrease allowed binary size to fit lwip code.
u-boot-with-spl.kwb exceeds file size limit:
  limit:  0xf6000 bytes
  actual: 0xf8600 bytes
  excess: 0x2600 bytes

Signed-off-by: Maxim Uvarov 
---
 configs/turris_omnia_defconfig | 1 +
 1 file changed, 1 insertion(+)

diff --git a/configs/turris_omnia_defconfig b/configs/turris_omnia_defconfig
index afcd4a1eb7..4e965c795a 100644
--- a/configs/turris_omnia_defconfig
+++ b/configs/turris_omnia_defconfig
@@ -118,3 +118,4 @@ CONFIG_USB_EHCI_HCD=y
 CONFIG_WDT=y
 CONFIG_WDT_ORION=y
 CONFIG_EXT4_WRITE=y
+CONFIG_LTO=y
-- 
2.30.2



[PATHv11 27/43] configs/socfpga_secu1_defconfig: enable LTO

2023-11-27 Thread Maxim Uvarov
Decrease allowed binary size to fit lwip code.

Signed-off-by: Maxim Uvarov 
---
 configs/socfpga_secu1_defconfig | 1 +
 1 file changed, 1 insertion(+)

diff --git a/configs/socfpga_secu1_defconfig b/configs/socfpga_secu1_defconfig
index b8052f1dee..4213941bcf 100644
--- a/configs/socfpga_secu1_defconfig
+++ b/configs/socfpga_secu1_defconfig
@@ -113,3 +113,4 @@ CONFIG_DESIGNWARE_WATCHDOG=y
 CONFIG_WDT=y
 CONFIG_SYS_TIMER_COUNTS_DOWN=y
 # CONFIG_GZIP is not set
+CONFIG_LTO=y
-- 
2.30.2



[PATHv11 26/43] configs/tbs2910_defconfig inc limit

2023-11-27 Thread Maxim Uvarov
Increase allowed binary size to fit lwip code.

Signed-off-by: Maxim Uvarov 
---
 configs/tbs2910_defconfig | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/configs/tbs2910_defconfig b/configs/tbs2910_defconfig
index 8fbe84f1d2..ce40efa9ab 100644
--- a/configs/tbs2910_defconfig
+++ b/configs/tbs2910_defconfig
@@ -17,7 +17,7 @@ CONFIG_SYS_MEMTEST_START=0x1000
 CONFIG_SYS_MEMTEST_END=0x2f40
 CONFIG_LTO=y
 CONFIG_HAS_BOARD_SIZE_LIMIT=y
-CONFIG_BOARD_SIZE_LIMIT=392192
+CONFIG_BOARD_SIZE_LIMIT=417792
 # CONFIG_BOOTSTD is not set
 CONFIG_SUPPORT_RAW_INITRD=y
 CONFIG_BOOTDELAY=3
-- 
2.30.2



[PATHv11 25/43] configs/turris_omnia_defconfig set limit to 0xf6000

2023-11-27 Thread Maxim Uvarov
Increase allowed binary size to fit lwip code.
0xf -> 0xf6000

Signed-off-by: Maxim Uvarov 
---
 configs/turris_omnia_defconfig | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/configs/turris_omnia_defconfig b/configs/turris_omnia_defconfig
index 65d4a296e7..afcd4a1eb7 100644
--- a/configs/turris_omnia_defconfig
+++ b/configs/turris_omnia_defconfig
@@ -32,7 +32,7 @@ CONFIG_OF_BOARD_FIXUP=y
 CONFIG_SYS_MEMTEST_START=0x0080
 CONFIG_SYS_MEMTEST_END=0x00ff
 CONFIG_HAS_BOARD_SIZE_LIMIT=y
-CONFIG_BOARD_SIZE_LIMIT=983040
+CONFIG_BOARD_SIZE_LIMIT=1007616
 CONFIG_FIT=y
 CONFIG_FIT_VERBOSE=y
 CONFIG_DISTRO_DEFAULTS=y
-- 
2.30.2



[PATHv11 24/43] lwip: omap3: rename mem_init

2023-11-27 Thread Maxim Uvarov
Rename mem_init to solve following compilation error.
+arm-linux-gnueabi-ld.bfd: net/lwip/lwip-external/src/core/mem.o: in
  function `mem_init':
+net/lwip/lwip-external/src/core/mem.c:162: multiple definition
  of `mem_init';
  arch/arm/mach-omap2/omap3/sdrc.o:arch/arm/mach-omap2/omap3/
  sdrc.c:240: first defined here
+make[1]: *** [Makefile:1764: u-boot] Error 1
+/opt/gcc-13.1.0-nolibc/arm-linux-gnueabi/bin/../lib/gcc/arm-linux-
  gnueabi/13.1.0/../../
../../arm-linux-gnueabi/bin/ld: net/lwip/lwip-external/src/core/
  mem.o (symbol from
  plugin): in function `mem_init':
+(.text+0x0): multiple definition of `mem_init'; arch/arm/mach-omap2/
  omap3/emif4.o
  (symbol from plugin):(.text+0x0): first defined here
+collect2: error: ld returned 1 exit status
+(.text+0x0): multiple definition of `mem_init'; arch/arm/mach-omap2/
  omap3/sdrc.o
  (symbol from plugin):(.text+0x0): first defined here
+Image 'simple-bin' is missing external blobs and is non-functional:
   tee-os
+/binman/simple-bin/fit/images/op-tee/tee-os (tee-os):

Signed-off-by: Maxim Uvarov 
---
 arch/arm/include/asm/arch-omap3/mem.h | 2 +-
 arch/arm/mach-omap2/omap3/board.c | 2 +-
 arch/arm/mach-omap2/omap3/emif4.c | 4 ++--
 arch/arm/mach-omap2/omap3/sdrc.c  | 6 +++---
 4 files changed, 7 insertions(+), 7 deletions(-)

diff --git a/arch/arm/include/asm/arch-omap3/mem.h 
b/arch/arm/include/asm/arch-omap3/mem.h
index 569779c55e..fce3568eca 100644
--- a/arch/arm/include/asm/arch-omap3/mem.h
+++ b/arch/arm/include/asm/arch-omap3/mem.h
@@ -475,7 +475,7 @@ enum {
 #ifndef __ASSEMBLY__
 
 /* Function prototypes */
-void mem_init(void);
+void omap3_mem_init(void);
 
 u32 is_mem_sdr(void);
 u32 mem_ok(u32 cs);
diff --git a/arch/arm/mach-omap2/omap3/board.c 
b/arch/arm/mach-omap2/omap3/board.c
index 8b70251457..c76a95dd5d 100644
--- a/arch/arm/mach-omap2/omap3/board.c
+++ b/arch/arm/mach-omap2/omap3/board.c
@@ -216,7 +216,7 @@ void s_init(void)
 void board_init_f(ulong dummy)
 {
early_system_init();
-   mem_init();
+   omap3_mem_init();
/*
* Save the boot parameters passed from romcode.
* We cannot delay the saving further than this,
diff --git a/arch/arm/mach-omap2/omap3/emif4.c 
b/arch/arm/mach-omap2/omap3/emif4.c
index 7e5a281922..4fbfb387ab 100644
--- a/arch/arm/mach-omap2/omap3/emif4.c
+++ b/arch/arm/mach-omap2/omap3/emif4.c
@@ -159,10 +159,10 @@ int dram_init_banksize(void)
 }
 
 /*
- * mem_init() -
+ * omap3_mem_init() -
  *  - Initialize memory subsystem
  */
-void mem_init(void)
+void omap3_mem_init(void)
 {
do_emif4_init();
 }
diff --git a/arch/arm/mach-omap2/omap3/sdrc.c b/arch/arm/mach-omap2/omap3/sdrc.c
index 5d43e7c9cf..f2a0769b9d 100644
--- a/arch/arm/mach-omap2/omap3/sdrc.c
+++ b/arch/arm/mach-omap2/omap3/sdrc.c
@@ -4,7 +4,7 @@
  *
  * This file has been created after exctracting and consolidating
  * the SDRC related content from mem.c and board.c, also created
- * generic init function (mem_init).
+ * generic init function (omap3_mem_init).
  *
  * Copyright (C) 2004-2010
  * Texas Instruments Incorporated - https://www.ti.com/
@@ -232,11 +232,11 @@ int dram_init_banksize(void)
 }
 
 /*
- * mem_init -
+ * map3_mem_init -
  *  - Init the sdrc chip,
  *  - Selects CS0 and CS1,
  */
-void mem_init(void)
+void omap3_mem_init(void)
 {
/* only init up first bank here */
do_sdrc_init(CS0, EARLY_INIT);
-- 
2.30.2



[PATHv11 23/43] rcar3_salvator-x_defconfig: increase binary size limit

2023-11-27 Thread Maxim Uvarov
   aarch64:  +   rcar3_salvator-x
u-boot.img exceeds file size limit:
  limit:  0x10 bytes
  actual: 0x106d6c bytes
  excess: 0x6d6c bytes

Signed-off-by: Maxim Uvarov 
---
 configs/rcar3_salvator-x_defconfig | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/configs/rcar3_salvator-x_defconfig 
b/configs/rcar3_salvator-x_defconfig
index e045cf27d3..238d0b3940 100644
--- a/configs/rcar3_salvator-x_defconfig
+++ b/configs/rcar3_salvator-x_defconfig
@@ -10,12 +10,13 @@ CONFIG_DEFAULT_DEVICE_TREE="r8a77950-salvator-x-u-boot"
 CONFIG_SPL_TEXT_BASE=0xe6338000
 CONFIG_RCAR_GEN3=y
 CONFIG_TARGET_SALVATOR_X=y
-CONFIG_SYS_MONITOR_LEN=1048576
+CONFIG_SYS_MONITOR_LEN=1085440
 CONFIG_SPL_STACK=0xe6304000
 CONFIG_SYS_LOAD_ADDR=0x5800
 CONFIG_PCI=y
 CONFIG_LTO=y
 CONFIG_REMAKE_ELF=y
+CONFIG_BOARD_SIZE_LIMIT=1085440
 CONFIG_SYS_MONITOR_BASE=0x
 CONFIG_FIT=y
 # CONFIG_BOOTSTD is not set
-- 
2.30.2



[PATHv11 22/43] bcm_ns3: fix overlap define with lwip

2023-11-27 Thread Maxim Uvarov
Rename declaration to not overlap with lwip.

aarch64:  +   bcm_ns3
+In file included from net/lwip/lwip-external/src/include/lwip/etharp.h:53,
+ from net/lwip/lwip-external/src/core/init.c:55:
+net/lwip/lwip-external/src/include/lwip/prot/ethernet.h:69:
  error: "ETH_ADDR" redefined [-Werror]
+   69 | #define ETH_ADDR(b0, b1, b2, b3, b4, b5) {{b0, b1, b2, b3, b4, b5}}
+  |
+In file included from include/config.h:3,
+ from arch/arm/include/asm/string.h:4,
+ from include/linux/string.h:21,
+ from include/malloc.h:369,
+ from include/stdlib.h:9,
+ from net/lwip/lwip-external/src/include/lwip/arch.h:83,
+ from net/lwip/lwip-external/src/include/lwip/debug.h:40,
+ from net/lwip/lwipopts.h:93,
+ from net/lwip/lwip-external/src/include/lwip/opt.h:51,
+ from net/lwip/lwip-external/src/core/init.c:38:
+include/configs/bcm_ns3.h:52: note: this is the location of the previous 
definition
+   52 | #define ETH_ADDR

Signed-off-by: Maxim Uvarov 
---
 include/configs/bcm_ns3.h | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/include/configs/bcm_ns3.h b/include/configs/bcm_ns3.h
index 47de4bc201..7c6e0725a6 100644
--- a/include/configs/bcm_ns3.h
+++ b/include/configs/bcm_ns3.h
@@ -45,11 +45,11 @@
 #define PCIE_ARGS "pcie_args=pci=pcie_bus_safe pcie_ports=native 
vfio_pci.disable_idle_d3=1\0"
 
 #ifdef CONFIG_BCM_SF2_ETH
-#define ETH_ADDR "ethaddr=00:0A:F7:95:65:A4\0"
+#define BCM_ETH_ADDR "ethaddr=00:0A:F7:95:65:A4\0"
 #define NET_ARGS "bgmac_platform.ethaddr=${ethaddr} " \
"ip=${ipaddr}::${gatewayip}:${netmask}::${ethif}:off"
 #else
-#define ETH_ADDR
+#define BMC_ETH_ADDR
 #define NET_ARGS
 #endif
 
@@ -749,7 +749,7 @@
OS_LOG_LEVEL \
EXTRA_ARGS \
PCIE_ARGS \
-   ETH_ADDR \
+   BMC_ETH_ADDR \
RESERVED_MEM \
SETBOOTARGS \
UPDATEME_FLASH_PARAMS \
-- 
2.30.2



[PATHv11 21/43] mach-socfpga: do not overlap defines with lwip

2023-11-27 Thread Maxim Uvarov
Fix compilation issue with overlapping lwip and march defines.

Signed-off-by: Maxim Uvarov 
---
 arch/arm/mach-socfpga/include/mach/handoff_soc64.h | 6 --
 arch/arm/mach-socfpga/wrap_handoff_soc64.c | 9 +
 2 files changed, 9 insertions(+), 6 deletions(-)

diff --git a/arch/arm/mach-socfpga/include/mach/handoff_soc64.h 
b/arch/arm/mach-socfpga/include/mach/handoff_soc64.h
index 902fc6bfb5..9b85e5865b 100644
--- a/arch/arm/mach-socfpga/include/mach/handoff_soc64.h
+++ b/arch/arm/mach-socfpga/include/mach/handoff_soc64.h
@@ -78,12 +78,6 @@
 
 #ifndef __ASSEMBLY__
 #include 
-enum endianness {
-   LITTLE_ENDIAN = 0,
-   BIG_ENDIAN,
-   UNKNOWN_ENDIANNESS
-};
-
 int socfpga_get_handoff_size(void *handoff_address);
 int socfpga_handoff_read(void *handoff_address, void *table, u32 table_len);
 #endif
diff --git a/arch/arm/mach-socfpga/wrap_handoff_soc64.c 
b/arch/arm/mach-socfpga/wrap_handoff_soc64.c
index e7cb5ea89c..df0701ec85 100644
--- a/arch/arm/mach-socfpga/wrap_handoff_soc64.c
+++ b/arch/arm/mach-socfpga/wrap_handoff_soc64.c
@@ -10,6 +10,15 @@
 #include 
 #include "log.h"
 
+#ifndef __ASSEMBLY__
+#include 
+enum endianness {
+   LITTLE_ENDIAN = 0,
+   BIG_ENDIAN,
+   UNKNOWN_ENDIANNESS
+};
+#endif
+
 static enum endianness check_endianness(u32 handoff)
 {
switch (handoff) {
-- 
2.30.2



[PATHv11 20/43] driver/net/rtl8139: remove debug print

2023-11-27 Thread Maxim Uvarov
debug print delays reset of the driver. Finally I see
bunch of "rx error " errors in the screen. CI can
not handle many prints. While network works fine there

Reproduced with:
make CROSS_COMPILE=sh2-linux- r2dplus_defconfig all
qemu-system-sh4 -M r2d -nographic -serial null \
-serial mon:stdio -net user,tftp=`pwd` \
-net nic,model=rtl8139 -kernel ./u-boot.bin

Signed-off-by: Maxim Uvarov 
---
 drivers/net/rtl8139.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/drivers/net/rtl8139.c b/drivers/net/rtl8139.c
index 106bc1c7ae..6003b88274 100644
--- a/drivers/net/rtl8139.c
+++ b/drivers/net/rtl8139.c
@@ -453,7 +453,6 @@ static int rtl8139_recv_common(struct rtl8139_priv *priv, 
unsigned char *rxdata,
  RTL_STS_RXBADALIGN)) ||
(rx_size < ETH_ZLEN) ||
(rx_size > ETH_FRAME_LEN + 4)) {
-   printf("rx error %hX\n", rx_status);
/* this clears all interrupts still pending */
rtl8139_reset(priv);
return 0;
-- 
2.30.2



[PATHv11 19/43] sandbox: eth-raw-os: successful return code is 0

2023-11-27 Thread Maxim Uvarov
all network drivers return 0 on the successful
transmission.

Signed-off-by: Maxim Uvarov 
---
 arch/sandbox/cpu/eth-raw-os.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/sandbox/cpu/eth-raw-os.c b/arch/sandbox/cpu/eth-raw-os.c
index e59b96be5f..92c35aed95 100644
--- a/arch/sandbox/cpu/eth-raw-os.c
+++ b/arch/sandbox/cpu/eth-raw-os.c
@@ -256,7 +256,7 @@ int sandbox_eth_raw_os_send(void *packet, int length,
   strerror(errno));
return -errno;
}
-   return retval;
+   return 0;
 }
 
 int sandbox_eth_raw_os_recv(void *packet, int *length,
-- 
2.30.2



[PATHv11 18/43] net/smc911x: fix return from smc911x_send

2023-11-27 Thread Maxim Uvarov
return value of smc911x_send is ignored, but on sucesseful
send we need return 0 and or error -ETIMEOUT, not opposite.

Signed-off-by: Maxim Uvarov 
---
 drivers/net/smc911x.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/net/smc911x.c b/drivers/net/smc911x.c
index 5c5ad8b84a..616b7ce174 100644
--- a/drivers/net/smc911x.c
+++ b/drivers/net/smc911x.c
@@ -403,7 +403,7 @@ static int smc911x_send(struct udevice *dev, void *packet, 
int length)
 
ret = smc911x_send_common(priv, packet, length);
 
-   return ret ? 0 : -ETIMEDOUT;
+   return ret ? -ETIMEDOUT : 0;
 }
 
 static int smc911x_recv(struct udevice *dev, int flags, uchar **packetp)
-- 
2.30.2



[PATHv11 16/43] test_net: print out net list

2023-11-27 Thread Maxim Uvarov
Printing net list is useful in CI log files.

Signed-off-by: Maxim Uvarov 
---
 test/py/tests/test_net.py | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/test/py/tests/test_net.py b/test/py/tests/test_net.py
index b2241ae6a4..cd5b791a6a 100644
--- a/test/py/tests/test_net.py
+++ b/test/py/tests/test_net.py
@@ -96,6 +96,8 @@ def test_net_pre_commands(u_boot_console):
 if init_pci:
 u_boot_console.run_command('pci enum')
 
+u_boot_console.run_command('net list')
+
 @pytest.mark.buildconfigspec('cmd_dhcp')
 def test_net_dhcp(u_boot_console):
 """Test the dhcp command.
-- 
2.30.2



[PATHv11 17/43] net: sandbox: fix NULL pointer derefences

2023-11-27 Thread Maxim Uvarov
Add additional checks for NULL pointers.

Signed-off-by: Maxim Uvarov 
---
 drivers/net/sandbox.c | 5 +
 1 file changed, 5 insertions(+)

diff --git a/drivers/net/sandbox.c b/drivers/net/sandbox.c
index 13022addb6..75d32db3a9 100644
--- a/drivers/net/sandbox.c
+++ b/drivers/net/sandbox.c
@@ -65,6 +65,9 @@ int sandbox_eth_arp_req_to_reply(struct udevice *dev, void 
*packet,
struct ethernet_hdr *eth_recv;
struct arp_hdr *arp_recv;
 
+   if (!priv)
+   return -EAGAIN;
+
if (ntohs(eth->et_protlen) != PROT_ARP)
return -EAGAIN;
 
@@ -82,6 +85,8 @@ int sandbox_eth_arp_req_to_reply(struct udevice *dev, void 
*packet,
 
/* Formulate a fake response */
eth_recv = (void *)priv->recv_packet_buffer[priv->recv_packets];
+   if (!eth_recv)
+   return -EAGAIN;
memcpy(eth_recv->et_dest, eth->et_src, ARP_HLEN);
memcpy(eth_recv->et_src, priv->fake_host_hwaddr, ARP_HLEN);
eth_recv->et_protlen = htons(PROT_ARP);
-- 
2.30.2



[PATHv11 15/43] test_efi_loader.py: use $filesize var

2023-11-27 Thread Maxim Uvarov
bootefi code relays in internal variable then to filesize environment.
lwip tftp do not update this variable. For not I update test to provide
correct size.

Signed-off-by: Maxim Uvarov 
---
 test/py/tests/test_efi_loader.py | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/test/py/tests/test_efi_loader.py b/test/py/tests/test_efi_loader.py
index 85473a9049..9b2541593c 100644
--- a/test/py/tests/test_efi_loader.py
+++ b/test/py/tests/test_efi_loader.py
@@ -158,7 +158,7 @@ def test_efi_helloworld_net(u_boot_console):
 
 addr = fetch_tftp_file(u_boot_console, 'env__efi_loader_helloworld_file')
 
-output = u_boot_console.run_command('bootefi %x' % addr)
+output = u_boot_console.run_command('bootefi $fileaddr:$filesize')
 expected_text = 'Hello, world'
 assert expected_text in output
 expected_text = '## Application failed'
@@ -187,7 +187,7 @@ def test_efi_grub_net(u_boot_console):
 
 addr = fetch_tftp_file(u_boot_console, 'env__efi_loader_grub_file')
 
-u_boot_console.run_command('bootefi %x' % addr, wait_for_prompt=False)
+u_boot_console.run_command('bootefi %x:$filesize' % addr, 
wait_for_prompt=False)
 
 # Verify that we have an SMBIOS table
 check_smbios = 
u_boot_console.config.env.get('env__efi_loader_check_smbios', False)
-- 
2.30.2



[PATHv11 14/43] net/lwip: split net.h to net.h, arp.h and eth.h

2023-11-27 Thread Maxim Uvarov
current net.h has ethernet and protocol definitions. Protocol definitions
overlap with lwIP protocol definitions and net.h can not be included from
lwIP code. Splitting on logical blocks makes that work.

Signed-off-by: Maxim Uvarov 
---
 include/net.h | 189 +---
 include/net/arp.h |   9 +++
 include/net/eth.h | 194 ++
 3 files changed, 207 insertions(+), 185 deletions(-)
 create mode 100644 include/net/arp.h
 create mode 100644 include/net/eth.h

diff --git a/include/net.h b/include/net.h
index ed15064fc1..8efc4d7f3e 100644
--- a/include/net.h
+++ b/include/net.h
@@ -21,6 +21,7 @@
 #include 
 #include 
 #include 
+#include  
 
 struct bd_info;
 struct cmd_tbl;
@@ -32,25 +33,6 @@ struct udevice;
 #define DEBUG_INT_STATE 0  /* Internal network state changes */
 #define DEBUG_NET_PKT_TRACE 0  /* Trace all packet data */
 
-/*
- * The number of receive packet buffers, and the required packet buffer
- * alignment in memory.
- *
- */
-#define PKTBUFSRX  CONFIG_SYS_RX_ETH_BUFFER
-#define PKTALIGN   ARCH_DMA_MINALIGN
-
-/* Number of packets processed together */
-#define ETH_PACKETS_BATCH_RECV 32
-
-/* ARP hardware address length */
-#define ARP_HLEN 6
-/*
- * The size of a MAC address in string form, each digit requires two chars
- * and five separator characters to form '00:00:00:00:00:00'.
- */
-#define ARP_HLEN_ASCII (ARP_HLEN * 2) + (ARP_HLEN - 1)
-
 /* IPv4 addresses are always 32 bits in size */
 struct in_addr {
__be32 s_addr;
@@ -114,150 +96,7 @@ typedef void rxhand_icmp_f(unsigned type, unsigned code, 
unsigned dport,
  */
 typedef void   thand_f(void);
 
-enum eth_state_t {
-   ETH_STATE_INIT,
-   ETH_STATE_PASSIVE,
-   ETH_STATE_ACTIVE
-};
-
-/**
- * struct eth_pdata - Platform data for Ethernet MAC controllers
- *
- * @iobase: The base address of the hardware registers
- * @enetaddr: The Ethernet MAC address that is loaded from EEPROM or env
- * @phy_interface: PHY interface to use - see PHY_INTERFACE_MODE_...
- * @max_speed: Maximum speed of Ethernet connection supported by MAC
- * @priv_pdata: device specific plat
- */
-struct eth_pdata {
-   phys_addr_t iobase;
-   unsigned char enetaddr[ARP_HLEN];
-   int phy_interface;
-   int max_speed;
-   void *priv_pdata;
-};
-
-enum eth_recv_flags {
-   /*
-* Check hardware device for new packets (otherwise only return those
-* which are already in the memory buffer ready to process)
-*/
-   ETH_RECV_CHECK_DEVICE   = 1 << 0,
-};
-
-/**
- * struct eth_ops - functions of Ethernet MAC controllers
- *
- * start: Prepare the hardware to send and receive packets
- * send: Send the bytes passed in "packet" as a packet on the wire
- * recv: Check if the hardware received a packet. If so, set the pointer to the
- *  packet buffer in the packetp parameter. If not, return an error or 0 to
- *  indicate that the hardware receive FIFO is empty. If 0 is returned, the
- *  network stack will not process the empty packet, but free_pkt() will be
- *  called if supplied
- * free_pkt: Give the driver an opportunity to manage its packet buffer memory
- *  when the network stack is finished processing it. This will only be
- *  called when no error was returned from recv - optional
- * stop: Stop the hardware from looking for packets - may be called even if
- *  state == PASSIVE
- * mcast: Join or leave a multicast group (for TFTP) - optional
- * write_hwaddr: Write a MAC address to the hardware (used to pass it to Linux
- *  on some platforms like ARM). This function expects the
- *  eth_pdata::enetaddr field to be populated. The method can
- *  return -ENOSYS to indicate that this is not implemented for
-this hardware - optional.
- * read_rom_hwaddr: Some devices have a backup of the MAC address stored in a
- * ROM on the board. This is how the driver should expose it
- * to the network stack. This function should fill in the
- * eth_pdata::enetaddr field - optional
- * set_promisc: Enable or Disable promiscuous mode
- * get_sset_count: Number of statistics counters
- * get_string: Names of the statistic counters
- * get_stats: The values of the statistic counters
- */
-struct eth_ops {
-   int (*start)(struct udevice *dev);
-   int (*send)(struct udevice *dev, void *packet, int length);
-   int (*recv)(struct udevice *dev, int flags, uchar **packetp);
-   int (*free_pkt)(struct udevice *dev, uchar *packet, int length);
-   void (*stop)(struct udevice *dev);
-   int (*mcast)(struct udevice *dev, const u8 *enetaddr, int join);
-   int (*write_hwaddr)(struct udevice *dev);
-   int (*read_rom_hwaddr)(struct udevice *dev);
-   int (*set_promisc)(struct udevice *dev, bool enable);
-   int (*get_

[PATHv11 13/43] net/lwip: replace original net commands with lwip

2023-11-27 Thread Maxim Uvarov
Replace original commands: ping, tftp, dhcp and wget.

Signed-off-by: Maxim Uvarov 
---
 boot/bootmeth_efi.c | 18 +++---
 boot/bootmeth_pxe.c | 21 ++-
 cmd/net.c   | 86 +
 cmd/pxe.c   | 19 +-
 include/net.h   |  8 +++--
 include/net/ulwip.h | 67 +++
 6 files changed, 116 insertions(+), 103 deletions(-)
 create mode 100644 include/net/ulwip.h

diff --git a/boot/bootmeth_efi.c b/boot/bootmeth_efi.c
index ae936c8daa..52399d627c 100644
--- a/boot/bootmeth_efi.c
+++ b/boot/bootmeth_efi.c
@@ -20,6 +20,8 @@
 #include 
 #include 
 #include 
+#include 
+#include 
 #include 
 #include 
 
@@ -319,9 +321,7 @@ static int distro_efi_try_bootflow_files(struct udevice 
*dev,
 
 static int distro_efi_read_bootflow_net(struct bootflow *bflow)
 {
-   char file_addr[17], fname[256];
-   char *tftp_argv[] = {"tftp", file_addr, fname, NULL};
-   struct cmd_tbl cmdtp = {};  /* dummy */
+   char fname[256];
const char *addr_str, *fdt_addr_str;
int ret, arch, size;
ulong addr, fdt_addr;
@@ -368,7 +368,6 @@ static int distro_efi_read_bootflow_net(struct bootflow 
*bflow)
if (!fdt_addr_str)
return log_msg_ret("fdt", -EINVAL);
fdt_addr = hextoul(fdt_addr_str, NULL);
-   sprintf(file_addr, "%lx", fdt_addr);
 
/* We only allow the first prefix with PXE */
ret = distro_efi_get_fdt_name(fname, sizeof(fname), 0);
@@ -379,7 +378,16 @@ static int distro_efi_read_bootflow_net(struct bootflow 
*bflow)
if (!bflow->fdt_fname)
return log_msg_ret("fil", -ENOMEM);
 
-   if (!do_tftpb(&cmdtp, 0, 3, tftp_argv)) {
+   ret = ulwip_init();
+   if (ret)
+   return log_msg_ret("ulwip_init", ret);
+
+   ret = ulwip_tftp(fdt_addr, fname);
+   if (ret)
+   return log_msg_ret("ulwip_tftp", ret);
+
+   ret = ulwip_loop();
+   if (!ret) {
bflow->fdt_size = env_get_hex("filesize", 0);
bflow->fdt_addr = fdt_addr;
} else {
diff --git a/boot/bootmeth_pxe.c b/boot/bootmeth_pxe.c
index 8d489a11aa..fc6aabaa18 100644
--- a/boot/bootmeth_pxe.c
+++ b/boot/bootmeth_pxe.c
@@ -21,6 +21,8 @@
 #include 
 #include 
 #include 
+#include 
+#include 
 #include 
 
 static int extlinux_pxe_getfile(struct pxe_context *ctx, const char *file_path,
@@ -116,18 +118,21 @@ static int extlinux_pxe_read_file(struct udevice *dev, 
struct bootflow *bflow,
  const char *file_path, ulong addr,
  ulong *sizep)
 {
-   char *tftp_argv[] = {"tftp", NULL, NULL, NULL};
-   struct pxe_context *ctx = dev_get_priv(dev);
-   char file_addr[17];
ulong size;
int ret;
 
-   sprintf(file_addr, "%lx", addr);
-   tftp_argv[1] = file_addr;
-   tftp_argv[2] = (void *)file_path;
+   ret = ulwip_init();
+   if (ret)
+   return log_msg_ret("ulwip_init", ret);
+
+   ret = ulwip_tftp(addr, file_path);
+   if (ret)
+   return log_msg_ret("ulwip_tftp", ret);
+
+   ret = ulwip_loop();
+   if (ret)
+   return log_msg_ret("ulwip_loop", ret);
 
-   if (do_tftpb(ctx->cmdtp, 0, 3, tftp_argv))
-   return -ENOENT;
ret = pxe_get_file_size(&size);
if (ret)
return log_msg_ret("tftp", ret);
diff --git a/cmd/net.c b/cmd/net.c
index d407d8320a..dc5a114309 100644
--- a/cmd/net.c
+++ b/cmd/net.c
@@ -22,6 +22,7 @@
 #include 
 #include 
 #include 
+#include 
 
 static int netboot_common(enum proto_t, struct cmd_tbl *, int, char * const 
[]);
 
@@ -40,19 +41,9 @@ U_BOOT_CMD(
 #endif
 
 #ifdef CONFIG_CMD_TFTPBOOT
-int do_tftpb(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
-{
-   int ret;
-
-   bootstage_mark_name(BOOTSTAGE_KERNELREAD_START, "tftp_start");
-   ret = netboot_common(TFTPGET, cmdtp, argc, argv);
-   bootstage_mark_name(BOOTSTAGE_KERNELREAD_STOP, "tftp_done");
-   return ret;
-}
-
 #if IS_ENABLED(CONFIG_IPV6)
 U_BOOT_CMD(
-   tftpboot,   4,  1,  do_tftpb,
+   tftpboot,   4,  1, do_lwip_tftp,
"boot image via network using TFTP protocol\n"
"To use IPv6 add -ipv6 parameter or use IPv6 hostIPaddr framed "
"with [] brackets",
@@ -60,7 +51,7 @@ U_BOOT_CMD(
 );
 #else
 U_BOOT_CMD(
-   tftpboot,   3,  1,  do_tftpb,
+   tftpboot,   3,  1,  do_lwip_tftp,
"load file via network using TFTP protocol",
"[loadAddress] [[hostIPaddr:]bootfilename]"
 );
@@ -139,7 +130,7 @@ U_BOOT_CMD(dhcp6,   3,  1,  do_dhcp6,
 static int do_dhcp(struct cmd_tbl *cmdtp, int

[PATHv11 12/43] net/lwip: connection between cmd and lwip apps

2023-11-27 Thread Maxim Uvarov
Use lwip variants of network commands.

Signed-off-by: Maxim Uvarov 
---
 cmd/Makefile   |   1 +
 cmd/net-lwip.c | 307 +
 2 files changed, 308 insertions(+)
 create mode 100644 cmd/net-lwip.c

diff --git a/cmd/Makefile b/cmd/Makefile
index 9a6790cc17..1b28b02844 100644
--- a/cmd/Makefile
+++ b/cmd/Makefile
@@ -128,6 +128,7 @@ endif
 obj-$(CONFIG_CMD_MUX) += mux.o
 obj-$(CONFIG_CMD_NAND) += nand.o
 obj-$(CONFIG_CMD_NET) += net.o
+obj-$(CONFIG_CMD_NET) += net-lwip.o
 obj-$(CONFIG_CMD_NVEDIT_EFI) += nvedit_efi.o
 obj-$(CONFIG_CMD_ONENAND) += onenand.o
 obj-$(CONFIG_CMD_OSD) += osd.o
diff --git a/cmd/net-lwip.c b/cmd/net-lwip.c
new file mode 100644
index 00..37b5005da5
--- /dev/null
+++ b/cmd/net-lwip.c
@@ -0,0 +1,307 @@
+// SPDX-License-Identifier: GPL-2.0
+
+/*
+ * (C) Copyright 2023 Maxim Uvarov, maxim.uva...@linaro.org
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "net/lwip.h"
+#include "net/ulwip.h"
+
+static int do_lwip_init(struct cmd_tbl *cmdtp, int flag, int argc,
+   char *const argv[])
+{
+   if (!ulwip_init())
+   return CMD_RET_SUCCESS;
+   return CMD_RET_FAILURE;
+}
+
+#if defined(CONFIG_CMD_DHCP) || defined(CONFIG_CMD_DNS)
+static void ulwip_timeout_handler(void)
+{
+   eth_halt();
+   net_set_state(NETLOOP_FAIL);/* we did not get the reply */
+   ulwip_loop_set(0);
+}
+#endif
+
+#if defined(CONFIG_CMD_DHCP) || defined(CONFIG_CMD_PING) || 
defined(CONFIG_CMD_DNS) || defined(CONFIG_CMD_WGET) || 
defined(CONFIG_CMD_TFTPBOOT)
+int ulwip_loop(void)
+{
+   int ret = CMD_RET_FAILURE;
+   struct udevice *udev;
+   struct ulwip *ulwip;
+
+   udev = eth_get_dev();
+   if (!udev)
+   return -1;
+
+   ulwip = eth_lwip_priv(udev);
+
+   ulwip_loop_set(1);
+   if (!net_loop(LWIP))
+   ret = CMD_RET_SUCCESS;
+   ulwip_loop_set(0);
+   net_loop(LWIP);
+   ulwip->active = 0;
+   return ret;
+}
+#endif
+
+#if defined(CONFIG_CMD_PING)
+int do_lwip_ping(struct cmd_tbl *cmdtp, int flag, int argc,
+char *const argv[])
+{
+   int ret;
+
+   if (argc < 2)
+   return CMD_RET_USAGE;
+
+   ret = ulwip_init();
+   if (ret) {
+   log_err("ulwip_init err %d\n", ret);
+   return CMD_RET_FAILURE;
+   }
+
+   log_info("Using %s device\n", eth_get_name());
+   log_info("pinging addr: %s\n", argv[1]);
+
+   if (ulwip_ping(argv[1])) {
+   printf("ping init fail\n");
+   return CMD_RET_FAILURE;
+   }
+
+   return ulwip_loop();
+}
+#endif /* CONFIG_CMD_PING */
+
+#if defined(CONFIG_CMD_WGET)
+int do_lwip_wget(struct cmd_tbl *cmdtp, int flag, int argc,
+char *const argv[])
+{
+   char *url;
+   int ret;
+
+   if (argc < 2)
+   return CMD_RET_USAGE;
+
+   url = argv[1];
+
+   ret = ulwip_init();
+   if (ret) {
+   log_err("ulwip_init err %d\n", ret);
+   return CMD_RET_FAILURE;
+   }
+
+   ret = ulwip_wget(image_load_addr, url);
+   if (ret) {
+   log_err("lwip_wget err %d\n", ret);
+   return CMD_RET_FAILURE;
+   }
+
+   return ulwip_loop();
+}
+#endif
+
+#if defined(CONFIG_CMD_TFTPBOOT)
+int do_lwip_tftp(struct cmd_tbl *cmdtp, int flag, int argc,
+char *const argv[])
+{
+   char *filename;
+   ulong addr;
+   char *end;
+   int ret;
+
+   switch (argc) {
+   case 1:
+   filename = env_get("bootfile");
+   break;
+   case 2:
+   /*
+* Only one arg - accept two forms:
+* Just load address, or just boot file name. The latter
+* form must be written in a format which can not be
+* mis-interpreted as a valid number.
+*/
+   addr = hextoul(argv[1], &end);
+   if (end == (argv[1] + strlen(argv[1]))) {
+   image_load_addr = addr;
+   filename = env_get("bootfile");
+   } else {
+   filename = argv[1];
+   }
+   break;
+   case 3:
+   image_load_addr = hextoul(argv[1], NULL);
+   filename = argv[2];
+   break;
+   default:
+   return CMD_RET_USAGE;
+   }
+
+   ret = ulwip_init();
+   if (ret) {
+   log_err("ulwip_init err %d\n", ret);
+   return CMD_RET_FAILURE;
+   }
+
+   ret = ulwip_tftp(image_load_addr, filename);
+   if (ret)
+   return ret;
+
+   return ulwip_loop();
+}
+#endif /* CONFIG_CMD_TFTPBOOT */
+
+#if defined(CONFIG_CMD_DHCP)
+int do_lwip_dhcp

[PATHv11 11/43] net/lwip: update .gitignore with lwIP

2023-11-27 Thread Maxim Uvarov
ignore lwIP library code and reused files from the lwIP.

Signed-off-by: Maxim Uvarov 
---
 net/lwip/.gitignore | 8 
 1 file changed, 8 insertions(+)
 create mode 100644 net/lwip/.gitignore

diff --git a/net/lwip/.gitignore b/net/lwip/.gitignore
new file mode 100644
index 00..7b5dacce90
--- /dev/null
+++ b/net/lwip/.gitignore
@@ -0,0 +1,8 @@
+lwip-external
+apps/ping/ping.c
+apps/http/http_client.c
+apps/http/http_client.h
+apps/tftp/tftp.c
+apps/tftp/tftp_client.h
+apps/tftp/tftp_common.h
+apps/tftp/tftp_example.h
-- 
2.30.2



[PATHv11 10/43] net/lwip: implement lwIP port to U-Boot

2023-11-27 Thread Maxim Uvarov
Implement port of lwIP stack to the U-Boot. lwIP is well known full IP stack
which provides wide functionality, various examples, API closer to linux 
userland.
Rich debug printing and possibility to run lwIP apps under linux make it
easier to develop and debug apps.
U-Boot implementation keeps the original file structure widely used for lwIP 
ports.
(i.e. port/if.c port/sys-arch.c). That should allow us to easy port apps to or
from U-Boot. Multiply ethernet devices are supported and "ethact" env variable
chooses the active device.
Having a rich IP stack inside U-Boot will allow us to have such applications
as http or https clients.

Signed-off-by: Maxim Uvarov 
---
 lib/Kconfig   |   2 +-
 net/eth-uclass.c  |  37 ++-
 net/lwip/Kconfig  |   1 +
 net/lwip/port/if.c| 327 ++
 net/lwip/port/include/arch/cc.h   |  44 
 net/lwip/port/include/arch/sys_arch.h |  10 +
 net/lwip/port/include/limits.h|   0
 net/lwip/port/sys-arch.c  |  13 +
 8 files changed, 426 insertions(+), 8 deletions(-)
 create mode 100644 net/lwip/port/if.c
 create mode 100644 net/lwip/port/include/arch/cc.h
 create mode 100644 net/lwip/port/include/arch/sys_arch.h
 create mode 100644 net/lwip/port/include/limits.h
 create mode 100644 net/lwip/port/sys-arch.c

diff --git a/lib/Kconfig b/lib/Kconfig
index 19649517a3..915402e843 100644
--- a/lib/Kconfig
+++ b/lib/Kconfig
@@ -258,7 +258,7 @@ config REGEX
 choice
prompt "Pseudo-random library support type"
depends on NET_RANDOM_ETHADDR || RANDOM_UUID || CMD_UUID || \
-  RNG_SANDBOX || UT_LIB && AES || FAT_WRITE
+  RNG_SANDBOX || UT_LIB && AES || FAT_WRITE || LWIP
default LIB_RAND
help
  Select the library to provide pseudo-random number generator
diff --git a/net/eth-uclass.c b/net/eth-uclass.c
index 3d0ec91dfa..f57da423f5 100644
--- a/net/eth-uclass.c
+++ b/net/eth-uclass.c
@@ -21,6 +21,7 @@
 #include 
 #include "eth_internal.h"
 #include 
+#include 
 
 DECLARE_GLOBAL_DATA_PTR;
 
@@ -32,6 +33,7 @@ DECLARE_GLOBAL_DATA_PTR;
 struct eth_device_priv {
enum eth_state_t state;
bool running;
+   ulwip ulwip;
 };
 
 /**
@@ -347,6 +349,13 @@ int eth_init(void)
return ret;
 }
 
+struct ulwip *eth_lwip_priv(struct udevice *current)
+{
+   struct eth_device_priv *priv = dev_get_uclass_priv(current);
+
+   return &priv->ulwip;
+}
+
 void eth_halt(void)
 {
struct udevice *current;
@@ -420,8 +429,13 @@ int eth_rx(void)
for (i = 0; i < ETH_PACKETS_BATCH_RECV; i++) {
ret = eth_get_ops(current)->recv(current, flags, &packet);
flags = 0;
-   if (ret > 0)
-   net_process_received_packet(packet, ret);
+   if (ret > 0) {
+   if (ulwip_active())
+   ulwip_poll(packet, ret);
+   else
+   net_process_received_packet(packet, ret);
+   }
+
if (ret >= 0 && eth_get_ops(current)->free_pkt)
eth_get_ops(current)->free_pkt(current, packet, ret);
if (ret <= 0)
@@ -555,6 +569,7 @@ static int eth_post_probe(struct udevice *dev)
struct eth_pdata *pdata = dev_get_plat(dev);
unsigned char env_enetaddr[ARP_HLEN];
char *source = "DT";
+   int ret;
 
priv->state = ETH_STATE_INIT;
priv->running = false;
@@ -587,18 +602,26 @@ static int eth_post_probe(struct udevice *dev)
/* Override the ROM MAC address */
memcpy(pdata->enetaddr, env_enetaddr, ARP_HLEN);
} else if (is_valid_ethaddr(pdata->enetaddr)) {
-   eth_env_set_enetaddr_by_index("eth", dev_seq(dev),
- pdata->enetaddr);
+   ret = eth_env_set_enetaddr_by_index("eth", dev_seq(dev),
+   pdata->enetaddr);
+   if (ret) {
+   log_err("Error update env for eth%d\n", dev_seq(dev));
+   return -EINVAL;
+   }
} else if (is_zero_ethaddr(pdata->enetaddr) ||
   !is_valid_ethaddr(pdata->enetaddr)) {
 #ifdef CONFIG_NET_RANDOM_ETHADDR
net_random_ethaddr(pdata->enetaddr);
printf("\nWarning: %s (eth%d) using random MAC address - %pM\n",
   dev->name, dev_seq(dev), pdata->enetaddr);
-   eth_env_set_enetaddr_by_index("eth", dev_seq(dev),
- pdata->enetaddr);
+   ret = eth_env_set_enetaddr_by_index("et

[PATHv11 09/43] net/lwip: add lwIP configuration

2023-11-27 Thread Maxim Uvarov
lwip configuration can be tuned with header file.

Signed-off-by: Maxim Uvarov 
---
 net/lwip/lwipopts.h | 178 
 1 file changed, 178 insertions(+)
 create mode 100644 net/lwip/lwipopts.h

diff --git a/net/lwip/lwipopts.h b/net/lwip/lwipopts.h
new file mode 100644
index 00..731da30baa
--- /dev/null
+++ b/net/lwip/lwipopts.h
@@ -0,0 +1,178 @@
+/* SPDX-License-Identifier: GPL-2.0+ */
+
+/*
+ * (C) Copyright 2023 Linaro Ltd. 
+ */
+
+#ifndef LWIP_LWIPOPTS_H
+#define LWIP_LWIPOPTS_H
+
+#include "lwipopts.h"
+
+#if defined(CONFIG_LWIP_LIB_DEBUG)
+#define LWIP_DEBUG 1
+#define LWIP_DBG_MIN_LEVEL  LWIP_DBG_LEVEL_ALL
+#define LWIP_DBG_TYPES_ON   LWIP_DBG_ON
+#define ETHARP_DEBUGLWIP_DBG_ON
+#define NETIF_DEBUG LWIP_DBG_ON
+#define PBUF_DEBUG  LWIP_DBG_OFF
+#define API_LIB_DEBUG   LWIP_DBG_ON
+#define API_MSG_DEBUG   LWIP_DBG_OFF
+#define SOCKETS_DEBUG   LWIP_DBG_OFF
+#define ICMP_DEBUG  LWIP_DBG_OFF
+#define IGMP_DEBUG  LWIP_DBG_OFF
+#define INET_DEBUG  LWIP_DBG_OFF
+#define IP_DEBUGLWIP_DBG_ON
+#define IP_REASS_DEBUG  LWIP_DBG_OFF
+#define RAW_DEBUG   LWIP_DBG_OFF
+#define MEM_DEBUG   LWIP_DBG_OFF
+#define MEMP_DEBUG  LWIP_DBG_OFF
+#define SYS_DEBUG   LWIP_DBG_OFF
+#define TIMERS_DEBUGLWIP_DBG_ON
+#define TCP_DEBUG   LWIP_DBG_OFF
+#define TCP_INPUT_DEBUG LWIP_DBG_OFF
+#define TCP_FR_DEBUGLWIP_DBG_OFF
+#define TCP_RTO_DEBUG   LWIP_DBG_OFF
+#define TCP_CWND_DEBUG  LWIP_DBG_OFF
+#define TCP_WND_DEBUG   LWIP_DBG_OFF
+#define TCP_OUTPUT_DEBUGLWIP_DBG_OFF
+#define TCP_RST_DEBUG   LWIP_DBG_OFF
+#define TCP_QLEN_DEBUG  LWIP_DBG_OFF
+#define UDP_DEBUG   LWIP_DBG_OFF
+#define TCPIP_DEBUG LWIP_DBG_OFF
+#define SLIP_DEBUG  LWIP_DBG_OFF
+#define DHCP_DEBUG  LWIP_DBG_ON
+#define AUTOIP_DEBUGLWIP_DBG_ON
+#define DNS_DEBUG   LWIP_DBG_ON
+#define IP6_DEBUG   LWIP_DBG_OFF
+#define DHCP6_DEBUG LWIP_DBG_OFF
+#else
+#define LWIP_DBG_MIN_LEVEL  LWIP_DBG_LEVEL_ALL
+#define LWIP_DBG_TYPES_ON   LWIP_DBG_OFF
+#define ETHARP_DEBUGLWIP_DBG_OFF
+#define NETIF_DEBUG LWIP_DBG_OFF
+#define PBUF_DEBUG  LWIP_DBG_OFF
+#define API_LIB_DEBUG   LWIP_DBG_OFF
+#define API_MSG_DEBUG   LWIP_DBG_OFF
+#define SOCKETS_DEBUG   LWIP_DBG_OFF
+#define ICMP_DEBUG  LWIP_DBG_OFF
+#define IGMP_DEBUG  LWIP_DBG_OFF
+#define INET_DEBUG  LWIP_DBG_OFF
+#define IP_DEBUGLWIP_DBG_OFF
+#define IP_REASS_DEBUG  LWIP_DBG_OFF
+#define RAW_DEBUG   LWIP_DBG_OFF
+#define MEM_DEBUG   LWIP_DBG_OFF
+#define MEMP_DEBUG  LWIP_DBG_OFF
+#define SYS_DEBUG   LWIP_DBG_OFF
+#define TIMERS_DEBUGLWIP_DBG_OFF
+#define TCP_DEBUG   LWIP_DBG_OFF
+#define TCP_INPUT_DEBUG LWIP_DBG_OFF
+#define TCP_FR_DEBUGLWIP_DBG_OFF
+#define TCP_RTO_DEBUG   LWIP_DBG_OFF
+#define TCP_CWND_DEBUG  LWIP_DBG_OFF
+#define TCP_WND_DEBUG   LWIP_DBG_OFF
+#define TCP_OUTPUT_DEBUGLWIP_DBG_OFF
+#define TCP_RST_DEBUG   LWIP_DBG_OFF
+#define TCP_QLEN_DEBUG  LWIP_DBG_OFF
+#define UDP_DEBUG   LWIP_DBG_OFF
+#define TCPIP_DEBUG LWIP_DBG_OFF
+#define SLIP_DEBUG  LWIP_DBG_OFF
+#define DHCP_DEBUG  LWIP_DBG_OFF
+#define AUTOIP_DEBUGLWIP_DBG_OFF
+#define DNS_DEBUG   LWIP_DBG_OFF
+#define IP6_DEBUG   LWIP_DBG_OFF
+#define DHCP6_DEBUG LWIP_DBG_OFF
+#endif
+#define LWIP_TESTMODE   0
+
+#if defined(CONFIG_LWIP_LIB_NOASSERT)
+#define LWIP_NOASSERT 1
+#define LWIP_ASSERT(message, assertion)
+#endif
+
+#include "lwip/debug.h"
+
+#define SYS_LIGHTWEIGHT_PROT0
+#define NO_SYS  1
+
+#define LWIP_IPV6  0
+
+#define MEM_ALIGNMENT   1
+#define MEM_SIZE1600
+
+#define MEMP_NUM_PBUF   4
+#define MEMP_NUM_RAW_PCB2
+#define MEMP_NUM_UDP_PCB4
+#def

[PATHv11 08/43] net/lwip: implement ping cmd

2023-11-27 Thread Maxim Uvarov
U-Boot recently got support for an alternative network stack using LWIP.
Replace ping command with the LWIP variant while keeping the output and
error messages identical. ping uses lwIP contrib/apps/ping/ping.c code.
Custom timeout is used to get an error message on not modified example.

Signed-off-by: Maxim Uvarov 
---
 Makefile   |  3 ++-
 include/net/lwip.h | 15 +
 net/lwip/Makefile  |  1 +
 net/lwip/apps/ping/Makefile| 12 +++
 net/lwip/apps/ping/lwip_ping.c | 39 ++
 net/lwip/apps/ping/lwip_ping.h | 15 +
 net/lwip/apps/ping/ping.h  | 28 
 7 files changed, 112 insertions(+), 1 deletion(-)
 create mode 100644 net/lwip/apps/ping/Makefile
 create mode 100644 net/lwip/apps/ping/lwip_ping.c
 create mode 100644 net/lwip/apps/ping/lwip_ping.h
 create mode 100644 net/lwip/apps/ping/ping.h

diff --git a/Makefile b/Makefile
index 132a60575a..769111bf09 100644
--- a/Makefile
+++ b/Makefile
@@ -2171,7 +2171,8 @@ CLEAN_FILES += include/autoconf.mk* include/bmp_logo.h 
include/bmp_logo_data.h \
   mkimage-out.spl.mkimage mkimage.spl.mkimage imx-boot.map \
   itb.fit.fit itb.fit.itb itb.map spl.map mkimage-out.rom.mkimage \
   mkimage.rom.mkimage mkimage-in-simple-bin* rom.map simple-bin* \
-  idbloader-spi.img lib/efi_loader/helloworld_efi.S *.itb
+  idbloader-spi.img lib/efi_loader/helloworld_efi.S *.itb \
+  net/lwip/apps/ping/ping.c
 
 # Directories & files removed with 'make mrproper'
 MRPROPER_DIRS  += include/config include/generated spl tpl vpl \
diff --git a/include/net/lwip.h b/include/net/lwip.h
index 04ffbec006..c9ea182d5d 100644
--- a/include/net/lwip.h
+++ b/include/net/lwip.h
@@ -2,6 +2,8 @@
 
 int do_lwip_dns(struct cmd_tbl *cmdtp, int flag, int argc,
char *const argv[]);
+int do_lwip_ping(struct cmd_tbl *cmdtp, int flag, int argc,
+char *const argv[]);
 
 /**
  * ulwip_dns() - creates the DNS request to resolve a domain host name
@@ -56,3 +58,16 @@ int ulwip_tftp(ulong addr, const char *filename);
  * Returns: 0 for success, !0 if error
  */
 int ulwip_wget(ulong addr, char *url);
+
+/**
+ * ulwip_ping - create the ping request
+ *
+ * This function creates the ping for  address provided in parameters.
+ * After this function you need to invoke the polling
+ * loop to process network communication.
+ *
+ *
+ * @ping_addr: IP address to ping
+ * Returns: 0 for success, !0 if error
+*/
+int ulwip_ping(char *ping_addr);
diff --git a/net/lwip/Makefile b/net/lwip/Makefile
index 61042862e1..5839d125c2 100644
--- a/net/lwip/Makefile
+++ b/net/lwip/Makefile
@@ -67,3 +67,4 @@ obj-y += apps/dhcp/lwip-dhcp.o
 obj-y += apps/dns/lwip-dns.o
 obj-y += apps/tftp/
 obj-y += apps/http/
+obj-y += apps/ping/
diff --git a/net/lwip/apps/ping/Makefile b/net/lwip/apps/ping/Makefile
new file mode 100644
index 00..e567c0dc3e
--- /dev/null
+++ b/net/lwip/apps/ping/Makefile
@@ -0,0 +1,12 @@
+ccflags-y += -I$(srctree)/net/lwip/port/include
+ccflags-y += -I$(srctree)/net/lwip/lwip-external/src/include 
-I$(srctree)/net/lwip
+ccflags-y += -I$(obj)
+
+# ping.c includes "ping.h", copy it to local directory, to override ping.h
+.PHONY: $(obj)/ping.c
+$(obj)/ping.o: $(obj)/ping.c
+$(obj)/ping.c:
+   cp $(srctree)/net/lwip/lwip-external/contrib/apps/ping/ping.c 
$(obj)/ping.c
+
+obj-y += ping.o
+obj-y += lwip_ping.o
diff --git a/net/lwip/apps/ping/lwip_ping.c b/net/lwip/apps/ping/lwip_ping.c
new file mode 100644
index 00..cdbe8d3eef
--- /dev/null
+++ b/net/lwip/apps/ping/lwip_ping.c
@@ -0,0 +1,39 @@
+// SPDX-License-Identifier: GPL-2.0
+
+/*
+ * (C) Copyright 2023 Linaro Ltd. 
+ */
+
+#include "lwip/opt.h"
+#include "lwip/ip_addr.h"
+#include "lwip/timeouts.h"
+#include 
+#include "ping.h"
+#include "lwip_ping.h"
+
+#define PING_WAIT_MS 5000
+
+static ip_addr_t ip_target;
+
+void ping_tmo(void *arg)
+{
+   log_err("%s: ping failed; host %s is not alive\n",
+   __func__, ipaddr_ntoa(&ip_target));
+   ulwip_exit(1);
+}
+
+int ulwip_ping(char *ping_addr)
+{
+   int err;
+
+   err = ipaddr_aton(ping_addr, &ip_target);
+   if (!err)
+   return -ENOENT;
+
+   sys_timeout(PING_WAIT_MS, ping_tmo, NULL);
+
+   ping_init(&ip_target);
+   ping_send_now();
+
+   return 0;
+}
diff --git a/net/lwip/apps/ping/lwip_ping.h b/net/lwip/apps/ping/lwip_ping.h
new file mode 100644
index 00..0374f07d9e
--- /dev/null
+++ b/net/lwip/apps/ping/lwip_ping.h
@@ -0,0 +1,15 @@
+/* SPDX-License-Identifier: GPL-2.0+ */
+
+/*
+ * (C) Copyright 2023 Linaro Ltd. 
+ */
+
+#ifndef LWIP_PING_H
+#define LWIP_PING_H
+
+#include 
+
+void ping_raw_init(void);
+void ping_send_now(void);
+
+#endif /* LWIP_PING_H */
diff --git a/net/lwip/apps/ping/ping.h b/net

[PATHv11 07/43] net/lwip: implement wget cmd

2023-11-27 Thread Maxim Uvarov
U-Boot recently got support for an alternative network stack using LWIP.
Replace wget command with the LWIP variant while keeping the output and
error messages identical.

Signed-off-by: Maxim Uvarov 
---
 include/net/lwip.h |  14 +
 net/lwip/Makefile  |   1 +
 net/lwip/apps/http/Makefile|   6 ++
 net/lwip/apps/http/lwip-wget.c | 105 +
 4 files changed, 126 insertions(+)
 create mode 100644 net/lwip/apps/http/Makefile
 create mode 100644 net/lwip/apps/http/lwip-wget.c

diff --git a/include/net/lwip.h b/include/net/lwip.h
index f025384c26..04ffbec006 100644
--- a/include/net/lwip.h
+++ b/include/net/lwip.h
@@ -42,3 +42,17 @@ int ulwip_dhcp(void);
  * Returns:  0 if success, !0 if error
  */
 int ulwip_tftp(ulong addr, const char *filename);
+
+/**
+ * ulwip_wget() - creates the HTTP request to download file
+ *
+ * This function creates the HTTP request to download file from url to the 
address
+ * specified in parameters. After this function you need to invoke the polling
+ * loop to process network communication.
+ *
+ *
+ * @addr:  start address to download result
+ * @url:   url in format http://host/url
+ * Returns: 0 for success, !0 if error
+ */
+int ulwip_wget(ulong addr, char *url);
diff --git a/net/lwip/Makefile b/net/lwip/Makefile
index b348e5ca31..61042862e1 100644
--- a/net/lwip/Makefile
+++ b/net/lwip/Makefile
@@ -66,3 +66,4 @@ obj-$(CONFIG_NET) += port/sys-arch.o
 obj-y += apps/dhcp/lwip-dhcp.o
 obj-y += apps/dns/lwip-dns.o
 obj-y += apps/tftp/
+obj-y += apps/http/
diff --git a/net/lwip/apps/http/Makefile b/net/lwip/apps/http/Makefile
new file mode 100644
index 00..ac0b3ede0d
--- /dev/null
+++ b/net/lwip/apps/http/Makefile
@@ -0,0 +1,6 @@
+ccflags-y += -I$(srctree)/net/lwip/port/include
+ccflags-y += -I$(srctree)/net/lwip/lwip-external/src/include 
-I$(srctree)/net/lwip
+ccflags-y += -I$(srctree)/net/lwip/lwip-external/src/include/lwip/apps
+
+obj-$(CONFIG_CMD_WGET) += ../../lwip-external/src/apps/http/http_client.o
+obj-$(CONFIG_CMD_WGET) += lwip-wget.o
diff --git a/net/lwip/apps/http/lwip-wget.c b/net/lwip/apps/http/lwip-wget.c
new file mode 100644
index 00..7a7cc3273d
--- /dev/null
+++ b/net/lwip/apps/http/lwip-wget.c
@@ -0,0 +1,105 @@
+// SPDX-License-Identifier: GPL-2.0
+
+/*
+ * (C) Copyright 2023 Linaro Ltd. 
+ */
+
+#include 
+#include 
+#include 
+#include 
+
+#include "http_client.h"
+#include 
+
+static ulong daddr;
+static httpc_connection_t settings;
+
+#define SERVER_NAME_SIZE 200
+#define HTTP_PORT_DEFAULT 80
+
+static err_t httpc_recv(void *arg, struct altcp_pcb *pcb, struct pbuf *pbuf,
+   err_t unused_err)
+{
+   struct pbuf *buf;
+
+   if (!pbuf)
+   return ERR_BUF;
+
+   for (buf = pbuf; buf != NULL; buf = buf->next) {
+   memcpy((void *)daddr, buf->payload, buf->len);
+   log_debug("downloaded chunk size %d, to addr 0x%lx\n",
+ buf->len, daddr);
+   daddr += buf->len;
+   }
+
+   altcp_recved(pcb, pbuf->tot_len);
+   pbuf_free(pbuf);
+   return ERR_OK;
+}
+
+static void httpc_result(void *arg, httpc_result_t httpc_result, u32_t 
rx_content_len,
+u32_t srv_res, err_t err)
+{
+   if (httpc_result == HTTPC_RESULT_OK) {
+   log_info("\n%d bytes successfully downloaded.\n", 
rx_content_len);
+   env_set_hex("filesize", rx_content_len);
+   ulwip_exit(0);
+   } else {
+   log_err("\nhttp eroror: %d\n", httpc_result);
+   ulwip_exit(-1);
+   }
+}
+
+/* http://hostname/url */
+static int parse_url(char *url, char *host, u16 *port)
+{
+   char *p, *pp;
+
+   p = strstr(url, "http://";);
+   if (!p)
+   return -ENOENT;
+
+   p += strlen("http://";);
+
+   /* parse hostname */
+   pp = strchr(p, '/');
+   if (!pp)
+   return -ENOENT;
+
+   if (p + SERVER_NAME_SIZE <= pp)
+   return -ENOENT;
+
+   memcpy(host, p, pp - p);
+   host[pp - p + 1] = '\0';
+   *port = HTTP_PORT_DEFAULT;
+
+   return 0;
+}
+
+int ulwip_wget(ulong addr, char *url)
+{
+   err_t err;
+   u16 port;
+   char server_name[SERVER_NAME_SIZE];
+   httpc_state_t *connection;
+
+   daddr = addr;
+
+   err = parse_url(url, server_name, &port);
+   if (err)
+   return -ENOENT;
+
+   log_info("downloading %s to addr 0x%lx\n", url, addr);
+   memset(&settings, 0, sizeof(settings));
+   settings.result_fn = httpc_result;
+   err = httpc_get_file_dns(server_name, port, url, &settings,
+httpc_recv, NULL,  &connection);
+   if (err != ERR_OK)
+   return -EPERM;
+
+   if (env_set_hex("fileaddr", addr))
+   return -EACCES;
+
+   return 0;
+}
-- 
2.30.2



[PATHv11 06/43] net/lwip: implement tftp cmd

2023-11-27 Thread Maxim Uvarov
U-Boot recently got support for an alternative network stack using LWIP.
Replace tftp command with the LWIP variant while keeping the output and
error messages identical.

Signed-off-by: Maxim Uvarov 
---
 include/net/lwip.h |  13 
 net/lwip/Makefile  |   1 +
 net/lwip/apps/tftp/Makefile|   7 ++
 net/lwip/apps/tftp/lwip-tftp.c | 132 +
 4 files changed, 153 insertions(+)
 create mode 100644 net/lwip/apps/tftp/Makefile
 create mode 100644 net/lwip/apps/tftp/lwip-tftp.c

diff --git a/include/net/lwip.h b/include/net/lwip.h
index 9941845f8c..f025384c26 100644
--- a/include/net/lwip.h
+++ b/include/net/lwip.h
@@ -29,3 +29,16 @@ int ulwip_dns(char *name, char *varname);
  * Other value < 0, if error
  **/
 int ulwip_dhcp(void);
+
+/**
+ * ulwip_tftp() - load file with tftp
+ *
+ * Load file with tftp to specific address
+ *
+ * @addr: Address to store downloaded file
+ * @filename: File name on remote tftp server to download
+ *
+ *
+ * Returns:  0 if success, !0 if error
+ */
+int ulwip_tftp(ulong addr, const char *filename);
diff --git a/net/lwip/Makefile b/net/lwip/Makefile
index a3a33b7f71..b348e5ca31 100644
--- a/net/lwip/Makefile
+++ b/net/lwip/Makefile
@@ -65,3 +65,4 @@ obj-$(CONFIG_NET) += port/sys-arch.o
 
 obj-y += apps/dhcp/lwip-dhcp.o
 obj-y += apps/dns/lwip-dns.o
+obj-y += apps/tftp/
diff --git a/net/lwip/apps/tftp/Makefile b/net/lwip/apps/tftp/Makefile
new file mode 100644
index 00..c3ad3c6353
--- /dev/null
+++ b/net/lwip/apps/tftp/Makefile
@@ -0,0 +1,7 @@
+ccflags-y += -I$(srctree)/net/lwip/port/include
+ccflags-y += -I$(srctree)/net/lwip/lwip-external/src/include 
-I$(srctree)/net/lwip
+ccflags-y += -I$(srctree)/net/lwip/lwip-external/src/include/lwip/apps
+ccflags-y += -I$(srctree)/net/lwip/lwip-external/contrib/examples/tftp/
+
+obj-y += ../../lwip-external/src/apps/tftp/tftp.o
+obj-y += lwip-tftp.o
diff --git a/net/lwip/apps/tftp/lwip-tftp.c b/net/lwip/apps/tftp/lwip-tftp.c
new file mode 100644
index 00..7b384cecf8
--- /dev/null
+++ b/net/lwip/apps/tftp/lwip-tftp.c
@@ -0,0 +1,132 @@
+// SPDX-License-Identifier: GPL-2.0
+
+/*
+ * (C) Copyright 2023 Linaro Ltd. 
+ */
+
+#include 
+#include 
+#include 
+#include 
+
+#include "tftp_client.h"
+#include "tftp_server.h"
+#include 
+
+#include 
+
+#include 
+
+static ulong daddr;
+static ulong size;
+static unsigned int progress_print;
+#define PROGRESS_PRINT 700 /* about one # per Megabyte */
+
+static void *tftp_open(const char *fname, const char *mode, u8_t is_write)
+{
+   return NULL;
+}
+
+static void tftp_close(void *handle)
+{
+   log_info("\ndone\n");
+   log_info("Bytes transferred = %ld (0x%lx hex)\n", size, size);
+
+   bootstage_mark_name(BOOTSTAGE_KERNELREAD_STOP, "tftp_done");
+   if (env_set_hex("filesize", size)) {
+   log_err("filesize not updated\n");
+   ulwip_exit(-1);
+   return;
+   }
+   ulwip_exit(0);
+}
+
+static int tftp_read(void *handle, void *buf, int bytes)
+{
+   return 0;
+}
+
+static int tftp_write(void *handle, struct pbuf *p)
+{
+   struct pbuf *q;
+
+   for (q = p; q != NULL; q = q->next) {
+   memcpy((void *)daddr, q->payload, q->len);
+   daddr += q->len;
+   size += q->len;
+   if (!(progress_print++ % PROGRESS_PRINT))
+   log_info("#");
+   }
+
+   return 0;
+}
+
+static void tftp_error(void *handle, int err, const char *msg, int size)
+{
+   char message[100];
+
+   memset(message, 0, sizeof(message));
+   memcpy(message, msg, LWIP_MIN(sizeof(message) - 1, (size_t)size));
+
+   log_info("TFTP error: %d (%s)", err, message);
+}
+
+static const struct tftp_context tftp = {
+   tftp_open,
+   tftp_close,
+   tftp_read,
+   tftp_write,
+   tftp_error
+};
+
+int ulwip_tftp(ulong addr, char *fname)
+{
+   void *f = (void *)0x1; /* unused fake file handle*/
+   err_t err;
+   ip_addr_t srv;
+   int ret;
+   char *server_ip;
+
+   if (!fname || addr == 0)
+   return CMD_RET_FAILURE;
+
+   size = 0;
+   daddr = addr;
+   server_ip = env_get("serverip");
+   if (!server_ip) {
+   log_err("error: serverip variable has to be set\n");
+   return CMD_RET_FAILURE;
+   }
+
+   ret = ipaddr_aton(server_ip, &srv);
+   if (!ret) {
+   log_err("error: ipaddr_aton\n");
+   return CMD_RET_FAILURE;
+   }
+
+   log_info("TFTP from server %s; our IP address is %s\n",
+server_ip, env_get("ipaddr"));
+   log_info("Filename '%s'.\n", fname);
+   log_info("Load address: 0x%lx\n", daddr);
+   log_info("Loading:");
+
+  

[PATHv11 05/43] net/lwip: implement dhcp cmd

2023-11-27 Thread Maxim Uvarov
U-Boot recently got support for an alternative network stack using LWIP.
Replace dhcp command with the LWIP variant while keeping the output and
error messages identical.

Signed-off-by: Maxim Uvarov 
---
 include/net/lwip.h | 12 +
 net/lwip/Makefile  |  1 +
 net/lwip/apps/dhcp/lwip-dhcp.c | 86 ++
 3 files changed, 99 insertions(+)
 create mode 100644 net/lwip/apps/dhcp/lwip-dhcp.c

diff --git a/include/net/lwip.h b/include/net/lwip.h
index ab3db1a214..9941845f8c 100644
--- a/include/net/lwip.h
+++ b/include/net/lwip.h
@@ -17,3 +17,15 @@ int do_lwip_dns(struct cmd_tbl *cmdtp, int flag, int argc,
  *  Other value < 0, if error
  */
 int ulwip_dns(char *name, char *varname);
+
+/**
+ * ulwip_dhcp() -  create the DHCP request to obtain IP address.
+ *
+ * This function creates the DHCP request to obtain IP address. If DHCP server
+ * returns file name, this file will be downloaded with tftp.  After this
+ * function you need to invoke the polling loop to process network 
communication.
+ *
+ * Returns: 0 if success
+ * Other value < 0, if error
+ **/
+int ulwip_dhcp(void);
diff --git a/net/lwip/Makefile b/net/lwip/Makefile
index 5d8d5527c6..a3a33b7f71 100644
--- a/net/lwip/Makefile
+++ b/net/lwip/Makefile
@@ -63,4 +63,5 @@ obj-$(CONFIG_NET) += lwip-external/src/netif/ethernet.o
 obj-$(CONFIG_NET) += port/if.o
 obj-$(CONFIG_NET) += port/sys-arch.o
 
+obj-y += apps/dhcp/lwip-dhcp.o
 obj-y += apps/dns/lwip-dns.o
diff --git a/net/lwip/apps/dhcp/lwip-dhcp.c b/net/lwip/apps/dhcp/lwip-dhcp.c
new file mode 100644
index 00..966b3991ee
--- /dev/null
+++ b/net/lwip/apps/dhcp/lwip-dhcp.c
@@ -0,0 +1,86 @@
+// SPDX-License-Identifier: GPL-2.0
+
+/*
+ * (C) Copyright 2023 Linaro Ltd. 
+ */
+
+#include 
+#include 
+#include 
+
+#include 
+#include 
+#include "lwip/timeouts.h"
+
+#include 
+#include 
+
+#define DHCP_TMO_TIME 1000 /* poll for DHCP state change */
+#define DHCP_TMO_NUM  20  /* number of tries */
+
+typedef struct dhcp_priv {
+   int num_tries;
+   struct netif *netif;
+} dhcp_priv;
+
+static void dhcp_tmo(void *arg)
+{
+   struct dhcp_priv *dpriv = (struct dhcp_priv *)arg;
+   struct netif *netif = dpriv->netif;
+   struct dhcp *dhcp;
+
+   log_err("%s %d/%d\n", __func__, dpriv->num_tries, DHCP_TMO_NUM);
+   dhcp = netif_get_client_data(netif, LWIP_NETIF_CLIENT_DATA_INDEX_DHCP);
+   if (!dhcp)
+   return;
+
+   if (dhcp->state == DHCP_STATE_BOUND) {
+   int err = 0;
+
+   err -= env_set("bootfile", dhcp->boot_file_name);
+   err -= env_set("ipaddr", ip4addr_ntoa(&dhcp->offered_ip_addr));
+   err -= env_set("netmask", ip4addr_ntoa(&dhcp->offered_sn_mask));
+   err -= env_set("serverip", ip4addr_ntoa(&dhcp->server_ip_addr));
+   if (err)
+   log_err("error update envs\n");
+   log_info("DHCP client bound to address %s\n", 
ip4addr_ntoa(&dhcp->offered_ip_addr));
+   free(dpriv);
+   ulwip_exit(err);
+   return;
+   }
+
+   dpriv->num_tries--;
+   if (dpriv->num_tries < 0) {
+   log_err("DHCP client timeout\n");
+   free(dpriv);
+   ulwip_exit(-1);
+   return;
+   }
+
+   sys_timeout(DHCP_TMO_TIME, dhcp_tmo, dpriv);
+}
+
+int ulwip_dhcp(void)
+{
+   struct netif *netif;
+   int eth_idx;
+   struct dhcp_priv *dpriv;
+
+   dpriv = malloc(sizeof(struct dhcp_priv));
+   if (!dpriv)
+   return -EPERM;
+
+   eth_idx = eth_get_dev_index();
+   if (eth_idx < 0)
+   return -EPERM;
+
+   netif = netif_get_by_index(eth_idx + 1);
+   if (!netif)
+   return -ENOENT;
+
+   dpriv->num_tries = DHCP_TMO_NUM;
+   dpriv->netif = netif;
+   sys_timeout(DHCP_TMO_TIME, dhcp_tmo, dpriv);
+
+   return dhcp_start(netif) ? -EPERM : 0;
+}
-- 
2.30.2



  1   2   3   >