当前位置:网站首页>Makefile template
Makefile template
2022-07-27 11:53:00 【Be good to me】
1. Templates
1.1 Compile driver module
# -C $(KDIR) Indicates to jump to the kernel source code directory and read there Makefile
# M=$(PWD) Indicates that you will then return to the current directory to continue reading 、 Execute current Makefile
# Module name to be generated
obj-m := GobiNet.o
# Generate the object file required by this module
GobiNet-objs := GobiUSBNet.o QMIDevice.o QMI.o MPQMUX.o
KDIR := /lib/modules/$(shell uname -r)/build
PWD := $(shell pwd)
OUTPUTDIR=/lib/modules/`uname -r`/kernel/drivers/net/usb/
all: clean
make -C $(KDIR) M=$(PWD) modules
# If cross compilation , be :
#make -C $(KDIR) M=$(PWD) modules ARCH=arm CROSS_COMPILE=/mnt/external/wangtao/8953/8953_APP_P/prebuilts/gcc/linux-x86/arm/arm-eabi-4.8/bin/arm-eabi-
install: all
mkdir -p $(OUTPUTDIR)
cp -f GobiNet.ko $(OUTPUTDIR)
depmod
clean:
rm -rf *.o *~ core .depend .*.cmd *.ko *.mod.c .tmp_versions Module.* modules.order
1.2 Compiling the application
CC=gcc
CFLAGS_WARN= -Wall
DEFINE=
INCLUDE= -I.
SOURCES=$(wildcard *.c)
OBJS=$(patsubst %.c,%.o,$(SOURCES))
TARGET= test
All:$(OBJS)
$(CC) -o $(TARGET)$(OBJS)
rm -f *.o
%.o:%.c
$(CC) -c $(CFLAGS_WARN)$(DEFINE)$(INCLUDE) $< -o [email protected]
clean:
rm -f $(OBJS)
2 . Add drivers to the development board
2.1 Compile into modules
(1) Create a new working folder under the source code hello;
(2) newly build c file , And edit :
#include <linux/module.h>
#include <linux/init.h>
static int __init test_init(void)
{
printk("hello\n");
return 0;
}
static void __exit test_exit(void)
{
printk("bye\n");
}
module_init(test_init);
module_exit(test_exit);
(3) newly build makefile, And edit :
obj-m := hello.o
modules-objs := hello.o
KERNELDIR := /mnt/external/wangtao/MDM9X07_LE11_MODEM/apps_proc/oe-core/build/tmp-glibc/work/mdm9607_perf-oe-linux-gnueabi/linux-quic/git-e3802ce3ddb62ec1c6b0484515a0523b8db30e2f-r3/build
PWD := $(shell pwd)
default:
$(MAKE) -C $(KERNELDIR) ARCH=arm CROSS_COMPILE=/mnt/external/wangtao/MDM9X07_LE11_MODEM/apps_proc/oe-core/build/tmp-glibc/sysroots/x86_64-linux/usr/bin/arm-oe-linux-gnueabi/arm-oe-linux-gnueabi- M=$(PWD) modules
clean:
$(MAKE) -C $(KERNELDIR) M=$(PWD) clean
(4) compile make, Generate ko file ;
(5) utilize FTP take ko File transfer to PC machine ;
(6) utilize adb take ko Download the file to the development board and modify the file permissions :
adb push C:\Users\20190712125\Desktop\hello.ko /data
adb shell chmod 755 /data/hello.ko
(7) Load module :
insmod hello.ko
(8) Check out the module :
lsmod

Be careful :makefile Medium all: The back is tab Indent , Instead of space indentation ( Will report a mistake ).
2.2 Compile into the kernel
(1) Create a new working folder under the source code hello;
(2) newly build c File and edit , ditto ;
(3) newly build Makefile And edit :
obj-$(CONFIG_nwy_HELLO)+=hello.o
(4) newly build Kconfig And edit :
config HELLO
tristate"First Driver"
default n
help
This is the first driver.
(5) modify kernel/drivers/kconfig file , stay menu "Device Drivers" and endmenu Add a line between :
$ source "drivers/hello/Kconfig"
such , perform make menuconfig when , You can configure hello Module compilation options .
(6) modify kernel/drivers/Makefile file , Add a row :
obj-$(CONFIG_HELLO)+=hello/
(7) Modify the general config file
stay kernel/arch/arm/configs/ There are specified items in the directory defconfig file , Such as msm9607_defconfig file , Add a line to this file :
CONFIG_HELLO=y
(9) Compiling the kernel :make
(10) utilize adb Single burn kernel image .
边栏推荐
- The difference between microcomputer and single chip microcomputer
- LeetCode 04: T26. 删除排序数组中的重复项(简单); 剑指 Offer 67. 把字符串转换成整数(中等); 面试题 01.08. 零矩阵 (简单)
- 1. Introduction and basic use of flume
- 剑指 Offer 笔记: T58 - II. 左旋转字符串
- origin如何作一张图中多张子图是柱状图(或其他图)
- PWM的原理和PWM波的产生
- LeetCode 01: T1. 两数之和 ; T1108. IP 地址无效化 ; T344. 反转字符串
- TLC549Proteus仿真&Sallen-Key滤波器&AD736Vrms到DC转换&Proteus查看51寄存器值
- Sword finger offer notes: T53 - ii Missing numbers from 0 to n-1
- 剑指 Offer 笔记: T45. 把数组排成最小的数
猜你喜欢

Keil MDK compilation appears..\user\stm32f10x H (428): error: # 67: expected a "}" wrong solution

The first case of monkeypox in pregnant women in the United States: the newborn was injected with immunoglobulin and was safely born

Newton-Raphson迭代法
Unexpected harvest of epic distributed resources, from basic to advanced are full of dry goods, big guys are strong!

npm踩坑

阿里云云数据库RDS版Exception during pool initialization

Could not load dynamic library ‘libcudnn.so.8‘;

Tlc549proteus simulation &sallen key filter &ad736vrms to DC conversion &proteus view 51 register value

EfficientNet

Matlab draws Bode diagram with time delay system
随机推荐
Principle, concept and construction process of MySQL database master-slave replication cluster
哈希表 详细讲解
Sword finger offer notes: t58 - I. flip word order
剑指 Offer 笔记: T57 - II. 和为 s 的连续正数序列
解决方案:Can not issue executeUpdate() or executeLargeUpdate() for SELECTs
Iptables firewall
意外收获史诗级分布式资源,从基础到进阶都干货满满,大佬就是强!
VSCode复制代码时去掉样式/语法高亮/代码高亮/黑色背景
LAN SDN technology hard core insider 12 cloud CP's daily love - hardware vxlan forwarding plane
V-show失效问题
微商的差商近似
V-show failure
Newton Raphson iterative method
LNMP architecture setup (deploy discuz Forum)
阿里云云数据库RDS版Exception during pool initialization
检定和校准的区别
【机器学习-白板推导系列】学习笔记---概率图模型和指数族分布
SMA TE: Semi-Supervised Spatio-Temporal RepresentationLearning on Multivariate Time Series
omitempty在go中的使用
STM32 compilation error: l6235e: more than one section matches selector - cannot all be first/l