How to Build FriendlyWrt

From FriendlyELEC WiKi
Revision as of 02:31, 7 November 2019 by Yftan (Talk | contribs) (Make Your Own Friendlywrt)

Jump to: navigation, search

查看中文

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.
After you get a repo package run the following command to extract it. Let's take an image for Allwinner H3 based boards as an example:

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

Now you have had the full source code for generating an image. The last number digits in the file name stand for the packing date. If you want to obtain the latest official release, remove "-l" and do "repo sync" again:

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

4.2.2 Two: Get Source Code from Github

4.2.2.1 H3 Based Boards
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 Based Boards
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 Based Boards
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 Based Boards
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 Based Boards
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 Get Latest Release With "Sync"

repo sync -c --no-clone-bundle

If synchronization is interrupted you can run the following script to do sync again:

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

4.2.4 Swtich To Different Platform

If you have been working on the source code for Allwinner H3's boards and want to swtich to the source code for Allwinner H5's boards you can do it this way:

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

5 Compile Source Code

5.1 Setup Development Environment

You need a host PC running a 64-bit Ubuntu 18.04 system and run the following command on the PC:

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

5.2 Get Help Info

Run the build.sh script without any options it will print the help information:

./build.sh

Let's take Allwinner H3 as an example, the help information will be presented as follows:

USAGE: ./build.sh <parameter>
 
# Select Board Type:
  ./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
 
# Select Module:
  ./build.sh all                -compile all
  ./build.sh uboot              -compile uboot
  ./build.sh kernel             -compile kernel
  ./build.sh friendlywrt        -compile friendlywrt
  ./build.sh sd-img             -generate an image for an sd card
  ./build.sh emmc-img           -generate an image for emmc (the generated image should be flased to an SD card and then flashed to emm with this SD card)
# Clean:
  ./build.sh cleanall

5.3 Auto Compile

For a first time compilation you need to select an SoC platform. Let's take the NanoPi R1(Allwinner H3) as an example:

./build.sh nanopi_r1.mk

After the script is done successfully all components including a u-boot, a kernel and a friendlywrt will be compiled, and an image file will be generated.

5.4 Compile Individual Component

5.4.1 kernel

./build.sh kernel

5.4.2 u-boot

./build.sh uboot

5.4.3 FriendlyWrt

./build.sh friendlywrt

5.5 Generate Image for SD Card

sudo ./build.sh sd-img

If an img file is generated successfully you will see the following messages. You can use the "dd" command to flash the img file to an SD card. Note: you will need to replace "/dev/sdX" with the actual device name which your system recognizes the device as:

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

5.6 Generate emmc (eflasher) Image

sudo ./build.sh emmc-img

If an img file is generated successfully you will see the following messages. You can use the "dd" command to flash the img file to an SD card. Note: you will need to replace "/dev/sdX" with the actual device name which your system recognizes the device as:

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

Use this SD card to boot the eflasher system and run eflasher commands to install an OS to emmc. After installation is done, take off the SD card of the board and boot your system friendlywrt will load from eMMC.

6 Make Your Own Friendlywrt

6.1 Structure of Source Code Directories

├── friendlywrt
│   ├── friendlywrt -> friendlywrt's source code
│   └── configs -> save the "friendlywrt defconfig" file
│   └── toolchain -> cross-compiler, used for compiling a u-boot and kernel
│   ├── build.sh -> script for auto-compile
│   ├── device/friendlyelec -> configuration file for friendlyelec boards
│   ├── kernel -> kernel
│   └── u-boot -> u-boot
│   └── scripts -> script files for generating an 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

  • 首次发布