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 C9153C433EF for ; Sat, 23 Oct 2021 23:32:20 +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 4F3A660E9C for ; Sat, 23 Oct 2021 23:32:20 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 4F3A660E9C 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 4DC84835D3; Sun, 24 Oct 2021 01:31:08 +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="OMwoIzy9"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 4E8D38331C; Sun, 24 Oct 2021 01:28:10 +0200 (CEST) Received: from mail-ot1-x331.google.com (mail-ot1-x331.google.com [IPv6:2607:f8b0:4864:20::331]) (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 03B3D83539 for ; Sun, 24 Oct 2021 01:27:25 +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-ot1-x331.google.com with SMTP id 34-20020a9d0325000000b00552cae0decbso9369018otv.0 for ; Sat, 23 Oct 2021 16:27:24 -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=5uDg2Zmpailq/PuXLhRygzw+KHHvMgkCYylrqltGhqI=; b=OMwoIzy95v7kL1vH4Hr1AcPXbSFpjksU1i92FnY+lApQ5x8e4qpZACT7U3JMH3fkHU T3C30xGA06tQIAfjyiybVuuRJ/b5zrgwxD2fCb6W1wkKwDSHiY79ILmZdRzAN1t/8r5e cwOKMZQARUyir+YmjRSyQHIj0r781Jeyk1Weo= 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=5uDg2Zmpailq/PuXLhRygzw+KHHvMgkCYylrqltGhqI=; b=3eG1QAjTXqlCESenWA1xPOqUDhqyiy2U9s+hAcgmyt7NdweHse9+7zzqP/Yce1exSa Voqdv4GQKHqxnKU8B2U3hiOMfbJ++56jWRsC+6cLTTslJ41KMYO1iBW9HFYEB3KarRQm g7QGuDmDYefRIBH6qa2s0ajTZkmWZtoFJjqXMOwGyYdd4cnsLY92TQsZDKlC6HrqA20a LsHuSi2YSIvKsBH0U9DUhs7m5RnX3CtQ9K9a3ch642bQ0qf2H6DU0VbTpzGN2Sf+J2tS sv6bpX5KI1MRDf3usxj8mfI+iX4LFrOssUXha3KB53j2ASysKTVgCPxLMGHK4vT0I9ae mmLQ== X-Gm-Message-State: AOAM531YVRjF0A8/wcda15tWCXFilUvAW+4p5iAteUtJAQKk3oAHZcCo fCU8LSt7YIPjBfsxB1dCk3lbYDvVa74= X-Google-Smtp-Source: ABdhPJwoTHrgOsIEYX78zSRkxS4EUcmAx6nX3wSobGXPOo/+4MzHPD45einoQevsBCgs1m37+wsxzw== X-Received: by 2002:a9d:6c4b:: with SMTP id g11mr7202734otq.122.1635031643580; Sat, 23 Oct 2021 16:27:23 -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.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 23 Oct 2021 16:27:23 -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 , Marek Vasut Subject: [PATCH v2 35/41] bootstd: usb: Add a bootdev driver Date: Sat, 23 Oct 2021 17:26:29 -0600 Message-Id: <20211023172618.v2.35.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 USB host. It can use the distro boot mechanism to locate a file, or any other available bootmeth. Signed-off-by: Simon Glass --- (no changes since v1) common/usb_storage.c | 12 +++++++ drivers/usb/host/Makefile | 4 +++ drivers/usb/host/usb_bootdev.c | 61 ++++++++++++++++++++++++++++++++++ 3 files changed, 77 insertions(+) create mode 100644 drivers/usb/host/usb_bootdev.c diff --git a/common/usb_storage.c b/common/usb_storage.c index c9e2d7343ce..24ccb21701c 100644 --- a/common/usb_storage.c +++ b/common/usb_storage.c @@ -34,6 +34,7 @@ #include #include +#include #include #include #include @@ -239,6 +240,17 @@ static int usb_stor_probe_device(struct usb_device *udev) if (ret) return ret; } + + ret = bootdev_setup_sibling_blk(dev, "usb_bootdev"); + if (ret) { + int ret2; + + ret2 = device_unbind(dev); + if (ret2) + return log_msg_ret("bootdev", ret2); + return log_msg_ret("bootdev", ret); + } + } #else /* We don't have space to even probe if we hit the maximum */ diff --git a/drivers/usb/host/Makefile b/drivers/usb/host/Makefile index eb6fe9f6b30..742957d199c 100644 --- a/drivers/usb/host/Makefile +++ b/drivers/usb/host/Makefile @@ -8,6 +8,10 @@ obj-y += usb-uclass.o obj-$(CONFIG_SANDBOX) += usb-sandbox.o endif +ifdef CONFIG_$(SPL_TPL_)USB_STORAGE +obj-$(CONFIG_$(SPL_TPL_)BOOTSTD) += usb_bootdev.o +endif + # ohci obj-$(CONFIG_USB_OHCI_NEW) += ohci-hcd.o obj-$(CONFIG_USB_ATMEL) += ohci-at91.o diff --git a/drivers/usb/host/usb_bootdev.c b/drivers/usb/host/usb_bootdev.c new file mode 100644 index 00000000000..b85f699933d --- /dev/null +++ b/drivers/usb/host/usb_bootdev.c @@ -0,0 +1,61 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Bootdevice for USB + * + * Copyright 2021 Google LLC + * Written by Simon Glass + */ + +#include +#include +#include +#include + +static int usb_get_bootflow(struct udevice *dev, struct bootflow_iter *iter, + struct bootflow *bflow) +{ + struct udevice *blk; + int ret; + + ret = bootdev_get_sibling_blk(dev, &blk); + /* + * If there is no media, indicate that no more partitions should be + * checked + */ + if (ret == -EOPNOTSUPP) + ret = -ESHUTDOWN; + if (ret) + return log_msg_ret("blk", ret); + assert(blk); + ret = bootdev_find_in_blk(dev, blk, iter, bflow); + if (ret) + return log_msg_ret("find", ret); + + return 0; +} + +static int usb_bootdev_bind(struct udevice *dev) +{ + struct bootdev_uc_plat *ucp = dev_get_uclass_plat(dev); + + ucp->prio = BOOTDEVP_3_SCAN_SLOW; + + return 0; +} + +struct bootdev_ops usb_bootdev_ops = { + .get_bootflow = usb_get_bootflow, +}; + +static const struct udevice_id usb_bootdev_ids[] = { + { .compatible = "u-boot,bootdev-usb" }, + { } +}; + +U_BOOT_DRIVER(usb_bootdev) = { + .name = "usb_bootdev", + .id = UCLASS_BOOTDEV, + .ops = &usb_bootdev_ops, + .bind = usb_bootdev_bind, + .of_match = usb_bootdev_ids, +}; -- 2.33.0.1079.g6e70778dc9-goog