History log of /u-boot/arch/sandbox/cpu/state.c
Revision Date Author Comments
(<<< Hide modified files)
(Show modified files >>>)
# 460b2c06 14-Dec-2023 Tom Rini <trini@konsulko.com>

sandbox: Audit config.h and common.h usage

Remove and replace common.h and config.h in sandbox when it's not needed
and add some explicit includes where needed.

Reviewed-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Tom Rini <trini@konsulko.com>

# 97192937 26-Sep-2023 Simon Glass <sjg@chromium.org>

sandbox: Only read the state if we have a state file

We should not read this unless requested. Make it conditional on the
option being provided.

Add some debugging to show the state being written.

Signed-off-by: Simon Glass <sjg@chromium.org>

# d02c6f57 26-Sep-2023 Simon Glass <sjg@chromium.org>

sandbox: Move reading the RAM buffer into a better place

This should not happen in the argument-parsing function. Move it to the
main program.

Add some debugging for reading/writing.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 763f0a1f 12-Apr-2023 Pavel Skripkin <paskripkin@gmail.com>

sandbox: disable tracing before unmapping RAM

Currently doing 'reset' command in sandbox with tracing enabled causes
SIGSEV

```
Hit any key to stop autoboot: 0
=>
=>
=> reset
resetting ...
Segmentation fault (core dumped)

```

Tracing callback uses RAM buffer for storing tracing reports, but
state_uninit() function unmaps whole RAM, which causes SIGSEV on umapped
memory inside tracing subsystem.

Fix it by disabling tracing before unmapping memory

Signed-off-by: Pavel Skripkin <paskripkin@gmail.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Add missing check for CONFIG_TRACE:
Signed-off-by: Simon Glass <sjg@chromium.org>

# 081bdc52 17-Jan-2023 Simon Glass <sjg@chromium.org>

sandbox: Allow SPI flash bootdevs to be disabled for tests

Most tests don't want these and they can create a lot of noise. Add a way
to disable them. Use that in tests, with a flag provided to enable them
for tests that need this feature.

Signed-off-by: Simon Glass <sjg@chromium.org>

# f43b2df3 17-Jan-2023 Simon Glass <sjg@chromium.org>

sandbox: Allow ethernet to be disabled at runtime

For bootstd tests it is seldom useful to have ethernet enabled. Add a way
to disable it, so that ethernet operations like tftpboot do nothing.

Signed-off-by: Simon Glass <sjg@chromium.org>

# aa6e94de 16-Nov-2022 Tom Rini <trini@konsulko.com>

global: Move remaining CONFIG_SYS_SDRAM_* to CFG_SYS_SDRAM_*

The rest of the unmigrated CONFIG symbols in the CONFIG_SYS_SDRAM
namespace do not easily transition to Kconfig. In many cases they likely
should come from the device tree instead. Move these out of CONFIG
namespace and in to CFG namespace.

Signed-off-by: Tom Rini <trini@konsulko.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 0b5c9b03 20-Oct-2022 Simon Glass <sjg@chromium.org>

sandbox: Drop message about writing sandbox state

This happens every time sandbox moves to the next phase so is not very
interesting. Display the message only when debugging.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 9859d89b 06-Sep-2022 Simon Glass <sjg@chromium.org>

sandbox: Support loading the other FDT

We need an 'other' FDT which is different from the control FDT, so we can
check that the ofnode tests correctly handle them both.

Add this to the build along with a way to read it into the sandbox state.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 73c5cb9d 06-Sep-2022 Simon Glass <sjg@chromium.org>

sandbox: Add a function to load a relative file path

At present this implementation is specific to loading the test FDT. We
plan to load others, so create a generic function to handle this.

The path is now limited to 256 characters, to simplify the code.

When there is an empty argv[0] (which should not happen), the function now
just uses the path as is, with no prefix.

Signed-off-by: Simon Glass <sjg@chromium.org>

# d02f99dd 28-Feb-2022 Simon Glass <sjg@chromium.org>

sandbox: Show a message when writing out the ram buffer

If state is not being written, but RAM is, we should still show a message,
so it is clear that this is happening.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 185f812c 19-Jan-2022 Heinrich Schuchardt <xypron.glpk@gmx.de>

doc: replace @return by Return:

Sphinx expects Return: and not @return to indicate a return value.

find . -name '*.c' -exec \
sed -i 's/^\(\s\)\*\(\s*\)@return\(\s\)/\1*\2Return:\3/' {} \;

find . -name '*.h' -exec \
sed -i 's/^\(\s\)\*\(\s*\)@return\(\s\)/\1*\2Return:\3/' {} \;

Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>

# cb897009 24-Jul-2021 Simon Glass <sjg@chromium.org>

sandbox: Reduce keyed autoboot delay

The autoboot tests are a recent addition to U-Boot, providing much-needed
coverage in this area.

A side effect of the keyed autoboot test is that this feature is enabled
in sandbox always. This changes the autoboot prompt and confuses the
pytests. Some tests become slower, for example the vboot tests take about
27s now instead of 3s.

We don't actually need this feature enabled to be able to run the tests.
Add a switch to allow sandbox to turn it on and off as needed. Use this
in the one test that needs it.

Add a command-line flag in case this is desired in normal use.

Signed-off-by: Simon Glass <sjg@chromium.org>
Fixes: 25c8b9f298e ("test: add first autoboot unit tests")
Reviewed-by: Steffen Jaeckel <jaeckel-floss@eyet-services.de>

# 9a72bea6 13-May-2021 Simon Glass <sjg@chromium.org>

sandbox: Silence coverity warning in state_read_file()

In this case the value seems save to pass to os_free(). Add a comment.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reported-by: Coverity (CID: 165109)

# 1c52fcca 06-Feb-2021 Simon Glass <sjg@chromium.org>

sandbox: Write out bloblist when exiting

Sandbox provides a way to write out its emulated memory on exit. This
makes it possible to pass a bloblist from one phase (e.g. SPL) to the
next.

However the bloblist is not closed off, so the checksum is generally
invalid. Fix this by finishing up the bloblist before writing the memory
file.

Signed-off-by: Simon Glass <sjg@chromium.org>

# b308d9fd 06-Feb-2021 Simon Glass <sjg@chromium.org>

sandbox: Avoid using malloc() for system state

This state is not accessible to the running U-Boot but at present it is
allocated in the emulated SDRAM. This doesn't seem very useful. Adjust
it to allocate from the OS instead.

The RAM buffer is currently not freed, but should be, so add that into
state_uninit(). Update the comment for os_free() to indicate that NULL is
a valid parameter value.

Note that the strdup() in spl_board_load_image() is changed as well, since
strdup() allocates memory in the RAM buffer.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 10bb90fa 20-Nov-2020 Patrick Delaunay <patrick.delaunay@foss.st.com>

sandbox: remove ram buffer file when U-Boot is loaded by SPL

Update management of "--rm_memory" sandbox's option and force
this option when U-Boot is loaded by SPL in os_spl_to_uboot()
and remove the ram file after reading in main() as described
in option help message: "Remove memory file after reading".

This patch avoids that the file "/tmp/u-boot.mem.XXXXXX" [created in
os_jump_to_file() when U-Boot is loaded by SPL] is never deleted
because state_uninit() is not called after U-Boot execution
(CtrlC or with running pytest for example).

This issue is reproduced by
> build-sandbox_spl/spl/u-boot-spl
and CtrlC in U-Bot console

> make qcheck

One temp file is created after each SPL and U-Boot execution
(7 tims in qcheck after test_handoff.py, test_ofplatdata.py,
test_spl.py execution).

Signed-off-by: Patrick Delaunay <patrick.delaunay@st.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 329dccc0 27-Oct-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

sandbox: implement reset

Up to now the sandbox would shutdown upon a cold reset request. Instead it
should be reset.

In our coding we use static variables like LIST_HEAD(efi_obj_list). A reset
can occur at any time, e.g. via an UEFI binary calling the reset service.
The only safe way to return to an initial state is to relaunch the U-Boot
binary.

The reset implementation uses execv() to relaunch U-Boot.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Simon Glass <sjg@chromium.org>

# c7e49ddc 04-Jun-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

sandbox: handling out of memory

assert() only works in debug mode. So checking a successful memory
allocation should not use assert().

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Simon Glass <sjg@chromium.org>

# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 3ff6fe5f 03-Feb-2020 Simon Glass <sjg@chromium.org>

sandbox: Add a new header for the system malloc()

Some files use U-Boot headers but still need to access the system
malloc(). Allow this by creating a new asm/malloc.h which can be used so
long as U-Boot's malloc.h has not been included.

Signed-off-by: Simon Glass <sjg@chromium.org>

# cf23c7c1 03-Feb-2020 Simon Glass <sjg@chromium.org>

sandbox: Rename 'free' variable

This name conflicts with our desire to #define free() to something else on
sandbox. Rename it.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 89694de5 06-Dec-2019 Simon Glass <sjg@chromium.org>

sandbox: Disable mmio by default in tests

When reseting sandbox for tests, disable mmio support since that is the
default state.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>

# 857f39d7 16-May-2019 Urja Rannikko <urjaman@gmail.com>

sysreset: switch to using SYSRESET_POWER_OFF for poweroff

It seems that SYSRESET_POWER_OFF was added recently, and all previous code
used SYSRESET_POWER for poweroff. SYSRESET_POWER is supposed to be a
PMIC-level power cycle, not a poweroff.

(Comment by Simon Glass)
SYSRESET_POWER means to do a power reset (removing and reinstating all power)
SYSRESET_POWER_OFF means to turn the device off and leave it off

Signed-off-by: Urja Rannikko <urjaman@gmail.com>
Reviewed-by: Patrick Delaunay <patrick.delaunay@st.com>
(Update comment to help understand the patch)
Signed-off-by: Kever Yang <kever.yang@rock-chips.com>

# 9072326a 18-May-2019 Simon Glass <sjg@chromium.org>

sandbox: Exit when SYSRESET_POWER_OFF is requested

At present this returns but it seems better to just exit sandbox
immediately.

Signed-off-by: Simon Glass <sjg@chromium.org>

reset

# 1c5a81d8 01-Oct-2018 Simon Glass <sjg@chromium.org>

sandbox: Remove the old memory file later

When debugging sandbox it is sometimes annoying that the memory file is
deleted early on. If sandbox later crashes or we quit (using the
debugger), it is not possible to run it again with the same state since
the memory file is gone.

Remove the old memory file when sandbox exits, instead. Also add debugging
showing the memory filename.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 428aa0ca 15-Sep-2018 Simon Glass <sjg@chromium.org>

sandbox: Enhance map_to_sysmem() to handle foreign pointers

At present map_sysmem() maps an address into the sandbox RAM buffer,
return a pointer, while map_to_sysmem() goes the other way.

The mapping is currently just 1:1 since a case was not found where a more
flexible mapping was needed. PCI does have a separate and more complex
mapping, but uses its own mechanism.

However this arrange cannot handle one important case, which is where a
test declares a stack variable and passes a pointer to it into a U-Boot
function which uses map_to_sysmem() to turn it into a address. Since the
pointer is not inside emulated DRAM, this will fail.

Add a mapping feature which can handle any such pointer, mapping it to a
simple tag value which can be passed around in U-Boot as an address.

Signed-off-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Alexander Graf <agraf@suse.de>

# 83d290c5 06-May-2018 Tom Rini <trini@konsulko.com>

SPDX: Convert all of our single license tags to Linux Kernel style

