Skip to contentSkip to conversation

expo: Add an initial configuration editor

PATCH In review Simon Glass 3 participants 43 messages Jun 1, 2023 – Jul 14, 2023

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

cover expo: Add an initial configuration editor

This series provides a means to edit board configuration in U-Boot in a graphical manner. It supports multiple menu items and allows moving between them and selecting items. The configuration is defined in a data format so that code is not needed in most cases. This allows the board configuration to be provided in the devicetree.

This is still at an early stage, since it only supports menus. Numeric values are not supported. Most importantly it does not yet support loading or saving the configuration selected by the user.

To try it out you can use something like:

./tools/expo.py -e test/boot/files/expo_layout.dts \
-l test/boot/files/expo_layout.dts -o cedit.dtb
./u-boot -Tl -c "cedit load hostfs - cedit.dtb; cedit run"

Use the arrow keys to move between menus, enter to open a menu, escape to exit.

Various minor fixes and improvements are provided in this series:
- Update STB TrueType library to latest
- Support clearing part of the video display
- Support multiple livetrees loaded at runtime
- Support loading and allocating a file
- Support proper measuring of text in expo
- Support simple themes for expo

This series is available at u-boot-dm/cedit-working

Simon Glass (40):
binman: Correct coverage gap in control
expo: Correct some header-file comments
expo: Convert to using a string ID for the scene title
sandbox: Fix quiting when the LCD window is closed
test: Restore test behaviour on failure
gpio: Avoid using an invalid ofnode
dm: core: Avoid registering an inaccessible tree
video: Drop #ifdefs from console_truetype
video: Provide a way to clear part of the console
expo: Store the console in the expo
expo: Avoid automatically arranging the scene
console: Correct truetype spacing error
expo: Rename exp_set_text_mode()
fs: Create functions to load and allocate a file
cat: Update command to use fs_load_alloc()
fdt: Align the start of the livetree
fdt: Clarify the fdt pre-relocation warning
fdt: Allow more general use of livetree
bootstd: Add a separate log category for expo
video: Correct docs for video_index_to_colour()
video: Allow temporary colour changes
console: Allow measuring the bounding box of text
expo: Allow setting the start of the dynamic-ID range
video: Use enum with video_index_to_colour()
expo: Add width and height to objects
expo: Use flags for objects
expo: Calculate text bounding-box correctly
expo: Set up the width and height of objects
expo: Support simple themes
expo: Move menu-item selection into a function
expo: Support drawing of popup menus
expo: Rename EXPOACT_POINT to EXPOACT_POINT_ITEM
expo: Draw popup menus in both opened and closed states
expo: Draw the current opened menu on top
expo: Implement the keypress logic for popup menus
expo: Add spacing around menus and items
expo: Support building an expo from a description file
expo: Add a configuration editor
expo: Add tests for the configuration editor
RFC: video: Update stb_truetype

 arch/sandbox/cpu/sdl.c            |    3 +-
 arch/sandbox/dts/cedit.dtsi       |   64 +
 arch/sandbox/dts/sandbox.dtsi     |    6 +
 arch/sandbox/dts/test.dts         |   13 +
 boot/Kconfig                      |   14 +
 boot/Makefile                     |    3 +-
 boot/bootflow_menu.c              |    6 +-
 boot/bootmeth-uclass.c            |   30 +-
 boot/cedit.c                      |  163 +++
 boot/expo.c                       |  102 +-
 boot/expo_build.c                 |  401 +++++
 boot/scene.c                      |  361 ++++-
 boot/scene_internal.h             |   84 +-
 boot/scene_menu.c                 |  290 +++-
 cmd/Kconfig                       |    9 +
 cmd/Makefile                      |    1 +
 cmd/cat.c                         |   47 +-
 cmd/cedit.c                       |   93 ++
 common/log.c                      |    1 +
 configs/sandbox_defconfig         |    1 +
 doc/develop/expo.rst              |  305 +++-
 doc/usage/cmd/cedit.rst           |   31 +
 doc/usage/index.rst               |    1 +
 drivers/core/ofnode.c             |   27 +-
 drivers/gpio/gpio-uclass.c        |    2 +-
 drivers/video/console_truetype.c  |  259 ++--
 drivers/video/stb_truetype.h      | 2257 ++++++++++++++++++++++++++---
 drivers/video/vidconsole-uclass.c |   42 +
 drivers/video/video-uclass.c      |   54 +-
 fs/fs.c                           |   58 +
 include/dm/of.h                   |    2 +
 include/dm/ofnode.h               |   10 +
 include/expo.h                    |  209 ++-
 include/fs.h                      |   38 +
 include/log.h                     |    2 +
 include/of_live.h                 |   10 +
 include/test/cedit-test.h         |   29 +
 include/test/ut.h                 |   36 +-
 include/video.h                   |   22 +-
 include/video_console.h           |   78 +
 lib/of_live.c                     |   11 +-
 test/boot/expo.c                  |  241 ++-
 test/boot/files/expo_layout.dts   |   84 ++
 test/dm/ofnode.c                  |   45 +
 test/dm/video.c                   |    6 +-
 test/py/tests/test_ut.py          |   10 +
 tools/binman/control.py           |    2 +-
 tools/expo.py                     |  130 ++
 48 files changed, 5110 insertions(+), 583 deletions(-)
 create mode 100644 arch/sandbox/dts/cedit.dtsi
 create mode 100644 boot/cedit.c
 create mode 100644 boot/expo_build.c
 create mode 100644 cmd/cedit.c
 create mode 100644 doc/usage/cmd/cedit.rst
 create mode 100644 include/test/cedit-test.h
 create mode 100644 test/boot/files/expo_layout.dts
 create mode 100755 tools/expo.py
Signature · 1 line
2.41.0.rc0.172.g3f132b7071-goog
#1 lore raw

PATCH 1/40 binman: Correct coverage gap in control

Add a pragma to deal with the code-coverage gap which drops binman down to 90% coverage.

Fixes de65b122a25 (tools: Fall back to importlib_resources on Python 3.6)

---

 tools/binman/control.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/binman/control.py +1 -1
index 68597c4e7792..7e2dd3541b96 100644
@@ -9,7 +9,7 @@ from collections import OrderedDict
 import glob
 try:
     import importlib.resources
-except ImportError:
+except ImportError:  # pragma: no cover
     # for Python 3.6
     import importlib_resources
 import os
Signature · 1 line
2.41.0.rc0.172.g3f132b7071-goog
#2 lore raw

PATCH 2/40 expo: Correct some header-file comments

In reply to Simon Glass

The use of Returns instead of @return still confuses me. Fix some problems that have crept in.

---

 boot/scene_internal.h | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
boot/scene_internal.h +5 -3
index e8fd765811e1..9f173dd749f0 100644
@@ -23,7 +23,7 @@ struct scene *expo_lookup_scene_id(struct expo *exp, uint scene_id);
  *
  * @exp: Expo to use
  * @id: ID to use, or 0 to auto-allocate one
- * @return: Either @id, or the auto-allocated ID
+ * Returns: Either @id, or the auto-allocated ID
  */
 uint resolve_id(struct expo *exp, uint id);
 
@@ -36,6 +36,7 @@ uint resolve_id(struct expo *exp, uint id);
  * @scn: Scene to search
  * @id: ID of object to find
  * @type: Type of the object, or SCENEOBJT_NONE to match any type
+ * Returns: Object found, or NULL if not found
  */
 void *scene_obj_find(struct scene *scn, uint id, enum scene_obj_t type);
 
@@ -62,6 +63,7 @@ int scene_obj_add(struct scene *scn, const char *name, uint id,
  *
  * @scn: Scene to update
  * @menu: Menu to process
+ * Returns: 0 if OK, -ve on error
  */
 int scene_menu_arrange(struct scene *scn, struct scene_obj_menu *menu);
 
@@ -72,7 +74,7 @@ int scene_menu_arrange(struct scene *scn, struct scene_obj_menu *menu);
  * @menu: Menu to use
  * @key: Key code to send (KEY_...)
  * @event: Place to put any event which is generated by the key
- * @return 0 if OK, -ENOTTY if there is no current menu item, other -ve on other
+ * Returns: 0 if OK, -ENOTTY if there is no current menu item, other -ve on other
  *	error
  */
 int scene_menu_send_key(struct scene *scn, struct scene_obj_menu *menu, int key,
@@ -89,7 +91,7 @@ void scene_menu_destroy(struct scene_obj_menu *menu);
  * scene_menu_display() - Display a menu as text
  *
  * @menu: Menu to display
- * @return 0 if OK, -ENOENT if @id is invalid
+ * Returns: 0 if OK, -ENOENT if @id is invalid
  */
 int scene_menu_display(struct scene_obj_menu *menu);
 
Signature · 1 line
2.41.0.rc0.172.g3f132b7071-goog
#3 lore raw

PATCH 3/40 expo: Convert to using a string ID for the scene title

In reply to Simon Glass

This is easier to deal with if it uses the existing string handling, since we will be able to use translations, etc. in the future.

Update it to use an ID instead of a string.

---

 boot/scene.c     |  8 ++------
 include/expo.h   | 10 +++++-----
 test/boot/expo.c | 19 ++++++++++---------
 3 files changed, 17 insertions(+), 20 deletions(-)
boot/scene.c +2 -6
index 030f6aa2a0a9..d2f77c008cf7 100644
@@ -65,16 +65,12 @@ void scene_destroy(struct scene *scn)
 		scene_obj_destroy(obj);
 
 	free(scn->name);
-	free(scn->title);
 	free(scn);
 }
 
-int scene_title_set(struct scene *scn, const char *title)
+int scene_title_set(struct scene *scn, uint id)
 {
-	free(scn->title);
-	scn->title = strdup(title);
-	if (!scn->title)
-		return log_msg_ret("tit", -ENOMEM);
+	scn->title_id = id;
 
 	return 0;
 }
include/expo.h +5 -5
index d242f48e30c7..8827f4b0b45f 100644
@@ -92,7 +92,7 @@ struct expo_string {
  * @expo: Expo this scene is part of
  * @name: Name of the scene (allocated)
  * @id: ID number of the scene
- * @title: Title of the scene (allocated)
+ * @title_id: String ID of title of the scene (allocated)
  * @sibling: Node to link this scene to its siblings
  * @obj_head: List of objects in the scene
  */
@@ -100,7 +100,7 @@ struct scene {
 	struct expo *expo;
 	char *name;
 	uint id;
-	char *title;
+	uint title_id;
 	struct list_head sibling;
 	struct list_head obj_head;
 };
@@ -338,10 +338,10 @@ struct scene *expo_lookup_scene_id(struct expo *exp, uint scene_id);
  * scene_title_set() - set the scene title
  *
  * @scn: Scene to update
- * @title: Title to set, NULL if none (this is allocated by this call)
- * Returns: 0 if OK, -ENOMEM if out of memory
+ * @title_id: Title ID to set
+ * Returns: 0 if OK
  */
-int scene_title_set(struct scene *scn, const char *title);
+int scene_title_set(struct scene *scn, uint title_id);
 
 /**
  * scene_obj_count() - Count the number of objects in a scene
test/boot/expo.c +10 -9
index 7104dff05e8d..3c0bc78bb7a4 100644
@@ -28,6 +28,8 @@ enum {
 	OBJ_MENU_TITLE,
 
 	/* strings */
+	STR_SCENE_TITLE,
+
 	STR_TEXT,
 	STR_TEXT2,
 	STR_MENU_TITLE,
@@ -120,7 +122,7 @@ static int expo_scene(struct unit_test_state *uts)
 	struct expo *exp;
 	ulong start_mem;
 	char name[100];
-	int id;
+	int id, title_id;
 
 	start_mem = ut_check_free();
 
@@ -141,21 +143,20 @@ static int expo_scene(struct unit_test_state *uts)
 	ut_asserteq_str(SCENE_NAME1, scn->name);
 
 	/* Set the title */
-	strcpy(name, SCENE_TITLE);
-	ut_assertok(scene_title_set(scn, name));
-	*name = '\0';
-	ut_assertnonnull(scn->title);
-	ut_asserteq_str(SCENE_TITLE, scn->title);
+	title_id = expo_str(exp, "title", STR_SCENE_TITLE, SCENE_TITLE);
+	ut_assert(title_id >= 0);
 
-	/* Use an allocated ID */
+	/* Use an allocated ID - this will be allocated after the title str */
 	scn = NULL;
 	id = scene_new(exp, SCENE_NAME2, 0, &scn);
 	ut_assertnonnull(scn);
-	ut_asserteq(SCENE2, id);
-	ut_asserteq(SCENE2 + 1, exp->next_id);
+	ut_assertok(scene_title_set(scn, title_id));
+	ut_asserteq(STR_SCENE_TITLE + 1, id);
+	ut_asserteq(STR_SCENE_TITLE + 2, exp->next_id);
 	ut_asserteq_ptr(exp, scn->expo);
 
 	ut_asserteq_str(SCENE_NAME2, scn->name);
+	ut_asserteq(title_id, scn->title_id);
 
 	expo_destroy(exp);
 
Signature · 1 line
2.41.0.rc0.172.g3f132b7071-goog
#4 lore raw

PATCH 4/40 sandbox: Fix quiting when the LCD window is closed

In reply to Simon Glass

With recent changes to how sandbox handles reset, closing the window currently just restarts sandbox.

Use the correct sysreset type to tell it to shut down.

---

 arch/sandbox/cpu/sdl.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
arch/sandbox/cpu/sdl.c +2 -1
index 2c570ed8d164..590e406517bf 100644
@@ -6,6 +6,7 @@
 #include <errno.h>
 #include <unistd.h>
 #include <stdbool.h>
+#include <sysreset.h>
 #include <linux/input.h>
 #include <SDL2/SDL.h>
 #include <asm/state.h>
@@ -81,7 +82,7 @@ static void sandbox_sdl_poll_events(void)
 		switch (event.type) {
 		case SDL_QUIT:
 			puts("LCD window closed - quitting\n");
-			reset_cpu();
+			sysreset_walk(SYSRESET_POWER_OFF);
 			break;
 		}
 	}
Signature · 1 line
2.41.0.rc0.172.g3f132b7071-goog
#5 lore raw

PATCH 5/40 test: Restore test behaviour on failure

In reply to Simon Glass

A recent change makes test continue to run after failure. This results in a lot of useless output and may lead to a segfault. Fix this by adding back the 'return' statement.

Fixes fa847bb409d ("test: Wrap assert macros in ({ ... }) and fix")

---

 include/test/ut.h | 36 ++++++++++++++++++------------------
 1 file changed, 18 insertions(+), 18 deletions(-)
include/test/ut.h +18 -18
index dddf9ad241fe..ea6ee95d7344 100644
@@ -130,7 +130,7 @@ int ut_check_console_dump(struct unit_test_state *uts, int total_bytes);
 									\
 	if (!(cond)) {							\
 		ut_fail(uts, __FILE__, __LINE__, __func__, #cond);	\
-		__ret = CMD_RET_FAILURE;				\
+		return CMD_RET_FAILURE;					\
 	}								\
 	__ret;								\
 })
@@ -142,7 +142,7 @@ int ut_check_console_dump(struct unit_test_state *uts, int total_bytes);
 	if (!(cond)) {							\
 		ut_failf(uts, __FILE__, __LINE__, __func__, #cond,	\
 			 fmt, ##args);					\
-		__ret = CMD_RET_FAILURE;				\
+		return CMD_RET_FAILURE;					\
 	}								\
 	__ret;								\
 })
@@ -157,7 +157,7 @@ int ut_check_console_dump(struct unit_test_state *uts, int total_bytes);
 			 #expr1 " == " #expr2,				\
 			 "Expected %#x (%d), got %#x (%d)",		\
 			 _val1, _val1, _val2, _val2);			\
-		__ret = CMD_RET_FAILURE;				\
+		return CMD_RET_FAILURE;					\
 	}								\
 	__ret;								\
 })
@@ -175,7 +175,7 @@ int ut_check_console_dump(struct unit_test_state *uts, int total_bytes);
 			 (unsigned long long)_val1,			\
 			 (unsigned long long)_val2,			\
 			 (unsigned long long)_val2);			\
-		__ret = CMD_RET_FAILURE;				\
+		return CMD_RET_FAILURE;					\
 	}								\
 	__ret;								\
 })
@@ -189,7 +189,7 @@ int ut_check_console_dump(struct unit_test_state *uts, int total_bytes);
 		ut_failf(uts, __FILE__, __LINE__, __func__,		\
 			 #expr1 " = " #expr2,				\
 			 "Expected \"%s\", got \"%s\"", _val1, _val2);	\
-		__ret = CMD_RET_FAILURE;				\
+		return CMD_RET_FAILURE;					\
 	}								\
 	__ret;								\
 })
@@ -208,7 +208,7 @@ int ut_check_console_dump(struct unit_test_state *uts, int total_bytes);
 			 #expr1 " = " #expr2,				\
 			 "Expected \"%.*s\", got \"%.*s\"",		\
 			 _len, _val1, _len, _val2);			\
-		__ret = CMD_RET_FAILURE;				\
+		return CMD_RET_FAILURE;					\
 	}								\
 	__ret;								\
 })
@@ -228,7 +228,7 @@ int ut_check_console_dump(struct unit_test_state *uts, int total_bytes);
 			 #expr1 " = " #expr2,				\
 			 "Expected \"%s\", got \"%s\"",			\
 			 __buf1, __buf2);				\
-		__ret = CMD_RET_FAILURE;				\
+		return CMD_RET_FAILURE;					\
 	}								\
 	__ret;								\
 })
@@ -242,7 +242,7 @@ int ut_check_console_dump(struct unit_test_state *uts, int total_bytes);
 		ut_failf(uts, __FILE__, __LINE__, __func__,		\
 			 #expr1 " = " #expr2,				\
 			 "Expected %p, got %p", _val1, _val2);		\
-		__ret = CMD_RET_FAILURE;				\
+		return CMD_RET_FAILURE;					\
 	}								\
 	__ret;								\
 })
@@ -257,7 +257,7 @@ int ut_check_console_dump(struct unit_test_state *uts, int total_bytes);
 		ut_failf(uts, __FILE__, __LINE__, __func__,		\
 			 #expr1 " = " #expr2,				\
 			 "Expected %lx, got %lx", _val1, _val2);	\
-		__ret = CMD_RET_FAILURE;				\
+		return CMD_RET_FAILURE;					\
 	}								\
 	__ret;								\
 })
@@ -271,7 +271,7 @@ int ut_check_console_dump(struct unit_test_state *uts, int total_bytes);
 		ut_failf(uts, __FILE__, __LINE__, __func__,		\
 			 #expr " != NULL",				\
 			 "Expected NULL, got %p", _val);		\
-		__ret = CMD_RET_FAILURE;				\
+		return CMD_RET_FAILURE;					\
 	}								\
 	__ret;								\
 })
@@ -285,7 +285,7 @@ int ut_check_console_dump(struct unit_test_state *uts, int total_bytes);
 		ut_failf(uts, __FILE__, __LINE__, __func__,		\
 			 #expr " = NULL",				\
 			 "Expected non-null, got NULL");		\
-		__ret = CMD_RET_FAILURE;				\
+		return CMD_RET_FAILURE;					\
 	}								\
 	__ret;								\
 })
@@ -300,7 +300,7 @@ int ut_check_console_dump(struct unit_test_state *uts, int total_bytes);
 			 #expr " = NULL",				\
 			 "Expected pointer, got error %ld",		\
 			 PTR_ERR(_val));				\
-		__ret = CMD_RET_FAILURE;				\
+		return CMD_RET_FAILURE;					\
 	}								\
 	__ret;								\
 })
@@ -316,7 +316,7 @@ int ut_check_console_dump(struct unit_test_state *uts, int total_bytes);
 		ut_failf(uts, __FILE__, __LINE__, __func__,		\
 			 "console", "\nExpected '%s',\n     got '%s'",	\
 			 uts->expect_str, uts->actual_str);		\
-		__ret = CMD_RET_FAILURE;				\
+		return CMD_RET_FAILURE;					\
 	}								\
 	__ret;								\
 })
@@ -329,7 +329,7 @@ int ut_check_console_dump(struct unit_test_state *uts, int total_bytes);
 		ut_failf(uts, __FILE__, __LINE__, __func__,		\
 			 "console", "\nExpected '%s',\n     got '%s'",	\
 			 uts->expect_str, uts->actual_str);		\
-		__ret = CMD_RET_FAILURE;				\
+		return CMD_RET_FAILURE;					\
 	}								\
 	__ret;								\
 })
@@ -341,7 +341,7 @@ int ut_check_console_dump(struct unit_test_state *uts, int total_bytes);
 	if (ut_check_skipline(uts)) {					\
 		ut_failf(uts, __FILE__, __LINE__, __func__,		\
 			 "console", "\nExpected a line, got end");	\
-		__ret = CMD_RET_FAILURE;				\
+		return CMD_RET_FAILURE;					\
 	}								\
 	__ret;								\
 })
@@ -354,7 +354,7 @@ int ut_check_console_dump(struct unit_test_state *uts, int total_bytes);
 		ut_failf(uts, __FILE__, __LINE__, __func__,		\
 			 "console", "\nExpected '%s',\n     got to '%s'", \
 			 uts->expect_str, uts->actual_str);		\
-		__ret = CMD_RET_FAILURE;				\
+		return CMD_RET_FAILURE;					\
 	}								\
 	__ret;								\
 })
@@ -367,7 +367,7 @@ int ut_check_console_dump(struct unit_test_state *uts, int total_bytes);
 		ut_failf(uts, __FILE__, __LINE__, __func__,		\
 			 "console", "Expected no more output, got '%s'",\
 			 uts->actual_str);				\
