OpenWrt Forum Archive

Topic: Anyone have a external kernel module development example that works?

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

I have been working for 3 days trying to port a simple device driver to Openwrt (Kamikaze 8.09) for a WRTSL54GS with, at best, no luck at all.

First I have found that despite the glowing words in the documentation and wiki as to how easy it is (and they contradict each other), I find that it is anything but.

I have one source module and one makefile which exist outside the kamikaze directories.

I have included a mine.mk file in the package/kernel/module directory (discovering that nuance was a trip!) 

After much effort I can see the package listed in Kernel modules in menuconfig which I select with an "M".

When I make, nothing happens with  my kernel module, no compile, no errors, nothing other than some indeciferable stuff and an .ipk file with nothing in it.  The makefile works outside the kamikaze make.  Just to be sure I've even put errors in the source code, and kamikaze make never compiles it.

As far as I can tell I have followed the doc, such as it is.

One curious thing is that the package used in the doc example (i2c-gpio-custom) doesn't show up at all in memuconfig as far as I can tell so I'm really not sure how one would select it.  I followed that garden path for a day.

I've been doing this kind of stuff for 45 years and this is something else.

Oh yes, I do understand that programmers generally don't like to write doc but a simple step by step cookbook would be nice.

Anyone got any help?

Regards,
Jim

(Last edited by obrienj on 26 Apr 2009, 22:05)

If the source module isn't too complex, you could try to take one existing external module's makefile and adapt it to yours. Take a look at the broadcom-diag module in package/broadcom-diag. I sucessfully used it as a template to compile a selfwritten module (a simple one to read some mips-registers).

KanjiMonster,

Thanks for the suggestion. 

I tried that with the i2c-gpio-custom (I think that's the name) and it didn't show up in menuconfig but maybe it'snot supposed to as the one I used as a pattern didn't show up either.  It's an external kernel modusle like I want to build.  The problem is that many of the packages that come with Openwrt are somewhat integrated at the build system level and that buildsystems seems to have morphed between releases.

Short of a cookbook, I may just reset and try again and this time climb down inside the hidden stuff and force it to work.

Too bad, Openwrt is a great piece of work and making it easy to expand and enhance would be a great attribute if it was in fact easy.

Regards,
Jim

obrienj,

I certainly sympathize and agree with your assessment and also wish there were a cookbook.  I can't help you with your problem, but regarding "i2c-gpio-custom" not appearing after you tried to build it externally, did you try searching with "/" in menuconfig?  I may be missing your point, since you were trying to build it as a test preview for building your own module, but there is a "kmod-i2c-gpio-custom" under "Kernel modules", "I2C support".  I find the "/" search very helpful in finding items in this complex hierarchy.

Hi, this is my simply external kernel package build as test. I hope this help you. Roberto

1)cd 8.09/package -> mkdir zprova;
2)cd  zprova -> mkdir src;
3)nano Makefile (*);
4)cd src -> nano zprova.c;
5) nano Makefile (**);

/*  zprova.c - The simplest kernel module.
 */
#include <linux/module.h>  /* Needed by all modules */
#include <linux/kernel.h>  /* Needed for KERN_ALERT */


int init_module(void)
{
   printk("<1>Hello world 1.\n");
    
   // A non 0 return means init_module failed; module can't be loaded.
   return 0;
}


void cleanup_module(void)
{
  printk(KERN_ALERT "Goodbye world 1.\n");
}

Makefile *

#
# Copyright (C) 2008 OpenWrt.org
#
# This is free software, licensed under the GNU General Public License v2.
# See /LICENSE for more information.
#

include $(TOPDIR)/rules.mk
include $(INCLUDE_DIR)/kernel.mk

PKG_NAME:=zprova
PKG_RELEASE:=2

include $(INCLUDE_DIR)/package.mk

define KernelPackage/zprova
  SUBMENU:=I2C support
  TITLE:=plutp
  FILES:=$(PKG_BUILD_DIR)/zprova.$(LINUX_KMOD_SUFFIX)
  KCONFIG:=
endef

define KernelPackage/zprova/description
 Provaaaaaaaaaa.
endef

EXTRA_KCONFIG:= \
    

EXTRA_CFLAGS:= \

MAKE_OPTS:= \
    ARCH="$(LINUX_KARCH)" \
    CROSS_COMPILE="$(TARGET_CROSS)" \
    SUBDIRS="$(PKG_BUILD_DIR)" \
    EXTRA_CFLAGS="$(EXTRA_CFLAGS)" \
    LINUXINCLUDE="-I$(LINUX_DIR)/include -include linux/autoconf.h" \
    $(EXTRA_KCONFIG)

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

define Build/Compile
    $(MAKE) -C "$(LINUX_DIR)" \
        $(MAKE_OPTS) \
        modules
endef

$(eval $(call KernelPackage,zprova))

Makefile **

obj-m   := zprova.o
ifeq ($(MAKING_MODULES),1)
-include $(TOPDIR)/Rules.make
endif

