[U-Boot] [RFC PATCH v3 08/14] dm: eth: Add network support to sandbox

Simon Glass sjg at chromium.org
Sun Feb 15 16:49:51 CET 2015


Hi Joe,

On 10 February 2015 at 18:30, Joe Hershberger <joe.hershberger at ni.com> wrote:
> Add basic network support to sandbox which includes a network driver.
>
> Signed-off-by: Joe Hershberger <joe.hershberger at ni.com>
> Reviewed-by: Simon Glass <sjg at chromium.org>
>
> ---
>
> Changes in v3:
> -Added 2 more ethaddr to sandbox
> -Print which device in the debug write hwaddr
>
> 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         |  1 +
>  drivers/net/sandbox.c        | 86 ++++++++++++++++++++++++++++++++++++++++++++
>  include/configs/sandbox.h    | 18 +++++++---
>  4 files changed, 104 insertions(+), 5 deletions(-)
>  create mode 100644 drivers/net/sandbox.c
>
> 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 at 10002000 {
> +               compatible = "sandbox,eth";
> +               reg = <0x10002000 0x1000>;
> +       };
>  };
> diff --git a/drivers/net/Makefile b/drivers/net/Makefile
> index 46c4ac6..15dc431 100644
> --- a/drivers/net/Makefile
> +++ b/drivers/net/Makefile
> @@ -50,6 +50,7 @@ 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_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..2a2ad41
> --- /dev/null
> +++ b/drivers/net/sandbox.c
> @@ -0,0 +1,86 @@
> +/*
> + * Copyright (c) 2015 National Instruments
> + *
> + * (C) Copyright 2015
> + * Joe Hershberger <joe.hershberger at 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;
> +
> +static int sb_eth_init(struct udevice *dev, bd_t *bis)
> +{
> +       debug("eth_sandbox: Init\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)
> +{
> +       return 0;
> +}
> +
> +static void sb_eth_halt(struct udevice *dev)
> +{
> +       debug("eth_sandbox: Halt\n");
> +}
> +
> +static int sb_eth_write_hwaddr(struct udevice *dev)
> +{
> +       struct eth_pdata *pdata = dev->platdata;
> +       debug("eth_sandbox %s: Write HW ADDR - %pM\n", dev->name,
> +             pdata->enetaddr);
> +       return 0;
> +}
> +
> +static const struct eth_ops sb_eth_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 sb_eth_remove(struct udevice *dev)
> +{
> +       return 0;
> +}
> +
> +#ifdef CONFIG_OF_CONTROL
> +static int sb_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 sb_eth_ids[] = {
> +       { .compatible = "sandbox,eth" },
> +       { }
> +};
> +#endif
> +
> +U_BOOT_DRIVER(eth_sandbox) = {
> +       .name   = "eth_sandbox",
> +       .id     = UCLASS_ETH,
> +       .of_match = of_match_ptr(sb_eth_ids),
> +       .ofdata_to_platdata = of_match_ptr(sb_eth_ofdata_to_platdata),
> +       .remove = sb_eth_remove,
> +       .ops    = &sb_eth_ops,
> +       .platdata_auto_alloc_size = sizeof(struct eth_pdata),
> +};
> diff --git a/include/configs/sandbox.h b/include/configs/sandbox.h
> index e9d3f32..fdba1c8 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,20 @@
>
>  #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" \
> +                                       "eth1addr=00:00:11:22:33:45\0" \
> +                                       "eth2addr=00:00:11:22:33:46\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" \
> +                                       "eth1addr=00:00:11:22:33:45\0" \
> +                                       "eth2addr=00:00:11:22:33:46\0" \
> +                                       "ipaddr=1.2.3.4\0"
>  #endif

This needs tidying up, something like:

#define SANDBOX_DEVICE_SETTINGS "stdin...stderr"
#define SANDBOX_NET_SETTINGS "your ones"

#define CONFIG_EXTRA_ENV_SETTINGS SANDBOX_DEVICE_SETTINGS SANDBOX_NET_SETTINGS

>
>  #define CONFIG_GZIP_COMPRESSED
> --
> 1.7.11.5
>

Regards,
Simon


More information about the U-Boot mailing list