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 4B16BC54EBC for ; Sun, 8 Jan 2023 02:58:24 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 52D3D8570C; Sun, 8 Jan 2023 03:53:21 +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="nALOeo8W"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 611C5856D6; Sun, 8 Jan 2023 03:52:39 +0100 (CET) Received: from mail-il1-x131.google.com (mail-il1-x131.google.com [IPv6:2607:f8b0:4864:20::131]) (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 98A35855FE for ; Sun, 8 Jan 2023 03:51:15 +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-il1-x131.google.com with SMTP id y2so3294632ily.5 for ; Sat, 07 Jan 2023 18:51:15 -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=R3bJ8eyurxBh7oJS+b1z4yQS9VZcWMK1XlgD4Nuv19g=; b=nALOeo8WK4Up0srE0XESUg/vPeQOECN+St7y1g5hOAR1LZdpoEb9DA84kQxwqu5mwP mvOQyJWaOUOmQFOi9OnfCSkcTefJMWhILiTOfpEDi8rkszccW10eM5YsP1PtsttOYw+G HIkm9ANkHslJGk08dGwyDDqU4PUUA++QwbFVg= 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=R3bJ8eyurxBh7oJS+b1z4yQS9VZcWMK1XlgD4Nuv19g=; b=6lFIQAwugxNyOH+8Cz/0s/npDzDvyH6BTKB6cFPhKKQYh2RlVvIyLAI2GSydLNwsBr Fce+2SEPDUNzYr9lGjAaxRpJeIhVpWfLOlxmFDHhF2GAtEZo862LmbOZFdpPbTH+tchb EockALrh29f9XTo1ISFrirrZDwRXAPwz6VeC8m5Fk67xQCvKHwgJhUX5mBk+yMNPwz8/ iKBSwVZ2KfQSXdplIrTjztNhTVCulXzMseTzy9IaL3khsUTQe/1ERkHEFnWfVVnXchSN tjqtOSxPxfY/siLkD4/nFibTw6YWsXKjxZu0xCaJOO6UfGXV2fI2EqQg0gQKttNki94K 1QYw== X-Gm-Message-State: AFqh2kobycKXzeSPkiSUPpN9AWiGTdolay0x8gEfrkOniENesBHK5ty1 NA8aTrwz1e2dwK6jCTIHJyeOMbpSsKAM3XtD X-Google-Smtp-Source: AMrXdXvcLhb73ur5HLpm5IoK1EJYcc4qqABbtD4vbk04jGIrLNV3y+yK3qdmt9ItTyr5xdiSnjWOpA== X-Received: by 2002:a92:c60e:0:b0:304:b79a:5008 with SMTP id p14-20020a92c60e000000b00304b79a5008mr44835595ilm.29.1673146275078; Sat, 07 Jan 2023 18:51:15 -0800 (PST) Received: from sjg1.roam.corp.google.com (c-71-56-217-229.hsd1.co.comcast.net. [71.56.217.229]) by smtp.gmail.com with ESMTPSA id c17-20020a92bd11000000b00302a00aaefasm1622174ile.26.2023.01.07.18.51.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 07 Jan 2023 18:51:14 -0800 (PST) From: Simon Glass To: U-Boot Mailing List Cc: U-Boot Custodians , Simon Glass Subject: [PATCH v2 24/71] bootstd: Support running bootdev hunters Date: Sat, 7 Jan 2023 19:50:00 -0700 Message-Id: <20230108025047.522240-25-sjg@chromium.org> X-Mailer: git-send-email 2.39.0.314.g84b9a713c41-goog In-Reply-To: <20230108025047.522240-1-sjg@chromium.org> References: <20230108025047.522240-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 way to run a bootdev hunter to find bootdevs of a certain type. Add this to the 'bootdev hunt' command. Test for this are added in a later patch, since a useful test needs some hunters to work with. Signed-off-by: Simon Glass --- (no changes since v1) boot/bootdev-uclass.c | 61 +++++++++++++++++++++++++++++++++++++++++++ cmd/bootdev.c | 7 ++++- include/bootdev.h | 14 ++++++++++ test/boot/bootdev.c | 3 +++ 4 files changed, 84 insertions(+), 1 deletion(-) diff --git a/boot/bootdev-uclass.c b/boot/bootdev-uclass.c index 62eb0b617cd..081b94ce332 100644 --- a/boot/bootdev-uclass.c +++ b/boot/bootdev-uclass.c @@ -636,6 +636,67 @@ int bootdev_setup_iter_order(struct bootflow_iter *iter, struct udevice **devp) return 0; } +static int bootdev_hunt_drv(struct bootdev_hunter *info, uint seq, bool show) +{ + const char *name = uclass_get_name(info->uclass); + struct bootstd_priv *std; + int ret; + + ret = bootstd_get_priv(&std); + if (ret) + return log_msg_ret("std", ret); + + if (!(std->hunters_used & BIT(seq))) { + if (show) + printf("Hunting with: %s\n", + uclass_get_name(info->uclass)); + log_debug("Hunting with: %s\n", name); + if (info->hunt) { + ret = info->hunt(info, show); + if (ret) + return ret; + } + std->hunters_used |= BIT(seq); + } + + return 0; +} + +int bootdev_hunt(const char *spec, bool show) +{ + struct bootdev_hunter *start; + const char *end; + int n_ent, i; + int result; + size_t len; + + start = ll_entry_start(struct bootdev_hunter, bootdev_hunter); + n_ent = ll_entry_count(struct bootdev_hunter, bootdev_hunter); + result = 0; + + len = SIZE_MAX; + if (spec) { + trailing_strtoln_end(spec, NULL, &end); + len = end - spec; + } + + for (i = 0; i < n_ent; i++) { + struct bootdev_hunter *info = start + i; + const char *name = uclass_get_name(info->uclass); + int ret; + + log_debug("looking at %.*s for %s\n", + (int)max(strlen(name), len), spec, name); + if (spec && strncmp(spec, name, max(strlen(name), len))) + continue; + ret = bootdev_hunt_drv(info, i, show); + if (ret) + result = ret; + } + + return result; +} + void bootdev_list_hunters(struct bootstd_priv *std) { struct bootdev_hunter *orig, *start; diff --git a/cmd/bootdev.c b/cmd/bootdev.c index 80bfe2812e4..28866faac76 100644 --- a/cmd/bootdev.c +++ b/cmd/bootdev.c @@ -128,7 +128,12 @@ static int do_bootdev_hunt(struct cmd_tbl *cmdtp, int flag, int argc, if (list) { bootdev_list_hunters(priv); } else { - /* TODO: implement hunting */ + ret = bootdev_hunt(spec, true); + if (ret) { + printf("Failed (err=%dE)\n", ret); + + return CMD_RET_FAILURE; + } } return 0; diff --git a/include/bootdev.h b/include/bootdev.h index cafb5285a28..deef7890489 100644 --- a/include/bootdev.h +++ b/include/bootdev.h @@ -263,6 +263,20 @@ int bootdev_setup_iter_order(struct bootflow_iter *iter, struct udevice **devp); */ void bootdev_list_hunters(struct bootstd_priv *std); +/** + * bootdev_hunt() - Hunt for bootdevs matching a particular spec + * + * This runs the selected hunter (or all if @spec is NULL) to try to find new + * bootdevs. + * + * @spec: Spec to match, e.g. "mmc0", or NULL for any. If provided, this must + * match a uclass name so that the hunter can be determined. Any trailing number + * is ignored + * @show: true to show each hunter before using it + * Returns: 0 if OK, -ve on error + */ +int bootdev_hunt(const char *spec, bool show); + #if CONFIG_IS_ENABLED(BOOTSTD) /** * bootdev_setup_for_dev() - Bind a new bootdev device (deprecated) diff --git a/test/boot/bootdev.c b/test/boot/bootdev.c index a8ca12a3c8f..45a00c34c0c 100644 --- a/test/boot/bootdev.c +++ b/test/boot/bootdev.c @@ -237,6 +237,9 @@ static int bootdev_test_hunter(struct unit_test_state *uts) ut_assert_nextline("(total hunters: 0)"); ut_assert_console_end(); + ut_assertok(bootdev_hunt("mmc1", false)); + ut_assert_console_end(); + return 0; } BOOTSTD_TEST(bootdev_test_hunter, UT_TESTF_DM | UT_TESTF_SCAN_FDT); -- 2.39.0.314.g84b9a713c41-goog