From the course: Linux Device Drivers

Unlock the full course today

Join today to access over 22,500 courses taught by industry experts or purchase this course individually.

Build and load a loadable module

Build and load a loadable module - Linux Tutorial

From the course: Linux Device Drivers

Start my 1-month free trial

Build and load a loadable module

- Now that we have some source code, how do we create a .ko file? Let's take a look. We'll see, we want to use a makefile. The Linux kernel source tree uses makefiles and we're going to use a makefile too. So we'll look at building or compiling a module and then we'll review inserting that module. So you want a makefile to compile your C code into a .ko. And a key part of your makefile is using a macro called obj-m, m for module. When you compile your code, you're going to use the kernel makefile and your makefile. When the kernel makefile uses your makefile, it's going to look for the value of obj-m. That macro will have in it the list of object files to make into .ko files. And it knows how to make an object file from C file. So you're not going to have to specify that part. Making a module from a single C file is really easy. Making a model for multiple C files is a little bit more complicated. Let's take a look…

Contents