xtrx-sdr / images

Pre-built XTRX packages and firmware images
https://www.crowdsupply.com/fairwaves/xtrx
43 stars 27 forks source link

Synchronous External Abort on Gateworks GW6200 #75

Closed ghost closed 4 years ago

ghost commented 4 years ago

Hi,

I'm trying to use an XTRX Pro on a Gateworks GW6200 SBC. Any help would be super appreciated.

I have stripped the test_xtrx code down to this. The same error happens with the original test_xtrx, it's just more noisy.

test_xtrx2.c code:
-----
#include "xtrx_api.h"

int main() {
        struct xtrx_dev* dev;
        xtrx_open("/dev/xtrx0", 2 | XTRX_O_RESET, &dev);
        xtrx_close(dev);
        return 0;                                                                                                                                                                                    
}

This is what I get when running it on the GW6200:

GW6200 environment:                                                                                                                                                                                  
-----                                                                                                                                                                                                
root@bionic-newport:~# cat /proc/cmdline                                                                                                                                                             
cma=64M coherent_pool=16M net.ifnames=0 root=/dev/mmcblk0p2 rw rootwait console=ttyAMA0,115200n8 earlycon=pl011,0x87e028000000 root=/dev/mmcblk0p2 rw rootwait console=ttyAMA0,115200n8 earlyco      n=pl011,0x87e028000000                                                                                                                                                                               
root@bionic-newport:~# uname -a                                                                                                                                                                      
Linux bionic-newport 4.14.4-g99455305dd70 #1 SMP PREEMPT Tue Jan 7 03:40:11 UTC 2020 aarch64 aarch64 aarch64 GNU/Linux                                                                               

GW6200 run:                                                                                                                                                                                          
-----                                                                                                                                                                                                
root@bionic-newport:~/xtrx-images/sources/build# ./libxtrx/test_xtrx2
Bus error

GW6200 strace:
-----
root@bionic-newport:~/xtrx-images/sources# strace ./build/libxtrx/test_xtrx2
execve("./build/libxtrx/test_xtrx2", ["./build/libxtrx/test_xtrx2"], 0xffffd650f710 /* 20 vars */) = 0
...
openat(AT_FDCWD, "/dev/xtrx0", O_RDWR)  = 3
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_SHARED, 3, 0) = 0xffff978ae000
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_SHARED, 3, 0x400000) = 0xffff978ad000
brk(NULL)                               = 0xaaaad0dbf000
brk(0xaaaad0de0000)                     = 0xaaaad0de0000
--- SIGBUS {si_signo=SIGBUS, si_code=SI_USER, si_pid=2542461032, si_uid=65535} ---
+++ killed by SIGBUS +++
Bus error

GW6200 dmesg:
-----
[  645.801736] xtrx: call: REGION=1 VMA=ffff800069724540 vma->vm_pgoff=0
[  645.801743] xtrx: VMA open, virt ffff81bfd000, phys 0
[  645.801752] xtrx: call: REGION=0 VMA=ffff800069724600 vma->vm_pgoff=1024
[  645.801755] xtrx: VMA open, virt ffff81bfc000, phys 400000
[  645.801877] Synchronous External Abort: synchronous external abort (0x92000210) at 0x0000ffff81bfd068
[  645.811526] xtrx: VMA close.
[  645.811530] xtrx: VMA close.

GW6200 gdb:
-----
root@bionic-newport:~/xtrx-images/sources# gdb ./build/libxtrx/test_xtrx2
...
(gdb) run
Starting program: /root/xtrx-images/sources/build/libxtrx/test_xtrx2
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/aarch64-linux-gnu/libthread_db.so.1".

