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 0D801C433EF for ; Wed, 20 Jul 2022 17:03:21 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 5CDF88414B; Wed, 20 Jul 2022 19:01:06 +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="KecNePdE"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 8EA4C840BB; Wed, 20 Jul 2022 19:00:38 +0200 (CEST) Received: from mail-wr1-x42c.google.com (mail-wr1-x42c.google.com [IPv6:2a00:1450:4864:20::42c]) (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 90A50840AC for ; Wed, 20 Jul 2022 19:00:33 +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-wr1-x42c.google.com with SMTP id z13so7430084wro.13 for ; Wed, 20 Jul 2022 10:00:33 -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=9Amn5/5psvu+R6nHT1CHY5yTMHar7St/lR81uznF9hM=; b=KecNePdEFbTr5iGexmEEoeRLxFCBbFHIRhy3/Ni8IEun7fE0JC9gtcHz4yd8cBt2iP 7aoeOkCSlNDKgLRbdtaJEuu1Fwy27fgDaMXbCehp6sC0yzLh3ulJOekgZ5m3NmTOtwEm A7G1A/CGdDp9XlVEdQ6qkqgxTBZuGz0FccUfg= 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=9Amn5/5psvu+R6nHT1CHY5yTMHar7St/lR81uznF9hM=; b=jZrB4uz2i16TA5XJzerpeyEh08RbICw7VVqqDzYSzdTaujGZxLVg4LxSnxkNpw/MlR 0KwKzTbKjdGdH0ciBNKWYhvpaG2y9xHhEVEYRZe1e7ZPB+nq4UGoYHfitq492aN+v356 OKWTiIJHymo06o7hltF1VjTkq1YXuCLrOyT5IflJmkkAvI0r/M+XTmrBuTEU0zysHt1n mEGfUaXroU/qOfNfFg59fkybt6MaKI7KXQkOng6aaLsrRuoPAjBBH42rMAHOyjGSGHks LgQnt8A7UUJav7thR8kg1XX7Izdux74dOSAZLVYTVTF33uyoOwJYEBuBjZU6lQlZ7psL iFFw== X-Gm-Message-State: AJIora/VqC/1037oren9NEkbrB3/2blzHfOOLKbvjAuC1JlQvx0V9Z+m 8K5kf/cFZuAFnyg0ecsNnHsVJ7lCjKTi2Bgn X-Google-Smtp-Source: AGRyM1uWmqNUdHvFMhuYCzYO+F00Zh/KqAdbzve29NAJoxPtu0W1bSNNEl1pSAKTVykFB9jZBZlN9w== X-Received: by 2002:a5d:52c4:0:b0:21e:428a:912b with SMTP id r4-20020a5d52c4000000b0021e428a912bmr6087688wrv.395.1658336433064; Wed, 20 Jul 2022 10:00:33 -0700 (PDT) Received: from sjg1.roam.corp.google.com ([62.48.169.138]) by smtp.gmail.com with ESMTPSA id u16-20020a05600c00d000b003a31c4f6f74sm3690906wmm.32.2022.07.20.10.00.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Jul 2022 10:00:32 -0700 (PDT) From: Simon Glass To: U-Boot Mailing List Cc: Tom Rini , Simon Glass Subject: [PATCH 16/19] bootstd: Provide a bootmeth method to obtain state info Date: Wed, 20 Jul 2022 10:59:44 -0600 Message-Id: <20220720165947.12728-14-sjg@chromium.org> X-Mailer: git-send-email 2.37.0.170.g444d1eabd0-goog In-Reply-To: <20220720165947.12728-1-sjg@chromium.org> References: <20220720165947.12728-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 Some bootmeths can provide information about what is available to boot. For example, VBE simple provides access to the firmware state. Add a new method for this, along with a sandbox test. Signed-off-by: Simon Glass --- boot/bootmeth-uclass.c | 10 ++++++++++ boot/bootmeth_distro.c | 14 ++++++++++++++ include/bootmeth.h | 38 +++++++++++++++++++++++++++++++++++++- test/boot/bootmeth.c | 18 ++++++++++++++++++ 4 files changed, 79 insertions(+), 1 deletion(-) diff --git a/boot/bootmeth-uclass.c b/boot/bootmeth-uclass.c index b8ba4eca7ab..1e276c0f26b 100644 --- a/boot/bootmeth-uclass.c +++ b/boot/bootmeth-uclass.c @@ -20,6 +20,16 @@ DECLARE_GLOBAL_DATA_PTR; +int bootmeth_get_state_desc(struct udevice *dev, char *buf, int maxsize) +{ + const struct bootmeth_ops *ops = bootmeth_get_ops(dev); + + if (!ops->get_state_desc) + return -ENOSYS; + + return ops->get_state_desc(dev, buf, maxsize); +} + int bootmeth_check(struct udevice *dev, struct bootflow_iter *iter) { const struct bootmeth_ops *ops = bootmeth_get_ops(dev); diff --git a/boot/bootmeth_distro.c b/boot/bootmeth_distro.c index 2b41e654ade..fea09b2c2fb 100644 --- a/boot/bootmeth_distro.c +++ b/boot/bootmeth_distro.c @@ -22,6 +22,19 @@ #include #include +static int distro_get_state_desc(struct udevice *dev, char *buf, int maxsize) +{ + if (IS_ENABLED(CONFIG_SANDBOX)) { + int len; + + len = snprintf(buf, maxsize, "OK"); + + return len + 1 < maxsize ? 0 : -ENOSPC; + } + + return 0; +} + static int disto_getfile(struct pxe_context *ctx, const char *file_path, char *file_addr, ulong *sizep) { @@ -123,6 +136,7 @@ static int distro_bootmeth_bind(struct udevice *dev) } static struct bootmeth_ops distro_bootmeth_ops = { + .get_state_desc = distro_get_state_desc, .check = distro_check, .read_bootflow = distro_read_bootflow, .read_file = bootmeth_common_read_file, diff --git a/include/bootmeth.h b/include/bootmeth.h index 484e503e338..4967031a0a8 100644 --- a/include/bootmeth.h +++ b/include/bootmeth.h @@ -24,7 +24,25 @@ struct bootmeth_uc_plat { /** struct bootmeth_ops - Operations for boot methods */ struct bootmeth_ops { /** - * check_supported() - check if a bootmeth supports this bootflow + * get_state_desc() - get detailed state information + * + * Prodecues a textual description of the state of the bootmeth. This + * can include newline characters if it extends to multiple lines. It + * must be a nul-terminated string. + * + * This may involve reading state from the system, e.g. some data in + * the firmware area. + * + * @dev: Bootmethod device to check + * @buf: Buffer to place the info in (terminator must fit) + * @maxsize: Size of buffer + * Returns: 0 if OK, -ENOSPC is buffer is too small, other -ve error if + * something else went wrong + */ + int (*get_state_desc)(struct udevice *dev, char *buf, int maxsize); + + /** + * check_supported() - check if a bootmeth supports this bootdev * * This is optional. If not provided, the bootdev is assumed to be * supported @@ -91,6 +109,24 @@ struct bootmeth_ops { #define bootmeth_get_ops(dev) ((struct bootmeth_ops *)(dev)->driver->ops) +/** + * bootmeth_get_state_desc() - get detailed state information + * + * Prodecues a textual description of the state of the bootmeth. This + * can include newline characters if it extends to multiple lines. It + * must be a nul-terminated string. + * + * This may involve reading state from the system, e.g. some data in + * the firmware area. + * + * @dev: Bootmethod device to check + * @buf: Buffer to place the info in (terminator must fit) + * @maxsize: Size of buffer + * Returns: 0 if OK, -ENOSPC is buffer is too small, other -ve error if + * something else went wrong + */ +int bootmeth_get_state_desc(struct udevice *dev, char *buf, int maxsize); + /** * bootmeth_check() - check if a bootmeth supports this bootflow * diff --git a/test/boot/bootmeth.c b/test/boot/bootmeth.c index 81421f550b5..5d2e87b1c95 100644 --- a/test/boot/bootmeth.c +++ b/test/boot/bootmeth.c @@ -7,7 +7,9 @@ */ #include +#include #include +#include #include #include #include "bootstd_common.h" @@ -120,3 +122,19 @@ static int bootmeth_env(struct unit_test_state *uts) return 0; } BOOTSTD_TEST(bootmeth_env, UT_TESTF_DM | UT_TESTF_SCAN_FDT); + +/* Check the get_state_desc() method */ +static int bootmeth_state(struct unit_test_state *uts) +{ + struct udevice *dev; + char buf[50]; + + ut_assertok(uclass_first_device(UCLASS_BOOTMETH, &dev)); + ut_assertnonnull(dev); + + ut_assertok(bootmeth_get_state_desc(dev, buf, sizeof(buf))); + ut_asserteq_str("OK", buf); + + return 0; +} +BOOTSTD_TEST(bootmeth_state, UT_TESTF_DM | UT_TESTF_SCAN_FDT); -- 2.37.0.170.g444d1eabd0-goog