OpenWrt Forum Archive

Topic: How to use linux driver on OpenWrt

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

Hi there,

I  am trying to add an at86fr212b transceiver on my Rapsberry Pi using OpenWrt as os and I would like to know if it is possible to use a linux drivers : https://github.com/torvalds/linux/blob/ … t86rf230.c without rewriting most of it  ?

Thanks for your help !

Yes - one can create a kernel package. - see http://wiki.openwrt.org/doc/devel/packages section "Creating packages for kernel modules"

add to kernel/linux/modules/other.mk

define KernelPackage/ieee802154
  SUBMENU:=$(OTHER_MENU)
  TITLE:=ieee802154 support
  KCONFIG:=CONFIG_IEEE802154
  FILES:= $(LINUX_DIR)/drivers/net/ieee802154/ieee802154.ko
  AUTOLOAD:=$(call AutoProbe,ieee802154)
endef

define KernelPackage/ieee802154/description
 Kernel support for ieee802154 devices
endef

$(eval $(call KernelPackage,ieee802154))


define KernelPackage/mac802154
  SUBMENU:=$(OTHER_MENU)
  TITLE:=mac802154 support
  DEPENDS:=+kmod-ieee802154
  KCONFIG:=CONFIG_MAC802154
  FILES:= $(LINUX_DIR)/drivers/net/mac802154/mac802154.ko
  AUTOLOAD:=$(call AutoProbe,mac802154)
endef

define KernelPackage/mac802154/description
 Kernel support for mac802154 devices
endef

$(eval $(call KernelPackage,mac802154))



define KernelPackage/ieee802154-drivers
  SUBMENU:=$(OTHER_MENU)
  TITLE:=ieee802154 support
  DEPENDS:=+kmod-ieee802154
  KCONFIG:=CONFIG_IEEE802154_DRIVERS
endef

define KernelPackage/ieee802154-drivers/description
 Kernel support for ieee802154 drivers
endef

$(eval $(call KernelPackage,ieee802154-drivers))


define KernelPackage/wpan-at86rf230
  SUBMENU:=$(OTHER_MENU)
  TITLE:=wpan-at86rf230 support
  DEPENDS:=+kmod-ieee802154-drivers +kmod-mac802154
  KCONFIG:=CONFIG_IEEE802154_AT86RF230
  FILES:= $(LINUX_DIR)/drivers/net/ieee802154/at86rf230.ko
  AUTOLOAD:=$(call AutoProbe,at86rf230)
endef

define KernelPackage/wpan-at86rf230/description
 Kernel support for at86rf230/231/233/212 SPI 802.15.4 wireless
 controller.
endef

$(eval $(call KernelPackage,wpan-at86rf230))

you should get entries in the menuconfig that should build the original module

I dont know if this is working or if there is an error in the above code when compiled (check against the kernel kconfig/makefiles)  - atm I dont have time to test this and I dont have 802154 devices anyway
If you have a working/correct version post it again if you made changes or give feedback and I (or you) can get this into OpenWrt

(Last edited by zloop on 3 Apr 2015, 22:24)

Ok thank you for your answer zloop ! When I'll have a working version I'll post it !

newer version - this diff that tries to add 802.15.4 stuff / kernel modules

As before: totally not tested with real hardware

diff --git a/package/kernel/linux/modules/other.mk b/package/kernel/linux/modules/other.mk
index 3460a55..abaade2 100644
--- a/package/kernel/linux/modules/other.mk
+++ b/package/kernel/linux/modules/other.mk
@@ -71,13 +71,9 @@ $(eval $(call KernelPackage,bluetooth))
 define KernelPackage/bluetooth_6lowpan
   SUBMENU:=$(OTHER_MENU)
   TITLE:=Bluetooth 6LoWPAN support
-  DEPENDS:=+kmod-bluetooth @!LINUX_3_10 @!LINUX_3_14
-  KCONFIG:= \
-  CONFIG_6LOWPAN=m \
-  CONFIG_BT_6LOWPAN=m
-  FILES:= \
-       $(LINUX_DIR)/net/bluetooth/bluetooth_6lowpan.ko \
-       $(LINUX_DIR)/net/6lowpan/6lowpan.ko
+  DEPENDS:=+kmod-bluetooth +kmod-6lowpan @!LINUX_3_10 @!LINUX_3_14
+  KCONFIG:=CONFIG_BT_6LOWPAN
+  FILES:=$(LINUX_DIR)/net/bluetooth/bluetooth_6lowpan.ko
        AUTOLOAD:=$(call AutoProbe,bluetooth)
 endef
 
