Difference between revisions of "How to Build FriendlyWrt"

From FriendlyELEC WiKi
Jump to: navigation, search
(当前支持的开发板型号)
(获取项目源代码)
Line 45: Line 45:
 
How to test the image: extract the image file, use the "dd" command under Linux or the win32image utility under Windows to flash the image to an SD card.
 
How to test the image: extract the image file, use the "dd" command under Linux or the win32image utility under Windows to flash the image to an SD card.
  
==获取项目源代码==
+
==Get Source Code==
===安装 repo 工具===
+
===Install repo===
首先需要安装 repo 工具:
+
Firstly you need to install the repo utility:
 
<syntaxhighlight lang="bash">
 
<syntaxhighlight lang="bash">
 
git clone https://github.com/friendlyarm/repo
 
git clone https://github.com/friendlyarm/repo
 
cp repo/repo /usr/bin/
 
cp repo/repo /usr/bin/
 
</syntaxhighlight>
 
</syntaxhighlight>
===下载项目源代码===
+
===Download Source Code===
有以下两种途径获取项目源代码,中国大陆用户建议使用方法1的途径下载:
+
There are two ways to obtain the source code. For mainland Chinese users the first is recommended:
====方法一:使用网盘里的repo压缩包====
+
====One: Use Repo Package from FriendlyElec's Cloud Storage====
文件位于网盘的以下路径:sources/friendlywrt-CPU-YYYYMMDD.tar (CPU为对应的cpu型号,YYYYMMDD表示打包的日期)<br />
+
The source files are located at the "sources/friendlywrt-CPU-YYYYMMDD.tar" directory in FriendlyElec's cloud storage. "CPU" stands for an SoC model and YYYYMMDD stands for date(the year, month and day) in which the package is packed.<br />
 
从网盘中获取的 repo 压缩包在解压之后,需要执行一下以下命令做一次解包动作,以H3为例:
 
从网盘中获取的 repo 压缩包在解压之后,需要执行一下以下命令做一次解包动作,以H3为例:
 
<syntaxhighlight lang="bash">
 
<syntaxhighlight lang="bash">

Revision as of 01:19, 7 November 2019

查看中文

1 Introduction to FriendlyWrt

FriendlyWrt is a customized OpenWrt system developed by FriendlyElec. It is open source and suitable for applications in IoT, NAS and smart home gateways and etc.

2 User Name & Password

User name: root
Password: fa

Note: some systems don't need passwords

3 Supported FriendlyElec Boards

OS Supported Board Types Image File Download Link
FriendlyWRT for H3 NanoPi-R1, NanoPi-NEO, NanoPi-NEO-Air,
NanoPi-M1, ZeroPi, NanoPi-NEO-S,
NanoPi-NEO-Core, NanoPi-M1-Plus, NanoPi-Duo2
nanopi-r1_sd_friendlywrt_4.14_armhf_YYYYMMDD.img.zip H3 Download Link
FriendlyWRT for H5 NanoPi-NEO2,NanoPi-K1-Plus,NanoPi-NEO-Core2 nanopi-neo-core2_sd_friendlywrt_4.14_arm64_YYYYMMDD.img.zip H5 Download Link
FriendlyWRT for S5P4418 NanoPi-Fire2A, NanoPC-T2, NanoPi-S2,
NanoPi-M2A, Smart4418
s5p4418-sd-friendlywrt-4.4-YYYYMMDD.img.zip S5P4418 Download Link
FriendlyWRT for S5P6818 NanoPi-Fire3, NanoPC-T3, Smart6818 s5p6818-sd-friendlywrt-4.4-YYYYMMDD.img.zip S5P6818 Download Link
FriendlyWRT for RK3399 NanoPi-M4, NanoPC-T4, NanoPi-NEO4, Som-RK3399 rk3399-sd-friendlywrt-4.4-YYYYMMDD.img.zip RK3399 Download Link

How to test the image: extract the image file, use the "dd" command under Linux or the win32image utility under Windows to flash the image to an SD card.

4 Get Source Code

4.1 Install repo

Firstly you need to install the repo utility:

git clone https://github.com/friendlyarm/repo
cp repo/repo /usr/bin/

4.2 Download Source Code

There are two ways to obtain the source code. For mainland Chinese users the first is recommended:

4.2.1 One: Use Repo Package from FriendlyElec's Cloud Storage

