[Click] Experiences with cross compiling kernel module for mipsel

Jens Mueller jmueller at informatik.hu-berlin.de
Wed Jun 13 08:14:42 EDT 2007


Hi,

recently I tried cross compiling the click kernel module (latest CVS)
for mipsel. I discovered some problems, but my solution is a bit
awkward. I'm going to step you through my building and fixing process to
get some feedback.  I'm using kamikaze from OpenWRT for cross compiling.
I downloaded the Linux kernel 2.6.19.2 and applied the click patch. To
build the kernel I ran:

$ PATH=/home/jkm/tmp/kamikaze/staging_dir_mipsel/bin:$PATH make
ARCH=mips CROSS_COMPILE=mipsel-linux-

Next I configured click:

$ ARCH=mips PATH=/home/jkm/tmp/kamikaze/staging_dir_mipsel/bin:$PATH
./configure --host=mipsel-linux --enable-linuxmodule
--with-linux=/home/jkm/linux-2.6.19.2/ --enable-tools=host
--disable-userlevel

I found out that adding ARCH=mips is important, otherwise configure
will fail, because the wrong kernel header files are used.

$ ARCH=mips PATH=/home/jkm/tmp/kamikaze/staging_dir_mipsel/bin:$PATH
make linuxmodule

failed. I suppose this is due to wrongly used g++, gcc and ld. So the
configure process has still some problems. That's why I changed into
directory linuxmodule/ and ran

$ ARCH=mips PATH=/home/jkm/tmp/kamikaze/staging_dir_mipsel/bin:$PATH
make CXX=mipsel-linux-g++ CC=mipsel-linux-gcc LD=mipsel-linux-ld

Some functions (atomic_set_mask, atomic_clear_mask) weren't defined in
asm-mips/atomic.h. I copied them from asm-sh/atomic.h. See attached
patch. But I suppose the kernel should look at asm-sh/atomic.h itself?

During linking the click module there is an undefined symbol named ffs.
That's why I changed some macros in integers.hh and integers.cc. See the
attached patch. But I don't know whether this is the right way to go. I
doubt it.
The module can't be loaded. You get 'module click: relocation overflow'.
I added '-mlong-calls' in linuxmodule/Makefile.in to fix this. See
also the attached patch.

I appreciate any feedback. I hope my changes show some problems and
somebody has a way to fix them more accurately.

Kind regards,
Jens
-------------- next part --------------
diff -Nur /tmp/linux-2.6.19.2/include/asm-mips/atomic.h linux-2.6.19.2/include/asm-mips/atomic.h
--- /tmp/linux-2.6.19.2/include/asm-mips/atomic.h	2007-01-10 20:10:37.000000000 +0100
+++ linux-2.6.19.2/include/asm-mips/atomic.h	2007-06-13 13:32:36.000000000 +0200
@@ -48,6 +48,32 @@
 #define atomic_set(v,i)		((v)->counter = (i))
 
 /*
+ * copied from asm-sh/atomic.h - jkm 2005-10-18
+ *
+ */
+static __inline__ void atomic_clear_mask(unsigned int mask, atomic_t *v)
+{
+        unsigned long flags;
+
+        local_irq_save(flags);
+        *(long *)v &= ~mask;
+        local_irq_restore(flags);
+}
+
+/*
+ * copied from asm-sh/atomic.h - jkm 2005-10-18
+ *
+ */
+static __inline__ void atomic_set_mask(unsigned int mask, atomic_t *v)
+{
+        unsigned long flags;
+
+        local_irq_save(flags);
+        *(long *)v |= mask;
+        local_irq_restore(flags);
+}
+
+/*
  * atomic_add - add integer to atomic variable
  * @i: integer value to add
  * @v: pointer of type atomic_t
-------------- next part --------------
? .cdtproject
? .project
? config.mk
? foo.patch
? installch
? elements/events
? elements/events_old
? etc/pkg-config.mk
? linuxmodule/.tmp_versions
? linuxmodule/Module.symvers
? linuxmodule/build.sh
Index: include/click/integers.hh
===================================================================
RCS file: /cvs/click/release/one/include/click/integers.hh,v
retrieving revision 1.11
diff -r1.11 integers.hh
26c26
< #if HAVE___BUILTIN_CLZ
---
> #if HAVE___BUILTIN_CLZ && !CLICK_LINUXMODULE
52c52
< #if HAVE___BUILTIN_FFS
---
> #if HAVE___BUILTIN_FFS && !CLICK_LINUXMODULE
56,59d55
< #elif HAVE_FFS
< inline int ffs_lsb(uint32_t x) {
<     return ffs(x);
< }
Index: lib/integers.cc
===================================================================
RCS file: /cvs/click/release/one/lib/integers.cc,v
retrieving revision 1.15
diff -r1.15 integers.cc
27c27
< #if !HAVE___BUILTIN_CLZ
---
> #if !HAVE___BUILTIN_CLZ || CLICK_LINUXMODULE
69c69
< #if !HAVE___BUILTIN_FFS && !HAVE_FFS
---
> #if !HAVE___BUILTIN_FFS && !HAVE_FFS || CLICK_LINUXMODULE
Index: linuxmodule/Makefile.in
===================================================================
RCS file: /cvs/click/release/one/linuxmodule/Makefile.in,v
retrieving revision 1.110
diff -r1.110 Makefile.in
91a92,94
> ifeq ($(ARCH), mips)
> CLICKCFLAGS += -mlong-calls
> endif
92a96,98
> ifeq ($(ARCH), mips)
> CLICKCXXFLAGS += -mlong-calls
> endif


More information about the click mailing list