Commit Graph

388 Commits

Author SHA1 Message Date
Simon Glass
84a64607a3 sandbox: Add --quiet_vidconsole option to speed up output
When running sandbox with lots of console output, the vidconsole slows
things down significantly since it renders truetype fonts to the
internal framebuffer. Add a -Q/--quiet_vidconsole command-line option
that removes vidconsole from stdout and stderr, using only the serial
console.

This can provide a ~300x speedup for output-heavy operations.

Co-developed-by: Claude Opus 4.5 <noreply@anthropic.com>
Signed-off-by: Simon Glass <simon.glass@canonical.com>
2026-01-01 14:27:12 -07:00
Simon Glass
ad7d1ec164 sandbox: os: Check executable directory for persistent files
When os_persistent_file() is called without a directory set in the
environment variable and the file isn't found in the current directory,
also check in the executable's directory.

This allows tests like dm_test_host to work when run directly from the
build directory rather than through the pytest framework, avoiding the
need to set U_BOOT_PERSISTENT_DATA_DIR manually.

Co-developed-by: Claude Opus 4.5 <noreply@anthropic.com>
Signed-off-by: Simon Glass <simon.glass@canonical.com>
2026-01-01 14:27:12 -07:00
Simon Glass
a3b60a2094 test: Add support for passing arguments to C tests
Add support for passing key=value arguments to unit tests. The test
framework parses arguments based on definitions provided by each test
and makes them available via uts->args[]

For now the 'ut' command does not support this new feature.

Co-developed-by: Claude Opus 4.5 <noreply@anthropic.com>
Signed-off-by: Simon Glass <simon.glass@canonical.com>
2025-12-14 09:14:34 -07:00
Simon Glass
e1e95b2887 backtrace: Use a static buffer in backtrace_ctx for symbols
Replace the dynamic allocation in os_backtrace_symbols() with a static
buffer embedded in struct backtrace_ctx. This avoids malloc recursion
when backtrace is called from within dlmalloc (e.g., for the upcoming
mcheck caller-tracking).

The API gets a complete rework as part of this:

- Combine addrs[] and syms[] arrays into struct backtrace_frame with
  addr and sym fields
- Store the strings in a unified buffer, with pointers from an array
- Change os_backtrace_symbols() to take ctx pointer and fill sym_buf
- Remove os_backtrace_symbols_free() as nothing needs freeing
- Rename BACKTRACE_MAX to BACKTRACE_MAX_FRAMES

Co-developed-by: Claude <noreply@anthropic.com>
Signed-off-by: Simon Glass <simon.glass@canonical.com>
2025-12-10 05:53:03 -07:00
Simon Glass
d5e3d066c7 backtrace: sandbox: Add support for obtaining symbols
Add backtrace functions for sandbox, including:

- os_backtrace() to collect addresses into a caller-supplied buffer
- os_backtrace_symbols() to convert addresses to symbol strings
- os_backtrace_symbols_free() to free the symbol array

The libbacktrace library (bundled with GCC) reads DWARF debug information
to provide detailed symbol resolution including function names (even for
static functions), source file paths, and line numbers.

The sandbox backtrace implementation wraps these OS functions to implement
the generic backtrace API (backtrace_init, backtrace_get_syms, etc.).

Enable it for just the 'sandbox' board. Add the library for the Rust
example too.

Co-developed-by: Claude <noreply@anthropic.com>
Signed-off-by: Simon Glass <simon.glass@canonical.com>
2025-12-01 15:42:04 +00:00
Simon Glass
db0f44ec8e sandbox: Add TTY configuration for TKey serial communication
Add os_tty_set_params() function to configure terminal devices for
serial communication with TKey devices:

  - Custom baud rate of 62500 using termios2
  - 8n1 configuration (8 data bits, no parity, 1 stop bit)
  - Raw mode for binary communication
  - Appropriate timeouts for frame-based protocols

This is needed for serial-based TKey communication on sandbox, allowing
U-Boot to communicate with TKey security tokens via a serial port.

Co-developed-by: Claude <noreply@anthropic.com>
Signed-off-by: Simon Glass <sjg@chromium.org>
2025-10-19 12:27:49 +01:00
Simon Glass
03c65c2b94 mouse: Replace press_state with bool pressed
Change the mouse_button structure to use a bool pressed field instead
of an unsigned char press_state. This simplifies the API by using a
natural boolean type for a binary state.

