From 909bd6d9729cb0c6ba6b80cdc283bbd3e1e12770 Mon Sep 17 00:00:00 2001 From: Joe Hershberger Date: Tue, 21 Apr 2015 13:57:18 -0500 Subject: sandbox: Add test function to advance time Add a function that maintains an offset to include in the system timer values returned from the lib/time.c APIs. This will allow timeouts to be skipped instantly in tests Signed-off-by: Joe Hershberger Acked-by: Simon Glass --- arch/sandbox/cpu/cpu.c | 5 ----- arch/sandbox/include/asm/test.h | 8 ++++++++ 2 files changed, 8 insertions(+), 5 deletions(-) (limited to 'arch') diff --git a/arch/sandbox/cpu/cpu.c b/arch/sandbox/cpu/cpu.c index 168f2efa33e..b6aae3718a1 100644 --- a/arch/sandbox/cpu/cpu.c +++ b/arch/sandbox/cpu/cpu.c @@ -45,11 +45,6 @@ void __udelay(unsigned long usec) os_usleep(usec); } -unsigned long __attribute__((no_instrument_function)) timer_get_us(void) -{ - return os_get_nsec() / 1000; -} - int cleanup_before_linux(void) { return 0; diff --git a/arch/sandbox/include/asm/test.h b/arch/sandbox/include/asm/test.h index 8e490e96d7a..296589c2826 100644 --- a/arch/sandbox/include/asm/test.h +++ b/arch/sandbox/include/asm/test.h @@ -28,4 +28,12 @@ void sandbox_i2c_eeprom_set_test_mode(struct udevice *dev, void sandbox_i2c_eeprom_set_offset_len(struct udevice *dev, int offset_len); +/* + * sandbox_timer_add_offset() + * + * Allow tests to add to the time reported through lib/time.c functions + * offset: number of milliseconds to advance the system time + */ +void sandbox_timer_add_offset(unsigned long offset); + #endif -- cgit v1.2.3 From 6f2707c6b135681f821b55cac484a7512f5fe79a Mon Sep 17 00:00:00 2001 From: Joe Hershberger Date: Tue, 21 Apr 2015 13:57:19 -0500 Subject: sandbox: eth: Add a function to skip ping timeouts When called, the next call to receive will trigger a 10-second leap forward in time to avoid waiting for time to pass when tests are evaluating timeout behavior. Signed-off-by: Joe Hershberger Acked-by: Simon Glass --- arch/sandbox/include/asm/eth.h | 2 ++ 1 file changed, 2 insertions(+) (limited to 'arch') diff --git a/arch/sandbox/include/asm/eth.h b/arch/sandbox/include/asm/eth.h index 4b79ede9b99..88804fb8e26 100644 --- a/arch/sandbox/include/asm/eth.h +++ b/arch/sandbox/include/asm/eth.h @@ -12,4 +12,6 @@ void sandbox_eth_disable_response(int index, bool disable); +void sandbox_eth_skip_timeout(void); + #endif /* __ETH_H */ -- cgit v1.2.3 From 182bf92d19cf007c2d6b9a264107d6996ae9014f Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Mon, 20 Apr 2015 12:37:15 -0600 Subject: dm: i2c: Add an explicit test mode to the sandbox I2C driver At present this driver has a few test features. They are needed for running the driver model unit tests but are confusing and unnecessary if using sandbox at the command line. Add a flag to enable the test mode, and don't enable it by default. Signed-off-by: Simon Glass --- arch/sandbox/include/asm/test.h | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'arch') diff --git a/arch/sandbox/include/asm/test.h b/arch/sandbox/include/asm/test.h index 296589c2826..06e73012680 100644 --- a/arch/sandbox/include/asm/test.h +++ b/arch/sandbox/include/asm/test.h @@ -17,6 +17,16 @@ #define SANDBOX_PCI_CLASS_CODE PCI_CLASS_CODE_COMM #define SANDBOX_PCI_CLASS_SUB_CODE PCI_CLASS_SUB_CODE_COMM_SERIAL +/** + * sandbox_i2c_set_test_mode() - set test mode for running unit tests + * + * See sandbox_i2c_xfer() for the behaviour changes. + * + * @bus: sandbox I2C bus to adjust + * @test_mode: true to select test mode, false to run normally + */ +void sandbox_i2c_set_test_mode(struct udevice *bus, bool test_mode); + enum sandbox_i2c_eeprom_test_mode { SIE_TEST_MODE_NONE, /* Permits read/write of only one byte per I2C transaction */ -- cgit v1.2.3 From 94eefdee2f5db36d52e817a01b07c8255527e193 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Mon, 20 Apr 2015 12:37:22 -0600 Subject: dm: sandbox: Add os_localtime() to obtain the system time Add a function to read the system time into U-Boot. Signed-off-by: Simon Glass --- arch/sandbox/cpu/os.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'arch') diff --git a/arch/sandbox/cpu/os.c b/arch/sandbox/cpu/os.c index 4d5f8057533..e6dd17e9efc 100644 --- a/arch/sandbox/cpu/os.c +++ b/arch/sandbox/cpu/os.c @@ -24,6 +24,7 @@ #include #include #include +#include /* Operating System Interface */ @@ -537,3 +538,20 @@ int os_jump_to_image(const void *dest, int size) return unlink(fname); } + +void os_localtime(struct rtc_time *rt) +{ + time_t t = time(NULL); + struct tm *tm; + + tm = localtime(&t); + rt->tm_sec = tm->tm_sec; + rt->tm_min = tm->tm_min; + rt->tm_hour = tm->tm_hour; + rt->tm_mday = tm->tm_mday; + rt->tm_mon = tm->tm_mon + 1; + rt->tm_year = tm->tm_year + 1900; + rt->tm_wday = tm->tm_wday; + rt->tm_yday = tm->tm_yday; + rt->tm_isdst = tm->tm_isdst; +} -- cgit v1.2.3 From dd18e5d8441e12e4ed084dfe7400112851b807f8 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Mon, 20 Apr 2015 12:37:24 -0600 Subject: dm: rtc: sandbox: Add an emulated I2C RTC device Add a sandbox I2C emulation device which emulates a real-time clock. The clock works off an offset from the current system time, and supports setting and getting the clock, as well as access to byte-width regisers in the RTC. It does not support changing the system time. This device can be used for testing the 'date' command on sandbox, as well as the RTC uclass. Signed-off-by: Simon Glass --- arch/sandbox/include/asm/rtc.h | 28 ++++++++++++++++++++++++++++ arch/sandbox/include/asm/test.h | 21 +++++++++++++++++++++ 2 files changed, 49 insertions(+) create mode 100644 arch/sandbox/include/asm/rtc.h (limited to 'arch') diff --git a/arch/sandbox/include/asm/rtc.h b/arch/sandbox/include/asm/rtc.h new file mode 100644 index 00000000000..5ed4584641c --- /dev/null +++ b/arch/sandbox/include/asm/rtc.h @@ -0,0 +1,28 @@ +/* + * Simulate an I2C real time clock + * + * Copyright (c) 2015 Google, Inc + * Written by Simon Glass + * + * SPDX-License-Identifier: GPL-2.0+ + */ + +#ifndef __asm_rtc_h +#define __asm_rtc_h + +/* Register numbers in the sandbox RTC */ +enum { + REG_SEC = 5, + REG_MIN, + REG_HOUR, + REG_MDAY, + REG_MON, + REG_YEAR, + REG_WDAY, + + REG_RESET = 0x20, + + REG_COUNT = 0x80, +}; + +#endif diff --git a/arch/sandbox/include/asm/test.h b/arch/sandbox/include/asm/test.h index 06e73012680..91a5c79ad2f 100644 --- a/arch/sandbox/include/asm/test.h +++ b/arch/sandbox/include/asm/test.h @@ -46,4 +46,25 @@ void sandbox_i2c_eeprom_set_offset_len(struct udevice *dev, int offset_len); */ void sandbox_timer_add_offset(unsigned long offset); +/** + * sandbox_i2c_rtc_set_offset() - set the time offset from system/base time + * + * @dev: RTC device to adjust + * @use_system_time: true to use system time, false to use @base_time + * @offset: RTC offset from current system/base time (-1 for no + * change) + * @return old value of RTC offset + */ +long sandbox_i2c_rtc_set_offset(struct udevice *dev, bool use_system_time, + int offset); + +/** + * sandbox_i2c_rtc_get_set_base_time() - get and set the base time + * + * @dev: RTC device to adjust + * @base_time: New base system time (set to -1 for no change) + * @return old base time + */ +long sandbox_i2c_rtc_get_set_base_time(struct udevice *dev, long base_time); + #endif -- cgit v1.2.3 From 46af3608ead71815c1a311dcf38aea773e584202 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Mon, 20 Apr 2015 12:37:28 -0600 Subject: dm: sandbox: dts: Add a real-time clock attached to I2C Add an emulated RTC device for sandbox, so that the 'date' command can be used. Signed-off-by: Simon Glass --- arch/sandbox/dts/sandbox.dts | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'arch') diff --git a/arch/sandbox/dts/sandbox.dts b/arch/sandbox/dts/sandbox.dts index efa2097b2d6..82d186ee5b0 100644 --- a/arch/sandbox/dts/sandbox.dts +++ b/arch/sandbox/dts/sandbox.dts @@ -8,7 +8,9 @@ aliases { eth5 = "/eth@90000000"; + i2c0 = &i2c_0; pci0 = &pci; + rtc0 = &rtc_0; }; chosen { @@ -90,7 +92,7 @@ num-gpios = <10>; }; - i2c@0 { + i2c_0: i2c@0 { #address-cells = <1>; #size-cells = <0>; reg = <0 0>; @@ -105,6 +107,14 @@ sandbox,size = <128>; }; }; + + rtc_0: rtc@43 { + reg = <0x43>; + compatible = "sandbox-rtc"; + emul { + compatible = "sandbox,i2c-rtc"; + }; + }; }; spi@0 { -- cgit v1.2.3 From ebaa832e9904677e2aea96d20e9c2c669e1ec7df Mon Sep 17 00:00:00 2001 From: Sjoerd Simons Date: Thu, 30 Apr 2015 22:16:09 +0200 Subject: sandbox: Don't try distro_bootcmd by default For the distro_bootcmds to succeed on the sandbox a bit of setup is required (e.g. network configured or host image bound), so running them by default isn't that useful. Add a -b/--boot command to the sandbox binary, which triggers the distro_bootcmds to run after the other command-line commands. Signed-off-by: Sjoerd Simons Acked-by: Simon Glass --- arch/sandbox/cpu/start.c | 20 +++++++++++++++++--- arch/sandbox/include/asm/state.h | 1 + 2 files changed, 18 insertions(+), 3 deletions(-) (limited to 'arch') diff --git a/arch/sandbox/cpu/start.c b/arch/sandbox/cpu/start.c index ec010402d77..b23d08b5a1b 100644 --- a/arch/sandbox/cpu/start.c +++ b/arch/sandbox/cpu/start.c @@ -77,12 +77,18 @@ int sandbox_main_loop_init(void) struct sandbox_state *state = state_get_current(); /* Execute command if required */ - if (state->cmd) { - int retval; + if (state->cmd || state->run_distro_boot) { + int retval = 0; cli_init(); - retval = run_command_list(state->cmd, -1, 0); + if (state->cmd) + retval = run_command_list(state->cmd, -1, 0); + + if (state->run_distro_boot) + retval = cli_simple_run_command("run distro_bootcmd", + 0); + if (!state->interactive) os_exit(retval); } @@ -90,6 +96,14 @@ int sandbox_main_loop_init(void) return 0; } +static int sandbox_cmdline_cb_boot(struct sandbox_state *state, + const char *arg) +{ + state->run_distro_boot = true; + return 0; +} +SANDBOX_CMDLINE_OPT_SHORT(boot, 'b', 0, "Run distro boot commands"); + static int sandbox_cmdline_cb_command(struct sandbox_state *state, const char *arg) { diff --git a/arch/sandbox/include/asm/state.h b/arch/sandbox/include/asm/state.h index a0c24ba1e05..a57480a996f 100644 --- a/arch/sandbox/include/asm/state.h +++ b/arch/sandbox/include/asm/state.h @@ -42,6 +42,7 @@ struct sandbox_spi_info { struct sandbox_state { const char *cmd; /* Command to execute */ bool interactive; /* Enable cmdline after execute */ + bool run_distro_boot; /* Automatically run distro bootcommands */ const char *fdt_fname; /* Filename of FDT binary */ const char *parse_err; /* Error to report from parsing */ int argc; /* Program arguments */ -- cgit v1.2.3