https://github.com/CyC2018/CS-Notes
? ? ? ? 在枯燥的程序工作激勵(lì)我們直面一次一次挫敗,繼續(xù)鼓足勇氣探究的原因是成就感驻襟。經(jīng)歷一次一次為什么憨募,百度薯鳍,谷歌出來(lái)的碎片拼接,最終實(shí)現(xiàn)一個(gè)小小目標(biāo)的成就感居然有如此大的力量月而,感謝互聯(lián)網(wǎng)知識(shí)時(shí)代汗洒,感謝那些知識(shí)的貢獻(xiàn)者,無(wú)論是原創(chuàng)還是轉(zhuǎn)發(fā)父款,都是線索溢谤,都最終幫助迷茫者走過(guò)一程。我寫下我的微小收獲铛漓,無(wú)論對(duì)錯(cuò)溯香,也希望更多地人記錄自己的經(jīng)歷,共同豐富知識(shí)寶庫(kù)浓恶。
? ? ? ?廢話多說(shuō)了。知識(shí)太多结笨,詳細(xì)了解可以慢慢來(lái)包晰。先操刀開干。
第一步肯定是需要假定你已經(jīng)編譯過(guò)一個(gè)能運(yùn)行的Widora openwrt 平臺(tái)了炕吸。漫長(zhǎng)的編譯時(shí)間讓墻內(nèi)人痛苦不堪伐憾,那么醫(yī)IPX插件的方式將會(huì)極大縮短時(shí)間,提高開發(fā)效率....所有的開發(fā)起步都是一個(gè)HELLOWORLD赫模。那么我就來(lái)弄一個(gè)树肃,能被widora openwrt運(yùn)行的helloworld :
? ? ? ? 有1點(diǎn)非常重要,ubantu 14.04平臺(tái)與widows不同瀑罗,大小寫敏感 胸嘴,所以坑里很多一字之差的謬誤。
由于后期開發(fā)以插件形式運(yùn)行斩祭,不整體編譯openwrt 那么我就需要 SDK的配合劣像。
openwrt解壓的 GIT 目錄下 執(zhí)行: make menuconfig
選擇上面的 build the openwrt SDK? 和 Package the OpenWrt-based Toolchain
然后save
執(zhí)行 make V=99
等候幾分鐘后會(huì)再 bin/ramips 目錄里生成一個(gè)超級(jí)長(zhǎng)的名字的壓縮包
cd bin/ramips
ls
解壓這個(gè)SDK 名字的文件。toolchain 暫時(shí)不用摧玫。
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
抄了這個(gè)兄弟幾句,哈哈
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 一下,然后運(yùn)行一下
./helloworld
make clean 防止意外坏挠。
cd .. 回到helloworld 目錄創(chuàng)建一個(gè)可以被 SDK識(shí)別的 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))
復(fù)制以上內(nèi)容存進(jìn)Makefile 里。注意大小寫癞揉。 以后用其他名稱的時(shí)候 將helloworld 換掉即可纸肉。
好了溺欧,退回到?OpenWrt-SDK-ramips-mt7688_gcc-4.8-linaro_uClibc-0.9.33.2.Linux-x86_64 目錄
make?
cd bin/ramips/packages/base
ls
將 這個(gè)ipx 復(fù)制到openwrt板子上
到opkg 發(fā)揮作用了
opkg install HelloWorld_1_ramips_24kec.ipk
執(zhí)行一下helloworld?
成功0胤尽姐刁!此圖有爛尾樓重建的嫌疑。不要疑惑烦味。
https://blog.csdn.net/lingyizhangfankai/article/details/47007811
http://archive.openwrt.org/chaos_calmer/15.05.1/ramips/mt7688/packages/packages/