Program received signal SIGBUS, Bus error.
0x0000ffffbf4f7610 in internal_xtrxll_reg_in (dev=0xaaaaaaabc260, reg=26) at /root/xtrx-images/sources/libxtrxll/mod_pcie/xtrxll_pcie_linux.c:152
152             uint32_t val = be32toh(__atomic_load_n(&dev->mmap_xtrxll_regs[reg],
(gdb) bt
#0  0x0000ffffbf4f7610 in internal_xtrxll_reg_in (dev=0xaaaaaaabc260, reg=26) at /root/xtrx-images/sources/libxtrxll/mod_pcie/xtrxll_pcie_linux.c:152
#1  0x0000ffffbf4f9554 in xtrxllpciev0_reg_in (bdev=0xaaaaaaabc260, reg=26, inval=0xaaaaaaabc280) at /root/xtrx-images/sources/libxtrxll/mod_pcie/xtrxll_pcie_linux.c:741
#2  0x0000ffffbf4f1ca4 in xtrxll_base_dev_init (dev=0xaaaaaaabc260, ops=0xffffbf512bb0 <mod_ops>, id=0xaaaaaaabc2d0 "PCI:/dev/xtrx0") at /root/xtrx-images/sources/libxtrxll/xtrxll_base.c:1114
#3  0x0000ffffbf4f818c in xtrxllpciev0_open (device=0xaaaaaaaaaca0 "/dev/xtrx0", flags=0, pdev=0xfffffffff3d0) at /root/xtrx-images/sources/libxtrxll/mod_pcie/xtrxll_pcie_linux.c:342
#4  0x0000ffffbf4f6a9c in xtrxll_open (device=0xaaaaaaaaaca0 "/dev/xtrx0", flags=0, odev=0xfffffffff418) at /root/xtrx-images/sources/libxtrxll/xtrxll_api.c:233
#5  0x0000ffffbf671748 in xtrx_open (device=0xaaaaaaaaaca0 "/dev/xtrx0", flags=258, outdev=0xfffffffff440) at /root/xtrx-images/sources/libxtrx/xtrx.c:314
#6  0x0000aaaaaaaaabc8 in main () at /root/xtrx-images/sources/libxtrx/test_xtrx2.c:5

This is what I get when I run the same code on an i7 laptop:

i7 run:
-----
root@connor-Latitude-E6540:/home/connor/images/sources/build# ./libxtrx/test_xtrx2 
CPU Features: SSE2+ SSE4.1+ AVX+ FMA+

i7 strace:
-----
root@connor-Latitude-E6540:/home/connor/images/sources/build# strace ./libxtrx/test_xtrx2     
execve("./libxtrx/test_xtrx2", ["./libxtrx/test_xtrx2"], 0x7fff340691f0 /* 17 vars */) = 0
...
openat(AT_FDCWD, "/dev/xtrx0", O_RDWR)  = 3
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_SHARED, 3, 0) = 0x7fe9265cd000
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_SHARED, 3, 0x400000) = 0x7fe9265cc000
brk(NULL)                               = 0x55c69ef7b000
brk(0x55c69ef9c000)                     = 0x55c69ef9c000
write(2, "CPU Features: SSE2+ SSE4.1+ AVX+"..., 38CPU Features: SSE2+ SSE4.1+ AVX+ FMA+
) = 38
nanosleep({tv_sec=0, tv_nsec=10000000}, NULL) = 0
ioctl(3, _IOC(0, 0x34, 0x5b, 0x12), 0x1) = 1
pread64(3, NULL, 0, 9)                  = 1
...

i7 dmesg:
-----
[69265.827173] xtrx: call: REGION=1 VMA=00000000b6b4a112 vma->vm_pgoff=0
[69265.827185] xtrx: VMA open, virt 7f9463441000, phys 0
[69265.827189] xtrx: call: REGION=0 VMA=000000004d29944d vma->vm_pgoff=1024
[69265.827194] x86/PAT: test_xtrx2:4096 map pfn RAM range req uncached-minus for [mem 0x20b7c7000-0x20b7c7fff], got write-back
[69265.827195] xtrx: VMA open, virt 7f9463440000, phys 400000
[69265.837421] xtrx: ioctl(12345b, 1) [ffffbb0300ca7000]
[69265.837422] xtrx:  3V3 CTRL:1
[69266.043380] xtrx: ioctl(12345b, 1) [ffffbb0300ca7000]
[69266.068610] xtrx: ioctl(12345b, 0) [ffffbb0300ca7000]
[69266.068614] xtrx:  3V3 CTRL:0
[69266.069730] xtrx: VMA close.
[69266.069739] xtrx: VMA close.

