OpenWRT环境搭建

我的机器主系统是Windows 7,用于op开发装了VirtualBox和Ubuntu 12.04 LTS。

首先,解决依赖问题,开发op必备如下组件。

#sudo apt-get install build-essential subversion git-core libncurses5-dev zlib1g-dev gawk flex quilt libssl-dev xsltproc libxml-parser-perl mercurial bzr ecj cvs unzip

接下来下载源代码,需要用到svn工具,下载最新开发版代码命令如下:

#svn co svn://svn.openwrt.org/openwrt/trunk

因源码随时可能变动,下载后,运行snv up更新本地代码。

下载后一般额外软件包需要更新:

#./scripts/feeds update -a

# ./scripts/feeds install -a

编译必须保证有良好的网络连接,且非root账户。

下一步是检查编译环境:

#make defconfig

若defconfig回显提示缺少软件包或编译库等依赖,则按提示安装所缺软件包或库等即可

接下来是配置:

#make menuconfig

比如:

编译一个mr3420的固件

1.Target System—–选择Atheros AR71xx/AR7240/AR913x/AR934x

2.Target Profile—-选择TP-LINK TL-MR3420 v1

3.LuCI—-选择Collections—– <*> luci

4.LuCI—-选择Translations—-<*> luci-i18n-chinese

5.Exit—-Yes

6.开始编译make V=99,最后会得到一个4M的带中文luci的mr3420固件。 MR3420的8M固件编译方法

1.在路径 /trunk/tools/firmware-utils/src/mktplinkfw.c 这个文件里边有个“fw max len”,默认3c0000是4M的,请改成7c0000 (这一步把固件最大限制改成8M),如果是16mflash,请改成fc0000(最大限制改成16m)。

2、修改target/linux/ar71xx/files/arch/mips/ar71xx/mach-tl-wr841n.c(找相应文件)

4M:

41 .name = “u-boot”,

42 .offset = 0,

43 .size = 0x020000,

44 .mask_flags = MTD_WRITEABLE,

45 }, {

46 .name = “kernel”,

47 .offset = 0x020000,

48 .size = 0x140000,

49 }, {

50 .name = “rootfs”,

51 .offset = 0x160000,

52 .size = 0x290000,

53 }, {

54 .name = “art”,

55 .offset = 0x3f0000,

56 .size = 0x010000,

57 .mask_flags = MTD_WRITEABLE,

58 }, {

59 .name = “firmware”,

60 .offset = 0x020000,

61 .size = 0x3d0000,

62 }

63 };

8M::

41 .name = “u-boot”,

42 .offset = 0,

43 .size = 0x020000,

44 .mask_flags = MTD_WRITEABLE,

45 }, {

46 .name = “kernel”,

47 .offset = 0x020000,

48 .size = 0x140000,

49 }, {

50 .name = “rootfs”,

51 .offset = 0x160000,

52 .size = 0x690000,

53 }, {

54 .name = “art”,

55 .offset = 0x7f0000,

56 .size = 0x010000,

57 .mask_flags = MTD_WRITEABLE,

58 }, {

59 .name = “firmware”,

60 .offset = 0x020000,

61 .size = 0x7d0000,

62 }

63 };

16M::

41 .name = “u-boot”,

42 .offset = 0,

43 .size = 0x020000,

44 .mask_flags = MTD_WRITEABLE,

45 }, {

46 .name = “kernel”,

47 .offset = 0x020000,

48 .size = 0x140000,

49 }, {

50 .name = “rootfs”,

51 .offset = 0x160000,

52 .size = 0xe90000,

53 }, {

54 .name = “art”,

55 .offset = 0xff0000,

56 .size = 0x010000,

57 .mask_flags = MTD_WRITEABLE,

58 }, {

59 .name = “firmware”,

60 .offset = 0x020000,

61 .size = 0xfd0000,

62 }

63 };

8M::

0x000000000000-0x000000020000 : “u-boot”

0x000000020000-0x000000160000 : “kernel”

0x000000160000-0x0000007f0000 : “rootfs”

0x000000620000-0x0000007f0000 : “rootfs_data”

0x0000007f0000-0x000000800000 : “art”

0x000000020000-0x0000007f0000 : “firmware”

4M::

0x000000000000-0x000000020000 : “u-boot”

0x000000020000-0x000000160000 : “kernel”

0x000000160000-0x0000003f0000 : “rootfs”

0x000000304000-0x0000003f0000 : “rootfs_data”

0x0000003f0000-0x000000400000 : “art”

0x000000020000-0x0000003f0000 : “firmware”

16M::

0x000000000000-0x000000020000 : “u-boot”

0x000000020000-0x000000160000 : “kernel”

0x000000160000-0x000000ff0000 : “rootfs”

0x000000380000-0x000000ff0000 : “rootfs_data”

0x000000ff0000-0x000001000000 : “art”

0x000000020000-0x000000ff0000 : “firmware”

最后是编译,其实编译命令最简单

#make

如果是多核CPU,可以增加参数,常规用法为 <您cpu处理器的数目 + 1> – 例如使用3进程来编译 (即双核CPU), 命令如下:

#make -j 3

如果想看到编译过程中的错误信息,可以增加一个V=99或者V=s的参数。

生成镜像(Image)位置

新生成的镜像会默认放在新建的一个bin目录下。例如:/bin/brcm-2.4/packages

[openwrt@localhost trunk]$ ls bin/*

将编译好的镜像做个备份,例如备份到/目录下:

[openwrt@localhost trunk]$ cp bin /

清理工作

建议现在清理编译产生的文件,以免下次编译时造成冲突,(文件如果存在的话,将不会被替换),执行make clean

注意:在执行clean命令,确保已经将编译好的image进行了备份。清理工作会清楚bin目录。

[openwrt@localhost trunk]$ make clean

除了清除生成的目录,还想清除交叉编译工具(以及工具链目录)

[openwrt@localhost trunk]$ make dirclean

清除所有相关的东西,包括下载的软件包,配置文件,,feed内容等:(不建议使用)

[openwrt@localhost trunk]$ make distclean

对于更新feeds后出现的错误:

ERROR:please fix package/feeds/packages/mc/Makefile 等类似的问题,需要执行这条语句进行系统的清理

本文永久更新链接地址:

生活会变成什么样子?正因为时光流逝一去不复返,

OpenWRT环境搭建

相关文章:

你感兴趣的文章:

标签云: