交叉编译linux驱动程序
交叉编译linux驱动程序
1,获取源码odroid开发板内核源码(已经打了preempt_rt-3.14.79-rt84实时补丁),并编译内核和驱动模块,并安装驱动模块:
$cd ~/odroid_c2
$git clone https://github.com/moonlinux/linux.git -b odroidc2-3.14.y-rt
$cd ./linux
$make ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- Image -j4
$make ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- modules -j4
$make ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- modules_install INSTALL_MOD_PATH=~/odroid_c2/modules
(编译器下载地址:https://releases.linaro.org/components/toolchain/binaries/4.9-2017.01/aarch64-linux-gnu/gcc-linaro-4.9.4-2017.01-x86_64_aarch64-linux-gnu.tar.xz)
2,编译驱动:
$make ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- -j4
3,源码
驱动源码:
/* simple kernel module:hello.c
** Copyright (C) 2014 Barry Song (baohua@kernel.org)
*
* Licensed under GPLv2 or later.
*/
#include <linux/init.h>
#include <linux/module.h>
static int __init hello_init(void)
{
printk(KERN_INFO "Hello World enter\n");
return 0;
}
module_init(hello_init);
static void __exit hello_exit(void)
{
printk(KERN_INFO "Hello World exit\n");
}
module_exit(hello_exit);
MODULE_AUTHOR("Barry Song <21cnbao@gmail.com>");
MODULE_LICENSE("GPL v2");
MODULE_DESCRIPTION("A simple Hello World Module");
MODULE_ALIAS("a simplest module");
-----------------------
Makefile文件:
#for Amlogic S905-build commond line :#or: make ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- -j4
obj-m := hello.o
KDIR := /home/bruce/odroid_c2/modules/lib/modules/3.14.79-rt84+/build
KBUILD_CFLAGS += -march=armv8-a -mtune=cortex-a53
MAKE := make
build: kernel_modules
kernel_modules:
${MAKE} -C $(KDIR) M=$(PWD) modules
.PHONY: clean
clean:
${MAKE} -C $(KDIR) M=$(PWD) clean
更多推荐
所有评论(0)