6) make menuconfig
7) you find the package in section ‘I2C support’. Enable the package
8) make
9) you find it in bin/package/mips

(Last edited by roberto99 on 27 Apr 2009, 07:05)

roberto99,

Thank your for your very clear and simple example.  Unfortunately, I get an error when running "make menuconfig":

:~/kamikaze$ make menuconfig
Collecting package info: package/zprovaERROR: please fix package/zprova/Makefile

Below is ~/kamikaze/package/zprova/Makefile (unchanged from yours). 

#
# Copyright (C) 2008 OpenWrt.org
#
# This is free software, licensed under the GNU
General Public License v2.
# See /LICENSE for more information.
#

include $(TOPDIR)/rules.mk
include $(INCLUDE_DIR)/kernel.mk

PKG_NAME:=zprova
PKG_RELEASE:=2

include $(INCLUDE_DIR)/package.mk

define KernelPackage/zprova
  SUBMENU:=I2C support
  TITLE:=plutp
  FILES:=$(PKG_BUILD_DIR)/zprova.$(LINUX_KMOD_SUFFIX)
  KCONFIG:=
endef

define KernelPackage/zprova/description
 Provaaaaaaaaaa.
endef

EXTRA_KCONFIG:= \

EXTRA_CFLAGS:= \

MAKE_OPTS:= \
    ARCH="$(LINUX_KARCH)" \
    CROSS_COMPILE="$(TARGET_CROSS)" \
    SUBDIRS="$(PKG_BUILD_DIR)" \
    EXTRA_CFLAGS="$(EXTRA_CFLAGS)" \
    LINUXINCLUDE="-I$(LINUX_DIR)/include -include linux/autoconf.h" \
    $(EXTRA_KCONFIG)

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

define Build/Compile
    $(MAKE) -C "$(LINUX_DIR)" \
        $(MAKE_OPTS) \
        modules
endef

$(eval $(call KernelPackage,zprova))

Here are the files in the directory chain:

x@Ubun1:~/kamikaze/package/zprova$ ls
Makefile  src
x@Ubun1:~/kamikaze/package/zprova$ cd src
x@Ubun1:~/kamikaze/package/zprova/src$ ls
Makefile  zprova.c

Note: I created this build setup 2 days ago with "svn co svn://svn.openwrt.org/openwrt/trunk ~/kamikaze".  What do I need to do to fix this?

(Last edited by lizby on 27 Apr 2009, 19:58)

I'm a very neebie about this world.
I can suggest you to get a copy of development environment from svp://svp.openwrt.org/openwrt/branches/8.09

1) Make menuconfig
2) Select target atheros 231/x5312
3) Make

Tell me if it works! Ciao

Ach, I don't know about svp.  What's the difference between "svp://svp.openwrt.org/openwrt/branches/8.09" and "svn co svn://svn.openwrt.org/openwrt/trunk ~/kamikaze" (which seems other than this to be working for me)?  My target, if it makes a difference, is ipx4xx, NSLU2.

Roberto99,

Brilliant!!!

Other than a small mess-up when I copied and pasted one of the make files to gedit, it works great.

Please see if you can get this simple  and easy to follow sample included as a HowTo.

Many thanks.

I'm now onto building and testing my device driver - another world of pain.

Regards,
Jim

Glad to have you helped.
I'm working around a device driver i2c with some Interrupt.

Please give me news in future about your work.

Ciao, Roberto.

Roberto99,

I'm working on porting a driver for an X10 device, the CM15A, which attaches via USB but has some specific requirements that require a specialized driver.

I will keep you posted of my work.

With your recent help, I can now focus on the real issues and not on the build process.

Again, thanks.

Regards,
Jim

(Last edited by obrienj on 28 Apr 2009, 00:01)

obrienj wrote:

Roberto99,

I'm working on porting a driver for an X10 device, the CM15A, which attaches via USB but has some specific requirements that require a specialized driver.

I will keep you posted of my work.

With your recent help, I can now focus on the real issues and not on the build process.

Again, thanks.

Regards,
Jim

Do you have any news about the cm15a driver?

regards,
Helder

The CM15A driver works with Kamikaze 8.09 on a WRTSL54GS (the only device I built for).

I also have MisterHouse running on the WRTSL54GS using the CM15A.

I am just into test mode but have not yet encountered a major issue.

The driver is an unchanged version of one I found on the web for Linux.

I use the latest Debian running on a VMWare virtual machine to do the builds and I followed the info on the OpenWRT web site.

It did take a while to sort through all the various bits of information and a big help from Roberto in providing a sample Makefile.

Jim

obrienj wrote:

The CM15A driver works with Kamikaze 8.09 on a WRTSL54GS (the only device I built for).

I also have MisterHouse running on the WRTSL54GS using the CM15A.

I am just into test mode but have not yet encountered a major issue.

The driver is an unchanged version of one I found on the web for Linux.

I use the latest Debian running on a VMWare virtual machine to do the builds and I followed the info on the OpenWRT web site.

It did take a while to sort through all the various bits of information and a big help from Roberto in providing a sample Makefile.

