Our Contribution to OpenSource         

Unable to create LKM for NETGEAR WGR614v9
Author: Varuna E.


I was trying to create a loadable kernel module for the NETGEAR 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/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


The TOPDIR is the root location where the source code has been extracted using tar, and on the TOPDIR of the code, I had executed:
make clean
make dep
make
make modules_install


Executing the modules_install (as root) created the directory /lib/modules/2.4.20 having 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 was used was 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 *.markersv*.order
clean:
rm -rf .tmp_versions *.mod.c .*.cmd *.o *.symvers *.markers *.order *.ko


BIG QUESTION: how to build a loadable kernel module for the NETGEAR WGR614v9?

After a lot of testing, breaking the code, understanding it – this is how it was SOLVED using the code search tools  cscope & cflow.  Following are the steps that were followed:

Step 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.

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

Step 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

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

Step 5:
Identify the configuration variable, check if it has been set to y.  As an example I would like to add a /procCONFIG_PROC_FS in the .config.

Step 6:
Search for the occurrence of the pattern CONFIG_PROC_FS in the entire code base using cscope.

Step 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.

Step 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.

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

Step 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.

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


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.


<< back     

Your feedback is warmly appreciated and we look forward to  Hear you at feedback at eudaemonicsystems dot net  or online at http://feedback.eudaemonicsystems.net


Simple, Specific & Insightful