]> git.baikalelectronics.ru Git - uboot.git/commitdiff
sandbox: Allow ethernet to be disabled at runtime
authorSimon Glass <sjg@chromium.org>
Tue, 17 Jan 2023 17:47:27 +0000 (10:47 -0700)
committerTom Rini <trini@konsulko.com>
Mon, 23 Jan 2023 23:11:39 +0000 (18:11 -0500)
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>
arch/sandbox/cpu/state.c
arch/sandbox/include/asm/state.h
arch/sandbox/include/asm/test.h
include/test/test.h
net/net.c

index dd7978cfced3e7c7c77a4ddde842b2f7e9f04e4f..267f280df14f6d80b8d5832172fb4ddad4343ef8 100644 (file)
@@ -12,6 +12,7 @@
 #include <os.h>
 #include <asm/malloc.h>
 #include <asm/state.h>
+#include <asm/test.h>
 
 /* Main state record for the sandbox */
 static struct sandbox_state main_state;
@@ -366,6 +367,7 @@ void state_reset_for_test(struct sandbox_state *state)
        state->sysreset_allowed[SYSRESET_POWER_OFF] = true;
        state->sysreset_allowed[SYSRESET_COLD] = true;
        state->allow_memio = false;
+       sandbox_set_eth_enable(true);
 
        memset(&state->wdt, '\0', sizeof(state->wdt));
        memset(state->spi, '\0', sizeof(state->spi));
@@ -444,6 +446,20 @@ int state_load_other_fdt(const char **bufp, int *sizep)
        return 0;
 }
 
+void sandbox_set_eth_enable(bool enable)
+{
+       struct sandbox_state *state = state_get_current();
+
+       state->disable_eth = !enable;
+}
+
+bool sandbox_eth_enabled(void)
+{
+       struct sandbox_state *state = state_get_current();
+
+       return !state->disable_eth;
+}
+
 int state_init(void)
 {
        state = &main_state;
index 49ea483d332bfc3a5a910d98e7b592f3b98ff1a6..f125fb87af71c8a802dac3779a21b214f1201755 100644 (file)
@@ -96,6 +96,7 @@ struct sandbox_state {
        const char *select_unittests;   /* Unit test to run */
        bool handle_signals;            /* Handle signals within sandbox */
        bool autoboot_keyed;            /* Use keyed-autoboot feature */
+       bool disable_eth;               /* Disable Ethernet devices */
 
        /* Pointer to information for each SPI bus/cs */
        struct sandbox_spi_info spi[CONFIG_SANDBOX_SPI_MAX_BUS]
index 568738c16d51f7ed0bcca3fbb6266ab56e0ee8f3..1c522e38f3d66f6c1fe9fe276aef3f13beba47ba 100644 (file)
@@ -344,4 +344,20 @@ void sandbox_set_fake_efi_mgr_dev(struct udevice *dev, bool fake_dev);
  */
 int sandbox_load_other_fdt(void **fdtp, int *sizep);
 
+/**
+ * sandbox_set_eth_enable() - Enable / disable Ethernet
+ *
+ * Allows control of whether Ethernet packets are actually send/received
+ *
+ * @enable: true to enable Ethernet, false to disable
+ */
+void sandbox_set_eth_enable(bool enable);
+
+/**
+ * sandbox_eth_enabled() - Check if Ethernet is enabled
+ *
+ * Returns: true if Ethernet is enabled on sandbox, False if not
+ */
+bool sandbox_eth_enabled(void);
+
 #endif
index 4ad74614afcb386c9917893ed8d0c11f98dc96ba..76ec4d739a3ea734f17fe3633e0b51aedec457c4 100644 (file)
@@ -169,4 +169,29 @@ static inline int test_load_other_fdt(struct unit_test_state *uts)
        return ret;
 }
 
+/**
+ * test_set_eth_enable() - Enable / disable Ethernet
+ *
+ * Allows control of whether Ethernet packets are actually send/received
+ *
+ * @enable: true to enable Ethernet, false to disable
+ */
+static inline void test_set_eth_enable(bool enable)
+{
+#ifdef CONFIG_SANDBOX
+       sandbox_set_eth_enable(enable);
+#endif
+}
+
+/* Allow ethernet to be disabled for testing purposes */
+static inline bool test_eth_enabled(void)
+{
+       bool enabled = true;
+
+#ifdef CONFIG_SANDBOX
+       enabled = sandbox_eth_enabled();
+#endif
+       return enabled;
+}
+
 #endif /* __TEST_TEST_H */
index 57da9bda85af994b98254fab600b5cf0c1e40260..c9a749f6cc82b85fa4c3da514e68b9ced1fd344d 100644 (file)
--- a/net/net.c
+++ b/net/net.c
 #endif
 #include <watchdog.h>
 #include <linux/compiler.h>
+#include <test/test.h>
 #include "arp.h"
 #include "bootp.h"
 #include "cdp.h"
@@ -465,6 +466,9 @@ restart:
        debug_cond(DEBUG_INT_STATE, "--- net_loop Init\n");
        net_init_loop();
 
+       if (!test_eth_enabled())
+               return 0;
+
        switch (net_check_prereq(protocol)) {
        case 1:
                /* network not configured */