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 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 smtp.lore.kernel.org (Postfix) with ESMTPS id 06456C54EBC for ; Sun, 8 Jan 2023 03:02:21 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 03EE485621; Sun, 8 Jan 2023 03:57:18 +0100 (CET) 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="kGoj2yEg"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id DE06185623; Sun, 8 Jan 2023 03:56:33 +0100 (CET) Received: from mail-io1-xd30.google.com (mail-io1-xd30.google.com [IPv6:2607:f8b0:4864:20::d30]) (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 2102285654 for ; Sun, 8 Jan 2023 03:51:21 +0100 (CET) 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-io1-xd30.google.com with SMTP id b192so2924560iof.8 for ; Sat, 07 Jan 2023 18:51:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; 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=PgPurPhMJYNTVahyGBkqhesUXFkkD7Bw+Cz7goLL0Ho=; b=kGoj2yEgIq8InaYTeiBLaukGnTPBp6Q1CXsIbMDDAtINmsy5bv/agQnQepWXPmC3xw iOb3XXUzSEb0lyWbFSbHa+tin32/QmCTL1IXIrPJWJF4su7PTZIYbTMbHO6J+s1Oa/LC hqTOfn0j16Vqn3j6bbC8sfSbIvWQmGESTj4o0= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=PgPurPhMJYNTVahyGBkqhesUXFkkD7Bw+Cz7goLL0Ho=; b=Qg4f+wB48CbK5qw6pkK1REImZiJUQn4l0AyuW89GcQnBpUXAVzf+XffCzMSicJMu8T uWo/RKpBEGeHDfROhcMy898aLCdP4G29FyJ7i8/LGM5uGDlo8v9nIcae7bEWjg7Og9iL oywA+x4x45TbtQsq2en6/4u8EUzkLaqJ8ICweKi2+k7j1HwOr4VRnjNiTTMy7KhYHfCK YwUZMRtdirhcMYJPzHo3DHrb46IzosLXjldrfTcBMsb9qRUcYk3YAvOCJUKmkvZPwIUp uPYRO765jqTdst/QJu/KgWqfYx7EnFqLA+cMFISjLF3bJysgYrP4E4+54118Tg8ajyhY 5ldg== X-Gm-Message-State: AFqh2koInmubgpWHdCE//5/yshjCBeMt9lfDaZrwBa9bWJghcmAg3P7L 0I9GnLooGzjoV3yWZ/LnnC8sVysgldVjOqxv X-Google-Smtp-Source: AMrXdXueeupnAaWm1cXTZ1VaQ2yrotBakz547o0yB0smcd9qG894e7Z9hUP+VG0Mfm7P7xb8kQlgag== X-Received: by 2002:a6b:d00a:0:b0:6ea:1239:6a78 with SMTP id x10-20020a6bd00a000000b006ea12396a78mr41246471ioa.1.1673146279402; Sat, 07 Jan 2023 18:51:19 -0800 (PST) Received: from sjg1.roam.corp.google.com (c-71-56-217-229.hsd1.co.comcast.net. [71.56.217.229]) by smtp.gmail.com with ESMTPSA id c17-20020a92bd11000000b00302a00aaefasm1622174ile.26.2023.01.07.18.51.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 07 Jan 2023 18:51:19 -0800 (PST) From: Simon Glass To: U-Boot Mailing List Cc: U-Boot Custodians , Simon Glass Subject: [PATCH v2 31/71] bootstd: Add a hunter for ethernet Date: Sat, 7 Jan 2023 19:50:07 -0700 Message-Id: <20230108025047.522240-32-sjg@chromium.org> X-Mailer: git-send-email 2.39.0.314.g84b9a713c41-goog In-Reply-To: <20230108025047.522240-1-sjg@chromium.org> References: <20230108025047.522240-1-sjg@chromium.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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.6 at phobos.denx.de X-Virus-Status: Clean Sometimes ethernet devices are attached to PCI. Since it is quick to scan, add this into the ethernet hunter. Run dhcp to establish the network connection. Drop this from the bootdev since that is not needed now. Update a log message for clarity. Signed-off-by: Simon Glass --- (no changes since v1) net/eth_bootdev.c | 64 +++++++++++++++++++++++++++++---------------- test/boot/bootdev.c | 17 +++++++----- 2 files changed, 52 insertions(+), 29 deletions(-) diff --git a/net/eth_bootdev.c b/net/eth_bootdev.c index b735966d2bc..fdf48f00131 100644 --- a/net/eth_bootdev.c +++ b/net/eth_bootdev.c @@ -6,6 +6,8 @@ * Written by Simon Glass */ +#define LOG_CATEGORY UCLASS_BOOTSTD + #include #include #include @@ -13,8 +15,10 @@ #include #include #include +#include #include #include +#include static int eth_get_bootflow(struct udevice *dev, struct bootflow_iter *iter, struct bootflow *bflow) @@ -41,30 +45,8 @@ static int eth_get_bootflow(struct udevice *dev, struct bootflow_iter *iter, 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", + 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); @@ -83,6 +65,35 @@ static int eth_bootdev_bind(struct udevice *dev) return 0; } +static int eth_bootdev_hunt(struct bootdev_hunter *info, bool show) +{ + int ret; + + if (!test_eth_enabled()) + return 0; + + /* init PCI first since this is often used to provide Ehternet */ + if (IS_ENABLED(CONFIG_PCI)) { + ret = pci_init(); + if (ret) + log_warning("Failed to init PCI (%dE)\n", ret); + } + + /* + * Ethernet devices can also come from USB, but that is a higher + * priority (BOOTDEVP_5_SCAN_SLOW) than ethernet, so it should have been + * enumerated already. If something like 'bootflow scan dhcp' is used + * then the user will need to run 'usb start' first. + */ + if (IS_ENABLED(CONFIG_CMD_DHCP)) { + ret = dhcp_run(0, NULL, false); + if (ret) + return -EINVAL; + } + + return 0; +} + struct bootdev_ops eth_bootdev_ops = { .get_bootflow = eth_get_bootflow, }; @@ -99,3 +110,10 @@ U_BOOT_DRIVER(eth_bootdev) = { .bind = eth_bootdev_bind, .of_match = eth_bootdev_ids, }; + +BOOTDEV_HUNTER(eth_bootdev_hunt) = { + .prio = BOOTDEVP_4_NET_BASE, + .uclass = UCLASS_ETH, + .hunt = eth_bootdev_hunt, + .drv = DM_DRIVER_REF(eth_bootdev), +}; diff --git a/test/boot/bootdev.c b/test/boot/bootdev.c index 78cb0ac628a..32a31c44609 100644 --- a/test/boot/bootdev.c +++ b/test/boot/bootdev.c @@ -238,9 +238,10 @@ static int bootdev_test_hunter(struct unit_test_state *uts) bootdev_list_hunters(std); ut_assert_nextline("Prio Used Uclass Hunter"); ut_assert_nextlinen("----"); + ut_assert_nextline(" 50 ethernet eth_bootdev"); ut_assert_nextline(" 10 mmc mmc_bootdev"); ut_assert_nextline(" 40 usb usb_bootdev"); - ut_assert_nextline("(total hunters: 2)"); + ut_assert_nextline("(total hunters: 3)"); ut_assert_console_end(); ut_assertok(bootdev_hunt("usb1", false)); @@ -248,8 +249,8 @@ static int bootdev_test_hunter(struct unit_test_state *uts) "Bus usb@1: scanning bus usb@1 for devices... 5 USB Device(s) found"); ut_assert_console_end(); - /* USB is second in the list, so bit 1 */ - ut_asserteq(BIT(1), std->hunters_used); + /* USB is third in the list, so bit 2 */ + ut_asserteq(BIT(2), std->hunters_used); return 0; } @@ -269,11 +270,14 @@ static int bootdev_test_cmd_hunt(struct unit_test_state *uts) ut_assertok(run_command("bootdev hunt -l", 0)); ut_assert_nextline("Prio Used Uclass Hunter"); ut_assert_nextlinen("----"); - ut_assert_skip_to_line("(total hunters: 2)"); + ut_assert_skip_to_line("(total hunters: 3)"); ut_assert_console_end(); /* Scan all hunters */ + sandbox_set_eth_enable(false); + ut_assertok(run_command("bootdev hunt", 0)); + ut_assert_nextline("Hunting with: ethernet"); ut_assert_nextline("Hunting with: mmc"); ut_assert_nextline("Hunting with: usb"); ut_assert_nextline( @@ -284,13 +288,14 @@ static int bootdev_test_cmd_hunt(struct unit_test_state *uts) ut_assertok(run_command("bootdev hunt -l", 0)); ut_assert_nextlinen("Prio"); ut_assert_nextlinen("----"); + ut_assert_nextline(" 50 * ethernet eth_bootdev"); ut_assert_nextline(" 10 * mmc mmc_bootdev"); ut_assert_nextline(" 40 * usb usb_bootdev"); - ut_assert_nextline("(total hunters: 2)"); + ut_assert_nextline("(total hunters: 3)"); ut_assert_console_end(); - ut_asserteq(GENMASK(1, 0), std->hunters_used); + ut_asserteq(GENMASK(2, 0), std->hunters_used); return 0; } -- 2.39.0.314.g84b9a713c41-goog