Skip to content

johnnylord/drivers

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Linux Kernel Driver Programming

This repo is for my own self-study about linux kernel driver programming. In the following sections, I record what I learned and what I did, and save some useful material for future references.

Documents to read before get your hands dirty

Environment setup

Whenever you trying to develop kernel module, make sure you are in a virtual machine. As you are programming in kernel space, wrong code might cause kernel crashing and you need to reboot your computer frequently.

First, download the vagrant, libvirt, and qemue utilities from offical repository in your host computer

$ sudo apt install -y \
    qemu-kvm \
    libvirt-dev \
    bridge-utils \
    libvirt-daemon-system \
    libvirt-daemon \
    virtinst \
    bridge-utils \
    libosinfo-bin \
    libguestfs-tools \
    virt-top

Download libvirt box and boot up the virtual machine with the downloaded box. (You can first modify the provided Vagrantfile to sync what directory you want to pass to the virtual machine)

$ vagrant up --provider=libvirt

Then you are good to login into the virtual machine and download essential tools for kernel development.

$ vagrant ssh
# Inside the virtual environment
$ sudo apt-get update
$ sudo apt-get install -y build-essential kmod
$ sudo apt-get install linux-headers-`uname -r`

Build the samples

In the top-level directory, the following command will compile all the modules in the sub-directories.

$ cd [TOP_DIR]
$ make

You can also go to each subdirectory to compile the module one-by-one

$ cd [SUB_DIR]
$ make

Useful commands for kernel development

Find files with the specified pattern recursively in current directory

$ grep -rnw '.' -e '[PATTERN]'

Find directories containing specific file recursively in current directory

$ find . -type f -name '[PATTERN]' | sed -r 's|/[^/]+$||' | sort | uniq

Useful projects for kernel debugging

  • bcc A collection of eBPF toolkits to used (e.g. trace kernel stack)
  • ftrace Native kernel tracing tool to trace kernel event or available kernel functions.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published