diff mbox series

[U-Boot,3/5] net: sandbox: Convert sandbox mock eth driver to livetree

Message ID 20180626211926.13172-4-joe.hershberger@ni.com
State Superseded
Delegated to: Joe Hershberger
Headers show
Series sandbox: net: Fix sandbox eth drivers | expand

Commit Message

Joe Hershberger June 26, 2018, 9:19 p.m. UTC
Use the dev_ functions to access DT properties.

Also correct the reading of the fake MAC address. The format from the DT
is u32s, so to accurately read the MAC from the DT, we need to cast each
value to a u8.

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

 drivers/net/sandbox.c | 15 +++++++++++----
 1 file changed, 11 insertions(+), 4 deletions(-)

Comments

Simon Glass June 26, 2018, 11:18 p.m. UTC | #1
Hi Joe,

On 26 June 2018 at 14:19, Joe Hershberger <joe.hershberger@ni.com> wrote:
> Use the dev_ functions to access DT properties.
>
> Also correct the reading of the fake MAC address. The format from the DT
> is u32s, so to accurately read the MAC from the DT, we need to cast each
> value to a u8.
>
> Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
> ---
>
>  drivers/net/sandbox.c | 15 +++++++++++----
>  1 file changed, 11 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/net/sandbox.c b/drivers/net/sandbox.c
> index b34712bd06..d5a30c05b8 100644
> --- a/drivers/net/sandbox.c
> +++ b/drivers/net/sandbox.c
> @@ -56,13 +56,20 @@ void sandbox_eth_skip_timeout(void)
>  static int sb_eth_start(struct udevice *dev)
>  {
>         struct eth_sandbox_priv *priv = dev_get_priv(dev);
> +       /* The DT integers are 32-bits */
> +       const u32 mac[ARP_HLEN];
>
>         debug("eth_sandbox: Start\n");
>
> -       fdtdec_get_byte_array(gd->fdt_blob, dev_of_offset(dev),
> -                             "fake-host-hwaddr", priv->fake_host_hwaddr,
> -                             ARP_HLEN);
> +       if (dev_read_u32_array(dev, "fake-host-hwaddr", mac, ARP_HLEN)) {
> +               printf("'fake-host-hwaddr' is missing from the DT\n");
> +               return -EINVAL;
> +       }

This is not equivalent  - I think you need a dev_read_u8_array() or similar.

> +       for (int i = 0; i < ARP_HLEN; i++)
> +               priv->fake_host_hwaddr[i] = (uint8_t)mac[i];
> +
>         priv->recv_packet_buffer = net_rx_packets[0];
> +
>         return 0;
>  }
>
> @@ -204,7 +211,7 @@ static int sb_eth_ofdata_to_platdata(struct udevice *dev)
>  {
>         struct eth_pdata *pdata = dev_get_platdata(dev);
>
> -       pdata->iobase = devfdt_get_addr(dev);
> +       pdata->iobase = dev_read_addr(dev);
>         return 0;
>  }
>
> --
> 2.11.0
>

Regards,
Simon
Joe Hershberger June 26, 2018, 11:25 p.m. UTC | #2
Hi Simon,

