Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 604ACC04FE1 for ; Thu, 10 Aug 2023 19:23:46 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 76C27868AB; Thu, 10 Aug 2023 21:23:44 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmx.de Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; secure) header.d=gmx.de header.i=goldsimon@gmx.de header.b="NH+OoCua"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id D282B868AE; Thu, 10 Aug 2023 21:23:43 +0200 (CEST) Received: from mout.gmx.net (mout.gmx.net [212.227.15.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id D39C28689A for ; Thu, 10 Aug 2023 21:23:41 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmx.de Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=goldsimon@gmx.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.de; s=s31663417; t=1691695416; x=1692300216; i=goldsimon@gmx.de; bh=R7WrghE6PA/p/DjJBEw4PD9KI8qirSDvHDfNQiCTiJ0=; h=X-UI-Sender-Class:Date:Subject:To:Cc:References:From:In-Reply-To; b=NH+OoCuamYs7fhbc8Ca7qhzox9OO35maLdmte69IyN+rh2KbUeyjfS6uqwV2RzLoqGJJ6fk r+VrbaVH4rH1AQtU8tV5w6PO5Dsbu5xiS5A61mTjE8m4d7sLmoeMT5Xn3LP5aearSOgc1qYmp IiUaqBccJAHdqWDIjV9ZyqKr/BAqgo1CV4U2w7vzgfplmZVpGVxHoy46LM/315u9XHnYfDh5j s4wYm41euWbdBpr/eyjyRk+JZxYtP49knhMxxvO9O6zyC0JF1bIU5oLNA7HIaFuec2fQV1gEj fcqZcS0YcbiNfQL9R1pvshyuFjXXofaUWvJaN2pXmL43KnwQBFdQ== X-UI-Sender-Class: 724b4f7f-cbec-4199-ad4e-598c01a50d3a Received: from [10.21.196.188] ([91.133.75.161]) by mail.gmx.net (mrgmx005 [212.227.17.190]) with ESMTPSA (Nemesis) id 1Mzyya-1pYd9a2h9C-00x0NH; Thu, 10 Aug 2023 21:23:36 +0200 Message-ID: <80ef8cc9-6dc1-e703-0291-32c66e009e5b@gmx.de> Date: Thu, 10 Aug 2023 21:23:37 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Thunderbird/102.14.0 Subject: Re: [PATCHv5 05/13] net/lwip: implement tftp cmd Content-Language: en-US To: Maxim Uvarov , Ilias Apalodimas Cc: u-boot@lists.denx.de, pbrobinson@redhat.com, joe.hershberger@ni.com, rfried.dev@gmail.com, trini@konsulko.com, lwip-devel@nongnu.org References: <20230802140658.10319-1-maxim.uvarov@linaro.org> <20230802140658.10319-6-maxim.uvarov@linaro.org> From: Simon Goldschmidt In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: quoted-printable X-Provags-ID: V03:K1:jHMCD29N/y7SRCzyt+OMoIrLk3Srlt97IeQr5g2gb3bSNl/VMCu nJi8CUc++l65WXS0XIjhfWwsCOaKNtIIF38tjc+V0aepJ0di3SBUAhQ8NDjKwFQ8kFhOdre 5nDp1VuGnht7bHb8yAvl7H6QA9HbuG6by3ZvYytFTfzqSn0oiEOCcI/v0vSgA4wd+juA5U/ gd+hjcQmWZs/zHQ6nJ7tQ== UI-OutboundReport: notjunk:1;M01:P0:G89SzTZ3uno=;NwDGciRu9ur3B35NkoHhoqmudmk tONC6OX47k2GoxZxaGRUbJPEQy/Ll4vhj+dRTlNVLOrz43/9kcdjg0ImTDcNA3+59Hbu9Kg4U cF9LrsVCghWXZnn+wNhc5lPJJKdt+Vcn+Ue/qELNieSBYN6tZivX/hGP90kNUwmxPFBGjBghU LYuU5bDevY0HDAwRwNv/xTANizRYh9ZKPrBBnb1w6iCaQRXD8KTw+dzhwRCgjOdWV6zyzM7fn LguicxcdwtKePmvWq35QuPFo93Y45tHLH624cxIV+WT6M93k9A2wjr0/ct9gelBuq4+1S84PB YOqt4ddzQvMOqbT76b9rZlawh3ghfQ97ERIL3i+l4/IkbI4jMmXfNTBF5sOWXM0s4gz7IeGI8 Jw1+O7nWGwtMP/CIVnUFWgCFtylLIqiyC2VswgOInFfzLE0LE6mpuYaF547FfZRuWukAWB3at 9YOhWoiozX85i2eBsEpXXHdVUlv9Sdpp5tOKSyLT60WoRW/bEvCC0PHBFqanA3xeTBRvd45hc SsFeZ60ByZR6h+054cCQrldjD9iSULoHCKMy9uEO2iuYEVdLGPumfiDRVoMGKyC/xLZ3iv6WZ 6M+n6tz811aWPx6J7n5QFxeesXqaf7AkSKRChB2YZvFqoyy6swb3dWdC4bW0UK5M97+zpPUfb y+xhcZ//pgSJN7RAoRaXegr1hKrOoXBvYyZHiqCFyWuKbWujNc4pXWaglldqp/bfICsCrek3T lPy6f3kTGL7Vp0czcJSdywoELaYz1X5br6yZAm9xWymODhKt21ngTZHbxkvuI1y/qxBXAfUe9 5tLtgBBmz352w1Xl9iIiCNNiUdkx4Ib71bTpuGdzOW6HxC4ZNAhCsM3R+MUkt2wt3/QsnHdqJ QNGwV0eGSDthAVfENcwsPPnXsOpdBew++udM6LfPfeB94BpfCRjVxN+q6X5XRCRUkW3xBFIkI JvNjKQ== X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.8 at phobos.denx.de X-Virus-Status: Clean On 10.08.2023 13:28, Maxim Uvarov wrote: > On Thu, 3 Aug 2023 at 12:42, Ilias Apalodimas > wrote: > >> On Wed, Aug 02, 2023 at 08:06:50PM +0600, Maxim Uvarov wrote: >>> Signed-off-by: Maxim Uvarov >>> --- >>> lib/lwip/Makefile | 1 + >>> lib/lwip/apps/tftp/Makefile | 16 +++++ >>> lib/lwip/apps/tftp/lwip-tftp.c | 124 +++++++++++++++++++++++++++++++= ++ >>> 3 files changed, 141 insertions(+) >>> create mode 100644 lib/lwip/apps/tftp/Makefile >>> create mode 100644 lib/lwip/apps/tftp/lwip-tftp.c >>> >>> diff --git a/lib/lwip/Makefile b/lib/lwip/Makefile >>> index a3521a9d18..1893162c1a 100644 >>> --- a/lib/lwip/Makefile >>> +++ b/lib/lwip/Makefile >>> @@ -67,3 +67,4 @@ obj-$(CONFIG_NET) +=3D port/sys-arch.o >>> >>> obj-$(CONFIG_CMD_DHCP) +=3D apps/dhcp/lwip-dhcp.o >>> obj-$(CONFIG_CMD_DNS) +=3D apps/dns/lwip-dns.o >>> +obj-$(CONFIG_CMD_TFTPBOOT) +=3D apps/tftp/ >>> diff --git a/lib/lwip/apps/tftp/Makefile b/lib/lwip/apps/tftp/Makefile >>> new file mode 100644 >>> index 0000000000..299c95e9c0 >>> --- /dev/null >>> +++ b/lib/lwip/apps/tftp/Makefile >>> @@ -0,0 +1,16 @@ >>> + >>> +ccflags-y +=3D -I$(srctree)/lib/lwip/port/include >>> +ccflags-y +=3D -I$(srctree)/lib/lwip/lwip-external/src/include >> -I$(srctree)/lib/lwip >>> +ccflags-y +=3D -I$(obj) >>> + >>> +$(obj)/tftp.o: $(obj)/tftp.c >>> +.PHONY: $(obj)/tftp.c >>> +$(obj)/tftp.c: >>> + cp $(srctree)/lib/lwip/lwip-external/src/apps/tftp/tftp.c >> $(obj)/tftp.c >>> + cp >> $(srctree)/lib/lwip/lwip-external/src/include/lwip/apps/tftp_client.h >> $(obj)/tftp_client.h >>> + cp >> $(srctree)/lib/lwip/lwip-external/src/include/lwip/apps/tftp_common.h >> $(obj)/tftp_common.h >>> + cp >> $(srctree)/lib/lwip/lwip-external/contrib/examples/tftp/tftp_example.h >> $(obj)/tftp_example.h >>> + >>> +obj-$(CONFIG_CMD_TFTPBOOT) +=3D tftp.o >>> +obj-$(CONFIG_CMD_TFTPBOOT) +=3D lwip-tftp.o >>> + >>> diff --git a/lib/lwip/apps/tftp/lwip-tftp.c >> b/lib/lwip/apps/tftp/lwip-tftp.c >>> new file mode 100644 >>> index 0000000000..511d82e600 >>> --- /dev/null >>> +++ b/lib/lwip/apps/tftp/lwip-tftp.c >>> @@ -0,0 +1,124 @@ >>> +// SPDX-License-Identifier: GPL-2.0 >>> + >>> +/* >>> + * (C) Copyright 2023 Linaro Ltd. >>> + */ >>> + >>> +#include >>> +#include >>> +#include >>> + >>> +#include "lwip/apps/tftp_client.h" >>> +#include "lwip/apps/tftp_server.h" >>> +#include >>> + >>> +#include >>> + >>> +#include "../../../lwip/ulwip.h" >>> + >>> +#if LWIP_UDP >>> + >>> +static ulong daddr; >>> +static ulong size; >>> + >>> +static void *tftp_open(const char *fname, const char *mode, u8_t >> is_write) >>> +{ >>> + LWIP_UNUSED_ARG(mode); >>> + return NULL; >>> +} >>> + >>> +static void tftp_close(void *handle) >>> +{ >>> + printf("\ndone\n"); >>> + printf("Bytes transferred =3D %ld (0x%lx hex)\n", size, size); >> >> Can you replace all the printf occurences with log_XXXX ? >> >>> + >>> + env_set_ulong("filesize", size); >>> + 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 =3D p; q !=3D NULL; q =3D q->next) { >>> + memcpy((void *)daddr, q->payload, q->len); >>> + /* printf("downloaded chunk size %d, to addr 0x%lx\n", >> q->len, daddr); */ >> >> Remove all those debug comments on the next version >> >>> + daddr +=3D q->len; >>> + size +=3D q->len; >>> + printf("#"); >>> + } >>> + >>> + return 0; >>> +} >>> + >>> +/* For TFTP client only */ >>> +static void tftp_error(void *handle, int err, const char *msg, int si= ze) >>> +{ >>> + char message[100]; >>> + >>> + LWIP_UNUSED_ARG(handle); >>> + >>> + memset(message, 0, sizeof(message)); >>> + MEMCPY(message, msg, LWIP_MIN(sizeof(message)-1, (size_t)size)); >> >> Why aren't we using the native memcpy? >> >>> + >>> + printf("TFTP error: %d (%s)", err, message); >>> +} >>> + >>> +static const struct tftp_context tftp =3D { >>> + tftp_open, >>> + tftp_close, >>> + tftp_read, >>> + tftp_write, >>> + tftp_error >>> +}; >>> + >>> +int lwip_tftp(ulong addr, char *fname) >>> +{ >>> + void *f =3D (void *)0x1; /*fake handle*/ >> >> If it's fake can't it just be NULL? What does 'fake' mean? is that safe= to >> be passed around the LWIP APIs? >> >> > Here I reuse a tftp example from lwIP. f here is a file handle to write > output. I do write to memory and do not use this value. > But there is a check that his value can not be NULL. So something needs = to > be passed here to not do modifications to > the example code. Sorry I did not have the time to follow all your patches here throgouhly enough. However, if things like this come up, please also do not hesitate to come to us (lwip developers) with ideas to make our code more easily integratable into target applications (like U-Boot here). As I said before (to Maxim in a private mail I think), I think it would be best to start targeting this integration based on lwIP's master branch, so modifications in the upstream lwIP sources would be possible to make this work neatly. Regards, Simon > > >> >>> + err_t err; >>> + ip_addr_t srv; >>> + int ret; >>> + char *server_ip; >>> + >>> + if (!fname || addr =3D=3D 0) >>> + return CMD_RET_FAILURE; >>> + >>> + size =3D 0; >>> + daddr =3D addr; >>> + server_ip =3D env_get("serverip"); >>> + if (!server_ip) { >>> + printf("error: serverip variable has to be set\n"); >>> + return CMD_RET_FAILURE; >>> + } >>> + >>> + ret =3D ipaddr_aton(server_ip, &srv); >>> + LWIP_ASSERT("ipaddr_aton failed", ret =3D=3D 1); >>> + >>> + printf("TFTP from server %s; our IP address is %s\n", >>> + server_ip, env_get("ipaddr")); >>> + printf("Filename '%s'.\n", fname); >>> + printf("Load address: 0x%lx\n", daddr); >>> + printf("Loading:"); >>> + >>> + err =3D tftp_init_client(&tftp); >>> + if (!(err =3D=3D ERR_OK || err =3D=3D ERR_USE)) >>> + printf("tftp_init_client err: %d\n", err); >>> + >>> + err =3D tftp_get(f, &srv, TFTP_PORT, fname, TFTP_MODE_OCTET); >>> + /* might return different errors, like routing problems */ >>> + if (err !=3D ERR_OK) { >>> + printf("tftp_get err=3D%d\n", err); >>> + } >>> + LWIP_ASSERT("tftp_get failed", err =3D=3D ERR_OK); >>> + >>> + env_set_hex("fileaddr", addr); >>> + return err; >>> +} >>> +#else >>> +#error "UDP has to be supported" >>> +#endif /* LWIP_UDP */ >>> -- >>> 2.30.2 >>> >> >