96 Commits

Author SHA1 Message Date
Simon Glass
9c19a957d3 video: vidconsole: Free cursor save buffer on device removal
The cursor save_data buffer is allocated when the cursor is enabled but
never freed. Add a pre_remove callback to free this buffer when the
vidconsole device is removed.

Fixes: aebedeac44 ("video: Provide a buffer to hold pixels behind the cursor")
Co-developed-by: Claude <noreply@anthropic.com>
Signed-off-by: Simon Glass <simon.glass@canonical.com>
2026-01-03 12:37:55 -07:00
Simon Glass
e38a1ae08e video: Show the cursor when idle
When the console is idle and at the CLI, ensure the cursor is visible.

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-09-19 12:56:02 -06:00
Simon Glass
8962a5fbe2 video: Save overwritten pixels when drawing the cursor
Save the pixels overwritten by the cursor into the save area.

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-09-19 12:56:02 -06:00
Simon Glass
f7b1a67327 video: Drop extra parameters from vidconsole_show_cursor()
Now that both console drivers use the CLI index, we don't need the extra
parameters for this. Drop them.

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-09-19 12:56:02 -06:00
Simon Glass
ea3440a535 video: Drop extra parameters from get_cursor_info()
Now that the console tracks the CLI index, remove the unnecessary
parameters. Both the normal and truetype consoles use the information
provided by the console.

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-09-19 12:56:02 -06:00
Simon Glass
54f7d358cd video: Drop vidconsole_set_cursor_visible()
There is only one user of this function. Update it to use the new
vidconsole_show_cursor() instead.

Remove the now-unused vidconsole_set_cursor_visible()

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-09-19 12:56:02 -06:00
Simon Glass
b59efb56f6 video: Track whether the cursor is enabled
The cursor should only be enabled if the user is entering something.
This can be at the CLI or in an expo. Provide a flag to track it, which
we can (later) use to determine whether or not to draw the cursor.

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-09-19 12:56:02 -06:00
Simon Glass
86655de2bd console: Add debugging for kerning
Add some debugging which can be used to manually check that truetype is
kerning against the expected character. This is tested by the
image-based tests but they are sometimes hard to debug.

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-09-19 12:56:01 -06:00
Simon Glass
691e10ead3 video: Provide a way to indicate the start of CLI entry
Add a new mark_start() method for the console, which indicates that the
CLI prompt has been written to the display and any following characters
will be user input.

There are two cases to consider, tracked by an indent flag in
struct vidconsole_cursor:

- normal CLI entry where new lines start at the left of the console
- expo entry where new lines start at the same position as the previous
  line (indent=true)

Record this position in the uclass info, so it is available to console
drivers.

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-09-19 12:56:01 -06:00
Simon Glass
fdfdb84dcc video: Track the current CLI index
Keep track of the current character index in the current CLI entry. This
corresponds to the cursor position and is numbered from zero.

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-09-19 12:56:01 -06:00
Simon Glass
6147153e56 video: Move cursor drawing into the uclass
Rather than having the truetype driver draw the cursor, make it just
return the information needed to draw the cursor. This will make it
possible for the normal console to support a cursor too.

Add a check for the cursor being entirely within the framebuffer.

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-09-19 12:56:01 -06:00
Simon Glass
4f5c8dcf7b video: Provide an idle function for the console
Add a way to tell the console that the machine is idle. This will be
used (later) to show the cursor.

Call the video console sync after that, so that any updates are shown.

Keep the video_sync_all() for the case where CONFIG_CURSOR is not
enabled, to reduce code size.

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-09-19 12:56:01 -06:00
Simon Glass
cca7523800 video: truetype: Handle rendering of bitmap fonts
Complete the support for this feature by dealing with rendering, the
moving to a particular row/column and scrolling.

Provide a simple test to check that things look right.

Allow omitting the font name to request the default font.

Fix an errant tab nearby.

Co-developed-by: Claude <noreply@anthropic.com>
Signed-off-by: Simon Glass <sjg@chromium.org>
2025-09-19 12:56:01 -06:00
Simon Glass
5c2b0938f1 video: Move setting of the bitmap font into uclass
Most of this function deals with uclass data, so move it into the
uclass. This will allow truetype to use it too.

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-09-19 12:56:01 -06:00
Simon Glass
2986bf7bcb video: Provide an option to enable the cursor
The video cursor is always enabled at present, but it is only used for
expo. Put it behind an option, to reduce code size for platforms which
do use video but don't want a cursor.

Move the existing set_cursor_visible() method behind this option, for
the normal console. For the truetype console, the fonts and extra
rendering dwarf the code-size saving, so include the cursor there
always.

Once the cursor is enabled for the CLI, this will produce code-size
savings.

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-09-19 11:42:51 -06:00
Simon Glass
551b30c659 video: Correct ops check for nominal, entry save/restore
All of these helper functions check the wrong member. Fix them.

