Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gqrx uses wrong spi_init function, and when I fix that, smi crashes the kernel #211

Open
DanaGoyette opened this issue Jul 24, 2024 · 0 comments

Comments

@DanaGoyette
Copy link

DanaGoyette commented Jul 24, 2024

Originally posted in #196 (comment)

On git revision 64895f0, trying to use gqrx or SoapyRemoteServer results in a crash with an access violation.

After hacking at all the CMakeLists.txt files to force a Debug build (the files all force a Release build instead of respecting CMAKE_BUILD_TYPE), Valgrind points out where the bad write is:

gr-osmosdr 0.2.0.0 (0.2.0) gnuradio 3.10.5.1
built-in source types: file fcd rtl rtl_tcp uhd hackrf bladerf rfspace airspy airspyhf soapy redpitaya freesrp xtrx
Resampling audio 96000 -> 48000
BandPlanFile is /home/dana/.config/gqrx/bandplan.csv
BookmarksFile is /home/dana/.config/gqrx/bookmarks.csv
[INFO] [UHD] linux; GNU C++ version 12.2.0; Boost_107400; UHD_4.3.0.0+ds1-5
libusb: warning [libusb_exit] device 2.1 still referenced
libusb: warning [libusb_exit] device 1.3 still referenced
libusb: warning [libusb_exit] device 1.2 still referenced
libusb: warning [libusb_exit] device 1.1 still referenced
[INFO] SoapyCaribouliteSession, sessionCount: 0
==57875== Invalid write of size 8
==57875==    at 0x7EAE998: spi_init (in /usr/lib/aarch64-linux-gnu/libbladeRF.so.2)
==57875==    by 0x1D4746B7: io_utils_spi_add_chip (io_utils_spi.c:427)
==57875==    by 0x1D4646FB: caribou_fpga_init (caribou_fpga.c:130)
==57875==    by 0x1D4602AF: cariboulite_init_driver_minimal (cariboulite_setup.c:624)
==57875==    by 0x1D4605AB: cariboulite_init_driver (cariboulite_setup.c:691)
==57875==    by 0x1D45D64B: SoapyCaribouliteSession::SoapyCaribouliteSession() (CaribouliteSession.cpp:49)
==57875==    by 0x1D4577A3: __static_initialization_and_destruction_0(int, int) (Cariboulite.cpp:5)
==57875==    by 0x1D4577DF: _GLOBAL__sub_I_Cariboulite.cpp (Cariboulite.cpp:545)
==57875==    by 0x40044C7: call_init (dl-init.c:74)
==57875==    by 0x40044C7: call_init (dl-init.c:26)
==57875==    by 0x40045D3: _dl_init (dl-init.c:121)
==57875==    by 0x6EBEDD3: _dl_catch_exception (dl-error-skeleton.c:182)
==57875==    by 0x400A437: dl_open_worker (dl-open.c:808)
==57875==  Address 0x10 is not stack'd, malloc'd or (recently) free'd
==57875==
CaribouLite: Signal [11] received from pid=[16]
Signal [11] caught, with the following information:
   signal errno = 0
   signal process pid = 16
   signal process uid = 0
   signal status = 0
   signal errno / SIGSEGV / the process access invalid region of memory
SIGSEGV: memory access violation

gdb shows this:

#0  0x0000007ff499e998 in spi_init (phy=<optimized out>, userdata=0x7fffffb060) at ./thirdparty/analogdevicesinc/no-OS_local/platform_bladerf2/platform.c:16
No locals.
#1  0x0000007fdca646b8 in io_utils_spi_add_chip (dev=0x7fdca99230 <SoapyCaribouliteSession::sys+400>, cs_pin=18, speed=1000000, swap_mi_mo=0, mode=0, chip_type=io_utils_spi_chip_type_fpga_comm, hard_dev=0x7fffffb0f8)
    at /home/dana/Downloads/cariboulite/software/libcariboulite/src/io_utils/io_utils_spi.c:427
        spi_device_file = "/dev/spidev1.0\000\000\000\000\000\000`\237\202\300\000\000\000\000\000\000\000"
        res = -1
        __func__ = "io_utils_spi_add_chip"
        i = 0
        new_chip_index = 0
#2  0x0000007fdca546fc in caribou_fpga_init (dev=0x7fdca994c8 <SoapyCaribouliteSession::sys+1064>, io_spi=0x7fdca99230 <SoapyCaribouliteSession::sys+400>)
    at /home/dana/Downloads/cariboulite/software/libcariboulite/src/caribou_fpga/caribou_fpga.c:130
        __func__ = "caribou_fpga_init"
        hard_dev_fpga = {spi_dev_id = 1, spi_dev_channel = 0, spidev = {fd = 0, speed = 0, mode = 0 '\000', lsb = 0 '\000', bits = 0 '\000'}}
#3  0x0000007fdca502b0 in cariboulite_init_driver_minimal (sys=0x7fdca990a0 <SoapyCaribouliteSession::sys>, info=0x0, production=false) at /home/dana/Downloads/cariboulite/software/libcariboulite/src/cariboulite_setup.c:624
        __func__ = "cariboulite_init_driver_minimal"
        led0 = 127
        led1 = -593164884
        btn = 127
        cfg = -592904024
#4  0x0000007fdca505ac in cariboulite_init_driver (sys=0x7fdca990a0 <SoapyCaribouliteSession::sys>, info=0x0) at /home/dana/Downloads/cariboulite/software/libcariboulite/src/cariboulite_setup.c:691
        ret = 127
        __func__ = "cariboulite_init_driver"
        self_tes_res = {fpga_fail = 0, modem_fail = 0, mixer_fail = -592902432, smi_fail = 127}

(It sure would be helpful to have those logs from the ZF_LOGD statements go to stderr.)

It seems like gqrx is loading the spi_init function from an entirely different library.
I had to rename spi_init to spi_init2 in these three files:

  • software/libcariboulite/src/io_utils/io_utils_spi.c
  • software/libcariboulite/src/io_utils/spidev/spi.c
  • software/libcariboulite/src/io_utils/spidev/spi.h

Now when I try to use gqrx locally on the Pi 4, it seems to work, but trying to use it remotely gives a weird spectrum with nothing visible except a symmetrical spike centered at the tuning frequency.

Screenshot 2024-07-24 at 3 05 15 PM

And then when I restart the stream a few times or adjust the sample rate, it crashes the Pi 4's kernel.

dmesg-ramoops-0.txt
dmesg-ramoops-1.txt

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant