Make DFU TFTP compatible with LwIP by implementing a slightly different
and simpler TFTP loading using do_tftpb_raw(). The loader supports all
the functionality that was supported by legacy network stack, but has
to implement CONFIG_UPDATE_TFTP_CNT_MAX manually.

Tested on Renesas R-Car H3 Salvator-X(S) board using both:
=> env set updatefile update.itb ; env set loadaddr 0x50000000 ; dfu tftp
=> tftp 0x50000000 update.itb && dfu tftp 0x50000000

Signed-off-by: Marek Vasut <[email protected]>
---
Cc: Ilias Apalodimas <[email protected]>
Cc: James Hilliard <[email protected]>
Cc: Jerome Forissier <[email protected]>
Cc: Lukasz Majewski <[email protected]>
Cc: Mattijs Korpershoek <[email protected]>
Cc: Quentin Schulz <[email protected]>
Cc: Tom Rini <[email protected]>
Cc: [email protected]
---
 common/update.c     | 27 +++++++++++++++++++++++++++
 drivers/dfu/Kconfig |  2 --
 2 files changed, 27 insertions(+), 2 deletions(-)

diff --git a/common/update.c b/common/update.c
index 06e53cbd402..1c3ecf47a39 100644
--- a/common/update.c
+++ b/common/update.c
@@ -30,6 +30,8 @@ extern int tftp_timeout_count_max;
 #include <mtd/cfi_flash.h>
 static uchar *saved_prot_info;
 #endif
+
+#if CONFIG_IS_ENABLED(NET_LEGACY)
 static int update_load(char *filename, ulong msec_max, int cnt_max, ulong addr)
 {
        int rv, ret;
@@ -77,6 +79,31 @@ static int update_load(char *filename, ulong msec_max, int 
cnt_max, ulong addr)
 
        return rv;
 }
+#else
+static int update_load(char *filename, ulong msec_max, int cnt_max, ulong addr)
+{
+       /* save used globals and env variable */
+       char *saved_netretry = strdup(env_get("netretry"));
+       int i, ret;
+
+       /* we don't want to retry the connection if errors occur */
+       env_set("netretry", "no");
+
+       for (i = 0; i <= CONFIG_UPDATE_TFTP_CNT_MAX; i++) {
+               ret = do_tftpb_raw(addr, filename, NULL, NULL, 
CONFIG_UPDATE_TFTP_MSEC_MAX);
+               if (ret)
+                       continue;
+
+               flush_cache(addr, net_boot_file_size);
+               break;
+       }
+
+       env_set("netretry", saved_netretry);
+       free(saved_netretry);
+
+       return ret;
+}
+#endif
 
 #ifdef CONFIG_MTD_NOR_FLASH
 static int update_flash_protect(int prot, ulong addr_first, ulong addr_last)
diff --git a/drivers/dfu/Kconfig b/drivers/dfu/Kconfig
index eeae2fd65ad..224a229866b 100644
--- a/drivers/dfu/Kconfig
+++ b/drivers/dfu/Kconfig
@@ -11,7 +11,6 @@ config DFU_OVER_USB
 
 config DFU_OVER_TFTP
        bool
-       depends on NET_LEGACY
 
 config DFU_WRITE_ALT
        bool
@@ -20,7 +19,6 @@ if DFU
 config DFU_TFTP
        bool "DFU via TFTP"
        depends on NETDEVICES
-       depends on !NET_LWIP
        select UPDATE_COMMON
        select DFU_OVER_TFTP
        help
-- 
2.53.0

Reply via email to