OpenWrt Forum Archive

Topic: building kernel modules that need kernel sources with buildroot-ng

The content of this topic has been archived on 28 Apr 2018. There are no obvious gaps in this topic, but there may still be some posts missing at the end.

Hi all!

I am trying to build a kernel module driver specific to a device I am trying to have working under openwrt. The makefile of this driver points to the kernel sources used to make the kernel of the platform that will be running the driver.

What path should I put in the Makefile so that it will find the kernel sources used to build my openwrt image with buildroot-ng?

Thanks!

Stanislas

Without having specific details about what your doing my best advice would be for the actual module's makefile to include some variable like $(KERNELPATH) which can be passed on the command line from the package's makefile -- the package Makefile will have the kernel's path available as $(LINUX_DIR).

Is there a list of available variables somewhere?

Thanks!

Stanislas

The majority of the variables are exported from rules.mk in the top directory.

Hum...

Specifically, I am trying to build the driver available here :
http://www.erwinrol.de/index.php?opensource/dmxusb.php

When I do a make package/dmxusb, I get this error message :

"Collecting package info...
ERROR: please fix package/dmxusb/Makefile

Here is my Makefile :

include $(TOPDIR)/rules.mk

PKG_NAME:=dmxusb
PKG_VERSION:=1.0
PKG_RELEASE:=1

PKG_BUILD_DIR:=$(BUILD_DIR)/$(PKG_NAME)


include $(INCLUDE_DIR)/package.mk

define Package/dmxusb
  SECTION:=base
  CATEGORY:=Drivers
  DEFAULT:=y
  TITLE:=dmxusb driver
  DESCRIPTION:=dmxusb driver
  URL:=http://www.erwinrol.de
endef

