当前位置:网站首页>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.02. 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]
endef3. 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)/
endef5. 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
endef6. 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=sAfter 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 16 paperclip count
- Opencv learning log 29 -- gamma correction
- [exercise-7] crossover answers
- Penetration testing (5) -- a collection of practical skills of scanning King nmap and penetration testing tools
- Opencv learning log 15 count the number of solder joints and output
- Analysis of protobuf format of real-time barrage and historical barrage at station B
- 【高老师UML软件建模基础】20级云班课习题答案合集
- Path problem before dynamic planning
- 【练习-9】Zombie’s Treasure Chest
- 【练习-6】(PTA)分而治之
猜你喜欢

1323. Maximum number of 6 and 9

Gartner: five suggestions on best practices for zero trust network access

Information security - threat detection - Flink broadcast stream broadcaststate dual stream merging application in filtering security logs

Borg maze (bfs+ minimum spanning tree) (problem solving report)
![[teacher Gao UML software modeling foundation] collection of exercises and answers for level 20 cloud class](/img/57/bc6eda91f7263acda38b9ee8732318.png)
[teacher Gao UML software modeling foundation] collection of exercises and answers for level 20 cloud class

STM32 learning record: LED light flashes (register version)

Nodejs+vue网上鲜花店销售信息系统express+mysql

Penetration testing (5) -- a collection of practical skills of scanning King nmap and penetration testing tools

Penetration test (1) -- necessary tools, navigation

Data storage in memory & loading into memory to make the program run
随机推荐
[exercise -11] 4 values why sum is 0 (and 4 values of 0)
Determine the Photo Position
Differential (one-dimensional, two-dimensional, three-dimensional) Blue Bridge Cup three body attack
【高老师UML软件建模基础】20级云班课习题答案合集
基于web的照片数码冲印网站
【练习-10】 Unread Messages(未读消息)
Opencv learning log 24 -- Hough transform 2 (maximum interval and minimum length can be limited)
China potato slicer market trend report, technical dynamic innovation and market forecast
TCP's three handshakes and four waves
Ball Dropping
【练习-11】4 Values whose Sum is 0(和为0的4个值)
【练习-1】(Uva 673) Parentheses Balance/平衡的括号 (栈stack)
The most complete programming language online API document
渗透测试 ( 3 ) --- Metasploit Framework ( MSF )
【练习4-1】Cake Distribution(分配蛋糕)
Find 3-friendly Integers
Nodejs+vue online fresh flower shop sales information system express+mysql
STM32 how to use stlink download program: light LED running light (Library version)
[exercise-2] (UVA 712) s-trees
Opencv learning log 15 count the number of solder joints and output