当前位置:网站首页>Openwrt build Hello ipk
Openwrt build Hello ipk
2022-07-06 16:08:00 【mrbone9】
We are in the actual work , Will develop their own functional modules
about Openwrt In terms of convenience, it can be like ko Install and uninstall at any time like file
So for Openwrt Speaking of , There is also a set ” standard “ New steps of :
1. stay package Add a module directory under the directory : hello
2. Add the corresponding file , like this
files: Store configuration files and startup scripts
The configuration file : The definition is uci Format
config globals 'globe'
option agent 'openwrt'
option url 'http://192.168.100.115:8080'
option delay '10'
The source code is customized by calling API
Store the configuration in
int read_conf( struct Hello *hello)
{
struct uci_context *ctx = uci_alloc_context();
if (!ctx)
{
fprintf(stderr, "No memory\n");
return 1;
}
getValue(ctx, "agent", hello->agent, sizeof(hello->agent));
getValue(ctx, "url", hello->url, sizeof(hello->url));
char delay[20];
getValue(ctx, "delay", delay, sizeof(delay));
hello->delay = atoi(delay);
uci_free_context(ctx);
return 0;
}
Then you can operate through the structure
The startup script :
#!/bin/sh /etc/rc.common
USE_PROCD=1
START=15
STOP=85
PROG=/bin/hello
validate_hello_section()
{
uci_validate_section hello globals globe \
'delay:range(1,200)'
}
start_service() {
echo "start HelloRoute!"
validate_hello_section || {
echo "hello validattion failed!"
return 1
}
procd_open_instance
procd_set_param command "$PROG" –f -w bjbook.net
procd_set_param respawn
procd_close_instance
}
service_triggers()
{
procd_add_reload_trigger "hello"
}
reload_service()
{
stop
start
}
START, STOP Variable : Determines the order of script execution
start(),stop(): Decide how to start and stop the service . We call directly here hello modular , So the boot will enable hello
custom(): The extension command uses , Not here for the time being
src: Store source code , And corresponding Makefile( Only for compiling source code )
all:
$(CC) $(CFLAGS) -luci hello.c -o hello
clean:
rm *.o hello
top floor Makefile: Including compilation and installation instructions , The control code is openwrt Compile and generate installation packages under the environment
1. mk The file import , Define package name , edition
include $(TOPDIR)/rules.mk
PKG_NAME:=hello
PKG_RELEASE:=1.0
2. Set package classification , such make menuconfig We can find it in the corresponding category
Set dependent variables libuci, In this way, the source code can call UCI Interface
Grammar use :+ Library name , Indicates that if the software package is selected , The library will be automatically selected
define Package/$(PKG_NAME)
SECTION:=net
CATEGORY:=Network
TITLE:=Hello utility
DEPENDS:=+libuci
URL:=https://blog.csdn.net/mrbone9?spm=1008.2028.3001.5343
MAINTAINER:[email protected]
endef
3. Compilation part : Create build directory , Copy the code to this directory
build_dir/target-i386_pentium4_musl/hello
define Build/Prepare
mkdir -p $(PKG_BUILD_DIR)
$(CP) ./src/* $(PKG_BUILD_DIR)/
endef
5. Install the parts :$(1) Represents the first parameter passed in
define Package/$(PKG_NAME)/install
$(INSTALL_DIR) $(1)/etc/config
$(INSTALL_CONF) ./files/hello.conf $(1)/etc/config/hello
$(INSTALL_DIR) $(1)/etc/init.d
$(INSTALL_BIN) ./files/hello.init $(1)/etc/init.d/hello
$(INSTALL_DIR) $(1)/usr/sbin
$(INSTALL_BIN) $(PKG_BUILD_DIR)/hello $(1)/usr/sbin/hello
endef
6. pack
$(eval $(call BuildPackage,$(PKG_NAME)))
compile :
When the files are ready, you can start compiling , Remember we set the category , Then you can select this module through the menu
$ make menuconfig
$ make package/hello/compile V=s
After completion, you can see the generated software package
install :
Copy ipk To Openwrt Running OS
uninstall :
Installed ipk You can view the actual name through the following command
call opkg To uninstall
opkg It's a package management tool , You can enter to check the specific command
Through the above steps, we build our own software package , The operation is as simple as this
The following chapters will study the code framework ,UCI,ubus,procd Waiting for content
边栏推荐
- Opencv learning log 13 corrosion, expansion, opening and closing operations
- 最全编程语言在线 API 文档
- 【练习-2】(Uva 712) S-Trees (S树)
- 信息安全-安全编排自动化与响应 (SOAR) 技术解析
- Nodejs crawler
- SSM框架常用配置文件
- Flink 使用之 CEP
- Quick to typescript Guide
- 信息安全-安全专业名称|CVE|RCE|POC|VUL|0DAY
- Information security - threat detection - Flink broadcast stream broadcaststate dual stream merging application in filtering security logs
猜你喜欢
D - function (HDU - 6546) girls' competition
Differential (one-dimensional, two-dimensional, three-dimensional) Blue Bridge Cup three body attack
mysql导入数据库报错 [Err] 1273 – Unknown collation: ‘utf8mb4_0900_ai_ci’
1010 things that college students majoring in it must do before graduation
Vs2019 initial use
Information security - threat detection engine - common rule engine base performance comparison
b站 实时弹幕和历史弹幕 Protobuf 格式解析
B - 代码派对(女生赛)
Matlab comprehensive exercise: application in signal and system
C language is the watershed between low-level and high-level
随机推荐
【练习-3】(Uva 442)Matrix Chain Multiplication(矩阵链乘)
Understand what is a programming language in a popular way
渗透测试 ( 7 ) --- 漏洞扫描工具 Nessus
【练习-1】(Uva 673) Parentheses Balance/平衡的括号 (栈stack)
Alice and Bob (2021 Niuke summer multi school training camp 1)
Flink 使用之 CEP
Opencv learning log 32 edge extraction
Research Report of cylindrical grinder industry - market status analysis and development prospect forecast
B - 代码派对(女生赛)
China exterior wall cladding (EWC) market trend report, technical dynamic innovation and market forecast
The most complete programming language online API document
Perform general operations on iptables
Penetration testing (5) -- a collection of practical skills of scanning King nmap and penetration testing tools
Differential (one-dimensional, two-dimensional, three-dimensional) Blue Bridge Cup three body attack
[exercise-3] (UVA 442) matrix chain multiplication
What is the difficulty of programming?
【练习4-1】Cake Distribution(分配蛋糕)
Matlab comprehensive exercise: application in signal and system
1903. Maximum odd number in string
【练习-10】 Unread Messages(未读消息)