Commit Graph

98931 Commits

Author SHA1 Message Date
Simon Glass
10a0dec8bc pager: doc: Add mention of the pager feature
Add a note about the pager to the console documentation, with some more
information in the developer section. Also include the pager API.

Series-to: concept
Cover-letter:
Introduce a pager for the console
Some U-Boot commands can produce a lot of output and this can run off
top of the display. This series introduces a simple pager feature, to
allow the output to be read, before pressing SPACE to continue.

A fixed buffer size (4K) is used, which sets a limit on the permmited
output before paging fails and the output is simply written all in one
lot. In most cases this is plenty, but 'env print' does print the whole
environment as one string, so if the legacy distro-boot scripts are used
it could happen.

The default number of visible lines is set with a Kconfig option. Where
a video terminal is being used, the page size is set to match that. In
general U-Boot cannot guess the number of visible lines, since a serial
terminal may be in use.

There is also a 'pager' environment variable which can override any
detected value.

This initial series only counts newlines. It has no support for counting
characters so the result will be sub-optimal if very long lines are
written. This could be addressed in a future patch.

Some effort is made to handle common cases correctly. For example, if
stdout is changed to a serial or vidconsole device, that is used to
determine the page length. When redirecting sandbox to a file, no
attempt is made.

Future work may detect the terminal size by sending an ANSI sequence.
END

Signed-off-by: Simon Glass <sjg@chromium.org>
Series-version: 2
2025-08-26 14:36:07 -06:00
Simon Glass
480be6d905 efi: Enable the console pager for the app
The app can produce quite a bit of output, so enable the pager feature.

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-08-26 14:36:07 -06:00
Simon Glass
f3d27f9841 console: Add tests for calc_check_console_lines()
Add tests for checking:
- environment variable override with hex values
- invalid environment variable handling
- Kconfig-default behavior with device detection
- precedence rules (environment overrides device detection)
- serial terminal detection by manipulating sandbox state

Also expose calc_check_console_lines() in console.h for testing
and update pager functionality to use bypass mode when serial
is not connected to a terminal.

Co-Authored-By: Claude <noreply@anthropic.com>
Signed-off-by: Simon Glass <sjg@chromium.org>
2025-08-26 14:36:07 -06:00
Simon Glass
4aefafb381 console: Recheck the page length when stdout device changes
It is annoying to have the pager use the line count from the display
when console output is actually using serial. Check this when stdio
changes and recaculate as needed.

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-08-26 14:36:07 -06:00
Simon Glass
ca37f12368 console: Get the pager lines from the serial console
If there is a serial console, use that to set the number of lines for the
pager.

This is controlled by CONFIG_SERIAL_TERM_PRESENT

Enable SERIAL_TERM_PRESENT by default if the pager is being used, since
people generally have a serial console enabled.

Make the serial a lower priority than the vidconsole.

We don't want to use the pager when the output of sandbox is being
redirected. So in that case, put the pager in bypass mode.

Series-changes: 2
- Only use the vidconsole if we believe it is visible

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-08-26 14:36:07 -06:00
Simon Glass
2f6efe5832 console: Get the pager lines from the vidconsole
If there is a video console, use that to set the number of lines for the
pager.

For sandbox, only do this if the -l flag was provided, i.e. the emulated
LCD is visible.

Series-changes: 2
- Only use the vidconsole if we believe it is visible

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-08-26 14:36:07 -06:00
Simon Glass
4412d9c3cf bdinfo: Show the pager page_len value
Show the actual value being used by the pager, if enabled.

Series-changes: 2
- Add new patch to show the pager page_len value

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-08-26 14:36:07 -06:00
Simon Glass
731ee5ebfb console: Implement an environment var to control the pager
The 'pager' environment variable can be used to set the number of lines
on the display. Provide a callback for this.

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-08-26 14:36:07 -06:00
Simon Glass
5d26e9dc1c console: Reset the pager when entering a new command
We don't want the pager appearing when entering commands, so add a way
to bypass it. Reset the line count to zero before executing the command.

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-08-26 14:36:07 -06:00
Simon Glass
5c8817090b console: Add a few more paging tests
Provide a test that the prompt is displayed and another that paging
happens but does not appear in the recorded console-output.

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-08-26 14:36:07 -06:00
Simon Glass
28311413de console: Support paging with single characters
A single character may result in a stall waiting for user input, which
means that it may request that a string be output. So when the pager is
active we never actually use the devices' putc() methods. Add a special
case so they don't go to wrack and ruin.

As before, the pager is only supported with CONFIG_CONSOLE_MUX enabled.

