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 76EE1C352A1 for ; Wed, 7 Dec 2022 09:02:26 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id F1B9B856AE; Wed, 7 Dec 2022 09:56: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="koLS3zTB"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 3E24785645; Wed, 7 Dec 2022 09:56:07 +0100 (CET) Received: from mail-pf1-x434.google.com (mail-pf1-x434.google.com [IPv6:2607:f8b0:4864:20::434]) (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 648CD8556A for ; Wed, 7 Dec 2022 09:56:02 +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-pf1-x434.google.com with SMTP id 140so16957051pfz.6 for ; Wed, 07 Dec 2022 00:56:02 -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=OLPar2FSoTjcKOnFLbHOrC9ZKtN9/yDZCrHOeK4J6e4=; b=koLS3zTBNWoiPwmhodclMcMtUkqyZdcFcbi1UGrc66GZ2u32PZWOP0Nk7Su5IBguAQ hdiDrDuJfZHmW/Oe2F2cJXFayNvNthM68qdkNhw/y/FK91pOgD6Diyk5gcZrMxxmgSwR S0aI16H+wICTspyXqbgzpxVGmJDE+JMKJ7tvY= 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=OLPar2FSoTjcKOnFLbHOrC9ZKtN9/yDZCrHOeK4J6e4=; b=bl/aXMEBNgBfaKxJA+x01gw9FlzPZrPcz1dT+vPbjsQdSp8FklJLBw+Vo/seRdYqms flm2oj4Jzq3SpljEvf9ejnt3jWhbTVsiaSI2+XPMJVjw7siF72coleLns+zDCGnZMpDs wLlRdUoStLs3P3j2wyQbWx2bmpplGb9M1XjzN6+qSQr0lbc9WyLsiet765WVZYW0fC3O fkAssLleNlgW3STe6agc7axKApiMdocsKliYJugo1vKQnNXVHX2D+qDUjym7mHH1Ic/z Rz8aYQ+UyTXt0NlyWdaVATwm1icXzX/cIwwBvKrMOu+8fVtygNiAli0/ZMGQSVxwDMGQ yZqw== X-Gm-Message-State: ANoB5pk5TePOgyPljGp8jIfPxEbQmkh1i2dEi+H7hzEgOXaZPB8GefNa xXIzctplCUVFn06Bn/zO/iWEySUZpZHNPpq5 X-Google-Smtp-Source: AA0mqf7tB4z3FuJ29I/NVtdPtXq1ZH4bwbCtmIK7aAXI8YNMxic3bFruRiVarLtgnhqHatzy9hOqUQ== X-Received: by 2002:a05:6a02:187:b0:46b:26a6:51bc with SMTP id bj7-20020a056a02018700b0046b26a651bcmr81389595pgb.204.1670403360536; Wed, 07 Dec 2022 00:56:00 -0800 (PST) Received: from localhost.localdomain ([27.110.126.54]) by smtp.gmail.com with ESMTPSA id l16-20020a170903121000b0018157b415dbsm14145514plh.63.2022.12.07.00.55.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 Dec 2022 00:56:00 -0800 (PST) From: Simon Glass To: U-Boot Mailing List Cc: U-Boot Custodians , Simon Glass , AKASHI Takahiro , Stefan Roese Subject: [PATCH 36/71] bootstd: Add a SCSI bootdev Date: Wed, 7 Dec 2022 21:51:02 +1300 Message-Id: <20221207085137.445249-37-sjg@chromium.org> X-Mailer: git-send-email 2.39.0.rc0.267.gcb52ba06e7-goog In-Reply-To: <20221207085137.445249-1-sjg@chromium.org> References: <20221207085137.445249-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 Add a bootdev for SCSI so that these devices can be used with standard boot. Signed-off-by: Simon Glass --- drivers/scsi/Makefile | 7 +++++ drivers/scsi/scsi.c | 7 ++++- drivers/scsi/scsi_bootdev.c | 62 +++++++++++++++++++++++++++++++++++++ test/boot/bootdev.c | 18 ++++++----- 4 files changed, 86 insertions(+), 8 deletions(-) create mode 100644 drivers/scsi/scsi_bootdev.c diff --git a/drivers/scsi/Makefile b/drivers/scsi/Makefile index d1b40c61401..d8d6de59090 100644 --- a/drivers/scsi/Makefile +++ b/drivers/scsi/Makefile @@ -6,6 +6,13 @@ ifndef CONFIG_SPL_BUILD obj-$(CONFIG_DM_SCSI) += scsi-uclass.o obj-$(CONFIG_SCSI) += scsi.o + +ifdef CONFIG_SCSI +ifdef CONFIG_DM_SCSI +obj-$(CONFIG_$(SPL_TPL_)BOOTSTD) += scsi_bootdev.o +endif +endif + endif ifdef CONFIG_SPL_BUILD diff --git a/drivers/scsi/scsi.c b/drivers/scsi/scsi.c index 2ae96e171eb..8d6af2a5068 100644 --- a/drivers/scsi/scsi.c +++ b/drivers/scsi/scsi.c @@ -8,6 +8,7 @@ #include #include +#include #include #include #include @@ -604,7 +605,11 @@ static int do_scsi_scan_one(struct udevice *dev, int id, int lun, bool verbose) ret = blk_probe_or_unbind(bdev); if (ret < 0) /* TODO: undo create */ - return ret; + return log_msg_ret("pro", ret); + + ret = bootdev_setup_sibling_blk(bdev, "scsi_bootdev"); + if (ret) + return log_msg_ret("bd", ret); if (verbose) { printf(" Device %d: ", bdesc->devnum); diff --git a/drivers/scsi/scsi_bootdev.c b/drivers/scsi/scsi_bootdev.c new file mode 100644 index 00000000000..2367b33da9c --- /dev/null +++ b/drivers/scsi/scsi_bootdev.c @@ -0,0 +1,62 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Bootdevice for USB + * + * Copyright 2021 Google LLC + * Written by Simon Glass + */ + +#include +#include +#include +#include +#include + +static int scsi_bootdev_bind(struct udevice *dev) +{ + struct bootdev_uc_plat *ucp = dev_get_uclass_plat(dev); + + ucp->prio = BOOTDEVP_2_SCAN_FAST; + + return 0; +} + +static int scsi_bootdev_hunt(struct bootdev_hunter *info, bool show) +{ + int ret; + + if (IS_ENABLED(CONFIG_PCI)) { + ret = pci_init(); + if (ret) + return log_msg_ret("pci", ret); + } + + ret = scsi_scan(true); + if (ret) + return log_msg_ret("scs", ret); + + return 0; +} + +struct bootdev_ops scsi_bootdev_ops = { +}; + +static const struct udevice_id scsi_bootdev_ids[] = { + { .compatible = "u-boot,bootdev-scsi" }, + { } +}; + +U_BOOT_DRIVER(scsi_bootdev) = { + .name = "scsi_bootdev", + .id = UCLASS_BOOTDEV, + .ops = &scsi_bootdev_ops, + .bind = scsi_bootdev_bind, + .of_match = scsi_bootdev_ids, +}; + +BOOTDEV_HUNTER(scsi_bootdev_hunter) = { + .prio = BOOTDEVP_2_SCAN_FAST, + .uclass = UCLASS_SCSI, + .hunt = scsi_bootdev_hunt, + .drv = DM_DRIVER_REF(scsi_bootdev), +}; diff --git a/test/boot/bootdev.c b/test/boot/bootdev.c index db0e0ca20fa..5661a3c0009 100644 --- a/test/boot/bootdev.c +++ b/test/boot/bootdev.c @@ -240,8 +240,9 @@ static int bootdev_test_hunter(struct unit_test_state *uts) ut_assert_nextlinen("----"); ut_assert_nextline(" 50 ethernet eth_bootdev"); ut_assert_nextline(" 10 mmc mmc_bootdev"); + ut_assert_nextline(" 30 scsi scsi_bootdev"); ut_assert_nextline(" 40 usb usb_bootdev"); - ut_assert_nextline("(total hunters: 3)"); + ut_assert_nextline("(total hunters: 4)"); ut_assert_console_end(); ut_assertok(bootdev_hunt("usb1", false)); @@ -249,8 +250,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 third in the list, so bit 2 */ - ut_asserteq(BIT(2), std->hunters_used); + /* USB is fourth in the list, so bit 3 */ + ut_asserteq(BIT(3), std->hunters_used); return 0; } @@ -270,7 +271,7 @@ 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: 3)"); + ut_assert_skip_to_line("(total hunters: 4)"); ut_assert_console_end(); /* Scan all hunters */ @@ -279,7 +280,9 @@ static int bootdev_test_cmd_hunt(struct unit_test_state *uts) 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("Hunting with: scsi"); + ut_assert_nextline("scanning bus for devices..."); + ut_assert_skip_to_line("Hunting with: usb"); ut_assert_nextline( "Bus usb@1: scanning bus usb@1 for devices... 5 USB Device(s) found"); ut_assert_console_end(); @@ -290,12 +293,13 @@ static int bootdev_test_cmd_hunt(struct unit_test_state *uts) ut_assert_nextlinen("----"); ut_assert_nextline(" 50 * ethernet eth_bootdev"); ut_assert_nextline(" 10 * mmc mmc_bootdev"); + ut_assert_nextline(" 30 * scsi scsi_bootdev"); ut_assert_nextline(" 40 * usb usb_bootdev"); - ut_assert_nextline("(total hunters: 3)"); + ut_assert_nextline("(total hunters: 4)"); ut_assert_console_end(); - ut_asserteq(GENMASK(2, 0), std->hunters_used); + ut_asserteq(GENMASK(3, 0), std->hunters_used); return 0; } -- 2.39.0.rc0.267.gcb52ba06e7-goog