From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1A246C433EF for ; Sat, 23 Oct 2021 23:37:40 +0000 (UTC) Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 8E21760F4F for ; Sat, 23 Oct 2021 23:37:39 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 8E21760F4F Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=chromium.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=lists.denx.de Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 07DCC83303; Sun, 24 Oct 2021 01:37:34 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="nvf5DGLM"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id F31A3834D6; Sun, 24 Oct 2021 01:27:59 +0200 (CEST) Received: from mail-oi1-x22b.google.com (mail-oi1-x22b.google.com [IPv6:2607:f8b0:4864:20::22b]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 6D6108350D for ; Sun, 24 Oct 2021 01:27:18 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=sjg@chromium.org Received: by mail-oi1-x22b.google.com with SMTP id v77so10052500oie.1 for ; Sat, 23 Oct 2021 16:27:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=cLZz9VgMW2fZ8JKFUirE91P6WnO7fhuoXhBAxwGtV/c=; b=nvf5DGLMH9SlAxbEtSiSkcqJ/L0Fyx0ersg5nzYcGQoPQ1arWLJhZBpCQaE5K5qD2L 5DTC9MYUShFFC810Uh1RlDRnxx5gqcjM9qP8e2fAxQXcfI7TRwBA9tk3BzSfrXaQGgWi WauO3jGVX5e6WNN2LdBz2qTNE1BHf2k1ycTMc= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=cLZz9VgMW2fZ8JKFUirE91P6WnO7fhuoXhBAxwGtV/c=; b=ImfCrOw2gyyyg6llEt17QB7X+pQ4MiUVgbhgBkFIkdJ4wiWZHrrch4AlWk3tSkytJp 1MaTYO3xQb2r8G4oNVLhlVPQ12PP9VGikiVsS6SXsxC8gl0zPUeAu7gkKTr2Q4+oDske 38IBesSVgVxovdmg3cF1kxl+kAHYdvRr4kH1ec18ifK0DS9wq9CVUqmUAB0RZjT3Oliq fpX9lIpqRr3qLMTCmNzdB3tXjd04gC3ozvEgB0Fl3qG/Gj3jT5VZRFgAEXOYxWz/L5A5 JhKpp21Fo9cq4Ijzk8vO5Wqf2zfkymZs4sJzBJwb+ACOWdHisRAgk9ZgExKt/bxYUykJ M08Q== X-Gm-Message-State: AOAM531VpJk7NAh5DZs19ZPBl120kO9tklZZXUTrmdVOuxsnd38hmgWD k1fEZQd+Py8OwhGh4Q7YXvWqhDIaUtOJBQ== X-Google-Smtp-Source: ABdhPJwAsnj/qfxv71pOSo7GQSdSlGe9PIRU/3MeBlrABi3qcl10XL/NsxS5xGUYCMxcKdcSVoPuyw== X-Received: by 2002:a54:4194:: with SMTP id 20mr7275046oiy.148.1635031636889; Sat, 23 Oct 2021 16:27:16 -0700 (PDT) Received: from kiwi.bld.corp.google.com (c-67-190-101-114.hsd1.co.comcast.net. [67.190.101.114]) by smtp.gmail.com with ESMTPSA id l24sm2253885oop.4.2021.10.23.16.27.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 23 Oct 2021 16:27:16 -0700 (PDT) From: Simon Glass To: U-Boot Mailing List Cc: Michal Simek , Heinrich Schuchardt , Tom Rini , Ilias Apalodimas , Daniel Schwierzeck , Steffen Jaeckel , =?UTF-8?q?Marek=20Beh=C3=BAn?= , Lukas Auer , Dennis Gilmore , Simon Glass Subject: [PATCH v2 29/41] bootstd: ethernet: Add a bootdev driver Date: Sat, 23 Oct 2021 17:26:23 -0600 Message-Id: <20211023172618.v2.29.Ibb454281fc9a82c3ad084f0f2f876e46809eee02@changeid> X-Mailer: git-send-email 2.33.0.1079.g6e70778dc9-goog In-Reply-To: <20211023232635.9195-1-sjg@chromium.org> References: <20211023232635.9195-1-sjg@chromium.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 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.2 at phobos.denx.de X-Virus-Status: Clean Add a bootdev driver for Ethernet. It can use the PXE boot mechanism to locate a file, added later. Signed-off-by: Simon Glass --- (no changes since v1) MAINTAINERS | 1 + net/Kconfig | 9 +++++ net/Makefile | 1 + net/eth-uclass.c | 8 ++++ net/eth_bootdev.c | 101 ++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 120 insertions(+) create mode 100644 net/eth_bootdev.c diff --git a/MAINTAINERS b/MAINTAINERS index 8a19d08623f..ae0b1613fe2 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -647,6 +647,7 @@ F: include/bootdev.h F: include/bootflow.h F: include/bootmeth.h F: include/bootstd.h +F: net/eth_bootdevice.c BTRFS M: Marek Behun diff --git a/net/Kconfig b/net/Kconfig index 7a2d1450188..e110930553a 100644 --- a/net/Kconfig +++ b/net/Kconfig @@ -14,6 +14,15 @@ config PROT_UDP Enable a generic udp framework that allows defining a custom handler for udp protocol. +config BOOTDEV_ETH + bool "Enable bootdev for ethernet" + depends on BOOTSTD + default y + help + Provide a bootdev for ethernet so that is it possible to boot + an operationg system over the network, using the PXE (Preboot + Execution Environment) protocol. + config BOOTP_SEND_HOSTNAME bool "Send hostname to DNS server" help diff --git a/net/Makefile b/net/Makefile index fb3eba840ff..6c812502d3e 100644 --- a/net/Makefile +++ b/net/Makefile @@ -12,6 +12,7 @@ obj-$(CONFIG_CMD_DNS) += dns.o obj-$(CONFIG_DM_DSA) += dsa-uclass.o ifdef CONFIG_DM_ETH obj-$(CONFIG_NET) += eth-uclass.o +obj-$(CONFIG_$(SPL_TPL_)BOOTDEV_ETH) += eth_bootdev.o else obj-$(CONFIG_NET) += eth_legacy.o endif diff --git a/net/eth-uclass.c b/net/eth-uclass.c index 0da0e85be03..cccbc87ab29 100644 --- a/net/eth-uclass.c +++ b/net/eth-uclass.c @@ -8,6 +8,7 @@ #define LOG_CATEGORY UCLASS_ETH #include +#include #include #include #include @@ -473,6 +474,8 @@ int eth_initialize(void) static int eth_post_bind(struct udevice *dev) { + int ret; + if (strchr(dev->name, ' ')) { printf("\nError: eth device name \"%s\" has a space!\n", dev->name); @@ -482,6 +485,11 @@ static int eth_post_bind(struct udevice *dev) #ifdef CONFIG_DM_ETH_PHY eth_phy_binds_nodes(dev); #endif + if (CONFIG_IS_ENABLED(BOOTDEV_ETH)) { + ret = bootdev_setup_for_dev(dev, "eth_bootdev"); + if (ret) + return log_msg_ret("bootdev", ret); + } return 0; } diff --git a/net/eth_bootdev.c b/net/eth_bootdev.c new file mode 100644 index 00000000000..b735966d2bc --- /dev/null +++ b/net/eth_bootdev.c @@ -0,0 +1,101 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Bootdevice for ethernet (uses PXE) + * + * Copyright 2021 Google LLC + * Written by Simon Glass + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +static int eth_get_bootflow(struct udevice *dev, struct bootflow_iter *iter, + struct bootflow *bflow) +{ + char name[60]; + int ret; + + /* Must be an Ethernet device */ + ret = bootflow_iter_uses_network(iter); + if (ret) + return log_msg_ret("net", ret); + + ret = bootmeth_check(bflow->method, iter); + if (ret) + return log_msg_ret("check", ret); + + /* + * Like distro boot, this assumes there is only one Ethernet device. + * In this case, that means that @eth is ignored + */ + + snprintf(name, sizeof(name), "%s.%d", dev->name, iter->part); + bflow->name = strdup(name); + if (!bflow->name) + return log_msg_ret("name", -ENOMEM); + + /* + * There is not a direct interface to the network stack so run + * everything through the command-line interpreter for now. + * + * Don't bother checking the result of dhcp. It can fail with: + * + * DHCP client bound to address 192.168.4.50 (4 ms) + * *** Warning: no boot file name; using 'C0A80432.img' + * Using smsc95xx_eth device + * TFTP from server 192.168.4.1; our IP address is 192.168.4.50 + * Filename 'C0A80432.img'. + * Load address: 0x200000 + * Loading: * + * TFTP error: 'File not found' (1) + * + * This is not a real failure, since we don't actually care if the + * boot file exists. + */ + log_debug("running dhcp\n"); + run_command("dhcp", 0); + bflow->state = BOOTFLOWST_MEDIA; + + /* See distro_pxe_read_bootflow() for the standard impl of this */ + log_debug("dhcp complete - reading bootflow with method %s\n", + bflow->method->name); + ret = bootmeth_read_bootflow(bflow->method, bflow); + log_debug("reading bootflow returned %d\n", ret); + if (ret) + return log_msg_ret("method", ret); + + return 0; +} + +static int eth_bootdev_bind(struct udevice *dev) +{ + struct bootdev_uc_plat *ucp = dev_get_uclass_plat(dev); + + ucp->prio = BOOTDEVP_4_NET_BASE; + + return 0; +} + +struct bootdev_ops eth_bootdev_ops = { + .get_bootflow = eth_get_bootflow, +}; + +static const struct udevice_id eth_bootdev_ids[] = { + { .compatible = "u-boot,bootdev-eth" }, + { } +}; + +U_BOOT_DRIVER(eth_bootdev) = { + .name = "eth_bootdev", + .id = UCLASS_BOOTDEV, + .ops = ð_bootdev_ops, + .bind = eth_bootdev_bind, + .of_match = eth_bootdev_ids, +}; -- 2.33.0.1079.g6e70778dc9-goog