今天跟随 讯为的开发板实现了 hello world 的驱动,之前已经实现了很多次,这次还是重新实现了一次 本文是基于RK3568
1. 编迅为的内核
topeet@ubuntu:~/Linux/rk356x_linux$ ./build.sh kernel
processing option: kernel
============Start building kernel============
TARGET_ARCH =arm64
TARGET_KERNEL_CONFIG =rockchip_linux_defconfig
TARGET_KERNEL_DTS =rk3568-evb1-ddr4-v10-linux
TARGET_KERNEL_CONFIG_FRAGMENT =
==========================================
HOSTCC scripts/basic/fixdep
HOSTCC scripts/kconfig/conf.o
YACC scripts/kconfig/zconf.tab.c
LEX scripts/kconfig/zconf.lex.c
HOSTCC scripts/kconfig/zconf.tab.o
HOSTLD scripts/kconfig/conf
#
# configuration written to .config
xxx
...
LD [M] drivers/net/wireless/rockchip_wlan/rkwifi/bcmdhd/bcmdhd.o
Building modules, stage 2.
MODPOST 3 modules
CC drivers/net/wireless/marvell/mwifiex/mwifiex.mod.o
CC drivers/net/wireless/marvell/mwifiex/mwifiex_sdio.mod.o
CC drivers/net/wireless/rockchip_wlan/rkwifi/bcmdhd/bcmdhd.mod.o
LD [M] drivers/net/wireless/rockchip_wlan/rkwifi/bcmdhd/bcmdhd.ko
LD [M] drivers/net/wireless/marvell/mwifiex/mwifiex.ko
LD [M] drivers/net/wireless/marvell/mwifiex/mwifiex_sdio.ko
found ./arch/arm64/boot/dts/rockchip/.rk3568-evb1-ddr4-v10-linux.dtb.dts.tmp
found ./arch/arm64/boot/dts/rockchip/.rk3568-evb1-ddr4-v10-linux.dtb.dts.tmp
found ./arch/arm64/boot/dts/rockchip/.rk3568-evb1-ddr4-v10-linux.dtb.dts.tmp
found ./arch/arm64/boot/dts/rockchip/.rk3568-evb1-ddr4-v10-linux.dtb.dts.tmp
found ./arch/arm64/boot/dts/rockchip/.rk3568-evb1-ddr4-v10-linux.dtb.dts.tmp
found ./arch/arm64/boot/dts/rockchip/.rk3568-evb1-ddr4-v10-linux.dtb.dts.tmp
found ./arch/arm64/boot/dts/rockchip/.rk3568-evb1-ddr4-v10-linux.dtb.dts.tmp
Image: resource.img (with rk3568-evb1-ddr4-v10-linux.dtb logo.bmp logo_kernel.bmp) is ready
Image: boot.img (with Image resource.img) is ready
Image: zboot.img (with Image.lz4 resource.img) is ready
fdt {
kernel {
resource {
FIT description: U-Boot FIT source file for arm
Created: Tue Dec 20 22:33:35 2022
Image 0 (fdt)
Description: unavailable
Created: Tue Dec 20 22:33:35 2022
Type: Flat Device Tree
Compression: uncompressed
Data Size: 137945 Bytes = 134.71 KiB = 0.13 MiB
Architecture: AArch64
Load Address: 0xffffff00
Hash algo: sha256
Hash value: 9cd38b1dd5c8dff695ae9928a6f96cc7d35dc3fd712907989d96c31a5ebb1aaf
Image 1 (kernel)
Description: unavailable
Created: Tue Dec 20 22:33:35 2022
Type: Kernel Image
Compression: uncompressed
Data Size: 26578952 Bytes = 25956.01 KiB = 25.35 MiB
Architecture: AArch64
OS: Linux
Load Address: 0xffffff01
Entry Point: 0xffffff01
Hash algo: sha256
Hash value: 86c70073ba22fb58d4121acf95e4f8a45772a3260da3686e07883adcc7c55a6d
Image 2 (resource)
Description: unavailable
Created: Tue Dec 20 22:33:35 2022
Type: Multi-File Image
Compression: uncompressed
Data Size: 176128 Bytes = 172.00 KiB = 0.17 MiB
Hash algo: sha256
Hash value: 0f60a9def334606c948d16f093c7340c2a4c1a7cae7ffc04ac0d2b663cc2f318
Default Configuration: 'conf'
Configuration 0 (conf)
Description: unavailable
Kernel: kernel
FDT: fdt
grep: exceeded PCRE's backtracking limit
grep: exceeded PCRE's backtracking limit
grep: exceeded PCRE's backtracking limit
grep: exceeded PCRE's backtracking limit
grep: exceeded PCRE's backtracking limit
grep: exceeded PCRE's backtracking limit
grep: exceeded PCRE's backtracking limit
grep: exceeded PCRE's backtracking limit
PLEASE CHECK BOARD GPIO POWER DOMAIN CONFIGURATION !!!!!
<<< ESPECIALLY Wi-Fi/Flash/Ethernet IO power domain >>> !!!!!
Check Node [pmu_io_domains] in the file: /home/topeet/Linux/rk356x_linux/kernel/arch/arm64/boot/dts/rockchip/rk3568-evb1-ddr4-v10-linux.dts
请再次确认板级的电源域配置!!!!!!
<<< 特别是Wi-Fi,FLASH,以太网这几路IO电源的配置 >>> !!!!!
检查内核文件 /home/topeet/Linux/rk356x_linux/kernel/arch/arm64/boot/dts/rockchip/rk3568-evb1-ddr4-v10-linux.dts 的节点 [pmu_io_domains]
Running build_kernel succeeded.
topeet@ubuntu:~/Linux/rk356x_linux$
内核编译层面 迅为基本已经都做好了 我这边使用的是迅为提供的虚拟机。
接下来按照文档说明的开始抄代码
第一个驱动如下 :
#include <linux/module.h>
#include <linux/init.h>
static int __init hello_init(void)
{
printk("init ... \n");
return 0;
}
static void hello_exit(void)
{
printk("exit ... \n");
}
module_init(hello_init);
module_exit(hello_exit);
MODULE_LICENSE("GPL v2");
MODULE_AUTHOR("jeason b");
MODULE_VERSION("1.0.0");
对应的makefile 如下:
obj-m += hello.o
KDIR:=/home/topeet/Linux/rk356x_linux/kernel
PWD?=$(shell pwd)
all:
make -C $(KDIR) M=$(PWD) modules
clean:
make -C $(KDIR) M=$(PWD) clean
rm -f *.ko *.o *.mod.o *.mod.c *.symvers *.order
2.模块安装测试
[root@RK356X:~]# modinfo hello.ko
-/bin/sh: modinfo: not found
[root@RK356X:~]# insmod hello.ko
[ 6478.328524] init ...
[root@RK356X:~]# rmmod hello.ko
[ 6482.710927] exit ...
[root@RK356X:~]#
在 rk3568 开发板的默认的系统里面没找到 modinfo的指令 在ubuntu上查看模块信息
topeet@ubuntu:~/drive/hello$ ls
hello.c hello.ko hello.mod.c hello.mod.o hello.o Makefile modules.order Module.symvers
topeet@ubuntu:~/drive/hello$
topeet@ubuntu:~/drive/hello$ modinfo hello.ko
filename: /home/topeet/drive/hello/hello.ko
version: 1.0.0
author: jeason b
license: GPL v2
srcversion: 8C25FFFAB4F34B01755F9C1
depends:
name: hello
vermagic: 4.19.232 SMP mod_unload aarch64
topeet@ubuntu:~/drive/hello$
topeet@ubuntu:~/drive/hello$ file hello.ko
hello.ko: ELF 64-bit LSB relocatable, ARM aarch64, version 1 (SYSV), BuildID[sha1]=9d25a5a92f3e27c8bc230f32ef6c54332b2d7a14, with debug_info, not stripped