1

I have working kernel module which I install manually with insmod/modprobe command as learnt by reading book. however I was wondering if there is way to do it automatically after compiling - So basically how to automate insmod/modprobe command ?

My modprobe has a dependent file thread_module.o as well

My make file so far

obj-m := wakeup_counter.o
obj-m += thread_module.o
$INSTALL_MOD_PATH = /lib/modules/2.6.32-5-amd64/

all:
    make -C /lib/modules/2.6.32-5-amd64/build M=$(PWD) modules

install:
    make $(INSTALL_MOD_PATH) =/build modules_install
clean:
    make -C /lib/modules/2.6.32-5-amd64/build M=$(PWD) modules

output after running : make install

root@xyz:/home/xyz/Desktop/Drivers/symbols# make install
make -C /lib/modules/2.6.32-5-amd64/build M=/home/xyz/Desktop/Drivers/symbols modules_install
make[1]: Entering directory `/usr/src/linux-headers-2.6.32-5-amd64'
  INSTALL /home/xyz/Desktop/Drivers/symbols/thread_module.ko
  INSTALL /home/xyz/Desktop/Drivers/symbols/wakeup_counter.ko
  DEPMOD  2.6.32-5-amd64
make[1]: Leaving directory `/usr/src/linux-headers-2.6.32-5-amd64'

Edit: After going through comments and https://www.kernel.org/doc/Documentation/kbuild/modules.txt I tried to add install command but I dont see any modules in the build path - Also at high level I get what we write in cmd prompt we type in Makefile but if someone can give an example it would help me to understand with nice base case to refer.

4

2 回答 2

1
obj-m := wakeup_counter.o
obj-m += thread_module.o

KDIR = /lib/modules/2.6.32-5-amd64/build

all:
    make -C $(KDIR) M=$(PWD) modules_install

clean:
    make -C $(KDIR) M=$(PWD) clean

Example of command shell instruction being used as rule in Makefile:

install:
    modprobe wakeup_counter
    modprobe thread_module
于 2015-11-05T07:22:20.180 回答
1

Enhancing the answer posted by @cm161 for future users to highlight exact steps which worked for me

With below Makefile use following steps

Step 1: make ( type just make command) - for creation of modules i.e. .ko files and associated files

Step 2: make install

Step 3 : now do lsmod you should be able to see new modules

obj-m := wakeup_counter.o
obj-m += thread_module.o

KDIR = /lib/modules/2.6.32-5-amd64/build

all:
    make -C $(KDIR) M=$(PWD) modules
    cp wakeup_counter.ko /lib/modules/2.6.32-5-amd64/
    cp thread_module.ko /lib/modules/2.6.32-5-amd64/

install:
    modprobe wakeup_counter
    modprobe thread_module

clean:
    make -C $(KDIR) M=$(PWD) clean
于 2015-11-05T08:43:31.707 回答