[U-Boot] [PATCH] at91_emac: fix compile warning

Reinhard Meyer u-boot at emk-elektronik.de
Thu Jun 9 13:08:34 CEST 2011


Dear Andreas Bießmann,
> This patch removes the warning
> 
> ---8<---
> at91_emac.c: In function 'at91emac_write_hwaddr':
> at91_emac.c:487:2: warning: dereferencing type-punned pointer will break strict-aliasing rules
> --->8---
> 
> Signed-off-by: Andreas Bießmann <andreas.devel at gmail.com>
> ---
> BEWARE! This patch is only compile tested!
> 
> It is possible, that there is an endianess problem. It would be great, if one
> could test it on real hardware!

If you have the time, can you make the same patch for macb? I can test it later on our
hardware.

> 
> Reinhard, you could adopt the macb driver also to get the warning there fixed.
> If it works on at91sam this way it would also work on at91rm9200 cause they have the
> same endianess.

See above ;)

> 
>  drivers/net/at91_emac.c |   12 +++++++-----
>  1 files changed, 7 insertions(+), 5 deletions(-)
> 
> diff --git a/drivers/net/at91_emac.c b/drivers/net/at91_emac.c
> index b09ff8c..97d2739 100644
> --- a/drivers/net/at91_emac.c
> +++ b/drivers/net/at91_emac.c
> @@ -481,11 +481,13 @@ static int at91emac_write_hwaddr(struct eth_device *netdev)
>  	dev = (emac_device *) netdev->priv;
>  
>  	writel(1 << ATMEL_ID_EMAC, &pmc->pcer);
> -	DEBUG_AT91EMAC("init MAC-ADDR %x%x \n",
> -		cpu_to_le16(*((u16 *)(netdev->enetaddr + 4))),
> -		cpu_to_le32(*((u32 *)netdev->enetaddr)));
> -	writel(cpu_to_le32(*((u32 *)netdev->enetaddr)), &emac->sa2l);
> -	writel(cpu_to_le16(*((u16 *)(netdev->enetaddr + 4))), &emac->sa2h);
> +	DEBUG_AT91EMAC("init MAC-ADDR %02x:%02x:%02x:%02x:%02x:%02x\n",
> +		netdev->enetaddr[5], netdev->enetaddr[4], netdev->enetaddr[3],
> +		netdev->enetaddr[2], netdev->enetaddr[1], netdev->enetaddr[0]);
> +	writel( (netdev->enetaddr[0] | netdev->enetaddr[1] << 8 |
> +			netdev->enetaddr[2] << 16 | netdev->enetaddr[3] << 24),
> +			&emac->sa2l);

OUCH, I would think by precedence rules, | comes before << !?!?!
Can you verify and supply a new patch if that holds true?

> +	writel((netdev->enetaddr[4] | netdev->enetaddr[5] << 8), &emac->sa2h);
>  	DEBUG_AT91EMAC("init MAC-ADDR %x%x \n",

If you touch the file next time, can you remove that space before the \n ?

>  		readl(&emac->sa2h), readl(&emac->sa2l));
>  	return 0;

Already applied to u-boot-atmel/master,
Thanks,
Reinhard


More information about the U-Boot mailing list