From patchwork Thu Jun 29 12:34:29 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Maxim Uvarov X-Patchwork-Id: 697690 Delivered-To: patch@linaro.org Received: by 2002:adf:e885:0:0:0:0:0 with SMTP id d5csp4867030wrm; Thu, 29 Jun 2023 05:41:35 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5pfskRIUmEC8hJptpNxmtzcOSWWQgzWsgoDj2FN1rfiZzfGHZ03lylMWj3WXSwoTrtzIOf X-Received: by 2002:a05:6512:2824:b0:4fb:7888:7e6d with SMTP id cf36-20020a056512282400b004fb78887e6dmr9082016lfb.46.1688042495727; Thu, 29 Jun 2023 05:41:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688042495; cv=none; d=google.com; s=arc-20160816; b=p947KzabVocjstLmDEBiANcC7kzrQm3GfxXzMfTEwPQacV3GpvI6yfdNUDzV2qU+Ju tKmKWr7bihNy0hhGObJkKr86fMR2Hp7Hk83ecNRC96KbReU8bmSE06ZgMC3VWLFhFd1Y yWDS8SLl0FmQgbA9O6Jt7zvbQw4boqP1tvtTc8NQRGIOKbHhiCNCae6+F8B3n67L6mtK UaSfSRc0oSUr7IL43XtoHcxbfz9Vsy351d1NZ6Bj91XFxz0ICebSaDbnpP6IZT5hNKxa h4/n9BMlkFzHOrELfeVXmA1otednRwm2MeptTVqTXPI43225GoyetcoKAQqpP4nnqC1/ 3gMQ== 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=zR/mAiHa/g2ftLqabFFjszrLQ75T0+a4qDU/lDizxas=; fh=378OOY3Qcv/6SzHacyD4RkrbXzlmlfqp4CO9kQxJxOk=; b=lrrFuitXs2uTayiem0vfHFwAQ2aLB5BkcfJB+J0pQJ2aAeVmIGtPEcpVpqXizQzDdn BPF0AjMKPu0UmP45WjjfozBA9pUi8kL7+W5V3CuhaQX0635nI58uWK0wwE1RjF+ZRTd8 m3lNMHCu1FkLI86KArfPbqVY4LYtfZDMmPWqdaz7rb/LI76brWpKBtMLp3v1XqNtXwB5 glRquofWgrKRDwGa0N7MYIfvbrRwRnOlEzkfrfNxytGYD+t7Tddv9SB/fNML/IlMqQHI Jb6iaccmYMxnmiglvsCNK47zkPU6SMKZ3L8jyYmi7P2jFysvUSNiBXMT5voT3AE8uvpf +AyQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=NDp4REYn; 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 y23-20020ac24477000000b004f8643d7fc7si1187038lfl.60.2023.06.29.05.41.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 29 Jun 2023 05:41:35 -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=NDp4REYn; 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 B8383866B5; Thu, 29 Jun 2023 14:41:28 +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="NDp4REYn"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 01853866DD; Thu, 29 Jun 2023 14:38:31 +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=-0.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NUMERIC_HTTP_ADDR,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-lf1-x133.google.com (mail-lf1-x133.google.com [IPv6:2a00:1450:4864:20::133]) (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 CCC51866F1 for ; Thu, 29 Jun 2023 14:36: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-lf1-x133.google.com with SMTP id 2adb3069b0e04-4f865f0e16cso973208e87.3 for ; Thu, 29 Jun 2023 05:36:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1688042204; x=1690634204; 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=zR/mAiHa/g2ftLqabFFjszrLQ75T0+a4qDU/lDizxas=; b=NDp4REYn9GD0niCchSHROxtGLK01G/BkoP3loFnaulK2PDhAtwHFitQ28Uqw/d35q4 jvVRP6SBVAi33vDpdO1kzbMxcjuT1FCAH543vOFD0iHRDG7sAo5O6g+v9eJTxZ1M9kNL Lsqm8Acj63JMrmrNgoaO9hiHpYUxMYEdpLUslzd4nFdG86GgtIVeyss2FG2ltTCgDHif 0lU9aV1tr9b4IQT/ZGqyQX1pOgDZXHII9xLhE3r6sZOSGUb26C03/kuhSD9TmU1Gno5R /6piBwCwkTnHUdQm/vJVyfx4P4tM3ChqM0rOxgBB/JzOsDRnEWCK/DXEk334BA/ByKA2 H/Dw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688042204; x=1690634204; 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=zR/mAiHa/g2ftLqabFFjszrLQ75T0+a4qDU/lDizxas=; b=cJNDSX+4PHbDDv9Y59ArHPSQNw7OvCCcQRGeAxWT8obNFuNBe2qU1NndT3L1uJbsS0 2sg8YkR0QQG3JVPKLD+J9ybWt+f1/OPEdXrDaO3rH5c1BosXXFyrdgMzNEafs4dy8PnN R6tL4hVWLPQkCEFV6BtjZYRcuCdKiEP8fEZMfuOknZ5g4kxrZi6O7dt8f1Oj7OdPr5C/ jIanlmhwA+yOjj2pgxEu/y6tkR38VwkHeFD8J9YAbqASzO/qWxYNihERMLilpmr1hzvv ygKzyDHbx+DE8Qx5G+LO5NqbqhTpHNBdHjMT1SExWbYsMUwaQn4Wu4LXtg+zt16tNn2B AStQ== X-Gm-Message-State: AC+VfDyfz5yg6TxagaoO1jlpUhzzzyRpLR4hH7+ookDW46xA4nq0InjB sGuXzAYBQV0Gex/282L3NXN3mBEf3SgkW4bNaqnOsg== X-Received: by 2002:a05:6512:39d0:b0:4f9:6581:8b4c with SMTP id k16-20020a05651239d000b004f965818b4cmr15713756lfu.44.1688042203680; Thu, 29 Jun 2023 05:36:43 -0700 (PDT) Received: from localhost.localdomain ([45.82.14.220]) by smtp.gmail.com with ESMTPSA id p3-20020ac246c3000000b004f59c182f7bsm2295742lfo.249.2023.06.29.05.36.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 29 Jun 2023 05:36:43 -0700 (PDT) From: Maxim Uvarov To: u-boot@lists.denx.de Cc: pbrobinson@redhat.com, ilias.apalodimas@linaro.org, joe.hershberger@ni.com, rfried.dev@gmail.com, trini@konsulko.com, goldsimon@gmx.de, lwip-devel@nongnu.org, Maxim Uvarov Subject: [PATCHv2 2/3] net/lwip: add README.lwip Date: Thu, 29 Jun 2023 18:34:29 +0600 Message-Id: <20230629123430.3679-2-maxim.uvarov@linaro.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230629123430.3679-1-maxim.uvarov@linaro.org> References: <20230629123430.3679-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 Just add inital README.lwip doc. Signed-off-by: Maxim Uvarov --- doc/README.lwip | 90 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 90 insertions(+) create mode 100644 doc/README.lwip diff --git a/doc/README.lwip b/doc/README.lwip new file mode 100644 index 0000000000..16f41049ab --- /dev/null +++ b/doc/README.lwip @@ -0,0 +1,90 @@ + RFC LWIP IP stack intergation for U-boot + ---------------------------------------- + +Reliable and bug free IP stack is usually an issue when you are trying to write it +from scratch. It looks like not, but when addinging new features it will be chelledging. +This RFC work is a demo to enable lwIP (lightweight IP) which is a widely used open-source +TCP/IP stack designed for embedded systems for U-boot. That will allow using already +written network applications for microcontrollers. + +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 I selected +the second variant: iwIP is very customizable with defines for features, memory size, types of +allocation, some internal types and platform specific code. And it was more easy 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). + This RFC implements only raw API as the proof of work. + +Raw IP means that the call back function for RX path is registered and will be called when packet +data passes the IP stack and is ready for the application. + +This RFC has an unmodified working ping example from lwip sources which registeres this callback. +  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) + +Socket API also gives nice advantages due it will be easy to port linux socket applications to u-boot. +I.e. lwIP sockets compatible with the linux ones. But that will require RX thread running in the background. +So that means we need some kind of scheduler, locking and threading support or find some other solution. + +3.  Input and output + +RX packet path is injected to U-boot eth_rx() polling loop and TX patch is in eth_send() accordingly. +So we do not touch any drivers code and just eat packets when they are ready. + +4. Testing + +Unmodified ping example can be used. I did ping from qemu/u-boot tap device on the host: + +=> lwip init +=> lwip ping 192.168.1.2 +ping: recv 3 ms +tcpdump on the host: +5:09:10.925951 ARP, Request who-has 192.168.1.200 tell 192.168.1.200, length 28 15:09:12.114643 IP6 fe80::38e2:41ff:fec3:8bda > ip6-allrouters: ICMP6, router solicitation, length 16 15:09:20.370725 ARP, Request who-has 192.168.1.2 tell 192.168.1.200, length 28 15:09:20.370740 ARP, Reply 192.168.1.2 is-at 3a:e2:41:c3:8b:da (oui Unknown), length 28 15:09:20.372789 IP 192.168.1.200 > 192.168.1.2: ICMP echo request, id 44975, seq 1, length 40 15:09:20.372810 IP 192.168.1.2 > 192.168.1.200: ICMP echo reply, id 44975, seq 1, length 40 15:09:25.426636 ARP, Request who-has 192.168.1.200 tell 192.168.1.2, length 28 15:09:25.426870 ARP, Reply 192.168.1.200 is-at f6:11:01:02:03:04 (oui Unknown), length 28 + + +5. Wget example + +Http server has 192.168.1.2 IP address. (I did not port DNS resolving yet, +but it's also exist in lwip.) So example just downloads some file with http +protocol: + +Net: eth0: virtio-net#30 +Hit any key to stop autoboot: 0 +=> lwip init +Starting lwIP, local interface IP is 192.168.1.200 +Initialized LWIP stack +=> lwip wget http://192.168.1.2/ +downloading http://192.168.1.2/ to addr 0x40200000 +downloaded chunk size 294, to addr 0x40200000 +downloaded chunk size 318, to addr 0x40200126 +=> md 0x40200000 0x40 +40200000: 4f44213c 50595443 74682045 0a3e6c6d . +40200010: 6d74683c 3c0a3e6c 64616568 743c0a3e ..Welcome to +40200030: 6e69676e 2f3c2178 6c746974 3c0a3e65 nginx!.< +40200040: 6c797473 200a3e65 62202020 2079646f style>. body +40200050: 20200a7b 20202020 69772020 3a687464 {. width: +40200060: 65353320 200a3b6d 20202020 6d202020 35em;. m +40200070: 69677261 30203a6e 74756120 200a3b6f argin: 0 auto;. +40200080: 20202020 66202020 2d746e6f 696d6166 font-fami +40200090: 203a796c 6f686154 202c616d 64726556 ly: Tahoma, Verd +402000a0: 2c616e61 69724120 202c6c61 736e6173 ana, Arial, sans +402000b0: 7265732d 0a3b6669 20202020 2f3c0a7d -serif;. }...< +402000d0: 79646f62 683c0a3e 65573e31 6d6f636c body>.

Welcom +402000e0: 6f742065 69676e20 3c21786e 3e31682f e to nginx!

+402000f0: 3e703c0a 79206649 7320756f 74206565 .

If you see t