Difference between revisions of "How to Build OpenWrt/zh"

From FriendlyELEC WiKi
Jump to: navigation, search
(为H3 平台编译OpenWrt)
Line 24: Line 24:
 
$ git clone https://github.com/friendlyarm/openwrt -b master-v18.06.1
 
$ git clone https://github.com/friendlyarm/openwrt -b master-v18.06.1
 
</syntaxhighlight>
 
</syntaxhighlight>
克隆完毕后,会得到一个名"openwrt"的目录。<br>
+
克隆完毕后,会得到一个名"openwrt"的目录。虽然该版本的OpenWrt目前仅支持为两款FriendlyElec H3开发板(NanoPi NEO / NanoPi M1 Plus)制作系统映像,但是由于FriendlyElec H3开发板都比较兼容和类似,所以我们完全可以基于NanoPi M1 Plus的OpenWrt的rootfs,为其他FriendlyElec H3开发板(NanoPi R1/NanoPi NEO/NanoPi NEO Air/NanoPi NEO Core/NanoPi M1)制作OpenWrt系统映像。<br>
虽然该版本的OpenWrt目前仅支持为两款FriendlyElec H3开发板(NanoPi NEO / NanoPi M1 Plus)制作系统映像,但是由于FriendlyElec H3开发板都比较兼容和类似,所以我们完全可以基于NanoPi M1 Plus的OpenWrt的rootfs,为其他FriendlyElec H3开发板(NanoPi R1/NanoPi NEO/NanoPi NEO Air/NanoPi NEO Core/NanoPi M1)制作OpenWrt系统映像。<br>
+
  
 
下面将以NanoPi M1 Plus为例,描述如何编译制作OpenWrt系统映像。在开始编译制作OpenWrt系统映像前,请务必先阅读OpenWrt官方编写的编译文档[https://openwrt.org/docs/guide-developer/build-system/use-buildsystem openwrt buildsystem],下面将不再赘述每一步编译操作的作用。<br>
 
下面将以NanoPi M1 Plus为例,描述如何编译制作OpenWrt系统映像。在开始编译制作OpenWrt系统映像前,请务必先阅读OpenWrt官方编写的编译文档[https://openwrt.org/docs/guide-developer/build-system/use-buildsystem openwrt buildsystem],下面将不再赘述每一步编译操作的作用。<br>
Line 70: Line 69:
  
 
<br>
 
<br>
 +
 
==为H3 平台制作OpenWrt ROM==
 
==为H3 平台制作OpenWrt ROM==
 
OpenWrt作为一个一体化的嵌入式系统制作方案,它集成了编译U-boot、Linux Kernel、Rootfs制作、软件源码包管理的功能。<br>
 
OpenWrt作为一个一体化的嵌入式系统制作方案,它集成了编译U-boot、Linux Kernel、Rootfs制作、软件源码包管理的功能。<br>

Revision as of 07:42, 1 July 2019

English

1 简介

OpenWrt是适合于嵌入式设备的一个Linux发行版,它不是一个单一、静态的固件,而是提供了一个可添加软件包的可写的文件系统。 这使用户可以自由的选择应用程序和配置,而不必受设备提供商的限制,并且可以使用一些适合某方面应用的软件包来定制你的设备。 对于开发者来说,OpenWrt是一个框架,开发者不必麻烦地构建整个固件就能得到想要的应用程序;对于用户来说,这意味着完全定制的能力,与以往不同的方式使用设备,OPKG包含超过3500个软件。 更详细的介绍请参考: OpenWrt官网

本Wiki页面的主要用于介绍如何为FriendlyElec发行的开发板编译OpenWrt,并不涉及太多对OpenWrt的定制和研究。 OpenWrt是由开源组织维护的开源项目,其官网上已经有丰富的用户文档和开发者文档,如果您需要对OpenWrt进行定制开发,请自行查看OpenWrt官方提供的文档: openwrt doc


2 为H3 平台编译OpenWrt

  • 首先,OpenWrt必须切换到普通用户才能正常编译,假设你的PC机的普通用户为fa,执行下列命令切换为该普通用户:
$ su fa

接下来的所有操作请务必在普通用户的环境下进行。


  • FriendlyElec使用的OpenWrt基于18.06.1版本,执行下列命令克隆源码并切换分支:
$ cd /home/fa/
$ git clone https://github.com/friendlyarm/openwrt -b master-v18.06.1

克隆完毕后,会得到一个名"openwrt"的目录。虽然该版本的OpenWrt目前仅支持为两款FriendlyElec H3开发板(NanoPi NEO / NanoPi M1 Plus)制作系统映像,但是由于FriendlyElec H3开发板都比较兼容和类似,所以我们完全可以基于NanoPi M1 Plus的OpenWrt的rootfs,为其他FriendlyElec H3开发板(NanoPi R1/NanoPi NEO/NanoPi NEO Air/NanoPi NEO Core/NanoPi M1)制作OpenWrt系统映像。

下面将以NanoPi M1 Plus为例,描述如何编译制作OpenWrt系统映像。在开始编译制作OpenWrt系统映像前,请务必先阅读OpenWrt官方编写的编译文档openwrt buildsystem,下面将不再赘述每一步编译操作的作用。


下载成功后,解压并拷贝dl目录到OpenWrt源码的根目录:

$ cd /home/fa/
$ tar xzf openwrt-18.06.1_sunxi-cortexa7_prebuilt_YYYMMDD.tar.gz ./
$ ls ./openwrt-18.06.1_sunxi-cortexa7_prebuilt/
bin  dl

其中,bin目录里包含的文件为FriendlyElec编译OpenWrt后产生的系统映像等文件,dl目录则为FriendlyElec预先下载好的软件包目录,将dl目录拷贝到OpenWrt源码的根目录:

$ cp -r ./openwrt-18.06.1_sunxi-cortexa7_prebuilt/dl /home/fa/openwrt/


  • 执行下列命令为FriendlyElec H3开发板(NanoPi NEO / NanoPi M1 Plus)编译并制作OpenWrt系统映像:
$ cd /home/fa/openwrt/friendlyelec
$ ./build.sh nanopi-h3

编译完成后,会生成下列文件:

$ tree bin/targets/sunxi/cortexa7/ -L 1
bin/targets/sunxi/cortexa7/
├── config.seed
├── openwrt-18.06.1-sunxi-cortexa7-device-sun8i-h3-nanopi-m1-plus.manifest
├── openwrt-18.06.1-sunxi-cortexa7.manifest
├── openwrt-18.06.1-sunxi-cortexa7-sun8i-h3-nanopi-m1-plus-ext4-sdcard.img.gz
├── openwrt-18.06.1-sunxi-cortexa7-sun8i-h3-nanopi-m1-plus-squashfs-sdcard.img.gz
├── openwrt-18.06.1-sunxi-cortexa7-sun8i-h3-nanopi-neo-ext4-sdcard.img.gz
├── openwrt-18.06.1-sunxi-cortexa7-sun8i-h3-nanopi-neo-squashfs-sdcard.img.gz
├── openwrt-imagebuilder-18.06.1-sunxi-cortexa7.Linux-x86_64.tar.xz
├── openwrt-sdk-18.06.1-sunxi-cortexa7_gcc-7.3.0_musl_eabi.Linux-x86_64.tar.xz
├── packages
└── sha256sums

openwrt-18.06.1-sunxi-cortexa7-sun8i-h3-nanopi-m1-plus-ext4-sdcard.img.gz可以用于烧写到TF卡并放在NanoPi M1 PLus上运行。
openwrt-18.06.1-sunxi-cortexa7-sun8i-h3-nanopi-neo-ext4-sdcard.img.gz可以烧写到TF卡并放在NanoPi NEO上运行。
这两个系统映像都是最原汁原味的OpenWrt系统。


3 为H3 平台制作OpenWrt ROM

OpenWrt作为一个一体化的嵌入式系统制作方案,它集成了编译U-boot、Linux Kernel、Rootfs制作、软件源码包管理的功能。
本WiKi编写时,对于FriendlyElec H3系列的开发板,OpenWrt官方使用的U-boot和Linux源码均为第三方开源社区维护的u-boot-2017.11.tar.bz2和linux-4.14.63.tar.xz(均位于dl目录下),而非FriendlyElec官方维护的版本。
开源社区维护的源码版本迭代较快并且变化较多,如果您想使用FriendlyElec官方维护的稳定版U-boot和Linux内核,请使用FriendlyElec定制过的系统映像,或者自行编译FriendlyElec提供的BSP源码并制作系统映像,相关参考如下:
1) Building U-boot and Linux for H5/H3/H2+,编译FriendlyElec维护的U-boot和Linux内核;
2) How to make your own SD-bootable ROM,以FriendlyElec的方式制作系统映像。FriendlyElec提供的nanopi-r1_sd_openwrt_4.14_armhf_YYYYMMDD.img.zip就是先从openwrt-18.06.1-sunxi-cortexa7-sun8i-h3-nanopi-m1-plus-ext4-sdcard.img.gz提取出rootfs,然后通过rom-maker-lite的脚本制作出来的;