From patchwork Wed Dec 7 08:51:28 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1713155 X-Patchwork-Delegate: trini@ti.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.a=rsa-sha256 header.s=google header.b=A9+YZA+y; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4NRs0D2n1Bz23ns for ; Wed, 7 Dec 2022 20:08:44 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id A076385743; Wed, 7 Dec 2022 09:57:40 +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="A9+YZA+y"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id AA3C585745; Wed, 7 Dec 2022 09:57:38 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE, SPF_PASS autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-pj1-x1035.google.com (mail-pj1-x1035.google.com [IPv6:2607:f8b0:4864:20::1035]) (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 4CC5B855D5 for ; Wed, 7 Dec 2022 09:57:27 +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-pj1-x1035.google.com with SMTP id w4-20020a17090ac98400b002186f5d7a4cso873379pjt.0 for ; Wed, 07 Dec 2022 00:57:27 -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=smcfIlXH9+UKbDrcnfvkWjhkmqsqUV6pK5Vzw9G1I7k=; b=A9+YZA+yA+ITQAx7mw8xZqwhF+wVzRyCurfmGsGF2wFxpZsJf6S1tha1QuKTBaBPJH MCbZnL6uVIZN366v/hZdNZ5PzBqXYxvV93js2vSfvDU/eBocoj+d9B148LY3JWnCwIaz GwD6papb4lUuQOaSdmWG4naGgwWBpzNS6fyPY= 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=smcfIlXH9+UKbDrcnfvkWjhkmqsqUV6pK5Vzw9G1I7k=; b=AwBA+KtGK3BAsxhC0HmEGaK82gCP0+tJgd1jbRFXi0YdTswHa4EhdU17ugggf1i2pB NnniPeCn+2pGMa4+5ZVv5mcDsUGJXAOAG57cpO8Za4i/4qkm5fP2nL+jv0IqU2B4qGVh 2BD+wvK9fnb/CXxoHN7xYD5sajTilHJU+ruc39PAAYrF7dBKBvf/eQ9evhjmhvxDPE9C rLUQDMzjoMRcw0DvYcKD+DXWwT4jYCzH+6kwy1x0cTZiE8uHodUJVymv2LA01zOjb+LC 7iAcnd43sgt0wmKeuabBIjgJwWntPCILPzFojnyyUlnA43fG6XILQjz6NbWwisIFVSH5 FDvA== X-Gm-Message-State: ANoB5pkt+lbLOxgBr9GUTp1QPgnUCoIq9z7kiOzFCDo4bWyfval2u4nM t0A5ClMj+0bWvHAy8Rwd76pGRUqcW4KK+jVm X-Google-Smtp-Source: AA0mqf4il64K4VJ4Ao1Pnd3akE/m0FWrhgxAb9MJa0Usbc7t2yw900vHVtIu4SVXerejr2oMXIakXA== X-Received: by 2002:a17:902:b40b:b0:188:ca57:ce0c with SMTP id x11-20020a170902b40b00b00188ca57ce0cmr79318575plr.57.1670403446508; Wed, 07 Dec 2022 00:57:26 -0800 (PST) Received: from localhost.localdomain ([27.110.126.54]) by smtp.gmail.com with ESMTPSA id l16-20020a170903121000b0018157b415dbsm14145514plh.63.2022.12.07.00.57.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 Dec 2022 00:57:26 -0800 (PST) From: Simon Glass To: U-Boot Mailing List Cc: U-Boot Custodians , Simon Glass Subject: [PATCH 62/71] bootstd: Allow iterating to the next bootdev priortiy Date: Wed, 7 Dec 2022 21:51:28 +1300 Message-Id: <20221207085137.445249-63-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 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 function which moves to the next priority to be processed. This works by storing the current priority in the bootflow iterator. The logic to set this up is included in a subsequent commit. Signed-off-by: Simon Glass --- boot/bootdev-uclass.c | 64 +++++++++++++++++++++++++++++++++ include/bootdev.h | 14 ++++++++ include/bootflow.h | 3 ++ test/boot/bootdev.c | 84 +++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 165 insertions(+) diff --git a/boot/bootdev-uclass.c b/boot/bootdev-uclass.c index ae08430ca8c..63005140061 100644 --- a/boot/bootdev-uclass.c +++ b/boot/bootdev-uclass.c @@ -585,6 +585,70 @@ int bootdev_next_label(struct bootflow_iter *iter, struct udevice **devp, return 0; } +int bootdev_next_prio(struct bootflow_iter *iter, struct udevice **devp) +{ + struct udevice *dev = *devp; + bool found; + int ret; + + /* find the next device with this priority */ + *devp = NULL; + log_debug("next prio %d: dev=%p/%s\n", iter->cur_prio, dev, + dev ? dev->name : "none"); + do { + /* + * Don't probe devices here since they may not be of the + * required priority + */ + if (!dev) + uclass_find_first_device(UCLASS_BOOTDEV, &dev); + else + uclass_find_next_device(&dev); + found = false; + + /* scan for the next device with the correct priority */ + while (dev) { + struct bootdev_uc_plat *plat; + + plat = dev_get_uclass_plat(dev); + log_debug("- %s: %d, want %d\n", dev->name, plat->prio, + iter->cur_prio); + if (plat->prio == iter->cur_prio) + break; + uclass_find_next_device(&dev); + } + + /* none found for this priority, so move to the next */ + if (!dev) { + log_debug("None found at prio %d, moving to %d\n", + iter->cur_prio, iter->cur_prio + 1); + if (++iter->cur_prio == BOOTDEVP_COUNT) + return log_msg_ret("fin", -ENODEV); + + if (iter->flags & BOOTFLOWF_HUNT) { + /* hunt to find new bootdevs */ + ret = bootdev_hunt_prio(iter->cur_prio, + iter->flags & + BOOTFLOWF_SHOW); + log_debug("- hunt ret %d\n", ret); + if (ret) + return log_msg_ret("hun", ret); + } + } else { + ret = device_probe(dev); + if (ret) { + log_debug("Device '%s' failed to probe\n", + dev->name); + dev = NULL; + } + } + } while (!dev); + + *devp = dev; + + return 0; +} + /** * h_cmp_bootdev() - Compare two bootdevs to find out which should go first * diff --git a/include/bootdev.h b/include/bootdev.h index 300bc736427..4b6a8eb8d8f 100644 --- a/include/bootdev.h +++ b/include/bootdev.h @@ -349,6 +349,20 @@ int bootdev_hunt_and_find_by_label(const char *label, struct udevice **devp, int bootdev_next_label(struct bootflow_iter *iter, struct udevice **devp, int *method_flagsp); +/** + * bootdev_next_prio() - Find the next bootdev in priority order + * + * This moves @devp to the next bootdev with the current priority. If there is + * none, then it moves to the next priority and scans for new bootdevs there. + * + * @iter: Interation info, containing iter->cur_prio + * @devp: On entry this is the previous bootdev that was considered. On exit + * this is the new bootdev, if any was found + * Returns 0 on success (*devp is updated), -ENODEV if there are no more + * bootdevs at any priority + */ +int bootdev_next_prio(struct bootflow_iter *iter, struct udevice **devp); + #if CONFIG_IS_ENABLED(BOOTSTD) /** * bootdev_setup_for_dev() - Bind a new bootdev device (deprecated) diff --git a/include/bootflow.h b/include/bootflow.h index 5d845b3a6f0..953a9776a29 100644 --- a/include/bootflow.h +++ b/include/bootflow.h @@ -7,6 +7,7 @@ #ifndef __bootflow_h #define __bootflow_h +#include #include /** @@ -169,6 +170,7 @@ enum bootflow_meth_flags_t { * @num_methods: Number of bootmeth devices in @method_order * @cur_method: Current method number, an index into @method_order * @first_glob_method: First global method, if any, else -1 + * @cur_prio: Current priority being scanned * @method_order: List of bootmeth devices to use, in order. The normal methods * appear first, then the global ones, if any * @doing_global: true if we are iterating through the global bootmeths (which @@ -192,6 +194,7 @@ struct bootflow_iter { int num_methods; int cur_method; int first_glob_method; + enum bootdev_prio_t cur_prio; struct udevice **method_order; bool doing_global; int method_flags; diff --git a/test/boot/bootdev.c b/test/boot/bootdev.c index 608aef15265..1090b92e510 100644 --- a/test/boot/bootdev.c +++ b/test/boot/bootdev.c @@ -588,3 +588,87 @@ static int bootdev_test_next_label(struct unit_test_state *uts) } BOOTSTD_TEST(bootdev_test_next_label, UT_TESTF_DM | UT_TESTF_SCAN_FDT | UT_TESTF_ETH_BOOTDEV | UT_TESTF_SF_BOOTDEV); + + +/* Check iterating to the next prioirty in a list */ +static int bootdev_test_next_prio(struct unit_test_state *uts) +{ + struct bootflow_iter iter; + struct bootstd_priv *std; + struct bootflow bflow; + struct udevice *dev; + int ret; + + sandbox_set_eth_enable(false); + test_set_skip_delays(true); + + /* get access to the used hunters */ + ut_assertok(bootstd_get_priv(&std)); + + memset(&iter, '\0', sizeof(iter)); + memset(&bflow, '\0', sizeof(bflow)); + iter.part = 0; + uclass_first_device(UCLASS_BOOTMETH, &bflow.method); + iter.cur_prio = 0; + iter.flags = BOOTFLOWF_SHOW; + + dev = NULL; + console_record_reset_enable(); + ut_assertok(bootdev_next_prio(&iter, &dev)); + ut_assertnonnull(dev); + ut_asserteq_str("mmc2.bootdev", dev->name); + + /* hunt flag not set, so this should not use any hunters */ + ut_asserteq(0, std->hunters_used); + ut_assert_console_end(); + + /* now try again with hunting enabled */ + iter.flags = BOOTFLOWF_SHOW | BOOTFLOWF_HUNT; + iter.cur_prio = 0; + iter.part = 0; + + ut_assertok(bootdev_next_prio(&iter, &dev)); + ut_asserteq_str("mmc2.bootdev", dev->name); + ut_assert_nextline("Hunting with: mmc"); + ut_assert_console_end(); + + ut_assertok(bootstd_test_check_mmc_hunter(uts)); + + ut_assertok(bootdev_next_prio(&iter, &dev)); + ut_asserteq_str("mmc1.bootdev", dev->name); + + ut_assertok(bootdev_next_prio(&iter, &dev)); + ut_asserteq_str("mmc0.bootdev", dev->name); + ut_assert_console_end(); + + ut_assertok(bootdev_next_prio(&iter, &dev)); + ut_asserteq_str("spi.bin@0.bootdev", dev->name); + ut_assert_skip_to_line("Hunting with: spi_flash"); + + /* + * this scans all bootdevs of priority BOOTDEVP_4_SCAN_FAST before it + * starts looking at the devices, so we se virtio as well + */ + ut_assert_nextline("Hunting with: virtio"); + ut_assert_nextlinen("SF: Detected m25p16"); + + ut_assertok(bootdev_next_prio(&iter, &dev)); + ut_asserteq_str("spi.bin@1.bootdev", dev->name); + ut_assert_nextlinen("SF: Detected m25p16"); + ut_assert_console_end(); + + /* keep going until there are no more bootdevs */ + do { + ret = bootdev_next_prio(&iter, &dev); + } while (!ret); + ut_asserteq(-ENODEV, ret); + ut_assertnull(dev); + ut_asserteq(GENMASK(7, 0), std->hunters_used); + + ut_assert_skip_to_line("Hunting with: ethernet"); + ut_assert_console_end(); + + return 0; +} +BOOTSTD_TEST(bootdev_test_next_prio, UT_TESTF_DM | UT_TESTF_SCAN_FDT | + UT_TESTF_SF_BOOTDEV);