Following the Linux Kernel Module Programming Guide with RISC-V Milkv Duo embedded board

2024-01-06

We saw in this post that The Linux Kernel Module Programming Guide is a great resource when learning Linux Device Drivers. It however takes a self-compiled route with the modules developed and run directly on the host system. For GPIO examples the Raspberry PI is used.

In this article we shall see how to adopt the guide to learn with the Milk-V Duo board. Here we assume you use the vanilla Buildroot repo for building the system image.

Adapting the Makefile#

As mentioned above, the modules are selfcompiled to run locally on the host system. To make them run on our dev board we need to modify the Makefile. The C source file is left untouched.

CC = $(CROSS_COMPILE)gcc

obj-m := hello.o
KDIR := /home/<user>/milkv/milkv-duo-buildroot/output/build/linux-duo-linux-5.10.4

all:
	$(MAKE) -C $(KDIR) M=$(PWD)

clean:
	$(MAKE) -C $(KDIR) M=$$PWD clean

Be sure to adapt the KDIR path to suite your system's location. Also make note to change hello.o to whatever you named your C source file.

Remember to execute the following environment variables before running make:

export PATH="$PATH:/home/ajit/work/ldd/milkv/milkv-duo-buildroot/output/host/bin"

export ARCH=riscv
export CROSS_COMPILE=riscv64-linux-

Changing the GPIO directives#

In the chapter #detecting-button-presses, they use the Raspberry PI which is based on Cortex-A architecture. Our RISC-V board uses different GPIO naming scheme, and we need to adapt accordingly...

TODO