【问题标题】:rtl-sdr crashes with "Bus error" when running rtl_tcp or rtl_test运行 rtl_tcp 或 rtl_test 时 rtl-sdr 因“总线错误”而崩溃
【发布时间】:2019-07-06 12:19:22
【问题描述】:

我在运行 Kali Linux Arm64 的 Raspberry Pi 3 上连接了一个 SDR 加密狗。 SDR 本身就是这个特殊的model

问题是,每当我远程连接到rtl_tcp 服务器时,它就会退出:

rtl_tcp -a 192.168.200.132
Found 1 device(s):
  0:  Realtek, RTL2838UHIDIR, SN: 00000001

Using device 0: Generic RTL2832U OEM
Found Rafael Micro R820T tuner
[R82XX] PLL not locked!
Tuned to 100000000 Hz.
listening...
Use the device argument 'rtl_tcp=192.168.200.132:1234' in OsmoSDR (gr-osmosdr) source
to receive samples in GRC and control rtl_tcp parameters (frequency, gain, ...).
client accepted! 192.168.200.102 64098
Allocating 15 zero-copy buffers
Bus error

rtl_test -t 测试没问题:

rtl_test -t
Found 1 device(s):
  0:  Realtek, RTL2838UHIDIR, SN: 00000001

Using device 0: Generic RTL2832U OEM
Found Rafael Micro R820T tuner
Supported gain values (29): 0.0 0.9 1.4 2.7 3.7 7.7 8.7 12.5 14.4 15.7 16.6 19.7 20.7 22.9 25.4 28.0 29.7 32.8 33.8 36.4 37.2 38.6 40.2 42.1 43.4 43.9 44.5 48.0 49.6
[R82XX] PLL not locked!
Sampling at 2048000 S/s.
No E4000 tuner found, aborting.

但是使用采样率进行测试会导致相同的不良行为。

rtl_test -s 2048000
Found 1 device(s):
  0:  Realtek, RTL2838UHIDIR, SN: 00000001

Using device 0: Generic RTL2832U OEM
Found Rafael Micro R820T tuner
Supported gain values (29): 0.0 0.9 1.4 2.7 3.7 7.7 8.7 12.5 14.4 15.7 16.6 19.7 20.7 22.9 25.4 28.0 29.7 32.8 33.8 36.4 37.2 38.6 40.2 42.1 43.4 43.9 44.5 48.0 49.6
[R82XX] PLL not locked!
Sampling at 2048000 S/s.

Info: This tool will continuously read from the device, and report if
samples get lost. If you observe no further output, everything is fine.

Reading samples in async mode...
Allocating 15 zero-copy buffers
Bus error

如何防止这种情况发生,并让RTL-SDR 正常运行?

我尝试过的事情

没有变化:

  1. 我在 Kali 的存储库中使用了 RTL-SDR,并使用 git.osmocom.org/rtl-sdr.git 存储库从源代码编译 - 没有变化
  2. 将交换文件大小增加到 2 GB — 没有变化

一些变化:

rtl_test 中强制同步模式没有产生错误。

rtl_test -s 2048000 -S
Found 1 device(s):
  0:  Realtek, RTL2838UHIDIR, SN: 00000001

Using device 0: Generic RTL2832U OEM
Found Rafael Micro R820T tuner
Supported gain values (29): 0.0 0.9 1.4 2.7 3.7 7.7 8.7 12.5 14.4 15.7 16.6 19.7 20.7 22.9 25.4 28.0 29.7 32.8 33.8 36.4 37.2 38.6 40.2 42.1 43.4 43.9 44.5 48.0 49.6
[R82XX] PLL not locked!
Sampling at 2048000 S/s.

Info: This tool will continuously read from the device, and report if
samples get lost. If you observe no further output, everything is fine.

Reading samples in sync mode...
(Samples are being lost but not reported.)

rtl_tcp 中引入b 标志可以让我设置缓冲区的数量,这似乎没有多大作用:

rtl_tcp -a 192.168.200.132 -b 1
Found 1 device(s):
  0:  Realtek, RTL2838UHIDIR, SN: 00000001

Using device 0: Generic RTL2832U OEM
Found Rafael Micro R820T tuner
[R82XX] PLL not locked!
Tuned to 100000000 Hz.
listening...
Use the device argument 'rtl_tcp=192.168.200.132:1234' in OsmoSDR (gr-osmosdr) source
to receive samples in GRC and control rtl_tcp parameters (frequency, gain, ...).
client accepted!
Allocating 1 zero-copy buffers
Bus error