define Build/Prepare
    mkdir -p $(PKG_BUILD_DIR)
    $(CP) ./src/* $(PKG_BUILD_DIR)/
endef


define Package/dmxusb/install
        install -m0755 -d $(1)/usr/sbin
        install -m0755 $(PKG_BUILD_DIR)/dmxusb $(1)/usr/sbin/
endef

$(eval $(call BuildPackage,dmxusb))

Any reasons why I get this error message?

Thanks again!

Stanislas

Run the following command (shown in the tutorial)

TOPDIR=$PWD make -C package/dmxusb DUMP=1

You'll find that your indentation is wrong; all shell commands need to be indented by a tab, so at the very least you need to fix your Build/Prepare section.

I verified my Makefile and there were no indentation errors.
I probably did something wrong while copy/paste the text block.

I ran TOPDIR=$PWD; make -C package/dmxusb DUMP=1 V=99
Here is what I got :

vmware@xubuntu:~/Desktop/buildroot-ng/openwrt$ TOPDIR=$PWD; make -C package/dmxusb DUMP=1 V=99
make: Entering directory `/home/vmware/Desktop/buildroot-ng/openwrt/package/dmxusb'
Makefile:1: /rules.mk: No such file or directory
Makefile:10: /package.mk: No such file or directory
make: *** No rule to make target `/package.mk'.  Stop.
make: Leaving directory `/home/vmware/Desktop/buildroot-ng/openwrt/package/dmxusb'

I find it strange that this command knows TOPDIR well enough to enter the right directory and start running the right Makefile, but nothing else happens after that, the Makefile does not seem to know what TOPDIR is anymore.

Stanislas

No ; in the command I gave

Sorry, I don't understand what you mean by your last post.

English is not my native lanquage, thank you very much for being so patient with me...

You didn't type the right command

TOPDIR=$PWD make -C package/dmxusb DUMP=1

Ok.

This is what I get now :

root@xubuntu:/home/vmware/Desktop/buildroot-ng/openwrt# TOPDIR=$PWD make -C package/dmxusb DUMP=1
make: Entering directory `/home/vmware/Desktop/buildroot-ng/openwrt/package/dmxusb'
Package: dmxusb
Default: y
Version: 1.0-1
Depends:
Build-Depends:
Category: Drivers
Title: dmxusb driver
Description: dmxusb driver

http://www.erwinrol.de
@@
make: Leaving directory `/home/vmware/Desktop/buildroot-ng/openwrt/package/dmxusb'

Something more usefull :

This is the Makefile from the source I am tryong to build :

#
# $Id: Makefile 38 2004-09-11 11:15:09Z erwin $
#
CC=mipsel-linux-uclibc-gcc

ifneq ($(KERNELRELEASE),)

obj-m := dmx_usb.o

else

KDIR    := $(KERNELPATH)
PWD    := $(shell pwd)

default:
    $(MAKE) -C $(KDIR) SUBDIRS=$(PWD) modules
    gcc -O2 -pipe dmx_usb_test.c -o dmx_usb_test

endif

clean:
    rm *.o *.ko
    rm dmx_usb_test

This is the error I get from the toolchain :

make -C dmxusb compile
make[4]: Entering directory `/home/vmware/Desktop/buildroot-ng/openwrt/package/dmxusb'
make -C /home/vmware/Desktop/buildroot-ng/openwrt/build_mipsel/dmxusb AR=mipsel-linux-uclibc-ar AS="mipsel-linux-uclibc-gcc -c -Os -pipe -mips32 -mtune=mips32 -funit-at-a-time" LD=mipsel-linux-uclibc-ld NM=mipsel-linux-uclibc-nm CC="mipsel-linux-uclibc-gcc" GCC="mipsel-linux-uclibc-gcc" CXX=mipsel-linux-uclibc-g++ RANLIB=mipsel-linux-uclibc-ranlib STRIP=mipsel-linux-uclibc-strip CROSS="mipsel-linux-uclibc-" EXTRA_CFLAGS="-Os -pipe -mips32 -mtune=mips32 -funit-at-a-time -I/home/vmware/Desktop/buildroot-ng/openwrt/staging_dir_mipsel/include -I/home/vmware/Desktop/buildroot-ng/openwrt/staging_dir_mipsel/usr/include" ARCH="mipsel" ;
make[5]: Entering directory `/home/vmware/Desktop/buildroot-ng/openwrt/build_mipsel/dmxusb'
make -C  SUBDIRS=/home/vmware/Desktop/buildroot-ng/openwrt/build_mipsel/dmxusb modules
make: Entering an unknown directory
make: *** SUBDIRS=/home/vmware/Desktop/buildroot-ng/openwrt/build_mipsel/dmxusb: No such file or directory.  Stop.
make: Leaving an unknown directory
make[5]: *** [default] Error 2
make[5]: Leaving directory `/home/vmware/Desktop/buildroot-ng/openwrt/build_mipsel/dmxusb'
make[4]: *** [/home/vmware/Desktop/buildroot-ng/openwrt/build_mipsel/dmxusb/.built] Error 2
make[4]: Leaving directory `/home/vmware/Desktop/buildroot-ng/openwrt/package/dmxusb'
make[3]: *** [dmxusb-compile] Error 2
make[3]: Leaving directory `/home/vmware/Desktop/buildroot-ng/openwrt/package'
make[2]: *** [compile] Error 2
make[2]: Leaving directory `/home/vmware/Desktop/buildroot-ng/openwrt/package'
make[1]: *** [package/compile] Error 2
make[1]: Leaving directory `/home/vmware/Desktop/buildroot-ng/openwrt'
make: *** [world] Error 2

So, it would appear I am having problems with paths.

The original Makefile want's a directory or object called modules and doesn't seem to find it.
Also, about the variable $(KERNELPATH), there is no mention of it in rules.mk, so I don't know where it came from. I can only find KERNEL_CROSS, LINUX_DIR and LINUX_HEADERS that could perhaps qualify.

Am I on the right track here?

Stanislas

(Last edited by stanelie on 14 Aug 2006, 19:23)

Ok, I narrowed it down a bit.

The problem seems to lie with the path to the kernel sources in the original makefile of my driver.

When I first downloaded the sources from the author, it was a hardcoded and looked like this :
KDIR    := /lib/modules/$(shell uname -r)/build

You made me change it to
KDIR    := $(KERNELPATH)
which didn't work.

I then tried to hardcode it too just to see if at least it would compile. So, I used this line :
KDIR    := /home/vmware/Desktop/buildroot-ng/openwrt/build_mipsel/linux-2.6-brcm/modules/lib/modules/2.6.17/build

That seemed to do the trick but now, make complains that it can't find some /arch/mipsel folder. I went to the /arch directory and there is only a /mips folder.

So, from what I understand, my real problem is telling make the right path to the kernel sources used in building my firmware image, and I don't seem to be able to do this on my own, newbie that I am.

anyone can help me with this?

Thanks again!

Stanislas

ok.

The path to kernel sources was the real problem with this build.

I ended up recompiling the kernel used in the buildroot-ng tree natively on the router (that took 10.5 hours to compile) and then point the Makefile of my driver to the new files compiled on the router itself.

It compiled without a hitch!

So, there seems to be a problem with cross compiling and kernel modules that need kernel sources.

But anyway, I have my driver now and I am happy.

Thanks for all the help!

Stanislas

stanelie wrote:

You made me change it to
KDIR    := $(KERNELPATH)
which didn't work.

No, read it again, I said $(LINUX_DIR)

I had already defined $(KERNELPATH) as $(LINUX_DIR) in the package's Makefile, I used $(KERNELPATH) in the driver's source Makefile.

Shouldn't that have worked?

Also, how can I have my module loaded automatically at system startup? I do a insmod <module_name> for now to load it, but there must be a proper way to do this.

Thanks!

Stanislas

The discussion might have continued from here.