4

I'm developing a device driver for embedded linux(ARM). How can I compile the KO file generated as a part of the kernel, in a way that the module will be loaded in boot ?

this is the first time I need to compile the driver into the kernel and not as a loadable module. so I'm not sure how to do it.

Thanks, Ramon.

stdcall
  • 27,613
  • 18
  • 81
  • 125
  • Are you building outside of the kernel tree, as documented in chapter 2 of [Linux Device Drivers 3ed](http://lwn.net/Kernel/LDD3/)? Unless you must have a statically linked driver, you could look at modprobe to automatically load your module at boot, see: `modprobe(8)` and `modprobe.conf(5)` man pages. – Marc Butler Aug 10 '11 at 21:19
  • I'm building inside a kernel tree. I don't want to load it as a module using a script, I want it to be static with the kernel, like other supported drivers (such as USB, ETHERNET) – stdcall Aug 10 '11 at 23:05

2 Answers2

2

For your first question, I assume that you want to build your driver statically into the kernel image(not as a module). First, you select a directory in drivers directory where you want to put your driver files. Assume you want to put your files in drivers/char/. Copy your files into this directory. There will be a Kconfig file in the drivers/char/ directory, open it and add an entry like this in the before the endmenu.

config MYDRIVER
    bool "This is a driver for something"
    default n
    help
      This is a test driver.

Save the file and open Makefile in the same directory. Goto end of the file and add the following entry.

     obj-$(CONFIG_MYDRIVER)            += mydriver.o

That's it you have added the file to the kernel tree. Now, as usual, do make menuconfig and select MYDRIVER.

See this Kernel Compilation article for more info.

agf
  • 171,228
  • 44
  • 289
  • 238
rulingminds
  • 176
  • 1
  • Note that the link is to the poster's own site (though it appears to be a good article). – agf Aug 11 '11 at 21:00
  • 1
    The "Kernel Compilcation article" link is now some other page. Is there an updated link available? – Rich Oct 23 '12 at 13:07
1

You need to build your device driver as a built-in. You can either edit your kernel .config file manually and change "=m" to "=y" for the CONFIG option that belongs to your module, or use make menuconfig to change <M> to <*> for your device driver.

before -> <M> Your Device Driver Name Here
after  -> <*> Your Device Driver Name Here
Jason Young
  • 441
  • 3
  • 6
  • That's what I though, but I didn't knew if this was the way to do it. – stdcall Aug 10 '11 at 23:06
  • Another small question... If I managed to static link the module to the kernel, can I know in which order it's initialized (before and after which modules...) ? – stdcall Aug 10 '11 at 23:07
  • http://stackoverflow.com/questions/5669647/linux-order-of-statically-linked-module-loading/5679670#5679670 seems relevant to your question. In short, the module init order is determined by 1) the linking order of the modules when the kernel is built and 2) the type of initcall used for the module (see inlude/linux/init.h). – Jason Young Aug 10 '11 at 23:35