Series-changes: 2
- Drop unnecessary '!= NULL'

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-08-26 14:36:07 -06:00
Simon Glass
3b30dd23bd console: Support a bypass state
Allow the pager to be put in a bypass state, e.g. if not connected to
a terminal.

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-08-26 14:36:07 -06:00
Simon Glass
cad364dd79 console: test: Allow tests to bypass the pager
We generally don't want the pager to be active when running tests,
since U-Boot appears to hang forever. Perhaps we could detect when the
tests are being run interactively and use the pager in that case. But
for now, just bypass it.

Co-developed-by: Claude <noreply@anthropic.com>
Signed-off-by: Simon Glass <sjg@chromium.org>
2025-08-26 14:36:07 -06:00
Simon Glass
d3d493c8a3 console: Plumb in the pager
Send all console output via the pager. If it is disabled, it will do
nothing.

The pager is only supported if CONSOLE_MUX and SYS_CONSOLE_IS_IN_ENV are
enabled. This is the common case for more richly featured boards, i.e.
those that can cope with the extra code size of this feature.

Series-changes: 2
- Drop an unnecessary direct call to the pager
- Repeat the old code in console_puts_pager() to avoid 16-byte growth

Co-developed-by: Claude <noreply@anthropic.com>
Signed-off-by: Simon Glass <sjg@chromium.org>
2025-08-26 14:36:07 -06:00
Simon Glass
149fe34151 test/py: Disable terminal detection with sandbox tests
Detecting the terminal size results in unwanted output in tests. Use the
-A option to disable this.

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-08-26 14:36:07 -06:00
Simon Glass
c0f36f2d00 sandbox: Add -A option to assume no terminal present
Add a new -A sandbox command-line option that sets a flag to assume no
terminal is present. This causes serial_query_size() to return -ENOENT
immediately, similar to when CONFIG_SERIAL_TERM_PRESENT is disabled.

This option is useful for testing pager behavior in non-interactive
environments without needing to modify configuration options.

Co-developed-by: Claude <noreply@anthropic.com>
2025-08-26 14:36:07 -06:00
Simon Glass
03fde8e2bf test/py: Disable the pager when running sandbox tests
The pager gets in the way of most tests, since it kicks in (by default)
when a command results in more than 25 lines of output. Use the -P flag
to bypass it.

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-08-26 14:36:07 -06:00
Simon Glass
b74731763e sandbox: Add -P flag to enable bypassing the pager
Add a new -P command line flag to sandbox that enables pager-bypass
mode. This is useful for tests and automated scripts that need to
disable pager interrupts.

The implementation stores the bypass request in sandbox_state during
command line parsing, then applies it in sandbox_main_loop_init()
after the pager has been initialized.

Co-developed-by: Claude <noreply@anthropic.com>
Signed-off-by: Simon Glass <sjg@chromium.org>
2025-08-26 14:36:07 -06:00
Simon Glass
048f9d4bb9 console: Rename console-put functions to prepare for pager
Rename console_puts() to console_puts_pager() and console_putc() to
console_putc_pager() to prepare for implementing a console-pager
feature.

All normal output goes through the pager.

Co-developed-by: Claude <noreply@anthropic.com>
Signed-off-by: Simon Glass <sjg@chromium.org>
2025-08-26 14:36:06 -06:00
Simon Glass
984b363d02 console: Provide a way to output without the pager
Sometimes output should be sent ignoring the pager, such as when it is
a message related to paging. Add a parameter to support this.

Co-developed-by: Claude <noreply@anthropic.com>
Signed-off-by: Simon Glass <sjg@chromium.org>
2025-08-26 14:36:06 -06:00
Simon Glass
4a74dee5ce console: Add tests for the basic functionality
Cover the various cases in the base code. Put the tests in the 'common'
suite to match where the pager implementation is.

Co-developed-by: Claude <noreply@anthropic.com>
Signed-off-by: Simon Glass <sjg@chromium.org>
2025-08-26 14:36:06 -06:00
Simon Glass
8a18343bdc console: Add the basic pager implementation
Add an implementation of the pager. It has quite a simple API:

  - call pager_post() to send some output, which returns what should
    actually be sent to the console devices
  - then call pager_next() repeatedly, outputting what it returns,
    until it returns NULL

There is one special case: pager_next() returns PAGER_WAITING if it is
waiting for the user to press a key. In that case, the caller should
read a key and then pass it to the next pager_next() call.

