Compile and Install Driver in Blade 3

Below is the instruction to compile and install driver in Blade 3.

  1. Download source code of kernel from this Github link and put it to folder of Blade 3.
git clone --single-branch --branch mixtile/blade3/debian11/kernel5.10 https://github.com/mixtile/linux.git

git clone –single-branch –branch mixtile/blade3/debian11/kernel5.10 https://github.com/mixtile/linux.git

2. Use Blade 3 console and modify the build link of /lib/modules directory to the folder directory of newly downloaded kernel files

rm /lib/modules/5.10.66/build

ln -snf xxx/kernel /lib/modules/5.10.66/build

(Note: You should replace “xxx” in above command with the absolute path of kernel folder)

  1. Install compilation tool by using below commands:
apt-get update

apt-get install -y git ssh make gcc libssl-dev liblz4-tool expect g++ patchelf chrpath gawk texinfo chrpath diffstat software-properties-common bison flex fakeroot cmake unzip device-tree-compiler libncurses-dev python3-pip python3-pyelftools bc make build-essential libssl-dev zlib1g-dev libbz2-dev libreadline-dev libsqlite3-dev wget curl llvm libncursesw5-dev xz-utils tk-dev libxml2-dev libxmlsec1-dev libffi-dev liblzma-dev python rsync

apt-get install gcc-aarch64-linux-gnu

4. Configure the Kernel

4.1 Go to the kernel directory and configure the kernel.

make ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- blade3_linux_defconfig

4.2 Compile the kernel

make ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- rk3588-blade3-v101-linux.img

5. Compile driver file

5.1 Write driver files, below is a simple example:

        (a) Write hello.c driver file

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

MODULE_AUTHOR("fengyc");
MODULE_DESCRIPTION("This is a demo.");
MODULE_VERSION("0.0.1");
MODULE_LICENSE("GPL");

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);

 (b) Write Makefile

obj-m += hello.o

all:
make -C "/lib/modules/$(shell uname -r)/build" M=$(PWD) modules

clean:
make -C "/lib/modules/$(shell uname -r)/build" M=$(PWD) clean

5.2 Compile the driver

Executing make in that directory

make

it produces the following file:

Makefile hello.c hello.mod hello.mod.o modules.order Module.symvers hello.ko hello.mod.c hello.o

5.3 Install the driver

insmod hello.ko

5.4 uninstall the driver

rmmod hello.ko
Was this article helpful?

Related Articles

Need Support?

Can't find the answer you're looking for?
Contact Support