On Tue, Jun 26, 2018 at 6:18 PM, Simon Glass <sjg@chromium.org> wrote:
> Hi Joe,
>
> On 26 June 2018 at 14:19, Joe Hershberger <joe.hershberger@ni.com> wrote:
>> Use the dev_ functions to access DT properties.
>>
>> Also correct the reading of the fake MAC address. The format from the DT
>> is u32s, so to accurately read the MAC from the DT, we need to cast each
>> value to a u8.
>>
>> Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
>> ---
>>
>>  drivers/net/sandbox.c | 15 +++++++++++----
>>  1 file changed, 11 insertions(+), 4 deletions(-)
>>
>> diff --git a/drivers/net/sandbox.c b/drivers/net/sandbox.c
>> index b34712bd06..d5a30c05b8 100644
>> --- a/drivers/net/sandbox.c
>> +++ b/drivers/net/sandbox.c
>> @@ -56,13 +56,20 @@ void sandbox_eth_skip_timeout(void)
>>  static int sb_eth_start(struct udevice *dev)
>>  {
>>         struct eth_sandbox_priv *priv = dev_get_priv(dev);
>> +       /* The DT integers are 32-bits */
>> +       const u32 mac[ARP_HLEN];
>>
>>         debug("eth_sandbox: Start\n");
>>
>> -       fdtdec_get_byte_array(gd->fdt_blob, dev_of_offset(dev),
>> -                             "fake-host-hwaddr", priv->fake_host_hwaddr,
>> -                             ARP_HLEN);
>> +       if (dev_read_u32_array(dev, "fake-host-hwaddr", mac, ARP_HLEN)) {
>> +               printf("'fake-host-hwaddr' is missing from the DT\n");
>> +               return -EINVAL;
>> +       }
>
> This is not equivalent  - I think you need a dev_read_u8_array() or similar.

Yes, I know it's not equivalent... I noted that in the commit log.
This is fixing a bug too.

>
>> +       for (int i = 0; i < ARP_HLEN; i++)
>> +               priv->fake_host_hwaddr[i] = (uint8_t)mac[i];
>> +
>>         priv->recv_packet_buffer = net_rx_packets[0];
>> +
>>         return 0;
>>  }
>>
>> @@ -204,7 +211,7 @@ static int sb_eth_ofdata_to_platdata(struct udevice *dev)
>>  {
>>         struct eth_pdata *pdata = dev_get_platdata(dev);
>>
>> -       pdata->iobase = devfdt_get_addr(dev);
>> +       pdata->iobase = dev_read_addr(dev);
>>         return 0;
>>  }
>>
>> --
>> 2.11.0
>>
>
> Regards,
> Simon
> _______________________________________________
> U-Boot mailing list
> U-Boot@lists.denx.de
> https://lists.denx.de/listinfo/u-boot
Simon Glass June 26, 2018, 11:28 p.m. UTC | #3
Hi Joe,

