Ubuntu配置OPENWRT开发环境

Ubuntu下配置OPENWRT开发环境

1.环境配置

sudo apt-get install gcc 
sudo apt-get install g++ 
sudo apt-get install patch 
sudo apt-get install bzip2 
sudo apt-get install make
sudo apt-get install gettext 
sudo apt-get install textinfo 
sudo apt-get install unzip 
sudo apt-get install libz-dev

sudo apt-get install binutils 
sudo apt-get install flex 
sudo apt-get install bison 
sudo apt-get install autoconf
sudo apt-get install sharutils 
sudo apt-get install subversion 
sudo apt-get install libncurses5-dev 
sudo apt-get install ncurses-term 
sudo apt-get install zlib1g-dev 
sudo apt-get install git-core
sudo apt-get install gawk
sudo apt-get install libssl-dev
sudo apt-get install asciidoc

最后一个安装时间较长,耐心等待。

2.下载openwrt

git clone git://git.openwrt.org/15.05/openwrt.git

3.添加软件扩展包

cd openwrt/
cp feeds.conf.default feeds.conf
./scripts/feeds update -a
./scripts/feeds install -a

4.编译

make defconfig

5.配置

make menuconfig

这里写图片描述
选择要编译的固件平台、型号,固件中要添加的功能和组件。

6.生成SDK

make menuconfig选上“Build the OpenWRT SDK”,保存,退出。

make V=99

完成后,在bin/ar71xx/目录下会生成SDK的压缩文件:OpenWrt-SDK-ar71xx-generic_gcc-4.8-linaro_uClibc-0.9.33.2.Linux-i686.tar.bz2

7.安装SDK

把上步生成的压缩文件放在任意目录,解压。

tar -zxvf OpenWrt-SDK-ar71xx-generic_gcc-4.8-linaro_uClibc-0.9.33.2.Linux-i686.tar.bz2

8.创建项目(例:helloworld)

mkdir helloword
cd helloword
touch helloword.c Makefile

helloworld.c文件的内容:

#include <stdio.h>
int main()
{
    printf(“hello my world!!!\n”);
    return 0;
}

Makefile文件的内容:

helloworld:helloworld.o
    cc -o helloworld hoelloworld.o
helloworld.o:helloworld.c
    cc -c helloworld.c
clean:
    rm *.o helloworld

9.生成包

cd OpenWrt-SDK/package
mkdir helloworld
cd hello world

把第8步的helloworld文件夹整体放入OpenWrt-SDK/package/helloworld中并改为src

touch Makefile 

Makefile文件的内容:

include $(TOPDIR)/rules.mk
PKG_NAME:=helloworld
PKG_VERSION:=5.0
PKG_RELEASE:=1.0
PKG_BUILD_DIR:= $(BUILD_DIR)/$(PKG_NAME)
include $(INCLUDE_DIR)/package.mk

define Package/$(PKG_NAME)
    SECTION:=utils
    CATEGORY:=Utilitie
    TITLE:=helloworld      -- i2c general program
    MAINTAINER:=asyncM
    DEPENDS:=+libc.so +libgcc_s.so.1 +libc.so.6
endef

define Package/$(PKG_NAME)/description
     general program
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/
    $(CP) /usr/lib/x86_64-linux-gnu/libc.so $(1)/bin/
    $(CP) /lib/x86_64-linux-gnu/libgcc_s.so.1 $(1)/bin/
    $(CP) /lib/x86_64-linux-gnu/libc.so.6 $(1)/bin/
ended

$(eval $(call BuildPackage,helloworld))

回到 OpenWrt-SDK 目录下,执行

make V=s

生成helloworld_1_ar71xx.ipk文件,可用find查看其位置

10.测试

将生成的helloworld_1_ar71xx.ipk文件用scp上传到目标路由器

scp helloworld_1_ar71xx.ipk root@IPaddr:

ssh登陆路由器,安装helloworld_1_ar71xx.ipk包

ssh root@IPaddr
root@OpenWrt:~# ls
helloworld_1_ar71xx.ipk
root@OpenWrt:~# opkg install helloworld_1_ar71xx.ipk 
Installing helloworld (1) to root...
Configuring helloworld.
root@OpenWrt:~# helloworld
hello my world!!!
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

天既明

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值