ts-7000
[Top] [All Lists]

[ts-7000] Re: Compiling device driver module for the linux-2.6.21-ts ker

To:
Subject: [ts-7000] Re: Compiling device driver module for the linux-2.6.21-ts kernel
From: "Vijay" <>
Date: Mon, 23 Jun 2008 06:26:06 -0000
Well, this is for anybody who wastes a whole day because he did not
read/understand the differences between the 2.4 and 2.6 Makefile...

I finally got my graphic lcd module to build for the 2.6 kernel. I was
still trying to compile the driver in the old fashioned 2.4 way which
does not work. See all the issues I ran into below. Finally creating a
makefile as mentioned in LDD3 got me going. My module compiles fine
and I am able to insmod into the new 2.6 kernel. This is the makefile
I use now.

:~/proj/base/module/glcd$ cat Makefile

ifneq ($(KERNELRELEASE),)
        obj-m := module.o
        module-objs := glcd_base.o glcd.o
else
        KERNELDIR ?= /home/vijay/proj/base/kernel/linux-2.6.21-ts/
        PWD     := $(shell pwd)

default:
        $(MAKE) -C $(KERNELDIR) M=$(PWD) modules

endif

clean:
        rm -rf *.o core .*.cmd *.ko *.mod.c .tmp_versions



I still am not sure how to name my module anything other than module.o
I would rather have my module named glcd.o but that is one of the
files I already have (glcd.c)...

I am not sure how to provide a custom module name if one has multiple
files to compile one module. 

Thanks!
-Vijay


