这几介绍一下openwrt 应用程序包开机自启动的两种方法 使用的平台是MTK7688开发板
首先写一个以及可以跑起来的工程,这里对工程就不做展开,以helloworld工程为例:
helloworld工程写在:openwrt/package/helloworld 下
自启动脚本文件都是要的 文件为helloworld
#!/bin/sh /etc/rc.common
START=48
STOP=10
start()
{
service_start /bin/helloworld &
}
stop()
{
service_stop /bin/helloworld
}
restart()
{
stop
start
}
第一种方法:
可以参考如下方法:我是参考这个的过程实现的,但是有点出入
https://blog.csdn.net/sessos/article/details/78451007
https://blog.csdn.net/qq_15391889/article/details/97799474
概括的步骤就是:
1.1、在 openwrt/package/base-files/files/etc/init.d/下添加自启动脚本,就是上面那个文件
1.2、该目录下给脚本赋予可执行权限,运行命令 chmod +x helloworld
1.3、编译 make V=99
1.4、查看openwrt/build_dir/target-mipsel_24kc_musl/root-ramips/etc/init.d目录下是否生成helloworld文件
1.5、查看openwrt/build_dir/target-mipsel_24kc_musl/root-ramips/etc/rc.d目录下是否生成S48helloworld文件
S48就是脚本文件的 START=48 的这个值。
有这两个文件的生成,基本上编译后下载,运用之后,输入ps命令,就可以看到helloworld的是运行的了。
亲测可行。
第二种方法:
2.1、在openwrt/package/helloworld/ 下建立新文件夹files
2.2、在openwrt/package/helloworld/files添加自启动脚本
2.3、修改openwrt/package/helloworld/下的Makefile
include $(TOPDIR)/rules.mk
PKG_NAME:=helloworld
PKG_RELEASE:=1
PKG_BUILD_DIR := $(BUILD_DIR)/$(PKG_NAME)
include $(INCLUDE_DIR)/package.mk
define Package/helloworld
SECTION:=utils
CATEGORY:=Utilities
TITLE:=ROCO---Helloworld -- prints a snarky message
endef
define Package/helloworld/description
If you can't figure out what this program does, you're probably
brain-dead and need immediate medical attention.
endef
define Build/Prepare
mkdir -p $(PKG_BUILD_DIR)
$(CP) ./src/* $(PKG_BUILD_DIR)/
endef
define Package/helloworld/install
$(INSTALL_DIR) $(1)/bin
$(INSTALL_BIN) $(PKG_BUILD_DIR)/helloworld $(1)/bin/
$(INSTALL_DIR) $(1)/etc/init.d
$(INSTALL_BIN) ./files/helloworld $(1)/etc/init.d/helloworld
endef
$(eval $(call BuildPackage,helloworld))
这个Makefile很多地方都能一样
主要就是
define Package/helloworld/install
$(INSTALL_DIR) $(1)/bin
$(INSTALL_BIN) $(PKG_BUILD_DIR)/helloworld $(1)/bin/
# 这里不一样,增加这个
$(INSTALL_DIR) $(1)/etc/init.d
$(INSTALL_BIN) ./files/helloworld $(1)/etc/init.d/helloworld
endef
这个链接里面有Makefile的与非说明,想知道的更清楚的可以点开看一下:
https://oldwiki.archive.openwrt.org/zh-cn/doc/devel/packages
2.3、编译 make V=99
2.4、查看openwrt/build_dir/target-mipsel_24kc_musl/root-ramips/etc/init.d目录下是否生成helloworld文件
2.5、查看openwrt/build_dir/target-mipsel_24kc_musl/root-ramips/etc/rc.d目录下是否生成S48helloworld文件
S48就是脚本文件的 START=48 的这个值。
同样 亲测可行