[关闭]
@cyysu 2017-11-17T07:57:16.000000Z 字数 8270 阅读 1461

openwrt开发-源码编译

  • 时间:2017年11月6日10:32:34
  • 作者:Kali
  • 邮箱:cyysu.github.io@gmail.com/2869905223@qq.com/微信lwyx1413
  • 版本:4.0
  • 描述:测试openwrt

路由器开发


声明

本文编译遇到的所有问题均已经解决,出错问题的解决方案均在路由器开发目录下。

编译注意

务必源码存放路径为英文路径,不要带有中文
务必源码存放路径为英文路径,不要带有中文
务必源码存放路径为英文路径,不要带有中文

简介与配置

编译机器环境

  1. mj@DZ:~$ cat /etc/issue
  2. Ubuntu 16.04.3 LTS \n \l
  3. mj@DZ:~$ cat /proc/version
  4. Linux version 4.10.0-37-generic (buildd@lgw01-amd64-037) (gcc version 5.4.0 20160609 (Ubuntu 5.4.0-6ubuntu1~16.04.4) ) #41~16.04.1-Ubuntu SMP Fri Oct 6 22:42:59 UTC 2017
  5. mj@DZ:~$

安装所需依赖软件包

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

下载地址

  1. git clone git://git.openwrt.org/openwrt.git
  2. 或者下面这个
  3. git clone git://git.openwrt.org/15.05/openwrt.git

简介如下

  1. * packages - 提供众多库、工具等基本功能;也是其他feed所依赖的软件源,因此在安装其他feed前一定要先安装packages
  2. * luci - OpenWrt默认的GUIWEB管理界面)
  3. * xwrt - 另一种可替换LuCIGUI
  4. * qpe - DreamBox维护的基于Qt的图形界面,包含Qt2Qt4QtopiaOPIESMPlayer等众多图形界面。
  5. * device - DreamBox维护与硬件密切相关的软件,如ubootqemu等。
  6. * dreambox_packages - DreamBox维护的国内常用网络工具,如oh3cnjit8021xclient
  7. * desktop -
  8. * xfce - 基于Xorg的著名轻量级桌面环境。Xfce建基在GTK+2.x之上,它使用Xfwm作为窗口管理器。
  9. * efl - 针对enlightenment
  10. * phone - 针对fso, paroli

openwrt之间的依赖关系

  1. packages --> luci
  2. packages --> xwrt
  3. packages --> qpe
  4. packages --> device
  5. packages --> dreambox_packages
  6. packages --> desktop --> xfce
  7. packages --> desktop --> efl --> phone

比如可以按照下面的安装方式进行安装,然后在进行install -a 操作

  1. $ ./scripts/feeds install -p packages -a
  2. $ ./scripts/feeds install -p xwrt -a
  3. $ ./scripts/feeds install -p luci -a
  4. $ ./scripts/feeds install -p desktop -a
  5. $ ./scripts/feeds install -p efl -a
  6. $ ./scripts/feeds install -p phone -a

如果想要安装某个软件包,如下面的方式蓝牙的地方

  1. openwrt@DZ:~/openwrt$ ./scripts/feeds search bluetooth
  2. Search results in feed 'packages':
  3. bluelog Bluetooth scanner and logger
  4. bluelog-live Bluetooth scanner and logger (live output)
  5. bluez-daemon Bluetooth daemon
  6. bluez-examples Bluetooth python example apps
  7. bluez-libs Bluetooth library
  8. bluez-utils Bluetooth utilities
  9. gnunet-transport-bluetooth GNUnet bluetooth transport
  10. hidapi Library to talk to HID devices
  11. sbc sbc encoding library

然后我们就可以使用./scripts/feeds install 具体的包名

下面给出feeds详细的使用说明

  1. openwrt@DZ:~/openwrt$ ./scripts/feeds
  2. Usage: ./scripts/feeds <command> [options]
  3. Commands:
  4. list [options]: List feeds, their content and revisions (if installed)
  5. Options:
  6. -n : List of feed names.
  7. -s : List of feed names and their URL.
  8. -r <feedname>: List packages of specified feed.
  9. -d <delimiter>: Use specified delimiter to distinguish rows (default: spaces)
  10. -f : List feeds in feeds.conf compatible format (when using -s).
  11. install [options] <package>: Install a package
  12. Options:
  13. -a : Install all packages from all feeds or from the specified feed using the -p option.
  14. -p <feedname>: Prefer this feed when installing packages.
  15. -d <y|m|n>: Set default for newly installed packages.
  16. -f : Install will be forced even if the package exists in core OpenWrt (override)
  17. search [options] <substring>: Search for a package
  18. Options:
  19. -r <feedname>: Only search in this feed
  20. uninstall -a|<package>: Uninstall a package
  21. Options:
  22. -a : Uninstalls all packages.
  23. update -a|<feedname(s)>: Update packages and lists of feeds in feeds.conf .
  24. Options:
  25. -a : Update all feeds listed within feeds.conf. Otherwise the specified feeds will be updated.
  26. -i : Recreate the index only. No feed update from repository is performed.
  27. clean: Remove downloaded/generated files.

