Kernel Drivers Porting and Configuration
Overview
Developing and porting Linux kernel drivers is essential for extending hardware support on LeMaker boards. The Allwinner A20 SoC used in the Banana Pi and Banana Pro, the Actions Semi S500 in the Guitar, and the HiSilicon Kirin series in the HiKey boards each require specific driver support for their peripherals. This guide covers the complete workflow for building, porting, and configuring kernel drivers for LeMaker single-board computers.
Cross-Compilation Setup
Kernel development for ARM-based LeMaker boards requires a cross-compilation toolchain on your host machine. Install the ARM cross-compiler on Ubuntu or Debian with sudo apt-get install gcc-arm-linux-gnueabihf. For 64-bit boards like HiKey, use gcc-aarch64-linux-gnu. Set the environment variables before building: export ARCH=arm and export CROSS_COMPILE=arm-linux-gnueabihf-. Clone the appropriate kernel source tree from the LeMaker or sunxi GitHub repositories. The Linaro toolchain is recommended for HiKey series boards for best compatibility with the HiSilicon BSP.
Kernel Configuration
Start with the default configuration for your board using make sun7i_defconfig for Banana Pi and Banana Pro or the appropriate defconfig for your target platform. Run make menuconfig to enable or disable specific drivers and kernel features through the interactive text-based interface. Navigate the menu tree to locate the subsystem relevant to your driver. Mark drivers as built-in with [*] for essential functionality or as loadable modules with [M] for optional features. Save your configuration and verify changes with diff .config .config.old to review exactly what was modified.
Device Tree Modifications
Modern kernels for LeMaker boards use device tree files to describe hardware. The device tree source files are located in arch/arm/boot/dts/ for A20-based boards. Modify the appropriate .dts or .dtsi file to add your hardware node with the correct compatible string, register addresses, interrupts, clocks, and pin control settings. Compile the device tree with make dtbs and deploy the resulting .dtb file to the boot partition. For older Allwinner kernels, the fex file serves a similar purpose and can be edited with fex2bin and bin2fex tools.
Building Out-of-Tree Modules
For driver development and testing, building modules out of tree is faster than full kernel rebuilds. Create a standard Kbuild Makefile with obj-m += mydriver.o and build against the kernel headers using make -C /path/to/kernel M=$(pwd) modules. Copy the resulting .ko file to the board and load it with insmod mydriver.ko. Use modinfo mydriver.ko to verify module metadata and modprobe for modules installed in the standard module path.
Common Subsystems
The most frequently ported driver subsystems on LeMaker boards include GPIO (General Purpose Input/Output) using the gpiolib framework, I2C for sensors and peripherals via the i2c-sunxi driver, SPI for high-speed serial devices, USB host and OTG support through the musb or ehci/ohci controllers, and UART for serial communication. Each subsystem has its own registration API and driver model. Consult the kernel documentation under Documentation/driver-api/ for the specific subsystem you are targeting.
Testing and Debugging
After loading your driver module, verify correct operation by checking the kernel log with dmesg | tail -50. Use printk() statements at various log levels (KERN_DEBUG, KERN_INFO, KERN_ERR) during development to trace driver execution flow. The /proc and /sys filesystems expose driver attributes for runtime inspection. For hardware register debugging, the devmem2 tool provides direct memory-mapped I/O access. Enable CONFIG_DYNAMIC_DEBUG in the kernel to toggle debug messages at runtime without recompilation.
Related Pages
For U-Boot and kernel building instructions, see Building U-Boot, script.bin and Linux Kernel. For hardware pin configuration, refer to Banana Pi Fex Configuration.
Author: LeMaker Documentation Team
Last updated: 2026-02-10