From patchwork Thu Sep 14 16:18: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: 722558 Delivered-To: patch@linaro.org Received: by 2002:adf:f0d1:0:b0:31d:da82:a3b4 with SMTP id x17csp485326wro; Thu, 14 Sep 2023 09:20:58 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGPCG4GZD7gjdL8u0NNVlQ1eer/R982LLtCiaj3mqPKbuYzO8D1rv9onGxoNfUJSBTwv0aB X-Received: by 2002:a05:6000:1c0a:b0:31f:eba4:9875 with SMTP id ba10-20020a0560001c0a00b0031feba49875mr555463wrb.30.1694708457867; Thu, 14 Sep 2023 09:20:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694708457; cv=none; d=google.com; s=arc-20160816; b=xJaREX7S6pJl0M8sryOdZavWsnyBaoYQ8nwJ0TCmJ+FKwIWhcVJ5nQoevk/K9DnR6Y 59+4/ExuZ1Sc+XTq65e0mEmsn4kCVZzEblTe5R/p344onZmCGQNJUD60xX/f7tMRdkSQ guFe5Qz+gIBFXNBRMi9b+xSLXslP6u0smdMLeQd6UZlQEnVlJdgdMp6R79CmJ+54wQVt GsjISYOs/GOMZvkl5BJFWkqoIlX9xSPkbtRo9vgb7+WqPEt2Puwak/bGeLNy1UeJ4X6O /W7ZltQhqGiO/0wY35n5VCO8wI+VBdD9aCch55hdTdQk3Rt0EwjP12r9jgscS8LmEFYr 5Dig== 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=Iqjo/S2dlM9bmalrr162ON2R3PCrWmnEZHSq09Dn8Zw=; fh=hYoOR0yg+Fo7S26X8ur5L+RaTmkyxWlAVaBypEC8A0g=; b=h01rnbEbLmnDEhSTF8iuKgCVOtTKhkGM6T9VFCVwAjHG8BqLEQrXoI1WQiV/GwbLU6 uD3TF5AdrNvUCMeEN3Z3kMCOj+kKlLaGy6SWa8vJziHHUxobGzIHIKMnOip6VNPE84Jv XsTFQmIwTG6d85SNc6gVJN4xB4nEQAzyACjWHZbNjtB8YI3y66TdlVyMxN5Y/C7NJHXe IQA0KqIayj/gikD8GRzoRctZk0KlKV2wN0ho6JmcpS9ErDu4NdTGNIP2nSYeSF5fiDvp J403lW1cgFrfwu8351nvcrfTrH1N3jI84dzpZTUt2KdKb+vHMDEXAyxRQBDg2nBO0RGa PqSw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=OtIMCkmw; 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 m4-20020adfe944000000b0031dd659075fsi801273wrn.482.2023.09.14.09.20.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Sep 2023 09:20:57 -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=OtIMCkmw; 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 A7AF186A7B; Thu, 14 Sep 2023 18:20:42 +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="OtIMCkmw"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 2C73686A3C; Thu, 14 Sep 2023 18:20: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-x234.google.com (mail-lj1-x234.google.com [IPv6:2a00:1450:4864:20::234]) (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 F3E2A86918 for ; Thu, 14 Sep 2023 18:20:38 +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-x234.google.com with SMTP id 38308e7fff4ca-2bfbd7d49e7so18452301fa.1 for ; Thu, 14 Sep 2023 09:20:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1694708438; x=1695313238; 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=Iqjo/S2dlM9bmalrr162ON2R3PCrWmnEZHSq09Dn8Zw=; b=OtIMCkmwQRto17VAqLzQvOkYwr0pVKZDZbmF90bFQjzGT7I5OhcwdKkjYASESFFKHU XeP9tiDuuCAJbngWXjX9ye589ilBDDkJO/7Msc/i0QucvYbXX8m2LFr/JREKYB8sJ0XN VwUEH/yYZ0YO2jr+e2B7bsTZg2c8U3l8lf1nCqof6/s1BtiFyEvhtcscZ96Ya9vD8Oir yTGfa54qeFRMS6YNLxS1qIlEYq0G96DDDNBuUNGLbYFKTe5/5d2Bj2+ay3nT4/CH9voj YgD+2J+QDGPX723M0RDVE+qbo11y6mk915tfeHjv3Dc6OOOyWn93mA/yDjnZr1+vF7ks mwGw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694708438; x=1695313238; 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=Iqjo/S2dlM9bmalrr162ON2R3PCrWmnEZHSq09Dn8Zw=; b=AILWgGaxUdKjcaWNgsJDauhT58YNLwBZJcKwaS/1dRujeYyVU/sq9aWg1oRUrsKUuK 84HRbal0q1lfF6wy0AgGUDw/riY8AGRrU5fSwlpzrdNMImLERiH1NtFDXaOt64X2XvAa dP021rSzXqfgtz75gxrfLKGcCq6JDrOSguAwOFCzYwFB3HVt5CgKWwtoTlgrHsl6PXrh Q+71GS6h25pf3FVp/lrf/kXTuSqFiTsyB+kj9g5zJKMSfU/gG9mYDyHAGdXNt52kSO2A 1kF6o5Mw8eeYBqFGsCTVJ4+N/M7QkhBFsJV24sseYKHj1TVxTwEZgYllKrsf/Ygzpwuu oqoA== X-Gm-Message-State: AOJu0Ywj5VMO/M9y1BGBR7sUiKmbwMdFob8F3lzEoFjmAM6lvzGLLRtL PNqtV9Uh04xZVqOHqS1lTEFT5nQbo4cHvO3WjnDwWw== X-Received: by 2002:a2e:93c5:0:b0:2b6:d89e:74e2 with SMTP id p5-20020a2e93c5000000b002b6d89e74e2mr5071779ljh.7.1694708438105; Thu, 14 Sep 2023 09:20:38 -0700 (PDT) Received: from localhost.localdomain ([45.82.14.220]) by smtp.gmail.com with ESMTPSA id z15-20020a2e8e8f000000b002ba7ae1f52asm346919ljk.0.2023.09.14.09.20.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Sep 2023 09:20:37 -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: [PATCHv9 01/15] submodule: add lwIP as git submodule Date: Thu, 14 Sep 2023 22:18:14 +0600 Message-Id: <20230914161828.3662-2-maxim.uvarov@linaro.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230914161828.3662-1-maxim.uvarov@linaro.org> References: <20230914161828.3662-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 external lwIP library as a git submodule. Signed-off-by: Maxim Uvarov --- .gitmodules | 3 +++ net/lwip/lwip-external | 1 + 2 files changed, 4 insertions(+) create mode 100644 .gitmodules create mode 160000 net/lwip/lwip-external diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000000..245ecff585 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "lwip"] + path = net/lwip/lwip-external + url = https://git.savannah.nongnu.org/git/lwip.git diff --git a/net/lwip/lwip-external b/net/lwip/lwip-external new file mode 160000 index 0000000000..84fde1ebbf --- /dev/null +++ b/net/lwip/lwip-external @@ -0,0 +1 @@ +Subproject commit 84fde1ebbfe35b3125fc2d89b8a456cbacf148e9 From patchwork Thu Sep 14 16:18:15 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Maxim Uvarov X-Patchwork-Id: 722559 Delivered-To: patch@linaro.org Received: by 2002:adf:f0d1:0:b0:31d:da82:a3b4 with SMTP id x17csp485420wro; Thu, 14 Sep 2023 09:21:06 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEJSce5PXqKbbFF+SC0CN+HBo2aoN6lOcDRGDYABjFI62AVU8Ko3gH9e6ROicaRIMWp2iWw X-Received: by 2002:a5d:6a4c:0:b0:31f:af30:1bd9 with SMTP id t12-20020a5d6a4c000000b0031faf301bd9mr5029381wrw.44.1694708466433; Thu, 14 Sep 2023 09:21:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694708466; cv=none; d=google.com; s=arc-20160816; b=wQcmfojsNXMSINAfarlS6g05q0qUieNJ8G3XIYn2epf/0ylqR0etccImewhRizmkdx DSEntqUDgYyjfQM1oka5gIJD+DQ3efS+Bs2e5rm8TgIHhB0JHBfERRTAEWGh1Q7E1VQ7 oE0eSqmF3UQtJCr3kqE8yRA8r+ADZFzuctsG12FAmnHqzytkgzNGe7M3Ny4pZeoORxx5 KcYoWOvSH0S7GJR5o5JNj6Cf4y6QcCUalAO4NbJ95JMgePY9HP/3YCAGY8G9xGjT2XAU s8ADEd1JSXIU+wn+oUmUT3Ry9+au8UpusMoLw6gPnNtdrRYd7vGmjcRGRHeaIhA2/1ld 3Aug== 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=KlGOSpnuP038/3uWYsQ6F/fPIq0GHwMSq4PrefaoKZA=; fh=g6X7VLA7Hwc4ddn6ja9UNjzyIs7WWcGrFqfXM5IokKA=; b=yCo0/5HYbNI4YL/U8alANvkZXn1a+pYOQPYcaoF6hFBI7tZAgy3L6ZauNTR9w35WOe E1iEAtwVU9CZ9sD/8iBY1EKCDjS8nykKGflZcQsGGx581RaTuNC/vbLDe3DnHdZK0sxU 1Jsicmi5NKLREBQL6XuYqVNt72ntgZ0Mqgr96fpb7apc4oHk8QDS4+aZKjys7hNx+dxf oI1chvpHGpqKtgFKG4hJBYOhJQwcUz4X60l19IscgR1m45SMELjgLQ9ptkrp2Y8wp/dT 3SN6fqgC38xLGEh+ii5jbOOXBkTwf4yLo4kjes5xJ8OE/t06rztDPikx48IpEiI3+WKA 6g5g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=yz2s0py2; 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 e12-20020adfef0c000000b0031f8cb5250fsi805480wro.1025.2023.09.14.09.20.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Sep 2023 09:21:06 -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=yz2s0py2; 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 0452A86AA2; Thu, 14 Sep 2023 18:20: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="yz2s0py2"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 945E286A3C; Thu, 14 Sep 2023 18:20: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-x229.google.com (mail-lj1-x229.google.com [IPv6:2a00:1450:4864:20::229]) (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 4762186672 for ; Thu, 14 Sep 2023 18:20: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=maxim.uvarov@linaro.org Received: by mail-lj1-x229.google.com with SMTP id 38308e7fff4ca-2bf66a32f25so17920021fa.2 for ; Thu, 14 Sep 2023 09:20:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1694708440; x=1695313240; 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=KlGOSpnuP038/3uWYsQ6F/fPIq0GHwMSq4PrefaoKZA=; b=yz2s0py2u8LPS/cBbe9AtJjfshM61oQDbP3BOJn2F0lbuA2U7mSqTGNz8o1dJPNabf Rr72xeE1nsN9spWqZi2kUZEQiJ+zW9PrwEEJra2lnGY8raQqnRFf0B5x0AJg2TMwUl5T KBCEFjAfc/YO9KRKnig68+QPxcp1QJu7P5g8Epf6sEsUst09UGA0FZh/hDLxWNcTsK2N nI5j+PE+oto/wSTPhv7Xo+MmPKuUj+4LJE9FgoZztxesyEqaonosX5Stlpdau5/nKh/t IvGwbwhLSy5+9iBG/DZg7pDtTXjjlfaOxAzd+92vcyYW79LdX2GICvqOLIA6cKjCDAfj hsFA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694708440; x=1695313240; 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=KlGOSpnuP038/3uWYsQ6F/fPIq0GHwMSq4PrefaoKZA=; b=SI/YPwBCW7Aj69ZLnLGnbveJTn2NsCRimMjy/oZUzawGQr+LJbp4MAyNMl30mQDQUw wvOnHFEaxr2Y0jkCVdaxGn1YVVIjjh8y2to7acN0b6Sz9I6tCW/oDK3DLaV966Gu5B+r QT4YvAubNFMILrPHJxWpHKQE7eITwfLcvm+mHWHdNQx4CXemygCwy+LbXFrlMeDDrChC 8UpWpATBk3nI6j/O9NuqEmNFidPrgXnFOWK03D1/6jVlUFrz5+5Q99dKA8TGuZAirdMp q4tpuFow+Rn6cwB/w0sHvL2uTcg85HO/0CA47RX70PHO7On9l76qUeAu1/5d8OwApa6x Ot4w== X-Gm-Message-State: AOJu0YyPqelK8Jg74WY9yLNR1RQVriqMcIeVzc1mUoQVqIrni4Us/EDy plCLjTfcHFwZmBwnBDQzaBshqjJuKRoGr4zZrxVkkg== X-Received: by 2002:a2e:9f06:0:b0:2bd:beb:4aca with SMTP id u6-20020a2e9f06000000b002bd0beb4acamr5170780ljk.13.1694708440428; Thu, 14 Sep 2023 09:20:40 -0700 (PDT) Received: from localhost.localdomain ([45.82.14.220]) by smtp.gmail.com with ESMTPSA id z15-20020a2e8e8f000000b002ba7ae1f52asm346919ljk.0.2023.09.14.09.20.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Sep 2023 09:20:40 -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: [PATCHv9 02/15] net/lwip: add doc/develop/net_lwip.rst Date: Thu, 14 Sep 2023 22:18:15 +0600 Message-Id: <20230914161828.3662-3-maxim.uvarov@linaro.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230914161828.3662-1-maxim.uvarov@linaro.org> References: <20230914161828.3662-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 Thu Sep 14 16:18: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: 722560 Delivered-To: patch@linaro.org Received: by 2002:adf:f0d1:0:b0:31d:da82:a3b4 with SMTP id x17csp485482wro; Thu, 14 Sep 2023 09:21:15 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEZl52PFm65f+aF+OCt1cUxEVM2JW5zYh/OtxBNvjW8G/1gBcn8u9CWBbNoh/+Bt+AJKzah X-Received: by 2002:a5d:55c1:0:b0:31d:d3db:4566 with SMTP id i1-20020a5d55c1000000b0031dd3db4566mr5134962wrw.4.1694708475068; Thu, 14 Sep 2023 09:21:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694708475; cv=none; d=google.com; s=arc-20160816; b=CxheSsv/hUr9u7IF2dbhovsB8KEpQ6Q92orWd2TT+8VMDCm29GCzGc5ahNeuSUMkHR ASEng2ZyHOCCKNN8zu87jSmu9+CiTIJ5ExwI44em3TNfc/Ip7fet2Ex2wAL5tApp61XX 7tPoo0JoY6VfOmIrKQ82qTFPf54Pg6e1yB7eHXhDOM4Qf12NippQOPmEcUZj2uMXCn9S YwwPVJH0y+r9xVZhM3hoD9CYCUcQwssXHS5p8s6lv48/bWbskujmn2ue6eviG4Yxw1NM 9n8RykFRe/b49Mikh36KwiNWZ2p4c6LwXB6PmA5Yy83Fj7ZdW8rmgEEbGSzRsvNItLOs RrpA== 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=G9UmwPy/yqSTJ1WFe3uvNATp90iKIufTPVKaByGsK/dripjYBawwmP3XqzOTxEVm9f ULrgjYSdaq8ql/dX9USnrrfDhV5ChsDw1xeEU2tcEHvKsME4llBJzWnpbAdej6Cwudro +FhBZOKl6chJTB1UAi4BnMQSLmO3PUM2PKPxtH4secpdyR7Osd1Mh/frqg/qmi5uHrEL tIzzQ+qn5MbWuhl3K6J+qfGVcOz6nzMZhh+c3uflOlBMuGp9g+PwuFVbuLXFKS1fcOwm zluQ1OqCiDO0euI/bHVgIUNFHnuhgNqHE4A37bjAY9M5O11dlU3bEVK1ozw//Wsvve4i JPTw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=LCdS3Wfu; 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 k15-20020a5d518f000000b003196ed2a5c0si799474wrv.409.2023.09.14.09.21.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Sep 2023 09:21:15 -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=LCdS3Wfu; 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 5268086A43; Thu, 14 Sep 2023 18:20:46 +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="LCdS3Wfu"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id D310786672; Thu, 14 Sep 2023 18:20:45 +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 84F4F869AC for ; Thu, 14 Sep 2023 18:20: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-x22e.google.com with SMTP id 38308e7fff4ca-2bfc8c02e82so14869361fa.0 for ; Thu, 14 Sep 2023 09:20:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1694708442; x=1695313242; 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=LCdS3WfuEtpd6hKfMCBrQ4wcmzlxmPYEiPlJc8Z9GLOBM4fw7tqoSMAFk8IH2JjgSS tklPxxrdIo2Yb+zV5mD0hhsQOd6p6ii38du1/iUz+whwSvnWice9HIsV7BsQs7KyvgKN JMw1UcSj0GG3LO4RH9c8GNxD1OznA5Ep51b9xmSDAuSrCvSw0v7p3aROpoO6tGe90RbX lCIR9S6jWWf/PgVxIvCZ6O/T1xeBkqSh3tZHP5SJM4xJeLkwZyPm8wTfrcHJanl/zGnL JsmNhtDIWz50m/rsW2fD9gVtyiUZWEoWghjDT0t/5PXYyrKpqXXyH2YHgunAvDDfG43E HrzA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694708442; x=1695313242; 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=wfy2YrZ1ljOXcqyiTjQcMN4hDVLaE0ALqJw9LTK92+wG7XZDQDtp/KHFboY3cDejXV WouVS82Xh5RGBNYShXBoxTJnSYYu2njOYHCw+ZgvUun3Lyx4HDfpFSEi8axg0hS38sjR TLNEie/4CNEqFfIN7cIyGY5fc8s679dQXXAe8nMhYyOm0jFysnh7dEv6nqAQYqkvMlSs fdysLENqbgMCL0gtHMqiW76Tq26SIacJro32S0/YIYs/7IeTbjZoKs/WACdhauerRsBT CuniOhQy1Ub8Jj1YyU+zXhQbN8jscc4/W59LJj6iOYblAo3hj+fwLX4au69LRPMUfb5W OB5w== X-Gm-Message-State: AOJu0YxwA4kiJDhmxQLbyrbICgQhvtYEDQE027nH9zp0KfMeczALw4Yv sAtQCmmiGgWUfArovsWlKVk8Wm7Fhp5093+6q4GJoA== X-Received: by 2002:a2e:9dc2:0:b0:2bf:ac97:df26 with SMTP id x2-20020a2e9dc2000000b002bfac97df26mr5198357ljj.25.1694708442643; Thu, 14 Sep 2023 09:20:42 -0700 (PDT) Received: from localhost.localdomain ([45.82.14.220]) by smtp.gmail.com with ESMTPSA id z15-20020a2e8e8f000000b002ba7ae1f52asm346919ljk.0.2023.09.14.09.20.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Sep 2023 09:20: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: [PATCHv9 03/15] net/lwip: integrate lwIP library Date: Thu, 14 Sep 2023 22:18:16 +0600 Message-Id: <20230914161828.3662-4-maxim.uvarov@linaro.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230914161828.3662-1-maxim.uvarov@linaro.org> References: <20230914161828.3662-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 Thu Sep 14 16:18: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: 722561 Delivered-To: patch@linaro.org Received: by 2002:adf:f0d1:0:b0:31d:da82:a3b4 with SMTP id x17csp485593wro; Thu, 14 Sep 2023 09:21:27 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGoOcG6wsBXwtWqX3KKWMlcPhsJorBVXYb46qJFpUeBXPbF7foHxcMuSxC9NJ4fzzypiTQA X-Received: by 2002:a5d:6407:0:b0:31c:7ada:5e05 with SMTP id z7-20020a5d6407000000b0031c7ada5e05mr4850309wru.51.1694708487390; Thu, 14 Sep 2023 09:21:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694708487; cv=none; d=google.com; s=arc-20160816; b=kMY0A16a2s8kzaXgx0KZ51VSCL9n6wpnqkjGlgWrpAncTqLEdMwFajKCeHei9wHiNU oV44SONE4LoDuM3jDcnAiwODxlOv1sBEvVI/qUDSV1BFxdKfMypHRUAO+U8Rvd8Tk+Ho Edgfb6kd4wzRhs5cFfDkmsCF4gnH47zhpMqFHcpNy2EFWx8CPgrLViS5nIGKiZrDf3dS qL9uSd0FxMg7ifKrBhX7qZiIF+1V3L7cCy52pYWqPxaUfVb9FrKOT4rwSV7fpFBUybyv TeWq0cg4Jeh9b1RORE6EM9uZABP6bGXnwZaqVq5Tr3148fBCsh2eid6dafPQyZVQDxcH Mz5g== 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=LUWP4Vp2l/kcF70jt1z+yuWxjmiAQYDKKzCdYrFjBMU=; fh=hYoOR0yg+Fo7S26X8ur5L+RaTmkyxWlAVaBypEC8A0g=; b=TngrGenmT5z6xCA7notfdavkNNL2zOyVwVmUp+eoLEjLlXEh0CdjBdCJ6ckJ/uw3J0 Ex6iz+MeN992MQis++Hk0hBoGJGetsSBv8H9jM84PKKsuDjW9AIDarxS/sp7Sj7apFV4 aLPS+dUc4ADaLf9rNDwKb4ZK9Da/yMi3mGsD75RETkrZ7tV/4EqVCBeLtRdB1IU/bx87 XoxJ1eOhDOLBJd/YEcWw5N7tqCrf24XN1JC25NJlJfVnr65LxoO68JWSco2YvyiBxp0C x6eOT1AKeuu8H4v+2moyc3x8Ne4i1FiPYFe0CAUpqP4IpSkYecxCL73P5dvkqTSr+qha dwAw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=bkO6trnA; 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 i7-20020a5d4387000000b003196dba12f9si817743wrq.864.2023.09.14.09.21.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Sep 2023 09:21:27 -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=bkO6trnA; 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 A357986A50; Thu, 14 Sep 2023 18:20: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="bkO6trnA"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id BBFC886A50; Thu, 14 Sep 2023 18:20:47 +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-x234.google.com (mail-lj1-x234.google.com [IPv6:2a00:1450:4864:20::234]) (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 CCA4286A9C for ; Thu, 14 Sep 2023 18:20: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-x234.google.com with SMTP id 38308e7fff4ca-2bcbfb3705dso18082901fa.1 for ; Thu, 14 Sep 2023 09:20:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1694708445; x=1695313245; 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=LUWP4Vp2l/kcF70jt1z+yuWxjmiAQYDKKzCdYrFjBMU=; b=bkO6trnApQ8vHjzOStkMMkxmbBA+rIOYSGch/J4lTeml5R16vWxi6Ea04GlN5HfzJZ xwN2T2dwPvEH4yz7fOckDtJrb8FzvBp9TebrDNO+c9tNcnKxvmgaQnvx+gF5GaALCTet 38HxCF844cedPYjA+QhxgvIoVx4s+hpV3l/QGiu5f8sOYRZoSiLsIege2m0jcbhOBdZS 50TVFlLDyVDPqOaJIjzSXzZcCvKj3NXllgo0sliPXwEC6BqtQxzzGqUuqaTtqnttVpLq zIY5Z/iOv0xq2arlOou0MbSQ8ShMjOoZESxR916N2/bbpus/ExikCiFEVV9dhFCWfMxY e3WA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694708445; x=1695313245; 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=LUWP4Vp2l/kcF70jt1z+yuWxjmiAQYDKKzCdYrFjBMU=; b=HZDSqsyJlsv2YDsZpA6EBEamD/QxSfC5qFm0eZhsd6Uqp7Tvws71Rn793jsFhvkDeF X4AdPasJxNkbSwTBF+quKMEmMVvD/buXGDbV090sfXQ2TZUhXHkpG5vKPM5Cwn0dQfeZ mrBqQJ++uHYujQPhkD9klD+xFcHuYoFc6WOivPLBelF4Ji3PZ/+MPdrLfNDK+rsJ92TR t7chrOOzmsn1U9Ps7Hq1BHpkwsJFIreNvOr6oC6DDYY8EoRmErRk6KJqYdjMMObcd7uw 0vOc/ctFHKhA9KoeNEqLcf5xwoYBnWuKGgDFdkVleQd9zDr8lhHCp/Rv7bGhT9KONh3o ermA== X-Gm-Message-State: AOJu0YwDG1TwqQFBbqBAs4fFTDG0XGlholyxMNnkV7ZyhePGKAwZkKux TDr59PLNoqfZ+rjGmqzE6j5X+AjjCMjkJarfrEirzQ== X-Received: by 2002:a2e:80d3:0:b0:2b6:df23:2117 with SMTP id r19-20020a2e80d3000000b002b6df232117mr6067969ljg.43.1694708445018; Thu, 14 Sep 2023 09:20:45 -0700 (PDT) Received: from localhost.localdomain ([45.82.14.220]) by smtp.gmail.com with ESMTPSA id z15-20020a2e8e8f000000b002ba7ae1f52asm346919ljk.0.2023.09.14.09.20.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Sep 2023 09:20: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: [PATCHv9 04/15] net/lwip: implement dns cmd Date: Thu, 14 Sep 2023 22:18:17 +0600 Message-Id: <20230914161828.3662-5-maxim.uvarov@linaro.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230914161828.3662-1-maxim.uvarov@linaro.org> References: <20230914161828.3662-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..3ee6e24ef4 --- /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 (dns2env && 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 Thu Sep 14 16:18: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: 722563 Delivered-To: patch@linaro.org Received: by 2002:adf:f0d1:0:b0:31d:da82:a3b4 with SMTP id x17csp485755wro; Thu, 14 Sep 2023 09:21:44 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEFjsNIATr1/Y/ddCpzUc1r4MdnA6Bwy4eYy//tcVyosXMCbqFTdpsuWLkDzT0HD6Sx4hkh X-Received: by 2002:a1c:4c14:0:b0:3fe:89be:cd3 with SMTP id z20-20020a1c4c14000000b003fe89be0cd3mr5226048wmf.22.1694708504257; Thu, 14 Sep 2023 09:21:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694708504; cv=none; d=google.com; s=arc-20160816; b=EVa2nCzf0RtjI3VmW0/cuN4J3JB1gd1lTKXWZhrLzqUhf1WB4T5IVSilHIoSdGFPN4 C5HqLaKm1Ku9Y6MMoNCCpGW2f9NahhiqlBnRf7yaCFeosy/WTrcGsM2YcyYEceng1QVV nZgrx6sH3CiIx9AOxFUBoTjeFadiAfMvVeBpwW/i2e37mJJQ/enjAlHktVlusBDbxXlU 3qW/gn0Kenm2XY6I9f7jNXI1g2vOZMGoXGfEmxTJcTNwlD5vvfy6mhvYj4jSiSEDn00z hz8ssznAkB/ydIIj6pKiGnHQMEN9UXUIM2vbknFIflmRfqQ6iO0+H5ZZf/Hm0Dbd36up DE7A== 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=2TpMV1fzgEaRtklvSF1wLKwOvwOJoWTA7xIFAq1N3os=; fh=hYoOR0yg+Fo7S26X8ur5L+RaTmkyxWlAVaBypEC8A0g=; b=Bgxh0nmNV7ezgrPHK4XyUzWpLB3XUz46fliVfKEjy6mUf8NFqP2SMkdtyqeWutzNwO q1LDVSbjqdmy4bSXHq8F589EtC+CI+qLeUgUsB3h53Q/U21i6wMWVuLAc/uXUXaAvaDt h68r9N9OjXKcpEZZRdyYJCae6Z8vEAvFCqgIQVb81Gh4dpmrIL6MpiI3d2ozYRy+F4FW pAL7A4XaM1JGb8uB7h46jzHJVbkVyDT0Y/pXYV35EJD1D/t3PtSDKVu713hTT+QFLKim YSYZ2FAxXX88CPTGW2xAzKaIYaZ1Yg159dvk/UOIWMzMXgmZHI4KFHSGXl9bi7yVs/j8 OC7w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=ljqCIAvj; 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 i21-20020a05600c481500b003fef351f886si2195648wmo.168.2023.09.14.09.21.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Sep 2023 09:21: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=ljqCIAvj; 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 F1F5C86A3C; Thu, 14 Sep 2023 18:20: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=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="ljqCIAvj"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 2FC9A86A94; Thu, 14 Sep 2023 18:20:50 +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 3A2EA86672 for ; Thu, 14 Sep 2023 18:20: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=maxim.uvarov@linaro.org Received: by mail-lj1-x236.google.com with SMTP id 38308e7fff4ca-2bce552508fso17390541fa.1 for ; Thu, 14 Sep 2023 09:20:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1694708447; x=1695313247; 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=2TpMV1fzgEaRtklvSF1wLKwOvwOJoWTA7xIFAq1N3os=; b=ljqCIAvjmfAO877hZFx1wSImW/qMteKp6WVjgaBio8MkYbztLx2WjxFS8FGYHZ0GJf +ce/dQIN8uHBmX28bUgRZkvQtJ9VsU2CaNih+Ayg+NlGEu+EtsiqbvKSH7RBW6Lrc763 Kn/ZUNYYJABo003yH2CBNrE6C9wAnCP5UUXq33kGdDp7e3IluecS3XU+VBDg8Uqk6rhs oJniavE/eBSESgFo0qI8kyZAx+BYtSnLdyJxhqEfR2Pfc1hCFU4+nW8epfjBtT5tlshP f4C1cFfN6OzRdUdEnSeRiHzV+plYw8x50iJbUUZBc3/JqIRVbHBT0zKxfQ1WLU70vcez M+Nw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694708447; x=1695313247; 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=2TpMV1fzgEaRtklvSF1wLKwOvwOJoWTA7xIFAq1N3os=; b=R4JD/AF8sUp6w6XXW+h5Dp5NP11D5BikiqYBuNq2nwFTMVcLIkRlhqDKsmKW0E6xDL fczia+ET3Y0revJgOtO8DCfUceffBqK3l4G3P64Q7lIvzkLNukGshx2h7KmJ1bSJdNy/ 80BmlMYMyrJlGY+k0fsXD3fJAYpK0llUjuPDouQSXDqHy5Br01XxpYAE4PUjyBoTesGv 612mESI0R4Ev8wxGNjnhwHbWanQIxKQfAde+Ifc81pjHyJDr4i/3vjIjjg99reWbH8X5 lcME+Mjwzc4LDYYb789FeF82FIlSxIuGaMZ1O//gMuhxIF575CVTmXkqJC5bUjoNveWr eiTA== X-Gm-Message-State: AOJu0YyOVAt0gu+X60gKPzvS8TUsBLsbN8XOBR+RysGnn3eB641EZS6S yx6zhPNuqRup480w6nL2aRTFcp6M0MyF6VprKBGlCg== X-Received: by 2002:a2e:9d41:0:b0:2bc:c3ad:f418 with SMTP id y1-20020a2e9d41000000b002bcc3adf418mr5241251ljj.20.1694708447426; Thu, 14 Sep 2023 09:20:47 -0700 (PDT) Received: from localhost.localdomain ([45.82.14.220]) by smtp.gmail.com with ESMTPSA id z15-20020a2e8e8f000000b002ba7ae1f52asm346919ljk.0.2023.09.14.09.20.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Sep 2023 09:20: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: [PATCHv9 05/15] net/lwip: implement dhcp cmd Date: Thu, 14 Sep 2023 22:18:18 +0600 Message-Id: <20230914161828.3662-6-maxim.uvarov@linaro.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230914161828.3662-1-maxim.uvarov@linaro.org> References: <20230914161828.3662-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 | 85 ++++++++++++++++++++++++++++++++++ 3 files changed, 98 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..f0b0e26f6e --- /dev/null +++ b/net/lwip/apps/dhcp/lwip-dhcp.c @@ -0,0 +1,85 @@ +// SPDX-License-Identifier: GPL-2.0 + +/* + * (C) Copyright 2023 Linaro Ltd. + */ + +#include +#include +#include + +#include +#include +#include "lwip/timeouts.h" + +#include +#include + +#define DHCP_TMO_TIME 500 /* poll for DHCP state change */ +#define DHCP_TMO_NUM 10 /* number of tries */ + +typedef struct dhcp_priv { + int num_tries; + struct netif *netif; +} dhcp_priv; + +static void dhcp_tmo(void *arg) +{ + struct dhcp_priv *dpriv = (struct dhcp_priv *)arg; + struct netif *netif = dpriv->netif; + struct dhcp *dhcp; + + dhcp = netif_get_client_data(netif, LWIP_NETIF_CLIENT_DATA_INDEX_DHCP); + if (!dhcp) + return; + + if (dhcp->state == DHCP_STATE_BOUND) { + int err = 0; + + 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)); + free(dpriv); + ulwip_exit(err); + return; + } + + dpriv->num_tries--; + if (dpriv->num_tries < 0) { + log_err("DHCP client timeout\n"); + free(dpriv); + ulwip_exit(-1); + return; + } + + sys_timeout(DHCP_TMO_TIME, dhcp_tmo, dpriv); +} + +int ulwip_dhcp(void) +{ + struct netif *netif; + int eth_idx; + struct dhcp_priv *dpriv; + + dpriv = malloc(sizeof(struct dhcp_priv)); + if (!dpriv) + return -EPERM; + + eth_idx = eth_get_dev_index(); + if (eth_idx < 0) + return -EPERM; + + netif = netif_get_by_index(eth_idx + 1); + if (!netif) + return -ENOENT; + + dpriv->num_tries = DHCP_TMO_NUM; + dpriv->netif = netif; + sys_timeout(DHCP_TMO_TIME, dhcp_tmo, dpriv); + + return dhcp_start(netif) ? 0 : -EPERM; +} From patchwork Thu Sep 14 16:18: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: 722562 Delivered-To: patch@linaro.org Received: by 2002:adf:f0d1:0:b0:31d:da82:a3b4 with SMTP id x17csp485725wro; Thu, 14 Sep 2023 09:21:41 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHguqaYtwmziwtVLKYcS5m9CavqQ4/k/K1ObTO86YPdgSq56ue5pKX8OdXbxjMOwLbdsL8j X-Received: by 2002:a1c:790d:0:b0:403:b86:f620 with SMTP id l13-20020a1c790d000000b004030b86f620mr5224065wme.12.1694708501104; Thu, 14 Sep 2023 09:21:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694708501; cv=none; d=google.com; s=arc-20160816; b=oNIsdEDfaoV5pdJUjDPfMHn8HAGe2RTg4db30BugsjIrynbr+5f/19AxV8ZFP6EJzN luM1bl62kuDmKRQqcmeSqoIqk7IbvRADHrMp6ENrOIjVygkEdCS3/AJFzNjOSh3SLXIz kntYf2uHPgAbLMYEW16OkMjK5cqznrTRFvj0R2+K2JSKe8Avrg+/XfraSQD6evO4Gft4 vkA2+Huradd8DgkhjecdF3kYr1uvdDVpMFGtyrw0f7MziCH/vzwk/SB59ZYdVSDb0RXG 6zHEdl4rwVUBy88cFW7ZpGLX2SDUZFxBtd1tRFe8PokffeHhnn/3fhPCLkyNaVAMQSHr DZjQ== 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=LC1rzNwjkmeiEROge7PliJ2TWgUzdEBLyUtsof2ZFvo=; fh=hYoOR0yg+Fo7S26X8ur5L+RaTmkyxWlAVaBypEC8A0g=; b=JwzU+9yNSU735HbVyzSEt7WHnDB1PKomcAT4RkO8NovTWtihhaASYI8q0biwLA4gHN 1NjdvABzAjuU0tQNDwWwF/fGGdOD41t5HDjmCGLRxHrVrEx/TAKA4J7fEGS7kN7TrQ0i NpJH5AgFzOhXdncvow6RB9oYlPm8i5UbXACPft4nUAe4c6PXm0jEDo09nRjM77UTvrTI MCHG/nZ+VIusYKO6KSnjgUyPvEt/3hVsBaHwPRylJm3bPq6ZY0++NxaXuzGH3FWbjgLW gUaSlTbAsz1vqQK76FAKWouwutQHDpPDbl3CL6kYpVWy23o6Mn6nMKebkWzujWGsXJBH CvvQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=tRHeWu1w; 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 d4-20020a05600c3ac400b00403045af3cdsi2232592wms.163.2023.09.14.09.21.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Sep 2023 09:21:41 -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=tRHeWu1w; 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 52D1686ABB; Thu, 14 Sep 2023 18:20: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="tRHeWu1w"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 8930B86AA9; Thu, 14 Sep 2023 18:20:52 +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-x233.google.com (mail-lj1-x233.google.com [IPv6:2a00:1450:4864:20::233]) (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 8AFD786672 for ; Thu, 14 Sep 2023 18:20:50 +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-x233.google.com with SMTP id 38308e7fff4ca-2b703a0453fso19032281fa.3 for ; Thu, 14 Sep 2023 09:20:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1694708449; x=1695313249; 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=LC1rzNwjkmeiEROge7PliJ2TWgUzdEBLyUtsof2ZFvo=; b=tRHeWu1wmx7am4gNWgl557BjAHePAxsh7xC9ngNwj5HoqZDLbdL/fv4OKTK+WqmycQ 63x4UZRSNvOlbjfzkHIG8obXZrj4l3RkXZG3vwkhmUlniJSiKLU36JC3wWo4s8fxiCVv sliYzxaWZsvRRP77rMWviERvyhFClYgNmYzxP7pcbG3soNA/6WRZ5seQkhpQ2+PLBjYy Yyn2ehmjS2s8Wy6xp9M9JFE3gUk9eRg0wtk8gMoYzHq8jtQ4TxANT2qDJdIHeh5xUEw6 y65eFEBDwoIVct3e8g9qBnvecbX9N4SZJiglQ5eRqSsgF1fSLi/v1z8Knkn95MqCLCUu kykA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694708449; x=1695313249; 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=LC1rzNwjkmeiEROge7PliJ2TWgUzdEBLyUtsof2ZFvo=; b=UQ5bY4YYHy98oQUrsLIjpgaBfkGOiQuZIjKqewZwosPTLOJeMB1d6v1RNEMsT2mWU3 xgMj/Y2AtwMlgKIz77WoyBU0QBtvreOpV8Uqi243JkXjRD1V2mBz9k5ou8iV1FXG6uYR dm7BJOSOL7V60jMpcbLIEP9e8om2gf0zvLWdM1FPk1wA03+lIK6LrpUf9UsqKV/yPFwk Q5PSFsHYDwVQ6Oa47njsZSqLro4fY36zw0ZyL99GdKYF22YL+A1ccjD547EWPkkJQIaX ziobSJOBkIe2Cf6pg9zxyk83rRuXmcaHSxo6Nsev2HbU9+2OeaSuoWeYZDRQjnlHROS7 jUmw== X-Gm-Message-State: AOJu0YzHzomSOJzfQ5Hzaa9UNeSk9bZJsjHlbS7ZnfhKBIP5ZtRm6CtR YC9x/JvNsf1LojWMlMQDGAfQM5/P/nCn0PfuJoJoyw== X-Received: by 2002:a2e:7c19:0:b0:2b6:bb21:8d74 with SMTP id x25-20020a2e7c19000000b002b6bb218d74mr5365865ljc.1.1694708449674; Thu, 14 Sep 2023 09:20:49 -0700 (PDT) Received: from localhost.localdomain ([45.82.14.220]) by smtp.gmail.com with ESMTPSA id z15-20020a2e8e8f000000b002ba7ae1f52asm346919ljk.0.2023.09.14.09.20.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Sep 2023 09:20:49 -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: [PATCHv9 06/15] net/lwip: implement tftp cmd Date: Thu, 14 Sep 2023 22:18:19 +0600 Message-Id: <20230914161828.3662-7-maxim.uvarov@linaro.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230914161828.3662-1-maxim.uvarov@linaro.org> References: <20230914161828.3662-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 | 13 ++++ net/lwip/Makefile | 1 + net/lwip/apps/tftp/Makefile | 7 ++ net/lwip/apps/tftp/lwip-tftp.c | 129 +++++++++++++++++++++++++++++++++ 4 files changed, 150 insertions(+) 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..11389bb038 100644 --- a/include/net/lwip.h +++ b/include/net/lwip.h @@ -29,3 +29,16 @@ int ulwip_dns(char *name, char *varname); * 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 Thu Sep 14 16:18: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: 722564 Delivered-To: patch@linaro.org Received: by 2002:adf:f0d1:0:b0:31d:da82:a3b4 with SMTP id x17csp485789wro; Thu, 14 Sep 2023 09:21:50 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGHAtifA2y+GrvgAO8Qgle9g89LlDm/gNps5YyOqpepQlcaPzevM012XE/JyM5A1sH+p6Mk X-Received: by 2002:a05:600c:24c:b0:3fe:1548:264f with SMTP id 12-20020a05600c024c00b003fe1548264fmr5148517wmj.22.1694708510560; Thu, 14 Sep 2023 09:21:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694708510; cv=none; d=google.com; s=arc-20160816; b=GFhsf6foed6DUmGYt3aJYVTULMP1/Rbj5JP0UTaodX0SgjGRR9mxyWC8MfGm7ac7HC EjqrS6xry73yReSi7lVUXbkaAykN+brihhZLEXOPrKQw6T1rZ7Jz2xpGW0+eIxcKeZ1Q hmZW/9OsM656Rui0miL7V3DVZm/gSBsFLpDtMoGaB2cOzmtpoLF9fUVp5T8ZbPhDe4sE 9bbYdomu3C1d3iH17vA2KIV9Y6KS+McxqoJ44wOdLZy7R+9+Zo/wr3w8H42MlsQT/GPi 77HUaZMHL5QDpqxohit5b+cp3EWbdV1kdOo9Ye1TBP29oQk8yfGz5cN6bhCAhKfFs7cL zCgg== 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=PKZJ9HOZxIBTiLch9aEDpcZKIBMQWo/QAQDhGkXMw7E=; fh=hYoOR0yg+Fo7S26X8ur5L+RaTmkyxWlAVaBypEC8A0g=; b=eo5yPomS2clviv6IxrVANeSzAIwulsdWespyI3O76D9OSwCNH7vzJkyeoAdDU9we+S amkl0JbOZrBkN37kKHzifhPFce4soTxlRpiqlqs/f/ItdSxCAj1CZ8oF5oxt8hOqbAyQ KGQtVM2HP2FU+kTBg3yAq18if88V/RIgwsZNcG+axUFNNpvQ+KV05CD0L5LXLLVEEit4 3QV3I2CfMTzIHgc5kzqXHm70VLqybDWf/uFowJj+DswO7TMtFX6n+Z1nXeVAbirfJd3+ lPwHfMOjHEV4oSPf2SVFmIC3f5zjvTh/X2e2ob2uMrypBSZ+dZHiJA5NK+hOrOAKGgtt 3tJw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=xOJTY1oy; 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 b18-20020a5d6352000000b00318f7b655d7si798037wrw.700.2023.09.14.09.21.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Sep 2023 09:21:50 -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=xOJTY1oy; 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 ADDC986AB5; Thu, 14 Sep 2023 18:20:56 +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="xOJTY1oy"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 2DC8F869BC; Thu, 14 Sep 2023 18:20:55 +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-x22a.google.com (mail-lj1-x22a.google.com [IPv6:2a00:1450:4864:20::22a]) (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 2F36386AB5 for ; Thu, 14 Sep 2023 18:20: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=maxim.uvarov@linaro.org Received: by mail-lj1-x22a.google.com with SMTP id 38308e7fff4ca-2bcbfb3705dso18084761fa.1 for ; Thu, 14 Sep 2023 09:20:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1694708452; x=1695313252; 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=PKZJ9HOZxIBTiLch9aEDpcZKIBMQWo/QAQDhGkXMw7E=; b=xOJTY1oyzb/z1gIN1S3U1+zEC67MGf0lrNFuopB++NZ4qVADYErZW1gpO5wxAKyYMh he9FK+y1gp3FCmJwUND8l/O7P4uIbFmtNWQv+FFzXGbAZ+iMhtKSQd0ugI5QZV3jv0pu lLr7N5wgXp1oqRdXVMRa+7sc8ovpqrsd93CsgqQJftZPgOcGf7Hs8yAl9bgDQNs7xpPP 8xCCEwCkzc/uZDg9kKqKExEAEXYhAOgtEW4LE61sNEFU5otIo2Q+Hmqd0qZKVujAg2JI xZVSOJYkYGm7mbYcMbkdxr9Rx7aVTz6ixtiitd7NyrzhPKHnCg0V5VpzaeDJUsK8mhQM UlDg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694708452; x=1695313252; 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=PKZJ9HOZxIBTiLch9aEDpcZKIBMQWo/QAQDhGkXMw7E=; b=C1IghAvaJNqdDIhxczudlSrTsmuLnl3hpDbD63nLyEFxq7meLXWRNUY45hT2EgEBVq dyhogL2v0tAVPdW23W1uYnr8gORXjxChVKZx4yLcvKilCqbLZwIknmz8mOmn/vMX5P6H za5y5Bo9+Ud4EFJ/mx0J5qwFnjLzqtuW4XNmUHb5/beMxIvCCyuOprgrutdc/rCszqRF bgGO6VrqnE8kUypO6CzcRpOprkUDN267ECf5p+uhb+1gv5w+3tEMEBsmdDMMfMyoi5CV LpjE6sDSND5PrVLz0it7hwBYlvnilbRDzFAEzVMVmHGBy6qg8ae6QpA1LI8i7ZF0of15 8LaA== X-Gm-Message-State: AOJu0Yzl5+sADTCtJbzKVNCJ91twA4VKd8SxR9GK/21cFZ7dgwgliLJK OquR9yN7n0w+WrzhxdRMoH1/h3hrq5NJS4Mw/3rz0A== X-Received: by 2002:a2e:8ed3:0:b0:2b9:53bd:47a7 with SMTP id e19-20020a2e8ed3000000b002b953bd47a7mr5293350ljl.30.1694708451941; Thu, 14 Sep 2023 09:20:51 -0700 (PDT) Received: from localhost.localdomain ([45.82.14.220]) by smtp.gmail.com with ESMTPSA id z15-20020a2e8e8f000000b002ba7ae1f52asm346919ljk.0.2023.09.14.09.20.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Sep 2023 09:20:51 -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: [PATCHv9 07/15] net/lwip: implement wget cmd Date: Thu, 14 Sep 2023 22:18:20 +0600 Message-Id: <20230914161828.3662-8-maxim.uvarov@linaro.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230914161828.3662-1-maxim.uvarov@linaro.org> References: <20230914161828.3662-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 | 14 +++++ net/lwip/Makefile | 1 + net/lwip/apps/http/Makefile | 6 ++ net/lwip/apps/http/lwip-wget.c | 105 +++++++++++++++++++++++++++++++++ 4 files changed, 126 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 11389bb038..85f08343fd 100644 --- a/include/net/lwip.h +++ b/include/net/lwip.h @@ -42,3 +42,17 @@ int ulwip_dhcp(void); * 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..d82d450c0f --- /dev/null +++ b/net/lwip/apps/http/lwip-wget.c @@ -0,0 +1,105 @@ +// 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/url */ +static int parse_url(char *url, char *host, u16 *port) +{ + char *p, *pp; + + p = strstr(url, "http://"); + if (!p) + return -ENOENT; + + p += strlen("http://"); + + /* parse hostname */ + pp = strchr(p, '/'); + if (!pp) + return -ENOENT; + + if (p + SERVER_NAME_SIZE >= pp) + return -ENOENT; + + 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 Thu Sep 14 16:18:21 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxim Uvarov X-Patchwork-Id: 722565 Delivered-To: patch@linaro.org Received: by 2002:adf:f0d1:0:b0:31d:da82:a3b4 with SMTP id x17csp486022wro; Thu, 14 Sep 2023 09:22:16 -0700 (PDT) X-Google-Smtp-Source: AGHT+IF6A06C3DDyhhSd0I2leIZfhfKDYsjbW0rkDGrtyo7PuhM8+r64HlyRoVtzBLYhXTe0rRRN X-Received: by 2002:adf:e886:0:b0:31f:b138:5a0 with SMTP id d6-20020adfe886000000b0031fb13805a0mr4873986wrm.48.1694708536270; Thu, 14 Sep 2023 09:22:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694708536; cv=none; d=google.com; s=arc-20160816; b=e4kmrn1mNX+b1kD/2kFjjRpm1Yggd9KnaO449D89EApY78wBb9+NW7PCFKhN4HuVLw ueYirWEtVbwM45lirsOPuof2YJaog9uNaDKcZsbXrUbT6hlAO0EJmEmhB9WNaIdQoNzC BjUm8Z6W1hmK5r/eeWfZbg1OcALa2dXzaM13xWf1wl5HbH9+iQOJdR7jRI8ydn/FvNJd sUxgJiBvYhpLnMB6IQ545UYk5K6f5nDhEppbB5A5vaN3zb3TB/hFmwsFyTtzw8wlszmr UOapThWrm1ZojWf6HAgV/H/BhhR2LyZ/L0Y9hPxlHIfuxwbu1LMoqYIdektZZFiD2HWO obsA== 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=Ej/bqt+mfyHFFKJj2NMu41mYOCWSZiMsqtww6RhsVjY=; fh=hYoOR0yg+Fo7S26X8ur5L+RaTmkyxWlAVaBypEC8A0g=; b=zV+F9XfACqQbEtdiR+syJ3eN6z3K0YLJHl+46tq13zj8GJLzzxrZZQXIA4MmXT9dtl PXkEMLxtHWYko1RiKrMfQfdDai9Us0VUWAmnC3JO+dcHNr2IqL1bCxo1Dxo4QW7OG5Hv 6D0XIfzrkrd+qfrm5R4iQ8oO/nPCDrGsYVo34EdkqairnSt5+X6zgnNErgb8LHnWB6wY l1n4HGZcXfyuoFVRUih5/+XR5ldoGpupCjM87JjIV2VGxUylmPw8waIETUQ7DFi5h11y eOaE05jD6wYI2JrGY/UWJVc3WW40OL73b6XOXHWjQsWO62vJUl+CN+WRNDFOSWutGofX fFZQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=L1dFDGKq; 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 z4-20020adff744000000b003175debc21fsi806102wrp.723.2023.09.14.09.22.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Sep 2023 09:22: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=L1dFDGKq; 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 0CC3286AE9; Thu, 14 Sep 2023 18:20:58 +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="L1dFDGKq"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id F414886E6B; Thu, 14 Sep 2023 18:20:56 +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-x22a.google.com (mail-lj1-x22a.google.com [IPv6:2a00:1450:4864:20::22a]) (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 EC75086D45 for ; Thu, 14 Sep 2023 18:20:54 +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-x22a.google.com with SMTP id 38308e7fff4ca-2bfbd7d49e7so18458251fa.1 for ; Thu, 14 Sep 2023 09:20:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1694708454; x=1695313254; 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=Ej/bqt+mfyHFFKJj2NMu41mYOCWSZiMsqtww6RhsVjY=; b=L1dFDGKqXvvQs2ObFtoJaLAjRY/ezg9h1vwo5JXYF/z05JL8MOtZ4J5p7UYiLZQvPl fhkULb9+iWFnOI/JITgtXgPBX7seW1Yw19OXMYIM/1I1XIHG+UQUdxDZMSbb1d8GNWnV zm7O74PhRdRjV/8KVx/4FJ3m1t7pKgq8Gw7YzbITBnWy7GlRAFLbHI+FqwGGZmXJdNO+ mamtc1Q6vlstLJ0fLOMnwGX3bqCCOZScWUbMUHZGx3SbRiIyQI6uwgWn3w+08ZMLkPZK 5tvf9AOxHSa6SsjFa0qJyOqdL2ja9WC9LhNczik5pd4MRuUl8cKL2gNc2uXUkZ0x4hHm CIGQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694708454; x=1695313254; 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=Ej/bqt+mfyHFFKJj2NMu41mYOCWSZiMsqtww6RhsVjY=; b=ufjkT/seEzT9V5rDk7h1m3yaIu1vD3uIl/rgz+/FTf2xoJ9IY0hSdtd4dKl7kbmMHo m9DI0swoRMyfEgoZC/YGKY8YGkGm2/9Zlb7jGYt962h+rJO5O4Keo8Up81wsct08Xe9s 2jETOETTpoxJtBPw/vmNgq2MPRFSGxxaMP3pzm8EZ1Mnxg/SuQiQ+8ed539d+UQ7TAev ZXjnYoiYtkAfEsOBBGRyorFI8CEFj52OztTGfOuPQpkT+BdY4eeGOtLMJEfTF2f8MlWA m/8FtWovi8dN0yBrybwD4VRAGDgPpLuouW2LJL1SqqHHAkiJM1lUESpOoEOp4pzuNWgt ia3A== X-Gm-Message-State: AOJu0Ywe725GY9FK8h9lcdXkeV+2YCeeutKt6GpOScQoQ31Oagi5yKIB xY84engcOjc+HvOc0P2X5sxGE87MtO3S6fske36/ow== X-Received: by 2002:a2e:9f4e:0:b0:2b9:e831:f16a with SMTP id v14-20020a2e9f4e000000b002b9e831f16amr6140183ljk.26.1694708454104; Thu, 14 Sep 2023 09:20:54 -0700 (PDT) Received: from localhost.localdomain ([45.82.14.220]) by smtp.gmail.com with ESMTPSA id z15-20020a2e8e8f000000b002ba7ae1f52asm346919ljk.0.2023.09.14.09.20.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Sep 2023 09:20:53 -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: [PATCHv9 08/15] net/lwip: implement ping cmd Date: Thu, 14 Sep 2023 22:18:21 +0600 Message-Id: <20230914161828.3662-9-maxim.uvarov@linaro.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230914161828.3662-1-maxim.uvarov@linaro.org> References: <20230914161828.3662-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 | 38 ++++++++++++++++++++++++++++++++++ net/lwip/apps/ping/lwip_ping.h | 15 ++++++++++++++ net/lwip/apps/ping/ping.h | 19 +++++++++++++++++ 6 files changed, 100 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..8e74b0a05b --- /dev/null +++ b/net/lwip/apps/ping/lwip_ping.c @@ -0,0 +1,38 @@ +// 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) +{ + log_err("ping failed; host %s is not alive\n", (char *)arg); + 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 Thu Sep 14 16:18:22 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxim Uvarov X-Patchwork-Id: 722567 Delivered-To: patch@linaro.org Received: by 2002:adf:f0d1:0:b0:31d:da82:a3b4 with SMTP id x17csp486177wro; Thu, 14 Sep 2023 09:22:31 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHixlcoTOkjkEcUKXnOEiRFOTBP7c/Kt4YsxDuoygK740j7Mt+pfK8vanDIct5kGxQEIwiS X-Received: by 2002:a5d:58d1:0:b0:31f:e5b8:469b with SMTP id o17-20020a5d58d1000000b0031fe5b8469bmr1485866wrf.19.1694708551276; Thu, 14 Sep 2023 09:22:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694708551; cv=none; d=google.com; s=arc-20160816; b=SEnz41J5iUXbrZC/o21KFfQgENtbZQ5IJRHNoPagqPf23HK0bNFaNW+iFbAA8QE4o5 q6bNFnX7zGwiYAyRr9aoaegkQEzyeOBsHCnHJPt/Cf31WbHrFZ8pgScIGFLALPx1otf1 XnLHaJ8rxKB3hXHp7hoGGpuN0Gc+bihY+UfctvdgDRTx9lTRldn/liaLIdlaXq4qNS1q AxdwD4RxZ2xj53e5eN74EUk4gewitFP8saecI+OfIuceUC3ZrwpHKFkQdu3B/WjYu4wu 76tUaoZFar9B60TU/oRm+szTP3ddid/Vfp/3X+i9T1XvyI7IM/lz/qOYaTbMmGc77pbf Mc8Q== 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=mAdOYSO6BAajf3/aQM+qwQ+weu6p1dY8pDD9XI7c6XFbX1XW+1BDTUtxE7dkUBzTPu XsjVKvFD8PY2WdTfVLci74srmWTf8kSKpgIGaJaOX/X8mgavl6vCWS9AAM9e2TbnCJ3j +Axb1ZvQmoBJdIISP41AmBF4pwi1FFFXYx+hzIcwpw8FfXPi8iiw4zdhaAXibCJVrbcu kdiypj8OVETZeKhJkoJwnVupwr6OBrmEzafClkEE4rPj20x0BTrcqJsc+G+M2fa3OuaY p+ihzb1O36l7GLIssUxTC4q3XLLURJWpFs7KEjzmuQXywdU9VhGnZ3sUMiQv8BzrgI/c 6t+A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=vFCJButw; 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 v9-20020a05600c214900b00401d86746d6si2202234wml.152.2023.09.14.09.22.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Sep 2023 09:22:31 -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=vFCJButw; 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 631AB86AA9; Thu, 14 Sep 2023 18:21: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=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="vFCJButw"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 4CF07869BC; Thu, 14 Sep 2023 18:20:59 +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-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 54EFB86672 for ; Thu, 14 Sep 2023 18:20: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-x232.google.com with SMTP id 38308e7fff4ca-2bf8b9c5ca0so18415411fa.0 for ; Thu, 14 Sep 2023 09:20:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1694708456; x=1695313256; 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=vFCJButwgtJkPkhoU1zRy3E9A6RlineX4cCw6Awc+FMeKwQ2xR0ZBFpHHLB2UIf7CE 9c/9V+oof8zJaSSur7xdJFldTwaW5mUmXgWOGmu3GMzU6FOU5eMVJK5dH3GQsxmGXALh prT/j6hhwlxSOrqQjbltryoDv1XLRDflnvLtRcpInqf5idvP0GOo2+Q0yuZVkNQzOLEn sXoGYvBvmX2UdaN7Mt+DIjor+TvmgKoUGP5l9j9AAW+purqoifsl7ys2l2qnkACJHiXE fRLHRpHJkWdssXF3RgZnQNqSt5A6cWtH/czqf45xild244k8fO8FxnpeZFkvc7n1EMc+ YJCg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694708456; x=1695313256; 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=aMGXsqODq1FuRyA/YdzrpWc/HzabYh9apHSNyev+GATg5NLHBw9LIug0JopQ6qwGIk X+dFiaq5cxHsSFGzT4GCWUmL6VFwNKIser8Hw0N6Q8SIDedEWRU7xPREKNUJPCfL/lf6 v7Akz9rlBSdvc3sbwNXuJXcrcBWFIz+laYQgt+kmQ7CZYZu0BzE0wtT47vYNNlipFXQG Rft/H53+jz0Xt7QlNwmNO75iG7zwQB7SzNSiagcAEudelTkGuAKEeW1YZW7IyffgR1i0 4OSvjC19zj2qbgpoIVitI1DMEYmZqsdiiKTRmEkWSP9maOPfhiXtsnyqwDw2d7oYAMi0 X+sA== X-Gm-Message-State: AOJu0YwyWyU3XUtKfz6dL90PuQO5M9Y3mH/fidKF4bKpEGDOeNjAfcyn 6mPtKZBVXjGmnz/1Y/ZGjEFNH0ZPh1fOi4IVsVnqyg== X-Received: by 2002:a2e:9f06:0:b0:2bc:f78a:e5e0 with SMTP id u6-20020a2e9f06000000b002bcf78ae5e0mr5612254ljk.43.1694708456484; Thu, 14 Sep 2023 09:20:56 -0700 (PDT) Received: from localhost.localdomain ([45.82.14.220]) by smtp.gmail.com with ESMTPSA id z15-20020a2e8e8f000000b002ba7ae1f52asm346919ljk.0.2023.09.14.09.20.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Sep 2023 09:20: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: [PATCHv9 09/15] net/lwip: add lwIP configuration Date: Thu, 14 Sep 2023 22:18:22 +0600 Message-Id: <20230914161828.3662-10-maxim.uvarov@linaro.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230914161828.3662-1-maxim.uvarov@linaro.org> References: <20230914161828.3662-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 Thu Sep 14 16:18:23 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxim Uvarov X-Patchwork-Id: 722568 Delivered-To: patch@linaro.org Received: by 2002:adf:f0d1:0:b0:31d:da82:a3b4 with SMTP id x17csp486286wro; Thu, 14 Sep 2023 09:22:43 -0700 (PDT) X-Google-Smtp-Source: AGHT+IE5GmCyeye1x1rU+jE8El9cJuTgIOOQ27VHclKZhbeA6W6v6AZYUKhZNcruMNSJJ+t9BPsf X-Received: by 2002:adf:e7cc:0:b0:319:7471:2965 with SMTP id e12-20020adfe7cc000000b0031974712965mr5889330wrn.21.1694708563249; Thu, 14 Sep 2023 09:22:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694708563; cv=none; d=google.com; s=arc-20160816; b=IK5bsCALCg5gAkP85GgHPweINR5Mg05C508Jo591NGkCyePtFl94hNOt4FiXUT7pcp G0zXyzBO6tO+mDinEZzVksZaUkGB5iHhr3poMb2T8zaTaOJyDOavjVbO+zqQOtKctmD/ +vvPOlu/nB31w1Ci30sl/abJmOxXTY2RcI1v5PkHHRX4pXWbjGWOJSDudK/S66DXf1YC 8nfaur67SUHTwzHvueKKEBknxgi2MRxfC7g6byqcqqyVouTMde220PRR84N2K6gbWfzp LkXc78UHL5/HvAr/xpM2RsKMG54p1t+GZHtaxDKSiX3IZoksId8SkUYKH0XI5iHSW/Kr iPVw== 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=V1RnU8OZSAxmHhsVjdL2Xu5rqq2oZh3prIU+7sKSXEx7xjq7KqySLw2ycMfTG6GUwz 3LWPDMczWnLbohJmoHSA0fwjRW4J8/k337L8UrPCx+VGATzb/t4EL2oVPmi6B8fJfQHk ItOWJti2Z5ez6D2VIuTCjA+GiPS7EAseRERsMy2/s0Q3XuJIvKln7fM54pZ2Mj2zHMZ4 sST8a0DP0H/nIXMxUeYAohQl/62M2LLoNsk3ZVV03ua5JZa2b9QFL62PzO/cr5JrgXp/ i5YI8UjviAn2eYtI74uZ3YTxx1iZleljONwc73gof2dip8I7m+XL9lNqrdAurwLlgs4m WkpQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=UhaPVwEz; 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 n8-20020a5d4208000000b003179af7ac77si813560wrq.257.2023.09.14.09.22.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Sep 2023 09:22:43 -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=UhaPVwEz; 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 B8AAC8706C; Thu, 14 Sep 2023 18:21: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=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="UhaPVwEz"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 3625C86E23; Thu, 14 Sep 2023 18:21:02 +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 0C5DF86672 for ; Thu, 14 Sep 2023 18:21: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-x22d.google.com with SMTP id 38308e7fff4ca-2bfb12b24e5so18323121fa.0 for ; Thu, 14 Sep 2023 09:21:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1694708459; x=1695313259; 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=UhaPVwEz8jXx35vOH4f0Zcy51XR3PQIJ+Nb7M7VYTEOpH4jnf8kNtXJQdiXaVI2t5m Gx1R+qTZoh/s3aa6jroz/ObKE9D+g4uaYU7PdM4PFHJzE0eXVu2DB03LoLbLImeO+CZb xfEV0TIViNmqxEYBZshX/gjhjXCeKJCibyYau+eZmW3QHt7aSBVg/pvar8uqB0aEkqqu C/97rxlbj2lCX+LUK3KYyH09SC0RbIrk3432Gadeu6wNTjaexib851LRL/zzi6zG6Vzo Nz2gYPMQc3jogisOy3tBL3cfgeUPjd/rF9X83U0yOcP0rGdxyRaCMtEbhX0ddFfL8LqL mY1A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694708459; x=1695313259; 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=QZ7suzQ0vDuY5FfCC/z/yL+bQsqZuKXlSqt2vLqd48mcNhXNbNWXNm3ApI8WhaFX91 IZSuVYryQEYZQYAxCgQQZIrtsYGGup38vL1AM29xspH6g/c1bE+Kk5GDBplAJdSJ2QdO 3xTzktLlI5eAIFYrA+B7mdNGZTVKtg1KjvJbcn5wzgClOPCyeEj0segzJh2YSq+/S93U EMFIck6Lj0u7aD+nRNo1mYCB+4gTsMQi2LOzIsBBt7YBBsczsE/5k/S0mFWnGz2rlJWj Rs8o+bm7dSXiL6WBNGwDNtBDhY6FJ/4BwbfmOpZ5mDlzALzG/MkVMqAaVmKvYAZb4ATP ux4w== X-Gm-Message-State: AOJu0YxtNcamCk6a9jZeEZRiGAx5X3d+SfDaxPFuDkEgZXE6yZwxE9/P cmvnTOEwHodoIvrvDGFwsi1zIHkWcZTHjC+VV+cW4w== X-Received: by 2002:a2e:9698:0:b0:2bf:ab17:d48b with SMTP id q24-20020a2e9698000000b002bfab17d48bmr5258604lji.34.1694708459032; Thu, 14 Sep 2023 09:20:59 -0700 (PDT) Received: from localhost.localdomain ([45.82.14.220]) by smtp.gmail.com with ESMTPSA id z15-20020a2e8e8f000000b002ba7ae1f52asm346919ljk.0.2023.09.14.09.20.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Sep 2023 09:20:58 -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: [PATCHv9 10/15] net/lwip: implement lwIP port to U-Boot Date: Thu, 14 Sep 2023 22:18:23 +0600 Message-Id: <20230914161828.3662-11-maxim.uvarov@linaro.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230914161828.3662-1-maxim.uvarov@linaro.org> References: <20230914161828.3662-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 Thu Sep 14 16:18:24 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxim Uvarov X-Patchwork-Id: 722566 Delivered-To: patch@linaro.org Received: by 2002:adf:f0d1:0:b0:31d:da82:a3b4 with SMTP id x17csp486176wro; Thu, 14 Sep 2023 09:22:31 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFDSc3T3XxoJYi5c0GxZSzwxTj24uGbR7IkeSvlKmAYHhaXJhr/e8mNCrD+S9uv5pkJ//Ra X-Received: by 2002:a7b:ce97:0:b0:401:519:c5 with SMTP id q23-20020a7bce97000000b00401051900c5mr5174628wmj.41.1694708551126; Thu, 14 Sep 2023 09:22:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694708551; cv=none; d=google.com; s=arc-20160816; b=r3WjexLsEpfEs6bCZPoJOTmuCHfWno7l9vbL8LxNrYFEY+7tb7qMZ2maNyHP2bO1+a qcaKSFeyNxnm6kdxjJd0bohyc5H7Zn7sARPDeTwVESvjvqVIXWntVkeVitDgsFT6YqM9 88oMjRsIb7op9kzUaLQdz0ZbzaVDdVHUKfVqjAfrVLaB4lXJ4z/upQrIP37+QfU6UPeH M8VxtuG3s81xz1RnwtfqDtkqqOBaihYLbKz72Uv3xCGlD9QAjnDQa7P3GAFcTGVLjFzK Umz+NM7DXccsTAs+O/VobRWcuj0SdASS+ptwz0XMWoYUQib7cio5jXLgPsMotT5pQzqg 7FiQ== 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=DKnjSygXhub0n7HcV34uxoNH5QG6iRU+OaDzQi3Rg5c5sFF1hyMRutg3Tf8RJYcM3N esfnFFmNacbEaT/aVx74bHtKdMR06+R5epTVeC8llU0j/p2UscINkdnBE/bnzYMMCjFJ NHt4QH+5UPutgXMCTmvD3aX7tA6aY4UbPLptfhZRUj0NPqnkHyHGeRNiZ9Pw1N8Fj7Xj 4uVedriMFbrnsJ89J/hDifKaQZ4mVeuu/Xr29otiFb4Ey2sWzNJgz6Dj+qZY0GBO92FL UF8BU+eAogwELFYzZPm84k7h4MaFsXY0PVFSfaBmSJ1Jw596CttO3b/K+IqwM2Ouo/Oy IwLw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=QsOJpp44; 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 p22-20020a05600c1d9600b0040477f8f8adsi39277wms.126.2023.09.14.09.22.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Sep 2023 09:22:31 -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=QsOJpp44; 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 16DF9869AC; Thu, 14 Sep 2023 18:21: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="QsOJpp44"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 1F2E387071; Thu, 14 Sep 2023 18:21:04 +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 3F7EE86672 for ; Thu, 14 Sep 2023 18:21:02 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=maxim.uvarov@linaro.org Received: by mail-lj1-x22f.google.com with SMTP id 38308e7fff4ca-2b962535808so19086941fa.0 for ; Thu, 14 Sep 2023 09:21:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1694708461; x=1695313261; 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=QsOJpp44qTLVg2iIUr1aiqkyGWo1RsSMz2AtoZ1SFIp5J8fFwEgyAPel+gUhrntAvH fs7IdA1q/G9tNUCMx96i6KT8QVuMcZ73lNppooGTV7V0sHe1i5PEHGf5rt2KNW/RFAzh fh/wGE46b/rzrgVZ9ipezi0Kqw7DBNK44M7ALUCGoGb4yteHUsj5YRHVfIH0/znTsKLA +p4dj/qyvw6F4YygQLfijLjrP9lajaUZm4wFbBnZNgcNsh0hWiyF5k+9MSO1cLMSborC ehg/EVwHO2YBHOxeUnXGtjFpJqHgcYYHY5ehYbviwMnwsxK0ILy1CGT/JravtBsJuXX1 rz+Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694708461; x=1695313261; 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=g+hR4jeHYtG9IMUqXkDg15DFMa0DxTpJFJP7dmiJTwR30GtBFhNTm1Hg4Q1Xtg+4mC LIJoMhD2E6g8NhBWlSVU4nJpbgLFKgOOpaMqVOyb+9UW5l/ucIGer/ZwsP1i7R1iNIsR PAb6fTbtOuDlMmYaK4+d/tBgELkq5YshsB2ssTalHrxwyttLSxlezawYJ2bxi/2jfVrt NmjzG78Yd2giO4/B0S409MAvb/4pmiA10Wkscs/8liuriyQOiBUQGfpx241VXfYdBM6b zOsWmxaVYt7JDP/jTSbVppqSaoMUUZhxAcYyofXIydkAnl3HHBfIzDYbz/YQatHOjzI7 JNlQ== X-Gm-Message-State: AOJu0YwV0YCshT2j+oXzt9RSYxXZdpDkVJtZKw3frMP5WarIObhG7ube SoxCIOPXdPSYg/xRfpOOvBccdcRxHdCxlKu52a7x8Q== X-Received: by 2002:a2e:9d95:0:b0:2bc:bef0:8612 with SMTP id c21-20020a2e9d95000000b002bcbef08612mr5818528ljj.23.1694708461337; Thu, 14 Sep 2023 09:21:01 -0700 (PDT) Received: from localhost.localdomain ([45.82.14.220]) by smtp.gmail.com with ESMTPSA id z15-20020a2e8e8f000000b002ba7ae1f52asm346919ljk.0.2023.09.14.09.20.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Sep 2023 09:21:01 -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: [PATCHv9 11/15] net/lwip: update .gitignore with lwIP Date: Thu, 14 Sep 2023 22:18:24 +0600 Message-Id: <20230914161828.3662-12-maxim.uvarov@linaro.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230914161828.3662-1-maxim.uvarov@linaro.org> References: <20230914161828.3662-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 Thu Sep 14 16:18:25 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxim Uvarov X-Patchwork-Id: 722569 Delivered-To: patch@linaro.org Received: by 2002:adf:f0d1:0:b0:31d:da82:a3b4 with SMTP id x17csp486293wro; Thu, 14 Sep 2023 09:22:44 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFKeMTnJGsVfAzglYOzDQzZz61/W5sR1BQjb+BpG90yH0ERABDV5jILKALDhtep2jdGybCK X-Received: by 2002:a05:600c:2288:b0:401:d803:6246 with SMTP id 8-20020a05600c228800b00401d8036246mr5447184wmf.2.1694708563885; Thu, 14 Sep 2023 09:22:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694708563; cv=none; d=google.com; s=arc-20160816; b=ECGYUCxGFYyPltv07ZpFrD3UeOdqjhyOoOr6+cbhTZK1jSrJUlLIzbSCB0ADsmR8Jo 5O49dWlibLK3lGIh+/XsfKP4yxVbQG3Lszw7AgcfSR9TUUeAnkZK/fcJfMRkFDT2l2fT tmEt1Mx6GKgZ40CAHXkOGvge3jjGqFZChWNXnb4NZQCpigXgRFInbz3i67aQiiDgseos MZCItcb7sYAAgY5u/arYgJdndCSlRiS1ribfE5IElTBkkBMw2aqWv4bqiMxGz6ayWLFp J6AB2Wtwqh/F8AvxsRyDqYNxyd2+PYlvaxiuzNhmOkuiiuzDIpPz4UIG93iQUrH2iKYg t5PQ== 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=lZ4JIF+sD0Yo+qyQl5nBu4ki7Xnxs2o7SEG2DlrYxvs=; fh=hYoOR0yg+Fo7S26X8ur5L+RaTmkyxWlAVaBypEC8A0g=; b=Zo2LQeHD1pXnj8XiIobiUuSe9fb0pLYpcYIlaok28CSkVLnCUDtkhzQUpJ9PieKOBQ /J38P0+uq5AOTPiuCyuN7IzIYu6T+Ud1KQtOw1cOLZ6gEW74dM8NgbCzMptDPlpwj6wN 2zU0gFuTG+vLmaGE7aSHPuZQkHRlBcWxS3mO+llRLiRbUSIO0r9Z4HWrhYmf+upeWBGU nO15/mEf0B77FioBlHuCXJazM/iMas/v06m73SEopqYS0TSIvdicRWpjF/vR4IQgtVdl /C5uyxJKno1Bno9hRu23tstYTVYj5usePBjRcjQD/tOUEI0yXWo7mmouVsg6wNh2IaEv L7oA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=tmEMQGkB; 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 f12-20020a05600c4e8c00b00401d7f0a864si2270680wmq.110.2023.09.14.09.22.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Sep 2023 09:22:43 -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=tmEMQGkB; 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 6B65F87073; Thu, 14 Sep 2023 18:21: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="tmEMQGkB"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id A43AC86672; Thu, 14 Sep 2023 18:21: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-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 935EC87072 for ; Thu, 14 Sep 2023 18:21: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=maxim.uvarov@linaro.org Received: by mail-lj1-x22f.google.com with SMTP id 38308e7fff4ca-2b974031aeaso19002261fa.0 for ; Thu, 14 Sep 2023 09:21:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1694708463; x=1695313263; 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=lZ4JIF+sD0Yo+qyQl5nBu4ki7Xnxs2o7SEG2DlrYxvs=; b=tmEMQGkBpAYKSr1Eq7Fmio7vZgAJwyJu+3WOaxbwTUNYPknuw6cKdip8J4gADRpMaF xlso5yjz6n8xpkEmkRzZNBv5qSWiU1JhvyOM3v+Gz3vNvIPj4IVESBVgTiz9DVcDUyry LUhhDYHdO9F1oWSXaAugOLLctAaQm6S1FJf53kxE2bx4QFloABd5rk98Npdv6rAw4zNE xaH8PmCuxYCXqNX09mGPfXY39lXiymSFPUPIZmEx+Mv1NauEAxm/DJWK36kCEqvaSQ4d QNjjVtwfVJ0ijUlvKAgmHvytw/X7oxdJCc3/6ZHKvbee/bg6eq/s2KuDh7DOIfehV8fl BTYA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694708463; x=1695313263; 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=lZ4JIF+sD0Yo+qyQl5nBu4ki7Xnxs2o7SEG2DlrYxvs=; b=nNXBYINzwQlYavUl8PeswIxgLOj+BoQBrntDztWPdlWB9hLQw7iTrxKtwQIqlo8MjK +pqvO69MhgkIYhe/E/HaiGP42M8Y3vvqunYA4O8dmIX2UOt+DYzM/yQKmkg5HWgdPjNj P9MtouAtuYVVvOz/CCCEQeGfYdU5odj2hj4ssisynFJ6YwbGSC/tvoSFQm05MafuLi8L p28tZbtflWzp4iKkOxIkcC5rQWoLE1igDNVjG6kpFLxcmZbQAn3Z6zLjadR4OyjWFPyi g2+BrJ6vjvoolA9WR06AKsUhEQRsOD73k57bRFljrLgFY4OeCLpxkqHshyCCE94miWzW gCQg== X-Gm-Message-State: AOJu0YxlCpGyXwnz1Y3rMlV9SXi+V+DWTNpuQ/5E6ZkCG0xDNPp1BFo+ JzEZYSeuZ++mGbb2rIFnPi/fgXVF8KFNvZ8uKa3XIQ== X-Received: by 2002:a2e:7306:0:b0:2bc:db5a:9540 with SMTP id o6-20020a2e7306000000b002bcdb5a9540mr5865593ljc.42.1694708463649; Thu, 14 Sep 2023 09:21:03 -0700 (PDT) Received: from localhost.localdomain ([45.82.14.220]) by smtp.gmail.com with ESMTPSA id z15-20020a2e8e8f000000b002ba7ae1f52asm346919ljk.0.2023.09.14.09.21.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Sep 2023 09:21:03 -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: [PATCHv9 12/15] net/lwip: connection between cmd and lwip apps Date: Thu, 14 Sep 2023 22:18:25 +0600 Message-Id: <20230914161828.3662-13-maxim.uvarov@linaro.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230914161828.3662-1-maxim.uvarov@linaro.org> References: <20230914161828.3662-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..90a18fb789 --- /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(20000UL, 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 Thu Sep 14 16:18:26 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxim Uvarov X-Patchwork-Id: 722570 Delivered-To: patch@linaro.org Received: by 2002:adf:f0d1:0:b0:31d:da82:a3b4 with SMTP id x17csp486338wro; Thu, 14 Sep 2023 09:22:51 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGmSVUsrRPRuzxjdbwzXhEdmROSlTAwhZ30P9h9tss2pVsOTT6HeIwQ05vQdmvRn6xLhmnX X-Received: by 2002:a5d:69cf:0:b0:317:7af4:5297 with SMTP id s15-20020a5d69cf000000b003177af45297mr5207083wrw.62.1694708571173; Thu, 14 Sep 2023 09:22:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694708571; cv=none; d=google.com; s=arc-20160816; b=UM8v15QeRU9NOOcvwGM57t2rWojyk7w7YEbbeGCh3/JmrivAcStoceOAlEftdb+4Rg NJcgUBhTiSmFKelbyeBdlrwz5j7vUHOBuPaxrxNfx2i+w4eahf+xcJ5sOWzEkScgOK3Z AYuYlkwyr4qi2JQDiuDxLm9WXs3FWxtD4GRWhPbQy7k85xd6BIjoRiHYaOpHRyGqhCAP RGfKFZqU+qzRK33xuFRGoTuWRMh0Ms3I9NwJM+RUaNFGro+2ThvY9PCYsVJYtDR7Z4i1 aRpV5qxl73F8BqH95o6litmG3WDvowoU5XIr+QOPTSfc0x99px/40xvD5e+yItLHVN47 W/zg== 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=UyMMML/lyGy47YdiF8TI2xAzcAyHtNLAzYRSbgZ7ji4ZmclkBwUnG1SXzr2yjPLXjP aMjSW6WPhG/rD2SZRt9NSRubudsUu6pd1jq6uv0rk15OQMVKkYGQmTJviOpy3KkUS0NK +VRQHv5WksZCtAmvg57sO7qsNJXwA1SUwxq8ZSY5S0OtuFauUVPv01KwXtSEK8UKgt2A PDia35raIDyow71Z7wb89oVojXNwfITvtW8G41Zc2jQ81HohrhTSlP00zAQWEYxZexQL anKWJHh0lqYG3/K1tmvry6+IxnuJhJVkyTqacSl+BMzXt+KfbE4VIIa+moAkU3nKtUYS D1Lw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=joSMAVXl; 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 m18-20020adffa12000000b003175e223edesi817536wrr.589.2023.09.14.09.22.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Sep 2023 09:22:51 -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=joSMAVXl; 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 C120687077; Thu, 14 Sep 2023 18:21: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="joSMAVXl"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 984B486AAC; Thu, 14 Sep 2023 18:21:12 +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-x229.google.com (mail-lj1-x229.google.com [IPv6:2a00:1450:4864:20::229]) (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 179EA869BC for ; Thu, 14 Sep 2023 18:21: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=maxim.uvarov@linaro.org Received: by mail-lj1-x229.google.com with SMTP id 38308e7fff4ca-2bcde83ce9fso18288721fa.1 for ; Thu, 14 Sep 2023 09:21:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1694708466; x=1695313266; 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=joSMAVXlrC0eO1PAeotiY5+BoSimQ+eRnJGKCmXi0eTxU+ze5WphvjA4Hr4wAgQ1IZ mM4Spt+R3UXzeYHzmJVC+cMOBddRMV1jEwxQEhk3fepILeYlLRsvtMejeOQz9QTxCyiY qStTBC+TssZGZX/9KK1hvf54yj66i6KQFnqKeFAWH/NTmaZJ+e0TCBU1F0KND3pl729+ gLEKBaUYYO5fx8kXxpBuCC2lVAY0qQ/l4K49VOvJWPvwPKjEd1TbvnY/QQV1gKBnAv10 1CNt5Qd600DDY8p31AAlH2/HakGudMI836Bv5eQ6HxiKnKVYgOpHG4rB9G3zMRULFNnA SzCg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694708466; x=1695313266; 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=b9GUyE9WNmRBBigbdo13mGDHzlsVY6NMlVi6RJNKZeD3Wl2cA6sOfVKM007wgAp+Id W1YrQwdFuWqBqspi3zXGWIlLg2VvkcSDaORpsml4zOg6f1URT/to4fCg/tDgSAn4hGF3 1WPN+lSUb3TAyfsDnt2bmsXBmoV42Blk7shUw8eEBzQ/J64iUfVdrrp/llIVuCk0MFAb wHNWyDNdrRzlpqIpmtedCJ3JvoUQAaM6xP8rvPJ7Nx11hjFYbm5j31RJgo9RRbGfap8P r/pcRJeu9tyHbIi0F2kGp5XQIAjRGdzxM5Fldalus+jrGJ9WsJ2givScq+FxLOYYlat/ W7YA== X-Gm-Message-State: AOJu0YyKKDsjpuuXOk7MpNioIWu5r2rZSbNf6o6KpEUPEz8pXzCIpoHk H9ruG0Wkgjg1nPE9fzv1McOVRS3R/U7BoLB6ZRkN5A== X-Received: by 2002:a2e:9185:0:b0:2bc:e46d:f4ca with SMTP id f5-20020a2e9185000000b002bce46df4camr5244171ljg.46.1694708466057; Thu, 14 Sep 2023 09:21:06 -0700 (PDT) Received: from localhost.localdomain ([45.82.14.220]) by smtp.gmail.com with ESMTPSA id z15-20020a2e8e8f000000b002ba7ae1f52asm346919ljk.0.2023.09.14.09.21.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Sep 2023 09:21:05 -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: [PATCHv9 13/15] net/lwip: replace original net commands with lwip Date: Thu, 14 Sep 2023 22:18:26 +0600 Message-Id: <20230914161828.3662-14-maxim.uvarov@linaro.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230914161828.3662-1-maxim.uvarov@linaro.org> References: <20230914161828.3662-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 Thu Sep 14 16:18:27 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxim Uvarov X-Patchwork-Id: 722572 Delivered-To: patch@linaro.org Received: by 2002:adf:f0d1:0:b0:31d:da82:a3b4 with SMTP id x17csp486555wro; Thu, 14 Sep 2023 09:23:17 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGgLF2p04ECFDGrmGRImGeATPjCokJsN5cP/uJSud9uf7oQ5fpI1CbS/13fjH90A6kZAUqi X-Received: by 2002:a05:600c:3657:b0:3fe:1871:1826 with SMTP id y23-20020a05600c365700b003fe18711826mr5166357wmq.27.1694708597011; Thu, 14 Sep 2023 09:23:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694708596; cv=none; d=google.com; s=arc-20160816; b=LvjiHQN5psrogz0BAbpRyMKB9M0ezfGa7DyrJ5Y/q97mm7wCBsouiOx8X9Kohg88GX xAVTiQzLvzIXOPWt8XEO8ItCJkCgiT5Rie0U5pVT+Q267BWjja9Yh7sRSxGZn4nqtc8v 7ossKZ0kcrC1bvA6lvpeLLO+AiAaZ2jOoKEnejQMPfVuaJVF8YFwAZ3pZRY0keXv3wVh DeP9e7bWNzumgXhDzL0axR77INkYJ6laQQYzNQgSHYdUtDBPrrXfJ9H9u0uyLHhtCLMk 1zPuWPhFngm4CtUd+2DEX4HC9oXs2WFwxvJtUcVec0BPoGa+iyc2JdLzWBAeS6Si7Upb owOA== 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=Vcoai2tXwCVkAlLthA0jhgSIZm3hroXZ0I9lqvouip5+k5cvSJPfmFdUcWb3ITdIBT xbjZOsArqmmu9yIzfgLpBqy+8HaqewF7XdxnvYQja5rCb54atANkY1uONVKDuwC1x5XL Lwa6dzR4h5G2D/5j4wjdLmHNabRI4dNKGJXpbOSaDJVtnFgSq5yfBmlgiHLCWEybpHIW /NJ2R+uujFLWds3lbGl/LvbwCfneb3++IW2h1rMLRkZYcEsaFFGPjvmiBFKBkEE5f413 gmh5fwIRV9XcaQoaOIN5D7qbn2kawGmHPJU9n94twW4Iu4Xf8o2HQqdDGyKhO28mLh/5 7ixA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Heqnjv4h; 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 z7-20020a05600c220700b003fe4a0c5e5csi1059033wml.85.2023.09.14.09.23.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Sep 2023 09:23:16 -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=Heqnjv4h; 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 69E1A87085; Thu, 14 Sep 2023 18:21:16 +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="Heqnjv4h"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id B7E0687080; Thu, 14 Sep 2023 18:21:14 +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 A498586672 for ; Thu, 14 Sep 2023 18:21:09 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=maxim.uvarov@linaro.org Received: by mail-lj1-x22c.google.com with SMTP id 38308e7fff4ca-2bd0d135ca3so19044381fa.3 for ; Thu, 14 Sep 2023 09:21:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1694708469; x=1695313269; 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=Heqnjv4hBecb9QiqEYTmjYEPG00F+sbUZdo6cTWVG8D6KDTTNmpYrtIi4uyKA67E5x rPnFhVrdtUWuNQGJgaXTNmICy+Bmul1MsrEEYdo+Gwr3kvxO2bwXTT6fODMuw3/QvVTp vk6Mo3RwsxUXBlNJeVCsp5Hb9eq5D8nSuaIt4kLQk1yoU/1+HcEYaYzwq8CyhfaS7YBY ybptJ4oEA8fxqLGXuHM+kpIpOxf0KRGux6k4qf+Ib8s3Ny7N3L4RWHuAtuedl4EKde2I fiW+ghr5EzxQ+Wtf4MC6AvtfSH4g27jBK7H7arE00J2MgQWVWpA9Ei+8Zs7KWHCuPoT8 bjxQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694708469; x=1695313269; 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=Ayo6Z+LhgKXJ8F8D3sQj0IFtwwPW0+D0Qk1w9E3X9PVMab5GEpKwKEC3wFoDE03n4L bSskjPaSJMurYwbx+0psvT8JA/HQ7SqaXH1fMxtK/wl5xZuMmkOO6e1xSZUpMANpC00f BJEp26TfsAlWioen5seZtcOR3KnRJk2H4A/vS6o0oa11xMrgzcycMPtsRdxMd9HF7Epr TfOU/T2JkmY89zBM1HKgeS7m/fOLO7wG0z0pRNArIWq05Ry/fD/395wgb95fm/lBLV5z bfOhZUsqkriQDyvVXmiEryVeppWGg+dh5XZG1et+CnL/MiZmJt+nHeXb100ntUxN/DYC yzSw== X-Gm-Message-State: AOJu0YyH7/+FzLOd1JnaP1BcTIRinUrD0Ma7xmqgH0NmmX0IyuIOhXUl Aus4v9m+q20jQmqNgeEb41h/U+OW/CQWcJPgHlTCaQ== X-Received: by 2002:a2e:8757:0:b0:2bc:b29e:8ff7 with SMTP id q23-20020a2e8757000000b002bcb29e8ff7mr5759520ljj.20.1694708468502; Thu, 14 Sep 2023 09:21:08 -0700 (PDT) Received: from localhost.localdomain ([45.82.14.220]) by smtp.gmail.com with ESMTPSA id z15-20020a2e8e8f000000b002ba7ae1f52asm346919ljk.0.2023.09.14.09.21.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Sep 2023 09:21:08 -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: [PATCHv9 14/15] net/lwip: split net.h to net.h, arp.h and eth.h Date: Thu, 14 Sep 2023 22:18:27 +0600 Message-Id: <20230914161828.3662-15-maxim.uvarov@linaro.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230914161828.3662-1-maxim.uvarov@linaro.org> References: <20230914161828.3662-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 Thu Sep 14 16:18:28 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxim Uvarov X-Patchwork-Id: 722571 Delivered-To: patch@linaro.org Received: by 2002:adf:f0d1:0:b0:31d:da82:a3b4 with SMTP id x17csp486441wro; Thu, 14 Sep 2023 09:23:05 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEOfss6q68iXiEzRBBqV9wa6Tz2hvMAa+vBrQE1R5grSI5HJMqSin3NHjf287/NU+EvwTMZ X-Received: by 2002:a5d:63c3:0:b0:319:6327:6adb with SMTP id c3-20020a5d63c3000000b0031963276adbmr4489777wrw.70.1694708584893; Thu, 14 Sep 2023 09:23:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694708584; cv=none; d=google.com; s=arc-20160816; b=iwVH4BsqWr8bjkHKFrXcTx8pY/SgDl4Qqa7kRjteLfRl6iJNnDBDTrpDRPkdOx6NN2 KfkK9huFCjR+98OqlLPc7eiNXWrP6/AnNNvUQZUI3y17BRDyFfMSNAeqN0XZFlr1ZiEv AIZAqx6PXSZ8XmuWgFYFNNlNwsVIa+xL83qHwwaT2E15kiT0/mUdPNwRAOV3fGMfCpVR RyKvslPMOH/mweV09H8AcYzGYp9BfPVheL9igLN8YoCiY9y7sieNKe/5FsvsRKWVZdcH SwISND2DRStyuLHXmpZ8nNfsCXoOWtSEZwweIUqZgWBKa5XvQuldf9Q6ID9GKfqOFFNg DVeA== 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=Q3SkI8m0jJgoyI96oA6Zeu2q6XC9dJKOA6GdCst75SjQpwGt2o2pbnBJzooMn0R2QV mJ/PUWUYAGQTjdcWug5zRHZVAb/HBpsktFMjBgfmM93IKLTYaGqaT8LdEeyyhEnj5BBR DqwwK59XCrd/5RHWt2yA+P6WJOKzVACRZwxGdjC3UR96wpzFJsirM1B2I0AsJIELai+3 E9NTq/qbqdRTUFczVBb+lTVrhEyoY+TFFtuouna9sriHe2FbpVSEgj5oum53c8O8g2D+ v9WLabb5IeMOUbSxmBJ5vg4I9B7jFLQBqRpK1KvfKRAKq0SF9IO7OUjz7+Us6r4QHhsJ DsXQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=GluuAknM; 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 o7-20020adfcf07000000b00317e2c85e03si785789wrj.394.2023.09.14.09.23.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Sep 2023 09:23: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=GluuAknM; 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 1A40186E46; Thu, 14 Sep 2023 18:21:16 +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="GluuAknM"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id AB58B87083; Thu, 14 Sep 2023 18:21:14 +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 F3C5787080 for ; Thu, 14 Sep 2023 18:21:11 +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-2b962535808so19091251fa.0 for ; Thu, 14 Sep 2023 09:21:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1694708471; x=1695313271; 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=GluuAknMK0HAY4xCc3KaoPK8GJFgnygSctWnZojKdyNFHG4sF5r2pz9Y214+GtyRa4 nt9PTgabfjX94NJGsXHtyawVhekZ8dj5Err6rAKFLIyqGhdg88nNCMxodNmHvWTkWZj/ +kv/eZ3G7yZqzEygjX44prBCDMEG6O/Tse9q+I+YlBC7CfUc3r8PSoywsywSiy+HCTUo 1s5HVa7ExDZe4PaBcqucNTN776cDOSqw41ISQUichLn5Wzey2gd1YEzSrnQSbEuecger LQ2FJgYC4WuE3+zWj92JW0NLDpDcXqqUraCwOUjVttgZ+1XG1kqaKS7zR/HU7ECiaAlC 8zqA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694708471; x=1695313271; 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=iOQQYcavL2OHyF5FrolI/rLNqxNo73CeIBt+BS5DhYQVrM8TSv9PFrKiwW9kxLpfDN Ea/sObY5idTN+tLLiHopYqWBIhEsd2fRfI7kXx1JKnewS2O5Ejkc9a/BsftLojUN1XEP pAt79aTjI032aedkXilORVVOfdbBhHeZeGVedlqL7Ni1lezmAchP7RAj5kuj2cQTPIhq lJxFW2aoIg1Va5O7KDKtO+dV3HFJhopMv3F5lap0BcVcgYIJJAly2nJ67BGMjzVcR6i8 LTxoWkz386yJkLRIRDQ/PNNk32LjBHijkWLnx3gleQpdlQ01qj6UQp/BrD3gyYFZ26CK gLiA== X-Gm-Message-State: AOJu0YySpz5qPQFzKihrg3VlWg2cZJYGw0kY5IFMEDpJFUIwpzser8hU ajb6BOQq4vLLIMtmVG03O/atQ/4XiXjW0aHgwZSUKA== X-Received: by 2002:a2e:9197:0:b0:2bb:985f:8479 with SMTP id f23-20020a2e9197000000b002bb985f8479mr5357611ljg.48.1694708470966; Thu, 14 Sep 2023 09:21:10 -0700 (PDT) Received: from localhost.localdomain ([45.82.14.220]) by smtp.gmail.com with ESMTPSA id z15-20020a2e8e8f000000b002ba7ae1f52asm346919ljk.0.2023.09.14.09.21.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Sep 2023 09:21:10 -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: [PATCHv9 15/15] net/lwip: drop old net/wget Date: Thu, 14 Sep 2023 22:18:28 +0600 Message-Id: <20230914161828.3662-16-maxim.uvarov@linaro.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230914161828.3662-1-maxim.uvarov@linaro.org> References: <20230914161828.3662-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); -}