]> git.dujemihanovic.xyz Git - u-boot.git/commitdiff
sandbox: eth: Add network support to sandbox
authorJoe Hershberger <joe.hershberger@ni.com>
Sun, 22 Mar 2015 22:09:13 +0000 (17:09 -0500)
committerSimon Glass <sjg@chromium.org>
Sat, 18 Apr 2015 17:11:12 +0000 (11:11 -0600)
Add basic network support to sandbox which includes a network driver.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
arch/sandbox/Kconfig
arch/sandbox/dts/sandbox.dts
board/sandbox/README.sandbox
drivers/net/Kconfig
drivers/net/Makefile
drivers/net/sandbox.c [new file with mode: 0644]
include/configs/sandbox.h

index 477a20a820c5cbcf990b8b10da37843568970251..e7f55fa82a5cedff7cf1019447445556a3d7848d 100644 (file)
@@ -41,4 +41,13 @@ config PCI
          used on some devices to allow the CPU to communicate with its
          peripherals.
 
+config NET
+       default y
+
+config NETDEVICES
+       default y
+
+config DM_ETH
+       default y
+
 endmenu
index 42a1f21e121f5f1a7ec8e918d4cbb497a2e3868f..0df7b40bebd3b1167c6a4879bae7760171038029 100644 (file)
                };
        };
 
+       eth@10002000 {
+               compatible = "sandbox,eth";
+               reg = <0x10002000 0x1000>;
+       };
 };
index 3c0df1784553a85222660061c5b570c40823684a..c1f5f7e21fadef55a6a9be49573b98bbe6438072 100644 (file)
@@ -173,16 +173,16 @@ U-Boot sandbox supports these emulations:
 - Chrome OS EC
 - GPIO
 - Host filesystem (access files on the host from within U-Boot)
+- I2C
 - Keyboard (Chrome OS)
 - LCD
+- Network
 - Serial (for console only)
 - Sound (incomplete - see sandbox_sdl_sound_init() for details)
 - SPI
 - SPI flash
 - TPM (Trusted Platform Module)
 
-Notable omissions are networking and I2C.
-
 A wide range of commands is implemented. Filesystems which use a block
 device are supported.
 
index 94cf099a677ac1468a441a4b5d8960d17aecb579..e46e57bc2eccbf93f7bf2ea14eda021717c65172 100644 (file)
@@ -7,3 +7,26 @@ config DM_ETH
          The eth_*() interface will be implemented by the UC_ETH class
          This is currently implemented in net/eth.c
          Look in include/net.h for details.
+
+menuconfig NETDEVICES
+       bool "Network device support"
+       depends on NET
+       help
+         You must select Y to enable any network device support
+         Generally if you have any networking support this is a given
+
+         If unsure, say Y
+
+if NETDEVICES
+
+config ETH_SANDBOX
+       depends on DM_ETH && SANDBOX
+       default y
+       bool "Sandbox: Mocked Ethernet driver"
+       help
+         This driver simply responds with fake ARP replies and ping
+         replies that are used to verify network stack functionality
+
+         This driver is particularly useful in the test/dm/eth.c tests
+
+endif # NETDEVICES
index 5a5269aa06d06cc64085654d6dafbb21e0ddaa6f..b9f5db30bb411568fd86e5497b2fb32617f89d77 100644 (file)
@@ -51,6 +51,7 @@ obj-$(CONFIG_PCH_GBE) += pch_gbe.o
 obj-$(CONFIG_PCNET) += pcnet.o
 obj-$(CONFIG_RTL8139) += rtl8139.o
 obj-$(CONFIG_RTL8169) += rtl8169.o
+obj-$(CONFIG_ETH_SANDBOX) += sandbox.o
 obj-$(CONFIG_SH_ETHER) += sh_eth.o
 obj-$(CONFIG_SMC91111) += smc91111.o
 obj-$(CONFIG_SMC911X) += smc911x.o