i7 gdb:
-----
root@connor-Latitude-E6540:/home/connor/images/sources/build# gdb ./libxtrx/test_xtrx2   
...
(gdb) run
Starting program: /home/connor/images/sources/build/libxtrx/test_xtrx2 
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
CPU Features: SSE2+ SSE4.1+ AVX+ FMA+
[New Thread 0x7ffff66fa700 (LWP 4082)]
[Thread 0x7ffff66fa700 (LWP 4082) exited]
[Inferior 1 (process 4078) exited normally]
(gdb) quit

This is how I compiled the driver:

Cross-compile driver for GW6200:
-----
connor@computron:~/code/XXXX/xtrx-images/sources/xtrx_linux_pcie_drv$ make -C ~/code/XXXX/newport/linux/ M=$PWD
make: Entering directory '/home/connor/code/XXXX/newport/linux'
  AR      /home/connor/code/XXXX/xtrx-images/sources/xtrx_linux_pcie_drv/built-in.o
  CC [M]  /home/connor/code/XXXX/xtrx-images/sources/xtrx_linux_pcie_drv/xtrx.o
  Building modules, stage 2.
  MODPOST 1 modules
  LD [M]  /home/connor/code/XXXX/xtrx-images/sources/xtrx_linux_pcie_drv/xtrx.ko
make: Leaving directory '/home/connor/code/XXXX/newport/linux'

Compile driver for AMD64:
-----
root@connor-Latitude-E6540:/home/connor/images/sources/xtrx_linux_pcie_drv# make -C /usr/src/linux-headers-5.0.0-37-generic/ M=$PWD
make: Entering directory '/usr/src/linux-headers-5.0.0-37-generic'
  CC [M]  /home/connor/images/sources/xtrx_linux_pcie_drv/xtrx.o
  Building modules, stage 2.
  MODPOST 1 modules
  CC      /home/connor/images/sources/xtrx_linux_pcie_drv/xtrx.mod.o
  LD [M]  /home/connor/images/sources/xtrx_linux_pcie_drv/xtrx.ko
make: Leaving directory '/usr/src/linux-headers-5.0.0-37-generic'
ghost commented 4 years ago

Ok, I think I might be doing something silly. If I run this code it works on Intel but not on the ARM:

#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <sys/mman.h>
#include <fcntl.h>
#include <stdint.h>
#include <string.h>

int main() {
        int fd = open("/dev/xtrx0", O_RDWR);
        uintptr_t* p1 = (uintptr_t*)mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0);
        uintptr_t* p2 = (uintptr_t*)malloc(4096);

        printf("p1=%p, p2=%p\n", p1, p2);

        memcpy(p2, p1, 4096);

        free(p2);
        munmap(p1, 4096);
        close(fd);

        return 0;
}

Intel output:

root@connor-Latitude-E6540:/home/connor# ./test 
p1=0x7f4574cca000, p2=0x5587a75ec260

dmesg:
[77147.214163] xtrx: call: REGION=1 VMA=000000004993e82b vma->vm_pgoff=0
[77147.214179] xtrx: VMA open, virt 7f2c449dd000, phys 0
[77147.214659] xtrx: VMA close.

ARM output:

root@bionic-newport:~# ./test 
p1=0xffff93991000, p2=0xaaab03985260
Bus error

dmesg:
[ 9953.508406] xtrx: call: REGION=1 VMA=ffff800066026300 vma->vm_pgoff=0
[ 9953.508413] xtrx: VMA open, virt ffff93991000, phys 0
[ 9953.508571] Synchronous External Abort: synchronous external abort (0x92000210) at 0x0000ffff93991000
[ 9953.518038] xtrx: VMA close.
ghost commented 4 years ago

Oh, using the latest code works :)