-		__ret = CMD_RET_FAILURE;				\
+		return CMD_RET_FAILURE;					\
 	}								\
 	__ret;								\
 })
@@ -381,7 +381,7 @@ int ut_check_console_dump(struct unit_test_state *uts, int total_bytes);
 			 "console",					\
 			"Expected dump of length %x bytes, got '%s'",	\
 			 total_bytes, uts->actual_str);			\
-		__ret = CMD_RET_FAILURE;				\
+		return CMD_RET_FAILURE;					\
 	}								\
 	__ret;								\
 })
Signature · 1 line
2.41.0.rc0.172.g3f132b7071-goog
#6 lore raw

PATCH 6/40 gpio: Avoid using an invalid ofnode

In reply to Simon Glass

Devices do not necessarily have nodes attached to them, since they can be created from platdata. In SPL a devicetree may in fact not exist at all.

Check the node before using it. This avoids failure when OF_CHECKS is enabled.

Fixes 5fc7cf8c8e2 ("gpio: add gpio-hog support")

---

 drivers/gpio/gpio-uclass.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpio/gpio-uclass.c +1 -1
index 712119c3415b..31027f3d9902 100644
@@ -1474,7 +1474,7 @@ static int gpio_post_bind(struct udevice *dev)
 	}
 #endif
 
