Tuesday 4 September 2012

Realtek RTL2832U DVB-T on Ubuntu 12.04 - A cleaner way

So, here we are again in the realms of the newbie, this time as a blog virgin.  I hope I can find the time to keep this up to date, as the main aim of this blog is to document new and useful things I've found that may be useful to others.  Wish me luck and please, provide as much feedback as you can.  If people are reading, I'll keep posting!

Some of you may have heard chatter about the nifty DVB-T/DAB USB dongles based upon the inexpensive RTL2832U chipset with E4000 tuner on board.  They come in a variety of shapes and sizes and are available for peanuts on eBay (£9 shipped from China when I purchased).  You might be thinking "Well that's nothing new", and on the basis of my initial description, you'd be correct.

When I add that these devices are from a functional perspective entirely software driven, that opens up different potential avenues for use and abuse.  With a little craft and some free open source software, these things can be turned into SDR's, or software defined radios to give them their full name.  They can pick up anything in the 60Mhz - 1700Mhz range, which includes (but isn't limited to) AM/FM radio, DVB-T, DAB/+ and even monitor the location and altitude of the aircraft flying above you.  As I said, pretty nifty stuff.

Before I got into playing with all of that neat stuff, I figured it'd be a nice starting point to at least get the DVB-T functionality working.  Unfortunately, the RTL2832U kernel modules haven't as of yet made it into the mainline, so we're on our own when it comes to getting these devices up and running.

Inspired by this blog post, I decided to leverage the Dell-sponsored DKMS system to manage this module.  The beauty of this solution is that you don't need to worry about ensuring that the module is rebuilt every time you upgrade your kernel; DKMS takes care of it all behind the scenes, so you won't have to manually recompile every time a kernel update is pushed out.  At worst a reinstall of the package via aptitude will fix any issues, which I'm sure you'll agree is much more elegant than the usual `make clean; make; make install;` rigmarole.  Learning the structure of the DKMS tree took around 20 minutes, plus another five minutes to hastily cobble together a .dsc set.  This has been tested on two different Ubuntu 12.04 LTS amd64 boxes, but should work just as well for i386 and possibly other architectures. 

Without further adieu, here are the commands you'll need to run to get up and running with DVB-T. Please ignore the typo in the repository name! It was late in the evening when I created the PPA repo, and I'd already published packages before I'd noticed. :)

$ sudo apt-add-repository ppa:chrisfu/rt2832u-dkms
$ sudo apt-get update
$ sudo apt-get install rtl2832u-dkms
Once the last command completes, you should be able to hot-plug the DVB-T dongle and see this sort of output in dmesg:

[  354.576385] IR NEC protocol handler initialized
[  354.579418] IR RC5(x) protocol handler initialized
[  354.586588] dvb-usb: found a 'RTL2832U DVB-T USB DEVICE' in warm state.
[  354.586602] dvb-usb: will pass the complete MPEG2 transport stream to the software demuxer.
[  354.588113] IR RC6 protocol handler initialized
[  354.588413] DVB: registering new adapter (RTL2832U DVB-T USB DEVICE)
[  354.590264] IR JVC protocol handler initialized
[  354.595469] IR Sony protocol handler initialized
[  354.598784] IR MCE Keyboard/mouse protocol handler initialized
[  354.600567] lirc_dev: IR Remote Control driver registered, major 249
[  354.600748] IR LIRC bridge handler initialized
[  354.604391] RTL2832U usb_init_bulk_setting : USB2.0 HIGH SPEED (480Mb/s)
[  354.844016] RTL2832U check_tuner_type : E4000 tuner on board...
[  355.405150] DVB: registering adapter 0 frontend 0 (Realtek DVB-T RTL2832)...
[  355.405396] input: IR-receiver inside an USB DVB receiver as /devices/pci0000:00/0000:00:1a.7/usb1/1-3/input/input5
[  355.406482] dvb-usb: schedule remote query interval to 287 msecs.
[  355.406489] dvb-usb: RTL2832U DVB-T USB DEVICE successfully initialized and connected.
[  355.406544] usbcore: registered new interface driver dvb_usb_rtl2832u

You can then use Xine/VLC/whatever you typically use to watch television.  I'd recommend you install the following package in order to test your card and scan the muxes for DVB-T channels to watch.
$ sudo apt-get install dvb-tools
$ scan -o zap /usr/share/dvb/dvb-t/uk-WinterHill > channels.conf
I'd suggest ditching any supplied aerial and using the best one available to you, for which you'll probably need a coaxial converter that can be bought on eBay for a few pounds. Remember to change the last argument in the above command to the nearest transmitter to you. You can find all the UK transmitter configs with the following command:
$ find /usr/share/dvb/dvb-t/ -type f -iname '*uk*'
That should get you started on your adventure. After you're through with tinkering with it's DVB-T capabilities, I'd strongly urge you to have a play with the devices other capabilities. After all, it's the tinkering that got Linux to where it is today!

