[U-Boot] Warning NetReceive(): Make sure packet buffers start on an even address

Hi,
The network layer currently handles packets with c-structures overlayd on the packets.
NetReceive() will fail to correctly parse packets that are not word aligned (at least on ARM cpus).
Just figured that out debugging the enc28j60 driver. Which had no fault except for having the receive packet buffer on an odd address :)
Instead of: static unsigned char buffer[ENC_MAX_FRM_LEN]; The following works fine: static unsigned long lbuffer[ENC_MAX_FRM_LEN/4]; #define buffer ((unsigned char *)lbuffer)
Is there a more elegant way of forcing a char array to start on an even address?
Reinhard

Dear "Reinhard Meyer (-VC)",
In message 4C5BE2CF.2020306@emk-elektronik.de you wrote:
Instead of: static unsigned char buffer[ENC_MAX_FRM_LEN]; The following works fine: static unsigned long lbuffer[ENC_MAX_FRM_LEN/4]; #define buffer ((unsigned char *)lbuffer)
Is there a more elegant way of forcing a char array to start on an even address?
Sure. Use something like
static unsigned char buffer[ENC_MAX_FRM_LEN] __attribute__ ((aligned(4)));
Or, probably even better, use malloc() to allocate the buffer.
Best regards,
Wolfgang Denk

Wolfgang Denk schrieb:
static unsigned char buffer[ENC_MAX_FRM_LEN] __attribute__ ((aligned(4)));
Thanks, sometimes the very obvious is hidden behind a large wooden board :)
Or, probably even better, use malloc() to allocate the buffer.
For each received packet? Could do that, but its not worth it. Received packets are queued in the 6K RAM of the enc28j60. I'll see if the enc can be made to ignore broadcast packets, otherwise it might get tough either way on a busy Windows network .....
Or are you aware of any need to hand over broadcast packets into NetReceive() ?
Reinhard

-----Original Message----- From: Reinhard Meyer (-VC) reinhard.meyer@emk-elektronik.de Reply-to: reinhard.meyer@emk-elektronik.de To: Wolfgang Denk wd@denx.de Cc: u-boot u-boot@lists.denx.de Subject: Re: [U-Boot] Warning NetReceive(): Make sure packet buffers start on an even address Date: Fri, 06 Aug 2010 12:38:58 +0200
Wolfgang Denk schrieb:
static unsigned char buffer[ENC_MAX_FRM_LEN] __attribute__ ((aligned(4)));
Thanks, sometimes the very obvious is hidden behind a large wooden board :)
Or, probably even better, use malloc() to allocate the buffer.
For each received packet? Could do that, but its not worth it. Received packets are queued in the 6K RAM of the enc28j60. I'll see if the enc can be made to ignore broadcast packets, otherwise it might get tough either way on a busy Windows network .....
Or are you aware of any need to hand over broadcast packets into NetReceive() ?
I am stepping into the middle of this, so the following may be totally misguided...
BOOTP/DHCP servers can send broadcast packets. I have just tried this with a Windows DHCP server the the DHCP response was broadcast.

Chris Isbell schrieb:
Or are you aware of any need to hand over broadcast packets into NetReceive() ?
I am stepping into the middle of this, so the following may be totally misguided...
BOOTP/DHCP servers can send broadcast packets. I have just tried this with a Windows DHCP server the the DHCP response was broadcast.
Thanks for the info!
That sounds like typical Windows (%&@#*)....
Duly noted, broadcast reception is configurable by #define now.
Best Regards Reinhard

Dear "Reinhard Meyer (-VC)",
In message 4C5BE642.4020706@emk-elektronik.de you wrote:
Wolfgang Denk schrieb:
static unsigned char buffer[ENC_MAX_FRM_LEN] __attribute__ ((aligned(4)));
Thanks, sometimes the very obvious is hidden behind a large wooden board :)
Or, probably even better, use malloc() to allocate the buffer.
For each received packet? Could do that, but its not worth it.
Not for each packet, only for the first one, of course, or when initializing the driver.
Best regards,
Wolfgang Denk

Wolfgang Denk schrieb:
Dear "Reinhard Meyer (-VC)",
In message 4C5BE642.4020706@emk-elektronik.de you wrote:
Wolfgang Denk schrieb:
static unsigned char buffer[ENC_MAX_FRM_LEN] __attribute__ ((aligned(4)));
Thanks, sometimes the very obvious is hidden behind a large wooden board :)
Or, probably even better, use malloc() to allocate the buffer.
For each received packet? Could do that, but its not worth it.
Not for each packet, only for the first one, of course, or when initializing the driver.
Whats the benefit except for probably increased code size?
The only one I see is 1.5k more free RAM as long as the driver is not initialized/used...
Best Regards Reinhard

Dear Reinhard Meyer,
In message 4C5C2A03.3070005@emk-elektronik.de you wrote:
Whats the benefit except for probably increased code size?
The only one I see is 1.5k more free RAM as long as the driver is not initialized/used...
Well, that is a benefit, isn't it? And it should have no negative side-effects either, so why not make use of it?
Best regards,
Wolfgang Denk
participants (4)
-
Chris Isbell
-
Reinhard Meyer
-
Reinhard Meyer (-VC)
-
Wolfgang Denk