Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Download Source Files

Please refer to the A Guide to Downloading and Compiling SP7350 Code for downloading and compiling the source files for the SP7350 platform.

...

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:

...

Code Block
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/init.h>

static int __init hello_init(void)
{
      	printk(KERN_INFO "Hello, World!\n");
      	return 0;
}

static void __exit hello_exit(void)
{
      	printk(KERN_INFO "Goodbye, World!\n");
}

module_init(hello_init);
module_exit(hello_exit);

MODULE_LICENSE("GPL");
MODULE_AUTHOR("Your Name");
MODULE_DESCRIPTION("A simple Hello World Kernel Module");

...

First, set up a new directory and create the necessary files:

Code Block
sunplus@ubuntu:~$ sudo mkdir -p /usr/src/mymodule-1v1.0
[sudo] password for sunplus:
sunplus@ubuntu:~$ cd /usr/src/mymodule-v1.0/
sunplus@ubuntu:/usr/src/mymodule-1v1.00$ sudo su
echo -e "root@ubuntu:/usr/src/mymodule-v1.0#

Then, create the following files:

Makefile:

Code Block
obj-m += mymodule.o\nall:\n\tmake
all:
	make -C /lib/modules/\$(uname -r)/build M=\$(PWD) modules\nclean:\n\tmake
clean:
	make -C /lib/modules/\$(uname -r)/build M=\$(PWD) clean" > /usr/src/mymodule-1.0/Makefile
echo -e "#include <linux/init.h>\n#include <linux/module.h>\nstatic

mymodule.c:

Code Block
#include <linux/init.h>
#include <linux/module.h>
static int __init mymodule_init(void)
{
	return 0;
}\nstatic
static void __exit mymodule_exit(void)
{
}\nmodule
module_init(mymodule_init);\nmodule
module_exit(mymodule_exit);\nMODULE
MODULE_LICENSE(\"GPL\");" > /usr/src/mymodule-1.0/mymodule.c
echo -e "

dkms.conf:

Code Block
PACKAGE_NAME=\"mymodule\"\nPACKAGE
PACKAGE_VERSION=\"1.0\"\nBUILT
BUILT_MODULE_NAME[0]=\"mymodule\"\nDEST
DEST_MODULE_LOCATION[0]=\"/updates/dkms/\"\nAUTOINSTALL=\"yes\"" > 
AUTOINSTALL="yes"

Exit the superuser mode:

Code Block
root@ubuntu:/usr/src/mymodule-v1.0# exit
exit
sunplus@ubuntu:/usr/src/mymodule-1.0/dkms.conf
exitv1.0$

Add, Build and Install DKMS Module

Add the module to DKMS:

Code Block
sunplus@ubuntu:/usr/src/mymodule-1.0$ sudo dkms add -m mymodule -v 1.0
Creating symlink /var/lib/dkms/mymodule/1.0/source -> /usr/src/mymodule-1.0

Build the module:

Code Block
sunplus@ubuntu:/usr/src/mymodule-1.0$ sudo dkms build -m mymodule -v 1.0

Kernel preparation unnecessary for this kernel. Skipping...

Building module:
cleaning build area...
make -j4 KERNELRELEASE=5.10.201 -C /lib/modules/5.10.201/build M=/var/lib/dkms/mymodule/1.0/build....
cleaning build area...

Install the module:

Code Block
sunplus@ubuntu:/usr/src/mymodule-1.0$ sudo dkms install -m mymodule -v 1.0

mymodule.ko:
Running module version sanity check.
 - Original module
   - No original module exists within this kernel
 - Installation
   - Installing to /lib/modules/5.10.201/updates/dkms/

depmod...

Load the module with modprobe and verify with lsmod:

Code Block
sunplus@ubuntu:/usr/src/mymodule-1.0$ sudo modprobe mymodule
sunplus@ubuntu:/usr/src/mymodule-1.0$ lsmod
Module                  Size  Used by
mymodule               16384  0
hello                  16384  0
galcore               794624  0
edt_ft5x06             32768  0
sp7350_rng             16384  0
rng_core               24576  1 sp7350_rng

Appendix: List of Target headers in Makefile within build/

...

under Project Top-directory

Code Block
headers:
	@KERNELRELEASE=$(shell cat $(LINUX_PATH)/include/config/kernel.release 2>/dev/null)
	@if ! [ -f $(LINUX_PATH)/.config ]; then \
		echo File \'$(LINUX_PATH)/.config\' does not exist!; \
		exit 1; \
	fi
	@if ! [ -f $(LINUX_PATH)/Module.symvers ]; then \
		echo File \'$(LINUX_PATH)/Module.symvers\' does not exist!; \
		exit 1; \
	fi
	rm -rf linux-headers-$(KERNELRELEASE)
	mkdir -p linux-headers-$(KERNELRELEASE)
	cp -f $(LINUX_PATH)/.config linux-headers-$(KERNELRELEASE)
	cp -f $(LINUX_PATH)/Module.symvers linux-headers-$(KERNELRELEASE)
	$(MAKE_ARCH) $(MAKE_JOBS) -C $(LINUX_PATH) CROSS_COMPILE=$(CROSS_COMPILE_FOR_LINUX) mrproper
	$(MAKE_ARCH) $(MAKE_JOBS) -C $(LINUX_PATH) O=../../linux-headers-$(KERNELRELEASE) CROSS_COMPILE=$(CROSS_COMPILE_FOR_LINUX) modules_prepare
	$(MAKE_ARCH) $(MAKE_JOBS) -C $(LINUX_PATH) headers_install INSTALL_HDR_PATH=../../linux-headers-$(KERNELRELEASE) CROSS_COMPILE=$(CROSS_COMPILE_FOR_LINUX)
	rm linux-headers-$(KERNELRELEASE)/source
	cp -rf $(LINUX_PATH)/include linux-headers-$(KERNELRELEASE)
	mkdir -p linux-headers-$(KERNELRELEASE)/arch
	cp -rf $(LINUX_PATH)/arch/arm64 linux-headers-$(KERNELRELEASE)/arch
	cp -f $(LINUX_PATH)/Makefile linux-headers-$(KERNELRELEASE)
	cp -rf $(LINUX_PATH)/scripts linux-headers-$(KERNELRELEASE)

...