Remove the BUTTON_PRESSED/BUTTON_RELEASED defines as they're no longer
needed.

Update all mouse drivers, tests, and the mouse command to use the new
field name and type.

Series-changes: 2
- Add new patch to replace press_state with bool pressed

Co-developed-by: Claude <noreply@anthropic.com>
Signed-off-by: Simon Glass <sjg@chromium.org>
2025-10-07 09:54:43 -06:00
Simon Glass
53aad73a6b sandbox: mouse: Implement set_ptr_visible()
Implement this new method using the SDL layer.

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-10-07 10:54:13 +00:00
Simon Glass
4a7ccfee27 video: sandbox: Add test for sync() damage rectangle
Add a test that verifies the sandbox SDL driver receives the correct
damage rectangle in its sync() method. The test:

- Clears the display and verifies full-screen damage is passed to sync()
- Writes text at a specific position and verifies smaller damage region
- Draws a box and verifies the damage matches the box dimensions

The damage rectangle is recorded in sandbox_sdl_plat.last_sync_damage
and can be retrieved using sandbox_sdl_get_sync_damage() for testing
purposes.

Series-to: concept
Series-cc: heinrich
Cover-letter:
video: Enhancements to support a pointer
The video subsystem has a video_sync() function which does quite a few
things and is rather hard to predict and control:

- it may or may not actually sync, depending on a timer, etc
- it may be called when U-Boot is idle, so any time delays can cause a
  sync

These two problems make it hard to test.

This series introduces a deterministic video_manual_sync() which does
exactly what it is told, using a set of flags:

   VIDSYNC_FORCE - the force flag was provided (info for the driver)
   VIDSYNC_FLUSH - framebuffer changes should be flushed to hardware
   VIDSYNC_COPY - the copy framebuffer (if any) should be updated

The video_sync() method is renamed to sync() and is passed the flags,
so that drivers can find out what to do. This allows the
sandbox-specific code in video_sync() to move to the driver.

These features will (later) be used by expo to provide a better user
experience, e.g. to sync only part of the display, or to sync quickly
when there is mouse movement.

The pointer also needs to be drawn with transparency which is not well
supported by the BMP code. This series adds support for a simple
transparency colour for now, although an alpha channel may be
appropriate in the future.
END

Co-developed-by: Claude <noreply@anthropic.com>
Signed-off-by: Simon Glass <sjg@chromium.org>
Series-links: 1:45
Series-version: 2
2025-10-06 06:29:29 -06:00
Simon Glass
0902eb2bfb video: sandbox: Add sync() method for video
At present, video_sync() has a special case for sandbox. Remove this and
add a sync() method in the sandbox_sdl driver instead.

The sync() method checks the VIDSYNC_FLUSH flag and skips sync operation
if it's not set, avoiding unnecessary SDL updates.

If CONFIG_VIDEO_DAMAGE is enabled, the SDL portion accepts an optional
damage rectangle parameter to support only updating the damaged region.

Use the struct video_bbox definition from the video_defs.h header as
this avoids trying to include too many U-Boot headers in code that is
build with system headers.

Co-developed-by: Claude <noreply@anthropic.com>
Signed-off-by: Simon Glass <sjg@chromium.org>
2025-10-06 06:29:29 -06:00
Simon Glass
878057090f video: sandbox: Optimise drawing based on damage
Update sandbox_sdl_sync() to accept an optional damage rectangle and
update only the damaged region. This should reduce the amount of work
performed by the driver when only a small part of the display needs to
be updated.

Series-changes: 2
- Update to use struct vid_bbox

Co-developed-by: Claude <noreply@anthropic.com>
Signed-off-by: Simon Glass <sjg@chromium.org>
2025-10-06 06:29:29 -06:00
Simon Glass
6853b7d8ad sandbox: Add --video_frames option to capture test frames
Add a new --video_frames option to sandbox which accepts a directory path.
When set, every video test assertion writes a BMP file (frame0.bmp,
frame1.bmp, etc.) to the specified directory, allowing visual inspection
of the framebuffer at each test step.

A new video_write_bmp() function writes 16/32bpp framebuffer contents as
Windows BMP files. On startup, any existing frame*.bmp files in the
directory are removed to ensure a clean state.

Usage example:

  ./u-boot --video_frames /tmp/frames -c "ut dm video_text"

