[U-Boot] [PATCH]Fix checksum to handle odd-length packet

Joakim Tjernlund joakim.tjernlund at transmode.se
Thu Dec 3 13:28:27 CET 2009


> Dear "Greg Ren",
>
> In message <CB2DD11991B27C4F99935E6229450D3204E5CB91 at STORK.scenix.com> you wrote:
> >
> > I am new to u-boot and got assignment to debug some networking issue. I
> > traced the checksum failure and was able to fix it with the patch below.
>
> It would be important to know on which system(s) you have actually
> tested your patch - and on which you experienced any issues in the
> first place. Please mention CPU, board, and network driver used.
>
> > The patch is a git commit log from my local git reposite.
> >
> > Thanks for your time and advice.
> >
> > % git show cffd5fb03e0c3f116cce9f3ff825c5445a1eca3f
>
> Please use git-format-patch / git-send-email to submit patches, see
> http://www.denx.de/wiki/U-Boot/Patches for details.
>
>
> > @@ -1420,12 +1420,12 @@ NetReceive(volatile uchar * inpkt, int len)
> >                                 ip->ip_off = 0;
> >                                 NetCopyIP((void*)&ip->ip_dst,
> > &ip->ip_src);
> >                                 NetCopyIP((void*)&ip->ip_src,
> > &NetOurIP);
> > -                               ip->ip_sum = ~NetCksum((uchar *)ip,
> > IP_HDR_SIZE_NO_UDP >> 1);
> > +                               ip->ip_sum = ~NetCksum((uchar *)ip,
> > IP_HDR_SIZE_NO_UDP);
>
> Your mailer has line-wrapped the patch which makes it useless.
>
> > +       if (len == 1) {
> > +               xsum += (*p & 0xff00);
>
> I doubt that this code is endianess-clean.

Nope, I would think some thing like this would work better:
      count = len >> 1; /* div by 2 */
	for(p--; count; --count)
	  xsum += *++p;

	if (len & 1) /* Odd */
	  xsum += *(u_char *)(++p);   /* one byte only */




More information about the U-Boot mailing list