Let's round off this first kernel module discussion with a simple yet useful custom Bash script called lkm that helps you out by automating the kernel module build, load, dmesg, and unload workflow. Here it is (the complete code is in the root of the book source tree):
#!/bin/bash
# lkm : a silly kernel module dev - build, load, unload - helper wrapper script
[...]
unset ARCH
unset CROSS_COMPILE
name=$(basename "${0}")
# Display and run the provided command.
# Parameter(s) : the command to run
runcmd()
{
local SEP="------------------------------"
[ $# -eq 0 ] && return
echo "${SEP}
$*
${SEP}"
eval "$@"
[ $? -ne 0 ] && echo " ^--[FAILED]"
}
### "main" here
[ $# -ne 1 ] && {
echo "Usage: ${name} name-of-kernel-module-file (without the .c)"
exit 1
}
[[ "${1}" = *"."* ]] && {
echo "Usage: ${name} name-of-kernel-module-file...