If anyone has any bug reports of questions, please go ahead and comment.

There we have it, my blog cherry has been officially popped.

Cheers,

Chris

22 comments:

  1. It doesn't work for me. I get

    [ 107.836170] usb 1-3: new high-speed USB device number 4 using ehci_hcd
    [ 108.159517] dvb_usb_rtl2832u: Unknown symbol dvb_usb_device_init (err 0)
    [ 108.159641] dvb_usb_rtl2832u: Unknown symbol dvb_usb_device_init (err 0)
    [ 108.159681] dvb_usb_rtl2832u: Unknown symbol dvb_usb_device_exit (err 0)
    [ 108.159728] dvb_usb_rtl2832u: Unknown symbol dvb_usb_device_exit (err 0)

    I have a terratec cinergy t stick RC rev.3

    The output of lsusb says:

    Bus 001 Device 004: ID 0ccd:00d3 TerraTec Electronic GmbH

    Thanks in advance if you can help me

    Ubuntu 12.04 32bit

    ReplyDelete
    Replies
    1. It would seem that your particular RTL2832U stick isn't supported by the driver. It works, but the PCI ID needs to be patched in so that it's correctly claimed by the driver.

      When I get a bit of spare time I'll either pull in the latest version of the driver (where hopefully your device will be supported) or I'll patch it myself.

      Delete
  2. W: Failed to fetch http://ppa.launchpad.net/chrisfu/rt2832u-dkms/ubuntu/dists/oneiric/main/source/Sources 404 Not Found

    W: Failed to fetch http://ppa.launchpad.net/chrisfu/rt2832u-dkms/ubuntu/dists/oneiric/main/binary-i386/Packages 404 Not Found

    Looks like you have not kept support for older versions :(

    ReplyDelete
    Replies
    1. You should be looking to at least upgrade to 12.04 LTS, it's worth it and just one step away. ;)

      I'll copy the package to a 11.10 repo for you shortly and you can take another shot at using it. With any luck it'll work fine for you. If not, I'll try rebuilding against 11.10 libraries.

      Delete
    2. Ok Anon, give it a shot. It's copied fine and may just work for you. :)

      Delete
  3. Doh, enough to make me wish I was running 12.04. I'm running 12.10 - what changes should I make? I'm a massive noob, so a link to a how-to would me most appreciated.

    ReplyDelete
    Replies
    1. I've copied the package into the "quantal" 12.10 repo now, so try again:

      sudo apt-add repository ppa:chrisfu/rt2832u-dkms
      sudo apt-get update
      sudo apt-get install rtl2832u-dkms

      It should be clean enough to work on there. Let me know how it works out for you!

      Delete
  4. Hi! First of all: thanks for your work. I was amazed to find a PPA for this cheapo DVB-T stick I just bought.

    I installed the package on my Ubuntu 12.10 machine, but during the DKMS step it says:

    /var/lib/dkms/rtl2832u/3.0.1/build/include-320/dvb_frontend.h:49:33: error: field ‘parameters’ has incomplete type
    /var/lib/dkms/rtl2832u/3.0.1/build/include-320/dvb_frontend.h:313:28: error: array type has incomplete element type

    I'm on kernel 3.5.0-25-generic. Any ideas?

    ReplyDelete
    Replies
    1. Yep, unfortunately you'll need to use a new driver it seems. I'm planning to scrap the lot and start from scratch on Monday. See my other comment from today below.

      Delete
    2. See my other comment from this afternoon below.

      Delete
  5. Are you planning to make it also available for the next Ubuntu release (Raring)?
    I tried to install it on the latest beta, but failed with the following error:
    Error! Bad return status for module build on kernel: 3.8.0-16-generic (x86_64)
    Maybe my kernel is too new?

    ReplyDelete
    Replies
    1. I'm starting from scratch and rebuilding for all Ubuntu releases from precise onwards, both i386 and amd64, next Monday.

      Basically the drivers have changes considerably since the most recent R820t tuner came out. The only support for these has been hacked into the previous driver I was using and for kernels >3.4.x, so there's a lot of testing involved to ensure that one DKMS package can do the trick for everything.

      Delete
    2. Just out of curiosity: Have you been able to make progress on this?

      Delete
    3. Have some problem with R820T. VLC player said there is no /dev/dvb/adapter0/frontend0 device. Dmesg prints that driver has been installed correct.

      Delete
  6. Hi, could not get this to work for me.

    got these errors after apt-get update

    W: Failed to fetch http://ppa.launchpad.net/kernel-ppa/ppa/ubuntu/dists/quantal/main/source/Sources 404 Not Found

    W: Failed to fetch http://ppa.launchpad.net/kernel-ppa/ppa/ubuntu/dists/quantal/main/binary-amd64/Packages 404 Not Found

    W: Failed to fetch http://ppa.launchpad.net/kernel-ppa/ppa/ubuntu/dists/quantal/main/binary-i386/Packages 404 Not Found

    E: Some index files failed to download. They have been ignored, or old ones used instead.

    my dmesg has not changed for dtv:

    [ 1721.214744] usb 1-1: USB disconnect, device number 3
    [ 1721.214756] usb 1-1.4: USB disconnect, device number 4
    [ 1725.708148] usb 1-1: new high-speed USB device number 5 using ehci_hcd
    [ 1725.841309] usb 1-1: New USB device found, idVendor=1a40, idProduct=0101
    [ 1725.841321] usb 1-1: New USB device strings: Mfr=0, Product=1, SerialNumber=0
    [ 1725.841335] usb 1-1: Product: USB 2.0 Hub [MTT]
    [ 1725.841870] hub 1-1:1.0: USB hub found
    [ 1725.842055] hub 1-1:1.0: 4 ports detected
    [ 1726.112482] usb 1-1.4: new high-speed USB device number 6 using ehci_hcd
    [ 1726.217769] usb 1-1.4: New USB device found, idVendor=1d19, idProduct=1101
    [ 1726.217782] usb 1-1.4: New USB device strings: Mfr=1, Product=2, SerialNumber=3
    [ 1726.217790] usb 1-1.4: Product: Rtl2832UDVB
    [ 1726.217796] usb 1-1.4: Manufacturer: Realtek
    [ 1726.217802] usb 1-1.4: SerialNumber: 0
    [ 2127.283585] toshiba_acpi: Unknown key 129
    [ 2128.777802] toshiba_acpi: Unknown key 129
    [ 2735.948113] cfg80211: Found new beacon on frequency: 2472 MHz (Ch 13) on phy0
    [ 4915.169583] usb 1-1: USB disconnect, device number 5
    [ 4915.169596] usb 1-1.4: USB disconnect, device number 6
    [ 4941.132342] usb 1-1: new high-speed USB device number 7 using ehci_hcd
    [ 4941.265424] usb 1-1: New USB device found, idVendor=1a40, idProduct=0101
    [ 4941.265437] usb 1-1: New USB device strings: Mfr=0, Product=1, SerialNumber=0
    [ 4941.265444] usb 1-1: Product: USB 2.0 Hub [MTT]
    [ 4941.265990] hub 1-1:1.0: USB hub found
    [ 4941.268484] hub 1-1:1.0: 4 ports detected
    [ 4941.540603] usb 1-1.4: new high-speed USB device number 8 using ehci_hcd
    [ 4941.645999] usb 1-1.4: New USB device found, idVendor=1d19, idProduct=1101
    [ 4941.646011] usb 1-1.4: New USB device strings: Mfr=1, Product=2, SerialNumber=3
    [ 4941.646019] usb 1-1.4: Product: Rtl2832UDVB
    [ 4941.646026] usb 1-1.4: Manufacturer: Realtek
    [ 4941.646032] usb 1-1.4: SerialNumber: 0

    my lsusb is:

    Bus 001 Device 008: ID 1d19:1101 Dexatek Technology Ltd. DK DVB-T Dongle

    I also seem to have a massive amount of stuff in dmesg now that I have no clue what it is I hope nothing bad has happened!

    ReplyDelete
  7. excellent.

    But I can't find the debian package dvb-tools. I was only able to locate in the debian squeeze repo a package "dvb-apps" (which contains scan), so I guess it should be "sudo apt-get install dvb-apps".

    ReplyDelete
    Replies
    1. Same here, no dvb-tools found for 12.04, only for Quantal.
      Thanks for this driver.

      Delete
  8. Thanks for this article. That's great help! I can watch the TV now ! :D

    ReplyDelete
  9. W: Failed to fetch http://ppa.launchpad.net/chrisfu/rt2832u-dkms/ubuntu/dists/raring/main/binary-i386/Packages 404 Not Found

    ReplyDelete
  10. So what about atsc-mh?

    And next obvious question is, hmm curious about getting this all working under allwinner/a10 on something like one of these tablets. I've done lots of work on getting some custom stuff working under debian 3.4 on same, love to see if the kernel driver will work and just swap out the android druggery for a RT debian kernel.

    ReplyDelete
  11. Hi, this is awesome but... any chance of getting this to work in 13.10?

    ReplyDelete