I can't create a driver in Ubuntu (iron beaver).

Makefile

# Makefile – makefile of our first driver # if KERNELRELEASE is defined, we've been invoked from the # kernel build system and can use its language. ifneq (${KERNELRELEASE},) obj-m := ofd.o # Otherwise we were called directly from the command line. # Invoke the kernel build system. else KERNEL_SOURCE := /lib/modules/4.15.0-47-generic/ PWD := $(shell pwd) default: ${MAKE} -C ${KERNEL_SOURCE} SUBDIRS=${PWD} modules clean: ${MAKE} -C ${KERNEL_SOURCE} SUBDIRS=${PWD} clean endif 

ofd.c / * ofd.c - Code of our first driver * / #include #include #include

 static int __init ofd_init(void) /* Конструктор */ { printk(KERN_INFO "dimon ^_^ : ofd registered"); return 0; } static void __exit ofd_exit(void) /* Деструктор*/ { printk(KERN_INFO "pumba ;_; : ofd unregistered"); } module_init(ofd_init); module_exit(ofd_exit); MODULE_LICENSE("GPL"); MODULE_AUTHOR("kaban <kaban@bk.ru>"); MODULE_DESCRIPTION("Moi perwii draiwer (Our First Driver)"); 

Got such a result enter image description here

I did everything under the article to write a pro-driver. I do not know why I did not: P


Corrected and added TABY.

 # Makefile – makefile of our first driver # if KERNELRELEASE is defined, we've been invoked from the # kernel build system and can use its language. ifneq (${KERNELRELEASE},) obj-m := ofd.o # Otherwise we were called directly from the command line. # Invoke the kernel build system. else KERNEL_SOURCE := /lib/modules/4.15.0-47-generic/ PWD := $(shell pwd) default: ${MAKE} -C ${KERNEL_SOURCE} SUBDIRS=${PWD} modules clean: ${MAKE} -C ${KERNEL_SOURCE} SUBDIRS=${PWD} clean endif 

Here is the conclusion that the computer gave me

 comp@comp0:~$ make make -C /lib/modules/4.15.0-47-generic/ SUBDIRS=/home/comp modules make[1]: вход в каталог «/lib/modules/4.15.0-47-generic» make[1]: *** Нет правила для сборки цели «modules». Останов. make[1]: выход из каталога «/lib/modules/4.15.0-47-generic» Makefile:13: recipe for target 'default' failed make: *** [default] Error 2 

Strange, it gives an error, although I have specified the correct kernel.

 comp@comp0:~$ uname -r 4.15.0-47-generic 
  • one
    In the Makefile indents should be made in one tab. If you have not (for example, instead of tabs spaces) - replace - andreymal

2 answers 2

At the beginning of the line with the recipe there should be a tab character .

you have only two such lines in the file (both begin with ${MAKE} ). check that the tab character is at the beginning, not the space.


in addition:

The first of the lines containing the recipe can be combined with the rule (see the link above), separated by a semicolon.

those. instead:

 цель: рецепт # здесь в начале строки — символ табуляции 

can write:

 цель: ; рецепт # здесь только пробелы, которые можно и убрать 

 make -C /lib/modules/4.15.0-47-generic/ SUBDIRS=/home/comp modules make[1]: вход в каталог «/lib/modules/4.15.0-47-generic» make[1]: *** Нет правила для сборки цели «modules». Останов. 

well, look in the directory where you are trying to execute the target modules : /lib/modules/4.15.0-47-generic/ . see there a file named [Mm]akefile or GNUmakefile ? I think no.

Perhaps in this directory there is a symlink with the name build or source (or something like that), which points to the correct directory (in which there is one of the listed files).

here and try to specify this path ( /lib/modules/4.15.0-47-generic/build/ ) instead of /lib/modules/4.15.0-47-generic/

  • Fixed but again the error - timob256
  • supplemented the answer. - aleksandr barakin
  • Yes, the Makefile was able to be in the /lib/modules/4.15.0-47-generic/build folder /lib/modules/4.15.0-47-generic/build In the Makefile I fixed the line on KERNEL_SOURCE := /lib/modules/4.15.0-47-generic/build - timob256

Remove spaces - use TABs instead.

  • Fixed but again the error - timob256
  • @ timob256, what? Show the output. - isnullxbh
  • drove make -e didn’t display how to look for the error (I didn’t find the log file either). - timob256
  • @ timob256, I see, you have already answered - sorry, I just got home. - isnullxbh pm