From patchwork Wed Dec 7 08:51:34 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1713159 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=S6zhsP50; 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 4NRs1G58Klz23ns for ; Wed, 7 Dec 2022 20:09:38 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id BC16385766; Wed, 7 Dec 2022 09:57:56 +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="S6zhsP50"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 906B685710; Wed, 7 Dec 2022 09:57:51 +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-pg1-x52e.google.com (mail-pg1-x52e.google.com [IPv6:2607:f8b0:4864:20::52e]) (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 E923285662 for ; Wed, 7 Dec 2022 09:57:46 +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-pg1-x52e.google.com with SMTP id q1so15666470pgl.11 for ; Wed, 07 Dec 2022 00:57:46 -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=pqr4mEBFwpE5z2MUMuk6ipFyUPz4AghKu+f3Od27xlU=; b=S6zhsP50N7szU9QLVbmlsiJSHf8MNZBZdze27DWmVG+GsQQ69OyNb4Mp3EBiAUbGsb xm7mHjzXMK3JZ50AXIrniyNSs368McMoQmzawgXnTlfAUz3nOFKWd2fLSw/NKfpqp3QO SP+Koy1QushvQvfH5x85ID1EHEk7xwQyKQBD0= 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=pqr4mEBFwpE5z2MUMuk6ipFyUPz4AghKu+f3Od27xlU=; b=Z4pdBuHauNDG39QYk2GxZFCuZJt/63vaOTnIPfvoR7nSTNX1BVeyqRXJUUIn27gDtf r7lRkLyUr0Mwg0cMsliwSrbZmWb2h6NHZkluEDfauFZPHxOMFpO3bYx3g/bbF/qA5xt/ GFUIYwHvmywIr2YroOROXgCNJTRFqNUy/eT03TfrGTuIJlXFvJ50qWiOBhnssDTDcGN9 HcVjzpL3zKp1wPSSblIUNbg01t/UbgDD69o0iXBkORhAU5RGh6K4y5+cPH29o7sHBuH0 PN9OnGB38wXtqDZ7zG7KzeKgjjgIHXnakkKbJSQP4jRGJ+MczjMRe97R+N0k3S2kv6J6 Of3w== X-Gm-Message-State: ANoB5pl3AUskfx+9Kd9SKKN9EHNwxORkIJlD5HAwFTCS7t+weZlPTdbl maGfD4EbgujSqMwtJQWK/9Dmsc/yYMCbHQ+9 X-Google-Smtp-Source: AA0mqf6HHpxu/Oeym2gaZD01F3fN+ocnqH2J8aectQxF8bkCsbmF9DhlxBQcx2v/a8YzKrCyEQEdZQ== X-Received: by 2002:a65:64d1:0:b0:478:980a:53fb with SMTP id t17-20020a6564d1000000b00478980a53fbmr17636972pgv.484.1670403465037; Wed, 07 Dec 2022 00:57:45 -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.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 Dec 2022 00:57:44 -0800 (PST) From: Simon Glass To: U-Boot Mailing List Cc: U-Boot Custodians , Simon Glass Subject: [PATCH 68/71] bootstd: Record the bootdevs used during scanning Date: Wed, 7 Dec 2022 21:51:34 +1300 Message-Id: <20221207085137.445249-69-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 way to record the bootdevs used when scanning for bootflows. This is useful for testing. Enable this only with BOOTSTD_FULL and do the same for the progress reporting. Re-enable and update the affected tests now that we have this feature. For bootdev_test_order_default() there is no-longer any support for using the bootdev aliases to specify an ordering, so drop that part of the test. Signed-off-by: Simon Glass --- boot/bootflow.c | 29 +++++++++++++------- include/bootflow.h | 10 ++++++- test/boot/bootdev.c | 67 +++++++++++++++++++++++---------------------- 3 files changed, 63 insertions(+), 43 deletions(-) diff --git a/boot/bootflow.c b/boot/bootflow.c index 61a4f16599c..a351dc5fdf1 100644 --- a/boot/bootflow.c +++ b/boot/bootflow.c @@ -88,6 +88,9 @@ void bootflow_iter_init(struct bootflow_iter *iter, int flags) memset(iter, '\0', sizeof(*iter)); iter->first_glob_method = -1; iter->flags = flags; + + /* remember the first bootdevs we see */ + iter->max_devs = BOOTFLOW_MAX_USED_DEVS; } void bootflow_iter_uninit(struct bootflow_iter *iter) @@ -131,16 +134,22 @@ static void bootflow_iter_set_dev(struct bootflow_iter *iter, iter->dev = dev; iter->method_flags = method_flags; - if ((iter->flags & (BOOTFLOWF_SHOW | BOOTFLOWF_SINGLE_DEV)) == - BOOTFLOWF_SHOW) { - if (dev) - printf("Scanning bootdev '%s':\n", dev->name); - else if (IS_ENABLED(CONFIG_BOOTMETH_GLOBAL) && - ucp->flags & BOOTMETHF_GLOBAL) - printf("Scanning global bootmeth '%s':\n", - iter->method->name); - else - printf("No more bootdevs\n"); + if (IS_ENABLED(CONFIG_BOOTSTD_FULL)) { + /* record the device for later */ + if (dev && iter->num_devs < iter->max_devs) + iter->dev_used[iter->num_devs++] = dev; + + if ((iter->flags & (BOOTFLOWF_SHOW | BOOTFLOWF_SINGLE_DEV)) == + BOOTFLOWF_SHOW) { + if (dev) + printf("Scanning bootdev '%s':\n", dev->name); + else if (IS_ENABLED(CONFIG_BOOTMETH_GLOBAL) && + ucp->flags & BOOTMETHF_GLOBAL) + printf("Scanning global bootmeth '%s':\n", + iter->method->name); + else + printf("No more bootdevs\n"); + } } } diff --git a/include/bootflow.h b/include/bootflow.h index 5b0bdc7e684..d96afc249cf 100644 --- a/include/bootflow.h +++ b/include/bootflow.h @@ -10,6 +10,10 @@ #include #include +enum { + BOOTFLOW_MAX_USED_DEVS = 16, +}; + /** * enum bootflow_state_t - states that a particular bootflow can be in * @@ -162,7 +166,9 @@ enum bootflow_meth_flags_t { * @err: Error obtained from checking the last iteration. This is used to skip * forward (e.g. to skip the current partition because it is not valid) * -ESHUTDOWN: try next bootdev - * @num_devs: Number of bootdevs in @dev_order + * @num_devs: Number of bootdevs in @dev_used + * @max_devs: Maximum number of entries in @dev_used + * @dev_used: List of bootdevs used during iteration * @labels: List of labels to scan for bootdevs * @cur_label: Current label being processed * @num_methods: Number of bootmeth devices in @method_order @@ -185,6 +191,8 @@ struct bootflow_iter { int first_bootable; int err; int num_devs; + int max_devs; + struct udevice *dev_used[BOOTFLOW_MAX_USED_DEVS]; const char *const *labels; int cur_label; int num_methods; diff --git a/test/boot/bootdev.c b/test/boot/bootdev.c index 5d5ce7f48cf..ef5215bbcec 100644 --- a/test/boot/bootdev.c +++ b/test/boot/bootdev.c @@ -186,7 +186,6 @@ static int bootdev_test_any(struct unit_test_state *uts) BOOTSTD_TEST(bootdev_test_any, UT_TESTF_DM | UT_TESTF_SCAN_FDT | UT_TESTF_ETH_BOOTDEV); -#if 0 /* disable for now */ /* Check bootdev ordering with the bootdev-order property */ static int bootdev_test_order(struct unit_test_state *uts) { @@ -205,18 +204,29 @@ static int bootdev_test_order(struct unit_test_state *uts) ut_assertok(env_set("boot_targets", NULL)); ut_assertok(bootflow_scan_first(NULL, NULL, &iter, 0, &bflow)); ut_asserteq(2, iter.num_devs); - ut_asserteq_str("mmc2.bootdev", iter.dev_order[0]->name); - ut_asserteq_str("mmc1.bootdev", iter.dev_order[1]->name); + ut_asserteq_str("mmc2.bootdev", iter.dev_used[0]->name); + ut_asserteq_str("mmc1.bootdev", iter.dev_used[1]->name); bootflow_iter_uninit(&iter); /* Use the environment variable to override it */ ut_assertok(env_set("boot_targets", "mmc1 mmc2")); ut_assertok(bootflow_scan_first(NULL, NULL, &iter, 0, &bflow)); + ut_asserteq(-ENODEV, bootflow_scan_next(&iter, &bflow)); ut_asserteq(2, iter.num_devs); - ut_asserteq_str("mmc1.bootdev", iter.dev_order[0]->name); - ut_asserteq_str("mmc2.bootdev", iter.dev_order[1]->name); + ut_asserteq_str("mmc1.bootdev", iter.dev_used[0]->name); + ut_asserteq_str("mmc2.bootdev", iter.dev_used[1]->name); bootflow_iter_uninit(&iter); + return 0; +} +BOOTSTD_TEST(bootdev_test_order, UT_TESTF_DM | UT_TESTF_SCAN_FDT); + +/* Check default bootdev ordering */ +static int bootdev_test_order_default(struct unit_test_state *uts) +{ + struct bootflow_iter iter; + struct bootflow bflow; + /* * Now drop both orderings, to check the default (prioriy/sequence) * ordering @@ -225,30 +235,18 @@ static int bootdev_test_order(struct unit_test_state *uts) ut_assertok(bootstd_test_drop_bootdev_order(uts)); ut_assertok(bootflow_scan_first(NULL, NULL, &iter, 0, &bflow)); - ut_asserteq(3, iter.num_devs); - ut_asserteq_str("mmc2.bootdev", iter.dev_order[0]->name); - ut_asserteq_str("mmc1.bootdev", iter.dev_order[1]->name); - ut_asserteq_str("mmc0.bootdev", iter.dev_order[2]->name); - - /* - * Check that adding aliases for the bootdevs works. We just fake it by - * setting the sequence numbers directly. - */ - iter.dev_order[0]->seq_ = 0; - iter.dev_order[1]->seq_ = 3; - iter.dev_order[2]->seq_ = 2; - bootflow_iter_uninit(&iter); + ut_asserteq(2, iter.num_devs); + ut_asserteq_str("mmc2.bootdev", iter.dev_used[0]->name); + ut_asserteq_str("mmc1.bootdev", iter.dev_used[1]->name); - ut_assertok(bootflow_scan_first(NULL, NULL, &iter, 0, &bflow)); + ut_asserteq(-ENODEV, bootflow_scan_next(&iter, &bflow)); ut_asserteq(3, iter.num_devs); - ut_asserteq_str("mmc2.bootdev", iter.dev_order[0]->name); - ut_asserteq_str("mmc0.bootdev", iter.dev_order[1]->name); - ut_asserteq_str("mmc1.bootdev", iter.dev_order[2]->name); + ut_asserteq_str("mmc0.bootdev", iter.dev_used[2]->name); bootflow_iter_uninit(&iter); return 0; } -BOOTSTD_TEST(bootdev_test_order, UT_TESTF_DM | UT_TESTF_SCAN_FDT); +BOOTSTD_TEST(bootdev_test_order_default, UT_TESTF_DM | UT_TESTF_SCAN_FDT); /* Check bootdev ordering with the uclass priority */ static int bootdev_test_prio(struct unit_test_state *uts) @@ -260,6 +258,9 @@ static int bootdev_test_prio(struct unit_test_state *uts) test_set_skip_delays(true); + /* disable ethernet since the hunter will run dhcp */ + test_set_eth_enable(false); + /* Start up USB which gives us three additional bootdevs */ usb_started = false; ut_assertok(run_command("usb start", 0)); @@ -269,30 +270,32 @@ static int bootdev_test_prio(struct unit_test_state *uts) /* 3 MMC and 3 USB bootdevs: MMC should come before USB */ console_record_reset_enable(); ut_assertok(bootflow_scan_first(NULL, NULL, &iter, 0, &bflow)); + ut_asserteq(-ENODEV, bootflow_scan_next(&iter, &bflow)); ut_asserteq(6, iter.num_devs); - ut_asserteq_str("mmc2.bootdev", iter.dev_order[0]->name); + ut_asserteq_str("mmc2.bootdev", iter.dev_used[0]->name); ut_asserteq_str("usb_mass_storage.lun0.bootdev", - iter.dev_order[3]->name); + iter.dev_used[3]->name); - ut_assertok(bootdev_get_sibling_blk(iter.dev_order[3], &blk)); + ut_assertok(bootdev_get_sibling_blk(iter.dev_used[3], &blk)); ut_asserteq_str("usb_mass_storage.lun0", blk->name); /* adjust the priority of the first USB bootdev to the highest */ - ucp = dev_get_uclass_plat(iter.dev_order[3]); - ucp->prio = 1; + ucp = dev_get_uclass_plat(iter.dev_used[3]); + ucp->prio = BOOTDEVP_1_PRE_SCAN; + /* try again but enable hunting, which brings in SCSI */ bootflow_iter_uninit(&iter); ut_assertok(bootflow_scan_first(NULL, NULL, &iter, BOOTFLOWF_HUNT, &bflow)); - ut_asserteq(6, iter.num_devs); + ut_asserteq(-ENODEV, bootflow_scan_next(&iter, &bflow)); + ut_asserteq(7, iter.num_devs); ut_asserteq_str("usb_mass_storage.lun0.bootdev", - iter.dev_order[0]->name); - ut_asserteq_str("mmc2.bootdev", iter.dev_order[1]->name); + iter.dev_used[0]->name); + ut_asserteq_str("mmc2.bootdev", iter.dev_used[1]->name); return 0; } BOOTSTD_TEST(bootdev_test_prio, UT_TESTF_DM | UT_TESTF_SCAN_FDT); -#endif /* Check listing hunters */ static int bootdev_test_hunter(struct unit_test_state *uts)