Creating Linux Kernel Headers
The document shows the steps to create Linux kernel headers of SP7350 platforms.
Table of Contents
- 1 Download Source Files
- 2 Configure Build Environment (create linux/kernel/.config)
- 3 Build Code (create linux/kernel/Module.symvers)
- 4 Create Linux Kernel-headers
- 5 Install Linux Kernel-headers
- 6 Build a Kernel Module (an example)
- 7 Build a Kernel Module with DKMS
- 8 Appendix: List of Target headers in Makefile within build/ under Project Top-directory
Download Source Files
Please refer to the Downloading and Compiling Code for downloading and compiling the source files for the SP7350 platform.
Configure Build Environment (create linux/kernel/.config)
For example, to configure the build environment for booting from an SD card and using BusyBox for the SP7350 Ev board:
Navigate to the project's top folder and execute make config. This will open a configuration menu with customization options:
Select the board by pressing 1 for "SP7350 Ev Board."
Choose the boot device; for instance, press 5 for booting from the SD card.
Opt for the Linux root file-system by pressing 1 for “BusyBox 1.31.1.”
Choose image security by pressing 1 for building “No secure” images.
After making your selections, the system will configure the build environment. This may take several seconds to minutes depending on your computer's performance. Please wait for the process to complete.
Build Code (create linux/kernel/Module.symvers)
Once configurations are set, initiate the build process with the following command:
make
If you're not using the English version of Ubuntu, use:
LANG=C make
This command ensures that make uses English language settings. The build process will compile the code based on your configurations, typically taking a few minutes. Please be patient and let the build complete.
Create Linux Kernel-headers
Generate Linux kernel headers by running:
make headers
After completion, list the contents of the project's top folder using the ll command. The Linux kernel headers will be stored in the linux-headers-5.10.201 folder.
wellslu@scdiu3:~/Q654$ ll
total 68
drwxr-xr-x 12 wellslu sp 4096 Apr 24 13:16 ./
drwxr-xr-x 31 wellslu sp 4096 Apr 24 12:58 ../
drwxr-xr-x 6 wellslu sp 4096 Nov 15 15:38 boot/
drwxr-xr-x 3 wellslu sp 4096 Apr 24 13:00 build/
-rw-r--r-- 1 wellslu sp 284 Apr 24 13:06 .config
drwxr-xr-x 7 wellslu sp 4096 Mar 21 12:02 crossgcc/
drwxr-xr-x 3 wellslu sp 4096 Nov 15 15:38 firmware/
drwxr-xr-x 9 wellslu sp 4096 Apr 24 13:00 .git/
-rw-r--r-- 1 wellslu sp 14 Apr 24 13:00 .gitignore
-rw-r--r-- 1 wellslu sp 1117 Nov 15 15:38 .gitmodules
drwxr-xr-x 7 wellslu sp 4096 Nov 15 15:40 ipack/
drwxr-xr-x 4 wellslu sp 4096 Nov 15 15:38 linux/
drwxr-xr-x 6 wellslu sp 4096 Apr 24 13:16 linux-headers-5.10.201/
-rw-r--r-- 1 wellslu sp 23 Nov 15 15:38 Makefile
drwxr-xr-x 5 wellslu sp 4096 Dec 29 13:20 optee/
drwxr-xr-x 3 wellslu sp 4096 Apr 24 13:10 out/
-rw-r--r-- 1 wellslu sp 1007 Mar 5 11:55 README.md
wellslu@scdiu3:~/Q654$
Refer to content of folder: linux-headers-5.10.201
wellslu@scdiu3:~/Q654$ ll linux-headers-5.10.201/
total 736
drwxr-xr-x 6 wellslu sp 4096 Apr 24 13:16 ./
drwxr-xr-x 12 wellslu sp 4096 Apr 24 13:16 ../
drwxr-xr-x 3 wellslu sp 4096 Apr 24 13:16 arch/
-rw-r--r-- 1 wellslu sp 135525 Apr 24 13:16 .config
-rw-r--r-- 1 wellslu sp 39 Apr 24 13:16 .gitignore
drwxr-xr-x 4 wellslu sp 4096 Apr 24 13:16 include/
drwxr-xr-x 2 wellslu sp 4096 Apr 24 13:16 kernel/
-rw-r--r-- 1 wellslu sp 141 Apr 24 13:16 Makefile
-rw-r--r-- 1 wellslu sp 1044 Apr 24 13:16 .missing-syscalls.d
-rw-r--r-- 1 wellslu sp 576967 Apr 24 13:16 Module.symvers
drwxr-xr-x 8 wellslu sp 4096 Apr 24 13:16 scripts/
lrwxrwxrwx 1 wellslu sp 31 Apr 24 13:16 source -> /home/wellslu/Q654/linux/kernel/
wellslu@scdiu3:~/Q654$
Install Linux Kernel-headers
Before using the Linux kernel headers, copy the linux-headers-5.10.201 folder to /usr/src/ on your target board. Refer to report of ll command in Ubuntu where linux-headers has been copied to:
sunplus@ubuntu:/usr/src$ ll linux-headers-5.10.201/
total 736
drwxr-xr-x 6 4031 501 4096 Apr 24 2024 ./
drwxr-xr-x 3 root root 4096 Mar 27 21:50 ../
drwxr-xr-x 3 4031 501 4096 Apr 24 2024 arch/
-rw-r--r-- 1 4031 501 135525 Apr 24 2024 .config
-rw-r--r-- 1 4031 501 39 Apr 24 2024 .gitignore
drwxr-xr-x 4 4031 501 4096 Apr 24 2024 include/
drwxr-xr-x 2 4031 501 4096 Apr 24 2024 kernel/
-rw-r--r-- 1 4031 501 141 Apr 24 2024 Makefile
-rw-r--r-- 1 4031 501 1044 Apr 24 2024 .missing-syscalls.d
-rw-r--r-- 1 4031 501 576967 Apr 24 2024 Module.symvers
drwxr-xr-x 8 4031 501 4096 Apr 24 2024 scripts/
lrwxrwxrwx 1 4031 501 31 Apr 24 2024 source -> /home/wellslu/Q654/linux/kernel
sunplus@ubuntu:/usr/src$
Remove the soft link named source in /usr/src/linux-headers-5.10.201/ as it's unnecessary. Create a soft link named build at /lib/modules/5.10.201/ pointing to /usr/src/linux-headers-5.10.201:
Generate kernel scripts for aarch64 and copy scripts to /usr/src/linux-headers-5.10.201
Build a Kernel Module (an example)
To ensure compatibility, update your GCC version to 12.3:
Create a simple kernel module by setting up two files: hello.c and Makefile.
hello.c:
Makefile:
Navigate to your module directory and build it using the make command. You should see output similar to this:
This process will generate a hello.ko file, which is the compiled kernel module.
You can load the compiled module into the kernel with the insmod command and verify its presence with lsmod:
Build a Kernel Module with DKMS
Dynamic Kernel Module Support (DKMS) allows you to automatically rebuild kernel modules when a new kernel is installed. Refer to below link for an introduction of DKMS in Ubuntu:
dkms - Dynamic Kernel Module Support
Install DKMS
Create a Sample DKMS Module
First, set up a new directory and create the necessary files:
Then, create the following files:
Makefile:
mymodule.c:
dkms.conf:
Exit the superuser mode:
Add, Build and Install DKMS Module
Add the module to DKMS:
Build the module:
Install the module:
Load the module with modprobe and verify with lsmod:
Appendix: List of Target headers in Makefile within build/ under Project Top-directory