当前位置:网站首页>Openwrt compilation driver module (write code at any position outside the openwrt source code, and compile independently in a modular manner.Ko)
Openwrt compilation driver module (write code at any position outside the openwrt source code, and compile independently in a modular manner.Ko)
2022-07-27 16:01:00 【xhoufei2010】
One 、 Hardware platform
MT7620(A9 kernel )
Two 、 software platform
1、Ubuntu 12.04
2、openwrt official 15.05 edition SDK Development kit
3、 ... and 、 Functional specifications
Recently, I am sorting openwrt The driver , But online information , Most of it is in openwr Source code package Under the table of contents , Create folder , And then in openwrt Compile under Directory . Although this method can be compiled , But it is not particularly convenient to maintain . For example, compile a module separately , It also depends on openwrt Of SDK package . such , Every time you need to add a drive module , All in SDK Create a directory under the package .
I prefer to drive the module to create a folder separately , The path is not restricted . This is convenient for code maintenance and management , And in git perhaps svn Easy to upload and download , And openwrt Source code SDK Subcontracting leave .
This article , The main introduction is , Anywhere , Create your own folders and write drivers , Then compile the driver module . The biggest advantage is , The path of the code is unlimited . If you need to modify a driver , Just download the driver file , There is no need to update the whole openwrt SDK Development kit .
Four 、 Operation steps
1、 To write C file
In any folder , For example, the path of this article is /home/test/ Write code , The name is “hello.c”.
#include <linux/init.h>
#include <linux/module.h>
#include <linux/kernel.h>
/* hello_init ---- Initialization function , Called when the module is loaded , If the load is successful, return 0 Otherwise return to non 0 value */
static int __init hello_init(void)
{
printk("I bear a charmed life.\n");
return 0;
}
/* hello_exit ---- Exit function , Called when the module is unloaded */
static void __exit hello_exit(void)
{
printk("Out, out, brief candle\n");
}
module_init(hello_init);
module_exit(hello_exit);
MODULE_LICENSE("GPL");2、 To write makefile
Compiled using makefile file , The file name is called “makefile”.
explain :
In this paper ,openwrt Of SDK The storage path of the development package is /home/sky/develop/openWrt/openwrt/
openwrt Download the kernel , The storage path is /home/sky/develop/openWrt/openwrt/build_dir/target-mipsel_24kec+dsp_glibc-2.21/linux-ramips_mt7620/linux-3.18.29/
openwrt Of gcc Cross compile toolchain , Path is :/home/sky/develop/openWrt/openwrt/staging_dir/toolchain-mipsel_24kec+dsp_gcc-4.8-linaro_glibc-2.21/bin/
For this article openwrt Of SDK package :
(1) The cross compiler tool chain is glibc2.21
(2) The target chip is selected as mt7620
stay makefile in , Illustrates the gcc and openwrt Of SDK Package path ,makefile The contents are as follows :
######################################## hello ################################
obj-m = hello.o
PWD=$(shell pwd)
KERNEL_DIR=/home/sky/develop/openWrt/openwrt/build_dir/target-mipsel_24kec+dsp_glibc-2.21/linux-ramips_mt7620/linux-3.18.29/
TOOLCHAIN="/home/sky/develop/openWrt/openwrt/staging_dir/toolchain-mipsel_24kec+dsp_gcc-4.8-linaro_glibc-2.21/bin/mipsel-openwrt-linux-gnu-"
###############################################################################
all:
make -C $(KERNEL_DIR) \
ARCH=mips \
CROSS_COMPILE=$(TOOLCHAIN) \
M=$(PWD) \
modules
clean:
rm -f *.ko
rm -f *.o
rm -f *.mod.c
rm -f *.mod.o
rm -f *.order
rm -f *.sysvers
#make command:
#make
#make clean
3、 compile
In the terminal , Compile , Enter the command : make
Need to clear , Then enter the command : make clean
边栏推荐
猜你喜欢

: 0xC0000005: 写入位置 0x01458000 时发生访问冲突----待解

keil 采用 makefile 实现编译

On juicefs

C language: string function and memory function

C language: function stack frame
![[sword finger offer] interview question 41: median in data flow - large and small heap implementation](/img/c3/7caf008b3bd4d32a00b74f2c508c65.png)
[sword finger offer] interview question 41: median in data flow - large and small heap implementation

Inter thread wait and wake-up mechanism, singleton mode, blocking queue, timer

网络原理(2)——网络开发

Analysis of spark task scheduling exceptions

DRF学习笔记(四):DRF视图
随机推荐
Spark 3.0 testing and use
初识MySQL数据库
[sword finger offer] interview question 46: translating numbers into strings - dynamic programming
Short video mall system, system prompt box, confirmation box, click blank to close the pop-up box
: 0xC0000005: 写入位置 0x01458000 时发生访问冲突----待解
[sword finger offer] interview question 52: the first common node of two linked lists - stack, hash table, double pointer
Voice live broadcast system -- a necessary means to improve the security of cloud storage
渗透测试-干货 | 80篇+网络安全面试经验帖(面试篇)
openwrt 增加RTC(MCP7940 I2C总线)驱动详解
【云享读书会第13期】FFmpeg 查看媒体信息和处理音视频文件的常用方法
UDP message structure and precautions
busybox login: can't execute '/bin/bash': No such file or directory 解决方法
台积电6纳米制程将于明年一季度进入试产
JS operation DOM node
Go language slow start - Basic built-in types
低代码是开发的未来吗?浅谈低代码平台
Network principle (2) -- network development
The shell script reads the redis command in the text and inserts redis in batches
[sword finger offer] interview question 54: the k-largest node of the binary search tree
Network principle (1) - overview of basic principles