@@ -980,3 +976,141 @@ define KernelPackage/echo/description
 endef
 
 $(eval $(call KernelPackage,echo))
+
+
+define KernelPackage/ieee802154
+  SUBMENU:=$(OTHER_MENU)
+  TITLE:=ieee802154 support
+  KCONFIG:=CONFIG_IEEE802154
+  FILES:= $(LINUX_DIR)/net/ieee802154/ieee802154.ko \
+      $(LINUX_DIR)/net/ieee802154/af_802154.ko
+  AUTOLOAD:=$(call AutoProbe,ieee802154 af_802154)
+endef
+
+define KernelPackage/ieee802154/description
+ Kernel support for ieee802154 devices
+endef
+
+$(eval $(call KernelPackage,ieee802154))
+
+
+define KernelPackage/ieee802154-6lowpan
+  SUBMENU:=$(OTHER_MENU)
+  TITLE:=ieee802154-6lowpan support
+  KCONFIG:=CONFIG_IEEE802154_6LOWPAN
+  DEPENDS:=+kmod-ieee802154 +kmod-6lowpan
+  FILES:= $(LINUX_DIR)/net/ieee802154/ieee802154_6lowpan.ko
+  AUTOLOAD:=$(call AutoProbe,ieee802154_6lowpan)
+endef
+
+define KernelPackage/ieee802154-6lowpan/description
+ Kernel support for 6lowpan support over IEEE 802.15.4
+endef
+
+$(eval $(call KernelPackage,ieee802154-6lowpan))
+
+
+define KernelPackage/mac802154
+  SUBMENU:=$(OTHER_MENU)
+  TITLE:=mac802154 support
+  DEPENDS:=+kmod-ieee802154 +kmod-lib-crc-ccitt +kmod-crypto-aead
+  KCONFIG:=CONFIG_MAC802154
+  FILES:= $(LINUX_DIR)/net/mac802154/mac802154.ko
+  AUTOLOAD:=$(call AutoProbe,mac802154)
+endef
+
+define KernelPackage/mac802154/description
+ Kernel support for mac802154 devices
+endef
+
+$(eval $(call KernelPackage,mac802154))
+
+
+define KernelPackage/ieee802154-drivers
+  SUBMENU:=$(OTHER_MENU)
+  TITLE:=ieee802154 support
+  DEPENDS:=+kmod-ieee802154
+  KCONFIG:= \
+    CONFIG_IEEE802154_DRIVERS \
+    CONFIG_IEEE802154_FAKEHARD=n \
+    CONFIG_IEEE802154_FAKELB=n
+  AUTOLOAD:=$(call AutoProbe,ieee802154)
+endef
+
+define KernelPackage/ieee802154-drivers/description
+ Kernel support for ieee802154 drivers
+endef
+
+$(eval $(call KernelPackage,ieee802154-drivers))
+
+
+define KernelPackage/wpan-at86rf230
+  SUBMENU:=$(OTHER_MENU)
+  TITLE:=wpan-at86rf230 support
+  DEPENDS:=+kmod-ieee802154-drivers +kmod-mac802154 +kmod-regmap
+  KCONFIG:= \
+    CONFIG_IEEE802154_AT86RF230 \
+    CONFIG_SPI=y \
+    CONFIG_SPI_MASTER=y
+  FILES:= $(LINUX_DIR)/drivers/net/ieee802154/at86rf230.ko
+  AUTOLOAD:=$(call AutoProbe,at86rf230)
+endef
+
+define KernelPackage/wpan-at86rf230/description
+ Kernel support for at86rf230/231/233/212 SPI 802.15.4 wireless
+ controller.
+endef
+
+$(eval $(call KernelPackage,wpan-at86rf230))
+
+
+define KernelPackage/wpan-mrf24j40
+  SUBMENU:=$(OTHER_MENU)
+  TITLE:=wpan-mrf24j40 support
+  DEPENDS:=+kmod-ieee802154-drivers +kmod-mac802154
+  KCONFIG:= \
+    CONFIG_IEEE802154_MRF24J40 \
+    CONFIG_SPI=y
+  FILES:= $(LINUX_DIR)/drivers/net/ieee802154/mrf24j40.ko
+  AUTOLOAD:=$(call AutoProbe,mrf24j40)
+endef
+
+define KernelPackage/wpan-mrf24j40/description
+ Kernel support for MRF24J20 SPI 802.15.4 wireless controller.
+endef
+
+$(eval $(call KernelPackage,wpan-mrf24j40))
+
+
+define KernelPackage/wpan-cc2520
+  SUBMENU:=$(OTHER_MENU)
+  TITLE:=wpan-mrf24j40 support
+  DEPENDS:=+kmod-ieee802154-drivers +kmod-mac802154
+  KCONFIG:= \
+    CONFIG_IEEE802154_CC2520 \
+    CONFIG_SPI=y
+  FILES:= $(LINUX_DIR)/drivers/net/ieee802154/cc2520.ko
+  AUTOLOAD:=$(call AutoProbe,cc2520)
+endef
+
+define KernelPackage/wpan-cc2520/description
+ Kernel support for MRF24J20 SPI 802.15.4 wireless controller.
+endef
+
+$(eval $(call KernelPackage,wpan-cc2520))
+
+
+define KernelPackage/6lowpan
+  SUBMENU:=$(OTHER_MENU)
+  TITLE:=Bluetooth 6LoWPAN support
+  DEPENDS:=@!LINUX_3_10 @!LINUX_3_14
+  KCONFIG:=CONFIG_6LOWPAN
+  FILES:=$(LINUX_DIR)/net/6lowpan/6lowpan.ko
+  AUTOLOAD:=$(call AutoProbe,6lowpan)
+endef
+
+define KernelPackage/6lowpan/description
+ Kernel support for 6LoWPAN for Bluetooth Low Energy or 802.15.4 devices
+endef
+
+$(eval $(call KernelPackage,6lowpan))