On 26 June 2018 at 16:25, Joe Hershberger <joe.hershberger@ni.com> wrote:
> Hi Simon,
>
> On Tue, Jun 26, 2018 at 6:18 PM, Simon Glass <sjg@chromium.org> wrote:
>> Hi Joe,
>>
>> On 26 June 2018 at 14:19, Joe Hershberger <joe.hershberger@ni.com> wrote:
>>> Use the dev_ functions to access DT properties.
>>>
>>> Also correct the reading of the fake MAC address. The format from the DT
>>> is u32s, so to accurately read the MAC from the DT, we need to cast each
>>> value to a u8.
>>>
>>> Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
>>> ---
>>>
>>>  drivers/net/sandbox.c | 15 +++++++++++----
>>>  1 file changed, 11 insertions(+), 4 deletions(-)
>>>
>>> diff --git a/drivers/net/sandbox.c b/drivers/net/sandbox.c
>>> index b34712bd06..d5a30c05b8 100644
>>> --- a/drivers/net/sandbox.c
>>> +++ b/drivers/net/sandbox.c
>>> @@ -56,13 +56,20 @@ void sandbox_eth_skip_timeout(void)
>>>  static int sb_eth_start(struct udevice *dev)
>>>  {
>>>         struct eth_sandbox_priv *priv = dev_get_priv(dev);
>>> +       /* The DT integers are 32-bits */
>>> +       const u32 mac[ARP_HLEN];
>>>
>>>         debug("eth_sandbox: Start\n");
>>>
>>> -       fdtdec_get_byte_array(gd->fdt_blob, dev_of_offset(dev),
>>> -                             "fake-host-hwaddr", priv->fake_host_hwaddr,
>>> -                             ARP_HLEN);
>>> +       if (dev_read_u32_array(dev, "fake-host-hwaddr", mac, ARP_HLEN)) {
>>> +               printf("'fake-host-hwaddr' is missing from the DT\n");
>>> +               return -EINVAL;
>>> +       }
>>
>> This is not equivalent  - I think you need a dev_read_u8_array() or similar.
>
> Yes, I know it's not equivalent... I noted that in the commit log.
> This is fixing a bug too.

Yes I see that, but I didn't realise there was a bug in the code.

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

Regards,
Simon
Joe Hershberger June 27, 2018, 12:29 a.m. UTC | #4
On Tue, Jun 26, 2018 at 6:28 PM, Simon Glass <sjg@chromium.org> wrote:
> Hi Joe,
>
> On 26 June 2018 at 16:25, Joe Hershberger <joe.hershberger@ni.com> wrote:
>> Hi Simon,
>>
>> On Tue, Jun 26, 2018 at 6:18 PM, Simon Glass <sjg@chromium.org> wrote:
>>> Hi Joe,
>>>
>>> On 26 June 2018 at 14:19, Joe Hershberger <joe.hershberger@ni.com> wrote:
>>>> Use the dev_ functions to access DT properties.
>>>>
>>>> Also correct the reading of the fake MAC address. The format from the DT
>>>> is u32s, so to accurately read the MAC from the DT, we need to cast each
>>>> value to a u8.
>>>>
>>>> Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
>>>> ---
>>>>
>>>>  drivers/net/sandbox.c | 15 +++++++++++----
>>>>  1 file changed, 11 insertions(+), 4 deletions(-)
>>>>
>>>> diff --git a/drivers/net/sandbox.c b/drivers/net/sandbox.c
>>>> index b34712bd06..d5a30c05b8 100644
>>>> --- a/drivers/net/sandbox.c
>>>> +++ b/drivers/net/sandbox.c
>>>> @@ -56,13 +56,20 @@ void sandbox_eth_skip_timeout(void)
>>>>  static int sb_eth_start(struct udevice *dev)
>>>>  {
>>>>         struct eth_sandbox_priv *priv = dev_get_priv(dev);
>>>> +       /* The DT integers are 32-bits */
>>>> +       const u32 mac[ARP_HLEN];
>>>>
>>>>         debug("eth_sandbox: Start\n");
>>>>
>>>> -       fdtdec_get_byte_array(gd->fdt_blob, dev_of_offset(dev),
>>>> -                             "fake-host-hwaddr", priv->fake_host_hwaddr,
>>>> -                             ARP_HLEN);
>>>> +       if (dev_read_u32_array(dev, "fake-host-hwaddr", mac, ARP_HLEN)) {
>>>> +               printf("'fake-host-hwaddr' is missing from the DT\n");
>>>> +               return -EINVAL;
>>>> +       }
>>>
>>> This is not equivalent  - I think you need a dev_read_u8_array() or similar.
>>
>> Yes, I know it's not equivalent... I noted that in the commit log.
>> This is fixing a bug too.
>
> Yes I see that, but I didn't realise there was a bug in the code.

OK, turns out this is the result of an inconsistency in the dts files,
and should actually be able to be u8s.

I'll correct it for v2.

> Reviewed-by: Simon Glass <sjg@chromium.org>
>
> Regards,
> Simon
> _______________________________________________
> U-Boot mailing list
> U-Boot@lists.denx.de
> https://lists.denx.de/listinfo/u-boot
diff mbox series

Patch

diff --git a/drivers/net/sandbox.c b/drivers/net/sandbox.c
index b34712bd06..d5a30c05b8 100644
--- a/drivers/net/sandbox.c
+++ b/drivers/net/sandbox.c
@@ -56,13 +56,20 @@  void sandbox_eth_skip_timeout(void)
 static int sb_eth_start(struct udevice *dev)
 {
 	struct eth_sandbox_priv *priv = dev_get_priv(dev);
+	/* The DT integers are 32-bits */
+	const u32 mac[ARP_HLEN];
 
 	debug("eth_sandbox: Start\n");
 
-	fdtdec_get_byte_array(gd->fdt_blob, dev_of_offset(dev),
-			      "fake-host-hwaddr", priv->fake_host_hwaddr,
-			      ARP_HLEN);
+	if (dev_read_u32_array(dev, "fake-host-hwaddr", mac, ARP_HLEN)) {
+		printf("'fake-host-hwaddr' is missing from the DT\n");
+		return -EINVAL;
+	}
+	for (int i = 0; i < ARP_HLEN; i++)
+		priv->fake_host_hwaddr[i] = (uint8_t)mac[i];
+
 	priv->recv_packet_buffer = net_rx_packets[0];
+
 	return 0;
 }
 
@@ -204,7 +211,7 @@  static int sb_eth_ofdata_to_platdata(struct udevice *dev)
 {
 	struct eth_pdata *pdata = dev_get_platdata(dev);
 
-	pdata->iobase = devfdt_get_addr(dev);
+	pdata->iobase = dev_read_addr(dev);
 	return 0;
 }