Commit Graph

319 Commits

Author SHA1 Message Date
Andrew Goodbody
eaba5aae8f sandbox: Correct guard around readq/writeq
In include/linux/io.h the declarations of ioread64 and iowrite64
which make use of readq/writeq are guarded with CONFIG_64BIT so
guard the sandbox declarations of readq and writeq also with
CONFIG_64BIT.

Reviewed-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Andrew Goodbody <andrew.goodbody@linaro.org>
(cherry picked from commit 99afa58e6d)
2025-12-24 05:17:05 -07:00
Simon Glass
d798b2e9ef sandbox: Move ulib_init_with_data() declaration to init.h
To avoid needing an #ifdef in the C code, move this sandbox-specific
declaration to the common init.h header.

Update ulib.c to include init.h to avoid warnings. Fix the ordering
while we are here.

Signed-off-by: Simon Glass <simon.glass@canonical.com>
2025-11-12 06:12:02 -07:00
Simon Glass
8751de0715 sandbox: mouse: Add test for pointer visibility
Add a test for the mouse set_ptr_visible() method. This uses a back-door
function to read the visibility state from the sandbox mouse driver.

Also add documentation for struct sandbox_mouse_priv.

Co-developed-by: Claude <noreply@anthropic.com>
Signed-off-by: Simon Glass <sjg@chromium.org>
2025-10-07 10:54:13 +00: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
f15ffe6f09 sandbox: Add a comment for sandbox_sdl_get_mouse_event()
This function was added without a comment. Fix it.

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
899722153f sandbox: Provide a test for the mouse uclass
Provide a few simple tests for two methods available in the mouse
uclass.

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-09-15 03:26:35 -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
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
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
9932bb407a sandbox: Move PCI EA space out of RAM
The address chosen for testing this feature is 1MB which is part of the
sandbox RAM. When devices access this, e.g. with map_sysmem(), the
memory is mapped to a PCI device. Any changes then apply to that device
and are not written to memory. Reads also come from the device.

It is not safe to use RAM space in this way.

A symptom that something is wrong is the log message:

   map_physmem: Warning: partial map at 100000, wanted 4, got 2000

Move the memory out of the way and document it.

Signed-off-by: Simon Glass <sjg@chromium.org>
Fixes: 21ebbafde8 ("test: dm: Add a test for PCI Enhanced Allocation")
2025-08-17 14:37:22 -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
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
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
Mikhail Kshevetskiy
6c785ecae5 test/cmd/wget: fix the test
Changes:
 * update to new tcp stack
 * fix zero values for ISS and IRS issue (see RFC 9293)

Signed-off-by: Mikhail Kshevetskiy <mikhail.kshevetskiy@iopsys.eu>
Reviewed-by: Simon Glass <sjg@chromium.org>
2025-05-16 17:58:51 +02: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
Heinrich Schuchardt
4a435ddf3d sandbox: remove linux/types.h dependency in setjmp.h
ulong is defined in linux/types.h use unsigned long instead.

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
ba34b61dcb sandbox: Enable PHYS_64BIT for 64-bit builds
Sandbox is special in that we use the bitness of the host. This should
extend to PHYS_64BIT as well, so enable this option when building on a
64-bit host.

Update the conditions in io.h so that 64-bit access is available.

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-05-02 09:02:53 -06:00
Simon Glass
ff5eb481d8 membuf: Rename struct
Rename the struct to match the function prefix and filenames.

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-02-25 16:39:30 -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
dc24948a45 sandbox: Fix comment for nomap_sysmem() function
This should say 'cast' rather than 'case', so fix it.

Signed-off-by: Simon Glass <sjg@chromium.org>
2024-11-03 21:27:13 -06: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
Tom Rini
0d28900dd1 Merge patch series "vbe: Series part D"
Simon Glass <sjg@chromium.org> says:

This includes various patches towards implementing the VBE abrec
bootmeth in U-Boot.
2024-10-03 11:52:42 -06:00
Simon Glass
99344c847d sandbox: Add missing header file
This file uses __aligned so should include the header which defines
that.

Signed-off-by: Simon Glass <sjg@chromium.org>
2024-10-03 11:52:16 -06:00
Tom Rini
c17805e19b Merge patch series "Fix various bugs"
Simon Glass <sjg@chromium.org> says:

This series includes the patches needed to make make the EFI 'boot' test
work. That test has now been split off into a separate series along with
the EFI patches.