Jim

It is possible for you to share the Makefile, so i can try and compile it to my Asus 500GPV2

regards,
Helder

I will try to get to that this evening. 

Jim

obrienj wrote:

I will try to get to that this evening. 

Jim

thanks,

regards,
Helder

Here are working openwrt and source makefiles for the x10 USB transceiver driver from http://lemaymd.com/files/x10-cm19a-0.1.1.tar.bz2

I changed the directory structure found in the source tarball (above), removing all subdirs found there, and creating a new subdir called "src" that contains only the files license, README, AUTHORS, a modified Makefile,  and the x10-cm19a.c file.  I did that to simplify debugging, and because I have no use for the xmms tools and test suite.

To use the tarball, untar it, and from the x10-cm19a dir, delete the test and tools directories and create the "src" directory, then move all the files in the drivers/usb/comm/  directory to src.  Then delete the drivers directory recursively.  Rename or delete the original Makefile in src and replace it with the modified source Makefile listed below.  You _MUST_ use tabs, not spaces, in both Makefiles, so your cut and paste will likely be trouble until you fix any tab conversions caused by the cut and paste.  If the line begins with whitespace, it's a tab.  You'll know you have spaces when the make fails with the error report 'Makefile:#: *** missing separator', where # is the offending line number in the makefile.  Look closely at the path reported by the error to ascertain which makefile has spaces.

See the original tarball for usage of the driver (I've not fully tested it yet, but I have succeeded in building the ipkg without error).

I have used the Ubiquiti Routerstation source (an SVN R15349 copy of Openwrt with patches) to build the firmware for the routerstation.  This is set up as a directory containing the openwrt tree source, so one can descend to the openwrt directory and do a make menuconfig as usual to build openwrt (the x10-cm19a module appears in the utilities submenu of menuconfig).  However, the Ubiquiti system will apply it's own .config (the file openwrt-routerstation-r####/config/rs  where #### is the ubiquiti release number) and overwrite any .config you might make with the openwrt menuconfig-you can hand edit the rs file to revise most software to the routerstation, but this module (x10-cm19a) will be offered as a prompt when you make the routerstation, so no hand editing of the rs file is required for it, instead, simply select the module with an "m" when prompted to include it for the routerstation after you invoke "make V=99" in the openwrt-routerstation-r#### directory.  Regular openwrt users will just use the standard menuconfig and makemethods.

I'll be testing the module soon, but it is the original source so it should work fine.


===source Makefile===
obj-m   := x10-cm19a.o
ifeq ($(MAKING_MODULES),1)
-include $(TOPDIR)/Rules.make
endif
===EOF source Makefile

===Openwrt package Makefile ===
#
# Copyright (C) 2009 WS. Herrick
#
# This software is licensed under the GNU General Public License v2.
# See /LICENSE for more information.
#
include $(TOPDIR)/rules.mk
include $(INCLUDE_DIR)/kernel.mk

PKG_NAME:=x10-cm19a
PKG_VERSION:=0.1.1
PKG_RELEASE:=1
###PKG_BUILD_DIR:=$(KERNEL_BUILD_DIR)/x10-cm19a-$(PKG_VERSION)
####PKG_BUILD_DIR:=$(BUILD_DIR)/x10-cm19a-$(PKG_VERSION)
###PKG_SOURCE:=x10-cm19a-$(PKG_VERSION).tar.bz2
###PKG_SOURCE_URL:=http://lemaymd.com/files/
###PKG_MD5SUM:=9e7ee0feb8315163eda60538729addb6

include $(INCLUDE_DIR)/package.mk

define KernelPackage/x10-cm19a
    TITLE:=X10-CM19A support
    SECTION:=utils
    CATEGORY:=Utilities
    FILES:=$(PKG_BUILD_DIR)/x10-cm19a.$(LINUX_KMOD_SUFFIX)
    AUTOLOAD:=$(call AutoLoad,50,x10-cm19a)
endef

define Package/x10-cm19a/description
    Kernel module for X10 CM19a USB controller
endef

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

define Build/Compile
    $(MAKE) -C $(LINUX_DIR) \
        CROSS_COMPILE="$(TARGET_CROSS)" \
        ARCH="$(LINUX_KARCH)" \
        SUBDIRS="$(PKG_BUILD_DIR)" \
        KERNELDIR=$(LINUX_DIR) \
        CC="$(TARGET_CC)" \
        modules
endef

$(eval $(call KernelPackage,x10-cm19a))

===EOF openwrt package Makefile ===


The Openwrt package Makefile was tediously exacting to construct, but ultimately, an examination of the included package siit's Makefile prevailed.  Most other examples were inappropriate or flawed. 

good luck,

p0g0

I forgot to mention that the tarball should be in the openwrt/package directory, as is standard.  In my case, building for the routerstation, that is:  /usr/src/openwrt-routerstation-r1665/openwrt/package/x10-cm19a-0.1.1

The cm19a module tests OK and works with the makefiles I listed above.

The discussion might have continued from here.