In order to facilitate learning each topic has a hands-on exercises section which will contain in-depth, incremental clues on how to solve one or multiple tasks. To focus on a particular issue most of the tasks will be performed on existing skeleton drivers. Each skeleton driver has clearly marked sections that needs to be filled in order to complete the tasks.
The skeleton drivers are generated from full source examples located in tools/labs/templates. To solve tasks you start by generating the skeleton drivers, running the skels target in tools/labs. To keep the workspace clean it is recommended to generate the skeletons for one lab only and clean the workspace before start working on a new lab. Labs can be selecting by using the LABS variable:
tools/labs $ make clean tools/labs $ LABS=kernel_modules make skels tools/labs $ ls skels/kernel_modules/ 1-2-test-mod 3-error-mod 4-multi-mod 5-oops-mod 6-cmd-mod \ 7-list-proc 8-kprobes 9-kdb
You can also uses the same variable to generate skeletons for specific tasks:
tools/labs $ LABS="kernel_modules/6-cmd-mod kernel_modules/8-kprobes" make skels tools/labs$ ls skels/kernel_modules 6-cmd-mod 8-kprobes
For each task you may have multiple steps to perform, usually incremental. These steps are marked in the code source as well as in the lab exercises with the keyword TODO. If we have multiple steps to perform they will be prefix by a number, like TODO1, TODO2, etc. If no number is used it is assumed to be the one and only step. If you want to resume a tasks from a certain step, you can using the TODO variable. The following example will generate the skeleton with the first TODO step resolved:
tools/labs $ TODO=2 LABS="kernel_modules/8-kprobes" skels
Once the skelton drivers are generated you can build them with the build make target:
tools/labs $ make build echo "# autogenerated, do not edit " > skels/Kbuild for i in ./kernel_modules/8-kprobes; do echo "obj-m += $i/" >> skels/Kbuild; done make -C /home/tavi/src/linux M=/home/tavi/src/linux/tools/labs/skels ARCH=x86 modules make: Entering directory '/home/tavi/src/linux' CC [M] /home/tavi/src/linux/tools/labs/skels/./kernel_modules/8-kprobes/kprobes.o Building modules, stage 2. MODPOST 1 modules CC /home/tavi/src/linux/tools/labs/skels/./kernel_modules/8-kprobes/kprobes.mod.o LD [M] /home/tavi/src/linux/tools/labs/skels/./kernel_modules/8-kprobes/kprobes.ko make: Leaving directory '/home/tavi/src/linux'
To copy the drivers to the VM you can use either use ssh or update the VM image directly using the copy target:
tools/labs $ make copy ... 'skels/kernel_modules/8-kprobes/kprobes.ko' -> '/tmp/tmp.4UMKcISmQM/home/root/skels/kernel_modules/8-kprobes/kprobes.ko'
The copy target will faili if the VM is running. This is intentional so that the we avoid corrupting the filesystem.