Ayush joshi
Ayush joshi

Reputation: 325

Error in make file for device driver Hello world

I have simple code with device driver hello world with a make file.it was executed well in case of 12.04 LTS but recently i have upgrade my ubuntu to 14.04 after this the same program not able to compiled. with error message on

make

make -C /lib/modules/3.13.0-45-generic/build M= modules
make[1]: Entering directory `/usr/src/linux-headers-3.13.0-45-generic'
make[2]: *** No rule to make target `/usr/src/linux-headers-3.13.0-45-generic/arch/x86/syscalls/syscall_32.tbl', needed by `arch/x86/syscalls/../include/generated/uapi/asm/unistd_32.h'.  Stop.
make[1]: *** [archheaders] Error 2
make[1]: Leaving directory `/usr/src/linux-headers-3.13.0-45-generic'
make: *** [all] Error 2

Thanks in advance......

Upvotes: 1

Views: 2685

Answers (2)

Dilip Kumar
Dilip Kumar

Reputation: 1746

your make file does't work for other versions of the kernel since the kernel library modules will be in /lib/modules/kernelversion/build.

so you should use make -C /lib/modules/"should be the current running kernel"/build

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

Which will automatically loads the current running kernel version using "shell uname -r".

Sample makefile

KERNELDIR := /lib/modules/$(shell uname -r)/build
CLEANFILE := *.dis *.o *.ko *.mod.* *.symvers *.*.old
obj-m := hello.o

    default:
            make -C $(KERNELDIR)  M=$(CURDIR) modules

    clean:
            rm -f $(CLEANFILE) 

Upvotes: 5

Surajeet Bharati
Surajeet Bharati

Reputation: 1433

You are expected to post the content of your Makefile in your question. Anyways, I think, there is some problem in your Makefile. Instead of specifying the kernel version as 3.13.0-45-generic , you should write $(shell uname -r) so that it can dynamically get the currently running kernel version. With upgrading ubuntu, your kernel version changed. So, it's not working anymore.

Create you Makefile as follows provided your device driver program file name is hello.c

obj-m += hello.o
all:
    make -C /lib/modules/$(shell uname -r)/build M=$(CURDIR) modules
clean:
    make -C /lib/modules/$(shell uname -r)/build M=$(CURDIR) clean

The execution of 'make' command starts by changing its directory to the one provided with the -C option that is /lib/modules/$(shell uname -r)/build which is your kernel source directory and The M= option causes that makefile to move back into your module source directory as CURDIR(current directory) is always set to current working directory.

Reply if it's still not working. This pdf can help you as a quick reference if you are beginner in this field. And if you want to become an expert in linux device driver programming in future, follow This Book. It's worth reading.

Upvotes: 1

Related Questions