OpenWrt Forum Archive

Topic: How to create openwrt driver?

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

I would like to know how to create a driver for openwrt from linux source code.

https://github.com/lourenssteyn/asic0x

This is where the source can be found.
It is a driver for Iburst USB and pcmcia modems.
I am still new to all things linux, but from what I understand it should be possible to make this driver work with openwrt.

This must be able to work because all the driver really is, is a USB to LAN adapter.
You then dial the connection over PPPOE

I have managed to setup build root and created custom firmware. It looks like I need to cross compile the driver.
I just need help with where to start to make this driver for openwrt.

You need to create a Makefile that will compile the code.

This seems to be a kernel module.

http://wiki.openwrt.org/doc/devel/packages
has a section about creating Kernel packages

Examples:
The directory "package/kernel" includes several examples how In-tree modules/drivers (in linux/modules)
and out of tree drivers are built (trelay seems to be the simplest on and possibly similar to your use-case).

My previous speaker is right, you should read the wiki first.
But here are instructions that should work:

Download and unpack the SDK for your System.
mkdir -p <SDK-path>/packages/kernel/lourenssteyn-asic0x
touch <SDK-path>/packages/kernel/lourenssteyn-asic0x/Makefile
and put the following code in it:

include $(TOPDIR)/rules.mk

PKG_NAME:=lourenssteyn_asic0x
PKG_VERSION:=2014.09.11
PKG_RELEASE:=1

PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.bz2
PKG_SOURCE_URL:=https://github.com/lourenssteyn/asic0x.git
PKG_SOURCE_SUBDIR:=$(PKG_NAME)-$(PKG_VERSION)
PKG_SOURCE_VERSION:=c99746677b75d23c80572ce99b893fb6e2ce01e0
PKG_SOURCE_PROTO:=git

PKG_MAINTAINER:=yourself


include $(INCLUDE_DIR)/kernel.mk
include $(INCLUDE_DIR)/package.mk



define KernelPackage/lourenssteyn_asic0x
  SUBMENU:=Your Submenu for asic0x in make manuconfig
  TITLE:=kernelmod asic0x
  DEPENDS:=
  FILES:=$(PKG_BUILD_DIR)/asic0x.ko
  #AUTOLOAD:=$(call AutoLoad,50,asic0x)
endef

define KernelPackage/lourenssteyn_asic0x/description
    The description of lourenssteyn_asic0x
endef



EXTRA_CFLAGS:= \
    $(patsubst CONFIG_%, -DCONFIG_%=1, $(patsubst %=m,%,$(filter %=m,$(EXTRA_KCONFIG)))) \
    $(patsubst CONFIG_%, -DCONFIG_%=1, $(patsubst %=y,%,$(filter %=y,$(EXTRA_KCONFIG)))) \



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

$(eval $(call KernelPackage,lourenssteyn_asic0x))

cd <SDK-path>
make

or better: make V=s
then you can see what going on.

you can run "make menuconfig" first then you can see the meaning of SUBMENU:=

If the module works enable AUTOLOAD:=.. in certain circumstances change the number on with position the modules load.
Make a better TITLE:=.. and description (short and good).
You can use PKG_RELEASE:=2 for distinction from my Makefile.

Thanks to everybody for your help.
This is what I am getting.
I am using 15rc3 SDK. Running on Mint 17

nitro@nitro-VirtualBox ~/openwrt/feeds/packages/iburst $ make
Makefile:1: /rules.mk: No such file or directory
Makefile:2: /kernel.mk: No such file or directory
Makefile:15: /package.mk: No such file or directory
make: *** No rule to make target `/package.mk'.  Stop.

nitro@nitro-VirtualBox ~/openwrt/feeds/packages/iburst $ make compile
Makefile:1: /rules.mk: No such file or directory
Makefile:2: /kernel.mk: No such file or directory
Makefile:15: /package.mk: No such file or directory
make: *** No rule to make target `/package.mk'.  Stop.
nitro@nitro-VirtualBox ~/openwrt/feeds/packages/iburst $


This is my Makefile.

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

PKG_NAME:=iburst-usb
PKG_VERSION:=1
PKG_RELEASE:=1

PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.bz2
PKG_SOURCE_URL:=file://$(TOPDIR)/home/nitro/openwrt/feeds/packages/iburst/src
PKG_SOURCE_SUBDIR:=$(PKG_NAME)-$(PKG_VERSION)
PKG_SOURCE_VERSION:=c99746677b75d23c80572ce99b893fb6e2ce01e0
PKG_SOURCE_PROTO:=git
PKG_MAINTAINER:=Nitrogen

include $(INCLUDE_DIR)/package.mk

define KernelPackage/iburst-usb
  SUBMENU:=Kernel modules
  TITLE:=Iburst USB Driver
  FILES:=$(PKG_BUILD_DIR)/asic0x.ko
  #AUTOLOAD:=$(call AutoLoad,50,asic0x,1)
endef

define KernelPackage/lourenssteyn_asic0x/description
    The description of lourenssteyn_asic0x
endef



EXTRA_CFLAGS:= \
    $(patsubst CONFIG_%, -DCONFIG_%=1, $(patsubst %=m,%,$(filter %=m,$(EXTRA_KCONFIG)))) \
    $(patsubst CONFIG_%, -DCONFIG_%=1, $(patsubst %=y,%,$(filter %=y,$(EXTRA_KCONFIG)))) \



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

$(eval $(call KernelPackage,iburst))

Not sure what I am doing wrong.
Sorry I am new to linux.
I am not new to Openwrt but usually use the provided packages.

Still learning I had not done this:

Build SDK

After Buildroot installation run configuration Choose your Target System and then
[x] Build the OpenWrt SDK

Nitrogen wrote:

I would like to know how to create a driver for openwrt from linux source code.

https://github.com/lourenssteyn/asic0x

This is where the source can be found.
It is a driver for Iburst USB and pcmcia modems.
I am still new to all things linux, but from what I understand it should be possible to make this driver work with openwrt.

This must be able to work because all the driver really is, is a USB to LAN adapter.
You then dial the connection over PPPOE

That driver looks like a really simple usbnet driver, which should be rather easy to get into mainline.  There are a few minor bugs (like using cpu_to_le16 in usb_control_msg args) and style issues (e.g. open coding instead of using is_broadcast_ether_addr helper) that will have to be fixed up, but I don't see why this couldn't be submitted for discussion on netdev+linux-usb as-is.

That would eventually make it easier to get into OpenWRT too, as it would be available as part of the kernel source code

Did you contact the author to hear about any plans for mainline?

First: run make always from SDK-root-path, this is the reason for your error message.


Second: there is somthing are wrong in your makefile.

this is wrong:

PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.bz2
PKG_SOURCE_URL:=file://$(TOPDIR)/home/nitro/openwrt/feeds/packages/iburst/src
PKG_SOURCE_SUBDIR:=$(PKG_NAME)-$(PKG_VERSION)
PKG_SOURCE_VERSION:=c99746677b75d23c80572ce99b893fb6e2ce01e0
PKG_SOURCE_PROTO:=git

because it mean the makeproces will do Something like:

git clone file://<SDK-path>/home/nitro/openwrt/feeds/packages/iburst/src $(PKG_NAME)-$(PKG_VERSION)
cd $(PKG_NAME)-$(PKG_VERSION)
git checkout c99746677b75d23c80572ce99b893fb6e2ce01e0
cd ..
tar -cjf $(PKG_NAME)-$(PKG_VERSION).tar.bz2 ./$(PKG_NAME)-$(PKG_VERSION)

I do not know my way around with feeds, so i do not use them to build my own packages.
But the source should normally in <SDK-path>/packages/kernel/iburst/src.

put this in the middle of your script:

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

This override the standart buildprocess for preparing and ensures that this: <SDK-path>/packages/kernel/iburst/src source will be used.

here a an example which the same situation.
I have wrote it for the spi-enc28j60 module:

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

PKG_NAME:=spi-enc28j60
PKG_RELEASE:=2

include $(INCLUDE_DIR)/package.mk

define KernelPackage/spi-enc28j60
  SUBMENU:=SPI Support
  TITLE:=SPI to Ethernet adapter enc28j60
  DEPENDS:=+kmod-spi-bcm2708
  FILES:=$(PKG_BUILD_DIR)/enc28j60.ko
  AUTOLOAD:=$(call AutoLoad,50,enc28j60)
