diff mbox

[U-Boot,RFC,v2,6/8] net: Add network support to sandbox

Message ID 1422923925-5572-7-git-send-email-joe.hershberger@ni.com
State Superseded
Headers show

Commit Message

Joe Hershberger Feb. 3, 2015, 12:38 a.m. UTC
Add basic network support to sandbox which includes a network driver.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

---

Changes in v2:
-Change printfs to debug in sandbox driver
-Remove unused priv struct for sandbox driver

 arch/sandbox/dts/sandbox.dts |  4 +++
 drivers/net/Makefile         |  2 ++
 drivers/net/sandbox.c        | 86 ++++++++++++++++++++++++++++++++++++++++++++
 include/configs/sandbox.h    | 14 +++++---
 4 files changed, 101 insertions(+), 5 deletions(-)
 create mode 100644 drivers/net/sandbox.c

Comments

Simon Glass Feb. 7, 2015, 1:25 a.m. UTC | #1
On 2 February 2015 at 17:38, Joe Hershberger <joe.hershberger@ni.com> wrote:
> Add basic network support to sandbox which includes a network driver.
>
> Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
>
> ---
>
> Changes in v2:
> -Change printfs to debug in sandbox driver
> -Remove unused priv struct for sandbox driver
>
>  arch/sandbox/dts/sandbox.dts |  4 +++
>  drivers/net/Makefile         |  2 ++
>  drivers/net/sandbox.c        | 86 ++++++++++++++++++++++++++++++++++++++++++++
>  include/configs/sandbox.h    | 14 +++++---
>  4 files changed, 101 insertions(+), 5 deletions(-)
>  create mode 100644 drivers/net/sandbox.c

Reviewed-by: Simon Glass <sjg@chromium.org>
diff mbox

Patch

diff --git a/arch/sandbox/dts/sandbox.dts b/arch/sandbox/dts/sandbox.dts
index 4c63e4f..502eb3d 100644
--- a/arch/sandbox/dts/sandbox.dts
+++ b/arch/sandbox/dts/sandbox.dts
@@ -183,4 +183,8 @@ 
 		};
 	};
 
+	eth@10002000 {
+		compatible = "sandbox,eth";
+		reg = <0x10002000 0x1000>;
+	};
 };
diff --git a/drivers/net/Makefile b/drivers/net/Makefile
index 46c4ac6..2659a8a 100644
--- a/drivers/net/Makefile
+++ b/drivers/net/Makefile
@@ -50,6 +50,8 @@  obj-$(CONFIG_NS8382X) += ns8382x.o
 obj-$(CONFIG_PCNET) += pcnet.o
 obj-$(CONFIG_RTL8139) += rtl8139.o
 obj-$(CONFIG_RTL8169) += rtl8169.o
+obj-$(CONFIG_ETH_SANDBOX) += sandbox.o
+obj-$(CONFIG_ETH_SANDBOX_RAW) += sandbox-raw.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
index 0000000..3b7c3ac
--- /dev/null
+++ b/drivers/net/sandbox.c
@@ -0,0 +1,86 @@ 
+/*
+ * 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 <fdtdec.h>
+#include <malloc.h>
+#include <net.h>
+
+DECLARE_GLOBAL_DATA_PTR;
+
+int sb_eth_init(struct udevice *dev, bd_t *bis)
+{
+	debug("eth_sandbox: Init\n");
+
+	return 0;
+}
+
+int sb_eth_send(struct udevice *dev, void *packet, int length)
+{
+	debug("eth_sandbox: Send packet %d\n", length);
+
+	return 0;
+#endif
+}
+
+int sb_eth_recv(struct udevice *dev)
+{
+	return 0;
+}
+
+void sb_eth_halt(struct udevice *dev)
+{
+	debug("eth_sandbox: Halt\n");
+}
+
+int sb_eth_write_hwaddr(struct udevice *dev)
+{
+	debug("eth_sandbox: Write HW ADDR\n");
+	return 0;
+}
+
+static const struct eth_ops eth_sandbox_ops = {
+	.init			= sb_eth_init,
+	.send			= sb_eth_send,
+	.recv			= sb_eth_recv,
+	.halt			= sb_eth_halt,
+	.write_hwaddr		= sb_eth_write_hwaddr,
+};
+
+static int eth_sandbox_remove(struct udevice *dev)
+{
+	return 0;
+}
+
+#ifdef CONFIG_OF_CONTROL
+static int sandbox_eth_ofdata_to_platdata(struct udevice *dev)
+{
+	struct eth_pdata *pdata = dev->platdata;
+
+	pdata->iobase = fdtdec_get_addr(gd->fdt_blob, dev->of_offset, "reg");
+	return 0;
+}
+
+static const struct udevice_id sandbox_eth_ids[] = {
+	{ .compatible = "sandbox,eth" },
+	{ }
+};
+#endif
+
+U_BOOT_DRIVER(eth_sandbox) = {
+	.name	= "eth_sandbox",
+	.id	= UCLASS_ETH,
+	.of_match = of_match_ptr(sandbox_eth_ids),
+	.ofdata_to_platdata = of_match_ptr(sandbox_eth_ofdata_to_platdata),
+	.remove	= eth_sandbox_remove,
+	.ops	= &eth_sandbox_ops,
+	.priv_auto_alloc_size = sizeof(struct eth_sandbox_priv),
+	.platdata_auto_alloc_size = sizeof(struct eth_pdata),
+};
diff --git a/include/configs/sandbox.h b/include/configs/sandbox.h
index e9d3f32..484caa8 100644
--- a/include/configs/sandbox.h
+++ b/include/configs/sandbox.h
@@ -139,9 +139,9 @@ 
 /* 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_DM_ETH
+#define CONFIG_ETH_SANDBOX
+#define CONFIG_CMD_PING
 
 #define CONFIG_CMD_HASH
 #define CONFIG_HASH_VERIFY
@@ -184,12 +184,16 @@ 
 
 #define CONFIG_EXTRA_ENV_SETTINGS	"stdin=serial,cros-ec-keyb\0" \
 					"stdout=serial,lcd\0" \
-					"stderr=serial,lcd\0"
+					"stderr=serial,lcd\0" \
+					"ethaddr=00:00:11:22:33:44\0" \
+					"ipaddr=1.2.3.4\0"
 #else
 
 #define CONFIG_EXTRA_ENV_SETTINGS	"stdin=serial\0" \
 					"stdout=serial,lcd\0" \
-					"stderr=serial,lcd\0"
+					"stderr=serial,lcd\0" \
+					"ethaddr=00:00:11:22:33:44\0" \
+					"ipaddr=1.2.3.4\0"
 #endif
 
 #define CONFIG_GZIP_COMPRESSED