其中feeds默认下载的链接地址如下

  1. mj@DZ:/home/openwrt/openwrt$ cat feeds.conf.default
  2. src-git packages https://github.com/openwrt/packages.git
  3. src-git luci https://github.com/openwrt/luci.git
  4. src-git routing https://github.com/openwrt-routing/packages.git
  5. src-git telephony https://github.com/openwrt/telephony.git
  6. src-git management https://github.com/openwrt-management/packages.git
  7. src-git targets https://github.com/openwrt/targets.git
  8. #src-git oldpackages http://git.openwrt.org/packages.git
  9. #src-link custom /usr/src/openwrt/custom-feed

配置信息主要需要配置下面的信息。

  1. 配置主要包括 4 个部分
  2. Target system(目标系统)
  3. Package selection(软件包选择)
  4. Build system settings(编译系统设置)
  5. Kernel modules(内核模块配置)

详细的配置信息如下

  1. Target System (x86) #目标平台选择
  2. Target Images --->
  3. [*] ext4 #生成.EXT4.IMG文件
  4. Base system --->
  5. <*> block-mount
  6. <*> busybox ---> #用于今后`initramfs`支持,可以将所有lib编译到busybox
  7. [*] Customize busybox options
  8. Busybox Settings --->
  9. General Configuration --->
  10. [*] Support --install [-s] to install applet links at runtime
  11. [*] Don't use /usr
  12. Linux Module Utilities --->
  13. [*] modinfo
  14. [*] Simplified modutils
  15. [*] Accept module options on modprobe command line
  16. [*] Skip loading of already loaded modules
  17. (/lib/modules) Default directory containing modules
  18. Linux System Utilities --->
  19. [*] mdev
  20. [*] Support /etc/mdev.conf
  21. [*] Support subdirs/symlinks
  22. [*] Support regular expressions substitutions when renaming
  23. [*] Support command execution at device addition/removal
  24. [*] Support loading of firmwares
  25. [*] findfs
  26. [*] blkid
  27. [*] Print filesystem type
  28. [*] losetup
  29. [*] lspci
  30. [*] lsusb
  31. [*] mount
  32. [*] Support specifying devices by label or UUID
  33. Filesystem/Volume identification --->
  34. [*] Ext filesystem
  35. [*] fat filesystem
  36. Networking Utilities --->
  37. [*] ftpd
  38. [*] Enable upload commands
  39. [*] Enable workaround for RFC-violating clients
  40. [*] inetd
  41. [*] telnetd
  42. [*] Support standalone telnetd (not inetd only)
  43. [*] tcpsvd
  44. [*] udpsvd
  45. `kernel` modules --->
  46. Block Devices --->
  47. <*> kmod-ata-core
  48. <*> kmod-ata-ahci
  49. <*> kmod-loop
  50. -*- kmod-scsi-core
  51. <*> kmod-scsi-generic
  52. Filesystems --->
  53. <*> kmod-fs-ext4
  54. <*> kmod-fs-ntfs
  55. <*> kmod-fs-vfat
  56. Input modules --->#键盘
  57. -*- kmod-hid
  58. <*> kmod-hid-generic
  59. -*- kmod-input-core
  60. -*- kmod-input-evdev
  61. Native Language Support --->
  62. <*> kmod-nls-cp437 #vfat需要这个
  63. <*> kmod-nls-iso8859-1
  64. <*> kmod-nls-utf8
  65. Network Devices ---> #网卡驱动
  66. <*> kmod-macvlan
  67. USB Support --->
  68. -*- kmod-usb-core
  69. <*> kmod-usb-hid #usb键盘
  70. <*> kmod-usb-ohci
  71. <*> kmod-usb-storage
  72. <*> kmod-usb2
  73. <*> kmod-usb3
  74. Wireless Drivers --->#wifi卡驱动
  75. Network --->
  76. <*> hostapd #wifi ap模式
  77. <*> hostapd-common
  78. <*> hostapd-utils
  79. <*> wpa-supplicant
  80. Utilities --->#自选 fdisk等

于此同时我们还可以单独对内核进行配置。
make kernel_menuconfig

  1. Processor type and features --->
  2. [*] Symmetric multi-processing support
  3. Processor family (Core 2/newer Xeon) --->#自行选择处理器平台
  4. [*] Supported processor vendors --->#自行选择处理器平台
  5. (2) Maximum number of CPUs #自行编辑
  6. [*] SMT (Hyperthreading) scheduler support#超线程支持
  7. [*] Multi-core scheduler support
  8. High Memory Support (4GB) --->

修改内核版本

如果想要更换内核版版本可以如下这么做

链接地址:http://blog.csdn.net/flexman09/article/details/51862858

修改root用户操作

  1. 直接修改include/prereq-build.mk这个文件,在最新的版本中已经去掉这个限制了。