Internally, there is a simple state machine to cope with hitting the
limit (and outputing a prompt), waiting for the user and the clearing
the prompt, before continuing in the normal PAGEST_OK state.

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-08-26 14:36:06 -06:00
Simon Glass
c2bc3cbc57 Merge branch 'clia3' into 'master'
console: Refactor in preparation for the pager

See merge request u-boot/u-boot!162
2025-08-26 20:35:41 +00:00
Simon Glass
b93fc06fd8 doc: Tidy up the console docs a little
Tweak the documentation to look better when viewed. Use 'write' instead
of 'put'.

Series-to: concept
Series-cc: heinrich
Series-version: 3
Cover-letter:
console: Refactor in preparation for the pager
This series tidies up a few small things the serial and console areas:

- Move detection of serial-console size to the serial module
- Provide a Kconfig to disable serial detection
- Fix some missing driver-model flags in stdio devices
- Move console docs into the main documentation

This series is marked v2 since some of the patches were sent in any
earlier series. With various tweaks that series grew too large to be
sent as a single series.
END

Signed-off-by: Simon Glass <sjg@chromium.org>
Series-links: 2:17
2025-08-26 06:02:03 -06:00
Simon Glass
2f6a2ed3db doc: Move console docs to rST
Move the console readme into the main documentation, with as few changes
as possible.

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-08-26 06:02:03 -06:00
Simon Glass
041d645d77 doc: Remove obsolete text in README.console
The latter part of this file is very out-of-date, so drop it.

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-08-26 06:02:03 -06:00
Simon Glass
28422856ce console: Refactor handling of the result in on_console()
This function has lots of return statements in a switch statement. Move
them out so we can (later) do something else in this function.

Series-changes: 2
- Add new patch to refactor handling of the result in on_console()

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-08-26 06:02:03 -06:00
Simon Glass
b662440385 console: Move environment handling lower in the file
Move the environment callbacks lower so that we can call functions
elsewhere in common/console.c

Series-changes: 2
- Add new patch to move environment handling lower in the file

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-08-26 06:02:03 -06:00
Simon Glass
ccdb52faf0 console: Update conio command to show uclass
When an stdio device is provided by a driver model device, optionally
show the uclass.

Be careful to avoid increasing code size, since this is a common
command.

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-08-26 06:02:03 -06:00
Simon Glass
249bb45cb3 console: Update coninfo to use sdev instead of dev
The 'dev' variable is generally used for driver model, so change
do_coninfo() to use sdev, to avoid confusion.

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-08-26 06:02:03 -06:00
Simon Glass
8aa1e7c81e cli: Avoid sending ANSI characters to a non-terminal
Detect if there is no terminal present (this only works on sandbox) and
skip sending ANSI characters when the CLI starts up. This avoids having
them in logs, for example.

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-08-26 06:02:03 -06:00
Simon Glass
ae8fb2dbf1 post: Include config.h in the header
The post system requires use of CFG_xxx values which are only included
via the config.h header. Most files don't include this now.

The serial.h header includes post.h which causes a build error on any
platform which enables CONFIG_POST, such as pg_wcom_seli8

Add an explicit #include of config.h in the post.h header file.

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-08-26 06:02:03 -06:00
Simon Glass
1ee02ca627 sandbox: Provide a way to tell if the video is visible
Sandbox is often run with the display disabled, so even though it has a
video device, it is not being shown. Provide a way to detect this. For
all other platforms, we assume the display is shown, when there is a
video device.

Series-changes: 2
- Add new patch to provide a way to tell if the video is visible

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-08-26 06:02:03 -06:00
Simon Glass
f1d98d202e sandbox: Add a function to detect terminal connection
Add a serial_is_tty() function that determines if the serial console
is connected to a terminal. For sandbox, this uses os_isatty() to
check stdin, except for cooked mode, where we don't want to assume
anything about the terminal.

For other platforms, it always returns true.

Co-developed-by: Claude <noreply@anthropic.com>
Signed-off-by: Simon Glass <sjg@chromium.org>
2025-08-26 06:02:03 -06:00
Simon Glass
0d5c9d1529 serial: Cache the terminal size
Add serial_priv structure to serial uclass to cache terminal dimensions.
When serial_query_size() successfully queries the terminal, store the
results in the uclass-private data for later retrieval.

This avoids repeated terminal queries and improves performance when
different subsystems need the terminal size.

Series-changes: 3
- Drop unnecessary 'dev' argument

Co-developed-by: Claude <noreply@anthropic.com>
Signed-off-by: Simon Glass <sjg@chromium.org>
2025-08-26 06:02:03 -06:00
Simon Glass
8364e9af3e serial: Generalise the code to check the terminal size
The EFI loader has some code to check the size (rows and columns) of an
attached terminal. Move this over to the serial uclass so that it can be
used elsewhere.