Signed-off-by: Simon Glass <sjg@chromium.org>
Fixes: 9e55d09596 ("video: Allow obtaining the nominal size of a...")
Fixes: 9899eef2cb ("video: Allow saving and restoring text-entry...")
2025-09-18 15:41:37 -06:00
Simon Glass
e9a72c6b7c video: Mark the vidconsole as a driver model stdio device
Set the DEV_FLAGS_DM flag so this stdio device is recognised as being
provided by a driver model device.

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-08-25 06:54:01 -06:00
Simon Glass
b04cc06e69 vidconsole: Avoid kerning against an unrelated character
When the cursor position changes, kerning should not be used for the
next character, since it can make the first displayed character shuffle
left or right a bit.

Clear the kern character when setting the position.

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-05-01 17:31:39 -06:00
Simon Glass
4fbd842e56 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>
2025-05-01 17:31:39 -06:00
Simon Glass
77b35845c2 video: Add a way to write a partial string to the console
When writing multiple lines of text we need to be able to control which
text goes on each line. Add a new vidconsole_put_stringn() function to
help with this.

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-05-01 17:31:39 -06:00
Simon Glass
3a9da4f932 video: truetype: Support a limit on the width of a line
Expo needs to be able to word-wrap lines so that they are displayed as
the user expects. Add a limit on the width of each line and support this
in the measurement algorithm.

Add a log category to truetype while we are here.

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-05-01 17:31:39 -06:00
Simon Glass
30ad08e2c0 video: Begin support for measuring multiple lines of text
Update the vidconsole API so that measure() can measure multiple lines
of text. This will make it easier to implement multi-line fields in
expo.

Tidy up the function comments while we are here.

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-05-01 17:31:39 -06:00
Alexander Graf
abbc0861a1 video: Use VIDEO_DAMAGE for VIDEO_COPY
CONFIG_VIDEO_COPY implemented a range-based copying mechanism: If we
print a single character, it will always copy the full range of bytes
from the top left corner of the character to the lower right onto the
uncached frame buffer. This includes pretty much the full line contents
of the printed character.

Since we now have proper damage tracking, let's make use of that to reduce
the amount of data we need to copy. With this patch applied, we will only
copy the tiny rectangle surrounding characters when we print them,
speeding up the video console.

After this, changes to the main frame buffer are not immediately copied
to the copy frame buffer, but postponed until the next video device
sync. So issue an explicit sync before inspecting the copy frame buffer
contents for the video tests.

Signed-off-by: Alexander Graf <agraf@csgraf.de>
[Alper: Rebase for fontdata->height/w, fill_part(), fix memmove(dev),
        drop from defconfig, use damage.xstart/yend, use IS_ENABLED(),
        call video_sync() before copy_fb check, update video_copy test]
Co-developed-by: Alper Nebi Yasak <alpernebiyasak@gmail.com>
Signed-off-by: Alper Nebi Yasak <alpernebiyasak@gmail.com>
Link: https://lore.kernel.org/u-boot/20230821135111.3558478-12-alpernebiyasak@gmail.com/
2024-12-07 15:55:33 -07:00
Simon Glass
18a85cf7b5 video: Avoid starting a new line to close to the bottom
When starting a new text line, an assumption is made that the current
vertical position is a multiple of the character height. When this is
not true, characters can be written after the end of the framebuffer.

This can causes crashes and strange errors from QEMU.

Adjust the scrolling check when processing a newline character, to
avoid any problems.

Add some comments to make things a little clearer.

Signed-off-by: Simon Glass <sjg@chromium.org>
2024-10-18 14:10:22 -06:00
Tom Rini
03de305ec4 Restore patch series "arm: dts: am62-beagleplay: Fix Beagleplay Ethernet"
As part of bringing the master branch back in to next, we need to allow
for all of these changes to exist here.

Reported-by: Jonas Karlman <jonas@kwiboo.se>
Signed-off-by: Tom Rini <trini@konsulko.com>
2024-05-20 13:35:03 -06:00
Tom Rini
d678a59d2d Revert "Merge patch series "arm: dts: am62-beagleplay: Fix Beagleplay Ethernet""
When bringing in the series 'arm: dts: am62-beagleplay: Fix Beagleplay
Ethernet"' I failed to notice that b4 noticed it was based on next and
so took that as the base commit and merged that part of next to master.

This reverts commit c8ffd1356d, reversing
changes made to 2ee6f3a5f7.

Reported-by: Jonas Karlman <jonas@kwiboo.se>
Signed-off-by: Tom Rini <trini@konsulko.com>
2024-05-19 08:16:36 -06:00
Tom Rini
a2955579e7 video: Remove <common.h> and add needed includes
Remove <common.h> from this driver directory and when needed
add missing include files directly.