-	if (CONFIG_IS_ENABLED(GPIO_HOG)) {
+	if (CONFIG_IS_ENABLED(GPIO_HOG) && dev_has_ofnode(dev)) {
 		struct udevice *child;
 		ofnode node;
 
Signature · 1 line
2.41.0.rc0.172.g3f132b7071-goog
Reviewed-by on v1 6/40
#7 lore raw

Re: [PATCH 06/40] gpio: Avoid using an invalid ofnode

Hello Simon,

Quoted 6 lines · Simon Glass

Devices do not necessarily have nodes attached to them, since they can be created from platdata. In SPL a devicetree may in fact not exist at all.

Check the node before using it. This avoids failure when OF_CHECKS is enabled.

Quoted 6 lines
Fixes 5fc7cf8c8e2 ("gpio: add gpio-hog support")

---

 drivers/gpio/gpio-uclass.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Thanks!

bye,
Heiko

Signature · 3 lines
DENX Software Engineering GmbH,      Managing Director: Erika Unter
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: +49-8142-66989-52   Fax: +49-8142-66989-80   Email: [email protected]
#8 lore raw

PATCH 7/40 dm: core: Avoid registering an inaccessible tree

In reply to Simon Glass

At present there are various restrictions on the use of livetree:

- It is only available once the tree is unflattened, i.e. after relocation
- It is designed to be used with the control FDT
- It can (in principle) be used with other FDTs, but only if they are unflattened first; this is not supported

Add a few checks to make sure that any tree that is created is actually valid. Otherwise it can be confusing when nodes and properties cannot actually be accessed.

---

 drivers/core/ofnode.c | 9 +++++++++
 1 file changed, 9 insertions(+)
drivers/core/ofnode.c +9 -0
index ec574c446079..1d4ab5bb6f2f 100644
@@ -60,6 +60,11 @@ static oftree oftree_ensure(void *fdt)
 				return oftree_null();
 			}
 
+			if (of_live_active()) {
+				log_err("Cannot register a flattree when OF_LIVE is active\n");
+				return oftree_null();
+			}
+
 			/* register the new tree */
 			i = oftree_count++;
 			oftree_list[i] = fdt;
@@ -133,6 +138,10 @@ oftree oftree_from_fdt(void *fdt)
 	if (CONFIG_IS_ENABLED(OFNODE_MULTI_TREE))
 		return oftree_ensure(fdt);
 
+#ifdef OF_CHECKS
+	if (of_live_active())
+		return oftree_null();
+#endif
 	tree.fdt = fdt;
 
 	return tree;
Signature · 1 line
2.41.0.rc0.172.g3f132b7071-goog
#9 lore raw

PATCH 8/40 video: Drop #ifdefs from console_truetype

In reply to Simon Glass

Use if() instead to reduce the number of build paths.

---

 drivers/video/console_truetype.c | 112 +++++++++++++++----------------
 1 file changed, 56 insertions(+), 56 deletions(-)
drivers/video/console_truetype.c +56 -56
index 6b5390136a7a..0ea8a9f6215e 100644
@@ -154,33 +154,33 @@ static int console_truetype_set_row(struct udevice *dev, uint row, int clr)
 	end = line + met->font_size * vid_priv->line_length;
 
 	switch (vid_priv->bpix) {
-#ifdef CONFIG_VIDEO_BPP8
 	case VIDEO_BPP8: {
 		u8 *dst;
 
-		for (dst = line; dst < (u8 *)end; ++dst)
-			*dst = clr;
+		if (IS_ENABLED(CONFIG_VIDEO_BPP8)) {
+			for (dst = line; dst < (u8 *)end; ++dst)
+				*dst = clr;
+		}
 		break;
 	}
-#endif
-#ifdef CONFIG_VIDEO_BPP16
 	case VIDEO_BPP16: {
 		u16 *dst = line;
 
-		for (dst = line; dst < (u16 *)end; ++dst)
-			*dst = clr;
+		if (IS_ENABLED(CONFIG_VIDEO_BPP16)) {
+			for (dst = line; dst < (u16 *)end; ++dst)
+				*dst = clr;
+		}
 		break;
 	}
-#endif
-#ifdef CONFIG_VIDEO_BPP32
 	case VIDEO_BPP32: {
 		u32 *dst = line;
 
-		for (dst = line; dst < (u32 *)end; ++dst)
-			*dst = clr;
+		if (IS_ENABLED(CONFIG_VIDEO_BPP32)) {
+			for (dst = line; dst < (u32 *)end; ++dst)
+				*dst = clr;
+		}
 		break;
 	}
-#endif
 	default:
 		return -ENOSYS;
 	}
@@ -317,52 +317,52 @@ static int console_truetype_putc_xy(struct udevice *dev, uint x, uint y,
 				end = dst;
 			}
 			break;
-#ifdef CONFIG_VIDEO_BPP16
 		case VIDEO_BPP16: {
 			uint16_t *dst = (uint16_t *)line + xoff;
 			int i;
 
-			for (i = 0; i < width; i++) {
-				int val = *bits;
-				int out;
-
-				if (vid_priv->colour_bg)
-					val = 255 - val;
-				out = val >> 3 |
-					(val >> 2) << 5 |
-					(val >> 3) << 11;
-				if (vid_priv->colour_fg)
-					*dst++ |= out;
-				else
-					*dst++ &= out;
-				bits++;
+			if (IS_ENABLED(CONFIG_VIDEO_BPP16)) {
+				for (i = 0; i < width; i++) {
+					int val = *bits;
+					int out;
+
+					if (vid_priv->colour_bg)
+						val = 255 - val;
+					out = val >> 3 |
+						(val >> 2) << 5 |
+						(val >> 3) << 11;
+					if (vid_priv->colour_fg)
+						*dst++ |= out;
+					else
+						*dst++ &= out;
+					bits++;
+				}
+				end = dst;
 			}
-			end = dst;
 			break;
 		}
-#endif
-#ifdef CONFIG_VIDEO_BPP32
 		case VIDEO_BPP32: {
 			u32 *dst = (u32 *)line + xoff;
 			int i;
 
-			for (i = 0; i < width; i++) {
-				int val = *bits;
-				int out;
-
-				if (vid_priv->colour_bg)
-					val = 255 - val;
-				out = val | val << 8 | val << 16;
-				if (vid_priv->colour_fg)
-					*dst++ |= out;
-				else
-					*dst++ &= out;
-				bits++;
+			if (IS_ENABLED(CONFIG_VIDEO_BPP32)) {
+				for (i = 0; i < width; i++) {
+					int val = *bits;
+					int out;
+
+					if (vid_priv->colour_bg)
+						val = 255 - val;
+					out = val | val << 8 | val << 16;
+					if (vid_priv->colour_fg)
+						*dst++ |= out;
+					else
+						*dst++ &= out;
+					bits++;
+				}
+				end = dst;
 			}
-			end = dst;
 			break;
 		}
-#endif
 		default:
 			free(data);
 			return -ENOSYS;
@@ -405,33 +405,33 @@ static int console_truetype_erase(struct udevice *dev, int xstart, int ystart,
 	line = start;
 	for (row = ystart; row < yend; row++) {
 		switch (vid_priv->bpix) {
-#ifdef CONFIG_VIDEO_BPP8
 		case VIDEO_BPP8: {
 			uint8_t *dst = line;
 
-			for (i = 0; i < pixels; i++)
-				*dst++ = clr;
+			if (IS_ENABLED(CONFIG_VIDEO_BPP8)) {
+				for (i = 0; i < pixels; i++)
+					*dst++ = clr;
+			}
 			break;
 		}
-#endif
-#ifdef CONFIG_VIDEO_BPP16
 		case VIDEO_BPP16: {
 			uint16_t *dst = line;
 
-			for (i = 0; i < pixels; i++)
-				*dst++ = clr;
+			if (IS_ENABLED(CONFIG_VIDEO_BPP16)) {
+				for (i = 0; i < pixels; i++)
+					*dst++ = clr;
+			}
 			break;
 		}
-#endif
-#ifdef CONFIG_VIDEO_BPP32
 		case VIDEO_BPP32: {
 			uint32_t *dst = line;
 
-			for (i = 0; i < pixels; i++)
-				*dst++ = clr;
+			if (IS_ENABLED(CONFIG_VIDEO_BPP32)) {
+				for (i = 0; i < pixels; i++)
+					*dst++ = clr;
+			}
 			break;
 		}
-#endif
 		default:
 			return -ENOSYS;
 		}
Signature · 1 line
2.41.0.rc0.172.g3f132b7071-goog
#10 lore raw

PATCH 9/40 video: Provide a way to clear part of the console

In reply to Simon Glass

This is useful when the background colour must be written before text is updated, to avoid strange display artifacts.

Add a function for this, using the existing code from the truetype console.

---

 drivers/video/console_truetype.c | 72 ++------------------------------
 drivers/video/video-uclass.c     | 52 +++++++++++++++++++++++
 include/video.h                  | 16 +++++++
 3 files changed, 71 insertions(+), 69 deletions(-)
drivers/video/console_truetype.c +3 -69
index 0ea8a9f6215e..63d7557c71a0 100644
@@ -378,72 +378,6 @@ static int console_truetype_putc_xy(struct udevice *dev, uint x, uint y,
 	return width_frac;
 }
 
-/**
- * console_truetype_erase() - Erase a character
- *
- * This is used for backspace. We erase a square of the display within the
- * given bounds.
- *
- * @dev:	Device to update
- * @xstart:	X start position in pixels from the left
- * @ystart:	Y start position in pixels from the top
- * @xend:	X end position in pixels from the left
- * @yend:	Y end position  in pixels from the top
- * @clr:	Value to write
- * Return: 0 if OK, -ENOSYS if the display depth is not supported
- */
-static int console_truetype_erase(struct udevice *dev, int xstart, int ystart,
-				  int xend, int yend, int clr)
-{
-	struct video_priv *vid_priv = dev_get_uclass_priv(dev->parent);
-	void *start, *line;
-	int pixels = xend - xstart;
-	int row, i, ret;
-
-	start = vid_priv->fb + ystart * vid_priv->line_length;
-	start += xstart * VNBYTES(vid_priv->bpix);
-	line = start;
-	for (row = ystart; row < yend; row++) {
-		switch (vid_priv->bpix) {
-		case VIDEO_BPP8: {
-			uint8_t *dst = line;
-
-			if (IS_ENABLED(CONFIG_VIDEO_BPP8)) {
-				for (i = 0; i < pixels; i++)
-					*dst++ = clr;
-			}
-			break;
-		}
-		case VIDEO_BPP16: {
-			uint16_t *dst = line;
-
-			if (IS_ENABLED(CONFIG_VIDEO_BPP16)) {
-				for (i = 0; i < pixels; i++)
-					*dst++ = clr;
-			}
-			break;
-		}
-		case VIDEO_BPP32: {
-			uint32_t *dst = line;
-
-			if (IS_ENABLED(CONFIG_VIDEO_BPP32)) {
-				for (i = 0; i < pixels; i++)
-					*dst++ = clr;
-			}
-			break;
-		}
-		default:
-			return -ENOSYS;
-		}
-		line += vid_priv->line_length;
-	}
-	ret = vidconsole_sync_copy(dev, start, line);
-	if (ret)
-		return ret;
-
-	return 0;
-}
-
 /**
  * console_truetype_backspace() - Handle a backspace operation
  *
@@ -482,9 +416,9 @@ static int console_truetype_backspace(struct udevice *dev)
 	else
 		xend = vid_priv->xsize;
 
-	console_truetype_erase(dev, VID_TO_PIXEL(pos->xpos_frac), pos->ypos,
-			       xend, pos->ypos + vc_priv->y_charsize,
-			       vid_priv->colour_bg);
+	video_fill_part(vid_dev, VID_TO_PIXEL(pos->xpos_frac), pos->ypos,
+			xend, pos->ypos + vc_priv->y_charsize,
+			vid_priv->colour_bg);
 
 	/* Move the cursor back to where it was when we pushed this record */
 	vc_priv->xcur_frac = pos->xpos_frac;
drivers/video/video-uclass.c +52 -0

58 lines not on this page · raw message

include/video.h +16 -0
index 29c4f51efb08..e5b0db294734 100644
@@ -203,6 +203,22 @@ int video_clear(struct udevice *dev);
  */
 int video_fill(struct udevice *dev, u32 colour);
 
+/**
+ * video_fill_part() - Erase a region
+ *
+ * Erase a rectangle of the display within the given bounds.
+ *
+ * @dev:	Device to update
+ * @xstart:	X start position in pixels from the left
+ * @ystart:	Y start position in pixels from the top
+ * @xend:	X end position in pixels from the left
+ * @yend:	Y end position  in pixels from the top
+ * @colour:	Value to write
+ * Return: 0 if OK, -ENOSYS if the display depth is not supported
+ */
+int video_fill_part(struct udevice *dev, int xstart, int ystart, int xend,
+		    int yend, u32 colour);
+
 /**
  * video_sync() - Sync a device's frame buffer with its hardware
  *
Signature · 1 line
2.41.0.rc0.172.g3f132b7071-goog
#11 lore raw

PATCH 10/40 expo: Store the console in the expo

In reply to Simon Glass

Rather than finding this each time, keep a pointer to it. This simplifies the code a little.

---

 boot/expo.c    |  9 +++++++++
 boot/scene.c   | 10 ++--------
 include/expo.h |  2 ++
 3 files changed, 13 insertions(+), 8 deletions(-)
boot/expo.c +9 -0
index 05950a176038..cd1b1a3de50c 100644
@@ -83,7 +83,16 @@ const char *expo_get_str(struct expo *exp, uint id)
 
 int expo_set_display(struct expo *exp, struct udevice *dev)
 {
+	struct udevice *cons;
+	int ret;
+
+	ret = device_find_first_child_by_uclass(dev, UCLASS_VIDEO_CONSOLE,
+						&cons);
+	if (ret)
+		return log_msg_ret("con", ret);
+
 	exp->display = dev;
+	exp->cons = cons;
 
 	return 0;
 }
boot/scene.c +2 -8
index d2f77c008cf7..7e9ba047f2d4 100644
@@ -278,16 +278,10 @@ static int scene_obj_render(struct scene_obj *obj, bool text_mode)
 {
 	struct scene *scn = obj->scene;
 	struct expo *exp = scn->expo;
-	struct udevice *cons, *dev = exp->display;
+	struct udevice *dev = exp->display;
+	struct udevice *cons = text_mode ? NULL : exp->cons;
 	int x, y, ret;
 
-	cons = NULL;
-	if (!text_mode) {
-		ret = device_find_first_child_by_uclass(dev,
-							UCLASS_VIDEO_CONSOLE,
-							&cons);
-	}
-
 	x = obj->x;
 	y = obj->y;
 
include/expo.h +2 -0
index 8827f4b0b45f..06f5629e03f8 100644
@@ -50,6 +50,7 @@ struct expo_action {
  *
  * @name: Name of the expo (allocated)
  * @display: Display to use (`UCLASS_VIDEO`), or NULL to use text mode
+ * @cons: Console to use (`UCLASS_VIDEO_CONSOLE`), or NULL to use text mode
  * @scene_id: Current scene ID (0 if none)
  * @next_id: Next ID number to use, for automatic allocation
  * @action: Action selected by user. At present only one is supported, with the
@@ -62,6 +63,7 @@ struct expo_action {
 struct expo {
 	char *name;
 	struct udevice *display;
+	struct udevice *cons;
 	uint scene_id;
 	uint next_id;
 	struct expo_action action;
Signature · 1 line
2.41.0.rc0.172.g3f132b7071-goog
#12 lore raw

PATCH 11/40 expo: Avoid automatically arranging the scene

In reply to Simon Glass

This should ideally be done once after all scene changes have been made. Require an explicit call when everything is ready.

Always arrange after a key it sent, just for convenience.

---

 boot/bootflow_menu.c |  4 ++++
 boot/expo.c          | 15 ++++++++++++++-
 boot/scene.c         |  7 -------
 boot/scene_menu.c    |  9 ---------
 test/boot/expo.c     |  4 +++-
 5 files changed, 21 insertions(+), 18 deletions(-)
boot/bootflow_menu.c +4 -0
index 7f06dac0af77..de0f44535690 100644
@@ -124,6 +124,10 @@ int bootflow_menu_new(struct expo **expp)
 		priv->num_bootflows++;
 	}
 
+	ret = scene_arrange(scn);
+	if (ret)
+		return log_msg_ret("arr", ret);
+
 	*expp = exp;
 
 	return 0;
boot/expo.c +14 -1
index cd1b1a3de50c..bfdda9570c60 100644
@@ -116,8 +116,16 @@ struct scene *expo_lookup_scene_id(struct expo *exp, uint scene_id)
 
 int expo_set_scene_id(struct expo *exp, uint scene_id)
 {
-	if (!expo_lookup_scene_id(exp, scene_id))
+	struct scene *scn;
+	int ret;
+
+	scn = expo_lookup_scene_id(exp, scene_id);
+	if (!scn)
 		return log_msg_ret("id", -ENOENT);
+	ret = scene_arrange(scn);
+	if (ret)
+		return log_msg_ret("arr", ret);
+
 	exp->scene_id = scene_id;
 
 	return 0;
@@ -165,6 +173,11 @@ int expo_send_key(struct expo *exp, int key)
 		ret = scene_send_key(scn, key, &exp->action);
 		if (ret)
 			return log_msg_ret("key", ret);
+
+		/* arrange it to get any changes */
+		ret = scene_arrange(scn);
+		if (ret)
+			return log_msg_ret("arr", ret);
 	}
 
 	return scn ? 0 : -ECHILD;
boot/scene.c +0 -7
index 7e9ba047f2d4..1383be20321f 100644
@@ -211,8 +211,6 @@ int scene_obj_set_pos(struct scene *scn, uint id, int x, int y)
 		return log_msg_ret("find", -ENOENT);
 	obj->x = x;
 	obj->y = y;
-	if (obj->type == SCENEOBJT_MENU)
-		scene_menu_arrange(scn, (struct scene_obj_menu *)obj);
 
 	return 0;
 }
@@ -391,11 +389,6 @@ int scene_send_key(struct scene *scn, int key, struct expo_action *event)
 			ret = scene_menu_send_key(scn, menu, key, event);
 			if (ret)
 				return log_msg_ret("key", ret);
-
-			/* only allow one menu */
-			ret = scene_menu_arrange(scn, menu);
-			if (ret)
-				return log_msg_ret("arr", ret);
 			break;
 		}
 	}
boot/scene_menu.c +0 -9
index 18998e862ab3..9ee911f2fa38 100644
@@ -158,10 +158,6 @@ int scene_menu(struct scene *scn, const char *name, uint id,
 		*menup = menu;
 	INIT_LIST_HEAD(&menu->item_head);
 
-	ret = scene_menu_arrange(scn, menu);
-	if (ret)
-		return log_msg_ret("pos", ret);
-
 	return menu->obj.id;
 }
 
@@ -258,7 +254,6 @@ int scene_menuitem(struct scene *scn, uint menu_id, const char *name, uint id,
 {
 	struct scene_obj_menu *menu;
 	struct scene_menitem *item;
-	int ret;
 
 	menu = scene_obj_find(scn, menu_id, SCENEOBJT_MENU);
 	if (!menu)
@@ -285,10 +280,6 @@ int scene_menuitem(struct scene *scn, uint menu_id, const char *name, uint id,
 	item->flags = flags;
 	list_add_tail(&item->sibling, &menu->item_head);
 
-	ret = scene_menu_arrange(scn, menu);
-	if (ret)
-		return log_msg_ret("pos", ret);
-
 	if (itemp)
 		*itemp = item;
 
test/boot/expo.c +3 -1
index 3c0bc78bb7a4..56a22ba9b066 100644
@@ -348,7 +348,9 @@ static int expo_object_menu(struct unit_test_state *uts)
 	ut_asserteq(desc_id, item->desc_id);
 	ut_asserteq(preview_id, item->preview_id);
 
-	/* adding an item should cause the first item to become current */
+	ut_assertok(scene_arrange(scn));
+
+	/* arranging the scene should cause the first item to become current */
 	ut_asserteq(id, menu->cur_item_id);
 
 	/* the title should be at the top */
Signature · 1 line
2.41.0.rc0.172.g3f132b7071-goog
#13 lore raw

PATCH 12/40 console: Correct truetype spacing error

In reply to Simon Glass

The putc_xy() method is supposed to return the amount of space used. The existing implementation erroneously adds the previous sub-pixel position to the returned value. This spaces out the characters very slightly more than it should. It is seldom noticeable but it does make accurate measurement of the text impossible.

Fix this minor but long-standing bug.

Fixes a29b012037c ("video: Add a console driver that uses TrueType fonts")

---

 drivers/video/console_truetype.c | 2 +-
 test/dm/video.c                  | 6 +++---
 2 files changed, 4 insertions(+), 4 deletions(-)
drivers/video/console_truetype.c +1 -1
index 63d7557c71a0..6f3fc82f9b05 100644
@@ -256,7 +256,7 @@ static int console_truetype_putc_xy(struct udevice *dev, uint x, uint y,
 	 */
 	x_shift = xpos - (double)tt_floor(xpos);
 	xpos += advance * met->scale;
-	width_frac = (int)VID_TO_POS(xpos);
+	width_frac = (int)VID_TO_POS(advance * met->scale);
 	if (x + width_frac >= vc_priv->xsize_frac)
 		return -EAGAIN;
 
test/dm/video.c +3 -3
index 30778157d940..6d9c55c14035 100644
@@ -556,7 +556,7 @@ static int dm_test_video_truetype(struct unit_test_state *uts)
 	ut_assertok(video_get_nologo(uts, &dev));
 	ut_assertok(uclass_get_device(UCLASS_VIDEO_CONSOLE, 0, &con));
 	vidconsole_put_string(con, test_string);
-	ut_asserteq(12237, compress_frame_buffer(uts, dev));
+	ut_asserteq(12187, compress_frame_buffer(uts, dev));
 
 	return 0;
 }
@@ -577,7 +577,7 @@ static int dm_test_video_truetype_scroll(struct unit_test_state *uts)
 	ut_assertok(video_get_nologo(uts, &dev));
 	ut_assertok(uclass_get_device(UCLASS_VIDEO_CONSOLE, 0, &con));
 	vidconsole_put_string(con, test_string);
-	ut_asserteq(35030, compress_frame_buffer(uts, dev));
+	ut_asserteq(34481, compress_frame_buffer(uts, dev));
 
 	return 0;
 }
@@ -598,7 +598,7 @@ static int dm_test_video_truetype_bs(struct unit_test_state *uts)
 	ut_assertok(video_get_nologo(uts, &dev));
 	ut_assertok(uclass_get_device(UCLASS_VIDEO_CONSOLE, 0, &con));
 	vidconsole_put_string(con, test_string);
-	ut_asserteq(29018, compress_frame_buffer(uts, dev));
+	ut_asserteq(29579, compress_frame_buffer(uts, dev));
 
 	return 0;
 }
Signature · 1 line
2.41.0.rc0.172.g3f132b7071-goog
#14 lore raw

PATCH 13/40 expo: Rename exp_set_text_mode()

In reply to Simon Glass

Rename this function to match its peers, using the full "expo' prefix.

---

 boot/bootflow_menu.c | 2 +-
 boot/expo.c          | 2 +-
 include/expo.h       | 4 ++--
 test/boot/expo.c     | 2 +-
 4 files changed, 5 insertions(+), 5 deletions(-)
boot/bootflow_menu.c +1 -1
index de0f44535690..7c1abe5772cd 100644
@@ -209,7 +209,7 @@ int bootflow_menu_run(struct bootstd_priv *std, bool text_mode,
 		return log_msg_ret("scn", ret);
 
 	if (text_mode)
-		exp_set_text_mode(exp, text_mode);
+		expo_set_text_mode(exp, text_mode);
 
 	done = false;
 	do {
boot/expo.c +1 -1
index bfdda9570c60..e7c81a3983d3 100644
@@ -97,7 +97,7 @@ int expo_set_display(struct expo *exp, struct udevice *dev)
 	return 0;
 }
 
-void exp_set_text_mode(struct expo *exp, bool text_mode)
+void expo_set_text_mode(struct expo *exp, bool text_mode)
 {
 	exp->text_mode = text_mode;
 }
include/expo.h +2 -2
index 06f5629e03f8..f77ee7085192 100644
@@ -306,12 +306,12 @@ int expo_set_scene_id(struct expo *exp, uint scene_id);
 int expo_render(struct expo *exp);
 
 /**
- * exp_set_text_mode() - Controls whether the expo renders in text mode
+ * expo_set_text_mode() - Controls whether the expo renders in text mode
  *
  * @exp: Expo to update
  * @text_mode: true to use text mode, false to use the console
  */
-void exp_set_text_mode(struct expo *exp, bool text_mode);
+void expo_set_text_mode(struct expo *exp, bool text_mode);
 
 /**
  * scene_new() - create a new scene in a expo
test/boot/expo.c +1 -1
index 56a22ba9b066..70750d307ffa 100644
@@ -507,7 +507,7 @@ static int expo_render_image(struct unit_test_state *uts)
 	ut_assert_console_end();
 
 	/* now try in text mode */
-	exp_set_text_mode(exp, true);
+	expo_set_text_mode(exp, true);
 	ut_assertok(expo_render(exp));
 
 	ut_assert_nextline("U-Boot    :    Boot Menu");
Signature · 1 line
2.41.0.rc0.172.g3f132b7071-goog
#15 lore raw

PATCH 14/40 fs: Create functions to load and allocate a file

In reply to Simon Glass

This functionality current sits in bootstd, but it is more generally useful. Add a function to load a file into memory, allocating it as needed. Adjust bootstd to use this version.

Note: Tests are added in the subsequent patch which converts the 'cat' command to use this function.

---

 boot/bootmeth-uclass.c | 30 ++--------------------
 fs/fs.c                | 58 ++++++++++++++++++++++++++++++++++++++++++
 include/fs.h           | 38 +++++++++++++++++++++++++++
 3 files changed, 98 insertions(+), 28 deletions(-)
boot/bootmeth-uclass.c +2 -28
index 3b3e0614dafa..701ee8ad1c8f 100644
@@ -301,32 +301,6 @@ int bootmeth_try_file(struct bootflow *bflow, struct blk_desc *desc,
 	return 0;
 }
 
-static int alloc_file(const char *fname, uint size, void **bufp)
-{
-	loff_t bytes_read;
-	ulong addr;
-	char *buf;
-	int ret;
-
-	buf = malloc(size + 1);
-	if (!buf)
-		return log_msg_ret("buf", -ENOMEM);
-	addr = map_to_sysmem(buf);
-
-	ret = fs_read(fname, addr, 0, size, &bytes_read);
-	if (ret) {
-		free(buf);
-		return log_msg_ret("read", ret);
-	}
-	if (size != bytes_read)
-		return log_msg_ret("bread", -EIO);
-	buf[size] = '\0';
-
-	*bufp = buf;
-
-	return 0;
-}
-
 int bootmeth_alloc_file(struct bootflow *bflow, uint size_limit, uint align)
 {
 	void *buf;
@@ -338,7 +312,7 @@ int bootmeth_alloc_file(struct bootflow *bflow, uint size_limit, uint align)
 	if (size > size_limit)
 		return log_msg_ret("chk", -E2BIG);
 
-	ret = alloc_file(bflow->fname, bflow->size, &buf);
+	ret = fs_read_alloc(bflow->fname, bflow->size, align, &buf);
 	if (ret)
 		return log_msg_ret("all", ret);
 
@@ -374,7 +348,7 @@ int bootmeth_alloc_other(struct bootflow *bflow, const char *fname,
 	if (ret)
 		return log_msg_ret("fs", ret);
 
-	ret = alloc_file(path, size, &buf);
+	ret = fs_read_alloc(path, size, 0, &buf);
 	if (ret)
 		return log_msg_ret("all", ret);
 
fs/fs.c +58 -0

73 lines not on this page · raw message

include/fs.h +38 -0
index 8370d88cb203..e341a0ed01bf 100644
@@ -300,4 +300,42 @@ int do_fs_type(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]);
  */
 int do_fs_types(struct cmd_tbl *cmdtp, int flag, int argc, char * const argv[]);
 
+/**
+ * fs_read_alloc() - Allocate space for a file and read it
+ *
+ * You must call fs_set_blk_dev() or a similar function before calling this,
+ * since that sets up the block device to use.
+ *
+ * The file is terminated with a nul character
+ *
+ * @fname: Filename to read
+ * @size: Size of file to read (must be correct!)
+ * @align: Alignment to use for memory allocation (0 for default)
+ * @bufp: On success, returns the allocated buffer with the nul-terminated file
+ *	in it
+ * Return: 0 if OK, -ENOMEM if out of memory, -EIO if read failed
+ */
+int fs_read_alloc(const char *fname, ulong size, uint align, void **bufp);
+
+/**
+ * fs_load_alloc() - Load a file into allocated space
+ *
+ * The file is terminated with a nul character
+ *
+ * @ifname: Interface name to read from (e.g. "mmc")
+ * @dev_part_str: Device and partition string (e.g. "1:2")
+ * @fname: Filename to read
+ * @max_size: Maximum allowed size for the file (use 0 for 1GB)
+ * @align: Alignment to use for memory allocation (0 for default)
+ * @bufp: On success, returns the allocated buffer with the nul-terminated file
+ *	in it
+ * @sizep: On success, returns the size of the file
+ * Return: 0 if OK, -ENOMEM if out of memory, -ENOENT if the file does not
+ * exist, -ENOMEDIUM if the device does not exist, -E2BIG if the file is too
+ * large (greater than @max_size), -EIO if read failed
+ */
+int fs_load_alloc(const char *ifname, const char *dev_part_str,
+		  const char *fname, ulong max_size, ulong align, void **bufp,
+		  ulong *sizep);
+
 #endif /* _FS_H */
Signature · 1 line
2.41.0.rc0.172.g3f132b7071-goog
#16 lore raw

PATCH 15/40 cat: Update command to use fs_load_alloc()

In reply to Simon Glass

Use this new function since it implements the required functionality and reduces duplicated code.

---

 cmd/cat.c | 47 +++++++++++++++++------------------------------
 1 file changed, 17 insertions(+), 30 deletions(-)
cmd/cat.c +17 -30
index 1273a26b1457..b059080193d4 100644
@@ -17,8 +17,8 @@ static int do_cat(struct cmd_tbl *cmdtp, int flag, int argc,
 	char *dev;
 	char *file;
 	char *buffer;
-	phys_addr_t addr;
-	loff_t file_size;
+	ulong file_size;
+	int ret;
 
 	if (argc < 4)
 		return CMD_RET_USAGE;
@@ -27,40 +27,27 @@ static int do_cat(struct cmd_tbl *cmdtp, int flag, int argc,
 	dev = argv[2];
 	file = argv[3];
 
+	ret = fs_load_alloc(ifname, dev, file, 0, 0, (void **)&buffer,
+			    &file_size);
+
 	// check file exists
-	if (fs_set_blk_dev(ifname, dev, FS_TYPE_ANY))
+	switch (ret) {
+	case 0:
+		break;
+	case -ENOMEDIUM:
 		return CMD_RET_FAILURE;
-
-	if (!fs_exists(file)) {
+	case -ENOENT:
 		log_err("File does not exist: ifname=%s dev=%s file=%s\n", ifname, dev, file);
 		return CMD_RET_FAILURE;
-	}
-
-	// get file size
-	if (fs_set_blk_dev(ifname, dev, FS_TYPE_ANY))
+	case -E2BIG:
+		log_err("File is too large: ifname=%s dev=%s file=%s\n", ifname, dev, file);
 		return CMD_RET_FAILURE;
-
-	if (fs_size(file, &file_size)) {
-		log_err("Cannot read file size: ifname=%s dev=%s file=%s\n", ifname, dev, file);
+	case -ENOMEM:
+		log_err("Not enough memory: ifname=%s dev=%s file=%s\n", ifname, dev, file);
 		return CMD_RET_FAILURE;
-	}
-
-	// allocate memory for file content
-	buffer = calloc(sizeof(char), file_size + 1);
-	if (!buffer) {
-		log_err("Out of memory\n");
-		return CMD_RET_FAILURE;
-	}
-
-	// map pointer to system memory
-	addr = map_to_sysmem(buffer);
-
-	// read file to memory
-	if (fs_set_blk_dev(ifname, dev, FS_TYPE_ANY))
-		return CMD_RET_FAILURE;
-
-	if (fs_read(file, addr, 0, 0, &file_size)) {
-		log_err("Cannot read file: ifname=%s dev=%s file=%s\n", ifname, dev, file);
+	default:
+	case -EIO:
+		log_err("File-read failed: ifname=%s dev=%s file=%s\n", ifname, dev, file);
 		return CMD_RET_FAILURE;
 	}
 
Signature · 1 line
2.41.0.rc0.172.g3f132b7071-goog
#17 lore raw

PATCH 16/40 fdt: Align the start of the livetree

In reply to Simon Glass

Ensure that the block of memory used by live tree is aligned according to the default for structures. This ensures that the root node appears at the start of the block, so it can be used with free(), rather than being 4 bytes later in some cases.

This corrects a rather obscure bug in unflatten_device_tree().

Fixes 8b50d526ea5 ("dm: Add a function to create a 'live' device tree")

---

 include/dm/of.h  |  2 ++
 lib/of_live.c    |  5 ++++-
 test/dm/ofnode.c | 26 ++++++++++++++++++++++++++
 3 files changed, 32 insertions(+), 1 deletion(-)
include/dm/of.h +2 -0
index fce7cef0ff69..b1c934f610d3 100644
@@ -63,6 +63,8 @@ struct device_node {
 	struct device_node *sibling;
 };
 
+#define BAD_OF_ROOT	0xdead11e3
+
 #define OF_MAX_PHANDLE_ARGS 16
 
 /**
lib/of_live.c +4 -1
index 1b5964d09a9d..05588d5ed282 100644
@@ -287,9 +287,12 @@ int unflatten_device_tree(const void *blob, struct device_node **mynodes)
 	debug("  size is %lx, allocating...\n", size);
 
 	/* Allocate memory for the expanded device tree */
-	mem = malloc(size + 4);
+	mem = memalign(__alignof__(struct device_node), size + 4);
 	memset(mem, '\0', size);
 
+	/* Set up value for dm_test_livetree_align() */
+	*(u32 *)mem = BAD_OF_ROOT;
+
 	*(__be32 *)(mem + size) = cpu_to_be32(0xdeadbeef);
 
 	debug("  unflattening %p...\n", mem);
test/dm/ofnode.c +26 -0
index 473a8cef5780..64baaf68db3a 100644
@@ -1240,3 +1240,29 @@ static int dm_test_ofnode_copy_props_ot(struct unit_test_state *uts)
 	return 0;
 }
 DM_TEST(dm_test_ofnode_copy_props_ot, UT_TESTF_SCAN_FDT | UT_TESTF_OTHER_FDT);
+
+/* check that the livetree is aligned to a structure boundary */
+static int dm_test_livetree_align(struct unit_test_state *uts)
+{
+	const int align = __alignof__(struct unit_test_state);
+	struct device_node *node;
+	u32 *sentinel;
+	ulong start;
+
+	start = (ulong)gd_of_root();
+	ut_asserteq(start, ALIGN(start, align));
+
+	node = gd_of_root();
+	sentinel = (void *)node - sizeof(u32);
+
+	/*
+	 * The sentinel should be overwritten with the root node. If it isn't,
+	 * then the root node is not at the very start of the livetree memory
+	 * area, and free(root) will fail to free the memory used by the
+	 * livetree.
+	 */
+	ut_assert(*sentinel != BAD_OF_ROOT);
+
+	return 0;
+}
+DM_TEST(dm_test_livetree_align, UT_TESTF_LIVE_TREE);
Signature · 1 line
2.41.0.rc0.172.g3f132b7071-goog
#18 lore raw

PATCH 17/40 fdt: Clarify the fdt pre-relocation warning

In reply to Simon Glass

Reword this so it is easier to understand.

---

 drivers/core/ofnode.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/core/ofnode.c +1 -1
index 1d4ab5bb6f2f..dee890b5527b 100644
@@ -72,7 +72,7 @@ static oftree oftree_ensure(void *fdt)
 		}
 	} else {
 		if (fdt != gd->fdt_blob) {
-			log_debug("Cannot only access control FDT before relocation\n");
+			log_debug("Only the control FDT can be accessed before relocation\n");
 			return oftree_null();
 		}
 	}
Signature · 1 line
2.41.0.rc0.172.g3f132b7071-goog
#19 lore raw

PATCH 18/40 fdt: Allow more general use of livetree

In reply to Simon Glass

At present livetree can only be used for the control FDT. It is useful to be able to use the ofnode API for other FDTs, e.g. those used by the upcoming configuration editor.

We already have most of the support present, and tests can be marked with the UT_TESTF_OTHER_FDT flag to use another FDT as a special case. But with this change, the functionality becomes more generally available.

Plumb in the require support.

---

 drivers/core/ofnode.c | 26 +++++++++++++++++++++-----
 include/dm/ofnode.h   | 10 ++++++++++
 include/of_live.h     | 10 ++++++++++
 lib/of_live.c         |  6 ++++++
 test/dm/ofnode.c      | 19 +++++++++++++++++++
 5 files changed, 66 insertions(+), 5 deletions(-)
drivers/core/ofnode.c +21 -5
index dee890b5527b..8df16e56af5c 100644
@@ -12,6 +12,7 @@
 #include <fdt_support.h>
 #include <log.h>
 #include <malloc.h>
+#include <of_live.h>
 #include <linux/libfdt.h>
 #include <dm/of_access.h>
 #include <dm/of_addr.h>
@@ -51,6 +52,20 @@ static oftree oftree_ensure(void *fdt)
 	oftree tree;
 	int i;
 
+	if (of_live_active()) {
+		struct device_node *root;
+		int ret;
+
+		ret = unflatten_device_tree(fdt, &root);
+		if (ret) {
+			log_err("Failed to create live tree: err=%d\n", ret);
+			return oftree_null();
+		}
+		tree = oftree_from_np(root);
+
+		return tree;
+	}
+
 	if (gd->flags & GD_FLG_RELOC) {
 		i = oftree_find(fdt);
 		if (i == -1) {
@@ -60,11 +75,6 @@ static oftree oftree_ensure(void *fdt)
 				return oftree_null();
 			}
 
-			if (of_live_active()) {
-				log_err("Cannot register a flattree when OF_LIVE is active\n");
-				return oftree_null();
-			}
-
 			/* register the new tree */
 			i = oftree_count++;
 			oftree_list[i] = fdt;
@@ -82,6 +92,12 @@ static oftree oftree_ensure(void *fdt)
 	return tree;
 }
 
+void oftree_dispose(oftree tree)
+{
+	if (of_live_active())
+		of_live_free(tree.np);
+}
+
 void *ofnode_lookup_fdt(ofnode node)
 {
 	if (gd->flags & GD_FLG_RELOC) {
include/dm/ofnode.h +10 -0
index 443db6252ddc..0f38b3e736de 100644
@@ -352,6 +352,16 @@ static inline oftree oftree_from_np(struct device_node *root)
 	return tree;
 }
 
+/**
+ * oftree_dispose() - Dispose of an oftree
+ *
+ * This can be used to dispose of a tree that has been created (other than
+ * the control FDT which must not be disposed)
+ *
+ * @tree: Tree to dispose
+ */
+void oftree_dispose(oftree tree);
+
 /**
  * ofnode_name_eq() - Check if the node name is equivalent to a given name
  *                    ignoring the unit address
include/of_live.h +10 -0
index f59d6af3350d..05e86ac06b1a 100644
@@ -36,4 +36,14 @@ int of_live_build(const void *fdt_blob, struct device_node **rootp);
  */
 int unflatten_device_tree(const void *blob, struct device_node **mynodes);
 
+/**
+ * of_live_free() - Dispose of a livetree
+ *
+ * This frees memory used by the tree, after which @root becomes invalid and
+ * cannot be used
+ *
+ * @root: Tree to dispose
+ */
+void of_live_free(struct device_node *root);
+
 #endif
lib/of_live.c +6 -0
index 05588d5ed282..25f7af61061e 100644
@@ -330,3 +330,9 @@ int of_live_build(const void *fdt_blob, struct device_node **rootp)
 
 	return ret;
 }
+
+void of_live_free(struct device_node *root)
+{
+	/* the tree is stored as a contiguous block of memory */
+	free(root);
+}
test/dm/ofnode.c +19 -0
index 64baaf68db3a..6fbebc7da085 100644
@@ -1266,3 +1266,22 @@ static int dm_test_livetree_align(struct unit_test_state *uts)
 	return 0;
 }
 DM_TEST(dm_test_livetree_align, UT_TESTF_LIVE_TREE);
+
+/* check that it is possible to load an arbitrary livetree */
+static int dm_test_livetree_ensure(struct unit_test_state *uts)
+{
+	oftree tree;
+	ofnode node;
+
+	/* read from other.dtb */
+	ut_assertok(test_load_other_fdt(uts));
+	tree = oftree_from_fdt(uts->other_fdt);
+	ut_assert(oftree_valid(tree));
+	node = oftree_path(tree, "/node/subnode");
+	ut_assert(ofnode_valid(node));
+	ut_asserteq_str("sandbox-other2",
+			ofnode_read_string(node, "compatible"));
+
+	return 0;
+}
+DM_TEST(dm_test_livetree_ensure, 0);
Signature · 1 line
2.41.0.rc0.172.g3f132b7071-goog
#20 lore raw

PATCH 19/40 bootstd: Add a separate log category for expo

In reply to Simon Glass

This feature is different enough from bootstd that it probably deserves its own log category. It cannot use a uclass since it is not a device.

Add a new category.

---

 boot/expo.c       | 2 ++
 boot/scene.c      | 2 ++
 boot/scene_menu.c | 2 +-
 common/log.c      | 1 +
 include/log.h     | 2 ++
 5 files changed, 8 insertions(+), 1 deletion(-)
boot/expo.c +2 -0
index e7c81a3983d3..8b966b6c793c 100644
@@ -6,6 +6,8 @@
  * Written by Simon Glass <[email protected]>
  */
 
+#define LOG_CATEGORY	LOGC_EXPO
+
 #include <common.h>
 #include <dm.h>
 #include <expo.h>
boot/scene.c +2 -0
index 1383be20321f..43c978e6ee80 100644
@@ -6,6 +6,8 @@
  * Written by Simon Glass <[email protected]>
  */
 
+#define LOG_CATEGORY	LOGC_EXPO
+
 #include <common.h>
 #include <dm.h>
 #include <expo.h>
boot/scene_menu.c +1 -1
index 9ee911f2fa38..8b04d4403139 100644
@@ -6,7 +6,7 @@
  * Written by Simon Glass <[email protected]>
  */
 
-#define LOG_CATEGORY	LOGC_BOOT
+#define LOG_CATEGORY	LOGC_EXPO
 
 #include <common.h>
 #include <dm.h>
common/log.c +1 -0
index 7cfc49bc28a5..6f02a25c5931 100644
@@ -31,6 +31,7 @@ static const char *const log_cat_name[] = {
 	"boot",
 	"event",
 	"fs",
+	"expo",
 };
 
 _Static_assert(ARRAY_SIZE(log_cat_name) == LOGC_COUNT - LOGC_NONE,
include/log.h +2 -0
index 3bab40b61715..6e84f080ef3d 100644
@@ -102,6 +102,8 @@ enum log_category_t {
 	LOGC_EVENT,
 	/** @LOGC_FS: Related to filesystems */
 	LOGC_FS,
+	/** @LOGC_EXPO: Related to expo handling */
+	LOGC_EXPO,
 	/** @LOGC_COUNT: Number of log categories */
 	LOGC_COUNT,
 	/** @LOGC_END: Sentinel value for lists of log categories */
Signature · 1 line
2.41.0.rc0.172.g3f132b7071-goog
#21 lore raw

PATCH 20/40 video: Correct docs for video_index_to_colour()

In reply to Simon Glass

This uses the private data of the video uclass, not the console uclass (its child). Update the comment to avoid confusion.

Fixes a032e4b55ea ("video: Move console colours to the video uclass")

---

 include/video.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
include/video.h +1 -1
index e5b0db294734..dd0d55baa31a 100644
@@ -162,7 +162,7 @@ enum colour_idx {
  * The caller has to guarantee that the color index is less than
  * VID_COLOR_COUNT.
  *
- * @priv	private data of the console device
+ * @priv	private data of the video device (UCLASS_VIDEO)
  * @idx		color index
  * Return:	color value
  */
Signature · 1 line
2.41.0.rc0.172.g3f132b7071-goog
#22 lore raw

PATCH 21/40 video: Allow temporary colour changes

In reply to Simon Glass

It is sometimes necessary to highlight some text in a different colour. Add an easy way to do this and then restore the original console colours.

---

 drivers/video/vidconsole-uclass.c | 20 ++++++++++++++++++++
 include/video_console.h           | 30 ++++++++++++++++++++++++++++++
 2 files changed, 50 insertions(+)
drivers/video/vidconsole-uclass.c +20 -0
index a21fde0e1d46..3f89537c47b7 100644
@@ -596,6 +596,26 @@ int vidconsole_select_font(struct udevice *dev, const char *name, uint size)
 	return ops->select_font(dev, name, size);
 }
 
+void vidconsole_push_colour(struct udevice *dev, enum colour_idx fg,
+			    enum colour_idx bg, struct vidconsole_colour *old)
+{
+	struct video_priv *vid_priv = dev_get_uclass_priv(dev->parent);
+
+	old->colour_fg = vid_priv->colour_fg;
+	old->colour_bg = vid_priv->colour_bg;
+
+	vid_priv->colour_fg = video_index_to_colour(vid_priv, fg);
+	vid_priv->colour_bg = video_index_to_colour(vid_priv, bg);
+}
+
+void vidconsole_pop_colour(struct udevice *dev, struct vidconsole_colour *old)
+{
+	struct video_priv *vid_priv = dev_get_uclass_priv(dev->parent);
+
+	vid_priv->colour_fg = old->colour_fg;
+	vid_priv->colour_bg = old->colour_bg;
+}
+
 /* Set up the number of rows and colours (rotated drivers override this) */
 static int vidconsole_pre_probe(struct udevice *dev)
 {
include/video_console.h +30 -0
index 3db9a7e1fb95..81d4c4d874df 100644
@@ -71,6 +71,17 @@ struct vidfont_info {
 	const char *name;
 };
 
+/**
+ * struct vidconsole_colour - Holds colour information
+ *
+ * @colour_fg:	Foreground colour (pixel value)
+ * @colour_bg:	Background colour (pixel value)
+ */
+struct vidconsole_colour {
+	u32 colour_fg;
+	u32 colour_bg;
+};
+
 /**
  * struct vidconsole_ops - Video console operations
  *
@@ -204,6 +215,25 @@ int vidconsole_get_font(struct udevice *dev, int seq,
  */
 int vidconsole_select_font(struct udevice *dev, const char *name, uint size);
 
+/**
+ * vidconsole_push_colour() - Temporarily change the font colour
+ *
+ * @dev:	Device to adjust
+ * @fg:		Foreground colour to select
+ * @bg:		Background colour to select
+ * @old:	Place to store the current colour, so it can be restored
+ */
+void vidconsole_push_colour(struct udevice *dev, enum colour_idx fg,
+			    enum colour_idx bg, struct vidconsole_colour *old);
+
+/**
+ * vidconsole_pop_colour() - Restore the original colour
+ *
+ * @dev:	Device to adjust
+ * @old:	Old colour to be restored
+ */
+void vidconsole_pop_colour(struct udevice *dev, struct vidconsole_colour *old);
+
 /**
  * vidconsole_putc_xy() - write a single character to a position
  *
Signature · 1 line
2.41.0.rc0.172.g3f132b7071-goog
#23 lore raw

PATCH 22/40 console: Allow measuring the bounding box of text

In reply to Simon Glass

For laying out text accurately it is necessary to know the width and height of the text. Add a measure() method to the console API, so this can be supported.

Add an implementation for truetype and a base implementation for the normal console.

---

 drivers/video/console_truetype.c  | 64 ++++++++++++++++++++++++++++++-
 drivers/video/vidconsole-uclass.c | 22 +++++++++++
 include/video_console.h           | 48 +++++++++++++++++++++++
 3 files changed, 132 insertions(+), 2 deletions(-)
drivers/video/console_truetype.c +62 -2
index 6f3fc82f9b05..288123a2e065 100644
@@ -614,8 +614,8 @@ static void select_metrics(struct udevice *dev, struct console_tt_metrics *met)
 	vc_priv->tab_width_frac = VID_TO_POS(met->font_size) * 8 / 2;
 }
 
-static int truetype_select_font(struct udevice *dev, const char *name,
-				uint size)
+static int get_metrics(struct udevice *dev, const char *name, uint size,
+		       struct console_tt_metrics **metp)
 {
 	struct console_tt_priv *priv = dev_get_priv(dev);
 	struct console_tt_metrics *met;
@@ -653,11 +653,70 @@ static int truetype_select_font(struct udevice *dev, const char *name,
 		met = priv->metrics;
 	}
 
+	*metp = met;
+
+	return 0;
+}
+
+static int truetype_select_font(struct udevice *dev, const char *name,
+				uint size)
+{
+	struct console_tt_metrics *met;
+	int ret;
+
+	ret = get_metrics(dev, name, size, &met);
+	if (ret)
+		return log_msg_ret("sel", ret);
+
 	select_metrics(dev, met);
 
 	return 0;
 }
 
+int truetype_measure(struct udevice *dev, const char *name, uint size,
+		     const char *text, struct vidconsole_bbox *bbox)
+{
+	struct console_tt_metrics *met;
+	stbtt_fontinfo *font;
+	int lsb, advance;
+	const char *s;
+	int width;
+	int last;
+	int ret;
+
+	ret = get_metrics(dev, name, size, &met);
+	if (ret)
+		return log_msg_ret("sel", ret);
+
+	bbox->valid = false;
+	if (!*text)
+		return 0;
+
+	font = &met->font;
+	width = 0;
+	for (last = 0, s = text; *s; s++) {
+		int ch = *s;
+
+		/* Used kerning to fine-tune the position of this character */
+		if (last)
+			width += stbtt_GetCodepointKernAdvance(font, last, ch);
+
+		/* First get some basic metrics about this character */
+		stbtt_GetCodepointHMetrics(font, ch, &advance, &lsb);
+
+		width += advance;
+		last = ch;
+	}
+
+	bbox->valid = true;
+	bbox->x0 = 0;
+	bbox->y0 = 0;
+	bbox->x1 = tt_ceil((double)width * met->scale);
+	bbox->y1 = met->font_size;
+
+	return 0;
+}
+
 const char *console_truetype_get_font_size(struct udevice *dev, uint *sizep)
 {
 	struct console_tt_priv *priv = dev_get_priv(dev);
@@ -709,6 +768,7 @@ struct vidconsole_ops console_truetype_ops = {
 	.get_font	= console_truetype_get_font,
 	.get_font_size	= console_truetype_get_font_size,
 	.select_font	= truetype_select_font,
+	.measure	= truetype_measure,
 };
 
 U_BOOT_DRIVER(vidconsole_truetype) = {
drivers/video/vidconsole-uclass.c +22 -0
index 3f89537c47b7..05f930478096 100644
@@ -596,6 +596,28 @@ int vidconsole_select_font(struct udevice *dev, const char *name, uint size)
 	return ops->select_font(dev, name, size);
 }
 
+int vidconsole_measure(struct udevice *dev, const char *name, uint size,
+		       const char *text, struct vidconsole_bbox *bbox)
+{
+	struct vidconsole_priv *priv = dev_get_uclass_priv(dev);
+	struct vidconsole_ops *ops = vidconsole_get_ops(dev);
+	int ret;
+
+	if (ops->select_font) {
+		ret = ops->measure(dev, name, size, text, bbox);
+		if (ret != -ENOSYS)
+			return ret;
+	}
+
+	bbox->valid = true;
+	bbox->x0 = 0;
+	bbox->y0 = 0;
+	bbox->x1 = priv->x_charsize * strlen(text);
+	bbox->y1 = priv->y_charsize;
+
+	return 0;
+}
+
 void vidconsole_push_colour(struct udevice *dev, enum colour_idx fg,
 			    enum colour_idx bg, struct vidconsole_colour *old)
 {
include/video_console.h +48 -0

66 lines not on this page · raw message

Signature · 1 line
2.41.0.rc0.172.g3f132b7071-goog
#24 lore raw

PATCH 23/40 expo: Allow setting the start of the dynamic-ID range

In reply to Simon Glass

Provide a way to set this value so that it is easy to separate the statically allocated IDs (generated by the caller) from those generated dynamically by expo itself.

---

 boot/expo.c          | 15 +++++++++++++++
 boot/scene.c         | 10 ----------
 doc/develop/expo.rst |  3 +++
 include/expo.h       | 19 +++++++++++++++++++
 4 files changed, 37 insertions(+), 10 deletions(-)
boot/expo.c +15 -0
index 8b966b6c793c..be11cfd4e946 100644
@@ -56,6 +56,21 @@ void expo_destroy(struct expo *exp)
 	free(exp);
 }
 
+uint resolve_id(struct expo *exp, uint id)
+{
+	if (!id)
+		id = exp->next_id++;
+	else if (id >= exp->next_id)
+		exp->next_id = id + 1;
+
+	return id;
+}
+
+void expo_set_dynamic_start(struct expo *exp, uint dyn_start)
+{
+	exp->next_id = dyn_start;
+}
+
 int expo_str(struct expo *exp, const char *name, uint id, const char *str)
 {
 	struct expo_string *estr;
boot/scene.c +0 -10
index 43c978e6ee80..2ac9bfcdbd52 100644
@@ -18,16 +18,6 @@
 #include <linux/input.h>
 #include "scene_internal.h"
 
-uint resolve_id(struct expo *exp, uint id)
-{
-	if (!id)
-		id = exp->next_id++;
-	else if (id >= exp->next_id)
-		exp->next_id = id + 1;
-
-	return id;
-}
-
 int scene_new(struct expo *exp, const char *name, uint id, struct scene **scnp)
 {
 	struct scene *scn;
doc/develop/expo.rst +3 -0
index 32dd7f090307..9565974a28e9 100644
@@ -85,6 +85,9 @@ or even the IDs of objects. Programmatic creation of many items in a loop can be
 handled by allocating space in the enum for a maximum number of items, then
 adding the loop count to the enum values to obtain unique IDs.
 
+Where dynamic IDs are need, use expo_set_dynamic_start() to set the start value,
+so that they are allocated above the starting (enum) IDs.
+
 All text strings are stored in a structure attached to the expo, referenced by
 a text ID. This makes it easier at some point to implement multiple languages or
 to support Unicode strings.
include/expo.h +19 -0
index f77ee7085192..b8f5327f2664 100644
@@ -257,6 +257,25 @@ int expo_new(const char *name, void *priv, struct expo **expp);
  */
 void expo_destroy(struct expo *exp);
 
+/**
+ * expo_set_dynamic_start() - Set the start of the 'dynamic' IDs
+ *
+ * It is common for a set of 'static' IDs to be used to refer to objects in the
+ * expo. These typically use an enum so that they are defined in sequential
+ * order.
+ *
+ * Dynamic IDs (for objects not in the enum) are intended to be used for
+ * objects to which the code does not need to refer. These are ideally located
+ * above the static IDs.
+ *
+ * Use this function to set the start of the dynamic range, making sure that the
+ * value is higher than all the statically allocated IDs.
+ *
+ * @exp: Expo to update
+ * @dyn_start: Start ID that expo should use for dynamic allocation
+ */
+void expo_set_dynamic_start(struct expo *exp, uint dyn_start);
+
 /**
  * expo_str() - add a new string to an expo
  *
Signature · 1 line
2.41.0.rc0.172.g3f132b7071-goog
#25 lore raw

PATCH 24/40 video: Use enum with video_index_to_colour()

In reply to Simon Glass

Use the provided enum with this function, so it is clearer what should be passed to it.

---

 drivers/video/video-uclass.c | 2 +-
 include/video.h              | 4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)
drivers/video/video-uclass.c +1 -1
index 1db049bec004..5bf40e1138f4 100644
@@ -260,7 +260,7 @@ static const struct vid_rgb colours[VID_COLOUR_COUNT] = {
 	{ 0xff, 0xff, 0xff },  /* white */
 };
 
-u32 video_index_to_colour(struct video_priv *priv, unsigned int idx)
+u32 video_index_to_colour(struct video_priv *priv, enum colour_idx idx)
 {
 	switch (priv->bpix) {
 	case VIDEO_BPP16:
include/video.h +2 -2
index dd0d55baa31a..124eb49fab7d 100644
@@ -163,10 +163,10 @@ enum colour_idx {
  * VID_COLOR_COUNT.
  *
  * @priv	private data of the video device (UCLASS_VIDEO)
- * @idx		color index
+ * @idx		color index (e.g. VID_YELLOW)
  * Return:	color value
  */
-u32 video_index_to_colour(struct video_priv *priv, unsigned int idx);
+u32 video_index_to_colour(struct video_priv *priv, enum colour_idx idx);
 
 /**
  * video_reserve() - Reserve frame-buffer memory for video devices
Signature · 1 line
2.41.0.rc0.172.g3f132b7071-goog
#26 lore raw

PATCH 25/40 expo: Add width and height to objects

In reply to Simon Glass

At present objects only have a position so it is not possible to determine the amount of space they take up on the display.

Add width and height properties, using a struct to keep all the dimensions together.

For now this is not used. Future work will set up these new properties.

---

 boot/scene.c      |  8 ++++----
 boot/scene_menu.c | 12 ++++++------
 include/expo.h    | 21 +++++++++++++++++----
 test/boot/expo.c  | 32 ++++++++++++++++----------------
 4 files changed, 43 insertions(+), 30 deletions(-)
boot/scene.c +4 -4
index 2ac9bfcdbd52..8033d77fb266 100644
@@ -201,8 +201,8 @@ int scene_obj_set_pos(struct scene *scn, uint id, int x, int y)
 	obj = scene_obj_find(scn, id, SCENEOBJT_NONE);
 	if (!obj)
 		return log_msg_ret("find", -ENOENT);
-	obj->x = x;
-	obj->y = y;
+	obj->dim.x = x;
+	obj->dim.y = y;
 
 	return 0;
 }
@@ -272,8 +272,8 @@ static int scene_obj_render(struct scene_obj *obj, bool text_mode)
 	struct udevice *cons = text_mode ? NULL : exp->cons;
 	int x, y, ret;
 
-	x = obj->x;
-	y = obj->y;
+	x = obj->dim.x;
+	y = obj->dim.y;
 
 	switch (obj->type) {
 	case SCENEOBJT_NONE:
boot/scene_menu.c +6 -6
index 8b04d4403139..eed7565f6a61 100644
@@ -49,9 +49,9 @@ int scene_menu_arrange(struct scene *scn, struct scene_obj_menu *menu)
 	int y, cur_y;
 	int ret;
 
-	y = menu->obj.y;
+	y = menu->obj.dim.y;
 	if (menu->title_id) {
-		ret = scene_obj_set_pos(scn, menu->title_id, menu->obj.x, y);
+		ret = scene_obj_set_pos(scn, menu->title_id, menu->obj.dim.x, y);
 		if (ret < 0)
 			return log_msg_ret("tit", ret);
 
@@ -89,18 +89,18 @@ int scene_menu_arrange(struct scene *scn, struct scene_obj_menu *menu)
 		 * pointer, then the key and the description
 		 */
 		if (item->label_id) {
-			ret = scene_obj_set_pos(scn, item->label_id, menu->obj.x,
+			ret = scene_obj_set_pos(scn, item->label_id, menu->obj.dim.x,
 						y);
 			if (ret < 0)
 				return log_msg_ret("nam", ret);
 		}
 
-		ret = scene_obj_set_pos(scn, item->key_id, menu->obj.x + 230,
+		ret = scene_obj_set_pos(scn, item->key_id, menu->obj.dim.x + 230,
 					y);
 		if (ret < 0)
 			return log_msg_ret("key", ret);
 
-		ret = scene_obj_set_pos(scn, item->desc_id, menu->obj.x + 280,
+		ret = scene_obj_set_pos(scn, item->desc_id, menu->obj.dim.x + 280,
 					y);
 		if (ret < 0)
 			return log_msg_ret("des", ret);
@@ -134,7 +134,7 @@ int scene_menu_arrange(struct scene *scn, struct scene_obj_menu *menu)
 		 * points to
 		 */
 		ret = scene_obj_set_pos(scn, menu->pointer_id,
-					menu->obj.x + 200, cur_y);
+					menu->obj.dim.x + 200, cur_y);
 		if (ret < 0)
 			return log_msg_ret("ptr", ret);
 	}
include/expo.h +17 -4
index b8f5327f2664..5135954ba139 100644
@@ -122,6 +122,21 @@ enum scene_obj_t {
 	SCENEOBJT_MENU,
 };
 
+/**
+ * struct scene_dim - Dimensions of an object
+ *
+ * @x: x position, in pixels from left side
+ * @y: y position, in pixels from top
+ * @w: width, in pixels
+ * @h: height, in pixels
+ */
+struct scene_dim {
+	int x;
+	int y;
+	int w;
+	int h;
+};
+
 /**
  * struct scene_obj - information about an object in a scene
  *
@@ -129,8 +144,7 @@ enum scene_obj_t {
  * @name: Name of the object (allocated)
  * @id: ID number of the object
  * @type: Type of this object
- * @x: x position, in pixels from left side
- * @y: y position, in pixels from top
+ * @dim: Dimensions for this object
  * @hide: true if the object should be hidden
  * @sibling: Node to link this object to its siblings
  */
@@ -139,8 +153,7 @@ struct scene_obj {
 	char *name;
 	uint id;
 	enum scene_obj_t type;
-	int x;
-	int y;
+	struct scene_dim dim;
 	bool hide;
 	struct list_head sibling;
 };
test/boot/expo.c +16 -16
index 70750d307ffa..10cb7b246f3f 100644
@@ -250,8 +250,8 @@ static int expo_object_attr(struct unit_test_state *uts)
 	ut_assert(id > 0);
 
 	ut_assertok(scene_obj_set_pos(scn, OBJ_LOGO, 123, 456));
-	ut_asserteq(123, img->obj.x);
-	ut_asserteq(456, img->obj.y);
+	ut_asserteq(123, img->obj.dim.x);
+	ut_asserteq(456, img->obj.dim.y);
 
 	ut_asserteq(-ENOENT, scene_obj_set_pos(scn, OBJ_TEXT2, 0, 0));
 
@@ -307,8 +307,8 @@ static int expo_object_menu(struct unit_test_state *uts)
 	ut_asserteq(0, menu->pointer_id);
 
 	ut_assertok(scene_obj_set_pos(scn, OBJ_MENU, 50, 400));
-	ut_asserteq(50, menu->obj.x);
-	ut_asserteq(400, menu->obj.y);
+	ut_asserteq(50, menu->obj.dim.x);
+	ut_asserteq(400, menu->obj.dim.y);
 
 	id = scene_txt_str(scn, "title", OBJ_MENU_TITLE, STR_MENU_TITLE,
 			   "Main Menu", &tit);
@@ -354,24 +354,24 @@ static int expo_object_menu(struct unit_test_state *uts)
 	ut_asserteq(id, menu->cur_item_id);
 
 	/* the title should be at the top */
-	ut_asserteq(menu->obj.x, tit->obj.x);
-	ut_asserteq(menu->obj.y, tit->obj.y);
+	ut_asserteq(menu->obj.dim.x, tit->obj.dim.x);
+	ut_asserteq(menu->obj.dim.y, tit->obj.dim.y);
 
 	/* the first item should be next */
-	ut_asserteq(menu->obj.x, name1->obj.x);
-	ut_asserteq(menu->obj.y + 32, name1->obj.y);
+	ut_asserteq(menu->obj.dim.x, name1->obj.dim.x);
+	ut_asserteq(menu->obj.dim.y + 32, name1->obj.dim.y);
 
-	ut_asserteq(menu->obj.x + 230, key1->obj.x);
-	ut_asserteq(menu->obj.y + 32, key1->obj.y);
+	ut_asserteq(menu->obj.dim.x + 230, key1->obj.dim.x);
+	ut_asserteq(menu->obj.dim.y + 32, key1->obj.dim.y);
 
-	ut_asserteq(menu->obj.x + 200, ptr->obj.x);
-	ut_asserteq(menu->obj.y + 32, ptr->obj.y);
+	ut_asserteq(menu->obj.dim.x + 200, ptr->obj.dim.x);
+	ut_asserteq(menu->obj.dim.y + 32, ptr->obj.dim.y);
 
-	ut_asserteq(menu->obj.x + 280, desc1->obj.x);
-	ut_asserteq(menu->obj.y + 32, desc1->obj.y);
+	ut_asserteq(menu->obj.dim.x + 280, desc1->obj.dim.x);
+	ut_asserteq(menu->obj.dim.y + 32, desc1->obj.dim.y);
 
-	ut_asserteq(-4, prev1->obj.x);
-	ut_asserteq(menu->obj.y + 32, prev1->obj.y);
+	ut_asserteq(-4, prev1->obj.dim.x);
+	ut_asserteq(menu->obj.dim.y + 32, prev1->obj.dim.y);
 	ut_asserteq(false, prev1->obj.hide);
 
 	expo_destroy(exp);
Signature · 1 line
2.41.0.rc0.172.g3f132b7071-goog
#27 lore raw

PATCH 26/40 expo: Use flags for objects

In reply to Simon Glass

We currently have just a 'hide' property for each object. In preparation for adding more properties, convert the struct to use a flags value, instead of individual booleans. This is more extensible.

---

 boot/scene.c          | 17 +++++++++++++++--
 boot/scene_internal.h | 11 +++++++++++
 include/expo.h        | 13 +++++++++++--
 test/boot/expo.c      |  6 +++---
 4 files changed, 40 insertions(+), 7 deletions(-)
boot/scene.c +15 -2
index 8033d77fb266..dd1472d4f9aa 100644
@@ -208,13 +208,26 @@ int scene_obj_set_pos(struct scene *scn, uint id, int x, int y)
 }
 
 int scene_obj_set_hide(struct scene *scn, uint id, bool hide)
+{
+	int ret;
+
+	ret = scene_obj_flag_clrset(scn, id, SCENEOF_HIDE,
+				    hide ? SCENEOF_HIDE : 0);
+	if (ret)
+		return log_msg_ret("flg", ret);
+
+	return 0;
+}
+
+int scene_obj_flag_clrset(struct scene *scn, uint id, uint clr, uint set)
 {
 	struct scene_obj *obj;
 
 	obj = scene_obj_find(scn, id, SCENEOBJT_NONE);
 	if (!obj)
 		return log_msg_ret("find", -ENOENT);
-	obj->hide = hide;
+	obj->flags &= ~clr;
+	obj->flags |= set;
 
 	return 0;
 }
@@ -358,7 +371,7 @@ int scene_render(struct scene *scn)
 	int ret;
 
 	list_for_each_entry(obj, &scn->obj_head, sibling) {
-		if (!obj->hide) {
+		if (!(obj->flags & SCENEOF_HIDE)) {
 			ret = scene_obj_render(obj, exp->text_mode);
 			if (ret && ret != -ENOTSUPP)
 				return log_msg_ret("ren", ret);
boot/scene_internal.h +11 -0
index 9f173dd749f0..24a2ba6a6a3d 100644
@@ -54,6 +54,17 @@ void *scene_obj_find(struct scene *scn, uint id, enum scene_obj_t type);
 int scene_obj_add(struct scene *scn, const char *name, uint id,
 		  enum scene_obj_t type, uint size, struct scene_obj **objp);
 
+/**
+ * scene_obj_flag_clrset() - Adjust object flags
+ *
+ * @scn: Scene to update
+ * @id: ID of object to update
+ * @clr: Bits to clear in the object's flags
+ * @set: Bits to set in the object's flags
+ * Returns 0 if OK, -ENOENT if the object was not found
+ */
+int scene_obj_flag_clrset(struct scene *scn, uint id, uint clr, uint set);
+
 /**
  * scene_menu_arrange() - Set the position of things in the menu
  *
include/expo.h +11 -2
index 5135954ba139..b6777cebcbec 100644
@@ -137,6 +137,15 @@ struct scene_dim {
 	int h;
 };
 
+/**
+ * enum scene_obj_flags_t - flags for objects
+ *
+ * @SCENEOF_HIDE: object should be hidden
+ */
+enum scene_obj_flags_t {
+	SCENEOF_HIDE	= 1 << 0,
+};
+
 /**
  * struct scene_obj - information about an object in a scene
  *
@@ -145,7 +154,7 @@ struct scene_dim {
  * @id: ID number of the object
  * @type: Type of this object
  * @dim: Dimensions for this object
- * @hide: true if the object should be hidden
+ * @flags: Flags for this object
  * @sibling: Node to link this object to its siblings
  */
 struct scene_obj {
@@ -154,7 +163,7 @@ struct scene_obj {
 	uint id;
 	enum scene_obj_t type;
 	struct scene_dim dim;
-	bool hide;
+	int flags;
 	struct list_head sibling;
 };
 
test/boot/expo.c +3 -3
index 10cb7b246f3f..5088776f7bd5 100644
@@ -372,7 +372,7 @@ static int expo_object_menu(struct unit_test_state *uts)
 
 	ut_asserteq(-4, prev1->obj.dim.x);
 	ut_asserteq(menu->obj.dim.y + 32, prev1->obj.dim.y);
-	ut_asserteq(false, prev1->obj.hide);
+	ut_asserteq(false, prev1->obj.flags & SCENEOF_HIDE);
 
 	expo_destroy(exp);
 
@@ -488,10 +488,10 @@ static int expo_render_image(struct unit_test_state *uts)
 
 	/* make sure only the preview for the second item is shown */
 	obj = scene_obj_find(scn, ITEM1_PREVIEW, SCENEOBJT_NONE);
-	ut_asserteq(true, obj->hide);
+	ut_asserteq(true, obj->flags & SCENEOF_HIDE);
 
 	obj = scene_obj_find(scn, ITEM2_PREVIEW, SCENEOBJT_NONE);
-	ut_asserteq(false, obj->hide);
+	ut_asserteq(false, obj->flags & SCENEOF_HIDE);
 
 	/* select it */
 	ut_assertok(expo_send_key(exp, BKEY_SELECT));
Signature · 1 line
2.41.0.rc0.172.g3f132b7071-goog
#28 lore raw

PATCH 27/40 expo: Calculate text bounding-box correctly

In reply to Simon Glass

Rather than estimating, measure the text accurately, using the new vidconsole feature. This allows accurate placement of objects.

---

 boot/scene.c | 30 ++++++++++++++++++++++--------
 1 file changed, 22 insertions(+), 8 deletions(-)
boot/scene.c +22 -8
index dd1472d4f9aa..981a18b3ba1c 100644
@@ -257,16 +257,30 @@ int scene_obj_get_hw(struct scene *scn, uint id, int *widthp)
 	case SCENEOBJT_TEXT: {
 		struct scene_obj_txt *txt = (struct scene_obj_txt *)obj;
 		struct expo *exp = scn->expo;
+		struct vidconsole_bbox bbox;
+		const char *str;
+		int len, ret;
 
+		str = expo_get_str(exp, txt->str_id);
+		if (!str)
+			return log_msg_ret("str", -ENOENT);
+		len = strlen(str);
+
+		/* if there is no console, make it up */
+		if (!exp->cons) {
+			if (widthp)
+				*widthp = 8 * len;
+			return 16;
+		}
+
+		ret = vidconsole_measure(scn->expo->cons, txt->font_name,
+					 txt->font_size, str, &bbox);
+		if (ret)
+			return log_msg_ret("mea", ret);
 		if (widthp)
-			*widthp = 16; /* fake value for now */
-		if (txt->font_size)
-			return txt->font_size;
-		if (exp->display)
-			return video_default_font_height(exp->display);
-
-		/* use a sensible default */
-		return 16;
+			*widthp = bbox.x1;
+
+		return bbox.y1;
 	}
 	}
 
Signature · 1 line
2.41.0.rc0.172.g3f132b7071-goog
#29 lore raw

PATCH 28/40 expo: Set up the width and height of objects

In reply to Simon Glass

Provide a way to set the full dimensions of objects, i.e. including the width and height.

For menus, calculate the bounding box of all objects in the menu. Set all labels to be the same size, so that highlighting works correct, once implemented.

---

 boot/expo.c           | 24 +++++++++++++
 boot/scene.c          | 52 ++++++++++++++++++++++++++++
 boot/scene_internal.h | 21 ++++++++++++
 boot/scene_menu.c     | 79 +++++++++++++++++++++++++++++++++++++++++++
 doc/develop/expo.rst  |  2 --
 include/expo.h        | 21 ++++++++++++
 test/boot/expo.c      | 42 +++++++++++++++++++++++
 7 files changed, 239 insertions(+), 2 deletions(-)
boot/expo.c +24 -0
index be11cfd4e946..67cae3c7e28d 100644
@@ -114,6 +114,30 @@ int expo_set_display(struct expo *exp, struct udevice *dev)
 	return 0;
 }
 
+int expo_calc_dims(struct expo *exp)
+{
+	struct scene *scn;
+	int ret;
+
+	if (!exp->cons)
+		return log_msg_ret("dim", -ENOTSUPP);
+
+	list_for_each_entry(scn, &exp->scene_head, sibling) {
+		/*
+		 * Do the menus last so that all the menus' text objects
+		 * are dimensioned
+		 */
+		ret = scene_calc_dims(scn, false);
+		if (ret)
+			return log_msg_ret("scn", ret);
+		ret = scene_calc_dims(scn, true);
+		if (ret)
+			return log_msg_ret("scn", ret);
+	}
+
+	return 0;
+}
+
 void expo_set_text_mode(struct expo *exp, bool text_mode)
 {
 	exp->text_mode = text_mode;
boot/scene.c +52 -0

61 lines not on this page · raw message

boot/scene_internal.h +21 -0
index 24a2ba6a6a3d..00085a2f55d3 100644
@@ -65,6 +65,17 @@ int scene_obj_add(struct scene *scn, const char *name, uint id,
  */
 int scene_obj_flag_clrset(struct scene *scn, uint id, uint clr, uint set);
 
+/**
+ * scene_calc_dims() - Calculate the dimensions of the scene objects
+ *
+ * Updates the width and height of all objects based on their contents
+ *
+ * @scn: Scene to update
+ * @do_menus: true to calculate only menus, false to calculate everything else
+ * Returns 0 if OK, -ENOTSUPP if there is no graphical console
+ */
+int scene_calc_dims(struct scene *scn, bool do_menus);
+
 /**
  * scene_menu_arrange() - Set the position of things in the menu
  *
@@ -133,4 +144,14 @@ int scene_render(struct scene *scn);
  */
 int scene_send_key(struct scene *scn, int key, struct expo_action *event);
 
+/**
+ * scene_menu_calc_dims() - Calculate the dimensions of a menu
+ *
+ * Updates the width and height of the menu based on its contents
+ *
+ * @menu: Menu to update
+ * Returns 0 if OK, -ENOTSUPP if there is no graphical console
+ */
+int scene_menu_calc_dims(struct scene_obj_menu *menu);
+
 #endif /* __SCENE_INTERNAL_H */
boot/scene_menu.c +79 -0

85 lines not on this page · raw message

doc/develop/expo.rst +0 -2
index 9565974a28e9..54861b93acf8 100644
@@ -182,8 +182,6 @@ Some ideas for future work:
 - Add a Kconfig option to drop the names to save code / data space
 - Add a Kconfig option to disable vidconsole support to save code / data space
 - Support both graphical and text menus at the same time on different devices
-- Implement proper measurement of object bounding boxes, to permit more exact
-  layout. This would tidy up the layout when Truetype is not used
 - Support unicode
 - Support curses for proper serial-terminal menus
 
include/expo.h +21 -0
index b6777cebcbec..6c45c403cf79 100644
@@ -327,6 +327,16 @@ const char *expo_get_str(struct expo *exp, uint id);
  */
 int expo_set_display(struct expo *exp, struct udevice *dev);
 
+/**
+ * expo_calc_dims() - Calculate the dimensions of the objects
+ *
+ * Updates the width and height of all objects based on their contents
+ *
+ * @exp: Expo to update
+ * Returns 0 if OK, -ENOTSUPP if there is no graphical console
+ */
+int expo_calc_dims(struct expo *exp);
+
 /**
  * expo_set_scene_id() - Set the current scene ID
  *
@@ -468,6 +478,17 @@ int scene_txt_set_font(struct scene *scn, uint id, const char *font_name,
  */
 int scene_obj_set_pos(struct scene *scn, uint id, int x, int y);
 
+/**
+ * scene_obj_set_size() - Set the size of an object
+ *
+ * @scn: Scene to update
+ * @id: ID of object to update
+ * @w: width in pixels
+ * @h: height in pixels
+ * Returns: 0 if OK, -ENOENT if @id is invalid
+ */
+int scene_obj_set_size(struct scene *scn, uint id, int w, int h);
+
 /**
  * scene_obj_set_hide() - Set whether an object is hidden
  *
test/boot/expo.c +42 -0

48 lines not on this page · raw message

Signature · 1 line
2.41.0.rc0.172.g3f132b7071-goog
#30 lore raw

PATCH 29/40 expo: Support simple themes

In reply to Simon Glass

It is a pain to manually set the fonts of all objects to be consistent. Some spacing settings are also better set globally than by manually positioning each object.

Add a 'theme' to the expo, to hold this information. For now it includes only the font size.

---

 boot/expo.c           | 20 ++++++++++++++++++++
 boot/scene.c          | 28 ++++++++++++++++++++++++++++
 boot/scene_internal.h |  9 +++++++++
 doc/develop/expo.rst  |  9 +++++++--
 include/expo.h        | 24 ++++++++++++++++++++++++
 test/boot/expo.c      |  8 +++++++-
 6 files changed, 95 insertions(+), 3 deletions(-)
boot/expo.c +20 -0
index 67cae3c7e28d..d5e935966bfd 100644
@@ -231,3 +231,23 @@ int expo_action_get(struct expo *exp, struct expo_action *act)
 
 	return act->type == EXPOACT_NONE ? -EAGAIN : 0;
 }
+
+int expo_apply_theme(struct expo *exp, ofnode node)
+{
+	struct scene *scn;
+	struct expo_theme *theme = &exp->theme;
+	int ret;
+
+	log_debug("Applying theme %s\n", ofnode_get_name(node));
+
+	memset(theme, '\0', sizeof(struct expo_theme));
+	ofnode_read_u32(node, "font-size", &theme->font_size);
+
+	list_for_each_entry(scn, &exp->scene_head, sibling) {
+		ret = scene_apply_theme(scn, theme);
+		if (ret)
+			return log_msg_ret("app", ret);
+	}
+
+	return 0;
+}
boot/scene.c +28 -0
index 6d5e3c1f03dd..4dbe12a2b740 100644
@@ -466,3 +466,31 @@ int scene_calc_dims(struct scene *scn, bool do_menus)
 
 	return 0;
 }
+
+int scene_apply_theme(struct scene *scn, struct expo_theme *theme)
+{
+	struct scene_obj *obj;
+	int ret;
+
+	/* Avoid error-checking optional items */
+	scene_txt_set_font(scn, scn->title_id, NULL, theme->font_size);
+
+	list_for_each_entry(obj, &scn->obj_head, sibling) {
+		switch (obj->type) {
+		case SCENEOBJT_NONE:
+		case SCENEOBJT_IMAGE:
+		case SCENEOBJT_MENU:
+			break;
+		case SCENEOBJT_TEXT:
+			scene_txt_set_font(scn, obj->id, NULL,
+					   theme->font_size);
+			break;
+		}
+	}
+
+	ret = scene_arrange(scn);
+	if (ret)
+		return log_msg_ret("arr", ret);
+
+	return 0;
+}
boot/scene_internal.h +9 -0
index 00085a2f55d3..3387a90761ab 100644
@@ -89,6 +89,15 @@ int scene_calc_dims(struct scene *scn, bool do_menus);
  */
 int scene_menu_arrange(struct scene *scn, struct scene_obj_menu *menu);
 
+/**
+ * scene_apply_theme() - Apply a theme to a scene
+ *
+ * @scn: Scene to update
+ * @theme: Theme to apply
+ * Returns: 0 if OK, -ve on error
+ */
+int scene_apply_theme(struct scene *scn, struct expo_theme *theme);
+
 /**
  * scene_menu_send_key() - Send a key to a menu for processing
  *
doc/develop/expo.rst +7 -2
index 54861b93acf8..2f4882899b6d 100644
@@ -155,8 +155,13 @@ such as scanning devices for more bootflows.
 Themes
 ------
 
-Expo does not itself support themes. The bootflow_menu implement supposed a
-basic theme, applying font sizes to the various text objects in the expo.
+Expo supports simple themes, for setting the font size, for example. Use the
+expo_apply_theme() function to load a theme, passing a node with the required
+properties:
+
+font-size
+    Font size to use for all text (type: u32)
+
 
 API documentation
 -----------------
include/expo.h +24 -0
index 6c45c403cf79..ea8f38913d8e 100644
@@ -7,6 +7,7 @@
 #ifndef __SCENE_H
 #define __SCENE_H
 
+#include <dm/ofnode_decl.h>
 #include <linux/list.h>
 
 struct udevice;
@@ -42,6 +43,19 @@ struct expo_action {
 	};
 };
 
+/**
+ * struct expo_theme - theme for the expo
+ *
+ * @font_size: Default font size for all text
+ * @menu_inset: Inset width (on each side and top/bottom) for menu items
+ * @menuitem_gap_y: Gap between menu items in pixels
+ */
+struct expo_theme {
+	u32 font_size;
+	u32 menu_inset;
+	u32 menuitem_gap_y;
+};
+
 /**
  * struct expo - information about an expo
  *
@@ -57,6 +71,7 @@ struct expo_action {
  * type set to EXPOACT_NONE if there is no action
  * @text_mode: true to use text mode for the menu (no vidconsole)
  * @priv: Private data for the controller
+ * @theme: Information about fonts styles, etc.
  * @scene_head: List of scenes
  * @str_head: list of strings
  */
@@ -69,6 +84,7 @@ struct expo {
 	struct expo_action action;
 	bool text_mode;
 	void *priv;
+	struct expo_theme theme;
 	struct list_head scene_head;
 	struct list_head str_head;
 };
@@ -583,4 +599,12 @@ int expo_send_key(struct expo *exp, int key);
  */
 int expo_action_get(struct expo *exp, struct expo_action *act);
 
+/**
+ * expo_apply_theme() - Apply a theme to an expo
+ *
+ * @exp: Expo to update
+ * @node: Node containing the theme
+ */
+int expo_apply_theme(struct expo *exp, ofnode node);
+
 #endif /*__SCENE_H */
test/boot/expo.c +7 -1
index 493d050baf87..c0ef03b59112 100644
@@ -226,7 +226,7 @@ static int expo_object(struct unit_test_state *uts)
 }
 BOOTSTD_TEST(expo_object, UT_TESTF_DM | UT_TESTF_SCAN_FDT);
 
-/* Check setting object attributes */
+/* Check setting object attributes and using themes */
 static int expo_object_attr(struct unit_test_state *uts)
 {
 	struct scene_obj_menu *menu;
@@ -236,6 +236,7 @@ static int expo_object_attr(struct unit_test_state *uts)
 	struct expo *exp;
 	ulong start_mem;
 	char name[100];
+	ofnode node;
 	char *data;
 	int id;
 
@@ -273,6 +274,11 @@ static int expo_object_attr(struct unit_test_state *uts)
 	ut_asserteq(-ENOENT, scene_menu_set_title(scn, OBJ_TEXT2, OBJ_TEXT));
 	ut_asserteq(-EINVAL, scene_menu_set_title(scn, OBJ_MENU, OBJ_TEXT2));
 
+	node = ofnode_path("/bootstd/theme");
+	ut_assert(ofnode_valid(node));
+	ut_assertok(expo_apply_theme(exp, node));
+	ut_asserteq(30, txt->font_size);
+
 	expo_destroy(exp);
 
 	ut_assertok(ut_check_delta(start_mem));
Signature · 1 line
2.41.0.rc0.172.g3f132b7071-goog
#31 lore raw

PATCH 30/40 expo: Move menu-item selection into a function

In reply to Simon Glass

The current implementation supports a 'pointer' object which points to the currently highlighted menu item. We want to support highlighting the label of the menu item instead, e.g. with inverse video. In this case we will need to 'unhighlight' the old item and highlight the new one.

As a first step, move the pointer logic into a function. This fixes a bug where the item is hidden when it should not be.

---

 boot/scene_menu.c | 67 ++++++++++++++++++++++++++++++++++++++---------
 test/boot/expo.c  |  2 +-
 2 files changed, 55 insertions(+), 14 deletions(-)
boot/scene_menu.c +54 -13
index fa79cecdbd93..154be7f0127f 100644
@@ -33,6 +33,51 @@ void scene_menu_destroy(struct scene_obj_menu *menu)
 		scene_menuitem_destroy(item);
 }
 
+static struct scene_menitem *scene_menuitem_find(struct scene_obj_menu *menu,
+						 int id)
+{
+	struct scene_menitem *item;
+
+	list_for_each_entry(item, &menu->item_head, sibling) {
+		if (item->id == id)
+			return item;
+	}
+
+	return NULL;
+}
+
+/**
+ * update_pointers() - Update the pointer object and handle highlights
+ *
+ * @menu: Menu to update
+ * @id: ID of menu item to select/deselect
+ * @point: true if @id is being selected, false if it is being deselected
+ */
+static int update_pointers(struct scene_obj_menu *menu, uint id, bool point)
+{
+	struct scene *scn = menu->obj.scene;
+	const struct scene_menitem *item;
+	int ret;
+
+	item = scene_menuitem_find(menu, id);
+	if (!item)
+		return log_msg_ret("itm", -ENOENT);
+
+	/* adjust the pointer object to point to the selected item */
+	if (menu->pointer_id && item && point) {
+		struct scene_obj *label;
+
+		label = scene_obj_find(scn, item->label_id, SCENEOBJT_NONE);
+
+		ret = scene_obj_set_pos(scn, menu->pointer_id,
+					menu->obj.dim.x + 200, label->dim.y);
+		if (ret < 0)
+			return log_msg_ret("ptr", ret);
+	}
+
+	return 0;
+}
+
 /**
  * menu_point_to_item() - Point to a particular menu item
  *
@@ -40,7 +85,10 @@ void scene_menu_destroy(struct scene_obj_menu *menu)
  */
 static void menu_point_to_item(struct scene_obj_menu *menu, uint item_id)
 {
+	if (menu->cur_item_id)
+		update_pointers(menu, menu->cur_item_id, false);
 	menu->cur_item_id = item_id;
+	update_pointers(menu, item_id, true);
 }
 
 static int scene_bbox_union(struct scene *scn, uint id,
@@ -125,6 +173,7 @@ int scene_menu_calc_dims(struct scene_obj_menu *menu)
 int scene_menu_arrange(struct scene *scn, struct scene_obj_menu *menu)
 {
 	struct scene_menitem *item;
+	uint sel_id;
 	int y, cur_y;
 	int ret;
 
@@ -147,7 +196,7 @@ int scene_menu_arrange(struct scene *scn, struct scene_obj_menu *menu)
 	 * small. This can be updated once text measuring is supported in
 	 * vidconsole
 	 */
-	cur_y = -1;
+	sel_id = menu->cur_item_id;
 	list_for_each_entry(item, &menu->item_head, sibling) {
 		int height;
 
@@ -160,8 +209,8 @@ int scene_menu_arrange(struct scene *scn, struct scene_obj_menu *menu)
 			y += height;
 
 		/* select an item if not done already */
-		if (!menu->cur_item_id)
-			menu_point_to_item(menu, item->id);
+		if (!sel_id)
+			sel_id = item->id;
 
 		/*
 		 * Put the label on the left, then leave a space for the
@@ -207,16 +256,8 @@ int scene_menu_arrange(struct scene *scn, struct scene_obj_menu *menu)
 		y += height;
 	}
 
-	if (menu->pointer_id && cur_y != -1) {
-		/*
-		 * put the pointer to the right of and level with the item it
-		 * points to
-		 */
-		ret = scene_obj_set_pos(scn, menu->pointer_id,
-					menu->obj.dim.x + 200, cur_y);
-		if (ret < 0)
-			return log_msg_ret("ptr", ret);
-	}
+	if (sel_id)
+		menu_point_to_item(menu, sel_id);
 
 	return 0;
 }
test/boot/expo.c +1 -1
index c0ef03b59112..453316ece7c3 100644
@@ -378,7 +378,7 @@ static int expo_object_menu(struct unit_test_state *uts)
 
 	ut_asserteq(-4, prev1->obj.dim.x);
 	ut_asserteq(menu->obj.dim.y + 32, prev1->obj.dim.y);
-	ut_asserteq(false, prev1->obj.flags & SCENEOF_HIDE);
+	ut_asserteq(true, prev1->obj.flags & SCENEOF_HIDE);
 
 	expo_destroy(exp);
 
Signature · 1 line
2.41.0.rc0.172.g3f132b7071-goog
#32 lore raw

PATCH 31/40 expo: Support drawing of popup menus

In reply to Simon Glass

At present only a single menu is supported. All items are shown and a pointer object points to the current item.

Add support for multiple menus, one of which is highlighted, indicated by the highlight_id property in the scene.

The highlighted menu item has a SCENEOF_POINT flag, indicating that it is currently pointed to.

The popup menu is normally closed, in which case it shows only the current menu item. When it is opened, it shows all items, allowing the user to select one.

Rather than requiring the menu item to have a description, require it to have a label. Use the label (only) for the popup menu.

With this, most of the drawing and layout logic is complete.

---

 boot/scene_menu.c | 58 ++++++++++++++++++++++++++++++-----------------
 include/expo.h    |  9 ++++++++
 2 files changed, 46 insertions(+), 21 deletions(-)
boot/scene_menu.c +37 -21
index 154be7f0127f..f2832b4ddfd7 100644
@@ -56,6 +56,7 @@ static struct scene_menitem *scene_menuitem_find(struct scene_obj_menu *menu,
 static int update_pointers(struct scene_obj_menu *menu, uint id, bool point)
 {
 	struct scene *scn = menu->obj.scene;
+	const bool stack = scn->expo->popup;
 	const struct scene_menitem *item;
 	int ret;
 
@@ -75,6 +76,12 @@ static int update_pointers(struct scene_obj_menu *menu, uint id, bool point)
 			return log_msg_ret("ptr", ret);
 	}
 
+	if (stack) {
+		point &= scn->highlight_id == menu->obj.id;
+		scene_obj_flag_clrset(scn, item->label_id, SCENEOF_POINT,
+				      point ? SCENEOF_POINT : 0);
+	}
+
 	return 0;
 }
 
@@ -172,11 +179,15 @@ int scene_menu_calc_dims(struct scene_obj_menu *menu)
 
 int scene_menu_arrange(struct scene *scn, struct scene_obj_menu *menu)
 {
+	const bool open = menu->obj.flags & SCENEOF_OPEN;
+	struct expo *exp = scn->expo;
+	const bool stack = exp->popup;
 	struct scene_menitem *item;
 	uint sel_id;
-	int y, cur_y;
+	int x, y;
 	int ret;
 
+	x = menu->obj.dim.x;
 	y = menu->obj.dim.y;
 	if (menu->title_id) {
 		ret = scene_obj_set_pos(scn, menu->title_id, menu->obj.dim.x, y);
@@ -187,7 +198,10 @@ int scene_menu_arrange(struct scene *scn, struct scene_obj_menu *menu)
 		if (ret < 0)
 			return log_msg_ret("hei", ret);
 
-		y += ret * 2;
+		if (stack)
+			x += 200;
+		else
+			y += ret * 2;
 	}
 
 	/*
@@ -198,9 +212,10 @@ int scene_menu_arrange(struct scene *scn, struct scene_obj_menu *menu)
 	 */
 	sel_id = menu->cur_item_id;
 	list_for_each_entry(item, &menu->item_head, sibling) {
+		bool selected;
 		int height;
 
-		ret = scene_obj_get_hw(scn, item->desc_id, NULL);
+		ret = scene_obj_get_hw(scn, item->label_id, NULL);
 		if (ret < 0)
 			return log_msg_ret("get", ret);
 		height = ret;
@@ -212,29 +227,29 @@ int scene_menu_arrange(struct scene *scn, struct scene_obj_menu *menu)
 		if (!sel_id)
 			sel_id = item->id;
 
+		selected = sel_id == item->id;
+
 		/*
 		 * Put the label on the left, then leave a space for the
 		 * pointer, then the key and the description
 		 */
-		if (item->label_id) {
-			ret = scene_obj_set_pos(scn, item->label_id, menu->obj.dim.x,
-						y);
-			if (ret < 0)
-				return log_msg_ret("nam", ret);
-		}
-
-		ret = scene_obj_set_pos(scn, item->key_id, menu->obj.dim.x + 230,
-					y);
+		ret = scene_obj_set_pos(scn, item->label_id, x, y);
 		if (ret < 0)
-			return log_msg_ret("key", ret);
+			return log_msg_ret("nam", ret);
+		scene_obj_set_hide(scn, item->label_id,
+				   stack && !open && !selected);
 
-		ret = scene_obj_set_pos(scn, item->desc_id, menu->obj.dim.x + 280,
-					y);
-		if (ret < 0)
-			return log_msg_ret("des", ret);
+		if (item->key_id) {
+			ret = scene_obj_set_pos(scn, item->key_id, x + 230, y);
+			if (ret < 0)
+				return log_msg_ret("key", ret);
+		}
 
-		if (menu->cur_item_id == item->id)
-			cur_y = y;
+		if (item->desc_id) {
+			ret = scene_obj_set_pos(scn, item->desc_id, x + 280, y);
+			if (ret < 0)
+				return log_msg_ret("des", ret);
+		}
 
 		if (item->preview_id) {
 			bool hide;
@@ -253,7 +268,8 @@ int scene_menu_arrange(struct scene *scn, struct scene_obj_menu *menu)
 				return log_msg_ret("hid", ret);
 		}
 
-		y += height;
+		if (!stack || open)
+			y += height;
 	}
 
 	if (sel_id)
@@ -380,7 +396,7 @@ int scene_menuitem(struct scene *scn, uint menu_id, const char *name, uint id,
 		return log_msg_ret("find", -ENOENT);
 
 	/* Check that the text ID is valid */
-	if (!scene_obj_find(scn, desc_id, SCENEOBJT_TEXT))
+	if (!scene_obj_find(scn, label_id, SCENEOBJT_TEXT))
 		return log_msg_ret("txt", -EINVAL);
 
 	item = calloc(1, sizeof(struct scene_obj_menu));
include/expo.h +9 -0
index ea8f38913d8e..0c55d60f71a7 100644
@@ -70,6 +70,7 @@ struct expo_theme {
  * @action: Action selected by user. At present only one is supported, with the
  * type set to EXPOACT_NONE if there is no action
  * @text_mode: true to use text mode for the menu (no vidconsole)
+ * @popup: true to use popup menus, instead of showing all items
  * @priv: Private data for the controller
  * @theme: Information about fonts styles, etc.
  * @scene_head: List of scenes
@@ -83,6 +84,7 @@ struct expo {
 	uint next_id;
 	struct expo_action action;
 	bool text_mode;
+	bool popup;
 	void *priv;
 	struct expo_theme theme;
 	struct list_head scene_head;
@@ -111,6 +113,7 @@ struct expo_string {
  * @name: Name of the scene (allocated)
  * @id: ID number of the scene
  * @title_id: String ID of title of the scene (allocated)
+ * @highlight_id: ID of highlighted object, if any
  * @sibling: Node to link this scene to its siblings
  * @obj_head: List of objects in the scene
  */
@@ -119,6 +122,7 @@ struct scene {
 	char *name;
 	uint id;
 	uint title_id;
+	uint highlight_id;
 	struct list_head sibling;
 	struct list_head obj_head;
 };
@@ -157,9 +161,14 @@ struct scene_dim {
  * enum scene_obj_flags_t - flags for objects
  *
  * @SCENEOF_HIDE: object should be hidden
+ * @SCENEOF_POINT: object should be highlighted
+ * @SCENEOF_OPEN: object should be opened (e.g. menu is opened so that an option
+ * can be selected)
  */
 enum scene_obj_flags_t {
 	SCENEOF_HIDE	= 1 << 0,
+	SCENEOF_POINT	= 1 << 1,
+	SCENEOF_OPEN	= 1 << 2,
 };
 
 /**
Signature · 1 line
2.41.0.rc0.172.g3f132b7071-goog
#33 lore raw

PATCH 32/40 expo: Rename EXPOACT_POINT to EXPOACT_POINT_ITEM

In reply to Simon Glass

At present we only support a single menu, so all that can be pointed to is the current menu item. Rename this action so that we can also add an action for pointing to an object. This will allow cycling through the objects in a scene.

---

 boot/scene_menu.c | 4 ++--
 include/expo.h    | 6 +++---
 test/boot/expo.c  | 4 ++--
 3 files changed, 7 insertions(+), 7 deletions(-)
boot/scene_menu.c +2 -2
index f2832b4ddfd7..892099557a99 100644
@@ -347,7 +347,7 @@ int scene_menu_send_key(struct scene *scn, struct scene_obj_menu *menu, int key,
 					     struct scene_menitem, sibling)) {
 			item = list_entry(item->sibling.prev,
 					  struct scene_menitem, sibling);
-			event->type = EXPOACT_POINT;
+			event->type = EXPOACT_POINT_ITEM;
 			event->select.id = item->id;
 			log_debug("up to item %d\n", event->select.id);
 		}
@@ -356,7 +356,7 @@ int scene_menu_send_key(struct scene *scn, struct scene_obj_menu *menu, int key,
 		if (!list_is_last(&item->sibling, &menu->item_head)) {
 			item = list_entry(item->sibling.next,
 					  struct scene_menitem, sibling);
-			event->type = EXPOACT_POINT;
+			event->type = EXPOACT_POINT_ITEM;
 			event->select.id = item->id;
 			log_debug("down to item %d\n", event->select.id);
 		}
include/expo.h +3 -3
index 0c55d60f71a7..0f4388897883 100644
@@ -16,13 +16,13 @@ struct udevice;
  * enum expoact_type - types of actions reported by the expo
  *
  * @EXPOACT_NONE: no action
- * @EXPOACT_POINT: menu item was highlighted (@id indicates which)
+ * @EXPOACT_POINT_ITEM: menu item was highlighted (@id indicates which)
  * @EXPOACT_SELECT: menu item was selected (@id indicates which)
  * @EXPOACT_QUIT: request to exit the menu
  */
 enum expoact_type {
 	EXPOACT_NONE,
-	EXPOACT_POINT,
+	EXPOACT_POINT_ITEM,
 	EXPOACT_SELECT,
 	EXPOACT_QUIT,
 };
@@ -31,7 +31,7 @@ enum expoact_type {
  * struct expo_action - an action report by the expo
  *
  * @type: Action type (EXPOACT_NONE if there is no action)
- * @select: Used for EXPOACT_POINT and EXPOACT_SELECT
+ * @select: Used for EXPOACT_POINT_ITEM and EXPOACT_SELECT
  * @id: ID number of the object affected.
  */
 struct expo_action {
test/boot/expo.c +2 -2
index 453316ece7c3..c34eaeedd66f 100644
@@ -530,7 +530,7 @@ static int expo_render_image(struct unit_test_state *uts)
 
 	ut_assertok(expo_action_get(exp, &act));
 
-	ut_asserteq(EXPOACT_POINT, act.type);
+	ut_asserteq(EXPOACT_POINT_ITEM, act.type);
 	ut_asserteq(ITEM2, act.select.id);
 	ut_assertok(expo_render(exp));
 
@@ -570,7 +570,7 @@ static int expo_render_image(struct unit_test_state *uts)
 
 	ut_assertok(expo_action_get(exp, &act));
 
-	ut_asserteq(EXPOACT_POINT, act.type);
+	ut_asserteq(EXPOACT_POINT_ITEM, act.type);
 	ut_asserteq(ITEM1, act.select.id);
 
 	ut_assertok(expo_render(exp));
Signature · 1 line
2.41.0.rc0.172.g3f132b7071-goog
#34 lore raw

PATCH 33/40 expo: Draw popup menus in both opened and closed states

In reply to Simon Glass

When a popup menu is closed it shows only the selected item. When it is open it shows a background and all items, with a highlight that can be moved between the items.

Add the drawing logic for this.

---

 boot/scene.c          | 66 +++++++++++++++++++++++++++++++++++++++++--
 boot/scene_internal.h |  7 +++++
 boot/scene_menu.c     | 29 +++++++++++++++++++
 include/expo.h        | 30 ++++++++++++++++++++
 4 files changed, 130 insertions(+), 2 deletions(-)
boot/scene.c +64 -2
index 4dbe12a2b740..fb199ef29538 100644
@@ -345,14 +345,44 @@ static int scene_obj_render(struct scene_obj *obj, bool text_mode)
 		}
 		if (ret && ret != -ENOSYS)
 			return log_msg_ret("font", ret);
-		vidconsole_set_cursor_pos(cons, x, y);
 		str = expo_get_str(exp, txt->str_id);
-		if (str)
+		if (str) {
+			struct video_priv *vid_priv;
+			struct vidconsole_colour old;
+			enum colour_idx fore, back;
+
+			if (CONFIG_IS_ENABLED(SYS_WHITE_ON_BLACK)) {
+				fore = VID_BLACK;
+				back = VID_WHITE;
+			} else {
+				fore = VID_LIGHT_GRAY;
+				back = VID_BLACK;
+			}
+
+			vid_priv = dev_get_uclass_priv(dev);
+			if (obj->flags & SCENEOF_POINT) {
+				vidconsole_push_colour(cons, fore, back, &old);
+				video_fill_part(dev, x, y,
+						x + obj->dim.w, y + obj->dim.h,
+						vid_priv->colour_bg);
+			}
+			vidconsole_set_cursor_pos(cons, x, y);
 			vidconsole_put_string(cons, str);
+			if (obj->flags & SCENEOF_POINT)
+				vidconsole_pop_colour(cons, &old);
+		}
 		break;
 	}
 	case SCENEOBJT_MENU: {
 		struct scene_obj_menu *menu = (struct scene_obj_menu *)obj;
+
+		if (exp->popup && (obj->flags & SCENEOF_OPEN)) {
+			if (!cons)
+				return -ENOTSUPP;
+
+			/* draw a background behind the menu items */
+			scene_menu_render(menu);
+		}
 		/*
 		 * With a vidconsole, the text and item pointer are rendered as
 		 * normal objects so we don't need to do anything here. The menu
@@ -494,3 +524,35 @@ int scene_apply_theme(struct scene *scn, struct expo_theme *theme)
 
 	return 0;
 }
+
+void scene_set_highlight_id(struct scene *scn, uint id)
+{
+	scn->highlight_id = id;
+}
+
+void scene_highlight_first(struct scene *scn)
+{
+	struct scene_obj *obj;
+
+	list_for_each_entry(obj, &scn->obj_head, sibling) {
+		switch (obj->type) {
+		case SCENEOBJT_MENU:
+			scene_set_highlight_id(scn, obj->id);
+			return;
+		default:
+			break;
+		}
+	}
+}
+
+int scene_set_open(struct scene *scn, uint id, bool open)
+{
+	int ret;
+
+	ret = scene_obj_flag_clrset(scn, id, SCENEOF_OPEN,
+				    open ? SCENEOF_OPEN : 0);
+	if (ret)
+		return log_msg_ret("flg", ret);
+
+	return 0;
+}
boot/scene_internal.h +7 -0
index 3387a90761ab..2544c961dab4 100644
@@ -153,6 +153,13 @@ int scene_render(struct scene *scn);
  */
 int scene_send_key(struct scene *scn, int key, struct expo_action *event);
 
+/**
+ * scene_menu_render() - Render the background behind a menu
+ *
+ * @menu: Menu to render
+ */
+void scene_menu_render(struct scene_obj_menu *menu);
+
 /**
  * scene_menu_calc_dims() - Calculate the dimensions of a menu
  *
boot/scene_menu.c +29 -0
index 892099557a99..20ded91fb3d6 100644
@@ -515,3 +515,32 @@ int scene_menu_display(struct scene_obj_menu *menu)
 
 	return -ENOTSUPP;
 }
+
+void scene_menu_render(struct scene_obj_menu *menu)
+{
+	struct expo *exp = menu->obj.scene->expo;
+	const struct expo_theme *theme = &exp->theme;
+	struct vidconsole_bbox bbox, label_bbox;
+	struct udevice *dev = exp->display;
+	struct video_priv *vid_priv;
+	struct udevice *cons = exp->cons;
+	struct vidconsole_colour old;
+	enum colour_idx fore, back;
+
+	if (CONFIG_IS_ENABLED(SYS_WHITE_ON_BLACK)) {
+		fore = VID_BLACK;
+		back = VID_WHITE;
+	} else {
+		fore = VID_LIGHT_GRAY;
+		back = VID_BLACK;
+	}
+
+	scene_menu_calc_bbox(menu, &bbox, &label_bbox);
+	vidconsole_push_colour(cons, fore, back, &old);
+	vid_priv = dev_get_uclass_priv(dev);
+	video_fill_part(dev, label_bbox.x0 - theme->menu_inset,
+			label_bbox.y0 - theme->menu_inset,
+			label_bbox.x1, label_bbox.y1 + theme->menu_inset,
+			vid_priv->colour_fg);
+	vidconsole_pop_colour(cons, &old);
+}
include/expo.h +30 -0
index 0f4388897883..0699cdb4c19c 100644
@@ -412,6 +412,36 @@ int scene_new(struct expo *exp, const char *name, uint id, struct scene **scnp);
  */
 struct scene *expo_lookup_scene_id(struct expo *exp, uint scene_id);
 
+/**
+ * scene_highlight_first() - Highlight the first item in a scene
+ *
+ * This highlights the first item, so that the user can see that it is pointed
+ * to
+ *
+ * @scn: Scene to update
+ */
+void scene_highlight_first(struct scene *scn);
+
+/**
+ * scene_set_highlight_id() - Set the object which is highlighted
+ *
+ * Sets a new object to highlight in the scene
+ *
+ * @scn: Scene to update
+ * @id: ID of object to highlight
+ */
+void scene_set_highlight_id(struct scene *scn, uint id);
+
+/**
+ * scene_set_open() - Set whether an item is open or not
+ *
+ * @scn: Scene to update
+ * @id: ID of object to update
+ * @open: true to open the object, false to close it
+ * Returns: 0 if OK, -ENOENT if @id is invalid
+ */
+int scene_set_open(struct scene *scn, uint id, bool open);
+
 /**
  * scene_title_set() - set the scene title
  *
Signature · 1 line
2.41.0.rc0.172.g3f132b7071-goog
#35 lore raw

PATCH 34/40 expo: Draw the current opened menu on top

In reply to Simon Glass

When a menu is opened, it must be displayed over all other objects in the scene, so that all its items are visible.

Handle this by drawing the menu object a second time, after all other objects have been drawn. Draw all of the objects which are dependent on the menu object.

---

 boot/expo.c           | 12 ++++++++++++
 boot/scene.c          | 31 +++++++++++++++++++++++++++++++
 boot/scene_internal.h | 20 ++++++++++++++++++++
 boot/scene_menu.c     | 17 +++++++++++++++++
 4 files changed, 80 insertions(+)
boot/expo.c +12 -0
index d5e935966bfd..e99555163ca4 100644
@@ -172,6 +172,18 @@ int expo_set_scene_id(struct expo *exp, uint scene_id)
 	return 0;
 }
 
+int expo_first_scene_id(struct expo *exp)
+{
+	struct scene *scn;
+
+	if (list_empty(&exp->scene_head))
+		return -ENOENT;
+
+	scn = list_first_entry(&exp->scene_head, struct scene, sibling);
+
+	return scn->id;
+}
+
 int expo_render(struct expo *exp)
 {
 	struct udevice *dev = exp->display;
boot/scene.c +31 -0
index fb199ef29538..bc213bc08b87 100644
@@ -421,6 +421,30 @@ int scene_arrange(struct scene *scn)
 	return 0;
 }
 
+int scene_render_deps(struct scene *scn, uint id)
+{
+	struct scene_obj *obj;
+	int ret;
+
+	if (!id)
+		return 0;
+	obj = scene_obj_find(scn, id, SCENEOBJT_NONE);
+	if (!obj)
+		return log_msg_ret("obj", -ENOENT);
+
+	if (!(obj->flags & SCENEOF_HIDE)) {
+		ret = scene_obj_render(obj, false);
+		if (ret && ret != -ENOTSUPP)
+			return log_msg_ret("ren", ret);
+
+		if (obj->type == SCENEOBJT_MENU)
+			scene_menu_render_deps(scn,
+					       (struct scene_obj_menu *)obj);
+	}
+
+	return 0;
+}
+
 int scene_render(struct scene *scn)
 {
 	struct expo *exp = scn->expo;
@@ -435,6 +459,13 @@ int scene_render(struct scene *scn)
 		}
 	}
 
+	/* render any highlighted object on top of the others */
+	if (scn->highlight_id && !exp->text_mode) {
+		ret = scene_render_deps(scn, scn->highlight_id);
+		if (ret && ret != -ENOTSUPP)
+			return log_msg_ret("dep", ret);
+	}
+
 	return 0;
 }
 
boot/scene_internal.h +20 -0
index 2544c961dab4..dc98ecd02146 100644
@@ -160,6 +160,26 @@ int scene_send_key(struct scene *scn, int key, struct expo_action *event);
  */
 void scene_menu_render(struct scene_obj_menu *menu);
 
+/**
+ * scene_render_deps() - Render an object and its dependencies
+ *
+ * @scn: Scene to render
+ * @id: Object ID to render (or 0 for none)
+ * Returns: 0 if OK, -ve on error
+ */
+int scene_render_deps(struct scene *scn, uint id);
+
+/**
+ * scene_menu_render_deps() - Render a menu and its dependencies
+ *
+ * Renders the menu and all of its attached objects
+ *
+ * @scn: Scene to render
+ * @menu: Menu render
+ * Returns: 0 if OK, -ve on error
+ */
+int scene_menu_render_deps(struct scene *scn, struct scene_obj_menu *menu);
+
 /**
  * scene_menu_calc_dims() - Calculate the dimensions of a menu
  *
boot/scene_menu.c +17 -0
index 20ded91fb3d6..6aab27611d71 100644
@@ -544,3 +544,20 @@ void scene_menu_render(struct scene_obj_menu *menu)
 			vid_priv->colour_fg);
 	vidconsole_pop_colour(cons, &old);
 }
+
+int scene_menu_render_deps(struct scene *scn, struct scene_obj_menu *menu)
+{
+	struct scene_menitem *item;
+
+	scene_render_deps(scn, menu->title_id);
+	scene_render_deps(scn, menu->cur_item_id);
+	scene_render_deps(scn, menu->pointer_id);
+
+	list_for_each_entry(item, &menu->item_head, sibling) {
+		scene_render_deps(scn, item->key_id);
+		scene_render_deps(scn, item->label_id);
+		scene_render_deps(scn, item->desc_id);
+	}
+
+	return 0;
+}
Signature · 1 line
2.41.0.rc0.172.g3f132b7071-goog
#36 lore raw

PATCH 35/40 expo: Implement the keypress logic for popup menus

In reply to Simon Glass

In 'popup' mode, the expo allows moving around the objects in a scene. When 'enter' is pressed on a menu, it opens and the user can move around the items in the menu.

Implement this using keypress handles and actions.

---

 boot/scene.c         | 80 ++++++++++++++++++++++++++++++++++++++++++++
 boot/scene_menu.c    | 10 ++++--
 doc/develop/expo.rst |  3 +-
 include/expo.h       |  7 ++++
 4 files changed, 96 insertions(+), 4 deletions(-)
boot/scene.c +80 -0
index bc213bc08b87..ea94b90584ee 100644
@@ -13,6 +13,7 @@
 #include <expo.h>
 #include <malloc.h>
 #include <mapmem.h>
+#include <menu.h>
 #include <video.h>
 #include <video_console.h>
 #include <linux/input.h>
@@ -469,11 +470,90 @@ int scene_render(struct scene *scn)
 	return 0;
 }
 
+/**
+ * send_key_obj() - Handle a keypress for moving between objects
+ *
+ * @scn: Scene to receive the key
+ * @key: Key to send (KEYCODE_UP)
+ * @event: Returns resulting event from this keypress
+ * Returns: 0 if OK, -ve on error
+ */
+static void send_key_obj(struct scene *scn, struct scene_obj *obj, int key,
+			 struct expo_action *event)
+{
+	switch (key) {
+	case BKEY_UP:
+		while (obj != list_first_entry(&scn->obj_head, struct scene_obj,
+					       sibling)) {
+			obj = list_entry(obj->sibling.prev,
+					 struct scene_obj, sibling);
+			if (obj->type == SCENEOBJT_MENU) {
+				event->type = EXPOACT_POINT_OBJ;
+				event->select.id = obj->id;
+				log_debug("up to obj %d\n", event->select.id);
+				break;
+			}
+		}
+		break;
+	case BKEY_DOWN:
+		while (!list_is_last(&obj->sibling, &scn->obj_head)) {
+			obj = list_entry(obj->sibling.next, struct scene_obj,
+					 sibling);
+			if (obj->type == SCENEOBJT_MENU) {
+				event->type = EXPOACT_POINT_OBJ;
+				event->select.id = obj->id;
+				log_debug("down to obj %d\n", event->select.id);
+				break;
+			}
+		}
+		break;
+	case BKEY_SELECT:
+		if (obj->type == SCENEOBJT_MENU) {
+			event->type = EXPOACT_OPEN;
+			event->select.id = obj->id;
+			log_debug("open obj %d\n", event->select.id);
+		}
+		break;
+	case BKEY_QUIT:
+		event->type = EXPOACT_QUIT;
+		log_debug("obj quit\n");
+		break;
+	}
+}
+
 int scene_send_key(struct scene *scn, int key, struct expo_action *event)
 {
+	struct scene_obj_menu *menu;
 	struct scene_obj *obj;
 	int ret;
 
+	event->type = EXPOACT_NONE;
+
+	/*
+	 * In 'popup' mode, arrow keys move betwen objects, unless a menu is
+	 * opened
+	 */
+	if (scn->expo->popup) {
+		obj = NULL;
+		if (scn->highlight_id) {
+			obj = scene_obj_find(scn, scn->highlight_id,
+					     SCENEOBJT_NONE);
+		}
+		if (!obj)
+			return 0;
+
+		if (!(obj->flags & SCENEOF_OPEN)) {
+			send_key_obj(scn, obj, key, event);
+			return 0;
+		}
+
+		menu = (struct scene_obj_menu *)obj,
+		ret = scene_menu_send_key(scn, menu, key, event);
+		if (ret)
+			return log_msg_ret("key", ret);
+		return 0;
+	}
+
 	list_for_each_entry(obj, &scn->obj_head, sibling) {
 		if (obj->type == SCENEOBJT_MENU) {
 			struct scene_obj_menu *menu;
boot/scene_menu.c +8 -2
index 6aab27611d71..dfe5692d6ce7 100644
@@ -323,6 +323,7 @@ static struct scene_menitem *scene_menu_find_key(struct scene *scn,
 int scene_menu_send_key(struct scene *scn, struct scene_obj_menu *menu, int key,
 			struct expo_action *event)
 {
+	const bool open = menu->obj.flags & SCENEOF_OPEN;
 	struct scene_menitem *item, *cur, *key_item;
 
 	cur = NULL;
@@ -367,8 +368,13 @@ int scene_menu_send_key(struct scene *scn, struct scene_obj_menu *menu, int key,
 		log_debug("select item %d\n", event->select.id);
 		break;
 	case BKEY_QUIT:
-		event->type = EXPOACT_QUIT;
-		log_debug("quit\n");
+		if (scn->expo->popup && open) {
+			event->type = EXPOACT_CLOSE;
+			event->select.id = menu->obj.id;
+		} else {
+			event->type = EXPOACT_QUIT;
+			log_debug("menu quit\n");
+		}
 		break;
 	case '0'...'9':
 		key_item = scene_menu_find_key(scn, menu, key);
doc/develop/expo.rst +1 -2
index 2f4882899b6d..80e435c5e65e 100644
@@ -178,8 +178,7 @@ Some ideas for future work:
 - Image formats other than BMP
 - Use of ANSI sequences to control a serial terminal
 - Colour selection
-- Better support for handling lots of settings, e.g. with multiple menus and
-  radio/option widgets
+- Better support for handling lots of settings, e.g. with radio/option widgets
 - Mouse support
 - Integrate Nuklear, NxWidgets or some other library for a richer UI
 - Optimise rendering by only updating the display with changes since last render
include/expo.h +7 -0
index 0699cdb4c19c..f7febe1c9ae7 100644
@@ -16,14 +16,21 @@ struct udevice;
  * enum expoact_type - types of actions reported by the expo
  *
  * @EXPOACT_NONE: no action
+ * @EXPOACT_POINT_OBJ: object was highlighted (@id indicates which)
  * @EXPOACT_POINT_ITEM: menu item was highlighted (@id indicates which)
  * @EXPOACT_SELECT: menu item was selected (@id indicates which)
+ * @EXPOACT_OPEN: menu was opened, so an item can be selected (@id indicates
+ * which menu object)
+ * @EXPOACT_CLOSE: menu was closed (@id indicates which menu object)
  * @EXPOACT_QUIT: request to exit the menu
  */
 enum expoact_type {
 	EXPOACT_NONE,
+	EXPOACT_POINT_OBJ,
 	EXPOACT_POINT_ITEM,
 	EXPOACT_SELECT,
+	EXPOACT_OPEN,
+	EXPOACT_CLOSE,
 	EXPOACT_QUIT,
 };
 
Signature · 1 line
2.41.0.rc0.172.g3f132b7071-goog
#37 lore raw

PATCH 36/40 expo: Add spacing around menus and items

In reply to Simon Glass

It looks better if menus have a bit of an inset, rather than be drawn hard up against the background. Also, menu items look better if they have a bit of spacing between them.

Add theme options for these and implement the required changes.

---

 arch/sandbox/dts/test.dts |  2 ++
 boot/expo.c               |  2 ++
 boot/scene.c              |  6 ++++--
 boot/scene_menu.c         | 37 ++++++++++++++++++++++++-------------
 doc/develop/expo.rst      |  6 ++++++
 5 files changed, 38 insertions(+), 15 deletions(-)
arch/sandbox/dts/test.dts +2 -0
index ff9f9222e6f9..38d5739421f6 100644
@@ -96,6 +96,8 @@
 
 		theme {
 			font-size = <30>;
+			menu-inset = <3>;
+			menuitem-gap-y = <1>;
 		};
 
 		/*
boot/expo.c +2 -0
index e99555163ca4..8c6fbc0e30bc 100644
@@ -254,6 +254,8 @@ int expo_apply_theme(struct expo *exp, ofnode node)
 
 	memset(theme, '\0', sizeof(struct expo_theme));
 	ofnode_read_u32(node, "font-size", &theme->font_size);
+	ofnode_read_u32(node, "menu-inset", &theme->menu_inset);
+	ofnode_read_u32(node, "menuitem-gap-y", &theme->menuitem_gap_y);
 
 	list_for_each_entry(scn, &exp->scene_head, sibling) {
 		ret = scene_apply_theme(scn, theme);
boot/scene.c +4 -2
index ea94b90584ee..6fbc1fc578c2 100644
@@ -309,6 +309,7 @@ static int scene_obj_render(struct scene_obj *obj, bool text_mode)
 {
 	struct scene *scn = obj->scene;
 	struct expo *exp = scn->expo;
+	const struct expo_theme *theme = &exp->theme;
 	struct udevice *dev = exp->display;
 	struct udevice *cons = text_mode ? NULL : exp->cons;
 	int x, y, ret;
@@ -363,8 +364,9 @@ static int scene_obj_render(struct scene_obj *obj, bool text_mode)
 			vid_priv = dev_get_uclass_priv(dev);
 			if (obj->flags & SCENEOF_POINT) {
 				vidconsole_push_colour(cons, fore, back, &old);
-				video_fill_part(dev, x, y,
-						x + obj->dim.w, y + obj->dim.h,
+				video_fill_part(dev, x - theme->menu_inset, y,
+						x + obj->dim.w,
+						y + obj->dim.h,
 						vid_priv->colour_bg);
 			}
 			vidconsole_set_cursor_pos(cons, x, y);
boot/scene_menu.c +24 -13
index dfe5692d6ce7..8a355f838cc8 100644
@@ -98,7 +98,7 @@ static void menu_point_to_item(struct scene_obj_menu *menu, uint item_id)
 	update_pointers(menu, item_id, true);
 }
 
-static int scene_bbox_union(struct scene *scn, uint id,
+static int scene_bbox_union(struct scene *scn, uint id, int inset,
 			    struct vidconsole_bbox *bbox)
 {
 	struct scene_obj *obj;
@@ -109,14 +109,14 @@ static int scene_bbox_union(struct scene *scn, uint id,
 	if (!obj)
 		return log_msg_ret("obj", -ENOENT);
 	if (bbox->valid) {
-		bbox->x0 = min(bbox->x0, obj->dim.x);
+		bbox->x0 = min(bbox->x0, obj->dim.x - inset);
 		bbox->y0 = min(bbox->y0, obj->dim.y);
-		bbox->x1 = max(bbox->x1, obj->dim.x + obj->dim.w);
+		bbox->x1 = max(bbox->x1, obj->dim.x + obj->dim.w + inset);
 		bbox->y1 = max(bbox->y1, obj->dim.y + obj->dim.h);
 	} else {
-		bbox->x0 = obj->dim.x;
+		bbox->x0 = obj->dim.x - inset;
 		bbox->y0 = obj->dim.y;
-		bbox->x1 = obj->dim.x + obj->dim.w;
+		bbox->x1 = obj->dim.x + obj->dim.w + inset;
 		bbox->y1 = obj->dim.y + obj->dim.h;
 		bbox->valid = true;
 	}
@@ -135,22 +135,31 @@ static void scene_menu_calc_bbox(struct scene_obj_menu *menu,
 				 struct vidconsole_bbox *bbox,
 				 struct vidconsole_bbox *label_bbox)
 {
+	const struct expo_theme *theme = &menu->obj.scene->expo->theme;
 	const struct scene_menitem *item;
 
 	bbox->valid = false;
-	scene_bbox_union(menu->obj.scene, menu->title_id, bbox);
+	scene_bbox_union(menu->obj.scene, menu->title_id, 0, bbox);
 
 	label_bbox->valid = false;
 
 	list_for_each_entry(item, &menu->item_head, sibling) {
-		scene_bbox_union(menu->obj.scene, item->label_id, bbox);
-		scene_bbox_union(menu->obj.scene, item->key_id, bbox);
-		scene_bbox_union(menu->obj.scene, item->desc_id, bbox);
-		scene_bbox_union(menu->obj.scene, item->preview_id, bbox);
+		scene_bbox_union(menu->obj.scene, item->label_id,
+				 theme->menu_inset, bbox);
+		scene_bbox_union(menu->obj.scene, item->key_id, 0, bbox);
+		scene_bbox_union(menu->obj.scene, item->desc_id, 0, bbox);
+		scene_bbox_union(menu->obj.scene, item->preview_id, 0, bbox);
 
 		/* Get the bounding box of all labels */
-		scene_bbox_union(menu->obj.scene, item->label_id, label_bbox);
+		scene_bbox_union(menu->obj.scene, item->label_id,
+				 theme->menu_inset, label_bbox);
 	}
+
+	/*
+	 * subtract the final menuitem's gap to keep the insert the same top
+	 * and bottom
+	 */
+	label_bbox->y1 -= theme->menuitem_gap_y;
 }
 
 int scene_menu_calc_dims(struct scene_obj_menu *menu)
@@ -182,6 +191,7 @@ int scene_menu_arrange(struct scene *scn, struct scene_obj_menu *menu)
 	const bool open = menu->obj.flags & SCENEOF_OPEN;
 	struct expo *exp = scn->expo;
 	const bool stack = exp->popup;
+	const struct expo_theme *theme = &exp->theme;
 	struct scene_menitem *item;
 	uint sel_id;
 	int x, y;
@@ -233,7 +243,8 @@ int scene_menu_arrange(struct scene *scn, struct scene_obj_menu *menu)
 		 * Put the label on the left, then leave a space for the
 		 * pointer, then the key and the description
 		 */
-		ret = scene_obj_set_pos(scn, item->label_id, x, y);
+		ret = scene_obj_set_pos(scn, item->label_id,
+					x + theme->menu_inset, y);
 		if (ret < 0)
 			return log_msg_ret("nam", ret);
 		scene_obj_set_hide(scn, item->label_id,
@@ -269,7 +280,7 @@ int scene_menu_arrange(struct scene *scn, struct scene_obj_menu *menu)
 		}
 
 		if (!stack || open)
-			y += height;
+			y += height + theme->menuitem_gap_y;
 	}
 
 	if (sel_id)
doc/develop/expo.rst +6 -0
index 80e435c5e65e..bd593dc2b3f5 100644
@@ -162,6 +162,12 @@ properties:
 font-size
     Font size to use for all text (type: u32)
 
+menu-inset
+    Number of pixels to inset the menu on the sides and top (type: u32)
+
+menuitem-gap-y
+    Number of pixels between menu items
+
 
 API documentation
 -----------------
Signature · 1 line
2.41.0.rc0.172.g3f132b7071-goog
#38 lore raw

PATCH 37/40 expo: Support building an expo from a description file

In reply to Simon Glass

The only way to create an expo at present is by calling the functions to create each object. It is useful to have more data-driven approach, where the objects can be specified in a suitable file format and created from that. This makes testing easier as well.

Add support for describing an expo in a devicetree node. This allows more complex tests to be set up, as well as providing an easier format for users. It also provides a better basis for the upcoming configuration editor.

---

 arch/sandbox/dts/cedit.dtsi |  64 ++++++
 arch/sandbox/dts/test.dts   |   5 +
 boot/Makefile               |   2 +-
 boot/expo.c                 |   1 +
 boot/expo_build.c           | 400 ++++++++++++++++++++++++++++++++++++
 doc/develop/expo.rst        | 282 ++++++++++++++++++++++++-
 include/expo.h              |  14 ++
 include/test/cedit-test.h   |  29 +++
 test/boot/expo.c            |  80 ++++++++
 9 files changed, 870 insertions(+), 7 deletions(-)
 create mode 100644 arch/sandbox/dts/cedit.dtsi
 create mode 100644 boot/expo_build.c
 create mode 100644 include/test/cedit-test.h
arch/sandbox/dts/cedit.dtsi new file +64 -0
new file mode 100644
index 000000000000..a9eb4c2d594a
@@ -0,0 +1,64 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Expo definition for the configuration editor
+ *
+ * This used for testing building an expo from a data file. This devicetree
+ * provides a description of the objects to be created.
+ */
+
+#include <test/cedit-test.h>
+
+&cedit {
+	dynamic-start = <ID_DYNAMIC_START>;
+
+	scenes {
+		main {
+			id = <ID_SCENE1>;
+
+			/* value refers to the matching id in /strings */
+			title-id = <ID_SCENE1_TITLE>;
+
+			/* simple string is used as it is */
+			prompt = "UP and DOWN to choose, ENTER to select";
+
+			/* defines a menu within the scene */
+			cpu-speed {
+				type = "menu";
+				id = <ID_CPU_SPEED>;
+
+				/*
+				 * has both string and ID. The string is ignored
+				 * if the ID is present and points to a string
+				 */
+				title = "CPU speed";
+				title-id = <ID_CPU_SPEED_TITLE>;
+
+				/* menu items as simple strings */
+				item-label = "2 GHz", "2.5 GHz", "3 GHz";
+
+				/* IDs for the menu items */
+				item-id = <ID_CPU_SPEED_1 ID_CPU_SPEED_2
+					ID_CPU_SPEED_3>;
+			};
+
+			power-loss {
+				type = "menu";
+				id = <ID_POWER_LOSS>;
+
+				title = "AC Power";
+				item-label = "Always Off", "Always On",
+					"Memory";
+
+				item-id = <ID_AC_OFF ID_AC_ON ID_AC_MEMORY>;
+			};
+		};
+	};
+
+	strings {
+		title {
+			id = <ID_SCENE1_TITLE>;
+			value = "Test Configuration";
+			value-es = "configuración de prueba";
+		};
+	};
+};
arch/sandbox/dts/test.dts +5 -0
index 38d5739421f6..442222e4b995 100644
@@ -141,6 +141,9 @@
 		};
 	};
 
+	cedit: cedit {
+	};
+
 	fuzzing-engine {
 		compatible = "sandbox,fuzzing-engine";
 	};
@@ -1830,3 +1833,5 @@
 #ifdef CONFIG_SANDBOX_VPL
 #include "sandbox_vpl.dtsi"
 #endif
+
+#include "cedit.dtsi"
boot/Makefile +1 -1
index f94c31d922de..28c4e55ca656 100644
@@ -50,7 +50,7 @@ ifdef CONFIG_SPL_BUILD
 obj-$(CONFIG_SPL_LOAD_FIT) += common_fit.o
 endif
 
-obj-$(CONFIG_$(SPL_TPL_)EXPO) += expo.o scene.o scene_menu.o
+obj-$(CONFIG_$(SPL_TPL_)EXPO) += expo.o scene.o scene_menu.o expo_build.o
 
 obj-$(CONFIG_$(SPL_TPL_)BOOTMETH_VBE) += vbe.o
 obj-$(CONFIG_$(SPL_TPL_)BOOTMETH_VBE_REQUEST) += vbe_request.o
boot/expo.c +1 -0
index 8c6fbc0e30bc..db837f7b4924 100644
@@ -58,6 +58,7 @@ void expo_destroy(struct expo *exp)
 
 uint resolve_id(struct expo *exp, uint id)
 {
+	log_debug("resolve id %d\n", id);
 	if (!id)
 		id = exp->next_id++;
 	else if (id >= exp->next_id)
boot/expo_build.c new file +400 -0

400 lines not on this page · raw message

doc/develop/expo.rst +276 -6

309 lines not on this page · raw message

include/expo.h +14 -0
index f7febe1c9ae7..9fec4d0cd84e 100644
@@ -653,4 +653,18 @@ int expo_action_get(struct expo *exp, struct expo_action *act);
  */
 int expo_apply_theme(struct expo *exp, ofnode node);
 
+/**
+ * expo_build() - Build an expo from an FDT description
+ *
+ * Build a complete expo from a description in the provided devicetree.
+ *
+ * See doc/developer/expo.rst for a description of the format
+ *
+ * @root: Root node for expo description
+ * @expp: Returns the new expo
+ * Returns: 0 if OK, -ENOMEM if out of memory, -EINVAL if there is a format
+ * error, -ENOENT if there is a references to a non-existent string
+ */
+int expo_build(ofnode root, struct expo **expp);
+
 #endif /*__SCENE_H */
include/test/cedit-test.h new file +29 -0
new file mode 100644
index 000000000000..349df75b16d4
@@ -0,0 +1,29 @@
+/* SPDX-License-Identifier: GPL-2.0+ */
+/*
+ * Binding shared between cedit.dtsi and test/boot/expo.c
+ *
+ * Copyright 2023 Google LLC
+ * Written by Simon Glass <[email protected]>
+ */
+
+#ifndef __cedit_test_h
+#define __cedit_test_h
+
+#define ID_PROMPT		1
+#define ID_SCENE1		2
+#define ID_SCENE1_TITLE		3
+
+#define ID_CPU_SPEED		4
+#define ID_CPU_SPEED_TITLE	5
+#define ID_CPU_SPEED_1		6
+#define ID_CPU_SPEED_2		7
+#define ID_CPU_SPEED_3		8
+
+#define ID_POWER_LOSS		9
+#define ID_AC_OFF		10
+#define ID_AC_ON		11
+#define ID_AC_MEMORY		12
+
+#define ID_DYNAMIC_START	13
+
+#endif
test/boot/expo.c +80 -0

89 lines not on this page · raw message

Signature · 1 line
2.41.0.rc0.172.g3f132b7071-goog
#39 lore raw

PATCH 38/40 expo: Add a configuration editor

In reply to Simon Glass

Add a new 'cedit' command which allows editing configuration using an expo. The configuration items appear as menus on the display.

This is extremely basic, only supporting menus and not providing any way to load or save the configuration.

---

 boot/Kconfig              |  14 ++++
 boot/Makefile             |   1 +
 boot/cedit.c              | 163 ++++++++++++++++++++++++++++++++++++++
 boot/expo_build.c         |   3 +-
 boot/scene.c              |  12 +++
 boot/scene_internal.h     |   8 ++
 cmd/Kconfig               |   9 +++
 cmd/Makefile              |   1 +
 cmd/cedit.c               |  93 ++++++++++++++++++++++
 configs/sandbox_defconfig |   1 +
 doc/develop/expo.rst      |   8 +-
 doc/usage/cmd/cedit.rst   |  31 ++++++++
 doc/usage/index.rst       |   1 +
 include/expo.h            |  29 +++++++
 14 files changed, 370 insertions(+), 4 deletions(-)
 create mode 100644 boot/cedit.c
 create mode 100644 cmd/cedit.c
 create mode 100644 doc/usage/cmd/cedit.rst
boot/Kconfig +14 -0
index eea5ed6040ff..5385130a6e01 100644
@@ -1630,4 +1630,18 @@ config SAVE_PREV_BL_INITRAMFS_START_ADDR
 	  If no initramfs was provided by previous bootloader, no env variables
 	  will be created.
 
+menu "Configuration editor"
+
+config CEDIT
+	bool "Configuration editor"
+	depends on BOOTSTD
+	help
+	  Provides a way to deal with board configuration and present it to
+	  the user for adjustment.
+
+	  This is intended to provide both graphical and text-based user
+	  interfaces, but only graphical is support at present.
+
+endmenu		# Configuration editor
+
 endmenu		# Booting
boot/Makefile +1 -0
index 28c4e55ca656..f828f870a37b 100644
@@ -33,6 +33,7 @@ ifdef CONFIG_$(SPL_TPL_)BOOTSTD_FULL
 obj-$(CONFIG_CMD_BOOTEFI_BOOTMGR) += bootmeth_efi_mgr.o
 obj-$(CONFIG_$(SPL_TPL_)EXPO) += bootflow_menu.o
 obj-$(CONFIG_$(SPL_TPL_)BOOTSTD) += bootflow_menu.o
+obj-$(CONFIG_$(SPL_TPL_)CEDIT) += cedit.o
 endif
 
 obj-$(CONFIG_$(SPL_TPL_)OF_LIBFDT) += image-fdt.o
boot/cedit.c new file +163 -0

163 lines not on this page · raw message

boot/expo_build.c +2 -1
index 7e61ab06a8da..22f62eb54bc5 100644
@@ -376,7 +376,8 @@ int expo_build(ofnode root, struct expo **expp)
 	ret = read_strings(&info, root);
 	if (ret)
 		return log_msg_ret("str", ret);
-	list_strings(&info);
+	if (_DEBUG)
+		list_strings(&info);
 
 	ret = expo_new("name", NULL, &exp);
 	if (ret)
boot/scene.c +12 -0
index 6fbc1fc578c2..e52333371f9c 100644
@@ -92,6 +92,18 @@ void *scene_obj_find(struct scene *scn, uint id, enum scene_obj_t type)
 	return NULL;
 }
 
+void *scene_obj_find_by_name(struct scene *scn, const char *name)
+{
+	struct scene_obj *obj;
+
+	list_for_each_entry(obj, &scn->obj_head, sibling) {
+		if (!strcmp(name, obj->name))
+			return obj;
+	}
+
+	return NULL;
+}
+
 int scene_obj_add(struct scene *scn, const char *name, uint id,
 		  enum scene_obj_t type, uint size, struct scene_obj **objp)
 {
boot/scene_internal.h +8 -0
index dc98ecd02146..fb1ea5533b9a 100644
@@ -40,6 +40,14 @@ uint resolve_id(struct expo *exp, uint id);
  */
 void *scene_obj_find(struct scene *scn, uint id, enum scene_obj_t type);
 
+/**
+ * scene_obj_find_by_name() - Find an object in a scene by name
+ *
+ * @scn: Scene to search
+ * @name: Name to search for
+ */
+void *scene_obj_find_by_name(struct scene *scn, const char *name);
+
 /**
  * scene_obj_add() - Add a new object to a scene
  *
cmd/Kconfig +9 -0
index 365371fb511a..21b5550bfdf3 100644
@@ -427,6 +427,15 @@ config CMD_ABOOTIMG
 
 	  See doc/android/boot-image.rst for details.
 
+config CMD_CEDIT
+	bool "cedit - Configuration editor"
+	depends on CEDIT
+	default y
+	help
+	  Provides a command to allow editing of board configuration and
+	  providing a UI for the user to adjust settings. Subcommands allow
+	  loading and saving of configuration as well as showing an editor.
+
 config CMD_ELF
 	bool "bootelf, bootvx"
 	default y
cmd/Makefile +1 -0
index 6c37521b4e2b..9f8c0b058bea 100644
@@ -43,6 +43,7 @@ obj-$(CONFIG_CMD_BUTTON) += button.o
 obj-$(CONFIG_CMD_CAT) += cat.o
 obj-$(CONFIG_CMD_CACHE) += cache.o
 obj-$(CONFIG_CMD_CBFS) += cbfs.o
+obj-$(CONFIG_CMD_CEDIT) += cedit.o
 obj-$(CONFIG_CMD_CLK) += clk.o
 obj-$(CONFIG_CMD_CLS) += cls.o
 obj-$(CONFIG_CMD_CONFIG) += config.o
cmd/cedit.c new file +93 -0

93 lines not on this page · raw message

configs/sandbox_defconfig +1 -0
index 1ec44d5b33bb..4cef6c515396 100644
@@ -30,6 +30,7 @@ CONFIG_AUTOBOOT_STOP_STR_ENABLE=y
 CONFIG_AUTOBOOT_STOP_STR_CRYPT="$5$rounds=640000$HrpE65IkB8CM5nCL$BKT3QdF98Bo8fJpTr9tjZLZQyzqPASBY20xuK5Rent9"
 CONFIG_IMAGE_PRE_LOAD=y
 CONFIG_IMAGE_PRE_LOAD_SIG=y
+CONFIG_CEDIT=y
 CONFIG_CONSOLE_RECORD=y
 CONFIG_CONSOLE_RECORD_OUT_SIZE=0x6000
 CONFIG_PRE_CONSOLE_BUFFER=y
doc/develop/expo.rst +5 -3
index f5caadbfd98c..2ac4af232da4 100644
@@ -171,8 +171,6 @@ menu-inset
 menuitem-gap-y
     Number of pixels between menu items
 
-.. _expo_format:
-
 Pop-up mode
 -----------
 
@@ -202,6 +200,8 @@ just as its title and label, as with the `CPU Speed` and `AC Power` menus here::
      UP and DOWN to choose, ENTER to select
 
 
+.. _expo_format:
+
 Expo Format
 -----------
 
@@ -211,7 +211,8 @@ makes it easier and faster to create and edit the description. An expo builder
 is provided to convert this format into an expo structure.
 
 Layout of the expo scenes is handled automatically, based on a set of simple
-rules.
+rules. The :doc:`../usage/cmd/cedit` can be used to load a configuration
+and create an expo from it.
 
 Top-level node
 ~~~~~~~~~~~~~~
@@ -464,6 +465,7 @@ Some ideas for future work:
 - Support unicode
 - Support curses for proper serial-terminal menus
 - Add support for large menus which need to scroll
+- Add support for reading and writing configuration settings with cedit
 
 .. Simon Glass <[email protected]>
 .. 7-Oct-22
doc/usage/cmd/cedit.rst new file +31 -0
new file mode 100644
index 000000000000..8e1110c7c77e
@@ -0,0 +1,31 @@
+.. SPDX-License-Identifier: GPL-2.0+:
+
+cedit command
+=============
+
+Synopis
+-------
+
+::
+
+    cedit load <interface> <dev[:part]> <filename>
+    cedit run
+
+Description
+-----------
+
+The *cedit* command is used to load a configuration-editor description and allow
+the user to interact with it.
+
+It makes use of the expo subsystem.
+
+The description is in the form of a devicetree file, as documented at
+:ref:`expo_format`.
+
+Example
+-------
+
+::
+
+    => cedit load hostfs - fred.dtb
+    => cedit run
doc/usage/index.rst +1 -0
index 0fde130a5480..06316e9d3118 100644
@@ -37,6 +37,7 @@ Shell commands
    cmd/bootz
    cmd/cat
    cmd/cbsysinfo
+   cmd/cedit
    cmd/cls
    cmd/cmp
    cmd/coninfo
include/expo.h +29 -0
index 9fec4d0cd84e..0b1d944a169f 100644
@@ -11,6 +11,7 @@
 #include <linux/list.h>
 
 struct udevice;
+struct video_priv;
 
 /**
  * enum expoact_type - types of actions reported by the expo
@@ -378,6 +379,14 @@ int expo_calc_dims(struct expo *exp);
  */
 int expo_set_scene_id(struct expo *exp, uint scene_id);
 
+/**
+ * expo_first_scene_id() - Get the ID of the first scene
+ *
+ * @exp: Expo to check
+ * Returns: Scene ID of first scene, or -ENOENT if there are no scenes
+ */
+int expo_first_scene_id(struct expo *exp);
+
 /**
  * expo_render() - render the expo on the display / console
  *
@@ -667,4 +676,24 @@ int expo_apply_theme(struct expo *exp, ofnode node);
  */
 int expo_build(ofnode root, struct expo **expp);
 
+/**
+ * cedit_arange() - Arrange objects in a configuration-editor scene
+ *
+ * @exp: Expo to update
+ * @vid_priv: Private info of the video device
+ * @scene_id: scene ID to arrange
+ * Returns: 0 if OK, -ve on error
+ */
+int cedit_arange(struct expo *exp, struct video_priv *vid_priv, uint scene_id);
+
+/**
+ * cedit_run() - Run a configuration editor
+ *
+ * This accepts input until the user quits with Escape
+ *
+ * @exp: Expo to use
+ * Returns: 0 if OK, -ve on error
+ */
+int cedit_run(struct expo *exp);
+
 #endif /*__SCENE_H */
Signature · 1 line
2.41.0.rc0.172.g3f132b7071-goog
#40 lore raw

PATCH 39/40 expo: Add tests for the configuration editor

In reply to Simon Glass

Add some simple tests and a helpful script to make the configuration editor easier to set up.

---

 arch/sandbox/dts/sandbox.dtsi   |   6 ++
 arch/sandbox/dts/test.dts       |   6 ++
 test/boot/expo.c                |  44 +++++++++++
 test/boot/files/expo_layout.dts |  84 +++++++++++++++++++++
 test/py/tests/test_ut.py        |  10 +++
 tools/expo.py                   | 130 ++++++++++++++++++++++++++++++++
 6 files changed, 280 insertions(+)
 create mode 100644 test/boot/files/expo_layout.dts
 create mode 100755 tools/expo.py
arch/sandbox/dts/sandbox.dtsi +6 -0
index 30a305c4d208..f0ee0b3481ac 100644
@@ -16,6 +16,12 @@
 		stdout-path = "/serial";
 	};
 
+	cedit-theme {
+		font-size = <30>;
+		menu-inset = <3>;
+		menuitem-gap-y = <1>;
+	};
+
 	alarm_wdt: alarm-wdt {
 		compatible = "sandbox,alarm-wdt";
 		timeout-sec = <5>;
arch/sandbox/dts/test.dts +6 -0
index 442222e4b995..b5509eee8cfe 100644
@@ -144,6 +144,12 @@
 	cedit: cedit {
 	};
 
+	cedit-theme {
+		font-size = <30>;
+		menu-inset = <3>;
+		menuitem-gap-y = <1>;
+	};
+
 	fuzzing-engine {
 		compatible = "sandbox,fuzzing-engine";
 	};
test/boot/expo.c +44 -0

53 lines not on this page · raw message

test/boot/files/expo_layout.dts new file +84 -0

84 lines not on this page · raw message

test/py/tests/test_ut.py +10 -0
index 0b45863b4385..aa1d477cd565 100644
@@ -282,6 +282,15 @@ label Fedora-Workstation-armhfp-31-1.9 (5.3.7-301.fc31.armv7hl)
         copy_prepared_image(cons, mmc_dev, fname)
 
 
+def setup_cedit_file(cons):
+    infname = os.path.join(cons.config.source_dir,
+                           'test/boot/files/expo_layout.dts')
+    expo_tool = os.path.join(cons.config.source_dir, 'tools/expo.py')
+    outfname = 'cedit.dtb'
+    u_boot_utils.run_and_log(
+        cons, f'{expo_tool} -e {infname} -l {infname} -o {outfname}')
+
+
 @pytest.mark.buildconfigspec('ut_dm')
 def test_ut_dm_init(u_boot_console):
     """Initialize data for ut dm tests."""
@@ -319,6 +328,7 @@ def test_ut_dm_init_bootstd(u_boot_console):
 
     setup_bootflow_image(u_boot_console)
     setup_bootmenu_image(u_boot_console)
+    setup_cedit_file(u_boot_console)
 
     # Restart so that the new mmc1.img is picked up
     u_boot_console.restart_uboot()
tools/expo.py new file +130 -0

130 lines not on this page · raw message

Signature · 1 line
2.41.0.rc0.172.g3f132b7071-goog
#41 lore raw

PATCH 40/40 RFC: video: Update stb_truetype

In reply to Simon Glass

This was brought in in 2016 and a number of changes have been made since then. There does not seem to be much change in functionality, but it is a good idea to update from time to time.

Bring in the latest version:

5736b15 ("re-add perlin noise again")

Add a few necessary functions, with dummies in some cases. Update the tests as there are subtle changes in rendering, perhaps not for the better.

---

 drivers/video/console_truetype.c |   33 +
 drivers/video/stb_truetype.h     | 2257 +++++++++++++++++++++++++++---
 test/dm/video.c                  |    6 +-
 3 files changed, 2077 insertions(+), 219 deletions(-)
drivers/video/console_truetype.c +33 -0
index 288123a2e065..0f9bb49e44f7 100644
@@ -62,10 +62,43 @@ static double tt_sqrt(double value)
 	return lo;
 }
 
+static double tt_fmod(double x, double y)
+{
+	double rem;
+
+	if (y == 0.0)
+		return 0.0;
+	rem = x - (x / y) * y;
+
+	return rem;
+}
+
+/* dummy implementation */
+static double tt_pow(double x, double y)
+{
+	return 0;
+}
+
+/* dummy implementation */
+static double tt_cos(double val)
+{
+	return 0;
+}
+
+/* dummy implementation */
+static double tt_acos(double val)
+{
+	return 0;
+}
+
 #define STBTT_ifloor		tt_floor
 #define STBTT_iceil		tt_ceil
 #define STBTT_fabs		tt_fabs
 #define STBTT_sqrt		tt_sqrt
+#define STBTT_pow		tt_pow
+#define STBTT_fmod		tt_fmod
+#define STBTT_cos		tt_cos
+#define STBTT_acos		tt_acos
 #define STBTT_malloc(size, u)	((void)(u), malloc(size))
 #define STBTT_free(size, u)	((void)(u), free(size))
 #define STBTT_assert(x)
drivers/video/stb_truetype.h +2041 -216

2,957 lines not on this page · raw message

test/dm/video.c +3 -3
index 6d9c55c14035..0534ee93a3d4 100644

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

Signature · 1 line
2.41.0.rc0.172.g3f132b7071-goog

Part of the diff is not shown here. View the raw message.

#42 lore raw
In reply to Simon Glass
Quoted 11 lines · Simon Glass

This series provides a means to edit board configuration in U-Boot in a graphical manner. It supports multiple menu items and allows moving between them and selecting items. The configuration is defined in a data format so that code is not needed in most cases. This allows the board configuration to be provided in the devicetree.

This is still at an early stage, since it only supports menus. Numeric values are not supported. Most importantly it does not yet support loading or saving the configuration selected by the user.

[...]

Applied to u-boot/master, thanks!

Signature · 1 line
Tom