[U-Boot] [RFC PATCH v3 09/14] dm: eth: Add ARP and PING response to sandbox driver

Simon Glass sjg at chromium.org
Wed Feb 18 06:02:16 CET 2015


Hi Joe,

On 16 February 2015 at 21:46, Joe Hershberger <joe.hershberger at gmail.com> wrote:
>
>
> On Sun, Feb 15, 2015 at 9:49 AM, Simon Glass <sjg at chromium.org> wrote:
>>
>> Hi Joe,
>>
>> On 10 February 2015 at 18:30, Joe Hershberger <joe.hershberger at ni.com>
>> wrote:
>> > The sandbox driver will now generate response traffic to exercise the
>> > ping command even when no network exists.  This allows the basic data
>> > pathways of the DM to be tested.
>> >
>> > Signed-off-by: Joe Hershberger <joe.hershberger at ni.com>
>> > Reviewed-by: Simon Glass <sjg at chromium.org>
>> > ---
>> >
>> > Changes in v3:
>> > -Prevent a crash if memory is not allocated
>> >
>> > Changes in v2:
>> > -Change printfs to debug in sandbox driver
>> > -Move static data to priv
>> > -Move fake hwaddr to the device tree
>> >
>> >  arch/sandbox/dts/sandbox.dts |   1 +
>> >  drivers/net/sandbox.c        | 101
>> > +++++++++++++++++++++++++++++++++++++++++++
>> >  2 files changed, 102 insertions(+)
>> >
>> > diff --git a/arch/sandbox/dts/sandbox.dts b/arch/sandbox/dts/sandbox.dts
>> > index 502eb3d..ba635e8 100644
>> > --- a/arch/sandbox/dts/sandbox.dts
>> > +++ b/arch/sandbox/dts/sandbox.dts
>> > @@ -186,5 +186,6 @@
>> >         eth at 10002000 {
>> >                 compatible = "sandbox,eth";
>> >                 reg = <0x10002000 0x1000>;
>> > +               fake-host-hwaddr = <0x00 0x00 0x66 0x44 0x22 0x00>;
>> >         };
>> >  };
>> > diff --git a/drivers/net/sandbox.c b/drivers/net/sandbox.c
>> > index 2a2ad41..f9fa1a1 100644
>> > --- a/drivers/net/sandbox.c
>> > +++ b/drivers/net/sandbox.c
>> > @@ -15,22 +15,121 @@
>> >
>> >  DECLARE_GLOBAL_DATA_PTR;
>> >
>> > +struct eth_sandbox_priv {
>> > +       uchar fake_host_hwaddr[ARP_HLEN];
>> > +       IPaddr_t fake_host_ipaddr;
>> > +       uchar recv_packet_buffer[PKTSIZE];
>> > +       int recv_packet_length;
>> > +};
>> > +
>> >  static int sb_eth_init(struct udevice *dev, bd_t *bis)
>> >  {
>> >         debug("eth_sandbox: Init\n");
>> >
>> > +       struct eth_sandbox_priv *priv = dev->priv;
>> > +       u32 int_array[ARP_HLEN];
>> > +       int i;
>> > +
>> > +       if (!priv)
>> > +               return -EINVAL;
>>
>> How can this happen?
>
> If I recall this was happening when the probe failed due to being unable to
> find a MAC address.  This meant that the device was not active when the init
> was called on it.  I believe I later remedied it by checking that the
> DM_FLAG_ACTIVATED was set, so this check is probably not needed any longer.
>
> Is there a way in DM to iterate through only those devices that have been
> successfully probed or is it my responsibility to check activated before
> using any ops?

I normally check it in the uclass. The functions which return a device
-e.g. uclass_get_device...() normally probe the device before it is
returned. The idea is that it should be hard to obtain a 'struct
udevice' in non-core code (i.e. outside drivers/core) without it being
probed first.

But if you want to iterate across all devices and skip those that are
not probed you will need to do it yourself, or add helper functions.

[snip]

Regards,
Simon


More information about the U-Boot mailing list