Create a new CONFIG_SERIAL_TERM_PRESENT to control whether it should be
used. Enable that for the EFI loader to preserve existing behaviour.

Adjust the implementation so that it returns a useful error code on
failure. Put the ESC and cESC values in the serial.h header.

Series-changes: 3
- Update comment for serial_query_size()

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-08-26 06:01:53 -06:00
Simon Glass
38af9c7f97 video: Mark keyboards as driver model stdio devices
Set the DEV_FLAGS_DM flag so keybaords are 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
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
82732edd5a bdinfo: Show the serial device
Show the name of the serial device with the 'bdinfo' command.

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-08-25 06:54:00 -06:00
Simon Glass
03cd5e055b Merge branch 'loads' into 'master'
efi: Improvements to env print -e

See merge request u-boot/u-boot!161
2025-08-22 22:39:44 +00:00
Simon Glass
31bd3547bb cmd: Add -s flag to printenv -e for sorted output
Add support for sorting EFI variables by name when using printenv -e.
The -s flag sorts variables alphabetically before display, useful when
dealing with large numbers of variables.

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

Series-to: concept
Series-cc: heinrich
Cover-letter:
efi: Improvements to env print -e
Printing EFI variables can be quite verbose, with many hundreds of lines
of text. Part of this is because GUIDs and hex dumps are included. It
can also be hard to find a few variables visually in an unsorted list.

This series makes the feature more user-friendly:
- Puts verbose output behind a -v flag, so that 'env print -e' behaves
  more like 'env print'
- Adds a -s option to sort the list
END
Series-links: 1:15
2025-08-22 08:23:17 -06:00
Simon Glass
ba43199ce9 efi: nvedit: Place variables in an alist before printing them
Rather than printing as we go, add variables to an alist so they can be
printed when all variables are present.

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-08-22 08:23:17 -06:00
Simon Glass
ceb8cb140e efi: Refactor error handling in efi_dump_var_all()
Rather than freeing the variable in several places, put it at the end.
Assume failure by default, returning success only if all steps passed.

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-08-22 08:23:17 -06:00
Simon Glass
5247ae8219 efi: Rename var_name64 to name in efi_dump_var_all()
This variable name is quite long. There is only one 'name' (the variable
name) and it has to be u16 as it is an EFI variable. So rename it to
'name'.

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-08-22 08:23:17 -06:00
Simon Glass
b60fd4dae9 efi: Change env print -e to show only names by default
Change the default behavior of 'printenv -e' to show only EFI variable
names. The previous verbose output is now available with the -v flag.
This makes the command more user-friendly for quick variable listing.

Update documentation to reflect the new behavior and provide examples
of all three output modes: default (names only), -n (details without
hex dump), and -v (full verbose output).

It might be nicer to use -d to enable the dump, rather than have it on
by default.

Co-developed-by: Claude <noreply@anthropic.com>
Signed-off-by: Simon Glass <sjg@chromium.org>
2025-08-22 08:23:17 -06:00
Simon Glass
b6c3c5ec6a efi: Enable access to efi variables from the app
Enable the 'setenv -e' feature.

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-08-22 08:23:17 -06:00
Simon Glass
b0341ef417 efi: Move guid used for variables to common files
Move efi_guid_image_security_database to a common file so that it can be
used by the app.

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-08-22 08:23:17 -06:00
Simon Glass
a815f55022 Merge branch 'loadr' into 'master'
efi: app: Support booting an OS

See merge request u-boot/u-boot!160
2025-08-22 14:13:19 +00:00
Simon Glass
96d39714e4 test: efi: Add a test for the app booting Ubuntu via EFI
Now that the EFI app supports booting Ubuntu via the EFI bootmeth, add
a test for this, for ARM. This uses the sjg lab.

Series-to: concept
Series-cc: heinrich
Cover-letter:
efi: app: Support booting an OS
This series completes the work to get the EFI app booting an EFI
application (e.g. Ubuntu):

- efidebug dh now works, and is slightly enhanced
- device paths which refer to the underlying EFI layer can now be
  requested by the app
- a test is provided, for EFI on ARM booting into Ubuntu using the sjg
  lab
END

Signed-off-by: Simon Glass <sjg@chromium.org>
Series-links: 1:12
2025-08-20 10:07:17 -06:00
Simon Glass
2e0fab9f72 efi: app: Allow booting an EFI app
Enable booting an app from the U-Boot app, since many distros package
their bootloader as an EFI app.

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-08-20 10:07:17 -06:00