[Concept,09/14] expo: Introduce a test mode

Message ID 20251006205856.2009292-10-sjg@u-boot.org
State New
Headers
Series expo: More mouse development for expo |

Commit Message

Simon Glass Oct. 6, 2025, 8:58 p.m. UTC
  From: Simon Glass <sjg@chromium.org>

Add a test mode for expo which will display useful debugging
information.

Put this feature behind a CONFIG_EXPO_TEST option to avoid code-size
growth. Create a separate C file and a header. Use static inlines to
avoid lots of CONFIG checking in expo.c

Enable this feature for sandbox and the EFI app for now.

Co-developed-by: Claude <noreply@anthropic.com>
Signed-off-by: Simon Glass <sjg@chromium.org>
---

 boot/Kconfig        | 10 +++++++++
 boot/Makefile       |  1 +
 boot/expo.c         | 11 ++++++++++
 boot/expo_test.c    | 25 +++++++++++++++++++++
 include/expo_test.h | 53 +++++++++++++++++++++++++++++++++++++++++++++
 5 files changed, 100 insertions(+)
 create mode 100644 boot/expo_test.c
 create mode 100644 include/expo_test.h
  

Patch

diff --git a/boot/Kconfig b/boot/Kconfig
index 933832b4dbf..fb34a10106b 100644
--- a/boot/Kconfig
+++ b/boot/Kconfig
@@ -982,6 +982,16 @@  config EXPO
 	  The expo can be presented in graphics form using a vidconsole, or in
 	  text form on a serial console.
 
+config EXPO_TEST
+	bool "Enable test mode for expo"
+	depends on EXPO
+	default y if SANDBOX || EFI_APP
+	help
+	  Enable test mode for expo. When enabled, expo displays a frame count
+	  in the top-right corner of the display when the 'expotest' environment
+	  variable is set to 1. This is useful for debugging and performance
+	  analysis.
+
 config BOOTMETH_SANDBOX
 	def_bool y
 	depends on SANDBOX
diff --git a/boot/Makefile b/boot/Makefile
index 3ab1fbb11c0..bb1888f1656 100644
--- a/boot/Makefile
+++ b/boot/Makefile
@@ -58,6 +58,7 @@  obj-$(CONFIG_$(PHASE_)LOAD_FIT) += common_fit.o
 
 obj-$(CONFIG_$(PHASE_)EXPO) += expo.o scene.o expo_build.o
 obj-$(CONFIG_$(PHASE_)EXPO) += scene_menu.o scene_textline.o scene_textedit.o
+obj-$(CONFIG_$(PHASE_)EXPO_TEST) += expo_test.o
 ifdef CONFIG_COREBOOT_SYSINFO
 obj-$(CONFIG_$(SPL_TPL_)EXPO) += expo_build_cb.o
 endif
diff --git a/boot/expo.c b/boot/expo.c
index afb09aaf5b5..e7c4ab8d7db 100644
--- a/boot/expo.c
+++ b/boot/expo.c
@@ -10,6 +10,7 @@ 
 
 #include <dm.h>
 #include <expo.h>
+#include <expo_test.h>
 #include <log.h>
 #include <malloc.h>
 #include <mapmem.h>
@@ -23,6 +24,7 @@ 
 int expo_new(const char *name, void *priv, struct expo **expp)
 {
 	struct expo *exp;
+	int ret;
 
 	exp = calloc(1, sizeof(struct expo));
 	if (!exp)
@@ -32,6 +34,12 @@  int expo_new(const char *name, void *priv, struct expo **expp)
 		free(exp);
 		return log_msg_ret("name", -ENOMEM);
 	}
+	ret = expo_test_init(exp);
+	if (ret) {
+		free(exp->name);
+		free(exp);
+		return log_msg_ret("tst", ret);
+	}
 	exp->priv = priv;
 	INIT_LIST_HEAD(&exp->scene_head);
 	INIT_LIST_HEAD(&exp->str_head);
@@ -53,6 +61,7 @@  void expo_destroy(struct expo *exp)
 	struct scene *scn, *next;
 	struct expo_string *estr, *enext;
 
+	expo_test_uninit(exp);
 	list_for_each_entry_safe(scn, next, &exp->scene_head, sibling)
 		scene_destroy(scn);
 
@@ -314,6 +323,8 @@  static int expo_render_(struct expo *exp, bool dirty_only)
 	u32 colour;
 	int ret;
 
+	expo_test_update(exp);
+
 	back = vid_priv->white_on_black ? VID_BLACK : VID_WHITE;
 	colour = video_index_to_colour(vid_priv, back);
 	ret = video_fill(dev, colour);
diff --git a/boot/expo_test.c b/boot/expo_test.c
new file mode 100644
index 00000000000..ecef8decc6e
--- /dev/null
+++ b/boot/expo_test.c
@@ -0,0 +1,25 @@ 
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Expo test mode
+ *
+ * Copyright 2025 Canonical Ltd
+ * Written by Simon Glass <sjg@chromium.org>
+ */
+
+#define LOG_CATEGORY	LOGC_EXPO
+
+#include <expo.h>
+#include <expo_test.h>
+
+int expo_test_init(struct expo *exp)
+{
+	return 0;
+}
+
+void expo_test_uninit(struct expo *exp)
+{
+}
+
+void expo_test_update(struct expo *exp)
+{
+}
diff --git a/include/expo_test.h b/include/expo_test.h
new file mode 100644
index 00000000000..e1918ddeff2
--- /dev/null
+++ b/include/expo_test.h
@@ -0,0 +1,53 @@ 
+/* SPDX-License-Identifier: GPL-2.0+ */
+/*
+ * Copyright Canonical Ltd
+ * Written by Simon Glass <sjg@chromium.org>
+ */
+
+#ifndef __EXPO_TEST_H
+#define __EXPO_TEST_H
+
+struct expo;
+
+#if CONFIG_IS_ENABLED(EXPO_TEST)
+
+/**
+ * expo_test_init() - Initialize test mode for an expo
+ *
+ * @exp: Expo to initialize test mode for
+ * Return: 0 if OK, -ve on error
+ */
+int expo_test_init(struct expo *exp);
+
+/**
+ * expo_test_uninit() - Uninitialize test mode for an expo
+ *
+ * @exp: Expo to uninitialize test mode for
+ */
+void expo_test_uninit(struct expo *exp);
+
+/**
+ * expo_test_update() - Update test mode counters
+ *
+ * @exp: Expo to update test mode for
+ */
+void expo_test_update(struct expo *exp);
+
+#else
+
+static inline int expo_test_init(struct expo *exp)
+{
+	return 0;
+}
+
+static inline void expo_test_uninit(struct expo *exp)
+{
+}
+
+static inline void expo_test_update(struct expo *exp)
+{
+}
+
+#endif /* EXPO_TEST */
+
+#endif /* __EXPO_TEST_H */