【问题讨论】:

    标签: software-defined-radio rtl-sdr


    【解决方案1】:

    不知道能不能完整回答这个问题,但是我在调​​试USB3设备的时候也遇到过类似的错误。问题似乎出现了,不是因为不支持 USB3(它是一个 USB3 适配器),而是因为卡驱动程序无法分配足够的背板带宽来动态分配特定的 USB 管道。

    我对 RPi 不太熟悉 - 您是否尝试通过 USB-以太网/Wifi 加密狗将捕获路由出去?除了USB3,我想知道这是否是类似的动态带宽分配问题。

    -- 不久前报告了与零拷贝缓冲区代码有关的事情:https://www.mail-archive.com/osmocom-sdr@lists.osmocom.org/msg01204.html 从描述中它以不同的方式表现出来,并且还应用了解决方法。

    【讨论】:

    • 有问题的设备是 USB2 上的 RTL-SDR,我正在尝试将捕获路由到以太网端口。但是,似乎在捕获阶段抛出了错误,因为rtl_test 只是捕获并转储数据。
    • 另外,改变缓冲区的数量也无济于事。我已经用一个例子更新了这个问题。也许我应该尝试在您链接的电子邮件中注释掉代码。
    • USB2 和 USB3 都动态分配具有一些前期带宽的数据管道,作为 USB 协议栈的一部分 - 这可能会在底层 USB 硬件驱动程序中失败,具体取决于一系列事物和内存之一在我看到的情况下,PCI(背板)带宽不足 - 换句话说,一直依赖于当前的硬件状态。我认为 libusb 可以在启用调试标志的情况下编译以获取更多信息。我最终在内核源代码 xhci 中弄清楚到底发生了什么。
    • 删除零拷贝代码对我有用!我认为这是一个错误,需要解决。
    【解决方案2】:

    我仍然不确定问题出在哪里,但根据 @jsr 给我的指示,我继续删除了 zerocopy 代码并重新编译了 rtl-sdr 并且它工作了。

    这是一个差异。这可能是程序中的错误,需要解决。

    diff --git a/src/librtlsdr.c b/src/librtlsdr.c
    index 89ec903..61bcebc 100644
    --- a/src/librtlsdr.c
    +++ b/src/librtlsdr.c
    @@ -1748,50 +1748,6 @@ static int _rtlsdr_alloc_async_buffers(rtlsdr_dev_t *dev)
            dev->xfer_buf = malloc(dev->xfer_buf_num * sizeof(unsigned char *));
            memset(dev->xfer_buf, 0, dev->xfer_buf_num * sizeof(unsigned char *));
    
    -#if defined (__linux__) && LIBUSB_API_VERSION >= 0x01000105
    -       fprintf(stderr, "Allocating %d zero-copy buffers\n", dev->xfer_buf_num);
    -
    -       dev->use_zerocopy = 1;
    -       for (i = 0; i < dev->xfer_buf_num; ++i) {
    -               dev->xfer_buf[i] = libusb_dev_mem_alloc(dev->devh, dev->xfer_buf_len);
    -
    -               if (dev->xfer_buf[i]) {
    -                       /* Check if Kernel usbfs mmap() bug is present: if the
    -                        * mapping is correct, the buffers point to memory that
    -                        * was memset to 0 by the Kernel, otherwise, they point
    -                        * to random memory. We check if the buffers are zeroed
    -                        * and otherwise fall back to buffers in userspace.
    -                        */
    -                       if (dev->xfer_buf[i][0] || memcmp(dev->xfer_buf[i],
    -                                                         dev->xfer_buf[i] + 1,
    -                                                         dev->xfer_buf_len - 1)) {
    -                               fprintf(stderr, "Detected Kernel usbfs mmap() "
    -                                               "bug, falling back to buffers "
    -                                               "in userspace\n");
    -                               dev->use_zerocopy = 0;
    -                               break;
    -                       }
    -               } else {
    -                       fprintf(stderr, "Failed to allocate zero-copy "
    -                                       "buffer for transfer %d\nFalling "
    -                                       "back to buffers in userspace\n", i);
    -                       dev->use_zerocopy = 0;
    -                       break;
    -               }
    -       }
    -
    -       /* zero-copy buffer allocation failed (partially or completely)
    -        * we need to free the buffers again if already allocated */
    -       if (!dev->use_zerocopy) {
    -               for (i = 0; i < dev->xfer_buf_num; ++i) {
    -                       if (dev->xfer_buf[i])
    -                               libusb_dev_mem_free(dev->devh,
    -                                                   dev->xfer_buf[i],
    -                                                   dev->xfer_buf_len);
    -               }
    -       }
    -#endif
    -
            /* no zero-copy available, allocate buffers in userspace */
            if (!dev->use_zerocopy) {
                    for (i = 0; i < dev->xfer_buf_num; ++i) {
    

    重新编译后,程序按预期运行:

    ~/sandbox/rtl-sdr# rtl_tcp -a 192.168.200.132 -f 89000 -b 100
    Found 1 device(s):
      0:  Realtek, RTL2838UHIDIR, SN: 00000001
    
    Using device 0: Generic RTL2832U OEM
    Found Rafael Micro R820T tuner
    [R82XX] PLL not locked!
    [R82XX] PLL not locked!
    Tuned to 89000 Hz.
    listening...
    Use the device argument 'rtl_tcp=192.168.200.132:1234' in OsmoSDR (gr-osmosdr) source
    to receive samples in GRC and control rtl_tcp parameters (frequency, gain, ...).
    client accepted!
    set gain mode 1
    set agc mode 0
    set direct sampling 0
    Disabled direct sampling mode
    [R82XX] PLL not locked!
    set offset tuning 0
    set bias tee 0
    set sample rate 1800000
    [R82XX] PLL not locked!
    ll+, now 1
    set freq 24000000
    set gain 495
    ll+, now 2
    set gain 495
    set gain 495
    set freq 106661000
    ll+, now 3
    ll+, now 4
    ll+, now 5
    ll+, now 6
    

    【讨论】:

      猜你喜欢
      • 2011-05-21
      • 2014-03-03
      • 2020-06-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-09-28
      • 2017-08-21
      • 2014-01-20
      相关资源
      最近更新 更多