Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How do I compile a Linux kernel module?

661 views
Skip to first unread message

Dave Rove

unread,
Jun 4, 2014, 5:49:53 AM6/4/14
to
I speculatively bought a USB video capture device for £4 from a
Chinese Ebay vendor, and dmesg identifies it as
"usbtv 3-3:1.0: Fushicai USBTV007 Video Grabber".

The video works OK in Ubuntu 14.04, but there's no audio. A web
search hit on a Wiki saying that the audio has just been added:
http://linuxtv.org/wiki/index.php/Easycap

The code is on github here:
https://github.com/simon3z/usbtv

So I need to compile my first Kernel module and I find it confusing.


The "Makefile" just contains this, so I get that I need to do
something more than just type "make":

usbtv-y := usbtv-core.o \
usbtv-video.o \
usbtv-audio.o

obj-$(CONFIG_VIDEO_USBTV) += usbtv.o


And there is a "Kconfig" that's evidently important:

config VIDEO_USBTV
tristate "USBTV007 video capture support"
depends on VIDEO_V4L2
select VIDEOBUF2_VMALLOC

---help---
This is a video4linux2 driver for USBTV007 based video capture devices.

To compile this driver as a module, choose M here: the
module will be called usbtv

But web searching just shows somebody with the same problem and no answer:
http://unix.stackexchange.com/questions/131553/kconfig-compiling-kernel-module

Help, please.

Pinnerite

unread,
Jun 4, 2014, 7:46:32 AM6/4/14
to
Most regular compilations require a 'config' first, although in your case it
might be kconfig.

As root, get to the top directory holding your source and at the # enter
./configure
If that fails, try ./kconfig

Best of luck.

Regards, Alan

--

Mageia 3 for x86_64, Kernel: 3.10.40-server-1.mga3
KDE version 4.10.5 Running on an AMD 4-core processor

Dave Rove

unread,
Jun 4, 2014, 8:39:58 AM6/4/14
to
On Wed, 04 Jun 2014 12:46:32 +0100, Pinnerite wrote:

> As root, get to the top directory holding your source and at the # enter
> ./configure If that fails, try ./kconfig

Thanks, there were no .config or .kconfig files, but I've now found a
webpage that said kernel modules for the running kernel are compiled with:

make -C /lib/modules/`uname -r`/build M=$PWD

That seemed to work but it objected to installing the module in the
running kernel, so I manually replaced this module and rebooted:
/lib/modules/3.13.0-24-generic/kernel/drivers/media/usb/usbtv/usbtv.ko

But this command still just played the video and no sound:
mplayer tv://

mplayer reports "Audio: no sound". So after much web searching, I
stumbled through how to find a new audio device on the system. I
identified the "sound card" with:

cat /proc/asound/cards | grep -i usbtv
1 [usbtv ]: usbtv - usbtv
USBTV Audio at bus 3 device 4

So it's apparently "sound card 1"

ls -l /dev/snd/*C1*
crw-rw----+ 1 root audio 116, 10 Jun 4 13:04 /dev/snd/controlC1
crw-rw----+ 1 root audio 116, 9 Jun 4 13:04 /dev/snd/pcmC1D0c

So that's the new device but how do I use it?

dd if=/dev/snd/pcmC1D0c bs=1K count=1 of=soundfile
dd: error reading ‘/dev/snd/pcmC1D0c’: File descriptor in bad state 0+0
records in 0+0
records out 0 bytes (0 B) copied, 0.000346106 s, 0.0 kB/s

I'm still confused by this.

William Unruh

unread,
Jun 4, 2014, 12:22:54 PM6/4/14
to
That is to add the driver to the kernel in a full compile of the kernel. Usually one can also compile a module separately. You have to have the kernel source tree installed to do that.

Here for example is the Makefile for a module I wrote, gps.o
You will have to figure out how to adapt it for your purpose.

# Comment/uncomment the following line to disable/enable debugging
#DEBUG = y


# Add your debugging flag (or not) to CFLAGS
ifeq ($(DEBUG),y)
DEBFLAGS = -O -g -DSHORT_DEBUG # "-O" is needed to expand inlines
else
DEBFLAGS = -O2
endif

EXTRA_CFLAGS += $(DEBFLAGS) -DUSE_IMMEDIATE
EXTRA_CFLAGS += -I..

ifneq ($(KERNELRELEASE),)
# call from kernel build system

obj-m := gps.o

else

KERNELDIR ?= /lib/modules/$(shell uname -r)/build
PWD := $(shell pwd)

modules:
$(MAKE) -C $(KERNELDIR) M=$(PWD) modules

endif


clean:
rm -rf *.o *~ core .depend .*.cmd *.ko *.mod.c .tmp_versions

depend .depend dep:
$(CC) $(EXTRA_CFLAGS) -M *.c > .depend


ifeq (.depend,$(wildcard .depend))
include .depend
endif


On 2014-06-04, Dave Rove <da...@dr.invalid> wrote:
> I speculatively bought a USB video capture device for ??4 from a

Andy Furniss

unread,
Jun 4, 2014, 2:58:13 PM6/4/14
to
Dave Rove wrote:

> But this command still just played the video and no sound:
> mplayer tv://

> cat /proc/asound/cards | grep -i usbtv
> 1 [usbtv ]: usbtv - usbtv
> USBTV Audio at bus 3 device 4

try

mplayer tv:// -tv alsa:adevice=hw.1

there are other options that may or may not be needed like

amode=1 to get stereo (probably default)

audiorate=48000 or whatever in case it sounds wrong

run alsamixer and make sure you are open OO not muted MM for the card.


Dave Rove

unread,
Jun 4, 2014, 4:00:27 PM6/4/14
to
On Wed, 04 Jun 2014 19:58:13 +0100, Andy Furniss wrote:

> try
> mplayer tv:// -tv alsa:adevice=hw.1
> there are other options that may or may not be needed like
> amode=1 to get stereo (probably default)
> audiorate=48000 or whatever in case it sounds wrong
> run alsamixer and make sure you are open OO not muted MM for the card.

Thanks, that was helpful. It didn't actually work like that but I
Googled for examples of those options and found this page:
http://inspirated.com/2007/04/05/alsa-line-in-capture-with-mplayer

And tweaked the example there until it worked, then pruned it down to
just the critical options which were:

mplayer -tv driver=v4l2:alsa:adevice=hw.1:forceaudio:immediatemode=0 tv://

Good enough. I'll leave it there for now and try to figure out the
options for mencoder or ffmpeg another day.

Pity I can't get any video editor in Ubuntu to work with it. Flowblade,
Openshot, and Avidemux have no device capture options; and Kdenlive only
sees "blackmagic" cards. Cinelarra actually does see it in its capture
settings but promptly crashes when I hit record.

mailt...@gmail.com

unread,
Jun 2, 2015, 11:59:50 AM6/2/15
to
Hey dave did u got audio working. I was trying to set things up in puppy.. needs guidance as am i am totally lost bcoz am a newbie
0 new messages