The source files are located at the "sources/friendlywrt-CPU-YYYYMMDD.tar" directory in FriendlyElec's cloud storage. "CPU" stands for an SoC model and YYYYMMDD stands for date(the year, month and day) in which the package is packed.
从网盘中获取的 repo 压缩包在解压之后,需要执行一下以下命令做一次解包动作,以H3为例:

tar xvf /path/to/netdisk/sources/friendlywrt-h3-20190101.tar
cd friendlywrt-h3
repo sync -l --no-clone-bundle

至此你已经获得了完整的可以编译生成img的源代码,源代码版本是打包对应的日期,如果想拉取到官方最新的版本,可以去掉 -l 参数,执行一次 repo sync即可, 命令如下:

cd friendlywrt-h3
repo sync --no-clone-bundle

4.2.2 方法二:直接从github下载完整的源代码

4.2.2.1 H3平台
mkdir friendlywrt-h3
cd friendlywrt-h3
repo init -u https://github.com/friendlyarm/friendlywrt_manifests -b master -m h3.xml --repo-url=https://github.com/friendlyarm/repo  --no-clone-bundle
repo sync -c  --no-clone-bundle
4.2.2.2 H5平台
mkdir friendlywrt-h5
cd friendlywrt-h5
repo init -u https://github.com/friendlyarm/friendlywrt_manifests -b master -m h5.xml --repo-url=https://github.com/friendlyarm/repo  --no-clone-bundle
repo sync -c  --no-clone-bundle
4.2.2.3 S5P4418平台
mkdir friendlywrt-s5p4418
cd friendlywrt-s5p4418
repo init -u https://github.com/friendlyarm/friendlywrt_manifests -b master -m s5p4418.xml --repo-url=https://github.com/friendlyarm/repo  --no-clone-bundle
repo sync -c  --no-clone-bundle
4.2.2.4 S5P6818平台
mkdir friendlywrt-s5p6818
cd friendlywrt-s5p6818
repo init -u https://github.com/friendlyarm/friendlywrt_manifests -b master -m s5p6818.xml --repo-url=https://github.com/friendlyarm/repo  --no-clone-bundle
repo sync -c  --no-clone-bundle
4.2.2.5 RK3399平台
mkdir friendlywrt-rk3399
cd friendlywrt-rk3399
repo init -u https://github.com/friendlyarm/friendlywrt_manifests -b master -m rk3399.xml --repo-url=https://github.com/friendlyarm/repo  --no-clone-bundle
repo sync -c  --no-clone-bundle

4.2.3 同步项目到最新版本

repo sync -c --no-clone-bundle

同步过程中,由于网络原因出现中断,可以使用下面脚本同步代码:

#! /bin/bash
repo sync -c --no-clone-bundle
while [ $? -ne 0 ]; 
do  
    repo sync -c --no-clone-bundle
done

4.2.4 同一份代码,切换到其他平台

比如已有H3平台的代码,现在要开发H5平台,可以用以下命令,好处是可以减少网络下载:

cp -af friendlywrt-h3 friendlywrt-h5
cd friendlywrt-h5
repo init -m h5.xml
repo sync --force-sync

5 如何编译

5.1 搭建编译环境

在PC的Ubuntu系统下 (建议使用版本18.04-64bit),执下以下命令安装所需的软件:

wget -O - https://raw.githubusercontent.com/friendlyarm/build-env-on-ubuntu-bionic/master/install.sh | bash

5.2 查看帮助

不带参数执行 build.sh,默认是打印帮助信息:

./build.sh

显示的帮助信息如下 (以H3平台为例):

USAGE: ./build.sh <parameter>
 
# 选择目标的硬件平台:
  ./build.sh nanopi_r1.mk
  ./build.sh nanopi_duo.mk
  ./build.sh nanopi_neo_core.mk
  ./build.sh nanopi_neo.mk
  ./build.sh nanopi_neo_s.mk
  ./build.sh nanopi_m1_plus.mk
  ./build.sh nanopi_m1.mk
  ./build.sh nanopi_neo_air.mk
 
# 编译各个模块:
  ./build.sh all                -编译所有组件
  ./build.sh uboot              -单独编译uboot
  ./build.sh kernel             -单独编译kernel
  ./build.sh friendlywrt        -单独编译friendlywrt
  ./build.sh sd-img             -生成sd启动的镜像文件
  ./build.sh emmc-img           -生成用于安装到emmc的镜像文件 (镜像文件需要dd到sd卡,通过sd卡启动安装程序)
# 清理:
  ./build.sh cleanall

