Unable to create LKM for WGR614v9

4 posts / 0 new
Last post
Varuna
Varuna's picture
Unable to create LKM for WGR614v9

Hello all,

I am trying to create a loadable kernel module for the WGR614v9.  The setup is as follows:
        Netgear WGR614v9 router
        Source code: Netgear WGR614v9-V1.2.6_18.0.17WW using Linux kernel 2.4.20
        Tool chain: hnd-tools-3.2.3
        Tools: Telnetenable-0.3
        Development system: Fedora 8 kernel 2.6.26

Executing make on the code to build a loadable module, the following error is seen:
---------------------------------------------------------------------------
/home/varuna/safe_area/rtes/final_project/code/test_apps/mips32 > make
make -C /lib/modules/2.4.20/build SUBDIRS=/home/varuna/safe_area/rtes/final_project/code/test_apps/mips32 modules
make[1]: Entering directory `/home/varuna/safe_area/rtes/build/bcm5354_app_test/src/linux/linux'
make -C  /home/varuna/safe_area/rtes/final_project/code/test_apps/mips32 CFLAGS="-D__KERNEL__ -I/home/varuna/safe_area/rtes/build/bcm5354_app_test/src/linux/linux/include -Wall -Wstrict-prototypes -Wno-trigraphs -O2 -fno-strict-aliasing -fno-common -fomit-frame-pointer -I/home/varuna/safe_area/rtes/build/bcm5354_app_test/src/linux/linux/../../include -DBCMDRIVER -I /home/varuna/safe_area/rtes/build/bcm5354_app_test/src/linux/linux/include/asm/gcc -G 0 -mno-abicalls -fno-pic -pipe -mcpu=r4600 -mips2 -Wa,--trap  -m4710a0kern -DMODULE -mlong-calls -fno-common" MAKING_MODULES=1 modules
make[2]: Entering directory `/home/varuna/safe_area/rtes/final_project/code/test_apps/mips32'
make[2]: *** No rule to make target `modules'.  Stop.
make[2]: Leaving directory `/home/varuna/safe_area/rtes/final_project/code/test_apps/mips32'
make[1]: *** [_mod_/home/varuna/safe_area/rtes/final_project/code/test_apps/mips32] Error 2
make[1]: Leaving directory `/home/varuna/safe_area/rtes/build/bcm5354_app_test/src/linux/linux'
make: *** [default] Error 2
---------------------------------------------------------------------------

On the TOPDIR of the code, I have executed:
    make clean
    make dep
    make
    make modules_install

Executing the modules_install (as root) created the directory /lib/modules/2.4.20 that has the following:
---------------------------------------------------------------------------
/home/varuna/safe_area/rtes/build/bcm5354_app_test/src/linux/linux > ll /lib/modules/2.4.20/
total 40
drwxr-xr-x 4 4096 2010-01-28 19:29 .
drwxr-xr-x 6 4096 2010-01-28 18:25 ..
lrwxrwxrwx 1   66 2010-01-28 19:29 build -> /home/varuna/safe_area/rtes/build/bcm5354_app_test/src/linux/linux
drwxr-xr-x 4 4096 2010-01-28 19:29 kernel
drwxr-xr-x 2 4096 2010-01-28 18:25 pcmcia
---------------------------------------------------------------------------

The part in here is that the modules related info is not seen in the directory.  What have I or am I missing?

The Makefile that I am using is the following:
---------------------------------------------------------------------------
include .config
ARCH = mips

# Build platform
export BUILD := i386-pc-linux-gnu
export HOSTCC := gcc

# uClibc wrapper
ifeq ($(CONFIG_UCLIBC),y)
export PLATFORM := $(PLATFORM)-uclibc
endif

ifeq ($(PLATFORM),mipsel)
export CROSS_COMPILE := mipsel-linux-
export CONFIGURE := ./configure mipsel-linux --build=$(BUILD)
#export TOOLCHAIN := $(shell cd $(dir $(shell which $(CROSS_COMPILE)gcc))/../mips
endif

ifeq ($(PLATFORM),mipsel-uclibc)
export CROSS_COMPILE := mipsel-uclibc-
endif

ifeq ($(CONFIG_BCMWPA2),y)
export CFLAGS += -DBCMWPA2
endif

export CC := $(CROSS_COMPILE)gcc
export AR := $(CROSS_COMPILE)ar
export AS := $(CROSS_COMPILE)as
export LD := $(CROSS_COMPILE)ld
export NM := $(CROSS_COMPILE)nm
export RANLIB := $(CROSS_COMPILE)ranlib
export STRIP := $(CROSS_COMPILE)strip
export SIZE := $(CROSS_COMPILE)size
export OBJCOPY := $(CROSS_COMPILE)objcopy

obj-m   := wgr_proc_mod.o

KDIR    := /lib/modules/2.4.20/build
PWD := $(shell pwd)
default:
    clear
    $(MAKE) -C $(KDIR) SUBDIRS=$(PWD) modules
    rm -r -f .tmp_versions *.mod.c .*.cmd *.o *.symvers *.markers *.order

clean:
    rm -rf .tmp_versions *.mod.c .*.cmd *.o *.symvers *.markers *.order *.ko
---------------------------------------------------------------------------

Requesting help on how to build a loadable kernel module for the Netgear WGR614.

With regards,
Varuna

Brandon C
Brandon C's picture
Dude, I no nothing about a

Dude, I no nothing about a loadable kernel module but am curious as to what you are doing this for. IE, what's the benefit of creating this?

Varuna
Varuna's picture
BrandonC

BrandonC

The focus of experimentation on the WGR614 is part of my Masters degree course
wherein we have to develop a device driver on an x86 system, then, demonstrate
the porting of the device driver on to an Embedded System there after.

With regards,
Varuna

Varuna
Varuna's picture
Hello Folks,

Hello Folks,

The setup that I used has been:
        Netgear WGR614v9 router
        Source code: Netgear WGR614v9-V1.2.6_18.0.17WW
        Tool chain: hnd-tools-3.2.3
        Tools: Telnetenable-0.3, cscope, cflow
        Development system: Fedora 8 kernel 2.6.26

Here is how I solved the problem that I had faced with respect to LKM.  The
choice of code search tool is cscope & cflow.

1.  Get into the $(TOPDIR)/arch directory, and further into the kernel directory
    of the associated architecture of the Embedded System that you are
    developing the driver for.  For example, I am working on the MIPS
    architecture, hence I will be getting into $(TOPDIR)/arch/mips/kernel
    directory.

2.  Create the source code file that will contain the driver functions.

3.  Modify the $(TOPDIR)/arch/mips/kernel/Makefile and append the object file
    name of the device driver into the listed variables:
        export-objs
        obj-y

4.  Locate the .config file in the $(TOPDIR) of the code base.

5.  Identify the configuration variable, check if it has been set to y.  As an
    example I would like to add a /proc file for the driver, so I would search
    for CONFIG_PROC_FS in the .config.

6.  Search for the occurence of the pattern CONFIG_PROC_FS in the entire code
    base using cscope.

7.  You will find a listing of code under the $(TOPDIR)/kernel directory, get
    deep into the code, and figure out where you have to plug in the function
    call that will create the required /proc entries and when it should be
    called.  For example you cannot create a /proc fs entry prior to it being
    mounted by the init.

8.  Call the device driver functions from the identified file in the directory
    $(TOPDIR)/kernel under the section that has the #ifdef for CONFIG_PROC_FS.

9.  Do a top level build from $(TOPDIR) after cleaning the code base of the
    earlier built object files.

10. Check for the availability of the printk messages listed in the kernel
    image at $(TOPDIR)/vmlinux using strings command that is associated with
    the LKM.

11. Check for the availability of the driver functions listed in the file
    $(TOPDIR)/System.map using the grep command.  This file also gives you the
    address of the functions that will be mapped in the kernel.

The TOPDIR is the root location where the source code has been untared.

Now type in the following command at the shell prompt: info gpl

You will find the following that indicates:
       --------------------------
       NO WARRANTY

       11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WAR-
           RANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW.
           EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS
           AND/OR OTHER PARTIES PROVIDE THE PROGRAM ''AS IS'' WITHOUT WARRANTY
           OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIM-
           ITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
           A PARTICULAR PURPOSE.  THE ENTIRE RISK AS TO THE QUALITY AND PER-
           FORMANCE OF THE PROGRAM IS WITH YOU.  SHOULD THE PROGRAM PROVE
           DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR
           OR CORRECTION.
       --------------------------

This is very true in this written instructions on how to include your drivers
into a code base that is not complete in many respects.   Corrections / update /
opinions will be accepted with gratitude.

With best wishes,
Varuna