openwrt 编译外部源码 过程与问题解决

1、openwrt 基本介绍

openwrt 是一个编译工具,帮助自定义编译内核和应用(我的理解)。所以如果有定制自己需要的内核,并基于这个定制化内核编译一些应用的话,可以使用openwrt,openwrt 还是很成熟,很方便的。

(PS:最开始不知道openwrt的时候,我是自己配置编译环境,然后自己编译应用,当然是很复杂的,又要应用和内核版本一致,又有各种规范,一个OVS编了好久才编好;而使用openwrt ,只需要勾选上自己想要的应用就可以了(openwrt 应用源中的应用很多,基本满足我的需求),所以推荐大家使用openwrt)

我使用的openwrt 版本是:19.07.1,想要移植到的平台是:Xilinx ZC702。

2、编译前准备

openwrt源码下载:

        网址是:https://github.com/openwrt/openwrt

                这个不用记,直接谷歌里面输:openwrt github 第一个就是。

        下载:git clone https://github.com.cnpmjs.org/openwrt/openwrt.git .

外部源码准备:

        你需要使用的源码,放在一个位置。

        .config 配置文件

其他应用或者库:

        这个是说有些库或者软件openwrt 确实没有,那么你可以准备下这些库或者软件的源码,借助 openwrt去帮你编译。

        (PS:当然,你不可能一上来就知道哪个库或者软件openwrt 没有,都是先进入到openwrt 里面,make menuconfig ,找一找,搜一搜,发现确实没有的话,你再去准备下这些东西。)

3、开始编译工作

选择版本:

        git tag 看看有哪些版本,我是因为openwrt 对ZC702 的支持从19.07.1 才开始,所以选择这个版本,大家可以根据需求选择版本。

        git checkout 版本号(直接复制git tag给出的某一个版本)

更新openwrt 库并下载:

        ./scripts/feeds update -a         #更新feeds软件源

        ./scripts/feeds install -a        #下载更新

功能选择:

        make menuconfig 

 .config - OpenWrt Configuration
 qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq
  lqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq OpenWrt Configuration qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqk
  x  Arrow keys navigate the menu.   selects submenus ---> (or empty submenus ----).  Highlighted letters x  
  x  are hotkeys.  Pressing  includes,  excludes,  modularizes features.  Press  to exit,  x  
  x  for Help,  for Search.  Legend: [*] built-in  [ ] excluded   module  < > module capable               x  
  x                                                                                                              x  
  x lqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqk x  
  x x                      Target System (Xilinx Zynq 7000 SoCs)  --->                                         x x  
  x x                      Target Profile (Xilinx ZC702)  --->                                                 x x  
  x x                      Target Images  --->                                                                 x x  
  x x                      Global build settings  --->                                                         x x  
  x x                  [*] Advanced configuration options (for developers)  --->                               x x  
  x x                  [ ] Build the OpenWrt Image Builder                                                     x x  
  x x                  [ ] Build the OpenWrt SDK                                                               x x  
  x x                  [ ] Package the OpenWrt-based Toolchain                                                 x x  
  x x                  [ ] Image configuration  --->                                                           x x  
  x x                      Base system  --->                                                                   x x  
  x x                      Administration  --->                                                                x x  
  x x                      Boot Loaders  ----                                                                  x x  
  x x                      Development  --->                                                                   x x  
  x x                      Extra packages  --->                                                                x x  
  x mqqqqqqqqqqqqqqqqqqv(+)qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqj x  
  tqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqu  
  x                               < Exit >    < Help >    < Save >    < Load >                           x  
  mqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqj  
                                                                                                                    

        use external kernel tree 按 enter 进入填写路径。

        外部源码配置只需要填下这个路径就行了,没有其他配置项。

编译:

        这里我建议,先去外部源码里面预编译一下,然后回来openwrt 走openwrt 的编译流程,因为这里面会涉及到很多问题。

        问题1:配置加载失败

                

		scripts/kconfig/conf  --silentoldconfig Kconfig
		*
		* Restart config...
		*
		*
		* Xilinx Specific Options
		*
Cache Prefetch (XILINX_PREFETCH) [Y/n/?] (NEW) 

            出现类似这样的错误,也就是内核的配置有问题,而先把内核源码编译一下就不会出现。

        问题2:make menuconfig 功能和 make kernel_menuconfig CONFIG_TARGET=target 功能的冲突

                这个问题对我来说是这样的:我需要kernel 中的某项功能支持,是cfg80211 模块的子功能,在make kernel_menuconfig CONFIG_TARGET=target(说明:这个是openwrt 下编译内核功能的命令)中已经勾选,但是make 时却提示:

                Package kmod-XXX is missing dependencies for the following libraries:

                cfg80211.ko

                mac80211.ko

                所以openwrt 未识别你在kernel 中勾选的功能,因此先编译下内核源码会让你的编译工作更顺畅。

        内核编译

                cd YOUR_KERNEL_PATH        #在你的外部源码路径下操作 

                准备好.config 配置文件

                export ARCH=arm

                export CROSS_COMPILE=arm-linux-gnueabihf-        #没有的话就下载:sudo apt-get install gcc-arm-linux-gnueabihf

                make menuconfig        #确认下你需要的一些功能有没有选上

                make prepare && make modules_prepare

                make -j12 uImage UIMAGE_LOADADDR=0x8000        #这个地方可能有个报错,直接百度下,安装那个工具就好了,具体我忘记了

                make modules

                到此为止,内核预编译工作完成,内核功能已经编好,接下来去openwrt 继续完成openwrt 的编译就好了。

        openwrt 编译

               cd OPENWRT_PATH

               make menuconfig        #确认下配置

               make kernel_menuconfig CONFIG_TARGET=target        #加载下内核配置,并进行确认。这里有个地方需要注意,openwrt 会分一个squashfs 分区,所以你的kernel 配置需要支持这个,进行勾选即可。

 .config - Linux/arm 4.14.0 Kernel Configuration
 > File systems > Miscellaneous filesystems qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq
  lqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq Miscellaneous filesystems qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqk
  x  Arrow keys navigate the menu.   selects submenus ---> (or empty submenus ----).  Highlighted letters x  
  x  are hotkeys.  Pressing  includes,  excludes,  modularizes features.  Press  to exit,  x  
  x  for Help,  for Search.  Legend: [*] built-in  [ ] excluded   module  < > module capable               x  
  x                                                                                                              x  
  x lqqqqqqqqqqqqqqqqqq^(-)qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqk x  
  x x                  [ ]     Advanced compression options for JFFS2                                          x x  
  x x                  < >   Compressed ROM file system support (cramfs) (OBSOLETE)                            x x  
  x x                  <*>   SquashFS 4.0 - Squashed file system support                                       x x  
  x x                          File decompression options (Decompress files directly into the page cache)  --->x x  
  x x                          Decompressor parallelisation options (Use percpu multiple decompressors for parax x  
  x x                  [ ]     Squashfs XATTR support                                                          x x  
  x x                  [ ]     Include support for ZLIB compressed file systems                                x x  
  x x                  [ ]     Include support for LZ4 compressed file systems                                 x x  
  x x                  [ ]     Include support for LZO compressed file systems                                 x x  
  x x                  [*]     Include support for XZ compressed file systems                                  x x  
  x x                  [ ]     Include support for ZSTD compressed file systems                                x x  
  x x                  [ ]     Use 4K device block size?                                                       x x  
  x x                  [*]     Additional option for memory-constrained systems                                x x  
  x x                  (3)       Number of fragments cached                                                    x x  
  x mqqqqqqqqqqqqqqqqqqv(+)qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqj x  
  tqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqu  
  x