5.3 全自动方式编译

初次编译,需要选择目标的硬件平台,以H3平台的R1为例:

./build.sh nanopi_r1.mk

执行上述命令,会自动编译所有组件,其中包括u-boot, kernel 和 friendlywrt,并生成sd启动的烧写镜像文件。

5.4 编译单独的模块

5.4.1 kernel

./build.sh kernel

5.4.2 u-boot

./build.sh uboot

5.4.3 FriendlyWrt

./build.sh friendlywrt

5.5 生成sdcard固件

sudo ./build.sh sd-img

打包img成功后,终端会显示如下信息,可以参考下面的dd命令将img写入sd卡,注意/dev/sdX需要替换成真实的sd卡设备:

Run the following for sdcard install:
    sudo dd if=out/FriendlyWrt_20190828_NanoPi-R1_armhf_sd.img bs=1M of=/dev/sdX

5.6 生成emmc (eflasher) 固件

sudo ./build.sh emmc-img

打包img成功后,终端会显示如下信息,可以参考下面的dd命令将img写入sd卡,注意/dev/sdX需要替换成真实的sd卡设备:

Run the following for sdcard install:
    sudo dd if=out/FriendlyWrt_20190828_NanoPi-R1_armhf_eflasher.img bs=1M of=/dev/sdX

用此sd卡启动eflasher系统,执行eflasher命令,将系统写入emmc,之后就可以拨掉sd卡,从emmc启动friendlywrt了。

6 friendlywrt定制与开发

6.1 源代码目录结构

├── friendlywrt
│   ├── friendlywrt -> friendlywrt源代码
|   └── configs -> 保存预设好的friendlywrt defconfig文件
|   └── toolchain -> 交叉编译器,仅用于编译u-boot与kernel
│   ├── build.sh -> 全自动编译脚本
│   ├── device/friendlyelec -> 用于适配友善电子开发板的相关文件
│   ├── kernel -> 内核
│   └── u-boot -> u-boot
│   └── scripts -> 打包img的相关脚本

6.2 配置friendlywrt的软件包

  • 使用make menuconfig更改配置 (以h3为例)
cd friendlywrt-h3/friendlywrt
make menuconfig
  • 另存你个人的软件包配置
make menuconfig
./scripts/diffconfig.sh > ../configs/my_config
  • 让以后的编译使用你的friendlywrt配置

以NanoPi-R1为例,编辑以下文件:

device/friendlyelec/h3/nanopi_r1.mk

将TARGET_FRIENDLYWRT_CONFIG的值改为你的配置。

  • 重新编译friendlywrt并制成sd启动镜像
./build.sh friendlywrt
./build.sh sd-img

6.3 固化个人文件到friendlywrt

以H3平台为例, 将文件或目录放入以下目录即可,打包img时会把它们都打包进去:
device/friendlyelec/h3/common-files

也可以放在新建的目录里,以NanoPi-R1为例,然后编辑以下文件:

device/friendlyelec/h3/nanopi_r1.mk

在文件中新增一行 (XXX替换为你的目录名):

FRIENDLYWRT_FILES+=(device/friendlyelec/h3/XXX)

6.4 修改friendlywrt系统的默认配置(如网络、防火墙等)

编辑如下目录中的文件:

device/friendlyelec/h3/default-settings/files
friendlywrt/package/base-files/files

6.5 更改u-boot和kernel配置 (以H3为例)

同样是编辑如下文件:

device/friendlyelec/h3/nanopi_r1.mk

可通过以下设置,将uboot的配置改为你自已的:

TARGET_UBOOT_CONFIG=nanopi_h3_defconfig

可通过以下设置,将kernel的配置改为你自已的:

TARGET_KERNEL_CONFIG=sunxi_defconfig

6.6 更换其他源代码

编辑如下 xml 文件,即可替换 kernel 、uboot以及friendlywrt的源代码:

.repo/manifests/h3.xml

想了解 xml 文件各个节点的含义和用法,请参考:repo Manifest Format
编辑完成后,需要用 repo 命令同步一下,比如更换了 kernel 的源代码,用以下命令同步一次:

repo sync --force-sync kernel

同步后单独重新内核即可:

./build.sh kernel

7 常见问题及注意事项

  • Ubuntu下不能使用 root 用户来编译,需要使用普通用户
  • 在 vnc 环境下编译可能会编译失败

8 参考资料

repo使用指南

9 更新日志

9.1 2019-08-28

  • 首次发布