This series fixes these problems:
- sandbox memory-mapping conflict with PCI
- the fix for that causes the mbr test to crash as it sets up pointers
  instead of addresses for its 'mmc' commands
- the mmc and read commands which cast addresses to pointers
- a tricky bug to do with USB keyboard and stdio
- a few other minor things
2024-09-18 13:07:19 -06:00
Simon Glass
f452e8f092 sandbox: Implement reference counting for address mapping
An address may be mapped twice and unmapped twice. Delete the mapping
only when the last user unmaps it.

Fix a missing comment while here.

Signed-off-by: Simon Glass <sjg@chromium.org>
2024-09-18 13:01:00 -06:00
Sughosh Ganu
727c4348d3 sandbox: iommu: remove lmb allocation in the driver
The sandbox iommu driver uses the LMB module to allocate a particular
range of memory for the device virtual address(DVA). This used to work
earlier since the LMB memory map was caller specific and not
global. But with the change to make the LMB allocations global and
persistent, adding this memory range has other side effects. On the
other hand, the sandbox iommu test expects to see this particular
value of the DVA. Use the DVA address directly, instead of mapping it
in the LMB memory map, and then have it allocated.

Signed-off-by: Sughosh Ganu <sughosh.ganu@linaro.org>
Reviewed-by: Simon Glass <sjg@chromium.org>
2024-09-03 14:08:50 -06:00
Simon Glass
91fde8e176 sandbox: Add an SPL loader for UPL
Add support for loading a UPL image from SPL. This uses the simple FIT
implementation, but also loads the full FIT just to permit more testing.

Signed-off-by: Simon Glass <sjg@chromium.org>
2024-08-09 16:03:20 -06:00
Simon Glass
dadd23ebab sandbox: Add a flag to enable UPL
UPL significantly alters the boot flow for sandbox. Add a flag to enable
this so that it can be enabled only on tests which need it.

Signed-off-by: Simon Glass <sjg@chromium.org>
2024-08-09 16:03:20 -06:00
Simon Glass
615d84b6ce test: Move some SPL-loading test-code into sandbox common
This code is useful for loading an image in sandbox_spl so move it into
a place where it can be called as needed.

Signed-off-by: Simon Glass <sjg@chromium.org>
2024-08-09 16:03:19 -06:00
Marek Vasut
2cd9466bed sandbox: Remove duplicate newlines
Drop all duplicate newlines. No functional change.

Signed-off-by: Marek Vasut <marek.vasut+renesas@mailbox.org>
2024-07-15 12:12:18 -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
6a7185887b global: Make <asm/global_data.h> include <asm/u-boot.h>
This follows the example of RISC-V where <asm/global_data.h> includes
<asm/u-boot.h> directly as "gd" includes a reference to bd_info already
and so the first must include the second anyhow. We then remove
<asm/u-boot.h> from all of the places which include references to "gd"
an so have <asm/global_data.h> already.

Signed-off-by: Tom Rini <trini@konsulko.com>
2024-05-06 15:07:48 -06:00
Sean Anderson
82719d3f40 clk: Remove rfree
Nothing uses this function. Remove it. Since clk_free no longer does
anything, just stub it out.

Signed-off-by: Sean Anderson <seanga2@gmail.com>
Link: https://lore.kernel.org/r/20231216193843.2463779-2-seanga2@gmail.com
2024-01-29 22:35:02 -05:00
Simon Glass
a8efebe719 acpi: Write pointers to tables instead of addresses
Sandbox uses an API to map between addresses and pointers. This allows
it to have (emulated) memory at zero and avoid arch-specific addressing
details. It also allows memory-mapped peripherals to work.

As an example, on many machines sandbox maps address 100 to pointer
value 10000000.

However this is not correct for ACPI, if sandbox starts another program
(e.g EFI app) and passes it the tables. That app has no knowledge of
sandbox's address mapping. So to make this work we want to store
10000000 as the value in the table.

Add two new 'nomap' functions which clearly make this exeption to how
sandbox works.

This should allow EFI apps to access ACPI tables with sandbox, e.g. for
testing purposes.

Signed-off-by: Simon Glass <sjg@chromium.org>
Suggested-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
2024-01-07 13:45:07 -07:00
Tom Rini
9d7f634811 sandbox: Add <linux/types.h> to asm/global_data.h and asm/io.h
We need <linux/types.h> in these files as we reference Linux types.

Reviewed-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Tom Rini <trini@konsulko.com>
2023-12-21 08:54:37 -05:00