[Concept,6/6] video: Provide a command to list built-in images

Message ID 20251001230537.3324058-7-sjg@u-boot.org
State New
Headers
Series video: Tidy up embedded graphical images |

Commit Message

Simon Glass Oct. 1, 2025, 11:05 p.m. UTC
  From: Simon Glass <sjg@chromium.org>

Add a new 'video images' command which lists the graphical images that
are compiled into U-Boot. Generally the only one is the logo.

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

 cmd/video.c             | 30 ++++++++++++++++++++++++++++--
 doc/usage/cmd/video.rst | 19 +++++++++++++++++++
 test/dm/video.c         | 16 ++++++++++++++++
 3 files changed, 63 insertions(+), 2 deletions(-)
  

Patch

diff --git a/cmd/video.c b/cmd/video.c
index c9f2d91a0ba..6f3fa29a147 100644
--- a/cmd/video.c
+++ b/cmd/video.c
@@ -8,6 +8,7 @@ 
 
 #include <command.h>
 #include <dm.h>
+#include <linker_lists.h>
 #include <video.h>
 #include <video_console.h>
 
@@ -47,6 +48,29 @@  static int do_video_puts(struct cmd_tbl *cmdtp, int flag, int argc,
 	return ret ? CMD_RET_FAILURE : 0;
 }
 
+static int do_video_images(struct cmd_tbl *cmdtp, int flag, int argc,
+			   char *const argv[])
+{
+	struct video_image *image;
+	int count, i;
+
+	image = ll_entry_start(struct video_image, video_image);
+	count = ll_entry_count(struct video_image, video_image);
+
+	printf("%-20s %10s\n", "Name", "Size");
+	printf("%-20s %10s\n", "--------------------", "----------");
+
+	for (i = 0; i < count; i++, image++) {
+		ulong size = (ulong)image->end - (ulong)image->begin;
+
+		printf("%-20s %10lu\n", image->name, size);
+	}
+
+	printf("\nTotal images: %d\n", count);
+
+	return 0;
+}
+
 U_BOOT_CMD(
 	setcurs, 3,	1,	do_video_setcursor,
 	"set cursor position within screen",
@@ -61,8 +85,10 @@  U_BOOT_CMD(
 
 U_BOOT_LONGHELP(video,
 	"setcursor <col> <row> - Set cursor position\n"
-	"video puts <string>       - Write string at current position");
+	"video puts <string>       - Write string at current position\n"
+	"video images              - List images compiled into U-Boot");
 
 U_BOOT_CMD_WITH_SUBCMDS(video, "Video commands", video_help_text,
 	U_BOOT_SUBCMD_MKENT(setcursor, 3, 1, do_video_setcursor),
-	U_BOOT_SUBCMD_MKENT(puts, 2, 1, do_video_puts));
+	U_BOOT_SUBCMD_MKENT(puts, 2, 1, do_video_puts),
+	U_BOOT_SUBCMD_MKENT(images, 1, 1, do_video_images));
diff --git a/doc/usage/cmd/video.rst b/doc/usage/cmd/video.rst
index 139f90bd3ff..d7e2527805a 100644
--- a/doc/usage/cmd/video.rst
+++ b/doc/usage/cmd/video.rst
@@ -11,6 +11,7 @@  Synopsis
 
     video setcursor <col> <row>
     video puts <string>
+    video images
 
 Description
 -----------
@@ -40,6 +41,15 @@  Write a string to the video console at the current cursor position.
 string
     Text string to display
 
+video images
+~~~~~~~~~~~~
+
+    video images
+
+List all images that are compiled into U-Boot. This shows the name and size
+of each image that was built from .bmp files in the drivers/video/images
+directory.
+
 Examples
 --------
 
@@ -55,6 +65,15 @@  Print at different positions::
     => video setcursor 0 10
     => video puts "Line 10"
 
+List compiled-in images::
+
+    => video images
+    Name                       Size
+    -------------------- ----------
+    u_boot                     6932
+
+    Total images: 1
+
 Configuration
 -------------
 
diff --git a/test/dm/video.c b/test/dm/video.c
index 98bb0057b18..1f1bf7c59c8 100644
--- a/test/dm/video.c
+++ b/test/dm/video.c
@@ -1105,3 +1105,19 @@  static int dm_test_video_cmd(struct unit_test_state *uts)
 	return 0;
 }
 DM_TEST(dm_test_video_cmd, UTF_SCAN_PDATA | UTF_SCAN_FDT);
+
+/* video images command */
+static int dm_test_video_images(struct unit_test_state *uts)
+{
+	ut_assertok(run_command("video images", 0));
+	ut_assert_nextline("Name                       Size");
+	ut_assert_nextline("-------------------- ----------");
+	ut_assert_nextline("bgrt                      43926");
+	ut_assert_nextline("u_boot                     6932");
+	ut_assert_skip_to_line("");
+	ut_assert_nextline("Total images: 2");
+	ut_assert_console_end();
+
+	return 0;
+}
+DM_TEST(dm_test_video_images, UTF_SCAN_PDATA | UTF_SCAN_FDT | UTF_CONSOLE);