PDA

View Full Version : How to implement a Makefile to do the module device driver ?



mark2219
2nd May 2006, 08:06 AM
Now I try to implement a Makefile which can do the module device driver in Core 4.
The driver GPIO function was implemented in the kernel 2.4.25; now had updated to the Core 4. But I don't know how to use the command parameters to compile the code.
Please tell me what I should do. If there is any sample Makefile, it is better for me.

jcliburn
3rd May 2006, 01:58 AM
This is for another driver (a pcmcia driver, in particular), but the process should be about the same.

cd to the directory you wish to download the 39MB source rpm file.


# wget http://download.fedora.redhat.com/pub/fedora/linux/core/updates/4/SRPMS/kernel-2.6.14-1.1656_FC4.src.rpm
# rpm -Uvh kernel-2.6.14-1.1656_FC4.src.rpm
# cd /usr/src/redhat/SPECS
# rpmbuild -bp --target $(arch) kernel-2.6.spec
# cd /usr/src/redhat/BUILD/kernel-2.6.14/linux-2.6.14/drivers/pcmcia
# cp /path/to/patch_file_name.diff .

Make sure your driver source code is here.


# patch -b < patch_file_name.diff
# mv Makefile Makefile.orig
# gedit Makefile


Edit Makefile so it looks like this.



obj-m := driver_name.o

KDIR := /lib/modules/$(shell uname -r)/build
PWD := $(shell pwd)

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


IMPORTANT: The whitespace preceding $(MAKE) *MUST* be a tab, not spaces.

Now compile your driver, copy it to the pcmcia directory, and tell the kernel to start using it.


# make
# cp driver_name.ko /lib/modules/`uname -r`/kernel/drivers/pcmcia/
# modprobe driver_name

mark2219
3rd May 2006, 02:35 AM
This is for another driver (a pcmcia driver, in particular), but the process should be about the same.

cd to the directory you wish to download the 39MB source rpm file.


# wget http://download.fedora.redhat.com/pub/fedora/linux/core/updates/4/SRPMS/kernel-2.6.14-1.1656_FC4.src.rpm
# rpm -Uvh kernel-2.6.14-1.1656_FC4.src.rpm
# cd /usr/src/redhat/SPECS
# rpmbuild -bp --target $(arch) kernel-2.6.spec
# cd /usr/src/redhat/BUILD/kernel-2.6.14/linux-2.6.14/drivers/pcmcia
# cp /path/to/patch_file_name.diff .

Make sure your driver source code is here.


# patch -b < patch_file_name.diff
# mv Makefile Makefile.orig
# gedit Makefile


Edit Makefile so it looks like this.



obj-m := driver_name.o

KDIR := /lib/modules/$(shell uname -r)/build
PWD := $(shell pwd)

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


IMPORTANT: The whitespace preceding $(MAKE) *MUST* be a tab, not spaces.

Now compile your driver, copy it to the pcmcia directory, and tell the kernel to start using it.


# make
# cp driver_name.ko /lib/modules/`uname -r`/kernel/drivers/pcmcia/
# modprobe driver_name





---------------------------
Thanks a lot. I got it and work well.

mark2219
3rd May 2006, 02:36 AM
Thanks a lot. I got it and work well.

jcliburn
3rd May 2006, 02:41 AM
Thanks a lot. I got it and work well.
You're welcome. Glad you got it working.