--- In  "Vijay" <> wrote:
>
> Thanks for the help Charlie.
> See my comments below. (tagged with [Vijay])
> 
> --- In  "charliem_1216" <charliem_1216@> wrote:
> >
> > Hi --
> > 
> > --- In  "Vijay" <osembedded@> wrote:
> > >
> > > Hi,
> > >  I am trying to compile/port a simple character device driver 
> > module
> > > that was previously built for the (ts) 2.4 kernel (and it runs 
> > fine).
> > > I have been able to install the gnu eabi cross tool chain and 
> > compile
> > > the 2.6.21 ts kernel.
> > > 
> > >  I used the following link as a guide.
> > > http://www.embeddedarm.com/software/arm-linux-26-ts72xx.php
> > > 
> > >  I edited my previously created Makefile to point to the new 
> > toolchain
> > > and the new kernel config/header files. But my build has been 
> > failing
> > > with the following errors.
> > > 
> > > :~/proj/base/module/glcd$ make
> > > /opt/crosstool/arm-none-linux-gnueabi/bin/arm-none-linux-gnueabi-gcc
> > > -D__KERNEL__ -DMODULE 
> > > -I/home/vijay/proj/base/kernel/linux-2.6.21-ts/include -O -Wall   -c
> > > -o glcd.o glcd.c
> > > In file included from
> > >
/home/vijay/proj/base/kernel/linux-2.6.21-ts/include/linux/bitops.h:9,
> > >                  from
> > >
>
/home/vijay/proj/base/kernel/linux-2.6.21-ts/include/linux/thread_info.h:20,
> > >                  from
> > >
> /home/vijay/proj/base/kernel/linux-2.6.21-ts/include/linux/preempt.h:9,
> > >                  from
> > >
>
/home/vijay/proj/base/kernel/linux-2.6.21-ts/include/linux/spinlock.h:49,
> > >                  from
> > >
/home/vijay/proj/base/kernel/linux-2.6.21-ts/include/linux/module.h:9,
> > >                  from glcd.c:24:
> > > /home/vijay/proj/base/kernel/linux-2.6.21-ts/include/asm/bitops.h: 
> > In
> > > function `____atomic_set_bit':
> > >
/home/vijay/proj/base/kernel/linux-2.6.21-ts/include/asm/bitops.h:40:
> > > warning: implicit declaration of function `local_irq_save'
> > >
/home/vijay/proj/base/kernel/linux-2.6.21-ts/include/asm/bitops.h:42:
> > > warning: implicit declaration of function `local_irq_restore'
> > 
> > Can you double check that the headers are from the correct kernel?  
> > My include/asm/bitops.h:40 refers to 'raw_local_irq_save', rather 
> > than 'local_irq_save'.
> > 
> [Vijay] I looked at my /asm/bitops.h:40 in the location mentioned
> above, i.e. 
> /home/vijay/proj/base/kernel/linux-2.6.21-ts/include/asm/bitops.h:40
> and I am surprised to find that the function (and file) there is no
> function named local_irq_restore. All I see on line 40 in that file is 
>   raw_local_irq_save(flags); 
> 
> but the compiler is giving an error for 'local_irq_save'... Something
> is wrong here. I am digging into this now to find why the different
names.
> 
> For reference, this is how that atomic_set_bit function of mine looks
> like. I am sure yours looks the same.
> 
> static inline void ____atomic_set_bit(unsigned int bit, volatile
> unsigned long *p)
> {
>         unsigned long flags;
>         unsigned long mask = 1UL << (bit & 31);
> 
>         p += bit >> 5;
> 
>         raw_local_irq_save(flags);
>         *p |= mask;
>         raw_local_irq_restore(flags);
> }
> 
> 
> 
> 
> > > In file included from
> > >
> /home/vijay/proj/base/kernel/linux-2.6.21-ts/include/linux/kobject.h:25,
> > >                  from
> > >
> /home/vijay/proj/base/kernel/linux-2.6.21-ts/include/linux/module.h:17,
> > >                  from glcd.c:24:
> > >
>
/home/vijay/proj/base/kernel/linux-2.6.21-ts/include/linux/rwsem.h:24:65:
> > > asm/rwsem.h: No such file or directory
> > 
> > Please just walk the include chain.  You can see that arch specific 
> > asm/rwsem.h is included if CONFIG_RWSEM_GENERIC_SPINLOCK is not 
> > defined.  Find out why that is not defined ... 
> > 
> > Oops, I see below you already looked into this.
> > 
> > Do you have include/asm symlinked to include/asm-arm?  Did you do 
> > a 'make mrproper' before or after?
> > 
> 
> [Vijay] I do have the include/asm folder symlinked to include/asm-arm
> 
> :~/proj/base/kernel/linux-2.6.21-ts/include$ ls -lh
> total 196K
> drwxr-xr-x  3 vijay admin 4.0K 2007-11-15 17:33 acpi
> lrwxrwxrwx  1 vijay admin    7 2008-06-20 23:53 asm -> asm-arm
> 
> My kernel config file (as I said before) sets the
> CONFIG_RWSEM_GENERIC_SPINLOCK to y. So, when the kernel was compiled I
> would imagine, it did the right 'thing'. But, in my out-of-tree
> module, I am doing something wrong in the (driver module) Make process
> and hence it doesn't see that CONFIG_RWSEM_GENERIC_SPINLOCK was set to
> y and so it is still trying to pull the <asm/rwsem.h> header file
> instead of pulling the <linux/rwsem-spinlock.h> file.
> 
> I think I did do a make mrproper before I compiled the kernel. But let
> me try it one more time. Typically what I have been doing is the
> following, (to build the kernel image)
> make mrproper
> make ts72xx_defconfig
> make menuconfig
> make
> 
> 
> 
> > > In file included from
> > >
> /home/vijay/proj/base/kernel/linux-2.6.21-ts/include/linux/module.h:17,
> > >                  from glcd.c:24:
> > >
/home/vijay/proj/base/kernel/linux-2.6.21-ts/include/linux/kobject.h:
> > > At top level:
> > >
>
/home/vijay/proj/base/kernel/linux-2.6.21-ts/include/linux/kobject.h:178:
> > > error: field `rwsem' has incomplete type
> > > In file included from
> > >
>
/home/vijay/proj/base/kernel/linux-2.6.21-ts/include/linux/memory_hotplug.h:7,
> > >                  from
> > >
> /home/vijay/proj/base/kernel/linux-2.6.21-ts/include/linux/mmzone.h:463,
> > >                  from
> > > /home/vijay/proj/base/kernel/linux-2.6.21-ts/include/linux/gfp.h:4,
> > >                  from
> > >
/home/vijay/proj/base/kernel/linux-2.6.21-ts/include/linux/slab.h:14,
> > >                  from
> > >
/home/vijay/proj/base/kernel/linux-2.6.21-ts/include/linux/percpu.h:5,
> > >                  from
> > >
>
/home/vijay/proj/base/kernel/linux-2.6.21-ts/include/asm-generic/local.h:4,
> > >                  from
> > > /home/vijay/proj/base/kernel/linux-2.6.21-ts/include/asm/local.h:1,
> > >                  from
> > >
> /home/vijay/proj/base/kernel/linux-2.6.21-ts/include/linux/module.h:19,
> > >                  from glcd.c:24:
> > >
>
/home/vijay/proj/base/kernel/linux-2.6.21-ts/include/linux/notifier.h:62:
> > > error: field `rwsem' has incomplete type
> > > In file included from
> > > /home/vijay/proj/base/kernel/linux-2.6.21-ts/include/linux/fs.h:359,
> > >                  from glcd.c:31:
> > >
> /home/vijay/proj/base/kernel/linux-2.6.21-ts/include/linux/quota.h:291: 
> > error:
> > > field `dqptr_sem' has incomplete type
> > > In file included from glcd.c:31:
> > > /home/vijay/proj/base/kernel/linux-2.6.21-ts/include/linux/fs.h:553:
> > > error: field `i_alloc_sem' has incomplete type
> > > In file included from glcd.c:31:
> > > /home/vijay/proj/base/kernel/linux-2.6.21-ts/include/linux/fs.h:917:
> > > error: field `s_umount' has incomplete type
> > > In file included from
> > >
/home/vijay/proj/base/kernel/linux-2.6.21-ts/include/linux/sched.h:51,
> > >                  from
> > >
/home/vijay/proj/base/kernel/linux-2.6.21-ts/include/asm/uaccess.h:14,
> > >                  from glcd.c:33:
> > >
>
/home/vijay/proj/base/kernel/linux-2.6.21-ts/include/linux/jiffies.h:33:3:
> > > #error You lose.
> > >
>
/home/vijay/proj/base/kernel/linux-2.6.21-ts/include/linux/jiffies.h:225:31:
> > > division by zero in #if
> > >
>
/home/vijay/proj/base/kernel/linux-2.6.21-ts/include/linux/jiffies.h:225:31:
> > > division by zero in #if
> > >
>
/home/vijay/proj/base/kernel/linux-2.6.21-ts/include/linux/jiffies.h:225:31:
> > > division by zero in #if
> > >
>
/home/vijay/proj/base/kernel/linux-2.6.21-ts/include/linux/jiffies.h:225:31:
> > > division by zero in #if
> > >
>
/home/vijay/proj/base/kernel/linux-2.6.21-ts/include/linux/jiffies.h:225:31:
> > > division by zero in #if
> > >
>
/home/vijay/proj/base/kernel/linux-2.6.21-ts/include/linux/jiffies.h:225:31:
> > > division by zero in #if
> > >
>
/home/vijay/proj/base/kernel/linux-2.6.21-ts/include/linux/jiffies.h:225:31:
> > > division by zero in #if
> > >
>
/home/vijay/proj/base/kernel/linux-2.6.21-ts/include/linux/jiffies.h:225:31:
> > > division by zero in #if
> > >
>
/home/vijay/proj/base/kernel/linux-2.6.21-ts/include/linux/jiffies.h:225:31:
> > > division by zero in #if
> > >
>
/home/vijay/proj/base/kernel/linux-2.6.21-ts/include/linux/jiffies.h:225:31:
> > > division by zero in #if
> > >
>
/home/vijay/proj/base/kernel/linux-2.6.21-ts/include/linux/jiffies.h:225:31:
> > > division by zero in #if
> > >
>
/home/vijay/proj/base/kernel/linux-2.6.21-ts/include/linux/jiffies.h:225:31:
> > > division by zero in #if
> > >
>
/home/vijay/proj/base/kernel/linux-2.6.21-ts/include/linux/jiffies.h:225:31:
> > > division by zero in #if
> > >
>
/home/vijay/proj/base/kernel/linux-2.6.21-ts/include/linux/jiffies.h:225:31:
> > > division by zero in #if
> > >
>
/home/vijay/proj/base/kernel/linux-2.6.21-ts/include/linux/jiffies.h:225:31:
> > > division by zero in #if
> > >
>
/home/vijay/proj/base/kernel/linux-2.6.21-ts/include/linux/jiffies.h:225:31:
> > > division by zero in #if
> > > In file included from
> > >
/home/vijay/proj/base/kernel/linux-2.6.21-ts/include/asm/uaccess.h:14,
> > >                  from glcd.c:33:
> > >
> /home/vijay/proj/base/kernel/linux-2.6.21-ts/include/linux/sched.h:326: 
> > error:
> > > field `mmap_sem' has incomplete type
> > > make: *** [glcd.o] Error 1
> > > 
> > > 
> > > The following is the makefile I tried to use.
> > >                                                                
     
> > >      
> > > ROOT_PATH=/home/vijay
> > > 
> > > 
> >
>
COMPILER_PATH=/opt/crosstool/arm-none-linux-gnueabi/bin/arm-none-linux-gnueabi-
> > > 
> > > CC=$(COMPILER_PATH)gcc
> > > LD=$(COMPILER_PATH)ld
> > > 
> > > INCLUDE_PATH=$(ROOT_PATH)/proj/base/kernel/linux-2.6.21-ts/include
> > > KERNEL_DIR=$(ROOT_PATH)/proj/base/kernel/linux-2.6.21-ts
> > > 
> > > include $(KERNEL_DIR)/.config
> > > 
> > > CFLAGS = -D__KERNEL__ -DMODULE  -I$(INCLUDE_PATH) -O -Wall
> > > 
> > > all:glcd.o glcd_base.o
> > >         $(LD) -r -o glcd glcd.o glcd_base.o
> > > 
> > > clean:
> > >         rm *.o glcd
> > > 
> > > 
> > > 2. Question on including the kernel .config file in the Makefile.
> > > 
> > > The following (see at the bottom) is an extract from the top 
> > portion
> > > of my kernel .config file. As you can see,
> > > CONFIG_RWSEM_GENERIC_SPINLOCK=y is turned ON. But still when 
> > compiling
> > > my code, when rwsem.h gets included (indirectly), it tries to pull 
> > in
> > > the <asm/rwsem.h> instead of the <linux/rwsem-spinlock.h> file. My
> > > make file did have the line "include $(KERNEL_DIR)/.config" which 
> > has
> > > CONFIG_RWSEM_GENERIC_SPINLOCK=y defined. So, I am not sure how the
> > > <asm/rwsem.h> file is being pulled in.
> > > 
> > > snip -- from include/linux/rwsem.h --
> > > #ifdef CONFIG_RWSEM_GENERIC_SPINLOCK
> > > #include <linux/rwsem-spinlock.h> /* use a generic implementation 
> > */
> > > #else
> > > #include <asm/rwsem.h> /* use an arch-specific implementation */
> > > #endif
> > > end snip -- from include/linux/rwsem.h --
> > > 
> > > 
> > > snip -- from .config file --
> > > #                                                              
     
> > >                                                                
     
> > >                  
> > > # Automatically generated make config: don't edit              
     
> > >                                                                
     
> > >                  
> > > # Linux kernel version: 2.6.21-ts                              
     
> > >                                                                
     
> > >                  
> > > # Fri Jun 20 23:53:04 2008                                     
     
> > >                                                                
     
> > >                  
> > > #                                                              
     
> > >                                                                
     
> > >                  
> > > CONFIG_ARM=y
> > > CONFIG_SYS_SUPPORTS_APM_EMULATION=y
> > > # CONFIG_GENERIC_GPIO is not set                               
     
> > >                                                                
     
> > >                  
> > > # CONFIG_GENERIC_TIME is not set                               
     
> > >                                                                
     
> > >                  
> > > CONFIG_MMU=y
> > > # CONFIG_NO_IOPORT is not set                                  
     
> > >                                                                
     
> > >                  
> > > CONFIG_GENERIC_HARDIRQS=y
> > > CONFIG_TRACE_IRQFLAGS_SUPPORT=y
> > > CONFIG_HARDIRQS_SW_RESEND=y
> > > CONFIG_GENERIC_IRQ_PROBE=y
> > > CONFIG_RWSEM_GENERIC_SPINLOCK=y
> > > # CONFIG_ARCH_HAS_ILOG2_U32 is not set                         
     
> > >                                                                
     
> > >                  
> > > # CONFIG_ARCH_HAS_ILOG2_U64 is not set                         
     
> > >                                                                
     
> > >                  
> > > CONFIG_GENERIC_HWEIGHT=y
> > > CONFIG_GENERIC_CALIBRATE_DELAY=y
> > > CONFIG_ZONE_DMA=y
> > > CONFIG_VECTORS_BASE=0xffff0000
> > > CONFIG_DEFCONFIG_LIST="/lib/modules/$UNAME_RELEASE/.config"
> > > 
> > > end snip -- from .config file --
> > > 
> > > I have tried to look through the mailing list before posting. But
> > > nothing comes close to the answer I need.
> > 
> > The method for compiling out-of-tree modules is very different for 
> > 2.6 than for 2.4.  The 3rd edition of the LDD book explains it quite 
> > well.  Both the second and third editions are also available on-line 
> > as well.
> > 
> > Regards. ............ Charlie
> 
> [Vijay] I am following the LDD3 currently. I may have missed a
> critical section in the book. I need to find out how to make the
> connection between the kernel .config file and the CFLAGS in my
> module's make file...
> 
> Thanks for the help once again. I will do some more digging and post
> back. In the mean time, if any of my comments above ring a bell, do
> let me know.
> 
> Thanks! 
> Vijay
> 
> > > 
> > > Thanks in advance for any help!
> > > -Vijay
> > >
> >
>



------------------------------------

Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/ts-7000/

<*> Your email settings:
    Individual Email | Traditional

<*> To change settings online go to:
    http://groups.yahoo.com/group/ts-7000/join
    (Yahoo! ID required)

<*> To change settings via email:
     
    

<*> To unsubscribe from this group, send an email to:
    

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/

<Prev in Thread] Current Thread [Next in Thread>
Admin

Disclaimer: Neither Andrew Taylor nor the University of NSW School of Computer and Engineering take any responsibility for the contents of this archive. It is purely a compilation of material sent by many people to the birding-aus mailing list. It has not been checked for accuracy nor its content verified in any way. If you wish to get material removed from the archive or have other queries about the archive e-mail Andrew Taylor at this address: andrewt@cse.unsw.EDU.AU