From mboxrd@z Thu Jan 1 00:00:00 1970 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 91161C04A6A for ; Mon, 14 Aug 2023 14:25:34 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id EA2328678A; Mon, 14 Aug 2023 16:25:32 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org 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; unprotected) header.d=linaro.org header.i=@linaro.org header.b="NBMN7IH+"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id D2809867F7; Mon, 14 Aug 2023 16:25:31 +0200 (CEST) Received: from mail-wm1-x336.google.com (mail-wm1-x336.google.com [IPv6:2a00:1450:4864:20::336]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id D637F86679 for ; Mon, 14 Aug 2023 16:25:29 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=ilias.apalodimas@linaro.org Received: by mail-wm1-x336.google.com with SMTP id 5b1f17b1804b1-3fe490c05c9so31041315e9.0 for ; Mon, 14 Aug 2023 07:25:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1692023129; x=1692627929; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=jIg5efVUqjAjU5lXkyX4XHI+UTFUVcJd0FnOFtYYNdU=; b=NBMN7IH+kUxwzQqAlW6SQ+P3QaElZWJYHeFcqf4a/gR/sNCk72DCQPNnzsZMOoQIw+ uBN/1coDgaWJ21aC15iBKIEQN7/ufDEepz04n6miWxWG/Oj7kbG0+CUNTG+JjBuVZ/N2 59PktUTAB6MBoytr+2Nxbu3/rL2uOMxVrNhVZjqrsjk0UT7MKL65WmKLSJpwI5RAkF5f jxvLsluKF81nYhmgsj/uq4auuWtgTQRuNsTUvsK6FodTKD5EUYPy0RRpilbwvHEgYCxi ewGAjSv8XOzlsA7ocg+0TkE2YqihwWvqCWwIHk4WZ/tSe6E0aiYDjn+73WOrNg767hNT qgxA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692023129; x=1692627929; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=jIg5efVUqjAjU5lXkyX4XHI+UTFUVcJd0FnOFtYYNdU=; b=P8j8Gr2JcGPWsdXVcCtyC1X1RgEIMgxUYpZ6Y5kigJdJ281lTPC+1vJ3nlysH551bU cpp8x3v7ivFglOuOx8aj3XSVFVIiuq17tc46UpumZ6bZbxVDOgw8Bqm7+dZTdJ2/LjvI Ya8oZTajlhc6Ni325vIPTjWMm1Ft+hSlDJkLXYG7voRfxNVeSFS8xlGV99XCf5ED1dmS Y4GK2ekhf3x6xtB5oeOot+yUyos4BhG1RCAfQQMlhZiu3prAK3zlq+xMSwjYVd0nKYcC vIRrBX9WC6JBDmJ1+jy4ENad5FnIWdoKkG2SvvEIPczDjTf1TJGaWWVbbLnsZUgsDTe9 YdlA== X-Gm-Message-State: AOJu0YxWqYXb/+D+jIFX1Ptkrs0395X2V2GI+rPWIjubHc9CfrbHcEMH cZv3FDhePUqeCicH7FJERu1KGA== X-Google-Smtp-Source: AGHT+IG4iU2l4Elgq9QOhvlq3LeWeQiEhdi2PF379a05NOTNdqSiI8sUHtE/KhaCNgYLtDIBOceXGQ== X-Received: by 2002:adf:ec52:0:b0:319:7363:f172 with SMTP id w18-20020adfec52000000b003197363f172mr3461444wrn.17.1692023129323; Mon, 14 Aug 2023 07:25:29 -0700 (PDT) Received: from hades (ppp089210246083.access.hol.gr. [89.210.246.83]) by smtp.gmail.com with ESMTPSA id z11-20020adfe54b000000b002c70ce264bfsm14567516wrm.76.2023.08.14.07.25.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Aug 2023 07:25:29 -0700 (PDT) Date: Mon, 14 Aug 2023 17:25:26 +0300 From: Ilias Apalodimas To: Maxim Uvarov Cc: u-boot@lists.denx.de, pbrobinson@redhat.com, joe.hershberger@ni.com, rfried.dev@gmail.com, trini@konsulko.com, goldsimon@gmx.de, lwip-devel@nongnu.org Subject: Re: [PATCHv6 05/14] net/lwip: implement tftp cmd Message-ID: References: <20230814133253.4150-1-maxim.uvarov@linaro.org> <20230814133253.4150-6-maxim.uvarov@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20230814133253.4150-6-maxim.uvarov@linaro.org> 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 > +// SPDX-License-Identifier: GPL-2.0 > + > +/* > + * (C) Copyright 2023 Linaro Ltd. > + */ > + > +#include > +#include > +#include > +#include > + > +#include "lwip/apps/tftp_client.h" > +#include "lwip/apps/tftp_server.h" > +#include > + > +#include > + > +#include > + > +#if LWIP_UDP Why do we have this? I dont think it makes sense to start reasoning about LWIP config options from within U-Boot code. Instead U-Boot makefiles should enable all the LWIP features we need when a command is included > + > +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) > +{ > + log_info("\ndone\n"); > + log_info("Bytes transferred = %ld (0x%lx hex)\n", size, size); > + > + bootstage_mark_name(BOOTSTAGE_KERNELREAD_STOP, "tftp_done"); > + 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 = p; q != NULL; q = q->next) { > + memcpy((void *)daddr, q->payload, q->len); > + daddr += q->len; > + size += q->len; > + log_info("#"); > + } > + > + return 0; > +} > + > +static void tftp_error(void *handle, int err, const char *msg, int size) > +{ > + char message[100]; > + > + LWIP_UNUSED_ARG(handle); > + > + 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:"); > + > + bootstage_mark_name(BOOTSTAGE_KERNELREAD_START, "tftp_start"); > + > + err = tftp_init_client(&tftp); > + if (!(err == ERR_OK || err == ERR_USE)) > + log_err("tftp_init_client err: %d\n", err); > + > + err = tftp_get(f, &srv, TFTP_PORT, fname, TFTP_MODE_OCTET); Shouldn't this be part of tftp_read()? > + /* might return different errors, like routing problems */ > + if (err != ERR_OK) { > + log_err("tftp_get err=%d\n", err); > + return CMD_RET_FAILURE; > + } > + > + env_set_hex("fileaddr", addr); > + return err; > +} > +#else > +#error "UDP has to be supported" > +#endif /* LWIP_UDP */ > -- > 2.30.2 >