From patchwork Mon Aug 14 13:32:44 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxim Uvarov X-Patchwork-Id: 713474 Delivered-To: patch@linaro.org Received: by 2002:a5d:4012:0:b0:317:ecd7:513f with SMTP id n18csp1242246wrp; Mon, 14 Aug 2023 06:36:07 -0700 (PDT) X-Google-Smtp-Source: AGHT+IF5UX0rE72IYq9AWMlk24/qYAIO7/J9gxNehpxbUfY5reEkFqMwkGBhXBsZP5gbVWpUUHM6 X-Received: by 2002:a5d:55c8:0:b0:319:74b5:b67d with SMTP id i8-20020a5d55c8000000b0031974b5b67dmr2966552wrw.66.1692020167583; Mon, 14 Aug 2023 06:36:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1692020167; cv=none; d=google.com; s=arc-20160816; b=U/jXpI7+HQyOsTBjwQmHZAlYMcHAQPpfsybXlFC2D49fKmi5OVbuuScI7pyeddFj0d kU8AJn/X5zM+3gUYRvXhVPpXLTtAU1gpY/WZfXIvEU2AGFKeJR2kLLZnR2mWv4xGYDX1 xblgqN1FlWKSRnDoAK/d/YvJazDiDFJKVGfs/zodDPD6d1VztwqaIHGYEv22j/C2PeSe ghmAHNgF2/w06seNdUtj4ICUepXXyW87VmDcRAtJjzYMDhJFBVdJNsjranMLJGy+33WM fdGwZUfPjg7oOk83IPwvmhi521TdrjKyKv4Ljx25hb8JBs2Lx+pvPHLGwO2kQi+F3Va+ 767g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=r8QdYd3MXhSbKcLqvYgrLdNh1oz8Fq8WB7WcnBC03uk=; fh=KONqw1VFBW9nCv9imase+52c+XJ0MeVkzLj6SOLcJqQ=; b=B4emH+hUvZ7ilImIOQcqvg2kqUshCHRJwpZOZvNc7Ik/RH4A3jrq3pgm1VhXdUqzcM 80ibCXY/97/zTo5Z3Tr3tkeRW3KxKNQ9Xqal8Yg+EL0lOb8IWif+5lNEJ6vnHvTq2Zx0 k4wJP4qu6SB274zkjkDqHXoJV/rZDmF+Je6wdxT52Q42hwKMhv21URSTkYlpWxSnnHzh nbgXloRK+kZytiwiOevDNJ2bnHo3oREp5KDbLytOGctSdxBvPShy5rqD+/NWjqpGf1dc Us8O9kDvI9Oypgxqqpv2xAYg3Z9/JzMGizasGEsGrP2V4iUKBYg9TbEIAHWxPjKGD69n yKrw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=zg7YsrZ0; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from phobos.denx.de (phobos.denx.de. [2a01:238:438b:c500:173d:9f52:ddab:ee01]) by mx.google.com with ESMTPS id b12-20020adff24c000000b003176361290asi5259305wrp.822.2023.08.14.06.36.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Aug 2023 06:36:07 -0700 (PDT) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=zg7YsrZ0; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id EAB5586983; Mon, 14 Aug 2023 15:35:27 +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="zg7YsrZ0"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 723CD807B4; Mon, 14 Aug 2023 15:35:26 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-lj1-x22b.google.com (mail-lj1-x22b.google.com [IPv6:2a00:1450:4864:20::22b]) (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 734AA807B3 for ; Mon, 14 Aug 2023 15:35:24 +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=maxim.uvarov@linaro.org Received: by mail-lj1-x22b.google.com with SMTP id 38308e7fff4ca-2b9bb097c1bso65033331fa.0 for ; Mon, 14 Aug 2023 06:35:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1692020123; x=1692624923; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=r8QdYd3MXhSbKcLqvYgrLdNh1oz8Fq8WB7WcnBC03uk=; b=zg7YsrZ00yOLBjDprkJ9msV2D4vMO8BnQQOgmJzgKfp8NYLzBuyv3iWHuCJLlK83+m O3jWgnZgS1BCkvn/PFDtavn8Uysjsm/ZnAlq2JQnBY9+fr35D+zx5nVxprTdPpDZ7tBE kS8vRfnxXaKX3qCiHpifjGtPuvxBNLpJ3opiOBuxGfNDKY5Fk7sg5mkHL/GZHDIYYah9 XLTlk3tQNDSDJLcla0OhNwC88oiNLaa+rSPjkCAd0rt1ia6OL2R4nAmBUwCEzyee1jQk gJ+ad8bB+CBK1TQ9tSxlSMkoWnzvKV7ID2mNiaWGK8mtXnyPjFQneZQ+rvnwDI8rRrRL o2qQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692020123; x=1692624923; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=r8QdYd3MXhSbKcLqvYgrLdNh1oz8Fq8WB7WcnBC03uk=; b=haSOyea8YUiuoHDSrizqQVuerYMIQnraKWiq67RzlgWiHR6JYE3RH0ZHhVW9GhNobV ZEva9pHXmlCrXpEIvd92XpMW/RR4ypA9n8dR0sHgTZTG0nuhhIQLNtEAJPtmiujvDlvW TmNh+nWCuNwKM7QwIYPUx4a7hIjlrGsvGzvPxIXemrpCmrTs6qFgLDkqb1mReF6TLtMG stUaBx7Bi1grcVkc6VjuM35UeXA9mN/9yPi84Xuw6xCIxXeeyqxDNRO7R372xx5IYlpH wp5JkQiNjAwn6e1NcoUuDH1eWBf2dPxLUXWiqVx6uKapGzxn+p8zSw4XCMirwlLgYF8F eMnQ== X-Gm-Message-State: AOJu0YxmoW1K/SpHhsiFtiBLH9+gWWBTXSbhm2b52mnQpDp7kK5sIBN1 CiDddaI5QEjF9Q9atOXZQ4w3FPMwyWholB/6esE= X-Received: by 2002:a2e:9790:0:b0:2b4:75f0:b9e9 with SMTP id y16-20020a2e9790000000b002b475f0b9e9mr6890562lji.10.1692020123572; Mon, 14 Aug 2023 06:35:23 -0700 (PDT) Received: from localhost.localdomain ([45.82.14.220]) by smtp.gmail.com with ESMTPSA id z24-20020a2e9658000000b002b9415597d0sm2411102ljh.78.2023.08.14.06.35.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Aug 2023 06:35:23 -0700 (PDT) From: Maxim Uvarov To: u-boot@lists.denx.de Cc: pbrobinson@redhat.com, ilias.apalodimas@linaro.org, joe.hershberger@ni.com, rfried.dev@gmail.com, trini@konsulko.com, goldsimon@gmx.de, lwip-devel@nongnu.org, Maxim Uvarov Subject: [PATCHv6 05/14] net/lwip: implement tftp cmd Date: Mon, 14 Aug 2023 19:32:44 +0600 Message-Id: <20230814133253.4150-6-maxim.uvarov@linaro.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230814133253.4150-1-maxim.uvarov@linaro.org> References: <20230814133253.4150-1-maxim.uvarov@linaro.org> MIME-Version: 1.0 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 Implement function for dhcp command with lwIP variant. Usage and output is the same as the original command. This code called by compatibility code between U-Boot and lwIP. Signed-off-by: Maxim Uvarov --- net/lwip/Makefile | 1 + net/lwip/apps/tftp/Makefile | 16 ++++ net/lwip/apps/tftp/lwip-tftp.c | 129 +++++++++++++++++++++++++++++++++ 3 files changed, 146 insertions(+) create mode 100644 net/lwip/apps/tftp/Makefile create mode 100644 net/lwip/apps/tftp/lwip-tftp.c diff --git a/net/lwip/Makefile b/net/lwip/Makefile index 59323fb325..0337d82cf5 100644 --- a/net/lwip/Makefile +++ b/net/lwip/Makefile @@ -67,3 +67,4 @@ obj-$(CONFIG_NET) += port/sys-arch.o obj-$(CONFIG_CMD_DHCP) += apps/dhcp/lwip-dhcp.o obj-$(CONFIG_CMD_DNS) += apps/dns/lwip-dns.o +obj-$(CONFIG_CMD_TFTPBOOT) += apps/tftp/ diff --git a/net/lwip/apps/tftp/Makefile b/net/lwip/apps/tftp/Makefile new file mode 100644 index 0000000000..0e50fcad45 --- /dev/null +++ b/net/lwip/apps/tftp/Makefile @@ -0,0 +1,16 @@ + +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) + +$(obj)/tftp.o: $(obj)/tftp.c +.PHONY: $(obj)/tftp.c +$(obj)/tftp.c: + cp $(srctree)/net/lwip/lwip-external/src/apps/tftp/tftp.c $(obj)/tftp.c + cp $(srctree)/net/lwip/lwip-external/src/include/lwip/apps/tftp_client.h $(obj)/tftp_client.h + cp $(srctree)/net/lwip/lwip-external/src/include/lwip/apps/tftp_common.h $(obj)/tftp_common.h + cp $(srctree)/net/lwip/lwip-external/contrib/examples/tftp/tftp_example.h $(obj)/tftp_example.h + +obj-$(CONFIG_CMD_TFTPBOOT) += tftp.o +obj-$(CONFIG_CMD_TFTPBOOT) += 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 0000000000..290229cb85 --- /dev/null +++ b/net/lwip/apps/tftp/lwip-tftp.c @@ -0,0 +1,129 @@ +// 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 + +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); + /* 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 */