Reviewed-by: Peter Robinson <pbrobinson@gmail.com>
Signed-off-by: Tom Rini <trini@konsulko.com>
2024-05-07 08:00:57 -06:00
Tom Rini
a691594241 Merge patch series "Resolve issues with booting distros on x86"
Simon Glass <sjg@chromium.org> says:

This little series reprises the EFI-video fix, fixes a USB problem and
enables a boot script for coreboot.

It also moves to truetype fonts for coreboot and qemu-x86, since the
menus look much better and there are no strong size constraints.

With these changes it is possible to boot a Linux distro automatically
with U-Boot on x86, including when U-Boot is the second-stage
bootloader.
2024-04-10 20:01:42 -06:00
Simon Glass
9e95e909f6 video: Correct setting of cursor position
The ANSI codes are not correctly handled at present, in that the
requested X position is added to the current one.

Correct this and also call vidconsole_entry_start() to start a new text
line.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Anatolij Gustschin <agust@denx.de>
2024-04-10 20:01:33 -06:00
Janne Grunau
5ea38f95c4 video: console: Parse UTF-8 character sequences
efi_console / UEFI applications (grub2, sd-boot, ...) pass UTF-8
character sequences to vidconsole which results in wrong glyphs for code
points outside of ASCII. The truetype console expects Unicode code
points and bitmap font based consoles expect code page 437 code points.
To support both convert UTF-8 to UTF-32 and pass Unicode code points in
vidconsole_ops.putc_xy(). These can be used directly in console_truetype
and after conversion to code page 437 in console_{normal,rotate}.

This fixes rendering of international, symbol and box drawing characters
used by UEFI applications.

Signed-off-by: Janne Grunau <j@jannau.net>
2024-03-21 06:56:13 +01:00
Simon Glass
37db20d0a6 video: Support showing a cursor
Add rudimentary support for displaying a cursor on a vidconsole. This
helps the user to see where text is being entered.

The implementation so far is very simple: the cursor is just a vertical
bar of fixed width and cannot be erased. To erase the cursor, the text
must be redrawn over it.

This is good enough for expo but will need enhancement to be useful for
the command-line console. For example, it could save and restore the
area behind the cursor.

For now, enable this only for expo, to reduce code size.

Signed-off-by: Simon Glass <sjg@chromium.org>
2023-10-11 15:43:55 -04:00
Simon Glass
617d7b545b video: Export vidconsole_entry_start()
At present this is called only when a newline is detected, since this
indicates the start of a line of text being entered.

Export this function so it can be used by expo, which may start a new
text line itself, without first writing out a newline.

Signed-off-by: Simon Glass <sjg@chromium.org>
2023-10-11 15:43:55 -04:00
Simon Glass
9899eef2cb video: Allow saving and restoring text-entry state
Text entry operates within a context which includes quite a bit of
information. For example, with Truetype fonts, each character in the
text string has a position stored, so that it is possible to
backspace to that character. This information is built up as strings
are drawn on the display.

For the command line, there is just a single context. It is created
when command-line entry starts and it is destroyed (or at least not
needed anymore) when the user presses <enter> to enter the command.

By contrast, expo needs to be able to switch in and out of a text-entry
context, since it is also displaying other objects in the scene.

Add a way to save and restore the entry context for a vidconsole. This
is only needed for the truetype vidconsole, so add a method for that,
storing the information in an abuf struct.

Signed-off-by: Simon Glass <sjg@chromium.org>
2023-10-11 15:43:55 -04:00
Simon Glass
9e55d09596 video: Allow obtaining the nominal size of a string size
At present there is a method for measuring text, but if the actual text
string is not known, it cannot be used.

For text editor we want to set the size of the entry box to cover the
expected text size. Add the concept of a 'norminal' size with a method
to calculate that for the vidconsole.

If the method is not implemented, fall back to using the font size,
which is sufficient for fixed-width fonts.

Signed-off-by: Simon Glass <sjg@chromium.org>
2023-10-11 15:43:55 -04:00
Bin Meng
01c76f1a64 video: vidconsole: Fix null dereference of ops->measure
At present vidconsole_measure() tests ops->select_font before calling
ops->measure, which would result in a null dereference when the console
driver provides no ops for measure.

Fixes: b828ed7d79 ("console: Allow measuring the bounding box of text")
Signed-off-by: Bin Meng <bmeng@tinylab.org>
Reviewed-by: Simon Glass <sjg@chromium.org>
2023-08-13 23:08:15 +02:00
Simon Glass
b828ed7d79 console: Allow measuring the bounding box of text
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.

Signed-off-by: Simon Glass <sjg@chromium.org>
2023-07-14 12:54:51 -04:00
Simon Glass
648a4991d0 video: Allow temporary colour changes
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.

