bootstd: Provide a bootmeth method to obtain state info
authorSimon Glass <sjg@chromium.org>
Sat, 30 Jul 2022 21:52:19 +0000 (15:52 -0600)
committerTom Rini <trini@konsulko.com>
Fri, 12 Aug 2022 12:14:24 +0000 (08:14 -0400)
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 <sjg@chromium.org>
boot/bootmeth-uclass.c
boot/bootmeth_distro.c
include/bootmeth.h
test/boot/bootmeth.c

index b8ba4ec..1e276c0 100644 (file)
 
 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);
index 2b41e65..fea09b2 100644 (file)
 #include <mmc.h>
 #include <pxe_utils.h>
 
+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,
index 484e503..4967031 100644 (file)
@@ -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
@@ -92,6 +110,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
  *
  * This is optional. If not provided, the bootdev is assumed to be
index 81421f5..5d2e87b 100644 (file)
@@ -7,7 +7,9 @@
  */
 
 #include <common.h>
+#include <bootmeth.h>
 #include <bootstd.h>
+#include <dm.h>
 #include <test/suites.h>
 #include <test/ut.h>
 #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);