




版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、之前写过一篇日志, 是关于如何搭建自己的 OpenWRT开发环境。经过最近一段时间的开发 学习和实践,对 OpenWRT环境的开发有了一定的了解。在这里将我的开发心得做个整理。1搭建开发环境首先,我们需要一个为路由器定制的开发环境,具体可以参考我的另一篇日志:搭建自己的OpenWrt开发环境。这里只做一个简单的补充,在执行 make menuconfig后,会出现下图:*ld the L;3enr: sssed ToGlchsin _ Ir.ige ccn:izuraticn :Base sys-fti IPv6 Libraries 一 Wl;1t ilt i1ii *-Eiczra 口国匚k
2、agesSound.亠一其中,图中红框部分是我定制路由器的系统版本,大家可以根据不同的路由器进行不同的选择;绿框部分表示我们需要编译一个SDK开发环境(默认情况下,此项未勾选)。编译过程中需要通过官网下载很多相关的软件包,所以必须保证能够顺利连上外网。由于下载速度的限制,编译过程大概需要数小时。编译结束后,所有的产品都会放在编译根目录下的bin/yourtarget/.例如:我所编译的产物都放在 ./bin/brcm47xx/下,其中文件主要有几类:(1) .bin/.trx文件:这些都是在我们所选的target-system的类别之下,针对不同路由器型号、版本编译的路由器固件。这些不同路由器
3、的型号和版本是openwrt预先设置好的,我们不需要更改。至于.bin和.trx的区别,一种说法是,第一次刷路由器的时候,需要用.bin 文件,如果需要再升级,则不能再使用.bin文件,而需要用.trx文件。原因是,.bin是将路由器的相关配置信息和.trx 封装在一起而生成的封包,也就是说是包含路由器版本信息的.trx。在第一次刷固件的时候,我们需要提供这样的信息,而在后续升级时,则不再需要,用.trx文件即可。(2)packages文件夹:里面包含了我们在配置文件里设定的所有编译好的软件包。默认情 况下,会有默认选择的软件包。(3) OpenWrt-SDK.*.tar.bz2:这个也就是我
4、们定制编译好的 OpenWRSDK环境。我们将 用这个来进行OpenWrt软件包的开发。例如,我所编译好的SDK环境包为: /bin/brcm47xx/Ope nWrt-SDK-brcm47xx-for-L in ux-x86_64-gcc-4.3.3+cs_uClibc-0.9.30.1. tar.bz2可以从名称上看出, target system 是 brcm47xx ,host system 是 Linux-x86_64 ,使用的编 译工具以及库是 4.3.3+cs_uClibc-0.9.30.1 。(4) md5sums文件:这个文件记录了所有我们编译好的文件的MD5直,来保证文件的
5、完整性。因为文件的不完整,很容易将路由器变成“砖头” 。需要主要的是, 编译完成后, 一定要将编译好的 bin 目录进行备份 (如果里面东西对你很重 要的话),因为在下次编译之前,执行 make clean 会将 bin 目录下的所有文件给清除掉 !2、更改原有 packages在编译根目录下会有一个 dl的目录,这个目录其实是download ”的简写,在编译前期, 需要从网络下载的数据包都会放在这个目录下, 这些软件包的一个特点就是, 会自动安装在 所编译的固件中,也就是我们 make menuconfig 的时候,为固件配置的一些软件包。如果我 们需要更改这些源码包,只需要将更改好的源码
6、包打包成相同的名字放在这个目录下,然后开始编译即可。编译时,会将软件包解压到 build_dir 目录下。当然,你也可以自己在dl 里面创建自己的软件包,然后更改相关的配置文件,让openwrt可以识别这个文件包。由于我的项目更改的内容是底层的, 需要跟固件一起安装。 所以, 我使用的方法就是直接更 改 dl 目录下软件包,然后重新进行固件编译。感觉类似于 Linux 的内核编译。反复编过十 多次,没有任何问题。3、新建自己的 packages对于自己新建的 package ,而这个 package 又不需要随固件一起安装,换句话说,就是可以 当做一个可选软件包的话。我们可以利用我们的SDK环
7、境来单独编译,编译后会生成一个ipk 的文件包。然后利用 opkg install xxx.ipk来安装这个软件。下面具体说下,如何编译一个 helloword 的软件包。( 1)首先,编写 helloworld 程序编写 helloworld.c/* Helloworld.c* The most simplistic C program ever written.* An epileptic monkey on crack could write this code.*/#include #include int main(void)printf(Hell! O world, why won
8、t my code compile?nn); return 0;编写 Makefile 文件# build helloworld executable when user executes makehelloworld: helloworld.o$(CC) $(LDFLAGS) helloworld.o -o helloworldhelloworld.o: helloworld.c$(CC) $(CFLAGS) -c helloworld.c# remove object files and executable when user executes make cleanclean:rm *.
9、o helloworld在这两个文件的目录下,执行 make 应该可以生成 helloworld 的可执行文件。执行 helloworld 后,能够打印出“ Hell! O world, why wont my code compile? ”。 这一步, 主要保证我们的源程序是可以正常编译的。下面我们将其移植到Ope nWR上。(2)将OpenWrt-SDK-brcm47xx-for-Linux-x86_64-gcc-4.3.3+cs_uClibc-0.9.30.1.tar.bz2解压tar- xvfOpenWrt-SDK-brcm47xx-for-Linux-x86_64-gcc-4.3.3
10、+cs_uClibc-0.9.30.1.tar.bz2(3)进入 SDKcd OpenWrt-SDK-brcm47xx-for-Linux-x86_64-gcc-4.3.3+cs_uClibc-0.9.30.1 可以看到里面的目录结构跟我们之前 source 的目录结构基本相同,所需要编译的软件包, 需要放置在 package 目录下(4)在 package 目录下创建 helloworld 目录cd packagemkdir helloworldcd helloworld( 5)创建 src 目录,拷贝 helloworld 文件mkdir srccp /home/wrt/test/hell
11、oworld.c srccp /home/wrt/test/Makefile src(6)在 helloworld 目录下创建 Makefile 文件这个Makefile 文件是给 OpenWR读的,而之前写的那个Makefile 文件是针对helloworld给编译其读的。两个 Makefile 不在同一层目录下。touch Makefile vim MakefileMakefile 文件模板内容如下:II II II II II II II II II II II II II II II II II II II II II II II II II II II II II II II II
12、II II II II II II II II II II II II II II a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a# OpenWrt Makefile for helloworld program# Most of the variables used here are defined in# the include directives below. We just need to# specify a basic description o
13、f 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 in this file.# Indents should be tabs, not spaces, and# there should be no trailing whitespace in# lines that are not commented.#a a a a
14、a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a ainclude $(TOPDIR)/rules.mk# Name and release number of this package PKG_NAME:=helloworldPKG_RELEASE:=1# This specifies the di
15、rectory where were going to build the program.# The root build directory, $(BUILD_DIR), is by default the build_mipsel# directory in your OpenWrt SDK directory PKG_BUILD_DIR := $(BUILD_DIR)/$(PKG_NAME)include $(INCLUDE_DIR)/package.mk# Specify package information for this program.# The variables def
16、ined here should be self explanatory.# If you are running Kamikaze, delete the DESCRIPTION# variable below and uncomment the Kamikaze define# directive for the description below define Package/helloworldSECTION:=utilsCATEGORY:=UtilitiesTITLE:=Helloworld - prints a snarky message endef# Uncomment por
17、tion below for Kamikaze and delete DESCRIPTION variable above define Package/helloworld/descriptionIf you cant figure out what this program does, youre probably brain-dead and need immediate medical attention. endef# Specify what needs to be done to prepare for building the package.# In our case, we
18、 need to copy the source files to the build directory.# This is NOT the default. The default uses the PKG_SOURCE_URL and the# PKG_SOURCE which is not defined 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 to do it this
19、 way.define Build/Preparemkdir -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 hav
20、e one file,# the helloworld executable, install it by copying it to the /bin directory onrunning# the router. The $(1) variable represents the root directory on the router# 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_DI
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 中国卫浴镜行业市场发展现状及投资战略咨询报告
- 线框项目投资可行性研究分析报告(2024-2030版)
- 税务师网校课件评价
- 星空主题商业计划书
- 2024年中国金属铥行业市场深度评估及投资方向研究报告
- 弹簧酒架项目投资可行性研究分析报告(2024-2030版)
- 2025年中国品牌燕麦片(麦片) 未来发展趋势分析及投资规划建议研究报告
- 中国凤凰木行业市场发展现状及投资潜力预测报告
- 2025-2030年中国化肥检测筛行业深度研究分析报告
- 2025年中国冲洗器市场运行格局及投资战略研究报告
- 餐饮老人临时用工协议书
- T/SHSOT 015.1-2024皮肤角质层胶带剥离方法及应用第1部分:角质层剥离方法
- 2025甘肃省农垦集团有限责任公司招聘生产技术人员145人笔试参考题库附带答案详解
- 2025至2030年中国豆角丝行业投资前景及策略咨询报告
- 消防心理测试题或答案及答案
- 全国中级注册安全工程师考试《其他安全》真题卷(2025年)
- 南开大学-商业健康保险与医药产业高质量协同发展-团体补充医疗保险改革新视角-2025年3月20日
- 弱电安防施工安全培训
- 电梯维保半年工作总结
- 12《寻找生活中的标志》(教学设计)-2023-2024学年二年级上册综合实践活动鲁科版
- 七年级道法下册 第二学期 期末综合测试卷(人教海南版 2025年春)
评论
0/150
提交评论