Signed-off-by: Simon Glass <sjg@chromium.org>
2023-07-14 12:54:51 -04:00
Nikhil M Jain
86fbee6020 drivers: video: Enable necessary video functions at SPL
To support video driver at SPL use CONFIG_IS_ENABLED and CONFIG_VAL,
which checks for stage specific configs and thus enables video support
at respective stage.

Signed-off-by: Nikhil M Jain <n-jain1@ti.com>
Reviewed-by: Devarsh Thakkar <devarsht@ti.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Tested-by: Simon Glass <sjg@chromium.org>
2023-04-24 21:37:45 +02:00
Tom Rini
f6546c7822 Revert 9f62a472df ("video: Remove duplicate cursor-positioning function")
This reverts commit 9f62a472df.

The changes here aren't quite right, and on platforms such as Raspberry
Pi where we can have both serial and video output, the change above
causes output to change. This can be seen as the hush tests we have now
fail.

Signed-off-by: Tom Rini <trini@konsulko.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
2023-03-16 12:17:02 -04:00
Simon Glass
a76b60f820 video: Clear the vidconsole rather than the video
It is better to clear the console device rather than the video device,
since the console has the text display. We also need to reset the cursor
position with the console, but not with the video device.

Add a new function to handle this and update the 'cls' command to use it.

Signed-off-by: Simon Glass <sjg@chromium.org>
2023-03-13 13:53:01 +01:00
Simon Glass
9f62a472df video: Remove duplicate cursor-positioning function
There are two functions for positioning the cursor on the console. Remove
one of them.

Signed-off-by: Simon Glass <sjg@chromium.org>
2023-03-13 13:53:01 +01:00
Dzmitry Sankouski
4f6e34811d video console: move vidconsole_get_font_size() logic to driver ops
Since multiple vidconsole drivers exists, vidconsole_get_font_size()
implementation cannot longer live in vidconsole_uclass.c file.

Move current vidconsole_get_font_size logic to truetype driver ops.

Signed-off-by: Dzmitry Sankouski <dsankouski@gmail.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
2023-03-07 15:59:21 +01:00
Tom Rini
a3fda0d30a global: Remove unused CONFIG defines
Remove some CONFIG symbols and related comments, etc, that are unused
within the code itself at this point.

Signed-off-by: Tom Rini <trini@konsulko.com>
2023-01-20 12:27:06 -05:00
Simon Glass
0e38bd848d video: Add font functions to the vidconsole API
Support for fonts currently depends on the type of vidconsole in use. Add
two new methods to enumerate fonts and to set the font.

Fix a few other method comments while we are here.

Signed-off-by: Simon Glass <sjg@chromium.org>
2023-01-16 18:26:50 -05:00
Simon Glass
f029f90e7d video: Move the console commands to cmd/
Move these commands and the implementation to the cmd/ directory, which is
where most commands are kept.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
[agust: keep vidconsole_position_cursor() in vidconsole uclass]
Signed-off-by: Anatolij Gustschin <agust@denx.de>
2022-10-30 19:55:22 +01:00
Simon Glass
92fd6a1220 video: Use vidconsole_put_string() to write a string
Use the existing function rather that duplicating the code. Also fix up
the missing error handling.

Signed-off-by: Simon Glass <sjg@chromium.org>
2022-10-30 09:56:02 +01:00
Simon Glass
6b6dc0d2fb video: Provide a function to set the cursor position
Add an exported function which allows the cursor position to be set to
pixel granularity. Make use of this in the existing code.

Signed-off-by: Simon Glass <sjg@chromium.org>
2022-10-30 09:53:47 +01:00
Simon Glass
a032e4b55e video: Move console colours to the video uclass
At present these are attached to vidconsole which means that the video
uclass requires that a console is enabled. This is not the intention.
The colours are a reasonable way of indexing common colours in any case,
so move them to the video uclass instead.

Rename vid_console_color() to video_index_to_colour() now that it is more
generic. Also fix the inconsistent spelling in these functions.

Signed-off-by: Simon Glass <sjg@chromium.org>
2022-10-30 08:43:24 +01:00
Mark Kettenis
0efe41ca15 video: Add 30bpp support
Add support for 30bpp mode where pixels are picked in 32-bit
integers but use 10 bits instead of 8 bits for each component.

Signed-off-by: Mark Kettenis <kettenis@openbsd.org>
2021-10-09 18:43:51 +02:00
Simon Glass
0b1284eb52 global: Convert simple_strtoul() with decimal to dectoul()
It is a pain to have to specify the value 10 in each call. Add a new
dectoul() function and update the code to use it.

Signed-off-by: Simon Glass <sjg@chromium.org>
2021-08-02 13:32:14 -04:00