If you are using VSCode for Linux kernel development, following setup will be useful:
- Clone https://github.com/aakbar5/handy-kernel_modules. It contains the
- Makefile: to build kernel modules
- .devcontainer: to setup vscode for remote development inside the Docker container
- .vscode: From tasks build and run Qemu.
- Start vscode
- Open the folder having linux kernel development project
- Select: Remote-Containers: Open Folder in Container… from the popup menu.
- Select the folder selected in #2
- Keep an eye on the vscode status bar while it is showing Opening Remote…
- Once vscode is setup, your project will be ready for development in container environment.
- Press CTRL+P for Tasks: Run Task
- Select kmod – build task to build a kernel module setup in Makefile.
- Press CTRL+P for Tasks: Run Task
- Select Generate compile_commands.json from the list of tasks.
- It will run generate_compdb.py (https://github.com/aakbar5/vscode-linux-kernel) for the linux kernel and for the project workspace.
- It will generate compile_commands.json which will help you in code assistance.
- Press CTRL+P for Tasks: Run Task
- Select Run QEMU and wait for QEMU to be ready for use
- Press CTRL+P for Tasks: Run Task and select kmod – load
- This command will copy built kernel module to QEMU.
- Get back to QEMU shell in vscode terminal and use kernel module commands to test your new kernel module.
- Once you are done with development, use Dev Container: Close Remote Connection option.
