OpenWrt Forum Archive

Topic: Howto cross compile labjack u3 driver, library and examples

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

The labjack u3 is a usb device with a linux kernel 2.6 driver.  I am in no way associated with labjack other than being a customer.  Here is a product link: http://www.labjack.com/labjack_u3.php

I did not have any luck using the device with a Netgear WGT634U (labjack did not power up).  However, I do have it working with an Asus WLHDD running a 2.6 kernel.

Here is a brief summary of what I did:
- started with a fresh Debian distro on a virtual machine
- followed OpenWRT build instructions, ie: get build software, svn checkout latest kamikaze trunk
- selected target brcm947xx [2.6] and usb support in make menuconfig
- ran make
- copied the labjack driver (Linux_C_NativeUSB_U3U9/U3) into build_dir/linux-brcm47xx/linux-2.6.23.1/drivers/labjack (I know this is not ideal)
- added obj-m += labjack/ to build_dir/linux-brcm47xx/linux-2.6.23.1/drivers/Makefile (again, I know this is not ideal)
- ran make again
- installed the firmware onto the router, and copied the labjacku3.ko files to it via scp (also usbcore.ko and ohci-hcd.ko but that's because I lied about when I toggled on usb support)
- added staging_dir/toolchain-mipsel_gcc4.1.2/bin to my PATH
- modified liblabjack and the labjack example Makefiles to include:
CROSS=mipsel-linux-uclibc-
CC=$(CROSS)gcc
LD=$(CROSS)ld
AR=$(CROSS)ar
RANLIB=$(CROSS)ranlib
- make'd those, and copied binaries to router
- loaded driver, mounted usbfs, made dev device, ran example:

root@OpenWrt:~/u3# insmod /lib/modules/2.6.23.1/usbcore.ko
root@OpenWrt:~/u3# insmod /lib/modules/2.6.23.1/ohci-hcd.ko
root@OpenWrt:~/u3# insmod /lib/modules/2.6.23.1/labjacku3.ko
root@OpenWrt:~/u3# mount -t usbfs none /proc/bus/usb
root@OpenWrt:~/u3# mkdir /dev/usb
root@OpenWrt:~/u3# mknod -m=a=rw /dev/usb/labjacku3_0 c 180 208
root@OpenWrt:~/u3# LD_LIBRARY_PATH=. ./u3Easy
Calling eDAC to set DAC0 to 2.1 V

Calling eAIN to read voltage from AIN3
AIN3 value = 0.405

Calling eDO to set FIO3 to output-high

Calling eDI to read the state of FIO2
FIO2 state = 1

Calling eTCConfig to enable and configure 1 output timer (Timer0) and 1 input timer (Timer1), and enable counter0

Waiting for 1 second...

Calling eTCValues to read and reset the input Timer1 and Counter0, and update the value (duty-cycle) of the output Timer0
Timer1 value = 0
Counter0 value = 0

Calling eTCConfig to disable all timers and counters


update: with a powered usb hub I have the Labjack working on both a WGT634U and WL500W.

(Last edited by matthewhandau on 30 Jan 2008, 10:31)

Hi,

I try to compile the Labjack U3 driver to work with Asus WL500gP V2 router. I did exactly how it was instructed, but when making the Kamikaze errors occur. Maybe my makefile or something like that is wrong.
My development environment is Fedora Core 11 (I'm need it to some other projects). I have downloaded the latest version of Kamikaze from SVN. And also have the latest Linux driver from Labjack's support page.

Labjack works with my Fedora Core laptop.

Please can you tell me what the Labjack's Makefile should exactly be like. I'm not so familiar with cross-compiling, this project was just thrown at me.
- Matti

Usually hacking Makefiles is undesirable, as parameters such as CC, LD, AR and RANLIB should be allowed to be overridden from the command line or a parent Makefile.  But Labjack specify CC in their Makefile and we need to use mipsel-linux-uclibc-gcc instead of gcc.  Of course the procedure I describe here is unfit for adopting software into the OpenWrt software repository.  Having said that, let's hack the Makefile...

You could just hack the offending CC line but that's not how I roll.  Instead I'll override it and include a comment.  Makefiles read from top to bottom so be sure to specify the new CC afterwards not before, ie:

CFLAGS=-Wall -g
CC=gcc $(CFLAGS)
LDFLAGS=
LIBS=-lm -llabjackusb

# cross compile kludge
CROSS=mipsel-linux-uclibc-
CC=$(CROSS)gcc
LD=$(CROSS)ld
AR=$(CROSS)ar
RANLIB=$(CROSS)ranlib

Defining LD, AR and RANLIB is not so important for the driver because it does not compile any libs.  But I just specify all 4 and copy from the driver Makefile to library Makefiles and example app Makefiles.

And of course this presumes you have mipsel-linux-uclibc-gcc in your PATH.  My steps here specify a relative directory but we really need an absolute.  My path is /home/matthewh/kamikaze-labjack/staging_dir/toolchain-mipsel_gcc4.1.2/bin, and the relevant gcc binaries are there.  Yours will be different.  Once set correctly you should be able to run mipsel-linux-uclibc-gcc.  Of course if we were doing things the proper way (creating an OpenWrt package) this step would be done for us. 

I suspect your issues are resolved with these two things.  If not, email me the errors or anything else relevant and I'll check it out.

edit: Re-reading your question it sounds like you are unable to build the latest version of kamikaze before applying any labjack specific hacks.  I'm not that active with OpenWrt and I don't use Fedora so you might have better luck creating or replying to an existing thread if the build documentation doesn't work under Fedora.

(Last edited by matthewhandau on 10 Sep 2009, 07:06)

Thanks for those instructions, they helped me to understand a little bit more about cross-compiling.
I was able to build latest 8.09 version of Kamikaze, with USB support. And it works in my Asus. I also used your instructions, and I think that I also compile the Labjack driver, when I run make in ../drivers/labjack folder. It make .o file and also a.out file. I'm not so familiar with these.
In first message you instruct to add obj-m += labjack to ../drivers folder Makefile. Is that correct with the latest version of Kamikaze, because all the other are marked like subdir-$ += ... I modified the Makefile couple of different ways, but Kamikaze make won't make the Labjack driver. Or should run make in labjack folder, and then run make to whole Kamikaze? Not so familiar with these.

Here is the drivers Makefile

#
# Makefile for the Linux kernel device drivers.
#
# 15 Sep 2000, Christoph Hellwig <hch@infradead.org>
# Rewritten to use lists instead of if-statements.
#


mod-subdirs :=    dio hil mtd sbus video macintosh usb input telephony ide \
        message/i2o message/fusion scsi md ieee1394 pnp isdn atm \
        fc4 net/hamradio i2c acpi bluetooth usb/gadget

subdir-y :=    parport char block net sound misc media cdrom hotplug labjack
subdir-m :=    $(subdir-y)


subdir-$(CONFIG_DIO)        += dio
subdir-$(CONFIG_PCI)        += pci
subdir-$(CONFIG_GSC)        += gsc
subdir-$(CONFIG_HIL)        += hil
subdir-$(CONFIG_PCMCIA)        += pcmcia
subdir-$(CONFIG_MTD)        += mtd
subdir-$(CONFIG_SBUS)        += sbus
subdir-$(CONFIG_ZORRO)        += zorro
subdir-$(CONFIG_NUBUS)        += nubus
subdir-$(CONFIG_TC)        += tc
subdir-$(CONFIG_VT)        += video
subdir-$(CONFIG_MAC)        += macintosh
subdir-$(CONFIG_PPC32)        += macintosh
subdir-$(CONFIG_USB)        += usb
subdir-$(CONFIG_USB_GADGET)    += usb/gadget
subdir-$(CONFIG_INPUT)        += input
subdir-$(CONFIG_PHONE)        += telephony
subdir-$(CONFIG_IDE)        += ide
subdir-$(CONFIG_SCSI)        += scsi
subdir-$(CONFIG_I2O)        += message/i2o
subdir-$(CONFIG_FUSION)        += message/fusion
subdir-$(CONFIG_MD)        += md
subdir-$(CONFIG_IEEE1394)    += ieee1394
subdir-$(CONFIG_PNP)        += pnp
subdir-$(CONFIG_ISDN)        += isdn
subdir-$(CONFIG_ATM)        += atm
subdir-$(CONFIG_FC4)        += fc4
subdir-m            += labjack
# CONFIG_HAMRADIO can be set without CONFIG_NETDEVICE being set  -- ch
subdir-$(CONFIG_HAMRADIO)    += net/hamradio
subdir-$(CONFIG_I2C)        += i2c
subdir-$(CONFIG_ACPI_BOOT)    += acpi

subdir-$(CONFIG_BLUEZ)        += bluetooth

include $(TOPDIR)/Rules.make

And the Labjack Makefile

#
# Makefile for liblabjackusb
#
#


# cross compile kludge
CROSS=mipsel-linux-uclibc-
CC=$(CROSS)gcc
LD=$(CROSS)ld
AR=$(CROSS)ar
RANLIB=$(CROSS)ranlib
TARGET = liblabjackusb.so.2.0.1
# DESTINATION = /usr/local/lib
# CFLAGS = -fPIC -g -Wall


CFLAGS=-Wall -g
CC=gcc $(CFLAGS)
LDFLAGS=
LIBS=-lm -llabjackusb
# LIBFLAGS = -lusb-1.0 -lc




%.o: %.c
    $(CC) $(CFLAGS) -c $<

all: $(TARGET)

$(TARGET): labjackusb.o
    #$(CC) -shared -Wl,-soname,liblabjackusb.so -o $(TARGET) labjackusb.o $(LIBFLAGS) 
    $(CC) -shared -Wl,-soname, labjackusb.o $(LIBFLAGS) 



clean:
    rm -f $(TARGET) *.o *~

Can you make something out of these two, what am I doing wrong?

- Matti

According to the LabJack download page the Linux C driver is no longer a kernel module and instead uses libusb.  This means kernel hacking is no longer required. 

But you will need libusb. And libusb is already disitributed with OpenWrt.  So perhaps now is the time to port liblabjack the-OpenWrt-way, as described here https://forum.openwrt.org/viewtopic.php?pid=31794.  This involves creating the file kamikaze/package/liblabjack/Makefile.  I knocked together this Makefile but it seems to be missing something:

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

include $(TOPDIR)/rules.mk

PKG_NAME:=liblabjack
PKG_VERSION:=2.0.0
PKG_RELEASE:=1

PKG_SOURCE:=Linux_C_NativeUSB.zip
PKG_SOURCE_URL:=http://labjack.com/sites/default/files/software/2009/07/
PKG_MD5SUM:=de437142698358b94ddcf62e4100748f

include $(INCLUDE_DIR)/package.mk

define Package/liblabjack
  SECTION:=libs
  CATEGORY:=Libraries
  TITLE:=Labjack USB device library
  URL:=http://labjack.com/
  DEPENDS:=+libusb
endef

define Package/liblabjack/description
 This package contains a system-independent library for user-level Labjack 
 acccess.
endef

define Build/Prepare
    mv $(PKG_BUILD_DIR)/../Linux_C_NativeUSB/liblabjackusb/* $(PKG_BUILD_DIR)/
endef

define Build/Compile
    $(MAKE) -C $(PKG_BUILD_DIR) \
        CC="$(TARGET_CC)" \
        DESTDIR="$(PKG_INSTALL_DIR)" \
        HOST_CPU="$(ARCH)" \
        all
endef

define Package/liblabjack/install
    $(INSTALL_DIR) $(1)/usr/lib
    $(CP) \
        $(PKG_INSTALL_DIR)/usr/lib/liblabjack*.so* \
        $(1)/usr/lib/
endef

$(eval $(call BuildPackage,liblabjack))

I might come back to this later and figure out what's wrong.  If you or anyone else figures it out be sure to post back here.

(Last edited by matthewhandau on 17 Sep 2009, 01:11)

The discussion might have continued from here.