1、在./package目錄中增加需要添加的目錄(此例目錄為hello-world);
2、在./package/Config.in中增加此目錄的Config檔案:source "package/hello-world/Config.in",建議增加到“Hardware handling”目錄下
3、在./package/hello-world中增加組態檔Config.in,示例如下:
config BR2_PACKAGE_HELLO_WORLD
bool "hello-world"
depends on BR2_LINUX_KERNEL
help
Test for adding driver in buildroot
comment "hello-world driver needs a Linux kernel to be built"
depends on !BR2_LINUX_KERNEL
4、在./package/hello-world中增加編譯檔案hello-world.mk,示例如下:
################################################################################
#
hello-world
#
################################################################################
HELLO_WORLD_VERSION = 1.0
HELLO_WORLD_SITE_METHOD = local
HELLO_WORLD_SITE = $(TOPDIR)/dl/hello-world
HELLO_WORLD_LICENSE = GPL-2.0
HELLO_WORLD_LICENSE_FILES = LICENSE
$(eval $(kernel-module))
$(eval $(generic-package))
5、在./dl目錄中增加hello-world目錄
6、在./dl/hello-world中增加驅動代碼hello-world.c,示例如下:
#include <linux/init.h>
#include <linux/module.h>
#include <linux/kernel.h>
static int __init hello_init(void){
printk(KERN_ALERT "hello driver init!\n");
return 0;
}
static void __exit hello_exit(void){
printk(KERN_ALERT "hello driver exit\n");
}
module_init(hello_init);
module_exit(hello_exit);
7、在./dl/hello-world中增加Makefile檔案,示例如下:
CC=arm-none-linux-gnueabi-gcc
ifeq ($(KERNELRELEASE),)
KERNELDIR ?= /home/freedom/tq2416_platform/buildroot-2019.08.1/output/build/linux-custom
PWD := $(shell pwd)
modules:
$(MAKE) -C $(KERNELDIR) M=$(PWD) modules
modules_install:
$(MAKE) -C $(KERNELDIR) M=$(PWD) modules_install
clean:
rm -rf *.o *~core.depend .*.cmd *.ko *.mod.c .tmp_versions
else
obj-m := hello-world.o
endif
8、在buildroot目錄下執行make menuconfig,進入Target packages->Hardware handling配置界面后,選上hello-world配置項;
9、執行make編譯(如果想單獨編譯此驅動的話,可執行make hello-world命令),編譯成功后生成的hello-world.ko驅動檔案會集成到檔案系統中的/lib/modules/3.1.0-EmbedSky/extra目錄中;
10、在目標機上只需要執行modprobe hello-world即可加載驅動;
11、也可通過上述方式添加普通包。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/78640.html
標籤:驅動開發/核心開發
下一篇:深入SQL(隨時更新。。。)