Co-developed-by: Claude <noreply@anthropic.com>
Signed-off-by: Simon Glass <sjg@chromium.org>
2025-10-06 06:29:29 -06:00
Simon Glass
12572f5a00 sandbox: Add -V flag for video test delay
Add a new -V flag to sandbox which accepts a delay in milliseconds. This
causes video tests to pause after each assertion, allowing the display
output to be visually inspected.

This is useful for debugging video tests and understanding what is being
drawn at each step.

Co-developed-by: Claude <noreply@anthropic.com>
Signed-off-by: Simon Glass <sjg@chromium.org>
2025-10-06 06:29:29 -06:00
Simon Glass
ebdefefba5 sandbox: sdl: Add support for mouse input
Allow mouse input to be reported from sandbox using SDL.

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-09-15 03:23:22 -06:00
Simon Glass
2f8c113cfc sandbox: Add a way to set the window title
Add a new option to set the window title for U-Boot sandbox. This is
helpful when different sandbox instances are used for different purposes
at the same time.

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-09-14 15:51:09 -06:00
Simon Glass
a5fc8d6989 ulib: Use the correct copyright message
Canonical should be written with the 'Ltd.' suffix, so add this to a few
files that need it.

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-09-08 13:09:58 -06:00
Simon Glass
9bdbea4092 ulib: Provide a test program for the static library
Create a static version of the library test. This requires a linker
script, since the linker lists much be correctly placed within the final
executable.

Provide a linker script for the sandbox version.

Add both test files to the clean target.

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-09-05 12:51:05 -06:00
Simon Glass
43d2f41234 ulib: Provide an init function for sandbox
Provide a simple function to set up the library, to avoid having to
worry about the details. This requires the caller to know about
global_data

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-09-05 12:51:05 -06:00
Simon Glass
7735072d66 sandbox: Add a function to read a line from a file
Provide a version of fgets() which works on file descriptors. This can
be used to read lines from a file, as will be needed for the ulib
test-program.

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-09-05 12:51:05 -06:00
Simon Glass
972b0b812b ulib: Add linker script for shared library build
Add a proper linker script (u-boot-lib.lds) for building libu-boot.so to
ensure correct section alignment and placement, particularly for the
linker lists.

Co-developed-by: Claude <noreply@anthropic.com>
Signed-off-by: Simon Glass <sjg@chromium.org>
2025-09-04 14:23:55 -06:00
Simon Glass
0725962096 sandbox: Extract init code into sandbox_init()
Split the init code from sandbox_main() into a separate sandbox_init()
function that handles all setup up to the call to board_init_f(). This
allows the init to be called independently of the main execution flow.

Co-developed-by: Claude <noreply@anthropic.com>
Signed-off-by: Simon Glass <sjg@chromium.org>
2025-09-04 14:23:55 -06:00
Simon Glass
4fe2bec2ea sandbox: Split main() into separate file
Normally sandbox includes a main() function so that it can be started
correctly.

When fuzzing is enabled, main() is not required.

When sandbox is built as a library, the main program will be somewhere
else so must not be in the library.

Split the main() function out into a new main.c file. Split the fuzzing
code into a new fuzz.c file.

Co-developed-by: Claude <noreply@anthropic.com>
Signed-off-by: Simon Glass <sjg@chromium.org>
2025-09-04 14:23:55 -06:00
Simon Glass
4ccad024ca sandbox: Move main.h contents into u-boot-sandbox header
It isn't really necessary to have a header file for just one function.
This makes it harder to see the full interface provided by sandbox.

Move the sandbox_main() declaration into u-boot-sandbox.h

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-09-04 14:23:55 -06:00
Simon Glass
1c0ee7d1b2 sandbox: Move PCI functions to separate header file
Move pci_map_physmem(), pci_unmap_physmem(), and
sandbox_set_enable_pci_map() from u-boot-sandbox.h to a new file
sandbox_pci.h to simplify dependencies.

Fix the header order in the PCI emul file while we are here.

Co-developed-by: Claude <noreply@anthropic.com>
Signed-off-by: Simon Glass <sjg@chromium.org>
2025-09-04 14:23:55 -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
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
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
0d523d8d55 sandbox: Abort if a partition memory map is detected
This can indicate that something is horribly wrong. It seems better to
abort, rather than just print a message which might not be noticed.

If the mapping does not map exactly, abort.

