From patchwork Fri Sep 8 13:53:06 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Maxim Uvarov X-Patchwork-Id: 720814 Delivered-To: patch@linaro.org Received: by 2002:adf:eec5:0:b0:31d:da82:a3b4 with SMTP id a5csp778633wrp; Fri, 8 Sep 2023 06:55:44 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFgw4uWHyvrX3Zugau9Y1B314ZLyDzdCAXtT5JVE6svRVD6bokexIPFTUJI0V/3S6PjSS4F X-Received: by 2002:a05:600c:2483:b0:401:d2cb:e6f3 with SMTP id 3-20020a05600c248300b00401d2cbe6f3mr2442133wms.1.1694181344150; Fri, 08 Sep 2023 06:55:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694181344; cv=none; d=google.com; s=arc-20160816; b=rzQfho+58NUXGZ7k6KvM9KaP+wj9/mqcW4uHxkUOaTwHOOWn9sKkI7o6FYs/MM8/ie aGTtAxF5PuyWRKnp4+pTm18H42EZOzljvVu9gVJvZXLW2xJzTVrZzIgiQ+kZfigSm2nA gS2dNwHcH6IgFwnVksx1n/9tLyCgs4lvoIwjnaNepNrXNnYFM6gMndDpFuxJ/LPMpxkS bhU9RK5vvQY7Une9EqiBlCIZSMKIouDonVLsIY7W7upJJAZOdeAh+xA9+SARIiuWxi7f VfKFKAoIPqXXFmm9D1hyGou9ozuLPxYLZixkSe3drcvPyplk/DB0Usgp/NT9mnj6pCkQ D4Ag== 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=qa7rsDpd8DTjUr2xn0X7Ta38Y9zQGUvwzqZuvwV3Ssg=; fh=g6X7VLA7Hwc4ddn6ja9UNjzyIs7WWcGrFqfXM5IokKA=; b=qPki2RUXEW2BOWsYfFmvjJ7tO+k6lwZbm4Gte238r/t247RNkfskgNauu7F7qw2j7A vAAFf0O5KUAtj9D+WKvg9W5JJwmmh+1OWDNJ6AveZQRduKsjse8FtK51aoH1QFjlgdyF Wy6F8/gQ+RiZPUPY9LlcM0lh5XzqieLders4vJum0WXFc8MFW78Qvug1Ud9qh+I2okFS 9bOGgIh0A4on7X9HovKtXVieVsZCMk34FCt6pW4hIvAxXfPuvUVdBFw/R8IewXm69yoV 2aoy+kuf9iapNcSbWiu97Y+HPUnL85SA58U4w7UjzTMr4SKUu4RzYF2CeogElNEDfZh6 ep4w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=MOmthwww; 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 b14-20020a5d634e000000b0031ad9c0666dsi806976wrw.692.2023.09.08.06.55.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Sep 2023 06:55:44 -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=MOmthwww; 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 3684786A4C; Fri, 8 Sep 2023 15:55:37 +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="MOmthwww"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 33D3686A45; Fri, 8 Sep 2023 15:55:36 +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-x236.google.com (mail-lj1-x236.google.com [IPv6:2a00:1450:4864:20::236]) (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 2477B86A34 for ; Fri, 8 Sep 2023 15:55:33 +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-x236.google.com with SMTP id 38308e7fff4ca-2bcb89b476bso35639801fa.1 for ; Fri, 08 Sep 2023 06:55:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1694181332; x=1694786132; darn=lists.denx.de; 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=qa7rsDpd8DTjUr2xn0X7Ta38Y9zQGUvwzqZuvwV3Ssg=; b=MOmthwwwMjhRJ1ocDfaZcSpciULwsNcSPMYBlMTWh96Mc20skDdVT2Z38+nVbNnPjb gm4D3v8Dc1mdPply4u7EOX86TulGNqDQu986/101Xq41OqO4Z6t+HOx+SCXk/JDeH+Wf XTECTLIMy+EESsuviHgCrbQhId9i02CvE+an59vbzrzcaxAT+MtenGMWBG02B+YU7Yv6 cm5scutgmVM9Xg0weLcUyBbhgo9x8n1bllqYyfPmmw2JRdVALXLw4YjpuJIZYGyX5Eoi fBefpKBvvZvNK5oNFv8ZDDaQcm/mCCBPD2l9peX4+tqTUkIsIcylZQc2UI9g0jleI+Tz yn1Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694181332; x=1694786132; 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=qa7rsDpd8DTjUr2xn0X7Ta38Y9zQGUvwzqZuvwV3Ssg=; b=Oz3WDyTPCWbVotSWMacJjuUoOBR5hhVG1oLrkxjTPCwdUWtMb5H53WQaCEdqb7nRgq C+ThaVCXkUtrCZFCzHox3oHT+La+MtmZ2+PY9jvNELcmSmH5YG+c8Tz4538obEPi+llo kBpJuyLrsfvRIczqe649vQwjPHjNc0O6ry87tIx7qbJCrNU3hxE7PeCyCOsRMikh4uVA +OOMTzLcLD/AQaRLj6eCKazybQ9jFJb4utuTi+yAgqwLZlkbaL4s4DNevO1iBtFfjebR I8alWZ6xj6BSYP8985wat01rUxr7LkTXuQxglzKlW5ov4c0k1glNVV6A1X/ke2WlqLAH GByw== X-Gm-Message-State: AOJu0YxdQpLFZe+3yJRC+wHThQpWVYnEzGVKHx5S0YbvE/Ew4AWxS+Ou y/oYDRuhwwubHO3HoM0r/hirz5hTv2mWOjk7rB2mcA== X-Received: by 2002:a2e:9906:0:b0:2bc:f60c:445f with SMTP id v6-20020a2e9906000000b002bcf60c445fmr1874095lji.36.1694181332244; Fri, 08 Sep 2023 06:55:32 -0700 (PDT) Received: from localhost.localdomain ([45.82.14.220]) by smtp.gmail.com with ESMTPSA id u14-20020a2e9f0e000000b002bcbae4c21fsm306907ljk.50.2023.09.08.06.55.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Sep 2023 06:55:32 -0700 (PDT) From: Maxim Uvarov To: u-boot@lists.denx.de Cc: pbrobinson@gmail.com, ilias.apalodimas@linaro.org, joe.hershberger@ni.com, rfried.dev@gmail.com, trini@konsulko.com, goldsimon@gmx.de, Maxim Uvarov , Simon Glass Subject: [PATCHv8 01/15] net/lwip: add doc/develop/net_lwip.rst Date: Fri, 8 Sep 2023 19:53:06 +0600 Message-Id: <20230908135320.7066-2-maxim.uvarov@linaro.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230908135320.7066-1-maxim.uvarov@linaro.org> References: <20230908135320.7066-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 Add initial documentation of lwIP network IP stack integration to the U-Boot (net_lwip.rst). Signed-off-by: Maxim Uvarov Reviewed-by: Simon Glass Reviewed-by: Ilias Apalodimas --- doc/develop/index.rst | 1 + doc/develop/net_lwip.rst | 75 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 76 insertions(+) create mode 100644 doc/develop/net_lwip.rst diff --git a/doc/develop/index.rst b/doc/develop/index.rst index 5b230d0321..4764990f25 100644 --- a/doc/develop/index.rst +++ b/doc/develop/index.rst @@ -48,6 +48,7 @@ Implementation spl falcon uefi/index + net_lwip vbe version diff --git a/doc/develop/net_lwip.rst b/doc/develop/net_lwip.rst new file mode 100644 index 0000000000..a77ab60d0f --- /dev/null +++ b/doc/develop/net_lwip.rst @@ -0,0 +1,75 @@ +.. SPDX-License-Identifier: GPL-2.0+ + +lwIP IP stack integration for U-Boot +==================================== + +Intro +----- + +lwIP is a library implementing network protocols, which is commonly used +on embedded devices. + +https://savannah.nongnu.org/projects/lwip/ +lwIP  license: +lwIP is licensed under a BSD-style license: http://lwip.wikia.com/wiki/License. + +Main features include: + +* Protocols: IP, IPv6, ICMP, ND, MLD, UDP, TCP, IGMP, ARP, PPPoS, PPPoE + +* DHCP client, DNS client (incl. mDNS hostname resolver), + AutoIP/APIPA (Zeroconf), SNMP agent (v1, v2c, v3, private MIB support + & MIB compiler) + +* APIs: specialized APIs for enhanced performance, optional Berkeley-alike + socket API + +* Extended features: IP forwarding over multiple network interfaces, TCP + congestion control, RTT estimation and fast recovery/fast retransmit + +* Addon applications: HTTP(S) server, SNTP client, SMTP(S) client, ping, + NetBIOS nameserver, mDNS responder, MQTT client, TFTP server + +U-Boot implementation details +----------------------------- + +1. In general we can build lwIP as a library and link it against U-Boot or + compile it in the U-Boot tree in the same way as other U-Boot files. There + are few reasons why second variant was selected: lwIP is very customizable + with defines for features, memory size, types of allocation, some internal + types and platform specific code. It turned out easier to enable/disable + debug which is also done with defines, and is needed periodically. + +2. lwIP has 2 APIs - raw mode and sequential (as lwIP names it, or socket API + as we name it in Linux). For now only raw API is supported. + +In raw IP mode a callback function for RX path is registered and will be called +when packet is passed to the IP stack and is ready for the application. + +One example is the unmodified working ping example from lwip sources which +registered the callback: + +.. code-block:: c + + ping_pcb = raw_new(IP_PROTO_ICMP); + raw_recv(ping_pcb, ping_recv, NULL); <- ping_recv is app callback. + raw_bind(ping_pcb, IP_ADDR_ANY) + +3.  Input and output + +RX packet path is injected to U-Boot eth_rx() polling loop and TX patch is in +eth_send() accordingly. That way we can leave the driver code unmodified and +consume packets once they are ready. So we do not touch any drivers code and +just eat packets when they are ready. + +U-Boot lwIP Applications +======================== + +.. kernel-doc:: include/net/lwip.h + :internal: + +lwIP API to control polling loop +================================ + +.. kernel-doc:: include/net/ulwip.h + :internal: From patchwork Fri Sep 8 13:53:07 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxim Uvarov X-Patchwork-Id: 720815 Delivered-To: patch@linaro.org Received: by 2002:adf:eec5:0:b0:31d:da82:a3b4 with SMTP id a5csp778719wrp; Fri, 8 Sep 2023 06:55:54 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEFO1CQPuq15vpAdI8QUlkT+q9wFBBkH9yWM2ojWv4Hn2hVZxq/m0GVIQLz94riTGXj8ZrK X-Received: by 2002:a5d:43d0:0:b0:31a:d871:7ae7 with SMTP id v16-20020a5d43d0000000b0031ad8717ae7mr2007532wrr.29.1694181354203; Fri, 08 Sep 2023 06:55:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694181354; cv=none; d=google.com; s=arc-20160816; b=bhXefhT9W5hhneixSQV0el/D8NsnYZAFUu9dADl/lJ5jmJF9IcxsImeRMPf3ZCQIcR PI9+ouovPVsu81HFuAvRNaf7wT3iwfoUAmn0wUXzmuJCvi1XzZMNmDe/AOfgMWS6Zwr6 p06iiJTMLAB/QBFJ0bwoDiO+7wYZqpnWhDwjfw5AbF0ZfrElmWDqD0/R4MrmXcfYlUFc H0n3y3fyGT5JozHGyby7GwgueCIYZO7IX/+BbIlKK/sPWEG3HwZq0yVr43dfAeuX2/q1 DOOJ1nmFEnXzjZ/gLlNelfSO5CnkHQm3XHdpXKNeOfA32VfCVthvwSwNedhi+hxu9msH CYMQ== 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=+ZWczJJ29oeFznXyVz4JvMIzBmThqxBGAsYRNpDOANo=; fh=hYoOR0yg+Fo7S26X8ur5L+RaTmkyxWlAVaBypEC8A0g=; b=VmbmMwff+nXIcqnY3S3YIohvW0n9ZXw8ZSOov7LGdC72lqtbfqJ5Ex33V0i71ayrUs pjxDFx3kWnLVVsj8TL/fjc2Luo/fZ41FwWmyAqDdbYqXCa3x/NKKKYoYO4aNpU18UURJ 65wELFpeZ9N8XkOtzbqGf4JeuS0Sl/Ys+6fetYjdEIc7p8uPVEHOWiWrWl77yB+cXvuI 0GOtzusQDHnsTSHn1pttDLlnk1XO5DSERgKE8Jy9q3plFzU254mzG6Icb4Cy09PrnJbY eibXlwKEaabhVW8l9uwvz+gSYn3To/CB3ASOf95diSSMGxs8+8aPLHq57XeKttVQzjwc SktQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=tSsP4sqR; 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 r12-20020adff10c000000b0031972d4f3d8si803337wro.178.2023.09.08.06.55.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Sep 2023 06:55:54 -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=tSsP4sqR; 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 85E6D86A6D; Fri, 8 Sep 2023 15:55:40 +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="tSsP4sqR"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id B537B86A68; Fri, 8 Sep 2023 15:55:38 +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-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 9053286A40 for ; Fri, 8 Sep 2023 15:55:35 +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-2b974031aeaso37227131fa.0 for ; Fri, 08 Sep 2023 06:55:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1694181334; x=1694786134; darn=lists.denx.de; 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=+ZWczJJ29oeFznXyVz4JvMIzBmThqxBGAsYRNpDOANo=; b=tSsP4sqRmaIrrMe365hwESTQHrvGTdI8W8u/ebu9n2jM2qx5hqlu4AuIBw0vfJI5gt 8gHm23W0zEc/8T2ICcg6eN70z4BO/Lyig7D5Yg6Rq5EVMOq7MDr2E2kzlfzxgDTPPPAt Pda8qPv2FgM6yhL77dFQSfC4qUz/zHBmPcgdY8+xqq5wSbZVGZd3b1/cXNuUsLQ3vRIf Dm7rwGF56bTZJtoeRLz9IDfnmINO1DlI/a+dCCoy5C8rStztd78kqNM2sBlCoP5cKUr1 fm93CjqMbucPWryh3M5u31K4lzJhW+RCWqY6ZxE03DXYNBf6a1ECHE73joZUMD9wXb80 EV3Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694181334; x=1694786134; 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=+ZWczJJ29oeFznXyVz4JvMIzBmThqxBGAsYRNpDOANo=; b=T1Plz1xV7vrb0PpPpbkZfHdBcJEn5v1kk77fh+awN+InYT5tHr1Tw8ehIEvESvBpYK B3/QmHnPRxioHezKrc6GNYBVTqldDKtQPmyEHkql5Ld0/1CfmnOzzjXYJbJ6f0Gvy93g HTpIOQqGi1kS+TAgbR2c/+9zmZ5AgOmX3f3pA1BoT9eZ0LvDjulVpcALjiLRFdz4sv1z EJzJqCiCBQKCkly1BK6O+QP531PV5za9nX1f+LKLkXq7dWy1LYFG7PCO8nexwHC4sade zjKTaGoZKik+HrhvgoLNcDl6d1v+bVzqzasRIaySMaIND5zrl90XH0NCukYRtmNk/9WA QtpA== X-Gm-Message-State: AOJu0YzAvmYExHcxRREQ37UKcTIRgObUO+GCnzWHgUGQ1TiXRZZOEh++ lkRpJjc+LpuDiPP5Go3Zgopf5yIylWyO9u70tnsMuQ== X-Received: by 2002:a2e:7a0a:0:b0:2b5:7f93:b3b0 with SMTP id v10-20020a2e7a0a000000b002b57f93b3b0mr1841172ljc.17.1694181334549; Fri, 08 Sep 2023 06:55:34 -0700 (PDT) Received: from localhost.localdomain ([45.82.14.220]) by smtp.gmail.com with ESMTPSA id u14-20020a2e9f0e000000b002bcbae4c21fsm306907ljk.50.2023.09.08.06.55.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Sep 2023 06:55:34 -0700 (PDT) From: Maxim Uvarov To: u-boot@lists.denx.de Cc: pbrobinson@gmail.com, ilias.apalodimas@linaro.org, joe.hershberger@ni.com, rfried.dev@gmail.com, trini@konsulko.com, goldsimon@gmx.de, Maxim Uvarov Subject: [PATCHv8 02/15] net/lwip: integrate lwIP library Date: Fri, 8 Sep 2023 19:53:07 +0600 Message-Id: <20230908135320.7066-3-maxim.uvarov@linaro.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230908135320.7066-1-maxim.uvarov@linaro.org> References: <20230908135320.7066-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 Define Makefile and Kconfig to build lwIP inside the U-Boot. We compile lwIP the same as the main code, plus we can do optimization for size at compile time with disabling not needed debug asserts, or not used protocols. So we can tune lwIP configuration specially for U-Boot environments. Signed-off-by: Maxim Uvarov --- net/Kconfig | 3 +++ net/Makefile | 1 + net/lwip/Kconfig | 25 ++++++++++++++++++ net/lwip/Makefile | 64 +++++++++++++++++++++++++++++++++++++++++++++++ net/net.c | 20 ++++++++++++++- 5 files changed, 112 insertions(+), 1 deletion(-) create mode 100644 net/lwip/Kconfig create mode 100644 net/lwip/Makefile diff --git a/net/Kconfig b/net/Kconfig index 4215889127..34c1e43c87 100644 --- a/net/Kconfig +++ b/net/Kconfig @@ -5,9 +5,12 @@ menuconfig NET bool "Networking support" default y + imply LWIP if NET +source net/lwip/Kconfig + config ARP_TIMEOUT int "Milliseconds before trying ARP again" default 5000 diff --git a/net/Makefile b/net/Makefile index 3e2d061338..61930c244e 100644 --- a/net/Makefile +++ b/net/Makefile @@ -33,6 +33,7 @@ obj-$(CONFIG_CMD_WOL) += wol.o obj-$(CONFIG_PROT_UDP) += udp.o obj-$(CONFIG_PROT_TCP) += tcp.o obj-$(CONFIG_CMD_WGET) += wget.o +obj-$(CONFIG_LWIP) += lwip/ # Disable this warning as it is triggered by: # sprintf(buf, index ? "foo%d" : "foo", index) diff --git a/net/lwip/Kconfig b/net/lwip/Kconfig new file mode 100644 index 0000000000..19f987a074 --- /dev/null +++ b/net/lwip/Kconfig @@ -0,0 +1,25 @@ +menu "lwIP" +config LWIP + bool "Support LWIP library" + help + Enable the lwIP library code with + all dependencies (commands are implemented with lwIP + library. This option is automatically enabled if CONFIG_NET=y. + lwIP library (https://git.savannah.nongnu.org/git/lwip.git) provides + network stack and application code for U-Boot commands. + Please see doc/develop/net_lwip.rst for more details. + +menu "LWIP options" + +config LWIP_LIB_DEBUG + bool "enable debug" + default n + +config LWIP_LIB_NOASSERT + bool "disable asserts" + default y + help + Disabling asserts reduces binary size by 16k. +endmenu + +endmenu diff --git a/net/lwip/Makefile b/net/lwip/Makefile new file mode 100644 index 0000000000..3fd5d34564 --- /dev/null +++ b/net/lwip/Makefile @@ -0,0 +1,64 @@ +# SPDX-License-Identifier: GPL-2.0+ +# +# (C) Copyright 2023 Linaro Ltd. + +ccflags-y += -I$(srctree)/net/lwip/port/include +ccflags-y += -I$(srctree)/net/lwip/lwip-external/src/include -I$(srctree)/net/lwip + +obj-$(CONFIG_NET) += lwip-external/src/core/init.o \ + lwip-external/src/core/def.o \ + lwip-external/src/core/dns.o \ + lwip-external/src/core/inet_chksum.o \ + lwip-external/src/core/ip.o \ + lwip-external/src/core/mem.o \ + lwip-external/src/core/memp.o \ + lwip-external/src/core/netif.o \ + lwip-external/src/core/pbuf.o \ + lwip-external/src/core/raw.o \ + lwip-external/src/core/stats.o \ + lwip-external/src/core/sys.o \ + lwip-external/src/core/altcp.o \ + lwip-external/src/core/altcp_alloc.o \ + lwip-external/src/core/altcp_tcp.o \ + lwip-external/src/core/tcp.o \ + lwip-external/src/core/tcp_in.o \ + lwip-external/src/core/tcp_out.o \ + lwip-external/src/core/timeouts.o \ + lwip-external/src/core/udp.o + +# IPv4 +obj-$(CONFIG_NET) += lwip-external/src/core/ipv4/acd.o \ + lwip-external/src/core/ipv4/autoip.o \ + lwip-external/src/core/ipv4/dhcp.o \ + lwip-external/src/core/ipv4/etharp.o \ + lwip-external/src/core/ipv4/icmp.o \ + lwip-external/src/core/ipv4/igmp.o \ + lwip-external/src/core/ipv4/ip4_frag.o \ + lwip-external/src/core/ipv4/ip4.o \ + lwip-external/src/core/ipv4/ip4_addr.o +# IPv6 +obj-$(CONFIG_NET) += lwip-external/src/core/ipv6/dhcp6.o \ + lwip-external/src/core/ipv6/ethip6.o \ + lwip-external/src/core/ipv6/icmp6.o \ + lwip-external/src/core/ipv6/inet6.o \ + lwip-external/src/core/ipv6/ip6.o \ + lwip-external/src/core/ipv6/ip6_addr.o \ + lwip-external/src/core/ipv6/ip6_frag.o \ + lwip-external/src/core/ipv6/mld6.o \ + lwip-external/src/core/ipv6/nd6.o +# API +obj-$(CONFIG_NET) += lwip-external/src/api/api_lib.o \ + lwip-external/src/api/api_msg.o \ + lwip-external/src/api/err.o \ + lwip-external/src/api/if_api.o \ + lwip-external/src/api/netbuf.o \ + lwip-external/src/api/netdb.o \ + lwip-external/src/api/netifapi.o \ + lwip-external/src/api/sockets.o \ + lwip-external/src/api/tcpip.o + +# Netdevs +obj-$(CONFIG_NET) += lwip-external/src/netif/ethernet.o + +obj-$(CONFIG_NET) += port/if.o +obj-$(CONFIG_NET) += port/sys-arch.o diff --git a/net/net.c b/net/net.c index 43abbac7c3..d9e566081c 100644 --- a/net/net.c +++ b/net/net.c @@ -125,6 +125,7 @@ #endif #include "dhcpv6.h" #include "net_rand.h" +#include /** BOOTP EXTENTIONS **/ @@ -452,7 +453,9 @@ int net_loop(enum proto_t protocol) #endif bootstage_mark_name(BOOTSTAGE_ID_ETH_START, "eth_start"); - net_init(); + if (!ulwip_enabled() || !ulwip_in_loop()) + net_init(); + if (eth_is_on_demand_init()) { eth_halt(); eth_set_current(); @@ -649,6 +652,16 @@ restart: */ eth_rx(); + if (ulwip_enabled()) { + net_set_state(NETLOOP_CONTINUE); + if (!ulwip_in_loop()) { + if (ulwip_app_get_err()) + net_set_state(NETLOOP_FAIL); + else + net_set_state(NETLOOP_SUCCESS); + goto done; + } + } /* * Abort if ctrl-c was pressed. */ @@ -1213,6 +1226,11 @@ void net_process_received_packet(uchar *in_packet, int len) if (len < ETHER_HDR_SIZE) return; + if (ulwip_enabled()) { + ulwip_poll(); + return; + } + #if defined(CONFIG_API) || defined(CONFIG_EFI_LOADER) if (push_packet) { (*push_packet)(in_packet, len); From patchwork Fri Sep 8 13:53:08 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxim Uvarov X-Patchwork-Id: 720816 Delivered-To: patch@linaro.org Received: by 2002:adf:eec5:0:b0:31d:da82:a3b4 with SMTP id a5csp778797wrp; Fri, 8 Sep 2023 06:56:04 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEhQcDwvn51LjxXI6lKUkdMGVCQTDWh8y57wu/xOdEYgk4k5Eue88+RmnH/H+9VXb8myl8T X-Received: by 2002:adf:e645:0:b0:317:417e:a467 with SMTP id b5-20020adfe645000000b00317417ea467mr4401779wrn.6.1694181364705; Fri, 08 Sep 2023 06:56:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694181364; cv=none; d=google.com; s=arc-20160816; b=ZgXGG8JJW09mqlppdJeqOzVfaEwfdCnDZnMlhb1emA+4UBDdnQwnpKz6fvjbPABTHf FSR42g9OXX0JSE/eeJIAsfmVR46CKtqFir0xKsDNHcYwbxlSbSTqHtFVHVra79y73hVP LzyHj4SKv1dno6GaW3xcURlyVK49+65cJlnougpdNVR2DFS1KnDEvzgSEhFqUVii+4d+ 87MchC1WcmzXYHYrdupF9vzUpfFOsClS4CBqz/t4i3wq7eYLlg2EBHncDDopHdhlPSw/ jwbsl9aMWHWwzQv/Qu+zX18AURvI3XmDWMFyYDMP3dRqzXkizjyl07BplP+IpLhqQvpD xHfg== 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=kTROnAHtoOcj9HwLA+i64O3iQOqf+PBBq8BxgaJV7hY=; fh=hYoOR0yg+Fo7S26X8ur5L+RaTmkyxWlAVaBypEC8A0g=; b=ny9pVswYwr0dZ5q9bSrecv1j77XWapbJbvoVk37FWdsZmwqXqj6/0m6jaGTgn8X4zN oRfFJ18unXC9XxQeZguyJJ6xZuOJ4j9/u3VcHlkNaLyi916z7ehelGVtwbtiVg4SivSm QEQocJAFVDgjvI6fK0aJqd4e2NBR4xjpY1Ld4dtZyQZ0NRjBZSkbo+5POCvrsI6uIh6K 1QJOawKWyV7XF+dkhVyUZnNrQavjyyGnbexu1rxqS7MARh9A8ppyHCuHcu2xGAFhRdUL zec1GqogZ/6J3zL6i3Y8E95XDacgMBWF6paJP1zy3xtXJlNa5HYbOoS2f13FD23FSGsY y0Lw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=f+88xNSB; 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 l7-20020a05600c1d0700b003fbc722b14asi896507wms.135.2023.09.08.06.56.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Sep 2023 06:56:04 -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=f+88xNSB; 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 D3D3E86A40; Fri, 8 Sep 2023 15:55:41 +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="f+88xNSB"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 5AF0F86A43; Fri, 8 Sep 2023 15:55:41 +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-x22f.google.com (mail-lj1-x22f.google.com [IPv6:2a00:1450:4864:20::22f]) (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 BD77A86A63 for ; Fri, 8 Sep 2023 15:55:37 +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-x22f.google.com with SMTP id 38308e7fff4ca-2be5e2a3c86so38309531fa.0 for ; Fri, 08 Sep 2023 06:55:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1694181337; x=1694786137; darn=lists.denx.de; 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=kTROnAHtoOcj9HwLA+i64O3iQOqf+PBBq8BxgaJV7hY=; b=f+88xNSBoh3xNDVqTlFJ17zdO6TTgMUp+znf2m3Oo361liT2VbFwlGefOzcOS2oDfv Qi44mMbdVytSNCLYcRonHKh1YPDgyE9zKmOcCYM2soul7SwTgvyu5BebR7Pcx3nX1f+M 9g/cH/zMd6u1tRZw/+bqbP0o7S2GTRzIyKXy8YwHQM494wDJTwD6Ho3wUVRHiQ0ZWjdA muPbq61/1cn3d74EkTHrNkDXQwgCAMMWkGb3c8ucOnlCMJRtA/Ink7LK/R9geT9xx5bU KIYyi0uLnjbHDf25b3DPt+oByY9gx7U5Esw44G7suU5hg1So2VyscH/QHJCPltgxRyiT Qm8Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694181337; x=1694786137; 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=kTROnAHtoOcj9HwLA+i64O3iQOqf+PBBq8BxgaJV7hY=; b=DE5wdgnSz+teXQR3a0Gz9JfBFkKH7uJ5YVsQ5eX/K32hXZqOECiRwZx98tu+zWH/7o g2yr1WBxlnC64JcSi6/0r+Azjw+ogd0Om/VKSvJGWBcXuUL2GZyIOgYe77aO7FvEdA+i ZUJHRtzrtxXe7qW0ri6cqoJupACjbQl3HxTSRHHTp2/e8q8ISSB26nnM6LpJgo0DQFvC i/7ECqe6bCdEcK4bOWf4n+FSW8h8MAlbXV5qo1bkJxffad0A3wN4XimXo81/mNTDJKIx cM5CpB86/vd/KDRU4N3PufSJeI3YtvZxs1lDiV/ryKlAS5b+xRQgYhp26eZUmBfc3vBW 8Egg== X-Gm-Message-State: AOJu0YxrXLoBQz5oRKuFVv3y+rhikgvUmy1qUAAmaeD1pvkvIGUzeeaq m9TXI+Nxaku0ROvnYh+HkkX9qPRiFw46qJDKmwqtjA== X-Received: by 2002:a2e:8285:0:b0:2b6:eceb:9b8 with SMTP id y5-20020a2e8285000000b002b6eceb09b8mr960059ljg.10.1694181336766; Fri, 08 Sep 2023 06:55:36 -0700 (PDT) Received: from localhost.localdomain ([45.82.14.220]) by smtp.gmail.com with ESMTPSA id u14-20020a2e9f0e000000b002bcbae4c21fsm306907ljk.50.2023.09.08.06.55.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Sep 2023 06:55:36 -0700 (PDT) From: Maxim Uvarov To: u-boot@lists.denx.de Cc: pbrobinson@gmail.com, ilias.apalodimas@linaro.org, joe.hershberger@ni.com, rfried.dev@gmail.com, trini@konsulko.com, goldsimon@gmx.de, Maxim Uvarov Subject: [PATCHv8 03/15] net/lwip: implement dns cmd Date: Fri, 8 Sep 2023 19:53:08 +0600 Message-Id: <20230908135320.7066-4-maxim.uvarov@linaro.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230908135320.7066-1-maxim.uvarov@linaro.org> References: <20230908135320.7066-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 U-Boot recently got support for an alternative network stack using LWIP. Replace dns command with the LWIP variant while keeping the output and error messages identical. Signed-off-by: Maxim Uvarov --- include/net/lwip.h | 19 +++++++++++ net/lwip/Makefile | 2 ++ net/lwip/apps/dns/lwip-dns.c | 63 ++++++++++++++++++++++++++++++++++++ 3 files changed, 84 insertions(+) create mode 100644 include/net/lwip.h create mode 100644 net/lwip/apps/dns/lwip-dns.c diff --git a/include/net/lwip.h b/include/net/lwip.h new file mode 100644 index 0000000000..ab3db1a214 --- /dev/null +++ b/include/net/lwip.h @@ -0,0 +1,19 @@ +/* SPDX-License-Identifier: GPL-2.0 */ + +int do_lwip_dns(struct cmd_tbl *cmdtp, int flag, int argc, + char *const argv[]); + +/** + * ulwip_dns() - creates the DNS request to resolve a domain host name + * + * This function creates the DNS request to resolve a domain host name. Function + * can return immediately if previous request was cached or it might require + * entering the polling loop for a request to a remote server. + * + * @name: dns name to resolve + * @varname: (optional) U-Boot variable name to store the result + * Returns: ERR_OK(0) for fetching entry from the cache + * -EINPROGRESS success, can go to the polling loop + * Other value < 0, if error + */ +int ulwip_dns(char *name, char *varname); diff --git a/net/lwip/Makefile b/net/lwip/Makefile index 3fd5d34564..5d8d5527c6 100644 --- a/net/lwip/Makefile +++ b/net/lwip/Makefile @@ -62,3 +62,5 @@ obj-$(CONFIG_NET) += lwip-external/src/netif/ethernet.o obj-$(CONFIG_NET) += port/if.o obj-$(CONFIG_NET) += port/sys-arch.o + +obj-y += apps/dns/lwip-dns.o diff --git a/net/lwip/apps/dns/lwip-dns.c b/net/lwip/apps/dns/lwip-dns.c new file mode 100644 index 0000000000..b340302f2c --- /dev/null +++ b/net/lwip/apps/dns/lwip-dns.c @@ -0,0 +1,63 @@ +// SPDX-License-Identifier: GPL-2.0 + +/* + * (C) Copyright 2023 Linaro Ltd. + */ + +#include +#include +#include + +#include +#include + +#include + +static void dns_found_cb(const char *name, const ip_addr_t *ipaddr, void *callback_arg) +{ + char *varname = (char *)callback_arg; + char *ipstr = ip4addr_ntoa(ipaddr); + + if (varname) + env_set(varname, ipstr); + log_info("resolved %s to %s\n", name, ipstr); + ulwip_exit(0); +} + +int ulwip_dns(char *name, char *varname) +{ + int err; + ip_addr_t ipaddr; /* not used */ + ip_addr_t dns1; + ip_addr_t dns2; + char *dnsenv = env_get("dnsip"); + char *dns2env = env_get("dnsip2"); + + if (!dnsenv && !dns2env) { + log_err("nameserver is not set with dnsip and dnsip2 vars\n"); + return -ENOENT; + } + + if (!dnsenv) + log_warning("dnsip var is not set\n"); + if (!dns2env) + log_warning("dnsip2 var is not set\n"); + + dns_init(); + + if (ipaddr_aton(dnsenv, &dns1)) + dns_setserver(0, &dns1); + + if (ipaddr_aton(dns2env, &dns2)) + dns_setserver(1, &dns2); + + err = dns_gethostbyname(name, &ipaddr, dns_found_cb, varname); + if (err == ERR_OK) + dns_found_cb(name, &ipaddr, varname); + + /* convert lwIP ERR_INPROGRESS to U-Boot -EINPROGRESS */ + if (err == ERR_INPROGRESS) + err = -EINPROGRESS; + + return err; +} From patchwork Fri Sep 8 13:53:09 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxim Uvarov X-Patchwork-Id: 720817 Delivered-To: patch@linaro.org Received: by 2002:adf:eec5:0:b0:31d:da82:a3b4 with SMTP id a5csp778891wrp; Fri, 8 Sep 2023 06:56:16 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGjpDlAiWf50Z8Mo+qCLKqgcmtMgeDJQSvtkMEd2HmdT8SlYuFmQCYSuQsN8H675goH9coA X-Received: by 2002:a1c:7716:0:b0:3fb:b248:67c with SMTP id t22-20020a1c7716000000b003fbb248067cmr2330315wmi.22.1694181376203; Fri, 08 Sep 2023 06:56:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694181376; cv=none; d=google.com; s=arc-20160816; b=D+4lJ/41Hiz8sx9Cczy5hHJPchcqC/X8wfUqgqtQtCg7mzBWlEcli7eL7fm5D5XiIO wHzESMTxQ+/MARcs1iGvyvkDiRhjckNq0TCHK0jjjnyjuV/9a+3ncZitSf/LrVp8fazv 5DsdYeC7xpSQm01TX3Q6MWWGXGwn18V6MXAj4BMVURq+mZlHi0+YfswLD25FMlfJ/a3C 3Y9DqzMgfkltEMLa4VdJuRBirF42SzXSu0mMUuW0I/F5hBa2Ka0yuBScAT3sG9qUKLUi JDaqQPT1jbn4+CNg/uKM7naowWDUpFB6q4E9e6uk1C9cvAQUxn2TxFzQx5VF1K7DKhee sc7Q== 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=fdgneGqqiBGx6Qr+uBbt0uaj/QAsGJ1j6vG1ulncYAM=; fh=hYoOR0yg+Fo7S26X8ur5L+RaTmkyxWlAVaBypEC8A0g=; b=M7LhBmWFkLyXIwnWmvzCcdeE+hAbIYMyBHD/+v8UaQ8OA99OScFo28FhmkBmac4raI UojpvhtpZtzCUMaXdzV69j3S2vSmCzPTMGnJOZ4WDC4/PaqmbqduR1Gxl3TipRIlfuZY o5MXzjtGcWxlbbhO1VxRLMcksIWVoiYX4JZpU0+uJ0tERsh642UYBc5kAmL3pREbFx8V 3sNfX58VNabm6U5KjRzCKU4H84VMmUkItFfcFIUxReuf8NySBrkwjIgbGcdYBSrUyssV X9R/QZuJ21o1W0ollGAFCZC9U7jw1Vp3JmC4xct002UQp6acE52BQ1owQYVfwz+cJdYi Mozw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=jF+3ZcZ1; 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 k17-20020a7bc411000000b003fefa7678b2si2280356wmi.81.2023.09.08.06.56.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Sep 2023 06:56:16 -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=jF+3ZcZ1; 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 2B4E086A34; Fri, 8 Sep 2023 15:55:45 +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="jF+3ZcZ1"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id C502986A63; Fri, 8 Sep 2023 15:55:43 +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-x236.google.com (mail-lj1-x236.google.com [IPv6:2a00:1450:4864:20::236]) (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 0DA6386A49 for ; Fri, 8 Sep 2023 15:55:40 +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-x236.google.com with SMTP id 38308e7fff4ca-2ba1e9b1fa9so36857891fa.3 for ; Fri, 08 Sep 2023 06:55:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1694181339; x=1694786139; darn=lists.denx.de; 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=fdgneGqqiBGx6Qr+uBbt0uaj/QAsGJ1j6vG1ulncYAM=; b=jF+3ZcZ1nNd98zXC5XSY5CTqqf5rEqLfFYUnXW5I5oaSyzcK5Y7xjg5E2pILclONMj SCVyUVqXr9VJ2fHnX6pRqD12TO3yuh9iNTixI671Q72qjAGe3KPhj2RyQCl7BfZzAECQ CcizQh1Xv080dUuxontRVT+EEH5kXDkH6406dcPhhZRFNq3FJFY+OmHhiP9Hzf+KeNxQ 1UpcrMjZiaSZgospTI3niPhgbRn6GRanhiGgERhlg+DKUkkzjbA/7x5tFv8B33YzliZZ LV9m5aTThcvfUaMHc9zugmpn475ggIorwGxZFULylVw6Np0DEyiG4rxj80dU5uIjDwh+ wwfg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694181339; x=1694786139; 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=fdgneGqqiBGx6Qr+uBbt0uaj/QAsGJ1j6vG1ulncYAM=; b=wnfZTyaHGfvxXk9NboIAsiVXvSQAyuirtzOG/47GJmao7UMfvDZipl8GD980e2gBfn q/mk8MbSoeA1RkJG56ViwYcKe0SJ3newC9K+bEimiIfWyO5WLVnDzNa+kq8MyYRoCOLD b6aJSQ4szYQS4x/zLZdLtuXacrTUfKtlyHVA2Zzncwr+RbtKeWDsdrL6t53vDhSvuS/4 Mng4/9nwMry5QaMnrxUcjWapaMahipuFRH1nE9lbpwMbXKOKY9RH3GKYHAr6Pyfzc664 Js1TUiOxV1IqmTEhaSpAQ41Rka/9ENbC3dn9UfC/HiPJIKCOW7oxJ1PN1AzsKpQVbIfD J9MA== X-Gm-Message-State: AOJu0Yx7VGvDdcOIRGP67mm7MLlJWm87qU9O0RQjr+Tb/xLwLonm4wJZ cKZT2FkrEdCtedbSd3r6nguRqiPpdZQkdrfkd0r/+A== X-Received: by 2002:a2e:9206:0:b0:2be:3ca8:bdc9 with SMTP id k6-20020a2e9206000000b002be3ca8bdc9mr1810804ljg.49.1694181339127; Fri, 08 Sep 2023 06:55:39 -0700 (PDT) Received: from localhost.localdomain ([45.82.14.220]) by smtp.gmail.com with ESMTPSA id u14-20020a2e9f0e000000b002bcbae4c21fsm306907ljk.50.2023.09.08.06.55.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Sep 2023 06:55:38 -0700 (PDT) From: Maxim Uvarov To: u-boot@lists.denx.de Cc: pbrobinson@gmail.com, ilias.apalodimas@linaro.org, joe.hershberger@ni.com, rfried.dev@gmail.com, trini@konsulko.com, goldsimon@gmx.de, Maxim Uvarov Subject: [PATCHv8 04/15] net/lwip: implement dhcp cmd Date: Fri, 8 Sep 2023 19:53:09 +0600 Message-Id: <20230908135320.7066-5-maxim.uvarov@linaro.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230908135320.7066-1-maxim.uvarov@linaro.org> References: <20230908135320.7066-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 U-Boot recently got support for an alternative network stack using LWIP. Replace dhcp command with the LWIP variant while keeping the output and error messages identical. Signed-off-by: Maxim Uvarov --- include/net/lwip.h | 12 +++++++ net/lwip/Makefile | 1 + net/lwip/apps/dhcp/lwip-dhcp.c | 61 ++++++++++++++++++++++++++++++++++ 3 files changed, 74 insertions(+) create mode 100644 net/lwip/apps/dhcp/lwip-dhcp.c diff --git a/include/net/lwip.h b/include/net/lwip.h index ab3db1a214..6a8fcef392 100644 --- a/include/net/lwip.h +++ b/include/net/lwip.h @@ -17,3 +17,15 @@ int do_lwip_dns(struct cmd_tbl *cmdtp, int flag, int argc, * Other value < 0, if error */ int ulwip_dns(char *name, char *varname); + +/** + * ulwip_dhcp() - create the DHCP request to obtain IP address. + * + * This function creates the DHCP request to obtain IP address. If DHCP server + * returns file name, this file will be downloaded with tftp. After this + * function you need to invoke the polling loop to process network communication. + * + * Returns: 0 if success + * Other value < 0, if error +*/ +int ulwip_dhcp(void); diff --git a/net/lwip/Makefile b/net/lwip/Makefile index 5d8d5527c6..a3a33b7f71 100644 --- a/net/lwip/Makefile +++ b/net/lwip/Makefile @@ -63,4 +63,5 @@ obj-$(CONFIG_NET) += lwip-external/src/netif/ethernet.o obj-$(CONFIG_NET) += port/if.o obj-$(CONFIG_NET) += port/sys-arch.o +obj-y += apps/dhcp/lwip-dhcp.o obj-y += apps/dns/lwip-dns.o diff --git a/net/lwip/apps/dhcp/lwip-dhcp.c b/net/lwip/apps/dhcp/lwip-dhcp.c new file mode 100644 index 0000000000..68334a02bb --- /dev/null +++ b/net/lwip/apps/dhcp/lwip-dhcp.c @@ -0,0 +1,61 @@ +// SPDX-License-Identifier: GPL-2.0 + +/* + * (C) Copyright 2023 Linaro Ltd. + */ + +#include +#include +#include + +#include +#include +#include "lwip/timeouts.h" + +#include +#include + +#define DHCP_WAIT_MS 2000 + +static void dhcp_tmo(void *arg) +{ + struct netif *netif = (struct netif *)arg; + struct dhcp *dhcp; + int err = 0; + + dhcp = netif_get_client_data(netif, LWIP_NETIF_CLIENT_DATA_INDEX_DHCP); + if (!dhcp) + return; + + switch (dhcp->state) { + case DHCP_STATE_BOUND: + err += env_set("bootfile", dhcp->boot_file_name); + err += env_set("ipaddr", ip4addr_ntoa(&dhcp->offered_ip_addr)); + err += env_set("netmask", ip4addr_ntoa(&dhcp->offered_sn_mask)); + err += env_set("serverip", ip4addr_ntoa(&dhcp->server_ip_addr)); + if (err) + log_err("error update envs\n"); + log_info("DHCP client bound to address %s\n", ip4addr_ntoa(&dhcp->offered_ip_addr)); + break; + default: + return; + } +} + +int ulwip_dhcp(void) +{ + struct netif *netif; + int eth_idx; + + eth_idx = eth_get_dev_index(); + if (eth_idx < 0) + return -EPERM; + + netif = netif_get_by_index(eth_idx + 1); + if (!netif) + return -ENOENT; + + sys_timeout(DHCP_WAIT_MS, dhcp_tmo, netif); + + return dhcp_start(netif) ? 0 : -EPERM; +} From patchwork Fri Sep 8 13:53:10 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxim Uvarov X-Patchwork-Id: 720818 Delivered-To: patch@linaro.org Received: by 2002:adf:eec5:0:b0:31d:da82:a3b4 with SMTP id a5csp778981wrp; Fri, 8 Sep 2023 06:56:27 -0700 (PDT) X-Google-Smtp-Source: AGHT+IE9suc3vRaGkCkdM9RRnE/B/RJxiCH6jTeTnn0syBBEQEGssIw1XN1z7DZCzeZg3gmjwW+w X-Received: by 2002:a5d:4d4b:0:b0:31a:d2b2:f29d with SMTP id a11-20020a5d4d4b000000b0031ad2b2f29dmr2339235wru.8.1694181386776; Fri, 08 Sep 2023 06:56:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694181386; cv=none; d=google.com; s=arc-20160816; b=klTG+DKziaRbts6YdzNhz4KcRoxiDLGMrOcf1fg1M+qyIL7CiReIJlE7uusUN36zJV W3514ttyxfjZKIzmq28FZd+7Xi3nKJ8TwlRIGSQA8oLOS1TJ6Rg5eLNhan3+/9kn+YVP TVWfcjDdpD1qJ+gWYo1A/1M4CR6FSU5fQJn9hwm9p4XjEpe+hgABkzy4/KN0ZdUsdGEt fqGs9DgpU8YZznD0aD/xILoX3eFwqgLQcQ2ch9KrR/0/neNeCwgWd+PGDVpBoyZfMamW P/cFkqfylP37X9jWZbaofbXSlQyi482eV1HoxAqZ4gwUWRezeBqb6Bhm+HGgUS+ZReIS +Llw== 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=pzg+r3izm5ZAuNWp/Ab142FiGLW7Rh4mOEO+/xgK6UM=; fh=hYoOR0yg+Fo7S26X8ur5L+RaTmkyxWlAVaBypEC8A0g=; b=nSuXYRVy+cU4y5MMbo1b/zvwAhFjyeKE4Q4Xp2bWBBTYDLnXUrqKAr/XTdxsvN5vzx 6mQOm3aL+3PEgDOVkplsKgWgZZvWCcEXJKgh+g1+s9e81AAZMtdaKbascuvVkL31pP2K e02uG81/iCFFTuLSj9tNEaMJP343K9wEGnqeBGgdpzpF4CYW+9Win8VsrdzucIbtizXN WCa5gETaqtn5k+XnTNfP02s/UCzUmVlfR/klHdSb29Jf4K1q/XSh8m5ydo/u2sLlMQwm b1SIQ23OJN4wLTQo/tXKou/mKjc7a3t8+R8Ob+iFxkLxsCKj5b+uEvV7L6UgZ+3VnvCd hWmA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=lRjjaCLj; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 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. [85.214.62.61]) by mx.google.com with ESMTPS id u17-20020a5d5151000000b0031ddeea13dasi800658wrt.377.2023.09.08.06.56.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Sep 2023 06:56:26 -0700 (PDT) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) client-ip=85.214.62.61; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=lRjjaCLj; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 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 7D18486A81; Fri, 8 Sep 2023 15:55:47 +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="lRjjaCLj"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 59D0B86A6B; Fri, 8 Sep 2023 15:55:46 +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-x235.google.com (mail-lj1-x235.google.com [IPv6:2a00:1450:4864:20::235]) (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 A2C9786A35 for ; Fri, 8 Sep 2023 15:55:43 +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-x235.google.com with SMTP id 38308e7fff4ca-2b703a0453fso35557641fa.3 for ; Fri, 08 Sep 2023 06:55:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1694181343; x=1694786143; darn=lists.denx.de; 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=pzg+r3izm5ZAuNWp/Ab142FiGLW7Rh4mOEO+/xgK6UM=; b=lRjjaCLjkzzorrx71O6XsHTF2ln0F53GNC2lTx87D/6iQBkoBX93J+3NifOmG9xT68 hLr+UUuzlyUpFD1/JwnQHpS26NsEp6pta9ff/MuM/azqhEE9nU7Bf+DrIgNMt+ljkGQy wxARCrvxWFuAd3hHEuaS6jLJj9wW3dy0f8PxBWookqgGuyZPWzR9qhXL5xlGZyYzNTLT RY7UFJS86ud+DSdSNmaNZUrLbcH/nx/dJe+s45v+hgHoA+t7Pc0TXFQh3qnBUlW2wP8n vDlhwtFctFFHfYc4O4Kwy60L2/yIZ+5jH34UDLM9xeD+jtDFhSWQVIcYj7FXL23PLOoU umLg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694181343; x=1694786143; 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=pzg+r3izm5ZAuNWp/Ab142FiGLW7Rh4mOEO+/xgK6UM=; b=gm4zJ5Wl33ctv6uA1XXOnO8+U+Im/DNljAOhV/FEeJkr2wvL+caGSeY3+rPZm8Fppv JQQOr/aGsBIG1cWXIEdaaZbL9U+kdsY5pGjx0c5P1KCrVr0NbR2+wnZ9A1H7xG8UxWYM l0Gghq5wrHKcdg9jew+ln2zAZqLskLPYybCkq89LwXOkZtpqKLd2T5IdNUDEdDIkjEB3 2T3X6bq1HgiYE/KaI3uivtyMt0yfx+EcWYBp0NIa1EZvlIWe6Tgc8G/2DV0x12EJM1Oa +oTj1f1YgY0cv9FxNn/GDJslJ+DZWn+SLvYVUf/DqbFhIVKZVXuFeLzGa+COXyqoQo7J PhMw== X-Gm-Message-State: AOJu0YxQSHLHFpIafQlKOxUPfnROsp2YIE8XvNgwqwd55G2tIw+6rE41 Fv/TEToZd/KYyQXm3gNAaPyQu+/TfjzGct9pqF6VsQ== X-Received: by 2002:a2e:8714:0:b0:2bc:d7cb:8283 with SMTP id m20-20020a2e8714000000b002bcd7cb8283mr1674756lji.40.1694181342647; Fri, 08 Sep 2023 06:55:42 -0700 (PDT) Received: from localhost.localdomain ([45.82.14.220]) by smtp.gmail.com with ESMTPSA id u14-20020a2e9f0e000000b002bcbae4c21fsm306907ljk.50.2023.09.08.06.55.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Sep 2023 06:55:42 -0700 (PDT) From: Maxim Uvarov To: u-boot@lists.denx.de Cc: pbrobinson@gmail.com, ilias.apalodimas@linaro.org, joe.hershberger@ni.com, rfried.dev@gmail.com, trini@konsulko.com, goldsimon@gmx.de, Maxim Uvarov Subject: [PATCHv8 05/15] net/lwip: implement tftp cmd Date: Fri, 8 Sep 2023 19:53:10 +0600 Message-Id: <20230908135320.7066-6-maxim.uvarov@linaro.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230908135320.7066-1-maxim.uvarov@linaro.org> References: <20230908135320.7066-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 U-Boot recently got support for an alternative network stack using LWIP. Replace tftp command with the LWIP variant while keeping the output and error messages identical. Signed-off-by: Maxim Uvarov --- include/net/lwip.h | 14 +++- net/lwip/Makefile | 1 + net/lwip/apps/tftp/Makefile | 7 ++ net/lwip/apps/tftp/lwip-tftp.c | 129 +++++++++++++++++++++++++++++++++ 4 files changed, 150 insertions(+), 1 deletion(-) create mode 100644 net/lwip/apps/tftp/Makefile create mode 100644 net/lwip/apps/tftp/lwip-tftp.c diff --git a/include/net/lwip.h b/include/net/lwip.h index 6a8fcef392..c9e2982a78 100644 --- a/include/net/lwip.h +++ b/include/net/lwip.h @@ -28,4 +28,16 @@ int ulwip_dns(char *name, char *varname); * Returns: 0 if success * Other value < 0, if error */ -int ulwip_dhcp(void); + +/** + * ulwip_tftp() - load file with tftp + * + * Load file with tftp to specific address + * + * @addr: Address to store downloaded file + * @filename: File name on remote tftp server to download + * + * + * Returns: 0 if success, !0 if error + */ +int ulwip_tftp(ulong addr, const char *filename); diff --git a/net/lwip/Makefile b/net/lwip/Makefile index a3a33b7f71..b348e5ca31 100644 --- a/net/lwip/Makefile +++ b/net/lwip/Makefile @@ -65,3 +65,4 @@ obj-$(CONFIG_NET) += port/sys-arch.o obj-y += apps/dhcp/lwip-dhcp.o obj-y += apps/dns/lwip-dns.o +obj-y += apps/tftp/ diff --git a/net/lwip/apps/tftp/Makefile b/net/lwip/apps/tftp/Makefile new file mode 100644 index 0000000000..c3ad3c6353 --- /dev/null +++ b/net/lwip/apps/tftp/Makefile @@ -0,0 +1,7 @@ +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$(srctree)/net/lwip/lwip-external/src/include/lwip/apps +ccflags-y += -I$(srctree)/net/lwip/lwip-external/contrib/examples/tftp/ + +obj-y += ../../lwip-external/src/apps/tftp/tftp.o +obj-y += 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..56eed3030b --- /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 "tftp_client.h" +#include "tftp_server.h" +#include + +#include + +#include + +static ulong daddr; +static ulong size; + +static void *tftp_open(const char *fname, const char *mode, u8_t is_write) +{ + 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"); + if (env_set_hex("filesize", size)) { + log_err("filesize not updated\n"); + ulwip_exit(-1); + return; + } + 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]; + + 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; + } + + if (env_set_hex("fileaddr", addr)) { + log_err("fileaddr not updated\n"); + return CMD_RET_FAILURE; + } + + return CMD_RET_SUCCESS; +} From patchwork Fri Sep 8 13:53:11 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxim Uvarov X-Patchwork-Id: 720819 Delivered-To: patch@linaro.org Received: by 2002:adf:eec5:0:b0:31d:da82:a3b4 with SMTP id a5csp779053wrp; Fri, 8 Sep 2023 06:56:37 -0700 (PDT) X-Google-Smtp-Source: AGHT+IH3jpyieCukX8MDmIJ6YnV6/GleyYqx8NxFVme21OOKzuNyRLWed3laMrF+NPSARF8geRoO X-Received: by 2002:a7b:c3d5:0:b0:401:73b2:f043 with SMTP id t21-20020a7bc3d5000000b0040173b2f043mr2309920wmj.1.1694181397061; Fri, 08 Sep 2023 06:56:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694181397; cv=none; d=google.com; s=arc-20160816; b=ntcYmIrWCHl2n8z0pUAx+eiZqi7tRtF4nOr0HkzyWndQHuXsRjFFgzQZ3aVqxr+pPD B5QuQD3Lx04gF8vyqyAgYuLREqvCiQBwv8GZQkdp/8ks1TOB1XEiteL05Ci9SoOO/Zy/ iepvBYyIQJRTm/a3V0sbftnT4y1AG6SzLMqwx8JUTvMY0H53zC4McmVZBwJtYyy2enHV aTn9T+4srFfs7Kh8VTSYnW4fr+f7q694u3dFahA9QQ59pLgab5dBskT8oKF5YRVqhyUU W+AdGK1TrdxiO06i+PYztj7Y7IRFWTc/+2bL4pnGou45GhKura8Bn5UTC6d3j1l2Y1E1 CAOQ== 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=HfQkS+Ld/qDASFnGXUOeUGjIwT7to1GV91ev5AX2Umc=; fh=hYoOR0yg+Fo7S26X8ur5L+RaTmkyxWlAVaBypEC8A0g=; b=XFFHOdyp4lrPKb+yUDk9d0WfWiw0hxWsH4D4NHpkzeLaTLPSfLvlwO5Owodn4I5czq oIYVI+KRunEKnxOwA3bx0z3TSCasUW70Bpbypsl5u0P7Wk6mEum4D9/yVEOGbNwym/Hw 7QPGu5F9JgyQdkBWTs3cgT2+A/axWJqRs+e6gPQMRBg4o83Yi62qryIq0DwJHOAUg+A+ LilySaC0zvDVkA24QDjfhAHQiRkiN3VFBSAL0mjX0VnL2qdInR6LZZ/8flJk2M6KzG98 X89bBzpwKAeXPYXImHILte0zvBmUCym9hGTtmyZrfYl4AKP6nXusqOKjJNkRnl743TYe Eviw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=nufeNNPa; 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 l9-20020a5d4809000000b0031751d7d8a5si812224wrq.453.2023.09.08.06.56.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Sep 2023 06:56:37 -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=nufeNNPa; 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 CE50386A91; Fri, 8 Sep 2023 15:55:48 +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="nufeNNPa"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 79EC986A88; Fri, 8 Sep 2023 15:55:48 +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-x22e.google.com (mail-lj1-x22e.google.com [IPv6:2a00:1450:4864:20::22e]) (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 C1D1C86A50 for ; Fri, 8 Sep 2023 15:55:45 +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-x22e.google.com with SMTP id 38308e7fff4ca-2b974031aeaso37230441fa.0 for ; Fri, 08 Sep 2023 06:55:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1694181345; x=1694786145; darn=lists.denx.de; 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=HfQkS+Ld/qDASFnGXUOeUGjIwT7to1GV91ev5AX2Umc=; b=nufeNNPazYu5yZEO7c8A4/9oZKGVY+8f0ATjd8AlodwiXRA02npWlVvyCyXSpyR89n vWENOOWdJK3AjTrpqtkUbewlglXTOiiNXgo6mUsZRByeSRHKdSJV4PayeGl4nEOBMXXO EulziDGyZd/X2Slnzy1sIOVNr5HW22h1rSuCN0qEfD0a+nbWSJcOTOo81frkTg3kTO1X OLSMlhYvZpW6s2XzrdPy6y/3PssFr8U3jO/Po5E5dTcx/71HzOISMzdKnb4g7X1yDoug rfZmKooMKTYaT4p9iBeF6P8k/z5TrdFvawnDwfKmxrmQHyvfvpZ+hHELcYWKgYITfuMS e+Aw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694181345; x=1694786145; 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=HfQkS+Ld/qDASFnGXUOeUGjIwT7to1GV91ev5AX2Umc=; b=cb1rrbFX5/SFGQXcBAxP78GqBl0/gNdFLH34EYSdyE0vfCH9E58uVt0683MTM3Wh4f W/Op5MeT9lxlusgobq5WjjQvJj3Bu9aZWNdSaVvVSP4DrBKsqokzF3NFh4+pmeyQ0uXK YUpJ8TfaqsFz3Wc3/txEfxycIdvDZpYoRvt2qCjlfRUY1qHiHOzedT3a1KsNjrVzLQ4I Wp/yAMILCCHi/FJ7hVrPmzy2eA3/oK2Y+3SAbejFT5OiwJxg07oZTQEudUGgYgEi1BDA i2OQEhtjD+KoBlEtO2keQZN86GP9rzJKFWleI0arbufp+ByjBDqPmd7v0sYCOQXCzfI7 LhCw== X-Gm-Message-State: AOJu0YyB8nXMK/kXhGnfuL0SxQos6r79ooLlBUpuadS/rAZIOl/pZIJd UxCKiTvPGBbMK2OtCYqbW1LpXp36Gtr3mbJOII9o9Q== X-Received: by 2002:a2e:9012:0:b0:2bc:db5a:9540 with SMTP id h18-20020a2e9012000000b002bcdb5a9540mr1954900ljg.42.1694181344944; Fri, 08 Sep 2023 06:55:44 -0700 (PDT) Received: from localhost.localdomain ([45.82.14.220]) by smtp.gmail.com with ESMTPSA id u14-20020a2e9f0e000000b002bcbae4c21fsm306907ljk.50.2023.09.08.06.55.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Sep 2023 06:55:44 -0700 (PDT) From: Maxim Uvarov To: u-boot@lists.denx.de Cc: pbrobinson@gmail.com, ilias.apalodimas@linaro.org, joe.hershberger@ni.com, rfried.dev@gmail.com, trini@konsulko.com, goldsimon@gmx.de, Maxim Uvarov Subject: [PATCHv8 06/15] net/lwip: implement wget cmd Date: Fri, 8 Sep 2023 19:53:11 +0600 Message-Id: <20230908135320.7066-7-maxim.uvarov@linaro.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230908135320.7066-1-maxim.uvarov@linaro.org> References: <20230908135320.7066-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 U-Boot recently got support for an alternative network stack using LWIP. Replace wget command with the LWIP variant while keeping the output and error messages identical. Signed-off-by: Maxim Uvarov --- include/net/lwip.h | 15 +++++ net/lwip/Makefile | 1 + net/lwip/apps/http/Makefile | 6 ++ net/lwip/apps/http/lwip-wget.c | 106 +++++++++++++++++++++++++++++++++ 4 files changed, 128 insertions(+) create mode 100644 net/lwip/apps/http/Makefile create mode 100644 net/lwip/apps/http/lwip-wget.c diff --git a/include/net/lwip.h b/include/net/lwip.h index c9e2982a78..85f08343fd 100644 --- a/include/net/lwip.h +++ b/include/net/lwip.h @@ -28,6 +28,7 @@ int ulwip_dns(char *name, char *varname); * Returns: 0 if success * Other value < 0, if error */ +int ulwip_dhcp(void); /** * ulwip_tftp() - load file with tftp @@ -41,3 +42,17 @@ int ulwip_dns(char *name, char *varname); * Returns: 0 if success, !0 if error */ int ulwip_tftp(ulong addr, const char *filename); + +/** + * ulwip_wget() - creates the HTTP request to download file + * + * This function creates the HTTP request to download file from url to the address + * specified in parameters. After this function you need to invoke the polling + * loop to process network communication. + * + * + * @addr: start address to download result + * @url: url in format http://host/url + * Returns: 0 for success, !0 if error + */ +int ulwip_wget(ulong addr, char *url); diff --git a/net/lwip/Makefile b/net/lwip/Makefile index b348e5ca31..61042862e1 100644 --- a/net/lwip/Makefile +++ b/net/lwip/Makefile @@ -66,3 +66,4 @@ obj-$(CONFIG_NET) += port/sys-arch.o obj-y += apps/dhcp/lwip-dhcp.o obj-y += apps/dns/lwip-dns.o obj-y += apps/tftp/ +obj-y += apps/http/ diff --git a/net/lwip/apps/http/Makefile b/net/lwip/apps/http/Makefile new file mode 100644 index 0000000000..ac0b3ede0d --- /dev/null +++ b/net/lwip/apps/http/Makefile @@ -0,0 +1,6 @@ +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$(srctree)/net/lwip/lwip-external/src/include/lwip/apps + +obj-$(CONFIG_CMD_WGET) += ../../lwip-external/src/apps/http/http_client.o +obj-$(CONFIG_CMD_WGET) += lwip-wget.o diff --git a/net/lwip/apps/http/lwip-wget.c b/net/lwip/apps/http/lwip-wget.c new file mode 100644 index 0000000000..5c432056b1 --- /dev/null +++ b/net/lwip/apps/http/lwip-wget.c @@ -0,0 +1,106 @@ +// SPDX-License-Identifier: GPL-2.0 + +/* + * (C) Copyright 2023 Linaro Ltd. + */ + +#include +#include +#include +#include + +#include "http_client.h" +#include + +static ulong daddr; +static httpc_connection_t settings; + +#define SERVER_NAME_SIZE 200 +#define HTTP_PORT_DEFAULT 80 + +static err_t httpc_recv(void *arg, struct altcp_pcb *pcb, struct pbuf *pbuf, + err_t unused_err) +{ + struct pbuf *buf; + + if (!pbuf) + return ERR_BUF; + + for (buf = pbuf; buf != NULL; buf = buf->next) { + memcpy((void *)daddr, buf->payload, buf->len); + log_debug("downloaded chunk size %d, to addr 0x%lx\n", + buf->len, daddr); + daddr += buf->len; + } + + altcp_recved(pcb, pbuf->tot_len); + pbuf_free(pbuf); + return ERR_OK; +} + +static void httpc_result(void *arg, httpc_result_t httpc_result, u32_t rx_content_len, + u32_t srv_res, err_t err) +{ + if (httpc_result == HTTPC_RESULT_OK) { + log_info("\n%d bytes successfully downloaded.\n", rx_content_len); + env_set_hex("filesize", rx_content_len); + ulwip_exit(0); + } else { + log_err("\nhttp eroror: %d\n", httpc_result); + ulwip_exit(-1); + } +} + +/* http://hostname:port/url */ +static int parse_url(char *url, char *host, u16 *port) +{ + char *p, *pp; + + p = strstr(url, "http://"); + if (!p) + return -1; + + p += strlen("http://"); + + /* parse hostname */ + pp = strchr(p, '/'); + if (!pp) { + return -2; + } + + if (pp - p >= SERVER_NAME_SIZE) + return -3; + + memcpy(host, p, pp - p); + host[pp - p + 1] = '\0'; + *port = HTTP_PORT_DEFAULT; + + return 0; +} + +int ulwip_wget(ulong addr, char *url) +{ + err_t err; + u16 port; + char server_name[SERVER_NAME_SIZE]; + httpc_state_t *connection; + + daddr = addr; + + err = parse_url(url, server_name, &port); + if (err) + return -ENOENT; + + log_info("downloading %s to addr 0x%lx\n", url, addr); + memset(&settings, 0, sizeof(settings)); + settings.result_fn = httpc_result; + err = httpc_get_file_dns(server_name, port, url, &settings, + httpc_recv, NULL, &connection); + if (err != ERR_OK) + return -EPERM; + + if (env_set_hex("fileaddr", addr)) + return -EACCES; + + return 0; +} From patchwork Fri Sep 8 13:53:12 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxim Uvarov X-Patchwork-Id: 720820 Delivered-To: patch@linaro.org Received: by 2002:adf:eec5:0:b0:31d:da82:a3b4 with SMTP id a5csp779136wrp; Fri, 8 Sep 2023 06:56:47 -0700 (PDT) X-Google-Smtp-Source: AGHT+IExveQ2Gd8iOHmRG+jOYYE8oekSIG71IReOiiMnXmukyRfViC6IcxcuTneACmjOCkqUO/dy X-Received: by 2002:a5d:54c8:0:b0:317:5af3:caa4 with SMTP id x8-20020a5d54c8000000b003175af3caa4mr1836264wrv.38.1694181406812; Fri, 08 Sep 2023 06:56:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694181406; cv=none; d=google.com; s=arc-20160816; b=POyMPCHyV2UEG8AabWmy4pdZ/gRxNoB48jgnpif5GKJKszDfN/eEKzUtXHUhNw0hzC zeizazSRNcTQJ9GSqI9x1e2byjfQbcO2pC5KjCynH0IUrTvstX0hC3Qva1J2I9i9GJn8 0zjMhACiyq3Q+mog6yfTItlsLVm+ySmsaV7LvZx89kr/ZbKXErwRT/nQqWUwq8EwWpnx oXwwwPRWSgOh0G8BqbmcXlN+kV6u1jOnrLXSj/QJnTJ4FyuZxLPvkdII6uEjq8n2Qc3L juB1miWGA2/XhytmI/aJiQO9YUovrXWpLTvF5YcpkDV5vJMi2LFyX2ps9KFUgFe4I803 kq4A== 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=WSz/BUYMS3B2bmhO/W/vyl5g01v4ioz1ndySXjtZ3T8=; fh=hYoOR0yg+Fo7S26X8ur5L+RaTmkyxWlAVaBypEC8A0g=; b=xBtZHTP3+E/9Eu8HHnCscYPpM8DIL959w+edCscX0acg7+NTbq5L9dXRPNENDUe0M2 pvmSu14oPWBFRab8nOZM8BSbsCiGdxzuVGVMtk6dMm+xak2pZMvhkLEuaZ+0MAWSbBYU 7pItyLHxFZQlivrdFar+NJ4GH04/hH8OtyQ+pVjPpT7NjT6XYteHplVdZa4JbJobuCIA 7CERaPNC56VWs8JL3zdDTAxIAQOTHbyIUUA0lbJf2E13cwfUt6pyI2SIZy7FgoTpEkIT rousVj8uAzgzeucQcfeWj5wtU1Mp4fpMdhp+tvyBSfGl9OQVTeXTul6Mrk2DP0mPCfug G5Tw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=KDL83fZP; 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 x1-20020adfdcc1000000b0031c680a7497si809099wrm.766.2023.09.08.06.56.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Sep 2023 06:56:46 -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=KDL83fZP; 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 2BB4B86A50; Fri, 8 Sep 2023 15:55:53 +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="KDL83fZP"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id EE66386A50; Fri, 8 Sep 2023 15:55:51 +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-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 0841586A97 for ; Fri, 8 Sep 2023 15:55:49 +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-2bd0d19a304so36993781fa.1 for ; Fri, 08 Sep 2023 06:55:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1694181348; x=1694786148; darn=lists.denx.de; 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=WSz/BUYMS3B2bmhO/W/vyl5g01v4ioz1ndySXjtZ3T8=; b=KDL83fZP/ZfQ8i6JiqavteDEpx90ob4IhFfwhVwsE492gtoz3Jg6qwfi+rrq7qC28D QzU5+FUlu+CtswzGkPodyv6GLFRG/MW3xrxLkvU9rmD0++9iiFvG5JSCX0XzcyAtx+nQ vsbHDjeQbLyQj4C+TJTYhW01cYwHLWXISo1QTaWnKZdVTzJR2FN9BmZy9QSjVfIpq2aJ 8e1vjNYX1naFxWy6DpLoPe7/1vlCZIOLnNn2Zi2hgy39LlUeziX4SNQtn9xALuChPjRL saWhCCXHxhQQOPAYLG87+ijXu5xzr5OZ1mmU0y9jZam18baCoSB40SRPsQq2M4KM2kcC Z3sw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694181348; x=1694786148; 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=WSz/BUYMS3B2bmhO/W/vyl5g01v4ioz1ndySXjtZ3T8=; b=kQu3Oe4enS3h0ERgle551mHgDRMUl2ZJz/I9pS/a0ceRXFKTyteRCGvk/TyRyfoMOf 9luyIKSMIH9Nytas3YZ6xFiSPGFR+fUM/rWnNa+sNjKfnGCXxJog66EC4NKj1l1sPJKt GlbyWLrSXWHqn/n8iPrDOOETV+K30CIgwkxH6Gj0fm3bEkz5hc88O5i+qE++GhAcmkK/ PfxxPQtxjC5/0SSirl78dSXxNYi2b09UVDhVU6djrUiq9gQGGyvVGV55sRrdCErP1Ei9 b5qddydXHn5aViG7OktwvW/+DJginOB2Ox3V+xT7acJNAE5uVXpljhB7tVVQsOU/lqR2 WWIg== X-Gm-Message-State: AOJu0Yyoap6EtiAkBdKJwTEjIO9j0/lkG9Lfl+XJcbPrmXS1XaapSHdb 9RzPiN4kgJMAgq08zu+Ce/PYdVPjiOkRpfbVlsSC7g== X-Received: by 2002:a2e:9ad8:0:b0:2bd:16e6:e34a with SMTP id p24-20020a2e9ad8000000b002bd16e6e34amr1903702ljj.19.1694181347962; Fri, 08 Sep 2023 06:55:47 -0700 (PDT) Received: from localhost.localdomain ([45.82.14.220]) by smtp.gmail.com with ESMTPSA id u14-20020a2e9f0e000000b002bcbae4c21fsm306907ljk.50.2023.09.08.06.55.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Sep 2023 06:55:47 -0700 (PDT) From: Maxim Uvarov To: u-boot@lists.denx.de Cc: pbrobinson@gmail.com, ilias.apalodimas@linaro.org, joe.hershberger@ni.com, rfried.dev@gmail.com, trini@konsulko.com, goldsimon@gmx.de, Maxim Uvarov Subject: [PATCHv8 07/15] net/lwip: implement ping cmd Date: Fri, 8 Sep 2023 19:53:12 +0600 Message-Id: <20230908135320.7066-8-maxim.uvarov@linaro.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230908135320.7066-1-maxim.uvarov@linaro.org> References: <20230908135320.7066-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 U-Boot recently got support for an alternative network stack using LWIP. Replace ping command with the LWIP variant while keeping the output and error messages identical. ping uses lwIP contrib/apps/ping/ping.c code. Custom timeout is used to get an error message on not modified example. lwIP timeouts are not yet implemented in U-Boot (#define LWIP_TIMERS 1) so that for now ping can not rechange itself for continuous pings and stops after the first request (the same behavior as the original ping.) Signed-off-by: Maxim Uvarov --- include/net/lwip.h | 15 +++++++++++++ net/lwip/Makefile | 1 + net/lwip/apps/ping/Makefile | 12 ++++++++++ net/lwip/apps/ping/lwip_ping.c | 40 ++++++++++++++++++++++++++++++++++ net/lwip/apps/ping/lwip_ping.h | 15 +++++++++++++ net/lwip/apps/ping/ping.h | 19 ++++++++++++++++ 6 files changed, 102 insertions(+) create mode 100644 net/lwip/apps/ping/Makefile create mode 100644 net/lwip/apps/ping/lwip_ping.c create mode 100644 net/lwip/apps/ping/lwip_ping.h create mode 100644 net/lwip/apps/ping/ping.h diff --git a/include/net/lwip.h b/include/net/lwip.h index 85f08343fd..1e92f9871c 100644 --- a/include/net/lwip.h +++ b/include/net/lwip.h @@ -2,6 +2,8 @@ int do_lwip_dns(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]); +int do_lwip_ping(struct cmd_tbl *cmdtp, int flag, int argc, + char *const argv[]); /** * ulwip_dns() - creates the DNS request to resolve a domain host name @@ -56,3 +58,16 @@ int ulwip_tftp(ulong addr, const char *filename); * Returns: 0 for success, !0 if error */ int ulwip_wget(ulong addr, char *url); + +/** + * ulwip_ping - create the ping request + * + * This function creates the ping for address provided in parameters. + * After this function you need to invoke the polling + * loop to process network communication. + * + * + * @ping_addr: IP address to ping + * Returns: 0 for success, !0 if error +*/ +int ulwip_ping(char *ping_addr); diff --git a/net/lwip/Makefile b/net/lwip/Makefile index 61042862e1..5839d125c2 100644 --- a/net/lwip/Makefile +++ b/net/lwip/Makefile @@ -67,3 +67,4 @@ obj-y += apps/dhcp/lwip-dhcp.o obj-y += apps/dns/lwip-dns.o obj-y += apps/tftp/ obj-y += apps/http/ +obj-y += apps/ping/ diff --git a/net/lwip/apps/ping/Makefile b/net/lwip/apps/ping/Makefile new file mode 100644 index 0000000000..e567c0dc3e --- /dev/null +++ b/net/lwip/apps/ping/Makefile @@ -0,0 +1,12 @@ +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) + +# ping.c includes "ping.h", copy it to local directory, to override ping.h +.PHONY: $(obj)/ping.c +$(obj)/ping.o: $(obj)/ping.c +$(obj)/ping.c: + cp $(srctree)/net/lwip/lwip-external/contrib/apps/ping/ping.c $(obj)/ping.c + +obj-y += ping.o +obj-y += lwip_ping.o diff --git a/net/lwip/apps/ping/lwip_ping.c b/net/lwip/apps/ping/lwip_ping.c new file mode 100644 index 0000000000..231ea6473a --- /dev/null +++ b/net/lwip/apps/ping/lwip_ping.c @@ -0,0 +1,40 @@ +// SPDX-License-Identifier: GPL-2.0 + +/* + * (C) Copyright 2023 Linaro Ltd. + */ + +#include "lwip/opt.h" +#include "lwip/ip_addr.h" +#include "lwip/timeouts.h" +#include +#include "ping.h" +#include "lwip_ping.h" + +#define PING_WAIT_MS 1000 + +static ip_addr_t ip_target; + +static void ping_tmo(void *arg) +{ + char *ping_addr = (char *)arg; + + log_err("ping failed; host %s is not alive\n", ping_addr); + ulwip_exit(1); +} + +int ulwip_ping(char *ping_addr) +{ + int err; + + err = ipaddr_aton(ping_addr, &ip_target); + if (!err) + return -ENOENT; + + sys_timeout(PING_WAIT_MS, ping_tmo, ping_addr); + + ping_init(&ip_target); + ping_send_now(); + + return 0; +} diff --git a/net/lwip/apps/ping/lwip_ping.h b/net/lwip/apps/ping/lwip_ping.h new file mode 100644 index 0000000000..0374f07d9e --- /dev/null +++ b/net/lwip/apps/ping/lwip_ping.h @@ -0,0 +1,15 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ + +/* + * (C) Copyright 2023 Linaro Ltd. + */ + +#ifndef LWIP_PING_H +#define LWIP_PING_H + +#include + +void ping_raw_init(void); +void ping_send_now(void); + +#endif /* LWIP_PING_H */ diff --git a/net/lwip/apps/ping/ping.h b/net/lwip/apps/ping/ping.h new file mode 100644 index 0000000000..006a18c658 --- /dev/null +++ b/net/lwip/apps/ping/ping.h @@ -0,0 +1,19 @@ +/* SPDX-License-Identifier: GPL-2.0 */ + +#include +#include "lwip/ip_addr.h" + +#define LWIP_DEBUG 1 /* ping_time is under ifdef*/ +#define PING_RESULT(cond) { \ + if (cond == 1) { \ + printf("host %s a alive\n", ipaddr_ntoa(addr)); \ + printf(" %"U32_F" ms\n", (sys_now() - ping_time)); \ + ulwip_exit(0); \ + } else { \ + printf("ping failed; host %s in not alive\n",\ + ipaddr_ntoa(addr)); \ + ulwip_exit(-1); \ + } \ + } while (0); + +void ping_init(const ip_addr_t *ping_addr); From patchwork Fri Sep 8 13:53:13 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxim Uvarov X-Patchwork-Id: 720821 Delivered-To: patch@linaro.org Received: by 2002:adf:eec5:0:b0:31d:da82:a3b4 with SMTP id a5csp779227wrp; Fri, 8 Sep 2023 06:56:57 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEWuHfOarvfplLZj+5CBJrHlsvV/jIJ0OauIhgfz5A5xHlDKhAv58I34I/ngsM20ApsWiek X-Received: by 2002:a05:600c:204c:b0:401:23fc:1f92 with SMTP id p12-20020a05600c204c00b0040123fc1f92mr2204416wmg.25.1694181417316; Fri, 08 Sep 2023 06:56:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694181417; cv=none; d=google.com; s=arc-20160816; b=FbMbaxdnTajYTEgLQtq3h6+6V+Zyel0ovqRJKlBTuP8cS6FnUAR9/2gv0YQpZuFVPj WW6fGhD9fNuO3fcxCiI0oUHS8fz2Ew3XMSo58/taHk6PsfW0+ilTEXws4edVAZwyM7av rPNr7Y65oZ6n8hdyd2IhmOrLeuol+cLxrwozN1PFV7dXIUyTAJiRkqnu6XCvTin2/o3u GWd9one01EUoHjVUhUVLszSI1v+nE+RpUVyx+D+lb/3HF4o40QMMC4yh7yHsNc/PH9u0 R6b//y2gYlANzBw6pNW4nJmNO7X+2uTZwl07WM3O+z9+qsjlnYsnk5E54EnPcTRS4x0h CftA== 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=WNzzTO9A4gGM/m8/mh0dG+0DOn4j7ZyXt/4zJSA/HSg=; fh=hYoOR0yg+Fo7S26X8ur5L+RaTmkyxWlAVaBypEC8A0g=; b=aLz9a0uNBuH0u+Qolt1ld+Xl1CLFUDoXP5lYI7SK3C3j/5tMNQNz5erSq86Qxhbk4a Tt//8yghzxrZ16Ml0324lyrg3f6p9mnwkLwjz/7um5UCrzjEyfvQSobyix5H3j2CHZxW zRbL5KHZTNmnVKZpx8xFvWqzmt1+iiPusTRnOriwKynAcWNlqOAwS6ZIOqG7z7pl4uQS y56bQwd5j8KyUoIPyqP1gRebarQy1mc193ttCjhYi0hhskAgUI/XIh9kcNeccdKGC1B1 5nh74lUVKRJY5UXCGcllie3O7tnclfvGuQcoLtWp/AEUJJYUxAEfMaAxnHNp1Ak3Y7mN uA4w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=SqfrhxhI; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 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. [85.214.62.61]) by mx.google.com with ESMTPS id o4-20020a1c7504000000b003fe21ac3f4asi873380wmc.191.2023.09.08.06.56.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Sep 2023 06:56:57 -0700 (PDT) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) client-ip=85.214.62.61; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=SqfrhxhI; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 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 7E46986A6B; Fri, 8 Sep 2023 15:55:55 +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="SqfrhxhI"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 3A4C686A6B; Fri, 8 Sep 2023 15:55:54 +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, UPPERCASE_50_75 autolearn=no 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 86A8486A17 for ; Fri, 8 Sep 2023 15:55:51 +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-2bd3f629c76so35824061fa.0 for ; Fri, 08 Sep 2023 06:55:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1694181350; x=1694786150; darn=lists.denx.de; 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=WNzzTO9A4gGM/m8/mh0dG+0DOn4j7ZyXt/4zJSA/HSg=; b=SqfrhxhIWoOP9l7CYa2TPOhveNynGj44nVS88e4UyNiWP05IVFPKTOUSY2Pf7gMOFr chdTyuA2YfT+pWzZCHpQCxBsMqsxRZvze4sX0Szr9yau+JB0IlzBnm6Ib6td2xiM2/9J X8MxbEtFC0TgnAWUUz2k8IBQG8bKg6skB7vsvT4+JH8RgBtGMcADRdzU4ncSjKM+XNke fMk1WoHEkG3vg3v2psrADIMr+kXU2Y9TEh7X5zs4TPktO90CCmnLxSnWxFF3wS/TqP5O Vgjedtvga2+ErMkbzsZQzZl7kujXXUmnOflvBDmK0Ybun90KRDbZBn+YAnnvSKzpJCTJ Rfog== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694181350; x=1694786150; 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=WNzzTO9A4gGM/m8/mh0dG+0DOn4j7ZyXt/4zJSA/HSg=; b=jX9fDZgpV4B7i/4wlvimqziHZLEi2Dsm05weHxb/Vn1bBsgwyN+0CIW/HZhHVm2gxc 7Icygldy70RbpKCjRLHwvYCYUzxk7MKFmGdIOL7IlaIP7VgIvgACDsq5GIazZtD9IyPF OxvOHg8bHSZkH9/XMA8hPbgQLs6ml7BtwZUu0A5hG/XkJ8z2bTftMaVbz7OkMAIO6Dvd RR5gAlukv/X8qZ4zEjgII3uDpLZC6Hbk2edQt3IMHx4jZWfICooyJ1NOWsvHzTrXn46e xJmV2VnGGjF4Ja0UKH2dO9LIq/TEWoOjs54vAtc1yKCRCN6ov6ujpQBoJb6bjgDiccB0 dyxw== X-Gm-Message-State: AOJu0Yz0aJKCiSc36I0HDvX0R+kB/L57Xros/+QjBu2XDKUM7DTWWUp/ EszrFPq/Ra+7kiN6WzIx5tkTnbydgI41wxe7stW1fw== X-Received: by 2002:a2e:8718:0:b0:2bc:c4af:36b7 with SMTP id m24-20020a2e8718000000b002bcc4af36b7mr1857288lji.39.1694181350716; Fri, 08 Sep 2023 06:55:50 -0700 (PDT) Received: from localhost.localdomain ([45.82.14.220]) by smtp.gmail.com with ESMTPSA id u14-20020a2e9f0e000000b002bcbae4c21fsm306907ljk.50.2023.09.08.06.55.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Sep 2023 06:55:50 -0700 (PDT) From: Maxim Uvarov To: u-boot@lists.denx.de Cc: pbrobinson@gmail.com, ilias.apalodimas@linaro.org, joe.hershberger@ni.com, rfried.dev@gmail.com, trini@konsulko.com, goldsimon@gmx.de, Maxim Uvarov Subject: [PATCHv8 08/15] net/lwip: add lwIP configuration Date: Fri, 8 Sep 2023 19:53:13 +0600 Message-Id: <20230908135320.7066-9-maxim.uvarov@linaro.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230908135320.7066-1-maxim.uvarov@linaro.org> References: <20230908135320.7066-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 lwip configuration can be tuned with header file. Signed-off-by: Maxim Uvarov --- net/lwip/lwipopts.h | 178 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 178 insertions(+) create mode 100644 net/lwip/lwipopts.h diff --git a/net/lwip/lwipopts.h b/net/lwip/lwipopts.h new file mode 100644 index 0000000000..731da30baa --- /dev/null +++ b/net/lwip/lwipopts.h @@ -0,0 +1,178 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ + +/* + * (C) Copyright 2023 Linaro Ltd. + */ + +#ifndef LWIP_LWIPOPTS_H +#define LWIP_LWIPOPTS_H + +#include "lwipopts.h" + +#if defined(CONFIG_LWIP_LIB_DEBUG) +#define LWIP_DEBUG 1 +#define LWIP_DBG_MIN_LEVEL LWIP_DBG_LEVEL_ALL +#define LWIP_DBG_TYPES_ON LWIP_DBG_ON +#define ETHARP_DEBUG LWIP_DBG_ON +#define NETIF_DEBUG LWIP_DBG_ON +#define PBUF_DEBUG LWIP_DBG_OFF +#define API_LIB_DEBUG LWIP_DBG_ON +#define API_MSG_DEBUG LWIP_DBG_OFF +#define SOCKETS_DEBUG LWIP_DBG_OFF +#define ICMP_DEBUG LWIP_DBG_OFF +#define IGMP_DEBUG LWIP_DBG_OFF +#define INET_DEBUG LWIP_DBG_OFF +#define IP_DEBUG LWIP_DBG_ON +#define IP_REASS_DEBUG LWIP_DBG_OFF +#define RAW_DEBUG LWIP_DBG_OFF +#define MEM_DEBUG LWIP_DBG_OFF +#define MEMP_DEBUG LWIP_DBG_OFF +#define SYS_DEBUG LWIP_DBG_OFF +#define TIMERS_DEBUG LWIP_DBG_ON +#define TCP_DEBUG LWIP_DBG_OFF +#define TCP_INPUT_DEBUG LWIP_DBG_OFF +#define TCP_FR_DEBUG LWIP_DBG_OFF +#define TCP_RTO_DEBUG LWIP_DBG_OFF +#define TCP_CWND_DEBUG LWIP_DBG_OFF +#define TCP_WND_DEBUG LWIP_DBG_OFF +#define TCP_OUTPUT_DEBUG LWIP_DBG_OFF +#define TCP_RST_DEBUG LWIP_DBG_OFF +#define TCP_QLEN_DEBUG LWIP_DBG_OFF +#define UDP_DEBUG LWIP_DBG_OFF +#define TCPIP_DEBUG LWIP_DBG_OFF +#define SLIP_DEBUG LWIP_DBG_OFF +#define DHCP_DEBUG LWIP_DBG_ON +#define AUTOIP_DEBUG LWIP_DBG_ON +#define DNS_DEBUG LWIP_DBG_ON +#define IP6_DEBUG LWIP_DBG_OFF +#define DHCP6_DEBUG LWIP_DBG_OFF +#else +#define LWIP_DBG_MIN_LEVEL LWIP_DBG_LEVEL_ALL +#define LWIP_DBG_TYPES_ON LWIP_DBG_OFF +#define ETHARP_DEBUG LWIP_DBG_OFF +#define NETIF_DEBUG LWIP_DBG_OFF +#define PBUF_DEBUG LWIP_DBG_OFF +#define API_LIB_DEBUG LWIP_DBG_OFF +#define API_MSG_DEBUG LWIP_DBG_OFF +#define SOCKETS_DEBUG LWIP_DBG_OFF +#define ICMP_DEBUG LWIP_DBG_OFF +#define IGMP_DEBUG LWIP_DBG_OFF +#define INET_DEBUG LWIP_DBG_OFF +#define IP_DEBUG LWIP_DBG_OFF +#define IP_REASS_DEBUG LWIP_DBG_OFF +#define RAW_DEBUG LWIP_DBG_OFF +#define MEM_DEBUG LWIP_DBG_OFF +#define MEMP_DEBUG LWIP_DBG_OFF +#define SYS_DEBUG LWIP_DBG_OFF +#define TIMERS_DEBUG LWIP_DBG_OFF +#define TCP_DEBUG LWIP_DBG_OFF +#define TCP_INPUT_DEBUG LWIP_DBG_OFF +#define TCP_FR_DEBUG LWIP_DBG_OFF +#define TCP_RTO_DEBUG LWIP_DBG_OFF +#define TCP_CWND_DEBUG LWIP_DBG_OFF +#define TCP_WND_DEBUG LWIP_DBG_OFF +#define TCP_OUTPUT_DEBUG LWIP_DBG_OFF +#define TCP_RST_DEBUG LWIP_DBG_OFF +#define TCP_QLEN_DEBUG LWIP_DBG_OFF +#define UDP_DEBUG LWIP_DBG_OFF +#define TCPIP_DEBUG LWIP_DBG_OFF +#define SLIP_DEBUG LWIP_DBG_OFF +#define DHCP_DEBUG LWIP_DBG_OFF +#define AUTOIP_DEBUG LWIP_DBG_OFF +#define DNS_DEBUG LWIP_DBG_OFF +#define IP6_DEBUG LWIP_DBG_OFF +#define DHCP6_DEBUG LWIP_DBG_OFF +#endif +#define LWIP_TESTMODE 0 + +#if defined(CONFIG_LWIP_LIB_NOASSERT) +#define LWIP_NOASSERT 1 +#define LWIP_ASSERT(message, assertion) +#endif + +#include "lwip/debug.h" + +#define SYS_LIGHTWEIGHT_PROT 0 +#define NO_SYS 1 + +#define LWIP_IPV6 0 + +#define MEM_ALIGNMENT 1 +#define MEM_SIZE 1600 + +#define MEMP_NUM_PBUF 4 +#define MEMP_NUM_RAW_PCB 2 +#define MEMP_NUM_UDP_PCB 4 +#define MEMP_NUM_TCP_PCB 2 +#define MEMP_NUM_TCP_PCB_LISTEN 2 +#define MEMP_NUM_TCP_SEG 16 +#define MEMP_NUM_REASSDATA 1 +#define MEMP_NUM_ARP_QUEUE 2 +#define MEMP_NUM_SYS_TIMEOUT 4 +#define MEMP_NUM_NETBUF 2 +#define MEMP_NUM_NETCONN 32 +#define MEMP_NUM_TCPIP_MSG_API 8 +#define MEMP_NUM_TCPIP_MSG_INPKT 8 +#define PBUF_POOL_SIZE 8 + +#define LWIP_ARP 1 +#define ARP_TABLE_SIZE 10 +#define ARP_QUEUEING 1 + +#define IP_FORWARD 0 +#define IP_OPTIONS_ALLOWED 1 +#define IP_REASSEMBLY 1 +#define IP_FRAG 1 +#define IP_REASS_MAXAGE 3 +#define IP_REASS_MAX_PBUFS 4 +#define IP_FRAG_USES_STATIC_BUF 0 + +#define IP_DEFAULT_TTL 255 + +#define LWIP_ICMP 1 + +#define LWIP_RAW 1 + +#define LWIP_DHCP 1 +#define LWIP_DHCP_BOOTP_FILE 1 +#define LWIP_DHCP_DOES_ACD_CHECK 0 + +#define LWIP_AUTOIP 0 + +#define LWIP_SNMP 0 + +#define LWIP_IGMP 0 + +#define LWIP_DNS 1 + +#define LWIP_UDP 1 + +#define LWIP_TCP 1 + +#define LWIP_LISTEN_BACKLOG 0 + +#define PBUF_LINK_HLEN 14 +#define PBUF_POOL_BUFSIZE LWIP_MEM_ALIGN_SIZE(TCP_MSS + 40 + PBUF_LINK_HLEN) + +#define LWIP_HAVE_LOOPIF 0 + +#define LWIP_NETCONN 0 +#define LWIP_DISABLE_MEMP_SANITY_CHECKS 1 + +#define LWIP_SOCKET 0 +#define SO_REUSE 0 + +#define LWIP_STATS 0 + +#define PPP_SUPPORT 0 + +#define LWIP_TCPIP_CORE_LOCKING 0 + +#define LWIP_NETIF_LOOPBACK 1 + +/* use malloc instead of pool */ +#define MEMP_MEM_MALLOC 1 +#define MEMP_MEM_INIT 1 +#define MEM_LIBC_MALLOC 1 + +#endif /* LWIP_LWIPOPTS_H */ From patchwork Fri Sep 8 13:53:14 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxim Uvarov X-Patchwork-Id: 720822 Delivered-To: patch@linaro.org Received: by 2002:adf:eec5:0:b0:31d:da82:a3b4 with SMTP id a5csp779297wrp; Fri, 8 Sep 2023 06:57:08 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGt5QVmTfMIYDz0gd7LqwJfa4FQ7LPzNadXixZL0HFN5ipdx8bfEwkMBKljLmqAQUIO2a4r X-Received: by 2002:a05:6000:1250:b0:31d:74f8:fae with SMTP id j16-20020a056000125000b0031d74f80faemr1766632wrx.71.1694181427952; Fri, 08 Sep 2023 06:57:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694181427; cv=none; d=google.com; s=arc-20160816; b=XDqFc20AXDZQovulBCBAf70bIRBaTG04l5NmiiyMX9zzTBgKjLGyl3dJLxgSNysXs7 My397x+zY2QWrKh420XxsQkE87s9ZMH1ajq+uNKFImJKL95DRMoUGGMxmQ3lFn0Wf/rZ pPOlQhRBPqkoE1U0EI/r7ZTG8YmmBaURDNAqW53Bt+E5xrvPtZebDi3KbkablGiOeLck x1mbwN296DWgMTiru802o2DUXOq+wGwQjLF6Gu2KyzN4onCC2tefnXQb1oOjOjmK2Jwu qWmR/NmQd4mjjMzmhiyxguvBbMDvOzAr/+My5H/HKr/YkTK8L89xChMQ0jrybM/ywg2y /Q+w== 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=ash13g7/if63QP3IHtWSLLGMQlWqbPSmRPF1wXNTlyw=; fh=hYoOR0yg+Fo7S26X8ur5L+RaTmkyxWlAVaBypEC8A0g=; b=N1kpyUNkZaz7fHFgXXdeuctIZfQKAV+d+eAZtK2b+ftfOEJjsHnDKUflg8bIqUT4e/ RnFX81SOgcgCXBoTs4EbpafkSzPJFpyDHq3I8qzhlEmAeHKhwPRJZY3rt/oDAFEvX9zh 6vnm8nyjGHFZZbzwbYKnikgPEx5MJV9PPO6NYocLib4LWifDu5c084fdV8BddPp6GgNA Y0F4h/mOZKjdWEOWnkneVkFr29a4uK5b/D97UtGR9Tg3fnkvMOExds8Xh9Ch3LMccYxL 1D8JFdRufyVnNDxq59Jh74EBf8FoMgjL4gCLPJfgZz8tZVCI12DJRLIJxt1oDbqWawxs UGag== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=kFhGJc+R; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 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. [85.214.62.61]) by mx.google.com with ESMTPS id w13-20020adfee4d000000b00317f7e2676bsi796353wro.152.2023.09.08.06.57.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Sep 2023 06:57:07 -0700 (PDT) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) client-ip=85.214.62.61; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=kFhGJc+R; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 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 CD7E186AA8; Fri, 8 Sep 2023 15:55:59 +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="kFhGJc+R"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 2AF1C86A2F; Fri, 8 Sep 2023 15:55:58 +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-x232.google.com (mail-lj1-x232.google.com [IPv6:2a00:1450:4864:20::232]) (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 4848886A17 for ; Fri, 8 Sep 2023 15:55:55 +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-x232.google.com with SMTP id 38308e7fff4ca-2b9c907bc68so35551691fa.2 for ; Fri, 08 Sep 2023 06:55:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1694181354; x=1694786154; darn=lists.denx.de; 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=ash13g7/if63QP3IHtWSLLGMQlWqbPSmRPF1wXNTlyw=; b=kFhGJc+RYdW+me09AXi8Jkhgp3z9dBlBecH88Ft01sQMNUWcy1N70zjiQOx8/265EC 8RBap/4LwHFZyQ1lFlQ1cMMBCdeV2Yw/IiciQpDBYlWKmWXOBA0JJbFDejRE/E5YzcK6 Gd4+QieB0mLvXfT2zfGDcBwwHfPu1pzA4V+oe6XXMKnCepxP11rg/B74Y2cIqBYCXdKC UrIgSJoWmOVBLthDAK3kih7UNuKS1MvVVNjBcfegu3qUVSipKO2tlmebN+XH73AbUZEw JWOvCnQueKOt23LDxFUXZNvXbJpTrOiqpOWajBGW2X63Zmc/UZSshoMmbgUFCk1GD779 fXsw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694181354; x=1694786154; 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=ash13g7/if63QP3IHtWSLLGMQlWqbPSmRPF1wXNTlyw=; b=Pa25C7z6x0pN16GTLPjUiSgQJ+RwDrM1pe1BFZTdNGNIJpbbj6TJNKP1pju4ZyCrDl F0jA0i78EiQhxsOlQTG6Viv1LihVnSu7+EQPtQsWFXPzMOrh6qc/5h3p3jK8mX4UpzEQ uOzdu5aFGOepFvTn27V1U7vNJWHctr0GPWqBU9bMvA51Jicgmjg/t0v9i1absAP0zm7b XYXcmlI1KJ+egRgazlp8VI7n5UJ4/fk/kYa2m9U97lFAXdcNJvBKbuH4pjYa4tS/2dWT 50MLG3J7gVOcPkT0Du8XrZrvVmnTSR6Mb8REe/p9P9GbrRO7T5BzHNBuqGzYjbK/00E+ 0osg== X-Gm-Message-State: AOJu0YxmxpJcSALIhZ3ZM1fK2YPkI7r0RBDudLI5d/XjhtcTarS/mdJz D9F14+mLAsvX8ZHLv17+/iopWRjzK2iWhlZWB67/7A== X-Received: by 2002:a2e:a406:0:b0:2b9:412a:111d with SMTP id p6-20020a2ea406000000b002b9412a111dmr2189491ljn.42.1694181354277; Fri, 08 Sep 2023 06:55:54 -0700 (PDT) Received: from localhost.localdomain ([45.82.14.220]) by smtp.gmail.com with ESMTPSA id u14-20020a2e9f0e000000b002bcbae4c21fsm306907ljk.50.2023.09.08.06.55.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Sep 2023 06:55:54 -0700 (PDT) From: Maxim Uvarov To: u-boot@lists.denx.de Cc: pbrobinson@gmail.com, ilias.apalodimas@linaro.org, joe.hershberger@ni.com, rfried.dev@gmail.com, trini@konsulko.com, goldsimon@gmx.de, Maxim Uvarov Subject: [PATCHv8 09/15] net/lwip: implement lwIP port to U-Boot Date: Fri, 8 Sep 2023 19:53:14 +0600 Message-Id: <20230908135320.7066-10-maxim.uvarov@linaro.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230908135320.7066-1-maxim.uvarov@linaro.org> References: <20230908135320.7066-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 port of lwIP stack to the U-Boot. lwIP is well known full IP stack which provides wide functionality, various examples, API closer to linux userland. Rich debug printing and possibility to run lwIP apps under linux make it easier to develop and debug apps. U-Boot implementation keeps the original file structure widely used for lwIP ports. (i.e. port/if.c port/sys-arch.c). That should allow us to easy port apps to or from U-Boot. Multiply ethernet devices are supported and "ethact" env variable chooses the active device. Having a rich IP stack inside U-Boot will allow us to have such applications as http or https clients. Signed-off-by: Maxim Uvarov --- net/eth-uclass.c | 8 + net/lwip/port/if.c | 332 ++++++++++++++++++++++++++ net/lwip/port/include/arch/cc.h | 38 +++ net/lwip/port/include/arch/sys_arch.h | 10 + net/lwip/port/include/limits.h | 0 net/lwip/port/sys-arch.c | 13 + 6 files changed, 401 insertions(+) create mode 100644 net/lwip/port/if.c create mode 100644 net/lwip/port/include/arch/cc.h create mode 100644 net/lwip/port/include/arch/sys_arch.h create mode 100644 net/lwip/port/include/limits.h create mode 100644 net/lwip/port/sys-arch.c diff --git a/net/eth-uclass.c b/net/eth-uclass.c index c393600fab..6625f6d8a5 100644 --- a/net/eth-uclass.c +++ b/net/eth-uclass.c @@ -32,6 +32,7 @@ DECLARE_GLOBAL_DATA_PTR; struct eth_device_priv { enum eth_state_t state; bool running; + ulwip ulwip; }; /** @@ -347,6 +348,13 @@ int eth_init(void) return ret; } +struct ulwip *eth_lwip_priv(struct udevice *current) +{ + struct eth_device_priv *priv = dev_get_uclass_priv(current); + + return &priv->ulwip; +} + void eth_halt(void) { struct udevice *current; diff --git a/net/lwip/port/if.c b/net/lwip/port/if.c new file mode 100644 index 0000000000..0025b1273f --- /dev/null +++ b/net/lwip/port/if.c @@ -0,0 +1,332 @@ +// SPDX-License-Identifier: GPL-2.0 + +/* + * (C) Copyright 2023 Linaro Ltd. + */ + +#include +#include +#include +#include +#include +#include +#include "lwip/debug.h" +#include "lwip/arch.h" +#include "netif/etharp.h" +#include "lwip/stats.h" +#include "lwip/def.h" +#include "lwip/mem.h" +#include "lwip/pbuf.h" +#include "lwip/sys.h" +#include "lwip/netif.h" +#include "lwip/ethip6.h" +#include "lwip/timeouts.h" + +#include "lwip/ip.h" + +/* + * MAC_ADDR_STRLEN: length of mac address string + */ +#define MAC_ADDR_STRLEN 17 + +int ulwip_enabled(void) +{ + struct udevice *udev; + struct ulwip *ulwip; + + udev = eth_get_dev(); + if (!udev) + return 0; + + ulwip = eth_lwip_priv(udev); + return ulwip->init_done; +} + +int ulwip_in_loop(void) +{ + struct udevice *udev; + struct ulwip *ulwip; + + udev = eth_get_dev(); + if (!udev) + return 0; + + sys_check_timeouts(); + + ulwip = eth_lwip_priv(udev); + return ulwip->loop; +} + +void ulwip_loop_set(int loop) +{ + struct udevice *udev; + struct ulwip *ulwip; + + udev = eth_get_dev(); + if (!udev) + return; + + ulwip = eth_lwip_priv(udev); + ulwip->loop = loop; +} + +void ulwip_exit(int err) +{ + struct udevice *udev; + struct ulwip *ulwip; + + udev = eth_get_dev(); + if (!udev) + return; + + ulwip = eth_lwip_priv(udev); + ulwip->loop = 0; + ulwip->err = err; +} + +int ulwip_app_get_err(void) +{ + struct udevice *udev; + struct ulwip *ulwip; + + udev = eth_get_dev(); + if (!udev) + return 0; + + ulwip = eth_lwip_priv(udev); + return ulwip->err; +} + +typedef struct { +} ulwip_if_t; + +static struct pbuf *low_level_input(void) +{ + struct pbuf *p, *q; + u16_t len = net_rx_packet_len; + uchar *data = net_rx_packet; + + /* We allocate a pbuf chain of pbufs from the pool. */ + p = pbuf_alloc(PBUF_RAW, len, PBUF_POOL); + if (!p) { + LINK_STATS_INC(link.memerr); + LINK_STATS_INC(link.drop); + return NULL; + } + + for (q = p; q != NULL; q = q->next) { + memcpy(q->payload, data, q->len); + data += q->len; + } + + LINK_STATS_INC(link.recv); + + return p; +} + +void ulwip_poll(void) +{ + struct pbuf *p; + int err; + struct netif *netif; + int eth_idx; + + eth_idx = eth_get_dev_index(); + if (eth_idx < 0) { + log_err("no eth idx\n"); + return; + } + + netif = netif_get_by_index(eth_idx + 1); + if (!netif) { + log_err("!netif\n"); + return; + } + + p = low_level_input(); + if (!p) { + log_err("no mem\n"); + return; + } + + /* ethernet_input always returns ERR_OK */ + err = ethernet_input(p, netif); + if (err) + log_err("ip4_input err %d\n", err); +} + +static int ethernetif_input(struct pbuf *p, struct netif *netif) +{ + struct ethernetif *ethernetif; + + ethernetif = netif->state; + + /* move received packet into a new pbuf */ + p = low_level_input(); + + /* if no packet could be read, silently ignore this */ + if (p) { + /* pass all packets to ethernet_input, which decides what packets it supports */ + if (netif->input(p, netif) != ERR_OK) { + LWIP_DEBUGF(NETIF_DEBUG, ("%s: IP input error\n", __func__)); + pbuf_free(p); + p = NULL; + } + } + + return 0; +} + +static err_t low_level_output(struct netif *netif, struct pbuf *p) +{ + int err; + + /* switch dev to active state */ + eth_init_state_only(); + + err = eth_send(p->payload, p->len); + if (err) { + log_err("eth_send error %d\n", err); + return ERR_ABRT; + } + return ERR_OK; +} + +err_t ulwip_if_init(struct netif *netif) +{ + ulwip_if_t *uif; + struct ulwip *ulwip; + + uif = malloc(sizeof(ulwip_if_t)); + if (!uif) { + log_err("uif: out of memory\n"); + return ERR_MEM; + } + netif->state = uif; + +#if defined(CONFIG_LWIP_LIB_DEBUG) + log_info(" MAC: %02X:%02X:%02X:%02X:%02X:%02X\n", + netif->hwaddr[0], netif->hwaddr[1], netif->hwaddr[2], + netif->hwaddr[3], netif->hwaddr[4], netif->hwaddr[5]); + log_info(" NAME: %s\n", netif->name); +#endif +#if LWIP_IPV4 + netif->output = etharp_output; +#endif +#if LWIP_IPV6 + netif->output_ip6 = ethip6_output; +#endif + + netif->linkoutput = low_level_output; + netif->mtu = 1500; + netif->flags = NETIF_FLAG_BROADCAST | NETIF_FLAG_ETHARP | NETIF_FLAG_LINK_UP; + + ulwip = eth_lwip_priv(eth_get_dev()); + ulwip->init_done = 1; + + return ERR_OK; +} + +int ulwip_init(void) +{ + ip4_addr_t ipaddr, netmask, gw; + struct netif *unetif; + struct ulwip *ulwip; + struct udevice *udev; + int ret; + unsigned char env_enetaddr[ARP_HLEN]; + const struct udevice *dev; + struct uclass *uc; + + ret = eth_init(); + if (ret) { + log_err("eth_init error %d\n", ret); + return ERR_IF; + } + + udev = eth_get_dev(); + if (!udev) { + log_err("no active eth device\n"); + return ERR_IF; + } + + eth_set_current(); + + ulwip = eth_lwip_priv(udev); + if (ulwip->init_done) { + log_info("init already done for %s\n", udev->name); + return CMD_RET_SUCCESS; + } + + uclass_id_foreach_dev(UCLASS_ETH, dev, uc) { + char ipstr[IP4ADDR_STRLEN_MAX]; + char maskstr[IP4ADDR_STRLEN_MAX]; + char gwstr[IP4ADDR_STRLEN_MAX]; + char hwstr[MAC_ADDR_STRLEN]; + + eth_env_get_enetaddr_by_index("eth", dev_seq(dev), env_enetaddr); + log_info("eth%d: %s %pM %s\n", dev_seq(dev), dev->name, env_enetaddr, + udev == dev ? "active" : ""); + + unetif = malloc(sizeof(struct netif)); + if (!unetif) + return ERR_MEM; + memset(unetif, 0, sizeof(struct netif)); + + ip4_addr_set_zero(&gw); + ip4_addr_set_zero(&ipaddr); + ip4_addr_set_zero(&netmask); + + if (dev_seq(dev) == 0) { + snprintf(ipstr, IP4ADDR_STRLEN_MAX, "ipaddr"); + snprintf(maskstr, IP4ADDR_STRLEN_MAX, "netmask"); + snprintf(gwstr, IP4ADDR_STRLEN_MAX, "gw"); + } else { + snprintf(ipstr, IP4ADDR_STRLEN_MAX, "ipaddr%d", dev_seq(dev)); + snprintf(maskstr, IP4ADDR_STRLEN_MAX, "netmask%d", dev_seq(dev)); + snprintf(gwstr, IP4ADDR_STRLEN_MAX, "gw%d", dev_seq(dev)); + } + snprintf(hwstr, MAC_ADDR_STRLEN, "%pM", env_enetaddr); + snprintf(unetif->name, 2, "%d", dev_seq(dev)); + + string_to_enetaddr(hwstr, unetif->hwaddr); + unetif->hwaddr_len = ETHARP_HWADDR_LEN; + + ipaddr_aton(env_get(ipstr), &ipaddr); + ipaddr_aton(env_get(maskstr), &netmask); + + if (IS_ENABLED(CONFIG_LWIP_LIB_DEBUG)) { + log_info("Starting lwIP\n "); + log_info(" netdev: %s\n", dev->name); + log_info(" IP: %s\n", ip4addr_ntoa(&ipaddr)); + log_info(" GW: %s\n", ip4addr_ntoa(&gw)); + log_info(" mask: %s\n", ip4addr_ntoa(&netmask)); + } + +#if LWIP_IPV6 +#define MAC_FROM_48_BIT 1 + netif_create_ip6_linklocal_address(unetif, MAC_FROM_48_BIT); + log_info(" IPv6: %s\n", ip6addr_ntoa(netif_ip6_addr(unetif, 0))); +#endif /* LWIP_IPV6 */ + + if (!netif_add(unetif, &ipaddr, &netmask, &gw, + unetif, ulwip_if_init, ethernetif_input)) { + log_err("err: netif_add failed!\n"); + free(unetif); + return ERR_IF; + } + + netif_set_up(unetif); + netif_set_link_up(unetif); + } + + if (IS_ENABLED(CONFIG_LWIP_LIB_DEBUG)) { + log_info("Initialized LWIP stack\n"); + } + return CMD_RET_SUCCESS; +} + +/* placeholder, not used now */ +void ulwip_destroy(void) +{ +} diff --git a/net/lwip/port/include/arch/cc.h b/net/lwip/port/include/arch/cc.h new file mode 100644 index 0000000000..23fd51c308 --- /dev/null +++ b/net/lwip/port/include/arch/cc.h @@ -0,0 +1,38 @@ +/* SPDX-License-Identifier: GPL-2.0 */ + +/* + * (C) Copyright 2023 Linaro Ltd. + */ + +#ifndef LWIP_ARCH_CC_H +#define LWIP_ARCH_CC_H + +#include +#include +#include +#include + +#define LWIP_ERRNO_INCLUDE + +#define LWIP_ERRNO_STDINCLUDE 1 +#define LWIP_NO_UNISTD_H 1 +#define LWIP_TIMEVAL_PRIVATE 1 + +#define LWIP_RAND() ((u32_t)rand()) + +/* different handling for unit test, normally not needed */ +#ifdef LWIP_NOASSERT_ON_ERROR +#define LWIP_ERROR(message, expression, handler) do { if (!(expression)) { \ + handler; }} while (0) +#endif + +#define LWIP_DONT_PROVIDE_BYTEORDER_FUNCTIONS + +#define LWIP_PLATFORM_ASSERT(x) do {printf("Assertion \"%s\" failed at line %d in %s\n", \ + x, __LINE__, __FILE__); } while (0) + +#define atoi(str) (int)dectoul(str, NULL) + +#define LWIP_ERR_T int + +#endif /* LWIP_ARCH_CC_H */ diff --git a/net/lwip/port/include/arch/sys_arch.h b/net/lwip/port/include/arch/sys_arch.h new file mode 100644 index 0000000000..87a3fb66d1 --- /dev/null +++ b/net/lwip/port/include/arch/sys_arch.h @@ -0,0 +1,10 @@ +/* SPDX-License-Identifier: GPL-2.0 */ + +/* + * (C) Copyright 2023 Linaro Ltd. + */ + +#ifndef LWIP_ARCH_SYS_ARCH_H +#define LWIP_ARCH_SYS_ARCH_H + +#endif /* LWIP_ARCH_SYS_ARCH_H */ diff --git a/net/lwip/port/include/limits.h b/net/lwip/port/include/limits.h new file mode 100644 index 0000000000..e69de29bb2 diff --git a/net/lwip/port/sys-arch.c b/net/lwip/port/sys-arch.c new file mode 100644 index 0000000000..68476d16e8 --- /dev/null +++ b/net/lwip/port/sys-arch.c @@ -0,0 +1,13 @@ +// SPDX-License-Identifier: GPL-2.0 + +/* + * (C) Copyright 2023 Linaro Ltd. + */ + +#include +#include "lwip/opt.h" + +u32_t sys_now(void) +{ + return get_timer(0); +} From patchwork Fri Sep 8 13:53:15 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxim Uvarov X-Patchwork-Id: 720823 Delivered-To: patch@linaro.org Received: by 2002:adf:eec5:0:b0:31d:da82:a3b4 with SMTP id a5csp779391wrp; Fri, 8 Sep 2023 06:57:18 -0700 (PDT) X-Google-Smtp-Source: AGHT+IESCj+vZ6BkapT/KIctMMazAKTrYYYHHD/YjdY/Vc8hcpkQbOuwnOFtluBhNLb+dzSEv4M3 X-Received: by 2002:a05:600c:2993:b0:401:aa8f:7570 with SMTP id r19-20020a05600c299300b00401aa8f7570mr2350001wmd.1.1694181438613; Fri, 08 Sep 2023 06:57:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694181438; cv=none; d=google.com; s=arc-20160816; b=xHikijTjVIrSmmheumb7frLiTFTmyUv5EO3Wbfc0qRQL8GZOBf+OE57DcQ9KXcVmR7 5ws4snOjWJRRDqGbusWwL8oT3jq148K1F3THUX68ocsPL4W0vl1RuOO8XHACqQ4eexJI Dslq7a4aiAmirfCYlAyC0Ma0R5kfHczrtZTWuRY+xqWO3RTQTlgZxrmAhqAkySl3w6ns sE2o6yWsMWXwMZvajBGUJEnvwDoFb49gPGqyOf7MXEb1mlniIK1muZlDhYKzxgxFxESZ OyJAei4vedlu1f6MikCzzmMeRS69uI6yeMBy3jmOTlCyAi/9UdDieUHMa9MpL9ma4VLx ImKw== 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=EDvrCmEs4AowbUl/thMcgKJCloHgFxRz4FWB3a/1gSQ=; fh=hYoOR0yg+Fo7S26X8ur5L+RaTmkyxWlAVaBypEC8A0g=; b=M2/VBnTyhAcU68/fds68n1FWz8QFOtn2j4jHy7QZ3S4IT/fvuuWeqbn04Nv9kvwcCG HfmV/cg4N6ze2yJN4iUbhhlrcNmGQBiZPIUEfmjuz5cUzb8IYI+QBgeLS6JH3QeLFJF6 D+u5jGbyyfh61HgvRr6R+TApGpm4WMUpGUnts0pUN2Mg76j4xzCeegaZ41tr7/9QyHfY KKWnObSgEMrm9EZzjcbCQoVNsdikJeDuHedyV7jzhPiRyA71qNMTqIQE/3hFA9DBnEXN xe/cC8XPlEyWRwG79ulrcfd6aQ7U528I3baJEKM1pi8xcluCtzBSSAjQiRk/oudMj99j Gugw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=JBhezNbw; 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 fl16-20020a05600c0b9000b003fe1e3937b8si2324717wmb.40.2023.09.08.06.57.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Sep 2023 06:57:18 -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=JBhezNbw; 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 2628B86A97; Fri, 8 Sep 2023 15:56:01 +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="JBhezNbw"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id B281486A8F; Fri, 8 Sep 2023 15:56:00 +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 8BA0D86A9E for ; Fri, 8 Sep 2023 15:55:57 +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-2bcbfb3705dso34855281fa.1 for ; Fri, 08 Sep 2023 06:55:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1694181356; x=1694786156; darn=lists.denx.de; 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=EDvrCmEs4AowbUl/thMcgKJCloHgFxRz4FWB3a/1gSQ=; b=JBhezNbwc8edQp3q/dG01K5fwSmdwdIEd8roVLwwMGVgnX2p/BpRE8d9/9hbCEzAUa /X5cBKzo0GmA0zVAZLTwv/XFzy8szAjH7xmpQLXSd9tS8KP0E6ZrDhIyngQ0WTIMj1A5 fltL+PHP1lhGDj3iEbQoxxVMmRitgLmRR2NtGW1TVmFqeWerLKQkbM4utuis3+3E0tnF aZSlO+/OidUcXhe2b6g+jGG55PdeM0faPfgionMRaXN24ZHT6tNi4kF69vzVgLSEggqf BUQiAt0PuQ9c01v+bUB9OYIH/bTJjOIZ8IX8BC43rcdXsXiFNEg5obWxdQxW83X7hMFZ BK9A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694181356; x=1694786156; 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=EDvrCmEs4AowbUl/thMcgKJCloHgFxRz4FWB3a/1gSQ=; b=f8h6zjDijCOKIvqVFJd3XpkxuXTDm5zq5jhTs+0UZdtZH5SqbDWyRu1FgYxiQ8t6Ue wrV7gzGaknbGiOI7lJaXTsJ5yn15aOYjLm3Nan8cipfo5msu4FBu0sFYR31SdF+CVFbJ LwrzaLJ5XAlDrk1TeIQVJZUqPMdhAFq9t/gpyJnu/1ENk0UF6AAgXncP/PP5PCs48feU YPBA6JgOoxFDU1jYH7VzACW0y8SqSs8JWYacSq5jpp8YHPbgl8KfzONFC5nm2RlsKLxZ nN9fZ2rIvMZWPlo/KX2z/CUDR+3K6LzeQywBs6BFLtjvUS9IQUp8VHGcJ7+KwVA4DaOS 7wuQ== X-Gm-Message-State: AOJu0Yymr0UO9l/yNn7KjtVZEh2AebKV4+eMsL9NPcXhcJbmvHGk/Y5I 00KQyhYzk+QizLpKs0f2SaQv/8iMZIr/Pm6pz+PFJg== X-Received: by 2002:a05:651c:2044:b0:2bc:dd96:147c with SMTP id t4-20020a05651c204400b002bcdd96147cmr1826408ljo.34.1694181356765; Fri, 08 Sep 2023 06:55:56 -0700 (PDT) Received: from localhost.localdomain ([45.82.14.220]) by smtp.gmail.com with ESMTPSA id u14-20020a2e9f0e000000b002bcbae4c21fsm306907ljk.50.2023.09.08.06.55.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Sep 2023 06:55:56 -0700 (PDT) From: Maxim Uvarov To: u-boot@lists.denx.de Cc: pbrobinson@gmail.com, ilias.apalodimas@linaro.org, joe.hershberger@ni.com, rfried.dev@gmail.com, trini@konsulko.com, goldsimon@gmx.de, Maxim Uvarov Subject: [PATCHv8 10/15] net/lwip: update .gitignore with lwIP Date: Fri, 8 Sep 2023 19:53:15 +0600 Message-Id: <20230908135320.7066-11-maxim.uvarov@linaro.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230908135320.7066-1-maxim.uvarov@linaro.org> References: <20230908135320.7066-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 ignore lwIP library code and reused files from the lwIP. Signed-off-by: Maxim Uvarov --- net/lwip/.gitignore | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 net/lwip/.gitignore diff --git a/net/lwip/.gitignore b/net/lwip/.gitignore new file mode 100644 index 0000000000..7b5dacce90 --- /dev/null +++ b/net/lwip/.gitignore @@ -0,0 +1,8 @@ +lwip-external +apps/ping/ping.c +apps/http/http_client.c +apps/http/http_client.h +apps/tftp/tftp.c +apps/tftp/tftp_client.h +apps/tftp/tftp_common.h +apps/tftp/tftp_example.h From patchwork Fri Sep 8 13:53:16 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxim Uvarov X-Patchwork-Id: 720824 Delivered-To: patch@linaro.org Received: by 2002:adf:eec5:0:b0:31d:da82:a3b4 with SMTP id a5csp779475wrp; Fri, 8 Sep 2023 06:57:30 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFGZykJlqBWWjAkrYBos7Z1ssqQKc28q6mTrTSPuBvM7lkbkqNqTy2nUfh4Vx/mli7PgSXw X-Received: by 2002:adf:f844:0:b0:317:ddd3:1aed with SMTP id d4-20020adff844000000b00317ddd31aedmr1949078wrq.68.1694181449941; Fri, 08 Sep 2023 06:57:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694181449; cv=none; d=google.com; s=arc-20160816; b=ZCfyg8c07GV1ymonNA+CW7xM66GwqI9MhZAXh0FJ9qlRHgKYFjy0qVOKyV9zKYPwSf DeYKYCpSXWLJSYwn/2/OkIc9HQnrcNbr49hxqyQ8EVHx2Hg89B9lDezRBD1Eyadpynyf BLR3s8W4RXk7ZF1tvtF4AfEfqJgz7dR7GfZ21ViNlM4oIV1oyIKORw03f+tmvF/FyldR u3QAExfuGJnHtd5uDBI7Z3EZpD5wW+SjAVfbVpL8E+x6upP78kYkHYq0xFRvkg8uJHcL HgDzqQFvc9XBVm2+T8EYpcubqgeTwq8kKrvVglRMGXg5NYwIR42HCzmzUZe68bcWjPuH H5Mg== 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=4B+NIoCaIipSyRVsbzMYMEmPAAldulFwGSMkMcSpesQ=; fh=hYoOR0yg+Fo7S26X8ur5L+RaTmkyxWlAVaBypEC8A0g=; b=fMIaIGjgdsNhdVbBAb2DcraqDjpMfkqeaF3qzupLCX4Sj4Z+slvUWNA8pKQdviaSPT 0Ha0UgFc1762cwltwWgOW+IKJVcKWtAzGdDRbjN27YGQ47dgxD3b8TfkJsrEfxx4FqqN wWlpVb4Wp9WNO2tga2ErxCpu1CWvNj0eRMMot5mAupI1lGJWStvFtgdTc9KCc5U9ma9j k+MkFMGwz5N6gppLJGxQzl9Ay1nUhuJB1I5OvQKD5+1xBb5fycAwXnuYY45E/OS4eKJI /A8o3eIJyUbXbxLkxDNPfSK2d/79dZLAD9Ed1ksfv8X/+AZlBqAdZmrhMbwDjT73x+OT SJFA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=SQRT7OWZ; 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 x14-20020adff64e000000b0031970ed3ce2si809119wrp.1072.2023.09.08.06.57.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Sep 2023 06:57:29 -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=SQRT7OWZ; 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 7662F86AA4; Fri, 8 Sep 2023 15:56:04 +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="SQRT7OWZ"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 8760586AA2; Fri, 8 Sep 2023 15:56:03 +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-x236.google.com (mail-lj1-x236.google.com [IPv6:2a00:1450:4864:20::236]) (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 C9C1185894 for ; Fri, 8 Sep 2023 15:56:00 +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-x236.google.com with SMTP id 38308e7fff4ca-2bcfdadd149so37202721fa.0 for ; Fri, 08 Sep 2023 06:56:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1694181360; x=1694786160; darn=lists.denx.de; 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=4B+NIoCaIipSyRVsbzMYMEmPAAldulFwGSMkMcSpesQ=; b=SQRT7OWZKS/4WoWQWc1XAw7dVZk1ZFoNmsU5tkZrbjvRX/NcIMCzvS5JvLC9wmxbba QrfJu/JNX8gYG1Jd3fDZYt9w9zvvUvjjtaOWyxqgS1lmLbQ3B68QJ2dzTEfSe+vWcKML n1/4oTRhfXkoc8rPIb7xIV2C+wjFGQ0+Jc66ENHS16ZZIPAuJ2BH7yrwh1YQjqXf2nJF ZZXp0S7AWuZhmfaE0RCGZNanT1ROCTVx843SKcVTWDOpWRaBu1wJ9JLJ1o9F04bsLx09 F05KcRyo0aXTtdELlJ5Z12RStldstiEKV8bmN3eRmDg5Q5LT7TxzOa9Rh+U50krm7XHh Mjgg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694181360; x=1694786160; 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=4B+NIoCaIipSyRVsbzMYMEmPAAldulFwGSMkMcSpesQ=; b=arRJdSPtnGJupmLM3u488K4rkSSk4wq9Bb8ZCjCMrqkAmQ8fvLYzghI5+wB9o+ugcF gKhnBjqZm1J0CW34LQ4LU3Wu8xDiEt5MYGEnTGt5hvm+5UacsFreoaPHvAqzj/W1Etnt Zcld18cmig1QqU6fUq1pV8Pwmc/m18JYfOURgq9xw2BXmspFQ/Eokm8ephdsTxY+0mYl AHIDoo04/sJgdLf36t2t88a5c6Com0g11DMUuejmTedE0ejYTvgyHOvTDxWOEDKbj8BP c4y1a7U8yk6f96TiCs5togrYFP4ETyPDN7VcH5NpDSvTXRUxLJUpBARWZG5OQfEQDsB1 ZHeA== X-Gm-Message-State: AOJu0Yx6K5HsbbQ4Oxe1qRRBQHkQgk8ByjIX0TzFqUgJQG7mi6z1x2Pi TeJdriukR82ulYBjUHHd+5Zqkaw/Lw4KpD2OJ2hn4g== X-Received: by 2002:a2e:9ed7:0:b0:2bd:a85:899e with SMTP id h23-20020a2e9ed7000000b002bd0a85899emr1839823ljk.3.1694181359959; Fri, 08 Sep 2023 06:55:59 -0700 (PDT) Received: from localhost.localdomain ([45.82.14.220]) by smtp.gmail.com with ESMTPSA id u14-20020a2e9f0e000000b002bcbae4c21fsm306907ljk.50.2023.09.08.06.55.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Sep 2023 06:55:59 -0700 (PDT) From: Maxim Uvarov To: u-boot@lists.denx.de Cc: pbrobinson@gmail.com, ilias.apalodimas@linaro.org, joe.hershberger@ni.com, rfried.dev@gmail.com, trini@konsulko.com, goldsimon@gmx.de, Maxim Uvarov Subject: [PATCHv8 11/15] net/lwip: connection between cmd and lwip apps Date: Fri, 8 Sep 2023 19:53:16 +0600 Message-Id: <20230908135320.7066-12-maxim.uvarov@linaro.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230908135320.7066-1-maxim.uvarov@linaro.org> References: <20230908135320.7066-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 Signed-off-by: Maxim Uvarov --- cmd/Makefile | 1 + cmd/net-lwip.c | 286 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 287 insertions(+) create mode 100644 cmd/net-lwip.c diff --git a/cmd/Makefile b/cmd/Makefile index 9bebf321c3..6ab6b16aab 100644 --- a/cmd/Makefile +++ b/cmd/Makefile @@ -128,6 +128,7 @@ endif obj-$(CONFIG_CMD_MUX) += mux.o obj-$(CONFIG_CMD_NAND) += nand.o obj-$(CONFIG_CMD_NET) += net.o +obj-$(CONFIG_CMD_NET) += net-lwip.o obj-$(CONFIG_CMD_NVEDIT_EFI) += nvedit_efi.o obj-$(CONFIG_CMD_ONENAND) += onenand.o obj-$(CONFIG_CMD_OSD) += osd.o diff --git a/cmd/net-lwip.c b/cmd/net-lwip.c new file mode 100644 index 0000000000..82e0fe392d --- /dev/null +++ b/cmd/net-lwip.c @@ -0,0 +1,286 @@ +// SPDX-License-Identifier: GPL-2.0 + +/* + * (C) Copyright 2023 Maxim Uvarov, maxim.uvarov@linaro.org + */ + +#include +#include +#include +#include +#include +#include +#include + +#include "net/lwip.h" +#include "net/ulwip.h" + +static int do_lwip_init(struct cmd_tbl *cmdtp, int flag, int argc, + char *const argv[]) +{ + if (!ulwip_init()) + return CMD_RET_SUCCESS; + return CMD_RET_FAILURE; +} + +static void ulwip_timeout_handler(void) +{ + eth_halt(); + net_set_state(NETLOOP_FAIL); /* we did not get the reply */ + ulwip_loop_set(0); +} + +int ulwip_loop(void) +{ + int ret = CMD_RET_FAILURE; + + ulwip_loop_set(1); + if (!net_loop(LWIP)) + ret = CMD_RET_SUCCESS; + ulwip_loop_set(0); + return ret; +} + +#if defined(CONFIG_CMD_PING) +int do_lwip_ping(struct cmd_tbl *cmdtp, int flag, int argc, + char *const argv[]) +{ + int ret; + + if (argc < 2) + return CMD_RET_USAGE; + + ret = ulwip_init(); + if (ret) { + log_err("ulwip_init err %d\n", ret); + return CMD_RET_FAILURE; + } + + log_info("Using %s device\n", eth_get_name()); + log_info("pinging addr: %s\n", argv[1]); + + if (ulwip_ping(argv[1])) { + printf("ping init fail\n"); + return CMD_RET_FAILURE; + } + + return ulwip_loop(); +} +#endif /* CONFIG_CMD_PING */ + +#if defined(CONFIG_CMD_WGET) +int do_lwip_wget(struct cmd_tbl *cmdtp, int flag, int argc, + char *const argv[]) +{ + char *url; + int ret; + + if (argc < 2) + return CMD_RET_USAGE; + + url = argv[1]; + + ret = ulwip_init(); + if (ret) { + log_err("ulwip_init err %d\n", ret); + return CMD_RET_FAILURE; + } + + ret = ulwip_wget(image_load_addr, url); + if (ret) { + log_err("lwip_wget err %d\n", ret); + return CMD_RET_FAILURE; + } + + + return ulwip_loop(); +} +#endif + +#if defined(CONFIG_CMD_TFTPBOOT) +int do_lwip_tftp(struct cmd_tbl *cmdtp, int flag, int argc, + char *const argv[]) +{ + char *filename; + ulong addr; + char *end; + int ret; + + switch (argc) { + case 1: + filename = env_get("bootfile"); + break; + case 2: + /* + * Only one arg - accept two forms: + * Just load address, or just boot file name. The latter + * form must be written in a format which can not be + * mis-interpreted as a valid number. + */ + addr = hextoul(argv[1], &end); + if (end == (argv[1] + strlen(argv[1]))) { + image_load_addr = addr; + filename = env_get("bootfile"); + } else { + filename = argv[1]; + } + break; + case 3: + image_load_addr = hextoul(argv[1], NULL); + filename = argv[2]; + break; + default: + return CMD_RET_USAGE; + } + + ret = ulwip_init(); + if (ret) { + log_err("ulwip_init err %d\n", ret); + return CMD_RET_FAILURE; + } + + ret = ulwip_tftp(image_load_addr, filename); + if (ret) + return ret; + + return ulwip_loop(); +} +#endif /* CONFIG_CMD_TFTPBOOT */ + +#if defined(CONFIG_CMD_DHCP) +int do_lwip_dhcp(void) +{ + int ret; + char *filename; + + ret = ulwip_init(); + if (ret) { + log_err("ulwip_init err %d\n", ret); + return CMD_RET_FAILURE; + } + + ret = ulwip_dhcp(); + + net_set_timeout_handler(2000UL, ulwip_timeout_handler); + + ulwip_loop(); + if (IS_ENABLED(CONFIG_CMD_TFTPBOOT)) { + filename = env_get("bootfile"); + if (!filename) { + log_notice("no bootfile\n"); + return CMD_RET_SUCCESS; + } + + ret = ulwip_init(); + if (ret) { + log_err("ulwip_init err %d\n", ret); + return CMD_RET_FAILURE; + } + + net_set_timeout_handler(20000UL, ulwip_timeout_handler); + ulwip_tftp(image_load_addr, filename); + + ret = ulwip_loop(); + } + + return ret; +} + +static int _do_lwip_dhcp(struct cmd_tbl *cmdtp, int flag, int argc, + char *const argv[]) +{ + return do_lwip_dhcp(); +} +#endif /* CONFIG_CMD_DHCP */ + +#if defined(CONFIG_CMD_DNS) +int do_lwip_dns(struct cmd_tbl *cmdtp, int flag, int argc, + char *const argv[]) +{ + int ret; + char *name; + char *varname; + + if (argc == 1) + return CMD_RET_USAGE; + + name = argv[1]; + + if (argc == 3) + varname = argv[2]; + else + varname = NULL; + + ret = ulwip_init(); + if (ret) { + log_err("ulwip_init err %d\n", ret); + return CMD_RET_FAILURE; + } + + ret = ulwip_dns(name, varname); + if (ret == 0) + return CMD_RET_SUCCESS; + if (ret != -EINPROGRESS) + return CMD_RET_FAILURE; + + net_set_timeout_handler(1000UL, ulwip_timeout_handler); + + return ulwip_loop(); +} +#endif /* CONFIG_CMD_DNS */ + +static struct cmd_tbl cmds[] = { + U_BOOT_CMD_MKENT(init, 1, 0, do_lwip_init, + "initialize lwip stack", ""), +#if defined(CONFIG_CMD_PING) + U_BOOT_CMD_MKENT(ping, 2, 0, do_lwip_ping, + "send ICMP ECHO_REQUEST to network host", + "pingAddress"), +#endif +#if defined(CONFIG_CMD_WGET) + U_BOOT_CMD_MKENT(wget, 2, 0, do_lwip_wget, "", ""), +#endif +#if defined(CONFIG_CMD_TFTPBOOT) + U_BOOT_CMD_MKENT(tftp, 3, 0, do_lwip_tftp, + "boot image via network using TFTP protocol\n", + "[loadAddress] [[hostIPaddr:]bootfilename]"), +#endif +#if defined(CONFIG_CMD_DHCP) + U_BOOT_CMD_MKENT(dhcp, 1, 0, _do_lwip_dhcp, + "boot image via network using DHCP/TFTP protocol", + ""), +#endif +#if defined(CONFIG_CMD_DNS) + U_BOOT_CMD_MKENT(dns, 3, 0, do_lwip_dns, + "lookup dns name [and store address at variable]", + ""), +#endif +}; + +static int do_ops(struct cmd_tbl *cmdtp, int flag, int argc, + char *const argv[]) +{ + struct cmd_tbl *cp; + + cp = find_cmd_tbl(argv[1], cmds, ARRAY_SIZE(cmds)); + + argc--; + argv++; + + if (cp == NULL || argc > cp->maxargs) + return CMD_RET_USAGE; + if (flag == CMD_FLAG_REPEAT && !cmd_is_repeatable(cp)) + return CMD_RET_SUCCESS; + + return cp->cmd(cmdtp, flag, argc, argv); +} + +U_BOOT_CMD( + lwip, 4, 1, do_ops, + "LWIP sub system", + "init - init LWIP\n" + "ping addr - pingAddress\n" + "wget http://IPadress/url/\n" + "tftp [loadAddress] [[hostIPaddr:]bootfilename]\n" + "dhcp - boot image via network using DHCP/TFTP protocol\n" + ); From patchwork Fri Sep 8 13:53:17 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxim Uvarov X-Patchwork-Id: 720825 Delivered-To: patch@linaro.org Received: by 2002:adf:eec5:0:b0:31d:da82:a3b4 with SMTP id a5csp779548wrp; Fri, 8 Sep 2023 06:57:39 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGROkZvNhtyf8Q2aKBPJDyB4LEyVrXyEGjvT9IQeby/jurpjilpw+nVuPycNH3IiQKQYbbT X-Received: by 2002:a05:600c:3b9a:b0:402:f5c4:2e5a with SMTP id n26-20020a05600c3b9a00b00402f5c42e5amr2173457wms.37.1694181459768; Fri, 08 Sep 2023 06:57:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694181459; cv=none; d=google.com; s=arc-20160816; b=RUjS+zAB47tJGdbRzEaAfEqF17uKWoKq0hOl0MMM0PGuo2jCdR55PzoWdIdu/Yfaeb lRxDz6JMIlIssDwoeI+wjGmFeZMPjFcazduqD4sGl7anqXBLXAbyVmSqqdwr7STErUhT duetHTZI5Pbvl3zvFAOVYzI54S+by94rCeGRsIY/vGBTU3xp/UToXS9Q8xk/HLP/5rvA +QJ23vNPrsYKTjrfyTsAFJEUrv/2WvLkLKCVAggySMjLY8ik+X+fg56YTHBBQukGYY2f vumTGuuwZF5gy/piIAcYN0RF4EJLKg8z7bO4WqV3DXCX32oVw8pa8HWfkq4I2u7Zv1po J1cQ== 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=PIYjLMZK0dZcDLpQ4w8B+bV3JHY4j/+fB+98zxRQ+mI=; fh=hYoOR0yg+Fo7S26X8ur5L+RaTmkyxWlAVaBypEC8A0g=; b=0WsaSXB36X6Apy8JZkP6Rx2b0cONLDuCwAqsIunyalrwVKD7VKUv+EoEcld5EBTMoy KhM2/IOcx0t1erS7JW++Qi1U0PqwyAfMUY+AOVxbKpcvywnsuLyjrkdQgNeFB+lXAGb5 ksrENUczFCEqSvIGj/Fke5aJPkqcM0qE3XcrKj0QabVOlDjuKZ8IGry9uT8ThlH2ItIS 73VYVgMx4Xlbu/T9PpuM6teAV25Nc5oy/GHTKqoNEfsMaTp8NKcjrRvFVO4RJzRTfoV+ gF8EtlcQ+ECv3eBx6+2eUA9OYLsCbKukT00WMNk5FPegSSVXwepj557Mh3xQXgAeG+5R rRRw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=cUhGCEaE; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 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. [85.214.62.61]) by mx.google.com with ESMTPS id e9-20020a5d5949000000b00317634df72csi803818wri.798.2023.09.08.06.57.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Sep 2023 06:57:39 -0700 (PDT) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) client-ip=85.214.62.61; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=cUhGCEaE; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 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 C600286AAF; Fri, 8 Sep 2023 15:56:07 +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="cUhGCEaE"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 60DE686AAE; Fri, 8 Sep 2023 15:56:06 +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 811ED86A8A for ; Fri, 8 Sep 2023 15:56:03 +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-2b703a0453fso35563931fa.3 for ; Fri, 08 Sep 2023 06:56:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1694181362; x=1694786162; darn=lists.denx.de; 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=PIYjLMZK0dZcDLpQ4w8B+bV3JHY4j/+fB+98zxRQ+mI=; b=cUhGCEaEVaQ5t4QSy5zdZF0SMU7fiDuxJ0po6Avm+SCYSyeBpI29ZroCWj8Renb8uB 6LNieRsmUF4eICuhLIFfgPTO08T/ivEsowc9Nnh0MkBZRBe5aSbR8b2izLgJg/DudWF1 4e8jqEsjBBbWMFjjOKWTNo8t65CQOqOQ0E4xRGjZ5r6T3UcApxe1ffTnEBSf5ENf4psu pjNChmwzMW57JABwFvdiEPWCV7VN6peFBUHAkrWZGimS92al+dNpF8GFKKYkm9YeJqUC XAZO/Hk0d2SwaJI1FOHrWwjr+axqeT2bPlZYxP2VWCe6XZsNTDwOdI/Q4P6d8ySYpyhS G3og== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694181362; x=1694786162; 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=PIYjLMZK0dZcDLpQ4w8B+bV3JHY4j/+fB+98zxRQ+mI=; b=X9eQ9gpg3aSejgSYJzanlTgKL0/+25f80Y9zi55KZH12l8rqO6WT+vnSPileRP4HnT oaptHP+hqdRWeAQrBeQOr6b3ow/fOQTXaoSPaLe1xIS6uP3fCTV2eANNMm4W44FKMqGl IHVavmI2FLcr1F3N2clFMvc4bnWwkvd8qVjJe16d9CFOH1AbxERLhSMXI7VizKpW7RWA Dc/DygGR/snBUHskCBMfooDBOzaAKE34ZckhX1Wee0OivpoVjHp++zpYHB7Qt6/l1iQ0 dHCeN0Pt2Y876CPDVdKdrehGGdpxB6Cb8d0NBIH5zvdaP3ZZ4jGNxj/oRCmM56cZJoT4 csrg== X-Gm-Message-State: AOJu0Yyk40eVZY6ZOsD+xkl0nMg9MrYMXs8FCzDhz2JldD3vhbBwVClL Q24q+K3kHbyqSPDTq6fWrJYp+ugb2kfVddx1DR9C4w== X-Received: by 2002:a2e:3204:0:b0:2bc:f2d7:f6ce with SMTP id y4-20020a2e3204000000b002bcf2d7f6cemr1785075ljy.49.1694181362536; Fri, 08 Sep 2023 06:56:02 -0700 (PDT) Received: from localhost.localdomain ([45.82.14.220]) by smtp.gmail.com with ESMTPSA id u14-20020a2e9f0e000000b002bcbae4c21fsm306907ljk.50.2023.09.08.06.56.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Sep 2023 06:56:02 -0700 (PDT) From: Maxim Uvarov To: u-boot@lists.denx.de Cc: pbrobinson@gmail.com, ilias.apalodimas@linaro.org, joe.hershberger@ni.com, rfried.dev@gmail.com, trini@konsulko.com, goldsimon@gmx.de, Maxim Uvarov Subject: [PATCHv8 12/15] net/lwip: replace original net commands with lwip Date: Fri, 8 Sep 2023 19:53:17 +0600 Message-Id: <20230908135320.7066-13-maxim.uvarov@linaro.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230908135320.7066-1-maxim.uvarov@linaro.org> References: <20230908135320.7066-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 | 18 +++++++--- boot/bootmeth_pxe.c | 21 ++++++----- cmd/net.c | 86 +++++---------------------------------------- cmd/pxe.c | 19 +++++----- include/net.h | 8 +++-- include/net/ulwip.h | 64 +++++++++++++++++++++++++++++++++ 6 files changed, 113 insertions(+), 103 deletions(-) create mode 100644 include/net/ulwip.h diff --git a/boot/bootmeth_efi.c b/boot/bootmeth_efi.c index ae936c8daa..52399d627c 100644 --- a/boot/bootmeth_efi.c +++ b/boot/bootmeth_efi.c @@ -20,6 +20,8 @@ #include #include #include +#include +#include #include #include @@ -319,9 +321,7 @@ static int distro_efi_try_bootflow_files(struct udevice *dev, static int distro_efi_read_bootflow_net(struct bootflow *bflow) { - char file_addr[17], fname[256]; - char *tftp_argv[] = {"tftp", file_addr, fname, NULL}; - struct cmd_tbl cmdtp = {}; /* dummy */ + char fname[256]; const char *addr_str, *fdt_addr_str; int ret, arch, size; ulong addr, fdt_addr; @@ -368,7 +368,6 @@ static int distro_efi_read_bootflow_net(struct bootflow *bflow) if (!fdt_addr_str) return log_msg_ret("fdt", -EINVAL); fdt_addr = hextoul(fdt_addr_str, NULL); - sprintf(file_addr, "%lx", fdt_addr); /* We only allow the first prefix with PXE */ ret = distro_efi_get_fdt_name(fname, sizeof(fname), 0); @@ -379,7 +378,16 @@ 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)) { + ret = ulwip_init(); + if (ret) + return log_msg_ret("ulwip_init", ret); + + ret = ulwip_tftp(fdt_addr, fname); + if (ret) + return log_msg_ret("ulwip_tftp", ret); + + ret = ulwip_loop(); + if (!ret) { 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 8d489a11aa..fc6aabaa18 100644 --- a/boot/bootmeth_pxe.c +++ b/boot/bootmeth_pxe.c @@ -21,6 +21,8 @@ #include #include #include +#include +#include #include static int extlinux_pxe_getfile(struct pxe_context *ctx, const char *file_path, @@ -116,18 +118,21 @@ static int extlinux_pxe_read_file(struct udevice *dev, struct bootflow *bflow, const char *file_path, ulong addr, ulong *sizep) { - char *tftp_argv[] = {"tftp", NULL, NULL, NULL}; - struct pxe_context *ctx = dev_get_priv(dev); - char file_addr[17]; ulong size; int ret; - sprintf(file_addr, "%lx", addr); - tftp_argv[1] = file_addr; - tftp_argv[2] = (void *)file_path; + ret = ulwip_init(); + if (ret) + return log_msg_ret("ulwip_init", ret); + + ret = ulwip_tftp(addr, file_path); + if (ret) + return log_msg_ret("ulwip_tftp", ret); + + ret = ulwip_loop(); + if (ret) + return log_msg_ret("ulwip_loop", ret); - if (do_tftpb(ctx->cmdtp, 0, 3, tftp_argv)) - return -ENOENT; ret = pxe_get_file_size(&size); if (ret) return log_msg_ret("tftp", 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..d44df428d2 100644 --- a/cmd/pxe.c +++ b/cmd/pxe.c @@ -8,6 +8,7 @@ #include #include #include +#include #include #include @@ -29,21 +30,19 @@ const char *pxe_default_paths[] = { static int do_get_tftp(struct pxe_context *ctx, const char *file_path, char *file_addr, ulong *sizep) { - char *tftp_argv[] = {"tftp", NULL, NULL, NULL}; + ulong addr; + char *end; int ret; - int num_args; - tftp_argv[1] = file_addr; - tftp_argv[2] = (void *)file_path; + addr = hextoul(file_addr, &end); + if (ctx->use_ipv6) { - tftp_argv[3] = USE_IP6_CMD_PARAM; - num_args = 4; - } else { - num_args = 3; + /* @todo: check and fix me, here */ } - if (do_tftpb(ctx->cmdtp, 0, num_args, tftp_argv)) - return -ENOENT; + ret = ulwip_tftp(addr, file_path); + if (ret) + return log_msg_ret("tftp", ret); ret = pxe_get_file_size(sizep); if (ret) 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/ulwip.h b/include/net/ulwip.h new file mode 100644 index 0000000000..8eac7aa130 --- /dev/null +++ b/include/net/ulwip.h @@ -0,0 +1,64 @@ +/* SPDX-License-Identifier: GPL-2.0 */ + +/** + * ulwip_init() - initialize lwIP network stack + * + * @return 0 if success, !0 if error + */ +int ulwip_init(void); + +/** + * ulwip_enabled() - check if lwIP network stack was initialized + * + * @return 1 lwip initialized, 0 if not yet initialized + */ +int ulwip_enabled(void); + +/** + * ulwip_in_loop() - lwIP controls packet net loop + * + * @return 1 lwIP owns packet loop, 0 lwip does not own packet loop + */ +int ulwip_in_loop(void); + +/** + * ulwip_loop_set() - make loop to be used by lwIP + * + * Function is used to make lwIP control network pool. + * + * @loop: 1. Rx packets go to lwIP 2. Rx packets go to the original stack. + */ +void ulwip_loop_set(int loop); + +/** + * ulwip_exit() - exit from lwIP with a return code + * + * Exit from lwIP application back to the U-Boot with specific error code. + * + * @err: Error code to return + */ +void ulwip_exit(int err); + +/** + * ulwip_poll() - polling function to feed lwIP with ethernet packet + * + * Function takes network packet and passes it to lwIP network stack + */ +void ulwip_poll(void); + +/** + * ulwip_app_get_err() - return error code from lwIP application + * + * @return error code + */ +int ulwip_app_get_err(void); + +/** + * ulwip_loop() - enter to packet polling loop + * + * When lwIP application did it's initialization stage, then it needs to enter + * to packet polling loop to grab rx packets. + * + * Returns: 0 if success, !0 if error + */ +int ulwip_loop(void); From patchwork Fri Sep 8 13:53:18 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxim Uvarov X-Patchwork-Id: 720826 Delivered-To: patch@linaro.org Received: by 2002:adf:eec5:0:b0:31d:da82:a3b4 with SMTP id a5csp779619wrp; Fri, 8 Sep 2023 06:57:50 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEkHF2RGiKvW3tSHDAljPvUDo4T8pakaxfrUIzfSAAXTVbXnD1WMLrclysQMKmvJyPj3qO3 X-Received: by 2002:a1c:4c0d:0:b0:402:ee9e:ed98 with SMTP id z13-20020a1c4c0d000000b00402ee9eed98mr2141982wmf.34.1694181470018; Fri, 08 Sep 2023 06:57:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694181469; cv=none; d=google.com; s=arc-20160816; b=qLAcyuh09dOhc3x8bl8ftFUjZCNUK8LLbjoVhgxcFmhPklAn6Y9bG9oaWoT7urilWd pTN3T1fNmM8WfvFNOErhSFedrGzXYvdAdpyPPYpYf59Py+XMgqhPwGmV4sfXNGHLhiz+ 6OvwZj3sqtuIUiJxxsWwOfn+wp3AwqCkCHdLSMOfZnckJAEPevPrkOt3Et2zYijPztrf e9ledkuQDCjB0/242vx0L8Mtz6KNe0d/9R9P6jvkH+x1wXnY77wQBlW4GzHlAW/vRsMh DfqNYhkqrW/mnxIZSVX2Vk6QkAm+l25Ni2G6kB5lOt016y9Nxvh9nrsy0J5T7DNJKQ/k tuiw== 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=E2ziTbeXz5Mw5Zsh+PXRJwRlKMm+1xFvTuTYPCWU9yo=; fh=hYoOR0yg+Fo7S26X8ur5L+RaTmkyxWlAVaBypEC8A0g=; b=OlWaKx2wd38rwZYh0Yhe8STNYlUubaI5nqs0a5alDSqsfUxdWyR4SdVD0hZtKRGAy/ MHO7Eh+ibrXF7RGQhZAyUbQKuk4X2n5WOkGgPF1TiLfthg7PH9di5agwMlAOMTwGU/lJ lp6tM+s+FOvzRdKcaCRycgA6wKsq/5pCUOlJ6NbCnZYq5Z7z34kLYKOHSxNo2GY7gMF9 acbqoPXr8K7JK4kPlVg1NA0JxdBX/gIaRAKvuFTUn+IH/2CeccZKxVZTn1F3X1J/frR4 XFJZil8MM9ttcdRvKP80eShqjIPRtLHPMj3WDzKhyKaAEyUdEY9Un2Gx2wqdrNyX81IY 7gQQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=VDDxuNek; 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 fm18-20020a05600c0c1200b003fef17e2a1dsi2273689wmb.182.2023.09.08.06.57.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Sep 2023 06:57:49 -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=VDDxuNek; 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 23BA186AA3; Fri, 8 Sep 2023 15:56:10 +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="VDDxuNek"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 1023D86AC0; Fri, 8 Sep 2023 15:56:09 +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-x22d.google.com (mail-lj1-x22d.google.com [IPv6:2a00:1450:4864:20::22d]) (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 F420B86A9E for ; Fri, 8 Sep 2023 15:56:05 +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-x22d.google.com with SMTP id 38308e7fff4ca-2bcfdadd149so37204251fa.0 for ; Fri, 08 Sep 2023 06:56:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1694181365; x=1694786165; darn=lists.denx.de; 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=E2ziTbeXz5Mw5Zsh+PXRJwRlKMm+1xFvTuTYPCWU9yo=; b=VDDxuNekJ4SFUqozqjIGkk3LgA7jyNjZJDq1mfAk6P75e9vgzVUO6Gql7x1ePs1lGQ U+o00RGbZ2b96X0pf3tixxqWpYwe7VQtLOpkzWsnfjpVrKsS9iYb/Sw3G1/2gQVzvuy7 AF7LbPiR6GwWwIbPKREX7I/TAEytM7ntrgpg1rVS3qVqKrLkjcVx/YKUtusjGClHPb+h 35Qotgx7BdKf/KdR3DXwOnabQgBDg0NPh10F+E+IXtRLWxwXSljQj72yNMIYy2c6qg+W Se2BDrXhdQif1kKjkN2q9S8TfTQiXhJ5rqfbexB8WcOyEMJG/IlCo45j3v5UpUZ5HOf9 7ccQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694181365; x=1694786165; 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=E2ziTbeXz5Mw5Zsh+PXRJwRlKMm+1xFvTuTYPCWU9yo=; b=TXzJ6MvP9JDrgs/5gfpiGvPwefLx/U1QadERIViqpfLXzwUEu26OZnAnYIq+i7egNG C/6Kmh4Xf83Zw5Jq1BZNl9uRZ8l/K3/rceMtR3njCOcXUf8cAOmYdGQgFw3bqr+aWd3s AK1Bid0GIaBglSWGBM36hVL8+XAl+nXE6FOZBdnqQH6lLjK0E0DUd3bIEVslP+sbGFB6 Sr5P+uTF0oJLIq40tAAdwCv0OXpvGTxdsnuFN3k1fJA7cyWWcpZkbjxv4QBGJtg4uu6+ wpQ2k71AGzpad194gmey+QiNJUTNLYE8MDZZIPVjgUeG4b2B3HAFYLybBU+Zq87iSvG8 sswA== X-Gm-Message-State: AOJu0YyI3Wc9qWxKLn5Kz80l6oeQzMVeAoQy7s59ilJBZRWu4I3Y5RoC 0ksGHOvqsErQk29qs4aSAYhDPStmQf1uOzHPNcXRhA== X-Received: by 2002:a2e:9204:0:b0:2bc:d8fd:13df with SMTP id k4-20020a2e9204000000b002bcd8fd13dfmr1993877ljg.41.1694181364911; Fri, 08 Sep 2023 06:56:04 -0700 (PDT) Received: from localhost.localdomain ([45.82.14.220]) by smtp.gmail.com with ESMTPSA id u14-20020a2e9f0e000000b002bcbae4c21fsm306907ljk.50.2023.09.08.06.56.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Sep 2023 06:56:04 -0700 (PDT) From: Maxim Uvarov To: u-boot@lists.denx.de Cc: pbrobinson@gmail.com, ilias.apalodimas@linaro.org, joe.hershberger@ni.com, rfried.dev@gmail.com, trini@konsulko.com, goldsimon@gmx.de, Maxim Uvarov Subject: [PATCHv8 13/15] net/lwip: split net.h to net.h, arp.h and eth.h Date: Fri, 8 Sep 2023 19:53:18 +0600 Message-Id: <20230908135320.7066-14-maxim.uvarov@linaro.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230908135320.7066-1-maxim.uvarov@linaro.org> References: <20230908135320.7066-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 current net.h has ethernet and protocol definitions. Protocol definitions overlap with lwIP protocol definitions and net.h can not be included from lwIP code. Splitting on logical blocks makes that work. Signed-off-by: Maxim Uvarov --- include/net.h | 189 +-------------------------------------------- include/net/arp.h | 7 ++ include/net/eth.h | 190 ++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 201 insertions(+), 185 deletions(-) create mode 100644 include/net/arp.h create mode 100644 include/net/eth.h diff --git a/include/net.h b/include/net.h index de7baeb121..780c51fab9 100644 --- a/include/net.h +++ b/include/net.h @@ -20,6 +20,7 @@ #include #include #include +#include struct bd_info; struct cmd_tbl; @@ -30,25 +31,6 @@ struct udevice; #define DEBUG_NET_PKT 0 /* Packets on info on the network at large */ #define DEBUG_INT_STATE 0 /* Internal network state changes */ -/* - * The number of receive packet buffers, and the required packet buffer - * alignment in memory. - * - */ -#define PKTBUFSRX CONFIG_SYS_RX_ETH_BUFFER -#define PKTALIGN ARCH_DMA_MINALIGN - -/* Number of packets processed together */ -#define ETH_PACKETS_BATCH_RECV 32 - -/* ARP hardware address length */ -#define ARP_HLEN 6 -/* - * The size of a MAC address in string form, each digit requires two chars - * and five separator characters to form '00:00:00:00:00:00'. - */ -#define ARP_HLEN_ASCII (ARP_HLEN * 2) + (ARP_HLEN - 1) - /* IPv4 addresses are always 32 bits in size */ struct in_addr { __be32 s_addr; @@ -112,150 +94,7 @@ typedef void rxhand_icmp_f(unsigned type, unsigned code, unsigned dport, */ typedef void thand_f(void); -enum eth_state_t { - ETH_STATE_INIT, - ETH_STATE_PASSIVE, - ETH_STATE_ACTIVE -}; - -/** - * struct eth_pdata - Platform data for Ethernet MAC controllers - * - * @iobase: The base address of the hardware registers - * @enetaddr: The Ethernet MAC address that is loaded from EEPROM or env - * @phy_interface: PHY interface to use - see PHY_INTERFACE_MODE_... - * @max_speed: Maximum speed of Ethernet connection supported by MAC - * @priv_pdata: device specific plat - */ -struct eth_pdata { - phys_addr_t iobase; - unsigned char enetaddr[ARP_HLEN]; - int phy_interface; - int max_speed; - void *priv_pdata; -}; - -enum eth_recv_flags { - /* - * Check hardware device for new packets (otherwise only return those - * which are already in the memory buffer ready to process) - */ - ETH_RECV_CHECK_DEVICE = 1 << 0, -}; - -/** - * struct eth_ops - functions of Ethernet MAC controllers - * - * start: Prepare the hardware to send and receive packets - * send: Send the bytes passed in "packet" as a packet on the wire - * recv: Check if the hardware received a packet. If so, set the pointer to the - * packet buffer in the packetp parameter. If not, return an error or 0 to - * indicate that the hardware receive FIFO is empty. If 0 is returned, the - * network stack will not process the empty packet, but free_pkt() will be - * called if supplied - * free_pkt: Give the driver an opportunity to manage its packet buffer memory - * when the network stack is finished processing it. This will only be - * called when no error was returned from recv - optional - * stop: Stop the hardware from looking for packets - may be called even if - * state == PASSIVE - * mcast: Join or leave a multicast group (for TFTP) - optional - * write_hwaddr: Write a MAC address to the hardware (used to pass it to Linux - * on some platforms like ARM). This function expects the - * eth_pdata::enetaddr field to be populated. The method can - * return -ENOSYS to indicate that this is not implemented for - this hardware - optional. - * read_rom_hwaddr: Some devices have a backup of the MAC address stored in a - * ROM on the board. This is how the driver should expose it - * to the network stack. This function should fill in the - * eth_pdata::enetaddr field - optional - * set_promisc: Enable or Disable promiscuous mode - * get_sset_count: Number of statistics counters - * get_string: Names of the statistic counters - * get_stats: The values of the statistic counters - */ -struct eth_ops { - int (*start)(struct udevice *dev); - int (*send)(struct udevice *dev, void *packet, int length); - int (*recv)(struct udevice *dev, int flags, uchar **packetp); - int (*free_pkt)(struct udevice *dev, uchar *packet, int length); - void (*stop)(struct udevice *dev); - int (*mcast)(struct udevice *dev, const u8 *enetaddr, int join); - int (*write_hwaddr)(struct udevice *dev); - int (*read_rom_hwaddr)(struct udevice *dev); - int (*set_promisc)(struct udevice *dev, bool enable); - int (*get_sset_count)(struct udevice *dev); - void (*get_strings)(struct udevice *dev, u8 *data); - void (*get_stats)(struct udevice *dev, u64 *data); -}; - -#define eth_get_ops(dev) ((struct eth_ops *)(dev)->driver->ops) - -struct udevice *eth_get_dev(void); /* get the current device */ -/* - * The devname can be either an exact name given by the driver or device tree - * or it can be an alias of the form "eth%d" - */ -struct udevice *eth_get_dev_by_name(const char *devname); -unsigned char *eth_get_ethaddr(void); /* get the current device MAC */ - -/* Used only when NetConsole is enabled */ -int eth_is_active(struct udevice *dev); /* Test device for active state */ -int eth_init_state_only(void); /* Set active state */ -void eth_halt_state_only(void); /* Set passive state */ - -int eth_initialize(void); /* Initialize network subsystem */ -void eth_try_another(int first_restart); /* Change the device */ -void eth_set_current(void); /* set nterface to ethcur var */ - -int eth_get_dev_index(void); /* get the device index */ - -/** - * eth_env_set_enetaddr_by_index() - set the MAC address environment variable - * - * This sets up an environment variable with the given MAC address (@enetaddr). - * The environment variable to be set is defined by <@base_name><@index>addr. - * If @index is 0 it is omitted. For common Ethernet this means ethaddr, - * eth1addr, etc. - * - * @base_name: Base name for variable, typically "eth" - * @index: Index of interface being updated (>=0) - * @enetaddr: Pointer to MAC address to put into the variable - * Return: 0 if OK, other value on error - */ -int eth_env_set_enetaddr_by_index(const char *base_name, int index, - uchar *enetaddr); - - -/* - * Initialize USB ethernet device with CONFIG_DM_ETH - * Returns: - * 0 is success, non-zero is error status. - */ -int usb_ether_init(void); - -/* - * Get the hardware address for an ethernet interface . - * Args: - * base_name - base name for device (normally "eth") - * index - device index number (0 for first) - * enetaddr - returns 6 byte hardware address - * Returns: - * Return true if the address is valid. - */ -int eth_env_get_enetaddr_by_index(const char *base_name, int index, - uchar *enetaddr); - -int eth_init(void); /* Initialize the device */ -int eth_send(void *packet, int length); /* Send a packet */ - -#if defined(CONFIG_API) || defined(CONFIG_EFI_LOADER) -int eth_receive(void *packet, int length); /* Receive a packet*/ -extern void (*push_packet)(void *packet, int length); -#endif -int eth_rx(void); /* Check for received packets */ -void eth_halt(void); /* stop SCC */ -const char *eth_get_name(void); /* get name of current device */ -int eth_mcast_join(struct in_addr mcast_addr, int join); +#include /**********************************************************************/ /* @@ -495,16 +334,6 @@ extern char net_root_path[CONFIG_BOOTP_MAX_ROOT_PATH_LEN]; /* Our root path */ /* Indicates whether the pxe path prefix / config file was specified in dhcp option */ extern char *pxelinux_configfile; /** END OF BOOTP EXTENTIONS **/ -extern u8 net_ethaddr[ARP_HLEN]; /* Our ethernet address */ -extern u8 net_server_ethaddr[ARP_HLEN]; /* Boot server enet address */ -extern struct in_addr net_ip; /* Our IP addr (0 = unknown) */ -extern struct in_addr net_server_ip; /* Server IP addr (0 = unknown) */ -extern uchar *net_tx_packet; /* THE transmit packet */ -extern uchar *net_rx_packets[PKTBUFSRX]; /* Receive packets */ -extern uchar *net_rx_packet; /* Current receive packet */ -extern int net_rx_packet_len; /* Current rx packet length */ -extern const u8 net_bcast_ethaddr[ARP_HLEN]; /* Ethernet broadcast address */ -extern const u8 net_null_ethaddr[ARP_HLEN]; #define VLAN_NONE 4095 /* untagged */ #define VLAN_IDMASK 0x0fff /* mask of valid vlan id */ @@ -557,6 +386,8 @@ extern struct in_addr net_ntp_server; /* the ip address to NTP */ extern int net_ntp_time_offset; /* offset time from UTC */ #endif +int eth_mcast_join(struct in_addr mcast_addr, int join); + /* Initialize the network adapter */ int net_init(void); int net_loop(enum proto_t); @@ -827,18 +658,6 @@ static inline void net_random_ethaddr(uchar *addr) addr[0] |= 0x02; /* set local assignment bit (IEEE802) */ } -/** - * string_to_enetaddr() - Parse a MAC address - * - * Convert a string MAC address - * - * Implemented in lib/net_utils.c (built unconditionally) - * - * @addr: MAC address in aa:bb:cc:dd:ee:ff format, where each part is a 2-digit - * hex value - * @enetaddr: Place to put MAC address (6 bytes) - */ -void string_to_enetaddr(const char *addr, uint8_t *enetaddr); /* Convert an IP address to a string */ void ip_to_string(struct in_addr x, char *s); diff --git a/include/net/arp.h b/include/net/arp.h new file mode 100644 index 0000000000..f614f0ef78 --- /dev/null +++ b/include/net/arp.h @@ -0,0 +1,7 @@ +/* ARP hardware address length */ +#define ARP_HLEN 6 +/* + * The size of a MAC address in string form, each digit requires two chars + * and five separator characters to form '00:00:00:00:00:00'. + */ +#define ARP_HLEN_ASCII (ARP_HLEN * 2) + (ARP_HLEN - 1) diff --git a/include/net/eth.h b/include/net/eth.h new file mode 100644 index 0000000000..17552bca81 --- /dev/null +++ b/include/net/eth.h @@ -0,0 +1,190 @@ +#include + +struct udevice; + +enum eth_state_t { + ETH_STATE_INIT, + ETH_STATE_PASSIVE, + ETH_STATE_ACTIVE +}; + +/** + * struct eth_pdata - Platform data for Ethernet MAC controllers + * + * @iobase: The base address of the hardware registers + * @enetaddr: The Ethernet MAC address that is loaded from EEPROM or env + * @phy_interface: PHY interface to use - see PHY_INTERFACE_MODE_... + * @max_speed: Maximum speed of Ethernet connection supported by MAC + * @priv_pdata: device specific plat + */ +struct eth_pdata { + phys_addr_t iobase; + unsigned char enetaddr[ARP_HLEN]; + int phy_interface; + int max_speed; + void *priv_pdata; +}; + +enum eth_recv_flags { + /* + * Check hardware device for new packets (otherwise only return those + * which are already in the memory buffer ready to process) + */ + ETH_RECV_CHECK_DEVICE = 1 << 0, +}; + +/** + * struct eth_ops - functions of Ethernet MAC controllers + * + * start: Prepare the hardware to send and receive packets + * send: Send the bytes passed in "packet" as a packet on the wire + * recv: Check if the hardware received a packet. If so, set the pointer to the + * packet buffer in the packetp parameter. If not, return an error or 0 to + * indicate that the hardware receive FIFO is empty. If 0 is returned, the + * network stack will not process the empty packet, but free_pkt() will be + * called if supplied + * free_pkt: Give the driver an opportunity to manage its packet buffer memory + * when the network stack is finished processing it. This will only be + * called when no error was returned from recv - optional + * stop: Stop the hardware from looking for packets - may be called even if + * state == PASSIVE + * mcast: Join or leave a multicast group (for TFTP) - optional + * write_hwaddr: Write a MAC address to the hardware (used to pass it to Linux + * on some platforms like ARM). This function expects the + * eth_pdata::enetaddr field to be populated. The method can + * return -ENOSYS to indicate that this is not implemented for + this hardware - optional. + * read_rom_hwaddr: Some devices have a backup of the MAC address stored in a + * ROM on the board. This is how the driver should expose it + * to the network stack. This function should fill in the + * eth_pdata::enetaddr field - optional + * set_promisc: Enable or Disable promiscuous mode + * get_sset_count: Number of statistics counters + * get_string: Names of the statistic counters + * get_stats: The values of the statistic counters + */ +struct eth_ops { + int (*start)(struct udevice *dev); + int (*send)(struct udevice *dev, void *packet, int length); + int (*recv)(struct udevice *dev, int flags, uchar **packetp); + int (*free_pkt)(struct udevice *dev, uchar *packet, int length); + void (*stop)(struct udevice *dev); + int (*mcast)(struct udevice *dev, const u8 *enetaddr, int join); + int (*write_hwaddr)(struct udevice *dev); + int (*read_rom_hwaddr)(struct udevice *dev); + int (*set_promisc)(struct udevice *dev, bool enable); + int (*get_sset_count)(struct udevice *dev); + void (*get_strings)(struct udevice *dev, u8 *data); + void (*get_stats)(struct udevice *dev, u64 *data); +}; + +#define eth_get_ops(dev) ((struct eth_ops *)(dev)->driver->ops) + +struct udevice *eth_get_dev(void); /* get the current device */ +/* + * The devname can be either an exact name given by the driver or device tree + * or it can be an alias of the form "eth%d" + */ +struct udevice *eth_get_dev_by_name(const char *devname); +unsigned char *eth_get_ethaddr(void); /* get the current device MAC */ + +/* Used only when NetConsole is enabled */ +int eth_is_active(struct udevice *dev); /* Test device for active state */ +int eth_init_state_only(void); /* Set active state */ +void eth_halt_state_only(void); /* Set passive state */ + +int eth_initialize(void); /* Initialize network subsystem */ +void eth_try_another(int first_restart); /* Change the device */ +void eth_set_current(void); /* set nterface to ethcur var */ + +int eth_get_dev_index(void); /* get the device index */ + +/** + * eth_env_set_enetaddr_by_index() - set the MAC address environment variable + * + * This sets up an environment variable with the given MAC address (@enetaddr). + * The environment variable to be set is defined by <@base_name><@index>addr. + * If @index is 0 it is omitted. For common Ethernet this means ethaddr, + * eth1addr, etc. + * + * @base_name: Base name for variable, typically "eth" + * @index: Index of interface being updated (>=0) + * @enetaddr: Pointer to MAC address to put into the variable + * Return: 0 if OK, other value on error + */ +int eth_env_set_enetaddr_by_index(const char *base_name, int index, + uchar *enetaddr); + + +/* + * Initialize USB ethernet device with CONFIG_DM_ETH + * Returns: + * 0 is success, non-zero is error status. + */ +int usb_ether_init(void); + +/* + * Get the hardware address for an ethernet interface . + * Args: + * base_name - base name for device (normally "eth") + * index - device index number (0 for first) + * enetaddr - returns 6 byte hardware address + * Returns: + * Return true if the address is valid. + */ +int eth_env_get_enetaddr_by_index(const char *base_name, int index, + uchar *enetaddr); + +int eth_init(void); /* Initialize the device */ +int eth_send(void *packet, int length); /* Send a packet */ + +#if defined(CONFIG_API) || defined(CONFIG_EFI_LOADER) +int eth_receive(void *packet, int length); /* Receive a packet*/ +extern void (*push_packet)(void *packet, int length); +#endif +int eth_rx(void); /* Check for received packets */ +void eth_halt(void); /* stop SCC */ +const char *eth_get_name(void); /* get name of current device */ + +/* + * The number of receive packet buffers, and the required packet buffer + * alignment in memory. + * + */ +#define PKTBUFSRX CONFIG_SYS_RX_ETH_BUFFER +#define PKTALIGN ARCH_DMA_MINALIGN + +/* Number of packets processed together */ +#define ETH_PACKETS_BATCH_RECV 32 + +extern u8 net_ethaddr[ARP_HLEN]; /* Our ethernet address */ +extern u8 net_server_ethaddr[ARP_HLEN]; /* Boot server enet address */ +extern struct in_addr net_ip; /* Our IP addr (0 = unknown) */ +extern struct in_addr net_server_ip; /* Server IP addr (0 = unknown) */ +extern uchar *net_tx_packet; /* THE transmit packet */ +extern uchar *net_rx_packets[PKTBUFSRX]; /* Receive packets */ +extern uchar *net_rx_packet; /* Current receive packet */ +extern int net_rx_packet_len; /* Current rx packet length */ +extern const u8 net_bcast_ethaddr[ARP_HLEN]; /* Ethernet broadcast address */ +extern const u8 net_null_ethaddr[ARP_HLEN]; + +/** + * string_to_enetaddr() - Parse a MAC address + * + * Convert a string MAC address + * + * Implemented in lib/net_utils.c (built unconditionally) + * + * @addr: MAC address in aa:bb:cc:dd:ee:ff format, where each part is a 2-digit + * hex value + * @enetaddr: Place to put MAC address (6 bytes) + */ +void string_to_enetaddr(const char *addr, uint8_t *enetaddr); + +typedef struct ulwip { + bool loop; + int err; + bool init_done; +} ulwip; + +struct ulwip *eth_lwip_priv(struct udevice *current); From patchwork Fri Sep 8 13:53:19 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxim Uvarov X-Patchwork-Id: 720827 Delivered-To: patch@linaro.org Received: by 2002:adf:eec5:0:b0:31d:da82:a3b4 with SMTP id a5csp779672wrp; Fri, 8 Sep 2023 06:58:00 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEsWUe71q0YQZnwjnNY/DFdhIwoqm9/zSK4qx9P08hkcS0TwQMxQDyPnDbhudd+rLhR4DG2 X-Received: by 2002:a05:6000:180b:b0:31a:d450:c513 with SMTP id m11-20020a056000180b00b0031ad450c513mr2210602wrh.26.1694181480290; Fri, 08 Sep 2023 06:58:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694181480; cv=none; d=google.com; s=arc-20160816; b=XOHL0p6aduhEidv33Fnr3uqfnHLLErTdrqr4R8aqzA6T3C4givR7Jec1EW8psGHMmT Dbb6AnTahd+DXPSTqLhoHiNPyDrMjYLlJ+71NIREcA2WfRlGVcDcfSqJTkLkysw93wpu uhA6KEmuaiK9h+IcxC3Zh/RjPMOM1TO3sDIq738zV9clnBbh39NEnfx4NOcpmdQgPi4M kHik2pyVYUQoKfVKPnABpNvK+NJ10IeE1MoOMXAhYGRJ4Kq3IDAC5gt7Lw0k2c4K6IKF cI2HY6NIszhloKt8vqTffzrEtRBNIFYtsobCm4hQVcR+gd77S6EU2ndXXcFWb9JFPTpo rujg== 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=Enmy0689N7W2ZgwZJNW/re8YJQVeDPBPlmUCaBkcQNw=; fh=hYoOR0yg+Fo7S26X8ur5L+RaTmkyxWlAVaBypEC8A0g=; b=t+D/exHsHxrIz4osUwfO4lxKACpXVXnPwqSx8Zw+dhZxY0j66/ofRmfJHx4qyAylaT DBe1svNrjrfGeD8eGJQa9Y4hpDPiWi5XdgW0dlF7UxZinankWkS88eTCp74/WFuXLere Pe9YQgR8T1zLF+g9TSDcgT43FigtaB+41kOQqC/acOcCokyoGxd4kFYnfQCoutohve3E IQL1+eTVggvqxc+GLhfz0tkQceTtHecSV4eOpQou9KxKBf13jt2RzyewBEEKriYHjuUx yEvYwYksJUS1vIR06ROOIFC3li7w6JeY18dBhHidQmqfMBNY+c7bD/XTq48+gYY5Bq5l Ediw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=xWYD3nqt; 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 j26-20020a5d453a000000b00319779a7e37si821176wra.680.2023.09.08.06.57.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Sep 2023 06:58:00 -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=xWYD3nqt; 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 741FC86A9F; Fri, 8 Sep 2023 15:56:13 +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="xWYD3nqt"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id EA67E86AB9; Fri, 8 Sep 2023 15:56:11 +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-x22c.google.com (mail-lj1-x22c.google.com [IPv6:2a00:1450:4864:20::22c]) (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 DD3B986ABD for ; Fri, 8 Sep 2023 15:56:08 +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-x22c.google.com with SMTP id 38308e7fff4ca-2bcfd3220d3so34951051fa.2 for ; Fri, 08 Sep 2023 06:56:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1694181368; x=1694786168; darn=lists.denx.de; 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=Enmy0689N7W2ZgwZJNW/re8YJQVeDPBPlmUCaBkcQNw=; b=xWYD3nqtt1P++90PyBQVDS4uOO+LyF7kSsi+ej2/ROWwxgCjayOOF+yocgWk5Sib7v vaYN3YpWPVwXtuAq4PDjyej4ZKX8kfB1tzniSai3zxwjdJ8trU6b1LMjo26thGxXu1Rf aSY4yOJhZNRMERkeaGmtQn/SLPN/hmYexUCdQspx4yNjeZicHs77Aqhbe0BhRdJ90IKP mfnDFOKwkAprsIGFWjZ6SK3GxO0trXV04kFGaTU4mEVCqVu5imjtIXwGnlRQOqdH+k0S TtrcsYQqOysXmCdU9EwqXOc7gfBF7ela6dv2oHu8BMHQTKrQyvvNiN8y+Z/qdavCQYs8 me0w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694181368; x=1694786168; 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=Enmy0689N7W2ZgwZJNW/re8YJQVeDPBPlmUCaBkcQNw=; b=Qnq2pGnXz+2Mbc6o4beR4XpwHc9tPLgaLAXmuWng6M3VZlWE2jtEi4YG5dmdFTNkhU 7HpGShmMetYxCpSG3BTlnFfqDXeacl/LpY6m2/B9BR/ms5otBUAULskJNfOV9WAp3zv0 N5XgP46MvCSjZ2Wq29YLfdZnagDa9tmGAx7jH2XQM9K/MRj7/gvvsxgQ6bywyR31yq5g p5J4VsqDCdFqlr3QQZXXOzAO97D+8FPJP5g0ymfbpJ12JQ/z+XK3brXHuvmhkajTeirt /J9VbAJmfD8LOMW9kTAkKVsdRah+xHOvcywxXfdF12M0i0o6QXVUUoMosJx6dhUrZKSZ TRpA== X-Gm-Message-State: AOJu0YyTDV+pDGWTXifKgwTwca2xTzm8ANC36Aorikds7qyt2Z1fh7uP CBAF2WNMGt35QFQ0Co96EmwaUL8I6nHdXXQCNL+Tuw== X-Received: by 2002:a2e:804b:0:b0:2bc:f523:c88a with SMTP id p11-20020a2e804b000000b002bcf523c88amr2023832ljg.1.1694181367891; Fri, 08 Sep 2023 06:56:07 -0700 (PDT) Received: from localhost.localdomain ([45.82.14.220]) by smtp.gmail.com with ESMTPSA id u14-20020a2e9f0e000000b002bcbae4c21fsm306907ljk.50.2023.09.08.06.56.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Sep 2023 06:56:07 -0700 (PDT) From: Maxim Uvarov To: u-boot@lists.denx.de Cc: pbrobinson@gmail.com, ilias.apalodimas@linaro.org, joe.hershberger@ni.com, rfried.dev@gmail.com, trini@konsulko.com, goldsimon@gmx.de, Maxim Uvarov Subject: [PATCHv8 14/15] net/lwip: drop old net/wget Date: Fri, 8 Sep 2023 19:53:19 +0600 Message-Id: <20230908135320.7066-15-maxim.uvarov@linaro.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230908135320.7066-1-maxim.uvarov@linaro.org> References: <20230908135320.7066-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 After which to lwip variants of working apps we need to drop old code with all dependencies. This commit drop old wget command files. Signed-off-by: Maxim Uvarov --- include/net/wget.h | 22 --- net/Makefile | 1 - net/net.c | 6 - net/wget.c | 440 --------------------------------------------- 4 files changed, 469 deletions(-) delete mode 100644 include/net/wget.h delete mode 100644 net/wget.c diff --git a/include/net/wget.h b/include/net/wget.h deleted file mode 100644 index da0920de11..0000000000 --- a/include/net/wget.h +++ /dev/null @@ -1,22 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -/* - * Duncan Hare Copyright 2017 - */ - -/** - * wget_start() - begin wget - */ -void wget_start(void); - -enum wget_state { - WGET_CLOSED, - WGET_CONNECTING, - WGET_CONNECTED, - WGET_TRANSFERRING, - WGET_TRANSFERRED -}; - -#define DEBUG_WGET 0 /* Set to 1 for debug messages */ -#define SERVER_PORT 80 -#define WGET_RETRY_COUNT 30 -#define WGET_TIMEOUT 2000UL diff --git a/net/Makefile b/net/Makefile index 61930c244e..eda21f988a 100644 --- a/net/Makefile +++ b/net/Makefile @@ -32,7 +32,6 @@ obj-$(CONFIG_TCP_FUNCTION_FASTBOOT) += fastboot_tcp.o obj-$(CONFIG_CMD_WOL) += wol.o obj-$(CONFIG_PROT_UDP) += udp.o obj-$(CONFIG_PROT_TCP) += tcp.o -obj-$(CONFIG_CMD_WGET) += wget.o obj-$(CONFIG_LWIP) += lwip/ # Disable this warning as it is triggered by: diff --git a/net/net.c b/net/net.c index d9e566081c..677eda26bc 100644 --- a/net/net.c +++ b/net/net.c @@ -109,7 +109,6 @@ #include #include #include -#include #include "arp.h" #include "bootp.h" #include "cdp.h" @@ -564,11 +563,6 @@ restart: nfs_start(); break; #endif -#if defined(CONFIG_CMD_WGET) - case WGET: - wget_start(); - break; -#endif #if defined(CONFIG_CMD_CDP) case CDP: cdp_start(); diff --git a/net/wget.c b/net/wget.c deleted file mode 100644 index 2dbfeb1a1d..0000000000 --- a/net/wget.c +++ /dev/null @@ -1,440 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0 -/* - * WGET/HTTP support driver based on U-BOOT's nfs.c - * Copyright Duncan Hare 2017 - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -static const char bootfile1[] = "GET "; -static const char bootfile3[] = " HTTP/1.0\r\n\r\n"; -static const char http_eom[] = "\r\n\r\n"; -static const char http_ok[] = "200"; -static const char content_len[] = "Content-Length"; -static const char linefeed[] = "\r\n"; -static struct in_addr web_server_ip; -static int our_port; -static int wget_timeout_count; - -struct pkt_qd { - uchar *pkt; - unsigned int tcp_seq_num; - unsigned int len; -}; - -/* - * This is a control structure for out of order packets received. - * The actual packet bufers are in the kernel space, and are - * expected to be overwritten by the downloaded image. - */ -static struct pkt_qd pkt_q[PKTBUFSRX / 4]; -static int pkt_q_idx; -static unsigned long content_length; -static unsigned int packets; - -static unsigned int initial_data_seq_num; - -static enum wget_state current_wget_state; - -static char *image_url; -static unsigned int wget_timeout = WGET_TIMEOUT; - -static enum net_loop_state wget_loop_state; - -/* Timeout retry parameters */ -static u8 retry_action; /* actions for TCP retry */ -static unsigned int retry_tcp_ack_num; /* TCP retry acknowledge number*/ -static unsigned int retry_tcp_seq_num; /* TCP retry sequence number */ -static int retry_len; /* TCP retry length */ - -/** - * store_block() - store block in memory - * @src: source of data - * @offset: offset - * @len: length - */ -static inline int store_block(uchar *src, unsigned int offset, unsigned int len) -{ - ulong newsize = offset + len; - uchar *ptr; - - ptr = map_sysmem(image_load_addr + offset, len); - memcpy(ptr, src, len); - unmap_sysmem(ptr); - - if (net_boot_file_size < (offset + len)) - net_boot_file_size = newsize; - - return 0; -} - -/** - * wget_send_stored() - wget response dispatcher - * - * WARNING, This, and only this, is the place in wget.c where - * SEQUENCE NUMBERS are swapped between incoming (RX) - * and outgoing (TX). - * Procedure wget_handler() is correct for RX traffic. - */ -static void wget_send_stored(void) -{ - u8 action = retry_action; - int len = retry_len; - unsigned int tcp_ack_num = retry_tcp_seq_num + (len == 0 ? 1 : len); - unsigned int tcp_seq_num = retry_tcp_ack_num; - uchar *ptr, *offset; - - switch (current_wget_state) { - case WGET_CLOSED: - debug_cond(DEBUG_WGET, "wget: send SYN\n"); - current_wget_state = WGET_CONNECTING; - net_send_tcp_packet(0, SERVER_PORT, our_port, action, - tcp_seq_num, tcp_ack_num); - packets = 0; - break; - case WGET_CONNECTING: - pkt_q_idx = 0; - net_send_tcp_packet(0, SERVER_PORT, our_port, action, - tcp_seq_num, tcp_ack_num); - - ptr = net_tx_packet + net_eth_hdr_size() + - IP_TCP_HDR_SIZE + TCP_TSOPT_SIZE + 2; - offset = ptr; - - memcpy(offset, &bootfile1, strlen(bootfile1)); - offset += strlen(bootfile1); - - memcpy(offset, image_url, strlen(image_url)); - offset += strlen(image_url); - - memcpy(offset, &bootfile3, strlen(bootfile3)); - offset += strlen(bootfile3); - net_send_tcp_packet((offset - ptr), SERVER_PORT, our_port, - TCP_PUSH, tcp_seq_num, tcp_ack_num); - current_wget_state = WGET_CONNECTED; - break; - case WGET_CONNECTED: - case WGET_TRANSFERRING: - case WGET_TRANSFERRED: - net_send_tcp_packet(0, SERVER_PORT, our_port, action, - tcp_seq_num, tcp_ack_num); - break; - } -} - -static void wget_send(u8 action, unsigned int tcp_seq_num, - unsigned int tcp_ack_num, int len) -{ - retry_action = action; - retry_tcp_ack_num = tcp_ack_num; - retry_tcp_seq_num = tcp_seq_num; - retry_len = len; - - wget_send_stored(); -} - -void wget_fail(char *error_message, unsigned int tcp_seq_num, - unsigned int tcp_ack_num, u8 action) -{ - printf("wget: Transfer Fail - %s\n", error_message); - net_set_timeout_handler(0, NULL); - wget_send(action, tcp_seq_num, tcp_ack_num, 0); -} - -void wget_success(u8 action, unsigned int tcp_seq_num, - unsigned int tcp_ack_num, int len, int packets) -{ - printf("Packets received %d, Transfer Successful\n", packets); - wget_send(action, tcp_seq_num, tcp_ack_num, len); -} - -/* - * Interfaces of U-BOOT - */ -static void wget_timeout_handler(void) -{ - if (++wget_timeout_count > WGET_RETRY_COUNT) { - puts("\nRetry count exceeded; starting again\n"); - wget_send(TCP_RST, 0, 0, 0); - net_start_again(); - } else { - puts("T "); - net_set_timeout_handler(wget_timeout + - WGET_TIMEOUT * wget_timeout_count, - wget_timeout_handler); - wget_send_stored(); - } -} - -#define PKT_QUEUE_OFFSET 0x20000 -#define PKT_QUEUE_PACKET_SIZE 0x800 - -static void wget_connected(uchar *pkt, unsigned int tcp_seq_num, - u8 action, unsigned int tcp_ack_num, unsigned int len) -{ - uchar *pkt_in_q; - char *pos; - int hlen, i; - uchar *ptr1; - - pkt[len] = '\0'; - pos = strstr((char *)pkt, http_eom); - - if (!pos) { - debug_cond(DEBUG_WGET, - "wget: Connected, data before Header %p\n", pkt); - pkt_in_q = (void *)image_load_addr + PKT_QUEUE_OFFSET + - (pkt_q_idx * PKT_QUEUE_PACKET_SIZE); - - ptr1 = map_sysmem((phys_addr_t)pkt_in_q, len); - memcpy(ptr1, pkt, len); - unmap_sysmem(ptr1); - - pkt_q[pkt_q_idx].pkt = pkt_in_q; - pkt_q[pkt_q_idx].tcp_seq_num = tcp_seq_num; - pkt_q[pkt_q_idx].len = len; - pkt_q_idx++; - } else { - debug_cond(DEBUG_WGET, "wget: Connected HTTP Header %p\n", pkt); - /* sizeof(http_eom) - 1 is the string length of (http_eom) */ - hlen = pos - (char *)pkt + sizeof(http_eom) - 1; - pos = strstr((char *)pkt, linefeed); - if (pos > 0) - i = pos - (char *)pkt; - else - i = hlen; - printf("%.*s", i, pkt); - - current_wget_state = WGET_TRANSFERRING; - - if (strstr((char *)pkt, http_ok) == 0) { - debug_cond(DEBUG_WGET, - "wget: Connected Bad Xfer\n"); - initial_data_seq_num = tcp_seq_num + hlen; - wget_loop_state = NETLOOP_FAIL; - wget_send(action, tcp_seq_num, tcp_ack_num, len); - } else { - debug_cond(DEBUG_WGET, - "wget: Connctd pkt %p hlen %x\n", - pkt, hlen); - initial_data_seq_num = tcp_seq_num + hlen; - - pos = strstr((char *)pkt, content_len); - if (!pos) { - content_length = -1; - } else { - pos += sizeof(content_len) + 2; - strict_strtoul(pos, 10, &content_length); - debug_cond(DEBUG_WGET, - "wget: Connected Len %lu\n", - content_length); - } - - net_boot_file_size = 0; - - if (len > hlen) - store_block(pkt + hlen, 0, len - hlen); - - debug_cond(DEBUG_WGET, - "wget: Connected Pkt %p hlen %x\n", - pkt, hlen); - - for (i = 0; i < pkt_q_idx; i++) { - ptr1 = map_sysmem( - (phys_addr_t)(pkt_q[i].pkt), - pkt_q[i].len); - store_block(ptr1, - pkt_q[i].tcp_seq_num - - initial_data_seq_num, - pkt_q[i].len); - unmap_sysmem(ptr1); - debug_cond(DEBUG_WGET, - "wget: Connctd pkt Q %p len %x\n", - pkt_q[i].pkt, pkt_q[i].len); - } - } - } - wget_send(action, tcp_seq_num, tcp_ack_num, len); -} - -/** - * wget_handler() - TCP handler of wget - * @pkt: pointer to the application packet - * @dport: destination TCP port - * @sip: source IP address - * @sport: source TCP port - * @tcp_seq_num: TCP sequential number - * @tcp_ack_num: TCP acknowledgment number - * @action: TCP action (SYN, ACK, FIN, etc) - * @len: packet length - * - * In the "application push" invocation, the TCP header with all - * its information is pointed to by the packet pointer. - */ -static void wget_handler(uchar *pkt, u16 dport, - struct in_addr sip, u16 sport, - u32 tcp_seq_num, u32 tcp_ack_num, - u8 action, unsigned int len) -{ - enum tcp_state wget_tcp_state = tcp_get_tcp_state(); - - net_set_timeout_handler(wget_timeout, wget_timeout_handler); - packets++; - - switch (current_wget_state) { - case WGET_CLOSED: - debug_cond(DEBUG_WGET, "wget: Handler: Error!, State wrong\n"); - break; - case WGET_CONNECTING: - debug_cond(DEBUG_WGET, - "wget: Connecting In len=%x, Seq=%u, Ack=%u\n", - len, tcp_seq_num, tcp_ack_num); - if (!len) { - if (wget_tcp_state == TCP_ESTABLISHED) { - debug_cond(DEBUG_WGET, - "wget: Cting, send, len=%x\n", len); - wget_send(action, tcp_seq_num, tcp_ack_num, - len); - } else { - printf("%.*s", len, pkt); - wget_fail("wget: Handler Connected Fail\n", - tcp_seq_num, tcp_ack_num, action); - } - } - break; - case WGET_CONNECTED: - debug_cond(DEBUG_WGET, "wget: Connected seq=%u, len=%x\n", - tcp_seq_num, len); - if (!len) { - wget_fail("Image not found, no data returned\n", - tcp_seq_num, tcp_ack_num, action); - } else { - wget_connected(pkt, tcp_seq_num, action, tcp_ack_num, len); - } - break; - case WGET_TRANSFERRING: - debug_cond(DEBUG_WGET, - "wget: Transferring, seq=%x, ack=%x,len=%x\n", - tcp_seq_num, tcp_ack_num, len); - - if (tcp_seq_num >= initial_data_seq_num && - store_block(pkt, tcp_seq_num - initial_data_seq_num, - len) != 0) { - wget_fail("wget: store error\n", - tcp_seq_num, tcp_ack_num, action); - return; - } - - switch (wget_tcp_state) { - case TCP_FIN_WAIT_2: - wget_send(TCP_ACK, tcp_seq_num, tcp_ack_num, len); - fallthrough; - case TCP_SYN_SENT: - case TCP_SYN_RECEIVED: - case TCP_CLOSING: - case TCP_FIN_WAIT_1: - case TCP_CLOSED: - net_set_state(NETLOOP_FAIL); - break; - case TCP_ESTABLISHED: - wget_send(TCP_ACK, tcp_seq_num, tcp_ack_num, - len); - wget_loop_state = NETLOOP_SUCCESS; - break; - case TCP_CLOSE_WAIT: /* End of transfer */ - current_wget_state = WGET_TRANSFERRED; - wget_send(action | TCP_ACK | TCP_FIN, - tcp_seq_num, tcp_ack_num, len); - break; - } - break; - case WGET_TRANSFERRED: - printf("Packets received %d, Transfer Successful\n", packets); - net_set_state(wget_loop_state); - break; - } -} - -#define RANDOM_PORT_START 1024 -#define RANDOM_PORT_RANGE 0x4000 - -/** - * random_port() - make port a little random (1024-17407) - * - * Return: random port number from 1024 to 17407 - * - * This keeps the math somewhat trivial to compute, and seems to work with - * all supported protocols/clients/servers - */ -static unsigned int random_port(void) -{ - return RANDOM_PORT_START + (get_timer(0) % RANDOM_PORT_RANGE); -} - -#define BLOCKSIZE 512 - -void wget_start(void) -{ - image_url = strchr(net_boot_file_name, ':'); - if (image_url > 0) { - web_server_ip = string_to_ip(net_boot_file_name); - ++image_url; - net_server_ip = web_server_ip; - } else { - web_server_ip = net_server_ip; - image_url = net_boot_file_name; - } - - debug_cond(DEBUG_WGET, - "wget: Transfer HTTP Server %pI4; our IP %pI4\n", - &web_server_ip, &net_ip); - - /* Check if we need to send across this subnet */ - if (net_gateway.s_addr && net_netmask.s_addr) { - struct in_addr our_net; - struct in_addr server_net; - - our_net.s_addr = net_ip.s_addr & net_netmask.s_addr; - server_net.s_addr = net_server_ip.s_addr & net_netmask.s_addr; - if (our_net.s_addr != server_net.s_addr) - debug_cond(DEBUG_WGET, - "wget: sending through gateway %pI4", - &net_gateway); - } - debug_cond(DEBUG_WGET, "URL '%s'\n", image_url); - - if (net_boot_file_expected_size_in_blocks) { - debug_cond(DEBUG_WGET, "wget: Size is 0x%x Bytes = ", - net_boot_file_expected_size_in_blocks * BLOCKSIZE); - print_size(net_boot_file_expected_size_in_blocks * BLOCKSIZE, - ""); - } - debug_cond(DEBUG_WGET, - "\nwget:Load address: 0x%lx\nLoading: *\b", image_load_addr); - - net_set_timeout_handler(wget_timeout, wget_timeout_handler); - tcp_set_tcp_handler(wget_handler); - - wget_timeout_count = 0; - current_wget_state = WGET_CLOSED; - - our_port = random_port(); - - /* - * Zero out server ether to force arp resolution in case - * the server ip for the previous u-boot command, for example dns - * is not the same as the web server ip. - */ - - memset(net_server_ethaddr, 0, 6); - - wget_send(TCP_SYN, 0, 0, 0); -} From patchwork Fri Sep 8 13:53:20 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxim Uvarov X-Patchwork-Id: 720828 Delivered-To: patch@linaro.org Received: by 2002:adf:eec5:0:b0:31d:da82:a3b4 with SMTP id a5csp779762wrp; Fri, 8 Sep 2023 06:58:12 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFBvstpx5E0UrTNoc0yGQrDPvBfDCQdQYyKqV5IFTaUK00+SaSCuJu4K2JbCc/3eyiTe3+/ X-Received: by 2002:a1c:790b:0:b0:401:c8b9:4b86 with SMTP id l11-20020a1c790b000000b00401c8b94b86mr1657404wme.9.1694181492169; Fri, 08 Sep 2023 06:58:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694181492; cv=none; d=google.com; s=arc-20160816; b=KJh56qpW8xyu6pjezWjuhDEv0q/hh9ZOLdjf4JFagkwbXof1dyWuYw8GemQEHemdOt /jD+lAQ2F9yReQqCoQczp+gVsXsJqfvSEUP3OIAGS2mvEfG1vUJ2YEf+6I3MVo+FOwNz X7okyxhYWPElTU3LtbLT8UK8+lGhQKd5ye/fV+6nNguhT7P8dx038sqqt9U8b3W02vq9 vmXJ4+Scpo7B9sH7DAlk5OV1Ob44zTuGX7ldOF+yp4lc4r8o0l2d2wgJMYZSO7Kxiigy 0Hkjf+DvLqLfoKbSU4ZgBu8qyKgHUCU6aYS7zCFwUQ+t1luiuUmNe8zT1EnRHFTAY0PG 6xmA== 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=jHXWqgTf/sMFZxv9oq24wQUKGoOCwB4OY4AAJ/pkjjE=; fh=hYoOR0yg+Fo7S26X8ur5L+RaTmkyxWlAVaBypEC8A0g=; b=T4bNs11jp2uvKRM6X+fHHrjQC5wTl7DABBUZd6UAvRBdFsTlVHhi7xUndUcKAxUSm9 ao1Z8IeDG4xXEyd6Xigez7675/8k9Oc2/fMYcrJ+iXCPK51lVC6VobJQxskWfvlVIhas NCQvp28CyW0+8DsQeQRaapcpJTlBpfJdtIroYKmUQD0rTyLH7GhZcI37XnAnrjN5eZHU ZrijT17Kq2rFiJhYLdLcCLBgHsPnIYlQnNKAuXIVJUbYMcfcX56UWXZGy7973ZWm2mKL vep4kcH2u+ttmjVqeJgG6suElYd+DsKRJhA5gO/NS4yNKPAUTHSoaSFQX9u6M6vUgKPv R+Hw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Q416S07D; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 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. [85.214.62.61]) by mx.google.com with ESMTPS id bh5-20020a05600c3d0500b00400f8f92c08si887041wmb.52.2023.09.08.06.58.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Sep 2023 06:58:12 -0700 (PDT) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) client-ip=85.214.62.61; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Q416S07D; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 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 C807886AC6; Fri, 8 Sep 2023 15:56:15 +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="Q416S07D"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 8CA3486ABC; Fri, 8 Sep 2023 15:56:13 +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-x22d.google.com (mail-lj1-x22d.google.com [IPv6:2a00:1450:4864:20::22d]) (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 E601286ACC for ; Fri, 8 Sep 2023 15:56:10 +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-x22d.google.com with SMTP id 38308e7fff4ca-2bcc331f942so25289921fa.0 for ; Fri, 08 Sep 2023 06:56:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1694181370; x=1694786170; darn=lists.denx.de; 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=jHXWqgTf/sMFZxv9oq24wQUKGoOCwB4OY4AAJ/pkjjE=; b=Q416S07Duidun2Jo2psxBsuHWBrpWy3AYMWuzWYJ7G2wvnNyJ1nyO8dMRoJhc7G7yv Od43vkVsU7wlapgLJ6419GHSDZ6/GUGPp4mN94uc/RsywbgTQhWQ8QKBJtDoUXOQzotT Z52GV1OujGBd6oM7AtgPNXNn4OZc1OWIXveFczUmlGeY5j9NnEVbaWzdZu9N3Jgjmnhk FRRExAaAS/02kRfnVEKPKdcxDnQl4BTWgTSu2pI5RcIkF7BlhU4Eh5APG1wm0wztYR0C hRo+sKgLLJB8QqGSNcJD9q7dU2C57DxD38yEK9cZ3o95tAFBaejL87C8mJuv9MJ6RCf6 WfyQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694181370; x=1694786170; 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=jHXWqgTf/sMFZxv9oq24wQUKGoOCwB4OY4AAJ/pkjjE=; b=Ww4uMyeSb7qEGGetz/knG5HbZJB6lXaFeP0VeO+cTdBcfLgphtIefxlx33uRSZEJJx DOPf6m8th5Qx7uWsxIl9bEN9/0YTreu8xdGmDwch0gjcul06zgZkQdY/cg8dkorTOt/n Np1rsYpd9fqTsS7jsUoBIYHbEoKbyi+qwZBmFSXUwRa/PzG0mrU1upo0CJZllj50sDIs vipSHYRWAD/qCu8Eme+MuYWia1CC2rIQauAnRGpHsFL0iBRFFIQOx2KN9RGYNipR9J1w SgkaJJapjB/6tcK7EWbbwvOnqCD/Xlk/DUqsmgg0gKWS6gP7VLKfzRHfdsVGHpfYmCQv H3Wg== X-Gm-Message-State: AOJu0Yz0jocX/pswyQAWuVNHVLmgPNyEhM4yKVE8l2+F9HvfAiu5AW8g JgWkw+R8YlMkZqtzHrqON4Awk2QH8yj3QfBPja1xPg== X-Received: by 2002:a2e:9c83:0:b0:2bb:c19b:710c with SMTP id x3-20020a2e9c83000000b002bbc19b710cmr862975lji.5.1694181370123; Fri, 08 Sep 2023 06:56:10 -0700 (PDT) Received: from localhost.localdomain ([45.82.14.220]) by smtp.gmail.com with ESMTPSA id u14-20020a2e9f0e000000b002bcbae4c21fsm306907ljk.50.2023.09.08.06.56.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Sep 2023 06:56:09 -0700 (PDT) From: Maxim Uvarov To: u-boot@lists.denx.de Cc: pbrobinson@gmail.com, ilias.apalodimas@linaro.org, joe.hershberger@ni.com, rfried.dev@gmail.com, trini@konsulko.com, goldsimon@gmx.de, Maxim Uvarov Subject: [PATCHv8 15/15] net/lwip/wget add port selection Date: Fri, 8 Sep 2023 19:53:20 +0600 Message-Id: <20230908135320.7066-16-maxim.uvarov@linaro.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230908135320.7066-1-maxim.uvarov@linaro.org> References: <20230908135320.7066-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 Allow to specify HTTP port instead of just using default for wget command. Signed-off-by: Maxim Uvarov --- include/net/lwip.h | 2 +- net/lwip/apps/http/lwip-wget.c | 40 +++++++++++++++++++++++++--------- 2 files changed, 31 insertions(+), 11 deletions(-) diff --git a/include/net/lwip.h b/include/net/lwip.h index 1e92f9871c..6de646771e 100644 --- a/include/net/lwip.h +++ b/include/net/lwip.h @@ -54,7 +54,7 @@ int ulwip_tftp(ulong addr, const char *filename); * * * @addr: start address to download result - * @url: url in format http://host/url + * @url: url in format http://host[:port]/url * Returns: 0 for success, !0 if error */ int ulwip_wget(ulong addr, char *url); diff --git a/net/lwip/apps/http/lwip-wget.c b/net/lwip/apps/http/lwip-wget.c index 5c432056b1..7de1c962c6 100644 --- a/net/lwip/apps/http/lwip-wget.c +++ b/net/lwip/apps/http/lwip-wget.c @@ -63,18 +63,38 @@ static int parse_url(char *url, char *host, u16 *port) p += strlen("http://"); /* parse hostname */ - pp = strchr(p, '/'); - if (!pp) { - return -2; + pp = strchr(p, ':'); + if (pp) { +#define PORT_STR_SIZE 5 + char portstr[PORT_STR_SIZE]; + + if (pp - p >= SERVER_NAME_SIZE) + return -2; + memcpy(host, p, pp - p); + host[pp - p + 1] = '\0'; + + p = pp + 1; + pp = strchr(p, '/'); + if (!pp) + return -3; + + if (pp - p >= PORT_STR_SIZE) + return -4; + memcpy(portstr, p, pp - p); + portstr[pp - p] = '\0'; + *port = (u16)dectoul(portstr, NULL); + } else { + pp = strchr(p, '/'); + if (!pp) + return -5; + + if (pp - p >= SERVER_NAME_SIZE) + return -6; + memcpy(host, p, pp - p); + host[pp - p + 1] = '\0'; + *port = HTTP_PORT_DEFAULT; } - if (pp - p >= SERVER_NAME_SIZE) - return -3; - - memcpy(host, p, pp - p); - host[pp - p + 1] = '\0'; - *port = HTTP_PORT_DEFAULT; - return 0; }