[BPI-R64] uboot

that’s bad

objdump indeed different project (binutils), but it have to work, even on modern binaries.

ok, give me u-boot file

FreeBSD always helps :)))))

it’s uploaded in gdrive-link above

look like it is net_set_ip_header, seems due not aligned access

r0 : 7efd874e & 0x3 = 0x2 - must be 0, or it have to be accesses with mem ops with w or b suffix

do tftp crashes too?

Using mtk_eth device
TFTP from server 192.168.0.10; our IP address is 192.168.0.18
Filename 'u-boot-mtk_r64_sd_rtl8367_gcc8.3.bin'.
Load address: 0x41dffe00
Loading: data abort
pc : [<7ef5f6b4>]          lr : [<7ef5f760>]
sp : 7cf29af8  ip : 00000033     fp : 00000045
r10: 00000dd7  r9 : 7cf29f40     r8 : 7efd8740
r7 : 00000dd7  r6 : 00000045     r5 : 00000044  r4 : 7efd874e
r3 : 14000045  r2 : 1200a8c0     r1 : 0a00a8c0  r0 : 7efd874e
Flags: nZCv  IRQs off  FIQs off  Mode SVC_32
Resetting CPU ...

yes

how did you get this output? if it is in net_set_ip_header it should affect also the other switch

can i somehow force aligned access? function itself looks not wrong

./net/net.c
1380 void net_set_ip_header(uchar *pkt, IPaddr_t dest, IPaddr_t source)
1381 {
1382         struct ip_udp_hdr *ip = (struct ip_udp_hdr *)pkt;
1383
1384         /*
1385          *      Construct an IP header.
1386          */
1387         /* IP_HDR_SIZE / 4 (not including UDP) */
1388         ip->ip_hl_v  = 0x45;
1389         ip->ip_tos   = 0;
1390         ip->ip_len   = htons(IP_HDR_SIZE);
1391         ip->ip_id    = htons(NetIPID++);
1392         ip->ip_off   = htons(IP_FLAGS_DFRAG);   /* Don't fragment */
1393         ip->ip_ttl   = 255;
1394         ip->ip_sum   = 0;
1395         /* already in network byte order */
1396         NetCopyIP((void *)&ip->ip_src, &source);
1397         /* already in network byte order */
1398         NetCopyIP((void *)&ip->ip_dst, &dest);
1399 }

i guess crash happens in the last 4 lines (=2 without comments)

try to add that line at beginning of net_set_ip_header

printf(“pkt=%p\n”, pkt);

I think it will be

7efd874e

or a bit moved by added code with printf

rtk_switch_init ret = 0!!!!!!!!!!!!
Set RTL8367S SGMII 2.5Gbps
 0x1b000014 = 0x00110214
Using mtk_eth device
pkt=7efd878e
data abort

disable optimization? -O0 in Makefile KBUILD_FLAGS?

rtk_switch_init ret = 0!!!!!!!!!!!!
Set RTL8367S SGMII 2.5Gbps
 0x1b000014 = 0x00110214
Using mtk_eth device
pkt=7efd89ce
ping failed; host 192.168.0.10 is not alive
BPI-R64> 

address also not aligned and ping not possible, but also no crash/reset, and not that fast as with -Os…sometimes it hangs a bit

second ping goes through

BPI-R64> ping 192.168.0.10
Using mtk_eth device
pkt=7efd89ce
host 192.168.0.10 is alive
BPI-R64> 

seems switch takes some time for setup…too long for first ping

uboot-binary is ~200kb larger, at least it is proofed, that optimization brings this problem, not alignment

https://gcc.gnu.org/onlinedocs/gcc/Optimize-Options.html

-Os (previous value)

Optimize for size. -Os enables all -O2 optimizations except those that often increase code size:

-falign-functions  -falign-jumps 
-falign-labels  -falign-loops 
-fprefetch-loop-arrays  -freorder-blocks-algorithm=stc

It also enables -finline-functions, causes the compiler to tune for code size rather than execution speed, and performs further optimizations designed to reduce code size. 

-O2:

-falign-functions  -falign-jumps 
-falign-labels  -falign-loops 
-fcaller-saves 
-fcode-hoisting 
-fcrossjumping 
-fcse-follow-jumps  -fcse-skip-blocks 
-fdelete-null-pointer-checks 
-fdevirtualize  -fdevirtualize-speculatively 
-fexpensive-optimizations 
-ffinite-loops 
-fgcse  -fgcse-lm  
-fhoist-adjacent-loads 
-finline-small-functions 
-findirect-inlining 
-fipa-bit-cp  -fipa-cp  -fipa-icf 
-fipa-ra  -fipa-sra  -fipa-vrp 
-fisolate-erroneous-paths-dereference 
-flra-remat 
-foptimize-sibling-calls 
-foptimize-strlen 
-fpartial-inlining 
-fpeephole2 
-freorder-blocks-algorithm=stc 
-freorder-blocks-and-partition  -freorder-functions 
-frerun-cse-after-loop  
-fschedule-insns  -fschedule-insns2 
-fsched-interblock  -fsched-spec 
-fstore-merging 
-fstrict-aliasing 
-fthread-jumps 
-ftree-builtin-call-dce 
-ftree-pre 
-ftree-switch-conversion  -ftree-tail-merge 
-ftree-vrp

is there any option i should disable? when using -Os

except
-falign-functions  -falign-jumps 
-falign-labels  -falign-loops 

sounds wrong in this context

mhm, O2 also crashes ;( O1 does not crash

1 Like

https://lists.denx.de/pipermail/u-boot/2017-July/297998.html

Conclusion:

This bug can be fixed by either:

  1) Always ensure proper alignment of the udp packet header
     pointers, which are passed to the net_set_ip_header() function
     and similar functions. Some further investigation is necessary.

or

  2) Just add a "packed" attribute to the ip_udp_hdr struct. In this
     case the compiler will always assume the smallest 1 byte alignment.
     It may have some performance implications though.

Yeah, usually we are transferring gigabytes of traffic with U-Boot and in most cases U-Boot’s network performance close to line speed :)))))))))))

Of course just select 2nd

I try it next week,i’m currently away from home and my repo has -O1 as workaround :smiley:

tried to change this like this way, but same result (crash)

--- a/include/net.h
+++ b/include/net.h
@@ -273,7 +273,7 @@ struct ip_hdr {
 /*
  *     Internet Protocol (IP) + UDP header.
  */
-struct ip_udp_hdr {
+struct __attribute__((__packed__)) ip_udp_hdr {
        uchar           ip_hl_v;        /* header length and version    */
        uchar           ip_tos;         /* type of service              */
        ushort          ip_len;         /* total length                 */

i have also set -mno-unaligned-access in KBUILD_FLAGS (where i had changed the optimization), same result

-O1 works, but -O2/-Os doesn’t, can’t we just disable one or more options from O2 to have best optimization without crash? which may cause the crash?

edit: nailed it down to this: -fstore-merging

i got no crash if using

KBUILD_CFLAGS += -Os -fno-store-merging

good catch https://lists.denx.de/pipermail/u-boot/2017-July/300392.html

But it seems still unfixed in upstream…

Even later releases? Or you about BPI one?

i’ve found no commit in uboot for this issue…thats why i asked tom (CC to mailinglist)