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 <sjg@chromium.org>
This commit is contained in:
Simon Glass
2025-04-02 06:29:42 +13:00
committed by Tom Rini
parent 7320a2cb94
commit cb32266d4a
3 changed files with 60 additions and 0 deletions

View File

@@ -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;
}

View File

@@ -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

View File

@@ -17,6 +17,7 @@
#include <asm/sdl.h>
#include <dm/test.h>
#include <dm/uclass-internal.h>
#include <test/lib.h>
#include <test/test.h>
#include <test/ut.h>
#include <test/video.h>
@@ -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);