[SOLVED] Makefile in Device Driver development

Status
Not open for further replies.

shaswat

Advanced Member level 4
Joined
Jul 2, 2013
Messages
115
Helped
1
Reputation
2
Reaction score
1
Trophy points
18
Visit site
Activity points
963
Here I work on my first device driver code. I simply start copying a code from LDD edition 3 and trying to execute the code using makefile. It should work but its not executing. First I think there would be some problem in my make command or it might be not updated. So I update my make command package but its still not working\. Everytime I execute the make command in terminal it shows
Code:
nothing to be done all
.
I searched on web but i found lots of commands to make a .ko file but nothing helps.

For simplicity here is my code

Code:
#include <linux/init.h>
#include <linux/module.h>
MODULE_LICENSE("Dual BSD/GPL");

static int hello_init(void)
{
 printk(KERN_ALERT "Hello, world\n");
 return 0;
}

static void hello_exit(void)
{
 printk(KERN_ALERT "Goodbye, cruel world\n");
}
module_init(hello_init);
module_exit(hello_exit);

and my Makefile code
Code:
obj-m += hello.o

all:
    make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules

clean:
    make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean

Any new idea would be really appreciated
 

I tried on shell
Code:
sudo make clean
but this time it shows "make: nothing to be done for 'clean' ".

One more thing that I am using virtual box. Is this error because of virtual box? I tried to run on other PC (ubuntu 12.04) and it works fine there.
 


If you are using space instead of tab, then try replacing the space with tab. Mostly this will solve your problem I guess.
 

If you are using space instead of tab, then try replacing the space with tab. Mostly this will solve your problem I guess.

I tried but again it shows "Nothing to be done for 'clean' ".
 

No need to worry about this issue as I found the problem and solved it myself.......

- - - Updated - - -

Do you have kernel sources or kernel headers present in /lib/modules/[kernel version]/build ?

No need to worry about this issue as I found the problem and solved it myself.......

- - - Updated - - -

Do you have kernel sources or kernel headers present in /lib/modules/[kernel version]/build ?

No need to worry about this issue as I found the problem and solved it myself.......
 

If you find the solution yourself, then it will be nice if you are posting it here because it can help others who are searching for similar errors.

The problem was in the Makefile. I just copied the code from the book
Code:
obj-m += hello.o

all:
    make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules

clean:
    make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean

The problem was that after ' all: ' "tab" button must be used instead of space. What I did was used space bar, that's why error pop ups. Just replacing the space with the tab button solves my problem

- - - Updated - - -


Other interesting thing that I found is , I used to print a message in my module_init & module_exit function. When I saw messages in my tty1, every-time before the message something shows that looks like [xxxx.xxxxxx]. what is that? That thing changes every time when I insert my module.
 

Status
Not open for further replies.

Similar threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…