当前位置:网站首页>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 .
边栏推荐
- Common power supply problems and solutions of Arduino
- LNMP架构搭建(部署Discuz论坛)
- 数据包传输:应用层-内核-硬件
- 【机器学习-白板推导系列】学习笔记---条件随机场
- NPM step pit
- Leetcode 02: sword finger offer 58 - I. flip the word order (simple); T123. Verify palindrome string; T9. Palindromes
- go入门篇 (3)
- How to make a graph? Multiple subgraphs in a graph are histogram (or other graphs)
- Shell编程之正则表达式(Shell脚本文本三剑客之grep)
- [untitled] multimodal model clip
猜你喜欢
随机推荐
上半年火灾起数下降27.7%,广东将这样提升全民消防安全素质
Principle of control system based on feedback rate
Idea: can't use subversion command line client: SVN solution
LNMP architecture setup (deploy discuz Forum)
解决方案:idea project没有显示树状图
[machine learning whiteboard derivation series] learning notes - probability graph model and exponential family distribution
Open source Flink has datastream connector written with holo or Flink SQL Conn
LAN SDN hard core technology insider 23 looking forward to the future - RDMA (Part 1)
Adobe Audition提示 音频输入的采样率与输出设备不匹配——问题解决
N ¨UWA: Visual Synthesis Pre-training for Neural visUal World creAtionChenfei
A possibility that ch340 module cannot be recognized / burned
剑指 Offer 笔记: T39. 数组中出现次数超过一半的数字
Vscode removes style / syntax highlighting / code highlighting / black background when copying code
Newton-Raphson迭代法
Sword finger offer notes: t57 - I. and two numbers of S
【无标题】多模态模型 CLIP
Leetcode 02: sword finger offer 58 - I. flip the word order (simple); T123. Verify palindrome string; T9. Palindromes
源码编译安装LAMP
USB 网卡驱动数据流
剑指 Offer 笔记: T58 - II. 左旋转字符串







