From the course: Linux Device Drivers: Reading, Writing, and Debugging

Unlock this course with a free trial

Join today to access over 25,500 courses taught by industry experts.

Writing a loadable kernel module

Writing a loadable kernel module

- [Instructor] Since many drivers are written as modules and you probably want to write your driver as a module, let's start looking at what the code needs to be. So in your code, you're going to have some includes, of course, for header files. And you'll typically have an init module function and an exit module function. And we can look at a little skeleton in a minute. The kernel source tree has lots of header files, so figuring out exactly which one you need might be a little bit of a challenge, but typically, when you write a driver, you try to find a driver as similar to the one you're writing as possible and use that as a template. With a module, you're probably going to want to include linux/module.h. Your module code should have an init module function. And you can kind of call it anything you want that's a legal name, but it'll be helpful for humans if you include init in the name and maybe a module and maybe the name of your driver or something like that. This function will…

Contents