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 A3DF0C19F28 for ; Sat, 30 Jul 2022 21:56:50 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 7D0118451D; Sat, 30 Jul 2022 23:53:58 +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="K7RjnBow"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id F07FA8412C; Sat, 30 Jul 2022 23:53:40 +0200 (CEST) Received: from mail-oa1-x31.google.com (mail-oa1-x31.google.com [IPv6:2001:4860:4864:20::31]) (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 191458449B for ; Sat, 30 Jul 2022 23:53:38 +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-oa1-x31.google.com with SMTP id 586e51a60fabf-10bd4812c29so9558863fac.11 for ; Sat, 30 Jul 2022 14:53:38 -0700 (PDT) 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; bh=ER94L6/yUWTr/2OXTTuRArTYBtQnAJ7wOly+M3giqsM=; b=K7RjnBowKCEPD4tibhA4gJNoDLb5m/25RJbf8yRaXWKfVkVHu1SsmyMYrLsP3ZmIU9 ZLeunvta7xzvlpoWuhimHboqd/7WRpL0HXB0Iaxe/ibkHHN5Kbf0eZt6Qcp55elLJpWf V6HekpEQoacIZeo+38bVKVI73F/C5NsNXqqjg= 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; bh=ER94L6/yUWTr/2OXTTuRArTYBtQnAJ7wOly+M3giqsM=; b=Cf6PJR4NdMjQt48KUUnwUHZDhC4jSif6u3lhh6sGZ10qxuw0gdD0npKQ3mTAcwvmmg AGCMJ3p4DmiTwJxZCo9nipwHMFwWVXiZAvkfaTzeZlAW8DppI6pPTB1zuqohOr5t11QG TEMasX3xwi5it7B0ZO/vSnMGqt0UnOTqcGMF90uUNIJtZLgcQ27JLhIrKxdSt3YjriEl v7JJVS7f7tzPRDlGs28Q6Xrbki86zQ+eBQAu1n846nJY1y68vcwHoKVvZ3fWr4+xvKxl lUYoxXrvMzbYYV0lC07ZWIbB3z299zGfhkYGnWt2DE1TlpzTsZNQ80GORRQEfO4CaIPv 2m5A== X-Gm-Message-State: AJIora/+2NkIuyVXXzlYQbikjSLhmqabCy4j6x0aamc/Jju00fs8XXY/ ExaoDyZycTDQTVRKhV/exHzpYHXLqXOuOOrC X-Google-Smtp-Source: AGRyM1vDzDFDB5WaICIUpwFSAimR+tE5+EodOI2Xe3Xv3FWo7zQKqMaafnUuZT0XkEdm9a9CyA0DVA== X-Received: by 2002:a05:6870:5b81:b0:101:b256:b7d with SMTP id em1-20020a0568705b8100b00101b2560b7dmr4726340oab.198.1659218002079; Sat, 30 Jul 2022 14:53:22 -0700 (PDT) Received: from sjg1.lan (c-67-190-102-125.hsd1.co.comcast.net. [67.190.102.125]) by smtp.gmail.com with ESMTPSA id 19-20020a544193000000b0032f75714af1sm1699656oiy.18.2022.07.30.14.53.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 30 Jul 2022 14:53:21 -0700 (PDT) From: Simon Glass To: U-Boot Mailing List Cc: Tom Rini , Bin Meng , Simon Glass Subject: [PATCH v2 17/35] bootstd: Provide a bootmeth method to obtain state info Date: Sat, 30 Jul 2022 15:52:19 -0600 Message-Id: <20220730215237.818368-13-sjg@chromium.org> X-Mailer: git-send-email 2.37.1.455.g008518b4e5-goog In-Reply-To: <20220730215237.818368-1-sjg@chromium.org> References: <20220730215237.818368-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 --- (no changes since v1) 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.1.455.g008518b4e5-goog