在openwrt添加并单独调试应用代码的方法记录

在openwrt添加并单独调试应用代码的方法记录

概述

往往应用代码会反复修改调试,如果每次都在系统集成应用程序然后刷系统版本的这种方法过于繁琐,下面将添加及单独调试应用代码的方法记录如下,便于以后查看。

步骤1:添加代码及makefile

在./package文件夹下创建应用程序文件夹example,其中包括Makefile及src文件夹,src文件夹下包括main.c源代码文件和Makefile。
其中,example下的Makefile内容如下:

#:
# Top level makefile for example application
# 
include $(TOPDIR)/rules.mk
PKG_NAME:=example
PKG_VERSION:=1.0.0
PKG_RELEASE:=1
include $(INCLUDE_DIR)/package.mk
define Package/example
SECTION:=utils
CATEGORY:=Utilities
TITLE:=example -- prints example 1 to 99
endef
define Build/Prepare
	mkdir -p $(PKG_BUILD_DIR)
	$(CP) ./src/* $(PKG_BUILD_DIR)
endef 
define Build/Configure
endef
TARGET_CFLAGS += $(FPIC)
define Package/example/install
	$(INSTALL_DIR) $(1)/bin
	$(INSTALL_BIN) $(PKG_BUILD_DIR)/example $(1)/bin/
endef


$(eval $(call BuildPackage,example))

src文件夹下的Makefile如下:

# build executable on typing make
#all: example 
#%.o: %.c
#	$(CC) $(CFLAGS) $(EXTRA_CFLAGS) -c -I. -Iinclude -o $@ $^
#example: main.o
#	$(CC) -o $@ $^ -L.
#clean:
#	rm -f *.o example
# build helloworld executable when user executes "make"
 
example: main.o
	$(CC) $(LDFLAGS) main.o -o example
#	$(info $(CC) )
#	$(info $(LDFLAGS) )		
#	@echo $(CC)
#	@echo $(LDFLAGS)
 
main.o: main.c
	$(CC) $(CFLAGS) -c main.c
#	$(info $(CC) )
#	$(info $(CFLAGS) )
#	@echo $(CC)	
#	@echo $(CFLAGS)
 
# remove object files and executable when user executes "make clean"
clean:
	rm *.o example

步骤2:编译脚本

避免每次手敲,写了个简单的编译脚本如下:
rm -rf /home/wooya/nfs_share/example_1.0.0-1_ramips_24kec.ipk
rm -rf /home/wooya/openwrt/openwrt-hiwooya/bin/ramips/packages/base/example_1.0.0-1_ramips_24kec.ipk
cd /home/wooya/openwrt/openwrt-hiwooya/
make V=s package/example/compile
make package/example/install
make package/index

cp /home/wooya/openwrt/openwrt-hiwooya/bin/ramips/packages/base/example_1.0.0-1_ramips_24kec.ipk /home/wooya/nfs_share/

其中/home/wooya/nfs_share是NFS网络共享文件夹,便于开发主机与设备之间传输共享文件。

步骤3:执行脚本

在设备上自己写了个执行脚本,避免每次手敲,用于执行生成的应用程序,脚本如下:

#mount -t nfs -o nolock 192.168.8.207:/home/wooya/nfs_share /mnt
cd /bin/
opkg remove example
cd /mnt/
opkg install example_1.0.0-1_ramips_24kec.ipk
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值