diff --git a/drivers/net/sandbox.c b/drivers/net/sandbox.c
new file mode 100644 (file)
index 0000000..522990d
--- /dev/null
@@ -0,0 +1,84 @@
+/*
+ * Copyright (c) 2015 National Instruments
+ *
+ * (C) Copyright 2015
+ * Joe Hershberger <joe.hershberger@ni.com>
+ *
+ * SPDX-License-Identifier:    GPL-2.0
+ */
+
+#include <common.h>
+#include <dm.h>
+#include <malloc.h>
+#include <net.h>
+
+DECLARE_GLOBAL_DATA_PTR;
+
+static int sb_eth_start(struct udevice *dev)
+{
+       debug("eth_sandbox: Start\n");
+
+       return 0;
+}
+
+static int sb_eth_send(struct udevice *dev, void *packet, int length)
+{
+       debug("eth_sandbox: Send packet %d\n", length);
+
+       return 0;
+}
+
+static int sb_eth_recv(struct udevice *dev, uchar **packetp)
+{
+       return 0;
+}
+
+static void sb_eth_stop(struct udevice *dev)
+{
+       debug("eth_sandbox: Stop\n");
+}
+
+static int sb_eth_write_hwaddr(struct udevice *dev)
+{
+       struct eth_pdata *pdata = dev_get_platdata(dev);
+
+       debug("eth_sandbox %s: Write HW ADDR - %pM\n", dev->name,
+             pdata->enetaddr);
+       return 0;
+}
+
+static const struct eth_ops sb_eth_ops = {
+       .start                  = sb_eth_start,
+       .send                   = sb_eth_send,
+       .recv                   = sb_eth_recv,
+       .stop                   = sb_eth_stop,
+       .write_hwaddr           = sb_eth_write_hwaddr,
+};
+
+static int sb_eth_remove(struct udevice *dev)
+{
+       return 0;
+}
+
+static int sb_eth_ofdata_to_platdata(struct udevice *dev)
+{
+       struct eth_pdata *pdata = dev_get_platdata(dev);
+
+       pdata->iobase = dev_get_addr(dev);
+       return 0;
+}
+
+static const struct udevice_id sb_eth_ids[] = {
+       { .compatible = "sandbox,eth" },
+       { }
+};
+
+U_BOOT_DRIVER(eth_sandbox) = {
+       .name   = "eth_sandbox",
+       .id     = UCLASS_ETH,
+       .of_match = sb_eth_ids,
+       .ofdata_to_platdata = sb_eth_ofdata_to_platdata,
+       .remove = sb_eth_remove,
+       .ops    = &sb_eth_ops,
+       .platdata_auto_alloc_size = sizeof(struct eth_pdata),
+};
index c12c53896a4053bf80495dfff920cbfaa72ae5a1..01c6f19bd9b2507e771d1f9b29a89a833261ba85 100644 (file)
 /* include default commands */
 #include <config_cmd_default.h>
 
-/* We don't have networking support yet */
-#undef CONFIG_CMD_NET
-#undef CONFIG_CMD_NFS
 
 #define CONFIG_CMD_HASH
 #define CONFIG_HASH_VERIFY
 
 #define CONFIG_KEYBOARD
 
-#define CONFIG_EXTRA_ENV_SETTINGS      "stdin=serial,cros-ec-keyb\0" \
+#define SANDBOX_SERIAL_SETTINGS                "stdin=serial,cros-ec-keyb\0" \
                                        "stdout=serial,lcd\0" \
                                        "stderr=serial,lcd\0"
 #else
-
-#define CONFIG_EXTRA_ENV_SETTINGS      "stdin=serial\0" \
+#define SANDBOX_SERIAL_SETTINGS                "stdin=serial\0" \
                                        "stdout=serial,lcd\0" \
                                        "stderr=serial,lcd\0"
 #endif
 
+#define SANDBOX_ETH_SETTINGS           "ethaddr=00:00:11:22:33:44\0" \
+                                       "eth1addr=00:00:11:22:33:45\0" \
+                                       "eth2addr=00:00:11:22:33:46\0" \
+                                       "ipaddr=1.2.3.4\0"
+
+#define CONFIG_EXTRA_ENV_SETTINGS      SANDBOX_SERIAL_SETTINGS \
+                                       SANDBOX_ETH_SETTINGS
+
 #define CONFIG_GZIP_COMPRESSED
 #define CONFIG_BZIP2
 #define CONFIG_LZO