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 35234C433EF for ; Sat, 23 Oct 2021 23:29:36 +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 A967660C4D for ; Sat, 23 Oct 2021 23:29:35 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org A967660C4D 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 7376E83549; Sun, 24 Oct 2021 01:28:59 +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="f7biuH5O"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id C8057833D4; Sun, 24 Oct 2021 01:27:40 +0200 (CEST) Received: from mail-ot1-x32d.google.com (mail-ot1-x32d.google.com [IPv6:2607:f8b0:4864:20::32d]) (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 989ED833D8 for ; Sun, 24 Oct 2021 01:27:09 +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-x32d.google.com with SMTP id z5-20020a9d4685000000b005537cbe6e5aso2590034ote.1 for ; Sat, 23 Oct 2021 16:27:09 -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=aBQ7fSIMlUy5pwPM5N8YRDSgyX/T1SybmuNmP+sJNg0=; b=f7biuH5O3a8Ya6qAsM0HkRmaLWViF0XOyXZJpPZwdXkfvVB9URqX+muNztY0Vt4mBy gJC2BNBOwEGDIw+XcgYv2eUP53hQGuJkunx7j2E0wpejulQYiFzAAbKLOm9nVFxOHnoa uzYapj+lIG2lzts9C1VI91LtXqYbz0ib+KAvU= 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=aBQ7fSIMlUy5pwPM5N8YRDSgyX/T1SybmuNmP+sJNg0=; b=Pec6yj3fpR1K7fwEvddpd5Jhwo+bVNC8ObYNo2ehcYeZ3z+PuLrp5V6nBrIrwvCCP9 dgQleYiyQZTSPq1TO8Xmh0w5mgAmjIZHxEgCDMfqREdu/jKgtEBv6RXzBxm4iHfAsUG4 lGeT2bLReRnu0cxODrLXLZV9ZJTXmC/FlUjjn2MCBTHQq8SWjZEi1jLaA8vil8wZMMM0 pLQ+PNelCUTZeN3OSYL+oaZ25IH9aH4v/cA+JJY3EA2Z2D5XZX/WULNmCfBDRDzgmew+ GKazb5fvCVpWNwvaXpkCCjxDJutRKxf+Z1dc27TOvMLAklZBnu0gPoBmLVeTVmS68vt4 CPWQ== X-Gm-Message-State: AOAM532YEER5UKbWuiRZAPvFyv/HPty0dCq3D696x5yPBrEnRQZD6zN1 eQSbGLSNRM81f9VhwZmjhTrmqTESNoLf/w== X-Google-Smtp-Source: ABdhPJyrl7R98V9iOckDKvBRPDp84qM6D2UW+GE2sQMa7UCxe6+tA+hg860Jd2IESWB9VJu6ltgzIQ== X-Received: by 2002:a05:6830:12d8:: with SMTP id a24mr6691361otq.34.1635031627770; Sat, 23 Oct 2021 16:27:07 -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.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 23 Oct 2021 16:27:07 -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 21/41] bootstd: Add the bootdev uclass Date: Sat, 23 Oct 2021 17:26:15 -0600 Message-Id: <20211023172618.v2.21.I3b5bc09d034cd72b2a9c604a0907c10abc05956a@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 A 'bootdev' is a device which can be used to boot an operating system. It is a child of the media device (e.g. MMC) which handles reading files from that device, such as a bootflow file. Add a uclass for bootdev and the various helpers needed to make it work. Also add a binding file, empty for now. Signed-off-by: Simon Glass --- (no changes since v1) MAINTAINERS | 4 +- boot/Makefile | 1 + boot/bootdev-uclass.c | 431 +++++++++++++++++++++++++++ doc/device-tree-bindings/bootdev.txt | 8 + include/bootdev.h | 258 ++++++++++++++++ include/dm/uclass-id.h | 1 + 6 files changed, 702 insertions(+), 1 deletion(-) create mode 100644 boot/bootdev-uclass.c create mode 100644 doc/device-tree-bindings/bootdev.txt create mode 100644 include/bootdev.h diff --git a/MAINTAINERS b/MAINTAINERS index c928130f94b..d800a3b7acb 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -636,9 +636,11 @@ F: tools/binman/ BOOTDEVICE M: Simon Glass S: Maintained +F: boot/bootdev*.c F: boot/bootstd.c -F: include/bootstd.h +F: include/bootdev*.h F: include/bootflow.h +F: include/bootstd.h BTRFS M: Marek Behun diff --git a/boot/Makefile b/boot/Makefile index 48031d1c2b0..35abfd37654 100644 --- a/boot/Makefile +++ b/boot/Makefile @@ -23,6 +23,7 @@ obj-y += image.o image-board.o obj-$(CONFIG_ANDROID_AB) += android_ab.o obj-$(CONFIG_ANDROID_BOOT_IMAGE) += image-android.o image-android-dt.o +obj-$(CONFIG_$(SPL_TPL_)BOOTSTD) += bootdev-uclass.o obj-$(CONFIG_$(SPL_TPL_)BOOTSTD) += bootstd-uclass.o obj-$(CONFIG_$(SPL_TPL_)OF_LIBFDT) += image-fdt.o diff --git a/boot/bootdev-uclass.c b/boot/bootdev-uclass.c new file mode 100644 index 00000000000..c8455ec5159 --- /dev/null +++ b/boot/bootdev-uclass.c @@ -0,0 +1,431 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Copyright 2021 Google LLC + * Written by Simon Glass + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +enum { + /* + * Set some sort of limit on the number of partitions a bootdev can + * have. Note that for disks this limits the partitions numbers that + * are scanned to 1..MAX_BOOTFLOWS_PER_BOOTDEV + */ + MAX_PART_PER_BOOTDEV = 30, +}; + +int bootdev_add_bootflow(struct bootflow *bflow) +{ + struct bootdev_uc_plat *ucp = dev_get_uclass_plat(bflow->dev); + struct bootstd_priv *std; + struct bootflow *new; + int ret; + + assert(bflow->dev); + ret = bootstd_get_priv(&std); + if (ret) + return ret; + + new = malloc(sizeof(*bflow)); + if (!new) + return log_msg_ret("bflow", -ENOMEM); + memcpy(new, bflow, sizeof(*bflow)); + + list_add_tail(&new->glob_node, &std->glob_head); + list_add_tail(&new->bm_node, &ucp->bootflow_head); + + return 0; +} + +int bootdev_first_bootflow(struct udevice *dev, struct bootflow **bflowp) +{ + struct bootdev_uc_plat *ucp = dev_get_uclass_plat(dev); + + if (list_empty(&ucp->bootflow_head)) + return -ENOENT; + + *bflowp = list_first_entry(&ucp->bootflow_head, struct bootflow, + bm_node); + + return 0; +} + +int bootdev_next_bootflow(struct bootflow **bflowp) +{ + struct bootflow *bflow = *bflowp; + struct bootdev_uc_plat *ucp = dev_get_uclass_plat(bflow->dev); + + *bflowp = NULL; + + if (list_is_last(&bflow->bm_node, &ucp->bootflow_head)) + return -ENOENT; + + *bflowp = list_entry(bflow->bm_node.next, struct bootflow, bm_node); + + return 0; +} + +int bootdev_bind(struct udevice *parent, const char *drv_name, const char *name, + struct udevice **devp) +{ + struct udevice *dev; + char dev_name[30]; + char *str; + int ret; + + snprintf(dev_name, sizeof(dev_name), "%s.%s", parent->name, name); + str = strdup(dev_name); + if (!str) + return -ENOMEM; + ret = device_bind_driver(parent, drv_name, str, &dev); + if (ret) + return ret; + device_set_name_alloced(dev); + *devp = dev; + + return 0; +} + +int bootdev_find_in_blk(struct udevice *dev, struct udevice *blk, + struct bootflow_iter *iter, struct bootflow *bflow) +{ + struct blk_desc *desc = dev_get_uclass_plat(blk); + struct disk_partition info; + char partstr[20]; + char name[60]; + int ret; + + /* Sanity check */ + if (iter->part >= MAX_PART_PER_BOOTDEV) + return log_msg_ret("max", -ESHUTDOWN); + + bflow->blk = blk; + if (iter->part) + snprintf(partstr, sizeof(partstr), "part_%x", iter->part); + else + strcpy(partstr, "whole"); + snprintf(name, sizeof(name), "%s.%s", dev->name, partstr); + bflow->name = strdup(name); + if (!bflow->name) + return log_msg_ret("name", -ENOMEM); + + bflow->state = BOOTFLOWST_BASE; + bflow->part = iter->part; + + /* + * partition numbers start at 0 so this cannot succeed, but it can tell + * us whether there is valid media there + */ + ret = part_get_info(desc, iter->part, &info); + if (!iter->part && ret == -ENOENT) + ret = 0; + + /* + * This error indicates the media is not present. Otherwise we just + * blindly scan the next partition. We could be more intelligent here + * and check which partition numbers actually exist. + */ + if (ret == -EOPNOTSUPP) + ret = -ESHUTDOWN; + else + bflow->state = BOOTFLOWST_MEDIA; + if (ret) + return log_msg_ret("part", ret); + + /* + * Currently we don't get the number of partitions, so just + * assume a large number + */ + iter->max_part = MAX_PART_PER_BOOTDEV; + + if (iter->part) { + ret = fs_set_blk_dev_with_part(desc, bflow->part); + bflow->state = BOOTFLOWST_PART; + + /* Use an #ifdef due to info.sys_ind */ +#ifdef CONFIG_DOS_PARTITION + log_debug("%s: Found partition %x type %x fstype %d\n", + blk->name, bflow->part, info.sys_ind, + ret ? -1 : fs_get_type()); +#endif + if (ret) + return log_msg_ret("fs", ret); + bflow->state = BOOTFLOWST_FS; + } + + return 0; +} + +void bootdev_list(bool probe) +{ + struct udevice *dev; + int ret; + int i; + + printf("Seq Probed Status Uclass Name\n"); + printf("--- ------ ------ -------- ------------------\n"); + if (probe) + ret = uclass_first_device_err(UCLASS_BOOTDEV, &dev); + else + ret = uclass_find_first_device(UCLASS_BOOTDEV, &dev); + for (i = 0; dev; i++) { + printf("%3x [ %c ] %6s %-9.9s %s\n", dev_seq(dev), + device_active(dev) ? '+' : ' ', + ret ? simple_itoa(ret) : "OK", + dev_get_uclass_name(dev_get_parent(dev)), dev->name); + if (probe) + ret = uclass_next_device_err(&dev); + else + ret = uclass_find_next_device(&dev); + } + printf("--- ------ ------ -------- ------------------\n"); + printf("(%d bootdev%s)\n", i, i != 1 ? "s" : ""); +} + +int bootdev_setup_for_dev(struct udevice *parent, const char *drv_name) +{ + struct udevice *bdev; + int ret; + + ret = device_find_first_child_by_uclass(parent, UCLASS_BOOTDEV, + &bdev); + if (ret) { + if (ret != -ENODEV) { + log_debug("Cannot access bootdev device\n"); + return ret; + } + + ret = bootdev_bind(parent, drv_name, "bootdev", &bdev); + if (ret) { + log_debug("Cannot create bootdev device\n"); + return ret; + } + } + + return 0; +} + +int bootdev_setup_sibling_blk(struct udevice *blk, const char *drv_name) +{ + struct udevice *parent, *dev; + char dev_name[50]; + int ret; + + snprintf(dev_name, sizeof(dev_name), "%s.%s", blk->name, "bootdev"); + + parent = dev_get_parent(blk); + ret = device_find_child_by_name(parent, dev_name, &dev); + if (ret) { + char *str; + + if (ret != -ENODEV) { + log_debug("Cannot access bootdev device\n"); + return ret; + } + str = strdup(dev_name); + if (!str) + return -ENOMEM; + + ret = device_bind_driver(parent, drv_name, str, &dev); + if (ret) { + log_debug("Cannot create bootdev device\n"); + return ret; + } + device_set_name_alloced(dev); + } + + return 0; +} + +int bootdev_get_sibling_blk(struct udevice *dev, struct udevice **blkp) +{ + struct udevice *parent = dev_get_parent(dev); + struct udevice *blk; + int ret, len; + char *p; + + if (device_get_uclass_id(dev) != UCLASS_BOOTDEV) + return -EINVAL; + + /* This should always work if bootdev_setup_sibling_blk() was used */ + p = strstr(dev->name, ".bootdev"); + if (!p) + return log_msg_ret("str", -EINVAL); + + len = p - dev->name; + ret = device_find_child_by_namelen(parent, dev->name, len, &blk); + if (ret) + return log_msg_ret("find", ret); + *blkp = blk; + + return 0; +} + +int bootdev_unbind_dev(struct udevice *parent) +{ + struct udevice *dev; + int ret; + + ret = device_find_first_child_by_uclass(parent, UCLASS_BOOTDEV, &dev); + if (!ret) { + ret = device_remove(dev, DM_REMOVE_NORMAL); + if (ret) + return log_msg_ret("rem", ret); + ret = device_unbind(dev); + if (ret) + return log_msg_ret("unb", ret); + } + + return 0; +} + +/** + * bootdev_find_by_label() - Convert a label string to a bootdev device + * + * Looks up a label name to find the associated bootdev. For example, if the + * label name is "mmc2", this will find a bootdev for an mmc device whose + * sequence number is 2. + * + * @label: Label string to convert, e.g. "mmc2" + * @devp: Returns bootdev device corresponding to that boot label + * @return 0 if OK, -EINVAL if the label name (e.g. "mmc") does not refer to a + * uclass, -ENOENT if no bootdev for that media has the sequence number + * (e.g. 2) + */ +int bootdev_find_by_label(const char *label, struct udevice **devp) +{ + struct udevice *media; + struct uclass *uc; + enum uclass_id id; + int seq, len; + + seq = trailing_strtoln_len(label, NULL, &len); + id = uclass_get_by_name_len(label, len); + if (id == UCLASS_INVALID) { + log_warning("Unknown uclass '%s' in label\n", label); + return -EINVAL; + } + + /* Iterate through devices in the media uclass (e.g. UCLASS_MMC) */ + uclass_id_foreach_dev(id, media, uc) { + struct udevice *bdev; + int ret; + + /* if there is no seq, match anything */ + if (seq != -1 && dev_seq(media) != seq) + continue; + + ret = device_find_first_child_by_uclass(media, UCLASS_BOOTDEV, + &bdev); + if (!ret) { + *devp = bdev; + return 0; + } + } + log_warning("Unknown seq %d for label '%s'\n", seq, label); + + return -ENOENT; +} + +int bootdev_find_by_any(const char *name, struct udevice **devp) +{ + struct udevice *dev; + int ret, seq; + char *endp; + + seq = simple_strtol(name, &endp, 16); + + /* Select by name, label or number */ + if (*endp) { + ret = uclass_get_device_by_name(UCLASS_BOOTDEV, name, &dev); + if (ret == -ENODEV) { + ret = bootdev_find_by_label(name, &dev); + if (ret) { + printf("Cannot find bootdev '%s' (err=%d)\n", + name, ret); + return ret; + } + ret = device_probe(dev); + } + if (ret) { + printf("Cannot probe bootdev '%s' (err=%d)\n", name, + ret); + return ret; + } + } else { + ret = uclass_get_device_by_seq(UCLASS_BOOTDEV, seq, &dev); + } + if (ret) { + printf("Cannot find '%s' (err=%d)\n", name, ret); + return ret; + } + + *devp = dev; + + return 0; +} + +int bootdev_get_bootflow(struct udevice *dev, struct bootflow_iter *iter, + struct bootflow *bflow) +{ + const struct bootdev_ops *ops = bootdev_get_ops(dev); + + if (!ops->get_bootflow) + return -ENOSYS; + memset(bflow, '\0', sizeof(*bflow)); + bflow->dev = dev; + bflow->method = iter->method; + bflow->state = BOOTFLOWST_BASE; + + return ops->get_bootflow(dev, iter, bflow); +} + +void bootdev_clear_bootflows(struct udevice *dev) +{ + struct bootdev_uc_plat *ucp = dev_get_uclass_plat(dev); + + while (!list_empty(&ucp->bootflow_head)) { + struct bootflow *bflow; + + bflow = list_first_entry(&ucp->bootflow_head, struct bootflow, + bm_node); + /* later bootflow_remove(bflow); */ + } +} + +static int bootdev_post_bind(struct udevice *dev) +{ + struct bootdev_uc_plat *ucp = dev_get_uclass_plat(dev); + + INIT_LIST_HEAD(&ucp->bootflow_head); + + return 0; +} + +static int bootdev_pre_unbind(struct udevice *dev) +{ + bootdev_clear_bootflows(dev); + + return 0; +} + +UCLASS_DRIVER(bootdev) = { + .id = UCLASS_BOOTDEV, + .name = "bootdev", + .flags = DM_UC_FLAG_SEQ_ALIAS, + .per_device_plat_auto = sizeof(struct bootdev_uc_plat), + .post_bind = bootdev_post_bind, + .pre_unbind = bootdev_pre_unbind, +}; diff --git a/doc/device-tree-bindings/bootdev.txt b/doc/device-tree-bindings/bootdev.txt new file mode 100644 index 00000000000..95b7fec8212 --- /dev/null +++ b/doc/device-tree-bindings/bootdev.txt @@ -0,0 +1,8 @@ +U-Boot boot device (bootdev) +============================ + +A bootdev provides a way to obtain a bootflow file from a device. It is a +child of the media device (UCLASS_MMC, UCLASS_SPI_FLASH, etc.) + +The bootdev driver is provided by the media devices. The bindings for each +are described in this file (to come). diff --git a/include/bootdev.h b/include/bootdev.h new file mode 100644 index 00000000000..3068cf309b9 --- /dev/null +++ b/include/bootdev.h @@ -0,0 +1,258 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ +/* + * Copyright 2021 Google LLC + * Written by Simon Glass + */ + +#ifndef __bootdev_h +#define __bootdev_h + +#include + +struct bootflow; +struct bootflow_iter; +struct udevice; + +/** + * enum bootdev_prio_t - priority of each bootdev + * + * These values are associated with each bootdev and set up by the driver. + * + * Smallest value is the highest priority. By default, bootdevs are scanned from + * highest to lowest priority + */ +enum bootdev_prio_t { + BOOTDEVP_0_INTERNAL_FAST = 10, + BOOTDEVP_1_INTERNAL_SLOW = 20, + BOOTDEVP_2_SCAN_FAST = 30, + BOOTDEVP_3_SCAN_SLOW = 40, + BOOTDEVP_4_NET_BASE = 50, + BOOTDEVP_5_NET_FALLBACK = 60, + BOOTDEVP_6_SYSTEM = 70, + + BOOTDEVP_COUNT, +}; + +/** + * struct bootdev_uc_plat - uclass information about a bootdev + * + * This is attached to each device in the bootdev uclass and accessible via + * dev_get_uclass_plat(dev) + * + * @bootflows: List of available bootflows for this bootdev + * @piro: Priority of this bootdev + */ +struct bootdev_uc_plat { + struct list_head bootflow_head; + enum bootdev_prio_t prio; +}; + +/** struct bootdev_ops - Operations for the bootdev uclass */ +struct bootdev_ops { + /** + * get_bootflow() - get a bootflow + * + * @dev: Bootflow device to check + * @iter: Provides current dev, part, method to get. Should update + * max_part if there is a partition table. Should update state, + * subdir, fname, buf, size according to progress + * @bflow: Updated bootflow if found + * @return 0 if OK, -ESHUTDOWN if there are no more bootflows on this + * device, -ENOSYS if this device doesn't support bootflows, + * other -ve value on other error + */ + int (*get_bootflow)(struct udevice *dev, struct bootflow_iter *iter, + struct bootflow *bflow); +}; + +#define bootdev_get_ops(dev) ((struct bootdev_ops *)(dev)->driver->ops) + +/** + * bootdev_get_bootflow() - get a bootflow + * + * @dev: Bootflow device to check + * @iter: Provides current part, method to get + * @bflow: Returns bootflow if found + * @return 0 if OK, -ESHUTDOWN if there are no more bootflows on this device, + * -ENOSYS if this device doesn't support bootflows, other -ve value on + * other error + */ +int bootdev_get_bootflow(struct udevice *dev, struct bootflow_iter *iter, + struct bootflow *bflow); + +/** + * bootdev_bind() - Bind a new named bootdev device + * + * @parent: Parent of the new device + * @drv_name: Driver name to use for the bootdev device + * @name: Name for the device (parent name is prepended) + * @devp: the new device (which has not been probed) + */ +int bootdev_bind(struct udevice *parent, const char *drv_name, const char *name, + struct udevice **devp); + +/** + * bootdev_find_in_blk() - Find a bootdev in a block device + * + * @dev: Bootflow device associated with this block device + * @blk: Block device to search + * @iter: Provides current dev, part, method to get. Should update + * max_part if there is a partition table + * @bflow: On entry, provides information about the partition and device to + * check. On exit, returns bootflow if found + * @return 0 if found, -ESHUTDOWN if no more bootflows, other -ve on error + */ +int bootdev_find_in_blk(struct udevice *dev, struct udevice *blk, + struct bootflow_iter *iter, struct bootflow *bflow); + +/** + * bootdev_list() - List all available bootdevs + * + * @probe: true to probe devices, false to leave them as is + */ +void bootdev_list(bool probe); + +/** + * bootdev_clear_bootflows() - Clear bootflows from a bootdev + * + * Each bootdev maintains a list of discovered bootflows. This provides a + * way to clear it. These bootflows are removed from the global list too. + * + * @dev: bootdev device to update + */ +void bootdev_clear_bootflows(struct udevice *dev); + +/** + * bootdev_add_bootflow() - Add a bootflow to the bootdev's list + * + * All fields in @bflow must be set up. Note that @bflow->dev is used to add the + * bootflow to that device. + * + * @dev: Bootdevice device to add to + * @bflow: Bootflow to add. Note that fields within bflow must be allocated + * since this function takes over ownership of these. This functions makes + * a copy of @bflow itself (without allocating its fields again), so the + * caller must dispose of the memory used by the @bflow pointer itself + * @return 0 if OK, -ENOMEM if out of memory + */ +int bootdev_add_bootflow(struct bootflow *bflow); + +/** + * bootdev_first_bootflow() - Get the first bootflow from a bootdev + * + * Returns the first bootflow attached to a bootdev + * + * @dev: bootdev device + * @bflowp: Returns a pointer to the bootflow + * @return 0 if found, -ENOENT if there are no bootflows + */ +int bootdev_first_bootflow(struct udevice *dev, struct bootflow **bflowp); + +/** + * bootdev_next_bootflow() - Get the next bootflow from a bootdev + * + * Returns the next bootflow attached to a bootdev + * + * @bflowp: On entry, the last bootflow returned , e.g. from + * bootdev_first_bootflow() + * @return 0 if found, -ENOENT if there are no more bootflows + */ +int bootdev_next_bootflow(struct bootflow **bflowp); + +/** + * bootdev_find_by_label() - Look up a bootdev by label + * + * Each bootdev has a label which contains the media-uclass name and a number, + * e.g. 'mmc2'. This looks up the label and returns the associated bootdev + * + * The lookup is performed based on the media device's sequence number. So for + * 'mmc2' this looks for a device in UCLASS_MMC with a dev_seq() of 2. + * + * @label: Label to look up (e.g. "mmc1" or "mmc0") + * @devp: Returns the bootdev device found, or NULL if none (note it does not + * return the media device, but its bootdev child) + * @return 0 if OK, -EINVAL if the uclass is not supported by this board, + * -ENOENT if there is no device with that number + */ +int bootdev_find_by_label(const char *label, struct udevice **devp); + +/** + * bootdev_find_by_any() - Find a bootdev by name, label or sequence + * + * @name: name (e.g. "mmc2.bootdev"), label ("mmc2"), or sequence ("2") to find + * @devp: returns the device found, on success + * @return 0 if OK, -ve on error + */ +int bootdev_find_by_any(const char *name, struct udevice **devp); + +#if CONFIG_IS_ENABLED(BOOTSTD) +/** + * bootdev_setup_for_dev() - Bind a new bootdev device + * + * Creates a bootdev device as a child of @parent. This should be called from + * the driver's bind() method or its uclass' post_bind() method. + * + * If a child bootdev already exists, this function does nothing + * + * @parent: Parent device (e.g. MMC or Ethernet) + * @drv_name: Name of bootdev driver to bind + * @return 0 if OK, -ve on error + */ +int bootdev_setup_for_dev(struct udevice *parent, const char *drv_name); + +/** + * bootdev_setup_for_blk() - Bind a new bootdev device for a blk device + * + * Creates a bootdev device as a sibling of @blk. This should be called from + * the driver's bind() method or its uclass' post_bind() method, at the same + * time as the bould device is bound + * + * If a device of the same name already exists, this function does nothing + * + * @parent: Parent device (e.g. MMC or Ethernet) + * @drv_name: Name of bootdev driver to bind + * @return 0 if OK, -ve on error + */ +int bootdev_setup_sibling_blk(struct udevice *blk, const char *drv_name); + +/** + * bootdev_get_sibling_blk() - Locate the block device for a bootdev + * + * @dev: bootdev to check + * @blkp: returns associated block device + * @return 0 if OK, -EINVAL if @dev is not a bootdev device, other -ve on other + * error + */ +int bootdev_get_sibling_blk(struct udevice *dev, struct udevice **blkp); + +/** + * bootdev_unbind_dev() - Unbind a bootdev device + * + * Remove and unbind a bootdev device which is a child of @parent. This should + * be called from the driver's unbind() method or its uclass' post_bind() + * method. + * + * @parent: Parent device (e.g. MMC or Ethernet) + * @return 0 if OK, -ve on error + */ +int bootdev_unbind_dev(struct udevice *parent); +#else +static inline int bootdev_setup_for_dev(struct udevice *parent, + const char *drv_name) +{ + return 0; +} + +static inline int bootdev_setup_sibling_blk(struct udevice *blk, + const char *drv_name) +{ + return 0; +} + +static inline int bootdev_unbind_dev(struct udevice *parent) +{ + return 0; +} +#endif + +#endif diff --git a/include/dm/uclass-id.h b/include/dm/uclass-id.h index 17383fc38c1..03912cb0db8 100644 --- a/include/dm/uclass-id.h +++ b/include/dm/uclass-id.h @@ -38,6 +38,7 @@ enum uclass_id { UCLASS_AXI, /* AXI bus */ UCLASS_BLK, /* Block device */ UCLASS_BOOTCOUNT, /* Bootcount backing store */ + UCLASS_BOOTDEV, /* Boot device for locating an OS to boot */ UCLASS_BOOTSTD, /* Standard boot driver */ UCLASS_BUTTON, /* Button */ UCLASS_CACHE, /* Cache controller */ -- 2.33.0.1079.g6e70778dc9-goog