When U-Boot started using SPDX tags we were among the early adopters and
there weren't a lot of other examples to borrow from. So we picked the
area of the file that usually had a full license text and replaced it
with an appropriate SPDX-License-Identifier: entry. Since then, the
Linux Kernel has adopted SPDX tags and they place it as the very first
line in a file (except where shebangs are used, then it's second line)
and with slightly different comment styles than us.

In part due to community overlap, in part due to better tag visibility
and in part for other minor reasons, switch over to that style.

This commit changes all instances where we have a single declared
license in the tag as both the before and after are identical in tag
contents. There's also a few places where I found we did not have a tag
and have introduced one.

Signed-off-by: Tom Rini <trini@konsulko.com>

# 9095d5b8 13-Feb-2018 Simon Goldschmidt <sgoldschmidt@de.pepperl-fuchs.com>

fix spelling of 'functions' in 2 places (was 'funtcions')

Signed-off-by: Simon Goldschmidt <sgoldschmidt@de.pepperl-fuchs.com>

# 34b744be 18-May-2017 Simon Glass <sjg@chromium.org>

sandbox: Add a way to reset sandbox state for tests

Running a new test should reset the sandbox state to avoid tests
interferring with each other. Move the existing state-reset code into a
function so it can be used from tests.

Also update the code to reset the SPI devices and adjust the test code to
call it.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 11636258 12-May-2016 Stephen Warren <swarren@nvidia.com>

Rename reset to sysreset

The current reset API implements a method to reset the entire system.
In the near future, I'd like to introduce code that implements the device
tree reset bindings; i.e. the equivalent of the Linux kernel's reset API.
This controls resets to individual HW blocks or external chips with reset
signals. It doesn't make sense to merge the two APIs into one since they
have different semantic purposes. Resolve the naming conflict by renaming
the existing reset API to sysreset instead, so the new reset API can be
called just reset.

Signed-off-by: Stephen Warren <swarren@nvidia.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 9723563a 08-Nov-2015 Simon Glass <sjg@chromium.org>

sandbox: Add a way to skip time delays

Some tests are slow due to delays which are unnecessary on sandbox. The
worst offender is USB where we lose two seconds. Add a way to disable time
delays.

Signed-off-by: Simon Glass <sjg@chromium.org>

# dc6f4d3a 06-Jul-2015 Simon Glass <sjg@chromium.org>

sandbox: Support multiple reset types

Add settings for the last reset generated, and the types of resets which
are permitted. This will be used for testing.

Signed-off-by: Simon Glass <sjg@chromium.org>

# d73125cb 04-May-2015 Simon Glass <sjg@chromium.org>

sandbox: Correct error handling in state_read_file()

This function should return a useful error for U-Boot, rather than -1.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Joe Hershberger <joe.hershberger@ni.com>

# 88539e44 06-Feb-2015 Joe Hershberger <joe.hershberger@ni.com>

sandbox: Return '-c command' exit value as sandbox exit code

When a command is passed into sandbox using the '-c' argument the
command is run directly. This is most helpful when running tests (such
as test-dm.sh). Previously the exit code was an unused enum. Change it
to be the actual return code from the command so that the script calling
sandbox can know if the command succeeded (tests passed). Also remove
the now completely unused "exit_state" in sandbox.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 96b1046d 17-Nov-2014 Suriyan Ramasami <suriyan.r@gmail.com>

sandbox: Prepare API change for files greater than 2GB

Change the internal sandbox functions to use loff_t for file offsets.

Signed-off-by: Suriyan Ramasami <suriyan.r@gmail.com>

Acked-by: Simon Glass <sjg@chromium.org>

# ab839dc3 27-Feb-2014 Simon Glass <sjg@chromium.org>

sandbox: Add options to clean up temporary files

When jumping from one sandbox U-Boot to another in sandbox, the RAM buffer
is preserved in the jump by using a temporary file. Add an option to tell
the receiving U-Boot to remove this file when it is no longer needed.

Similarly the old U-Boot image is left behind in this case. We cannot delete
it immediately since gdb cannot then find its debug symbols. Delete it just
before exiting.

Together these changes ensure that temporary files are removed both for
memory and U-Boot.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 1209e272 10-Nov-2013 Simon Glass <sjg@chromium.org>

sandbox: Add facility to save/restore sandbox state

It is often useful to be able to save out the state from a sandbox test
run, for analysis or to restore it later to continue a test. Add generic
infrastructure for doing this using a device tree binary file. This is
a flexible tagged file format which is already supported by U-Boot, and
it supports hierarchy if needed.

Signed-off-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Hung-ying Tyan <tyanh@chromium.org>

# 5c2859cd 10-Nov-2013 Simon Glass <sjg@chromium.org>

sandbox: Allow reading/writing of RAM buffer

It is useful to be able to save and restore the RAM contents of sandbox
U-Boot either for setting up tests, for later analysys, or for chaining
together multiple tests which need to keep the same memory contents.

Add a function to provide a memory file for U-Boot. This is read on
start-up and written when shutting down. If the file does not exist
on start-up, it will be created when shutting down.

Signed-off-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Simon Glass <sjg@chromium.org>

# 1a459660 08-Jul-2013 Wolfgang Denk <wd@denx.de>

Add GPL-2.0+ SPDX-License-Identifier to source files

Signed-off-by: Wolfgang Denk <wd@denx.de>
[trini: Fixup common/cmd_io.c]
Signed-off-by: Tom Rini <trini@ti.com>

# 6fb62078 15-Feb-2012 Simon Glass <sjg@chromium.org>

sandbox: add concept of sandbox state

The state exists through the life of U-Boot. It can be adjusted by command
line options and perhaps later through a config file. It is available to
U-Boot through state_...() calls (within sandbox code).

The primary purpose of this is to contain the "hardware" state. It should
only be used by sandbox internal code.

Signed-off-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Mike Frysinger <vapier@gentoo.org>

# 97192937 26-Sep-2023 Simon Glass <sjg@chromium.org>

sandbox: Only read the state if we have a state file

We should not read this unless requested. Make it conditional on the
option being provided.

Add some debugging to show the state being written.

Signed-off-by: Simon Glass <sjg@chromium.org>

# d02c6f57 26-Sep-2023 Simon Glass <sjg@chromium.org>

sandbox: Move reading the RAM buffer into a better place

This should not happen in the argument-parsing function. Move it to the
main program.

Add some debugging for reading/writing.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 763f0a1f 12-Apr-2023 Pavel Skripkin <paskripkin@gmail.com>

sandbox: disable tracing before unmapping RAM

Currently doing 'reset' command in sandbox with tracing enabled causes
SIGSEV

```
Hit any key to stop autoboot: 0
=>
=>
=> reset
resetting ...
Segmentation fault (core dumped)

```

Tracing callback uses RAM buffer for storing tracing reports, but
state_uninit() function unmaps whole RAM, which causes SIGSEV on umapped
memory inside tracing subsystem.

Fix it by disabling tracing before unmapping memory

Signed-off-by: Pavel Skripkin <paskripkin@gmail.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Add missing check for CONFIG_TRACE:
Signed-off-by: Simon Glass <sjg@chromium.org>

# 081bdc52 17-Jan-2023 Simon Glass <sjg@chromium.org>

sandbox: Allow SPI flash bootdevs to be disabled for tests

Most tests don't want these and they can create a lot of noise. Add a way
to disable them. Use that in tests, with a flag provided to enable them
for tests that need this feature.

Signed-off-by: Simon Glass <sjg@chromium.org>

# f43b2df3 17-Jan-2023 Simon Glass <sjg@chromium.org>

sandbox: Allow ethernet to be disabled at runtime

For bootstd tests it is seldom useful to have ethernet enabled. Add a way
to disable it, so that ethernet operations like tftpboot do nothing.

Signed-off-by: Simon Glass <sjg@chromium.org>

# aa6e94de 16-Nov-2022 Tom Rini <trini@konsulko.com>

global: Move remaining CONFIG_SYS_SDRAM_* to CFG_SYS_SDRAM_*

The rest of the unmigrated CONFIG symbols in the CONFIG_SYS_SDRAM
namespace do not easily transition to Kconfig. In many cases they likely
should come from the device tree instead. Move these out of CONFIG
namespace and in to CFG namespace.

Signed-off-by: Tom Rini <trini@konsulko.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 0b5c9b03 20-Oct-2022 Simon Glass <sjg@chromium.org>

sandbox: Drop message about writing sandbox state

This happens every time sandbox moves to the next phase so is not very
interesting. Display the message only when debugging.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 9859d89b 06-Sep-2022 Simon Glass <sjg@chromium.org>

sandbox: Support loading the other FDT

We need an 'other' FDT which is different from the control FDT, so we can
check that the ofnode tests correctly handle them both.

Add this to the build along with a way to read it into the sandbox state.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 73c5cb9d 06-Sep-2022 Simon Glass <sjg@chromium.org>

sandbox: Add a function to load a relative file path

At present this implementation is specific to loading the test FDT. We
plan to load others, so create a generic function to handle this.

The path is now limited to 256 characters, to simplify the code.

When there is an empty argv[0] (which should not happen), the function now
just uses the path as is, with no prefix.

Signed-off-by: Simon Glass <sjg@chromium.org>

# d02f99dd 28-Feb-2022 Simon Glass <sjg@chromium.org>

sandbox: Show a message when writing out the ram buffer

If state is not being written, but RAM is, we should still show a message,
so it is clear that this is happening.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 185f812c 19-Jan-2022 Heinrich Schuchardt <xypron.glpk@gmx.de>

doc: replace @return by Return:

Sphinx expects Return: and not @return to indicate a return value.

find . -name '*.c' -exec \
sed -i 's/^\(\s\)\*\(\s*\)@return\(\s\)/\1*\2Return:\3/' {} \;

find . -name '*.h' -exec \
sed -i 's/^\(\s\)\*\(\s*\)@return\(\s\)/\1*\2Return:\3/' {} \;

Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>

# cb897009 24-Jul-2021 Simon Glass <sjg@chromium.org>

sandbox: Reduce keyed autoboot delay

The autoboot tests are a recent addition to U-Boot, providing much-needed
coverage in this area.

A side effect of the keyed autoboot test is that this feature is enabled
in sandbox always. This changes the autoboot prompt and confuses the
pytests. Some tests become slower, for example the vboot tests take about
27s now instead of 3s.

We don't actually need this feature enabled to be able to run the tests.
Add a switch to allow sandbox to turn it on and off as needed. Use this
in the one test that needs it.

Add a command-line flag in case this is desired in normal use.

Signed-off-by: Simon Glass <sjg@chromium.org>
Fixes: 25c8b9f298e ("test: add first autoboot unit tests")
Reviewed-by: Steffen Jaeckel <jaeckel-floss@eyet-services.de>

# 9a72bea6 13-May-2021 Simon Glass <sjg@chromium.org>

sandbox: Silence coverity warning in state_read_file()

In this case the value seems save to pass to os_free(). Add a comment.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reported-by: Coverity (CID: 165109)

# 1c52fcca 06-Feb-2021 Simon Glass <sjg@chromium.org>

sandbox: Write out bloblist when exiting

Sandbox provides a way to write out its emulated memory on exit. This
makes it possible to pass a bloblist from one phase (e.g. SPL) to the
next.

However the bloblist is not closed off, so the checksum is generally
invalid. Fix this by finishing up the bloblist before writing the memory
file.

Signed-off-by: Simon Glass <sjg@chromium.org>

# b308d9fd 06-Feb-2021 Simon Glass <sjg@chromium.org>

sandbox: Avoid using malloc() for system state

This state is not accessible to the running U-Boot but at present it is
allocated in the emulated SDRAM. This doesn't seem very useful. Adjust
it to allocate from the OS instead.

The RAM buffer is currently not freed, but should be, so add that into
state_uninit(). Update the comment for os_free() to indicate that NULL is
a valid parameter value.

Note that the strdup() in spl_board_load_image() is changed as well, since
strdup() allocates memory in the RAM buffer.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 10bb90fa 20-Nov-2020 Patrick Delaunay <patrick.delaunay@foss.st.com>

sandbox: remove ram buffer file when U-Boot is loaded by SPL

Update management of "--rm_memory" sandbox's option and force
this option when U-Boot is loaded by SPL in os_spl_to_uboot()
and remove the ram file after reading in main() as described
in option help message: "Remove memory file after reading".

This patch avoids that the file "/tmp/u-boot.mem.XXXXXX" [created in
os_jump_to_file() when U-Boot is loaded by SPL] is never deleted
because state_uninit() is not called after U-Boot execution
(CtrlC or with running pytest for example).

This issue is reproduced by
> build-sandbox_spl/spl/u-boot-spl
and CtrlC in U-Bot console

> make qcheck

One temp file is created after each SPL and U-Boot execution
(7 tims in qcheck after test_handoff.py, test_ofplatdata.py,
test_spl.py execution).

Signed-off-by: Patrick Delaunay <patrick.delaunay@st.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 329dccc0 27-Oct-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

sandbox: implement reset

Up to now the sandbox would shutdown upon a cold reset request. Instead it
should be reset.

In our coding we use static variables like LIST_HEAD(efi_obj_list). A reset
can occur at any time, e.g. via an UEFI binary calling the reset service.
The only safe way to return to an initial state is to relaunch the U-Boot
binary.

The reset implementation uses execv() to relaunch U-Boot.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Simon Glass <sjg@chromium.org>

# c7e49ddc 04-Jun-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

sandbox: handling out of memory

assert() only works in debug mode. So checking a successful memory
allocation should not use assert().

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Simon Glass <sjg@chromium.org>

# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 3ff6fe5f 03-Feb-2020 Simon Glass <sjg@chromium.org>

sandbox: Add a new header for the system malloc()

Some files use U-Boot headers but still need to access the system
malloc(). Allow this by creating a new asm/malloc.h which can be used so
long as U-Boot's malloc.h has not been included.

Signed-off-by: Simon Glass <sjg@chromium.org>

# cf23c7c1 03-Feb-2020 Simon Glass <sjg@chromium.org>

sandbox: Rename 'free' variable

This name conflicts with our desire to #define free() to something else on
sandbox. Rename it.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 89694de5 06-Dec-2019 Simon Glass <sjg@chromium.org>

sandbox: Disable mmio by default in tests

When reseting sandbox for tests, disable mmio support since that is the
default state.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>

# 857f39d7 16-May-2019 Urja Rannikko <urjaman@gmail.com>

sysreset: switch to using SYSRESET_POWER_OFF for poweroff

It seems that SYSRESET_POWER_OFF was added recently, and all previous code
used SYSRESET_POWER for poweroff. SYSRESET_POWER is supposed to be a
PMIC-level power cycle, not a poweroff.

(Comment by Simon Glass)
SYSRESET_POWER means to do a power reset (removing and reinstating all power)
SYSRESET_POWER_OFF means to turn the device off and leave it off

Signed-off-by: Urja Rannikko <urjaman@gmail.com>
Reviewed-by: Patrick Delaunay <patrick.delaunay@st.com>
(Update comment to help understand the patch)
Signed-off-by: Kever Yang <kever.yang@rock-chips.com>

# 9072326a 18-May-2019 Simon Glass <sjg@chromium.org>

sandbox: Exit when SYSRESET_POWER_OFF is requested

At present this returns but it seems better to just exit sandbox
immediately.

Signed-off-by: Simon Glass <sjg@chromium.org>

reset

# 1c5a81d8 01-Oct-2018 Simon Glass <sjg@chromium.org>

sandbox: Remove the old memory file later

When debugging sandbox it is sometimes annoying that the memory file is
deleted early on. If sandbox later crashes or we quit (using the
debugger), it is not possible to run it again with the same state since
the memory file is gone.

Remove the old memory file when sandbox exits, instead. Also add debugging
showing the memory filename.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 428aa0ca 15-Sep-2018 Simon Glass <sjg@chromium.org>

sandbox: Enhance map_to_sysmem() to handle foreign pointers

At present map_sysmem() maps an address into the sandbox RAM buffer,
return a pointer, while map_to_sysmem() goes the other way.

The mapping is currently just 1:1 since a case was not found where a more
flexible mapping was needed. PCI does have a separate and more complex
mapping, but uses its own mechanism.

However this arrange cannot handle one important case, which is where a
test declares a stack variable and passes a pointer to it into a U-Boot
function which uses map_to_sysmem() to turn it into a address. Since the
pointer is not inside emulated DRAM, this will fail.

Add a mapping feature which can handle any such pointer, mapping it to a
simple tag value which can be passed around in U-Boot as an address.

Signed-off-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Alexander Graf <agraf@suse.de>

# 83d290c5 06-May-2018 Tom Rini <trini@konsulko.com>

SPDX: Convert all of our single license tags to Linux Kernel style

When U-Boot started using SPDX tags we were among the early adopters and
there weren't a lot of other examples to borrow from. So we picked the
area of the file that usually had a full license text and replaced it
with an appropriate SPDX-License-Identifier: entry. Since then, the
Linux Kernel has adopted SPDX tags and they place it as the very first
line in a file (except where shebangs are used, then it's second line)
and with slightly different comment styles than us.

In part due to community overlap, in part due to better tag visibility
and in part for other minor reasons, switch over to that style.

This commit changes all instances where we have a single declared
license in the tag as both the before and after are identical in tag
contents. There's also a few places where I found we did not have a tag
and have introduced one.

Signed-off-by: Tom Rini <trini@konsulko.com>

# 9095d5b8 13-Feb-2018 Simon Goldschmidt <sgoldschmidt@de.pepperl-fuchs.com>

fix spelling of 'functions' in 2 places (was 'funtcions')

Signed-off-by: Simon Goldschmidt <sgoldschmidt@de.pepperl-fuchs.com>

# 34b744be 18-May-2017 Simon Glass <sjg@chromium.org>

sandbox: Add a way to reset sandbox state for tests

Running a new test should reset the sandbox state to avoid tests
interferring with each other. Move the existing state-reset code into a
function so it can be used from tests.

Also update the code to reset the SPI devices and adjust the test code to
call it.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 11636258 12-May-2016 Stephen Warren <swarren@nvidia.com>

Rename reset to sysreset

The current reset API implements a method to reset the entire system.
In the near future, I'd like to introduce code that implements the device
tree reset bindings; i.e. the equivalent of the Linux kernel's reset API.
This controls resets to individual HW blocks or external chips with reset
signals. It doesn't make sense to merge the two APIs into one since they
have different semantic purposes. Resolve the naming conflict by renaming
the existing reset API to sysreset instead, so the new reset API can be
called just reset.

Signed-off-by: Stephen Warren <swarren@nvidia.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 9723563a 08-Nov-2015 Simon Glass <sjg@chromium.org>

sandbox: Add a way to skip time delays

Some tests are slow due to delays which are unnecessary on sandbox. The
worst offender is USB where we lose two seconds. Add a way to disable time
delays.

Signed-off-by: Simon Glass <sjg@chromium.org>

# dc6f4d3a 06-Jul-2015 Simon Glass <sjg@chromium.org>

sandbox: Support multiple reset types

Add settings for the last reset generated, and the types of resets which
are permitted. This will be used for testing.

Signed-off-by: Simon Glass <sjg@chromium.org>

# d73125cb 04-May-2015 Simon Glass <sjg@chromium.org>

sandbox: Correct error handling in state_read_file()

This function should return a useful error for U-Boot, rather than -1.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Joe Hershberger <joe.hershberger@ni.com>

# 88539e44 06-Feb-2015 Joe Hershberger <joe.hershberger@ni.com>

sandbox: Return '-c command' exit value as sandbox exit code

When a command is passed into sandbox using the '-c' argument the
command is run directly. This is most helpful when running tests (such
as test-dm.sh). Previously the exit code was an unused enum. Change it
to be the actual return code from the command so that the script calling
sandbox can know if the command succeeded (tests passed). Also remove
the now completely unused "exit_state" in sandbox.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 96b1046d 17-Nov-2014 Suriyan Ramasami <suriyan.r@gmail.com>

sandbox: Prepare API change for files greater than 2GB

Change the internal sandbox functions to use loff_t for file offsets.

Signed-off-by: Suriyan Ramasami <suriyan.r@gmail.com>

Acked-by: Simon Glass <sjg@chromium.org>

# ab839dc3 27-Feb-2014 Simon Glass <sjg@chromium.org>

sandbox: Add options to clean up temporary files

When jumping from one sandbox U-Boot to another in sandbox, the RAM buffer
is preserved in the jump by using a temporary file. Add an option to tell
the receiving U-Boot to remove this file when it is no longer needed.

Similarly the old U-Boot image is left behind in this case. We cannot delete
it immediately since gdb cannot then find its debug symbols. Delete it just
before exiting.

Together these changes ensure that temporary files are removed both for
memory and U-Boot.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 1209e272 10-Nov-2013 Simon Glass <sjg@chromium.org>

sandbox: Add facility to save/restore sandbox state

It is often useful to be able to save out the state from a sandbox test
run, for analysis or to restore it later to continue a test. Add generic
infrastructure for doing this using a device tree binary file. This is
a flexible tagged file format which is already supported by U-Boot, and
it supports hierarchy if needed.

Signed-off-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Hung-ying Tyan <tyanh@chromium.org>

# 5c2859cd 10-Nov-2013 Simon Glass <sjg@chromium.org>

sandbox: Allow reading/writing of RAM buffer

It is useful to be able to save and restore the RAM contents of sandbox
U-Boot either for setting up tests, for later analysys, or for chaining
together multiple tests which need to keep the same memory contents.

Add a function to provide a memory file for U-Boot. This is read on
start-up and written when shutting down. If the file does not exist
on start-up, it will be created when shutting down.

Signed-off-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Simon Glass <sjg@chromium.org>

# 1a459660 08-Jul-2013 Wolfgang Denk <wd@denx.de>

Add GPL-2.0+ SPDX-License-Identifier to source files

Signed-off-by: Wolfgang Denk <wd@denx.de>
[trini: Fixup common/cmd_io.c]
Signed-off-by: Tom Rini <trini@ti.com>

# 6fb62078 15-Feb-2012 Simon Glass <sjg@chromium.org>

sandbox: add concept of sandbox state

The state exists through the life of U-Boot. It can be adjusted by command
line options and perhaps later through a config file. It is available to
U-Boot through state_...() calls (within sandbox code).

The primary purpose of this is to contain the "hardware" state. It should
only be used by sandbox internal code.

Signed-off-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Mike Frysinger <vapier@gentoo.org>

# 763f0a1f 12-Apr-2023 Pavel Skripkin <paskripkin@gmail.com>

sandbox: disable tracing before unmapping RAM

Currently doing 'reset' command in sandbox with tracing enabled causes
SIGSEV

```
Hit any key to stop autoboot: 0
=>
=>
=> reset
resetting ...
Segmentation fault (core dumped)

```

Tracing callback uses RAM buffer for storing tracing reports, but
state_uninit() function unmaps whole RAM, which causes SIGSEV on umapped
memory inside tracing subsystem.

Fix it by disabling tracing before unmapping memory

Signed-off-by: Pavel Skripkin <paskripkin@gmail.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Add missing check for CONFIG_TRACE:
Signed-off-by: Simon Glass <sjg@chromium.org>

# 081bdc52 17-Jan-2023 Simon Glass <sjg@chromium.org>

sandbox: Allow SPI flash bootdevs to be disabled for tests

Most tests don't want these and they can create a lot of noise. Add a way
to disable them. Use that in tests, with a flag provided to enable them
for tests that need this feature.

Signed-off-by: Simon Glass <sjg@chromium.org>

# f43b2df3 17-Jan-2023 Simon Glass <sjg@chromium.org>

sandbox: Allow ethernet to be disabled at runtime

For bootstd tests it is seldom useful to have ethernet enabled. Add a way
to disable it, so that ethernet operations like tftpboot do nothing.

Signed-off-by: Simon Glass <sjg@chromium.org>

# aa6e94de 16-Nov-2022 Tom Rini <trini@konsulko.com>

global: Move remaining CONFIG_SYS_SDRAM_* to CFG_SYS_SDRAM_*

The rest of the unmigrated CONFIG symbols in the CONFIG_SYS_SDRAM
namespace do not easily transition to Kconfig. In many cases they likely
should come from the device tree instead. Move these out of CONFIG
namespace and in to CFG namespace.

Signed-off-by: Tom Rini <trini@konsulko.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 0b5c9b03 20-Oct-2022 Simon Glass <sjg@chromium.org>

sandbox: Drop message about writing sandbox state

This happens every time sandbox moves to the next phase so is not very
interesting. Display the message only when debugging.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 9859d89b 06-Sep-2022 Simon Glass <sjg@chromium.org>

sandbox: Support loading the other FDT

We need an 'other' FDT which is different from the control FDT, so we can
check that the ofnode tests correctly handle them both.

Add this to the build along with a way to read it into the sandbox state.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 73c5cb9d 06-Sep-2022 Simon Glass <sjg@chromium.org>

sandbox: Add a function to load a relative file path

At present this implementation is specific to loading the test FDT. We
plan to load others, so create a generic function to handle this.

The path is now limited to 256 characters, to simplify the code.

When there is an empty argv[0] (which should not happen), the function now
just uses the path as is, with no prefix.

Signed-off-by: Simon Glass <sjg@chromium.org>

# d02f99dd 28-Feb-2022 Simon Glass <sjg@chromium.org>

sandbox: Show a message when writing out the ram buffer

If state is not being written, but RAM is, we should still show a message,
so it is clear that this is happening.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 185f812c 19-Jan-2022 Heinrich Schuchardt <xypron.glpk@gmx.de>

doc: replace @return by Return:

Sphinx expects Return: and not @return to indicate a return value.

find . -name '*.c' -exec \
sed -i 's/^\(\s\)\*\(\s*\)@return\(\s\)/\1*\2Return:\3/' {} \;

find . -name '*.h' -exec \
sed -i 's/^\(\s\)\*\(\s*\)@return\(\s\)/\1*\2Return:\3/' {} \;

Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>

# cb897009 24-Jul-2021 Simon Glass <sjg@chromium.org>

sandbox: Reduce keyed autoboot delay

The autoboot tests are a recent addition to U-Boot, providing much-needed
coverage in this area.

A side effect of the keyed autoboot test is that this feature is enabled
in sandbox always. This changes the autoboot prompt and confuses the
pytests. Some tests become slower, for example the vboot tests take about
27s now instead of 3s.

We don't actually need this feature enabled to be able to run the tests.
Add a switch to allow sandbox to turn it on and off as needed. Use this
in the one test that needs it.

Add a command-line flag in case this is desired in normal use.

Signed-off-by: Simon Glass <sjg@chromium.org>
Fixes: 25c8b9f298e ("test: add first autoboot unit tests")
Reviewed-by: Steffen Jaeckel <jaeckel-floss@eyet-services.de>

# 9a72bea6 13-May-2021 Simon Glass <sjg@chromium.org>

sandbox: Silence coverity warning in state_read_file()

In this case the value seems save to pass to os_free(). Add a comment.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reported-by: Coverity (CID: 165109)

# 1c52fcca 06-Feb-2021 Simon Glass <sjg@chromium.org>

sandbox: Write out bloblist when exiting

Sandbox provides a way to write out its emulated memory on exit. This
makes it possible to pass a bloblist from one phase (e.g. SPL) to the
next.

However the bloblist is not closed off, so the checksum is generally
invalid. Fix this by finishing up the bloblist before writing the memory
file.

Signed-off-by: Simon Glass <sjg@chromium.org>

# b308d9fd 06-Feb-2021 Simon Glass <sjg@chromium.org>

sandbox: Avoid using malloc() for system state

This state is not accessible to the running U-Boot but at present it is
allocated in the emulated SDRAM. This doesn't seem very useful. Adjust
it to allocate from the OS instead.

The RAM buffer is currently not freed, but should be, so add that into
state_uninit(). Update the comment for os_free() to indicate that NULL is
a valid parameter value.

Note that the strdup() in spl_board_load_image() is changed as well, since
strdup() allocates memory in the RAM buffer.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 10bb90fa 20-Nov-2020 Patrick Delaunay <patrick.delaunay@foss.st.com>

sandbox: remove ram buffer file when U-Boot is loaded by SPL

Update management of "--rm_memory" sandbox's option and force
this option when U-Boot is loaded by SPL in os_spl_to_uboot()
and remove the ram file after reading in main() as described
in option help message: "Remove memory file after reading".

This patch avoids that the file "/tmp/u-boot.mem.XXXXXX" [created in
os_jump_to_file() when U-Boot is loaded by SPL] is never deleted
because state_uninit() is not called after U-Boot execution
(CtrlC or with running pytest for example).

This issue is reproduced by
> build-sandbox_spl/spl/u-boot-spl
and CtrlC in U-Bot console

> make qcheck

One temp file is created after each SPL and U-Boot execution
(7 tims in qcheck after test_handoff.py, test_ofplatdata.py,
test_spl.py execution).

Signed-off-by: Patrick Delaunay <patrick.delaunay@st.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 329dccc0 27-Oct-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

sandbox: implement reset

Up to now the sandbox would shutdown upon a cold reset request. Instead it
should be reset.

In our coding we use static variables like LIST_HEAD(efi_obj_list). A reset
can occur at any time, e.g. via an UEFI binary calling the reset service.
The only safe way to return to an initial state is to relaunch the U-Boot
binary.

The reset implementation uses execv() to relaunch U-Boot.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Simon Glass <sjg@chromium.org>

# c7e49ddc 04-Jun-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

sandbox: handling out of memory

assert() only works in debug mode. So checking a successful memory
allocation should not use assert().

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Simon Glass <sjg@chromium.org>

# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 3ff6fe5f 03-Feb-2020 Simon Glass <sjg@chromium.org>

sandbox: Add a new header for the system malloc()

Some files use U-Boot headers but still need to access the system
malloc(). Allow this by creating a new asm/malloc.h which can be used so
long as U-Boot's malloc.h has not been included.

Signed-off-by: Simon Glass <sjg@chromium.org>

# cf23c7c1 03-Feb-2020 Simon Glass <sjg@chromium.org>

sandbox: Rename 'free' variable

This name conflicts with our desire to #define free() to something else on
sandbox. Rename it.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 89694de5 06-Dec-2019 Simon Glass <sjg@chromium.org>

sandbox: Disable mmio by default in tests

When reseting sandbox for tests, disable mmio support since that is the
default state.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>

# 857f39d7 16-May-2019 Urja Rannikko <urjaman@gmail.com>

sysreset: switch to using SYSRESET_POWER_OFF for poweroff

It seems that SYSRESET_POWER_OFF was added recently, and all previous code
used SYSRESET_POWER for poweroff. SYSRESET_POWER is supposed to be a
PMIC-level power cycle, not a poweroff.

(Comment by Simon Glass)
SYSRESET_POWER means to do a power reset (removing and reinstating all power)
SYSRESET_POWER_OFF means to turn the device off and leave it off

Signed-off-by: Urja Rannikko <urjaman@gmail.com>
Reviewed-by: Patrick Delaunay <patrick.delaunay@st.com>
(Update comment to help understand the patch)
Signed-off-by: Kever Yang <kever.yang@rock-chips.com>

# 9072326a 18-May-2019 Simon Glass <sjg@chromium.org>

sandbox: Exit when SYSRESET_POWER_OFF is requested

At present this returns but it seems better to just exit sandbox
immediately.

Signed-off-by: Simon Glass <sjg@chromium.org>

reset

# 1c5a81d8 01-Oct-2018 Simon Glass <sjg@chromium.org>

sandbox: Remove the old memory file later

When debugging sandbox it is sometimes annoying that the memory file is
deleted early on. If sandbox later crashes or we quit (using the
debugger), it is not possible to run it again with the same state since
the memory file is gone.

Remove the old memory file when sandbox exits, instead. Also add debugging
showing the memory filename.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 428aa0ca 15-Sep-2018 Simon Glass <sjg@chromium.org>

sandbox: Enhance map_to_sysmem() to handle foreign pointers

At present map_sysmem() maps an address into the sandbox RAM buffer,
return a pointer, while map_to_sysmem() goes the other way.

The mapping is currently just 1:1 since a case was not found where a more
flexible mapping was needed. PCI does have a separate and more complex
mapping, but uses its own mechanism.

However this arrange cannot handle one important case, which is where a
test declares a stack variable and passes a pointer to it into a U-Boot
function which uses map_to_sysmem() to turn it into a address. Since the
pointer is not inside emulated DRAM, this will fail.

Add a mapping feature which can handle any such pointer, mapping it to a
simple tag value which can be passed around in U-Boot as an address.

Signed-off-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Alexander Graf <agraf@suse.de>

# 83d290c5 06-May-2018 Tom Rini <trini@konsulko.com>

SPDX: Convert all of our single license tags to Linux Kernel style

When U-Boot started using SPDX tags we were among the early adopters and
there weren't a lot of other examples to borrow from. So we picked the
area of the file that usually had a full license text and replaced it
with an appropriate SPDX-License-Identifier: entry. Since then, the
Linux Kernel has adopted SPDX tags and they place it as the very first
line in a file (except where shebangs are used, then it's second line)
and with slightly different comment styles than us.

In part due to community overlap, in part due to better tag visibility
and in part for other minor reasons, switch over to that style.

This commit changes all instances where we have a single declared
license in the tag as both the before and after are identical in tag
contents. There's also a few places where I found we did not have a tag
and have introduced one.

Signed-off-by: Tom Rini <trini@konsulko.com>

# 9095d5b8 13-Feb-2018 Simon Goldschmidt <sgoldschmidt@de.pepperl-fuchs.com>

fix spelling of 'functions' in 2 places (was 'funtcions')

Signed-off-by: Simon Goldschmidt <sgoldschmidt@de.pepperl-fuchs.com>

# 34b744be 18-May-2017 Simon Glass <sjg@chromium.org>

sandbox: Add a way to reset sandbox state for tests

Running a new test should reset the sandbox state to avoid tests
interferring with each other. Move the existing state-reset code into a
function so it can be used from tests.

Also update the code to reset the SPI devices and adjust the test code to
call it.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 11636258 12-May-2016 Stephen Warren <swarren@nvidia.com>

Rename reset to sysreset

The current reset API implements a method to reset the entire system.
In the near future, I'd like to introduce code that implements the device
tree reset bindings; i.e. the equivalent of the Linux kernel's reset API.
This controls resets to individual HW blocks or external chips with reset
signals. It doesn't make sense to merge the two APIs into one since they
have different semantic purposes. Resolve the naming conflict by renaming
the existing reset API to sysreset instead, so the new reset API can be
called just reset.

Signed-off-by: Stephen Warren <swarren@nvidia.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 9723563a 08-Nov-2015 Simon Glass <sjg@chromium.org>

sandbox: Add a way to skip time delays

Some tests are slow due to delays which are unnecessary on sandbox. The
worst offender is USB where we lose two seconds. Add a way to disable time
delays.

Signed-off-by: Simon Glass <sjg@chromium.org>

# dc6f4d3a 06-Jul-2015 Simon Glass <sjg@chromium.org>

sandbox: Support multiple reset types

Add settings for the last reset generated, and the types of resets which
are permitted. This will be used for testing.

Signed-off-by: Simon Glass <sjg@chromium.org>

# d73125cb 04-May-2015 Simon Glass <sjg@chromium.org>

sandbox: Correct error handling in state_read_file()

This function should return a useful error for U-Boot, rather than -1.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Joe Hershberger <joe.hershberger@ni.com>

# 88539e44 06-Feb-2015 Joe Hershberger <joe.hershberger@ni.com>

sandbox: Return '-c command' exit value as sandbox exit code

When a command is passed into sandbox using the '-c' argument the
command is run directly. This is most helpful when running tests (such
as test-dm.sh). Previously the exit code was an unused enum. Change it
to be the actual return code from the command so that the script calling
sandbox can know if the command succeeded (tests passed). Also remove
the now completely unused "exit_state" in sandbox.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 96b1046d 17-Nov-2014 Suriyan Ramasami <suriyan.r@gmail.com>

sandbox: Prepare API change for files greater than 2GB

Change the internal sandbox functions to use loff_t for file offsets.

Signed-off-by: Suriyan Ramasami <suriyan.r@gmail.com>

Acked-by: Simon Glass <sjg@chromium.org>

# ab839dc3 27-Feb-2014 Simon Glass <sjg@chromium.org>

sandbox: Add options to clean up temporary files

When jumping from one sandbox U-Boot to another in sandbox, the RAM buffer
is preserved in the jump by using a temporary file. Add an option to tell
the receiving U-Boot to remove this file when it is no longer needed.

Similarly the old U-Boot image is left behind in this case. We cannot delete
it immediately since gdb cannot then find its debug symbols. Delete it just
before exiting.

Together these changes ensure that temporary files are removed both for
memory and U-Boot.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 1209e272 10-Nov-2013 Simon Glass <sjg@chromium.org>

sandbox: Add facility to save/restore sandbox state

It is often useful to be able to save out the state from a sandbox test
run, for analysis or to restore it later to continue a test. Add generic
infrastructure for doing this using a device tree binary file. This is
a flexible tagged file format which is already supported by U-Boot, and
it supports hierarchy if needed.

Signed-off-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Hung-ying Tyan <tyanh@chromium.org>

# 5c2859cd 10-Nov-2013 Simon Glass <sjg@chromium.org>

sandbox: Allow reading/writing of RAM buffer

It is useful to be able to save and restore the RAM contents of sandbox
U-Boot either for setting up tests, for later analysys, or for chaining
together multiple tests which need to keep the same memory contents.

Add a function to provide a memory file for U-Boot. This is read on
start-up and written when shutting down. If the file does not exist
on start-up, it will be created when shutting down.

Signed-off-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Simon Glass <sjg@chromium.org>

# 1a459660 08-Jul-2013 Wolfgang Denk <wd@denx.de>

Add GPL-2.0+ SPDX-License-Identifier to source files

Signed-off-by: Wolfgang Denk <wd@denx.de>
[trini: Fixup common/cmd_io.c]
Signed-off-by: Tom Rini <trini@ti.com>

# 6fb62078 15-Feb-2012 Simon Glass <sjg@chromium.org>

sandbox: add concept of sandbox state

The state exists through the life of U-Boot. It can be adjusted by command
line options and perhaps later through a config file. It is available to
U-Boot through state_...() calls (within sandbox code).

The primary purpose of this is to contain the "hardware" state. It should
only be used by sandbox internal code.

Signed-off-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Mike Frysinger <vapier@gentoo.org>

# 081bdc52 17-Jan-2023 Simon Glass <sjg@chromium.org>

sandbox: Allow SPI flash bootdevs to be disabled for tests

Most tests don't want these and they can create a lot of noise. Add a way
to disable them. Use that in tests, with a flag provided to enable them
for tests that need this feature.

Signed-off-by: Simon Glass <sjg@chromium.org>

# f43b2df3 17-Jan-2023 Simon Glass <sjg@chromium.org>

sandbox: Allow ethernet to be disabled at runtime

For bootstd tests it is seldom useful to have ethernet enabled. Add a way
to disable it, so that ethernet operations like tftpboot do nothing.

Signed-off-by: Simon Glass <sjg@chromium.org>

# aa6e94de 16-Nov-2022 Tom Rini <trini@konsulko.com>

global: Move remaining CONFIG_SYS_SDRAM_* to CFG_SYS_SDRAM_*

The rest of the unmigrated CONFIG symbols in the CONFIG_SYS_SDRAM
namespace do not easily transition to Kconfig. In many cases they likely
should come from the device tree instead. Move these out of CONFIG
namespace and in to CFG namespace.

Signed-off-by: Tom Rini <trini@konsulko.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 0b5c9b03 20-Oct-2022 Simon Glass <sjg@chromium.org>

sandbox: Drop message about writing sandbox state

This happens every time sandbox moves to the next phase so is not very
interesting. Display the message only when debugging.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 9859d89b 06-Sep-2022 Simon Glass <sjg@chromium.org>

sandbox: Support loading the other FDT

We need an 'other' FDT which is different from the control FDT, so we can
check that the ofnode tests correctly handle them both.

Add this to the build along with a way to read it into the sandbox state.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 73c5cb9d 06-Sep-2022 Simon Glass <sjg@chromium.org>

sandbox: Add a function to load a relative file path

At present this implementation is specific to loading the test FDT. We
plan to load others, so create a generic function to handle this.

The path is now limited to 256 characters, to simplify the code.

When there is an empty argv[0] (which should not happen), the function now
just uses the path as is, with no prefix.

Signed-off-by: Simon Glass <sjg@chromium.org>

# d02f99dd 28-Feb-2022 Simon Glass <sjg@chromium.org>

sandbox: Show a message when writing out the ram buffer

If state is not being written, but RAM is, we should still show a message,
so it is clear that this is happening.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 185f812c 19-Jan-2022 Heinrich Schuchardt <xypron.glpk@gmx.de>

doc: replace @return by Return:

Sphinx expects Return: and not @return to indicate a return value.

find . -name '*.c' -exec \
sed -i 's/^\(\s\)\*\(\s*\)@return\(\s\)/\1*\2Return:\3/' {} \;

find . -name '*.h' -exec \
sed -i 's/^\(\s\)\*\(\s*\)@return\(\s\)/\1*\2Return:\3/' {} \;

Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>

# cb897009 24-Jul-2021 Simon Glass <sjg@chromium.org>

sandbox: Reduce keyed autoboot delay

The autoboot tests are a recent addition to U-Boot, providing much-needed
coverage in this area.

A side effect of the keyed autoboot test is that this feature is enabled
in sandbox always. This changes the autoboot prompt and confuses the
pytests. Some tests become slower, for example the vboot tests take about
27s now instead of 3s.

We don't actually need this feature enabled to be able to run the tests.
Add a switch to allow sandbox to turn it on and off as needed. Use this
in the one test that needs it.

Add a command-line flag in case this is desired in normal use.

Signed-off-by: Simon Glass <sjg@chromium.org>
Fixes: 25c8b9f298e ("test: add first autoboot unit tests")
Reviewed-by: Steffen Jaeckel <jaeckel-floss@eyet-services.de>

# 9a72bea6 13-May-2021 Simon Glass <sjg@chromium.org>

sandbox: Silence coverity warning in state_read_file()

In this case the value seems save to pass to os_free(). Add a comment.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reported-by: Coverity (CID: 165109)

# 1c52fcca 06-Feb-2021 Simon Glass <sjg@chromium.org>

sandbox: Write out bloblist when exiting

Sandbox provides a way to write out its emulated memory on exit. This
makes it possible to pass a bloblist from one phase (e.g. SPL) to the
next.

However the bloblist is not closed off, so the checksum is generally
invalid. Fix this by finishing up the bloblist before writing the memory
file.

Signed-off-by: Simon Glass <sjg@chromium.org>

# b308d9fd 06-Feb-2021 Simon Glass <sjg@chromium.org>

sandbox: Avoid using malloc() for system state

This state is not accessible to the running U-Boot but at present it is
allocated in the emulated SDRAM. This doesn't seem very useful. Adjust
it to allocate from the OS instead.

The RAM buffer is currently not freed, but should be, so add that into
state_uninit(). Update the comment for os_free() to indicate that NULL is
a valid parameter value.

Note that the strdup() in spl_board_load_image() is changed as well, since
strdup() allocates memory in the RAM buffer.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 10bb90fa 20-Nov-2020 Patrick Delaunay <patrick.delaunay@foss.st.com>

sandbox: remove ram buffer file when U-Boot is loaded by SPL

Update management of "--rm_memory" sandbox's option and force
this option when U-Boot is loaded by SPL in os_spl_to_uboot()
and remove the ram file after reading in main() as described
in option help message: "Remove memory file after reading".

This patch avoids that the file "/tmp/u-boot.mem.XXXXXX" [created in
os_jump_to_file() when U-Boot is loaded by SPL] is never deleted
because state_uninit() is not called after U-Boot execution
(CtrlC or with running pytest for example).

This issue is reproduced by
> build-sandbox_spl/spl/u-boot-spl
and CtrlC in U-Bot console

> make qcheck

One temp file is created after each SPL and U-Boot execution
(7 tims in qcheck after test_handoff.py, test_ofplatdata.py,
test_spl.py execution).

Signed-off-by: Patrick Delaunay <patrick.delaunay@st.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 329dccc0 27-Oct-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

sandbox: implement reset

Up to now the sandbox would shutdown upon a cold reset request. Instead it
should be reset.

In our coding we use static variables like LIST_HEAD(efi_obj_list). A reset
can occur at any time, e.g. via an UEFI binary calling the reset service.
The only safe way to return to an initial state is to relaunch the U-Boot
binary.

The reset implementation uses execv() to relaunch U-Boot.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Simon Glass <sjg@chromium.org>

# c7e49ddc 04-Jun-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

sandbox: handling out of memory

assert() only works in debug mode. So checking a successful memory
allocation should not use assert().

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Simon Glass <sjg@chromium.org>

# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 3ff6fe5f 03-Feb-2020 Simon Glass <sjg@chromium.org>

sandbox: Add a new header for the system malloc()

Some files use U-Boot headers but still need to access the system
malloc(). Allow this by creating a new asm/malloc.h which can be used so
long as U-Boot's malloc.h has not been included.

Signed-off-by: Simon Glass <sjg@chromium.org>

# cf23c7c1 03-Feb-2020 Simon Glass <sjg@chromium.org>

sandbox: Rename 'free' variable

This name conflicts with our desire to #define free() to something else on
sandbox. Rename it.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 89694de5 06-Dec-2019 Simon Glass <sjg@chromium.org>

sandbox: Disable mmio by default in tests

When reseting sandbox for tests, disable mmio support since that is the
default state.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>

# 857f39d7 16-May-2019 Urja Rannikko <urjaman@gmail.com>

sysreset: switch to using SYSRESET_POWER_OFF for poweroff

It seems that SYSRESET_POWER_OFF was added recently, and all previous code
used SYSRESET_POWER for poweroff. SYSRESET_POWER is supposed to be a
PMIC-level power cycle, not a poweroff.

(Comment by Simon Glass)
SYSRESET_POWER means to do a power reset (removing and reinstating all power)
SYSRESET_POWER_OFF means to turn the device off and leave it off

Signed-off-by: Urja Rannikko <urjaman@gmail.com>
Reviewed-by: Patrick Delaunay <patrick.delaunay@st.com>
(Update comment to help understand the patch)
Signed-off-by: Kever Yang <kever.yang@rock-chips.com>

# 9072326a 18-May-2019 Simon Glass <sjg@chromium.org>

sandbox: Exit when SYSRESET_POWER_OFF is requested

At present this returns but it seems better to just exit sandbox
immediately.

Signed-off-by: Simon Glass <sjg@chromium.org>

reset

# 1c5a81d8 01-Oct-2018 Simon Glass <sjg@chromium.org>

sandbox: Remove the old memory file later

When debugging sandbox it is sometimes annoying that the memory file is
deleted early on. If sandbox later crashes or we quit (using the
debugger), it is not possible to run it again with the same state since
the memory file is gone.

Remove the old memory file when sandbox exits, instead. Also add debugging
showing the memory filename.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 428aa0ca 15-Sep-2018 Simon Glass <sjg@chromium.org>

sandbox: Enhance map_to_sysmem() to handle foreign pointers

At present map_sysmem() maps an address into the sandbox RAM buffer,
return a pointer, while map_to_sysmem() goes the other way.

The mapping is currently just 1:1 since a case was not found where a more
flexible mapping was needed. PCI does have a separate and more complex
mapping, but uses its own mechanism.

However this arrange cannot handle one important case, which is where a
test declares a stack variable and passes a pointer to it into a U-Boot
function which uses map_to_sysmem() to turn it into a address. Since the
pointer is not inside emulated DRAM, this will fail.

Add a mapping feature which can handle any such pointer, mapping it to a
simple tag value which can be passed around in U-Boot as an address.

Signed-off-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Alexander Graf <agraf@suse.de>

# 83d290c5 06-May-2018 Tom Rini <trini@konsulko.com>

SPDX: Convert all of our single license tags to Linux Kernel style

When U-Boot started using SPDX tags we were among the early adopters and
there weren't a lot of other examples to borrow from. So we picked the
area of the file that usually had a full license text and replaced it
with an appropriate SPDX-License-Identifier: entry. Since then, the
Linux Kernel has adopted SPDX tags and they place it as the very first
line in a file (except where shebangs are used, then it's second line)
and with slightly different comment styles than us.

In part due to community overlap, in part due to better tag visibility
and in part for other minor reasons, switch over to that style.

This commit changes all instances where we have a single declared
license in the tag as both the before and after are identical in tag
contents. There's also a few places where I found we did not have a tag
and have introduced one.

Signed-off-by: Tom Rini <trini@konsulko.com>

# 9095d5b8 13-Feb-2018 Simon Goldschmidt <sgoldschmidt@de.pepperl-fuchs.com>

fix spelling of 'functions' in 2 places (was 'funtcions')

Signed-off-by: Simon Goldschmidt <sgoldschmidt@de.pepperl-fuchs.com>

# 34b744be 18-May-2017 Simon Glass <sjg@chromium.org>

sandbox: Add a way to reset sandbox state for tests

Running a new test should reset the sandbox state to avoid tests
interferring with each other. Move the existing state-reset code into a
function so it can be used from tests.

Also update the code to reset the SPI devices and adjust the test code to
call it.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 11636258 12-May-2016 Stephen Warren <swarren@nvidia.com>

Rename reset to sysreset

The current reset API implements a method to reset the entire system.
In the near future, I'd like to introduce code that implements the device
tree reset bindings; i.e. the equivalent of the Linux kernel's reset API.
This controls resets to individual HW blocks or external chips with reset
signals. It doesn't make sense to merge the two APIs into one since they
have different semantic purposes. Resolve the naming conflict by renaming
the existing reset API to sysreset instead, so the new reset API can be
called just reset.

Signed-off-by: Stephen Warren <swarren@nvidia.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 9723563a 08-Nov-2015 Simon Glass <sjg@chromium.org>

sandbox: Add a way to skip time delays

Some tests are slow due to delays which are unnecessary on sandbox. The
worst offender is USB where we lose two seconds. Add a way to disable time
delays.

Signed-off-by: Simon Glass <sjg@chromium.org>

# dc6f4d3a 06-Jul-2015 Simon Glass <sjg@chromium.org>

sandbox: Support multiple reset types

Add settings for the last reset generated, and the types of resets which
are permitted. This will be used for testing.

Signed-off-by: Simon Glass <sjg@chromium.org>

# d73125cb 04-May-2015 Simon Glass <sjg@chromium.org>

sandbox: Correct error handling in state_read_file()

This function should return a useful error for U-Boot, rather than -1.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Joe Hershberger <joe.hershberger@ni.com>

# 88539e44 06-Feb-2015 Joe Hershberger <joe.hershberger@ni.com>

sandbox: Return '-c command' exit value as sandbox exit code

When a command is passed into sandbox using the '-c' argument the
command is run directly. This is most helpful when running tests (such
as test-dm.sh). Previously the exit code was an unused enum. Change it
to be the actual return code from the command so that the script calling
sandbox can know if the command succeeded (tests passed). Also remove
the now completely unused "exit_state" in sandbox.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 96b1046d 17-Nov-2014 Suriyan Ramasami <suriyan.r@gmail.com>

sandbox: Prepare API change for files greater than 2GB

Change the internal sandbox functions to use loff_t for file offsets.

Signed-off-by: Suriyan Ramasami <suriyan.r@gmail.com>

Acked-by: Simon Glass <sjg@chromium.org>

# ab839dc3 27-Feb-2014 Simon Glass <sjg@chromium.org>

sandbox: Add options to clean up temporary files

When jumping from one sandbox U-Boot to another in sandbox, the RAM buffer
is preserved in the jump by using a temporary file. Add an option to tell
the receiving U-Boot to remove this file when it is no longer needed.

Similarly the old U-Boot image is left behind in this case. We cannot delete
it immediately since gdb cannot then find its debug symbols. Delete it just
before exiting.

Together these changes ensure that temporary files are removed both for
memory and U-Boot.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 1209e272 10-Nov-2013 Simon Glass <sjg@chromium.org>

sandbox: Add facility to save/restore sandbox state

It is often useful to be able to save out the state from a sandbox test
run, for analysis or to restore it later to continue a test. Add generic
infrastructure for doing this using a device tree binary file. This is
a flexible tagged file format which is already supported by U-Boot, and
it supports hierarchy if needed.

Signed-off-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Hung-ying Tyan <tyanh@chromium.org>

# 5c2859cd 10-Nov-2013 Simon Glass <sjg@chromium.org>

sandbox: Allow reading/writing of RAM buffer

It is useful to be able to save and restore the RAM contents of sandbox
U-Boot either for setting up tests, for later analysys, or for chaining
together multiple tests which need to keep the same memory contents.

Add a function to provide a memory file for U-Boot. This is read on
start-up and written when shutting down. If the file does not exist
on start-up, it will be created when shutting down.

Signed-off-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Simon Glass <sjg@chromium.org>

# 1a459660 08-Jul-2013 Wolfgang Denk <wd@denx.de>

Add GPL-2.0+ SPDX-License-Identifier to source files

Signed-off-by: Wolfgang Denk <wd@denx.de>
[trini: Fixup common/cmd_io.c]
Signed-off-by: Tom Rini <trini@ti.com>

# 6fb62078 15-Feb-2012 Simon Glass <sjg@chromium.org>

sandbox: add concept of sandbox state

The state exists through the life of U-Boot. It can be adjusted by command
line options and perhaps later through a config file. It is available to
U-Boot through state_...() calls (within sandbox code).

The primary purpose of this is to contain the "hardware" state. It should
only be used by sandbox internal code.

Signed-off-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Mike Frysinger <vapier@gentoo.org>

# aa6e94de 16-Nov-2022 Tom Rini <trini@konsulko.com>

global: Move remaining CONFIG_SYS_SDRAM_* to CFG_SYS_SDRAM_*

The rest of the unmigrated CONFIG symbols in the CONFIG_SYS_SDRAM
namespace do not easily transition to Kconfig. In many cases they likely
should come from the device tree instead. Move these out of CONFIG
namespace and in to CFG namespace.

Signed-off-by: Tom Rini <trini@konsulko.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 0b5c9b03 20-Oct-2022 Simon Glass <sjg@chromium.org>

sandbox: Drop message about writing sandbox state

This happens every time sandbox moves to the next phase so is not very
interesting. Display the message only when debugging.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 9859d89b 06-Sep-2022 Simon Glass <sjg@chromium.org>

sandbox: Support loading the other FDT

We need an 'other' FDT which is different from the control FDT, so we can
check that the ofnode tests correctly handle them both.

Add this to the build along with a way to read it into the sandbox state.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 73c5cb9d 06-Sep-2022 Simon Glass <sjg@chromium.org>

sandbox: Add a function to load a relative file path

At present this implementation is specific to loading the test FDT. We
plan to load others, so create a generic function to handle this.

The path is now limited to 256 characters, to simplify the code.

When there is an empty argv[0] (which should not happen), the function now
just uses the path as is, with no prefix.

Signed-off-by: Simon Glass <sjg@chromium.org>

# d02f99dd 28-Feb-2022 Simon Glass <sjg@chromium.org>

sandbox: Show a message when writing out the ram buffer

If state is not being written, but RAM is, we should still show a message,
so it is clear that this is happening.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 185f812c 19-Jan-2022 Heinrich Schuchardt <xypron.glpk@gmx.de>

doc: replace @return by Return:

Sphinx expects Return: and not @return to indicate a return value.

find . -name '*.c' -exec \
sed -i 's/^\(\s\)\*\(\s*\)@return\(\s\)/\1*\2Return:\3/' {} \;

find . -name '*.h' -exec \
sed -i 's/^\(\s\)\*\(\s*\)@return\(\s\)/\1*\2Return:\3/' {} \;

Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>

# cb897009 24-Jul-2021 Simon Glass <sjg@chromium.org>

sandbox: Reduce keyed autoboot delay

The autoboot tests are a recent addition to U-Boot, providing much-needed
coverage in this area.

A side effect of the keyed autoboot test is that this feature is enabled
in sandbox always. This changes the autoboot prompt and confuses the
pytests. Some tests become slower, for example the vboot tests take about
27s now instead of 3s.

We don't actually need this feature enabled to be able to run the tests.
Add a switch to allow sandbox to turn it on and off as needed. Use this
in the one test that needs it.

Add a command-line flag in case this is desired in normal use.

Signed-off-by: Simon Glass <sjg@chromium.org>
Fixes: 25c8b9f298e ("test: add first autoboot unit tests")
Reviewed-by: Steffen Jaeckel <jaeckel-floss@eyet-services.de>

# 9a72bea6 13-May-2021 Simon Glass <sjg@chromium.org>

sandbox: Silence coverity warning in state_read_file()

In this case the value seems save to pass to os_free(). Add a comment.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reported-by: Coverity (CID: 165109)

# 1c52fcca 06-Feb-2021 Simon Glass <sjg@chromium.org>

sandbox: Write out bloblist when exiting

Sandbox provides a way to write out its emulated memory on exit. This
makes it possible to pass a bloblist from one phase (e.g. SPL) to the
next.

However the bloblist is not closed off, so the checksum is generally
invalid. Fix this by finishing up the bloblist before writing the memory
file.

Signed-off-by: Simon Glass <sjg@chromium.org>

# b308d9fd 06-Feb-2021 Simon Glass <sjg@chromium.org>

sandbox: Avoid using malloc() for system state

This state is not accessible to the running U-Boot but at present it is
allocated in the emulated SDRAM. This doesn't seem very useful. Adjust
it to allocate from the OS instead.

The RAM buffer is currently not freed, but should be, so add that into
state_uninit(). Update the comment for os_free() to indicate that NULL is
a valid parameter value.

Note that the strdup() in spl_board_load_image() is changed as well, since
strdup() allocates memory in the RAM buffer.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 10bb90fa 20-Nov-2020 Patrick Delaunay <patrick.delaunay@foss.st.com>

sandbox: remove ram buffer file when U-Boot is loaded by SPL

Update management of "--rm_memory" sandbox's option and force
this option when U-Boot is loaded by SPL in os_spl_to_uboot()
and remove the ram file after reading in main() as described
in option help message: "Remove memory file after reading".

This patch avoids that the file "/tmp/u-boot.mem.XXXXXX" [created in
os_jump_to_file() when U-Boot is loaded by SPL] is never deleted
because state_uninit() is not called after U-Boot execution
(CtrlC or with running pytest for example).

This issue is reproduced by
> build-sandbox_spl/spl/u-boot-spl
and CtrlC in U-Bot console

> make qcheck

One temp file is created after each SPL and U-Boot execution
(7 tims in qcheck after test_handoff.py, test_ofplatdata.py,
test_spl.py execution).

Signed-off-by: Patrick Delaunay <patrick.delaunay@st.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 329dccc0 27-Oct-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

sandbox: implement reset

Up to now the sandbox would shutdown upon a cold reset request. Instead it
should be reset.

In our coding we use static variables like LIST_HEAD(efi_obj_list). A reset
can occur at any time, e.g. via an UEFI binary calling the reset service.
The only safe way to return to an initial state is to relaunch the U-Boot
binary.

The reset implementation uses execv() to relaunch U-Boot.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Simon Glass <sjg@chromium.org>

# c7e49ddc 04-Jun-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

sandbox: handling out of memory

assert() only works in debug mode. So checking a successful memory
allocation should not use assert().

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Simon Glass <sjg@chromium.org>

# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 3ff6fe5f 03-Feb-2020 Simon Glass <sjg@chromium.org>

sandbox: Add a new header for the system malloc()

Some files use U-Boot headers but still need to access the system
malloc(). Allow this by creating a new asm/malloc.h which can be used so
long as U-Boot's malloc.h has not been included.

Signed-off-by: Simon Glass <sjg@chromium.org>

# cf23c7c1 03-Feb-2020 Simon Glass <sjg@chromium.org>

sandbox: Rename 'free' variable

This name conflicts with our desire to #define free() to something else on
sandbox. Rename it.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 89694de5 06-Dec-2019 Simon Glass <sjg@chromium.org>

sandbox: Disable mmio by default in tests

When reseting sandbox for tests, disable mmio support since that is the
default state.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>

# 857f39d7 16-May-2019 Urja Rannikko <urjaman@gmail.com>

sysreset: switch to using SYSRESET_POWER_OFF for poweroff

It seems that SYSRESET_POWER_OFF was added recently, and all previous code
used SYSRESET_POWER for poweroff. SYSRESET_POWER is supposed to be a
PMIC-level power cycle, not a poweroff.

(Comment by Simon Glass)
SYSRESET_POWER means to do a power reset (removing and reinstating all power)
SYSRESET_POWER_OFF means to turn the device off and leave it off

Signed-off-by: Urja Rannikko <urjaman@gmail.com>
Reviewed-by: Patrick Delaunay <patrick.delaunay@st.com>
(Update comment to help understand the patch)
Signed-off-by: Kever Yang <kever.yang@rock-chips.com>

# 9072326a 18-May-2019 Simon Glass <sjg@chromium.org>

sandbox: Exit when SYSRESET_POWER_OFF is requested

At present this returns but it seems better to just exit sandbox
immediately.

Signed-off-by: Simon Glass <sjg@chromium.org>

reset

# 1c5a81d8 01-Oct-2018 Simon Glass <sjg@chromium.org>

sandbox: Remove the old memory file later

When debugging sandbox it is sometimes annoying that the memory file is
deleted early on. If sandbox later crashes or we quit (using the
debugger), it is not possible to run it again with the same state since
the memory file is gone.

Remove the old memory file when sandbox exits, instead. Also add debugging
showing the memory filename.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 428aa0ca 15-Sep-2018 Simon Glass <sjg@chromium.org>

sandbox: Enhance map_to_sysmem() to handle foreign pointers

At present map_sysmem() maps an address into the sandbox RAM buffer,
return a pointer, while map_to_sysmem() goes the other way.

The mapping is currently just 1:1 since a case was not found where a more
flexible mapping was needed. PCI does have a separate and more complex
mapping, but uses its own mechanism.

However this arrange cannot handle one important case, which is where a
test declares a stack variable and passes a pointer to it into a U-Boot
function which uses map_to_sysmem() to turn it into a address. Since the
pointer is not inside emulated DRAM, this will fail.

Add a mapping feature which can handle any such pointer, mapping it to a
simple tag value which can be passed around in U-Boot as an address.

Signed-off-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Alexander Graf <agraf@suse.de>

# 83d290c5 06-May-2018 Tom Rini <trini@konsulko.com>

SPDX: Convert all of our single license tags to Linux Kernel style

When U-Boot started using SPDX tags we were among the early adopters and
there weren't a lot of other examples to borrow from. So we picked the
area of the file that usually had a full license text and replaced it
with an appropriate SPDX-License-Identifier: entry. Since then, the
Linux Kernel has adopted SPDX tags and they place it as the very first
line in a file (except where shebangs are used, then it's second line)
and with slightly different comment styles than us.

In part due to community overlap, in part due to better tag visibility
and in part for other minor reasons, switch over to that style.

This commit changes all instances where we have a single declared
license in the tag as both the before and after are identical in tag
contents. There's also a few places where I found we did not have a tag
and have introduced one.

Signed-off-by: Tom Rini <trini@konsulko.com>

# 9095d5b8 13-Feb-2018 Simon Goldschmidt <sgoldschmidt@de.pepperl-fuchs.com>

fix spelling of 'functions' in 2 places (was 'funtcions')

Signed-off-by: Simon Goldschmidt <sgoldschmidt@de.pepperl-fuchs.com>

# 34b744be 18-May-2017 Simon Glass <sjg@chromium.org>

sandbox: Add a way to reset sandbox state for tests

Running a new test should reset the sandbox state to avoid tests
interferring with each other. Move the existing state-reset code into a
function so it can be used from tests.

Also update the code to reset the SPI devices and adjust the test code to
call it.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 11636258 12-May-2016 Stephen Warren <swarren@nvidia.com>

Rename reset to sysreset

The current reset API implements a method to reset the entire system.
In the near future, I'd like to introduce code that implements the device
tree reset bindings; i.e. the equivalent of the Linux kernel's reset API.
This controls resets to individual HW blocks or external chips with reset
signals. It doesn't make sense to merge the two APIs into one since they
have different semantic purposes. Resolve the naming conflict by renaming
the existing reset API to sysreset instead, so the new reset API can be
called just reset.

Signed-off-by: Stephen Warren <swarren@nvidia.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 9723563a 08-Nov-2015 Simon Glass <sjg@chromium.org>

sandbox: Add a way to skip time delays

Some tests are slow due to delays which are unnecessary on sandbox. The
worst offender is USB where we lose two seconds. Add a way to disable time
delays.

Signed-off-by: Simon Glass <sjg@chromium.org>

# dc6f4d3a 06-Jul-2015 Simon Glass <sjg@chromium.org>

sandbox: Support multiple reset types

Add settings for the last reset generated, and the types of resets which
are permitted. This will be used for testing.

Signed-off-by: Simon Glass <sjg@chromium.org>

# d73125cb 04-May-2015 Simon Glass <sjg@chromium.org>

sandbox: Correct error handling in state_read_file()

This function should return a useful error for U-Boot, rather than -1.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Joe Hershberger <joe.hershberger@ni.com>

# 88539e44 06-Feb-2015 Joe Hershberger <joe.hershberger@ni.com>

sandbox: Return '-c command' exit value as sandbox exit code

When a command is passed into sandbox using the '-c' argument the
command is run directly. This is most helpful when running tests (such
as test-dm.sh). Previously the exit code was an unused enum. Change it
to be the actual return code from the command so that the script calling
sandbox can know if the command succeeded (tests passed). Also remove
the now completely unused "exit_state" in sandbox.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 96b1046d 17-Nov-2014 Suriyan Ramasami <suriyan.r@gmail.com>

sandbox: Prepare API change for files greater than 2GB

Change the internal sandbox functions to use loff_t for file offsets.

Signed-off-by: Suriyan Ramasami <suriyan.r@gmail.com>

Acked-by: Simon Glass <sjg@chromium.org>

# ab839dc3 27-Feb-2014 Simon Glass <sjg@chromium.org>

sandbox: Add options to clean up temporary files

When jumping from one sandbox U-Boot to another in sandbox, the RAM buffer
is preserved in the jump by using a temporary file. Add an option to tell
the receiving U-Boot to remove this file when it is no longer needed.

Similarly the old U-Boot image is left behind in this case. We cannot delete
it immediately since gdb cannot then find its debug symbols. Delete it just
before exiting.

Together these changes ensure that temporary files are removed both for
memory and U-Boot.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 1209e272 10-Nov-2013 Simon Glass <sjg@chromium.org>

sandbox: Add facility to save/restore sandbox state

It is often useful to be able to save out the state from a sandbox test
run, for analysis or to restore it later to continue a test. Add generic
infrastructure for doing this using a device tree binary file. This is
a flexible tagged file format which is already supported by U-Boot, and
it supports hierarchy if needed.

Signed-off-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Hung-ying Tyan <tyanh@chromium.org>

# 5c2859cd 10-Nov-2013 Simon Glass <sjg@chromium.org>

sandbox: Allow reading/writing of RAM buffer

It is useful to be able to save and restore the RAM contents of sandbox
U-Boot either for setting up tests, for later analysys, or for chaining
together multiple tests which need to keep the same memory contents.

Add a function to provide a memory file for U-Boot. This is read on
start-up and written when shutting down. If the file does not exist
on start-up, it will be created when shutting down.

Signed-off-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Simon Glass <sjg@chromium.org>

# 1a459660 08-Jul-2013 Wolfgang Denk <wd@denx.de>

Add GPL-2.0+ SPDX-License-Identifier to source files

Signed-off-by: Wolfgang Denk <wd@denx.de>
[trini: Fixup common/cmd_io.c]
Signed-off-by: Tom Rini <trini@ti.com>

# 6fb62078 15-Feb-2012 Simon Glass <sjg@chromium.org>

sandbox: add concept of sandbox state

The state exists through the life of U-Boot. It can be adjusted by command
line options and perhaps later through a config file. It is available to
U-Boot through state_...() calls (within sandbox code).

The primary purpose of this is to contain the "hardware" state. It should
only be used by sandbox internal code.

Signed-off-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Mike Frysinger <vapier@gentoo.org>

# 0b5c9b03 20-Oct-2022 Simon Glass <sjg@chromium.org>

sandbox: Drop message about writing sandbox state

This happens every time sandbox moves to the next phase so is not very
interesting. Display the message only when debugging.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 9859d89b 06-Sep-2022 Simon Glass <sjg@chromium.org>

sandbox: Support loading the other FDT

We need an 'other' FDT which is different from the control FDT, so we can
check that the ofnode tests correctly handle them both.

Add this to the build along with a way to read it into the sandbox state.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 73c5cb9d 06-Sep-2022 Simon Glass <sjg@chromium.org>

sandbox: Add a function to load a relative file path

At present this implementation is specific to loading the test FDT. We
plan to load others, so create a generic function to handle this.

The path is now limited to 256 characters, to simplify the code.

When there is an empty argv[0] (which should not happen), the function now
just uses the path as is, with no prefix.

Signed-off-by: Simon Glass <sjg@chromium.org>

# d02f99dd 28-Feb-2022 Simon Glass <sjg@chromium.org>

sandbox: Show a message when writing out the ram buffer

If state is not being written, but RAM is, we should still show a message,
so it is clear that this is happening.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 185f812c 19-Jan-2022 Heinrich Schuchardt <xypron.glpk@gmx.de>

doc: replace @return by Return:

Sphinx expects Return: and not @return to indicate a return value.

find . -name '*.c' -exec \
sed -i 's/^\(\s\)\*\(\s*\)@return\(\s\)/\1*\2Return:\3/' {} \;

find . -name '*.h' -exec \
sed -i 's/^\(\s\)\*\(\s*\)@return\(\s\)/\1*\2Return:\3/' {} \;

Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>

# cb897009 24-Jul-2021 Simon Glass <sjg@chromium.org>

sandbox: Reduce keyed autoboot delay

The autoboot tests are a recent addition to U-Boot, providing much-needed
coverage in this area.

A side effect of the keyed autoboot test is that this feature is enabled
in sandbox always. This changes the autoboot prompt and confuses the
pytests. Some tests become slower, for example the vboot tests take about
27s now instead of 3s.

We don't actually need this feature enabled to be able to run the tests.
Add a switch to allow sandbox to turn it on and off as needed. Use this
in the one test that needs it.

Add a command-line flag in case this is desired in normal use.

Signed-off-by: Simon Glass <sjg@chromium.org>
Fixes: 25c8b9f298e ("test: add first autoboot unit tests")
Reviewed-by: Steffen Jaeckel <jaeckel-floss@eyet-services.de>

# 9a72bea6 13-May-2021 Simon Glass <sjg@chromium.org>

sandbox: Silence coverity warning in state_read_file()

In this case the value seems save to pass to os_free(). Add a comment.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reported-by: Coverity (CID: 165109)

# 1c52fcca 06-Feb-2021 Simon Glass <sjg@chromium.org>

sandbox: Write out bloblist when exiting

Sandbox provides a way to write out its emulated memory on exit. This
makes it possible to pass a bloblist from one phase (e.g. SPL) to the
next.

However the bloblist is not closed off, so the checksum is generally
invalid. Fix this by finishing up the bloblist before writing the memory
file.

Signed-off-by: Simon Glass <sjg@chromium.org>

# b308d9fd 06-Feb-2021 Simon Glass <sjg@chromium.org>

sandbox: Avoid using malloc() for system state

This state is not accessible to the running U-Boot but at present it is
allocated in the emulated SDRAM. This doesn't seem very useful. Adjust
it to allocate from the OS instead.

The RAM buffer is currently not freed, but should be, so add that into
state_uninit(). Update the comment for os_free() to indicate that NULL is
a valid parameter value.

Note that the strdup() in spl_board_load_image() is changed as well, since
strdup() allocates memory in the RAM buffer.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 10bb90fa 20-Nov-2020 Patrick Delaunay <patrick.delaunay@foss.st.com>

sandbox: remove ram buffer file when U-Boot is loaded by SPL

Update management of "--rm_memory" sandbox's option and force
this option when U-Boot is loaded by SPL in os_spl_to_uboot()
and remove the ram file after reading in main() as described
in option help message: "Remove memory file after reading".

This patch avoids that the file "/tmp/u-boot.mem.XXXXXX" [created in
os_jump_to_file() when U-Boot is loaded by SPL] is never deleted
because state_uninit() is not called after U-Boot execution
(CtrlC or with running pytest for example).

This issue is reproduced by
> build-sandbox_spl/spl/u-boot-spl
and CtrlC in U-Bot console

> make qcheck

One temp file is created after each SPL and U-Boot execution
(7 tims in qcheck after test_handoff.py, test_ofplatdata.py,
test_spl.py execution).

Signed-off-by: Patrick Delaunay <patrick.delaunay@st.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 329dccc0 27-Oct-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

sandbox: implement reset

Up to now the sandbox would shutdown upon a cold reset request. Instead it
should be reset.

In our coding we use static variables like LIST_HEAD(efi_obj_list). A reset
can occur at any time, e.g. via an UEFI binary calling the reset service.
The only safe way to return to an initial state is to relaunch the U-Boot
binary.

The reset implementation uses execv() to relaunch U-Boot.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Simon Glass <sjg@chromium.org>

# c7e49ddc 04-Jun-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

sandbox: handling out of memory

assert() only works in debug mode. So checking a successful memory
allocation should not use assert().

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Simon Glass <sjg@chromium.org>

# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 3ff6fe5f 03-Feb-2020 Simon Glass <sjg@chromium.org>

sandbox: Add a new header for the system malloc()

Some files use U-Boot headers but still need to access the system
malloc(). Allow this by creating a new asm/malloc.h which can be used so
long as U-Boot's malloc.h has not been included.

Signed-off-by: Simon Glass <sjg@chromium.org>

# cf23c7c1 03-Feb-2020 Simon Glass <sjg@chromium.org>

sandbox: Rename 'free' variable

This name conflicts with our desire to #define free() to something else on
sandbox. Rename it.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 89694de5 06-Dec-2019 Simon Glass <sjg@chromium.org>

sandbox: Disable mmio by default in tests

When reseting sandbox for tests, disable mmio support since that is the
default state.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>

# 857f39d7 16-May-2019 Urja Rannikko <urjaman@gmail.com>

sysreset: switch to using SYSRESET_POWER_OFF for poweroff

It seems that SYSRESET_POWER_OFF was added recently, and all previous code
used SYSRESET_POWER for poweroff. SYSRESET_POWER is supposed to be a
PMIC-level power cycle, not a poweroff.

(Comment by Simon Glass)
SYSRESET_POWER means to do a power reset (removing and reinstating all power)
SYSRESET_POWER_OFF means to turn the device off and leave it off

Signed-off-by: Urja Rannikko <urjaman@gmail.com>
Reviewed-by: Patrick Delaunay <patrick.delaunay@st.com>
(Update comment to help understand the patch)
Signed-off-by: Kever Yang <kever.yang@rock-chips.com>

# 9072326a 18-May-2019 Simon Glass <sjg@chromium.org>

sandbox: Exit when SYSRESET_POWER_OFF is requested

At present this returns but it seems better to just exit sandbox
immediately.

Signed-off-by: Simon Glass <sjg@chromium.org>

reset

# 1c5a81d8 01-Oct-2018 Simon Glass <sjg@chromium.org>

sandbox: Remove the old memory file later

When debugging sandbox it is sometimes annoying that the memory file is
deleted early on. If sandbox later crashes or we quit (using the
debugger), it is not possible to run it again with the same state since
the memory file is gone.

Remove the old memory file when sandbox exits, instead. Also add debugging
showing the memory filename.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 428aa0ca 15-Sep-2018 Simon Glass <sjg@chromium.org>

sandbox: Enhance map_to_sysmem() to handle foreign pointers

At present map_sysmem() maps an address into the sandbox RAM buffer,
return a pointer, while map_to_sysmem() goes the other way.

The mapping is currently just 1:1 since a case was not found where a more
flexible mapping was needed. PCI does have a separate and more complex
mapping, but uses its own mechanism.

However this arrange cannot handle one important case, which is where a
test declares a stack variable and passes a pointer to it into a U-Boot
function which uses map_to_sysmem() to turn it into a address. Since the
pointer is not inside emulated DRAM, this will fail.

Add a mapping feature which can handle any such pointer, mapping it to a
simple tag value which can be passed around in U-Boot as an address.

Signed-off-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Alexander Graf <agraf@suse.de>

# 83d290c5 06-May-2018 Tom Rini <trini@konsulko.com>

SPDX: Convert all of our single license tags to Linux Kernel style

When U-Boot started using SPDX tags we were among the early adopters and
there weren't a lot of other examples to borrow from. So we picked the
area of the file that usually had a full license text and replaced it
with an appropriate SPDX-License-Identifier: entry. Since then, the
Linux Kernel has adopted SPDX tags and they place it as the very first
line in a file (except where shebangs are used, then it's second line)
and with slightly different comment styles than us.

In part due to community overlap, in part due to better tag visibility
and in part for other minor reasons, switch over to that style.

This commit changes all instances where we have a single declared
license in the tag as both the before and after are identical in tag
contents. There's also a few places where I found we did not have a tag
and have introduced one.

Signed-off-by: Tom Rini <trini@konsulko.com>

# 9095d5b8 13-Feb-2018 Simon Goldschmidt <sgoldschmidt@de.pepperl-fuchs.com>

fix spelling of 'functions' in 2 places (was 'funtcions')

Signed-off-by: Simon Goldschmidt <sgoldschmidt@de.pepperl-fuchs.com>

# 34b744be 18-May-2017 Simon Glass <sjg@chromium.org>

sandbox: Add a way to reset sandbox state for tests

Running a new test should reset the sandbox state to avoid tests
interferring with each other. Move the existing state-reset code into a
function so it can be used from tests.

Also update the code to reset the SPI devices and adjust the test code to
call it.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 11636258 12-May-2016 Stephen Warren <swarren@nvidia.com>

Rename reset to sysreset

The current reset API implements a method to reset the entire system.
In the near future, I'd like to introduce code that implements the device
tree reset bindings; i.e. the equivalent of the Linux kernel's reset API.
This controls resets to individual HW blocks or external chips with reset
signals. It doesn't make sense to merge the two APIs into one since they
have different semantic purposes. Resolve the naming conflict by renaming
the existing reset API to sysreset instead, so the new reset API can be
called just reset.

Signed-off-by: Stephen Warren <swarren@nvidia.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 9723563a 08-Nov-2015 Simon Glass <sjg@chromium.org>

sandbox: Add a way to skip time delays

Some tests are slow due to delays which are unnecessary on sandbox. The
worst offender is USB where we lose two seconds. Add a way to disable time
delays.

Signed-off-by: Simon Glass <sjg@chromium.org>

# dc6f4d3a 06-Jul-2015 Simon Glass <sjg@chromium.org>

sandbox: Support multiple reset types

Add settings for the last reset generated, and the types of resets which
are permitted. This will be used for testing.

Signed-off-by: Simon Glass <sjg@chromium.org>

# d73125cb 04-May-2015 Simon Glass <sjg@chromium.org>

sandbox: Correct error handling in state_read_file()

This function should return a useful error for U-Boot, rather than -1.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Joe Hershberger <joe.hershberger@ni.com>

# 88539e44 06-Feb-2015 Joe Hershberger <joe.hershberger@ni.com>

sandbox: Return '-c command' exit value as sandbox exit code

When a command is passed into sandbox using the '-c' argument the
command is run directly. This is most helpful when running tests (such
as test-dm.sh). Previously the exit code was an unused enum. Change it
to be the actual return code from the command so that the script calling
sandbox can know if the command succeeded (tests passed). Also remove
the now completely unused "exit_state" in sandbox.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 96b1046d 17-Nov-2014 Suriyan Ramasami <suriyan.r@gmail.com>

sandbox: Prepare API change for files greater than 2GB

Change the internal sandbox functions to use loff_t for file offsets.

Signed-off-by: Suriyan Ramasami <suriyan.r@gmail.com>

Acked-by: Simon Glass <sjg@chromium.org>

# ab839dc3 27-Feb-2014 Simon Glass <sjg@chromium.org>

sandbox: Add options to clean up temporary files

When jumping from one sandbox U-Boot to another in sandbox, the RAM buffer
is preserved in the jump by using a temporary file. Add an option to tell
the receiving U-Boot to remove this file when it is no longer needed.

Similarly the old U-Boot image is left behind in this case. We cannot delete
it immediately since gdb cannot then find its debug symbols. Delete it just
before exiting.

Together these changes ensure that temporary files are removed both for
memory and U-Boot.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 1209e272 10-Nov-2013 Simon Glass <sjg@chromium.org>

sandbox: Add facility to save/restore sandbox state

It is often useful to be able to save out the state from a sandbox test
run, for analysis or to restore it later to continue a test. Add generic
infrastructure for doing this using a device tree binary file. This is
a flexible tagged file format which is already supported by U-Boot, and
it supports hierarchy if needed.

Signed-off-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Hung-ying Tyan <tyanh@chromium.org>

# 5c2859cd 10-Nov-2013 Simon Glass <sjg@chromium.org>

sandbox: Allow reading/writing of RAM buffer

It is useful to be able to save and restore the RAM contents of sandbox
U-Boot either for setting up tests, for later analysys, or for chaining
together multiple tests which need to keep the same memory contents.

Add a function to provide a memory file for U-Boot. This is read on
start-up and written when shutting down. If the file does not exist
on start-up, it will be created when shutting down.

Signed-off-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Simon Glass <sjg@chromium.org>

# 1a459660 08-Jul-2013 Wolfgang Denk <wd@denx.de>

Add GPL-2.0+ SPDX-License-Identifier to source files

Signed-off-by: Wolfgang Denk <wd@denx.de>
[trini: Fixup common/cmd_io.c]
Signed-off-by: Tom Rini <trini@ti.com>

# 6fb62078 15-Feb-2012 Simon Glass <sjg@chromium.org>

sandbox: add concept of sandbox state

The state exists through the life of U-Boot. It can be adjusted by command
line options and perhaps later through a config file. It is available to
U-Boot through state_...() calls (within sandbox code).

The primary purpose of this is to contain the "hardware" state. It should
only be used by sandbox internal code.

Signed-off-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Mike Frysinger <vapier@gentoo.org>

# 9859d89b 06-Sep-2022 Simon Glass <sjg@chromium.org>

sandbox: Support loading the other FDT

We need an 'other' FDT which is different from the control FDT, so we can
check that the ofnode tests correctly handle them both.

Add this to the build along with a way to read it into the sandbox state.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 73c5cb9d 06-Sep-2022 Simon Glass <sjg@chromium.org>

sandbox: Add a function to load a relative file path

At present this implementation is specific to loading the test FDT. We
plan to load others, so create a generic function to handle this.

The path is now limited to 256 characters, to simplify the code.

When there is an empty argv[0] (which should not happen), the function now
just uses the path as is, with no prefix.

Signed-off-by: Simon Glass <sjg@chromium.org>

# d02f99dd 28-Feb-2022 Simon Glass <sjg@chromium.org>

sandbox: Show a message when writing out the ram buffer

If state is not being written, but RAM is, we should still show a message,
so it is clear that this is happening.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 185f812c 19-Jan-2022 Heinrich Schuchardt <xypron.glpk@gmx.de>

doc: replace @return by Return:

Sphinx expects Return: and not @return to indicate a return value.

find . -name '*.c' -exec \
sed -i 's/^\(\s\)\*\(\s*\)@return\(\s\)/\1*\2Return:\3/' {} \;

find . -name '*.h' -exec \
sed -i 's/^\(\s\)\*\(\s*\)@return\(\s\)/\1*\2Return:\3/' {} \;

Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>

# cb897009 24-Jul-2021 Simon Glass <sjg@chromium.org>

sandbox: Reduce keyed autoboot delay

The autoboot tests are a recent addition to U-Boot, providing much-needed
coverage in this area.

A side effect of the keyed autoboot test is that this feature is enabled
in sandbox always. This changes the autoboot prompt and confuses the
pytests. Some tests become slower, for example the vboot tests take about
27s now instead of 3s.

We don't actually need this feature enabled to be able to run the tests.
Add a switch to allow sandbox to turn it on and off as needed. Use this
in the one test that needs it.

Add a command-line flag in case this is desired in normal use.

Signed-off-by: Simon Glass <sjg@chromium.org>
Fixes: 25c8b9f298e ("test: add first autoboot unit tests")
Reviewed-by: Steffen Jaeckel <jaeckel-floss@eyet-services.de>

# 9a72bea6 13-May-2021 Simon Glass <sjg@chromium.org>

sandbox: Silence coverity warning in state_read_file()

In this case the value seems save to pass to os_free(). Add a comment.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reported-by: Coverity (CID: 165109)

# 1c52fcca 06-Feb-2021 Simon Glass <sjg@chromium.org>

sandbox: Write out bloblist when exiting

Sandbox provides a way to write out its emulated memory on exit. This
makes it possible to pass a bloblist from one phase (e.g. SPL) to the
next.

However the bloblist is not closed off, so the checksum is generally
invalid. Fix this by finishing up the bloblist before writing the memory
file.

Signed-off-by: Simon Glass <sjg@chromium.org>

# b308d9fd 06-Feb-2021 Simon Glass <sjg@chromium.org>

sandbox: Avoid using malloc() for system state

This state is not accessible to the running U-Boot but at present it is
allocated in the emulated SDRAM. This doesn't seem very useful. Adjust
it to allocate from the OS instead.

The RAM buffer is currently not freed, but should be, so add that into
state_uninit(). Update the comment for os_free() to indicate that NULL is
a valid parameter value.

Note that the strdup() in spl_board_load_image() is changed as well, since
strdup() allocates memory in the RAM buffer.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 10bb90fa 20-Nov-2020 Patrick Delaunay <patrick.delaunay@foss.st.com>

sandbox: remove ram buffer file when U-Boot is loaded by SPL

Update management of "--rm_memory" sandbox's option and force
this option when U-Boot is loaded by SPL in os_spl_to_uboot()
and remove the ram file after reading in main() as described
in option help message: "Remove memory file after reading".

This patch avoids that the file "/tmp/u-boot.mem.XXXXXX" [created in
os_jump_to_file() when U-Boot is loaded by SPL] is never deleted
because state_uninit() is not called after U-Boot execution
(CtrlC or with running pytest for example).

This issue is reproduced by
> build-sandbox_spl/spl/u-boot-spl
and CtrlC in U-Bot console

> make qcheck

One temp file is created after each SPL and U-Boot execution
(7 tims in qcheck after test_handoff.py, test_ofplatdata.py,
test_spl.py execution).

Signed-off-by: Patrick Delaunay <patrick.delaunay@st.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 329dccc0 27-Oct-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

sandbox: implement reset

Up to now the sandbox would shutdown upon a cold reset request. Instead it
should be reset.

In our coding we use static variables like LIST_HEAD(efi_obj_list). A reset
can occur at any time, e.g. via an UEFI binary calling the reset service.
The only safe way to return to an initial state is to relaunch the U-Boot
binary.

The reset implementation uses execv() to relaunch U-Boot.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Simon Glass <sjg@chromium.org>

# c7e49ddc 04-Jun-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

sandbox: handling out of memory

assert() only works in debug mode. So checking a successful memory
allocation should not use assert().

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Simon Glass <sjg@chromium.org>

# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 3ff6fe5f 03-Feb-2020 Simon Glass <sjg@chromium.org>

sandbox: Add a new header for the system malloc()

Some files use U-Boot headers but still need to access the system
malloc(). Allow this by creating a new asm/malloc.h which can be used so
long as U-Boot's malloc.h has not been included.

Signed-off-by: Simon Glass <sjg@chromium.org>

# cf23c7c1 03-Feb-2020 Simon Glass <sjg@chromium.org>

sandbox: Rename 'free' variable

This name conflicts with our desire to #define free() to something else on
sandbox. Rename it.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 89694de5 06-Dec-2019 Simon Glass <sjg@chromium.org>

sandbox: Disable mmio by default in tests

When reseting sandbox for tests, disable mmio support since that is the
default state.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>

# 857f39d7 16-May-2019 Urja Rannikko <urjaman@gmail.com>

sysreset: switch to using SYSRESET_POWER_OFF for poweroff

It seems that SYSRESET_POWER_OFF was added recently, and all previous code
used SYSRESET_POWER for poweroff. SYSRESET_POWER is supposed to be a
PMIC-level power cycle, not a poweroff.

(Comment by Simon Glass)
SYSRESET_POWER means to do a power reset (removing and reinstating all power)
SYSRESET_POWER_OFF means to turn the device off and leave it off

Signed-off-by: Urja Rannikko <urjaman@gmail.com>
Reviewed-by: Patrick Delaunay <patrick.delaunay@st.com>
(Update comment to help understand the patch)
Signed-off-by: Kever Yang <kever.yang@rock-chips.com>

# 9072326a 18-May-2019 Simon Glass <sjg@chromium.org>

sandbox: Exit when SYSRESET_POWER_OFF is requested

At present this returns but it seems better to just exit sandbox
immediately.

Signed-off-by: Simon Glass <sjg@chromium.org>

reset

# 1c5a81d8 01-Oct-2018 Simon Glass <sjg@chromium.org>

sandbox: Remove the old memory file later

When debugging sandbox it is sometimes annoying that the memory file is
deleted early on. If sandbox later crashes or we quit (using the
debugger), it is not possible to run it again with the same state since
the memory file is gone.

Remove the old memory file when sandbox exits, instead. Also add debugging
showing the memory filename.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 428aa0ca 15-Sep-2018 Simon Glass <sjg@chromium.org>

sandbox: Enhance map_to_sysmem() to handle foreign pointers

At present map_sysmem() maps an address into the sandbox RAM buffer,
return a pointer, while map_to_sysmem() goes the other way.

The mapping is currently just 1:1 since a case was not found where a more
flexible mapping was needed. PCI does have a separate and more complex
mapping, but uses its own mechanism.

However this arrange cannot handle one important case, which is where a
test declares a stack variable and passes a pointer to it into a U-Boot
function which uses map_to_sysmem() to turn it into a address. Since the
pointer is not inside emulated DRAM, this will fail.

Add a mapping feature which can handle any such pointer, mapping it to a
simple tag value which can be passed around in U-Boot as an address.

Signed-off-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Alexander Graf <agraf@suse.de>

# 83d290c5 06-May-2018 Tom Rini <trini@konsulko.com>

SPDX: Convert all of our single license tags to Linux Kernel style

When U-Boot started using SPDX tags we were among the early adopters and
there weren't a lot of other examples to borrow from. So we picked the
area of the file that usually had a full license text and replaced it
with an appropriate SPDX-License-Identifier: entry. Since then, the
Linux Kernel has adopted SPDX tags and they place it as the very first
line in a file (except where shebangs are used, then it's second line)
and with slightly different comment styles than us.

In part due to community overlap, in part due to better tag visibility
and in part for other minor reasons, switch over to that style.

This commit changes all instances where we have a single declared
license in the tag as both the before and after are identical in tag
contents. There's also a few places where I found we did not have a tag
and have introduced one.

Signed-off-by: Tom Rini <trini@konsulko.com>

# 9095d5b8 13-Feb-2018 Simon Goldschmidt <sgoldschmidt@de.pepperl-fuchs.com>

fix spelling of 'functions' in 2 places (was 'funtcions')

Signed-off-by: Simon Goldschmidt <sgoldschmidt@de.pepperl-fuchs.com>

# 34b744be 18-May-2017 Simon Glass <sjg@chromium.org>

sandbox: Add a way to reset sandbox state for tests

Running a new test should reset the sandbox state to avoid tests
interferring with each other. Move the existing state-reset code into a
function so it can be used from tests.

Also update the code to reset the SPI devices and adjust the test code to
call it.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 11636258 12-May-2016 Stephen Warren <swarren@nvidia.com>

Rename reset to sysreset

The current reset API implements a method to reset the entire system.
In the near future, I'd like to introduce code that implements the device
tree reset bindings; i.e. the equivalent of the Linux kernel's reset API.
This controls resets to individual HW blocks or external chips with reset
signals. It doesn't make sense to merge the two APIs into one since they
have different semantic purposes. Resolve the naming conflict by renaming
the existing reset API to sysreset instead, so the new reset API can be
called just reset.

Signed-off-by: Stephen Warren <swarren@nvidia.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 9723563a 08-Nov-2015 Simon Glass <sjg@chromium.org>

sandbox: Add a way to skip time delays

Some tests are slow due to delays which are unnecessary on sandbox. The
worst offender is USB where we lose two seconds. Add a way to disable time
delays.

Signed-off-by: Simon Glass <sjg@chromium.org>

# dc6f4d3a 06-Jul-2015 Simon Glass <sjg@chromium.org>

sandbox: Support multiple reset types

Add settings for the last reset generated, and the types of resets which
are permitted. This will be used for testing.

Signed-off-by: Simon Glass <sjg@chromium.org>

# d73125cb 04-May-2015 Simon Glass <sjg@chromium.org>

sandbox: Correct error handling in state_read_file()

This function should return a useful error for U-Boot, rather than -1.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Joe Hershberger <joe.hershberger@ni.com>

# 88539e44 06-Feb-2015 Joe Hershberger <joe.hershberger@ni.com>

sandbox: Return '-c command' exit value as sandbox exit code

When a command is passed into sandbox using the '-c' argument the
command is run directly. This is most helpful when running tests (such
as test-dm.sh). Previously the exit code was an unused enum. Change it
to be the actual return code from the command so that the script calling
sandbox can know if the command succeeded (tests passed). Also remove
the now completely unused "exit_state" in sandbox.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 96b1046d 17-Nov-2014 Suriyan Ramasami <suriyan.r@gmail.com>

sandbox: Prepare API change for files greater than 2GB

Change the internal sandbox functions to use loff_t for file offsets.

Signed-off-by: Suriyan Ramasami <suriyan.r@gmail.com>

Acked-by: Simon Glass <sjg@chromium.org>

# ab839dc3 27-Feb-2014 Simon Glass <sjg@chromium.org>

sandbox: Add options to clean up temporary files

When jumping from one sandbox U-Boot to another in sandbox, the RAM buffer
is preserved in the jump by using a temporary file. Add an option to tell
the receiving U-Boot to remove this file when it is no longer needed.

Similarly the old U-Boot image is left behind in this case. We cannot delete
it immediately since gdb cannot then find its debug symbols. Delete it just
before exiting.

Together these changes ensure that temporary files are removed both for
memory and U-Boot.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 1209e272 10-Nov-2013 Simon Glass <sjg@chromium.org>

sandbox: Add facility to save/restore sandbox state

It is often useful to be able to save out the state from a sandbox test
run, for analysis or to restore it later to continue a test. Add generic
infrastructure for doing this using a device tree binary file. This is
a flexible tagged file format which is already supported by U-Boot, and
it supports hierarchy if needed.

Signed-off-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Hung-ying Tyan <tyanh@chromium.org>

# 5c2859cd 10-Nov-2013 Simon Glass <sjg@chromium.org>

sandbox: Allow reading/writing of RAM buffer

It is useful to be able to save and restore the RAM contents of sandbox
U-Boot either for setting up tests, for later analysys, or for chaining
together multiple tests which need to keep the same memory contents.

Add a function to provide a memory file for U-Boot. This is read on
start-up and written when shutting down. If the file does not exist
on start-up, it will be created when shutting down.

Signed-off-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Simon Glass <sjg@chromium.org>

# 1a459660 08-Jul-2013 Wolfgang Denk <wd@denx.de>

Add GPL-2.0+ SPDX-License-Identifier to source files

Signed-off-by: Wolfgang Denk <wd@denx.de>
[trini: Fixup common/cmd_io.c]
Signed-off-by: Tom Rini <trini@ti.com>

# 6fb62078 15-Feb-2012 Simon Glass <sjg@chromium.org>

sandbox: add concept of sandbox state

The state exists through the life of U-Boot. It can be adjusted by command
line options and perhaps later through a config file. It is available to
U-Boot through state_...() calls (within sandbox code).

The primary purpose of this is to contain the "hardware" state. It should
only be used by sandbox internal code.

Signed-off-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Mike Frysinger <vapier@gentoo.org>

# d02f99dd 28-Feb-2022 Simon Glass <sjg@chromium.org>

sandbox: Show a message when writing out the ram buffer

If state is not being written, but RAM is, we should still show a message,
so it is clear that this is happening.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 185f812c 19-Jan-2022 Heinrich Schuchardt <xypron.glpk@gmx.de>

doc: replace @return by Return:

Sphinx expects Return: and not @return to indicate a return value.

find . -name '*.c' -exec \
sed -i 's/^\(\s\)\*\(\s*\)@return\(\s\)/\1*\2Return:\3/' {} \;

find . -name '*.h' -exec \
sed -i 's/^\(\s\)\*\(\s*\)@return\(\s\)/\1*\2Return:\3/' {} \;

Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>

# cb897009 24-Jul-2021 Simon Glass <sjg@chromium.org>

sandbox: Reduce keyed autoboot delay

The autoboot tests are a recent addition to U-Boot, providing much-needed
coverage in this area.

A side effect of the keyed autoboot test is that this feature is enabled
in sandbox always. This changes the autoboot prompt and confuses the
pytests. Some tests become slower, for example the vboot tests take about
27s now instead of 3s.

We don't actually need this feature enabled to be able to run the tests.
Add a switch to allow sandbox to turn it on and off as needed. Use this
in the one test that needs it.

Add a command-line flag in case this is desired in normal use.

Signed-off-by: Simon Glass <sjg@chromium.org>
Fixes: 25c8b9f298e ("test: add first autoboot unit tests")
Reviewed-by: Steffen Jaeckel <jaeckel-floss@eyet-services.de>

# 9a72bea6 13-May-2021 Simon Glass <sjg@chromium.org>

sandbox: Silence coverity warning in state_read_file()

In this case the value seems save to pass to os_free(). Add a comment.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reported-by: Coverity (CID: 165109)

# 1c52fcca 06-Feb-2021 Simon Glass <sjg@chromium.org>

sandbox: Write out bloblist when exiting

Sandbox provides a way to write out its emulated memory on exit. This
makes it possible to pass a bloblist from one phase (e.g. SPL) to the
next.

However the bloblist is not closed off, so the checksum is generally
invalid. Fix this by finishing up the bloblist before writing the memory
file.

Signed-off-by: Simon Glass <sjg@chromium.org>

# b308d9fd 06-Feb-2021 Simon Glass <sjg@chromium.org>

sandbox: Avoid using malloc() for system state

This state is not accessible to the running U-Boot but at present it is
allocated in the emulated SDRAM. This doesn't seem very useful. Adjust
it to allocate from the OS instead.

The RAM buffer is currently not freed, but should be, so add that into
state_uninit(). Update the comment for os_free() to indicate that NULL is
a valid parameter value.

Note that the strdup() in spl_board_load_image() is changed as well, since
strdup() allocates memory in the RAM buffer.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 10bb90fa 20-Nov-2020 Patrick Delaunay <patrick.delaunay@foss.st.com>

sandbox: remove ram buffer file when U-Boot is loaded by SPL

Update management of "--rm_memory" sandbox's option and force
this option when U-Boot is loaded by SPL in os_spl_to_uboot()
and remove the ram file after reading in main() as described
in option help message: "Remove memory file after reading".

This patch avoids that the file "/tmp/u-boot.mem.XXXXXX" [created in
os_jump_to_file() when U-Boot is loaded by SPL] is never deleted
because state_uninit() is not called after U-Boot execution
(CtrlC or with running pytest for example).

This issue is reproduced by
> build-sandbox_spl/spl/u-boot-spl
and CtrlC in U-Bot console

> make qcheck

One temp file is created after each SPL and U-Boot execution
(7 tims in qcheck after test_handoff.py, test_ofplatdata.py,
test_spl.py execution).

Signed-off-by: Patrick Delaunay <patrick.delaunay@st.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 329dccc0 27-Oct-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

sandbox: implement reset

Up to now the sandbox would shutdown upon a cold reset request. Instead it
should be reset.

In our coding we use static variables like LIST_HEAD(efi_obj_list). A reset
can occur at any time, e.g. via an UEFI binary calling the reset service.
The only safe way to return to an initial state is to relaunch the U-Boot
binary.

The reset implementation uses execv() to relaunch U-Boot.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Simon Glass <sjg@chromium.org>

# c7e49ddc 04-Jun-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

sandbox: handling out of memory

assert() only works in debug mode. So checking a successful memory
allocation should not use assert().

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Simon Glass <sjg@chromium.org>

# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 3ff6fe5f 03-Feb-2020 Simon Glass <sjg@chromium.org>

sandbox: Add a new header for the system malloc()

Some files use U-Boot headers but still need to access the system
malloc(). Allow this by creating a new asm/malloc.h which can be used so
long as U-Boot's malloc.h has not been included.

Signed-off-by: Simon Glass <sjg@chromium.org>

# cf23c7c1 03-Feb-2020 Simon Glass <sjg@chromium.org>

sandbox: Rename 'free' variable

This name conflicts with our desire to #define free() to something else on
sandbox. Rename it.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 89694de5 06-Dec-2019 Simon Glass <sjg@chromium.org>

sandbox: Disable mmio by default in tests

When reseting sandbox for tests, disable mmio support since that is the
default state.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>

# 857f39d7 16-May-2019 Urja Rannikko <urjaman@gmail.com>

sysreset: switch to using SYSRESET_POWER_OFF for poweroff

It seems that SYSRESET_POWER_OFF was added recently, and all previous code
used SYSRESET_POWER for poweroff. SYSRESET_POWER is supposed to be a
PMIC-level power cycle, not a poweroff.

(Comment by Simon Glass)
SYSRESET_POWER means to do a power reset (removing and reinstating all power)
SYSRESET_POWER_OFF means to turn the device off and leave it off

Signed-off-by: Urja Rannikko <urjaman@gmail.com>
Reviewed-by: Patrick Delaunay <patrick.delaunay@st.com>
(Update comment to help understand the patch)
Signed-off-by: Kever Yang <kever.yang@rock-chips.com>

# 9072326a 18-May-2019 Simon Glass <sjg@chromium.org>

sandbox: Exit when SYSRESET_POWER_OFF is requested

At present this returns but it seems better to just exit sandbox
immediately.

Signed-off-by: Simon Glass <sjg@chromium.org>

reset

# 1c5a81d8 01-Oct-2018 Simon Glass <sjg@chromium.org>

sandbox: Remove the old memory file later

When debugging sandbox it is sometimes annoying that the memory file is
deleted early on. If sandbox later crashes or we quit (using the
debugger), it is not possible to run it again with the same state since
the memory file is gone.

Remove the old memory file when sandbox exits, instead. Also add debugging
showing the memory filename.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 428aa0ca 15-Sep-2018 Simon Glass <sjg@chromium.org>

sandbox: Enhance map_to_sysmem() to handle foreign pointers

At present map_sysmem() maps an address into the sandbox RAM buffer,
return a pointer, while map_to_sysmem() goes the other way.

The mapping is currently just 1:1 since a case was not found where a more
flexible mapping was needed. PCI does have a separate and more complex
mapping, but uses its own mechanism.

However this arrange cannot handle one important case, which is where a
test declares a stack variable and passes a pointer to it into a U-Boot
function which uses map_to_sysmem() to turn it into a address. Since the
pointer is not inside emulated DRAM, this will fail.

Add a mapping feature which can handle any such pointer, mapping it to a
simple tag value which can be passed around in U-Boot as an address.

Signed-off-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Alexander Graf <agraf@suse.de>

# 83d290c5 06-May-2018 Tom Rini <trini@konsulko.com>

SPDX: Convert all of our single license tags to Linux Kernel style

When U-Boot started using SPDX tags we were among the early adopters and
there weren't a lot of other examples to borrow from. So we picked the
area of the file that usually had a full license text and replaced it
with an appropriate SPDX-License-Identifier: entry. Since then, the
Linux Kernel has adopted SPDX tags and they place it as the very first
line in a file (except where shebangs are used, then it's second line)
and with slightly different comment styles than us.

In part due to community overlap, in part due to better tag visibility
and in part for other minor reasons, switch over to that style.

This commit changes all instances where we have a single declared
license in the tag as both the before and after are identical in tag
contents. There's also a few places where I found we did not have a tag
and have introduced one.

Signed-off-by: Tom Rini <trini@konsulko.com>

# 9095d5b8 13-Feb-2018 Simon Goldschmidt <sgoldschmidt@de.pepperl-fuchs.com>

fix spelling of 'functions' in 2 places (was 'funtcions')

Signed-off-by: Simon Goldschmidt <sgoldschmidt@de.pepperl-fuchs.com>

# 34b744be 18-May-2017 Simon Glass <sjg@chromium.org>

sandbox: Add a way to reset sandbox state for tests

Running a new test should reset the sandbox state to avoid tests
interferring with each other. Move the existing state-reset code into a
function so it can be used from tests.

Also update the code to reset the SPI devices and adjust the test code to
call it.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 11636258 12-May-2016 Stephen Warren <swarren@nvidia.com>

Rename reset to sysreset

The current reset API implements a method to reset the entire system.
In the near future, I'd like to introduce code that implements the device
tree reset bindings; i.e. the equivalent of the Linux kernel's reset API.
This controls resets to individual HW blocks or external chips with reset
signals. It doesn't make sense to merge the two APIs into one since they
have different semantic purposes. Resolve the naming conflict by renaming
the existing reset API to sysreset instead, so the new reset API can be
called just reset.

Signed-off-by: Stephen Warren <swarren@nvidia.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 9723563a 08-Nov-2015 Simon Glass <sjg@chromium.org>

sandbox: Add a way to skip time delays

Some tests are slow due to delays which are unnecessary on sandbox. The
worst offender is USB where we lose two seconds. Add a way to disable time
delays.

Signed-off-by: Simon Glass <sjg@chromium.org>

# dc6f4d3a 06-Jul-2015 Simon Glass <sjg@chromium.org>

sandbox: Support multiple reset types

Add settings for the last reset generated, and the types of resets which
are permitted. This will be used for testing.

Signed-off-by: Simon Glass <sjg@chromium.org>

# d73125cb 04-May-2015 Simon Glass <sjg@chromium.org>

sandbox: Correct error handling in state_read_file()

This function should return a useful error for U-Boot, rather than -1.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Joe Hershberger <joe.hershberger@ni.com>

# 88539e44 06-Feb-2015 Joe Hershberger <joe.hershberger@ni.com>

sandbox: Return '-c command' exit value as sandbox exit code

When a command is passed into sandbox using the '-c' argument the
command is run directly. This is most helpful when running tests (such
as test-dm.sh). Previously the exit code was an unused enum. Change it
to be the actual return code from the command so that the script calling
sandbox can know if the command succeeded (tests passed). Also remove
the now completely unused "exit_state" in sandbox.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 96b1046d 17-Nov-2014 Suriyan Ramasami <suriyan.r@gmail.com>

sandbox: Prepare API change for files greater than 2GB

Change the internal sandbox functions to use loff_t for file offsets.

Signed-off-by: Suriyan Ramasami <suriyan.r@gmail.com>

Acked-by: Simon Glass <sjg@chromium.org>

# ab839dc3 27-Feb-2014 Simon Glass <sjg@chromium.org>

sandbox: Add options to clean up temporary files

When jumping from one sandbox U-Boot to another in sandbox, the RAM buffer
is preserved in the jump by using a temporary file. Add an option to tell
the receiving U-Boot to remove this file when it is no longer needed.

Similarly the old U-Boot image is left behind in this case. We cannot delete
it immediately since gdb cannot then find its debug symbols. Delete it just
before exiting.

Together these changes ensure that temporary files are removed both for
memory and U-Boot.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 1209e272 10-Nov-2013 Simon Glass <sjg@chromium.org>

sandbox: Add facility to save/restore sandbox state

It is often useful to be able to save out the state from a sandbox test
run, for analysis or to restore it later to continue a test. Add generic
infrastructure for doing this using a device tree binary file. This is
a flexible tagged file format which is already supported by U-Boot, and
it supports hierarchy if needed.

Signed-off-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Hung-ying Tyan <tyanh@chromium.org>

# 5c2859cd 10-Nov-2013 Simon Glass <sjg@chromium.org>

sandbox: Allow reading/writing of RAM buffer

It is useful to be able to save and restore the RAM contents of sandbox
U-Boot either for setting up tests, for later analysys, or for chaining
together multiple tests which need to keep the same memory contents.

Add a function to provide a memory file for U-Boot. This is read on
start-up and written when shutting down. If the file does not exist
on start-up, it will be created when shutting down.

Signed-off-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Simon Glass <sjg@chromium.org>

# 1a459660 08-Jul-2013 Wolfgang Denk <wd@denx.de>

Add GPL-2.0+ SPDX-License-Identifier to source files

Signed-off-by: Wolfgang Denk <wd@denx.de>
[trini: Fixup common/cmd_io.c]
Signed-off-by: Tom Rini <trini@ti.com>

# 6fb62078 15-Feb-2012 Simon Glass <sjg@chromium.org>

sandbox: add concept of sandbox state

The state exists through the life of U-Boot. It can be adjusted by command
line options and perhaps later through a config file. It is available to
U-Boot through state_...() calls (within sandbox code).

The primary purpose of this is to contain the "hardware" state. It should
only be used by sandbox internal code.

Signed-off-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Mike Frysinger <vapier@gentoo.org>

# 185f812c 19-Jan-2022 Heinrich Schuchardt <xypron.glpk@gmx.de>

doc: replace @return by Return:

Sphinx expects Return: and not @return to indicate a return value.

find . -name '*.c' -exec \
sed -i 's/^\(\s\)\*\(\s*\)@return\(\s\)/\1*\2Return:\3/' {} \;

find . -name '*.h' -exec \
sed -i 's/^\(\s\)\*\(\s*\)@return\(\s\)/\1*\2Return:\3/' {} \;

Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>

# cb897009 24-Jul-2021 Simon Glass <sjg@chromium.org>

sandbox: Reduce keyed autoboot delay

The autoboot tests are a recent addition to U-Boot, providing much-needed
coverage in this area.

A side effect of the keyed autoboot test is that this feature is enabled
in sandbox always. This changes the autoboot prompt and confuses the
pytests. Some tests become slower, for example the vboot tests take about
27s now instead of 3s.

We don't actually need this feature enabled to be able to run the tests.
Add a switch to allow sandbox to turn it on and off as needed. Use this
in the one test that needs it.

Add a command-line flag in case this is desired in normal use.

Signed-off-by: Simon Glass <sjg@chromium.org>
Fixes: 25c8b9f298e ("test: add first autoboot unit tests")
Reviewed-by: Steffen Jaeckel <jaeckel-floss@eyet-services.de>

# 9a72bea6 13-May-2021 Simon Glass <sjg@chromium.org>

sandbox: Silence coverity warning in state_read_file()

In this case the value seems save to pass to os_free(). Add a comment.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reported-by: Coverity (CID: 165109)

# 1c52fcca 06-Feb-2021 Simon Glass <sjg@chromium.org>

sandbox: Write out bloblist when exiting

Sandbox provides a way to write out its emulated memory on exit. This
makes it possible to pass a bloblist from one phase (e.g. SPL) to the
next.

However the bloblist is not closed off, so the checksum is generally
invalid. Fix this by finishing up the bloblist before writing the memory
file.

Signed-off-by: Simon Glass <sjg@chromium.org>

# b308d9fd 06-Feb-2021 Simon Glass <sjg@chromium.org>

sandbox: Avoid using malloc() for system state

This state is not accessible to the running U-Boot but at present it is
allocated in the emulated SDRAM. This doesn't seem very useful. Adjust
it to allocate from the OS instead.

The RAM buffer is currently not freed, but should be, so add that into
state_uninit(). Update the comment for os_free() to indicate that NULL is
a valid parameter value.

Note that the strdup() in spl_board_load_image() is changed as well, since
strdup() allocates memory in the RAM buffer.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 10bb90fa 20-Nov-2020 Patrick Delaunay <patrick.delaunay@foss.st.com>

sandbox: remove ram buffer file when U-Boot is loaded by SPL

Update management of "--rm_memory" sandbox's option and force
this option when U-Boot is loaded by SPL in os_spl_to_uboot()
and remove the ram file after reading in main() as described
in option help message: "Remove memory file after reading".

This patch avoids that the file "/tmp/u-boot.mem.XXXXXX" [created in
os_jump_to_file() when U-Boot is loaded by SPL] is never deleted
because state_uninit() is not called after U-Boot execution
(CtrlC or with running pytest for example).

This issue is reproduced by
> build-sandbox_spl/spl/u-boot-spl
and CtrlC in U-Bot console

> make qcheck

One temp file is created after each SPL and U-Boot execution
(7 tims in qcheck after test_handoff.py, test_ofplatdata.py,
test_spl.py execution).

Signed-off-by: Patrick Delaunay <patrick.delaunay@st.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 329dccc0 27-Oct-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

sandbox: implement reset

Up to now the sandbox would shutdown upon a cold reset request. Instead it
should be reset.

In our coding we use static variables like LIST_HEAD(efi_obj_list). A reset
can occur at any time, e.g. via an UEFI binary calling the reset service.
The only safe way to return to an initial state is to relaunch the U-Boot
binary.

The reset implementation uses execv() to relaunch U-Boot.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Simon Glass <sjg@chromium.org>

# c7e49ddc 04-Jun-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

sandbox: handling out of memory

assert() only works in debug mode. So checking a successful memory
allocation should not use assert().

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Simon Glass <sjg@chromium.org>

# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 3ff6fe5f 03-Feb-2020 Simon Glass <sjg@chromium.org>

sandbox: Add a new header for the system malloc()

Some files use U-Boot headers but still need to access the system
malloc(). Allow this by creating a new asm/malloc.h which can be used so
long as U-Boot's malloc.h has not been included.

Signed-off-by: Simon Glass <sjg@chromium.org>

# cf23c7c1 03-Feb-2020 Simon Glass <sjg@chromium.org>

sandbox: Rename 'free' variable

This name conflicts with our desire to #define free() to something else on
sandbox. Rename it.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 89694de5 06-Dec-2019 Simon Glass <sjg@chromium.org>

sandbox: Disable mmio by default in tests

When reseting sandbox for tests, disable mmio support since that is the
default state.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>

# 857f39d7 16-May-2019 Urja Rannikko <urjaman@gmail.com>

sysreset: switch to using SYSRESET_POWER_OFF for poweroff

It seems that SYSRESET_POWER_OFF was added recently, and all previous code
used SYSRESET_POWER for poweroff. SYSRESET_POWER is supposed to be a
PMIC-level power cycle, not a poweroff.

(Comment by Simon Glass)
SYSRESET_POWER means to do a power reset (removing and reinstating all power)
SYSRESET_POWER_OFF means to turn the device off and leave it off

Signed-off-by: Urja Rannikko <urjaman@gmail.com>
Reviewed-by: Patrick Delaunay <patrick.delaunay@st.com>
(Update comment to help understand the patch)
Signed-off-by: Kever Yang <kever.yang@rock-chips.com>

# 9072326a 18-May-2019 Simon Glass <sjg@chromium.org>

sandbox: Exit when SYSRESET_POWER_OFF is requested

At present this returns but it seems better to just exit sandbox
immediately.

Signed-off-by: Simon Glass <sjg@chromium.org>

reset

# 1c5a81d8 01-Oct-2018 Simon Glass <sjg@chromium.org>

sandbox: Remove the old memory file later

When debugging sandbox it is sometimes annoying that the memory file is
deleted early on. If sandbox later crashes or we quit (using the
debugger), it is not possible to run it again with the same state since
the memory file is gone.

Remove the old memory file when sandbox exits, instead. Also add debugging
showing the memory filename.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 428aa0ca 15-Sep-2018 Simon Glass <sjg@chromium.org>

sandbox: Enhance map_to_sysmem() to handle foreign pointers

At present map_sysmem() maps an address into the sandbox RAM buffer,
return a pointer, while map_to_sysmem() goes the other way.

The mapping is currently just 1:1 since a case was not found where a more
flexible mapping was needed. PCI does have a separate and more complex
mapping, but uses its own mechanism.

However this arrange cannot handle one important case, which is where a
test declares a stack variable and passes a pointer to it into a U-Boot
function which uses map_to_sysmem() to turn it into a address. Since the
pointer is not inside emulated DRAM, this will fail.

Add a mapping feature which can handle any such pointer, mapping it to a
simple tag value which can be passed around in U-Boot as an address.

Signed-off-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Alexander Graf <agraf@suse.de>

# 83d290c5 06-May-2018 Tom Rini <trini@konsulko.com>

SPDX: Convert all of our single license tags to Linux Kernel style

When U-Boot started using SPDX tags we were among the early adopters and
there weren't a lot of other examples to borrow from. So we picked the
area of the file that usually had a full license text and replaced it
with an appropriate SPDX-License-Identifier: entry. Since then, the
Linux Kernel has adopted SPDX tags and they place it as the very first
line in a file (except where shebangs are used, then it's second line)
and with slightly different comment styles than us.

In part due to community overlap, in part due to better tag visibility
and in part for other minor reasons, switch over to that style.

This commit changes all instances where we have a single declared
license in the tag as both the before and after are identical in tag
contents. There's also a few places where I found we did not have a tag
and have introduced one.

Signed-off-by: Tom Rini <trini@konsulko.com>

# 9095d5b8 13-Feb-2018 Simon Goldschmidt <sgoldschmidt@de.pepperl-fuchs.com>

fix spelling of 'functions' in 2 places (was 'funtcions')

Signed-off-by: Simon Goldschmidt <sgoldschmidt@de.pepperl-fuchs.com>

# 34b744be 18-May-2017 Simon Glass <sjg@chromium.org>

sandbox: Add a way to reset sandbox state for tests

Running a new test should reset the sandbox state to avoid tests
interferring with each other. Move the existing state-reset code into a
function so it can be used from tests.

Also update the code to reset the SPI devices and adjust the test code to
call it.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 11636258 12-May-2016 Stephen Warren <swarren@nvidia.com>

Rename reset to sysreset

The current reset API implements a method to reset the entire system.
In the near future, I'd like to introduce code that implements the device
tree reset bindings; i.e. the equivalent of the Linux kernel's reset API.
This controls resets to individual HW blocks or external chips with reset
signals. It doesn't make sense to merge the two APIs into one since they
have different semantic purposes. Resolve the naming conflict by renaming
the existing reset API to sysreset instead, so the new reset API can be
called just reset.

Signed-off-by: Stephen Warren <swarren@nvidia.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 9723563a 08-Nov-2015 Simon Glass <sjg@chromium.org>

sandbox: Add a way to skip time delays

Some tests are slow due to delays which are unnecessary on sandbox. The
worst offender is USB where we lose two seconds. Add a way to disable time
delays.

Signed-off-by: Simon Glass <sjg@chromium.org>

# dc6f4d3a 06-Jul-2015 Simon Glass <sjg@chromium.org>

sandbox: Support multiple reset types

Add settings for the last reset generated, and the types of resets which
are permitted. This will be used for testing.

Signed-off-by: Simon Glass <sjg@chromium.org>

# d73125cb 04-May-2015 Simon Glass <sjg@chromium.org>

sandbox: Correct error handling in state_read_file()

This function should return a useful error for U-Boot, rather than -1.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Joe Hershberger <joe.hershberger@ni.com>

# 88539e44 06-Feb-2015 Joe Hershberger <joe.hershberger@ni.com>

sandbox: Return '-c command' exit value as sandbox exit code

When a command is passed into sandbox using the '-c' argument the
command is run directly. This is most helpful when running tests (such
as test-dm.sh). Previously the exit code was an unused enum. Change it
to be the actual return code from the command so that the script calling
sandbox can know if the command succeeded (tests passed). Also remove
the now completely unused "exit_state" in sandbox.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 96b1046d 17-Nov-2014 Suriyan Ramasami <suriyan.r@gmail.com>

sandbox: Prepare API change for files greater than 2GB

Change the internal sandbox functions to use loff_t for file offsets.

Signed-off-by: Suriyan Ramasami <suriyan.r@gmail.com>

Acked-by: Simon Glass <sjg@chromium.org>

# ab839dc3 27-Feb-2014 Simon Glass <sjg@chromium.org>

sandbox: Add options to clean up temporary files

When jumping from one sandbox U-Boot to another in sandbox, the RAM buffer
is preserved in the jump by using a temporary file. Add an option to tell
the receiving U-Boot to remove this file when it is no longer needed.

Similarly the old U-Boot image is left behind in this case. We cannot delete
it immediately since gdb cannot then find its debug symbols. Delete it just
before exiting.

Together these changes ensure that temporary files are removed both for
memory and U-Boot.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 1209e272 10-Nov-2013 Simon Glass <sjg@chromium.org>

sandbox: Add facility to save/restore sandbox state

It is often useful to be able to save out the state from a sandbox test
run, for analysis or to restore it later to continue a test. Add generic
infrastructure for doing this using a device tree binary file. This is
a flexible tagged file format which is already supported by U-Boot, and
it supports hierarchy if needed.

Signed-off-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Hung-ying Tyan <tyanh@chromium.org>

# 5c2859cd 10-Nov-2013 Simon Glass <sjg@chromium.org>

sandbox: Allow reading/writing of RAM buffer

It is useful to be able to save and restore the RAM contents of sandbox
U-Boot either for setting up tests, for later analysys, or for chaining
together multiple tests which need to keep the same memory contents.

Add a function to provide a memory file for U-Boot. This is read on
start-up and written when shutting down. If the file does not exist
on start-up, it will be created when shutting down.

Signed-off-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Simon Glass <sjg@chromium.org>

# 1a459660 08-Jul-2013 Wolfgang Denk <wd@denx.de>

Add GPL-2.0+ SPDX-License-Identifier to source files

Signed-off-by: Wolfgang Denk <wd@denx.de>
[trini: Fixup common/cmd_io.c]
Signed-off-by: Tom Rini <trini@ti.com>

# 6fb62078 15-Feb-2012 Simon Glass <sjg@chromium.org>

sandbox: add concept of sandbox state

The state exists through the life of U-Boot. It can be adjusted by command
line options and perhaps later through a config file. It is available to
U-Boot through state_...() calls (within sandbox code).

The primary purpose of this is to contain the "hardware" state. It should
only be used by sandbox internal code.

Signed-off-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Mike Frysinger <vapier@gentoo.org>

# cb897009 24-Jul-2021 Simon Glass <sjg@chromium.org>

sandbox: Reduce keyed autoboot delay

The autoboot tests are a recent addition to U-Boot, providing much-needed
coverage in this area.

A side effect of the keyed autoboot test is that this feature is enabled
in sandbox always. This changes the autoboot prompt and confuses the
pytests. Some tests become slower, for example the vboot tests take about
27s now instead of 3s.

We don't actually need this feature enabled to be able to run the tests.
Add a switch to allow sandbox to turn it on and off as needed. Use this
in the one test that needs it.

Add a command-line flag in case this is desired in normal use.

Signed-off-by: Simon Glass <sjg@chromium.org>
Fixes: 25c8b9f298e ("test: add first autoboot unit tests")
Reviewed-by: Steffen Jaeckel <jaeckel-floss@eyet-services.de>

# 9a72bea6 13-May-2021 Simon Glass <sjg@chromium.org>

sandbox: Silence coverity warning in state_read_file()

In this case the value seems save to pass to os_free(). Add a comment.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reported-by: Coverity (CID: 165109)

# 1c52fcca 06-Feb-2021 Simon Glass <sjg@chromium.org>

sandbox: Write out bloblist when exiting

Sandbox provides a way to write out its emulated memory on exit. This
makes it possible to pass a bloblist from one phase (e.g. SPL) to the
next.

However the bloblist is not closed off, so the checksum is generally
invalid. Fix this by finishing up the bloblist before writing the memory
file.

Signed-off-by: Simon Glass <sjg@chromium.org>

# b308d9fd 06-Feb-2021 Simon Glass <sjg@chromium.org>

sandbox: Avoid using malloc() for system state

This state is not accessible to the running U-Boot but at present it is
allocated in the emulated SDRAM. This doesn't seem very useful. Adjust
it to allocate from the OS instead.

The RAM buffer is currently not freed, but should be, so add that into
state_uninit(). Update the comment for os_free() to indicate that NULL is
a valid parameter value.

Note that the strdup() in spl_board_load_image() is changed as well, since
strdup() allocates memory in the RAM buffer.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 10bb90fa 20-Nov-2020 Patrick Delaunay <patrick.delaunay@foss.st.com>

sandbox: remove ram buffer file when U-Boot is loaded by SPL

Update management of "--rm_memory" sandbox's option and force
this option when U-Boot is loaded by SPL in os_spl_to_uboot()
and remove the ram file after reading in main() as described
in option help message: "Remove memory file after reading".

This patch avoids that the file "/tmp/u-boot.mem.XXXXXX" [created in
os_jump_to_file() when U-Boot is loaded by SPL] is never deleted
because state_uninit() is not called after U-Boot execution
(CtrlC or with running pytest for example).

This issue is reproduced by
> build-sandbox_spl/spl/u-boot-spl
and CtrlC in U-Bot console

> make qcheck

One temp file is created after each SPL and U-Boot execution
(7 tims in qcheck after test_handoff.py, test_ofplatdata.py,
test_spl.py execution).

Signed-off-by: Patrick Delaunay <patrick.delaunay@st.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 329dccc0 27-Oct-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

sandbox: implement reset

Up to now the sandbox would shutdown upon a cold reset request. Instead it
should be reset.

In our coding we use static variables like LIST_HEAD(efi_obj_list). A reset
can occur at any time, e.g. via an UEFI binary calling the reset service.
The only safe way to return to an initial state is to relaunch the U-Boot
binary.

The reset implementation uses execv() to relaunch U-Boot.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Simon Glass <sjg@chromium.org>

# c7e49ddc 04-Jun-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

sandbox: handling out of memory

assert() only works in debug mode. So checking a successful memory
allocation should not use assert().

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Simon Glass <sjg@chromium.org>

# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 3ff6fe5f 03-Feb-2020 Simon Glass <sjg@chromium.org>

sandbox: Add a new header for the system malloc()

Some files use U-Boot headers but still need to access the system
malloc(). Allow this by creating a new asm/malloc.h which can be used so
long as U-Boot's malloc.h has not been included.

Signed-off-by: Simon Glass <sjg@chromium.org>

# cf23c7c1 03-Feb-2020 Simon Glass <sjg@chromium.org>

sandbox: Rename 'free' variable

This name conflicts with our desire to #define free() to something else on
sandbox. Rename it.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 89694de5 06-Dec-2019 Simon Glass <sjg@chromium.org>

sandbox: Disable mmio by default in tests

When reseting sandbox for tests, disable mmio support since that is the
default state.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>

# 857f39d7 16-May-2019 Urja Rannikko <urjaman@gmail.com>

sysreset: switch to using SYSRESET_POWER_OFF for poweroff

It seems that SYSRESET_POWER_OFF was added recently, and all previous code
used SYSRESET_POWER for poweroff. SYSRESET_POWER is supposed to be a
PMIC-level power cycle, not a poweroff.

(Comment by Simon Glass)
SYSRESET_POWER means to do a power reset (removing and reinstating all power)
SYSRESET_POWER_OFF means to turn the device off and leave it off

Signed-off-by: Urja Rannikko <urjaman@gmail.com>
Reviewed-by: Patrick Delaunay <patrick.delaunay@st.com>
(Update comment to help understand the patch)
Signed-off-by: Kever Yang <kever.yang@rock-chips.com>

# 9072326a 18-May-2019 Simon Glass <sjg@chromium.org>

sandbox: Exit when SYSRESET_POWER_OFF is requested

At present this returns but it seems better to just exit sandbox
immediately.

Signed-off-by: Simon Glass <sjg@chromium.org>

reset

# 1c5a81d8 01-Oct-2018 Simon Glass <sjg@chromium.org>

sandbox: Remove the old memory file later

When debugging sandbox it is sometimes annoying that the memory file is
deleted early on. If sandbox later crashes or we quit (using the
debugger), it is not possible to run it again with the same state since
the memory file is gone.

Remove the old memory file when sandbox exits, instead. Also add debugging
showing the memory filename.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 428aa0ca 15-Sep-2018 Simon Glass <sjg@chromium.org>

sandbox: Enhance map_to_sysmem() to handle foreign pointers

At present map_sysmem() maps an address into the sandbox RAM buffer,
return a pointer, while map_to_sysmem() goes the other way.

The mapping is currently just 1:1 since a case was not found where a more
flexible mapping was needed. PCI does have a separate and more complex
mapping, but uses its own mechanism.

However this arrange cannot handle one important case, which is where a
test declares a stack variable and passes a pointer to it into a U-Boot
function which uses map_to_sysmem() to turn it into a address. Since the
pointer is not inside emulated DRAM, this will fail.

Add a mapping feature which can handle any such pointer, mapping it to a
simple tag value which can be passed around in U-Boot as an address.

Signed-off-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Alexander Graf <agraf@suse.de>

# 83d290c5 06-May-2018 Tom Rini <trini@konsulko.com>

SPDX: Convert all of our single license tags to Linux Kernel style

When U-Boot started using SPDX tags we were among the early adopters and
there weren't a lot of other examples to borrow from. So we picked the
area of the file that usually had a full license text and replaced it
with an appropriate SPDX-License-Identifier: entry. Since then, the
Linux Kernel has adopted SPDX tags and they place it as the very first
line in a file (except where shebangs are used, then it's second line)
and with slightly different comment styles than us.

In part due to community overlap, in part due to better tag visibility
and in part for other minor reasons, switch over to that style.

This commit changes all instances where we have a single declared
license in the tag as both the before and after are identical in tag
contents. There's also a few places where I found we did not have a tag
and have introduced one.

Signed-off-by: Tom Rini <trini@konsulko.com>

# 9095d5b8 13-Feb-2018 Simon Goldschmidt <sgoldschmidt@de.pepperl-fuchs.com>

fix spelling of 'functions' in 2 places (was 'funtcions')

Signed-off-by: Simon Goldschmidt <sgoldschmidt@de.pepperl-fuchs.com>

# 34b744be 18-May-2017 Simon Glass <sjg@chromium.org>

sandbox: Add a way to reset sandbox state for tests

Running a new test should reset the sandbox state to avoid tests
interferring with each other. Move the existing state-reset code into a
function so it can be used from tests.

Also update the code to reset the SPI devices and adjust the test code to
call it.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 11636258 12-May-2016 Stephen Warren <swarren@nvidia.com>

Rename reset to sysreset

The current reset API implements a method to reset the entire system.
In the near future, I'd like to introduce code that implements the device
tree reset bindings; i.e. the equivalent of the Linux kernel's reset API.
This controls resets to individual HW blocks or external chips with reset
signals. It doesn't make sense to merge the two APIs into one since they
have different semantic purposes. Resolve the naming conflict by renaming
the existing reset API to sysreset instead, so the new reset API can be
called just reset.

Signed-off-by: Stephen Warren <swarren@nvidia.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 9723563a 08-Nov-2015 Simon Glass <sjg@chromium.org>

sandbox: Add a way to skip time delays

Some tests are slow due to delays which are unnecessary on sandbox. The
worst offender is USB where we lose two seconds. Add a way to disable time
delays.

Signed-off-by: Simon Glass <sjg@chromium.org>

# dc6f4d3a 06-Jul-2015 Simon Glass <sjg@chromium.org>

sandbox: Support multiple reset types

Add settings for the last reset generated, and the types of resets which
are permitted. This will be used for testing.

Signed-off-by: Simon Glass <sjg@chromium.org>

# d73125cb 04-May-2015 Simon Glass <sjg@chromium.org>

sandbox: Correct error handling in state_read_file()

This function should return a useful error for U-Boot, rather than -1.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Joe Hershberger <joe.hershberger@ni.com>

# 88539e44 06-Feb-2015 Joe Hershberger <joe.hershberger@ni.com>

sandbox: Return '-c command' exit value as sandbox exit code

When a command is passed into sandbox using the '-c' argument the
command is run directly. This is most helpful when running tests (such
as test-dm.sh). Previously the exit code was an unused enum. Change it
to be the actual return code from the command so that the script calling
sandbox can know if the command succeeded (tests passed). Also remove
the now completely unused "exit_state" in sandbox.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 96b1046d 17-Nov-2014 Suriyan Ramasami <suriyan.r@gmail.com>

sandbox: Prepare API change for files greater than 2GB

Change the internal sandbox functions to use loff_t for file offsets.

Signed-off-by: Suriyan Ramasami <suriyan.r@gmail.com>

Acked-by: Simon Glass <sjg@chromium.org>

# ab839dc3 27-Feb-2014 Simon Glass <sjg@chromium.org>

sandbox: Add options to clean up temporary files

When jumping from one sandbox U-Boot to another in sandbox, the RAM buffer
is preserved in the jump by using a temporary file. Add an option to tell
the receiving U-Boot to remove this file when it is no longer needed.

Similarly the old U-Boot image is left behind in this case. We cannot delete
it immediately since gdb cannot then find its debug symbols. Delete it just
before exiting.

Together these changes ensure that temporary files are removed both for
memory and U-Boot.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 1209e272 10-Nov-2013 Simon Glass <sjg@chromium.org>

sandbox: Add facility to save/restore sandbox state

It is often useful to be able to save out the state from a sandbox test
run, for analysis or to restore it later to continue a test. Add generic
infrastructure for doing this using a device tree binary file. This is
a flexible tagged file format which is already supported by U-Boot, and
it supports hierarchy if needed.

Signed-off-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Hung-ying Tyan <tyanh@chromium.org>

# 5c2859cd 10-Nov-2013 Simon Glass <sjg@chromium.org>

sandbox: Allow reading/writing of RAM buffer

It is useful to be able to save and restore the RAM contents of sandbox
U-Boot either for setting up tests, for later analysys, or for chaining
together multiple tests which need to keep the same memory contents.

Add a function to provide a memory file for U-Boot. This is read on
start-up and written when shutting down. If the file does not exist
on start-up, it will be created when shutting down.

Signed-off-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Simon Glass <sjg@chromium.org>

# 1a459660 08-Jul-2013 Wolfgang Denk <wd@denx.de>

Add GPL-2.0+ SPDX-License-Identifier to source files

Signed-off-by: Wolfgang Denk <wd@denx.de>
[trini: Fixup common/cmd_io.c]
Signed-off-by: Tom Rini <trini@ti.com>

# 6fb62078 15-Feb-2012 Simon Glass <sjg@chromium.org>

sandbox: add concept of sandbox state

The state exists through the life of U-Boot. It can be adjusted by command
line options and perhaps later through a config file. It is available to
U-Boot through state_...() calls (within sandbox code).

The primary purpose of this is to contain the "hardware" state. It should
only be used by sandbox internal code.

Signed-off-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Mike Frysinger <vapier@gentoo.org>

# 9a72bea6 13-May-2021 Simon Glass <sjg@chromium.org>

sandbox: Silence coverity warning in state_read_file()

In this case the value seems save to pass to os_free(). Add a comment.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reported-by: Coverity (CID: 165109)

# 1c52fcca 06-Feb-2021 Simon Glass <sjg@chromium.org>

sandbox: Write out bloblist when exiting

Sandbox provides a way to write out its emulated memory on exit. This
makes it possible to pass a bloblist from one phase (e.g. SPL) to the
next.

However the bloblist is not closed off, so the checksum is generally
invalid. Fix this by finishing up the bloblist before writing the memory
file.

Signed-off-by: Simon Glass <sjg@chromium.org>

# b308d9fd 06-Feb-2021 Simon Glass <sjg@chromium.org>

sandbox: Avoid using malloc() for system state

This state is not accessible to the running U-Boot but at present it is
allocated in the emulated SDRAM. This doesn't seem very useful. Adjust
it to allocate from the OS instead.

The RAM buffer is currently not freed, but should be, so add that into
state_uninit(). Update the comment for os_free() to indicate that NULL is
a valid parameter value.

Note that the strdup() in spl_board_load_image() is changed as well, since
strdup() allocates memory in the RAM buffer.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 10bb90fa 20-Nov-2020 Patrick Delaunay <patrick.delaunay@foss.st.com>

sandbox: remove ram buffer file when U-Boot is loaded by SPL

Update management of "--rm_memory" sandbox's option and force
this option when U-Boot is loaded by SPL in os_spl_to_uboot()
and remove the ram file after reading in main() as described
in option help message: "Remove memory file after reading".

This patch avoids that the file "/tmp/u-boot.mem.XXXXXX" [created in
os_jump_to_file() when U-Boot is loaded by SPL] is never deleted
because state_uninit() is not called after U-Boot execution
(CtrlC or with running pytest for example).

This issue is reproduced by
> build-sandbox_spl/spl/u-boot-spl
and CtrlC in U-Bot console

> make qcheck

One temp file is created after each SPL and U-Boot execution
(7 tims in qcheck after test_handoff.py, test_ofplatdata.py,
test_spl.py execution).

Signed-off-by: Patrick Delaunay <patrick.delaunay@st.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 329dccc0 27-Oct-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

sandbox: implement reset

Up to now the sandbox would shutdown upon a cold reset request. Instead it
should be reset.

In our coding we use static variables like LIST_HEAD(efi_obj_list). A reset
can occur at any time, e.g. via an UEFI binary calling the reset service.
The only safe way to return to an initial state is to relaunch the U-Boot
binary.

The reset implementation uses execv() to relaunch U-Boot.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Simon Glass <sjg@chromium.org>

# c7e49ddc 04-Jun-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

sandbox: handling out of memory

assert() only works in debug mode. So checking a successful memory
allocation should not use assert().

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Simon Glass <sjg@chromium.org>

# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 3ff6fe5f 03-Feb-2020 Simon Glass <sjg@chromium.org>

sandbox: Add a new header for the system malloc()

Some files use U-Boot headers but still need to access the system
malloc(). Allow this by creating a new asm/malloc.h which can be used so
long as U-Boot's malloc.h has not been included.

Signed-off-by: Simon Glass <sjg@chromium.org>

# cf23c7c1 03-Feb-2020 Simon Glass <sjg@chromium.org>

sandbox: Rename 'free' variable

This name conflicts with our desire to #define free() to something else on
sandbox. Rename it.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 89694de5 06-Dec-2019 Simon Glass <sjg@chromium.org>

sandbox: Disable mmio by default in tests

When reseting sandbox for tests, disable mmio support since that is the
default state.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>

# 857f39d7 16-May-2019 Urja Rannikko <urjaman@gmail.com>

sysreset: switch to using SYSRESET_POWER_OFF for poweroff

It seems that SYSRESET_POWER_OFF was added recently, and all previous code
used SYSRESET_POWER for poweroff. SYSRESET_POWER is supposed to be a
PMIC-level power cycle, not a poweroff.

(Comment by Simon Glass)
SYSRESET_POWER means to do a power reset (removing and reinstating all power)
SYSRESET_POWER_OFF means to turn the device off and leave it off

Signed-off-by: Urja Rannikko <urjaman@gmail.com>
Reviewed-by: Patrick Delaunay <patrick.delaunay@st.com>
(Update comment to help understand the patch)
Signed-off-by: Kever Yang <kever.yang@rock-chips.com>

# 9072326a 18-May-2019 Simon Glass <sjg@chromium.org>

sandbox: Exit when SYSRESET_POWER_OFF is requested

At present this returns but it seems better to just exit sandbox
immediately.

Signed-off-by: Simon Glass <sjg@chromium.org>

reset

# 1c5a81d8 01-Oct-2018 Simon Glass <sjg@chromium.org>

sandbox: Remove the old memory file later

When debugging sandbox it is sometimes annoying that the memory file is
deleted early on. If sandbox later crashes or we quit (using the
debugger), it is not possible to run it again with the same state since
the memory file is gone.

Remove the old memory file when sandbox exits, instead. Also add debugging
showing the memory filename.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 428aa0ca 15-Sep-2018 Simon Glass <sjg@chromium.org>

sandbox: Enhance map_to_sysmem() to handle foreign pointers

At present map_sysmem() maps an address into the sandbox RAM buffer,
return a pointer, while map_to_sysmem() goes the other way.

The mapping is currently just 1:1 since a case was not found where a more
flexible mapping was needed. PCI does have a separate and more complex
mapping, but uses its own mechanism.

However this arrange cannot handle one important case, which is where a
test declares a stack variable and passes a pointer to it into a U-Boot
function which uses map_to_sysmem() to turn it into a address. Since the
pointer is not inside emulated DRAM, this will fail.

Add a mapping feature which can handle any such pointer, mapping it to a
simple tag value which can be passed around in U-Boot as an address.

Signed-off-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Alexander Graf <agraf@suse.de>

# 83d290c5 06-May-2018 Tom Rini <trini@konsulko.com>

SPDX: Convert all of our single license tags to Linux Kernel style

When U-Boot started using SPDX tags we were among the early adopters and
there weren't a lot of other examples to borrow from. So we picked the
area of the file that usually had a full license text and replaced it
with an appropriate SPDX-License-Identifier: entry. Since then, the
Linux Kernel has adopted SPDX tags and they place it as the very first
line in a file (except where shebangs are used, then it's second line)
and with slightly different comment styles than us.

In part due to community overlap, in part due to better tag visibility
and in part for other minor reasons, switch over to that style.

This commit changes all instances where we have a single declared
license in the tag as both the before and after are identical in tag
contents. There's also a few places where I found we did not have a tag
and have introduced one.

Signed-off-by: Tom Rini <trini@konsulko.com>

# 9095d5b8 13-Feb-2018 Simon Goldschmidt <sgoldschmidt@de.pepperl-fuchs.com>

fix spelling of 'functions' in 2 places (was 'funtcions')

Signed-off-by: Simon Goldschmidt <sgoldschmidt@de.pepperl-fuchs.com>

# 34b744be 18-May-2017 Simon Glass <sjg@chromium.org>

sandbox: Add a way to reset sandbox state for tests

Running a new test should reset the sandbox state to avoid tests
interferring with each other. Move the existing state-reset code into a
function so it can be used from tests.

Also update the code to reset the SPI devices and adjust the test code to
call it.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 11636258 12-May-2016 Stephen Warren <swarren@nvidia.com>

Rename reset to sysreset

The current reset API implements a method to reset the entire system.
In the near future, I'd like to introduce code that implements the device
tree reset bindings; i.e. the equivalent of the Linux kernel's reset API.
This controls resets to individual HW blocks or external chips with reset
signals. It doesn't make sense to merge the two APIs into one since they
have different semantic purposes. Resolve the naming conflict by renaming
the existing reset API to sysreset instead, so the new reset API can be
called just reset.

Signed-off-by: Stephen Warren <swarren@nvidia.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 9723563a 08-Nov-2015 Simon Glass <sjg@chromium.org>

sandbox: Add a way to skip time delays

Some tests are slow due to delays which are unnecessary on sandbox. The
worst offender is USB where we lose two seconds. Add a way to disable time
delays.

Signed-off-by: Simon Glass <sjg@chromium.org>

# dc6f4d3a 06-Jul-2015 Simon Glass <sjg@chromium.org>

sandbox: Support multiple reset types

Add settings for the last reset generated, and the types of resets which
are permitted. This will be used for testing.

Signed-off-by: Simon Glass <sjg@chromium.org>

# d73125cb 04-May-2015 Simon Glass <sjg@chromium.org>

sandbox: Correct error handling in state_read_file()

This function should return a useful error for U-Boot, rather than -1.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Joe Hershberger <joe.hershberger@ni.com>

# 88539e44 06-Feb-2015 Joe Hershberger <joe.hershberger@ni.com>

sandbox: Return '-c command' exit value as sandbox exit code

When a command is passed into sandbox using the '-c' argument the
command is run directly. This is most helpful when running tests (such
as test-dm.sh). Previously the exit code was an unused enum. Change it
to be the actual return code from the command so that the script calling
sandbox can know if the command succeeded (tests passed). Also remove
the now completely unused "exit_state" in sandbox.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 96b1046d 17-Nov-2014 Suriyan Ramasami <suriyan.r@gmail.com>

sandbox: Prepare API change for files greater than 2GB

Change the internal sandbox functions to use loff_t for file offsets.

Signed-off-by: Suriyan Ramasami <suriyan.r@gmail.com>

Acked-by: Simon Glass <sjg@chromium.org>

# ab839dc3 27-Feb-2014 Simon Glass <sjg@chromium.org>

sandbox: Add options to clean up temporary files

When jumping from one sandbox U-Boot to another in sandbox, the RAM buffer
is preserved in the jump by using a temporary file. Add an option to tell
the receiving U-Boot to remove this file when it is no longer needed.

Similarly the old U-Boot image is left behind in this case. We cannot delete
it immediately since gdb cannot then find its debug symbols. Delete it just
before exiting.

Together these changes ensure that temporary files are removed both for
memory and U-Boot.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 1209e272 10-Nov-2013 Simon Glass <sjg@chromium.org>

sandbox: Add facility to save/restore sandbox state

It is often useful to be able to save out the state from a sandbox test
run, for analysis or to restore it later to continue a test. Add generic
infrastructure for doing this using a device tree binary file. This is
a flexible tagged file format which is already supported by U-Boot, and
it supports hierarchy if needed.

Signed-off-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Hung-ying Tyan <tyanh@chromium.org>

# 5c2859cd 10-Nov-2013 Simon Glass <sjg@chromium.org>

sandbox: Allow reading/writing of RAM buffer

It is useful to be able to save and restore the RAM contents of sandbox
U-Boot either for setting up tests, for later analysys, or for chaining
together multiple tests which need to keep the same memory contents.

Add a function to provide a memory file for U-Boot. This is read on
start-up and written when shutting down. If the file does not exist
on start-up, it will be created when shutting down.

Signed-off-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Simon Glass <sjg@chromium.org>

# 1a459660 08-Jul-2013 Wolfgang Denk <wd@denx.de>

Add GPL-2.0+ SPDX-License-Identifier to source files

Signed-off-by: Wolfgang Denk <wd@denx.de>
[trini: Fixup common/cmd_io.c]
Signed-off-by: Tom Rini <trini@ti.com>

# 6fb62078 15-Feb-2012 Simon Glass <sjg@chromium.org>

sandbox: add concept of sandbox state

The state exists through the life of U-Boot. It can be adjusted by command
line options and perhaps later through a config file. It is available to
U-Boot through state_...() calls (within sandbox code).

The primary purpose of this is to contain the "hardware" state. It should
only be used by sandbox internal code.

Signed-off-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Mike Frysinger <vapier@gentoo.org>

# 1c52fcca 06-Feb-2021 Simon Glass <sjg@chromium.org>

sandbox: Write out bloblist when exiting

Sandbox provides a way to write out its emulated memory on exit. This
makes it possible to pass a bloblist from one phase (e.g. SPL) to the
next.

However the bloblist is not closed off, so the checksum is generally
invalid. Fix this by finishing up the bloblist before writing the memory
file.

Signed-off-by: Simon Glass <sjg@chromium.org>

# b308d9fd 06-Feb-2021 Simon Glass <sjg@chromium.org>

sandbox: Avoid using malloc() for system state

This state is not accessible to the running U-Boot but at present it is
allocated in the emulated SDRAM. This doesn't seem very useful. Adjust
it to allocate from the OS instead.

The RAM buffer is currently not freed, but should be, so add that into
state_uninit(). Update the comment for os_free() to indicate that NULL is
a valid parameter value.

Note that the strdup() in spl_board_load_image() is changed as well, since
strdup() allocates memory in the RAM buffer.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 10bb90fa 20-Nov-2020 Patrick Delaunay <patrick.delaunay@foss.st.com>

sandbox: remove ram buffer file when U-Boot is loaded by SPL

Update management of "--rm_memory" sandbox's option and force
this option when U-Boot is loaded by SPL in os_spl_to_uboot()
and remove the ram file after reading in main() as described
in option help message: "Remove memory file after reading".

This patch avoids that the file "/tmp/u-boot.mem.XXXXXX" [created in
os_jump_to_file() when U-Boot is loaded by SPL] is never deleted
because state_uninit() is not called after U-Boot execution
(CtrlC or with running pytest for example).

This issue is reproduced by
> build-sandbox_spl/spl/u-boot-spl
and CtrlC in U-Bot console

> make qcheck

One temp file is created after each SPL and U-Boot execution
(7 tims in qcheck after test_handoff.py, test_ofplatdata.py,
test_spl.py execution).

Signed-off-by: Patrick Delaunay <patrick.delaunay@st.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 329dccc0 27-Oct-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

sandbox: implement reset

Up to now the sandbox would shutdown upon a cold reset request. Instead it
should be reset.

In our coding we use static variables like LIST_HEAD(efi_obj_list). A reset
can occur at any time, e.g. via an UEFI binary calling the reset service.
The only safe way to return to an initial state is to relaunch the U-Boot
binary.

The reset implementation uses execv() to relaunch U-Boot.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Simon Glass <sjg@chromium.org>

# c7e49ddc 04-Jun-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

sandbox: handling out of memory

assert() only works in debug mode. So checking a successful memory
allocation should not use assert().

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Simon Glass <sjg@chromium.org>

# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 3ff6fe5f 03-Feb-2020 Simon Glass <sjg@chromium.org>

sandbox: Add a new header for the system malloc()

Some files use U-Boot headers but still need to access the system
malloc(). Allow this by creating a new asm/malloc.h which can be used so
long as U-Boot's malloc.h has not been included.

Signed-off-by: Simon Glass <sjg@chromium.org>

# cf23c7c1 03-Feb-2020 Simon Glass <sjg@chromium.org>

sandbox: Rename 'free' variable

This name conflicts with our desire to #define free() to something else on
sandbox. Rename it.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 89694de5 06-Dec-2019 Simon Glass <sjg@chromium.org>

sandbox: Disable mmio by default in tests

When reseting sandbox for tests, disable mmio support since that is the
default state.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>

# 857f39d7 16-May-2019 Urja Rannikko <urjaman@gmail.com>

sysreset: switch to using SYSRESET_POWER_OFF for poweroff

It seems that SYSRESET_POWER_OFF was added recently, and all previous code
used SYSRESET_POWER for poweroff. SYSRESET_POWER is supposed to be a
PMIC-level power cycle, not a poweroff.

(Comment by Simon Glass)
SYSRESET_POWER means to do a power reset (removing and reinstating all power)
SYSRESET_POWER_OFF means to turn the device off and leave it off

Signed-off-by: Urja Rannikko <urjaman@gmail.com>
Reviewed-by: Patrick Delaunay <patrick.delaunay@st.com>
(Update comment to help understand the patch)
Signed-off-by: Kever Yang <kever.yang@rock-chips.com>

# 9072326a 18-May-2019 Simon Glass <sjg@chromium.org>

sandbox: Exit when SYSRESET_POWER_OFF is requested

At present this returns but it seems better to just exit sandbox
immediately.

Signed-off-by: Simon Glass <sjg@chromium.org>

reset

# 1c5a81d8 01-Oct-2018 Simon Glass <sjg@chromium.org>

sandbox: Remove the old memory file later

When debugging sandbox it is sometimes annoying that the memory file is
deleted early on. If sandbox later crashes or we quit (using the
debugger), it is not possible to run it again with the same state since
the memory file is gone.

Remove the old memory file when sandbox exits, instead. Also add debugging
showing the memory filename.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 428aa0ca 15-Sep-2018 Simon Glass <sjg@chromium.org>

sandbox: Enhance map_to_sysmem() to handle foreign pointers

At present map_sysmem() maps an address into the sandbox RAM buffer,
return a pointer, while map_to_sysmem() goes the other way.

The mapping is currently just 1:1 since a case was not found where a more
flexible mapping was needed. PCI does have a separate and more complex
mapping, but uses its own mechanism.

However this arrange cannot handle one important case, which is where a
test declares a stack variable and passes a pointer to it into a U-Boot
function which uses map_to_sysmem() to turn it into a address. Since the
pointer is not inside emulated DRAM, this will fail.

Add a mapping feature which can handle any such pointer, mapping it to a
simple tag value which can be passed around in U-Boot as an address.

Signed-off-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Alexander Graf <agraf@suse.de>

# 83d290c5 06-May-2018 Tom Rini <trini@konsulko.com>

SPDX: Convert all of our single license tags to Linux Kernel style

When U-Boot started using SPDX tags we were among the early adopters and
there weren't a lot of other examples to borrow from. So we picked the
area of the file that usually had a full license text and replaced it
with an appropriate SPDX-License-Identifier: entry. Since then, the
Linux Kernel has adopted SPDX tags and they place it as the very first
line in a file (except where shebangs are used, then it's second line)
and with slightly different comment styles than us.

In part due to community overlap, in part due to better tag visibility
and in part for other minor reasons, switch over to that style.

This commit changes all instances where we have a single declared
license in the tag as both the before and after are identical in tag
contents. There's also a few places where I found we did not have a tag
and have introduced one.

Signed-off-by: Tom Rini <trini@konsulko.com>

# 9095d5b8 13-Feb-2018 Simon Goldschmidt <sgoldschmidt@de.pepperl-fuchs.com>

fix spelling of 'functions' in 2 places (was 'funtcions')

Signed-off-by: Simon Goldschmidt <sgoldschmidt@de.pepperl-fuchs.com>

# 34b744be 18-May-2017 Simon Glass <sjg@chromium.org>

sandbox: Add a way to reset sandbox state for tests

Running a new test should reset the sandbox state to avoid tests
interferring with each other. Move the existing state-reset code into a
function so it can be used from tests.

Also update the code to reset the SPI devices and adjust the test code to
call it.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 11636258 12-May-2016 Stephen Warren <swarren@nvidia.com>

Rename reset to sysreset

The current reset API implements a method to reset the entire system.
In the near future, I'd like to introduce code that implements the device
tree reset bindings; i.e. the equivalent of the Linux kernel's reset API.
This controls resets to individual HW blocks or external chips with reset
signals. It doesn't make sense to merge the two APIs into one since they
have different semantic purposes. Resolve the naming conflict by renaming
the existing reset API to sysreset instead, so the new reset API can be
called just reset.

Signed-off-by: Stephen Warren <swarren@nvidia.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 9723563a 08-Nov-2015 Simon Glass <sjg@chromium.org>

sandbox: Add a way to skip time delays

Some tests are slow due to delays which are unnecessary on sandbox. The
worst offender is USB where we lose two seconds. Add a way to disable time
delays.

Signed-off-by: Simon Glass <sjg@chromium.org>

# dc6f4d3a 06-Jul-2015 Simon Glass <sjg@chromium.org>

sandbox: Support multiple reset types

Add settings for the last reset generated, and the types of resets which
are permitted. This will be used for testing.

Signed-off-by: Simon Glass <sjg@chromium.org>

# d73125cb 04-May-2015 Simon Glass <sjg@chromium.org>

sandbox: Correct error handling in state_read_file()

This function should return a useful error for U-Boot, rather than -1.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Joe Hershberger <joe.hershberger@ni.com>

# 88539e44 06-Feb-2015 Joe Hershberger <joe.hershberger@ni.com>

sandbox: Return '-c command' exit value as sandbox exit code

When a command is passed into sandbox using the '-c' argument the
command is run directly. This is most helpful when running tests (such
as test-dm.sh). Previously the exit code was an unused enum. Change it
to be the actual return code from the command so that the script calling
sandbox can know if the command succeeded (tests passed). Also remove
the now completely unused "exit_state" in sandbox.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 96b1046d 17-Nov-2014 Suriyan Ramasami <suriyan.r@gmail.com>

sandbox: Prepare API change for files greater than 2GB

Change the internal sandbox functions to use loff_t for file offsets.

Signed-off-by: Suriyan Ramasami <suriyan.r@gmail.com>

Acked-by: Simon Glass <sjg@chromium.org>

# ab839dc3 27-Feb-2014 Simon Glass <sjg@chromium.org>

sandbox: Add options to clean up temporary files

When jumping from one sandbox U-Boot to another in sandbox, the RAM buffer
is preserved in the jump by using a temporary file. Add an option to tell
the receiving U-Boot to remove this file when it is no longer needed.

Similarly the old U-Boot image is left behind in this case. We cannot delete
it immediately since gdb cannot then find its debug symbols. Delete it just
before exiting.

Together these changes ensure that temporary files are removed both for
memory and U-Boot.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 1209e272 10-Nov-2013 Simon Glass <sjg@chromium.org>

sandbox: Add facility to save/restore sandbox state

It is often useful to be able to save out the state from a sandbox test
run, for analysis or to restore it later to continue a test. Add generic
infrastructure for doing this using a device tree binary file. This is
a flexible tagged file format which is already supported by U-Boot, and
it supports hierarchy if needed.

Signed-off-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Hung-ying Tyan <tyanh@chromium.org>

# 5c2859cd 10-Nov-2013 Simon Glass <sjg@chromium.org>

sandbox: Allow reading/writing of RAM buffer

It is useful to be able to save and restore the RAM contents of sandbox
U-Boot either for setting up tests, for later analysys, or for chaining
together multiple tests which need to keep the same memory contents.

Add a function to provide a memory file for U-Boot. This is read on
start-up and written when shutting down. If the file does not exist
on start-up, it will be created when shutting down.

Signed-off-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Simon Glass <sjg@chromium.org>

# 1a459660 08-Jul-2013 Wolfgang Denk <wd@denx.de>

Add GPL-2.0+ SPDX-License-Identifier to source files

Signed-off-by: Wolfgang Denk <wd@denx.de>
[trini: Fixup common/cmd_io.c]
Signed-off-by: Tom Rini <trini@ti.com>

# 6fb62078 15-Feb-2012 Simon Glass <sjg@chromium.org>

sandbox: add concept of sandbox state

The state exists through the life of U-Boot. It can be adjusted by command
line options and perhaps later through a config file. It is available to
U-Boot through state_...() calls (within sandbox code).

The primary purpose of this is to contain the "hardware" state. It should
only be used by sandbox internal code.

Signed-off-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Mike Frysinger <vapier@gentoo.org>

# 10bb90fa 20-Nov-2020 Patrick Delaunay <patrick.delaunay@foss.st.com>

sandbox: remove ram buffer file when U-Boot is loaded by SPL

Update management of "--rm_memory" sandbox's option and force
this option when U-Boot is loaded by SPL in os_spl_to_uboot()
and remove the ram file after reading in main() as described
in option help message: "Remove memory file after reading".

This patch avoids that the file "/tmp/u-boot.mem.XXXXXX" [created in
os_jump_to_file() when U-Boot is loaded by SPL] is never deleted
because state_uninit() is not called after U-Boot execution
(CtrlC or with running pytest for example).

This issue is reproduced by
> build-sandbox_spl/spl/u-boot-spl
and CtrlC in U-Bot console

> make qcheck

One temp file is created after each SPL and U-Boot execution
(7 tims in qcheck after test_handoff.py, test_ofplatdata.py,
test_spl.py execution).

Signed-off-by: Patrick Delaunay <patrick.delaunay@st.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 329dccc0 27-Oct-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

sandbox: implement reset

Up to now the sandbox would shutdown upon a cold reset request. Instead it
should be reset.

In our coding we use static variables like LIST_HEAD(efi_obj_list). A reset
can occur at any time, e.g. via an UEFI binary calling the reset service.
The only safe way to return to an initial state is to relaunch the U-Boot
binary.

The reset implementation uses execv() to relaunch U-Boot.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Simon Glass <sjg@chromium.org>

# c7e49ddc 04-Jun-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

sandbox: handling out of memory

assert() only works in debug mode. So checking a successful memory
allocation should not use assert().

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Simon Glass <sjg@chromium.org>

# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 3ff6fe5f 03-Feb-2020 Simon Glass <sjg@chromium.org>

sandbox: Add a new header for the system malloc()

Some files use U-Boot headers but still need to access the system
malloc(). Allow this by creating a new asm/malloc.h which can be used so
long as U-Boot's malloc.h has not been included.

Signed-off-by: Simon Glass <sjg@chromium.org>

# cf23c7c1 03-Feb-2020 Simon Glass <sjg@chromium.org>

sandbox: Rename 'free' variable

This name conflicts with our desire to #define free() to something else on
sandbox. Rename it.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 89694de5 06-Dec-2019 Simon Glass <sjg@chromium.org>

sandbox: Disable mmio by default in tests

When reseting sandbox for tests, disable mmio support since that is the
default state.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>

# 857f39d7 16-May-2019 Urja Rannikko <urjaman@gmail.com>

sysreset: switch to using SYSRESET_POWER_OFF for poweroff

It seems that SYSRESET_POWER_OFF was added recently, and all previous code
used SYSRESET_POWER for poweroff. SYSRESET_POWER is supposed to be a
PMIC-level power cycle, not a poweroff.

(Comment by Simon Glass)
SYSRESET_POWER means to do a power reset (removing and reinstating all power)
SYSRESET_POWER_OFF means to turn the device off and leave it off

Signed-off-by: Urja Rannikko <urjaman@gmail.com>
Reviewed-by: Patrick Delaunay <patrick.delaunay@st.com>
(Update comment to help understand the patch)
Signed-off-by: Kever Yang <kever.yang@rock-chips.com>

# 9072326a 18-May-2019 Simon Glass <sjg@chromium.org>

sandbox: Exit when SYSRESET_POWER_OFF is requested

At present this returns but it seems better to just exit sandbox
immediately.

Signed-off-by: Simon Glass <sjg@chromium.org>

reset

# 1c5a81d8 01-Oct-2018 Simon Glass <sjg@chromium.org>

sandbox: Remove the old memory file later

When debugging sandbox it is sometimes annoying that the memory file is
deleted early on. If sandbox later crashes or we quit (using the
debugger), it is not possible to run it again with the same state since
the memory file is gone.

Remove the old memory file when sandbox exits, instead. Also add debugging
showing the memory filename.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 428aa0ca 15-Sep-2018 Simon Glass <sjg@chromium.org>

sandbox: Enhance map_to_sysmem() to handle foreign pointers

At present map_sysmem() maps an address into the sandbox RAM buffer,
return a pointer, while map_to_sysmem() goes the other way.

The mapping is currently just 1:1 since a case was not found where a more
flexible mapping was needed. PCI does have a separate and more complex
mapping, but uses its own mechanism.

However this arrange cannot handle one important case, which is where a
test declares a stack variable and passes a pointer to it into a U-Boot
function which uses map_to_sysmem() to turn it into a address. Since the
pointer is not inside emulated DRAM, this will fail.

Add a mapping feature which can handle any such pointer, mapping it to a
simple tag value which can be passed around in U-Boot as an address.

Signed-off-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Alexander Graf <agraf@suse.de>

# 83d290c5 06-May-2018 Tom Rini <trini@konsulko.com>

SPDX: Convert all of our single license tags to Linux Kernel style

When U-Boot started using SPDX tags we were among the early adopters and
there weren't a lot of other examples to borrow from. So we picked the
area of the file that usually had a full license text and replaced it
with an appropriate SPDX-License-Identifier: entry. Since then, the
Linux Kernel has adopted SPDX tags and they place it as the very first
line in a file (except where shebangs are used, then it's second line)
and with slightly different comment styles than us.

In part due to community overlap, in part due to better tag visibility
and in part for other minor reasons, switch over to that style.

This commit changes all instances where we have a single declared
license in the tag as both the before and after are identical in tag
contents. There's also a few places where I found we did not have a tag
and have introduced one.

Signed-off-by: Tom Rini <trini@konsulko.com>

# 9095d5b8 13-Feb-2018 Simon Goldschmidt <sgoldschmidt@de.pepperl-fuchs.com>

fix spelling of 'functions' in 2 places (was 'funtcions')

Signed-off-by: Simon Goldschmidt <sgoldschmidt@de.pepperl-fuchs.com>

# 34b744be 18-May-2017 Simon Glass <sjg@chromium.org>

sandbox: Add a way to reset sandbox state for tests

Running a new test should reset the sandbox state to avoid tests
interferring with each other. Move the existing state-reset code into a
function so it can be used from tests.

Also update the code to reset the SPI devices and adjust the test code to
call it.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 11636258 12-May-2016 Stephen Warren <swarren@nvidia.com>

Rename reset to sysreset

The current reset API implements a method to reset the entire system.
In the near future, I'd like to introduce code that implements the device
tree reset bindings; i.e. the equivalent of the Linux kernel's reset API.
This controls resets to individual HW blocks or external chips with reset
signals. It doesn't make sense to merge the two APIs into one since they
have different semantic purposes. Resolve the naming conflict by renaming
the existing reset API to sysreset instead, so the new reset API can be
called just reset.

Signed-off-by: Stephen Warren <swarren@nvidia.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 9723563a 08-Nov-2015 Simon Glass <sjg@chromium.org>

sandbox: Add a way to skip time delays

Some tests are slow due to delays which are unnecessary on sandbox. The
worst offender is USB where we lose two seconds. Add a way to disable time
delays.

Signed-off-by: Simon Glass <sjg@chromium.org>

# dc6f4d3a 06-Jul-2015 Simon Glass <sjg@chromium.org>

sandbox: Support multiple reset types

Add settings for the last reset generated, and the types of resets which
are permitted. This will be used for testing.

Signed-off-by: Simon Glass <sjg@chromium.org>

# d73125cb 04-May-2015 Simon Glass <sjg@chromium.org>

sandbox: Correct error handling in state_read_file()

This function should return a useful error for U-Boot, rather than -1.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Joe Hershberger <joe.hershberger@ni.com>

# 88539e44 06-Feb-2015 Joe Hershberger <joe.hershberger@ni.com>

sandbox: Return '-c command' exit value as sandbox exit code

When a command is passed into sandbox using the '-c' argument the
command is run directly. This is most helpful when running tests (such
as test-dm.sh). Previously the exit code was an unused enum. Change it
to be the actual return code from the command so that the script calling
sandbox can know if the command succeeded (tests passed). Also remove
the now completely unused "exit_state" in sandbox.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 96b1046d 17-Nov-2014 Suriyan Ramasami <suriyan.r@gmail.com>

sandbox: Prepare API change for files greater than 2GB

Change the internal sandbox functions to use loff_t for file offsets.

Signed-off-by: Suriyan Ramasami <suriyan.r@gmail.com>

Acked-by: Simon Glass <sjg@chromium.org>

# ab839dc3 27-Feb-2014 Simon Glass <sjg@chromium.org>

sandbox: Add options to clean up temporary files

When jumping from one sandbox U-Boot to another in sandbox, the RAM buffer
is preserved in the jump by using a temporary file. Add an option to tell
the receiving U-Boot to remove this file when it is no longer needed.

Similarly the old U-Boot image is left behind in this case. We cannot delete
it immediately since gdb cannot then find its debug symbols. Delete it just
before exiting.

Together these changes ensure that temporary files are removed both for
memory and U-Boot.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 1209e272 10-Nov-2013 Simon Glass <sjg@chromium.org>

sandbox: Add facility to save/restore sandbox state

It is often useful to be able to save out the state from a sandbox test
run, for analysis or to restore it later to continue a test. Add generic
infrastructure for doing this using a device tree binary file. This is
a flexible tagged file format which is already supported by U-Boot, and
it supports hierarchy if needed.

Signed-off-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Hung-ying Tyan <tyanh@chromium.org>

# 5c2859cd 10-Nov-2013 Simon Glass <sjg@chromium.org>

sandbox: Allow reading/writing of RAM buffer

It is useful to be able to save and restore the RAM contents of sandbox
U-Boot either for setting up tests, for later analysys, or for chaining
together multiple tests which need to keep the same memory contents.

Add a function to provide a memory file for U-Boot. This is read on
start-up and written when shutting down. If the file does not exist
on start-up, it will be created when shutting down.

Signed-off-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Simon Glass <sjg@chromium.org>

# 1a459660 08-Jul-2013 Wolfgang Denk <wd@denx.de>

Add GPL-2.0+ SPDX-License-Identifier to source files

Signed-off-by: Wolfgang Denk <wd@denx.de>
[trini: Fixup common/cmd_io.c]
Signed-off-by: Tom Rini <trini@ti.com>

# 6fb62078 15-Feb-2012 Simon Glass <sjg@chromium.org>

sandbox: add concept of sandbox state

The state exists through the life of U-Boot. It can be adjusted by command
line options and perhaps later through a config file. It is available to
U-Boot through state_...() calls (within sandbox code).

The primary purpose of this is to contain the "hardware" state. It should
only be used by sandbox internal code.

Signed-off-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Mike Frysinger <vapier@gentoo.org>

# 329dccc0 27-Oct-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

sandbox: implement reset

Up to now the sandbox would shutdown upon a cold reset request. Instead it
should be reset.

In our coding we use static variables like LIST_HEAD(efi_obj_list). A reset
can occur at any time, e.g. via an UEFI binary calling the reset service.
The only safe way to return to an initial state is to relaunch the U-Boot
binary.

The reset implementation uses execv() to relaunch U-Boot.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Simon Glass <sjg@chromium.org>

# c7e49ddc 04-Jun-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

sandbox: handling out of memory

assert() only works in debug mode. So checking a successful memory
allocation should not use assert().

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Simon Glass <sjg@chromium.org>

# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 3ff6fe5f 03-Feb-2020 Simon Glass <sjg@chromium.org>

sandbox: Add a new header for the system malloc()

Some files use U-Boot headers but still need to access the system
malloc(). Allow this by creating a new asm/malloc.h which can be used so
long as U-Boot's malloc.h has not been included.

Signed-off-by: Simon Glass <sjg@chromium.org>

# cf23c7c1 03-Feb-2020 Simon Glass <sjg@chromium.org>

sandbox: Rename 'free' variable

This name conflicts with our desire to #define free() to something else on
sandbox. Rename it.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 89694de5 06-Dec-2019 Simon Glass <sjg@chromium.org>

sandbox: Disable mmio by default in tests

When reseting sandbox for tests, disable mmio support since that is the
default state.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>

# 857f39d7 16-May-2019 Urja Rannikko <urjaman@gmail.com>

sysreset: switch to using SYSRESET_POWER_OFF for poweroff

It seems that SYSRESET_POWER_OFF was added recently, and all previous code
used SYSRESET_POWER for poweroff. SYSRESET_POWER is supposed to be a
PMIC-level power cycle, not a poweroff.

(Comment by Simon Glass)
SYSRESET_POWER means to do a power reset (removing and reinstating all power)
SYSRESET_POWER_OFF means to turn the device off and leave it off

Signed-off-by: Urja Rannikko <urjaman@gmail.com>
Reviewed-by: Patrick Delaunay <patrick.delaunay@st.com>
(Update comment to help understand the patch)
Signed-off-by: Kever Yang <kever.yang@rock-chips.com>

# 9072326a 18-May-2019 Simon Glass <sjg@chromium.org>

sandbox: Exit when SYSRESET_POWER_OFF is requested

At present this returns but it seems better to just exit sandbox
immediately.

Signed-off-by: Simon Glass <sjg@chromium.org>

reset

# 1c5a81d8 01-Oct-2018 Simon Glass <sjg@chromium.org>

sandbox: Remove the old memory file later

When debugging sandbox it is sometimes annoying that the memory file is
deleted early on. If sandbox later crashes or we quit (using the
debugger), it is not possible to run it again with the same state since
the memory file is gone.

Remove the old memory file when sandbox exits, instead. Also add debugging
showing the memory filename.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 428aa0ca 15-Sep-2018 Simon Glass <sjg@chromium.org>

sandbox: Enhance map_to_sysmem() to handle foreign pointers

At present map_sysmem() maps an address into the sandbox RAM buffer,
return a pointer, while map_to_sysmem() goes the other way.

The mapping is currently just 1:1 since a case was not found where a more
flexible mapping was needed. PCI does have a separate and more complex
mapping, but uses its own mechanism.

However this arrange cannot handle one important case, which is where a
test declares a stack variable and passes a pointer to it into a U-Boot
function which uses map_to_sysmem() to turn it into a address. Since the
pointer is not inside emulated DRAM, this will fail.

Add a mapping feature which can handle any such pointer, mapping it to a
simple tag value which can be passed around in U-Boot as an address.

Signed-off-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Alexander Graf <agraf@suse.de>

# 83d290c5 06-May-2018 Tom Rini <trini@konsulko.com>

SPDX: Convert all of our single license tags to Linux Kernel style

When U-Boot started using SPDX tags we were among the early adopters and
there weren't a lot of other examples to borrow from. So we picked the
area of the file that usually had a full license text and replaced it
with an appropriate SPDX-License-Identifier: entry. Since then, the
Linux Kernel has adopted SPDX tags and they place it as the very first
line in a file (except where shebangs are used, then it's second line)
and with slightly different comment styles than us.

In part due to community overlap, in part due to better tag visibility
and in part for other minor reasons, switch over to that style.

This commit changes all instances where we have a single declared
license in the tag as both the before and after are identical in tag
contents. There's also a few places where I found we did not have a tag
and have introduced one.

Signed-off-by: Tom Rini <trini@konsulko.com>

# 9095d5b8 13-Feb-2018 Simon Goldschmidt <sgoldschmidt@de.pepperl-fuchs.com>

fix spelling of 'functions' in 2 places (was 'funtcions')

Signed-off-by: Simon Goldschmidt <sgoldschmidt@de.pepperl-fuchs.com>

# 34b744be 18-May-2017 Simon Glass <sjg@chromium.org>

sandbox: Add a way to reset sandbox state for tests

Running a new test should reset the sandbox state to avoid tests
interferring with each other. Move the existing state-reset code into a
function so it can be used from tests.

Also update the code to reset the SPI devices and adjust the test code to
call it.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 11636258 12-May-2016 Stephen Warren <swarren@nvidia.com>

Rename reset to sysreset

The current reset API implements a method to reset the entire system.
In the near future, I'd like to introduce code that implements the device
tree reset bindings; i.e. the equivalent of the Linux kernel's reset API.
This controls resets to individual HW blocks or external chips with reset
signals. It doesn't make sense to merge the two APIs into one since they
have different semantic purposes. Resolve the naming conflict by renaming
the existing reset API to sysreset instead, so the new reset API can be
called just reset.

Signed-off-by: Stephen Warren <swarren@nvidia.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 9723563a 08-Nov-2015 Simon Glass <sjg@chromium.org>

sandbox: Add a way to skip time delays

Some tests are slow due to delays which are unnecessary on sandbox. The
worst offender is USB where we lose two seconds. Add a way to disable time
delays.

Signed-off-by: Simon Glass <sjg@chromium.org>

# dc6f4d3a 06-Jul-2015 Simon Glass <sjg@chromium.org>

sandbox: Support multiple reset types

Add settings for the last reset generated, and the types of resets which
are permitted. This will be used for testing.

Signed-off-by: Simon Glass <sjg@chromium.org>

# d73125cb 04-May-2015 Simon Glass <sjg@chromium.org>

sandbox: Correct error handling in state_read_file()

This function should return a useful error for U-Boot, rather than -1.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Joe Hershberger <joe.hershberger@ni.com>

# 88539e44 06-Feb-2015 Joe Hershberger <joe.hershberger@ni.com>

sandbox: Return '-c command' exit value as sandbox exit code

When a command is passed into sandbox using the '-c' argument the
command is run directly. This is most helpful when running tests (such
as test-dm.sh). Previously the exit code was an unused enum. Change it
to be the actual return code from the command so that the script calling
sandbox can know if the command succeeded (tests passed). Also remove
the now completely unused "exit_state" in sandbox.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 96b1046d 17-Nov-2014 Suriyan Ramasami <suriyan.r@gmail.com>

sandbox: Prepare API change for files greater than 2GB

Change the internal sandbox functions to use loff_t for file offsets.

Signed-off-by: Suriyan Ramasami <suriyan.r@gmail.com>

Acked-by: Simon Glass <sjg@chromium.org>

# ab839dc3 27-Feb-2014 Simon Glass <sjg@chromium.org>

sandbox: Add options to clean up temporary files

When jumping from one sandbox U-Boot to another in sandbox, the RAM buffer
is preserved in the jump by using a temporary file. Add an option to tell
the receiving U-Boot to remove this file when it is no longer needed.

Similarly the old U-Boot image is left behind in this case. We cannot delete
it immediately since gdb cannot then find its debug symbols. Delete it just
before exiting.

Together these changes ensure that temporary files are removed both for
memory and U-Boot.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 1209e272 10-Nov-2013 Simon Glass <sjg@chromium.org>

sandbox: Add facility to save/restore sandbox state

It is often useful to be able to save out the state from a sandbox test
run, for analysis or to restore it later to continue a test. Add generic
infrastructure for doing this using a device tree binary file. This is
a flexible tagged file format which is already supported by U-Boot, and
it supports hierarchy if needed.

Signed-off-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Hung-ying Tyan <tyanh@chromium.org>

# 5c2859cd 10-Nov-2013 Simon Glass <sjg@chromium.org>

sandbox: Allow reading/writing of RAM buffer

It is useful to be able to save and restore the RAM contents of sandbox
U-Boot either for setting up tests, for later analysys, or for chaining
together multiple tests which need to keep the same memory contents.

Add a function to provide a memory file for U-Boot. This is read on
start-up and written when shutting down. If the file does not exist
on start-up, it will be created when shutting down.

Signed-off-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Simon Glass <sjg@chromium.org>

# 1a459660 08-Jul-2013 Wolfgang Denk <wd@denx.de>

Add GPL-2.0+ SPDX-License-Identifier to source files

Signed-off-by: Wolfgang Denk <wd@denx.de>
[trini: Fixup common/cmd_io.c]
Signed-off-by: Tom Rini <trini@ti.com>

# 6fb62078 15-Feb-2012 Simon Glass <sjg@chromium.org>

sandbox: add concept of sandbox state

The state exists through the life of U-Boot. It can be adjusted by command
line options and perhaps later through a config file. It is available to
U-Boot through state_...() calls (within sandbox code).

The primary purpose of this is to contain the "hardware" state. It should
only be used by sandbox internal code.

Signed-off-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Mike Frysinger <vapier@gentoo.org>

# c7e49ddc 04-Jun-2020 Heinrich Schuchardt <xypron.glpk@gmx.de>

sandbox: handling out of memory

assert() only works in debug mode. So checking a successful memory
allocation should not use assert().

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Simon Glass <sjg@chromium.org>

# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 3ff6fe5f 03-Feb-2020 Simon Glass <sjg@chromium.org>

sandbox: Add a new header for the system malloc()

Some files use U-Boot headers but still need to access the system
malloc(). Allow this by creating a new asm/malloc.h which can be used so
long as U-Boot's malloc.h has not been included.

Signed-off-by: Simon Glass <sjg@chromium.org>

# cf23c7c1 03-Feb-2020 Simon Glass <sjg@chromium.org>

sandbox: Rename 'free' variable

This name conflicts with our desire to #define free() to something else on
sandbox. Rename it.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 89694de5 06-Dec-2019 Simon Glass <sjg@chromium.org>

sandbox: Disable mmio by default in tests

When reseting sandbox for tests, disable mmio support since that is the
default state.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>

# 857f39d7 16-May-2019 Urja Rannikko <urjaman@gmail.com>

sysreset: switch to using SYSRESET_POWER_OFF for poweroff

It seems that SYSRESET_POWER_OFF was added recently, and all previous code
used SYSRESET_POWER for poweroff. SYSRESET_POWER is supposed to be a
PMIC-level power cycle, not a poweroff.

(Comment by Simon Glass)
SYSRESET_POWER means to do a power reset (removing and reinstating all power)
SYSRESET_POWER_OFF means to turn the device off and leave it off

Signed-off-by: Urja Rannikko <urjaman@gmail.com>
Reviewed-by: Patrick Delaunay <patrick.delaunay@st.com>
(Update comment to help understand the patch)
Signed-off-by: Kever Yang <kever.yang@rock-chips.com>

# 9072326a 18-May-2019 Simon Glass <sjg@chromium.org>

sandbox: Exit when SYSRESET_POWER_OFF is requested

At present this returns but it seems better to just exit sandbox
immediately.

Signed-off-by: Simon Glass <sjg@chromium.org>

reset

# 1c5a81d8 01-Oct-2018 Simon Glass <sjg@chromium.org>

sandbox: Remove the old memory file later

When debugging sandbox it is sometimes annoying that the memory file is
deleted early on. If sandbox later crashes or we quit (using the
debugger), it is not possible to run it again with the same state since
the memory file is gone.

Remove the old memory file when sandbox exits, instead. Also add debugging
showing the memory filename.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 428aa0ca 15-Sep-2018 Simon Glass <sjg@chromium.org>

sandbox: Enhance map_to_sysmem() to handle foreign pointers

At present map_sysmem() maps an address into the sandbox RAM buffer,
return a pointer, while map_to_sysmem() goes the other way.

The mapping is currently just 1:1 since a case was not found where a more
flexible mapping was needed. PCI does have a separate and more complex
mapping, but uses its own mechanism.

However this arrange cannot handle one important case, which is where a
test declares a stack variable and passes a pointer to it into a U-Boot
function which uses map_to_sysmem() to turn it into a address. Since the
pointer is not inside emulated DRAM, this will fail.

Add a mapping feature which can handle any such pointer, mapping it to a
simple tag value which can be passed around in U-Boot as an address.

Signed-off-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Alexander Graf <agraf@suse.de>

# 83d290c5 06-May-2018 Tom Rini <trini@konsulko.com>

SPDX: Convert all of our single license tags to Linux Kernel style

When U-Boot started using SPDX tags we were among the early adopters and
there weren't a lot of other examples to borrow from. So we picked the
area of the file that usually had a full license text and replaced it
with an appropriate SPDX-License-Identifier: entry. Since then, the
Linux Kernel has adopted SPDX tags and they place it as the very first
line in a file (except where shebangs are used, then it's second line)
and with slightly different comment styles than us.

In part due to community overlap, in part due to better tag visibility
and in part for other minor reasons, switch over to that style.

This commit changes all instances where we have a single declared
license in the tag as both the before and after are identical in tag
contents. There's also a few places where I found we did not have a tag
and have introduced one.

Signed-off-by: Tom Rini <trini@konsulko.com>

# 9095d5b8 13-Feb-2018 Simon Goldschmidt <sgoldschmidt@de.pepperl-fuchs.com>

fix spelling of 'functions' in 2 places (was 'funtcions')

Signed-off-by: Simon Goldschmidt <sgoldschmidt@de.pepperl-fuchs.com>

# 34b744be 18-May-2017 Simon Glass <sjg@chromium.org>

sandbox: Add a way to reset sandbox state for tests

Running a new test should reset the sandbox state to avoid tests
interferring with each other. Move the existing state-reset code into a
function so it can be used from tests.

Also update the code to reset the SPI devices and adjust the test code to
call it.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 11636258 12-May-2016 Stephen Warren <swarren@nvidia.com>

Rename reset to sysreset

The current reset API implements a method to reset the entire system.
In the near future, I'd like to introduce code that implements the device
tree reset bindings; i.e. the equivalent of the Linux kernel's reset API.
This controls resets to individual HW blocks or external chips with reset
signals. It doesn't make sense to merge the two APIs into one since they
have different semantic purposes. Resolve the naming conflict by renaming
the existing reset API to sysreset instead, so the new reset API can be
called just reset.

Signed-off-by: Stephen Warren <swarren@nvidia.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 9723563a 08-Nov-2015 Simon Glass <sjg@chromium.org>

sandbox: Add a way to skip time delays

Some tests are slow due to delays which are unnecessary on sandbox. The
worst offender is USB where we lose two seconds. Add a way to disable time
delays.

Signed-off-by: Simon Glass <sjg@chromium.org>

# dc6f4d3a 06-Jul-2015 Simon Glass <sjg@chromium.org>

sandbox: Support multiple reset types

Add settings for the last reset generated, and the types of resets which
are permitted. This will be used for testing.

Signed-off-by: Simon Glass <sjg@chromium.org>

# d73125cb 04-May-2015 Simon Glass <sjg@chromium.org>

sandbox: Correct error handling in state_read_file()

This function should return a useful error for U-Boot, rather than -1.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Joe Hershberger <joe.hershberger@ni.com>

# 88539e44 06-Feb-2015 Joe Hershberger <joe.hershberger@ni.com>

sandbox: Return '-c command' exit value as sandbox exit code

When a command is passed into sandbox using the '-c' argument the
command is run directly. This is most helpful when running tests (such
as test-dm.sh). Previously the exit code was an unused enum. Change it
to be the actual return code from the command so that the script calling
sandbox can know if the command succeeded (tests passed). Also remove
the now completely unused "exit_state" in sandbox.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 96b1046d 17-Nov-2014 Suriyan Ramasami <suriyan.r@gmail.com>

sandbox: Prepare API change for files greater than 2GB

Change the internal sandbox functions to use loff_t for file offsets.

Signed-off-by: Suriyan Ramasami <suriyan.r@gmail.com>

Acked-by: Simon Glass <sjg@chromium.org>

# ab839dc3 27-Feb-2014 Simon Glass <sjg@chromium.org>

sandbox: Add options to clean up temporary files

When jumping from one sandbox U-Boot to another in sandbox, the RAM buffer
is preserved in the jump by using a temporary file. Add an option to tell
the receiving U-Boot to remove this file when it is no longer needed.

Similarly the old U-Boot image is left behind in this case. We cannot delete
it immediately since gdb cannot then find its debug symbols. Delete it just
before exiting.

Together these changes ensure that temporary files are removed both for
memory and U-Boot.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 1209e272 10-Nov-2013 Simon Glass <sjg@chromium.org>

sandbox: Add facility to save/restore sandbox state

It is often useful to be able to save out the state from a sandbox test
run, for analysis or to restore it later to continue a test. Add generic
infrastructure for doing this using a device tree binary file. This is
a flexible tagged file format which is already supported by U-Boot, and
it supports hierarchy if needed.

Signed-off-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Hung-ying Tyan <tyanh@chromium.org>

# 5c2859cd 10-Nov-2013 Simon Glass <sjg@chromium.org>

sandbox: Allow reading/writing of RAM buffer

It is useful to be able to save and restore the RAM contents of sandbox
U-Boot either for setting up tests, for later analysys, or for chaining
together multiple tests which need to keep the same memory contents.

Add a function to provide a memory file for U-Boot. This is read on
start-up and written when shutting down. If the file does not exist
on start-up, it will be created when shutting down.

Signed-off-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Simon Glass <sjg@chromium.org>

# 1a459660 08-Jul-2013 Wolfgang Denk <wd@denx.de>

Add GPL-2.0+ SPDX-License-Identifier to source files

Signed-off-by: Wolfgang Denk <wd@denx.de>
[trini: Fixup common/cmd_io.c]
Signed-off-by: Tom Rini <trini@ti.com>

# 6fb62078 15-Feb-2012 Simon Glass <sjg@chromium.org>

sandbox: add concept of sandbox state

The state exists through the life of U-Boot. It can be adjusted by command
line options and perhaps later through a config file. It is available to
U-Boot through state_...() calls (within sandbox code).

The primary purpose of this is to contain the "hardware" state. It should
only be used by sandbox internal code.

Signed-off-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Mike Frysinger <vapier@gentoo.org>

# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 3ff6fe5f 03-Feb-2020 Simon Glass <sjg@chromium.org>

sandbox: Add a new header for the system malloc()

Some files use U-Boot headers but still need to access the system
malloc(). Allow this by creating a new asm/malloc.h which can be used so
long as U-Boot's malloc.h has not been included.

Signed-off-by: Simon Glass <sjg@chromium.org>

# cf23c7c1 03-Feb-2020 Simon Glass <sjg@chromium.org>

sandbox: Rename 'free' variable

This name conflicts with our desire to #define free() to something else on
sandbox. Rename it.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 89694de5 06-Dec-2019 Simon Glass <sjg@chromium.org>

sandbox: Disable mmio by default in tests

When reseting sandbox for tests, disable mmio support since that is the
default state.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>

# 857f39d7 16-May-2019 Urja Rannikko <urjaman@gmail.com>

sysreset: switch to using SYSRESET_POWER_OFF for poweroff

It seems that SYSRESET_POWER_OFF was added recently, and all previous code
used SYSRESET_POWER for poweroff. SYSRESET_POWER is supposed to be a
PMIC-level power cycle, not a poweroff.

(Comment by Simon Glass)
SYSRESET_POWER means to do a power reset (removing and reinstating all power)
SYSRESET_POWER_OFF means to turn the device off and leave it off

Signed-off-by: Urja Rannikko <urjaman@gmail.com>
Reviewed-by: Patrick Delaunay <patrick.delaunay@st.com>
(Update comment to help understand the patch)
Signed-off-by: Kever Yang <kever.yang@rock-chips.com>

# 9072326a 18-May-2019 Simon Glass <sjg@chromium.org>

sandbox: Exit when SYSRESET_POWER_OFF is requested

At present this returns but it seems better to just exit sandbox
immediately.

Signed-off-by: Simon Glass <sjg@chromium.org>

reset

# 1c5a81d8 01-Oct-2018 Simon Glass <sjg@chromium.org>

sandbox: Remove the old memory file later

When debugging sandbox it is sometimes annoying that the memory file is
deleted early on. If sandbox later crashes or we quit (using the
debugger), it is not possible to run it again with the same state since
the memory file is gone.

Remove the old memory file when sandbox exits, instead. Also add debugging
showing the memory filename.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 428aa0ca 15-Sep-2018 Simon Glass <sjg@chromium.org>

sandbox: Enhance map_to_sysmem() to handle foreign pointers

At present map_sysmem() maps an address into the sandbox RAM buffer,
return a pointer, while map_to_sysmem() goes the other way.

The mapping is currently just 1:1 since a case was not found where a more
flexible mapping was needed. PCI does have a separate and more complex
mapping, but uses its own mechanism.

However this arrange cannot handle one important case, which is where a
test declares a stack variable and passes a pointer to it into a U-Boot
function which uses map_to_sysmem() to turn it into a address. Since the
pointer is not inside emulated DRAM, this will fail.

Add a mapping feature which can handle any such pointer, mapping it to a
simple tag value which can be passed around in U-Boot as an address.

Signed-off-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Alexander Graf <agraf@suse.de>

# 83d290c5 06-May-2018 Tom Rini <trini@konsulko.com>

SPDX: Convert all of our single license tags to Linux Kernel style

When U-Boot started using SPDX tags we were among the early adopters and
there weren't a lot of other examples to borrow from. So we picked the
area of the file that usually had a full license text and replaced it
with an appropriate SPDX-License-Identifier: entry. Since then, the
Linux Kernel has adopted SPDX tags and they place it as the very first
line in a file (except where shebangs are used, then it's second line)
and with slightly different comment styles than us.

In part due to community overlap, in part due to better tag visibility
and in part for other minor reasons, switch over to that style.

This commit changes all instances where we have a single declared
license in the tag as both the before and after are identical in tag
contents. There's also a few places where I found we did not have a tag
and have introduced one.

Signed-off-by: Tom Rini <trini@konsulko.com>

# 9095d5b8 13-Feb-2018 Simon Goldschmidt <sgoldschmidt@de.pepperl-fuchs.com>

fix spelling of 'functions' in 2 places (was 'funtcions')

Signed-off-by: Simon Goldschmidt <sgoldschmidt@de.pepperl-fuchs.com>

# 34b744be 18-May-2017 Simon Glass <sjg@chromium.org>

sandbox: Add a way to reset sandbox state for tests

Running a new test should reset the sandbox state to avoid tests
interferring with each other. Move the existing state-reset code into a
function so it can be used from tests.

Also update the code to reset the SPI devices and adjust the test code to
call it.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 11636258 12-May-2016 Stephen Warren <swarren@nvidia.com>

Rename reset to sysreset

The current reset API implements a method to reset the entire system.
In the near future, I'd like to introduce code that implements the device
tree reset bindings; i.e. the equivalent of the Linux kernel's reset API.
This controls resets to individual HW blocks or external chips with reset
signals. It doesn't make sense to merge the two APIs into one since they
have different semantic purposes. Resolve the naming conflict by renaming
the existing reset API to sysreset instead, so the new reset API can be
called just reset.

Signed-off-by: Stephen Warren <swarren@nvidia.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 9723563a 08-Nov-2015 Simon Glass <sjg@chromium.org>

sandbox: Add a way to skip time delays

Some tests are slow due to delays which are unnecessary on sandbox. The
worst offender is USB where we lose two seconds. Add a way to disable time
delays.

Signed-off-by: Simon Glass <sjg@chromium.org>

# dc6f4d3a 06-Jul-2015 Simon Glass <sjg@chromium.org>

sandbox: Support multiple reset types

Add settings for the last reset generated, and the types of resets which
are permitted. This will be used for testing.

Signed-off-by: Simon Glass <sjg@chromium.org>

# d73125cb 04-May-2015 Simon Glass <sjg@chromium.org>

sandbox: Correct error handling in state_read_file()

This function should return a useful error for U-Boot, rather than -1.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Joe Hershberger <joe.hershberger@ni.com>

# 88539e44 06-Feb-2015 Joe Hershberger <joe.hershberger@ni.com>

sandbox: Return '-c command' exit value as sandbox exit code

When a command is passed into sandbox using the '-c' argument the
command is run directly. This is most helpful when running tests (such
as test-dm.sh). Previously the exit code was an unused enum. Change it
to be the actual return code from the command so that the script calling
sandbox can know if the command succeeded (tests passed). Also remove
the now completely unused "exit_state" in sandbox.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 96b1046d 17-Nov-2014 Suriyan Ramasami <suriyan.r@gmail.com>

sandbox: Prepare API change for files greater than 2GB

Change the internal sandbox functions to use loff_t for file offsets.

Signed-off-by: Suriyan Ramasami <suriyan.r@gmail.com>

Acked-by: Simon Glass <sjg@chromium.org>

# ab839dc3 27-Feb-2014 Simon Glass <sjg@chromium.org>

sandbox: Add options to clean up temporary files

When jumping from one sandbox U-Boot to another in sandbox, the RAM buffer
is preserved in the jump by using a temporary file. Add an option to tell
the receiving U-Boot to remove this file when it is no longer needed.

Similarly the old U-Boot image is left behind in this case. We cannot delete
it immediately since gdb cannot then find its debug symbols. Delete it just
before exiting.

Together these changes ensure that temporary files are removed both for
memory and U-Boot.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 1209e272 10-Nov-2013 Simon Glass <sjg@chromium.org>

sandbox: Add facility to save/restore sandbox state

It is often useful to be able to save out the state from a sandbox test
run, for analysis or to restore it later to continue a test. Add generic
infrastructure for doing this using a device tree binary file. This is
a flexible tagged file format which is already supported by U-Boot, and
it supports hierarchy if needed.

Signed-off-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Hung-ying Tyan <tyanh@chromium.org>

# 5c2859cd 10-Nov-2013 Simon Glass <sjg@chromium.org>

sandbox: Allow reading/writing of RAM buffer

It is useful to be able to save and restore the RAM contents of sandbox
U-Boot either for setting up tests, for later analysys, or for chaining
together multiple tests which need to keep the same memory contents.

Add a function to provide a memory file for U-Boot. This is read on
start-up and written when shutting down. If the file does not exist
on start-up, it will be created when shutting down.

Signed-off-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Simon Glass <sjg@chromium.org>

# 1a459660 08-Jul-2013 Wolfgang Denk <wd@denx.de>

Add GPL-2.0+ SPDX-License-Identifier to source files

Signed-off-by: Wolfgang Denk <wd@denx.de>
[trini: Fixup common/cmd_io.c]
Signed-off-by: Tom Rini <trini@ti.com>

# 6fb62078 15-Feb-2012 Simon Glass <sjg@chromium.org>

sandbox: add concept of sandbox state

The state exists through the life of U-Boot. It can be adjusted by command
line options and perhaps later through a config file. It is available to
U-Boot through state_...() calls (within sandbox code).

The primary purpose of this is to contain the "hardware" state. It should
only be used by sandbox internal code.

Signed-off-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Mike Frysinger <vapier@gentoo.org>

# 3ff6fe5f 03-Feb-2020 Simon Glass <sjg@chromium.org>

sandbox: Add a new header for the system malloc()

Some files use U-Boot headers but still need to access the system
malloc(). Allow this by creating a new asm/malloc.h which can be used so
long as U-Boot's malloc.h has not been included.

Signed-off-by: Simon Glass <sjg@chromium.org>

# cf23c7c1 03-Feb-2020 Simon Glass <sjg@chromium.org>

sandbox: Rename 'free' variable

This name conflicts with our desire to #define free() to something else on
sandbox. Rename it.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 89694de5 06-Dec-2019 Simon Glass <sjg@chromium.org>

sandbox: Disable mmio by default in tests

When reseting sandbox for tests, disable mmio support since that is the
default state.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>

# 857f39d7 16-May-2019 Urja Rannikko <urjaman@gmail.com>

sysreset: switch to using SYSRESET_POWER_OFF for poweroff

It seems that SYSRESET_POWER_OFF was added recently, and all previous code
used SYSRESET_POWER for poweroff. SYSRESET_POWER is supposed to be a
PMIC-level power cycle, not a poweroff.

(Comment by Simon Glass)
SYSRESET_POWER means to do a power reset (removing and reinstating all power)
SYSRESET_POWER_OFF means to turn the device off and leave it off

Signed-off-by: Urja Rannikko <urjaman@gmail.com>
Reviewed-by: Patrick Delaunay <patrick.delaunay@st.com>
(Update comment to help understand the patch)
Signed-off-by: Kever Yang <kever.yang@rock-chips.com>

# 9072326a 18-May-2019 Simon Glass <sjg@chromium.org>

sandbox: Exit when SYSRESET_POWER_OFF is requested

At present this returns but it seems better to just exit sandbox
immediately.

Signed-off-by: Simon Glass <sjg@chromium.org>

reset

# 1c5a81d8 01-Oct-2018 Simon Glass <sjg@chromium.org>

sandbox: Remove the old memory file later

When debugging sandbox it is sometimes annoying that the memory file is
deleted early on. If sandbox later crashes or we quit (using the
debugger), it is not possible to run it again with the same state since
the memory file is gone.

Remove the old memory file when sandbox exits, instead. Also add debugging
showing the memory filename.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 428aa0ca 15-Sep-2018 Simon Glass <sjg@chromium.org>

sandbox: Enhance map_to_sysmem() to handle foreign pointers

At present map_sysmem() maps an address into the sandbox RAM buffer,
return a pointer, while map_to_sysmem() goes the other way.

The mapping is currently just 1:1 since a case was not found where a more
flexible mapping was needed. PCI does have a separate and more complex
mapping, but uses its own mechanism.

However this arrange cannot handle one important case, which is where a
test declares a stack variable and passes a pointer to it into a U-Boot
function which uses map_to_sysmem() to turn it into a address. Since the
pointer is not inside emulated DRAM, this will fail.

Add a mapping feature which can handle any such pointer, mapping it to a
simple tag value which can be passed around in U-Boot as an address.

Signed-off-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Alexander Graf <agraf@suse.de>

# 83d290c5 06-May-2018 Tom Rini <trini@konsulko.com>

SPDX: Convert all of our single license tags to Linux Kernel style

When U-Boot started using SPDX tags we were among the early adopters and
there weren't a lot of other examples to borrow from. So we picked the
area of the file that usually had a full license text and replaced it
with an appropriate SPDX-License-Identifier: entry. Since then, the
Linux Kernel has adopted SPDX tags and they place it as the very first
line in a file (except where shebangs are used, then it's second line)
and with slightly different comment styles than us.

In part due to community overlap, in part due to better tag visibility
and in part for other minor reasons, switch over to that style.

This commit changes all instances where we have a single declared
license in the tag as both the before and after are identical in tag
contents. There's also a few places where I found we did not have a tag
and have introduced one.

Signed-off-by: Tom Rini <trini@konsulko.com>

# 9095d5b8 13-Feb-2018 Simon Goldschmidt <sgoldschmidt@de.pepperl-fuchs.com>

fix spelling of 'functions' in 2 places (was 'funtcions')

Signed-off-by: Simon Goldschmidt <sgoldschmidt@de.pepperl-fuchs.com>

# 34b744be 18-May-2017 Simon Glass <sjg@chromium.org>

sandbox: Add a way to reset sandbox state for tests

Running a new test should reset the sandbox state to avoid tests
interferring with each other. Move the existing state-reset code into a
function so it can be used from tests.

Also update the code to reset the SPI devices and adjust the test code to
call it.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 11636258 12-May-2016 Stephen Warren <swarren@nvidia.com>

Rename reset to sysreset

The current reset API implements a method to reset the entire system.
In the near future, I'd like to introduce code that implements the device
tree reset bindings; i.e. the equivalent of the Linux kernel's reset API.
This controls resets to individual HW blocks or external chips with reset
signals. It doesn't make sense to merge the two APIs into one since they
have different semantic purposes. Resolve the naming conflict by renaming
the existing reset API to sysreset instead, so the new reset API can be
called just reset.

Signed-off-by: Stephen Warren <swarren@nvidia.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 9723563a 08-Nov-2015 Simon Glass <sjg@chromium.org>

sandbox: Add a way to skip time delays

Some tests are slow due to delays which are unnecessary on sandbox. The
worst offender is USB where we lose two seconds. Add a way to disable time
delays.

Signed-off-by: Simon Glass <sjg@chromium.org>

# dc6f4d3a 06-Jul-2015 Simon Glass <sjg@chromium.org>

sandbox: Support multiple reset types

Add settings for the last reset generated, and the types of resets which
are permitted. This will be used for testing.

Signed-off-by: Simon Glass <sjg@chromium.org>

# d73125cb 04-May-2015 Simon Glass <sjg@chromium.org>

sandbox: Correct error handling in state_read_file()

This function should return a useful error for U-Boot, rather than -1.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Joe Hershberger <joe.hershberger@ni.com>

# 88539e44 06-Feb-2015 Joe Hershberger <joe.hershberger@ni.com>

sandbox: Return '-c command' exit value as sandbox exit code

When a command is passed into sandbox using the '-c' argument the
command is run directly. This is most helpful when running tests (such
as test-dm.sh). Previously the exit code was an unused enum. Change it
to be the actual return code from the command so that the script calling
sandbox can know if the command succeeded (tests passed). Also remove
the now completely unused "exit_state" in sandbox.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 96b1046d 17-Nov-2014 Suriyan Ramasami <suriyan.r@gmail.com>

sandbox: Prepare API change for files greater than 2GB

Change the internal sandbox functions to use loff_t for file offsets.

Signed-off-by: Suriyan Ramasami <suriyan.r@gmail.com>

Acked-by: Simon Glass <sjg@chromium.org>

# ab839dc3 27-Feb-2014 Simon Glass <sjg@chromium.org>

sandbox: Add options to clean up temporary files

When jumping from one sandbox U-Boot to another in sandbox, the RAM buffer
is preserved in the jump by using a temporary file. Add an option to tell
the receiving U-Boot to remove this file when it is no longer needed.

Similarly the old U-Boot image is left behind in this case. We cannot delete
it immediately since gdb cannot then find its debug symbols. Delete it just
before exiting.

Together these changes ensure that temporary files are removed both for
memory and U-Boot.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 1209e272 10-Nov-2013 Simon Glass <sjg@chromium.org>

sandbox: Add facility to save/restore sandbox state

It is often useful to be able to save out the state from a sandbox test
run, for analysis or to restore it later to continue a test. Add generic
infrastructure for doing this using a device tree binary file. This is
a flexible tagged file format which is already supported by U-Boot, and
it supports hierarchy if needed.

Signed-off-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Hung-ying Tyan <tyanh@chromium.org>

# 5c2859cd 10-Nov-2013 Simon Glass <sjg@chromium.org>

sandbox: Allow reading/writing of RAM buffer

It is useful to be able to save and restore the RAM contents of sandbox
U-Boot either for setting up tests, for later analysys, or for chaining
together multiple tests which need to keep the same memory contents.

Add a function to provide a memory file for U-Boot. This is read on
start-up and written when shutting down. If the file does not exist
on start-up, it will be created when shutting down.

Signed-off-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Simon Glass <sjg@chromium.org>

# 1a459660 08-Jul-2013 Wolfgang Denk <wd@denx.de>

Add GPL-2.0+ SPDX-License-Identifier to source files

Signed-off-by: Wolfgang Denk <wd@denx.de>
[trini: Fixup common/cmd_io.c]
Signed-off-by: Tom Rini <trini@ti.com>

# 6fb62078 15-Feb-2012 Simon Glass <sjg@chromium.org>

sandbox: add concept of sandbox state

The state exists through the life of U-Boot. It can be adjusted by command
line options and perhaps later through a config file. It is available to
U-Boot through state_...() calls (within sandbox code).

The primary purpose of this is to contain the "hardware" state. It should
only be used by sandbox internal code.

Signed-off-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Mike Frysinger <vapier@gentoo.org>

# 89694de5 06-Dec-2019 Simon Glass <sjg@chromium.org>

sandbox: Disable mmio by default in tests

When reseting sandbox for tests, disable mmio support since that is the
default state.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>

# 857f39d7 16-May-2019 Urja Rannikko <urjaman@gmail.com>

sysreset: switch to using SYSRESET_POWER_OFF for poweroff

It seems that SYSRESET_POWER_OFF was added recently, and all previous code
used SYSRESET_POWER for poweroff. SYSRESET_POWER is supposed to be a
PMIC-level power cycle, not a poweroff.

(Comment by Simon Glass)
SYSRESET_POWER means to do a power reset (removing and reinstating all power)
SYSRESET_POWER_OFF means to turn the device off and leave it off

Signed-off-by: Urja Rannikko <urjaman@gmail.com>
Reviewed-by: Patrick Delaunay <patrick.delaunay@st.com>
(Update comment to help understand the patch)
Signed-off-by: Kever Yang <kever.yang@rock-chips.com>

# 9072326a 18-May-2019 Simon Glass <sjg@chromium.org>

sandbox: Exit when SYSRESET_POWER_OFF is requested

At present this returns but it seems better to just exit sandbox
immediately.

Signed-off-by: Simon Glass <sjg@chromium.org>

reset

# 1c5a81d8 01-Oct-2018 Simon Glass <sjg@chromium.org>

sandbox: Remove the old memory file later

When debugging sandbox it is sometimes annoying that the memory file is
deleted early on. If sandbox later crashes or we quit (using the
debugger), it is not possible to run it again with the same state since
the memory file is gone.

Remove the old memory file when sandbox exits, instead. Also add debugging
showing the memory filename.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 428aa0ca 15-Sep-2018 Simon Glass <sjg@chromium.org>

sandbox: Enhance map_to_sysmem() to handle foreign pointers

At present map_sysmem() maps an address into the sandbox RAM buffer,
return a pointer, while map_to_sysmem() goes the other way.

The mapping is currently just 1:1 since a case was not found where a more
flexible mapping was needed. PCI does have a separate and more complex
mapping, but uses its own mechanism.

However this arrange cannot handle one important case, which is where a
test declares a stack variable and passes a pointer to it into a U-Boot
function which uses map_to_sysmem() to turn it into a address. Since the
pointer is not inside emulated DRAM, this will fail.

Add a mapping feature which can handle any such pointer, mapping it to a
simple tag value which can be passed around in U-Boot as an address.

Signed-off-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Alexander Graf <agraf@suse.de>

# 83d290c5 06-May-2018 Tom Rini <trini@konsulko.com>

SPDX: Convert all of our single license tags to Linux Kernel style

When U-Boot started using SPDX tags we were among the early adopters and
there weren't a lot of other examples to borrow from. So we picked the
area of the file that usually had a full license text and replaced it
with an appropriate SPDX-License-Identifier: entry. Since then, the
Linux Kernel has adopted SPDX tags and they place it as the very first
line in a file (except where shebangs are used, then it's second line)
and with slightly different comment styles than us.

In part due to community overlap, in part due to better tag visibility
and in part for other minor reasons, switch over to that style.

This commit changes all instances where we have a single declared
license in the tag as both the before and after are identical in tag
contents. There's also a few places where I found we did not have a tag
and have introduced one.

Signed-off-by: Tom Rini <trini@konsulko.com>

# 9095d5b8 13-Feb-2018 Simon Goldschmidt <sgoldschmidt@de.pepperl-fuchs.com>

fix spelling of 'functions' in 2 places (was 'funtcions')

Signed-off-by: Simon Goldschmidt <sgoldschmidt@de.pepperl-fuchs.com>

# 34b744be 18-May-2017 Simon Glass <sjg@chromium.org>

sandbox: Add a way to reset sandbox state for tests

Running a new test should reset the sandbox state to avoid tests
interferring with each other. Move the existing state-reset code into a
function so it can be used from tests.

Also update the code to reset the SPI devices and adjust the test code to
call it.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 11636258 12-May-2016 Stephen Warren <swarren@nvidia.com>

Rename reset to sysreset

The current reset API implements a method to reset the entire system.
In the near future, I'd like to introduce code that implements the device
tree reset bindings; i.e. the equivalent of the Linux kernel's reset API.
This controls resets to individual HW blocks or external chips with reset
signals. It doesn't make sense to merge the two APIs into one since they
have different semantic purposes. Resolve the naming conflict by renaming
the existing reset API to sysreset instead, so the new reset API can be
called just reset.

Signed-off-by: Stephen Warren <swarren@nvidia.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 9723563a 08-Nov-2015 Simon Glass <sjg@chromium.org>

sandbox: Add a way to skip time delays

Some tests are slow due to delays which are unnecessary on sandbox. The
worst offender is USB where we lose two seconds. Add a way to disable time
delays.

Signed-off-by: Simon Glass <sjg@chromium.org>

# dc6f4d3a 06-Jul-2015 Simon Glass <sjg@chromium.org>

sandbox: Support multiple reset types

Add settings for the last reset generated, and the types of resets which
are permitted. This will be used for testing.

Signed-off-by: Simon Glass <sjg@chromium.org>

# d73125cb 04-May-2015 Simon Glass <sjg@chromium.org>

sandbox: Correct error handling in state_read_file()

This function should return a useful error for U-Boot, rather than -1.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Joe Hershberger <joe.hershberger@ni.com>

# 88539e44 06-Feb-2015 Joe Hershberger <joe.hershberger@ni.com>

sandbox: Return '-c command' exit value as sandbox exit code

When a command is passed into sandbox using the '-c' argument the
command is run directly. This is most helpful when running tests (such
as test-dm.sh). Previously the exit code was an unused enum. Change it
to be the actual return code from the command so that the script calling
sandbox can know if the command succeeded (tests passed). Also remove
the now completely unused "exit_state" in sandbox.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 96b1046d 17-Nov-2014 Suriyan Ramasami <suriyan.r@gmail.com>

sandbox: Prepare API change for files greater than 2GB

Change the internal sandbox functions to use loff_t for file offsets.

Signed-off-by: Suriyan Ramasami <suriyan.r@gmail.com>

Acked-by: Simon Glass <sjg@chromium.org>

# ab839dc3 27-Feb-2014 Simon Glass <sjg@chromium.org>

sandbox: Add options to clean up temporary files

When jumping from one sandbox U-Boot to another in sandbox, the RAM buffer
is preserved in the jump by using a temporary file. Add an option to tell
the receiving U-Boot to remove this file when it is no longer needed.

Similarly the old U-Boot image is left behind in this case. We cannot delete
it immediately since gdb cannot then find its debug symbols. Delete it just
before exiting.

Together these changes ensure that temporary files are removed both for
memory and U-Boot.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 1209e272 10-Nov-2013 Simon Glass <sjg@chromium.org>

sandbox: Add facility to save/restore sandbox state

It is often useful to be able to save out the state from a sandbox test
run, for analysis or to restore it later to continue a test. Add generic
infrastructure for doing this using a device tree binary file. This is
a flexible tagged file format which is already supported by U-Boot, and
it supports hierarchy if needed.

Signed-off-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Hung-ying Tyan <tyanh@chromium.org>

# 5c2859cd 10-Nov-2013 Simon Glass <sjg@chromium.org>

sandbox: Allow reading/writing of RAM buffer

It is useful to be able to save and restore the RAM contents of sandbox
U-Boot either for setting up tests, for later analysys, or for chaining
together multiple tests which need to keep the same memory contents.

Add a function to provide a memory file for U-Boot. This is read on
start-up and written when shutting down. If the file does not exist
on start-up, it will be created when shutting down.

Signed-off-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Simon Glass <sjg@chromium.org>

# 1a459660 08-Jul-2013 Wolfgang Denk <wd@denx.de>

Add GPL-2.0+ SPDX-License-Identifier to source files

Signed-off-by: Wolfgang Denk <wd@denx.de>
[trini: Fixup common/cmd_io.c]
Signed-off-by: Tom Rini <trini@ti.com>

# 6fb62078 15-Feb-2012 Simon Glass <sjg@chromium.org>

sandbox: add concept of sandbox state

The state exists through the life of U-Boot. It can be adjusted by command
line options and perhaps later through a config file. It is available to
U-Boot through state_...() calls (within sandbox code).

The primary purpose of this is to contain the "hardware" state. It should
only be used by sandbox internal code.

Signed-off-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Mike Frysinger <vapier@gentoo.org>

# 857f39d7 16-May-2019 Urja Rannikko <urjaman@gmail.com>

sysreset: switch to using SYSRESET_POWER_OFF for poweroff

It seems that SYSRESET_POWER_OFF was added recently, and all previous code
used SYSRESET_POWER for poweroff. SYSRESET_POWER is supposed to be a
PMIC-level power cycle, not a poweroff.

(Comment by Simon Glass)
SYSRESET_POWER means to do a power reset (removing and reinstating all power)
SYSRESET_POWER_OFF means to turn the device off and leave it off

Signed-off-by: Urja Rannikko <urjaman@gmail.com>
Reviewed-by: Patrick Delaunay <patrick.delaunay@st.com>
(Update comment to help understand the patch)
Signed-off-by: Kever Yang <kever.yang@rock-chips.com>

# 9072326a 18-May-2019 Simon Glass <sjg@chromium.org>

sandbox: Exit when SYSRESET_POWER_OFF is requested

At present this returns but it seems better to just exit sandbox
immediately.

Signed-off-by: Simon Glass <sjg@chromium.org>

reset

# 1c5a81d8 01-Oct-2018 Simon Glass <sjg@chromium.org>

sandbox: Remove the old memory file later

When debugging sandbox it is sometimes annoying that the memory file is
deleted early on. If sandbox later crashes or we quit (using the
debugger), it is not possible to run it again with the same state since
the memory file is gone.

Remove the old memory file when sandbox exits, instead. Also add debugging
showing the memory filename.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 428aa0ca 15-Sep-2018 Simon Glass <sjg@chromium.org>

sandbox: Enhance map_to_sysmem() to handle foreign pointers

At present map_sysmem() maps an address into the sandbox RAM buffer,
return a pointer, while map_to_sysmem() goes the other way.

The mapping is currently just 1:1 since a case was not found where a more
flexible mapping was needed. PCI does have a separate and more complex
mapping, but uses its own mechanism.

However this arrange cannot handle one important case, which is where a
test declares a stack variable and passes a pointer to it into a U-Boot
function which uses map_to_sysmem() to turn it into a address. Since the
pointer is not inside emulated DRAM, this will fail.

Add a mapping feature which can handle any such pointer, mapping it to a
simple tag value which can be passed around in U-Boot as an address.

Signed-off-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Alexander Graf <agraf@suse.de>

# 83d290c5 06-May-2018 Tom Rini <trini@konsulko.com>

SPDX: Convert all of our single license tags to Linux Kernel style

When U-Boot started using SPDX tags we were among the early adopters and
there weren't a lot of other examples to borrow from. So we picked the
area of the file that usually had a full license text and replaced it
with an appropriate SPDX-License-Identifier: entry. Since then, the
Linux Kernel has adopted SPDX tags and they place it as the very first
line in a file (except where shebangs are used, then it's second line)
and with slightly different comment styles than us.

In part due to community overlap, in part due to better tag visibility
and in part for other minor reasons, switch over to that style.

This commit changes all instances where we have a single declared
license in the tag as both the before and after are identical in tag
contents. There's also a few places where I found we did not have a tag
and have introduced one.

Signed-off-by: Tom Rini <trini@konsulko.com>

# 9095d5b8 13-Feb-2018 Simon Goldschmidt <sgoldschmidt@de.pepperl-fuchs.com>

fix spelling of 'functions' in 2 places (was 'funtcions')

Signed-off-by: Simon Goldschmidt <sgoldschmidt@de.pepperl-fuchs.com>

# 34b744be 18-May-2017 Simon Glass <sjg@chromium.org>

sandbox: Add a way to reset sandbox state for tests

Running a new test should reset the sandbox state to avoid tests
interferring with each other. Move the existing state-reset code into a
function so it can be used from tests.

Also update the code to reset the SPI devices and adjust the test code to
call it.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 11636258 12-May-2016 Stephen Warren <swarren@nvidia.com>

Rename reset to sysreset

The current reset API implements a method to reset the entire system.
In the near future, I'd like to introduce code that implements the device
tree reset bindings; i.e. the equivalent of the Linux kernel's reset API.
This controls resets to individual HW blocks or external chips with reset
signals. It doesn't make sense to merge the two APIs into one since they
have different semantic purposes. Resolve the naming conflict by renaming
the existing reset API to sysreset instead, so the new reset API can be
called just reset.

Signed-off-by: Stephen Warren <swarren@nvidia.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 9723563a 08-Nov-2015 Simon Glass <sjg@chromium.org>

sandbox: Add a way to skip time delays

Some tests are slow due to delays which are unnecessary on sandbox. The
worst offender is USB where we lose two seconds. Add a way to disable time
delays.

Signed-off-by: Simon Glass <sjg@chromium.org>

# dc6f4d3a 06-Jul-2015 Simon Glass <sjg@chromium.org>

sandbox: Support multiple reset types

Add settings for the last reset generated, and the types of resets which
are permitted. This will be used for testing.

Signed-off-by: Simon Glass <sjg@chromium.org>

# d73125cb 04-May-2015 Simon Glass <sjg@chromium.org>

sandbox: Correct error handling in state_read_file()

This function should return a useful error for U-Boot, rather than -1.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Joe Hershberger <joe.hershberger@ni.com>

# 88539e44 06-Feb-2015 Joe Hershberger <joe.hershberger@ni.com>

sandbox: Return '-c command' exit value as sandbox exit code

When a command is passed into sandbox using the '-c' argument the
command is run directly. This is most helpful when running tests (such
as test-dm.sh). Previously the exit code was an unused enum. Change it
to be the actual return code from the command so that the script calling
sandbox can know if the command succeeded (tests passed). Also remove
the now completely unused "exit_state" in sandbox.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 96b1046d 17-Nov-2014 Suriyan Ramasami <suriyan.r@gmail.com>

sandbox: Prepare API change for files greater than 2GB

Change the internal sandbox functions to use loff_t for file offsets.

Signed-off-by: Suriyan Ramasami <suriyan.r@gmail.com>

Acked-by: Simon Glass <sjg@chromium.org>

# ab839dc3 27-Feb-2014 Simon Glass <sjg@chromium.org>

sandbox: Add options to clean up temporary files

When jumping from one sandbox U-Boot to another in sandbox, the RAM buffer
is preserved in the jump by using a temporary file. Add an option to tell
the receiving U-Boot to remove this file when it is no longer needed.

Similarly the old U-Boot image is left behind in this case. We cannot delete
it immediately since gdb cannot then find its debug symbols. Delete it just
before exiting.

Together these changes ensure that temporary files are removed both for
memory and U-Boot.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 1209e272 10-Nov-2013 Simon Glass <sjg@chromium.org>

sandbox: Add facility to save/restore sandbox state

It is often useful to be able to save out the state from a sandbox test
run, for analysis or to restore it later to continue a test. Add generic
infrastructure for doing this using a device tree binary file. This is
a flexible tagged file format which is already supported by U-Boot, and
it supports hierarchy if needed.

Signed-off-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Hung-ying Tyan <tyanh@chromium.org>

# 5c2859cd 10-Nov-2013 Simon Glass <sjg@chromium.org>

sandbox: Allow reading/writing of RAM buffer

It is useful to be able to save and restore the RAM contents of sandbox
U-Boot either for setting up tests, for later analysys, or for chaining
together multiple tests which need to keep the same memory contents.

Add a function to provide a memory file for U-Boot. This is read on
start-up and written when shutting down. If the file does not exist
on start-up, it will be created when shutting down.

Signed-off-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Simon Glass <sjg@chromium.org>

# 1a459660 08-Jul-2013 Wolfgang Denk <wd@denx.de>

Add GPL-2.0+ SPDX-License-Identifier to source files

Signed-off-by: Wolfgang Denk <wd@denx.de>
[trini: Fixup common/cmd_io.c]
Signed-off-by: Tom Rini <trini@ti.com>

# 6fb62078 15-Feb-2012 Simon Glass <sjg@chromium.org>

sandbox: add concept of sandbox state

The state exists through the life of U-Boot. It can be adjusted by command
line options and perhaps later through a config file. It is available to
U-Boot through state_...() calls (within sandbox code).

The primary purpose of this is to contain the "hardware" state. It should
only be used by sandbox internal code.

Signed-off-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Mike Frysinger <vapier@gentoo.org>

# 1c5a81d8 01-Oct-2018 Simon Glass <sjg@chromium.org>

sandbox: Remove the old memory file later

When debugging sandbox it is sometimes annoying that the memory file is
deleted early on. If sandbox later crashes or we quit (using the
debugger), it is not possible to run it again with the same state since
the memory file is gone.

Remove the old memory file when sandbox exits, instead. Also add debugging
showing the memory filename.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 428aa0ca 15-Sep-2018 Simon Glass <sjg@chromium.org>

sandbox: Enhance map_to_sysmem() to handle foreign pointers

At present map_sysmem() maps an address into the sandbox RAM buffer,
return a pointer, while map_to_sysmem() goes the other way.

The mapping is currently just 1:1 since a case was not found where a more
flexible mapping was needed. PCI does have a separate and more complex
mapping, but uses its own mechanism.

However this arrange cannot handle one important case, which is where a
test declares a stack variable and passes a pointer to it into a U-Boot
function which uses map_to_sysmem() to turn it into a address. Since the
pointer is not inside emulated DRAM, this will fail.

Add a mapping feature which can handle any such pointer, mapping it to a
simple tag value which can be passed around in U-Boot as an address.

Signed-off-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Alexander Graf <agraf@suse.de>


# 83d290c5 06-May-2018 Tom Rini <trini@konsulko.com>

SPDX: Convert all of our single license tags to Linux Kernel style

When U-Boot started using SPDX tags we were among the early adopters and
there weren't a lot of other examples to borrow from. So we picked the
area of the file that usually had a full license text and replaced it
with an appropriate SPDX-License-Identifier: entry. Since then, the
Linux Kernel has adopted SPDX tags and they place it as the very first
line in a file (except where shebangs are used, then it's second line)
and with slightly different comment styles than us.

In part due to community overlap, in part due to better tag visibility
and in part for other minor reasons, switch over to that style.

This commit changes all instances where we have a single declared
license in the tag as both the before and after are identical in tag
contents. There's also a few places where I found we did not have a tag
and have introduced one.

Signed-off-by: Tom Rini <trini@konsulko.com>


# 9095d5b8 13-Feb-2018 Simon Goldschmidt <sgoldschmidt@de.pepperl-fuchs.com>

fix spelling of 'functions' in 2 places (was 'funtcions')

Signed-off-by: Simon Goldschmidt <sgoldschmidt@de.pepperl-fuchs.com>


# 34b744be 18-May-2017 Simon Glass <sjg@chromium.org>

sandbox: Add a way to reset sandbox state for tests

Running a new test should reset the sandbox state to avoid tests
interferring with each other. Move the existing state-reset code into a
function so it can be used from tests.

Also update the code to reset the SPI devices and adjust the test code to
call it.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 11636258 12-May-2016 Stephen Warren <swarren@nvidia.com>

Rename reset to sysreset

The current reset API implements a method to reset the entire system.
In the near future, I'd like to introduce code that implements the device
tree reset bindings; i.e. the equivalent of the Linux kernel's reset API.
This controls resets to individual HW blocks or external chips with reset
signals. It doesn't make sense to merge the two APIs into one since they
have different semantic purposes. Resolve the naming conflict by renaming
the existing reset API to sysreset instead, so the new reset API can be
called just reset.

Signed-off-by: Stephen Warren <swarren@nvidia.com>
Acked-by: Simon Glass <sjg@chromium.org>


# 9723563a 08-Nov-2015 Simon Glass <sjg@chromium.org>

sandbox: Add a way to skip time delays

Some tests are slow due to delays which are unnecessary on sandbox. The
worst offender is USB where we lose two seconds. Add a way to disable time
delays.

Signed-off-by: Simon Glass <sjg@chromium.org>


# dc6f4d3a 06-Jul-2015 Simon Glass <sjg@chromium.org>

sandbox: Support multiple reset types

Add settings for the last reset generated, and the types of resets which
are permitted. This will be used for testing.

Signed-off-by: Simon Glass <sjg@chromium.org>


# d73125cb 04-May-2015 Simon Glass <sjg@chromium.org>

sandbox: Correct error handling in state_read_file()

This function should return a useful error for U-Boot, rather than -1.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Joe Hershberger <joe.hershberger@ni.com>


# 88539e44 06-Feb-2015 Joe Hershberger <joe.hershberger@ni.com>

sandbox: Return '-c command' exit value as sandbox exit code

When a command is passed into sandbox using the '-c' argument the
command is run directly. This is most helpful when running tests (such
as test-dm.sh). Previously the exit code was an unused enum. Change it
to be the actual return code from the command so that the script calling
sandbox can know if the command succeeded (tests passed). Also remove
the now completely unused "exit_state" in sandbox.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>


# 96b1046d 17-Nov-2014 Suriyan Ramasami <suriyan.r@gmail.com>

sandbox: Prepare API change for files greater than 2GB

Change the internal sandbox functions to use loff_t for file offsets.

Signed-off-by: Suriyan Ramasami <suriyan.r@gmail.com>

Acked-by: Simon Glass <sjg@chromium.org>


# ab839dc3 27-Feb-2014 Simon Glass <sjg@chromium.org>

sandbox: Add options to clean up temporary files

When jumping from one sandbox U-Boot to another in sandbox, the RAM buffer
is preserved in the jump by using a temporary file. Add an option to tell
the receiving U-Boot to remove this file when it is no longer needed.

Similarly the old U-Boot image is left behind in this case. We cannot delete
it immediately since gdb cannot then find its debug symbols. Delete it just
before exiting.

Together these changes ensure that temporary files are removed both for
memory and U-Boot.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 1209e272 10-Nov-2013 Simon Glass <sjg@chromium.org>

sandbox: Add facility to save/restore sandbox state

It is often useful to be able to save out the state from a sandbox test
run, for analysis or to restore it later to continue a test. Add generic
infrastructure for doing this using a device tree binary file. This is
a flexible tagged file format which is already supported by U-Boot, and
it supports hierarchy if needed.

Signed-off-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Hung-ying Tyan <tyanh@chromium.org>


# 5c2859cd 10-Nov-2013 Simon Glass <sjg@chromium.org>

sandbox: Allow reading/writing of RAM buffer

It is useful to be able to save and restore the RAM contents of sandbox
U-Boot either for setting up tests, for later analysys, or for chaining
together multiple tests which need to keep the same memory contents.

Add a function to provide a memory file for U-Boot. This is read on
start-up and written when shutting down. If the file does not exist
on start-up, it will be created when shutting down.

Signed-off-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Simon Glass <sjg@chromium.org>


# 1a459660 08-Jul-2013 Wolfgang Denk <wd@denx.de>

Add GPL-2.0+ SPDX-License-Identifier to source files

Signed-off-by: Wolfgang Denk <wd@denx.de>
[trini: Fixup common/cmd_io.c]
Signed-off-by: Tom Rini <trini@ti.com>


# 6fb62078 15-Feb-2012 Simon Glass <sjg@chromium.org>

sandbox: add concept of sandbox state

The state exists through the life of U-Boot. It can be adjusted by command
line options and perhaps later through a config file. It is available to
U-Boot through state_...() calls (within sandbox code).

The primary purpose of this is to contain the "hardware" state. It should
only be used by sandbox internal code.

Signed-off-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Mike Frysinger <vapier@gentoo.org>