endef

define KernelPackage/spi-enc28j60/description
 Kernel module for enc28j60 SPI to Ethernet adapter
endef

EXTRA_KCONFIG:= \
    CONFIG_ENC28J60=m \
    CONFIG_ENC28J60_WRITEVERIFY=y
    # i do not know what CONFIG_ENC28J60_WRITEVERIFY is good
    
EXTRA_CFLAGS:= \
    $(patsubst CONFIG_%, -DCONFIG_%=1, $(patsubst %=m,%,$(filter %=m,$(EXTRA_KCONFIG)))) \
    $(patsubst CONFIG_%, -DCONFIG_%=1, $(patsubst %=y,%,$(filter %=y,$(EXTRA_KCONFIG)))) \

MAKE_OPTS:= \
    ARCH="$(LINUX_KARCH)" \
    CROSS_COMPILE="$(TARGET_CROSS)" \
    SUBDIRS="$(PKG_BUILD_DIR)" \
    EXTRA_CFLAGS="$(EXTRA_CFLAGS)" \
    $(EXTRA_KCONFIG)

define Build/Prepare
    mkdir -p $(PKG_BUILD_DIR)
    # the source came from here $(LINUX_DIR)/drivers/net/ethernet/microchip/*
    $(CP) ./src/* $(PKG_BUILD_DIR)/
    $(Build/Patch)
endef

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

$(eval $(call KernelPackage,spi-enc28j60))

I think it is done big_smile

I setup a new make file copying from a makefile that existed already and it worked.
I still have to test it on a router but it is there in the make menuconfig menu!!!!
Thanks to everyone for your help.

This is the makefile that eventually worked.

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

PKG_NAME:=iburst-usb
PKG_VERSION:=1
PKG_RELEASE:=1

include $(INCLUDE_DIR)/package.mk

define KernelPackage/iburst-usb
  SUBMENU:=Network
  TITLE:=Iburst USB Driver
  FILES:=$(PKG_BUILD_DIR)/asic0x.ko
  AUTOLOAD:=$(call AutoLoad,50,asic0x,1)
  KCONFIG:=
endef

define KernelPackage/lourenssteyn_asic0x/description
    Kernal module for Iburst USB to Ethernet adapter
endef

EXTRA_KCONFIG:= \
    CONFIG_IBURST-USB=m

EXTRA_CFLAGS:= \
    $(patsubst CONFIG_%, -DCONFIG_%=1, $(patsubst %=m,%,$(filter %=m,$(EXTRA_KCONFIG)))) \
    $(patsubst CONFIG_%, -DCONFIG_%=1, $(patsubst %=y,%,$(filter %=y,$(EXTRA_KCONFIG)))) \

MAKE_OPTS:= \
    ARCH="$(LINUX_KARCH)" \
    CROSS_COMPILE="$(TARGET_CROSS)" \
    SUBDIRS="$(PKG_BUILD_DIR)" \
    EXTRA_CFLAGS="$(EXTRA_CFLAGS)" \
    $(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,iburst-usb))

No not done yet.
make -r world -j1 V=s

Package kmod-iburst-usb is missing dependencies for the following libraries:
usbcore.ko
make[3]: *** [/home/nitro/openwrt/bin/ar71xx/packages/base/kmod-iburst-usb_4.1.4+1-1_ar71xx.ipk] Error 1
make[3]: Leaving directory `/home/nitro/openwrt/package/iburst-usb'
make[2]: *** [package/iburst-usb/compile] Error 2
make[2]: Leaving directory `/home/nitro/openwrt'
make[1]: *** [/home/nitro/openwrt/staging_dir/target-mips_34kc_musl-1.1.10/stamp/.package_compile] Error 2
make[1]: Leaving directory `/home/nitro/openwrt'
make: *** [world] Error 2

I am not sure how to find the dependencies required.

Good question i thing the omniscient developers know something easy.
The ordinary foot soldiers have to guess.
I do not know, if existing a list of packages <-> including files.
But you need a kmod package and somthing with usb, for this reason use this on openwrt:

opkg update
opkg list | grep "kmod-usb.*"

and them i guess you should add this

DEPENDS:=+kmod-usb-core

in:

define KernelPackage/iburst-usb
....
endef
Plonk34 wrote:

Good question i thing the omniscient developers know something easy.
The ordinary foot soldiers have to guess.
I do not know, if existing a list of packages <-> including files.
But you need a kmod package and somthing with usb, for this reason use this on openwrt:

opkg update
opkg list | grep "kmod-usb.*"

and them i guess you should add this

DEPENDS:=+kmod-usb-core

in:

define KernelPackage/iburst-usb
....
endef

You'll probably want kmod-usb-net instead.  It will pull in the other usb dependecies.  And you will need the usbnet.ko module for this driver.

I don't know the proper way to figure out such things on OpenWRT, but looking at similar packages is one possible strategy.  You can find a number of them in package/kernel/linux/modules/usb.mk.

Or if you have a normal Linux system with the same driver, then you can use "modinfo -F depends <driver>" to look up the dependencies.  But you'll still have to figure out which OpenWRT packages are providing those dependencies.

Thanks Guys

DEPENDS:=+kmod-usb-core
Did work at first then it did not want to compile.
So I changed it to kmod-usb-net.
After that it compiled and worked.
The USB to LAN part came up with eth2 and now the modem lights up.
This to me is a success by its self but, it still wont dial.

dmesg

[ 1418.771934] usb 1-1: new full-speed USB device number 4 using ehci-platform
[ 1418.964238] usb 1-1: asic0x_bind UT04_ASIC02_MODEM type detected.
[ 1418.973761] asic0x 1-1:1.0 eth2: register 'asic0x' at usb-ehci-platform-1, iBurst Terminal, 00:c0:ee:0d:4c:55


 net_ratelimit: 14 callbacks suppressed
[ 1336.094248] asic0x 1-1:1.0 eth2: kevent 12 may have been dropped
[ 1336.100442] asic0x 1-1:1.0 eth2: kevent 12 may have been dropped
[ 1336.504865] asic0x 1-1:1.0 eth2: kevent 12 may have been dropped
[ 1336.509778] asic0x 1-1:1.0 eth2: kevent 12 may have been dropped
[ 1336.913197] asic0x 1-1:1.0 eth2: kevent 12 may have been dropped
[ 1336.917863] asic0x 1-1:1.0 eth2: kevent 12 may have been dropped
[ 1337.324282] asic0x 1-1:1.0 eth2: kevent 12 may have been dropped
[ 1337.328949] asic0x 1-1:1.0 eth2: kevent 12 may have been dropped
[ 1337.734181] asic0x 1-1:1.0 eth2: kevent 12 may have been dropped
[ 1337.738847] asic0x 1-1:1.0 eth2: kevent 12 may have been dropped

The usb light on the router flashes continually and produces:
asic0x 1-1:1.0 eth2: kevent 12 may have been dropped.

Any ideas as to what is the cause of this?

bmork wrote:
Nitrogen wrote:

I would like to know how to create a driver for openwrt from linux source code.

https://github.com/lourenssteyn/asic0x

This is where the source can be found.
It is a driver for Iburst USB and pcmcia modems.
I am still new to all things linux, but from what I understand it should be possible to make this driver work with openwrt.

This must be able to work because all the driver really is, is a USB to LAN adapter.
You then dial the connection over PPPOE

That driver looks like a really simple usbnet driver, which should be rather easy to get into mainline.  There are a few minor bugs (like using cpu_to_le16 in usb_control_msg args) and style issues (e.g. open coding instead of using is_broadcast_ether_addr helper) that will have to be fixed up, but I don't see why this couldn't be submitted for discussion on netdev+linux-usb as-is.

That would eventually make it easier to get into OpenWRT too, as it would be available as part of the kernel source code

Did you contact the author to hear about any plans for mainline?


I have contacted the author and he told me he got the iburst usb terminal to work on a MR3420 running the original firmware and OpenWRT but that was all he told me.
I am not sure why he has not taken it further after going to all the effort of creating the driver.

Just an update.

I got the driver working on OpenWRT 14.

I have tested the driver on a MR3220 and a WA701ND with a USB mod.

The discussion might have continued from here.