Series-to: concept
Cover-letter:
sandbox: Fix memory corruption around 1MB
After many hours of debugging, it turns out that the PCI EA driver is
mapping itself into RAM at 1MB. This happens to be where the kernel
ends up, with the vbe_abrec_os bootmeth. Since measurement is enabled,
bootm_measure() calls map_sysmem() on the kernel in order to measure it.

easurement takes place, although of course using the wrong data. Then,
through a strange sequence of events, which I have found very hard to
narrow down, the malloc() heap is corrupted.

This series provides a fix.

To repeat this problem:

  NO_LTO=1 ./test/py/test.py --bd sandbox --build -k
     "(ut or vbe) and not efi and not slow and not dm"

which dies when running vbe_test_abrec_oem_norun:

   ...
   => echo $?
   0
   => host bind 0 [...]/build-sandbox/persistent-data/vbe1.img
   => ut -f bootstd vbe_test_abrec_oem_norun
   Test: bootstd_setup_for_tests: bootstd_common.c
   common/dlmalloc.c:793: do_check_free_chunk:
      Assertion `next->prev_size == sz' failed.
   resetting ...

With this series, the above now passes.
END
Signed-off-by: Simon Glass <sjg@chromium.org>
2025-08-17 14:37:25 -06:00
Simon Glass
dcfec7fd37 sandbox: Swap the wanted and got messages in map_physmem()
The ordering is reversed. Fix it, to avoid confusion.

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-08-17 14:37:22 -06:00
Simon Glass
3b8ed0cebb sandbox: Adjust how OS-interface files are built
The current mechanism uses a completely separate build rule for each
file which must be built with system headers.

Before adding any more files, adjust the scheme so that the flags are
handled in the common Makefile, with sandbox simply listing the files
affected.

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-07-23 20:19:42 -06:00
Simon Glass
dbe7b5ae23 spl: Finish rename of jump_to_image_no_args()
Some uses of this weak function were missed. Fix them.

Signed-off-by: Simon Glass <sjg@chromium.org>
Fixes: e2670b665d
2025-07-17 18:30:01 -06:00
Simon Glass
7482087639 bootm: Move cleanup_before_linux() to bootm.h
Move the declaration of this function to a common header. Make sure it
is included by files which define it.

Fix up a few whitespace problems while here.

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-07-12 16:18:34 -06:00
Simon Glass
dd58526971 fs: Add a sandbox test for the directory uclass
Create a test which looks for a file and a directory in the U-Boot
source tree.

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-06-28 12:30:56 -06:00
Simon Glass
ddaa12e605 sandbox: Update os_open() to return an error code
It is convenient to be able to report the system error when available.
Update os_open() to return it.

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-06-28 07:53:25 -06:00
Simon Glass
f09acc02f2 sandbox: Support memory-mapped I/O
Add a way for calls to readl()/writel() etc. to be picked up by a driver
in order to implement MMIO.

This works by registering some functions, which are then called when
accesses occur.

Add comments to sandbox_read() and sandbox_write() while we are here.

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-06-27 20:55:01 -06:00
Simon Glass
0807f9a068 sandbox: Move memory-related functions to a separate file
Add a new mem.c file and move memory-related functions to it.

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-06-27 20:55:01 -06:00
Simon Glass
b11c37615c sandbox: Provide a cmdline flag to bind disk images
Normally it is possible to bind disk images using the 'host bind'
command. But when CONFIG_CMDLINE is not enabled, this is not possible.

Add a -B flag to provide equivalent functionality.

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-06-05 14:42:46 -06:00
Simon Glass
e2670b665d spl: Rename jump_to_image_no_args()
This is about to become a misnomer since with standard passage we need to
pass arguments to U-Boot. Rename the function.

Also rename the local variable to 'jumper' to avoid a conflict.

Series-changes: 2
- Split the jump_to_image_no_args() change into its own patch

Signed-off-by: Simon Glass <sjg@chromium.org>
Change-Id: Ieb1fd7a5478ba1dfe3a58666ed586e83b0641590
2025-05-29 17:21:36 +01:00
Heinrich Schuchardt
24fa04ebac common: clean up setjmp.h
Separate setjmp.h into an architecture independent part and an architecture
specific part. This simplifies moving from using struct jmp_buf_data
directly to using type jmp_buf in our code which is the C compliant way.

Reviewed-by: Jerome Forissier <jerome.forissier@linaro.org>
Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
2025-05-16 14:45:25 +02:00
Simon Glass
dcdba01518 sandbox: Provide an option to continue on failure
Normally the first failed assertion causes the test to stop. Provide a
flag to allow the test to continue, as a means to discover other
problems later in the test.

Note that the utility of this depends on the test, since some tests will
be broken if any step fails. But this can be useful when there are lots
of test adjustments to make.

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-05-02 09:45:32 -06:00
Simon Glass
d6ef1f6220 sandbox: Provide an option to skip flattree tests
When OF_LIVE is enabled, sandbox runs tests with that and with flattree.
When debugging tests, this is often just a distraction.

Provide a -F option to skip the flattree tests in this case.

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-05-02 09:45:32 -06:00
Simon Glass
f86e5ab18d test: Move stat-printing into its own function
Add a function to show the stats, so we can decide when to print it.

This slightly adjusts the output, so that any 'test not found' message
appears on its own line after all other output.

The 'failures' message now appears in lower case so update pytest
accordingly.

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-02-08 13:50:15 +00:00
Simon Glass
28efb7316c test: Pass the test-state into ut_run_list()
Pass this into the function so that callers can inspect the state
afterwards.

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-02-08 13:50:15 +00:00
Simon Glass
43104a2100 fdt: Swap the signature for board_fdt_blob_setup()
This returns a devicetree and updates a parameter with an error code.
Swap it, since this fits better with the way U-Boot normally works. It
also (more easily) allows leaving the existing pointer unchanged.

No yaks were harmed in this change, but there is a very small code-size
reduction.

For sifive, the OF_BOARD option must be set for the function to be
called, so there is no point in checking it again. Also OF_SEPARATE is
defined always.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Matthias Brugger <mbrugger@suse.com>
Reviewed-by: Patrice Chotard <patrice.chotard@foss.st.com>
2024-12-17 17:30:25 -07:00
Simon Glass
2ea15e57a0 sandbox: efi_loader: Correct use of addresses as pointers
The cache-flush function is incorrect which causes a crash in the
remoteproc tests with arm64.

Fix both problems by using map_sysmem() to convert an address to a
pointer and map_to_sysmem() to convert a pointer to an address.

Also update the image-loader's cache-flushing logic.

Signed-off-by: Simon Glass <sjg@chromium.org>
Fixes: 3286d223fd ("sandbox: implement invalidate_icache_all()")
Acked-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

Changes in v6:
- Re-introduce

Changes in v2:
- Drop message about EFI_LOADER

 arch/sandbox/cpu/cache.c              |  8 +++++++-
 drivers/remoteproc/rproc-elf-loader.c | 18 +++++++++++-------
 lib/efi_loader/efi_image_loader.c     |  3 ++-
 3 files changed, 20 insertions(+), 9 deletions(-)
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
2024-12-17 06:53:19 -07:00
Simon Glass
efe9bd4a08 sandbox: Add a -N flag to control on-host behaviour
Sandbox is its own architecture, but sometimes we want to mimic the host
architecture, e.g. when running an EFI app not built by U-Boot.

Add a -N/--native flag which tells sandbox to reflect the architecture
of the host.

Signed-off-by: Simon Glass <sjg@chromium.org>
2024-11-09 10:00:15 +01:00
Simon Glass
5400c4bc05 sandbox: Add a way to show the sandbox memory-mapping
This is mostly hidden in the background, but it is sometimes useful to
look at it. Add a function to allow this.

Signed-off-by: Simon Glass <sjg@chromium.org>
2024-11-03 21:27:12 -06:00
Simon Glass
58918fa4f0 sandbox_spl: Restrict use of UPL when not enabled
With sandbox_spl we want to use the file-based boot in CI, so that this
flow is tested. The recent UPL change enabled booting via that method,
thus overriding the file-based boot.

Correct this by using UPL only when the --upl flag is given.

Signed-off-by: Simon Glass <sjg@chromium.org>
Fixes: 91fde8e176 ("sandbox: Add an SPL loader for UPL")
2024-10-18 14:10:22 -06:00
Simon Glass
bef9fdbed2 arch: Use CONFIG_XPL_BUILD instead of CONFIG_SPL_BUILD
Use the new symbol to refer to any 'SPL' build, including TPL and VPL

Signed-off-by: Simon Glass <sjg@chromium.org>
2024-10-11 11:44:47 -06:00