LWIP buffer alignment

Tim Harvey tharvey at gateworks.com
Mon Sep 8 18:44:15 CEST 2025


On Mon, Sep 8, 2025 at 7:21 AM Jerome Forissier
<jerome.forissier at linaro.org> wrote:
>
> Hi Tim,
>
> On 9/5/25 19:45, Tim Harvey wrote:
> > Hi Jerome,
> >
> > I'm working with a board that has an IMX ENETC MAC on it
> > drivers/net/fsl_enetc.c and when configured for LWIP it fails and
> > warns about RX buffers not being 64B aligned:
> > WARNING at drivers/net/fsl_enetc.c:776/enetc_setup_rx_bdr()!
> >
> > I tried changing MEM_ALIGNMENT to 64 in lib/lwip/u-boot/lwipopts.h but
> > that did not align the buffers to 64B. Where are the lwip buffers
> > created and do you have any suggestions for working around this?
>
> The LwIP RX buffers are created in net-lwip.c. See eth_init_rings().
> You might have PKTSIZE_ALIGN and/or PKTALIGN set wrongly.
>

Hi Jerome,

Thanks for pointing me to eth_init_rings(). This function uses
net_pkt_buf as the base for the net_rx_packets array which is a static
global and not aligned.

Looks like we need:
diff --git a/net/lwip/net-lwip.c b/net/lwip/net-lwip.c
index 660ceb10cbe..aec05d55de6 100644
--- a/net/lwip/net-lwip.c
+++ b/net/lwip/net-lwip.c
@@ -30,7 +30,7 @@ void (*push_packet)(void *, int len) = 0;
 static int net_try_count;
 static int net_restarted;
 int net_restart_wrap;
-static uchar net_pkt_buf[(PKTBUFSRX) * PKTSIZE_ALIGN + PKTALIGN];
+static uchar net_pkt_buf[(PKTBUFSRX) * PKTSIZE_ALIGN + PKTALIGN]
__attribute__((aligned(PKTALIGN)));
 uchar *net_rx_packets[PKTBUFSRX];
 uchar *net_rx_packet;
 const u8 net_bcast_ethaddr[6] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };

If you agree I'll submit that. This does resolve the issue I see with
the enetc driver using LwIP.

Best Regards,

Tim


More information about the U-Boot mailing list