编译之后结果

  1. mj@DZ:/home/openwrt/openwrt$ ls
  2. bin Config.in feeds.conf.default LICENSE rules.mk tmp
  3. BSDmakefile dl include Makefile scripts toolchain
  4. build_dir docs key-build package staging_dir tools
  5. config feeds key-build.pub README target
  6. # 查看对应的目标平台
  7. mj@DZ:/home/openwrt/openwrt$ ls bin/x86/
  8. md5sums openwrt-x86-64-rootfs-squashfs.img
  9. openwrt-x86-64-combined-ext4.img.gz openwrt-x86-64-vmlinuz
  10. openwrt-x86-64-combined-squashfs.img packages
  11. openwrt-x86-64-generic-rootfs.tar.gz sha256sums
  12. openwrt-x86-64-rootfs-ext4.img.gz
  13. mj@DZ:/home/openwrt/openwrt$

交叉工具编译问题

  1. make toolchain/clean V=99 -j
  2. make toolchain/compile V=99 -j
  3. 具体解决方法连接如下:

http://see.sl088.com/wiki/Openwrt_%E7%BC%96%E8%AF%91toolchain%E5%87%BA%E9%94%99

文件找不到错误

如果出现这个问题那么可以按照下图操作一下。

将其中文件夹下的软件应用程序复制到指定目录下面。出现这个问题的原因可能是编译成功一次之后有些内容不会重新编译,这样有些文件他又需要用到,就造成了文件找不到。

如果出现下面这个情况,你用root用户去编译就可以。但是在没有出现之前不要用root用户去编译,原因是你的openwrt源码可能是不允许root编译。

如果以上无法解决问题,可以尝试清除编译文件,然后重新编译。

编译文件格式转换

  1. # 如果需要用到将img文件格式文件转换为vmware虚拟机的格式,可以采用如下方式转换
  2. qemu-img convert -f raw openwrt-15.05-x86.img -O vmdk openwrt.vmdk

总结

编译过程还是比较顺利的,中间遇到几次下载文件出错的问题,所以这里建议大家在进行编译的时候采用make V=99进行编译,同时建议最好不要用make -j参数进行编译。下面我给出我这里编译成功的完整openwrt。

实验效果

  1. 我这边测试时用VMware去启动怎么都启动不了,但是通过做U盘镜像的方式在电脑上运行就可以运行。这个原因目前还不知道,虚拟机中一直停留在下面这个界面。后面继续了解openwrt之后再更新这里。

启动u盘做出来之后的效果是下图这样,记住不要格式化之后的启动盘。

那么上图的10M和48M这空间是如何划分的呢?我们看一下我们menuconfig的界面

也就是说这个10M是内核大小空间,48M是根文件系统大小。

运行配置

登录界面如下

当我们登录系统之后先设置完ip地址,首先让这个路由器先上网。我这里演示的也是先配置完ip,在做的教程记录。

  1. # 网络配置
  2. root@OpenWrt:~# cat /etc/config/network
  3. config interface 'loopback'
  4. option ifname 'lo'
  5. option proto 'static'
  6. option ipaddr '127.0.0.1'
  7. option netmask '255.0.0.0'
  8. config globals 'globals'
  9. option ula_prefix 'fdf2:a041:a1ba::/48'
  10. config interface 'lan'
  11. option type 'bridge'
  12. option ifname 'eth0'
  13. option proto 'dhcp'

然后就是配置一下我们的web界面,如果你在编译的时候没有安装,那么我们可以等路由器连上网之后我们在进行下载安装。详细的步骤如下:

  1. # 依次执行下面命令
  2. opkg update
  3. opkg install luci
  4. /etc/init.d/uhttpd start
  1. root@OpenWrt:~# netstat -ntulp
  2. Active Internet connections (only servers)
  3. Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
  4. tcp 0 0 127.0.0.1:20001 0.0.0.0:* LISTEN 2573/autossh
  5. tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 4897/uhttpd
  6. tcp 0 0 0.0.0.0:53 0.0.0.0:* LISTEN 2515/dnsmasq
  7. tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 1352/dropbear
  8. tcp 0 0 127.0.0.1:6010 0.0.0.0:* LISTEN 5701/dropbear
  9. tcp 0 0 :::80 :::* LISTEN 4897/uhttpd
  10. tcp 0 0 :::53 :::* LISTEN 2515/dnsmasq
  11. tcp 0 0 :::22 :::* LISTEN 1352/dropbear
  12. udp 0 0 0.0.0.0:53 0.0.0.0:* 2515/dnsmasq
  13. udp 0 0 0.0.0.0:5353 0.0.0.0:* 1440/avahi-daemon:
  14. udp 0 0 :::53 :::* 2515/dnsmasq
  15. udp 0 0 :::547 :::* 1303/odhcpd
  16. udp 0 0 :::5353 :::* 1440/avahi-daemon:

执行完之后我们就可以登录我们的web界面了

下面就是我们的开发了。这个就单独另外写一篇文章进行整理了。

教程参考

openwrt x86 编译部署

打赏

                    支付宝                                                         微信

微信与支付宝支付

添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注