Kernel Module Cross Compilation Notes¶
๐งญ Overview¶
External kernel module development requires a matching build environment with the target kernel.
Matching includes:
- Kernel version (
uname -r) - Configuration (
.config) - Symbol version (
Module.symvers)
๐๏ธ Two Worlds in Cross Compilation¶
| Type | Runs on | Purpose |
|---|---|---|
| Host tools | x86 (WSL) | Build system (fixdep, modpost) |
| Target code | ARM (Pi) | Kernel module (.ko) |
โ๏ธ Kernel Release Matching¶
Kernel release format:
Example:
Key Config¶
Remove extra '+'¶
๐ง Build Preparation¶
Purpose:
- Generate headers
- Build host tools
- Prepare external module interface
๐งฉ Module.symvers¶
What it is¶
- Symbol version database
- Maps exported kernel symbols
Why it matters¶
Used during:
Without it:
- Undefined symbols
- Version mismatch
- Module load failure
โ Symbol Version Mismatch¶
Example error:
Cause¶
- Kernel and module built with different symbol versions
Fix¶
- Use exact
Module.symversfrom target kernel
๐ vermagic¶
Check with:
Example:
Note¶
Matching vermagic does NOT guarantee success.
โ ๏ธ Common Errors¶
Exec format error¶
Cause:
- Running ARM binary on x86
Fix:
Invalid module format¶
Cause:
- Kernel mismatch
- vermagic mismatch
Unknown symbol¶
Cause:
- Missing or incorrect
Module.symvers
๐งช Debugging Workflow¶
Useful:
๐งญ Best Practice¶
- Always use target kernel config
- Always align
Module.symvers - Avoid mixing different kernel builds
- Do not rely only on version string
๐ฏ Summary¶
A working kernel module requires matching:
- Kernel version
- Configuration
- Symbol version