From: Simon Glass Date: Tue, 1 Apr 2025 17:29:42 +0000 (+1300) Subject: video: Allow console output to be silenced X-Git-Tag: v2025.07-rc2~43^2~2 X-Git-Url: http://git.openpandora.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=cb32266d4aeca4a730c1f8b85c981a8793d768c4;p=pandora-u-boot.git video: Allow console output to be silenced When using expo we want to be able to control the information on the display and avoid other messages (such as USB scanning) appearing. Add a 'quiet' flag for the console, to help with this. The test is a little messy since stdio is still using the original vidconsole create on start-up. So take care to use the same. Signed-off-by: Simon Glass --- diff --git a/drivers/video/vidconsole-uclass.c b/drivers/video/vidconsole-uclass.c index fa329bd1b37..6ba62ec348e 100644 --- a/drivers/video/vidconsole-uclass.c +++ b/drivers/video/vidconsole-uclass.c @@ -532,8 +532,11 @@ int vidconsole_put_string(struct udevice *dev, const char *str) static void vidconsole_putc(struct stdio_dev *sdev, const char ch) { struct udevice *dev = sdev->priv; + struct vidconsole_priv *priv = dev_get_uclass_priv(dev); int ret; + if (priv->quiet) + return; ret = vidconsole_put_char(dev, ch); if (ret) { #ifdef DEBUG @@ -551,8 +554,11 @@ static void vidconsole_putc(struct stdio_dev *sdev, const char ch) static void vidconsole_puts(struct stdio_dev *sdev, const char *s) { struct udevice *dev = sdev->priv; + struct vidconsole_priv *priv = dev_get_uclass_priv(dev); int ret; + if (priv->quiet) + return; ret = vidconsole_put_string(dev, s); if (ret) { #ifdef DEBUG @@ -794,3 +800,10 @@ void vidconsole_position_cursor(struct udevice *dev, unsigned col, unsigned row) y = min_t(short, row * priv->y_charsize, vid_priv->ysize - 1); vidconsole_set_cursor_pos(dev, x, y); } + +void vidconsole_set_quiet(struct udevice *dev, bool quiet) +{ + struct vidconsole_priv *priv = dev_get_uclass_priv(dev); + + priv->quiet = quiet; +} diff --git a/include/video_console.h b/include/video_console.h index e4fc776e2d3..8f3f58f3aa9 100644 --- a/include/video_console.h +++ b/include/video_console.h @@ -53,6 +53,7 @@ enum { * @row_saved: Saved Y position in pixels (0=top) * @escape_buf: Buffer to accumulate escape sequence * @utf8_buf: Buffer to accumulate UTF-8 byte sequence + * @quiet: Suppress all output from stdio */ struct vidconsole_priv { struct stdio_dev sdev; @@ -77,6 +78,7 @@ struct vidconsole_priv { int col_saved; char escape_buf[32]; char utf8_buf[5]; + bool quiet; }; /** @@ -584,4 +586,12 @@ void vidconsole_list_fonts(struct udevice *dev); */ int vidconsole_get_font_size(struct udevice *dev, const char **name, uint *sizep); +/** + * vidconsole_set_quiet() - Select whether the console should output stdio + * + * @dev: vidconsole device + * @quiet: true to suppress stdout/stderr output, false to enable it + */ +void vidconsole_set_quiet(struct udevice *dev, bool quiet); + #endif diff --git a/test/dm/video.c b/test/dm/video.c index 737ab915f41..dd06b2f58e8 100644 --- a/test/dm/video.c +++ b/test/dm/video.c @@ -17,6 +17,7 @@ #include #include #include +#include #include #include #include @@ -865,3 +866,39 @@ static int dm_test_font_measure(struct unit_test_state *uts) return 0; } DM_TEST(dm_test_font_measure, UTF_SCAN_FDT); + +/* Test silencing the video console */ +static int dm_test_video_silence(struct unit_test_state *uts) +{ + struct udevice *dev, *con; + struct stdio_dev *sdev; + + ut_assertok(uclass_first_device_err(UCLASS_VIDEO, &dev)); + + /* + * use the old console device from before when dm_test_pre_run() was + * called, since that is what is in stdio / console + */ + sdev = stdio_get_by_name("vidconsole"); + ut_assertnonnull(sdev); + con = sdev->priv; + ut_assertok(vidconsole_clear_and_reset(con)); + ut_unsilence_console(uts); + + printf("message 1: console\n"); + vidconsole_put_string(con, "message 1: video\n"); + + vidconsole_set_quiet(con, true); + printf("second message: console\n"); + vidconsole_put_string(con, "second message: video\n"); + + vidconsole_set_quiet(con, false); + printf("final message: console\n"); + vidconsole_put_string(con, "final message: video\n"); + + ut_asserteq(3892, video_compress_fb(uts, dev, false)); + ut_assertok(video_check_copy_fb(uts, dev)); + + return 0; +} +DM_TEST(dm_test_video_silence, UTF_SCAN_FDT);