2018-05-06 21:58:06 +00:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0+ */
|
2012-02-15 23:51:15 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2011-2012 The Chromium OS Authors.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef __SANDBOX_STATE_H
|
|
|
|
#define __SANDBOX_STATE_H
|
|
|
|
|
2012-02-15 23:51:16 +00:00
|
|
|
#include <config.h>
|
2016-05-12 18:03:35 +00:00
|
|
|
#include <sysreset.h>
|
2013-11-10 17:27:02 +00:00
|
|
|
#include <stdbool.h>
|
2018-09-15 06:50:56 +00:00
|
|
|
#include <linux/list.h>
|
2013-11-10 17:27:04 +00:00
|
|
|
#include <linux/stringify.h>
|
2012-02-15 23:51:16 +00:00
|
|
|
|
2014-02-27 20:26:22 +00:00
|
|
|
/**
|
|
|
|
* Selects the behavior of the serial terminal.
|
|
|
|
*
|
|
|
|
* If Ctrl-C is processed by U-Boot, then the only way to quit sandbox is with
|
|
|
|
* the 'reset' command, or equivalent.
|
|
|
|
*
|
|
|
|
* If the terminal is cooked, then Ctrl-C will terminate U-Boot, and the
|
|
|
|
* command line will not be quite such a faithful emulation.
|
|
|
|
*
|
|
|
|
* Options are:
|
|
|
|
*
|
|
|
|
* raw-with-sigs - Raw, but allow signals (Ctrl-C will quit)
|
|
|
|
* raw - Terminal is always raw
|
|
|
|
* cooked - Terminal is always cooked
|
|
|
|
*/
|
|
|
|
enum state_terminal_raw {
|
|
|
|
STATE_TERM_RAW_WITH_SIGS, /* Default */
|
|
|
|
STATE_TERM_RAW,
|
|
|
|
STATE_TERM_COOKED,
|
|
|
|
|
|
|
|
STATE_TERM_COUNT,
|
|
|
|
};
|
|
|
|
|
2013-12-03 23:43:26 +00:00
|
|
|
struct sandbox_spi_info {
|
2014-10-14 05:41:57 +00:00
|
|
|
struct udevice *emul;
|
2013-12-03 23:43:26 +00:00
|
|
|
};
|
|
|
|
|
2017-04-17 19:00:21 +00:00
|
|
|
struct sandbox_wdt_info {
|
|
|
|
unsigned long long counter;
|
|
|
|
uint reset_count;
|
|
|
|
bool running;
|
|
|
|
};
|
|
|
|
|
2018-09-15 06:50:56 +00:00
|
|
|
/**
|
|
|
|
* struct sandbox_mapmem_entry - maps pointers to/from U-Boot addresses
|
|
|
|
*
|
|
|
|
* When map_to_sysmem() is called with an address outside sandbox's emulated
|
|
|
|
* RAM, a record is created with a tag that can be used to reference that
|
|
|
|
* pointer. When map_sysmem() is called later with that tag, the pointer will
|
|
|
|
* be returned, just as it would for a normal sandbox address.
|
|
|
|
*
|
|
|
|
* @tag: Address tag (a value which U-Boot uses to refer to the address)
|
|
|
|
* @ptr: Associated pointer for that tag
|
|
|
|
*/
|
|
|
|
struct sandbox_mapmem_entry {
|
|
|
|
ulong tag;
|
|
|
|
void *ptr;
|
|
|
|
struct list_head sibling_node;
|
|
|
|
};
|
|
|
|
|
2012-02-15 23:51:15 +00:00
|
|
|
/* The complete state of the test system */
|
|
|
|
struct sandbox_state {
|
|
|
|
const char *cmd; /* Command to execute */
|
2013-11-10 17:27:02 +00:00
|
|
|
bool interactive; /* Enable cmdline after execute */
|
2015-04-30 20:16:09 +00:00
|
|
|
bool run_distro_boot; /* Automatically run distro bootcommands */
|
2013-04-20 08:42:41 +00:00
|
|
|
const char *fdt_fname; /* Filename of FDT binary */
|
2012-02-15 23:51:16 +00:00
|
|
|
const char *parse_err; /* Error to report from parsing */
|
|
|
|
int argc; /* Program arguments */
|
2014-02-27 20:26:16 +00:00
|
|
|
char **argv; /* Command line arguments */
|
2014-02-27 20:26:23 +00:00
|
|
|
const char *jumped_fname; /* Jumped from previous U_Boot */
|
2013-11-10 17:27:03 +00:00
|
|
|
uint8_t *ram_buf; /* Emulated RAM buffer */
|
|
|
|
unsigned int ram_size; /* Size of RAM buffer */
|
|
|
|
const char *ram_buf_fname; /* Filename to use for RAM buffer */
|
2014-02-27 20:26:23 +00:00
|
|
|
bool ram_buf_rm; /* Remove RAM buffer file after read */
|
2013-11-10 17:27:03 +00:00
|
|
|
bool write_ram_buf; /* Write RAM buffer on exit */
|
2013-11-10 17:27:04 +00:00
|
|
|
const char *state_fname; /* File containing sandbox state */
|
|
|
|
void *state_fdt; /* Holds saved state for sandbox */
|
|
|
|
bool read_state; /* Read sandbox state on startup */
|
|
|
|
bool write_state; /* Write sandbox state on exit */
|
|
|
|
bool ignore_missing_state_on_read; /* No error if state missing */
|
2014-02-27 20:26:19 +00:00
|
|
|
bool show_lcd; /* Show LCD on start-up */
|
2016-05-12 18:03:35 +00:00
|
|
|
enum sysreset_t last_sysreset; /* Last system reset type */
|
|
|
|
bool sysreset_allowed[SYSRESET_COUNT]; /* Allowed system reset types */
|
2014-02-27 20:26:22 +00:00
|
|
|
enum state_terminal_raw term_raw; /* Terminal raw/cooked */
|
2015-11-09 06:47:43 +00:00
|
|
|
bool skip_delays; /* Ignore any time delays (for test) */
|
2015-11-09 06:47:50 +00:00
|
|
|
bool show_test_output; /* Don't suppress stdout in tests */
|
2018-10-01 17:55:11 +00:00
|
|
|
int default_log_level; /* Default log level for sandbox */
|
2013-12-03 23:43:26 +00:00
|
|
|
|
|
|
|
/* Pointer to information for each SPI bus/cs */
|
|
|
|
struct sandbox_spi_info spi[CONFIG_SANDBOX_SPI_MAX_BUS]
|
|
|
|
[CONFIG_SANDBOX_SPI_MAX_CS];
|
2017-04-17 19:00:21 +00:00
|
|
|
|
|
|
|
/* Information about Watchdog */
|
|
|
|
struct sandbox_wdt_info wdt;
|
2018-09-15 06:50:56 +00:00
|
|
|
|
|
|
|
ulong next_tag; /* Next address tag to allocate */
|
|
|
|
struct list_head mapmem_head; /* struct sandbox_mapmem_entry */
|
2012-02-15 23:51:15 +00:00
|
|
|
};
|
|
|
|
|
2013-11-10 17:27:04 +00:00
|
|
|
/* Minimum space we guarantee in the state FDT when calling read/write*/
|
|
|
|
#define SANDBOX_STATE_MIN_SPACE 0x1000
|
|
|
|
|
|
|
|
/**
|
|
|
|
* struct sandbox_state_io - methods to saved/restore sandbox state
|
|
|
|
* @name: Name of of the device tree node, also the name of the variable
|
|
|
|
* holding this data so it should be an identifier (use underscore
|
|
|
|
* instead of minus)
|
|
|
|
* @compat: Compatible string for the node containing this state
|
|
|
|
*
|
|
|
|
* @read: Function to read state from FDT
|
|
|
|
* If data is available, then blob and node will provide access to it. If
|
|
|
|
* not (blob == NULL and node == -1) this function should set up an empty
|
|
|
|
* data set for start-of-day.
|
|
|
|
* @param blob: Pointer to device tree blob, or NULL if no data to read
|
|
|
|
* @param node: Node offset to read from
|
|
|
|
* @return 0 if OK, -ve on error
|
|
|
|
*
|
|
|
|
* @write: Function to write state to FDT
|
|
|
|
* The caller will ensure that there is a node ready for the state. The
|
|
|
|
* node may already contain the old state, in which case it should be
|
|
|
|
* overridden. There is guaranteed to be SANDBOX_STATE_MIN_SPACE bytes
|
|
|
|
* of free space, so error checking is not required for fdt_setprop...()
|
|
|
|
* calls which add up to less than this much space.
|
|
|
|
*
|
|
|
|
* For adding larger properties, use state_setprop().
|
|
|
|
*
|
|
|
|
* @param blob: Device tree blob holding state
|
|
|
|
* @param node: Node to write our state into
|
|
|
|
*
|
|
|
|
* Note that it is possible to save data as large blobs or as individual
|
|
|
|
* hierarchical properties. However, unless you intend to keep state files
|
|
|
|
* around for a long time and be able to run an old state file on a new
|
|
|
|
* sandbox, it might not be worth using individual properties for everything.
|
|
|
|
* This is certainly supported, it is just a matter of the effort you wish
|
|
|
|
* to put into the state read/write feature.
|
|
|
|
*/
|
|
|
|
struct sandbox_state_io {
|
|
|
|
const char *name;
|
|
|
|
const char *compat;
|
|
|
|
int (*write)(void *blob, int node);
|
|
|
|
int (*read)(const void *blob, int node);
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* SANDBOX_STATE_IO - Declare sandbox state to read/write
|
|
|
|
*
|
|
|
|
* Sandbox permits saving state from one run and restoring it in another. This
|
|
|
|
* allows the test system to retain state between runs and thus better
|
|
|
|
* emulate a real system. Examples of state that might be useful to save are
|
|
|
|
* the emulated GPIOs pin settings, flash memory contents and TPM private
|
|
|
|
* data. U-Boot memory contents is dealth with separately since it is large
|
|
|
|
* and it is not normally useful to save it (since a normal system does not
|
|
|
|
* preserve DRAM between runs). See the '-m' option for this.
|
|
|
|
*
|
|
|
|
* See struct sandbox_state_io above for member documentation.
|
|
|
|
*/
|
|
|
|
#define SANDBOX_STATE_IO(_name, _compat, _read, _write) \
|
|
|
|
ll_entry_declare(struct sandbox_state_io, _name, state_io) = { \
|
|
|
|
.name = __stringify(_name), \
|
|
|
|
.read = _read, \
|
|
|
|
.write = _write, \
|
|
|
|
.compat = _compat, \
|
|
|
|
}
|
|
|
|
|
2012-02-15 23:51:15 +00:00
|
|
|
/**
|
|
|
|
* Gets a pointer to the current state.
|
|
|
|
*
|
|
|
|
* @return pointer to state
|
|
|
|
*/
|
|
|
|
struct sandbox_state *state_get_current(void);
|
|
|
|
|
2013-11-10 17:27:04 +00:00
|
|
|
/**
|
|
|
|
* Read the sandbox state from the supplied device tree file
|
|
|
|
*
|
|
|
|
* This calls all registered state handlers to read in the sandbox state
|
|
|
|
* from a previous test run.
|
|
|
|
*
|
|
|
|
* @param state Sandbox state to update
|
|
|
|
* @param fname Filename of device tree file to read from
|
|
|
|
* @return 0 if OK, -ve on error
|
|
|
|
*/
|
|
|
|
int sandbox_read_state(struct sandbox_state *state, const char *fname);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Write the sandbox state to the supplied device tree file
|
|
|
|
*
|
|
|
|
* This calls all registered state handlers to write out the sandbox state
|
|
|
|
* so that it can be preserved for a future test run.
|
|
|
|
*
|
|
|
|
* If the file exists it is overwritten.
|
|
|
|
*
|
|
|
|
* @param state Sandbox state to update
|
|
|
|
* @param fname Filename of device tree file to write to
|
|
|
|
* @return 0 if OK, -ve on error
|
|
|
|
*/
|
|
|
|
int sandbox_write_state(struct sandbox_state *state, const char *fname);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Add a property to a sandbox state node
|
|
|
|
*
|
|
|
|
* This is equivalent to fdt_setprop except that it automatically enlarges
|
|
|
|
* the device tree if necessary. That means it is safe to write any amount
|
|
|
|
* of data here.
|
|
|
|
*
|
|
|
|
* This function can only be called from within struct sandbox_state_io's
|
|
|
|
* ->write method, i.e. within state I/O drivers.
|
|
|
|
*
|
|
|
|
* @param node Device tree node to write to
|
|
|
|
* @param prop_name Property to write
|
|
|
|
* @param data Data to write into property
|
|
|
|
* @param size Size of data to write into property
|
|
|
|
*/
|
|
|
|
int state_setprop(int node, const char *prop_name, const void *data, int size);
|
|
|
|
|
2015-11-09 06:47:43 +00:00
|
|
|
/**
|
|
|
|
* Control skipping of time delays
|
|
|
|
*
|
|
|
|
* Some tests have unnecessay time delays (e.g. USB). Allow these to be
|
|
|
|
* skipped to speed up testing
|
|
|
|
*
|
|
|
|
* @param skip_delays true to skip delays from now on, false to honour delay
|
|
|
|
* requests
|
|
|
|
*/
|
|
|
|
void state_set_skip_delays(bool skip_delays);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* See if delays should be skipped
|
|
|
|
*
|
|
|
|
* @return true if delays should be skipped, false if they should be honoured
|
|
|
|
*/
|
|
|
|
bool state_get_skip_delays(void);
|
|
|
|
|
2017-05-19 02:09:13 +00:00
|
|
|
/**
|
|
|
|
* state_reset_for_test() - Reset ready to re-run tests
|
|
|
|
*
|
|
|
|
* This clears out any test state ready for another test run.
|
|
|
|
*/
|
|
|
|
void state_reset_for_test(struct sandbox_state *state);
|
|
|
|
|
2012-02-15 23:51:15 +00:00
|
|
|
/**
|
|
|
|
* Initialize the test system state
|
|
|
|
*/
|
|
|
|
int state_init(void);
|
|
|
|
|
2013-11-10 17:27:03 +00:00
|
|
|
/**
|
|
|
|
* Uninitialize the test system state, writing out state if configured to
|
|
|
|
* do so.
|
|
|
|
*
|
|
|
|
* @return 0 if OK, -ve on error
|
|
|
|
*/
|
|
|
|
int state_uninit(void);
|
|
|
|
|
2012-02-15 23:51:15 +00:00
|
|
|
#endif
|