编译内核驱动程序步骤 – 基于firefly的aio-3399j 平台
1.进入kernel/device目录中 , 创建一个目录名 , 如lowfree
2.进入lowfree,创建一个hello.c, 写入如下代码
#include <linux/kernel.h>
#include <linux/init.h>
#include <linux/module.h>
#include <linux/delay.h>
static int __init hello_init(void)
{
int i;
for(i=0;i<=10;i++)
{
printk("============================================== Hello , this is lowfree's work ============================================== %d\n",i);
mdelay(1000);
}
return 0;
}
static void __exit hello_exit(void)
{
printk("Exit Hello world\n");
}
subsys_initcall(hello_init);
module_exit(hello_exit);
MODULE_AUTHOR("lowfree");
MODULE_DESCRIPTION("hello driver");
MODULE_LICENSE("GPL");
3.创建一个Makefile文件, 写入
obj-$(CONFIG_HELLO) += hello.o
4.创建一个Kconfig,写入
config HELLO
tristate "Hello for Firefly --- lowfree"
help
Hello for Firefly --- lowfree
5.返回到drivers目录下, 进入 Makefile, 添加
obj-y += lowfree/
6.进入 Kconfig, 加入
source "drivers/lowfree/Kconfig"
7.返回kernel 目录下, 输入make ARCH=arm64 menuconfig ,再进入到drivers下, 可看到lowfree
8.返回 sdk根目录下, 输入
./build.sh kernel
进行内核编译, 当然 ,若非全sdk的情况下编译, 可使用make命令进行编译
============Start build kernel============
TARGET_ARCH =arm64
TARGET_KERNEL_CONFIG =firefly_linux_defconfig
TARGET_KERNEL_DTS =rk3399-firefly-aio
==========================================
#
# configuration written to .config
#
scripts/kconfig/conf --silentoldconfig Kconfig
CHK include/config/kernel.release
CHK include/generated/uapi/linux/version.h
CHK include/generated/utsrelease.h
CHK scripts/mod/devicetable-offsets.h
CHK include/generated/timeconst.h
CHK include/generated/bounds.h
CHK include/generated/asm-offsets.h
make[1]: 'arch/arm64/boot/dts/rockchip/rk3399-firefly-aio.dtb' is up to date.
CALL scripts/checksyscalls.sh
make[1]: 'include/generated/vdso-offsets.h' is up to date.
CHK include/generated/compile.h
make[1]: 'arch/arm64/boot/Image.lz4' is up to date.
Image: kernel.img is ready
w CHK include/config/kernel.release
CHK include/generated/uapi/linux/version.h
CHK include/generated/utsrelease.h
CHK scripts/mod/devicetable-offsets.h
CHK include/generated/timeconst.h
CHK include/generated/bounds.h
CHK include/generated/asm-offsets.h
CALL scripts/checksyscalls.sh
make[2]: 'include/generated/vdso-offsets.h' is up to date.
Building modules, stage 2.
MODPOST 1 modules
Pack to resource.img successed!
Image: resource.img (with rk3399-firefly-aio.dtb logo.bmp ) is ready
Image: boot.img (with Image resource.img) is ready
Image: zboot.img (with Image.lz4 resource.img) is ready
/home/lowfree/doc/rk3399_camera/aiork3399j/linux/repo/linux-sdk
====Build kernel ok!====
9.将生成的boot.img 烧录到aio-3399j
注意, 使用安卓烧写工具v2.58时, 没有kernel和resource的信息, 可只用烧写boot.img即可