(Last edited by zloop on 5 Apr 2015, 23:53)

zloop, why did you add kmod-bluetooth and kmod-bluetooth_6lowpan for the at86rf212b transceiver ? Is there a need for this module if I want to use 6Lowpan protocol with the at86rf212b ?

This is a patch file (wikipedia)- it adds code lines (begins with"+") and removes code lines ("-")

currently "6lowpan.ko" is only part of bluetooth module - according to Kernel documentation
6lowpan is used in Bluetooth AND 802.15.4 . So editing the kmod-bluetooth_6lowpan parts
make separation cleaner and is necessary.

I think I added all modules other 802.15.4 stuff that I could find to have 6Lowpan protocol with your device (or the other devices).
Please report if something is not working:
- missing dependencies
- missing Kernel modules / settings
- missing test tool/package

PS: you simply do "git apply <patch>" in your openwrt buildroot

(Last edited by zloop on 7 Apr 2015, 17:56)

Yes, actually I successfully applied this patch and compile openwrt with those new packages. But my question now is how to send messages using my transceiver. I guess, I have to configure my at86rf230 drivers to use spidev1.0 but when I try to create a .c file witch configure my driver interfaces, I can't access to my driver function because it's not declared in my project. Can you help me, because I think I am on the wrong way to make it works. Thanks !

Thanks for your help zloop. I just updated OpenWrt today and I noticed that there is a wpan file now which add all the module you included in your patch. But actually I tried to use the new wpan.mk file but I can't figure out why I can't find the new module included in the wpan file in the menuconfig list. Do you have any idea where the problem come from ? Is this problem just happened to me ?

I finally figured out that WPAN_MENU and WIRELESS_MENU are set to Wireless Drivers and maybe there is a conflict. There is also some packages which DEPENDS to LINUX@4.0  which is maybe no the kernel version on github for openwrt. So I removed LINUX@4.0 dependency but I'm not sure it's the right thing to do.

(Last edited by maxence8512 on 13 Apr 2015, 08:38)

The discussion might have continued from here.