From patchwork Wed Aug 2 14:06:57 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxim Uvarov X-Patchwork-Id: 709176 Delivered-To: patch@linaro.org Received: by 2002:a5d:55c5:0:b0:317:2194:b2bc with SMTP id i5csp931854wrw; Wed, 2 Aug 2023 07:11:46 -0700 (PDT) X-Google-Smtp-Source: APBJJlE0se+cFry16aD+YNUg4ayfHec/IJ165I3gnb1oYkpktFl+yP9hnapvg+Dx6OUwNsAe1RUs X-Received: by 2002:a7b:cbd8:0:b0:3fe:228a:e782 with SMTP id n24-20020a7bcbd8000000b003fe228ae782mr4922567wmi.37.1690985505838; Wed, 02 Aug 2023 07:11:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690985505; cv=none; d=google.com; s=arc-20160816; b=cIoTgjrbxHRj40nWVSj0p5SSTMaWLj07t772595DKW/LJOXndbupAoKjEieCy2gtnO 8IfMm0r+INo/3RHOOd3FRnodJJTIfz57YBHtBLI98EIKjcTc0JuEZngzUXej/bdqb4UO 4yddcYZt4jKd+cCcH0Ur7BYc3we2jNHOdR+0INcbftMv+Yk11peWmaWZIhbHzk5LKnbb AjvVMKbH+JnSJs/raSRv4sERL9pxv0Diba+Kepnva1ZBGN/bYvhJzaIFIH/ykwudEaUV HaVh9Aj6r7uu9UZ3gLT1MUIKo8Fp+xgoMSJ0075upK9uloL3JNDZcx5bu+VhPNDIg3fD N0Jg== 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=HPoIBbv1Hue7iQOMoDsGPKtGzwsDGPb1bojhwVGJNCM=; fh=KONqw1VFBW9nCv9imase+52c+XJ0MeVkzLj6SOLcJqQ=; b=ZOfPawR+6US+w/NrKgEraoU8xSTDagZWQDjv/pcBTcBj4wdDmDZS/kVgqQOcxzkFSd X9RcwLDq6VWeVfG8GK8P60QvNE7jM/HN7xgaIhxQJStUSdlflc6Lhi7wnd7EUJsdwmdb sq5y+Qvohmrl5Dj1gtaYq90Vf9Ded7FnLVvferrCdzRzS0nyBr5KJqNLcm6y1mIjR2nK XVdHMoF1YATTThIKRc94TZCgf/5aec6B4v2M4uFQoG1hykiTs0LtK2zCQ1dWVpGqKRbG 2UtSjuHe0zHDyhY6pS31fDwCe5Xz0kqL57O1+HHZJuRBh84btpcJCg41VaIWjHOAYEgr YfYQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=RfJp+sI1; 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 s3-20020a5d4243000000b0031449181a94si255782wrr.570.2023.08.02.07.11.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Aug 2023 07:11:45 -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=RfJp+sI1; 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 563EF86C84; Wed, 2 Aug 2023 16:10:09 +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="RfJp+sI1"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 53D2486C84; Wed, 2 Aug 2023 16:10:08 +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, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-lj1-x230.google.com (mail-lj1-x230.google.com [IPv6:2a00:1450:4864:20::230]) (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 4410A86C9E for ; Wed, 2 Aug 2023 16:10:02 +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-x230.google.com with SMTP id 38308e7fff4ca-2b9d07a8d84so87699741fa.3 for ; Wed, 02 Aug 2023 07:10:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1690985401; x=1691590201; 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=HPoIBbv1Hue7iQOMoDsGPKtGzwsDGPb1bojhwVGJNCM=; b=RfJp+sI1dZb05ZhOMtBfAE+2gPaZQ8kwAYgj6ba5WCeI8Rb28NO3EEJFmlECmsrInE Egp7OLsbp6IsrM2sdxB4pp8rgqVMyyWd7pUUd+aE7oZmoDboSZCs3BFPHlKzWDkK1WF6 u9V736OfnNKHdYCmYCeDQd1pibMPF5UGio8/WVPVdzlePC4vzZsCRXfNVRxOOahwb4Kb QS1vNAg96uTofmOiJn3lLXoqpvnttBZE38yUZJZf1dQIRDgTB2k0UK2xGQiVcSdoS/uz MKp9a9m+vQlqU4LmtYjoA9/cTrjjU/8CCoR9xeYP8xXOP1LIgXFsGv6zlZpiXZ4d4hgC 433Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690985401; x=1691590201; 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=HPoIBbv1Hue7iQOMoDsGPKtGzwsDGPb1bojhwVGJNCM=; b=AqPeUnZGOCAvSkOkDo43K6oePG0sby0h36cR8tXRCtDXnGtoAIq5+GQpWEuvlzu0Pj KiemS3puOeLPEKnFVCWrCUJRaCnDVurp7XtL5CkwAHey1lInNyIeQ+UWYiCu1MwPQmRG cGhLEirxJWn9hM6vB/Yb0xe1XC4fj46fP6IVXR8Gn4vOgPURJDAxv3E51WowvXFGEeEx gPUzVjcXy9HUkqIodQpslKDIDLzxSTc3jb2wjZ9J8FSEIXlTxuj6Ead4IdRmQKbExdAg hBFyUUS/SrO/hRxW4xOqxJkz/iIUnlp29niigHs6lRBefARZb6YVpPrh6k5TrxXBxYCL HZ1Q== X-Gm-Message-State: ABy/qLY6/Po92nzU0cKTeL/Q5OwEcqyq/sWCP3hWAiY7RrGFycCJ02g1 KDNQ2RQDEe7OzalzvQVUqBLKdgsTQecut/FcE+WlcQ== X-Received: by 2002:a05:6512:451:b0:4fb:89b3:3374 with SMTP id y17-20020a056512045100b004fb89b33374mr4181726lfk.54.1690985401124; Wed, 02 Aug 2023 07:10:01 -0700 (PDT) Received: from localhost.localdomain ([45.82.14.220]) by smtp.gmail.com with ESMTPSA id a12-20020a056512020c00b004fbbef8d4dbsm2982026lfo.121.2023.08.02.07.09.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Aug 2023 07:10:00 -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: [PATCHv5 12/13] net/lwip: replace original net commands with lwip Date: Wed, 2 Aug 2023 20:06:57 +0600 Message-Id: <20230802140658.10319-13-maxim.uvarov@linaro.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230802140658.10319-1-maxim.uvarov@linaro.org> References: <20230802140658.10319-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 Replace original commands: ping, tftp, dhcp and wget. Signed-off-by: Maxim Uvarov --- boot/bootmeth_efi.c | 2 +- boot/bootmeth_pxe.c | 2 +- cmd/net.c | 86 +++++---------------------------------------- cmd/pxe.c | 2 +- include/net.h | 8 +++-- include/net/lwip.h | 5 +++ lib/Makefile | 2 -- lib/lwip/ulwip.h | 9 +++++ 8 files changed, 31 insertions(+), 85 deletions(-) create mode 100644 include/net/lwip.h create mode 100644 lib/lwip/ulwip.h diff --git a/boot/bootmeth_efi.c b/boot/bootmeth_efi.c index af31fbfc85..83334991bb 100644 --- a/boot/bootmeth_efi.c +++ b/boot/bootmeth_efi.c @@ -340,7 +340,7 @@ 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)) { + if (!do_lwip_tftp(&cmdtp, 0, 3, tftp_argv)) { 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 ce986bd260..881d2167a6 100644 --- a/boot/bootmeth_pxe.c +++ b/boot/bootmeth_pxe.c @@ -123,7 +123,7 @@ static int extlinux_pxe_read_file(struct udevice *dev, struct bootflow *bflow, tftp_argv[1] = file_addr; tftp_argv[2] = (void *)file_path; - if (do_tftpb(ctx->cmdtp, 0, 3, tftp_argv)) + if (do_lwip_tftp(ctx->cmdtp, 0, 3, tftp_argv)) return -ENOENT; ret = pxe_get_file_size(&size); if (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 flag, int argc, char *const argv[]) { - return netboot_common(DHCP, cmdtp, argc, argv); + return do_lwip_dhcp(); } U_BOOT_CMD( @@ -196,13 +187,11 @@ U_BOOT_CMD( #endif #if defined(CONFIG_CMD_WGET) -static int do_wget(struct cmd_tbl *cmdtp, int flag, int argc, char * const argv[]) -{ - return netboot_common(WGET, cmdtp, argc, argv); -} +int do_lwip_wget(struct cmd_tbl *cmdtp, int flag, int argc, + char *const argv[]); U_BOOT_CMD( - wget, 3, 1, do_wget, + wget, 3, 1, do_lwip_wget, "boot image via network using HTTP protocol", "[loadAddress] [[hostIPaddr:]path and image name]" ); @@ -456,28 +445,8 @@ static int netboot_common(enum proto_t proto, struct cmd_tbl *cmdtp, int argc, } #if defined(CONFIG_CMD_PING) -static int do_ping(struct cmd_tbl *cmdtp, int flag, int argc, - char *const argv[]) -{ - if (argc < 2) - return CMD_RET_USAGE; - - net_ping_ip = string_to_ip(argv[1]); - if (net_ping_ip.s_addr == 0) - return CMD_RET_USAGE; - - if (net_loop(PING) < 0) { - printf("ping failed; host %s is not alive\n", argv[1]); - return CMD_RET_FAILURE; - } - - printf("host %s is alive\n", argv[1]); - - return CMD_RET_SUCCESS; -} - U_BOOT_CMD( - ping, 2, 1, do_ping, + ping, 2, 1, do_lwip_ping, "send ICMP ECHO_REQUEST to network host", "pingAddress" ); @@ -601,45 +570,8 @@ U_BOOT_CMD( #endif #if defined(CONFIG_CMD_DNS) -int do_dns(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) -{ - if (argc == 1) - return CMD_RET_USAGE; - - /* - * We should check for a valid hostname: - * - Each label must be between 1 and 63 characters long - * - the entire hostname has a maximum of 255 characters - * - only the ASCII letters 'a' through 'z' (case-insensitive), - * the digits '0' through '9', and the hyphen - * - cannot begin or end with a hyphen - * - no other symbols, punctuation characters, or blank spaces are - * permitted - * but hey - this is a minimalist implmentation, so only check length - * and let the name server deal with things. - */ - if (strlen(argv[1]) >= 255) { - printf("dns error: hostname too long\n"); - return CMD_RET_FAILURE; - } - - net_dns_resolve = argv[1]; - - if (argc == 3) - net_dns_env_var = argv[2]; - else - net_dns_env_var = NULL; - - if (net_loop(DNS) < 0) { - printf("dns lookup of %s failed, check setup\n", argv[1]); - return CMD_RET_FAILURE; - } - - return CMD_RET_SUCCESS; -} - U_BOOT_CMD( - dns, 3, 1, do_dns, + dns, 3, 1, do_lwip_dns, "lookup the IP of a hostname", "hostname [envvar]" ); diff --git a/cmd/pxe.c b/cmd/pxe.c index 677142520b..a31fbd7e40 100644 --- a/cmd/pxe.c +++ b/cmd/pxe.c @@ -42,7 +42,7 @@ static int do_get_tftp(struct pxe_context *ctx, const char *file_path, num_args = 3; } - if (do_tftpb(ctx->cmdtp, 0, num_args, tftp_argv)) + if (do_lwip_tftp(ctx->cmdtp, 0, num_args, tftp_argv)) return -ENOENT; ret = pxe_get_file_size(sizep); diff --git a/include/net.h b/include/net.h index e254df7d7f..de7baeb121 100644 --- a/include/net.h +++ b/include/net.h @@ -54,8 +54,10 @@ struct in_addr { __be32 s_addr; }; +int do_lwip_dhcp(void); + /** - * do_tftpb - Run the tftpboot command + * do_lwip_tftp - Run the tftpboot command * * @cmdtp: Command information for tftpboot * @flag: Command flags (CMD_FLAG_...) @@ -63,7 +65,7 @@ struct in_addr { * @argv: List of arguments * Return: result (see enum command_ret_t) */ -int do_tftpb(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]); +int do_lwip_tftp(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]); /** * dhcp_run() - Run DHCP on the current ethernet device @@ -514,7 +516,7 @@ extern int net_restart_wrap; /* Tried all network devices */ enum proto_t { BOOTP, RARP, ARP, TFTPGET, DHCP, DHCP6, PING, PING6, DNS, NFS, CDP, NETCONS, SNTP, TFTPSRV, TFTPPUT, LINKLOCAL, FASTBOOT_UDP, FASTBOOT_TCP, - WOL, UDP, NCSI, WGET, RS + WOL, UDP, NCSI, WGET, RS, LWIP }; extern char net_boot_file_name[1024];/* Boot File name */ diff --git a/include/net/lwip.h b/include/net/lwip.h new file mode 100644 index 0000000000..6686a52bfc --- /dev/null +++ b/include/net/lwip.h @@ -0,0 +1,5 @@ + +int do_lwip_ping(struct cmd_tbl *cmdtp, int flag, int argc, + char *const argv[]); +int do_lwip_dns(struct cmd_tbl *cmdtp, int flag, int argc, + char *const argv[]); diff --git a/lib/Makefile b/lib/Makefile index 598b5755dd..414f171e74 100644 --- a/lib/Makefile +++ b/lib/Makefile @@ -93,8 +93,6 @@ obj-$(CONFIG_LIBAVB) += libavb/ obj-$(CONFIG_$(SPL_TPL_)OF_LIBFDT) += libfdt/ obj-$(CONFIG_$(SPL_TPL_)OF_REAL) += fdtdec_common.o fdtdec.o -obj-y += lwip/ - ifdef CONFIG_SPL_BUILD obj-$(CONFIG_SPL_YMODEM_SUPPORT) += crc16-ccitt.o obj-$(CONFIG_$(SPL_TPL_)HASH) += crc16-ccitt.o diff --git a/lib/lwip/ulwip.h b/lib/lwip/ulwip.h new file mode 100644 index 0000000000..11ca52aa1f --- /dev/null +++ b/lib/lwip/ulwip.h @@ -0,0 +1,9 @@ +/* SPDX-License-Identifier: GPL-2.0 */ + +int ulwip_enabled(void); +int ulwip_in_loop(void); +int ulwip_loop_set(int loop); +int ulwip_exit(int err); +int uboot_lwip_poll(void); +int ulwip_app_get_err(void); +void ulwip_set_tmo(int (*tmo)(void));