https://github.com/CyC2018/CS-Notes
在枯燥的程序工作激励我们直面一次一次挫败,继续鼓足勇气探究的原因是成就感。经历一次一次为什么,百度,谷歌出来的碎片拼接,最终实现一个小小目标的成就感居然有如此大的力量,感谢互联网知识时代,感谢那些知识的贡献者,无论是原创还是转发,都是线索,都最终帮助迷茫者走过一程。我写下我的微小收获,无论对错,也希望更多地人记录自己的经历,共同丰富知识宝库。
废话多说了。知识太多,详细了解可以慢慢来。先操刀开干。
第一步肯定是需要假定你已经编译过一个能运行的Widora openwrt 平台了。漫长的编译时间让墙内人痛苦不堪,那么医IPX插件的方式将会极大缩短时间,提高开发效率....所有的开发起步都是一个HELLOWORLD。那么我就来弄一个,能被widora openwrt运行的helloworld :
有1点非常重要,ubantu 14.04平台与widows不同,大小写敏感 ,所以坑里很多一字之差的谬误。
由于后期开发以插件形式运行,不整体编译openwrt 那么我就需要 SDK的配合。
openwrt解压的 GIT 目录下 执行: make menuconfig
选择上面的 build the openwrt SDK 和 Package the OpenWrt-based Toolchain
然后save
执行 make V=99
等候几分钟后会再 bin/ramips 目录里生成一个超级长的名字的压缩包
cd bin/ramips
ls
解压这个SDK 名字的文件。toolchain 暂时不用。
tar -xvf OpenWrt-SDK-ramips-mt7688_gcc-4.8-linaro_uClibc-0.9.33.2.Linux-x86_64.tar.bz2
cd OpenWrt-SDK-ramips-mt7688_gcc-4.8-linaro_uClibc-0.9.33.2.Linux-x86_64
ls 一下看看
package 目录就是我们写自己插件的地方。
cd package
mkdir helloworld
cd hellowrold
mkdir src
cd src
vim helloworld.c
抄了这个兄弟几句,哈哈
https://blog.csdn.net/hui523hui523hui523/article/details/38366427?utm_source=blogxgwz0
保存,然后再 vim Makefile 再抄几句
# build helloworld executable when user executes "make"
helloworld: helloworld.o
$(CC) $(LDFLAGS) helloworld.o -o helloworld
helloworld.o: helloworld.c
$(CC) $(CFLAGS) -c helloworld.c
# remove object files and executable when user executes "make clean"
clean:
rm *.o helloworld
保存 ,make 一下,然后运行一下
./helloworld
make clean 防止意外。
cd .. 回到helloworld 目录创建一个可以被 SDK识别的 Makefile 文件。
vim Makefile
##################https://blog.csdn.net/icy_river/article/details/48260859
# OpenWrt MakefileforHelloWorld program
#
#
# Most of the variables used here are defined in
# theincludedirectives below. We just need to
# specify a basic description of the package,
# where to build our program, where to find
# the source files, and where to install the
# compiled program on the router.
#
# Be very careful of spacing inthisfile.
# Indents should be tabs,notspaces,and
# there should be no trailing whitespace in
# lines that are not commented.
#
##############################################
include$(TOPDIR)/rules.mk
# Nameandrelease number ofthispackage
PKG_NAME:=helloworld
PKG_RELEASE:=1
# This specifies the directory where we're going to build the program.
# The root build directory, $(BUILD_DIR), is bydefaultthe build_mipsel
# directory in your OpenWrt SDK directory
PKG_BUILD_DIR := $(BUILD_DIR)/$(PKG_NAME)
include $(INCLUDE_DIR)/package.mk
# Specify package informationforthisprogram.
# The variables defined here should be self explanatory.
# If you are running Kamikaze,deletethe DESCRIPTION
# variable belowanduncomment the Kamikaze define
# directiveforthe description below
define Package/helloworld
SECTION:=utils
CATEGORY:=Utilities
TITLE:=HelloWorld -- prints a snarky message
endef
# Uncomment portion belowforKamikazeanddeleteDESCRIPTION variable above
define Package/HelloWorld/description
If you can't figure out whatthisprogram does, you're probably brain-deadandneed immediate medical attention.
endef
# Specify what needs to be done to prepareforbuilding the package.
# In ourcase, we need to copy the source files to the build directory.
# This is NOT thedefault. Thedefaultuses the PKG_SOURCE_URLandthe
# PKG_SOURCE which isnotdefined here to download the source from the web.
# In order to just build a simple program that we have just written, it is
# much easier todoitthisway.
define Build/Prepare
mkdir -p $(PKG_BUILD_DIR)
$(CP) ./src/* $(PKG_BUILD_DIR)/
endef
# We do not need to define Build/Configure or Build/Compile directives
# The defaults are appropriate for compiling a simple program such as this one
# Specify where and how to install the program. Since we only have one file,
# the HelloWorld executable, install it by copying it to the /bin directory on
# the router. The $(1) variable represents the root directory on the router running
# OpenWrt. The $(INSTALL_DIR) variable contains a command to prepare the install
# directory if it does not already exist. Likewise $(INSTALL_BIN) contains the
# command to copy the binary file from its current location (in our case the build
# directory) to the install directory.
define Package/HelloWorld/install
$(INSTALL_DIR) $(1)/bin
$(INSTALL_BIN) $(PKG_BUILD_DIR)/HelloWorld $(1)/bin/
endef
# This line executes the necessary commands to compile our program.
# The above define directives specify all the information needed, but this
# line calls BuildPackage which in turn actually uses this information to
# build a package.
$(eval $(call BuildPackage,HelloWorld))
复制以上内容存进Makefile 里。注意大小写。 以后用其他名称的时候 将helloworld 换掉即可。
好了,退回到 OpenWrt-SDK-ramips-mt7688_gcc-4.8-linaro_uClibc-0.9.33.2.Linux-x86_64 目录
make
cd bin/ramips/packages/base
ls
将 这个ipx 复制到openwrt板子上
到opkg 发挥作用了
opkg install HelloWorld_1_ramips_24kec.ipk
执行一下helloworld
成功!!此图有烂尾楼重建的嫌疑。不要疑惑。
https://blog.csdn.net/lingyizhangfankai/article/details/47007811
http://archive.openwrt.org/chaos_calmer/15.05.1/ramips/mt7688/packages/packages/